我有一个solidity
方法可以从我的合同中获取字符串列表,对每个字符串进行哈希处理并返回一个哈希数组。我对此进行了测试Remix
,效果很好。
在开发中,我从其中调用此函数,nodejs
但由于某种原因返回[object Object]
不包含哈希数组的函数。
我应该补充一点,我的提供者web3
不是Ethereum
但Quorum
7nodes example.
这是solidity
功能:
function getHashs(string id) public view returns (bytes32[]) {
bytes32[] memory stringsToHash = getStrings(id);
bytes32[] memory hashes = new bytes32[](5);
for(uint i=0; i<=stringsToHash.length-1; i++) {
bytes32 str = seeds[i];
bytes32 hash = sha256(abi.encodePacked(seed));
hashes[i] = hash;
}
return hashes;
}
这是w3
代码:
function getHashes(id, contract, fromAccount, privateForNode) {
return new Promise(function(resolve, reject) {
contract.methods.getHashs(id).send({from: fromAccount, gas: 150000000, privateFor: [privateForNode]})
.then(hashes => {
console.log("got hashes from node === ");
console.log(hashes[0]); // this is 'undefined'
resolve(hashes);
},
(error) => {
reject(error);
}).catch((err) => {
reject(err);
});
})
.catch((err) => {
reject(err);
});
}