mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-17 18:30:45 +00:00
Access list state test format (#22290)
This commit is contained in:
parent
1c47afb286
commit
32778572d7
4 changed files with 40 additions and 22 deletions
|
|
@ -13,6 +13,7 @@ import (
|
||||||
|
|
||||||
var _ = (*stEnvMarshaling)(nil)
|
var _ = (*stEnvMarshaling)(nil)
|
||||||
|
|
||||||
|
// MarshalJSON marshals as JSON.
|
||||||
func (s stEnv) MarshalJSON() ([]byte, error) {
|
func (s stEnv) MarshalJSON() ([]byte, error) {
|
||||||
type stEnv struct {
|
type stEnv struct {
|
||||||
Coinbase common.UnprefixedAddress `json:"currentCoinbase" gencodec:"required"`
|
Coinbase common.UnprefixedAddress `json:"currentCoinbase" gencodec:"required"`
|
||||||
|
|
@ -30,6 +31,7 @@ func (s stEnv) MarshalJSON() ([]byte, error) {
|
||||||
return json.Marshal(&enc)
|
return json.Marshal(&enc)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UnmarshalJSON unmarshals from JSON.
|
||||||
func (s *stEnv) UnmarshalJSON(input []byte) error {
|
func (s *stEnv) UnmarshalJSON(input []byte) error {
|
||||||
type stEnv struct {
|
type stEnv struct {
|
||||||
Coinbase *common.UnprefixedAddress `json:"currentCoinbase" gencodec:"required"`
|
Coinbase *common.UnprefixedAddress `json:"currentCoinbase" gencodec:"required"`
|
||||||
|
|
|
||||||
|
|
@ -8,25 +8,29 @@ import (
|
||||||
|
|
||||||
"github.com/XinFinOrg/XDPoSChain/common/hexutil"
|
"github.com/XinFinOrg/XDPoSChain/common/hexutil"
|
||||||
"github.com/XinFinOrg/XDPoSChain/common/math"
|
"github.com/XinFinOrg/XDPoSChain/common/math"
|
||||||
|
"github.com/XinFinOrg/XDPoSChain/core/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ = (*stTransactionMarshaling)(nil)
|
var _ = (*stTransactionMarshaling)(nil)
|
||||||
|
|
||||||
|
// MarshalJSON marshals as JSON.
|
||||||
func (s stTransaction) MarshalJSON() ([]byte, error) {
|
func (s stTransaction) MarshalJSON() ([]byte, error) {
|
||||||
type stTransaction struct {
|
type stTransaction struct {
|
||||||
GasPrice *math.HexOrDecimal256 `json:"gasPrice"`
|
GasPrice *math.HexOrDecimal256 `json:"gasPrice"`
|
||||||
Nonce math.HexOrDecimal64 `json:"nonce"`
|
Nonce math.HexOrDecimal64 `json:"nonce"`
|
||||||
To string `json:"to"`
|
To string `json:"to"`
|
||||||
Data []string `json:"data"`
|
Data []string `json:"data"`
|
||||||
GasLimit []math.HexOrDecimal64 `json:"gasLimit"`
|
AccessLists []*types.AccessList `json:"accessLists,omitempty"`
|
||||||
Value []string `json:"value"`
|
GasLimit []math.HexOrDecimal64 `json:"gasLimit"`
|
||||||
PrivateKey hexutil.Bytes `json:"secretKey"`
|
Value []string `json:"value"`
|
||||||
|
PrivateKey hexutil.Bytes `json:"secretKey"`
|
||||||
}
|
}
|
||||||
var enc stTransaction
|
var enc stTransaction
|
||||||
enc.GasPrice = (*math.HexOrDecimal256)(s.GasPrice)
|
enc.GasPrice = (*math.HexOrDecimal256)(s.GasPrice)
|
||||||
enc.Nonce = math.HexOrDecimal64(s.Nonce)
|
enc.Nonce = math.HexOrDecimal64(s.Nonce)
|
||||||
enc.To = s.To
|
enc.To = s.To
|
||||||
enc.Data = s.Data
|
enc.Data = s.Data
|
||||||
|
enc.AccessLists = s.AccessLists
|
||||||
if s.GasLimit != nil {
|
if s.GasLimit != nil {
|
||||||
enc.GasLimit = make([]math.HexOrDecimal64, len(s.GasLimit))
|
enc.GasLimit = make([]math.HexOrDecimal64, len(s.GasLimit))
|
||||||
for k, v := range s.GasLimit {
|
for k, v := range s.GasLimit {
|
||||||
|
|
@ -38,15 +42,17 @@ func (s stTransaction) MarshalJSON() ([]byte, error) {
|
||||||
return json.Marshal(&enc)
|
return json.Marshal(&enc)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UnmarshalJSON unmarshals from JSON.
|
||||||
func (s *stTransaction) UnmarshalJSON(input []byte) error {
|
func (s *stTransaction) UnmarshalJSON(input []byte) error {
|
||||||
type stTransaction struct {
|
type stTransaction struct {
|
||||||
GasPrice *math.HexOrDecimal256 `json:"gasPrice"`
|
GasPrice *math.HexOrDecimal256 `json:"gasPrice"`
|
||||||
Nonce *math.HexOrDecimal64 `json:"nonce"`
|
Nonce *math.HexOrDecimal64 `json:"nonce"`
|
||||||
To *string `json:"to"`
|
To *string `json:"to"`
|
||||||
Data []string `json:"data"`
|
Data []string `json:"data"`
|
||||||
GasLimit []math.HexOrDecimal64 `json:"gasLimit"`
|
AccessLists []*types.AccessList `json:"accessLists,omitempty"`
|
||||||
Value []string `json:"value"`
|
GasLimit []math.HexOrDecimal64 `json:"gasLimit"`
|
||||||
PrivateKey *hexutil.Bytes `json:"secretKey"`
|
Value []string `json:"value"`
|
||||||
|
PrivateKey *hexutil.Bytes `json:"secretKey"`
|
||||||
}
|
}
|
||||||
var dec stTransaction
|
var dec stTransaction
|
||||||
if err := json.Unmarshal(input, &dec); err != nil {
|
if err := json.Unmarshal(input, &dec); err != nil {
|
||||||
|
|
@ -64,6 +70,9 @@ func (s *stTransaction) UnmarshalJSON(input []byte) error {
|
||||||
if dec.Data != nil {
|
if dec.Data != nil {
|
||||||
s.Data = dec.Data
|
s.Data = dec.Data
|
||||||
}
|
}
|
||||||
|
if dec.AccessLists != nil {
|
||||||
|
s.AccessLists = dec.AccessLists
|
||||||
|
}
|
||||||
if dec.GasLimit != nil {
|
if dec.GasLimit != nil {
|
||||||
s.GasLimit = make([]uint64, len(dec.GasLimit))
|
s.GasLimit = make([]uint64, len(dec.GasLimit))
|
||||||
for k, v := range dec.GasLimit {
|
for k, v := range dec.GasLimit {
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ import (
|
||||||
|
|
||||||
var _ = (*vmExecMarshaling)(nil)
|
var _ = (*vmExecMarshaling)(nil)
|
||||||
|
|
||||||
|
// MarshalJSON marshals as JSON.
|
||||||
func (v vmExec) MarshalJSON() ([]byte, error) {
|
func (v vmExec) MarshalJSON() ([]byte, error) {
|
||||||
type vmExec struct {
|
type vmExec struct {
|
||||||
Address common.UnprefixedAddress `json:"address" gencodec:"required"`
|
Address common.UnprefixedAddress `json:"address" gencodec:"required"`
|
||||||
|
|
@ -37,6 +38,7 @@ func (v vmExec) MarshalJSON() ([]byte, error) {
|
||||||
return json.Marshal(&enc)
|
return json.Marshal(&enc)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UnmarshalJSON unmarshals from JSON.
|
||||||
func (v *vmExec) UnmarshalJSON(input []byte) error {
|
func (v *vmExec) UnmarshalJSON(input []byte) error {
|
||||||
type vmExec struct {
|
type vmExec struct {
|
||||||
Address *common.UnprefixedAddress `json:"address" gencodec:"required"`
|
Address *common.UnprefixedAddress `json:"address" gencodec:"required"`
|
||||||
|
|
|
||||||
|
|
@ -93,13 +93,14 @@ type stEnvMarshaling struct {
|
||||||
//go:generate gencodec -type stTransaction -field-override stTransactionMarshaling -out gen_sttransaction.go
|
//go:generate gencodec -type stTransaction -field-override stTransactionMarshaling -out gen_sttransaction.go
|
||||||
|
|
||||||
type stTransaction struct {
|
type stTransaction struct {
|
||||||
GasPrice *big.Int `json:"gasPrice"`
|
GasPrice *big.Int `json:"gasPrice"`
|
||||||
Nonce uint64 `json:"nonce"`
|
Nonce uint64 `json:"nonce"`
|
||||||
To string `json:"to"`
|
To string `json:"to"`
|
||||||
Data []string `json:"data"`
|
Data []string `json:"data"`
|
||||||
GasLimit []uint64 `json:"gasLimit"`
|
AccessLists []*types.AccessList `json:"accessLists,omitempty"`
|
||||||
Value []string `json:"value"`
|
GasLimit []uint64 `json:"gasLimit"`
|
||||||
PrivateKey []byte `json:"secretKey"`
|
Value []string `json:"value"`
|
||||||
|
PrivateKey []byte `json:"secretKey"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type stTransactionMarshaling struct {
|
type stTransactionMarshaling struct {
|
||||||
|
|
@ -241,7 +242,11 @@ func (tx *stTransaction) toMessage(ps stPostState, number *big.Int) (core.Messag
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("invalid tx data %q", dataHex)
|
return nil, fmt.Errorf("invalid tx data %q", dataHex)
|
||||||
}
|
}
|
||||||
msg := types.NewMessage(from, to, tx.Nonce, value, gasLimit, tx.GasPrice, nil, nil, data, nil, true, nil, number)
|
var accessList types.AccessList
|
||||||
|
if tx.AccessLists != nil && tx.AccessLists[ps.Indexes.Data] != nil {
|
||||||
|
accessList = *tx.AccessLists[ps.Indexes.Data]
|
||||||
|
}
|
||||||
|
msg := types.NewMessage(from, to, tx.Nonce, value, gasLimit, tx.GasPrice, nil, nil, data, accessList, true, nil, number)
|
||||||
return msg, nil
|
return msg, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue