智能合约代码无法通过Nethereum失败,但可以在其他地方运行

时间:2019-05-15 14:29:28

标签: c# blockchain solidity truffle

我正在尝试通过C#/ Nethereum调用智能合约上的功能。当我在js中运行单元测试时,此代码将运行。我也在Remix IDE中对其进行了测试,并且可以正常工作。

当我在Nethereum中调用此代码时,出现VM错误,并且事务恢复。

我得到的错误是:

[5/15/2019 2:27:14 PM] System.Private.CoreLib:执行函数DeployContractManager时发生异常。 Nethereum.JsonRpc.Client:处理事务时,VM异常:恢复。

以前有没有人遇到过这个问题,或者对我应该如何找出问题有任何见识?

这是团结合同:


pragma solidity >=0.4.21 <0.6.0;
import "./ContractManager.sol";

contract ContractManagerFactory {
    mapping(bytes32 => address) addresses;

    function createManager(address supplier, address customer) public returns(address) {
        bytes32 key = keccak256(abi.encodePacked(supplier, customer));
        ContractManager cm = new ContractManager(supplier, customer);
        addresses[key] = address(cm);
        return addresses[key];
    }

    function getAddress(address supplier, address customer) public view returns(address) {
        bytes32 key = keccak256(abi.encodePacked(supplier, customer));
        return addresses[key];
    }
}

这是JS测试(有效):

    it("can create contract manager and get its address", async() => {
        await factory.createManager(supplier, customer, {from:supplier});
        const addr = await factory.getAddress(supplier, customer, {from:supplier});
        console.log(addr);
    });

这是C#代码(失败):

    public class ContractManagerFactoryProxy
    {
        private readonly Web3 _web3;
        private readonly string _address;

        //I have had issues getting this to work, so I have been manually
        //deploying 
        public ContractManagerFactoryProxy(string providerUrl)
        {
            //this should be a fixed address
            _web3 = new Web3(providerUrl);
            _address = "0xD47a082BcF57E696F425d86fE17430Bc05666a69";
        }

        public async Task<string> CreateManager(string saddr, string caddr, string from)
        {
            var msg = _web3.Eth.GetContractTransactionHandler<CreateManagerMessage>();

            var tx = await msg.SendRequestAsync(
                _address, 
                new CreateManagerMessage
                {
                    FromAddress = from,
                    Supplier = saddr,
                    Customer = caddr
                });

            return tx;
        }
    }

    [Function("createManager", "address")]
    public class CreateManagerMessage : FunctionMessage
    {
        [Parameter("address", "supplier")] public string Supplier { get; set; }
        [Parameter("address", "customer")] public string Customer { get; set; }
    }

0 个答案:

没有答案