Some checks failed
Build SimApp / build (amd64) (push) Waiting to run
Build SimApp / build (arm64) (push) Waiting to run
CodeQL / Analyze (push) Waiting to run
Build & Push / build (push) Waiting to run
Run Gosec / Gosec (push) Waiting to run
Lint / golangci-lint (push) Waiting to run
Checks dependencies and mocks generation / Check go mod tidy (push) Waiting to run
Checks dependencies and mocks generation / Check up to date mocks (push) Waiting to run
System Tests / setup (push) Waiting to run
System Tests / test-system (push) Blocked by required conditions
System Tests / test-system-legacy (push) Blocked by required conditions
Tests / Code Coverage / split-test-files (push) Waiting to run
Tests / Code Coverage / tests (00) (push) Blocked by required conditions
Tests / Code Coverage / tests (01) (push) Blocked by required conditions
Tests / Code Coverage / tests (02) (push) Blocked by required conditions
Tests / Code Coverage / tests (03) (push) Blocked by required conditions
Tests / Code Coverage / test-integration (push) Waiting to run
Tests / Code Coverage / test-e2e (push) Waiting to run
Tests / Code Coverage / repo-analysis (push) Blocked by required conditions
Tests / Code Coverage / test-sim-nondeterminism (push) Waiting to run
Tests / Code Coverage / test-clientv2 (push) Waiting to run
Tests / Code Coverage / test-core (push) Waiting to run
Tests / Code Coverage / test-depinject (push) Waiting to run
Tests / Code Coverage / test-errors (push) Waiting to run
Tests / Code Coverage / test-math (push) Waiting to run
Tests / Code Coverage / test-schema (push) Waiting to run
Tests / Code Coverage / test-collections (push) Waiting to run
Tests / Code Coverage / test-cosmovisor (push) Waiting to run
Tests / Code Coverage / test-confix (push) Waiting to run
Tests / Code Coverage / test-store (push) Waiting to run
Tests / Code Coverage / test-log (push) Waiting to run
Tests / Code Coverage / test-x-tx (push) Waiting to run
Tests / Code Coverage / test-x-nft (push) Waiting to run
Tests / Code Coverage / test-x-circuit (push) Waiting to run
Tests / Code Coverage / test-x-feegrant (push) Waiting to run
Tests / Code Coverage / test-x-evidence (push) Waiting to run
Tests / Code Coverage / test-x-upgrade (push) Waiting to run
Tests / Code Coverage / test-tools-benchmark (push) Waiting to run
Build & Push SDK Proto Builder / build (push) Has been cancelled
146 lines
3.6 KiB
Go
146 lines
3.6 KiB
Go
package legacytx
|
|
|
|
import (
|
|
"github.com/cosmos/cosmos-sdk/codec"
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
|
"github.com/cosmos/cosmos-sdk/types/tx"
|
|
"github.com/cosmos/cosmos-sdk/types/tx/signing"
|
|
)
|
|
|
|
// StdTxBuilder wraps StdTx to implement to the context.TxBuilder interface.
|
|
// Note that this type just exists for backwards compatibility with amino StdTx
|
|
// and will not work for protobuf transactions.
|
|
type StdTxBuilder struct {
|
|
StdTx
|
|
cdc *codec.LegacyAmino
|
|
}
|
|
|
|
// SetMsgs implements TxBuilder.SetMsgs
|
|
func (s *StdTxBuilder) SetMsgs(msgs ...sdk.Msg) error {
|
|
s.Msgs = msgs
|
|
return nil
|
|
}
|
|
|
|
// SetSignatures implements TxBuilder.SetSignatures.
|
|
func (s *StdTxBuilder) SetSignatures(signatures ...signing.SignatureV2) error {
|
|
sigs := make([]StdSignature, len(signatures))
|
|
var err error
|
|
for i, sig := range signatures {
|
|
sigs[i], err = SignatureV2ToStdSignature(s.cdc, sig)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
s.Signatures = sigs
|
|
return nil
|
|
}
|
|
|
|
func (s *StdTxBuilder) SetFeeAmount(amount sdk.Coins) {
|
|
s.Fee.Amount = amount
|
|
}
|
|
|
|
func (s *StdTxBuilder) SetGasLimit(limit uint64) {
|
|
s.Fee.Gas = limit
|
|
}
|
|
|
|
// SetMemo implements TxBuilder.SetMemo
|
|
func (s *StdTxBuilder) SetMemo(memo string) {
|
|
s.Memo = memo
|
|
}
|
|
|
|
// SetTimeoutHeight sets the transaction's height timeout.
|
|
func (s *StdTxBuilder) SetTimeoutHeight(height uint64) {
|
|
s.TimeoutHeight = height
|
|
}
|
|
|
|
// SetFeeGranter does nothing for stdtx
|
|
func (s *StdTxBuilder) SetFeeGranter(_ sdk.AccAddress) {}
|
|
|
|
// SetFeePayer does nothing for stdtx
|
|
func (s *StdTxBuilder) SetFeePayer(_ sdk.AccAddress) {}
|
|
|
|
// AddAuxSignerData returns an error for StdTxBuilder.
|
|
func (s *StdTxBuilder) AddAuxSignerData(_ tx.AuxSignerData) error {
|
|
return sdkerrors.ErrLogic.Wrap("cannot use AuxSignerData with StdTxBuilder")
|
|
}
|
|
|
|
// StdTxConfig is a context.TxConfig for StdTx
|
|
type StdTxConfig struct {
|
|
Cdc *codec.LegacyAmino
|
|
}
|
|
|
|
// MarshalTx implements TxConfig.MarshalTx
|
|
func (s StdTxConfig) TxEncoder() sdk.TxEncoder {
|
|
return DefaultTxEncoder(s.Cdc)
|
|
}
|
|
|
|
func (s StdTxConfig) TxJSONEncoder() sdk.TxEncoder {
|
|
return func(tx sdk.Tx) ([]byte, error) {
|
|
return s.Cdc.MarshalJSON(tx)
|
|
}
|
|
}
|
|
|
|
func (s StdTxConfig) MarshalSignatureJSON(sigs []signing.SignatureV2) ([]byte, error) {
|
|
stdSigs := make([]StdSignature, len(sigs))
|
|
for i, sig := range sigs {
|
|
stdSig, err := SignatureV2ToStdSignature(s.Cdc, sig)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
stdSigs[i] = stdSig
|
|
}
|
|
return s.Cdc.MarshalJSON(stdSigs)
|
|
}
|
|
|
|
func (s StdTxConfig) UnmarshalSignatureJSON(bz []byte) ([]signing.SignatureV2, error) {
|
|
var stdSigs []StdSignature
|
|
err := s.Cdc.UnmarshalJSON(bz, &stdSigs)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
sigs := make([]signing.SignatureV2, len(stdSigs))
|
|
for i, stdSig := range stdSigs {
|
|
sig, err := StdSignatureToSignatureV2(s.Cdc, stdSig)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
sigs[i] = sig
|
|
}
|
|
|
|
return sigs, nil
|
|
}
|
|
|
|
// SignatureV2ToStdSignature converts a SignatureV2 to a StdSignature
|
|
// [Deprecated]
|
|
func SignatureV2ToStdSignature(cdc *codec.LegacyAmino, sig signing.SignatureV2) (StdSignature, error) {
|
|
var (
|
|
sigBz []byte
|
|
err error
|
|
)
|
|
|
|
if sig.Data != nil {
|
|
sigBz, err = SignatureDataToAminoSignature(cdc, sig.Data)
|
|
if err != nil {
|
|
return StdSignature{}, err
|
|
}
|
|
}
|
|
|
|
return StdSignature{
|
|
PubKey: sig.PubKey,
|
|
Signature: sigBz,
|
|
}, nil
|
|
}
|
|
|
|
// Unmarshaler is a generic type for Unmarshal functions
|
|
type Unmarshaler func(bytes []byte, ptr any) error
|
|
|
|
// DefaultTxEncoder logic for standard transaction encoding
|
|
func DefaultTxEncoder(cdc *codec.LegacyAmino) sdk.TxEncoder {
|
|
return func(tx sdk.Tx) ([]byte, error) {
|
|
return cdc.Marshal(tx)
|
|
}
|
|
}
|