Update context
This commit is contained in:
parent
7838d750e1
commit
c49af0b8dd
|
@ -14,6 +14,7 @@ import (
|
|||
rpcclient "github.com/tendermint/tendermint/rpc/client"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
clientx "github.com/cosmos/cosmos-sdk/client/tx"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
|
@ -25,6 +26,8 @@ type CLIContext struct {
|
|||
FromAddress sdk.AccAddress
|
||||
Client rpcclient.Client
|
||||
ChainID string
|
||||
TxGenerator clientx.TxGenerator
|
||||
Marshaler codec.Marshaler
|
||||
Keybase keys.Keybase
|
||||
Input io.Reader
|
||||
Output io.Writer
|
||||
|
@ -36,13 +39,15 @@ type CLIContext struct {
|
|||
BroadcastMode string
|
||||
Verifier tmlite.Verifier
|
||||
FromName string
|
||||
Codec *codec.Codec
|
||||
TrustNode bool
|
||||
UseLedger bool
|
||||
Simulate bool
|
||||
GenerateOnly bool
|
||||
Indent bool
|
||||
SkipConfirm bool
|
||||
|
||||
// TODO: Deprecated (remove).
|
||||
Codec *codec.Codec
|
||||
}
|
||||
|
||||
// NewCLIContextWithInputAndFrom returns a new initialized CLIContext with parameters from the
|
||||
|
@ -130,7 +135,20 @@ func (ctx CLIContext) WithInput(r io.Reader) CLIContext {
|
|||
return ctx
|
||||
}
|
||||
|
||||
// WithTxGenerator returns a copy of the CLIContext with an updated TxGenerator.
|
||||
func (ctx CLIContext) WithTxGenerator(txg clientx.TxGenerator) CLIContext {
|
||||
ctx.TxGenerator = txg
|
||||
return ctx
|
||||
}
|
||||
|
||||
// WithMarshaler returns a copy of the CLIContext with an updated Marshaler.
|
||||
func (ctx CLIContext) WithMarshaler(m codec.Marshaler) CLIContext {
|
||||
ctx.Marshaler = m
|
||||
return ctx
|
||||
}
|
||||
|
||||
// WithCodec returns a copy of the context with an updated codec.
|
||||
// TODO: Deprecated (remove).
|
||||
func (ctx CLIContext) WithCodec(cdc *codec.Codec) CLIContext {
|
||||
ctx.Codec = cdc
|
||||
return ctx
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package client
|
||||
package tx
|
||||
|
||||
import (
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
|
@ -6,14 +6,6 @@ import (
|
|||
)
|
||||
|
||||
type (
|
||||
// ClientMarshaler defines an interface that REST and CLI handler will use to
|
||||
// create application-specific transactions and be able to serialize types
|
||||
// specific to the application including transactions.
|
||||
ClientMarshaler interface {
|
||||
TxGenerator
|
||||
codec.Marshaler
|
||||
}
|
||||
|
||||
// TxGenerator defines an interface a client can utilize to generate an
|
||||
// application-defined concrete transaction type. The type returned must
|
||||
// implement ClientTx.
|
|
@ -1,17 +1,27 @@
|
|||
package std
|
||||
|
||||
import (
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
clientx "github.com/cosmos/cosmos-sdk/client/tx"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
||||
)
|
||||
|
||||
var (
|
||||
_ sdk.Tx = (*Transaction)(nil)
|
||||
_ client.ClientTx = (*Transaction)(nil)
|
||||
_ sdk.Tx = (*Transaction)(nil)
|
||||
_ clientx.ClientTx = (*Transaction)(nil)
|
||||
_ clientx.TxGenerator = TxGenerator{}
|
||||
)
|
||||
|
||||
// TxGenerator defines a transaction generator that allows clients to construct
|
||||
// transactions.
|
||||
type TxGenerator struct{}
|
||||
|
||||
// NewTx returns a reference to an empty Transaction type.
|
||||
func (TxGenerator) NewTx() clientx.ClientTx {
|
||||
return &Transaction{}
|
||||
}
|
||||
|
||||
func NewTransaction(fee auth.StdFee, memo string, sdkMsgs []sdk.Msg) (*Transaction, error) {
|
||||
tx := &Transaction{
|
||||
StdTxBase: auth.NewStdTxBase(fee, nil, memo),
|
||||
|
|
|
@ -123,18 +123,11 @@ type ClientTx interface {
|
|||
}
|
||||
```
|
||||
|
||||
We then extend `codec.Marshaler` to also require fulfillment of `TxGenerator`.
|
||||
We then update `CLIContext` to have two new fields: `TxGenerator` and `TxGenerator`.
|
||||
|
||||
```go
|
||||
type ClientMarshaler interface {
|
||||
TxGenerator
|
||||
codec.Marshaler
|
||||
}
|
||||
```
|
||||
|
||||
Then, each module will at the minimum accept a `ClientMarshaler` instead of a concrete
|
||||
Then, each module will at the minimum accept a `Marshaler` instead of a concrete
|
||||
Amino codec. If the module needs to work with any interface types, it will use
|
||||
the `Codec` interface defined by the module which also extends `ClientMarshaler`.
|
||||
the `Codec` interface defined by the module which also extends `Marshaler`.
|
||||
|
||||
## Future Improvements
|
||||
|
||||
|
|
Loading…
Reference in New Issue