Skip to content

Commit

Permalink
Merge PR cosmos#5795: Proto Transaction Migration
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderbez authored Mar 17, 2020
2 parents a6547c3 + 91115fd commit f31b625
Show file tree
Hide file tree
Showing 23 changed files with 4,425 additions and 880 deletions.
20 changes: 19 additions & 1 deletion client/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -25,6 +26,8 @@ type CLIContext struct {
FromAddress sdk.AccAddress
Client rpcclient.Client
ChainID string
TxGenerator clientx.Generator
Marshaler codec.Marshaler
Keybase keys.Keybase
Input io.Reader
Output io.Writer
Expand All @@ -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
Expand Down Expand Up @@ -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.Generator) 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
Expand Down
38 changes: 38 additions & 0 deletions client/tx/tx.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package tx

import (
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
)

type (
// Generator defines an interface a client can utilize to generate an
// application-defined concrete transaction type. The type returned must
// implement ClientTx.
Generator interface {
NewTx() ClientTx
}

// ClientTx defines an interface which an application-defined concrete transaction
// type must implement. Namely, it must be able to set messages, generate
// signatures, and provide canonical bytes to sign over. The transaction must
// also know how to encode itself.
ClientTx interface {
sdk.Tx
codec.ProtoMarshaler

SetMsgs(...sdk.Msg) error
GetSignatures() []sdk.Signature
SetSignatures(...sdk.Signature)
GetFee() sdk.Fee
SetFee(sdk.Fee)
GetMemo() string
SetMemo(string)

// CanonicalSignBytes returns the canonical JSON bytes to sign over, given a
// chain ID, along with an account and sequence number. The JSON encoding
// ensures all field names adhere to their proto definition, default values
// are omitted, and follows the JSON Canonical Form.
CanonicalSignBytes(cid string, num, seq uint64) ([]byte, error)
}
)
Loading

0 comments on commit f31b625

Please sign in to comment.