diff --git a/blockchain/blockchain.go b/blockchain/blockchain.go index 72e870ef1e..7b8c2d69d0 100644 --- a/blockchain/blockchain.go +++ b/blockchain/blockchain.go @@ -652,18 +652,18 @@ func stateUpdateByHash(txn db.Transaction, hash *felt.Felt) (*core.StateUpdate, } func l1HandlerTxnHashByMsgHash(txn db.Transaction, l1HandlerMsgHash *common.Hash) (*felt.Felt, error) { - var raw []byte + l1HandlerTxnHash := new(felt.Felt) err := txn.Get(db.L1HandlerTxnHashByMsgHash.Key(l1HandlerMsgHash.Bytes()), func(val []byte) error { if len(val) == 0 { return db.ErrKeyNotFound } - raw = val + l1HandlerTxnHash.Unmarshal(val) return nil }) if err != nil { return nil, err } - return new(felt.Felt).SetBytes(raw), nil + return l1HandlerTxnHash, nil } // SanityCheckNewHeight checks integrity of a block and resulting state update diff --git a/core/felt/felt.go b/core/felt/felt.go index 84fa3c2f3f..284e7a064b 100644 --- a/core/felt/felt.go +++ b/core/felt/felt.go @@ -144,6 +144,11 @@ func (z *Felt) Marshal() []byte { return z.val.Marshal() } +// Unmarshal forwards the call to underlying field element implementation +func (z *Felt) Unmarshal(e []byte) { + z.val.Unmarshal(e) +} + // Bytes forwards the call to underlying field element implementation func (z *Felt) Bytes() [32]byte { return z.val.Bytes() diff --git a/core/felt/felt_test.go b/core/felt/felt_test.go index 6a7c40afc9..b7fb10f07b 100644 --- a/core/felt/felt_test.go +++ b/core/felt/felt_test.go @@ -65,3 +65,13 @@ func TestShortString(t *testing.T) { assert.Equal(t, "0x1234...6789", f.ShortString()) }) } +func TestFeltMarshalAndUnmarshal(t *testing.T) { + f := new(felt.Felt).SetBytes([]byte("somebytes")) + + fBytes := f.Marshal() + + f2 := new(felt.Felt) + f2.Unmarshal(fBytes) + + assert.True(t, f2.Equal(f)) +}