Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve client-side tx UX #6034

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 2 additions & 47 deletions codec/std/codec.proto
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ message Content {
message Transaction {
option (gogoproto.goproto_getters) = false;

StdTxBase base = 1 [(gogoproto.jsontag) = "", (gogoproto.embed) = true, (gogoproto.nullable) = false];
repeated Message msgs = 2 [(gogoproto.nullable) = false];
cosmos_sdk.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 Expand Up @@ -137,48 +137,3 @@ message Message {
}
}

// SignDoc defines a standard application-level signing document to compose
// signatures for a Transaction.
message SignDoc {
StdSignDocBase base = 1 [(gogoproto.jsontag) = "", (gogoproto.embed) = true, (gogoproto.nullable) = false];
repeated Message msgs = 2 [(gogoproto.nullable) = false];
}

// StdFee includes the amount of coins paid in fees and the maximum
// 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.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"];
uint64 gas = 2;
}

// StdSignature defines a signature structure that contains the signature of a
// transaction and an optional public key.
message StdSignature {
option (gogoproto.goproto_getters) = false;

bytes pub_key = 1 [(gogoproto.jsontag) = "public_key,omitempty", (gogoproto.moretags) = "yaml:\"public_key\""];
bytes signature = 2;
}

// StdTxBase defines a transaction base which application-level concrete transaction
// types can extend.
message StdTxBase {
StdFee fee = 1 [(gogoproto.nullable) = false];
repeated StdSignature signatures = 2 [(gogoproto.nullable) = false];
string memo = 3;
}

// StdSignDocBase defines the base structure for which applications can extend
// to define the concrete structure that signers sign over.
message StdSignDocBase {
string chain_id = 1 [(gogoproto.customname) = "ChainID", (gogoproto.moretags) = "yaml:\"chain_id\""];
uint64 account_number = 2 [(gogoproto.moretags) = "yaml:\"account_number\""];
uint64 sequence = 3;
string memo = 4;
StdFee fee = 5 [(gogoproto.nullable) = false];
}
9 changes: 8 additions & 1 deletion scripts/protocgen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ proto_dirs=$(find . -path ./third_party -prune -o -name '*.proto' -print0 | xarg
for dir in $proto_dirs; do
protoc \
-I. \
--gocosmos_out=plugins=interfacetype,paths=source_relative:. \
--gocosmos_out=\
plugins=interfacetype,paths=source_relative,\
Mgoogle/protobuf/any.proto=github.com/gogo/protobuf/types,\
Mgoogle/protobuf/empty.proto=github.com/gogo/protobuf/types,\
Mgoogle/protobuf/duration.proto=github.com/gogo/protobuf/types,\
Mgoogle/protobuf/struct.proto=github.com/gogo/protobuf/types,\
Mgoogle/protobuf/timestamp.proto=github.com/gogo/protobuf/types,\
Mgoogle/protobuf/wrappers.proto=github.com/gogo/protobuf/types:.\
$(find "${dir}" -name '*.proto')
done
74 changes: 74 additions & 0 deletions tx/tx.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
syntax = "proto3";
package cosmos_sdk.tx.v1;

import "third_party/proto/gogoproto/gogo.proto";
import "google/protobuf/any.proto";
import "types/types.proto";

option go_package = "github.com/cosmos/cosmos-sdk/tx";
option (gogoproto.goproto_stringer_all) = false;
option (gogoproto.stringer_all) = false;

message Tx {
TxBody body = 1;
Signature signatures = 3;
}

// SignDoc defines a standard application-level signing document to compose
// signatures for a Transaction.
message SignDoc {
TxBody body = 1;
string chain_id = 2 [(gogoproto.customname) = "ChainID", (gogoproto.moretags) = "yaml:\"chain_id\""];
uint64 account_number = 3 [(gogoproto.moretags) = "yaml:\"account_number\""];
uint64 sequence = 4;
string human_readable_text = 5;
}

message TxBody {
repeated google.protobuf.Any msgs = 1;
Fee fee = 2;
string memo = 3;
}

// Fee includes the amount of coins paid in fees and the maximum
// 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 Fee {
option (gogoproto.goproto_getters) = false;
option (gogoproto.equal) = true;

repeated cosmos_sdk.v1.Coin amount = 1 [(gogoproto.nullable) = false, (gogoproto.castrepeated) = "Coins"];
uint64 gas = 2;
}

// Signature defines a signature structure that contains the signature of a
// transaction and an optional public key.
message Signature {
option (gogoproto.goproto_getters) = false;

PublicKey pub_key = 1 [(gogoproto.jsontag) = "public_key,omitempty", (gogoproto.moretags) = "yaml:\"public_key\""];
bytes signature = 2;
Mode mode = 3;

enum Mode {
BASIC = 0;
LEGACY = 1;
EXTENDED = 2;
}
}

message PublicKey {
PublicKeyType type = 1;
bytes bytes = 2;
}

enum PublicKeyType {
TYPE_UNSPECIFIED = 0;
TYPE_SECP256K1 = 1;
TYPE_MULTISIG = 2;
TYPE_ED25519 = 3;
TYPE_SR25519 = 4;
TYPE_SECP256R1 = 5;
reserved 6 to 1024;
}

33 changes: 33 additions & 0 deletions types/module/interface_module.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package module

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

type ProtoMsg interface {
sdk.Msg
codec.ProtoMarshaler
}

type InterfaceModule interface {
Route() string
// GetSigningProxy converts the provided message into another message type
// that is to be used for signing or returns the original message
// or an error if the msg type can't be handled.
// Generally this is used with messages that have an interface member that
// is encoded as a oneof at the app-level. The signing proxy should encode
// this interface member using google.protobuf.Any to provide an app
// independent representation for signatures
GetSigningProxy(msg ProtoMsg) (ProtoMsg, error)

// GetEncodingProxy converts the provided message into another message type
// that is to be used for encoding or returns the original message
// or an error if the msg type can't be handled.
// Generally this is used with messages that have an interface member that
// is encoded as a google.protobuf.Any in an app-independent (module level)
// signing proxiy. The encoding proxy should encode
// this interface member using an oneof at the app-level to minimize
// transaction size over the wire and on disk
GetEncodingProxy(msg ProtoMsg) (ProtoMsg, error)
}
Loading