mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-18 09:53:48 +00:00
core/types: gencodec JSON marshalling for ReturnData struct
This commit is contained in:
parent
0cc11a6165
commit
3743b1fe50
2 changed files with 57 additions and 0 deletions
52
core/types/gen_return_data.go
Normal file
52
core/types/gen_return_data.go
Normal file
|
|
@ -0,0 +1,52 @@
|
||||||
|
// Code generated by github.com/fjl/gencodec. DO NOT EDIT.
|
||||||
|
|
||||||
|
package types
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
|
||||||
|
"github.com/ethereum/go-ethereum/common"
|
||||||
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||||
|
)
|
||||||
|
|
||||||
|
var _ = (*returnDataMarshaling)(nil)
|
||||||
|
|
||||||
|
// MarshalJSON marshals as JSON.
|
||||||
|
func (r ReturnData) MarshalJSON() ([]byte, error) {
|
||||||
|
type ReturnData struct {
|
||||||
|
TxHash common.Hash `json:"transactionHash" gencodec:"required"`
|
||||||
|
Data hexutil.Bytes `json:"returndata" gencodec:"required"`
|
||||||
|
Removed bool `json:"removed"`
|
||||||
|
}
|
||||||
|
var enc ReturnData
|
||||||
|
enc.TxHash = r.TxHash
|
||||||
|
enc.Data = r.Data
|
||||||
|
enc.Removed = r.Removed
|
||||||
|
return json.Marshal(&enc)
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnmarshalJSON unmarshals from JSON.
|
||||||
|
func (r *ReturnData) UnmarshalJSON(input []byte) error {
|
||||||
|
type ReturnData struct {
|
||||||
|
TxHash *common.Hash `json:"transactionHash" gencodec:"required"`
|
||||||
|
Data *hexutil.Bytes `json:"returndata" gencodec:"required"`
|
||||||
|
Removed *bool `json:"removed"`
|
||||||
|
}
|
||||||
|
var dec ReturnData
|
||||||
|
if err := json.Unmarshal(input, &dec); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if dec.TxHash == nil {
|
||||||
|
return errors.New("missing required field 'transactionHash' for ReturnData")
|
||||||
|
}
|
||||||
|
r.TxHash = *dec.TxHash
|
||||||
|
if dec.Data == nil {
|
||||||
|
return errors.New("missing required field 'returndata' for ReturnData")
|
||||||
|
}
|
||||||
|
r.Data = *dec.Data
|
||||||
|
if dec.Removed != nil {
|
||||||
|
r.Removed = *dec.Removed
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
@ -30,6 +30,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
//go:generate gencodec -type txdata -field-override txdataMarshaling -out gen_tx_json.go
|
//go:generate gencodec -type txdata -field-override txdataMarshaling -out gen_tx_json.go
|
||||||
|
//go:generate gencodec -type ReturnData -field-override returnDataMarshaling -out gen_return_data.go
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ErrInvalidSig = errors.New("invalid transaction v, r, s values")
|
ErrInvalidSig = errors.New("invalid transaction v, r, s values")
|
||||||
|
|
@ -92,6 +93,10 @@ type ReturnData struct {
|
||||||
Removed bool `json:"removed"`
|
Removed bool `json:"removed"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type returnDataMarshaling struct {
|
||||||
|
Data hexutil.Bytes
|
||||||
|
}
|
||||||
|
|
||||||
func NewTransaction(nonce uint64, to common.Address, amount *big.Int, gasLimit uint64, gasPrice *big.Int, data []byte) *Transaction {
|
func NewTransaction(nonce uint64, to common.Address, amount *big.Int, gasLimit uint64, gasPrice *big.Int, data []byte) *Transaction {
|
||||||
return newTransaction(nonce, &to, amount, gasLimit, gasPrice, data)
|
return newTransaction(nonce, &to, amount, gasLimit, gasPrice, data)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue