web3.py - Python-dtype für Vertragsfunktion mit int256[x]

Angenommen, ich habe diesen Beispielvertrag:

pragma solidity ^0.4.0;
contract SEexample {

    int256[3] thing;
    uint8 internal i=0;

    function submit(int256[3] bids,int256[3] prefs) public returns (int256[3]){
            for (i=0;i<3;i++){
                thing[i] = bids[i] + prefs[i];
            }
        return thing;
    }
}

Dieses Abi geben:

[
    {
        "constant": false,
        "inputs": [
            {
                "name": "bids",
                "type": "int256[3]"
            },
            {
                "name": "prefs",
                "type": "int256[3]"
            }
        ],
        "name": "submit",
        "outputs": [
            {
                "name": "",
                "type": "int256[3]"
            }
        ],
        "payable": false,
        "stateMutability": "nonpayable",
        "type": "function"
    }
]

Und ich stelle mit web3.py bereit:

from web3 import Web3, HTTPProvider, IPCProvider
w3 = Web3(HTTPProvider('http://localhost:8545'))   //(testrpc)
tx_hash = contract.deploy(transaction={'from': w3nce.eth.accounts[0], 'gas': 10000000})
tx_receipt = w3.eth.getTransactionReceipt(tx_hash)
contract_address = tx_receipt['contractAddress']
contract_instance = w3.eth.contract(address=contract_address, abi=abi, ContractFactoryClass=ConciseContract)

Wie weise ich Python an, den int256 [13] zu erfüllen, den die Funktion erfordert?

Ich habe Variationen ausprobiert von:

import numpy as np
a=np.ones((3,),dtype=int)
b=np.ones((3,),dtype=int)
x=contract_instance.submit(a,b, transact={'from': w3.eth.accounts[1]})

auch mit a.tobytes(),b.tobytes()

Ergebnisse in:

raise ValueError("No matching functions found")

ValueError: Keine passenden Funktionen gefunden

Antworten (1)

Das scheint zu funktionieren:

x=contract_instance.submit(a.tolist(),b.tolist(), transact={'from': w3.eth.accounts[1]})