Commit 04af14cd7056250c22a08f3950f10cfa2dcbb8c8
Kernel: move contract creation to the correct location
Alex Beregszaszi committed on 8/23/2016, 12:27:46 AMParent: 37461769a82fe6533209cae948cd10a1cd8789bf
Files changed
index.js | changed |
index.js | ||
---|---|---|
@@ -63,25 +63,8 @@ | ||
63 | 63 | // Detects if code is EVM or WASM |
64 | 64 | // Detects if the code injection is needed |
65 | 65 | // Detects if transcompilation is needed |
66 | 66 | callHandler (address, gaslimit, gasprice, value, data) { |
67 | - // Special case: contract deployment | |
68 | - // FIXME: place this in the best location with the best condition checking | |
69 | - if (address.isZero()) { | |
70 | - if (data.length !== 0) { | |
71 | - console.log('This is a contract deployment transaction') | |
72 | - | |
73 | - let account = new Map() | |
74 | - account.set('nonce', new U256(0)) | |
75 | - account.set('balance', value) | |
76 | - account.set('code', data) | |
77 | - account.set('storage', new Map()) | |
78 | - | |
79 | - // FIXME: calculate the contract address | |
80 | - this.environment.state.set(address.toString(), account) | |
81 | - } | |
82 | - } | |
83 | - | |
84 | 67 | let account = this.environment.state.get(address.toString()) |
85 | 68 | if (!account) { |
86 | 69 | throw new Error('Account not found') |
87 | 70 | } |
@@ -141,8 +124,32 @@ | ||
141 | 124 | if (!fromAccount) { |
142 | 125 | throw new Error('Sender account not found') |
143 | 126 | } |
144 | 127 | |
128 | + // Special case: contract deployment | |
129 | + if (tx.to.isZero()) { | |
130 | + if (tx.data.length !== 0) { | |
131 | + console.log('This is a contract deployment transaction') | |
132 | + | |
133 | + let account = new Map() | |
134 | + account.set('nonce', new U256(0)) | |
135 | + account.set('balance', tx.value) | |
136 | + account.set('code', tx.data) | |
137 | + account.set('storage', new Map()) | |
138 | + | |
139 | + // FIXME: calculate the contract address | |
140 | + let address = tx.to | |
141 | + | |
142 | + this.environment.state.set(address.toString(), account) | |
143 | + | |
144 | + // FIXME: deduct fees | |
145 | + | |
146 | + return { | |
147 | + accountCreated: address | |
148 | + } | |
149 | + } | |
150 | + } | |
151 | + | |
145 | 152 | // deduct gasLimit * gasPrice from sender |
146 | 153 | if (fromAccount.get('balance').lt(tx.gasLimit.mul(tx.gasPrice))) { |
147 | 154 | throw new Error(`Insufficient account balance: ${fromAccount.get('balance').toString()} < ${tx.gasLimit.mul(tx.gasPrice).toString()}`) |
148 | 155 | } |
Built with git-ssb-web