Skip to content

Commit

Permalink
fixed marshaling
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverbundalo committed Nov 2, 2024
1 parent bf7d0f7 commit 4db3476
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
4 changes: 4 additions & 0 deletions types/rlp_marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,10 @@ func (t *Transactions) MarshalRLPWith(a *fastrlp.Arena) *fastrlp.Value {
vv := a.NewArray()

for _, tt := range *t {
if tt.Type() != LegacyTxType {
vv.Set(a.NewCopyBytes([]byte{byte(tt.Type())}))
}

vv.Set(tt.MarshalRLPWith(a))
}

Expand Down
36 changes: 18 additions & 18 deletions types/rlp_unmarshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,24 +229,6 @@ func (h *Header) unmarshalRLPFrom(_ *fastrlp.Parser, v *fastrlp.Value) error {
return err
}

func (t *Transactions) UnmarshalRLP(input []byte) error {
return UnmarshalRlp(t.unmarshalRLPFrom, input)
}

func (t *Transactions) unmarshalRLPFrom(p *fastrlp.Parser, v *fastrlp.Value) error {
return unmarshalRLPFrom(p, v, func(_ TxType, p *fastrlp.Parser, v *fastrlp.Value) error {
obj := &Transaction{}

if err := obj.UnmarshalRLPFrom(p, v); err != nil {
return err
}

*t = append(*t, obj)

return nil
})
}

func (r *Receipts) UnmarshalRLP(input []byte) error {
return UnmarshalRlp(r.unmarshalRLPFrom, input)
}
Expand Down Expand Up @@ -376,6 +358,24 @@ func (l *Log) unmarshalRLPFrom(_ *fastrlp.Parser, v *fastrlp.Value) error {
return nil
}

func (t *Transactions) UnmarshalRLP(input []byte) error {
return UnmarshalRlp(t.unmarshalRLPFrom, input)
}

func (t *Transactions) unmarshalRLPFrom(p *fastrlp.Parser, v *fastrlp.Value) error {
return unmarshalRLPFrom(p, v, func(txType TxType, p *fastrlp.Parser, v *fastrlp.Value) error {
obj := NewTxWithType(txType)

if err := obj.UnmarshalRLPFrom(p, v); err != nil {
return err
}

*t = append(*t, obj)

return nil
})
}

// UnmarshalRLP unmarshals transaction from byte slice
// Caution: Hash calculation should be done from the outside!
func (t *Transaction) UnmarshalRLP(input []byte) error {
Expand Down

0 comments on commit 4db3476

Please sign in to comment.