diff options
author | Péter Szilágyi <peterke@gmail.com> | 2016-09-08 23:16:53 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2016-09-08 23:16:53 +0800 |
commit | b6b5ec8f75502df65a44cea4f4c07cc28231027c (patch) | |
tree | 267cedf7a6b18c386a715b367207e4da238b40fc /core/types/transaction.go | |
parent | ca37730c9ddf8b3b7e59abc95f462de54ac9457e (diff) | |
download | go-tangerine-b6b5ec8f75502df65a44cea4f4c07cc28231027c.tar.gz go-tangerine-b6b5ec8f75502df65a44cea4f4c07cc28231027c.tar.zst go-tangerine-b6b5ec8f75502df65a44cea4f4c07cc28231027c.zip |
core/types: add core type marshal methods too
Diffstat (limited to 'core/types/transaction.go')
-rw-r--r-- | core/types/transaction.go | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/core/types/transaction.go b/core/types/transaction.go index 5bb599479..f0512ae7e 100644 --- a/core/types/transaction.go +++ b/core/types/transaction.go @@ -128,6 +128,24 @@ func (tx *Transaction) DecodeRLP(s *rlp.Stream) error { return err } +// MarshalJSON encodes transactions into the web3 RPC response block format. +func (tx *Transaction) MarshalJSON() ([]byte, error) { + hash, v := tx.Hash(), uint64(tx.data.V) + + return json.Marshal(&jsonTransaction{ + Hash: &hash, + AccountNonce: (*hexUint64)(&tx.data.AccountNonce), + Price: (*hexBig)(tx.data.Price), + GasLimit: (*hexBig)(tx.data.GasLimit), + Recipient: tx.data.Recipient, + Amount: (*hexBig)(tx.data.Amount), + Payload: (*hexBytes)(&tx.data.Payload), + V: (*hexUint64)(&v), + R: (*hexBig)(tx.data.R), + S: (*hexBig)(tx.data.S), + }) +} + // UnmarshalJSON decodes the web3 RPC transaction format. func (tx *Transaction) UnmarshalJSON(input []byte) error { var dec jsonTransaction |