Skip to content

Commit b38d3ae

Browse files
committed
Update ADR and types
1 parent 5513927 commit b38d3ae

File tree

8 files changed

+250
-200
lines changed

8 files changed

+250
-200
lines changed

client/tx.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package client
2+
3+
import (
4+
"github.com/cosmos/cosmos-sdk/codec"
5+
sdk "github.com/cosmos/cosmos-sdk/types"
6+
)
7+
8+
type (
9+
// ClientMarshaler defines an interface that REST and CLI handler will use to
10+
// create application-specific transactions and be able to serialize types
11+
// specific to the application including transactions.
12+
ClientMarshaler interface {
13+
TxGenerator
14+
codec.Marshaler
15+
}
16+
17+
// TxGenerator defines an interface a client can utilize to generate an
18+
// application-defined concrete transaction type. The type returned must
19+
// implement ClientTx.
20+
TxGenerator interface {
21+
NewTx() ClientTx
22+
}
23+
24+
// ClientTx defines an interface which an application-defined concrete transaction
25+
// type must implement. Namely, it must be able to set messages, generate
26+
// signatures, and provide canonical bytes to sign over. The transaction must
27+
// also know how to encode itself.
28+
ClientTx interface {
29+
sdk.Tx
30+
codec.ProtoMarshaler
31+
32+
SetMsgs(...sdk.Msg) error
33+
GetSignatures() []sdk.Signature
34+
SetSignatures(...sdk.Signature)
35+
GetFee() sdk.Fee
36+
SetFee(sdk.Fee)
37+
GetMemo() string
38+
SetMemo(string)
39+
40+
CanonicalSignBytes(cid string, num, seq uint64) ([]byte, error)
41+
}
42+
)

codec/std/codec.pb.go

Lines changed: 100 additions & 100 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

codec/std/codec.proto

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,9 @@ message Content {
106106
message Transaction {
107107
option (gogoproto.goproto_getters) = false;
108108

109-
cosmos_sdk.x.auth.v1.StdTxBase base = 1 [(gogoproto.nullable) = false];
110-
repeated Message msgs = 2 [(gogoproto.nullable) = false];
109+
cosmos_sdk.x.auth.v1.StdTxBase base = 1
110+
[(gogoproto.jsontag) = "", (gogoproto.embed) = true, (gogoproto.nullable) = false];
111+
repeated Message msgs = 2 [(gogoproto.nullable) = false];
111112
}
112113

113114
// Message defines the set of valid concrete message types that can be used to

docs/architecture/adr-020-protobuf-transaction-encoding.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,20 +104,21 @@ and messages.
104104
```go
105105
type TxGenerator interface {
106106
NewTx() ClientTx
107-
SignBytes func(chainID string, num, seq uint64, fee StdFee, msgs []sdk.Msg, memo string) ([]byte, error)
108107
}
109108

110109
type ClientTx interface {
111110
sdk.Tx
112111
codec.ProtoMarshaler
113112

114113
SetMsgs(...sdk.Msg) error
115-
GetSignatures() []StdSignature
116-
SetSignatures(...StdSignature) error
117-
GetFee() StdFee
118-
SetFee(StdFee)
114+
GetSignatures() []sdk.Signature
115+
SetSignatures(...sdk.Signature)
116+
GetFee() sdk.Fee
117+
SetFee(sdk.Fee)
119118
GetMemo() string
120119
SetMemo(string)
120+
121+
CanonicalSignBytes(cid string, num, seq uint64) ([]byte, error)
121122
}
122123
```
123124

types/tx_msg.go

Lines changed: 43 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,45 +2,60 @@ package types
22

33
import (
44
"encoding/json"
5+
6+
"github.com/tendermint/tendermint/crypto"
57
)
68

7-
// Transactions messages must fulfill the Msg
8-
type Msg interface {
9+
type (
10+
// Msg defines the interface a transaction message must fulfill.
11+
Msg interface {
912

10-
// Return the message type.
11-
// Must be alphanumeric or empty.
12-
Route() string
13+
// Return the message type.
14+
// Must be alphanumeric or empty.
15+
Route() string
1316

14-
// Returns a human-readable string for the message, intended for utilization
15-
// within tags
16-
Type() string
17+
// Returns a human-readable string for the message, intended for utilization
18+
// within tags
19+
Type() string
1720

18-
// ValidateBasic does a simple validation check that
19-
// doesn't require access to any other information.
20-
ValidateBasic() error
21+
// ValidateBasic does a simple validation check that
22+
// doesn't require access to any other information.
23+
ValidateBasic() error
2124

22-
// Get the canonical byte representation of the Msg.
23-
GetSignBytes() []byte
25+
// Get the canonical byte representation of the Msg.
26+
GetSignBytes() []byte
2427

25-
// Signers returns the addrs of signers that must sign.
26-
// CONTRACT: All signatures must be present to be valid.
27-
// CONTRACT: Returns addrs in some deterministic order.
28-
GetSigners() []AccAddress
29-
}
28+
// Signers returns the addrs of signers that must sign.
29+
// CONTRACT: All signatures must be present to be valid.
30+
// CONTRACT: Returns addrs in some deterministic order.
31+
GetSigners() []AccAddress
32+
}
3033

31-
//__________________________________________________________
34+
// Fee defines an interface for an application application-defined concrete
35+
// transaction type to be able to set and return the transaction fee.
36+
Fee interface {
37+
GetGas() uint64
38+
GetAmount() Coins
39+
}
3240

33-
// Transactions objects must fulfill the Tx
34-
type Tx interface {
35-
// Gets the all the transaction's messages.
36-
GetMsgs() []Msg
41+
// Signature defines an interface for an application application-defined
42+
// concrete transaction type to be able to set and return transaction signatures.
43+
Signature interface {
44+
GetPubKey() crypto.PubKey
45+
GetSignature() []byte
46+
}
3747

38-
// ValidateBasic does a simple and lightweight validation check that doesn't
39-
// require access to any other information.
40-
ValidateBasic() error
41-
}
48+
// Tx defines the interface a transaction must fulfill.
49+
Tx interface {
50+
// Gets the all the transaction's messages.
51+
GetMsgs() []Msg
52+
53+
// ValidateBasic does a simple and lightweight validation check that doesn't
54+
// require access to any other information.
55+
ValidateBasic() error
56+
}
57+
)
4258

43-
//__________________________________________________________
4459

4560
// TxDecoder unmarshals transaction bytes
4661
type TxDecoder func(txBytes []byte) (Tx, error)

x/auth/alias.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ var (
5959
MakeSignature = types.MakeSignature
6060
ValidateGenAccounts = types.ValidateGenAccounts
6161
GetGenesisStateFromAppState = types.GetGenesisStateFromAppState
62+
NewStdSignature = types.NewStdSignature
63+
NewStdTxBase = types.NewStdTxBase
64+
NewStdSignDocBase = types.NewStdSignDocBase
6265

6366
// variable aliases
6467
ModuleCdc = types.ModuleCdc
@@ -89,4 +92,5 @@ type (
8992
GenesisAccountIterator = types.GenesisAccountIterator
9093
Codec = types.Codec
9194
StdSignDocBase = types.StdSignDocBase
95+
StdTxBase = types.StdTxBase
9296
)

x/auth/types/types.pb.go

Lines changed: 50 additions & 64 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

x/auth/types/types.proto

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ message BaseAccount {
2323
// gas to be used by the transaction. The ratio yields an effective "gasprice",
2424
// which must be above some miminum to be accepted into the mempool.
2525
message StdFee {
26-
option (gogoproto.equal) = true;
26+
option (gogoproto.goproto_getters) = false;
27+
option (gogoproto.equal) = true;
2728

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

0 commit comments

Comments
 (0)