core/types: gencodec JSON marshalling for ReturnData struct

This commit is contained in:
Domino Valdano 2018-04-16 22:43:37 -07:00
parent 0cc11a6165
commit 3743b1fe50
No known key found for this signature in database
GPG key ID: 3FDFE30EE92AC05E
2 changed files with 57 additions and 0 deletions

View 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
}

View file

@ -30,6 +30,7 @@ import (
)
//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 (
ErrInvalidSig = errors.New("invalid transaction v, r, s values")
@ -92,6 +93,10 @@ type ReturnData struct {
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 {
return newTransaction(nonce, &to, amount, gasLimit, gasPrice, data)
}