Всегда возвращает пустой массив массивов, хотя показывает успешную транзакцию в сети Shasta.
Я пытаюсь вернуть все struct
введите записи из моих solidity contract
функция см. ниже solidity contract
фрагмент кода
struct Record {
uint _id;
string _countryCode;
string _state;
string _postal;
string _location;
string _userId;
string _additionalDetails;
}
Record[] public records;
function getEntries() public view returns (Record[] memory) {
return records;
}
function setRecord(
string memory _countryCode,
string memory _state,
string memory _postal,
string memory _location,
string memory _userId,
string memory _additionalDetails
) public onlyOwner {
Record memory newStruct = Record({
_id: _counter + 1,
_countryCode: _countryCode,
_state: _state,
_postal: _postal,
_location: _location,
_userId: _userId,
_additionalDetails: _additionalDetails
});
records.push(newStruct);
_counter++;
}
Я успешно могу добавить новую запись, используя tronweb
в nodejs
ниже в моем NodeJs
фрагмент кода
const walletAddress = "";
const privateKey = "";
const contractAddress = "";
tronweb.setAddress(walletAddress);
tronweb.setPrivateKey(privateKey);
const init = async () => {
let contract = await tronweb.contract().at(contractAddress);
const getRecords = async () => await contract.getEntries().call();
const setRecord = async () => await contract.setRecord(
"USA",
"LA",
"12345",
"Street 1",
"1324-12345-12456-45642",
"Testing notes"
).send({
"from": walletAddress
});
await setRecord();
getRecords().then(result => {
console.log(result); // getting empty array like [ [], [] ]
});
};
init();
Вот изображение консоли результатов моего скрипта nodejs, которое всегда возвращает пустой массив массивов
Вот детали транзакции Shasta Network со статусом CONFIRMED
Кто-нибудь может мне помочь?
1 ответ
Решение
В ABI любое возвращаемое значение типа структуры будет интерпретироваться как tuple
. В вашем случае его типtuple[]
.
Библиотека не знает, какой у вас tuple
есть, как долго, что за тип.
Вам следует проанализировать возвращаемые данные вручную.
{
"constant_result": [
"000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000005800000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000000000000001c00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000002400000000000000000000000000000000000000000000000000000000000000003555341000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000024c4100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000053132333435000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000853747265657420310000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000016313332342d31323334352d31323435362d343536343200000000000000000000000000000000000000000000000000000000000000000000000000000000000d54657374696e67206e6f74657300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000000000000001c00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000002400000000000000000000000000000000000000000000000000000000000000003555341000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000024c4100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000053132333435000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000853747265657420310000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000016313332342d31323334352d31323435362d343536343200000000000000000000000000000000000000000000000000000000000000000000000000000000000d54657374696e67206e6f74657300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000000000000001c00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000002400000000000000000000000000000000000000000000000000000000000000003555341000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000024c4100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000053132333435000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000853747265657420310000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000016313332342d31323334352d31323435362d343536343200000000000000000000000000000000000000000000000000000000000000000000000000000000001254657374696e672077697468204a616d65730000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000000000000001c00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000002400000000000000000000000000000000000000000000000000000000000000003555341000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000024c4100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000053132333435000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000853747265657420310000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000016313332342d31323334352d31323435362d343536343200000000000000000000000000000000000000000000000000000000000000000000000000000000001e54657374696e672077697468204a616d6573206e65772076657273696f6e0000"
],
"result": {
"code": "SUCCESS",
"message": "",
"result": true
}
}
Чтобы проанализировать constant_result:
- выровняйте его по границе из 64 символов (256 бит)
- обычно значения - смещения или длины
- за подробностями обратитесь к документу ETH ABI
0000000000000000000000000000000000000000000000000000000000000020 offset of first parm
0000000000000000000000000000000000000000000000000000000000000004
0000000000000000000000000000000000000000000000000000000000000080
0000000000000000000000000000000000000000000000000000000000000300
0000000000000000000000000000000000000000000000000000000000000580
0000000000000000000000000000000000000000000000000000000000000800
0000000000000000000000000000000000000000000000000000000000000001 #first
0000000000000000000000000000000000000000000000000000000000000100
0000000000000000000000000000000000000000000000000000000000000140
0000000000000000000000000000000000000000000000000000000000000180
00000000000000000000000000000000000000000000000000000000000001c0
0000000000000000000000000000000000000000000000000000000000000200
0000000000000000000000000000000000000000000000000000000000000001
0000000000000000000000000000000000000000000000000000000000000240
0000000000000000000000000000000000000000000000000000000000000003 a string with 3 chars
5553410000000000000000000000000000000000000000000000000000000000 "USA"
0000000000000000000000000000000000000000000000000000000000000002 a string with 2 chars
4c41000000000000000000000000000000000000000000000000000000000000 "LA"
0000000000000000000000000000000000000000000000000000000000000005
3132333435000000000000000000000000000000000000000000000000000000 '12345'
0000000000000000000000000000000000000000000000000000000000000008
5374726565742031000000000000000000000000000000000000000000000000 'Street 1'
0000000000000000000000000000000000000000000000000000000000000016
313332342d31323334352d31323435362d343536343200000000000000000000 '1324-12345-12456-45642'
000000000000000000000000000000000000000000000000000000000000000d
54657374696e67206e6f74657300000000000000000000000000000000000000 'Testing notes'
0000000000000000000000000000000000000000000000000000000000000002 #second
0000000000000000000000000000000000000000000000000000000000000100
0000000000000000000000000000000000000000000000000000000000000140
0000000000000000000000000000000000000000000000000000000000000180
00000000000000000000000000000000000000000000000000000000000001c0
0000000000000000000000000000000000000000000000000000000000000200
0000000000000000000000000000000000000000000000000000000000000001
0000000000000000000000000000000000000000000000000000000000000240
0000000000000000000000000000000000000000000000000000000000000003
5553410000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000002
4c41000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000005
3132333435000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000008
5374726565742031000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000016
313332342d31323334352d31323435362d343536343200000000000000000000
000000000000000000000000000000000000000000000000000000000000000d
54657374696e67206e6f74657300000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000003 #third
0000000000000000000000000000000000000000000000000000000000000100
0000000000000000000000000000000000000000000000000000000000000140
0000000000000000000000000000000000000000000000000000000000000180
00000000000000000000000000000000000000000000000000000000000001c0
0000000000000000000000000000000000000000000000000000000000000200
0000000000000000000000000000000000000000000000000000000000000001
0000000000000000000000000000000000000000000000000000000000000240
0000000000000000000000000000000000000000000000000000000000000003
5553410000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000002
4c41000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000005
3132333435000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000008
5374726565742031000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000016
313332342d31323334352d31323435362d343536343200000000000000000000
0000000000000000000000000000000000000000000000000000000000000012
54657374696e672077697468204a616d65730000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000004 #fourth
0000000000000000000000000000000000000000000000000000000000000100
0000000000000000000000000000000000000000000000000000000000000140
0000000000000000000000000000000000000000000000000000000000000180
00000000000000000000000000000000000000000000000000000000000001c0
0000000000000000000000000000000000000000000000000000000000000200
0000000000000000000000000000000000000000000000000000000000000001
0000000000000000000000000000000000000000000000000000000000000240
0000000000000000000000000000000000000000000000000000000000000003
5553410000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000002
4c41000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000005
3132333435000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000008
5374726565742031000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000016
313332342d31323334352d31323435362d343536343200000000000000000000
000000000000000000000000000000000000000000000000000000000000001e
54657374696e672077697468204a616d6573206e65772076657273696f6e0000