我正在尝试在私有区块链上运行出价智能合约,而我的智能合约正在 Remix IDE 上运行,并且在我的私有链上同样有效,除了一个函数 [dataOwnedBy()] 应该返回一个字节数组,但是在 geth 控制台中返回所有零值。我已经使用 truffle 编译并部署了我的智能合约。
不起作用的函数是:(以及数据声明片段和其他函数原型)
struct data{
bytes32 data_id;
address bidder;
uint bid;
}
mapping(bytes32=>data) bidInfo;
mapping(address=>data[]) dataOwned; //data owned by each address
address[] dataOwners; //list of address who own data
function Bid(bytes32 data_id) public payable { ... }
function closeBid(bytes32 data_id) public { ... }
function whoOwns(bytes32 _data_id) constant public returns (address){ ... }
function dataOwnedBy(address _addr) constant public returns (bytes32[10]){
uint length = dataOwned[_addr].length;
bytes32[10] memory _idArray;
for (uint i=0;i<length;i++){
_idArray[i] = (dataOwned[_addr][i].data_id);
}
return _idArray;
}
关闭投标后,当我用中标者的地址查询上述函数时,它返回大小为 10 bytes32 值的数组,全部为零,它应该返回该地址拥有的 data_ids。!
Version Information from console
> web3.version.api
"0.20.1"
truffle(development)> version
Truffle v3.4.11 (core: 3.4.11)
Solidity v0.4.15 (solc-js)
这是控制台输出:
playbid.whoOwns("data_id1")
“0x7d8eb703bd863313325b784ac35017614484f2e7”
playbid.dataOwnedBy("0x7d8eb703bd863313325b784ac35017614484f2e7")
["0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000"]
相反,数组的第一个值应该是“data_id1”的十六进制。
不知道这里出了什么问题,但它在 Remix IDE 上运行良好。提前致谢 !