@@ -250,6 +250,57 @@ func RPCMarshalEvent(e EventI) map[string]interface{} {
250250 }
251251}
252252
253+ // RPCUnmarshalEvent converts the RPC output to the header.
254+ func RPCUnmarshalEvent (data map [string ]interface {}) EventI {
255+ mustBeUint64 := func (name string ) uint64 {
256+ s := data [name ].(string )
257+ return hexutil .MustDecodeUint64 (s )
258+ }
259+ mustBeBytes := func (name string ) []byte {
260+ s := data [name ].(string )
261+ return hexutil .MustDecode (s )
262+ }
263+ mustBeID := func (name string ) (id [24 ]byte ) {
264+ s := data [name ].(string )
265+ bb := hexutil .MustDecode (s )
266+ copy (id [:], bb )
267+ return
268+ }
269+ mayBeHash := func (name string ) * hash.Hash {
270+ s , ok := data [name ].(string )
271+ if ! ok {
272+ return nil
273+ }
274+ bb := hexutil .MustDecode (s )
275+ h := hash .BytesToHash (bb )
276+ return & h
277+ }
278+
279+ e := MutableEventPayload {}
280+
281+ e .SetEpoch (idx .Epoch (mustBeUint64 ("epoch" )))
282+ e .SetSeq (idx .Event (mustBeUint64 ("seq" )))
283+ e .SetID (mustBeID ("id" ))
284+ e .SetFrame (idx .Frame (mustBeUint64 ("frame" )))
285+ e .SetCreator (idx .ValidatorID (mustBeUint64 ("creator" )))
286+ e .SetPrevEpochHash (mayBeHash ("prevEpochHash" ))
287+ e .SetParents (HexToEventIDs (data ["parents" ].([]interface {})))
288+ e .SetLamport (idx .Lamport (mustBeUint64 ("lamport" )))
289+ e .SetCreationTime (Timestamp (mustBeUint64 ("creationTime" )))
290+ e .SetMedianTime (Timestamp (mustBeUint64 ("medianTime" )))
291+ e .SetExtra (mustBeBytes ("extraData" ))
292+ e .SetTxHash (* mayBeHash ("transactionsRoot" ))
293+ e .SetGasPowerUsed (mustBeUint64 ("gasPowerUsed" ))
294+
295+ gas := GasPowerLeft {}
296+ obj := data ["gasPowerLeft" ].(map [string ]interface {})
297+ gas .Gas [ShortTermGas ] = hexutil .MustDecodeUint64 (obj ["shortTerm" ].(string ))
298+ gas .Gas [LongTermGas ] = hexutil .MustDecodeUint64 (obj ["longTerm" ].(string ))
299+ e .SetGasPowerLeft (gas )
300+
301+ return e .Build ()
302+ }
303+
253304// RPCMarshalEventPayload converts the given event to the RPC output which depends on fullTx. If inclTx is true transactions are
254305// returned. When fullTx is true the returned block contains full transaction details, otherwise it will only contain
255306// transaction hashes.
0 commit comments