Skip to content
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (server) [#24072](https://github.com/cosmos/cosmos-sdk/pull/24072) Return BlockHeader by shallow copy in server Context.
* (x/bank) [#24053](https://github.com/cosmos/cosmos-sdk/pull/24053) Resolve a foot-gun by swapping send restrictions check in `InputOutputCoins` before coin deduction.
* (codec/types) [#24336](https://github.com/cosmos/cosmos-sdk/pull/24336) Most types definitions were moved to `github.com/cosmos/gogoproto/types/any` with aliases to these left in `codec/types` so that there should be no breakage to existing code. This allows protobuf generated code to optionally reference the SDK's custom `Any` type without a direct dependency on the SDK. This can be done by changing the `protoc` `M` parameter for `any.proto` to `Mgoogle/protobuf/any.proto=github.com/cosmos/gogoproto/types/any`.
* [#24378](https://github.com/cosmos/cosmos-sdk/pull/24378) Added interactive autocli prompt functionality, including message field prompting, validation helpers, and default value support.

### Bug Fixes

Expand Down
35 changes: 35 additions & 0 deletions client/prompt/internal/helpers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package internal

import (
cosmos_proto "github.com/cosmos/cosmos-proto"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/reflect/protoreflect"

msgv1 "cosmossdk.io/api/cosmos/msg/v1"
)

const (
AddressStringScalarType = "cosmos.AddressString"
ValidatorAddressStringScalarType = "cosmos.ValidatorAddressString"
ConsensusAddressStringScalarType = "cosmos.ConsensusAddressString"
)

// GetScalarType gets scalar type of a field.
// Copied from client/v2/flag package. Lives here to avoid circular dependency.
func GetScalarType(field protoreflect.FieldDescriptor) (string, bool) {
scalar := proto.GetExtension(field.Options(), cosmos_proto.E_Scalar)
scalarStr, ok := scalar.(string)
return scalarStr, ok
}

// GetSignerFieldName gets signer field name of a message.
// AutoCLI supports only one signer field per message.
// Copied from client/v2/flag package. Lives here to avoid circular dependency.
func GetSignerFieldName(descriptor protoreflect.MessageDescriptor) string {
signersFields := proto.GetExtension(descriptor.Options(), msgv1.E_Signer).([]string)
if len(signersFields) == 0 {
return ""
}

return signersFields[0]
}
62 changes: 62 additions & 0 deletions client/prompt/internal/testpb/msg.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
syntax = "proto3";

package testpb;

import "google/protobuf/timestamp.proto";
import "google/protobuf/duration.proto";
import "cosmos_proto/cosmos.proto";
import "cosmos/base/query/v1beta1/pagination.proto";
import "cosmos/base/v1beta1/coin.proto";
import "testpb/query.proto";

service Msg {
// Send a request and returns the request as a response.
rpc Send(MsgRequest) returns (MsgResponse) {
option (cosmos_proto.method_added_in) = "cosmos-sdk v0.50.0";
};

rpc Clawback(MsgClawbackRequest) returns (MsgClawbackResponse) {
option (cosmos_proto.method_added_in) = "cosmos-sdk v0.51.0";
}
}

message MsgRequest {
// u32 is an uint32
uint32 u32 = 1;
uint64 u64 = 2;
string str = 3;
bytes bz = 4;
google.protobuf.Timestamp timestamp = 5;
google.protobuf.Duration duration = 6;
int32 i32 = 7;
int64 i64 = 10;
bool a_bool = 15;
testpb.Enum an_enum = 16;
testpb.AMessage a_message = 17;
cosmos.base.v1beta1.Coin a_coin = 18;
string an_address = 19 [(cosmos_proto.scalar) = "cosmos.AddressString"];
cosmos.base.query.v1beta1.PageRequest page = 20;
repeated bool bools = 21;
repeated uint32 uints = 22;
repeated string strings = 23;
repeated testpb.Enum enums = 24;
repeated google.protobuf.Duration durations = 25;
repeated testpb.AMessage some_messages = 26;

int32 positional1 = 27;
string positional2 = 28;
repeated cosmos.base.v1beta1.Coin positional3_varargs = 29;

string deprecated_field = 30;
string shorthand_deprecated_field = 31;
bool hidden_bool = 32;
string a_validator_address = 33 [(cosmos_proto.scalar) = "cosmos.ValidatorAddressString"];
}

message MsgResponse {
MsgRequest request = 1;
}

message MsgClawbackRequest {}

message MsgClawbackResponse {}
Loading
Loading