eth/protocols/eth: simplify

This commit is contained in:
Felix Lange 2025-04-16 10:02:19 +02:00
parent 5943631173
commit 268f33ac95
2 changed files with 4 additions and 20 deletions

View file

@ -19,7 +19,6 @@ package eth
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"io"
"iter" "iter"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
@ -63,19 +62,8 @@ func (r *Receipt) DecodeRLP(s *rlp.Stream) error {
return s.ListEnd() return s.ListEnd()
} }
// EncodeRLP writes the network encoding of receipts. // encodeStorage writes the storage encoding, i.e. the result matches
func (r *Receipt) EncodeRLP(_w io.Writer) error { // types.ReceiptForStorage.
w := rlp.NewEncoderBuffer(_w)
list := w.List()
w.WriteUint64(uint64(r.TxType))
w.WriteBytes(r.PostStateOrStatus)
w.WriteUint64(r.GasUsed)
w.Write(r.Logs)
w.ListEnd(list)
return w.Flush()
}
// encodeStorage writes the network encoding of receipts.
func (r *Receipt) encodeStorage(w *rlp.EncoderBuffer) { func (r *Receipt) encodeStorage(w *rlp.EncoderBuffer) {
list := w.List() list := w.List()
w.WriteBytes(r.PostStateOrStatus) w.WriteBytes(r.PostStateOrStatus)

View file

@ -66,18 +66,14 @@ func TestTransformReceipts(t *testing.T) {
encBlockBody, _ := rlp.EncodeToBytes(blockBody) encBlockBody, _ := rlp.EncodeToBytes(blockBody)
// convert from storage encoding to network encoding // convert from storage encoding to network encoding
have, err := blockReceiptsToNetwork(in, encBlockBody) network, err := blockReceiptsToNetwork(in, encBlockBody)
if err != nil { if err != nil {
t.Fatalf("test[%d]: blockReceiptsToNetwork error: %v", i, err) t.Fatalf("test[%d]: blockReceiptsToNetwork error: %v", i, err)
} }
out, _ := rlp.EncodeToBytes(test.output)
if !bytes.Equal(have, out) {
t.Fatalf("test[%d]: blockReceiptsToNetwork mismatch\nhave: %x\nwant: %x\n in: %x", i, out, have, in)
}
// parse as Receipts response list from network encoding // parse as Receipts response list from network encoding
var rl ReceiptList69 var rl ReceiptList69
if err := rlp.DecodeBytes(out, &rl); err != nil { if err := rlp.DecodeBytes(network, &rl); err != nil {
t.Fatalf("test[%d]: can't decode network receipts: %v", i, err) t.Fatalf("test[%d]: can't decode network receipts: %v", i, err)
} }
storageEnc := rl.toStorageReceiptsRLP() storageEnc := rl.toStorageReceiptsRLP()