git ssb

0+

wanderer🌟 / js-primea-hypervisor



Tree: c8eec344b7def6dcff0d4682d181e6324d80b6b8

Files: c8eec344b7def6dcff0d4682d181e6324d80b6b8 / transaction.js

905 bytesRaw
1//
2// This class parses a serialised Ethereum transaction
3//
4// The input is a Buffer.
5//
6const Address = require('./address.js')
7const U256 = require('./u256.js')
8const OldTx = require('ethereumjs-tx')
9
10module.exports = class Transaction {
11 constructor (tx) {
12 this._tx = new OldTx(tx)
13 }
14
15 get valid () {
16 return this._tx.verifySignature()
17 }
18
19 get nonce () {
20 return new U256(this._tx.nonce)
21 }
22
23 get gasPrice () {
24 return new U256(this._tx.gasPrice)
25 }
26
27 get gasLimit () {
28 return new U256(this._tx.gasLimit)
29 }
30
31 get value () {
32 return new U256(this._tx.value)
33 }
34
35 get data () {
36 return Uint8Array.from(this._tx.data)
37 }
38
39 get from () {
40 return new Address(this._tx.getSenderAddress())
41 }
42
43 get to () {
44 if (this._tx.to.length === 0) {
45 return new Address('0x0000000000000000000000000000000000000000')
46 }
47 return new Address(this._tx.to)
48 }
49}
50

Built with git-ssb-web