Skip to content

Commit

Permalink
Update ADR and types
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderbez committed Mar 12, 2020
1 parent 5513927 commit b38d3ae
Show file tree
Hide file tree
Showing 8 changed files with 250 additions and 200 deletions.
42 changes: 42 additions & 0 deletions client/tx.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package client

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

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.
TxGenerator 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(cid string, num, seq uint64) ([]byte, error)
}
)
200 changes: 100 additions & 100 deletions codec/std/codec.pb.go

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions codec/std/codec.proto
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,9 @@ message Content {
message Transaction {
option (gogoproto.goproto_getters) = false;

cosmos_sdk.x.auth.v1.StdTxBase base = 1 [(gogoproto.nullable) = false];
repeated Message msgs = 2 [(gogoproto.nullable) = false];
cosmos_sdk.x.auth.v1.StdTxBase base = 1
[(gogoproto.jsontag) = "", (gogoproto.embed) = true, (gogoproto.nullable) = false];
repeated Message msgs = 2 [(gogoproto.nullable) = false];
}

// Message defines the set of valid concrete message types that can be used to
Expand Down
11 changes: 6 additions & 5 deletions docs/architecture/adr-020-protobuf-transaction-encoding.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,20 +104,21 @@ and messages.
```go
type TxGenerator interface {
NewTx() ClientTx
SignBytes func(chainID string, num, seq uint64, fee StdFee, msgs []sdk.Msg, memo string) ([]byte, error)
}

type ClientTx interface {
sdk.Tx
codec.ProtoMarshaler

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

CanonicalSignBytes(cid string, num, seq uint64) ([]byte, error)
}
```

Expand Down
71 changes: 43 additions & 28 deletions types/tx_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,60 @@ package types

import (
"encoding/json"

"github.com/tendermint/tendermint/crypto"
)

// Transactions messages must fulfill the Msg
type Msg interface {
type (
// Msg defines the interface a transaction message must fulfill.
Msg interface {

// Return the message type.
// Must be alphanumeric or empty.
Route() string
// Return the message type.
// Must be alphanumeric or empty.
Route() string

// Returns a human-readable string for the message, intended for utilization
// within tags
Type() string
// Returns a human-readable string for the message, intended for utilization
// within tags
Type() string

// ValidateBasic does a simple validation check that
// doesn't require access to any other information.
ValidateBasic() error
// ValidateBasic does a simple validation check that
// doesn't require access to any other information.
ValidateBasic() error

// Get the canonical byte representation of the Msg.
GetSignBytes() []byte
// Get the canonical byte representation of the Msg.
GetSignBytes() []byte

// Signers returns the addrs of signers that must sign.
// CONTRACT: All signatures must be present to be valid.
// CONTRACT: Returns addrs in some deterministic order.
GetSigners() []AccAddress
}
// Signers returns the addrs of signers that must sign.
// CONTRACT: All signatures must be present to be valid.
// CONTRACT: Returns addrs in some deterministic order.
GetSigners() []AccAddress
}

//__________________________________________________________
// Fee defines an interface for an application application-defined concrete
// transaction type to be able to set and return the transaction fee.
Fee interface {
GetGas() uint64
GetAmount() Coins
}

// Transactions objects must fulfill the Tx
type Tx interface {
// Gets the all the transaction's messages.
GetMsgs() []Msg
// Signature defines an interface for an application application-defined
// concrete transaction type to be able to set and return transaction signatures.
Signature interface {
GetPubKey() crypto.PubKey
GetSignature() []byte
}

// ValidateBasic does a simple and lightweight validation check that doesn't
// require access to any other information.
ValidateBasic() error
}
// Tx defines the interface a transaction must fulfill.
Tx interface {
// Gets the all the transaction's messages.
GetMsgs() []Msg

// ValidateBasic does a simple and lightweight validation check that doesn't
// require access to any other information.
ValidateBasic() error
}
)

//__________________________________________________________

// TxDecoder unmarshals transaction bytes
type TxDecoder func(txBytes []byte) (Tx, error)
Expand Down
4 changes: 4 additions & 0 deletions x/auth/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ var (
MakeSignature = types.MakeSignature
ValidateGenAccounts = types.ValidateGenAccounts
GetGenesisStateFromAppState = types.GetGenesisStateFromAppState
NewStdSignature = types.NewStdSignature
NewStdTxBase = types.NewStdTxBase
NewStdSignDocBase = types.NewStdSignDocBase

// variable aliases
ModuleCdc = types.ModuleCdc
Expand Down Expand Up @@ -89,4 +92,5 @@ type (
GenesisAccountIterator = types.GenesisAccountIterator
Codec = types.Codec
StdSignDocBase = types.StdSignDocBase
StdTxBase = types.StdTxBase
)
114 changes: 50 additions & 64 deletions x/auth/types/types.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion x/auth/types/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ message BaseAccount {
// gas to be used by the transaction. The ratio yields an effective "gasprice",
// which must be above some miminum to be accepted into the mempool.
message StdFee {
option (gogoproto.equal) = true;
option (gogoproto.goproto_getters) = false;
option (gogoproto.equal) = true;

repeated cosmos_sdk.v1.Coin amount = 1
[(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"];
Expand Down

0 comments on commit b38d3ae

Please sign in to comment.