cosmos-sdk/x/auth/tx/config.go

73 lines
1.9 KiB
Go

package tx
import (
"fmt"
signingtypes "github.com/cosmos/cosmos-sdk/types/tx/signing"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth/signing"
)
type config struct {
pubkeyCodec types.PublicKeyCodec
handler signing.SignModeHandler
decoder sdk.TxDecoder
encoder sdk.TxEncoder
jsonDecoder sdk.TxDecoder
jsonEncoder sdk.TxEncoder
protoCodec *codec.ProtoCodec
}
// NewTxConfig returns a new protobuf TxConfig using the provided ProtoCodec, PublicKeyCodec and sign modes. The
// first enabled sign mode will become the default sign mode.
func NewTxConfig(protoCodec *codec.ProtoCodec, pubkeyCodec types.PublicKeyCodec, enabledSignModes []signingtypes.SignMode) client.TxConfig {
return &config{
pubkeyCodec: pubkeyCodec,
handler: makeSignModeHandler(enabledSignModes),
decoder: DefaultTxDecoder(protoCodec, pubkeyCodec),
encoder: DefaultTxEncoder(),
jsonDecoder: DefaultJSONTxDecoder(protoCodec, pubkeyCodec),
jsonEncoder: DefaultJSONTxEncoder(),
protoCodec: protoCodec,
}
}
func (g config) NewTxBuilder() client.TxBuilder {
return newBuilder(g.pubkeyCodec)
}
// WrapTxBuilder returns a builder from provided transaction
func (g config) WrapTxBuilder(newTx sdk.Tx) (client.TxBuilder, error) {
newBuilder, ok := newTx.(*builder)
if !ok {
return nil, fmt.Errorf("expected %T, got %T", &builder{}, newTx)
}
return newBuilder, nil
}
func (g config) SignModeHandler() signing.SignModeHandler {
return g.handler
}
func (g config) TxEncoder() sdk.TxEncoder {
return g.encoder
}
func (g config) TxDecoder() sdk.TxDecoder {
return g.decoder
}
func (g config) TxJSONEncoder() sdk.TxEncoder {
return g.jsonEncoder
}
func (g config) TxJSONDecoder() sdk.TxDecoder {
return g.jsonDecoder
}