坚固版0.6.10
struct LogisticsData {
address cargo;
address orgin;
address destination;
string memo;
uint createdAt;
uint queryCount;
}
function getLogisticsInfo(address cargo) public returns(LogisticsData[] memory _cargoLogisticsData) {
_cargoLogisticsData = new LogisticsData[](3);
// do something
}由abigen生成的Go代码
type LogisticsLogisticsData struct {
Cargo common.Address
Orgin common.Address
Destination common.Address
Memo string
CreatedAt *big.Int
QueryCount *big.Int
}我尝试了以下代码,但它返回了一个错误。
_, receipt, _ := instance.GetLogisticsInfo(client.GetTransactOpts(), common.HexToAddress(address))
parsedAbi, _ := abi.JSON(strings.NewReader(logistics.LogisticsABI))
temp := make([]logistics.LogisticsLogisticsData, 10)
err = parsedAbi.Unpack(&temp, "getLogisticsInfo", []byte(receipt.Output))
fmt.Println(err) // abi: improperly formatted output: xxx我希望将返回数据转换为LogisticsLogisticsData结构。该怎么做呢?
发布于 2022-04-27 08:31:18
需要将十六进制转换为二进制
bytesOutput, _ := hex.DecodeString(receipt.Output[2:])
err = parsedAbi.Unpack(&temp, "getLogisticsInfo", bytesOutput)https://ethereum.stackexchange.com/questions/126838
复制相似问题