-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* WIP on adding Fee granter field * WIP on adding Fee granter field * WIP on adding Fee granter field * Update comments, add tests
- Loading branch information
Showing
10 changed files
with
227 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package ante | ||
|
||
import ( | ||
"github.com/cosmos/cosmos-sdk/types" | ||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
) | ||
|
||
// RejectFeeGranterDecorator is an AnteDecorator which rejects transactions which | ||
// have the Fee.granter field set. It is to be used by chains which do not support | ||
// fee grants. | ||
type RejectFeeGranterDecorator struct{} | ||
|
||
// NewRejectFeeGranterDecorator returns a new RejectFeeGranterDecorator. | ||
func NewRejectFeeGranterDecorator() RejectFeeGranterDecorator { | ||
return RejectFeeGranterDecorator{} | ||
} | ||
|
||
var _ types.AnteDecorator = RejectFeeGranterDecorator{} | ||
|
||
func (d RejectFeeGranterDecorator) AnteHandle(ctx types.Context, tx types.Tx, simulate bool, next types.AnteHandler) (newCtx types.Context, err error) { | ||
feeTx, ok := tx.(types.FeeTx) | ||
if ok && len(feeTx.FeeGranter()) != 0 { | ||
return ctx, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "fee grants are not supported") | ||
} | ||
|
||
return next(ctx, tx, simulate) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package ante_test | ||
|
||
import ( | ||
"github.com/cosmos/cosmos-sdk/codec" | ||
"github.com/cosmos/cosmos-sdk/codec/types" | ||
"github.com/cosmos/cosmos-sdk/testutil/testdata" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/x/auth/ante" | ||
"github.com/cosmos/cosmos-sdk/x/auth/tx" | ||
) | ||
|
||
type setFeeGranter interface { | ||
SetFeeGranter(feeGranter sdk.AccAddress) | ||
} | ||
|
||
func (suite *AnteTestSuite) TestRejectFeeGranter() { | ||
suite.SetupTest(true) // setup | ||
txConfig := tx.NewTxConfig(codec.NewProtoCodec(types.NewInterfaceRegistry()), tx.DefaultSignModes) | ||
txBuilder := txConfig.NewTxBuilder() | ||
d := ante.NewRejectFeeGranterDecorator() | ||
antehandler := sdk.ChainAnteDecorators(d) | ||
|
||
_, err := antehandler(suite.ctx, txBuilder.GetTx(), false) | ||
suite.Require().NoError(err) | ||
|
||
setGranterTx := txBuilder.(setFeeGranter) | ||
_, _, addr := testdata.KeyTestPubAddr() | ||
setGranterTx.SetFeeGranter(addr) | ||
|
||
_, err = antehandler(suite.ctx, txBuilder.GetTx(), false) | ||
suite.Require().Error(err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters