git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit ffe3b1001d995030b9b814805b54e159d5d388eb

Add transaction parser API

Alex Beregszaszi committed on 8/17/2016, 2:14:35 AM
Parent: fd26631fcd9d58a023da60ee87d85bc063953cff

Files changed

package.jsonchanged
transaction.jsadded
package.jsonView
@@ -36,7 +36,8 @@
3636 ]
3737 },
3838 "dependencies": {
3939 "bn.js": "^4.11.6",
40+ "ethereumjs-tx": "^1.1.2",
4041 "ethereumjs-util": "^4.5.0"
4142 }
4243 }
transaction.jsView
@@ -1,0 +1,60 @@
1+//
2+// This class parses a serialised Ethereum transaction
3+//
4+// The input is a Buffer.
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+}

Built with git-ssb-web