mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-16 01:40:44 +00:00
parent
20e6a3ef9d
commit
f363000d2d
3 changed files with 48 additions and 50 deletions
|
|
@ -12,8 +12,8 @@ import (
|
||||||
// MarshalJSON marshals as JSON.
|
// MarshalJSON marshals as JSON.
|
||||||
func (a AccessTuple) MarshalJSON() ([]byte, error) {
|
func (a AccessTuple) MarshalJSON() ([]byte, error) {
|
||||||
type AccessTuple struct {
|
type AccessTuple struct {
|
||||||
Address common.Address `json:"address" gencodec:"required"`
|
Address common.Address `json:"address" gencodec:"required"`
|
||||||
StorageKeys []common.Hash `json:"storageKeys" gencodec:"required"`
|
StorageKeys []common.Hash `json:"storageKeys" gencodec:"required"`
|
||||||
}
|
}
|
||||||
var enc AccessTuple
|
var enc AccessTuple
|
||||||
enc.Address = a.Address
|
enc.Address = a.Address
|
||||||
|
|
@ -24,8 +24,8 @@ func (a AccessTuple) MarshalJSON() ([]byte, error) {
|
||||||
// UnmarshalJSON unmarshals from JSON.
|
// UnmarshalJSON unmarshals from JSON.
|
||||||
func (a *AccessTuple) UnmarshalJSON(input []byte) error {
|
func (a *AccessTuple) UnmarshalJSON(input []byte) error {
|
||||||
type AccessTuple struct {
|
type AccessTuple struct {
|
||||||
Address *common.Address `json:"address" gencodec:"required"`
|
Address *common.Address `json:"address" gencodec:"required"`
|
||||||
StorageKeys []common.Hash `json:"storageKeys" gencodec:"required"`
|
StorageKeys []common.Hash `json:"storageKeys" gencodec:"required"`
|
||||||
}
|
}
|
||||||
var dec AccessTuple
|
var dec AccessTuple
|
||||||
if err := json.Unmarshal(input, &dec); err != nil {
|
if err := json.Unmarshal(input, &dec); err != nil {
|
||||||
|
|
|
||||||
|
|
@ -29,22 +29,19 @@ import (
|
||||||
type txJSON struct {
|
type txJSON struct {
|
||||||
Type hexutil.Uint64 `json:"type"`
|
Type hexutil.Uint64 `json:"type"`
|
||||||
|
|
||||||
// Common transaction fields:
|
ChainID *hexutil.Big `json:"chainId,omitempty"`
|
||||||
Nonce *hexutil.Uint64 `json:"nonce"`
|
Nonce *hexutil.Uint64 `json:"nonce"`
|
||||||
|
To *common.Address `json:"to"`
|
||||||
|
Gas *hexutil.Uint64 `json:"gas"`
|
||||||
GasPrice *hexutil.Big `json:"gasPrice"`
|
GasPrice *hexutil.Big `json:"gasPrice"`
|
||||||
MaxPriorityFeePerGas *hexutil.Big `json:"maxPriorityFeePerGas"`
|
MaxPriorityFeePerGas *hexutil.Big `json:"maxPriorityFeePerGas"`
|
||||||
MaxFeePerGas *hexutil.Big `json:"maxFeePerGas"`
|
MaxFeePerGas *hexutil.Big `json:"maxFeePerGas"`
|
||||||
Gas *hexutil.Uint64 `json:"gas"`
|
|
||||||
Value *hexutil.Big `json:"value"`
|
Value *hexutil.Big `json:"value"`
|
||||||
Data *hexutil.Bytes `json:"input"`
|
Input *hexutil.Bytes `json:"input"`
|
||||||
|
AccessList *AccessList `json:"accessList,omitempty"`
|
||||||
V *hexutil.Big `json:"v"`
|
V *hexutil.Big `json:"v"`
|
||||||
R *hexutil.Big `json:"r"`
|
R *hexutil.Big `json:"r"`
|
||||||
S *hexutil.Big `json:"s"`
|
S *hexutil.Big `json:"s"`
|
||||||
To *common.Address `json:"to"`
|
|
||||||
|
|
||||||
// Access list transaction fields:
|
|
||||||
ChainID *hexutil.Big `json:"chainId,omitempty"`
|
|
||||||
AccessList *AccessList `json:"accessList,omitempty"`
|
|
||||||
|
|
||||||
// Only used for encoding:
|
// Only used for encoding:
|
||||||
Hash common.Hash `json:"hash"`
|
Hash common.Hash `json:"hash"`
|
||||||
|
|
@ -65,7 +62,7 @@ func (tx *Transaction) MarshalJSON() ([]byte, error) {
|
||||||
enc.Gas = (*hexutil.Uint64)(&itx.Gas)
|
enc.Gas = (*hexutil.Uint64)(&itx.Gas)
|
||||||
enc.GasPrice = (*hexutil.Big)(itx.GasPrice)
|
enc.GasPrice = (*hexutil.Big)(itx.GasPrice)
|
||||||
enc.Value = (*hexutil.Big)(itx.Value)
|
enc.Value = (*hexutil.Big)(itx.Value)
|
||||||
enc.Data = (*hexutil.Bytes)(&itx.Data)
|
enc.Input = (*hexutil.Bytes)(&itx.Data)
|
||||||
enc.V = (*hexutil.Big)(itx.V)
|
enc.V = (*hexutil.Big)(itx.V)
|
||||||
enc.R = (*hexutil.Big)(itx.R)
|
enc.R = (*hexutil.Big)(itx.R)
|
||||||
enc.S = (*hexutil.Big)(itx.S)
|
enc.S = (*hexutil.Big)(itx.S)
|
||||||
|
|
@ -77,7 +74,7 @@ func (tx *Transaction) MarshalJSON() ([]byte, error) {
|
||||||
enc.Gas = (*hexutil.Uint64)(&itx.Gas)
|
enc.Gas = (*hexutil.Uint64)(&itx.Gas)
|
||||||
enc.GasPrice = (*hexutil.Big)(itx.GasPrice)
|
enc.GasPrice = (*hexutil.Big)(itx.GasPrice)
|
||||||
enc.Value = (*hexutil.Big)(itx.Value)
|
enc.Value = (*hexutil.Big)(itx.Value)
|
||||||
enc.Data = (*hexutil.Bytes)(&itx.Data)
|
enc.Input = (*hexutil.Bytes)(&itx.Data)
|
||||||
enc.AccessList = &itx.AccessList
|
enc.AccessList = &itx.AccessList
|
||||||
enc.V = (*hexutil.Big)(itx.V)
|
enc.V = (*hexutil.Big)(itx.V)
|
||||||
enc.R = (*hexutil.Big)(itx.R)
|
enc.R = (*hexutil.Big)(itx.R)
|
||||||
|
|
@ -91,7 +88,7 @@ func (tx *Transaction) MarshalJSON() ([]byte, error) {
|
||||||
enc.MaxFeePerGas = (*hexutil.Big)(itx.GasFeeCap)
|
enc.MaxFeePerGas = (*hexutil.Big)(itx.GasFeeCap)
|
||||||
enc.MaxPriorityFeePerGas = (*hexutil.Big)(itx.GasTipCap)
|
enc.MaxPriorityFeePerGas = (*hexutil.Big)(itx.GasTipCap)
|
||||||
enc.Value = (*hexutil.Big)(itx.Value)
|
enc.Value = (*hexutil.Big)(itx.Value)
|
||||||
enc.Data = (*hexutil.Bytes)(&itx.Data)
|
enc.Input = (*hexutil.Bytes)(&itx.Data)
|
||||||
enc.AccessList = &itx.AccessList
|
enc.AccessList = &itx.AccessList
|
||||||
enc.V = (*hexutil.Big)(itx.V)
|
enc.V = (*hexutil.Big)(itx.V)
|
||||||
enc.R = (*hexutil.Big)(itx.R)
|
enc.R = (*hexutil.Big)(itx.R)
|
||||||
|
|
@ -114,29 +111,30 @@ func (tx *Transaction) UnmarshalJSON(input []byte) error {
|
||||||
case LegacyTxType:
|
case LegacyTxType:
|
||||||
var itx LegacyTx
|
var itx LegacyTx
|
||||||
inner = &itx
|
inner = &itx
|
||||||
if dec.To != nil {
|
|
||||||
itx.To = dec.To
|
|
||||||
}
|
|
||||||
if dec.Nonce == nil {
|
if dec.Nonce == nil {
|
||||||
return errors.New("missing required field 'nonce' in transaction")
|
return errors.New("missing required field 'nonce' in transaction")
|
||||||
}
|
}
|
||||||
itx.Nonce = uint64(*dec.Nonce)
|
itx.Nonce = uint64(*dec.Nonce)
|
||||||
if dec.GasPrice == nil {
|
if dec.To != nil {
|
||||||
return errors.New("missing required field 'gasPrice' in transaction")
|
itx.To = dec.To
|
||||||
}
|
}
|
||||||
itx.GasPrice = (*big.Int)(dec.GasPrice)
|
|
||||||
if dec.Gas == nil {
|
if dec.Gas == nil {
|
||||||
return errors.New("missing required field 'gas' in transaction")
|
return errors.New("missing required field 'gas' in transaction")
|
||||||
}
|
}
|
||||||
itx.Gas = uint64(*dec.Gas)
|
itx.Gas = uint64(*dec.Gas)
|
||||||
|
if dec.GasPrice == nil {
|
||||||
|
return errors.New("missing required field 'gasPrice' in transaction")
|
||||||
|
}
|
||||||
|
itx.GasPrice = (*big.Int)(dec.GasPrice)
|
||||||
if dec.Value == nil {
|
if dec.Value == nil {
|
||||||
return errors.New("missing required field 'value' in transaction")
|
return errors.New("missing required field 'value' in transaction")
|
||||||
}
|
}
|
||||||
itx.Value = (*big.Int)(dec.Value)
|
itx.Value = (*big.Int)(dec.Value)
|
||||||
if dec.Data == nil {
|
if dec.Input == nil {
|
||||||
return errors.New("missing required field 'input' in transaction")
|
return errors.New("missing required field 'input' in transaction")
|
||||||
}
|
}
|
||||||
itx.Data = *dec.Data
|
itx.Data = *dec.Input
|
||||||
|
|
||||||
if dec.V == nil {
|
if dec.V == nil {
|
||||||
return errors.New("missing required field 'v' in transaction")
|
return errors.New("missing required field 'v' in transaction")
|
||||||
}
|
}
|
||||||
|
|
@ -159,37 +157,37 @@ func (tx *Transaction) UnmarshalJSON(input []byte) error {
|
||||||
case AccessListTxType:
|
case AccessListTxType:
|
||||||
var itx AccessListTx
|
var itx AccessListTx
|
||||||
inner = &itx
|
inner = &itx
|
||||||
// Access list is optional for now.
|
|
||||||
if dec.AccessList != nil {
|
|
||||||
itx.AccessList = *dec.AccessList
|
|
||||||
}
|
|
||||||
if dec.ChainID == nil {
|
if dec.ChainID == nil {
|
||||||
return errors.New("missing required field 'chainId' in transaction")
|
return errors.New("missing required field 'chainId' in transaction")
|
||||||
}
|
}
|
||||||
itx.ChainID = (*big.Int)(dec.ChainID)
|
itx.ChainID = (*big.Int)(dec.ChainID)
|
||||||
if dec.To != nil {
|
|
||||||
itx.To = dec.To
|
|
||||||
}
|
|
||||||
if dec.Nonce == nil {
|
if dec.Nonce == nil {
|
||||||
return errors.New("missing required field 'nonce' in transaction")
|
return errors.New("missing required field 'nonce' in transaction")
|
||||||
}
|
}
|
||||||
itx.Nonce = uint64(*dec.Nonce)
|
itx.Nonce = uint64(*dec.Nonce)
|
||||||
if dec.GasPrice == nil {
|
if dec.To != nil {
|
||||||
return errors.New("missing required field 'gasPrice' in transaction")
|
itx.To = dec.To
|
||||||
}
|
}
|
||||||
itx.GasPrice = (*big.Int)(dec.GasPrice)
|
|
||||||
if dec.Gas == nil {
|
if dec.Gas == nil {
|
||||||
return errors.New("missing required field 'gas' in transaction")
|
return errors.New("missing required field 'gas' in transaction")
|
||||||
}
|
}
|
||||||
itx.Gas = uint64(*dec.Gas)
|
itx.Gas = uint64(*dec.Gas)
|
||||||
|
if dec.GasPrice == nil {
|
||||||
|
return errors.New("missing required field 'gasPrice' in transaction")
|
||||||
|
}
|
||||||
|
itx.GasPrice = (*big.Int)(dec.GasPrice)
|
||||||
if dec.Value == nil {
|
if dec.Value == nil {
|
||||||
return errors.New("missing required field 'value' in transaction")
|
return errors.New("missing required field 'value' in transaction")
|
||||||
}
|
}
|
||||||
itx.Value = (*big.Int)(dec.Value)
|
itx.Value = (*big.Int)(dec.Value)
|
||||||
if dec.Data == nil {
|
if dec.Input == nil {
|
||||||
return errors.New("missing required field 'input' in transaction")
|
return errors.New("missing required field 'input' in transaction")
|
||||||
}
|
}
|
||||||
itx.Data = *dec.Data
|
itx.Data = *dec.Input
|
||||||
|
if dec.AccessList != nil {
|
||||||
|
itx.AccessList = *dec.AccessList
|
||||||
|
}
|
||||||
|
|
||||||
if dec.V == nil {
|
if dec.V == nil {
|
||||||
return errors.New("missing required field 'v' in transaction")
|
return errors.New("missing required field 'v' in transaction")
|
||||||
}
|
}
|
||||||
|
|
@ -212,21 +210,21 @@ func (tx *Transaction) UnmarshalJSON(input []byte) error {
|
||||||
case DynamicFeeTxType:
|
case DynamicFeeTxType:
|
||||||
var itx DynamicFeeTx
|
var itx DynamicFeeTx
|
||||||
inner = &itx
|
inner = &itx
|
||||||
// Access list is optional for now.
|
|
||||||
if dec.AccessList != nil {
|
|
||||||
itx.AccessList = *dec.AccessList
|
|
||||||
}
|
|
||||||
if dec.ChainID == nil {
|
if dec.ChainID == nil {
|
||||||
return errors.New("missing required field 'chainId' in transaction")
|
return errors.New("missing required field 'chainId' in transaction")
|
||||||
}
|
}
|
||||||
itx.ChainID = (*big.Int)(dec.ChainID)
|
itx.ChainID = (*big.Int)(dec.ChainID)
|
||||||
if dec.To != nil {
|
|
||||||
itx.To = dec.To
|
|
||||||
}
|
|
||||||
if dec.Nonce == nil {
|
if dec.Nonce == nil {
|
||||||
return errors.New("missing required field 'nonce' in transaction")
|
return errors.New("missing required field 'nonce' in transaction")
|
||||||
}
|
}
|
||||||
itx.Nonce = uint64(*dec.Nonce)
|
itx.Nonce = uint64(*dec.Nonce)
|
||||||
|
if dec.To != nil {
|
||||||
|
itx.To = dec.To
|
||||||
|
}
|
||||||
|
if dec.Gas == nil {
|
||||||
|
return errors.New("missing required field 'gas' for txdata")
|
||||||
|
}
|
||||||
|
itx.Gas = uint64(*dec.Gas)
|
||||||
if dec.MaxPriorityFeePerGas == nil {
|
if dec.MaxPriorityFeePerGas == nil {
|
||||||
return errors.New("missing required field 'maxPriorityFeePerGas' for txdata")
|
return errors.New("missing required field 'maxPriorityFeePerGas' for txdata")
|
||||||
}
|
}
|
||||||
|
|
@ -235,18 +233,18 @@ func (tx *Transaction) UnmarshalJSON(input []byte) error {
|
||||||
return errors.New("missing required field 'maxFeePerGas' for txdata")
|
return errors.New("missing required field 'maxFeePerGas' for txdata")
|
||||||
}
|
}
|
||||||
itx.GasFeeCap = (*big.Int)(dec.MaxFeePerGas)
|
itx.GasFeeCap = (*big.Int)(dec.MaxFeePerGas)
|
||||||
if dec.Gas == nil {
|
|
||||||
return errors.New("missing required field 'gas' for txdata")
|
|
||||||
}
|
|
||||||
itx.Gas = uint64(*dec.Gas)
|
|
||||||
if dec.Value == nil {
|
if dec.Value == nil {
|
||||||
return errors.New("missing required field 'value' in transaction")
|
return errors.New("missing required field 'value' in transaction")
|
||||||
}
|
}
|
||||||
itx.Value = (*big.Int)(dec.Value)
|
itx.Value = (*big.Int)(dec.Value)
|
||||||
if dec.Data == nil {
|
if dec.Input == nil {
|
||||||
return errors.New("missing required field 'input' in transaction")
|
return errors.New("missing required field 'input' in transaction")
|
||||||
}
|
}
|
||||||
itx.Data = *dec.Data
|
itx.Data = *dec.Input
|
||||||
|
if dec.AccessList != nil {
|
||||||
|
itx.AccessList = *dec.AccessList
|
||||||
|
}
|
||||||
|
|
||||||
if dec.V == nil {
|
if dec.V == nil {
|
||||||
return errors.New("missing required field 'v' in transaction")
|
return errors.New("missing required field 'v' in transaction")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,8 +31,8 @@ type AccessList []AccessTuple
|
||||||
|
|
||||||
// AccessTuple is the element type of an access list.
|
// AccessTuple is the element type of an access list.
|
||||||
type AccessTuple struct {
|
type AccessTuple struct {
|
||||||
Address common.Address `json:"address" gencodec:"required"`
|
Address common.Address `json:"address" gencodec:"required"`
|
||||||
StorageKeys []common.Hash `json:"storageKeys" gencodec:"required"`
|
StorageKeys []common.Hash `json:"storageKeys" gencodec:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// StorageKeys returns the total number of storage keys in the access list.
|
// StorageKeys returns the total number of storage keys in the access list.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue