供气资金不足*价格+ Java中的值错误

时间:2019-10-02 07:06:42

标签: java oracle transactions blockchain solidity

当我在添加交易时将合同部署在区块链上时,会产生错误...

private static final Web3j web3j = Web3j.build(new HttpService("HTTPS://ropsten.infura.io/v3/d11459c1c17049628f462a1492c7df36"));

private static final Credentials hostCredentials = Credentials.create("666A82FC33F8134577A7BEB1BDEAA689BB72740178727691D63032432B83E0FB");

private static final BigInteger gasLimit = BigInteger.valueOf(4712388L);
private static final BigInteger gasPrice =  BigInteger.valueOf(20000000000L);

 public String depart_wallet(String code) {
    String walletCode = "";
    switch(code) {
        case "ct_01" : 
                walletCode = "83E094366642F531189D56DF33AC870DB53AF8C7F7F60A7A8B20CB85BC43A59F";
                break;
        case "ft_01" :
                walletCode = "666A82FC33F8134577A7BEB1BDEAA689BB72740178727691D63032432B83E0FB";
                break;
        case "ms_01" :
                walletCode = "3F0B5C58378DE554534A5A8C630AAC075886E74A6B3229000AE78F4500E153E3";
                break;
        case "st_01" :
                walletCode = "3B69CC479DBAC9B02D2B7C39F7829A2E5DF850203A1766355D854DD89FCC6848";
                break;
        case "hr_01" :
                walletCode = "3F1E2BD4EF8941731D244359F0CDF1EF079E5EAFFD57EA6D31ADDEB55E20D426";
                break;
        case "mf_01" :
                walletCode = "C6FD20908CDC2326A8A5E366228C149FA7632E9C4EF035F5B7EBEE1A04158B7E";
                break;

    }
    return walletCode;
}

我将从网上获取代码。

并通过上述方法将其发送以获取钱包地址并进行部署。

public void budgetAdd(HttpServletRequest req, Model model) throws Exception {

    String department_code = req.getParameter("dept_code");

    String deptWallet = depart_wallet(department_code);

    Credentials dept_AccountNumber = Credentials.create(deptWallet);

    String contractAddress2 = Materal.deploy(web3j, dept_AccountNumber, gasPrice, gasLimit).send().getContractAddress();

    int price = Integer.parseInt(req.getParameter("money"));
    BigInteger ethers = null;

    if(price < 100000) {
        ethers = etherToWei(new BigDecimal(1));
    }
    else if((100000 < price) && (price < 300000)) {
        ethers = etherToWei(new BigDecimal(1.25));
    }
    else if ((300000 < price) && (price < 500000)) {
        ethers = etherToWei(new BigDecimal(1.5));
    }
    else if ((500000 < price) && (price < 800000)) {
        ethers = etherToWei(new BigDecimal(1.8));
    }
    else if ((800000 < price) && (price < 1000000)) {
        ethers = etherToWei(new BigDecimal(2));
    }
    else {
        ethers = etherToWei(new BigDecimal(2.25));
    }

    byte[] name = stringToBytes32(department_code);

    Materal dept = Materal.load(contractAddress2, web3j, hostCredentials, gasPrice, gasLimit);
    String hash = dept.buyMaterial(new BigInteger("0"), name, ethers).send().getTransactionHash();

    String purpose = req.getParameter("purpose");

    HashVO vos = new HashVO();
    vos.setDepartment_code(department_code);
    vos.setE_subject(purpose);
    vos.setE_hashcode(hash);

    int insertCnt = dao.insertLog(vos);
    if(insertCnt == 1) {
        System.out.println("등록되었습니다.");
    }
}

我要部署和以太交易完成,插入到My Oracle。 但是我的代码无法部署。

也许gasLimit低吗? 但是,将GasLimit更改为6721975时,也会发生相同的错误。

昨天它可以正常运行且没有错误,但现在不起作用。你能给我答案这个错误吗?

0 个答案:

没有答案