智能合约之间相互交互的错误

时间:2019-08-13 23:58:05

标签: python smartcontracts truffle vyper

我正在尝试在VM上的两个智能合约之间进行交互。我写了一份智能合约,履行一些职责,另一笔捐赠以太坊。现在,我想在它们之间进行交互,但是当我在truffle-console中执行一段代码时,会发生错误。错误是:

错误:返回的错误:处理事务时VM异常:还原

at XMLHttpRequest._onHttpResponseEnd (/usr/lib/node_modules/truffle/build/webpack:/~/xhr2-cookies/dist/xml-http-request.js:318:1)
at XMLHttpRequest._setReadyState (/usr/lib/node_modules/truffle/build/webpack:/~/xhr2-cookies/dist/xml-http-request.js:208:1)
at XMLHttpRequestEventTarget.dispatchEvent (/usr/lib/node_modules/truffle/build/webpack:/~/xhr2-cookies/dist/xml-http-request-event-target.js:34:1)
at XMLHttpRequest.request.onreadystatechange (/usr/lib/node_modules/truffle/build/webpack:/~/web3/~/web3-providers-http/src/index.js:96:1)
at /usr/lib/node_modules/truffle/build/webpack:/packages/truffle-provider/wrapper.js:112:1
at /usr/lib/node_modules/truffle/build/webpack:/~/web3-eth/~/web3-core-requestmanager/src/index.js:140:1
at Object.ErrorResponse (/usr/lib/node_modules/truffle/build/webpack:/~/web3-eth/~/web3-core-helpers/src/errors.js:29:1)

我执行的命令是: truffle migrate --reset

然后,在松露控制台中: Donation.at("0xEFCC3f9d79Fc3d9cC6096D2102E41370770B15c7").then(function(instance) { return instance.donation_smart_contract_call_hello_smart_contract_method.call("0xEa84767876ef2a05094E745B6E3113b2a694F371"); } ); [1]

使用vyper命令创建了Hello.json和Donation.json并获得了它们的“ abi”和“ bytecode”: vyper -f json,bytecode hello.vy(donation.vy)。 具体来说,它们是:

Hello.json

    "contractName": "Hello",
    "abi": [{"outputs": [], "inputs": [], "constant": false, "payable": false, "type": "constructor"}, {"name": "change_name", "outputs": [], "inputs": [{"type": "bytes", "name": "new_name"}], "constant": false, "payable": false, "type": "function", "gas": 70936}, {"name": "say_hello", "outputs": [{"type": "bytes", "name": "out"}], "inputs": [], "constant": false, "payable": false, "type": "function", "gas": 78764}, {"name": "name", "outputs": [{"type": "bytes", "name": "out"}], "inputs": [], "constant": true, "payable": false, "type": "function", "gas": 5180}],
    "bytecode": "0x740100000000000000000000000000000000000000006020526f7fffffffffffffffffffffffffffffff6040527fffffffffffffffffffffffffffffffff8000000000000000000000000000000060605274012a05f1fffffffffffffffffffffffffdabf41c006080527ffffffffffffffffffffffffed5fa0e000000000000000000000000000000000060a052341561009857600080fd5b6010610140527f5361746f736869204e616b616d6f746f000000000000000000000000000000006101605261014080600060c052602060c020602082510161012060006002818352015b826101205160200211156100f557610117565b61012051602002850151610120518501555b81516001018083528114156100e2575b50505050505061055b56600035601c52740100000000000000000000000000000000000000006020526f7fffffffffffffffffffffffffffffff6040527fffffffffffffffffffffffffffffffff8000000000000000000000000000000060605274012a05f1fffffffffffffffffffffffffdabf41c006080527ffffffffffffffffffffffffed5fa0e000000000000000000000000000000000060a052634596d11f60005114156101285734156100ac57600080fd5b60386004356004016101403760186004356004013511156100cc57600080fd5b61014080600060c052602060c020602082510161012060006002818352015b826101205160200211156100fe57610120565b61012051602002850151610120518501555b81516001018083528114156100eb575b505050505050005b63b4598503600051141561034f57341561014157600080fd5b6006610140527f48656c6c6f2000000000000000000000000000000000000000000000000000006101605261014080600160c052602060c020602082510161012060006002818352015b8261012051602002111561019e576101c0565b61012051602002850151610120518501555b815160010180835281141561018b575b5050505050506000600160018160c052602060c020016020836101a001018260c052602060c0205461012060006001818352015b8261012051602002111561020757610229565b61012051850154610120516020028501525b81516001018083528114156101f4575b50505050508060c052602060c020548201915050600060018160c052602060c020016020836101a001018260c052602060c0205461012060006001818352015b8261012051602002111561027c5761029e565b61012051850154610120516020028501525b8151600101808352811415610269575b50505050508060c052602060c020548201915050806101a0526101a09050805160200180610240828460006004600a8704601201f16102dc57600080fd5b50506102405160206001820306601f82010390506102a061024051601e818352015b826102a051111561030e5761032a565b60006102a05161026001535b81516001018083528114156102fe575b5050506020610220526040610240510160206001820306601f8201039050610220f350005b6306fdde03600051141561043357341561036857600080fd5b60008060c052602060c020610180602082540161012060006002818352015b8261012051602002111561039a576103bc565b61012051850154610120516020028501525b8151600101808352811415610387575b5050505050506101805160206001820306601f82010390506101e0610180516018818352015b826101e05111156103f25761040e565b60006101e0516101a001535b81516001018083528114156103e2575b5050506020610160526040610180510160206001820306601f8201039050610160f350005b60006000fd5b61012261055b0361012260003961012261055b036000f3"
}

Donation.json:

  "contractName": "Donation",
  "abi": [{"outputs": [], "inputs": [], "constant": false, "payable": false, "type": "constructor"}, {"name": "donate", "outputs": [], "inputs": [{"type": "bytes", "name": "name"}], "constant": false, "payable": true, "type": "function", "gas": 317680}, {"name": "withdraw_donation", "outputs": [], "inputs": [], "constant": false, "payable": false, "type": "function", "gas": 35996}, {"name": "donation_smart_contract_call_hello_smart_contract_method", "outputs": [{"type": "bytes", "name": "out"}], "inputs": [{"type": "address", "name": "smart_contract_address"}], "constant": true, "payable": false, "type": "function", "gas": 7296}, {"name": "donatur_details__sum", "outputs": [{"type": "uint256", "unit": "wei", "name": "out"}], "inputs": [{"type": "address", "name": "arg0"}], "constant": true, "payable": false, "type": "function", "gas": 829}, {"name": "donatur_details__name", "outputs": [{"type": "bytes", "name": "out"}], "inputs": [{"type": "address", "name": "arg0"}], "constant": true, "payable": false, "type": "function", "gas": 17927}, {"name": "donatur_details__time", "outputs": [{"type": "uint256", "unit": "sec", "name": "out"}], "inputs": [{"type": "address", "name": "arg0"}], "constant": true, "payable": false, "type": "function", "gas": 895}, {"name": "donaturs", "outputs": [{"type": "address", "name": "out"}], "inputs": [{"type": "int128", "name": "arg0"}], "constant": true, "payable": false, "type": "function", "gas": 892}, {"name": "donatee", "outputs": [{"type": "address", "name": "out"}], "inputs": [], "constant": true, "payable": false, "type": "function", "gas": 723}],
  "bytecode": "0x740100000000000000000000000000000000000000006020526f7fffffffffffffffffffffffffffffff6040527fffffffffffffffffffffffffffffffff8000000000000000000000000000000060605274012a05f1fffffffffffffffffffffffffdabf41c006080527ffffffffffffffffffffffffed5fa0e000000000000000000000000000000000060a052341561009857600080fd5b336004556105d056600035601c52740100000000000000000000000000000000000000006020526f7fffffffffffffffffffffffffffffff6040527fffffffffffffffffffffffffffffffff8000000000000000000000000000000060605274012a05f1fffffffffffffffffffffffffdabf41c006080527ffffffffffffffffffffffffed5fa0e000000000000000000000000000000000060a052637202d11060005114156101ab5760846004356004016101403760646004356004013511156100c157600080fd5b670de0b6b3a76400003410156100d657600080fd5b600a600554126100e557600080fd5b60003360e05260c052604060c02060c052602060c020348155610140806001830160c052602060c020602082510161012060006005818352015b8261012051602002111561013257610154565b61012051602002850151610120518501555b815160010180835281141561011f575b5050505050504260028201555033600554600a811061017257600080fd5b600360c052602060c0200155600560605160018254018060405190131561019857600080fd5b80919012156101a657600080fd5b815550005b6333158cf360005114156101ed5734156101c457600080fd5b60045433146101d257600080fd5b600060006000600030316004546000f16101eb57600080fd5b005b6332a0cc2260005114156102ed57341561020657600080fd5b600435602051811061021757600080fd5b506004353b61022557600080fd5b600435301861023357600080fd5b60606101a0600463b45985036101405261015c6004355afa61025457600080fd5b6000506101c0805160200180610240828460006004600a8704601201f161027a57600080fd5b50506102405160206001820306601f82010390506102a0610240516020818352015b826102a05111156102ac576102c8565b60006102a05161026001535b815160010180835281141561029c575b5050506020610220526040610240510160206001820306601f8201039050610220f350005b630cf6a753600051141561033c57341561030657600080fd5b600435602051811061031757600080fd5b50600060043560e05260c052604060c02060c052602060c0205460005260206000f350005b6308572e7c600051141561044b57341561035557600080fd5b600435602051811061036657600080fd5b506001600060043560e05260c052604060c02060c052602060c020018060c052602060c020610180602082540161012060006005818352015b826101205160200211156103b2576103d4565b61012051850154610120516020028501525b815160010180835281141561039f575b5050505050506101805160206001820306601f8201039050610240610180516064818352015b8261024051111561040a57610426565b6000610240516101a001535b81516001018083528114156103fa575b5050506020610160526040610180510160206001820306601f8201039050610160f350005b63ce2bc6b6600051141561049d57341561046457600080fd5b600435602051811061047557600080fd5b506002600060043560e05260c052604060c02060c052602060c020015460005260206000f350005b63086790a060005114156105025734156104b657600080fd5b606051600435806040519013156104cc57600080fd5b80919012156104da57600080fd5b50600435600a81106104eb57600080fd5b600360c052602060c020015460005260206000f350005b63c3351640600051141561052957341561051b57600080fd5b60045460005260206000f350005b60006000fd5b6100a16105d0036100a16000396100a16105d0036000f3"
}

脚本报告如下:

hello.vy:

name: public(bytes[24])
hello: bytes[6]

@public
def __init__():
    self.name = "Satoshi Nakamoto"

@public
def change_name(new_name: bytes[24]):
    self.name = new_name

@public
def say_hello() -> bytes[32]:
    self.hello = "Hello "
    return concat(self.hello, self.name) 

还有donation.vy

struct DonaturDetail:
    sum: uint256(wei)
    name: bytes[100]
    time: timestamp

contract Hello():
    def say_hello() -> bytes[32]: constant

donatur_details: public(map(address, DonaturDetail))

infinite_array_of_strings: map(uint256, bytes[100])

mapping_of_mapping_of_mapping: map(uint256, map(uint256, map(uint256, bytes[10])))

donaturs: public(address[10])

donatee: public(address)

index: int128

@public
def __init__():
    self.donatee = msg.sender

@payable
@public
def donate(name: bytes[100]):
    assert msg.value >= as_wei_value(1, "ether")
    assert self.index < 10

    self.donatur_details[msg.sender] = DonaturDetail({
                                         sum: msg.value,
                                         name: name,
                                         time: block.timestamp
                                       })

    self.donaturs[self.index] = msg.sender
    self.index += 1

@public
def withdraw_donation():
    assert msg.sender == self.donatee

    send(self.donatee, self.balance)

@public
@constant
def donation_smart_contract_call_hello_smart_contract_method(smart_contract_address: address) -> bytes[32]:
    return Hello(smart_contract_address).say_hello()

在执行命令[1]之后,发生了先前报告的错误。 这些脚本有什么错误吗?我该如何解决这个问题? 预先谢谢你。

0 个答案:

没有答案