-
Notifications
You must be signed in to change notification settings - Fork 20.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature(abigen): support parse transaction input bytes readable go struct in abigen
#27361
Conversation
abigen
abigen
abigen
abigen
Here is the code generated by new Solidity: function collect((uint256,address,uint128,uint128) params) payable returns(uint256 amount0, uint256 amount1) // CollectParams is an auto generated read-only Go binding of transcaction calldata params
type CollectParams struct {
Param_params INonfungiblePositionManagerCollectParams
}
// Parse Collect method from calldata of a transaction
//
// Solidity: function collect((uint256,address,uint128,uint128) params) payable returns(uint256 amount0, uint256 amount1)
func ParseCollect(calldata []byte) (*CollectParams, error) {
if len(calldata) <= 4 {
return nil, fmt.Errorf("invalid calldata input")
}
_abi, err := UniswapMetaData.GetAbi()
if err != nil {
return nil, fmt.Errorf("failed to get abi of registry metadata:%w", err)
}
out, err := _abi.Methods["collect"].Inputs.Unpack(calldata[4:])
if err != nil {
return nil, fmt.Errorf("failed to unpack collect params data: %w", err)
}
var paramsResult = new(CollectParams)
value := reflect.ValueOf(paramsResult).Elem()
if value.NumField() != len(out) {
return nil, fmt.Errorf("failed to match calldata with param field number")
}
out0 := *abi.ConvertType(out[0], new(INonfungiblePositionManagerCollectParams)).(*INonfungiblePositionManagerCollectParams)
return &CollectParams{
Param_params: out0,
}, nil
} |
I'm working on a v2 of abigen #26782 and this feature is one of the building blocks. |
Nice. Your code looks neat. Should I merge my commits into your branch? And what I should do next? |
This PR is non-intrusive. |
As discussed in Discord, we would prefer to ship abigen v2 (#26782) rather than adding more features into abigen v1. |
feature: support parse transaction input bytes readable go struct
abigen
It's easy to use
abigen
to generate code that help you parse theevent log
and call the payable method with the transactor.But parsing the transaction call data is missing. You can only send a transaction with a transactor. This PR aims to generate codes that help developer parse transaction calldata.
abigen
can generate code to parse the transaction call data.example
Method ParseRenew is generate by
abigen
.Here is the output of above codes:
&{Param_params:{TokenId:+894123 Recipient:0x48B8e4ed457da9B64c33Ee50Fd5490614833A37D Amount0Max:+340282366920938463463374607431768211455 Amount1Max:+340282366920938463463374607431768211455}}
&{Param_params:{TokenId:+891904 Amount0Desired:+331092 Amount1Desired:+0 Amount0Min:+331092 Amount1Min:+0 Deadline:+1685112789}}