git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit 48ac29e384052f91a71431f96b509f0fe11684fb

Merge pull request #44 from ewasm/frontier-address-gen

Kernel: use Frontier-style address generation for accounts
wanderer 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.jschanged
utils.jschanged
index.jsView
@@ -168,10 +168,15 @@
168168 throw new Error('Metering injection failed: ' + Buffer.from(code).slice(1).toString())
169169 }
170170 }
171171
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+ }
173176
177+ let address = Utils.newAccountAddress(create.from, account.get('nonce'))
178+
174179 this.environment.addAccount(address.toString(), {
175180 balance: create.value,
176181 code: code
177182 })
utils.jsView
@@ -6,9 +6,9 @@
66 Utils.isWASMCode = function (code) {
77 return code.slice(0, 4).toString() === new Uint8Array([0, 0x61, 0x73, 0x6d]).toString()
88 }
99
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'))
1212 }
1313
1414 module.exports = Utils

Built with git-ssb-web