I have a view call in my Solidity code that looks like this:
function call1 (address[] calldata targets) external view returns(Return[] memory returnData)
And the struct from the array which is returned looks like this:
struct Return {
bool success;
address addr;
bytes data;
}
My goal is to decode the function call results of this function in Golang. So far I could log the results partially with this code:
res, err := client.CallContract(context.Background(), callMsg, nil)
outputDataList := make([]interface{}, 10)
outputDataList, err = contractABI.Unpack("call1", res)
fmt.Println(outputDataList[0].(interface{}))
I could log the bool
and address
from the struct, however the bytes variable is still not encoded.
[{true 0x8840c6252e2e86e545defb6da98b2a0e26d8c1ba[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 24 75 122 0 63 109 85 204 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 15 215 247 135 154 188 2 164 101 11 198 216 164 41 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 100 139 110 44]} {true 0x8840c6252e2e86e545defb6da98b2a0e26d8c1ba[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 24 75 122 0 63 109 85 204 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 15 215 247 135 154 188 2 164 101 11 198 216 164 41 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 100 139 110 44]}]
My question is that how should I continue the decode process of this? I would like to have the results in an array of structs that have the same structure as the Solidity struct. What would be the most elegant way to do it? I am also no sure that using an array (outputDataList
) is the best option or another solution should be used.