* Update genutil collect and gentx to use TxGenerator * Remove print statement * Use Tx in genutil DeliverGenTxs * Use Tx in genutil genesis_state * Use Tx in ValidateGenesis * Use amino txJSONDecoder and txBinaryEncoder in genutil InitGenesis * Use TxConfig in place of TxGenerator * Add gentx tests * Remove commented line * Test fixes * Apply suggestions from code review Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com> * Fixes * Fixes * Fixes * Fixes * Remove unneeded test case (doesn't apply to proto marshaling) * linting * Refactor to use new TxEncodingConfig interface in genutil module * Replace golang/protobuf with gogo/protobuf package * Use TxEncodingConfig in InitTestnet * Remove old amino.go file * Use TxJSONDecoder in genutil ValidateGenesis * Add parameter to ValidateGenesis to resolve the tx JSON decoder issue * Address review feedback Co-authored-by: Jack Zampolin <jack.zampolin@gmail.com> Co-authored-by: Aaron Craelius <aaronc@users.noreply.github.com> Co-authored-by: Aaron Craelius <aaron@regen.network> Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
85 lines
2.0 KiB
Go
85 lines
2.0 KiB
Go
package tx
|
|
|
|
import (
|
|
"github.com/tendermint/tendermint/crypto"
|
|
|
|
"github.com/cosmos/cosmos-sdk/codec"
|
|
"github.com/cosmos/cosmos-sdk/codec/types"
|
|
|
|
"github.com/cosmos/cosmos-sdk/types/tx"
|
|
|
|
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
)
|
|
|
|
// DefaultTxDecoder returns a default protobuf TxDecoder using the provided Marshaler and PublicKeyCodec
|
|
func DefaultTxDecoder(anyUnpacker types.AnyUnpacker, keyCodec cryptotypes.PublicKeyCodec) sdk.TxDecoder {
|
|
cdc := codec.NewProtoCodec(anyUnpacker)
|
|
return func(txBytes []byte) (sdk.Tx, error) {
|
|
var raw tx.TxRaw
|
|
err := cdc.UnmarshalBinaryBare(txBytes, &raw)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
var theTx tx.Tx
|
|
err = cdc.UnmarshalBinaryBare(txBytes, &theTx)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
pks, err := extractPubKeys(theTx, keyCodec)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &builder{
|
|
tx: &theTx,
|
|
bodyBz: raw.BodyBytes,
|
|
authInfoBz: raw.AuthInfoBytes,
|
|
pubKeys: pks,
|
|
pubkeyCodec: keyCodec,
|
|
}, nil
|
|
}
|
|
}
|
|
|
|
// DefaultTxDecoder returns a default protobuf JSON TxDecoder using the provided Marshaler and PublicKeyCodec
|
|
func DefaultJSONTxDecoder(anyUnpacker types.AnyUnpacker, keyCodec cryptotypes.PublicKeyCodec) sdk.TxDecoder {
|
|
cdc := codec.NewProtoCodec(anyUnpacker)
|
|
return func(txBytes []byte) (sdk.Tx, error) {
|
|
var theTx tx.Tx
|
|
err := cdc.UnmarshalJSON(txBytes, &theTx)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
pks, err := extractPubKeys(theTx, keyCodec)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &builder{
|
|
tx: &theTx,
|
|
pubKeys: pks,
|
|
pubkeyCodec: keyCodec,
|
|
}, nil
|
|
}
|
|
}
|
|
|
|
func extractPubKeys(tx tx.Tx, keyCodec cryptotypes.PublicKeyCodec) ([]crypto.PubKey, error) {
|
|
if tx.AuthInfo == nil {
|
|
return []crypto.PubKey{}, nil
|
|
}
|
|
|
|
signerInfos := tx.AuthInfo.SignerInfos
|
|
pks := make([]crypto.PubKey, len(signerInfos))
|
|
for i, si := range signerInfos {
|
|
pk, err := keyCodec.Decode(si.PublicKey)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
pks[i] = pk
|
|
}
|
|
return pks, nil
|
|
}
|