git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit bc6f76ca178aa4920b10ba3bd729582dfcb4cff4

Interface: implement callCode

Alex Beregszaszi committed on 8/17/2016, 10:23:35 PM
Parent: d42548aec13093f0e30edf69632e67ad56a0cec2

Files changed

environment.jschanged
interface.jschanged
environment.jsView
@@ -52,8 +52,13 @@
5252 // STUB
5353 return // result
5454 }
5555
56+ callCode (gas, address, value, data) {
57+ // STUB
58+ return // result
59+ }
60+
5661 delegateCall (gas, address, data) {
5762 // STUB
5863 return // result
5964 }
interface.jsView
@@ -38,8 +38,9 @@
3838 'gasLimit',
3939 'log',
4040 'create',
4141 'call',
42+ 'callCode',
4243 'callDelegate',
4344 'sstore',
4445 'sload',
4546 'return',
@@ -310,8 +311,31 @@
310311 return errorCode
311312 }
312313
313314 /**
315+ * Message-call into this account with an alternative account’s code.
316+ * @param {integer} addressOffset the offset to load the address path from
317+ * @param {integer} valueOffset the offset to load the value from
318+ * @param {integer} dataOffset the offset to load data from
319+ * @param {integer} dataLength the length of data
320+ * @param {integer} resultOffset the offset to store the result data at
321+ * @param {integer} resultLength
322+ * @param {integer} gas
323+ * @return {integer} Returns 1 or 0 depending on if the VM trapped on the message or not
324+ * TODO: add proper gas counting
325+ */
326+ callCode (addressOffset, valueOffset, dataOffset, dataLength, resultOffset, resultLength, gas) {
327+ // Load the params from mem
328+ const address = new Address(this.getMemory(addressOffset, constants.ADDRESS_SIZE_BYTES))
329+ const value = new U256(this.getMemory(valueOffset, constants.BALANCE_SIZE_BYTES))
330+ const data = this.getMemory(dataOffset, dataLength)
331+ // Run the call
332+ const [result, errorCode] = this.environment.callCode(gas, address, value, data)
333+ this.setMemory(resultOffset, resultLength, result)
334+ return errorCode
335+ }
336+
337+ /**
314338 * Message-call into this account with an alternative account’s code, but
315339 * persisting the current values for sender and value.
316340 * @param {integer} gas
317341 * @param {integer} addressOffset the offset to load the address path from

Built with git-ssb-web