Web3j получает ошибку переполнения стека с Ganache - PullRequest
0 голосов
/ 07 марта 2020

У меня возникает ошибка «Ошибка при обработке запроса транзакции: исключение виртуальной машины при обработке транзакции: потеря стека» в основном с любым контрактом. Я использую Ganache v2.1.2 и Web3j 4.5.15. То же самое и с Ganache CLI v6.9.1 (ganache-core: 2.10.2). Я могу развернуть контракт с Remix IDE и плагином Metamask без каких-либо проблем.

Код Java:

public class contractCR
  {

    static class OSCGasProvider implements ContractGasProvider
      {     

        public OSCGasProvider(){}

        @Override
        public BigInteger getGasPrice(String string)
          {            
           return Convert.toWei("1", Convert.Unit.GWEI).toBigInteger();             
          }       

        @Override
        public BigInteger getGasLimit(String string)
          {
            return BigInteger.valueOf(3000000);
          }

        @Override
        public BigInteger getGasPrice()
          {
            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
          }

        @Override
        public BigInteger getGasLimit()
          {
            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
          }

      }

    public static void main (String args[])
      {
        System.out.println("Connecting to Ethereum ...");
        Web3j web3 = Web3j.build(new HttpService("http://localhost:7545"));
        System.out.println("Successfuly connected to Ethereum");
        try 
          {
            // web3_clientVersion returns the current client version.
            Web3ClientVersion clientVersion = web3.web3ClientVersion().send();
            Credentials credentials=Credentials.create(privateKey);
            Faucet osc = Faucet.deploy(web3, credentials, new OSCGasProvider()).send();
            String contractAddress = osc.getContractAddress();
            System.out.println("The contract address is: "+contractAddress);
           } 
        catch (IOException ex)
          {
            throw new RuntimeException("Error while sending json-rpc requests", ex);
          }
        catch (Exception ex)
          {
              System.out.println(ex.toString());
          }     
      }
}

Простой контракт Faucet:

// Version of Solidity compiler this program was written for
pragma solidity ^0.5.12;

// Our first contract is a faucet!
contract Faucet {

    address payable owner_addr; //the owner address

    //initialize the contract
    constructor() public 
    {
      owner_addr=msg.sender;
    }

    //contract destructor
    modifier owner_allowed
    {
      require (msg.sender==owner_addr, "Only contract owner is allowed to call this function");    
      _;
    }

    function destroy() public owner_allowed
    {
      selfdestruct(owner_addr);
    }

    // Give out ether to anyone who asks
    function withdraw(uint withdraw_amount) public
     {
        // Limit withdrawal amount
        require(withdraw_amount <= 100000000000000000); //0.1ether
        // Send the amount to the address that requested it
        msg.sender.transfer(withdraw_amount);
    }

    // Accept any incoming amount
    function () external payable {} //fallback or default function

}

Ответы [ 2 ]

0 голосов
/ 09 марта 2020

Наконец-то я разобрался в проблеме. Web3j-cli не принимает двоичный файл, предоставленный Remix-IDE, а только поле «двоичный». Предоставление в качестве входных данных файла, содержащего только двоичные данные, для Web3j-cli дает правильную оболочку.

0 голосов
/ 09 марта 2020

Похоже, что это одна проблема, связанная с Ganache https://github.com/trufflesuite/ganache-cli/issues/465

В моем тесте это может хорошо работать в моем локальном Ganache 2.1.2

...