mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 15:16:43 +00:00
core/types: add handcrafted and generated rlp encoders
This commit is contained in:
parent
89a5581473
commit
9a070f7ab1
4 changed files with 63 additions and 63 deletions
|
|
@ -555,88 +555,88 @@ func HeaderParentHashFromRLP(header []byte) common.Hash {
|
|||
return common.BytesToHash(parentHash)
|
||||
}
|
||||
|
||||
func (obj *Header) DecodeRLP(dec *rlp.Stream) error {
|
||||
func (h *Header) DecodeRLP(dec *rlp.Stream) error {
|
||||
var err error
|
||||
{
|
||||
if _, err := dec.List(); err != nil {
|
||||
return err
|
||||
}
|
||||
// ParentHash:
|
||||
if err := dec.ReadBytes(obj.ParentHash[:]); err != nil {
|
||||
if err := dec.ReadBytes(h.ParentHash[:]); err != nil {
|
||||
return err
|
||||
}
|
||||
// UncleHash:
|
||||
if err := dec.ReadBytes(obj.UncleHash[:]); err != nil {
|
||||
if err := dec.ReadBytes(h.UncleHash[:]); err != nil {
|
||||
return err
|
||||
}
|
||||
// Coinbase:
|
||||
if err := dec.ReadBytes(obj.Coinbase[:]); err != nil {
|
||||
if err := dec.ReadBytes(h.Coinbase[:]); err != nil {
|
||||
return err
|
||||
}
|
||||
// Root:
|
||||
if err := dec.ReadBytes(obj.Root[:]); err != nil {
|
||||
if err := dec.ReadBytes(h.Root[:]); err != nil {
|
||||
return err
|
||||
}
|
||||
// TxHash:
|
||||
if err := dec.ReadBytes(obj.TxHash[:]); err != nil {
|
||||
if err := dec.ReadBytes(h.TxHash[:]); err != nil {
|
||||
return err
|
||||
}
|
||||
// ReceiptHash:
|
||||
if err := dec.ReadBytes(obj.ReceiptHash[:]); err != nil {
|
||||
if err := dec.ReadBytes(h.ReceiptHash[:]); err != nil {
|
||||
return err
|
||||
}
|
||||
// Bloom:
|
||||
if err := dec.ReadBytes(obj.Bloom[:]); err != nil {
|
||||
if err := dec.ReadBytes(h.Bloom[:]); err != nil {
|
||||
return err
|
||||
}
|
||||
// Difficulty:
|
||||
obj.Difficulty, err = dec.BigInt()
|
||||
h.Difficulty, err = dec.BigInt()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Number:
|
||||
obj.Number, err = dec.BigInt()
|
||||
h.Number, err = dec.BigInt()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var err error
|
||||
// GasLimit:
|
||||
obj.GasLimit, err = dec.Uint64()
|
||||
h.GasLimit, err = dec.Uint64()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// GasUsed:
|
||||
obj.GasUsed, err = dec.Uint64()
|
||||
h.GasUsed, err = dec.Uint64()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Time:
|
||||
obj.Time, err = dec.Uint64()
|
||||
h.Time, err = dec.Uint64()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Extra:
|
||||
obj.Extra, err = dec.Bytes()
|
||||
h.Extra, err = dec.Bytes()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// MixDigest:
|
||||
if err := dec.ReadBytes(obj.MixDigest[:]); err != nil {
|
||||
if err := dec.ReadBytes(h.MixDigest[:]); err != nil {
|
||||
return err
|
||||
}
|
||||
// Nonce:
|
||||
if err := dec.ReadBytes(obj.Nonce[:]); err != nil {
|
||||
if err := dec.ReadBytes(h.Nonce[:]); err != nil {
|
||||
return err
|
||||
}
|
||||
// BaseFee:
|
||||
if dec.MoreDataInList() {
|
||||
obj.BaseFee, err = dec.BigInt()
|
||||
h.BaseFee, err = dec.BigInt()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// WithdrawalsHash:
|
||||
if dec.MoreDataInList() {
|
||||
if err := dec.ReadBytes(obj.WithdrawalsHash[:]); err != nil {
|
||||
if err := dec.ReadBytes(h.WithdrawalsHash[:]); err != nil {
|
||||
return err
|
||||
}
|
||||
// BlobGasUsed:
|
||||
|
|
@ -645,22 +645,22 @@ func (obj *Header) DecodeRLP(dec *rlp.Stream) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
obj.BlobGasUsed = &_tmp18
|
||||
h.BlobGasUsed = &_tmp18
|
||||
// ExcessBlobGas:
|
||||
if dec.MoreDataInList() {
|
||||
_tmp19, err := dec.Uint64()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
obj.ExcessBlobGas = &_tmp19
|
||||
h.ExcessBlobGas = &_tmp19
|
||||
// ParentBeaconRoot:
|
||||
if dec.MoreDataInList() {
|
||||
if err := dec.ReadBytes(obj.ParentBeaconRoot[:]); err != nil {
|
||||
if err := dec.ReadBytes(h.ParentBeaconRoot[:]); err != nil {
|
||||
return err
|
||||
}
|
||||
// RequestsHash:
|
||||
if dec.MoreDataInList() {
|
||||
if err := dec.ReadBytes(obj.RequestsHash[:]); err != nil {
|
||||
if err := dec.ReadBytes(h.RequestsHash[:]); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,9 +2,7 @@
|
|||
|
||||
package types
|
||||
|
||||
import "github.com/ethereum/go-ethereum/common"
|
||||
import "github.com/ethereum/go-ethereum/rlp"
|
||||
import "github.com/holiman/uint256"
|
||||
import "io"
|
||||
|
||||
func (obj *StateAccount) EncodeRLP(_w io.Writer) error {
|
||||
|
|
@ -21,41 +19,3 @@ func (obj *StateAccount) EncodeRLP(_w io.Writer) error {
|
|||
w.ListEnd(_tmp0)
|
||||
return w.Flush()
|
||||
}
|
||||
|
||||
func (obj *StateAccount) DecodeRLP(dec *rlp.Stream) error {
|
||||
var _tmp0 StateAccount
|
||||
{
|
||||
if _, err := dec.List(); err != nil {
|
||||
return err
|
||||
}
|
||||
// Nonce:
|
||||
_tmp1, err := dec.Uint64()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_tmp0.Nonce = _tmp1
|
||||
// Balance:
|
||||
var _tmp2 uint256.Int
|
||||
if err := dec.ReadUint256(&_tmp2); err != nil {
|
||||
return err
|
||||
}
|
||||
_tmp0.Balance = &_tmp2
|
||||
// Root:
|
||||
var _tmp3 common.Hash
|
||||
if err := dec.ReadBytes(_tmp3[:]); err != nil {
|
||||
return err
|
||||
}
|
||||
_tmp0.Root = _tmp3
|
||||
// CodeHash:
|
||||
_tmp4, err := dec.Bytes()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_tmp0.CodeHash = _tmp4
|
||||
if err := dec.ListEnd(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
*obj = _tmp0
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ import (
|
|||
"github.com/holiman/uint256"
|
||||
)
|
||||
|
||||
//go:generate go run ../../rlp/rlpgen -type StateAccount -out gen_account_rlp.go
|
||||
//go:generate go run ../../rlp/rlpgen -type StateAccount -decoder=false -out gen_account_rlp.go
|
||||
|
||||
// StateAccount is the Ethereum consensus representation of accounts.
|
||||
// These objects are stored in the main account trie.
|
||||
|
|
@ -35,6 +35,37 @@ type StateAccount struct {
|
|||
CodeHash []byte
|
||||
}
|
||||
|
||||
func (obj *StateAccount) DecodeRLP(dec *rlp.Stream) error {
|
||||
var err error
|
||||
{
|
||||
if _, err := dec.List(); err != nil {
|
||||
return err
|
||||
}
|
||||
// Nonce:
|
||||
obj.Nonce, err = dec.Uint64()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Balance:
|
||||
if err := dec.ReadUint256(obj.Balance); err != nil {
|
||||
return err
|
||||
}
|
||||
// Root:
|
||||
if err := dec.ReadBytes(obj.Root[:]); err != nil {
|
||||
return err
|
||||
}
|
||||
// CodeHash:
|
||||
obj.CodeHash, err = dec.Bytes()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := dec.ListEnd(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// NewEmptyStateAccount constructs an empty state account.
|
||||
func NewEmptyStateAccount() *StateAccount {
|
||||
return &StateAccount{
|
||||
|
|
|
|||
|
|
@ -149,6 +149,15 @@ func benchRLP(b *testing.B, encode bool) {
|
|||
"full-block",
|
||||
makeBenchBlock(),
|
||||
},
|
||||
{
|
||||
"state-account",
|
||||
&StateAccount{
|
||||
Nonce: 0,
|
||||
Balance: uint256.NewInt(0),
|
||||
Root: common.Hash{},
|
||||
CodeHash: make([]byte, 32),
|
||||
},
|
||||
},
|
||||
} {
|
||||
if encode {
|
||||
b.Run(tc.name, func(b *testing.B) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue