Migrate {x/auth, x/gov, x/staking} missing CLI queries to proto (#6994)
* Fix error code * Fix decoder * Fix typo * Fix decode * refactor * Migrate SearchTxsResult to proto * fix MarkEventsToIndex * lint++ * Fix output * Add QueryTxCmd cli test * Add fmt * Put txBuilder in types/tx * Add GetAnyTx in TxBuilder * Add new IsAnyTx * Rename to IntoAny * Fix bug * fmt Co-authored-by: Marie <marie.gauthier63@gmail.com> * Fix ibc CLI to use proto * Fix any MarshalJSON * Fix test * Make tx.Tx implement sdk.Tx * Register sdk.Tx * Fix lint * Allow DefaultJSONTxEncoder to take tx.Tx * refactor * Rename variable * remove fmt Co-authored-by: Anil Kumar Kammari <anil@vitwit.com> Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com> Co-authored-by: Aleksandr Bezobchuk <aleks.bezobchuk@gmail.com> Co-authored-by: Amaury Martiny <amaury.martiny@protonmail.com> Co-authored-by: Marie <marie.gauthier63@gmail.com>
This commit is contained in:
co-authored by
Marie
Anil Kumar Kammari
Alexander Bezobchuk
Aleksandr Bezobchuk
Amaury Martiny
parent
d84296a5fc
commit
b2348180b8
+99
-3
@@ -1,16 +1,106 @@
|
||||
package tx
|
||||
|
||||
import (
|
||||
fmt "fmt"
|
||||
|
||||
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||
)
|
||||
|
||||
// MaxGasWanted defines the max gas allowed.
|
||||
const MaxGasWanted = uint64((1 << 63) - 1)
|
||||
|
||||
var _, _ codectypes.UnpackInterfacesMessage = &Tx{}, &TxBody{}
|
||||
var _ sdk.Tx = &Tx{}
|
||||
|
||||
// GetMsgs implements the GetMsgs method on sdk.Tx.
|
||||
func (t *Tx) GetMsgs() []sdk.Msg {
|
||||
if t == nil || t.Body == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
anys := t.Body.Messages
|
||||
res := make([]sdk.Msg, len(anys))
|
||||
for i, any := range anys {
|
||||
msg := any.GetCachedValue().(sdk.Msg)
|
||||
res[i] = msg
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
// ValidateBasic implements the ValidateBasic method on sdk.Tx.
|
||||
func (t *Tx) ValidateBasic() error {
|
||||
if t == nil {
|
||||
return fmt.Errorf("bad Tx")
|
||||
}
|
||||
|
||||
body := t.Body
|
||||
if body == nil {
|
||||
return fmt.Errorf("missing TxBody")
|
||||
}
|
||||
|
||||
authInfo := t.AuthInfo
|
||||
if authInfo == nil {
|
||||
return fmt.Errorf("missing AuthInfo")
|
||||
}
|
||||
|
||||
fee := authInfo.Fee
|
||||
if fee == nil {
|
||||
return fmt.Errorf("missing fee")
|
||||
}
|
||||
|
||||
if fee.GasLimit > MaxGasWanted {
|
||||
return sdkerrors.Wrapf(
|
||||
sdkerrors.ErrInvalidRequest,
|
||||
"invalid gas supplied; %d > %d", fee.GasLimit, MaxGasWanted,
|
||||
)
|
||||
}
|
||||
|
||||
if fee.Amount.IsAnyNegative() {
|
||||
return sdkerrors.Wrapf(
|
||||
sdkerrors.ErrInsufficientFee,
|
||||
"invalid fee provided: %s", fee.Amount,
|
||||
)
|
||||
}
|
||||
|
||||
sigs := t.Signatures
|
||||
|
||||
if len(sigs) == 0 {
|
||||
return sdkerrors.ErrNoSignatures
|
||||
}
|
||||
|
||||
if len(sigs) != len(t.GetSigners()) {
|
||||
return sdkerrors.Wrapf(
|
||||
sdkerrors.ErrUnauthorized,
|
||||
"wrong number of signers; expected %d, got %d", t.GetSigners(), len(sigs),
|
||||
)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetSigners retrieves all the signers of a tx.
|
||||
func (t *Tx) GetSigners() []sdk.AccAddress {
|
||||
var signers []sdk.AccAddress
|
||||
seen := map[string]bool{}
|
||||
|
||||
for _, msg := range t.GetMsgs() {
|
||||
for _, addr := range msg.GetSigners() {
|
||||
if !seen[addr.String()] {
|
||||
signers = append(signers, addr)
|
||||
seen[addr.String()] = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return signers
|
||||
}
|
||||
|
||||
// UnpackInterfaces implements the UnpackInterfaceMessages.UnpackInterfaces method
|
||||
func (m *Tx) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error {
|
||||
if m.Body != nil {
|
||||
return m.Body.UnpackInterfaces(unpacker)
|
||||
func (t *Tx) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error {
|
||||
if t.Body != nil {
|
||||
return t.Body.UnpackInterfaces(unpacker)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -26,3 +116,9 @@ func (m *TxBody) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// RegisterInterfaces registers the sdk.Tx interface.
|
||||
func RegisterInterfaces(registry codectypes.InterfaceRegistry) {
|
||||
registry.RegisterInterface("cosmos.tx.v1beta1.Tx", (*sdk.Tx)(nil))
|
||||
registry.RegisterImplementations((*sdk.Tx)(nil), &Tx{})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user