index.jsView |
---|
67 | 67 | |
68 | 68 | |
69 | 69 | if (address.isZero()) { |
70 | 70 | if (data.length !== 0) { |
71 | | - let codeHash = sha3(data) |
72 | | - this.environment.state.set(codeHash, data); |
73 | | - this.environment.state.set(address.toString(), { balance: value, codeHash: codeHash }) |
| 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 | + |
| 80 | + this.environment.state.set(address.toString(), account) |
74 | 81 | } |
75 | 82 | } |
76 | 83 | |
77 | 84 | let account = this.environment.state.get(address.toString()) |
78 | 85 | if (!account) { |
79 | 86 | throw new Error('Account not found') |
80 | 87 | } |
81 | 88 | |
82 | | - const code = this.environment.state.get(account.codeHash) |
83 | | - |
84 | | - if (!code) { |
| 89 | + const code = Uint8Array.from(account.get('code')) |
| 90 | + if (code.length === 0) { |
85 | 91 | throw new Error('Contract not found') |
86 | 92 | } |
87 | 93 | |
88 | 94 | if (!Utils.isWASMCode(code)) { |
136 | 142 | throw new Error('Sender account not found') |
137 | 143 | } |
138 | 144 | |
139 | 145 | |
140 | | - if (fromAccount.balance.lt(tx.gasLimit.mul(tx.gasPrice))) { |
141 | | - throw new Error('Insufficient account balance') |
| 146 | + if (fromAccount.get('balance').lt(tx.gasLimit.mul(tx.gasPrice))) { |
| 147 | + throw new Error(`Insufficient account balance: ${fromAccount.get('balance').toString()} < ${tx.gasLimit.mul(tx.gasPrice).toString()}`) |
142 | 148 | } |
143 | 149 | |
144 | | - fromAccount.balance = fromAccount.balance.sub(ts.gasLimit.mul(tx.gasPrice)) |
| 150 | + fromAccount.set('balance', fromAccount.get('balance').sub(tx.gasLimit.mul(tx.gasPrice))) |
145 | 151 | |
146 | 152 | let ret = this.callHandler(tx.to, tx.gasLimit, tx.gasPrice, tx.value, tx.data) |
147 | 153 | |
148 | 154 | |
149 | 155 | if (ret.executionOutcome === 1) { |
150 | | - fromAccount.balance = fromAccount.balance.add(tx.gasPrice.mul(ret.gasLeft.add(ret.gasRefund))) |
| 156 | + fromAccount.set('balance', fromAccount.get('balance').add(tx.gasPrice.mul(ret.gasLeft.add(ret.gasRefund)))) |
151 | 157 | } |
152 | 158 | |
153 | 159 | |
154 | 160 | |