Commit 9ab801b3372e1e99fdac810e1d108dffbf2dff34
Merge pull request #35 from ewasm/address
Address: revert 78a0cad until Node.js is fixedwanderer authored on 8/23/2016, 10:16:50 PM
GitHub committed on 8/23/2016, 10:16:50 PM
Parent: 0031bf1b8a9976595e38cc4e2b49124a79ff927d
Parent: c83dccd5d95b611b7a0810479c3516f920ca2146
Files changed
address.js | changed |
interface.js | changed |
address.js | ||
---|---|---|
@@ -1,31 +1,41 @@ | ||
1 | 1 | const ethUtil = require('ethereumjs-util') |
2 | 2 | |
3 | -module.exports = class Address extends Buffer { | |
3 | +module.exports = class Address { | |
4 | 4 | constructor (value) { |
5 | - if (value instanceof Address || value instanceof Uint8Array) { | |
6 | - super(value) | |
5 | + // Special case: duplicate | |
6 | + if (value instanceof Address) { | |
7 | + this._value = new Buffer(value._value) | |
8 | + return | |
9 | + } | |
10 | + | |
11 | + if (value instanceof Uint8Array) { | |
12 | + this._value = new Buffer(value) | |
7 | 13 | } else if (typeof value !== 'string') { |
8 | 14 | throw new Error('Invalid input to address') |
9 | 15 | } else if (!ethUtil.isHexPrefixed(value)) { |
10 | 16 | throw new Error('Invalid address format') |
11 | 17 | } else { |
12 | - super(ethUtil.stripHexPrefix(value), 'hex') | |
18 | + this._value = new Buffer(ethUtil.stripHexPrefix(value), 'hex') | |
13 | 19 | } |
14 | 20 | |
15 | - if (this.length !== 20) { | |
21 | + if (this._value.length !== 20) { | |
16 | 22 | throw new Error('Invalid address length') |
17 | 23 | } |
18 | 24 | } |
19 | 25 | |
26 | + toBuffer () { | |
27 | + return this._value | |
28 | + } | |
29 | + | |
20 | 30 | toString () { |
21 | - return '0x' + this.toString('hex') | |
31 | + return '0x' + this._value.toString('hex') | |
22 | 32 | } |
23 | 33 | |
24 | 34 | isZero () { |
25 | - return this.every((el) => el === 0) | |
35 | + return this._value.equals(ethUtil.zeros(20)) | |
26 | 36 | } |
27 | 37 | |
28 | 38 | equals (address) { |
29 | - return this.toString('hex') === address.toBuffer().toString('hex') | |
39 | + return this._value.toString('hex') === address.toBuffer().toString('hex') | |
30 | 40 | } |
31 | 41 | } |
interface.js | ||
---|---|---|
@@ -86,9 +86,9 @@ | ||
86 | 86 | */ |
87 | 87 | getAddress (offset) { |
88 | 88 | this.takeGas(2) |
89 | 89 | |
90 | - this.setMemory(offset, constants.ADDRESS_SIZE_BYTES, this.environment.address) | |
90 | + this.setMemory(offset, constants.ADDRESS_SIZE_BYTES, this.environment.address.toBuffer()) | |
91 | 91 | } |
92 | 92 | |
93 | 93 | /** |
94 | 94 | * Gets balance of the given account and loads it into memory at the given |
@@ -113,9 +113,9 @@ | ||
113 | 113 | */ |
114 | 114 | getTxOrigin (offset) { |
115 | 115 | this.takeGas(2) |
116 | 116 | |
117 | - this.setMemory(offset, constants.ADDRESS_SIZE_BYTES, this.environment.origin) | |
117 | + this.setMemory(offset, constants.ADDRESS_SIZE_BYTES, this.environment.origin.toBuffer()) | |
118 | 118 | } |
119 | 119 | |
120 | 120 | /** |
121 | 121 | * Gets caller address and loads it into memory at the given offset. This is |
@@ -124,9 +124,9 @@ | ||
124 | 124 | */ |
125 | 125 | getCaller (offset) { |
126 | 126 | this.takeGas(2) |
127 | 127 | |
128 | - this.setMemory(offset, constants.ADDRESS_SIZE_BYTES, this.environment.caller) | |
128 | + this.setMemory(offset, constants.ADDRESS_SIZE_BYTES, this.environment.caller.toBuffer()) | |
129 | 129 | } |
130 | 130 | |
131 | 131 | /** |
132 | 132 | * Gets the deposited value by the instruction/transaction responsible for |
@@ -264,9 +264,9 @@ | ||
264 | 264 | */ |
265 | 265 | getBlockCoinbase (offset) { |
266 | 266 | this.takeGas(2) |
267 | 267 | |
268 | - this.setMemory(offset, constants.ADDRESS_SIZE_BYTES, this.environment.block.coinbase) | |
268 | + this.setMemory(offset, constants.ADDRESS_SIZE_BYTES, this.environment.block.coinbase.toBuffer()) | |
269 | 269 | } |
270 | 270 | |
271 | 271 | /** |
272 | 272 | * Get the block’s timestamp. |
Built with git-ssb-web