git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit 04af14cd7056250c22a08f3950f10cfa2dcbb8c8

Kernel: move contract creation to the correct location

Alex Beregszaszi committed on 8/23/2016, 12:27:46 AM
Parent: 37461769a82fe6533209cae948cd10a1cd8789bf

Files changed

index.jschanged
index.jsView
@@ -63,25 +63,8 @@
6363 // Detects if code is EVM or WASM
6464 // Detects if the code injection is needed
6565 // Detects if transcompilation is needed
6666 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-
8467 let account = this.environment.state.get(address.toString())
8568 if (!account) {
8669 throw new Error('Account not found')
8770 }
@@ -141,8 +124,32 @@
141124 if (!fromAccount) {
142125 throw new Error('Sender account not found')
143126 }
144127
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+
145152 // deduct gasLimit * gasPrice from sender
146153 if (fromAccount.get('balance').lt(tx.gasLimit.mul(tx.gasPrice))) {
147154 throw new Error(`Insufficient account balance: ${fromAccount.get('balance').toString()} < ${tx.gasLimit.mul(tx.gasPrice).toString()}`)
148155 }

Built with git-ssb-web