aboutsummaryrefslogtreecommitdiffstats
path: root/core/types/transaction.go
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2016-09-08 23:16:53 +0800
committerPéter Szilágyi <peterke@gmail.com>2016-09-08 23:16:53 +0800
commitb6b5ec8f75502df65a44cea4f4c07cc28231027c (patch)
tree267cedf7a6b18c386a715b367207e4da238b40fc /core/types/transaction.go
parentca37730c9ddf8b3b7e59abc95f462de54ac9457e (diff)
downloadgo-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.go18
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