Skip to content

Commit

Permalink
hard copy
Browse files Browse the repository at this point in the history
  • Loading branch information
rianhughes committed Nov 1, 2024
1 parent 2738c3f commit e814915
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
6 changes: 3 additions & 3 deletions blockchain/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions core/felt/felt.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
10 changes: 10 additions & 0 deletions core/felt/felt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

0 comments on commit e814915

Please sign in to comment.