git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit c83dccd5d95b611b7a0810479c3516f920ca2146

Address: revert 78a0cad until Node.js is fixed

Alex Beregszaszi committed on 8/23/2016, 1:52:07 AM
Parent: 0031bf1b8a9976595e38cc4e2b49124a79ff927d

Files changed

address.jschanged
interface.jschanged
address.jsView
@@ -1,31 +1,41 @@
11 const ethUtil = require('ethereumjs-util')
22
3-module.exports = class Address extends Buffer {
3+module.exports = class Address {
44 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)
713 } else if (typeof value !== 'string') {
814 throw new Error('Invalid input to address')
915 } else if (!ethUtil.isHexPrefixed(value)) {
1016 throw new Error('Invalid address format')
1117 } else {
12- super(ethUtil.stripHexPrefix(value), 'hex')
18+ this._value = new Buffer(ethUtil.stripHexPrefix(value), 'hex')
1319 }
1420
15- if (this.length !== 20) {
21+ if (this._value.length !== 20) {
1622 throw new Error('Invalid address length')
1723 }
1824 }
1925
26+ toBuffer () {
27+ return this._value
28+ }
29+
2030 toString () {
21- return '0x' + this.toString('hex')
31+ return '0x' + this._value.toString('hex')
2232 }
2333
2434 isZero () {
25- return this.every((el) => el === 0)
35+ return this._value.equals(ethUtil.zeros(20))
2636 }
2737
2838 equals (address) {
29- return this.toString('hex') === address.toBuffer().toString('hex')
39+ return this._value.toString('hex') === address.toBuffer().toString('hex')
3040 }
3141 }
interface.jsView
@@ -86,9 +86,9 @@
8686 */
8787 getAddress (offset) {
8888 this.takeGas(2)
8989
90- this.setMemory(offset, constants.ADDRESS_SIZE_BYTES, this.environment.address)
90+ this.setMemory(offset, constants.ADDRESS_SIZE_BYTES, this.environment.address.toBuffer())
9191 }
9292
9393 /**
9494 * Gets balance of the given account and loads it into memory at the given
@@ -113,9 +113,9 @@
113113 */
114114 getTxOrigin (offset) {
115115 this.takeGas(2)
116116
117- this.setMemory(offset, constants.ADDRESS_SIZE_BYTES, this.environment.origin)
117+ this.setMemory(offset, constants.ADDRESS_SIZE_BYTES, this.environment.origin.toBuffer())
118118 }
119119
120120 /**
121121 * Gets caller address and loads it into memory at the given offset. This is
@@ -124,9 +124,9 @@
124124 */
125125 getCaller (offset) {
126126 this.takeGas(2)
127127
128- this.setMemory(offset, constants.ADDRESS_SIZE_BYTES, this.environment.caller)
128+ this.setMemory(offset, constants.ADDRESS_SIZE_BYTES, this.environment.caller.toBuffer())
129129 }
130130
131131 /**
132132 * Gets the deposited value by the instruction/transaction responsible for
@@ -264,9 +264,9 @@
264264 */
265265 getBlockCoinbase (offset) {
266266 this.takeGas(2)
267267
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())
269269 }
270270
271271 /**
272272 * Get the block’s timestamp.

Built with git-ssb-web