This repository has been archived by the owner on Dec 8, 2022. It is now read-only.
forked from cosmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.go
69 lines (55 loc) · 1.72 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package tx
import (
"fmt"
signingtypes "github.com/Pylons-tech/cosmos-sdk/types/tx/signing"
"github.com/Pylons-tech/cosmos-sdk/codec"
"github.com/Pylons-tech/cosmos-sdk/client"
sdk "github.com/Pylons-tech/cosmos-sdk/types"
"github.com/Pylons-tech/cosmos-sdk/x/auth/signing"
)
type config struct {
handler signing.SignModeHandler
decoder sdk.TxDecoder
encoder sdk.TxEncoder
jsonDecoder sdk.TxDecoder
jsonEncoder sdk.TxEncoder
protoCodec codec.ProtoCodecMarshaler
}
// NewTxConfig returns a new protobuf TxConfig using the provided ProtoCodec and sign modes. The
// first enabled sign mode will become the default sign mode.
func NewTxConfig(protoCodec codec.ProtoCodecMarshaler, enabledSignModes []signingtypes.SignMode) client.TxConfig {
return &config{
handler: makeSignModeHandler(enabledSignModes),
decoder: DefaultTxDecoder(protoCodec),
encoder: DefaultTxEncoder(),
jsonDecoder: DefaultJSONTxDecoder(protoCodec),
jsonEncoder: DefaultJSONTxEncoder(protoCodec),
protoCodec: protoCodec,
}
}
func (g config) NewTxBuilder() client.TxBuilder {
return newBuilder()
}
// WrapTxBuilder returns a builder from provided transaction
func (g config) WrapTxBuilder(newTx sdk.Tx) (client.TxBuilder, error) {
newBuilder, ok := newTx.(*wrapper)
if !ok {
return nil, fmt.Errorf("expected %T, got %T", &wrapper{}, 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
}