Solidity - 使用webpack app时{EVM无效JUMP

时间:2017-04-17 10:39:42

标签: javascript solidity distributed-apps

我正在创建一个基于Truffle + Webpack的前端应用程序,遵循此tuto:http://truffleframework.com/tutorials/building-testing-frontend-app-truffle-3,并且根本不了解JavaScript。

代码适用于松露控制台,应用程序全局工作,除了函数" append_buy_brent",将新元素添加到名为buy_orderbook_brent的结构数组

Solidity:

contract Petroleum{


// Initialisations

address _creator;
uint user_number;


struct Baril_order {
    uint price;
    uint quantity;
    address addr;
}

Baril_order[] buy_orderbook_brent;

mapping(address => uint) account_map;
mapping(uint => uint) user_balance;
mapping(uint => uint) number_of_brent;

function Petroleum() payable{       

    _creator=msg.sender;
    user_number=0;
    test=0;

    account_map[_creator]=0;
    account_map[0x7f8105da4dd1af61da7bf587766103ba8534fcdc]=1;

    user_balance[account_map[msg.sender]]=100000;
    number_of_brent[account_map[msg.sender]]=5;
    number_of_wti[account_map[msg.sender]]=2;
    debt[account_map[msg.sender]]=20;
    user_balance[account_map[0x7f8105da4dd1af61da7bf587766103ba8534fcdc]]=200000;
    number_of_brent[account_map[0x7f8105da4dd1af61da7bf587766103ba8534fcdc]]=7;
    number_of_wti[account_map[0x7f8105da4dd1af61da7bf587766103ba8534fcdc]]=10;
    debt[account_map[0x7f8105da4dd1af61da7bf587766103ba8534fcdc]]=3;
}

function append_buy_brent(uint price, uint quantity, address addr) payable {
        buy_orderbook_brent.push(
            Baril_order({
                price:price,
                quantity: quantity,
                addr: addr,
            })
        );
    }
}

JavaScript:

import { default as Web3} from 'web3';
import { default as contract } from 'truffle-contract'
import Petroleum_artifacts from '../../build/contracts/Petroleum.json'
var Petroleum = contract(Petroleum_artifacts);

var accounts;
var account;
var account1;

window.App = {
start: function() {
    var self = this;

    Petroleum.setProvider(web3.currentProvider);

    web3.eth.getAccounts(function(err, accs) {
      if (err != null) {
        alert("There was an error fetching your accounts.");
        return;
      }

      if (accs.length == 0) {
        alert("Couldn't get any accounts! Make sure your Ethereum client is configured correctly.");
        return;
      }

      accounts = accs;
      account = accounts[0];
      account1 = accounts[1];

      self.refreshBalance1();
      self.refreshBalance2();
    });
  },

append_buy_brent: function(){
        var self = this;

var price_buy_brent= parseInt(document.getElementById("price_buy_brent").value);
        var quantity_buy_brent=parseInt(document.getElementById("quantity_buy_brent").value);

        this.setStatus("Initiating transaction... (please wait)");

        var petro;

        Petroleum.deployed().then(function(instance) {
          petro = instance;
          return petro.append_buy_brent(price_buy_brent,quantity_buy_brent, account, {from: account, value: web3.toWei(1000, "ether")});
        }).then(function(value) {
            self.setStatus("Transaction complete!");
            self.refreshBalance1();
            self.refreshBalance2();
        }).catch(function(e) {
          console.log(e);
          self.setStatus("Error placing buy_brent; see log.");
        });
     },
}

记录:

  

错误:处理事务时出现VM异常:JUMP无效   d8abbe98e23bfa2cd66729f537c8dd23bb72c25425af350243627a30533c3b73 / a8c9aca1a9b5fd638a6aa025545e1274787f3456:790

我希望我第一次在这里提供足够的信息。非常感谢。

1 个答案:

答案 0 :(得分:0)

它看起来像一个EVM错误。您可以尝试不将合同部署和函数调用放在两个不同的事务中吗?

https://github.com/ethereumjs/testrpc/issues/196