Commit 48ac29e384052f91a71431f96b509f0fe11684fb
Merge pull request #44 from ewasm/frontier-address-gen
Kernel: use Frontier-style address generation for accountswanderer authored on 10/6/2016, 8:28:45 AM
GitHub committed on 10/6/2016, 8:28:45 AM
Parent: a9ce2e3d2d7449ca0005d46cb47468fcfaf15223
Parent: e7e36382dc9e3373aad516a7c37df5e4fa7554a6
Files changed
index.js | changed |
utils.js | changed |
index.js | ||
---|---|---|
@@ -168,10 +168,15 @@ | ||
168 | 168 | throw new Error('Metering injection failed: ' + Buffer.from(code).slice(1).toString()) |
169 | 169 | } |
170 | 170 | } |
171 | 171 | |
172 | - let address = Utils.newAccountAddress(create.from, code) | |
172 | + let account = this.environment.state.get(create.from.toString()) | |
173 | + if (!account) { | |
174 | + throw new Error('Account not found: ' + create.from.toString()) | |
175 | + } | |
173 | 176 | |
177 | + let address = Utils.newAccountAddress(create.from, account.get('nonce')) | |
178 | + | |
174 | 179 | this.environment.addAccount(address.toString(), { |
175 | 180 | balance: create.value, |
176 | 181 | code: code |
177 | 182 | }) |
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