Skip to content

Commit

Permalink
unpack extension options Any's
Browse files Browse the repository at this point in the history
  • Loading branch information
yihuang committed Mar 29, 2022
1 parent a579692 commit 0b93914
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* [\#11274](https://github.com/cosmos/cosmos-sdk/pull/11274) `types/errors.New` now is an alias for `types/errors.Register` and should only be used in initialization code.
* (authz)[\#11060](https://github.com/cosmos/cosmos-sdk/pull/11060) `authz.NewMsgGrant` `expiration` is now a pointer. When `nil` is used then no expiration will be set (grant won't expire).
* (x/distribution)[\#11457](https://github.com/cosmos/cosmos-sdk/pull/11457) Add amount field to `distr.MsgWithdrawDelegatorRewardResponse` and `distr.MsgWithdrawValidatorCommissionResponse`.
* (x/auth/middleware) [#11413](https://github.com/cosmos/cosmos-sdk/pull/11413) Refactor tx middleware to be extensible on tx fee logic. Merged `MempoolFeeMiddleware` and `TxPriorityMiddleware` functionalities into `DeductFeeMiddleware`, make the logic extensible using the `TxFeeChecker` option, the current fee logic is preserved by the default `checkTxFeeWithValidatorMinGasPrices` implementation. Change `RejectExtensionOptionsMiddleware` to `NewExtensionOptionsMiddleware` which is extensible with the `ExtensionOptionChecker` option.
* (x/auth/middleware) [#11413](https://github.com/cosmos/cosmos-sdk/pull/11413) Refactor tx middleware to be extensible on tx fee logic. Merged `MempoolFeeMiddleware` and `TxPriorityMiddleware` functionalities into `DeductFeeMiddleware`, make the logic extensible using the `TxFeeChecker` option, the current fee logic is preserved by the default `checkTxFeeWithValidatorMinGasPrices` implementation. Change `RejectExtensionOptionsMiddleware` to `NewExtensionOptionsMiddleware` which is extensible with the `ExtensionOptionChecker` option. Unpack the tx extension options `Any`s to interface `TxExtensionOptionI`.

### Client Breaking Changes

Expand Down
21 changes: 21 additions & 0 deletions types/tx/ext.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package tx

import (
"github.com/cosmos/cosmos-sdk/codec/types"
)

// TxExtensionOptionI defines the interface for tx extension options
type TxExtensionOptionI interface{}

// UnpackExtensionOptionsI unpacks Any's to TxExtensionOptionI's.
func UnpackTxExtensionOptionsI(unpacker types.AnyUnpacker, anys []*types.Any) error {
for _, any := range anys {
var opt TxExtensionOptionI
err := unpacker.UnpackAny(any, &opt)
if err != nil {
return err
}
}

return nil
}
16 changes: 15 additions & 1 deletion types/tx/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,19 @@ func (t *Tx) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error {

// UnpackInterfaces implements the UnpackInterfaceMessages.UnpackInterfaces method
func (m *TxBody) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error {
return UnpackInterfaces(unpacker, m.Messages)
if err := UnpackInterfaces(unpacker, m.Messages); err != nil {
return err
}

if err := UnpackTxExtensionOptionsI(unpacker, m.ExtensionOptions); err != nil {
return err
}

if err := UnpackTxExtensionOptionsI(unpacker, m.NonCriticalExtensionOptions); err != nil {
return err
}

return nil
}

// UnpackInterfaces implements the UnpackInterfaceMessages.UnpackInterfaces method
Expand All @@ -200,4 +212,6 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) {

registry.RegisterInterface("cosmos.tx.v1beta1.Tx", (*sdk.Tx)(nil))
registry.RegisterImplementations((*sdk.Tx)(nil), &Tx{})

registry.RegisterInterface("cosmos.tx.v1beta1.TxExtensionOptionI", (*TxExtensionOptionI)(nil))
}

0 comments on commit 0b93914

Please sign in to comment.