Beispiel #1
0
 function loadToAccount () {
   // get receiver's account
   if (!toAddress) {
     // generate a new contract if no `to`
     code = txData
     txData = undefined
     var newNonce = new BN(account.nonce).subn(1)
     createdAddress = toAddress = ethUtil.generateAddress(caller, newNonce.toArray())
     toAccount = new Account()
   } else {
     // else load the `to` account
     toAccount = stateManager.cache.get(toAddress)
   }
 }
    async exec(conn, payload) {
        const txHash = payload.params[0];

        // Sends regular eth_getTransactionReceipt request
        const ret = await conn.socket.send(payload, {
            fullResult: true
        });

        // If that contains a contractAddress already, fine.
        if (ret.result.result.contractAddress != null) {
            return ret.result;
        }

        // Due to a geth's light client v1 bug, it does not return
        // contractAddress value on the receipts. Let's fix that.
        // 1. GET TRANSACTION from AND nonce VALUES
        const transactionInfo = await conn.socket.send({
            jsonrpc: '2.0',
            id: _.uuid(),
            method: 'eth_getTransactionByHash',
            params: [txHash]
        }, { fullResult: true });


        const fromAddress = transactionInfo.result.result.from;
        const nonce = parseInt(transactionInfo.result.result.nonce, 16);
        const possibleContractAddress = `0x${eth.generateAddress(fromAddress, nonce).toString('hex')}`;


        // 2. GET CODE FROM ADDRESS
        const contractCode = await conn.socket.send({
            jsonrpc: '2.0',
            id: _.uuid(),
            method: 'eth_getCode',
            params: [possibleContractAddress, 'latest']
        }, { fullResult: true });
        const contractCodeResult = contractCode.result.result;

        // 3. IF IT EXISTS, ASSIGN TO RETURN VALUE
        if (contractCodeResult && contractCodeResult.length > 2) {
            ret.result.result.contractAddress = possibleContractAddress;
        }

        return ret.result;
    }
Beispiel #3
0
 function loadToAccount (done) {
   // get receiver's account
   // toAccount = stateManager.cache.get(toAddress)
   if (!toAddress) {
     // generate a new contract if no `to`
     code = txData
     txData = undefined
     var newNonce = new BN(account.nonce).subn(1)
     createdAddress = toAddress = ethUtil.generateAddress(caller, newNonce.toArray())
     stateManager.getAccount(createdAddress, function (err, account) {
       toAccount = account
       done(err)
     })
   } else {
     // else load the `to` account
     toAccount = stateManager.cache.get(toAddress)
     done()
   }
 }
Beispiel #4
0
  /**
   * Creates a new contract with a given value.
   * @param {integer} valueOffset the offset in memory to the value from
   * @param {integer} dataOffset the offset to load the code for the new contract from
   * @param {integer} length the data length
   * @param (integer} resultOffset the offset to write the new contract address to
   * @return {integer} Return 1 or 0 depending on if the VM trapped on the message or not
   */
  create (valueOffset, dataOffset, length, resultOffset, cbIndex) {
    log.debug('EVMImports.js create')
    this.takeGas(32000)

    const value = U256.fromMemory(this.getMemory(valueOffset, U128_SIZE_BYTES))
    // if (length) {
    //   const code = this.getMemory(dataOffset, length).slice(0)
    // }

    let opPromise

    if (value.gt(this.kernel.environment.value)) {
      opPromise = Promise.resolve(Buffer.alloc(20))
    } else {
      // todo actully run the code
      opPromise = Promise.resolve(ethUtil.generateAddress(this.kernel.environment.address, this.kernel.environment.nonce))
    }

    // wait for all the prevouse async ops to finish before running the callback
    this.kernel.pushOpsQueue(opPromise, cbIndex, address => {
      this.setMemory(resultOffset, ADDRESS_SIZE_BYTES, address)
    })
  }
Beispiel #5
0
 determineAddress: function (sender, nonce) {
   return ethJsUtil.bufferToHex(ethJsUtil.generateAddress(
     sender,
     nonce
   ));
 },