Commit 05bf86af31b825ac9b412fbc4b18522d2b40e829
Kernel: split createHandler out of runTx
Alex Beregszaszi committed on 8/26/2016, 9:40:45 PMParent: 35fc7a2516bd2641e4b9bb32ebdaed256fe57491
Files changed
index.js | changed |
index.js | ||
---|---|---|
@@ -105,9 +105,10 @@ | ||
105 | 105 | environment.callData = call.data |
106 | 106 | environment.callValue = call.value |
107 | 107 | environment.gasLeft = call.gasLimit |
108 | 108 | |
109 | - // environment.setCallHandler(callHandler) | |
109 | + // environment.setCallHandler(this.callHandler) | |
110 | + // environment.setCreateHandler(this.createHandler) | |
110 | 111 | |
111 | 112 | const kernel = new Kernel(this, environment) |
112 | 113 | kernel.codeHandler(code, new Interface(environment)) |
113 | 114 | |
@@ -123,8 +124,24 @@ | ||
123 | 124 | logs: environment.logs |
124 | 125 | } |
125 | 126 | } |
126 | 127 | |
128 | + createHandler (create) { | |
129 | + // Inject metering | |
130 | + const code = this.callHandler({ to: meteringContract, data: create.data }).returnValue | |
131 | + | |
132 | + let address = Utils.newAccountAddress(create.from, code) | |
133 | + | |
134 | + this.environment.addAccount(address.toString(), { | |
135 | + balance: create.value, | |
136 | + code: code | |
137 | + }) | |
138 | + | |
139 | + return { | |
140 | + accountCreated: address | |
141 | + } | |
142 | + } | |
143 | + | |
127 | 144 | // run tx; the tx message handler |
128 | 145 | runTx (tx, environment = new Environment()) { |
129 | 146 | this.environment = environment |
130 | 147 | |
@@ -151,23 +168,16 @@ | ||
151 | 168 | if (tx.to.isZero()) { |
152 | 169 | if (tx.data.length !== 0) { |
153 | 170 | console.log('This is a contract deployment transaction') |
154 | 171 | |
155 | - // Inject metering | |
156 | - const code = this.callHandler({ to: meteringContract, data: tx.data }).returnValue | |
172 | + // FIXME: deduct fees | |
157 | 173 | |
158 | - let address = Utils.newAccountAddress(tx.from, code) | |
159 | - | |
160 | - this.environment.addAccount(address.toString(), { | |
161 | - balance: tx.value, | |
162 | - code: code | |
174 | + return this.createHandler({ | |
175 | + from: tx.from, | |
176 | + gasLimit: tx.gasLimit, | |
177 | + value: tx.value, | |
178 | + data: txdata | |
163 | 179 | }) |
164 | - | |
165 | - // FIXME: deduct fees | |
166 | - | |
167 | - return { | |
168 | - accountCreated: address | |
169 | - } | |
170 | 180 | } |
171 | 181 | } |
172 | 182 | |
173 | 183 | // deduct gasLimit * gasPrice from sender |
Built with git-ssb-web