Co-authored-by: Marko <marbar3778@yahoo.com> Co-authored-by: Julien Robert <julien@rbrt.fr>
This commit is contained in:
co-authored by
Marko
Julien Robert
parent
b1208ef298
commit
deea20c712
@@ -6,7 +6,6 @@ import (
|
||||
"github.com/cosmos/gogoproto/proto"
|
||||
"google.golang.org/protobuf/types/known/anypb"
|
||||
|
||||
basev1beta1 "cosmossdk.io/api/cosmos/base/v1beta1"
|
||||
txv1beta1 "cosmossdk.io/api/cosmos/tx/v1beta1"
|
||||
txsigning "cosmossdk.io/x/tx/signing"
|
||||
"cosmossdk.io/x/tx/signing/aminojson"
|
||||
@@ -130,12 +129,6 @@ func (b *AuxTxBuilder) SetSignMode(mode signing.SignMode) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetTip sets an optional tip in the AuxSignerData.
|
||||
func (b *AuxTxBuilder) SetTip(tip *tx.Tip) {
|
||||
b.checkEmptyFields()
|
||||
b.auxSignerData.SignDoc.Tip = tip
|
||||
}
|
||||
|
||||
// SetSignature sets the aux signer's signature in the AuxSignerData.
|
||||
func (b *AuxTxBuilder) SetSignature(sig []byte) {
|
||||
b.checkEmptyFields()
|
||||
@@ -214,11 +207,7 @@ func (b *AuxTxBuilder) GetSignBytes() ([]byte, error) {
|
||||
handler := aminojson.NewSignModeHandler(aminojson.SignModeHandlerOptions{
|
||||
FileResolver: proto.HybridResolver,
|
||||
})
|
||||
legacyTip := b.auxSignerData.SignDoc.Tip
|
||||
tip := &txv1beta1.Tip{
|
||||
Amount: make([]*basev1beta1.Coin, len(legacyTip.Amount)),
|
||||
Tipper: legacyTip.Tipper,
|
||||
}
|
||||
|
||||
auxBody := &txv1beta1.TxBody{
|
||||
Messages: body.Messages,
|
||||
Memo: body.Memo,
|
||||
@@ -230,12 +219,7 @@ func (b *AuxTxBuilder) GetSignBytes() ([]byte, error) {
|
||||
ExtensionOptions: nil,
|
||||
NonCriticalExtensionOptions: nil,
|
||||
}
|
||||
for i, coin := range legacyTip.Amount {
|
||||
tip.Amount[i] = &basev1beta1.Coin{
|
||||
Denom: coin.Denom,
|
||||
Amount: coin.Amount.String(),
|
||||
}
|
||||
}
|
||||
|
||||
signBz, err = handler.GetSignBytes(
|
||||
context.Background(),
|
||||
txsigning.SignerData{
|
||||
@@ -254,7 +238,6 @@ func (b *AuxTxBuilder) GetSignBytes() ([]byte, error) {
|
||||
// over empty fees.
|
||||
// ref: https://github.com/cosmos/cosmos-sdk/pull/10348
|
||||
Fee: &txv1beta1.Fee{},
|
||||
Tip: tip,
|
||||
},
|
||||
},
|
||||
)
|
||||
|
||||
@@ -84,25 +84,11 @@ func TestAuxTxBuilder(t *testing.T) {
|
||||
},
|
||||
true, "got unknown sign mode SIGN_MODE_UNSPECIFIED",
|
||||
},
|
||||
{
|
||||
"GetSignBytes tipper should not be nil (if tip is set)",
|
||||
func() error {
|
||||
require.NoError(t, b.SetMsgs(msg1))
|
||||
require.NoError(t, b.SetPubKey(pub1))
|
||||
b.SetTip(&typestx.Tip{})
|
||||
require.NoError(t, b.SetSignMode(signing.SignMode_SIGN_MODE_DIRECT_AUX))
|
||||
|
||||
_, err := b.GetSignBytes()
|
||||
return err
|
||||
},
|
||||
true, "tipper cannot be empty",
|
||||
},
|
||||
{
|
||||
"GetSignBytes works for DIRECT_AUX",
|
||||
func() error {
|
||||
require.NoError(t, b.SetMsgs(msg1))
|
||||
require.NoError(t, b.SetPubKey(pub1))
|
||||
b.SetTip(tip)
|
||||
require.NoError(t, b.SetSignMode(signing.SignMode_SIGN_MODE_DIRECT_AUX))
|
||||
|
||||
_, err := b.GetSignBytes()
|
||||
@@ -115,7 +101,6 @@ func TestAuxTxBuilder(t *testing.T) {
|
||||
func() error {
|
||||
require.NoError(t, b.SetMsgs(msg1))
|
||||
require.NoError(t, b.SetPubKey(pub1))
|
||||
b.SetTip(tip)
|
||||
require.NoError(t, b.SetSignMode(signing.SignMode_SIGN_MODE_DIRECT_AUX))
|
||||
|
||||
_, err := b.GetSignBytes()
|
||||
@@ -131,7 +116,6 @@ func TestAuxTxBuilder(t *testing.T) {
|
||||
func() error {
|
||||
require.NoError(t, b.SetMsgs(msg1))
|
||||
require.NoError(t, b.SetPubKey(pub1))
|
||||
b.SetTip(tip)
|
||||
b.SetAddress(addr1.String())
|
||||
require.NoError(t, b.SetSignMode(signing.SignMode_SIGN_MODE_DIRECT_AUX))
|
||||
|
||||
@@ -153,7 +137,6 @@ func TestAuxTxBuilder(t *testing.T) {
|
||||
b.SetChainID(chainID)
|
||||
require.NoError(t, b.SetMsgs(msg1))
|
||||
require.NoError(t, b.SetPubKey(pub1))
|
||||
b.SetTip(tip)
|
||||
b.SetAddress(addr1.String())
|
||||
err := b.SetSignMode(signing.SignMode_SIGN_MODE_DIRECT_AUX)
|
||||
require.NoError(t, err)
|
||||
@@ -176,7 +159,6 @@ func TestAuxTxBuilder(t *testing.T) {
|
||||
func() error {
|
||||
require.NoError(t, b.SetMsgs(msg1))
|
||||
require.NoError(t, b.SetPubKey(pub1))
|
||||
b.SetTip(tip)
|
||||
b.SetAddress(addr1.String())
|
||||
err := b.SetSignMode(signing.SignMode_SIGN_MODE_LEGACY_AMINO_JSON)
|
||||
require.NoError(t, err)
|
||||
@@ -196,7 +178,6 @@ func TestAuxTxBuilder(t *testing.T) {
|
||||
b.SetChainID(chainID)
|
||||
require.NoError(t, b.SetMsgs(msg1))
|
||||
require.NoError(t, b.SetPubKey(pub1))
|
||||
b.SetTip(tip)
|
||||
b.SetAddress(addr1.String())
|
||||
err := b.SetSignMode(signing.SignMode_SIGN_MODE_LEGACY_AMINO_JSON)
|
||||
require.NoError(t, err)
|
||||
@@ -250,7 +231,6 @@ func checkCorrectData(t *testing.T, cdc codec.Codec, auxSignerData typestx.AuxSi
|
||||
require.Equal(t, chainID, auxSignerData.SignDoc.ChainId)
|
||||
require.Equal(t, msgAny, body.GetMessages()[0])
|
||||
require.Equal(t, pkAny, auxSignerData.SignDoc.PublicKey)
|
||||
require.Equal(t, tip, auxSignerData.SignDoc.Tip)
|
||||
require.Equal(t, signMode, auxSignerData.Mode)
|
||||
require.Equal(t, rawSig, auxSignerData.Sig)
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
|
||||
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/types/tx"
|
||||
"github.com/cosmos/cosmos-sdk/types/tx/signing"
|
||||
)
|
||||
|
||||
@@ -38,7 +37,6 @@ type Factory struct {
|
||||
generateOnly bool
|
||||
memo string
|
||||
fees sdk.Coins
|
||||
tip *tx.Tip
|
||||
feeGranter sdk.AccAddress
|
||||
feePayer sdk.AccAddress
|
||||
gasPrices sdk.DecCoins
|
||||
@@ -105,11 +103,6 @@ func NewFactoryCLI(clientCtx client.Context, flagSet *pflag.FlagSet) (Factory, e
|
||||
feesStr, _ := flagSet.GetString(flags.FlagFees)
|
||||
f = f.WithFees(feesStr)
|
||||
|
||||
tipsStr, _ := flagSet.GetString(flags.FlagTip)
|
||||
// Add tips to factory. The tipper is necessarily the Msg signer, i.e.
|
||||
// the from address.
|
||||
f = f.WithTips(tipsStr, clientCtx.FromAddress.String())
|
||||
|
||||
gasPricesStr, _ := flagSet.GetString(flags.FlagGasPrices)
|
||||
f = f.WithGasPrices(gasPricesStr)
|
||||
|
||||
@@ -169,20 +162,6 @@ func (f Factory) WithFees(fees string) Factory {
|
||||
return f
|
||||
}
|
||||
|
||||
// WithTips returns a copy of the Factory with an updated tip.
|
||||
func (f Factory) WithTips(tip, tipper string) Factory {
|
||||
parsedTips, err := sdk.ParseCoinsNormalized(tip)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
f.tip = &tx.Tip{
|
||||
Tipper: tipper,
|
||||
Amount: parsedTips,
|
||||
}
|
||||
return f
|
||||
}
|
||||
|
||||
// WithGasPrices returns a copy of the Factory with updated gas prices.
|
||||
func (f Factory) WithGasPrices(gasPrices string) Factory {
|
||||
parsedGasPrices, err := sdk.ParseDecCoins(gasPrices)
|
||||
|
||||
@@ -3,7 +3,6 @@ package tx_test
|
||||
import (
|
||||
"github.com/cosmos/cosmos-sdk/testutil/testdata"
|
||||
"github.com/cosmos/cosmos-sdk/types"
|
||||
typestx "github.com/cosmos/cosmos-sdk/types/tx"
|
||||
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
||||
)
|
||||
|
||||
@@ -19,5 +18,4 @@ var (
|
||||
msg1 = banktypes.NewMsgSend(addr1, addr2, types.NewCoins(types.NewInt64Coin("wack", 2)))
|
||||
|
||||
chainID = "test-chain"
|
||||
tip = &typestx.Tip{Tipper: addr1.String(), Amount: testdata.NewTestFeeAmount()}
|
||||
)
|
||||
|
||||
@@ -393,13 +393,6 @@ func makeAuxSignerData(clientCtx client.Context, f Factory, msgs ...sdk.Msg) (tx
|
||||
return tx.AuxSignerData{}, err
|
||||
}
|
||||
|
||||
if f.tip != nil {
|
||||
if _, err := sdk.AccAddressFromBech32(f.tip.Tipper); err != nil {
|
||||
return tx.AuxSignerData{}, sdkerrors.ErrInvalidAddress.Wrap("tipper must be a bech32 address")
|
||||
}
|
||||
b.SetTip(f.tip)
|
||||
}
|
||||
|
||||
err = b.SetSignMode(f.SignMode())
|
||||
if err != nil {
|
||||
return tx.AuxSignerData{}, err
|
||||
|
||||
@@ -9,8 +9,6 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
"google.golang.org/grpc"
|
||||
|
||||
"cosmossdk.io/math"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/tx"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
@@ -388,22 +386,12 @@ func TestPreprocessHook(t *testing.T) {
|
||||
extAny, err := codectypes.NewAnyWithValue(extVal)
|
||||
requireT.NoError(err)
|
||||
|
||||
coin := sdk.Coin{
|
||||
Denom: "atom",
|
||||
Amount: math.NewInt(20),
|
||||
}
|
||||
newTip := &txtypes.Tip{
|
||||
Amount: sdk.Coins{coin},
|
||||
Tipper: "galaxy",
|
||||
}
|
||||
|
||||
preprocessHook := client.PreprocessTxFn(func(chainID string, key keyring.KeyType, tx client.TxBuilder) error {
|
||||
extensionBuilder, ok := tx.(authtx.ExtensionOptionsTxBuilder)
|
||||
requireT.True(ok)
|
||||
|
||||
// Set new extension and tip
|
||||
extensionBuilder.SetExtensionOptions(extAny)
|
||||
tx.SetTip(newTip)
|
||||
|
||||
return nil
|
||||
})
|
||||
@@ -435,9 +423,6 @@ func TestPreprocessHook(t *testing.T) {
|
||||
|
||||
opt := hasExtOptsTx.GetExtensionOptions()[0]
|
||||
requireT.Equal(opt, extAny)
|
||||
|
||||
tip := txb.GetTx().GetTip()
|
||||
requireT.Equal(tip, newTip)
|
||||
}
|
||||
|
||||
func testSigners(require *require.Assertions, tr signing.Tx, pks ...cryptotypes.PubKey) []signingtypes.SignatureV2 {
|
||||
|
||||
@@ -47,7 +47,6 @@ type (
|
||||
SetFeeAmount(amount sdk.Coins)
|
||||
SetFeePayer(feePayer sdk.AccAddress)
|
||||
SetGasLimit(limit uint64)
|
||||
SetTip(tip *tx.Tip)
|
||||
SetTimeoutHeight(height uint64)
|
||||
SetFeeGranter(feeGranter sdk.AccAddress)
|
||||
AddAuxSignerData(tx.AuxSignerData) error
|
||||
|
||||
Reference in New Issue
Block a user