transaction.jsView |
---|
| 1 | + |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | +const Address = require('./address.js') |
| 8 | +const U256 = require('./u256.js') |
| 9 | +const ethUtils = require('ethereumjs-util') |
| 10 | +const ethTx = require('ethereumjs-tx') |
| 11 | + |
| 12 | +module.exports = class Transaction { |
| 13 | + constructor (tx) { |
| 14 | + this._tx = new ethTx(tx) |
| 15 | + } |
| 16 | + |
| 17 | + get valid () { |
| 18 | + return this._tx.verifySignature() |
| 19 | + } |
| 20 | + |
| 21 | + get nonce () { |
| 22 | + return new U256(this._tx.nonce) |
| 23 | + } |
| 24 | + |
| 25 | + get gasPrice () { |
| 26 | + return new U256(this._tx.gasPrice) |
| 27 | + } |
| 28 | + |
| 29 | + get gasLimit () { |
| 30 | + return new U256(this._tx.gasLimit) |
| 31 | + } |
| 32 | + |
| 33 | + get value () { |
| 34 | + return new U256(this._tx.value) |
| 35 | + } |
| 36 | + |
| 37 | + get data () { |
| 38 | + return this._tx.data |
| 39 | + } |
| 40 | + |
| 41 | + get from () { |
| 42 | + return new Address(this._tx.getSenderAddress()) |
| 43 | + } |
| 44 | + |
| 45 | + get to () { |
| 46 | + if (this._tx.to.length === 0) { |
| 47 | + return new Address('0x0000000000000000000000000000000000000000') |
| 48 | + } |
| 49 | + return new Address(this._tx.to) |
| 50 | + } |
| 51 | + |
| 52 | + get isSend () { |
| 53 | + } |
| 54 | + |
| 55 | + get isContractCall () { |
| 56 | + } |
| 57 | + |
| 58 | + get isContractDeployment () { |
| 59 | + } |
| 60 | +} |