Open bonedaddy opened 3 years ago
One of the Go-Ethereum devs gave me this code snippet which can be refactored for a Golang equivalent of the Solidity abi.encode
function:
// encodeState encodes the state as with abi.encode() in the smart contracts.
func encodeState(state *adjudicator.ChannelState) ([]byte, error) {
args := abi.Arguments{
{Type: abiBytes32},
{Type: abiUint64},
{Type: abiBytes},
{Type: abiBytes},
{Type: abiBool},
}
alloc, err := encodeAllocation(&state.Outcome)
if err != nil {
return nil, err
}
enc, err := args.Pack(
state.ChannelID,
state.Version,
alloc,
state.AppData,
state.IsFinal,
)
return enc, errors.WithStack(err)
}
At the moment I'm using a customized mutlicall contract that exposes view functions for specific functionality. This was due to the complexity of manual abi encoding/decoding with Golang. It is satisfactory, however there is something to be said for having a generalized golang equivalent of
multicall.js
.