From b6b5ec8f75502df65a44cea4f4c07cc28231027c Mon Sep 17 00:00:00 2001 From: Péter Szilágyi Date: Thu, 8 Sep 2016 18:16:53 +0300 Subject: core/types: add core type marshal methods too --- core/types/transaction.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'core/types/transaction.go') 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 -- cgit