Commit e7e36382dc9e3373aad516a7c37df5e4fa7554a6
Kernel: use Frontier-style address generation for accounts
Alex Beregszaszi committed on 8/26/2016, 11:41:38 PMParent: 3cb8a54180de3ba70e81bfebcd2e944557d99715
Files changed
index.js | changed |
utils.js | changed |
index.js | ||
---|---|---|
@@ -134,10 +134,15 @@ | ||
134 | 134 | // FIXME: decide if these are the right values here: from: 0, gasLimit: 0, value: 0 |
135 | 135 | code = this.callHandler({ from: Address.zero(), to: meteringContract, gasLimit: 0, value: new U256(0), data: code }).returnValue |
136 | 136 | } |
137 | 137 | |
138 | - let address = Utils.newAccountAddress(create.from, code) | |
138 | + let account = this.environment.state.get(create.from.toString()) | |
139 | + if (!account) { | |
140 | + throw new Error('Account not found: ' + create.from.toString()) | |
141 | + } | |
139 | 142 | |
143 | + let address = Utils.newAccountAddress(create.from, account.get('nonce')) | |
144 | + | |
140 | 145 | this.environment.addAccount(address.toString(), { |
141 | 146 | balance: create.value, |
142 | 147 | code: code |
143 | 148 | }) |
utils.js | ||
---|---|---|
@@ -6,9 +6,9 @@ | ||
6 | 6 | Utils.isWASMCode = function (code) { |
7 | 7 | return code.slice(0, 4).toString() === new Uint8Array([0, 0x61, 0x73, 0x6d]).toString() |
8 | 8 | } |
9 | 9 | |
10 | -Utils.newAccountAddress = function (sender, data) { | |
11 | - return new Address('0x' + ethUtil.sha3(Buffer.concat([ sender.toBuffer(), Buffer.from(data) ])).slice(0, 20).toString('hex')) | |
10 | +Utils.newAccountAddress = function (sender, nonce) { | |
11 | + return new Address('0x' + ethUtil.generateAddress(sender.toString(), nonce.toString()).toString('hex')) | |
12 | 12 | } |
13 | 13 | |
14 | 14 | module.exports = Utils |
Built with git-ssb-web