Decouple client/tx from x/auth (#5992)
As part of #5864 part 2), this PR decouples the new client/tx package from x/auth (as an incremental step to deprecating all the tx logic in x/auth) and adds StdFee, StdSignature, StdSignMsgBase and StdTxBase to codec/std, while deprecating the corresponding types in x/auth.
This commit is contained in:
@@ -60,8 +60,6 @@ var (
|
||||
ValidateGenAccounts = types.ValidateGenAccounts
|
||||
GetGenesisStateFromAppState = types.GetGenesisStateFromAppState
|
||||
NewStdSignature = types.NewStdSignature
|
||||
NewStdTxBase = types.NewStdTxBase
|
||||
NewStdSignDocBase = types.NewStdSignDocBase
|
||||
|
||||
// variable aliases
|
||||
ModuleCdc = types.ModuleCdc
|
||||
@@ -91,6 +89,4 @@ type (
|
||||
TxBuilder = types.TxBuilder
|
||||
GenesisAccountIterator = types.GenesisAccountIterator
|
||||
Codec = types.Codec
|
||||
StdSignDocBase = types.StdSignDocBase
|
||||
StdTxBase = types.StdTxBase
|
||||
)
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/client/context"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/types/errors"
|
||||
"github.com/cosmos/cosmos-sdk/types/rest"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
)
|
||||
@@ -30,7 +31,7 @@ func WriteGenerateStdTxResponse(w http.ResponseWriter, cliCtx context.CLIContext
|
||||
|
||||
if br.Simulate || simAndExec {
|
||||
if gasAdj < 0 {
|
||||
rest.WriteErrorResponse(w, http.StatusBadRequest, types.ErrorInvalidGasAdjustment.Error())
|
||||
rest.WriteErrorResponse(w, http.StatusBadRequest, errors.ErrorInvalidGasAdjustment.Error())
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
+3
-2
@@ -18,6 +18,7 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/client/keys"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
)
|
||||
|
||||
@@ -193,7 +194,7 @@ func SignStdTx(
|
||||
|
||||
// check whether the address is a signer
|
||||
if !isTxSigner(sdk.AccAddress(addr), stdTx.GetSigners()) {
|
||||
return signedStdTx, fmt.Errorf("%s: %s", authtypes.ErrorInvalidSigner, name)
|
||||
return signedStdTx, fmt.Errorf("%s: %s", sdkerrors.ErrorInvalidSigner, name)
|
||||
}
|
||||
|
||||
if !offline {
|
||||
@@ -216,7 +217,7 @@ func SignStdTxWithSignerAddress(
|
||||
|
||||
// check whether the address is a signer
|
||||
if !isTxSigner(addr, stdTx.GetSigners()) {
|
||||
return signedStdTx, fmt.Errorf("%s: %s", authtypes.ErrorInvalidSigner, name)
|
||||
return signedStdTx, fmt.Errorf("%s: %s", sdkerrors.ErrorInvalidSigner, name)
|
||||
}
|
||||
|
||||
if !offline {
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrorInvalidSigner = sdkerrors.Register(ModuleName, 2, "tx intended signer does not match the given signer")
|
||||
ErrorInvalidGasAdjustment = sdkerrors.Register(ModuleName, 3, "invalid gas adjustment")
|
||||
)
|
||||
+16
-19
@@ -17,7 +17,15 @@ import (
|
||||
// MaxGasWanted defines the max gas allowed.
|
||||
const MaxGasWanted = uint64((1 << 63) - 1)
|
||||
|
||||
// NewStdFee returns a new instance of StdFee
|
||||
// Deprecated: StdFee includes the amount of coins paid in fees and the maximum
|
||||
// gas to be used by the transaction. The ratio yields an effective "gasprice",
|
||||
// which must be above some miminum to be accepted into the mempool.
|
||||
type StdFee struct {
|
||||
Amount sdk.Coins `json:"amount" yaml:"amount"`
|
||||
Gas uint64 `json:"gas" yaml:"gas"`
|
||||
}
|
||||
|
||||
// Deprecated: NewStdFee returns a new instance of StdFee
|
||||
func NewStdFee(gas uint64, amount sdk.Coins) StdFee {
|
||||
return StdFee{
|
||||
Amount: amount,
|
||||
@@ -58,6 +66,7 @@ func (fee StdFee) GasPrices() sdk.DecCoins {
|
||||
return sdk.NewDecCoinsFromCoins(fee.Amount...).QuoDec(sdk.NewDec(int64(fee.Gas)))
|
||||
}
|
||||
|
||||
// Deprecated
|
||||
func NewStdSignature(pk crypto.PubKey, sig []byte) StdSignature {
|
||||
var pkBz []byte
|
||||
if pk != nil {
|
||||
@@ -112,24 +121,6 @@ func (ss StdSignature) MarshalYAML() (interface{}, error) {
|
||||
return string(bz), err
|
||||
}
|
||||
|
||||
func NewStdTxBase(fee StdFee, sigs []StdSignature, memo string) StdTxBase {
|
||||
return StdTxBase{
|
||||
Fee: fee,
|
||||
Signatures: sigs,
|
||||
Memo: memo,
|
||||
}
|
||||
}
|
||||
|
||||
func NewStdSignDocBase(num, seq uint64, cid, memo string, fee StdFee) StdSignDocBase {
|
||||
return StdSignDocBase{
|
||||
ChainID: cid,
|
||||
AccountNumber: num,
|
||||
Sequence: seq,
|
||||
Memo: memo,
|
||||
Fee: fee,
|
||||
}
|
||||
}
|
||||
|
||||
// CountSubKeys counts the total number of keys for a multi-sig public key.
|
||||
func CountSubKeys(pub crypto.PubKey) int {
|
||||
v, ok := pub.(multisig.PubKeyMultisigThreshold)
|
||||
@@ -320,6 +311,12 @@ func StdSignBytes(chainID string, accnum uint64, sequence uint64, fee StdFee, ms
|
||||
return sdk.MustSortJSON(bz)
|
||||
}
|
||||
|
||||
// Deprecated: StdSignature represents a sig
|
||||
type StdSignature struct {
|
||||
PubKey []byte `json:"pub_key" yaml:"pub_key"` // optional
|
||||
Signature []byte `json:"signature" yaml:"signature"`
|
||||
}
|
||||
|
||||
// DefaultTxDecoder logic for standard transaction decoding
|
||||
func DefaultTxDecoder(cdc *codec.Codec) sdk.TxDecoder {
|
||||
return func(txBytes []byte) (sdk.Tx, error) {
|
||||
|
||||
+37
-1149
File diff suppressed because it is too large
Load Diff
@@ -2,7 +2,6 @@ syntax = "proto3";
|
||||
package cosmos_sdk.x.auth.v1;
|
||||
|
||||
import "third_party/proto/gogoproto/gogo.proto";
|
||||
import "types/types.proto";
|
||||
|
||||
option go_package = "github.com/cosmos/cosmos-sdk/x/auth/types";
|
||||
|
||||
@@ -19,27 +18,6 @@ message BaseAccount {
|
||||
uint64 sequence = 4;
|
||||
}
|
||||
|
||||
// StdFee includes the amount of coins paid in fees and the maximum
|
||||
// gas to be used by the transaction. The ratio yields an effective "gasprice",
|
||||
// which must be above some miminum to be accepted into the mempool.
|
||||
message StdFee {
|
||||
option (gogoproto.goproto_getters) = false;
|
||||
option (gogoproto.equal) = true;
|
||||
|
||||
repeated cosmos_sdk.v1.Coin amount = 1
|
||||
[(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"];
|
||||
uint64 gas = 2;
|
||||
}
|
||||
|
||||
// StdSignature defines a signature structure that contains the signature of a
|
||||
// transaction and an optional public key.
|
||||
message StdSignature {
|
||||
option (gogoproto.goproto_getters) = false;
|
||||
|
||||
bytes pub_key = 1 [(gogoproto.jsontag) = "public_key,omitempty", (gogoproto.moretags) = "yaml:\"public_key\""];
|
||||
bytes signature = 2;
|
||||
}
|
||||
|
||||
// Params defines the parameters for the auth module.
|
||||
message Params {
|
||||
option (gogoproto.equal) = true;
|
||||
@@ -49,25 +27,8 @@ message Params {
|
||||
uint64 tx_sig_limit = 2 [(gogoproto.moretags) = "yaml:\"tx_sig_limit\""];
|
||||
uint64 tx_size_cost_per_byte = 3 [(gogoproto.moretags) = "yaml:\"tx_size_cost_per_byte\""];
|
||||
uint64 sig_verify_cost_ed25519 = 4
|
||||
[(gogoproto.customname) = "SigVerifyCostED25519", (gogoproto.moretags) = "yaml:\"sig_verify_cost_ed25519\""];
|
||||
[(gogoproto.customname) = "SigVerifyCostED25519", (gogoproto.moretags) = "yaml:\"sig_verify_cost_ed25519\""];
|
||||
uint64 sig_verify_cost_secp256k1 = 5
|
||||
[(gogoproto.customname) = "SigVerifyCostSecp256k1", (gogoproto.moretags) = "yaml:\"sig_verify_cost_secp256k1\""];
|
||||
[(gogoproto.customname) = "SigVerifyCostSecp256k1", (gogoproto.moretags) = "yaml:\"sig_verify_cost_secp256k1\""];
|
||||
}
|
||||
|
||||
// StdTxBase defines a transaction base which application-level concrete transaction
|
||||
// types can extend.
|
||||
message StdTxBase {
|
||||
StdFee fee = 1 [(gogoproto.nullable) = false];
|
||||
repeated StdSignature signatures = 2 [(gogoproto.nullable) = false];
|
||||
string memo = 3;
|
||||
}
|
||||
|
||||
// StdSignDocBase defines the base structure for which applications can extend
|
||||
// to define the concrete structure that signers sign over.
|
||||
message StdSignDocBase {
|
||||
string chain_id = 1 [(gogoproto.customname) = "ChainID", (gogoproto.moretags) = "yaml:\"chain_id\""];
|
||||
uint64 account_number = 2 [(gogoproto.moretags) = "yaml:\"account_number\""];
|
||||
uint64 sequence = 3;
|
||||
string memo = 4;
|
||||
StdFee fee = 5 [(gogoproto.nullable) = false];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user