0

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

代码在 truffle 控制台上运行,应用程序在全局范围内运行,除了函数“append_buy_brent”,将一个新元素添加到一个名为 buy_orderbook_brent 的结构数组中

坚固性:

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 异常:d8abbe98e23bfa2cd66729f537c8dd23bb72c25425af350243627a30533c3b73/a8c9aca1a9b5fd638a6aa025545e1274787f3456:790 处的无效跳转

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

4

1 回答 1

0

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

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

于 2017-05-03T05:10:55.790 回答