From c20a43381694af4ee3daa8816f4617cdbf3be215 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Fri, 14 Feb 2025 00:57:10 +0100 Subject: [PATCH 01/17] feat(connect): fork client/v2 and use internal connect version --- connect/go.mod | 30 +- connect/go.sum | 15 +- connect/internal/autocli/app.go | 148 + connect/internal/autocli/builder.go | 34 + connect/internal/autocli/common.go | 373 ++ connect/internal/autocli/common_test.go | 235 + connect/internal/autocli/config/config.go | 133 + connect/internal/autocli/flag/address.go | 163 + connect/internal/autocli/flag/binary.go | 63 + connect/internal/autocli/flag/builder.go | 511 ++ connect/internal/autocli/flag/coin.go | 58 + connect/internal/autocli/flag/dec_coin.go | 58 + connect/internal/autocli/flag/doc.go | 4 + connect/internal/autocli/flag/duration.go | 51 + connect/internal/autocli/flag/enum.go | 79 + connect/internal/autocli/flag/interface.go | 32 + connect/internal/autocli/flag/json_message.go | 86 + connect/internal/autocli/flag/legacy_dec.go | 48 + connect/internal/autocli/flag/list.go | 107 + connect/internal/autocli/flag/map.go | 254 + connect/internal/autocli/flag/maps/generic.go | 61 + .../autocli/flag/maps/map_bool_to_value.go | 138 + .../autocli/flag/maps/map_int32_to_value.go | 159 + .../autocli/flag/maps/map_int64_to_value.go | 180 + .../autocli/flag/maps/map_string_to_value.go | 28 + .../autocli/flag/maps/map_uint32_to_value.go | 138 + .../autocli/flag/maps/map_uint64_to_value.go | 138 + .../internal/autocli/flag/messager_binder.go | 155 + connect/internal/autocli/flag/pubkey.go | 61 + connect/internal/autocli/flag/simple.go | 44 + connect/internal/autocli/flag/timestamp.go | 50 + connect/internal/autocli/interface.go | 32 + connect/internal/autocli/keyring/interface.go | 23 + connect/internal/autocli/keyring/keyring.go | 83 + .../internal/autocli/keyring/no_keyring.go | 31 + connect/internal/autocli/msg.go | 232 + connect/internal/autocli/msg_test.go | 285 + connect/internal/autocli/prompt/message.go | 259 + .../internal/autocli/prompt/message_test.go | 59 + connect/internal/autocli/prompt/struct.go | 134 + .../internal/autocli/prompt/struct_test.go | 46 + connect/internal/autocli/prompt/util.go | 70 + connect/internal/autocli/prompt/validation.go | 52 + .../autocli/prompt/validation_test.go | 55 + connect/internal/autocli/query.go | 253 + connect/internal/autocli/query_test.go | 739 +++ .../autocli/testdata/flatten-output.golden | 1 + .../autocli/testdata/help-deprecated.golden | 50 + .../autocli/testdata/help-echo-msg.golden | 34 + .../autocli/testdata/help-echo.golden | 52 + .../autocli/testdata/help-skip.golden | 7 + .../autocli/testdata/help-toplevel-msg.golden | 19 + .../autocli/testdata/help-toplevel.golden | 17 + connect/internal/autocli/testdata/help.golden | 40 + .../autocli/testdata/msg-output.golden | 1 + .../autocli/testdata/some_message.json | 1 + connect/internal/autocli/util.go | 50 + connect/internal/autocli/validate.go | 60 + connect/internal/broadcast/broadcaster.go | 15 + .../internal/broadcast/comet/client_conn.go | 146 + connect/internal/broadcast/comet/comet.go | 199 + .../internal/broadcast/comet/comet_test.go | 149 + .../broadcast/comet/testutil/comet_mock.go | 285 + connect/internal/context/context.go | 55 + connect/internal/helpers/home.go | 48 + .../internal/internal/account/retriever.go | 116 + connect/internal/internal/buf.gen.gogo.yaml | 5 + connect/internal/internal/buf.gen.pulsar.yaml | 16 + connect/internal/internal/buf.lock | 33 + connect/internal/internal/buf.yaml | 12 + connect/internal/internal/coins/format.go | 62 + .../internal/internal/coins/format_test.go | 73 + connect/internal/internal/coins/util.go | 66 + connect/internal/internal/coins/util_test.go | 83 + connect/internal/internal/flags/flags.go | 47 + connect/internal/internal/governance/gov.go | 98 + connect/internal/internal/print/printer.go | 84 + connect/internal/internal/strcase/kebab.go | 101 + .../internal/internal/strcase/kebab_test.go | 44 + connect/internal/internal/testpb/msg.proto | 62 + .../internal/internal/testpb/msg.pulsar.go | 4435 ++++++++++++++ .../internal/internal/testpb/msg_grpc.pb.go | 161 + connect/internal/internal/testpb/query.proto | 70 + .../internal/internal/testpb/query.pulsar.go | 5438 +++++++++++++++++ .../internal/internal/testpb/query_grpc.pb.go | 123 + connect/internal/internal/util/util.go | 96 + connect/internal/internal/util/util_test.go | 125 + 87 files changed, 18551 insertions(+), 15 deletions(-) create mode 100644 connect/internal/autocli/app.go create mode 100644 connect/internal/autocli/builder.go create mode 100644 connect/internal/autocli/common.go create mode 100644 connect/internal/autocli/common_test.go create mode 100644 connect/internal/autocli/config/config.go create mode 100644 connect/internal/autocli/flag/address.go create mode 100644 connect/internal/autocli/flag/binary.go create mode 100644 connect/internal/autocli/flag/builder.go create mode 100644 connect/internal/autocli/flag/coin.go create mode 100644 connect/internal/autocli/flag/dec_coin.go create mode 100644 connect/internal/autocli/flag/doc.go create mode 100644 connect/internal/autocli/flag/duration.go create mode 100644 connect/internal/autocli/flag/enum.go create mode 100644 connect/internal/autocli/flag/interface.go create mode 100644 connect/internal/autocli/flag/json_message.go create mode 100644 connect/internal/autocli/flag/legacy_dec.go create mode 100644 connect/internal/autocli/flag/list.go create mode 100644 connect/internal/autocli/flag/map.go create mode 100644 connect/internal/autocli/flag/maps/generic.go create mode 100644 connect/internal/autocli/flag/maps/map_bool_to_value.go create mode 100644 connect/internal/autocli/flag/maps/map_int32_to_value.go create mode 100644 connect/internal/autocli/flag/maps/map_int64_to_value.go create mode 100644 connect/internal/autocli/flag/maps/map_string_to_value.go create mode 100644 connect/internal/autocli/flag/maps/map_uint32_to_value.go create mode 100644 connect/internal/autocli/flag/maps/map_uint64_to_value.go create mode 100644 connect/internal/autocli/flag/messager_binder.go create mode 100644 connect/internal/autocli/flag/pubkey.go create mode 100644 connect/internal/autocli/flag/simple.go create mode 100644 connect/internal/autocli/flag/timestamp.go create mode 100644 connect/internal/autocli/interface.go create mode 100644 connect/internal/autocli/keyring/interface.go create mode 100644 connect/internal/autocli/keyring/keyring.go create mode 100644 connect/internal/autocli/keyring/no_keyring.go create mode 100644 connect/internal/autocli/msg.go create mode 100644 connect/internal/autocli/msg_test.go create mode 100644 connect/internal/autocli/prompt/message.go create mode 100644 connect/internal/autocli/prompt/message_test.go create mode 100644 connect/internal/autocli/prompt/struct.go create mode 100644 connect/internal/autocli/prompt/struct_test.go create mode 100644 connect/internal/autocli/prompt/util.go create mode 100644 connect/internal/autocli/prompt/validation.go create mode 100644 connect/internal/autocli/prompt/validation_test.go create mode 100644 connect/internal/autocli/query.go create mode 100644 connect/internal/autocli/query_test.go create mode 100644 connect/internal/autocli/testdata/flatten-output.golden create mode 100644 connect/internal/autocli/testdata/help-deprecated.golden create mode 100644 connect/internal/autocli/testdata/help-echo-msg.golden create mode 100644 connect/internal/autocli/testdata/help-echo.golden create mode 100644 connect/internal/autocli/testdata/help-skip.golden create mode 100644 connect/internal/autocli/testdata/help-toplevel-msg.golden create mode 100644 connect/internal/autocli/testdata/help-toplevel.golden create mode 100644 connect/internal/autocli/testdata/help.golden create mode 100644 connect/internal/autocli/testdata/msg-output.golden create mode 100644 connect/internal/autocli/testdata/some_message.json create mode 100644 connect/internal/autocli/util.go create mode 100644 connect/internal/autocli/validate.go create mode 100644 connect/internal/broadcast/broadcaster.go create mode 100644 connect/internal/broadcast/comet/client_conn.go create mode 100644 connect/internal/broadcast/comet/comet.go create mode 100644 connect/internal/broadcast/comet/comet_test.go create mode 100644 connect/internal/broadcast/comet/testutil/comet_mock.go create mode 100644 connect/internal/context/context.go create mode 100644 connect/internal/helpers/home.go create mode 100644 connect/internal/internal/account/retriever.go create mode 100644 connect/internal/internal/buf.gen.gogo.yaml create mode 100644 connect/internal/internal/buf.gen.pulsar.yaml create mode 100644 connect/internal/internal/buf.lock create mode 100644 connect/internal/internal/buf.yaml create mode 100644 connect/internal/internal/coins/format.go create mode 100644 connect/internal/internal/coins/format_test.go create mode 100644 connect/internal/internal/coins/util.go create mode 100644 connect/internal/internal/coins/util_test.go create mode 100644 connect/internal/internal/flags/flags.go create mode 100644 connect/internal/internal/governance/gov.go create mode 100644 connect/internal/internal/print/printer.go create mode 100644 connect/internal/internal/strcase/kebab.go create mode 100644 connect/internal/internal/strcase/kebab_test.go create mode 100644 connect/internal/internal/testpb/msg.proto create mode 100644 connect/internal/internal/testpb/msg.pulsar.go create mode 100644 connect/internal/internal/testpb/msg_grpc.pb.go create mode 100644 connect/internal/internal/testpb/query.proto create mode 100644 connect/internal/internal/testpb/query.pulsar.go create mode 100644 connect/internal/internal/testpb/query_grpc.pb.go create mode 100644 connect/internal/internal/util/util.go create mode 100644 connect/internal/internal/util/util_test.go diff --git a/connect/go.mod b/connect/go.mod index e51a9257..2025472f 100644 --- a/connect/go.mod +++ b/connect/go.mod @@ -5,27 +5,37 @@ go 1.23.0 require ( cosmossdk.io/api v0.7.6 cosmossdk.io/client/v2 v2.0.0-beta.6 + cosmossdk.io/core v0.11.1 + cosmossdk.io/depinject v1.1.0 + cosmossdk.io/errors v1.0.1 + cosmossdk.io/math v1.4.0 + cosmossdk.io/x/tx v0.13.8 github.com/charmbracelet/bubbles v0.7.6 github.com/charmbracelet/bubbletea v1.2.4 + github.com/cometbft/cometbft v0.38.15 + github.com/cosmos/cosmos-proto v1.0.0-beta.5 github.com/cosmos/cosmos-sdk v0.50.11 + github.com/cosmos/gogoproto v1.7.0 github.com/hashicorp/go-plugin v1.6.1 github.com/ignite/cli/v28 v28.7.1-0.20250116085640-fcf01a4e4b39 + github.com/manifoldco/promptui v0.9.0 + github.com/pelletier/go-toml/v2 v2.2.2 github.com/spf13/cobra v1.8.1 + github.com/spf13/pflag v1.0.5 + github.com/spf13/viper v1.19.0 github.com/stretchr/testify v1.10.0 + go.uber.org/mock v0.5.0 google.golang.org/grpc v1.67.1 google.golang.org/protobuf v1.35.1 gopkg.in/yaml.v3 v3.0.1 + gotest.tools/v3 v3.5.1 + sigs.k8s.io/yaml v1.4.0 ) require ( cosmossdk.io/collections v0.4.0 // indirect - cosmossdk.io/core v0.11.1 // indirect - cosmossdk.io/depinject v1.1.0 // indirect - cosmossdk.io/errors v1.0.1 // indirect cosmossdk.io/log v1.4.1 // indirect - cosmossdk.io/math v1.4.0 // indirect cosmossdk.io/store v1.1.1 // indirect - cosmossdk.io/x/tx v0.13.7 // indirect dario.cat/mergo v1.0.0 // indirect filippo.io/edwards25519 v1.0.0 // indirect github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect @@ -45,6 +55,7 @@ require ( github.com/charmbracelet/lipgloss v1.0.0 // indirect github.com/charmbracelet/x/ansi v0.4.5 // indirect github.com/charmbracelet/x/term v0.2.1 // indirect + github.com/chzyer/readline v1.5.1 // indirect github.com/cloudflare/circl v1.3.7 // indirect github.com/cockroachdb/errors v1.11.3 // indirect github.com/cockroachdb/fifo v0.0.0-20240606204812-0bbfbd93a7ce // indirect @@ -52,14 +63,11 @@ require ( github.com/cockroachdb/pebble v1.1.2 // indirect github.com/cockroachdb/redact v1.1.5 // indirect github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect - github.com/cometbft/cometbft v0.38.15 // indirect github.com/cometbft/cometbft-db v0.14.1 // indirect github.com/cosmos/btcutil v1.0.5 // indirect github.com/cosmos/cosmos-db v1.1.0 // indirect - github.com/cosmos/cosmos-proto v1.0.0-beta.5 // indirect github.com/cosmos/go-bip39 v1.0.0 // indirect github.com/cosmos/gogogateway v1.2.0 // indirect - github.com/cosmos/gogoproto v1.7.0 // indirect github.com/cosmos/iavl v1.2.2 // indirect github.com/cosmos/ics23/go v0.11.0 // indirect github.com/cosmos/ledger-cosmos-go v0.13.3 // indirect @@ -102,6 +110,7 @@ require ( github.com/gogo/protobuf v1.3.2 // indirect github.com/golang/glog v1.2.2 // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect + github.com/golang/mock v1.6.0 // indirect github.com/golang/protobuf v1.5.4 // indirect github.com/golang/snappy v0.0.4 // indirect github.com/google/btree v1.1.3 // indirect @@ -156,7 +165,6 @@ require ( github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/oasisprotocol/curve25519-voi v0.0.0-20230904125328-1f23a7beb09a // indirect github.com/oklog/run v1.1.0 // indirect - github.com/pelletier/go-toml/v2 v2.2.2 // indirect github.com/petermattis/goid v0.0.0-20240813172612-4fcff4a6cae7 // indirect github.com/pjbgf/sha1cd v0.3.0 // indirect github.com/pkg/errors v0.9.1 // indirect @@ -181,8 +189,6 @@ require ( github.com/sourcegraph/syntaxhighlight v0.0.0-20170531221838-bd320f5d308e // indirect github.com/spf13/afero v1.11.0 // indirect github.com/spf13/cast v1.7.0 // indirect - github.com/spf13/pflag v1.0.5 // indirect - github.com/spf13/viper v1.19.0 // indirect github.com/subosito/gotenv v1.6.0 // indirect github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d // indirect github.com/tendermint/go-amino v0.16.0 // indirect @@ -209,8 +215,6 @@ require ( gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/warnings.v0 v0.1.2 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect - gotest.tools/v3 v3.5.1 // indirect nhooyr.io/websocket v1.8.6 // indirect pgregory.net/rapid v1.1.0 // indirect - sigs.k8s.io/yaml v1.4.0 // indirect ) diff --git a/connect/go.sum b/connect/go.sum index 2a34678f..61df7717 100644 --- a/connect/go.sum +++ b/connect/go.sum @@ -18,8 +18,8 @@ cosmossdk.io/math v1.4.0 h1:XbgExXFnXmF/CccPPEto40gOO7FpWu9yWNAZPN3nkNQ= cosmossdk.io/math v1.4.0/go.mod h1:O5PkD4apz2jZs4zqFdTr16e1dcaQCc5z6lkEnrrppuk= cosmossdk.io/store v1.1.1 h1:NA3PioJtWDVU7cHHeyvdva5J/ggyLDkyH0hGHl2804Y= cosmossdk.io/store v1.1.1/go.mod h1:8DwVTz83/2PSI366FERGbWSH7hL6sB7HbYp8bqksNwM= -cosmossdk.io/x/tx v0.13.7 h1:8WSk6B/OHJLYjiZeMKhq7DK7lHDMyK0UfDbBMxVmeOI= -cosmossdk.io/x/tx v0.13.7/go.mod h1:V6DImnwJMTq5qFjeGWpXNiT/fjgE4HtmclRmTqRVM3w= +cosmossdk.io/x/tx v0.13.8 h1:dQwC8jMe7awx/edi1HPPZ40AjHnsix6KSO/jbKMUYKk= +cosmossdk.io/x/tx v0.13.8/go.mod h1:V6DImnwJMTq5qFjeGWpXNiT/fjgE4HtmclRmTqRVM3w= dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk= dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= @@ -117,10 +117,14 @@ github.com/charmbracelet/x/ansi v0.4.5/go.mod h1:dk73KoMTT5AX5BsX0KrqhsTqAnhZZoC github.com/charmbracelet/x/term v0.2.1 h1:AQeHeLZ1OqSXhrAWpYUtZyX1T3zVxfpZuEQMIQaGIAQ= github.com/charmbracelet/x/term v0.2.1/go.mod h1:oQ4enTYFV7QN4m0i9mzHrViD7TQKvNEEkHUMCmsxdUg= github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= +github.com/chzyer/logex v1.2.1 h1:XHDu3E6q+gdHgsdTPH6ImJMIp436vR6MPtH8gP05QzM= +github.com/chzyer/logex v1.2.1/go.mod h1:JLbx6lG2kDbNRFnfkgvh4eRJRPX1QCoOIWomwysCBrQ= github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= github.com/chzyer/readline v1.5.1 h1:upd/6fQk4src78LMRzh5vItIt361/o4uq553V8B5sGI= github.com/chzyer/readline v1.5.1/go.mod h1:Eh+b79XXUwfKfcPLepksvw2tcLE/Ct21YObkaSkeBlk= github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= +github.com/chzyer/test v1.0.0 h1:p3BQDXSxOhOG0P9z6/hGnII4LGiEPOYBhs8asl/fC04= +github.com/chzyer/test v1.0.0/go.mod h1:2JlltgoNkt4TW/z9V/IzDdFaMTM2JPIi26O1pF38GC8= github.com/circonus-labs/circonus-gometrics v2.3.1+incompatible/go.mod h1:nmEj6Dob7S7YxXgwXpfOuvO54S+tGdZdw9fuRZt25Ag= github.com/circonus-labs/circonusllhist v0.1.3/go.mod h1:kMXHVDlOchFAehlya5ePtbp5jckzBHf4XRpQvBOLI+I= github.com/clbanning/x2j v0.0.0-20191024224557-825249438eec/go.mod h1:jMjuTZXRI4dUb/I5gc9Hdhagfvm9+RyrPryS/auMzxE= @@ -844,6 +848,7 @@ github.com/xanzy/ssh-agent v0.3.3/go.mod h1:6dzNDKs0J9rVPHPhaGCukekBHKqfl+L3KghI github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= github.com/zondax/hid v0.9.2 h1:WCJFnEDMiqGF64nlZz28E9qLVZ0KSJ7xpc5DLEyma2U= github.com/zondax/hid v0.9.2/go.mod h1:l5wttcP0jwtdLjqjMMWFVEE7d1zO0jvSPA9OPZxWpEM= @@ -864,6 +869,8 @@ go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/goleak v1.1.10/go.mod h1:8a7PlsEVH3e/a/GLqe5IIrQx6GzcnRmZEufDUTk4A7A= +go.uber.org/mock v0.5.0 h1:KAMbZvZPyBPWgD14IrIQ38QCyjwpvVVV6K/bHl1IwQU= +go.uber.org/mock v0.5.0/go.mod h1:ge71pBPLYDk7QIi1LupWxdAykm7KIEFchiOqd6z7qMM= go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= go.uber.org/multierr v1.3.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4= go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU= @@ -907,6 +914,7 @@ golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzB golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/mod v0.20.0 h1:utOm6MM3R3dnawAiJgn0y+xvuYRsm1RKM/4giyfDgV0= @@ -960,6 +968,7 @@ golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220929204114-8fcdb60fdcc0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -1013,6 +1022,7 @@ golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220315194320-039c03cc5b86/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= @@ -1071,6 +1081,7 @@ golang.org/x/tools v0.0.0-20200207183749-b753a1ba74fa/go.mod h1:TB2adYChydJhpapK golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= golang.org/x/tools v0.24.0 h1:J1shsA93PJUEVaUSaay7UXAyE8aimq3GW0pjlolpa24= diff --git a/connect/internal/autocli/app.go b/connect/internal/autocli/app.go new file mode 100644 index 00000000..297a52b4 --- /dev/null +++ b/connect/internal/autocli/app.go @@ -0,0 +1,148 @@ +package autocli + +import ( + "github.com/spf13/cobra" + "google.golang.org/protobuf/reflect/protoregistry" + + autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" + apisigning "cosmossdk.io/api/cosmos/tx/signing/v1beta1" + "cosmossdk.io/core/address" + "cosmossdk.io/core/appmodule" + "cosmossdk.io/depinject" + "github.com/ignite/apps/connect/internal/autocli/flag" + + sdkflags "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/codec" + authtx "github.com/cosmos/cosmos-sdk/x/auth/tx" +) + +// AppOptions are input options for an autocli enabled app. These options can be built via depinject based on an app config. +// Ex: +// +// var autoCliOpts autocli.AppOptions +// err := depinject.Inject(appConfig, &encodingConfig.InterfaceRegistry, &autoCliOpts) +// +// If depinject isn't used, options can be provided manually or extracted from modules and the address codec can be provided by the auth keeper. +// One method for extracting autocli options is via the github.com/cosmos/cosmos-sdk/runtime/services.ExtractAutoCLIOptions function. +type AppOptions struct { + depinject.In + + // Modules are the AppModule implementations for the modules in the app. + Modules map[string]appmodule.AppModule + + // ModuleOptions are autocli options to be used for modules instead of what + // is specified on the module's AppModule implementation. This allows an + // app to override module options if they are either not provided by a + // module or need to be improved. + ModuleOptions map[string]*autocliv1.ModuleOptions `optional:"true"` + + AddressCodec address.Codec // AddressCodec is used to encode/decode account addresses. + ValidatorAddressCodec address.Codec // ValidatorAddressCodec is used to encode/decode validator addresses. + ConsensusAddressCodec address.Codec // ConsensusAddressCodec is used to encode/decode consensus addresses. + + // Cdc is the codec used for binary encoding/decoding of messages. + Cdc codec.Codec + + // TxConfigOpts contains options for configuring transaction handling. + TxConfigOpts authtx.ConfigOptions + + skipValidation bool +} + +// EnhanceRootCommand enhances the provided root command with autocli AppOptions, +// only adding missing commands and doesn't override commands already +// in the root command. This allows for the graceful integration of autocli with +// existing app CLI commands where autocli simply automatically adds things that +// weren't manually provided. It does take into account custom commands +// provided by modules with the HasCustomQueryCommand or HasCustomTxCommand extension interface. +// Example Usage: +// +// var autoCliOpts autocli.AppOptions +// err := depinject.Inject(appConfig, &autoCliOpts) +// if err != nil { +// panic(err) +// } +// rootCmd := initRootCmd() +// err = autoCliOpts.EnhanceRootCommand(rootCmd) +func (appOptions AppOptions) EnhanceRootCommand(rootCmd *cobra.Command) error { + // convert the API sign modes to internal sign modes + signModes := make([]apisigning.SignMode, len(appOptions.TxConfigOpts.EnabledSignModes)) + for i, mode := range appOptions.TxConfigOpts.EnabledSignModes { + signModes[i] = apisigning.SignMode(mode) + } + + builder := &Builder{ + Builder: flag.Builder{ + TypeResolver: protoregistry.GlobalTypes, + FileResolver: appOptions.Cdc.InterfaceRegistry(), + AddressCodec: appOptions.AddressCodec, + ValidatorAddressCodec: appOptions.ValidatorAddressCodec, + ConsensusAddressCodec: appOptions.ConsensusAddressCodec, + }, + GetClientConn: getQueryClientConn(appOptions.Cdc), + AddQueryConnFlags: func(c *cobra.Command) { + sdkflags.AddQueryFlagsToCmd(c) + sdkflags.AddKeyringFlags(c.Flags()) + }, + AddTxConnFlags: sdkflags.AddTxFlagsToCmd, + Cdc: appOptions.Cdc, + EnabledSignModes: signModes, + } + + return appOptions.EnhanceRootCommandWithBuilder(rootCmd, builder) +} + +func (appOptions AppOptions) EnhanceRootCommandWithBuilder(rootCmd *cobra.Command, builder *Builder) error { + if !appOptions.skipValidation { + if err := builder.ValidateAndComplete(); err != nil { + return err + } + } + + // extract any custom commands from modules + customQueryCmds, customMsgCmds := map[string]*cobra.Command{}, map[string]*cobra.Command{} + for name, module := range appOptions.Modules { + if queryModule, ok := module.(HasCustomQueryCommand); ok { + queryCmd := queryModule.GetQueryCmd() + // filter any nil commands + if queryCmd != nil { + customQueryCmds[name] = queryCmd + } + } + if msgModule, ok := module.(HasCustomTxCommand); ok { + msgCmd := msgModule.GetTxCmd() + // filter any nil commands + if msgCmd != nil { + customMsgCmds[name] = msgCmd + } + } + } + + if queryCmd := findSubCommand(rootCmd, "query"); queryCmd != nil { + if err := builder.enhanceCommandCommon(queryCmd, queryCmdType, appOptions, customQueryCmds); err != nil { + return err + } + } else { + queryCmd, err := builder.BuildQueryCommand(rootCmd.Context(), appOptions, customQueryCmds) + if err != nil { + return err + } + + rootCmd.AddCommand(queryCmd) + } + + if msgCmd := findSubCommand(rootCmd, "tx"); msgCmd != nil { + if err := builder.enhanceCommandCommon(msgCmd, msgCmdType, appOptions, customMsgCmds); err != nil { + return err + } + } else { + subCmd, err := builder.BuildMsgCommand(rootCmd.Context(), appOptions, customMsgCmds) + if err != nil { + return err + } + + rootCmd.AddCommand(subCmd) + } + + return nil +} diff --git a/connect/internal/autocli/builder.go b/connect/internal/autocli/builder.go new file mode 100644 index 00000000..e6cc2768 --- /dev/null +++ b/connect/internal/autocli/builder.go @@ -0,0 +1,34 @@ +package autocli + +import ( + "github.com/spf13/cobra" + "google.golang.org/grpc" + + apisigning "cosmossdk.io/api/cosmos/tx/signing/v1beta1" + "github.com/ignite/apps/connect/internal/autocli/flag" + + "github.com/cosmos/cosmos-sdk/codec" +) + +// Builder manages options for building CLI commands. +type Builder struct { + // flag.Builder embeds the flag builder and its options. + flag.Builder + + // GetClientConn specifies how CLI commands will resolve a grpc.ClientConnInterface + // from a given context. + GetClientConn func(*cobra.Command) (grpc.ClientConnInterface, error) + + // AddQueryConnFlags and AddTxConnFlags are functions that add flags to query and transaction commands + AddQueryConnFlags func(*cobra.Command) + AddTxConnFlags func(*cobra.Command) + + Cdc codec.Codec + EnabledSignModes []apisigning.SignMode +} + +// ValidateAndComplete the builder fields. +// It returns an error if any of the required fields are missing. +func (b *Builder) ValidateAndComplete() error { + return b.Builder.ValidateAndComplete() +} diff --git a/connect/internal/autocli/common.go b/connect/internal/autocli/common.go new file mode 100644 index 00000000..46379803 --- /dev/null +++ b/connect/internal/autocli/common.go @@ -0,0 +1,373 @@ +package autocli + +import ( + "context" + "crypto/tls" + "fmt" + "strconv" + + "github.com/spf13/cobra" + "google.golang.org/grpc" + "google.golang.org/grpc/credentials" + grpcinsecure "google.golang.org/grpc/credentials/insecure" + "google.golang.org/protobuf/reflect/protoreflect" + + autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" + "github.com/ignite/apps/connect/internal/autocli/config" + "github.com/ignite/apps/connect/internal/autocli/keyring" + "github.com/ignite/apps/connect/internal/broadcast/comet" + clientcontext "github.com/ignite/apps/connect/internal/context" + "github.com/ignite/apps/connect/internal/internal/flags" + "github.com/ignite/apps/connect/internal/internal/print" + "github.com/ignite/apps/connect/internal/internal/util" + + "github.com/cosmos/cosmos-sdk/codec" +) + +type cmdType int + +const ( + queryCmdType cmdType = iota + msgCmdType +) + +func (b *Builder) buildMethodCommandCommon(descriptor protoreflect.MethodDescriptor, options *autocliv1.RpcCommandOptions, exec func(cmd *cobra.Command, input protoreflect.Message) error) (*cobra.Command, error) { + if options == nil { + // use the defaults + options = &autocliv1.RpcCommandOptions{} + } + + short := options.Short + if short == "" { + short = fmt.Sprintf("Execute the %s RPC method", descriptor.Name()) + } + + inputDesc := descriptor.Input() + inputType := util.ResolveMessageType(b.TypeResolver, inputDesc) + + use := options.Use + if use == "" { + use = protoNameToCliName(descriptor.Name()) + } + + cmd := &cobra.Command{ + SilenceUsage: false, + Use: use, + Long: options.Long, + Short: short, + Example: options.Example, + Aliases: options.Alias, + SuggestFor: options.SuggestFor, + Deprecated: options.Deprecated, + Version: options.Version, + } + + // we need to use a pointer to the context as the correct context is set in the RunE function + // however we need to set the flags before the RunE function is called + ctx := cmd.Context() + binder, err := b.AddMessageFlags(&ctx, cmd.Flags(), inputType, options) + if err != nil { + return nil, err + } + cmd.Args = binder.CobraArgs + + cmd.PreRunE = b.preRunE() + + cmd.RunE = func(cmd *cobra.Command, args []string) error { + ctx, err = b.getContext(cmd) + if err != nil { + return err + } + + input, err := binder.BuildMessage(args) + if err != nil { + return err + } + + // signer related logic, triggers only when there is a signer defined + if binder.SignerInfo.FieldName != "" { + if binder.SignerInfo.IsFlag { + // the client context uses the from flag to determine the signer. + // this sets the signer flags to the from flag value if a custom signer flag is set. + // marks the custom flag as required. + if binder.SignerInfo.FlagName != flags.FlagFrom { + if err := cmd.MarkFlagRequired(binder.SignerInfo.FlagName); err != nil { + return err + } + + if err := cmd.Flags().Set(flags.FlagFrom, cmd.Flag(binder.SignerInfo.FlagName).Value.String()); err != nil { + return err + } + } + } else { + // if the signer is not a flag, it is a positional argument + // we need to get the correct positional arguments + if err := cmd.Flags().Set(flags.FlagFrom, args[binder.SignerInfo.PositionalArgIndex]); err != nil { + return err + } + } + } + + return exec(cmd, input) + } + + return cmd, nil +} + +// enhanceCommandCommon enhances the provided query or msg command with either generated commands based on the provided module +// options or the provided custom commands for each module. If the provided query command already contains a command +// for a module, that command is not over-written by this method. This allows a graceful addition of autocli to +// automatically fill in missing commands. +func (b *Builder) enhanceCommandCommon( + cmd *cobra.Command, + cmdType cmdType, + appOptions AppOptions, + customCmds map[string]*cobra.Command, +) error { + moduleOptions := appOptions.ModuleOptions + if len(moduleOptions) == 0 { + moduleOptions = make(map[string]*autocliv1.ModuleOptions) + } + for name, module := range appOptions.Modules { + if _, ok := moduleOptions[name]; !ok { + if module, ok := module.(HasAutoCLIConfig); ok { + moduleOptions[name] = module.AutoCLIOptions() + } else { + moduleOptions[name] = nil + } + } + } + + for moduleName, modOpts := range moduleOptions { + hasModuleOptions := modOpts != nil + + // if we have an existing command skip adding one here + if subCmd := findSubCommand(cmd, moduleName); subCmd != nil { + if hasModuleOptions { // check if we need to enhance the existing command + if err := enhanceCustomCmd(b, subCmd, cmdType, modOpts); err != nil { + return err + } + } + + continue + } + + // if we have a custom command use that instead of generating one + if custom, ok := customCmds[moduleName]; ok { + // Custom may not be called the same as its module, so we need to have a separate check here + if subCmd := findSubCommand(cmd, custom.Name()); subCmd != nil { + if hasModuleOptions { // check if we need to enhance the existing command + if err := enhanceCustomCmd(b, subCmd, cmdType, modOpts); err != nil { + return err + } + } + continue + } + if hasModuleOptions { // check if we need to enhance the new command + if err := enhanceCustomCmd(b, custom, cmdType, modOpts); err != nil { + return err + } + } + + cmd.AddCommand(custom) + continue + } + + // if we don't have module options, skip adding a command as we don't have anything to add + if !hasModuleOptions { + continue + } + + switch cmdType { + case queryCmdType: + if err := enhanceQuery(b, moduleName, cmd, modOpts); err != nil { + return err + } + case msgCmdType: + if err := enhanceMsg(b, moduleName, cmd, modOpts); err != nil { + return err + } + } + } + + return nil +} + +// enhanceQuery enhances the provided query command with the autocli commands for a module. +func enhanceQuery(builder *Builder, moduleName string, cmd *cobra.Command, modOpts *autocliv1.ModuleOptions) error { + if queryCmdDesc := modOpts.Query; queryCmdDesc != nil { + short := queryCmdDesc.Short + if short == "" { + short = fmt.Sprintf("Querying commands for the %s module", moduleName) + } + subCmd := topLevelCmd(cmd.Context(), moduleName, short) + if err := builder.AddQueryServiceCommands(subCmd, queryCmdDesc); err != nil { + return err + } + + cmd.AddCommand(subCmd) + } + + return nil +} + +// enhanceMsg enhances the provided msg command with the autocli commands for a module. +func enhanceMsg(builder *Builder, moduleName string, cmd *cobra.Command, modOpts *autocliv1.ModuleOptions) error { + if txCmdDesc := modOpts.Tx; txCmdDesc != nil { + short := txCmdDesc.Short + if short == "" { + short = fmt.Sprintf("Transactions commands for the %s module", moduleName) + } + subCmd := topLevelCmd(cmd.Context(), moduleName, short) + if err := builder.AddMsgServiceCommands(subCmd, txCmdDesc); err != nil { + return err + } + + cmd.AddCommand(subCmd) + } + + return nil +} + +// enhanceCustomCmd enhances the provided custom query or msg command autocli commands for a module. +func enhanceCustomCmd(builder *Builder, cmd *cobra.Command, cmdType cmdType, modOpts *autocliv1.ModuleOptions) error { + switch cmdType { + case queryCmdType: + if modOpts.Query != nil && modOpts.Query.EnhanceCustomCommand { + if err := builder.AddQueryServiceCommands(cmd, modOpts.Query); err != nil { + return err + } + } + case msgCmdType: + if modOpts.Tx != nil && modOpts.Tx.EnhanceCustomCommand { + if err := builder.AddMsgServiceCommands(cmd, modOpts.Tx); err != nil { + return err + } + } + } + + return nil +} + +// outOrStdoutFormat formats the output based on the output flag and writes it to the command's output stream. +func (b *Builder) outOrStdoutFormat(cmd *cobra.Command, out []byte) error { + p, err := print.NewPrinter(cmd) + if err != nil { + return err + } + return p.PrintBytes(out) +} + +// getContext creates and returns a new context.Context with an autocli.Context value. +// It initializes a printer and, if necessary, a keyring based on command flags. +func (b *Builder) getContext(cmd *cobra.Command) (context.Context, error) { + // if the command uses the keyring this must be set + var ( + k keyring.Keyring + err error + ) + if cmd.Flags().Lookup(flags.FlagKeyringDir) != nil && cmd.Flags().Lookup(flags.FlagKeyringBackend) != nil { + k, err = keyring.NewKeyringFromFlags(cmd.Flags(), b.AddressCodec, cmd.InOrStdin(), b.Cdc) + if err != nil { + return nil, err + } + } else { + k = keyring.NoKeyring{} + } + + clientCtx := clientcontext.Context{ + Flags: cmd.Flags(), + AddressCodec: b.AddressCodec, + ValidatorAddressCodec: b.ValidatorAddressCodec, + ConsensusAddressCodec: b.ConsensusAddressCodec, + Cdc: b.Cdc, + Keyring: k, + EnabledSignModes: b.EnabledSignModes, + } + + return clientcontext.SetInContext(cmd.Context(), clientCtx), nil +} + +// preRunE returns a function that sets flags from the configuration before running a command. +// It is used as a PreRunE hook for cobra commands to ensure flags are properly initialized +// from the configuration before command execution. +func (b *Builder) preRunE() func(cmd *cobra.Command, args []string) error { + return func(cmd *cobra.Command, args []string) error { + err := b.setFlagsFromConfig(cmd) + if err != nil { + return err + } + + return nil + } +} + +// setFlagsFromConfig sets command flags from the provided configuration. +// It only sets flags that haven't been explicitly changed by the user. +func (b *Builder) setFlagsFromConfig(cmd *cobra.Command) error { + conf, err := config.CreateClientConfigFromFlags(cmd.Flags()) + if err != nil { + return err + } + + flagsToSet := map[string]string{ + flags.FlagChainID: conf.ChainID, + flags.FlagKeyringBackend: conf.KeyringBackend, + flags.FlagFrom: conf.KeyringDefaultKeyName, + flags.FlagOutput: conf.Output, + flags.FlagNode: conf.Node, + flags.FlagBroadcastMode: conf.BroadcastMode, + flags.FlagGrpcAddress: conf.GRPC.Address, + flags.FlagGrpcInsecure: strconv.FormatBool(conf.GRPC.Insecure), + } + + for flagName, value := range flagsToSet { + if flag := cmd.Flags().Lookup(flagName); flag != nil && !cmd.Flags().Changed(flagName) { + if err := cmd.Flags().Set(flagName, value); err != nil { + return err + } + } + } + + return nil +} + +// getQueryClientConn returns a function that creates a gRPC client connection based on command flags. +// It handles the creation of secure or insecure connections and falls back to a CometBFT broadcaster +// if no gRPC address is specified. +func getQueryClientConn(cdc codec.Codec) func(cmd *cobra.Command) (grpc.ClientConnInterface, error) { + return func(cmd *cobra.Command) (grpc.ClientConnInterface, error) { + var err error + creds := grpcinsecure.NewCredentials() + + insecure := true + if cmd.Flags().Lookup(flags.FlagGrpcInsecure) != nil { + insecure, err = cmd.Flags().GetBool(flags.FlagGrpcInsecure) + if err != nil { + return nil, err + } + } + if !insecure { + creds = credentials.NewTLS(&tls.Config{MinVersion: tls.VersionTLS12}) + } + + var addr string + if cmd.Flags().Lookup(flags.FlagGrpcAddress) != nil { + addr, err = cmd.Flags().GetString(flags.FlagGrpcAddress) + if err != nil { + return nil, err + } + } + if addr == "" { + // if grpc-addr has not been set, use the default clientConn + // TODO: default is comet + node, err := cmd.Flags().GetString(flags.FlagNode) + if err != nil { + return nil, err + } + return comet.NewCometBFTBroadcaster(node, comet.BroadcastSync, cdc) + } + + return grpc.NewClient(addr, []grpc.DialOption{grpc.WithTransportCredentials(creds)}...) + } +} diff --git a/connect/internal/autocli/common_test.go b/connect/internal/autocli/common_test.go new file mode 100644 index 00000000..bc857467 --- /dev/null +++ b/connect/internal/autocli/common_test.go @@ -0,0 +1,235 @@ +package autocli + +import ( + "bytes" + "context" + "net" + "testing" + + "github.com/spf13/cobra" + "google.golang.org/grpc" + "google.golang.org/grpc/credentials/insecure" + "google.golang.org/protobuf/reflect/protoregistry" + "gotest.tools/v3/assert" + + autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" + reflectionv2alpha1 "cosmossdk.io/api/cosmos/base/reflection/v2alpha1" + "github.com/ignite/apps/connect/internal/autocli/flag" + "github.com/ignite/apps/connect/internal/internal/testpb" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + sdkkeyring "github.com/cosmos/cosmos-sdk/crypto/keyring" + sdk "github.com/cosmos/cosmos-sdk/types" + moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" + "github.com/cosmos/cosmos-sdk/x/bank" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" +) + +type fixture struct { + conn *testClientConn + b *Builder + clientCtx client.Context + + home string + chainID string + kBackend string +} + +func initFixture(t *testing.T) *fixture { + t.Helper() + home := t.TempDir() + server := grpc.NewServer() + testpb.RegisterQueryServer(server, &testEchoServer{}) + reflectionv2alpha1.RegisterReflectionServiceServer(server, &testReflectionServer{}) + listener, err := net.Listen("tcp", "127.0.0.1:0") + assert.NilError(t, err) + go func() { + err := server.Serve(listener) + if err != nil { + panic(err) + } + }() + + clientConn, err := grpc.NewClient(listener.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials())) + assert.NilError(t, err) + + encodingConfig := moduletestutil.MakeTestEncodingConfig(bank.AppModule{}) + kr, err := sdkkeyring.New(sdk.KeyringServiceName(), sdkkeyring.BackendMemory, home, nil, encodingConfig.Codec) + assert.NilError(t, err) + + interfaceRegistry := encodingConfig.Codec.InterfaceRegistry() + banktypes.RegisterInterfaces(interfaceRegistry) + + clientCtx := client.Context{}. + WithKeyring(kr). + WithKeyringDir(home). + WithHomeDir(home). + WithViper(""). + WithInterfaceRegistry(interfaceRegistry). + WithTxConfig(encodingConfig.TxConfig). + WithAccountRetriever(client.MockAccountRetriever{}). + WithChainID("autocli-test") + + conn := &testClientConn{ClientConn: clientConn} + b := &Builder{ + Builder: flag.Builder{ + TypeResolver: protoregistry.GlobalTypes, + FileResolver: protoregistry.GlobalFiles, + AddressCodec: interfaceRegistry.SigningContext().AddressCodec(), + ValidatorAddressCodec: interfaceRegistry.SigningContext().ValidatorAddressCodec(), + ConsensusAddressCodec: addresscodec.NewBech32Codec("cosmosvalcons"), + }, + GetClientConn: func(*cobra.Command) (grpc.ClientConnInterface, error) { + return conn, nil + }, + AddQueryConnFlags: flags.AddQueryFlagsToCmd, + AddTxConnFlags: addTxAndGlobalFlagsToCmd, + Cdc: encodingConfig.Codec, + } + assert.NilError(t, b.ValidateAndComplete()) + + return &fixture{ + conn: conn, + b: b, + clientCtx: clientCtx, + + home: home, + chainID: "autocli-test", + kBackend: sdkkeyring.BackendMemory, + } +} + +func addTxAndGlobalFlagsToCmd(cmd *cobra.Command) { + f := cmd.Flags() + f.String("home", "", "home directory") + flags.AddTxFlagsToCmd(cmd) +} + +func runCmd(fixture *fixture, command func(moduleName string, f *fixture) (*cobra.Command, error), args ...string) (*bytes.Buffer, error) { + out := &bytes.Buffer{} + cmd, err := command("test", fixture) + if err != nil { + return out, err + } + + cmd.SetArgs(args) + cmd.SetOut(out) + return out, cmd.Execute() +} + +type testReflectionServer struct { + reflectionv2alpha1.UnimplementedReflectionServiceServer +} + +func (t testReflectionServer) GetConfigurationDescriptor(_ context.Context, client *reflectionv2alpha1.GetConfigurationDescriptorRequest) (*reflectionv2alpha1.GetConfigurationDescriptorResponse, error) { + return &reflectionv2alpha1.GetConfigurationDescriptorResponse{ + Config: &reflectionv2alpha1.ConfigurationDescriptor{ + Bech32AccountAddressPrefix: "cosmos", + }, + }, nil +} + +var _ reflectionv2alpha1.ReflectionServiceServer = testReflectionServer{} + +type testClientConn struct { + *grpc.ClientConn + lastRequest interface{} + lastResponse interface{} +} + +func (t *testClientConn) Invoke(ctx context.Context, method string, args, reply interface{}, opts ...grpc.CallOption) error { + err := t.ClientConn.Invoke(ctx, method, args, reply, opts...) + t.lastRequest = args + t.lastResponse = reply + return err +} + +type testEchoServer struct { + testpb.UnimplementedQueryServer +} + +func (t testEchoServer) Echo(_ context.Context, request *testpb.EchoRequest) (*testpb.EchoResponse, error) { + return &testpb.EchoResponse{Request: request}, nil +} + +var _ testpb.QueryServer = testEchoServer{} + +func TestEnhanceCommand(t *testing.T) { + b := &Builder{} + // Test that the command has a subcommand + cmd := &cobra.Command{Use: "test"} + cmd.AddCommand(&cobra.Command{Use: "test"}) + + for i := 0; i < 2; i++ { + cmdTp := cmdType(i) + + appOptions := AppOptions{ + ModuleOptions: map[string]*autocliv1.ModuleOptions{ + "test": {}, + }, + } + + err := b.enhanceCommandCommon(cmd, cmdTp, appOptions, map[string]*cobra.Command{}) + assert.NilError(t, err) + + cmd = &cobra.Command{Use: "test"} + + appOptions = AppOptions{ + ModuleOptions: map[string]*autocliv1.ModuleOptions{}, + } + customCommands := map[string]*cobra.Command{ + "test2": {Use: "test"}, + } + err = b.enhanceCommandCommon(cmd, cmdTp, appOptions, customCommands) + assert.NilError(t, err) + + cmd = &cobra.Command{Use: "test"} + appOptions = AppOptions{ + ModuleOptions: map[string]*autocliv1.ModuleOptions{ + "test": {Tx: nil}, + }, + } + err = b.enhanceCommandCommon(cmd, cmdTp, appOptions, map[string]*cobra.Command{}) + assert.NilError(t, err) + } +} + +func TestErrorBuildCommand(t *testing.T) { + fixture := initFixture(t) + b := fixture.b + b.AddQueryConnFlags = nil + b.AddTxConnFlags = nil + + commandDescriptor := &autocliv1.ServiceCommandDescriptor{ + Service: testpb.Msg_ServiceDesc.ServiceName, + RpcCommandOptions: []*autocliv1.RpcCommandOptions{ + { + RpcMethod: "Send", + PositionalArgs: []*autocliv1.PositionalArgDescriptor{ + { + ProtoField: "un-existent-proto-field", + }, + }, + }, + }, + } + + appOptions := AppOptions{ + ModuleOptions: map[string]*autocliv1.ModuleOptions{ + "test": { + Query: commandDescriptor, + Tx: commandDescriptor, + }, + }, + } + + _, err := b.BuildMsgCommand(context.Background(), appOptions, nil) + assert.ErrorContains(t, err, "can't find field un-existent-proto-field") + + appOptions.ModuleOptions["test"].Tx = &autocliv1.ServiceCommandDescriptor{Service: "un-existent-service"} + appOptions.ModuleOptions["test"].Query = &autocliv1.ServiceCommandDescriptor{Service: "un-existent-service"} + _, err = b.BuildMsgCommand(context.Background(), appOptions, nil) + assert.ErrorContains(t, err, "can't find service un-existent-service") +} diff --git a/connect/internal/autocli/config/config.go b/connect/internal/autocli/config/config.go new file mode 100644 index 00000000..91b93988 --- /dev/null +++ b/connect/internal/autocli/config/config.go @@ -0,0 +1,133 @@ +package config + +import ( + "errors" + "fmt" + "os" + "path" + "path/filepath" + "strings" + + "github.com/pelletier/go-toml/v2" + "github.com/spf13/pflag" + "github.com/spf13/viper" + + "github.com/ignite/apps/connect/internal/internal/flags" +) + +type Config struct { + ChainID string `mapstructure:"chain-id" toml:"chain-id" comment:"The chain ID of the blockchain network"` + KeyringBackend string `mapstructure:"keyring-backend" toml:"keyring-backend" comment:"The keyring backend to use (os|file|kwallet|pass|test|memory)"` + KeyringDefaultKeyName string `mapstructure:"keyring-default-keyname" toml:"keyring-default-keyname" comment:"The default key name to use for signing transactions"` + Output string `mapstructure:"output" toml:"output" comment:"The output format for queries (text|json)"` + Node string `mapstructure:"node" toml:"node" comment:"The RPC endpoint URL for the node to connect to"` + BroadcastMode string `mapstructure:"broadcast-mode" toml:"broadcast-mode" comment:"How transactions are broadcast to the network (sync|async|block)"` + GRPC GRPCConfig `mapstructure:",squash" comment:"The gRPC client configuration"` +} + +// GRPCConfig holds the gRPC client configuration. +type GRPCConfig struct { + Address string `mapstructure:"grpc-address" toml:"grpc-address" comment:"The gRPC server address to connect to"` + Insecure bool `mapstructure:"grpc-insecure" toml:"grpc-insecure" comment:"Allow gRPC over insecure connections"` +} + +func DefaultConfig() *Config { + return &Config{ + ChainID: "", + KeyringBackend: "os", + KeyringDefaultKeyName: "", + Output: "text", + Node: "tcp://localhost:26657", + BroadcastMode: "sync", + } +} + +// CreateClientConfig creates a new client configuration or reads an existing one. +func CreateClientConfig(homeDir, chainID string, v *viper.Viper) (*Config, error) { + if homeDir == "" { + return nil, errors.New("home dir can't be empty") + } + + configPath := filepath.Join(homeDir, "config") + configFilePath := filepath.Join(configPath, "client.toml") + + // when client.toml does not exist create and init with default values + if _, err := os.Stat(configFilePath); os.IsNotExist(err) { + if err := os.MkdirAll(configPath, os.ModePerm); err != nil { + return nil, fmt.Errorf("couldn't make client config: %w", err) + } + + conf := DefaultConfig() + if chainID != "" { + // chain-id will be written to the client.toml while initiating the chain. + conf.ChainID = chainID + } + + if err := writeConfigFile(configFilePath, conf); err != nil { + return nil, fmt.Errorf("could not write client config to the file: %w", err) + } + } + + conf, err := readConfig(configPath, v) + if err != nil { + return nil, fmt.Errorf("couldn't get client config: %w", err) + } + + return conf, nil +} + +// CreateClientConfigFromFlags creates a client configuration from command-line flags. +func CreateClientConfigFromFlags(set *pflag.FlagSet) (*Config, error) { + homeDir, _ := set.GetString(flags.FlagHome) + if homeDir == "" { + return DefaultConfig(), nil + } + chainID, _ := set.GetString(flags.FlagChainID) + + v := viper.New() + executableName, err := os.Executable() + if err != nil { + return nil, err + } + + v.SetEnvPrefix(path.Base(executableName)) + v.SetEnvKeyReplacer(strings.NewReplacer(".", "_", "-", "_")) + v.AutomaticEnv() + + return CreateClientConfig(homeDir, chainID, v) +} + +// writeConfigFile renders config using the template and writes it to +// configFilePath. +func writeConfigFile(configFilePath string, config *Config) error { + b, err := toml.Marshal(config) + if err != nil { + return err + } + + if dir := filepath.Dir(configFilePath); dir != "" { + if err := os.MkdirAll(dir, os.ModePerm); err != nil { + return err + } + } + + return os.WriteFile(configFilePath, b, 0o600) +} + +// readConfig reads values from client.toml file and unmarshals them into ClientConfig +func readConfig(configPath string, v *viper.Viper) (*Config, error) { + v.AddConfigPath(configPath) + v.SetConfigName("client") + v.SetConfigType("toml") + + if err := v.ReadInConfig(); err != nil { + return nil, err + } + + conf := DefaultConfig() + if err := v.Unmarshal(conf); err != nil { + return nil, err + } + + return conf, nil +} diff --git a/connect/internal/autocli/flag/address.go b/connect/internal/autocli/flag/address.go new file mode 100644 index 00000000..415159d6 --- /dev/null +++ b/connect/internal/autocli/flag/address.go @@ -0,0 +1,163 @@ +package flag + +import ( + "context" + "fmt" + + "google.golang.org/protobuf/reflect/protoreflect" + + "cosmossdk.io/core/address" + "github.com/ignite/apps/connect/internal/autocli/keyring" + clientcontext "github.com/ignite/apps/connect/internal/context" + + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/types" + cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" +) + +type addressStringType struct{} + +func (a addressStringType) NewValue(ctx *context.Context, b *Builder) Value { + return &addressValue{addressCodec: b.AddressCodec, ctx: ctx} +} + +func (a addressStringType) DefaultValue() string { + return "" +} + +type validatorAddressStringType struct{} + +func (a validatorAddressStringType) NewValue(ctx *context.Context, b *Builder) Value { + return &addressValue{addressCodec: b.ValidatorAddressCodec, ctx: ctx} +} + +func (a validatorAddressStringType) DefaultValue() string { + return "" +} + +type addressValue struct { + ctx *context.Context + addressCodec address.Codec + + value string +} + +func (a *addressValue) Get(protoreflect.Value) (protoreflect.Value, error) { + return protoreflect.ValueOfString(a.value), nil +} + +func (a *addressValue) String() string { + return a.value +} + +// Set implements the flag.Value interface for addressValue. +func (a *addressValue) Set(s string) error { + // we get the keyring on set, as in NewValue the context is the parent context (before RunE) + k := getKeyringFromCtx(a.ctx) + addr, err := k.LookupAddressByKeyName(s) + if err == nil { + addrStr, err := a.addressCodec.BytesToString(addr) + if err != nil { + return fmt.Errorf("invalid account address got from keyring: %w", err) + } + + a.value = addrStr + return nil + } + + _, err = a.addressCodec.StringToBytes(s) + if err != nil { + return fmt.Errorf("invalid account address or key name: %w", err) + } + + a.value = s + + return nil +} + +func (a *addressValue) Type() string { + return "account address or key name" +} + +type consensusAddressStringType struct{} + +func (a consensusAddressStringType) NewValue(ctx *context.Context, b *Builder) Value { + return &consensusAddressValue{ + addressValue: addressValue{ + addressCodec: b.ConsensusAddressCodec, + ctx: ctx, + }, + } +} + +func (a consensusAddressStringType) DefaultValue() string { + return "" +} + +type consensusAddressValue struct { + addressValue +} + +func (a consensusAddressValue) Get(protoreflect.Value) (protoreflect.Value, error) { + return protoreflect.ValueOfString(a.value), nil +} + +func (a consensusAddressValue) String() string { + return a.value +} + +func (a *consensusAddressValue) Set(s string) error { + // we get the keyring on set, as in NewValue the context is the parent context (before RunE) + k := getKeyringFromCtx(a.ctx) + addr, err := k.LookupAddressByKeyName(s) + if err == nil { + addrStr, err := a.addressCodec.BytesToString(addr) + if err != nil { + return fmt.Errorf("invalid consensus address got from keyring: %w", err) + } + + a.value = addrStr + return nil + } + + _, err = a.addressCodec.StringToBytes(s) + if err == nil { + a.value = s + return nil + } + + // fallback to pubkey parsing + registry := types.NewInterfaceRegistry() + cryptocodec.RegisterInterfaces(registry) + cdc := codec.NewProtoCodec(registry) + + var pk cryptotypes.PubKey + err2 := cdc.UnmarshalInterfaceJSON([]byte(s), &pk) + if err2 != nil { + return fmt.Errorf("input isn't a pubkey (%w) or is an invalid account address (%w)", err, err2) + } + + a.value, err = a.addressCodec.BytesToString(pk.Address()) + if err != nil { + return fmt.Errorf("invalid pubkey address: %w", err) + } + + return nil +} + +// getKeyringFromCtx retrieves the keyring from the provided context. +// If the context is nil or does not contain a valid client context, +// it returns a no-op keyring implementation. +func getKeyringFromCtx(ctx *context.Context) keyring.Keyring { + if *ctx == nil { + return keyring.NoKeyring{} + } + + c, err := clientcontext.ClientContextFromGoContext(*ctx) + if err != nil { + return keyring.NoKeyring{} + } + + return c.Keyring +} diff --git a/connect/internal/autocli/flag/binary.go b/connect/internal/autocli/flag/binary.go new file mode 100644 index 00000000..5567d5f8 --- /dev/null +++ b/connect/internal/autocli/flag/binary.go @@ -0,0 +1,63 @@ +package flag + +import ( + "context" + "encoding/base64" + "encoding/hex" + "errors" + "os" + + "google.golang.org/protobuf/reflect/protoreflect" +) + +type binaryType struct{} + +var _ Value = (*fileBinaryValue)(nil) + +func (f binaryType) NewValue(*context.Context, *Builder) Value { + return &fileBinaryValue{} +} + +func (f binaryType) DefaultValue() string { + return "" +} + +// fileBinaryValue is a Value that holds a binary file. +type fileBinaryValue struct { + value []byte +} + +func (f *fileBinaryValue) Get(protoreflect.Value) (protoreflect.Value, error) { + return protoreflect.ValueOfBytes(f.value), nil +} + +func (f *fileBinaryValue) String() string { + return string(f.value) +} + +// Set implements the flag.Value interface for binary files, with exceptions. +// If the input string is a valid file path, the value will be the content of that file. +// If the input string is a valid hex or base64 string, the value will be the decoded form of that string. +// If the input string is not a valid file path, hex string, or base64 string, Set will return an error. +func (f *fileBinaryValue) Set(s string) error { + if data, err := os.ReadFile(s); err == nil { + f.value = data + return nil + } + + if data, err := hex.DecodeString(s); err == nil { + f.value = data + return nil + } + + if data, err := base64.StdEncoding.DecodeString(s); err == nil { + f.value = data + return nil + } + + return errors.New("input string is neither a valid file path, hex, or base64 encoded") +} + +func (f *fileBinaryValue) Type() string { + return "binary" +} diff --git a/connect/internal/autocli/flag/builder.go b/connect/internal/autocli/flag/builder.go new file mode 100644 index 00000000..4109ef60 --- /dev/null +++ b/connect/internal/autocli/flag/builder.go @@ -0,0 +1,511 @@ +package flag + +import ( + "context" + "errors" + "fmt" + "strconv" + "strings" + + cosmos_proto "github.com/cosmos/cosmos-proto" + "github.com/spf13/cobra" + "github.com/spf13/pflag" + "google.golang.org/protobuf/proto" + "google.golang.org/protobuf/reflect/protodesc" + "google.golang.org/protobuf/reflect/protoreflect" + "google.golang.org/protobuf/reflect/protoregistry" + + autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" + msgv1 "cosmossdk.io/api/cosmos/msg/v1" + "cosmossdk.io/core/address" + "github.com/ignite/apps/connect/internal/internal/flags" + "github.com/ignite/apps/connect/internal/internal/util" +) + +const ( + AddressStringScalarType = "cosmos.AddressString" + ValidatorAddressStringScalarType = "cosmos.ValidatorAddressString" + ConsensusAddressStringScalarType = "cosmos.ConsensusAddressString" + PubkeyScalarType = "cosmos.Pubkey" + DecScalarType = "cosmos.Dec" +) + +// Builder manages options for building pflag flags for protobuf messages. +type Builder struct { + // TypeResolver specifies how protobuf types will be resolved. If it is + // nil protoregistry.GlobalTypes will be used. + TypeResolver interface { + protoregistry.MessageTypeResolver + protoregistry.ExtensionTypeResolver + } + + // FileResolver specifies how protobuf file descriptors will be resolved. If it is + // nil protoregistry.GlobalFiles will be used. + FileResolver interface { + protodesc.Resolver + RangeFiles(func(protoreflect.FileDescriptor) bool) + } + + messageFlagTypes map[protoreflect.FullName]Type + scalarFlagTypes map[string]Type + + // Address Codecs are the address codecs to use for client/v2. + AddressCodec address.Codec + ValidatorAddressCodec address.Codec + ConsensusAddressCodec address.Codec +} + +func (b *Builder) init() { + if b.messageFlagTypes == nil { + b.messageFlagTypes = map[protoreflect.FullName]Type{} + b.messageFlagTypes["google.protobuf.Timestamp"] = timestampType{} + b.messageFlagTypes["google.protobuf.Duration"] = durationType{} + b.messageFlagTypes["cosmos.base.v1beta1.Coin"] = coinType{} + b.messageFlagTypes["cosmos.base.v1beta1.DecCoin"] = decCoinType{} + } + + if b.scalarFlagTypes == nil { + b.scalarFlagTypes = map[string]Type{} + b.scalarFlagTypes[AddressStringScalarType] = addressStringType{} + b.scalarFlagTypes[ValidatorAddressStringScalarType] = validatorAddressStringType{} + b.scalarFlagTypes[ConsensusAddressStringScalarType] = consensusAddressStringType{} + b.scalarFlagTypes[PubkeyScalarType] = pubkeyType{} + b.scalarFlagTypes[DecScalarType] = decType{} + } +} + +// ValidateAndComplete the flag builder fields. +// It returns an error if any of the required fields are missing. +// If the keyring is nil, it will be set to a no keyring. +func (b *Builder) ValidateAndComplete() error { + if b.AddressCodec == nil { + return errors.New("address codec is required in flag builder") + } + + if b.ValidatorAddressCodec == nil { + return errors.New("validator address codec is required in flag builder") + } + + if b.ConsensusAddressCodec == nil { + return errors.New("consensus address codec is required in flag builder") + } + + if b.TypeResolver == nil { + return errors.New("type resolver is required in flag builder") + } + + if b.FileResolver == nil { + return errors.New("file resolver is required in flag builder") + } + + return nil +} + +// DefineMessageFlagType allows to extend custom protobuf message type handling for flags (and positional arguments). +func (b *Builder) DefineMessageFlagType(messageName protoreflect.FullName, flagType Type) { + b.init() + b.messageFlagTypes[messageName] = flagType +} + +// DefineScalarFlagType allows to extend custom scalar type handling for flags (and positional arguments). +func (b *Builder) DefineScalarFlagType(scalarName string, flagType Type) { + b.init() + b.scalarFlagTypes[scalarName] = flagType +} + +// AddMessageFlags adds flags for each field in the message to the flag set. +func (b *Builder) AddMessageFlags(ctx *context.Context, flagSet *pflag.FlagSet, messageType protoreflect.MessageType, commandOptions *autocliv1.RpcCommandOptions) (*MessageBinder, error) { + return b.addMessageFlags(ctx, flagSet, messageType, commandOptions, namingOptions{}) +} + +// addMessageFlags adds flags for each field in the message to the flag set. +func (b *Builder) addMessageFlags(ctx *context.Context, flagSet *pflag.FlagSet, messageType protoreflect.MessageType, commandOptions *autocliv1.RpcCommandOptions, options namingOptions) (*MessageBinder, error) { + messageBinder := &MessageBinder{ + messageType: messageType, + // positional args are also parsed using a FlagSet so that we can reuse all the same parsers + positionalFlagSet: pflag.NewFlagSet("positional", pflag.ContinueOnError), + } + + fields := messageType.Descriptor().Fields() + signerFieldName := GetSignerFieldName(messageType.Descriptor()) + + isPositional := map[string]bool{} + + positionalArgsLen := len(commandOptions.PositionalArgs) + for i, arg := range commandOptions.PositionalArgs { + isPositional[arg.ProtoField] = true + + // verify if a positional field is a signer field + if arg.ProtoField == signerFieldName { + messageBinder.SignerInfo = SignerInfo{ + PositionalArgIndex: i, + FieldName: arg.ProtoField, + } + } + + if arg.Optional && arg.Varargs { + return nil, fmt.Errorf("positional argument %s can't be both optional and varargs", arg.ProtoField) + } + + if arg.Varargs { + if i != positionalArgsLen-1 { + return nil, fmt.Errorf("varargs positional argument %s must be the last argument", arg.ProtoField) + } + + messageBinder.hasVarargs = true + } + + if arg.Optional { + if i != positionalArgsLen-1 { + return nil, fmt.Errorf("optional positional argument %s must be the last argument", arg.ProtoField) + } + + messageBinder.hasOptional = true + } + + s := strings.Split(arg.ProtoField, ".") + if len(s) == 1 { + f, err := b.addFieldBindingToArgs(ctx, messageBinder, protoreflect.Name(arg.ProtoField), fields) + if err != nil { + return nil, err + } + messageBinder.positionalArgs = append(messageBinder.positionalArgs, f) + } else { + err := b.addFlattenFieldBindingToArgs(ctx, arg.ProtoField, s, messageType, messageBinder) + if err != nil { + return nil, err + } + } + } + + totalArgs := len(messageBinder.positionalArgs) + switch { + case messageBinder.hasVarargs: + messageBinder.CobraArgs = cobra.MinimumNArgs(totalArgs - 1) + messageBinder.mandatoryArgUntil = totalArgs - 1 + case messageBinder.hasOptional: + messageBinder.CobraArgs = cobra.RangeArgs(totalArgs-1, totalArgs) + messageBinder.mandatoryArgUntil = totalArgs - 1 + default: + messageBinder.CobraArgs = cobra.ExactArgs(totalArgs) + messageBinder.mandatoryArgUntil = totalArgs + } + + // validate flag options + for name, opts := range commandOptions.FlagOptions { + if fields.ByName(protoreflect.Name(name)) == nil { + return nil, fmt.Errorf("can't find field %s on %s specified as a flag", name, messageType.Descriptor().FullName()) + } + + // verify if a flag is a signer field + if name == signerFieldName { + messageBinder.SignerInfo = SignerInfo{ + FieldName: name, + IsFlag: true, + FlagName: opts.Name, + } + } + } + + // if signer has not been specified as positional arguments, + // add it as `--from` flag (instead of --field-name flags) + if signerFieldName != "" && messageBinder.SignerInfo == (SignerInfo{}) { + if commandOptions.FlagOptions == nil { + commandOptions.FlagOptions = make(map[string]*autocliv1.FlagOptions) + } + + commandOptions.FlagOptions[signerFieldName] = &autocliv1.FlagOptions{ + Name: flags.FlagFrom, + Usage: "Name or address with which to sign the message", + Shorthand: "f", + } + + messageBinder.SignerInfo = SignerInfo{ + FieldName: signerFieldName, + IsFlag: true, + FlagName: flags.FlagFrom, + } + } + + // define all other fields as flags + flagOptsByFlagName := map[string]*autocliv1.FlagOptions{} + for i := 0; i < fields.Len(); i++ { + field := fields.Get(i) + fieldName := string(field.Name()) + + // skips positional args and signer field if already set + if isPositional[fieldName] || + (fieldName == signerFieldName && messageBinder.SignerInfo.FlagName == flags.FlagFrom) { + continue + } + + flagOpts := commandOptions.FlagOptions[fieldName] + name, hasValue, err := b.addFieldFlag(ctx, flagSet, field, flagOpts, options) + if err != nil { + return nil, err + } + flagOptsByFlagName[name] = flagOpts + + messageBinder.flagBindings = append(messageBinder.flagBindings, fieldBinding{ + hasValue: hasValue, + field: field, + }) + } + + flagSet.VisitAll(func(flag *pflag.Flag) { + opts := flagOptsByFlagName[flag.Name] + if opts != nil { + // This is a bit of hacking around the pflag API, but + // we need to set these options here using Flag.VisitAll because the flag + // constructors that pflag gives us (StringP, Int32P, etc.) do not + // actually return the *Flag instance + flag.Deprecated = opts.Deprecated + flag.ShorthandDeprecated = opts.ShorthandDeprecated + flag.Hidden = opts.Hidden + } + }) + + return messageBinder, nil +} + +// addFlattenFieldBindingToArgs recursively adds field bindings for nested message fields to the message binder. +// It takes a slice of field names representing the path to the target field, where each element is a field name +// in the nested message structure. For example, ["foo", "bar", "baz"] would bind the "baz" field inside the "bar" +// message which is inside the "foo" message. +func (b *Builder) addFlattenFieldBindingToArgs(ctx *context.Context, path string, s []string, msg protoreflect.MessageType, messageBinder *MessageBinder) error { + fields := msg.Descriptor().Fields() + if len(s) == 1 { + f, err := b.addFieldBindingToArgs(ctx, messageBinder, protoreflect.Name(s[0]), fields) + if err != nil { + return err + } + f.path = path + messageBinder.positionalArgs = append(messageBinder.positionalArgs, f) + return nil + } + fd := fields.ByName(protoreflect.Name(s[0])) + var innerMsg protoreflect.MessageType + if fd.IsList() { + innerMsg = msg.New().Get(fd).List().NewElement().Message().Type() + } else { + innerMsg = msg.New().Get(fd).Message().Type() + } + return b.addFlattenFieldBindingToArgs(ctx, path, s[1:], innerMsg, messageBinder) +} + +// addFieldBindingToArgs adds a fieldBinding for a positional argument to the message binder. +// The fieldBinding is appended to the positional arguments list in the message binder. +func (b *Builder) addFieldBindingToArgs(ctx *context.Context, messageBinder *MessageBinder, name protoreflect.Name, fields protoreflect.FieldDescriptors) (fieldBinding, error) { + field := fields.ByName(name) + if field == nil { + return fieldBinding{}, fmt.Errorf("can't find field %s", name) // TODO: it will improve error if msg.FullName() was included.` + } + + _, hasValue, err := b.addFieldFlag( + ctx, + messageBinder.positionalFlagSet, + field, + &autocliv1.FlagOptions{Name: fmt.Sprintf("%d", len(messageBinder.positionalArgs))}, + namingOptions{}, + ) + if err != nil { + return fieldBinding{}, err + } + + return fieldBinding{ + field: field, + hasValue: hasValue, + }, nil +} + +// bindPageRequest create a flag for pagination +func (b *Builder) bindPageRequest(ctx *context.Context, flagSet *pflag.FlagSet, field protoreflect.FieldDescriptor) (HasValue, error) { + return b.addMessageFlags( + ctx, + flagSet, + util.ResolveMessageType(b.TypeResolver, field.Message()), + &autocliv1.RpcCommandOptions{}, + namingOptions{Prefix: "page-"}, + ) +} + +// namingOptions specifies internal naming options for flags. +type namingOptions struct { + // Prefix is a prefix to prepend to all flags. + Prefix string +} + +// addFieldFlag adds a flag for the provided field to the flag set. +func (b *Builder) addFieldFlag(ctx *context.Context, flagSet *pflag.FlagSet, field protoreflect.FieldDescriptor, opts *autocliv1.FlagOptions, options namingOptions) (name string, hasValue HasValue, err error) { + if opts == nil { + opts = &autocliv1.FlagOptions{} + } + + if field.Kind() == protoreflect.MessageKind && field.Message().FullName() == "cosmos.base.query.v1beta1.PageRequest" { + hasValue, err := b.bindPageRequest(ctx, flagSet, field) + return "", hasValue, err + } + + name = opts.Name + if name == "" { + name = options.Prefix + util.DescriptorKebabName(field) + } + + usage := opts.Usage + shorthand := opts.Shorthand + defaultValue := opts.DefaultValue + + if typ := b.resolveFlagType(field); typ != nil { + if defaultValue == "" { + defaultValue = typ.DefaultValue() + } + + val := typ.NewValue(ctx, b) + flagSet.AddFlag(&pflag.Flag{ + Name: name, + Shorthand: shorthand, + Usage: usage, + DefValue: defaultValue, + Value: val, + }) + return name, val, nil + } + + // use the built-in pflag StringP, Int32P, etc. functions + var val HasValue + + if field.IsList() { + val = bindSimpleListFlag(flagSet, field.Kind(), name, shorthand, usage) + } else if field.IsMap() { + keyKind := field.MapKey().Kind() + valKind := field.MapValue().Kind() + val = bindSimpleMapFlag(flagSet, keyKind, valKind, name, shorthand, usage) + } else { + val = bindSimpleFlag(flagSet, field.Kind(), name, shorthand, usage) + } + + // This is a bit of hacking around the pflag API, but the + // defaultValue is set in this way because this is much easier than trying + // to parse the string into the types that StringSliceP, Int32P, etc. + if defaultValue != "" { + err = flagSet.Set(name, defaultValue) + } + + return name, val, err +} + +func (b *Builder) resolveFlagType(field protoreflect.FieldDescriptor) Type { + typ := b.resolveFlagTypeBasic(field) + if field.IsList() { + if typ != nil { + return compositeListType{simpleType: typ} + } + return nil + } + if field.IsMap() { + keyKind := field.MapKey().Kind() + valType := b.resolveFlagType(field.MapValue()) + if valType != nil { + switch keyKind { + case protoreflect.StringKind: + ct := new(compositeMapType[string]) + ct.keyValueResolver = func(s string) (string, error) { return s, nil } + ct.valueType = valType + ct.keyType = "string" + return ct + case protoreflect.Int32Kind, protoreflect.Sint32Kind, protoreflect.Sfixed32Kind: + ct := new(compositeMapType[int32]) + ct.keyValueResolver = func(s string) (int32, error) { + i, err := strconv.ParseInt(s, 10, 32) + return int32(i), err + } + ct.valueType = valType + ct.keyType = "int32" + return ct + case protoreflect.Int64Kind, protoreflect.Sint64Kind, protoreflect.Sfixed64Kind: + ct := new(compositeMapType[int64]) + ct.keyValueResolver = func(s string) (int64, error) { + i, err := strconv.ParseInt(s, 10, 64) + return i, err + } + ct.valueType = valType + ct.keyType = "int64" + return ct + case protoreflect.Uint32Kind, protoreflect.Fixed32Kind: + ct := new(compositeMapType[uint32]) + ct.keyValueResolver = func(s string) (uint32, error) { + i, err := strconv.ParseUint(s, 10, 32) + return uint32(i), err + } + ct.valueType = valType + ct.keyType = "uint32" + return ct + case protoreflect.Uint64Kind, protoreflect.Fixed64Kind: + ct := new(compositeMapType[uint64]) + ct.keyValueResolver = func(s string) (uint64, error) { + i, err := strconv.ParseUint(s, 10, 64) + return i, err + } + ct.valueType = valType + ct.keyType = "uint64" + return ct + case protoreflect.BoolKind: + ct := new(compositeMapType[bool]) + ct.keyValueResolver = strconv.ParseBool + ct.valueType = valType + ct.keyType = "bool" + return ct + } + return nil + + } + return nil + } + + return typ +} + +func (b *Builder) resolveFlagTypeBasic(field protoreflect.FieldDescriptor) Type { + scalar, ok := GetScalarType(field) + if ok { + b.init() + if typ, ok := b.scalarFlagTypes[scalar]; ok { + return typ + } + } + + switch field.Kind() { + case protoreflect.BytesKind: + return binaryType{} + case protoreflect.EnumKind: + return enumType{enum: field.Enum()} + case protoreflect.MessageKind: + b.init() + if flagType, ok := b.messageFlagTypes[field.Message().FullName()]; ok { + return flagType + } + return jsonMessageFlagType{ + messageDesc: field.Message(), + } + default: + return nil + } +} + +// GetScalarType gets scalar type of a field. +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. +func GetSignerFieldName(descriptor protoreflect.MessageDescriptor) string { + signersFields := proto.GetExtension(descriptor.Options(), msgv1.E_Signer).([]string) + if len(signersFields) == 0 { + return "" + } + + return signersFields[0] +} diff --git a/connect/internal/autocli/flag/coin.go b/connect/internal/autocli/flag/coin.go new file mode 100644 index 00000000..28a6230a --- /dev/null +++ b/connect/internal/autocli/flag/coin.go @@ -0,0 +1,58 @@ +package flag + +import ( + "context" + "errors" + "strings" + + "google.golang.org/protobuf/reflect/protoreflect" + + basev1beta1 "cosmossdk.io/api/cosmos/base/v1beta1" + "github.com/ignite/apps/connect/internal/internal/coins" +) + +type coinType struct{} + +type coinValue struct { + value *basev1beta1.Coin +} + +func (c coinType) NewValue(*context.Context, *Builder) Value { + return &coinValue{} +} + +func (c coinType) DefaultValue() string { + return "zero" +} + +func (c *coinValue) Get(protoreflect.Value) (protoreflect.Value, error) { + if c.value == nil { + return protoreflect.Value{}, nil + } + return protoreflect.ValueOfMessage(c.value.ProtoReflect()), nil +} + +func (c *coinValue) String() string { + if c.value == nil { + return "" + } + + return c.value.String() +} + +func (c *coinValue) Set(stringValue string) error { + if strings.Contains(stringValue, ",") { + return errors.New("coin flag must be a single coin, specific multiple coins with multiple flags or spaces") + } + + coin, err := coins.ParseCoin(stringValue) + if err != nil { + return err + } + c.value = coin + return nil +} + +func (c *coinValue) Type() string { + return "cosmos.base.v1beta1.Coin" +} diff --git a/connect/internal/autocli/flag/dec_coin.go b/connect/internal/autocli/flag/dec_coin.go new file mode 100644 index 00000000..6672bad9 --- /dev/null +++ b/connect/internal/autocli/flag/dec_coin.go @@ -0,0 +1,58 @@ +package flag + +import ( + "context" + "errors" + "strings" + + "google.golang.org/protobuf/reflect/protoreflect" + + basev1beta1 "cosmossdk.io/api/cosmos/base/v1beta1" + "github.com/ignite/apps/connect/internal/internal/coins" +) + +type decCoinType struct{} + +type decCoinValue struct { + value *basev1beta1.DecCoin +} + +func (c decCoinType) NewValue(*context.Context, *Builder) Value { + return &decCoinValue{} +} + +func (c decCoinType) DefaultValue() string { + return "zero" +} + +func (c *decCoinValue) Get(protoreflect.Value) (protoreflect.Value, error) { + if c.value == nil { + return protoreflect.Value{}, nil + } + return protoreflect.ValueOfMessage(c.value.ProtoReflect()), nil +} + +func (c *decCoinValue) String() string { + if c.value == nil { + return "" + } + + return c.value.String() +} + +func (c *decCoinValue) Set(stringValue string) error { + if strings.Contains(stringValue, ",") { + return errors.New("coin flag must be a single coin, specific multiple coins with multiple flags or spaces") + } + + coin, err := coins.ParseDecCoin(stringValue) + if err != nil { + return err + } + c.value = coin + return nil +} + +func (c *decCoinValue) Type() string { + return "cosmos.base.v1beta1.DecCoin" +} diff --git a/connect/internal/autocli/flag/doc.go b/connect/internal/autocli/flag/doc.go new file mode 100644 index 00000000..5e8a1f36 --- /dev/null +++ b/connect/internal/autocli/flag/doc.go @@ -0,0 +1,4 @@ +// Package flag defines functionality for automatically managing command +// line flags as well positional arguments that are based on protobuf message +// fields. +package flag diff --git a/connect/internal/autocli/flag/duration.go b/connect/internal/autocli/flag/duration.go new file mode 100644 index 00000000..df02cba7 --- /dev/null +++ b/connect/internal/autocli/flag/duration.go @@ -0,0 +1,51 @@ +package flag + +import ( + "context" + "time" + + "google.golang.org/protobuf/reflect/protoreflect" + "google.golang.org/protobuf/types/known/durationpb" +) + +type durationType struct{} + +func (d durationType) NewValue(*context.Context, *Builder) Value { + return &durationValue{} +} + +func (d durationType) DefaultValue() string { + return "" +} + +type durationValue struct { + value *durationpb.Duration +} + +func (d durationValue) Get(protoreflect.Value) (protoreflect.Value, error) { + if d.value == nil { + return protoreflect.Value{}, nil + } + return protoreflect.ValueOfMessage(d.value.ProtoReflect()), nil +} + +func (d durationValue) String() string { + if d.value == nil { + return "" + } + return d.value.AsDuration().String() +} + +func (d *durationValue) Set(s string) error { + dur, err := time.ParseDuration(s) + if err != nil { + return err + } + + d.value = durationpb.New(dur) + return nil +} + +func (d durationValue) Type() string { + return "duration" +} diff --git a/connect/internal/autocli/flag/enum.go b/connect/internal/autocli/flag/enum.go new file mode 100644 index 00000000..0346b344 --- /dev/null +++ b/connect/internal/autocli/flag/enum.go @@ -0,0 +1,79 @@ +package flag + +import ( + "context" + "fmt" + "strings" + + "google.golang.org/protobuf/reflect/protoreflect" + + "github.com/ignite/apps/connect/internal/internal/strcase" +) + +type enumType struct { + enum protoreflect.EnumDescriptor +} + +func (b enumType) NewValue(*context.Context, *Builder) Value { + val := &enumValue{ + enum: b.enum, + valMap: map[string]protoreflect.EnumValueDescriptor{}, + } + n := b.enum.Values().Len() + for i := 0; i < n; i++ { + valDesc := b.enum.Values().Get(i) + val.valMap[enumValueName(b.enum, valDesc)] = valDesc + } + return val +} + +func (b enumType) DefaultValue() string { + defValue := "" + if def := b.enum.Values().ByNumber(0); def != nil { + defValue = enumValueName(b.enum, def) + } + return defValue +} + +type enumValue struct { + enum protoreflect.EnumDescriptor + value protoreflect.EnumNumber + valMap map[string]protoreflect.EnumValueDescriptor +} + +func (e enumValue) Get(protoreflect.Value) (protoreflect.Value, error) { + return protoreflect.ValueOfEnum(e.value), nil +} + +func enumValueName(enum protoreflect.EnumDescriptor, enumValue protoreflect.EnumValueDescriptor) string { + name := string(enumValue.Name()) + name = strings.TrimPrefix(name, strcase.ToScreamingSnake(string(enum.Name()))+"_") + return strcase.ToKebab(name) +} + +func (e enumValue) String() string { + return enumValueName(e.enum, e.enum.Values().ByNumber(e.value)) +} + +func (e *enumValue) Set(s string) error { + valDesc, ok := e.valMap[s] + if !ok { + var validValues []string + for k := range e.valMap { + validValues = append(validValues, k) + } + + return fmt.Errorf("%s is not a valid value for enum %s. Valid values are: %s", s, e.enum.FullName(), strings.Join(validValues, ", ")) + } + e.value = valDesc.Number() + return nil +} + +func (e enumValue) Type() string { + var vals []string + n := e.enum.Values().Len() + for i := 0; i < n; i++ { + vals = append(vals, enumValueName(e.enum, e.enum.Values().Get(i))) + } + return fmt.Sprintf("%s (%s)", e.enum.Name(), strings.Join(vals, " | ")) +} diff --git a/connect/internal/autocli/flag/interface.go b/connect/internal/autocli/flag/interface.go new file mode 100644 index 00000000..1d983c09 --- /dev/null +++ b/connect/internal/autocli/flag/interface.go @@ -0,0 +1,32 @@ +package flag + +import ( + "context" + + "github.com/spf13/pflag" + "google.golang.org/protobuf/reflect/protoreflect" +) + +// Type specifies a custom flag type. +type Type interface { + // NewValue returns a new pflag.Value which must also implement either SimpleValue or ListValue. + NewValue(*context.Context, *Builder) Value + + // DefaultValue is the default value for this type. + DefaultValue() string +} + +// Value represents a single pflag.Value value. +type Value interface { + pflag.Value + HasValue +} + +// HasValue wraps a reference to a protobuf value. +type HasValue interface { + // Get gets the value of the protobuf value reference and returns that value + // or an error. For composite protoreflect.Value types such as messages, + // lists and maps, a mutable reference to the value of field obtained with + // protoreflect.Message.NewField should be passed as the newFieldValue parameter. + Get(newFieldValue protoreflect.Value) (protoreflect.Value, error) +} diff --git a/connect/internal/autocli/flag/json_message.go b/connect/internal/autocli/flag/json_message.go new file mode 100644 index 00000000..7a2df5dd --- /dev/null +++ b/connect/internal/autocli/flag/json_message.go @@ -0,0 +1,86 @@ +package flag + +import ( + "context" + "fmt" + "io" + "os" + "regexp" + + "google.golang.org/protobuf/encoding/protojson" + "google.golang.org/protobuf/proto" + "google.golang.org/protobuf/reflect/protoreflect" + + "github.com/ignite/apps/connect/internal/internal/util" +) + +var isJSONFileRegex = regexp.MustCompile(`\.json$`) + +type jsonMessageFlagType struct { + messageDesc protoreflect.MessageDescriptor +} + +func (j jsonMessageFlagType) NewValue(_ *context.Context, builder *Builder) Value { + return &jsonMessageFlagValue{ + messageType: util.ResolveMessageType(builder.TypeResolver, j.messageDesc), + jsonMarshalOptions: protojson.MarshalOptions{Resolver: builder.TypeResolver}, + jsonUnmarshalOptions: protojson.UnmarshalOptions{Resolver: builder.TypeResolver}, + } +} + +func (j jsonMessageFlagType) DefaultValue() string { + return "" +} + +type jsonMessageFlagValue struct { + jsonMarshalOptions protojson.MarshalOptions + jsonUnmarshalOptions protojson.UnmarshalOptions + messageType protoreflect.MessageType + message proto.Message +} + +func (j *jsonMessageFlagValue) Get(protoreflect.Value) (protoreflect.Value, error) { + if j.message == nil { + return protoreflect.Value{}, nil + } + return protoreflect.ValueOfMessage(j.message.ProtoReflect()), nil +} + +func (j *jsonMessageFlagValue) String() string { + if j.message == nil { + return "" + } + + bz, err := j.jsonMarshalOptions.Marshal(j.message) + if err != nil { + return err.Error() + } + return string(bz) +} + +func (j *jsonMessageFlagValue) Set(s string) error { + j.message = j.messageType.New().Interface() + var messageBytes []byte + if isJSONFileRegex.MatchString(s) { + jsonFile, err := os.Open(s) + if err != nil { + return err + } + messageBytes, err = io.ReadAll(jsonFile) + if err != nil { + _ = jsonFile.Close() + return err + } + err = jsonFile.Close() + if err != nil { + return err + } + } else { + messageBytes = []byte(s) + } + return j.jsonUnmarshalOptions.Unmarshal(messageBytes, j.message) +} + +func (j *jsonMessageFlagValue) Type() string { + return fmt.Sprintf("%s (json)", j.messageType.Descriptor().FullName()) +} diff --git a/connect/internal/autocli/flag/legacy_dec.go b/connect/internal/autocli/flag/legacy_dec.go new file mode 100644 index 00000000..073afa94 --- /dev/null +++ b/connect/internal/autocli/flag/legacy_dec.go @@ -0,0 +1,48 @@ +package flag + +import ( + "context" + + "google.golang.org/protobuf/reflect/protoreflect" + + "cosmossdk.io/math" +) + +type decType struct{} + +func (a decType) NewValue(_ *context.Context, _ *Builder) Value { + return &decValue{} +} + +func (a decType) DefaultValue() string { + return "0" +} + +type decValue struct { + value string +} + +func (a decValue) Get(protoreflect.Value) (protoreflect.Value, error) { + return protoreflect.ValueOf(a.value), nil +} + +func (a decValue) String() string { + return a.value +} + +func (a *decValue) Set(s string) error { + dec, err := math.LegacyNewDecFromStr(s) + if err != nil { + return err + } + + // we need to convert from float representation to non-float representation using default precision + // 0.5 -> 500000000000000000 + a.value = dec.BigInt().String() + + return nil +} + +func (a decValue) Type() string { + return "cosmos.Dec" +} diff --git a/connect/internal/autocli/flag/list.go b/connect/internal/autocli/flag/list.go new file mode 100644 index 00000000..d30f2992 --- /dev/null +++ b/connect/internal/autocli/flag/list.go @@ -0,0 +1,107 @@ +package flag + +import ( + "context" + "fmt" + + "github.com/spf13/pflag" + "google.golang.org/protobuf/reflect/protoreflect" +) + +func bindSimpleListFlag(flagSet *pflag.FlagSet, kind protoreflect.Kind, name, shorthand, usage string) HasValue { + switch kind { + case protoreflect.StringKind: + val := flagSet.StringSliceP(name, shorthand, nil, usage) + return newListValue(val, protoreflect.ValueOfString) + case protoreflect.Uint32Kind, protoreflect.Fixed32Kind, + protoreflect.Uint64Kind, protoreflect.Fixed64Kind: + val := flagSet.UintSliceP(name, shorthand, nil, usage) + return newListValue(val, func(x uint) protoreflect.Value { return protoreflect.ValueOfUint64(uint64(x)) }) + case protoreflect.Int32Kind, protoreflect.Sint32Kind, protoreflect.Sfixed32Kind: + val := flagSet.Int32SliceP(name, shorthand, nil, usage) + return newListValue(val, protoreflect.ValueOfInt32) + case protoreflect.Int64Kind, protoreflect.Sint64Kind, protoreflect.Sfixed64Kind: + val := flagSet.Int64SliceP(name, shorthand, nil, usage) + return newListValue(val, protoreflect.ValueOfInt64) + case protoreflect.BoolKind: + val := flagSet.BoolSliceP(name, shorthand, nil, usage) + return newListValue(val, protoreflect.ValueOfBool) + default: + return nil + } +} + +type listValue[T any] struct { + array *[]T + toProtoreflectValue func(T) protoreflect.Value +} + +func newListValue[T any](array *[]T, toProtoreflectValue func(T) protoreflect.Value) listValue[T] { + return listValue[T]{array: array, toProtoreflectValue: toProtoreflectValue} +} + +func (v listValue[T]) Get(mutable protoreflect.Value) (protoreflect.Value, error) { + list := mutable.List() + for _, x := range *v.array { + list.Append(v.toProtoreflectValue(x)) + } + return mutable, nil +} + +type compositeListType struct { + simpleType Type +} + +func (t compositeListType) NewValue(ctx *context.Context, opts *Builder) Value { + return &compositeListValue{ + simpleType: t.simpleType, + values: nil, + ctx: ctx, + opts: opts, + } +} + +func (t compositeListType) DefaultValue() string { + return "" +} + +type compositeListValue struct { + simpleType Type + values []protoreflect.Value + ctx *context.Context + opts *Builder +} + +func (c *compositeListValue) Get(mutable protoreflect.Value) (protoreflect.Value, error) { + list := mutable.List() + for _, value := range c.values { + list.Append(value) + } + return mutable, nil +} + +func (c *compositeListValue) String() string { + if len(c.values) == 0 { + return "" + } + + return fmt.Sprintf("%+v", c.values) +} + +func (c *compositeListValue) Set(val string) error { + simpleVal := c.simpleType.NewValue(c.ctx, c.opts) + err := simpleVal.Set(val) + if err != nil { + return err + } + v, err := simpleVal.Get(protoreflect.Value{}) + if err != nil { + return err + } + c.values = append(c.values, v) + return nil +} + +func (c *compositeListValue) Type() string { + return fmt.Sprintf("%s (repeated)", c.simpleType.NewValue(c.ctx, c.opts).Type()) +} diff --git a/connect/internal/autocli/flag/map.go b/connect/internal/autocli/flag/map.go new file mode 100644 index 00000000..0c0e136f --- /dev/null +++ b/connect/internal/autocli/flag/map.go @@ -0,0 +1,254 @@ +package flag + +import ( + "context" + "errors" + "fmt" + "strings" + + "github.com/spf13/pflag" + "google.golang.org/protobuf/reflect/protoreflect" + + "github.com/ignite/apps/connect/internal/autocli/flag/maps" +) + +func bindSimpleMapFlag(flagSet *pflag.FlagSet, keyKind, valueKind protoreflect.Kind, name, shorthand, usage string) HasValue { + switch keyKind { + case protoreflect.StringKind: + switch valueKind { + case protoreflect.StringKind: + val := flagSet.StringToStringP(name, shorthand, nil, usage) + return newMapValue(val, protoreflect.ValueOfString) + case protoreflect.Int32Kind, protoreflect.Sint32Kind, protoreflect.Sfixed32Kind: + val := maps.StringToInt32P(flagSet, name, shorthand, nil, usage) + return newMapValue(val, protoreflect.ValueOfInt32) + case protoreflect.Int64Kind, protoreflect.Sint64Kind, protoreflect.Sfixed64Kind: + val := flagSet.StringToInt64P(name, shorthand, nil, usage) + return newMapValue(val, protoreflect.ValueOfInt64) + case protoreflect.Uint32Kind: + val := maps.StringToUint32P(flagSet, name, shorthand, nil, usage) + return newMapValue(val, protoreflect.ValueOfUint32) + case protoreflect.Uint64Kind: + val := maps.StringToUint64P(flagSet, name, shorthand, nil, usage) + return newMapValue(val, protoreflect.ValueOfUint64) + case protoreflect.BoolKind: + val := maps.StringToBoolP(flagSet, name, shorthand, nil, usage) + return newMapValue(val, protoreflect.ValueOfBool) + } + + case protoreflect.Int32Kind, protoreflect.Sint32Kind, protoreflect.Sfixed32Kind: + switch valueKind { + case protoreflect.StringKind: + val := maps.Int32ToStringP(flagSet, name, shorthand, nil, usage) + return newMapValue(val, protoreflect.ValueOfString) + case protoreflect.Int32Kind, protoreflect.Sint32Kind, protoreflect.Sfixed32Kind: + val := maps.Int32ToInt32P(flagSet, name, shorthand, nil, usage) + return newMapValue(val, protoreflect.ValueOfInt32) + case protoreflect.Int64Kind, protoreflect.Sint64Kind, protoreflect.Sfixed64Kind: + val := maps.Int32ToInt64P(flagSet, name, shorthand, nil, usage) + return newMapValue(val, protoreflect.ValueOfInt64) + case protoreflect.Uint32Kind: + val := maps.Int32ToUint32P(flagSet, name, shorthand, nil, usage) + return newMapValue(val, protoreflect.ValueOfUint32) + case protoreflect.Uint64Kind: + val := maps.Int32ToUint64P(flagSet, name, shorthand, nil, usage) + return newMapValue(val, protoreflect.ValueOfUint64) + case protoreflect.BoolKind: + val := maps.Int32ToBoolP(flagSet, name, shorthand, nil, usage) + return newMapValue(val, protoreflect.ValueOfBool) + } + + case protoreflect.Int64Kind, protoreflect.Sint64Kind, protoreflect.Sfixed64Kind: + switch valueKind { + case protoreflect.StringKind: + val := maps.Int64ToStringP(flagSet, name, shorthand, nil, usage) + return newMapValue(val, protoreflect.ValueOfString) + case protoreflect.Int32Kind, protoreflect.Sint32Kind, protoreflect.Sfixed32Kind: + val := maps.Int64ToInt32P(flagSet, name, shorthand, nil, usage) + return newMapValue(val, protoreflect.ValueOfInt32) + case protoreflect.Int64Kind, protoreflect.Sint64Kind, protoreflect.Sfixed64Kind: + val := maps.Int64ToInt64P(flagSet, name, shorthand, nil, usage) + return newMapValue(val, protoreflect.ValueOfInt64) + case protoreflect.Uint32Kind: + val := maps.Int64ToUint32P(flagSet, name, shorthand, nil, usage) + return newMapValue(val, protoreflect.ValueOfUint32) + case protoreflect.Uint64Kind: + val := maps.Int64ToUint64P(flagSet, name, shorthand, nil, usage) + return newMapValue(val, protoreflect.ValueOfUint64) + case protoreflect.BoolKind: + val := maps.Int64ToBoolP(flagSet, name, shorthand, nil, usage) + return newMapValue(val, protoreflect.ValueOfBool) + } + case protoreflect.Uint32Kind: + switch valueKind { + case protoreflect.StringKind: + val := maps.Uint32ToStringP(flagSet, name, shorthand, nil, usage) + return newMapValue(val, protoreflect.ValueOfString) + case protoreflect.Int32Kind, protoreflect.Sint32Kind, protoreflect.Sfixed32Kind: + val := maps.Uint32ToInt32P(flagSet, name, shorthand, nil, usage) + return newMapValue(val, protoreflect.ValueOfInt32) + case protoreflect.Int64Kind, protoreflect.Sint64Kind, protoreflect.Sfixed64Kind: + val := maps.Uint32ToInt64P(flagSet, name, shorthand, nil, usage) + return newMapValue(val, protoreflect.ValueOfInt64) + case protoreflect.Uint32Kind: + val := maps.Uint32ToUint32P(flagSet, name, shorthand, nil, usage) + return newMapValue(val, protoreflect.ValueOfUint32) + case protoreflect.Uint64Kind: + val := maps.Uint32ToUint64P(flagSet, name, shorthand, nil, usage) + return newMapValue(val, protoreflect.ValueOfUint64) + case protoreflect.BoolKind: + val := maps.Uint32ToBoolP(flagSet, name, shorthand, nil, usage) + return newMapValue(val, protoreflect.ValueOfBool) + } + case protoreflect.Uint64Kind: + switch valueKind { + case protoreflect.StringKind: + val := maps.Uint64ToStringP(flagSet, name, shorthand, nil, usage) + return newMapValue(val, protoreflect.ValueOfString) + case protoreflect.Int32Kind, protoreflect.Sint32Kind, protoreflect.Sfixed32Kind: + val := maps.Uint64ToInt32P(flagSet, name, shorthand, nil, usage) + return newMapValue(val, protoreflect.ValueOfInt32) + case protoreflect.Int64Kind, protoreflect.Sint64Kind, protoreflect.Sfixed64Kind: + val := maps.Uint64ToInt64P(flagSet, name, shorthand, nil, usage) + return newMapValue(val, protoreflect.ValueOfInt64) + case protoreflect.Uint32Kind: + val := maps.Uint64ToUint32P(flagSet, name, shorthand, nil, usage) + return newMapValue(val, protoreflect.ValueOfUint32) + case protoreflect.Uint64Kind: + val := maps.Uint64ToUint64P(flagSet, name, shorthand, nil, usage) + return newMapValue(val, protoreflect.ValueOfUint64) + case protoreflect.BoolKind: + val := maps.Uint64ToBoolP(flagSet, name, shorthand, nil, usage) + return newMapValue(val, protoreflect.ValueOfBool) + } + case protoreflect.BoolKind: + switch valueKind { + case protoreflect.StringKind: + val := maps.BoolToStringP(flagSet, name, shorthand, nil, usage) + return newMapValue(val, protoreflect.ValueOfString) + case protoreflect.Int32Kind, protoreflect.Sint32Kind, protoreflect.Sfixed32Kind: + val := maps.BoolToInt32P(flagSet, name, shorthand, nil, usage) + return newMapValue(val, protoreflect.ValueOfInt32) + case protoreflect.Int64Kind, protoreflect.Sint64Kind, protoreflect.Sfixed64Kind: + val := maps.BoolToInt64P(flagSet, name, shorthand, nil, usage) + return newMapValue(val, protoreflect.ValueOfInt64) + case protoreflect.Uint32Kind: + val := maps.BoolToUint32P(flagSet, name, shorthand, nil, usage) + return newMapValue(val, protoreflect.ValueOfUint32) + case protoreflect.Uint64Kind: + val := maps.BoolToUint64P(flagSet, name, shorthand, nil, usage) + return newMapValue(val, protoreflect.ValueOfUint64) + case protoreflect.BoolKind: + val := maps.BoolToBoolP(flagSet, name, shorthand, nil, usage) + return newMapValue(val, protoreflect.ValueOfBool) + } + + } + return nil +} + +type mapValue[K comparable, V any] struct { + value *map[K]V + toProtoreflectValue func(V) protoreflect.Value +} + +func newMapValue[K comparable, V any](mapV *map[K]V, toProtoreflectValue func(V) protoreflect.Value) mapValue[K, V] { + return mapValue[K, V]{value: mapV, toProtoreflectValue: toProtoreflectValue} +} + +func (v mapValue[K, V]) Get(mutable protoreflect.Value) (protoreflect.Value, error) { + protoMap := mutable.Map() + for k, val := range *v.value { + protoMap.Set(protoreflect.MapKey(protoreflect.ValueOf(k)), v.toProtoreflectValue(val)) + } + return mutable, nil +} + +// keyValueResolver is a function that converts a string to a key that is primitive Type T +type keyValueResolver[T comparable] func(string) (T, error) + +// compositeMapType is a map type that is composed of a key and value type that are both primitive types +type compositeMapType[T comparable] struct { + keyValueResolver keyValueResolver[T] + keyType string + valueType Type +} + +// compositeMapValue is a map value that is composed of a key and value type that are both primitive types +type compositeMapValue[T comparable] struct { + keyValueResolver keyValueResolver[T] + keyType string + valueType Type + values map[T]protoreflect.Value + ctx *context.Context + opts *Builder +} + +func (m compositeMapType[T]) DefaultValue() string { + return "" +} + +func (m compositeMapType[T]) NewValue(ctx *context.Context, opts *Builder) Value { + return &compositeMapValue[T]{ + keyValueResolver: m.keyValueResolver, + valueType: m.valueType, + keyType: m.keyType, + ctx: ctx, + opts: opts, + values: nil, + } +} + +func (m *compositeMapValue[T]) Set(s string) error { + comaArgs := strings.Split(s, ",") + for _, arg := range comaArgs { + parts := strings.SplitN(arg, "=", 2) + if len(parts) != 2 { + return errors.New("invalid format, expected key=value") + } + key, val := parts[0], parts[1] + + keyValue, err := m.keyValueResolver(key) + if err != nil { + return err + } + + simpleVal := m.valueType.NewValue(m.ctx, m.opts) + err = simpleVal.Set(val) + if err != nil { + return err + } + protoValue, err := simpleVal.Get(protoreflect.Value{}) + if err != nil { + return err + } + if m.values == nil { + m.values = make(map[T]protoreflect.Value) + } + + m.values[keyValue] = protoValue + } + + return nil +} + +func (m *compositeMapValue[T]) Get(mutable protoreflect.Value) (protoreflect.Value, error) { + protoMap := mutable.Map() + for key, value := range m.values { + keyVal := protoreflect.ValueOf(key) + protoMap.Set(keyVal.MapKey(), value) + } + return protoreflect.ValueOfMap(protoMap), nil +} + +func (m *compositeMapValue[T]) String() string { + if m.values == nil { + return "" + } + + return fmt.Sprintf("%+v", m.values) +} + +func (m *compositeMapValue[T]) Type() string { + return fmt.Sprintf("map[%s]%s", m.keyType, m.valueType.NewValue(m.ctx, m.opts).Type()) +} diff --git a/connect/internal/autocli/flag/maps/generic.go b/connect/internal/autocli/flag/maps/generic.go new file mode 100644 index 00000000..1a734faf --- /dev/null +++ b/connect/internal/autocli/flag/maps/generic.go @@ -0,0 +1,61 @@ +package maps + +import ( + "fmt" + "strings" +) + +type genericMapValueOptions[K comparable, V any] struct { + keyParser func(string) (K, error) + valueParser func(string) (V, error) + genericType string +} + +type genericMapValue[K comparable, V any] struct { + value *map[K]V + changed bool + Options genericMapValueOptions[K, V] +} + +func newGenericMapValue[K comparable, V any](val map[K]V, p *map[K]V) *genericMapValue[K, V] { + ssv := new(genericMapValue[K, V]) + ssv.value = p + *ssv.value = val + return ssv +} + +func (gm *genericMapValue[K, V]) Set(val string) error { + ss := strings.Split(val, ",") + out := make(map[K]V, len(ss)) + for _, pair := range ss { + kv := strings.SplitN(pair, "=", 2) + if len(kv) != 2 { + return fmt.Errorf("%s must be formatted as key=value", pair) + } + key, err := gm.Options.keyParser(kv[0]) + if err != nil { + return err + } + out[key], err = gm.Options.valueParser(kv[1]) + if err != nil { + return err + } + } + if !gm.changed { + *gm.value = out + } else { + for k, v := range out { + (*gm.value)[k] = v + } + } + gm.changed = true + return nil +} + +func (gm *genericMapValue[K, V]) Type() string { + return gm.Options.genericType +} + +func (gm *genericMapValue[K, V]) String() string { + return "" +} diff --git a/connect/internal/autocli/flag/maps/map_bool_to_value.go b/connect/internal/autocli/flag/maps/map_bool_to_value.go new file mode 100644 index 00000000..aae8a7d6 --- /dev/null +++ b/connect/internal/autocli/flag/maps/map_bool_to_value.go @@ -0,0 +1,138 @@ +package maps + +import ( + "strconv" + + "github.com/spf13/pflag" +) + +func newBoolToString[K bool, V string](val map[K]V, p *map[K]V) *genericMapValue[K, V] { + newBoolStringMap := newGenericMapValue(val, p) + newBoolStringMap.Options = genericMapValueOptions[K, V]{ + genericType: "boolToString", + keyParser: func(s string) (K, error) { + value, err := strconv.ParseBool(s) + return K(value), err + }, + valueParser: func(s string) (V, error) { + return V(s), nil + }, + } + return newBoolStringMap +} + +func BoolToStringP(flagSet *pflag.FlagSet, name, shorthand string, value map[bool]string, usage string) *map[bool]string { + p := make(map[bool]string) + flagSet.VarP(newBoolToString(value, &p), name, shorthand, usage) + return &p +} + +func newBoolToInt32[K bool, V int32](val map[K]V, p *map[K]V) *genericMapValue[K, V] { + newBoolInt32Map := newGenericMapValue(val, p) + newBoolInt32Map.Options = genericMapValueOptions[K, V]{ + genericType: "boolToInt32", + keyParser: func(s string) (K, error) { + value, err := strconv.ParseBool(s) + return K(value), err + }, + valueParser: func(s string) (V, error) { + value, err := strconv.ParseInt(s, 10, 32) + return V(value), err + }, + } + return newBoolInt32Map +} + +func BoolToInt32P(flagSet *pflag.FlagSet, name, shorthand string, value map[bool]int32, usage string) *map[bool]int32 { + p := make(map[bool]int32) + flagSet.VarP(newBoolToInt32(value, &p), name, shorthand, usage) + return &p +} + +func newBoolToInt64[K bool, V int64](val map[K]V, p *map[K]V) *genericMapValue[K, V] { + newBoolInt64Map := newGenericMapValue(val, p) + newBoolInt64Map.Options = genericMapValueOptions[K, V]{ + genericType: "boolToInt64", + keyParser: func(s string) (K, error) { + value, err := strconv.ParseBool(s) + return K(value), err + }, + valueParser: func(s string) (V, error) { + value, err := strconv.ParseInt(s, 10, 64) + return V(value), err + }, + } + return newBoolInt64Map +} + +func BoolToInt64P(flagSet *pflag.FlagSet, name, shorthand string, value map[bool]int64, usage string) *map[bool]int64 { + p := make(map[bool]int64) + flagSet.VarP(newBoolToInt64(value, &p), name, shorthand, usage) + return &p +} + +func newBoolToUint32[K bool, V uint32](val map[K]V, p *map[K]V) *genericMapValue[K, V] { + newBoolUint32Map := newGenericMapValue(val, p) + newBoolUint32Map.Options = genericMapValueOptions[K, V]{ + genericType: "boolToUint32", + keyParser: func(s string) (K, error) { + value, err := strconv.ParseBool(s) + return K(value), err + }, + valueParser: func(s string) (V, error) { + value, err := strconv.ParseUint(s, 10, 32) + return V(value), err + }, + } + return newBoolUint32Map +} + +func BoolToUint32P(flagSet *pflag.FlagSet, name, shorthand string, value map[bool]uint32, usage string) *map[bool]uint32 { + p := make(map[bool]uint32) + flagSet.VarP(newBoolToUint32(value, &p), name, shorthand, usage) + return &p +} + +func newBoolToUint64[K bool, V uint64](val map[K]V, p *map[K]V) *genericMapValue[K, V] { + newBoolUint64Map := newGenericMapValue(val, p) + newBoolUint64Map.Options = genericMapValueOptions[K, V]{ + genericType: "boolToUint64", + keyParser: func(s string) (K, error) { + value, err := strconv.ParseBool(s) + return K(value), err + }, + valueParser: func(s string) (V, error) { + value, err := strconv.ParseUint(s, 10, 64) + return V(value), err + }, + } + return newBoolUint64Map +} + +func BoolToUint64P(flagSet *pflag.FlagSet, name, shorthand string, value map[bool]uint64, usage string) *map[bool]uint64 { + p := make(map[bool]uint64) + flagSet.VarP(newBoolToUint64(value, &p), name, shorthand, usage) + return &p +} + +func newBoolToBool[K, V bool](val map[K]V, p *map[K]V) *genericMapValue[K, V] { + newBoolBoolMap := newGenericMapValue(val, p) + newBoolBoolMap.Options = genericMapValueOptions[K, V]{ + genericType: "boolToBool", + keyParser: func(s string) (K, error) { + value, err := strconv.ParseBool(s) + return K(value), err + }, + valueParser: func(s string) (V, error) { + value, err := strconv.ParseBool(s) + return V(value), err + }, + } + return newBoolBoolMap +} + +func BoolToBoolP(flagSet *pflag.FlagSet, name, shorthand string, value map[bool]bool, usage string) *map[bool]bool { + p := make(map[bool]bool) + flagSet.VarP(newBoolToBool(value, &p), name, shorthand, usage) + return &p +} diff --git a/connect/internal/autocli/flag/maps/map_int32_to_value.go b/connect/internal/autocli/flag/maps/map_int32_to_value.go new file mode 100644 index 00000000..c10adf73 --- /dev/null +++ b/connect/internal/autocli/flag/maps/map_int32_to_value.go @@ -0,0 +1,159 @@ +package maps + +import ( + "strconv" + + "github.com/spf13/pflag" +) + +func newInt32ToString[K int32, V string](val map[K]V, p *map[K]V) *genericMapValue[K, V] { + newInt32StringMap := newGenericMapValue(val, p) + newInt32StringMap.Options = genericMapValueOptions[K, V]{ + genericType: "int32ToString", + keyParser: func(s string) (K, error) { + value, err := strconv.ParseInt(s, 10, 32) + return K(value), err + }, + valueParser: func(s string) (V, error) { + return V(s), nil + }, + } + return newInt32StringMap +} + +func Int32ToStringP(flagSet *pflag.FlagSet, name, shorthand string, value map[int32]string, usage string) *map[int32]string { + p := make(map[int32]string) + flagSet.VarP(newInt32ToString(value, &p), name, shorthand, usage) + return &p +} + +func newInt32ToInt32[K, V int32](val map[K]V, p *map[K]V) *genericMapValue[K, V] { + newInt32Int32Map := newGenericMapValue(val, p) + newInt32Int32Map.Options = genericMapValueOptions[K, V]{ + genericType: "int32ToInt32", + keyParser: func(s string) (K, error) { + value, err := strconv.ParseInt(s, 10, 32) + return K(value), err + }, + valueParser: func(s string) (V, error) { + value, err := strconv.ParseInt(s, 10, 32) + return V(value), err + }, + } + return newInt32Int32Map +} + +func Int32ToInt32P(flagSet *pflag.FlagSet, name, shorthand string, value map[int32]int32, usage string) *map[int32]int32 { + p := make(map[int32]int32) + flagSet.VarP(newInt32ToInt32(value, &p), name, shorthand, usage) + return &p +} + +func newInt32ToInt64[K int32, V int64](val map[K]V, p *map[K]V) *genericMapValue[K, V] { + newInt32Int64Map := newGenericMapValue(val, p) + newInt32Int64Map.Options = genericMapValueOptions[K, V]{ + genericType: "int32ToInt64", + keyParser: func(s string) (K, error) { + value, err := strconv.ParseInt(s, 10, 32) + return K(value), err + }, + valueParser: func(s string) (V, error) { + value, err := strconv.ParseInt(s, 10, 64) + return V(value), err + }, + } + return newInt32Int64Map +} + +func Int32ToInt64P(flagSet *pflag.FlagSet, name, shorthand string, value map[int32]int64, usage string) *map[int32]int64 { + p := make(map[int32]int64) + flagSet.VarP(newInt32ToInt64(value, &p), name, shorthand, usage) + return &p +} + +func newInt32ToUint32[K int32, V uint32](val map[K]V, p *map[K]V) *genericMapValue[K, V] { + newInt32Uint32Map := newGenericMapValue(val, p) + newInt32Uint32Map.Options = genericMapValueOptions[K, V]{ + genericType: "int32ToUint32", + keyParser: func(s string) (K, error) { + value, err := strconv.ParseInt(s, 10, 32) + return K(value), err + }, + valueParser: func(s string) (V, error) { + value, err := strconv.ParseUint(s, 10, 32) + return V(value), err + }, + } + return newInt32Uint32Map +} + +func Int32ToUint32P(flagSet *pflag.FlagSet, name, shorthand string, value map[int32]uint32, usage string) *map[int32]uint32 { + p := make(map[int32]uint32) + flagSet.VarP(newInt32ToUint32(value, &p), name, shorthand, usage) + return &p +} + +func newInt32ToUint64[K int32, V uint64](val map[K]V, p *map[K]V) *genericMapValue[K, V] { + newInt32Uint64Map := newGenericMapValue(val, p) + newInt32Uint64Map.Options = genericMapValueOptions[K, V]{ + genericType: "int32ToUint64", + keyParser: func(s string) (K, error) { + value, err := strconv.ParseInt(s, 10, 32) + return K(value), err + }, + valueParser: func(s string) (V, error) { + value, err := strconv.ParseUint(s, 10, 64) + return V(value), err + }, + } + return newInt32Uint64Map +} + +func Int32ToUint64P(flagSet *pflag.FlagSet, name, shorthand string, value map[int32]uint64, usage string) *map[int32]uint64 { + p := make(map[int32]uint64) + flagSet.VarP(newInt32ToUint64(value, &p), name, shorthand, usage) + return &p +} + +func newInt32ToBool[K int32, V bool](val map[K]V, p *map[K]V) *genericMapValue[K, V] { + newInt32BoolMap := newGenericMapValue(val, p) + newInt32BoolMap.Options = genericMapValueOptions[K, V]{ + genericType: "int32ToBool", + keyParser: func(s string) (K, error) { + value, err := strconv.ParseInt(s, 10, 32) + return K(value), err + }, + valueParser: func(s string) (V, error) { + value, err := strconv.ParseBool(s) + return V(value), err + }, + } + return newInt32BoolMap +} + +func Int32ToBoolP(flagSet *pflag.FlagSet, name, shorthand string, value map[int32]bool, usage string) *map[int32]bool { + p := make(map[int32]bool) + flagSet.VarP(newInt32ToBool(value, &p), name, shorthand, usage) + return &p +} + +func newStringToBool[K string, V bool](val map[K]V, p *map[K]V) *genericMapValue[K, V] { + newStringBoolMap := newGenericMapValue(val, p) + newStringBoolMap.Options = genericMapValueOptions[K, V]{ + genericType: "stringToBool", + keyParser: func(s string) (K, error) { + return K(s), nil + }, + valueParser: func(s string) (V, error) { + value, err := strconv.ParseBool(s) + return V(value), err + }, + } + return newStringBoolMap +} + +func StringToBoolP(flagSet *pflag.FlagSet, name, shorthand string, value map[string]bool, usage string) *map[string]bool { + p := make(map[string]bool) + flagSet.VarP(newStringToBool(value, &p), name, shorthand, usage) + return &p +} diff --git a/connect/internal/autocli/flag/maps/map_int64_to_value.go b/connect/internal/autocli/flag/maps/map_int64_to_value.go new file mode 100644 index 00000000..9d85ef96 --- /dev/null +++ b/connect/internal/autocli/flag/maps/map_int64_to_value.go @@ -0,0 +1,180 @@ +package maps + +import ( + "strconv" + + "github.com/spf13/pflag" +) + +func newInt64ToString[K int64, V string](val map[K]V, p *map[K]V) *genericMapValue[K, V] { + newInt64StringMap := newGenericMapValue(val, p) + newInt64StringMap.Options = genericMapValueOptions[K, V]{ + genericType: "int64ToString", + keyParser: func(s string) (K, error) { + value, err := strconv.ParseInt(s, 10, 64) + return K(value), err + }, + valueParser: func(s string) (V, error) { + return V(s), nil + }, + } + return newInt64StringMap +} + +func Int64ToStringP(flagSet *pflag.FlagSet, name, shorthand string, value map[int64]string, usage string) *map[int64]string { + p := make(map[int64]string) + flagSet.VarP(newInt64ToString(value, &p), name, shorthand, usage) + return &p +} + +func newInt64ToInt32[K int64, V int32](val map[K]V, p *map[K]V) *genericMapValue[K, V] { + newInt64Int32Map := newGenericMapValue(val, p) + newInt64Int32Map.Options = genericMapValueOptions[K, V]{ + genericType: "int64ToInt32", + keyParser: func(s string) (K, error) { + value, err := strconv.ParseInt(s, 10, 64) + return K(value), err + }, + valueParser: func(s string) (V, error) { + value, err := strconv.ParseInt(s, 10, 32) + return V(value), err + }, + } + return newInt64Int32Map +} + +func Int64ToInt32P(flagSet *pflag.FlagSet, name, shorthand string, value map[int64]int32, usage string) *map[int64]int32 { + p := make(map[int64]int32) + flagSet.VarP(newInt64ToInt32(value, &p), name, shorthand, usage) + return &p +} + +func newInt64ToInt64[K, V int64](val map[K]V, p *map[K]V) *genericMapValue[K, V] { + newInt64Int64Map := newGenericMapValue(val, p) + newInt64Int64Map.Options = genericMapValueOptions[K, V]{ + genericType: "int64ToInt64", + keyParser: func(s string) (K, error) { + value, err := strconv.ParseInt(s, 10, 64) + return K(value), err + }, + valueParser: func(s string) (V, error) { + value, err := strconv.ParseInt(s, 10, 64) + return V(value), err + }, + } + return newInt64Int64Map +} + +func Int64ToInt64P(flagSet *pflag.FlagSet, name, shorthand string, value map[int64]int64, usage string) *map[int64]int64 { + p := make(map[int64]int64) + flagSet.VarP(newInt64ToInt64(value, &p), name, shorthand, usage) + return &p +} + +func newInt64ToUint32[K int64, V uint32](val map[K]V, p *map[K]V) *genericMapValue[K, V] { + newInt64Uint32Map := newGenericMapValue(val, p) + newInt64Uint32Map.Options = genericMapValueOptions[K, V]{ + genericType: "int64ToUint32", + keyParser: func(s string) (K, error) { + value, err := strconv.ParseInt(s, 10, 64) + return K(value), err + }, + valueParser: func(s string) (V, error) { + value, err := strconv.ParseUint(s, 10, 32) + return V(value), err + }, + } + return newInt64Uint32Map +} + +func Int64ToUint32P(flagSet *pflag.FlagSet, name, shorthand string, value map[int64]uint32, usage string) *map[int64]uint32 { + p := make(map[int64]uint32) + flagSet.VarP(newInt64ToUint32(value, &p), name, shorthand, usage) + return &p +} + +func newInt64ToUint64[K int64, V uint64](val map[K]V, p *map[K]V) *genericMapValue[K, V] { + newInt64Uint64Map := newGenericMapValue(val, p) + newInt64Uint64Map.Options = genericMapValueOptions[K, V]{ + genericType: "int64ToUint64", + keyParser: func(s string) (K, error) { + value, err := strconv.ParseInt(s, 10, 64) + return K(value), err + }, + valueParser: func(s string) (V, error) { + value, err := strconv.ParseUint(s, 10, 64) + return V(value), err + }, + } + return newInt64Uint64Map +} + +func Int64ToUint64P(flagSet *pflag.FlagSet, name, shorthand string, value map[int64]uint64, usage string) *map[int64]uint64 { + p := make(map[int64]uint64) + flagSet.VarP(newInt64ToUint64(value, &p), name, shorthand, usage) + return &p +} + +func newInt64ToBool[K int64, V bool](val map[K]V, p *map[K]V) *genericMapValue[K, V] { + newInt64BoolMap := newGenericMapValue(val, p) + newInt64BoolMap.Options = genericMapValueOptions[K, V]{ + genericType: "int64ToBool", + keyParser: func(s string) (K, error) { + value, err := strconv.ParseInt(s, 10, 64) + return K(value), err + }, + valueParser: func(s string) (V, error) { + value, err := strconv.ParseBool(s) + return V(value), err + }, + } + return newInt64BoolMap +} + +func Int64ToBoolP(flagSet *pflag.FlagSet, name, shorthand string, value map[int64]bool, usage string) *map[int64]bool { + p := make(map[int64]bool) + flagSet.VarP(newInt64ToBool(value, &p), name, shorthand, usage) + return &p +} + +func newStringToUint32[K string, V uint32](val map[K]V, p *map[K]V) *genericMapValue[K, V] { + newStringUintMap := newGenericMapValue(val, p) + newStringUintMap.Options = genericMapValueOptions[K, V]{ + genericType: "stringToUint32", + keyParser: func(s string) (K, error) { + return K(s), nil + }, + valueParser: func(s string) (V, error) { + value, err := strconv.ParseUint(s, 10, 32) + return V(value), err + }, + } + return newStringUintMap +} + +func StringToUint32P(flagSet *pflag.FlagSet, name, shorthand string, value map[string]uint32, usage string) *map[string]uint32 { + p := make(map[string]uint32) + flagSet.VarP(newStringToUint32(value, &p), name, shorthand, usage) + return &p +} + +func newStringToUint64[K string, V uint64](val map[K]V, p *map[K]V) *genericMapValue[K, V] { + newStringUint64Map := newGenericMapValue(val, p) + newStringUint64Map.Options = genericMapValueOptions[K, V]{ + genericType: "stringToUint64", + keyParser: func(s string) (K, error) { + return K(s), nil + }, + valueParser: func(s string) (V, error) { + value, err := strconv.ParseUint(s, 10, 64) + return V(value), err + }, + } + return newStringUint64Map +} + +func StringToUint64P(flagSet *pflag.FlagSet, name, shorthand string, value map[string]uint64, usage string) *map[string]uint64 { + p := make(map[string]uint64) + flagSet.VarP(newStringToUint64(value, &p), name, shorthand, usage) + return &p +} diff --git a/connect/internal/autocli/flag/maps/map_string_to_value.go b/connect/internal/autocli/flag/maps/map_string_to_value.go new file mode 100644 index 00000000..aff2fd94 --- /dev/null +++ b/connect/internal/autocli/flag/maps/map_string_to_value.go @@ -0,0 +1,28 @@ +package maps + +import ( + "strconv" + + "github.com/spf13/pflag" +) + +func newStringToInt32[K string, V int32](val map[K]V, p *map[K]V) *genericMapValue[K, V] { + newStringIntMap := newGenericMapValue(val, p) + newStringIntMap.Options = genericMapValueOptions[K, V]{ + genericType: "stringToInt32", + keyParser: func(s string) (K, error) { + return K(s), nil + }, + valueParser: func(s string) (V, error) { + value, err := strconv.ParseInt(s, 10, 32) + return V(value), err + }, + } + return newStringIntMap +} + +func StringToInt32P(flagSet *pflag.FlagSet, name, shorthand string, value map[string]int32, usage string) *map[string]int32 { + p := make(map[string]int32) + flagSet.VarP(newStringToInt32(value, &p), name, shorthand, usage) + return &p +} diff --git a/connect/internal/autocli/flag/maps/map_uint32_to_value.go b/connect/internal/autocli/flag/maps/map_uint32_to_value.go new file mode 100644 index 00000000..c346cd33 --- /dev/null +++ b/connect/internal/autocli/flag/maps/map_uint32_to_value.go @@ -0,0 +1,138 @@ +package maps + +import ( + "strconv" + + "github.com/spf13/pflag" +) + +func newUint32ToString[K uint32, V string](val map[K]V, p *map[K]V) *genericMapValue[K, V] { + newUint32StringMap := newGenericMapValue(val, p) + newUint32StringMap.Options = genericMapValueOptions[K, V]{ + genericType: "uint32ToString", + keyParser: func(s string) (K, error) { + value, err := strconv.ParseUint(s, 10, 32) + return K(value), err + }, + valueParser: func(s string) (V, error) { + return V(s), nil + }, + } + return newUint32StringMap +} + +func Uint32ToStringP(flagSet *pflag.FlagSet, name, shorthand string, value map[uint32]string, usage string) *map[uint32]string { + p := make(map[uint32]string) + flagSet.VarP(newUint32ToString(value, &p), name, shorthand, usage) + return &p +} + +func newUint32ToInt32[K uint32, V int32](val map[K]V, p *map[K]V) *genericMapValue[K, V] { + newUint32Int32Map := newGenericMapValue(val, p) + newUint32Int32Map.Options = genericMapValueOptions[K, V]{ + genericType: "uint32ToInt32", + keyParser: func(s string) (K, error) { + value, err := strconv.ParseUint(s, 10, 32) + return K(value), err + }, + valueParser: func(s string) (V, error) { + value, err := strconv.ParseInt(s, 10, 32) + return V(value), err + }, + } + return newUint32Int32Map +} + +func Uint32ToInt32P(flagSet *pflag.FlagSet, name, shorthand string, value map[uint32]int32, usage string) *map[uint32]int32 { + p := make(map[uint32]int32) + flagSet.VarP(newUint32ToInt32(value, &p), name, shorthand, usage) + return &p +} + +func newUint32ToInt64[K uint32, V int64](val map[K]V, p *map[K]V) *genericMapValue[K, V] { + newUint32Int64Map := newGenericMapValue(val, p) + newUint32Int64Map.Options = genericMapValueOptions[K, V]{ + genericType: "uint32ToInt64", + keyParser: func(s string) (K, error) { + value, err := strconv.ParseUint(s, 10, 32) + return K(value), err + }, + valueParser: func(s string) (V, error) { + value, err := strconv.ParseInt(s, 10, 64) + return V(value), err + }, + } + return newUint32Int64Map +} + +func Uint32ToInt64P(flagSet *pflag.FlagSet, name, shorthand string, value map[uint32]int64, usage string) *map[uint32]int64 { + p := make(map[uint32]int64) + flagSet.VarP(newUint32ToInt64(value, &p), name, shorthand, usage) + return &p +} + +func newUint32ToUint32[K, V uint32](val map[K]V, p *map[K]V) *genericMapValue[K, V] { + newUint32Uint32Map := newGenericMapValue(val, p) + newUint32Uint32Map.Options = genericMapValueOptions[K, V]{ + genericType: "uint32ToUint32", + keyParser: func(s string) (K, error) { + value, err := strconv.ParseUint(s, 10, 32) + return K(value), err + }, + valueParser: func(s string) (V, error) { + value, err := strconv.ParseUint(s, 10, 32) + return V(value), err + }, + } + return newUint32Uint32Map +} + +func Uint32ToUint32P(flagSet *pflag.FlagSet, name, shorthand string, value map[uint32]uint32, usage string) *map[uint32]uint32 { + p := make(map[uint32]uint32) + flagSet.VarP(newUint32ToUint32(value, &p), name, shorthand, usage) + return &p +} + +func newUint32ToUint64[K uint32, V uint64](val map[K]V, p *map[K]V) *genericMapValue[K, V] { + newUint32Uint64Map := newGenericMapValue(val, p) + newUint32Uint64Map.Options = genericMapValueOptions[K, V]{ + genericType: "uint32ToUint64", + keyParser: func(s string) (K, error) { + value, err := strconv.ParseUint(s, 10, 32) + return K(value), err + }, + valueParser: func(s string) (V, error) { + value, err := strconv.ParseUint(s, 10, 64) + return V(value), err + }, + } + return newUint32Uint64Map +} + +func Uint32ToUint64P(flagSet *pflag.FlagSet, name, shorthand string, value map[uint32]uint64, usage string) *map[uint32]uint64 { + p := make(map[uint32]uint64) + flagSet.VarP(newUint32ToUint64(value, &p), name, shorthand, usage) + return &p +} + +func newUint32ToBool[K uint32, V bool](val map[K]V, p *map[K]V) *genericMapValue[K, V] { + newUint32BoolMap := newGenericMapValue(val, p) + newUint32BoolMap.Options = genericMapValueOptions[K, V]{ + genericType: "uint32ToBool", + keyParser: func(s string) (K, error) { + value, err := strconv.ParseUint(s, 10, 32) + return K(value), err + }, + valueParser: func(s string) (V, error) { + value, err := strconv.ParseBool(s) + return V(value), err + }, + } + return newUint32BoolMap +} + +func Uint32ToBoolP(flagSet *pflag.FlagSet, name, shorthand string, value map[uint32]bool, usage string) *map[uint32]bool { + p := make(map[uint32]bool) + flagSet.VarP(newUint32ToBool(value, &p), name, shorthand, usage) + return &p +} diff --git a/connect/internal/autocli/flag/maps/map_uint64_to_value.go b/connect/internal/autocli/flag/maps/map_uint64_to_value.go new file mode 100644 index 00000000..e5e4318b --- /dev/null +++ b/connect/internal/autocli/flag/maps/map_uint64_to_value.go @@ -0,0 +1,138 @@ +package maps + +import ( + "strconv" + + "github.com/spf13/pflag" +) + +func newUint64ToString[K uint64, V string](val map[K]V, p *map[K]V) *genericMapValue[K, V] { + newUint64StringMap := newGenericMapValue(val, p) + newUint64StringMap.Options = genericMapValueOptions[K, V]{ + genericType: "uint64ToString", + keyParser: func(s string) (K, error) { + value, err := strconv.ParseUint(s, 10, 64) + return K(value), err + }, + valueParser: func(s string) (V, error) { + return V(s), nil + }, + } + return newUint64StringMap +} + +func Uint64ToStringP(flagSet *pflag.FlagSet, name, shorthand string, value map[uint64]string, usage string) *map[uint64]string { + p := make(map[uint64]string) + flagSet.VarP(newUint64ToString(value, &p), name, shorthand, usage) + return &p +} + +func newUint64ToInt32[K uint64, V int32](val map[K]V, p *map[K]V) *genericMapValue[K, V] { + newUint64Int32Map := newGenericMapValue(val, p) + newUint64Int32Map.Options = genericMapValueOptions[K, V]{ + genericType: "uint64ToInt32", + keyParser: func(s string) (K, error) { + value, err := strconv.ParseUint(s, 10, 64) + return K(value), err + }, + valueParser: func(s string) (V, error) { + value, err := strconv.ParseInt(s, 10, 32) + return V(value), err + }, + } + return newUint64Int32Map +} + +func Uint64ToInt32P(flagSet *pflag.FlagSet, name, shorthand string, value map[uint64]int32, usage string) *map[uint64]int32 { + p := make(map[uint64]int32) + flagSet.VarP(newUint64ToInt32(value, &p), name, shorthand, usage) + return &p +} + +func newUint64ToInt64[K uint64, V int64](val map[K]V, p *map[K]V) *genericMapValue[K, V] { + newUint64Int64Map := newGenericMapValue(val, p) + newUint64Int64Map.Options = genericMapValueOptions[K, V]{ + genericType: "uint64ToInt64", + keyParser: func(s string) (K, error) { + value, err := strconv.ParseUint(s, 10, 64) + return K(value), err + }, + valueParser: func(s string) (V, error) { + value, err := strconv.ParseInt(s, 10, 64) + return V(value), err + }, + } + return newUint64Int64Map +} + +func Uint64ToInt64P(flagSet *pflag.FlagSet, name, shorthand string, value map[uint64]int64, usage string) *map[uint64]int64 { + p := make(map[uint64]int64) + flagSet.VarP(newUint64ToInt64(value, &p), name, shorthand, usage) + return &p +} + +func newUint64ToUint32[K uint64, V uint32](val map[K]V, p *map[K]V) *genericMapValue[K, V] { + newUint64Uint32Map := newGenericMapValue(val, p) + newUint64Uint32Map.Options = genericMapValueOptions[K, V]{ + genericType: "uint64ToUint32", + keyParser: func(s string) (K, error) { + value, err := strconv.ParseUint(s, 10, 64) + return K(value), err + }, + valueParser: func(s string) (V, error) { + value, err := strconv.ParseUint(s, 10, 32) + return V(value), err + }, + } + return newUint64Uint32Map +} + +func Uint64ToUint32P(flagSet *pflag.FlagSet, name, shorthand string, value map[uint64]uint32, usage string) *map[uint64]uint32 { + p := make(map[uint64]uint32) + flagSet.VarP(newUint64ToUint32(value, &p), name, shorthand, usage) + return &p +} + +func newUint64ToUint64[K, V uint64](val map[K]V, p *map[K]V) *genericMapValue[K, V] { + newUint64Uint64Map := newGenericMapValue(val, p) + newUint64Uint64Map.Options = genericMapValueOptions[K, V]{ + genericType: "uint64ToUint64", + keyParser: func(s string) (K, error) { + value, err := strconv.ParseUint(s, 10, 64) + return K(value), err + }, + valueParser: func(s string) (V, error) { + value, err := strconv.ParseUint(s, 10, 64) + return V(value), err + }, + } + return newUint64Uint64Map +} + +func Uint64ToUint64P(flagSet *pflag.FlagSet, name, shorthand string, value map[uint64]uint64, usage string) *map[uint64]uint64 { + p := make(map[uint64]uint64) + flagSet.VarP(newUint64ToUint64(value, &p), name, shorthand, usage) + return &p +} + +func newUint64ToBool[K uint64, V bool](val map[K]V, p *map[K]V) *genericMapValue[K, V] { + newUint64BoolMap := newGenericMapValue(val, p) + newUint64BoolMap.Options = genericMapValueOptions[K, V]{ + genericType: "uint64ToBool", + keyParser: func(s string) (K, error) { + value, err := strconv.ParseUint(s, 10, 64) + return K(value), err + }, + valueParser: func(s string) (V, error) { + value, err := strconv.ParseBool(s) + return V(value), err + }, + } + return newUint64BoolMap +} + +func Uint64ToBoolP(flagSet *pflag.FlagSet, name, shorthand string, value map[uint64]bool, usage string) *map[uint64]bool { + p := make(map[uint64]bool) + flagSet.VarP(newUint64ToBool(value, &p), name, shorthand, usage) + return &p +} diff --git a/connect/internal/autocli/flag/messager_binder.go b/connect/internal/autocli/flag/messager_binder.go new file mode 100644 index 00000000..08a270e7 --- /dev/null +++ b/connect/internal/autocli/flag/messager_binder.go @@ -0,0 +1,155 @@ +package flag + +import ( + "fmt" + "strings" + + "github.com/spf13/cobra" + "github.com/spf13/pflag" + "google.golang.org/protobuf/reflect/protoreflect" +) + +// SignerInfo contains information about the signer field. +// That field is special because it needs to be known for signing. +// This struct keeps track of the field name and whether it is a flag. +// IsFlag and PositionalArgIndex are mutually exclusive. +type SignerInfo struct { + PositionalArgIndex int + IsFlag bool + + FieldName string + FlagName string // flag name (always set if IsFlag is true) +} + +// MessageBinder binds multiple flags in a flag set to a protobuf message. +type MessageBinder struct { + CobraArgs cobra.PositionalArgs + SignerInfo SignerInfo + + positionalFlagSet *pflag.FlagSet + positionalArgs []fieldBinding + flagBindings []fieldBinding + messageType protoreflect.MessageType + + hasVarargs bool + hasOptional bool + mandatoryArgUntil int +} + +// BuildMessage builds and returns a new message for the bound flags. +func (m MessageBinder) BuildMessage(positionalArgs []string) (protoreflect.Message, error) { + msg := m.messageType.New() + err := m.Bind(msg, positionalArgs) + return msg, err +} + +// Bind binds the flag values to an existing protobuf message. +func (m MessageBinder) Bind(msg protoreflect.Message, positionalArgs []string) error { + // first set positional args in the positional arg flag set + n := len(positionalArgs) + for i := range m.positionalArgs { + if i == n { + break + } + + name := fmt.Sprintf("%d", i) + if i == m.mandatoryArgUntil && m.hasVarargs { + for _, v := range positionalArgs[i:] { + if err := m.positionalFlagSet.Set(name, v); err != nil { + return err + } + } + } else { + if err := m.positionalFlagSet.Set(name, positionalArgs[i]); err != nil { + return err + } + } + } + + msgName := msg.Descriptor().Name() + // bind positional arg values to the message + for _, arg := range m.positionalArgs { + if msgName == arg.field.Parent().Name() { + if err := arg.bind(msg); err != nil { + return err + } + } else { + s := strings.Split(arg.path, ".") + if err := m.bindNestedField(msg, arg, s); err != nil { + return err + } + } + } + + // bind flag values to the message + for _, binding := range m.flagBindings { + if err := binding.bind(msg); err != nil { + return err + } + } + + return nil +} + +// bindNestedField binds a field value to a nested message field. It handles cases where the field +// belongs to a nested message type by recursively traversing the message structure. +func (m *MessageBinder) bindNestedField(msg protoreflect.Message, arg fieldBinding, path []string) error { + if len(path) == 1 { + return arg.bind(msg) + } + + name := protoreflect.Name(path[0]) + fd := msg.Descriptor().Fields().ByName(name) + if fd == nil { + return fmt.Errorf("field %q not found", path[0]) + } + + var innerMsg protoreflect.Message + if fd.IsList() { + if msg.Get(fd).List().Len() == 0 { + l := msg.Mutable(fd).List() + elem := l.NewElement().Message().New() + l.Append(protoreflect.ValueOfMessage(elem)) + msg.Set(msg.Descriptor().Fields().ByName(name), protoreflect.ValueOfList(l)) + } + innerMsg = msg.Get(fd).List().Get(0).Message() + } else { + innerMsgValue := msg.Get(fd) + if !innerMsgValue.Message().IsValid() { + msg.Set(msg.Descriptor().Fields().ByName(name), protoreflect.ValueOfMessage(innerMsgValue.Message().New())) + } + innerMsg = msg.Get(msg.Descriptor().Fields().ByName(name)).Message() + } + + return m.bindNestedField(innerMsg, arg, path[1:]) +} + +// Get calls BuildMessage and wraps the result in a protoreflect.Value. +func (m MessageBinder) Get(protoreflect.Value) (protoreflect.Value, error) { + msg, err := m.BuildMessage(nil) + return protoreflect.ValueOfMessage(msg), err +} + +type fieldBinding struct { + hasValue HasValue + field protoreflect.FieldDescriptor + path string +} + +func (f fieldBinding) bind(msg protoreflect.Message) error { + field := f.field + val, err := f.hasValue.Get(msg.NewField(field)) + if err != nil { + return err + } + + if field.IsMap() { + return nil + } + + if msg.IsValid() && val.IsValid() { + msg.Set(f.field, val) + } + + return nil +} diff --git a/connect/internal/autocli/flag/pubkey.go b/connect/internal/autocli/flag/pubkey.go new file mode 100644 index 00000000..f91eab8f --- /dev/null +++ b/connect/internal/autocli/flag/pubkey.go @@ -0,0 +1,61 @@ +package flag + +import ( + "context" + "errors" + "fmt" + + "google.golang.org/protobuf/reflect/protoreflect" + + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/types" + cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" +) + +type pubkeyType struct{} + +func (a pubkeyType) NewValue(_ *context.Context, _ *Builder) Value { + return &pubkeyValue{} +} + +func (a pubkeyType) DefaultValue() string { + return "" +} + +type pubkeyValue struct { + value *types.Any +} + +func (a pubkeyValue) Get(protoreflect.Value) (protoreflect.Value, error) { + return protoreflect.ValueOf(a.value), nil +} + +func (a pubkeyValue) String() string { + return a.value.String() +} + +func (a *pubkeyValue) Set(s string) error { + registry := types.NewInterfaceRegistry() + cryptocodec.RegisterInterfaces(registry) + cdc := codec.NewProtoCodec(registry) + + var pk cryptotypes.PubKey + err := cdc.UnmarshalInterfaceJSON([]byte(s), &pk) + if err != nil { + return fmt.Errorf("input isn't a pubkey: %w", err) + } + + any, err := types.NewAnyWithValue(pk) + if err != nil { + return errors.New("error converting to any type") + } + + a.value = any + + return nil +} + +func (a pubkeyValue) Type() string { + return "pubkey" +} diff --git a/connect/internal/autocli/flag/simple.go b/connect/internal/autocli/flag/simple.go new file mode 100644 index 00000000..a64c565e --- /dev/null +++ b/connect/internal/autocli/flag/simple.go @@ -0,0 +1,44 @@ +package flag + +import ( + "github.com/spf13/pflag" + "google.golang.org/protobuf/reflect/protoreflect" +) + +func bindSimpleFlag(flagSet *pflag.FlagSet, kind protoreflect.Kind, name, shorthand, usage string) HasValue { + switch kind { + case protoreflect.StringKind: + val := flagSet.StringP(name, shorthand, "", usage) + return newSimpleValue(val, protoreflect.ValueOfString) + case protoreflect.Uint32Kind, protoreflect.Fixed32Kind: + val := flagSet.Uint32P(name, shorthand, 0, usage) + return newSimpleValue(val, protoreflect.ValueOfUint32) + case protoreflect.Uint64Kind, protoreflect.Fixed64Kind: + val := flagSet.Uint64P(name, shorthand, 0, usage) + return newSimpleValue(val, protoreflect.ValueOfUint64) + case protoreflect.Int32Kind, protoreflect.Sint32Kind, protoreflect.Sfixed32Kind: + val := flagSet.Int32P(name, shorthand, 0, usage) + return newSimpleValue(val, protoreflect.ValueOfInt32) + case protoreflect.Int64Kind, protoreflect.Sint64Kind, protoreflect.Sfixed64Kind: + val := flagSet.Int64P(name, shorthand, 0, usage) + return newSimpleValue(val, protoreflect.ValueOfInt64) + case protoreflect.BoolKind: + val := flagSet.BoolP(name, shorthand, false, usage) + return newSimpleValue(val, protoreflect.ValueOfBool) + default: + return nil + } +} + +type simpleValue[T any] struct { + val *T + toProtoreflectValue func(T) protoreflect.Value +} + +func newSimpleValue[T any](val *T, toProtoreflectValue func(T) protoreflect.Value) HasValue { + return simpleValue[T]{val: val, toProtoreflectValue: toProtoreflectValue} +} + +func (v simpleValue[T]) Get(protoreflect.Value) (protoreflect.Value, error) { + return v.toProtoreflectValue(*v.val), nil +} diff --git a/connect/internal/autocli/flag/timestamp.go b/connect/internal/autocli/flag/timestamp.go new file mode 100644 index 00000000..d77f0293 --- /dev/null +++ b/connect/internal/autocli/flag/timestamp.go @@ -0,0 +1,50 @@ +package flag + +import ( + "context" + "time" + + "google.golang.org/protobuf/reflect/protoreflect" + "google.golang.org/protobuf/types/known/timestamppb" +) + +type timestampType struct{} + +func (t timestampType) NewValue(*context.Context, *Builder) Value { + return ×tampValue{} +} + +func (t timestampType) DefaultValue() string { + return "" +} + +type timestampValue struct { + value *timestamppb.Timestamp +} + +func (t timestampValue) Get(protoreflect.Value) (protoreflect.Value, error) { + if t.value == nil { + return protoreflect.Value{}, nil + } + return protoreflect.ValueOfMessage(t.value.ProtoReflect()), nil +} + +func (t timestampValue) String() string { + if t.value == nil { + return "" + } + return t.value.AsTime().Format(time.RFC3339) +} + +func (t *timestampValue) Set(s string) error { + time, err := time.Parse(time.RFC3339, s) + if err != nil { + return err + } + t.value = timestamppb.New(time) + return nil +} + +func (t timestampValue) Type() string { + return "timestamp (RFC 3339)" +} diff --git a/connect/internal/autocli/interface.go b/connect/internal/autocli/interface.go new file mode 100644 index 00000000..df318172 --- /dev/null +++ b/connect/internal/autocli/interface.go @@ -0,0 +1,32 @@ +package autocli + +import ( + "github.com/spf13/cobra" + + autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" + "cosmossdk.io/core/appmodule" +) + +// HasAutoCLIConfig is an AppModule extension interface for declaring autocli module options. +type HasAutoCLIConfig interface { + appmodule.AppModule + + // AutoCLIOptions are the autocli module options for this module. + AutoCLIOptions() *autocliv1.ModuleOptions +} + +// HasCustomQueryCommand is an AppModule extension interface for declaring a custom query command. +type HasCustomQueryCommand interface { + appmodule.AppModule + + // GetQueryCmd returns a custom cobra query command for this module. + GetQueryCmd() *cobra.Command +} + +// HasCustomTxCommand is an AppModule extension interface for declaring a custom tx command. +type HasCustomTxCommand interface { + appmodule.AppModule + + // GetTxCmd returns a custom cobra tx command for this module. + GetTxCmd() *cobra.Command +} diff --git a/connect/internal/autocli/keyring/interface.go b/connect/internal/autocli/keyring/interface.go new file mode 100644 index 00000000..fa448bd2 --- /dev/null +++ b/connect/internal/autocli/keyring/interface.go @@ -0,0 +1,23 @@ +package keyring + +import ( + signingv1beta1 "cosmossdk.io/api/cosmos/tx/signing/v1beta1" + + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" +) + +// Keyring is an interface used for signing transactions. +// It aims to be simplistic and easy to use. +type Keyring interface { + // List returns the names of all keys stored in the keyring. + List() ([]string, error) + + // LookupAddressByKeyName returns the address of the key with the given name. + LookupAddressByKeyName(name string) ([]byte, error) + + // GetPubKey returns the public key of the key with the given name. + GetPubKey(name string) (cryptotypes.PubKey, error) + + // Sign signs the given bytes with the key with the given name. + Sign(name string, msg []byte, signMode signingv1beta1.SignMode) ([]byte, error) +} diff --git a/connect/internal/autocli/keyring/keyring.go b/connect/internal/autocli/keyring/keyring.go new file mode 100644 index 00000000..2b69d995 --- /dev/null +++ b/connect/internal/autocli/keyring/keyring.go @@ -0,0 +1,83 @@ +package keyring + +import ( + "io" + + "github.com/spf13/pflag" + + signingv1beta1 "cosmossdk.io/api/cosmos/tx/signing/v1beta1" + "cosmossdk.io/core/address" + + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/crypto/keyring" + "github.com/cosmos/cosmos-sdk/crypto/types" +) + +// KeyringContextKey is the key used to store the keyring in the context. +// The keyring must be wrapped using the KeyringImpl. +var KeyringContextKey keyringContextKey + +type keyringContextKey struct{} + +var _ Keyring = &KeyringImpl{} + +type KeyringImpl struct { + k Keyring +} + +// NewKeyringFromFlags creates a new Keyring instance based on command-line flags. +// It retrieves the keyring backend and directory from flags, creates a new keyring, +// and wraps it with an AutoCLI-compatible interface. +func NewKeyringFromFlags(flagSet *pflag.FlagSet, ac address.Codec, input io.Reader, cdc codec.Codec, opts ...keyring.Option) (Keyring, error) { + backEnd, err := flagSet.GetString("keyring-backend") + if err != nil { + return nil, err + } + + keyringDir, err := flagSet.GetString("keyring-dir") + if err != nil { + return nil, err + } + if keyringDir == "" { + keyringDir, err = flagSet.GetString("home") + if err != nil { + return nil, err + } + } + + k, err := keyring.New("autoclikeyring", backEnd, keyringDir, input, cdc, opts...) + if err != nil { + return nil, err + } + + autoCLIKeyring, err := keyring.NewAutoCLIKeyring(k) + if err != nil { + return nil, err + } + + return NewKeyringImpl(autoCLIKeyring), nil +} + +func NewKeyringImpl(k Keyring) *KeyringImpl { + return &KeyringImpl{k: k} +} + +// GetPubKey implements Keyring. +func (k *KeyringImpl) GetPubKey(name string) (types.PubKey, error) { + return k.k.GetPubKey(name) +} + +// List implements Keyring. +func (k *KeyringImpl) List() ([]string, error) { + return k.k.List() +} + +// LookupAddressByKeyName implements Keyring. +func (k *KeyringImpl) LookupAddressByKeyName(name string) ([]byte, error) { + return k.k.LookupAddressByKeyName(name) +} + +// Sign implements Keyring. +func (k *KeyringImpl) Sign(name string, msg []byte, signMode signingv1beta1.SignMode) ([]byte, error) { + return k.k.Sign(name, msg, signMode) +} diff --git a/connect/internal/autocli/keyring/no_keyring.go b/connect/internal/autocli/keyring/no_keyring.go new file mode 100644 index 00000000..e14267ce --- /dev/null +++ b/connect/internal/autocli/keyring/no_keyring.go @@ -0,0 +1,31 @@ +package keyring + +import ( + "errors" + + signingv1beta1 "cosmossdk.io/api/cosmos/tx/signing/v1beta1" + + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" +) + +var _ Keyring = NoKeyring{} + +var errNoKeyring = errors.New("no keyring configured") + +type NoKeyring struct{} + +func (k NoKeyring) List() ([]string, error) { + return nil, errNoKeyring +} + +func (k NoKeyring) LookupAddressByKeyName(name string) ([]byte, error) { + return nil, errNoKeyring +} + +func (k NoKeyring) GetPubKey(name string) (cryptotypes.PubKey, error) { + return nil, errNoKeyring +} + +func (k NoKeyring) Sign(name string, msg []byte, signMode signingv1beta1.SignMode) ([]byte, error) { + return nil, errNoKeyring +} diff --git a/connect/internal/autocli/msg.go b/connect/internal/autocli/msg.go new file mode 100644 index 00000000..85538f60 --- /dev/null +++ b/connect/internal/autocli/msg.go @@ -0,0 +1,232 @@ +package autocli + +import ( + "context" + "fmt" + + "github.com/spf13/cobra" + "google.golang.org/protobuf/proto" + "google.golang.org/protobuf/reflect/protoreflect" + "google.golang.org/protobuf/types/dynamicpb" + + autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" + addresscodec "cosmossdk.io/core/address" + "github.com/ignite/apps/connect/internal/autocli/flag" + "github.com/ignite/apps/connect/internal/internal/flags" + "github.com/ignite/apps/connect/internal/internal/governance" + "github.com/ignite/apps/connect/internal/internal/util" + + "github.com/cosmos/cosmos-sdk/client" + clienttx "github.com/cosmos/cosmos-sdk/client/tx" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" +) + +// BuildMsgCommand builds the msg commands for all the provided modules. If a custom command is provided for a +// module, this is used instead of any automatically generated CLI commands. This allows apps to a fully dynamic client +// with a more customized experience if a binary with custom commands is downloaded. +func (b *Builder) BuildMsgCommand(ctx context.Context, appOptions AppOptions, customCmds map[string]*cobra.Command) (*cobra.Command, error) { + msgCmd := topLevelCmd(ctx, "tx", "Transaction subcommands") + + if err := b.enhanceCommandCommon(msgCmd, msgCmdType, appOptions, customCmds); err != nil { + return nil, err + } + + return msgCmd, nil +} + +// AddMsgServiceCommands adds a sub-command to the provided command for each +// method in the specified service and returns the command. This can be used in +// order to add auto-generated commands to an existing command. +func (b *Builder) AddMsgServiceCommands(cmd *cobra.Command, cmdDescriptor *autocliv1.ServiceCommandDescriptor) error { + for cmdName, subCmdDescriptor := range cmdDescriptor.SubCommands { + subCmd := findSubCommand(cmd, cmdName) + if subCmd == nil { + short := subCmdDescriptor.Short + if short == "" { + short = fmt.Sprintf("Tx commands for the %s service", subCmdDescriptor.Service) + } + subCmd = topLevelCmd(cmd.Context(), cmdName, short) + } + + // Add recursive sub-commands if there are any. This is used for nested services. + if err := b.AddMsgServiceCommands(subCmd, subCmdDescriptor); err != nil { + return err + } + + if !subCmdDescriptor.EnhanceCustomCommand { + cmd.AddCommand(subCmd) + } + } + + if cmdDescriptor.Service == "" { + // skip empty command descriptor + return nil + } + + descriptor, err := b.FileResolver.FindDescriptorByName(protoreflect.FullName(cmdDescriptor.Service)) + if err != nil { + return fmt.Errorf("can't find service %s: %w", cmdDescriptor.Service, err) + } + service := descriptor.(protoreflect.ServiceDescriptor) + methods := service.Methods() + + rpcOptMap := map[protoreflect.Name]*autocliv1.RpcCommandOptions{} + for _, option := range cmdDescriptor.RpcCommandOptions { + methodName := protoreflect.Name(option.RpcMethod) + // validate that methods exist + if m := methods.ByName(methodName); m == nil { + return fmt.Errorf("rpc method %q not found for service %q", methodName, service.FullName()) + } + rpcOptMap[methodName] = option + + } + + for i := 0; i < methods.Len(); i++ { + methodDescriptor := methods.Get(i) + methodOpts, ok := rpcOptMap[methodDescriptor.Name()] + if !ok { + methodOpts = &autocliv1.RpcCommandOptions{} + } + + if methodOpts.Skip { + continue + } + + if !util.IsSupportedVersion(methodDescriptor) { + continue + } + + methodCmd, err := b.BuildMsgMethodCommand(methodDescriptor, methodOpts) + if err != nil { + return err + } + + if findSubCommand(cmd, methodCmd.Name()) != nil { + // do not overwrite existing commands + // we do not display a warning because you may want to overwrite an autocli command + continue + } + + cmd.AddCommand(methodCmd) + } + + return nil +} + +// BuildMsgMethodCommand returns a command that outputs the JSON representation of the message. +func (b *Builder) BuildMsgMethodCommand(descriptor protoreflect.MethodDescriptor, options *autocliv1.RpcCommandOptions) (*cobra.Command, error) { + execFunc := func(cmd *cobra.Command, input protoreflect.Message) error { + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + clientCtx = clientCtx.WithCmdContext(cmd.Context()) + clientCtx = clientCtx.WithOutput(cmd.OutOrStdout()) + + fd := input.Descriptor().Fields().ByName(protoreflect.Name(flag.GetSignerFieldName(input.Descriptor()))) + addressCodec := b.Builder.AddressCodec + + // handle gov proposals commands + skipProposal, _ := cmd.Flags().GetBool(flags.FlagNoProposal) + if isProposalMessage(descriptor.Input()) && !skipProposal { + return b.handleGovProposal(cmd, input, clientCtx, addressCodec, fd) + } + + // set signer to signer field if empty + if addr := input.Get(fd).String(); addr == "" { + scalarType, ok := flag.GetScalarType(fd) + if ok { + // override address codec if validator or consensus address + switch scalarType { + case flag.ValidatorAddressStringScalarType: + addressCodec = b.Builder.ValidatorAddressCodec + case flag.ConsensusAddressStringScalarType: + addressCodec = b.Builder.ConsensusAddressCodec + } + } + + signerFromFlag := clientCtx.GetFromAddress() + signer, err := addressCodec.BytesToString(signerFromFlag.Bytes()) + if err != nil { + return fmt.Errorf("failed to set signer on message, got %v: %w", signerFromFlag, err) + } + + input.Set(fd, protoreflect.ValueOfString(signer)) + } + + // AutoCLI uses protov2 messages, while the SDK only supports proto v1 messages. + // Here we use dynamicpb, to create a proto v1 compatible message. + // The SDK codec will handle protov2 -> protov1 (marshal) + msg := dynamicpb.NewMessage(input.Descriptor()) + proto.Merge(msg, input.Interface()) + + return clienttx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + } + + cmd, err := b.buildMethodCommandCommon(descriptor, options, execFunc) + if err != nil { + return nil, err + } + + if b.AddTxConnFlags != nil { + b.AddTxConnFlags(cmd) + } + + // silence usage only for inner txs & queries commands + cmd.SilenceUsage = true + + // set gov proposal flags if command is a gov proposal + if isProposalMessage(descriptor.Input()) { + governance.AddGovPropFlagsToCmd(cmd) + cmd.Flags().Bool(flags.FlagNoProposal, false, "Skip gov proposal and submit a normal transaction") + } + + return cmd, nil +} + +// handleGovProposal sets the authority field of the message to the gov module address and creates a gov proposal. +func (b *Builder) handleGovProposal( + cmd *cobra.Command, + input protoreflect.Message, + clientCtx client.Context, + addressCodec addresscodec.Codec, + fd protoreflect.FieldDescriptor, +) error { + govAuthority := authtypes.NewModuleAddress(governance.ModuleName) + authority, err := addressCodec.BytesToString(govAuthority.Bytes()) + if err != nil { + return fmt.Errorf("failed to convert gov authority: %w", err) + } + input.Set(fd, protoreflect.ValueOfString(authority)) + + signerFromFlag := clientCtx.GetFromAddress() + signer, err := addressCodec.BytesToString(signerFromFlag.Bytes()) + if err != nil { + return fmt.Errorf("failed to set signer on message, got %q: %w", signerFromFlag, err) + } + + proposal, err := governance.ReadGovPropCmdFlags(signer, cmd.Flags()) + if err != nil { + return err + } + + // AutoCLI uses protov2 messages, while the SDK only supports proto v1 messages. + // Here we use dynamicpb, to create a proto v1 compatible message. + // The SDK codec will handle protov2 -> protov1 (marshal) + msg := dynamicpb.NewMessage(input.Descriptor()) + proto.Merge(msg, input.Interface()) + + if err := governance.SetGovMsgs(proposal, msg); err != nil { + return fmt.Errorf("failed to set msg in proposal %w", err) + } + + return clienttx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), proposal) +} + +// isProposalMessage checks the msg name against well known proposal messages. +// this isn't exhaustive. to have it better we need to add a field in autocli proto +// as it was done in v0.52. +func isProposalMessage(_ protoreflect.MessageDescriptor) bool { + return false +} diff --git a/connect/internal/autocli/msg_test.go b/connect/internal/autocli/msg_test.go new file mode 100644 index 00000000..83a92109 --- /dev/null +++ b/connect/internal/autocli/msg_test.go @@ -0,0 +1,285 @@ +package autocli + +import ( + "bytes" + "context" + "encoding/json" + "fmt" + "os" + "path/filepath" + "testing" + + "github.com/spf13/cobra" + "gotest.tools/v3/assert" + "gotest.tools/v3/golden" + + autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" + bankv1beta1 "cosmossdk.io/api/cosmos/bank/v1beta1" + "github.com/ignite/apps/connect/internal/internal/testpb" + + "github.com/cosmos/cosmos-sdk/client" +) + +var buildModuleMsgCommand = func(moduleName string, f *fixture) (*cobra.Command, error) { + ctx := context.WithValue(context.Background(), client.ClientContextKey, &f.clientCtx) + cmd := topLevelCmd(ctx, moduleName, fmt.Sprintf("Transactions commands for the %s module", moduleName)) + err := f.b.AddMsgServiceCommands(cmd, bankAutoCLI) + return cmd, err +} + +func buildCustomModuleMsgCommand(cmdDescriptor *autocliv1.ServiceCommandDescriptor) func(moduleName string, f *fixture) (*cobra.Command, error) { + return func(moduleName string, f *fixture) (*cobra.Command, error) { + ctx := context.WithValue(context.Background(), client.ClientContextKey, &f.clientCtx) + cmd := topLevelCmd(ctx, moduleName, fmt.Sprintf("Transactions commands for the %s module", moduleName)) + err := f.b.AddMsgServiceCommands(cmd, cmdDescriptor) + return cmd, err + } +} + +var bankAutoCLI = &autocliv1.ServiceCommandDescriptor{ + Service: bankv1beta1.Msg_ServiceDesc.ServiceName, + RpcCommandOptions: []*autocliv1.RpcCommandOptions{ + { + RpcMethod: "Send", + Use: "send [flags]", + Short: "Send coins from one account to another", + PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "from_address"}, {ProtoField: "to_address"}, {ProtoField: "amount"}}, + }, + }, + EnhanceCustomCommand: true, +} + +func TestMsg(t *testing.T) { + fixture := initFixture(t) + out, err := runCmd(fixture, buildModuleMsgCommand, "send", + "cosmos1y74p8wyy4enfhfn342njve6cjmj5c8dtl6emdk", "cosmos1y74p8wyy4enfhfn342njve6cjmj5c8dtl6emdk", "1foo", + "--generate-only", + "--output", "json", + "--chain-id", fixture.chainID, + ) + assert.NilError(t, err) + assertNormalizedJSONEqual(t, out.Bytes(), goldenLoad(t, "msg-output.golden")) + + out, err = runCmd(fixture, buildCustomModuleMsgCommand(&autocliv1.ServiceCommandDescriptor{ + Service: bankv1beta1.Msg_ServiceDesc.ServiceName, + RpcCommandOptions: []*autocliv1.RpcCommandOptions{ + { + RpcMethod: "Send", + Use: "send [flags]", + Short: "Send coins from one account to another", + PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "from_address"}, {ProtoField: "to_address"}, {ProtoField: "amount"}}, + }, + }, + EnhanceCustomCommand: true, + }), "send", + "cosmos1y74p8wyy4enfhfn342njve6cjmj5c8dtl6emdk", "cosmos1y74p8wyy4enfhfn342njve6cjmj5c8dtl6emdk", "1foo", + "--generate-only", + "--output", "json", + "--chain-id", fixture.chainID, + ) + assert.NilError(t, err) + assertNormalizedJSONEqual(t, out.Bytes(), goldenLoad(t, "msg-output.golden")) + + out, err = runCmd(fixture, buildCustomModuleMsgCommand(&autocliv1.ServiceCommandDescriptor{ + Service: bankv1beta1.Msg_ServiceDesc.ServiceName, + RpcCommandOptions: []*autocliv1.RpcCommandOptions{ + { + RpcMethod: "Send", + Use: "send [flags]", + Short: "Send coins from one account to another", + PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "to_address"}, {ProtoField: "amount"}}, + // from_address should be automatically added + }, + }, + EnhanceCustomCommand: true, + }), "send", + "cosmos1y74p8wyy4enfhfn342njve6cjmj5c8dtl6emdk", "1foo", + "--from", "cosmos1y74p8wyy4enfhfn342njve6cjmj5c8dtl6emdk", + "--output", "json", + "--generate-only", + "--chain-id", fixture.chainID, + "--keyring-backend", fixture.kBackend, + ) + assert.NilError(t, err) + assertNormalizedJSONEqual(t, out.Bytes(), goldenLoad(t, "msg-output.golden")) + + out, err = runCmd(fixture, buildCustomModuleMsgCommand(&autocliv1.ServiceCommandDescriptor{ + Service: bankv1beta1.Msg_ServiceDesc.ServiceName, + RpcCommandOptions: []*autocliv1.RpcCommandOptions{ + { + RpcMethod: "Send", + Use: "send [flags]", + Short: "Send coins from one account to another", + PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "to_address"}, {ProtoField: "amount"}}, + FlagOptions: map[string]*autocliv1.FlagOptions{ + "from_address": {Name: "sender"}, // use a custom flag for signer + }, + }, + }, + EnhanceCustomCommand: true, + }), "send", + "cosmos1y74p8wyy4enfhfn342njve6cjmj5c8dtl6emdk", "1foo", + "--sender", "cosmos1y74p8wyy4enfhfn342njve6cjmj5c8dtl6emdk", + "--output", "json", + "--generate-only", + "--chain-id", fixture.chainID, + ) + assert.NilError(t, err) + assertNormalizedJSONEqual(t, out.Bytes(), goldenLoad(t, "msg-output.golden")) +} + +func TestMsgWithFlattenFields(t *testing.T) { + fixture := initFixture(t) + + out, err := runCmd(fixture, buildCustomModuleMsgCommand(&autocliv1.ServiceCommandDescriptor{ + Service: bankv1beta1.Msg_ServiceDesc.ServiceName, + RpcCommandOptions: []*autocliv1.RpcCommandOptions{ + { + RpcMethod: "UpdateParams", + PositionalArgs: []*autocliv1.PositionalArgDescriptor{ + {ProtoField: "authority"}, + {ProtoField: "params.send_enabled.denom"}, + {ProtoField: "params.send_enabled.enabled"}, + {ProtoField: "params.default_send_enabled"}, + }, + }, + }, + EnhanceCustomCommand: true, + }), "update-params", + "cosmos1y74p8wyy4enfhfn342njve6cjmj5c8dtl6emdk", "stake", "true", "true", + "--generate-only", + "--output", "json", + "--chain-id", fixture.chainID, + ) + assert.NilError(t, err) + assertNormalizedJSONEqual(t, out.Bytes(), goldenLoad(t, "flatten-output.golden")) +} + +func goldenLoad(t *testing.T, filename string) []byte { + t.Helper() + content, err := os.ReadFile(filepath.Join("testdata", filename)) + assert.NilError(t, err) + return content +} + +func assertNormalizedJSONEqual(t *testing.T, expected, actual []byte) { + t.Helper() + normalizedExpected, err := normalizeJSON(expected) + assert.NilError(t, err) + normalizedActual, err := normalizeJSON(actual) + assert.NilError(t, err) + assert.Equal(t, string(normalizedExpected), string(normalizedActual)) +} + +// normalizeJSON normalizes the JSON content by removing unnecessary white spaces and newlines. +func normalizeJSON(content []byte) ([]byte, error) { + var buf bytes.Buffer + err := json.Compact(&buf, content) + if err != nil { + return nil, err + } + return buf.Bytes(), nil +} + +func TestMsgOptionsError(t *testing.T) { + fixture := initFixture(t) + + _, err := runCmd(fixture, buildModuleMsgCommand, + "send", "5", + ) + assert.ErrorContains(t, err, "accepts 3 arg(s)") + + _, err = runCmd(fixture, buildModuleMsgCommand, + "send", "foo", "bar", "invalid", + ) + assert.ErrorContains(t, err, "invalid argument") +} + +func TestHelpMsg(t *testing.T) { + fixture := initFixture(t) + + out, err := runCmd(fixture, buildModuleMsgCommand, "-h") + assert.NilError(t, err) + golden.Assert(t, out.String(), "help-toplevel-msg.golden") + + out, err = runCmd(fixture, buildModuleMsgCommand, "send", "-h") + assert.NilError(t, err) + golden.Assert(t, out.String(), "help-echo-msg.golden") +} + +func TestBuildCustomMsgCommand(t *testing.T) { + b := &Builder{} + customCommandCalled := false + appOptions := AppOptions{ + ModuleOptions: map[string]*autocliv1.ModuleOptions{ + "test": { + Tx: &autocliv1.ServiceCommandDescriptor{ + Service: testpb.Msg_ServiceDesc.ServiceName, + RpcCommandOptions: []*autocliv1.RpcCommandOptions{}, + }, + }, + }, + } + + cmd, err := b.BuildMsgCommand(context.Background(), appOptions, map[string]*cobra.Command{ + "test": {Use: "test", Run: func(cmd *cobra.Command, args []string) { + customCommandCalled = true + }}, + }) + assert.NilError(t, err) + cmd.SetArgs([]string{"test", "tx"}) + assert.NilError(t, cmd.Execute()) + assert.Assert(t, customCommandCalled) +} + +func TestNotFoundErrorsMsg(t *testing.T) { + fixture := initFixture(t) + b := fixture.b + b.AddQueryConnFlags = nil + b.AddTxConnFlags = nil + + buildModuleMsgCommand := func(moduleName string, cmdDescriptor *autocliv1.ServiceCommandDescriptor) (*cobra.Command, error) { + cmd := topLevelCmd(context.Background(), moduleName, fmt.Sprintf("Transactions commands for the %s module", moduleName)) + + err := b.AddMsgServiceCommands(cmd, cmdDescriptor) + return cmd, err + } + + // Query non existent service + _, err := buildModuleMsgCommand("test", &autocliv1.ServiceCommandDescriptor{Service: "un-existent-service"}) + assert.ErrorContains(t, err, "can't find service un-existent-service") + + _, err = buildModuleMsgCommand("test", &autocliv1.ServiceCommandDescriptor{ + Service: testpb.Query_ServiceDesc.ServiceName, + RpcCommandOptions: []*autocliv1.RpcCommandOptions{{RpcMethod: "un-existent-method"}}, + }) + assert.ErrorContains(t, err, "rpc method \"un-existent-method\" not found") + + _, err = buildModuleMsgCommand("test", &autocliv1.ServiceCommandDescriptor{ + Service: testpb.Msg_ServiceDesc.ServiceName, + RpcCommandOptions: []*autocliv1.RpcCommandOptions{ + { + RpcMethod: "Send", + PositionalArgs: []*autocliv1.PositionalArgDescriptor{ + { + ProtoField: "un-existent-proto-field", + }, + }, + }, + }, + }) + assert.ErrorContains(t, err, "can't find field un-existent-proto-field") + + _, err = buildModuleMsgCommand("test", &autocliv1.ServiceCommandDescriptor{ + Service: testpb.Msg_ServiceDesc.ServiceName, + RpcCommandOptions: []*autocliv1.RpcCommandOptions{ + { + RpcMethod: "Send", + FlagOptions: map[string]*autocliv1.FlagOptions{ + "un-existent-flag": {}, + }, + }, + }, + }) + assert.ErrorContains(t, err, "can't find field un-existent-flag") +} diff --git a/connect/internal/autocli/prompt/message.go b/connect/internal/autocli/prompt/message.go new file mode 100644 index 00000000..2bd73a33 --- /dev/null +++ b/connect/internal/autocli/prompt/message.go @@ -0,0 +1,259 @@ +package prompt + +import ( + "fmt" + "io" + "strconv" + "strings" + + "github.com/manifoldco/promptui" + "google.golang.org/protobuf/reflect/protoreflect" + + addresscodec "cosmossdk.io/core/address" + "github.com/ignite/apps/connect/internal/autocli/flag" +) + +// PromptMessage prompts the user for values to populate a protobuf message interactively. +// It returns the populated message and any error encountered during prompting. +func PromptMessage( + addressCodec, validatorAddressCodec, consensusAddressCodec addresscodec.Codec, + promptPrefix string, msg protoreflect.Message, +) (protoreflect.Message, error) { + return promptMessage(addressCodec, validatorAddressCodec, consensusAddressCodec, promptPrefix, nil, msg) +} + +// promptMessage prompts the user for values to populate a protobuf message interactively. +// stdIn is provided to make the function easier to unit test by allowing injection of predefined inputs. +func promptMessage( + addressCodec, validatorAddressCodec, consensusAddressCodec addresscodec.Codec, + promptPrefix string, stdIn io.ReadCloser, msg protoreflect.Message, +) (protoreflect.Message, error) { + fields := msg.Descriptor().Fields() + for i := 0; i < fields.Len(); i++ { + field := fields.Get(i) + fieldName := string(field.Name()) + + promptUi := promptui.Prompt{ + Validate: ValidatePromptNotEmpty, + Stdin: stdIn, + } + + // If this signer field has already a valid default value set, + // use that value as the default prompt value. This is useful for + // commands that have an authority such as gov. + if strings.EqualFold(fieldName, flag.GetSignerFieldName(msg.Descriptor())) { + if defaultValue := msg.Get(field); defaultValue.IsValid() { + promptUi.Default = defaultValue.String() + } + } + + // validate address fields + scalarField, ok := flag.GetScalarType(field) + if ok { + switch scalarField { + case flag.AddressStringScalarType: + promptUi.Validate = ValidateAddress(addressCodec) + case flag.ValidatorAddressStringScalarType: + promptUi.Validate = ValidateAddress(validatorAddressCodec) + case flag.ConsensusAddressStringScalarType: + promptUi.Validate = ValidateAddress(consensusAddressCodec) + default: + // prompt.Validate = ValidatePromptNotEmpty (we possibly don't want to force all fields to be non-empty) + promptUi.Validate = nil + } + } + + // handle nested message fields recursively + if field.Kind() == protoreflect.MessageKind { + err := promptInnerMessageKind(field, addressCodec, validatorAddressCodec, consensusAddressCodec, promptPrefix, stdIn, msg) + if err != nil { + return nil, err + } + continue + } + + // handle repeated fields by prompting for a comma-separated list of values + if field.IsList() { + list, err := promptList(field, msg, promptUi, promptPrefix) + if err != nil { + return nil, err + } + + msg.Set(field, protoreflect.ValueOfList(list)) + continue + } + + promptUi.Label = fmt.Sprintf("Enter %s %s", promptPrefix, fieldName) + result, err := promptUi.Run() + if err != nil { + return msg, fmt.Errorf("failed to prompt for %s: %w", fieldName, err) + } + + v, err := valueOf(field, result) + if err != nil { + return msg, err + } + msg.Set(field, v) + } + + return msg, nil +} + +// valueOf converts a string input value to a protoreflect.Value based on the field's type. +// It handles string, numeric, bool, bytes and enum field types. +// Returns the converted value and any error that occurred during conversion. +func valueOf(field protoreflect.FieldDescriptor, result string) (protoreflect.Value, error) { + switch field.Kind() { + case protoreflect.StringKind: + return protoreflect.ValueOfString(result), nil + case protoreflect.Uint32Kind, protoreflect.Fixed32Kind, protoreflect.Uint64Kind, protoreflect.Fixed64Kind: + resultUint, err := strconv.ParseUint(result, 10, 0) + if err != nil { + return protoreflect.Value{}, fmt.Errorf("invalid value for int: %w", err) + } + + return protoreflect.ValueOfUint64(resultUint), nil + case protoreflect.Int32Kind, protoreflect.Sint32Kind, protoreflect.Sfixed32Kind, protoreflect.Int64Kind, protoreflect.Sint64Kind, protoreflect.Sfixed64Kind: + resultInt, err := strconv.ParseInt(result, 10, 0) + if err != nil { + return protoreflect.Value{}, fmt.Errorf("invalid value for int: %w", err) + } + // If a value was successfully parsed the ranges of: + // [minInt, maxInt] + // are within the ranges of: + // [minInt64, maxInt64] + // of which on 64-bit machines, which are most common, + // int==int64 + return protoreflect.ValueOfInt64(resultInt), nil + case protoreflect.BoolKind: + resultBool, err := strconv.ParseBool(result) + if err != nil { + return protoreflect.Value{}, fmt.Errorf("invalid value for bool: %w", err) + } + + return protoreflect.ValueOfBool(resultBool), nil + case protoreflect.BytesKind: + resultBytes := []byte(result) + return protoreflect.ValueOfBytes(resultBytes), nil + case protoreflect.EnumKind: + enumValue := field.Enum().Values().ByName(protoreflect.Name(result)) + if enumValue == nil { + return protoreflect.Value{}, fmt.Errorf("invalid enum value %q", result) + } + return protoreflect.ValueOfEnum(enumValue.Number()), nil + default: + // TODO: add more kinds + // skip any other types + return protoreflect.Value{}, nil + } +} + +// promptList prompts the user for a comma-separated list of values for a repeated field. +// The user will be prompted to enter values separated by commas which will be parsed +// according to the field's type using valueOf. +func promptList(field protoreflect.FieldDescriptor, msg protoreflect.Message, promptUi promptui.Prompt, promptPrefix string) (protoreflect.List, error) { + promptUi.Label = fmt.Sprintf("Enter %s %s list (separate values with ',')", promptPrefix, string(field.Name())) + result, err := promptUi.Run() + if err != nil { + return nil, fmt.Errorf("failed to prompt for %s: %w", string(field.Name()), err) + } + + list := msg.Mutable(field).List() + for _, item := range strings.Split(result, ",") { + v, err := valueOf(field, item) + if err != nil { + return nil, err + } + list.Append(v) + } + + return list, nil +} + +// promptInnerMessageKind handles prompting for fields that are of message kind. +// It handles both single messages and repeated message fields by delegating to +// promptInnerMessage and promptMessageList respectively. +func promptInnerMessageKind( + f protoreflect.FieldDescriptor, addressCodec addresscodec.Codec, + validatorAddressCodec, consensusAddressCodec addresscodec.Codec, + promptPrefix string, stdIn io.ReadCloser, msg protoreflect.Message, +) error { + if f.IsList() { + return promptMessageList(f, addressCodec, validatorAddressCodec, consensusAddressCodec, promptPrefix, stdIn, msg) + } + return promptInnerMessage(f, addressCodec, validatorAddressCodec, consensusAddressCodec, promptPrefix, stdIn, msg) +} + +// promptInnerMessage prompts for a single nested message field. It creates a new message instance, +// recursively prompts for its fields, and sets the populated message on the parent message. +func promptInnerMessage( + f protoreflect.FieldDescriptor, addressCodec addresscodec.Codec, + validatorAddressCodec, consensusAddressCodec addresscodec.Codec, + promptPrefix string, stdIn io.ReadCloser, msg protoreflect.Message, +) error { + fieldName := promptPrefix + "." + string(f.Name()) + nestedMsg := msg.Get(f).Message() + nestedMsg = nestedMsg.New() + // Recursively prompt for nested message fields + updatedMsg, err := promptMessage( + addressCodec, + validatorAddressCodec, + consensusAddressCodec, + fieldName, + stdIn, + nestedMsg, + ) + if err != nil { + return fmt.Errorf("failed to prompt for nested message %s: %w", fieldName, err) + } + + msg.Set(f, protoreflect.ValueOfMessage(updatedMsg)) + return nil +} + +// promptMessageList prompts for a repeated message field by repeatedly creating new message instances, +// prompting for their fields, and appending them to the list until the user chooses to stop. +func promptMessageList( + f protoreflect.FieldDescriptor, addressCodec addresscodec.Codec, + validatorAddressCodec, consensusAddressCodec addresscodec.Codec, + promptPrefix string, stdIn io.ReadCloser, msg protoreflect.Message, +) error { + list := msg.Mutable(f).List() + for { + fieldName := promptPrefix + "." + string(f.Name()) + // Create and populate a new message for the list + nestedMsg := list.NewElement().Message() + updatedMsg, err := promptMessage( + addressCodec, + validatorAddressCodec, + consensusAddressCodec, + fieldName, + stdIn, + nestedMsg, + ) + if err != nil { + return fmt.Errorf("failed to prompt for list item in %s: %w", fieldName, err) + } + + list.Append(protoreflect.ValueOfMessage(updatedMsg)) + + // Prompt whether to continue + // TODO: may be better yes/no rather than interactive? + continuePrompt := promptui.Select{ + Label: "Add another item?", + Items: []string{"No", "Yes"}, + Stdin: stdIn, + } + + _, result, err := continuePrompt.Run() + if err != nil { + return fmt.Errorf("failed to prompt for continuation: %w", err) + } + + if result == "No" { + break + } + } + + return nil +} diff --git a/connect/internal/autocli/prompt/message_test.go b/connect/internal/autocli/prompt/message_test.go new file mode 100644 index 00000000..0d844e84 --- /dev/null +++ b/connect/internal/autocli/prompt/message_test.go @@ -0,0 +1,59 @@ +package prompt + +import ( + "io" + "strings" + "testing" + + "github.com/stretchr/testify/require" + "google.golang.org/protobuf/reflect/protoreflect" + + "github.com/ignite/apps/connect/internal/internal/testpb" + + address2 "github.com/cosmos/cosmos-sdk/codec/address" +) + +func getReader(inputs []string) io.ReadCloser { + // https://github.com/manifoldco/promptui/issues/63#issuecomment-621118463 + var paddedInputs []string + for _, input := range inputs { + padding := strings.Repeat("a", 4096-1-len(input)%4096) + paddedInputs = append(paddedInputs, input+"\n"+padding) + } + return io.NopCloser(strings.NewReader(strings.Join(paddedInputs, ""))) +} + +func TestPromptMessage(t *testing.T) { + tests := []struct { + name string + msg protoreflect.Message + inputs []string + }{ + { + name: "testPb", + inputs: []string{ + "1", "2", "string", "bytes", "10101010", "0", "234234", "3", "4", "5", "true", "ENUM_ONE", + "bar", "6", "10000", "stake", "cosmos10d07y265gmmuvt4z0w9aw880jnsr700j6zn9kn", + "bytes", "6", "7", "false", "false", "true,false,true", "1,2,3", "hello,hola,ciao", "ENUM_ONE,ENUM_TWO", + "10239", "0", "No", "bar", "343", "No", "134", "positional2", "23455", "stake", "No", "deprecate", + "shorthand", "false", "cosmosvaloper1tnh2q55v8wyygtt9srz5safamzdengsn9dsd7z", + }, + msg: (&testpb.MsgRequest{}).ProtoReflect(), + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + // https://github.com/manifoldco/promptui/issues/63#issuecomment-621118463 + var paddedInputs []string + for _, input := range tt.inputs { + padding := strings.Repeat("a", 4096-1-len(input)%4096) + paddedInputs = append(paddedInputs, input+"\n"+padding) + } + reader := io.NopCloser(strings.NewReader(strings.Join(paddedInputs, ""))) + + got, err := promptMessage(address2.NewBech32Codec("cosmos"), address2.NewBech32Codec("cosmosvaloper"), address2.NewBech32Codec("cosmosvalcons"), "prefix", reader, tt.msg) + require.NoError(t, err) + require.NotNil(t, got) + }) + } +} diff --git a/connect/internal/autocli/prompt/struct.go b/connect/internal/autocli/prompt/struct.go new file mode 100644 index 00000000..a450b5a6 --- /dev/null +++ b/connect/internal/autocli/prompt/struct.go @@ -0,0 +1,134 @@ +package prompt + +import ( + "fmt" + "io" + "reflect" + "strconv" + "strings" + + "github.com/manifoldco/promptui" +) + +// PromptStruct prompts for values of a struct's fields interactively. +// It returns the populated struct and any error encountered. +func PromptStruct[T any](promptPrefix string, data T) (T, error) { + return promptStruct(promptPrefix, data, nil) +} + +// promptStruct prompts for values of a struct's fields interactively. +// +// For each field in the struct: +// - Pointer fields are initialized if nil and handled recursively if they contain structs +// - Struct fields are handled recursively +// - String and int slices are supported +// - String and int fields are prompted for and populated +// - Only String and int pointers are supported +// - Other types are skipped +func promptStruct[T any](promptPrefix string, data T, stdIn io.ReadCloser) (T, error) { + v := reflect.ValueOf(&data).Elem() + if v.Kind() == reflect.Interface { + v = reflect.ValueOf(data) + if v.Kind() == reflect.Ptr { + v = v.Elem() + } + } + + for i := 0; i < v.NumField(); i++ { + field := v.Field(i) + fieldName := strings.ToLower(v.Type().Field(i).Name) + + // Handle pointer types + if field.Kind() == reflect.Ptr { + if field.IsNil() { + field.Set(reflect.New(field.Type().Elem())) + } + if field.Elem().Kind() == reflect.Struct { + result, err := promptStruct(promptPrefix+"."+fieldName, field.Interface(), stdIn) + if err != nil { + return data, err + } + field.Set(reflect.ValueOf(result)) + continue + } + } + + switch field.Kind() { + case reflect.Struct: + // For struct fields, create a new pointer to handle them + structPtr := reflect.New(field.Type()).Interface() + reflect.ValueOf(structPtr).Elem().Set(field) + + result, err := promptStruct(promptPrefix+"."+fieldName, structPtr, stdIn) + if err != nil { + return data, err + } + + // Get the actual struct value from the result + resultValue := reflect.ValueOf(result) + if resultValue.Kind() == reflect.Ptr { + resultValue = resultValue.Elem() + } + field.Set(resultValue) + continue + case reflect.Slice: + if v.Field(i).Type().Elem().Kind() != reflect.String && v.Field(i).Type().Elem().Kind() != reflect.Int { + continue + } + } + + // create prompts + prompt := promptui.Prompt{ + Label: fmt.Sprintf("Enter %s %s", promptPrefix, strings.Title(fieldName)), // nolint:staticcheck // strings.Title has a better API + Validate: ValidatePromptNotEmpty, + Stdin: stdIn, + } + + result, err := prompt.Run() + if err != nil { + return data, fmt.Errorf("failed to prompt for %s: %w", fieldName, err) + } + + switch field.Kind() { + case reflect.String: + v.Field(i).SetString(result) + case reflect.Int: + resultInt, err := strconv.ParseInt(result, 10, 0) + if err != nil { + return data, fmt.Errorf("invalid value for int: %w", err) + } + v.Field(i).SetInt(resultInt) + case reflect.Slice: + switch v.Field(i).Type().Elem().Kind() { + case reflect.String: + v.Field(i).Set(reflect.ValueOf([]string{result})) + case reflect.Int: + resultInt, err := strconv.ParseInt(result, 10, 0) + if err != nil { + return data, fmt.Errorf("invalid value for int: %w", err) + } + + v.Field(i).Set(reflect.ValueOf([]int{int(resultInt)})) + } + case reflect.Ptr: + // Handle pointer fields by creating a new value and setting it + ptrValue := reflect.New(field.Type().Elem()) + if ptrValue.Elem().Kind() == reflect.String { + ptrValue.Elem().SetString(result) + v.Field(i).Set(ptrValue) + } else if ptrValue.Elem().Kind() == reflect.Int { + resultInt, err := strconv.ParseInt(result, 10, 0) + if err != nil { + return data, fmt.Errorf("invalid value for int: %w", err) + } + ptrValue.Elem().SetInt(resultInt) + v.Field(i).Set(ptrValue) + } + default: + // skip any other types + continue + } + } + + return data, nil +} diff --git a/connect/internal/autocli/prompt/struct_test.go b/connect/internal/autocli/prompt/struct_test.go new file mode 100644 index 00000000..1b712d81 --- /dev/null +++ b/connect/internal/autocli/prompt/struct_test.go @@ -0,0 +1,46 @@ +package prompt + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +type innerStruct struct { + A string + B int +} + +type testStruct struct { + A string + B int + C *innerStruct + D innerStruct + E *string + F []string +} + +func TestPromptStruct(t *testing.T) { + type testCase[T any] struct { + name string + data T + inputs []string + } + tests := []testCase[testStruct]{ + { + name: "test struct", + data: testStruct{}, + inputs: []string{ + "a", "1", "b", "2", "c", "3", "pointerStr", "list", + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + inputs := getReader(tt.inputs) + got, err := promptStruct("testStruct", tt.data, inputs) + require.NoError(t, err) + require.NotNil(t, got) + }) + } +} diff --git a/connect/internal/autocli/prompt/util.go b/connect/internal/autocli/prompt/util.go new file mode 100644 index 00000000..4b3bdec5 --- /dev/null +++ b/connect/internal/autocli/prompt/util.go @@ -0,0 +1,70 @@ +package prompt + +import ( + "fmt" + + "github.com/manifoldco/promptui" + "google.golang.org/protobuf/reflect/protoreflect" +) + +// Select prompts the user to select an option from a list of choices. +// It takes a label string to display above the selection prompt and a slice of string options to choose from. +func Select(label string, options []string) (string, error) { + selectUi := promptui.Select{ + Label: label, + Items: options, + } + + _, selectedProposalType, err := selectUi.Run() + if err != nil { + return "", fmt.Errorf("failed to prompt proposal types: %w", err) + } + + return selectedProposalType, nil +} + +// PromptString prompts the user for a string input with the given label. +// It validates the input using the provided validate function. +func PromptString(label string, validate func(string) error) (string, error) { + promptUi := promptui.Prompt{ + Label: label, + Validate: validate, + } + + return promptUi.Run() +} + +// SetDefaults sets default values on a protobuf message based on a map of field names to values. +// It iterates through the message fields and sets values from the defaults map if the field name +// and type match. +func SetDefaults(msg protoreflect.Message, defaults map[string]interface{}) { + fields := msg.Descriptor().Fields() + for i := 0; i < fields.Len(); i++ { + field := fields.Get(i) + fieldName := string(field.Name()) + + if v, ok := defaults[fieldName]; ok { + // Get the field's kind + fieldKind := field.Kind() + + switch v.(type) { + case string: + if fieldKind == protoreflect.StringKind { + msg.Set(field, protoreflect.ValueOf(v)) + } + case int64: + if fieldKind == protoreflect.Int64Kind { + msg.Set(field, protoreflect.ValueOf(v)) + } + case int32: + if fieldKind == protoreflect.Int32Kind { + msg.Set(field, protoreflect.ValueOf(v)) + } + case bool: + if fieldKind == protoreflect.BoolKind { + msg.Set(field, protoreflect.ValueOf(v)) + } + } + } + } +} diff --git a/connect/internal/autocli/prompt/validation.go b/connect/internal/autocli/prompt/validation.go new file mode 100644 index 00000000..c1899184 --- /dev/null +++ b/connect/internal/autocli/prompt/validation.go @@ -0,0 +1,52 @@ +package prompt + +import ( + "errors" + "fmt" + "net/url" + "unicode" + + "cosmossdk.io/core/address" +) + +// ValidatePromptNotEmpty validates that the input is not empty. +func ValidatePromptNotEmpty(input string) error { + if input == "" { + return errors.New("input cannot be empty") + } + + return nil +} + +// ValidateAddress returns a validation function that checks if a string is a valid address +// for the given address codec. +func ValidateAddress(ac address.Codec) func(string) error { + return func(i string) error { + if _, err := ac.StringToBytes(i); err != nil { + return fmt.Errorf("invalid address") + } + + return nil + } +} + +// ValidatePromptURL validates that the input is a valid URL. +func ValidatePromptURL(input string) error { + _, err := url.ParseRequestURI(input) + if err != nil { + return fmt.Errorf("invalid URL: %w", err) + } + + return nil +} + +// CamelCaseToString converts a camel case string to a string with spaces. +func CamelCaseToString(str string) string { + w := []rune(str) + for i := len(w) - 1; i > 1; i-- { + if unicode.IsUpper(w[i]) { + w = append(w[:i], append([]rune{' '}, w[i:]...)...) + } + } + return string(w) +} diff --git a/connect/internal/autocli/prompt/validation_test.go b/connect/internal/autocli/prompt/validation_test.go new file mode 100644 index 00000000..32b65b2c --- /dev/null +++ b/connect/internal/autocli/prompt/validation_test.go @@ -0,0 +1,55 @@ +package prompt + +import ( + "testing" + + "github.com/stretchr/testify/require" + + "cosmossdk.io/core/address" + + address2 "github.com/cosmos/cosmos-sdk/codec/address" +) + +func TestValidatePromptNotEmpty(t *testing.T) { + require := require.New(t) + + require.NoError(ValidatePromptNotEmpty("foo")) + require.ErrorContains(ValidatePromptNotEmpty(""), "input cannot be empty") +} + +func TestValidateAddress(t *testing.T) { + tests := []struct { + name string + ac address.Codec + addr string + }{ + { + name: "address", + ac: address2.NewBech32Codec("cosmos"), + addr: "cosmos129lxcu2n3hx54fdxlwsahqkjr3sp32cxm00zlm", + }, + { + name: "validator address", + ac: address2.NewBech32Codec("cosmosvaloper"), + addr: "cosmosvaloper1tnh2q55v8wyygtt9srz5safamzdengsn9dsd7z", + }, + { + name: "consensus address", + ac: address2.NewBech32Codec("cosmosvalcons"), + addr: "cosmosvalcons136uu5rj23kdr3jjcmjt7aw5qpugjjat2klgrus", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + err := ValidateAddress(tt.ac)(tt.addr) + require.NoError(t, err) + }) + } +} + +func TestValidatePromptURL(t *testing.T) { + require := require.New(t) + + require.NoError(ValidatePromptURL("https://example.com")) + require.ErrorContains(ValidatePromptURL("foo"), "invalid URL") +} diff --git a/connect/internal/autocli/query.go b/connect/internal/autocli/query.go new file mode 100644 index 00000000..78e6a061 --- /dev/null +++ b/connect/internal/autocli/query.go @@ -0,0 +1,253 @@ +package autocli + +import ( + "context" + "errors" + "fmt" + "io" + "strings" + "time" + + "github.com/spf13/cobra" + "google.golang.org/grpc/metadata" + "google.golang.org/protobuf/reflect/protoreflect" + + autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" + "cosmossdk.io/math" + "cosmossdk.io/x/tx/signing/aminojson" + "github.com/ignite/apps/connect/internal/internal/flags" + "github.com/ignite/apps/connect/internal/internal/util" + + sdk "github.com/cosmos/cosmos-sdk/types" +) + +// BuildQueryCommand builds the query commands for all the provided modules. If a custom command is provided for a +// module, this is used instead of any automatically generated CLI commands. This allows apps to a fully dynamic client +// with a more customized experience if a binary with custom commands is downloaded. +func (b *Builder) BuildQueryCommand(ctx context.Context, appOptions AppOptions, customCmds map[string]*cobra.Command) (*cobra.Command, error) { + queryCmd := topLevelCmd(ctx, "query", "Querying subcommands") + queryCmd.Aliases = []string{"q"} + + if err := b.enhanceCommandCommon(queryCmd, queryCmdType, appOptions, customCmds); err != nil { + return nil, err + } + + return queryCmd, nil +} + +// AddQueryServiceCommands adds a sub-command to the provided command for each +// method in the specified service and returns the command. This can be used in +// order to add auto-generated commands to an existing command. +func (b *Builder) AddQueryServiceCommands(cmd *cobra.Command, cmdDescriptor *autocliv1.ServiceCommandDescriptor) error { + for cmdName, subCmdDesc := range cmdDescriptor.SubCommands { + subCmd := findSubCommand(cmd, cmdName) + if subCmd == nil { + short := subCmdDesc.Short + if short == "" { + short = fmt.Sprintf("Querying commands for the %s service", subCmdDesc.Service) + } + subCmd = topLevelCmd(cmd.Context(), cmdName, short) + } + + if err := b.AddQueryServiceCommands(subCmd, subCmdDesc); err != nil { + return err + } + + if !subCmdDesc.EnhanceCustomCommand { + cmd.AddCommand(subCmd) + } + } + + // skip empty command descriptors + if cmdDescriptor.Service == "" { + return nil + } + + descriptor, err := b.FileResolver.FindDescriptorByName(protoreflect.FullName(cmdDescriptor.Service)) + if err != nil { + return fmt.Errorf("can't find service %s: %w", cmdDescriptor.Service, err) + } + + service := descriptor.(protoreflect.ServiceDescriptor) + methods := service.Methods() + + rpcOptMap := map[protoreflect.Name]*autocliv1.RpcCommandOptions{} + for _, option := range cmdDescriptor.RpcCommandOptions { + name := protoreflect.Name(option.RpcMethod) + rpcOptMap[name] = option + // make sure method exists + if m := methods.ByName(name); m == nil { + return fmt.Errorf("rpc method %q not found for service %q", name, service.FullName()) + } + } + + for i := 0; i < methods.Len(); i++ { + methodDescriptor := methods.Get(i) + methodOpts, ok := rpcOptMap[methodDescriptor.Name()] + if !ok { + methodOpts = &autocliv1.RpcCommandOptions{} + } + + if methodOpts.Skip { + continue + } + + if !util.IsSupportedVersion(methodDescriptor) { + continue + } + + methodCmd, err := b.BuildQueryMethodCommand(cmd.Context(), methodDescriptor, methodOpts) + if err != nil { + return err + } + + if findSubCommand(cmd, methodCmd.Name()) != nil { + // do not overwrite existing commands + // we do not display a warning because you may want to overwrite an autocli command + continue + } + + cmd.AddCommand(methodCmd) + } + + return nil +} + +// BuildQueryMethodCommand creates a gRPC query command for the given service method. This can be used to auto-generate +// just a single command for a single service rpc method. +func (b *Builder) BuildQueryMethodCommand(ctx context.Context, descriptor protoreflect.MethodDescriptor, options *autocliv1.RpcCommandOptions) (*cobra.Command, error) { + serviceDescriptor := descriptor.Parent().(protoreflect.ServiceDescriptor) + methodName := fmt.Sprintf("/%s/%s", serviceDescriptor.FullName(), descriptor.Name()) + outputType := util.ResolveMessageType(b.TypeResolver, descriptor.Output()) + encoderOptions := aminojson.EncoderOptions{ + Indent: " ", + EnumAsString: true, + DoNotSortFields: true, + AminoNameAsTypeURL: true, + MarshalMappings: true, + TypeResolver: b.TypeResolver, + FileResolver: b.FileResolver, + } + + cmd, err := b.buildMethodCommandCommon(descriptor, options, func(cmd *cobra.Command, input protoreflect.Message) error { + clientConn, err := b.GetClientConn(cmd) + if err != nil { + return err + } + + output := outputType.New() + if err := clientConn.Invoke(b.queryContext(cmd.Context(), cmd), methodName, input.Interface(), output.Interface()); err != nil { + return err + } + + if noIndent, _ := cmd.Flags().GetBool(flags.FlagNoIndent); noIndent { + encoderOptions.Indent = "" + } + + enc := encoder(aminojson.NewEncoder(encoderOptions)) + bz, err := enc.Marshal(output.Interface()) + if err != nil { + return fmt.Errorf("cannot marshal response %v: %w", output.Interface(), err) + } + + return b.outOrStdoutFormat(cmd, bz) + }) + if err != nil { + return nil, err + } + + if b.AddQueryConnFlags != nil { + b.AddQueryConnFlags(cmd) + + cmd.Flags().BoolP(flags.FlagNoIndent, "", false, "Do not indent JSON output") + } + + // silence usage only for inner txs & queries commands + if cmd != nil { + cmd.SilenceUsage = true + } + + return cmd, nil +} + +// queryContext returns a new context with metadata for block height if specified. +// If the context already has metadata, it is returned as-is. Otherwise, if a height +// flag is present on the command, it adds an x-cosmos-block-height metadata value +// with the specified height. +func (b *Builder) queryContext(ctx context.Context, cmd *cobra.Command) context.Context { + md, _ := metadata.FromOutgoingContext(ctx) + if md != nil { + return ctx + } + + md = map[string][]string{} + if cmd.Flags().Lookup("height") != nil { + h, _ := cmd.Flags().GetInt64("height") + md["x-cosmos-block-height"] = []string{fmt.Sprintf("%d", h)} + } + + return metadata.NewOutgoingContext(ctx, md) +} + +func encoder(encoder aminojson.Encoder) aminojson.Encoder { + return encoder.DefineTypeEncoding("google.protobuf.Duration", func(_ *aminojson.Encoder, msg protoreflect.Message, w io.Writer) error { + var ( + secondsName protoreflect.Name = "seconds" + nanosName protoreflect.Name = "nanos" + ) + + fields := msg.Descriptor().Fields() + secondsField := fields.ByName(secondsName) + if secondsField == nil { + return errors.New("expected seconds field") + } + + seconds := msg.Get(secondsField).Int() + + nanosField := fields.ByName(nanosName) + if nanosField == nil { + return errors.New("expected nanos field") + } + + nanos := msg.Get(nanosField).Int() + + _, err := fmt.Fprintf(w, `"%s"`, (time.Duration(seconds)*time.Second + (time.Duration(nanos) * time.Nanosecond)).String()) + return err + }).DefineTypeEncoding("cosmos.base.v1beta1.DecCoin", func(_ *aminojson.Encoder, msg protoreflect.Message, w io.Writer) error { + var ( + denomName protoreflect.Name = "denom" + amountName protoreflect.Name = "amount" + ) + + fields := msg.Descriptor().Fields() + denomField := fields.ByName(denomName) + if denomField == nil { + return errors.New("expected denom field") + } + + denom := msg.Get(denomField).String() + + amountField := fields.ByName(amountName) + if amountField == nil { + return errors.New("expected amount field") + } + + amount := msg.Get(amountField).String() + decimalPlace := len(amount) - math.LegacyPrecision + if decimalPlace > 0 { + amount = amount[:decimalPlace] + "." + amount[decimalPlace:] + } else if decimalPlace == 0 { + amount = "0." + amount + } else { + amount = "0." + strings.Repeat("0", -decimalPlace) + amount + } + + amountDec, err := math.LegacyNewDecFromStr(amount) + if err != nil { + return fmt.Errorf("invalid amount: %s: %w", amount, err) + } + + _, err = fmt.Fprintf(w, `"%s"`, sdk.NewDecCoinFromDec(denom, amountDec)) // TODO(@julienrbrt): Eventually remove this SDK dependency + return err + }) +} diff --git a/connect/internal/autocli/query_test.go b/connect/internal/autocli/query_test.go new file mode 100644 index 00000000..cfd0be95 --- /dev/null +++ b/connect/internal/autocli/query_test.go @@ -0,0 +1,739 @@ +package autocli + +import ( + "context" + "fmt" + "os" + "strings" + "testing" + "time" + + "github.com/spf13/cobra" + "google.golang.org/protobuf/testing/protocmp" + "google.golang.org/protobuf/types/known/durationpb" + "google.golang.org/protobuf/types/known/timestamppb" + "gotest.tools/v3/assert" + "gotest.tools/v3/golden" + + autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" + queryv1beta1 "cosmossdk.io/api/cosmos/base/query/v1beta1" + basev1beta1 "cosmossdk.io/api/cosmos/base/v1beta1" + "github.com/ignite/apps/connect/internal/internal/testpb" + + "github.com/cosmos/cosmos-sdk/client" +) + +var buildModuleQueryCommand = func(moduleName string, f *fixture) (*cobra.Command, error) { + ctx := context.WithValue(context.Background(), client.ClientContextKey, &f.clientCtx) + cmd := topLevelCmd(ctx, moduleName, fmt.Sprintf("Querying commands for the %s module", moduleName)) + + err := f.b.AddQueryServiceCommands(cmd, testCmdDesc) + return cmd, err +} + +var buildModuleQueryCommandOptional = func(moduleName string, f *fixture) (*cobra.Command, error) { + ctx := context.WithValue(context.Background(), client.ClientContextKey, &f.clientCtx) + cmd := topLevelCmd(ctx, moduleName, fmt.Sprintf("Querying commands for the %s module", moduleName)) + + err := f.b.AddQueryServiceCommands(cmd, testCmdDescOptional) + return cmd, err +} + +var buildModuleVargasOptional = func(moduleName string, f *fixture) (*cobra.Command, error) { + ctx := context.WithValue(context.Background(), client.ClientContextKey, &f.clientCtx) + cmd := topLevelCmd(ctx, moduleName, fmt.Sprintf("Querying commands for the %s module", moduleName)) + + err := f.b.AddQueryServiceCommands(cmd, testCmdDescInvalidOptAndVargas) + return cmd, err +} + +var testCmdDesc = &autocliv1.ServiceCommandDescriptor{ + Service: testpb.Query_ServiceDesc.ServiceName, + RpcCommandOptions: []*autocliv1.RpcCommandOptions{ + { + RpcMethod: "Echo", + Use: "echo [pos1] [pos2] [pos3...]", + Version: "1.0", + Alias: []string{"e"}, + SuggestFor: []string{"eco"}, + Example: "echo 1 abc {}", + Short: "echo echos the value provided by the user", + Long: "echo echos the value provided by the user as a proto JSON object with populated with the provided fields and positional arguments", + PositionalArgs: []*autocliv1.PositionalArgDescriptor{ + { + ProtoField: "positional1", + }, + { + ProtoField: "positional2", + }, + { + ProtoField: "positional3_varargs", + Varargs: true, + }, + }, + FlagOptions: map[string]*autocliv1.FlagOptions{ + "u32": { + Name: "uint32", + Shorthand: "u", + Usage: "some random uint32", + }, + "i32": { + Usage: "some random int32", + DefaultValue: "3", + }, + "u64": { + Usage: "some random uint64", + DefaultValue: "5", + }, + "deprecated_field": { + Deprecated: "don't use this", + }, + "shorthand_deprecated_field": { + Shorthand: "s", + Deprecated: "bad idea", + }, + "hidden_bool": { + Hidden: true, + }, + "a_coin": { + Usage: "some random coin", + }, + "duration": { + Usage: "some random duration", + }, + "bz": { + Usage: "some bytes", + }, + "map_string_string": { + Usage: "some map of string to string", + }, + "map_string_uint32": { + Usage: "some map of string to int32", + }, + "map_string_coin": { + Usage: "some map of string to coin", + }, + }, + }, + }, + SubCommands: map[string]*autocliv1.ServiceCommandDescriptor{ + // we test the sub-command functionality using the same service with different options + "deprecatedecho": { + Service: testpb.Query_ServiceDesc.ServiceName, + RpcCommandOptions: []*autocliv1.RpcCommandOptions{ + { + RpcMethod: "Echo", + Deprecated: "don't use this", + }, + }, + }, + "skipecho": { + Service: testpb.Query_ServiceDesc.ServiceName, + RpcCommandOptions: []*autocliv1.RpcCommandOptions{ + { + RpcMethod: "Echo", + Skip: true, + }, + }, + }, + }, +} + +var testCmdDescOptional = &autocliv1.ServiceCommandDescriptor{ + Service: testpb.Query_ServiceDesc.ServiceName, + RpcCommandOptions: []*autocliv1.RpcCommandOptions{ + { + RpcMethod: "Echo", + Use: "echo [pos1] [pos2] [pos3...]", + Version: "1.0", + Alias: []string{"e"}, + SuggestFor: []string{"eco"}, + Example: "echo 1 abc {}", + Short: "echo echos the value provided by the user", + Long: "echo echos the value provided by the user as a proto JSON object with populated with the provided fields and positional arguments", + PositionalArgs: []*autocliv1.PositionalArgDescriptor{ + { + ProtoField: "positional1", + }, + { + ProtoField: "positional2", + Optional: true, + }, + }, + }, + }, +} + +var testCmdDescInvalidOptAndVargas = &autocliv1.ServiceCommandDescriptor{ + Service: testpb.Query_ServiceDesc.ServiceName, + RpcCommandOptions: []*autocliv1.RpcCommandOptions{ + { + RpcMethod: "Echo", + Use: "echo [pos1] [pos2] [pos3...]", + Version: "1.0", + Alias: []string{"e"}, + SuggestFor: []string{"eco"}, + Example: "echo 1 abc {}", + Short: "echo echos the value provided by the user", + Long: "echo echos the value provided by the user as a proto JSON object with populated with the provided fields and positional arguments", + PositionalArgs: []*autocliv1.PositionalArgDescriptor{ + { + ProtoField: "positional1", + }, + { + ProtoField: "positional2", + Optional: true, + }, + { + ProtoField: "positional3_varargs", + Varargs: true, + }, + }, + }, + }, +} + +func TestCoin(t *testing.T) { + fixture := initFixture(t) + + _, err := runCmd(fixture, buildModuleQueryCommand, + "echo", + "1", + "abc", + "1234foo,4321bar", + "100uatom", + "--a-coin", "100000foo", + ) + assert.ErrorContains(t, err, "coin flag must be a single coin, specific multiple coins with multiple flags or spaces") + + _, err = runCmd(fixture, buildModuleQueryCommand, + "echo", + "1", + "abc", + "1234foo", + "4321bar", + "100uatom", + "--a-coin", "100000foo", + "--coins", "100000bar", + "--coins", "100uatom", + ) + assert.NilError(t, err) + assert.DeepEqual(t, fixture.conn.lastRequest, fixture.conn.lastResponse.(*testpb.EchoResponse).Request, protocmp.Transform()) + expectedResp := &testpb.EchoResponse{ + Request: &testpb.EchoRequest{ + Positional1: 1, + Positional2: "abc", + Positional3Varargs: []*basev1beta1.Coin{ + {Amount: "1234", Denom: "foo"}, + {Amount: "4321", Denom: "bar"}, + {Amount: "100", Denom: "uatom"}, + }, + ACoin: &basev1beta1.Coin{ + Amount: "100000", + Denom: "foo", + }, + Coins: []*basev1beta1.Coin{ + {Amount: "100000", Denom: "bar"}, + {Amount: "100", Denom: "uatom"}, + }, + Page: &queryv1beta1.PageRequest{}, + I32: 3, + U64: 5, + }, + } + assert.DeepEqual(t, fixture.conn.lastResponse.(*testpb.EchoResponse), expectedResp, protocmp.Transform()) +} + +func TestOptional(t *testing.T) { + fixture := initFixture(t) + + _, err := runCmd(fixture, buildModuleQueryCommandOptional, + "echo", + "1", + "abc", + ) + assert.NilError(t, err) + request := fixture.conn.lastRequest.(*testpb.EchoRequest) + assert.Equal(t, request.Positional2, "abc") + assert.DeepEqual(t, fixture.conn.lastRequest, fixture.conn.lastResponse.(*testpb.EchoResponse).Request, protocmp.Transform()) + + _, err = runCmd(fixture, buildModuleQueryCommandOptional, + "echo", + "1", + ) + assert.NilError(t, err) + + request = fixture.conn.lastRequest.(*testpb.EchoRequest) + assert.Equal(t, request.Positional2, "") + assert.DeepEqual(t, fixture.conn.lastRequest, fixture.conn.lastResponse.(*testpb.EchoResponse).Request, protocmp.Transform()) + + _, err = runCmd(fixture, buildModuleQueryCommandOptional, + "echo", + "1", + "abc", + "extra-arg", + ) + assert.ErrorContains(t, err, "accepts between 1 and 2 arg(s), received 3") + + _, err = runCmd(fixture, buildModuleVargasOptional, + "echo", + "1", + "abc", + "extra-arg", + ) + assert.ErrorContains(t, err, "optional positional argument positional2 must be the last argument") +} + +func TestMap(t *testing.T) { + fixture := initFixture(t) + + _, err := runCmd(fixture, buildModuleQueryCommand, + "echo", + "1", + "abc", + "1234foo", + "4321bar", + "--map-string-uint32", "bar=123", + "--map-string-string", "val=foo", + "--map-string-coin", "baz=100000foo", + "--map-string-coin", "sec=100000bar", + "--map-string-coin", "multi=100000bar,flag=100000foo", + ) + assert.NilError(t, err) + assert.DeepEqual(t, fixture.conn.lastRequest, fixture.conn.lastResponse.(*testpb.EchoResponse).Request, protocmp.Transform()) + + _, err = runCmd(fixture, buildModuleQueryCommand, + "echo", + "1", + "abc", + "1234foo", + "4321bar", + "--map-string-uint32", "bar=123", + "--map-string-coin", "baz,100000foo", + "--map-string-coin", "sec=100000bar", + ) + assert.ErrorContains(t, err, "invalid argument \"baz,100000foo\" for \"--map-string-coin\" flag: invalid format, expected key=value") + + _, err = runCmd(fixture, buildModuleQueryCommand, + "echo", + "1", + "abc", + "1234foo", + "4321bar", + "--map-string-uint32", "bar=not-unint32", + "--map-string-coin", "baz=100000foo", + "--map-string-coin", "sec=100000bar", + ) + assert.ErrorContains(t, err, "invalid argument \"bar=not-unint32\" for \"--map-string-uint32\" flag: strconv.ParseUint: parsing \"not-unint32\": invalid syntax") + + _, err = runCmd(fixture, buildModuleQueryCommand, + "echo", + "1", + "abc", + "1234foo", + "4321bar", + "--map-string-uint32", "bar=123.9", + "--map-string-coin", "baz=100000foo", + "--map-string-coin", "sec=100000bar", + ) + assert.ErrorContains(t, err, "invalid argument \"bar=123.9\" for \"--map-string-uint32\" flag: strconv.ParseUint: parsing \"123.9\": invalid syntax") +} + +// TestEverything tests all the different types of flags are correctly read and as well as correctly returned +// This tests the flag binding and the message building +func TestEverything(t *testing.T) { + fixture := initFixture(t) + + _, err := runCmd(fixture, buildModuleQueryCommand, + "echo", + "1", + "abc", + "123.123123124foo", + "4321bar", + "--a-bool", + "--an-enum", "one", + "--a-message", `{"bar":"abc", "baz":-3}`, + "--duration", "4h3s", + "--uint32", "27", + "--u64", "3267246890", + "--i32", "-253", + "--i64", "-234602347", + "--str", "def", + "--timestamp", "2019-01-02T00:01:02Z", + "--a-coin", "100000foo", + "--an-address", "cosmos1y74p8wyy4enfhfn342njve6cjmj5c8dtl6emdk", + "--a-validator-address", "cosmosvaloper1tnh2q55v8wyygtt9srz5safamzdengsn9dsd7z", + "--a-consensus-address", "cosmosvalcons16vm0nx49eam4q0xasdnwdzsdl6ymgyjt757sgr", + "--bz", "c2RncXdlZndkZ3NkZw==", + "--page-count-total", + "--page-key", "MTIzNTQ4N3NnaGRhcw==", + "--page-limit", "1000", + "--page-offset", "10", + "--page-reverse", + "--bools", "true", + "--bools", "false,false,true", + "--enums", "one", + "--enums", "five", + "--enums", "two", + "--strings", "abc", + "--strings", "xyz", + "--strings", "xyz,qrs", + "--durations", "3s", + "--durations", "5s", + "--durations", "10h", + "--some-messages", "{}", + "--some-messages", `{"bar":"baz"}`, + "--some-messages", `{"baz":-1}`, + "--uints", "1,2,3", + "--uints", "4", + ) + assert.NilError(t, err) + + expectedResp := &testpb.EchoResponse{ + Request: &testpb.EchoRequest{ + Positional1: 1, + Positional2: "abc", + Positional3Varargs: []*basev1beta1.Coin{ + {Amount: "123.123123124", Denom: "foo"}, + {Amount: "4321", Denom: "bar"}, + }, + ABool: true, + AnEnum: testpb.Enum_ENUM_ONE, + AMessage: &testpb.AMessage{ + Bar: "abc", + Baz: -3, + }, + Duration: durationpb.New(4*time.Hour + 3*time.Second), + U32: 27, + U64: 3267246890, + I32: -253, + I64: -234602347, + Str: "def", + Timestamp: ×tamppb.Timestamp{ + Seconds: 1546387262, + }, + ACoin: &basev1beta1.Coin{ + Amount: "100000", + Denom: "foo", + }, + AnAddress: "cosmos1y74p8wyy4enfhfn342njve6cjmj5c8dtl6emdk", + AValidatorAddress: "cosmosvaloper1tnh2q55v8wyygtt9srz5safamzdengsn9dsd7z", + AConsensusAddress: "cosmosvalcons16vm0nx49eam4q0xasdnwdzsdl6ymgyjt757sgr", + Bz: []byte("sdgqwefwdgsdg"), + Page: &queryv1beta1.PageRequest{ + CountTotal: true, + Key: []byte("1235487sghdas"), + Limit: 1000, + Offset: 10, + Reverse: true, + }, + Bools: []bool{true, false, false, true}, + Enums: []testpb.Enum{testpb.Enum_ENUM_ONE, testpb.Enum_ENUM_FIVE, testpb.Enum_ENUM_TWO}, + Strings: []string{ + "abc", + "xyz", + "xyz", + "qrs", + }, + Durations: []*durationpb.Duration{ + durationpb.New(3 * time.Second), + durationpb.New(5 * time.Second), + durationpb.New(10 * time.Hour), + }, + SomeMessages: []*testpb.AMessage{ + {}, + {Bar: "baz"}, + {Baz: -1}, + }, + Uints: []uint32{1, 2, 3, 4}, + }, + } + + assert.DeepEqual(t, fixture.conn.lastRequest, fixture.conn.lastResponse.(*testpb.EchoResponse).Request, protocmp.Transform()) + assert.DeepEqual(t, fixture.conn.lastResponse.(*testpb.EchoResponse), expectedResp, protocmp.Transform()) +} + +func TestPubKeyParsingConsensusAddress(t *testing.T) { + fixture := initFixture(t) + + _, err := runCmd(fixture, buildModuleQueryCommand, + "echo", + "1", "abc", "1foo", + "--a-consensus-address", "{\"@type\":\"/cosmos.crypto.ed25519.PubKey\",\"key\":\"j8qdbR+AlH/V6aBTCSWXRvX3JUESF2bV+SEzndBhF0o=\"}", + "-u", "27", // shorthand + ) + assert.NilError(t, err) + assert.DeepEqual(t, fixture.conn.lastRequest, fixture.conn.lastResponse.(*testpb.EchoResponse).Request, protocmp.Transform()) +} + +func TestJSONParsing(t *testing.T) { + fixture := initFixture(t) + + _, err := runCmd(fixture, buildModuleQueryCommand, + "echo", + "1", "abc", "1foo", + "--some-messages", `{"bar":"baz"}`, + "-u", "27", // shorthand + ) + assert.NilError(t, err) + assert.DeepEqual(t, fixture.conn.lastRequest, fixture.conn.lastResponse.(*testpb.EchoResponse).Request, protocmp.Transform()) + + _, err = runCmd(fixture, buildModuleQueryCommand, + "echo", + "1", "abc", "1foo", + "--some-messages", "testdata/some_message.json", + "-u", "27", // shorthand + ) + assert.NilError(t, err) + assert.DeepEqual(t, fixture.conn.lastRequest, fixture.conn.lastResponse.(*testpb.EchoResponse).Request, protocmp.Transform()) +} + +func TestOptions(t *testing.T) { + fixture := initFixture(t) + + _, err := runCmd(fixture, buildModuleQueryCommand, + "echo", + "1", "abc", "123foo", + "-u", "27", // shorthand + "--u64", "5", // no opt default value + ) + assert.NilError(t, err) + + lastReq := fixture.conn.lastRequest.(*testpb.EchoRequest) + assert.Equal(t, uint32(27), lastReq.U32) // shorthand got set + assert.Equal(t, int32(3), lastReq.I32) // default value got set + assert.Equal(t, uint64(5), lastReq.U64) // no opt default value got set +} + +func TestBinaryFlag(t *testing.T) { + // Create a temporary file with some content + tempFile, err := os.Open("testdata/file.test") + if err != nil { + t.Fatal(err) + } + content := []byte("this is just a test file") + if err := tempFile.Close(); err != nil { + t.Fatal(err) + } + + // Test cases + tests := []struct { + name string + input string + expected []byte + hasError bool + err string + }{ + { + name: "Valid file path with extension", + input: tempFile.Name(), + expected: content, + hasError: false, + err: "", + }, + { + name: "Valid hex-encoded string", + input: "68656c6c6f20776f726c64", + expected: []byte("hello world"), + hasError: false, + err: "", + }, + { + name: "Valid base64-encoded string", + input: "SGVsbG8gV29ybGQ=", + expected: []byte("Hello World"), + hasError: false, + err: "", + }, + { + name: "Invalid input (not a file path or encoded string)", + input: "not a file or encoded string", + expected: nil, + hasError: true, + err: "input string is neither a valid file path, hex, or base64 encoded", + }, + } + + // Run test cases + fixture := initFixture(t) + for _, tc := range tests { + t.Run(tc.name, func(t *testing.T) { + _, err := runCmd(fixture, buildModuleQueryCommand, + "echo", + "1", "abc", `100foo`, + "--bz", tc.input, + ) + if tc.hasError { + assert.ErrorContains(t, err, tc.err) + } else { + assert.NilError(t, err) + lastReq := fixture.conn.lastRequest.(*testpb.EchoRequest) + assert.DeepEqual(t, tc.expected, lastReq.Bz) + } + }) + } +} + +func TestAddressValidation(t *testing.T) { + fixture := initFixture(t) + + _, err := runCmd(fixture, buildModuleQueryCommand, + "echo", + "1", "abc", "1foo", + "--an-address", "cosmos1y74p8wyy4enfhfn342njve6cjmj5c8dtl6emdk", + ) + assert.NilError(t, err) + + _, err = runCmd(fixture, buildModuleQueryCommand, + "echo", + "1", "abc", "1foo", + "--an-address", "regen1y74p8wyy4enfhfn342njve6cjmj5c8dtlqj7ule2", + ) + assert.ErrorContains(t, err, "invalid account address") + + _, err = runCmd(fixture, buildModuleQueryCommand, + "echo", + "1", "abc", "1foo", + "--an-address", "cosmps1BAD_ENCODING", + ) + assert.ErrorContains(t, err, "invalid account address") +} + +func TestOutputFormat(t *testing.T) { + fixture := initFixture(t) + + out, err := runCmd(fixture, buildModuleQueryCommand, + "echo", + "1", "abc", "1foo", + "--output", "json", + ) + assert.NilError(t, err) + assert.Assert(t, strings.Contains(out.String(), "{")) + + out, err = runCmd(fixture, buildModuleQueryCommand, + "echo", + "1", "abc", "1foo", + "--output", "text", + ) + assert.NilError(t, err) + assert.Assert(t, strings.Contains(out.String(), " positional1: 1")) +} + +func TestHelpQuery(t *testing.T) { + fixture := initFixture(t) + + out, err := runCmd(fixture, buildModuleQueryCommand, "-h") + assert.NilError(t, err) + golden.Assert(t, out.String(), "help-toplevel.golden") + + out, err = runCmd(fixture, buildModuleQueryCommand, "echo", "-h") + assert.NilError(t, err) + golden.Assert(t, out.String(), "help-echo.golden") + + out, err = runCmd(fixture, buildModuleQueryCommand, "deprecatedecho", "echo", "-h") + assert.NilError(t, err) + golden.Assert(t, out.String(), "help-deprecated.golden") + + out, err = runCmd(fixture, buildModuleQueryCommand, "skipecho", "-h") + assert.NilError(t, err) + golden.Assert(t, out.String(), "help-skip.golden") +} + +func TestDeprecatedQuery(t *testing.T) { + fixture := initFixture(t) + + out, err := runCmd(fixture, buildModuleQueryCommand, "echo", + "1", "abc", "--deprecated-field", "foo") + assert.NilError(t, err) + assert.Assert(t, strings.Contains(out.String(), "--deprecated-field has been deprecated")) + + out, err = runCmd(fixture, buildModuleQueryCommand, "echo", + "1", "abc", "-s", "foo") + assert.NilError(t, err) + assert.Assert(t, strings.Contains(out.String(), "--shorthand-deprecated-field has been deprecated")) +} + +func TestBuildCustomQueryCommand(t *testing.T) { + b := &Builder{} + customCommandCalled := false + + appOptions := AppOptions{ + ModuleOptions: map[string]*autocliv1.ModuleOptions{ + "test": { + Query: testCmdDesc, + }, + }, + } + + cmd, err := b.BuildQueryCommand(context.Background(), appOptions, map[string]*cobra.Command{ + "test": {Use: "test", Run: func(cmd *cobra.Command, args []string) { + customCommandCalled = true + }}, + }) + assert.NilError(t, err) + cmd.SetArgs([]string{"test", "query"}) + assert.NilError(t, cmd.Execute()) + assert.Assert(t, customCommandCalled) +} + +func TestNotFoundErrorsQuery(t *testing.T) { + fixture := initFixture(t) + b := fixture.b + b.AddQueryConnFlags = nil + b.AddTxConnFlags = nil + + buildModuleQueryCommand := func(_ string, cmdDescriptor *autocliv1.ServiceCommandDescriptor) (*cobra.Command, error) { + cmd := topLevelCmd(context.Background(), "query", "Querying subcommands") + err := b.AddMsgServiceCommands(cmd, cmdDescriptor) + return cmd, err + } + + // bad service + _, err := buildModuleQueryCommand("test", &autocliv1.ServiceCommandDescriptor{Service: "foo"}) + assert.ErrorContains(t, err, "can't find service foo") + + // bad method + _, err = buildModuleQueryCommand("test", &autocliv1.ServiceCommandDescriptor{ + Service: testpb.Query_ServiceDesc.ServiceName, + RpcCommandOptions: []*autocliv1.RpcCommandOptions{{RpcMethod: "bar"}}, + }) + assert.ErrorContains(t, err, "rpc method \"bar\" not found") + + // bad positional field + _, err = buildModuleQueryCommand("test", &autocliv1.ServiceCommandDescriptor{ + Service: testpb.Query_ServiceDesc.ServiceName, + RpcCommandOptions: []*autocliv1.RpcCommandOptions{ + { + RpcMethod: "Echo", + PositionalArgs: []*autocliv1.PositionalArgDescriptor{ + { + ProtoField: "foo", + }, + }, + }, + }, + }) + assert.ErrorContains(t, err, "can't find field foo") + + // bad flag field + _, err = buildModuleQueryCommand("test", &autocliv1.ServiceCommandDescriptor{ + Service: testpb.Query_ServiceDesc.ServiceName, + RpcCommandOptions: []*autocliv1.RpcCommandOptions{ + { + RpcMethod: "Echo", + FlagOptions: map[string]*autocliv1.FlagOptions{ + "baz": {}, + }, + }, + }, + }) + assert.ErrorContains(t, err, "can't find field baz") +} + +func TestDurationMarshal(t *testing.T) { + fixture := initFixture(t) + + out, err := runCmd(fixture, buildModuleQueryCommand, "echo", "1", "abc", "--duration", "1s") + assert.NilError(t, err) + assert.Assert(t, strings.Contains(out.String(), "duration: 1s")) +} diff --git a/connect/internal/autocli/testdata/flatten-output.golden b/connect/internal/autocli/testdata/flatten-output.golden new file mode 100644 index 00000000..7b19e08d --- /dev/null +++ b/connect/internal/autocli/testdata/flatten-output.golden @@ -0,0 +1 @@ +{"body":{"messages":[{"@type":"/cosmos.bank.v1beta1.MsgUpdateParams","authority":"cosmos1y74p8wyy4enfhfn342njve6cjmj5c8dtl6emdk","params":{"send_enabled":[{"denom":"stake","enabled":true}],"default_send_enabled":true}}],"memo":"","timeout_height":"0","unordered":false,"timeout_timestamp":null,"extension_options":[],"non_critical_extension_options":[]},"auth_info":{"signer_infos":[],"fee":{"amount":[],"gas_limit":"200000","payer":"","granter":""},"tip":null},"signatures":[]} diff --git a/connect/internal/autocli/testdata/help-deprecated.golden b/connect/internal/autocli/testdata/help-deprecated.golden new file mode 100644 index 00000000..94586620 --- /dev/null +++ b/connect/internal/autocli/testdata/help-deprecated.golden @@ -0,0 +1,50 @@ +Command "echo" is deprecated, don't use this +Execute the Echo RPC method + +Usage: + test deprecatedecho echo [flags] + +Flags: + --a-bool + --a-coin cosmos.base.v1beta1.Coin + --a-consensus-address account address or key name + --a-message testpb.AMessage (json) + --a-validator-address account address or key name + --an-address account address or key name + --an-enum Enum (unspecified | one | two | five | neg-three) (default unspecified) + --bools bools (default []) + --bz binary + --coins cosmos.base.v1beta1.Coin (repeated) + --deprecated-field string + --duration duration + --durations duration (repeated) + --enums Enum (unspecified | one | two | five | neg-three) (repeated) + --grpc-addr string the gRPC endpoint to use for this chain + --grpc-insecure allow gRPC over insecure channels, if not the server must use TLS + --height int Use a specific height to query state at (this can error if the node is pruning state) + -h, --help help for echo + --hidden-bool + --i32 int32 + --i64 int + --map-string-coin map[string]cosmos.base.v1beta1.Coin + --map-string-string stringToString (default []) + --map-string-uint32 stringToUint32 + --no-indent Do not indent JSON output + --node string : to CometBFT RPC interface for this chain (default "tcp://localhost:26657") + -o, --output string Output format (text|json) (default "text") + --page-count-total + --page-key binary + --page-limit uint + --page-offset uint + --page-reverse + --positional1 int32 + --positional2 string + --positional3-varargs cosmos.base.v1beta1.Coin (repeated) + --shorthand-deprecated-field string + --some-messages testpb.AMessage (json) (repeated) + --str string + --strings strings + --timestamp timestamp (RFC 3339) + --u32 uint32 + --u64 uint + --uints uints (default []) diff --git a/connect/internal/autocli/testdata/help-echo-msg.golden b/connect/internal/autocli/testdata/help-echo-msg.golden new file mode 100644 index 00000000..0761494e --- /dev/null +++ b/connect/internal/autocli/testdata/help-echo-msg.golden @@ -0,0 +1,34 @@ +Send coins from one account to another + +Usage: + test send [flags] + +Flags: + -a, --account-number uint The account number of the signing account (offline mode only) + --aux Generate aux signer data instead of sending a tx + -b, --broadcast-mode string Transaction broadcasting mode (sync|async) (default "sync") + --chain-id string The network chain ID + --dry-run ignore the --gas flag and perform a simulation of a transaction, but don't broadcast it (when enabled, the local Keybase is not accessible) + --fee-granter string Fee granter grants fees for the transaction + --fee-payer string Fee payer pays fees for the transaction instead of deducting from the signer + --fees string Fees to pay along with transaction; eg: 10uatom + --from string Name or address of private key with which to sign + --gas string gas limit to set per-transaction; set to "auto" to calculate sufficient gas automatically. Note: "auto" option doesn't always report accurate results. Set a valid coin value to adjust the result. Can be used instead of "fees". (default 200000) + --gas-adjustment float adjustment factor to be multiplied against the estimate returned by the tx simulation; if the gas limit is set manually this flag is ignored (default 1) + --gas-prices string Determine the transaction fee by multiplying max gas units by gas prices (e.g. 0.1uatom), rounding up to nearest denom unit + --generate-only Build an unsigned transaction and write it to STDOUT (when enabled, the local Keybase only accessed when providing a key name) + -h, --help help for send + --home string home directory + --keyring-backend string Select keyring's backend (os|file|kwallet|pass|test|memory) (default "os") + --keyring-dir string The client Keyring directory; if omitted, the default 'home' directory will be used + --ledger Use a connected Ledger device + --node string : to CometBFT rpc interface for this chain (default "tcp://localhost:26657") + --note string Note to add a description to the transaction (previously --memo) + --offline Offline mode (does not allow any online functionality) + -o, --output string Output format (text|json) (default "json") + -s, --sequence uint The sequence number of the signing account (offline mode only) + --sign-mode string Choose sign mode (direct|amino-json|direct-aux|textual), this is an advanced feature + --timeout-timestamp int Set a block timeout timestamp to prevent the tx from being committed past a certain time + --tip string Tip is the amount that is going to be transferred to the fee payer on the target chain. This flag is only valid when used with --aux, and is ignored if the target chain didn't enable the TipDecorator + --unordered Enable unordered transaction delivery; must be used in conjunction with --timeout-timestamp + -y, --yes Skip tx broadcasting prompt confirmation diff --git a/connect/internal/autocli/testdata/help-echo.golden b/connect/internal/autocli/testdata/help-echo.golden new file mode 100644 index 00000000..2b3fe024 --- /dev/null +++ b/connect/internal/autocli/testdata/help-echo.golden @@ -0,0 +1,52 @@ +echo echos the value provided by the user as a proto JSON object with populated with the provided fields and positional arguments + +Usage: + test echo [pos1] [pos2] [pos3...] [flags] + +Aliases: + echo, e + +Examples: +echo 1 abc {} + +Flags: + --a-bool + --a-coin cosmos.base.v1beta1.Coin some random coin + --a-consensus-address account address or key name + --a-message testpb.AMessage (json) + --a-validator-address account address or key name + --an-address account address or key name + --an-enum Enum (unspecified | one | two | five | neg-three) (default unspecified) + --bools bools (default []) + --bz binary some bytes + --coins cosmos.base.v1beta1.Coin (repeated) + --deprecated-field string (DEPRECATED: don't use this) + --duration duration some random duration + --durations duration (repeated) + --enums Enum (unspecified | one | two | five | neg-three) (repeated) + --grpc-addr string the gRPC endpoint to use for this chain + --grpc-insecure allow gRPC over insecure channels, if not the server must use TLS + --height int Use a specific height to query state at (this can error if the node is pruning state) + -h, --help help for echo + --i32 int32 some random int32 + --i64 int + --map-string-coin map[string]cosmos.base.v1beta1.Coin some map of string to coin + --map-string-string stringToString some map of string to string (default []) + --map-string-uint32 stringToUint32 some map of string to int32 + --no-indent Do not indent JSON output + --node string : to CometBFT RPC interface for this chain (default "tcp://localhost:26657") + -o, --output string Output format (text|json) (default "text") + --page-count-total + --page-key binary + --page-limit uint + --page-offset uint + --page-reverse + -s, --shorthand-deprecated-field string (DEPRECATED: bad idea) + --some-messages testpb.AMessage (json) (repeated) + --str string + --strings strings + --timestamp timestamp (RFC 3339) + --u64 uint some random uint64 + -u, --uint32 uint32 some random uint32 + --uints uints (default []) + -v, --version version for echo diff --git a/connect/internal/autocli/testdata/help-skip.golden b/connect/internal/autocli/testdata/help-skip.golden new file mode 100644 index 00000000..a85dbef6 --- /dev/null +++ b/connect/internal/autocli/testdata/help-skip.golden @@ -0,0 +1,7 @@ +Querying commands for the testpb.Query service + +Usage: + test skipecho [flags] + +Flags: + -h, --help help for skipecho diff --git a/connect/internal/autocli/testdata/help-toplevel-msg.golden b/connect/internal/autocli/testdata/help-toplevel-msg.golden new file mode 100644 index 00000000..f4afbd99 --- /dev/null +++ b/connect/internal/autocli/testdata/help-toplevel-msg.golden @@ -0,0 +1,19 @@ +Transactions commands for the test module + +Usage: + test [flags] + test [command] + +Available Commands: + burn Execute the Burn RPC method + completion Generate the autocompletion script for the specified shell + help Help about any command + multi-send Execute the MultiSend RPC method + send Send coins from one account to another + set-send-enabled Execute the SetSendEnabled RPC method + update-params Execute the UpdateParams RPC method + +Flags: + -h, --help help for test + +Use "test [command] --help" for more information about a command. diff --git a/connect/internal/autocli/testdata/help-toplevel.golden b/connect/internal/autocli/testdata/help-toplevel.golden new file mode 100644 index 00000000..7bab88a5 --- /dev/null +++ b/connect/internal/autocli/testdata/help-toplevel.golden @@ -0,0 +1,17 @@ +Querying commands for the test module + +Usage: + test [flags] + test [command] + +Available Commands: + completion Generate the autocompletion script for the specified shell + deprecatedecho Querying commands for the testpb.Query service + echo echo echos the value provided by the user + help Help about any command + skipecho Querying commands for the testpb.Query service + +Flags: + -h, --help help for test + +Use "test [command] --help" for more information about a command. diff --git a/connect/internal/autocli/testdata/help.golden b/connect/internal/autocli/testdata/help.golden new file mode 100644 index 00000000..c8fe6bbf --- /dev/null +++ b/connect/internal/autocli/testdata/help.golden @@ -0,0 +1,40 @@ +echo echos the value provided by the user as a proto JSON object with populated with the provided fields and positional arguments + +Usage: + test echo [pos1] [pos2] [pos3...] [flags] + +Aliases: + echo, e + +Examples: +echo 1 abc {} + +Flags: + --a-bool + --a-coin cosmos.base.v1beta1.Coin (json) + --a-message testpb.AMessage (json) + --an-address bech32 account address key name + --an-enum Enum (unspecified | one | two | five | neg-three) (default unspecified) + --bools bools (default []) + --bz bytesBase64 + --deprecated-field string (DEPRECATED: don't use this) + --duration duration + --durations duration (repeated) + --enums Enum (unspecified | one | two | five | neg-three) (repeated) + -h, --help help for echo + --i32 int32 some random int32 + --i64 int + --page-count-total + --page-key bytesBase64 + --page-limit uint + --page-offset uint + --page-reverse + -s, --shorthand-deprecated-field string (DEPRECATED: bad idea) + --some-messages testpb.AMessage (json) (repeated) + --str string + --strings strings + --timestamp timestamp (RFC 3339) + --u64 uint[=5] some random uint64 + -u, --uint32 uint32 some random uint32 + --uints uints (default []) + -v, --version version for echo diff --git a/connect/internal/autocli/testdata/msg-output.golden b/connect/internal/autocli/testdata/msg-output.golden new file mode 100644 index 00000000..0e171b2b --- /dev/null +++ b/connect/internal/autocli/testdata/msg-output.golden @@ -0,0 +1 @@ +{"body":{"messages":[{"@type":"/cosmos.bank.v1beta1.MsgSend","from_address":"cosmos1y74p8wyy4enfhfn342njve6cjmj5c8dtl6emdk","to_address":"cosmos1y74p8wyy4enfhfn342njve6cjmj5c8dtl6emdk","amount":[{"denom":"foo","amount":"1"}]}],"memo":"","timeout_height":"0","unordered":false,"timeout_timestamp":null,"extension_options":[],"non_critical_extension_options":[]},"auth_info":{"signer_infos":[],"fee":{"amount":[],"gas_limit":"200000","payer":"","granter":""},"tip":null},"signatures":[]} \ No newline at end of file diff --git a/connect/internal/autocli/testdata/some_message.json b/connect/internal/autocli/testdata/some_message.json new file mode 100644 index 00000000..795d59a9 --- /dev/null +++ b/connect/internal/autocli/testdata/some_message.json @@ -0,0 +1 @@ +{"bar":"baz"} \ No newline at end of file diff --git a/connect/internal/autocli/util.go b/connect/internal/autocli/util.go new file mode 100644 index 00000000..0343e870 --- /dev/null +++ b/connect/internal/autocli/util.go @@ -0,0 +1,50 @@ +package autocli + +import ( + "context" + "strings" + + "github.com/spf13/cobra" + "google.golang.org/protobuf/reflect/protoreflect" + + "github.com/ignite/apps/connect/internal/internal/strcase" +) + +// findSubCommand finds a sub-command of the provided command whose Use +// string is or begins with the provided subCmdName. +// It verifies the command's aliases as well. +func findSubCommand(cmd *cobra.Command, subCmdName string) *cobra.Command { + for _, subCmd := range cmd.Commands() { + use := subCmd.Use + if use == subCmdName || strings.HasPrefix(use, subCmdName+" ") { + return subCmd + } + + for _, alias := range subCmd.Aliases { + if alias == subCmdName || strings.HasPrefix(alias, subCmdName+" ") { + return subCmd + } + } + } + return nil +} + +// topLevelCmd creates a new top-level command with the provided name and +// description. The command will have DisableFlagParsing set to false and +// SuggestionsMinimumDistance set to 2. +func topLevelCmd(ctx context.Context, use, short string) *cobra.Command { + cmd := &cobra.Command{ + Use: use, + Short: short, + DisableFlagParsing: false, + SuggestionsMinimumDistance: 2, + RunE: validateCmd, + } + cmd.SetContext(ctx) + + return cmd +} + +func protoNameToCliName(name protoreflect.Name) string { + return strcase.ToKebab(string(name)) +} diff --git a/connect/internal/autocli/validate.go b/connect/internal/autocli/validate.go new file mode 100644 index 00000000..3256aeb8 --- /dev/null +++ b/connect/internal/autocli/validate.go @@ -0,0 +1,60 @@ +package autocli + +import ( + "errors" + "fmt" + "strings" + + "github.com/spf13/cobra" +) + +// NOTE: this was copied from client/cmd.go to avoid introducing a dependency +// on the v1 client package. + +// validateCmd returns unknown command error or Help display if help flag set +func validateCmd(cmd *cobra.Command, args []string) error { + var unknownCmd string + var skipNext bool + + for _, arg := range args { + // search for help flag + if arg == "--help" || arg == "-h" { + return cmd.Help() + } + + // check if the current arg is a flag + switch { + case len(arg) > 0 && (arg[0] == '-'): + // the next arg should be skipped if the current arg is a + // flag and does not use "=" to assign the flag's value + if !strings.Contains(arg, "=") { + skipNext = true + } else { + skipNext = false + } + case skipNext: + // skip current arg + skipNext = false + case unknownCmd == "": + // unknown command found + // continue searching for help flag + unknownCmd = arg + } + } + + // return the help screen if no unknown command is found + if unknownCmd != "" { + err := fmt.Sprintf("unknown command \"%s\" for \"%s\"", unknownCmd, cmd.CalledAs()) + + // build suggestions for unknown argument + if suggestions := cmd.SuggestionsFor(unknownCmd); len(suggestions) > 0 { + err += "\n\nDid you mean this?\n" + for _, s := range suggestions { + err += fmt.Sprintf("\t%v\n", s) + } + } + return errors.New(err) + } + + return cmd.Help() +} diff --git a/connect/internal/broadcast/broadcaster.go b/connect/internal/broadcast/broadcaster.go new file mode 100644 index 00000000..bcee034b --- /dev/null +++ b/connect/internal/broadcast/broadcaster.go @@ -0,0 +1,15 @@ +package broadcast + +import "context" + +// Broadcaster defines an interface for broadcasting transactions to the consensus engine. +type Broadcaster interface { + // Broadcast sends a transaction to the network and returns the result. + // + // It returns a byte slice containing the formatted result that will be + // passed to the output writer, and an error if the broadcast failed. + Broadcast(ctx context.Context, txBytes []byte) ([]byte, error) + + // Consensus returns the consensus engine identifier for this Broadcaster. + Consensus() string +} diff --git a/connect/internal/broadcast/comet/client_conn.go b/connect/internal/broadcast/comet/client_conn.go new file mode 100644 index 00000000..3ae20f6f --- /dev/null +++ b/connect/internal/broadcast/comet/client_conn.go @@ -0,0 +1,146 @@ +package comet + +import ( + "context" + "errors" + "strconv" + + abci "github.com/cometbft/cometbft/abci/types" + rpcclient "github.com/cometbft/cometbft/rpc/client" + gogogrpc "github.com/cosmos/gogoproto/grpc" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/encoding" + "google.golang.org/grpc/metadata" + "google.golang.org/grpc/status" + + errorsmod "cosmossdk.io/errors" + + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" +) + +const grpcBlockHeightHeader = "x-cosmos-block-height" + +var ( + _ gogogrpc.ClientConn = &CometBFTBroadcaster{} + _ grpc.ClientConnInterface = &CometBFTBroadcaster{} +) + +func (c *CometBFTBroadcaster) NewStream(_ context.Context, _ *grpc.StreamDesc, _ string, _ ...grpc.CallOption) (grpc.ClientStream, error) { + return nil, errors.New("not implemented") +} + +// Invoke implements the gRPC ClientConn interface by forwarding the RPC call to CometBFT's ABCI Query. +// It marshals the request, sends it as an ABCI query, and unmarshals the response. +func (c *CometBFTBroadcaster) Invoke(ctx context.Context, method string, req, reply interface{}, opts ...grpc.CallOption) (err error) { + reqBz, err := c.getRPCCodec().Marshal(req) + if err != nil { + return err + } + + // parse height header + md, _ := metadata.FromOutgoingContext(ctx) + var height int64 + if heights := md.Get(grpcBlockHeightHeader); len(heights) > 0 { + height, err = strconv.ParseInt(heights[0], 10, 64) + if err != nil { + return err + } + if height < 0 { + return errorsmod.Wrapf( + sdkerrors.ErrInvalidRequest, + "client.Context.Invoke: height (%d) from %q must be >= 0", height, grpcBlockHeightHeader) + } + } + + abciR := abci.RequestQuery{ + Path: method, + Data: reqBz, + Height: height, + } + + res, err := c.queryABCI(ctx, abciR) + if err != nil { + return err + } + + err = c.getRPCCodec().Unmarshal(res.Value, reply) + if err != nil { + return err + } + + // Create header metadata. For now the headers contain: + // - block height + // We then parse all the call options, if the call option is a + // HeaderCallOption, then we manually set the value of that header to the + // metadata. + md = metadata.Pairs(grpcBlockHeightHeader, strconv.FormatInt(res.Height, 10)) + for _, callOpt := range opts { + header, ok := callOpt.(grpc.HeaderCallOption) + if !ok { + continue + } + + *header.HeaderAddr = md + } + + if c.cdc.InterfaceRegistry() != nil { + return types.UnpackInterfaces(reply, c.cdc.InterfaceRegistry()) + } + + return nil +} + +// queryABCI performs an ABCI query request to the CometBFT RPC client. +// If the RPC query fails or returns a non-OK response, it will return an error. +// The response is converted from ABCI error codes to gRPC status errors. +func (c *CometBFTBroadcaster) queryABCI(ctx context.Context, req abci.RequestQuery) (abci.ResponseQuery, error) { + opts := rpcclient.ABCIQueryOptions{ + Height: req.Height, + Prove: req.Prove, + } + + result, err := c.rpcClient.ABCIQueryWithOptions(ctx, req.Path, req.Data, opts) + if err != nil { + return abci.ResponseQuery{}, err + } + + if !result.Response.IsOK() { + return abci.ResponseQuery{}, sdkErrorToGRPCError(result.Response) + } + + return result.Response, nil +} + +// sdkErrorToGRPCError converts an ABCI query response error code to an appropriate gRPC status error. +// It maps common SDK error codes to their gRPC equivalents: +// - ErrInvalidRequest -> InvalidArgument +// - ErrUnauthorized -> Unauthenticated +// - ErrKeyNotFound -> NotFound +// Any other error codes are mapped to Unknown. +func sdkErrorToGRPCError(resp abci.ResponseQuery) error { + switch resp.Code { + case sdkerrors.ErrInvalidRequest.ABCICode(): + return status.Error(codes.InvalidArgument, resp.Log) + case sdkerrors.ErrUnauthorized.ABCICode(): + return status.Error(codes.Unauthenticated, resp.Log) + case sdkerrors.ErrKeyNotFound.ABCICode(): + return status.Error(codes.NotFound, resp.Log) + default: + return status.Error(codes.Unknown, resp.Log) + } +} + +// getRPCCodec returns the gRPC codec for the CometBFT broadcaster. +// If the broadcaster's codec implements GRPCCodecProvider, it returns its gRPC codec. +// Otherwise, it creates a new ProtoCodec with the broadcaster's interface registry and returns its gRPC codec. +func (c *CometBFTBroadcaster) getRPCCodec() encoding.Codec { + cdc, ok := c.cdc.(codec.GRPCCodecProvider) + if !ok { + return codec.NewProtoCodec(c.cdc.InterfaceRegistry()).GRPCCodec() + } + + return cdc.GRPCCodec() +} diff --git a/connect/internal/broadcast/comet/comet.go b/connect/internal/broadcast/comet/comet.go new file mode 100644 index 00000000..3ce9cfda --- /dev/null +++ b/connect/internal/broadcast/comet/comet.go @@ -0,0 +1,199 @@ +package comet + +import ( + "context" + "encoding/json" + "errors" + "fmt" + "strings" + + "github.com/cometbft/cometbft/mempool" + rpcclient "github.com/cometbft/cometbft/rpc/client" + rpchttp "github.com/cometbft/cometbft/rpc/client/http" + coretypes "github.com/cometbft/cometbft/rpc/core/types" + cmttypes "github.com/cometbft/cometbft/types" + + apiacbci "cosmossdk.io/api/cosmos/base/abci/v1beta1" + "github.com/ignite/apps/connect/internal/broadcast" + + "github.com/cosmos/cosmos-sdk/codec" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" +) + +const ( + // BroadcastSync defines a tx broadcasting mode where the client waits for + // a CheckTx execution response only. + BroadcastSync = "sync" + // BroadcastAsync defines a tx broadcasting mode where the client returns + // immediately. + BroadcastAsync = "async" + + // cometBftConsensus is the identifier for the CometBFT consensus engine. + cometBFTConsensus = "comet" +) + +// CometRPC defines the interface of a CometBFT RPC client needed for +// queries and transaction handling. +type CometRPC interface { + rpcclient.ABCIClient + + Validators(ctx context.Context, height *int64, page, perPage *int) (*coretypes.ResultValidators, error) + Status(context.Context) (*coretypes.ResultStatus, error) + Block(ctx context.Context, height *int64) (*coretypes.ResultBlock, error) + BlockByHash(ctx context.Context, hash []byte) (*coretypes.ResultBlock, error) + BlockResults(ctx context.Context, height *int64) (*coretypes.ResultBlockResults, error) + BlockchainInfo(ctx context.Context, minHeight, maxHeight int64) (*coretypes.ResultBlockchainInfo, error) + Commit(ctx context.Context, height *int64) (*coretypes.ResultCommit, error) + Tx(ctx context.Context, hash []byte, prove bool) (*coretypes.ResultTx, error) + TxSearch( + ctx context.Context, + query string, + prove bool, + page, perPage *int, + orderBy string, + ) (*coretypes.ResultTxSearch, error) + BlockSearch( + ctx context.Context, + query string, + page, perPage *int, + orderBy string, + ) (*coretypes.ResultBlockSearch, error) +} + +var _ broadcast.Broadcaster = &CometBFTBroadcaster{} + +// CometBFTBroadcaster implements the Broadcaster interface for CometBFT consensus engine. +type CometBFTBroadcaster struct { + rpcClient CometRPC + mode string + cdc codec.Codec +} + +// NewCometBFTBroadcaster creates a new CometBFTBroadcaster. +func NewCometBFTBroadcaster(rpcURL, mode string, cdc codec.Codec) (*CometBFTBroadcaster, error) { + if cdc == nil { + return nil, errors.New("codec can't be nil") + } + + if mode == "" { + mode = BroadcastSync + } + + rpcClient, err := rpchttp.New(rpcURL, "/websocket") + if err != nil { + return nil, fmt.Errorf("failed to create CometBft RPC client: %w", err) + } + + return &CometBFTBroadcaster{ + rpcClient: rpcClient, + mode: mode, + cdc: cdc, + }, nil +} + +// Consensus returns the consensus engine name used by the broadcaster. +// It always returns "comet" for CometBFTBroadcaster. +func (c *CometBFTBroadcaster) Consensus() string { + return cometBFTConsensus +} + +// Broadcast sends a transaction to the network and returns the result. +// returns a byte slice containing the JSON-encoded result and an error if the broadcast failed. +func (c *CometBFTBroadcaster) Broadcast(ctx context.Context, txBytes []byte) ([]byte, error) { + if c.cdc == nil { + return []byte{}, fmt.Errorf("JSON codec is not initialized") + } + + var broadcastFunc func(ctx context.Context, tx cmttypes.Tx) (*coretypes.ResultBroadcastTx, error) + switch c.mode { + case BroadcastSync: + broadcastFunc = c.rpcClient.BroadcastTxSync + case BroadcastAsync: + broadcastFunc = c.rpcClient.BroadcastTxAsync + default: + return []byte{}, fmt.Errorf("unknown broadcast mode: %s", c.mode) + } + + res, err := c.broadcast(ctx, txBytes, broadcastFunc) + if err != nil { + return []byte{}, err + } + + return c.cdc.MarshalJSON(res) +} + +// broadcast sends a transaction to the CometBFT network using the provided function. +func (c *CometBFTBroadcaster) broadcast(ctx context.Context, txBytes []byte, + fn func(ctx context.Context, tx cmttypes.Tx) (*coretypes.ResultBroadcastTx, error), +) (*apiacbci.TxResponse, error) { + res, err := fn(ctx, txBytes) + if errRes := checkCometError(err, txBytes); errRes != nil { + return errRes, nil + } + + if res == nil { + return nil, err + } + + parsedLogs, _ := parseABCILogs(res.Log) + return &apiacbci.TxResponse{ + Code: res.Code, + Codespace: res.Codespace, + Data: res.Data.String(), + RawLog: res.Log, + Logs: parsedLogs, + Txhash: res.Hash.String(), + }, err +} + +// checkCometError checks for errors returned by the CometBFT network and returns an appropriate TxResponse. +// It extracts error information and constructs a TxResponse with the error details. +func checkCometError(err error, tx cmttypes.Tx) *apiacbci.TxResponse { + if err == nil { + return nil + } + + errStr := strings.ToLower(err.Error()) + txHash := fmt.Sprintf("%X", tx.Hash()) + + switch { + case strings.Contains(errStr, strings.ToLower(mempool.ErrTxInCache.Error())) || + strings.Contains(errStr, strings.ToLower(sdkerrors.ErrTxInMempoolCache.Error())): + return &apiacbci.TxResponse{ + Code: sdkerrors.ErrTxInMempoolCache.ABCICode(), + Codespace: sdkerrors.ErrTxInMempoolCache.Codespace(), + Txhash: txHash, + } + + case strings.Contains(errStr, "mempool is full"): + return &apiacbci.TxResponse{ + Code: sdkerrors.ErrMempoolIsFull.ABCICode(), + Codespace: sdkerrors.ErrMempoolIsFull.Codespace(), + Txhash: txHash, + } + + case strings.Contains(errStr, "tx too large"): + return &apiacbci.TxResponse{ + Code: sdkerrors.ErrTxTooLarge.ABCICode(), + Codespace: sdkerrors.ErrTxTooLarge.Codespace(), + Txhash: txHash, + } + + case strings.Contains(errStr, "no signatures supplied"): + return &apiacbci.TxResponse{ + Code: sdkerrors.ErrNoSignatures.ABCICode(), + Codespace: sdkerrors.ErrNoSignatures.Codespace(), + Txhash: txHash, + } + + default: + return nil + } +} + +// parseABCILogs attempts to parse a stringified ABCI tx log into a slice of +// ABCIMessageLog types. It returns an error upon JSON decoding failure. +func parseABCILogs(logs string) (res []*apiacbci.ABCIMessageLog, err error) { + err = json.Unmarshal([]byte(logs), &res) + return res, err +} diff --git a/connect/internal/broadcast/comet/comet_test.go b/connect/internal/broadcast/comet/comet_test.go new file mode 100644 index 00000000..98bacf05 --- /dev/null +++ b/connect/internal/broadcast/comet/comet_test.go @@ -0,0 +1,149 @@ +package comet + +import ( + "context" + "errors" + "testing" + + "github.com/cometbft/cometbft/mempool" + coretypes "github.com/cometbft/cometbft/rpc/core/types" + "github.com/stretchr/testify/require" + "go.uber.org/mock/gomock" + + apiacbci "cosmossdk.io/api/cosmos/base/abci/v1beta1" + mockrpc "github.com/ignite/apps/connect/internal/broadcast/comet/testutil" + + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/testutil" +) + +var cdc = testutil.CodecOptions{}.NewCodec() + +func TestNewCometBftBroadcaster(t *testing.T) { + tests := []struct { + name string + cdc codec.Codec + mode string + want *CometBFTBroadcaster + wantErr bool + }{ + { + name: "constructor", + mode: BroadcastSync, + cdc: cdc, + want: &CometBFTBroadcaster{ + mode: BroadcastSync, + cdc: cdc, + }, + }, + { + name: "nil codec", + mode: BroadcastSync, + cdc: nil, + wantErr: true, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := NewCometBFTBroadcaster("localhost:26657", tt.mode, tt.cdc) + if tt.wantErr { + require.Error(t, err) + require.Nil(t, got) + } else { + require.Equal(t, got.mode, tt.want.mode) + require.Equal(t, got.cdc, tt.want.cdc) + } + }) + } +} + +func TestCometBftBroadcaster_Broadcast(t *testing.T) { + ctrl := gomock.NewController(t) + cometMock := mockrpc.NewMockCometRPC(ctrl) + c := CometBFTBroadcaster{ + rpcClient: cometMock, + mode: BroadcastSync, + cdc: cdc, + } + tests := []struct { + name string + mode string + setupMock func(*mockrpc.MockCometRPC) + wantErr bool + }{ + { + name: "sync", + mode: BroadcastSync, + setupMock: func(m *mockrpc.MockCometRPC) { + m.EXPECT().BroadcastTxSync(context.Background(), gomock.Any()).Return(&coretypes.ResultBroadcastTx{ + Code: 0, + Data: []byte{}, + Log: "", + Codespace: "", + Hash: []byte("%�����\u0010\n�T�\u0017\u0016�N^H[5�\u0006}�n�w�/Vi� "), + }, nil) + }, + }, + { + name: "async", + mode: BroadcastAsync, + setupMock: func(m *mockrpc.MockCometRPC) { + m.EXPECT().BroadcastTxAsync(context.Background(), gomock.Any()).Return(&coretypes.ResultBroadcastTx{ + Code: 0, + Data: []byte{}, + Log: "", + Codespace: "", + Hash: []byte("%�����\u0010\n�T�\u0017\u0016�N^H[5�\u0006}�n�w�/Vi� "), + }, nil) + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + c.mode = tt.mode + tt.setupMock(cometMock) + got, err := c.Broadcast(context.Background(), []byte{}) + if tt.wantErr { + require.Error(t, err) + } else { + require.NotNil(t, got) + } + }) + } +} + +func Test_checkCometError(t *testing.T) { + tests := []struct { + name string + err error + want *apiacbci.TxResponse + }{ + { + name: "tx already in cache", + err: errors.New("tx already exists in cache"), + want: &apiacbci.TxResponse{ + Code: 19, + }, + }, + { + name: "mempool is full", + err: mempool.ErrMempoolIsFull{}, + want: &apiacbci.TxResponse{ + Code: 20, + }, + }, + { + name: "tx too large", + err: mempool.ErrTxTooLarge{}, + want: &apiacbci.TxResponse{ + Code: 21, + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got := checkCometError(tt.err, []byte{}) + require.Equal(t, got.Code, tt.want.Code) + }) + } +} diff --git a/connect/internal/broadcast/comet/testutil/comet_mock.go b/connect/internal/broadcast/comet/testutil/comet_mock.go new file mode 100644 index 00000000..75cdc50a --- /dev/null +++ b/connect/internal/broadcast/comet/testutil/comet_mock.go @@ -0,0 +1,285 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: client/v2/broadcast/comet/comet.go +// +// Generated by this command: +// +// mockgen -source=client/v2/broadcast/comet/comet.go -package testutil -destination client/v2/broadcast/comet/testutil/comet_mock.go +// + +// Package testutil is a generated GoMock package. +package testutil + +import ( + context "context" + reflect "reflect" + + bytes "github.com/cometbft/cometbft/libs/bytes" + client "github.com/cometbft/cometbft/rpc/client" + coretypes "github.com/cometbft/cometbft/rpc/core/types" + types "github.com/cometbft/cometbft/types" + gomock "go.uber.org/mock/gomock" +) + +// MockCometRPC is a mock of CometRPC interface. +type MockCometRPC struct { + ctrl *gomock.Controller + recorder *MockCometRPCMockRecorder + isgomock struct{} +} + +// MockCometRPCMockRecorder is the mock recorder for MockCometRPC. +type MockCometRPCMockRecorder struct { + mock *MockCometRPC +} + +// NewMockCometRPC creates a new mock instance. +func NewMockCometRPC(ctrl *gomock.Controller) *MockCometRPC { + mock := &MockCometRPC{ctrl: ctrl} + mock.recorder = &MockCometRPCMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockCometRPC) EXPECT() *MockCometRPCMockRecorder { + return m.recorder +} + +// ABCIInfo mocks base method. +func (m *MockCometRPC) ABCIInfo(ctx context.Context) (*coretypes.ResultABCIInfo, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ABCIInfo", ctx) + ret0, _ := ret[0].(*coretypes.ResultABCIInfo) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ABCIInfo indicates an expected call of ABCIInfo. +func (mr *MockCometRPCMockRecorder) ABCIInfo(ctx any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ABCIInfo", reflect.TypeOf((*MockCometRPC)(nil).ABCIInfo), ctx) +} + +// ABCIQuery mocks base method. +func (m *MockCometRPC) ABCIQuery(ctx context.Context, path string, data bytes.HexBytes) (*coretypes.ResultABCIQuery, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ABCIQuery", ctx, path, data) + ret0, _ := ret[0].(*coretypes.ResultABCIQuery) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ABCIQuery indicates an expected call of ABCIQuery. +func (mr *MockCometRPCMockRecorder) ABCIQuery(ctx, path, data any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ABCIQuery", reflect.TypeOf((*MockCometRPC)(nil).ABCIQuery), ctx, path, data) +} + +// ABCIQueryWithOptions mocks base method. +func (m *MockCometRPC) ABCIQueryWithOptions(ctx context.Context, path string, data bytes.HexBytes, opts client.ABCIQueryOptions) (*coretypes.ResultABCIQuery, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ABCIQueryWithOptions", ctx, path, data, opts) + ret0, _ := ret[0].(*coretypes.ResultABCIQuery) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ABCIQueryWithOptions indicates an expected call of ABCIQueryWithOptions. +func (mr *MockCometRPCMockRecorder) ABCIQueryWithOptions(ctx, path, data, opts any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ABCIQueryWithOptions", reflect.TypeOf((*MockCometRPC)(nil).ABCIQueryWithOptions), ctx, path, data, opts) +} + +// Block mocks base method. +func (m *MockCometRPC) Block(ctx context.Context, height *int64) (*coretypes.ResultBlock, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Block", ctx, height) + ret0, _ := ret[0].(*coretypes.ResultBlock) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Block indicates an expected call of Block. +func (mr *MockCometRPCMockRecorder) Block(ctx, height any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Block", reflect.TypeOf((*MockCometRPC)(nil).Block), ctx, height) +} + +// BlockByHash mocks base method. +func (m *MockCometRPC) BlockByHash(ctx context.Context, hash []byte) (*coretypes.ResultBlock, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "BlockByHash", ctx, hash) + ret0, _ := ret[0].(*coretypes.ResultBlock) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// BlockByHash indicates an expected call of BlockByHash. +func (mr *MockCometRPCMockRecorder) BlockByHash(ctx, hash any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BlockByHash", reflect.TypeOf((*MockCometRPC)(nil).BlockByHash), ctx, hash) +} + +// BlockResults mocks base method. +func (m *MockCometRPC) BlockResults(ctx context.Context, height *int64) (*coretypes.ResultBlockResults, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "BlockResults", ctx, height) + ret0, _ := ret[0].(*coretypes.ResultBlockResults) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// BlockResults indicates an expected call of BlockResults. +func (mr *MockCometRPCMockRecorder) BlockResults(ctx, height any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BlockResults", reflect.TypeOf((*MockCometRPC)(nil).BlockResults), ctx, height) +} + +// BlockSearch mocks base method. +func (m *MockCometRPC) BlockSearch(ctx context.Context, query string, page, perPage *int, orderBy string) (*coretypes.ResultBlockSearch, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "BlockSearch", ctx, query, page, perPage, orderBy) + ret0, _ := ret[0].(*coretypes.ResultBlockSearch) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// BlockSearch indicates an expected call of BlockSearch. +func (mr *MockCometRPCMockRecorder) BlockSearch(ctx, query, page, perPage, orderBy any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BlockSearch", reflect.TypeOf((*MockCometRPC)(nil).BlockSearch), ctx, query, page, perPage, orderBy) +} + +// BlockchainInfo mocks base method. +func (m *MockCometRPC) BlockchainInfo(ctx context.Context, minHeight, maxHeight int64) (*coretypes.ResultBlockchainInfo, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "BlockchainInfo", ctx, minHeight, maxHeight) + ret0, _ := ret[0].(*coretypes.ResultBlockchainInfo) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// BlockchainInfo indicates an expected call of BlockchainInfo. +func (mr *MockCometRPCMockRecorder) BlockchainInfo(ctx, minHeight, maxHeight any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BlockchainInfo", reflect.TypeOf((*MockCometRPC)(nil).BlockchainInfo), ctx, minHeight, maxHeight) +} + +// BroadcastTxAsync mocks base method. +func (m *MockCometRPC) BroadcastTxAsync(ctx context.Context, tx types.Tx) (*coretypes.ResultBroadcastTx, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "BroadcastTxAsync", ctx, tx) + ret0, _ := ret[0].(*coretypes.ResultBroadcastTx) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// BroadcastTxAsync indicates an expected call of BroadcastTxAsync. +func (mr *MockCometRPCMockRecorder) BroadcastTxAsync(ctx, tx any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BroadcastTxAsync", reflect.TypeOf((*MockCometRPC)(nil).BroadcastTxAsync), ctx, tx) +} + +// BroadcastTxCommit mocks base method. +func (m *MockCometRPC) BroadcastTxCommit(ctx context.Context, tx types.Tx) (*coretypes.ResultBroadcastTxCommit, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "BroadcastTxCommit", ctx, tx) + ret0, _ := ret[0].(*coretypes.ResultBroadcastTxCommit) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// BroadcastTxCommit indicates an expected call of BroadcastTxCommit. +func (mr *MockCometRPCMockRecorder) BroadcastTxCommit(ctx, tx any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BroadcastTxCommit", reflect.TypeOf((*MockCometRPC)(nil).BroadcastTxCommit), ctx, tx) +} + +// BroadcastTxSync mocks base method. +func (m *MockCometRPC) BroadcastTxSync(ctx context.Context, tx types.Tx) (*coretypes.ResultBroadcastTx, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "BroadcastTxSync", ctx, tx) + ret0, _ := ret[0].(*coretypes.ResultBroadcastTx) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// BroadcastTxSync indicates an expected call of BroadcastTxSync. +func (mr *MockCometRPCMockRecorder) BroadcastTxSync(ctx, tx any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BroadcastTxSync", reflect.TypeOf((*MockCometRPC)(nil).BroadcastTxSync), ctx, tx) +} + +// Commit mocks base method. +func (m *MockCometRPC) Commit(ctx context.Context, height *int64) (*coretypes.ResultCommit, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Commit", ctx, height) + ret0, _ := ret[0].(*coretypes.ResultCommit) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Commit indicates an expected call of Commit. +func (mr *MockCometRPCMockRecorder) Commit(ctx, height any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Commit", reflect.TypeOf((*MockCometRPC)(nil).Commit), ctx, height) +} + +// Status mocks base method. +func (m *MockCometRPC) Status(arg0 context.Context) (*coretypes.ResultStatus, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Status", arg0) + ret0, _ := ret[0].(*coretypes.ResultStatus) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Status indicates an expected call of Status. +func (mr *MockCometRPCMockRecorder) Status(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Status", reflect.TypeOf((*MockCometRPC)(nil).Status), arg0) +} + +// Tx mocks base method. +func (m *MockCometRPC) Tx(ctx context.Context, hash []byte, prove bool) (*coretypes.ResultTx, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Tx", ctx, hash, prove) + ret0, _ := ret[0].(*coretypes.ResultTx) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Tx indicates an expected call of Tx. +func (mr *MockCometRPCMockRecorder) Tx(ctx, hash, prove any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Tx", reflect.TypeOf((*MockCometRPC)(nil).Tx), ctx, hash, prove) +} + +// TxSearch mocks base method. +func (m *MockCometRPC) TxSearch(ctx context.Context, query string, prove bool, page, perPage *int, orderBy string) (*coretypes.ResultTxSearch, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "TxSearch", ctx, query, prove, page, perPage, orderBy) + ret0, _ := ret[0].(*coretypes.ResultTxSearch) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// TxSearch indicates an expected call of TxSearch. +func (mr *MockCometRPCMockRecorder) TxSearch(ctx, query, prove, page, perPage, orderBy any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "TxSearch", reflect.TypeOf((*MockCometRPC)(nil).TxSearch), ctx, query, prove, page, perPage, orderBy) +} + +// Validators mocks base method. +func (m *MockCometRPC) Validators(ctx context.Context, height *int64, page, perPage *int) (*coretypes.ResultValidators, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Validators", ctx, height, page, perPage) + ret0, _ := ret[0].(*coretypes.ResultValidators) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Validators indicates an expected call of Validators. +func (mr *MockCometRPCMockRecorder) Validators(ctx, height, page, perPage any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Validators", reflect.TypeOf((*MockCometRPC)(nil).Validators), ctx, height, page, perPage) +} diff --git a/connect/internal/context/context.go b/connect/internal/context/context.go new file mode 100644 index 00000000..eb40302b --- /dev/null +++ b/connect/internal/context/context.go @@ -0,0 +1,55 @@ +package context + +import ( + gocontext "context" + "errors" + + "github.com/spf13/pflag" + + apisigning "cosmossdk.io/api/cosmos/tx/signing/v1beta1" + "cosmossdk.io/core/address" + "github.com/ignite/apps/connect/internal/autocli/keyring" + + "github.com/cosmos/cosmos-sdk/codec" +) + +// ContextKey is a key used to store and retrieve Context from a Go context.Context. +var ContextKey contextKey + +// contextKey is an empty struct used as a key type for storing Context in a context.Context. +type contextKey struct{} + +// Context represents the client context used in autocli commands. +// It contains various components needed for command execution. +type Context struct { + Flags *pflag.FlagSet + + AddressCodec address.Codec + ValidatorAddressCodec address.Codec + ConsensusAddressCodec address.Codec + + Cdc codec.Codec + + Keyring keyring.Keyring + + EnabledSignModes []apisigning.SignMode +} + +// SetInContext stores the provided autocli.Context in the given Go context.Context. +// It returns a new context.Context containing the autocli.Context value. +func SetInContext(goCtx gocontext.Context, cliCtx Context) gocontext.Context { + return gocontext.WithValue(goCtx, ContextKey, cliCtx) +} + +// ClientContextFromGoContext returns the autocli.Context from a given Go context. +// It checks if the context contains a valid autocli.Context and returns it. +func ClientContextFromGoContext(ctx gocontext.Context) (*Context, error) { + if c := ctx.Value(ContextKey); c != nil { + cliCtx, ok := c.(Context) + if !ok { + return nil, errors.New("context value is not of type autocli.Context") + } + return &cliCtx, nil + } + return nil, errors.New("context does not contain autocli.Context value") +} diff --git a/connect/internal/helpers/home.go b/connect/internal/helpers/home.go new file mode 100644 index 00000000..af3fc288 --- /dev/null +++ b/connect/internal/helpers/home.go @@ -0,0 +1,48 @@ +package helpers + +import ( + "os" + "path/filepath" + "strings" +) + +// EnvPrefix is the prefix for environment variables that are used by the CLI. +// It should match the one used for viper in the CLI. +var EnvPrefix = "" + +// GetNodeHomeDirectory gets the home directory of the node (where the config is located). +// It parses the home flag if set if the `(PREFIX)_HOME` environment variable if set (and ignores name). +// When no prefix is set, it reads the `NODE_HOME` environment variable. +// Otherwise, it returns the default home directory given its name. +func GetNodeHomeDirectory(name string) (string, error) { + // get the home directory from the flag + args := os.Args + for i := 0; i < len(args); i++ { + if args[i] == "--home" && i+1 < len(args) { + return filepath.Clean(args[i+1]), nil + } else if strings.HasPrefix(args[i], "--home=") { + return filepath.Clean(args[i][7:]), nil + } + } + + // get the home directory from the environment variable + // to not clash with the $HOME system variable, when no prefix is set + // we check the NODE_HOME environment variable + homeDir, envHome := "", "HOME" + if len(EnvPrefix) > 0 { + homeDir = os.Getenv(EnvPrefix + "_" + envHome) + } else { + homeDir = os.Getenv("NODE_" + envHome) + } + if homeDir != "" { + return filepath.Clean(homeDir), nil + } + + // get user home directory + userHomeDir, err := os.UserHomeDir() + if err != nil { + return "", err + } + + return filepath.Join(userHomeDir, name), nil +} diff --git a/connect/internal/internal/account/retriever.go b/connect/internal/internal/account/retriever.go new file mode 100644 index 00000000..2cef69f9 --- /dev/null +++ b/connect/internal/internal/account/retriever.go @@ -0,0 +1,116 @@ +package account + +import ( + "context" + "fmt" + "strconv" + + gogogrpc "github.com/cosmos/gogoproto/grpc" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/metadata" + "google.golang.org/grpc/status" + + "cosmossdk.io/core/address" + + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" + sdk "github.com/cosmos/cosmos-sdk/types" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" +) + +// GRPCBlockHeightHeader represents the gRPC header for block height. +const GRPCBlockHeightHeader = "x-cosmos-block-height" + +var _ AccountRetriever = accountRetriever{} + +// Account provides a read-only abstraction over the auth module's AccountI. +type Account interface { + GetAddress() sdk.AccAddress + GetPubKey() cryptotypes.PubKey // can return nil. + GetAccountNumber() uint64 + GetSequence() uint64 +} + +// AccountRetriever defines methods required to retrieve account details necessary for transaction signing. +type AccountRetriever interface { + GetAccount(context.Context, []byte) (Account, error) + GetAccountWithHeight(context.Context, []byte) (Account, int64, error) + EnsureExists(context.Context, []byte) error + GetAccountNumberSequence(context.Context, []byte) (accNum, accSeq uint64, err error) +} + +type accountRetriever struct { + ac address.Codec + conn gogogrpc.ClientConn + registry codectypes.InterfaceRegistry +} + +// NewAccountRetriever creates a new instance of accountRetriever. +func NewAccountRetriever(ac address.Codec, conn gogogrpc.ClientConn, registry codectypes.InterfaceRegistry) *accountRetriever { + return &accountRetriever{ + ac: ac, + conn: conn, + registry: registry, + } +} + +// GetAccount retrieves an account using its address. +func (a accountRetriever) GetAccount(ctx context.Context, addr []byte) (Account, error) { + acc, _, err := a.GetAccountWithHeight(ctx, addr) + return acc, err +} + +// GetAccountWithHeight retrieves an account and its associated block height using the account's address. +func (a accountRetriever) GetAccountWithHeight(ctx context.Context, addr []byte) (Account, int64, error) { + var header metadata.MD + qc := authtypes.NewQueryClient(a.conn) + + addrStr, err := a.ac.BytesToString(addr) + if err != nil { + return nil, 0, err + } + + res, err := qc.Account(ctx, &authtypes.QueryAccountRequest{Address: addrStr}, grpc.Header(&header)) + if err != nil { + return nil, 0, err + } + + blockHeight := header.Get(GRPCBlockHeightHeader) + if len(blockHeight) != 1 { + return nil, 0, fmt.Errorf("unexpected '%s' header length; got %d, expected 1", GRPCBlockHeightHeader, len(blockHeight)) + } + + nBlockHeight, err := strconv.Atoi(blockHeight[0]) + if err != nil { + return nil, 0, fmt.Errorf("failed to parse block height: %w", err) + } + + var acc Account + if err := a.registry.UnpackAny(res.Account, &acc); err != nil { + return nil, 0, err + } + + return acc, int64(nBlockHeight), nil +} + +// EnsureExists checks if an account exists using its address. +func (a accountRetriever) EnsureExists(ctx context.Context, addr []byte) error { + if _, err := a.GetAccount(ctx, addr); err != nil { + return err + } + return nil +} + +// GetAccountNumberSequence retrieves the account number and sequence for an account using its address. +func (a accountRetriever) GetAccountNumberSequence(ctx context.Context, addr []byte) (accNum, accSeq uint64, err error) { + acc, err := a.GetAccount(ctx, addr) + if err != nil { + if status.Code(err) == codes.NotFound { + return 0, 0, nil + } + return 0, 0, err + } + + return acc.GetAccountNumber(), acc.GetSequence(), nil +} diff --git a/connect/internal/internal/buf.gen.gogo.yaml b/connect/internal/internal/buf.gen.gogo.yaml new file mode 100644 index 00000000..a1df55b8 --- /dev/null +++ b/connect/internal/internal/buf.gen.gogo.yaml @@ -0,0 +1,5 @@ +version: v1 +plugins: + - name: gocosmos + out: .. + opt: plugins=grpc,Mgoogle/protobuf/any.proto=github.com/cosmos/gogoproto/types/any diff --git a/connect/internal/internal/buf.gen.pulsar.yaml b/connect/internal/internal/buf.gen.pulsar.yaml new file mode 100644 index 00000000..48859547 --- /dev/null +++ b/connect/internal/internal/buf.gen.pulsar.yaml @@ -0,0 +1,16 @@ +version: v1 +managed: + enabled: true + go_package_prefix: + default: github.com/cosmos/cosmos-sdk/client/v2/internal + except: + - buf.build/cosmos/cosmos-proto + override: + buf.build/cosmos/cosmos-sdk: cosmossdk.io/api +plugins: + - name: go-pulsar + out: . + opt: paths=source_relative + - name: go-grpc + out: . + opt: paths=source_relative diff --git a/connect/internal/internal/buf.lock b/connect/internal/internal/buf.lock new file mode 100644 index 00000000..ca09fbb4 --- /dev/null +++ b/connect/internal/internal/buf.lock @@ -0,0 +1,33 @@ +# Generated by buf. DO NOT EDIT. +version: v1 +deps: + - remote: buf.build + owner: cosmos + repository: cosmos-proto + commit: 04467658e59e44bbb22fe568206e1f70 + digest: shake256:73a640bd60e0c523b0f8237ff34eab67c45a38b64bbbde1d80224819d272dbf316ac183526bd245f994af6608b025f5130483d0133c5edd385531326b5990466 + - remote: buf.build + owner: cosmos + repository: cosmos-sdk + commit: 05419252bcc241ea8023acf1ed4cadc5 + digest: shake256:1e54a48c19a8b59d35e0a7efa76402939f515f2d8005df099856f24c37c20a52800308f025abb8cffcd014d437b49707388aaca4865d9d063d8f25d5d4eb77d5 + - remote: buf.build + owner: cosmos + repository: gogo-proto + commit: 88ef6483f90f478fb938c37dde52ece3 + digest: shake256:89c45df2aa11e0cff97b0d695436713db3d993d76792e9f8dc1ae90e6ab9a9bec55503d48ceedd6b86069ab07d3041b32001b2bfe0227fa725dd515ff381e5ba + - remote: buf.build + owner: googleapis + repository: googleapis + commit: 7e6f6e774e29406da95bd61cdcdbc8bc + digest: shake256:fe43dd2265ea0c07d76bd925eeba612667cf4c948d2ce53d6e367e1b4b3cb5fa69a51e6acb1a6a50d32f894f054a35e6c0406f6808a483f2752e10c866ffbf73 + - remote: buf.build + owner: protocolbuffers + repository: wellknowntypes + commit: 657250e6a39648cbb169d079a60bd9ba + digest: shake256:00de25001b8dd2e29d85fc4bcc3ede7aed886d76d67f5e0f7a9b320b90f871d3eb73507d50818d823a0512f3f8db77a11c043685528403e31ff3fef18323a9fb + - remote: buf.build + owner: tendermint + repository: tendermint + commit: 33ed361a90514289beabf3189e1d7665 + digest: shake256:038267e06294714fd883610626554b04a127b576b4e253befb4206cb72d5d3c1eeccacd4b9ec8e3fb891f7c14e1cb0f770c077d2989638995b0a61c85afedb1d diff --git a/connect/internal/internal/buf.yaml b/connect/internal/internal/buf.yaml new file mode 100644 index 00000000..96af160b --- /dev/null +++ b/connect/internal/internal/buf.yaml @@ -0,0 +1,12 @@ +version: v1 +deps: + - buf.build/cosmos/cosmos-sdk + - buf.build/cosmos/cosmos-proto +lint: + use: + - DEFAULT + except: + - PACKAGE_VERSION_SUFFIX +breaking: + ignore: + - testpb diff --git a/connect/internal/internal/coins/format.go b/connect/internal/internal/coins/format.go new file mode 100644 index 00000000..b3ca0866 --- /dev/null +++ b/connect/internal/internal/coins/format.go @@ -0,0 +1,62 @@ +package coins + +import ( + "errors" + "regexp" + "strings" + + basev1beta1 "cosmossdk.io/api/cosmos/base/v1beta1" +) + +// Amount can be a whole number or a decimal number. Denominations can be 3 ~ 128 +// characters long and support letters, followed by either a letter, a number or +// a separator ('/', ':', '.', '_' or '-'). +var coinRegex = regexp.MustCompile(`^(\d+(\.\d+)?)([a-zA-Z][a-zA-Z0-9\/\:\._\-]{2,127})$`) + +// ParseCoin parses a coin from a string. The string must be in the format +// , where is a number and is a valid denom. +func ParseCoin(input string) (*basev1beta1.Coin, error) { + amount, denom, err := parseCoin(input) + if err != nil { + return nil, err + } + + return &basev1beta1.Coin{ + Amount: amount, + Denom: denom, + }, nil +} + +// ParseDecCoin parses a decCoin from a string. The string must be in the format +// , where is a number and is a valid denom. +func ParseDecCoin(input string) (*basev1beta1.DecCoin, error) { + amount, denom, err := parseCoin(input) + if err != nil { + return nil, err + } + + return &basev1beta1.DecCoin{ + Amount: amount, + Denom: denom, + }, nil +} + +// parseCoin parses a coin string into its amount and denom components. +// The input string must be in the format . +// It returns the amount string, denom string, and any error encountered. +// Returns an error if the input is empty or doesn't match the expected format. +func parseCoin(input string) (amount, denom string, err error) { + input = strings.TrimSpace(input) + + if input == "" { + return "", "", errors.New("empty input when parsing coin") + } + + matches := coinRegex.FindStringSubmatch(input) + + if len(matches) == 0 { + return "", "", errors.New("invalid input format") + } + + return matches[1], matches[3], nil +} diff --git a/connect/internal/internal/coins/format_test.go b/connect/internal/internal/coins/format_test.go new file mode 100644 index 00000000..a5c42ac1 --- /dev/null +++ b/connect/internal/internal/coins/format_test.go @@ -0,0 +1,73 @@ +package coins + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func Test_parseCoin(t *testing.T) { + tests := []struct { + name string + input string + amount string + denom string + err string + }{ + { + name: "ok", + input: "1000stake", + amount: "1000", + denom: "stake", + }, + { + name: "empty", + input: "", + err: "empty input when parsing coin", + }, + { + name: "empty denom", + input: "1000", + err: "invalid input format", + }, + { + name: "empty amount", + input: "stake", + err: "invalid input format", + }, + { + name: " format", + input: "stake1000", + err: "invalid input format", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + amount, denom, err := parseCoin(tt.input) + if tt.err != "" { + require.Error(t, err) + require.Contains(t, err.Error(), tt.err) + } else { + require.NoError(t, err) + require.Equal(t, tt.amount, amount) + require.Equal(t, tt.denom, denom) + } + }) + } +} + +func TestParseCoin(t *testing.T) { + encodedCoin := "1000000000foo" + coin, err := ParseCoin(encodedCoin) + require.NoError(t, err) + require.Equal(t, "1000000000", coin.Amount) + require.Equal(t, "foo", coin.Denom) +} + +func TestParseDecCoin(t *testing.T) { + encodedCoin := "1000000000foo" + coin, err := ParseDecCoin(encodedCoin) + require.NoError(t, err) + require.Equal(t, "1000000000", coin.Amount) + require.Equal(t, "foo", coin.Denom) +} diff --git a/connect/internal/internal/coins/util.go b/connect/internal/internal/coins/util.go new file mode 100644 index 00000000..14953867 --- /dev/null +++ b/connect/internal/internal/coins/util.go @@ -0,0 +1,66 @@ +package coins + +import ( + "errors" + + base "cosmossdk.io/api/cosmos/base/v1beta1" + "cosmossdk.io/math" + + sdk "github.com/cosmos/cosmos-sdk/types" +) + +var ( + _ withAmount = &base.Coin{} + _ withAmount = &base.DecCoin{} +) + +type withAmount interface { + GetAmount() string +} + +// IsZero check if given coins are zero. +func IsZero[T withAmount](coins []T) (bool, error) { + for _, coin := range coins { + amount, ok := math.NewIntFromString(coin.GetAmount()) + if !ok { + return false, errors.New("invalid coin amount") + } + if !amount.IsZero() { + return false, nil + } + } + return true, nil +} + +func ParseDecCoins(coins string) ([]*base.DecCoin, error) { + parsedGasPrices, err := sdk.ParseDecCoins(coins) // TODO: do it here to avoid sdk dependency + if err != nil { + return nil, err + } + + finalGasPrices := make([]*base.DecCoin, len(parsedGasPrices)) + for i, coin := range parsedGasPrices { + finalGasPrices[i] = &base.DecCoin{ + Denom: coin.Denom, + Amount: coin.Amount.String(), + } + } + return finalGasPrices, nil +} + +func ParseCoinsNormalized(coins string) ([]*base.Coin, error) { + parsedFees, err := sdk.ParseCoinsNormalized(coins) // TODO: do it here to avoid sdk dependency + if err != nil { + return nil, err + } + + finalFees := make([]*base.Coin, len(parsedFees)) + for i, coin := range parsedFees { + finalFees[i] = &base.Coin{ + Denom: coin.Denom, + Amount: coin.Amount.String(), + } + } + + return finalFees, nil +} diff --git a/connect/internal/internal/coins/util_test.go b/connect/internal/internal/coins/util_test.go new file mode 100644 index 00000000..1ee7f584 --- /dev/null +++ b/connect/internal/internal/coins/util_test.go @@ -0,0 +1,83 @@ +package coins + +import ( + "testing" + + "github.com/stretchr/testify/require" + + base "cosmossdk.io/api/cosmos/base/v1beta1" +) + +func TestCoinIsZero(t *testing.T) { + type testCase[T withAmount] struct { + name string + coins []T + isZero bool + } + tests := []testCase[*base.Coin]{ + { + name: "not zero coin", + coins: []*base.Coin{ + { + Denom: "stake", + Amount: "100", + }, + }, + isZero: false, + }, + { + name: "zero coin", + coins: []*base.Coin{ + { + Denom: "stake", + Amount: "0", + }, + }, + isZero: true, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := IsZero(tt.coins) + require.NoError(t, err) + require.Equal(t, got, tt.isZero) + }) + } +} + +func TestDecCoinIsZero(t *testing.T) { + type testCase[T withAmount] struct { + name string + coins []T + isZero bool + } + tests := []testCase[*base.DecCoin]{ + { + name: "not zero coin", + coins: []*base.DecCoin{ + { + Denom: "stake", + Amount: "100", + }, + }, + isZero: false, + }, + { + name: "zero coin", + coins: []*base.DecCoin{ + { + Denom: "stake", + Amount: "0", + }, + }, + isZero: true, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := IsZero(tt.coins) + require.NoError(t, err) + require.Equal(t, got, tt.isZero) + }) + } +} diff --git a/connect/internal/internal/flags/flags.go b/connect/internal/internal/flags/flags.go new file mode 100644 index 00000000..7f684ac4 --- /dev/null +++ b/connect/internal/internal/flags/flags.go @@ -0,0 +1,47 @@ +package flags + +// This defines flag names that can be used in autocli. +const ( + // FlagHome is the flag to specify the home dir of the app. + FlagHome = "home" + + // FlagChainID is the flag to specify the chain ID of the network. + FlagChainID = "chain-id" + + // FlagFrom is the flag to set the from address with which to sign the transaction. + FlagFrom = "from" + + // FlagOutput is the flag to set the output format. + FlagOutput = "output" + + // FlagNoIndent is the flag to not indent the output. + FlagNoIndent = "no-indent" + + // FlagNoPrompt is the flag to not use a prompt for commands. + FlagNoPrompt = "no-prompt" + + // FlagKeyringDir is the flag to specify the directory where the keyring is stored. + FlagKeyringDir = "keyring-dir" + // FlagKeyringBackend is the flag to specify which backend to use for the keyring (e.g. os, file, test). + FlagKeyringBackend = "keyring-backend" + + // FlagNoProposal is the flag convert a gov proposal command into a normal command. + // This is used to allow user of chains with custom authority to not use gov submit proposals for usual proposal commands. + FlagNoProposal = "no-proposal" + + // FlagNode is the flag to specify the node address to connect to. + FlagNode = "node" + // FlagBroadcastMode is the flag to specify the broadcast mode for transactions. + FlagBroadcastMode = "broadcast-mode" + + // FlagGrpcAddress is the flag to specify the gRPC server address to connect to. + FlagGrpcAddress = "grpc-addr" + // FlagGrpcInsecure is the flag to allow insecure gRPC connections. + FlagGrpcInsecure = "grpc-insecure" +) + +// List of supported output formats +const ( + OutputFormatJSON = "json" + OutputFormatText = "text" +) diff --git a/connect/internal/internal/governance/gov.go b/connect/internal/internal/governance/gov.go new file mode 100644 index 00000000..0edc0077 --- /dev/null +++ b/connect/internal/internal/governance/gov.go @@ -0,0 +1,98 @@ +package governance + +import ( + "fmt" + + gogoproto "github.com/cosmos/gogoproto/proto" + gogoprotoany "github.com/cosmos/gogoproto/types/any" + "github.com/spf13/cobra" + "github.com/spf13/pflag" + "google.golang.org/protobuf/types/known/anypb" + + govv1 "cosmossdk.io/api/cosmos/gov/v1" + "github.com/ignite/apps/connect/internal/internal/coins" +) + +const ( + // ModuleName is the name of the governance module name. + // It should match the module name of the github.com/cosmos/cosmos-sdk/x/gov module. + ModuleName = "gov" + + FlagDeposit = "deposit" + FlagMetadata = "metadata" + FlagTitle = "title" + FlagSummary = "summary" + FlagExpedited = "expedited" +) + +// AddGovPropFlagsToCmd adds governance proposal flags to the provided command. +func AddGovPropFlagsToCmd(cmd *cobra.Command) { + cmd.Flags().String(FlagDeposit, "", "The deposit to include with the governance proposal") + cmd.Flags().String(FlagMetadata, "", "The metadata to include with the governance proposal") + cmd.Flags().String(FlagTitle, "", "The title to put on the governance proposal") + cmd.Flags().String(FlagSummary, "", "The summary to include with the governance proposal") + cmd.Flags().Bool(FlagExpedited, false, "Whether to expedite the governance proposal") +} + +// ReadGovPropCmdFlags parses a MsgSubmitProposal from the provided context and flags. +func ReadGovPropCmdFlags(proposer string, flagSet *pflag.FlagSet) (*govv1.MsgSubmitProposal, error) { + rv := &govv1.MsgSubmitProposal{} + + deposit, err := flagSet.GetString(FlagDeposit) + if err != nil { + return nil, fmt.Errorf("could not read deposit: %w", err) + } + if len(deposit) > 0 { + rv.InitialDeposit, err = coins.ParseCoinsNormalized(deposit) + if err != nil { + return nil, fmt.Errorf("invalid deposit: %w", err) + } + } + + rv.Metadata, err = flagSet.GetString(FlagMetadata) + if err != nil { + return nil, fmt.Errorf("could not read metadata: %w", err) + } + + rv.Title, err = flagSet.GetString(FlagTitle) + if err != nil { + return nil, fmt.Errorf("could not read title: %w", err) + } + + rv.Summary, err = flagSet.GetString(FlagSummary) + if err != nil { + return nil, fmt.Errorf("could not read summary: %w", err) + } + + expedited, err := flagSet.GetBool(FlagExpedited) + if err != nil { + return nil, fmt.Errorf("could not read expedited: %w", err) + } + if expedited { + rv.Expedited = true + } + + rv.Proposer = proposer + + return rv, nil +} + +func SetGovMsgs(proposal *govv1.MsgSubmitProposal, msgs ...gogoproto.Message) error { + if len(msgs) == 0 { + return fmt.Errorf("zero messages is not supported") + } + + for _, msg := range msgs { + anyMsg, err := gogoprotoany.NewAnyWithCacheWithValue(msg) + if err != nil { + return err + } + + proposal.Messages = append(proposal.Messages, &anypb.Any{ + TypeUrl: anyMsg.TypeUrl, + Value: anyMsg.Value, + }) + } + + return nil +} diff --git a/connect/internal/internal/print/printer.go b/connect/internal/internal/print/printer.go new file mode 100644 index 00000000..35b5bb2d --- /dev/null +++ b/connect/internal/internal/print/printer.go @@ -0,0 +1,84 @@ +package print + +import ( + "encoding/json" + "fmt" + "io" + "os" + + "github.com/spf13/cobra" + "sigs.k8s.io/yaml" + + "github.com/ignite/apps/connect/internal/internal/flags" +) + +const ( + jsonOutput = flags.OutputFormatJSON + textOutput = flags.OutputFormatText +) + +// Printer handles formatted output of different types of data +type Printer struct { + Output io.Writer + OutputFormat string +} + +// NewPrinter creates a new Printer instance with default stdout +func NewPrinter(cmd *cobra.Command) (*Printer, error) { + outputFormat, err := cmd.Flags().GetString("output") + if err != nil { + return nil, err + } + + if outputFormat != jsonOutput && outputFormat != textOutput { + return nil, fmt.Errorf("unsupported output format: %s", outputFormat) + } + + return &Printer{ + Output: cmd.OutOrStdout(), + OutputFormat: outputFormat, + }, nil +} + +// PrintString prints the raw string +func (p *Printer) PrintString(str string) error { + return p.PrintBytes([]byte(str)) +} + +// PrintRaw prints raw JSON message without marshaling +func (p *Printer) PrintRaw(toPrint json.RawMessage) error { + return p.PrintBytes(toPrint) +} + +// PrintBytes prints and formats bytes +func (p *Printer) PrintBytes(out []byte) error { + var err error + if p.OutputFormat == textOutput { + if !json.Valid(out) { + return fmt.Errorf("invalid JSON") + } + out, err = yaml.JSONToYAML(out) + if err != nil { + return err + } + } + + writer := p.Output + if writer == nil { + writer = os.Stdout + } + + _, err = writer.Write(out) + if err != nil { + return err + } + + if p.OutputFormat != textOutput { + _, err = writer.Write([]byte("\n")) + if err != nil { + return err + } + } + + return nil +} diff --git a/connect/internal/internal/strcase/kebab.go b/connect/internal/internal/strcase/kebab.go new file mode 100644 index 00000000..ac3eb1c0 --- /dev/null +++ b/connect/internal/internal/strcase/kebab.go @@ -0,0 +1,101 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2015 Ian Coleman + * Copyright (c) 2018 Ma_124, + * Copyright (c) 2022 Cosmos SDK Developers, + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, Subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or Substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package strcase + +import ( + "strings" +) + +// ToKebab converts a string to kebab-case +func ToKebab(s string) string { + return ToDelimited(s, '-', false) +} + +// ToScreamingKebab converts a string to SCREAMING-KEBAB-CASE +func ToScreamingKebab(s string) string { + return ToDelimited(s, '-', true) +} + +// ToSnake converts a string to snake_case +func ToSnake(s string) string { + return ToDelimited(s, '_', false) +} + +// ToScreamingSnake converts a string to SCREAMING_SNAKE_CASE +func ToScreamingSnake(s string) string { + return ToDelimited(s, '_', true) +} + +// ToDelimited converts a string to delimited.snake.case +// (in this case `delimiter = '.'`) +func ToDelimited(s string, delimiter uint8, screaming bool) string { + s = strings.TrimSpace(s) + n := strings.Builder{} + n.Grow(len(s) + 2) // nominal 2 bytes of extra space for inserted delimiters + for i, v := range []byte(s) { + vIsCap := v >= 'A' && v <= 'Z' + vIsLow := v >= 'a' && v <= 'z' + if vIsLow && screaming { + v += 'A' + v -= 'a' + } else if vIsCap && !screaming { + v += 'a' + v -= 'A' + } + + // treat acronyms as words, eg for JSONData -> JSON is a whole word + if i+1 < len(s) { + next := s[i+1] + vIsNum := v >= '0' && v <= '9' + nextIsCap := next >= 'A' && next <= 'Z' + nextIsLow := next >= 'a' && next <= 'z' + nextIsNum := next >= '0' && next <= '9' + // add underscore if next letter case type is changed + if (vIsCap && (nextIsLow || nextIsNum)) || (vIsLow && (nextIsCap || nextIsNum)) || (vIsNum && (nextIsCap || nextIsLow)) { + if vIsCap && nextIsLow { + if prevIsCap := i > 0 && s[i-1] >= 'A' && s[i-1] <= 'Z'; prevIsCap { + n.WriteByte(delimiter) + } + } + n.WriteByte(v) + if (vIsLow && nextIsCap) || (vIsNum && nextIsCap) || (vIsNum && nextIsLow) { + n.WriteByte(delimiter) + } + continue + } + } + + if v == ' ' || v == '_' || v == '-' || v == '.' { + // replace space/underscore/hyphen/dot with delimiter + n.WriteByte(delimiter) + } else { + n.WriteByte(v) + } + } + + return n.String() +} diff --git a/connect/internal/internal/strcase/kebab_test.go b/connect/internal/internal/strcase/kebab_test.go new file mode 100644 index 00000000..ba3fe1bc --- /dev/null +++ b/connect/internal/internal/strcase/kebab_test.go @@ -0,0 +1,44 @@ +package strcase_test + +import ( + "testing" + + "gotest.tools/v3/assert" + + "github.com/ignite/apps/connect/internal/internal/strcase" +) + +func toKebab(tb testing.TB) { + tb.Helper() + cases := [][]string{ + {"testCase", "test-case"}, + {"TestCase", "test-case"}, + {"Test Case", "test-case"}, + {"TEST CASE", "test-case"}, + {"TESTCase", "test-case"}, + {"TESTCASE", "testcase"}, + {"TEST_CASE", "test-case"}, + {"Bech32", "bech32"}, + {"Bech32Address", "bech32-address"}, + {"Bech32_Address", "bech32-address"}, + {"Bech32Address10", "bech32-address10"}, + {"Bech32-Address10", "bech32-address10"}, + {"SecondBech32Address10Foo", "second-bech32-address10-foo"}, + } + for _, i := range cases { + in := i[0] + out := i[1] + result := strcase.ToKebab(in) + assert.Equal(tb, out, result, "ToKebab(%s) = %s, want %s", in, result, out) + } +} + +func TestToKebab(t *testing.T) { + toKebab(t) +} + +func BenchmarkToKebab(b *testing.B) { + for n := 0; n < b.N; n++ { + toKebab(b) + } +} diff --git a/connect/internal/internal/testpb/msg.proto b/connect/internal/internal/testpb/msg.proto new file mode 100644 index 00000000..a8189519 --- /dev/null +++ b/connect/internal/internal/testpb/msg.proto @@ -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.53.0 "; + } +} + +message MsgRequest { + // u32 is a 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 {} diff --git a/connect/internal/internal/testpb/msg.pulsar.go b/connect/internal/internal/testpb/msg.pulsar.go new file mode 100644 index 00000000..216a5c15 --- /dev/null +++ b/connect/internal/internal/testpb/msg.pulsar.go @@ -0,0 +1,4435 @@ +// Code generated by protoc-gen-go-pulsar. DO NOT EDIT. +package testpb + +import ( + v1beta11 "cosmossdk.io/api/cosmos/base/query/v1beta1" + v1beta1 "cosmossdk.io/api/cosmos/base/v1beta1" + fmt "fmt" + _ "github.com/cosmos/cosmos-proto" + runtime "github.com/cosmos/cosmos-proto/runtime" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoiface "google.golang.org/protobuf/runtime/protoiface" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + durationpb "google.golang.org/protobuf/types/known/durationpb" + timestamppb "google.golang.org/protobuf/types/known/timestamppb" + io "io" + reflect "reflect" + sync "sync" +) + +var _ protoreflect.List = (*_MsgRequest_21_list)(nil) + +type _MsgRequest_21_list struct { + list *[]bool +} + +func (x *_MsgRequest_21_list) Len() int { + if x.list == nil { + return 0 + } + return len(*x.list) +} + +func (x *_MsgRequest_21_list) Get(i int) protoreflect.Value { + return protoreflect.ValueOfBool((*x.list)[i]) +} + +func (x *_MsgRequest_21_list) Set(i int, value protoreflect.Value) { + valueUnwrapped := value.Bool() + concreteValue := valueUnwrapped + (*x.list)[i] = concreteValue +} + +func (x *_MsgRequest_21_list) Append(value protoreflect.Value) { + valueUnwrapped := value.Bool() + concreteValue := valueUnwrapped + *x.list = append(*x.list, concreteValue) +} + +func (x *_MsgRequest_21_list) AppendMutable() protoreflect.Value { + panic(fmt.Errorf("AppendMutable can not be called on message MsgRequest at list field Bools as it is not of Message kind")) +} + +func (x *_MsgRequest_21_list) Truncate(n int) { + *x.list = (*x.list)[:n] +} + +func (x *_MsgRequest_21_list) NewElement() protoreflect.Value { + v := false + return protoreflect.ValueOfBool(v) +} + +func (x *_MsgRequest_21_list) IsValid() bool { + return x.list != nil +} + +var _ protoreflect.List = (*_MsgRequest_22_list)(nil) + +type _MsgRequest_22_list struct { + list *[]uint32 +} + +func (x *_MsgRequest_22_list) Len() int { + if x.list == nil { + return 0 + } + return len(*x.list) +} + +func (x *_MsgRequest_22_list) Get(i int) protoreflect.Value { + return protoreflect.ValueOfUint32((*x.list)[i]) +} + +func (x *_MsgRequest_22_list) Set(i int, value protoreflect.Value) { + valueUnwrapped := value.Uint() + concreteValue := (uint32)(valueUnwrapped) + (*x.list)[i] = concreteValue +} + +func (x *_MsgRequest_22_list) Append(value protoreflect.Value) { + valueUnwrapped := value.Uint() + concreteValue := (uint32)(valueUnwrapped) + *x.list = append(*x.list, concreteValue) +} + +func (x *_MsgRequest_22_list) AppendMutable() protoreflect.Value { + panic(fmt.Errorf("AppendMutable can not be called on message MsgRequest at list field Uints as it is not of Message kind")) +} + +func (x *_MsgRequest_22_list) Truncate(n int) { + *x.list = (*x.list)[:n] +} + +func (x *_MsgRequest_22_list) NewElement() protoreflect.Value { + v := uint32(0) + return protoreflect.ValueOfUint32(v) +} + +func (x *_MsgRequest_22_list) IsValid() bool { + return x.list != nil +} + +var _ protoreflect.List = (*_MsgRequest_23_list)(nil) + +type _MsgRequest_23_list struct { + list *[]string +} + +func (x *_MsgRequest_23_list) Len() int { + if x.list == nil { + return 0 + } + return len(*x.list) +} + +func (x *_MsgRequest_23_list) Get(i int) protoreflect.Value { + return protoreflect.ValueOfString((*x.list)[i]) +} + +func (x *_MsgRequest_23_list) Set(i int, value protoreflect.Value) { + valueUnwrapped := value.String() + concreteValue := valueUnwrapped + (*x.list)[i] = concreteValue +} + +func (x *_MsgRequest_23_list) Append(value protoreflect.Value) { + valueUnwrapped := value.String() + concreteValue := valueUnwrapped + *x.list = append(*x.list, concreteValue) +} + +func (x *_MsgRequest_23_list) AppendMutable() protoreflect.Value { + panic(fmt.Errorf("AppendMutable can not be called on message MsgRequest at list field Strings as it is not of Message kind")) +} + +func (x *_MsgRequest_23_list) Truncate(n int) { + *x.list = (*x.list)[:n] +} + +func (x *_MsgRequest_23_list) NewElement() protoreflect.Value { + v := "" + return protoreflect.ValueOfString(v) +} + +func (x *_MsgRequest_23_list) IsValid() bool { + return x.list != nil +} + +var _ protoreflect.List = (*_MsgRequest_24_list)(nil) + +type _MsgRequest_24_list struct { + list *[]Enum +} + +func (x *_MsgRequest_24_list) Len() int { + if x.list == nil { + return 0 + } + return len(*x.list) +} + +func (x *_MsgRequest_24_list) Get(i int) protoreflect.Value { + return protoreflect.ValueOfEnum((protoreflect.EnumNumber)((*x.list)[i])) +} + +func (x *_MsgRequest_24_list) Set(i int, value protoreflect.Value) { + valueUnwrapped := value.Enum() + concreteValue := (Enum)(valueUnwrapped) + (*x.list)[i] = concreteValue +} + +func (x *_MsgRequest_24_list) Append(value protoreflect.Value) { + valueUnwrapped := value.Enum() + concreteValue := (Enum)(valueUnwrapped) + *x.list = append(*x.list, concreteValue) +} + +func (x *_MsgRequest_24_list) AppendMutable() protoreflect.Value { + panic(fmt.Errorf("AppendMutable can not be called on message MsgRequest at list field Enums as it is not of Message kind")) +} + +func (x *_MsgRequest_24_list) Truncate(n int) { + *x.list = (*x.list)[:n] +} + +func (x *_MsgRequest_24_list) NewElement() protoreflect.Value { + v := 0 + return protoreflect.ValueOfEnum((protoreflect.EnumNumber)(v)) +} + +func (x *_MsgRequest_24_list) IsValid() bool { + return x.list != nil +} + +var _ protoreflect.List = (*_MsgRequest_25_list)(nil) + +type _MsgRequest_25_list struct { + list *[]*durationpb.Duration +} + +func (x *_MsgRequest_25_list) Len() int { + if x.list == nil { + return 0 + } + return len(*x.list) +} + +func (x *_MsgRequest_25_list) Get(i int) protoreflect.Value { + return protoreflect.ValueOfMessage((*x.list)[i].ProtoReflect()) +} + +func (x *_MsgRequest_25_list) Set(i int, value protoreflect.Value) { + valueUnwrapped := value.Message() + concreteValue := valueUnwrapped.Interface().(*durationpb.Duration) + (*x.list)[i] = concreteValue +} + +func (x *_MsgRequest_25_list) Append(value protoreflect.Value) { + valueUnwrapped := value.Message() + concreteValue := valueUnwrapped.Interface().(*durationpb.Duration) + *x.list = append(*x.list, concreteValue) +} + +func (x *_MsgRequest_25_list) AppendMutable() protoreflect.Value { + v := new(durationpb.Duration) + *x.list = append(*x.list, v) + return protoreflect.ValueOfMessage(v.ProtoReflect()) +} + +func (x *_MsgRequest_25_list) Truncate(n int) { + for i := n; i < len(*x.list); i++ { + (*x.list)[i] = nil + } + *x.list = (*x.list)[:n] +} + +func (x *_MsgRequest_25_list) NewElement() protoreflect.Value { + v := new(durationpb.Duration) + return protoreflect.ValueOfMessage(v.ProtoReflect()) +} + +func (x *_MsgRequest_25_list) IsValid() bool { + return x.list != nil +} + +var _ protoreflect.List = (*_MsgRequest_26_list)(nil) + +type _MsgRequest_26_list struct { + list *[]*AMessage +} + +func (x *_MsgRequest_26_list) Len() int { + if x.list == nil { + return 0 + } + return len(*x.list) +} + +func (x *_MsgRequest_26_list) Get(i int) protoreflect.Value { + return protoreflect.ValueOfMessage((*x.list)[i].ProtoReflect()) +} + +func (x *_MsgRequest_26_list) Set(i int, value protoreflect.Value) { + valueUnwrapped := value.Message() + concreteValue := valueUnwrapped.Interface().(*AMessage) + (*x.list)[i] = concreteValue +} + +func (x *_MsgRequest_26_list) Append(value protoreflect.Value) { + valueUnwrapped := value.Message() + concreteValue := valueUnwrapped.Interface().(*AMessage) + *x.list = append(*x.list, concreteValue) +} + +func (x *_MsgRequest_26_list) AppendMutable() protoreflect.Value { + v := new(AMessage) + *x.list = append(*x.list, v) + return protoreflect.ValueOfMessage(v.ProtoReflect()) +} + +func (x *_MsgRequest_26_list) Truncate(n int) { + for i := n; i < len(*x.list); i++ { + (*x.list)[i] = nil + } + *x.list = (*x.list)[:n] +} + +func (x *_MsgRequest_26_list) NewElement() protoreflect.Value { + v := new(AMessage) + return protoreflect.ValueOfMessage(v.ProtoReflect()) +} + +func (x *_MsgRequest_26_list) IsValid() bool { + return x.list != nil +} + +var _ protoreflect.List = (*_MsgRequest_29_list)(nil) + +type _MsgRequest_29_list struct { + list *[]*v1beta1.Coin +} + +func (x *_MsgRequest_29_list) Len() int { + if x.list == nil { + return 0 + } + return len(*x.list) +} + +func (x *_MsgRequest_29_list) Get(i int) protoreflect.Value { + return protoreflect.ValueOfMessage((*x.list)[i].ProtoReflect()) +} + +func (x *_MsgRequest_29_list) Set(i int, value protoreflect.Value) { + valueUnwrapped := value.Message() + concreteValue := valueUnwrapped.Interface().(*v1beta1.Coin) + (*x.list)[i] = concreteValue +} + +func (x *_MsgRequest_29_list) Append(value protoreflect.Value) { + valueUnwrapped := value.Message() + concreteValue := valueUnwrapped.Interface().(*v1beta1.Coin) + *x.list = append(*x.list, concreteValue) +} + +func (x *_MsgRequest_29_list) AppendMutable() protoreflect.Value { + v := new(v1beta1.Coin) + *x.list = append(*x.list, v) + return protoreflect.ValueOfMessage(v.ProtoReflect()) +} + +func (x *_MsgRequest_29_list) Truncate(n int) { + for i := n; i < len(*x.list); i++ { + (*x.list)[i] = nil + } + *x.list = (*x.list)[:n] +} + +func (x *_MsgRequest_29_list) NewElement() protoreflect.Value { + v := new(v1beta1.Coin) + return protoreflect.ValueOfMessage(v.ProtoReflect()) +} + +func (x *_MsgRequest_29_list) IsValid() bool { + return x.list != nil +} + +var ( + md_MsgRequest protoreflect.MessageDescriptor + fd_MsgRequest_u32 protoreflect.FieldDescriptor + fd_MsgRequest_u64 protoreflect.FieldDescriptor + fd_MsgRequest_str protoreflect.FieldDescriptor + fd_MsgRequest_bz protoreflect.FieldDescriptor + fd_MsgRequest_timestamp protoreflect.FieldDescriptor + fd_MsgRequest_duration protoreflect.FieldDescriptor + fd_MsgRequest_i32 protoreflect.FieldDescriptor + fd_MsgRequest_i64 protoreflect.FieldDescriptor + fd_MsgRequest_a_bool protoreflect.FieldDescriptor + fd_MsgRequest_an_enum protoreflect.FieldDescriptor + fd_MsgRequest_a_message protoreflect.FieldDescriptor + fd_MsgRequest_a_coin protoreflect.FieldDescriptor + fd_MsgRequest_an_address protoreflect.FieldDescriptor + fd_MsgRequest_page protoreflect.FieldDescriptor + fd_MsgRequest_bools protoreflect.FieldDescriptor + fd_MsgRequest_uints protoreflect.FieldDescriptor + fd_MsgRequest_strings protoreflect.FieldDescriptor + fd_MsgRequest_enums protoreflect.FieldDescriptor + fd_MsgRequest_durations protoreflect.FieldDescriptor + fd_MsgRequest_some_messages protoreflect.FieldDescriptor + fd_MsgRequest_positional1 protoreflect.FieldDescriptor + fd_MsgRequest_positional2 protoreflect.FieldDescriptor + fd_MsgRequest_positional3_varargs protoreflect.FieldDescriptor + fd_MsgRequest_deprecated_field protoreflect.FieldDescriptor + fd_MsgRequest_shorthand_deprecated_field protoreflect.FieldDescriptor + fd_MsgRequest_hidden_bool protoreflect.FieldDescriptor + fd_MsgRequest_a_validator_address protoreflect.FieldDescriptor +) + +func init() { + file_testpb_msg_proto_init() + md_MsgRequest = File_testpb_msg_proto.Messages().ByName("MsgRequest") + fd_MsgRequest_u32 = md_MsgRequest.Fields().ByName("u32") + fd_MsgRequest_u64 = md_MsgRequest.Fields().ByName("u64") + fd_MsgRequest_str = md_MsgRequest.Fields().ByName("str") + fd_MsgRequest_bz = md_MsgRequest.Fields().ByName("bz") + fd_MsgRequest_timestamp = md_MsgRequest.Fields().ByName("timestamp") + fd_MsgRequest_duration = md_MsgRequest.Fields().ByName("duration") + fd_MsgRequest_i32 = md_MsgRequest.Fields().ByName("i32") + fd_MsgRequest_i64 = md_MsgRequest.Fields().ByName("i64") + fd_MsgRequest_a_bool = md_MsgRequest.Fields().ByName("a_bool") + fd_MsgRequest_an_enum = md_MsgRequest.Fields().ByName("an_enum") + fd_MsgRequest_a_message = md_MsgRequest.Fields().ByName("a_message") + fd_MsgRequest_a_coin = md_MsgRequest.Fields().ByName("a_coin") + fd_MsgRequest_an_address = md_MsgRequest.Fields().ByName("an_address") + fd_MsgRequest_page = md_MsgRequest.Fields().ByName("page") + fd_MsgRequest_bools = md_MsgRequest.Fields().ByName("bools") + fd_MsgRequest_uints = md_MsgRequest.Fields().ByName("uints") + fd_MsgRequest_strings = md_MsgRequest.Fields().ByName("strings") + fd_MsgRequest_enums = md_MsgRequest.Fields().ByName("enums") + fd_MsgRequest_durations = md_MsgRequest.Fields().ByName("durations") + fd_MsgRequest_some_messages = md_MsgRequest.Fields().ByName("some_messages") + fd_MsgRequest_positional1 = md_MsgRequest.Fields().ByName("positional1") + fd_MsgRequest_positional2 = md_MsgRequest.Fields().ByName("positional2") + fd_MsgRequest_positional3_varargs = md_MsgRequest.Fields().ByName("positional3_varargs") + fd_MsgRequest_deprecated_field = md_MsgRequest.Fields().ByName("deprecated_field") + fd_MsgRequest_shorthand_deprecated_field = md_MsgRequest.Fields().ByName("shorthand_deprecated_field") + fd_MsgRequest_hidden_bool = md_MsgRequest.Fields().ByName("hidden_bool") + fd_MsgRequest_a_validator_address = md_MsgRequest.Fields().ByName("a_validator_address") +} + +var _ protoreflect.Message = (*fastReflection_MsgRequest)(nil) + +type fastReflection_MsgRequest MsgRequest + +func (x *MsgRequest) ProtoReflect() protoreflect.Message { + return (*fastReflection_MsgRequest)(x) +} + +func (x *MsgRequest) slowProtoReflect() protoreflect.Message { + mi := &file_testpb_msg_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +var _fastReflection_MsgRequest_messageType fastReflection_MsgRequest_messageType +var _ protoreflect.MessageType = fastReflection_MsgRequest_messageType{} + +type fastReflection_MsgRequest_messageType struct{} + +func (x fastReflection_MsgRequest_messageType) Zero() protoreflect.Message { + return (*fastReflection_MsgRequest)(nil) +} +func (x fastReflection_MsgRequest_messageType) New() protoreflect.Message { + return new(fastReflection_MsgRequest) +} +func (x fastReflection_MsgRequest_messageType) Descriptor() protoreflect.MessageDescriptor { + return md_MsgRequest +} + +// Descriptor returns message descriptor, which contains only the protobuf +// type information for the message. +func (x *fastReflection_MsgRequest) Descriptor() protoreflect.MessageDescriptor { + return md_MsgRequest +} + +// Type returns the message type, which encapsulates both Go and protobuf +// type information. If the Go type information is not needed, +// it is recommended that the message descriptor be used instead. +func (x *fastReflection_MsgRequest) Type() protoreflect.MessageType { + return _fastReflection_MsgRequest_messageType +} + +// New returns a newly allocated and mutable empty message. +func (x *fastReflection_MsgRequest) New() protoreflect.Message { + return new(fastReflection_MsgRequest) +} + +// Interface unwraps the message reflection interface and +// returns the underlying ProtoMessage interface. +func (x *fastReflection_MsgRequest) Interface() protoreflect.ProtoMessage { + return (*MsgRequest)(x) +} + +// Range iterates over every populated field in an undefined order, +// calling f for each field descriptor and value encountered. +// Range returns immediately if f returns false. +// While iterating, mutating operations may only be performed +// on the current field descriptor. +func (x *fastReflection_MsgRequest) Range(f func(protoreflect.FieldDescriptor, protoreflect.Value) bool) { + if x.U32 != uint32(0) { + value := protoreflect.ValueOfUint32(x.U32) + if !f(fd_MsgRequest_u32, value) { + return + } + } + if x.U64 != uint64(0) { + value := protoreflect.ValueOfUint64(x.U64) + if !f(fd_MsgRequest_u64, value) { + return + } + } + if x.Str != "" { + value := protoreflect.ValueOfString(x.Str) + if !f(fd_MsgRequest_str, value) { + return + } + } + if len(x.Bz) != 0 { + value := protoreflect.ValueOfBytes(x.Bz) + if !f(fd_MsgRequest_bz, value) { + return + } + } + if x.Timestamp != nil { + value := protoreflect.ValueOfMessage(x.Timestamp.ProtoReflect()) + if !f(fd_MsgRequest_timestamp, value) { + return + } + } + if x.Duration != nil { + value := protoreflect.ValueOfMessage(x.Duration.ProtoReflect()) + if !f(fd_MsgRequest_duration, value) { + return + } + } + if x.I32 != int32(0) { + value := protoreflect.ValueOfInt32(x.I32) + if !f(fd_MsgRequest_i32, value) { + return + } + } + if x.I64 != int64(0) { + value := protoreflect.ValueOfInt64(x.I64) + if !f(fd_MsgRequest_i64, value) { + return + } + } + if x.ABool != false { + value := protoreflect.ValueOfBool(x.ABool) + if !f(fd_MsgRequest_a_bool, value) { + return + } + } + if x.AnEnum != 0 { + value := protoreflect.ValueOfEnum((protoreflect.EnumNumber)(x.AnEnum)) + if !f(fd_MsgRequest_an_enum, value) { + return + } + } + if x.AMessage != nil { + value := protoreflect.ValueOfMessage(x.AMessage.ProtoReflect()) + if !f(fd_MsgRequest_a_message, value) { + return + } + } + if x.ACoin != nil { + value := protoreflect.ValueOfMessage(x.ACoin.ProtoReflect()) + if !f(fd_MsgRequest_a_coin, value) { + return + } + } + if x.AnAddress != "" { + value := protoreflect.ValueOfString(x.AnAddress) + if !f(fd_MsgRequest_an_address, value) { + return + } + } + if x.Page != nil { + value := protoreflect.ValueOfMessage(x.Page.ProtoReflect()) + if !f(fd_MsgRequest_page, value) { + return + } + } + if len(x.Bools) != 0 { + value := protoreflect.ValueOfList(&_MsgRequest_21_list{list: &x.Bools}) + if !f(fd_MsgRequest_bools, value) { + return + } + } + if len(x.Uints) != 0 { + value := protoreflect.ValueOfList(&_MsgRequest_22_list{list: &x.Uints}) + if !f(fd_MsgRequest_uints, value) { + return + } + } + if len(x.Strings) != 0 { + value := protoreflect.ValueOfList(&_MsgRequest_23_list{list: &x.Strings}) + if !f(fd_MsgRequest_strings, value) { + return + } + } + if len(x.Enums) != 0 { + value := protoreflect.ValueOfList(&_MsgRequest_24_list{list: &x.Enums}) + if !f(fd_MsgRequest_enums, value) { + return + } + } + if len(x.Durations) != 0 { + value := protoreflect.ValueOfList(&_MsgRequest_25_list{list: &x.Durations}) + if !f(fd_MsgRequest_durations, value) { + return + } + } + if len(x.SomeMessages) != 0 { + value := protoreflect.ValueOfList(&_MsgRequest_26_list{list: &x.SomeMessages}) + if !f(fd_MsgRequest_some_messages, value) { + return + } + } + if x.Positional1 != int32(0) { + value := protoreflect.ValueOfInt32(x.Positional1) + if !f(fd_MsgRequest_positional1, value) { + return + } + } + if x.Positional2 != "" { + value := protoreflect.ValueOfString(x.Positional2) + if !f(fd_MsgRequest_positional2, value) { + return + } + } + if len(x.Positional3Varargs) != 0 { + value := protoreflect.ValueOfList(&_MsgRequest_29_list{list: &x.Positional3Varargs}) + if !f(fd_MsgRequest_positional3_varargs, value) { + return + } + } + if x.DeprecatedField != "" { + value := protoreflect.ValueOfString(x.DeprecatedField) + if !f(fd_MsgRequest_deprecated_field, value) { + return + } + } + if x.ShorthandDeprecatedField != "" { + value := protoreflect.ValueOfString(x.ShorthandDeprecatedField) + if !f(fd_MsgRequest_shorthand_deprecated_field, value) { + return + } + } + if x.HiddenBool != false { + value := protoreflect.ValueOfBool(x.HiddenBool) + if !f(fd_MsgRequest_hidden_bool, value) { + return + } + } + if x.AValidatorAddress != "" { + value := protoreflect.ValueOfString(x.AValidatorAddress) + if !f(fd_MsgRequest_a_validator_address, value) { + return + } + } +} + +// Has reports whether a field is populated. +// +// Some fields have the property of nullability where it is possible to +// distinguish between the default value of a field and whether the field +// was explicitly populated with the default value. Singular message fields, +// member fields of a oneof, and proto2 scalar fields are nullable. Such +// fields are populated only if explicitly set. +// +// In other cases (aside from the nullable cases above), +// a proto3 scalar field is populated if it contains a non-zero value, and +// a repeated field is populated if it is non-empty. +func (x *fastReflection_MsgRequest) Has(fd protoreflect.FieldDescriptor) bool { + switch fd.FullName() { + case "testpb.MsgRequest.u32": + return x.U32 != uint32(0) + case "testpb.MsgRequest.u64": + return x.U64 != uint64(0) + case "testpb.MsgRequest.str": + return x.Str != "" + case "testpb.MsgRequest.bz": + return len(x.Bz) != 0 + case "testpb.MsgRequest.timestamp": + return x.Timestamp != nil + case "testpb.MsgRequest.duration": + return x.Duration != nil + case "testpb.MsgRequest.i32": + return x.I32 != int32(0) + case "testpb.MsgRequest.i64": + return x.I64 != int64(0) + case "testpb.MsgRequest.a_bool": + return x.ABool != false + case "testpb.MsgRequest.an_enum": + return x.AnEnum != 0 + case "testpb.MsgRequest.a_message": + return x.AMessage != nil + case "testpb.MsgRequest.a_coin": + return x.ACoin != nil + case "testpb.MsgRequest.an_address": + return x.AnAddress != "" + case "testpb.MsgRequest.page": + return x.Page != nil + case "testpb.MsgRequest.bools": + return len(x.Bools) != 0 + case "testpb.MsgRequest.uints": + return len(x.Uints) != 0 + case "testpb.MsgRequest.strings": + return len(x.Strings) != 0 + case "testpb.MsgRequest.enums": + return len(x.Enums) != 0 + case "testpb.MsgRequest.durations": + return len(x.Durations) != 0 + case "testpb.MsgRequest.some_messages": + return len(x.SomeMessages) != 0 + case "testpb.MsgRequest.positional1": + return x.Positional1 != int32(0) + case "testpb.MsgRequest.positional2": + return x.Positional2 != "" + case "testpb.MsgRequest.positional3_varargs": + return len(x.Positional3Varargs) != 0 + case "testpb.MsgRequest.deprecated_field": + return x.DeprecatedField != "" + case "testpb.MsgRequest.shorthand_deprecated_field": + return x.ShorthandDeprecatedField != "" + case "testpb.MsgRequest.hidden_bool": + return x.HiddenBool != false + case "testpb.MsgRequest.a_validator_address": + return x.AValidatorAddress != "" + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.MsgRequest")) + } + panic(fmt.Errorf("message testpb.MsgRequest does not contain field %s", fd.FullName())) + } +} + +// Clear clears the field such that a subsequent Has call reports false. +// +// Clearing an extension field clears both the extension type and value +// associated with the given field number. +// +// Clear is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_MsgRequest) Clear(fd protoreflect.FieldDescriptor) { + switch fd.FullName() { + case "testpb.MsgRequest.u32": + x.U32 = uint32(0) + case "testpb.MsgRequest.u64": + x.U64 = uint64(0) + case "testpb.MsgRequest.str": + x.Str = "" + case "testpb.MsgRequest.bz": + x.Bz = nil + case "testpb.MsgRequest.timestamp": + x.Timestamp = nil + case "testpb.MsgRequest.duration": + x.Duration = nil + case "testpb.MsgRequest.i32": + x.I32 = int32(0) + case "testpb.MsgRequest.i64": + x.I64 = int64(0) + case "testpb.MsgRequest.a_bool": + x.ABool = false + case "testpb.MsgRequest.an_enum": + x.AnEnum = 0 + case "testpb.MsgRequest.a_message": + x.AMessage = nil + case "testpb.MsgRequest.a_coin": + x.ACoin = nil + case "testpb.MsgRequest.an_address": + x.AnAddress = "" + case "testpb.MsgRequest.page": + x.Page = nil + case "testpb.MsgRequest.bools": + x.Bools = nil + case "testpb.MsgRequest.uints": + x.Uints = nil + case "testpb.MsgRequest.strings": + x.Strings = nil + case "testpb.MsgRequest.enums": + x.Enums = nil + case "testpb.MsgRequest.durations": + x.Durations = nil + case "testpb.MsgRequest.some_messages": + x.SomeMessages = nil + case "testpb.MsgRequest.positional1": + x.Positional1 = int32(0) + case "testpb.MsgRequest.positional2": + x.Positional2 = "" + case "testpb.MsgRequest.positional3_varargs": + x.Positional3Varargs = nil + case "testpb.MsgRequest.deprecated_field": + x.DeprecatedField = "" + case "testpb.MsgRequest.shorthand_deprecated_field": + x.ShorthandDeprecatedField = "" + case "testpb.MsgRequest.hidden_bool": + x.HiddenBool = false + case "testpb.MsgRequest.a_validator_address": + x.AValidatorAddress = "" + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.MsgRequest")) + } + panic(fmt.Errorf("message testpb.MsgRequest does not contain field %s", fd.FullName())) + } +} + +// Get retrieves the value for a field. +// +// For unpopulated scalars, it returns the default value, where +// the default value of a bytes scalar is guaranteed to be a copy. +// For unpopulated composite types, it returns an empty, read-only view +// of the value; to obtain a mutable reference, use Mutable. +func (x *fastReflection_MsgRequest) Get(descriptor protoreflect.FieldDescriptor) protoreflect.Value { + switch descriptor.FullName() { + case "testpb.MsgRequest.u32": + value := x.U32 + return protoreflect.ValueOfUint32(value) + case "testpb.MsgRequest.u64": + value := x.U64 + return protoreflect.ValueOfUint64(value) + case "testpb.MsgRequest.str": + value := x.Str + return protoreflect.ValueOfString(value) + case "testpb.MsgRequest.bz": + value := x.Bz + return protoreflect.ValueOfBytes(value) + case "testpb.MsgRequest.timestamp": + value := x.Timestamp + return protoreflect.ValueOfMessage(value.ProtoReflect()) + case "testpb.MsgRequest.duration": + value := x.Duration + return protoreflect.ValueOfMessage(value.ProtoReflect()) + case "testpb.MsgRequest.i32": + value := x.I32 + return protoreflect.ValueOfInt32(value) + case "testpb.MsgRequest.i64": + value := x.I64 + return protoreflect.ValueOfInt64(value) + case "testpb.MsgRequest.a_bool": + value := x.ABool + return protoreflect.ValueOfBool(value) + case "testpb.MsgRequest.an_enum": + value := x.AnEnum + return protoreflect.ValueOfEnum((protoreflect.EnumNumber)(value)) + case "testpb.MsgRequest.a_message": + value := x.AMessage + return protoreflect.ValueOfMessage(value.ProtoReflect()) + case "testpb.MsgRequest.a_coin": + value := x.ACoin + return protoreflect.ValueOfMessage(value.ProtoReflect()) + case "testpb.MsgRequest.an_address": + value := x.AnAddress + return protoreflect.ValueOfString(value) + case "testpb.MsgRequest.page": + value := x.Page + return protoreflect.ValueOfMessage(value.ProtoReflect()) + case "testpb.MsgRequest.bools": + if len(x.Bools) == 0 { + return protoreflect.ValueOfList(&_MsgRequest_21_list{}) + } + listValue := &_MsgRequest_21_list{list: &x.Bools} + return protoreflect.ValueOfList(listValue) + case "testpb.MsgRequest.uints": + if len(x.Uints) == 0 { + return protoreflect.ValueOfList(&_MsgRequest_22_list{}) + } + listValue := &_MsgRequest_22_list{list: &x.Uints} + return protoreflect.ValueOfList(listValue) + case "testpb.MsgRequest.strings": + if len(x.Strings) == 0 { + return protoreflect.ValueOfList(&_MsgRequest_23_list{}) + } + listValue := &_MsgRequest_23_list{list: &x.Strings} + return protoreflect.ValueOfList(listValue) + case "testpb.MsgRequest.enums": + if len(x.Enums) == 0 { + return protoreflect.ValueOfList(&_MsgRequest_24_list{}) + } + listValue := &_MsgRequest_24_list{list: &x.Enums} + return protoreflect.ValueOfList(listValue) + case "testpb.MsgRequest.durations": + if len(x.Durations) == 0 { + return protoreflect.ValueOfList(&_MsgRequest_25_list{}) + } + listValue := &_MsgRequest_25_list{list: &x.Durations} + return protoreflect.ValueOfList(listValue) + case "testpb.MsgRequest.some_messages": + if len(x.SomeMessages) == 0 { + return protoreflect.ValueOfList(&_MsgRequest_26_list{}) + } + listValue := &_MsgRequest_26_list{list: &x.SomeMessages} + return protoreflect.ValueOfList(listValue) + case "testpb.MsgRequest.positional1": + value := x.Positional1 + return protoreflect.ValueOfInt32(value) + case "testpb.MsgRequest.positional2": + value := x.Positional2 + return protoreflect.ValueOfString(value) + case "testpb.MsgRequest.positional3_varargs": + if len(x.Positional3Varargs) == 0 { + return protoreflect.ValueOfList(&_MsgRequest_29_list{}) + } + listValue := &_MsgRequest_29_list{list: &x.Positional3Varargs} + return protoreflect.ValueOfList(listValue) + case "testpb.MsgRequest.deprecated_field": + value := x.DeprecatedField + return protoreflect.ValueOfString(value) + case "testpb.MsgRequest.shorthand_deprecated_field": + value := x.ShorthandDeprecatedField + return protoreflect.ValueOfString(value) + case "testpb.MsgRequest.hidden_bool": + value := x.HiddenBool + return protoreflect.ValueOfBool(value) + case "testpb.MsgRequest.a_validator_address": + value := x.AValidatorAddress + return protoreflect.ValueOfString(value) + default: + if descriptor.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.MsgRequest")) + } + panic(fmt.Errorf("message testpb.MsgRequest does not contain field %s", descriptor.FullName())) + } +} + +// Set stores the value for a field. +// +// For a field belonging to a oneof, it implicitly clears any other field +// that may be currently set within the same oneof. +// For extension fields, it implicitly stores the provided ExtensionType. +// When setting a composite type, it is unspecified whether the stored value +// aliases the source's memory in any way. If the composite value is an +// empty, read-only value, then it panics. +// +// Set is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_MsgRequest) Set(fd protoreflect.FieldDescriptor, value protoreflect.Value) { + switch fd.FullName() { + case "testpb.MsgRequest.u32": + x.U32 = uint32(value.Uint()) + case "testpb.MsgRequest.u64": + x.U64 = value.Uint() + case "testpb.MsgRequest.str": + x.Str = value.Interface().(string) + case "testpb.MsgRequest.bz": + x.Bz = value.Bytes() + case "testpb.MsgRequest.timestamp": + x.Timestamp = value.Message().Interface().(*timestamppb.Timestamp) + case "testpb.MsgRequest.duration": + x.Duration = value.Message().Interface().(*durationpb.Duration) + case "testpb.MsgRequest.i32": + x.I32 = int32(value.Int()) + case "testpb.MsgRequest.i64": + x.I64 = value.Int() + case "testpb.MsgRequest.a_bool": + x.ABool = value.Bool() + case "testpb.MsgRequest.an_enum": + x.AnEnum = (Enum)(value.Enum()) + case "testpb.MsgRequest.a_message": + x.AMessage = value.Message().Interface().(*AMessage) + case "testpb.MsgRequest.a_coin": + x.ACoin = value.Message().Interface().(*v1beta1.Coin) + case "testpb.MsgRequest.an_address": + x.AnAddress = value.Interface().(string) + case "testpb.MsgRequest.page": + x.Page = value.Message().Interface().(*v1beta11.PageRequest) + case "testpb.MsgRequest.bools": + lv := value.List() + clv := lv.(*_MsgRequest_21_list) + x.Bools = *clv.list + case "testpb.MsgRequest.uints": + lv := value.List() + clv := lv.(*_MsgRequest_22_list) + x.Uints = *clv.list + case "testpb.MsgRequest.strings": + lv := value.List() + clv := lv.(*_MsgRequest_23_list) + x.Strings = *clv.list + case "testpb.MsgRequest.enums": + lv := value.List() + clv := lv.(*_MsgRequest_24_list) + x.Enums = *clv.list + case "testpb.MsgRequest.durations": + lv := value.List() + clv := lv.(*_MsgRequest_25_list) + x.Durations = *clv.list + case "testpb.MsgRequest.some_messages": + lv := value.List() + clv := lv.(*_MsgRequest_26_list) + x.SomeMessages = *clv.list + case "testpb.MsgRequest.positional1": + x.Positional1 = int32(value.Int()) + case "testpb.MsgRequest.positional2": + x.Positional2 = value.Interface().(string) + case "testpb.MsgRequest.positional3_varargs": + lv := value.List() + clv := lv.(*_MsgRequest_29_list) + x.Positional3Varargs = *clv.list + case "testpb.MsgRequest.deprecated_field": + x.DeprecatedField = value.Interface().(string) + case "testpb.MsgRequest.shorthand_deprecated_field": + x.ShorthandDeprecatedField = value.Interface().(string) + case "testpb.MsgRequest.hidden_bool": + x.HiddenBool = value.Bool() + case "testpb.MsgRequest.a_validator_address": + x.AValidatorAddress = value.Interface().(string) + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.MsgRequest")) + } + panic(fmt.Errorf("message testpb.MsgRequest does not contain field %s", fd.FullName())) + } +} + +// Mutable returns a mutable reference to a composite type. +// +// If the field is unpopulated, it may allocate a composite value. +// For a field belonging to a oneof, it implicitly clears any other field +// that may be currently set within the same oneof. +// For extension fields, it implicitly stores the provided ExtensionType +// if not already stored. +// It panics if the field does not contain a composite type. +// +// Mutable is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_MsgRequest) Mutable(fd protoreflect.FieldDescriptor) protoreflect.Value { + switch fd.FullName() { + case "testpb.MsgRequest.timestamp": + if x.Timestamp == nil { + x.Timestamp = new(timestamppb.Timestamp) + } + return protoreflect.ValueOfMessage(x.Timestamp.ProtoReflect()) + case "testpb.MsgRequest.duration": + if x.Duration == nil { + x.Duration = new(durationpb.Duration) + } + return protoreflect.ValueOfMessage(x.Duration.ProtoReflect()) + case "testpb.MsgRequest.a_message": + if x.AMessage == nil { + x.AMessage = new(AMessage) + } + return protoreflect.ValueOfMessage(x.AMessage.ProtoReflect()) + case "testpb.MsgRequest.a_coin": + if x.ACoin == nil { + x.ACoin = new(v1beta1.Coin) + } + return protoreflect.ValueOfMessage(x.ACoin.ProtoReflect()) + case "testpb.MsgRequest.page": + if x.Page == nil { + x.Page = new(v1beta11.PageRequest) + } + return protoreflect.ValueOfMessage(x.Page.ProtoReflect()) + case "testpb.MsgRequest.bools": + if x.Bools == nil { + x.Bools = []bool{} + } + value := &_MsgRequest_21_list{list: &x.Bools} + return protoreflect.ValueOfList(value) + case "testpb.MsgRequest.uints": + if x.Uints == nil { + x.Uints = []uint32{} + } + value := &_MsgRequest_22_list{list: &x.Uints} + return protoreflect.ValueOfList(value) + case "testpb.MsgRequest.strings": + if x.Strings == nil { + x.Strings = []string{} + } + value := &_MsgRequest_23_list{list: &x.Strings} + return protoreflect.ValueOfList(value) + case "testpb.MsgRequest.enums": + if x.Enums == nil { + x.Enums = []Enum{} + } + value := &_MsgRequest_24_list{list: &x.Enums} + return protoreflect.ValueOfList(value) + case "testpb.MsgRequest.durations": + if x.Durations == nil { + x.Durations = []*durationpb.Duration{} + } + value := &_MsgRequest_25_list{list: &x.Durations} + return protoreflect.ValueOfList(value) + case "testpb.MsgRequest.some_messages": + if x.SomeMessages == nil { + x.SomeMessages = []*AMessage{} + } + value := &_MsgRequest_26_list{list: &x.SomeMessages} + return protoreflect.ValueOfList(value) + case "testpb.MsgRequest.positional3_varargs": + if x.Positional3Varargs == nil { + x.Positional3Varargs = []*v1beta1.Coin{} + } + value := &_MsgRequest_29_list{list: &x.Positional3Varargs} + return protoreflect.ValueOfList(value) + case "testpb.MsgRequest.u32": + panic(fmt.Errorf("field u32 of message testpb.MsgRequest is not mutable")) + case "testpb.MsgRequest.u64": + panic(fmt.Errorf("field u64 of message testpb.MsgRequest is not mutable")) + case "testpb.MsgRequest.str": + panic(fmt.Errorf("field str of message testpb.MsgRequest is not mutable")) + case "testpb.MsgRequest.bz": + panic(fmt.Errorf("field bz of message testpb.MsgRequest is not mutable")) + case "testpb.MsgRequest.i32": + panic(fmt.Errorf("field i32 of message testpb.MsgRequest is not mutable")) + case "testpb.MsgRequest.i64": + panic(fmt.Errorf("field i64 of message testpb.MsgRequest is not mutable")) + case "testpb.MsgRequest.a_bool": + panic(fmt.Errorf("field a_bool of message testpb.MsgRequest is not mutable")) + case "testpb.MsgRequest.an_enum": + panic(fmt.Errorf("field an_enum of message testpb.MsgRequest is not mutable")) + case "testpb.MsgRequest.an_address": + panic(fmt.Errorf("field an_address of message testpb.MsgRequest is not mutable")) + case "testpb.MsgRequest.positional1": + panic(fmt.Errorf("field positional1 of message testpb.MsgRequest is not mutable")) + case "testpb.MsgRequest.positional2": + panic(fmt.Errorf("field positional2 of message testpb.MsgRequest is not mutable")) + case "testpb.MsgRequest.deprecated_field": + panic(fmt.Errorf("field deprecated_field of message testpb.MsgRequest is not mutable")) + case "testpb.MsgRequest.shorthand_deprecated_field": + panic(fmt.Errorf("field shorthand_deprecated_field of message testpb.MsgRequest is not mutable")) + case "testpb.MsgRequest.hidden_bool": + panic(fmt.Errorf("field hidden_bool of message testpb.MsgRequest is not mutable")) + case "testpb.MsgRequest.a_validator_address": + panic(fmt.Errorf("field a_validator_address of message testpb.MsgRequest is not mutable")) + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.MsgRequest")) + } + panic(fmt.Errorf("message testpb.MsgRequest does not contain field %s", fd.FullName())) + } +} + +// NewField returns a new value that is assignable to the field +// for the given descriptor. For scalars, this returns the default value. +// For lists, maps, and messages, this returns a new, empty, mutable value. +func (x *fastReflection_MsgRequest) NewField(fd protoreflect.FieldDescriptor) protoreflect.Value { + switch fd.FullName() { + case "testpb.MsgRequest.u32": + return protoreflect.ValueOfUint32(uint32(0)) + case "testpb.MsgRequest.u64": + return protoreflect.ValueOfUint64(uint64(0)) + case "testpb.MsgRequest.str": + return protoreflect.ValueOfString("") + case "testpb.MsgRequest.bz": + return protoreflect.ValueOfBytes(nil) + case "testpb.MsgRequest.timestamp": + m := new(timestamppb.Timestamp) + return protoreflect.ValueOfMessage(m.ProtoReflect()) + case "testpb.MsgRequest.duration": + m := new(durationpb.Duration) + return protoreflect.ValueOfMessage(m.ProtoReflect()) + case "testpb.MsgRequest.i32": + return protoreflect.ValueOfInt32(int32(0)) + case "testpb.MsgRequest.i64": + return protoreflect.ValueOfInt64(int64(0)) + case "testpb.MsgRequest.a_bool": + return protoreflect.ValueOfBool(false) + case "testpb.MsgRequest.an_enum": + return protoreflect.ValueOfEnum(0) + case "testpb.MsgRequest.a_message": + m := new(AMessage) + return protoreflect.ValueOfMessage(m.ProtoReflect()) + case "testpb.MsgRequest.a_coin": + m := new(v1beta1.Coin) + return protoreflect.ValueOfMessage(m.ProtoReflect()) + case "testpb.MsgRequest.an_address": + return protoreflect.ValueOfString("") + case "testpb.MsgRequest.page": + m := new(v1beta11.PageRequest) + return protoreflect.ValueOfMessage(m.ProtoReflect()) + case "testpb.MsgRequest.bools": + list := []bool{} + return protoreflect.ValueOfList(&_MsgRequest_21_list{list: &list}) + case "testpb.MsgRequest.uints": + list := []uint32{} + return protoreflect.ValueOfList(&_MsgRequest_22_list{list: &list}) + case "testpb.MsgRequest.strings": + list := []string{} + return protoreflect.ValueOfList(&_MsgRequest_23_list{list: &list}) + case "testpb.MsgRequest.enums": + list := []Enum{} + return protoreflect.ValueOfList(&_MsgRequest_24_list{list: &list}) + case "testpb.MsgRequest.durations": + list := []*durationpb.Duration{} + return protoreflect.ValueOfList(&_MsgRequest_25_list{list: &list}) + case "testpb.MsgRequest.some_messages": + list := []*AMessage{} + return protoreflect.ValueOfList(&_MsgRequest_26_list{list: &list}) + case "testpb.MsgRequest.positional1": + return protoreflect.ValueOfInt32(int32(0)) + case "testpb.MsgRequest.positional2": + return protoreflect.ValueOfString("") + case "testpb.MsgRequest.positional3_varargs": + list := []*v1beta1.Coin{} + return protoreflect.ValueOfList(&_MsgRequest_29_list{list: &list}) + case "testpb.MsgRequest.deprecated_field": + return protoreflect.ValueOfString("") + case "testpb.MsgRequest.shorthand_deprecated_field": + return protoreflect.ValueOfString("") + case "testpb.MsgRequest.hidden_bool": + return protoreflect.ValueOfBool(false) + case "testpb.MsgRequest.a_validator_address": + return protoreflect.ValueOfString("") + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.MsgRequest")) + } + panic(fmt.Errorf("message testpb.MsgRequest does not contain field %s", fd.FullName())) + } +} + +// WhichOneof reports which field within the oneof is populated, +// returning nil if none are populated. +// It panics if the oneof descriptor does not belong to this message. +func (x *fastReflection_MsgRequest) WhichOneof(d protoreflect.OneofDescriptor) protoreflect.FieldDescriptor { + switch d.FullName() { + default: + panic(fmt.Errorf("%s is not a oneof field in testpb.MsgRequest", d.FullName())) + } + panic("unreachable") +} + +// GetUnknown retrieves the entire list of unknown fields. +// The caller may only mutate the contents of the RawFields +// if the mutated bytes are stored back into the message with SetUnknown. +func (x *fastReflection_MsgRequest) GetUnknown() protoreflect.RawFields { + return x.unknownFields +} + +// SetUnknown stores an entire list of unknown fields. +// The raw fields must be syntactically valid according to the wire format. +// An implementation may panic if this is not the case. +// Once stored, the caller must not mutate the content of the RawFields. +// An empty RawFields may be passed to clear the fields. +// +// SetUnknown is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_MsgRequest) SetUnknown(fields protoreflect.RawFields) { + x.unknownFields = fields +} + +// IsValid reports whether the message is valid. +// +// An invalid message is an empty, read-only value. +// +// An invalid message often corresponds to a nil pointer of the concrete +// message type, but the details are implementation dependent. +// Validity is not part of the protobuf data model, and may not +// be preserved in marshaling or other operations. +func (x *fastReflection_MsgRequest) IsValid() bool { + return x != nil +} + +// ProtoMethods returns optional fastReflectionFeature-path implementations of various operations. +// This method may return nil. +// +// The returned methods type is identical to +// "google.golang.org/protobuf/runtime/protoiface".Methods. +// Consult the protoiface package documentation for details. +func (x *fastReflection_MsgRequest) ProtoMethods() *protoiface.Methods { + size := func(input protoiface.SizeInput) protoiface.SizeOutput { + x := input.Message.Interface().(*MsgRequest) + if x == nil { + return protoiface.SizeOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Size: 0, + } + } + options := runtime.SizeInputToOptions(input) + _ = options + var n int + var l int + _ = l + if x.U32 != 0 { + n += 1 + runtime.Sov(uint64(x.U32)) + } + if x.U64 != 0 { + n += 1 + runtime.Sov(uint64(x.U64)) + } + l = len(x.Str) + if l > 0 { + n += 1 + l + runtime.Sov(uint64(l)) + } + l = len(x.Bz) + if l > 0 { + n += 1 + l + runtime.Sov(uint64(l)) + } + if x.Timestamp != nil { + l = options.Size(x.Timestamp) + n += 1 + l + runtime.Sov(uint64(l)) + } + if x.Duration != nil { + l = options.Size(x.Duration) + n += 1 + l + runtime.Sov(uint64(l)) + } + if x.I32 != 0 { + n += 1 + runtime.Sov(uint64(x.I32)) + } + if x.I64 != 0 { + n += 1 + runtime.Sov(uint64(x.I64)) + } + if x.ABool { + n += 2 + } + if x.AnEnum != 0 { + n += 2 + runtime.Sov(uint64(x.AnEnum)) + } + if x.AMessage != nil { + l = options.Size(x.AMessage) + n += 2 + l + runtime.Sov(uint64(l)) + } + if x.ACoin != nil { + l = options.Size(x.ACoin) + n += 2 + l + runtime.Sov(uint64(l)) + } + l = len(x.AnAddress) + if l > 0 { + n += 2 + l + runtime.Sov(uint64(l)) + } + if x.Page != nil { + l = options.Size(x.Page) + n += 2 + l + runtime.Sov(uint64(l)) + } + if len(x.Bools) > 0 { + n += 2 + runtime.Sov(uint64(len(x.Bools))) + len(x.Bools)*1 + } + if len(x.Uints) > 0 { + l = 0 + for _, e := range x.Uints { + l += runtime.Sov(uint64(e)) + } + n += 2 + runtime.Sov(uint64(l)) + l + } + if len(x.Strings) > 0 { + for _, s := range x.Strings { + l = len(s) + n += 2 + l + runtime.Sov(uint64(l)) + } + } + if len(x.Enums) > 0 { + l = 0 + for _, e := range x.Enums { + l += runtime.Sov(uint64(e)) + } + n += 2 + runtime.Sov(uint64(l)) + l + } + if len(x.Durations) > 0 { + for _, e := range x.Durations { + l = options.Size(e) + n += 2 + l + runtime.Sov(uint64(l)) + } + } + if len(x.SomeMessages) > 0 { + for _, e := range x.SomeMessages { + l = options.Size(e) + n += 2 + l + runtime.Sov(uint64(l)) + } + } + if x.Positional1 != 0 { + n += 2 + runtime.Sov(uint64(x.Positional1)) + } + l = len(x.Positional2) + if l > 0 { + n += 2 + l + runtime.Sov(uint64(l)) + } + if len(x.Positional3Varargs) > 0 { + for _, e := range x.Positional3Varargs { + l = options.Size(e) + n += 2 + l + runtime.Sov(uint64(l)) + } + } + l = len(x.DeprecatedField) + if l > 0 { + n += 2 + l + runtime.Sov(uint64(l)) + } + l = len(x.ShorthandDeprecatedField) + if l > 0 { + n += 2 + l + runtime.Sov(uint64(l)) + } + if x.HiddenBool { + n += 3 + } + l = len(x.AValidatorAddress) + if l > 0 { + n += 2 + l + runtime.Sov(uint64(l)) + } + if x.unknownFields != nil { + n += len(x.unknownFields) + } + return protoiface.SizeOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Size: n, + } + } + + marshal := func(input protoiface.MarshalInput) (protoiface.MarshalOutput, error) { + x := input.Message.Interface().(*MsgRequest) + if x == nil { + return protoiface.MarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Buf: input.Buf, + }, nil + } + options := runtime.MarshalInputToOptions(input) + _ = options + size := options.Size(x) + dAtA := make([]byte, size) + i := len(dAtA) + _ = i + var l int + _ = l + if x.unknownFields != nil { + i -= len(x.unknownFields) + copy(dAtA[i:], x.unknownFields) + } + if len(x.AValidatorAddress) > 0 { + i -= len(x.AValidatorAddress) + copy(dAtA[i:], x.AValidatorAddress) + i = runtime.EncodeVarint(dAtA, i, uint64(len(x.AValidatorAddress))) + i-- + dAtA[i] = 0x2 + i-- + dAtA[i] = 0x8a + } + if x.HiddenBool { + i-- + if x.HiddenBool { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x2 + i-- + dAtA[i] = 0x80 + } + if len(x.ShorthandDeprecatedField) > 0 { + i -= len(x.ShorthandDeprecatedField) + copy(dAtA[i:], x.ShorthandDeprecatedField) + i = runtime.EncodeVarint(dAtA, i, uint64(len(x.ShorthandDeprecatedField))) + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0xfa + } + if len(x.DeprecatedField) > 0 { + i -= len(x.DeprecatedField) + copy(dAtA[i:], x.DeprecatedField) + i = runtime.EncodeVarint(dAtA, i, uint64(len(x.DeprecatedField))) + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0xf2 + } + if len(x.Positional3Varargs) > 0 { + for iNdEx := len(x.Positional3Varargs) - 1; iNdEx >= 0; iNdEx-- { + encoded, err := options.Marshal(x.Positional3Varargs[iNdEx]) + if err != nil { + return protoiface.MarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Buf: input.Buf, + }, err + } + i -= len(encoded) + copy(dAtA[i:], encoded) + i = runtime.EncodeVarint(dAtA, i, uint64(len(encoded))) + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0xea + } + } + if len(x.Positional2) > 0 { + i -= len(x.Positional2) + copy(dAtA[i:], x.Positional2) + i = runtime.EncodeVarint(dAtA, i, uint64(len(x.Positional2))) + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0xe2 + } + if x.Positional1 != 0 { + i = runtime.EncodeVarint(dAtA, i, uint64(x.Positional1)) + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0xd8 + } + if len(x.SomeMessages) > 0 { + for iNdEx := len(x.SomeMessages) - 1; iNdEx >= 0; iNdEx-- { + encoded, err := options.Marshal(x.SomeMessages[iNdEx]) + if err != nil { + return protoiface.MarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Buf: input.Buf, + }, err + } + i -= len(encoded) + copy(dAtA[i:], encoded) + i = runtime.EncodeVarint(dAtA, i, uint64(len(encoded))) + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0xd2 + } + } + if len(x.Durations) > 0 { + for iNdEx := len(x.Durations) - 1; iNdEx >= 0; iNdEx-- { + encoded, err := options.Marshal(x.Durations[iNdEx]) + if err != nil { + return protoiface.MarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Buf: input.Buf, + }, err + } + i -= len(encoded) + copy(dAtA[i:], encoded) + i = runtime.EncodeVarint(dAtA, i, uint64(len(encoded))) + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0xca + } + } + if len(x.Enums) > 0 { + var pksize2 int + for _, num := range x.Enums { + pksize2 += runtime.Sov(uint64(num)) + } + i -= pksize2 + j1 := i + for _, num1 := range x.Enums { + num := uint64(num1) + for num >= 1<<7 { + dAtA[j1] = uint8(uint64(num)&0x7f | 0x80) + num >>= 7 + j1++ + } + dAtA[j1] = uint8(num) + j1++ + } + i = runtime.EncodeVarint(dAtA, i, uint64(pksize2)) + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0xc2 + } + if len(x.Strings) > 0 { + for iNdEx := len(x.Strings) - 1; iNdEx >= 0; iNdEx-- { + i -= len(x.Strings[iNdEx]) + copy(dAtA[i:], x.Strings[iNdEx]) + i = runtime.EncodeVarint(dAtA, i, uint64(len(x.Strings[iNdEx]))) + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0xba + } + } + if len(x.Uints) > 0 { + var pksize4 int + for _, num := range x.Uints { + pksize4 += runtime.Sov(uint64(num)) + } + i -= pksize4 + j3 := i + for _, num := range x.Uints { + for num >= 1<<7 { + dAtA[j3] = uint8(uint64(num)&0x7f | 0x80) + num >>= 7 + j3++ + } + dAtA[j3] = uint8(num) + j3++ + } + i = runtime.EncodeVarint(dAtA, i, uint64(pksize4)) + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0xb2 + } + if len(x.Bools) > 0 { + for iNdEx := len(x.Bools) - 1; iNdEx >= 0; iNdEx-- { + i-- + if x.Bools[iNdEx] { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + } + i = runtime.EncodeVarint(dAtA, i, uint64(len(x.Bools))) + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0xaa + } + if x.Page != nil { + encoded, err := options.Marshal(x.Page) + if err != nil { + return protoiface.MarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Buf: input.Buf, + }, err + } + i -= len(encoded) + copy(dAtA[i:], encoded) + i = runtime.EncodeVarint(dAtA, i, uint64(len(encoded))) + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0xa2 + } + if len(x.AnAddress) > 0 { + i -= len(x.AnAddress) + copy(dAtA[i:], x.AnAddress) + i = runtime.EncodeVarint(dAtA, i, uint64(len(x.AnAddress))) + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0x9a + } + if x.ACoin != nil { + encoded, err := options.Marshal(x.ACoin) + if err != nil { + return protoiface.MarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Buf: input.Buf, + }, err + } + i -= len(encoded) + copy(dAtA[i:], encoded) + i = runtime.EncodeVarint(dAtA, i, uint64(len(encoded))) + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0x92 + } + if x.AMessage != nil { + encoded, err := options.Marshal(x.AMessage) + if err != nil { + return protoiface.MarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Buf: input.Buf, + }, err + } + i -= len(encoded) + copy(dAtA[i:], encoded) + i = runtime.EncodeVarint(dAtA, i, uint64(len(encoded))) + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0x8a + } + if x.AnEnum != 0 { + i = runtime.EncodeVarint(dAtA, i, uint64(x.AnEnum)) + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0x80 + } + if x.ABool { + i-- + if x.ABool { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x78 + } + if x.I64 != 0 { + i = runtime.EncodeVarint(dAtA, i, uint64(x.I64)) + i-- + dAtA[i] = 0x50 + } + if x.I32 != 0 { + i = runtime.EncodeVarint(dAtA, i, uint64(x.I32)) + i-- + dAtA[i] = 0x38 + } + if x.Duration != nil { + encoded, err := options.Marshal(x.Duration) + if err != nil { + return protoiface.MarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Buf: input.Buf, + }, err + } + i -= len(encoded) + copy(dAtA[i:], encoded) + i = runtime.EncodeVarint(dAtA, i, uint64(len(encoded))) + i-- + dAtA[i] = 0x32 + } + if x.Timestamp != nil { + encoded, err := options.Marshal(x.Timestamp) + if err != nil { + return protoiface.MarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Buf: input.Buf, + }, err + } + i -= len(encoded) + copy(dAtA[i:], encoded) + i = runtime.EncodeVarint(dAtA, i, uint64(len(encoded))) + i-- + dAtA[i] = 0x2a + } + if len(x.Bz) > 0 { + i -= len(x.Bz) + copy(dAtA[i:], x.Bz) + i = runtime.EncodeVarint(dAtA, i, uint64(len(x.Bz))) + i-- + dAtA[i] = 0x22 + } + if len(x.Str) > 0 { + i -= len(x.Str) + copy(dAtA[i:], x.Str) + i = runtime.EncodeVarint(dAtA, i, uint64(len(x.Str))) + i-- + dAtA[i] = 0x1a + } + if x.U64 != 0 { + i = runtime.EncodeVarint(dAtA, i, uint64(x.U64)) + i-- + dAtA[i] = 0x10 + } + if x.U32 != 0 { + i = runtime.EncodeVarint(dAtA, i, uint64(x.U32)) + i-- + dAtA[i] = 0x8 + } + if input.Buf != nil { + input.Buf = append(input.Buf, dAtA...) + } else { + input.Buf = dAtA + } + return protoiface.MarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Buf: input.Buf, + }, nil + } + unmarshal := func(input protoiface.UnmarshalInput) (protoiface.UnmarshalOutput, error) { + x := input.Message.Interface().(*MsgRequest) + if x == nil { + return protoiface.UnmarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Flags: input.Flags, + }, nil + } + options := runtime.UnmarshalInputToOptions(input) + _ = options + dAtA := input.Buf + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: MsgRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: MsgRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field U32", wireType) + } + x.U32 = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + x.U32 |= uint32(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field U64", wireType) + } + x.U64 = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + x.U64 |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Str", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if postIndex > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + x.Str = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 4: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Bz", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if postIndex > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + x.Bz = append(x.Bz[:0], dAtA[iNdEx:postIndex]...) + if x.Bz == nil { + x.Bz = []byte{} + } + iNdEx = postIndex + case 5: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Timestamp", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if postIndex > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + if x.Timestamp == nil { + x.Timestamp = ×tamppb.Timestamp{} + } + if err := options.Unmarshal(dAtA[iNdEx:postIndex], x.Timestamp); err != nil { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err + } + iNdEx = postIndex + case 6: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Duration", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if postIndex > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + if x.Duration == nil { + x.Duration = &durationpb.Duration{} + } + if err := options.Unmarshal(dAtA[iNdEx:postIndex], x.Duration); err != nil { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err + } + iNdEx = postIndex + case 7: + if wireType != 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field I32", wireType) + } + x.I32 = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + x.I32 |= int32(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 10: + if wireType != 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field I64", wireType) + } + x.I64 = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + x.I64 |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 15: + if wireType != 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field ABool", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + x.ABool = bool(v != 0) + case 16: + if wireType != 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field AnEnum", wireType) + } + x.AnEnum = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + x.AnEnum |= Enum(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 17: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field AMessage", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if postIndex > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + if x.AMessage == nil { + x.AMessage = &AMessage{} + } + if err := options.Unmarshal(dAtA[iNdEx:postIndex], x.AMessage); err != nil { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err + } + iNdEx = postIndex + case 18: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field ACoin", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if postIndex > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + if x.ACoin == nil { + x.ACoin = &v1beta1.Coin{} + } + if err := options.Unmarshal(dAtA[iNdEx:postIndex], x.ACoin); err != nil { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err + } + iNdEx = postIndex + case 19: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field AnAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if postIndex > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + x.AnAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 20: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Page", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if postIndex > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + if x.Page == nil { + x.Page = &v1beta11.PageRequest{} + } + if err := options.Unmarshal(dAtA[iNdEx:postIndex], x.Page); err != nil { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err + } + iNdEx = postIndex + case 21: + if wireType == 0 { + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + x.Bools = append(x.Bools, bool(v != 0)) + } else if wireType == 2 { + var packedLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + packedLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if packedLen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postIndex := iNdEx + packedLen + if postIndex < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if postIndex > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + var elementCount int + elementCount = packedLen + if elementCount != 0 && len(x.Bools) == 0 { + x.Bools = make([]bool, 0, elementCount) + } + for iNdEx < postIndex { + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + x.Bools = append(x.Bools, bool(v != 0)) + } + } else { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Bools", wireType) + } + case 22: + if wireType == 0 { + var v uint32 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= uint32(b&0x7F) << shift + if b < 0x80 { + break + } + } + x.Uints = append(x.Uints, v) + } else if wireType == 2 { + var packedLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + packedLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if packedLen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postIndex := iNdEx + packedLen + if postIndex < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if postIndex > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + var elementCount int + var count int + for _, integer := range dAtA[iNdEx:postIndex] { + if integer < 128 { + count++ + } + } + elementCount = count + if elementCount != 0 && len(x.Uints) == 0 { + x.Uints = make([]uint32, 0, elementCount) + } + for iNdEx < postIndex { + var v uint32 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= uint32(b&0x7F) << shift + if b < 0x80 { + break + } + } + x.Uints = append(x.Uints, v) + } + } else { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Uints", wireType) + } + case 23: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Strings", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if postIndex > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + x.Strings = append(x.Strings, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex + case 24: + if wireType == 0 { + var v Enum + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= Enum(b&0x7F) << shift + if b < 0x80 { + break + } + } + x.Enums = append(x.Enums, v) + } else if wireType == 2 { + var packedLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + packedLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if packedLen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postIndex := iNdEx + packedLen + if postIndex < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if postIndex > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + var elementCount int + if elementCount != 0 && len(x.Enums) == 0 { + x.Enums = make([]Enum, 0, elementCount) + } + for iNdEx < postIndex { + var v Enum + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= Enum(b&0x7F) << shift + if b < 0x80 { + break + } + } + x.Enums = append(x.Enums, v) + } + } else { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Enums", wireType) + } + case 25: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Durations", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if postIndex > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + x.Durations = append(x.Durations, &durationpb.Duration{}) + if err := options.Unmarshal(dAtA[iNdEx:postIndex], x.Durations[len(x.Durations)-1]); err != nil { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err + } + iNdEx = postIndex + case 26: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field SomeMessages", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if postIndex > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + x.SomeMessages = append(x.SomeMessages, &AMessage{}) + if err := options.Unmarshal(dAtA[iNdEx:postIndex], x.SomeMessages[len(x.SomeMessages)-1]); err != nil { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err + } + iNdEx = postIndex + case 27: + if wireType != 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Positional1", wireType) + } + x.Positional1 = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + x.Positional1 |= int32(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 28: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Positional2", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if postIndex > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + x.Positional2 = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 29: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Positional3Varargs", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if postIndex > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + x.Positional3Varargs = append(x.Positional3Varargs, &v1beta1.Coin{}) + if err := options.Unmarshal(dAtA[iNdEx:postIndex], x.Positional3Varargs[len(x.Positional3Varargs)-1]); err != nil { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err + } + iNdEx = postIndex + case 30: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field DeprecatedField", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if postIndex > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + x.DeprecatedField = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 31: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field ShorthandDeprecatedField", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if postIndex > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + x.ShorthandDeprecatedField = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 32: + if wireType != 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field HiddenBool", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + x.HiddenBool = bool(v != 0) + case 33: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field AValidatorAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if postIndex > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + x.AValidatorAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := runtime.Skip(dAtA[iNdEx:]) + if err != nil { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if (iNdEx + skippy) > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + if !options.DiscardUnknown { + x.unknownFields = append(x.unknownFields, dAtA[iNdEx:iNdEx+skippy]...) + } + iNdEx += skippy + } + } + + if iNdEx > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, nil + } + return &protoiface.Methods{ + NoUnkeyedLiterals: struct{}{}, + Flags: protoiface.SupportMarshalDeterministic | protoiface.SupportUnmarshalDiscardUnknown, + Size: size, + Marshal: marshal, + Unmarshal: unmarshal, + Merge: nil, + CheckInitialized: nil, + } +} + +var ( + md_MsgResponse protoreflect.MessageDescriptor + fd_MsgResponse_request protoreflect.FieldDescriptor +) + +func init() { + file_testpb_msg_proto_init() + md_MsgResponse = File_testpb_msg_proto.Messages().ByName("MsgResponse") + fd_MsgResponse_request = md_MsgResponse.Fields().ByName("request") +} + +var _ protoreflect.Message = (*fastReflection_MsgResponse)(nil) + +type fastReflection_MsgResponse MsgResponse + +func (x *MsgResponse) ProtoReflect() protoreflect.Message { + return (*fastReflection_MsgResponse)(x) +} + +func (x *MsgResponse) slowProtoReflect() protoreflect.Message { + mi := &file_testpb_msg_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +var _fastReflection_MsgResponse_messageType fastReflection_MsgResponse_messageType +var _ protoreflect.MessageType = fastReflection_MsgResponse_messageType{} + +type fastReflection_MsgResponse_messageType struct{} + +func (x fastReflection_MsgResponse_messageType) Zero() protoreflect.Message { + return (*fastReflection_MsgResponse)(nil) +} +func (x fastReflection_MsgResponse_messageType) New() protoreflect.Message { + return new(fastReflection_MsgResponse) +} +func (x fastReflection_MsgResponse_messageType) Descriptor() protoreflect.MessageDescriptor { + return md_MsgResponse +} + +// Descriptor returns message descriptor, which contains only the protobuf +// type information for the message. +func (x *fastReflection_MsgResponse) Descriptor() protoreflect.MessageDescriptor { + return md_MsgResponse +} + +// Type returns the message type, which encapsulates both Go and protobuf +// type information. If the Go type information is not needed, +// it is recommended that the message descriptor be used instead. +func (x *fastReflection_MsgResponse) Type() protoreflect.MessageType { + return _fastReflection_MsgResponse_messageType +} + +// New returns a newly allocated and mutable empty message. +func (x *fastReflection_MsgResponse) New() protoreflect.Message { + return new(fastReflection_MsgResponse) +} + +// Interface unwraps the message reflection interface and +// returns the underlying ProtoMessage interface. +func (x *fastReflection_MsgResponse) Interface() protoreflect.ProtoMessage { + return (*MsgResponse)(x) +} + +// Range iterates over every populated field in an undefined order, +// calling f for each field descriptor and value encountered. +// Range returns immediately if f returns false. +// While iterating, mutating operations may only be performed +// on the current field descriptor. +func (x *fastReflection_MsgResponse) Range(f func(protoreflect.FieldDescriptor, protoreflect.Value) bool) { + if x.Request != nil { + value := protoreflect.ValueOfMessage(x.Request.ProtoReflect()) + if !f(fd_MsgResponse_request, value) { + return + } + } +} + +// Has reports whether a field is populated. +// +// Some fields have the property of nullability where it is possible to +// distinguish between the default value of a field and whether the field +// was explicitly populated with the default value. Singular message fields, +// member fields of a oneof, and proto2 scalar fields are nullable. Such +// fields are populated only if explicitly set. +// +// In other cases (aside from the nullable cases above), +// a proto3 scalar field is populated if it contains a non-zero value, and +// a repeated field is populated if it is non-empty. +func (x *fastReflection_MsgResponse) Has(fd protoreflect.FieldDescriptor) bool { + switch fd.FullName() { + case "testpb.MsgResponse.request": + return x.Request != nil + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.MsgResponse")) + } + panic(fmt.Errorf("message testpb.MsgResponse does not contain field %s", fd.FullName())) + } +} + +// Clear clears the field such that a subsequent Has call reports false. +// +// Clearing an extension field clears both the extension type and value +// associated with the given field number. +// +// Clear is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_MsgResponse) Clear(fd protoreflect.FieldDescriptor) { + switch fd.FullName() { + case "testpb.MsgResponse.request": + x.Request = nil + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.MsgResponse")) + } + panic(fmt.Errorf("message testpb.MsgResponse does not contain field %s", fd.FullName())) + } +} + +// Get retrieves the value for a field. +// +// For unpopulated scalars, it returns the default value, where +// the default value of a bytes scalar is guaranteed to be a copy. +// For unpopulated composite types, it returns an empty, read-only view +// of the value; to obtain a mutable reference, use Mutable. +func (x *fastReflection_MsgResponse) Get(descriptor protoreflect.FieldDescriptor) protoreflect.Value { + switch descriptor.FullName() { + case "testpb.MsgResponse.request": + value := x.Request + return protoreflect.ValueOfMessage(value.ProtoReflect()) + default: + if descriptor.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.MsgResponse")) + } + panic(fmt.Errorf("message testpb.MsgResponse does not contain field %s", descriptor.FullName())) + } +} + +// Set stores the value for a field. +// +// For a field belonging to a oneof, it implicitly clears any other field +// that may be currently set within the same oneof. +// For extension fields, it implicitly stores the provided ExtensionType. +// When setting a composite type, it is unspecified whether the stored value +// aliases the source's memory in any way. If the composite value is an +// empty, read-only value, then it panics. +// +// Set is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_MsgResponse) Set(fd protoreflect.FieldDescriptor, value protoreflect.Value) { + switch fd.FullName() { + case "testpb.MsgResponse.request": + x.Request = value.Message().Interface().(*MsgRequest) + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.MsgResponse")) + } + panic(fmt.Errorf("message testpb.MsgResponse does not contain field %s", fd.FullName())) + } +} + +// Mutable returns a mutable reference to a composite type. +// +// If the field is unpopulated, it may allocate a composite value. +// For a field belonging to a oneof, it implicitly clears any other field +// that may be currently set within the same oneof. +// For extension fields, it implicitly stores the provided ExtensionType +// if not already stored. +// It panics if the field does not contain a composite type. +// +// Mutable is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_MsgResponse) Mutable(fd protoreflect.FieldDescriptor) protoreflect.Value { + switch fd.FullName() { + case "testpb.MsgResponse.request": + if x.Request == nil { + x.Request = new(MsgRequest) + } + return protoreflect.ValueOfMessage(x.Request.ProtoReflect()) + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.MsgResponse")) + } + panic(fmt.Errorf("message testpb.MsgResponse does not contain field %s", fd.FullName())) + } +} + +// NewField returns a new value that is assignable to the field +// for the given descriptor. For scalars, this returns the default value. +// For lists, maps, and messages, this returns a new, empty, mutable value. +func (x *fastReflection_MsgResponse) NewField(fd protoreflect.FieldDescriptor) protoreflect.Value { + switch fd.FullName() { + case "testpb.MsgResponse.request": + m := new(MsgRequest) + return protoreflect.ValueOfMessage(m.ProtoReflect()) + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.MsgResponse")) + } + panic(fmt.Errorf("message testpb.MsgResponse does not contain field %s", fd.FullName())) + } +} + +// WhichOneof reports which field within the oneof is populated, +// returning nil if none are populated. +// It panics if the oneof descriptor does not belong to this message. +func (x *fastReflection_MsgResponse) WhichOneof(d protoreflect.OneofDescriptor) protoreflect.FieldDescriptor { + switch d.FullName() { + default: + panic(fmt.Errorf("%s is not a oneof field in testpb.MsgResponse", d.FullName())) + } + panic("unreachable") +} + +// GetUnknown retrieves the entire list of unknown fields. +// The caller may only mutate the contents of the RawFields +// if the mutated bytes are stored back into the message with SetUnknown. +func (x *fastReflection_MsgResponse) GetUnknown() protoreflect.RawFields { + return x.unknownFields +} + +// SetUnknown stores an entire list of unknown fields. +// The raw fields must be syntactically valid according to the wire format. +// An implementation may panic if this is not the case. +// Once stored, the caller must not mutate the content of the RawFields. +// An empty RawFields may be passed to clear the fields. +// +// SetUnknown is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_MsgResponse) SetUnknown(fields protoreflect.RawFields) { + x.unknownFields = fields +} + +// IsValid reports whether the message is valid. +// +// An invalid message is an empty, read-only value. +// +// An invalid message often corresponds to a nil pointer of the concrete +// message type, but the details are implementation dependent. +// Validity is not part of the protobuf data model, and may not +// be preserved in marshaling or other operations. +func (x *fastReflection_MsgResponse) IsValid() bool { + return x != nil +} + +// ProtoMethods returns optional fastReflectionFeature-path implementations of various operations. +// This method may return nil. +// +// The returned methods type is identical to +// "google.golang.org/protobuf/runtime/protoiface".Methods. +// Consult the protoiface package documentation for details. +func (x *fastReflection_MsgResponse) ProtoMethods() *protoiface.Methods { + size := func(input protoiface.SizeInput) protoiface.SizeOutput { + x := input.Message.Interface().(*MsgResponse) + if x == nil { + return protoiface.SizeOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Size: 0, + } + } + options := runtime.SizeInputToOptions(input) + _ = options + var n int + var l int + _ = l + if x.Request != nil { + l = options.Size(x.Request) + n += 1 + l + runtime.Sov(uint64(l)) + } + if x.unknownFields != nil { + n += len(x.unknownFields) + } + return protoiface.SizeOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Size: n, + } + } + + marshal := func(input protoiface.MarshalInput) (protoiface.MarshalOutput, error) { + x := input.Message.Interface().(*MsgResponse) + if x == nil { + return protoiface.MarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Buf: input.Buf, + }, nil + } + options := runtime.MarshalInputToOptions(input) + _ = options + size := options.Size(x) + dAtA := make([]byte, size) + i := len(dAtA) + _ = i + var l int + _ = l + if x.unknownFields != nil { + i -= len(x.unknownFields) + copy(dAtA[i:], x.unknownFields) + } + if x.Request != nil { + encoded, err := options.Marshal(x.Request) + if err != nil { + return protoiface.MarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Buf: input.Buf, + }, err + } + i -= len(encoded) + copy(dAtA[i:], encoded) + i = runtime.EncodeVarint(dAtA, i, uint64(len(encoded))) + i-- + dAtA[i] = 0xa + } + if input.Buf != nil { + input.Buf = append(input.Buf, dAtA...) + } else { + input.Buf = dAtA + } + return protoiface.MarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Buf: input.Buf, + }, nil + } + unmarshal := func(input protoiface.UnmarshalInput) (protoiface.UnmarshalOutput, error) { + x := input.Message.Interface().(*MsgResponse) + if x == nil { + return protoiface.UnmarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Flags: input.Flags, + }, nil + } + options := runtime.UnmarshalInputToOptions(input) + _ = options + dAtA := input.Buf + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: MsgResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: MsgResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Request", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if postIndex > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + if x.Request == nil { + x.Request = &MsgRequest{} + } + if err := options.Unmarshal(dAtA[iNdEx:postIndex], x.Request); err != nil { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := runtime.Skip(dAtA[iNdEx:]) + if err != nil { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if (iNdEx + skippy) > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + if !options.DiscardUnknown { + x.unknownFields = append(x.unknownFields, dAtA[iNdEx:iNdEx+skippy]...) + } + iNdEx += skippy + } + } + + if iNdEx > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, nil + } + return &protoiface.Methods{ + NoUnkeyedLiterals: struct{}{}, + Flags: protoiface.SupportMarshalDeterministic | protoiface.SupportUnmarshalDiscardUnknown, + Size: size, + Marshal: marshal, + Unmarshal: unmarshal, + Merge: nil, + CheckInitialized: nil, + } +} + +var ( + md_MsgClawbackRequest protoreflect.MessageDescriptor +) + +func init() { + file_testpb_msg_proto_init() + md_MsgClawbackRequest = File_testpb_msg_proto.Messages().ByName("MsgClawbackRequest") +} + +var _ protoreflect.Message = (*fastReflection_MsgClawbackRequest)(nil) + +type fastReflection_MsgClawbackRequest MsgClawbackRequest + +func (x *MsgClawbackRequest) ProtoReflect() protoreflect.Message { + return (*fastReflection_MsgClawbackRequest)(x) +} + +func (x *MsgClawbackRequest) slowProtoReflect() protoreflect.Message { + mi := &file_testpb_msg_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +var _fastReflection_MsgClawbackRequest_messageType fastReflection_MsgClawbackRequest_messageType +var _ protoreflect.MessageType = fastReflection_MsgClawbackRequest_messageType{} + +type fastReflection_MsgClawbackRequest_messageType struct{} + +func (x fastReflection_MsgClawbackRequest_messageType) Zero() protoreflect.Message { + return (*fastReflection_MsgClawbackRequest)(nil) +} +func (x fastReflection_MsgClawbackRequest_messageType) New() protoreflect.Message { + return new(fastReflection_MsgClawbackRequest) +} +func (x fastReflection_MsgClawbackRequest_messageType) Descriptor() protoreflect.MessageDescriptor { + return md_MsgClawbackRequest +} + +// Descriptor returns message descriptor, which contains only the protobuf +// type information for the message. +func (x *fastReflection_MsgClawbackRequest) Descriptor() protoreflect.MessageDescriptor { + return md_MsgClawbackRequest +} + +// Type returns the message type, which encapsulates both Go and protobuf +// type information. If the Go type information is not needed, +// it is recommended that the message descriptor be used instead. +func (x *fastReflection_MsgClawbackRequest) Type() protoreflect.MessageType { + return _fastReflection_MsgClawbackRequest_messageType +} + +// New returns a newly allocated and mutable empty message. +func (x *fastReflection_MsgClawbackRequest) New() protoreflect.Message { + return new(fastReflection_MsgClawbackRequest) +} + +// Interface unwraps the message reflection interface and +// returns the underlying ProtoMessage interface. +func (x *fastReflection_MsgClawbackRequest) Interface() protoreflect.ProtoMessage { + return (*MsgClawbackRequest)(x) +} + +// Range iterates over every populated field in an undefined order, +// calling f for each field descriptor and value encountered. +// Range returns immediately if f returns false. +// While iterating, mutating operations may only be performed +// on the current field descriptor. +func (x *fastReflection_MsgClawbackRequest) Range(f func(protoreflect.FieldDescriptor, protoreflect.Value) bool) { +} + +// Has reports whether a field is populated. +// +// Some fields have the property of nullability where it is possible to +// distinguish between the default value of a field and whether the field +// was explicitly populated with the default value. Singular message fields, +// member fields of a oneof, and proto2 scalar fields are nullable. Such +// fields are populated only if explicitly set. +// +// In other cases (aside from the nullable cases above), +// a proto3 scalar field is populated if it contains a non-zero value, and +// a repeated field is populated if it is non-empty. +func (x *fastReflection_MsgClawbackRequest) Has(fd protoreflect.FieldDescriptor) bool { + switch fd.FullName() { + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.MsgClawbackRequest")) + } + panic(fmt.Errorf("message testpb.MsgClawbackRequest does not contain field %s", fd.FullName())) + } +} + +// Clear clears the field such that a subsequent Has call reports false. +// +// Clearing an extension field clears both the extension type and value +// associated with the given field number. +// +// Clear is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_MsgClawbackRequest) Clear(fd protoreflect.FieldDescriptor) { + switch fd.FullName() { + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.MsgClawbackRequest")) + } + panic(fmt.Errorf("message testpb.MsgClawbackRequest does not contain field %s", fd.FullName())) + } +} + +// Get retrieves the value for a field. +// +// For unpopulated scalars, it returns the default value, where +// the default value of a bytes scalar is guaranteed to be a copy. +// For unpopulated composite types, it returns an empty, read-only view +// of the value; to obtain a mutable reference, use Mutable. +func (x *fastReflection_MsgClawbackRequest) Get(descriptor protoreflect.FieldDescriptor) protoreflect.Value { + switch descriptor.FullName() { + default: + if descriptor.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.MsgClawbackRequest")) + } + panic(fmt.Errorf("message testpb.MsgClawbackRequest does not contain field %s", descriptor.FullName())) + } +} + +// Set stores the value for a field. +// +// For a field belonging to a oneof, it implicitly clears any other field +// that may be currently set within the same oneof. +// For extension fields, it implicitly stores the provided ExtensionType. +// When setting a composite type, it is unspecified whether the stored value +// aliases the source's memory in any way. If the composite value is an +// empty, read-only value, then it panics. +// +// Set is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_MsgClawbackRequest) Set(fd protoreflect.FieldDescriptor, value protoreflect.Value) { + switch fd.FullName() { + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.MsgClawbackRequest")) + } + panic(fmt.Errorf("message testpb.MsgClawbackRequest does not contain field %s", fd.FullName())) + } +} + +// Mutable returns a mutable reference to a composite type. +// +// If the field is unpopulated, it may allocate a composite value. +// For a field belonging to a oneof, it implicitly clears any other field +// that may be currently set within the same oneof. +// For extension fields, it implicitly stores the provided ExtensionType +// if not already stored. +// It panics if the field does not contain a composite type. +// +// Mutable is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_MsgClawbackRequest) Mutable(fd protoreflect.FieldDescriptor) protoreflect.Value { + switch fd.FullName() { + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.MsgClawbackRequest")) + } + panic(fmt.Errorf("message testpb.MsgClawbackRequest does not contain field %s", fd.FullName())) + } +} + +// NewField returns a new value that is assignable to the field +// for the given descriptor. For scalars, this returns the default value. +// For lists, maps, and messages, this returns a new, empty, mutable value. +func (x *fastReflection_MsgClawbackRequest) NewField(fd protoreflect.FieldDescriptor) protoreflect.Value { + switch fd.FullName() { + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.MsgClawbackRequest")) + } + panic(fmt.Errorf("message testpb.MsgClawbackRequest does not contain field %s", fd.FullName())) + } +} + +// WhichOneof reports which field within the oneof is populated, +// returning nil if none are populated. +// It panics if the oneof descriptor does not belong to this message. +func (x *fastReflection_MsgClawbackRequest) WhichOneof(d protoreflect.OneofDescriptor) protoreflect.FieldDescriptor { + switch d.FullName() { + default: + panic(fmt.Errorf("%s is not a oneof field in testpb.MsgClawbackRequest", d.FullName())) + } + panic("unreachable") +} + +// GetUnknown retrieves the entire list of unknown fields. +// The caller may only mutate the contents of the RawFields +// if the mutated bytes are stored back into the message with SetUnknown. +func (x *fastReflection_MsgClawbackRequest) GetUnknown() protoreflect.RawFields { + return x.unknownFields +} + +// SetUnknown stores an entire list of unknown fields. +// The raw fields must be syntactically valid according to the wire format. +// An implementation may panic if this is not the case. +// Once stored, the caller must not mutate the content of the RawFields. +// An empty RawFields may be passed to clear the fields. +// +// SetUnknown is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_MsgClawbackRequest) SetUnknown(fields protoreflect.RawFields) { + x.unknownFields = fields +} + +// IsValid reports whether the message is valid. +// +// An invalid message is an empty, read-only value. +// +// An invalid message often corresponds to a nil pointer of the concrete +// message type, but the details are implementation dependent. +// Validity is not part of the protobuf data model, and may not +// be preserved in marshaling or other operations. +func (x *fastReflection_MsgClawbackRequest) IsValid() bool { + return x != nil +} + +// ProtoMethods returns optional fastReflectionFeature-path implementations of various operations. +// This method may return nil. +// +// The returned methods type is identical to +// "google.golang.org/protobuf/runtime/protoiface".Methods. +// Consult the protoiface package documentation for details. +func (x *fastReflection_MsgClawbackRequest) ProtoMethods() *protoiface.Methods { + size := func(input protoiface.SizeInput) protoiface.SizeOutput { + x := input.Message.Interface().(*MsgClawbackRequest) + if x == nil { + return protoiface.SizeOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Size: 0, + } + } + options := runtime.SizeInputToOptions(input) + _ = options + var n int + var l int + _ = l + if x.unknownFields != nil { + n += len(x.unknownFields) + } + return protoiface.SizeOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Size: n, + } + } + + marshal := func(input protoiface.MarshalInput) (protoiface.MarshalOutput, error) { + x := input.Message.Interface().(*MsgClawbackRequest) + if x == nil { + return protoiface.MarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Buf: input.Buf, + }, nil + } + options := runtime.MarshalInputToOptions(input) + _ = options + size := options.Size(x) + dAtA := make([]byte, size) + i := len(dAtA) + _ = i + var l int + _ = l + if x.unknownFields != nil { + i -= len(x.unknownFields) + copy(dAtA[i:], x.unknownFields) + } + if input.Buf != nil { + input.Buf = append(input.Buf, dAtA...) + } else { + input.Buf = dAtA + } + return protoiface.MarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Buf: input.Buf, + }, nil + } + unmarshal := func(input protoiface.UnmarshalInput) (protoiface.UnmarshalOutput, error) { + x := input.Message.Interface().(*MsgClawbackRequest) + if x == nil { + return protoiface.UnmarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Flags: input.Flags, + }, nil + } + options := runtime.UnmarshalInputToOptions(input) + _ = options + dAtA := input.Buf + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: MsgClawbackRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: MsgClawbackRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := runtime.Skip(dAtA[iNdEx:]) + if err != nil { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if (iNdEx + skippy) > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + if !options.DiscardUnknown { + x.unknownFields = append(x.unknownFields, dAtA[iNdEx:iNdEx+skippy]...) + } + iNdEx += skippy + } + } + + if iNdEx > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, nil + } + return &protoiface.Methods{ + NoUnkeyedLiterals: struct{}{}, + Flags: protoiface.SupportMarshalDeterministic | protoiface.SupportUnmarshalDiscardUnknown, + Size: size, + Marshal: marshal, + Unmarshal: unmarshal, + Merge: nil, + CheckInitialized: nil, + } +} + +var ( + md_MsgClawbackResponse protoreflect.MessageDescriptor +) + +func init() { + file_testpb_msg_proto_init() + md_MsgClawbackResponse = File_testpb_msg_proto.Messages().ByName("MsgClawbackResponse") +} + +var _ protoreflect.Message = (*fastReflection_MsgClawbackResponse)(nil) + +type fastReflection_MsgClawbackResponse MsgClawbackResponse + +func (x *MsgClawbackResponse) ProtoReflect() protoreflect.Message { + return (*fastReflection_MsgClawbackResponse)(x) +} + +func (x *MsgClawbackResponse) slowProtoReflect() protoreflect.Message { + mi := &file_testpb_msg_proto_msgTypes[3] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +var _fastReflection_MsgClawbackResponse_messageType fastReflection_MsgClawbackResponse_messageType +var _ protoreflect.MessageType = fastReflection_MsgClawbackResponse_messageType{} + +type fastReflection_MsgClawbackResponse_messageType struct{} + +func (x fastReflection_MsgClawbackResponse_messageType) Zero() protoreflect.Message { + return (*fastReflection_MsgClawbackResponse)(nil) +} +func (x fastReflection_MsgClawbackResponse_messageType) New() protoreflect.Message { + return new(fastReflection_MsgClawbackResponse) +} +func (x fastReflection_MsgClawbackResponse_messageType) Descriptor() protoreflect.MessageDescriptor { + return md_MsgClawbackResponse +} + +// Descriptor returns message descriptor, which contains only the protobuf +// type information for the message. +func (x *fastReflection_MsgClawbackResponse) Descriptor() protoreflect.MessageDescriptor { + return md_MsgClawbackResponse +} + +// Type returns the message type, which encapsulates both Go and protobuf +// type information. If the Go type information is not needed, +// it is recommended that the message descriptor be used instead. +func (x *fastReflection_MsgClawbackResponse) Type() protoreflect.MessageType { + return _fastReflection_MsgClawbackResponse_messageType +} + +// New returns a newly allocated and mutable empty message. +func (x *fastReflection_MsgClawbackResponse) New() protoreflect.Message { + return new(fastReflection_MsgClawbackResponse) +} + +// Interface unwraps the message reflection interface and +// returns the underlying ProtoMessage interface. +func (x *fastReflection_MsgClawbackResponse) Interface() protoreflect.ProtoMessage { + return (*MsgClawbackResponse)(x) +} + +// Range iterates over every populated field in an undefined order, +// calling f for each field descriptor and value encountered. +// Range returns immediately if f returns false. +// While iterating, mutating operations may only be performed +// on the current field descriptor. +func (x *fastReflection_MsgClawbackResponse) Range(f func(protoreflect.FieldDescriptor, protoreflect.Value) bool) { +} + +// Has reports whether a field is populated. +// +// Some fields have the property of nullability where it is possible to +// distinguish between the default value of a field and whether the field +// was explicitly populated with the default value. Singular message fields, +// member fields of a oneof, and proto2 scalar fields are nullable. Such +// fields are populated only if explicitly set. +// +// In other cases (aside from the nullable cases above), +// a proto3 scalar field is populated if it contains a non-zero value, and +// a repeated field is populated if it is non-empty. +func (x *fastReflection_MsgClawbackResponse) Has(fd protoreflect.FieldDescriptor) bool { + switch fd.FullName() { + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.MsgClawbackResponse")) + } + panic(fmt.Errorf("message testpb.MsgClawbackResponse does not contain field %s", fd.FullName())) + } +} + +// Clear clears the field such that a subsequent Has call reports false. +// +// Clearing an extension field clears both the extension type and value +// associated with the given field number. +// +// Clear is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_MsgClawbackResponse) Clear(fd protoreflect.FieldDescriptor) { + switch fd.FullName() { + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.MsgClawbackResponse")) + } + panic(fmt.Errorf("message testpb.MsgClawbackResponse does not contain field %s", fd.FullName())) + } +} + +// Get retrieves the value for a field. +// +// For unpopulated scalars, it returns the default value, where +// the default value of a bytes scalar is guaranteed to be a copy. +// For unpopulated composite types, it returns an empty, read-only view +// of the value; to obtain a mutable reference, use Mutable. +func (x *fastReflection_MsgClawbackResponse) Get(descriptor protoreflect.FieldDescriptor) protoreflect.Value { + switch descriptor.FullName() { + default: + if descriptor.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.MsgClawbackResponse")) + } + panic(fmt.Errorf("message testpb.MsgClawbackResponse does not contain field %s", descriptor.FullName())) + } +} + +// Set stores the value for a field. +// +// For a field belonging to a oneof, it implicitly clears any other field +// that may be currently set within the same oneof. +// For extension fields, it implicitly stores the provided ExtensionType. +// When setting a composite type, it is unspecified whether the stored value +// aliases the source's memory in any way. If the composite value is an +// empty, read-only value, then it panics. +// +// Set is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_MsgClawbackResponse) Set(fd protoreflect.FieldDescriptor, value protoreflect.Value) { + switch fd.FullName() { + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.MsgClawbackResponse")) + } + panic(fmt.Errorf("message testpb.MsgClawbackResponse does not contain field %s", fd.FullName())) + } +} + +// Mutable returns a mutable reference to a composite type. +// +// If the field is unpopulated, it may allocate a composite value. +// For a field belonging to a oneof, it implicitly clears any other field +// that may be currently set within the same oneof. +// For extension fields, it implicitly stores the provided ExtensionType +// if not already stored. +// It panics if the field does not contain a composite type. +// +// Mutable is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_MsgClawbackResponse) Mutable(fd protoreflect.FieldDescriptor) protoreflect.Value { + switch fd.FullName() { + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.MsgClawbackResponse")) + } + panic(fmt.Errorf("message testpb.MsgClawbackResponse does not contain field %s", fd.FullName())) + } +} + +// NewField returns a new value that is assignable to the field +// for the given descriptor. For scalars, this returns the default value. +// For lists, maps, and messages, this returns a new, empty, mutable value. +func (x *fastReflection_MsgClawbackResponse) NewField(fd protoreflect.FieldDescriptor) protoreflect.Value { + switch fd.FullName() { + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.MsgClawbackResponse")) + } + panic(fmt.Errorf("message testpb.MsgClawbackResponse does not contain field %s", fd.FullName())) + } +} + +// WhichOneof reports which field within the oneof is populated, +// returning nil if none are populated. +// It panics if the oneof descriptor does not belong to this message. +func (x *fastReflection_MsgClawbackResponse) WhichOneof(d protoreflect.OneofDescriptor) protoreflect.FieldDescriptor { + switch d.FullName() { + default: + panic(fmt.Errorf("%s is not a oneof field in testpb.MsgClawbackResponse", d.FullName())) + } + panic("unreachable") +} + +// GetUnknown retrieves the entire list of unknown fields. +// The caller may only mutate the contents of the RawFields +// if the mutated bytes are stored back into the message with SetUnknown. +func (x *fastReflection_MsgClawbackResponse) GetUnknown() protoreflect.RawFields { + return x.unknownFields +} + +// SetUnknown stores an entire list of unknown fields. +// The raw fields must be syntactically valid according to the wire format. +// An implementation may panic if this is not the case. +// Once stored, the caller must not mutate the content of the RawFields. +// An empty RawFields may be passed to clear the fields. +// +// SetUnknown is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_MsgClawbackResponse) SetUnknown(fields protoreflect.RawFields) { + x.unknownFields = fields +} + +// IsValid reports whether the message is valid. +// +// An invalid message is an empty, read-only value. +// +// An invalid message often corresponds to a nil pointer of the concrete +// message type, but the details are implementation dependent. +// Validity is not part of the protobuf data model, and may not +// be preserved in marshaling or other operations. +func (x *fastReflection_MsgClawbackResponse) IsValid() bool { + return x != nil +} + +// ProtoMethods returns optional fastReflectionFeature-path implementations of various operations. +// This method may return nil. +// +// The returned methods type is identical to +// "google.golang.org/protobuf/runtime/protoiface".Methods. +// Consult the protoiface package documentation for details. +func (x *fastReflection_MsgClawbackResponse) ProtoMethods() *protoiface.Methods { + size := func(input protoiface.SizeInput) protoiface.SizeOutput { + x := input.Message.Interface().(*MsgClawbackResponse) + if x == nil { + return protoiface.SizeOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Size: 0, + } + } + options := runtime.SizeInputToOptions(input) + _ = options + var n int + var l int + _ = l + if x.unknownFields != nil { + n += len(x.unknownFields) + } + return protoiface.SizeOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Size: n, + } + } + + marshal := func(input protoiface.MarshalInput) (protoiface.MarshalOutput, error) { + x := input.Message.Interface().(*MsgClawbackResponse) + if x == nil { + return protoiface.MarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Buf: input.Buf, + }, nil + } + options := runtime.MarshalInputToOptions(input) + _ = options + size := options.Size(x) + dAtA := make([]byte, size) + i := len(dAtA) + _ = i + var l int + _ = l + if x.unknownFields != nil { + i -= len(x.unknownFields) + copy(dAtA[i:], x.unknownFields) + } + if input.Buf != nil { + input.Buf = append(input.Buf, dAtA...) + } else { + input.Buf = dAtA + } + return protoiface.MarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Buf: input.Buf, + }, nil + } + unmarshal := func(input protoiface.UnmarshalInput) (protoiface.UnmarshalOutput, error) { + x := input.Message.Interface().(*MsgClawbackResponse) + if x == nil { + return protoiface.UnmarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Flags: input.Flags, + }, nil + } + options := runtime.UnmarshalInputToOptions(input) + _ = options + dAtA := input.Buf + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: MsgClawbackResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: MsgClawbackResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := runtime.Skip(dAtA[iNdEx:]) + if err != nil { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if (iNdEx + skippy) > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + if !options.DiscardUnknown { + x.unknownFields = append(x.unknownFields, dAtA[iNdEx:iNdEx+skippy]...) + } + iNdEx += skippy + } + } + + if iNdEx > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, nil + } + return &protoiface.Methods{ + NoUnkeyedLiterals: struct{}{}, + Flags: protoiface.SupportMarshalDeterministic | protoiface.SupportUnmarshalDiscardUnknown, + Size: size, + Marshal: marshal, + Unmarshal: unmarshal, + Merge: nil, + CheckInitialized: nil, + } +} + +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.27.0 +// protoc (unknown) +// source: testpb/msg.proto + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type MsgRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // u32 is a uint32 + U32 uint32 `protobuf:"varint,1,opt,name=u32,proto3" json:"u32,omitempty"` + U64 uint64 `protobuf:"varint,2,opt,name=u64,proto3" json:"u64,omitempty"` + Str string `protobuf:"bytes,3,opt,name=str,proto3" json:"str,omitempty"` + Bz []byte `protobuf:"bytes,4,opt,name=bz,proto3" json:"bz,omitempty"` + Timestamp *timestamppb.Timestamp `protobuf:"bytes,5,opt,name=timestamp,proto3" json:"timestamp,omitempty"` + Duration *durationpb.Duration `protobuf:"bytes,6,opt,name=duration,proto3" json:"duration,omitempty"` + I32 int32 `protobuf:"varint,7,opt,name=i32,proto3" json:"i32,omitempty"` + I64 int64 `protobuf:"varint,10,opt,name=i64,proto3" json:"i64,omitempty"` + ABool bool `protobuf:"varint,15,opt,name=a_bool,json=aBool,proto3" json:"a_bool,omitempty"` + AnEnum Enum `protobuf:"varint,16,opt,name=an_enum,json=anEnum,proto3,enum=testpb.Enum" json:"an_enum,omitempty"` + AMessage *AMessage `protobuf:"bytes,17,opt,name=a_message,json=aMessage,proto3" json:"a_message,omitempty"` + ACoin *v1beta1.Coin `protobuf:"bytes,18,opt,name=a_coin,json=aCoin,proto3" json:"a_coin,omitempty"` + AnAddress string `protobuf:"bytes,19,opt,name=an_address,json=anAddress,proto3" json:"an_address,omitempty"` + Page *v1beta11.PageRequest `protobuf:"bytes,20,opt,name=page,proto3" json:"page,omitempty"` + Bools []bool `protobuf:"varint,21,rep,packed,name=bools,proto3" json:"bools,omitempty"` + Uints []uint32 `protobuf:"varint,22,rep,packed,name=uints,proto3" json:"uints,omitempty"` + Strings []string `protobuf:"bytes,23,rep,name=strings,proto3" json:"strings,omitempty"` + Enums []Enum `protobuf:"varint,24,rep,packed,name=enums,proto3,enum=testpb.Enum" json:"enums,omitempty"` + Durations []*durationpb.Duration `protobuf:"bytes,25,rep,name=durations,proto3" json:"durations,omitempty"` + SomeMessages []*AMessage `protobuf:"bytes,26,rep,name=some_messages,json=someMessages,proto3" json:"some_messages,omitempty"` + Positional1 int32 `protobuf:"varint,27,opt,name=positional1,proto3" json:"positional1,omitempty"` + Positional2 string `protobuf:"bytes,28,opt,name=positional2,proto3" json:"positional2,omitempty"` + Positional3Varargs []*v1beta1.Coin `protobuf:"bytes,29,rep,name=positional3_varargs,json=positional3Varargs,proto3" json:"positional3_varargs,omitempty"` + DeprecatedField string `protobuf:"bytes,30,opt,name=deprecated_field,json=deprecatedField,proto3" json:"deprecated_field,omitempty"` + ShorthandDeprecatedField string `protobuf:"bytes,31,opt,name=shorthand_deprecated_field,json=shorthandDeprecatedField,proto3" json:"shorthand_deprecated_field,omitempty"` + HiddenBool bool `protobuf:"varint,32,opt,name=hidden_bool,json=hiddenBool,proto3" json:"hidden_bool,omitempty"` + AValidatorAddress string `protobuf:"bytes,33,opt,name=a_validator_address,json=aValidatorAddress,proto3" json:"a_validator_address,omitempty"` +} + +func (x *MsgRequest) Reset() { + *x = MsgRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_testpb_msg_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *MsgRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*MsgRequest) ProtoMessage() {} + +// Deprecated: Use MsgRequest.ProtoReflect.Descriptor instead. +func (*MsgRequest) Descriptor() ([]byte, []int) { + return file_testpb_msg_proto_rawDescGZIP(), []int{0} +} + +func (x *MsgRequest) GetU32() uint32 { + if x != nil { + return x.U32 + } + return 0 +} + +func (x *MsgRequest) GetU64() uint64 { + if x != nil { + return x.U64 + } + return 0 +} + +func (x *MsgRequest) GetStr() string { + if x != nil { + return x.Str + } + return "" +} + +func (x *MsgRequest) GetBz() []byte { + if x != nil { + return x.Bz + } + return nil +} + +func (x *MsgRequest) GetTimestamp() *timestamppb.Timestamp { + if x != nil { + return x.Timestamp + } + return nil +} + +func (x *MsgRequest) GetDuration() *durationpb.Duration { + if x != nil { + return x.Duration + } + return nil +} + +func (x *MsgRequest) GetI32() int32 { + if x != nil { + return x.I32 + } + return 0 +} + +func (x *MsgRequest) GetI64() int64 { + if x != nil { + return x.I64 + } + return 0 +} + +func (x *MsgRequest) GetABool() bool { + if x != nil { + return x.ABool + } + return false +} + +func (x *MsgRequest) GetAnEnum() Enum { + if x != nil { + return x.AnEnum + } + return Enum_ENUM_UNSPECIFIED +} + +func (x *MsgRequest) GetAMessage() *AMessage { + if x != nil { + return x.AMessage + } + return nil +} + +func (x *MsgRequest) GetACoin() *v1beta1.Coin { + if x != nil { + return x.ACoin + } + return nil +} + +func (x *MsgRequest) GetAnAddress() string { + if x != nil { + return x.AnAddress + } + return "" +} + +func (x *MsgRequest) GetPage() *v1beta11.PageRequest { + if x != nil { + return x.Page + } + return nil +} + +func (x *MsgRequest) GetBools() []bool { + if x != nil { + return x.Bools + } + return nil +} + +func (x *MsgRequest) GetUints() []uint32 { + if x != nil { + return x.Uints + } + return nil +} + +func (x *MsgRequest) GetStrings() []string { + if x != nil { + return x.Strings + } + return nil +} + +func (x *MsgRequest) GetEnums() []Enum { + if x != nil { + return x.Enums + } + return nil +} + +func (x *MsgRequest) GetDurations() []*durationpb.Duration { + if x != nil { + return x.Durations + } + return nil +} + +func (x *MsgRequest) GetSomeMessages() []*AMessage { + if x != nil { + return x.SomeMessages + } + return nil +} + +func (x *MsgRequest) GetPositional1() int32 { + if x != nil { + return x.Positional1 + } + return 0 +} + +func (x *MsgRequest) GetPositional2() string { + if x != nil { + return x.Positional2 + } + return "" +} + +func (x *MsgRequest) GetPositional3Varargs() []*v1beta1.Coin { + if x != nil { + return x.Positional3Varargs + } + return nil +} + +func (x *MsgRequest) GetDeprecatedField() string { + if x != nil { + return x.DeprecatedField + } + return "" +} + +func (x *MsgRequest) GetShorthandDeprecatedField() string { + if x != nil { + return x.ShorthandDeprecatedField + } + return "" +} + +func (x *MsgRequest) GetHiddenBool() bool { + if x != nil { + return x.HiddenBool + } + return false +} + +func (x *MsgRequest) GetAValidatorAddress() string { + if x != nil { + return x.AValidatorAddress + } + return "" +} + +type MsgResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Request *MsgRequest `protobuf:"bytes,1,opt,name=request,proto3" json:"request,omitempty"` +} + +func (x *MsgResponse) Reset() { + *x = MsgResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_testpb_msg_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *MsgResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*MsgResponse) ProtoMessage() {} + +// Deprecated: Use MsgResponse.ProtoReflect.Descriptor instead. +func (*MsgResponse) Descriptor() ([]byte, []int) { + return file_testpb_msg_proto_rawDescGZIP(), []int{1} +} + +func (x *MsgResponse) GetRequest() *MsgRequest { + if x != nil { + return x.Request + } + return nil +} + +type MsgClawbackRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *MsgClawbackRequest) Reset() { + *x = MsgClawbackRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_testpb_msg_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *MsgClawbackRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*MsgClawbackRequest) ProtoMessage() {} + +// Deprecated: Use MsgClawbackRequest.ProtoReflect.Descriptor instead. +func (*MsgClawbackRequest) Descriptor() ([]byte, []int) { + return file_testpb_msg_proto_rawDescGZIP(), []int{2} +} + +type MsgClawbackResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *MsgClawbackResponse) Reset() { + *x = MsgClawbackResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_testpb_msg_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *MsgClawbackResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*MsgClawbackResponse) ProtoMessage() {} + +// Deprecated: Use MsgClawbackResponse.ProtoReflect.Descriptor instead. +func (*MsgClawbackResponse) Descriptor() ([]byte, []int) { + return file_testpb_msg_proto_rawDescGZIP(), []int{3} +} + +var File_testpb_msg_proto protoreflect.FileDescriptor + +var file_testpb_msg_proto_rawDesc = []byte{ + 0x0a, 0x10, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x2f, 0x6d, 0x73, 0x67, 0x2e, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x12, 0x06, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x1a, 0x1f, 0x67, 0x6f, 0x6f, 0x67, + 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x74, 0x69, 0x6d, 0x65, + 0x73, 0x74, 0x61, 0x6d, 0x70, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1e, 0x67, 0x6f, 0x6f, + 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x64, 0x75, 0x72, + 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x19, 0x63, 0x6f, 0x73, + 0x6d, 0x6f, 0x73, 0x5f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, + 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x2a, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x62, + 0x61, 0x73, 0x65, 0x2f, 0x71, 0x75, 0x65, 0x72, 0x79, 0x2f, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, + 0x31, 0x2f, 0x70, 0x61, 0x67, 0x69, 0x6e, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x1a, 0x1e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x62, 0x61, 0x73, 0x65, 0x2f, + 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x2f, 0x63, 0x6f, 0x69, 0x6e, 0x2e, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x1a, 0x12, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x2f, 0x71, 0x75, 0x65, 0x72, 0x79, + 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xc2, 0x08, 0x0a, 0x0a, 0x4d, 0x73, 0x67, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x33, 0x32, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x0d, 0x52, 0x03, 0x75, 0x33, 0x32, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x36, 0x34, 0x18, 0x02, + 0x20, 0x01, 0x28, 0x04, 0x52, 0x03, 0x75, 0x36, 0x34, 0x12, 0x10, 0x0a, 0x03, 0x73, 0x74, 0x72, + 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x73, 0x74, 0x72, 0x12, 0x0e, 0x0a, 0x02, 0x62, + 0x7a, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x02, 0x62, 0x7a, 0x12, 0x38, 0x0a, 0x09, 0x74, + 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, + 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, + 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x09, 0x74, 0x69, 0x6d, 0x65, + 0x73, 0x74, 0x61, 0x6d, 0x70, 0x12, 0x35, 0x0a, 0x08, 0x64, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, + 0x6e, 0x18, 0x06, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, + 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x44, 0x75, 0x72, 0x61, 0x74, 0x69, + 0x6f, 0x6e, 0x52, 0x08, 0x64, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x10, 0x0a, 0x03, + 0x69, 0x33, 0x32, 0x18, 0x07, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x69, 0x33, 0x32, 0x12, 0x10, + 0x0a, 0x03, 0x69, 0x36, 0x34, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x03, 0x52, 0x03, 0x69, 0x36, 0x34, + 0x12, 0x15, 0x0a, 0x06, 0x61, 0x5f, 0x62, 0x6f, 0x6f, 0x6c, 0x18, 0x0f, 0x20, 0x01, 0x28, 0x08, + 0x52, 0x05, 0x61, 0x42, 0x6f, 0x6f, 0x6c, 0x12, 0x25, 0x0a, 0x07, 0x61, 0x6e, 0x5f, 0x65, 0x6e, + 0x75, 0x6d, 0x18, 0x10, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x0c, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x70, + 0x62, 0x2e, 0x45, 0x6e, 0x75, 0x6d, 0x52, 0x06, 0x61, 0x6e, 0x45, 0x6e, 0x75, 0x6d, 0x12, 0x2d, + 0x0a, 0x09, 0x61, 0x5f, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x11, 0x20, 0x01, 0x28, + 0x0b, 0x32, 0x10, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x2e, 0x41, 0x4d, 0x65, 0x73, 0x73, + 0x61, 0x67, 0x65, 0x52, 0x08, 0x61, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x30, 0x0a, + 0x06, 0x61, 0x5f, 0x63, 0x6f, 0x69, 0x6e, 0x18, 0x12, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x19, 0x2e, + 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x76, 0x31, 0x62, 0x65, + 0x74, 0x61, 0x31, 0x2e, 0x43, 0x6f, 0x69, 0x6e, 0x52, 0x05, 0x61, 0x43, 0x6f, 0x69, 0x6e, 0x12, + 0x37, 0x0a, 0x0a, 0x61, 0x6e, 0x5f, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, 0x13, 0x20, + 0x01, 0x28, 0x09, 0x42, 0x18, 0xd2, 0xb4, 0x2d, 0x14, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, + 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x52, 0x09, 0x61, + 0x6e, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x12, 0x3a, 0x0a, 0x04, 0x70, 0x61, 0x67, 0x65, + 0x18, 0x14, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x26, 0x2e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, + 0x62, 0x61, 0x73, 0x65, 0x2e, 0x71, 0x75, 0x65, 0x72, 0x79, 0x2e, 0x76, 0x31, 0x62, 0x65, 0x74, + 0x61, 0x31, 0x2e, 0x50, 0x61, 0x67, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x52, 0x04, + 0x70, 0x61, 0x67, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x62, 0x6f, 0x6f, 0x6c, 0x73, 0x18, 0x15, 0x20, + 0x03, 0x28, 0x08, 0x52, 0x05, 0x62, 0x6f, 0x6f, 0x6c, 0x73, 0x12, 0x14, 0x0a, 0x05, 0x75, 0x69, + 0x6e, 0x74, 0x73, 0x18, 0x16, 0x20, 0x03, 0x28, 0x0d, 0x52, 0x05, 0x75, 0x69, 0x6e, 0x74, 0x73, + 0x12, 0x18, 0x0a, 0x07, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x73, 0x18, 0x17, 0x20, 0x03, 0x28, + 0x09, 0x52, 0x07, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x73, 0x12, 0x22, 0x0a, 0x05, 0x65, 0x6e, + 0x75, 0x6d, 0x73, 0x18, 0x18, 0x20, 0x03, 0x28, 0x0e, 0x32, 0x0c, 0x2e, 0x74, 0x65, 0x73, 0x74, + 0x70, 0x62, 0x2e, 0x45, 0x6e, 0x75, 0x6d, 0x52, 0x05, 0x65, 0x6e, 0x75, 0x6d, 0x73, 0x12, 0x37, + 0x0a, 0x09, 0x64, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0x19, 0x20, 0x03, 0x28, + 0x0b, 0x32, 0x19, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x62, 0x75, 0x66, 0x2e, 0x44, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x09, 0x64, 0x75, + 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x35, 0x0a, 0x0d, 0x73, 0x6f, 0x6d, 0x65, 0x5f, + 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x73, 0x18, 0x1a, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x10, + 0x2e, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x2e, 0x41, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, + 0x52, 0x0c, 0x73, 0x6f, 0x6d, 0x65, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x73, 0x12, 0x20, + 0x0a, 0x0b, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x61, 0x6c, 0x31, 0x18, 0x1b, 0x20, + 0x01, 0x28, 0x05, 0x52, 0x0b, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x61, 0x6c, 0x31, + 0x12, 0x20, 0x0a, 0x0b, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x61, 0x6c, 0x32, 0x18, + 0x1c, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x61, + 0x6c, 0x32, 0x12, 0x4a, 0x0a, 0x13, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x61, 0x6c, + 0x33, 0x5f, 0x76, 0x61, 0x72, 0x61, 0x72, 0x67, 0x73, 0x18, 0x1d, 0x20, 0x03, 0x28, 0x0b, 0x32, + 0x19, 0x2e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x76, 0x31, + 0x62, 0x65, 0x74, 0x61, 0x31, 0x2e, 0x43, 0x6f, 0x69, 0x6e, 0x52, 0x12, 0x70, 0x6f, 0x73, 0x69, + 0x74, 0x69, 0x6f, 0x6e, 0x61, 0x6c, 0x33, 0x56, 0x61, 0x72, 0x61, 0x72, 0x67, 0x73, 0x12, 0x29, + 0x0a, 0x10, 0x64, 0x65, 0x70, 0x72, 0x65, 0x63, 0x61, 0x74, 0x65, 0x64, 0x5f, 0x66, 0x69, 0x65, + 0x6c, 0x64, 0x18, 0x1e, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0f, 0x64, 0x65, 0x70, 0x72, 0x65, 0x63, + 0x61, 0x74, 0x65, 0x64, 0x46, 0x69, 0x65, 0x6c, 0x64, 0x12, 0x3c, 0x0a, 0x1a, 0x73, 0x68, 0x6f, + 0x72, 0x74, 0x68, 0x61, 0x6e, 0x64, 0x5f, 0x64, 0x65, 0x70, 0x72, 0x65, 0x63, 0x61, 0x74, 0x65, + 0x64, 0x5f, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x18, 0x1f, 0x20, 0x01, 0x28, 0x09, 0x52, 0x18, 0x73, + 0x68, 0x6f, 0x72, 0x74, 0x68, 0x61, 0x6e, 0x64, 0x44, 0x65, 0x70, 0x72, 0x65, 0x63, 0x61, 0x74, + 0x65, 0x64, 0x46, 0x69, 0x65, 0x6c, 0x64, 0x12, 0x1f, 0x0a, 0x0b, 0x68, 0x69, 0x64, 0x64, 0x65, + 0x6e, 0x5f, 0x62, 0x6f, 0x6f, 0x6c, 0x18, 0x20, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0a, 0x68, 0x69, + 0x64, 0x64, 0x65, 0x6e, 0x42, 0x6f, 0x6f, 0x6c, 0x12, 0x51, 0x0a, 0x13, 0x61, 0x5f, 0x76, 0x61, + 0x6c, 0x69, 0x64, 0x61, 0x74, 0x6f, 0x72, 0x5f, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, + 0x21, 0x20, 0x01, 0x28, 0x09, 0x42, 0x21, 0xd2, 0xb4, 0x2d, 0x1d, 0x63, 0x6f, 0x73, 0x6d, 0x6f, + 0x73, 0x2e, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x6f, 0x72, 0x41, 0x64, 0x64, 0x72, 0x65, + 0x73, 0x73, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x52, 0x11, 0x61, 0x56, 0x61, 0x6c, 0x69, 0x64, + 0x61, 0x74, 0x6f, 0x72, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x22, 0x3b, 0x0a, 0x0b, 0x4d, + 0x73, 0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x2c, 0x0a, 0x07, 0x72, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x12, 0x2e, 0x74, 0x65, + 0x73, 0x74, 0x70, 0x62, 0x2e, 0x4d, 0x73, 0x67, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x52, + 0x07, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0x14, 0x0a, 0x12, 0x4d, 0x73, 0x67, 0x43, + 0x6c, 0x61, 0x77, 0x62, 0x61, 0x63, 0x6b, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0x15, + 0x0a, 0x13, 0x4d, 0x73, 0x67, 0x43, 0x6c, 0x61, 0x77, 0x62, 0x61, 0x63, 0x6b, 0x52, 0x65, 0x73, + 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x32, 0xac, 0x01, 0x0a, 0x03, 0x4d, 0x73, 0x67, 0x12, 0x47, 0x0a, + 0x04, 0x53, 0x65, 0x6e, 0x64, 0x12, 0x12, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x2e, 0x4d, + 0x73, 0x67, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x13, 0x2e, 0x74, 0x65, 0x73, 0x74, + 0x70, 0x62, 0x2e, 0x4d, 0x73, 0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x16, + 0xca, 0xb4, 0x2d, 0x12, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2d, 0x73, 0x64, 0x6b, 0x20, 0x76, + 0x30, 0x2e, 0x35, 0x30, 0x2e, 0x30, 0x12, 0x5c, 0x0a, 0x08, 0x43, 0x6c, 0x61, 0x77, 0x62, 0x61, + 0x63, 0x6b, 0x12, 0x1a, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x2e, 0x4d, 0x73, 0x67, 0x43, + 0x6c, 0x61, 0x77, 0x62, 0x61, 0x63, 0x6b, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1b, + 0x2e, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x2e, 0x4d, 0x73, 0x67, 0x43, 0x6c, 0x61, 0x77, 0x62, + 0x61, 0x63, 0x6b, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x17, 0xca, 0xb4, 0x2d, + 0x13, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2d, 0x73, 0x64, 0x6b, 0x20, 0x76, 0x30, 0x2e, 0x35, + 0x33, 0x2e, 0x30, 0x20, 0x42, 0x86, 0x01, 0x0a, 0x0a, 0x63, 0x6f, 0x6d, 0x2e, 0x74, 0x65, 0x73, + 0x74, 0x70, 0x62, 0x42, 0x08, 0x4d, 0x73, 0x67, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, + 0x36, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, 0x6f, 0x73, 0x6d, + 0x6f, 0x73, 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2d, 0x73, 0x64, 0x6b, 0x2f, 0x63, 0x6c, + 0x69, 0x65, 0x6e, 0x74, 0x2f, 0x76, 0x32, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, + 0x2f, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0xa2, 0x02, 0x03, 0x54, 0x58, 0x58, 0xaa, 0x02, 0x06, + 0x54, 0x65, 0x73, 0x74, 0x70, 0x62, 0xca, 0x02, 0x06, 0x54, 0x65, 0x73, 0x74, 0x70, 0x62, 0xe2, + 0x02, 0x12, 0x54, 0x65, 0x73, 0x74, 0x70, 0x62, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, + 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x06, 0x54, 0x65, 0x73, 0x74, 0x70, 0x62, 0x62, 0x06, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_testpb_msg_proto_rawDescOnce sync.Once + file_testpb_msg_proto_rawDescData = file_testpb_msg_proto_rawDesc +) + +func file_testpb_msg_proto_rawDescGZIP() []byte { + file_testpb_msg_proto_rawDescOnce.Do(func() { + file_testpb_msg_proto_rawDescData = protoimpl.X.CompressGZIP(file_testpb_msg_proto_rawDescData) + }) + return file_testpb_msg_proto_rawDescData +} + +var file_testpb_msg_proto_msgTypes = make([]protoimpl.MessageInfo, 4) +var file_testpb_msg_proto_goTypes = []interface{}{ + (*MsgRequest)(nil), // 0: testpb.MsgRequest + (*MsgResponse)(nil), // 1: testpb.MsgResponse + (*MsgClawbackRequest)(nil), // 2: testpb.MsgClawbackRequest + (*MsgClawbackResponse)(nil), // 3: testpb.MsgClawbackResponse + (*timestamppb.Timestamp)(nil), // 4: google.protobuf.Timestamp + (*durationpb.Duration)(nil), // 5: google.protobuf.Duration + (Enum)(0), // 6: testpb.Enum + (*AMessage)(nil), // 7: testpb.AMessage + (*v1beta1.Coin)(nil), // 8: cosmos.base.v1beta1.Coin + (*v1beta11.PageRequest)(nil), // 9: cosmos.base.query.v1beta1.PageRequest +} +var file_testpb_msg_proto_depIdxs = []int32{ + 4, // 0: testpb.MsgRequest.timestamp:type_name -> google.protobuf.Timestamp + 5, // 1: testpb.MsgRequest.duration:type_name -> google.protobuf.Duration + 6, // 2: testpb.MsgRequest.an_enum:type_name -> testpb.Enum + 7, // 3: testpb.MsgRequest.a_message:type_name -> testpb.AMessage + 8, // 4: testpb.MsgRequest.a_coin:type_name -> cosmos.base.v1beta1.Coin + 9, // 5: testpb.MsgRequest.page:type_name -> cosmos.base.query.v1beta1.PageRequest + 6, // 6: testpb.MsgRequest.enums:type_name -> testpb.Enum + 5, // 7: testpb.MsgRequest.durations:type_name -> google.protobuf.Duration + 7, // 8: testpb.MsgRequest.some_messages:type_name -> testpb.AMessage + 8, // 9: testpb.MsgRequest.positional3_varargs:type_name -> cosmos.base.v1beta1.Coin + 0, // 10: testpb.MsgResponse.request:type_name -> testpb.MsgRequest + 0, // 11: testpb.Msg.Send:input_type -> testpb.MsgRequest + 2, // 12: testpb.Msg.Clawback:input_type -> testpb.MsgClawbackRequest + 1, // 13: testpb.Msg.Send:output_type -> testpb.MsgResponse + 3, // 14: testpb.Msg.Clawback:output_type -> testpb.MsgClawbackResponse + 13, // [13:15] is the sub-list for method output_type + 11, // [11:13] is the sub-list for method input_type + 11, // [11:11] is the sub-list for extension type_name + 11, // [11:11] is the sub-list for extension extendee + 0, // [0:11] is the sub-list for field type_name +} + +func init() { file_testpb_msg_proto_init() } +func file_testpb_msg_proto_init() { + if File_testpb_msg_proto != nil { + return + } + file_testpb_query_proto_init() + if !protoimpl.UnsafeEnabled { + file_testpb_msg_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*MsgRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_testpb_msg_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*MsgResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_testpb_msg_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*MsgClawbackRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_testpb_msg_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*MsgClawbackResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_testpb_msg_proto_rawDesc, + NumEnums: 0, + NumMessages: 4, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_testpb_msg_proto_goTypes, + DependencyIndexes: file_testpb_msg_proto_depIdxs, + MessageInfos: file_testpb_msg_proto_msgTypes, + }.Build() + File_testpb_msg_proto = out.File + file_testpb_msg_proto_rawDesc = nil + file_testpb_msg_proto_goTypes = nil + file_testpb_msg_proto_depIdxs = nil +} diff --git a/connect/internal/internal/testpb/msg_grpc.pb.go b/connect/internal/internal/testpb/msg_grpc.pb.go new file mode 100644 index 00000000..703528e2 --- /dev/null +++ b/connect/internal/internal/testpb/msg_grpc.pb.go @@ -0,0 +1,161 @@ +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.5.1 +// - protoc (unknown) +// source: testpb/msg.proto + +package testpb + +import ( + context "context" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +// Requires gRPC-Go v1.64.0 or later. +const _ = grpc.SupportPackageIsVersion9 + +const ( + Msg_Send_FullMethodName = "/testpb.Msg/Send" + Msg_Clawback_FullMethodName = "/testpb.Msg/Clawback" +) + +// MsgClient is the client API for Msg service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. +type MsgClient interface { + // Send a request and returns the request as a response. + Send(ctx context.Context, in *MsgRequest, opts ...grpc.CallOption) (*MsgResponse, error) + Clawback(ctx context.Context, in *MsgClawbackRequest, opts ...grpc.CallOption) (*MsgClawbackResponse, error) +} + +type msgClient struct { + cc grpc.ClientConnInterface +} + +func NewMsgClient(cc grpc.ClientConnInterface) MsgClient { + return &msgClient{cc} +} + +func (c *msgClient) Send(ctx context.Context, in *MsgRequest, opts ...grpc.CallOption) (*MsgResponse, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(MsgResponse) + err := c.cc.Invoke(ctx, Msg_Send_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *msgClient) Clawback(ctx context.Context, in *MsgClawbackRequest, opts ...grpc.CallOption) (*MsgClawbackResponse, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(MsgClawbackResponse) + err := c.cc.Invoke(ctx, Msg_Clawback_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +// MsgServer is the server API for Msg service. +// All implementations must embed UnimplementedMsgServer +// for forward compatibility. +type MsgServer interface { + // Send a request and returns the request as a response. + Send(context.Context, *MsgRequest) (*MsgResponse, error) + Clawback(context.Context, *MsgClawbackRequest) (*MsgClawbackResponse, error) + mustEmbedUnimplementedMsgServer() +} + +// UnimplementedMsgServer must be embedded to have +// forward compatible implementations. +// +// NOTE: this should be embedded by value instead of pointer to avoid a nil +// pointer dereference when methods are called. +type UnimplementedMsgServer struct{} + +func (UnimplementedMsgServer) Send(context.Context, *MsgRequest) (*MsgResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Send not implemented") +} +func (UnimplementedMsgServer) Clawback(context.Context, *MsgClawbackRequest) (*MsgClawbackResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Clawback not implemented") +} +func (UnimplementedMsgServer) mustEmbedUnimplementedMsgServer() {} +func (UnimplementedMsgServer) testEmbeddedByValue() {} + +// UnsafeMsgServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to MsgServer will +// result in compilation errors. +type UnsafeMsgServer interface { + mustEmbedUnimplementedMsgServer() +} + +func RegisterMsgServer(s grpc.ServiceRegistrar, srv MsgServer) { + // If the following call pancis, it indicates UnimplementedMsgServer was + // embedded by pointer and is nil. This will cause panics if an + // unimplemented method is ever invoked, so we test this at initialization + // time to prevent it from happening at runtime later due to I/O. + if t, ok := srv.(interface{ testEmbeddedByValue() }); ok { + t.testEmbeddedByValue() + } + s.RegisterService(&Msg_ServiceDesc, srv) +} + +func _Msg_Send_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).Send(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Msg_Send_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).Send(ctx, req.(*MsgRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Msg_Clawback_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgClawbackRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).Clawback(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Msg_Clawback_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).Clawback(ctx, req.(*MsgClawbackRequest)) + } + return interceptor(ctx, in, info, handler) +} + +// Msg_ServiceDesc is the grpc.ServiceDesc for Msg service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var Msg_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "testpb.Msg", + HandlerType: (*MsgServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Send", + Handler: _Msg_Send_Handler, + }, + { + MethodName: "Clawback", + Handler: _Msg_Clawback_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "testpb/msg.proto", +} diff --git a/connect/internal/internal/testpb/query.proto b/connect/internal/internal/testpb/query.proto new file mode 100644 index 00000000..86c852e5 --- /dev/null +++ b/connect/internal/internal/testpb/query.proto @@ -0,0 +1,70 @@ +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"; + +service Query { + // Echo returns the request in the response + rpc Echo(EchoRequest) returns (EchoResponse); +} + +message AMessage { + string bar = 1; + int32 baz = 2; +} + +message EchoRequest { + // 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; + Enum an_enum = 16; + 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 Enum enums = 24; + repeated google.protobuf.Duration durations = 25; + repeated 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; + map map_string_string = 33; + map map_string_uint32 = 34; + map map_string_coin = 35; + string a_validator_address = 36 [(cosmos_proto.scalar) = "cosmos.ValidatorAddressString"]; + string a_consensus_address = 37 [(cosmos_proto.scalar) = "cosmos.ConsensusAddressString"]; + + repeated cosmos.base.v1beta1.Coin coins = 38; +} + +enum Enum { + ENUM_UNSPECIFIED = 0; + ENUM_ONE = 1; + ENUM_TWO = 2; + ENUM_FIVE = 5; + ENUM_NEG_THREE = -3; +} + +message EchoResponse { + EchoRequest request = 1; +} diff --git a/connect/internal/internal/testpb/query.pulsar.go b/connect/internal/internal/testpb/query.pulsar.go new file mode 100644 index 00000000..53f899b3 --- /dev/null +++ b/connect/internal/internal/testpb/query.pulsar.go @@ -0,0 +1,5438 @@ +// Code generated by protoc-gen-go-pulsar. DO NOT EDIT. +package testpb + +import ( + v1beta11 "cosmossdk.io/api/cosmos/base/query/v1beta1" + v1beta1 "cosmossdk.io/api/cosmos/base/v1beta1" + fmt "fmt" + _ "github.com/cosmos/cosmos-proto" + runtime "github.com/cosmos/cosmos-proto/runtime" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoiface "google.golang.org/protobuf/runtime/protoiface" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + durationpb "google.golang.org/protobuf/types/known/durationpb" + timestamppb "google.golang.org/protobuf/types/known/timestamppb" + io "io" + reflect "reflect" + sort "sort" + sync "sync" +) + +var ( + md_AMessage protoreflect.MessageDescriptor + fd_AMessage_bar protoreflect.FieldDescriptor + fd_AMessage_baz protoreflect.FieldDescriptor +) + +func init() { + file_testpb_query_proto_init() + md_AMessage = File_testpb_query_proto.Messages().ByName("AMessage") + fd_AMessage_bar = md_AMessage.Fields().ByName("bar") + fd_AMessage_baz = md_AMessage.Fields().ByName("baz") +} + +var _ protoreflect.Message = (*fastReflection_AMessage)(nil) + +type fastReflection_AMessage AMessage + +func (x *AMessage) ProtoReflect() protoreflect.Message { + return (*fastReflection_AMessage)(x) +} + +func (x *AMessage) slowProtoReflect() protoreflect.Message { + mi := &file_testpb_query_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +var _fastReflection_AMessage_messageType fastReflection_AMessage_messageType +var _ protoreflect.MessageType = fastReflection_AMessage_messageType{} + +type fastReflection_AMessage_messageType struct{} + +func (x fastReflection_AMessage_messageType) Zero() protoreflect.Message { + return (*fastReflection_AMessage)(nil) +} +func (x fastReflection_AMessage_messageType) New() protoreflect.Message { + return new(fastReflection_AMessage) +} +func (x fastReflection_AMessage_messageType) Descriptor() protoreflect.MessageDescriptor { + return md_AMessage +} + +// Descriptor returns message descriptor, which contains only the protobuf +// type information for the message. +func (x *fastReflection_AMessage) Descriptor() protoreflect.MessageDescriptor { + return md_AMessage +} + +// Type returns the message type, which encapsulates both Go and protobuf +// type information. If the Go type information is not needed, +// it is recommended that the message descriptor be used instead. +func (x *fastReflection_AMessage) Type() protoreflect.MessageType { + return _fastReflection_AMessage_messageType +} + +// New returns a newly allocated and mutable empty message. +func (x *fastReflection_AMessage) New() protoreflect.Message { + return new(fastReflection_AMessage) +} + +// Interface unwraps the message reflection interface and +// returns the underlying ProtoMessage interface. +func (x *fastReflection_AMessage) Interface() protoreflect.ProtoMessage { + return (*AMessage)(x) +} + +// Range iterates over every populated field in an undefined order, +// calling f for each field descriptor and value encountered. +// Range returns immediately if f returns false. +// While iterating, mutating operations may only be performed +// on the current field descriptor. +func (x *fastReflection_AMessage) Range(f func(protoreflect.FieldDescriptor, protoreflect.Value) bool) { + if x.Bar != "" { + value := protoreflect.ValueOfString(x.Bar) + if !f(fd_AMessage_bar, value) { + return + } + } + if x.Baz != int32(0) { + value := protoreflect.ValueOfInt32(x.Baz) + if !f(fd_AMessage_baz, value) { + return + } + } +} + +// Has reports whether a field is populated. +// +// Some fields have the property of nullability where it is possible to +// distinguish between the default value of a field and whether the field +// was explicitly populated with the default value. Singular message fields, +// member fields of a oneof, and proto2 scalar fields are nullable. Such +// fields are populated only if explicitly set. +// +// In other cases (aside from the nullable cases above), +// a proto3 scalar field is populated if it contains a non-zero value, and +// a repeated field is populated if it is non-empty. +func (x *fastReflection_AMessage) Has(fd protoreflect.FieldDescriptor) bool { + switch fd.FullName() { + case "testpb.AMessage.bar": + return x.Bar != "" + case "testpb.AMessage.baz": + return x.Baz != int32(0) + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.AMessage")) + } + panic(fmt.Errorf("message testpb.AMessage does not contain field %s", fd.FullName())) + } +} + +// Clear clears the field such that a subsequent Has call reports false. +// +// Clearing an extension field clears both the extension type and value +// associated with the given field number. +// +// Clear is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_AMessage) Clear(fd protoreflect.FieldDescriptor) { + switch fd.FullName() { + case "testpb.AMessage.bar": + x.Bar = "" + case "testpb.AMessage.baz": + x.Baz = int32(0) + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.AMessage")) + } + panic(fmt.Errorf("message testpb.AMessage does not contain field %s", fd.FullName())) + } +} + +// Get retrieves the value for a field. +// +// For unpopulated scalars, it returns the default value, where +// the default value of a bytes scalar is guaranteed to be a copy. +// For unpopulated composite types, it returns an empty, read-only view +// of the value; to obtain a mutable reference, use Mutable. +func (x *fastReflection_AMessage) Get(descriptor protoreflect.FieldDescriptor) protoreflect.Value { + switch descriptor.FullName() { + case "testpb.AMessage.bar": + value := x.Bar + return protoreflect.ValueOfString(value) + case "testpb.AMessage.baz": + value := x.Baz + return protoreflect.ValueOfInt32(value) + default: + if descriptor.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.AMessage")) + } + panic(fmt.Errorf("message testpb.AMessage does not contain field %s", descriptor.FullName())) + } +} + +// Set stores the value for a field. +// +// For a field belonging to a oneof, it implicitly clears any other field +// that may be currently set within the same oneof. +// For extension fields, it implicitly stores the provided ExtensionType. +// When setting a composite type, it is unspecified whether the stored value +// aliases the source's memory in any way. If the composite value is an +// empty, read-only value, then it panics. +// +// Set is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_AMessage) Set(fd protoreflect.FieldDescriptor, value protoreflect.Value) { + switch fd.FullName() { + case "testpb.AMessage.bar": + x.Bar = value.Interface().(string) + case "testpb.AMessage.baz": + x.Baz = int32(value.Int()) + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.AMessage")) + } + panic(fmt.Errorf("message testpb.AMessage does not contain field %s", fd.FullName())) + } +} + +// Mutable returns a mutable reference to a composite type. +// +// If the field is unpopulated, it may allocate a composite value. +// For a field belonging to a oneof, it implicitly clears any other field +// that may be currently set within the same oneof. +// For extension fields, it implicitly stores the provided ExtensionType +// if not already stored. +// It panics if the field does not contain a composite type. +// +// Mutable is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_AMessage) Mutable(fd protoreflect.FieldDescriptor) protoreflect.Value { + switch fd.FullName() { + case "testpb.AMessage.bar": + panic(fmt.Errorf("field bar of message testpb.AMessage is not mutable")) + case "testpb.AMessage.baz": + panic(fmt.Errorf("field baz of message testpb.AMessage is not mutable")) + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.AMessage")) + } + panic(fmt.Errorf("message testpb.AMessage does not contain field %s", fd.FullName())) + } +} + +// NewField returns a new value that is assignable to the field +// for the given descriptor. For scalars, this returns the default value. +// For lists, maps, and messages, this returns a new, empty, mutable value. +func (x *fastReflection_AMessage) NewField(fd protoreflect.FieldDescriptor) protoreflect.Value { + switch fd.FullName() { + case "testpb.AMessage.bar": + return protoreflect.ValueOfString("") + case "testpb.AMessage.baz": + return protoreflect.ValueOfInt32(int32(0)) + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.AMessage")) + } + panic(fmt.Errorf("message testpb.AMessage does not contain field %s", fd.FullName())) + } +} + +// WhichOneof reports which field within the oneof is populated, +// returning nil if none are populated. +// It panics if the oneof descriptor does not belong to this message. +func (x *fastReflection_AMessage) WhichOneof(d protoreflect.OneofDescriptor) protoreflect.FieldDescriptor { + switch d.FullName() { + default: + panic(fmt.Errorf("%s is not a oneof field in testpb.AMessage", d.FullName())) + } + panic("unreachable") +} + +// GetUnknown retrieves the entire list of unknown fields. +// The caller may only mutate the contents of the RawFields +// if the mutated bytes are stored back into the message with SetUnknown. +func (x *fastReflection_AMessage) GetUnknown() protoreflect.RawFields { + return x.unknownFields +} + +// SetUnknown stores an entire list of unknown fields. +// The raw fields must be syntactically valid according to the wire format. +// An implementation may panic if this is not the case. +// Once stored, the caller must not mutate the content of the RawFields. +// An empty RawFields may be passed to clear the fields. +// +// SetUnknown is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_AMessage) SetUnknown(fields protoreflect.RawFields) { + x.unknownFields = fields +} + +// IsValid reports whether the message is valid. +// +// An invalid message is an empty, read-only value. +// +// An invalid message often corresponds to a nil pointer of the concrete +// message type, but the details are implementation dependent. +// Validity is not part of the protobuf data model, and may not +// be preserved in marshaling or other operations. +func (x *fastReflection_AMessage) IsValid() bool { + return x != nil +} + +// ProtoMethods returns optional fastReflectionFeature-path implementations of various operations. +// This method may return nil. +// +// The returned methods type is identical to +// "google.golang.org/protobuf/runtime/protoiface".Methods. +// Consult the protoiface package documentation for details. +func (x *fastReflection_AMessage) ProtoMethods() *protoiface.Methods { + size := func(input protoiface.SizeInput) protoiface.SizeOutput { + x := input.Message.Interface().(*AMessage) + if x == nil { + return protoiface.SizeOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Size: 0, + } + } + options := runtime.SizeInputToOptions(input) + _ = options + var n int + var l int + _ = l + l = len(x.Bar) + if l > 0 { + n += 1 + l + runtime.Sov(uint64(l)) + } + if x.Baz != 0 { + n += 1 + runtime.Sov(uint64(x.Baz)) + } + if x.unknownFields != nil { + n += len(x.unknownFields) + } + return protoiface.SizeOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Size: n, + } + } + + marshal := func(input protoiface.MarshalInput) (protoiface.MarshalOutput, error) { + x := input.Message.Interface().(*AMessage) + if x == nil { + return protoiface.MarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Buf: input.Buf, + }, nil + } + options := runtime.MarshalInputToOptions(input) + _ = options + size := options.Size(x) + dAtA := make([]byte, size) + i := len(dAtA) + _ = i + var l int + _ = l + if x.unknownFields != nil { + i -= len(x.unknownFields) + copy(dAtA[i:], x.unknownFields) + } + if x.Baz != 0 { + i = runtime.EncodeVarint(dAtA, i, uint64(x.Baz)) + i-- + dAtA[i] = 0x10 + } + if len(x.Bar) > 0 { + i -= len(x.Bar) + copy(dAtA[i:], x.Bar) + i = runtime.EncodeVarint(dAtA, i, uint64(len(x.Bar))) + i-- + dAtA[i] = 0xa + } + if input.Buf != nil { + input.Buf = append(input.Buf, dAtA...) + } else { + input.Buf = dAtA + } + return protoiface.MarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Buf: input.Buf, + }, nil + } + unmarshal := func(input protoiface.UnmarshalInput) (protoiface.UnmarshalOutput, error) { + x := input.Message.Interface().(*AMessage) + if x == nil { + return protoiface.UnmarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Flags: input.Flags, + }, nil + } + options := runtime.UnmarshalInputToOptions(input) + _ = options + dAtA := input.Buf + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: AMessage: wiretype end group for non-group") + } + if fieldNum <= 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: AMessage: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Bar", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if postIndex > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + x.Bar = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Baz", wireType) + } + x.Baz = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + x.Baz |= int32(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := runtime.Skip(dAtA[iNdEx:]) + if err != nil { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if (iNdEx + skippy) > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + if !options.DiscardUnknown { + x.unknownFields = append(x.unknownFields, dAtA[iNdEx:iNdEx+skippy]...) + } + iNdEx += skippy + } + } + + if iNdEx > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, nil + } + return &protoiface.Methods{ + NoUnkeyedLiterals: struct{}{}, + Flags: protoiface.SupportMarshalDeterministic | protoiface.SupportUnmarshalDiscardUnknown, + Size: size, + Marshal: marshal, + Unmarshal: unmarshal, + Merge: nil, + CheckInitialized: nil, + } +} + +var _ protoreflect.List = (*_EchoRequest_21_list)(nil) + +type _EchoRequest_21_list struct { + list *[]bool +} + +func (x *_EchoRequest_21_list) Len() int { + if x.list == nil { + return 0 + } + return len(*x.list) +} + +func (x *_EchoRequest_21_list) Get(i int) protoreflect.Value { + return protoreflect.ValueOfBool((*x.list)[i]) +} + +func (x *_EchoRequest_21_list) Set(i int, value protoreflect.Value) { + valueUnwrapped := value.Bool() + concreteValue := valueUnwrapped + (*x.list)[i] = concreteValue +} + +func (x *_EchoRequest_21_list) Append(value protoreflect.Value) { + valueUnwrapped := value.Bool() + concreteValue := valueUnwrapped + *x.list = append(*x.list, concreteValue) +} + +func (x *_EchoRequest_21_list) AppendMutable() protoreflect.Value { + panic(fmt.Errorf("AppendMutable can not be called on message EchoRequest at list field Bools as it is not of Message kind")) +} + +func (x *_EchoRequest_21_list) Truncate(n int) { + *x.list = (*x.list)[:n] +} + +func (x *_EchoRequest_21_list) NewElement() protoreflect.Value { + v := false + return protoreflect.ValueOfBool(v) +} + +func (x *_EchoRequest_21_list) IsValid() bool { + return x.list != nil +} + +var _ protoreflect.List = (*_EchoRequest_22_list)(nil) + +type _EchoRequest_22_list struct { + list *[]uint32 +} + +func (x *_EchoRequest_22_list) Len() int { + if x.list == nil { + return 0 + } + return len(*x.list) +} + +func (x *_EchoRequest_22_list) Get(i int) protoreflect.Value { + return protoreflect.ValueOfUint32((*x.list)[i]) +} + +func (x *_EchoRequest_22_list) Set(i int, value protoreflect.Value) { + valueUnwrapped := value.Uint() + concreteValue := (uint32)(valueUnwrapped) + (*x.list)[i] = concreteValue +} + +func (x *_EchoRequest_22_list) Append(value protoreflect.Value) { + valueUnwrapped := value.Uint() + concreteValue := (uint32)(valueUnwrapped) + *x.list = append(*x.list, concreteValue) +} + +func (x *_EchoRequest_22_list) AppendMutable() protoreflect.Value { + panic(fmt.Errorf("AppendMutable can not be called on message EchoRequest at list field Uints as it is not of Message kind")) +} + +func (x *_EchoRequest_22_list) Truncate(n int) { + *x.list = (*x.list)[:n] +} + +func (x *_EchoRequest_22_list) NewElement() protoreflect.Value { + v := uint32(0) + return protoreflect.ValueOfUint32(v) +} + +func (x *_EchoRequest_22_list) IsValid() bool { + return x.list != nil +} + +var _ protoreflect.List = (*_EchoRequest_23_list)(nil) + +type _EchoRequest_23_list struct { + list *[]string +} + +func (x *_EchoRequest_23_list) Len() int { + if x.list == nil { + return 0 + } + return len(*x.list) +} + +func (x *_EchoRequest_23_list) Get(i int) protoreflect.Value { + return protoreflect.ValueOfString((*x.list)[i]) +} + +func (x *_EchoRequest_23_list) Set(i int, value protoreflect.Value) { + valueUnwrapped := value.String() + concreteValue := valueUnwrapped + (*x.list)[i] = concreteValue +} + +func (x *_EchoRequest_23_list) Append(value protoreflect.Value) { + valueUnwrapped := value.String() + concreteValue := valueUnwrapped + *x.list = append(*x.list, concreteValue) +} + +func (x *_EchoRequest_23_list) AppendMutable() protoreflect.Value { + panic(fmt.Errorf("AppendMutable can not be called on message EchoRequest at list field Strings as it is not of Message kind")) +} + +func (x *_EchoRequest_23_list) Truncate(n int) { + *x.list = (*x.list)[:n] +} + +func (x *_EchoRequest_23_list) NewElement() protoreflect.Value { + v := "" + return protoreflect.ValueOfString(v) +} + +func (x *_EchoRequest_23_list) IsValid() bool { + return x.list != nil +} + +var _ protoreflect.List = (*_EchoRequest_24_list)(nil) + +type _EchoRequest_24_list struct { + list *[]Enum +} + +func (x *_EchoRequest_24_list) Len() int { + if x.list == nil { + return 0 + } + return len(*x.list) +} + +func (x *_EchoRequest_24_list) Get(i int) protoreflect.Value { + return protoreflect.ValueOfEnum((protoreflect.EnumNumber)((*x.list)[i])) +} + +func (x *_EchoRequest_24_list) Set(i int, value protoreflect.Value) { + valueUnwrapped := value.Enum() + concreteValue := (Enum)(valueUnwrapped) + (*x.list)[i] = concreteValue +} + +func (x *_EchoRequest_24_list) Append(value protoreflect.Value) { + valueUnwrapped := value.Enum() + concreteValue := (Enum)(valueUnwrapped) + *x.list = append(*x.list, concreteValue) +} + +func (x *_EchoRequest_24_list) AppendMutable() protoreflect.Value { + panic(fmt.Errorf("AppendMutable can not be called on message EchoRequest at list field Enums as it is not of Message kind")) +} + +func (x *_EchoRequest_24_list) Truncate(n int) { + *x.list = (*x.list)[:n] +} + +func (x *_EchoRequest_24_list) NewElement() protoreflect.Value { + v := 0 + return protoreflect.ValueOfEnum((protoreflect.EnumNumber)(v)) +} + +func (x *_EchoRequest_24_list) IsValid() bool { + return x.list != nil +} + +var _ protoreflect.List = (*_EchoRequest_25_list)(nil) + +type _EchoRequest_25_list struct { + list *[]*durationpb.Duration +} + +func (x *_EchoRequest_25_list) Len() int { + if x.list == nil { + return 0 + } + return len(*x.list) +} + +func (x *_EchoRequest_25_list) Get(i int) protoreflect.Value { + return protoreflect.ValueOfMessage((*x.list)[i].ProtoReflect()) +} + +func (x *_EchoRequest_25_list) Set(i int, value protoreflect.Value) { + valueUnwrapped := value.Message() + concreteValue := valueUnwrapped.Interface().(*durationpb.Duration) + (*x.list)[i] = concreteValue +} + +func (x *_EchoRequest_25_list) Append(value protoreflect.Value) { + valueUnwrapped := value.Message() + concreteValue := valueUnwrapped.Interface().(*durationpb.Duration) + *x.list = append(*x.list, concreteValue) +} + +func (x *_EchoRequest_25_list) AppendMutable() protoreflect.Value { + v := new(durationpb.Duration) + *x.list = append(*x.list, v) + return protoreflect.ValueOfMessage(v.ProtoReflect()) +} + +func (x *_EchoRequest_25_list) Truncate(n int) { + for i := n; i < len(*x.list); i++ { + (*x.list)[i] = nil + } + *x.list = (*x.list)[:n] +} + +func (x *_EchoRequest_25_list) NewElement() protoreflect.Value { + v := new(durationpb.Duration) + return protoreflect.ValueOfMessage(v.ProtoReflect()) +} + +func (x *_EchoRequest_25_list) IsValid() bool { + return x.list != nil +} + +var _ protoreflect.List = (*_EchoRequest_26_list)(nil) + +type _EchoRequest_26_list struct { + list *[]*AMessage +} + +func (x *_EchoRequest_26_list) Len() int { + if x.list == nil { + return 0 + } + return len(*x.list) +} + +func (x *_EchoRequest_26_list) Get(i int) protoreflect.Value { + return protoreflect.ValueOfMessage((*x.list)[i].ProtoReflect()) +} + +func (x *_EchoRequest_26_list) Set(i int, value protoreflect.Value) { + valueUnwrapped := value.Message() + concreteValue := valueUnwrapped.Interface().(*AMessage) + (*x.list)[i] = concreteValue +} + +func (x *_EchoRequest_26_list) Append(value protoreflect.Value) { + valueUnwrapped := value.Message() + concreteValue := valueUnwrapped.Interface().(*AMessage) + *x.list = append(*x.list, concreteValue) +} + +func (x *_EchoRequest_26_list) AppendMutable() protoreflect.Value { + v := new(AMessage) + *x.list = append(*x.list, v) + return protoreflect.ValueOfMessage(v.ProtoReflect()) +} + +func (x *_EchoRequest_26_list) Truncate(n int) { + for i := n; i < len(*x.list); i++ { + (*x.list)[i] = nil + } + *x.list = (*x.list)[:n] +} + +func (x *_EchoRequest_26_list) NewElement() protoreflect.Value { + v := new(AMessage) + return protoreflect.ValueOfMessage(v.ProtoReflect()) +} + +func (x *_EchoRequest_26_list) IsValid() bool { + return x.list != nil +} + +var _ protoreflect.List = (*_EchoRequest_29_list)(nil) + +type _EchoRequest_29_list struct { + list *[]*v1beta1.Coin +} + +func (x *_EchoRequest_29_list) Len() int { + if x.list == nil { + return 0 + } + return len(*x.list) +} + +func (x *_EchoRequest_29_list) Get(i int) protoreflect.Value { + return protoreflect.ValueOfMessage((*x.list)[i].ProtoReflect()) +} + +func (x *_EchoRequest_29_list) Set(i int, value protoreflect.Value) { + valueUnwrapped := value.Message() + concreteValue := valueUnwrapped.Interface().(*v1beta1.Coin) + (*x.list)[i] = concreteValue +} + +func (x *_EchoRequest_29_list) Append(value protoreflect.Value) { + valueUnwrapped := value.Message() + concreteValue := valueUnwrapped.Interface().(*v1beta1.Coin) + *x.list = append(*x.list, concreteValue) +} + +func (x *_EchoRequest_29_list) AppendMutable() protoreflect.Value { + v := new(v1beta1.Coin) + *x.list = append(*x.list, v) + return protoreflect.ValueOfMessage(v.ProtoReflect()) +} + +func (x *_EchoRequest_29_list) Truncate(n int) { + for i := n; i < len(*x.list); i++ { + (*x.list)[i] = nil + } + *x.list = (*x.list)[:n] +} + +func (x *_EchoRequest_29_list) NewElement() protoreflect.Value { + v := new(v1beta1.Coin) + return protoreflect.ValueOfMessage(v.ProtoReflect()) +} + +func (x *_EchoRequest_29_list) IsValid() bool { + return x.list != nil +} + +var _ protoreflect.Map = (*_EchoRequest_33_map)(nil) + +type _EchoRequest_33_map struct { + m *map[string]string +} + +func (x *_EchoRequest_33_map) Len() int { + if x.m == nil { + return 0 + } + return len(*x.m) +} + +func (x *_EchoRequest_33_map) Range(f func(protoreflect.MapKey, protoreflect.Value) bool) { + if x.m == nil { + return + } + for k, v := range *x.m { + mapKey := (protoreflect.MapKey)(protoreflect.ValueOfString(k)) + mapValue := protoreflect.ValueOfString(v) + if !f(mapKey, mapValue) { + break + } + } +} + +func (x *_EchoRequest_33_map) Has(key protoreflect.MapKey) bool { + if x.m == nil { + return false + } + keyUnwrapped := key.String() + concreteValue := keyUnwrapped + _, ok := (*x.m)[concreteValue] + return ok +} + +func (x *_EchoRequest_33_map) Clear(key protoreflect.MapKey) { + if x.m == nil { + return + } + keyUnwrapped := key.String() + concreteKey := keyUnwrapped + delete(*x.m, concreteKey) +} + +func (x *_EchoRequest_33_map) Get(key protoreflect.MapKey) protoreflect.Value { + if x.m == nil { + return protoreflect.Value{} + } + keyUnwrapped := key.String() + concreteKey := keyUnwrapped + v, ok := (*x.m)[concreteKey] + if !ok { + return protoreflect.Value{} + } + return protoreflect.ValueOfString(v) +} + +func (x *_EchoRequest_33_map) Set(key protoreflect.MapKey, value protoreflect.Value) { + if !key.IsValid() || !value.IsValid() { + panic("invalid key or value provided") + } + keyUnwrapped := key.String() + concreteKey := keyUnwrapped + valueUnwrapped := value.String() + concreteValue := valueUnwrapped + (*x.m)[concreteKey] = concreteValue +} + +func (x *_EchoRequest_33_map) Mutable(key protoreflect.MapKey) protoreflect.Value { + panic("should not call Mutable on protoreflect.Map whose value is not of type protoreflect.Message") +} + +func (x *_EchoRequest_33_map) NewValue() protoreflect.Value { + v := "" + return protoreflect.ValueOfString(v) +} + +func (x *_EchoRequest_33_map) IsValid() bool { + return x.m != nil +} + +var _ protoreflect.Map = (*_EchoRequest_34_map)(nil) + +type _EchoRequest_34_map struct { + m *map[string]uint32 +} + +func (x *_EchoRequest_34_map) Len() int { + if x.m == nil { + return 0 + } + return len(*x.m) +} + +func (x *_EchoRequest_34_map) Range(f func(protoreflect.MapKey, protoreflect.Value) bool) { + if x.m == nil { + return + } + for k, v := range *x.m { + mapKey := (protoreflect.MapKey)(protoreflect.ValueOfString(k)) + mapValue := protoreflect.ValueOfUint32(v) + if !f(mapKey, mapValue) { + break + } + } +} + +func (x *_EchoRequest_34_map) Has(key protoreflect.MapKey) bool { + if x.m == nil { + return false + } + keyUnwrapped := key.String() + concreteValue := keyUnwrapped + _, ok := (*x.m)[concreteValue] + return ok +} + +func (x *_EchoRequest_34_map) Clear(key protoreflect.MapKey) { + if x.m == nil { + return + } + keyUnwrapped := key.String() + concreteKey := keyUnwrapped + delete(*x.m, concreteKey) +} + +func (x *_EchoRequest_34_map) Get(key protoreflect.MapKey) protoreflect.Value { + if x.m == nil { + return protoreflect.Value{} + } + keyUnwrapped := key.String() + concreteKey := keyUnwrapped + v, ok := (*x.m)[concreteKey] + if !ok { + return protoreflect.Value{} + } + return protoreflect.ValueOfUint32(v) +} + +func (x *_EchoRequest_34_map) Set(key protoreflect.MapKey, value protoreflect.Value) { + if !key.IsValid() || !value.IsValid() { + panic("invalid key or value provided") + } + keyUnwrapped := key.String() + concreteKey := keyUnwrapped + valueUnwrapped := value.Uint() + concreteValue := (uint32)(valueUnwrapped) + (*x.m)[concreteKey] = concreteValue +} + +func (x *_EchoRequest_34_map) Mutable(key protoreflect.MapKey) protoreflect.Value { + panic("should not call Mutable on protoreflect.Map whose value is not of type protoreflect.Message") +} + +func (x *_EchoRequest_34_map) NewValue() protoreflect.Value { + v := uint32(0) + return protoreflect.ValueOfUint32(v) +} + +func (x *_EchoRequest_34_map) IsValid() bool { + return x.m != nil +} + +var _ protoreflect.Map = (*_EchoRequest_35_map)(nil) + +type _EchoRequest_35_map struct { + m *map[string]*v1beta1.Coin +} + +func (x *_EchoRequest_35_map) Len() int { + if x.m == nil { + return 0 + } + return len(*x.m) +} + +func (x *_EchoRequest_35_map) Range(f func(protoreflect.MapKey, protoreflect.Value) bool) { + if x.m == nil { + return + } + for k, v := range *x.m { + mapKey := (protoreflect.MapKey)(protoreflect.ValueOfString(k)) + mapValue := protoreflect.ValueOfMessage(v.ProtoReflect()) + if !f(mapKey, mapValue) { + break + } + } +} + +func (x *_EchoRequest_35_map) Has(key protoreflect.MapKey) bool { + if x.m == nil { + return false + } + keyUnwrapped := key.String() + concreteValue := keyUnwrapped + _, ok := (*x.m)[concreteValue] + return ok +} + +func (x *_EchoRequest_35_map) Clear(key protoreflect.MapKey) { + if x.m == nil { + return + } + keyUnwrapped := key.String() + concreteKey := keyUnwrapped + delete(*x.m, concreteKey) +} + +func (x *_EchoRequest_35_map) Get(key protoreflect.MapKey) protoreflect.Value { + if x.m == nil { + return protoreflect.Value{} + } + keyUnwrapped := key.String() + concreteKey := keyUnwrapped + v, ok := (*x.m)[concreteKey] + if !ok { + return protoreflect.Value{} + } + return protoreflect.ValueOfMessage(v.ProtoReflect()) +} + +func (x *_EchoRequest_35_map) Set(key protoreflect.MapKey, value protoreflect.Value) { + if !key.IsValid() || !value.IsValid() { + panic("invalid key or value provided") + } + keyUnwrapped := key.String() + concreteKey := keyUnwrapped + valueUnwrapped := value.Message() + concreteValue := valueUnwrapped.Interface().(*v1beta1.Coin) + (*x.m)[concreteKey] = concreteValue +} + +func (x *_EchoRequest_35_map) Mutable(key protoreflect.MapKey) protoreflect.Value { + keyUnwrapped := key.String() + concreteKey := keyUnwrapped + v, ok := (*x.m)[concreteKey] + if ok { + return protoreflect.ValueOfMessage(v.ProtoReflect()) + } + newValue := new(v1beta1.Coin) + (*x.m)[concreteKey] = newValue + return protoreflect.ValueOfMessage(newValue.ProtoReflect()) +} + +func (x *_EchoRequest_35_map) NewValue() protoreflect.Value { + v := new(v1beta1.Coin) + return protoreflect.ValueOfMessage(v.ProtoReflect()) +} + +func (x *_EchoRequest_35_map) IsValid() bool { + return x.m != nil +} + +var _ protoreflect.List = (*_EchoRequest_38_list)(nil) + +type _EchoRequest_38_list struct { + list *[]*v1beta1.Coin +} + +func (x *_EchoRequest_38_list) Len() int { + if x.list == nil { + return 0 + } + return len(*x.list) +} + +func (x *_EchoRequest_38_list) Get(i int) protoreflect.Value { + return protoreflect.ValueOfMessage((*x.list)[i].ProtoReflect()) +} + +func (x *_EchoRequest_38_list) Set(i int, value protoreflect.Value) { + valueUnwrapped := value.Message() + concreteValue := valueUnwrapped.Interface().(*v1beta1.Coin) + (*x.list)[i] = concreteValue +} + +func (x *_EchoRequest_38_list) Append(value protoreflect.Value) { + valueUnwrapped := value.Message() + concreteValue := valueUnwrapped.Interface().(*v1beta1.Coin) + *x.list = append(*x.list, concreteValue) +} + +func (x *_EchoRequest_38_list) AppendMutable() protoreflect.Value { + v := new(v1beta1.Coin) + *x.list = append(*x.list, v) + return protoreflect.ValueOfMessage(v.ProtoReflect()) +} + +func (x *_EchoRequest_38_list) Truncate(n int) { + for i := n; i < len(*x.list); i++ { + (*x.list)[i] = nil + } + *x.list = (*x.list)[:n] +} + +func (x *_EchoRequest_38_list) NewElement() protoreflect.Value { + v := new(v1beta1.Coin) + return protoreflect.ValueOfMessage(v.ProtoReflect()) +} + +func (x *_EchoRequest_38_list) IsValid() bool { + return x.list != nil +} + +var ( + md_EchoRequest protoreflect.MessageDescriptor + fd_EchoRequest_u32 protoreflect.FieldDescriptor + fd_EchoRequest_u64 protoreflect.FieldDescriptor + fd_EchoRequest_str protoreflect.FieldDescriptor + fd_EchoRequest_bz protoreflect.FieldDescriptor + fd_EchoRequest_timestamp protoreflect.FieldDescriptor + fd_EchoRequest_duration protoreflect.FieldDescriptor + fd_EchoRequest_i32 protoreflect.FieldDescriptor + fd_EchoRequest_i64 protoreflect.FieldDescriptor + fd_EchoRequest_a_bool protoreflect.FieldDescriptor + fd_EchoRequest_an_enum protoreflect.FieldDescriptor + fd_EchoRequest_a_message protoreflect.FieldDescriptor + fd_EchoRequest_a_coin protoreflect.FieldDescriptor + fd_EchoRequest_an_address protoreflect.FieldDescriptor + fd_EchoRequest_page protoreflect.FieldDescriptor + fd_EchoRequest_bools protoreflect.FieldDescriptor + fd_EchoRequest_uints protoreflect.FieldDescriptor + fd_EchoRequest_strings protoreflect.FieldDescriptor + fd_EchoRequest_enums protoreflect.FieldDescriptor + fd_EchoRequest_durations protoreflect.FieldDescriptor + fd_EchoRequest_some_messages protoreflect.FieldDescriptor + fd_EchoRequest_positional1 protoreflect.FieldDescriptor + fd_EchoRequest_positional2 protoreflect.FieldDescriptor + fd_EchoRequest_positional3_varargs protoreflect.FieldDescriptor + fd_EchoRequest_deprecated_field protoreflect.FieldDescriptor + fd_EchoRequest_shorthand_deprecated_field protoreflect.FieldDescriptor + fd_EchoRequest_hidden_bool protoreflect.FieldDescriptor + fd_EchoRequest_map_string_string protoreflect.FieldDescriptor + fd_EchoRequest_map_string_uint32 protoreflect.FieldDescriptor + fd_EchoRequest_map_string_coin protoreflect.FieldDescriptor + fd_EchoRequest_a_validator_address protoreflect.FieldDescriptor + fd_EchoRequest_a_consensus_address protoreflect.FieldDescriptor + fd_EchoRequest_coins protoreflect.FieldDescriptor +) + +func init() { + file_testpb_query_proto_init() + md_EchoRequest = File_testpb_query_proto.Messages().ByName("EchoRequest") + fd_EchoRequest_u32 = md_EchoRequest.Fields().ByName("u32") + fd_EchoRequest_u64 = md_EchoRequest.Fields().ByName("u64") + fd_EchoRequest_str = md_EchoRequest.Fields().ByName("str") + fd_EchoRequest_bz = md_EchoRequest.Fields().ByName("bz") + fd_EchoRequest_timestamp = md_EchoRequest.Fields().ByName("timestamp") + fd_EchoRequest_duration = md_EchoRequest.Fields().ByName("duration") + fd_EchoRequest_i32 = md_EchoRequest.Fields().ByName("i32") + fd_EchoRequest_i64 = md_EchoRequest.Fields().ByName("i64") + fd_EchoRequest_a_bool = md_EchoRequest.Fields().ByName("a_bool") + fd_EchoRequest_an_enum = md_EchoRequest.Fields().ByName("an_enum") + fd_EchoRequest_a_message = md_EchoRequest.Fields().ByName("a_message") + fd_EchoRequest_a_coin = md_EchoRequest.Fields().ByName("a_coin") + fd_EchoRequest_an_address = md_EchoRequest.Fields().ByName("an_address") + fd_EchoRequest_page = md_EchoRequest.Fields().ByName("page") + fd_EchoRequest_bools = md_EchoRequest.Fields().ByName("bools") + fd_EchoRequest_uints = md_EchoRequest.Fields().ByName("uints") + fd_EchoRequest_strings = md_EchoRequest.Fields().ByName("strings") + fd_EchoRequest_enums = md_EchoRequest.Fields().ByName("enums") + fd_EchoRequest_durations = md_EchoRequest.Fields().ByName("durations") + fd_EchoRequest_some_messages = md_EchoRequest.Fields().ByName("some_messages") + fd_EchoRequest_positional1 = md_EchoRequest.Fields().ByName("positional1") + fd_EchoRequest_positional2 = md_EchoRequest.Fields().ByName("positional2") + fd_EchoRequest_positional3_varargs = md_EchoRequest.Fields().ByName("positional3_varargs") + fd_EchoRequest_deprecated_field = md_EchoRequest.Fields().ByName("deprecated_field") + fd_EchoRequest_shorthand_deprecated_field = md_EchoRequest.Fields().ByName("shorthand_deprecated_field") + fd_EchoRequest_hidden_bool = md_EchoRequest.Fields().ByName("hidden_bool") + fd_EchoRequest_map_string_string = md_EchoRequest.Fields().ByName("map_string_string") + fd_EchoRequest_map_string_uint32 = md_EchoRequest.Fields().ByName("map_string_uint32") + fd_EchoRequest_map_string_coin = md_EchoRequest.Fields().ByName("map_string_coin") + fd_EchoRequest_a_validator_address = md_EchoRequest.Fields().ByName("a_validator_address") + fd_EchoRequest_a_consensus_address = md_EchoRequest.Fields().ByName("a_consensus_address") + fd_EchoRequest_coins = md_EchoRequest.Fields().ByName("coins") +} + +var _ protoreflect.Message = (*fastReflection_EchoRequest)(nil) + +type fastReflection_EchoRequest EchoRequest + +func (x *EchoRequest) ProtoReflect() protoreflect.Message { + return (*fastReflection_EchoRequest)(x) +} + +func (x *EchoRequest) slowProtoReflect() protoreflect.Message { + mi := &file_testpb_query_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +var _fastReflection_EchoRequest_messageType fastReflection_EchoRequest_messageType +var _ protoreflect.MessageType = fastReflection_EchoRequest_messageType{} + +type fastReflection_EchoRequest_messageType struct{} + +func (x fastReflection_EchoRequest_messageType) Zero() protoreflect.Message { + return (*fastReflection_EchoRequest)(nil) +} +func (x fastReflection_EchoRequest_messageType) New() protoreflect.Message { + return new(fastReflection_EchoRequest) +} +func (x fastReflection_EchoRequest_messageType) Descriptor() protoreflect.MessageDescriptor { + return md_EchoRequest +} + +// Descriptor returns message descriptor, which contains only the protobuf +// type information for the message. +func (x *fastReflection_EchoRequest) Descriptor() protoreflect.MessageDescriptor { + return md_EchoRequest +} + +// Type returns the message type, which encapsulates both Go and protobuf +// type information. If the Go type information is not needed, +// it is recommended that the message descriptor be used instead. +func (x *fastReflection_EchoRequest) Type() protoreflect.MessageType { + return _fastReflection_EchoRequest_messageType +} + +// New returns a newly allocated and mutable empty message. +func (x *fastReflection_EchoRequest) New() protoreflect.Message { + return new(fastReflection_EchoRequest) +} + +// Interface unwraps the message reflection interface and +// returns the underlying ProtoMessage interface. +func (x *fastReflection_EchoRequest) Interface() protoreflect.ProtoMessage { + return (*EchoRequest)(x) +} + +// Range iterates over every populated field in an undefined order, +// calling f for each field descriptor and value encountered. +// Range returns immediately if f returns false. +// While iterating, mutating operations may only be performed +// on the current field descriptor. +func (x *fastReflection_EchoRequest) Range(f func(protoreflect.FieldDescriptor, protoreflect.Value) bool) { + if x.U32 != uint32(0) { + value := protoreflect.ValueOfUint32(x.U32) + if !f(fd_EchoRequest_u32, value) { + return + } + } + if x.U64 != uint64(0) { + value := protoreflect.ValueOfUint64(x.U64) + if !f(fd_EchoRequest_u64, value) { + return + } + } + if x.Str != "" { + value := protoreflect.ValueOfString(x.Str) + if !f(fd_EchoRequest_str, value) { + return + } + } + if len(x.Bz) != 0 { + value := protoreflect.ValueOfBytes(x.Bz) + if !f(fd_EchoRequest_bz, value) { + return + } + } + if x.Timestamp != nil { + value := protoreflect.ValueOfMessage(x.Timestamp.ProtoReflect()) + if !f(fd_EchoRequest_timestamp, value) { + return + } + } + if x.Duration != nil { + value := protoreflect.ValueOfMessage(x.Duration.ProtoReflect()) + if !f(fd_EchoRequest_duration, value) { + return + } + } + if x.I32 != int32(0) { + value := protoreflect.ValueOfInt32(x.I32) + if !f(fd_EchoRequest_i32, value) { + return + } + } + if x.I64 != int64(0) { + value := protoreflect.ValueOfInt64(x.I64) + if !f(fd_EchoRequest_i64, value) { + return + } + } + if x.ABool != false { + value := protoreflect.ValueOfBool(x.ABool) + if !f(fd_EchoRequest_a_bool, value) { + return + } + } + if x.AnEnum != 0 { + value := protoreflect.ValueOfEnum((protoreflect.EnumNumber)(x.AnEnum)) + if !f(fd_EchoRequest_an_enum, value) { + return + } + } + if x.AMessage != nil { + value := protoreflect.ValueOfMessage(x.AMessage.ProtoReflect()) + if !f(fd_EchoRequest_a_message, value) { + return + } + } + if x.ACoin != nil { + value := protoreflect.ValueOfMessage(x.ACoin.ProtoReflect()) + if !f(fd_EchoRequest_a_coin, value) { + return + } + } + if x.AnAddress != "" { + value := protoreflect.ValueOfString(x.AnAddress) + if !f(fd_EchoRequest_an_address, value) { + return + } + } + if x.Page != nil { + value := protoreflect.ValueOfMessage(x.Page.ProtoReflect()) + if !f(fd_EchoRequest_page, value) { + return + } + } + if len(x.Bools) != 0 { + value := protoreflect.ValueOfList(&_EchoRequest_21_list{list: &x.Bools}) + if !f(fd_EchoRequest_bools, value) { + return + } + } + if len(x.Uints) != 0 { + value := protoreflect.ValueOfList(&_EchoRequest_22_list{list: &x.Uints}) + if !f(fd_EchoRequest_uints, value) { + return + } + } + if len(x.Strings) != 0 { + value := protoreflect.ValueOfList(&_EchoRequest_23_list{list: &x.Strings}) + if !f(fd_EchoRequest_strings, value) { + return + } + } + if len(x.Enums) != 0 { + value := protoreflect.ValueOfList(&_EchoRequest_24_list{list: &x.Enums}) + if !f(fd_EchoRequest_enums, value) { + return + } + } + if len(x.Durations) != 0 { + value := protoreflect.ValueOfList(&_EchoRequest_25_list{list: &x.Durations}) + if !f(fd_EchoRequest_durations, value) { + return + } + } + if len(x.SomeMessages) != 0 { + value := protoreflect.ValueOfList(&_EchoRequest_26_list{list: &x.SomeMessages}) + if !f(fd_EchoRequest_some_messages, value) { + return + } + } + if x.Positional1 != int32(0) { + value := protoreflect.ValueOfInt32(x.Positional1) + if !f(fd_EchoRequest_positional1, value) { + return + } + } + if x.Positional2 != "" { + value := protoreflect.ValueOfString(x.Positional2) + if !f(fd_EchoRequest_positional2, value) { + return + } + } + if len(x.Positional3Varargs) != 0 { + value := protoreflect.ValueOfList(&_EchoRequest_29_list{list: &x.Positional3Varargs}) + if !f(fd_EchoRequest_positional3_varargs, value) { + return + } + } + if x.DeprecatedField != "" { + value := protoreflect.ValueOfString(x.DeprecatedField) + if !f(fd_EchoRequest_deprecated_field, value) { + return + } + } + if x.ShorthandDeprecatedField != "" { + value := protoreflect.ValueOfString(x.ShorthandDeprecatedField) + if !f(fd_EchoRequest_shorthand_deprecated_field, value) { + return + } + } + if x.HiddenBool != false { + value := protoreflect.ValueOfBool(x.HiddenBool) + if !f(fd_EchoRequest_hidden_bool, value) { + return + } + } + if len(x.MapStringString) != 0 { + value := protoreflect.ValueOfMap(&_EchoRequest_33_map{m: &x.MapStringString}) + if !f(fd_EchoRequest_map_string_string, value) { + return + } + } + if len(x.MapStringUint32) != 0 { + value := protoreflect.ValueOfMap(&_EchoRequest_34_map{m: &x.MapStringUint32}) + if !f(fd_EchoRequest_map_string_uint32, value) { + return + } + } + if len(x.MapStringCoin) != 0 { + value := protoreflect.ValueOfMap(&_EchoRequest_35_map{m: &x.MapStringCoin}) + if !f(fd_EchoRequest_map_string_coin, value) { + return + } + } + if x.AValidatorAddress != "" { + value := protoreflect.ValueOfString(x.AValidatorAddress) + if !f(fd_EchoRequest_a_validator_address, value) { + return + } + } + if x.AConsensusAddress != "" { + value := protoreflect.ValueOfString(x.AConsensusAddress) + if !f(fd_EchoRequest_a_consensus_address, value) { + return + } + } + if len(x.Coins) != 0 { + value := protoreflect.ValueOfList(&_EchoRequest_38_list{list: &x.Coins}) + if !f(fd_EchoRequest_coins, value) { + return + } + } +} + +// Has reports whether a field is populated. +// +// Some fields have the property of nullability where it is possible to +// distinguish between the default value of a field and whether the field +// was explicitly populated with the default value. Singular message fields, +// member fields of a oneof, and proto2 scalar fields are nullable. Such +// fields are populated only if explicitly set. +// +// In other cases (aside from the nullable cases above), +// a proto3 scalar field is populated if it contains a non-zero value, and +// a repeated field is populated if it is non-empty. +func (x *fastReflection_EchoRequest) Has(fd protoreflect.FieldDescriptor) bool { + switch fd.FullName() { + case "testpb.EchoRequest.u32": + return x.U32 != uint32(0) + case "testpb.EchoRequest.u64": + return x.U64 != uint64(0) + case "testpb.EchoRequest.str": + return x.Str != "" + case "testpb.EchoRequest.bz": + return len(x.Bz) != 0 + case "testpb.EchoRequest.timestamp": + return x.Timestamp != nil + case "testpb.EchoRequest.duration": + return x.Duration != nil + case "testpb.EchoRequest.i32": + return x.I32 != int32(0) + case "testpb.EchoRequest.i64": + return x.I64 != int64(0) + case "testpb.EchoRequest.a_bool": + return x.ABool != false + case "testpb.EchoRequest.an_enum": + return x.AnEnum != 0 + case "testpb.EchoRequest.a_message": + return x.AMessage != nil + case "testpb.EchoRequest.a_coin": + return x.ACoin != nil + case "testpb.EchoRequest.an_address": + return x.AnAddress != "" + case "testpb.EchoRequest.page": + return x.Page != nil + case "testpb.EchoRequest.bools": + return len(x.Bools) != 0 + case "testpb.EchoRequest.uints": + return len(x.Uints) != 0 + case "testpb.EchoRequest.strings": + return len(x.Strings) != 0 + case "testpb.EchoRequest.enums": + return len(x.Enums) != 0 + case "testpb.EchoRequest.durations": + return len(x.Durations) != 0 + case "testpb.EchoRequest.some_messages": + return len(x.SomeMessages) != 0 + case "testpb.EchoRequest.positional1": + return x.Positional1 != int32(0) + case "testpb.EchoRequest.positional2": + return x.Positional2 != "" + case "testpb.EchoRequest.positional3_varargs": + return len(x.Positional3Varargs) != 0 + case "testpb.EchoRequest.deprecated_field": + return x.DeprecatedField != "" + case "testpb.EchoRequest.shorthand_deprecated_field": + return x.ShorthandDeprecatedField != "" + case "testpb.EchoRequest.hidden_bool": + return x.HiddenBool != false + case "testpb.EchoRequest.map_string_string": + return len(x.MapStringString) != 0 + case "testpb.EchoRequest.map_string_uint32": + return len(x.MapStringUint32) != 0 + case "testpb.EchoRequest.map_string_coin": + return len(x.MapStringCoin) != 0 + case "testpb.EchoRequest.a_validator_address": + return x.AValidatorAddress != "" + case "testpb.EchoRequest.a_consensus_address": + return x.AConsensusAddress != "" + case "testpb.EchoRequest.coins": + return len(x.Coins) != 0 + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.EchoRequest")) + } + panic(fmt.Errorf("message testpb.EchoRequest does not contain field %s", fd.FullName())) + } +} + +// Clear clears the field such that a subsequent Has call reports false. +// +// Clearing an extension field clears both the extension type and value +// associated with the given field number. +// +// Clear is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_EchoRequest) Clear(fd protoreflect.FieldDescriptor) { + switch fd.FullName() { + case "testpb.EchoRequest.u32": + x.U32 = uint32(0) + case "testpb.EchoRequest.u64": + x.U64 = uint64(0) + case "testpb.EchoRequest.str": + x.Str = "" + case "testpb.EchoRequest.bz": + x.Bz = nil + case "testpb.EchoRequest.timestamp": + x.Timestamp = nil + case "testpb.EchoRequest.duration": + x.Duration = nil + case "testpb.EchoRequest.i32": + x.I32 = int32(0) + case "testpb.EchoRequest.i64": + x.I64 = int64(0) + case "testpb.EchoRequest.a_bool": + x.ABool = false + case "testpb.EchoRequest.an_enum": + x.AnEnum = 0 + case "testpb.EchoRequest.a_message": + x.AMessage = nil + case "testpb.EchoRequest.a_coin": + x.ACoin = nil + case "testpb.EchoRequest.an_address": + x.AnAddress = "" + case "testpb.EchoRequest.page": + x.Page = nil + case "testpb.EchoRequest.bools": + x.Bools = nil + case "testpb.EchoRequest.uints": + x.Uints = nil + case "testpb.EchoRequest.strings": + x.Strings = nil + case "testpb.EchoRequest.enums": + x.Enums = nil + case "testpb.EchoRequest.durations": + x.Durations = nil + case "testpb.EchoRequest.some_messages": + x.SomeMessages = nil + case "testpb.EchoRequest.positional1": + x.Positional1 = int32(0) + case "testpb.EchoRequest.positional2": + x.Positional2 = "" + case "testpb.EchoRequest.positional3_varargs": + x.Positional3Varargs = nil + case "testpb.EchoRequest.deprecated_field": + x.DeprecatedField = "" + case "testpb.EchoRequest.shorthand_deprecated_field": + x.ShorthandDeprecatedField = "" + case "testpb.EchoRequest.hidden_bool": + x.HiddenBool = false + case "testpb.EchoRequest.map_string_string": + x.MapStringString = nil + case "testpb.EchoRequest.map_string_uint32": + x.MapStringUint32 = nil + case "testpb.EchoRequest.map_string_coin": + x.MapStringCoin = nil + case "testpb.EchoRequest.a_validator_address": + x.AValidatorAddress = "" + case "testpb.EchoRequest.a_consensus_address": + x.AConsensusAddress = "" + case "testpb.EchoRequest.coins": + x.Coins = nil + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.EchoRequest")) + } + panic(fmt.Errorf("message testpb.EchoRequest does not contain field %s", fd.FullName())) + } +} + +// Get retrieves the value for a field. +// +// For unpopulated scalars, it returns the default value, where +// the default value of a bytes scalar is guaranteed to be a copy. +// For unpopulated composite types, it returns an empty, read-only view +// of the value; to obtain a mutable reference, use Mutable. +func (x *fastReflection_EchoRequest) Get(descriptor protoreflect.FieldDescriptor) protoreflect.Value { + switch descriptor.FullName() { + case "testpb.EchoRequest.u32": + value := x.U32 + return protoreflect.ValueOfUint32(value) + case "testpb.EchoRequest.u64": + value := x.U64 + return protoreflect.ValueOfUint64(value) + case "testpb.EchoRequest.str": + value := x.Str + return protoreflect.ValueOfString(value) + case "testpb.EchoRequest.bz": + value := x.Bz + return protoreflect.ValueOfBytes(value) + case "testpb.EchoRequest.timestamp": + value := x.Timestamp + return protoreflect.ValueOfMessage(value.ProtoReflect()) + case "testpb.EchoRequest.duration": + value := x.Duration + return protoreflect.ValueOfMessage(value.ProtoReflect()) + case "testpb.EchoRequest.i32": + value := x.I32 + return protoreflect.ValueOfInt32(value) + case "testpb.EchoRequest.i64": + value := x.I64 + return protoreflect.ValueOfInt64(value) + case "testpb.EchoRequest.a_bool": + value := x.ABool + return protoreflect.ValueOfBool(value) + case "testpb.EchoRequest.an_enum": + value := x.AnEnum + return protoreflect.ValueOfEnum((protoreflect.EnumNumber)(value)) + case "testpb.EchoRequest.a_message": + value := x.AMessage + return protoreflect.ValueOfMessage(value.ProtoReflect()) + case "testpb.EchoRequest.a_coin": + value := x.ACoin + return protoreflect.ValueOfMessage(value.ProtoReflect()) + case "testpb.EchoRequest.an_address": + value := x.AnAddress + return protoreflect.ValueOfString(value) + case "testpb.EchoRequest.page": + value := x.Page + return protoreflect.ValueOfMessage(value.ProtoReflect()) + case "testpb.EchoRequest.bools": + if len(x.Bools) == 0 { + return protoreflect.ValueOfList(&_EchoRequest_21_list{}) + } + listValue := &_EchoRequest_21_list{list: &x.Bools} + return protoreflect.ValueOfList(listValue) + case "testpb.EchoRequest.uints": + if len(x.Uints) == 0 { + return protoreflect.ValueOfList(&_EchoRequest_22_list{}) + } + listValue := &_EchoRequest_22_list{list: &x.Uints} + return protoreflect.ValueOfList(listValue) + case "testpb.EchoRequest.strings": + if len(x.Strings) == 0 { + return protoreflect.ValueOfList(&_EchoRequest_23_list{}) + } + listValue := &_EchoRequest_23_list{list: &x.Strings} + return protoreflect.ValueOfList(listValue) + case "testpb.EchoRequest.enums": + if len(x.Enums) == 0 { + return protoreflect.ValueOfList(&_EchoRequest_24_list{}) + } + listValue := &_EchoRequest_24_list{list: &x.Enums} + return protoreflect.ValueOfList(listValue) + case "testpb.EchoRequest.durations": + if len(x.Durations) == 0 { + return protoreflect.ValueOfList(&_EchoRequest_25_list{}) + } + listValue := &_EchoRequest_25_list{list: &x.Durations} + return protoreflect.ValueOfList(listValue) + case "testpb.EchoRequest.some_messages": + if len(x.SomeMessages) == 0 { + return protoreflect.ValueOfList(&_EchoRequest_26_list{}) + } + listValue := &_EchoRequest_26_list{list: &x.SomeMessages} + return protoreflect.ValueOfList(listValue) + case "testpb.EchoRequest.positional1": + value := x.Positional1 + return protoreflect.ValueOfInt32(value) + case "testpb.EchoRequest.positional2": + value := x.Positional2 + return protoreflect.ValueOfString(value) + case "testpb.EchoRequest.positional3_varargs": + if len(x.Positional3Varargs) == 0 { + return protoreflect.ValueOfList(&_EchoRequest_29_list{}) + } + listValue := &_EchoRequest_29_list{list: &x.Positional3Varargs} + return protoreflect.ValueOfList(listValue) + case "testpb.EchoRequest.deprecated_field": + value := x.DeprecatedField + return protoreflect.ValueOfString(value) + case "testpb.EchoRequest.shorthand_deprecated_field": + value := x.ShorthandDeprecatedField + return protoreflect.ValueOfString(value) + case "testpb.EchoRequest.hidden_bool": + value := x.HiddenBool + return protoreflect.ValueOfBool(value) + case "testpb.EchoRequest.map_string_string": + if len(x.MapStringString) == 0 { + return protoreflect.ValueOfMap(&_EchoRequest_33_map{}) + } + mapValue := &_EchoRequest_33_map{m: &x.MapStringString} + return protoreflect.ValueOfMap(mapValue) + case "testpb.EchoRequest.map_string_uint32": + if len(x.MapStringUint32) == 0 { + return protoreflect.ValueOfMap(&_EchoRequest_34_map{}) + } + mapValue := &_EchoRequest_34_map{m: &x.MapStringUint32} + return protoreflect.ValueOfMap(mapValue) + case "testpb.EchoRequest.map_string_coin": + if len(x.MapStringCoin) == 0 { + return protoreflect.ValueOfMap(&_EchoRequest_35_map{}) + } + mapValue := &_EchoRequest_35_map{m: &x.MapStringCoin} + return protoreflect.ValueOfMap(mapValue) + case "testpb.EchoRequest.a_validator_address": + value := x.AValidatorAddress + return protoreflect.ValueOfString(value) + case "testpb.EchoRequest.a_consensus_address": + value := x.AConsensusAddress + return protoreflect.ValueOfString(value) + case "testpb.EchoRequest.coins": + if len(x.Coins) == 0 { + return protoreflect.ValueOfList(&_EchoRequest_38_list{}) + } + listValue := &_EchoRequest_38_list{list: &x.Coins} + return protoreflect.ValueOfList(listValue) + default: + if descriptor.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.EchoRequest")) + } + panic(fmt.Errorf("message testpb.EchoRequest does not contain field %s", descriptor.FullName())) + } +} + +// Set stores the value for a field. +// +// For a field belonging to a oneof, it implicitly clears any other field +// that may be currently set within the same oneof. +// For extension fields, it implicitly stores the provided ExtensionType. +// When setting a composite type, it is unspecified whether the stored value +// aliases the source's memory in any way. If the composite value is an +// empty, read-only value, then it panics. +// +// Set is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_EchoRequest) Set(fd protoreflect.FieldDescriptor, value protoreflect.Value) { + switch fd.FullName() { + case "testpb.EchoRequest.u32": + x.U32 = uint32(value.Uint()) + case "testpb.EchoRequest.u64": + x.U64 = value.Uint() + case "testpb.EchoRequest.str": + x.Str = value.Interface().(string) + case "testpb.EchoRequest.bz": + x.Bz = value.Bytes() + case "testpb.EchoRequest.timestamp": + x.Timestamp = value.Message().Interface().(*timestamppb.Timestamp) + case "testpb.EchoRequest.duration": + x.Duration = value.Message().Interface().(*durationpb.Duration) + case "testpb.EchoRequest.i32": + x.I32 = int32(value.Int()) + case "testpb.EchoRequest.i64": + x.I64 = value.Int() + case "testpb.EchoRequest.a_bool": + x.ABool = value.Bool() + case "testpb.EchoRequest.an_enum": + x.AnEnum = (Enum)(value.Enum()) + case "testpb.EchoRequest.a_message": + x.AMessage = value.Message().Interface().(*AMessage) + case "testpb.EchoRequest.a_coin": + x.ACoin = value.Message().Interface().(*v1beta1.Coin) + case "testpb.EchoRequest.an_address": + x.AnAddress = value.Interface().(string) + case "testpb.EchoRequest.page": + x.Page = value.Message().Interface().(*v1beta11.PageRequest) + case "testpb.EchoRequest.bools": + lv := value.List() + clv := lv.(*_EchoRequest_21_list) + x.Bools = *clv.list + case "testpb.EchoRequest.uints": + lv := value.List() + clv := lv.(*_EchoRequest_22_list) + x.Uints = *clv.list + case "testpb.EchoRequest.strings": + lv := value.List() + clv := lv.(*_EchoRequest_23_list) + x.Strings = *clv.list + case "testpb.EchoRequest.enums": + lv := value.List() + clv := lv.(*_EchoRequest_24_list) + x.Enums = *clv.list + case "testpb.EchoRequest.durations": + lv := value.List() + clv := lv.(*_EchoRequest_25_list) + x.Durations = *clv.list + case "testpb.EchoRequest.some_messages": + lv := value.List() + clv := lv.(*_EchoRequest_26_list) + x.SomeMessages = *clv.list + case "testpb.EchoRequest.positional1": + x.Positional1 = int32(value.Int()) + case "testpb.EchoRequest.positional2": + x.Positional2 = value.Interface().(string) + case "testpb.EchoRequest.positional3_varargs": + lv := value.List() + clv := lv.(*_EchoRequest_29_list) + x.Positional3Varargs = *clv.list + case "testpb.EchoRequest.deprecated_field": + x.DeprecatedField = value.Interface().(string) + case "testpb.EchoRequest.shorthand_deprecated_field": + x.ShorthandDeprecatedField = value.Interface().(string) + case "testpb.EchoRequest.hidden_bool": + x.HiddenBool = value.Bool() + case "testpb.EchoRequest.map_string_string": + mv := value.Map() + cmv := mv.(*_EchoRequest_33_map) + x.MapStringString = *cmv.m + case "testpb.EchoRequest.map_string_uint32": + mv := value.Map() + cmv := mv.(*_EchoRequest_34_map) + x.MapStringUint32 = *cmv.m + case "testpb.EchoRequest.map_string_coin": + mv := value.Map() + cmv := mv.(*_EchoRequest_35_map) + x.MapStringCoin = *cmv.m + case "testpb.EchoRequest.a_validator_address": + x.AValidatorAddress = value.Interface().(string) + case "testpb.EchoRequest.a_consensus_address": + x.AConsensusAddress = value.Interface().(string) + case "testpb.EchoRequest.coins": + lv := value.List() + clv := lv.(*_EchoRequest_38_list) + x.Coins = *clv.list + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.EchoRequest")) + } + panic(fmt.Errorf("message testpb.EchoRequest does not contain field %s", fd.FullName())) + } +} + +// Mutable returns a mutable reference to a composite type. +// +// If the field is unpopulated, it may allocate a composite value. +// For a field belonging to a oneof, it implicitly clears any other field +// that may be currently set within the same oneof. +// For extension fields, it implicitly stores the provided ExtensionType +// if not already stored. +// It panics if the field does not contain a composite type. +// +// Mutable is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_EchoRequest) Mutable(fd protoreflect.FieldDescriptor) protoreflect.Value { + switch fd.FullName() { + case "testpb.EchoRequest.timestamp": + if x.Timestamp == nil { + x.Timestamp = new(timestamppb.Timestamp) + } + return protoreflect.ValueOfMessage(x.Timestamp.ProtoReflect()) + case "testpb.EchoRequest.duration": + if x.Duration == nil { + x.Duration = new(durationpb.Duration) + } + return protoreflect.ValueOfMessage(x.Duration.ProtoReflect()) + case "testpb.EchoRequest.a_message": + if x.AMessage == nil { + x.AMessage = new(AMessage) + } + return protoreflect.ValueOfMessage(x.AMessage.ProtoReflect()) + case "testpb.EchoRequest.a_coin": + if x.ACoin == nil { + x.ACoin = new(v1beta1.Coin) + } + return protoreflect.ValueOfMessage(x.ACoin.ProtoReflect()) + case "testpb.EchoRequest.page": + if x.Page == nil { + x.Page = new(v1beta11.PageRequest) + } + return protoreflect.ValueOfMessage(x.Page.ProtoReflect()) + case "testpb.EchoRequest.bools": + if x.Bools == nil { + x.Bools = []bool{} + } + value := &_EchoRequest_21_list{list: &x.Bools} + return protoreflect.ValueOfList(value) + case "testpb.EchoRequest.uints": + if x.Uints == nil { + x.Uints = []uint32{} + } + value := &_EchoRequest_22_list{list: &x.Uints} + return protoreflect.ValueOfList(value) + case "testpb.EchoRequest.strings": + if x.Strings == nil { + x.Strings = []string{} + } + value := &_EchoRequest_23_list{list: &x.Strings} + return protoreflect.ValueOfList(value) + case "testpb.EchoRequest.enums": + if x.Enums == nil { + x.Enums = []Enum{} + } + value := &_EchoRequest_24_list{list: &x.Enums} + return protoreflect.ValueOfList(value) + case "testpb.EchoRequest.durations": + if x.Durations == nil { + x.Durations = []*durationpb.Duration{} + } + value := &_EchoRequest_25_list{list: &x.Durations} + return protoreflect.ValueOfList(value) + case "testpb.EchoRequest.some_messages": + if x.SomeMessages == nil { + x.SomeMessages = []*AMessage{} + } + value := &_EchoRequest_26_list{list: &x.SomeMessages} + return protoreflect.ValueOfList(value) + case "testpb.EchoRequest.positional3_varargs": + if x.Positional3Varargs == nil { + x.Positional3Varargs = []*v1beta1.Coin{} + } + value := &_EchoRequest_29_list{list: &x.Positional3Varargs} + return protoreflect.ValueOfList(value) + case "testpb.EchoRequest.map_string_string": + if x.MapStringString == nil { + x.MapStringString = make(map[string]string) + } + value := &_EchoRequest_33_map{m: &x.MapStringString} + return protoreflect.ValueOfMap(value) + case "testpb.EchoRequest.map_string_uint32": + if x.MapStringUint32 == nil { + x.MapStringUint32 = make(map[string]uint32) + } + value := &_EchoRequest_34_map{m: &x.MapStringUint32} + return protoreflect.ValueOfMap(value) + case "testpb.EchoRequest.map_string_coin": + if x.MapStringCoin == nil { + x.MapStringCoin = make(map[string]*v1beta1.Coin) + } + value := &_EchoRequest_35_map{m: &x.MapStringCoin} + return protoreflect.ValueOfMap(value) + case "testpb.EchoRequest.coins": + if x.Coins == nil { + x.Coins = []*v1beta1.Coin{} + } + value := &_EchoRequest_38_list{list: &x.Coins} + return protoreflect.ValueOfList(value) + case "testpb.EchoRequest.u32": + panic(fmt.Errorf("field u32 of message testpb.EchoRequest is not mutable")) + case "testpb.EchoRequest.u64": + panic(fmt.Errorf("field u64 of message testpb.EchoRequest is not mutable")) + case "testpb.EchoRequest.str": + panic(fmt.Errorf("field str of message testpb.EchoRequest is not mutable")) + case "testpb.EchoRequest.bz": + panic(fmt.Errorf("field bz of message testpb.EchoRequest is not mutable")) + case "testpb.EchoRequest.i32": + panic(fmt.Errorf("field i32 of message testpb.EchoRequest is not mutable")) + case "testpb.EchoRequest.i64": + panic(fmt.Errorf("field i64 of message testpb.EchoRequest is not mutable")) + case "testpb.EchoRequest.a_bool": + panic(fmt.Errorf("field a_bool of message testpb.EchoRequest is not mutable")) + case "testpb.EchoRequest.an_enum": + panic(fmt.Errorf("field an_enum of message testpb.EchoRequest is not mutable")) + case "testpb.EchoRequest.an_address": + panic(fmt.Errorf("field an_address of message testpb.EchoRequest is not mutable")) + case "testpb.EchoRequest.positional1": + panic(fmt.Errorf("field positional1 of message testpb.EchoRequest is not mutable")) + case "testpb.EchoRequest.positional2": + panic(fmt.Errorf("field positional2 of message testpb.EchoRequest is not mutable")) + case "testpb.EchoRequest.deprecated_field": + panic(fmt.Errorf("field deprecated_field of message testpb.EchoRequest is not mutable")) + case "testpb.EchoRequest.shorthand_deprecated_field": + panic(fmt.Errorf("field shorthand_deprecated_field of message testpb.EchoRequest is not mutable")) + case "testpb.EchoRequest.hidden_bool": + panic(fmt.Errorf("field hidden_bool of message testpb.EchoRequest is not mutable")) + case "testpb.EchoRequest.a_validator_address": + panic(fmt.Errorf("field a_validator_address of message testpb.EchoRequest is not mutable")) + case "testpb.EchoRequest.a_consensus_address": + panic(fmt.Errorf("field a_consensus_address of message testpb.EchoRequest is not mutable")) + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.EchoRequest")) + } + panic(fmt.Errorf("message testpb.EchoRequest does not contain field %s", fd.FullName())) + } +} + +// NewField returns a new value that is assignable to the field +// for the given descriptor. For scalars, this returns the default value. +// For lists, maps, and messages, this returns a new, empty, mutable value. +func (x *fastReflection_EchoRequest) NewField(fd protoreflect.FieldDescriptor) protoreflect.Value { + switch fd.FullName() { + case "testpb.EchoRequest.u32": + return protoreflect.ValueOfUint32(uint32(0)) + case "testpb.EchoRequest.u64": + return protoreflect.ValueOfUint64(uint64(0)) + case "testpb.EchoRequest.str": + return protoreflect.ValueOfString("") + case "testpb.EchoRequest.bz": + return protoreflect.ValueOfBytes(nil) + case "testpb.EchoRequest.timestamp": + m := new(timestamppb.Timestamp) + return protoreflect.ValueOfMessage(m.ProtoReflect()) + case "testpb.EchoRequest.duration": + m := new(durationpb.Duration) + return protoreflect.ValueOfMessage(m.ProtoReflect()) + case "testpb.EchoRequest.i32": + return protoreflect.ValueOfInt32(int32(0)) + case "testpb.EchoRequest.i64": + return protoreflect.ValueOfInt64(int64(0)) + case "testpb.EchoRequest.a_bool": + return protoreflect.ValueOfBool(false) + case "testpb.EchoRequest.an_enum": + return protoreflect.ValueOfEnum(0) + case "testpb.EchoRequest.a_message": + m := new(AMessage) + return protoreflect.ValueOfMessage(m.ProtoReflect()) + case "testpb.EchoRequest.a_coin": + m := new(v1beta1.Coin) + return protoreflect.ValueOfMessage(m.ProtoReflect()) + case "testpb.EchoRequest.an_address": + return protoreflect.ValueOfString("") + case "testpb.EchoRequest.page": + m := new(v1beta11.PageRequest) + return protoreflect.ValueOfMessage(m.ProtoReflect()) + case "testpb.EchoRequest.bools": + list := []bool{} + return protoreflect.ValueOfList(&_EchoRequest_21_list{list: &list}) + case "testpb.EchoRequest.uints": + list := []uint32{} + return protoreflect.ValueOfList(&_EchoRequest_22_list{list: &list}) + case "testpb.EchoRequest.strings": + list := []string{} + return protoreflect.ValueOfList(&_EchoRequest_23_list{list: &list}) + case "testpb.EchoRequest.enums": + list := []Enum{} + return protoreflect.ValueOfList(&_EchoRequest_24_list{list: &list}) + case "testpb.EchoRequest.durations": + list := []*durationpb.Duration{} + return protoreflect.ValueOfList(&_EchoRequest_25_list{list: &list}) + case "testpb.EchoRequest.some_messages": + list := []*AMessage{} + return protoreflect.ValueOfList(&_EchoRequest_26_list{list: &list}) + case "testpb.EchoRequest.positional1": + return protoreflect.ValueOfInt32(int32(0)) + case "testpb.EchoRequest.positional2": + return protoreflect.ValueOfString("") + case "testpb.EchoRequest.positional3_varargs": + list := []*v1beta1.Coin{} + return protoreflect.ValueOfList(&_EchoRequest_29_list{list: &list}) + case "testpb.EchoRequest.deprecated_field": + return protoreflect.ValueOfString("") + case "testpb.EchoRequest.shorthand_deprecated_field": + return protoreflect.ValueOfString("") + case "testpb.EchoRequest.hidden_bool": + return protoreflect.ValueOfBool(false) + case "testpb.EchoRequest.map_string_string": + m := make(map[string]string) + return protoreflect.ValueOfMap(&_EchoRequest_33_map{m: &m}) + case "testpb.EchoRequest.map_string_uint32": + m := make(map[string]uint32) + return protoreflect.ValueOfMap(&_EchoRequest_34_map{m: &m}) + case "testpb.EchoRequest.map_string_coin": + m := make(map[string]*v1beta1.Coin) + return protoreflect.ValueOfMap(&_EchoRequest_35_map{m: &m}) + case "testpb.EchoRequest.a_validator_address": + return protoreflect.ValueOfString("") + case "testpb.EchoRequest.a_consensus_address": + return protoreflect.ValueOfString("") + case "testpb.EchoRequest.coins": + list := []*v1beta1.Coin{} + return protoreflect.ValueOfList(&_EchoRequest_38_list{list: &list}) + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.EchoRequest")) + } + panic(fmt.Errorf("message testpb.EchoRequest does not contain field %s", fd.FullName())) + } +} + +// WhichOneof reports which field within the oneof is populated, +// returning nil if none are populated. +// It panics if the oneof descriptor does not belong to this message. +func (x *fastReflection_EchoRequest) WhichOneof(d protoreflect.OneofDescriptor) protoreflect.FieldDescriptor { + switch d.FullName() { + default: + panic(fmt.Errorf("%s is not a oneof field in testpb.EchoRequest", d.FullName())) + } + panic("unreachable") +} + +// GetUnknown retrieves the entire list of unknown fields. +// The caller may only mutate the contents of the RawFields +// if the mutated bytes are stored back into the message with SetUnknown. +func (x *fastReflection_EchoRequest) GetUnknown() protoreflect.RawFields { + return x.unknownFields +} + +// SetUnknown stores an entire list of unknown fields. +// The raw fields must be syntactically valid according to the wire format. +// An implementation may panic if this is not the case. +// Once stored, the caller must not mutate the content of the RawFields. +// An empty RawFields may be passed to clear the fields. +// +// SetUnknown is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_EchoRequest) SetUnknown(fields protoreflect.RawFields) { + x.unknownFields = fields +} + +// IsValid reports whether the message is valid. +// +// An invalid message is an empty, read-only value. +// +// An invalid message often corresponds to a nil pointer of the concrete +// message type, but the details are implementation dependent. +// Validity is not part of the protobuf data model, and may not +// be preserved in marshaling or other operations. +func (x *fastReflection_EchoRequest) IsValid() bool { + return x != nil +} + +// ProtoMethods returns optional fastReflectionFeature-path implementations of various operations. +// This method may return nil. +// +// The returned methods type is identical to +// "google.golang.org/protobuf/runtime/protoiface".Methods. +// Consult the protoiface package documentation for details. +func (x *fastReflection_EchoRequest) ProtoMethods() *protoiface.Methods { + size := func(input protoiface.SizeInput) protoiface.SizeOutput { + x := input.Message.Interface().(*EchoRequest) + if x == nil { + return protoiface.SizeOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Size: 0, + } + } + options := runtime.SizeInputToOptions(input) + _ = options + var n int + var l int + _ = l + if x.U32 != 0 { + n += 1 + runtime.Sov(uint64(x.U32)) + } + if x.U64 != 0 { + n += 1 + runtime.Sov(uint64(x.U64)) + } + l = len(x.Str) + if l > 0 { + n += 1 + l + runtime.Sov(uint64(l)) + } + l = len(x.Bz) + if l > 0 { + n += 1 + l + runtime.Sov(uint64(l)) + } + if x.Timestamp != nil { + l = options.Size(x.Timestamp) + n += 1 + l + runtime.Sov(uint64(l)) + } + if x.Duration != nil { + l = options.Size(x.Duration) + n += 1 + l + runtime.Sov(uint64(l)) + } + if x.I32 != 0 { + n += 1 + runtime.Sov(uint64(x.I32)) + } + if x.I64 != 0 { + n += 1 + runtime.Sov(uint64(x.I64)) + } + if x.ABool { + n += 2 + } + if x.AnEnum != 0 { + n += 2 + runtime.Sov(uint64(x.AnEnum)) + } + if x.AMessage != nil { + l = options.Size(x.AMessage) + n += 2 + l + runtime.Sov(uint64(l)) + } + if x.ACoin != nil { + l = options.Size(x.ACoin) + n += 2 + l + runtime.Sov(uint64(l)) + } + l = len(x.AnAddress) + if l > 0 { + n += 2 + l + runtime.Sov(uint64(l)) + } + if x.Page != nil { + l = options.Size(x.Page) + n += 2 + l + runtime.Sov(uint64(l)) + } + if len(x.Bools) > 0 { + n += 2 + runtime.Sov(uint64(len(x.Bools))) + len(x.Bools)*1 + } + if len(x.Uints) > 0 { + l = 0 + for _, e := range x.Uints { + l += runtime.Sov(uint64(e)) + } + n += 2 + runtime.Sov(uint64(l)) + l + } + if len(x.Strings) > 0 { + for _, s := range x.Strings { + l = len(s) + n += 2 + l + runtime.Sov(uint64(l)) + } + } + if len(x.Enums) > 0 { + l = 0 + for _, e := range x.Enums { + l += runtime.Sov(uint64(e)) + } + n += 2 + runtime.Sov(uint64(l)) + l + } + if len(x.Durations) > 0 { + for _, e := range x.Durations { + l = options.Size(e) + n += 2 + l + runtime.Sov(uint64(l)) + } + } + if len(x.SomeMessages) > 0 { + for _, e := range x.SomeMessages { + l = options.Size(e) + n += 2 + l + runtime.Sov(uint64(l)) + } + } + if x.Positional1 != 0 { + n += 2 + runtime.Sov(uint64(x.Positional1)) + } + l = len(x.Positional2) + if l > 0 { + n += 2 + l + runtime.Sov(uint64(l)) + } + if len(x.Positional3Varargs) > 0 { + for _, e := range x.Positional3Varargs { + l = options.Size(e) + n += 2 + l + runtime.Sov(uint64(l)) + } + } + l = len(x.DeprecatedField) + if l > 0 { + n += 2 + l + runtime.Sov(uint64(l)) + } + l = len(x.ShorthandDeprecatedField) + if l > 0 { + n += 2 + l + runtime.Sov(uint64(l)) + } + if x.HiddenBool { + n += 3 + } + if len(x.MapStringString) > 0 { + SiZeMaP := func(k string, v string) { + mapEntrySize := 1 + len(k) + runtime.Sov(uint64(len(k))) + 1 + len(v) + runtime.Sov(uint64(len(v))) + n += mapEntrySize + 2 + runtime.Sov(uint64(mapEntrySize)) + } + if options.Deterministic { + sortme := make([]string, 0, len(x.MapStringString)) + for k := range x.MapStringString { + sortme = append(sortme, k) + } + sort.Strings(sortme) + for _, k := range sortme { + v := x.MapStringString[k] + SiZeMaP(k, v) + } + } else { + for k, v := range x.MapStringString { + SiZeMaP(k, v) + } + } + } + if len(x.MapStringUint32) > 0 { + SiZeMaP := func(k string, v uint32) { + mapEntrySize := 1 + len(k) + runtime.Sov(uint64(len(k))) + 1 + runtime.Sov(uint64(v)) + n += mapEntrySize + 2 + runtime.Sov(uint64(mapEntrySize)) + } + if options.Deterministic { + sortme := make([]string, 0, len(x.MapStringUint32)) + for k := range x.MapStringUint32 { + sortme = append(sortme, k) + } + sort.Strings(sortme) + for _, k := range sortme { + v := x.MapStringUint32[k] + SiZeMaP(k, v) + } + } else { + for k, v := range x.MapStringUint32 { + SiZeMaP(k, v) + } + } + } + if len(x.MapStringCoin) > 0 { + SiZeMaP := func(k string, v *v1beta1.Coin) { + l := 0 + if v != nil { + l = options.Size(v) + } + l += 1 + runtime.Sov(uint64(l)) + mapEntrySize := 1 + len(k) + runtime.Sov(uint64(len(k))) + l + n += mapEntrySize + 2 + runtime.Sov(uint64(mapEntrySize)) + } + if options.Deterministic { + sortme := make([]string, 0, len(x.MapStringCoin)) + for k := range x.MapStringCoin { + sortme = append(sortme, k) + } + sort.Strings(sortme) + for _, k := range sortme { + v := x.MapStringCoin[k] + SiZeMaP(k, v) + } + } else { + for k, v := range x.MapStringCoin { + SiZeMaP(k, v) + } + } + } + l = len(x.AValidatorAddress) + if l > 0 { + n += 2 + l + runtime.Sov(uint64(l)) + } + l = len(x.AConsensusAddress) + if l > 0 { + n += 2 + l + runtime.Sov(uint64(l)) + } + if len(x.Coins) > 0 { + for _, e := range x.Coins { + l = options.Size(e) + n += 2 + l + runtime.Sov(uint64(l)) + } + } + if x.unknownFields != nil { + n += len(x.unknownFields) + } + return protoiface.SizeOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Size: n, + } + } + + marshal := func(input protoiface.MarshalInput) (protoiface.MarshalOutput, error) { + x := input.Message.Interface().(*EchoRequest) + if x == nil { + return protoiface.MarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Buf: input.Buf, + }, nil + } + options := runtime.MarshalInputToOptions(input) + _ = options + size := options.Size(x) + dAtA := make([]byte, size) + i := len(dAtA) + _ = i + var l int + _ = l + if x.unknownFields != nil { + i -= len(x.unknownFields) + copy(dAtA[i:], x.unknownFields) + } + if len(x.Coins) > 0 { + for iNdEx := len(x.Coins) - 1; iNdEx >= 0; iNdEx-- { + encoded, err := options.Marshal(x.Coins[iNdEx]) + if err != nil { + return protoiface.MarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Buf: input.Buf, + }, err + } + i -= len(encoded) + copy(dAtA[i:], encoded) + i = runtime.EncodeVarint(dAtA, i, uint64(len(encoded))) + i-- + dAtA[i] = 0x2 + i-- + dAtA[i] = 0xb2 + } + } + if len(x.AConsensusAddress) > 0 { + i -= len(x.AConsensusAddress) + copy(dAtA[i:], x.AConsensusAddress) + i = runtime.EncodeVarint(dAtA, i, uint64(len(x.AConsensusAddress))) + i-- + dAtA[i] = 0x2 + i-- + dAtA[i] = 0xaa + } + if len(x.AValidatorAddress) > 0 { + i -= len(x.AValidatorAddress) + copy(dAtA[i:], x.AValidatorAddress) + i = runtime.EncodeVarint(dAtA, i, uint64(len(x.AValidatorAddress))) + i-- + dAtA[i] = 0x2 + i-- + dAtA[i] = 0xa2 + } + if len(x.MapStringCoin) > 0 { + MaRsHaLmAp := func(k string, v *v1beta1.Coin) (protoiface.MarshalOutput, error) { + baseI := i + encoded, err := options.Marshal(v) + if err != nil { + return protoiface.MarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Buf: input.Buf, + }, err + } + i -= len(encoded) + copy(dAtA[i:], encoded) + i = runtime.EncodeVarint(dAtA, i, uint64(len(encoded))) + i-- + dAtA[i] = 0x12 + i -= len(k) + copy(dAtA[i:], k) + i = runtime.EncodeVarint(dAtA, i, uint64(len(k))) + i-- + dAtA[i] = 0xa + i = runtime.EncodeVarint(dAtA, i, uint64(baseI-i)) + i-- + dAtA[i] = 0x2 + i-- + dAtA[i] = 0x9a + return protoiface.MarshalOutput{}, nil + } + if options.Deterministic { + keysForMapStringCoin := make([]string, 0, len(x.MapStringCoin)) + for k := range x.MapStringCoin { + keysForMapStringCoin = append(keysForMapStringCoin, string(k)) + } + sort.Slice(keysForMapStringCoin, func(i, j int) bool { + return keysForMapStringCoin[i] < keysForMapStringCoin[j] + }) + for iNdEx := len(keysForMapStringCoin) - 1; iNdEx >= 0; iNdEx-- { + v := x.MapStringCoin[string(keysForMapStringCoin[iNdEx])] + out, err := MaRsHaLmAp(keysForMapStringCoin[iNdEx], v) + if err != nil { + return out, err + } + } + } else { + for k := range x.MapStringCoin { + v := x.MapStringCoin[k] + out, err := MaRsHaLmAp(k, v) + if err != nil { + return out, err + } + } + } + } + if len(x.MapStringUint32) > 0 { + MaRsHaLmAp := func(k string, v uint32) (protoiface.MarshalOutput, error) { + baseI := i + i = runtime.EncodeVarint(dAtA, i, uint64(v)) + i-- + dAtA[i] = 0x10 + i -= len(k) + copy(dAtA[i:], k) + i = runtime.EncodeVarint(dAtA, i, uint64(len(k))) + i-- + dAtA[i] = 0xa + i = runtime.EncodeVarint(dAtA, i, uint64(baseI-i)) + i-- + dAtA[i] = 0x2 + i-- + dAtA[i] = 0x92 + return protoiface.MarshalOutput{}, nil + } + if options.Deterministic { + keysForMapStringUint32 := make([]string, 0, len(x.MapStringUint32)) + for k := range x.MapStringUint32 { + keysForMapStringUint32 = append(keysForMapStringUint32, string(k)) + } + sort.Slice(keysForMapStringUint32, func(i, j int) bool { + return keysForMapStringUint32[i] < keysForMapStringUint32[j] + }) + for iNdEx := len(keysForMapStringUint32) - 1; iNdEx >= 0; iNdEx-- { + v := x.MapStringUint32[string(keysForMapStringUint32[iNdEx])] + out, err := MaRsHaLmAp(keysForMapStringUint32[iNdEx], v) + if err != nil { + return out, err + } + } + } else { + for k := range x.MapStringUint32 { + v := x.MapStringUint32[k] + out, err := MaRsHaLmAp(k, v) + if err != nil { + return out, err + } + } + } + } + if len(x.MapStringString) > 0 { + MaRsHaLmAp := func(k string, v string) (protoiface.MarshalOutput, error) { + baseI := i + i -= len(v) + copy(dAtA[i:], v) + i = runtime.EncodeVarint(dAtA, i, uint64(len(v))) + i-- + dAtA[i] = 0x12 + i -= len(k) + copy(dAtA[i:], k) + i = runtime.EncodeVarint(dAtA, i, uint64(len(k))) + i-- + dAtA[i] = 0xa + i = runtime.EncodeVarint(dAtA, i, uint64(baseI-i)) + i-- + dAtA[i] = 0x2 + i-- + dAtA[i] = 0x8a + return protoiface.MarshalOutput{}, nil + } + if options.Deterministic { + keysForMapStringString := make([]string, 0, len(x.MapStringString)) + for k := range x.MapStringString { + keysForMapStringString = append(keysForMapStringString, string(k)) + } + sort.Slice(keysForMapStringString, func(i, j int) bool { + return keysForMapStringString[i] < keysForMapStringString[j] + }) + for iNdEx := len(keysForMapStringString) - 1; iNdEx >= 0; iNdEx-- { + v := x.MapStringString[string(keysForMapStringString[iNdEx])] + out, err := MaRsHaLmAp(keysForMapStringString[iNdEx], v) + if err != nil { + return out, err + } + } + } else { + for k := range x.MapStringString { + v := x.MapStringString[k] + out, err := MaRsHaLmAp(k, v) + if err != nil { + return out, err + } + } + } + } + if x.HiddenBool { + i-- + if x.HiddenBool { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x2 + i-- + dAtA[i] = 0x80 + } + if len(x.ShorthandDeprecatedField) > 0 { + i -= len(x.ShorthandDeprecatedField) + copy(dAtA[i:], x.ShorthandDeprecatedField) + i = runtime.EncodeVarint(dAtA, i, uint64(len(x.ShorthandDeprecatedField))) + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0xfa + } + if len(x.DeprecatedField) > 0 { + i -= len(x.DeprecatedField) + copy(dAtA[i:], x.DeprecatedField) + i = runtime.EncodeVarint(dAtA, i, uint64(len(x.DeprecatedField))) + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0xf2 + } + if len(x.Positional3Varargs) > 0 { + for iNdEx := len(x.Positional3Varargs) - 1; iNdEx >= 0; iNdEx-- { + encoded, err := options.Marshal(x.Positional3Varargs[iNdEx]) + if err != nil { + return protoiface.MarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Buf: input.Buf, + }, err + } + i -= len(encoded) + copy(dAtA[i:], encoded) + i = runtime.EncodeVarint(dAtA, i, uint64(len(encoded))) + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0xea + } + } + if len(x.Positional2) > 0 { + i -= len(x.Positional2) + copy(dAtA[i:], x.Positional2) + i = runtime.EncodeVarint(dAtA, i, uint64(len(x.Positional2))) + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0xe2 + } + if x.Positional1 != 0 { + i = runtime.EncodeVarint(dAtA, i, uint64(x.Positional1)) + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0xd8 + } + if len(x.SomeMessages) > 0 { + for iNdEx := len(x.SomeMessages) - 1; iNdEx >= 0; iNdEx-- { + encoded, err := options.Marshal(x.SomeMessages[iNdEx]) + if err != nil { + return protoiface.MarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Buf: input.Buf, + }, err + } + i -= len(encoded) + copy(dAtA[i:], encoded) + i = runtime.EncodeVarint(dAtA, i, uint64(len(encoded))) + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0xd2 + } + } + if len(x.Durations) > 0 { + for iNdEx := len(x.Durations) - 1; iNdEx >= 0; iNdEx-- { + encoded, err := options.Marshal(x.Durations[iNdEx]) + if err != nil { + return protoiface.MarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Buf: input.Buf, + }, err + } + i -= len(encoded) + copy(dAtA[i:], encoded) + i = runtime.EncodeVarint(dAtA, i, uint64(len(encoded))) + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0xca + } + } + if len(x.Enums) > 0 { + var pksize2 int + for _, num := range x.Enums { + pksize2 += runtime.Sov(uint64(num)) + } + i -= pksize2 + j1 := i + for _, num1 := range x.Enums { + num := uint64(num1) + for num >= 1<<7 { + dAtA[j1] = uint8(uint64(num)&0x7f | 0x80) + num >>= 7 + j1++ + } + dAtA[j1] = uint8(num) + j1++ + } + i = runtime.EncodeVarint(dAtA, i, uint64(pksize2)) + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0xc2 + } + if len(x.Strings) > 0 { + for iNdEx := len(x.Strings) - 1; iNdEx >= 0; iNdEx-- { + i -= len(x.Strings[iNdEx]) + copy(dAtA[i:], x.Strings[iNdEx]) + i = runtime.EncodeVarint(dAtA, i, uint64(len(x.Strings[iNdEx]))) + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0xba + } + } + if len(x.Uints) > 0 { + var pksize4 int + for _, num := range x.Uints { + pksize4 += runtime.Sov(uint64(num)) + } + i -= pksize4 + j3 := i + for _, num := range x.Uints { + for num >= 1<<7 { + dAtA[j3] = uint8(uint64(num)&0x7f | 0x80) + num >>= 7 + j3++ + } + dAtA[j3] = uint8(num) + j3++ + } + i = runtime.EncodeVarint(dAtA, i, uint64(pksize4)) + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0xb2 + } + if len(x.Bools) > 0 { + for iNdEx := len(x.Bools) - 1; iNdEx >= 0; iNdEx-- { + i-- + if x.Bools[iNdEx] { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + } + i = runtime.EncodeVarint(dAtA, i, uint64(len(x.Bools))) + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0xaa + } + if x.Page != nil { + encoded, err := options.Marshal(x.Page) + if err != nil { + return protoiface.MarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Buf: input.Buf, + }, err + } + i -= len(encoded) + copy(dAtA[i:], encoded) + i = runtime.EncodeVarint(dAtA, i, uint64(len(encoded))) + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0xa2 + } + if len(x.AnAddress) > 0 { + i -= len(x.AnAddress) + copy(dAtA[i:], x.AnAddress) + i = runtime.EncodeVarint(dAtA, i, uint64(len(x.AnAddress))) + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0x9a + } + if x.ACoin != nil { + encoded, err := options.Marshal(x.ACoin) + if err != nil { + return protoiface.MarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Buf: input.Buf, + }, err + } + i -= len(encoded) + copy(dAtA[i:], encoded) + i = runtime.EncodeVarint(dAtA, i, uint64(len(encoded))) + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0x92 + } + if x.AMessage != nil { + encoded, err := options.Marshal(x.AMessage) + if err != nil { + return protoiface.MarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Buf: input.Buf, + }, err + } + i -= len(encoded) + copy(dAtA[i:], encoded) + i = runtime.EncodeVarint(dAtA, i, uint64(len(encoded))) + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0x8a + } + if x.AnEnum != 0 { + i = runtime.EncodeVarint(dAtA, i, uint64(x.AnEnum)) + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0x80 + } + if x.ABool { + i-- + if x.ABool { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x78 + } + if x.I64 != 0 { + i = runtime.EncodeVarint(dAtA, i, uint64(x.I64)) + i-- + dAtA[i] = 0x50 + } + if x.I32 != 0 { + i = runtime.EncodeVarint(dAtA, i, uint64(x.I32)) + i-- + dAtA[i] = 0x38 + } + if x.Duration != nil { + encoded, err := options.Marshal(x.Duration) + if err != nil { + return protoiface.MarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Buf: input.Buf, + }, err + } + i -= len(encoded) + copy(dAtA[i:], encoded) + i = runtime.EncodeVarint(dAtA, i, uint64(len(encoded))) + i-- + dAtA[i] = 0x32 + } + if x.Timestamp != nil { + encoded, err := options.Marshal(x.Timestamp) + if err != nil { + return protoiface.MarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Buf: input.Buf, + }, err + } + i -= len(encoded) + copy(dAtA[i:], encoded) + i = runtime.EncodeVarint(dAtA, i, uint64(len(encoded))) + i-- + dAtA[i] = 0x2a + } + if len(x.Bz) > 0 { + i -= len(x.Bz) + copy(dAtA[i:], x.Bz) + i = runtime.EncodeVarint(dAtA, i, uint64(len(x.Bz))) + i-- + dAtA[i] = 0x22 + } + if len(x.Str) > 0 { + i -= len(x.Str) + copy(dAtA[i:], x.Str) + i = runtime.EncodeVarint(dAtA, i, uint64(len(x.Str))) + i-- + dAtA[i] = 0x1a + } + if x.U64 != 0 { + i = runtime.EncodeVarint(dAtA, i, uint64(x.U64)) + i-- + dAtA[i] = 0x10 + } + if x.U32 != 0 { + i = runtime.EncodeVarint(dAtA, i, uint64(x.U32)) + i-- + dAtA[i] = 0x8 + } + if input.Buf != nil { + input.Buf = append(input.Buf, dAtA...) + } else { + input.Buf = dAtA + } + return protoiface.MarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Buf: input.Buf, + }, nil + } + unmarshal := func(input protoiface.UnmarshalInput) (protoiface.UnmarshalOutput, error) { + x := input.Message.Interface().(*EchoRequest) + if x == nil { + return protoiface.UnmarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Flags: input.Flags, + }, nil + } + options := runtime.UnmarshalInputToOptions(input) + _ = options + dAtA := input.Buf + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: EchoRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: EchoRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field U32", wireType) + } + x.U32 = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + x.U32 |= uint32(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field U64", wireType) + } + x.U64 = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + x.U64 |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Str", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if postIndex > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + x.Str = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 4: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Bz", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if postIndex > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + x.Bz = append(x.Bz[:0], dAtA[iNdEx:postIndex]...) + if x.Bz == nil { + x.Bz = []byte{} + } + iNdEx = postIndex + case 5: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Timestamp", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if postIndex > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + if x.Timestamp == nil { + x.Timestamp = ×tamppb.Timestamp{} + } + if err := options.Unmarshal(dAtA[iNdEx:postIndex], x.Timestamp); err != nil { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err + } + iNdEx = postIndex + case 6: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Duration", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if postIndex > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + if x.Duration == nil { + x.Duration = &durationpb.Duration{} + } + if err := options.Unmarshal(dAtA[iNdEx:postIndex], x.Duration); err != nil { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err + } + iNdEx = postIndex + case 7: + if wireType != 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field I32", wireType) + } + x.I32 = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + x.I32 |= int32(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 10: + if wireType != 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field I64", wireType) + } + x.I64 = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + x.I64 |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 15: + if wireType != 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field ABool", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + x.ABool = bool(v != 0) + case 16: + if wireType != 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field AnEnum", wireType) + } + x.AnEnum = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + x.AnEnum |= Enum(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 17: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field AMessage", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if postIndex > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + if x.AMessage == nil { + x.AMessage = &AMessage{} + } + if err := options.Unmarshal(dAtA[iNdEx:postIndex], x.AMessage); err != nil { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err + } + iNdEx = postIndex + case 18: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field ACoin", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if postIndex > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + if x.ACoin == nil { + x.ACoin = &v1beta1.Coin{} + } + if err := options.Unmarshal(dAtA[iNdEx:postIndex], x.ACoin); err != nil { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err + } + iNdEx = postIndex + case 19: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field AnAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if postIndex > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + x.AnAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 20: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Page", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if postIndex > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + if x.Page == nil { + x.Page = &v1beta11.PageRequest{} + } + if err := options.Unmarshal(dAtA[iNdEx:postIndex], x.Page); err != nil { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err + } + iNdEx = postIndex + case 21: + if wireType == 0 { + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + x.Bools = append(x.Bools, bool(v != 0)) + } else if wireType == 2 { + var packedLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + packedLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if packedLen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postIndex := iNdEx + packedLen + if postIndex < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if postIndex > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + var elementCount int + elementCount = packedLen + if elementCount != 0 && len(x.Bools) == 0 { + x.Bools = make([]bool, 0, elementCount) + } + for iNdEx < postIndex { + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + x.Bools = append(x.Bools, bool(v != 0)) + } + } else { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Bools", wireType) + } + case 22: + if wireType == 0 { + var v uint32 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= uint32(b&0x7F) << shift + if b < 0x80 { + break + } + } + x.Uints = append(x.Uints, v) + } else if wireType == 2 { + var packedLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + packedLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if packedLen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postIndex := iNdEx + packedLen + if postIndex < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if postIndex > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + var elementCount int + var count int + for _, integer := range dAtA[iNdEx:postIndex] { + if integer < 128 { + count++ + } + } + elementCount = count + if elementCount != 0 && len(x.Uints) == 0 { + x.Uints = make([]uint32, 0, elementCount) + } + for iNdEx < postIndex { + var v uint32 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= uint32(b&0x7F) << shift + if b < 0x80 { + break + } + } + x.Uints = append(x.Uints, v) + } + } else { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Uints", wireType) + } + case 23: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Strings", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if postIndex > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + x.Strings = append(x.Strings, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex + case 24: + if wireType == 0 { + var v Enum + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= Enum(b&0x7F) << shift + if b < 0x80 { + break + } + } + x.Enums = append(x.Enums, v) + } else if wireType == 2 { + var packedLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + packedLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if packedLen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postIndex := iNdEx + packedLen + if postIndex < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if postIndex > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + var elementCount int + if elementCount != 0 && len(x.Enums) == 0 { + x.Enums = make([]Enum, 0, elementCount) + } + for iNdEx < postIndex { + var v Enum + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= Enum(b&0x7F) << shift + if b < 0x80 { + break + } + } + x.Enums = append(x.Enums, v) + } + } else { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Enums", wireType) + } + case 25: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Durations", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if postIndex > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + x.Durations = append(x.Durations, &durationpb.Duration{}) + if err := options.Unmarshal(dAtA[iNdEx:postIndex], x.Durations[len(x.Durations)-1]); err != nil { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err + } + iNdEx = postIndex + case 26: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field SomeMessages", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if postIndex > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + x.SomeMessages = append(x.SomeMessages, &AMessage{}) + if err := options.Unmarshal(dAtA[iNdEx:postIndex], x.SomeMessages[len(x.SomeMessages)-1]); err != nil { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err + } + iNdEx = postIndex + case 27: + if wireType != 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Positional1", wireType) + } + x.Positional1 = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + x.Positional1 |= int32(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 28: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Positional2", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if postIndex > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + x.Positional2 = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 29: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Positional3Varargs", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if postIndex > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + x.Positional3Varargs = append(x.Positional3Varargs, &v1beta1.Coin{}) + if err := options.Unmarshal(dAtA[iNdEx:postIndex], x.Positional3Varargs[len(x.Positional3Varargs)-1]); err != nil { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err + } + iNdEx = postIndex + case 30: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field DeprecatedField", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if postIndex > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + x.DeprecatedField = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 31: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field ShorthandDeprecatedField", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if postIndex > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + x.ShorthandDeprecatedField = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 32: + if wireType != 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field HiddenBool", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + x.HiddenBool = bool(v != 0) + case 33: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field MapStringString", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if postIndex > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + if x.MapStringString == nil { + x.MapStringString = make(map[string]string) + } + var mapkey string + var mapvalue string + for iNdEx < postIndex { + entryPreIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + if fieldNum == 1 { + var stringLenmapkey uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLenmapkey |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLenmapkey := int(stringLenmapkey) + if intStringLenmapkey < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postStringIndexmapkey := iNdEx + intStringLenmapkey + if postStringIndexmapkey < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if postStringIndexmapkey > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + mapkey = string(dAtA[iNdEx:postStringIndexmapkey]) + iNdEx = postStringIndexmapkey + } else if fieldNum == 2 { + var stringLenmapvalue uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLenmapvalue |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLenmapvalue := int(stringLenmapvalue) + if intStringLenmapvalue < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postStringIndexmapvalue := iNdEx + intStringLenmapvalue + if postStringIndexmapvalue < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if postStringIndexmapvalue > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + mapvalue = string(dAtA[iNdEx:postStringIndexmapvalue]) + iNdEx = postStringIndexmapvalue + } else { + iNdEx = entryPreIndex + skippy, err := runtime.Skip(dAtA[iNdEx:]) + if err != nil { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if (iNdEx + skippy) > postIndex { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + x.MapStringString[mapkey] = mapvalue + iNdEx = postIndex + case 34: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field MapStringUint32", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if postIndex > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + if x.MapStringUint32 == nil { + x.MapStringUint32 = make(map[string]uint32) + } + var mapkey string + var mapvalue uint32 + for iNdEx < postIndex { + entryPreIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + if fieldNum == 1 { + var stringLenmapkey uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLenmapkey |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLenmapkey := int(stringLenmapkey) + if intStringLenmapkey < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postStringIndexmapkey := iNdEx + intStringLenmapkey + if postStringIndexmapkey < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if postStringIndexmapkey > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + mapkey = string(dAtA[iNdEx:postStringIndexmapkey]) + iNdEx = postStringIndexmapkey + } else if fieldNum == 2 { + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + mapvalue |= uint32(b&0x7F) << shift + if b < 0x80 { + break + } + } + } else { + iNdEx = entryPreIndex + skippy, err := runtime.Skip(dAtA[iNdEx:]) + if err != nil { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if (iNdEx + skippy) > postIndex { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + x.MapStringUint32[mapkey] = mapvalue + iNdEx = postIndex + case 35: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field MapStringCoin", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if postIndex > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + if x.MapStringCoin == nil { + x.MapStringCoin = make(map[string]*v1beta1.Coin) + } + var mapkey string + var mapvalue *v1beta1.Coin + for iNdEx < postIndex { + entryPreIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + if fieldNum == 1 { + var stringLenmapkey uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLenmapkey |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLenmapkey := int(stringLenmapkey) + if intStringLenmapkey < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postStringIndexmapkey := iNdEx + intStringLenmapkey + if postStringIndexmapkey < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if postStringIndexmapkey > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + mapkey = string(dAtA[iNdEx:postStringIndexmapkey]) + iNdEx = postStringIndexmapkey + } else if fieldNum == 2 { + var mapmsglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + mapmsglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if mapmsglen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postmsgIndex := iNdEx + mapmsglen + if postmsgIndex < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if postmsgIndex > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + mapvalue = &v1beta1.Coin{} + if err := options.Unmarshal(dAtA[iNdEx:postmsgIndex], mapvalue); err != nil { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err + } + iNdEx = postmsgIndex + } else { + iNdEx = entryPreIndex + skippy, err := runtime.Skip(dAtA[iNdEx:]) + if err != nil { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if (iNdEx + skippy) > postIndex { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + x.MapStringCoin[mapkey] = mapvalue + iNdEx = postIndex + case 36: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field AValidatorAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if postIndex > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + x.AValidatorAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 37: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field AConsensusAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if postIndex > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + x.AConsensusAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 38: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Coins", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if postIndex > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + x.Coins = append(x.Coins, &v1beta1.Coin{}) + if err := options.Unmarshal(dAtA[iNdEx:postIndex], x.Coins[len(x.Coins)-1]); err != nil { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := runtime.Skip(dAtA[iNdEx:]) + if err != nil { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if (iNdEx + skippy) > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + if !options.DiscardUnknown { + x.unknownFields = append(x.unknownFields, dAtA[iNdEx:iNdEx+skippy]...) + } + iNdEx += skippy + } + } + + if iNdEx > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, nil + } + return &protoiface.Methods{ + NoUnkeyedLiterals: struct{}{}, + Flags: protoiface.SupportMarshalDeterministic | protoiface.SupportUnmarshalDiscardUnknown, + Size: size, + Marshal: marshal, + Unmarshal: unmarshal, + Merge: nil, + CheckInitialized: nil, + } +} + +var ( + md_EchoResponse protoreflect.MessageDescriptor + fd_EchoResponse_request protoreflect.FieldDescriptor +) + +func init() { + file_testpb_query_proto_init() + md_EchoResponse = File_testpb_query_proto.Messages().ByName("EchoResponse") + fd_EchoResponse_request = md_EchoResponse.Fields().ByName("request") +} + +var _ protoreflect.Message = (*fastReflection_EchoResponse)(nil) + +type fastReflection_EchoResponse EchoResponse + +func (x *EchoResponse) ProtoReflect() protoreflect.Message { + return (*fastReflection_EchoResponse)(x) +} + +func (x *EchoResponse) slowProtoReflect() protoreflect.Message { + mi := &file_testpb_query_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +var _fastReflection_EchoResponse_messageType fastReflection_EchoResponse_messageType +var _ protoreflect.MessageType = fastReflection_EchoResponse_messageType{} + +type fastReflection_EchoResponse_messageType struct{} + +func (x fastReflection_EchoResponse_messageType) Zero() protoreflect.Message { + return (*fastReflection_EchoResponse)(nil) +} +func (x fastReflection_EchoResponse_messageType) New() protoreflect.Message { + return new(fastReflection_EchoResponse) +} +func (x fastReflection_EchoResponse_messageType) Descriptor() protoreflect.MessageDescriptor { + return md_EchoResponse +} + +// Descriptor returns message descriptor, which contains only the protobuf +// type information for the message. +func (x *fastReflection_EchoResponse) Descriptor() protoreflect.MessageDescriptor { + return md_EchoResponse +} + +// Type returns the message type, which encapsulates both Go and protobuf +// type information. If the Go type information is not needed, +// it is recommended that the message descriptor be used instead. +func (x *fastReflection_EchoResponse) Type() protoreflect.MessageType { + return _fastReflection_EchoResponse_messageType +} + +// New returns a newly allocated and mutable empty message. +func (x *fastReflection_EchoResponse) New() protoreflect.Message { + return new(fastReflection_EchoResponse) +} + +// Interface unwraps the message reflection interface and +// returns the underlying ProtoMessage interface. +func (x *fastReflection_EchoResponse) Interface() protoreflect.ProtoMessage { + return (*EchoResponse)(x) +} + +// Range iterates over every populated field in an undefined order, +// calling f for each field descriptor and value encountered. +// Range returns immediately if f returns false. +// While iterating, mutating operations may only be performed +// on the current field descriptor. +func (x *fastReflection_EchoResponse) Range(f func(protoreflect.FieldDescriptor, protoreflect.Value) bool) { + if x.Request != nil { + value := protoreflect.ValueOfMessage(x.Request.ProtoReflect()) + if !f(fd_EchoResponse_request, value) { + return + } + } +} + +// Has reports whether a field is populated. +// +// Some fields have the property of nullability where it is possible to +// distinguish between the default value of a field and whether the field +// was explicitly populated with the default value. Singular message fields, +// member fields of a oneof, and proto2 scalar fields are nullable. Such +// fields are populated only if explicitly set. +// +// In other cases (aside from the nullable cases above), +// a proto3 scalar field is populated if it contains a non-zero value, and +// a repeated field is populated if it is non-empty. +func (x *fastReflection_EchoResponse) Has(fd protoreflect.FieldDescriptor) bool { + switch fd.FullName() { + case "testpb.EchoResponse.request": + return x.Request != nil + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.EchoResponse")) + } + panic(fmt.Errorf("message testpb.EchoResponse does not contain field %s", fd.FullName())) + } +} + +// Clear clears the field such that a subsequent Has call reports false. +// +// Clearing an extension field clears both the extension type and value +// associated with the given field number. +// +// Clear is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_EchoResponse) Clear(fd protoreflect.FieldDescriptor) { + switch fd.FullName() { + case "testpb.EchoResponse.request": + x.Request = nil + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.EchoResponse")) + } + panic(fmt.Errorf("message testpb.EchoResponse does not contain field %s", fd.FullName())) + } +} + +// Get retrieves the value for a field. +// +// For unpopulated scalars, it returns the default value, where +// the default value of a bytes scalar is guaranteed to be a copy. +// For unpopulated composite types, it returns an empty, read-only view +// of the value; to obtain a mutable reference, use Mutable. +func (x *fastReflection_EchoResponse) Get(descriptor protoreflect.FieldDescriptor) protoreflect.Value { + switch descriptor.FullName() { + case "testpb.EchoResponse.request": + value := x.Request + return protoreflect.ValueOfMessage(value.ProtoReflect()) + default: + if descriptor.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.EchoResponse")) + } + panic(fmt.Errorf("message testpb.EchoResponse does not contain field %s", descriptor.FullName())) + } +} + +// Set stores the value for a field. +// +// For a field belonging to a oneof, it implicitly clears any other field +// that may be currently set within the same oneof. +// For extension fields, it implicitly stores the provided ExtensionType. +// When setting a composite type, it is unspecified whether the stored value +// aliases the source's memory in any way. If the composite value is an +// empty, read-only value, then it panics. +// +// Set is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_EchoResponse) Set(fd protoreflect.FieldDescriptor, value protoreflect.Value) { + switch fd.FullName() { + case "testpb.EchoResponse.request": + x.Request = value.Message().Interface().(*EchoRequest) + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.EchoResponse")) + } + panic(fmt.Errorf("message testpb.EchoResponse does not contain field %s", fd.FullName())) + } +} + +// Mutable returns a mutable reference to a composite type. +// +// If the field is unpopulated, it may allocate a composite value. +// For a field belonging to a oneof, it implicitly clears any other field +// that may be currently set within the same oneof. +// For extension fields, it implicitly stores the provided ExtensionType +// if not already stored. +// It panics if the field does not contain a composite type. +// +// Mutable is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_EchoResponse) Mutable(fd protoreflect.FieldDescriptor) protoreflect.Value { + switch fd.FullName() { + case "testpb.EchoResponse.request": + if x.Request == nil { + x.Request = new(EchoRequest) + } + return protoreflect.ValueOfMessage(x.Request.ProtoReflect()) + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.EchoResponse")) + } + panic(fmt.Errorf("message testpb.EchoResponse does not contain field %s", fd.FullName())) + } +} + +// NewField returns a new value that is assignable to the field +// for the given descriptor. For scalars, this returns the default value. +// For lists, maps, and messages, this returns a new, empty, mutable value. +func (x *fastReflection_EchoResponse) NewField(fd protoreflect.FieldDescriptor) protoreflect.Value { + switch fd.FullName() { + case "testpb.EchoResponse.request": + m := new(EchoRequest) + return protoreflect.ValueOfMessage(m.ProtoReflect()) + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.EchoResponse")) + } + panic(fmt.Errorf("message testpb.EchoResponse does not contain field %s", fd.FullName())) + } +} + +// WhichOneof reports which field within the oneof is populated, +// returning nil if none are populated. +// It panics if the oneof descriptor does not belong to this message. +func (x *fastReflection_EchoResponse) WhichOneof(d protoreflect.OneofDescriptor) protoreflect.FieldDescriptor { + switch d.FullName() { + default: + panic(fmt.Errorf("%s is not a oneof field in testpb.EchoResponse", d.FullName())) + } + panic("unreachable") +} + +// GetUnknown retrieves the entire list of unknown fields. +// The caller may only mutate the contents of the RawFields +// if the mutated bytes are stored back into the message with SetUnknown. +func (x *fastReflection_EchoResponse) GetUnknown() protoreflect.RawFields { + return x.unknownFields +} + +// SetUnknown stores an entire list of unknown fields. +// The raw fields must be syntactically valid according to the wire format. +// An implementation may panic if this is not the case. +// Once stored, the caller must not mutate the content of the RawFields. +// An empty RawFields may be passed to clear the fields. +// +// SetUnknown is a mutating operation and unsafe for concurrent use. +func (x *fastReflection_EchoResponse) SetUnknown(fields protoreflect.RawFields) { + x.unknownFields = fields +} + +// IsValid reports whether the message is valid. +// +// An invalid message is an empty, read-only value. +// +// An invalid message often corresponds to a nil pointer of the concrete +// message type, but the details are implementation dependent. +// Validity is not part of the protobuf data model, and may not +// be preserved in marshaling or other operations. +func (x *fastReflection_EchoResponse) IsValid() bool { + return x != nil +} + +// ProtoMethods returns optional fastReflectionFeature-path implementations of various operations. +// This method may return nil. +// +// The returned methods type is identical to +// "google.golang.org/protobuf/runtime/protoiface".Methods. +// Consult the protoiface package documentation for details. +func (x *fastReflection_EchoResponse) ProtoMethods() *protoiface.Methods { + size := func(input protoiface.SizeInput) protoiface.SizeOutput { + x := input.Message.Interface().(*EchoResponse) + if x == nil { + return protoiface.SizeOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Size: 0, + } + } + options := runtime.SizeInputToOptions(input) + _ = options + var n int + var l int + _ = l + if x.Request != nil { + l = options.Size(x.Request) + n += 1 + l + runtime.Sov(uint64(l)) + } + if x.unknownFields != nil { + n += len(x.unknownFields) + } + return protoiface.SizeOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Size: n, + } + } + + marshal := func(input protoiface.MarshalInput) (protoiface.MarshalOutput, error) { + x := input.Message.Interface().(*EchoResponse) + if x == nil { + return protoiface.MarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Buf: input.Buf, + }, nil + } + options := runtime.MarshalInputToOptions(input) + _ = options + size := options.Size(x) + dAtA := make([]byte, size) + i := len(dAtA) + _ = i + var l int + _ = l + if x.unknownFields != nil { + i -= len(x.unknownFields) + copy(dAtA[i:], x.unknownFields) + } + if x.Request != nil { + encoded, err := options.Marshal(x.Request) + if err != nil { + return protoiface.MarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Buf: input.Buf, + }, err + } + i -= len(encoded) + copy(dAtA[i:], encoded) + i = runtime.EncodeVarint(dAtA, i, uint64(len(encoded))) + i-- + dAtA[i] = 0xa + } + if input.Buf != nil { + input.Buf = append(input.Buf, dAtA...) + } else { + input.Buf = dAtA + } + return protoiface.MarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Buf: input.Buf, + }, nil + } + unmarshal := func(input protoiface.UnmarshalInput) (protoiface.UnmarshalOutput, error) { + x := input.Message.Interface().(*EchoResponse) + if x == nil { + return protoiface.UnmarshalOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Flags: input.Flags, + }, nil + } + options := runtime.UnmarshalInputToOptions(input) + _ = options + dAtA := input.Buf + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: EchoResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: EchoResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Request", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow + } + if iNdEx >= l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if postIndex > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + if x.Request == nil { + x.Request = &EchoRequest{} + } + if err := options.Unmarshal(dAtA[iNdEx:postIndex], x.Request); err != nil { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := runtime.Skip(dAtA[iNdEx:]) + if err != nil { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if (iNdEx + skippy) > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + if !options.DiscardUnknown { + x.unknownFields = append(x.unknownFields, dAtA[iNdEx:iNdEx+skippy]...) + } + iNdEx += skippy + } + } + + if iNdEx > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, nil + } + return &protoiface.Methods{ + NoUnkeyedLiterals: struct{}{}, + Flags: protoiface.SupportMarshalDeterministic | protoiface.SupportUnmarshalDiscardUnknown, + Size: size, + Marshal: marshal, + Unmarshal: unmarshal, + Merge: nil, + CheckInitialized: nil, + } +} + +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.27.0 +// protoc (unknown) +// source: testpb/query.proto + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type Enum int32 + +const ( + Enum_ENUM_UNSPECIFIED Enum = 0 + Enum_ENUM_ONE Enum = 1 + Enum_ENUM_TWO Enum = 2 + Enum_ENUM_FIVE Enum = 5 + Enum_ENUM_NEG_THREE Enum = -3 +) + +// Enum value maps for Enum. +var ( + Enum_name = map[int32]string{ + 0: "ENUM_UNSPECIFIED", + 1: "ENUM_ONE", + 2: "ENUM_TWO", + 5: "ENUM_FIVE", + -3: "ENUM_NEG_THREE", + } + Enum_value = map[string]int32{ + "ENUM_UNSPECIFIED": 0, + "ENUM_ONE": 1, + "ENUM_TWO": 2, + "ENUM_FIVE": 5, + "ENUM_NEG_THREE": -3, + } +) + +func (x Enum) Enum() *Enum { + p := new(Enum) + *p = x + return p +} + +func (x Enum) String() string { + return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) +} + +func (Enum) Descriptor() protoreflect.EnumDescriptor { + return file_testpb_query_proto_enumTypes[0].Descriptor() +} + +func (Enum) Type() protoreflect.EnumType { + return &file_testpb_query_proto_enumTypes[0] +} + +func (x Enum) Number() protoreflect.EnumNumber { + return protoreflect.EnumNumber(x) +} + +// Deprecated: Use Enum.Descriptor instead. +func (Enum) EnumDescriptor() ([]byte, []int) { + return file_testpb_query_proto_rawDescGZIP(), []int{0} +} + +type AMessage struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Bar string `protobuf:"bytes,1,opt,name=bar,proto3" json:"bar,omitempty"` + Baz int32 `protobuf:"varint,2,opt,name=baz,proto3" json:"baz,omitempty"` +} + +func (x *AMessage) Reset() { + *x = AMessage{} + if protoimpl.UnsafeEnabled { + mi := &file_testpb_query_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *AMessage) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*AMessage) ProtoMessage() {} + +// Deprecated: Use AMessage.ProtoReflect.Descriptor instead. +func (*AMessage) Descriptor() ([]byte, []int) { + return file_testpb_query_proto_rawDescGZIP(), []int{0} +} + +func (x *AMessage) GetBar() string { + if x != nil { + return x.Bar + } + return "" +} + +func (x *AMessage) GetBaz() int32 { + if x != nil { + return x.Baz + } + return 0 +} + +type EchoRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // u32 is an uint32 + U32 uint32 `protobuf:"varint,1,opt,name=u32,proto3" json:"u32,omitempty"` + U64 uint64 `protobuf:"varint,2,opt,name=u64,proto3" json:"u64,omitempty"` + Str string `protobuf:"bytes,3,opt,name=str,proto3" json:"str,omitempty"` + Bz []byte `protobuf:"bytes,4,opt,name=bz,proto3" json:"bz,omitempty"` + Timestamp *timestamppb.Timestamp `protobuf:"bytes,5,opt,name=timestamp,proto3" json:"timestamp,omitempty"` + Duration *durationpb.Duration `protobuf:"bytes,6,opt,name=duration,proto3" json:"duration,omitempty"` + I32 int32 `protobuf:"varint,7,opt,name=i32,proto3" json:"i32,omitempty"` + I64 int64 `protobuf:"varint,10,opt,name=i64,proto3" json:"i64,omitempty"` + ABool bool `protobuf:"varint,15,opt,name=a_bool,json=aBool,proto3" json:"a_bool,omitempty"` + AnEnum Enum `protobuf:"varint,16,opt,name=an_enum,json=anEnum,proto3,enum=testpb.Enum" json:"an_enum,omitempty"` + AMessage *AMessage `protobuf:"bytes,17,opt,name=a_message,json=aMessage,proto3" json:"a_message,omitempty"` + ACoin *v1beta1.Coin `protobuf:"bytes,18,opt,name=a_coin,json=aCoin,proto3" json:"a_coin,omitempty"` + AnAddress string `protobuf:"bytes,19,opt,name=an_address,json=anAddress,proto3" json:"an_address,omitempty"` + Page *v1beta11.PageRequest `protobuf:"bytes,20,opt,name=page,proto3" json:"page,omitempty"` + Bools []bool `protobuf:"varint,21,rep,packed,name=bools,proto3" json:"bools,omitempty"` + Uints []uint32 `protobuf:"varint,22,rep,packed,name=uints,proto3" json:"uints,omitempty"` + Strings []string `protobuf:"bytes,23,rep,name=strings,proto3" json:"strings,omitempty"` + Enums []Enum `protobuf:"varint,24,rep,packed,name=enums,proto3,enum=testpb.Enum" json:"enums,omitempty"` + Durations []*durationpb.Duration `protobuf:"bytes,25,rep,name=durations,proto3" json:"durations,omitempty"` + SomeMessages []*AMessage `protobuf:"bytes,26,rep,name=some_messages,json=someMessages,proto3" json:"some_messages,omitempty"` + Positional1 int32 `protobuf:"varint,27,opt,name=positional1,proto3" json:"positional1,omitempty"` + Positional2 string `protobuf:"bytes,28,opt,name=positional2,proto3" json:"positional2,omitempty"` + Positional3Varargs []*v1beta1.Coin `protobuf:"bytes,29,rep,name=positional3_varargs,json=positional3Varargs,proto3" json:"positional3_varargs,omitempty"` + DeprecatedField string `protobuf:"bytes,30,opt,name=deprecated_field,json=deprecatedField,proto3" json:"deprecated_field,omitempty"` + ShorthandDeprecatedField string `protobuf:"bytes,31,opt,name=shorthand_deprecated_field,json=shorthandDeprecatedField,proto3" json:"shorthand_deprecated_field,omitempty"` + HiddenBool bool `protobuf:"varint,32,opt,name=hidden_bool,json=hiddenBool,proto3" json:"hidden_bool,omitempty"` + MapStringString map[string]string `protobuf:"bytes,33,rep,name=map_string_string,json=mapStringString,proto3" json:"map_string_string,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` + MapStringUint32 map[string]uint32 `protobuf:"bytes,34,rep,name=map_string_uint32,json=mapStringUint32,proto3" json:"map_string_uint32,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3"` + MapStringCoin map[string]*v1beta1.Coin `protobuf:"bytes,35,rep,name=map_string_coin,json=mapStringCoin,proto3" json:"map_string_coin,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` + AValidatorAddress string `protobuf:"bytes,36,opt,name=a_validator_address,json=aValidatorAddress,proto3" json:"a_validator_address,omitempty"` + AConsensusAddress string `protobuf:"bytes,37,opt,name=a_consensus_address,json=aConsensusAddress,proto3" json:"a_consensus_address,omitempty"` + Coins []*v1beta1.Coin `protobuf:"bytes,38,rep,name=coins,proto3" json:"coins,omitempty"` +} + +func (x *EchoRequest) Reset() { + *x = EchoRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_testpb_query_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *EchoRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*EchoRequest) ProtoMessage() {} + +// Deprecated: Use EchoRequest.ProtoReflect.Descriptor instead. +func (*EchoRequest) Descriptor() ([]byte, []int) { + return file_testpb_query_proto_rawDescGZIP(), []int{1} +} + +func (x *EchoRequest) GetU32() uint32 { + if x != nil { + return x.U32 + } + return 0 +} + +func (x *EchoRequest) GetU64() uint64 { + if x != nil { + return x.U64 + } + return 0 +} + +func (x *EchoRequest) GetStr() string { + if x != nil { + return x.Str + } + return "" +} + +func (x *EchoRequest) GetBz() []byte { + if x != nil { + return x.Bz + } + return nil +} + +func (x *EchoRequest) GetTimestamp() *timestamppb.Timestamp { + if x != nil { + return x.Timestamp + } + return nil +} + +func (x *EchoRequest) GetDuration() *durationpb.Duration { + if x != nil { + return x.Duration + } + return nil +} + +func (x *EchoRequest) GetI32() int32 { + if x != nil { + return x.I32 + } + return 0 +} + +func (x *EchoRequest) GetI64() int64 { + if x != nil { + return x.I64 + } + return 0 +} + +func (x *EchoRequest) GetABool() bool { + if x != nil { + return x.ABool + } + return false +} + +func (x *EchoRequest) GetAnEnum() Enum { + if x != nil { + return x.AnEnum + } + return Enum_ENUM_UNSPECIFIED +} + +func (x *EchoRequest) GetAMessage() *AMessage { + if x != nil { + return x.AMessage + } + return nil +} + +func (x *EchoRequest) GetACoin() *v1beta1.Coin { + if x != nil { + return x.ACoin + } + return nil +} + +func (x *EchoRequest) GetAnAddress() string { + if x != nil { + return x.AnAddress + } + return "" +} + +func (x *EchoRequest) GetPage() *v1beta11.PageRequest { + if x != nil { + return x.Page + } + return nil +} + +func (x *EchoRequest) GetBools() []bool { + if x != nil { + return x.Bools + } + return nil +} + +func (x *EchoRequest) GetUints() []uint32 { + if x != nil { + return x.Uints + } + return nil +} + +func (x *EchoRequest) GetStrings() []string { + if x != nil { + return x.Strings + } + return nil +} + +func (x *EchoRequest) GetEnums() []Enum { + if x != nil { + return x.Enums + } + return nil +} + +func (x *EchoRequest) GetDurations() []*durationpb.Duration { + if x != nil { + return x.Durations + } + return nil +} + +func (x *EchoRequest) GetSomeMessages() []*AMessage { + if x != nil { + return x.SomeMessages + } + return nil +} + +func (x *EchoRequest) GetPositional1() int32 { + if x != nil { + return x.Positional1 + } + return 0 +} + +func (x *EchoRequest) GetPositional2() string { + if x != nil { + return x.Positional2 + } + return "" +} + +func (x *EchoRequest) GetPositional3Varargs() []*v1beta1.Coin { + if x != nil { + return x.Positional3Varargs + } + return nil +} + +func (x *EchoRequest) GetDeprecatedField() string { + if x != nil { + return x.DeprecatedField + } + return "" +} + +func (x *EchoRequest) GetShorthandDeprecatedField() string { + if x != nil { + return x.ShorthandDeprecatedField + } + return "" +} + +func (x *EchoRequest) GetHiddenBool() bool { + if x != nil { + return x.HiddenBool + } + return false +} + +func (x *EchoRequest) GetMapStringString() map[string]string { + if x != nil { + return x.MapStringString + } + return nil +} + +func (x *EchoRequest) GetMapStringUint32() map[string]uint32 { + if x != nil { + return x.MapStringUint32 + } + return nil +} + +func (x *EchoRequest) GetMapStringCoin() map[string]*v1beta1.Coin { + if x != nil { + return x.MapStringCoin + } + return nil +} + +func (x *EchoRequest) GetAValidatorAddress() string { + if x != nil { + return x.AValidatorAddress + } + return "" +} + +func (x *EchoRequest) GetAConsensusAddress() string { + if x != nil { + return x.AConsensusAddress + } + return "" +} + +func (x *EchoRequest) GetCoins() []*v1beta1.Coin { + if x != nil { + return x.Coins + } + return nil +} + +type EchoResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Request *EchoRequest `protobuf:"bytes,1,opt,name=request,proto3" json:"request,omitempty"` +} + +func (x *EchoResponse) Reset() { + *x = EchoResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_testpb_query_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *EchoResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*EchoResponse) ProtoMessage() {} + +// Deprecated: Use EchoResponse.ProtoReflect.Descriptor instead. +func (*EchoResponse) Descriptor() ([]byte, []int) { + return file_testpb_query_proto_rawDescGZIP(), []int{2} +} + +func (x *EchoResponse) GetRequest() *EchoRequest { + if x != nil { + return x.Request + } + return nil +} + +var File_testpb_query_proto protoreflect.FileDescriptor + +var file_testpb_query_proto_rawDesc = []byte{ + 0x0a, 0x12, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x2f, 0x71, 0x75, 0x65, 0x72, 0x79, 0x2e, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x06, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x1a, 0x1f, 0x67, 0x6f, + 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x74, 0x69, + 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1e, 0x67, + 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x64, + 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x19, 0x63, + 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x5f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x63, 0x6f, 0x73, 0x6d, + 0x6f, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x2a, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, + 0x2f, 0x62, 0x61, 0x73, 0x65, 0x2f, 0x71, 0x75, 0x65, 0x72, 0x79, 0x2f, 0x76, 0x31, 0x62, 0x65, + 0x74, 0x61, 0x31, 0x2f, 0x70, 0x61, 0x67, 0x69, 0x6e, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x62, 0x61, 0x73, + 0x65, 0x2f, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x2f, 0x63, 0x6f, 0x69, 0x6e, 0x2e, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x2e, 0x0a, 0x08, 0x41, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, + 0x12, 0x10, 0x0a, 0x03, 0x62, 0x61, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x62, + 0x61, 0x72, 0x12, 0x10, 0x0a, 0x03, 0x62, 0x61, 0x7a, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, + 0x03, 0x62, 0x61, 0x7a, 0x22, 0xa8, 0x0d, 0x0a, 0x0b, 0x45, 0x63, 0x68, 0x6f, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x33, 0x32, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x0d, 0x52, 0x03, 0x75, 0x33, 0x32, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x36, 0x34, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x04, 0x52, 0x03, 0x75, 0x36, 0x34, 0x12, 0x10, 0x0a, 0x03, 0x73, 0x74, 0x72, 0x18, + 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x73, 0x74, 0x72, 0x12, 0x0e, 0x0a, 0x02, 0x62, 0x7a, + 0x18, 0x04, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x02, 0x62, 0x7a, 0x12, 0x38, 0x0a, 0x09, 0x74, 0x69, + 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, + 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, + 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x09, 0x74, 0x69, 0x6d, 0x65, 0x73, + 0x74, 0x61, 0x6d, 0x70, 0x12, 0x35, 0x0a, 0x08, 0x64, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, + 0x18, 0x06, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x44, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, + 0x6e, 0x52, 0x08, 0x64, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x10, 0x0a, 0x03, 0x69, + 0x33, 0x32, 0x18, 0x07, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x69, 0x33, 0x32, 0x12, 0x10, 0x0a, + 0x03, 0x69, 0x36, 0x34, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x03, 0x52, 0x03, 0x69, 0x36, 0x34, 0x12, + 0x15, 0x0a, 0x06, 0x61, 0x5f, 0x62, 0x6f, 0x6f, 0x6c, 0x18, 0x0f, 0x20, 0x01, 0x28, 0x08, 0x52, + 0x05, 0x61, 0x42, 0x6f, 0x6f, 0x6c, 0x12, 0x25, 0x0a, 0x07, 0x61, 0x6e, 0x5f, 0x65, 0x6e, 0x75, + 0x6d, 0x18, 0x10, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x0c, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, + 0x2e, 0x45, 0x6e, 0x75, 0x6d, 0x52, 0x06, 0x61, 0x6e, 0x45, 0x6e, 0x75, 0x6d, 0x12, 0x2d, 0x0a, + 0x09, 0x61, 0x5f, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x11, 0x20, 0x01, 0x28, 0x0b, + 0x32, 0x10, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x2e, 0x41, 0x4d, 0x65, 0x73, 0x73, 0x61, + 0x67, 0x65, 0x52, 0x08, 0x61, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x30, 0x0a, 0x06, + 0x61, 0x5f, 0x63, 0x6f, 0x69, 0x6e, 0x18, 0x12, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x63, + 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x76, 0x31, 0x62, 0x65, 0x74, + 0x61, 0x31, 0x2e, 0x43, 0x6f, 0x69, 0x6e, 0x52, 0x05, 0x61, 0x43, 0x6f, 0x69, 0x6e, 0x12, 0x37, + 0x0a, 0x0a, 0x61, 0x6e, 0x5f, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, 0x13, 0x20, 0x01, + 0x28, 0x09, 0x42, 0x18, 0xd2, 0xb4, 0x2d, 0x14, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x41, + 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x52, 0x09, 0x61, 0x6e, + 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x12, 0x3a, 0x0a, 0x04, 0x70, 0x61, 0x67, 0x65, 0x18, + 0x14, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x26, 0x2e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x62, + 0x61, 0x73, 0x65, 0x2e, 0x71, 0x75, 0x65, 0x72, 0x79, 0x2e, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, + 0x31, 0x2e, 0x50, 0x61, 0x67, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x52, 0x04, 0x70, + 0x61, 0x67, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x62, 0x6f, 0x6f, 0x6c, 0x73, 0x18, 0x15, 0x20, 0x03, + 0x28, 0x08, 0x52, 0x05, 0x62, 0x6f, 0x6f, 0x6c, 0x73, 0x12, 0x14, 0x0a, 0x05, 0x75, 0x69, 0x6e, + 0x74, 0x73, 0x18, 0x16, 0x20, 0x03, 0x28, 0x0d, 0x52, 0x05, 0x75, 0x69, 0x6e, 0x74, 0x73, 0x12, + 0x18, 0x0a, 0x07, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x73, 0x18, 0x17, 0x20, 0x03, 0x28, 0x09, + 0x52, 0x07, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x73, 0x12, 0x22, 0x0a, 0x05, 0x65, 0x6e, 0x75, + 0x6d, 0x73, 0x18, 0x18, 0x20, 0x03, 0x28, 0x0e, 0x32, 0x0c, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x70, + 0x62, 0x2e, 0x45, 0x6e, 0x75, 0x6d, 0x52, 0x05, 0x65, 0x6e, 0x75, 0x6d, 0x73, 0x12, 0x37, 0x0a, + 0x09, 0x64, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0x19, 0x20, 0x03, 0x28, 0x0b, + 0x32, 0x19, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, + 0x75, 0x66, 0x2e, 0x44, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x09, 0x64, 0x75, 0x72, + 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x35, 0x0a, 0x0d, 0x73, 0x6f, 0x6d, 0x65, 0x5f, 0x6d, + 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x73, 0x18, 0x1a, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x10, 0x2e, + 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x2e, 0x41, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x52, + 0x0c, 0x73, 0x6f, 0x6d, 0x65, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x73, 0x12, 0x20, 0x0a, + 0x0b, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x61, 0x6c, 0x31, 0x18, 0x1b, 0x20, 0x01, + 0x28, 0x05, 0x52, 0x0b, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x61, 0x6c, 0x31, 0x12, + 0x20, 0x0a, 0x0b, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x61, 0x6c, 0x32, 0x18, 0x1c, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x61, 0x6c, + 0x32, 0x12, 0x4a, 0x0a, 0x13, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x61, 0x6c, 0x33, + 0x5f, 0x76, 0x61, 0x72, 0x61, 0x72, 0x67, 0x73, 0x18, 0x1d, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x19, + 0x2e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x76, 0x31, 0x62, + 0x65, 0x74, 0x61, 0x31, 0x2e, 0x43, 0x6f, 0x69, 0x6e, 0x52, 0x12, 0x70, 0x6f, 0x73, 0x69, 0x74, + 0x69, 0x6f, 0x6e, 0x61, 0x6c, 0x33, 0x56, 0x61, 0x72, 0x61, 0x72, 0x67, 0x73, 0x12, 0x29, 0x0a, + 0x10, 0x64, 0x65, 0x70, 0x72, 0x65, 0x63, 0x61, 0x74, 0x65, 0x64, 0x5f, 0x66, 0x69, 0x65, 0x6c, + 0x64, 0x18, 0x1e, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0f, 0x64, 0x65, 0x70, 0x72, 0x65, 0x63, 0x61, + 0x74, 0x65, 0x64, 0x46, 0x69, 0x65, 0x6c, 0x64, 0x12, 0x3c, 0x0a, 0x1a, 0x73, 0x68, 0x6f, 0x72, + 0x74, 0x68, 0x61, 0x6e, 0x64, 0x5f, 0x64, 0x65, 0x70, 0x72, 0x65, 0x63, 0x61, 0x74, 0x65, 0x64, + 0x5f, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x18, 0x1f, 0x20, 0x01, 0x28, 0x09, 0x52, 0x18, 0x73, 0x68, + 0x6f, 0x72, 0x74, 0x68, 0x61, 0x6e, 0x64, 0x44, 0x65, 0x70, 0x72, 0x65, 0x63, 0x61, 0x74, 0x65, + 0x64, 0x46, 0x69, 0x65, 0x6c, 0x64, 0x12, 0x1f, 0x0a, 0x0b, 0x68, 0x69, 0x64, 0x64, 0x65, 0x6e, + 0x5f, 0x62, 0x6f, 0x6f, 0x6c, 0x18, 0x20, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0a, 0x68, 0x69, 0x64, + 0x64, 0x65, 0x6e, 0x42, 0x6f, 0x6f, 0x6c, 0x12, 0x54, 0x0a, 0x11, 0x6d, 0x61, 0x70, 0x5f, 0x73, + 0x74, 0x72, 0x69, 0x6e, 0x67, 0x5f, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x18, 0x21, 0x20, 0x03, + 0x28, 0x0b, 0x32, 0x28, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x2e, 0x45, 0x63, 0x68, 0x6f, + 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x2e, 0x4d, 0x61, 0x70, 0x53, 0x74, 0x72, 0x69, 0x6e, + 0x67, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x0f, 0x6d, 0x61, + 0x70, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x12, 0x54, 0x0a, + 0x11, 0x6d, 0x61, 0x70, 0x5f, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x5f, 0x75, 0x69, 0x6e, 0x74, + 0x33, 0x32, 0x18, 0x22, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x28, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x70, + 0x62, 0x2e, 0x45, 0x63, 0x68, 0x6f, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x2e, 0x4d, 0x61, + 0x70, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x55, 0x69, 0x6e, 0x74, 0x33, 0x32, 0x45, 0x6e, 0x74, + 0x72, 0x79, 0x52, 0x0f, 0x6d, 0x61, 0x70, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x55, 0x69, 0x6e, + 0x74, 0x33, 0x32, 0x12, 0x4e, 0x0a, 0x0f, 0x6d, 0x61, 0x70, 0x5f, 0x73, 0x74, 0x72, 0x69, 0x6e, + 0x67, 0x5f, 0x63, 0x6f, 0x69, 0x6e, 0x18, 0x23, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x26, 0x2e, 0x74, + 0x65, 0x73, 0x74, 0x70, 0x62, 0x2e, 0x45, 0x63, 0x68, 0x6f, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x2e, 0x4d, 0x61, 0x70, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x43, 0x6f, 0x69, 0x6e, 0x45, + 0x6e, 0x74, 0x72, 0x79, 0x52, 0x0d, 0x6d, 0x61, 0x70, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x43, + 0x6f, 0x69, 0x6e, 0x12, 0x51, 0x0a, 0x13, 0x61, 0x5f, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, + 0x6f, 0x72, 0x5f, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, 0x24, 0x20, 0x01, 0x28, 0x09, + 0x42, 0x21, 0xd2, 0xb4, 0x2d, 0x1d, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x56, 0x61, 0x6c, + 0x69, 0x64, 0x61, 0x74, 0x6f, 0x72, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x53, 0x74, 0x72, + 0x69, 0x6e, 0x67, 0x52, 0x11, 0x61, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x6f, 0x72, 0x41, + 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x12, 0x51, 0x0a, 0x13, 0x61, 0x5f, 0x63, 0x6f, 0x6e, 0x73, + 0x65, 0x6e, 0x73, 0x75, 0x73, 0x5f, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, 0x25, 0x20, + 0x01, 0x28, 0x09, 0x42, 0x21, 0xd2, 0xb4, 0x2d, 0x1d, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, + 0x43, 0x6f, 0x6e, 0x73, 0x65, 0x6e, 0x73, 0x75, 0x73, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, + 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x52, 0x11, 0x61, 0x43, 0x6f, 0x6e, 0x73, 0x65, 0x6e, 0x73, + 0x75, 0x73, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x12, 0x2f, 0x0a, 0x05, 0x63, 0x6f, 0x69, + 0x6e, 0x73, 0x18, 0x26, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, + 0x73, 0x2e, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x2e, 0x43, + 0x6f, 0x69, 0x6e, 0x52, 0x05, 0x63, 0x6f, 0x69, 0x6e, 0x73, 0x1a, 0x42, 0x0a, 0x14, 0x4d, 0x61, + 0x70, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x45, 0x6e, 0x74, + 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x1a, 0x42, + 0x0a, 0x14, 0x4d, 0x61, 0x70, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x55, 0x69, 0x6e, 0x74, 0x33, + 0x32, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, + 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, + 0x38, 0x01, 0x1a, 0x5b, 0x0a, 0x12, 0x4d, 0x61, 0x70, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x43, + 0x6f, 0x69, 0x6e, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x2f, 0x0a, 0x05, 0x76, 0x61, + 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x63, 0x6f, 0x73, 0x6d, + 0x6f, 0x73, 0x2e, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x2e, + 0x43, 0x6f, 0x69, 0x6e, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, + 0x3d, 0x0a, 0x0c, 0x45, 0x63, 0x68, 0x6f, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, + 0x2d, 0x0a, 0x07, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, + 0x32, 0x13, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x2e, 0x45, 0x63, 0x68, 0x6f, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x52, 0x07, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x2a, 0x64, + 0x0a, 0x04, 0x45, 0x6e, 0x75, 0x6d, 0x12, 0x14, 0x0a, 0x10, 0x45, 0x4e, 0x55, 0x4d, 0x5f, 0x55, + 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, 0x00, 0x12, 0x0c, 0x0a, 0x08, + 0x45, 0x4e, 0x55, 0x4d, 0x5f, 0x4f, 0x4e, 0x45, 0x10, 0x01, 0x12, 0x0c, 0x0a, 0x08, 0x45, 0x4e, + 0x55, 0x4d, 0x5f, 0x54, 0x57, 0x4f, 0x10, 0x02, 0x12, 0x0d, 0x0a, 0x09, 0x45, 0x4e, 0x55, 0x4d, + 0x5f, 0x46, 0x49, 0x56, 0x45, 0x10, 0x05, 0x12, 0x1b, 0x0a, 0x0e, 0x45, 0x4e, 0x55, 0x4d, 0x5f, + 0x4e, 0x45, 0x47, 0x5f, 0x54, 0x48, 0x52, 0x45, 0x45, 0x10, 0xfd, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0x01, 0x32, 0x3a, 0x0a, 0x05, 0x51, 0x75, 0x65, 0x72, 0x79, 0x12, 0x31, 0x0a, + 0x04, 0x45, 0x63, 0x68, 0x6f, 0x12, 0x13, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x2e, 0x45, + 0x63, 0x68, 0x6f, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x14, 0x2e, 0x74, 0x65, 0x73, + 0x74, 0x70, 0x62, 0x2e, 0x45, 0x63, 0x68, 0x6f, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, + 0x42, 0x88, 0x01, 0x0a, 0x0a, 0x63, 0x6f, 0x6d, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x42, + 0x0a, 0x51, 0x75, 0x65, 0x72, 0x79, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x36, 0x67, + 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, + 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2d, 0x73, 0x64, 0x6b, 0x2f, 0x63, 0x6c, 0x69, 0x65, + 0x6e, 0x74, 0x2f, 0x76, 0x32, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x74, + 0x65, 0x73, 0x74, 0x70, 0x62, 0xa2, 0x02, 0x03, 0x54, 0x58, 0x58, 0xaa, 0x02, 0x06, 0x54, 0x65, + 0x73, 0x74, 0x70, 0x62, 0xca, 0x02, 0x06, 0x54, 0x65, 0x73, 0x74, 0x70, 0x62, 0xe2, 0x02, 0x12, + 0x54, 0x65, 0x73, 0x74, 0x70, 0x62, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, + 0x74, 0x61, 0xea, 0x02, 0x06, 0x54, 0x65, 0x73, 0x74, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x33, +} + +var ( + file_testpb_query_proto_rawDescOnce sync.Once + file_testpb_query_proto_rawDescData = file_testpb_query_proto_rawDesc +) + +func file_testpb_query_proto_rawDescGZIP() []byte { + file_testpb_query_proto_rawDescOnce.Do(func() { + file_testpb_query_proto_rawDescData = protoimpl.X.CompressGZIP(file_testpb_query_proto_rawDescData) + }) + return file_testpb_query_proto_rawDescData +} + +var file_testpb_query_proto_enumTypes = make([]protoimpl.EnumInfo, 1) +var file_testpb_query_proto_msgTypes = make([]protoimpl.MessageInfo, 6) +var file_testpb_query_proto_goTypes = []interface{}{ + (Enum)(0), // 0: testpb.Enum + (*AMessage)(nil), // 1: testpb.AMessage + (*EchoRequest)(nil), // 2: testpb.EchoRequest + (*EchoResponse)(nil), // 3: testpb.EchoResponse + nil, // 4: testpb.EchoRequest.MapStringStringEntry + nil, // 5: testpb.EchoRequest.MapStringUint32Entry + nil, // 6: testpb.EchoRequest.MapStringCoinEntry + (*timestamppb.Timestamp)(nil), // 7: google.protobuf.Timestamp + (*durationpb.Duration)(nil), // 8: google.protobuf.Duration + (*v1beta1.Coin)(nil), // 9: cosmos.base.v1beta1.Coin + (*v1beta11.PageRequest)(nil), // 10: cosmos.base.query.v1beta1.PageRequest +} +var file_testpb_query_proto_depIdxs = []int32{ + 7, // 0: testpb.EchoRequest.timestamp:type_name -> google.protobuf.Timestamp + 8, // 1: testpb.EchoRequest.duration:type_name -> google.protobuf.Duration + 0, // 2: testpb.EchoRequest.an_enum:type_name -> testpb.Enum + 1, // 3: testpb.EchoRequest.a_message:type_name -> testpb.AMessage + 9, // 4: testpb.EchoRequest.a_coin:type_name -> cosmos.base.v1beta1.Coin + 10, // 5: testpb.EchoRequest.page:type_name -> cosmos.base.query.v1beta1.PageRequest + 0, // 6: testpb.EchoRequest.enums:type_name -> testpb.Enum + 8, // 7: testpb.EchoRequest.durations:type_name -> google.protobuf.Duration + 1, // 8: testpb.EchoRequest.some_messages:type_name -> testpb.AMessage + 9, // 9: testpb.EchoRequest.positional3_varargs:type_name -> cosmos.base.v1beta1.Coin + 4, // 10: testpb.EchoRequest.map_string_string:type_name -> testpb.EchoRequest.MapStringStringEntry + 5, // 11: testpb.EchoRequest.map_string_uint32:type_name -> testpb.EchoRequest.MapStringUint32Entry + 6, // 12: testpb.EchoRequest.map_string_coin:type_name -> testpb.EchoRequest.MapStringCoinEntry + 9, // 13: testpb.EchoRequest.coins:type_name -> cosmos.base.v1beta1.Coin + 2, // 14: testpb.EchoResponse.request:type_name -> testpb.EchoRequest + 9, // 15: testpb.EchoRequest.MapStringCoinEntry.value:type_name -> cosmos.base.v1beta1.Coin + 2, // 16: testpb.Query.Echo:input_type -> testpb.EchoRequest + 3, // 17: testpb.Query.Echo:output_type -> testpb.EchoResponse + 17, // [17:18] is the sub-list for method output_type + 16, // [16:17] is the sub-list for method input_type + 16, // [16:16] is the sub-list for extension type_name + 16, // [16:16] is the sub-list for extension extendee + 0, // [0:16] is the sub-list for field type_name +} + +func init() { file_testpb_query_proto_init() } +func file_testpb_query_proto_init() { + if File_testpb_query_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_testpb_query_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*AMessage); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_testpb_query_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*EchoRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_testpb_query_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*EchoResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_testpb_query_proto_rawDesc, + NumEnums: 1, + NumMessages: 6, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_testpb_query_proto_goTypes, + DependencyIndexes: file_testpb_query_proto_depIdxs, + EnumInfos: file_testpb_query_proto_enumTypes, + MessageInfos: file_testpb_query_proto_msgTypes, + }.Build() + File_testpb_query_proto = out.File + file_testpb_query_proto_rawDesc = nil + file_testpb_query_proto_goTypes = nil + file_testpb_query_proto_depIdxs = nil +} diff --git a/connect/internal/internal/testpb/query_grpc.pb.go b/connect/internal/internal/testpb/query_grpc.pb.go new file mode 100644 index 00000000..7b31c042 --- /dev/null +++ b/connect/internal/internal/testpb/query_grpc.pb.go @@ -0,0 +1,123 @@ +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.5.1 +// - protoc (unknown) +// source: testpb/query.proto + +package testpb + +import ( + context "context" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +// Requires gRPC-Go v1.64.0 or later. +const _ = grpc.SupportPackageIsVersion9 + +const ( + Query_Echo_FullMethodName = "/testpb.Query/Echo" +) + +// QueryClient is the client API for Query service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. +type QueryClient interface { + // Echo returns the request in the response + Echo(ctx context.Context, in *EchoRequest, opts ...grpc.CallOption) (*EchoResponse, error) +} + +type queryClient struct { + cc grpc.ClientConnInterface +} + +func NewQueryClient(cc grpc.ClientConnInterface) QueryClient { + return &queryClient{cc} +} + +func (c *queryClient) Echo(ctx context.Context, in *EchoRequest, opts ...grpc.CallOption) (*EchoResponse, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(EchoResponse) + err := c.cc.Invoke(ctx, Query_Echo_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +// QueryServer is the server API for Query service. +// All implementations must embed UnimplementedQueryServer +// for forward compatibility. +type QueryServer interface { + // Echo returns the request in the response + Echo(context.Context, *EchoRequest) (*EchoResponse, error) + mustEmbedUnimplementedQueryServer() +} + +// UnimplementedQueryServer must be embedded to have +// forward compatible implementations. +// +// NOTE: this should be embedded by value instead of pointer to avoid a nil +// pointer dereference when methods are called. +type UnimplementedQueryServer struct{} + +func (UnimplementedQueryServer) Echo(context.Context, *EchoRequest) (*EchoResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Echo not implemented") +} +func (UnimplementedQueryServer) mustEmbedUnimplementedQueryServer() {} +func (UnimplementedQueryServer) testEmbeddedByValue() {} + +// UnsafeQueryServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to QueryServer will +// result in compilation errors. +type UnsafeQueryServer interface { + mustEmbedUnimplementedQueryServer() +} + +func RegisterQueryServer(s grpc.ServiceRegistrar, srv QueryServer) { + // If the following call pancis, it indicates UnimplementedQueryServer was + // embedded by pointer and is nil. This will cause panics if an + // unimplemented method is ever invoked, so we test this at initialization + // time to prevent it from happening at runtime later due to I/O. + if t, ok := srv.(interface{ testEmbeddedByValue() }); ok { + t.testEmbeddedByValue() + } + s.RegisterService(&Query_ServiceDesc, srv) +} + +func _Query_Echo_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(EchoRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).Echo(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Query_Echo_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).Echo(ctx, req.(*EchoRequest)) + } + return interceptor(ctx, in, info, handler) +} + +// Query_ServiceDesc is the grpc.ServiceDesc for Query service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var Query_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "testpb.Query", + HandlerType: (*QueryServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Echo", + Handler: _Query_Echo_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "testpb/query.proto", +} diff --git a/connect/internal/internal/util/util.go b/connect/internal/internal/util/util.go new file mode 100644 index 00000000..e478c577 --- /dev/null +++ b/connect/internal/internal/util/util.go @@ -0,0 +1,96 @@ +package util + +import ( + "regexp" + "runtime/debug" + "strings" + + cosmos_proto "github.com/cosmos/cosmos-proto" + "google.golang.org/protobuf/proto" + "google.golang.org/protobuf/reflect/protoreflect" + "google.golang.org/protobuf/reflect/protoregistry" + "google.golang.org/protobuf/types/dynamicpb" + + "github.com/ignite/apps/connect/internal/internal/strcase" +) + +// get build info to verify later if comment is supported +// this is a hack in because of the global api module package +// later versions unsupported by the current version can be added +var buildInfo, _ = debug.ReadBuildInfo() + +// DescriptorKebabName returns the name of the descriptor in kebab case. +func DescriptorKebabName(descriptor protoreflect.Descriptor) string { + return strcase.ToKebab(string(descriptor.Name())) +} + +func ResolveMessageType(resolver protoregistry.MessageTypeResolver, descriptor protoreflect.MessageDescriptor) protoreflect.MessageType { + typ, err := resolver.FindMessageByName(descriptor.FullName()) + if err == nil { + return typ + } + + return dynamicpb.NewMessageType(descriptor) +} + +// IsSupportedVersion is used to determine in which version of a module / sdk a rpc was introduced. +// It returns false if the rpc has comment for an higher version than the current one. +// It returns true if the method descriptor contains no annotation. +func IsSupportedVersion(methodDesc protoreflect.MethodDescriptor) bool { + return isSupportedVersion(methodDesc, buildInfo) +} + +// isSupportedVersion is used to determine in which version of a module / sdk a rpc was introduced. +// It returns false if the rpc has comment for an higher version than the current one. +// It returns true if the method descriptor contains no annotation. +// It takes a buildInfo as argument to be able to test it. +func isSupportedVersion(methodDesc protoreflect.MethodDescriptor, buildInfo *debug.BuildInfo) bool { + hasVersion := proto.HasExtension(methodDesc.Options(), cosmos_proto.E_MethodAddedIn) + if !hasVersion || buildInfo == nil || len(buildInfo.Deps) == 0 { + return true + } + + version := proto.GetExtension(methodDesc.Options(), cosmos_proto.E_MethodAddedIn).(string) + moduleName, version := parseVersion(version) + if moduleName == "" || version == "" { + return true // if no comment consider it's supported + } + + for _, dep := range buildInfo.Deps { + if !strings.Contains(dep.Path, moduleName) { + continue + } + + return version <= dep.Version + } + + // if cannot find the module consider it isn't supported + // for instance the x/gov module wasn't extracted in v0.50 + // so it isn't present in the build info, however, that means + // it isn't supported in v0.50. + return false +} + +var sinceCommentRegex = regexp.MustCompile(`(\S+) (\S+)`) + +// parseVersion parses the `cosmos-sdk v0.xx` comment on rpc. +func parseVersion(input string) (string, string) { + var ( + moduleName string + version string + ) + + input = strings.ToLower(input) + input = strings.ReplaceAll(input, "cosmos sdk", "cosmos-sdk") + + matches := sinceCommentRegex.FindStringSubmatch(input) + if len(matches) >= 3 { + moduleName, version = strings.TrimPrefix(matches[1], "x/"), matches[2] + + if !strings.HasPrefix(version, "v") { + version = "v" + version + } + } + + return moduleName, version +} diff --git a/connect/internal/internal/util/util_test.go b/connect/internal/internal/util/util_test.go new file mode 100644 index 00000000..89fdb994 --- /dev/null +++ b/connect/internal/internal/util/util_test.go @@ -0,0 +1,125 @@ +package util + +import ( + "runtime/debug" + "testing" + + "google.golang.org/protobuf/reflect/protoreflect" + "google.golang.org/protobuf/reflect/protoregistry" + + _ "github.com/ignite/apps/connect/internal/internal/testpb" +) + +func TestIsSupportedVersion(t *testing.T) { + mockBuildInfo := &debug.BuildInfo{ + Deps: []*debug.Module{ + { + Path: "github.com/cosmos/cosmos-sdk", + Version: "v0.50.0", + }, + { + Path: "cosmossdk.io/feegrant", + Version: "v0.1.0", + }, + }, + } + + cases := []struct { + messageName string + expected bool + }{ + { + messageName: "testpb.Msg.Send", + expected: true, + }, + { + messageName: "testpb.Query.Echo", + expected: true, + }, + { + messageName: "testpb.Msg.Clawback", + expected: false, + }, + } + + for _, tc := range cases { + t.Run(tc.messageName, func(t *testing.T) { + desc, err := protoregistry.GlobalFiles.FindDescriptorByName(protoreflect.FullName(tc.messageName)) + if err != nil { + t.Fatal(err) + } + + methodDesc := desc.(protoreflect.MethodDescriptor) + isSupported := isSupportedVersion(methodDesc, mockBuildInfo) + if isSupported != tc.expected { + t.Errorf("expected %v, got %v for %s", tc.expected, isSupported, methodDesc.FullName()) + } + }) + } +} + +func TestParseVersion(t *testing.T) { + cases := []struct { + input string + expectedModuleName string + expectedVersion string + }{ + { + input: "", + expectedModuleName: "", + expectedVersion: "", + }, + { + input: "Cosmos SDK 0.50", + expectedModuleName: "cosmos-sdk", + expectedVersion: "v0.50", + }, + { + input: "cosmos sdk 0.50", + expectedModuleName: "cosmos-sdk", + expectedVersion: "v0.50", + }, + { + input: "Cosmos-SDK 0.50", + expectedModuleName: "cosmos-sdk", + expectedVersion: "v0.50", + }, + { + input: "cosmos-sdk v0.50", + expectedModuleName: "cosmos-sdk", + expectedVersion: "v0.50", + }, + { + input: "cosmos-sdk v0.50.1", + expectedModuleName: "cosmos-sdk", + expectedVersion: "v0.50.1", + }, + { + input: "cosmos-sdk 0.47.0-veronica", + expectedModuleName: "cosmos-sdk", + expectedVersion: "v0.47.0-veronica", + }, + { + input: "x/feegrant v0.1.0", + expectedModuleName: "feegrant", + expectedVersion: "v0.1.0", + }, + { + input: "x/feegrant 0.1", + expectedModuleName: "feegrant", + expectedVersion: "v0.1", + }, + } + + for _, tc := range cases { + t.Run(tc.input, func(t *testing.T) { + moduleName, version := parseVersion(tc.input) + if moduleName != tc.expectedModuleName { + t.Errorf("expected module name %s, got %s", tc.expectedModuleName, moduleName) + } + if version != tc.expectedVersion { + t.Errorf("expected version %s, got %s", tc.expectedVersion, version) + } + }) + } +} From 206866aa7cf34f7c79321e7b233dd446790de03f Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Fri, 14 Feb 2025 00:57:59 +0100 Subject: [PATCH 02/17] updates --- connect/cmd/app.go | 4 ++-- connect/go.mod | 1 - connect/go.sum | 2 -- 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/connect/cmd/app.go b/connect/cmd/app.go index 0ceb2214..665f348c 100644 --- a/connect/cmd/app.go +++ b/connect/cmd/app.go @@ -5,8 +5,6 @@ import ( "fmt" "strings" - "cosmossdk.io/client/v2/autocli" - "cosmossdk.io/client/v2/autocli/flag" "github.com/cosmos/cosmos-sdk/client" sdkflags "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/grpc/cmtservice" @@ -18,6 +16,8 @@ import ( "google.golang.org/protobuf/types/dynamicpb" "github.com/ignite/apps/connect/chains" + "github.com/ignite/apps/connect/internal/autocli" + "github.com/ignite/apps/connect/internal/autocli/flag" ) func AppHandler(ctx context.Context, name string, cfg *chains.ChainConfig, args ...string) (*cobra.Command, error) { diff --git a/connect/go.mod b/connect/go.mod index 2025472f..43199ab5 100644 --- a/connect/go.mod +++ b/connect/go.mod @@ -4,7 +4,6 @@ go 1.23.0 require ( cosmossdk.io/api v0.7.6 - cosmossdk.io/client/v2 v2.0.0-beta.6 cosmossdk.io/core v0.11.1 cosmossdk.io/depinject v1.1.0 cosmossdk.io/errors v1.0.1 diff --git a/connect/go.sum b/connect/go.sum index 61df7717..5115bffa 100644 --- a/connect/go.sum +++ b/connect/go.sum @@ -2,8 +2,6 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cosmossdk.io/api v0.7.6 h1:PC20PcXy1xYKH2KU4RMurVoFjjKkCgYRbVAD4PdqUuY= cosmossdk.io/api v0.7.6/go.mod h1:IcxpYS5fMemZGqyYtErK7OqvdM0C8kdW3dq8Q/XIG38= -cosmossdk.io/client/v2 v2.0.0-beta.6 h1:CygEwABxbwFmqgLINBb3WGVwzaN4yRgB9ZtIGQzhRNQ= -cosmossdk.io/client/v2 v2.0.0-beta.6/go.mod h1:4p0P6o0ro+FizakJUYS9SeM94RNbv0thLmkHRw5o5as= cosmossdk.io/collections v0.4.0 h1:PFmwj2W8szgpD5nOd8GWH6AbYNi1f2J6akWXJ7P5t9s= cosmossdk.io/collections v0.4.0/go.mod h1:oa5lUING2dP+gdDquow+QjlF45eL1t4TJDypgGd+tv0= cosmossdk.io/core v0.11.1 h1:h9WfBey7NAiFfIcUhDVNS503I2P2HdZLebJlUIs8LPA= From b8d81b8de3649d992c7d21ecbd280d59ee23f3d9 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Fri, 14 Feb 2025 01:03:46 +0100 Subject: [PATCH 03/17] updates --- .../{internal => }/account/retriever.go | 0 connect/internal/autocli/common.go | 6 +-- connect/internal/autocli/common_test.go | 2 +- connect/internal/autocli/config/config.go | 2 +- connect/internal/autocli/flag/builder.go | 4 +- connect/internal/autocli/flag/coin.go | 2 +- connect/internal/autocli/flag/dec_coin.go | 2 +- connect/internal/autocli/flag/enum.go | 2 +- connect/internal/autocli/flag/json_message.go | 2 +- connect/internal/autocli/msg.go | 6 +-- connect/internal/autocli/msg_test.go | 2 +- .../internal/autocli/prompt/message_test.go | 2 +- connect/internal/autocli/query.go | 4 +- connect/internal/autocli/query_test.go | 2 +- connect/internal/autocli/util.go | 2 +- .../internal/{internal => }/buf.gen.gogo.yaml | 0 .../{internal => }/buf.gen.pulsar.yaml | 2 +- connect/internal/{internal => }/buf.lock | 0 connect/internal/{internal => }/buf.yaml | 0 .../internal/{internal => }/coins/format.go | 0 .../{internal => }/coins/format_test.go | 0 connect/internal/{internal => }/coins/util.go | 0 .../{internal => }/coins/util_test.go | 0 .../internal/{internal => }/flags/flags.go | 0 .../internal/{internal => }/governance/gov.go | 2 +- connect/internal/helpers/home.go | 48 ------------------- .../internal/{internal => }/print/printer.go | 2 +- .../internal/{internal => }/strcase/kebab.go | 0 .../{internal => }/strcase/kebab_test.go | 2 +- .../internal/{internal => }/testpb/msg.proto | 0 .../{internal => }/testpb/msg.pulsar.go | 0 .../{internal => }/testpb/msg_grpc.pb.go | 0 .../{internal => }/testpb/query.proto | 0 .../{internal => }/testpb/query.pulsar.go | 0 .../{internal => }/testpb/query_grpc.pb.go | 0 connect/internal/{internal => }/util/util.go | 2 +- .../internal/{internal => }/util/util_test.go | 2 +- 37 files changed, 26 insertions(+), 74 deletions(-) rename connect/internal/{internal => }/account/retriever.go (100%) rename connect/internal/{internal => }/buf.gen.gogo.yaml (100%) rename connect/internal/{internal => }/buf.gen.pulsar.yaml (83%) rename connect/internal/{internal => }/buf.lock (100%) rename connect/internal/{internal => }/buf.yaml (100%) rename connect/internal/{internal => }/coins/format.go (100%) rename connect/internal/{internal => }/coins/format_test.go (100%) rename connect/internal/{internal => }/coins/util.go (100%) rename connect/internal/{internal => }/coins/util_test.go (100%) rename connect/internal/{internal => }/flags/flags.go (100%) rename connect/internal/{internal => }/governance/gov.go (97%) delete mode 100644 connect/internal/helpers/home.go rename connect/internal/{internal => }/print/printer.go (96%) rename connect/internal/{internal => }/strcase/kebab.go (100%) rename connect/internal/{internal => }/strcase/kebab_test.go (93%) rename connect/internal/{internal => }/testpb/msg.proto (100%) rename connect/internal/{internal => }/testpb/msg.pulsar.go (100%) rename connect/internal/{internal => }/testpb/msg_grpc.pb.go (100%) rename connect/internal/{internal => }/testpb/query.proto (100%) rename connect/internal/{internal => }/testpb/query.pulsar.go (100%) rename connect/internal/{internal => }/testpb/query_grpc.pb.go (100%) rename connect/internal/{internal => }/util/util.go (98%) rename connect/internal/{internal => }/util/util_test.go (97%) diff --git a/connect/internal/internal/account/retriever.go b/connect/internal/account/retriever.go similarity index 100% rename from connect/internal/internal/account/retriever.go rename to connect/internal/account/retriever.go diff --git a/connect/internal/autocli/common.go b/connect/internal/autocli/common.go index 46379803..ce51c004 100644 --- a/connect/internal/autocli/common.go +++ b/connect/internal/autocli/common.go @@ -17,9 +17,9 @@ import ( "github.com/ignite/apps/connect/internal/autocli/keyring" "github.com/ignite/apps/connect/internal/broadcast/comet" clientcontext "github.com/ignite/apps/connect/internal/context" - "github.com/ignite/apps/connect/internal/internal/flags" - "github.com/ignite/apps/connect/internal/internal/print" - "github.com/ignite/apps/connect/internal/internal/util" + "github.com/ignite/apps/connect/internal/flags" + "github.com/ignite/apps/connect/internal/print" + "github.com/ignite/apps/connect/internal/util" "github.com/cosmos/cosmos-sdk/codec" ) diff --git a/connect/internal/autocli/common_test.go b/connect/internal/autocli/common_test.go index bc857467..242213b9 100644 --- a/connect/internal/autocli/common_test.go +++ b/connect/internal/autocli/common_test.go @@ -15,7 +15,7 @@ import ( autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" reflectionv2alpha1 "cosmossdk.io/api/cosmos/base/reflection/v2alpha1" "github.com/ignite/apps/connect/internal/autocli/flag" - "github.com/ignite/apps/connect/internal/internal/testpb" + "github.com/ignite/apps/connect/internal/testpb" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" diff --git a/connect/internal/autocli/config/config.go b/connect/internal/autocli/config/config.go index 91b93988..a3349cbc 100644 --- a/connect/internal/autocli/config/config.go +++ b/connect/internal/autocli/config/config.go @@ -12,7 +12,7 @@ import ( "github.com/spf13/pflag" "github.com/spf13/viper" - "github.com/ignite/apps/connect/internal/internal/flags" + "github.com/ignite/apps/connect/internal/flags" ) type Config struct { diff --git a/connect/internal/autocli/flag/builder.go b/connect/internal/autocli/flag/builder.go index 4109ef60..b2e254d7 100644 --- a/connect/internal/autocli/flag/builder.go +++ b/connect/internal/autocli/flag/builder.go @@ -18,8 +18,8 @@ import ( autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" msgv1 "cosmossdk.io/api/cosmos/msg/v1" "cosmossdk.io/core/address" - "github.com/ignite/apps/connect/internal/internal/flags" - "github.com/ignite/apps/connect/internal/internal/util" + "github.com/ignite/apps/connect/internal/flags" + "github.com/ignite/apps/connect/internal/util" ) const ( diff --git a/connect/internal/autocli/flag/coin.go b/connect/internal/autocli/flag/coin.go index 28a6230a..8db9c3f9 100644 --- a/connect/internal/autocli/flag/coin.go +++ b/connect/internal/autocli/flag/coin.go @@ -8,7 +8,7 @@ import ( "google.golang.org/protobuf/reflect/protoreflect" basev1beta1 "cosmossdk.io/api/cosmos/base/v1beta1" - "github.com/ignite/apps/connect/internal/internal/coins" + "github.com/ignite/apps/connect/internal/coins" ) type coinType struct{} diff --git a/connect/internal/autocli/flag/dec_coin.go b/connect/internal/autocli/flag/dec_coin.go index 6672bad9..8ed1b566 100644 --- a/connect/internal/autocli/flag/dec_coin.go +++ b/connect/internal/autocli/flag/dec_coin.go @@ -8,7 +8,7 @@ import ( "google.golang.org/protobuf/reflect/protoreflect" basev1beta1 "cosmossdk.io/api/cosmos/base/v1beta1" - "github.com/ignite/apps/connect/internal/internal/coins" + "github.com/ignite/apps/connect/internal/coins" ) type decCoinType struct{} diff --git a/connect/internal/autocli/flag/enum.go b/connect/internal/autocli/flag/enum.go index 0346b344..15017b1f 100644 --- a/connect/internal/autocli/flag/enum.go +++ b/connect/internal/autocli/flag/enum.go @@ -7,7 +7,7 @@ import ( "google.golang.org/protobuf/reflect/protoreflect" - "github.com/ignite/apps/connect/internal/internal/strcase" + "github.com/ignite/apps/connect/internal/strcase" ) type enumType struct { diff --git a/connect/internal/autocli/flag/json_message.go b/connect/internal/autocli/flag/json_message.go index 7a2df5dd..426dafb7 100644 --- a/connect/internal/autocli/flag/json_message.go +++ b/connect/internal/autocli/flag/json_message.go @@ -11,7 +11,7 @@ import ( "google.golang.org/protobuf/proto" "google.golang.org/protobuf/reflect/protoreflect" - "github.com/ignite/apps/connect/internal/internal/util" + "github.com/ignite/apps/connect/internal/util" ) var isJSONFileRegex = regexp.MustCompile(`\.json$`) diff --git a/connect/internal/autocli/msg.go b/connect/internal/autocli/msg.go index 85538f60..310c8a9c 100644 --- a/connect/internal/autocli/msg.go +++ b/connect/internal/autocli/msg.go @@ -12,9 +12,9 @@ import ( autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" addresscodec "cosmossdk.io/core/address" "github.com/ignite/apps/connect/internal/autocli/flag" - "github.com/ignite/apps/connect/internal/internal/flags" - "github.com/ignite/apps/connect/internal/internal/governance" - "github.com/ignite/apps/connect/internal/internal/util" + "github.com/ignite/apps/connect/internal/flags" + "github.com/ignite/apps/connect/internal/governance" + "github.com/ignite/apps/connect/internal/util" "github.com/cosmos/cosmos-sdk/client" clienttx "github.com/cosmos/cosmos-sdk/client/tx" diff --git a/connect/internal/autocli/msg_test.go b/connect/internal/autocli/msg_test.go index 83a92109..fb44ae6e 100644 --- a/connect/internal/autocli/msg_test.go +++ b/connect/internal/autocli/msg_test.go @@ -15,7 +15,7 @@ import ( autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" bankv1beta1 "cosmossdk.io/api/cosmos/bank/v1beta1" - "github.com/ignite/apps/connect/internal/internal/testpb" + "github.com/ignite/apps/connect/internal/testpb" "github.com/cosmos/cosmos-sdk/client" ) diff --git a/connect/internal/autocli/prompt/message_test.go b/connect/internal/autocli/prompt/message_test.go index 0d844e84..b3886845 100644 --- a/connect/internal/autocli/prompt/message_test.go +++ b/connect/internal/autocli/prompt/message_test.go @@ -8,7 +8,7 @@ import ( "github.com/stretchr/testify/require" "google.golang.org/protobuf/reflect/protoreflect" - "github.com/ignite/apps/connect/internal/internal/testpb" + "github.com/ignite/apps/connect/internal/testpb" address2 "github.com/cosmos/cosmos-sdk/codec/address" ) diff --git a/connect/internal/autocli/query.go b/connect/internal/autocli/query.go index 78e6a061..39e93308 100644 --- a/connect/internal/autocli/query.go +++ b/connect/internal/autocli/query.go @@ -15,8 +15,8 @@ import ( autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" "cosmossdk.io/math" "cosmossdk.io/x/tx/signing/aminojson" - "github.com/ignite/apps/connect/internal/internal/flags" - "github.com/ignite/apps/connect/internal/internal/util" + "github.com/ignite/apps/connect/internal/flags" + "github.com/ignite/apps/connect/internal/util" sdk "github.com/cosmos/cosmos-sdk/types" ) diff --git a/connect/internal/autocli/query_test.go b/connect/internal/autocli/query_test.go index cfd0be95..d8f24c24 100644 --- a/connect/internal/autocli/query_test.go +++ b/connect/internal/autocli/query_test.go @@ -18,7 +18,7 @@ import ( autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" queryv1beta1 "cosmossdk.io/api/cosmos/base/query/v1beta1" basev1beta1 "cosmossdk.io/api/cosmos/base/v1beta1" - "github.com/ignite/apps/connect/internal/internal/testpb" + "github.com/ignite/apps/connect/internal/testpb" "github.com/cosmos/cosmos-sdk/client" ) diff --git a/connect/internal/autocli/util.go b/connect/internal/autocli/util.go index 0343e870..e04ee080 100644 --- a/connect/internal/autocli/util.go +++ b/connect/internal/autocli/util.go @@ -7,7 +7,7 @@ import ( "github.com/spf13/cobra" "google.golang.org/protobuf/reflect/protoreflect" - "github.com/ignite/apps/connect/internal/internal/strcase" + "github.com/ignite/apps/connect/internal/strcase" ) // findSubCommand finds a sub-command of the provided command whose Use diff --git a/connect/internal/internal/buf.gen.gogo.yaml b/connect/internal/buf.gen.gogo.yaml similarity index 100% rename from connect/internal/internal/buf.gen.gogo.yaml rename to connect/internal/buf.gen.gogo.yaml diff --git a/connect/internal/internal/buf.gen.pulsar.yaml b/connect/internal/buf.gen.pulsar.yaml similarity index 83% rename from connect/internal/internal/buf.gen.pulsar.yaml rename to connect/internal/buf.gen.pulsar.yaml index 48859547..d27cab62 100644 --- a/connect/internal/internal/buf.gen.pulsar.yaml +++ b/connect/internal/buf.gen.pulsar.yaml @@ -2,7 +2,7 @@ version: v1 managed: enabled: true go_package_prefix: - default: github.com/cosmos/cosmos-sdk/client/v2/internal + default: github.com/ignite/apps/connect/internal except: - buf.build/cosmos/cosmos-proto override: diff --git a/connect/internal/internal/buf.lock b/connect/internal/buf.lock similarity index 100% rename from connect/internal/internal/buf.lock rename to connect/internal/buf.lock diff --git a/connect/internal/internal/buf.yaml b/connect/internal/buf.yaml similarity index 100% rename from connect/internal/internal/buf.yaml rename to connect/internal/buf.yaml diff --git a/connect/internal/internal/coins/format.go b/connect/internal/coins/format.go similarity index 100% rename from connect/internal/internal/coins/format.go rename to connect/internal/coins/format.go diff --git a/connect/internal/internal/coins/format_test.go b/connect/internal/coins/format_test.go similarity index 100% rename from connect/internal/internal/coins/format_test.go rename to connect/internal/coins/format_test.go diff --git a/connect/internal/internal/coins/util.go b/connect/internal/coins/util.go similarity index 100% rename from connect/internal/internal/coins/util.go rename to connect/internal/coins/util.go diff --git a/connect/internal/internal/coins/util_test.go b/connect/internal/coins/util_test.go similarity index 100% rename from connect/internal/internal/coins/util_test.go rename to connect/internal/coins/util_test.go diff --git a/connect/internal/internal/flags/flags.go b/connect/internal/flags/flags.go similarity index 100% rename from connect/internal/internal/flags/flags.go rename to connect/internal/flags/flags.go diff --git a/connect/internal/internal/governance/gov.go b/connect/internal/governance/gov.go similarity index 97% rename from connect/internal/internal/governance/gov.go rename to connect/internal/governance/gov.go index 0edc0077..61472196 100644 --- a/connect/internal/internal/governance/gov.go +++ b/connect/internal/governance/gov.go @@ -10,7 +10,7 @@ import ( "google.golang.org/protobuf/types/known/anypb" govv1 "cosmossdk.io/api/cosmos/gov/v1" - "github.com/ignite/apps/connect/internal/internal/coins" + "github.com/ignite/apps/connect/internal/coins" ) const ( diff --git a/connect/internal/helpers/home.go b/connect/internal/helpers/home.go deleted file mode 100644 index af3fc288..00000000 --- a/connect/internal/helpers/home.go +++ /dev/null @@ -1,48 +0,0 @@ -package helpers - -import ( - "os" - "path/filepath" - "strings" -) - -// EnvPrefix is the prefix for environment variables that are used by the CLI. -// It should match the one used for viper in the CLI. -var EnvPrefix = "" - -// GetNodeHomeDirectory gets the home directory of the node (where the config is located). -// It parses the home flag if set if the `(PREFIX)_HOME` environment variable if set (and ignores name). -// When no prefix is set, it reads the `NODE_HOME` environment variable. -// Otherwise, it returns the default home directory given its name. -func GetNodeHomeDirectory(name string) (string, error) { - // get the home directory from the flag - args := os.Args - for i := 0; i < len(args); i++ { - if args[i] == "--home" && i+1 < len(args) { - return filepath.Clean(args[i+1]), nil - } else if strings.HasPrefix(args[i], "--home=") { - return filepath.Clean(args[i][7:]), nil - } - } - - // get the home directory from the environment variable - // to not clash with the $HOME system variable, when no prefix is set - // we check the NODE_HOME environment variable - homeDir, envHome := "", "HOME" - if len(EnvPrefix) > 0 { - homeDir = os.Getenv(EnvPrefix + "_" + envHome) - } else { - homeDir = os.Getenv("NODE_" + envHome) - } - if homeDir != "" { - return filepath.Clean(homeDir), nil - } - - // get user home directory - userHomeDir, err := os.UserHomeDir() - if err != nil { - return "", err - } - - return filepath.Join(userHomeDir, name), nil -} diff --git a/connect/internal/internal/print/printer.go b/connect/internal/print/printer.go similarity index 96% rename from connect/internal/internal/print/printer.go rename to connect/internal/print/printer.go index 35b5bb2d..68ff3bff 100644 --- a/connect/internal/internal/print/printer.go +++ b/connect/internal/print/printer.go @@ -9,7 +9,7 @@ import ( "github.com/spf13/cobra" "sigs.k8s.io/yaml" - "github.com/ignite/apps/connect/internal/internal/flags" + "github.com/ignite/apps/connect/internal/flags" ) const ( diff --git a/connect/internal/internal/strcase/kebab.go b/connect/internal/strcase/kebab.go similarity index 100% rename from connect/internal/internal/strcase/kebab.go rename to connect/internal/strcase/kebab.go diff --git a/connect/internal/internal/strcase/kebab_test.go b/connect/internal/strcase/kebab_test.go similarity index 93% rename from connect/internal/internal/strcase/kebab_test.go rename to connect/internal/strcase/kebab_test.go index ba3fe1bc..3add7144 100644 --- a/connect/internal/internal/strcase/kebab_test.go +++ b/connect/internal/strcase/kebab_test.go @@ -5,7 +5,7 @@ import ( "gotest.tools/v3/assert" - "github.com/ignite/apps/connect/internal/internal/strcase" + "github.com/ignite/apps/connect/internal/strcase" ) func toKebab(tb testing.TB) { diff --git a/connect/internal/internal/testpb/msg.proto b/connect/internal/testpb/msg.proto similarity index 100% rename from connect/internal/internal/testpb/msg.proto rename to connect/internal/testpb/msg.proto diff --git a/connect/internal/internal/testpb/msg.pulsar.go b/connect/internal/testpb/msg.pulsar.go similarity index 100% rename from connect/internal/internal/testpb/msg.pulsar.go rename to connect/internal/testpb/msg.pulsar.go diff --git a/connect/internal/internal/testpb/msg_grpc.pb.go b/connect/internal/testpb/msg_grpc.pb.go similarity index 100% rename from connect/internal/internal/testpb/msg_grpc.pb.go rename to connect/internal/testpb/msg_grpc.pb.go diff --git a/connect/internal/internal/testpb/query.proto b/connect/internal/testpb/query.proto similarity index 100% rename from connect/internal/internal/testpb/query.proto rename to connect/internal/testpb/query.proto diff --git a/connect/internal/internal/testpb/query.pulsar.go b/connect/internal/testpb/query.pulsar.go similarity index 100% rename from connect/internal/internal/testpb/query.pulsar.go rename to connect/internal/testpb/query.pulsar.go diff --git a/connect/internal/internal/testpb/query_grpc.pb.go b/connect/internal/testpb/query_grpc.pb.go similarity index 100% rename from connect/internal/internal/testpb/query_grpc.pb.go rename to connect/internal/testpb/query_grpc.pb.go diff --git a/connect/internal/internal/util/util.go b/connect/internal/util/util.go similarity index 98% rename from connect/internal/internal/util/util.go rename to connect/internal/util/util.go index e478c577..9bb3c467 100644 --- a/connect/internal/internal/util/util.go +++ b/connect/internal/util/util.go @@ -11,7 +11,7 @@ import ( "google.golang.org/protobuf/reflect/protoregistry" "google.golang.org/protobuf/types/dynamicpb" - "github.com/ignite/apps/connect/internal/internal/strcase" + "github.com/ignite/apps/connect/internal/strcase" ) // get build info to verify later if comment is supported diff --git a/connect/internal/internal/util/util_test.go b/connect/internal/util/util_test.go similarity index 97% rename from connect/internal/internal/util/util_test.go rename to connect/internal/util/util_test.go index 89fdb994..76c6b720 100644 --- a/connect/internal/internal/util/util_test.go +++ b/connect/internal/util/util_test.go @@ -7,7 +7,7 @@ import ( "google.golang.org/protobuf/reflect/protoreflect" "google.golang.org/protobuf/reflect/protoregistry" - _ "github.com/ignite/apps/connect/internal/internal/testpb" + _ "github.com/ignite/apps/connect/internal/testpb" ) func TestIsSupportedVersion(t *testing.T) { From a871064b01e62a3e8911cd2a39da37ca56b4b652 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Mon, 17 Feb 2025 23:36:01 +0100 Subject: [PATCH 04/17] cl --- rollkit/CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/rollkit/CHANGELOG.md b/rollkit/CHANGELOG.md index 0a5ed21c..e4928d74 100644 --- a/rollkit/CHANGELOG.md +++ b/rollkit/CHANGELOG.md @@ -2,6 +2,9 @@ ## Unreleased +## [`v0.2.2`](https://github.com/ignite/apps/releases/tag/rollkit/v0.2.2) + +* [#168](https://github.com/ignite/apps/pull/168) Update expected template. * [#112](https://github.com/ignite/apps/pull/112) Use default command instead cobra commands. ## [`v0.2.1`](https://github.com/ignite/apps/releases/tag/rollkit/v0.2.1) From 7c47660bbd25d9f72a91a596f1cc992c29be61c1 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 20 Feb 2025 15:42:32 +0100 Subject: [PATCH 05/17] fix unit tests --- connect/internal/autocli/testdata/flatten-output.golden | 2 +- connect/internal/autocli/testdata/help-echo-msg.golden | 5 ++--- connect/internal/autocli/testdata/msg-output.golden | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/connect/internal/autocli/testdata/flatten-output.golden b/connect/internal/autocli/testdata/flatten-output.golden index 7b19e08d..7df8be4c 100644 --- a/connect/internal/autocli/testdata/flatten-output.golden +++ b/connect/internal/autocli/testdata/flatten-output.golden @@ -1 +1 @@ -{"body":{"messages":[{"@type":"/cosmos.bank.v1beta1.MsgUpdateParams","authority":"cosmos1y74p8wyy4enfhfn342njve6cjmj5c8dtl6emdk","params":{"send_enabled":[{"denom":"stake","enabled":true}],"default_send_enabled":true}}],"memo":"","timeout_height":"0","unordered":false,"timeout_timestamp":null,"extension_options":[],"non_critical_extension_options":[]},"auth_info":{"signer_infos":[],"fee":{"amount":[],"gas_limit":"200000","payer":"","granter":""},"tip":null},"signatures":[]} +{"body":{"messages":[{"@type":"/cosmos.bank.v1beta1.MsgUpdateParams","authority":"cosmos1y74p8wyy4enfhfn342njve6cjmj5c8dtl6emdk","params":{"send_enabled":[{"denom":"stake","enabled":true}],"default_send_enabled":true}}],"memo":"","timeout_height":"0","extension_options":[],"non_critical_extension_options":[]},"auth_info":{"signer_infos":[],"fee":{"amount":[],"gas_limit":"200000","payer":"","granter":""},"tip":null},"signatures":[]} diff --git a/connect/internal/autocli/testdata/help-echo-msg.golden b/connect/internal/autocli/testdata/help-echo-msg.golden index 0761494e..12420587 100644 --- a/connect/internal/autocli/testdata/help-echo-msg.golden +++ b/connect/internal/autocli/testdata/help-echo-msg.golden @@ -15,7 +15,7 @@ Flags: --from string Name or address of private key with which to sign --gas string gas limit to set per-transaction; set to "auto" to calculate sufficient gas automatically. Note: "auto" option doesn't always report accurate results. Set a valid coin value to adjust the result. Can be used instead of "fees". (default 200000) --gas-adjustment float adjustment factor to be multiplied against the estimate returned by the tx simulation; if the gas limit is set manually this flag is ignored (default 1) - --gas-prices string Determine the transaction fee by multiplying max gas units by gas prices (e.g. 0.1uatom), rounding up to nearest denom unit + --gas-prices string Gas prices in decimal format to determine the transaction fee (e.g. 0.1uatom) --generate-only Build an unsigned transaction and write it to STDOUT (when enabled, the local Keybase only accessed when providing a key name) -h, --help help for send --home string home directory @@ -28,7 +28,6 @@ Flags: -o, --output string Output format (text|json) (default "json") -s, --sequence uint The sequence number of the signing account (offline mode only) --sign-mode string Choose sign mode (direct|amino-json|direct-aux|textual), this is an advanced feature - --timeout-timestamp int Set a block timeout timestamp to prevent the tx from being committed past a certain time + --timeout-height uint Set a block timeout height to prevent the tx from being committed past a certain height --tip string Tip is the amount that is going to be transferred to the fee payer on the target chain. This flag is only valid when used with --aux, and is ignored if the target chain didn't enable the TipDecorator - --unordered Enable unordered transaction delivery; must be used in conjunction with --timeout-timestamp -y, --yes Skip tx broadcasting prompt confirmation diff --git a/connect/internal/autocli/testdata/msg-output.golden b/connect/internal/autocli/testdata/msg-output.golden index 0e171b2b..07eb3d6b 100644 --- a/connect/internal/autocli/testdata/msg-output.golden +++ b/connect/internal/autocli/testdata/msg-output.golden @@ -1 +1 @@ -{"body":{"messages":[{"@type":"/cosmos.bank.v1beta1.MsgSend","from_address":"cosmos1y74p8wyy4enfhfn342njve6cjmj5c8dtl6emdk","to_address":"cosmos1y74p8wyy4enfhfn342njve6cjmj5c8dtl6emdk","amount":[{"denom":"foo","amount":"1"}]}],"memo":"","timeout_height":"0","unordered":false,"timeout_timestamp":null,"extension_options":[],"non_critical_extension_options":[]},"auth_info":{"signer_infos":[],"fee":{"amount":[],"gas_limit":"200000","payer":"","granter":""},"tip":null},"signatures":[]} \ No newline at end of file +{"body":{"messages":[{"@type":"/cosmos.bank.v1beta1.MsgSend","from_address":"cosmos1y74p8wyy4enfhfn342njve6cjmj5c8dtl6emdk","to_address":"cosmos1y74p8wyy4enfhfn342njve6cjmj5c8dtl6emdk","amount":[{"denom":"foo","amount":"1"}]}],"memo":"","timeout_height":"0","extension_options":[],"non_critical_extension_options":[]},"auth_info":{"signer_infos":[],"fee":{"amount":[],"gas_limit":"200000","payer":"","granter":""},"tip":null},"signatures":[]} \ No newline at end of file From 2232d2096daf6d59d489f76bb958d16c4505fa2a Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 20 Feb 2025 22:52:53 +0100 Subject: [PATCH 06/17] simplify --- connect/cmd/app.go | 17 +-- connect/go.mod | 6 +- connect/internal/account/retriever.go | 116 -------------- connect/internal/autocli/app.go | 159 +++++--------------- connect/internal/autocli/builder.go | 34 ----- connect/internal/autocli/common.go | 126 ++-------------- connect/internal/autocli/common_test.go | 48 ++---- connect/internal/autocli/config/config.go | 133 ---------------- connect/internal/autocli/flag/address.go | 14 +- connect/internal/autocli/flag/builder.go | 5 +- connect/internal/autocli/interface.go | 32 ---- connect/internal/autocli/keyring/keyring.go | 42 +++--- connect/internal/autocli/msg.go | 8 +- connect/internal/autocli/msg_test.go | 25 --- connect/internal/autocli/query.go | 8 +- connect/internal/autocli/query_test.go | 23 --- connect/internal/context/context.go | 55 ------- 17 files changed, 109 insertions(+), 742 deletions(-) delete mode 100644 connect/internal/account/retriever.go delete mode 100644 connect/internal/autocli/builder.go delete mode 100644 connect/internal/autocli/config/config.go delete mode 100644 connect/internal/autocli/interface.go delete mode 100644 connect/internal/context/context.go diff --git a/connect/cmd/app.go b/connect/cmd/app.go index 665f348c..612f9c27 100644 --- a/connect/cmd/app.go +++ b/connect/cmd/app.go @@ -35,14 +35,6 @@ func AppHandler(ctx context.Context, name string, cfg *chains.ChainConfig, args return nil, err } - // add comet commands - cometCmds := cmtservice.NewCometBFTCommands() - conn.ModuleOptions[cometCmds.Name()] = cometCmds.AutoCLIOptions() - - appOpts := autocli.AppOptions{ - ModuleOptions: conn.ModuleOptions, - } - builder := &autocli.Builder{ Builder: flag.Builder{ TypeResolver: &dynamicTypeResolver{conn}, @@ -51,6 +43,7 @@ func AppHandler(ctx context.Context, name string, cfg *chains.ChainConfig, args ValidatorAddressCodec: addresscodec.NewBech32Codec(fmt.Sprintf("%svaloper", cfg.Bech32Prefix)), ConsensusAddressCodec: addresscodec.NewBech32Codec(fmt.Sprintf("%svalcons", cfg.Bech32Prefix)), }, + Config: cfg, GetClientConn: func(command *cobra.Command) (grpc.ClientConnInterface, error) { return conn.Connect() }, @@ -64,7 +57,13 @@ func AppHandler(ctx context.Context, name string, cfg *chains.ChainConfig, args // add client context clientCtx := client.Context{} chainCmd.SetContext(context.WithValue(context.Background(), client.ClientContextKey, &clientCtx)) - if err := appOpts.EnhanceRootCommandWithBuilder(chainCmd, builder); err != nil { + + // add comet commands + cometCmds := cmtservice.NewCometBFTCommands() + conn.ModuleOptions[cometCmds.Name()] = cometCmds.AutoCLIOptions() + + // add autocli commands + if err := autocli.EnhanceRootCommand(chainCmd, builder, conn.ModuleOptions); err != nil { return nil, err } diff --git a/connect/go.mod b/connect/go.mod index 43199ab5..c2640e69 100644 --- a/connect/go.mod +++ b/connect/go.mod @@ -5,7 +5,6 @@ go 1.23.0 require ( cosmossdk.io/api v0.7.6 cosmossdk.io/core v0.11.1 - cosmossdk.io/depinject v1.1.0 cosmossdk.io/errors v1.0.1 cosmossdk.io/math v1.4.0 cosmossdk.io/x/tx v0.13.8 @@ -18,10 +17,8 @@ require ( github.com/hashicorp/go-plugin v1.6.1 github.com/ignite/cli/v28 v28.7.1-0.20250116085640-fcf01a4e4b39 github.com/manifoldco/promptui v0.9.0 - github.com/pelletier/go-toml/v2 v2.2.2 github.com/spf13/cobra v1.8.1 github.com/spf13/pflag v1.0.5 - github.com/spf13/viper v1.19.0 github.com/stretchr/testify v1.10.0 go.uber.org/mock v0.5.0 google.golang.org/grpc v1.67.1 @@ -33,6 +30,7 @@ require ( require ( cosmossdk.io/collections v0.4.0 // indirect + cosmossdk.io/depinject v1.1.0 // indirect cosmossdk.io/log v1.4.1 // indirect cosmossdk.io/store v1.1.1 // indirect dario.cat/mergo v1.0.0 // indirect @@ -164,6 +162,7 @@ require ( github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/oasisprotocol/curve25519-voi v0.0.0-20230904125328-1f23a7beb09a // indirect github.com/oklog/run v1.1.0 // indirect + github.com/pelletier/go-toml/v2 v2.2.2 // indirect github.com/petermattis/goid v0.0.0-20240813172612-4fcff4a6cae7 // indirect github.com/pjbgf/sha1cd v0.3.0 // indirect github.com/pkg/errors v0.9.1 // indirect @@ -188,6 +187,7 @@ require ( github.com/sourcegraph/syntaxhighlight v0.0.0-20170531221838-bd320f5d308e // indirect github.com/spf13/afero v1.11.0 // indirect github.com/spf13/cast v1.7.0 // indirect + github.com/spf13/viper v1.19.0 // indirect github.com/subosito/gotenv v1.6.0 // indirect github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d // indirect github.com/tendermint/go-amino v0.16.0 // indirect diff --git a/connect/internal/account/retriever.go b/connect/internal/account/retriever.go deleted file mode 100644 index 2cef69f9..00000000 --- a/connect/internal/account/retriever.go +++ /dev/null @@ -1,116 +0,0 @@ -package account - -import ( - "context" - "fmt" - "strconv" - - gogogrpc "github.com/cosmos/gogoproto/grpc" - "google.golang.org/grpc" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/metadata" - "google.golang.org/grpc/status" - - "cosmossdk.io/core/address" - - codectypes "github.com/cosmos/cosmos-sdk/codec/types" - cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" - sdk "github.com/cosmos/cosmos-sdk/types" - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" -) - -// GRPCBlockHeightHeader represents the gRPC header for block height. -const GRPCBlockHeightHeader = "x-cosmos-block-height" - -var _ AccountRetriever = accountRetriever{} - -// Account provides a read-only abstraction over the auth module's AccountI. -type Account interface { - GetAddress() sdk.AccAddress - GetPubKey() cryptotypes.PubKey // can return nil. - GetAccountNumber() uint64 - GetSequence() uint64 -} - -// AccountRetriever defines methods required to retrieve account details necessary for transaction signing. -type AccountRetriever interface { - GetAccount(context.Context, []byte) (Account, error) - GetAccountWithHeight(context.Context, []byte) (Account, int64, error) - EnsureExists(context.Context, []byte) error - GetAccountNumberSequence(context.Context, []byte) (accNum, accSeq uint64, err error) -} - -type accountRetriever struct { - ac address.Codec - conn gogogrpc.ClientConn - registry codectypes.InterfaceRegistry -} - -// NewAccountRetriever creates a new instance of accountRetriever. -func NewAccountRetriever(ac address.Codec, conn gogogrpc.ClientConn, registry codectypes.InterfaceRegistry) *accountRetriever { - return &accountRetriever{ - ac: ac, - conn: conn, - registry: registry, - } -} - -// GetAccount retrieves an account using its address. -func (a accountRetriever) GetAccount(ctx context.Context, addr []byte) (Account, error) { - acc, _, err := a.GetAccountWithHeight(ctx, addr) - return acc, err -} - -// GetAccountWithHeight retrieves an account and its associated block height using the account's address. -func (a accountRetriever) GetAccountWithHeight(ctx context.Context, addr []byte) (Account, int64, error) { - var header metadata.MD - qc := authtypes.NewQueryClient(a.conn) - - addrStr, err := a.ac.BytesToString(addr) - if err != nil { - return nil, 0, err - } - - res, err := qc.Account(ctx, &authtypes.QueryAccountRequest{Address: addrStr}, grpc.Header(&header)) - if err != nil { - return nil, 0, err - } - - blockHeight := header.Get(GRPCBlockHeightHeader) - if len(blockHeight) != 1 { - return nil, 0, fmt.Errorf("unexpected '%s' header length; got %d, expected 1", GRPCBlockHeightHeader, len(blockHeight)) - } - - nBlockHeight, err := strconv.Atoi(blockHeight[0]) - if err != nil { - return nil, 0, fmt.Errorf("failed to parse block height: %w", err) - } - - var acc Account - if err := a.registry.UnpackAny(res.Account, &acc); err != nil { - return nil, 0, err - } - - return acc, int64(nBlockHeight), nil -} - -// EnsureExists checks if an account exists using its address. -func (a accountRetriever) EnsureExists(ctx context.Context, addr []byte) error { - if _, err := a.GetAccount(ctx, addr); err != nil { - return err - } - return nil -} - -// GetAccountNumberSequence retrieves the account number and sequence for an account using its address. -func (a accountRetriever) GetAccountNumberSequence(ctx context.Context, addr []byte) (accNum, accSeq uint64, err error) { - acc, err := a.GetAccount(ctx, addr) - if err != nil { - if status.Code(err) == codes.NotFound { - return 0, 0, nil - } - return 0, 0, err - } - - return acc.GetAccountNumber(), acc.GetSequence(), nil -} diff --git a/connect/internal/autocli/app.go b/connect/internal/autocli/app.go index 297a52b4..b7b5701f 100644 --- a/connect/internal/autocli/app.go +++ b/connect/internal/autocli/app.go @@ -1,148 +1,61 @@ package autocli import ( + "github.com/cosmos/cosmos-sdk/codec" + "github.com/ignite/apps/connect/chains" + "github.com/ignite/apps/connect/internal/autocli/flag" "github.com/spf13/cobra" - "google.golang.org/protobuf/reflect/protoregistry" + "google.golang.org/grpc" autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" - apisigning "cosmossdk.io/api/cosmos/tx/signing/v1beta1" - "cosmossdk.io/core/address" - "cosmossdk.io/core/appmodule" - "cosmossdk.io/depinject" - "github.com/ignite/apps/connect/internal/autocli/flag" - - sdkflags "github.com/cosmos/cosmos-sdk/client/flags" - "github.com/cosmos/cosmos-sdk/codec" - authtx "github.com/cosmos/cosmos-sdk/x/auth/tx" ) -// AppOptions are input options for an autocli enabled app. These options can be built via depinject based on an app config. -// Ex: -// -// var autoCliOpts autocli.AppOptions -// err := depinject.Inject(appConfig, &encodingConfig.InterfaceRegistry, &autoCliOpts) -// -// If depinject isn't used, options can be provided manually or extracted from modules and the address codec can be provided by the auth keeper. -// One method for extracting autocli options is via the github.com/cosmos/cosmos-sdk/runtime/services.ExtractAutoCLIOptions function. -type AppOptions struct { - depinject.In +// Builder manages options for building CLI commands. +type Builder struct { + // flag.Builder embeds the flag builder and its options. + flag.Builder - // Modules are the AppModule implementations for the modules in the app. - Modules map[string]appmodule.AppModule + // Config is the config of the chain from the connect app + Config *chains.ChainConfig - // ModuleOptions are autocli options to be used for modules instead of what - // is specified on the module's AppModule implementation. This allows an - // app to override module options if they are either not provided by a - // module or need to be improved. - ModuleOptions map[string]*autocliv1.ModuleOptions `optional:"true"` + // GetClientConn specifies how CLI commands will resolve a grpc.ClientConnInterface + // from a given context. + GetClientConn func(*cobra.Command) (grpc.ClientConnInterface, error) - AddressCodec address.Codec // AddressCodec is used to encode/decode account addresses. - ValidatorAddressCodec address.Codec // ValidatorAddressCodec is used to encode/decode validator addresses. - ConsensusAddressCodec address.Codec // ConsensusAddressCodec is used to encode/decode consensus addresses. + // AddQueryConnFlags adds flags to query commands + AddQueryConnFlags func(*cobra.Command) - // Cdc is the codec used for binary encoding/decoding of messages. - Cdc codec.Codec + // AddTxConnFlags adds flags to transaction commands + AddTxConnFlags func(*cobra.Command) - // TxConfigOpts contains options for configuring transaction handling. - TxConfigOpts authtx.ConfigOptions - - skipValidation bool + // Cdc is the codec to use for encoding and decoding messages. + Cdc codec.Codec } -// EnhanceRootCommand enhances the provided root command with autocli AppOptions, -// only adding missing commands and doesn't override commands already -// in the root command. This allows for the graceful integration of autocli with -// existing app CLI commands where autocli simply automatically adds things that -// weren't manually provided. It does take into account custom commands -// provided by modules with the HasCustomQueryCommand or HasCustomTxCommand extension interface. -// Example Usage: +// EnhanceRootCommand enhances the root command with the provided module options. // -// var autoCliOpts autocli.AppOptions -// err := depinject.Inject(appConfig, &autoCliOpts) -// if err != nil { -// panic(err) -// } -// rootCmd := initRootCmd() -// err = autoCliOpts.EnhanceRootCommand(rootCmd) -func (appOptions AppOptions) EnhanceRootCommand(rootCmd *cobra.Command) error { - // convert the API sign modes to internal sign modes - signModes := make([]apisigning.SignMode, len(appOptions.TxConfigOpts.EnabledSignModes)) - for i, mode := range appOptions.TxConfigOpts.EnabledSignModes { - signModes[i] = apisigning.SignMode(mode) +// ModuleOptions are autocli options to be used for modules. They are gotten from +// the reflection service. +func EnhanceRootCommand( + rootCmd *cobra.Command, + builder *Builder, + moduleOptions map[string]*autocliv1.ModuleOptions, +) error { + if err := builder.Validate(); err != nil { + return err } - builder := &Builder{ - Builder: flag.Builder{ - TypeResolver: protoregistry.GlobalTypes, - FileResolver: appOptions.Cdc.InterfaceRegistry(), - AddressCodec: appOptions.AddressCodec, - ValidatorAddressCodec: appOptions.ValidatorAddressCodec, - ConsensusAddressCodec: appOptions.ConsensusAddressCodec, - }, - GetClientConn: getQueryClientConn(appOptions.Cdc), - AddQueryConnFlags: func(c *cobra.Command) { - sdkflags.AddQueryFlagsToCmd(c) - sdkflags.AddKeyringFlags(c.Flags()) - }, - AddTxConnFlags: sdkflags.AddTxFlagsToCmd, - Cdc: appOptions.Cdc, - EnabledSignModes: signModes, + queryCmd, err := builder.BuildQueryCommand(rootCmd.Context(), moduleOptions) + if err != nil { + return err } - return appOptions.EnhanceRootCommandWithBuilder(rootCmd, builder) -} - -func (appOptions AppOptions) EnhanceRootCommandWithBuilder(rootCmd *cobra.Command, builder *Builder) error { - if !appOptions.skipValidation { - if err := builder.ValidateAndComplete(); err != nil { - return err - } + msgCmd, err := builder.BuildMsgCommand(rootCmd.Context(), moduleOptions) + if err != nil { + return err } - // extract any custom commands from modules - customQueryCmds, customMsgCmds := map[string]*cobra.Command{}, map[string]*cobra.Command{} - for name, module := range appOptions.Modules { - if queryModule, ok := module.(HasCustomQueryCommand); ok { - queryCmd := queryModule.GetQueryCmd() - // filter any nil commands - if queryCmd != nil { - customQueryCmds[name] = queryCmd - } - } - if msgModule, ok := module.(HasCustomTxCommand); ok { - msgCmd := msgModule.GetTxCmd() - // filter any nil commands - if msgCmd != nil { - customMsgCmds[name] = msgCmd - } - } - } - - if queryCmd := findSubCommand(rootCmd, "query"); queryCmd != nil { - if err := builder.enhanceCommandCommon(queryCmd, queryCmdType, appOptions, customQueryCmds); err != nil { - return err - } - } else { - queryCmd, err := builder.BuildQueryCommand(rootCmd.Context(), appOptions, customQueryCmds) - if err != nil { - return err - } - - rootCmd.AddCommand(queryCmd) - } - - if msgCmd := findSubCommand(rootCmd, "tx"); msgCmd != nil { - if err := builder.enhanceCommandCommon(msgCmd, msgCmdType, appOptions, customMsgCmds); err != nil { - return err - } - } else { - subCmd, err := builder.BuildMsgCommand(rootCmd.Context(), appOptions, customMsgCmds) - if err != nil { - return err - } - - rootCmd.AddCommand(subCmd) - } + rootCmd.AddCommand(queryCmd, msgCmd) return nil } diff --git a/connect/internal/autocli/builder.go b/connect/internal/autocli/builder.go deleted file mode 100644 index e6cc2768..00000000 --- a/connect/internal/autocli/builder.go +++ /dev/null @@ -1,34 +0,0 @@ -package autocli - -import ( - "github.com/spf13/cobra" - "google.golang.org/grpc" - - apisigning "cosmossdk.io/api/cosmos/tx/signing/v1beta1" - "github.com/ignite/apps/connect/internal/autocli/flag" - - "github.com/cosmos/cosmos-sdk/codec" -) - -// Builder manages options for building CLI commands. -type Builder struct { - // flag.Builder embeds the flag builder and its options. - flag.Builder - - // GetClientConn specifies how CLI commands will resolve a grpc.ClientConnInterface - // from a given context. - GetClientConn func(*cobra.Command) (grpc.ClientConnInterface, error) - - // AddQueryConnFlags and AddTxConnFlags are functions that add flags to query and transaction commands - AddQueryConnFlags func(*cobra.Command) - AddTxConnFlags func(*cobra.Command) - - Cdc codec.Codec - EnabledSignModes []apisigning.SignMode -} - -// ValidateAndComplete the builder fields. -// It returns an error if any of the required fields are missing. -func (b *Builder) ValidateAndComplete() error { - return b.Builder.ValidateAndComplete() -} diff --git a/connect/internal/autocli/common.go b/connect/internal/autocli/common.go index ce51c004..1d37fd99 100644 --- a/connect/internal/autocli/common.go +++ b/connect/internal/autocli/common.go @@ -2,26 +2,16 @@ package autocli import ( "context" - "crypto/tls" "fmt" - "strconv" "github.com/spf13/cobra" - "google.golang.org/grpc" - "google.golang.org/grpc/credentials" - grpcinsecure "google.golang.org/grpc/credentials/insecure" "google.golang.org/protobuf/reflect/protoreflect" autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" - "github.com/ignite/apps/connect/internal/autocli/config" "github.com/ignite/apps/connect/internal/autocli/keyring" - "github.com/ignite/apps/connect/internal/broadcast/comet" - clientcontext "github.com/ignite/apps/connect/internal/context" "github.com/ignite/apps/connect/internal/flags" "github.com/ignite/apps/connect/internal/print" "github.com/ignite/apps/connect/internal/util" - - "github.com/cosmos/cosmos-sdk/codec" ) type cmdType int @@ -121,22 +111,11 @@ func (b *Builder) buildMethodCommandCommon(descriptor protoreflect.MethodDescrip func (b *Builder) enhanceCommandCommon( cmd *cobra.Command, cmdType cmdType, - appOptions AppOptions, - customCmds map[string]*cobra.Command, + moduleOptions map[string]*autocliv1.ModuleOptions, ) error { - moduleOptions := appOptions.ModuleOptions if len(moduleOptions) == 0 { moduleOptions = make(map[string]*autocliv1.ModuleOptions) } - for name, module := range appOptions.Modules { - if _, ok := moduleOptions[name]; !ok { - if module, ok := module.(HasAutoCLIConfig); ok { - moduleOptions[name] = module.AutoCLIOptions() - } else { - moduleOptions[name] = nil - } - } - } for moduleName, modOpts := range moduleOptions { hasModuleOptions := modOpts != nil @@ -152,27 +131,6 @@ func (b *Builder) enhanceCommandCommon( continue } - // if we have a custom command use that instead of generating one - if custom, ok := customCmds[moduleName]; ok { - // Custom may not be called the same as its module, so we need to have a separate check here - if subCmd := findSubCommand(cmd, custom.Name()); subCmd != nil { - if hasModuleOptions { // check if we need to enhance the existing command - if err := enhanceCustomCmd(b, subCmd, cmdType, modOpts); err != nil { - return err - } - } - continue - } - if hasModuleOptions { // check if we need to enhance the new command - if err := enhanceCustomCmd(b, custom, cmdType, modOpts); err != nil { - return err - } - } - - cmd.AddCommand(custom) - continue - } - // if we don't have module options, skip adding a command as we don't have anything to add if !hasModuleOptions { continue @@ -266,26 +224,13 @@ func (b *Builder) getContext(cmd *cobra.Command) (context.Context, error) { k keyring.Keyring err error ) - if cmd.Flags().Lookup(flags.FlagKeyringDir) != nil && cmd.Flags().Lookup(flags.FlagKeyringBackend) != nil { - k, err = keyring.NewKeyringFromFlags(cmd.Flags(), b.AddressCodec, cmd.InOrStdin(), b.Cdc) - if err != nil { - return nil, err - } - } else { - k = keyring.NoKeyring{} - } - clientCtx := clientcontext.Context{ - Flags: cmd.Flags(), - AddressCodec: b.AddressCodec, - ValidatorAddressCodec: b.ValidatorAddressCodec, - ConsensusAddressCodec: b.ConsensusAddressCodec, - Cdc: b.Cdc, - Keyring: k, - EnabledSignModes: b.EnabledSignModes, + k, err = keyring.NewKeyringFromFlags(cmd.Flags(), b.AddressCodec, cmd.InOrStdin(), b.Cdc) + if err != nil { + return nil, err } - return clientcontext.SetInContext(cmd.Context(), clientCtx), nil + return context.WithValue(cmd.Context(), keyring.ContextKey, k), nil } // preRunE returns a function that sets flags from the configuration before running a command. @@ -305,20 +250,15 @@ func (b *Builder) preRunE() func(cmd *cobra.Command, args []string) error { // setFlagsFromConfig sets command flags from the provided configuration. // It only sets flags that haven't been explicitly changed by the user. func (b *Builder) setFlagsFromConfig(cmd *cobra.Command) error { - conf, err := config.CreateClientConfigFromFlags(cmd.Flags()) - if err != nil { - return err - } - flagsToSet := map[string]string{ - flags.FlagChainID: conf.ChainID, - flags.FlagKeyringBackend: conf.KeyringBackend, - flags.FlagFrom: conf.KeyringDefaultKeyName, - flags.FlagOutput: conf.Output, - flags.FlagNode: conf.Node, - flags.FlagBroadcastMode: conf.BroadcastMode, - flags.FlagGrpcAddress: conf.GRPC.Address, - flags.FlagGrpcInsecure: strconv.FormatBool(conf.GRPC.Insecure), + flags.FlagChainID: b.Config.ChainID, + // flags.FlagKeyringBackend: conf.KeyringBackend, + // flags.FlagFrom: conf.KeyringDefaultKeyName, + // flags.FlagOutput: conf.Output, + // flags.FlagNode: conf.Node, + // flags.FlagBroadcastMode: conf.BroadcastMode, + // flags.FlagGrpcAddress: conf.GRPC.Address, + // flags.FlagGrpcInsecure: strconv.FormatBool(conf.GRPC.Insecure), } for flagName, value := range flagsToSet { @@ -331,43 +271,3 @@ func (b *Builder) setFlagsFromConfig(cmd *cobra.Command) error { return nil } - -// getQueryClientConn returns a function that creates a gRPC client connection based on command flags. -// It handles the creation of secure or insecure connections and falls back to a CometBFT broadcaster -// if no gRPC address is specified. -func getQueryClientConn(cdc codec.Codec) func(cmd *cobra.Command) (grpc.ClientConnInterface, error) { - return func(cmd *cobra.Command) (grpc.ClientConnInterface, error) { - var err error - creds := grpcinsecure.NewCredentials() - - insecure := true - if cmd.Flags().Lookup(flags.FlagGrpcInsecure) != nil { - insecure, err = cmd.Flags().GetBool(flags.FlagGrpcInsecure) - if err != nil { - return nil, err - } - } - if !insecure { - creds = credentials.NewTLS(&tls.Config{MinVersion: tls.VersionTLS12}) - } - - var addr string - if cmd.Flags().Lookup(flags.FlagGrpcAddress) != nil { - addr, err = cmd.Flags().GetString(flags.FlagGrpcAddress) - if err != nil { - return nil, err - } - } - if addr == "" { - // if grpc-addr has not been set, use the default clientConn - // TODO: default is comet - node, err := cmd.Flags().GetString(flags.FlagNode) - if err != nil { - return nil, err - } - return comet.NewCometBFTBroadcaster(node, comet.BroadcastSync, cdc) - } - - return grpc.NewClient(addr, []grpc.DialOption{grpc.WithTransportCredentials(creds)}...) - } -} diff --git a/connect/internal/autocli/common_test.go b/connect/internal/autocli/common_test.go index 242213b9..1af0111a 100644 --- a/connect/internal/autocli/common_test.go +++ b/connect/internal/autocli/common_test.go @@ -88,7 +88,7 @@ func initFixture(t *testing.T) *fixture { AddTxConnFlags: addTxAndGlobalFlagsToCmd, Cdc: encodingConfig.Codec, } - assert.NilError(t, b.ValidateAndComplete()) + assert.NilError(t, b.Validate()) return &fixture{ conn: conn, @@ -165,33 +165,17 @@ func TestEnhanceCommand(t *testing.T) { for i := 0; i < 2; i++ { cmdTp := cmdType(i) - appOptions := AppOptions{ - ModuleOptions: map[string]*autocliv1.ModuleOptions{ - "test": {}, - }, - } - - err := b.enhanceCommandCommon(cmd, cmdTp, appOptions, map[string]*cobra.Command{}) - assert.NilError(t, err) - - cmd = &cobra.Command{Use: "test"} - - appOptions = AppOptions{ - ModuleOptions: map[string]*autocliv1.ModuleOptions{}, - } - customCommands := map[string]*cobra.Command{ - "test2": {Use: "test"}, + moduleOptions := map[string]*autocliv1.ModuleOptions{ + "test": {}, } - err = b.enhanceCommandCommon(cmd, cmdTp, appOptions, customCommands) + err := b.enhanceCommandCommon(cmd, cmdTp, moduleOptions) assert.NilError(t, err) cmd = &cobra.Command{Use: "test"} - appOptions = AppOptions{ - ModuleOptions: map[string]*autocliv1.ModuleOptions{ - "test": {Tx: nil}, - }, + moduleOptions = map[string]*autocliv1.ModuleOptions{ + "test": {Tx: nil}, } - err = b.enhanceCommandCommon(cmd, cmdTp, appOptions, map[string]*cobra.Command{}) + err = b.enhanceCommandCommon(cmd, cmdTp, moduleOptions) assert.NilError(t, err) } } @@ -216,20 +200,18 @@ func TestErrorBuildCommand(t *testing.T) { }, } - appOptions := AppOptions{ - ModuleOptions: map[string]*autocliv1.ModuleOptions{ - "test": { - Query: commandDescriptor, - Tx: commandDescriptor, - }, + moduleOptions := map[string]*autocliv1.ModuleOptions{ + "test": { + Query: commandDescriptor, + Tx: commandDescriptor, }, } - _, err := b.BuildMsgCommand(context.Background(), appOptions, nil) + _, err := b.BuildMsgCommand(context.Background(), moduleOptions) assert.ErrorContains(t, err, "can't find field un-existent-proto-field") - appOptions.ModuleOptions["test"].Tx = &autocliv1.ServiceCommandDescriptor{Service: "un-existent-service"} - appOptions.ModuleOptions["test"].Query = &autocliv1.ServiceCommandDescriptor{Service: "un-existent-service"} - _, err = b.BuildMsgCommand(context.Background(), appOptions, nil) + moduleOptions["test"].Tx = &autocliv1.ServiceCommandDescriptor{Service: "un-existent-service"} + moduleOptions["test"].Query = &autocliv1.ServiceCommandDescriptor{Service: "un-existent-service"} + _, err = b.BuildMsgCommand(context.Background(), moduleOptions) assert.ErrorContains(t, err, "can't find service un-existent-service") } diff --git a/connect/internal/autocli/config/config.go b/connect/internal/autocli/config/config.go deleted file mode 100644 index a3349cbc..00000000 --- a/connect/internal/autocli/config/config.go +++ /dev/null @@ -1,133 +0,0 @@ -package config - -import ( - "errors" - "fmt" - "os" - "path" - "path/filepath" - "strings" - - "github.com/pelletier/go-toml/v2" - "github.com/spf13/pflag" - "github.com/spf13/viper" - - "github.com/ignite/apps/connect/internal/flags" -) - -type Config struct { - ChainID string `mapstructure:"chain-id" toml:"chain-id" comment:"The chain ID of the blockchain network"` - KeyringBackend string `mapstructure:"keyring-backend" toml:"keyring-backend" comment:"The keyring backend to use (os|file|kwallet|pass|test|memory)"` - KeyringDefaultKeyName string `mapstructure:"keyring-default-keyname" toml:"keyring-default-keyname" comment:"The default key name to use for signing transactions"` - Output string `mapstructure:"output" toml:"output" comment:"The output format for queries (text|json)"` - Node string `mapstructure:"node" toml:"node" comment:"The RPC endpoint URL for the node to connect to"` - BroadcastMode string `mapstructure:"broadcast-mode" toml:"broadcast-mode" comment:"How transactions are broadcast to the network (sync|async|block)"` - GRPC GRPCConfig `mapstructure:",squash" comment:"The gRPC client configuration"` -} - -// GRPCConfig holds the gRPC client configuration. -type GRPCConfig struct { - Address string `mapstructure:"grpc-address" toml:"grpc-address" comment:"The gRPC server address to connect to"` - Insecure bool `mapstructure:"grpc-insecure" toml:"grpc-insecure" comment:"Allow gRPC over insecure connections"` -} - -func DefaultConfig() *Config { - return &Config{ - ChainID: "", - KeyringBackend: "os", - KeyringDefaultKeyName: "", - Output: "text", - Node: "tcp://localhost:26657", - BroadcastMode: "sync", - } -} - -// CreateClientConfig creates a new client configuration or reads an existing one. -func CreateClientConfig(homeDir, chainID string, v *viper.Viper) (*Config, error) { - if homeDir == "" { - return nil, errors.New("home dir can't be empty") - } - - configPath := filepath.Join(homeDir, "config") - configFilePath := filepath.Join(configPath, "client.toml") - - // when client.toml does not exist create and init with default values - if _, err := os.Stat(configFilePath); os.IsNotExist(err) { - if err := os.MkdirAll(configPath, os.ModePerm); err != nil { - return nil, fmt.Errorf("couldn't make client config: %w", err) - } - - conf := DefaultConfig() - if chainID != "" { - // chain-id will be written to the client.toml while initiating the chain. - conf.ChainID = chainID - } - - if err := writeConfigFile(configFilePath, conf); err != nil { - return nil, fmt.Errorf("could not write client config to the file: %w", err) - } - } - - conf, err := readConfig(configPath, v) - if err != nil { - return nil, fmt.Errorf("couldn't get client config: %w", err) - } - - return conf, nil -} - -// CreateClientConfigFromFlags creates a client configuration from command-line flags. -func CreateClientConfigFromFlags(set *pflag.FlagSet) (*Config, error) { - homeDir, _ := set.GetString(flags.FlagHome) - if homeDir == "" { - return DefaultConfig(), nil - } - chainID, _ := set.GetString(flags.FlagChainID) - - v := viper.New() - executableName, err := os.Executable() - if err != nil { - return nil, err - } - - v.SetEnvPrefix(path.Base(executableName)) - v.SetEnvKeyReplacer(strings.NewReplacer(".", "_", "-", "_")) - v.AutomaticEnv() - - return CreateClientConfig(homeDir, chainID, v) -} - -// writeConfigFile renders config using the template and writes it to -// configFilePath. -func writeConfigFile(configFilePath string, config *Config) error { - b, err := toml.Marshal(config) - if err != nil { - return err - } - - if dir := filepath.Dir(configFilePath); dir != "" { - if err := os.MkdirAll(dir, os.ModePerm); err != nil { - return err - } - } - - return os.WriteFile(configFilePath, b, 0o600) -} - -// readConfig reads values from client.toml file and unmarshals them into ClientConfig -func readConfig(configPath string, v *viper.Viper) (*Config, error) { - v.AddConfigPath(configPath) - v.SetConfigName("client") - v.SetConfigType("toml") - - if err := v.ReadInConfig(); err != nil { - return nil, err - } - - conf := DefaultConfig() - if err := v.Unmarshal(conf); err != nil { - return nil, err - } - - return conf, nil -} diff --git a/connect/internal/autocli/flag/address.go b/connect/internal/autocli/flag/address.go index 415159d6..549f5f50 100644 --- a/connect/internal/autocli/flag/address.go +++ b/connect/internal/autocli/flag/address.go @@ -2,13 +2,13 @@ package flag import ( "context" + "errors" "fmt" "google.golang.org/protobuf/reflect/protoreflect" "cosmossdk.io/core/address" "github.com/ignite/apps/connect/internal/autocli/keyring" - clientcontext "github.com/ignite/apps/connect/internal/context" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/types" @@ -154,10 +154,14 @@ func getKeyringFromCtx(ctx *context.Context) keyring.Keyring { return keyring.NoKeyring{} } - c, err := clientcontext.ClientContextFromGoContext(*ctx) - if err != nil { - return keyring.NoKeyring{} + if kv := (*ctx).Value(keyring.ContextKey); kv != nil { + k, ok := kv.(*keyring.KeyringImpl) + if !ok { + panic(errors.New("keyring is not of type *keyring.KeyringImpl")) + } + + return k } - return c.Keyring + return keyring.NoKeyring{} } diff --git a/connect/internal/autocli/flag/builder.go b/connect/internal/autocli/flag/builder.go index b2e254d7..3004d204 100644 --- a/connect/internal/autocli/flag/builder.go +++ b/connect/internal/autocli/flag/builder.go @@ -74,10 +74,9 @@ func (b *Builder) init() { } } -// ValidateAndComplete the flag builder fields. +// Validate the flag builder fields. // It returns an error if any of the required fields are missing. -// If the keyring is nil, it will be set to a no keyring. -func (b *Builder) ValidateAndComplete() error { +func (b *Builder) Validate() error { if b.AddressCodec == nil { return errors.New("address codec is required in flag builder") } diff --git a/connect/internal/autocli/interface.go b/connect/internal/autocli/interface.go deleted file mode 100644 index df318172..00000000 --- a/connect/internal/autocli/interface.go +++ /dev/null @@ -1,32 +0,0 @@ -package autocli - -import ( - "github.com/spf13/cobra" - - autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" - "cosmossdk.io/core/appmodule" -) - -// HasAutoCLIConfig is an AppModule extension interface for declaring autocli module options. -type HasAutoCLIConfig interface { - appmodule.AppModule - - // AutoCLIOptions are the autocli module options for this module. - AutoCLIOptions() *autocliv1.ModuleOptions -} - -// HasCustomQueryCommand is an AppModule extension interface for declaring a custom query command. -type HasCustomQueryCommand interface { - appmodule.AppModule - - // GetQueryCmd returns a custom cobra query command for this module. - GetQueryCmd() *cobra.Command -} - -// HasCustomTxCommand is an AppModule extension interface for declaring a custom tx command. -type HasCustomTxCommand interface { - appmodule.AppModule - - // GetTxCmd returns a custom cobra tx command for this module. - GetTxCmd() *cobra.Command -} diff --git a/connect/internal/autocli/keyring/keyring.go b/connect/internal/autocli/keyring/keyring.go index 2b69d995..66d94b23 100644 --- a/connect/internal/autocli/keyring/keyring.go +++ b/connect/internal/autocli/keyring/keyring.go @@ -5,6 +5,9 @@ import ( "github.com/spf13/pflag" + "github.com/ignite/apps/connect/internal/flags" + "github.com/ignite/cli/v28/ignite/pkg/cosmosaccount" + signingv1beta1 "cosmossdk.io/api/cosmos/tx/signing/v1beta1" "cosmossdk.io/core/address" @@ -13,9 +16,9 @@ import ( "github.com/cosmos/cosmos-sdk/crypto/types" ) -// KeyringContextKey is the key used to store the keyring in the context. +// ContextKey is the key used to store the keyring in the context. // The keyring must be wrapped using the KeyringImpl. -var KeyringContextKey keyringContextKey +var ContextKey keyringContextKey type keyringContextKey struct{} @@ -25,41 +28,30 @@ type KeyringImpl struct { k Keyring } -// NewKeyringFromFlags creates a new Keyring instance based on command-line flags. -// It retrieves the keyring backend and directory from flags, creates a new keyring, -// and wraps it with an AutoCLI-compatible interface. -func NewKeyringFromFlags(flagSet *pflag.FlagSet, ac address.Codec, input io.Reader, cdc codec.Codec, opts ...keyring.Option) (Keyring, error) { - backEnd, err := flagSet.GetString("keyring-backend") - if err != nil { - return nil, err - } - - keyringDir, err := flagSet.GetString("keyring-dir") +// NewKeyringFromFlags creates a new keyring instance based on command-line flags. +func NewKeyringFromFlags( + flagSet *pflag.FlagSet, + ac address.Codec, + input io.Reader, + cdc codec.Codec, + opts ...keyring.Option, +) (*KeyringImpl, error) { + backEnd, err := flagSet.GetString(flags.FlagKeyringBackend) if err != nil { return nil, err } - if keyringDir == "" { - keyringDir, err = flagSet.GetString("home") - if err != nil { - return nil, err - } - } - k, err := keyring.New("autoclikeyring", backEnd, keyringDir, input, cdc, opts...) + k, err := keyring.New("ignitekeyring", backEnd, cosmosaccount.KeyringHome, input, cdc, opts...) if err != nil { return nil, err } - autoCLIKeyring, err := keyring.NewAutoCLIKeyring(k) + igniteKeyring, err := keyring.NewAutoCLIKeyring(k) if err != nil { return nil, err } - return NewKeyringImpl(autoCLIKeyring), nil -} - -func NewKeyringImpl(k Keyring) *KeyringImpl { - return &KeyringImpl{k: k} + return &KeyringImpl{k: igniteKeyring}, nil } // GetPubKey implements Keyring. diff --git a/connect/internal/autocli/msg.go b/connect/internal/autocli/msg.go index 310c8a9c..6334feea 100644 --- a/connect/internal/autocli/msg.go +++ b/connect/internal/autocli/msg.go @@ -21,13 +21,11 @@ import ( authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" ) -// BuildMsgCommand builds the msg commands for all the provided modules. If a custom command is provided for a -// module, this is used instead of any automatically generated CLI commands. This allows apps to a fully dynamic client -// with a more customized experience if a binary with custom commands is downloaded. -func (b *Builder) BuildMsgCommand(ctx context.Context, appOptions AppOptions, customCmds map[string]*cobra.Command) (*cobra.Command, error) { +// BuildMsgCommand builds the msg commands for all the provided modules. +func (b *Builder) BuildMsgCommand(ctx context.Context, moduleOptions map[string]*autocliv1.ModuleOptions) (*cobra.Command, error) { msgCmd := topLevelCmd(ctx, "tx", "Transaction subcommands") - if err := b.enhanceCommandCommon(msgCmd, msgCmdType, appOptions, customCmds); err != nil { + if err := b.enhanceCommandCommon(msgCmd, msgCmdType, moduleOptions); err != nil { return nil, err } diff --git a/connect/internal/autocli/msg_test.go b/connect/internal/autocli/msg_test.go index fb44ae6e..6bd963a4 100644 --- a/connect/internal/autocli/msg_test.go +++ b/connect/internal/autocli/msg_test.go @@ -207,31 +207,6 @@ func TestHelpMsg(t *testing.T) { golden.Assert(t, out.String(), "help-echo-msg.golden") } -func TestBuildCustomMsgCommand(t *testing.T) { - b := &Builder{} - customCommandCalled := false - appOptions := AppOptions{ - ModuleOptions: map[string]*autocliv1.ModuleOptions{ - "test": { - Tx: &autocliv1.ServiceCommandDescriptor{ - Service: testpb.Msg_ServiceDesc.ServiceName, - RpcCommandOptions: []*autocliv1.RpcCommandOptions{}, - }, - }, - }, - } - - cmd, err := b.BuildMsgCommand(context.Background(), appOptions, map[string]*cobra.Command{ - "test": {Use: "test", Run: func(cmd *cobra.Command, args []string) { - customCommandCalled = true - }}, - }) - assert.NilError(t, err) - cmd.SetArgs([]string{"test", "tx"}) - assert.NilError(t, cmd.Execute()) - assert.Assert(t, customCommandCalled) -} - func TestNotFoundErrorsMsg(t *testing.T) { fixture := initFixture(t) b := fixture.b diff --git a/connect/internal/autocli/query.go b/connect/internal/autocli/query.go index 39e93308..33ad01a8 100644 --- a/connect/internal/autocli/query.go +++ b/connect/internal/autocli/query.go @@ -21,14 +21,12 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" ) -// BuildQueryCommand builds the query commands for all the provided modules. If a custom command is provided for a -// module, this is used instead of any automatically generated CLI commands. This allows apps to a fully dynamic client -// with a more customized experience if a binary with custom commands is downloaded. -func (b *Builder) BuildQueryCommand(ctx context.Context, appOptions AppOptions, customCmds map[string]*cobra.Command) (*cobra.Command, error) { +// BuildQueryCommand builds the query commands for all the provided modules. +func (b *Builder) BuildQueryCommand(ctx context.Context, moduleOptions map[string]*autocliv1.ModuleOptions) (*cobra.Command, error) { queryCmd := topLevelCmd(ctx, "query", "Querying subcommands") queryCmd.Aliases = []string{"q"} - if err := b.enhanceCommandCommon(queryCmd, queryCmdType, appOptions, customCmds); err != nil { + if err := b.enhanceCommandCommon(queryCmd, queryCmdType, moduleOptions); err != nil { return nil, err } diff --git a/connect/internal/autocli/query_test.go b/connect/internal/autocli/query_test.go index d8f24c24..09892fdd 100644 --- a/connect/internal/autocli/query_test.go +++ b/connect/internal/autocli/query_test.go @@ -653,29 +653,6 @@ func TestDeprecatedQuery(t *testing.T) { assert.Assert(t, strings.Contains(out.String(), "--shorthand-deprecated-field has been deprecated")) } -func TestBuildCustomQueryCommand(t *testing.T) { - b := &Builder{} - customCommandCalled := false - - appOptions := AppOptions{ - ModuleOptions: map[string]*autocliv1.ModuleOptions{ - "test": { - Query: testCmdDesc, - }, - }, - } - - cmd, err := b.BuildQueryCommand(context.Background(), appOptions, map[string]*cobra.Command{ - "test": {Use: "test", Run: func(cmd *cobra.Command, args []string) { - customCommandCalled = true - }}, - }) - assert.NilError(t, err) - cmd.SetArgs([]string{"test", "query"}) - assert.NilError(t, cmd.Execute()) - assert.Assert(t, customCommandCalled) -} - func TestNotFoundErrorsQuery(t *testing.T) { fixture := initFixture(t) b := fixture.b diff --git a/connect/internal/context/context.go b/connect/internal/context/context.go deleted file mode 100644 index eb40302b..00000000 --- a/connect/internal/context/context.go +++ /dev/null @@ -1,55 +0,0 @@ -package context - -import ( - gocontext "context" - "errors" - - "github.com/spf13/pflag" - - apisigning "cosmossdk.io/api/cosmos/tx/signing/v1beta1" - "cosmossdk.io/core/address" - "github.com/ignite/apps/connect/internal/autocli/keyring" - - "github.com/cosmos/cosmos-sdk/codec" -) - -// ContextKey is a key used to store and retrieve Context from a Go context.Context. -var ContextKey contextKey - -// contextKey is an empty struct used as a key type for storing Context in a context.Context. -type contextKey struct{} - -// Context represents the client context used in autocli commands. -// It contains various components needed for command execution. -type Context struct { - Flags *pflag.FlagSet - - AddressCodec address.Codec - ValidatorAddressCodec address.Codec - ConsensusAddressCodec address.Codec - - Cdc codec.Codec - - Keyring keyring.Keyring - - EnabledSignModes []apisigning.SignMode -} - -// SetInContext stores the provided autocli.Context in the given Go context.Context. -// It returns a new context.Context containing the autocli.Context value. -func SetInContext(goCtx gocontext.Context, cliCtx Context) gocontext.Context { - return gocontext.WithValue(goCtx, ContextKey, cliCtx) -} - -// ClientContextFromGoContext returns the autocli.Context from a given Go context. -// It checks if the context contains a valid autocli.Context and returns it. -func ClientContextFromGoContext(ctx gocontext.Context) (*Context, error) { - if c := ctx.Value(ContextKey); c != nil { - cliCtx, ok := c.(Context) - if !ok { - return nil, errors.New("context value is not of type autocli.Context") - } - return &cliCtx, nil - } - return nil, errors.New("context does not contain autocli.Context value") -} From 16166fba4636f0c06c0801af80c2e2d598e02cfc Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Fri, 21 Feb 2025 11:06:25 +0100 Subject: [PATCH 07/17] updates --- connect/cmd/app.go | 60 +++- connect/go.mod | 5 +- connect/go.sum | 2 - connect/internal/ATTRIBUTIONS.md | 7 + connect/internal/autocli/common.go | 21 +- connect/internal/autocli/msg.go | 14 +- connect/internal/autocli/query.go | 4 +- connect/internal/autocli/validate.go | 3 - connect/internal/broadcast/broadcaster.go | 15 - .../internal/broadcast/comet/client_conn.go | 146 --------- connect/internal/broadcast/comet/comet.go | 199 ------------ .../internal/broadcast/comet/comet_test.go | 149 --------- .../broadcast/comet/testutil/comet_mock.go | 285 ------------------ connect/internal/flags/flags.go | 5 + 14 files changed, 80 insertions(+), 835 deletions(-) create mode 100644 connect/internal/ATTRIBUTIONS.md delete mode 100644 connect/internal/broadcast/broadcaster.go delete mode 100644 connect/internal/broadcast/comet/client_conn.go delete mode 100644 connect/internal/broadcast/comet/comet.go delete mode 100644 connect/internal/broadcast/comet/comet_test.go delete mode 100644 connect/internal/broadcast/comet/testutil/comet_mock.go diff --git a/connect/cmd/app.go b/connect/cmd/app.go index 612f9c27..eeedb510 100644 --- a/connect/cmd/app.go +++ b/connect/cmd/app.go @@ -5,10 +5,12 @@ import ( "fmt" "strings" + "cosmossdk.io/core/address" "github.com/cosmos/cosmos-sdk/client" sdkflags "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/grpc/cmtservice" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/spf13/cobra" "google.golang.org/grpc" "google.golang.org/protobuf/reflect/protoreflect" @@ -26,6 +28,10 @@ func AppHandler(ctx context.Context, name string, cfg *chains.ChainConfig, args Short: fmt.Sprintf("Commands for %s chain", name), } + if len(args) > 0 { + chainCmd.SetArgs(args) + } + conn, err := chains.NewConn(name, cfg) if err != nil { return nil, err @@ -35,28 +41,30 @@ func AppHandler(ctx context.Context, name string, cfg *chains.ChainConfig, args return nil, err } + addressCodec, validatorAddressCodec, consensusAddressCodec := setupAddressPrefixesAndCodecs(cfg.Bech32Prefix) + builder := &autocli.Builder{ Builder: flag.Builder{ TypeResolver: &dynamicTypeResolver{conn}, FileResolver: conn.ProtoFiles, - AddressCodec: addresscodec.NewBech32Codec(cfg.Bech32Prefix), - ValidatorAddressCodec: addresscodec.NewBech32Codec(fmt.Sprintf("%svaloper", cfg.Bech32Prefix)), - ConsensusAddressCodec: addresscodec.NewBech32Codec(fmt.Sprintf("%svalcons", cfg.Bech32Prefix)), + AddressCodec: addressCodec, + ValidatorAddressCodec: validatorAddressCodec, + ConsensusAddressCodec: consensusAddressCodec, }, Config: cfg, - GetClientConn: func(command *cobra.Command) (grpc.ClientConnInterface, error) { + GetClientConn: func(cmd *cobra.Command) (grpc.ClientConnInterface, error) { return conn.Connect() }, - AddQueryConnFlags: func(command *cobra.Command) { - sdkflags.AddQueryFlagsToCmd(command) - sdkflags.AddKeyringFlags(command.Flags()) + AddQueryConnFlags: func(cmd *cobra.Command) { + sdkflags.AddQueryFlagsToCmd(cmd) + sdkflags.AddKeyringFlags(cmd.Flags()) }, AddTxConnFlags: sdkflags.AddTxFlagsToCmd, } // add client context clientCtx := client.Context{} - chainCmd.SetContext(context.WithValue(context.Background(), client.ClientContextKey, &clientCtx)) + chainCmd.SetContext(context.WithValue(ctx, client.ClientContextKey, &clientCtx)) // add comet commands cometCmds := cmtservice.NewCometBFTCommands() @@ -67,13 +75,41 @@ func AppHandler(ctx context.Context, name string, cfg *chains.ChainConfig, args return nil, err } - if len(args) > 0 { - chainCmd.SetArgs(args) - } - return chainCmd, nil } +// setupAddressPrefixesAndCodecs returns the address codecs for the given bech32 prefix. +// Additionally it sets the address prefix for the sdk.Config. +func setupAddressPrefixesAndCodecs(prefix string) ( + address.Codec, + address.Codec, + address.Codec, +) { + // set address prefix for sdk.Config + var ( + // Bech32PrefixAccPub defines the Bech32 prefix of an account's public key. + bech32PrefixAccPub = prefix + sdk.PrefixPublic + // Bech32PrefixValAddr defines the Bech32 prefix of a validator's operator address. + bech32PrefixValAddr = prefix + sdk.PrefixValidator + sdk.PrefixOperator + // Bech32PrefixValPub defines the Bech32 prefix of a validator's operator public key. + bech32PrefixValPub = bech32PrefixValAddr + sdk.PrefixPublic + // Bech32PrefixConsAddr defines the Bech32 prefix of a consensus node address. + bech32PrefixConsAddr = prefix + sdk.PrefixValidator + sdk.PrefixConsensus + // Bech32PrefixConsPub defines the Bech32 prefix of a consensus node public key. + bech32PrefixConsPub = bech32PrefixConsAddr + sdk.PrefixPublic + ) + + config := sdk.GetConfig() + config.SetBech32PrefixForAccount(prefix, bech32PrefixAccPub) + config.SetBech32PrefixForValidator(bech32PrefixValAddr, bech32PrefixValPub) + config.SetBech32PrefixForConsensusNode(bech32PrefixConsAddr, bech32PrefixConsPub) + config.Seal() + + return addresscodec.NewBech32Codec(prefix), + addresscodec.NewBech32Codec(bech32PrefixValAddr), + addresscodec.NewBech32Codec(bech32PrefixConsAddr) +} + type dynamicTypeResolver struct { *chains.Conn } diff --git a/connect/go.mod b/connect/go.mod index c2640e69..3987aecc 100644 --- a/connect/go.mod +++ b/connect/go.mod @@ -5,12 +5,10 @@ go 1.23.0 require ( cosmossdk.io/api v0.7.6 cosmossdk.io/core v0.11.1 - cosmossdk.io/errors v1.0.1 cosmossdk.io/math v1.4.0 cosmossdk.io/x/tx v0.13.8 github.com/charmbracelet/bubbles v0.7.6 github.com/charmbracelet/bubbletea v1.2.4 - github.com/cometbft/cometbft v0.38.15 github.com/cosmos/cosmos-proto v1.0.0-beta.5 github.com/cosmos/cosmos-sdk v0.50.11 github.com/cosmos/gogoproto v1.7.0 @@ -20,7 +18,6 @@ require ( github.com/spf13/cobra v1.8.1 github.com/spf13/pflag v1.0.5 github.com/stretchr/testify v1.10.0 - go.uber.org/mock v0.5.0 google.golang.org/grpc v1.67.1 google.golang.org/protobuf v1.35.1 gopkg.in/yaml.v3 v3.0.1 @@ -31,6 +28,7 @@ require ( require ( cosmossdk.io/collections v0.4.0 // indirect cosmossdk.io/depinject v1.1.0 // indirect + cosmossdk.io/errors v1.0.1 // indirect cosmossdk.io/log v1.4.1 // indirect cosmossdk.io/store v1.1.1 // indirect dario.cat/mergo v1.0.0 // indirect @@ -60,6 +58,7 @@ require ( github.com/cockroachdb/pebble v1.1.2 // indirect github.com/cockroachdb/redact v1.1.5 // indirect github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect + github.com/cometbft/cometbft v0.38.15 // indirect github.com/cometbft/cometbft-db v0.14.1 // indirect github.com/cosmos/btcutil v1.0.5 // indirect github.com/cosmos/cosmos-db v1.1.0 // indirect diff --git a/connect/go.sum b/connect/go.sum index 5115bffa..2f861ed9 100644 --- a/connect/go.sum +++ b/connect/go.sum @@ -867,8 +867,6 @@ go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/goleak v1.1.10/go.mod h1:8a7PlsEVH3e/a/GLqe5IIrQx6GzcnRmZEufDUTk4A7A= -go.uber.org/mock v0.5.0 h1:KAMbZvZPyBPWgD14IrIQ38QCyjwpvVVV6K/bHl1IwQU= -go.uber.org/mock v0.5.0/go.mod h1:ge71pBPLYDk7QIi1LupWxdAykm7KIEFchiOqd6z7qMM= go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= go.uber.org/multierr v1.3.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4= go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU= diff --git a/connect/internal/ATTRIBUTIONS.md b/connect/internal/ATTRIBUTIONS.md new file mode 100644 index 00000000..162f62d2 --- /dev/null +++ b/connect/internal/ATTRIBUTIONS.md @@ -0,0 +1,7 @@ +# Attributions + +This package is a fork of [client/v2](https://github.com/cosmos/cosmos-sdk/tree/client/v2.10.0-beta.3/client/v2) at the v2.10.0-beta.3 tag. + +Any modifications made to the original code are subject to [Ignite CLI's license](../../LICENSE). + +The aim of the fork is to incorporate the latest changes from client/v2 that were previously dropped and to make client/v2 more Ignite Connect-focused. diff --git a/connect/internal/autocli/common.go b/connect/internal/autocli/common.go index 1d37fd99..4e27206a 100644 --- a/connect/internal/autocli/common.go +++ b/connect/internal/autocli/common.go @@ -64,10 +64,12 @@ func (b *Builder) buildMethodCommandCommon(descriptor protoreflect.MethodDescrip cmd.PreRunE = b.preRunE() cmd.RunE = func(cmd *cobra.Command, args []string) error { - ctx, err = b.getContext(cmd) + // set keyring in context + k, err := keyring.NewKeyringFromFlags(cmd.Flags(), b.AddressCodec, cmd.InOrStdin(), b.Cdc) if err != nil { return err } + cmd.SetContext(context.WithValue(cmd.Context(), keyring.ContextKey, k)) input, err := binder.BuildMessage(args) if err != nil { @@ -216,23 +218,6 @@ func (b *Builder) outOrStdoutFormat(cmd *cobra.Command, out []byte) error { return p.PrintBytes(out) } -// getContext creates and returns a new context.Context with an autocli.Context value. -// It initializes a printer and, if necessary, a keyring based on command flags. -func (b *Builder) getContext(cmd *cobra.Command) (context.Context, error) { - // if the command uses the keyring this must be set - var ( - k keyring.Keyring - err error - ) - - k, err = keyring.NewKeyringFromFlags(cmd.Flags(), b.AddressCodec, cmd.InOrStdin(), b.Cdc) - if err != nil { - return nil, err - } - - return context.WithValue(cmd.Context(), keyring.ContextKey, k), nil -} - // preRunE returns a function that sets flags from the configuration before running a command. // It is used as a PreRunE hook for cobra commands to ensure flags are properly initialized // from the configuration before command execution. diff --git a/connect/internal/autocli/msg.go b/connect/internal/autocli/msg.go index 6334feea..4d37bd16 100644 --- a/connect/internal/autocli/msg.go +++ b/connect/internal/autocli/msg.go @@ -3,6 +3,7 @@ package autocli import ( "context" "fmt" + "strings" "github.com/spf13/cobra" "google.golang.org/protobuf/proto" @@ -225,6 +226,17 @@ func (b *Builder) handleGovProposal( // isProposalMessage checks the msg name against well known proposal messages. // this isn't exhaustive. to have it better we need to add a field in autocli proto // as it was done in v0.52. -func isProposalMessage(_ protoreflect.MessageDescriptor) bool { +func isProposalMessage(desc protoreflect.MessageDescriptor) bool { + msg := []string{ + "cosmos.gov.v1.MsgSubmitProposal", + ".MsgUpdateParams", + } + + for _, m := range msg { + if strings.HasSuffix(string(desc.FullName()), m) { + return true + } + } + return false } diff --git a/connect/internal/autocli/query.go b/connect/internal/autocli/query.go index 33ad01a8..9caac36e 100644 --- a/connect/internal/autocli/query.go +++ b/connect/internal/autocli/query.go @@ -179,8 +179,8 @@ func (b *Builder) queryContext(ctx context.Context, cmd *cobra.Command) context. } md = map[string][]string{} - if cmd.Flags().Lookup("height") != nil { - h, _ := cmd.Flags().GetInt64("height") + if cmd.Flags().Lookup(flags.FlagHeight) != nil { + h, _ := cmd.Flags().GetInt64(flags.FlagHeight) md["x-cosmos-block-height"] = []string{fmt.Sprintf("%d", h)} } diff --git a/connect/internal/autocli/validate.go b/connect/internal/autocli/validate.go index 3256aeb8..0b7c1c97 100644 --- a/connect/internal/autocli/validate.go +++ b/connect/internal/autocli/validate.go @@ -8,9 +8,6 @@ import ( "github.com/spf13/cobra" ) -// NOTE: this was copied from client/cmd.go to avoid introducing a dependency -// on the v1 client package. - // validateCmd returns unknown command error or Help display if help flag set func validateCmd(cmd *cobra.Command, args []string) error { var unknownCmd string diff --git a/connect/internal/broadcast/broadcaster.go b/connect/internal/broadcast/broadcaster.go deleted file mode 100644 index bcee034b..00000000 --- a/connect/internal/broadcast/broadcaster.go +++ /dev/null @@ -1,15 +0,0 @@ -package broadcast - -import "context" - -// Broadcaster defines an interface for broadcasting transactions to the consensus engine. -type Broadcaster interface { - // Broadcast sends a transaction to the network and returns the result. - // - // It returns a byte slice containing the formatted result that will be - // passed to the output writer, and an error if the broadcast failed. - Broadcast(ctx context.Context, txBytes []byte) ([]byte, error) - - // Consensus returns the consensus engine identifier for this Broadcaster. - Consensus() string -} diff --git a/connect/internal/broadcast/comet/client_conn.go b/connect/internal/broadcast/comet/client_conn.go deleted file mode 100644 index 3ae20f6f..00000000 --- a/connect/internal/broadcast/comet/client_conn.go +++ /dev/null @@ -1,146 +0,0 @@ -package comet - -import ( - "context" - "errors" - "strconv" - - abci "github.com/cometbft/cometbft/abci/types" - rpcclient "github.com/cometbft/cometbft/rpc/client" - gogogrpc "github.com/cosmos/gogoproto/grpc" - "google.golang.org/grpc" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/encoding" - "google.golang.org/grpc/metadata" - "google.golang.org/grpc/status" - - errorsmod "cosmossdk.io/errors" - - "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/codec/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" -) - -const grpcBlockHeightHeader = "x-cosmos-block-height" - -var ( - _ gogogrpc.ClientConn = &CometBFTBroadcaster{} - _ grpc.ClientConnInterface = &CometBFTBroadcaster{} -) - -func (c *CometBFTBroadcaster) NewStream(_ context.Context, _ *grpc.StreamDesc, _ string, _ ...grpc.CallOption) (grpc.ClientStream, error) { - return nil, errors.New("not implemented") -} - -// Invoke implements the gRPC ClientConn interface by forwarding the RPC call to CometBFT's ABCI Query. -// It marshals the request, sends it as an ABCI query, and unmarshals the response. -func (c *CometBFTBroadcaster) Invoke(ctx context.Context, method string, req, reply interface{}, opts ...grpc.CallOption) (err error) { - reqBz, err := c.getRPCCodec().Marshal(req) - if err != nil { - return err - } - - // parse height header - md, _ := metadata.FromOutgoingContext(ctx) - var height int64 - if heights := md.Get(grpcBlockHeightHeader); len(heights) > 0 { - height, err = strconv.ParseInt(heights[0], 10, 64) - if err != nil { - return err - } - if height < 0 { - return errorsmod.Wrapf( - sdkerrors.ErrInvalidRequest, - "client.Context.Invoke: height (%d) from %q must be >= 0", height, grpcBlockHeightHeader) - } - } - - abciR := abci.RequestQuery{ - Path: method, - Data: reqBz, - Height: height, - } - - res, err := c.queryABCI(ctx, abciR) - if err != nil { - return err - } - - err = c.getRPCCodec().Unmarshal(res.Value, reply) - if err != nil { - return err - } - - // Create header metadata. For now the headers contain: - // - block height - // We then parse all the call options, if the call option is a - // HeaderCallOption, then we manually set the value of that header to the - // metadata. - md = metadata.Pairs(grpcBlockHeightHeader, strconv.FormatInt(res.Height, 10)) - for _, callOpt := range opts { - header, ok := callOpt.(grpc.HeaderCallOption) - if !ok { - continue - } - - *header.HeaderAddr = md - } - - if c.cdc.InterfaceRegistry() != nil { - return types.UnpackInterfaces(reply, c.cdc.InterfaceRegistry()) - } - - return nil -} - -// queryABCI performs an ABCI query request to the CometBFT RPC client. -// If the RPC query fails or returns a non-OK response, it will return an error. -// The response is converted from ABCI error codes to gRPC status errors. -func (c *CometBFTBroadcaster) queryABCI(ctx context.Context, req abci.RequestQuery) (abci.ResponseQuery, error) { - opts := rpcclient.ABCIQueryOptions{ - Height: req.Height, - Prove: req.Prove, - } - - result, err := c.rpcClient.ABCIQueryWithOptions(ctx, req.Path, req.Data, opts) - if err != nil { - return abci.ResponseQuery{}, err - } - - if !result.Response.IsOK() { - return abci.ResponseQuery{}, sdkErrorToGRPCError(result.Response) - } - - return result.Response, nil -} - -// sdkErrorToGRPCError converts an ABCI query response error code to an appropriate gRPC status error. -// It maps common SDK error codes to their gRPC equivalents: -// - ErrInvalidRequest -> InvalidArgument -// - ErrUnauthorized -> Unauthenticated -// - ErrKeyNotFound -> NotFound -// Any other error codes are mapped to Unknown. -func sdkErrorToGRPCError(resp abci.ResponseQuery) error { - switch resp.Code { - case sdkerrors.ErrInvalidRequest.ABCICode(): - return status.Error(codes.InvalidArgument, resp.Log) - case sdkerrors.ErrUnauthorized.ABCICode(): - return status.Error(codes.Unauthenticated, resp.Log) - case sdkerrors.ErrKeyNotFound.ABCICode(): - return status.Error(codes.NotFound, resp.Log) - default: - return status.Error(codes.Unknown, resp.Log) - } -} - -// getRPCCodec returns the gRPC codec for the CometBFT broadcaster. -// If the broadcaster's codec implements GRPCCodecProvider, it returns its gRPC codec. -// Otherwise, it creates a new ProtoCodec with the broadcaster's interface registry and returns its gRPC codec. -func (c *CometBFTBroadcaster) getRPCCodec() encoding.Codec { - cdc, ok := c.cdc.(codec.GRPCCodecProvider) - if !ok { - return codec.NewProtoCodec(c.cdc.InterfaceRegistry()).GRPCCodec() - } - - return cdc.GRPCCodec() -} diff --git a/connect/internal/broadcast/comet/comet.go b/connect/internal/broadcast/comet/comet.go deleted file mode 100644 index 3ce9cfda..00000000 --- a/connect/internal/broadcast/comet/comet.go +++ /dev/null @@ -1,199 +0,0 @@ -package comet - -import ( - "context" - "encoding/json" - "errors" - "fmt" - "strings" - - "github.com/cometbft/cometbft/mempool" - rpcclient "github.com/cometbft/cometbft/rpc/client" - rpchttp "github.com/cometbft/cometbft/rpc/client/http" - coretypes "github.com/cometbft/cometbft/rpc/core/types" - cmttypes "github.com/cometbft/cometbft/types" - - apiacbci "cosmossdk.io/api/cosmos/base/abci/v1beta1" - "github.com/ignite/apps/connect/internal/broadcast" - - "github.com/cosmos/cosmos-sdk/codec" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" -) - -const ( - // BroadcastSync defines a tx broadcasting mode where the client waits for - // a CheckTx execution response only. - BroadcastSync = "sync" - // BroadcastAsync defines a tx broadcasting mode where the client returns - // immediately. - BroadcastAsync = "async" - - // cometBftConsensus is the identifier for the CometBFT consensus engine. - cometBFTConsensus = "comet" -) - -// CometRPC defines the interface of a CometBFT RPC client needed for -// queries and transaction handling. -type CometRPC interface { - rpcclient.ABCIClient - - Validators(ctx context.Context, height *int64, page, perPage *int) (*coretypes.ResultValidators, error) - Status(context.Context) (*coretypes.ResultStatus, error) - Block(ctx context.Context, height *int64) (*coretypes.ResultBlock, error) - BlockByHash(ctx context.Context, hash []byte) (*coretypes.ResultBlock, error) - BlockResults(ctx context.Context, height *int64) (*coretypes.ResultBlockResults, error) - BlockchainInfo(ctx context.Context, minHeight, maxHeight int64) (*coretypes.ResultBlockchainInfo, error) - Commit(ctx context.Context, height *int64) (*coretypes.ResultCommit, error) - Tx(ctx context.Context, hash []byte, prove bool) (*coretypes.ResultTx, error) - TxSearch( - ctx context.Context, - query string, - prove bool, - page, perPage *int, - orderBy string, - ) (*coretypes.ResultTxSearch, error) - BlockSearch( - ctx context.Context, - query string, - page, perPage *int, - orderBy string, - ) (*coretypes.ResultBlockSearch, error) -} - -var _ broadcast.Broadcaster = &CometBFTBroadcaster{} - -// CometBFTBroadcaster implements the Broadcaster interface for CometBFT consensus engine. -type CometBFTBroadcaster struct { - rpcClient CometRPC - mode string - cdc codec.Codec -} - -// NewCometBFTBroadcaster creates a new CometBFTBroadcaster. -func NewCometBFTBroadcaster(rpcURL, mode string, cdc codec.Codec) (*CometBFTBroadcaster, error) { - if cdc == nil { - return nil, errors.New("codec can't be nil") - } - - if mode == "" { - mode = BroadcastSync - } - - rpcClient, err := rpchttp.New(rpcURL, "/websocket") - if err != nil { - return nil, fmt.Errorf("failed to create CometBft RPC client: %w", err) - } - - return &CometBFTBroadcaster{ - rpcClient: rpcClient, - mode: mode, - cdc: cdc, - }, nil -} - -// Consensus returns the consensus engine name used by the broadcaster. -// It always returns "comet" for CometBFTBroadcaster. -func (c *CometBFTBroadcaster) Consensus() string { - return cometBFTConsensus -} - -// Broadcast sends a transaction to the network and returns the result. -// returns a byte slice containing the JSON-encoded result and an error if the broadcast failed. -func (c *CometBFTBroadcaster) Broadcast(ctx context.Context, txBytes []byte) ([]byte, error) { - if c.cdc == nil { - return []byte{}, fmt.Errorf("JSON codec is not initialized") - } - - var broadcastFunc func(ctx context.Context, tx cmttypes.Tx) (*coretypes.ResultBroadcastTx, error) - switch c.mode { - case BroadcastSync: - broadcastFunc = c.rpcClient.BroadcastTxSync - case BroadcastAsync: - broadcastFunc = c.rpcClient.BroadcastTxAsync - default: - return []byte{}, fmt.Errorf("unknown broadcast mode: %s", c.mode) - } - - res, err := c.broadcast(ctx, txBytes, broadcastFunc) - if err != nil { - return []byte{}, err - } - - return c.cdc.MarshalJSON(res) -} - -// broadcast sends a transaction to the CometBFT network using the provided function. -func (c *CometBFTBroadcaster) broadcast(ctx context.Context, txBytes []byte, - fn func(ctx context.Context, tx cmttypes.Tx) (*coretypes.ResultBroadcastTx, error), -) (*apiacbci.TxResponse, error) { - res, err := fn(ctx, txBytes) - if errRes := checkCometError(err, txBytes); errRes != nil { - return errRes, nil - } - - if res == nil { - return nil, err - } - - parsedLogs, _ := parseABCILogs(res.Log) - return &apiacbci.TxResponse{ - Code: res.Code, - Codespace: res.Codespace, - Data: res.Data.String(), - RawLog: res.Log, - Logs: parsedLogs, - Txhash: res.Hash.String(), - }, err -} - -// checkCometError checks for errors returned by the CometBFT network and returns an appropriate TxResponse. -// It extracts error information and constructs a TxResponse with the error details. -func checkCometError(err error, tx cmttypes.Tx) *apiacbci.TxResponse { - if err == nil { - return nil - } - - errStr := strings.ToLower(err.Error()) - txHash := fmt.Sprintf("%X", tx.Hash()) - - switch { - case strings.Contains(errStr, strings.ToLower(mempool.ErrTxInCache.Error())) || - strings.Contains(errStr, strings.ToLower(sdkerrors.ErrTxInMempoolCache.Error())): - return &apiacbci.TxResponse{ - Code: sdkerrors.ErrTxInMempoolCache.ABCICode(), - Codespace: sdkerrors.ErrTxInMempoolCache.Codespace(), - Txhash: txHash, - } - - case strings.Contains(errStr, "mempool is full"): - return &apiacbci.TxResponse{ - Code: sdkerrors.ErrMempoolIsFull.ABCICode(), - Codespace: sdkerrors.ErrMempoolIsFull.Codespace(), - Txhash: txHash, - } - - case strings.Contains(errStr, "tx too large"): - return &apiacbci.TxResponse{ - Code: sdkerrors.ErrTxTooLarge.ABCICode(), - Codespace: sdkerrors.ErrTxTooLarge.Codespace(), - Txhash: txHash, - } - - case strings.Contains(errStr, "no signatures supplied"): - return &apiacbci.TxResponse{ - Code: sdkerrors.ErrNoSignatures.ABCICode(), - Codespace: sdkerrors.ErrNoSignatures.Codespace(), - Txhash: txHash, - } - - default: - return nil - } -} - -// parseABCILogs attempts to parse a stringified ABCI tx log into a slice of -// ABCIMessageLog types. It returns an error upon JSON decoding failure. -func parseABCILogs(logs string) (res []*apiacbci.ABCIMessageLog, err error) { - err = json.Unmarshal([]byte(logs), &res) - return res, err -} diff --git a/connect/internal/broadcast/comet/comet_test.go b/connect/internal/broadcast/comet/comet_test.go deleted file mode 100644 index 98bacf05..00000000 --- a/connect/internal/broadcast/comet/comet_test.go +++ /dev/null @@ -1,149 +0,0 @@ -package comet - -import ( - "context" - "errors" - "testing" - - "github.com/cometbft/cometbft/mempool" - coretypes "github.com/cometbft/cometbft/rpc/core/types" - "github.com/stretchr/testify/require" - "go.uber.org/mock/gomock" - - apiacbci "cosmossdk.io/api/cosmos/base/abci/v1beta1" - mockrpc "github.com/ignite/apps/connect/internal/broadcast/comet/testutil" - - "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/codec/testutil" -) - -var cdc = testutil.CodecOptions{}.NewCodec() - -func TestNewCometBftBroadcaster(t *testing.T) { - tests := []struct { - name string - cdc codec.Codec - mode string - want *CometBFTBroadcaster - wantErr bool - }{ - { - name: "constructor", - mode: BroadcastSync, - cdc: cdc, - want: &CometBFTBroadcaster{ - mode: BroadcastSync, - cdc: cdc, - }, - }, - { - name: "nil codec", - mode: BroadcastSync, - cdc: nil, - wantErr: true, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - got, err := NewCometBFTBroadcaster("localhost:26657", tt.mode, tt.cdc) - if tt.wantErr { - require.Error(t, err) - require.Nil(t, got) - } else { - require.Equal(t, got.mode, tt.want.mode) - require.Equal(t, got.cdc, tt.want.cdc) - } - }) - } -} - -func TestCometBftBroadcaster_Broadcast(t *testing.T) { - ctrl := gomock.NewController(t) - cometMock := mockrpc.NewMockCometRPC(ctrl) - c := CometBFTBroadcaster{ - rpcClient: cometMock, - mode: BroadcastSync, - cdc: cdc, - } - tests := []struct { - name string - mode string - setupMock func(*mockrpc.MockCometRPC) - wantErr bool - }{ - { - name: "sync", - mode: BroadcastSync, - setupMock: func(m *mockrpc.MockCometRPC) { - m.EXPECT().BroadcastTxSync(context.Background(), gomock.Any()).Return(&coretypes.ResultBroadcastTx{ - Code: 0, - Data: []byte{}, - Log: "", - Codespace: "", - Hash: []byte("%�����\u0010\n�T�\u0017\u0016�N^H[5�\u0006}�n�w�/Vi� "), - }, nil) - }, - }, - { - name: "async", - mode: BroadcastAsync, - setupMock: func(m *mockrpc.MockCometRPC) { - m.EXPECT().BroadcastTxAsync(context.Background(), gomock.Any()).Return(&coretypes.ResultBroadcastTx{ - Code: 0, - Data: []byte{}, - Log: "", - Codespace: "", - Hash: []byte("%�����\u0010\n�T�\u0017\u0016�N^H[5�\u0006}�n�w�/Vi� "), - }, nil) - }, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - c.mode = tt.mode - tt.setupMock(cometMock) - got, err := c.Broadcast(context.Background(), []byte{}) - if tt.wantErr { - require.Error(t, err) - } else { - require.NotNil(t, got) - } - }) - } -} - -func Test_checkCometError(t *testing.T) { - tests := []struct { - name string - err error - want *apiacbci.TxResponse - }{ - { - name: "tx already in cache", - err: errors.New("tx already exists in cache"), - want: &apiacbci.TxResponse{ - Code: 19, - }, - }, - { - name: "mempool is full", - err: mempool.ErrMempoolIsFull{}, - want: &apiacbci.TxResponse{ - Code: 20, - }, - }, - { - name: "tx too large", - err: mempool.ErrTxTooLarge{}, - want: &apiacbci.TxResponse{ - Code: 21, - }, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - got := checkCometError(tt.err, []byte{}) - require.Equal(t, got.Code, tt.want.Code) - }) - } -} diff --git a/connect/internal/broadcast/comet/testutil/comet_mock.go b/connect/internal/broadcast/comet/testutil/comet_mock.go deleted file mode 100644 index 75cdc50a..00000000 --- a/connect/internal/broadcast/comet/testutil/comet_mock.go +++ /dev/null @@ -1,285 +0,0 @@ -// Code generated by MockGen. DO NOT EDIT. -// Source: client/v2/broadcast/comet/comet.go -// -// Generated by this command: -// -// mockgen -source=client/v2/broadcast/comet/comet.go -package testutil -destination client/v2/broadcast/comet/testutil/comet_mock.go -// - -// Package testutil is a generated GoMock package. -package testutil - -import ( - context "context" - reflect "reflect" - - bytes "github.com/cometbft/cometbft/libs/bytes" - client "github.com/cometbft/cometbft/rpc/client" - coretypes "github.com/cometbft/cometbft/rpc/core/types" - types "github.com/cometbft/cometbft/types" - gomock "go.uber.org/mock/gomock" -) - -// MockCometRPC is a mock of CometRPC interface. -type MockCometRPC struct { - ctrl *gomock.Controller - recorder *MockCometRPCMockRecorder - isgomock struct{} -} - -// MockCometRPCMockRecorder is the mock recorder for MockCometRPC. -type MockCometRPCMockRecorder struct { - mock *MockCometRPC -} - -// NewMockCometRPC creates a new mock instance. -func NewMockCometRPC(ctrl *gomock.Controller) *MockCometRPC { - mock := &MockCometRPC{ctrl: ctrl} - mock.recorder = &MockCometRPCMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockCometRPC) EXPECT() *MockCometRPCMockRecorder { - return m.recorder -} - -// ABCIInfo mocks base method. -func (m *MockCometRPC) ABCIInfo(ctx context.Context) (*coretypes.ResultABCIInfo, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ABCIInfo", ctx) - ret0, _ := ret[0].(*coretypes.ResultABCIInfo) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// ABCIInfo indicates an expected call of ABCIInfo. -func (mr *MockCometRPCMockRecorder) ABCIInfo(ctx any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ABCIInfo", reflect.TypeOf((*MockCometRPC)(nil).ABCIInfo), ctx) -} - -// ABCIQuery mocks base method. -func (m *MockCometRPC) ABCIQuery(ctx context.Context, path string, data bytes.HexBytes) (*coretypes.ResultABCIQuery, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ABCIQuery", ctx, path, data) - ret0, _ := ret[0].(*coretypes.ResultABCIQuery) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// ABCIQuery indicates an expected call of ABCIQuery. -func (mr *MockCometRPCMockRecorder) ABCIQuery(ctx, path, data any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ABCIQuery", reflect.TypeOf((*MockCometRPC)(nil).ABCIQuery), ctx, path, data) -} - -// ABCIQueryWithOptions mocks base method. -func (m *MockCometRPC) ABCIQueryWithOptions(ctx context.Context, path string, data bytes.HexBytes, opts client.ABCIQueryOptions) (*coretypes.ResultABCIQuery, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ABCIQueryWithOptions", ctx, path, data, opts) - ret0, _ := ret[0].(*coretypes.ResultABCIQuery) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// ABCIQueryWithOptions indicates an expected call of ABCIQueryWithOptions. -func (mr *MockCometRPCMockRecorder) ABCIQueryWithOptions(ctx, path, data, opts any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ABCIQueryWithOptions", reflect.TypeOf((*MockCometRPC)(nil).ABCIQueryWithOptions), ctx, path, data, opts) -} - -// Block mocks base method. -func (m *MockCometRPC) Block(ctx context.Context, height *int64) (*coretypes.ResultBlock, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Block", ctx, height) - ret0, _ := ret[0].(*coretypes.ResultBlock) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// Block indicates an expected call of Block. -func (mr *MockCometRPCMockRecorder) Block(ctx, height any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Block", reflect.TypeOf((*MockCometRPC)(nil).Block), ctx, height) -} - -// BlockByHash mocks base method. -func (m *MockCometRPC) BlockByHash(ctx context.Context, hash []byte) (*coretypes.ResultBlock, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "BlockByHash", ctx, hash) - ret0, _ := ret[0].(*coretypes.ResultBlock) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// BlockByHash indicates an expected call of BlockByHash. -func (mr *MockCometRPCMockRecorder) BlockByHash(ctx, hash any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BlockByHash", reflect.TypeOf((*MockCometRPC)(nil).BlockByHash), ctx, hash) -} - -// BlockResults mocks base method. -func (m *MockCometRPC) BlockResults(ctx context.Context, height *int64) (*coretypes.ResultBlockResults, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "BlockResults", ctx, height) - ret0, _ := ret[0].(*coretypes.ResultBlockResults) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// BlockResults indicates an expected call of BlockResults. -func (mr *MockCometRPCMockRecorder) BlockResults(ctx, height any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BlockResults", reflect.TypeOf((*MockCometRPC)(nil).BlockResults), ctx, height) -} - -// BlockSearch mocks base method. -func (m *MockCometRPC) BlockSearch(ctx context.Context, query string, page, perPage *int, orderBy string) (*coretypes.ResultBlockSearch, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "BlockSearch", ctx, query, page, perPage, orderBy) - ret0, _ := ret[0].(*coretypes.ResultBlockSearch) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// BlockSearch indicates an expected call of BlockSearch. -func (mr *MockCometRPCMockRecorder) BlockSearch(ctx, query, page, perPage, orderBy any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BlockSearch", reflect.TypeOf((*MockCometRPC)(nil).BlockSearch), ctx, query, page, perPage, orderBy) -} - -// BlockchainInfo mocks base method. -func (m *MockCometRPC) BlockchainInfo(ctx context.Context, minHeight, maxHeight int64) (*coretypes.ResultBlockchainInfo, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "BlockchainInfo", ctx, minHeight, maxHeight) - ret0, _ := ret[0].(*coretypes.ResultBlockchainInfo) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// BlockchainInfo indicates an expected call of BlockchainInfo. -func (mr *MockCometRPCMockRecorder) BlockchainInfo(ctx, minHeight, maxHeight any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BlockchainInfo", reflect.TypeOf((*MockCometRPC)(nil).BlockchainInfo), ctx, minHeight, maxHeight) -} - -// BroadcastTxAsync mocks base method. -func (m *MockCometRPC) BroadcastTxAsync(ctx context.Context, tx types.Tx) (*coretypes.ResultBroadcastTx, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "BroadcastTxAsync", ctx, tx) - ret0, _ := ret[0].(*coretypes.ResultBroadcastTx) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// BroadcastTxAsync indicates an expected call of BroadcastTxAsync. -func (mr *MockCometRPCMockRecorder) BroadcastTxAsync(ctx, tx any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BroadcastTxAsync", reflect.TypeOf((*MockCometRPC)(nil).BroadcastTxAsync), ctx, tx) -} - -// BroadcastTxCommit mocks base method. -func (m *MockCometRPC) BroadcastTxCommit(ctx context.Context, tx types.Tx) (*coretypes.ResultBroadcastTxCommit, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "BroadcastTxCommit", ctx, tx) - ret0, _ := ret[0].(*coretypes.ResultBroadcastTxCommit) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// BroadcastTxCommit indicates an expected call of BroadcastTxCommit. -func (mr *MockCometRPCMockRecorder) BroadcastTxCommit(ctx, tx any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BroadcastTxCommit", reflect.TypeOf((*MockCometRPC)(nil).BroadcastTxCommit), ctx, tx) -} - -// BroadcastTxSync mocks base method. -func (m *MockCometRPC) BroadcastTxSync(ctx context.Context, tx types.Tx) (*coretypes.ResultBroadcastTx, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "BroadcastTxSync", ctx, tx) - ret0, _ := ret[0].(*coretypes.ResultBroadcastTx) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// BroadcastTxSync indicates an expected call of BroadcastTxSync. -func (mr *MockCometRPCMockRecorder) BroadcastTxSync(ctx, tx any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BroadcastTxSync", reflect.TypeOf((*MockCometRPC)(nil).BroadcastTxSync), ctx, tx) -} - -// Commit mocks base method. -func (m *MockCometRPC) Commit(ctx context.Context, height *int64) (*coretypes.ResultCommit, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Commit", ctx, height) - ret0, _ := ret[0].(*coretypes.ResultCommit) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// Commit indicates an expected call of Commit. -func (mr *MockCometRPCMockRecorder) Commit(ctx, height any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Commit", reflect.TypeOf((*MockCometRPC)(nil).Commit), ctx, height) -} - -// Status mocks base method. -func (m *MockCometRPC) Status(arg0 context.Context) (*coretypes.ResultStatus, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Status", arg0) - ret0, _ := ret[0].(*coretypes.ResultStatus) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// Status indicates an expected call of Status. -func (mr *MockCometRPCMockRecorder) Status(arg0 any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Status", reflect.TypeOf((*MockCometRPC)(nil).Status), arg0) -} - -// Tx mocks base method. -func (m *MockCometRPC) Tx(ctx context.Context, hash []byte, prove bool) (*coretypes.ResultTx, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Tx", ctx, hash, prove) - ret0, _ := ret[0].(*coretypes.ResultTx) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// Tx indicates an expected call of Tx. -func (mr *MockCometRPCMockRecorder) Tx(ctx, hash, prove any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Tx", reflect.TypeOf((*MockCometRPC)(nil).Tx), ctx, hash, prove) -} - -// TxSearch mocks base method. -func (m *MockCometRPC) TxSearch(ctx context.Context, query string, prove bool, page, perPage *int, orderBy string) (*coretypes.ResultTxSearch, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "TxSearch", ctx, query, prove, page, perPage, orderBy) - ret0, _ := ret[0].(*coretypes.ResultTxSearch) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// TxSearch indicates an expected call of TxSearch. -func (mr *MockCometRPCMockRecorder) TxSearch(ctx, query, prove, page, perPage, orderBy any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "TxSearch", reflect.TypeOf((*MockCometRPC)(nil).TxSearch), ctx, query, prove, page, perPage, orderBy) -} - -// Validators mocks base method. -func (m *MockCometRPC) Validators(ctx context.Context, height *int64, page, perPage *int) (*coretypes.ResultValidators, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Validators", ctx, height, page, perPage) - ret0, _ := ret[0].(*coretypes.ResultValidators) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// Validators indicates an expected call of Validators. -func (mr *MockCometRPCMockRecorder) Validators(ctx, height, page, perPage any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Validators", reflect.TypeOf((*MockCometRPC)(nil).Validators), ctx, height, page, perPage) -} diff --git a/connect/internal/flags/flags.go b/connect/internal/flags/flags.go index 7f684ac4..a8a98aba 100644 --- a/connect/internal/flags/flags.go +++ b/connect/internal/flags/flags.go @@ -31,13 +31,18 @@ const ( // FlagNode is the flag to specify the node address to connect to. FlagNode = "node" + // FlagBroadcastMode is the flag to specify the broadcast mode for transactions. FlagBroadcastMode = "broadcast-mode" // FlagGrpcAddress is the flag to specify the gRPC server address to connect to. FlagGrpcAddress = "grpc-addr" + // FlagGrpcInsecure is the flag to allow insecure gRPC connections. FlagGrpcInsecure = "grpc-insecure" + + // FlagHeight is the flag to specify the height at which to query the state. + FlagHeight = "height" ) // List of supported output formats From 4ef3f16aee219b4c4cce45ca33880944e183d0fd Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Fri, 21 Feb 2025 11:19:56 +0100 Subject: [PATCH 08/17] updates --- connect/internal/autocli/app.go | 6 ++++++ connect/internal/autocli/common_test.go | 2 ++ connect/internal/autocli/msg.go | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/connect/internal/autocli/app.go b/connect/internal/autocli/app.go index b7b5701f..a526b599 100644 --- a/connect/internal/autocli/app.go +++ b/connect/internal/autocli/app.go @@ -1,6 +1,8 @@ package autocli import ( + "errors" + "github.com/cosmos/cosmos-sdk/codec" "github.com/ignite/apps/connect/chains" "github.com/ignite/apps/connect/internal/autocli/flag" @@ -41,6 +43,10 @@ func EnhanceRootCommand( builder *Builder, moduleOptions map[string]*autocliv1.ModuleOptions, ) error { + if builder.Config == nil { + return errors.New("missing config") + } + if err := builder.Validate(); err != nil { return err } diff --git a/connect/internal/autocli/common_test.go b/connect/internal/autocli/common_test.go index 1af0111a..eb82073c 100644 --- a/connect/internal/autocli/common_test.go +++ b/connect/internal/autocli/common_test.go @@ -14,6 +14,7 @@ import ( autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" reflectionv2alpha1 "cosmossdk.io/api/cosmos/base/reflection/v2alpha1" + "github.com/ignite/apps/connect/chains" "github.com/ignite/apps/connect/internal/autocli/flag" "github.com/ignite/apps/connect/internal/testpb" @@ -87,6 +88,7 @@ func initFixture(t *testing.T) *fixture { AddQueryConnFlags: flags.AddQueryFlagsToCmd, AddTxConnFlags: addTxAndGlobalFlagsToCmd, Cdc: encodingConfig.Codec, + Config: &chains.ChainConfig{}, } assert.NilError(t, b.Validate()) diff --git a/connect/internal/autocli/msg.go b/connect/internal/autocli/msg.go index 4d37bd16..6814d36c 100644 --- a/connect/internal/autocli/msg.go +++ b/connect/internal/autocli/msg.go @@ -229,6 +229,10 @@ func (b *Builder) handleGovProposal( func isProposalMessage(desc protoreflect.MessageDescriptor) bool { msg := []string{ "cosmos.gov.v1.MsgSubmitProposal", + "cosmos.upgrade.v1beta1.MsgSoftwareUpgrade", + "cosmos.upgrade.v1beta1.MsgCancelUpgrade", + "cosmos.distribution.v1beta1.MsgFundCommunityPool", + "ibc.core.client.v1.MsgIBCSoftwareUpgrade", ".MsgUpdateParams", } From 63535cfde42f2ab6d17958984b67e838a4718dac Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Fri, 21 Feb 2025 11:36:57 +0100 Subject: [PATCH 09/17] fix --- connect/internal/autocli/msg.go | 31 ++++++++++++++-------------- connect/internal/autocli/msg_test.go | 1 + 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/connect/internal/autocli/msg.go b/connect/internal/autocli/msg.go index 6814d36c..21f68642 100644 --- a/connect/internal/autocli/msg.go +++ b/connect/internal/autocli/msg.go @@ -3,7 +3,6 @@ package autocli import ( "context" "fmt" - "strings" "github.com/spf13/cobra" "google.golang.org/protobuf/proto" @@ -226,21 +225,21 @@ func (b *Builder) handleGovProposal( // isProposalMessage checks the msg name against well known proposal messages. // this isn't exhaustive. to have it better we need to add a field in autocli proto // as it was done in v0.52. -func isProposalMessage(desc protoreflect.MessageDescriptor) bool { - msg := []string{ - "cosmos.gov.v1.MsgSubmitProposal", - "cosmos.upgrade.v1beta1.MsgSoftwareUpgrade", - "cosmos.upgrade.v1beta1.MsgCancelUpgrade", - "cosmos.distribution.v1beta1.MsgFundCommunityPool", - "ibc.core.client.v1.MsgIBCSoftwareUpgrade", - ".MsgUpdateParams", - } - - for _, m := range msg { - if strings.HasSuffix(string(desc.FullName()), m) { - return true - } - } +func isProposalMessage(_ protoreflect.MessageDescriptor) bool { + // msg := []string{ + // "cosmos.gov.v1.MsgSubmitProposal", + // "cosmos.upgrade.v1beta1.MsgSoftwareUpgrade", + // "cosmos.upgrade.v1beta1.MsgCancelUpgrade", + // "cosmos.distribution.v1beta1.MsgFundCommunityPool", + // "ibc.core.client.v1.MsgIBCSoftwareUpgrade", + // ".MsgUpdateParams", + // } + + // for _, m := range msg { + // if strings.HasSuffix(string(desc.FullName()), m) { + // return true + // } + // } return false } diff --git a/connect/internal/autocli/msg_test.go b/connect/internal/autocli/msg_test.go index 6bd963a4..c36eaf73 100644 --- a/connect/internal/autocli/msg_test.go +++ b/connect/internal/autocli/msg_test.go @@ -150,6 +150,7 @@ func TestMsgWithFlattenFields(t *testing.T) { "--generate-only", "--output", "json", "--chain-id", fixture.chainID, + "--no-proposal", ) assert.NilError(t, err) assertNormalizedJSONEqual(t, out.Bytes(), goldenLoad(t, "flatten-output.golden")) From 159d8661533f44023926553b0c2cca56eae6f7bf Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Sat, 22 Feb 2025 01:11:18 +0100 Subject: [PATCH 10/17] use cosmosaccount + cleanup builder --- connect/internal/autocli/app.go | 4 ---- connect/internal/autocli/common.go | 2 +- connect/internal/autocli/common_test.go | 1 - connect/internal/autocli/keyring/keyring.go | 20 ++++++++++---------- 4 files changed, 11 insertions(+), 16 deletions(-) diff --git a/connect/internal/autocli/app.go b/connect/internal/autocli/app.go index a526b599..040bebba 100644 --- a/connect/internal/autocli/app.go +++ b/connect/internal/autocli/app.go @@ -3,7 +3,6 @@ package autocli import ( "errors" - "github.com/cosmos/cosmos-sdk/codec" "github.com/ignite/apps/connect/chains" "github.com/ignite/apps/connect/internal/autocli/flag" "github.com/spf13/cobra" @@ -29,9 +28,6 @@ type Builder struct { // AddTxConnFlags adds flags to transaction commands AddTxConnFlags func(*cobra.Command) - - // Cdc is the codec to use for encoding and decoding messages. - Cdc codec.Codec } // EnhanceRootCommand enhances the root command with the provided module options. diff --git a/connect/internal/autocli/common.go b/connect/internal/autocli/common.go index 4e27206a..af7b8724 100644 --- a/connect/internal/autocli/common.go +++ b/connect/internal/autocli/common.go @@ -65,7 +65,7 @@ func (b *Builder) buildMethodCommandCommon(descriptor protoreflect.MethodDescrip cmd.RunE = func(cmd *cobra.Command, args []string) error { // set keyring in context - k, err := keyring.NewKeyringFromFlags(cmd.Flags(), b.AddressCodec, cmd.InOrStdin(), b.Cdc) + k, err := keyring.NewIgniteKeyring(cmd.Flags(), cmd.InOrStdin()) if err != nil { return err } diff --git a/connect/internal/autocli/common_test.go b/connect/internal/autocli/common_test.go index eb82073c..dca925cb 100644 --- a/connect/internal/autocli/common_test.go +++ b/connect/internal/autocli/common_test.go @@ -87,7 +87,6 @@ func initFixture(t *testing.T) *fixture { }, AddQueryConnFlags: flags.AddQueryFlagsToCmd, AddTxConnFlags: addTxAndGlobalFlagsToCmd, - Cdc: encodingConfig.Codec, Config: &chains.ChainConfig{}, } assert.NilError(t, b.Validate()) diff --git a/connect/internal/autocli/keyring/keyring.go b/connect/internal/autocli/keyring/keyring.go index 66d94b23..cc506d0e 100644 --- a/connect/internal/autocli/keyring/keyring.go +++ b/connect/internal/autocli/keyring/keyring.go @@ -9,9 +9,7 @@ import ( "github.com/ignite/cli/v28/ignite/pkg/cosmosaccount" signingv1beta1 "cosmossdk.io/api/cosmos/tx/signing/v1beta1" - "cosmossdk.io/core/address" - "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/crypto/types" ) @@ -28,25 +26,27 @@ type KeyringImpl struct { k Keyring } -// NewKeyringFromFlags creates a new keyring instance based on command-line flags. -func NewKeyringFromFlags( +// NewIgniteKeyring creates a new keyring instance based on command-line flags. +func NewIgniteKeyring( flagSet *pflag.FlagSet, - ac address.Codec, input io.Reader, - cdc codec.Codec, - opts ...keyring.Option, ) (*KeyringImpl, error) { - backEnd, err := flagSet.GetString(flags.FlagKeyringBackend) + keyringBackend, err := flagSet.GetString(flags.FlagKeyringBackend) if err != nil { return nil, err + } else if keyringBackend == "" { + keyringBackend = keyring.BackendTest } - k, err := keyring.New("ignitekeyring", backEnd, cosmosaccount.KeyringHome, input, cdc, opts...) + ca, err := cosmosaccount.New( + cosmosaccount.WithKeyringBackend(cosmosaccount.KeyringBackend(keyringBackend)), + cosmosaccount.WithKeyringServiceName("ignitekeyring"), + ) if err != nil { return nil, err } - igniteKeyring, err := keyring.NewAutoCLIKeyring(k) + igniteKeyring, err := keyring.NewAutoCLIKeyring(ca.Keyring) if err != nil { return nil, err } From eff79980385b0db749995a22260f028177890155 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Sat, 22 Feb 2025 21:53:48 +0100 Subject: [PATCH 11/17] kill client context --- connect/cmd/app.go | 5 - connect/go.mod | 6 +- connect/internal/account/retriever.go | 116 +++ connect/internal/autocli/common.go | 15 +- connect/internal/autocli/common_test.go | 25 +- connect/internal/autocli/flag/address.go | 11 +- connect/internal/autocli/keyring/adapter.go | 106 ++ connect/internal/autocli/keyring/interface.go | 3 + connect/internal/autocli/keyring/keyring.go | 46 +- .../internal/autocli/keyring/no_keyring.go | 4 + connect/internal/autocli/msg.go | 40 +- connect/internal/autocli/msg_test.go | 6 +- connect/internal/autocli/query_test.go | 8 +- connect/internal/tx/README.md | 465 +++++++++ connect/internal/tx/broadcaster.go | 15 + connect/internal/tx/comet_broadcaster.go | 196 ++++ connect/internal/tx/comet_client_conn.go | 146 +++ connect/internal/tx/common_test.go | 116 +++ connect/internal/tx/config.go | 325 +++++++ connect/internal/tx/config_test.go | 242 +++++ connect/internal/tx/context.go | 51 + connect/internal/tx/encoder.go | 159 +++ connect/internal/tx/encoder_test.go | 108 +++ connect/internal/tx/factory.go | 757 +++++++++++++++ connect/internal/tx/factory_test.go | 907 ++++++++++++++++++ connect/internal/tx/flags.go | 52 + connect/internal/tx/from.go | 97 ++ connect/internal/tx/signature.go | 197 ++++ connect/internal/tx/signature_test.go | 143 +++ connect/internal/tx/tx.go | 312 ++++++ connect/internal/tx/types.go | 218 +++++ connect/internal/tx/wrapper.go | 139 +++ 32 files changed, 4926 insertions(+), 110 deletions(-) create mode 100644 connect/internal/account/retriever.go create mode 100644 connect/internal/autocli/keyring/adapter.go create mode 100644 connect/internal/tx/README.md create mode 100644 connect/internal/tx/broadcaster.go create mode 100644 connect/internal/tx/comet_broadcaster.go create mode 100644 connect/internal/tx/comet_client_conn.go create mode 100644 connect/internal/tx/common_test.go create mode 100644 connect/internal/tx/config.go create mode 100644 connect/internal/tx/config_test.go create mode 100644 connect/internal/tx/context.go create mode 100644 connect/internal/tx/encoder.go create mode 100644 connect/internal/tx/encoder_test.go create mode 100644 connect/internal/tx/factory.go create mode 100644 connect/internal/tx/factory_test.go create mode 100644 connect/internal/tx/flags.go create mode 100644 connect/internal/tx/from.go create mode 100644 connect/internal/tx/signature.go create mode 100644 connect/internal/tx/signature_test.go create mode 100644 connect/internal/tx/tx.go create mode 100644 connect/internal/tx/types.go create mode 100644 connect/internal/tx/wrapper.go diff --git a/connect/cmd/app.go b/connect/cmd/app.go index eeedb510..3f70ef3f 100644 --- a/connect/cmd/app.go +++ b/connect/cmd/app.go @@ -6,7 +6,6 @@ import ( "strings" "cosmossdk.io/core/address" - "github.com/cosmos/cosmos-sdk/client" sdkflags "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/grpc/cmtservice" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" @@ -62,10 +61,6 @@ func AppHandler(ctx context.Context, name string, cfg *chains.ChainConfig, args AddTxConnFlags: sdkflags.AddTxFlagsToCmd, } - // add client context - clientCtx := client.Context{} - chainCmd.SetContext(context.WithValue(ctx, client.ClientContextKey, &clientCtx)) - // add comet commands cometCmds := cmtservice.NewCometBFTCommands() conn.ModuleOptions[cometCmds.Name()] = cometCmds.AutoCLIOptions() diff --git a/connect/go.mod b/connect/go.mod index 3987aecc..e7edc727 100644 --- a/connect/go.mod +++ b/connect/go.mod @@ -5,12 +5,15 @@ go 1.23.0 require ( cosmossdk.io/api v0.7.6 cosmossdk.io/core v0.11.1 + cosmossdk.io/errors v1.0.1 cosmossdk.io/math v1.4.0 cosmossdk.io/x/tx v0.13.8 github.com/charmbracelet/bubbles v0.7.6 github.com/charmbracelet/bubbletea v1.2.4 + github.com/cometbft/cometbft v0.38.15 github.com/cosmos/cosmos-proto v1.0.0-beta.5 github.com/cosmos/cosmos-sdk v0.50.11 + github.com/cosmos/go-bip39 v1.0.0 github.com/cosmos/gogoproto v1.7.0 github.com/hashicorp/go-plugin v1.6.1 github.com/ignite/cli/v28 v28.7.1-0.20250116085640-fcf01a4e4b39 @@ -28,7 +31,6 @@ require ( require ( cosmossdk.io/collections v0.4.0 // indirect cosmossdk.io/depinject v1.1.0 // indirect - cosmossdk.io/errors v1.0.1 // indirect cosmossdk.io/log v1.4.1 // indirect cosmossdk.io/store v1.1.1 // indirect dario.cat/mergo v1.0.0 // indirect @@ -58,11 +60,9 @@ require ( github.com/cockroachdb/pebble v1.1.2 // indirect github.com/cockroachdb/redact v1.1.5 // indirect github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect - github.com/cometbft/cometbft v0.38.15 // indirect github.com/cometbft/cometbft-db v0.14.1 // indirect github.com/cosmos/btcutil v1.0.5 // indirect github.com/cosmos/cosmos-db v1.1.0 // indirect - github.com/cosmos/go-bip39 v1.0.0 // indirect github.com/cosmos/gogogateway v1.2.0 // indirect github.com/cosmos/iavl v1.2.2 // indirect github.com/cosmos/ics23/go v0.11.0 // indirect diff --git a/connect/internal/account/retriever.go b/connect/internal/account/retriever.go new file mode 100644 index 00000000..2cef69f9 --- /dev/null +++ b/connect/internal/account/retriever.go @@ -0,0 +1,116 @@ +package account + +import ( + "context" + "fmt" + "strconv" + + gogogrpc "github.com/cosmos/gogoproto/grpc" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/metadata" + "google.golang.org/grpc/status" + + "cosmossdk.io/core/address" + + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" + sdk "github.com/cosmos/cosmos-sdk/types" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" +) + +// GRPCBlockHeightHeader represents the gRPC header for block height. +const GRPCBlockHeightHeader = "x-cosmos-block-height" + +var _ AccountRetriever = accountRetriever{} + +// Account provides a read-only abstraction over the auth module's AccountI. +type Account interface { + GetAddress() sdk.AccAddress + GetPubKey() cryptotypes.PubKey // can return nil. + GetAccountNumber() uint64 + GetSequence() uint64 +} + +// AccountRetriever defines methods required to retrieve account details necessary for transaction signing. +type AccountRetriever interface { + GetAccount(context.Context, []byte) (Account, error) + GetAccountWithHeight(context.Context, []byte) (Account, int64, error) + EnsureExists(context.Context, []byte) error + GetAccountNumberSequence(context.Context, []byte) (accNum, accSeq uint64, err error) +} + +type accountRetriever struct { + ac address.Codec + conn gogogrpc.ClientConn + registry codectypes.InterfaceRegistry +} + +// NewAccountRetriever creates a new instance of accountRetriever. +func NewAccountRetriever(ac address.Codec, conn gogogrpc.ClientConn, registry codectypes.InterfaceRegistry) *accountRetriever { + return &accountRetriever{ + ac: ac, + conn: conn, + registry: registry, + } +} + +// GetAccount retrieves an account using its address. +func (a accountRetriever) GetAccount(ctx context.Context, addr []byte) (Account, error) { + acc, _, err := a.GetAccountWithHeight(ctx, addr) + return acc, err +} + +// GetAccountWithHeight retrieves an account and its associated block height using the account's address. +func (a accountRetriever) GetAccountWithHeight(ctx context.Context, addr []byte) (Account, int64, error) { + var header metadata.MD + qc := authtypes.NewQueryClient(a.conn) + + addrStr, err := a.ac.BytesToString(addr) + if err != nil { + return nil, 0, err + } + + res, err := qc.Account(ctx, &authtypes.QueryAccountRequest{Address: addrStr}, grpc.Header(&header)) + if err != nil { + return nil, 0, err + } + + blockHeight := header.Get(GRPCBlockHeightHeader) + if len(blockHeight) != 1 { + return nil, 0, fmt.Errorf("unexpected '%s' header length; got %d, expected 1", GRPCBlockHeightHeader, len(blockHeight)) + } + + nBlockHeight, err := strconv.Atoi(blockHeight[0]) + if err != nil { + return nil, 0, fmt.Errorf("failed to parse block height: %w", err) + } + + var acc Account + if err := a.registry.UnpackAny(res.Account, &acc); err != nil { + return nil, 0, err + } + + return acc, int64(nBlockHeight), nil +} + +// EnsureExists checks if an account exists using its address. +func (a accountRetriever) EnsureExists(ctx context.Context, addr []byte) error { + if _, err := a.GetAccount(ctx, addr); err != nil { + return err + } + return nil +} + +// GetAccountNumberSequence retrieves the account number and sequence for an account using its address. +func (a accountRetriever) GetAccountNumberSequence(ctx context.Context, addr []byte) (accNum, accSeq uint64, err error) { + acc, err := a.GetAccount(ctx, addr) + if err != nil { + if status.Code(err) == codes.NotFound { + return 0, 0, nil + } + return 0, 0, err + } + + return acc.GetAccountNumber(), acc.GetSequence(), nil +} diff --git a/connect/internal/autocli/common.go b/connect/internal/autocli/common.go index af7b8724..7a4f9dbb 100644 --- a/connect/internal/autocli/common.go +++ b/connect/internal/autocli/common.go @@ -1,7 +1,6 @@ package autocli import ( - "context" "fmt" "github.com/spf13/cobra" @@ -11,6 +10,7 @@ import ( "github.com/ignite/apps/connect/internal/autocli/keyring" "github.com/ignite/apps/connect/internal/flags" "github.com/ignite/apps/connect/internal/print" + "github.com/ignite/apps/connect/internal/tx" "github.com/ignite/apps/connect/internal/util" ) @@ -64,12 +64,19 @@ func (b *Builder) buildMethodCommandCommon(descriptor protoreflect.MethodDescrip cmd.PreRunE = b.preRunE() cmd.RunE = func(cmd *cobra.Command, args []string) error { - // set keyring in context - k, err := keyring.NewIgniteKeyring(cmd.Flags(), cmd.InOrStdin()) + // create context + k, err := keyring.NewKeyring(cmd.Flags(), cmd.InOrStdin(), b.AddressCodec) if err != nil { return err } - cmd.SetContext(context.WithValue(cmd.Context(), keyring.ContextKey, k)) + + cmd.SetContext(tx.SetContext(cmd.Context(), tx.Context{ + Flags: cmd.Flags(), + Keyring: k, + AddressCodec: b.AddressCodec, + ValidatorAddressCodec: b.ValidatorAddressCodec, + ConsensusAddressCodec: b.ConsensusAddressCodec, + })) input, err := binder.BuildMessage(args) if err != nil { diff --git a/connect/internal/autocli/common_test.go b/connect/internal/autocli/common_test.go index dca925cb..f340b9e5 100644 --- a/connect/internal/autocli/common_test.go +++ b/connect/internal/autocli/common_test.go @@ -18,20 +18,17 @@ import ( "github.com/ignite/apps/connect/internal/autocli/flag" "github.com/ignite/apps/connect/internal/testpb" - "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" sdkkeyring "github.com/cosmos/cosmos-sdk/crypto/keyring" - sdk "github.com/cosmos/cosmos-sdk/types" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" "github.com/cosmos/cosmos-sdk/x/bank" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" ) type fixture struct { - conn *testClientConn - b *Builder - clientCtx client.Context + conn *testClientConn + b *Builder home string chainID string @@ -57,22 +54,9 @@ func initFixture(t *testing.T) *fixture { assert.NilError(t, err) encodingConfig := moduletestutil.MakeTestEncodingConfig(bank.AppModule{}) - kr, err := sdkkeyring.New(sdk.KeyringServiceName(), sdkkeyring.BackendMemory, home, nil, encodingConfig.Codec) - assert.NilError(t, err) - interfaceRegistry := encodingConfig.Codec.InterfaceRegistry() banktypes.RegisterInterfaces(interfaceRegistry) - clientCtx := client.Context{}. - WithKeyring(kr). - WithKeyringDir(home). - WithHomeDir(home). - WithViper(""). - WithInterfaceRegistry(interfaceRegistry). - WithTxConfig(encodingConfig.TxConfig). - WithAccountRetriever(client.MockAccountRetriever{}). - WithChainID("autocli-test") - conn := &testClientConn{ClientConn: clientConn} b := &Builder{ Builder: flag.Builder{ @@ -92,9 +76,8 @@ func initFixture(t *testing.T) *fixture { assert.NilError(t, b.Validate()) return &fixture{ - conn: conn, - b: b, - clientCtx: clientCtx, + conn: conn, + b: b, home: home, chainID: "autocli-test", diff --git a/connect/internal/autocli/flag/address.go b/connect/internal/autocli/flag/address.go index 549f5f50..0133c4c7 100644 --- a/connect/internal/autocli/flag/address.go +++ b/connect/internal/autocli/flag/address.go @@ -2,13 +2,13 @@ package flag import ( "context" - "errors" "fmt" "google.golang.org/protobuf/reflect/protoreflect" "cosmossdk.io/core/address" "github.com/ignite/apps/connect/internal/autocli/keyring" + "github.com/ignite/apps/connect/internal/tx" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/types" @@ -154,13 +154,8 @@ func getKeyringFromCtx(ctx *context.Context) keyring.Keyring { return keyring.NoKeyring{} } - if kv := (*ctx).Value(keyring.ContextKey); kv != nil { - k, ok := kv.(*keyring.KeyringImpl) - if !ok { - panic(errors.New("keyring is not of type *keyring.KeyringImpl")) - } - - return k + if txCtx, err := tx.GetContext(*ctx); err == nil { + return txCtx.Keyring } return keyring.NoKeyring{} diff --git a/connect/internal/autocli/keyring/adapter.go b/connect/internal/autocli/keyring/adapter.go new file mode 100644 index 00000000..c53848c5 --- /dev/null +++ b/connect/internal/autocli/keyring/adapter.go @@ -0,0 +1,106 @@ +package keyring + +import ( + signingv1beta1 "cosmossdk.io/api/cosmos/tx/signing/v1beta1" + "cosmossdk.io/core/address" + + "github.com/cosmos/cosmos-sdk/crypto/keyring" + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/tx/signing" +) + +// NewAutoCLIKeyring wraps the SDK keyring and make it compatible with the AutoCLI keyring interfaces. +func NewAutoCLIKeyring(kr keyring.Keyring, ac address.Codec) (Keyring, error) { + return &autoCLIKeyringAdapter{kr, ac}, nil +} + +type autoCLIKeyringAdapter struct { + keyring.Keyring + ac address.Codec +} + +func (a *autoCLIKeyringAdapter) List() ([]string, error) { + list, err := a.Keyring.List() + if err != nil { + return nil, err + } + + names := make([]string, len(list)) + for i, key := range list { + names[i] = key.Name + } + + return names, nil +} + +// LookupAddressByKeyName returns the address of a key stored in the keyring +func (a *autoCLIKeyringAdapter) LookupAddressByKeyName(name string) ([]byte, error) { + record, err := a.Keyring.Key(name) + if err != nil { + return nil, err + } + + addr, err := record.GetAddress() + if err != nil { + return nil, err + } + + return addr, nil +} + +func (a *autoCLIKeyringAdapter) GetPubKey(name string) (cryptotypes.PubKey, error) { + record, err := a.Keyring.Key(name) + if err != nil { + return nil, err + } + + return record.GetPubKey() +} + +func (a *autoCLIKeyringAdapter) Sign(name string, msg []byte, signMode signingv1beta1.SignMode) ([]byte, error) { + record, err := a.Keyring.Key(name) + if err != nil { + return nil, err + } + + signBytes, _, err := a.Keyring.Sign(record.Name, msg, signing.SignMode(signMode)) + return signBytes, err +} + +func (a *autoCLIKeyringAdapter) KeyType(name string) (uint, error) { + record, err := a.Keyring.Key(name) + if err != nil { + return 0, err + } + + return uint(record.GetType()), nil +} + +func (a *autoCLIKeyringAdapter) KeyInfo(nameOrAddr string) (string, string, uint, error) { + addr, err := a.ac.StringToBytes(nameOrAddr) + if err != nil { + // If conversion fails, it's likely a name, not an address + record, err := a.Keyring.Key(nameOrAddr) + if err != nil { + return "", "", 0, err + } + addr, err = record.GetAddress() + if err != nil { + return "", "", 0, err + } + addrStr, err := a.ac.BytesToString(addr) + if err != nil { + return "", "", 0, err + } + return record.Name, addrStr, uint(record.GetType()), nil + } + + // If conversion succeeds, it's an address, get the key info by address + record, err := a.Keyring.KeyByAddress(sdk.AccAddress(addr)) + if err != nil { + return "", "", 0, err + } + + return record.Name, nameOrAddr, uint(record.GetType()), nil +} diff --git a/connect/internal/autocli/keyring/interface.go b/connect/internal/autocli/keyring/interface.go index fa448bd2..70cd1b2c 100644 --- a/connect/internal/autocli/keyring/interface.go +++ b/connect/internal/autocli/keyring/interface.go @@ -20,4 +20,7 @@ type Keyring interface { // Sign signs the given bytes with the key with the given name. Sign(name string, msg []byte, signMode signingv1beta1.SignMode) ([]byte, error) + + // KeyInfo given a key name or address returns key name, key address and key type. + KeyInfo(nameOrAddr string) (string, string, uint, error) } diff --git a/connect/internal/autocli/keyring/keyring.go b/connect/internal/autocli/keyring/keyring.go index cc506d0e..366452f9 100644 --- a/connect/internal/autocli/keyring/keyring.go +++ b/connect/internal/autocli/keyring/keyring.go @@ -8,29 +8,17 @@ import ( "github.com/ignite/apps/connect/internal/flags" "github.com/ignite/cli/v28/ignite/pkg/cosmosaccount" - signingv1beta1 "cosmossdk.io/api/cosmos/tx/signing/v1beta1" + "cosmossdk.io/core/address" "github.com/cosmos/cosmos-sdk/crypto/keyring" - "github.com/cosmos/cosmos-sdk/crypto/types" ) -// ContextKey is the key used to store the keyring in the context. -// The keyring must be wrapped using the KeyringImpl. -var ContextKey keyringContextKey - -type keyringContextKey struct{} - -var _ Keyring = &KeyringImpl{} - -type KeyringImpl struct { - k Keyring -} - -// NewIgniteKeyring creates a new keyring instance based on command-line flags. -func NewIgniteKeyring( +// NewKeyring creates a new keyring instance based on command-line flags. +func NewKeyring( flagSet *pflag.FlagSet, input io.Reader, -) (*KeyringImpl, error) { + addressCodec address.Codec, +) (Keyring, error) { keyringBackend, err := flagSet.GetString(flags.FlagKeyringBackend) if err != nil { return nil, err @@ -46,30 +34,10 @@ func NewIgniteKeyring( return nil, err } - igniteKeyring, err := keyring.NewAutoCLIKeyring(ca.Keyring) + igniteKeyring, err := NewAutoCLIKeyring(ca.Keyring, addressCodec) if err != nil { return nil, err } - return &KeyringImpl{k: igniteKeyring}, nil -} - -// GetPubKey implements Keyring. -func (k *KeyringImpl) GetPubKey(name string) (types.PubKey, error) { - return k.k.GetPubKey(name) -} - -// List implements Keyring. -func (k *KeyringImpl) List() ([]string, error) { - return k.k.List() -} - -// LookupAddressByKeyName implements Keyring. -func (k *KeyringImpl) LookupAddressByKeyName(name string) ([]byte, error) { - return k.k.LookupAddressByKeyName(name) -} - -// Sign implements Keyring. -func (k *KeyringImpl) Sign(name string, msg []byte, signMode signingv1beta1.SignMode) ([]byte, error) { - return k.k.Sign(name, msg, signMode) + return igniteKeyring, nil } diff --git a/connect/internal/autocli/keyring/no_keyring.go b/connect/internal/autocli/keyring/no_keyring.go index e14267ce..3ee5243b 100644 --- a/connect/internal/autocli/keyring/no_keyring.go +++ b/connect/internal/autocli/keyring/no_keyring.go @@ -29,3 +29,7 @@ func (k NoKeyring) GetPubKey(name string) (cryptotypes.PubKey, error) { func (k NoKeyring) Sign(name string, msg []byte, signMode signingv1beta1.SignMode) ([]byte, error) { return nil, errNoKeyring } + +func (k NoKeyring) KeyInfo(nameOrAddr string) (string, string, uint, error) { + return "", "", 0, errNoKeyring +} diff --git a/connect/internal/autocli/msg.go b/connect/internal/autocli/msg.go index 21f68642..1b3b2ad4 100644 --- a/connect/internal/autocli/msg.go +++ b/connect/internal/autocli/msg.go @@ -14,10 +14,9 @@ import ( "github.com/ignite/apps/connect/internal/autocli/flag" "github.com/ignite/apps/connect/internal/flags" "github.com/ignite/apps/connect/internal/governance" + "github.com/ignite/apps/connect/internal/tx" "github.com/ignite/apps/connect/internal/util" - "github.com/cosmos/cosmos-sdk/client" - clienttx "github.com/cosmos/cosmos-sdk/client/tx" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" ) @@ -114,21 +113,13 @@ func (b *Builder) AddMsgServiceCommands(cmd *cobra.Command, cmdDescriptor *autoc // BuildMsgMethodCommand returns a command that outputs the JSON representation of the message. func (b *Builder) BuildMsgMethodCommand(descriptor protoreflect.MethodDescriptor, options *autocliv1.RpcCommandOptions) (*cobra.Command, error) { execFunc := func(cmd *cobra.Command, input protoreflect.Message) error { - clientCtx, err := client.GetClientTxContext(cmd) - if err != nil { - return err - } - - clientCtx = clientCtx.WithCmdContext(cmd.Context()) - clientCtx = clientCtx.WithOutput(cmd.OutOrStdout()) - fd := input.Descriptor().Fields().ByName(protoreflect.Name(flag.GetSignerFieldName(input.Descriptor()))) addressCodec := b.Builder.AddressCodec // handle gov proposals commands skipProposal, _ := cmd.Flags().GetBool(flags.FlagNoProposal) if isProposalMessage(descriptor.Input()) && !skipProposal { - return b.handleGovProposal(cmd, input, clientCtx, addressCodec, fd) + return b.handleGovProposal(cmd, input, addressCodec, fd) } // set signer to signer field if empty @@ -144,10 +135,9 @@ func (b *Builder) BuildMsgMethodCommand(descriptor protoreflect.MethodDescriptor } } - signerFromFlag := clientCtx.GetFromAddress() - signer, err := addressCodec.BytesToString(signerFromFlag.Bytes()) + signer, err := tx.GetFromAddress(cmd) if err != nil { - return fmt.Errorf("failed to set signer on message, got %v: %w", signerFromFlag, err) + return fmt.Errorf("failed to get from address: %w", err) } input.Set(fd, protoreflect.ValueOfString(signer)) @@ -159,7 +149,12 @@ func (b *Builder) BuildMsgMethodCommand(descriptor protoreflect.MethodDescriptor msg := dynamicpb.NewMessage(input.Descriptor()) proto.Merge(msg, input.Interface()) - return clienttx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + out, err := tx.GenerateAndBroadcastTxCLI(cmd.Context(), nil /* TODO */, msg) + if err != nil { + return err + } + + return b.outOrStdoutFormat(cmd, out) } cmd, err := b.buildMethodCommandCommon(descriptor, options, execFunc) @@ -187,7 +182,6 @@ func (b *Builder) BuildMsgMethodCommand(descriptor protoreflect.MethodDescriptor func (b *Builder) handleGovProposal( cmd *cobra.Command, input protoreflect.Message, - clientCtx client.Context, addressCodec addresscodec.Codec, fd protoreflect.FieldDescriptor, ) error { @@ -198,13 +192,12 @@ func (b *Builder) handleGovProposal( } input.Set(fd, protoreflect.ValueOfString(authority)) - signerFromFlag := clientCtx.GetFromAddress() - signer, err := addressCodec.BytesToString(signerFromFlag.Bytes()) + signerFromFlag, err := tx.GetFromAddress(cmd) if err != nil { - return fmt.Errorf("failed to set signer on message, got %q: %w", signerFromFlag, err) + return fmt.Errorf("failed to get from address: %w", err) } - proposal, err := governance.ReadGovPropCmdFlags(signer, cmd.Flags()) + proposal, err := governance.ReadGovPropCmdFlags(signerFromFlag, cmd.Flags()) if err != nil { return err } @@ -219,7 +212,12 @@ func (b *Builder) handleGovProposal( return fmt.Errorf("failed to set msg in proposal %w", err) } - return clienttx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), proposal) + out, err := tx.GenerateAndBroadcastTxCLI(cmd.Context(), nil /* TODO */, proposal) + if err != nil { + return err + } + + return b.outOrStdoutFormat(cmd, out) } // isProposalMessage checks the msg name against well known proposal messages. diff --git a/connect/internal/autocli/msg_test.go b/connect/internal/autocli/msg_test.go index c36eaf73..751219cb 100644 --- a/connect/internal/autocli/msg_test.go +++ b/connect/internal/autocli/msg_test.go @@ -16,12 +16,10 @@ import ( autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" bankv1beta1 "cosmossdk.io/api/cosmos/bank/v1beta1" "github.com/ignite/apps/connect/internal/testpb" - - "github.com/cosmos/cosmos-sdk/client" ) var buildModuleMsgCommand = func(moduleName string, f *fixture) (*cobra.Command, error) { - ctx := context.WithValue(context.Background(), client.ClientContextKey, &f.clientCtx) + ctx := context.TODO() cmd := topLevelCmd(ctx, moduleName, fmt.Sprintf("Transactions commands for the %s module", moduleName)) err := f.b.AddMsgServiceCommands(cmd, bankAutoCLI) return cmd, err @@ -29,7 +27,7 @@ var buildModuleMsgCommand = func(moduleName string, f *fixture) (*cobra.Command, func buildCustomModuleMsgCommand(cmdDescriptor *autocliv1.ServiceCommandDescriptor) func(moduleName string, f *fixture) (*cobra.Command, error) { return func(moduleName string, f *fixture) (*cobra.Command, error) { - ctx := context.WithValue(context.Background(), client.ClientContextKey, &f.clientCtx) + ctx := context.TODO() cmd := topLevelCmd(ctx, moduleName, fmt.Sprintf("Transactions commands for the %s module", moduleName)) err := f.b.AddMsgServiceCommands(cmd, cmdDescriptor) return cmd, err diff --git a/connect/internal/autocli/query_test.go b/connect/internal/autocli/query_test.go index 09892fdd..85894a38 100644 --- a/connect/internal/autocli/query_test.go +++ b/connect/internal/autocli/query_test.go @@ -19,12 +19,10 @@ import ( queryv1beta1 "cosmossdk.io/api/cosmos/base/query/v1beta1" basev1beta1 "cosmossdk.io/api/cosmos/base/v1beta1" "github.com/ignite/apps/connect/internal/testpb" - - "github.com/cosmos/cosmos-sdk/client" ) var buildModuleQueryCommand = func(moduleName string, f *fixture) (*cobra.Command, error) { - ctx := context.WithValue(context.Background(), client.ClientContextKey, &f.clientCtx) + ctx := context.TODO() cmd := topLevelCmd(ctx, moduleName, fmt.Sprintf("Querying commands for the %s module", moduleName)) err := f.b.AddQueryServiceCommands(cmd, testCmdDesc) @@ -32,7 +30,7 @@ var buildModuleQueryCommand = func(moduleName string, f *fixture) (*cobra.Comman } var buildModuleQueryCommandOptional = func(moduleName string, f *fixture) (*cobra.Command, error) { - ctx := context.WithValue(context.Background(), client.ClientContextKey, &f.clientCtx) + ctx := context.TODO() cmd := topLevelCmd(ctx, moduleName, fmt.Sprintf("Querying commands for the %s module", moduleName)) err := f.b.AddQueryServiceCommands(cmd, testCmdDescOptional) @@ -40,7 +38,7 @@ var buildModuleQueryCommandOptional = func(moduleName string, f *fixture) (*cobr } var buildModuleVargasOptional = func(moduleName string, f *fixture) (*cobra.Command, error) { - ctx := context.WithValue(context.Background(), client.ClientContextKey, &f.clientCtx) + ctx := context.TODO() cmd := topLevelCmd(ctx, moduleName, fmt.Sprintf("Querying commands for the %s module", moduleName)) err := f.b.AddQueryServiceCommands(cmd, testCmdDescInvalidOptAndVargas) diff --git a/connect/internal/tx/README.md b/connect/internal/tx/README.md new file mode 100644 index 00000000..6d196b1e --- /dev/null +++ b/connect/internal/tx/README.md @@ -0,0 +1,465 @@ +The tx package provides a robust set of tools for building, signing, and managing transactions in a Cosmos SDK-based blockchain application. + +## Overview + +This package includes several key components: + +1. Transaction Factory +2. Transaction Config +3. Transaction Encoder/Decoder +4. Signature Handling + +## Architecture + +```mermaid +graph TD + A[Client] --> B[Factory] + B --> D[TxConfig] + D --> E[TxEncodingConfig] + D --> F[TxSigningConfig] + B --> G[Tx] + G --> H[Encoder] + G --> I[Decoder] + F --> J[SignModeHandler] + F --> K[SigningContext] + B --> L[AuxTxBuilder] +``` + +## Key Components + +### TxConfig + +`TxConfig` provides configuration for transaction handling, including: + +- Encoding and decoding +- Sign mode handling +- Signature JSON marshaling/unmarshaling + +```mermaid +classDiagram + class TxConfig { + <> + TxEncodingConfig + TxSigningConfig + } + + class TxEncodingConfig { + <> + TxEncoder() txEncoder + TxDecoder() txDecoder + TxJSONEncoder() txEncoder + TxJSONDecoder() txDecoder + Decoder() Decoder + } + + class TxSigningConfig { + <> + SignModeHandler() *signing.HandlerMap + SigningContext() *signing.Context + MarshalSignatureJSON([]Signature) ([]byte, error) + UnmarshalSignatureJSON([]byte) ([]Signature, error) + } + + class txConfig { + TxEncodingConfig + TxSigningConfig + } + + class defaultEncodingConfig { + cdc codec.BinaryCodec + decoder Decoder + TxEncoder() txEncoder + TxDecoder() txDecoder + TxJSONEncoder() txEncoder + TxJSONDecoder() txDecoder + } + + class defaultTxSigningConfig { + signingCtx *signing.Context + handlerMap *signing.HandlerMap + cdc codec.BinaryCodec + SignModeHandler() *signing.HandlerMap + SigningContext() *signing.Context + MarshalSignatureJSON([]Signature) ([]byte, error) + UnmarshalSignatureJSON([]byte) ([]Signature, error) + } + + TxConfig <|-- txConfig + TxEncodingConfig <|.. defaultEncodingConfig + TxSigningConfig <|.. defaultTxSigningConfig + txConfig *-- defaultEncodingConfig + txConfig *-- defaultTxSigningConfig +``` + +### Factory + +The `Factory` is the main entry point for creating and managing transactions. It handles: + +- Account preparation +- Gas calculation +- Unsigned transaction building +- Transaction signing +- Transaction simulation +- Transaction broadcasting + +```mermaid +classDiagram + class Factory { + keybase keyring.Keyring + cdc codec.BinaryCodec + accountRetriever account.AccountRetriever + ac address.Codec + conn gogogrpc.ClientConn + txConfig TxConfig + txParams TxParameters + tx txState + + NewFactory(keybase, cdc, accRetriever, txConfig, ac, conn, parameters) Factory + Prepare() error + BuildUnsignedTx(msgs ...sdk.Msg) error + BuildsSignedTx(ctx context.Context, msgs ...sdk.Msg) (Tx, error) + calculateGas(msgs ...sdk.Msg) error + Simulate(msgs ...sdk.Msg) (*apitx.SimulateResponse, uint64, error) + UnsignedTxString(msgs ...sdk.Msg) (string, error) + BuildSimTx(msgs ...sdk.Msg) ([]byte, error) + sign(ctx context.Context, overwriteSig bool) (Tx, error) + WithGas(gas uint64) + WithSequence(sequence uint64) + WithAccountNumber(accnum uint64) + getTx() (Tx, error) + getFee() (*apitx.Fee, error) + getSigningTxData() (signing.TxData, error) + setSignatures(...Signature) error + } + + class TxParameters { + <> + chainID string + AccountConfig + GasConfig + FeeConfig + SignModeConfig + TimeoutConfig + MemoConfig + } + + class TxConfig { + <> + } + + class Tx { + <> + } + + class txState { + <> + msgs []sdk.Msg + memo string + fees []*base.Coin + gasLimit uint64 + feeGranter []byte + feePayer []byte + timeoutHeight uint64 + unordered bool + timeoutTimestamp uint64 + signatures []Signature + signerInfos []*apitx.SignerInfo + } + + Factory *-- TxParameters + Factory *-- TxConfig + Factory *-- txState + Factory ..> Tx : creates +``` + +### Encoder/Decoder + +The package includes functions for encoding and decoding transactions in both binary and JSON formats. + +```mermaid +classDiagram + class Decoder { + <> + Decode(txBytes []byte) (*txdecode.DecodedTx, error) + } + + class txDecoder { + <> + decode(txBytes []byte) (Tx, error) + } + + class txEncoder { + <> + encode(tx Tx) ([]byte, error) + } + + class EncoderUtils { + <> + decodeTx(cdc codec.BinaryCodec, decoder Decoder) txDecoder + encodeTx(tx Tx) ([]byte, error) + decodeJsonTx(cdc codec.BinaryCodec, decoder Decoder) txDecoder + encodeJsonTx(tx Tx) ([]byte, error) + protoTxBytes(tx *txv1beta1.Tx) ([]byte, error) + } + + class MarshalOptions { + <> + Deterministic bool + } + + class JSONMarshalOptions { + <> + Indent string + UseProtoNames bool + UseEnumNumbers bool + } + + Decoder <.. EncoderUtils : uses + txDecoder <.. EncoderUtils : creates + txEncoder <.. EncoderUtils : implements + EncoderUtils ..> MarshalOptions : uses + EncoderUtils ..> JSONMarshalOptions : uses +``` + +### Sequence Diagrams + +#### Generate Aux Signer Data +```mermaid +sequenceDiagram + participant User + participant GenerateOrBroadcastTxCLI + participant generateAuxSignerData + participant makeAuxSignerData + participant AuxTxBuilder + participant ctx.PrintProto + + User->>GenerateOrBroadcastTxCLI: Call with isAux flag + GenerateOrBroadcastTxCLI->>generateAuxSignerData: Call + + generateAuxSignerData->>makeAuxSignerData: Call + makeAuxSignerData->>AuxTxBuilder: NewAuxTxBuilder() + + makeAuxSignerData->>AuxTxBuilder: SetAddress(f.txParams.fromAddress) + + alt f.txParams.offline + makeAuxSignerData->>AuxTxBuilder: SetAccountNumber(f.AccountNumber()) + makeAuxSignerData->>AuxTxBuilder: SetSequence(f.Sequence()) + else + makeAuxSignerData->>f.accountRetriever: GetAccountNumberSequence() + makeAuxSignerData->>AuxTxBuilder: SetAccountNumber(accNum) + makeAuxSignerData->>AuxTxBuilder: SetSequence(seq) + end + + makeAuxSignerData->>AuxTxBuilder: SetMsgs(msgs...) + makeAuxSignerData->>AuxTxBuilder: SetSignMode(f.SignMode()) + + makeAuxSignerData->>f.keybase: GetPubKey(f.txParams.fromName) + makeAuxSignerData->>AuxTxBuilder: SetPubKey(pubKey) + + makeAuxSignerData->>AuxTxBuilder: SetChainID(f.txParams.chainID) + makeAuxSignerData->>AuxTxBuilder: GetSignBytes() + + makeAuxSignerData->>f.keybase: Sign(f.txParams.fromName, signBz, f.SignMode()) + makeAuxSignerData->>AuxTxBuilder: SetSignature(sig) + + makeAuxSignerData->>AuxTxBuilder: GetAuxSignerData() + AuxTxBuilder-->>makeAuxSignerData: Return AuxSignerData + makeAuxSignerData-->>generateAuxSignerData: Return AuxSignerData + + generateAuxSignerData->>ctx.PrintProto: Print AuxSignerData + ctx.PrintProto-->>GenerateOrBroadcastTxCLI: Return result + GenerateOrBroadcastTxCLI-->>User: Return result +``` + +#### Generate Only +```mermaid +sequenceDiagram + participant User + participant GenerateOrBroadcastTxCLI + participant generateOnly + participant Factory + participant ctx.PrintString + + User->>GenerateOrBroadcastTxCLI: Call with generateOnly flag + GenerateOrBroadcastTxCLI->>generateOnly: Call + + generateOnly->>Factory: Prepare() + alt Error in Prepare + Factory-->>generateOnly: Return error + generateOnly-->>GenerateOrBroadcastTxCLI: Return error + GenerateOrBroadcastTxCLI-->>User: Return error + end + + generateOnly->>Factory: UnsignedTxString(msgs...) + Factory->>Factory: BuildUnsignedTx(msgs...) + Factory->>Factory: setMsgs(msgs...) + Factory->>Factory: setMemo(f.txParams.memo) + Factory->>Factory: setFees(f.txParams.gasPrices) + Factory->>Factory: setGasLimit(f.txParams.gas) + Factory->>Factory: setFeeGranter(f.txParams.feeGranter) + Factory->>Factory: setFeePayer(f.txParams.feePayer) + Factory->>Factory: setTimeoutHeight(f.txParams.timeoutHeight) + + Factory->>Factory: getTx() + Factory->>Factory: txConfig.TxJSONEncoder() + Factory->>Factory: encoder(tx) + + Factory-->>generateOnly: Return unsigned tx string + generateOnly->>ctx.PrintString: Print unsigned tx string + ctx.PrintString-->>generateOnly: Return result + generateOnly-->>GenerateOrBroadcastTxCLI: Return result + GenerateOrBroadcastTxCLI-->>User: Return result +``` + +#### DryRun +```mermaid +sequenceDiagram + participant User + participant GenerateOrBroadcastTxCLI + participant dryRun + participant Factory + participant os.Stderr + + User->>GenerateOrBroadcastTxCLI: Call with dryRun flag + GenerateOrBroadcastTxCLI->>dryRun: Call + + dryRun->>Factory: Prepare() + alt Error in Prepare + Factory-->>dryRun: Return error + dryRun-->>GenerateOrBroadcastTxCLI: Return error + GenerateOrBroadcastTxCLI-->>User: Return error + end + + dryRun->>Factory: Simulate(msgs...) + Factory->>Factory: BuildSimTx(msgs...) + Factory->>Factory: BuildUnsignedTx(msgs...) + Factory->>Factory: getSimPK() + Factory->>Factory: getSimSignatureData(pk) + Factory->>Factory: setSignatures(sig) + Factory->>Factory: getTx() + Factory->>Factory: txConfig.TxEncoder()(tx) + + Factory->>ServiceClient: Simulate(context.Background(), &apitx.SimulateRequest{}) + ServiceClient->>Factory: Return result + + Factory-->>dryRun: Return (simulation, gas, error) + alt Error in Simulate + dryRun-->>GenerateOrBroadcastTxCLI: Return error + GenerateOrBroadcastTxCLI-->>User: Return error + end + + dryRun->>os.Stderr: Fprintf(GasEstimateResponse{GasEstimate: gas}) + os.Stderr-->>dryRun: Return result + dryRun-->>GenerateOrBroadcastTxCLI: Return result + GenerateOrBroadcastTxCLI-->>User: Return result +``` + +#### Generate and Broadcast Tx +```mermaid +sequenceDiagram + participant User + participant GenerateOrBroadcastTxCLI + participant BroadcastTx + participant Factory + participant clientCtx + + User->>GenerateOrBroadcastTxCLI: Call + GenerateOrBroadcastTxCLI->>BroadcastTx: Call + + BroadcastTx->>Factory: Prepare() + alt Error in Prepare + Factory-->>BroadcastTx: Return error + BroadcastTx-->>GenerateOrBroadcastTxCLI: Return error + GenerateOrBroadcastTxCLI-->>User: Return error + end + + alt SimulateAndExecute is true + BroadcastTx->>Factory: calculateGas(msgs...) + Factory->>Factory: Simulate(msgs...) + Factory->>Factory: WithGas(adjusted) + end + + BroadcastTx->>Factory: BuildUnsignedTx(msgs...) + Factory->>Factory: setMsgs(msgs...) + Factory->>Factory: setMemo(f.txParams.memo) + Factory->>Factory: setFees(f.txParams.gasPrices) + Factory->>Factory: setGasLimit(f.txParams.gas) + Factory->>Factory: setFeeGranter(f.txParams.feeGranter) + Factory->>Factory: setFeePayer(f.txParams.feePayer) + Factory->>Factory: setTimeoutHeight(f.txParams.timeoutHeight) + + alt !clientCtx.SkipConfirm + BroadcastTx->>Factory: getTx() + BroadcastTx->>Factory: txConfig.TxJSONEncoder() + BroadcastTx->>clientCtx: PrintRaw(txBytes) + BroadcastTx->>clientCtx: Input.GetConfirmation() + alt Not confirmed + BroadcastTx-->>GenerateOrBroadcastTxCLI: Return error + GenerateOrBroadcastTxCLI-->>User: Return error + end + end + + BroadcastTx->>Factory: BuildsSignedTx(ctx, msgs...) + Factory->>Factory: sign(ctx, true) + Factory->>Factory: keybase.GetPubKey(fromName) + Factory->>Factory: getSignBytesAdapter() + Factory->>Factory: keybase.Sign(fromName, bytesToSign, signMode) + Factory->>Factory: setSignatures(sig) + Factory->>Factory: getTx() + + BroadcastTx->>Factory: txConfig.TxEncoder() + BroadcastTx->>clientCtx: BroadcastTx(txBytes) + + alt Error in BroadcastTx + clientCtx-->>BroadcastTx: Return error + BroadcastTx-->>GenerateOrBroadcastTxCLI: Return error + GenerateOrBroadcastTxCLI-->>User: Return error + end + + BroadcastTx->>clientCtx: OutputTx(res) + clientCtx-->>BroadcastTx: Return result + BroadcastTx-->>GenerateOrBroadcastTxCLI: Return result + GenerateOrBroadcastTxCLI-->>User: Return result +``` + +## Usage + +To use the `tx` package, typically you would: + +1. Create a `Factory` +2. Simulate the transaction (optional) +3. Build a signed transaction +4. Encode the transaction +5. Broadcast the transaction + +Here's a simplified example: + +```go +// Create a Factory +factory, err := NewFactory(keybase, cdc, accountRetriever, txConfig, addressCodec, conn, txParameters) +if err != nil { + return err +} + +// Simulate the transaction (optional) +simRes, gas, err := factory.Simulate(msgs...) +if err != nil { + return err +} +factory.WithGas(gas) + +// Build a signed transaction +signedTx, err := factory.BuildsSignedTx(context.Background(), msgs...) +if err != nil { + return err +} + +// Encode the transaction +txBytes, err := factory.txConfig.TxEncoder()(signedTx) +if err != nil { + return err +} + +// Broadcast the transaction +// (This step depends on your specific client implementation) +``` \ No newline at end of file diff --git a/connect/internal/tx/broadcaster.go b/connect/internal/tx/broadcaster.go new file mode 100644 index 00000000..7f871d5e --- /dev/null +++ b/connect/internal/tx/broadcaster.go @@ -0,0 +1,15 @@ +package tx + +import "context" + +// Broadcaster defines an interface for broadcasting transactions to the consensus engine. +type Broadcaster interface { + // Broadcast sends a transaction to the network and returns the result. + // + // It returns a byte slice containing the formatted result that will be + // passed to the output writer, and an error if the broadcast failed. + Broadcast(ctx context.Context, txBytes []byte) ([]byte, error) + + // Consensus returns the consensus engine identifier for this Broadcaster. + Consensus() string +} diff --git a/connect/internal/tx/comet_broadcaster.go b/connect/internal/tx/comet_broadcaster.go new file mode 100644 index 00000000..a66a7802 --- /dev/null +++ b/connect/internal/tx/comet_broadcaster.go @@ -0,0 +1,196 @@ +package tx + +import ( + "context" + "encoding/json" + "errors" + "fmt" + "strings" + + "github.com/cometbft/cometbft/mempool" + rpcclient "github.com/cometbft/cometbft/rpc/client" + rpchttp "github.com/cometbft/cometbft/rpc/client/http" + coretypes "github.com/cometbft/cometbft/rpc/core/types" + cmttypes "github.com/cometbft/cometbft/types" + + apiacbci "cosmossdk.io/api/cosmos/base/abci/v1beta1" + + "github.com/cosmos/cosmos-sdk/codec" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" +) + +const ( + // BroadcastSync defines a tx broadcasting mode where the client waits for + // a CheckTx execution response only. + BroadcastSync = "sync" + // BroadcastAsync defines a tx broadcasting mode where the client returns + // immediately. + BroadcastAsync = "async" + + // cometBftConsensus is the identifier for the CometBFT consensus engine. + cometBFTConsensus = "comet" +) + +// CometRPC defines the interface of a CometBFT RPC client needed for +// queries and transaction handling. +type CometRPC interface { + rpcclient.ABCIClient + + Validators(ctx context.Context, height *int64, page, perPage *int) (*coretypes.ResultValidators, error) + Status(context.Context) (*coretypes.ResultStatus, error) + Block(ctx context.Context, height *int64) (*coretypes.ResultBlock, error) + BlockByHash(ctx context.Context, hash []byte) (*coretypes.ResultBlock, error) + BlockResults(ctx context.Context, height *int64) (*coretypes.ResultBlockResults, error) + BlockchainInfo(ctx context.Context, minHeight, maxHeight int64) (*coretypes.ResultBlockchainInfo, error) + Commit(ctx context.Context, height *int64) (*coretypes.ResultCommit, error) + Tx(ctx context.Context, hash []byte, prove bool) (*coretypes.ResultTx, error) + TxSearch( + ctx context.Context, + query string, + prove bool, + page, perPage *int, + orderBy string, + ) (*coretypes.ResultTxSearch, error) + BlockSearch( + ctx context.Context, + query string, + page, perPage *int, + orderBy string, + ) (*coretypes.ResultBlockSearch, error) +} + +// CometBFTBroadcaster implements the Broadcaster interface for CometBFT consensus engine. +type CometBFTBroadcaster struct { + rpcClient CometRPC + mode string + cdc codec.Codec +} + +// NewCometBFTBroadcaster creates a new CometBFTBroadcaster. +func NewCometBFTBroadcaster(rpcURL, mode string, cdc codec.Codec) (*CometBFTBroadcaster, error) { + if cdc == nil { + return nil, errors.New("codec can't be nil") + } + + if mode == "" { + mode = BroadcastSync + } + + rpcClient, err := rpchttp.New(rpcURL, "/websocket") + if err != nil { + return nil, fmt.Errorf("failed to create CometBft RPC client: %w", err) + } + + return &CometBFTBroadcaster{ + rpcClient: rpcClient, + mode: mode, + cdc: cdc, + }, nil +} + +// Consensus returns the consensus engine name used by the broadcaster. +// It always returns "comet" for CometBFTBroadcaster. +func (c *CometBFTBroadcaster) Consensus() string { + return cometBFTConsensus +} + +// Broadcast sends a transaction to the network and returns the result. +// returns a byte slice containing the JSON-encoded result and an error if the broadcast failed. +func (c *CometBFTBroadcaster) Broadcast(ctx context.Context, txBytes []byte) ([]byte, error) { + if c.cdc == nil { + return []byte{}, fmt.Errorf("JSON codec is not initialized") + } + + var broadcastFunc func(ctx context.Context, tx cmttypes.Tx) (*coretypes.ResultBroadcastTx, error) + switch c.mode { + case BroadcastSync: + broadcastFunc = c.rpcClient.BroadcastTxSync + case BroadcastAsync: + broadcastFunc = c.rpcClient.BroadcastTxAsync + default: + return []byte{}, fmt.Errorf("unknown broadcast mode: %s", c.mode) + } + + res, err := c.broadcast(ctx, txBytes, broadcastFunc) + if err != nil { + return []byte{}, err + } + + return c.cdc.MarshalJSON(res) +} + +// broadcast sends a transaction to the CometBFT network using the provided function. +func (c *CometBFTBroadcaster) broadcast(ctx context.Context, txBytes []byte, + fn func(ctx context.Context, tx cmttypes.Tx) (*coretypes.ResultBroadcastTx, error), +) (*apiacbci.TxResponse, error) { + res, err := fn(ctx, txBytes) + if errRes := checkCometError(err, txBytes); errRes != nil { + return errRes, nil + } + + if res == nil { + return nil, err + } + + parsedLogs, _ := parseABCILogs(res.Log) + return &apiacbci.TxResponse{ + Code: res.Code, + Codespace: res.Codespace, + Data: res.Data.String(), + RawLog: res.Log, + Logs: parsedLogs, + Txhash: res.Hash.String(), + }, err +} + +// checkCometError checks for errors returned by the CometBFT network and returns an appropriate TxResponse. +// It extracts error information and constructs a TxResponse with the error details. +func checkCometError(err error, tx cmttypes.Tx) *apiacbci.TxResponse { + if err == nil { + return nil + } + + errStr := strings.ToLower(err.Error()) + txHash := fmt.Sprintf("%X", tx.Hash()) + + switch { + case strings.Contains(errStr, strings.ToLower(mempool.ErrTxInCache.Error())) || + strings.Contains(errStr, strings.ToLower(sdkerrors.ErrTxInMempoolCache.Error())): + return &apiacbci.TxResponse{ + Code: sdkerrors.ErrTxInMempoolCache.ABCICode(), + Codespace: sdkerrors.ErrTxInMempoolCache.Codespace(), + Txhash: txHash, + } + + case strings.Contains(errStr, "mempool is full"): + return &apiacbci.TxResponse{ + Code: sdkerrors.ErrMempoolIsFull.ABCICode(), + Codespace: sdkerrors.ErrMempoolIsFull.Codespace(), + Txhash: txHash, + } + + case strings.Contains(errStr, "tx too large"): + return &apiacbci.TxResponse{ + Code: sdkerrors.ErrTxTooLarge.ABCICode(), + Codespace: sdkerrors.ErrTxTooLarge.Codespace(), + Txhash: txHash, + } + + case strings.Contains(errStr, "no signatures supplied"): + return &apiacbci.TxResponse{ + Code: sdkerrors.ErrNoSignatures.ABCICode(), + Codespace: sdkerrors.ErrNoSignatures.Codespace(), + Txhash: txHash, + } + + default: + return nil + } +} + +// parseABCILogs attempts to parse a stringified ABCI tx log into a slice of +// ABCIMessageLog types. It returns an error upon JSON decoding failure. +func parseABCILogs(logs string) (res []*apiacbci.ABCIMessageLog, err error) { + err = json.Unmarshal([]byte(logs), &res) + return res, err +} diff --git a/connect/internal/tx/comet_client_conn.go b/connect/internal/tx/comet_client_conn.go new file mode 100644 index 00000000..93f5b4f3 --- /dev/null +++ b/connect/internal/tx/comet_client_conn.go @@ -0,0 +1,146 @@ +package tx + +import ( + "context" + "errors" + "strconv" + + abci "github.com/cometbft/cometbft/abci/types" + rpcclient "github.com/cometbft/cometbft/rpc/client" + gogogrpc "github.com/cosmos/gogoproto/grpc" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/encoding" + "google.golang.org/grpc/metadata" + "google.golang.org/grpc/status" + + errorsmod "cosmossdk.io/errors" + + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" +) + +const grpcBlockHeightHeader = "x-cosmos-block-height" + +var ( + _ gogogrpc.ClientConn = &CometBFTBroadcaster{} + _ grpc.ClientConnInterface = &CometBFTBroadcaster{} +) + +func (c *CometBFTBroadcaster) NewStream(_ context.Context, _ *grpc.StreamDesc, _ string, _ ...grpc.CallOption) (grpc.ClientStream, error) { + return nil, errors.New("not implemented") +} + +// Invoke implements the gRPC ClientConn interface by forwarding the RPC call to CometBFT's ABCI Query. +// It marshals the request, sends it as an ABCI query, and unmarshals the response. +func (c *CometBFTBroadcaster) Invoke(ctx context.Context, method string, req, reply interface{}, opts ...grpc.CallOption) (err error) { + reqBz, err := c.getRPCCodec().Marshal(req) + if err != nil { + return err + } + + // parse height header + md, _ := metadata.FromOutgoingContext(ctx) + var height int64 + if heights := md.Get(grpcBlockHeightHeader); len(heights) > 0 { + height, err = strconv.ParseInt(heights[0], 10, 64) + if err != nil { + return err + } + if height < 0 { + return errorsmod.Wrapf( + sdkerrors.ErrInvalidRequest, + "Invoke: height (%d) from %q must be >= 0", height, grpcBlockHeightHeader) + } + } + + abciR := abci.RequestQuery{ + Path: method, + Data: reqBz, + Height: height, + } + + res, err := c.queryABCI(ctx, abciR) + if err != nil { + return err + } + + err = c.getRPCCodec().Unmarshal(res.Value, reply) + if err != nil { + return err + } + + // Create header metadata. For now the headers contain: + // - block height + // We then parse all the call options, if the call option is a + // HeaderCallOption, then we manually set the value of that header to the + // metadata. + md = metadata.Pairs(grpcBlockHeightHeader, strconv.FormatInt(res.Height, 10)) + for _, callOpt := range opts { + header, ok := callOpt.(grpc.HeaderCallOption) + if !ok { + continue + } + + *header.HeaderAddr = md + } + + if c.cdc.InterfaceRegistry() != nil { + return types.UnpackInterfaces(reply, c.cdc.InterfaceRegistry()) + } + + return nil +} + +// queryABCI performs an ABCI query request to the CometBFT RPC client. +// If the RPC query fails or returns a non-OK response, it will return an error. +// The response is converted from ABCI error codes to gRPC status errors. +func (c *CometBFTBroadcaster) queryABCI(ctx context.Context, req abci.RequestQuery) (abci.ResponseQuery, error) { + opts := rpcclient.ABCIQueryOptions{ + Height: req.Height, + Prove: req.Prove, + } + + result, err := c.rpcClient.ABCIQueryWithOptions(ctx, req.Path, req.Data, opts) + if err != nil { + return abci.ResponseQuery{}, err + } + + if !result.Response.IsOK() { + return abci.ResponseQuery{}, sdkErrorToGRPCError(result.Response) + } + + return result.Response, nil +} + +// sdkErrorToGRPCError converts an ABCI query response error code to an appropriate gRPC status error. +// It maps common SDK error codes to their gRPC equivalents: +// - ErrInvalidRequest -> InvalidArgument +// - ErrUnauthorized -> Unauthenticated +// - ErrKeyNotFound -> NotFound +// Any other error codes are mapped to Unknown. +func sdkErrorToGRPCError(resp abci.ResponseQuery) error { + switch resp.Code { + case sdkerrors.ErrInvalidRequest.ABCICode(): + return status.Error(codes.InvalidArgument, resp.Log) + case sdkerrors.ErrUnauthorized.ABCICode(): + return status.Error(codes.Unauthenticated, resp.Log) + case sdkerrors.ErrKeyNotFound.ABCICode(): + return status.Error(codes.NotFound, resp.Log) + default: + return status.Error(codes.Unknown, resp.Log) + } +} + +// getRPCCodec returns the gRPC codec for the CometBFT broadcaster. +// If the broadcaster's codec implements GRPCCodecProvider, it returns its gRPC codec. +// Otherwise, it creates a new ProtoCodec with the broadcaster's interface registry and returns its gRPC codec. +func (c *CometBFTBroadcaster) getRPCCodec() encoding.Codec { + cdc, ok := c.cdc.(codec.GRPCCodecProvider) + if !ok { + return codec.NewProtoCodec(c.cdc.InterfaceRegistry()).GRPCCodec() + } + + return cdc.GRPCCodec() +} diff --git a/connect/internal/tx/common_test.go b/connect/internal/tx/common_test.go new file mode 100644 index 00000000..864a1153 --- /dev/null +++ b/connect/internal/tx/common_test.go @@ -0,0 +1,116 @@ +package tx + +import ( + "context" + + "google.golang.org/grpc" + + abciv1beta1 "cosmossdk.io/api/cosmos/base/abci/v1beta1" + apitx "cosmossdk.io/api/cosmos/tx/v1beta1" + txdecode "cosmossdk.io/x/tx/decode" + "cosmossdk.io/x/tx/signing" + "github.com/ignite/apps/connect/internal/account" + "github.com/ignite/apps/connect/internal/autocli/keyring" + + "github.com/cosmos/cosmos-sdk/codec" + addrcodec "github.com/cosmos/cosmos-sdk/codec/address" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + codec2 "github.com/cosmos/cosmos-sdk/crypto/codec" + "github.com/cosmos/cosmos-sdk/crypto/hd" + cryptoKeyring "github.com/cosmos/cosmos-sdk/crypto/keyring" + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" + "github.com/cosmos/cosmos-sdk/types" +) + +var ( + cdc = codec.NewProtoCodec(codectypes.NewInterfaceRegistry()) + ac = addrcodec.NewBech32Codec("cosmos") + valCodec = addrcodec.NewBech32Codec("cosmosval") + signingOptions = signing.Options{ + AddressCodec: ac, + ValidatorAddressCodec: valCodec, + } + signingContext, _ = signing.NewContext(signingOptions) + decodeOptions = txdecode.Options{SigningContext: signingContext} + decoder, _ = txdecode.NewDecoder(decodeOptions) + + k = cryptoKeyring.NewInMemory(cdc) + keybase, _ = keyring.NewAutoCLIKeyring(k, ac) + txConf, _ = NewTxConfig(ConfigOptions{ + AddressCodec: ac, + Cdc: cdc, + ValidatorAddressCodec: valCodec, + }) +) + +func setKeyring() keyring.Keyring { + registry := codectypes.NewInterfaceRegistry() + codec2.RegisterInterfaces(registry) + cdc := codec.NewProtoCodec(registry) + k := cryptoKeyring.NewInMemory(cdc) + _, err := k.NewAccount("alice", "equip will roof matter pink blind book anxiety banner elbow sun young", "", "m/44'/118'/0'/0/0", hd.Secp256k1) + if err != nil { + panic(err) + } + keybase, err := keyring.NewAutoCLIKeyring(k, ac) + if err != nil { + panic(err) + } + return keybase +} + +type mockAccount struct { + addr []byte +} + +func (m mockAccount) GetAddress() types.AccAddress { + return m.addr +} + +func (m mockAccount) GetPubKey() cryptotypes.PubKey { + return nil +} + +func (m mockAccount) GetAccountNumber() uint64 { + return 1 +} + +func (m mockAccount) GetSequence() uint64 { + return 0 +} + +type mockAccountRetriever struct{} + +func (m mockAccountRetriever) GetAccount(_ context.Context, address []byte) (account.Account, error) { + return mockAccount{addr: address}, nil +} + +func (m mockAccountRetriever) GetAccountWithHeight(_ context.Context, address []byte) (account.Account, int64, error) { + return mockAccount{addr: address}, 0, nil +} + +func (m mockAccountRetriever) EnsureExists(_ context.Context, _ []byte) error { + return nil +} + +func (m mockAccountRetriever) GetAccountNumberSequence(_ context.Context, _ []byte) (accNum, accSeq uint64, err error) { + return accNum, accSeq, nil +} + +type mockClientConn struct{} + +func (m mockClientConn) Invoke(_ context.Context, _ string, _, reply interface{}, _ ...grpc.CallOption) error { + simResponse := apitx.SimulateResponse{ + GasInfo: &abciv1beta1.GasInfo{ + GasWanted: 10000, + GasUsed: 7500, + }, + Result: nil, + } + *reply.(*apitx.SimulateResponse) = simResponse // nolint:govet // ignore linting error + return nil +} + +func (m mockClientConn) NewStream(_ context.Context, _ *grpc.StreamDesc, _ string, _ ...grpc.CallOption) (grpc.ClientStream, error) { + return nil, nil +} diff --git a/connect/internal/tx/config.go b/connect/internal/tx/config.go new file mode 100644 index 00000000..d7008be5 --- /dev/null +++ b/connect/internal/tx/config.go @@ -0,0 +1,325 @@ +package tx + +import ( + "errors" + + "google.golang.org/protobuf/encoding/protojson" + "google.golang.org/protobuf/reflect/protoreflect" + "google.golang.org/protobuf/types/known/anypb" + + apitxsigning "cosmossdk.io/api/cosmos/tx/signing/v1beta1" + "cosmossdk.io/core/address" + txdecode "cosmossdk.io/x/tx/decode" + "cosmossdk.io/x/tx/signing" + "cosmossdk.io/x/tx/signing/aminojson" + "cosmossdk.io/x/tx/signing/direct" + "cosmossdk.io/x/tx/signing/directaux" + + "github.com/cosmos/cosmos-sdk/codec" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" +) + +var ( + _ TxConfig = txConfig{} + _ TxEncodingConfig = defaultEncodingConfig{} + _ TxSigningConfig = defaultTxSigningConfig{} +) + +// TxConfig is an interface that a client can use to generate a concrete transaction type +// defined by the application. +type TxConfig interface { + TxEncodingConfig + TxSigningConfig +} + +// TxEncodingConfig defines the interface for transaction encoding and decoding. +// It provides methods for both binary and JSON encoding/decoding. +type TxEncodingConfig interface { + // TxEncoder returns an encoder for binary transaction encoding. + TxEncoder() txEncoder + // TxDecoder returns a decoder for binary transaction decoding. + TxDecoder() txDecoder + // TxJSONEncoder returns an encoder for JSON transaction encoding. + TxJSONEncoder() txEncoder + // TxJSONDecoder returns a decoder for JSON transaction decoding. + TxJSONDecoder() txDecoder + // TxTextEncoder returns an encoder for text transaction encoding. + TxTextEncoder() txEncoder + // TxTextDecoder returns a decoder for text transaction decoding. + TxTextDecoder() txDecoder + // Decoder returns the Decoder interface for decoding transaction bytes into a DecodedTx. + Decoder() Decoder +} + +// TxSigningConfig defines the interface for transaction signing configurations. +type TxSigningConfig interface { + // SignModeHandler returns a reference to the HandlerMap which manages the different signing modes. + SignModeHandler() *signing.HandlerMap + // SigningContext returns a reference to the Context which holds additional data required during signing. + SigningContext() *signing.Context + // MarshalSignatureJSON takes a slice of Signature objects and returns their JSON encoding. + MarshalSignatureJSON([]Signature) ([]byte, error) + // UnmarshalSignatureJSON takes a JSON byte slice and returns a slice of Signature objects. + UnmarshalSignatureJSON([]byte) ([]Signature, error) +} + +// ConfigOptions defines the configuration options for transaction processing. +type ConfigOptions struct { + AddressCodec address.Codec + Decoder Decoder + Cdc codec.BinaryCodec + + ValidatorAddressCodec address.Codec + FileResolver signing.ProtoFileResolver + TypeResolver signing.TypeResolver + CustomGetSigner map[protoreflect.FullName]signing.GetSignersFunc + MaxRecursionDepth int + + CustomSignModes []signing.SignModeHandler +} + +// validate checks the ConfigOptions for required fields and sets default values where necessary. +// It returns an error if any required field is missing. +func (c *ConfigOptions) validate() error { + if c.AddressCodec == nil { + return errors.New("address codec cannot be nil") + } + + if c.ValidatorAddressCodec == nil { + return errors.New("validator address codec cannot be nil") + } + + if c.Cdc == nil { + return errors.New("codec cannot be nil") + } + + return nil +} + +// txConfig is a struct that embeds TxEncodingConfig and TxSigningConfig interfaces. +type txConfig struct { + TxEncodingConfig + TxSigningConfig +} + +// NewTxConfig creates a new TxConfig instance using the provided ConfigOptions. +// It validates the options, initializes the signing context, and sets up the decoder if not provided. +func NewTxConfig(options ConfigOptions) (TxConfig, error) { + err := options.validate() + if err != nil { + return nil, err + } + + signingCtx, err := newDefaultTxSigningConfig(options) + if err != nil { + return nil, err + } + + if options.Decoder == nil { + options.Decoder, err = txdecode.NewDecoder(txdecode.Options{ + SigningContext: signingCtx.SigningContext(), + }) + if err != nil { + return nil, err + } + } + + return &txConfig{ + TxEncodingConfig: defaultEncodingConfig{ + cdc: options.Cdc, + decoder: options.Decoder, + }, + TxSigningConfig: signingCtx, + }, nil +} + +// defaultEncodingConfig is an empty struct that implements the TxEncodingConfig interface. +type defaultEncodingConfig struct { + cdc codec.BinaryCodec + decoder Decoder +} + +// TxEncoder returns the default transaction encoder. +func (t defaultEncodingConfig) TxEncoder() txEncoder { + return encodeTx +} + +// TxDecoder returns the default transaction decoder. +func (t defaultEncodingConfig) TxDecoder() txDecoder { + return decodeTx(t.cdc, t.decoder) +} + +// TxJSONEncoder returns the default JSON transaction encoder. +func (t defaultEncodingConfig) TxJSONEncoder() txEncoder { + return encodeJsonTx +} + +// TxJSONDecoder returns the default JSON transaction decoder. +func (t defaultEncodingConfig) TxJSONDecoder() txDecoder { + return decodeJsonTx(t.cdc, t.decoder) +} + +// TxTextEncoder returns the default text transaction encoder. +func (t defaultEncodingConfig) TxTextEncoder() txEncoder { + return encodeTextTx +} + +// TxTextDecoder returns the default text transaction decoder. +func (t defaultEncodingConfig) TxTextDecoder() txDecoder { + return decodeTextTx(t.cdc, t.decoder) +} + +// Decoder returns the Decoder instance associated with this encoding configuration. +func (t defaultEncodingConfig) Decoder() Decoder { + return t.decoder +} + +// defaultTxSigningConfig is a struct that holds the signing context and handler map. +type defaultTxSigningConfig struct { + signingCtx *signing.Context + handlerMap *signing.HandlerMap + cdc codec.BinaryCodec +} + +// newDefaultTxSigningConfig creates a new defaultTxSigningConfig instance using the provided ConfigOptions. +// It initializes the signing context and handler map. +func newDefaultTxSigningConfig(opts ConfigOptions) (*defaultTxSigningConfig, error) { + signingCtx, err := newSigningContext(opts) + if err != nil { + return nil, err + } + + handlerMap, err := newHandlerMap(opts, signingCtx) + if err != nil { + return nil, err + } + + return &defaultTxSigningConfig{ + signingCtx: signingCtx, + handlerMap: handlerMap, + cdc: opts.Cdc, + }, nil +} + +// SignModeHandler returns the handler map that manages the different signing modes. +func (t defaultTxSigningConfig) SignModeHandler() *signing.HandlerMap { + return t.handlerMap +} + +// SigningContext returns the signing context that holds additional data required during signing. +func (t defaultTxSigningConfig) SigningContext() *signing.Context { + return t.signingCtx +} + +// MarshalSignatureJSON takes a slice of Signature objects and returns their JSON encoding. +// This method is not yet implemented and will panic if called. +func (t defaultTxSigningConfig) MarshalSignatureJSON(signatures []Signature) ([]byte, error) { + descriptor := make([]*apitxsigning.SignatureDescriptor, len(signatures)) + + for i, sig := range signatures { + descData, err := signatureDataToProto(sig.Data) + if err != nil { + return nil, err + } + + anyPk, err := codectypes.NewAnyWithValue(sig.PubKey) + if err != nil { + return nil, err + } + + descriptor[i] = &apitxsigning.SignatureDescriptor{ + PublicKey: &anypb.Any{ + TypeUrl: codectypes.MsgTypeURL(sig.PubKey), + Value: anyPk.Value, + }, + Data: descData, + Sequence: sig.Sequence, + } + } + + return jsonMarshalOptions.Marshal(&apitxsigning.SignatureDescriptors{Signatures: descriptor}) +} + +// UnmarshalSignatureJSON takes a JSON byte slice and returns a slice of Signature objects. +// This method is not yet implemented and will panic if called. +func (t defaultTxSigningConfig) UnmarshalSignatureJSON(bz []byte) ([]Signature, error) { + var descriptor apitxsigning.SignatureDescriptors + + err := protojson.UnmarshalOptions{}.Unmarshal(bz, &descriptor) + if err != nil { + return nil, err + } + + sigs := make([]Signature, len(descriptor.Signatures)) + for i, desc := range descriptor.Signatures { + var pubkey cryptotypes.PubKey + + anyPk := &codectypes.Any{ + TypeUrl: desc.PublicKey.TypeUrl, + Value: desc.PublicKey.Value, + } + + err = t.cdc.UnpackAny(anyPk, &pubkey) + if err != nil { + return nil, err + } + + data, err := SignatureDataFromProto(desc.Data) + if err != nil { + return nil, err + } + + sigs[i] = Signature{ + PubKey: pubkey, + Data: data, + Sequence: desc.Sequence, + } + } + + return sigs, nil +} + +// newSigningContext creates a new signing context using the provided ConfigOptions. +// Returns a signing.Context instance or an error if initialization fails. +func newSigningContext(opts ConfigOptions) (*signing.Context, error) { + return signing.NewContext(signing.Options{ + FileResolver: opts.FileResolver, + TypeResolver: opts.TypeResolver, + AddressCodec: opts.AddressCodec, + ValidatorAddressCodec: opts.ValidatorAddressCodec, + CustomGetSigners: opts.CustomGetSigner, + MaxRecursionDepth: opts.MaxRecursionDepth, + }) +} + +// newHandlerMap constructs a new HandlerMap based on the provided ConfigOptions and signing context. +// It initializes handlers for each enabled and custom sign mode specified in the options. +func newHandlerMap(opts ConfigOptions, signingCtx *signing.Context) (hm *signing.HandlerMap, err error) { + lenSignModes := 3 + handlers := make([]signing.SignModeHandler, lenSignModes+len(opts.CustomSignModes)) + + // sign mode direct + handlers[0] = &direct.SignModeHandler{} + // sign mode direct aux + handlers[1], err = directaux.NewSignModeHandler(directaux.SignModeHandlerOptions{ + TypeResolver: signingCtx.TypeResolver(), + SignersContext: signingCtx, + }) + if err != nil { + return nil, err + } + // sign mode amino json + handlers[2] = aminojson.NewSignModeHandler(aminojson.SignModeHandlerOptions{ + FileResolver: signingCtx.FileResolver(), + TypeResolver: opts.TypeResolver, + }) + + for i, m := range opts.CustomSignModes { + handlers[i+lenSignModes] = m + } + + hm = signing.NewHandlerMap(handlers...) + + return hm, nil +} diff --git a/connect/internal/tx/config_test.go b/connect/internal/tx/config_test.go new file mode 100644 index 00000000..ad91c4bd --- /dev/null +++ b/connect/internal/tx/config_test.go @@ -0,0 +1,242 @@ +package tx + +import ( + "context" + "testing" + + "github.com/stretchr/testify/require" + + apicrypto "cosmossdk.io/api/cosmos/crypto/multisig/v1beta1" + _ "cosmossdk.io/api/cosmos/crypto/secp256k1" + apitxsigning "cosmossdk.io/api/cosmos/tx/signing/v1beta1" + "cosmossdk.io/x/tx/signing" + + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/address" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + codec2 "github.com/cosmos/cosmos-sdk/crypto/codec" + kmultisig "github.com/cosmos/cosmos-sdk/crypto/keys/multisig" + "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" +) + +type mockModeHandler struct{} + +func (t mockModeHandler) Mode() apitxsigning.SignMode { + return apitxsigning.SignMode_SIGN_MODE_DIRECT +} + +func (t mockModeHandler) GetSignBytes(_ context.Context, _ signing.SignerData, _ signing.TxData) ([]byte, error) { + return []byte{}, nil +} + +func TestConfigOptions_validate(t *testing.T) { + tests := []struct { + name string + opts ConfigOptions + wantErr bool + }{ + { + name: "valid options", + opts: ConfigOptions{ + AddressCodec: address.NewBech32Codec("cosmos"), + Decoder: decoder, + Cdc: cdc, + ValidatorAddressCodec: address.NewBech32Codec("cosmosvaloper"), + }, + }, + { + name: "missing address codec", + opts: ConfigOptions{ + Decoder: decoder, + Cdc: cdc, + ValidatorAddressCodec: address.NewBech32Codec("cosmosvaloper"), + }, + wantErr: true, + }, + { + name: "missing decoder", + opts: ConfigOptions{ + AddressCodec: address.NewBech32Codec("cosmos"), + Cdc: cdc, + ValidatorAddressCodec: address.NewBech32Codec("cosmosvaloper"), + }, + }, + { + name: "missing codec", + opts: ConfigOptions{ + AddressCodec: address.NewBech32Codec("cosmos"), + Decoder: decoder, + ValidatorAddressCodec: address.NewBech32Codec("cosmosvaloper"), + }, + wantErr: true, + }, + { + name: "missing validator address codec", + opts: ConfigOptions{ + AddressCodec: address.NewBech32Codec("cosmos"), + Decoder: decoder, + Cdc: cdc, + }, + wantErr: true, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := tt.opts.validate(); (err != nil) != tt.wantErr { + t.Errorf("validate() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func TestNewTxConfig(t *testing.T) { + tests := []struct { + name string + options ConfigOptions + wantErr bool + }{ + { + name: "valid options", + options: ConfigOptions{ + AddressCodec: ac, + Cdc: cdc, + ValidatorAddressCodec: valCodec, + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := NewTxConfig(tt.options) + if (err != nil) != tt.wantErr { + t.Errorf("NewTxConfig() error = %v, wantErr %v", err, tt.wantErr) + return + } + require.NotNil(t, got) + }) + } +} + +func Test_defaultTxSigningConfig_MarshalSignatureJSON(t *testing.T) { + tests := []struct { + name string + options ConfigOptions + signatures func(t *testing.T) []Signature + }{ + { + name: "single signature", + options: ConfigOptions{ + AddressCodec: ac, + Cdc: cdc, + ValidatorAddressCodec: valCodec, + }, + signatures: func(t *testing.T) []Signature { + t.Helper() + + k := setKeyring() + pk, err := k.GetPubKey("alice") + require.NoError(t, err) + signature, err := k.Sign("alice", make([]byte, 10), apitxsigning.SignMode_SIGN_MODE_DIRECT) + require.NoError(t, err) + return []Signature{ + { + PubKey: pk, + Data: &SingleSignatureData{ + SignMode: apitxsigning.SignMode_SIGN_MODE_DIRECT, + Signature: signature, + }, + }, + } + }, + }, + { + name: "multisig signatures", + options: ConfigOptions{ + AddressCodec: ac, + Cdc: cdc, + ValidatorAddressCodec: valCodec, + }, + signatures: func(t *testing.T) []Signature { + t.Helper() + + n := 2 + pubKeys := make([]cryptotypes.PubKey, n) + sigs := make([]SignatureData, n) + for i := 0; i < n; i++ { + sk := secp256k1.GenPrivKey() + pubKeys[i] = sk.PubKey() + msg, err := sk.Sign(make([]byte, 10)) + require.NoError(t, err) + sigs[i] = &SingleSignatureData{ + SignMode: apitxsigning.SignMode_SIGN_MODE_DIRECT, + Signature: msg, + } + } + bitArray := cryptotypes.NewCompactBitArray(n) + mKey := kmultisig.NewLegacyAminoPubKey(n, pubKeys) + return []Signature{ + { + PubKey: mKey, + Data: &MultiSignatureData{ + BitArray: &apicrypto.CompactBitArray{ + ExtraBitsStored: bitArray.ExtraBitsStored, + Elems: bitArray.Elems, + }, + Signatures: sigs, + }, + }, + } + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + config, err := NewTxConfig(tt.options) + require.NoError(t, err) + + got, err := config.MarshalSignatureJSON(tt.signatures(t)) + require.NoError(t, err) + require.NotNil(t, got) + }) + } +} + +func Test_defaultTxSigningConfig_UnmarshalSignatureJSON(t *testing.T) { + registry := codectypes.NewInterfaceRegistry() + codec2.RegisterInterfaces(registry) + cdc := codec.NewProtoCodec(registry) + tests := []struct { + name string + options ConfigOptions + bz []byte + }{ + { + name: "single signature", + options: ConfigOptions{ + AddressCodec: ac, + Cdc: cdc, + ValidatorAddressCodec: valCodec, + }, + bz: []byte(`{"signatures":[{"public_key":{"@type":"/cosmos.crypto.secp256k1.PubKey", "key":"A0/vnNfExjWI07A/61KBudIyy6NNbz1xruWSEf+/4f6H"}, "data":{"single":{"mode":"SIGN_MODE_DIRECT", "signature":"usUTJwdc4PWPuox0Y0G/RuHoxyj+QpUcBGvXyNdDX1FOdoVj0tg4TGKT2NnM3QP6wCNbubjHuMOhTtqfW8SkYg=="}}}]}`), + }, + { + name: "multisig signatures", + options: ConfigOptions{ + AddressCodec: ac, + Cdc: cdc, + ValidatorAddressCodec: valCodec, + }, + bz: []byte(`{"signatures":[{"public_key":{"@type":"/cosmos.crypto.multisig.LegacyAminoPubKey","threshold":2,"public_keys":[{"@type":"/cosmos.crypto.secp256k1.PubKey","key":"A4Bs9huvS/COpZNhVhTnhgc8YR6VrSQ8hLQIHgnA+m3w"},{"@type":"/cosmos.crypto.secp256k1.PubKey","key":"AuNz2lFkLn3sKNjC5r4OWhgkWg5DZpGUiR9OdpzXspnp"}]},"data":{"multi":{"bitarray":{"extra_bits_stored":2,"elems":"AA=="},"signatures":[{"single":{"mode":"SIGN_MODE_DIRECT","signature":"vng4IlPzLH3fDFpikM5y1SfXFGny4BcLGwIFU0Ty4yoWjIxjTS4m6fgDB61sxEkV5DK/CD7gUwenGuEpzJ2IGw=="}},{"single":{"mode":"SIGN_MODE_DIRECT","signature":"2dsGmr13bq/mPxbk9AgqcFpuvk4beszWu6uxkx+EhTMdVGp4J8FtjZc8xs/Pp3oTWY4ScAORYQHxwqN4qwMXGg=="}}]}}}]}`), + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + config, err := NewTxConfig(tt.options) + require.NoError(t, err) + + got, err := config.UnmarshalSignatureJSON(tt.bz) + require.NoError(t, err) + require.NotNil(t, got) + }) + } +} diff --git a/connect/internal/tx/context.go b/connect/internal/tx/context.go new file mode 100644 index 00000000..1da1ddbc --- /dev/null +++ b/connect/internal/tx/context.go @@ -0,0 +1,51 @@ +package tx + +import ( + "context" + "errors" + + "github.com/spf13/pflag" + + "cosmossdk.io/core/address" + "github.com/ignite/apps/connect/internal/autocli/keyring" + + "github.com/cosmos/cosmos-sdk/codec" +) + +// ContextKey is a key used to store and retrieve Context from a Go context.Context. +var ContextKey contextKey + +// contextKey is an empty struct used as a key type for storing Context in a context.Context. +type contextKey struct{} + +// Context represents the client context used in autocli commands. +// It contains various components needed for command execution. +type Context struct { + Flags *pflag.FlagSet + + AddressCodec address.Codec + ValidatorAddressCodec address.Codec + ConsensusAddressCodec address.Codec + + Cdc codec.Codec + Keyring keyring.Keyring +} + +// SetContext sets client context in the go context. +func SetContext(goCtx context.Context, ctx Context) context.Context { + return context.WithValue(goCtx, ContextKey, ctx) +} + +// GetContext gets the context from the go context. +func GetContext(goCtx context.Context) (Context, error) { + if c := goCtx.Value(ContextKey); c != nil { + ctx, ok := c.(Context) + if !ok { + return Context{}, errors.New("context value is not of type autocli context") + } + + return ctx, nil + } + + return Context{}, errors.New("context does not contain autocli context value") +} diff --git a/connect/internal/tx/encoder.go b/connect/internal/tx/encoder.go new file mode 100644 index 00000000..09011c83 --- /dev/null +++ b/connect/internal/tx/encoder.go @@ -0,0 +1,159 @@ +package tx + +import ( + "fmt" + + "google.golang.org/protobuf/encoding/protojson" + "google.golang.org/protobuf/encoding/prototext" + protov2 "google.golang.org/protobuf/proto" + + txv1beta1 "cosmossdk.io/api/cosmos/tx/v1beta1" + txdecode "cosmossdk.io/x/tx/decode" + + "github.com/cosmos/cosmos-sdk/codec" +) + +var ( + // marshalOption configures protobuf marshaling to be deterministic. + marshalOption = protov2.MarshalOptions{Deterministic: true} + + // jsonMarshalOptions configures JSON marshaling for protobuf messages. + jsonMarshalOptions = protojson.MarshalOptions{ + Indent: "", + UseProtoNames: true, + UseEnumNumbers: false, + EmitUnpopulated: true, + } + + // textMarshalOptions + textMarshalOptions = prototext.MarshalOptions{ + Indent: "", + } +) + +// Decoder defines the interface for decoding transaction bytes into a DecodedTx. +type Decoder interface { + Decode(txBytes []byte) (*txdecode.DecodedTx, error) +} + +// txDecoder is a function type that unmarshals transaction bytes into an API Tx type. +type txDecoder func(txBytes []byte) (Tx, error) + +// txEncoder is a function type that marshals a transaction into bytes. +type txEncoder func(tx Tx) ([]byte, error) + +// decodeTx decodes transaction bytes into an apitx.Tx structure. +func decodeTx(cdc codec.BinaryCodec, decoder Decoder) txDecoder { + return func(txBytes []byte) (Tx, error) { + tx := new(txv1beta1.Tx) + err := protov2.Unmarshal(txBytes, tx) + if err != nil { + return nil, err + } + + pTxBytes, err := protoTxBytes(tx) + if err != nil { + return nil, err + } + + decodedTx, err := decoder.Decode(pTxBytes) + if err != nil { + return nil, err + } + return newWrapperTx(cdc, decodedTx), nil + } +} + +// encodeTx encodes an apitx.Tx into bytes using protobuf marshaling options. +func encodeTx(tx Tx) ([]byte, error) { + wTx, ok := tx.(*wrappedTx) + if !ok { + return nil, fmt.Errorf("unexpected tx type: %T", tx) + } + return marshalOption.Marshal(wTx.Tx) +} + +// decodeJsonTx decodes transaction bytes into an apitx.Tx structure using JSON format. +func decodeJsonTx(cdc codec.BinaryCodec, decoder Decoder) txDecoder { + return func(txBytes []byte) (Tx, error) { + jsonTx := new(txv1beta1.Tx) + err := protojson.UnmarshalOptions{ + AllowPartial: false, + DiscardUnknown: false, + }.Unmarshal(txBytes, jsonTx) + if err != nil { + return nil, err + } + + pTxBytes, err := protoTxBytes(jsonTx) + if err != nil { + return nil, err + } + + decodedTx, err := decoder.Decode(pTxBytes) + if err != nil { + return nil, err + } + return newWrapperTx(cdc, decodedTx), nil + } +} + +// encodeJsonTx encodes an apitx.Tx into bytes using JSON marshaling options. +func encodeJsonTx(tx Tx) ([]byte, error) { + wTx, ok := tx.(*wrappedTx) + if !ok { + return nil, fmt.Errorf("unexpected tx type: %T", tx) + } + return jsonMarshalOptions.Marshal(wTx.Tx) +} + +func encodeTextTx(tx Tx) ([]byte, error) { + wTx, ok := tx.(*wrappedTx) + if !ok { + return nil, fmt.Errorf("unexpected tx type: %T", tx) + } + return textMarshalOptions.Marshal(wTx.Tx) +} + +// decodeJsonTx decodes transaction bytes into an apitx.Tx structure using JSON format. +func decodeTextTx(cdc codec.BinaryCodec, decoder Decoder) txDecoder { + return func(txBytes []byte) (Tx, error) { + jsonTx := new(txv1beta1.Tx) + err := prototext.UnmarshalOptions{ + AllowPartial: false, + DiscardUnknown: false, + }.Unmarshal(txBytes, jsonTx) + if err != nil { + return nil, err + } + + pTxBytes, err := protoTxBytes(jsonTx) + if err != nil { + return nil, err + } + + decodedTx, err := decoder.Decode(pTxBytes) + if err != nil { + return nil, err + } + return newWrapperTx(cdc, decodedTx), nil + } +} + +func protoTxBytes(tx *txv1beta1.Tx) ([]byte, error) { + bodyBytes, err := marshalOption.Marshal(tx.Body) + if err != nil { + return nil, err + } + + authInfoBytes, err := marshalOption.Marshal(tx.AuthInfo) + if err != nil { + return nil, err + } + + return marshalOption.Marshal(&txv1beta1.TxRaw{ + BodyBytes: bodyBytes, + AuthInfoBytes: authInfoBytes, + Signatures: tx.Signatures, + }) +} diff --git a/connect/internal/tx/encoder_test.go b/connect/internal/tx/encoder_test.go new file mode 100644 index 00000000..16dea70d --- /dev/null +++ b/connect/internal/tx/encoder_test.go @@ -0,0 +1,108 @@ +package tx + +import ( + "testing" + + "github.com/stretchr/testify/require" + + bankv1beta1 "cosmossdk.io/api/cosmos/bank/v1beta1" + base "cosmossdk.io/api/cosmos/base/v1beta1" + apisigning "cosmossdk.io/api/cosmos/tx/signing/v1beta1" + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" +) + +func getWrappedTx(t *testing.T) *wrappedTx { + t.Helper() + + f, err := NewFactory(keybase, cdc, mockAccountRetriever{}, txConf, ac, mockClientConn{}, TxParameters{}) + require.NoError(t, err) + + pk := secp256k1.GenPrivKey().PubKey() + addr, _ := ac.BytesToString(pk.Address()) + + f.tx.msgs = []sdk.Msg{&bankv1beta1.MsgSend{ + FromAddress: addr, + ToAddress: addr, + Amount: []*base.Coin{}, + }} + require.NoError(t, err) + + err = f.setFeePayer(addr) + require.NoError(t, err) + + f.tx.fees = []*base.Coin{{ + Denom: "cosmos", + Amount: "1000", + }} + + err = f.setSignatures([]Signature{{ + PubKey: pk, + Data: &SingleSignatureData{ + SignMode: apisigning.SignMode_SIGN_MODE_DIRECT, + Signature: nil, + }, + Sequence: 0, + }}...) + require.NoError(t, err) + wTx, err := f.getTx() + require.NoError(t, err) + return wTx +} + +func Test_txEncoder_txDecoder(t *testing.T) { + wTx := getWrappedTx(t) + + encodedTx, err := encodeTx(wTx) + require.NoError(t, err) + require.NotNil(t, encodedTx) + + isDeterministic, err := encodeTx(wTx) + require.NoError(t, err) + require.NotNil(t, encodedTx) + require.Equal(t, encodedTx, isDeterministic) + + f := decodeTx(cdc, decoder) + decodedTx, err := f(encodedTx) + require.NoError(t, err) + require.NotNil(t, decodedTx) + + dTx, ok := decodedTx.(*wrappedTx) + require.True(t, ok) + require.Equal(t, wTx.TxRaw, dTx.TxRaw) + require.Equal(t, wTx.Tx.AuthInfo.String(), dTx.Tx.AuthInfo.String()) + require.Equal(t, wTx.Tx.Body.String(), dTx.Tx.Body.String()) + require.Equal(t, wTx.Tx.Signatures, dTx.Tx.Signatures) +} + +func Test_txJsonEncoder_txJsonDecoder(t *testing.T) { + tests := []struct { + name string + }{ + { + name: "json encode and decode tx", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + wTx := getWrappedTx(t) + + encodedTx, err := encodeJsonTx(wTx) + require.NoError(t, err) + require.NotNil(t, encodedTx) + + f := decodeJsonTx(cdc, decoder) + decodedTx, err := f(encodedTx) + require.NoError(t, err) + require.NotNil(t, decodedTx) + + dTx, ok := decodedTx.(*wrappedTx) + require.True(t, ok) + require.Equal(t, wTx.TxRaw, dTx.TxRaw) + require.Equal(t, wTx.Tx.AuthInfo.String(), dTx.Tx.AuthInfo.String()) + require.Equal(t, wTx.Tx.Body.String(), dTx.Tx.Body.String()) + require.Equal(t, wTx.Tx.Signatures, dTx.Tx.Signatures) + }) + } +} diff --git a/connect/internal/tx/factory.go b/connect/internal/tx/factory.go new file mode 100644 index 00000000..cb489150 --- /dev/null +++ b/connect/internal/tx/factory.go @@ -0,0 +1,757 @@ +package tx + +import ( + "context" + "errors" + "fmt" + "math/big" + "strings" + + "github.com/cosmos/go-bip39" + gogogrpc "github.com/cosmos/gogoproto/grpc" + "github.com/spf13/pflag" + "google.golang.org/protobuf/types/known/anypb" + + base "cosmossdk.io/api/cosmos/base/v1beta1" + apicrypto "cosmossdk.io/api/cosmos/crypto/multisig/v1beta1" + apitxsigning "cosmossdk.io/api/cosmos/tx/signing/v1beta1" + apitx "cosmossdk.io/api/cosmos/tx/v1beta1" + "cosmossdk.io/core/address" + "cosmossdk.io/math" + "cosmossdk.io/x/tx/signing" + flags2 "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/codec" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/cosmos/cosmos-sdk/crypto/keys/multisig" + "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/ignite/apps/connect/internal/account" + "github.com/ignite/apps/connect/internal/autocli/keyring" + "github.com/ignite/apps/connect/internal/coins" +) + +// Factory defines a client transaction factory that facilitates generating and +// signing an application-specific transaction. +type Factory struct { + keybase keyring.Keyring + cdc codec.BinaryCodec + accountRetriever account.AccountRetriever + ac address.Codec + conn gogogrpc.ClientConn + txConfig TxConfig + txParams TxParameters + + tx *txState +} + +func NewFactoryFromFlagSet(f *pflag.FlagSet, keybase keyring.Keyring, cdc codec.BinaryCodec, accRetriever account.AccountRetriever, + txConfig TxConfig, ac address.Codec, conn gogogrpc.ClientConn, +) (Factory, error) { + offline, _ := f.GetBool(FlagOffline) + if err := validateFlagSet(f, offline); err != nil { + return Factory{}, err + } + + params, err := txParamsFromFlagSet(f, keybase, ac) + if err != nil { + return Factory{}, err + } + + params, err = prepareTxParams(params, accRetriever, offline) + if err != nil { + return Factory{}, err + } + + return NewFactory(keybase, cdc, accRetriever, txConfig, ac, conn, params) +} + +// NewFactory returns a new instance of Factory. +func NewFactory(keybase keyring.Keyring, cdc codec.BinaryCodec, accRetriever account.AccountRetriever, + txConfig TxConfig, ac address.Codec, conn gogogrpc.ClientConn, parameters TxParameters, +) (Factory, error) { + return Factory{ + keybase: keybase, + cdc: cdc, + accountRetriever: accRetriever, + ac: ac, + conn: conn, + txConfig: txConfig, + txParams: parameters, + + tx: &txState{}, + }, nil +} + +// validateFlagSet checks the provided flags for consistency and requirements based on the operation mode. +func validateFlagSet(f *pflag.FlagSet, offline bool) error { + dryRun, _ := f.GetBool(FlagDryRun) + if offline && dryRun { + return errors.New("dry-run: cannot use offline mode") + } + + generateOnly, _ := f.GetBool(FlagGenerateOnly) + chainID, _ := f.GetString(FlagChainID) + if offline { + if !generateOnly && (!f.Changed(FlagAccountNumber) || !f.Changed(FlagSequence)) { + return errors.New("account-number and sequence must be set in offline mode") + } + + if generateOnly && chainID != "" { + return errors.New("chain ID cannot be used when offline and generate-only flags are set") + } + + gas, _ := f.GetString(FlagGas) + gasSetting, _ := flags2.ParseGasSetting(gas) + if gasSetting.Simulate { + return errors.New("simulate and offline flags cannot be set at the same time") + } + } else if chainID == "" { + return errors.New("chain ID required but not specified") + } + + return nil +} + +// prepareTxParams ensures the account defined by ctx.GetFromAddress() exists and +// if the account number and/or the account sequence number are zero (not set), +// they will be queried for and set on the provided Factory. +func prepareTxParams(parameters TxParameters, accRetriever account.AccountRetriever, offline bool) (TxParameters, error) { + if offline { + return parameters, nil + } + + if len(parameters.Address) == 0 { + return parameters, errors.New("missing 'from address' field") + } + + if parameters.AccountNumber == 0 || parameters.Sequence == 0 { + num, seq, err := accRetriever.GetAccountNumberSequence(context.Background(), parameters.Address) + if err != nil { + return parameters, err + } + + if parameters.AccountNumber == 0 { + parameters.AccountNumber = num + } + + if parameters.Sequence == 0 { + parameters.Sequence = seq + } + } + + return parameters, nil +} + +// BuildUnsignedTx builds a transaction to be signed given a set of messages. +// Once created, the fee, memo, and messages are set. +func (f *Factory) BuildUnsignedTx(msgs ...sdk.Msg) error { + fees := f.txParams.fees + + isGasPriceZero, err := coins.IsZero(f.txParams.gasPrices) + if err != nil { + return err + } + if !isGasPriceZero { + areFeesZero, err := coins.IsZero(fees) + if err != nil { + return err + } + if !areFeesZero { + return errors.New("cannot provide both fees and gas prices") + } + + // f.gas is an uint64 and we should convert to LegacyDec + // without the risk of under/overflow via uint64->int64. + glDec := math.LegacyNewDecFromBigInt(new(big.Int).SetUint64(f.txParams.gas)) + + // Derive the fees based on the provided gas prices, where + // fee = ceil(gasPrice * gasLimit). + fees = make([]*base.Coin, len(f.txParams.gasPrices)) + + for i, gp := range f.txParams.gasPrices { + fee, err := math.LegacyNewDecFromStr(gp.Amount) + if err != nil { + return err + } + fee = fee.Mul(glDec) + fees[i] = &base.Coin{Denom: gp.Denom, Amount: fee.Ceil().RoundInt().String()} + } + } + + if err := validateMemo(f.txParams.memo); err != nil { + return err + } + + f.tx.msgs = msgs + f.tx.memo = f.txParams.memo + f.tx.fees = fees + f.tx.gasLimit = f.txParams.gas + f.tx.unordered = f.txParams.unordered + f.tx.timeoutTimestamp = f.txParams.timeoutTimestamp + + err = f.setFeeGranter(f.txParams.feeGranter) + if err != nil { + return err + } + err = f.setFeePayer(f.txParams.feePayer) + if err != nil { + return err + } + + return nil +} + +func (f *Factory) BuildsSignedTx(ctx context.Context, msgs ...sdk.Msg) (Tx, error) { + err := f.BuildUnsignedTx(msgs...) + if err != nil { + return nil, err + } + + return f.sign(ctx, true) +} + +// calculateGas calculates the gas required for the given messages. +func (f *Factory) calculateGas(msgs ...sdk.Msg) error { + _, adjusted, err := f.Simulate(msgs...) + if err != nil { + return err + } + + f.WithGas(adjusted) + + return nil +} + +// Simulate simulates the execution of a transaction and returns the +// simulation response obtained by the query and the adjusted gas amount. +func (f *Factory) Simulate(msgs ...sdk.Msg) (*apitx.SimulateResponse, uint64, error) { + txBytes, err := f.BuildSimTx(msgs...) + if err != nil { + return nil, 0, err + } + + txSvcClient := apitx.NewServiceClient(f.conn) + simRes, err := txSvcClient.Simulate(context.Background(), &apitx.SimulateRequest{ + TxBytes: txBytes, + }) + if err != nil { + return nil, 0, err + } + + return simRes, uint64(f.gasAdjustment() * float64(simRes.GasInfo.GasUsed)), nil +} + +// UnsignedTxString will generate an unsigned transaction and print it to the writer +// specified by ctx.Output. If simulation was requested, the gas will be +// simulated and also printed to the same writer before the transaction is +// printed. +func (f *Factory) UnsignedTxString(msgs ...sdk.Msg) (string, error) { + if f.simulateAndExecute() { + err := f.calculateGas(msgs...) + if err != nil { + return "", err + } + } + + err := f.BuildUnsignedTx(msgs...) + if err != nil { + return "", err + } + + encoder := f.txConfig.TxJSONEncoder() + if encoder == nil { + return "", errors.New("cannot print unsigned tx: tx json encoder is nil") + } + + tx, err := f.getTx() + if err != nil { + return "", err + } + + json, err := encoder(tx) + if err != nil { + return "", err + } + + return fmt.Sprintf("%s\n", json), nil +} + +// BuildSimTx creates an unsigned tx with an empty single signature and returns +// the encoded transaction or an error if the unsigned transaction cannot be +// built. +func (f *Factory) BuildSimTx(msgs ...sdk.Msg) ([]byte, error) { + err := f.BuildUnsignedTx(msgs...) + if err != nil { + return nil, err + } + + pk, err := f.getSimPK() + if err != nil { + return nil, err + } + + // Create an empty signature literal as the ante handler will populate with a + // sentinel pubkey. + sig := Signature{ + PubKey: pk, + Data: f.getSimSignatureData(pk), + Sequence: f.sequence(), + } + if err := f.setSignatures(sig); err != nil { + return nil, err + } + + encoder := f.txConfig.TxEncoder() + if encoder == nil { + return nil, fmt.Errorf("cannot simulate tx: tx encoder is nil") + } + + tx, err := f.getTx() + if err != nil { + return nil, err + } + return encoder(tx) +} + +// sign signs a given tx with a named key. The bytes signed over are canonical. +// The resulting signature will be added to the transaction builder overwriting the previous +// ones if overwrite=true (otherwise, the signature will be appended). +// Signing a transaction with multiple signers in the DIRECT mode is not supported and will +// return an error. +func (f *Factory) sign(ctx context.Context, overwriteSig bool) (Tx, error) { + if f.keybase == nil { + return nil, errors.New("keybase must be set prior to signing a transaction") + } + + var err error + if f.txParams.SignMode == apitxsigning.SignMode_SIGN_MODE_UNSPECIFIED { + f.txParams.SignMode = f.txConfig.SignModeHandler().DefaultMode() + } + + pubKey, err := f.keybase.GetPubKey(f.txParams.FromName) + if err != nil { + return nil, err + } + + addr, err := f.ac.BytesToString(pubKey.Address()) + if err != nil { + return nil, err + } + + signerData := signing.SignerData{ + ChainID: f.txParams.ChainID, + AccountNumber: f.txParams.AccountNumber, + Sequence: f.txParams.Sequence, + PubKey: &anypb.Any{ + TypeUrl: codectypes.MsgTypeURL(pubKey), + Value: pubKey.Bytes(), + }, + Address: addr, + } + + // For SIGN_MODE_DIRECT, we need to set the SignerInfos before generating + // the sign bytes. This is done by calling setSignatures with a nil + // signature, which in turn calls setSignerInfos internally. + // + // For SIGN_MODE_LEGACY_AMINO, this step is not strictly necessary, + // but we include it for consistency across all sign modes. + // It does not affect the generated sign bytes for LEGACY_AMINO. + // + // By setting the signatures here, we ensure that the correct SignerInfos + // are in place for all subsequent operations, regardless of the sign mode. + sigData := SingleSignatureData{ + SignMode: f.txParams.SignMode, + Signature: nil, + } + sig := Signature{ + PubKey: pubKey, + Data: &sigData, + Sequence: f.txParams.Sequence, + } + + var prevSignatures []Signature + if !overwriteSig { + tx, err := f.getTx() + if err != nil { + return nil, err + } + + prevSignatures, err = tx.GetSignatures() + if err != nil { + return nil, err + } + } + // Overwrite or append signer infos. + var sigs []Signature + if overwriteSig { + sigs = []Signature{sig} + } else { + sigs = append(sigs, prevSignatures...) + sigs = append(sigs, sig) + } + if err := f.setSignatures(sigs...); err != nil { + return nil, err + } + + tx, err := f.getTx() + if err != nil { + return nil, err + } + + if err := checkMultipleSigners(tx); err != nil { + return nil, err + } + + bytesToSign, err := f.getSignBytesAdapter(ctx, signerData) + if err != nil { + return nil, err + } + + // Sign those bytes + sigBytes, err := f.keybase.Sign(f.txParams.FromName, bytesToSign, f.txParams.SignMode) + if err != nil { + return nil, err + } + + // Construct the SignatureV2 struct + sigData = SingleSignatureData{ + SignMode: f.signMode(), + Signature: sigBytes, + } + sig = Signature{ + PubKey: pubKey, + Data: &sigData, + Sequence: f.txParams.Sequence, + } + + if overwriteSig { + err = f.setSignatures(sig) + } else { + prevSignatures = append(prevSignatures, sig) + err = f.setSignatures(prevSignatures...) + } + + if err != nil { + return nil, fmt.Errorf("unable to set signatures on payload: %w", err) + } + + return f.getTx() +} + +// getSignBytesAdapter returns the sign bytes for a given transaction and sign mode. +func (f *Factory) getSignBytesAdapter(ctx context.Context, signerData signing.SignerData) ([]byte, error) { + txData, err := f.getSigningTxData() + if err != nil { + return nil, err + } + + // Generate the bytes to be signed. + return f.txConfig.SignModeHandler().GetSignBytes(ctx, f.signMode(), signerData, *txData) +} + +// WithGas returns a copy of the Factory with an updated gas value. +func (f *Factory) WithGas(gas uint64) { + f.txParams.gas = gas +} + +// WithSequence returns a copy of the Factory with an updated sequence number. +func (f *Factory) WithSequence(sequence uint64) { + f.txParams.Sequence = sequence +} + +// WithAccountNumber returns a copy of the Factory with an updated account number. +func (f *Factory) WithAccountNumber(accnum uint64) { + f.txParams.AccountNumber = accnum +} + +// sequence returns the sequence number. +func (f *Factory) sequence() uint64 { return f.txParams.Sequence } + +// gasAdjustment returns the gas adjustment value. +func (f *Factory) gasAdjustment() float64 { return f.txParams.gasAdjustment } + +// simulateAndExecute returns whether to simulate and execute. +func (f *Factory) simulateAndExecute() bool { return f.txParams.simulateAndExecute } + +// signMode returns the sign mode. +func (f *Factory) signMode() apitxsigning.SignMode { return f.txParams.SignMode } + +// getSimPK gets the public key to use for building a simulation tx. +// Note, we should only check for keys in the keybase if we are in simulate and execute mode, +// e.g. when using --gas=auto. +// When using --dry-run, we are is simulation mode only and should not check the keybase. +// Ref: https://github.com/cosmos/cosmos-sdk/issues/11283 +func (f *Factory) getSimPK() (cryptotypes.PubKey, error) { + var ( + err error + pk cryptotypes.PubKey = &secp256k1.PubKey{} + ) + + if f.txParams.simulateAndExecute && f.keybase != nil { + pk, err = f.keybase.GetPubKey(f.txParams.FromName) + if err != nil { + return nil, err + } + } else { + // When in dry-run mode, attempt to retrieve the account using the provided address. + // If the account retrieval fails, the default public key is used. + acc, err := f.accountRetriever.GetAccount(context.Background(), f.txParams.Address) + if err != nil { + // If there is an error retrieving the account, return the default public key. + return pk, nil + } + // If the account is successfully retrieved, use its public key. + pk = acc.GetPubKey() + } + + return pk, nil +} + +// getSimSignatureData based on the pubKey type gets the correct SignatureData type +// to use for building a simulation tx. +func (f *Factory) getSimSignatureData(pk cryptotypes.PubKey) SignatureData { + multisigPubKey, ok := pk.(*multisig.LegacyAminoPubKey) + if !ok { + return &SingleSignatureData{SignMode: f.txParams.SignMode} + } + + multiSignatureData := make([]SignatureData, 0, multisigPubKey.Threshold) + for i := uint32(0); i < multisigPubKey.Threshold; i++ { + multiSignatureData = append(multiSignatureData, &SingleSignatureData{ + SignMode: f.signMode(), + }) + } + + return &MultiSignatureData{ + BitArray: &apicrypto.CompactBitArray{}, + Signatures: multiSignatureData, + } +} + +func (f *Factory) getTx() (*wrappedTx, error) { + msgs, err := msgsV1toAnyV2(f.tx.msgs) + if err != nil { + return nil, err + } + + body := &apitx.TxBody{ + Messages: msgs, + Memo: f.tx.memo, + TimeoutHeight: f.tx.timeoutHeight, + ExtensionOptions: f.tx.extensionOptions, + NonCriticalExtensionOptions: f.tx.nonCriticalExtensionOptions, + } + + fee, err := f.getFee() + if err != nil { + return nil, err + } + + authInfo := &apitx.AuthInfo{ + SignerInfos: f.tx.signerInfos, + Fee: fee, + } + + bodyBytes, err := marshalOption.Marshal(body) + if err != nil { + return nil, err + } + + authInfoBytes, err := marshalOption.Marshal(authInfo) + if err != nil { + return nil, err + } + + txRawBytes, err := marshalOption.Marshal(&apitx.TxRaw{ + BodyBytes: bodyBytes, + AuthInfoBytes: authInfoBytes, + Signatures: f.tx.signatures, + }) + if err != nil { + return nil, err + } + + decodedTx, err := f.txConfig.Decoder().Decode(txRawBytes) + if err != nil { + return nil, err + } + + return newWrapperTx(f.cdc, decodedTx), nil +} + +// getSigningTxData returns a TxData with the current txState info. +func (f *Factory) getSigningTxData() (*signing.TxData, error) { + tx, err := f.getTx() + if err != nil { + return nil, err + } + + return &signing.TxData{ + Body: tx.Tx.Body, + AuthInfo: tx.Tx.AuthInfo, + BodyBytes: tx.TxRaw.BodyBytes, + AuthInfoBytes: tx.TxRaw.AuthInfoBytes, + BodyHasUnknownNonCriticals: tx.TxBodyHasUnknownNonCriticals, + }, nil +} + +// setSignatures sets the signatures for the transaction builder. +// It takes a variable number of Signature arguments and processes each one to extract the mode information and raw signature. +// It also converts the public key to the appropriate format and sets the signer information. +func (f *Factory) setSignatures(signatures ...Signature) error { + n := len(signatures) + signerInfos := make([]*apitx.SignerInfo, n) + rawSignatures := make([][]byte, n) + + for i, sig := range signatures { + var ( + modeInfo *apitx.ModeInfo + pubKey *codectypes.Any + err error + anyPk *anypb.Any + ) + + modeInfo, rawSignatures[i] = signatureDataToModeInfoAndSig(sig.Data) + if sig.PubKey != nil { + pubKey, err = codectypes.NewAnyWithValue(sig.PubKey) + if err != nil { + return err + } + anyPk = &anypb.Any{ + TypeUrl: pubKey.TypeUrl, + Value: pubKey.Value, + } + } + + signerInfos[i] = &apitx.SignerInfo{ + PublicKey: anyPk, + ModeInfo: modeInfo, + Sequence: sig.Sequence, + } + } + + f.tx.signerInfos = signerInfos + f.tx.signatures = rawSignatures + + return nil +} + +// getFee computes the transaction fee information. +// It returns a pointer to an apitx.Fee struct containing the fee amount, gas limit, payer, and granter information. +// If the granter or payer addresses are set, it converts them from bytes to string using the addressCodec. +func (f *Factory) getFee() (fee *apitx.Fee, err error) { + granterStr := "" + if f.tx.granter != nil { + granterStr, err = f.ac.BytesToString(f.tx.granter) + if err != nil { + return nil, err + } + } + + payerStr := "" + if f.tx.payer != nil { + payerStr, err = f.ac.BytesToString(f.tx.payer) + if err != nil { + return nil, err + } + } + + fee = &apitx.Fee{ + Amount: f.tx.fees, + GasLimit: f.tx.gasLimit, + Payer: payerStr, + Granter: granterStr, + } + + return fee, nil +} + +// setFeePayer sets the fee payer for the transaction. +func (f *Factory) setFeePayer(feePayer string) error { + if feePayer == "" { + return nil + } + + addr, err := f.ac.StringToBytes(feePayer) + if err != nil { + return err + } + f.tx.payer = addr + return nil +} + +// setFeeGranter sets the fee granter's address in the transaction builder. +// If the feeGranter string is empty, the function returns nil without setting an address. +// It converts the feeGranter string to bytes using the address codec and sets it as the granter address. +// Returns an error if the conversion fails. +func (f *Factory) setFeeGranter(feeGranter string) error { + if feeGranter == "" { + return nil + } + + addr, err := f.ac.StringToBytes(feeGranter) + if err != nil { + return err + } + f.tx.granter = addr + + return nil +} + +// msgsV1toAnyV2 converts a slice of sdk.Msg (v1) to a slice of anypb.Any (v2). +// It first converts each sdk.Msg into a codectypes.Any and then converts +// these into anypb.Any. +func msgsV1toAnyV2(msgs []sdk.Msg) ([]*anypb.Any, error) { + anys := make([]*codectypes.Any, len(msgs)) + for i, msg := range msgs { + anyMsg, err := codectypes.NewAnyWithValue(msg) + if err != nil { + return nil, err + } + anys[i] = anyMsg + } + + return intoAnyV2(anys), nil +} + +// intoAnyV2 converts a slice of codectypes.Any (v1) to a slice of anypb.Any (v2). +func intoAnyV2(v1s []*codectypes.Any) []*anypb.Any { + v2s := make([]*anypb.Any, len(v1s)) + for i, v1 := range v1s { + v2s[i] = &anypb.Any{ + TypeUrl: v1.TypeUrl, + Value: v1.Value, + } + } + return v2s +} + +// checkMultipleSigners checks that there can be maximum one DIRECT signer in +// a tx. +func checkMultipleSigners(tx Tx) error { + directSigners := 0 + sigsV2, err := tx.GetSignatures() + if err != nil { + return err + } + for _, sig := range sigsV2 { + directSigners += countDirectSigners(sig.Data) + if directSigners > 1 { + return errors.New("txs signed with CLI can have maximum 1 DIRECT signer") + } + } + + return nil +} + +// validateMemo validates the memo field. +func validateMemo(memo string) error { + // Prevent simple inclusion of a valid mnemonic in the memo field + if memo != "" && bip39.IsMnemonicValid(strings.ToLower(memo)) { + return errors.New("cannot provide a valid mnemonic seed in the memo field") + } + + return nil +} diff --git a/connect/internal/tx/factory_test.go b/connect/internal/tx/factory_test.go new file mode 100644 index 00000000..4bf4fc1a --- /dev/null +++ b/connect/internal/tx/factory_test.go @@ -0,0 +1,907 @@ +package tx + +import ( + "context" + "testing" + + "github.com/stretchr/testify/require" + "google.golang.org/protobuf/types/known/anypb" + + banktypes "cosmossdk.io/api/cosmos/bank/v1beta1" + base "cosmossdk.io/api/cosmos/base/v1beta1" + apitxsigning "cosmossdk.io/api/cosmos/tx/signing/v1beta1" + "cosmossdk.io/x/tx/signing" + + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" + "github.com/cosmos/cosmos-sdk/crypto/keys/multisig" + "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +var ( + FromAddress = "cosmos1zglwfu6xjzvzagqcmvzewyzjp9xwqw5qwrr8n9" + addr, _ = ac.StringToBytes(FromAddress) +) + +func TestFactory_prepareTxParams(t *testing.T) { + tests := []struct { + name string + txParams TxParameters + error bool + }{ + { + name: "no error", + txParams: TxParameters{ + AccountConfig: AccountConfig{ + Address: addr, + }, + }, + }, + { + name: "without account", + txParams: TxParameters{}, + error: true, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + var err error + tt.txParams, err = prepareTxParams(tt.txParams, mockAccountRetriever{}, false) + if (err != nil) != tt.error { + t.Errorf("Prepare() error = %v, wantErr %v", err, tt.error) + } + }) + } +} + +func TestFactory_BuildUnsignedTx(t *testing.T) { + tests := []struct { + name string + txParams TxParameters + msgs []sdk.Msg + error bool + }{ + { + name: "no error", + txParams: TxParameters{ + ChainID: "demo", + AccountConfig: AccountConfig{ + Address: addr, + }, + }, + msgs: []sdk.Msg{ + &banktypes.MsgSend{ + FromAddress: FromAddress, + }, + }, + }, + { + name: "fees and gas price provided", + txParams: TxParameters{ + ChainID: "demo", + AccountConfig: AccountConfig{ + Address: addr, + }, + GasConfig: GasConfig{ + gasPrices: []*base.DecCoin{ + { + Amount: "1000", + Denom: "stake", + }, + }, + }, + FeeConfig: FeeConfig{ + fees: []*base.Coin{ + { + Amount: "1000", + Denom: "stake", + }, + }, + }, + }, + msgs: []sdk.Msg{}, + error: true, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + f, err := NewFactory(keybase, cdc, mockAccountRetriever{}, txConf, ac, mockClientConn{}, tt.txParams) + require.NoError(t, err) + require.NotNil(t, f) + err = f.BuildUnsignedTx(tt.msgs...) + if tt.error { + require.Error(t, err) + } else { + require.NoError(t, err) + require.Nil(t, f.tx.signatures) + } + }) + } +} + +func TestFactory_calculateGas(t *testing.T) { + tests := []struct { + name string + txParams TxParameters + msgs []sdk.Msg + error bool + }{ + { + name: "no error", + txParams: TxParameters{ + ChainID: "demo", + AccountConfig: AccountConfig{ + Address: addr, + }, + GasConfig: GasConfig{ + gasAdjustment: 1, + }, + }, + msgs: []sdk.Msg{ + &banktypes.MsgSend{ + FromAddress: FromAddress, + }, + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + f, err := NewFactory(keybase, cdc, mockAccountRetriever{}, txConf, ac, mockClientConn{}, tt.txParams) + require.NoError(t, err) + require.NotNil(t, f) + err = f.calculateGas(tt.msgs...) + if tt.error { + require.Error(t, err) + } else { + require.NoError(t, err) + require.NotZero(t, f.txParams.GasConfig) + } + }) + } +} + +func TestFactory_Simulate(t *testing.T) { + tests := []struct { + name string + txParams TxParameters + msgs []sdk.Msg + error bool + }{ + { + name: "no error", + txParams: TxParameters{ + ChainID: "demo", + AccountConfig: AccountConfig{ + Address: addr, + }, + GasConfig: GasConfig{ + gasAdjustment: 1, + }, + }, + msgs: []sdk.Msg{ + &banktypes.MsgSend{ + FromAddress: FromAddress, + }, + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + f, err := NewFactory(keybase, cdc, mockAccountRetriever{}, txConf, ac, mockClientConn{}, tt.txParams) + require.NoError(t, err) + require.NotNil(t, f) + got, got1, err := f.Simulate(tt.msgs...) + if tt.error { + require.Error(t, err) + } else { + require.NoError(t, err) + require.NotNil(t, got) + require.NotZero(t, got1) + } + }) + } +} + +func TestFactory_BuildSimTx(t *testing.T) { + tests := []struct { + name string + txParams TxParameters + msgs []sdk.Msg + want []byte + error bool + }{ + { + name: "no error", + txParams: TxParameters{ + ChainID: "demo", + AccountConfig: AccountConfig{ + Address: addr, + }, + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + f, err := NewFactory(keybase, cdc, mockAccountRetriever{}, txConf, ac, mockClientConn{}, tt.txParams) + require.NoError(t, err) + require.NotNil(t, f) + got, err := f.BuildSimTx(tt.msgs...) + if tt.error { + require.Error(t, err) + } else { + require.NoError(t, err) + require.NotNil(t, got) + } + }) + } +} + +func TestFactory_Sign(t *testing.T) { + tests := []struct { + name string + txParams TxParameters + wantErr bool + }{ + { + name: "no error", + txParams: TxParameters{ + ChainID: "demo", + AccountConfig: AccountConfig{ + FromName: "alice", + Address: addr, + }, + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + f, err := NewFactory(setKeyring(), cdc, mockAccountRetriever{}, txConf, ac, mockClientConn{}, tt.txParams) + require.NoError(t, err) + require.NotNil(t, f) + + err = f.BuildUnsignedTx([]sdk.Msg{ + &banktypes.MsgSend{ + FromAddress: FromAddress, + }, + }...) + require.NoError(t, err) + + require.Nil(t, f.tx.signatures) + + tx, err := f.sign(context.Background(), true) + if tt.wantErr { + require.Error(t, err) + } else { + require.NoError(t, err) + sigs, err := tx.GetSignatures() + require.NoError(t, err) + require.NotNil(t, sigs) + } + }) + } +} + +func TestFactory_getSignBytesAdapter(t *testing.T) { + tests := []struct { + name string + txParams TxParameters + error bool + }{ + { + name: "no error", + txParams: TxParameters{ + ChainID: "demo", + SignMode: apitxsigning.SignMode_SIGN_MODE_DIRECT, + AccountConfig: AccountConfig{ + Address: addr, + }, + }, + }, + { + name: "signMode not specified", + txParams: TxParameters{ + ChainID: "demo", + AccountConfig: AccountConfig{ + Address: addr, + }, + }, + error: true, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + f, err := NewFactory(setKeyring(), cdc, mockAccountRetriever{}, txConf, ac, mockClientConn{}, tt.txParams) + require.NoError(t, err) + require.NotNil(t, f) + + err = f.BuildUnsignedTx([]sdk.Msg{ + &banktypes.MsgSend{ + FromAddress: FromAddress, + }, + }...) + require.NoError(t, err) + + pk, err := f.keybase.GetPubKey("alice") + require.NoError(t, err) + require.NotNil(t, pk) + + addr, err := f.ac.BytesToString(pk.Address()) + require.NoError(t, err) + require.NotNil(t, addr) + + FromAddressData := signing.SignerData{ + Address: addr, + ChainID: f.txParams.ChainID, + AccountNumber: 0, + Sequence: 0, + PubKey: &anypb.Any{ + TypeUrl: codectypes.MsgTypeURL(pk), + Value: pk.Bytes(), + }, + } + + got, err := f.getSignBytesAdapter(context.Background(), FromAddressData) + if tt.error { + require.Error(t, err) + } else { + require.NoError(t, err) + require.NotNil(t, got) + } + }) + } +} + +func Test_validateMemo(t *testing.T) { + tests := []struct { + name string + memo string + wantErr bool + }{ + { + name: "empty memo", + memo: "", + }, + { + name: "valid memo", + memo: "11245", + }, + { + name: "invalid Memo", + memo: "echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo", + wantErr: true, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := validateMemo(tt.memo); (err != nil) != tt.wantErr { + t.Errorf("validateMemo() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func TestFactory_WithFunctions(t *testing.T) { + tests := []struct { + name string + txParams TxParameters + withFunc func(*Factory) + checkFunc func(*Factory) bool + }{ + { + name: "with gas", + txParams: TxParameters{ + AccountConfig: AccountConfig{ + Address: addr, + }, + }, + withFunc: func(f *Factory) { + f.WithGas(1000) + }, + checkFunc: func(f *Factory) bool { + return f.txParams.GasConfig.gas == 1000 + }, + }, + { + name: "with sequence", + txParams: TxParameters{ + AccountConfig: AccountConfig{ + Address: addr, + }, + }, + withFunc: func(f *Factory) { + f.WithSequence(10) + }, + checkFunc: func(f *Factory) bool { + return f.txParams.AccountConfig.Sequence == 10 + }, + }, + { + name: "with account number", + txParams: TxParameters{ + AccountConfig: AccountConfig{ + Address: addr, + }, + }, + withFunc: func(f *Factory) { + f.WithAccountNumber(123) + }, + checkFunc: func(f *Factory) bool { + return f.txParams.AccountConfig.AccountNumber == 123 + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + f, err := NewFactory(setKeyring(), cdc, mockAccountRetriever{}, txConf, ac, mockClientConn{}, tt.txParams) + require.NoError(t, err) + require.NotNil(t, f) + + tt.withFunc(&f) + require.True(t, tt.checkFunc(&f)) + }) + } +} + +func TestFactory_getTx(t *testing.T) { + tests := []struct { + name string + txSetter func(f *Factory) + checkResult func(Tx) + }{ + { + name: "empty tx", + txSetter: func(f *Factory) { + }, + checkResult: func(tx Tx) { + wTx, ok := tx.(*wrappedTx) + require.True(t, ok) + // require.Equal(t, []*anypb.Any(nil), wTx.Tx.Body.Messages) + require.Nil(t, wTx.Tx.Body.Messages) + require.Empty(t, wTx.Tx.Body.Memo) + require.Equal(t, uint64(0), wTx.Tx.Body.TimeoutHeight) + require.Nil(t, wTx.Tx.Body.ExtensionOptions) + require.Nil(t, wTx.Tx.Body.NonCriticalExtensionOptions) + + require.Nil(t, wTx.Tx.AuthInfo.Fee.Amount) + require.Equal(t, uint64(0), wTx.Tx.AuthInfo.Fee.GasLimit) + require.Empty(t, wTx.Tx.AuthInfo.Fee.Payer) + require.Empty(t, wTx.Tx.AuthInfo.Fee.Granter) + + require.Nil(t, wTx.Tx.Signatures) + }, + }, + { + name: "full tx", + txSetter: func(f *Factory) { + pk := secp256k1.GenPrivKey().PubKey() + addr, _ := f.ac.BytesToString(pk.Address()) + + f.tx.msgs = []sdk.Msg{&banktypes.MsgSend{ + FromAddress: addr, + }} + + err := f.setFeePayer(addr) + require.NoError(t, err) + + f.tx.fees = []*base.Coin{{ + Denom: "cosmos", + Amount: "1000", + }} + + err = f.setSignatures([]Signature{{ + PubKey: pk, + Data: &SingleSignatureData{ + SignMode: apitxsigning.SignMode_SIGN_MODE_DIRECT, + Signature: nil, + }, + Sequence: 0, + }}...) + require.NoError(t, err) + }, + checkResult: func(tx Tx) { + wTx, ok := tx.(*wrappedTx) + require.True(t, ok) + require.True(t, len(wTx.Tx.Body.Messages) == 1) + + require.NotNil(t, wTx.Tx.AuthInfo.Fee.Amount) + require.NotNil(t, wTx.Tx.Signatures) + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + f, err := NewFactory(keybase, cdc, mockAccountRetriever{}, txConf, ac, mockClientConn{}, TxParameters{}) + require.NoError(t, err) + tt.txSetter(&f) + got, err := f.getTx() + require.NoError(t, err) + require.NotNil(t, got) + tt.checkResult(got) + }) + } +} + +func TestFactory_getFee(t *testing.T) { + tests := []struct { + name string + feeAmount []*base.Coin + feeGranter string + feePayer string + }{ + { + name: "get fee with payer", + feeAmount: []*base.Coin{ + { + Denom: "cosmos", + Amount: "1000", + }, + }, + feeGranter: "", + feePayer: "cosmos1zglwfu6xjzvzagqcmvzewyzjp9xwqw5qwrr8n9", + }, + { + name: "get fee with granter", + feeAmount: []*base.Coin{ + { + Denom: "cosmos", + Amount: "1000", + }, + }, + feeGranter: "cosmos1zglwfu6xjzvzagqcmvzewyzjp9xwqw5qwrr8n9", + feePayer: "", + }, + { + name: "get fee with granter and granter", + feeAmount: []*base.Coin{ + { + Denom: "cosmos", + Amount: "1000", + }, + }, + feeGranter: "cosmos1zglwfu6xjzvzagqcmvzewyzjp9xwqw5qwrr8n9", + feePayer: "cosmos1zglwfu6xjzvzagqcmvzewyzjp9xwqw5qwrr8n9", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + f, err := NewFactory(keybase, cdc, mockAccountRetriever{}, txConf, ac, mockClientConn{}, TxParameters{}) + require.NoError(t, err) + f.tx.fees = tt.feeAmount + err = f.setFeeGranter(tt.feeGranter) + require.NoError(t, err) + err = f.setFeePayer(tt.feePayer) + require.NoError(t, err) + + fee, err := f.getFee() + require.NoError(t, err) + require.NotNil(t, fee) + + require.Equal(t, fee.Amount, tt.feeAmount) + require.Equal(t, fee.Granter, tt.feeGranter) + require.Equal(t, fee.Payer, tt.feePayer) + }) + } +} + +func TestFactory_getSigningTxData(t *testing.T) { + tests := []struct { + name string + txSetter func(f *Factory) + }{ + { + name: "empty tx", + txSetter: func(f *Factory) {}, + }, + { + name: "full tx", + txSetter: func(f *Factory) { + pk := secp256k1.GenPrivKey().PubKey() + addr, _ := ac.BytesToString(pk.Address()) + + f.tx.msgs = []sdk.Msg{&banktypes.MsgSend{ + FromAddress: addr, + }} + + err := f.setFeePayer(addr) + require.NoError(t, err) + + f.tx.fees = []*base.Coin{{ + Denom: "cosmos", + Amount: "1000", + }} + + err = f.setSignatures([]Signature{{ + PubKey: pk, + Data: &SingleSignatureData{ + SignMode: apitxsigning.SignMode_SIGN_MODE_DIRECT, + Signature: []byte("signature"), + }, + Sequence: 0, + }}...) + require.NoError(t, err) + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + f, err := NewFactory(keybase, cdc, mockAccountRetriever{}, txConf, ac, mockClientConn{}, TxParameters{}) + require.NoError(t, err) + tt.txSetter(&f) + got, err := f.getSigningTxData() + require.NoError(t, err) + require.NotNil(t, got) + }) + } +} + +func TestFactory_setMsgs(t *testing.T) { + tests := []struct { + name string + msgs []sdk.Msg + wantErr bool + }{ + { + name: "set msgs", + msgs: []sdk.Msg{ + &banktypes.MsgSend{ + FromAddress: "cosmos1zglwfu6xjzvzagqcmvzewyzjp9xwqw5qwrr8n9", + ToAddress: "cosmos1zglwfu6xjzvzagqcmvzewyzjp9xwqw5qwrr8n9", + }, + &banktypes.MsgSend{ + FromAddress: "cosmos1zglwfu6xjzvzagqcmvzewyzjp9xwqw5qwrr8n9", + ToAddress: "cosmos1zglwfu6xjzvzagqcmvzewyzjp9xwqw5qwrr8n9", + }, + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + f, err := NewFactory(keybase, cdc, mockAccountRetriever{}, txConf, ac, mockClientConn{}, TxParameters{}) + require.NoError(t, err) + f.tx.msgs = tt.msgs + require.NoError(t, err) + require.Equal(t, len(tt.msgs), len(f.tx.msgs)) + + for i, msg := range tt.msgs { + require.Equal(t, msg, f.tx.msgs[i]) + } + }) + } +} + +func TestFactory_SetMemo(t *testing.T) { + tests := []struct { + name string + memo string + }{ + { + name: "set memo", + memo: "test", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + f, err := NewFactory(keybase, cdc, mockAccountRetriever{}, txConf, ac, mockClientConn{}, TxParameters{}) + require.NoError(t, err) + f.tx.memo = tt.memo + require.Equal(t, f.tx.memo, tt.memo) + }) + } +} + +func TestFactory_SetFeeAmount(t *testing.T) { + tests := []struct { + name string + coins []*base.Coin + }{ + { + name: "set coins", + coins: []*base.Coin{ + { + Denom: "cosmos", + Amount: "1000", + }, + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + f, err := NewFactory(keybase, cdc, mockAccountRetriever{}, txConf, ac, mockClientConn{}, TxParameters{}) + require.NoError(t, err) + f.tx.fees = tt.coins + require.Equal(t, len(tt.coins), len(f.tx.fees)) + + for i, coin := range tt.coins { + require.Equal(t, coin.Amount, f.tx.fees[i].Amount) + } + }) + } +} + +func TestFactory_SetGasLimit(t *testing.T) { + tests := []struct { + name string + gasLimit uint64 + }{ + { + name: "set gas limit", + gasLimit: 1, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + f, err := NewFactory(keybase, cdc, mockAccountRetriever{}, txConf, ac, mockClientConn{}, TxParameters{}) + require.NoError(t, err) + f.tx.gasLimit = tt.gasLimit + require.Equal(t, f.tx.gasLimit, tt.gasLimit) + }) + } +} + +func TestFactory_SetUnordered(t *testing.T) { + tests := []struct { + name string + unordered bool + }{ + { + name: "unordered", + unordered: true, + }, + { + name: "not unordered", + unordered: false, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + f, err := NewFactory(keybase, cdc, mockAccountRetriever{}, txConf, ac, mockClientConn{}, TxParameters{}) + require.NoError(t, err) + f.tx.unordered = tt.unordered + require.Equal(t, f.tx.unordered, tt.unordered) + }) + } +} + +func TestFactory_setSignatures(t *testing.T) { + tests := []struct { + name string + signatures func() []Signature + }{ + { + name: "set empty single signature", + signatures: func() []Signature { + return []Signature{{ + PubKey: secp256k1.GenPrivKey().PubKey(), + Data: &SingleSignatureData{ + SignMode: apitxsigning.SignMode_SIGN_MODE_DIRECT, + Signature: nil, + }, + Sequence: 0, + }} + }, + }, + { + name: "set single signature", + signatures: func() []Signature { + return []Signature{{ + PubKey: secp256k1.GenPrivKey().PubKey(), + Data: &SingleSignatureData{ + SignMode: apitxsigning.SignMode_SIGN_MODE_DIRECT, + Signature: []byte("signature"), + }, + Sequence: 0, + }} + }, + }, + { + name: "set empty multi signature", + signatures: func() []Signature { + return []Signature{{ + PubKey: multisig.NewLegacyAminoPubKey(1, []cryptotypes.PubKey{secp256k1.GenPrivKey().PubKey()}), + Data: &MultiSignatureData{ + BitArray: nil, + Signatures: []SignatureData{ + &SingleSignatureData{ + SignMode: apitxsigning.SignMode_SIGN_MODE_DIRECT, + Signature: nil, + }, + }, + }, + Sequence: 0, + }} + }, + }, + { + name: "set multi signature", + signatures: func() []Signature { + return []Signature{{ + PubKey: multisig.NewLegacyAminoPubKey(1, []cryptotypes.PubKey{secp256k1.GenPrivKey().PubKey()}), + Data: &MultiSignatureData{ + BitArray: nil, + Signatures: []SignatureData{ + &SingleSignatureData{ + SignMode: apitxsigning.SignMode_SIGN_MODE_DIRECT, + Signature: []byte("signature"), + }, + }, + }, + Sequence: 0, + }} + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + cryptocodec.RegisterInterfaces(cdc.InterfaceRegistry()) + f, err := NewFactory(keybase, cdc, mockAccountRetriever{}, txConf, ac, mockClientConn{}, TxParameters{}) + require.NoError(t, err) + sigs := tt.signatures() + err = f.setSignatures(sigs...) + require.NoError(t, err) + tx, err := f.getTx() + require.NoError(t, err) + signatures, err := tx.GetSignatures() + require.NoError(t, err) + require.Equal(t, len(sigs), len(signatures)) + for i := range signatures { + require.Equal(t, sigs[i].PubKey, signatures[i].PubKey) + } + }) + } +} + +/////////////////////// + +func Test_msgsV1toAnyV2(t *testing.T) { + tests := []struct { + name string + msgs []sdk.Msg + }{ + { + name: "convert msgV1 to V2", + msgs: []sdk.Msg{ + &banktypes.MsgSend{ + FromAddress: "cosmos1zglwfu6xjzvzagqcmvzewyzjp9xwqw5qwrr8n9", + ToAddress: "cosmos1zglwfu6xjzvzagqcmvzewyzjp9xwqw5qwrr8n9", + }, + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := msgsV1toAnyV2(tt.msgs) + require.NoError(t, err) + require.NotNil(t, got) + }) + } +} + +func Test_intoAnyV2(t *testing.T) { + tests := []struct { + name string + msgs []*codectypes.Any + }{ + { + name: "any to v2", + msgs: []*codectypes.Any{ + { + TypeUrl: "/random/msg", + Value: []byte("random message"), + }, + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got := intoAnyV2(tt.msgs) + require.NotNil(t, got) + require.Equal(t, len(got), len(tt.msgs)) + for i, msg := range got { + require.Equal(t, msg.TypeUrl, tt.msgs[i].TypeUrl) + require.Equal(t, msg.Value, tt.msgs[i].Value) + } + }) + } +} diff --git a/connect/internal/tx/flags.go b/connect/internal/tx/flags.go new file mode 100644 index 00000000..9d0a7c4a --- /dev/null +++ b/connect/internal/tx/flags.go @@ -0,0 +1,52 @@ +package tx + +import ( + "fmt" + "strconv" +) + +// Flag constants for transaction-related flags +const ( + defaultGasLimit = 200000 + gasFlagAuto = "auto" + + FlagTimeoutTimestamp = "timeout-timestamp" + FlagChainID = "chain-id" + FlagNote = "note" + FlagSignMode = "sign-mode" + FlagAccountNumber = "account-number" + FlagSequence = "sequence" + FlagFrom = "from" + FlagDryRun = "dry-run" + FlagGas = "gas" + FlagGasAdjustment = "gas-adjustment" + FlagGasPrices = "gas-prices" + FlagFees = "fees" + FlagFeePayer = "fee-payer" + FlagFeeGranter = "fee-granter" + FlagUnordered = "unordered" + FlagOffline = "offline" + FlagGenerateOnly = "generate-only" +) + +// parseGasSetting parses a string gas value. The value may either be 'auto', +// which indicates a transaction should be executed in simulate mode to +// automatically find a sufficient gas value, or a string integer. It returns an +// error if a string integer is provided which cannot be parsed. +func parseGasSetting(gasStr string) (bool, uint64, error) { + switch gasStr { + case "": + return false, defaultGasLimit, nil + + case gasFlagAuto: + return true, 0, nil + + default: + gas, err := strconv.ParseUint(gasStr, 10, 64) + if err != nil { + return false, 0, fmt.Errorf("gas must be either integer or %s", gasFlagAuto) + } + + return false, gas, nil + } +} diff --git a/connect/internal/tx/from.go b/connect/internal/tx/from.go new file mode 100644 index 00000000..5dab438c --- /dev/null +++ b/connect/internal/tx/from.go @@ -0,0 +1,97 @@ +package tx + +import ( + // "fmt" + + // "github.com/cosmos/cosmos-sdk/client/flags" + // "github.com/cosmos/cosmos-sdk/crypto/keyring" + // sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/spf13/cobra" +) + +/* TODO */ + +// GetFromAddress gets the from address from the cobra command. +// It checks the from flags, as well as the potential default ignite account (the first one) +func GetFromAddress(cmd *cobra.Command) (string, error) { + return "", nil +} + +// func setFrom() { +// if clientCtx.From == "" || flagSet.Changed(flags.FlagFrom) { +// from, _ := flagSet.GetString(flags.FlagFrom) +// fromAddr, fromName, keyType, err := GetFromFields(clientCtx, clientCtx.Keyring, from) +// if err != nil { +// return clientCtx, fmt.Errorf("failed to convert address field to address: %w", err) +// } + +// clientCtx = clientCtx.WithFrom(from).WithFromAddress(fromAddr).WithFromName(fromName) + +// if keyType == keyring.TypeLedger && clientCtx.SignModeStr == flags.SignModeTextual { +// if !slicsliceses.Contains(clientCtx.TxConfig.SignModeHandler().SupportedModes(), signingv1beta1.SignMode_SIGN_MODE_TEXTUAL) { +// return clientCtx, fmt.Errorf("SIGN_MODE_TEXTUAL is not available") +// } +// } + +// // If the `from` signer account is a ledger key, we need to use +// // SIGN_MODE_AMINO_JSON, because ledger doesn't support proto yet. +// // ref: https://github.com/cosmos/cosmos-sdk/issues/8109 +// if keyType == keyring.TypeLedger && +// clientCtx.SignModeStr != flags.SignModeLegacyAminoJSON && +// clientCtx.SignModeStr != flags.SignModeTextual && +// !clientCtx.LedgerHasProtobuf { +// fmt.Println("Default sign-mode 'direct' not supported by Ledger, using sign-mode 'amino-json'.") +// clientCtx = clientCtx.WithSignModeStr(flags.SignModeLegacyAminoJSON) +// } +// } +// } + +// // GetFromFields returns a from account address, account name and keyring type, given either an address or key name. +// // If clientCtx.Simulate is true the keystore is not accessed and a valid address must be provided +// // If clientCtx.GenerateOnly is true the keystore is only accessed if a key name is provided +// // If from is empty, the default key if specified in the context will be used +// func GetFromFields(clientCtx Context, kr keyring.Keyring, from string) (sdk.AccAddress, string, keyring.KeyType, error) { +// if from == "" && clientCtx.KeyringDefaultKeyName != "" { +// from = clientCtx.KeyringDefaultKeyName +// _ = clientCtx.PrintString(fmt.Sprintf("No key name or address provided; using the default key: %s\n", clientCtx.KeyringDefaultKeyName)) +// } + +// if from == "" { +// return nil, "", 0, nil +// } + +// addr, err := clientCtx.AddressCodec.StringToBytes(from) +// switch { +// case clientCtx.Simulate: +// if err != nil { +// return nil, "", 0, fmt.Errorf("a valid address must be provided in simulation mode: %w", err) +// } + +// return addr, "", 0, nil + +// case clientCtx.GenerateOnly: +// if err == nil { +// return addr, "", 0, nil +// } +// } + +// var k *keyring.Record +// if err == nil { +// k, err = kr.KeyByAddress(addr) +// if err != nil { +// return nil, "", 0, err +// } +// } else { +// k, err = kr.Key(from) +// if err != nil { +// return nil, "", 0, err +// } +// } + +// addr, err = k.GetAddress() +// if err != nil { +// return nil, "", 0, err +// } + +// return addr, k.Name, k.GetType(), nil +// } diff --git a/connect/internal/tx/signature.go b/connect/internal/tx/signature.go new file mode 100644 index 00000000..66235380 --- /dev/null +++ b/connect/internal/tx/signature.go @@ -0,0 +1,197 @@ +package tx + +import ( + "errors" + "fmt" + + apicrypto "cosmossdk.io/api/cosmos/crypto/multisig/v1beta1" + apitxsigning "cosmossdk.io/api/cosmos/tx/signing/v1beta1" + apitx "cosmossdk.io/api/cosmos/tx/v1beta1" + + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" +) + +// Signature holds the necessary components to verify transaction signatures. +type Signature struct { + PubKey cryptotypes.PubKey // Public key for signature verification. + Data SignatureData // Signature data containing the actual signatures. + Sequence uint64 // Account sequence, relevant for SIGN_MODE_DIRECT. +} + +// SignatureData defines an interface for different signature data types. +type SignatureData interface { + isSignatureData() +} + +// SingleSignatureData stores a single signer's signature and its mode. +type SingleSignatureData struct { + SignMode apitxsigning.SignMode // Mode of the signature. + Signature []byte // Actual binary signature. +} + +// MultiSignatureData encapsulates signatures from a multisig transaction. +type MultiSignatureData struct { + BitArray *apicrypto.CompactBitArray // Bitmap of signers. + Signatures []SignatureData // Individual signatures. +} + +func (m *SingleSignatureData) isSignatureData() {} +func (m *MultiSignatureData) isSignatureData() {} + +// signatureDataToModeInfoAndSig converts SignatureData to ModeInfo and its corresponding raw signature. +func signatureDataToModeInfoAndSig(data SignatureData) (*apitx.ModeInfo, []byte) { + if data == nil { + return nil, nil + } + + switch data := data.(type) { + case *SingleSignatureData: + return &apitx.ModeInfo{ + Sum: &apitx.ModeInfo_Single_{ + Single: &apitx.ModeInfo_Single{Mode: data.SignMode}, + }, + }, data.Signature + case *MultiSignatureData: + modeInfos := make([]*apitx.ModeInfo, len(data.Signatures)) + sigs := make([][]byte, len(data.Signatures)) + + for i, d := range data.Signatures { + modeInfos[i], sigs[i] = signatureDataToModeInfoAndSig(d) + } + + multisig := cryptotypes.MultiSignature{Signatures: sigs} + sig, err := multisig.Marshal() + if err != nil { + panic(err) + } + + return &apitx.ModeInfo{ + Sum: &apitx.ModeInfo_Multi_{ + Multi: &apitx.ModeInfo_Multi{ + Bitarray: data.BitArray, + ModeInfos: modeInfos, + }, + }, + }, sig + default: + panic(fmt.Sprintf("unexpected signature data type %T", data)) + } +} + +// modeInfoAndSigToSignatureData converts ModeInfo and a raw signature to SignatureData. +func modeInfoAndSigToSignatureData(modeInfo *apitx.ModeInfo, sig []byte) (SignatureData, error) { + switch mi := modeInfo.Sum.(type) { + case *apitx.ModeInfo_Single_: + return &SingleSignatureData{ + SignMode: mi.Single.Mode, + Signature: sig, + }, nil + + case *apitx.ModeInfo_Multi_: + multi := mi.Multi + + sigs, err := decodeMultiSignatures(sig) + if err != nil { + return nil, err + } + + sigsV2 := make([]SignatureData, len(sigs)) + for i, mi := range multi.ModeInfos { + sigsV2[i], err = modeInfoAndSigToSignatureData(mi, sigs[i]) + if err != nil { + return nil, err + } + } + return &MultiSignatureData{ + BitArray: multi.Bitarray, + Signatures: sigsV2, + }, nil + } + + return nil, fmt.Errorf("unsupported ModeInfo type %T", modeInfo) +} + +// decodeMultiSignatures decodes a byte array into individual signatures. +func decodeMultiSignatures(bz []byte) ([][]byte, error) { + multisig := cryptotypes.MultiSignature{} + + err := multisig.Unmarshal(bz) + if err != nil { + return nil, err + } + + if len(multisig.XXX_unrecognized) > 0 { + return nil, errors.New("unrecognized fields in MultiSignature") + } + return multisig.Signatures, nil +} + +// signatureDataToProto converts a SignatureData interface to a protobuf SignatureDescriptor_Data. +// This function supports both SingleSignatureData and MultiSignatureData types. +// For SingleSignatureData, it directly maps the signature mode and signature bytes to the protobuf structure. +// For MultiSignatureData, it recursively converts each signature in the collection to the corresponding protobuf structure. +func signatureDataToProto(data SignatureData) (*apitxsigning.SignatureDescriptor_Data, error) { + switch data := data.(type) { + case *SingleSignatureData: + // Handle single signature data conversion. + return &apitxsigning.SignatureDescriptor_Data{ + Sum: &apitxsigning.SignatureDescriptor_Data_Single_{ + Single: &apitxsigning.SignatureDescriptor_Data_Single{ + Mode: data.SignMode, + Signature: data.Signature, + }, + }, + }, nil + case *MultiSignatureData: + var err error + descDatas := make([]*apitxsigning.SignatureDescriptor_Data, len(data.Signatures)) + + for i, j := range data.Signatures { + descDatas[i], err = signatureDataToProto(j) + if err != nil { + return nil, err + } + } + return &apitxsigning.SignatureDescriptor_Data{ + Sum: &apitxsigning.SignatureDescriptor_Data_Multi_{ + Multi: &apitxsigning.SignatureDescriptor_Data_Multi{ + Bitarray: data.BitArray, + Signatures: descDatas, + }, + }, + }, nil + } + + // Return an error if the data type is not supported. + return nil, fmt.Errorf("unexpected signature data type %T", data) +} + +// SignatureDataFromProto converts a protobuf SignatureDescriptor_Data to a SignatureData interface. +// This function supports both Single and Multi signature data types. +func SignatureDataFromProto(descData *apitxsigning.SignatureDescriptor_Data) (SignatureData, error) { + switch descData := descData.Sum.(type) { + case *apitxsigning.SignatureDescriptor_Data_Single_: + return &SingleSignatureData{ + SignMode: descData.Single.Mode, + Signature: descData.Single.Signature, + }, nil + case *apitxsigning.SignatureDescriptor_Data_Multi_: + var err error + multi := descData.Multi + data := make([]SignatureData, len(multi.Signatures)) + + for i, j := range multi.Signatures { + data[i], err = SignatureDataFromProto(j) + if err != nil { + return nil, err + } + } + + return &MultiSignatureData{ + BitArray: multi.Bitarray, + Signatures: data, + }, nil + } + + return nil, fmt.Errorf("unexpected signature data type %T", descData) +} diff --git a/connect/internal/tx/signature_test.go b/connect/internal/tx/signature_test.go new file mode 100644 index 00000000..dd78add3 --- /dev/null +++ b/connect/internal/tx/signature_test.go @@ -0,0 +1,143 @@ +package tx + +import ( + "reflect" + "testing" + + "github.com/stretchr/testify/require" + + apimultisig "cosmossdk.io/api/cosmos/crypto/multisig/v1beta1" + apisigning "cosmossdk.io/api/cosmos/tx/signing/v1beta1" + apitx "cosmossdk.io/api/cosmos/tx/v1beta1" +) + +func TestSignatureDataToModeInfoAndSig(t *testing.T) { + tests := []struct { + name string + data SignatureData + mIResult *apitx.ModeInfo + sigResult []byte + }{ + { + name: "single signature", + data: &SingleSignatureData{ + SignMode: apisigning.SignMode_SIGN_MODE_DIRECT, + Signature: []byte("signature"), + }, + mIResult: &apitx.ModeInfo{ + Sum: &apitx.ModeInfo_Single_{ + Single: &apitx.ModeInfo_Single{Mode: apisigning.SignMode_SIGN_MODE_DIRECT}, + }, + }, + sigResult: []byte("signature"), + }, + { + name: "multi signature", + data: &MultiSignatureData{ + BitArray: nil, + Signatures: []SignatureData{ + &SingleSignatureData{ + SignMode: apisigning.SignMode_SIGN_MODE_DIRECT, + Signature: []byte("signature"), + }, + }, + }, + mIResult: &apitx.ModeInfo{ + Sum: &apitx.ModeInfo_Multi_{ + Multi: &apitx.ModeInfo_Multi{ + Bitarray: nil, + ModeInfos: []*apitx.ModeInfo{ + { + Sum: &apitx.ModeInfo_Single_{ + Single: &apitx.ModeInfo_Single{Mode: apisigning.SignMode_SIGN_MODE_DIRECT}, + }, + }, + }, + }, + }, + }, + sigResult: []byte("\n\tsignature"), + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + modeInfo, signature := signatureDataToModeInfoAndSig(tt.data) + require.Equal(t, tt.mIResult, modeInfo) + require.Equal(t, tt.sigResult, signature) + }) + } +} + +func TestModeInfoAndSigToSignatureData(t *testing.T) { + type args struct { + modeInfo func() *apitx.ModeInfo + sig []byte + } + tests := []struct { + name string + args args + want SignatureData + wantErr bool + }{ + { + name: "to SingleSignatureData", + args: args{ + modeInfo: func() *apitx.ModeInfo { + return &apitx.ModeInfo{ + Sum: &apitx.ModeInfo_Single_{ + Single: &apitx.ModeInfo_Single{Mode: apisigning.SignMode_SIGN_MODE_DIRECT}, + }, + } + }, + sig: []byte("signature"), + }, + want: &SingleSignatureData{ + SignMode: apisigning.SignMode_SIGN_MODE_DIRECT, + Signature: []byte("signature"), + }, + }, + { + name: "to MultiSignatureData", + args: args{ + modeInfo: func() *apitx.ModeInfo { + return &apitx.ModeInfo{ + Sum: &apitx.ModeInfo_Multi_{ + Multi: &apitx.ModeInfo_Multi{ + Bitarray: &apimultisig.CompactBitArray{}, + ModeInfos: []*apitx.ModeInfo{ + { + Sum: &apitx.ModeInfo_Single_{ + Single: &apitx.ModeInfo_Single{Mode: apisigning.SignMode_SIGN_MODE_DIRECT}, + }, + }, + }, + }, + }, + } + }, + sig: []byte("\n\tsignature"), + }, + want: &MultiSignatureData{ // Changed from SingleSignatureData to MultiSignatureData + BitArray: &apimultisig.CompactBitArray{}, + Signatures: []SignatureData{ + &SingleSignatureData{ + SignMode: apisigning.SignMode_SIGN_MODE_DIRECT, + Signature: []byte("signature"), + }, + }, + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := modeInfoAndSigToSignatureData(tt.args.modeInfo(), tt.args.sig) + if (err != nil) != tt.wantErr { + t.Errorf("ModeInfoAndSigToSignatureData() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("ModeInfoAndSigToSignatureData() got = %v, want %v", got, tt.want) + } + }) + } +} diff --git a/connect/internal/tx/tx.go b/connect/internal/tx/tx.go new file mode 100644 index 00000000..57a3ef85 --- /dev/null +++ b/connect/internal/tx/tx.go @@ -0,0 +1,312 @@ +package tx + +import ( + "context" + "errors" + "fmt" + + apitxsigning "cosmossdk.io/api/cosmos/tx/signing/v1beta1" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/gogoproto/grpc" + "github.com/cosmos/gogoproto/proto" + + "github.com/ignite/apps/connect/internal/account" + "github.com/ignite/apps/connect/internal/flags" +) + +// GenerateAndBroadcastTxCLI will either generate and print an unsigned transaction +// or sign it and broadcast it using default CometBFT broadcaster, returning an error upon failure. +func GenerateAndBroadcastTxCLI(ctx context.Context, conn grpc.ClientConn, msgs ...sdk.Msg) ([]byte, error) { + txCtx, err := GetContext(ctx) + if err != nil { + return nil, err + } + + txf, err := initFactory(txCtx, conn, msgs...) + if err != nil { + return nil, err + } + + if err := generateTx(txf, msgs...); err != nil { + return nil, err + } + + cBroadcaster, err := cometBroadcaster(txCtx) + if err != nil { + return nil, err + } + + return BroadcastTx(ctx, txf, cBroadcaster) +} + +// GenerateAndBroadcastTxCLIWithPrompt generates, signs and broadcasts a transaction after prompting the user for confirmation. +// It takes a context, gRPC client connection, prompt function for user confirmation, and transaction messages. +// The prompt function receives the unsigned transaction bytes and returns a boolean indicating user confirmation and any error. +// Returns the broadcast response bytes and any error encountered. +func GenerateAndBroadcastTxCLIWithPrompt( + ctx context.Context, + conn grpc.ClientConn, + prompt func([]byte) (bool, error), + msgs ...sdk.Msg, +) ([]byte, error) { + txCtx, err := GetContext(ctx) + if err != nil { + return nil, err + } + + txf, err := initFactory(txCtx, conn, msgs...) + if err != nil { + return nil, err + } + + err = generateTx(txf, msgs...) + if err != nil { + return nil, err + } + + confirmed, err := askConfirmation(txf, prompt) + if err != nil { + return nil, err + } + + if !confirmed { + return nil, nil + } + + cBroadcaster, err := cometBroadcaster(txCtx) + if err != nil { + return nil, err + } + + return BroadcastTx(ctx, txf, cBroadcaster) +} + +// GenerateOnly generates an unsigned transaction without broadcasting it. +// It initializes a transaction factory using the provided context, connection and messages, +// then generates an unsigned transaction. +// Returns the unsigned transaction bytes and any error encountered. +func GenerateOnly(ctx context.Context, conn grpc.ClientConn, msgs ...sdk.Msg) ([]byte, error) { + txCtx, err := GetContext(ctx) + if err != nil { + return nil, err + } + + txf, err := initFactory(txCtx, conn) + if err != nil { + return nil, err + } + + return generateOnly(txf, msgs...) +} + +// DryRun simulates a transaction without broadcasting it to the network. +// It initializes a transaction factory using the provided context, connection and messages, +// then performs a dry run simulation of the transaction. +// Returns the simulation response bytes and any error encountered. +func DryRun(ctx context.Context, conn grpc.ClientConn, msgs ...sdk.Msg) ([]byte, error) { + txCtx, err := GetContext(ctx) + if err != nil { + return nil, err + } + + txf, err := initFactory(txCtx, conn, msgs...) + if err != nil { + return nil, err + } + + return dryRun(txf, msgs...) +} + +// initFactory initializes a new transaction Factory and validates the provided messages. +// It retrieves the client v2 context from the provided context, validates all messages, +// and creates a new transaction Factory using the client context and connection. +// Returns the initialized Factory and any error encountered. +func initFactory(ctx Context, conn grpc.ClientConn, msgs ...sdk.Msg) (Factory, error) { + if err := validateMessages(msgs...); err != nil { + return Factory{}, err + } + + txf, err := newFactory(ctx, conn) + if err != nil { + return Factory{}, err + } + + return txf, nil +} + +// newFactory creates a new transaction Factory based on the provided context and flag set. +// It initializes a new CLI keyring, extracts transaction parameters from the flag set, +// configures transaction settings, and sets up an account retriever for the transaction Factory. +func newFactory(ctx Context, conn grpc.ClientConn) (Factory, error) { + txConfig, err := NewTxConfig(ConfigOptions{ + AddressCodec: ctx.AddressCodec, + Cdc: ctx.Cdc, + ValidatorAddressCodec: ctx.ValidatorAddressCodec, + }) + if err != nil { + return Factory{}, err + } + + accRetriever := account.NewAccountRetriever(ctx.AddressCodec, conn, ctx.Cdc.InterfaceRegistry()) + + txf, err := NewFactoryFromFlagSet(ctx.Flags, ctx.Keyring, ctx.Cdc, accRetriever, txConfig, ctx.AddressCodec, conn) + if err != nil { + return Factory{}, err + } + + return txf, nil +} + +// validateMessages validates all msgs before generating or broadcasting the tx. +// We were calling ValidateBasic separately in each CLI handler before. +// Right now, we're factorizing that call inside this function. +// ref: https://github.com/cosmos/cosmos-sdk/pull/9236#discussion_r623803504 +func validateMessages(msgs ...sdk.Msg) error { + for _, msg := range msgs { + m, ok := msg.(HasValidateBasic) + if !ok { + continue + } + + if err := m.ValidateBasic(); err != nil { + return err + } + } + + return nil +} + +// generateOnly prepares the transaction and prints the unsigned transaction string. +// It first calls Prepare on the transaction factory to set up any necessary pre-conditions. +// If preparation is successful, it generates an unsigned transaction string using the provided messages. +func generateOnly(txf Factory, msgs ...sdk.Msg) ([]byte, error) { + uTx, err := txf.UnsignedTxString(msgs...) + if err != nil { + return nil, err + } + + return []byte(uTx), nil +} + +// dryRun performs a dry run of the transaction to estimate the gas required. +// It prepares the transaction factory and simulates the transaction with the provided messages. +func dryRun(txf Factory, msgs ...sdk.Msg) ([]byte, error) { + _, gas, err := txf.Simulate(msgs...) + if err != nil { + return nil, err + } + + return []byte(fmt.Sprintf(`{"gas_estimate": %d}`, gas)), nil +} + +// SimulateTx simulates a tx and returns the simulation response obtained by the query. +func SimulateTx(ctx Context, conn grpc.ClientConn, msgs ...sdk.Msg) (proto.Message, error) { + txf, err := newFactory(ctx, conn) + if err != nil { + return nil, err + } + + simulation, _, err := txf.Simulate(msgs...) + return simulation, err +} + +// generateTx generates an unsigned transaction using the provided transaction factory and messages. +// If simulation and execution are enabled, it first calculates the gas requirements. +// It then builds the unsigned transaction with the provided messages. +func generateTx(txf Factory, msgs ...sdk.Msg) error { + if txf.simulateAndExecute() { + err := txf.calculateGas(msgs...) + if err != nil { + return err + } + } + + return txf.BuildUnsignedTx(msgs...) +} + +// BroadcastTx attempts to sign and broadcast a transaction using the provided factory and broadcaster. +// GenerateTx must be called first to prepare the transaction for signing. +// This function then signs the transaction using the factory's signing capabilities, encodes it, +// and finally broadcasts it using the provided broadcaster. +func BroadcastTx(ctx context.Context, txf Factory, broadcaster Broadcaster) ([]byte, error) { + if len(txf.tx.msgs) == 0 { + return nil, errors.New("no messages to broadcast") + } + + signedTx, err := txf.sign(ctx, true) + if err != nil { + return nil, err + } + + txBytes, err := txf.txConfig.TxEncoder()(signedTx) + if err != nil { + return nil, err + } + + return broadcaster.Broadcast(ctx, txBytes) +} + +// countDirectSigners counts the number of DIRECT signers in a signature data. +func countDirectSigners(sigData SignatureData) int { + switch data := sigData.(type) { + case *SingleSignatureData: + if data.SignMode == apitxsigning.SignMode_SIGN_MODE_DIRECT { + return 1 + } + + return 0 + case *MultiSignatureData: + directSigners := 0 + for _, d := range data.Signatures { + directSigners += countDirectSigners(d) + } + + return directSigners + default: + panic("unreachable case") + } +} + +// cometBroadcaster returns a broadcast.Broadcaster implementation that uses the CometBFT RPC client. +// It extracts the client context from the provided context and uses it to create a CometBFT broadcaster. +func cometBroadcaster(ctx Context) (Broadcaster, error) { + url, _ := ctx.Flags.GetString(flags.FlagNode) + mode, _ := ctx.Flags.GetString(flags.FlagBroadcastMode) + + return NewCometBFTBroadcaster(url, mode, ctx.Cdc) +} + +// askConfirmation encodes the transaction as JSON and prompts the user for confirmation using the provided prompter function. +// It returns the user's confirmation response and any error that occurred during the process. +func askConfirmation(txf Factory, prompter func([]byte) (bool, error)) (bool, error) { + encoder := txf.txConfig.TxJSONEncoder() + if encoder == nil { + return false, errors.New("failed to encode transaction: tx json encoder is nil") + } + + tx, err := txf.getTx() + if err != nil { + return false, err + } + + txBytes, err := encoder(tx) + if err != nil { + return false, fmt.Errorf("failed to encode transaction: %w", err) + } + + return prompter(txBytes) +} + +// getSignMode returns the corresponding apitxsigning.SignMode based on the provided mode string. +func getSignMode(mode string) apitxsigning.SignMode { + switch mode { + case "direct": + return apitxsigning.SignMode_SIGN_MODE_DIRECT + case "direct-aux": + return apitxsigning.SignMode_SIGN_MODE_DIRECT_AUX + case "amino-json": + return apitxsigning.SignMode_SIGN_MODE_LEGACY_AMINO_JSON + } + + return apitxsigning.SignMode_SIGN_MODE_UNSPECIFIED +} diff --git a/connect/internal/tx/types.go b/connect/internal/tx/types.go new file mode 100644 index 00000000..fd3b255b --- /dev/null +++ b/connect/internal/tx/types.go @@ -0,0 +1,218 @@ +package tx + +import ( + "fmt" + "time" + + "github.com/spf13/pflag" + "google.golang.org/protobuf/types/known/anypb" + + base "cosmossdk.io/api/cosmos/base/v1beta1" + apitxsigning "cosmossdk.io/api/cosmos/tx/signing/v1beta1" + apitx "cosmossdk.io/api/cosmos/tx/v1beta1" + "cosmossdk.io/core/address" + "cosmossdk.io/x/tx/signing" + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/ignite/apps/connect/internal/autocli/keyring" + "github.com/ignite/apps/connect/internal/coins" +) + +// HasValidateBasic is a copy of types.HasValidateBasic to avoid sdk import. +type HasValidateBasic interface { + // ValidateBasic does a simple validation check that + // doesn't require access to any other information. + ValidateBasic() error +} + +// TxParameters defines the parameters required for constructing a transaction. +type TxParameters struct { + timeoutTimestamp time.Time // timeoutTimestamp indicates a timestamp after which the transaction is no longer valid. + ChainID string // ChainID specifies the unique identifier of the blockchain where the transaction will be processed. + memo string // memo contains any arbitrary memo to be attached to the transaction. + SignMode apitxsigning.SignMode // signMode determines the signing mode to be used for the transaction. + + AccountConfig // AccountConfig includes information about the transaction originator's account. + GasConfig // GasConfig specifies the gas settings for the transaction. + FeeConfig // FeeConfig details the fee associated with the transaction. + ExecutionOptions // ExecutionOptions includes settings that modify how the transaction is executed. +} + +// AccountConfig defines the 'account' related fields in a transaction. +type AccountConfig struct { + // accountNumber is the unique identifier for the account. + AccountNumber uint64 + // sequence is the sequence number of the transaction. + Sequence uint64 + // fromName is the name of the account sending the transaction. + FromName string + // fromAddress is the address of the account sending the transaction. + FromAddress string + // address is the byte representation of the account address. + Address []byte +} + +// GasConfig defines the 'gas' related fields in a transaction. +// GasConfig defines the gas-related settings for a transaction. +type GasConfig struct { + gas uint64 // gas is the amount of gas requested for the transaction. + gasAdjustment float64 // gasAdjustment is the factor by which the estimated gas is multiplied to calculate the final gas limit. + gasPrices []*base.DecCoin // gasPrices is a list of denominations of DecCoin used to calculate the fee paid for the gas. +} + +// NewGasConfig creates a new GasConfig with the specified gas, gasAdjustment, and gasPrices. +// If the provided gas value is zero, it defaults to a predefined value (defaultGas). +// The gasPrices string is parsed into a slice of DecCoin. +func NewGasConfig(gas uint64, gasAdjustment float64, gasPrices string) (GasConfig, error) { + parsedGasPrices, err := coins.ParseDecCoins(gasPrices) + if err != nil { + return GasConfig{}, err + } + + return GasConfig{ + gas: gas, + gasAdjustment: gasAdjustment, + gasPrices: parsedGasPrices, + }, nil +} + +// FeeConfig holds the fee details for a transaction. +type FeeConfig struct { + fees []*base.Coin // fees are the amounts paid for the transaction. + feePayer string // feePayer is the account responsible for paying the fees. + feeGranter string // feeGranter is the account granting the fee payment if different from the payer. +} + +// NewFeeConfig creates a new FeeConfig with the specified fees, feePayer, and feeGranter. +// It parses the fees string into a slice of Coin, handling normalization. +func NewFeeConfig(fees, feePayer, feeGranter string) (FeeConfig, error) { + parsedFees, err := coins.ParseCoinsNormalized(fees) + if err != nil { + return FeeConfig{}, err + } + + return FeeConfig{ + fees: parsedFees, + feePayer: feePayer, + feeGranter: feeGranter, + }, nil +} + +// ExecutionOptions defines the transaction execution options ran by the client +type ExecutionOptions struct { + unordered bool // unordered indicates if the transaction execution order is not guaranteed. + simulateAndExecute bool // simulateAndExecute indicates if the transaction should be simulated before execution. +} + +// GasEstimateResponse defines a response definition for tx gas estimation. +type GasEstimateResponse struct { + GasEstimate uint64 `json:"gas_estimate" yaml:"gas_estimate"` +} + +func (gr GasEstimateResponse) String() string { + return fmt.Sprintf("gas estimate: %d", gr.GasEstimate) +} + +// txState represents the internal state of a transaction. +type txState struct { + msgs []sdk.Msg + timeoutHeight uint64 + timeoutTimestamp time.Time + granter []byte + payer []byte + unordered bool + memo string + gasLimit uint64 + fees []*base.Coin + signerInfos []*apitx.SignerInfo + signatures [][]byte + + extensionOptions []*anypb.Any + nonCriticalExtensionOptions []*anypb.Any +} + +// Tx defines the interface for transaction operations. +type Tx interface { + sdk.Tx + + // GetSigners fetches the addresses of the signers of the transaction. + GetSigners() ([][]byte, error) + // GetPubKeys retrieves the public keys of the signers of the transaction. + GetPubKeys() ([]cryptotypes.PubKey, error) + // GetSignatures fetches the signatures attached to the transaction. + GetSignatures() ([]Signature, error) + // GetSigningTxData returns the signing.TxData for the transaction. + GetSigningTxData() (signing.TxData, error) +} + +// txParamsFromFlagSet extracts the transaction parameters from the provided FlagSet. +func txParamsFromFlagSet(flags *pflag.FlagSet, keybase keyring.Keyring, ac address.Codec) (params TxParameters, err error) { + timestampUnix, _ := flags.GetInt64(FlagTimeoutTimestamp) + timeoutTimestamp := time.Unix(timestampUnix, 0) + chainID, _ := flags.GetString(FlagChainID) + memo, _ := flags.GetString(FlagNote) + signMode, _ := flags.GetString(FlagSignMode) + + accNumber, _ := flags.GetUint64(FlagAccountNumber) + sequence, _ := flags.GetUint64(FlagSequence) + from, _ := flags.GetString(FlagFrom) + + var fromName, fromAddress string + var addr []byte + isDryRun, _ := flags.GetBool(FlagDryRun) + generateOnly, _ := flags.GetBool(FlagGenerateOnly) + if isDryRun || generateOnly { + addr, err = ac.StringToBytes(from) + } else { + fromName, fromAddress, _, err = keybase.KeyInfo(from) + if err == nil { + addr, err = ac.StringToBytes(fromAddress) + } + } + if err != nil { + return params, err + } + + gas, _ := flags.GetString(FlagGas) + simulate, gasValue, _ := parseGasSetting(gas) + gasAdjustment, _ := flags.GetFloat64(FlagGasAdjustment) + gasPrices, _ := flags.GetString(FlagGasPrices) + + fees, _ := flags.GetString(FlagFees) + feePayer, _ := flags.GetString(FlagFeePayer) + feeGranter, _ := flags.GetString(FlagFeeGranter) + + unordered, _ := flags.GetBool(FlagUnordered) + + gasConfig, err := NewGasConfig(gasValue, gasAdjustment, gasPrices) + if err != nil { + return params, err + } + feeConfig, err := NewFeeConfig(fees, feePayer, feeGranter) + if err != nil { + return params, err + } + + txParams := TxParameters{ + timeoutTimestamp: timeoutTimestamp, + ChainID: chainID, + memo: memo, + SignMode: getSignMode(signMode), + AccountConfig: AccountConfig{ + AccountNumber: accNumber, + Sequence: sequence, + FromName: fromName, + FromAddress: fromAddress, + Address: addr, + }, + GasConfig: gasConfig, + FeeConfig: feeConfig, + ExecutionOptions: ExecutionOptions{ + unordered: unordered, + simulateAndExecute: simulate, + }, + } + + return txParams, nil +} diff --git a/connect/internal/tx/wrapper.go b/connect/internal/tx/wrapper.go new file mode 100644 index 00000000..8a3c97e2 --- /dev/null +++ b/connect/internal/tx/wrapper.go @@ -0,0 +1,139 @@ +package tx + +import ( + "fmt" + "reflect" + "strings" + + "github.com/cosmos/gogoproto/proto" + protov2 "google.golang.org/protobuf/proto" + "google.golang.org/protobuf/types/known/anypb" + + "cosmossdk.io/x/tx/decode" + "cosmossdk.io/x/tx/signing" + + "github.com/cosmos/cosmos-sdk/codec" + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +var _ Tx = wrappedTx{} + +// wrappedTx wraps a transaction and provides a codec for binary encoding/decoding. +type wrappedTx struct { + *decode.DecodedTx + + cdc codec.BinaryCodec +} + +func newWrapperTx(cdc codec.BinaryCodec, decodedTx *decode.DecodedTx) *wrappedTx { + return &wrappedTx{ + DecodedTx: decodedTx, + cdc: cdc, + } +} + +// GetSigners fetches the addresses of the signers of the transaction. +func (w wrappedTx) GetSigners() ([][]byte, error) { + return w.Signers, nil +} + +// GetPubKeys retrieves the public keys of the signers from the transaction's SignerInfos. +func (w wrappedTx) GetPubKeys() ([]cryptotypes.PubKey, error) { + signerInfos := w.Tx.AuthInfo.SignerInfos + pks := make([]cryptotypes.PubKey, len(signerInfos)) + + for i, si := range signerInfos { + // NOTE: it is okay to leave this nil if there is no PubKey in the SignerInfo. + // PubKey's can be left unset in SignerInfo. + if si.PublicKey == nil { + continue + } + maybePk, err := w.decodeAny(si.PublicKey) + if err != nil { + return nil, err + } + pk, ok := maybePk.(cryptotypes.PubKey) + if !ok { + return nil, fmt.Errorf("invalid public key type: %T", maybePk) + } + pks[i] = pk + } + + return pks, nil +} + +// GetSignatures fetches the signatures attached to the transaction. +func (w wrappedTx) GetSignatures() ([]Signature, error) { + signerInfos := w.Tx.AuthInfo.SignerInfos + sigs := w.Tx.Signatures + + pubKeys, err := w.GetPubKeys() + if err != nil { + return nil, err + } + signatures := make([]Signature, len(sigs)) + + for i, si := range signerInfos { + if si.ModeInfo == nil || si.ModeInfo.Sum == nil { + signatures[i] = Signature{ + PubKey: pubKeys[i], + } + } else { + sigData, err := modeInfoAndSigToSignatureData(si.ModeInfo, sigs[i]) + if err != nil { + return nil, err + } + signatures[i] = Signature{ + PubKey: pubKeys[i], + Data: sigData, + Sequence: si.GetSequence(), + } + } + } + + return signatures, nil +} + +func (w wrappedTx) GetSigningTxData() (signing.TxData, error) { + return signing.TxData{ + Body: w.Tx.Body, + AuthInfo: w.Tx.AuthInfo, + BodyBytes: w.TxRaw.BodyBytes, + AuthInfoBytes: w.TxRaw.AuthInfoBytes, + BodyHasUnknownNonCriticals: w.TxBodyHasUnknownNonCriticals, + }, nil +} + +// GetMsgs implements Tx. +func (w wrappedTx) GetMsgs() []sdk.Msg { + panic("not implemented") +} + +// GetMsgsV2 implements Tx. +func (w wrappedTx) GetMsgsV2() ([]protov2.Message, error) { + msgs := make([]protov2.Message, len(w.Tx.Body.Messages)) + for i, msg := range w.Tx.Body.Messages { + msgs[i] = msg + } + + return msgs, nil +} + +// decodeAny decodes a protobuf Any message into a concrete proto.Message. +func (w wrappedTx) decodeAny(anyPb *anypb.Any) (proto.Message, error) { + name := anyPb.GetTypeUrl() + if i := strings.LastIndexByte(name, '/'); i >= 0 { + name = name[i+len("/"):] + } + typ := proto.MessageType(name) + if typ == nil { + return nil, fmt.Errorf("unknown type: %s", name) + } + v1 := reflect.New(typ.Elem()).Interface().(proto.Message) + err := w.cdc.Unmarshal(anyPb.GetValue(), v1) + if err != nil { + return nil, err + } + return v1, nil +} From cd22c285ccc97d819695b27febeadbe03a90f768 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Sat, 22 Feb 2025 22:31:16 +0100 Subject: [PATCH 12/17] fix from --- connect/internal/autocli/keyring/adapter.go | 13 ++ connect/internal/autocli/keyring/interface.go | 6 + .../internal/autocli/keyring/no_keyring.go | 8 + connect/internal/tx/from.go | 149 ++++++++---------- 4 files changed, 90 insertions(+), 86 deletions(-) diff --git a/connect/internal/autocli/keyring/adapter.go b/connect/internal/autocli/keyring/adapter.go index c53848c5..48def0df 100644 --- a/connect/internal/autocli/keyring/adapter.go +++ b/connect/internal/autocli/keyring/adapter.go @@ -20,6 +20,15 @@ type autoCLIKeyringAdapter struct { ac address.Codec } +func (a *autoCLIKeyringAdapter) DefaultKey() string { + l, err := a.List() + if err != nil || len(l) == 0 { + return "" + } + + return l[0] +} + func (a *autoCLIKeyringAdapter) List() ([]string, error) { list, err := a.Keyring.List() if err != nil { @@ -104,3 +113,7 @@ func (a *autoCLIKeyringAdapter) KeyInfo(nameOrAddr string) (string, string, uint return record.Name, nameOrAddr, uint(record.GetType()), nil } + +func (a *autoCLIKeyringAdapter) Impl() any { + return a.Keyring +} diff --git a/connect/internal/autocli/keyring/interface.go b/connect/internal/autocli/keyring/interface.go index 70cd1b2c..a8ca2ce4 100644 --- a/connect/internal/autocli/keyring/interface.go +++ b/connect/internal/autocli/keyring/interface.go @@ -9,6 +9,9 @@ import ( // Keyring is an interface used for signing transactions. // It aims to be simplistic and easy to use. type Keyring interface { + // DefaultKey returns the default key name. + DefaultKey() string + // List returns the names of all keys stored in the keyring. List() ([]string, error) @@ -23,4 +26,7 @@ type Keyring interface { // KeyInfo given a key name or address returns key name, key address and key type. KeyInfo(nameOrAddr string) (string, string, uint, error) + + // Impl returns the underlying keyring implementation. + Impl() any } diff --git a/connect/internal/autocli/keyring/no_keyring.go b/connect/internal/autocli/keyring/no_keyring.go index 3ee5243b..8cabca45 100644 --- a/connect/internal/autocli/keyring/no_keyring.go +++ b/connect/internal/autocli/keyring/no_keyring.go @@ -14,6 +14,10 @@ var errNoKeyring = errors.New("no keyring configured") type NoKeyring struct{} +func (k NoKeyring) DefaultKey() string { + return "" +} + func (k NoKeyring) List() ([]string, error) { return nil, errNoKeyring } @@ -33,3 +37,7 @@ func (k NoKeyring) Sign(name string, msg []byte, signMode signingv1beta1.SignMod func (k NoKeyring) KeyInfo(nameOrAddr string) (string, string, uint, error) { return "", "", 0, errNoKeyring } + +func (k NoKeyring) Impl() any { + return nil +} diff --git a/connect/internal/tx/from.go b/connect/internal/tx/from.go index 5dab438c..55fb7648 100644 --- a/connect/internal/tx/from.go +++ b/connect/internal/tx/from.go @@ -1,97 +1,74 @@ package tx import ( - // "fmt" + "fmt" - // "github.com/cosmos/cosmos-sdk/client/flags" - // "github.com/cosmos/cosmos-sdk/crypto/keyring" - // sdk "github.com/cosmos/cosmos-sdk/types" "github.com/spf13/cobra" -) -/* TODO */ + "github.com/cosmos/cosmos-sdk/client/flags" + + sdkkeyring "github.com/cosmos/cosmos-sdk/crypto/keyring" + sdk "github.com/cosmos/cosmos-sdk/types" +) // GetFromAddress gets the from address from the cobra command. -// It checks the from flags, as well as the potential default ignite account (the first one) func GetFromAddress(cmd *cobra.Command) (string, error) { - return "", nil + from, err := cmd.Flags().GetString(flags.FlagFrom) + if err != nil { + return "", err + } + + txCtx, err := GetContext(cmd.Context()) + if err != nil { + return "", err + } + + fromAddr, keyType, err := GetFromFields(txCtx, from) + if err != nil { + return "", fmt.Errorf("failed to convert address field to address: %w", err) + } + + if keyType == sdkkeyring.TypeLedger { + // Set sign-mode flag to legacy Amino JSON when using a Ledger key. + _ = cmd.Flags().Set(flags.FlagSignMode, flags.SignModeLegacyAminoJSON) + } + + return fromAddr.String(), nil } -// func setFrom() { -// if clientCtx.From == "" || flagSet.Changed(flags.FlagFrom) { -// from, _ := flagSet.GetString(flags.FlagFrom) -// fromAddr, fromName, keyType, err := GetFromFields(clientCtx, clientCtx.Keyring, from) -// if err != nil { -// return clientCtx, fmt.Errorf("failed to convert address field to address: %w", err) -// } - -// clientCtx = clientCtx.WithFrom(from).WithFromAddress(fromAddr).WithFromName(fromName) - -// if keyType == keyring.TypeLedger && clientCtx.SignModeStr == flags.SignModeTextual { -// if !slicsliceses.Contains(clientCtx.TxConfig.SignModeHandler().SupportedModes(), signingv1beta1.SignMode_SIGN_MODE_TEXTUAL) { -// return clientCtx, fmt.Errorf("SIGN_MODE_TEXTUAL is not available") -// } -// } - -// // If the `from` signer account is a ledger key, we need to use -// // SIGN_MODE_AMINO_JSON, because ledger doesn't support proto yet. -// // ref: https://github.com/cosmos/cosmos-sdk/issues/8109 -// if keyType == keyring.TypeLedger && -// clientCtx.SignModeStr != flags.SignModeLegacyAminoJSON && -// clientCtx.SignModeStr != flags.SignModeTextual && -// !clientCtx.LedgerHasProtobuf { -// fmt.Println("Default sign-mode 'direct' not supported by Ledger, using sign-mode 'amino-json'.") -// clientCtx = clientCtx.WithSignModeStr(flags.SignModeLegacyAminoJSON) -// } -// } -// } - -// // GetFromFields returns a from account address, account name and keyring type, given either an address or key name. -// // If clientCtx.Simulate is true the keystore is not accessed and a valid address must be provided -// // If clientCtx.GenerateOnly is true the keystore is only accessed if a key name is provided -// // If from is empty, the default key if specified in the context will be used -// func GetFromFields(clientCtx Context, kr keyring.Keyring, from string) (sdk.AccAddress, string, keyring.KeyType, error) { -// if from == "" && clientCtx.KeyringDefaultKeyName != "" { -// from = clientCtx.KeyringDefaultKeyName -// _ = clientCtx.PrintString(fmt.Sprintf("No key name or address provided; using the default key: %s\n", clientCtx.KeyringDefaultKeyName)) -// } - -// if from == "" { -// return nil, "", 0, nil -// } - -// addr, err := clientCtx.AddressCodec.StringToBytes(from) -// switch { -// case clientCtx.Simulate: -// if err != nil { -// return nil, "", 0, fmt.Errorf("a valid address must be provided in simulation mode: %w", err) -// } - -// return addr, "", 0, nil - -// case clientCtx.GenerateOnly: -// if err == nil { -// return addr, "", 0, nil -// } -// } - -// var k *keyring.Record -// if err == nil { -// k, err = kr.KeyByAddress(addr) -// if err != nil { -// return nil, "", 0, err -// } -// } else { -// k, err = kr.Key(from) -// if err != nil { -// return nil, "", 0, err -// } -// } - -// addr, err = k.GetAddress() -// if err != nil { -// return nil, "", 0, err -// } - -// return addr, k.Name, k.GetType(), nil -// } +// GetFromFields returns a from account address and keyring type, given either an address or key name. +func GetFromFields(ctx Context, from string) (sdk.AccAddress, sdkkeyring.KeyType, error) { + if from == "" { + from = ctx.Keyring.DefaultKey() + if from == "" { + return nil, 0, fmt.Errorf("no key name or address provided") + } + } + + addr, err := ctx.AddressCodec.StringToBytes(from) + var k *sdkkeyring.Record + + sdkKeyring, ok := ctx.Keyring.Impl().(sdkkeyring.Keyring) + if !ok { + return nil, 0, fmt.Errorf("keyring does not implement sdkkeyring.Keyring") + } + + if err == nil { + k, err = sdkKeyring.KeyByAddress(sdk.AccAddress(addr)) + if err != nil { + return nil, 0, err + } + } else { + k, err = sdkKeyring.Key(from) + if err != nil { + return nil, 0, err + } + } + + addr, err = k.GetAddress() + if err != nil { + return nil, 0, err + } + + return addr, k.GetType(), nil +} From 53fcfa46ae3104ae451828583b80bf977acfd5f4 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Mon, 31 Mar 2025 16:02:59 +0200 Subject: [PATCH 13/17] updates --- connect/cmd/app.go | 3 ++- connect/internal/autocli/common.go | 23 ++++++++++++++++++++- connect/internal/autocli/common_test.go | 5 ++--- connect/internal/autocli/keyring/keyring.go | 7 +++---- connect/internal/autocli/msg.go | 4 ++-- connect/internal/autocli/query.go | 2 +- connect/internal/coins/util.go | 4 ++-- connect/internal/tx/from.go | 10 +++++++-- 8 files changed, 42 insertions(+), 16 deletions(-) diff --git a/connect/cmd/app.go b/connect/cmd/app.go index 3f70ef3f..1a04d7ca 100644 --- a/connect/cmd/app.go +++ b/connect/cmd/app.go @@ -66,7 +66,8 @@ func AppHandler(ctx context.Context, name string, cfg *chains.ChainConfig, args conn.ModuleOptions[cometCmds.Name()] = cometCmds.AutoCLIOptions() // add autocli commands - if err := autocli.EnhanceRootCommand(chainCmd, builder, conn.ModuleOptions); err != nil { + err = autocli.EnhanceRootCommand(chainCmd, builder, conn.ModuleOptions) + if err != nil { return nil, err } diff --git a/connect/internal/autocli/common.go b/connect/internal/autocli/common.go index 7a4f9dbb..195bcad3 100644 --- a/connect/internal/autocli/common.go +++ b/connect/internal/autocli/common.go @@ -3,10 +3,14 @@ package autocli import ( "fmt" + "github.com/cosmos/cosmos-sdk/codec" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/cosmos/gogoproto/proto" "github.com/spf13/cobra" "google.golang.org/protobuf/reflect/protoreflect" autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" + "cosmossdk.io/x/tx/signing" "github.com/ignite/apps/connect/internal/autocli/keyring" "github.com/ignite/apps/connect/internal/flags" "github.com/ignite/apps/connect/internal/print" @@ -65,12 +69,29 @@ func (b *Builder) buildMethodCommandCommon(descriptor protoreflect.MethodDescrip cmd.RunE = func(cmd *cobra.Command, args []string) error { // create context - k, err := keyring.NewKeyring(cmd.Flags(), cmd.InOrStdin(), b.AddressCodec) + k, err := keyring.NewKeyring(cmd.Flags(), b.AddressCodec, b.Config.Bech32Prefix) + if err != nil { + return err + } + + mergedFiles, err := proto.MergedRegistry() + if err != nil { + return err + } + + ir, err := codectypes.NewInterfaceRegistryWithOptions(codectypes.InterfaceRegistryOptions{ + ProtoFiles: mergedFiles, + SigningOptions: signing.Options{ + AddressCodec: b.AddressCodec, + ValidatorAddressCodec: b.ValidatorAddressCodec, + }, + }) if err != nil { return err } cmd.SetContext(tx.SetContext(cmd.Context(), tx.Context{ + Cdc: codec.NewProtoCodec(ir), Flags: cmd.Flags(), Keyring: k, AddressCodec: b.AddressCodec, diff --git a/connect/internal/autocli/common_test.go b/connect/internal/autocli/common_test.go index f340b9e5..b355754e 100644 --- a/connect/internal/autocli/common_test.go +++ b/connect/internal/autocli/common_test.go @@ -76,9 +76,8 @@ func initFixture(t *testing.T) *fixture { assert.NilError(t, b.Validate()) return &fixture{ - conn: conn, - b: b, - + conn: conn, + b: b, home: home, chainID: "autocli-test", kBackend: sdkkeyring.BackendMemory, diff --git a/connect/internal/autocli/keyring/keyring.go b/connect/internal/autocli/keyring/keyring.go index 366452f9..c49f7a30 100644 --- a/connect/internal/autocli/keyring/keyring.go +++ b/connect/internal/autocli/keyring/keyring.go @@ -1,8 +1,6 @@ package keyring import ( - "io" - "github.com/spf13/pflag" "github.com/ignite/apps/connect/internal/flags" @@ -16,8 +14,8 @@ import ( // NewKeyring creates a new keyring instance based on command-line flags. func NewKeyring( flagSet *pflag.FlagSet, - input io.Reader, addressCodec address.Codec, + bech32Prefix string, ) (Keyring, error) { keyringBackend, err := flagSet.GetString(flags.FlagKeyringBackend) if err != nil { @@ -27,8 +25,9 @@ func NewKeyring( } ca, err := cosmosaccount.New( + cosmosaccount.WithBech32Prefix(bech32Prefix), + cosmosaccount.WithHome(cosmosaccount.KeyringHome), cosmosaccount.WithKeyringBackend(cosmosaccount.KeyringBackend(keyringBackend)), - cosmosaccount.WithKeyringServiceName("ignitekeyring"), ) if err != nil { return nil, err diff --git a/connect/internal/autocli/msg.go b/connect/internal/autocli/msg.go index 1b3b2ad4..717b969f 100644 --- a/connect/internal/autocli/msg.go +++ b/connect/internal/autocli/msg.go @@ -135,7 +135,7 @@ func (b *Builder) BuildMsgMethodCommand(descriptor protoreflect.MethodDescriptor } } - signer, err := tx.GetFromAddress(cmd) + signer, err := tx.GetFromAddress(cmd, addressCodec) if err != nil { return fmt.Errorf("failed to get from address: %w", err) } @@ -192,7 +192,7 @@ func (b *Builder) handleGovProposal( } input.Set(fd, protoreflect.ValueOfString(authority)) - signerFromFlag, err := tx.GetFromAddress(cmd) + signerFromFlag, err := tx.GetFromAddress(cmd, addressCodec) if err != nil { return fmt.Errorf("failed to get from address: %w", err) } diff --git a/connect/internal/autocli/query.go b/connect/internal/autocli/query.go index 9caac36e..e9a3c174 100644 --- a/connect/internal/autocli/query.go +++ b/connect/internal/autocli/query.go @@ -245,7 +245,7 @@ func encoder(encoder aminojson.Encoder) aminojson.Encoder { return fmt.Errorf("invalid amount: %s: %w", amount, err) } - _, err = fmt.Fprintf(w, `"%s"`, sdk.NewDecCoinFromDec(denom, amountDec)) // TODO(@julienrbrt): Eventually remove this SDK dependency + _, err = fmt.Fprintf(w, `"%s"`, sdk.NewDecCoinFromDec(denom, amountDec)) return err }) } diff --git a/connect/internal/coins/util.go b/connect/internal/coins/util.go index 14953867..d5760898 100644 --- a/connect/internal/coins/util.go +++ b/connect/internal/coins/util.go @@ -33,7 +33,7 @@ func IsZero[T withAmount](coins []T) (bool, error) { } func ParseDecCoins(coins string) ([]*base.DecCoin, error) { - parsedGasPrices, err := sdk.ParseDecCoins(coins) // TODO: do it here to avoid sdk dependency + parsedGasPrices, err := sdk.ParseDecCoins(coins) if err != nil { return nil, err } @@ -49,7 +49,7 @@ func ParseDecCoins(coins string) ([]*base.DecCoin, error) { } func ParseCoinsNormalized(coins string) ([]*base.Coin, error) { - parsedFees, err := sdk.ParseCoinsNormalized(coins) // TODO: do it here to avoid sdk dependency + parsedFees, err := sdk.ParseCoinsNormalized(coins) if err != nil { return nil, err } diff --git a/connect/internal/tx/from.go b/connect/internal/tx/from.go index 55fb7648..faeae731 100644 --- a/connect/internal/tx/from.go +++ b/connect/internal/tx/from.go @@ -3,6 +3,7 @@ package tx import ( "fmt" + "cosmossdk.io/core/address" "github.com/spf13/cobra" "github.com/cosmos/cosmos-sdk/client/flags" @@ -12,7 +13,7 @@ import ( ) // GetFromAddress gets the from address from the cobra command. -func GetFromAddress(cmd *cobra.Command) (string, error) { +func GetFromAddress(cmd *cobra.Command, addressCodec address.Codec) (string, error) { from, err := cmd.Flags().GetString(flags.FlagFrom) if err != nil { return "", err @@ -33,7 +34,12 @@ func GetFromAddress(cmd *cobra.Command) (string, error) { _ = cmd.Flags().Set(flags.FlagSignMode, flags.SignModeLegacyAminoJSON) } - return fromAddr.String(), nil + fromAddrStr, err := addressCodec.BytesToString(fromAddr) + if err != nil { + return "", fmt.Errorf("failed to convert address to string: %w", err) + } + + return fromAddrStr, nil } // GetFromFields returns a from account address and keyring type, given either an address or key name. From 8d8637f040ff2d7c82213dafa8efe0bf46a24ffe Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Fri, 4 Apr 2025 00:42:15 +0200 Subject: [PATCH 14/17] try upstream --- connect/cmd/app.go | 20 +- connect/cmd/cmd.go | 13 +- connect/go.mod | 131 +- connect/go.sum | 266 +- connect/internal/ATTRIBUTIONS.md | 7 - connect/internal/account/retriever.go | 116 - connect/internal/autocli/app.go | 63 - connect/internal/autocli/common.go | 286 - connect/internal/autocli/common_test.go | 200 - connect/internal/autocli/flag/address.go | 162 - connect/internal/autocli/flag/binary.go | 63 - connect/internal/autocli/flag/builder.go | 510 -- connect/internal/autocli/flag/coin.go | 58 - connect/internal/autocli/flag/dec_coin.go | 58 - connect/internal/autocli/flag/doc.go | 4 - connect/internal/autocli/flag/duration.go | 51 - connect/internal/autocli/flag/enum.go | 79 - connect/internal/autocli/flag/interface.go | 32 - connect/internal/autocli/flag/json_message.go | 86 - connect/internal/autocli/flag/legacy_dec.go | 48 - connect/internal/autocli/flag/list.go | 107 - connect/internal/autocli/flag/map.go | 254 - connect/internal/autocli/flag/maps/generic.go | 61 - .../autocli/flag/maps/map_bool_to_value.go | 138 - .../autocli/flag/maps/map_int32_to_value.go | 159 - .../autocli/flag/maps/map_int64_to_value.go | 180 - .../autocli/flag/maps/map_string_to_value.go | 28 - .../autocli/flag/maps/map_uint32_to_value.go | 138 - .../autocli/flag/maps/map_uint64_to_value.go | 138 - .../internal/autocli/flag/messager_binder.go | 155 - connect/internal/autocli/flag/pubkey.go | 61 - connect/internal/autocli/flag/simple.go | 44 - connect/internal/autocli/flag/timestamp.go | 50 - connect/internal/autocli/keyring/adapter.go | 119 - connect/internal/autocli/keyring/interface.go | 32 - .../internal/autocli/keyring/no_keyring.go | 43 - connect/internal/autocli/msg.go | 243 - connect/internal/autocli/msg_test.go | 259 - connect/internal/autocli/prompt/message.go | 259 - .../internal/autocli/prompt/message_test.go | 59 - connect/internal/autocli/prompt/struct.go | 134 - .../internal/autocli/prompt/struct_test.go | 46 - connect/internal/autocli/prompt/util.go | 70 - connect/internal/autocli/prompt/validation.go | 52 - .../autocli/prompt/validation_test.go | 55 - connect/internal/autocli/query.go | 251 - connect/internal/autocli/query_test.go | 714 --- .../autocli/testdata/flatten-output.golden | 1 - .../autocli/testdata/help-deprecated.golden | 50 - .../autocli/testdata/help-echo-msg.golden | 33 - .../autocli/testdata/help-echo.golden | 52 - .../autocli/testdata/help-skip.golden | 7 - .../autocli/testdata/help-toplevel-msg.golden | 19 - .../autocli/testdata/help-toplevel.golden | 17 - connect/internal/autocli/testdata/help.golden | 40 - .../autocli/testdata/msg-output.golden | 1 - .../autocli/testdata/some_message.json | 1 - connect/internal/autocli/util.go | 50 - connect/internal/autocli/validate.go | 57 - connect/internal/buf.gen.gogo.yaml | 5 - connect/internal/buf.gen.pulsar.yaml | 16 - connect/internal/buf.lock | 33 - connect/internal/buf.yaml | 12 - connect/internal/coins/format.go | 62 - connect/internal/coins/format_test.go | 73 - connect/internal/coins/util.go | 66 - connect/internal/coins/util_test.go | 83 - connect/internal/governance/gov.go | 98 - .../internal/{autocli/keyring => }/keyring.go | 18 +- connect/internal/print/printer.go | 84 - connect/internal/strcase/kebab.go | 101 - connect/internal/strcase/kebab_test.go | 44 - connect/internal/testpb/msg.proto | 62 - connect/internal/testpb/msg.pulsar.go | 4435 -------------- connect/internal/testpb/msg_grpc.pb.go | 161 - connect/internal/testpb/query.proto | 70 - connect/internal/testpb/query.pulsar.go | 5438 ----------------- connect/internal/testpb/query_grpc.pb.go | 123 - connect/internal/tx/README.md | 465 -- connect/internal/tx/broadcaster.go | 15 - connect/internal/tx/comet_broadcaster.go | 196 - connect/internal/tx/comet_client_conn.go | 146 - connect/internal/tx/common_test.go | 116 - connect/internal/tx/config.go | 325 - connect/internal/tx/config_test.go | 242 - connect/internal/tx/context.go | 51 - connect/internal/tx/encoder.go | 159 - connect/internal/tx/encoder_test.go | 108 - connect/internal/tx/factory.go | 757 --- connect/internal/tx/factory_test.go | 907 --- connect/internal/tx/flags.go | 52 - connect/internal/tx/from.go | 80 - connect/internal/tx/signature.go | 197 - connect/internal/tx/signature_test.go | 143 - connect/internal/tx/tx.go | 312 - connect/internal/tx/types.go | 218 - connect/internal/tx/wrapper.go | 139 - connect/internal/util/util.go | 96 - connect/internal/util/util_test.go | 125 - connect/main.go | 22 +- 100 files changed, 251 insertions(+), 22034 deletions(-) delete mode 100644 connect/internal/ATTRIBUTIONS.md delete mode 100644 connect/internal/account/retriever.go delete mode 100644 connect/internal/autocli/app.go delete mode 100644 connect/internal/autocli/common.go delete mode 100644 connect/internal/autocli/common_test.go delete mode 100644 connect/internal/autocli/flag/address.go delete mode 100644 connect/internal/autocli/flag/binary.go delete mode 100644 connect/internal/autocli/flag/builder.go delete mode 100644 connect/internal/autocli/flag/coin.go delete mode 100644 connect/internal/autocli/flag/dec_coin.go delete mode 100644 connect/internal/autocli/flag/doc.go delete mode 100644 connect/internal/autocli/flag/duration.go delete mode 100644 connect/internal/autocli/flag/enum.go delete mode 100644 connect/internal/autocli/flag/interface.go delete mode 100644 connect/internal/autocli/flag/json_message.go delete mode 100644 connect/internal/autocli/flag/legacy_dec.go delete mode 100644 connect/internal/autocli/flag/list.go delete mode 100644 connect/internal/autocli/flag/map.go delete mode 100644 connect/internal/autocli/flag/maps/generic.go delete mode 100644 connect/internal/autocli/flag/maps/map_bool_to_value.go delete mode 100644 connect/internal/autocli/flag/maps/map_int32_to_value.go delete mode 100644 connect/internal/autocli/flag/maps/map_int64_to_value.go delete mode 100644 connect/internal/autocli/flag/maps/map_string_to_value.go delete mode 100644 connect/internal/autocli/flag/maps/map_uint32_to_value.go delete mode 100644 connect/internal/autocli/flag/maps/map_uint64_to_value.go delete mode 100644 connect/internal/autocli/flag/messager_binder.go delete mode 100644 connect/internal/autocli/flag/pubkey.go delete mode 100644 connect/internal/autocli/flag/simple.go delete mode 100644 connect/internal/autocli/flag/timestamp.go delete mode 100644 connect/internal/autocli/keyring/adapter.go delete mode 100644 connect/internal/autocli/keyring/interface.go delete mode 100644 connect/internal/autocli/keyring/no_keyring.go delete mode 100644 connect/internal/autocli/msg.go delete mode 100644 connect/internal/autocli/msg_test.go delete mode 100644 connect/internal/autocli/prompt/message.go delete mode 100644 connect/internal/autocli/prompt/message_test.go delete mode 100644 connect/internal/autocli/prompt/struct.go delete mode 100644 connect/internal/autocli/prompt/struct_test.go delete mode 100644 connect/internal/autocli/prompt/util.go delete mode 100644 connect/internal/autocli/prompt/validation.go delete mode 100644 connect/internal/autocli/prompt/validation_test.go delete mode 100644 connect/internal/autocli/query.go delete mode 100644 connect/internal/autocli/query_test.go delete mode 100644 connect/internal/autocli/testdata/flatten-output.golden delete mode 100644 connect/internal/autocli/testdata/help-deprecated.golden delete mode 100644 connect/internal/autocli/testdata/help-echo-msg.golden delete mode 100644 connect/internal/autocli/testdata/help-echo.golden delete mode 100644 connect/internal/autocli/testdata/help-skip.golden delete mode 100644 connect/internal/autocli/testdata/help-toplevel-msg.golden delete mode 100644 connect/internal/autocli/testdata/help-toplevel.golden delete mode 100644 connect/internal/autocli/testdata/help.golden delete mode 100644 connect/internal/autocli/testdata/msg-output.golden delete mode 100644 connect/internal/autocli/testdata/some_message.json delete mode 100644 connect/internal/autocli/util.go delete mode 100644 connect/internal/autocli/validate.go delete mode 100644 connect/internal/buf.gen.gogo.yaml delete mode 100644 connect/internal/buf.gen.pulsar.yaml delete mode 100644 connect/internal/buf.lock delete mode 100644 connect/internal/buf.yaml delete mode 100644 connect/internal/coins/format.go delete mode 100644 connect/internal/coins/format_test.go delete mode 100644 connect/internal/coins/util.go delete mode 100644 connect/internal/coins/util_test.go delete mode 100644 connect/internal/governance/gov.go rename connect/internal/{autocli/keyring => }/keyring.go (82%) delete mode 100644 connect/internal/print/printer.go delete mode 100644 connect/internal/strcase/kebab.go delete mode 100644 connect/internal/strcase/kebab_test.go delete mode 100644 connect/internal/testpb/msg.proto delete mode 100644 connect/internal/testpb/msg.pulsar.go delete mode 100644 connect/internal/testpb/msg_grpc.pb.go delete mode 100644 connect/internal/testpb/query.proto delete mode 100644 connect/internal/testpb/query.pulsar.go delete mode 100644 connect/internal/testpb/query_grpc.pb.go delete mode 100644 connect/internal/tx/README.md delete mode 100644 connect/internal/tx/broadcaster.go delete mode 100644 connect/internal/tx/comet_broadcaster.go delete mode 100644 connect/internal/tx/comet_client_conn.go delete mode 100644 connect/internal/tx/common_test.go delete mode 100644 connect/internal/tx/config.go delete mode 100644 connect/internal/tx/config_test.go delete mode 100644 connect/internal/tx/context.go delete mode 100644 connect/internal/tx/encoder.go delete mode 100644 connect/internal/tx/encoder_test.go delete mode 100644 connect/internal/tx/factory.go delete mode 100644 connect/internal/tx/factory_test.go delete mode 100644 connect/internal/tx/flags.go delete mode 100644 connect/internal/tx/from.go delete mode 100644 connect/internal/tx/signature.go delete mode 100644 connect/internal/tx/signature_test.go delete mode 100644 connect/internal/tx/tx.go delete mode 100644 connect/internal/tx/types.go delete mode 100644 connect/internal/tx/wrapper.go delete mode 100644 connect/internal/util/util.go delete mode 100644 connect/internal/util/util_test.go diff --git a/connect/cmd/app.go b/connect/cmd/app.go index 1a04d7ca..825520eb 100644 --- a/connect/cmd/app.go +++ b/connect/cmd/app.go @@ -16,9 +16,9 @@ import ( "google.golang.org/protobuf/reflect/protoregistry" "google.golang.org/protobuf/types/dynamicpb" + "cosmossdk.io/client/v2/autocli" + "cosmossdk.io/client/v2/autocli/flag" "github.com/ignite/apps/connect/chains" - "github.com/ignite/apps/connect/internal/autocli" - "github.com/ignite/apps/connect/internal/autocli/flag" ) func AppHandler(ctx context.Context, name string, cfg *chains.ChainConfig, args ...string) (*cobra.Command, error) { @@ -50,7 +50,6 @@ func AppHandler(ctx context.Context, name string, cfg *chains.ChainConfig, args ValidatorAddressCodec: validatorAddressCodec, ConsensusAddressCodec: consensusAddressCodec, }, - Config: cfg, GetClientConn: func(cmd *cobra.Command) (grpc.ClientConnInterface, error) { return conn.Connect() }, @@ -65,8 +64,21 @@ func AppHandler(ctx context.Context, name string, cfg *chains.ChainConfig, args cometCmds := cmtservice.NewCometBFTCommands() conn.ModuleOptions[cometCmds.Name()] = cometCmds.AutoCLIOptions() + // k, err := internal.NewKeyring(chainCmd.Flags(), addressCodec, cfg.Bech32Prefix) + // if err != nil { + // return nil, err + // } + // clientCtx := client.Context{}.WithKeyring(k) + // add autocli commands - err = autocli.EnhanceRootCommand(chainCmd, builder, conn.ModuleOptions) + autocliOptions := &autocli.AppOptions{ + ModuleOptions: conn.ModuleOptions, + AddressCodec: addressCodec, + ValidatorAddressCodec: validatorAddressCodec, + ConsensusAddressCodec: consensusAddressCodec, + } + + err = autocliOptions.EnhanceRootCommandWithBuilder(chainCmd, builder) if err != nil { return nil, err } diff --git a/connect/cmd/cmd.go b/connect/cmd/cmd.go index 84162724..d2c3d6ce 100644 --- a/connect/cmd/cmd.go +++ b/connect/cmd/cmd.go @@ -1,13 +1,11 @@ package cmd import ( - "fmt" - "github.com/ignite/cli/v28/ignite/services/plugin" ) // GetCommands returns the list of app commands. -func GetCommands(availableChains []string) []*plugin.Command { +func GetCommands() []*plugin.Command { cmd := []*plugin.Command{ { Use: "connect [command]", @@ -38,14 +36,5 @@ func GetCommands(availableChains []string) []*plugin.Command { }, } - for _, name := range availableChains { - cmd[0].Commands = append(cmd[0].Commands, - &plugin.Command{ - Use: name, - Short: fmt.Sprintf("Commands for %s chain", name), - }, - ) - } - return cmd } diff --git a/connect/go.mod b/connect/go.mod index cd1bdc28..2bbacbda 100644 --- a/connect/go.mod +++ b/connect/go.mod @@ -1,51 +1,52 @@ module github.com/ignite/apps/connect -go 1.23.0 +go 1.23.2 + +toolchain go1.24.1 + +replace github.com/cosmos/cosmos-sdk => github.com/cosmos/cosmos-sdk v0.50.13 require ( - cosmossdk.io/api v0.7.6 - cosmossdk.io/core v0.11.2 - cosmossdk.io/errors v1.0.1 - cosmossdk.io/math v1.5.0 - cosmossdk.io/x/tx v0.13.8 + cosmossdk.io/api v0.9.0 + cosmossdk.io/client/v2 v2.0.0-beta.8.0.20250403203325-d6f3ede8dc11 + cosmossdk.io/core v0.11.3 github.com/charmbracelet/bubbles v0.7.6 github.com/charmbracelet/bubbletea v1.2.4 - github.com/cometbft/cometbft v0.38.17 - github.com/cosmos/cosmos-proto v1.0.0-beta.5 - github.com/cosmos/cosmos-sdk v0.50.13 - github.com/cosmos/go-bip39 v1.0.0 - github.com/cosmos/gogoproto v1.7.0 - github.com/hashicorp/go-plugin v1.6.1 + github.com/cosmos/cosmos-sdk v0.53.0-rc.2 + github.com/hashicorp/go-plugin v1.6.3 github.com/ignite/cli/v28 v28.8.2 - github.com/manifoldco/promptui v0.9.0 - github.com/spf13/cobra v1.8.1 - github.com/spf13/pflag v1.0.5 + github.com/spf13/cobra v1.9.1 + github.com/spf13/pflag v1.0.6 github.com/stretchr/testify v1.10.0 - google.golang.org/grpc v1.70.0 - google.golang.org/protobuf v1.36.4 + google.golang.org/grpc v1.71.1 + google.golang.org/protobuf v1.36.6 gopkg.in/yaml.v3 v3.0.1 - gotest.tools/v3 v3.5.1 - sigs.k8s.io/yaml v1.4.0 ) require ( - cosmossdk.io/collections v0.4.0 // indirect - cosmossdk.io/depinject v1.1.0 // indirect - cosmossdk.io/log v1.4.1 // indirect - cosmossdk.io/store v1.1.1 // indirect + cosmossdk.io/collections v1.2.0 // indirect + cosmossdk.io/depinject v1.2.0-rc.1 // indirect + cosmossdk.io/errors v1.0.2 // indirect + cosmossdk.io/log v1.5.1 // indirect + cosmossdk.io/math v1.5.2 // indirect + cosmossdk.io/schema v1.0.0 // indirect + cosmossdk.io/store v1.1.2 // indirect + cosmossdk.io/x/tx v0.14.0-rc.1 // indirect dario.cat/mergo v1.0.1 // indirect - filippo.io/edwards25519 v1.0.0 // indirect + filippo.io/edwards25519 v1.1.0 // indirect github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect github.com/99designs/keyring v1.2.2 // indirect github.com/DataDog/datadog-go v3.2.0+incompatible // indirect - github.com/DataDog/zstd v1.5.5 // indirect + github.com/DataDog/zstd v1.5.6 // indirect github.com/Microsoft/go-winio v0.6.1 // indirect github.com/ProtonMail/go-crypto v1.1.5 // indirect github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect github.com/aymerick/douceur v0.2.0 // indirect github.com/beorn7/perks v1.0.1 // indirect - github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816 // indirect + github.com/bgentry/speakeasy v0.2.0 // indirect github.com/blang/semver/v4 v4.0.0 // indirect + github.com/bytedance/sonic v1.13.1 // indirect + github.com/bytedance/sonic/loader v0.2.4 // indirect github.com/cenkalti/backoff v2.2.1+incompatible // indirect github.com/cenkalti/backoff/v4 v4.3.0 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect @@ -54,6 +55,7 @@ require ( github.com/charmbracelet/x/term v0.2.1 // indirect github.com/chzyer/readline v1.5.1 // indirect github.com/cloudflare/circl v1.3.7 // indirect + github.com/cloudwego/base64x v0.1.5 // indirect github.com/cockroachdb/apd/v3 v3.2.1 // indirect github.com/cockroachdb/errors v1.11.3 // indirect github.com/cockroachdb/fifo v0.0.0-20240606204812-0bbfbd93a7ce // indirect @@ -61,17 +63,21 @@ require ( github.com/cockroachdb/pebble v1.1.2 // indirect github.com/cockroachdb/redact v1.1.5 // indirect github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect + github.com/cometbft/cometbft v0.38.17 // indirect github.com/cometbft/cometbft-db v0.14.1 // indirect github.com/cosmos/btcutil v1.0.5 // indirect github.com/cosmos/cosmos-db v1.1.1 // indirect + github.com/cosmos/cosmos-proto v1.0.0-beta.5 // indirect + github.com/cosmos/go-bip39 v1.0.0 // indirect github.com/cosmos/gogogateway v1.2.0 // indirect + github.com/cosmos/gogoproto v1.7.0 // indirect github.com/cosmos/iavl v1.2.2 // indirect github.com/cosmos/ics23/go v0.11.0 // indirect github.com/cosmos/ledger-cosmos-go v0.14.0 // indirect github.com/cyphar/filepath-securejoin v0.3.6 // indirect github.com/danieljoos/wincred v1.2.1 // indirect github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect - github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect + github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0 // indirect github.com/desertbit/timer v0.0.0-20180107155436-c41aec40b27f // indirect github.com/dgraph-io/badger/v4 v4.2.0 // indirect github.com/dgraph-io/ristretto v0.1.1 // indirect @@ -83,7 +89,7 @@ require ( github.com/fatih/color v1.17.0 // indirect github.com/fatih/structs v1.1.0 // indirect github.com/felixge/httpsnoop v1.0.4 // indirect - github.com/fsnotify/fsnotify v1.7.0 // indirect + github.com/fsnotify/fsnotify v1.8.0 // indirect github.com/getsentry/sentry-go v0.27.0 // indirect github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect github.com/go-git/go-billy/v5 v5.6.2 // indirect @@ -91,6 +97,7 @@ require ( github.com/go-kit/kit v0.13.0 // indirect github.com/go-kit/log v0.2.1 // indirect github.com/go-logfmt/logfmt v0.6.0 // indirect + github.com/go-viper/mapstructure/v2 v2.2.1 // indirect github.com/gobuffalo/flect v0.3.0 // indirect github.com/gobuffalo/genny/v2 v2.1.0 // indirect github.com/gobuffalo/github_flavored_markdown v1.1.4 // indirect @@ -105,14 +112,13 @@ require ( github.com/gofrs/uuid v4.4.0+incompatible // indirect github.com/gogo/googleapis v1.4.1 // indirect github.com/gogo/protobuf v1.3.2 // indirect - github.com/golang/glog v1.2.3 // indirect + github.com/golang/glog v1.2.4 // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect - github.com/golang/mock v1.6.0 // indirect github.com/golang/protobuf v1.5.4 // indirect github.com/golang/snappy v0.0.4 // indirect github.com/google/btree v1.1.3 // indirect github.com/google/flatbuffers v1.12.1 // indirect - github.com/google/go-cmp v0.6.0 // indirect + github.com/google/go-cmp v0.7.0 // indirect github.com/google/go-github/v48 v48.2.0 // indirect github.com/google/go-querystring v1.1.0 // indirect github.com/google/orderedcode v0.0.1 // indirect @@ -125,13 +131,12 @@ require ( github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c // indirect github.com/hashicorp/go-hclog v1.6.3 // indirect github.com/hashicorp/go-immutable-radix v1.3.1 // indirect - github.com/hashicorp/go-metrics v0.5.3 // indirect + github.com/hashicorp/go-metrics v0.5.4 // indirect github.com/hashicorp/golang-lru v1.0.2 // indirect github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect - github.com/hashicorp/hcl v1.0.0 // indirect github.com/hashicorp/yamux v0.1.1 // indirect - github.com/hdevalence/ed25519consensus v0.1.0 // indirect - github.com/huandu/skiplist v1.2.0 // indirect + github.com/hdevalence/ed25519consensus v0.2.0 // indirect + github.com/huandu/skiplist v1.2.1 // indirect github.com/iancoleman/strcase v0.3.0 // indirect github.com/imdario/mergo v0.3.13 // indirect github.com/improbable-eng/grpc-web v0.15.0 // indirect @@ -139,20 +144,20 @@ require ( github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect github.com/jmhodges/levigo v1.0.0 // indirect github.com/kevinburke/ssh_config v1.2.0 // indirect - github.com/klauspost/compress v1.17.9 // indirect + github.com/klauspost/compress v1.18.0 // indirect + github.com/klauspost/cpuid/v2 v2.2.10 // indirect github.com/kr/pretty v0.3.1 // indirect github.com/kr/text v0.2.0 // indirect github.com/lib/pq v1.10.9 // indirect github.com/linxGnu/grocksdb v1.8.14 // indirect github.com/lucasb-eyer/go-colorful v1.2.0 // indirect - github.com/magiconair/properties v1.8.7 // indirect - github.com/mattn/go-colorable v0.1.13 // indirect + github.com/manifoldco/promptui v0.9.0 // indirect + github.com/mattn/go-colorable v0.1.14 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/mattn/go-localereader v0.0.1 // indirect github.com/mattn/go-runewidth v0.0.15 // indirect github.com/microcosm-cc/bluemonday v1.0.23 // indirect github.com/minio/highwayhash v1.0.3 // indirect - github.com/mitchellh/go-testing-interface v1.14.1 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/mtibben/percent v0.2.1 // indirect github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect @@ -162,22 +167,21 @@ require ( github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/oasisprotocol/curve25519-voi v0.0.0-20230904125328-1f23a7beb09a // indirect github.com/oklog/run v1.1.0 // indirect - github.com/pelletier/go-toml/v2 v2.2.2 // indirect + github.com/pelletier/go-toml/v2 v2.2.3 // indirect github.com/petermattis/goid v0.0.0-20240813172612-4fcff4a6cae7 // indirect github.com/pjbgf/sha1cd v0.3.2 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect - github.com/prometheus/client_golang v1.20.5 // indirect + github.com/prometheus/client_golang v1.21.1 // indirect github.com/prometheus/client_model v0.6.1 // indirect - github.com/prometheus/common v0.62.0 // indirect + github.com/prometheus/common v0.63.0 // indirect github.com/prometheus/procfs v0.15.1 // indirect github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect github.com/rivo/uniseg v0.4.7 // indirect - github.com/rogpeppe/go-internal v1.12.0 // indirect + github.com/rogpeppe/go-internal v1.14.1 // indirect github.com/rs/cors v1.11.1 // indirect - github.com/rs/zerolog v1.33.0 // indirect - github.com/sagikazarmark/locafero v0.4.0 // indirect - github.com/sagikazarmark/slog-shim v0.1.0 // indirect + github.com/rs/zerolog v1.34.0 // indirect + github.com/sagikazarmark/locafero v0.7.0 // indirect github.com/sasha-s/go-deadlock v0.3.5 // indirect github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect github.com/sirupsen/logrus v1.9.3 // indirect @@ -185,35 +189,38 @@ require ( github.com/sourcegraph/annotate v0.0.0-20160123013949-f4cad6c6324d // indirect github.com/sourcegraph/conc v0.3.0 // indirect github.com/sourcegraph/syntaxhighlight v0.0.0-20170531221838-bd320f5d308e // indirect - github.com/spf13/afero v1.11.0 // indirect + github.com/spf13/afero v1.12.0 // indirect github.com/spf13/cast v1.7.1 // indirect - github.com/spf13/viper v1.19.0 // indirect + github.com/spf13/viper v1.20.1 // indirect github.com/subosito/gotenv v1.6.0 // indirect github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d // indirect github.com/tendermint/go-amino v0.16.0 // indirect github.com/tidwall/btree v1.7.0 // indirect + github.com/twitchyliquid64/golang-asm v0.15.1 // indirect github.com/xanzy/ssh-agent v0.3.3 // indirect github.com/zondax/hid v0.9.2 // indirect github.com/zondax/ledger-go v0.14.3 // indirect go.etcd.io/bbolt v1.4.0-alpha.0.0.20240404170359-43604f3112c5 // indirect go.opencensus.io v0.24.0 // indirect go.uber.org/multierr v1.11.0 // indirect - golang.org/x/crypto v0.32.0 // indirect - golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect - golang.org/x/mod v0.20.0 // indirect - golang.org/x/net v0.34.0 // indirect - golang.org/x/sync v0.10.0 // indirect - golang.org/x/sys v0.29.0 // indirect - golang.org/x/term v0.28.0 // indirect - golang.org/x/text v0.21.0 // indirect - golang.org/x/tools v0.24.0 // indirect + golang.org/x/arch v0.15.0 // indirect + golang.org/x/crypto v0.36.0 // indirect + golang.org/x/exp v0.0.0-20250305212735-054e65f0b394 // indirect + golang.org/x/mod v0.24.0 // indirect + golang.org/x/net v0.38.0 // indirect + golang.org/x/sync v0.12.0 // indirect + golang.org/x/sys v0.31.0 // indirect + golang.org/x/term v0.30.0 // indirect + golang.org/x/text v0.23.0 // indirect + golang.org/x/tools v0.31.0 // indirect golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect - google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de // indirect - google.golang.org/genproto/googleapis/api v0.0.0-20241202173237-19429a94021a // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20241202173237-19429a94021a // indirect - gopkg.in/ini.v1 v1.67.0 // indirect + google.golang.org/genproto v0.0.0-20241118233622-e639e219e697 // indirect + google.golang.org/genproto/googleapis/api v0.0.0-20250324211829-b45e905df463 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20250324211829-b45e905df463 // indirect gopkg.in/warnings.v0 v0.1.2 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect + gotest.tools/v3 v3.5.2 // indirect nhooyr.io/websocket v1.8.6 // indirect - pgregory.net/rapid v1.1.0 // indirect + pgregory.net/rapid v1.2.0 // indirect + sigs.k8s.io/yaml v1.4.0 // indirect ) diff --git a/connect/go.sum b/connect/go.sum index 96f96ae3..8bbdc8d2 100644 --- a/connect/go.sum +++ b/connect/go.sum @@ -1,28 +1,32 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -cosmossdk.io/api v0.7.6 h1:PC20PcXy1xYKH2KU4RMurVoFjjKkCgYRbVAD4PdqUuY= -cosmossdk.io/api v0.7.6/go.mod h1:IcxpYS5fMemZGqyYtErK7OqvdM0C8kdW3dq8Q/XIG38= -cosmossdk.io/collections v0.4.0 h1:PFmwj2W8szgpD5nOd8GWH6AbYNi1f2J6akWXJ7P5t9s= -cosmossdk.io/collections v0.4.0/go.mod h1:oa5lUING2dP+gdDquow+QjlF45eL1t4TJDypgGd+tv0= -cosmossdk.io/core v0.11.2 h1:20PXbQxhWRKA83pSYW76OXrc1MI2E93flbMAGSVFlyc= -cosmossdk.io/core v0.11.2/go.mod h1:q137AJUo+/BFZ0hTTgx+7enPAar5c3Nr0h042BgcZMY= -cosmossdk.io/depinject v1.1.0 h1:wLan7LG35VM7Yo6ov0jId3RHWCGRhe8E8bsuARorl5E= -cosmossdk.io/depinject v1.1.0/go.mod h1:kkI5H9jCGHeKeYWXTqYdruogYrEeWvBQCw1Pj4/eCFI= -cosmossdk.io/errors v1.0.1 h1:bzu+Kcr0kS/1DuPBtUFdWjzLqyUuCiyHjyJB6srBV/0= -cosmossdk.io/errors v1.0.1/go.mod h1:MeelVSZThMi4bEakzhhhE/CKqVv3nOJDA25bIqRDu/U= -cosmossdk.io/log v1.4.1 h1:wKdjfDRbDyZRuWa8M+9nuvpVYxrEOwbD/CA8hvhU8QM= -cosmossdk.io/log v1.4.1/go.mod h1:k08v0Pyq+gCP6phvdI6RCGhLf/r425UT6Rk/m+o74rU= -cosmossdk.io/math v1.5.0 h1:sbOASxee9Zxdjd6OkzogvBZ25/hP929vdcYcBJQbkLc= -cosmossdk.io/math v1.5.0/go.mod h1:AAwwBmUhqtk2nlku174JwSll+/DepUXW3rWIXN5q+Nw= -cosmossdk.io/store v1.1.1 h1:NA3PioJtWDVU7cHHeyvdva5J/ggyLDkyH0hGHl2804Y= -cosmossdk.io/store v1.1.1/go.mod h1:8DwVTz83/2PSI366FERGbWSH7hL6sB7HbYp8bqksNwM= -cosmossdk.io/x/tx v0.13.8 h1:dQwC8jMe7awx/edi1HPPZ40AjHnsix6KSO/jbKMUYKk= -cosmossdk.io/x/tx v0.13.8/go.mod h1:V6DImnwJMTq5qFjeGWpXNiT/fjgE4HtmclRmTqRVM3w= +cosmossdk.io/api v0.9.0 h1:QYs9APeSlDNGbsBOBFjp3jXgGd4hnEPnnku3+W3tT4Y= +cosmossdk.io/api v0.9.0/go.mod h1:pLkU/NSqYHWxyN7XftVt8iD7oldKJzqMZgzeiOmT2nk= +cosmossdk.io/client/v2 v2.0.0-beta.8.0.20250403203325-d6f3ede8dc11 h1:bKUGZ6U3IAsfYIlJcIAvttw/9VwmGPniadR104NjMro= +cosmossdk.io/client/v2 v2.0.0-beta.8.0.20250403203325-d6f3ede8dc11/go.mod h1:Gm12rSvOYtgoGk2BH2o5nYVjPrwmFeSJqNtD/5CVFj4= +cosmossdk.io/collections v1.2.0 h1:IesfVG8G/+FYCMVMP01frS/Cw99Omk5vBh3cHbO01Gg= +cosmossdk.io/collections v1.2.0/go.mod h1:4NkMoYw6qRA8fnSH/yn1D/MOutr8qyQnwsO50Mz9ItU= +cosmossdk.io/core v0.11.3 h1:mei+MVDJOwIjIniaKelE3jPDqShCc/F4LkNNHh+4yfo= +cosmossdk.io/core v0.11.3/go.mod h1:9rL4RE1uDt5AJ4Tg55sYyHWXA16VmpHgbe0PbJc6N2Y= +cosmossdk.io/depinject v1.2.0-rc.1 h1:Q7qfs+j8MuFPpogx4ohiSXmFvw0Ns2wcBAYU8wIZRbg= +cosmossdk.io/depinject v1.2.0-rc.1/go.mod h1:SMffgggZXkCAbLbJ65pHELkB1Z6cpFbY4CNohGojAz4= +cosmossdk.io/errors v1.0.2 h1:wcYiJz08HThbWxd/L4jObeLaLySopyyuUFB5w4AGpCo= +cosmossdk.io/errors v1.0.2/go.mod h1:0rjgiHkftRYPj//3DrD6y8hcm40HcPv/dR4R/4efr0k= +cosmossdk.io/log v1.5.1 h1:wLwiYXmfrort/O+j6EkjF+HvbdrRQd+4cYCPKFSm+zM= +cosmossdk.io/log v1.5.1/go.mod h1:5cXXBvfBkR2/BcXmosdCSLXllvgSjphrrDVdfVRmBGM= +cosmossdk.io/math v1.5.2 h1:PIhyy1JzmgPA712ewaYRjs+Hhh0iNuM8+fH18WPSejU= +cosmossdk.io/math v1.5.2/go.mod h1:ToembcWID/wR94cucsMD+2gq6xrlBBOfWcGwC7ZdwZA= +cosmossdk.io/schema v1.0.0 h1:/diH4XJjpV1JQwuIozwr+A4uFuuwanFdnw2kKeiXwwQ= +cosmossdk.io/schema v1.0.0/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= +cosmossdk.io/store v1.1.2 h1:3HOZG8+CuThREKv6cn3WSohAc6yccxO3hLzwK6rBC7o= +cosmossdk.io/store v1.1.2/go.mod h1:60rAGzTHevGm592kFhiUVkNC9w7gooSEn5iUBPzHQ6A= +cosmossdk.io/x/tx v0.14.0-rc.1 h1:EEYTknUALt7PEK7b3Q8RVDQ2vDA5A+DGFlEvVcUWjqA= +cosmossdk.io/x/tx v0.14.0-rc.1/go.mod h1:MKYHaI9c1PVM3Qns4c/7PfdbO4OaGvtaP9BmAbv8APo= dario.cat/mergo v1.0.1 h1:Ra4+bf83h2ztPIQYNP99R6m+Y7KfnARDfID+a+vLl4s= dario.cat/mergo v1.0.1/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= -filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek= -filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= +filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= +filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 h1:/vQbFIOMbk2FiG/kXiLl8BRyzTWDw7gX/Hz7Dd5eDMs= github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4/go.mod h1:hN7oaIRCjzsZ2dE+yG5k+rsdt3qcwykqK6HVGcKwsw4= github.com/99designs/keyring v1.2.2 h1:pZd3neh/EmUzWONb35LxQfvuY7kiSXAq3HQd97+XBn0= @@ -33,8 +37,8 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03 github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/DataDog/datadog-go v3.2.0+incompatible h1:qSG2N4FghB1He/r2mFrWKCaL7dXCilEuNEeAn20fdD4= github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ= -github.com/DataDog/zstd v1.5.5 h1:oWf5W7GtOLgp6bciQYDmhHHjdhYkALu6S/5Ni9ZgSvQ= -github.com/DataDog/zstd v1.5.5/go.mod h1:g4AWEaM3yOg3HYfnJ3YIawPnVdXJh9QME85blwSAmyw= +github.com/DataDog/zstd v1.5.6 h1:LbEglqepa/ipmmQJUDnSsfvA8e8IStVcGaFWDuxvGOY= +github.com/DataDog/zstd v1.5.6/go.mod h1:g4AWEaM3yOg3HYfnJ3YIawPnVdXJh9QME85blwSAmyw= github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0= github.com/Microsoft/go-winio v0.5.2/go.mod h1:WpS1mjBmmwHBEWmogvA2mj8546UReBk4v8QkMxJ6pZY= github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow= @@ -62,6 +66,7 @@ github.com/apache/thrift v0.12.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb github.com/apache/thrift v0.13.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ= github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o= github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY= +github.com/armon/go-metrics v0.4.1/go.mod h1:E6amYzXo6aW1tqzoZGT755KkbgrJsSdpwZ+3JqfkOG4= github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs= @@ -80,8 +85,8 @@ github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+Ce github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= -github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816 h1:41iFGWnSlI2gVpmOtVTJZNodLdLQLn/KsJqFvXwnd/s= -github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= +github.com/bgentry/speakeasy v0.2.0 h1:tgObeVOf8WAvtuAX6DhJ4xks4CFNwPDZiqzGqIHE51E= +github.com/bgentry/speakeasy v0.2.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= github.com/bits-and-blooms/bitset v1.8.0 h1:FD+XqgOZDUxxZ8hzoBFuV9+cGWY9CslN6d5MS5JVb4c= github.com/bits-and-blooms/bitset v1.8.0/go.mod h1:7hO7Gc7Pp1vODcmWvKMRA9BNmbv6a/7QIWpPxHddWR8= github.com/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM= @@ -92,6 +97,11 @@ github.com/btcsuite/btcd/btcutil v1.1.6 h1:zFL2+c3Lb9gEgqKNzowKUPQNb8jV7v5Oaodi/ github.com/btcsuite/btcd/btcutil v1.1.6/go.mod h1:9dFymx8HpuLqBnsPELrImQeTQfKBQqzqGbbV3jK55aE= github.com/bufbuild/protocompile v0.14.0 h1:z3DW4IvXE5G/uTOnSQn+qwQQxvhckkTWLS/0No/o7KU= github.com/bufbuild/protocompile v0.14.0/go.mod h1:N6J1NYzkspJo3ZwyL4Xjvli86XOj1xq4qAasUFxGups= +github.com/bytedance/sonic v1.13.1 h1:Jyd5CIvdFnkOWuKXr+wm4Nyk2h0yAFsr8ucJgEasO3g= +github.com/bytedance/sonic v1.13.1/go.mod h1:o68xyaF9u2gvVBuGHPlUVCy+ZfmNNO5ETf1+KgkJhz4= +github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU= +github.com/bytedance/sonic/loader v0.2.4 h1:ZWCw4stuXUsn1/+zQDqeE7JKP+QO47tz7QCNan80NzY= +github.com/bytedance/sonic/loader v0.2.4/go.mod h1:N8A3vUdtUebEY2/VQC0MyhYeKUFosQU6FxH2JmUe6VI= github.com/casbin/casbin/v2 v2.1.2/go.mod h1:YcPU1XXisHhLzuxH9coDNf2FbKpjGlbCg3n9yuLkIJQ= github.com/cenkalti/backoff v2.2.1+incompatible h1:tNowT99t7UNflLxfYYSlKYsBpXdEet03Pg2g16Swow4= github.com/cenkalti/backoff v2.2.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM= @@ -128,6 +138,9 @@ github.com/clbanning/x2j v0.0.0-20191024224557-825249438eec/go.mod h1:jMjuTZXRI4 github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/cloudflare/circl v1.3.7 h1:qlCDlTPz2n9fu58M0Nh1J/JzcFpfgkFHHX3O35r5vcU= github.com/cloudflare/circl v1.3.7/go.mod h1:sRTcRWXGLrKw6yIGJ+l7amYJFfAXbZG0kBSc8r4zxgA= +github.com/cloudwego/base64x v0.1.5 h1:XPciSp1xaq2VCSt6lF0phncD4koWyULpl5bUxbfCyP4= +github.com/cloudwego/base64x v0.1.5/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w= +github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY= github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= github.com/cncf/udpa/go v0.0.0-20210930031921-04548b0d99d4/go.mod h1:6pvJx4me5XPnfI9Z40ddWsdw2W/uZgQLFXToKeRcDiI= @@ -188,7 +201,7 @@ github.com/cosmos/ics23/go v0.11.0/go.mod h1:A8OjxPE67hHST4Icw94hOxxFEJMBG031xIG github.com/cosmos/ledger-cosmos-go v0.14.0 h1:WfCHricT3rPbkPSVKRH+L4fQGKYHuGOK9Edpel8TYpE= github.com/cosmos/ledger-cosmos-go v0.14.0/go.mod h1:E07xCWSBl3mTGofZ2QnL4cIUzMbbGVyik84QYKbX3RA= github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= -github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= +github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g= github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/cyphar/filepath-securejoin v0.3.6 h1:4d9N5ykBnSp5Xn2JkhocYDkOpURL/18CYMpo6xB9uWM= @@ -199,10 +212,10 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/decred/dcrd/crypto/blake256 v1.0.1 h1:7PltbUIQB7u/FfZ39+DGa/ShuMyJ5ilcvdfma9wOH6Y= -github.com/decred/dcrd/crypto/blake256 v1.0.1/go.mod h1:2OfgNZ5wDpcsFmHmCK5gZTPcCXqlm2ArzUIkw9czNJo= -github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 h1:rpfIENRNNilwHwZeG5+P150SMrnNEcHYvcCuK6dPZSg= -github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0= +github.com/decred/dcrd/crypto/blake256 v1.1.0 h1:zPMNGQCm0g4QTY27fOCorQW7EryeQ/U0x++OzVrdms8= +github.com/decred/dcrd/crypto/blake256 v1.1.0/go.mod h1:2OfgNZ5wDpcsFmHmCK5gZTPcCXqlm2ArzUIkw9czNJo= +github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0 h1:NMZiJj8QnKe1LgsbDayM4UoHwbvwDRwnI3hwNaAHRnc= +github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0/go.mod h1:ZXNYxsqcloTdSy/rNShjYzMhyjf0LaoftYK0p+A3h40= github.com/desertbit/timer v0.0.0-20180107155436-c41aec40b27f h1:U5y3Y5UE0w7amNe7Z5G/twsBW0KEalRQXZzf8ufSh9I= github.com/desertbit/timer v0.0.0-20180107155436-c41aec40b27f/go.mod h1:xH/i4TFMt8koVQZ6WFms69WAsDWr2XsYL3Hkl7jkoLE= github.com/dgraph-io/badger/v4 v4.2.0 h1:kJrlajbXXL9DFTNuhhu9yCx7JJa4qpYWxtE8BzuWsEs= @@ -260,8 +273,8 @@ github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7z github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU= -github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= -github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= +github.com/fsnotify/fsnotify v1.8.0 h1:dAwr6QBTBZIkG8roQaJjGof0pp0EeF+tNV7YBP3F/8M= +github.com/fsnotify/fsnotify v1.8.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0= github.com/getsentry/sentry-go v0.27.0 h1:Pv98CIbtB3LkMWmXi4Joa5OOcwbmnX88sF5qbK3r3Ps= github.com/getsentry/sentry-go v0.27.0/go.mod h1:lc76E2QywIyW8WuBnwl8Lc4bkmQH4+w1gwTf25trprY= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= @@ -313,6 +326,8 @@ github.com/go-playground/validator/v10 v10.11.1/go.mod h1:i+3WkQ1FvaUjjxh1kSvIA4 github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= +github.com/go-viper/mapstructure/v2 v2.2.1 h1:ZAaOCxANMuZx5RCeg0mBdEZk7DZasvvZIxtHqx8aGss= +github.com/go-viper/mapstructure/v2 v2.2.1/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM= github.com/gobuffalo/flect v0.3.0 h1:erfPWM+K1rFNIQeRPdeEXxo8yFr/PO17lhRnS8FUrtk= github.com/gobuffalo/flect v0.3.0/go.mod h1:5pf3aGnsvqvCj50AVni7mJJF8ICxGZ8HomberC3pXLE= github.com/gobuffalo/genny/v2 v2.1.0 h1:cCRBbqzo3GfNvj3UetD16zRgUvWFEyyl0qTqquuIqOM= @@ -360,8 +375,8 @@ github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXP github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= -github.com/golang/glog v1.2.3 h1:oDTdz9f5VGVVNGu/Q7UXKWYsD0873HXLHdJUNBsSEKM= -github.com/golang/glog v1.2.3/go.mod h1:6AhwSGph0fcJtXVM/PEHPqZlFeoLxhs7/t5UDAwmO+w= +github.com/golang/glog v1.2.4 h1:CNNw5U8lSiiBk7druxtSHHTsRWcxKoac6kZKm2peBBc= +github.com/golang/glog v1.2.4/go.mod h1:6AhwSGph0fcJtXVM/PEHPqZlFeoLxhs7/t5UDAwmO+w= github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= @@ -404,11 +419,12 @@ github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= -github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= -github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= +github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= github.com/google/go-github/v48 v48.2.0 h1:68puzySE6WqUY9KWmpOsDEQfDZsso98rT6pZcz9HqcE= github.com/google/go-github/v48 v48.2.0/go.mod h1:dDlehKBDo850ZPvCTK0sEqTCVWcrGl2LcDiajkYi89Y= github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8= @@ -460,12 +476,12 @@ github.com/hashicorp/go-hclog v1.6.3/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVH github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= github.com/hashicorp/go-immutable-radix v1.3.1 h1:DKHmCUm2hRBK510BaiZlwvpD40f8bJFeZnpfm2KLowc= github.com/hashicorp/go-immutable-radix v1.3.1/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= -github.com/hashicorp/go-metrics v0.5.3 h1:M5uADWMOGCTUNU1YuC4hfknOeHNaX54LDm4oYSucoNE= -github.com/hashicorp/go-metrics v0.5.3/go.mod h1:KEjodfebIOuBYSAe/bHTm+HChmKSxAOXPBieMLYozDE= +github.com/hashicorp/go-metrics v0.5.4 h1:8mmPiIJkTPPEbAiV97IxdAGNdRdaWwVap1BU6elejKY= +github.com/hashicorp/go-metrics v0.5.4/go.mod h1:CG5yz4NZ/AI/aQt9Ucm/vdBnbh7fvmv4lxZ350i+QQI= github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM= github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk= -github.com/hashicorp/go-plugin v1.6.1 h1:P7MR2UP6gNKGPp+y7EZw2kOiq4IR9WiqLvp0XOsVdwI= -github.com/hashicorp/go-plugin v1.6.1/go.mod h1:XPHFku2tFo3o3QKFgSYo+cghcUhw1NA1hZyMK0PWAw0= +github.com/hashicorp/go-plugin v1.6.3 h1:xgHB+ZUSYeuJi96WtxEjzi23uh7YQpznjGh0U0UUrwg= +github.com/hashicorp/go-plugin v1.6.3/go.mod h1:MRobyh+Wc/nYy1V4KAXUiYfzxoYhs7V1mlH1Z7iY2h0= github.com/hashicorp/go-retryablehttp v0.5.3/go.mod h1:9B5zBasrRhHXnJnui7y6sL7es7NDiJgTc6Er0maI1Xs= github.com/hashicorp/go-rootcerts v1.0.0/go.mod h1:K6zTfqpRlCUIjkwsN4Z+hiSfzSTQa6eBIzfwKfwNnHU= github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerXegt+ozgdvDeDU= @@ -482,21 +498,19 @@ github.com/hashicorp/golang-lru v1.0.2 h1:dV3g9Z/unq5DpblPpw+Oqcv4dU/1omnb4Ok8iP github.com/hashicorp/golang-lru v1.0.2/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k= github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM= -github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= -github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64= github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0mNTz8vQ= github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I= github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc= github.com/hashicorp/yamux v0.1.1 h1:yrQxtgseBDrq9Y652vSRDvsKCJKOUD+GzTS4Y0Y8pvE= github.com/hashicorp/yamux v0.1.1/go.mod h1:CtWFDAQgb7dxtzFs4tWbplKIe2jSi3+5vKbgIO0SLnQ= -github.com/hdevalence/ed25519consensus v0.1.0 h1:jtBwzzcHuTmFrQN6xQZn6CQEO/V9f7HsjsjeEZ6auqU= -github.com/hdevalence/ed25519consensus v0.1.0/go.mod h1:w3BHWjwJbFU29IRHL1Iqkw3sus+7FctEyM4RqDxYNzo= +github.com/hdevalence/ed25519consensus v0.2.0 h1:37ICyZqdyj0lAZ8P4D1d1id3HqbbG1N3iBb1Tb4rdcU= +github.com/hdevalence/ed25519consensus v0.2.0/go.mod h1:w3BHWjwJbFU29IRHL1Iqkw3sus+7FctEyM4RqDxYNzo= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/huandu/go-assert v1.1.5 h1:fjemmA7sSfYHJD7CUqs9qTwwfdNAx7/j2/ZlHXzNB3c= github.com/huandu/go-assert v1.1.5/go.mod h1:yOLvuqZwmcHIC5rIzrBhT7D3Q9c3GFnd0JrPVhn/06U= -github.com/huandu/skiplist v1.2.0 h1:gox56QD77HzSC0w+Ws3MH3iie755GBJU1OER3h5VsYw= -github.com/huandu/skiplist v1.2.0/go.mod h1:7v3iFjLcSAzO4fN5B8dvebvo/qsfumiLiDXMrPiHF9w= +github.com/huandu/skiplist v1.2.1 h1:dTi93MgjwErA/8idWTzIw4Y1kZsMWx35fmI2c8Rij7w= +github.com/huandu/skiplist v1.2.1/go.mod h1:7v3iFjLcSAzO4fN5B8dvebvo/qsfumiLiDXMrPiHF9w= github.com/hudl/fargo v1.3.0/go.mod h1:y3CKSmjA+wD2gak7sUSXTAoopbhU08POFhmITJgmKTg= github.com/iancoleman/strcase v0.3.0 h1:nTXanmYxhfFAMjZL34Ov6gkzEsSJZ5DbhxWjvSASxEI= github.com/iancoleman/strcase v0.3.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho= @@ -525,6 +539,7 @@ github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/u github.com/json-iterator/go v1.1.8/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= +github.com/json-iterator/go v1.1.11/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= @@ -538,8 +553,12 @@ github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/klauspost/compress v1.10.3/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs= github.com/klauspost/compress v1.11.7/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs= -github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA= -github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw= +github.com/klauspost/compress v1.18.0 h1:c/Cqfb0r+Yi+JtIEq73FWXVkRonBlf0CRNYc8Zttxdo= +github.com/klauspost/compress v1.18.0/go.mod h1:2Pp+KzxcywXVXMr50+X0Q/Lsb43OQHYWRCY2AiWywWQ= +github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= +github.com/klauspost/cpuid/v2 v2.2.10 h1:tBs3QSyvjDyFTq3uoc/9xFpCuOsJQFNPiAhYdw2skhE= +github.com/klauspost/cpuid/v2 v2.2.10/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0= +github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= @@ -572,8 +591,9 @@ github.com/manifoldco/promptui v0.9.0/go.mod h1:ka04sppxSGFAtxX0qhlYQjISsg9mR4GW github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4= -github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= +github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE= +github.com/mattn/go-colorable v0.1.14/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8= github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= @@ -600,8 +620,6 @@ github.com/minio/highwayhash v1.0.3/go.mod h1:GGYsuwP/fPD6Y9hMiXuapVvlIUEhFhMTh0 github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc= github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI= -github.com/mitchellh/go-testing-interface v1.14.1 h1:jrgshOhYAUVNMAJiKbEu7EqAwgJJ2JqpQmpLJOu07cU= -github.com/mitchellh/go-testing-interface v1.14.1/go.mod h1:gfgS7OtZj6MA4U1UrDRp04twqAjfvlZyCfX3sDjEym8= github.com/mitchellh/gox v0.4.0/go.mod h1:Sd9lOJ0+aimLBi73mGofS1ycjY8lL3uZM3JPS42BGNg= github.com/mitchellh/iochan v1.0.0/go.mod h1:JwYml1nuB7xOzsp52dPpHFffvOCDupsG0QubkSMEySY= github.com/mitchellh/mapstructure v0.0.0-20160808181253-ca63d7c062ee/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= @@ -688,8 +706,8 @@ github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FI github.com/pascaldekloe/goe v0.1.0 h1:cBOtyMzM9HTpWjXfbbunk26uA6nG3a8n06Wieeh0MwY= github.com/pascaldekloe/goe v0.1.0/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k= -github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM= -github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs= +github.com/pelletier/go-toml/v2 v2.2.3 h1:YmeHyLY8mFWbdkNWwpr+qIL2bEqT0o95WSdkNHvL12M= +github.com/pelletier/go-toml/v2 v2.2.3/go.mod h1:MfCQTFTvCcUyyvvwm1+G6H/jORL20Xlb6rzQu9GuUkc= github.com/performancecopilot/speed v3.0.0+incompatible/go.mod h1:/CLtqpZ5gBg1M9iaPbIdPPGyKcA8hKdoy6hAWba7Yac= github.com/petermattis/goid v0.0.0-20240813172612-4fcff4a6cae7 h1:Dx7Ovyv/SFnMFw3fD4oEoeorXc6saIiQ23LrGLth0Gw= github.com/petermattis/goid v0.0.0-20240813172612-4fcff4a6cae7/go.mod h1:pxMtw7cyUw6B2bRH0ZBANSPg+AoSud1I1iyJHI69jH4= @@ -715,8 +733,9 @@ github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5Fsn github.com/prometheus/client_golang v1.3.0/go.mod h1:hJaj2vgQTGQmVCsAACORcieXFeDPbaTKGT+JTgUa3og= github.com/prometheus/client_golang v1.4.0/go.mod h1:e9GMxYsXl05ICDXkRhurwBS4Q3OK1iX/F2sw+iXX5zU= github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M= -github.com/prometheus/client_golang v1.20.5 h1:cxppBPuYhUnsO6yo/aoRol4L7q7UFfdm+bR9r+8l63Y= -github.com/prometheus/client_golang v1.20.5/go.mod h1:PIEt8X02hGcP8JWbeHyeZ53Y/jReSnHgO035n//V5WE= +github.com/prometheus/client_golang v1.11.1/go.mod h1:Z6t4BnS23TR94PD6BsDNk8yVqroYurpAkEiz0P2BEV0= +github.com/prometheus/client_golang v1.21.1 h1:DOvXXTqVzvkIewV/CDPFdejpMCGeMcbGCQ8YOmu+Ibk= +github.com/prometheus/client_golang v1.21.1/go.mod h1:U9NM32ykUErtVBxdvD3zfi+EuFkkaBvMb09mIfe0Zgg= github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= github.com/prometheus/client_model v0.0.0-20190115171406-56726106282f/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= @@ -731,14 +750,16 @@ github.com/prometheus/common v0.7.0/go.mod h1:DjGbpBbp5NYNiECxcL/VnbXCCaQpKd3tt2 github.com/prometheus/common v0.9.1/go.mod h1:yhUN8i9wzaXS3w1O07YhxHEBxD+W35wd8bs7vj7HSQ4= github.com/prometheus/common v0.10.0/go.mod h1:Tlit/dnDKsSWFlCLTWaA1cyBgKHSMdTB80sz/V91rCo= github.com/prometheus/common v0.15.0/go.mod h1:U+gB1OBLb1lF3O42bTCL+FK18tX9Oar16Clt/msog/s= -github.com/prometheus/common v0.62.0 h1:xasJaQlnWAeyHdUBeGjXmutelfJHWMRr+Fg4QszZ2Io= -github.com/prometheus/common v0.62.0/go.mod h1:vyBcEuLSvWos9B1+CyL7JZ2up+uFzXhkqml0W5zIY1I= +github.com/prometheus/common v0.26.0/go.mod h1:M7rCNAaPfAosfx8veZJCuw84e35h3Cfd9VFqTh1DIvc= +github.com/prometheus/common v0.63.0 h1:YR/EIY1o3mEFP/kZCD7iDMnLPlGyuU2Gb3HIcXnA98k= +github.com/prometheus/common v0.63.0/go.mod h1:VVFF/fBIoToEnWRVkYoXEkq3R3paCoxG9PXP74SnV18= github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.0-20190117184657-bf6a532e95b1/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A= github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU= github.com/prometheus/procfs v0.3.0/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU= +github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA= github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc= github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk= github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= @@ -752,21 +773,19 @@ github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6So github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= -github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8= -github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4= +github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ= +github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc= github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU= github.com/rs/cors v1.11.1 h1:eU3gRzXLRK57F5rKMGMZURNdIG4EoAmX8k94r9wXWHA= github.com/rs/cors v1.11.1/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU= -github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= -github.com/rs/zerolog v1.33.0 h1:1cU2KZkvPxNyfgEmhHAz/1A9Bz+llsdYzklWFzgp0r8= -github.com/rs/zerolog v1.33.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss= +github.com/rs/xid v1.6.0/go.mod h1:7XoLgs4eV+QndskICGsho+ADou8ySMSjJKDIan90Nz0= +github.com/rs/zerolog v1.34.0 h1:k43nTLIwcTVQAncfCw4KZ2VY6ukYoZaBPNOE8txlOeY= +github.com/rs/zerolog v1.34.0/go.mod h1:bJsvje4Z08ROH4Nhs5iH600c3IkWhwp44iRc54W6wYQ= github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= -github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6keLGt6kNQ= -github.com/sagikazarmark/locafero v0.4.0/go.mod h1:Pe1W6UlPYUk/+wc/6KFhbORCfqzgYEpgQ3O5fPuL3H4= -github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6gto+ugjYE= -github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWRIczQRv+GVI1AkeQ= +github.com/sagikazarmark/locafero v0.7.0 h1:5MqpDsTGNDhY8sGp0Aowyf0qKsPrhewaLSsFaodPcyo= +github.com/sagikazarmark/locafero v0.7.0/go.mod h1:2za3Cg5rMaTMoG/2Ulr9AwtFaIppKXTRYnozin4aB5k= github.com/samuel/go-zookeeper v0.0.0-20190923202752-2cc03de413da/go.mod h1:gi+0XIa01GRL2eRQVjQkKGqKF3SF9vZR/HnPullcV2E= github.com/sasha-s/go-deadlock v0.3.5 h1:tNCOEEDG6tBqrNDOX35j/7hL5FcFViG6awUGROb2NsU= github.com/sasha-s/go-deadlock v0.3.5/go.mod h1:bugP6EGbdGYObIlx7pUZtWqlvo8k9H6vCBBsiChJQ5U= @@ -795,18 +814,19 @@ github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9yS github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0= github.com/sourcegraph/syntaxhighlight v0.0.0-20170531221838-bd320f5d308e h1:qpG93cPwA5f7s/ZPBJnGOYQNK/vKsaDaseuKT5Asee8= github.com/sourcegraph/syntaxhighlight v0.0.0-20170531221838-bd320f5d308e/go.mod h1:HuIsMU8RRBOtsCgI77wP899iHVBQpCmg4ErYMZB+2IA= -github.com/spf13/afero v1.11.0 h1:WJQKhtpdm3v2IzqG8VMqrr6Rf3UYpEF239Jy9wNepM8= -github.com/spf13/afero v1.11.0/go.mod h1:GH9Y3pIexgf1MTIWtNGyogA5MwRIDXGUr+hbWNoBjkY= +github.com/spf13/afero v1.12.0 h1:UcOPyRBYczmFn6yvphxkn9ZEOY65cpwGKb5mL36mrqs= +github.com/spf13/afero v1.12.0/go.mod h1:ZTlWwG4/ahT8W7T0WQ5uYmjI9duaLQGy3Q2OAl4sk/4= github.com/spf13/cast v1.7.1 h1:cuNEagBQEHWN1FnbGEjCXL2szYEXqfJPbP2HNUaca9Y= github.com/spf13/cast v1.7.1/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo= github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ= -github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM= -github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y= +github.com/spf13/cobra v1.9.1 h1:CXSaggrXdbHK9CF+8ywj8Amf7PBRmPCOJugH954Nnlo= +github.com/spf13/cobra v1.9.1/go.mod h1:nDyEzZ8ogv936Cinf6g1RU9MRY64Ir93oCnqb9wxYW0= github.com/spf13/pflag v1.0.1/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= -github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= -github.com/spf13/viper v1.19.0 h1:RWq5SEjt8o25SROyN3z2OrDB9l7RPd3lwTWU8EcEdcI= -github.com/spf13/viper v1.19.0/go.mod h1:GQUN9bilAbhU/jgc1bKs99f/suXKeUMct8Adx5+Ntkg= +github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o= +github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +github.com/spf13/viper v1.20.1 h1:ZMi+z/lvLyPSCoNtFCpqjy0S4kPbirhpTMwl8BkW9X4= +github.com/spf13/viper v1.20.1/go.mod h1:P9Mdzt1zoHIG8m2eZQinpiBjo6kCmZSKBClNNqjJvu4= github.com/streadway/amqp v0.0.0-20190404075320-75d898a42a94/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw= github.com/streadway/amqp v0.0.0-20190827072141-edfb9018d271/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw= github.com/streadway/handy v0.0.0-20190108123426-d5acb3125c2a/go.mod h1:qNTQ5P5JnDBl6z3cMAg/SywNDC5ABu5ApDIw6lUbRmI= @@ -827,7 +847,6 @@ github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1F github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8= @@ -840,6 +859,8 @@ github.com/tidwall/btree v1.7.0 h1:L1fkJH/AuEh5zBnnBbmTwQ5Lt+bRJ5A8EWecslvo9iI= github.com/tidwall/btree v1.7.0/go.mod h1:twD9XRA5jj9VUQGELzDO4HPQTNJsoWWfYEL+EUQ2cKY= github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM= +github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI= +github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08= github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo= github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw= github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY= @@ -852,7 +873,6 @@ github.com/xanzy/ssh-agent v0.3.3/go.mod h1:6dzNDKs0J9rVPHPhaGCukekBHKqfl+L3KghI github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= -github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= github.com/zondax/hid v0.9.2 h1:WCJFnEDMiqGF64nlZz28E9qLVZ0KSJ7xpc5DLEyma2U= github.com/zondax/hid v0.9.2/go.mod h1:l5wttcP0jwtdLjqjMMWFVEE7d1zO0jvSPA9OPZxWpEM= @@ -867,22 +887,26 @@ go.opencensus.io v0.20.2/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk= go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0= go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo= -go.opentelemetry.io/otel v1.32.0 h1:WnBN+Xjcteh0zdk01SVqV55d/m62NJLJdIyb4y/WO5U= -go.opentelemetry.io/otel v1.32.0/go.mod h1:00DCVSB0RQcnzlwyTfqtxSm+DRr9hpYrHjNGiBHVQIg= -go.opentelemetry.io/otel/metric v1.32.0 h1:xV2umtmNcThh2/a/aCP+h64Xx5wsj8qqnkYZktzNa0M= -go.opentelemetry.io/otel/metric v1.32.0/go.mod h1:jH7CIbbK6SH2V2wE16W05BHCtIDzauciCRLoc/SyMv8= -go.opentelemetry.io/otel/sdk v1.32.0 h1:RNxepc9vK59A8XsgZQouW8ue8Gkb4jpWtJm9ge5lEG4= -go.opentelemetry.io/otel/sdk v1.32.0/go.mod h1:LqgegDBjKMmb2GC6/PrTnteJG39I8/vJCAP9LlJXEjU= -go.opentelemetry.io/otel/sdk/metric v1.32.0 h1:rZvFnvmvawYb0alrYkjraqJq0Z4ZUJAiyYCU9snn1CU= -go.opentelemetry.io/otel/sdk/metric v1.32.0/go.mod h1:PWeZlq0zt9YkYAp3gjKZ0eicRYvOh1Gd+X99x6GHpCQ= -go.opentelemetry.io/otel/trace v1.32.0 h1:WIC9mYrXf8TmY/EXuULKc8hR17vE+Hjv2cssQDe03fM= -go.opentelemetry.io/otel/trace v1.32.0/go.mod h1:+i4rkvCraA+tG6AzwloGaCtkx53Fa+L+V8e9a7YvhT8= +go.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA= +go.opentelemetry.io/auto/sdk v1.1.0/go.mod h1:3wSPjt5PWp2RhlCcmmOial7AvC4DQqZb7a7wCow3W8A= +go.opentelemetry.io/otel v1.34.0 h1:zRLXxLCgL1WyKsPVrgbSdMN4c0FMkDAskSTQP+0hdUY= +go.opentelemetry.io/otel v1.34.0/go.mod h1:OWFPOQ+h4G8xpyjgqo4SxJYdDQ/qmRH+wivy7zzx9oI= +go.opentelemetry.io/otel/metric v1.34.0 h1:+eTR3U0MyfWjRDhmFMxe2SsW64QrZ84AOhvqS7Y+PoQ= +go.opentelemetry.io/otel/metric v1.34.0/go.mod h1:CEDrp0fy2D0MvkXE+dPV7cMi8tWZwX3dmaIhwPOaqHE= +go.opentelemetry.io/otel/sdk v1.34.0 h1:95zS4k/2GOy069d321O8jWgYsW3MzVV+KuSPKp7Wr1A= +go.opentelemetry.io/otel/sdk v1.34.0/go.mod h1:0e/pNiaMAqaykJGKbi+tSjWfNNHMTxoC9qANsCzbyxU= +go.opentelemetry.io/otel/sdk/metric v1.34.0 h1:5CeK9ujjbFVL5c1PhLuStg1wxA7vQv7ce1EK0Gyvahk= +go.opentelemetry.io/otel/sdk/metric v1.34.0/go.mod h1:jQ/r8Ze28zRKoNRdkjCZxfs6YvBTG1+YIqyFVFYec5w= +go.opentelemetry.io/otel/trace v1.34.0 h1:+ouXS2V8Rd4hp4580a8q23bg0azF2nI8cqLYnC8mh/k= +go.opentelemetry.io/otel/trace v1.34.0/go.mod h1:Svm7lSjQD7kG7KJ/MUHPVXSDGz2OX4h0M2jHBhmSfRE= go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI= go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/goleak v1.1.10/go.mod h1:8a7PlsEVH3e/a/GLqe5IIrQx6GzcnRmZEufDUTk4A7A= +go.uber.org/mock v0.5.0 h1:KAMbZvZPyBPWgD14IrIQ38QCyjwpvVVV6K/bHl1IwQU= +go.uber.org/mock v0.5.0/go.mod h1:ge71pBPLYDk7QIi1LupWxdAykm7KIEFchiOqd6z7qMM= go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= go.uber.org/multierr v1.3.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4= go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU= @@ -892,6 +916,8 @@ go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9E go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= go.uber.org/zap v1.13.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM= go.uber.org/zap v1.18.1/go.mod h1:xg/QME4nWcxGxrpdeYfq7UvYrLh66cuVKdrbD1XF/NI= +golang.org/x/arch v0.15.0 h1:QtOrQd0bTUnhNVNndMpLHNWrDmYzZ2KDqSrEymqInZw= +golang.org/x/arch v0.15.0/go.mod h1:JmwW7aLIoRUKgaTzhkiEFxvcEiQGyOg9BMonBJUS7EE= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= @@ -904,13 +930,13 @@ golang.org/x/crypto v0.0.0-20201012173705-84dcc777aaee/go.mod h1:LzIPMQfyMNhhGPh golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= -golang.org/x/crypto v0.32.0 h1:euUpcYgM8WcP71gNpTqQCn6rC2t6ULUPiOzfWaXVVfc= -golang.org/x/crypto v0.32.0/go.mod h1:ZnnJkOaASj8g0AjIduWNlq2NRxL0PlBrbKVyZ6V/Ugc= +golang.org/x/crypto v0.36.0 h1:AnAEvhDddvBdpY+uR+MyHmuZzzNqXSe/GvuDeob5L34= +golang.org/x/crypto v0.36.0/go.mod h1:Y4J0ReaxCR1IMaabaSMugxJES1EpwhBHhv2bDHklZvc= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20200331195152-e8c3332aa8e5/go.mod h1:4M0jN8W1tt0AVLNr8HDosyJCDCDuyL9N9+3m7wDWgKw= -golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 h1:2dVuKD2vS7b0QIHQbpyTISPd0LeHDbnYEryqj5Q1ug8= -golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56/go.mod h1:M4RDyNAINzryxdtnbRXRL/OHtkFuWGRjvuhBJpk2IlY= +golang.org/x/exp v0.0.0-20250305212735-054e65f0b394 h1:nDVHiLt8aIbd/VzvPWN6kSOPE7+F/fNFDSXLVYkE/Iw= +golang.org/x/exp v0.0.0-20250305212735-054e65f0b394/go.mod h1:sIifuuw/Yco/y6yb6+bDNfyeQ/MdPUy/hKEMYQV17cM= golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= @@ -924,10 +950,9 @@ golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzB golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= -golang.org/x/mod v0.20.0 h1:utOm6MM3R3dnawAiJgn0y+xvuYRsm1RKM/4giyfDgV0= -golang.org/x/mod v0.20.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= +golang.org/x/mod v0.24.0 h1:ZfthKaKaT4NrhGVZHO1/WDTwGES4De8KtWO0SIbNJMU= +golang.org/x/mod v0.24.0/go.mod h1:IXM97Txy2VM4PJ3gI61r1YEk/gAj6zAHN3AdZt6S9Ww= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -962,8 +987,8 @@ golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug golang.org/x/net v0.0.0-20220826154423-83b083e8dc8b/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk= golang.org/x/net v0.0.0-20221002022538-bcab6841153b/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk= golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= -golang.org/x/net v0.34.0 h1:Mb7Mrk043xzHgnRM88suvJFwzVrRfHEHJEl5/71CKw0= -golang.org/x/net v0.34.0/go.mod h1:di0qlW3YNM5oh6GqDGQr92MyTozJPmybPK4Ev/Gm31k= +golang.org/x/net v0.38.0 h1:vRMAPTMaeGqVhG5QyLJHqNDwecKTomGeqbnfZyKlBI8= +golang.org/x/net v0.38.0/go.mod h1:ivrbrMbzFq5J41QOQh0siUuly180yBYtLp+CKbEaFx8= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -974,12 +999,12 @@ golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220929204114-8fcdb60fdcc0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= -golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ= -golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.12.0 h1:MHc5BpPuC30uJk597Ri8TV3CNZcTLu6B6z4lJy+g6Jw= +golang.org/x/sync v0.12.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -1021,6 +1046,7 @@ golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= @@ -1041,14 +1067,14 @@ golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU= -golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik= +golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.0.0-20220722155259-a9ba230a4035/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= -golang.org/x/term v0.28.0 h1:/Ts8HFuMR2E6IP/jlo7QVLZHggjKQbhu/7H0LJFr3Gg= -golang.org/x/term v0.28.0/go.mod h1:Sw/lC2IAUZ92udQNf3WodGtn4k/XoLyZoh8v/8uiwek= +golang.org/x/term v0.30.0 h1:PQ39fJZ+mfadBm0y5WlL4vlM7Sx1Hgf13sMIY2+QS9Y= +golang.org/x/term v0.30.0/go.mod h1:NYYFdzHoI5wRh/h5tDMdMqCqPJZEuNqVR5xJLd/n67g= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= @@ -1056,8 +1082,8 @@ golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= -golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo= -golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ= +golang.org/x/text v0.23.0 h1:D71I7dUrlY+VX0gQShAThNGHFxZ13dGLBHQLVl1mJlY= +golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4= golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= @@ -1080,10 +1106,9 @@ golang.org/x/tools v0.0.0-20200207183749-b753a1ba74fa/go.mod h1:TB2adYChydJhpapK golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= -golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= -golang.org/x/tools v0.24.0 h1:J1shsA93PJUEVaUSaay7UXAyE8aimq3GW0pjlolpa24= -golang.org/x/tools v0.24.0/go.mod h1:YhNqVBIfWHdzvTLs0d8LCuMhkKUgSUKldakyV7W/WDQ= +golang.org/x/tools v0.31.0 h1:0EedkvKDbh+qistFTd0Bcwe/YLh4vHwWEkiI0toFIBU= +golang.org/x/tools v0.31.0/go.mod h1:naFTU+Cev749tSJRXJlna0T3WxKvb1kWEx15xA4SdmQ= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -1106,12 +1131,12 @@ google.golang.org/genproto v0.0.0-20200513103714-09dca8ec2884/go.mod h1:55QSHmfG google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= google.golang.org/genproto v0.0.0-20210126160654-44e461bb6506/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= google.golang.org/genproto v0.0.0-20220314164441-57ef72a4c106/go.mod h1:hAL49I2IFola2sVEjAn7MEwsja0xp51I0tlGAf9hz4E= -google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de h1:F6qOa9AZTYJXOUEr4jDysRDLrm4PHePlge4v4TGAlxY= -google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de/go.mod h1:VUhTRKeHn9wwcdrk73nvdC9gF178Tzhmt/qyaFcPLSo= -google.golang.org/genproto/googleapis/api v0.0.0-20241202173237-19429a94021a h1:OAiGFfOiA0v9MRYsSidp3ubZaBnteRUyn3xB2ZQ5G/E= -google.golang.org/genproto/googleapis/api v0.0.0-20241202173237-19429a94021a/go.mod h1:jehYqy3+AhJU9ve55aNOaSml7wUXjF9x6z2LcCfpAhY= -google.golang.org/genproto/googleapis/rpc v0.0.0-20241202173237-19429a94021a h1:hgh8P4EuoxpsuKMXX/To36nOFD7vixReXgn8lPGnt+o= -google.golang.org/genproto/googleapis/rpc v0.0.0-20241202173237-19429a94021a/go.mod h1:5uTbfoYQed2U9p3KIj2/Zzm02PYhndfdmML0qC3q3FU= +google.golang.org/genproto v0.0.0-20241118233622-e639e219e697 h1:ToEetK57OidYuqD4Q5w+vfEnPvPpuTwedCNVohYJfNk= +google.golang.org/genproto v0.0.0-20241118233622-e639e219e697/go.mod h1:JJrvXBWRZaFMxBufik1a4RpFw4HhgVtBBWQeQgUj2cc= +google.golang.org/genproto/googleapis/api v0.0.0-20250324211829-b45e905df463 h1:hE3bRWtU6uceqlh4fhrSnUyjKHMKB9KrTLLG+bc0ddM= +google.golang.org/genproto/googleapis/api v0.0.0-20250324211829-b45e905df463/go.mod h1:U90ffi8eUL9MwPcrJylN5+Mk2v3vuPDptd5yyNUiRR8= +google.golang.org/genproto/googleapis/rpc v0.0.0-20250324211829-b45e905df463 h1:e0AIkUUhxyBKh6ssZNrAMeqhA7RKUj42346d1y02i2g= +google.golang.org/genproto/googleapis/rpc v0.0.0-20250324211829-b45e905df463/go.mod h1:qQ0YXyHHx3XkvlzUtpXDkS29lDSafHMZBAZDc03LQ3A= google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.20.0/go.mod h1:chYK+tFQF0nDUGJgXMSgLCQk3phJEuONr2DCgLDdAQM= @@ -1130,8 +1155,8 @@ google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= google.golang.org/grpc v1.45.0/go.mod h1:lN7owxKUQEqMfSyQikvvk5tf/6zMPsrK+ONuO11+0rQ= google.golang.org/grpc v1.49.0/go.mod h1:ZgQEeidpAuNRZ8iRrlBKXZQP1ghovWIVhdJRyCDK+GI= -google.golang.org/grpc v1.70.0 h1:pWFv03aZoHzlRKHWicjsZytKAiYCtNS0dHbXnIdq7jQ= -google.golang.org/grpc v1.70.0/go.mod h1:ofIJqVKDXx/JiXrwr2IG4/zwdH9txy3IlF40RmcJSQw= +google.golang.org/grpc v1.71.1 h1:ffsFWr7ygTUscGPI0KKK6TLrGz0476KUvvsbqWK0rPI= +google.golang.org/grpc v1.71.1/go.mod h1:H0GRtasmQOh9LkFoCPDu3ZrwUtD1YGE+b2vYBYd/8Ec= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= @@ -1146,8 +1171,8 @@ google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp0 google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= -google.golang.org/protobuf v1.36.4 h1:6A3ZDJHn/eNqc1i+IdefRzy/9PokBTPvcqMySR7NNIM= -google.golang.org/protobuf v1.36.4/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= +google.golang.org/protobuf v1.36.6 h1:z1NpPI8ku2WgiWnf+t9wTPsn6eP1L7ksHUlkfLvd9xY= +google.golang.org/protobuf v1.36.6/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/5YcXBHnY= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= @@ -1159,8 +1184,6 @@ gopkg.in/cheggaaa/pb.v1 v1.0.25/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qS gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= gopkg.in/gcfg.v1 v1.2.3/go.mod h1:yesOnuUOFQAhST5vPY4nbZsb/huCgGGXlipJsBn0b3o= -gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA= -gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= @@ -1181,16 +1204,17 @@ gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gotest.tools/v3 v3.5.1 h1:EENdUnS3pdur5nybKYIh2Vfgc8IUNBjxDPSjtiJcOzU= -gotest.tools/v3 v3.5.1/go.mod h1:isy3WKz7GK6uNw/sbHzfKBLvlvXwUyV06n6brMxxopU= +gotest.tools/v3 v3.5.2 h1:7koQfIKdy+I8UTetycgUqXWSDwpgv193Ka+qRsmBY8Q= +gotest.tools/v3 v3.5.2/go.mod h1:LtdLGcnqToBH83WByAAi/wiwSFCArdFIUV/xxN4pcjA= honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= nhooyr.io/websocket v1.8.6 h1:s+C3xAMLwGmlI31Nyn/eAehUlZPwfYZu2JXM621Q5/k= nhooyr.io/websocket v1.8.6/go.mod h1:B70DZP8IakI65RVQ51MsWP/8jndNma26DVA/nFSCgW0= -pgregory.net/rapid v1.1.0 h1:CMa0sjHSru3puNx+J0MIAuiiEV4N0qj8/cMWGBBCsjw= -pgregory.net/rapid v1.1.0/go.mod h1:PY5XlDGj0+V1FCq0o192FdRhpKHGTRIWBgqjDBTrq04= +nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50= +pgregory.net/rapid v1.2.0 h1:keKAYRcjm+e1F0oAuU5F5+YPAWcyxNNRK2wud503Gnk= +pgregory.net/rapid v1.2.0/go.mod h1:PY5XlDGj0+V1FCq0o192FdRhpKHGTRIWBgqjDBTrq04= sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o= sigs.k8s.io/yaml v1.4.0 h1:Mk1wCc2gy/F0THH0TAp1QYyJNzRm2KCLy3o5ASXVI5E= sigs.k8s.io/yaml v1.4.0/go.mod h1:Ejl7/uTz7PSA4eKMyQCUTnhZYNmLIl+5c2lQPGR2BPY= diff --git a/connect/internal/ATTRIBUTIONS.md b/connect/internal/ATTRIBUTIONS.md deleted file mode 100644 index 162f62d2..00000000 --- a/connect/internal/ATTRIBUTIONS.md +++ /dev/null @@ -1,7 +0,0 @@ -# Attributions - -This package is a fork of [client/v2](https://github.com/cosmos/cosmos-sdk/tree/client/v2.10.0-beta.3/client/v2) at the v2.10.0-beta.3 tag. - -Any modifications made to the original code are subject to [Ignite CLI's license](../../LICENSE). - -The aim of the fork is to incorporate the latest changes from client/v2 that were previously dropped and to make client/v2 more Ignite Connect-focused. diff --git a/connect/internal/account/retriever.go b/connect/internal/account/retriever.go deleted file mode 100644 index 2cef69f9..00000000 --- a/connect/internal/account/retriever.go +++ /dev/null @@ -1,116 +0,0 @@ -package account - -import ( - "context" - "fmt" - "strconv" - - gogogrpc "github.com/cosmos/gogoproto/grpc" - "google.golang.org/grpc" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/metadata" - "google.golang.org/grpc/status" - - "cosmossdk.io/core/address" - - codectypes "github.com/cosmos/cosmos-sdk/codec/types" - cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" - sdk "github.com/cosmos/cosmos-sdk/types" - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" -) - -// GRPCBlockHeightHeader represents the gRPC header for block height. -const GRPCBlockHeightHeader = "x-cosmos-block-height" - -var _ AccountRetriever = accountRetriever{} - -// Account provides a read-only abstraction over the auth module's AccountI. -type Account interface { - GetAddress() sdk.AccAddress - GetPubKey() cryptotypes.PubKey // can return nil. - GetAccountNumber() uint64 - GetSequence() uint64 -} - -// AccountRetriever defines methods required to retrieve account details necessary for transaction signing. -type AccountRetriever interface { - GetAccount(context.Context, []byte) (Account, error) - GetAccountWithHeight(context.Context, []byte) (Account, int64, error) - EnsureExists(context.Context, []byte) error - GetAccountNumberSequence(context.Context, []byte) (accNum, accSeq uint64, err error) -} - -type accountRetriever struct { - ac address.Codec - conn gogogrpc.ClientConn - registry codectypes.InterfaceRegistry -} - -// NewAccountRetriever creates a new instance of accountRetriever. -func NewAccountRetriever(ac address.Codec, conn gogogrpc.ClientConn, registry codectypes.InterfaceRegistry) *accountRetriever { - return &accountRetriever{ - ac: ac, - conn: conn, - registry: registry, - } -} - -// GetAccount retrieves an account using its address. -func (a accountRetriever) GetAccount(ctx context.Context, addr []byte) (Account, error) { - acc, _, err := a.GetAccountWithHeight(ctx, addr) - return acc, err -} - -// GetAccountWithHeight retrieves an account and its associated block height using the account's address. -func (a accountRetriever) GetAccountWithHeight(ctx context.Context, addr []byte) (Account, int64, error) { - var header metadata.MD - qc := authtypes.NewQueryClient(a.conn) - - addrStr, err := a.ac.BytesToString(addr) - if err != nil { - return nil, 0, err - } - - res, err := qc.Account(ctx, &authtypes.QueryAccountRequest{Address: addrStr}, grpc.Header(&header)) - if err != nil { - return nil, 0, err - } - - blockHeight := header.Get(GRPCBlockHeightHeader) - if len(blockHeight) != 1 { - return nil, 0, fmt.Errorf("unexpected '%s' header length; got %d, expected 1", GRPCBlockHeightHeader, len(blockHeight)) - } - - nBlockHeight, err := strconv.Atoi(blockHeight[0]) - if err != nil { - return nil, 0, fmt.Errorf("failed to parse block height: %w", err) - } - - var acc Account - if err := a.registry.UnpackAny(res.Account, &acc); err != nil { - return nil, 0, err - } - - return acc, int64(nBlockHeight), nil -} - -// EnsureExists checks if an account exists using its address. -func (a accountRetriever) EnsureExists(ctx context.Context, addr []byte) error { - if _, err := a.GetAccount(ctx, addr); err != nil { - return err - } - return nil -} - -// GetAccountNumberSequence retrieves the account number and sequence for an account using its address. -func (a accountRetriever) GetAccountNumberSequence(ctx context.Context, addr []byte) (accNum, accSeq uint64, err error) { - acc, err := a.GetAccount(ctx, addr) - if err != nil { - if status.Code(err) == codes.NotFound { - return 0, 0, nil - } - return 0, 0, err - } - - return acc.GetAccountNumber(), acc.GetSequence(), nil -} diff --git a/connect/internal/autocli/app.go b/connect/internal/autocli/app.go deleted file mode 100644 index 040bebba..00000000 --- a/connect/internal/autocli/app.go +++ /dev/null @@ -1,63 +0,0 @@ -package autocli - -import ( - "errors" - - "github.com/ignite/apps/connect/chains" - "github.com/ignite/apps/connect/internal/autocli/flag" - "github.com/spf13/cobra" - "google.golang.org/grpc" - - autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" -) - -// Builder manages options for building CLI commands. -type Builder struct { - // flag.Builder embeds the flag builder and its options. - flag.Builder - - // Config is the config of the chain from the connect app - Config *chains.ChainConfig - - // GetClientConn specifies how CLI commands will resolve a grpc.ClientConnInterface - // from a given context. - GetClientConn func(*cobra.Command) (grpc.ClientConnInterface, error) - - // AddQueryConnFlags adds flags to query commands - AddQueryConnFlags func(*cobra.Command) - - // AddTxConnFlags adds flags to transaction commands - AddTxConnFlags func(*cobra.Command) -} - -// EnhanceRootCommand enhances the root command with the provided module options. -// -// ModuleOptions are autocli options to be used for modules. They are gotten from -// the reflection service. -func EnhanceRootCommand( - rootCmd *cobra.Command, - builder *Builder, - moduleOptions map[string]*autocliv1.ModuleOptions, -) error { - if builder.Config == nil { - return errors.New("missing config") - } - - if err := builder.Validate(); err != nil { - return err - } - - queryCmd, err := builder.BuildQueryCommand(rootCmd.Context(), moduleOptions) - if err != nil { - return err - } - - msgCmd, err := builder.BuildMsgCommand(rootCmd.Context(), moduleOptions) - if err != nil { - return err - } - - rootCmd.AddCommand(queryCmd, msgCmd) - - return nil -} diff --git a/connect/internal/autocli/common.go b/connect/internal/autocli/common.go deleted file mode 100644 index 195bcad3..00000000 --- a/connect/internal/autocli/common.go +++ /dev/null @@ -1,286 +0,0 @@ -package autocli - -import ( - "fmt" - - "github.com/cosmos/cosmos-sdk/codec" - codectypes "github.com/cosmos/cosmos-sdk/codec/types" - "github.com/cosmos/gogoproto/proto" - "github.com/spf13/cobra" - "google.golang.org/protobuf/reflect/protoreflect" - - autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" - "cosmossdk.io/x/tx/signing" - "github.com/ignite/apps/connect/internal/autocli/keyring" - "github.com/ignite/apps/connect/internal/flags" - "github.com/ignite/apps/connect/internal/print" - "github.com/ignite/apps/connect/internal/tx" - "github.com/ignite/apps/connect/internal/util" -) - -type cmdType int - -const ( - queryCmdType cmdType = iota - msgCmdType -) - -func (b *Builder) buildMethodCommandCommon(descriptor protoreflect.MethodDescriptor, options *autocliv1.RpcCommandOptions, exec func(cmd *cobra.Command, input protoreflect.Message) error) (*cobra.Command, error) { - if options == nil { - // use the defaults - options = &autocliv1.RpcCommandOptions{} - } - - short := options.Short - if short == "" { - short = fmt.Sprintf("Execute the %s RPC method", descriptor.Name()) - } - - inputDesc := descriptor.Input() - inputType := util.ResolveMessageType(b.TypeResolver, inputDesc) - - use := options.Use - if use == "" { - use = protoNameToCliName(descriptor.Name()) - } - - cmd := &cobra.Command{ - SilenceUsage: false, - Use: use, - Long: options.Long, - Short: short, - Example: options.Example, - Aliases: options.Alias, - SuggestFor: options.SuggestFor, - Deprecated: options.Deprecated, - Version: options.Version, - } - - // we need to use a pointer to the context as the correct context is set in the RunE function - // however we need to set the flags before the RunE function is called - ctx := cmd.Context() - binder, err := b.AddMessageFlags(&ctx, cmd.Flags(), inputType, options) - if err != nil { - return nil, err - } - cmd.Args = binder.CobraArgs - - cmd.PreRunE = b.preRunE() - - cmd.RunE = func(cmd *cobra.Command, args []string) error { - // create context - k, err := keyring.NewKeyring(cmd.Flags(), b.AddressCodec, b.Config.Bech32Prefix) - if err != nil { - return err - } - - mergedFiles, err := proto.MergedRegistry() - if err != nil { - return err - } - - ir, err := codectypes.NewInterfaceRegistryWithOptions(codectypes.InterfaceRegistryOptions{ - ProtoFiles: mergedFiles, - SigningOptions: signing.Options{ - AddressCodec: b.AddressCodec, - ValidatorAddressCodec: b.ValidatorAddressCodec, - }, - }) - if err != nil { - return err - } - - cmd.SetContext(tx.SetContext(cmd.Context(), tx.Context{ - Cdc: codec.NewProtoCodec(ir), - Flags: cmd.Flags(), - Keyring: k, - AddressCodec: b.AddressCodec, - ValidatorAddressCodec: b.ValidatorAddressCodec, - ConsensusAddressCodec: b.ConsensusAddressCodec, - })) - - input, err := binder.BuildMessage(args) - if err != nil { - return err - } - - // signer related logic, triggers only when there is a signer defined - if binder.SignerInfo.FieldName != "" { - if binder.SignerInfo.IsFlag { - // the client context uses the from flag to determine the signer. - // this sets the signer flags to the from flag value if a custom signer flag is set. - // marks the custom flag as required. - if binder.SignerInfo.FlagName != flags.FlagFrom { - if err := cmd.MarkFlagRequired(binder.SignerInfo.FlagName); err != nil { - return err - } - - if err := cmd.Flags().Set(flags.FlagFrom, cmd.Flag(binder.SignerInfo.FlagName).Value.String()); err != nil { - return err - } - } - } else { - // if the signer is not a flag, it is a positional argument - // we need to get the correct positional arguments - if err := cmd.Flags().Set(flags.FlagFrom, args[binder.SignerInfo.PositionalArgIndex]); err != nil { - return err - } - } - } - - return exec(cmd, input) - } - - return cmd, nil -} - -// enhanceCommandCommon enhances the provided query or msg command with either generated commands based on the provided module -// options or the provided custom commands for each module. If the provided query command already contains a command -// for a module, that command is not over-written by this method. This allows a graceful addition of autocli to -// automatically fill in missing commands. -func (b *Builder) enhanceCommandCommon( - cmd *cobra.Command, - cmdType cmdType, - moduleOptions map[string]*autocliv1.ModuleOptions, -) error { - if len(moduleOptions) == 0 { - moduleOptions = make(map[string]*autocliv1.ModuleOptions) - } - - for moduleName, modOpts := range moduleOptions { - hasModuleOptions := modOpts != nil - - // if we have an existing command skip adding one here - if subCmd := findSubCommand(cmd, moduleName); subCmd != nil { - if hasModuleOptions { // check if we need to enhance the existing command - if err := enhanceCustomCmd(b, subCmd, cmdType, modOpts); err != nil { - return err - } - } - - continue - } - - // if we don't have module options, skip adding a command as we don't have anything to add - if !hasModuleOptions { - continue - } - - switch cmdType { - case queryCmdType: - if err := enhanceQuery(b, moduleName, cmd, modOpts); err != nil { - return err - } - case msgCmdType: - if err := enhanceMsg(b, moduleName, cmd, modOpts); err != nil { - return err - } - } - } - - return nil -} - -// enhanceQuery enhances the provided query command with the autocli commands for a module. -func enhanceQuery(builder *Builder, moduleName string, cmd *cobra.Command, modOpts *autocliv1.ModuleOptions) error { - if queryCmdDesc := modOpts.Query; queryCmdDesc != nil { - short := queryCmdDesc.Short - if short == "" { - short = fmt.Sprintf("Querying commands for the %s module", moduleName) - } - subCmd := topLevelCmd(cmd.Context(), moduleName, short) - if err := builder.AddQueryServiceCommands(subCmd, queryCmdDesc); err != nil { - return err - } - - cmd.AddCommand(subCmd) - } - - return nil -} - -// enhanceMsg enhances the provided msg command with the autocli commands for a module. -func enhanceMsg(builder *Builder, moduleName string, cmd *cobra.Command, modOpts *autocliv1.ModuleOptions) error { - if txCmdDesc := modOpts.Tx; txCmdDesc != nil { - short := txCmdDesc.Short - if short == "" { - short = fmt.Sprintf("Transactions commands for the %s module", moduleName) - } - subCmd := topLevelCmd(cmd.Context(), moduleName, short) - if err := builder.AddMsgServiceCommands(subCmd, txCmdDesc); err != nil { - return err - } - - cmd.AddCommand(subCmd) - } - - return nil -} - -// enhanceCustomCmd enhances the provided custom query or msg command autocli commands for a module. -func enhanceCustomCmd(builder *Builder, cmd *cobra.Command, cmdType cmdType, modOpts *autocliv1.ModuleOptions) error { - switch cmdType { - case queryCmdType: - if modOpts.Query != nil && modOpts.Query.EnhanceCustomCommand { - if err := builder.AddQueryServiceCommands(cmd, modOpts.Query); err != nil { - return err - } - } - case msgCmdType: - if modOpts.Tx != nil && modOpts.Tx.EnhanceCustomCommand { - if err := builder.AddMsgServiceCommands(cmd, modOpts.Tx); err != nil { - return err - } - } - } - - return nil -} - -// outOrStdoutFormat formats the output based on the output flag and writes it to the command's output stream. -func (b *Builder) outOrStdoutFormat(cmd *cobra.Command, out []byte) error { - p, err := print.NewPrinter(cmd) - if err != nil { - return err - } - return p.PrintBytes(out) -} - -// preRunE returns a function that sets flags from the configuration before running a command. -// It is used as a PreRunE hook for cobra commands to ensure flags are properly initialized -// from the configuration before command execution. -func (b *Builder) preRunE() func(cmd *cobra.Command, args []string) error { - return func(cmd *cobra.Command, args []string) error { - err := b.setFlagsFromConfig(cmd) - if err != nil { - return err - } - - return nil - } -} - -// setFlagsFromConfig sets command flags from the provided configuration. -// It only sets flags that haven't been explicitly changed by the user. -func (b *Builder) setFlagsFromConfig(cmd *cobra.Command) error { - flagsToSet := map[string]string{ - flags.FlagChainID: b.Config.ChainID, - // flags.FlagKeyringBackend: conf.KeyringBackend, - // flags.FlagFrom: conf.KeyringDefaultKeyName, - // flags.FlagOutput: conf.Output, - // flags.FlagNode: conf.Node, - // flags.FlagBroadcastMode: conf.BroadcastMode, - // flags.FlagGrpcAddress: conf.GRPC.Address, - // flags.FlagGrpcInsecure: strconv.FormatBool(conf.GRPC.Insecure), - } - - for flagName, value := range flagsToSet { - if flag := cmd.Flags().Lookup(flagName); flag != nil && !cmd.Flags().Changed(flagName) { - if err := cmd.Flags().Set(flagName, value); err != nil { - return err - } - } - } - - return nil -} diff --git a/connect/internal/autocli/common_test.go b/connect/internal/autocli/common_test.go deleted file mode 100644 index b355754e..00000000 --- a/connect/internal/autocli/common_test.go +++ /dev/null @@ -1,200 +0,0 @@ -package autocli - -import ( - "bytes" - "context" - "net" - "testing" - - "github.com/spf13/cobra" - "google.golang.org/grpc" - "google.golang.org/grpc/credentials/insecure" - "google.golang.org/protobuf/reflect/protoregistry" - "gotest.tools/v3/assert" - - autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" - reflectionv2alpha1 "cosmossdk.io/api/cosmos/base/reflection/v2alpha1" - "github.com/ignite/apps/connect/chains" - "github.com/ignite/apps/connect/internal/autocli/flag" - "github.com/ignite/apps/connect/internal/testpb" - - "github.com/cosmos/cosmos-sdk/client/flags" - addresscodec "github.com/cosmos/cosmos-sdk/codec/address" - sdkkeyring "github.com/cosmos/cosmos-sdk/crypto/keyring" - moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" - "github.com/cosmos/cosmos-sdk/x/bank" - banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" -) - -type fixture struct { - conn *testClientConn - b *Builder - - home string - chainID string - kBackend string -} - -func initFixture(t *testing.T) *fixture { - t.Helper() - home := t.TempDir() - server := grpc.NewServer() - testpb.RegisterQueryServer(server, &testEchoServer{}) - reflectionv2alpha1.RegisterReflectionServiceServer(server, &testReflectionServer{}) - listener, err := net.Listen("tcp", "127.0.0.1:0") - assert.NilError(t, err) - go func() { - err := server.Serve(listener) - if err != nil { - panic(err) - } - }() - - clientConn, err := grpc.NewClient(listener.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials())) - assert.NilError(t, err) - - encodingConfig := moduletestutil.MakeTestEncodingConfig(bank.AppModule{}) - interfaceRegistry := encodingConfig.Codec.InterfaceRegistry() - banktypes.RegisterInterfaces(interfaceRegistry) - - conn := &testClientConn{ClientConn: clientConn} - b := &Builder{ - Builder: flag.Builder{ - TypeResolver: protoregistry.GlobalTypes, - FileResolver: protoregistry.GlobalFiles, - AddressCodec: interfaceRegistry.SigningContext().AddressCodec(), - ValidatorAddressCodec: interfaceRegistry.SigningContext().ValidatorAddressCodec(), - ConsensusAddressCodec: addresscodec.NewBech32Codec("cosmosvalcons"), - }, - GetClientConn: func(*cobra.Command) (grpc.ClientConnInterface, error) { - return conn, nil - }, - AddQueryConnFlags: flags.AddQueryFlagsToCmd, - AddTxConnFlags: addTxAndGlobalFlagsToCmd, - Config: &chains.ChainConfig{}, - } - assert.NilError(t, b.Validate()) - - return &fixture{ - conn: conn, - b: b, - home: home, - chainID: "autocli-test", - kBackend: sdkkeyring.BackendMemory, - } -} - -func addTxAndGlobalFlagsToCmd(cmd *cobra.Command) { - f := cmd.Flags() - f.String("home", "", "home directory") - flags.AddTxFlagsToCmd(cmd) -} - -func runCmd(fixture *fixture, command func(moduleName string, f *fixture) (*cobra.Command, error), args ...string) (*bytes.Buffer, error) { - out := &bytes.Buffer{} - cmd, err := command("test", fixture) - if err != nil { - return out, err - } - - cmd.SetArgs(args) - cmd.SetOut(out) - return out, cmd.Execute() -} - -type testReflectionServer struct { - reflectionv2alpha1.UnimplementedReflectionServiceServer -} - -func (t testReflectionServer) GetConfigurationDescriptor(_ context.Context, client *reflectionv2alpha1.GetConfigurationDescriptorRequest) (*reflectionv2alpha1.GetConfigurationDescriptorResponse, error) { - return &reflectionv2alpha1.GetConfigurationDescriptorResponse{ - Config: &reflectionv2alpha1.ConfigurationDescriptor{ - Bech32AccountAddressPrefix: "cosmos", - }, - }, nil -} - -var _ reflectionv2alpha1.ReflectionServiceServer = testReflectionServer{} - -type testClientConn struct { - *grpc.ClientConn - lastRequest interface{} - lastResponse interface{} -} - -func (t *testClientConn) Invoke(ctx context.Context, method string, args, reply interface{}, opts ...grpc.CallOption) error { - err := t.ClientConn.Invoke(ctx, method, args, reply, opts...) - t.lastRequest = args - t.lastResponse = reply - return err -} - -type testEchoServer struct { - testpb.UnimplementedQueryServer -} - -func (t testEchoServer) Echo(_ context.Context, request *testpb.EchoRequest) (*testpb.EchoResponse, error) { - return &testpb.EchoResponse{Request: request}, nil -} - -var _ testpb.QueryServer = testEchoServer{} - -func TestEnhanceCommand(t *testing.T) { - b := &Builder{} - // Test that the command has a subcommand - cmd := &cobra.Command{Use: "test"} - cmd.AddCommand(&cobra.Command{Use: "test"}) - - for i := 0; i < 2; i++ { - cmdTp := cmdType(i) - - moduleOptions := map[string]*autocliv1.ModuleOptions{ - "test": {}, - } - err := b.enhanceCommandCommon(cmd, cmdTp, moduleOptions) - assert.NilError(t, err) - - cmd = &cobra.Command{Use: "test"} - moduleOptions = map[string]*autocliv1.ModuleOptions{ - "test": {Tx: nil}, - } - err = b.enhanceCommandCommon(cmd, cmdTp, moduleOptions) - assert.NilError(t, err) - } -} - -func TestErrorBuildCommand(t *testing.T) { - fixture := initFixture(t) - b := fixture.b - b.AddQueryConnFlags = nil - b.AddTxConnFlags = nil - - commandDescriptor := &autocliv1.ServiceCommandDescriptor{ - Service: testpb.Msg_ServiceDesc.ServiceName, - RpcCommandOptions: []*autocliv1.RpcCommandOptions{ - { - RpcMethod: "Send", - PositionalArgs: []*autocliv1.PositionalArgDescriptor{ - { - ProtoField: "un-existent-proto-field", - }, - }, - }, - }, - } - - moduleOptions := map[string]*autocliv1.ModuleOptions{ - "test": { - Query: commandDescriptor, - Tx: commandDescriptor, - }, - } - - _, err := b.BuildMsgCommand(context.Background(), moduleOptions) - assert.ErrorContains(t, err, "can't find field un-existent-proto-field") - - moduleOptions["test"].Tx = &autocliv1.ServiceCommandDescriptor{Service: "un-existent-service"} - moduleOptions["test"].Query = &autocliv1.ServiceCommandDescriptor{Service: "un-existent-service"} - _, err = b.BuildMsgCommand(context.Background(), moduleOptions) - assert.ErrorContains(t, err, "can't find service un-existent-service") -} diff --git a/connect/internal/autocli/flag/address.go b/connect/internal/autocli/flag/address.go deleted file mode 100644 index 0133c4c7..00000000 --- a/connect/internal/autocli/flag/address.go +++ /dev/null @@ -1,162 +0,0 @@ -package flag - -import ( - "context" - "fmt" - - "google.golang.org/protobuf/reflect/protoreflect" - - "cosmossdk.io/core/address" - "github.com/ignite/apps/connect/internal/autocli/keyring" - "github.com/ignite/apps/connect/internal/tx" - - "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/codec/types" - cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" - cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" -) - -type addressStringType struct{} - -func (a addressStringType) NewValue(ctx *context.Context, b *Builder) Value { - return &addressValue{addressCodec: b.AddressCodec, ctx: ctx} -} - -func (a addressStringType) DefaultValue() string { - return "" -} - -type validatorAddressStringType struct{} - -func (a validatorAddressStringType) NewValue(ctx *context.Context, b *Builder) Value { - return &addressValue{addressCodec: b.ValidatorAddressCodec, ctx: ctx} -} - -func (a validatorAddressStringType) DefaultValue() string { - return "" -} - -type addressValue struct { - ctx *context.Context - addressCodec address.Codec - - value string -} - -func (a *addressValue) Get(protoreflect.Value) (protoreflect.Value, error) { - return protoreflect.ValueOfString(a.value), nil -} - -func (a *addressValue) String() string { - return a.value -} - -// Set implements the flag.Value interface for addressValue. -func (a *addressValue) Set(s string) error { - // we get the keyring on set, as in NewValue the context is the parent context (before RunE) - k := getKeyringFromCtx(a.ctx) - addr, err := k.LookupAddressByKeyName(s) - if err == nil { - addrStr, err := a.addressCodec.BytesToString(addr) - if err != nil { - return fmt.Errorf("invalid account address got from keyring: %w", err) - } - - a.value = addrStr - return nil - } - - _, err = a.addressCodec.StringToBytes(s) - if err != nil { - return fmt.Errorf("invalid account address or key name: %w", err) - } - - a.value = s - - return nil -} - -func (a *addressValue) Type() string { - return "account address or key name" -} - -type consensusAddressStringType struct{} - -func (a consensusAddressStringType) NewValue(ctx *context.Context, b *Builder) Value { - return &consensusAddressValue{ - addressValue: addressValue{ - addressCodec: b.ConsensusAddressCodec, - ctx: ctx, - }, - } -} - -func (a consensusAddressStringType) DefaultValue() string { - return "" -} - -type consensusAddressValue struct { - addressValue -} - -func (a consensusAddressValue) Get(protoreflect.Value) (protoreflect.Value, error) { - return protoreflect.ValueOfString(a.value), nil -} - -func (a consensusAddressValue) String() string { - return a.value -} - -func (a *consensusAddressValue) Set(s string) error { - // we get the keyring on set, as in NewValue the context is the parent context (before RunE) - k := getKeyringFromCtx(a.ctx) - addr, err := k.LookupAddressByKeyName(s) - if err == nil { - addrStr, err := a.addressCodec.BytesToString(addr) - if err != nil { - return fmt.Errorf("invalid consensus address got from keyring: %w", err) - } - - a.value = addrStr - return nil - } - - _, err = a.addressCodec.StringToBytes(s) - if err == nil { - a.value = s - return nil - } - - // fallback to pubkey parsing - registry := types.NewInterfaceRegistry() - cryptocodec.RegisterInterfaces(registry) - cdc := codec.NewProtoCodec(registry) - - var pk cryptotypes.PubKey - err2 := cdc.UnmarshalInterfaceJSON([]byte(s), &pk) - if err2 != nil { - return fmt.Errorf("input isn't a pubkey (%w) or is an invalid account address (%w)", err, err2) - } - - a.value, err = a.addressCodec.BytesToString(pk.Address()) - if err != nil { - return fmt.Errorf("invalid pubkey address: %w", err) - } - - return nil -} - -// getKeyringFromCtx retrieves the keyring from the provided context. -// If the context is nil or does not contain a valid client context, -// it returns a no-op keyring implementation. -func getKeyringFromCtx(ctx *context.Context) keyring.Keyring { - if *ctx == nil { - return keyring.NoKeyring{} - } - - if txCtx, err := tx.GetContext(*ctx); err == nil { - return txCtx.Keyring - } - - return keyring.NoKeyring{} -} diff --git a/connect/internal/autocli/flag/binary.go b/connect/internal/autocli/flag/binary.go deleted file mode 100644 index 5567d5f8..00000000 --- a/connect/internal/autocli/flag/binary.go +++ /dev/null @@ -1,63 +0,0 @@ -package flag - -import ( - "context" - "encoding/base64" - "encoding/hex" - "errors" - "os" - - "google.golang.org/protobuf/reflect/protoreflect" -) - -type binaryType struct{} - -var _ Value = (*fileBinaryValue)(nil) - -func (f binaryType) NewValue(*context.Context, *Builder) Value { - return &fileBinaryValue{} -} - -func (f binaryType) DefaultValue() string { - return "" -} - -// fileBinaryValue is a Value that holds a binary file. -type fileBinaryValue struct { - value []byte -} - -func (f *fileBinaryValue) Get(protoreflect.Value) (protoreflect.Value, error) { - return protoreflect.ValueOfBytes(f.value), nil -} - -func (f *fileBinaryValue) String() string { - return string(f.value) -} - -// Set implements the flag.Value interface for binary files, with exceptions. -// If the input string is a valid file path, the value will be the content of that file. -// If the input string is a valid hex or base64 string, the value will be the decoded form of that string. -// If the input string is not a valid file path, hex string, or base64 string, Set will return an error. -func (f *fileBinaryValue) Set(s string) error { - if data, err := os.ReadFile(s); err == nil { - f.value = data - return nil - } - - if data, err := hex.DecodeString(s); err == nil { - f.value = data - return nil - } - - if data, err := base64.StdEncoding.DecodeString(s); err == nil { - f.value = data - return nil - } - - return errors.New("input string is neither a valid file path, hex, or base64 encoded") -} - -func (f *fileBinaryValue) Type() string { - return "binary" -} diff --git a/connect/internal/autocli/flag/builder.go b/connect/internal/autocli/flag/builder.go deleted file mode 100644 index 3004d204..00000000 --- a/connect/internal/autocli/flag/builder.go +++ /dev/null @@ -1,510 +0,0 @@ -package flag - -import ( - "context" - "errors" - "fmt" - "strconv" - "strings" - - cosmos_proto "github.com/cosmos/cosmos-proto" - "github.com/spf13/cobra" - "github.com/spf13/pflag" - "google.golang.org/protobuf/proto" - "google.golang.org/protobuf/reflect/protodesc" - "google.golang.org/protobuf/reflect/protoreflect" - "google.golang.org/protobuf/reflect/protoregistry" - - autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" - msgv1 "cosmossdk.io/api/cosmos/msg/v1" - "cosmossdk.io/core/address" - "github.com/ignite/apps/connect/internal/flags" - "github.com/ignite/apps/connect/internal/util" -) - -const ( - AddressStringScalarType = "cosmos.AddressString" - ValidatorAddressStringScalarType = "cosmos.ValidatorAddressString" - ConsensusAddressStringScalarType = "cosmos.ConsensusAddressString" - PubkeyScalarType = "cosmos.Pubkey" - DecScalarType = "cosmos.Dec" -) - -// Builder manages options for building pflag flags for protobuf messages. -type Builder struct { - // TypeResolver specifies how protobuf types will be resolved. If it is - // nil protoregistry.GlobalTypes will be used. - TypeResolver interface { - protoregistry.MessageTypeResolver - protoregistry.ExtensionTypeResolver - } - - // FileResolver specifies how protobuf file descriptors will be resolved. If it is - // nil protoregistry.GlobalFiles will be used. - FileResolver interface { - protodesc.Resolver - RangeFiles(func(protoreflect.FileDescriptor) bool) - } - - messageFlagTypes map[protoreflect.FullName]Type - scalarFlagTypes map[string]Type - - // Address Codecs are the address codecs to use for client/v2. - AddressCodec address.Codec - ValidatorAddressCodec address.Codec - ConsensusAddressCodec address.Codec -} - -func (b *Builder) init() { - if b.messageFlagTypes == nil { - b.messageFlagTypes = map[protoreflect.FullName]Type{} - b.messageFlagTypes["google.protobuf.Timestamp"] = timestampType{} - b.messageFlagTypes["google.protobuf.Duration"] = durationType{} - b.messageFlagTypes["cosmos.base.v1beta1.Coin"] = coinType{} - b.messageFlagTypes["cosmos.base.v1beta1.DecCoin"] = decCoinType{} - } - - if b.scalarFlagTypes == nil { - b.scalarFlagTypes = map[string]Type{} - b.scalarFlagTypes[AddressStringScalarType] = addressStringType{} - b.scalarFlagTypes[ValidatorAddressStringScalarType] = validatorAddressStringType{} - b.scalarFlagTypes[ConsensusAddressStringScalarType] = consensusAddressStringType{} - b.scalarFlagTypes[PubkeyScalarType] = pubkeyType{} - b.scalarFlagTypes[DecScalarType] = decType{} - } -} - -// Validate the flag builder fields. -// It returns an error if any of the required fields are missing. -func (b *Builder) Validate() error { - if b.AddressCodec == nil { - return errors.New("address codec is required in flag builder") - } - - if b.ValidatorAddressCodec == nil { - return errors.New("validator address codec is required in flag builder") - } - - if b.ConsensusAddressCodec == nil { - return errors.New("consensus address codec is required in flag builder") - } - - if b.TypeResolver == nil { - return errors.New("type resolver is required in flag builder") - } - - if b.FileResolver == nil { - return errors.New("file resolver is required in flag builder") - } - - return nil -} - -// DefineMessageFlagType allows to extend custom protobuf message type handling for flags (and positional arguments). -func (b *Builder) DefineMessageFlagType(messageName protoreflect.FullName, flagType Type) { - b.init() - b.messageFlagTypes[messageName] = flagType -} - -// DefineScalarFlagType allows to extend custom scalar type handling for flags (and positional arguments). -func (b *Builder) DefineScalarFlagType(scalarName string, flagType Type) { - b.init() - b.scalarFlagTypes[scalarName] = flagType -} - -// AddMessageFlags adds flags for each field in the message to the flag set. -func (b *Builder) AddMessageFlags(ctx *context.Context, flagSet *pflag.FlagSet, messageType protoreflect.MessageType, commandOptions *autocliv1.RpcCommandOptions) (*MessageBinder, error) { - return b.addMessageFlags(ctx, flagSet, messageType, commandOptions, namingOptions{}) -} - -// addMessageFlags adds flags for each field in the message to the flag set. -func (b *Builder) addMessageFlags(ctx *context.Context, flagSet *pflag.FlagSet, messageType protoreflect.MessageType, commandOptions *autocliv1.RpcCommandOptions, options namingOptions) (*MessageBinder, error) { - messageBinder := &MessageBinder{ - messageType: messageType, - // positional args are also parsed using a FlagSet so that we can reuse all the same parsers - positionalFlagSet: pflag.NewFlagSet("positional", pflag.ContinueOnError), - } - - fields := messageType.Descriptor().Fields() - signerFieldName := GetSignerFieldName(messageType.Descriptor()) - - isPositional := map[string]bool{} - - positionalArgsLen := len(commandOptions.PositionalArgs) - for i, arg := range commandOptions.PositionalArgs { - isPositional[arg.ProtoField] = true - - // verify if a positional field is a signer field - if arg.ProtoField == signerFieldName { - messageBinder.SignerInfo = SignerInfo{ - PositionalArgIndex: i, - FieldName: arg.ProtoField, - } - } - - if arg.Optional && arg.Varargs { - return nil, fmt.Errorf("positional argument %s can't be both optional and varargs", arg.ProtoField) - } - - if arg.Varargs { - if i != positionalArgsLen-1 { - return nil, fmt.Errorf("varargs positional argument %s must be the last argument", arg.ProtoField) - } - - messageBinder.hasVarargs = true - } - - if arg.Optional { - if i != positionalArgsLen-1 { - return nil, fmt.Errorf("optional positional argument %s must be the last argument", arg.ProtoField) - } - - messageBinder.hasOptional = true - } - - s := strings.Split(arg.ProtoField, ".") - if len(s) == 1 { - f, err := b.addFieldBindingToArgs(ctx, messageBinder, protoreflect.Name(arg.ProtoField), fields) - if err != nil { - return nil, err - } - messageBinder.positionalArgs = append(messageBinder.positionalArgs, f) - } else { - err := b.addFlattenFieldBindingToArgs(ctx, arg.ProtoField, s, messageType, messageBinder) - if err != nil { - return nil, err - } - } - } - - totalArgs := len(messageBinder.positionalArgs) - switch { - case messageBinder.hasVarargs: - messageBinder.CobraArgs = cobra.MinimumNArgs(totalArgs - 1) - messageBinder.mandatoryArgUntil = totalArgs - 1 - case messageBinder.hasOptional: - messageBinder.CobraArgs = cobra.RangeArgs(totalArgs-1, totalArgs) - messageBinder.mandatoryArgUntil = totalArgs - 1 - default: - messageBinder.CobraArgs = cobra.ExactArgs(totalArgs) - messageBinder.mandatoryArgUntil = totalArgs - } - - // validate flag options - for name, opts := range commandOptions.FlagOptions { - if fields.ByName(protoreflect.Name(name)) == nil { - return nil, fmt.Errorf("can't find field %s on %s specified as a flag", name, messageType.Descriptor().FullName()) - } - - // verify if a flag is a signer field - if name == signerFieldName { - messageBinder.SignerInfo = SignerInfo{ - FieldName: name, - IsFlag: true, - FlagName: opts.Name, - } - } - } - - // if signer has not been specified as positional arguments, - // add it as `--from` flag (instead of --field-name flags) - if signerFieldName != "" && messageBinder.SignerInfo == (SignerInfo{}) { - if commandOptions.FlagOptions == nil { - commandOptions.FlagOptions = make(map[string]*autocliv1.FlagOptions) - } - - commandOptions.FlagOptions[signerFieldName] = &autocliv1.FlagOptions{ - Name: flags.FlagFrom, - Usage: "Name or address with which to sign the message", - Shorthand: "f", - } - - messageBinder.SignerInfo = SignerInfo{ - FieldName: signerFieldName, - IsFlag: true, - FlagName: flags.FlagFrom, - } - } - - // define all other fields as flags - flagOptsByFlagName := map[string]*autocliv1.FlagOptions{} - for i := 0; i < fields.Len(); i++ { - field := fields.Get(i) - fieldName := string(field.Name()) - - // skips positional args and signer field if already set - if isPositional[fieldName] || - (fieldName == signerFieldName && messageBinder.SignerInfo.FlagName == flags.FlagFrom) { - continue - } - - flagOpts := commandOptions.FlagOptions[fieldName] - name, hasValue, err := b.addFieldFlag(ctx, flagSet, field, flagOpts, options) - if err != nil { - return nil, err - } - flagOptsByFlagName[name] = flagOpts - - messageBinder.flagBindings = append(messageBinder.flagBindings, fieldBinding{ - hasValue: hasValue, - field: field, - }) - } - - flagSet.VisitAll(func(flag *pflag.Flag) { - opts := flagOptsByFlagName[flag.Name] - if opts != nil { - // This is a bit of hacking around the pflag API, but - // we need to set these options here using Flag.VisitAll because the flag - // constructors that pflag gives us (StringP, Int32P, etc.) do not - // actually return the *Flag instance - flag.Deprecated = opts.Deprecated - flag.ShorthandDeprecated = opts.ShorthandDeprecated - flag.Hidden = opts.Hidden - } - }) - - return messageBinder, nil -} - -// addFlattenFieldBindingToArgs recursively adds field bindings for nested message fields to the message binder. -// It takes a slice of field names representing the path to the target field, where each element is a field name -// in the nested message structure. For example, ["foo", "bar", "baz"] would bind the "baz" field inside the "bar" -// message which is inside the "foo" message. -func (b *Builder) addFlattenFieldBindingToArgs(ctx *context.Context, path string, s []string, msg protoreflect.MessageType, messageBinder *MessageBinder) error { - fields := msg.Descriptor().Fields() - if len(s) == 1 { - f, err := b.addFieldBindingToArgs(ctx, messageBinder, protoreflect.Name(s[0]), fields) - if err != nil { - return err - } - f.path = path - messageBinder.positionalArgs = append(messageBinder.positionalArgs, f) - return nil - } - fd := fields.ByName(protoreflect.Name(s[0])) - var innerMsg protoreflect.MessageType - if fd.IsList() { - innerMsg = msg.New().Get(fd).List().NewElement().Message().Type() - } else { - innerMsg = msg.New().Get(fd).Message().Type() - } - return b.addFlattenFieldBindingToArgs(ctx, path, s[1:], innerMsg, messageBinder) -} - -// addFieldBindingToArgs adds a fieldBinding for a positional argument to the message binder. -// The fieldBinding is appended to the positional arguments list in the message binder. -func (b *Builder) addFieldBindingToArgs(ctx *context.Context, messageBinder *MessageBinder, name protoreflect.Name, fields protoreflect.FieldDescriptors) (fieldBinding, error) { - field := fields.ByName(name) - if field == nil { - return fieldBinding{}, fmt.Errorf("can't find field %s", name) // TODO: it will improve error if msg.FullName() was included.` - } - - _, hasValue, err := b.addFieldFlag( - ctx, - messageBinder.positionalFlagSet, - field, - &autocliv1.FlagOptions{Name: fmt.Sprintf("%d", len(messageBinder.positionalArgs))}, - namingOptions{}, - ) - if err != nil { - return fieldBinding{}, err - } - - return fieldBinding{ - field: field, - hasValue: hasValue, - }, nil -} - -// bindPageRequest create a flag for pagination -func (b *Builder) bindPageRequest(ctx *context.Context, flagSet *pflag.FlagSet, field protoreflect.FieldDescriptor) (HasValue, error) { - return b.addMessageFlags( - ctx, - flagSet, - util.ResolveMessageType(b.TypeResolver, field.Message()), - &autocliv1.RpcCommandOptions{}, - namingOptions{Prefix: "page-"}, - ) -} - -// namingOptions specifies internal naming options for flags. -type namingOptions struct { - // Prefix is a prefix to prepend to all flags. - Prefix string -} - -// addFieldFlag adds a flag for the provided field to the flag set. -func (b *Builder) addFieldFlag(ctx *context.Context, flagSet *pflag.FlagSet, field protoreflect.FieldDescriptor, opts *autocliv1.FlagOptions, options namingOptions) (name string, hasValue HasValue, err error) { - if opts == nil { - opts = &autocliv1.FlagOptions{} - } - - if field.Kind() == protoreflect.MessageKind && field.Message().FullName() == "cosmos.base.query.v1beta1.PageRequest" { - hasValue, err := b.bindPageRequest(ctx, flagSet, field) - return "", hasValue, err - } - - name = opts.Name - if name == "" { - name = options.Prefix + util.DescriptorKebabName(field) - } - - usage := opts.Usage - shorthand := opts.Shorthand - defaultValue := opts.DefaultValue - - if typ := b.resolveFlagType(field); typ != nil { - if defaultValue == "" { - defaultValue = typ.DefaultValue() - } - - val := typ.NewValue(ctx, b) - flagSet.AddFlag(&pflag.Flag{ - Name: name, - Shorthand: shorthand, - Usage: usage, - DefValue: defaultValue, - Value: val, - }) - return name, val, nil - } - - // use the built-in pflag StringP, Int32P, etc. functions - var val HasValue - - if field.IsList() { - val = bindSimpleListFlag(flagSet, field.Kind(), name, shorthand, usage) - } else if field.IsMap() { - keyKind := field.MapKey().Kind() - valKind := field.MapValue().Kind() - val = bindSimpleMapFlag(flagSet, keyKind, valKind, name, shorthand, usage) - } else { - val = bindSimpleFlag(flagSet, field.Kind(), name, shorthand, usage) - } - - // This is a bit of hacking around the pflag API, but the - // defaultValue is set in this way because this is much easier than trying - // to parse the string into the types that StringSliceP, Int32P, etc. - if defaultValue != "" { - err = flagSet.Set(name, defaultValue) - } - - return name, val, err -} - -func (b *Builder) resolveFlagType(field protoreflect.FieldDescriptor) Type { - typ := b.resolveFlagTypeBasic(field) - if field.IsList() { - if typ != nil { - return compositeListType{simpleType: typ} - } - return nil - } - if field.IsMap() { - keyKind := field.MapKey().Kind() - valType := b.resolveFlagType(field.MapValue()) - if valType != nil { - switch keyKind { - case protoreflect.StringKind: - ct := new(compositeMapType[string]) - ct.keyValueResolver = func(s string) (string, error) { return s, nil } - ct.valueType = valType - ct.keyType = "string" - return ct - case protoreflect.Int32Kind, protoreflect.Sint32Kind, protoreflect.Sfixed32Kind: - ct := new(compositeMapType[int32]) - ct.keyValueResolver = func(s string) (int32, error) { - i, err := strconv.ParseInt(s, 10, 32) - return int32(i), err - } - ct.valueType = valType - ct.keyType = "int32" - return ct - case protoreflect.Int64Kind, protoreflect.Sint64Kind, protoreflect.Sfixed64Kind: - ct := new(compositeMapType[int64]) - ct.keyValueResolver = func(s string) (int64, error) { - i, err := strconv.ParseInt(s, 10, 64) - return i, err - } - ct.valueType = valType - ct.keyType = "int64" - return ct - case protoreflect.Uint32Kind, protoreflect.Fixed32Kind: - ct := new(compositeMapType[uint32]) - ct.keyValueResolver = func(s string) (uint32, error) { - i, err := strconv.ParseUint(s, 10, 32) - return uint32(i), err - } - ct.valueType = valType - ct.keyType = "uint32" - return ct - case protoreflect.Uint64Kind, protoreflect.Fixed64Kind: - ct := new(compositeMapType[uint64]) - ct.keyValueResolver = func(s string) (uint64, error) { - i, err := strconv.ParseUint(s, 10, 64) - return i, err - } - ct.valueType = valType - ct.keyType = "uint64" - return ct - case protoreflect.BoolKind: - ct := new(compositeMapType[bool]) - ct.keyValueResolver = strconv.ParseBool - ct.valueType = valType - ct.keyType = "bool" - return ct - } - return nil - - } - return nil - } - - return typ -} - -func (b *Builder) resolveFlagTypeBasic(field protoreflect.FieldDescriptor) Type { - scalar, ok := GetScalarType(field) - if ok { - b.init() - if typ, ok := b.scalarFlagTypes[scalar]; ok { - return typ - } - } - - switch field.Kind() { - case protoreflect.BytesKind: - return binaryType{} - case protoreflect.EnumKind: - return enumType{enum: field.Enum()} - case protoreflect.MessageKind: - b.init() - if flagType, ok := b.messageFlagTypes[field.Message().FullName()]; ok { - return flagType - } - return jsonMessageFlagType{ - messageDesc: field.Message(), - } - default: - return nil - } -} - -// GetScalarType gets scalar type of a field. -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. -func GetSignerFieldName(descriptor protoreflect.MessageDescriptor) string { - signersFields := proto.GetExtension(descriptor.Options(), msgv1.E_Signer).([]string) - if len(signersFields) == 0 { - return "" - } - - return signersFields[0] -} diff --git a/connect/internal/autocli/flag/coin.go b/connect/internal/autocli/flag/coin.go deleted file mode 100644 index 8db9c3f9..00000000 --- a/connect/internal/autocli/flag/coin.go +++ /dev/null @@ -1,58 +0,0 @@ -package flag - -import ( - "context" - "errors" - "strings" - - "google.golang.org/protobuf/reflect/protoreflect" - - basev1beta1 "cosmossdk.io/api/cosmos/base/v1beta1" - "github.com/ignite/apps/connect/internal/coins" -) - -type coinType struct{} - -type coinValue struct { - value *basev1beta1.Coin -} - -func (c coinType) NewValue(*context.Context, *Builder) Value { - return &coinValue{} -} - -func (c coinType) DefaultValue() string { - return "zero" -} - -func (c *coinValue) Get(protoreflect.Value) (protoreflect.Value, error) { - if c.value == nil { - return protoreflect.Value{}, nil - } - return protoreflect.ValueOfMessage(c.value.ProtoReflect()), nil -} - -func (c *coinValue) String() string { - if c.value == nil { - return "" - } - - return c.value.String() -} - -func (c *coinValue) Set(stringValue string) error { - if strings.Contains(stringValue, ",") { - return errors.New("coin flag must be a single coin, specific multiple coins with multiple flags or spaces") - } - - coin, err := coins.ParseCoin(stringValue) - if err != nil { - return err - } - c.value = coin - return nil -} - -func (c *coinValue) Type() string { - return "cosmos.base.v1beta1.Coin" -} diff --git a/connect/internal/autocli/flag/dec_coin.go b/connect/internal/autocli/flag/dec_coin.go deleted file mode 100644 index 8ed1b566..00000000 --- a/connect/internal/autocli/flag/dec_coin.go +++ /dev/null @@ -1,58 +0,0 @@ -package flag - -import ( - "context" - "errors" - "strings" - - "google.golang.org/protobuf/reflect/protoreflect" - - basev1beta1 "cosmossdk.io/api/cosmos/base/v1beta1" - "github.com/ignite/apps/connect/internal/coins" -) - -type decCoinType struct{} - -type decCoinValue struct { - value *basev1beta1.DecCoin -} - -func (c decCoinType) NewValue(*context.Context, *Builder) Value { - return &decCoinValue{} -} - -func (c decCoinType) DefaultValue() string { - return "zero" -} - -func (c *decCoinValue) Get(protoreflect.Value) (protoreflect.Value, error) { - if c.value == nil { - return protoreflect.Value{}, nil - } - return protoreflect.ValueOfMessage(c.value.ProtoReflect()), nil -} - -func (c *decCoinValue) String() string { - if c.value == nil { - return "" - } - - return c.value.String() -} - -func (c *decCoinValue) Set(stringValue string) error { - if strings.Contains(stringValue, ",") { - return errors.New("coin flag must be a single coin, specific multiple coins with multiple flags or spaces") - } - - coin, err := coins.ParseDecCoin(stringValue) - if err != nil { - return err - } - c.value = coin - return nil -} - -func (c *decCoinValue) Type() string { - return "cosmos.base.v1beta1.DecCoin" -} diff --git a/connect/internal/autocli/flag/doc.go b/connect/internal/autocli/flag/doc.go deleted file mode 100644 index 5e8a1f36..00000000 --- a/connect/internal/autocli/flag/doc.go +++ /dev/null @@ -1,4 +0,0 @@ -// Package flag defines functionality for automatically managing command -// line flags as well positional arguments that are based on protobuf message -// fields. -package flag diff --git a/connect/internal/autocli/flag/duration.go b/connect/internal/autocli/flag/duration.go deleted file mode 100644 index df02cba7..00000000 --- a/connect/internal/autocli/flag/duration.go +++ /dev/null @@ -1,51 +0,0 @@ -package flag - -import ( - "context" - "time" - - "google.golang.org/protobuf/reflect/protoreflect" - "google.golang.org/protobuf/types/known/durationpb" -) - -type durationType struct{} - -func (d durationType) NewValue(*context.Context, *Builder) Value { - return &durationValue{} -} - -func (d durationType) DefaultValue() string { - return "" -} - -type durationValue struct { - value *durationpb.Duration -} - -func (d durationValue) Get(protoreflect.Value) (protoreflect.Value, error) { - if d.value == nil { - return protoreflect.Value{}, nil - } - return protoreflect.ValueOfMessage(d.value.ProtoReflect()), nil -} - -func (d durationValue) String() string { - if d.value == nil { - return "" - } - return d.value.AsDuration().String() -} - -func (d *durationValue) Set(s string) error { - dur, err := time.ParseDuration(s) - if err != nil { - return err - } - - d.value = durationpb.New(dur) - return nil -} - -func (d durationValue) Type() string { - return "duration" -} diff --git a/connect/internal/autocli/flag/enum.go b/connect/internal/autocli/flag/enum.go deleted file mode 100644 index 15017b1f..00000000 --- a/connect/internal/autocli/flag/enum.go +++ /dev/null @@ -1,79 +0,0 @@ -package flag - -import ( - "context" - "fmt" - "strings" - - "google.golang.org/protobuf/reflect/protoreflect" - - "github.com/ignite/apps/connect/internal/strcase" -) - -type enumType struct { - enum protoreflect.EnumDescriptor -} - -func (b enumType) NewValue(*context.Context, *Builder) Value { - val := &enumValue{ - enum: b.enum, - valMap: map[string]protoreflect.EnumValueDescriptor{}, - } - n := b.enum.Values().Len() - for i := 0; i < n; i++ { - valDesc := b.enum.Values().Get(i) - val.valMap[enumValueName(b.enum, valDesc)] = valDesc - } - return val -} - -func (b enumType) DefaultValue() string { - defValue := "" - if def := b.enum.Values().ByNumber(0); def != nil { - defValue = enumValueName(b.enum, def) - } - return defValue -} - -type enumValue struct { - enum protoreflect.EnumDescriptor - value protoreflect.EnumNumber - valMap map[string]protoreflect.EnumValueDescriptor -} - -func (e enumValue) Get(protoreflect.Value) (protoreflect.Value, error) { - return protoreflect.ValueOfEnum(e.value), nil -} - -func enumValueName(enum protoreflect.EnumDescriptor, enumValue protoreflect.EnumValueDescriptor) string { - name := string(enumValue.Name()) - name = strings.TrimPrefix(name, strcase.ToScreamingSnake(string(enum.Name()))+"_") - return strcase.ToKebab(name) -} - -func (e enumValue) String() string { - return enumValueName(e.enum, e.enum.Values().ByNumber(e.value)) -} - -func (e *enumValue) Set(s string) error { - valDesc, ok := e.valMap[s] - if !ok { - var validValues []string - for k := range e.valMap { - validValues = append(validValues, k) - } - - return fmt.Errorf("%s is not a valid value for enum %s. Valid values are: %s", s, e.enum.FullName(), strings.Join(validValues, ", ")) - } - e.value = valDesc.Number() - return nil -} - -func (e enumValue) Type() string { - var vals []string - n := e.enum.Values().Len() - for i := 0; i < n; i++ { - vals = append(vals, enumValueName(e.enum, e.enum.Values().Get(i))) - } - return fmt.Sprintf("%s (%s)", e.enum.Name(), strings.Join(vals, " | ")) -} diff --git a/connect/internal/autocli/flag/interface.go b/connect/internal/autocli/flag/interface.go deleted file mode 100644 index 1d983c09..00000000 --- a/connect/internal/autocli/flag/interface.go +++ /dev/null @@ -1,32 +0,0 @@ -package flag - -import ( - "context" - - "github.com/spf13/pflag" - "google.golang.org/protobuf/reflect/protoreflect" -) - -// Type specifies a custom flag type. -type Type interface { - // NewValue returns a new pflag.Value which must also implement either SimpleValue or ListValue. - NewValue(*context.Context, *Builder) Value - - // DefaultValue is the default value for this type. - DefaultValue() string -} - -// Value represents a single pflag.Value value. -type Value interface { - pflag.Value - HasValue -} - -// HasValue wraps a reference to a protobuf value. -type HasValue interface { - // Get gets the value of the protobuf value reference and returns that value - // or an error. For composite protoreflect.Value types such as messages, - // lists and maps, a mutable reference to the value of field obtained with - // protoreflect.Message.NewField should be passed as the newFieldValue parameter. - Get(newFieldValue protoreflect.Value) (protoreflect.Value, error) -} diff --git a/connect/internal/autocli/flag/json_message.go b/connect/internal/autocli/flag/json_message.go deleted file mode 100644 index 426dafb7..00000000 --- a/connect/internal/autocli/flag/json_message.go +++ /dev/null @@ -1,86 +0,0 @@ -package flag - -import ( - "context" - "fmt" - "io" - "os" - "regexp" - - "google.golang.org/protobuf/encoding/protojson" - "google.golang.org/protobuf/proto" - "google.golang.org/protobuf/reflect/protoreflect" - - "github.com/ignite/apps/connect/internal/util" -) - -var isJSONFileRegex = regexp.MustCompile(`\.json$`) - -type jsonMessageFlagType struct { - messageDesc protoreflect.MessageDescriptor -} - -func (j jsonMessageFlagType) NewValue(_ *context.Context, builder *Builder) Value { - return &jsonMessageFlagValue{ - messageType: util.ResolveMessageType(builder.TypeResolver, j.messageDesc), - jsonMarshalOptions: protojson.MarshalOptions{Resolver: builder.TypeResolver}, - jsonUnmarshalOptions: protojson.UnmarshalOptions{Resolver: builder.TypeResolver}, - } -} - -func (j jsonMessageFlagType) DefaultValue() string { - return "" -} - -type jsonMessageFlagValue struct { - jsonMarshalOptions protojson.MarshalOptions - jsonUnmarshalOptions protojson.UnmarshalOptions - messageType protoreflect.MessageType - message proto.Message -} - -func (j *jsonMessageFlagValue) Get(protoreflect.Value) (protoreflect.Value, error) { - if j.message == nil { - return protoreflect.Value{}, nil - } - return protoreflect.ValueOfMessage(j.message.ProtoReflect()), nil -} - -func (j *jsonMessageFlagValue) String() string { - if j.message == nil { - return "" - } - - bz, err := j.jsonMarshalOptions.Marshal(j.message) - if err != nil { - return err.Error() - } - return string(bz) -} - -func (j *jsonMessageFlagValue) Set(s string) error { - j.message = j.messageType.New().Interface() - var messageBytes []byte - if isJSONFileRegex.MatchString(s) { - jsonFile, err := os.Open(s) - if err != nil { - return err - } - messageBytes, err = io.ReadAll(jsonFile) - if err != nil { - _ = jsonFile.Close() - return err - } - err = jsonFile.Close() - if err != nil { - return err - } - } else { - messageBytes = []byte(s) - } - return j.jsonUnmarshalOptions.Unmarshal(messageBytes, j.message) -} - -func (j *jsonMessageFlagValue) Type() string { - return fmt.Sprintf("%s (json)", j.messageType.Descriptor().FullName()) -} diff --git a/connect/internal/autocli/flag/legacy_dec.go b/connect/internal/autocli/flag/legacy_dec.go deleted file mode 100644 index 073afa94..00000000 --- a/connect/internal/autocli/flag/legacy_dec.go +++ /dev/null @@ -1,48 +0,0 @@ -package flag - -import ( - "context" - - "google.golang.org/protobuf/reflect/protoreflect" - - "cosmossdk.io/math" -) - -type decType struct{} - -func (a decType) NewValue(_ *context.Context, _ *Builder) Value { - return &decValue{} -} - -func (a decType) DefaultValue() string { - return "0" -} - -type decValue struct { - value string -} - -func (a decValue) Get(protoreflect.Value) (protoreflect.Value, error) { - return protoreflect.ValueOf(a.value), nil -} - -func (a decValue) String() string { - return a.value -} - -func (a *decValue) Set(s string) error { - dec, err := math.LegacyNewDecFromStr(s) - if err != nil { - return err - } - - // we need to convert from float representation to non-float representation using default precision - // 0.5 -> 500000000000000000 - a.value = dec.BigInt().String() - - return nil -} - -func (a decValue) Type() string { - return "cosmos.Dec" -} diff --git a/connect/internal/autocli/flag/list.go b/connect/internal/autocli/flag/list.go deleted file mode 100644 index d30f2992..00000000 --- a/connect/internal/autocli/flag/list.go +++ /dev/null @@ -1,107 +0,0 @@ -package flag - -import ( - "context" - "fmt" - - "github.com/spf13/pflag" - "google.golang.org/protobuf/reflect/protoreflect" -) - -func bindSimpleListFlag(flagSet *pflag.FlagSet, kind protoreflect.Kind, name, shorthand, usage string) HasValue { - switch kind { - case protoreflect.StringKind: - val := flagSet.StringSliceP(name, shorthand, nil, usage) - return newListValue(val, protoreflect.ValueOfString) - case protoreflect.Uint32Kind, protoreflect.Fixed32Kind, - protoreflect.Uint64Kind, protoreflect.Fixed64Kind: - val := flagSet.UintSliceP(name, shorthand, nil, usage) - return newListValue(val, func(x uint) protoreflect.Value { return protoreflect.ValueOfUint64(uint64(x)) }) - case protoreflect.Int32Kind, protoreflect.Sint32Kind, protoreflect.Sfixed32Kind: - val := flagSet.Int32SliceP(name, shorthand, nil, usage) - return newListValue(val, protoreflect.ValueOfInt32) - case protoreflect.Int64Kind, protoreflect.Sint64Kind, protoreflect.Sfixed64Kind: - val := flagSet.Int64SliceP(name, shorthand, nil, usage) - return newListValue(val, protoreflect.ValueOfInt64) - case protoreflect.BoolKind: - val := flagSet.BoolSliceP(name, shorthand, nil, usage) - return newListValue(val, protoreflect.ValueOfBool) - default: - return nil - } -} - -type listValue[T any] struct { - array *[]T - toProtoreflectValue func(T) protoreflect.Value -} - -func newListValue[T any](array *[]T, toProtoreflectValue func(T) protoreflect.Value) listValue[T] { - return listValue[T]{array: array, toProtoreflectValue: toProtoreflectValue} -} - -func (v listValue[T]) Get(mutable protoreflect.Value) (protoreflect.Value, error) { - list := mutable.List() - for _, x := range *v.array { - list.Append(v.toProtoreflectValue(x)) - } - return mutable, nil -} - -type compositeListType struct { - simpleType Type -} - -func (t compositeListType) NewValue(ctx *context.Context, opts *Builder) Value { - return &compositeListValue{ - simpleType: t.simpleType, - values: nil, - ctx: ctx, - opts: opts, - } -} - -func (t compositeListType) DefaultValue() string { - return "" -} - -type compositeListValue struct { - simpleType Type - values []protoreflect.Value - ctx *context.Context - opts *Builder -} - -func (c *compositeListValue) Get(mutable protoreflect.Value) (protoreflect.Value, error) { - list := mutable.List() - for _, value := range c.values { - list.Append(value) - } - return mutable, nil -} - -func (c *compositeListValue) String() string { - if len(c.values) == 0 { - return "" - } - - return fmt.Sprintf("%+v", c.values) -} - -func (c *compositeListValue) Set(val string) error { - simpleVal := c.simpleType.NewValue(c.ctx, c.opts) - err := simpleVal.Set(val) - if err != nil { - return err - } - v, err := simpleVal.Get(protoreflect.Value{}) - if err != nil { - return err - } - c.values = append(c.values, v) - return nil -} - -func (c *compositeListValue) Type() string { - return fmt.Sprintf("%s (repeated)", c.simpleType.NewValue(c.ctx, c.opts).Type()) -} diff --git a/connect/internal/autocli/flag/map.go b/connect/internal/autocli/flag/map.go deleted file mode 100644 index 0c0e136f..00000000 --- a/connect/internal/autocli/flag/map.go +++ /dev/null @@ -1,254 +0,0 @@ -package flag - -import ( - "context" - "errors" - "fmt" - "strings" - - "github.com/spf13/pflag" - "google.golang.org/protobuf/reflect/protoreflect" - - "github.com/ignite/apps/connect/internal/autocli/flag/maps" -) - -func bindSimpleMapFlag(flagSet *pflag.FlagSet, keyKind, valueKind protoreflect.Kind, name, shorthand, usage string) HasValue { - switch keyKind { - case protoreflect.StringKind: - switch valueKind { - case protoreflect.StringKind: - val := flagSet.StringToStringP(name, shorthand, nil, usage) - return newMapValue(val, protoreflect.ValueOfString) - case protoreflect.Int32Kind, protoreflect.Sint32Kind, protoreflect.Sfixed32Kind: - val := maps.StringToInt32P(flagSet, name, shorthand, nil, usage) - return newMapValue(val, protoreflect.ValueOfInt32) - case protoreflect.Int64Kind, protoreflect.Sint64Kind, protoreflect.Sfixed64Kind: - val := flagSet.StringToInt64P(name, shorthand, nil, usage) - return newMapValue(val, protoreflect.ValueOfInt64) - case protoreflect.Uint32Kind: - val := maps.StringToUint32P(flagSet, name, shorthand, nil, usage) - return newMapValue(val, protoreflect.ValueOfUint32) - case protoreflect.Uint64Kind: - val := maps.StringToUint64P(flagSet, name, shorthand, nil, usage) - return newMapValue(val, protoreflect.ValueOfUint64) - case protoreflect.BoolKind: - val := maps.StringToBoolP(flagSet, name, shorthand, nil, usage) - return newMapValue(val, protoreflect.ValueOfBool) - } - - case protoreflect.Int32Kind, protoreflect.Sint32Kind, protoreflect.Sfixed32Kind: - switch valueKind { - case protoreflect.StringKind: - val := maps.Int32ToStringP(flagSet, name, shorthand, nil, usage) - return newMapValue(val, protoreflect.ValueOfString) - case protoreflect.Int32Kind, protoreflect.Sint32Kind, protoreflect.Sfixed32Kind: - val := maps.Int32ToInt32P(flagSet, name, shorthand, nil, usage) - return newMapValue(val, protoreflect.ValueOfInt32) - case protoreflect.Int64Kind, protoreflect.Sint64Kind, protoreflect.Sfixed64Kind: - val := maps.Int32ToInt64P(flagSet, name, shorthand, nil, usage) - return newMapValue(val, protoreflect.ValueOfInt64) - case protoreflect.Uint32Kind: - val := maps.Int32ToUint32P(flagSet, name, shorthand, nil, usage) - return newMapValue(val, protoreflect.ValueOfUint32) - case protoreflect.Uint64Kind: - val := maps.Int32ToUint64P(flagSet, name, shorthand, nil, usage) - return newMapValue(val, protoreflect.ValueOfUint64) - case protoreflect.BoolKind: - val := maps.Int32ToBoolP(flagSet, name, shorthand, nil, usage) - return newMapValue(val, protoreflect.ValueOfBool) - } - - case protoreflect.Int64Kind, protoreflect.Sint64Kind, protoreflect.Sfixed64Kind: - switch valueKind { - case protoreflect.StringKind: - val := maps.Int64ToStringP(flagSet, name, shorthand, nil, usage) - return newMapValue(val, protoreflect.ValueOfString) - case protoreflect.Int32Kind, protoreflect.Sint32Kind, protoreflect.Sfixed32Kind: - val := maps.Int64ToInt32P(flagSet, name, shorthand, nil, usage) - return newMapValue(val, protoreflect.ValueOfInt32) - case protoreflect.Int64Kind, protoreflect.Sint64Kind, protoreflect.Sfixed64Kind: - val := maps.Int64ToInt64P(flagSet, name, shorthand, nil, usage) - return newMapValue(val, protoreflect.ValueOfInt64) - case protoreflect.Uint32Kind: - val := maps.Int64ToUint32P(flagSet, name, shorthand, nil, usage) - return newMapValue(val, protoreflect.ValueOfUint32) - case protoreflect.Uint64Kind: - val := maps.Int64ToUint64P(flagSet, name, shorthand, nil, usage) - return newMapValue(val, protoreflect.ValueOfUint64) - case protoreflect.BoolKind: - val := maps.Int64ToBoolP(flagSet, name, shorthand, nil, usage) - return newMapValue(val, protoreflect.ValueOfBool) - } - case protoreflect.Uint32Kind: - switch valueKind { - case protoreflect.StringKind: - val := maps.Uint32ToStringP(flagSet, name, shorthand, nil, usage) - return newMapValue(val, protoreflect.ValueOfString) - case protoreflect.Int32Kind, protoreflect.Sint32Kind, protoreflect.Sfixed32Kind: - val := maps.Uint32ToInt32P(flagSet, name, shorthand, nil, usage) - return newMapValue(val, protoreflect.ValueOfInt32) - case protoreflect.Int64Kind, protoreflect.Sint64Kind, protoreflect.Sfixed64Kind: - val := maps.Uint32ToInt64P(flagSet, name, shorthand, nil, usage) - return newMapValue(val, protoreflect.ValueOfInt64) - case protoreflect.Uint32Kind: - val := maps.Uint32ToUint32P(flagSet, name, shorthand, nil, usage) - return newMapValue(val, protoreflect.ValueOfUint32) - case protoreflect.Uint64Kind: - val := maps.Uint32ToUint64P(flagSet, name, shorthand, nil, usage) - return newMapValue(val, protoreflect.ValueOfUint64) - case protoreflect.BoolKind: - val := maps.Uint32ToBoolP(flagSet, name, shorthand, nil, usage) - return newMapValue(val, protoreflect.ValueOfBool) - } - case protoreflect.Uint64Kind: - switch valueKind { - case protoreflect.StringKind: - val := maps.Uint64ToStringP(flagSet, name, shorthand, nil, usage) - return newMapValue(val, protoreflect.ValueOfString) - case protoreflect.Int32Kind, protoreflect.Sint32Kind, protoreflect.Sfixed32Kind: - val := maps.Uint64ToInt32P(flagSet, name, shorthand, nil, usage) - return newMapValue(val, protoreflect.ValueOfInt32) - case protoreflect.Int64Kind, protoreflect.Sint64Kind, protoreflect.Sfixed64Kind: - val := maps.Uint64ToInt64P(flagSet, name, shorthand, nil, usage) - return newMapValue(val, protoreflect.ValueOfInt64) - case protoreflect.Uint32Kind: - val := maps.Uint64ToUint32P(flagSet, name, shorthand, nil, usage) - return newMapValue(val, protoreflect.ValueOfUint32) - case protoreflect.Uint64Kind: - val := maps.Uint64ToUint64P(flagSet, name, shorthand, nil, usage) - return newMapValue(val, protoreflect.ValueOfUint64) - case protoreflect.BoolKind: - val := maps.Uint64ToBoolP(flagSet, name, shorthand, nil, usage) - return newMapValue(val, protoreflect.ValueOfBool) - } - case protoreflect.BoolKind: - switch valueKind { - case protoreflect.StringKind: - val := maps.BoolToStringP(flagSet, name, shorthand, nil, usage) - return newMapValue(val, protoreflect.ValueOfString) - case protoreflect.Int32Kind, protoreflect.Sint32Kind, protoreflect.Sfixed32Kind: - val := maps.BoolToInt32P(flagSet, name, shorthand, nil, usage) - return newMapValue(val, protoreflect.ValueOfInt32) - case protoreflect.Int64Kind, protoreflect.Sint64Kind, protoreflect.Sfixed64Kind: - val := maps.BoolToInt64P(flagSet, name, shorthand, nil, usage) - return newMapValue(val, protoreflect.ValueOfInt64) - case protoreflect.Uint32Kind: - val := maps.BoolToUint32P(flagSet, name, shorthand, nil, usage) - return newMapValue(val, protoreflect.ValueOfUint32) - case protoreflect.Uint64Kind: - val := maps.BoolToUint64P(flagSet, name, shorthand, nil, usage) - return newMapValue(val, protoreflect.ValueOfUint64) - case protoreflect.BoolKind: - val := maps.BoolToBoolP(flagSet, name, shorthand, nil, usage) - return newMapValue(val, protoreflect.ValueOfBool) - } - - } - return nil -} - -type mapValue[K comparable, V any] struct { - value *map[K]V - toProtoreflectValue func(V) protoreflect.Value -} - -func newMapValue[K comparable, V any](mapV *map[K]V, toProtoreflectValue func(V) protoreflect.Value) mapValue[K, V] { - return mapValue[K, V]{value: mapV, toProtoreflectValue: toProtoreflectValue} -} - -func (v mapValue[K, V]) Get(mutable protoreflect.Value) (protoreflect.Value, error) { - protoMap := mutable.Map() - for k, val := range *v.value { - protoMap.Set(protoreflect.MapKey(protoreflect.ValueOf(k)), v.toProtoreflectValue(val)) - } - return mutable, nil -} - -// keyValueResolver is a function that converts a string to a key that is primitive Type T -type keyValueResolver[T comparable] func(string) (T, error) - -// compositeMapType is a map type that is composed of a key and value type that are both primitive types -type compositeMapType[T comparable] struct { - keyValueResolver keyValueResolver[T] - keyType string - valueType Type -} - -// compositeMapValue is a map value that is composed of a key and value type that are both primitive types -type compositeMapValue[T comparable] struct { - keyValueResolver keyValueResolver[T] - keyType string - valueType Type - values map[T]protoreflect.Value - ctx *context.Context - opts *Builder -} - -func (m compositeMapType[T]) DefaultValue() string { - return "" -} - -func (m compositeMapType[T]) NewValue(ctx *context.Context, opts *Builder) Value { - return &compositeMapValue[T]{ - keyValueResolver: m.keyValueResolver, - valueType: m.valueType, - keyType: m.keyType, - ctx: ctx, - opts: opts, - values: nil, - } -} - -func (m *compositeMapValue[T]) Set(s string) error { - comaArgs := strings.Split(s, ",") - for _, arg := range comaArgs { - parts := strings.SplitN(arg, "=", 2) - if len(parts) != 2 { - return errors.New("invalid format, expected key=value") - } - key, val := parts[0], parts[1] - - keyValue, err := m.keyValueResolver(key) - if err != nil { - return err - } - - simpleVal := m.valueType.NewValue(m.ctx, m.opts) - err = simpleVal.Set(val) - if err != nil { - return err - } - protoValue, err := simpleVal.Get(protoreflect.Value{}) - if err != nil { - return err - } - if m.values == nil { - m.values = make(map[T]protoreflect.Value) - } - - m.values[keyValue] = protoValue - } - - return nil -} - -func (m *compositeMapValue[T]) Get(mutable protoreflect.Value) (protoreflect.Value, error) { - protoMap := mutable.Map() - for key, value := range m.values { - keyVal := protoreflect.ValueOf(key) - protoMap.Set(keyVal.MapKey(), value) - } - return protoreflect.ValueOfMap(protoMap), nil -} - -func (m *compositeMapValue[T]) String() string { - if m.values == nil { - return "" - } - - return fmt.Sprintf("%+v", m.values) -} - -func (m *compositeMapValue[T]) Type() string { - return fmt.Sprintf("map[%s]%s", m.keyType, m.valueType.NewValue(m.ctx, m.opts).Type()) -} diff --git a/connect/internal/autocli/flag/maps/generic.go b/connect/internal/autocli/flag/maps/generic.go deleted file mode 100644 index 1a734faf..00000000 --- a/connect/internal/autocli/flag/maps/generic.go +++ /dev/null @@ -1,61 +0,0 @@ -package maps - -import ( - "fmt" - "strings" -) - -type genericMapValueOptions[K comparable, V any] struct { - keyParser func(string) (K, error) - valueParser func(string) (V, error) - genericType string -} - -type genericMapValue[K comparable, V any] struct { - value *map[K]V - changed bool - Options genericMapValueOptions[K, V] -} - -func newGenericMapValue[K comparable, V any](val map[K]V, p *map[K]V) *genericMapValue[K, V] { - ssv := new(genericMapValue[K, V]) - ssv.value = p - *ssv.value = val - return ssv -} - -func (gm *genericMapValue[K, V]) Set(val string) error { - ss := strings.Split(val, ",") - out := make(map[K]V, len(ss)) - for _, pair := range ss { - kv := strings.SplitN(pair, "=", 2) - if len(kv) != 2 { - return fmt.Errorf("%s must be formatted as key=value", pair) - } - key, err := gm.Options.keyParser(kv[0]) - if err != nil { - return err - } - out[key], err = gm.Options.valueParser(kv[1]) - if err != nil { - return err - } - } - if !gm.changed { - *gm.value = out - } else { - for k, v := range out { - (*gm.value)[k] = v - } - } - gm.changed = true - return nil -} - -func (gm *genericMapValue[K, V]) Type() string { - return gm.Options.genericType -} - -func (gm *genericMapValue[K, V]) String() string { - return "" -} diff --git a/connect/internal/autocli/flag/maps/map_bool_to_value.go b/connect/internal/autocli/flag/maps/map_bool_to_value.go deleted file mode 100644 index aae8a7d6..00000000 --- a/connect/internal/autocli/flag/maps/map_bool_to_value.go +++ /dev/null @@ -1,138 +0,0 @@ -package maps - -import ( - "strconv" - - "github.com/spf13/pflag" -) - -func newBoolToString[K bool, V string](val map[K]V, p *map[K]V) *genericMapValue[K, V] { - newBoolStringMap := newGenericMapValue(val, p) - newBoolStringMap.Options = genericMapValueOptions[K, V]{ - genericType: "boolToString", - keyParser: func(s string) (K, error) { - value, err := strconv.ParseBool(s) - return K(value), err - }, - valueParser: func(s string) (V, error) { - return V(s), nil - }, - } - return newBoolStringMap -} - -func BoolToStringP(flagSet *pflag.FlagSet, name, shorthand string, value map[bool]string, usage string) *map[bool]string { - p := make(map[bool]string) - flagSet.VarP(newBoolToString(value, &p), name, shorthand, usage) - return &p -} - -func newBoolToInt32[K bool, V int32](val map[K]V, p *map[K]V) *genericMapValue[K, V] { - newBoolInt32Map := newGenericMapValue(val, p) - newBoolInt32Map.Options = genericMapValueOptions[K, V]{ - genericType: "boolToInt32", - keyParser: func(s string) (K, error) { - value, err := strconv.ParseBool(s) - return K(value), err - }, - valueParser: func(s string) (V, error) { - value, err := strconv.ParseInt(s, 10, 32) - return V(value), err - }, - } - return newBoolInt32Map -} - -func BoolToInt32P(flagSet *pflag.FlagSet, name, shorthand string, value map[bool]int32, usage string) *map[bool]int32 { - p := make(map[bool]int32) - flagSet.VarP(newBoolToInt32(value, &p), name, shorthand, usage) - return &p -} - -func newBoolToInt64[K bool, V int64](val map[K]V, p *map[K]V) *genericMapValue[K, V] { - newBoolInt64Map := newGenericMapValue(val, p) - newBoolInt64Map.Options = genericMapValueOptions[K, V]{ - genericType: "boolToInt64", - keyParser: func(s string) (K, error) { - value, err := strconv.ParseBool(s) - return K(value), err - }, - valueParser: func(s string) (V, error) { - value, err := strconv.ParseInt(s, 10, 64) - return V(value), err - }, - } - return newBoolInt64Map -} - -func BoolToInt64P(flagSet *pflag.FlagSet, name, shorthand string, value map[bool]int64, usage string) *map[bool]int64 { - p := make(map[bool]int64) - flagSet.VarP(newBoolToInt64(value, &p), name, shorthand, usage) - return &p -} - -func newBoolToUint32[K bool, V uint32](val map[K]V, p *map[K]V) *genericMapValue[K, V] { - newBoolUint32Map := newGenericMapValue(val, p) - newBoolUint32Map.Options = genericMapValueOptions[K, V]{ - genericType: "boolToUint32", - keyParser: func(s string) (K, error) { - value, err := strconv.ParseBool(s) - return K(value), err - }, - valueParser: func(s string) (V, error) { - value, err := strconv.ParseUint(s, 10, 32) - return V(value), err - }, - } - return newBoolUint32Map -} - -func BoolToUint32P(flagSet *pflag.FlagSet, name, shorthand string, value map[bool]uint32, usage string) *map[bool]uint32 { - p := make(map[bool]uint32) - flagSet.VarP(newBoolToUint32(value, &p), name, shorthand, usage) - return &p -} - -func newBoolToUint64[K bool, V uint64](val map[K]V, p *map[K]V) *genericMapValue[K, V] { - newBoolUint64Map := newGenericMapValue(val, p) - newBoolUint64Map.Options = genericMapValueOptions[K, V]{ - genericType: "boolToUint64", - keyParser: func(s string) (K, error) { - value, err := strconv.ParseBool(s) - return K(value), err - }, - valueParser: func(s string) (V, error) { - value, err := strconv.ParseUint(s, 10, 64) - return V(value), err - }, - } - return newBoolUint64Map -} - -func BoolToUint64P(flagSet *pflag.FlagSet, name, shorthand string, value map[bool]uint64, usage string) *map[bool]uint64 { - p := make(map[bool]uint64) - flagSet.VarP(newBoolToUint64(value, &p), name, shorthand, usage) - return &p -} - -func newBoolToBool[K, V bool](val map[K]V, p *map[K]V) *genericMapValue[K, V] { - newBoolBoolMap := newGenericMapValue(val, p) - newBoolBoolMap.Options = genericMapValueOptions[K, V]{ - genericType: "boolToBool", - keyParser: func(s string) (K, error) { - value, err := strconv.ParseBool(s) - return K(value), err - }, - valueParser: func(s string) (V, error) { - value, err := strconv.ParseBool(s) - return V(value), err - }, - } - return newBoolBoolMap -} - -func BoolToBoolP(flagSet *pflag.FlagSet, name, shorthand string, value map[bool]bool, usage string) *map[bool]bool { - p := make(map[bool]bool) - flagSet.VarP(newBoolToBool(value, &p), name, shorthand, usage) - return &p -} diff --git a/connect/internal/autocli/flag/maps/map_int32_to_value.go b/connect/internal/autocli/flag/maps/map_int32_to_value.go deleted file mode 100644 index c10adf73..00000000 --- a/connect/internal/autocli/flag/maps/map_int32_to_value.go +++ /dev/null @@ -1,159 +0,0 @@ -package maps - -import ( - "strconv" - - "github.com/spf13/pflag" -) - -func newInt32ToString[K int32, V string](val map[K]V, p *map[K]V) *genericMapValue[K, V] { - newInt32StringMap := newGenericMapValue(val, p) - newInt32StringMap.Options = genericMapValueOptions[K, V]{ - genericType: "int32ToString", - keyParser: func(s string) (K, error) { - value, err := strconv.ParseInt(s, 10, 32) - return K(value), err - }, - valueParser: func(s string) (V, error) { - return V(s), nil - }, - } - return newInt32StringMap -} - -func Int32ToStringP(flagSet *pflag.FlagSet, name, shorthand string, value map[int32]string, usage string) *map[int32]string { - p := make(map[int32]string) - flagSet.VarP(newInt32ToString(value, &p), name, shorthand, usage) - return &p -} - -func newInt32ToInt32[K, V int32](val map[K]V, p *map[K]V) *genericMapValue[K, V] { - newInt32Int32Map := newGenericMapValue(val, p) - newInt32Int32Map.Options = genericMapValueOptions[K, V]{ - genericType: "int32ToInt32", - keyParser: func(s string) (K, error) { - value, err := strconv.ParseInt(s, 10, 32) - return K(value), err - }, - valueParser: func(s string) (V, error) { - value, err := strconv.ParseInt(s, 10, 32) - return V(value), err - }, - } - return newInt32Int32Map -} - -func Int32ToInt32P(flagSet *pflag.FlagSet, name, shorthand string, value map[int32]int32, usage string) *map[int32]int32 { - p := make(map[int32]int32) - flagSet.VarP(newInt32ToInt32(value, &p), name, shorthand, usage) - return &p -} - -func newInt32ToInt64[K int32, V int64](val map[K]V, p *map[K]V) *genericMapValue[K, V] { - newInt32Int64Map := newGenericMapValue(val, p) - newInt32Int64Map.Options = genericMapValueOptions[K, V]{ - genericType: "int32ToInt64", - keyParser: func(s string) (K, error) { - value, err := strconv.ParseInt(s, 10, 32) - return K(value), err - }, - valueParser: func(s string) (V, error) { - value, err := strconv.ParseInt(s, 10, 64) - return V(value), err - }, - } - return newInt32Int64Map -} - -func Int32ToInt64P(flagSet *pflag.FlagSet, name, shorthand string, value map[int32]int64, usage string) *map[int32]int64 { - p := make(map[int32]int64) - flagSet.VarP(newInt32ToInt64(value, &p), name, shorthand, usage) - return &p -} - -func newInt32ToUint32[K int32, V uint32](val map[K]V, p *map[K]V) *genericMapValue[K, V] { - newInt32Uint32Map := newGenericMapValue(val, p) - newInt32Uint32Map.Options = genericMapValueOptions[K, V]{ - genericType: "int32ToUint32", - keyParser: func(s string) (K, error) { - value, err := strconv.ParseInt(s, 10, 32) - return K(value), err - }, - valueParser: func(s string) (V, error) { - value, err := strconv.ParseUint(s, 10, 32) - return V(value), err - }, - } - return newInt32Uint32Map -} - -func Int32ToUint32P(flagSet *pflag.FlagSet, name, shorthand string, value map[int32]uint32, usage string) *map[int32]uint32 { - p := make(map[int32]uint32) - flagSet.VarP(newInt32ToUint32(value, &p), name, shorthand, usage) - return &p -} - -func newInt32ToUint64[K int32, V uint64](val map[K]V, p *map[K]V) *genericMapValue[K, V] { - newInt32Uint64Map := newGenericMapValue(val, p) - newInt32Uint64Map.Options = genericMapValueOptions[K, V]{ - genericType: "int32ToUint64", - keyParser: func(s string) (K, error) { - value, err := strconv.ParseInt(s, 10, 32) - return K(value), err - }, - valueParser: func(s string) (V, error) { - value, err := strconv.ParseUint(s, 10, 64) - return V(value), err - }, - } - return newInt32Uint64Map -} - -func Int32ToUint64P(flagSet *pflag.FlagSet, name, shorthand string, value map[int32]uint64, usage string) *map[int32]uint64 { - p := make(map[int32]uint64) - flagSet.VarP(newInt32ToUint64(value, &p), name, shorthand, usage) - return &p -} - -func newInt32ToBool[K int32, V bool](val map[K]V, p *map[K]V) *genericMapValue[K, V] { - newInt32BoolMap := newGenericMapValue(val, p) - newInt32BoolMap.Options = genericMapValueOptions[K, V]{ - genericType: "int32ToBool", - keyParser: func(s string) (K, error) { - value, err := strconv.ParseInt(s, 10, 32) - return K(value), err - }, - valueParser: func(s string) (V, error) { - value, err := strconv.ParseBool(s) - return V(value), err - }, - } - return newInt32BoolMap -} - -func Int32ToBoolP(flagSet *pflag.FlagSet, name, shorthand string, value map[int32]bool, usage string) *map[int32]bool { - p := make(map[int32]bool) - flagSet.VarP(newInt32ToBool(value, &p), name, shorthand, usage) - return &p -} - -func newStringToBool[K string, V bool](val map[K]V, p *map[K]V) *genericMapValue[K, V] { - newStringBoolMap := newGenericMapValue(val, p) - newStringBoolMap.Options = genericMapValueOptions[K, V]{ - genericType: "stringToBool", - keyParser: func(s string) (K, error) { - return K(s), nil - }, - valueParser: func(s string) (V, error) { - value, err := strconv.ParseBool(s) - return V(value), err - }, - } - return newStringBoolMap -} - -func StringToBoolP(flagSet *pflag.FlagSet, name, shorthand string, value map[string]bool, usage string) *map[string]bool { - p := make(map[string]bool) - flagSet.VarP(newStringToBool(value, &p), name, shorthand, usage) - return &p -} diff --git a/connect/internal/autocli/flag/maps/map_int64_to_value.go b/connect/internal/autocli/flag/maps/map_int64_to_value.go deleted file mode 100644 index 9d85ef96..00000000 --- a/connect/internal/autocli/flag/maps/map_int64_to_value.go +++ /dev/null @@ -1,180 +0,0 @@ -package maps - -import ( - "strconv" - - "github.com/spf13/pflag" -) - -func newInt64ToString[K int64, V string](val map[K]V, p *map[K]V) *genericMapValue[K, V] { - newInt64StringMap := newGenericMapValue(val, p) - newInt64StringMap.Options = genericMapValueOptions[K, V]{ - genericType: "int64ToString", - keyParser: func(s string) (K, error) { - value, err := strconv.ParseInt(s, 10, 64) - return K(value), err - }, - valueParser: func(s string) (V, error) { - return V(s), nil - }, - } - return newInt64StringMap -} - -func Int64ToStringP(flagSet *pflag.FlagSet, name, shorthand string, value map[int64]string, usage string) *map[int64]string { - p := make(map[int64]string) - flagSet.VarP(newInt64ToString(value, &p), name, shorthand, usage) - return &p -} - -func newInt64ToInt32[K int64, V int32](val map[K]V, p *map[K]V) *genericMapValue[K, V] { - newInt64Int32Map := newGenericMapValue(val, p) - newInt64Int32Map.Options = genericMapValueOptions[K, V]{ - genericType: "int64ToInt32", - keyParser: func(s string) (K, error) { - value, err := strconv.ParseInt(s, 10, 64) - return K(value), err - }, - valueParser: func(s string) (V, error) { - value, err := strconv.ParseInt(s, 10, 32) - return V(value), err - }, - } - return newInt64Int32Map -} - -func Int64ToInt32P(flagSet *pflag.FlagSet, name, shorthand string, value map[int64]int32, usage string) *map[int64]int32 { - p := make(map[int64]int32) - flagSet.VarP(newInt64ToInt32(value, &p), name, shorthand, usage) - return &p -} - -func newInt64ToInt64[K, V int64](val map[K]V, p *map[K]V) *genericMapValue[K, V] { - newInt64Int64Map := newGenericMapValue(val, p) - newInt64Int64Map.Options = genericMapValueOptions[K, V]{ - genericType: "int64ToInt64", - keyParser: func(s string) (K, error) { - value, err := strconv.ParseInt(s, 10, 64) - return K(value), err - }, - valueParser: func(s string) (V, error) { - value, err := strconv.ParseInt(s, 10, 64) - return V(value), err - }, - } - return newInt64Int64Map -} - -func Int64ToInt64P(flagSet *pflag.FlagSet, name, shorthand string, value map[int64]int64, usage string) *map[int64]int64 { - p := make(map[int64]int64) - flagSet.VarP(newInt64ToInt64(value, &p), name, shorthand, usage) - return &p -} - -func newInt64ToUint32[K int64, V uint32](val map[K]V, p *map[K]V) *genericMapValue[K, V] { - newInt64Uint32Map := newGenericMapValue(val, p) - newInt64Uint32Map.Options = genericMapValueOptions[K, V]{ - genericType: "int64ToUint32", - keyParser: func(s string) (K, error) { - value, err := strconv.ParseInt(s, 10, 64) - return K(value), err - }, - valueParser: func(s string) (V, error) { - value, err := strconv.ParseUint(s, 10, 32) - return V(value), err - }, - } - return newInt64Uint32Map -} - -func Int64ToUint32P(flagSet *pflag.FlagSet, name, shorthand string, value map[int64]uint32, usage string) *map[int64]uint32 { - p := make(map[int64]uint32) - flagSet.VarP(newInt64ToUint32(value, &p), name, shorthand, usage) - return &p -} - -func newInt64ToUint64[K int64, V uint64](val map[K]V, p *map[K]V) *genericMapValue[K, V] { - newInt64Uint64Map := newGenericMapValue(val, p) - newInt64Uint64Map.Options = genericMapValueOptions[K, V]{ - genericType: "int64ToUint64", - keyParser: func(s string) (K, error) { - value, err := strconv.ParseInt(s, 10, 64) - return K(value), err - }, - valueParser: func(s string) (V, error) { - value, err := strconv.ParseUint(s, 10, 64) - return V(value), err - }, - } - return newInt64Uint64Map -} - -func Int64ToUint64P(flagSet *pflag.FlagSet, name, shorthand string, value map[int64]uint64, usage string) *map[int64]uint64 { - p := make(map[int64]uint64) - flagSet.VarP(newInt64ToUint64(value, &p), name, shorthand, usage) - return &p -} - -func newInt64ToBool[K int64, V bool](val map[K]V, p *map[K]V) *genericMapValue[K, V] { - newInt64BoolMap := newGenericMapValue(val, p) - newInt64BoolMap.Options = genericMapValueOptions[K, V]{ - genericType: "int64ToBool", - keyParser: func(s string) (K, error) { - value, err := strconv.ParseInt(s, 10, 64) - return K(value), err - }, - valueParser: func(s string) (V, error) { - value, err := strconv.ParseBool(s) - return V(value), err - }, - } - return newInt64BoolMap -} - -func Int64ToBoolP(flagSet *pflag.FlagSet, name, shorthand string, value map[int64]bool, usage string) *map[int64]bool { - p := make(map[int64]bool) - flagSet.VarP(newInt64ToBool(value, &p), name, shorthand, usage) - return &p -} - -func newStringToUint32[K string, V uint32](val map[K]V, p *map[K]V) *genericMapValue[K, V] { - newStringUintMap := newGenericMapValue(val, p) - newStringUintMap.Options = genericMapValueOptions[K, V]{ - genericType: "stringToUint32", - keyParser: func(s string) (K, error) { - return K(s), nil - }, - valueParser: func(s string) (V, error) { - value, err := strconv.ParseUint(s, 10, 32) - return V(value), err - }, - } - return newStringUintMap -} - -func StringToUint32P(flagSet *pflag.FlagSet, name, shorthand string, value map[string]uint32, usage string) *map[string]uint32 { - p := make(map[string]uint32) - flagSet.VarP(newStringToUint32(value, &p), name, shorthand, usage) - return &p -} - -func newStringToUint64[K string, V uint64](val map[K]V, p *map[K]V) *genericMapValue[K, V] { - newStringUint64Map := newGenericMapValue(val, p) - newStringUint64Map.Options = genericMapValueOptions[K, V]{ - genericType: "stringToUint64", - keyParser: func(s string) (K, error) { - return K(s), nil - }, - valueParser: func(s string) (V, error) { - value, err := strconv.ParseUint(s, 10, 64) - return V(value), err - }, - } - return newStringUint64Map -} - -func StringToUint64P(flagSet *pflag.FlagSet, name, shorthand string, value map[string]uint64, usage string) *map[string]uint64 { - p := make(map[string]uint64) - flagSet.VarP(newStringToUint64(value, &p), name, shorthand, usage) - return &p -} diff --git a/connect/internal/autocli/flag/maps/map_string_to_value.go b/connect/internal/autocli/flag/maps/map_string_to_value.go deleted file mode 100644 index aff2fd94..00000000 --- a/connect/internal/autocli/flag/maps/map_string_to_value.go +++ /dev/null @@ -1,28 +0,0 @@ -package maps - -import ( - "strconv" - - "github.com/spf13/pflag" -) - -func newStringToInt32[K string, V int32](val map[K]V, p *map[K]V) *genericMapValue[K, V] { - newStringIntMap := newGenericMapValue(val, p) - newStringIntMap.Options = genericMapValueOptions[K, V]{ - genericType: "stringToInt32", - keyParser: func(s string) (K, error) { - return K(s), nil - }, - valueParser: func(s string) (V, error) { - value, err := strconv.ParseInt(s, 10, 32) - return V(value), err - }, - } - return newStringIntMap -} - -func StringToInt32P(flagSet *pflag.FlagSet, name, shorthand string, value map[string]int32, usage string) *map[string]int32 { - p := make(map[string]int32) - flagSet.VarP(newStringToInt32(value, &p), name, shorthand, usage) - return &p -} diff --git a/connect/internal/autocli/flag/maps/map_uint32_to_value.go b/connect/internal/autocli/flag/maps/map_uint32_to_value.go deleted file mode 100644 index c346cd33..00000000 --- a/connect/internal/autocli/flag/maps/map_uint32_to_value.go +++ /dev/null @@ -1,138 +0,0 @@ -package maps - -import ( - "strconv" - - "github.com/spf13/pflag" -) - -func newUint32ToString[K uint32, V string](val map[K]V, p *map[K]V) *genericMapValue[K, V] { - newUint32StringMap := newGenericMapValue(val, p) - newUint32StringMap.Options = genericMapValueOptions[K, V]{ - genericType: "uint32ToString", - keyParser: func(s string) (K, error) { - value, err := strconv.ParseUint(s, 10, 32) - return K(value), err - }, - valueParser: func(s string) (V, error) { - return V(s), nil - }, - } - return newUint32StringMap -} - -func Uint32ToStringP(flagSet *pflag.FlagSet, name, shorthand string, value map[uint32]string, usage string) *map[uint32]string { - p := make(map[uint32]string) - flagSet.VarP(newUint32ToString(value, &p), name, shorthand, usage) - return &p -} - -func newUint32ToInt32[K uint32, V int32](val map[K]V, p *map[K]V) *genericMapValue[K, V] { - newUint32Int32Map := newGenericMapValue(val, p) - newUint32Int32Map.Options = genericMapValueOptions[K, V]{ - genericType: "uint32ToInt32", - keyParser: func(s string) (K, error) { - value, err := strconv.ParseUint(s, 10, 32) - return K(value), err - }, - valueParser: func(s string) (V, error) { - value, err := strconv.ParseInt(s, 10, 32) - return V(value), err - }, - } - return newUint32Int32Map -} - -func Uint32ToInt32P(flagSet *pflag.FlagSet, name, shorthand string, value map[uint32]int32, usage string) *map[uint32]int32 { - p := make(map[uint32]int32) - flagSet.VarP(newUint32ToInt32(value, &p), name, shorthand, usage) - return &p -} - -func newUint32ToInt64[K uint32, V int64](val map[K]V, p *map[K]V) *genericMapValue[K, V] { - newUint32Int64Map := newGenericMapValue(val, p) - newUint32Int64Map.Options = genericMapValueOptions[K, V]{ - genericType: "uint32ToInt64", - keyParser: func(s string) (K, error) { - value, err := strconv.ParseUint(s, 10, 32) - return K(value), err - }, - valueParser: func(s string) (V, error) { - value, err := strconv.ParseInt(s, 10, 64) - return V(value), err - }, - } - return newUint32Int64Map -} - -func Uint32ToInt64P(flagSet *pflag.FlagSet, name, shorthand string, value map[uint32]int64, usage string) *map[uint32]int64 { - p := make(map[uint32]int64) - flagSet.VarP(newUint32ToInt64(value, &p), name, shorthand, usage) - return &p -} - -func newUint32ToUint32[K, V uint32](val map[K]V, p *map[K]V) *genericMapValue[K, V] { - newUint32Uint32Map := newGenericMapValue(val, p) - newUint32Uint32Map.Options = genericMapValueOptions[K, V]{ - genericType: "uint32ToUint32", - keyParser: func(s string) (K, error) { - value, err := strconv.ParseUint(s, 10, 32) - return K(value), err - }, - valueParser: func(s string) (V, error) { - value, err := strconv.ParseUint(s, 10, 32) - return V(value), err - }, - } - return newUint32Uint32Map -} - -func Uint32ToUint32P(flagSet *pflag.FlagSet, name, shorthand string, value map[uint32]uint32, usage string) *map[uint32]uint32 { - p := make(map[uint32]uint32) - flagSet.VarP(newUint32ToUint32(value, &p), name, shorthand, usage) - return &p -} - -func newUint32ToUint64[K uint32, V uint64](val map[K]V, p *map[K]V) *genericMapValue[K, V] { - newUint32Uint64Map := newGenericMapValue(val, p) - newUint32Uint64Map.Options = genericMapValueOptions[K, V]{ - genericType: "uint32ToUint64", - keyParser: func(s string) (K, error) { - value, err := strconv.ParseUint(s, 10, 32) - return K(value), err - }, - valueParser: func(s string) (V, error) { - value, err := strconv.ParseUint(s, 10, 64) - return V(value), err - }, - } - return newUint32Uint64Map -} - -func Uint32ToUint64P(flagSet *pflag.FlagSet, name, shorthand string, value map[uint32]uint64, usage string) *map[uint32]uint64 { - p := make(map[uint32]uint64) - flagSet.VarP(newUint32ToUint64(value, &p), name, shorthand, usage) - return &p -} - -func newUint32ToBool[K uint32, V bool](val map[K]V, p *map[K]V) *genericMapValue[K, V] { - newUint32BoolMap := newGenericMapValue(val, p) - newUint32BoolMap.Options = genericMapValueOptions[K, V]{ - genericType: "uint32ToBool", - keyParser: func(s string) (K, error) { - value, err := strconv.ParseUint(s, 10, 32) - return K(value), err - }, - valueParser: func(s string) (V, error) { - value, err := strconv.ParseBool(s) - return V(value), err - }, - } - return newUint32BoolMap -} - -func Uint32ToBoolP(flagSet *pflag.FlagSet, name, shorthand string, value map[uint32]bool, usage string) *map[uint32]bool { - p := make(map[uint32]bool) - flagSet.VarP(newUint32ToBool(value, &p), name, shorthand, usage) - return &p -} diff --git a/connect/internal/autocli/flag/maps/map_uint64_to_value.go b/connect/internal/autocli/flag/maps/map_uint64_to_value.go deleted file mode 100644 index e5e4318b..00000000 --- a/connect/internal/autocli/flag/maps/map_uint64_to_value.go +++ /dev/null @@ -1,138 +0,0 @@ -package maps - -import ( - "strconv" - - "github.com/spf13/pflag" -) - -func newUint64ToString[K uint64, V string](val map[K]V, p *map[K]V) *genericMapValue[K, V] { - newUint64StringMap := newGenericMapValue(val, p) - newUint64StringMap.Options = genericMapValueOptions[K, V]{ - genericType: "uint64ToString", - keyParser: func(s string) (K, error) { - value, err := strconv.ParseUint(s, 10, 64) - return K(value), err - }, - valueParser: func(s string) (V, error) { - return V(s), nil - }, - } - return newUint64StringMap -} - -func Uint64ToStringP(flagSet *pflag.FlagSet, name, shorthand string, value map[uint64]string, usage string) *map[uint64]string { - p := make(map[uint64]string) - flagSet.VarP(newUint64ToString(value, &p), name, shorthand, usage) - return &p -} - -func newUint64ToInt32[K uint64, V int32](val map[K]V, p *map[K]V) *genericMapValue[K, V] { - newUint64Int32Map := newGenericMapValue(val, p) - newUint64Int32Map.Options = genericMapValueOptions[K, V]{ - genericType: "uint64ToInt32", - keyParser: func(s string) (K, error) { - value, err := strconv.ParseUint(s, 10, 64) - return K(value), err - }, - valueParser: func(s string) (V, error) { - value, err := strconv.ParseInt(s, 10, 32) - return V(value), err - }, - } - return newUint64Int32Map -} - -func Uint64ToInt32P(flagSet *pflag.FlagSet, name, shorthand string, value map[uint64]int32, usage string) *map[uint64]int32 { - p := make(map[uint64]int32) - flagSet.VarP(newUint64ToInt32(value, &p), name, shorthand, usage) - return &p -} - -func newUint64ToInt64[K uint64, V int64](val map[K]V, p *map[K]V) *genericMapValue[K, V] { - newUint64Int64Map := newGenericMapValue(val, p) - newUint64Int64Map.Options = genericMapValueOptions[K, V]{ - genericType: "uint64ToInt64", - keyParser: func(s string) (K, error) { - value, err := strconv.ParseUint(s, 10, 64) - return K(value), err - }, - valueParser: func(s string) (V, error) { - value, err := strconv.ParseInt(s, 10, 64) - return V(value), err - }, - } - return newUint64Int64Map -} - -func Uint64ToInt64P(flagSet *pflag.FlagSet, name, shorthand string, value map[uint64]int64, usage string) *map[uint64]int64 { - p := make(map[uint64]int64) - flagSet.VarP(newUint64ToInt64(value, &p), name, shorthand, usage) - return &p -} - -func newUint64ToUint32[K uint64, V uint32](val map[K]V, p *map[K]V) *genericMapValue[K, V] { - newUint64Uint32Map := newGenericMapValue(val, p) - newUint64Uint32Map.Options = genericMapValueOptions[K, V]{ - genericType: "uint64ToUint32", - keyParser: func(s string) (K, error) { - value, err := strconv.ParseUint(s, 10, 64) - return K(value), err - }, - valueParser: func(s string) (V, error) { - value, err := strconv.ParseUint(s, 10, 32) - return V(value), err - }, - } - return newUint64Uint32Map -} - -func Uint64ToUint32P(flagSet *pflag.FlagSet, name, shorthand string, value map[uint64]uint32, usage string) *map[uint64]uint32 { - p := make(map[uint64]uint32) - flagSet.VarP(newUint64ToUint32(value, &p), name, shorthand, usage) - return &p -} - -func newUint64ToUint64[K, V uint64](val map[K]V, p *map[K]V) *genericMapValue[K, V] { - newUint64Uint64Map := newGenericMapValue(val, p) - newUint64Uint64Map.Options = genericMapValueOptions[K, V]{ - genericType: "uint64ToUint64", - keyParser: func(s string) (K, error) { - value, err := strconv.ParseUint(s, 10, 64) - return K(value), err - }, - valueParser: func(s string) (V, error) { - value, err := strconv.ParseUint(s, 10, 64) - return V(value), err - }, - } - return newUint64Uint64Map -} - -func Uint64ToUint64P(flagSet *pflag.FlagSet, name, shorthand string, value map[uint64]uint64, usage string) *map[uint64]uint64 { - p := make(map[uint64]uint64) - flagSet.VarP(newUint64ToUint64(value, &p), name, shorthand, usage) - return &p -} - -func newUint64ToBool[K uint64, V bool](val map[K]V, p *map[K]V) *genericMapValue[K, V] { - newUint64BoolMap := newGenericMapValue(val, p) - newUint64BoolMap.Options = genericMapValueOptions[K, V]{ - genericType: "uint64ToBool", - keyParser: func(s string) (K, error) { - value, err := strconv.ParseUint(s, 10, 64) - return K(value), err - }, - valueParser: func(s string) (V, error) { - value, err := strconv.ParseBool(s) - return V(value), err - }, - } - return newUint64BoolMap -} - -func Uint64ToBoolP(flagSet *pflag.FlagSet, name, shorthand string, value map[uint64]bool, usage string) *map[uint64]bool { - p := make(map[uint64]bool) - flagSet.VarP(newUint64ToBool(value, &p), name, shorthand, usage) - return &p -} diff --git a/connect/internal/autocli/flag/messager_binder.go b/connect/internal/autocli/flag/messager_binder.go deleted file mode 100644 index 08a270e7..00000000 --- a/connect/internal/autocli/flag/messager_binder.go +++ /dev/null @@ -1,155 +0,0 @@ -package flag - -import ( - "fmt" - "strings" - - "github.com/spf13/cobra" - "github.com/spf13/pflag" - "google.golang.org/protobuf/reflect/protoreflect" -) - -// SignerInfo contains information about the signer field. -// That field is special because it needs to be known for signing. -// This struct keeps track of the field name and whether it is a flag. -// IsFlag and PositionalArgIndex are mutually exclusive. -type SignerInfo struct { - PositionalArgIndex int - IsFlag bool - - FieldName string - FlagName string // flag name (always set if IsFlag is true) -} - -// MessageBinder binds multiple flags in a flag set to a protobuf message. -type MessageBinder struct { - CobraArgs cobra.PositionalArgs - SignerInfo SignerInfo - - positionalFlagSet *pflag.FlagSet - positionalArgs []fieldBinding - flagBindings []fieldBinding - messageType protoreflect.MessageType - - hasVarargs bool - hasOptional bool - mandatoryArgUntil int -} - -// BuildMessage builds and returns a new message for the bound flags. -func (m MessageBinder) BuildMessage(positionalArgs []string) (protoreflect.Message, error) { - msg := m.messageType.New() - err := m.Bind(msg, positionalArgs) - return msg, err -} - -// Bind binds the flag values to an existing protobuf message. -func (m MessageBinder) Bind(msg protoreflect.Message, positionalArgs []string) error { - // first set positional args in the positional arg flag set - n := len(positionalArgs) - for i := range m.positionalArgs { - if i == n { - break - } - - name := fmt.Sprintf("%d", i) - if i == m.mandatoryArgUntil && m.hasVarargs { - for _, v := range positionalArgs[i:] { - if err := m.positionalFlagSet.Set(name, v); err != nil { - return err - } - } - } else { - if err := m.positionalFlagSet.Set(name, positionalArgs[i]); err != nil { - return err - } - } - } - - msgName := msg.Descriptor().Name() - // bind positional arg values to the message - for _, arg := range m.positionalArgs { - if msgName == arg.field.Parent().Name() { - if err := arg.bind(msg); err != nil { - return err - } - } else { - s := strings.Split(arg.path, ".") - if err := m.bindNestedField(msg, arg, s); err != nil { - return err - } - } - } - - // bind flag values to the message - for _, binding := range m.flagBindings { - if err := binding.bind(msg); err != nil { - return err - } - } - - return nil -} - -// bindNestedField binds a field value to a nested message field. It handles cases where the field -// belongs to a nested message type by recursively traversing the message structure. -func (m *MessageBinder) bindNestedField(msg protoreflect.Message, arg fieldBinding, path []string) error { - if len(path) == 1 { - return arg.bind(msg) - } - - name := protoreflect.Name(path[0]) - fd := msg.Descriptor().Fields().ByName(name) - if fd == nil { - return fmt.Errorf("field %q not found", path[0]) - } - - var innerMsg protoreflect.Message - if fd.IsList() { - if msg.Get(fd).List().Len() == 0 { - l := msg.Mutable(fd).List() - elem := l.NewElement().Message().New() - l.Append(protoreflect.ValueOfMessage(elem)) - msg.Set(msg.Descriptor().Fields().ByName(name), protoreflect.ValueOfList(l)) - } - innerMsg = msg.Get(fd).List().Get(0).Message() - } else { - innerMsgValue := msg.Get(fd) - if !innerMsgValue.Message().IsValid() { - msg.Set(msg.Descriptor().Fields().ByName(name), protoreflect.ValueOfMessage(innerMsgValue.Message().New())) - } - innerMsg = msg.Get(msg.Descriptor().Fields().ByName(name)).Message() - } - - return m.bindNestedField(innerMsg, arg, path[1:]) -} - -// Get calls BuildMessage and wraps the result in a protoreflect.Value. -func (m MessageBinder) Get(protoreflect.Value) (protoreflect.Value, error) { - msg, err := m.BuildMessage(nil) - return protoreflect.ValueOfMessage(msg), err -} - -type fieldBinding struct { - hasValue HasValue - field protoreflect.FieldDescriptor - path string -} - -func (f fieldBinding) bind(msg protoreflect.Message) error { - field := f.field - val, err := f.hasValue.Get(msg.NewField(field)) - if err != nil { - return err - } - - if field.IsMap() { - return nil - } - - if msg.IsValid() && val.IsValid() { - msg.Set(f.field, val) - } - - return nil -} diff --git a/connect/internal/autocli/flag/pubkey.go b/connect/internal/autocli/flag/pubkey.go deleted file mode 100644 index f91eab8f..00000000 --- a/connect/internal/autocli/flag/pubkey.go +++ /dev/null @@ -1,61 +0,0 @@ -package flag - -import ( - "context" - "errors" - "fmt" - - "google.golang.org/protobuf/reflect/protoreflect" - - "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/codec/types" - cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" - cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" -) - -type pubkeyType struct{} - -func (a pubkeyType) NewValue(_ *context.Context, _ *Builder) Value { - return &pubkeyValue{} -} - -func (a pubkeyType) DefaultValue() string { - return "" -} - -type pubkeyValue struct { - value *types.Any -} - -func (a pubkeyValue) Get(protoreflect.Value) (protoreflect.Value, error) { - return protoreflect.ValueOf(a.value), nil -} - -func (a pubkeyValue) String() string { - return a.value.String() -} - -func (a *pubkeyValue) Set(s string) error { - registry := types.NewInterfaceRegistry() - cryptocodec.RegisterInterfaces(registry) - cdc := codec.NewProtoCodec(registry) - - var pk cryptotypes.PubKey - err := cdc.UnmarshalInterfaceJSON([]byte(s), &pk) - if err != nil { - return fmt.Errorf("input isn't a pubkey: %w", err) - } - - any, err := types.NewAnyWithValue(pk) - if err != nil { - return errors.New("error converting to any type") - } - - a.value = any - - return nil -} - -func (a pubkeyValue) Type() string { - return "pubkey" -} diff --git a/connect/internal/autocli/flag/simple.go b/connect/internal/autocli/flag/simple.go deleted file mode 100644 index a64c565e..00000000 --- a/connect/internal/autocli/flag/simple.go +++ /dev/null @@ -1,44 +0,0 @@ -package flag - -import ( - "github.com/spf13/pflag" - "google.golang.org/protobuf/reflect/protoreflect" -) - -func bindSimpleFlag(flagSet *pflag.FlagSet, kind protoreflect.Kind, name, shorthand, usage string) HasValue { - switch kind { - case protoreflect.StringKind: - val := flagSet.StringP(name, shorthand, "", usage) - return newSimpleValue(val, protoreflect.ValueOfString) - case protoreflect.Uint32Kind, protoreflect.Fixed32Kind: - val := flagSet.Uint32P(name, shorthand, 0, usage) - return newSimpleValue(val, protoreflect.ValueOfUint32) - case protoreflect.Uint64Kind, protoreflect.Fixed64Kind: - val := flagSet.Uint64P(name, shorthand, 0, usage) - return newSimpleValue(val, protoreflect.ValueOfUint64) - case protoreflect.Int32Kind, protoreflect.Sint32Kind, protoreflect.Sfixed32Kind: - val := flagSet.Int32P(name, shorthand, 0, usage) - return newSimpleValue(val, protoreflect.ValueOfInt32) - case protoreflect.Int64Kind, protoreflect.Sint64Kind, protoreflect.Sfixed64Kind: - val := flagSet.Int64P(name, shorthand, 0, usage) - return newSimpleValue(val, protoreflect.ValueOfInt64) - case protoreflect.BoolKind: - val := flagSet.BoolP(name, shorthand, false, usage) - return newSimpleValue(val, protoreflect.ValueOfBool) - default: - return nil - } -} - -type simpleValue[T any] struct { - val *T - toProtoreflectValue func(T) protoreflect.Value -} - -func newSimpleValue[T any](val *T, toProtoreflectValue func(T) protoreflect.Value) HasValue { - return simpleValue[T]{val: val, toProtoreflectValue: toProtoreflectValue} -} - -func (v simpleValue[T]) Get(protoreflect.Value) (protoreflect.Value, error) { - return v.toProtoreflectValue(*v.val), nil -} diff --git a/connect/internal/autocli/flag/timestamp.go b/connect/internal/autocli/flag/timestamp.go deleted file mode 100644 index d77f0293..00000000 --- a/connect/internal/autocli/flag/timestamp.go +++ /dev/null @@ -1,50 +0,0 @@ -package flag - -import ( - "context" - "time" - - "google.golang.org/protobuf/reflect/protoreflect" - "google.golang.org/protobuf/types/known/timestamppb" -) - -type timestampType struct{} - -func (t timestampType) NewValue(*context.Context, *Builder) Value { - return ×tampValue{} -} - -func (t timestampType) DefaultValue() string { - return "" -} - -type timestampValue struct { - value *timestamppb.Timestamp -} - -func (t timestampValue) Get(protoreflect.Value) (protoreflect.Value, error) { - if t.value == nil { - return protoreflect.Value{}, nil - } - return protoreflect.ValueOfMessage(t.value.ProtoReflect()), nil -} - -func (t timestampValue) String() string { - if t.value == nil { - return "" - } - return t.value.AsTime().Format(time.RFC3339) -} - -func (t *timestampValue) Set(s string) error { - time, err := time.Parse(time.RFC3339, s) - if err != nil { - return err - } - t.value = timestamppb.New(time) - return nil -} - -func (t timestampValue) Type() string { - return "timestamp (RFC 3339)" -} diff --git a/connect/internal/autocli/keyring/adapter.go b/connect/internal/autocli/keyring/adapter.go deleted file mode 100644 index 48def0df..00000000 --- a/connect/internal/autocli/keyring/adapter.go +++ /dev/null @@ -1,119 +0,0 @@ -package keyring - -import ( - signingv1beta1 "cosmossdk.io/api/cosmos/tx/signing/v1beta1" - "cosmossdk.io/core/address" - - "github.com/cosmos/cosmos-sdk/crypto/keyring" - cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/tx/signing" -) - -// NewAutoCLIKeyring wraps the SDK keyring and make it compatible with the AutoCLI keyring interfaces. -func NewAutoCLIKeyring(kr keyring.Keyring, ac address.Codec) (Keyring, error) { - return &autoCLIKeyringAdapter{kr, ac}, nil -} - -type autoCLIKeyringAdapter struct { - keyring.Keyring - ac address.Codec -} - -func (a *autoCLIKeyringAdapter) DefaultKey() string { - l, err := a.List() - if err != nil || len(l) == 0 { - return "" - } - - return l[0] -} - -func (a *autoCLIKeyringAdapter) List() ([]string, error) { - list, err := a.Keyring.List() - if err != nil { - return nil, err - } - - names := make([]string, len(list)) - for i, key := range list { - names[i] = key.Name - } - - return names, nil -} - -// LookupAddressByKeyName returns the address of a key stored in the keyring -func (a *autoCLIKeyringAdapter) LookupAddressByKeyName(name string) ([]byte, error) { - record, err := a.Keyring.Key(name) - if err != nil { - return nil, err - } - - addr, err := record.GetAddress() - if err != nil { - return nil, err - } - - return addr, nil -} - -func (a *autoCLIKeyringAdapter) GetPubKey(name string) (cryptotypes.PubKey, error) { - record, err := a.Keyring.Key(name) - if err != nil { - return nil, err - } - - return record.GetPubKey() -} - -func (a *autoCLIKeyringAdapter) Sign(name string, msg []byte, signMode signingv1beta1.SignMode) ([]byte, error) { - record, err := a.Keyring.Key(name) - if err != nil { - return nil, err - } - - signBytes, _, err := a.Keyring.Sign(record.Name, msg, signing.SignMode(signMode)) - return signBytes, err -} - -func (a *autoCLIKeyringAdapter) KeyType(name string) (uint, error) { - record, err := a.Keyring.Key(name) - if err != nil { - return 0, err - } - - return uint(record.GetType()), nil -} - -func (a *autoCLIKeyringAdapter) KeyInfo(nameOrAddr string) (string, string, uint, error) { - addr, err := a.ac.StringToBytes(nameOrAddr) - if err != nil { - // If conversion fails, it's likely a name, not an address - record, err := a.Keyring.Key(nameOrAddr) - if err != nil { - return "", "", 0, err - } - addr, err = record.GetAddress() - if err != nil { - return "", "", 0, err - } - addrStr, err := a.ac.BytesToString(addr) - if err != nil { - return "", "", 0, err - } - return record.Name, addrStr, uint(record.GetType()), nil - } - - // If conversion succeeds, it's an address, get the key info by address - record, err := a.Keyring.KeyByAddress(sdk.AccAddress(addr)) - if err != nil { - return "", "", 0, err - } - - return record.Name, nameOrAddr, uint(record.GetType()), nil -} - -func (a *autoCLIKeyringAdapter) Impl() any { - return a.Keyring -} diff --git a/connect/internal/autocli/keyring/interface.go b/connect/internal/autocli/keyring/interface.go deleted file mode 100644 index a8ca2ce4..00000000 --- a/connect/internal/autocli/keyring/interface.go +++ /dev/null @@ -1,32 +0,0 @@ -package keyring - -import ( - signingv1beta1 "cosmossdk.io/api/cosmos/tx/signing/v1beta1" - - cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" -) - -// Keyring is an interface used for signing transactions. -// It aims to be simplistic and easy to use. -type Keyring interface { - // DefaultKey returns the default key name. - DefaultKey() string - - // List returns the names of all keys stored in the keyring. - List() ([]string, error) - - // LookupAddressByKeyName returns the address of the key with the given name. - LookupAddressByKeyName(name string) ([]byte, error) - - // GetPubKey returns the public key of the key with the given name. - GetPubKey(name string) (cryptotypes.PubKey, error) - - // Sign signs the given bytes with the key with the given name. - Sign(name string, msg []byte, signMode signingv1beta1.SignMode) ([]byte, error) - - // KeyInfo given a key name or address returns key name, key address and key type. - KeyInfo(nameOrAddr string) (string, string, uint, error) - - // Impl returns the underlying keyring implementation. - Impl() any -} diff --git a/connect/internal/autocli/keyring/no_keyring.go b/connect/internal/autocli/keyring/no_keyring.go deleted file mode 100644 index 8cabca45..00000000 --- a/connect/internal/autocli/keyring/no_keyring.go +++ /dev/null @@ -1,43 +0,0 @@ -package keyring - -import ( - "errors" - - signingv1beta1 "cosmossdk.io/api/cosmos/tx/signing/v1beta1" - - cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" -) - -var _ Keyring = NoKeyring{} - -var errNoKeyring = errors.New("no keyring configured") - -type NoKeyring struct{} - -func (k NoKeyring) DefaultKey() string { - return "" -} - -func (k NoKeyring) List() ([]string, error) { - return nil, errNoKeyring -} - -func (k NoKeyring) LookupAddressByKeyName(name string) ([]byte, error) { - return nil, errNoKeyring -} - -func (k NoKeyring) GetPubKey(name string) (cryptotypes.PubKey, error) { - return nil, errNoKeyring -} - -func (k NoKeyring) Sign(name string, msg []byte, signMode signingv1beta1.SignMode) ([]byte, error) { - return nil, errNoKeyring -} - -func (k NoKeyring) KeyInfo(nameOrAddr string) (string, string, uint, error) { - return "", "", 0, errNoKeyring -} - -func (k NoKeyring) Impl() any { - return nil -} diff --git a/connect/internal/autocli/msg.go b/connect/internal/autocli/msg.go deleted file mode 100644 index 717b969f..00000000 --- a/connect/internal/autocli/msg.go +++ /dev/null @@ -1,243 +0,0 @@ -package autocli - -import ( - "context" - "fmt" - - "github.com/spf13/cobra" - "google.golang.org/protobuf/proto" - "google.golang.org/protobuf/reflect/protoreflect" - "google.golang.org/protobuf/types/dynamicpb" - - autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" - addresscodec "cosmossdk.io/core/address" - "github.com/ignite/apps/connect/internal/autocli/flag" - "github.com/ignite/apps/connect/internal/flags" - "github.com/ignite/apps/connect/internal/governance" - "github.com/ignite/apps/connect/internal/tx" - "github.com/ignite/apps/connect/internal/util" - - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" -) - -// BuildMsgCommand builds the msg commands for all the provided modules. -func (b *Builder) BuildMsgCommand(ctx context.Context, moduleOptions map[string]*autocliv1.ModuleOptions) (*cobra.Command, error) { - msgCmd := topLevelCmd(ctx, "tx", "Transaction subcommands") - - if err := b.enhanceCommandCommon(msgCmd, msgCmdType, moduleOptions); err != nil { - return nil, err - } - - return msgCmd, nil -} - -// AddMsgServiceCommands adds a sub-command to the provided command for each -// method in the specified service and returns the command. This can be used in -// order to add auto-generated commands to an existing command. -func (b *Builder) AddMsgServiceCommands(cmd *cobra.Command, cmdDescriptor *autocliv1.ServiceCommandDescriptor) error { - for cmdName, subCmdDescriptor := range cmdDescriptor.SubCommands { - subCmd := findSubCommand(cmd, cmdName) - if subCmd == nil { - short := subCmdDescriptor.Short - if short == "" { - short = fmt.Sprintf("Tx commands for the %s service", subCmdDescriptor.Service) - } - subCmd = topLevelCmd(cmd.Context(), cmdName, short) - } - - // Add recursive sub-commands if there are any. This is used for nested services. - if err := b.AddMsgServiceCommands(subCmd, subCmdDescriptor); err != nil { - return err - } - - if !subCmdDescriptor.EnhanceCustomCommand { - cmd.AddCommand(subCmd) - } - } - - if cmdDescriptor.Service == "" { - // skip empty command descriptor - return nil - } - - descriptor, err := b.FileResolver.FindDescriptorByName(protoreflect.FullName(cmdDescriptor.Service)) - if err != nil { - return fmt.Errorf("can't find service %s: %w", cmdDescriptor.Service, err) - } - service := descriptor.(protoreflect.ServiceDescriptor) - methods := service.Methods() - - rpcOptMap := map[protoreflect.Name]*autocliv1.RpcCommandOptions{} - for _, option := range cmdDescriptor.RpcCommandOptions { - methodName := protoreflect.Name(option.RpcMethod) - // validate that methods exist - if m := methods.ByName(methodName); m == nil { - return fmt.Errorf("rpc method %q not found for service %q", methodName, service.FullName()) - } - rpcOptMap[methodName] = option - - } - - for i := 0; i < methods.Len(); i++ { - methodDescriptor := methods.Get(i) - methodOpts, ok := rpcOptMap[methodDescriptor.Name()] - if !ok { - methodOpts = &autocliv1.RpcCommandOptions{} - } - - if methodOpts.Skip { - continue - } - - if !util.IsSupportedVersion(methodDescriptor) { - continue - } - - methodCmd, err := b.BuildMsgMethodCommand(methodDescriptor, methodOpts) - if err != nil { - return err - } - - if findSubCommand(cmd, methodCmd.Name()) != nil { - // do not overwrite existing commands - // we do not display a warning because you may want to overwrite an autocli command - continue - } - - cmd.AddCommand(methodCmd) - } - - return nil -} - -// BuildMsgMethodCommand returns a command that outputs the JSON representation of the message. -func (b *Builder) BuildMsgMethodCommand(descriptor protoreflect.MethodDescriptor, options *autocliv1.RpcCommandOptions) (*cobra.Command, error) { - execFunc := func(cmd *cobra.Command, input protoreflect.Message) error { - fd := input.Descriptor().Fields().ByName(protoreflect.Name(flag.GetSignerFieldName(input.Descriptor()))) - addressCodec := b.Builder.AddressCodec - - // handle gov proposals commands - skipProposal, _ := cmd.Flags().GetBool(flags.FlagNoProposal) - if isProposalMessage(descriptor.Input()) && !skipProposal { - return b.handleGovProposal(cmd, input, addressCodec, fd) - } - - // set signer to signer field if empty - if addr := input.Get(fd).String(); addr == "" { - scalarType, ok := flag.GetScalarType(fd) - if ok { - // override address codec if validator or consensus address - switch scalarType { - case flag.ValidatorAddressStringScalarType: - addressCodec = b.Builder.ValidatorAddressCodec - case flag.ConsensusAddressStringScalarType: - addressCodec = b.Builder.ConsensusAddressCodec - } - } - - signer, err := tx.GetFromAddress(cmd, addressCodec) - if err != nil { - return fmt.Errorf("failed to get from address: %w", err) - } - - input.Set(fd, protoreflect.ValueOfString(signer)) - } - - // AutoCLI uses protov2 messages, while the SDK only supports proto v1 messages. - // Here we use dynamicpb, to create a proto v1 compatible message. - // The SDK codec will handle protov2 -> protov1 (marshal) - msg := dynamicpb.NewMessage(input.Descriptor()) - proto.Merge(msg, input.Interface()) - - out, err := tx.GenerateAndBroadcastTxCLI(cmd.Context(), nil /* TODO */, msg) - if err != nil { - return err - } - - return b.outOrStdoutFormat(cmd, out) - } - - cmd, err := b.buildMethodCommandCommon(descriptor, options, execFunc) - if err != nil { - return nil, err - } - - if b.AddTxConnFlags != nil { - b.AddTxConnFlags(cmd) - } - - // silence usage only for inner txs & queries commands - cmd.SilenceUsage = true - - // set gov proposal flags if command is a gov proposal - if isProposalMessage(descriptor.Input()) { - governance.AddGovPropFlagsToCmd(cmd) - cmd.Flags().Bool(flags.FlagNoProposal, false, "Skip gov proposal and submit a normal transaction") - } - - return cmd, nil -} - -// handleGovProposal sets the authority field of the message to the gov module address and creates a gov proposal. -func (b *Builder) handleGovProposal( - cmd *cobra.Command, - input protoreflect.Message, - addressCodec addresscodec.Codec, - fd protoreflect.FieldDescriptor, -) error { - govAuthority := authtypes.NewModuleAddress(governance.ModuleName) - authority, err := addressCodec.BytesToString(govAuthority.Bytes()) - if err != nil { - return fmt.Errorf("failed to convert gov authority: %w", err) - } - input.Set(fd, protoreflect.ValueOfString(authority)) - - signerFromFlag, err := tx.GetFromAddress(cmd, addressCodec) - if err != nil { - return fmt.Errorf("failed to get from address: %w", err) - } - - proposal, err := governance.ReadGovPropCmdFlags(signerFromFlag, cmd.Flags()) - if err != nil { - return err - } - - // AutoCLI uses protov2 messages, while the SDK only supports proto v1 messages. - // Here we use dynamicpb, to create a proto v1 compatible message. - // The SDK codec will handle protov2 -> protov1 (marshal) - msg := dynamicpb.NewMessage(input.Descriptor()) - proto.Merge(msg, input.Interface()) - - if err := governance.SetGovMsgs(proposal, msg); err != nil { - return fmt.Errorf("failed to set msg in proposal %w", err) - } - - out, err := tx.GenerateAndBroadcastTxCLI(cmd.Context(), nil /* TODO */, proposal) - if err != nil { - return err - } - - return b.outOrStdoutFormat(cmd, out) -} - -// isProposalMessage checks the msg name against well known proposal messages. -// this isn't exhaustive. to have it better we need to add a field in autocli proto -// as it was done in v0.52. -func isProposalMessage(_ protoreflect.MessageDescriptor) bool { - // msg := []string{ - // "cosmos.gov.v1.MsgSubmitProposal", - // "cosmos.upgrade.v1beta1.MsgSoftwareUpgrade", - // "cosmos.upgrade.v1beta1.MsgCancelUpgrade", - // "cosmos.distribution.v1beta1.MsgFundCommunityPool", - // "ibc.core.client.v1.MsgIBCSoftwareUpgrade", - // ".MsgUpdateParams", - // } - - // for _, m := range msg { - // if strings.HasSuffix(string(desc.FullName()), m) { - // return true - // } - // } - - return false -} diff --git a/connect/internal/autocli/msg_test.go b/connect/internal/autocli/msg_test.go deleted file mode 100644 index 751219cb..00000000 --- a/connect/internal/autocli/msg_test.go +++ /dev/null @@ -1,259 +0,0 @@ -package autocli - -import ( - "bytes" - "context" - "encoding/json" - "fmt" - "os" - "path/filepath" - "testing" - - "github.com/spf13/cobra" - "gotest.tools/v3/assert" - "gotest.tools/v3/golden" - - autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" - bankv1beta1 "cosmossdk.io/api/cosmos/bank/v1beta1" - "github.com/ignite/apps/connect/internal/testpb" -) - -var buildModuleMsgCommand = func(moduleName string, f *fixture) (*cobra.Command, error) { - ctx := context.TODO() - cmd := topLevelCmd(ctx, moduleName, fmt.Sprintf("Transactions commands for the %s module", moduleName)) - err := f.b.AddMsgServiceCommands(cmd, bankAutoCLI) - return cmd, err -} - -func buildCustomModuleMsgCommand(cmdDescriptor *autocliv1.ServiceCommandDescriptor) func(moduleName string, f *fixture) (*cobra.Command, error) { - return func(moduleName string, f *fixture) (*cobra.Command, error) { - ctx := context.TODO() - cmd := topLevelCmd(ctx, moduleName, fmt.Sprintf("Transactions commands for the %s module", moduleName)) - err := f.b.AddMsgServiceCommands(cmd, cmdDescriptor) - return cmd, err - } -} - -var bankAutoCLI = &autocliv1.ServiceCommandDescriptor{ - Service: bankv1beta1.Msg_ServiceDesc.ServiceName, - RpcCommandOptions: []*autocliv1.RpcCommandOptions{ - { - RpcMethod: "Send", - Use: "send [flags]", - Short: "Send coins from one account to another", - PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "from_address"}, {ProtoField: "to_address"}, {ProtoField: "amount"}}, - }, - }, - EnhanceCustomCommand: true, -} - -func TestMsg(t *testing.T) { - fixture := initFixture(t) - out, err := runCmd(fixture, buildModuleMsgCommand, "send", - "cosmos1y74p8wyy4enfhfn342njve6cjmj5c8dtl6emdk", "cosmos1y74p8wyy4enfhfn342njve6cjmj5c8dtl6emdk", "1foo", - "--generate-only", - "--output", "json", - "--chain-id", fixture.chainID, - ) - assert.NilError(t, err) - assertNormalizedJSONEqual(t, out.Bytes(), goldenLoad(t, "msg-output.golden")) - - out, err = runCmd(fixture, buildCustomModuleMsgCommand(&autocliv1.ServiceCommandDescriptor{ - Service: bankv1beta1.Msg_ServiceDesc.ServiceName, - RpcCommandOptions: []*autocliv1.RpcCommandOptions{ - { - RpcMethod: "Send", - Use: "send [flags]", - Short: "Send coins from one account to another", - PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "from_address"}, {ProtoField: "to_address"}, {ProtoField: "amount"}}, - }, - }, - EnhanceCustomCommand: true, - }), "send", - "cosmos1y74p8wyy4enfhfn342njve6cjmj5c8dtl6emdk", "cosmos1y74p8wyy4enfhfn342njve6cjmj5c8dtl6emdk", "1foo", - "--generate-only", - "--output", "json", - "--chain-id", fixture.chainID, - ) - assert.NilError(t, err) - assertNormalizedJSONEqual(t, out.Bytes(), goldenLoad(t, "msg-output.golden")) - - out, err = runCmd(fixture, buildCustomModuleMsgCommand(&autocliv1.ServiceCommandDescriptor{ - Service: bankv1beta1.Msg_ServiceDesc.ServiceName, - RpcCommandOptions: []*autocliv1.RpcCommandOptions{ - { - RpcMethod: "Send", - Use: "send [flags]", - Short: "Send coins from one account to another", - PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "to_address"}, {ProtoField: "amount"}}, - // from_address should be automatically added - }, - }, - EnhanceCustomCommand: true, - }), "send", - "cosmos1y74p8wyy4enfhfn342njve6cjmj5c8dtl6emdk", "1foo", - "--from", "cosmos1y74p8wyy4enfhfn342njve6cjmj5c8dtl6emdk", - "--output", "json", - "--generate-only", - "--chain-id", fixture.chainID, - "--keyring-backend", fixture.kBackend, - ) - assert.NilError(t, err) - assertNormalizedJSONEqual(t, out.Bytes(), goldenLoad(t, "msg-output.golden")) - - out, err = runCmd(fixture, buildCustomModuleMsgCommand(&autocliv1.ServiceCommandDescriptor{ - Service: bankv1beta1.Msg_ServiceDesc.ServiceName, - RpcCommandOptions: []*autocliv1.RpcCommandOptions{ - { - RpcMethod: "Send", - Use: "send [flags]", - Short: "Send coins from one account to another", - PositionalArgs: []*autocliv1.PositionalArgDescriptor{{ProtoField: "to_address"}, {ProtoField: "amount"}}, - FlagOptions: map[string]*autocliv1.FlagOptions{ - "from_address": {Name: "sender"}, // use a custom flag for signer - }, - }, - }, - EnhanceCustomCommand: true, - }), "send", - "cosmos1y74p8wyy4enfhfn342njve6cjmj5c8dtl6emdk", "1foo", - "--sender", "cosmos1y74p8wyy4enfhfn342njve6cjmj5c8dtl6emdk", - "--output", "json", - "--generate-only", - "--chain-id", fixture.chainID, - ) - assert.NilError(t, err) - assertNormalizedJSONEqual(t, out.Bytes(), goldenLoad(t, "msg-output.golden")) -} - -func TestMsgWithFlattenFields(t *testing.T) { - fixture := initFixture(t) - - out, err := runCmd(fixture, buildCustomModuleMsgCommand(&autocliv1.ServiceCommandDescriptor{ - Service: bankv1beta1.Msg_ServiceDesc.ServiceName, - RpcCommandOptions: []*autocliv1.RpcCommandOptions{ - { - RpcMethod: "UpdateParams", - PositionalArgs: []*autocliv1.PositionalArgDescriptor{ - {ProtoField: "authority"}, - {ProtoField: "params.send_enabled.denom"}, - {ProtoField: "params.send_enabled.enabled"}, - {ProtoField: "params.default_send_enabled"}, - }, - }, - }, - EnhanceCustomCommand: true, - }), "update-params", - "cosmos1y74p8wyy4enfhfn342njve6cjmj5c8dtl6emdk", "stake", "true", "true", - "--generate-only", - "--output", "json", - "--chain-id", fixture.chainID, - "--no-proposal", - ) - assert.NilError(t, err) - assertNormalizedJSONEqual(t, out.Bytes(), goldenLoad(t, "flatten-output.golden")) -} - -func goldenLoad(t *testing.T, filename string) []byte { - t.Helper() - content, err := os.ReadFile(filepath.Join("testdata", filename)) - assert.NilError(t, err) - return content -} - -func assertNormalizedJSONEqual(t *testing.T, expected, actual []byte) { - t.Helper() - normalizedExpected, err := normalizeJSON(expected) - assert.NilError(t, err) - normalizedActual, err := normalizeJSON(actual) - assert.NilError(t, err) - assert.Equal(t, string(normalizedExpected), string(normalizedActual)) -} - -// normalizeJSON normalizes the JSON content by removing unnecessary white spaces and newlines. -func normalizeJSON(content []byte) ([]byte, error) { - var buf bytes.Buffer - err := json.Compact(&buf, content) - if err != nil { - return nil, err - } - return buf.Bytes(), nil -} - -func TestMsgOptionsError(t *testing.T) { - fixture := initFixture(t) - - _, err := runCmd(fixture, buildModuleMsgCommand, - "send", "5", - ) - assert.ErrorContains(t, err, "accepts 3 arg(s)") - - _, err = runCmd(fixture, buildModuleMsgCommand, - "send", "foo", "bar", "invalid", - ) - assert.ErrorContains(t, err, "invalid argument") -} - -func TestHelpMsg(t *testing.T) { - fixture := initFixture(t) - - out, err := runCmd(fixture, buildModuleMsgCommand, "-h") - assert.NilError(t, err) - golden.Assert(t, out.String(), "help-toplevel-msg.golden") - - out, err = runCmd(fixture, buildModuleMsgCommand, "send", "-h") - assert.NilError(t, err) - golden.Assert(t, out.String(), "help-echo-msg.golden") -} - -func TestNotFoundErrorsMsg(t *testing.T) { - fixture := initFixture(t) - b := fixture.b - b.AddQueryConnFlags = nil - b.AddTxConnFlags = nil - - buildModuleMsgCommand := func(moduleName string, cmdDescriptor *autocliv1.ServiceCommandDescriptor) (*cobra.Command, error) { - cmd := topLevelCmd(context.Background(), moduleName, fmt.Sprintf("Transactions commands for the %s module", moduleName)) - - err := b.AddMsgServiceCommands(cmd, cmdDescriptor) - return cmd, err - } - - // Query non existent service - _, err := buildModuleMsgCommand("test", &autocliv1.ServiceCommandDescriptor{Service: "un-existent-service"}) - assert.ErrorContains(t, err, "can't find service un-existent-service") - - _, err = buildModuleMsgCommand("test", &autocliv1.ServiceCommandDescriptor{ - Service: testpb.Query_ServiceDesc.ServiceName, - RpcCommandOptions: []*autocliv1.RpcCommandOptions{{RpcMethod: "un-existent-method"}}, - }) - assert.ErrorContains(t, err, "rpc method \"un-existent-method\" not found") - - _, err = buildModuleMsgCommand("test", &autocliv1.ServiceCommandDescriptor{ - Service: testpb.Msg_ServiceDesc.ServiceName, - RpcCommandOptions: []*autocliv1.RpcCommandOptions{ - { - RpcMethod: "Send", - PositionalArgs: []*autocliv1.PositionalArgDescriptor{ - { - ProtoField: "un-existent-proto-field", - }, - }, - }, - }, - }) - assert.ErrorContains(t, err, "can't find field un-existent-proto-field") - - _, err = buildModuleMsgCommand("test", &autocliv1.ServiceCommandDescriptor{ - Service: testpb.Msg_ServiceDesc.ServiceName, - RpcCommandOptions: []*autocliv1.RpcCommandOptions{ - { - RpcMethod: "Send", - FlagOptions: map[string]*autocliv1.FlagOptions{ - "un-existent-flag": {}, - }, - }, - }, - }) - assert.ErrorContains(t, err, "can't find field un-existent-flag") -} diff --git a/connect/internal/autocli/prompt/message.go b/connect/internal/autocli/prompt/message.go deleted file mode 100644 index 2bd73a33..00000000 --- a/connect/internal/autocli/prompt/message.go +++ /dev/null @@ -1,259 +0,0 @@ -package prompt - -import ( - "fmt" - "io" - "strconv" - "strings" - - "github.com/manifoldco/promptui" - "google.golang.org/protobuf/reflect/protoreflect" - - addresscodec "cosmossdk.io/core/address" - "github.com/ignite/apps/connect/internal/autocli/flag" -) - -// PromptMessage prompts the user for values to populate a protobuf message interactively. -// It returns the populated message and any error encountered during prompting. -func PromptMessage( - addressCodec, validatorAddressCodec, consensusAddressCodec addresscodec.Codec, - promptPrefix string, msg protoreflect.Message, -) (protoreflect.Message, error) { - return promptMessage(addressCodec, validatorAddressCodec, consensusAddressCodec, promptPrefix, nil, msg) -} - -// promptMessage prompts the user for values to populate a protobuf message interactively. -// stdIn is provided to make the function easier to unit test by allowing injection of predefined inputs. -func promptMessage( - addressCodec, validatorAddressCodec, consensusAddressCodec addresscodec.Codec, - promptPrefix string, stdIn io.ReadCloser, msg protoreflect.Message, -) (protoreflect.Message, error) { - fields := msg.Descriptor().Fields() - for i := 0; i < fields.Len(); i++ { - field := fields.Get(i) - fieldName := string(field.Name()) - - promptUi := promptui.Prompt{ - Validate: ValidatePromptNotEmpty, - Stdin: stdIn, - } - - // If this signer field has already a valid default value set, - // use that value as the default prompt value. This is useful for - // commands that have an authority such as gov. - if strings.EqualFold(fieldName, flag.GetSignerFieldName(msg.Descriptor())) { - if defaultValue := msg.Get(field); defaultValue.IsValid() { - promptUi.Default = defaultValue.String() - } - } - - // validate address fields - scalarField, ok := flag.GetScalarType(field) - if ok { - switch scalarField { - case flag.AddressStringScalarType: - promptUi.Validate = ValidateAddress(addressCodec) - case flag.ValidatorAddressStringScalarType: - promptUi.Validate = ValidateAddress(validatorAddressCodec) - case flag.ConsensusAddressStringScalarType: - promptUi.Validate = ValidateAddress(consensusAddressCodec) - default: - // prompt.Validate = ValidatePromptNotEmpty (we possibly don't want to force all fields to be non-empty) - promptUi.Validate = nil - } - } - - // handle nested message fields recursively - if field.Kind() == protoreflect.MessageKind { - err := promptInnerMessageKind(field, addressCodec, validatorAddressCodec, consensusAddressCodec, promptPrefix, stdIn, msg) - if err != nil { - return nil, err - } - continue - } - - // handle repeated fields by prompting for a comma-separated list of values - if field.IsList() { - list, err := promptList(field, msg, promptUi, promptPrefix) - if err != nil { - return nil, err - } - - msg.Set(field, protoreflect.ValueOfList(list)) - continue - } - - promptUi.Label = fmt.Sprintf("Enter %s %s", promptPrefix, fieldName) - result, err := promptUi.Run() - if err != nil { - return msg, fmt.Errorf("failed to prompt for %s: %w", fieldName, err) - } - - v, err := valueOf(field, result) - if err != nil { - return msg, err - } - msg.Set(field, v) - } - - return msg, nil -} - -// valueOf converts a string input value to a protoreflect.Value based on the field's type. -// It handles string, numeric, bool, bytes and enum field types. -// Returns the converted value and any error that occurred during conversion. -func valueOf(field protoreflect.FieldDescriptor, result string) (protoreflect.Value, error) { - switch field.Kind() { - case protoreflect.StringKind: - return protoreflect.ValueOfString(result), nil - case protoreflect.Uint32Kind, protoreflect.Fixed32Kind, protoreflect.Uint64Kind, protoreflect.Fixed64Kind: - resultUint, err := strconv.ParseUint(result, 10, 0) - if err != nil { - return protoreflect.Value{}, fmt.Errorf("invalid value for int: %w", err) - } - - return protoreflect.ValueOfUint64(resultUint), nil - case protoreflect.Int32Kind, protoreflect.Sint32Kind, protoreflect.Sfixed32Kind, protoreflect.Int64Kind, protoreflect.Sint64Kind, protoreflect.Sfixed64Kind: - resultInt, err := strconv.ParseInt(result, 10, 0) - if err != nil { - return protoreflect.Value{}, fmt.Errorf("invalid value for int: %w", err) - } - // If a value was successfully parsed the ranges of: - // [minInt, maxInt] - // are within the ranges of: - // [minInt64, maxInt64] - // of which on 64-bit machines, which are most common, - // int==int64 - return protoreflect.ValueOfInt64(resultInt), nil - case protoreflect.BoolKind: - resultBool, err := strconv.ParseBool(result) - if err != nil { - return protoreflect.Value{}, fmt.Errorf("invalid value for bool: %w", err) - } - - return protoreflect.ValueOfBool(resultBool), nil - case protoreflect.BytesKind: - resultBytes := []byte(result) - return protoreflect.ValueOfBytes(resultBytes), nil - case protoreflect.EnumKind: - enumValue := field.Enum().Values().ByName(protoreflect.Name(result)) - if enumValue == nil { - return protoreflect.Value{}, fmt.Errorf("invalid enum value %q", result) - } - return protoreflect.ValueOfEnum(enumValue.Number()), nil - default: - // TODO: add more kinds - // skip any other types - return protoreflect.Value{}, nil - } -} - -// promptList prompts the user for a comma-separated list of values for a repeated field. -// The user will be prompted to enter values separated by commas which will be parsed -// according to the field's type using valueOf. -func promptList(field protoreflect.FieldDescriptor, msg protoreflect.Message, promptUi promptui.Prompt, promptPrefix string) (protoreflect.List, error) { - promptUi.Label = fmt.Sprintf("Enter %s %s list (separate values with ',')", promptPrefix, string(field.Name())) - result, err := promptUi.Run() - if err != nil { - return nil, fmt.Errorf("failed to prompt for %s: %w", string(field.Name()), err) - } - - list := msg.Mutable(field).List() - for _, item := range strings.Split(result, ",") { - v, err := valueOf(field, item) - if err != nil { - return nil, err - } - list.Append(v) - } - - return list, nil -} - -// promptInnerMessageKind handles prompting for fields that are of message kind. -// It handles both single messages and repeated message fields by delegating to -// promptInnerMessage and promptMessageList respectively. -func promptInnerMessageKind( - f protoreflect.FieldDescriptor, addressCodec addresscodec.Codec, - validatorAddressCodec, consensusAddressCodec addresscodec.Codec, - promptPrefix string, stdIn io.ReadCloser, msg protoreflect.Message, -) error { - if f.IsList() { - return promptMessageList(f, addressCodec, validatorAddressCodec, consensusAddressCodec, promptPrefix, stdIn, msg) - } - return promptInnerMessage(f, addressCodec, validatorAddressCodec, consensusAddressCodec, promptPrefix, stdIn, msg) -} - -// promptInnerMessage prompts for a single nested message field. It creates a new message instance, -// recursively prompts for its fields, and sets the populated message on the parent message. -func promptInnerMessage( - f protoreflect.FieldDescriptor, addressCodec addresscodec.Codec, - validatorAddressCodec, consensusAddressCodec addresscodec.Codec, - promptPrefix string, stdIn io.ReadCloser, msg protoreflect.Message, -) error { - fieldName := promptPrefix + "." + string(f.Name()) - nestedMsg := msg.Get(f).Message() - nestedMsg = nestedMsg.New() - // Recursively prompt for nested message fields - updatedMsg, err := promptMessage( - addressCodec, - validatorAddressCodec, - consensusAddressCodec, - fieldName, - stdIn, - nestedMsg, - ) - if err != nil { - return fmt.Errorf("failed to prompt for nested message %s: %w", fieldName, err) - } - - msg.Set(f, protoreflect.ValueOfMessage(updatedMsg)) - return nil -} - -// promptMessageList prompts for a repeated message field by repeatedly creating new message instances, -// prompting for their fields, and appending them to the list until the user chooses to stop. -func promptMessageList( - f protoreflect.FieldDescriptor, addressCodec addresscodec.Codec, - validatorAddressCodec, consensusAddressCodec addresscodec.Codec, - promptPrefix string, stdIn io.ReadCloser, msg protoreflect.Message, -) error { - list := msg.Mutable(f).List() - for { - fieldName := promptPrefix + "." + string(f.Name()) - // Create and populate a new message for the list - nestedMsg := list.NewElement().Message() - updatedMsg, err := promptMessage( - addressCodec, - validatorAddressCodec, - consensusAddressCodec, - fieldName, - stdIn, - nestedMsg, - ) - if err != nil { - return fmt.Errorf("failed to prompt for list item in %s: %w", fieldName, err) - } - - list.Append(protoreflect.ValueOfMessage(updatedMsg)) - - // Prompt whether to continue - // TODO: may be better yes/no rather than interactive? - continuePrompt := promptui.Select{ - Label: "Add another item?", - Items: []string{"No", "Yes"}, - Stdin: stdIn, - } - - _, result, err := continuePrompt.Run() - if err != nil { - return fmt.Errorf("failed to prompt for continuation: %w", err) - } - - if result == "No" { - break - } - } - - return nil -} diff --git a/connect/internal/autocli/prompt/message_test.go b/connect/internal/autocli/prompt/message_test.go deleted file mode 100644 index b3886845..00000000 --- a/connect/internal/autocli/prompt/message_test.go +++ /dev/null @@ -1,59 +0,0 @@ -package prompt - -import ( - "io" - "strings" - "testing" - - "github.com/stretchr/testify/require" - "google.golang.org/protobuf/reflect/protoreflect" - - "github.com/ignite/apps/connect/internal/testpb" - - address2 "github.com/cosmos/cosmos-sdk/codec/address" -) - -func getReader(inputs []string) io.ReadCloser { - // https://github.com/manifoldco/promptui/issues/63#issuecomment-621118463 - var paddedInputs []string - for _, input := range inputs { - padding := strings.Repeat("a", 4096-1-len(input)%4096) - paddedInputs = append(paddedInputs, input+"\n"+padding) - } - return io.NopCloser(strings.NewReader(strings.Join(paddedInputs, ""))) -} - -func TestPromptMessage(t *testing.T) { - tests := []struct { - name string - msg protoreflect.Message - inputs []string - }{ - { - name: "testPb", - inputs: []string{ - "1", "2", "string", "bytes", "10101010", "0", "234234", "3", "4", "5", "true", "ENUM_ONE", - "bar", "6", "10000", "stake", "cosmos10d07y265gmmuvt4z0w9aw880jnsr700j6zn9kn", - "bytes", "6", "7", "false", "false", "true,false,true", "1,2,3", "hello,hola,ciao", "ENUM_ONE,ENUM_TWO", - "10239", "0", "No", "bar", "343", "No", "134", "positional2", "23455", "stake", "No", "deprecate", - "shorthand", "false", "cosmosvaloper1tnh2q55v8wyygtt9srz5safamzdengsn9dsd7z", - }, - msg: (&testpb.MsgRequest{}).ProtoReflect(), - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - // https://github.com/manifoldco/promptui/issues/63#issuecomment-621118463 - var paddedInputs []string - for _, input := range tt.inputs { - padding := strings.Repeat("a", 4096-1-len(input)%4096) - paddedInputs = append(paddedInputs, input+"\n"+padding) - } - reader := io.NopCloser(strings.NewReader(strings.Join(paddedInputs, ""))) - - got, err := promptMessage(address2.NewBech32Codec("cosmos"), address2.NewBech32Codec("cosmosvaloper"), address2.NewBech32Codec("cosmosvalcons"), "prefix", reader, tt.msg) - require.NoError(t, err) - require.NotNil(t, got) - }) - } -} diff --git a/connect/internal/autocli/prompt/struct.go b/connect/internal/autocli/prompt/struct.go deleted file mode 100644 index a450b5a6..00000000 --- a/connect/internal/autocli/prompt/struct.go +++ /dev/null @@ -1,134 +0,0 @@ -package prompt - -import ( - "fmt" - "io" - "reflect" - "strconv" - "strings" - - "github.com/manifoldco/promptui" -) - -// PromptStruct prompts for values of a struct's fields interactively. -// It returns the populated struct and any error encountered. -func PromptStruct[T any](promptPrefix string, data T) (T, error) { - return promptStruct(promptPrefix, data, nil) -} - -// promptStruct prompts for values of a struct's fields interactively. -// -// For each field in the struct: -// - Pointer fields are initialized if nil and handled recursively if they contain structs -// - Struct fields are handled recursively -// - String and int slices are supported -// - String and int fields are prompted for and populated -// - Only String and int pointers are supported -// - Other types are skipped -func promptStruct[T any](promptPrefix string, data T, stdIn io.ReadCloser) (T, error) { - v := reflect.ValueOf(&data).Elem() - if v.Kind() == reflect.Interface { - v = reflect.ValueOf(data) - if v.Kind() == reflect.Ptr { - v = v.Elem() - } - } - - for i := 0; i < v.NumField(); i++ { - field := v.Field(i) - fieldName := strings.ToLower(v.Type().Field(i).Name) - - // Handle pointer types - if field.Kind() == reflect.Ptr { - if field.IsNil() { - field.Set(reflect.New(field.Type().Elem())) - } - if field.Elem().Kind() == reflect.Struct { - result, err := promptStruct(promptPrefix+"."+fieldName, field.Interface(), stdIn) - if err != nil { - return data, err - } - field.Set(reflect.ValueOf(result)) - continue - } - } - - switch field.Kind() { - case reflect.Struct: - // For struct fields, create a new pointer to handle them - structPtr := reflect.New(field.Type()).Interface() - reflect.ValueOf(structPtr).Elem().Set(field) - - result, err := promptStruct(promptPrefix+"."+fieldName, structPtr, stdIn) - if err != nil { - return data, err - } - - // Get the actual struct value from the result - resultValue := reflect.ValueOf(result) - if resultValue.Kind() == reflect.Ptr { - resultValue = resultValue.Elem() - } - field.Set(resultValue) - continue - case reflect.Slice: - if v.Field(i).Type().Elem().Kind() != reflect.String && v.Field(i).Type().Elem().Kind() != reflect.Int { - continue - } - } - - // create prompts - prompt := promptui.Prompt{ - Label: fmt.Sprintf("Enter %s %s", promptPrefix, strings.Title(fieldName)), // nolint:staticcheck // strings.Title has a better API - Validate: ValidatePromptNotEmpty, - Stdin: stdIn, - } - - result, err := prompt.Run() - if err != nil { - return data, fmt.Errorf("failed to prompt for %s: %w", fieldName, err) - } - - switch field.Kind() { - case reflect.String: - v.Field(i).SetString(result) - case reflect.Int: - resultInt, err := strconv.ParseInt(result, 10, 0) - if err != nil { - return data, fmt.Errorf("invalid value for int: %w", err) - } - v.Field(i).SetInt(resultInt) - case reflect.Slice: - switch v.Field(i).Type().Elem().Kind() { - case reflect.String: - v.Field(i).Set(reflect.ValueOf([]string{result})) - case reflect.Int: - resultInt, err := strconv.ParseInt(result, 10, 0) - if err != nil { - return data, fmt.Errorf("invalid value for int: %w", err) - } - - v.Field(i).Set(reflect.ValueOf([]int{int(resultInt)})) - } - case reflect.Ptr: - // Handle pointer fields by creating a new value and setting it - ptrValue := reflect.New(field.Type().Elem()) - if ptrValue.Elem().Kind() == reflect.String { - ptrValue.Elem().SetString(result) - v.Field(i).Set(ptrValue) - } else if ptrValue.Elem().Kind() == reflect.Int { - resultInt, err := strconv.ParseInt(result, 10, 0) - if err != nil { - return data, fmt.Errorf("invalid value for int: %w", err) - } - ptrValue.Elem().SetInt(resultInt) - v.Field(i).Set(ptrValue) - } - default: - // skip any other types - continue - } - } - - return data, nil -} diff --git a/connect/internal/autocli/prompt/struct_test.go b/connect/internal/autocli/prompt/struct_test.go deleted file mode 100644 index 1b712d81..00000000 --- a/connect/internal/autocli/prompt/struct_test.go +++ /dev/null @@ -1,46 +0,0 @@ -package prompt - -import ( - "testing" - - "github.com/stretchr/testify/require" -) - -type innerStruct struct { - A string - B int -} - -type testStruct struct { - A string - B int - C *innerStruct - D innerStruct - E *string - F []string -} - -func TestPromptStruct(t *testing.T) { - type testCase[T any] struct { - name string - data T - inputs []string - } - tests := []testCase[testStruct]{ - { - name: "test struct", - data: testStruct{}, - inputs: []string{ - "a", "1", "b", "2", "c", "3", "pointerStr", "list", - }, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - inputs := getReader(tt.inputs) - got, err := promptStruct("testStruct", tt.data, inputs) - require.NoError(t, err) - require.NotNil(t, got) - }) - } -} diff --git a/connect/internal/autocli/prompt/util.go b/connect/internal/autocli/prompt/util.go deleted file mode 100644 index 4b3bdec5..00000000 --- a/connect/internal/autocli/prompt/util.go +++ /dev/null @@ -1,70 +0,0 @@ -package prompt - -import ( - "fmt" - - "github.com/manifoldco/promptui" - "google.golang.org/protobuf/reflect/protoreflect" -) - -// Select prompts the user to select an option from a list of choices. -// It takes a label string to display above the selection prompt and a slice of string options to choose from. -func Select(label string, options []string) (string, error) { - selectUi := promptui.Select{ - Label: label, - Items: options, - } - - _, selectedProposalType, err := selectUi.Run() - if err != nil { - return "", fmt.Errorf("failed to prompt proposal types: %w", err) - } - - return selectedProposalType, nil -} - -// PromptString prompts the user for a string input with the given label. -// It validates the input using the provided validate function. -func PromptString(label string, validate func(string) error) (string, error) { - promptUi := promptui.Prompt{ - Label: label, - Validate: validate, - } - - return promptUi.Run() -} - -// SetDefaults sets default values on a protobuf message based on a map of field names to values. -// It iterates through the message fields and sets values from the defaults map if the field name -// and type match. -func SetDefaults(msg protoreflect.Message, defaults map[string]interface{}) { - fields := msg.Descriptor().Fields() - for i := 0; i < fields.Len(); i++ { - field := fields.Get(i) - fieldName := string(field.Name()) - - if v, ok := defaults[fieldName]; ok { - // Get the field's kind - fieldKind := field.Kind() - - switch v.(type) { - case string: - if fieldKind == protoreflect.StringKind { - msg.Set(field, protoreflect.ValueOf(v)) - } - case int64: - if fieldKind == protoreflect.Int64Kind { - msg.Set(field, protoreflect.ValueOf(v)) - } - case int32: - if fieldKind == protoreflect.Int32Kind { - msg.Set(field, protoreflect.ValueOf(v)) - } - case bool: - if fieldKind == protoreflect.BoolKind { - msg.Set(field, protoreflect.ValueOf(v)) - } - } - } - } -} diff --git a/connect/internal/autocli/prompt/validation.go b/connect/internal/autocli/prompt/validation.go deleted file mode 100644 index c1899184..00000000 --- a/connect/internal/autocli/prompt/validation.go +++ /dev/null @@ -1,52 +0,0 @@ -package prompt - -import ( - "errors" - "fmt" - "net/url" - "unicode" - - "cosmossdk.io/core/address" -) - -// ValidatePromptNotEmpty validates that the input is not empty. -func ValidatePromptNotEmpty(input string) error { - if input == "" { - return errors.New("input cannot be empty") - } - - return nil -} - -// ValidateAddress returns a validation function that checks if a string is a valid address -// for the given address codec. -func ValidateAddress(ac address.Codec) func(string) error { - return func(i string) error { - if _, err := ac.StringToBytes(i); err != nil { - return fmt.Errorf("invalid address") - } - - return nil - } -} - -// ValidatePromptURL validates that the input is a valid URL. -func ValidatePromptURL(input string) error { - _, err := url.ParseRequestURI(input) - if err != nil { - return fmt.Errorf("invalid URL: %w", err) - } - - return nil -} - -// CamelCaseToString converts a camel case string to a string with spaces. -func CamelCaseToString(str string) string { - w := []rune(str) - for i := len(w) - 1; i > 1; i-- { - if unicode.IsUpper(w[i]) { - w = append(w[:i], append([]rune{' '}, w[i:]...)...) - } - } - return string(w) -} diff --git a/connect/internal/autocli/prompt/validation_test.go b/connect/internal/autocli/prompt/validation_test.go deleted file mode 100644 index 32b65b2c..00000000 --- a/connect/internal/autocli/prompt/validation_test.go +++ /dev/null @@ -1,55 +0,0 @@ -package prompt - -import ( - "testing" - - "github.com/stretchr/testify/require" - - "cosmossdk.io/core/address" - - address2 "github.com/cosmos/cosmos-sdk/codec/address" -) - -func TestValidatePromptNotEmpty(t *testing.T) { - require := require.New(t) - - require.NoError(ValidatePromptNotEmpty("foo")) - require.ErrorContains(ValidatePromptNotEmpty(""), "input cannot be empty") -} - -func TestValidateAddress(t *testing.T) { - tests := []struct { - name string - ac address.Codec - addr string - }{ - { - name: "address", - ac: address2.NewBech32Codec("cosmos"), - addr: "cosmos129lxcu2n3hx54fdxlwsahqkjr3sp32cxm00zlm", - }, - { - name: "validator address", - ac: address2.NewBech32Codec("cosmosvaloper"), - addr: "cosmosvaloper1tnh2q55v8wyygtt9srz5safamzdengsn9dsd7z", - }, - { - name: "consensus address", - ac: address2.NewBech32Codec("cosmosvalcons"), - addr: "cosmosvalcons136uu5rj23kdr3jjcmjt7aw5qpugjjat2klgrus", - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - err := ValidateAddress(tt.ac)(tt.addr) - require.NoError(t, err) - }) - } -} - -func TestValidatePromptURL(t *testing.T) { - require := require.New(t) - - require.NoError(ValidatePromptURL("https://example.com")) - require.ErrorContains(ValidatePromptURL("foo"), "invalid URL") -} diff --git a/connect/internal/autocli/query.go b/connect/internal/autocli/query.go deleted file mode 100644 index e9a3c174..00000000 --- a/connect/internal/autocli/query.go +++ /dev/null @@ -1,251 +0,0 @@ -package autocli - -import ( - "context" - "errors" - "fmt" - "io" - "strings" - "time" - - "github.com/spf13/cobra" - "google.golang.org/grpc/metadata" - "google.golang.org/protobuf/reflect/protoreflect" - - autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" - "cosmossdk.io/math" - "cosmossdk.io/x/tx/signing/aminojson" - "github.com/ignite/apps/connect/internal/flags" - "github.com/ignite/apps/connect/internal/util" - - sdk "github.com/cosmos/cosmos-sdk/types" -) - -// BuildQueryCommand builds the query commands for all the provided modules. -func (b *Builder) BuildQueryCommand(ctx context.Context, moduleOptions map[string]*autocliv1.ModuleOptions) (*cobra.Command, error) { - queryCmd := topLevelCmd(ctx, "query", "Querying subcommands") - queryCmd.Aliases = []string{"q"} - - if err := b.enhanceCommandCommon(queryCmd, queryCmdType, moduleOptions); err != nil { - return nil, err - } - - return queryCmd, nil -} - -// AddQueryServiceCommands adds a sub-command to the provided command for each -// method in the specified service and returns the command. This can be used in -// order to add auto-generated commands to an existing command. -func (b *Builder) AddQueryServiceCommands(cmd *cobra.Command, cmdDescriptor *autocliv1.ServiceCommandDescriptor) error { - for cmdName, subCmdDesc := range cmdDescriptor.SubCommands { - subCmd := findSubCommand(cmd, cmdName) - if subCmd == nil { - short := subCmdDesc.Short - if short == "" { - short = fmt.Sprintf("Querying commands for the %s service", subCmdDesc.Service) - } - subCmd = topLevelCmd(cmd.Context(), cmdName, short) - } - - if err := b.AddQueryServiceCommands(subCmd, subCmdDesc); err != nil { - return err - } - - if !subCmdDesc.EnhanceCustomCommand { - cmd.AddCommand(subCmd) - } - } - - // skip empty command descriptors - if cmdDescriptor.Service == "" { - return nil - } - - descriptor, err := b.FileResolver.FindDescriptorByName(protoreflect.FullName(cmdDescriptor.Service)) - if err != nil { - return fmt.Errorf("can't find service %s: %w", cmdDescriptor.Service, err) - } - - service := descriptor.(protoreflect.ServiceDescriptor) - methods := service.Methods() - - rpcOptMap := map[protoreflect.Name]*autocliv1.RpcCommandOptions{} - for _, option := range cmdDescriptor.RpcCommandOptions { - name := protoreflect.Name(option.RpcMethod) - rpcOptMap[name] = option - // make sure method exists - if m := methods.ByName(name); m == nil { - return fmt.Errorf("rpc method %q not found for service %q", name, service.FullName()) - } - } - - for i := 0; i < methods.Len(); i++ { - methodDescriptor := methods.Get(i) - methodOpts, ok := rpcOptMap[methodDescriptor.Name()] - if !ok { - methodOpts = &autocliv1.RpcCommandOptions{} - } - - if methodOpts.Skip { - continue - } - - if !util.IsSupportedVersion(methodDescriptor) { - continue - } - - methodCmd, err := b.BuildQueryMethodCommand(cmd.Context(), methodDescriptor, methodOpts) - if err != nil { - return err - } - - if findSubCommand(cmd, methodCmd.Name()) != nil { - // do not overwrite existing commands - // we do not display a warning because you may want to overwrite an autocli command - continue - } - - cmd.AddCommand(methodCmd) - } - - return nil -} - -// BuildQueryMethodCommand creates a gRPC query command for the given service method. This can be used to auto-generate -// just a single command for a single service rpc method. -func (b *Builder) BuildQueryMethodCommand(ctx context.Context, descriptor protoreflect.MethodDescriptor, options *autocliv1.RpcCommandOptions) (*cobra.Command, error) { - serviceDescriptor := descriptor.Parent().(protoreflect.ServiceDescriptor) - methodName := fmt.Sprintf("/%s/%s", serviceDescriptor.FullName(), descriptor.Name()) - outputType := util.ResolveMessageType(b.TypeResolver, descriptor.Output()) - encoderOptions := aminojson.EncoderOptions{ - Indent: " ", - EnumAsString: true, - DoNotSortFields: true, - AminoNameAsTypeURL: true, - MarshalMappings: true, - TypeResolver: b.TypeResolver, - FileResolver: b.FileResolver, - } - - cmd, err := b.buildMethodCommandCommon(descriptor, options, func(cmd *cobra.Command, input protoreflect.Message) error { - clientConn, err := b.GetClientConn(cmd) - if err != nil { - return err - } - - output := outputType.New() - if err := clientConn.Invoke(b.queryContext(cmd.Context(), cmd), methodName, input.Interface(), output.Interface()); err != nil { - return err - } - - if noIndent, _ := cmd.Flags().GetBool(flags.FlagNoIndent); noIndent { - encoderOptions.Indent = "" - } - - enc := encoder(aminojson.NewEncoder(encoderOptions)) - bz, err := enc.Marshal(output.Interface()) - if err != nil { - return fmt.Errorf("cannot marshal response %v: %w", output.Interface(), err) - } - - return b.outOrStdoutFormat(cmd, bz) - }) - if err != nil { - return nil, err - } - - if b.AddQueryConnFlags != nil { - b.AddQueryConnFlags(cmd) - - cmd.Flags().BoolP(flags.FlagNoIndent, "", false, "Do not indent JSON output") - } - - // silence usage only for inner txs & queries commands - if cmd != nil { - cmd.SilenceUsage = true - } - - return cmd, nil -} - -// queryContext returns a new context with metadata for block height if specified. -// If the context already has metadata, it is returned as-is. Otherwise, if a height -// flag is present on the command, it adds an x-cosmos-block-height metadata value -// with the specified height. -func (b *Builder) queryContext(ctx context.Context, cmd *cobra.Command) context.Context { - md, _ := metadata.FromOutgoingContext(ctx) - if md != nil { - return ctx - } - - md = map[string][]string{} - if cmd.Flags().Lookup(flags.FlagHeight) != nil { - h, _ := cmd.Flags().GetInt64(flags.FlagHeight) - md["x-cosmos-block-height"] = []string{fmt.Sprintf("%d", h)} - } - - return metadata.NewOutgoingContext(ctx, md) -} - -func encoder(encoder aminojson.Encoder) aminojson.Encoder { - return encoder.DefineTypeEncoding("google.protobuf.Duration", func(_ *aminojson.Encoder, msg protoreflect.Message, w io.Writer) error { - var ( - secondsName protoreflect.Name = "seconds" - nanosName protoreflect.Name = "nanos" - ) - - fields := msg.Descriptor().Fields() - secondsField := fields.ByName(secondsName) - if secondsField == nil { - return errors.New("expected seconds field") - } - - seconds := msg.Get(secondsField).Int() - - nanosField := fields.ByName(nanosName) - if nanosField == nil { - return errors.New("expected nanos field") - } - - nanos := msg.Get(nanosField).Int() - - _, err := fmt.Fprintf(w, `"%s"`, (time.Duration(seconds)*time.Second + (time.Duration(nanos) * time.Nanosecond)).String()) - return err - }).DefineTypeEncoding("cosmos.base.v1beta1.DecCoin", func(_ *aminojson.Encoder, msg protoreflect.Message, w io.Writer) error { - var ( - denomName protoreflect.Name = "denom" - amountName protoreflect.Name = "amount" - ) - - fields := msg.Descriptor().Fields() - denomField := fields.ByName(denomName) - if denomField == nil { - return errors.New("expected denom field") - } - - denom := msg.Get(denomField).String() - - amountField := fields.ByName(amountName) - if amountField == nil { - return errors.New("expected amount field") - } - - amount := msg.Get(amountField).String() - decimalPlace := len(amount) - math.LegacyPrecision - if decimalPlace > 0 { - amount = amount[:decimalPlace] + "." + amount[decimalPlace:] - } else if decimalPlace == 0 { - amount = "0." + amount - } else { - amount = "0." + strings.Repeat("0", -decimalPlace) + amount - } - - amountDec, err := math.LegacyNewDecFromStr(amount) - if err != nil { - return fmt.Errorf("invalid amount: %s: %w", amount, err) - } - - _, err = fmt.Fprintf(w, `"%s"`, sdk.NewDecCoinFromDec(denom, amountDec)) - return err - }) -} diff --git a/connect/internal/autocli/query_test.go b/connect/internal/autocli/query_test.go deleted file mode 100644 index 85894a38..00000000 --- a/connect/internal/autocli/query_test.go +++ /dev/null @@ -1,714 +0,0 @@ -package autocli - -import ( - "context" - "fmt" - "os" - "strings" - "testing" - "time" - - "github.com/spf13/cobra" - "google.golang.org/protobuf/testing/protocmp" - "google.golang.org/protobuf/types/known/durationpb" - "google.golang.org/protobuf/types/known/timestamppb" - "gotest.tools/v3/assert" - "gotest.tools/v3/golden" - - autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" - queryv1beta1 "cosmossdk.io/api/cosmos/base/query/v1beta1" - basev1beta1 "cosmossdk.io/api/cosmos/base/v1beta1" - "github.com/ignite/apps/connect/internal/testpb" -) - -var buildModuleQueryCommand = func(moduleName string, f *fixture) (*cobra.Command, error) { - ctx := context.TODO() - cmd := topLevelCmd(ctx, moduleName, fmt.Sprintf("Querying commands for the %s module", moduleName)) - - err := f.b.AddQueryServiceCommands(cmd, testCmdDesc) - return cmd, err -} - -var buildModuleQueryCommandOptional = func(moduleName string, f *fixture) (*cobra.Command, error) { - ctx := context.TODO() - cmd := topLevelCmd(ctx, moduleName, fmt.Sprintf("Querying commands for the %s module", moduleName)) - - err := f.b.AddQueryServiceCommands(cmd, testCmdDescOptional) - return cmd, err -} - -var buildModuleVargasOptional = func(moduleName string, f *fixture) (*cobra.Command, error) { - ctx := context.TODO() - cmd := topLevelCmd(ctx, moduleName, fmt.Sprintf("Querying commands for the %s module", moduleName)) - - err := f.b.AddQueryServiceCommands(cmd, testCmdDescInvalidOptAndVargas) - return cmd, err -} - -var testCmdDesc = &autocliv1.ServiceCommandDescriptor{ - Service: testpb.Query_ServiceDesc.ServiceName, - RpcCommandOptions: []*autocliv1.RpcCommandOptions{ - { - RpcMethod: "Echo", - Use: "echo [pos1] [pos2] [pos3...]", - Version: "1.0", - Alias: []string{"e"}, - SuggestFor: []string{"eco"}, - Example: "echo 1 abc {}", - Short: "echo echos the value provided by the user", - Long: "echo echos the value provided by the user as a proto JSON object with populated with the provided fields and positional arguments", - PositionalArgs: []*autocliv1.PositionalArgDescriptor{ - { - ProtoField: "positional1", - }, - { - ProtoField: "positional2", - }, - { - ProtoField: "positional3_varargs", - Varargs: true, - }, - }, - FlagOptions: map[string]*autocliv1.FlagOptions{ - "u32": { - Name: "uint32", - Shorthand: "u", - Usage: "some random uint32", - }, - "i32": { - Usage: "some random int32", - DefaultValue: "3", - }, - "u64": { - Usage: "some random uint64", - DefaultValue: "5", - }, - "deprecated_field": { - Deprecated: "don't use this", - }, - "shorthand_deprecated_field": { - Shorthand: "s", - Deprecated: "bad idea", - }, - "hidden_bool": { - Hidden: true, - }, - "a_coin": { - Usage: "some random coin", - }, - "duration": { - Usage: "some random duration", - }, - "bz": { - Usage: "some bytes", - }, - "map_string_string": { - Usage: "some map of string to string", - }, - "map_string_uint32": { - Usage: "some map of string to int32", - }, - "map_string_coin": { - Usage: "some map of string to coin", - }, - }, - }, - }, - SubCommands: map[string]*autocliv1.ServiceCommandDescriptor{ - // we test the sub-command functionality using the same service with different options - "deprecatedecho": { - Service: testpb.Query_ServiceDesc.ServiceName, - RpcCommandOptions: []*autocliv1.RpcCommandOptions{ - { - RpcMethod: "Echo", - Deprecated: "don't use this", - }, - }, - }, - "skipecho": { - Service: testpb.Query_ServiceDesc.ServiceName, - RpcCommandOptions: []*autocliv1.RpcCommandOptions{ - { - RpcMethod: "Echo", - Skip: true, - }, - }, - }, - }, -} - -var testCmdDescOptional = &autocliv1.ServiceCommandDescriptor{ - Service: testpb.Query_ServiceDesc.ServiceName, - RpcCommandOptions: []*autocliv1.RpcCommandOptions{ - { - RpcMethod: "Echo", - Use: "echo [pos1] [pos2] [pos3...]", - Version: "1.0", - Alias: []string{"e"}, - SuggestFor: []string{"eco"}, - Example: "echo 1 abc {}", - Short: "echo echos the value provided by the user", - Long: "echo echos the value provided by the user as a proto JSON object with populated with the provided fields and positional arguments", - PositionalArgs: []*autocliv1.PositionalArgDescriptor{ - { - ProtoField: "positional1", - }, - { - ProtoField: "positional2", - Optional: true, - }, - }, - }, - }, -} - -var testCmdDescInvalidOptAndVargas = &autocliv1.ServiceCommandDescriptor{ - Service: testpb.Query_ServiceDesc.ServiceName, - RpcCommandOptions: []*autocliv1.RpcCommandOptions{ - { - RpcMethod: "Echo", - Use: "echo [pos1] [pos2] [pos3...]", - Version: "1.0", - Alias: []string{"e"}, - SuggestFor: []string{"eco"}, - Example: "echo 1 abc {}", - Short: "echo echos the value provided by the user", - Long: "echo echos the value provided by the user as a proto JSON object with populated with the provided fields and positional arguments", - PositionalArgs: []*autocliv1.PositionalArgDescriptor{ - { - ProtoField: "positional1", - }, - { - ProtoField: "positional2", - Optional: true, - }, - { - ProtoField: "positional3_varargs", - Varargs: true, - }, - }, - }, - }, -} - -func TestCoin(t *testing.T) { - fixture := initFixture(t) - - _, err := runCmd(fixture, buildModuleQueryCommand, - "echo", - "1", - "abc", - "1234foo,4321bar", - "100uatom", - "--a-coin", "100000foo", - ) - assert.ErrorContains(t, err, "coin flag must be a single coin, specific multiple coins with multiple flags or spaces") - - _, err = runCmd(fixture, buildModuleQueryCommand, - "echo", - "1", - "abc", - "1234foo", - "4321bar", - "100uatom", - "--a-coin", "100000foo", - "--coins", "100000bar", - "--coins", "100uatom", - ) - assert.NilError(t, err) - assert.DeepEqual(t, fixture.conn.lastRequest, fixture.conn.lastResponse.(*testpb.EchoResponse).Request, protocmp.Transform()) - expectedResp := &testpb.EchoResponse{ - Request: &testpb.EchoRequest{ - Positional1: 1, - Positional2: "abc", - Positional3Varargs: []*basev1beta1.Coin{ - {Amount: "1234", Denom: "foo"}, - {Amount: "4321", Denom: "bar"}, - {Amount: "100", Denom: "uatom"}, - }, - ACoin: &basev1beta1.Coin{ - Amount: "100000", - Denom: "foo", - }, - Coins: []*basev1beta1.Coin{ - {Amount: "100000", Denom: "bar"}, - {Amount: "100", Denom: "uatom"}, - }, - Page: &queryv1beta1.PageRequest{}, - I32: 3, - U64: 5, - }, - } - assert.DeepEqual(t, fixture.conn.lastResponse.(*testpb.EchoResponse), expectedResp, protocmp.Transform()) -} - -func TestOptional(t *testing.T) { - fixture := initFixture(t) - - _, err := runCmd(fixture, buildModuleQueryCommandOptional, - "echo", - "1", - "abc", - ) - assert.NilError(t, err) - request := fixture.conn.lastRequest.(*testpb.EchoRequest) - assert.Equal(t, request.Positional2, "abc") - assert.DeepEqual(t, fixture.conn.lastRequest, fixture.conn.lastResponse.(*testpb.EchoResponse).Request, protocmp.Transform()) - - _, err = runCmd(fixture, buildModuleQueryCommandOptional, - "echo", - "1", - ) - assert.NilError(t, err) - - request = fixture.conn.lastRequest.(*testpb.EchoRequest) - assert.Equal(t, request.Positional2, "") - assert.DeepEqual(t, fixture.conn.lastRequest, fixture.conn.lastResponse.(*testpb.EchoResponse).Request, protocmp.Transform()) - - _, err = runCmd(fixture, buildModuleQueryCommandOptional, - "echo", - "1", - "abc", - "extra-arg", - ) - assert.ErrorContains(t, err, "accepts between 1 and 2 arg(s), received 3") - - _, err = runCmd(fixture, buildModuleVargasOptional, - "echo", - "1", - "abc", - "extra-arg", - ) - assert.ErrorContains(t, err, "optional positional argument positional2 must be the last argument") -} - -func TestMap(t *testing.T) { - fixture := initFixture(t) - - _, err := runCmd(fixture, buildModuleQueryCommand, - "echo", - "1", - "abc", - "1234foo", - "4321bar", - "--map-string-uint32", "bar=123", - "--map-string-string", "val=foo", - "--map-string-coin", "baz=100000foo", - "--map-string-coin", "sec=100000bar", - "--map-string-coin", "multi=100000bar,flag=100000foo", - ) - assert.NilError(t, err) - assert.DeepEqual(t, fixture.conn.lastRequest, fixture.conn.lastResponse.(*testpb.EchoResponse).Request, protocmp.Transform()) - - _, err = runCmd(fixture, buildModuleQueryCommand, - "echo", - "1", - "abc", - "1234foo", - "4321bar", - "--map-string-uint32", "bar=123", - "--map-string-coin", "baz,100000foo", - "--map-string-coin", "sec=100000bar", - ) - assert.ErrorContains(t, err, "invalid argument \"baz,100000foo\" for \"--map-string-coin\" flag: invalid format, expected key=value") - - _, err = runCmd(fixture, buildModuleQueryCommand, - "echo", - "1", - "abc", - "1234foo", - "4321bar", - "--map-string-uint32", "bar=not-unint32", - "--map-string-coin", "baz=100000foo", - "--map-string-coin", "sec=100000bar", - ) - assert.ErrorContains(t, err, "invalid argument \"bar=not-unint32\" for \"--map-string-uint32\" flag: strconv.ParseUint: parsing \"not-unint32\": invalid syntax") - - _, err = runCmd(fixture, buildModuleQueryCommand, - "echo", - "1", - "abc", - "1234foo", - "4321bar", - "--map-string-uint32", "bar=123.9", - "--map-string-coin", "baz=100000foo", - "--map-string-coin", "sec=100000bar", - ) - assert.ErrorContains(t, err, "invalid argument \"bar=123.9\" for \"--map-string-uint32\" flag: strconv.ParseUint: parsing \"123.9\": invalid syntax") -} - -// TestEverything tests all the different types of flags are correctly read and as well as correctly returned -// This tests the flag binding and the message building -func TestEverything(t *testing.T) { - fixture := initFixture(t) - - _, err := runCmd(fixture, buildModuleQueryCommand, - "echo", - "1", - "abc", - "123.123123124foo", - "4321bar", - "--a-bool", - "--an-enum", "one", - "--a-message", `{"bar":"abc", "baz":-3}`, - "--duration", "4h3s", - "--uint32", "27", - "--u64", "3267246890", - "--i32", "-253", - "--i64", "-234602347", - "--str", "def", - "--timestamp", "2019-01-02T00:01:02Z", - "--a-coin", "100000foo", - "--an-address", "cosmos1y74p8wyy4enfhfn342njve6cjmj5c8dtl6emdk", - "--a-validator-address", "cosmosvaloper1tnh2q55v8wyygtt9srz5safamzdengsn9dsd7z", - "--a-consensus-address", "cosmosvalcons16vm0nx49eam4q0xasdnwdzsdl6ymgyjt757sgr", - "--bz", "c2RncXdlZndkZ3NkZw==", - "--page-count-total", - "--page-key", "MTIzNTQ4N3NnaGRhcw==", - "--page-limit", "1000", - "--page-offset", "10", - "--page-reverse", - "--bools", "true", - "--bools", "false,false,true", - "--enums", "one", - "--enums", "five", - "--enums", "two", - "--strings", "abc", - "--strings", "xyz", - "--strings", "xyz,qrs", - "--durations", "3s", - "--durations", "5s", - "--durations", "10h", - "--some-messages", "{}", - "--some-messages", `{"bar":"baz"}`, - "--some-messages", `{"baz":-1}`, - "--uints", "1,2,3", - "--uints", "4", - ) - assert.NilError(t, err) - - expectedResp := &testpb.EchoResponse{ - Request: &testpb.EchoRequest{ - Positional1: 1, - Positional2: "abc", - Positional3Varargs: []*basev1beta1.Coin{ - {Amount: "123.123123124", Denom: "foo"}, - {Amount: "4321", Denom: "bar"}, - }, - ABool: true, - AnEnum: testpb.Enum_ENUM_ONE, - AMessage: &testpb.AMessage{ - Bar: "abc", - Baz: -3, - }, - Duration: durationpb.New(4*time.Hour + 3*time.Second), - U32: 27, - U64: 3267246890, - I32: -253, - I64: -234602347, - Str: "def", - Timestamp: ×tamppb.Timestamp{ - Seconds: 1546387262, - }, - ACoin: &basev1beta1.Coin{ - Amount: "100000", - Denom: "foo", - }, - AnAddress: "cosmos1y74p8wyy4enfhfn342njve6cjmj5c8dtl6emdk", - AValidatorAddress: "cosmosvaloper1tnh2q55v8wyygtt9srz5safamzdengsn9dsd7z", - AConsensusAddress: "cosmosvalcons16vm0nx49eam4q0xasdnwdzsdl6ymgyjt757sgr", - Bz: []byte("sdgqwefwdgsdg"), - Page: &queryv1beta1.PageRequest{ - CountTotal: true, - Key: []byte("1235487sghdas"), - Limit: 1000, - Offset: 10, - Reverse: true, - }, - Bools: []bool{true, false, false, true}, - Enums: []testpb.Enum{testpb.Enum_ENUM_ONE, testpb.Enum_ENUM_FIVE, testpb.Enum_ENUM_TWO}, - Strings: []string{ - "abc", - "xyz", - "xyz", - "qrs", - }, - Durations: []*durationpb.Duration{ - durationpb.New(3 * time.Second), - durationpb.New(5 * time.Second), - durationpb.New(10 * time.Hour), - }, - SomeMessages: []*testpb.AMessage{ - {}, - {Bar: "baz"}, - {Baz: -1}, - }, - Uints: []uint32{1, 2, 3, 4}, - }, - } - - assert.DeepEqual(t, fixture.conn.lastRequest, fixture.conn.lastResponse.(*testpb.EchoResponse).Request, protocmp.Transform()) - assert.DeepEqual(t, fixture.conn.lastResponse.(*testpb.EchoResponse), expectedResp, protocmp.Transform()) -} - -func TestPubKeyParsingConsensusAddress(t *testing.T) { - fixture := initFixture(t) - - _, err := runCmd(fixture, buildModuleQueryCommand, - "echo", - "1", "abc", "1foo", - "--a-consensus-address", "{\"@type\":\"/cosmos.crypto.ed25519.PubKey\",\"key\":\"j8qdbR+AlH/V6aBTCSWXRvX3JUESF2bV+SEzndBhF0o=\"}", - "-u", "27", // shorthand - ) - assert.NilError(t, err) - assert.DeepEqual(t, fixture.conn.lastRequest, fixture.conn.lastResponse.(*testpb.EchoResponse).Request, protocmp.Transform()) -} - -func TestJSONParsing(t *testing.T) { - fixture := initFixture(t) - - _, err := runCmd(fixture, buildModuleQueryCommand, - "echo", - "1", "abc", "1foo", - "--some-messages", `{"bar":"baz"}`, - "-u", "27", // shorthand - ) - assert.NilError(t, err) - assert.DeepEqual(t, fixture.conn.lastRequest, fixture.conn.lastResponse.(*testpb.EchoResponse).Request, protocmp.Transform()) - - _, err = runCmd(fixture, buildModuleQueryCommand, - "echo", - "1", "abc", "1foo", - "--some-messages", "testdata/some_message.json", - "-u", "27", // shorthand - ) - assert.NilError(t, err) - assert.DeepEqual(t, fixture.conn.lastRequest, fixture.conn.lastResponse.(*testpb.EchoResponse).Request, protocmp.Transform()) -} - -func TestOptions(t *testing.T) { - fixture := initFixture(t) - - _, err := runCmd(fixture, buildModuleQueryCommand, - "echo", - "1", "abc", "123foo", - "-u", "27", // shorthand - "--u64", "5", // no opt default value - ) - assert.NilError(t, err) - - lastReq := fixture.conn.lastRequest.(*testpb.EchoRequest) - assert.Equal(t, uint32(27), lastReq.U32) // shorthand got set - assert.Equal(t, int32(3), lastReq.I32) // default value got set - assert.Equal(t, uint64(5), lastReq.U64) // no opt default value got set -} - -func TestBinaryFlag(t *testing.T) { - // Create a temporary file with some content - tempFile, err := os.Open("testdata/file.test") - if err != nil { - t.Fatal(err) - } - content := []byte("this is just a test file") - if err := tempFile.Close(); err != nil { - t.Fatal(err) - } - - // Test cases - tests := []struct { - name string - input string - expected []byte - hasError bool - err string - }{ - { - name: "Valid file path with extension", - input: tempFile.Name(), - expected: content, - hasError: false, - err: "", - }, - { - name: "Valid hex-encoded string", - input: "68656c6c6f20776f726c64", - expected: []byte("hello world"), - hasError: false, - err: "", - }, - { - name: "Valid base64-encoded string", - input: "SGVsbG8gV29ybGQ=", - expected: []byte("Hello World"), - hasError: false, - err: "", - }, - { - name: "Invalid input (not a file path or encoded string)", - input: "not a file or encoded string", - expected: nil, - hasError: true, - err: "input string is neither a valid file path, hex, or base64 encoded", - }, - } - - // Run test cases - fixture := initFixture(t) - for _, tc := range tests { - t.Run(tc.name, func(t *testing.T) { - _, err := runCmd(fixture, buildModuleQueryCommand, - "echo", - "1", "abc", `100foo`, - "--bz", tc.input, - ) - if tc.hasError { - assert.ErrorContains(t, err, tc.err) - } else { - assert.NilError(t, err) - lastReq := fixture.conn.lastRequest.(*testpb.EchoRequest) - assert.DeepEqual(t, tc.expected, lastReq.Bz) - } - }) - } -} - -func TestAddressValidation(t *testing.T) { - fixture := initFixture(t) - - _, err := runCmd(fixture, buildModuleQueryCommand, - "echo", - "1", "abc", "1foo", - "--an-address", "cosmos1y74p8wyy4enfhfn342njve6cjmj5c8dtl6emdk", - ) - assert.NilError(t, err) - - _, err = runCmd(fixture, buildModuleQueryCommand, - "echo", - "1", "abc", "1foo", - "--an-address", "regen1y74p8wyy4enfhfn342njve6cjmj5c8dtlqj7ule2", - ) - assert.ErrorContains(t, err, "invalid account address") - - _, err = runCmd(fixture, buildModuleQueryCommand, - "echo", - "1", "abc", "1foo", - "--an-address", "cosmps1BAD_ENCODING", - ) - assert.ErrorContains(t, err, "invalid account address") -} - -func TestOutputFormat(t *testing.T) { - fixture := initFixture(t) - - out, err := runCmd(fixture, buildModuleQueryCommand, - "echo", - "1", "abc", "1foo", - "--output", "json", - ) - assert.NilError(t, err) - assert.Assert(t, strings.Contains(out.String(), "{")) - - out, err = runCmd(fixture, buildModuleQueryCommand, - "echo", - "1", "abc", "1foo", - "--output", "text", - ) - assert.NilError(t, err) - assert.Assert(t, strings.Contains(out.String(), " positional1: 1")) -} - -func TestHelpQuery(t *testing.T) { - fixture := initFixture(t) - - out, err := runCmd(fixture, buildModuleQueryCommand, "-h") - assert.NilError(t, err) - golden.Assert(t, out.String(), "help-toplevel.golden") - - out, err = runCmd(fixture, buildModuleQueryCommand, "echo", "-h") - assert.NilError(t, err) - golden.Assert(t, out.String(), "help-echo.golden") - - out, err = runCmd(fixture, buildModuleQueryCommand, "deprecatedecho", "echo", "-h") - assert.NilError(t, err) - golden.Assert(t, out.String(), "help-deprecated.golden") - - out, err = runCmd(fixture, buildModuleQueryCommand, "skipecho", "-h") - assert.NilError(t, err) - golden.Assert(t, out.String(), "help-skip.golden") -} - -func TestDeprecatedQuery(t *testing.T) { - fixture := initFixture(t) - - out, err := runCmd(fixture, buildModuleQueryCommand, "echo", - "1", "abc", "--deprecated-field", "foo") - assert.NilError(t, err) - assert.Assert(t, strings.Contains(out.String(), "--deprecated-field has been deprecated")) - - out, err = runCmd(fixture, buildModuleQueryCommand, "echo", - "1", "abc", "-s", "foo") - assert.NilError(t, err) - assert.Assert(t, strings.Contains(out.String(), "--shorthand-deprecated-field has been deprecated")) -} - -func TestNotFoundErrorsQuery(t *testing.T) { - fixture := initFixture(t) - b := fixture.b - b.AddQueryConnFlags = nil - b.AddTxConnFlags = nil - - buildModuleQueryCommand := func(_ string, cmdDescriptor *autocliv1.ServiceCommandDescriptor) (*cobra.Command, error) { - cmd := topLevelCmd(context.Background(), "query", "Querying subcommands") - err := b.AddMsgServiceCommands(cmd, cmdDescriptor) - return cmd, err - } - - // bad service - _, err := buildModuleQueryCommand("test", &autocliv1.ServiceCommandDescriptor{Service: "foo"}) - assert.ErrorContains(t, err, "can't find service foo") - - // bad method - _, err = buildModuleQueryCommand("test", &autocliv1.ServiceCommandDescriptor{ - Service: testpb.Query_ServiceDesc.ServiceName, - RpcCommandOptions: []*autocliv1.RpcCommandOptions{{RpcMethod: "bar"}}, - }) - assert.ErrorContains(t, err, "rpc method \"bar\" not found") - - // bad positional field - _, err = buildModuleQueryCommand("test", &autocliv1.ServiceCommandDescriptor{ - Service: testpb.Query_ServiceDesc.ServiceName, - RpcCommandOptions: []*autocliv1.RpcCommandOptions{ - { - RpcMethod: "Echo", - PositionalArgs: []*autocliv1.PositionalArgDescriptor{ - { - ProtoField: "foo", - }, - }, - }, - }, - }) - assert.ErrorContains(t, err, "can't find field foo") - - // bad flag field - _, err = buildModuleQueryCommand("test", &autocliv1.ServiceCommandDescriptor{ - Service: testpb.Query_ServiceDesc.ServiceName, - RpcCommandOptions: []*autocliv1.RpcCommandOptions{ - { - RpcMethod: "Echo", - FlagOptions: map[string]*autocliv1.FlagOptions{ - "baz": {}, - }, - }, - }, - }) - assert.ErrorContains(t, err, "can't find field baz") -} - -func TestDurationMarshal(t *testing.T) { - fixture := initFixture(t) - - out, err := runCmd(fixture, buildModuleQueryCommand, "echo", "1", "abc", "--duration", "1s") - assert.NilError(t, err) - assert.Assert(t, strings.Contains(out.String(), "duration: 1s")) -} diff --git a/connect/internal/autocli/testdata/flatten-output.golden b/connect/internal/autocli/testdata/flatten-output.golden deleted file mode 100644 index 7df8be4c..00000000 --- a/connect/internal/autocli/testdata/flatten-output.golden +++ /dev/null @@ -1 +0,0 @@ -{"body":{"messages":[{"@type":"/cosmos.bank.v1beta1.MsgUpdateParams","authority":"cosmos1y74p8wyy4enfhfn342njve6cjmj5c8dtl6emdk","params":{"send_enabled":[{"denom":"stake","enabled":true}],"default_send_enabled":true}}],"memo":"","timeout_height":"0","extension_options":[],"non_critical_extension_options":[]},"auth_info":{"signer_infos":[],"fee":{"amount":[],"gas_limit":"200000","payer":"","granter":""},"tip":null},"signatures":[]} diff --git a/connect/internal/autocli/testdata/help-deprecated.golden b/connect/internal/autocli/testdata/help-deprecated.golden deleted file mode 100644 index 94586620..00000000 --- a/connect/internal/autocli/testdata/help-deprecated.golden +++ /dev/null @@ -1,50 +0,0 @@ -Command "echo" is deprecated, don't use this -Execute the Echo RPC method - -Usage: - test deprecatedecho echo [flags] - -Flags: - --a-bool - --a-coin cosmos.base.v1beta1.Coin - --a-consensus-address account address or key name - --a-message testpb.AMessage (json) - --a-validator-address account address or key name - --an-address account address or key name - --an-enum Enum (unspecified | one | two | five | neg-three) (default unspecified) - --bools bools (default []) - --bz binary - --coins cosmos.base.v1beta1.Coin (repeated) - --deprecated-field string - --duration duration - --durations duration (repeated) - --enums Enum (unspecified | one | two | five | neg-three) (repeated) - --grpc-addr string the gRPC endpoint to use for this chain - --grpc-insecure allow gRPC over insecure channels, if not the server must use TLS - --height int Use a specific height to query state at (this can error if the node is pruning state) - -h, --help help for echo - --hidden-bool - --i32 int32 - --i64 int - --map-string-coin map[string]cosmos.base.v1beta1.Coin - --map-string-string stringToString (default []) - --map-string-uint32 stringToUint32 - --no-indent Do not indent JSON output - --node string : to CometBFT RPC interface for this chain (default "tcp://localhost:26657") - -o, --output string Output format (text|json) (default "text") - --page-count-total - --page-key binary - --page-limit uint - --page-offset uint - --page-reverse - --positional1 int32 - --positional2 string - --positional3-varargs cosmos.base.v1beta1.Coin (repeated) - --shorthand-deprecated-field string - --some-messages testpb.AMessage (json) (repeated) - --str string - --strings strings - --timestamp timestamp (RFC 3339) - --u32 uint32 - --u64 uint - --uints uints (default []) diff --git a/connect/internal/autocli/testdata/help-echo-msg.golden b/connect/internal/autocli/testdata/help-echo-msg.golden deleted file mode 100644 index 12420587..00000000 --- a/connect/internal/autocli/testdata/help-echo-msg.golden +++ /dev/null @@ -1,33 +0,0 @@ -Send coins from one account to another - -Usage: - test send [flags] - -Flags: - -a, --account-number uint The account number of the signing account (offline mode only) - --aux Generate aux signer data instead of sending a tx - -b, --broadcast-mode string Transaction broadcasting mode (sync|async) (default "sync") - --chain-id string The network chain ID - --dry-run ignore the --gas flag and perform a simulation of a transaction, but don't broadcast it (when enabled, the local Keybase is not accessible) - --fee-granter string Fee granter grants fees for the transaction - --fee-payer string Fee payer pays fees for the transaction instead of deducting from the signer - --fees string Fees to pay along with transaction; eg: 10uatom - --from string Name or address of private key with which to sign - --gas string gas limit to set per-transaction; set to "auto" to calculate sufficient gas automatically. Note: "auto" option doesn't always report accurate results. Set a valid coin value to adjust the result. Can be used instead of "fees". (default 200000) - --gas-adjustment float adjustment factor to be multiplied against the estimate returned by the tx simulation; if the gas limit is set manually this flag is ignored (default 1) - --gas-prices string Gas prices in decimal format to determine the transaction fee (e.g. 0.1uatom) - --generate-only Build an unsigned transaction and write it to STDOUT (when enabled, the local Keybase only accessed when providing a key name) - -h, --help help for send - --home string home directory - --keyring-backend string Select keyring's backend (os|file|kwallet|pass|test|memory) (default "os") - --keyring-dir string The client Keyring directory; if omitted, the default 'home' directory will be used - --ledger Use a connected Ledger device - --node string : to CometBFT rpc interface for this chain (default "tcp://localhost:26657") - --note string Note to add a description to the transaction (previously --memo) - --offline Offline mode (does not allow any online functionality) - -o, --output string Output format (text|json) (default "json") - -s, --sequence uint The sequence number of the signing account (offline mode only) - --sign-mode string Choose sign mode (direct|amino-json|direct-aux|textual), this is an advanced feature - --timeout-height uint Set a block timeout height to prevent the tx from being committed past a certain height - --tip string Tip is the amount that is going to be transferred to the fee payer on the target chain. This flag is only valid when used with --aux, and is ignored if the target chain didn't enable the TipDecorator - -y, --yes Skip tx broadcasting prompt confirmation diff --git a/connect/internal/autocli/testdata/help-echo.golden b/connect/internal/autocli/testdata/help-echo.golden deleted file mode 100644 index 2b3fe024..00000000 --- a/connect/internal/autocli/testdata/help-echo.golden +++ /dev/null @@ -1,52 +0,0 @@ -echo echos the value provided by the user as a proto JSON object with populated with the provided fields and positional arguments - -Usage: - test echo [pos1] [pos2] [pos3...] [flags] - -Aliases: - echo, e - -Examples: -echo 1 abc {} - -Flags: - --a-bool - --a-coin cosmos.base.v1beta1.Coin some random coin - --a-consensus-address account address or key name - --a-message testpb.AMessage (json) - --a-validator-address account address or key name - --an-address account address or key name - --an-enum Enum (unspecified | one | two | five | neg-three) (default unspecified) - --bools bools (default []) - --bz binary some bytes - --coins cosmos.base.v1beta1.Coin (repeated) - --deprecated-field string (DEPRECATED: don't use this) - --duration duration some random duration - --durations duration (repeated) - --enums Enum (unspecified | one | two | five | neg-three) (repeated) - --grpc-addr string the gRPC endpoint to use for this chain - --grpc-insecure allow gRPC over insecure channels, if not the server must use TLS - --height int Use a specific height to query state at (this can error if the node is pruning state) - -h, --help help for echo - --i32 int32 some random int32 - --i64 int - --map-string-coin map[string]cosmos.base.v1beta1.Coin some map of string to coin - --map-string-string stringToString some map of string to string (default []) - --map-string-uint32 stringToUint32 some map of string to int32 - --no-indent Do not indent JSON output - --node string : to CometBFT RPC interface for this chain (default "tcp://localhost:26657") - -o, --output string Output format (text|json) (default "text") - --page-count-total - --page-key binary - --page-limit uint - --page-offset uint - --page-reverse - -s, --shorthand-deprecated-field string (DEPRECATED: bad idea) - --some-messages testpb.AMessage (json) (repeated) - --str string - --strings strings - --timestamp timestamp (RFC 3339) - --u64 uint some random uint64 - -u, --uint32 uint32 some random uint32 - --uints uints (default []) - -v, --version version for echo diff --git a/connect/internal/autocli/testdata/help-skip.golden b/connect/internal/autocli/testdata/help-skip.golden deleted file mode 100644 index a85dbef6..00000000 --- a/connect/internal/autocli/testdata/help-skip.golden +++ /dev/null @@ -1,7 +0,0 @@ -Querying commands for the testpb.Query service - -Usage: - test skipecho [flags] - -Flags: - -h, --help help for skipecho diff --git a/connect/internal/autocli/testdata/help-toplevel-msg.golden b/connect/internal/autocli/testdata/help-toplevel-msg.golden deleted file mode 100644 index f4afbd99..00000000 --- a/connect/internal/autocli/testdata/help-toplevel-msg.golden +++ /dev/null @@ -1,19 +0,0 @@ -Transactions commands for the test module - -Usage: - test [flags] - test [command] - -Available Commands: - burn Execute the Burn RPC method - completion Generate the autocompletion script for the specified shell - help Help about any command - multi-send Execute the MultiSend RPC method - send Send coins from one account to another - set-send-enabled Execute the SetSendEnabled RPC method - update-params Execute the UpdateParams RPC method - -Flags: - -h, --help help for test - -Use "test [command] --help" for more information about a command. diff --git a/connect/internal/autocli/testdata/help-toplevel.golden b/connect/internal/autocli/testdata/help-toplevel.golden deleted file mode 100644 index 7bab88a5..00000000 --- a/connect/internal/autocli/testdata/help-toplevel.golden +++ /dev/null @@ -1,17 +0,0 @@ -Querying commands for the test module - -Usage: - test [flags] - test [command] - -Available Commands: - completion Generate the autocompletion script for the specified shell - deprecatedecho Querying commands for the testpb.Query service - echo echo echos the value provided by the user - help Help about any command - skipecho Querying commands for the testpb.Query service - -Flags: - -h, --help help for test - -Use "test [command] --help" for more information about a command. diff --git a/connect/internal/autocli/testdata/help.golden b/connect/internal/autocli/testdata/help.golden deleted file mode 100644 index c8fe6bbf..00000000 --- a/connect/internal/autocli/testdata/help.golden +++ /dev/null @@ -1,40 +0,0 @@ -echo echos the value provided by the user as a proto JSON object with populated with the provided fields and positional arguments - -Usage: - test echo [pos1] [pos2] [pos3...] [flags] - -Aliases: - echo, e - -Examples: -echo 1 abc {} - -Flags: - --a-bool - --a-coin cosmos.base.v1beta1.Coin (json) - --a-message testpb.AMessage (json) - --an-address bech32 account address key name - --an-enum Enum (unspecified | one | two | five | neg-three) (default unspecified) - --bools bools (default []) - --bz bytesBase64 - --deprecated-field string (DEPRECATED: don't use this) - --duration duration - --durations duration (repeated) - --enums Enum (unspecified | one | two | five | neg-three) (repeated) - -h, --help help for echo - --i32 int32 some random int32 - --i64 int - --page-count-total - --page-key bytesBase64 - --page-limit uint - --page-offset uint - --page-reverse - -s, --shorthand-deprecated-field string (DEPRECATED: bad idea) - --some-messages testpb.AMessage (json) (repeated) - --str string - --strings strings - --timestamp timestamp (RFC 3339) - --u64 uint[=5] some random uint64 - -u, --uint32 uint32 some random uint32 - --uints uints (default []) - -v, --version version for echo diff --git a/connect/internal/autocli/testdata/msg-output.golden b/connect/internal/autocli/testdata/msg-output.golden deleted file mode 100644 index 07eb3d6b..00000000 --- a/connect/internal/autocli/testdata/msg-output.golden +++ /dev/null @@ -1 +0,0 @@ -{"body":{"messages":[{"@type":"/cosmos.bank.v1beta1.MsgSend","from_address":"cosmos1y74p8wyy4enfhfn342njve6cjmj5c8dtl6emdk","to_address":"cosmos1y74p8wyy4enfhfn342njve6cjmj5c8dtl6emdk","amount":[{"denom":"foo","amount":"1"}]}],"memo":"","timeout_height":"0","extension_options":[],"non_critical_extension_options":[]},"auth_info":{"signer_infos":[],"fee":{"amount":[],"gas_limit":"200000","payer":"","granter":""},"tip":null},"signatures":[]} \ No newline at end of file diff --git a/connect/internal/autocli/testdata/some_message.json b/connect/internal/autocli/testdata/some_message.json deleted file mode 100644 index 795d59a9..00000000 --- a/connect/internal/autocli/testdata/some_message.json +++ /dev/null @@ -1 +0,0 @@ -{"bar":"baz"} \ No newline at end of file diff --git a/connect/internal/autocli/util.go b/connect/internal/autocli/util.go deleted file mode 100644 index e04ee080..00000000 --- a/connect/internal/autocli/util.go +++ /dev/null @@ -1,50 +0,0 @@ -package autocli - -import ( - "context" - "strings" - - "github.com/spf13/cobra" - "google.golang.org/protobuf/reflect/protoreflect" - - "github.com/ignite/apps/connect/internal/strcase" -) - -// findSubCommand finds a sub-command of the provided command whose Use -// string is or begins with the provided subCmdName. -// It verifies the command's aliases as well. -func findSubCommand(cmd *cobra.Command, subCmdName string) *cobra.Command { - for _, subCmd := range cmd.Commands() { - use := subCmd.Use - if use == subCmdName || strings.HasPrefix(use, subCmdName+" ") { - return subCmd - } - - for _, alias := range subCmd.Aliases { - if alias == subCmdName || strings.HasPrefix(alias, subCmdName+" ") { - return subCmd - } - } - } - return nil -} - -// topLevelCmd creates a new top-level command with the provided name and -// description. The command will have DisableFlagParsing set to false and -// SuggestionsMinimumDistance set to 2. -func topLevelCmd(ctx context.Context, use, short string) *cobra.Command { - cmd := &cobra.Command{ - Use: use, - Short: short, - DisableFlagParsing: false, - SuggestionsMinimumDistance: 2, - RunE: validateCmd, - } - cmd.SetContext(ctx) - - return cmd -} - -func protoNameToCliName(name protoreflect.Name) string { - return strcase.ToKebab(string(name)) -} diff --git a/connect/internal/autocli/validate.go b/connect/internal/autocli/validate.go deleted file mode 100644 index 0b7c1c97..00000000 --- a/connect/internal/autocli/validate.go +++ /dev/null @@ -1,57 +0,0 @@ -package autocli - -import ( - "errors" - "fmt" - "strings" - - "github.com/spf13/cobra" -) - -// validateCmd returns unknown command error or Help display if help flag set -func validateCmd(cmd *cobra.Command, args []string) error { - var unknownCmd string - var skipNext bool - - for _, arg := range args { - // search for help flag - if arg == "--help" || arg == "-h" { - return cmd.Help() - } - - // check if the current arg is a flag - switch { - case len(arg) > 0 && (arg[0] == '-'): - // the next arg should be skipped if the current arg is a - // flag and does not use "=" to assign the flag's value - if !strings.Contains(arg, "=") { - skipNext = true - } else { - skipNext = false - } - case skipNext: - // skip current arg - skipNext = false - case unknownCmd == "": - // unknown command found - // continue searching for help flag - unknownCmd = arg - } - } - - // return the help screen if no unknown command is found - if unknownCmd != "" { - err := fmt.Sprintf("unknown command \"%s\" for \"%s\"", unknownCmd, cmd.CalledAs()) - - // build suggestions for unknown argument - if suggestions := cmd.SuggestionsFor(unknownCmd); len(suggestions) > 0 { - err += "\n\nDid you mean this?\n" - for _, s := range suggestions { - err += fmt.Sprintf("\t%v\n", s) - } - } - return errors.New(err) - } - - return cmd.Help() -} diff --git a/connect/internal/buf.gen.gogo.yaml b/connect/internal/buf.gen.gogo.yaml deleted file mode 100644 index a1df55b8..00000000 --- a/connect/internal/buf.gen.gogo.yaml +++ /dev/null @@ -1,5 +0,0 @@ -version: v1 -plugins: - - name: gocosmos - out: .. - opt: plugins=grpc,Mgoogle/protobuf/any.proto=github.com/cosmos/gogoproto/types/any diff --git a/connect/internal/buf.gen.pulsar.yaml b/connect/internal/buf.gen.pulsar.yaml deleted file mode 100644 index d27cab62..00000000 --- a/connect/internal/buf.gen.pulsar.yaml +++ /dev/null @@ -1,16 +0,0 @@ -version: v1 -managed: - enabled: true - go_package_prefix: - default: github.com/ignite/apps/connect/internal - except: - - buf.build/cosmos/cosmos-proto - override: - buf.build/cosmos/cosmos-sdk: cosmossdk.io/api -plugins: - - name: go-pulsar - out: . - opt: paths=source_relative - - name: go-grpc - out: . - opt: paths=source_relative diff --git a/connect/internal/buf.lock b/connect/internal/buf.lock deleted file mode 100644 index ca09fbb4..00000000 --- a/connect/internal/buf.lock +++ /dev/null @@ -1,33 +0,0 @@ -# Generated by buf. DO NOT EDIT. -version: v1 -deps: - - remote: buf.build - owner: cosmos - repository: cosmos-proto - commit: 04467658e59e44bbb22fe568206e1f70 - digest: shake256:73a640bd60e0c523b0f8237ff34eab67c45a38b64bbbde1d80224819d272dbf316ac183526bd245f994af6608b025f5130483d0133c5edd385531326b5990466 - - remote: buf.build - owner: cosmos - repository: cosmos-sdk - commit: 05419252bcc241ea8023acf1ed4cadc5 - digest: shake256:1e54a48c19a8b59d35e0a7efa76402939f515f2d8005df099856f24c37c20a52800308f025abb8cffcd014d437b49707388aaca4865d9d063d8f25d5d4eb77d5 - - remote: buf.build - owner: cosmos - repository: gogo-proto - commit: 88ef6483f90f478fb938c37dde52ece3 - digest: shake256:89c45df2aa11e0cff97b0d695436713db3d993d76792e9f8dc1ae90e6ab9a9bec55503d48ceedd6b86069ab07d3041b32001b2bfe0227fa725dd515ff381e5ba - - remote: buf.build - owner: googleapis - repository: googleapis - commit: 7e6f6e774e29406da95bd61cdcdbc8bc - digest: shake256:fe43dd2265ea0c07d76bd925eeba612667cf4c948d2ce53d6e367e1b4b3cb5fa69a51e6acb1a6a50d32f894f054a35e6c0406f6808a483f2752e10c866ffbf73 - - remote: buf.build - owner: protocolbuffers - repository: wellknowntypes - commit: 657250e6a39648cbb169d079a60bd9ba - digest: shake256:00de25001b8dd2e29d85fc4bcc3ede7aed886d76d67f5e0f7a9b320b90f871d3eb73507d50818d823a0512f3f8db77a11c043685528403e31ff3fef18323a9fb - - remote: buf.build - owner: tendermint - repository: tendermint - commit: 33ed361a90514289beabf3189e1d7665 - digest: shake256:038267e06294714fd883610626554b04a127b576b4e253befb4206cb72d5d3c1eeccacd4b9ec8e3fb891f7c14e1cb0f770c077d2989638995b0a61c85afedb1d diff --git a/connect/internal/buf.yaml b/connect/internal/buf.yaml deleted file mode 100644 index 96af160b..00000000 --- a/connect/internal/buf.yaml +++ /dev/null @@ -1,12 +0,0 @@ -version: v1 -deps: - - buf.build/cosmos/cosmos-sdk - - buf.build/cosmos/cosmos-proto -lint: - use: - - DEFAULT - except: - - PACKAGE_VERSION_SUFFIX -breaking: - ignore: - - testpb diff --git a/connect/internal/coins/format.go b/connect/internal/coins/format.go deleted file mode 100644 index b3ca0866..00000000 --- a/connect/internal/coins/format.go +++ /dev/null @@ -1,62 +0,0 @@ -package coins - -import ( - "errors" - "regexp" - "strings" - - basev1beta1 "cosmossdk.io/api/cosmos/base/v1beta1" -) - -// Amount can be a whole number or a decimal number. Denominations can be 3 ~ 128 -// characters long and support letters, followed by either a letter, a number or -// a separator ('/', ':', '.', '_' or '-'). -var coinRegex = regexp.MustCompile(`^(\d+(\.\d+)?)([a-zA-Z][a-zA-Z0-9\/\:\._\-]{2,127})$`) - -// ParseCoin parses a coin from a string. The string must be in the format -// , where is a number and is a valid denom. -func ParseCoin(input string) (*basev1beta1.Coin, error) { - amount, denom, err := parseCoin(input) - if err != nil { - return nil, err - } - - return &basev1beta1.Coin{ - Amount: amount, - Denom: denom, - }, nil -} - -// ParseDecCoin parses a decCoin from a string. The string must be in the format -// , where is a number and is a valid denom. -func ParseDecCoin(input string) (*basev1beta1.DecCoin, error) { - amount, denom, err := parseCoin(input) - if err != nil { - return nil, err - } - - return &basev1beta1.DecCoin{ - Amount: amount, - Denom: denom, - }, nil -} - -// parseCoin parses a coin string into its amount and denom components. -// The input string must be in the format . -// It returns the amount string, denom string, and any error encountered. -// Returns an error if the input is empty or doesn't match the expected format. -func parseCoin(input string) (amount, denom string, err error) { - input = strings.TrimSpace(input) - - if input == "" { - return "", "", errors.New("empty input when parsing coin") - } - - matches := coinRegex.FindStringSubmatch(input) - - if len(matches) == 0 { - return "", "", errors.New("invalid input format") - } - - return matches[1], matches[3], nil -} diff --git a/connect/internal/coins/format_test.go b/connect/internal/coins/format_test.go deleted file mode 100644 index a5c42ac1..00000000 --- a/connect/internal/coins/format_test.go +++ /dev/null @@ -1,73 +0,0 @@ -package coins - -import ( - "testing" - - "github.com/stretchr/testify/require" -) - -func Test_parseCoin(t *testing.T) { - tests := []struct { - name string - input string - amount string - denom string - err string - }{ - { - name: "ok", - input: "1000stake", - amount: "1000", - denom: "stake", - }, - { - name: "empty", - input: "", - err: "empty input when parsing coin", - }, - { - name: "empty denom", - input: "1000", - err: "invalid input format", - }, - { - name: "empty amount", - input: "stake", - err: "invalid input format", - }, - { - name: " format", - input: "stake1000", - err: "invalid input format", - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - amount, denom, err := parseCoin(tt.input) - if tt.err != "" { - require.Error(t, err) - require.Contains(t, err.Error(), tt.err) - } else { - require.NoError(t, err) - require.Equal(t, tt.amount, amount) - require.Equal(t, tt.denom, denom) - } - }) - } -} - -func TestParseCoin(t *testing.T) { - encodedCoin := "1000000000foo" - coin, err := ParseCoin(encodedCoin) - require.NoError(t, err) - require.Equal(t, "1000000000", coin.Amount) - require.Equal(t, "foo", coin.Denom) -} - -func TestParseDecCoin(t *testing.T) { - encodedCoin := "1000000000foo" - coin, err := ParseDecCoin(encodedCoin) - require.NoError(t, err) - require.Equal(t, "1000000000", coin.Amount) - require.Equal(t, "foo", coin.Denom) -} diff --git a/connect/internal/coins/util.go b/connect/internal/coins/util.go deleted file mode 100644 index d5760898..00000000 --- a/connect/internal/coins/util.go +++ /dev/null @@ -1,66 +0,0 @@ -package coins - -import ( - "errors" - - base "cosmossdk.io/api/cosmos/base/v1beta1" - "cosmossdk.io/math" - - sdk "github.com/cosmos/cosmos-sdk/types" -) - -var ( - _ withAmount = &base.Coin{} - _ withAmount = &base.DecCoin{} -) - -type withAmount interface { - GetAmount() string -} - -// IsZero check if given coins are zero. -func IsZero[T withAmount](coins []T) (bool, error) { - for _, coin := range coins { - amount, ok := math.NewIntFromString(coin.GetAmount()) - if !ok { - return false, errors.New("invalid coin amount") - } - if !amount.IsZero() { - return false, nil - } - } - return true, nil -} - -func ParseDecCoins(coins string) ([]*base.DecCoin, error) { - parsedGasPrices, err := sdk.ParseDecCoins(coins) - if err != nil { - return nil, err - } - - finalGasPrices := make([]*base.DecCoin, len(parsedGasPrices)) - for i, coin := range parsedGasPrices { - finalGasPrices[i] = &base.DecCoin{ - Denom: coin.Denom, - Amount: coin.Amount.String(), - } - } - return finalGasPrices, nil -} - -func ParseCoinsNormalized(coins string) ([]*base.Coin, error) { - parsedFees, err := sdk.ParseCoinsNormalized(coins) - if err != nil { - return nil, err - } - - finalFees := make([]*base.Coin, len(parsedFees)) - for i, coin := range parsedFees { - finalFees[i] = &base.Coin{ - Denom: coin.Denom, - Amount: coin.Amount.String(), - } - } - - return finalFees, nil -} diff --git a/connect/internal/coins/util_test.go b/connect/internal/coins/util_test.go deleted file mode 100644 index 1ee7f584..00000000 --- a/connect/internal/coins/util_test.go +++ /dev/null @@ -1,83 +0,0 @@ -package coins - -import ( - "testing" - - "github.com/stretchr/testify/require" - - base "cosmossdk.io/api/cosmos/base/v1beta1" -) - -func TestCoinIsZero(t *testing.T) { - type testCase[T withAmount] struct { - name string - coins []T - isZero bool - } - tests := []testCase[*base.Coin]{ - { - name: "not zero coin", - coins: []*base.Coin{ - { - Denom: "stake", - Amount: "100", - }, - }, - isZero: false, - }, - { - name: "zero coin", - coins: []*base.Coin{ - { - Denom: "stake", - Amount: "0", - }, - }, - isZero: true, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - got, err := IsZero(tt.coins) - require.NoError(t, err) - require.Equal(t, got, tt.isZero) - }) - } -} - -func TestDecCoinIsZero(t *testing.T) { - type testCase[T withAmount] struct { - name string - coins []T - isZero bool - } - tests := []testCase[*base.DecCoin]{ - { - name: "not zero coin", - coins: []*base.DecCoin{ - { - Denom: "stake", - Amount: "100", - }, - }, - isZero: false, - }, - { - name: "zero coin", - coins: []*base.DecCoin{ - { - Denom: "stake", - Amount: "0", - }, - }, - isZero: true, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - got, err := IsZero(tt.coins) - require.NoError(t, err) - require.Equal(t, got, tt.isZero) - }) - } -} diff --git a/connect/internal/governance/gov.go b/connect/internal/governance/gov.go deleted file mode 100644 index 61472196..00000000 --- a/connect/internal/governance/gov.go +++ /dev/null @@ -1,98 +0,0 @@ -package governance - -import ( - "fmt" - - gogoproto "github.com/cosmos/gogoproto/proto" - gogoprotoany "github.com/cosmos/gogoproto/types/any" - "github.com/spf13/cobra" - "github.com/spf13/pflag" - "google.golang.org/protobuf/types/known/anypb" - - govv1 "cosmossdk.io/api/cosmos/gov/v1" - "github.com/ignite/apps/connect/internal/coins" -) - -const ( - // ModuleName is the name of the governance module name. - // It should match the module name of the github.com/cosmos/cosmos-sdk/x/gov module. - ModuleName = "gov" - - FlagDeposit = "deposit" - FlagMetadata = "metadata" - FlagTitle = "title" - FlagSummary = "summary" - FlagExpedited = "expedited" -) - -// AddGovPropFlagsToCmd adds governance proposal flags to the provided command. -func AddGovPropFlagsToCmd(cmd *cobra.Command) { - cmd.Flags().String(FlagDeposit, "", "The deposit to include with the governance proposal") - cmd.Flags().String(FlagMetadata, "", "The metadata to include with the governance proposal") - cmd.Flags().String(FlagTitle, "", "The title to put on the governance proposal") - cmd.Flags().String(FlagSummary, "", "The summary to include with the governance proposal") - cmd.Flags().Bool(FlagExpedited, false, "Whether to expedite the governance proposal") -} - -// ReadGovPropCmdFlags parses a MsgSubmitProposal from the provided context and flags. -func ReadGovPropCmdFlags(proposer string, flagSet *pflag.FlagSet) (*govv1.MsgSubmitProposal, error) { - rv := &govv1.MsgSubmitProposal{} - - deposit, err := flagSet.GetString(FlagDeposit) - if err != nil { - return nil, fmt.Errorf("could not read deposit: %w", err) - } - if len(deposit) > 0 { - rv.InitialDeposit, err = coins.ParseCoinsNormalized(deposit) - if err != nil { - return nil, fmt.Errorf("invalid deposit: %w", err) - } - } - - rv.Metadata, err = flagSet.GetString(FlagMetadata) - if err != nil { - return nil, fmt.Errorf("could not read metadata: %w", err) - } - - rv.Title, err = flagSet.GetString(FlagTitle) - if err != nil { - return nil, fmt.Errorf("could not read title: %w", err) - } - - rv.Summary, err = flagSet.GetString(FlagSummary) - if err != nil { - return nil, fmt.Errorf("could not read summary: %w", err) - } - - expedited, err := flagSet.GetBool(FlagExpedited) - if err != nil { - return nil, fmt.Errorf("could not read expedited: %w", err) - } - if expedited { - rv.Expedited = true - } - - rv.Proposer = proposer - - return rv, nil -} - -func SetGovMsgs(proposal *govv1.MsgSubmitProposal, msgs ...gogoproto.Message) error { - if len(msgs) == 0 { - return fmt.Errorf("zero messages is not supported") - } - - for _, msg := range msgs { - anyMsg, err := gogoprotoany.NewAnyWithCacheWithValue(msg) - if err != nil { - return err - } - - proposal.Messages = append(proposal.Messages, &anypb.Any{ - TypeUrl: anyMsg.TypeUrl, - Value: anyMsg.Value, - }) - } - - return nil -} diff --git a/connect/internal/autocli/keyring/keyring.go b/connect/internal/keyring.go similarity index 82% rename from connect/internal/autocli/keyring/keyring.go rename to connect/internal/keyring.go index c49f7a30..338a79ce 100644 --- a/connect/internal/autocli/keyring/keyring.go +++ b/connect/internal/keyring.go @@ -1,14 +1,13 @@ -package keyring +package internal import ( "github.com/spf13/pflag" - "github.com/ignite/apps/connect/internal/flags" - "github.com/ignite/cli/v28/ignite/pkg/cosmosaccount" - "cosmossdk.io/core/address" - "github.com/cosmos/cosmos-sdk/crypto/keyring" + + "github.com/ignite/apps/connect/internal/flags" + "github.com/ignite/cli/v28/ignite/pkg/cosmosaccount" ) // NewKeyring creates a new keyring instance based on command-line flags. @@ -16,7 +15,7 @@ func NewKeyring( flagSet *pflag.FlagSet, addressCodec address.Codec, bech32Prefix string, -) (Keyring, error) { +) (keyring.Keyring, error) { keyringBackend, err := flagSet.GetString(flags.FlagKeyringBackend) if err != nil { return nil, err @@ -33,10 +32,5 @@ func NewKeyring( return nil, err } - igniteKeyring, err := NewAutoCLIKeyring(ca.Keyring, addressCodec) - if err != nil { - return nil, err - } - - return igniteKeyring, nil + return ca.Keyring, nil } diff --git a/connect/internal/print/printer.go b/connect/internal/print/printer.go deleted file mode 100644 index 68ff3bff..00000000 --- a/connect/internal/print/printer.go +++ /dev/null @@ -1,84 +0,0 @@ -package print - -import ( - "encoding/json" - "fmt" - "io" - "os" - - "github.com/spf13/cobra" - "sigs.k8s.io/yaml" - - "github.com/ignite/apps/connect/internal/flags" -) - -const ( - jsonOutput = flags.OutputFormatJSON - textOutput = flags.OutputFormatText -) - -// Printer handles formatted output of different types of data -type Printer struct { - Output io.Writer - OutputFormat string -} - -// NewPrinter creates a new Printer instance with default stdout -func NewPrinter(cmd *cobra.Command) (*Printer, error) { - outputFormat, err := cmd.Flags().GetString("output") - if err != nil { - return nil, err - } - - if outputFormat != jsonOutput && outputFormat != textOutput { - return nil, fmt.Errorf("unsupported output format: %s", outputFormat) - } - - return &Printer{ - Output: cmd.OutOrStdout(), - OutputFormat: outputFormat, - }, nil -} - -// PrintString prints the raw string -func (p *Printer) PrintString(str string) error { - return p.PrintBytes([]byte(str)) -} - -// PrintRaw prints raw JSON message without marshaling -func (p *Printer) PrintRaw(toPrint json.RawMessage) error { - return p.PrintBytes(toPrint) -} - -// PrintBytes prints and formats bytes -func (p *Printer) PrintBytes(out []byte) error { - var err error - if p.OutputFormat == textOutput { - if !json.Valid(out) { - return fmt.Errorf("invalid JSON") - } - out, err = yaml.JSONToYAML(out) - if err != nil { - return err - } - } - - writer := p.Output - if writer == nil { - writer = os.Stdout - } - - _, err = writer.Write(out) - if err != nil { - return err - } - - if p.OutputFormat != textOutput { - _, err = writer.Write([]byte("\n")) - if err != nil { - return err - } - } - - return nil -} diff --git a/connect/internal/strcase/kebab.go b/connect/internal/strcase/kebab.go deleted file mode 100644 index ac3eb1c0..00000000 --- a/connect/internal/strcase/kebab.go +++ /dev/null @@ -1,101 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2015 Ian Coleman - * Copyright (c) 2018 Ma_124, - * Copyright (c) 2022 Cosmos SDK Developers, - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, Subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or Substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package strcase - -import ( - "strings" -) - -// ToKebab converts a string to kebab-case -func ToKebab(s string) string { - return ToDelimited(s, '-', false) -} - -// ToScreamingKebab converts a string to SCREAMING-KEBAB-CASE -func ToScreamingKebab(s string) string { - return ToDelimited(s, '-', true) -} - -// ToSnake converts a string to snake_case -func ToSnake(s string) string { - return ToDelimited(s, '_', false) -} - -// ToScreamingSnake converts a string to SCREAMING_SNAKE_CASE -func ToScreamingSnake(s string) string { - return ToDelimited(s, '_', true) -} - -// ToDelimited converts a string to delimited.snake.case -// (in this case `delimiter = '.'`) -func ToDelimited(s string, delimiter uint8, screaming bool) string { - s = strings.TrimSpace(s) - n := strings.Builder{} - n.Grow(len(s) + 2) // nominal 2 bytes of extra space for inserted delimiters - for i, v := range []byte(s) { - vIsCap := v >= 'A' && v <= 'Z' - vIsLow := v >= 'a' && v <= 'z' - if vIsLow && screaming { - v += 'A' - v -= 'a' - } else if vIsCap && !screaming { - v += 'a' - v -= 'A' - } - - // treat acronyms as words, eg for JSONData -> JSON is a whole word - if i+1 < len(s) { - next := s[i+1] - vIsNum := v >= '0' && v <= '9' - nextIsCap := next >= 'A' && next <= 'Z' - nextIsLow := next >= 'a' && next <= 'z' - nextIsNum := next >= '0' && next <= '9' - // add underscore if next letter case type is changed - if (vIsCap && (nextIsLow || nextIsNum)) || (vIsLow && (nextIsCap || nextIsNum)) || (vIsNum && (nextIsCap || nextIsLow)) { - if vIsCap && nextIsLow { - if prevIsCap := i > 0 && s[i-1] >= 'A' && s[i-1] <= 'Z'; prevIsCap { - n.WriteByte(delimiter) - } - } - n.WriteByte(v) - if (vIsLow && nextIsCap) || (vIsNum && nextIsCap) || (vIsNum && nextIsLow) { - n.WriteByte(delimiter) - } - continue - } - } - - if v == ' ' || v == '_' || v == '-' || v == '.' { - // replace space/underscore/hyphen/dot with delimiter - n.WriteByte(delimiter) - } else { - n.WriteByte(v) - } - } - - return n.String() -} diff --git a/connect/internal/strcase/kebab_test.go b/connect/internal/strcase/kebab_test.go deleted file mode 100644 index 3add7144..00000000 --- a/connect/internal/strcase/kebab_test.go +++ /dev/null @@ -1,44 +0,0 @@ -package strcase_test - -import ( - "testing" - - "gotest.tools/v3/assert" - - "github.com/ignite/apps/connect/internal/strcase" -) - -func toKebab(tb testing.TB) { - tb.Helper() - cases := [][]string{ - {"testCase", "test-case"}, - {"TestCase", "test-case"}, - {"Test Case", "test-case"}, - {"TEST CASE", "test-case"}, - {"TESTCase", "test-case"}, - {"TESTCASE", "testcase"}, - {"TEST_CASE", "test-case"}, - {"Bech32", "bech32"}, - {"Bech32Address", "bech32-address"}, - {"Bech32_Address", "bech32-address"}, - {"Bech32Address10", "bech32-address10"}, - {"Bech32-Address10", "bech32-address10"}, - {"SecondBech32Address10Foo", "second-bech32-address10-foo"}, - } - for _, i := range cases { - in := i[0] - out := i[1] - result := strcase.ToKebab(in) - assert.Equal(tb, out, result, "ToKebab(%s) = %s, want %s", in, result, out) - } -} - -func TestToKebab(t *testing.T) { - toKebab(t) -} - -func BenchmarkToKebab(b *testing.B) { - for n := 0; n < b.N; n++ { - toKebab(b) - } -} diff --git a/connect/internal/testpb/msg.proto b/connect/internal/testpb/msg.proto deleted file mode 100644 index a8189519..00000000 --- a/connect/internal/testpb/msg.proto +++ /dev/null @@ -1,62 +0,0 @@ -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.53.0 "; - } -} - -message MsgRequest { - // u32 is a 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 {} diff --git a/connect/internal/testpb/msg.pulsar.go b/connect/internal/testpb/msg.pulsar.go deleted file mode 100644 index 216a5c15..00000000 --- a/connect/internal/testpb/msg.pulsar.go +++ /dev/null @@ -1,4435 +0,0 @@ -// Code generated by protoc-gen-go-pulsar. DO NOT EDIT. -package testpb - -import ( - v1beta11 "cosmossdk.io/api/cosmos/base/query/v1beta1" - v1beta1 "cosmossdk.io/api/cosmos/base/v1beta1" - fmt "fmt" - _ "github.com/cosmos/cosmos-proto" - runtime "github.com/cosmos/cosmos-proto/runtime" - protoreflect "google.golang.org/protobuf/reflect/protoreflect" - protoiface "google.golang.org/protobuf/runtime/protoiface" - protoimpl "google.golang.org/protobuf/runtime/protoimpl" - durationpb "google.golang.org/protobuf/types/known/durationpb" - timestamppb "google.golang.org/protobuf/types/known/timestamppb" - io "io" - reflect "reflect" - sync "sync" -) - -var _ protoreflect.List = (*_MsgRequest_21_list)(nil) - -type _MsgRequest_21_list struct { - list *[]bool -} - -func (x *_MsgRequest_21_list) Len() int { - if x.list == nil { - return 0 - } - return len(*x.list) -} - -func (x *_MsgRequest_21_list) Get(i int) protoreflect.Value { - return protoreflect.ValueOfBool((*x.list)[i]) -} - -func (x *_MsgRequest_21_list) Set(i int, value protoreflect.Value) { - valueUnwrapped := value.Bool() - concreteValue := valueUnwrapped - (*x.list)[i] = concreteValue -} - -func (x *_MsgRequest_21_list) Append(value protoreflect.Value) { - valueUnwrapped := value.Bool() - concreteValue := valueUnwrapped - *x.list = append(*x.list, concreteValue) -} - -func (x *_MsgRequest_21_list) AppendMutable() protoreflect.Value { - panic(fmt.Errorf("AppendMutable can not be called on message MsgRequest at list field Bools as it is not of Message kind")) -} - -func (x *_MsgRequest_21_list) Truncate(n int) { - *x.list = (*x.list)[:n] -} - -func (x *_MsgRequest_21_list) NewElement() protoreflect.Value { - v := false - return protoreflect.ValueOfBool(v) -} - -func (x *_MsgRequest_21_list) IsValid() bool { - return x.list != nil -} - -var _ protoreflect.List = (*_MsgRequest_22_list)(nil) - -type _MsgRequest_22_list struct { - list *[]uint32 -} - -func (x *_MsgRequest_22_list) Len() int { - if x.list == nil { - return 0 - } - return len(*x.list) -} - -func (x *_MsgRequest_22_list) Get(i int) protoreflect.Value { - return protoreflect.ValueOfUint32((*x.list)[i]) -} - -func (x *_MsgRequest_22_list) Set(i int, value protoreflect.Value) { - valueUnwrapped := value.Uint() - concreteValue := (uint32)(valueUnwrapped) - (*x.list)[i] = concreteValue -} - -func (x *_MsgRequest_22_list) Append(value protoreflect.Value) { - valueUnwrapped := value.Uint() - concreteValue := (uint32)(valueUnwrapped) - *x.list = append(*x.list, concreteValue) -} - -func (x *_MsgRequest_22_list) AppendMutable() protoreflect.Value { - panic(fmt.Errorf("AppendMutable can not be called on message MsgRequest at list field Uints as it is not of Message kind")) -} - -func (x *_MsgRequest_22_list) Truncate(n int) { - *x.list = (*x.list)[:n] -} - -func (x *_MsgRequest_22_list) NewElement() protoreflect.Value { - v := uint32(0) - return protoreflect.ValueOfUint32(v) -} - -func (x *_MsgRequest_22_list) IsValid() bool { - return x.list != nil -} - -var _ protoreflect.List = (*_MsgRequest_23_list)(nil) - -type _MsgRequest_23_list struct { - list *[]string -} - -func (x *_MsgRequest_23_list) Len() int { - if x.list == nil { - return 0 - } - return len(*x.list) -} - -func (x *_MsgRequest_23_list) Get(i int) protoreflect.Value { - return protoreflect.ValueOfString((*x.list)[i]) -} - -func (x *_MsgRequest_23_list) Set(i int, value protoreflect.Value) { - valueUnwrapped := value.String() - concreteValue := valueUnwrapped - (*x.list)[i] = concreteValue -} - -func (x *_MsgRequest_23_list) Append(value protoreflect.Value) { - valueUnwrapped := value.String() - concreteValue := valueUnwrapped - *x.list = append(*x.list, concreteValue) -} - -func (x *_MsgRequest_23_list) AppendMutable() protoreflect.Value { - panic(fmt.Errorf("AppendMutable can not be called on message MsgRequest at list field Strings as it is not of Message kind")) -} - -func (x *_MsgRequest_23_list) Truncate(n int) { - *x.list = (*x.list)[:n] -} - -func (x *_MsgRequest_23_list) NewElement() protoreflect.Value { - v := "" - return protoreflect.ValueOfString(v) -} - -func (x *_MsgRequest_23_list) IsValid() bool { - return x.list != nil -} - -var _ protoreflect.List = (*_MsgRequest_24_list)(nil) - -type _MsgRequest_24_list struct { - list *[]Enum -} - -func (x *_MsgRequest_24_list) Len() int { - if x.list == nil { - return 0 - } - return len(*x.list) -} - -func (x *_MsgRequest_24_list) Get(i int) protoreflect.Value { - return protoreflect.ValueOfEnum((protoreflect.EnumNumber)((*x.list)[i])) -} - -func (x *_MsgRequest_24_list) Set(i int, value protoreflect.Value) { - valueUnwrapped := value.Enum() - concreteValue := (Enum)(valueUnwrapped) - (*x.list)[i] = concreteValue -} - -func (x *_MsgRequest_24_list) Append(value protoreflect.Value) { - valueUnwrapped := value.Enum() - concreteValue := (Enum)(valueUnwrapped) - *x.list = append(*x.list, concreteValue) -} - -func (x *_MsgRequest_24_list) AppendMutable() protoreflect.Value { - panic(fmt.Errorf("AppendMutable can not be called on message MsgRequest at list field Enums as it is not of Message kind")) -} - -func (x *_MsgRequest_24_list) Truncate(n int) { - *x.list = (*x.list)[:n] -} - -func (x *_MsgRequest_24_list) NewElement() protoreflect.Value { - v := 0 - return protoreflect.ValueOfEnum((protoreflect.EnumNumber)(v)) -} - -func (x *_MsgRequest_24_list) IsValid() bool { - return x.list != nil -} - -var _ protoreflect.List = (*_MsgRequest_25_list)(nil) - -type _MsgRequest_25_list struct { - list *[]*durationpb.Duration -} - -func (x *_MsgRequest_25_list) Len() int { - if x.list == nil { - return 0 - } - return len(*x.list) -} - -func (x *_MsgRequest_25_list) Get(i int) protoreflect.Value { - return protoreflect.ValueOfMessage((*x.list)[i].ProtoReflect()) -} - -func (x *_MsgRequest_25_list) Set(i int, value protoreflect.Value) { - valueUnwrapped := value.Message() - concreteValue := valueUnwrapped.Interface().(*durationpb.Duration) - (*x.list)[i] = concreteValue -} - -func (x *_MsgRequest_25_list) Append(value protoreflect.Value) { - valueUnwrapped := value.Message() - concreteValue := valueUnwrapped.Interface().(*durationpb.Duration) - *x.list = append(*x.list, concreteValue) -} - -func (x *_MsgRequest_25_list) AppendMutable() protoreflect.Value { - v := new(durationpb.Duration) - *x.list = append(*x.list, v) - return protoreflect.ValueOfMessage(v.ProtoReflect()) -} - -func (x *_MsgRequest_25_list) Truncate(n int) { - for i := n; i < len(*x.list); i++ { - (*x.list)[i] = nil - } - *x.list = (*x.list)[:n] -} - -func (x *_MsgRequest_25_list) NewElement() protoreflect.Value { - v := new(durationpb.Duration) - return protoreflect.ValueOfMessage(v.ProtoReflect()) -} - -func (x *_MsgRequest_25_list) IsValid() bool { - return x.list != nil -} - -var _ protoreflect.List = (*_MsgRequest_26_list)(nil) - -type _MsgRequest_26_list struct { - list *[]*AMessage -} - -func (x *_MsgRequest_26_list) Len() int { - if x.list == nil { - return 0 - } - return len(*x.list) -} - -func (x *_MsgRequest_26_list) Get(i int) protoreflect.Value { - return protoreflect.ValueOfMessage((*x.list)[i].ProtoReflect()) -} - -func (x *_MsgRequest_26_list) Set(i int, value protoreflect.Value) { - valueUnwrapped := value.Message() - concreteValue := valueUnwrapped.Interface().(*AMessage) - (*x.list)[i] = concreteValue -} - -func (x *_MsgRequest_26_list) Append(value protoreflect.Value) { - valueUnwrapped := value.Message() - concreteValue := valueUnwrapped.Interface().(*AMessage) - *x.list = append(*x.list, concreteValue) -} - -func (x *_MsgRequest_26_list) AppendMutable() protoreflect.Value { - v := new(AMessage) - *x.list = append(*x.list, v) - return protoreflect.ValueOfMessage(v.ProtoReflect()) -} - -func (x *_MsgRequest_26_list) Truncate(n int) { - for i := n; i < len(*x.list); i++ { - (*x.list)[i] = nil - } - *x.list = (*x.list)[:n] -} - -func (x *_MsgRequest_26_list) NewElement() protoreflect.Value { - v := new(AMessage) - return protoreflect.ValueOfMessage(v.ProtoReflect()) -} - -func (x *_MsgRequest_26_list) IsValid() bool { - return x.list != nil -} - -var _ protoreflect.List = (*_MsgRequest_29_list)(nil) - -type _MsgRequest_29_list struct { - list *[]*v1beta1.Coin -} - -func (x *_MsgRequest_29_list) Len() int { - if x.list == nil { - return 0 - } - return len(*x.list) -} - -func (x *_MsgRequest_29_list) Get(i int) protoreflect.Value { - return protoreflect.ValueOfMessage((*x.list)[i].ProtoReflect()) -} - -func (x *_MsgRequest_29_list) Set(i int, value protoreflect.Value) { - valueUnwrapped := value.Message() - concreteValue := valueUnwrapped.Interface().(*v1beta1.Coin) - (*x.list)[i] = concreteValue -} - -func (x *_MsgRequest_29_list) Append(value protoreflect.Value) { - valueUnwrapped := value.Message() - concreteValue := valueUnwrapped.Interface().(*v1beta1.Coin) - *x.list = append(*x.list, concreteValue) -} - -func (x *_MsgRequest_29_list) AppendMutable() protoreflect.Value { - v := new(v1beta1.Coin) - *x.list = append(*x.list, v) - return protoreflect.ValueOfMessage(v.ProtoReflect()) -} - -func (x *_MsgRequest_29_list) Truncate(n int) { - for i := n; i < len(*x.list); i++ { - (*x.list)[i] = nil - } - *x.list = (*x.list)[:n] -} - -func (x *_MsgRequest_29_list) NewElement() protoreflect.Value { - v := new(v1beta1.Coin) - return protoreflect.ValueOfMessage(v.ProtoReflect()) -} - -func (x *_MsgRequest_29_list) IsValid() bool { - return x.list != nil -} - -var ( - md_MsgRequest protoreflect.MessageDescriptor - fd_MsgRequest_u32 protoreflect.FieldDescriptor - fd_MsgRequest_u64 protoreflect.FieldDescriptor - fd_MsgRequest_str protoreflect.FieldDescriptor - fd_MsgRequest_bz protoreflect.FieldDescriptor - fd_MsgRequest_timestamp protoreflect.FieldDescriptor - fd_MsgRequest_duration protoreflect.FieldDescriptor - fd_MsgRequest_i32 protoreflect.FieldDescriptor - fd_MsgRequest_i64 protoreflect.FieldDescriptor - fd_MsgRequest_a_bool protoreflect.FieldDescriptor - fd_MsgRequest_an_enum protoreflect.FieldDescriptor - fd_MsgRequest_a_message protoreflect.FieldDescriptor - fd_MsgRequest_a_coin protoreflect.FieldDescriptor - fd_MsgRequest_an_address protoreflect.FieldDescriptor - fd_MsgRequest_page protoreflect.FieldDescriptor - fd_MsgRequest_bools protoreflect.FieldDescriptor - fd_MsgRequest_uints protoreflect.FieldDescriptor - fd_MsgRequest_strings protoreflect.FieldDescriptor - fd_MsgRequest_enums protoreflect.FieldDescriptor - fd_MsgRequest_durations protoreflect.FieldDescriptor - fd_MsgRequest_some_messages protoreflect.FieldDescriptor - fd_MsgRequest_positional1 protoreflect.FieldDescriptor - fd_MsgRequest_positional2 protoreflect.FieldDescriptor - fd_MsgRequest_positional3_varargs protoreflect.FieldDescriptor - fd_MsgRequest_deprecated_field protoreflect.FieldDescriptor - fd_MsgRequest_shorthand_deprecated_field protoreflect.FieldDescriptor - fd_MsgRequest_hidden_bool protoreflect.FieldDescriptor - fd_MsgRequest_a_validator_address protoreflect.FieldDescriptor -) - -func init() { - file_testpb_msg_proto_init() - md_MsgRequest = File_testpb_msg_proto.Messages().ByName("MsgRequest") - fd_MsgRequest_u32 = md_MsgRequest.Fields().ByName("u32") - fd_MsgRequest_u64 = md_MsgRequest.Fields().ByName("u64") - fd_MsgRequest_str = md_MsgRequest.Fields().ByName("str") - fd_MsgRequest_bz = md_MsgRequest.Fields().ByName("bz") - fd_MsgRequest_timestamp = md_MsgRequest.Fields().ByName("timestamp") - fd_MsgRequest_duration = md_MsgRequest.Fields().ByName("duration") - fd_MsgRequest_i32 = md_MsgRequest.Fields().ByName("i32") - fd_MsgRequest_i64 = md_MsgRequest.Fields().ByName("i64") - fd_MsgRequest_a_bool = md_MsgRequest.Fields().ByName("a_bool") - fd_MsgRequest_an_enum = md_MsgRequest.Fields().ByName("an_enum") - fd_MsgRequest_a_message = md_MsgRequest.Fields().ByName("a_message") - fd_MsgRequest_a_coin = md_MsgRequest.Fields().ByName("a_coin") - fd_MsgRequest_an_address = md_MsgRequest.Fields().ByName("an_address") - fd_MsgRequest_page = md_MsgRequest.Fields().ByName("page") - fd_MsgRequest_bools = md_MsgRequest.Fields().ByName("bools") - fd_MsgRequest_uints = md_MsgRequest.Fields().ByName("uints") - fd_MsgRequest_strings = md_MsgRequest.Fields().ByName("strings") - fd_MsgRequest_enums = md_MsgRequest.Fields().ByName("enums") - fd_MsgRequest_durations = md_MsgRequest.Fields().ByName("durations") - fd_MsgRequest_some_messages = md_MsgRequest.Fields().ByName("some_messages") - fd_MsgRequest_positional1 = md_MsgRequest.Fields().ByName("positional1") - fd_MsgRequest_positional2 = md_MsgRequest.Fields().ByName("positional2") - fd_MsgRequest_positional3_varargs = md_MsgRequest.Fields().ByName("positional3_varargs") - fd_MsgRequest_deprecated_field = md_MsgRequest.Fields().ByName("deprecated_field") - fd_MsgRequest_shorthand_deprecated_field = md_MsgRequest.Fields().ByName("shorthand_deprecated_field") - fd_MsgRequest_hidden_bool = md_MsgRequest.Fields().ByName("hidden_bool") - fd_MsgRequest_a_validator_address = md_MsgRequest.Fields().ByName("a_validator_address") -} - -var _ protoreflect.Message = (*fastReflection_MsgRequest)(nil) - -type fastReflection_MsgRequest MsgRequest - -func (x *MsgRequest) ProtoReflect() protoreflect.Message { - return (*fastReflection_MsgRequest)(x) -} - -func (x *MsgRequest) slowProtoReflect() protoreflect.Message { - mi := &file_testpb_msg_proto_msgTypes[0] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -var _fastReflection_MsgRequest_messageType fastReflection_MsgRequest_messageType -var _ protoreflect.MessageType = fastReflection_MsgRequest_messageType{} - -type fastReflection_MsgRequest_messageType struct{} - -func (x fastReflection_MsgRequest_messageType) Zero() protoreflect.Message { - return (*fastReflection_MsgRequest)(nil) -} -func (x fastReflection_MsgRequest_messageType) New() protoreflect.Message { - return new(fastReflection_MsgRequest) -} -func (x fastReflection_MsgRequest_messageType) Descriptor() protoreflect.MessageDescriptor { - return md_MsgRequest -} - -// Descriptor returns message descriptor, which contains only the protobuf -// type information for the message. -func (x *fastReflection_MsgRequest) Descriptor() protoreflect.MessageDescriptor { - return md_MsgRequest -} - -// Type returns the message type, which encapsulates both Go and protobuf -// type information. If the Go type information is not needed, -// it is recommended that the message descriptor be used instead. -func (x *fastReflection_MsgRequest) Type() protoreflect.MessageType { - return _fastReflection_MsgRequest_messageType -} - -// New returns a newly allocated and mutable empty message. -func (x *fastReflection_MsgRequest) New() protoreflect.Message { - return new(fastReflection_MsgRequest) -} - -// Interface unwraps the message reflection interface and -// returns the underlying ProtoMessage interface. -func (x *fastReflection_MsgRequest) Interface() protoreflect.ProtoMessage { - return (*MsgRequest)(x) -} - -// Range iterates over every populated field in an undefined order, -// calling f for each field descriptor and value encountered. -// Range returns immediately if f returns false. -// While iterating, mutating operations may only be performed -// on the current field descriptor. -func (x *fastReflection_MsgRequest) Range(f func(protoreflect.FieldDescriptor, protoreflect.Value) bool) { - if x.U32 != uint32(0) { - value := protoreflect.ValueOfUint32(x.U32) - if !f(fd_MsgRequest_u32, value) { - return - } - } - if x.U64 != uint64(0) { - value := protoreflect.ValueOfUint64(x.U64) - if !f(fd_MsgRequest_u64, value) { - return - } - } - if x.Str != "" { - value := protoreflect.ValueOfString(x.Str) - if !f(fd_MsgRequest_str, value) { - return - } - } - if len(x.Bz) != 0 { - value := protoreflect.ValueOfBytes(x.Bz) - if !f(fd_MsgRequest_bz, value) { - return - } - } - if x.Timestamp != nil { - value := protoreflect.ValueOfMessage(x.Timestamp.ProtoReflect()) - if !f(fd_MsgRequest_timestamp, value) { - return - } - } - if x.Duration != nil { - value := protoreflect.ValueOfMessage(x.Duration.ProtoReflect()) - if !f(fd_MsgRequest_duration, value) { - return - } - } - if x.I32 != int32(0) { - value := protoreflect.ValueOfInt32(x.I32) - if !f(fd_MsgRequest_i32, value) { - return - } - } - if x.I64 != int64(0) { - value := protoreflect.ValueOfInt64(x.I64) - if !f(fd_MsgRequest_i64, value) { - return - } - } - if x.ABool != false { - value := protoreflect.ValueOfBool(x.ABool) - if !f(fd_MsgRequest_a_bool, value) { - return - } - } - if x.AnEnum != 0 { - value := protoreflect.ValueOfEnum((protoreflect.EnumNumber)(x.AnEnum)) - if !f(fd_MsgRequest_an_enum, value) { - return - } - } - if x.AMessage != nil { - value := protoreflect.ValueOfMessage(x.AMessage.ProtoReflect()) - if !f(fd_MsgRequest_a_message, value) { - return - } - } - if x.ACoin != nil { - value := protoreflect.ValueOfMessage(x.ACoin.ProtoReflect()) - if !f(fd_MsgRequest_a_coin, value) { - return - } - } - if x.AnAddress != "" { - value := protoreflect.ValueOfString(x.AnAddress) - if !f(fd_MsgRequest_an_address, value) { - return - } - } - if x.Page != nil { - value := protoreflect.ValueOfMessage(x.Page.ProtoReflect()) - if !f(fd_MsgRequest_page, value) { - return - } - } - if len(x.Bools) != 0 { - value := protoreflect.ValueOfList(&_MsgRequest_21_list{list: &x.Bools}) - if !f(fd_MsgRequest_bools, value) { - return - } - } - if len(x.Uints) != 0 { - value := protoreflect.ValueOfList(&_MsgRequest_22_list{list: &x.Uints}) - if !f(fd_MsgRequest_uints, value) { - return - } - } - if len(x.Strings) != 0 { - value := protoreflect.ValueOfList(&_MsgRequest_23_list{list: &x.Strings}) - if !f(fd_MsgRequest_strings, value) { - return - } - } - if len(x.Enums) != 0 { - value := protoreflect.ValueOfList(&_MsgRequest_24_list{list: &x.Enums}) - if !f(fd_MsgRequest_enums, value) { - return - } - } - if len(x.Durations) != 0 { - value := protoreflect.ValueOfList(&_MsgRequest_25_list{list: &x.Durations}) - if !f(fd_MsgRequest_durations, value) { - return - } - } - if len(x.SomeMessages) != 0 { - value := protoreflect.ValueOfList(&_MsgRequest_26_list{list: &x.SomeMessages}) - if !f(fd_MsgRequest_some_messages, value) { - return - } - } - if x.Positional1 != int32(0) { - value := protoreflect.ValueOfInt32(x.Positional1) - if !f(fd_MsgRequest_positional1, value) { - return - } - } - if x.Positional2 != "" { - value := protoreflect.ValueOfString(x.Positional2) - if !f(fd_MsgRequest_positional2, value) { - return - } - } - if len(x.Positional3Varargs) != 0 { - value := protoreflect.ValueOfList(&_MsgRequest_29_list{list: &x.Positional3Varargs}) - if !f(fd_MsgRequest_positional3_varargs, value) { - return - } - } - if x.DeprecatedField != "" { - value := protoreflect.ValueOfString(x.DeprecatedField) - if !f(fd_MsgRequest_deprecated_field, value) { - return - } - } - if x.ShorthandDeprecatedField != "" { - value := protoreflect.ValueOfString(x.ShorthandDeprecatedField) - if !f(fd_MsgRequest_shorthand_deprecated_field, value) { - return - } - } - if x.HiddenBool != false { - value := protoreflect.ValueOfBool(x.HiddenBool) - if !f(fd_MsgRequest_hidden_bool, value) { - return - } - } - if x.AValidatorAddress != "" { - value := protoreflect.ValueOfString(x.AValidatorAddress) - if !f(fd_MsgRequest_a_validator_address, value) { - return - } - } -} - -// Has reports whether a field is populated. -// -// Some fields have the property of nullability where it is possible to -// distinguish between the default value of a field and whether the field -// was explicitly populated with the default value. Singular message fields, -// member fields of a oneof, and proto2 scalar fields are nullable. Such -// fields are populated only if explicitly set. -// -// In other cases (aside from the nullable cases above), -// a proto3 scalar field is populated if it contains a non-zero value, and -// a repeated field is populated if it is non-empty. -func (x *fastReflection_MsgRequest) Has(fd protoreflect.FieldDescriptor) bool { - switch fd.FullName() { - case "testpb.MsgRequest.u32": - return x.U32 != uint32(0) - case "testpb.MsgRequest.u64": - return x.U64 != uint64(0) - case "testpb.MsgRequest.str": - return x.Str != "" - case "testpb.MsgRequest.bz": - return len(x.Bz) != 0 - case "testpb.MsgRequest.timestamp": - return x.Timestamp != nil - case "testpb.MsgRequest.duration": - return x.Duration != nil - case "testpb.MsgRequest.i32": - return x.I32 != int32(0) - case "testpb.MsgRequest.i64": - return x.I64 != int64(0) - case "testpb.MsgRequest.a_bool": - return x.ABool != false - case "testpb.MsgRequest.an_enum": - return x.AnEnum != 0 - case "testpb.MsgRequest.a_message": - return x.AMessage != nil - case "testpb.MsgRequest.a_coin": - return x.ACoin != nil - case "testpb.MsgRequest.an_address": - return x.AnAddress != "" - case "testpb.MsgRequest.page": - return x.Page != nil - case "testpb.MsgRequest.bools": - return len(x.Bools) != 0 - case "testpb.MsgRequest.uints": - return len(x.Uints) != 0 - case "testpb.MsgRequest.strings": - return len(x.Strings) != 0 - case "testpb.MsgRequest.enums": - return len(x.Enums) != 0 - case "testpb.MsgRequest.durations": - return len(x.Durations) != 0 - case "testpb.MsgRequest.some_messages": - return len(x.SomeMessages) != 0 - case "testpb.MsgRequest.positional1": - return x.Positional1 != int32(0) - case "testpb.MsgRequest.positional2": - return x.Positional2 != "" - case "testpb.MsgRequest.positional3_varargs": - return len(x.Positional3Varargs) != 0 - case "testpb.MsgRequest.deprecated_field": - return x.DeprecatedField != "" - case "testpb.MsgRequest.shorthand_deprecated_field": - return x.ShorthandDeprecatedField != "" - case "testpb.MsgRequest.hidden_bool": - return x.HiddenBool != false - case "testpb.MsgRequest.a_validator_address": - return x.AValidatorAddress != "" - default: - if fd.IsExtension() { - panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.MsgRequest")) - } - panic(fmt.Errorf("message testpb.MsgRequest does not contain field %s", fd.FullName())) - } -} - -// Clear clears the field such that a subsequent Has call reports false. -// -// Clearing an extension field clears both the extension type and value -// associated with the given field number. -// -// Clear is a mutating operation and unsafe for concurrent use. -func (x *fastReflection_MsgRequest) Clear(fd protoreflect.FieldDescriptor) { - switch fd.FullName() { - case "testpb.MsgRequest.u32": - x.U32 = uint32(0) - case "testpb.MsgRequest.u64": - x.U64 = uint64(0) - case "testpb.MsgRequest.str": - x.Str = "" - case "testpb.MsgRequest.bz": - x.Bz = nil - case "testpb.MsgRequest.timestamp": - x.Timestamp = nil - case "testpb.MsgRequest.duration": - x.Duration = nil - case "testpb.MsgRequest.i32": - x.I32 = int32(0) - case "testpb.MsgRequest.i64": - x.I64 = int64(0) - case "testpb.MsgRequest.a_bool": - x.ABool = false - case "testpb.MsgRequest.an_enum": - x.AnEnum = 0 - case "testpb.MsgRequest.a_message": - x.AMessage = nil - case "testpb.MsgRequest.a_coin": - x.ACoin = nil - case "testpb.MsgRequest.an_address": - x.AnAddress = "" - case "testpb.MsgRequest.page": - x.Page = nil - case "testpb.MsgRequest.bools": - x.Bools = nil - case "testpb.MsgRequest.uints": - x.Uints = nil - case "testpb.MsgRequest.strings": - x.Strings = nil - case "testpb.MsgRequest.enums": - x.Enums = nil - case "testpb.MsgRequest.durations": - x.Durations = nil - case "testpb.MsgRequest.some_messages": - x.SomeMessages = nil - case "testpb.MsgRequest.positional1": - x.Positional1 = int32(0) - case "testpb.MsgRequest.positional2": - x.Positional2 = "" - case "testpb.MsgRequest.positional3_varargs": - x.Positional3Varargs = nil - case "testpb.MsgRequest.deprecated_field": - x.DeprecatedField = "" - case "testpb.MsgRequest.shorthand_deprecated_field": - x.ShorthandDeprecatedField = "" - case "testpb.MsgRequest.hidden_bool": - x.HiddenBool = false - case "testpb.MsgRequest.a_validator_address": - x.AValidatorAddress = "" - default: - if fd.IsExtension() { - panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.MsgRequest")) - } - panic(fmt.Errorf("message testpb.MsgRequest does not contain field %s", fd.FullName())) - } -} - -// Get retrieves the value for a field. -// -// For unpopulated scalars, it returns the default value, where -// the default value of a bytes scalar is guaranteed to be a copy. -// For unpopulated composite types, it returns an empty, read-only view -// of the value; to obtain a mutable reference, use Mutable. -func (x *fastReflection_MsgRequest) Get(descriptor protoreflect.FieldDescriptor) protoreflect.Value { - switch descriptor.FullName() { - case "testpb.MsgRequest.u32": - value := x.U32 - return protoreflect.ValueOfUint32(value) - case "testpb.MsgRequest.u64": - value := x.U64 - return protoreflect.ValueOfUint64(value) - case "testpb.MsgRequest.str": - value := x.Str - return protoreflect.ValueOfString(value) - case "testpb.MsgRequest.bz": - value := x.Bz - return protoreflect.ValueOfBytes(value) - case "testpb.MsgRequest.timestamp": - value := x.Timestamp - return protoreflect.ValueOfMessage(value.ProtoReflect()) - case "testpb.MsgRequest.duration": - value := x.Duration - return protoreflect.ValueOfMessage(value.ProtoReflect()) - case "testpb.MsgRequest.i32": - value := x.I32 - return protoreflect.ValueOfInt32(value) - case "testpb.MsgRequest.i64": - value := x.I64 - return protoreflect.ValueOfInt64(value) - case "testpb.MsgRequest.a_bool": - value := x.ABool - return protoreflect.ValueOfBool(value) - case "testpb.MsgRequest.an_enum": - value := x.AnEnum - return protoreflect.ValueOfEnum((protoreflect.EnumNumber)(value)) - case "testpb.MsgRequest.a_message": - value := x.AMessage - return protoreflect.ValueOfMessage(value.ProtoReflect()) - case "testpb.MsgRequest.a_coin": - value := x.ACoin - return protoreflect.ValueOfMessage(value.ProtoReflect()) - case "testpb.MsgRequest.an_address": - value := x.AnAddress - return protoreflect.ValueOfString(value) - case "testpb.MsgRequest.page": - value := x.Page - return protoreflect.ValueOfMessage(value.ProtoReflect()) - case "testpb.MsgRequest.bools": - if len(x.Bools) == 0 { - return protoreflect.ValueOfList(&_MsgRequest_21_list{}) - } - listValue := &_MsgRequest_21_list{list: &x.Bools} - return protoreflect.ValueOfList(listValue) - case "testpb.MsgRequest.uints": - if len(x.Uints) == 0 { - return protoreflect.ValueOfList(&_MsgRequest_22_list{}) - } - listValue := &_MsgRequest_22_list{list: &x.Uints} - return protoreflect.ValueOfList(listValue) - case "testpb.MsgRequest.strings": - if len(x.Strings) == 0 { - return protoreflect.ValueOfList(&_MsgRequest_23_list{}) - } - listValue := &_MsgRequest_23_list{list: &x.Strings} - return protoreflect.ValueOfList(listValue) - case "testpb.MsgRequest.enums": - if len(x.Enums) == 0 { - return protoreflect.ValueOfList(&_MsgRequest_24_list{}) - } - listValue := &_MsgRequest_24_list{list: &x.Enums} - return protoreflect.ValueOfList(listValue) - case "testpb.MsgRequest.durations": - if len(x.Durations) == 0 { - return protoreflect.ValueOfList(&_MsgRequest_25_list{}) - } - listValue := &_MsgRequest_25_list{list: &x.Durations} - return protoreflect.ValueOfList(listValue) - case "testpb.MsgRequest.some_messages": - if len(x.SomeMessages) == 0 { - return protoreflect.ValueOfList(&_MsgRequest_26_list{}) - } - listValue := &_MsgRequest_26_list{list: &x.SomeMessages} - return protoreflect.ValueOfList(listValue) - case "testpb.MsgRequest.positional1": - value := x.Positional1 - return protoreflect.ValueOfInt32(value) - case "testpb.MsgRequest.positional2": - value := x.Positional2 - return protoreflect.ValueOfString(value) - case "testpb.MsgRequest.positional3_varargs": - if len(x.Positional3Varargs) == 0 { - return protoreflect.ValueOfList(&_MsgRequest_29_list{}) - } - listValue := &_MsgRequest_29_list{list: &x.Positional3Varargs} - return protoreflect.ValueOfList(listValue) - case "testpb.MsgRequest.deprecated_field": - value := x.DeprecatedField - return protoreflect.ValueOfString(value) - case "testpb.MsgRequest.shorthand_deprecated_field": - value := x.ShorthandDeprecatedField - return protoreflect.ValueOfString(value) - case "testpb.MsgRequest.hidden_bool": - value := x.HiddenBool - return protoreflect.ValueOfBool(value) - case "testpb.MsgRequest.a_validator_address": - value := x.AValidatorAddress - return protoreflect.ValueOfString(value) - default: - if descriptor.IsExtension() { - panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.MsgRequest")) - } - panic(fmt.Errorf("message testpb.MsgRequest does not contain field %s", descriptor.FullName())) - } -} - -// Set stores the value for a field. -// -// For a field belonging to a oneof, it implicitly clears any other field -// that may be currently set within the same oneof. -// For extension fields, it implicitly stores the provided ExtensionType. -// When setting a composite type, it is unspecified whether the stored value -// aliases the source's memory in any way. If the composite value is an -// empty, read-only value, then it panics. -// -// Set is a mutating operation and unsafe for concurrent use. -func (x *fastReflection_MsgRequest) Set(fd protoreflect.FieldDescriptor, value protoreflect.Value) { - switch fd.FullName() { - case "testpb.MsgRequest.u32": - x.U32 = uint32(value.Uint()) - case "testpb.MsgRequest.u64": - x.U64 = value.Uint() - case "testpb.MsgRequest.str": - x.Str = value.Interface().(string) - case "testpb.MsgRequest.bz": - x.Bz = value.Bytes() - case "testpb.MsgRequest.timestamp": - x.Timestamp = value.Message().Interface().(*timestamppb.Timestamp) - case "testpb.MsgRequest.duration": - x.Duration = value.Message().Interface().(*durationpb.Duration) - case "testpb.MsgRequest.i32": - x.I32 = int32(value.Int()) - case "testpb.MsgRequest.i64": - x.I64 = value.Int() - case "testpb.MsgRequest.a_bool": - x.ABool = value.Bool() - case "testpb.MsgRequest.an_enum": - x.AnEnum = (Enum)(value.Enum()) - case "testpb.MsgRequest.a_message": - x.AMessage = value.Message().Interface().(*AMessage) - case "testpb.MsgRequest.a_coin": - x.ACoin = value.Message().Interface().(*v1beta1.Coin) - case "testpb.MsgRequest.an_address": - x.AnAddress = value.Interface().(string) - case "testpb.MsgRequest.page": - x.Page = value.Message().Interface().(*v1beta11.PageRequest) - case "testpb.MsgRequest.bools": - lv := value.List() - clv := lv.(*_MsgRequest_21_list) - x.Bools = *clv.list - case "testpb.MsgRequest.uints": - lv := value.List() - clv := lv.(*_MsgRequest_22_list) - x.Uints = *clv.list - case "testpb.MsgRequest.strings": - lv := value.List() - clv := lv.(*_MsgRequest_23_list) - x.Strings = *clv.list - case "testpb.MsgRequest.enums": - lv := value.List() - clv := lv.(*_MsgRequest_24_list) - x.Enums = *clv.list - case "testpb.MsgRequest.durations": - lv := value.List() - clv := lv.(*_MsgRequest_25_list) - x.Durations = *clv.list - case "testpb.MsgRequest.some_messages": - lv := value.List() - clv := lv.(*_MsgRequest_26_list) - x.SomeMessages = *clv.list - case "testpb.MsgRequest.positional1": - x.Positional1 = int32(value.Int()) - case "testpb.MsgRequest.positional2": - x.Positional2 = value.Interface().(string) - case "testpb.MsgRequest.positional3_varargs": - lv := value.List() - clv := lv.(*_MsgRequest_29_list) - x.Positional3Varargs = *clv.list - case "testpb.MsgRequest.deprecated_field": - x.DeprecatedField = value.Interface().(string) - case "testpb.MsgRequest.shorthand_deprecated_field": - x.ShorthandDeprecatedField = value.Interface().(string) - case "testpb.MsgRequest.hidden_bool": - x.HiddenBool = value.Bool() - case "testpb.MsgRequest.a_validator_address": - x.AValidatorAddress = value.Interface().(string) - default: - if fd.IsExtension() { - panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.MsgRequest")) - } - panic(fmt.Errorf("message testpb.MsgRequest does not contain field %s", fd.FullName())) - } -} - -// Mutable returns a mutable reference to a composite type. -// -// If the field is unpopulated, it may allocate a composite value. -// For a field belonging to a oneof, it implicitly clears any other field -// that may be currently set within the same oneof. -// For extension fields, it implicitly stores the provided ExtensionType -// if not already stored. -// It panics if the field does not contain a composite type. -// -// Mutable is a mutating operation and unsafe for concurrent use. -func (x *fastReflection_MsgRequest) Mutable(fd protoreflect.FieldDescriptor) protoreflect.Value { - switch fd.FullName() { - case "testpb.MsgRequest.timestamp": - if x.Timestamp == nil { - x.Timestamp = new(timestamppb.Timestamp) - } - return protoreflect.ValueOfMessage(x.Timestamp.ProtoReflect()) - case "testpb.MsgRequest.duration": - if x.Duration == nil { - x.Duration = new(durationpb.Duration) - } - return protoreflect.ValueOfMessage(x.Duration.ProtoReflect()) - case "testpb.MsgRequest.a_message": - if x.AMessage == nil { - x.AMessage = new(AMessage) - } - return protoreflect.ValueOfMessage(x.AMessage.ProtoReflect()) - case "testpb.MsgRequest.a_coin": - if x.ACoin == nil { - x.ACoin = new(v1beta1.Coin) - } - return protoreflect.ValueOfMessage(x.ACoin.ProtoReflect()) - case "testpb.MsgRequest.page": - if x.Page == nil { - x.Page = new(v1beta11.PageRequest) - } - return protoreflect.ValueOfMessage(x.Page.ProtoReflect()) - case "testpb.MsgRequest.bools": - if x.Bools == nil { - x.Bools = []bool{} - } - value := &_MsgRequest_21_list{list: &x.Bools} - return protoreflect.ValueOfList(value) - case "testpb.MsgRequest.uints": - if x.Uints == nil { - x.Uints = []uint32{} - } - value := &_MsgRequest_22_list{list: &x.Uints} - return protoreflect.ValueOfList(value) - case "testpb.MsgRequest.strings": - if x.Strings == nil { - x.Strings = []string{} - } - value := &_MsgRequest_23_list{list: &x.Strings} - return protoreflect.ValueOfList(value) - case "testpb.MsgRequest.enums": - if x.Enums == nil { - x.Enums = []Enum{} - } - value := &_MsgRequest_24_list{list: &x.Enums} - return protoreflect.ValueOfList(value) - case "testpb.MsgRequest.durations": - if x.Durations == nil { - x.Durations = []*durationpb.Duration{} - } - value := &_MsgRequest_25_list{list: &x.Durations} - return protoreflect.ValueOfList(value) - case "testpb.MsgRequest.some_messages": - if x.SomeMessages == nil { - x.SomeMessages = []*AMessage{} - } - value := &_MsgRequest_26_list{list: &x.SomeMessages} - return protoreflect.ValueOfList(value) - case "testpb.MsgRequest.positional3_varargs": - if x.Positional3Varargs == nil { - x.Positional3Varargs = []*v1beta1.Coin{} - } - value := &_MsgRequest_29_list{list: &x.Positional3Varargs} - return protoreflect.ValueOfList(value) - case "testpb.MsgRequest.u32": - panic(fmt.Errorf("field u32 of message testpb.MsgRequest is not mutable")) - case "testpb.MsgRequest.u64": - panic(fmt.Errorf("field u64 of message testpb.MsgRequest is not mutable")) - case "testpb.MsgRequest.str": - panic(fmt.Errorf("field str of message testpb.MsgRequest is not mutable")) - case "testpb.MsgRequest.bz": - panic(fmt.Errorf("field bz of message testpb.MsgRequest is not mutable")) - case "testpb.MsgRequest.i32": - panic(fmt.Errorf("field i32 of message testpb.MsgRequest is not mutable")) - case "testpb.MsgRequest.i64": - panic(fmt.Errorf("field i64 of message testpb.MsgRequest is not mutable")) - case "testpb.MsgRequest.a_bool": - panic(fmt.Errorf("field a_bool of message testpb.MsgRequest is not mutable")) - case "testpb.MsgRequest.an_enum": - panic(fmt.Errorf("field an_enum of message testpb.MsgRequest is not mutable")) - case "testpb.MsgRequest.an_address": - panic(fmt.Errorf("field an_address of message testpb.MsgRequest is not mutable")) - case "testpb.MsgRequest.positional1": - panic(fmt.Errorf("field positional1 of message testpb.MsgRequest is not mutable")) - case "testpb.MsgRequest.positional2": - panic(fmt.Errorf("field positional2 of message testpb.MsgRequest is not mutable")) - case "testpb.MsgRequest.deprecated_field": - panic(fmt.Errorf("field deprecated_field of message testpb.MsgRequest is not mutable")) - case "testpb.MsgRequest.shorthand_deprecated_field": - panic(fmt.Errorf("field shorthand_deprecated_field of message testpb.MsgRequest is not mutable")) - case "testpb.MsgRequest.hidden_bool": - panic(fmt.Errorf("field hidden_bool of message testpb.MsgRequest is not mutable")) - case "testpb.MsgRequest.a_validator_address": - panic(fmt.Errorf("field a_validator_address of message testpb.MsgRequest is not mutable")) - default: - if fd.IsExtension() { - panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.MsgRequest")) - } - panic(fmt.Errorf("message testpb.MsgRequest does not contain field %s", fd.FullName())) - } -} - -// NewField returns a new value that is assignable to the field -// for the given descriptor. For scalars, this returns the default value. -// For lists, maps, and messages, this returns a new, empty, mutable value. -func (x *fastReflection_MsgRequest) NewField(fd protoreflect.FieldDescriptor) protoreflect.Value { - switch fd.FullName() { - case "testpb.MsgRequest.u32": - return protoreflect.ValueOfUint32(uint32(0)) - case "testpb.MsgRequest.u64": - return protoreflect.ValueOfUint64(uint64(0)) - case "testpb.MsgRequest.str": - return protoreflect.ValueOfString("") - case "testpb.MsgRequest.bz": - return protoreflect.ValueOfBytes(nil) - case "testpb.MsgRequest.timestamp": - m := new(timestamppb.Timestamp) - return protoreflect.ValueOfMessage(m.ProtoReflect()) - case "testpb.MsgRequest.duration": - m := new(durationpb.Duration) - return protoreflect.ValueOfMessage(m.ProtoReflect()) - case "testpb.MsgRequest.i32": - return protoreflect.ValueOfInt32(int32(0)) - case "testpb.MsgRequest.i64": - return protoreflect.ValueOfInt64(int64(0)) - case "testpb.MsgRequest.a_bool": - return protoreflect.ValueOfBool(false) - case "testpb.MsgRequest.an_enum": - return protoreflect.ValueOfEnum(0) - case "testpb.MsgRequest.a_message": - m := new(AMessage) - return protoreflect.ValueOfMessage(m.ProtoReflect()) - case "testpb.MsgRequest.a_coin": - m := new(v1beta1.Coin) - return protoreflect.ValueOfMessage(m.ProtoReflect()) - case "testpb.MsgRequest.an_address": - return protoreflect.ValueOfString("") - case "testpb.MsgRequest.page": - m := new(v1beta11.PageRequest) - return protoreflect.ValueOfMessage(m.ProtoReflect()) - case "testpb.MsgRequest.bools": - list := []bool{} - return protoreflect.ValueOfList(&_MsgRequest_21_list{list: &list}) - case "testpb.MsgRequest.uints": - list := []uint32{} - return protoreflect.ValueOfList(&_MsgRequest_22_list{list: &list}) - case "testpb.MsgRequest.strings": - list := []string{} - return protoreflect.ValueOfList(&_MsgRequest_23_list{list: &list}) - case "testpb.MsgRequest.enums": - list := []Enum{} - return protoreflect.ValueOfList(&_MsgRequest_24_list{list: &list}) - case "testpb.MsgRequest.durations": - list := []*durationpb.Duration{} - return protoreflect.ValueOfList(&_MsgRequest_25_list{list: &list}) - case "testpb.MsgRequest.some_messages": - list := []*AMessage{} - return protoreflect.ValueOfList(&_MsgRequest_26_list{list: &list}) - case "testpb.MsgRequest.positional1": - return protoreflect.ValueOfInt32(int32(0)) - case "testpb.MsgRequest.positional2": - return protoreflect.ValueOfString("") - case "testpb.MsgRequest.positional3_varargs": - list := []*v1beta1.Coin{} - return protoreflect.ValueOfList(&_MsgRequest_29_list{list: &list}) - case "testpb.MsgRequest.deprecated_field": - return protoreflect.ValueOfString("") - case "testpb.MsgRequest.shorthand_deprecated_field": - return protoreflect.ValueOfString("") - case "testpb.MsgRequest.hidden_bool": - return protoreflect.ValueOfBool(false) - case "testpb.MsgRequest.a_validator_address": - return protoreflect.ValueOfString("") - default: - if fd.IsExtension() { - panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.MsgRequest")) - } - panic(fmt.Errorf("message testpb.MsgRequest does not contain field %s", fd.FullName())) - } -} - -// WhichOneof reports which field within the oneof is populated, -// returning nil if none are populated. -// It panics if the oneof descriptor does not belong to this message. -func (x *fastReflection_MsgRequest) WhichOneof(d protoreflect.OneofDescriptor) protoreflect.FieldDescriptor { - switch d.FullName() { - default: - panic(fmt.Errorf("%s is not a oneof field in testpb.MsgRequest", d.FullName())) - } - panic("unreachable") -} - -// GetUnknown retrieves the entire list of unknown fields. -// The caller may only mutate the contents of the RawFields -// if the mutated bytes are stored back into the message with SetUnknown. -func (x *fastReflection_MsgRequest) GetUnknown() protoreflect.RawFields { - return x.unknownFields -} - -// SetUnknown stores an entire list of unknown fields. -// The raw fields must be syntactically valid according to the wire format. -// An implementation may panic if this is not the case. -// Once stored, the caller must not mutate the content of the RawFields. -// An empty RawFields may be passed to clear the fields. -// -// SetUnknown is a mutating operation and unsafe for concurrent use. -func (x *fastReflection_MsgRequest) SetUnknown(fields protoreflect.RawFields) { - x.unknownFields = fields -} - -// IsValid reports whether the message is valid. -// -// An invalid message is an empty, read-only value. -// -// An invalid message often corresponds to a nil pointer of the concrete -// message type, but the details are implementation dependent. -// Validity is not part of the protobuf data model, and may not -// be preserved in marshaling or other operations. -func (x *fastReflection_MsgRequest) IsValid() bool { - return x != nil -} - -// ProtoMethods returns optional fastReflectionFeature-path implementations of various operations. -// This method may return nil. -// -// The returned methods type is identical to -// "google.golang.org/protobuf/runtime/protoiface".Methods. -// Consult the protoiface package documentation for details. -func (x *fastReflection_MsgRequest) ProtoMethods() *protoiface.Methods { - size := func(input protoiface.SizeInput) protoiface.SizeOutput { - x := input.Message.Interface().(*MsgRequest) - if x == nil { - return protoiface.SizeOutput{ - NoUnkeyedLiterals: input.NoUnkeyedLiterals, - Size: 0, - } - } - options := runtime.SizeInputToOptions(input) - _ = options - var n int - var l int - _ = l - if x.U32 != 0 { - n += 1 + runtime.Sov(uint64(x.U32)) - } - if x.U64 != 0 { - n += 1 + runtime.Sov(uint64(x.U64)) - } - l = len(x.Str) - if l > 0 { - n += 1 + l + runtime.Sov(uint64(l)) - } - l = len(x.Bz) - if l > 0 { - n += 1 + l + runtime.Sov(uint64(l)) - } - if x.Timestamp != nil { - l = options.Size(x.Timestamp) - n += 1 + l + runtime.Sov(uint64(l)) - } - if x.Duration != nil { - l = options.Size(x.Duration) - n += 1 + l + runtime.Sov(uint64(l)) - } - if x.I32 != 0 { - n += 1 + runtime.Sov(uint64(x.I32)) - } - if x.I64 != 0 { - n += 1 + runtime.Sov(uint64(x.I64)) - } - if x.ABool { - n += 2 - } - if x.AnEnum != 0 { - n += 2 + runtime.Sov(uint64(x.AnEnum)) - } - if x.AMessage != nil { - l = options.Size(x.AMessage) - n += 2 + l + runtime.Sov(uint64(l)) - } - if x.ACoin != nil { - l = options.Size(x.ACoin) - n += 2 + l + runtime.Sov(uint64(l)) - } - l = len(x.AnAddress) - if l > 0 { - n += 2 + l + runtime.Sov(uint64(l)) - } - if x.Page != nil { - l = options.Size(x.Page) - n += 2 + l + runtime.Sov(uint64(l)) - } - if len(x.Bools) > 0 { - n += 2 + runtime.Sov(uint64(len(x.Bools))) + len(x.Bools)*1 - } - if len(x.Uints) > 0 { - l = 0 - for _, e := range x.Uints { - l += runtime.Sov(uint64(e)) - } - n += 2 + runtime.Sov(uint64(l)) + l - } - if len(x.Strings) > 0 { - for _, s := range x.Strings { - l = len(s) - n += 2 + l + runtime.Sov(uint64(l)) - } - } - if len(x.Enums) > 0 { - l = 0 - for _, e := range x.Enums { - l += runtime.Sov(uint64(e)) - } - n += 2 + runtime.Sov(uint64(l)) + l - } - if len(x.Durations) > 0 { - for _, e := range x.Durations { - l = options.Size(e) - n += 2 + l + runtime.Sov(uint64(l)) - } - } - if len(x.SomeMessages) > 0 { - for _, e := range x.SomeMessages { - l = options.Size(e) - n += 2 + l + runtime.Sov(uint64(l)) - } - } - if x.Positional1 != 0 { - n += 2 + runtime.Sov(uint64(x.Positional1)) - } - l = len(x.Positional2) - if l > 0 { - n += 2 + l + runtime.Sov(uint64(l)) - } - if len(x.Positional3Varargs) > 0 { - for _, e := range x.Positional3Varargs { - l = options.Size(e) - n += 2 + l + runtime.Sov(uint64(l)) - } - } - l = len(x.DeprecatedField) - if l > 0 { - n += 2 + l + runtime.Sov(uint64(l)) - } - l = len(x.ShorthandDeprecatedField) - if l > 0 { - n += 2 + l + runtime.Sov(uint64(l)) - } - if x.HiddenBool { - n += 3 - } - l = len(x.AValidatorAddress) - if l > 0 { - n += 2 + l + runtime.Sov(uint64(l)) - } - if x.unknownFields != nil { - n += len(x.unknownFields) - } - return protoiface.SizeOutput{ - NoUnkeyedLiterals: input.NoUnkeyedLiterals, - Size: n, - } - } - - marshal := func(input protoiface.MarshalInput) (protoiface.MarshalOutput, error) { - x := input.Message.Interface().(*MsgRequest) - if x == nil { - return protoiface.MarshalOutput{ - NoUnkeyedLiterals: input.NoUnkeyedLiterals, - Buf: input.Buf, - }, nil - } - options := runtime.MarshalInputToOptions(input) - _ = options - size := options.Size(x) - dAtA := make([]byte, size) - i := len(dAtA) - _ = i - var l int - _ = l - if x.unknownFields != nil { - i -= len(x.unknownFields) - copy(dAtA[i:], x.unknownFields) - } - if len(x.AValidatorAddress) > 0 { - i -= len(x.AValidatorAddress) - copy(dAtA[i:], x.AValidatorAddress) - i = runtime.EncodeVarint(dAtA, i, uint64(len(x.AValidatorAddress))) - i-- - dAtA[i] = 0x2 - i-- - dAtA[i] = 0x8a - } - if x.HiddenBool { - i-- - if x.HiddenBool { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i-- - dAtA[i] = 0x2 - i-- - dAtA[i] = 0x80 - } - if len(x.ShorthandDeprecatedField) > 0 { - i -= len(x.ShorthandDeprecatedField) - copy(dAtA[i:], x.ShorthandDeprecatedField) - i = runtime.EncodeVarint(dAtA, i, uint64(len(x.ShorthandDeprecatedField))) - i-- - dAtA[i] = 0x1 - i-- - dAtA[i] = 0xfa - } - if len(x.DeprecatedField) > 0 { - i -= len(x.DeprecatedField) - copy(dAtA[i:], x.DeprecatedField) - i = runtime.EncodeVarint(dAtA, i, uint64(len(x.DeprecatedField))) - i-- - dAtA[i] = 0x1 - i-- - dAtA[i] = 0xf2 - } - if len(x.Positional3Varargs) > 0 { - for iNdEx := len(x.Positional3Varargs) - 1; iNdEx >= 0; iNdEx-- { - encoded, err := options.Marshal(x.Positional3Varargs[iNdEx]) - if err != nil { - return protoiface.MarshalOutput{ - NoUnkeyedLiterals: input.NoUnkeyedLiterals, - Buf: input.Buf, - }, err - } - i -= len(encoded) - copy(dAtA[i:], encoded) - i = runtime.EncodeVarint(dAtA, i, uint64(len(encoded))) - i-- - dAtA[i] = 0x1 - i-- - dAtA[i] = 0xea - } - } - if len(x.Positional2) > 0 { - i -= len(x.Positional2) - copy(dAtA[i:], x.Positional2) - i = runtime.EncodeVarint(dAtA, i, uint64(len(x.Positional2))) - i-- - dAtA[i] = 0x1 - i-- - dAtA[i] = 0xe2 - } - if x.Positional1 != 0 { - i = runtime.EncodeVarint(dAtA, i, uint64(x.Positional1)) - i-- - dAtA[i] = 0x1 - i-- - dAtA[i] = 0xd8 - } - if len(x.SomeMessages) > 0 { - for iNdEx := len(x.SomeMessages) - 1; iNdEx >= 0; iNdEx-- { - encoded, err := options.Marshal(x.SomeMessages[iNdEx]) - if err != nil { - return protoiface.MarshalOutput{ - NoUnkeyedLiterals: input.NoUnkeyedLiterals, - Buf: input.Buf, - }, err - } - i -= len(encoded) - copy(dAtA[i:], encoded) - i = runtime.EncodeVarint(dAtA, i, uint64(len(encoded))) - i-- - dAtA[i] = 0x1 - i-- - dAtA[i] = 0xd2 - } - } - if len(x.Durations) > 0 { - for iNdEx := len(x.Durations) - 1; iNdEx >= 0; iNdEx-- { - encoded, err := options.Marshal(x.Durations[iNdEx]) - if err != nil { - return protoiface.MarshalOutput{ - NoUnkeyedLiterals: input.NoUnkeyedLiterals, - Buf: input.Buf, - }, err - } - i -= len(encoded) - copy(dAtA[i:], encoded) - i = runtime.EncodeVarint(dAtA, i, uint64(len(encoded))) - i-- - dAtA[i] = 0x1 - i-- - dAtA[i] = 0xca - } - } - if len(x.Enums) > 0 { - var pksize2 int - for _, num := range x.Enums { - pksize2 += runtime.Sov(uint64(num)) - } - i -= pksize2 - j1 := i - for _, num1 := range x.Enums { - num := uint64(num1) - for num >= 1<<7 { - dAtA[j1] = uint8(uint64(num)&0x7f | 0x80) - num >>= 7 - j1++ - } - dAtA[j1] = uint8(num) - j1++ - } - i = runtime.EncodeVarint(dAtA, i, uint64(pksize2)) - i-- - dAtA[i] = 0x1 - i-- - dAtA[i] = 0xc2 - } - if len(x.Strings) > 0 { - for iNdEx := len(x.Strings) - 1; iNdEx >= 0; iNdEx-- { - i -= len(x.Strings[iNdEx]) - copy(dAtA[i:], x.Strings[iNdEx]) - i = runtime.EncodeVarint(dAtA, i, uint64(len(x.Strings[iNdEx]))) - i-- - dAtA[i] = 0x1 - i-- - dAtA[i] = 0xba - } - } - if len(x.Uints) > 0 { - var pksize4 int - for _, num := range x.Uints { - pksize4 += runtime.Sov(uint64(num)) - } - i -= pksize4 - j3 := i - for _, num := range x.Uints { - for num >= 1<<7 { - dAtA[j3] = uint8(uint64(num)&0x7f | 0x80) - num >>= 7 - j3++ - } - dAtA[j3] = uint8(num) - j3++ - } - i = runtime.EncodeVarint(dAtA, i, uint64(pksize4)) - i-- - dAtA[i] = 0x1 - i-- - dAtA[i] = 0xb2 - } - if len(x.Bools) > 0 { - for iNdEx := len(x.Bools) - 1; iNdEx >= 0; iNdEx-- { - i-- - if x.Bools[iNdEx] { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - } - i = runtime.EncodeVarint(dAtA, i, uint64(len(x.Bools))) - i-- - dAtA[i] = 0x1 - i-- - dAtA[i] = 0xaa - } - if x.Page != nil { - encoded, err := options.Marshal(x.Page) - if err != nil { - return protoiface.MarshalOutput{ - NoUnkeyedLiterals: input.NoUnkeyedLiterals, - Buf: input.Buf, - }, err - } - i -= len(encoded) - copy(dAtA[i:], encoded) - i = runtime.EncodeVarint(dAtA, i, uint64(len(encoded))) - i-- - dAtA[i] = 0x1 - i-- - dAtA[i] = 0xa2 - } - if len(x.AnAddress) > 0 { - i -= len(x.AnAddress) - copy(dAtA[i:], x.AnAddress) - i = runtime.EncodeVarint(dAtA, i, uint64(len(x.AnAddress))) - i-- - dAtA[i] = 0x1 - i-- - dAtA[i] = 0x9a - } - if x.ACoin != nil { - encoded, err := options.Marshal(x.ACoin) - if err != nil { - return protoiface.MarshalOutput{ - NoUnkeyedLiterals: input.NoUnkeyedLiterals, - Buf: input.Buf, - }, err - } - i -= len(encoded) - copy(dAtA[i:], encoded) - i = runtime.EncodeVarint(dAtA, i, uint64(len(encoded))) - i-- - dAtA[i] = 0x1 - i-- - dAtA[i] = 0x92 - } - if x.AMessage != nil { - encoded, err := options.Marshal(x.AMessage) - if err != nil { - return protoiface.MarshalOutput{ - NoUnkeyedLiterals: input.NoUnkeyedLiterals, - Buf: input.Buf, - }, err - } - i -= len(encoded) - copy(dAtA[i:], encoded) - i = runtime.EncodeVarint(dAtA, i, uint64(len(encoded))) - i-- - dAtA[i] = 0x1 - i-- - dAtA[i] = 0x8a - } - if x.AnEnum != 0 { - i = runtime.EncodeVarint(dAtA, i, uint64(x.AnEnum)) - i-- - dAtA[i] = 0x1 - i-- - dAtA[i] = 0x80 - } - if x.ABool { - i-- - if x.ABool { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i-- - dAtA[i] = 0x78 - } - if x.I64 != 0 { - i = runtime.EncodeVarint(dAtA, i, uint64(x.I64)) - i-- - dAtA[i] = 0x50 - } - if x.I32 != 0 { - i = runtime.EncodeVarint(dAtA, i, uint64(x.I32)) - i-- - dAtA[i] = 0x38 - } - if x.Duration != nil { - encoded, err := options.Marshal(x.Duration) - if err != nil { - return protoiface.MarshalOutput{ - NoUnkeyedLiterals: input.NoUnkeyedLiterals, - Buf: input.Buf, - }, err - } - i -= len(encoded) - copy(dAtA[i:], encoded) - i = runtime.EncodeVarint(dAtA, i, uint64(len(encoded))) - i-- - dAtA[i] = 0x32 - } - if x.Timestamp != nil { - encoded, err := options.Marshal(x.Timestamp) - if err != nil { - return protoiface.MarshalOutput{ - NoUnkeyedLiterals: input.NoUnkeyedLiterals, - Buf: input.Buf, - }, err - } - i -= len(encoded) - copy(dAtA[i:], encoded) - i = runtime.EncodeVarint(dAtA, i, uint64(len(encoded))) - i-- - dAtA[i] = 0x2a - } - if len(x.Bz) > 0 { - i -= len(x.Bz) - copy(dAtA[i:], x.Bz) - i = runtime.EncodeVarint(dAtA, i, uint64(len(x.Bz))) - i-- - dAtA[i] = 0x22 - } - if len(x.Str) > 0 { - i -= len(x.Str) - copy(dAtA[i:], x.Str) - i = runtime.EncodeVarint(dAtA, i, uint64(len(x.Str))) - i-- - dAtA[i] = 0x1a - } - if x.U64 != 0 { - i = runtime.EncodeVarint(dAtA, i, uint64(x.U64)) - i-- - dAtA[i] = 0x10 - } - if x.U32 != 0 { - i = runtime.EncodeVarint(dAtA, i, uint64(x.U32)) - i-- - dAtA[i] = 0x8 - } - if input.Buf != nil { - input.Buf = append(input.Buf, dAtA...) - } else { - input.Buf = dAtA - } - return protoiface.MarshalOutput{ - NoUnkeyedLiterals: input.NoUnkeyedLiterals, - Buf: input.Buf, - }, nil - } - unmarshal := func(input protoiface.UnmarshalInput) (protoiface.UnmarshalOutput, error) { - x := input.Message.Interface().(*MsgRequest) - if x == nil { - return protoiface.UnmarshalOutput{ - NoUnkeyedLiterals: input.NoUnkeyedLiterals, - Flags: input.Flags, - }, nil - } - options := runtime.UnmarshalInputToOptions(input) - _ = options - dAtA := input.Buf - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: MsgRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: MsgRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field U32", wireType) - } - x.U32 = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - x.U32 |= uint32(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field U64", wireType) - } - x.U64 = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - x.U64 |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 3: - if wireType != 2 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Str", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - if postIndex > l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - x.Str = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 4: - if wireType != 2 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Bz", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - if postIndex > l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - x.Bz = append(x.Bz[:0], dAtA[iNdEx:postIndex]...) - if x.Bz == nil { - x.Bz = []byte{} - } - iNdEx = postIndex - case 5: - if wireType != 2 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Timestamp", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - if postIndex > l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - if x.Timestamp == nil { - x.Timestamp = ×tamppb.Timestamp{} - } - if err := options.Unmarshal(dAtA[iNdEx:postIndex], x.Timestamp); err != nil { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err - } - iNdEx = postIndex - case 6: - if wireType != 2 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Duration", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - if postIndex > l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - if x.Duration == nil { - x.Duration = &durationpb.Duration{} - } - if err := options.Unmarshal(dAtA[iNdEx:postIndex], x.Duration); err != nil { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err - } - iNdEx = postIndex - case 7: - if wireType != 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field I32", wireType) - } - x.I32 = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - x.I32 |= int32(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 10: - if wireType != 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field I64", wireType) - } - x.I64 = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - x.I64 |= int64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 15: - if wireType != 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field ABool", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - x.ABool = bool(v != 0) - case 16: - if wireType != 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field AnEnum", wireType) - } - x.AnEnum = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - x.AnEnum |= Enum(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 17: - if wireType != 2 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field AMessage", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - if postIndex > l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - if x.AMessage == nil { - x.AMessage = &AMessage{} - } - if err := options.Unmarshal(dAtA[iNdEx:postIndex], x.AMessage); err != nil { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err - } - iNdEx = postIndex - case 18: - if wireType != 2 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field ACoin", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - if postIndex > l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - if x.ACoin == nil { - x.ACoin = &v1beta1.Coin{} - } - if err := options.Unmarshal(dAtA[iNdEx:postIndex], x.ACoin); err != nil { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err - } - iNdEx = postIndex - case 19: - if wireType != 2 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field AnAddress", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - if postIndex > l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - x.AnAddress = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 20: - if wireType != 2 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Page", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - if postIndex > l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - if x.Page == nil { - x.Page = &v1beta11.PageRequest{} - } - if err := options.Unmarshal(dAtA[iNdEx:postIndex], x.Page); err != nil { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err - } - iNdEx = postIndex - case 21: - if wireType == 0 { - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - x.Bools = append(x.Bools, bool(v != 0)) - } else if wireType == 2 { - var packedLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - packedLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if packedLen < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - postIndex := iNdEx + packedLen - if postIndex < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - if postIndex > l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - var elementCount int - elementCount = packedLen - if elementCount != 0 && len(x.Bools) == 0 { - x.Bools = make([]bool, 0, elementCount) - } - for iNdEx < postIndex { - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - x.Bools = append(x.Bools, bool(v != 0)) - } - } else { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Bools", wireType) - } - case 22: - if wireType == 0 { - var v uint32 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= uint32(b&0x7F) << shift - if b < 0x80 { - break - } - } - x.Uints = append(x.Uints, v) - } else if wireType == 2 { - var packedLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - packedLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if packedLen < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - postIndex := iNdEx + packedLen - if postIndex < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - if postIndex > l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - var elementCount int - var count int - for _, integer := range dAtA[iNdEx:postIndex] { - if integer < 128 { - count++ - } - } - elementCount = count - if elementCount != 0 && len(x.Uints) == 0 { - x.Uints = make([]uint32, 0, elementCount) - } - for iNdEx < postIndex { - var v uint32 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= uint32(b&0x7F) << shift - if b < 0x80 { - break - } - } - x.Uints = append(x.Uints, v) - } - } else { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Uints", wireType) - } - case 23: - if wireType != 2 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Strings", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - if postIndex > l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - x.Strings = append(x.Strings, string(dAtA[iNdEx:postIndex])) - iNdEx = postIndex - case 24: - if wireType == 0 { - var v Enum - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= Enum(b&0x7F) << shift - if b < 0x80 { - break - } - } - x.Enums = append(x.Enums, v) - } else if wireType == 2 { - var packedLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - packedLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if packedLen < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - postIndex := iNdEx + packedLen - if postIndex < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - if postIndex > l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - var elementCount int - if elementCount != 0 && len(x.Enums) == 0 { - x.Enums = make([]Enum, 0, elementCount) - } - for iNdEx < postIndex { - var v Enum - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= Enum(b&0x7F) << shift - if b < 0x80 { - break - } - } - x.Enums = append(x.Enums, v) - } - } else { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Enums", wireType) - } - case 25: - if wireType != 2 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Durations", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - if postIndex > l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - x.Durations = append(x.Durations, &durationpb.Duration{}) - if err := options.Unmarshal(dAtA[iNdEx:postIndex], x.Durations[len(x.Durations)-1]); err != nil { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err - } - iNdEx = postIndex - case 26: - if wireType != 2 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field SomeMessages", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - if postIndex > l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - x.SomeMessages = append(x.SomeMessages, &AMessage{}) - if err := options.Unmarshal(dAtA[iNdEx:postIndex], x.SomeMessages[len(x.SomeMessages)-1]); err != nil { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err - } - iNdEx = postIndex - case 27: - if wireType != 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Positional1", wireType) - } - x.Positional1 = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - x.Positional1 |= int32(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 28: - if wireType != 2 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Positional2", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - if postIndex > l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - x.Positional2 = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 29: - if wireType != 2 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Positional3Varargs", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - if postIndex > l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - x.Positional3Varargs = append(x.Positional3Varargs, &v1beta1.Coin{}) - if err := options.Unmarshal(dAtA[iNdEx:postIndex], x.Positional3Varargs[len(x.Positional3Varargs)-1]); err != nil { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err - } - iNdEx = postIndex - case 30: - if wireType != 2 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field DeprecatedField", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - if postIndex > l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - x.DeprecatedField = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 31: - if wireType != 2 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field ShorthandDeprecatedField", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - if postIndex > l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - x.ShorthandDeprecatedField = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 32: - if wireType != 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field HiddenBool", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - x.HiddenBool = bool(v != 0) - case 33: - if wireType != 2 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field AValidatorAddress", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - if postIndex > l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - x.AValidatorAddress = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := runtime.Skip(dAtA[iNdEx:]) - if err != nil { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - if (iNdEx + skippy) > l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - if !options.DiscardUnknown { - x.unknownFields = append(x.unknownFields, dAtA[iNdEx:iNdEx+skippy]...) - } - iNdEx += skippy - } - } - - if iNdEx > l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, nil - } - return &protoiface.Methods{ - NoUnkeyedLiterals: struct{}{}, - Flags: protoiface.SupportMarshalDeterministic | protoiface.SupportUnmarshalDiscardUnknown, - Size: size, - Marshal: marshal, - Unmarshal: unmarshal, - Merge: nil, - CheckInitialized: nil, - } -} - -var ( - md_MsgResponse protoreflect.MessageDescriptor - fd_MsgResponse_request protoreflect.FieldDescriptor -) - -func init() { - file_testpb_msg_proto_init() - md_MsgResponse = File_testpb_msg_proto.Messages().ByName("MsgResponse") - fd_MsgResponse_request = md_MsgResponse.Fields().ByName("request") -} - -var _ protoreflect.Message = (*fastReflection_MsgResponse)(nil) - -type fastReflection_MsgResponse MsgResponse - -func (x *MsgResponse) ProtoReflect() protoreflect.Message { - return (*fastReflection_MsgResponse)(x) -} - -func (x *MsgResponse) slowProtoReflect() protoreflect.Message { - mi := &file_testpb_msg_proto_msgTypes[1] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -var _fastReflection_MsgResponse_messageType fastReflection_MsgResponse_messageType -var _ protoreflect.MessageType = fastReflection_MsgResponse_messageType{} - -type fastReflection_MsgResponse_messageType struct{} - -func (x fastReflection_MsgResponse_messageType) Zero() protoreflect.Message { - return (*fastReflection_MsgResponse)(nil) -} -func (x fastReflection_MsgResponse_messageType) New() protoreflect.Message { - return new(fastReflection_MsgResponse) -} -func (x fastReflection_MsgResponse_messageType) Descriptor() protoreflect.MessageDescriptor { - return md_MsgResponse -} - -// Descriptor returns message descriptor, which contains only the protobuf -// type information for the message. -func (x *fastReflection_MsgResponse) Descriptor() protoreflect.MessageDescriptor { - return md_MsgResponse -} - -// Type returns the message type, which encapsulates both Go and protobuf -// type information. If the Go type information is not needed, -// it is recommended that the message descriptor be used instead. -func (x *fastReflection_MsgResponse) Type() protoreflect.MessageType { - return _fastReflection_MsgResponse_messageType -} - -// New returns a newly allocated and mutable empty message. -func (x *fastReflection_MsgResponse) New() protoreflect.Message { - return new(fastReflection_MsgResponse) -} - -// Interface unwraps the message reflection interface and -// returns the underlying ProtoMessage interface. -func (x *fastReflection_MsgResponse) Interface() protoreflect.ProtoMessage { - return (*MsgResponse)(x) -} - -// Range iterates over every populated field in an undefined order, -// calling f for each field descriptor and value encountered. -// Range returns immediately if f returns false. -// While iterating, mutating operations may only be performed -// on the current field descriptor. -func (x *fastReflection_MsgResponse) Range(f func(protoreflect.FieldDescriptor, protoreflect.Value) bool) { - if x.Request != nil { - value := protoreflect.ValueOfMessage(x.Request.ProtoReflect()) - if !f(fd_MsgResponse_request, value) { - return - } - } -} - -// Has reports whether a field is populated. -// -// Some fields have the property of nullability where it is possible to -// distinguish between the default value of a field and whether the field -// was explicitly populated with the default value. Singular message fields, -// member fields of a oneof, and proto2 scalar fields are nullable. Such -// fields are populated only if explicitly set. -// -// In other cases (aside from the nullable cases above), -// a proto3 scalar field is populated if it contains a non-zero value, and -// a repeated field is populated if it is non-empty. -func (x *fastReflection_MsgResponse) Has(fd protoreflect.FieldDescriptor) bool { - switch fd.FullName() { - case "testpb.MsgResponse.request": - return x.Request != nil - default: - if fd.IsExtension() { - panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.MsgResponse")) - } - panic(fmt.Errorf("message testpb.MsgResponse does not contain field %s", fd.FullName())) - } -} - -// Clear clears the field such that a subsequent Has call reports false. -// -// Clearing an extension field clears both the extension type and value -// associated with the given field number. -// -// Clear is a mutating operation and unsafe for concurrent use. -func (x *fastReflection_MsgResponse) Clear(fd protoreflect.FieldDescriptor) { - switch fd.FullName() { - case "testpb.MsgResponse.request": - x.Request = nil - default: - if fd.IsExtension() { - panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.MsgResponse")) - } - panic(fmt.Errorf("message testpb.MsgResponse does not contain field %s", fd.FullName())) - } -} - -// Get retrieves the value for a field. -// -// For unpopulated scalars, it returns the default value, where -// the default value of a bytes scalar is guaranteed to be a copy. -// For unpopulated composite types, it returns an empty, read-only view -// of the value; to obtain a mutable reference, use Mutable. -func (x *fastReflection_MsgResponse) Get(descriptor protoreflect.FieldDescriptor) protoreflect.Value { - switch descriptor.FullName() { - case "testpb.MsgResponse.request": - value := x.Request - return protoreflect.ValueOfMessage(value.ProtoReflect()) - default: - if descriptor.IsExtension() { - panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.MsgResponse")) - } - panic(fmt.Errorf("message testpb.MsgResponse does not contain field %s", descriptor.FullName())) - } -} - -// Set stores the value for a field. -// -// For a field belonging to a oneof, it implicitly clears any other field -// that may be currently set within the same oneof. -// For extension fields, it implicitly stores the provided ExtensionType. -// When setting a composite type, it is unspecified whether the stored value -// aliases the source's memory in any way. If the composite value is an -// empty, read-only value, then it panics. -// -// Set is a mutating operation and unsafe for concurrent use. -func (x *fastReflection_MsgResponse) Set(fd protoreflect.FieldDescriptor, value protoreflect.Value) { - switch fd.FullName() { - case "testpb.MsgResponse.request": - x.Request = value.Message().Interface().(*MsgRequest) - default: - if fd.IsExtension() { - panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.MsgResponse")) - } - panic(fmt.Errorf("message testpb.MsgResponse does not contain field %s", fd.FullName())) - } -} - -// Mutable returns a mutable reference to a composite type. -// -// If the field is unpopulated, it may allocate a composite value. -// For a field belonging to a oneof, it implicitly clears any other field -// that may be currently set within the same oneof. -// For extension fields, it implicitly stores the provided ExtensionType -// if not already stored. -// It panics if the field does not contain a composite type. -// -// Mutable is a mutating operation and unsafe for concurrent use. -func (x *fastReflection_MsgResponse) Mutable(fd protoreflect.FieldDescriptor) protoreflect.Value { - switch fd.FullName() { - case "testpb.MsgResponse.request": - if x.Request == nil { - x.Request = new(MsgRequest) - } - return protoreflect.ValueOfMessage(x.Request.ProtoReflect()) - default: - if fd.IsExtension() { - panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.MsgResponse")) - } - panic(fmt.Errorf("message testpb.MsgResponse does not contain field %s", fd.FullName())) - } -} - -// NewField returns a new value that is assignable to the field -// for the given descriptor. For scalars, this returns the default value. -// For lists, maps, and messages, this returns a new, empty, mutable value. -func (x *fastReflection_MsgResponse) NewField(fd protoreflect.FieldDescriptor) protoreflect.Value { - switch fd.FullName() { - case "testpb.MsgResponse.request": - m := new(MsgRequest) - return protoreflect.ValueOfMessage(m.ProtoReflect()) - default: - if fd.IsExtension() { - panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.MsgResponse")) - } - panic(fmt.Errorf("message testpb.MsgResponse does not contain field %s", fd.FullName())) - } -} - -// WhichOneof reports which field within the oneof is populated, -// returning nil if none are populated. -// It panics if the oneof descriptor does not belong to this message. -func (x *fastReflection_MsgResponse) WhichOneof(d protoreflect.OneofDescriptor) protoreflect.FieldDescriptor { - switch d.FullName() { - default: - panic(fmt.Errorf("%s is not a oneof field in testpb.MsgResponse", d.FullName())) - } - panic("unreachable") -} - -// GetUnknown retrieves the entire list of unknown fields. -// The caller may only mutate the contents of the RawFields -// if the mutated bytes are stored back into the message with SetUnknown. -func (x *fastReflection_MsgResponse) GetUnknown() protoreflect.RawFields { - return x.unknownFields -} - -// SetUnknown stores an entire list of unknown fields. -// The raw fields must be syntactically valid according to the wire format. -// An implementation may panic if this is not the case. -// Once stored, the caller must not mutate the content of the RawFields. -// An empty RawFields may be passed to clear the fields. -// -// SetUnknown is a mutating operation and unsafe for concurrent use. -func (x *fastReflection_MsgResponse) SetUnknown(fields protoreflect.RawFields) { - x.unknownFields = fields -} - -// IsValid reports whether the message is valid. -// -// An invalid message is an empty, read-only value. -// -// An invalid message often corresponds to a nil pointer of the concrete -// message type, but the details are implementation dependent. -// Validity is not part of the protobuf data model, and may not -// be preserved in marshaling or other operations. -func (x *fastReflection_MsgResponse) IsValid() bool { - return x != nil -} - -// ProtoMethods returns optional fastReflectionFeature-path implementations of various operations. -// This method may return nil. -// -// The returned methods type is identical to -// "google.golang.org/protobuf/runtime/protoiface".Methods. -// Consult the protoiface package documentation for details. -func (x *fastReflection_MsgResponse) ProtoMethods() *protoiface.Methods { - size := func(input protoiface.SizeInput) protoiface.SizeOutput { - x := input.Message.Interface().(*MsgResponse) - if x == nil { - return protoiface.SizeOutput{ - NoUnkeyedLiterals: input.NoUnkeyedLiterals, - Size: 0, - } - } - options := runtime.SizeInputToOptions(input) - _ = options - var n int - var l int - _ = l - if x.Request != nil { - l = options.Size(x.Request) - n += 1 + l + runtime.Sov(uint64(l)) - } - if x.unknownFields != nil { - n += len(x.unknownFields) - } - return protoiface.SizeOutput{ - NoUnkeyedLiterals: input.NoUnkeyedLiterals, - Size: n, - } - } - - marshal := func(input protoiface.MarshalInput) (protoiface.MarshalOutput, error) { - x := input.Message.Interface().(*MsgResponse) - if x == nil { - return protoiface.MarshalOutput{ - NoUnkeyedLiterals: input.NoUnkeyedLiterals, - Buf: input.Buf, - }, nil - } - options := runtime.MarshalInputToOptions(input) - _ = options - size := options.Size(x) - dAtA := make([]byte, size) - i := len(dAtA) - _ = i - var l int - _ = l - if x.unknownFields != nil { - i -= len(x.unknownFields) - copy(dAtA[i:], x.unknownFields) - } - if x.Request != nil { - encoded, err := options.Marshal(x.Request) - if err != nil { - return protoiface.MarshalOutput{ - NoUnkeyedLiterals: input.NoUnkeyedLiterals, - Buf: input.Buf, - }, err - } - i -= len(encoded) - copy(dAtA[i:], encoded) - i = runtime.EncodeVarint(dAtA, i, uint64(len(encoded))) - i-- - dAtA[i] = 0xa - } - if input.Buf != nil { - input.Buf = append(input.Buf, dAtA...) - } else { - input.Buf = dAtA - } - return protoiface.MarshalOutput{ - NoUnkeyedLiterals: input.NoUnkeyedLiterals, - Buf: input.Buf, - }, nil - } - unmarshal := func(input protoiface.UnmarshalInput) (protoiface.UnmarshalOutput, error) { - x := input.Message.Interface().(*MsgResponse) - if x == nil { - return protoiface.UnmarshalOutput{ - NoUnkeyedLiterals: input.NoUnkeyedLiterals, - Flags: input.Flags, - }, nil - } - options := runtime.UnmarshalInputToOptions(input) - _ = options - dAtA := input.Buf - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: MsgResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: MsgResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Request", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - if postIndex > l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - if x.Request == nil { - x.Request = &MsgRequest{} - } - if err := options.Unmarshal(dAtA[iNdEx:postIndex], x.Request); err != nil { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := runtime.Skip(dAtA[iNdEx:]) - if err != nil { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - if (iNdEx + skippy) > l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - if !options.DiscardUnknown { - x.unknownFields = append(x.unknownFields, dAtA[iNdEx:iNdEx+skippy]...) - } - iNdEx += skippy - } - } - - if iNdEx > l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, nil - } - return &protoiface.Methods{ - NoUnkeyedLiterals: struct{}{}, - Flags: protoiface.SupportMarshalDeterministic | protoiface.SupportUnmarshalDiscardUnknown, - Size: size, - Marshal: marshal, - Unmarshal: unmarshal, - Merge: nil, - CheckInitialized: nil, - } -} - -var ( - md_MsgClawbackRequest protoreflect.MessageDescriptor -) - -func init() { - file_testpb_msg_proto_init() - md_MsgClawbackRequest = File_testpb_msg_proto.Messages().ByName("MsgClawbackRequest") -} - -var _ protoreflect.Message = (*fastReflection_MsgClawbackRequest)(nil) - -type fastReflection_MsgClawbackRequest MsgClawbackRequest - -func (x *MsgClawbackRequest) ProtoReflect() protoreflect.Message { - return (*fastReflection_MsgClawbackRequest)(x) -} - -func (x *MsgClawbackRequest) slowProtoReflect() protoreflect.Message { - mi := &file_testpb_msg_proto_msgTypes[2] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -var _fastReflection_MsgClawbackRequest_messageType fastReflection_MsgClawbackRequest_messageType -var _ protoreflect.MessageType = fastReflection_MsgClawbackRequest_messageType{} - -type fastReflection_MsgClawbackRequest_messageType struct{} - -func (x fastReflection_MsgClawbackRequest_messageType) Zero() protoreflect.Message { - return (*fastReflection_MsgClawbackRequest)(nil) -} -func (x fastReflection_MsgClawbackRequest_messageType) New() protoreflect.Message { - return new(fastReflection_MsgClawbackRequest) -} -func (x fastReflection_MsgClawbackRequest_messageType) Descriptor() protoreflect.MessageDescriptor { - return md_MsgClawbackRequest -} - -// Descriptor returns message descriptor, which contains only the protobuf -// type information for the message. -func (x *fastReflection_MsgClawbackRequest) Descriptor() protoreflect.MessageDescriptor { - return md_MsgClawbackRequest -} - -// Type returns the message type, which encapsulates both Go and protobuf -// type information. If the Go type information is not needed, -// it is recommended that the message descriptor be used instead. -func (x *fastReflection_MsgClawbackRequest) Type() protoreflect.MessageType { - return _fastReflection_MsgClawbackRequest_messageType -} - -// New returns a newly allocated and mutable empty message. -func (x *fastReflection_MsgClawbackRequest) New() protoreflect.Message { - return new(fastReflection_MsgClawbackRequest) -} - -// Interface unwraps the message reflection interface and -// returns the underlying ProtoMessage interface. -func (x *fastReflection_MsgClawbackRequest) Interface() protoreflect.ProtoMessage { - return (*MsgClawbackRequest)(x) -} - -// Range iterates over every populated field in an undefined order, -// calling f for each field descriptor and value encountered. -// Range returns immediately if f returns false. -// While iterating, mutating operations may only be performed -// on the current field descriptor. -func (x *fastReflection_MsgClawbackRequest) Range(f func(protoreflect.FieldDescriptor, protoreflect.Value) bool) { -} - -// Has reports whether a field is populated. -// -// Some fields have the property of nullability where it is possible to -// distinguish between the default value of a field and whether the field -// was explicitly populated with the default value. Singular message fields, -// member fields of a oneof, and proto2 scalar fields are nullable. Such -// fields are populated only if explicitly set. -// -// In other cases (aside from the nullable cases above), -// a proto3 scalar field is populated if it contains a non-zero value, and -// a repeated field is populated if it is non-empty. -func (x *fastReflection_MsgClawbackRequest) Has(fd protoreflect.FieldDescriptor) bool { - switch fd.FullName() { - default: - if fd.IsExtension() { - panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.MsgClawbackRequest")) - } - panic(fmt.Errorf("message testpb.MsgClawbackRequest does not contain field %s", fd.FullName())) - } -} - -// Clear clears the field such that a subsequent Has call reports false. -// -// Clearing an extension field clears both the extension type and value -// associated with the given field number. -// -// Clear is a mutating operation and unsafe for concurrent use. -func (x *fastReflection_MsgClawbackRequest) Clear(fd protoreflect.FieldDescriptor) { - switch fd.FullName() { - default: - if fd.IsExtension() { - panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.MsgClawbackRequest")) - } - panic(fmt.Errorf("message testpb.MsgClawbackRequest does not contain field %s", fd.FullName())) - } -} - -// Get retrieves the value for a field. -// -// For unpopulated scalars, it returns the default value, where -// the default value of a bytes scalar is guaranteed to be a copy. -// For unpopulated composite types, it returns an empty, read-only view -// of the value; to obtain a mutable reference, use Mutable. -func (x *fastReflection_MsgClawbackRequest) Get(descriptor protoreflect.FieldDescriptor) protoreflect.Value { - switch descriptor.FullName() { - default: - if descriptor.IsExtension() { - panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.MsgClawbackRequest")) - } - panic(fmt.Errorf("message testpb.MsgClawbackRequest does not contain field %s", descriptor.FullName())) - } -} - -// Set stores the value for a field. -// -// For a field belonging to a oneof, it implicitly clears any other field -// that may be currently set within the same oneof. -// For extension fields, it implicitly stores the provided ExtensionType. -// When setting a composite type, it is unspecified whether the stored value -// aliases the source's memory in any way. If the composite value is an -// empty, read-only value, then it panics. -// -// Set is a mutating operation and unsafe for concurrent use. -func (x *fastReflection_MsgClawbackRequest) Set(fd protoreflect.FieldDescriptor, value protoreflect.Value) { - switch fd.FullName() { - default: - if fd.IsExtension() { - panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.MsgClawbackRequest")) - } - panic(fmt.Errorf("message testpb.MsgClawbackRequest does not contain field %s", fd.FullName())) - } -} - -// Mutable returns a mutable reference to a composite type. -// -// If the field is unpopulated, it may allocate a composite value. -// For a field belonging to a oneof, it implicitly clears any other field -// that may be currently set within the same oneof. -// For extension fields, it implicitly stores the provided ExtensionType -// if not already stored. -// It panics if the field does not contain a composite type. -// -// Mutable is a mutating operation and unsafe for concurrent use. -func (x *fastReflection_MsgClawbackRequest) Mutable(fd protoreflect.FieldDescriptor) protoreflect.Value { - switch fd.FullName() { - default: - if fd.IsExtension() { - panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.MsgClawbackRequest")) - } - panic(fmt.Errorf("message testpb.MsgClawbackRequest does not contain field %s", fd.FullName())) - } -} - -// NewField returns a new value that is assignable to the field -// for the given descriptor. For scalars, this returns the default value. -// For lists, maps, and messages, this returns a new, empty, mutable value. -func (x *fastReflection_MsgClawbackRequest) NewField(fd protoreflect.FieldDescriptor) protoreflect.Value { - switch fd.FullName() { - default: - if fd.IsExtension() { - panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.MsgClawbackRequest")) - } - panic(fmt.Errorf("message testpb.MsgClawbackRequest does not contain field %s", fd.FullName())) - } -} - -// WhichOneof reports which field within the oneof is populated, -// returning nil if none are populated. -// It panics if the oneof descriptor does not belong to this message. -func (x *fastReflection_MsgClawbackRequest) WhichOneof(d protoreflect.OneofDescriptor) protoreflect.FieldDescriptor { - switch d.FullName() { - default: - panic(fmt.Errorf("%s is not a oneof field in testpb.MsgClawbackRequest", d.FullName())) - } - panic("unreachable") -} - -// GetUnknown retrieves the entire list of unknown fields. -// The caller may only mutate the contents of the RawFields -// if the mutated bytes are stored back into the message with SetUnknown. -func (x *fastReflection_MsgClawbackRequest) GetUnknown() protoreflect.RawFields { - return x.unknownFields -} - -// SetUnknown stores an entire list of unknown fields. -// The raw fields must be syntactically valid according to the wire format. -// An implementation may panic if this is not the case. -// Once stored, the caller must not mutate the content of the RawFields. -// An empty RawFields may be passed to clear the fields. -// -// SetUnknown is a mutating operation and unsafe for concurrent use. -func (x *fastReflection_MsgClawbackRequest) SetUnknown(fields protoreflect.RawFields) { - x.unknownFields = fields -} - -// IsValid reports whether the message is valid. -// -// An invalid message is an empty, read-only value. -// -// An invalid message often corresponds to a nil pointer of the concrete -// message type, but the details are implementation dependent. -// Validity is not part of the protobuf data model, and may not -// be preserved in marshaling or other operations. -func (x *fastReflection_MsgClawbackRequest) IsValid() bool { - return x != nil -} - -// ProtoMethods returns optional fastReflectionFeature-path implementations of various operations. -// This method may return nil. -// -// The returned methods type is identical to -// "google.golang.org/protobuf/runtime/protoiface".Methods. -// Consult the protoiface package documentation for details. -func (x *fastReflection_MsgClawbackRequest) ProtoMethods() *protoiface.Methods { - size := func(input protoiface.SizeInput) protoiface.SizeOutput { - x := input.Message.Interface().(*MsgClawbackRequest) - if x == nil { - return protoiface.SizeOutput{ - NoUnkeyedLiterals: input.NoUnkeyedLiterals, - Size: 0, - } - } - options := runtime.SizeInputToOptions(input) - _ = options - var n int - var l int - _ = l - if x.unknownFields != nil { - n += len(x.unknownFields) - } - return protoiface.SizeOutput{ - NoUnkeyedLiterals: input.NoUnkeyedLiterals, - Size: n, - } - } - - marshal := func(input protoiface.MarshalInput) (protoiface.MarshalOutput, error) { - x := input.Message.Interface().(*MsgClawbackRequest) - if x == nil { - return protoiface.MarshalOutput{ - NoUnkeyedLiterals: input.NoUnkeyedLiterals, - Buf: input.Buf, - }, nil - } - options := runtime.MarshalInputToOptions(input) - _ = options - size := options.Size(x) - dAtA := make([]byte, size) - i := len(dAtA) - _ = i - var l int - _ = l - if x.unknownFields != nil { - i -= len(x.unknownFields) - copy(dAtA[i:], x.unknownFields) - } - if input.Buf != nil { - input.Buf = append(input.Buf, dAtA...) - } else { - input.Buf = dAtA - } - return protoiface.MarshalOutput{ - NoUnkeyedLiterals: input.NoUnkeyedLiterals, - Buf: input.Buf, - }, nil - } - unmarshal := func(input protoiface.UnmarshalInput) (protoiface.UnmarshalOutput, error) { - x := input.Message.Interface().(*MsgClawbackRequest) - if x == nil { - return protoiface.UnmarshalOutput{ - NoUnkeyedLiterals: input.NoUnkeyedLiterals, - Flags: input.Flags, - }, nil - } - options := runtime.UnmarshalInputToOptions(input) - _ = options - dAtA := input.Buf - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: MsgClawbackRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: MsgClawbackRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - default: - iNdEx = preIndex - skippy, err := runtime.Skip(dAtA[iNdEx:]) - if err != nil { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - if (iNdEx + skippy) > l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - if !options.DiscardUnknown { - x.unknownFields = append(x.unknownFields, dAtA[iNdEx:iNdEx+skippy]...) - } - iNdEx += skippy - } - } - - if iNdEx > l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, nil - } - return &protoiface.Methods{ - NoUnkeyedLiterals: struct{}{}, - Flags: protoiface.SupportMarshalDeterministic | protoiface.SupportUnmarshalDiscardUnknown, - Size: size, - Marshal: marshal, - Unmarshal: unmarshal, - Merge: nil, - CheckInitialized: nil, - } -} - -var ( - md_MsgClawbackResponse protoreflect.MessageDescriptor -) - -func init() { - file_testpb_msg_proto_init() - md_MsgClawbackResponse = File_testpb_msg_proto.Messages().ByName("MsgClawbackResponse") -} - -var _ protoreflect.Message = (*fastReflection_MsgClawbackResponse)(nil) - -type fastReflection_MsgClawbackResponse MsgClawbackResponse - -func (x *MsgClawbackResponse) ProtoReflect() protoreflect.Message { - return (*fastReflection_MsgClawbackResponse)(x) -} - -func (x *MsgClawbackResponse) slowProtoReflect() protoreflect.Message { - mi := &file_testpb_msg_proto_msgTypes[3] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -var _fastReflection_MsgClawbackResponse_messageType fastReflection_MsgClawbackResponse_messageType -var _ protoreflect.MessageType = fastReflection_MsgClawbackResponse_messageType{} - -type fastReflection_MsgClawbackResponse_messageType struct{} - -func (x fastReflection_MsgClawbackResponse_messageType) Zero() protoreflect.Message { - return (*fastReflection_MsgClawbackResponse)(nil) -} -func (x fastReflection_MsgClawbackResponse_messageType) New() protoreflect.Message { - return new(fastReflection_MsgClawbackResponse) -} -func (x fastReflection_MsgClawbackResponse_messageType) Descriptor() protoreflect.MessageDescriptor { - return md_MsgClawbackResponse -} - -// Descriptor returns message descriptor, which contains only the protobuf -// type information for the message. -func (x *fastReflection_MsgClawbackResponse) Descriptor() protoreflect.MessageDescriptor { - return md_MsgClawbackResponse -} - -// Type returns the message type, which encapsulates both Go and protobuf -// type information. If the Go type information is not needed, -// it is recommended that the message descriptor be used instead. -func (x *fastReflection_MsgClawbackResponse) Type() protoreflect.MessageType { - return _fastReflection_MsgClawbackResponse_messageType -} - -// New returns a newly allocated and mutable empty message. -func (x *fastReflection_MsgClawbackResponse) New() protoreflect.Message { - return new(fastReflection_MsgClawbackResponse) -} - -// Interface unwraps the message reflection interface and -// returns the underlying ProtoMessage interface. -func (x *fastReflection_MsgClawbackResponse) Interface() protoreflect.ProtoMessage { - return (*MsgClawbackResponse)(x) -} - -// Range iterates over every populated field in an undefined order, -// calling f for each field descriptor and value encountered. -// Range returns immediately if f returns false. -// While iterating, mutating operations may only be performed -// on the current field descriptor. -func (x *fastReflection_MsgClawbackResponse) Range(f func(protoreflect.FieldDescriptor, protoreflect.Value) bool) { -} - -// Has reports whether a field is populated. -// -// Some fields have the property of nullability where it is possible to -// distinguish between the default value of a field and whether the field -// was explicitly populated with the default value. Singular message fields, -// member fields of a oneof, and proto2 scalar fields are nullable. Such -// fields are populated only if explicitly set. -// -// In other cases (aside from the nullable cases above), -// a proto3 scalar field is populated if it contains a non-zero value, and -// a repeated field is populated if it is non-empty. -func (x *fastReflection_MsgClawbackResponse) Has(fd protoreflect.FieldDescriptor) bool { - switch fd.FullName() { - default: - if fd.IsExtension() { - panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.MsgClawbackResponse")) - } - panic(fmt.Errorf("message testpb.MsgClawbackResponse does not contain field %s", fd.FullName())) - } -} - -// Clear clears the field such that a subsequent Has call reports false. -// -// Clearing an extension field clears both the extension type and value -// associated with the given field number. -// -// Clear is a mutating operation and unsafe for concurrent use. -func (x *fastReflection_MsgClawbackResponse) Clear(fd protoreflect.FieldDescriptor) { - switch fd.FullName() { - default: - if fd.IsExtension() { - panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.MsgClawbackResponse")) - } - panic(fmt.Errorf("message testpb.MsgClawbackResponse does not contain field %s", fd.FullName())) - } -} - -// Get retrieves the value for a field. -// -// For unpopulated scalars, it returns the default value, where -// the default value of a bytes scalar is guaranteed to be a copy. -// For unpopulated composite types, it returns an empty, read-only view -// of the value; to obtain a mutable reference, use Mutable. -func (x *fastReflection_MsgClawbackResponse) Get(descriptor protoreflect.FieldDescriptor) protoreflect.Value { - switch descriptor.FullName() { - default: - if descriptor.IsExtension() { - panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.MsgClawbackResponse")) - } - panic(fmt.Errorf("message testpb.MsgClawbackResponse does not contain field %s", descriptor.FullName())) - } -} - -// Set stores the value for a field. -// -// For a field belonging to a oneof, it implicitly clears any other field -// that may be currently set within the same oneof. -// For extension fields, it implicitly stores the provided ExtensionType. -// When setting a composite type, it is unspecified whether the stored value -// aliases the source's memory in any way. If the composite value is an -// empty, read-only value, then it panics. -// -// Set is a mutating operation and unsafe for concurrent use. -func (x *fastReflection_MsgClawbackResponse) Set(fd protoreflect.FieldDescriptor, value protoreflect.Value) { - switch fd.FullName() { - default: - if fd.IsExtension() { - panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.MsgClawbackResponse")) - } - panic(fmt.Errorf("message testpb.MsgClawbackResponse does not contain field %s", fd.FullName())) - } -} - -// Mutable returns a mutable reference to a composite type. -// -// If the field is unpopulated, it may allocate a composite value. -// For a field belonging to a oneof, it implicitly clears any other field -// that may be currently set within the same oneof. -// For extension fields, it implicitly stores the provided ExtensionType -// if not already stored. -// It panics if the field does not contain a composite type. -// -// Mutable is a mutating operation and unsafe for concurrent use. -func (x *fastReflection_MsgClawbackResponse) Mutable(fd protoreflect.FieldDescriptor) protoreflect.Value { - switch fd.FullName() { - default: - if fd.IsExtension() { - panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.MsgClawbackResponse")) - } - panic(fmt.Errorf("message testpb.MsgClawbackResponse does not contain field %s", fd.FullName())) - } -} - -// NewField returns a new value that is assignable to the field -// for the given descriptor. For scalars, this returns the default value. -// For lists, maps, and messages, this returns a new, empty, mutable value. -func (x *fastReflection_MsgClawbackResponse) NewField(fd protoreflect.FieldDescriptor) protoreflect.Value { - switch fd.FullName() { - default: - if fd.IsExtension() { - panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.MsgClawbackResponse")) - } - panic(fmt.Errorf("message testpb.MsgClawbackResponse does not contain field %s", fd.FullName())) - } -} - -// WhichOneof reports which field within the oneof is populated, -// returning nil if none are populated. -// It panics if the oneof descriptor does not belong to this message. -func (x *fastReflection_MsgClawbackResponse) WhichOneof(d protoreflect.OneofDescriptor) protoreflect.FieldDescriptor { - switch d.FullName() { - default: - panic(fmt.Errorf("%s is not a oneof field in testpb.MsgClawbackResponse", d.FullName())) - } - panic("unreachable") -} - -// GetUnknown retrieves the entire list of unknown fields. -// The caller may only mutate the contents of the RawFields -// if the mutated bytes are stored back into the message with SetUnknown. -func (x *fastReflection_MsgClawbackResponse) GetUnknown() protoreflect.RawFields { - return x.unknownFields -} - -// SetUnknown stores an entire list of unknown fields. -// The raw fields must be syntactically valid according to the wire format. -// An implementation may panic if this is not the case. -// Once stored, the caller must not mutate the content of the RawFields. -// An empty RawFields may be passed to clear the fields. -// -// SetUnknown is a mutating operation and unsafe for concurrent use. -func (x *fastReflection_MsgClawbackResponse) SetUnknown(fields protoreflect.RawFields) { - x.unknownFields = fields -} - -// IsValid reports whether the message is valid. -// -// An invalid message is an empty, read-only value. -// -// An invalid message often corresponds to a nil pointer of the concrete -// message type, but the details are implementation dependent. -// Validity is not part of the protobuf data model, and may not -// be preserved in marshaling or other operations. -func (x *fastReflection_MsgClawbackResponse) IsValid() bool { - return x != nil -} - -// ProtoMethods returns optional fastReflectionFeature-path implementations of various operations. -// This method may return nil. -// -// The returned methods type is identical to -// "google.golang.org/protobuf/runtime/protoiface".Methods. -// Consult the protoiface package documentation for details. -func (x *fastReflection_MsgClawbackResponse) ProtoMethods() *protoiface.Methods { - size := func(input protoiface.SizeInput) protoiface.SizeOutput { - x := input.Message.Interface().(*MsgClawbackResponse) - if x == nil { - return protoiface.SizeOutput{ - NoUnkeyedLiterals: input.NoUnkeyedLiterals, - Size: 0, - } - } - options := runtime.SizeInputToOptions(input) - _ = options - var n int - var l int - _ = l - if x.unknownFields != nil { - n += len(x.unknownFields) - } - return protoiface.SizeOutput{ - NoUnkeyedLiterals: input.NoUnkeyedLiterals, - Size: n, - } - } - - marshal := func(input protoiface.MarshalInput) (protoiface.MarshalOutput, error) { - x := input.Message.Interface().(*MsgClawbackResponse) - if x == nil { - return protoiface.MarshalOutput{ - NoUnkeyedLiterals: input.NoUnkeyedLiterals, - Buf: input.Buf, - }, nil - } - options := runtime.MarshalInputToOptions(input) - _ = options - size := options.Size(x) - dAtA := make([]byte, size) - i := len(dAtA) - _ = i - var l int - _ = l - if x.unknownFields != nil { - i -= len(x.unknownFields) - copy(dAtA[i:], x.unknownFields) - } - if input.Buf != nil { - input.Buf = append(input.Buf, dAtA...) - } else { - input.Buf = dAtA - } - return protoiface.MarshalOutput{ - NoUnkeyedLiterals: input.NoUnkeyedLiterals, - Buf: input.Buf, - }, nil - } - unmarshal := func(input protoiface.UnmarshalInput) (protoiface.UnmarshalOutput, error) { - x := input.Message.Interface().(*MsgClawbackResponse) - if x == nil { - return protoiface.UnmarshalOutput{ - NoUnkeyedLiterals: input.NoUnkeyedLiterals, - Flags: input.Flags, - }, nil - } - options := runtime.UnmarshalInputToOptions(input) - _ = options - dAtA := input.Buf - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: MsgClawbackResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: MsgClawbackResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - default: - iNdEx = preIndex - skippy, err := runtime.Skip(dAtA[iNdEx:]) - if err != nil { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - if (iNdEx + skippy) > l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - if !options.DiscardUnknown { - x.unknownFields = append(x.unknownFields, dAtA[iNdEx:iNdEx+skippy]...) - } - iNdEx += skippy - } - } - - if iNdEx > l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, nil - } - return &protoiface.Methods{ - NoUnkeyedLiterals: struct{}{}, - Flags: protoiface.SupportMarshalDeterministic | protoiface.SupportUnmarshalDiscardUnknown, - Size: size, - Marshal: marshal, - Unmarshal: unmarshal, - Merge: nil, - CheckInitialized: nil, - } -} - -// Code generated by protoc-gen-go. DO NOT EDIT. -// versions: -// protoc-gen-go v1.27.0 -// protoc (unknown) -// source: testpb/msg.proto - -const ( - // Verify that this generated code is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) - // Verify that runtime/protoimpl is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) -) - -type MsgRequest struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - // u32 is a uint32 - U32 uint32 `protobuf:"varint,1,opt,name=u32,proto3" json:"u32,omitempty"` - U64 uint64 `protobuf:"varint,2,opt,name=u64,proto3" json:"u64,omitempty"` - Str string `protobuf:"bytes,3,opt,name=str,proto3" json:"str,omitempty"` - Bz []byte `protobuf:"bytes,4,opt,name=bz,proto3" json:"bz,omitempty"` - Timestamp *timestamppb.Timestamp `protobuf:"bytes,5,opt,name=timestamp,proto3" json:"timestamp,omitempty"` - Duration *durationpb.Duration `protobuf:"bytes,6,opt,name=duration,proto3" json:"duration,omitempty"` - I32 int32 `protobuf:"varint,7,opt,name=i32,proto3" json:"i32,omitempty"` - I64 int64 `protobuf:"varint,10,opt,name=i64,proto3" json:"i64,omitempty"` - ABool bool `protobuf:"varint,15,opt,name=a_bool,json=aBool,proto3" json:"a_bool,omitempty"` - AnEnum Enum `protobuf:"varint,16,opt,name=an_enum,json=anEnum,proto3,enum=testpb.Enum" json:"an_enum,omitempty"` - AMessage *AMessage `protobuf:"bytes,17,opt,name=a_message,json=aMessage,proto3" json:"a_message,omitempty"` - ACoin *v1beta1.Coin `protobuf:"bytes,18,opt,name=a_coin,json=aCoin,proto3" json:"a_coin,omitempty"` - AnAddress string `protobuf:"bytes,19,opt,name=an_address,json=anAddress,proto3" json:"an_address,omitempty"` - Page *v1beta11.PageRequest `protobuf:"bytes,20,opt,name=page,proto3" json:"page,omitempty"` - Bools []bool `protobuf:"varint,21,rep,packed,name=bools,proto3" json:"bools,omitempty"` - Uints []uint32 `protobuf:"varint,22,rep,packed,name=uints,proto3" json:"uints,omitempty"` - Strings []string `protobuf:"bytes,23,rep,name=strings,proto3" json:"strings,omitempty"` - Enums []Enum `protobuf:"varint,24,rep,packed,name=enums,proto3,enum=testpb.Enum" json:"enums,omitempty"` - Durations []*durationpb.Duration `protobuf:"bytes,25,rep,name=durations,proto3" json:"durations,omitempty"` - SomeMessages []*AMessage `protobuf:"bytes,26,rep,name=some_messages,json=someMessages,proto3" json:"some_messages,omitempty"` - Positional1 int32 `protobuf:"varint,27,opt,name=positional1,proto3" json:"positional1,omitempty"` - Positional2 string `protobuf:"bytes,28,opt,name=positional2,proto3" json:"positional2,omitempty"` - Positional3Varargs []*v1beta1.Coin `protobuf:"bytes,29,rep,name=positional3_varargs,json=positional3Varargs,proto3" json:"positional3_varargs,omitempty"` - DeprecatedField string `protobuf:"bytes,30,opt,name=deprecated_field,json=deprecatedField,proto3" json:"deprecated_field,omitempty"` - ShorthandDeprecatedField string `protobuf:"bytes,31,opt,name=shorthand_deprecated_field,json=shorthandDeprecatedField,proto3" json:"shorthand_deprecated_field,omitempty"` - HiddenBool bool `protobuf:"varint,32,opt,name=hidden_bool,json=hiddenBool,proto3" json:"hidden_bool,omitempty"` - AValidatorAddress string `protobuf:"bytes,33,opt,name=a_validator_address,json=aValidatorAddress,proto3" json:"a_validator_address,omitempty"` -} - -func (x *MsgRequest) Reset() { - *x = MsgRequest{} - if protoimpl.UnsafeEnabled { - mi := &file_testpb_msg_proto_msgTypes[0] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *MsgRequest) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*MsgRequest) ProtoMessage() {} - -// Deprecated: Use MsgRequest.ProtoReflect.Descriptor instead. -func (*MsgRequest) Descriptor() ([]byte, []int) { - return file_testpb_msg_proto_rawDescGZIP(), []int{0} -} - -func (x *MsgRequest) GetU32() uint32 { - if x != nil { - return x.U32 - } - return 0 -} - -func (x *MsgRequest) GetU64() uint64 { - if x != nil { - return x.U64 - } - return 0 -} - -func (x *MsgRequest) GetStr() string { - if x != nil { - return x.Str - } - return "" -} - -func (x *MsgRequest) GetBz() []byte { - if x != nil { - return x.Bz - } - return nil -} - -func (x *MsgRequest) GetTimestamp() *timestamppb.Timestamp { - if x != nil { - return x.Timestamp - } - return nil -} - -func (x *MsgRequest) GetDuration() *durationpb.Duration { - if x != nil { - return x.Duration - } - return nil -} - -func (x *MsgRequest) GetI32() int32 { - if x != nil { - return x.I32 - } - return 0 -} - -func (x *MsgRequest) GetI64() int64 { - if x != nil { - return x.I64 - } - return 0 -} - -func (x *MsgRequest) GetABool() bool { - if x != nil { - return x.ABool - } - return false -} - -func (x *MsgRequest) GetAnEnum() Enum { - if x != nil { - return x.AnEnum - } - return Enum_ENUM_UNSPECIFIED -} - -func (x *MsgRequest) GetAMessage() *AMessage { - if x != nil { - return x.AMessage - } - return nil -} - -func (x *MsgRequest) GetACoin() *v1beta1.Coin { - if x != nil { - return x.ACoin - } - return nil -} - -func (x *MsgRequest) GetAnAddress() string { - if x != nil { - return x.AnAddress - } - return "" -} - -func (x *MsgRequest) GetPage() *v1beta11.PageRequest { - if x != nil { - return x.Page - } - return nil -} - -func (x *MsgRequest) GetBools() []bool { - if x != nil { - return x.Bools - } - return nil -} - -func (x *MsgRequest) GetUints() []uint32 { - if x != nil { - return x.Uints - } - return nil -} - -func (x *MsgRequest) GetStrings() []string { - if x != nil { - return x.Strings - } - return nil -} - -func (x *MsgRequest) GetEnums() []Enum { - if x != nil { - return x.Enums - } - return nil -} - -func (x *MsgRequest) GetDurations() []*durationpb.Duration { - if x != nil { - return x.Durations - } - return nil -} - -func (x *MsgRequest) GetSomeMessages() []*AMessage { - if x != nil { - return x.SomeMessages - } - return nil -} - -func (x *MsgRequest) GetPositional1() int32 { - if x != nil { - return x.Positional1 - } - return 0 -} - -func (x *MsgRequest) GetPositional2() string { - if x != nil { - return x.Positional2 - } - return "" -} - -func (x *MsgRequest) GetPositional3Varargs() []*v1beta1.Coin { - if x != nil { - return x.Positional3Varargs - } - return nil -} - -func (x *MsgRequest) GetDeprecatedField() string { - if x != nil { - return x.DeprecatedField - } - return "" -} - -func (x *MsgRequest) GetShorthandDeprecatedField() string { - if x != nil { - return x.ShorthandDeprecatedField - } - return "" -} - -func (x *MsgRequest) GetHiddenBool() bool { - if x != nil { - return x.HiddenBool - } - return false -} - -func (x *MsgRequest) GetAValidatorAddress() string { - if x != nil { - return x.AValidatorAddress - } - return "" -} - -type MsgResponse struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Request *MsgRequest `protobuf:"bytes,1,opt,name=request,proto3" json:"request,omitempty"` -} - -func (x *MsgResponse) Reset() { - *x = MsgResponse{} - if protoimpl.UnsafeEnabled { - mi := &file_testpb_msg_proto_msgTypes[1] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *MsgResponse) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*MsgResponse) ProtoMessage() {} - -// Deprecated: Use MsgResponse.ProtoReflect.Descriptor instead. -func (*MsgResponse) Descriptor() ([]byte, []int) { - return file_testpb_msg_proto_rawDescGZIP(), []int{1} -} - -func (x *MsgResponse) GetRequest() *MsgRequest { - if x != nil { - return x.Request - } - return nil -} - -type MsgClawbackRequest struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields -} - -func (x *MsgClawbackRequest) Reset() { - *x = MsgClawbackRequest{} - if protoimpl.UnsafeEnabled { - mi := &file_testpb_msg_proto_msgTypes[2] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *MsgClawbackRequest) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*MsgClawbackRequest) ProtoMessage() {} - -// Deprecated: Use MsgClawbackRequest.ProtoReflect.Descriptor instead. -func (*MsgClawbackRequest) Descriptor() ([]byte, []int) { - return file_testpb_msg_proto_rawDescGZIP(), []int{2} -} - -type MsgClawbackResponse struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields -} - -func (x *MsgClawbackResponse) Reset() { - *x = MsgClawbackResponse{} - if protoimpl.UnsafeEnabled { - mi := &file_testpb_msg_proto_msgTypes[3] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *MsgClawbackResponse) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*MsgClawbackResponse) ProtoMessage() {} - -// Deprecated: Use MsgClawbackResponse.ProtoReflect.Descriptor instead. -func (*MsgClawbackResponse) Descriptor() ([]byte, []int) { - return file_testpb_msg_proto_rawDescGZIP(), []int{3} -} - -var File_testpb_msg_proto protoreflect.FileDescriptor - -var file_testpb_msg_proto_rawDesc = []byte{ - 0x0a, 0x10, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x2f, 0x6d, 0x73, 0x67, 0x2e, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x12, 0x06, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x1a, 0x1f, 0x67, 0x6f, 0x6f, 0x67, - 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x74, 0x69, 0x6d, 0x65, - 0x73, 0x74, 0x61, 0x6d, 0x70, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1e, 0x67, 0x6f, 0x6f, - 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x64, 0x75, 0x72, - 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x19, 0x63, 0x6f, 0x73, - 0x6d, 0x6f, 0x73, 0x5f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, - 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x2a, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x62, - 0x61, 0x73, 0x65, 0x2f, 0x71, 0x75, 0x65, 0x72, 0x79, 0x2f, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, - 0x31, 0x2f, 0x70, 0x61, 0x67, 0x69, 0x6e, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x1a, 0x1e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x62, 0x61, 0x73, 0x65, 0x2f, - 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x2f, 0x63, 0x6f, 0x69, 0x6e, 0x2e, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x1a, 0x12, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x2f, 0x71, 0x75, 0x65, 0x72, 0x79, - 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xc2, 0x08, 0x0a, 0x0a, 0x4d, 0x73, 0x67, 0x52, 0x65, - 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x33, 0x32, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x0d, 0x52, 0x03, 0x75, 0x33, 0x32, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x36, 0x34, 0x18, 0x02, - 0x20, 0x01, 0x28, 0x04, 0x52, 0x03, 0x75, 0x36, 0x34, 0x12, 0x10, 0x0a, 0x03, 0x73, 0x74, 0x72, - 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x73, 0x74, 0x72, 0x12, 0x0e, 0x0a, 0x02, 0x62, - 0x7a, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x02, 0x62, 0x7a, 0x12, 0x38, 0x0a, 0x09, 0x74, - 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, - 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, - 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x09, 0x74, 0x69, 0x6d, 0x65, - 0x73, 0x74, 0x61, 0x6d, 0x70, 0x12, 0x35, 0x0a, 0x08, 0x64, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, - 0x6e, 0x18, 0x06, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, - 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x44, 0x75, 0x72, 0x61, 0x74, 0x69, - 0x6f, 0x6e, 0x52, 0x08, 0x64, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x10, 0x0a, 0x03, - 0x69, 0x33, 0x32, 0x18, 0x07, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x69, 0x33, 0x32, 0x12, 0x10, - 0x0a, 0x03, 0x69, 0x36, 0x34, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x03, 0x52, 0x03, 0x69, 0x36, 0x34, - 0x12, 0x15, 0x0a, 0x06, 0x61, 0x5f, 0x62, 0x6f, 0x6f, 0x6c, 0x18, 0x0f, 0x20, 0x01, 0x28, 0x08, - 0x52, 0x05, 0x61, 0x42, 0x6f, 0x6f, 0x6c, 0x12, 0x25, 0x0a, 0x07, 0x61, 0x6e, 0x5f, 0x65, 0x6e, - 0x75, 0x6d, 0x18, 0x10, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x0c, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x70, - 0x62, 0x2e, 0x45, 0x6e, 0x75, 0x6d, 0x52, 0x06, 0x61, 0x6e, 0x45, 0x6e, 0x75, 0x6d, 0x12, 0x2d, - 0x0a, 0x09, 0x61, 0x5f, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x11, 0x20, 0x01, 0x28, - 0x0b, 0x32, 0x10, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x2e, 0x41, 0x4d, 0x65, 0x73, 0x73, - 0x61, 0x67, 0x65, 0x52, 0x08, 0x61, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x30, 0x0a, - 0x06, 0x61, 0x5f, 0x63, 0x6f, 0x69, 0x6e, 0x18, 0x12, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x19, 0x2e, - 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x76, 0x31, 0x62, 0x65, - 0x74, 0x61, 0x31, 0x2e, 0x43, 0x6f, 0x69, 0x6e, 0x52, 0x05, 0x61, 0x43, 0x6f, 0x69, 0x6e, 0x12, - 0x37, 0x0a, 0x0a, 0x61, 0x6e, 0x5f, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, 0x13, 0x20, - 0x01, 0x28, 0x09, 0x42, 0x18, 0xd2, 0xb4, 0x2d, 0x14, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, - 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x52, 0x09, 0x61, - 0x6e, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x12, 0x3a, 0x0a, 0x04, 0x70, 0x61, 0x67, 0x65, - 0x18, 0x14, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x26, 0x2e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, - 0x62, 0x61, 0x73, 0x65, 0x2e, 0x71, 0x75, 0x65, 0x72, 0x79, 0x2e, 0x76, 0x31, 0x62, 0x65, 0x74, - 0x61, 0x31, 0x2e, 0x50, 0x61, 0x67, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x52, 0x04, - 0x70, 0x61, 0x67, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x62, 0x6f, 0x6f, 0x6c, 0x73, 0x18, 0x15, 0x20, - 0x03, 0x28, 0x08, 0x52, 0x05, 0x62, 0x6f, 0x6f, 0x6c, 0x73, 0x12, 0x14, 0x0a, 0x05, 0x75, 0x69, - 0x6e, 0x74, 0x73, 0x18, 0x16, 0x20, 0x03, 0x28, 0x0d, 0x52, 0x05, 0x75, 0x69, 0x6e, 0x74, 0x73, - 0x12, 0x18, 0x0a, 0x07, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x73, 0x18, 0x17, 0x20, 0x03, 0x28, - 0x09, 0x52, 0x07, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x73, 0x12, 0x22, 0x0a, 0x05, 0x65, 0x6e, - 0x75, 0x6d, 0x73, 0x18, 0x18, 0x20, 0x03, 0x28, 0x0e, 0x32, 0x0c, 0x2e, 0x74, 0x65, 0x73, 0x74, - 0x70, 0x62, 0x2e, 0x45, 0x6e, 0x75, 0x6d, 0x52, 0x05, 0x65, 0x6e, 0x75, 0x6d, 0x73, 0x12, 0x37, - 0x0a, 0x09, 0x64, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0x19, 0x20, 0x03, 0x28, - 0x0b, 0x32, 0x19, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x62, 0x75, 0x66, 0x2e, 0x44, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x09, 0x64, 0x75, - 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x35, 0x0a, 0x0d, 0x73, 0x6f, 0x6d, 0x65, 0x5f, - 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x73, 0x18, 0x1a, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x10, - 0x2e, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x2e, 0x41, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, - 0x52, 0x0c, 0x73, 0x6f, 0x6d, 0x65, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x73, 0x12, 0x20, - 0x0a, 0x0b, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x61, 0x6c, 0x31, 0x18, 0x1b, 0x20, - 0x01, 0x28, 0x05, 0x52, 0x0b, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x61, 0x6c, 0x31, - 0x12, 0x20, 0x0a, 0x0b, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x61, 0x6c, 0x32, 0x18, - 0x1c, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x61, - 0x6c, 0x32, 0x12, 0x4a, 0x0a, 0x13, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x61, 0x6c, - 0x33, 0x5f, 0x76, 0x61, 0x72, 0x61, 0x72, 0x67, 0x73, 0x18, 0x1d, 0x20, 0x03, 0x28, 0x0b, 0x32, - 0x19, 0x2e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x76, 0x31, - 0x62, 0x65, 0x74, 0x61, 0x31, 0x2e, 0x43, 0x6f, 0x69, 0x6e, 0x52, 0x12, 0x70, 0x6f, 0x73, 0x69, - 0x74, 0x69, 0x6f, 0x6e, 0x61, 0x6c, 0x33, 0x56, 0x61, 0x72, 0x61, 0x72, 0x67, 0x73, 0x12, 0x29, - 0x0a, 0x10, 0x64, 0x65, 0x70, 0x72, 0x65, 0x63, 0x61, 0x74, 0x65, 0x64, 0x5f, 0x66, 0x69, 0x65, - 0x6c, 0x64, 0x18, 0x1e, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0f, 0x64, 0x65, 0x70, 0x72, 0x65, 0x63, - 0x61, 0x74, 0x65, 0x64, 0x46, 0x69, 0x65, 0x6c, 0x64, 0x12, 0x3c, 0x0a, 0x1a, 0x73, 0x68, 0x6f, - 0x72, 0x74, 0x68, 0x61, 0x6e, 0x64, 0x5f, 0x64, 0x65, 0x70, 0x72, 0x65, 0x63, 0x61, 0x74, 0x65, - 0x64, 0x5f, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x18, 0x1f, 0x20, 0x01, 0x28, 0x09, 0x52, 0x18, 0x73, - 0x68, 0x6f, 0x72, 0x74, 0x68, 0x61, 0x6e, 0x64, 0x44, 0x65, 0x70, 0x72, 0x65, 0x63, 0x61, 0x74, - 0x65, 0x64, 0x46, 0x69, 0x65, 0x6c, 0x64, 0x12, 0x1f, 0x0a, 0x0b, 0x68, 0x69, 0x64, 0x64, 0x65, - 0x6e, 0x5f, 0x62, 0x6f, 0x6f, 0x6c, 0x18, 0x20, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0a, 0x68, 0x69, - 0x64, 0x64, 0x65, 0x6e, 0x42, 0x6f, 0x6f, 0x6c, 0x12, 0x51, 0x0a, 0x13, 0x61, 0x5f, 0x76, 0x61, - 0x6c, 0x69, 0x64, 0x61, 0x74, 0x6f, 0x72, 0x5f, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, - 0x21, 0x20, 0x01, 0x28, 0x09, 0x42, 0x21, 0xd2, 0xb4, 0x2d, 0x1d, 0x63, 0x6f, 0x73, 0x6d, 0x6f, - 0x73, 0x2e, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x6f, 0x72, 0x41, 0x64, 0x64, 0x72, 0x65, - 0x73, 0x73, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x52, 0x11, 0x61, 0x56, 0x61, 0x6c, 0x69, 0x64, - 0x61, 0x74, 0x6f, 0x72, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x22, 0x3b, 0x0a, 0x0b, 0x4d, - 0x73, 0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x2c, 0x0a, 0x07, 0x72, 0x65, - 0x71, 0x75, 0x65, 0x73, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x12, 0x2e, 0x74, 0x65, - 0x73, 0x74, 0x70, 0x62, 0x2e, 0x4d, 0x73, 0x67, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x52, - 0x07, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0x14, 0x0a, 0x12, 0x4d, 0x73, 0x67, 0x43, - 0x6c, 0x61, 0x77, 0x62, 0x61, 0x63, 0x6b, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0x15, - 0x0a, 0x13, 0x4d, 0x73, 0x67, 0x43, 0x6c, 0x61, 0x77, 0x62, 0x61, 0x63, 0x6b, 0x52, 0x65, 0x73, - 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x32, 0xac, 0x01, 0x0a, 0x03, 0x4d, 0x73, 0x67, 0x12, 0x47, 0x0a, - 0x04, 0x53, 0x65, 0x6e, 0x64, 0x12, 0x12, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x2e, 0x4d, - 0x73, 0x67, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x13, 0x2e, 0x74, 0x65, 0x73, 0x74, - 0x70, 0x62, 0x2e, 0x4d, 0x73, 0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x16, - 0xca, 0xb4, 0x2d, 0x12, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2d, 0x73, 0x64, 0x6b, 0x20, 0x76, - 0x30, 0x2e, 0x35, 0x30, 0x2e, 0x30, 0x12, 0x5c, 0x0a, 0x08, 0x43, 0x6c, 0x61, 0x77, 0x62, 0x61, - 0x63, 0x6b, 0x12, 0x1a, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x2e, 0x4d, 0x73, 0x67, 0x43, - 0x6c, 0x61, 0x77, 0x62, 0x61, 0x63, 0x6b, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1b, - 0x2e, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x2e, 0x4d, 0x73, 0x67, 0x43, 0x6c, 0x61, 0x77, 0x62, - 0x61, 0x63, 0x6b, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x17, 0xca, 0xb4, 0x2d, - 0x13, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2d, 0x73, 0x64, 0x6b, 0x20, 0x76, 0x30, 0x2e, 0x35, - 0x33, 0x2e, 0x30, 0x20, 0x42, 0x86, 0x01, 0x0a, 0x0a, 0x63, 0x6f, 0x6d, 0x2e, 0x74, 0x65, 0x73, - 0x74, 0x70, 0x62, 0x42, 0x08, 0x4d, 0x73, 0x67, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, - 0x36, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, 0x6f, 0x73, 0x6d, - 0x6f, 0x73, 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2d, 0x73, 0x64, 0x6b, 0x2f, 0x63, 0x6c, - 0x69, 0x65, 0x6e, 0x74, 0x2f, 0x76, 0x32, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, - 0x2f, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0xa2, 0x02, 0x03, 0x54, 0x58, 0x58, 0xaa, 0x02, 0x06, - 0x54, 0x65, 0x73, 0x74, 0x70, 0x62, 0xca, 0x02, 0x06, 0x54, 0x65, 0x73, 0x74, 0x70, 0x62, 0xe2, - 0x02, 0x12, 0x54, 0x65, 0x73, 0x74, 0x70, 0x62, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, - 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x06, 0x54, 0x65, 0x73, 0x74, 0x70, 0x62, 0x62, 0x06, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x33, -} - -var ( - file_testpb_msg_proto_rawDescOnce sync.Once - file_testpb_msg_proto_rawDescData = file_testpb_msg_proto_rawDesc -) - -func file_testpb_msg_proto_rawDescGZIP() []byte { - file_testpb_msg_proto_rawDescOnce.Do(func() { - file_testpb_msg_proto_rawDescData = protoimpl.X.CompressGZIP(file_testpb_msg_proto_rawDescData) - }) - return file_testpb_msg_proto_rawDescData -} - -var file_testpb_msg_proto_msgTypes = make([]protoimpl.MessageInfo, 4) -var file_testpb_msg_proto_goTypes = []interface{}{ - (*MsgRequest)(nil), // 0: testpb.MsgRequest - (*MsgResponse)(nil), // 1: testpb.MsgResponse - (*MsgClawbackRequest)(nil), // 2: testpb.MsgClawbackRequest - (*MsgClawbackResponse)(nil), // 3: testpb.MsgClawbackResponse - (*timestamppb.Timestamp)(nil), // 4: google.protobuf.Timestamp - (*durationpb.Duration)(nil), // 5: google.protobuf.Duration - (Enum)(0), // 6: testpb.Enum - (*AMessage)(nil), // 7: testpb.AMessage - (*v1beta1.Coin)(nil), // 8: cosmos.base.v1beta1.Coin - (*v1beta11.PageRequest)(nil), // 9: cosmos.base.query.v1beta1.PageRequest -} -var file_testpb_msg_proto_depIdxs = []int32{ - 4, // 0: testpb.MsgRequest.timestamp:type_name -> google.protobuf.Timestamp - 5, // 1: testpb.MsgRequest.duration:type_name -> google.protobuf.Duration - 6, // 2: testpb.MsgRequest.an_enum:type_name -> testpb.Enum - 7, // 3: testpb.MsgRequest.a_message:type_name -> testpb.AMessage - 8, // 4: testpb.MsgRequest.a_coin:type_name -> cosmos.base.v1beta1.Coin - 9, // 5: testpb.MsgRequest.page:type_name -> cosmos.base.query.v1beta1.PageRequest - 6, // 6: testpb.MsgRequest.enums:type_name -> testpb.Enum - 5, // 7: testpb.MsgRequest.durations:type_name -> google.protobuf.Duration - 7, // 8: testpb.MsgRequest.some_messages:type_name -> testpb.AMessage - 8, // 9: testpb.MsgRequest.positional3_varargs:type_name -> cosmos.base.v1beta1.Coin - 0, // 10: testpb.MsgResponse.request:type_name -> testpb.MsgRequest - 0, // 11: testpb.Msg.Send:input_type -> testpb.MsgRequest - 2, // 12: testpb.Msg.Clawback:input_type -> testpb.MsgClawbackRequest - 1, // 13: testpb.Msg.Send:output_type -> testpb.MsgResponse - 3, // 14: testpb.Msg.Clawback:output_type -> testpb.MsgClawbackResponse - 13, // [13:15] is the sub-list for method output_type - 11, // [11:13] is the sub-list for method input_type - 11, // [11:11] is the sub-list for extension type_name - 11, // [11:11] is the sub-list for extension extendee - 0, // [0:11] is the sub-list for field type_name -} - -func init() { file_testpb_msg_proto_init() } -func file_testpb_msg_proto_init() { - if File_testpb_msg_proto != nil { - return - } - file_testpb_query_proto_init() - if !protoimpl.UnsafeEnabled { - file_testpb_msg_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*MsgRequest); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_testpb_msg_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*MsgResponse); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_testpb_msg_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*MsgClawbackRequest); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_testpb_msg_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*MsgClawbackResponse); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - } - type x struct{} - out := protoimpl.TypeBuilder{ - File: protoimpl.DescBuilder{ - GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_testpb_msg_proto_rawDesc, - NumEnums: 0, - NumMessages: 4, - NumExtensions: 0, - NumServices: 1, - }, - GoTypes: file_testpb_msg_proto_goTypes, - DependencyIndexes: file_testpb_msg_proto_depIdxs, - MessageInfos: file_testpb_msg_proto_msgTypes, - }.Build() - File_testpb_msg_proto = out.File - file_testpb_msg_proto_rawDesc = nil - file_testpb_msg_proto_goTypes = nil - file_testpb_msg_proto_depIdxs = nil -} diff --git a/connect/internal/testpb/msg_grpc.pb.go b/connect/internal/testpb/msg_grpc.pb.go deleted file mode 100644 index 703528e2..00000000 --- a/connect/internal/testpb/msg_grpc.pb.go +++ /dev/null @@ -1,161 +0,0 @@ -// Code generated by protoc-gen-go-grpc. DO NOT EDIT. -// versions: -// - protoc-gen-go-grpc v1.5.1 -// - protoc (unknown) -// source: testpb/msg.proto - -package testpb - -import ( - context "context" - grpc "google.golang.org/grpc" - codes "google.golang.org/grpc/codes" - status "google.golang.org/grpc/status" -) - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the grpc package it is being compiled against. -// Requires gRPC-Go v1.64.0 or later. -const _ = grpc.SupportPackageIsVersion9 - -const ( - Msg_Send_FullMethodName = "/testpb.Msg/Send" - Msg_Clawback_FullMethodName = "/testpb.Msg/Clawback" -) - -// MsgClient is the client API for Msg service. -// -// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. -type MsgClient interface { - // Send a request and returns the request as a response. - Send(ctx context.Context, in *MsgRequest, opts ...grpc.CallOption) (*MsgResponse, error) - Clawback(ctx context.Context, in *MsgClawbackRequest, opts ...grpc.CallOption) (*MsgClawbackResponse, error) -} - -type msgClient struct { - cc grpc.ClientConnInterface -} - -func NewMsgClient(cc grpc.ClientConnInterface) MsgClient { - return &msgClient{cc} -} - -func (c *msgClient) Send(ctx context.Context, in *MsgRequest, opts ...grpc.CallOption) (*MsgResponse, error) { - cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) - out := new(MsgResponse) - err := c.cc.Invoke(ctx, Msg_Send_FullMethodName, in, out, cOpts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *msgClient) Clawback(ctx context.Context, in *MsgClawbackRequest, opts ...grpc.CallOption) (*MsgClawbackResponse, error) { - cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) - out := new(MsgClawbackResponse) - err := c.cc.Invoke(ctx, Msg_Clawback_FullMethodName, in, out, cOpts...) - if err != nil { - return nil, err - } - return out, nil -} - -// MsgServer is the server API for Msg service. -// All implementations must embed UnimplementedMsgServer -// for forward compatibility. -type MsgServer interface { - // Send a request and returns the request as a response. - Send(context.Context, *MsgRequest) (*MsgResponse, error) - Clawback(context.Context, *MsgClawbackRequest) (*MsgClawbackResponse, error) - mustEmbedUnimplementedMsgServer() -} - -// UnimplementedMsgServer must be embedded to have -// forward compatible implementations. -// -// NOTE: this should be embedded by value instead of pointer to avoid a nil -// pointer dereference when methods are called. -type UnimplementedMsgServer struct{} - -func (UnimplementedMsgServer) Send(context.Context, *MsgRequest) (*MsgResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method Send not implemented") -} -func (UnimplementedMsgServer) Clawback(context.Context, *MsgClawbackRequest) (*MsgClawbackResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method Clawback not implemented") -} -func (UnimplementedMsgServer) mustEmbedUnimplementedMsgServer() {} -func (UnimplementedMsgServer) testEmbeddedByValue() {} - -// UnsafeMsgServer may be embedded to opt out of forward compatibility for this service. -// Use of this interface is not recommended, as added methods to MsgServer will -// result in compilation errors. -type UnsafeMsgServer interface { - mustEmbedUnimplementedMsgServer() -} - -func RegisterMsgServer(s grpc.ServiceRegistrar, srv MsgServer) { - // If the following call pancis, it indicates UnimplementedMsgServer was - // embedded by pointer and is nil. This will cause panics if an - // unimplemented method is ever invoked, so we test this at initialization - // time to prevent it from happening at runtime later due to I/O. - if t, ok := srv.(interface{ testEmbeddedByValue() }); ok { - t.testEmbeddedByValue() - } - s.RegisterService(&Msg_ServiceDesc, srv) -} - -func _Msg_Send_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(MsgRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(MsgServer).Send(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: Msg_Send_FullMethodName, - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(MsgServer).Send(ctx, req.(*MsgRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Msg_Clawback_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(MsgClawbackRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(MsgServer).Clawback(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: Msg_Clawback_FullMethodName, - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(MsgServer).Clawback(ctx, req.(*MsgClawbackRequest)) - } - return interceptor(ctx, in, info, handler) -} - -// Msg_ServiceDesc is the grpc.ServiceDesc for Msg service. -// It's only intended for direct use with grpc.RegisterService, -// and not to be introspected or modified (even as a copy) -var Msg_ServiceDesc = grpc.ServiceDesc{ - ServiceName: "testpb.Msg", - HandlerType: (*MsgServer)(nil), - Methods: []grpc.MethodDesc{ - { - MethodName: "Send", - Handler: _Msg_Send_Handler, - }, - { - MethodName: "Clawback", - Handler: _Msg_Clawback_Handler, - }, - }, - Streams: []grpc.StreamDesc{}, - Metadata: "testpb/msg.proto", -} diff --git a/connect/internal/testpb/query.proto b/connect/internal/testpb/query.proto deleted file mode 100644 index 86c852e5..00000000 --- a/connect/internal/testpb/query.proto +++ /dev/null @@ -1,70 +0,0 @@ -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"; - -service Query { - // Echo returns the request in the response - rpc Echo(EchoRequest) returns (EchoResponse); -} - -message AMessage { - string bar = 1; - int32 baz = 2; -} - -message EchoRequest { - // 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; - Enum an_enum = 16; - 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 Enum enums = 24; - repeated google.protobuf.Duration durations = 25; - repeated 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; - map map_string_string = 33; - map map_string_uint32 = 34; - map map_string_coin = 35; - string a_validator_address = 36 [(cosmos_proto.scalar) = "cosmos.ValidatorAddressString"]; - string a_consensus_address = 37 [(cosmos_proto.scalar) = "cosmos.ConsensusAddressString"]; - - repeated cosmos.base.v1beta1.Coin coins = 38; -} - -enum Enum { - ENUM_UNSPECIFIED = 0; - ENUM_ONE = 1; - ENUM_TWO = 2; - ENUM_FIVE = 5; - ENUM_NEG_THREE = -3; -} - -message EchoResponse { - EchoRequest request = 1; -} diff --git a/connect/internal/testpb/query.pulsar.go b/connect/internal/testpb/query.pulsar.go deleted file mode 100644 index 53f899b3..00000000 --- a/connect/internal/testpb/query.pulsar.go +++ /dev/null @@ -1,5438 +0,0 @@ -// Code generated by protoc-gen-go-pulsar. DO NOT EDIT. -package testpb - -import ( - v1beta11 "cosmossdk.io/api/cosmos/base/query/v1beta1" - v1beta1 "cosmossdk.io/api/cosmos/base/v1beta1" - fmt "fmt" - _ "github.com/cosmos/cosmos-proto" - runtime "github.com/cosmos/cosmos-proto/runtime" - protoreflect "google.golang.org/protobuf/reflect/protoreflect" - protoiface "google.golang.org/protobuf/runtime/protoiface" - protoimpl "google.golang.org/protobuf/runtime/protoimpl" - durationpb "google.golang.org/protobuf/types/known/durationpb" - timestamppb "google.golang.org/protobuf/types/known/timestamppb" - io "io" - reflect "reflect" - sort "sort" - sync "sync" -) - -var ( - md_AMessage protoreflect.MessageDescriptor - fd_AMessage_bar protoreflect.FieldDescriptor - fd_AMessage_baz protoreflect.FieldDescriptor -) - -func init() { - file_testpb_query_proto_init() - md_AMessage = File_testpb_query_proto.Messages().ByName("AMessage") - fd_AMessage_bar = md_AMessage.Fields().ByName("bar") - fd_AMessage_baz = md_AMessage.Fields().ByName("baz") -} - -var _ protoreflect.Message = (*fastReflection_AMessage)(nil) - -type fastReflection_AMessage AMessage - -func (x *AMessage) ProtoReflect() protoreflect.Message { - return (*fastReflection_AMessage)(x) -} - -func (x *AMessage) slowProtoReflect() protoreflect.Message { - mi := &file_testpb_query_proto_msgTypes[0] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -var _fastReflection_AMessage_messageType fastReflection_AMessage_messageType -var _ protoreflect.MessageType = fastReflection_AMessage_messageType{} - -type fastReflection_AMessage_messageType struct{} - -func (x fastReflection_AMessage_messageType) Zero() protoreflect.Message { - return (*fastReflection_AMessage)(nil) -} -func (x fastReflection_AMessage_messageType) New() protoreflect.Message { - return new(fastReflection_AMessage) -} -func (x fastReflection_AMessage_messageType) Descriptor() protoreflect.MessageDescriptor { - return md_AMessage -} - -// Descriptor returns message descriptor, which contains only the protobuf -// type information for the message. -func (x *fastReflection_AMessage) Descriptor() protoreflect.MessageDescriptor { - return md_AMessage -} - -// Type returns the message type, which encapsulates both Go and protobuf -// type information. If the Go type information is not needed, -// it is recommended that the message descriptor be used instead. -func (x *fastReflection_AMessage) Type() protoreflect.MessageType { - return _fastReflection_AMessage_messageType -} - -// New returns a newly allocated and mutable empty message. -func (x *fastReflection_AMessage) New() protoreflect.Message { - return new(fastReflection_AMessage) -} - -// Interface unwraps the message reflection interface and -// returns the underlying ProtoMessage interface. -func (x *fastReflection_AMessage) Interface() protoreflect.ProtoMessage { - return (*AMessage)(x) -} - -// Range iterates over every populated field in an undefined order, -// calling f for each field descriptor and value encountered. -// Range returns immediately if f returns false. -// While iterating, mutating operations may only be performed -// on the current field descriptor. -func (x *fastReflection_AMessage) Range(f func(protoreflect.FieldDescriptor, protoreflect.Value) bool) { - if x.Bar != "" { - value := protoreflect.ValueOfString(x.Bar) - if !f(fd_AMessage_bar, value) { - return - } - } - if x.Baz != int32(0) { - value := protoreflect.ValueOfInt32(x.Baz) - if !f(fd_AMessage_baz, value) { - return - } - } -} - -// Has reports whether a field is populated. -// -// Some fields have the property of nullability where it is possible to -// distinguish between the default value of a field and whether the field -// was explicitly populated with the default value. Singular message fields, -// member fields of a oneof, and proto2 scalar fields are nullable. Such -// fields are populated only if explicitly set. -// -// In other cases (aside from the nullable cases above), -// a proto3 scalar field is populated if it contains a non-zero value, and -// a repeated field is populated if it is non-empty. -func (x *fastReflection_AMessage) Has(fd protoreflect.FieldDescriptor) bool { - switch fd.FullName() { - case "testpb.AMessage.bar": - return x.Bar != "" - case "testpb.AMessage.baz": - return x.Baz != int32(0) - default: - if fd.IsExtension() { - panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.AMessage")) - } - panic(fmt.Errorf("message testpb.AMessage does not contain field %s", fd.FullName())) - } -} - -// Clear clears the field such that a subsequent Has call reports false. -// -// Clearing an extension field clears both the extension type and value -// associated with the given field number. -// -// Clear is a mutating operation and unsafe for concurrent use. -func (x *fastReflection_AMessage) Clear(fd protoreflect.FieldDescriptor) { - switch fd.FullName() { - case "testpb.AMessage.bar": - x.Bar = "" - case "testpb.AMessage.baz": - x.Baz = int32(0) - default: - if fd.IsExtension() { - panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.AMessage")) - } - panic(fmt.Errorf("message testpb.AMessage does not contain field %s", fd.FullName())) - } -} - -// Get retrieves the value for a field. -// -// For unpopulated scalars, it returns the default value, where -// the default value of a bytes scalar is guaranteed to be a copy. -// For unpopulated composite types, it returns an empty, read-only view -// of the value; to obtain a mutable reference, use Mutable. -func (x *fastReflection_AMessage) Get(descriptor protoreflect.FieldDescriptor) protoreflect.Value { - switch descriptor.FullName() { - case "testpb.AMessage.bar": - value := x.Bar - return protoreflect.ValueOfString(value) - case "testpb.AMessage.baz": - value := x.Baz - return protoreflect.ValueOfInt32(value) - default: - if descriptor.IsExtension() { - panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.AMessage")) - } - panic(fmt.Errorf("message testpb.AMessage does not contain field %s", descriptor.FullName())) - } -} - -// Set stores the value for a field. -// -// For a field belonging to a oneof, it implicitly clears any other field -// that may be currently set within the same oneof. -// For extension fields, it implicitly stores the provided ExtensionType. -// When setting a composite type, it is unspecified whether the stored value -// aliases the source's memory in any way. If the composite value is an -// empty, read-only value, then it panics. -// -// Set is a mutating operation and unsafe for concurrent use. -func (x *fastReflection_AMessage) Set(fd protoreflect.FieldDescriptor, value protoreflect.Value) { - switch fd.FullName() { - case "testpb.AMessage.bar": - x.Bar = value.Interface().(string) - case "testpb.AMessage.baz": - x.Baz = int32(value.Int()) - default: - if fd.IsExtension() { - panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.AMessage")) - } - panic(fmt.Errorf("message testpb.AMessage does not contain field %s", fd.FullName())) - } -} - -// Mutable returns a mutable reference to a composite type. -// -// If the field is unpopulated, it may allocate a composite value. -// For a field belonging to a oneof, it implicitly clears any other field -// that may be currently set within the same oneof. -// For extension fields, it implicitly stores the provided ExtensionType -// if not already stored. -// It panics if the field does not contain a composite type. -// -// Mutable is a mutating operation and unsafe for concurrent use. -func (x *fastReflection_AMessage) Mutable(fd protoreflect.FieldDescriptor) protoreflect.Value { - switch fd.FullName() { - case "testpb.AMessage.bar": - panic(fmt.Errorf("field bar of message testpb.AMessage is not mutable")) - case "testpb.AMessage.baz": - panic(fmt.Errorf("field baz of message testpb.AMessage is not mutable")) - default: - if fd.IsExtension() { - panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.AMessage")) - } - panic(fmt.Errorf("message testpb.AMessage does not contain field %s", fd.FullName())) - } -} - -// NewField returns a new value that is assignable to the field -// for the given descriptor. For scalars, this returns the default value. -// For lists, maps, and messages, this returns a new, empty, mutable value. -func (x *fastReflection_AMessage) NewField(fd protoreflect.FieldDescriptor) protoreflect.Value { - switch fd.FullName() { - case "testpb.AMessage.bar": - return protoreflect.ValueOfString("") - case "testpb.AMessage.baz": - return protoreflect.ValueOfInt32(int32(0)) - default: - if fd.IsExtension() { - panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.AMessage")) - } - panic(fmt.Errorf("message testpb.AMessage does not contain field %s", fd.FullName())) - } -} - -// WhichOneof reports which field within the oneof is populated, -// returning nil if none are populated. -// It panics if the oneof descriptor does not belong to this message. -func (x *fastReflection_AMessage) WhichOneof(d protoreflect.OneofDescriptor) protoreflect.FieldDescriptor { - switch d.FullName() { - default: - panic(fmt.Errorf("%s is not a oneof field in testpb.AMessage", d.FullName())) - } - panic("unreachable") -} - -// GetUnknown retrieves the entire list of unknown fields. -// The caller may only mutate the contents of the RawFields -// if the mutated bytes are stored back into the message with SetUnknown. -func (x *fastReflection_AMessage) GetUnknown() protoreflect.RawFields { - return x.unknownFields -} - -// SetUnknown stores an entire list of unknown fields. -// The raw fields must be syntactically valid according to the wire format. -// An implementation may panic if this is not the case. -// Once stored, the caller must not mutate the content of the RawFields. -// An empty RawFields may be passed to clear the fields. -// -// SetUnknown is a mutating operation and unsafe for concurrent use. -func (x *fastReflection_AMessage) SetUnknown(fields protoreflect.RawFields) { - x.unknownFields = fields -} - -// IsValid reports whether the message is valid. -// -// An invalid message is an empty, read-only value. -// -// An invalid message often corresponds to a nil pointer of the concrete -// message type, but the details are implementation dependent. -// Validity is not part of the protobuf data model, and may not -// be preserved in marshaling or other operations. -func (x *fastReflection_AMessage) IsValid() bool { - return x != nil -} - -// ProtoMethods returns optional fastReflectionFeature-path implementations of various operations. -// This method may return nil. -// -// The returned methods type is identical to -// "google.golang.org/protobuf/runtime/protoiface".Methods. -// Consult the protoiface package documentation for details. -func (x *fastReflection_AMessage) ProtoMethods() *protoiface.Methods { - size := func(input protoiface.SizeInput) protoiface.SizeOutput { - x := input.Message.Interface().(*AMessage) - if x == nil { - return protoiface.SizeOutput{ - NoUnkeyedLiterals: input.NoUnkeyedLiterals, - Size: 0, - } - } - options := runtime.SizeInputToOptions(input) - _ = options - var n int - var l int - _ = l - l = len(x.Bar) - if l > 0 { - n += 1 + l + runtime.Sov(uint64(l)) - } - if x.Baz != 0 { - n += 1 + runtime.Sov(uint64(x.Baz)) - } - if x.unknownFields != nil { - n += len(x.unknownFields) - } - return protoiface.SizeOutput{ - NoUnkeyedLiterals: input.NoUnkeyedLiterals, - Size: n, - } - } - - marshal := func(input protoiface.MarshalInput) (protoiface.MarshalOutput, error) { - x := input.Message.Interface().(*AMessage) - if x == nil { - return protoiface.MarshalOutput{ - NoUnkeyedLiterals: input.NoUnkeyedLiterals, - Buf: input.Buf, - }, nil - } - options := runtime.MarshalInputToOptions(input) - _ = options - size := options.Size(x) - dAtA := make([]byte, size) - i := len(dAtA) - _ = i - var l int - _ = l - if x.unknownFields != nil { - i -= len(x.unknownFields) - copy(dAtA[i:], x.unknownFields) - } - if x.Baz != 0 { - i = runtime.EncodeVarint(dAtA, i, uint64(x.Baz)) - i-- - dAtA[i] = 0x10 - } - if len(x.Bar) > 0 { - i -= len(x.Bar) - copy(dAtA[i:], x.Bar) - i = runtime.EncodeVarint(dAtA, i, uint64(len(x.Bar))) - i-- - dAtA[i] = 0xa - } - if input.Buf != nil { - input.Buf = append(input.Buf, dAtA...) - } else { - input.Buf = dAtA - } - return protoiface.MarshalOutput{ - NoUnkeyedLiterals: input.NoUnkeyedLiterals, - Buf: input.Buf, - }, nil - } - unmarshal := func(input protoiface.UnmarshalInput) (protoiface.UnmarshalOutput, error) { - x := input.Message.Interface().(*AMessage) - if x == nil { - return protoiface.UnmarshalOutput{ - NoUnkeyedLiterals: input.NoUnkeyedLiterals, - Flags: input.Flags, - }, nil - } - options := runtime.UnmarshalInputToOptions(input) - _ = options - dAtA := input.Buf - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: AMessage: wiretype end group for non-group") - } - if fieldNum <= 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: AMessage: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Bar", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - if postIndex > l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - x.Bar = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - if wireType != 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Baz", wireType) - } - x.Baz = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - x.Baz |= int32(b&0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := runtime.Skip(dAtA[iNdEx:]) - if err != nil { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - if (iNdEx + skippy) > l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - if !options.DiscardUnknown { - x.unknownFields = append(x.unknownFields, dAtA[iNdEx:iNdEx+skippy]...) - } - iNdEx += skippy - } - } - - if iNdEx > l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, nil - } - return &protoiface.Methods{ - NoUnkeyedLiterals: struct{}{}, - Flags: protoiface.SupportMarshalDeterministic | protoiface.SupportUnmarshalDiscardUnknown, - Size: size, - Marshal: marshal, - Unmarshal: unmarshal, - Merge: nil, - CheckInitialized: nil, - } -} - -var _ protoreflect.List = (*_EchoRequest_21_list)(nil) - -type _EchoRequest_21_list struct { - list *[]bool -} - -func (x *_EchoRequest_21_list) Len() int { - if x.list == nil { - return 0 - } - return len(*x.list) -} - -func (x *_EchoRequest_21_list) Get(i int) protoreflect.Value { - return protoreflect.ValueOfBool((*x.list)[i]) -} - -func (x *_EchoRequest_21_list) Set(i int, value protoreflect.Value) { - valueUnwrapped := value.Bool() - concreteValue := valueUnwrapped - (*x.list)[i] = concreteValue -} - -func (x *_EchoRequest_21_list) Append(value protoreflect.Value) { - valueUnwrapped := value.Bool() - concreteValue := valueUnwrapped - *x.list = append(*x.list, concreteValue) -} - -func (x *_EchoRequest_21_list) AppendMutable() protoreflect.Value { - panic(fmt.Errorf("AppendMutable can not be called on message EchoRequest at list field Bools as it is not of Message kind")) -} - -func (x *_EchoRequest_21_list) Truncate(n int) { - *x.list = (*x.list)[:n] -} - -func (x *_EchoRequest_21_list) NewElement() protoreflect.Value { - v := false - return protoreflect.ValueOfBool(v) -} - -func (x *_EchoRequest_21_list) IsValid() bool { - return x.list != nil -} - -var _ protoreflect.List = (*_EchoRequest_22_list)(nil) - -type _EchoRequest_22_list struct { - list *[]uint32 -} - -func (x *_EchoRequest_22_list) Len() int { - if x.list == nil { - return 0 - } - return len(*x.list) -} - -func (x *_EchoRequest_22_list) Get(i int) protoreflect.Value { - return protoreflect.ValueOfUint32((*x.list)[i]) -} - -func (x *_EchoRequest_22_list) Set(i int, value protoreflect.Value) { - valueUnwrapped := value.Uint() - concreteValue := (uint32)(valueUnwrapped) - (*x.list)[i] = concreteValue -} - -func (x *_EchoRequest_22_list) Append(value protoreflect.Value) { - valueUnwrapped := value.Uint() - concreteValue := (uint32)(valueUnwrapped) - *x.list = append(*x.list, concreteValue) -} - -func (x *_EchoRequest_22_list) AppendMutable() protoreflect.Value { - panic(fmt.Errorf("AppendMutable can not be called on message EchoRequest at list field Uints as it is not of Message kind")) -} - -func (x *_EchoRequest_22_list) Truncate(n int) { - *x.list = (*x.list)[:n] -} - -func (x *_EchoRequest_22_list) NewElement() protoreflect.Value { - v := uint32(0) - return protoreflect.ValueOfUint32(v) -} - -func (x *_EchoRequest_22_list) IsValid() bool { - return x.list != nil -} - -var _ protoreflect.List = (*_EchoRequest_23_list)(nil) - -type _EchoRequest_23_list struct { - list *[]string -} - -func (x *_EchoRequest_23_list) Len() int { - if x.list == nil { - return 0 - } - return len(*x.list) -} - -func (x *_EchoRequest_23_list) Get(i int) protoreflect.Value { - return protoreflect.ValueOfString((*x.list)[i]) -} - -func (x *_EchoRequest_23_list) Set(i int, value protoreflect.Value) { - valueUnwrapped := value.String() - concreteValue := valueUnwrapped - (*x.list)[i] = concreteValue -} - -func (x *_EchoRequest_23_list) Append(value protoreflect.Value) { - valueUnwrapped := value.String() - concreteValue := valueUnwrapped - *x.list = append(*x.list, concreteValue) -} - -func (x *_EchoRequest_23_list) AppendMutable() protoreflect.Value { - panic(fmt.Errorf("AppendMutable can not be called on message EchoRequest at list field Strings as it is not of Message kind")) -} - -func (x *_EchoRequest_23_list) Truncate(n int) { - *x.list = (*x.list)[:n] -} - -func (x *_EchoRequest_23_list) NewElement() protoreflect.Value { - v := "" - return protoreflect.ValueOfString(v) -} - -func (x *_EchoRequest_23_list) IsValid() bool { - return x.list != nil -} - -var _ protoreflect.List = (*_EchoRequest_24_list)(nil) - -type _EchoRequest_24_list struct { - list *[]Enum -} - -func (x *_EchoRequest_24_list) Len() int { - if x.list == nil { - return 0 - } - return len(*x.list) -} - -func (x *_EchoRequest_24_list) Get(i int) protoreflect.Value { - return protoreflect.ValueOfEnum((protoreflect.EnumNumber)((*x.list)[i])) -} - -func (x *_EchoRequest_24_list) Set(i int, value protoreflect.Value) { - valueUnwrapped := value.Enum() - concreteValue := (Enum)(valueUnwrapped) - (*x.list)[i] = concreteValue -} - -func (x *_EchoRequest_24_list) Append(value protoreflect.Value) { - valueUnwrapped := value.Enum() - concreteValue := (Enum)(valueUnwrapped) - *x.list = append(*x.list, concreteValue) -} - -func (x *_EchoRequest_24_list) AppendMutable() protoreflect.Value { - panic(fmt.Errorf("AppendMutable can not be called on message EchoRequest at list field Enums as it is not of Message kind")) -} - -func (x *_EchoRequest_24_list) Truncate(n int) { - *x.list = (*x.list)[:n] -} - -func (x *_EchoRequest_24_list) NewElement() protoreflect.Value { - v := 0 - return protoreflect.ValueOfEnum((protoreflect.EnumNumber)(v)) -} - -func (x *_EchoRequest_24_list) IsValid() bool { - return x.list != nil -} - -var _ protoreflect.List = (*_EchoRequest_25_list)(nil) - -type _EchoRequest_25_list struct { - list *[]*durationpb.Duration -} - -func (x *_EchoRequest_25_list) Len() int { - if x.list == nil { - return 0 - } - return len(*x.list) -} - -func (x *_EchoRequest_25_list) Get(i int) protoreflect.Value { - return protoreflect.ValueOfMessage((*x.list)[i].ProtoReflect()) -} - -func (x *_EchoRequest_25_list) Set(i int, value protoreflect.Value) { - valueUnwrapped := value.Message() - concreteValue := valueUnwrapped.Interface().(*durationpb.Duration) - (*x.list)[i] = concreteValue -} - -func (x *_EchoRequest_25_list) Append(value protoreflect.Value) { - valueUnwrapped := value.Message() - concreteValue := valueUnwrapped.Interface().(*durationpb.Duration) - *x.list = append(*x.list, concreteValue) -} - -func (x *_EchoRequest_25_list) AppendMutable() protoreflect.Value { - v := new(durationpb.Duration) - *x.list = append(*x.list, v) - return protoreflect.ValueOfMessage(v.ProtoReflect()) -} - -func (x *_EchoRequest_25_list) Truncate(n int) { - for i := n; i < len(*x.list); i++ { - (*x.list)[i] = nil - } - *x.list = (*x.list)[:n] -} - -func (x *_EchoRequest_25_list) NewElement() protoreflect.Value { - v := new(durationpb.Duration) - return protoreflect.ValueOfMessage(v.ProtoReflect()) -} - -func (x *_EchoRequest_25_list) IsValid() bool { - return x.list != nil -} - -var _ protoreflect.List = (*_EchoRequest_26_list)(nil) - -type _EchoRequest_26_list struct { - list *[]*AMessage -} - -func (x *_EchoRequest_26_list) Len() int { - if x.list == nil { - return 0 - } - return len(*x.list) -} - -func (x *_EchoRequest_26_list) Get(i int) protoreflect.Value { - return protoreflect.ValueOfMessage((*x.list)[i].ProtoReflect()) -} - -func (x *_EchoRequest_26_list) Set(i int, value protoreflect.Value) { - valueUnwrapped := value.Message() - concreteValue := valueUnwrapped.Interface().(*AMessage) - (*x.list)[i] = concreteValue -} - -func (x *_EchoRequest_26_list) Append(value protoreflect.Value) { - valueUnwrapped := value.Message() - concreteValue := valueUnwrapped.Interface().(*AMessage) - *x.list = append(*x.list, concreteValue) -} - -func (x *_EchoRequest_26_list) AppendMutable() protoreflect.Value { - v := new(AMessage) - *x.list = append(*x.list, v) - return protoreflect.ValueOfMessage(v.ProtoReflect()) -} - -func (x *_EchoRequest_26_list) Truncate(n int) { - for i := n; i < len(*x.list); i++ { - (*x.list)[i] = nil - } - *x.list = (*x.list)[:n] -} - -func (x *_EchoRequest_26_list) NewElement() protoreflect.Value { - v := new(AMessage) - return protoreflect.ValueOfMessage(v.ProtoReflect()) -} - -func (x *_EchoRequest_26_list) IsValid() bool { - return x.list != nil -} - -var _ protoreflect.List = (*_EchoRequest_29_list)(nil) - -type _EchoRequest_29_list struct { - list *[]*v1beta1.Coin -} - -func (x *_EchoRequest_29_list) Len() int { - if x.list == nil { - return 0 - } - return len(*x.list) -} - -func (x *_EchoRequest_29_list) Get(i int) protoreflect.Value { - return protoreflect.ValueOfMessage((*x.list)[i].ProtoReflect()) -} - -func (x *_EchoRequest_29_list) Set(i int, value protoreflect.Value) { - valueUnwrapped := value.Message() - concreteValue := valueUnwrapped.Interface().(*v1beta1.Coin) - (*x.list)[i] = concreteValue -} - -func (x *_EchoRequest_29_list) Append(value protoreflect.Value) { - valueUnwrapped := value.Message() - concreteValue := valueUnwrapped.Interface().(*v1beta1.Coin) - *x.list = append(*x.list, concreteValue) -} - -func (x *_EchoRequest_29_list) AppendMutable() protoreflect.Value { - v := new(v1beta1.Coin) - *x.list = append(*x.list, v) - return protoreflect.ValueOfMessage(v.ProtoReflect()) -} - -func (x *_EchoRequest_29_list) Truncate(n int) { - for i := n; i < len(*x.list); i++ { - (*x.list)[i] = nil - } - *x.list = (*x.list)[:n] -} - -func (x *_EchoRequest_29_list) NewElement() protoreflect.Value { - v := new(v1beta1.Coin) - return protoreflect.ValueOfMessage(v.ProtoReflect()) -} - -func (x *_EchoRequest_29_list) IsValid() bool { - return x.list != nil -} - -var _ protoreflect.Map = (*_EchoRequest_33_map)(nil) - -type _EchoRequest_33_map struct { - m *map[string]string -} - -func (x *_EchoRequest_33_map) Len() int { - if x.m == nil { - return 0 - } - return len(*x.m) -} - -func (x *_EchoRequest_33_map) Range(f func(protoreflect.MapKey, protoreflect.Value) bool) { - if x.m == nil { - return - } - for k, v := range *x.m { - mapKey := (protoreflect.MapKey)(protoreflect.ValueOfString(k)) - mapValue := protoreflect.ValueOfString(v) - if !f(mapKey, mapValue) { - break - } - } -} - -func (x *_EchoRequest_33_map) Has(key protoreflect.MapKey) bool { - if x.m == nil { - return false - } - keyUnwrapped := key.String() - concreteValue := keyUnwrapped - _, ok := (*x.m)[concreteValue] - return ok -} - -func (x *_EchoRequest_33_map) Clear(key protoreflect.MapKey) { - if x.m == nil { - return - } - keyUnwrapped := key.String() - concreteKey := keyUnwrapped - delete(*x.m, concreteKey) -} - -func (x *_EchoRequest_33_map) Get(key protoreflect.MapKey) protoreflect.Value { - if x.m == nil { - return protoreflect.Value{} - } - keyUnwrapped := key.String() - concreteKey := keyUnwrapped - v, ok := (*x.m)[concreteKey] - if !ok { - return protoreflect.Value{} - } - return protoreflect.ValueOfString(v) -} - -func (x *_EchoRequest_33_map) Set(key protoreflect.MapKey, value protoreflect.Value) { - if !key.IsValid() || !value.IsValid() { - panic("invalid key or value provided") - } - keyUnwrapped := key.String() - concreteKey := keyUnwrapped - valueUnwrapped := value.String() - concreteValue := valueUnwrapped - (*x.m)[concreteKey] = concreteValue -} - -func (x *_EchoRequest_33_map) Mutable(key protoreflect.MapKey) protoreflect.Value { - panic("should not call Mutable on protoreflect.Map whose value is not of type protoreflect.Message") -} - -func (x *_EchoRequest_33_map) NewValue() protoreflect.Value { - v := "" - return protoreflect.ValueOfString(v) -} - -func (x *_EchoRequest_33_map) IsValid() bool { - return x.m != nil -} - -var _ protoreflect.Map = (*_EchoRequest_34_map)(nil) - -type _EchoRequest_34_map struct { - m *map[string]uint32 -} - -func (x *_EchoRequest_34_map) Len() int { - if x.m == nil { - return 0 - } - return len(*x.m) -} - -func (x *_EchoRequest_34_map) Range(f func(protoreflect.MapKey, protoreflect.Value) bool) { - if x.m == nil { - return - } - for k, v := range *x.m { - mapKey := (protoreflect.MapKey)(protoreflect.ValueOfString(k)) - mapValue := protoreflect.ValueOfUint32(v) - if !f(mapKey, mapValue) { - break - } - } -} - -func (x *_EchoRequest_34_map) Has(key protoreflect.MapKey) bool { - if x.m == nil { - return false - } - keyUnwrapped := key.String() - concreteValue := keyUnwrapped - _, ok := (*x.m)[concreteValue] - return ok -} - -func (x *_EchoRequest_34_map) Clear(key protoreflect.MapKey) { - if x.m == nil { - return - } - keyUnwrapped := key.String() - concreteKey := keyUnwrapped - delete(*x.m, concreteKey) -} - -func (x *_EchoRequest_34_map) Get(key protoreflect.MapKey) protoreflect.Value { - if x.m == nil { - return protoreflect.Value{} - } - keyUnwrapped := key.String() - concreteKey := keyUnwrapped - v, ok := (*x.m)[concreteKey] - if !ok { - return protoreflect.Value{} - } - return protoreflect.ValueOfUint32(v) -} - -func (x *_EchoRequest_34_map) Set(key protoreflect.MapKey, value protoreflect.Value) { - if !key.IsValid() || !value.IsValid() { - panic("invalid key or value provided") - } - keyUnwrapped := key.String() - concreteKey := keyUnwrapped - valueUnwrapped := value.Uint() - concreteValue := (uint32)(valueUnwrapped) - (*x.m)[concreteKey] = concreteValue -} - -func (x *_EchoRequest_34_map) Mutable(key protoreflect.MapKey) protoreflect.Value { - panic("should not call Mutable on protoreflect.Map whose value is not of type protoreflect.Message") -} - -func (x *_EchoRequest_34_map) NewValue() protoreflect.Value { - v := uint32(0) - return protoreflect.ValueOfUint32(v) -} - -func (x *_EchoRequest_34_map) IsValid() bool { - return x.m != nil -} - -var _ protoreflect.Map = (*_EchoRequest_35_map)(nil) - -type _EchoRequest_35_map struct { - m *map[string]*v1beta1.Coin -} - -func (x *_EchoRequest_35_map) Len() int { - if x.m == nil { - return 0 - } - return len(*x.m) -} - -func (x *_EchoRequest_35_map) Range(f func(protoreflect.MapKey, protoreflect.Value) bool) { - if x.m == nil { - return - } - for k, v := range *x.m { - mapKey := (protoreflect.MapKey)(protoreflect.ValueOfString(k)) - mapValue := protoreflect.ValueOfMessage(v.ProtoReflect()) - if !f(mapKey, mapValue) { - break - } - } -} - -func (x *_EchoRequest_35_map) Has(key protoreflect.MapKey) bool { - if x.m == nil { - return false - } - keyUnwrapped := key.String() - concreteValue := keyUnwrapped - _, ok := (*x.m)[concreteValue] - return ok -} - -func (x *_EchoRequest_35_map) Clear(key protoreflect.MapKey) { - if x.m == nil { - return - } - keyUnwrapped := key.String() - concreteKey := keyUnwrapped - delete(*x.m, concreteKey) -} - -func (x *_EchoRequest_35_map) Get(key protoreflect.MapKey) protoreflect.Value { - if x.m == nil { - return protoreflect.Value{} - } - keyUnwrapped := key.String() - concreteKey := keyUnwrapped - v, ok := (*x.m)[concreteKey] - if !ok { - return protoreflect.Value{} - } - return protoreflect.ValueOfMessage(v.ProtoReflect()) -} - -func (x *_EchoRequest_35_map) Set(key protoreflect.MapKey, value protoreflect.Value) { - if !key.IsValid() || !value.IsValid() { - panic("invalid key or value provided") - } - keyUnwrapped := key.String() - concreteKey := keyUnwrapped - valueUnwrapped := value.Message() - concreteValue := valueUnwrapped.Interface().(*v1beta1.Coin) - (*x.m)[concreteKey] = concreteValue -} - -func (x *_EchoRequest_35_map) Mutable(key protoreflect.MapKey) protoreflect.Value { - keyUnwrapped := key.String() - concreteKey := keyUnwrapped - v, ok := (*x.m)[concreteKey] - if ok { - return protoreflect.ValueOfMessage(v.ProtoReflect()) - } - newValue := new(v1beta1.Coin) - (*x.m)[concreteKey] = newValue - return protoreflect.ValueOfMessage(newValue.ProtoReflect()) -} - -func (x *_EchoRequest_35_map) NewValue() protoreflect.Value { - v := new(v1beta1.Coin) - return protoreflect.ValueOfMessage(v.ProtoReflect()) -} - -func (x *_EchoRequest_35_map) IsValid() bool { - return x.m != nil -} - -var _ protoreflect.List = (*_EchoRequest_38_list)(nil) - -type _EchoRequest_38_list struct { - list *[]*v1beta1.Coin -} - -func (x *_EchoRequest_38_list) Len() int { - if x.list == nil { - return 0 - } - return len(*x.list) -} - -func (x *_EchoRequest_38_list) Get(i int) protoreflect.Value { - return protoreflect.ValueOfMessage((*x.list)[i].ProtoReflect()) -} - -func (x *_EchoRequest_38_list) Set(i int, value protoreflect.Value) { - valueUnwrapped := value.Message() - concreteValue := valueUnwrapped.Interface().(*v1beta1.Coin) - (*x.list)[i] = concreteValue -} - -func (x *_EchoRequest_38_list) Append(value protoreflect.Value) { - valueUnwrapped := value.Message() - concreteValue := valueUnwrapped.Interface().(*v1beta1.Coin) - *x.list = append(*x.list, concreteValue) -} - -func (x *_EchoRequest_38_list) AppendMutable() protoreflect.Value { - v := new(v1beta1.Coin) - *x.list = append(*x.list, v) - return protoreflect.ValueOfMessage(v.ProtoReflect()) -} - -func (x *_EchoRequest_38_list) Truncate(n int) { - for i := n; i < len(*x.list); i++ { - (*x.list)[i] = nil - } - *x.list = (*x.list)[:n] -} - -func (x *_EchoRequest_38_list) NewElement() protoreflect.Value { - v := new(v1beta1.Coin) - return protoreflect.ValueOfMessage(v.ProtoReflect()) -} - -func (x *_EchoRequest_38_list) IsValid() bool { - return x.list != nil -} - -var ( - md_EchoRequest protoreflect.MessageDescriptor - fd_EchoRequest_u32 protoreflect.FieldDescriptor - fd_EchoRequest_u64 protoreflect.FieldDescriptor - fd_EchoRequest_str protoreflect.FieldDescriptor - fd_EchoRequest_bz protoreflect.FieldDescriptor - fd_EchoRequest_timestamp protoreflect.FieldDescriptor - fd_EchoRequest_duration protoreflect.FieldDescriptor - fd_EchoRequest_i32 protoreflect.FieldDescriptor - fd_EchoRequest_i64 protoreflect.FieldDescriptor - fd_EchoRequest_a_bool protoreflect.FieldDescriptor - fd_EchoRequest_an_enum protoreflect.FieldDescriptor - fd_EchoRequest_a_message protoreflect.FieldDescriptor - fd_EchoRequest_a_coin protoreflect.FieldDescriptor - fd_EchoRequest_an_address protoreflect.FieldDescriptor - fd_EchoRequest_page protoreflect.FieldDescriptor - fd_EchoRequest_bools protoreflect.FieldDescriptor - fd_EchoRequest_uints protoreflect.FieldDescriptor - fd_EchoRequest_strings protoreflect.FieldDescriptor - fd_EchoRequest_enums protoreflect.FieldDescriptor - fd_EchoRequest_durations protoreflect.FieldDescriptor - fd_EchoRequest_some_messages protoreflect.FieldDescriptor - fd_EchoRequest_positional1 protoreflect.FieldDescriptor - fd_EchoRequest_positional2 protoreflect.FieldDescriptor - fd_EchoRequest_positional3_varargs protoreflect.FieldDescriptor - fd_EchoRequest_deprecated_field protoreflect.FieldDescriptor - fd_EchoRequest_shorthand_deprecated_field protoreflect.FieldDescriptor - fd_EchoRequest_hidden_bool protoreflect.FieldDescriptor - fd_EchoRequest_map_string_string protoreflect.FieldDescriptor - fd_EchoRequest_map_string_uint32 protoreflect.FieldDescriptor - fd_EchoRequest_map_string_coin protoreflect.FieldDescriptor - fd_EchoRequest_a_validator_address protoreflect.FieldDescriptor - fd_EchoRequest_a_consensus_address protoreflect.FieldDescriptor - fd_EchoRequest_coins protoreflect.FieldDescriptor -) - -func init() { - file_testpb_query_proto_init() - md_EchoRequest = File_testpb_query_proto.Messages().ByName("EchoRequest") - fd_EchoRequest_u32 = md_EchoRequest.Fields().ByName("u32") - fd_EchoRequest_u64 = md_EchoRequest.Fields().ByName("u64") - fd_EchoRequest_str = md_EchoRequest.Fields().ByName("str") - fd_EchoRequest_bz = md_EchoRequest.Fields().ByName("bz") - fd_EchoRequest_timestamp = md_EchoRequest.Fields().ByName("timestamp") - fd_EchoRequest_duration = md_EchoRequest.Fields().ByName("duration") - fd_EchoRequest_i32 = md_EchoRequest.Fields().ByName("i32") - fd_EchoRequest_i64 = md_EchoRequest.Fields().ByName("i64") - fd_EchoRequest_a_bool = md_EchoRequest.Fields().ByName("a_bool") - fd_EchoRequest_an_enum = md_EchoRequest.Fields().ByName("an_enum") - fd_EchoRequest_a_message = md_EchoRequest.Fields().ByName("a_message") - fd_EchoRequest_a_coin = md_EchoRequest.Fields().ByName("a_coin") - fd_EchoRequest_an_address = md_EchoRequest.Fields().ByName("an_address") - fd_EchoRequest_page = md_EchoRequest.Fields().ByName("page") - fd_EchoRequest_bools = md_EchoRequest.Fields().ByName("bools") - fd_EchoRequest_uints = md_EchoRequest.Fields().ByName("uints") - fd_EchoRequest_strings = md_EchoRequest.Fields().ByName("strings") - fd_EchoRequest_enums = md_EchoRequest.Fields().ByName("enums") - fd_EchoRequest_durations = md_EchoRequest.Fields().ByName("durations") - fd_EchoRequest_some_messages = md_EchoRequest.Fields().ByName("some_messages") - fd_EchoRequest_positional1 = md_EchoRequest.Fields().ByName("positional1") - fd_EchoRequest_positional2 = md_EchoRequest.Fields().ByName("positional2") - fd_EchoRequest_positional3_varargs = md_EchoRequest.Fields().ByName("positional3_varargs") - fd_EchoRequest_deprecated_field = md_EchoRequest.Fields().ByName("deprecated_field") - fd_EchoRequest_shorthand_deprecated_field = md_EchoRequest.Fields().ByName("shorthand_deprecated_field") - fd_EchoRequest_hidden_bool = md_EchoRequest.Fields().ByName("hidden_bool") - fd_EchoRequest_map_string_string = md_EchoRequest.Fields().ByName("map_string_string") - fd_EchoRequest_map_string_uint32 = md_EchoRequest.Fields().ByName("map_string_uint32") - fd_EchoRequest_map_string_coin = md_EchoRequest.Fields().ByName("map_string_coin") - fd_EchoRequest_a_validator_address = md_EchoRequest.Fields().ByName("a_validator_address") - fd_EchoRequest_a_consensus_address = md_EchoRequest.Fields().ByName("a_consensus_address") - fd_EchoRequest_coins = md_EchoRequest.Fields().ByName("coins") -} - -var _ protoreflect.Message = (*fastReflection_EchoRequest)(nil) - -type fastReflection_EchoRequest EchoRequest - -func (x *EchoRequest) ProtoReflect() protoreflect.Message { - return (*fastReflection_EchoRequest)(x) -} - -func (x *EchoRequest) slowProtoReflect() protoreflect.Message { - mi := &file_testpb_query_proto_msgTypes[1] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -var _fastReflection_EchoRequest_messageType fastReflection_EchoRequest_messageType -var _ protoreflect.MessageType = fastReflection_EchoRequest_messageType{} - -type fastReflection_EchoRequest_messageType struct{} - -func (x fastReflection_EchoRequest_messageType) Zero() protoreflect.Message { - return (*fastReflection_EchoRequest)(nil) -} -func (x fastReflection_EchoRequest_messageType) New() protoreflect.Message { - return new(fastReflection_EchoRequest) -} -func (x fastReflection_EchoRequest_messageType) Descriptor() protoreflect.MessageDescriptor { - return md_EchoRequest -} - -// Descriptor returns message descriptor, which contains only the protobuf -// type information for the message. -func (x *fastReflection_EchoRequest) Descriptor() protoreflect.MessageDescriptor { - return md_EchoRequest -} - -// Type returns the message type, which encapsulates both Go and protobuf -// type information. If the Go type information is not needed, -// it is recommended that the message descriptor be used instead. -func (x *fastReflection_EchoRequest) Type() protoreflect.MessageType { - return _fastReflection_EchoRequest_messageType -} - -// New returns a newly allocated and mutable empty message. -func (x *fastReflection_EchoRequest) New() protoreflect.Message { - return new(fastReflection_EchoRequest) -} - -// Interface unwraps the message reflection interface and -// returns the underlying ProtoMessage interface. -func (x *fastReflection_EchoRequest) Interface() protoreflect.ProtoMessage { - return (*EchoRequest)(x) -} - -// Range iterates over every populated field in an undefined order, -// calling f for each field descriptor and value encountered. -// Range returns immediately if f returns false. -// While iterating, mutating operations may only be performed -// on the current field descriptor. -func (x *fastReflection_EchoRequest) Range(f func(protoreflect.FieldDescriptor, protoreflect.Value) bool) { - if x.U32 != uint32(0) { - value := protoreflect.ValueOfUint32(x.U32) - if !f(fd_EchoRequest_u32, value) { - return - } - } - if x.U64 != uint64(0) { - value := protoreflect.ValueOfUint64(x.U64) - if !f(fd_EchoRequest_u64, value) { - return - } - } - if x.Str != "" { - value := protoreflect.ValueOfString(x.Str) - if !f(fd_EchoRequest_str, value) { - return - } - } - if len(x.Bz) != 0 { - value := protoreflect.ValueOfBytes(x.Bz) - if !f(fd_EchoRequest_bz, value) { - return - } - } - if x.Timestamp != nil { - value := protoreflect.ValueOfMessage(x.Timestamp.ProtoReflect()) - if !f(fd_EchoRequest_timestamp, value) { - return - } - } - if x.Duration != nil { - value := protoreflect.ValueOfMessage(x.Duration.ProtoReflect()) - if !f(fd_EchoRequest_duration, value) { - return - } - } - if x.I32 != int32(0) { - value := protoreflect.ValueOfInt32(x.I32) - if !f(fd_EchoRequest_i32, value) { - return - } - } - if x.I64 != int64(0) { - value := protoreflect.ValueOfInt64(x.I64) - if !f(fd_EchoRequest_i64, value) { - return - } - } - if x.ABool != false { - value := protoreflect.ValueOfBool(x.ABool) - if !f(fd_EchoRequest_a_bool, value) { - return - } - } - if x.AnEnum != 0 { - value := protoreflect.ValueOfEnum((protoreflect.EnumNumber)(x.AnEnum)) - if !f(fd_EchoRequest_an_enum, value) { - return - } - } - if x.AMessage != nil { - value := protoreflect.ValueOfMessage(x.AMessage.ProtoReflect()) - if !f(fd_EchoRequest_a_message, value) { - return - } - } - if x.ACoin != nil { - value := protoreflect.ValueOfMessage(x.ACoin.ProtoReflect()) - if !f(fd_EchoRequest_a_coin, value) { - return - } - } - if x.AnAddress != "" { - value := protoreflect.ValueOfString(x.AnAddress) - if !f(fd_EchoRequest_an_address, value) { - return - } - } - if x.Page != nil { - value := protoreflect.ValueOfMessage(x.Page.ProtoReflect()) - if !f(fd_EchoRequest_page, value) { - return - } - } - if len(x.Bools) != 0 { - value := protoreflect.ValueOfList(&_EchoRequest_21_list{list: &x.Bools}) - if !f(fd_EchoRequest_bools, value) { - return - } - } - if len(x.Uints) != 0 { - value := protoreflect.ValueOfList(&_EchoRequest_22_list{list: &x.Uints}) - if !f(fd_EchoRequest_uints, value) { - return - } - } - if len(x.Strings) != 0 { - value := protoreflect.ValueOfList(&_EchoRequest_23_list{list: &x.Strings}) - if !f(fd_EchoRequest_strings, value) { - return - } - } - if len(x.Enums) != 0 { - value := protoreflect.ValueOfList(&_EchoRequest_24_list{list: &x.Enums}) - if !f(fd_EchoRequest_enums, value) { - return - } - } - if len(x.Durations) != 0 { - value := protoreflect.ValueOfList(&_EchoRequest_25_list{list: &x.Durations}) - if !f(fd_EchoRequest_durations, value) { - return - } - } - if len(x.SomeMessages) != 0 { - value := protoreflect.ValueOfList(&_EchoRequest_26_list{list: &x.SomeMessages}) - if !f(fd_EchoRequest_some_messages, value) { - return - } - } - if x.Positional1 != int32(0) { - value := protoreflect.ValueOfInt32(x.Positional1) - if !f(fd_EchoRequest_positional1, value) { - return - } - } - if x.Positional2 != "" { - value := protoreflect.ValueOfString(x.Positional2) - if !f(fd_EchoRequest_positional2, value) { - return - } - } - if len(x.Positional3Varargs) != 0 { - value := protoreflect.ValueOfList(&_EchoRequest_29_list{list: &x.Positional3Varargs}) - if !f(fd_EchoRequest_positional3_varargs, value) { - return - } - } - if x.DeprecatedField != "" { - value := protoreflect.ValueOfString(x.DeprecatedField) - if !f(fd_EchoRequest_deprecated_field, value) { - return - } - } - if x.ShorthandDeprecatedField != "" { - value := protoreflect.ValueOfString(x.ShorthandDeprecatedField) - if !f(fd_EchoRequest_shorthand_deprecated_field, value) { - return - } - } - if x.HiddenBool != false { - value := protoreflect.ValueOfBool(x.HiddenBool) - if !f(fd_EchoRequest_hidden_bool, value) { - return - } - } - if len(x.MapStringString) != 0 { - value := protoreflect.ValueOfMap(&_EchoRequest_33_map{m: &x.MapStringString}) - if !f(fd_EchoRequest_map_string_string, value) { - return - } - } - if len(x.MapStringUint32) != 0 { - value := protoreflect.ValueOfMap(&_EchoRequest_34_map{m: &x.MapStringUint32}) - if !f(fd_EchoRequest_map_string_uint32, value) { - return - } - } - if len(x.MapStringCoin) != 0 { - value := protoreflect.ValueOfMap(&_EchoRequest_35_map{m: &x.MapStringCoin}) - if !f(fd_EchoRequest_map_string_coin, value) { - return - } - } - if x.AValidatorAddress != "" { - value := protoreflect.ValueOfString(x.AValidatorAddress) - if !f(fd_EchoRequest_a_validator_address, value) { - return - } - } - if x.AConsensusAddress != "" { - value := protoreflect.ValueOfString(x.AConsensusAddress) - if !f(fd_EchoRequest_a_consensus_address, value) { - return - } - } - if len(x.Coins) != 0 { - value := protoreflect.ValueOfList(&_EchoRequest_38_list{list: &x.Coins}) - if !f(fd_EchoRequest_coins, value) { - return - } - } -} - -// Has reports whether a field is populated. -// -// Some fields have the property of nullability where it is possible to -// distinguish between the default value of a field and whether the field -// was explicitly populated with the default value. Singular message fields, -// member fields of a oneof, and proto2 scalar fields are nullable. Such -// fields are populated only if explicitly set. -// -// In other cases (aside from the nullable cases above), -// a proto3 scalar field is populated if it contains a non-zero value, and -// a repeated field is populated if it is non-empty. -func (x *fastReflection_EchoRequest) Has(fd protoreflect.FieldDescriptor) bool { - switch fd.FullName() { - case "testpb.EchoRequest.u32": - return x.U32 != uint32(0) - case "testpb.EchoRequest.u64": - return x.U64 != uint64(0) - case "testpb.EchoRequest.str": - return x.Str != "" - case "testpb.EchoRequest.bz": - return len(x.Bz) != 0 - case "testpb.EchoRequest.timestamp": - return x.Timestamp != nil - case "testpb.EchoRequest.duration": - return x.Duration != nil - case "testpb.EchoRequest.i32": - return x.I32 != int32(0) - case "testpb.EchoRequest.i64": - return x.I64 != int64(0) - case "testpb.EchoRequest.a_bool": - return x.ABool != false - case "testpb.EchoRequest.an_enum": - return x.AnEnum != 0 - case "testpb.EchoRequest.a_message": - return x.AMessage != nil - case "testpb.EchoRequest.a_coin": - return x.ACoin != nil - case "testpb.EchoRequest.an_address": - return x.AnAddress != "" - case "testpb.EchoRequest.page": - return x.Page != nil - case "testpb.EchoRequest.bools": - return len(x.Bools) != 0 - case "testpb.EchoRequest.uints": - return len(x.Uints) != 0 - case "testpb.EchoRequest.strings": - return len(x.Strings) != 0 - case "testpb.EchoRequest.enums": - return len(x.Enums) != 0 - case "testpb.EchoRequest.durations": - return len(x.Durations) != 0 - case "testpb.EchoRequest.some_messages": - return len(x.SomeMessages) != 0 - case "testpb.EchoRequest.positional1": - return x.Positional1 != int32(0) - case "testpb.EchoRequest.positional2": - return x.Positional2 != "" - case "testpb.EchoRequest.positional3_varargs": - return len(x.Positional3Varargs) != 0 - case "testpb.EchoRequest.deprecated_field": - return x.DeprecatedField != "" - case "testpb.EchoRequest.shorthand_deprecated_field": - return x.ShorthandDeprecatedField != "" - case "testpb.EchoRequest.hidden_bool": - return x.HiddenBool != false - case "testpb.EchoRequest.map_string_string": - return len(x.MapStringString) != 0 - case "testpb.EchoRequest.map_string_uint32": - return len(x.MapStringUint32) != 0 - case "testpb.EchoRequest.map_string_coin": - return len(x.MapStringCoin) != 0 - case "testpb.EchoRequest.a_validator_address": - return x.AValidatorAddress != "" - case "testpb.EchoRequest.a_consensus_address": - return x.AConsensusAddress != "" - case "testpb.EchoRequest.coins": - return len(x.Coins) != 0 - default: - if fd.IsExtension() { - panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.EchoRequest")) - } - panic(fmt.Errorf("message testpb.EchoRequest does not contain field %s", fd.FullName())) - } -} - -// Clear clears the field such that a subsequent Has call reports false. -// -// Clearing an extension field clears both the extension type and value -// associated with the given field number. -// -// Clear is a mutating operation and unsafe for concurrent use. -func (x *fastReflection_EchoRequest) Clear(fd protoreflect.FieldDescriptor) { - switch fd.FullName() { - case "testpb.EchoRequest.u32": - x.U32 = uint32(0) - case "testpb.EchoRequest.u64": - x.U64 = uint64(0) - case "testpb.EchoRequest.str": - x.Str = "" - case "testpb.EchoRequest.bz": - x.Bz = nil - case "testpb.EchoRequest.timestamp": - x.Timestamp = nil - case "testpb.EchoRequest.duration": - x.Duration = nil - case "testpb.EchoRequest.i32": - x.I32 = int32(0) - case "testpb.EchoRequest.i64": - x.I64 = int64(0) - case "testpb.EchoRequest.a_bool": - x.ABool = false - case "testpb.EchoRequest.an_enum": - x.AnEnum = 0 - case "testpb.EchoRequest.a_message": - x.AMessage = nil - case "testpb.EchoRequest.a_coin": - x.ACoin = nil - case "testpb.EchoRequest.an_address": - x.AnAddress = "" - case "testpb.EchoRequest.page": - x.Page = nil - case "testpb.EchoRequest.bools": - x.Bools = nil - case "testpb.EchoRequest.uints": - x.Uints = nil - case "testpb.EchoRequest.strings": - x.Strings = nil - case "testpb.EchoRequest.enums": - x.Enums = nil - case "testpb.EchoRequest.durations": - x.Durations = nil - case "testpb.EchoRequest.some_messages": - x.SomeMessages = nil - case "testpb.EchoRequest.positional1": - x.Positional1 = int32(0) - case "testpb.EchoRequest.positional2": - x.Positional2 = "" - case "testpb.EchoRequest.positional3_varargs": - x.Positional3Varargs = nil - case "testpb.EchoRequest.deprecated_field": - x.DeprecatedField = "" - case "testpb.EchoRequest.shorthand_deprecated_field": - x.ShorthandDeprecatedField = "" - case "testpb.EchoRequest.hidden_bool": - x.HiddenBool = false - case "testpb.EchoRequest.map_string_string": - x.MapStringString = nil - case "testpb.EchoRequest.map_string_uint32": - x.MapStringUint32 = nil - case "testpb.EchoRequest.map_string_coin": - x.MapStringCoin = nil - case "testpb.EchoRequest.a_validator_address": - x.AValidatorAddress = "" - case "testpb.EchoRequest.a_consensus_address": - x.AConsensusAddress = "" - case "testpb.EchoRequest.coins": - x.Coins = nil - default: - if fd.IsExtension() { - panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.EchoRequest")) - } - panic(fmt.Errorf("message testpb.EchoRequest does not contain field %s", fd.FullName())) - } -} - -// Get retrieves the value for a field. -// -// For unpopulated scalars, it returns the default value, where -// the default value of a bytes scalar is guaranteed to be a copy. -// For unpopulated composite types, it returns an empty, read-only view -// of the value; to obtain a mutable reference, use Mutable. -func (x *fastReflection_EchoRequest) Get(descriptor protoreflect.FieldDescriptor) protoreflect.Value { - switch descriptor.FullName() { - case "testpb.EchoRequest.u32": - value := x.U32 - return protoreflect.ValueOfUint32(value) - case "testpb.EchoRequest.u64": - value := x.U64 - return protoreflect.ValueOfUint64(value) - case "testpb.EchoRequest.str": - value := x.Str - return protoreflect.ValueOfString(value) - case "testpb.EchoRequest.bz": - value := x.Bz - return protoreflect.ValueOfBytes(value) - case "testpb.EchoRequest.timestamp": - value := x.Timestamp - return protoreflect.ValueOfMessage(value.ProtoReflect()) - case "testpb.EchoRequest.duration": - value := x.Duration - return protoreflect.ValueOfMessage(value.ProtoReflect()) - case "testpb.EchoRequest.i32": - value := x.I32 - return protoreflect.ValueOfInt32(value) - case "testpb.EchoRequest.i64": - value := x.I64 - return protoreflect.ValueOfInt64(value) - case "testpb.EchoRequest.a_bool": - value := x.ABool - return protoreflect.ValueOfBool(value) - case "testpb.EchoRequest.an_enum": - value := x.AnEnum - return protoreflect.ValueOfEnum((protoreflect.EnumNumber)(value)) - case "testpb.EchoRequest.a_message": - value := x.AMessage - return protoreflect.ValueOfMessage(value.ProtoReflect()) - case "testpb.EchoRequest.a_coin": - value := x.ACoin - return protoreflect.ValueOfMessage(value.ProtoReflect()) - case "testpb.EchoRequest.an_address": - value := x.AnAddress - return protoreflect.ValueOfString(value) - case "testpb.EchoRequest.page": - value := x.Page - return protoreflect.ValueOfMessage(value.ProtoReflect()) - case "testpb.EchoRequest.bools": - if len(x.Bools) == 0 { - return protoreflect.ValueOfList(&_EchoRequest_21_list{}) - } - listValue := &_EchoRequest_21_list{list: &x.Bools} - return protoreflect.ValueOfList(listValue) - case "testpb.EchoRequest.uints": - if len(x.Uints) == 0 { - return protoreflect.ValueOfList(&_EchoRequest_22_list{}) - } - listValue := &_EchoRequest_22_list{list: &x.Uints} - return protoreflect.ValueOfList(listValue) - case "testpb.EchoRequest.strings": - if len(x.Strings) == 0 { - return protoreflect.ValueOfList(&_EchoRequest_23_list{}) - } - listValue := &_EchoRequest_23_list{list: &x.Strings} - return protoreflect.ValueOfList(listValue) - case "testpb.EchoRequest.enums": - if len(x.Enums) == 0 { - return protoreflect.ValueOfList(&_EchoRequest_24_list{}) - } - listValue := &_EchoRequest_24_list{list: &x.Enums} - return protoreflect.ValueOfList(listValue) - case "testpb.EchoRequest.durations": - if len(x.Durations) == 0 { - return protoreflect.ValueOfList(&_EchoRequest_25_list{}) - } - listValue := &_EchoRequest_25_list{list: &x.Durations} - return protoreflect.ValueOfList(listValue) - case "testpb.EchoRequest.some_messages": - if len(x.SomeMessages) == 0 { - return protoreflect.ValueOfList(&_EchoRequest_26_list{}) - } - listValue := &_EchoRequest_26_list{list: &x.SomeMessages} - return protoreflect.ValueOfList(listValue) - case "testpb.EchoRequest.positional1": - value := x.Positional1 - return protoreflect.ValueOfInt32(value) - case "testpb.EchoRequest.positional2": - value := x.Positional2 - return protoreflect.ValueOfString(value) - case "testpb.EchoRequest.positional3_varargs": - if len(x.Positional3Varargs) == 0 { - return protoreflect.ValueOfList(&_EchoRequest_29_list{}) - } - listValue := &_EchoRequest_29_list{list: &x.Positional3Varargs} - return protoreflect.ValueOfList(listValue) - case "testpb.EchoRequest.deprecated_field": - value := x.DeprecatedField - return protoreflect.ValueOfString(value) - case "testpb.EchoRequest.shorthand_deprecated_field": - value := x.ShorthandDeprecatedField - return protoreflect.ValueOfString(value) - case "testpb.EchoRequest.hidden_bool": - value := x.HiddenBool - return protoreflect.ValueOfBool(value) - case "testpb.EchoRequest.map_string_string": - if len(x.MapStringString) == 0 { - return protoreflect.ValueOfMap(&_EchoRequest_33_map{}) - } - mapValue := &_EchoRequest_33_map{m: &x.MapStringString} - return protoreflect.ValueOfMap(mapValue) - case "testpb.EchoRequest.map_string_uint32": - if len(x.MapStringUint32) == 0 { - return protoreflect.ValueOfMap(&_EchoRequest_34_map{}) - } - mapValue := &_EchoRequest_34_map{m: &x.MapStringUint32} - return protoreflect.ValueOfMap(mapValue) - case "testpb.EchoRequest.map_string_coin": - if len(x.MapStringCoin) == 0 { - return protoreflect.ValueOfMap(&_EchoRequest_35_map{}) - } - mapValue := &_EchoRequest_35_map{m: &x.MapStringCoin} - return protoreflect.ValueOfMap(mapValue) - case "testpb.EchoRequest.a_validator_address": - value := x.AValidatorAddress - return protoreflect.ValueOfString(value) - case "testpb.EchoRequest.a_consensus_address": - value := x.AConsensusAddress - return protoreflect.ValueOfString(value) - case "testpb.EchoRequest.coins": - if len(x.Coins) == 0 { - return protoreflect.ValueOfList(&_EchoRequest_38_list{}) - } - listValue := &_EchoRequest_38_list{list: &x.Coins} - return protoreflect.ValueOfList(listValue) - default: - if descriptor.IsExtension() { - panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.EchoRequest")) - } - panic(fmt.Errorf("message testpb.EchoRequest does not contain field %s", descriptor.FullName())) - } -} - -// Set stores the value for a field. -// -// For a field belonging to a oneof, it implicitly clears any other field -// that may be currently set within the same oneof. -// For extension fields, it implicitly stores the provided ExtensionType. -// When setting a composite type, it is unspecified whether the stored value -// aliases the source's memory in any way. If the composite value is an -// empty, read-only value, then it panics. -// -// Set is a mutating operation and unsafe for concurrent use. -func (x *fastReflection_EchoRequest) Set(fd protoreflect.FieldDescriptor, value protoreflect.Value) { - switch fd.FullName() { - case "testpb.EchoRequest.u32": - x.U32 = uint32(value.Uint()) - case "testpb.EchoRequest.u64": - x.U64 = value.Uint() - case "testpb.EchoRequest.str": - x.Str = value.Interface().(string) - case "testpb.EchoRequest.bz": - x.Bz = value.Bytes() - case "testpb.EchoRequest.timestamp": - x.Timestamp = value.Message().Interface().(*timestamppb.Timestamp) - case "testpb.EchoRequest.duration": - x.Duration = value.Message().Interface().(*durationpb.Duration) - case "testpb.EchoRequest.i32": - x.I32 = int32(value.Int()) - case "testpb.EchoRequest.i64": - x.I64 = value.Int() - case "testpb.EchoRequest.a_bool": - x.ABool = value.Bool() - case "testpb.EchoRequest.an_enum": - x.AnEnum = (Enum)(value.Enum()) - case "testpb.EchoRequest.a_message": - x.AMessage = value.Message().Interface().(*AMessage) - case "testpb.EchoRequest.a_coin": - x.ACoin = value.Message().Interface().(*v1beta1.Coin) - case "testpb.EchoRequest.an_address": - x.AnAddress = value.Interface().(string) - case "testpb.EchoRequest.page": - x.Page = value.Message().Interface().(*v1beta11.PageRequest) - case "testpb.EchoRequest.bools": - lv := value.List() - clv := lv.(*_EchoRequest_21_list) - x.Bools = *clv.list - case "testpb.EchoRequest.uints": - lv := value.List() - clv := lv.(*_EchoRequest_22_list) - x.Uints = *clv.list - case "testpb.EchoRequest.strings": - lv := value.List() - clv := lv.(*_EchoRequest_23_list) - x.Strings = *clv.list - case "testpb.EchoRequest.enums": - lv := value.List() - clv := lv.(*_EchoRequest_24_list) - x.Enums = *clv.list - case "testpb.EchoRequest.durations": - lv := value.List() - clv := lv.(*_EchoRequest_25_list) - x.Durations = *clv.list - case "testpb.EchoRequest.some_messages": - lv := value.List() - clv := lv.(*_EchoRequest_26_list) - x.SomeMessages = *clv.list - case "testpb.EchoRequest.positional1": - x.Positional1 = int32(value.Int()) - case "testpb.EchoRequest.positional2": - x.Positional2 = value.Interface().(string) - case "testpb.EchoRequest.positional3_varargs": - lv := value.List() - clv := lv.(*_EchoRequest_29_list) - x.Positional3Varargs = *clv.list - case "testpb.EchoRequest.deprecated_field": - x.DeprecatedField = value.Interface().(string) - case "testpb.EchoRequest.shorthand_deprecated_field": - x.ShorthandDeprecatedField = value.Interface().(string) - case "testpb.EchoRequest.hidden_bool": - x.HiddenBool = value.Bool() - case "testpb.EchoRequest.map_string_string": - mv := value.Map() - cmv := mv.(*_EchoRequest_33_map) - x.MapStringString = *cmv.m - case "testpb.EchoRequest.map_string_uint32": - mv := value.Map() - cmv := mv.(*_EchoRequest_34_map) - x.MapStringUint32 = *cmv.m - case "testpb.EchoRequest.map_string_coin": - mv := value.Map() - cmv := mv.(*_EchoRequest_35_map) - x.MapStringCoin = *cmv.m - case "testpb.EchoRequest.a_validator_address": - x.AValidatorAddress = value.Interface().(string) - case "testpb.EchoRequest.a_consensus_address": - x.AConsensusAddress = value.Interface().(string) - case "testpb.EchoRequest.coins": - lv := value.List() - clv := lv.(*_EchoRequest_38_list) - x.Coins = *clv.list - default: - if fd.IsExtension() { - panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.EchoRequest")) - } - panic(fmt.Errorf("message testpb.EchoRequest does not contain field %s", fd.FullName())) - } -} - -// Mutable returns a mutable reference to a composite type. -// -// If the field is unpopulated, it may allocate a composite value. -// For a field belonging to a oneof, it implicitly clears any other field -// that may be currently set within the same oneof. -// For extension fields, it implicitly stores the provided ExtensionType -// if not already stored. -// It panics if the field does not contain a composite type. -// -// Mutable is a mutating operation and unsafe for concurrent use. -func (x *fastReflection_EchoRequest) Mutable(fd protoreflect.FieldDescriptor) protoreflect.Value { - switch fd.FullName() { - case "testpb.EchoRequest.timestamp": - if x.Timestamp == nil { - x.Timestamp = new(timestamppb.Timestamp) - } - return protoreflect.ValueOfMessage(x.Timestamp.ProtoReflect()) - case "testpb.EchoRequest.duration": - if x.Duration == nil { - x.Duration = new(durationpb.Duration) - } - return protoreflect.ValueOfMessage(x.Duration.ProtoReflect()) - case "testpb.EchoRequest.a_message": - if x.AMessage == nil { - x.AMessage = new(AMessage) - } - return protoreflect.ValueOfMessage(x.AMessage.ProtoReflect()) - case "testpb.EchoRequest.a_coin": - if x.ACoin == nil { - x.ACoin = new(v1beta1.Coin) - } - return protoreflect.ValueOfMessage(x.ACoin.ProtoReflect()) - case "testpb.EchoRequest.page": - if x.Page == nil { - x.Page = new(v1beta11.PageRequest) - } - return protoreflect.ValueOfMessage(x.Page.ProtoReflect()) - case "testpb.EchoRequest.bools": - if x.Bools == nil { - x.Bools = []bool{} - } - value := &_EchoRequest_21_list{list: &x.Bools} - return protoreflect.ValueOfList(value) - case "testpb.EchoRequest.uints": - if x.Uints == nil { - x.Uints = []uint32{} - } - value := &_EchoRequest_22_list{list: &x.Uints} - return protoreflect.ValueOfList(value) - case "testpb.EchoRequest.strings": - if x.Strings == nil { - x.Strings = []string{} - } - value := &_EchoRequest_23_list{list: &x.Strings} - return protoreflect.ValueOfList(value) - case "testpb.EchoRequest.enums": - if x.Enums == nil { - x.Enums = []Enum{} - } - value := &_EchoRequest_24_list{list: &x.Enums} - return protoreflect.ValueOfList(value) - case "testpb.EchoRequest.durations": - if x.Durations == nil { - x.Durations = []*durationpb.Duration{} - } - value := &_EchoRequest_25_list{list: &x.Durations} - return protoreflect.ValueOfList(value) - case "testpb.EchoRequest.some_messages": - if x.SomeMessages == nil { - x.SomeMessages = []*AMessage{} - } - value := &_EchoRequest_26_list{list: &x.SomeMessages} - return protoreflect.ValueOfList(value) - case "testpb.EchoRequest.positional3_varargs": - if x.Positional3Varargs == nil { - x.Positional3Varargs = []*v1beta1.Coin{} - } - value := &_EchoRequest_29_list{list: &x.Positional3Varargs} - return protoreflect.ValueOfList(value) - case "testpb.EchoRequest.map_string_string": - if x.MapStringString == nil { - x.MapStringString = make(map[string]string) - } - value := &_EchoRequest_33_map{m: &x.MapStringString} - return protoreflect.ValueOfMap(value) - case "testpb.EchoRequest.map_string_uint32": - if x.MapStringUint32 == nil { - x.MapStringUint32 = make(map[string]uint32) - } - value := &_EchoRequest_34_map{m: &x.MapStringUint32} - return protoreflect.ValueOfMap(value) - case "testpb.EchoRequest.map_string_coin": - if x.MapStringCoin == nil { - x.MapStringCoin = make(map[string]*v1beta1.Coin) - } - value := &_EchoRequest_35_map{m: &x.MapStringCoin} - return protoreflect.ValueOfMap(value) - case "testpb.EchoRequest.coins": - if x.Coins == nil { - x.Coins = []*v1beta1.Coin{} - } - value := &_EchoRequest_38_list{list: &x.Coins} - return protoreflect.ValueOfList(value) - case "testpb.EchoRequest.u32": - panic(fmt.Errorf("field u32 of message testpb.EchoRequest is not mutable")) - case "testpb.EchoRequest.u64": - panic(fmt.Errorf("field u64 of message testpb.EchoRequest is not mutable")) - case "testpb.EchoRequest.str": - panic(fmt.Errorf("field str of message testpb.EchoRequest is not mutable")) - case "testpb.EchoRequest.bz": - panic(fmt.Errorf("field bz of message testpb.EchoRequest is not mutable")) - case "testpb.EchoRequest.i32": - panic(fmt.Errorf("field i32 of message testpb.EchoRequest is not mutable")) - case "testpb.EchoRequest.i64": - panic(fmt.Errorf("field i64 of message testpb.EchoRequest is not mutable")) - case "testpb.EchoRequest.a_bool": - panic(fmt.Errorf("field a_bool of message testpb.EchoRequest is not mutable")) - case "testpb.EchoRequest.an_enum": - panic(fmt.Errorf("field an_enum of message testpb.EchoRequest is not mutable")) - case "testpb.EchoRequest.an_address": - panic(fmt.Errorf("field an_address of message testpb.EchoRequest is not mutable")) - case "testpb.EchoRequest.positional1": - panic(fmt.Errorf("field positional1 of message testpb.EchoRequest is not mutable")) - case "testpb.EchoRequest.positional2": - panic(fmt.Errorf("field positional2 of message testpb.EchoRequest is not mutable")) - case "testpb.EchoRequest.deprecated_field": - panic(fmt.Errorf("field deprecated_field of message testpb.EchoRequest is not mutable")) - case "testpb.EchoRequest.shorthand_deprecated_field": - panic(fmt.Errorf("field shorthand_deprecated_field of message testpb.EchoRequest is not mutable")) - case "testpb.EchoRequest.hidden_bool": - panic(fmt.Errorf("field hidden_bool of message testpb.EchoRequest is not mutable")) - case "testpb.EchoRequest.a_validator_address": - panic(fmt.Errorf("field a_validator_address of message testpb.EchoRequest is not mutable")) - case "testpb.EchoRequest.a_consensus_address": - panic(fmt.Errorf("field a_consensus_address of message testpb.EchoRequest is not mutable")) - default: - if fd.IsExtension() { - panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.EchoRequest")) - } - panic(fmt.Errorf("message testpb.EchoRequest does not contain field %s", fd.FullName())) - } -} - -// NewField returns a new value that is assignable to the field -// for the given descriptor. For scalars, this returns the default value. -// For lists, maps, and messages, this returns a new, empty, mutable value. -func (x *fastReflection_EchoRequest) NewField(fd protoreflect.FieldDescriptor) protoreflect.Value { - switch fd.FullName() { - case "testpb.EchoRequest.u32": - return protoreflect.ValueOfUint32(uint32(0)) - case "testpb.EchoRequest.u64": - return protoreflect.ValueOfUint64(uint64(0)) - case "testpb.EchoRequest.str": - return protoreflect.ValueOfString("") - case "testpb.EchoRequest.bz": - return protoreflect.ValueOfBytes(nil) - case "testpb.EchoRequest.timestamp": - m := new(timestamppb.Timestamp) - return protoreflect.ValueOfMessage(m.ProtoReflect()) - case "testpb.EchoRequest.duration": - m := new(durationpb.Duration) - return protoreflect.ValueOfMessage(m.ProtoReflect()) - case "testpb.EchoRequest.i32": - return protoreflect.ValueOfInt32(int32(0)) - case "testpb.EchoRequest.i64": - return protoreflect.ValueOfInt64(int64(0)) - case "testpb.EchoRequest.a_bool": - return protoreflect.ValueOfBool(false) - case "testpb.EchoRequest.an_enum": - return protoreflect.ValueOfEnum(0) - case "testpb.EchoRequest.a_message": - m := new(AMessage) - return protoreflect.ValueOfMessage(m.ProtoReflect()) - case "testpb.EchoRequest.a_coin": - m := new(v1beta1.Coin) - return protoreflect.ValueOfMessage(m.ProtoReflect()) - case "testpb.EchoRequest.an_address": - return protoreflect.ValueOfString("") - case "testpb.EchoRequest.page": - m := new(v1beta11.PageRequest) - return protoreflect.ValueOfMessage(m.ProtoReflect()) - case "testpb.EchoRequest.bools": - list := []bool{} - return protoreflect.ValueOfList(&_EchoRequest_21_list{list: &list}) - case "testpb.EchoRequest.uints": - list := []uint32{} - return protoreflect.ValueOfList(&_EchoRequest_22_list{list: &list}) - case "testpb.EchoRequest.strings": - list := []string{} - return protoreflect.ValueOfList(&_EchoRequest_23_list{list: &list}) - case "testpb.EchoRequest.enums": - list := []Enum{} - return protoreflect.ValueOfList(&_EchoRequest_24_list{list: &list}) - case "testpb.EchoRequest.durations": - list := []*durationpb.Duration{} - return protoreflect.ValueOfList(&_EchoRequest_25_list{list: &list}) - case "testpb.EchoRequest.some_messages": - list := []*AMessage{} - return protoreflect.ValueOfList(&_EchoRequest_26_list{list: &list}) - case "testpb.EchoRequest.positional1": - return protoreflect.ValueOfInt32(int32(0)) - case "testpb.EchoRequest.positional2": - return protoreflect.ValueOfString("") - case "testpb.EchoRequest.positional3_varargs": - list := []*v1beta1.Coin{} - return protoreflect.ValueOfList(&_EchoRequest_29_list{list: &list}) - case "testpb.EchoRequest.deprecated_field": - return protoreflect.ValueOfString("") - case "testpb.EchoRequest.shorthand_deprecated_field": - return protoreflect.ValueOfString("") - case "testpb.EchoRequest.hidden_bool": - return protoreflect.ValueOfBool(false) - case "testpb.EchoRequest.map_string_string": - m := make(map[string]string) - return protoreflect.ValueOfMap(&_EchoRequest_33_map{m: &m}) - case "testpb.EchoRequest.map_string_uint32": - m := make(map[string]uint32) - return protoreflect.ValueOfMap(&_EchoRequest_34_map{m: &m}) - case "testpb.EchoRequest.map_string_coin": - m := make(map[string]*v1beta1.Coin) - return protoreflect.ValueOfMap(&_EchoRequest_35_map{m: &m}) - case "testpb.EchoRequest.a_validator_address": - return protoreflect.ValueOfString("") - case "testpb.EchoRequest.a_consensus_address": - return protoreflect.ValueOfString("") - case "testpb.EchoRequest.coins": - list := []*v1beta1.Coin{} - return protoreflect.ValueOfList(&_EchoRequest_38_list{list: &list}) - default: - if fd.IsExtension() { - panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.EchoRequest")) - } - panic(fmt.Errorf("message testpb.EchoRequest does not contain field %s", fd.FullName())) - } -} - -// WhichOneof reports which field within the oneof is populated, -// returning nil if none are populated. -// It panics if the oneof descriptor does not belong to this message. -func (x *fastReflection_EchoRequest) WhichOneof(d protoreflect.OneofDescriptor) protoreflect.FieldDescriptor { - switch d.FullName() { - default: - panic(fmt.Errorf("%s is not a oneof field in testpb.EchoRequest", d.FullName())) - } - panic("unreachable") -} - -// GetUnknown retrieves the entire list of unknown fields. -// The caller may only mutate the contents of the RawFields -// if the mutated bytes are stored back into the message with SetUnknown. -func (x *fastReflection_EchoRequest) GetUnknown() protoreflect.RawFields { - return x.unknownFields -} - -// SetUnknown stores an entire list of unknown fields. -// The raw fields must be syntactically valid according to the wire format. -// An implementation may panic if this is not the case. -// Once stored, the caller must not mutate the content of the RawFields. -// An empty RawFields may be passed to clear the fields. -// -// SetUnknown is a mutating operation and unsafe for concurrent use. -func (x *fastReflection_EchoRequest) SetUnknown(fields protoreflect.RawFields) { - x.unknownFields = fields -} - -// IsValid reports whether the message is valid. -// -// An invalid message is an empty, read-only value. -// -// An invalid message often corresponds to a nil pointer of the concrete -// message type, but the details are implementation dependent. -// Validity is not part of the protobuf data model, and may not -// be preserved in marshaling or other operations. -func (x *fastReflection_EchoRequest) IsValid() bool { - return x != nil -} - -// ProtoMethods returns optional fastReflectionFeature-path implementations of various operations. -// This method may return nil. -// -// The returned methods type is identical to -// "google.golang.org/protobuf/runtime/protoiface".Methods. -// Consult the protoiface package documentation for details. -func (x *fastReflection_EchoRequest) ProtoMethods() *protoiface.Methods { - size := func(input protoiface.SizeInput) protoiface.SizeOutput { - x := input.Message.Interface().(*EchoRequest) - if x == nil { - return protoiface.SizeOutput{ - NoUnkeyedLiterals: input.NoUnkeyedLiterals, - Size: 0, - } - } - options := runtime.SizeInputToOptions(input) - _ = options - var n int - var l int - _ = l - if x.U32 != 0 { - n += 1 + runtime.Sov(uint64(x.U32)) - } - if x.U64 != 0 { - n += 1 + runtime.Sov(uint64(x.U64)) - } - l = len(x.Str) - if l > 0 { - n += 1 + l + runtime.Sov(uint64(l)) - } - l = len(x.Bz) - if l > 0 { - n += 1 + l + runtime.Sov(uint64(l)) - } - if x.Timestamp != nil { - l = options.Size(x.Timestamp) - n += 1 + l + runtime.Sov(uint64(l)) - } - if x.Duration != nil { - l = options.Size(x.Duration) - n += 1 + l + runtime.Sov(uint64(l)) - } - if x.I32 != 0 { - n += 1 + runtime.Sov(uint64(x.I32)) - } - if x.I64 != 0 { - n += 1 + runtime.Sov(uint64(x.I64)) - } - if x.ABool { - n += 2 - } - if x.AnEnum != 0 { - n += 2 + runtime.Sov(uint64(x.AnEnum)) - } - if x.AMessage != nil { - l = options.Size(x.AMessage) - n += 2 + l + runtime.Sov(uint64(l)) - } - if x.ACoin != nil { - l = options.Size(x.ACoin) - n += 2 + l + runtime.Sov(uint64(l)) - } - l = len(x.AnAddress) - if l > 0 { - n += 2 + l + runtime.Sov(uint64(l)) - } - if x.Page != nil { - l = options.Size(x.Page) - n += 2 + l + runtime.Sov(uint64(l)) - } - if len(x.Bools) > 0 { - n += 2 + runtime.Sov(uint64(len(x.Bools))) + len(x.Bools)*1 - } - if len(x.Uints) > 0 { - l = 0 - for _, e := range x.Uints { - l += runtime.Sov(uint64(e)) - } - n += 2 + runtime.Sov(uint64(l)) + l - } - if len(x.Strings) > 0 { - for _, s := range x.Strings { - l = len(s) - n += 2 + l + runtime.Sov(uint64(l)) - } - } - if len(x.Enums) > 0 { - l = 0 - for _, e := range x.Enums { - l += runtime.Sov(uint64(e)) - } - n += 2 + runtime.Sov(uint64(l)) + l - } - if len(x.Durations) > 0 { - for _, e := range x.Durations { - l = options.Size(e) - n += 2 + l + runtime.Sov(uint64(l)) - } - } - if len(x.SomeMessages) > 0 { - for _, e := range x.SomeMessages { - l = options.Size(e) - n += 2 + l + runtime.Sov(uint64(l)) - } - } - if x.Positional1 != 0 { - n += 2 + runtime.Sov(uint64(x.Positional1)) - } - l = len(x.Positional2) - if l > 0 { - n += 2 + l + runtime.Sov(uint64(l)) - } - if len(x.Positional3Varargs) > 0 { - for _, e := range x.Positional3Varargs { - l = options.Size(e) - n += 2 + l + runtime.Sov(uint64(l)) - } - } - l = len(x.DeprecatedField) - if l > 0 { - n += 2 + l + runtime.Sov(uint64(l)) - } - l = len(x.ShorthandDeprecatedField) - if l > 0 { - n += 2 + l + runtime.Sov(uint64(l)) - } - if x.HiddenBool { - n += 3 - } - if len(x.MapStringString) > 0 { - SiZeMaP := func(k string, v string) { - mapEntrySize := 1 + len(k) + runtime.Sov(uint64(len(k))) + 1 + len(v) + runtime.Sov(uint64(len(v))) - n += mapEntrySize + 2 + runtime.Sov(uint64(mapEntrySize)) - } - if options.Deterministic { - sortme := make([]string, 0, len(x.MapStringString)) - for k := range x.MapStringString { - sortme = append(sortme, k) - } - sort.Strings(sortme) - for _, k := range sortme { - v := x.MapStringString[k] - SiZeMaP(k, v) - } - } else { - for k, v := range x.MapStringString { - SiZeMaP(k, v) - } - } - } - if len(x.MapStringUint32) > 0 { - SiZeMaP := func(k string, v uint32) { - mapEntrySize := 1 + len(k) + runtime.Sov(uint64(len(k))) + 1 + runtime.Sov(uint64(v)) - n += mapEntrySize + 2 + runtime.Sov(uint64(mapEntrySize)) - } - if options.Deterministic { - sortme := make([]string, 0, len(x.MapStringUint32)) - for k := range x.MapStringUint32 { - sortme = append(sortme, k) - } - sort.Strings(sortme) - for _, k := range sortme { - v := x.MapStringUint32[k] - SiZeMaP(k, v) - } - } else { - for k, v := range x.MapStringUint32 { - SiZeMaP(k, v) - } - } - } - if len(x.MapStringCoin) > 0 { - SiZeMaP := func(k string, v *v1beta1.Coin) { - l := 0 - if v != nil { - l = options.Size(v) - } - l += 1 + runtime.Sov(uint64(l)) - mapEntrySize := 1 + len(k) + runtime.Sov(uint64(len(k))) + l - n += mapEntrySize + 2 + runtime.Sov(uint64(mapEntrySize)) - } - if options.Deterministic { - sortme := make([]string, 0, len(x.MapStringCoin)) - for k := range x.MapStringCoin { - sortme = append(sortme, k) - } - sort.Strings(sortme) - for _, k := range sortme { - v := x.MapStringCoin[k] - SiZeMaP(k, v) - } - } else { - for k, v := range x.MapStringCoin { - SiZeMaP(k, v) - } - } - } - l = len(x.AValidatorAddress) - if l > 0 { - n += 2 + l + runtime.Sov(uint64(l)) - } - l = len(x.AConsensusAddress) - if l > 0 { - n += 2 + l + runtime.Sov(uint64(l)) - } - if len(x.Coins) > 0 { - for _, e := range x.Coins { - l = options.Size(e) - n += 2 + l + runtime.Sov(uint64(l)) - } - } - if x.unknownFields != nil { - n += len(x.unknownFields) - } - return protoiface.SizeOutput{ - NoUnkeyedLiterals: input.NoUnkeyedLiterals, - Size: n, - } - } - - marshal := func(input protoiface.MarshalInput) (protoiface.MarshalOutput, error) { - x := input.Message.Interface().(*EchoRequest) - if x == nil { - return protoiface.MarshalOutput{ - NoUnkeyedLiterals: input.NoUnkeyedLiterals, - Buf: input.Buf, - }, nil - } - options := runtime.MarshalInputToOptions(input) - _ = options - size := options.Size(x) - dAtA := make([]byte, size) - i := len(dAtA) - _ = i - var l int - _ = l - if x.unknownFields != nil { - i -= len(x.unknownFields) - copy(dAtA[i:], x.unknownFields) - } - if len(x.Coins) > 0 { - for iNdEx := len(x.Coins) - 1; iNdEx >= 0; iNdEx-- { - encoded, err := options.Marshal(x.Coins[iNdEx]) - if err != nil { - return protoiface.MarshalOutput{ - NoUnkeyedLiterals: input.NoUnkeyedLiterals, - Buf: input.Buf, - }, err - } - i -= len(encoded) - copy(dAtA[i:], encoded) - i = runtime.EncodeVarint(dAtA, i, uint64(len(encoded))) - i-- - dAtA[i] = 0x2 - i-- - dAtA[i] = 0xb2 - } - } - if len(x.AConsensusAddress) > 0 { - i -= len(x.AConsensusAddress) - copy(dAtA[i:], x.AConsensusAddress) - i = runtime.EncodeVarint(dAtA, i, uint64(len(x.AConsensusAddress))) - i-- - dAtA[i] = 0x2 - i-- - dAtA[i] = 0xaa - } - if len(x.AValidatorAddress) > 0 { - i -= len(x.AValidatorAddress) - copy(dAtA[i:], x.AValidatorAddress) - i = runtime.EncodeVarint(dAtA, i, uint64(len(x.AValidatorAddress))) - i-- - dAtA[i] = 0x2 - i-- - dAtA[i] = 0xa2 - } - if len(x.MapStringCoin) > 0 { - MaRsHaLmAp := func(k string, v *v1beta1.Coin) (protoiface.MarshalOutput, error) { - baseI := i - encoded, err := options.Marshal(v) - if err != nil { - return protoiface.MarshalOutput{ - NoUnkeyedLiterals: input.NoUnkeyedLiterals, - Buf: input.Buf, - }, err - } - i -= len(encoded) - copy(dAtA[i:], encoded) - i = runtime.EncodeVarint(dAtA, i, uint64(len(encoded))) - i-- - dAtA[i] = 0x12 - i -= len(k) - copy(dAtA[i:], k) - i = runtime.EncodeVarint(dAtA, i, uint64(len(k))) - i-- - dAtA[i] = 0xa - i = runtime.EncodeVarint(dAtA, i, uint64(baseI-i)) - i-- - dAtA[i] = 0x2 - i-- - dAtA[i] = 0x9a - return protoiface.MarshalOutput{}, nil - } - if options.Deterministic { - keysForMapStringCoin := make([]string, 0, len(x.MapStringCoin)) - for k := range x.MapStringCoin { - keysForMapStringCoin = append(keysForMapStringCoin, string(k)) - } - sort.Slice(keysForMapStringCoin, func(i, j int) bool { - return keysForMapStringCoin[i] < keysForMapStringCoin[j] - }) - for iNdEx := len(keysForMapStringCoin) - 1; iNdEx >= 0; iNdEx-- { - v := x.MapStringCoin[string(keysForMapStringCoin[iNdEx])] - out, err := MaRsHaLmAp(keysForMapStringCoin[iNdEx], v) - if err != nil { - return out, err - } - } - } else { - for k := range x.MapStringCoin { - v := x.MapStringCoin[k] - out, err := MaRsHaLmAp(k, v) - if err != nil { - return out, err - } - } - } - } - if len(x.MapStringUint32) > 0 { - MaRsHaLmAp := func(k string, v uint32) (protoiface.MarshalOutput, error) { - baseI := i - i = runtime.EncodeVarint(dAtA, i, uint64(v)) - i-- - dAtA[i] = 0x10 - i -= len(k) - copy(dAtA[i:], k) - i = runtime.EncodeVarint(dAtA, i, uint64(len(k))) - i-- - dAtA[i] = 0xa - i = runtime.EncodeVarint(dAtA, i, uint64(baseI-i)) - i-- - dAtA[i] = 0x2 - i-- - dAtA[i] = 0x92 - return protoiface.MarshalOutput{}, nil - } - if options.Deterministic { - keysForMapStringUint32 := make([]string, 0, len(x.MapStringUint32)) - for k := range x.MapStringUint32 { - keysForMapStringUint32 = append(keysForMapStringUint32, string(k)) - } - sort.Slice(keysForMapStringUint32, func(i, j int) bool { - return keysForMapStringUint32[i] < keysForMapStringUint32[j] - }) - for iNdEx := len(keysForMapStringUint32) - 1; iNdEx >= 0; iNdEx-- { - v := x.MapStringUint32[string(keysForMapStringUint32[iNdEx])] - out, err := MaRsHaLmAp(keysForMapStringUint32[iNdEx], v) - if err != nil { - return out, err - } - } - } else { - for k := range x.MapStringUint32 { - v := x.MapStringUint32[k] - out, err := MaRsHaLmAp(k, v) - if err != nil { - return out, err - } - } - } - } - if len(x.MapStringString) > 0 { - MaRsHaLmAp := func(k string, v string) (protoiface.MarshalOutput, error) { - baseI := i - i -= len(v) - copy(dAtA[i:], v) - i = runtime.EncodeVarint(dAtA, i, uint64(len(v))) - i-- - dAtA[i] = 0x12 - i -= len(k) - copy(dAtA[i:], k) - i = runtime.EncodeVarint(dAtA, i, uint64(len(k))) - i-- - dAtA[i] = 0xa - i = runtime.EncodeVarint(dAtA, i, uint64(baseI-i)) - i-- - dAtA[i] = 0x2 - i-- - dAtA[i] = 0x8a - return protoiface.MarshalOutput{}, nil - } - if options.Deterministic { - keysForMapStringString := make([]string, 0, len(x.MapStringString)) - for k := range x.MapStringString { - keysForMapStringString = append(keysForMapStringString, string(k)) - } - sort.Slice(keysForMapStringString, func(i, j int) bool { - return keysForMapStringString[i] < keysForMapStringString[j] - }) - for iNdEx := len(keysForMapStringString) - 1; iNdEx >= 0; iNdEx-- { - v := x.MapStringString[string(keysForMapStringString[iNdEx])] - out, err := MaRsHaLmAp(keysForMapStringString[iNdEx], v) - if err != nil { - return out, err - } - } - } else { - for k := range x.MapStringString { - v := x.MapStringString[k] - out, err := MaRsHaLmAp(k, v) - if err != nil { - return out, err - } - } - } - } - if x.HiddenBool { - i-- - if x.HiddenBool { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i-- - dAtA[i] = 0x2 - i-- - dAtA[i] = 0x80 - } - if len(x.ShorthandDeprecatedField) > 0 { - i -= len(x.ShorthandDeprecatedField) - copy(dAtA[i:], x.ShorthandDeprecatedField) - i = runtime.EncodeVarint(dAtA, i, uint64(len(x.ShorthandDeprecatedField))) - i-- - dAtA[i] = 0x1 - i-- - dAtA[i] = 0xfa - } - if len(x.DeprecatedField) > 0 { - i -= len(x.DeprecatedField) - copy(dAtA[i:], x.DeprecatedField) - i = runtime.EncodeVarint(dAtA, i, uint64(len(x.DeprecatedField))) - i-- - dAtA[i] = 0x1 - i-- - dAtA[i] = 0xf2 - } - if len(x.Positional3Varargs) > 0 { - for iNdEx := len(x.Positional3Varargs) - 1; iNdEx >= 0; iNdEx-- { - encoded, err := options.Marshal(x.Positional3Varargs[iNdEx]) - if err != nil { - return protoiface.MarshalOutput{ - NoUnkeyedLiterals: input.NoUnkeyedLiterals, - Buf: input.Buf, - }, err - } - i -= len(encoded) - copy(dAtA[i:], encoded) - i = runtime.EncodeVarint(dAtA, i, uint64(len(encoded))) - i-- - dAtA[i] = 0x1 - i-- - dAtA[i] = 0xea - } - } - if len(x.Positional2) > 0 { - i -= len(x.Positional2) - copy(dAtA[i:], x.Positional2) - i = runtime.EncodeVarint(dAtA, i, uint64(len(x.Positional2))) - i-- - dAtA[i] = 0x1 - i-- - dAtA[i] = 0xe2 - } - if x.Positional1 != 0 { - i = runtime.EncodeVarint(dAtA, i, uint64(x.Positional1)) - i-- - dAtA[i] = 0x1 - i-- - dAtA[i] = 0xd8 - } - if len(x.SomeMessages) > 0 { - for iNdEx := len(x.SomeMessages) - 1; iNdEx >= 0; iNdEx-- { - encoded, err := options.Marshal(x.SomeMessages[iNdEx]) - if err != nil { - return protoiface.MarshalOutput{ - NoUnkeyedLiterals: input.NoUnkeyedLiterals, - Buf: input.Buf, - }, err - } - i -= len(encoded) - copy(dAtA[i:], encoded) - i = runtime.EncodeVarint(dAtA, i, uint64(len(encoded))) - i-- - dAtA[i] = 0x1 - i-- - dAtA[i] = 0xd2 - } - } - if len(x.Durations) > 0 { - for iNdEx := len(x.Durations) - 1; iNdEx >= 0; iNdEx-- { - encoded, err := options.Marshal(x.Durations[iNdEx]) - if err != nil { - return protoiface.MarshalOutput{ - NoUnkeyedLiterals: input.NoUnkeyedLiterals, - Buf: input.Buf, - }, err - } - i -= len(encoded) - copy(dAtA[i:], encoded) - i = runtime.EncodeVarint(dAtA, i, uint64(len(encoded))) - i-- - dAtA[i] = 0x1 - i-- - dAtA[i] = 0xca - } - } - if len(x.Enums) > 0 { - var pksize2 int - for _, num := range x.Enums { - pksize2 += runtime.Sov(uint64(num)) - } - i -= pksize2 - j1 := i - for _, num1 := range x.Enums { - num := uint64(num1) - for num >= 1<<7 { - dAtA[j1] = uint8(uint64(num)&0x7f | 0x80) - num >>= 7 - j1++ - } - dAtA[j1] = uint8(num) - j1++ - } - i = runtime.EncodeVarint(dAtA, i, uint64(pksize2)) - i-- - dAtA[i] = 0x1 - i-- - dAtA[i] = 0xc2 - } - if len(x.Strings) > 0 { - for iNdEx := len(x.Strings) - 1; iNdEx >= 0; iNdEx-- { - i -= len(x.Strings[iNdEx]) - copy(dAtA[i:], x.Strings[iNdEx]) - i = runtime.EncodeVarint(dAtA, i, uint64(len(x.Strings[iNdEx]))) - i-- - dAtA[i] = 0x1 - i-- - dAtA[i] = 0xba - } - } - if len(x.Uints) > 0 { - var pksize4 int - for _, num := range x.Uints { - pksize4 += runtime.Sov(uint64(num)) - } - i -= pksize4 - j3 := i - for _, num := range x.Uints { - for num >= 1<<7 { - dAtA[j3] = uint8(uint64(num)&0x7f | 0x80) - num >>= 7 - j3++ - } - dAtA[j3] = uint8(num) - j3++ - } - i = runtime.EncodeVarint(dAtA, i, uint64(pksize4)) - i-- - dAtA[i] = 0x1 - i-- - dAtA[i] = 0xb2 - } - if len(x.Bools) > 0 { - for iNdEx := len(x.Bools) - 1; iNdEx >= 0; iNdEx-- { - i-- - if x.Bools[iNdEx] { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - } - i = runtime.EncodeVarint(dAtA, i, uint64(len(x.Bools))) - i-- - dAtA[i] = 0x1 - i-- - dAtA[i] = 0xaa - } - if x.Page != nil { - encoded, err := options.Marshal(x.Page) - if err != nil { - return protoiface.MarshalOutput{ - NoUnkeyedLiterals: input.NoUnkeyedLiterals, - Buf: input.Buf, - }, err - } - i -= len(encoded) - copy(dAtA[i:], encoded) - i = runtime.EncodeVarint(dAtA, i, uint64(len(encoded))) - i-- - dAtA[i] = 0x1 - i-- - dAtA[i] = 0xa2 - } - if len(x.AnAddress) > 0 { - i -= len(x.AnAddress) - copy(dAtA[i:], x.AnAddress) - i = runtime.EncodeVarint(dAtA, i, uint64(len(x.AnAddress))) - i-- - dAtA[i] = 0x1 - i-- - dAtA[i] = 0x9a - } - if x.ACoin != nil { - encoded, err := options.Marshal(x.ACoin) - if err != nil { - return protoiface.MarshalOutput{ - NoUnkeyedLiterals: input.NoUnkeyedLiterals, - Buf: input.Buf, - }, err - } - i -= len(encoded) - copy(dAtA[i:], encoded) - i = runtime.EncodeVarint(dAtA, i, uint64(len(encoded))) - i-- - dAtA[i] = 0x1 - i-- - dAtA[i] = 0x92 - } - if x.AMessage != nil { - encoded, err := options.Marshal(x.AMessage) - if err != nil { - return protoiface.MarshalOutput{ - NoUnkeyedLiterals: input.NoUnkeyedLiterals, - Buf: input.Buf, - }, err - } - i -= len(encoded) - copy(dAtA[i:], encoded) - i = runtime.EncodeVarint(dAtA, i, uint64(len(encoded))) - i-- - dAtA[i] = 0x1 - i-- - dAtA[i] = 0x8a - } - if x.AnEnum != 0 { - i = runtime.EncodeVarint(dAtA, i, uint64(x.AnEnum)) - i-- - dAtA[i] = 0x1 - i-- - dAtA[i] = 0x80 - } - if x.ABool { - i-- - if x.ABool { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i-- - dAtA[i] = 0x78 - } - if x.I64 != 0 { - i = runtime.EncodeVarint(dAtA, i, uint64(x.I64)) - i-- - dAtA[i] = 0x50 - } - if x.I32 != 0 { - i = runtime.EncodeVarint(dAtA, i, uint64(x.I32)) - i-- - dAtA[i] = 0x38 - } - if x.Duration != nil { - encoded, err := options.Marshal(x.Duration) - if err != nil { - return protoiface.MarshalOutput{ - NoUnkeyedLiterals: input.NoUnkeyedLiterals, - Buf: input.Buf, - }, err - } - i -= len(encoded) - copy(dAtA[i:], encoded) - i = runtime.EncodeVarint(dAtA, i, uint64(len(encoded))) - i-- - dAtA[i] = 0x32 - } - if x.Timestamp != nil { - encoded, err := options.Marshal(x.Timestamp) - if err != nil { - return protoiface.MarshalOutput{ - NoUnkeyedLiterals: input.NoUnkeyedLiterals, - Buf: input.Buf, - }, err - } - i -= len(encoded) - copy(dAtA[i:], encoded) - i = runtime.EncodeVarint(dAtA, i, uint64(len(encoded))) - i-- - dAtA[i] = 0x2a - } - if len(x.Bz) > 0 { - i -= len(x.Bz) - copy(dAtA[i:], x.Bz) - i = runtime.EncodeVarint(dAtA, i, uint64(len(x.Bz))) - i-- - dAtA[i] = 0x22 - } - if len(x.Str) > 0 { - i -= len(x.Str) - copy(dAtA[i:], x.Str) - i = runtime.EncodeVarint(dAtA, i, uint64(len(x.Str))) - i-- - dAtA[i] = 0x1a - } - if x.U64 != 0 { - i = runtime.EncodeVarint(dAtA, i, uint64(x.U64)) - i-- - dAtA[i] = 0x10 - } - if x.U32 != 0 { - i = runtime.EncodeVarint(dAtA, i, uint64(x.U32)) - i-- - dAtA[i] = 0x8 - } - if input.Buf != nil { - input.Buf = append(input.Buf, dAtA...) - } else { - input.Buf = dAtA - } - return protoiface.MarshalOutput{ - NoUnkeyedLiterals: input.NoUnkeyedLiterals, - Buf: input.Buf, - }, nil - } - unmarshal := func(input protoiface.UnmarshalInput) (protoiface.UnmarshalOutput, error) { - x := input.Message.Interface().(*EchoRequest) - if x == nil { - return protoiface.UnmarshalOutput{ - NoUnkeyedLiterals: input.NoUnkeyedLiterals, - Flags: input.Flags, - }, nil - } - options := runtime.UnmarshalInputToOptions(input) - _ = options - dAtA := input.Buf - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: EchoRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: EchoRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field U32", wireType) - } - x.U32 = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - x.U32 |= uint32(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field U64", wireType) - } - x.U64 = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - x.U64 |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 3: - if wireType != 2 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Str", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - if postIndex > l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - x.Str = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 4: - if wireType != 2 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Bz", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - if postIndex > l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - x.Bz = append(x.Bz[:0], dAtA[iNdEx:postIndex]...) - if x.Bz == nil { - x.Bz = []byte{} - } - iNdEx = postIndex - case 5: - if wireType != 2 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Timestamp", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - if postIndex > l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - if x.Timestamp == nil { - x.Timestamp = ×tamppb.Timestamp{} - } - if err := options.Unmarshal(dAtA[iNdEx:postIndex], x.Timestamp); err != nil { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err - } - iNdEx = postIndex - case 6: - if wireType != 2 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Duration", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - if postIndex > l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - if x.Duration == nil { - x.Duration = &durationpb.Duration{} - } - if err := options.Unmarshal(dAtA[iNdEx:postIndex], x.Duration); err != nil { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err - } - iNdEx = postIndex - case 7: - if wireType != 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field I32", wireType) - } - x.I32 = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - x.I32 |= int32(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 10: - if wireType != 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field I64", wireType) - } - x.I64 = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - x.I64 |= int64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 15: - if wireType != 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field ABool", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - x.ABool = bool(v != 0) - case 16: - if wireType != 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field AnEnum", wireType) - } - x.AnEnum = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - x.AnEnum |= Enum(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 17: - if wireType != 2 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field AMessage", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - if postIndex > l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - if x.AMessage == nil { - x.AMessage = &AMessage{} - } - if err := options.Unmarshal(dAtA[iNdEx:postIndex], x.AMessage); err != nil { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err - } - iNdEx = postIndex - case 18: - if wireType != 2 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field ACoin", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - if postIndex > l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - if x.ACoin == nil { - x.ACoin = &v1beta1.Coin{} - } - if err := options.Unmarshal(dAtA[iNdEx:postIndex], x.ACoin); err != nil { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err - } - iNdEx = postIndex - case 19: - if wireType != 2 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field AnAddress", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - if postIndex > l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - x.AnAddress = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 20: - if wireType != 2 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Page", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - if postIndex > l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - if x.Page == nil { - x.Page = &v1beta11.PageRequest{} - } - if err := options.Unmarshal(dAtA[iNdEx:postIndex], x.Page); err != nil { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err - } - iNdEx = postIndex - case 21: - if wireType == 0 { - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - x.Bools = append(x.Bools, bool(v != 0)) - } else if wireType == 2 { - var packedLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - packedLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if packedLen < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - postIndex := iNdEx + packedLen - if postIndex < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - if postIndex > l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - var elementCount int - elementCount = packedLen - if elementCount != 0 && len(x.Bools) == 0 { - x.Bools = make([]bool, 0, elementCount) - } - for iNdEx < postIndex { - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - x.Bools = append(x.Bools, bool(v != 0)) - } - } else { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Bools", wireType) - } - case 22: - if wireType == 0 { - var v uint32 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= uint32(b&0x7F) << shift - if b < 0x80 { - break - } - } - x.Uints = append(x.Uints, v) - } else if wireType == 2 { - var packedLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - packedLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if packedLen < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - postIndex := iNdEx + packedLen - if postIndex < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - if postIndex > l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - var elementCount int - var count int - for _, integer := range dAtA[iNdEx:postIndex] { - if integer < 128 { - count++ - } - } - elementCount = count - if elementCount != 0 && len(x.Uints) == 0 { - x.Uints = make([]uint32, 0, elementCount) - } - for iNdEx < postIndex { - var v uint32 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= uint32(b&0x7F) << shift - if b < 0x80 { - break - } - } - x.Uints = append(x.Uints, v) - } - } else { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Uints", wireType) - } - case 23: - if wireType != 2 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Strings", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - if postIndex > l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - x.Strings = append(x.Strings, string(dAtA[iNdEx:postIndex])) - iNdEx = postIndex - case 24: - if wireType == 0 { - var v Enum - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= Enum(b&0x7F) << shift - if b < 0x80 { - break - } - } - x.Enums = append(x.Enums, v) - } else if wireType == 2 { - var packedLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - packedLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if packedLen < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - postIndex := iNdEx + packedLen - if postIndex < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - if postIndex > l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - var elementCount int - if elementCount != 0 && len(x.Enums) == 0 { - x.Enums = make([]Enum, 0, elementCount) - } - for iNdEx < postIndex { - var v Enum - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= Enum(b&0x7F) << shift - if b < 0x80 { - break - } - } - x.Enums = append(x.Enums, v) - } - } else { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Enums", wireType) - } - case 25: - if wireType != 2 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Durations", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - if postIndex > l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - x.Durations = append(x.Durations, &durationpb.Duration{}) - if err := options.Unmarshal(dAtA[iNdEx:postIndex], x.Durations[len(x.Durations)-1]); err != nil { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err - } - iNdEx = postIndex - case 26: - if wireType != 2 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field SomeMessages", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - if postIndex > l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - x.SomeMessages = append(x.SomeMessages, &AMessage{}) - if err := options.Unmarshal(dAtA[iNdEx:postIndex], x.SomeMessages[len(x.SomeMessages)-1]); err != nil { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err - } - iNdEx = postIndex - case 27: - if wireType != 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Positional1", wireType) - } - x.Positional1 = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - x.Positional1 |= int32(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 28: - if wireType != 2 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Positional2", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - if postIndex > l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - x.Positional2 = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 29: - if wireType != 2 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Positional3Varargs", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - if postIndex > l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - x.Positional3Varargs = append(x.Positional3Varargs, &v1beta1.Coin{}) - if err := options.Unmarshal(dAtA[iNdEx:postIndex], x.Positional3Varargs[len(x.Positional3Varargs)-1]); err != nil { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err - } - iNdEx = postIndex - case 30: - if wireType != 2 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field DeprecatedField", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - if postIndex > l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - x.DeprecatedField = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 31: - if wireType != 2 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field ShorthandDeprecatedField", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - if postIndex > l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - x.ShorthandDeprecatedField = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 32: - if wireType != 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field HiddenBool", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - x.HiddenBool = bool(v != 0) - case 33: - if wireType != 2 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field MapStringString", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - if postIndex > l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - if x.MapStringString == nil { - x.MapStringString = make(map[string]string) - } - var mapkey string - var mapvalue string - for iNdEx < postIndex { - entryPreIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - if fieldNum == 1 { - var stringLenmapkey uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLenmapkey |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLenmapkey := int(stringLenmapkey) - if intStringLenmapkey < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - postStringIndexmapkey := iNdEx + intStringLenmapkey - if postStringIndexmapkey < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - if postStringIndexmapkey > l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - mapkey = string(dAtA[iNdEx:postStringIndexmapkey]) - iNdEx = postStringIndexmapkey - } else if fieldNum == 2 { - var stringLenmapvalue uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLenmapvalue |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLenmapvalue := int(stringLenmapvalue) - if intStringLenmapvalue < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - postStringIndexmapvalue := iNdEx + intStringLenmapvalue - if postStringIndexmapvalue < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - if postStringIndexmapvalue > l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - mapvalue = string(dAtA[iNdEx:postStringIndexmapvalue]) - iNdEx = postStringIndexmapvalue - } else { - iNdEx = entryPreIndex - skippy, err := runtime.Skip(dAtA[iNdEx:]) - if err != nil { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - if (iNdEx + skippy) > postIndex { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - x.MapStringString[mapkey] = mapvalue - iNdEx = postIndex - case 34: - if wireType != 2 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field MapStringUint32", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - if postIndex > l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - if x.MapStringUint32 == nil { - x.MapStringUint32 = make(map[string]uint32) - } - var mapkey string - var mapvalue uint32 - for iNdEx < postIndex { - entryPreIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - if fieldNum == 1 { - var stringLenmapkey uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLenmapkey |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLenmapkey := int(stringLenmapkey) - if intStringLenmapkey < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - postStringIndexmapkey := iNdEx + intStringLenmapkey - if postStringIndexmapkey < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - if postStringIndexmapkey > l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - mapkey = string(dAtA[iNdEx:postStringIndexmapkey]) - iNdEx = postStringIndexmapkey - } else if fieldNum == 2 { - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - mapvalue |= uint32(b&0x7F) << shift - if b < 0x80 { - break - } - } - } else { - iNdEx = entryPreIndex - skippy, err := runtime.Skip(dAtA[iNdEx:]) - if err != nil { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - if (iNdEx + skippy) > postIndex { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - x.MapStringUint32[mapkey] = mapvalue - iNdEx = postIndex - case 35: - if wireType != 2 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field MapStringCoin", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - if postIndex > l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - if x.MapStringCoin == nil { - x.MapStringCoin = make(map[string]*v1beta1.Coin) - } - var mapkey string - var mapvalue *v1beta1.Coin - for iNdEx < postIndex { - entryPreIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - if fieldNum == 1 { - var stringLenmapkey uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLenmapkey |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLenmapkey := int(stringLenmapkey) - if intStringLenmapkey < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - postStringIndexmapkey := iNdEx + intStringLenmapkey - if postStringIndexmapkey < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - if postStringIndexmapkey > l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - mapkey = string(dAtA[iNdEx:postStringIndexmapkey]) - iNdEx = postStringIndexmapkey - } else if fieldNum == 2 { - var mapmsglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - mapmsglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if mapmsglen < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - postmsgIndex := iNdEx + mapmsglen - if postmsgIndex < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - if postmsgIndex > l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - mapvalue = &v1beta1.Coin{} - if err := options.Unmarshal(dAtA[iNdEx:postmsgIndex], mapvalue); err != nil { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err - } - iNdEx = postmsgIndex - } else { - iNdEx = entryPreIndex - skippy, err := runtime.Skip(dAtA[iNdEx:]) - if err != nil { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - if (iNdEx + skippy) > postIndex { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - x.MapStringCoin[mapkey] = mapvalue - iNdEx = postIndex - case 36: - if wireType != 2 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field AValidatorAddress", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - if postIndex > l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - x.AValidatorAddress = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 37: - if wireType != 2 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field AConsensusAddress", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - if postIndex > l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - x.AConsensusAddress = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 38: - if wireType != 2 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Coins", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - if postIndex > l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - x.Coins = append(x.Coins, &v1beta1.Coin{}) - if err := options.Unmarshal(dAtA[iNdEx:postIndex], x.Coins[len(x.Coins)-1]); err != nil { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := runtime.Skip(dAtA[iNdEx:]) - if err != nil { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - if (iNdEx + skippy) > l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - if !options.DiscardUnknown { - x.unknownFields = append(x.unknownFields, dAtA[iNdEx:iNdEx+skippy]...) - } - iNdEx += skippy - } - } - - if iNdEx > l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, nil - } - return &protoiface.Methods{ - NoUnkeyedLiterals: struct{}{}, - Flags: protoiface.SupportMarshalDeterministic | protoiface.SupportUnmarshalDiscardUnknown, - Size: size, - Marshal: marshal, - Unmarshal: unmarshal, - Merge: nil, - CheckInitialized: nil, - } -} - -var ( - md_EchoResponse protoreflect.MessageDescriptor - fd_EchoResponse_request protoreflect.FieldDescriptor -) - -func init() { - file_testpb_query_proto_init() - md_EchoResponse = File_testpb_query_proto.Messages().ByName("EchoResponse") - fd_EchoResponse_request = md_EchoResponse.Fields().ByName("request") -} - -var _ protoreflect.Message = (*fastReflection_EchoResponse)(nil) - -type fastReflection_EchoResponse EchoResponse - -func (x *EchoResponse) ProtoReflect() protoreflect.Message { - return (*fastReflection_EchoResponse)(x) -} - -func (x *EchoResponse) slowProtoReflect() protoreflect.Message { - mi := &file_testpb_query_proto_msgTypes[2] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -var _fastReflection_EchoResponse_messageType fastReflection_EchoResponse_messageType -var _ protoreflect.MessageType = fastReflection_EchoResponse_messageType{} - -type fastReflection_EchoResponse_messageType struct{} - -func (x fastReflection_EchoResponse_messageType) Zero() protoreflect.Message { - return (*fastReflection_EchoResponse)(nil) -} -func (x fastReflection_EchoResponse_messageType) New() protoreflect.Message { - return new(fastReflection_EchoResponse) -} -func (x fastReflection_EchoResponse_messageType) Descriptor() protoreflect.MessageDescriptor { - return md_EchoResponse -} - -// Descriptor returns message descriptor, which contains only the protobuf -// type information for the message. -func (x *fastReflection_EchoResponse) Descriptor() protoreflect.MessageDescriptor { - return md_EchoResponse -} - -// Type returns the message type, which encapsulates both Go and protobuf -// type information. If the Go type information is not needed, -// it is recommended that the message descriptor be used instead. -func (x *fastReflection_EchoResponse) Type() protoreflect.MessageType { - return _fastReflection_EchoResponse_messageType -} - -// New returns a newly allocated and mutable empty message. -func (x *fastReflection_EchoResponse) New() protoreflect.Message { - return new(fastReflection_EchoResponse) -} - -// Interface unwraps the message reflection interface and -// returns the underlying ProtoMessage interface. -func (x *fastReflection_EchoResponse) Interface() protoreflect.ProtoMessage { - return (*EchoResponse)(x) -} - -// Range iterates over every populated field in an undefined order, -// calling f for each field descriptor and value encountered. -// Range returns immediately if f returns false. -// While iterating, mutating operations may only be performed -// on the current field descriptor. -func (x *fastReflection_EchoResponse) Range(f func(protoreflect.FieldDescriptor, protoreflect.Value) bool) { - if x.Request != nil { - value := protoreflect.ValueOfMessage(x.Request.ProtoReflect()) - if !f(fd_EchoResponse_request, value) { - return - } - } -} - -// Has reports whether a field is populated. -// -// Some fields have the property of nullability where it is possible to -// distinguish between the default value of a field and whether the field -// was explicitly populated with the default value. Singular message fields, -// member fields of a oneof, and proto2 scalar fields are nullable. Such -// fields are populated only if explicitly set. -// -// In other cases (aside from the nullable cases above), -// a proto3 scalar field is populated if it contains a non-zero value, and -// a repeated field is populated if it is non-empty. -func (x *fastReflection_EchoResponse) Has(fd protoreflect.FieldDescriptor) bool { - switch fd.FullName() { - case "testpb.EchoResponse.request": - return x.Request != nil - default: - if fd.IsExtension() { - panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.EchoResponse")) - } - panic(fmt.Errorf("message testpb.EchoResponse does not contain field %s", fd.FullName())) - } -} - -// Clear clears the field such that a subsequent Has call reports false. -// -// Clearing an extension field clears both the extension type and value -// associated with the given field number. -// -// Clear is a mutating operation and unsafe for concurrent use. -func (x *fastReflection_EchoResponse) Clear(fd protoreflect.FieldDescriptor) { - switch fd.FullName() { - case "testpb.EchoResponse.request": - x.Request = nil - default: - if fd.IsExtension() { - panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.EchoResponse")) - } - panic(fmt.Errorf("message testpb.EchoResponse does not contain field %s", fd.FullName())) - } -} - -// Get retrieves the value for a field. -// -// For unpopulated scalars, it returns the default value, where -// the default value of a bytes scalar is guaranteed to be a copy. -// For unpopulated composite types, it returns an empty, read-only view -// of the value; to obtain a mutable reference, use Mutable. -func (x *fastReflection_EchoResponse) Get(descriptor protoreflect.FieldDescriptor) protoreflect.Value { - switch descriptor.FullName() { - case "testpb.EchoResponse.request": - value := x.Request - return protoreflect.ValueOfMessage(value.ProtoReflect()) - default: - if descriptor.IsExtension() { - panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.EchoResponse")) - } - panic(fmt.Errorf("message testpb.EchoResponse does not contain field %s", descriptor.FullName())) - } -} - -// Set stores the value for a field. -// -// For a field belonging to a oneof, it implicitly clears any other field -// that may be currently set within the same oneof. -// For extension fields, it implicitly stores the provided ExtensionType. -// When setting a composite type, it is unspecified whether the stored value -// aliases the source's memory in any way. If the composite value is an -// empty, read-only value, then it panics. -// -// Set is a mutating operation and unsafe for concurrent use. -func (x *fastReflection_EchoResponse) Set(fd protoreflect.FieldDescriptor, value protoreflect.Value) { - switch fd.FullName() { - case "testpb.EchoResponse.request": - x.Request = value.Message().Interface().(*EchoRequest) - default: - if fd.IsExtension() { - panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.EchoResponse")) - } - panic(fmt.Errorf("message testpb.EchoResponse does not contain field %s", fd.FullName())) - } -} - -// Mutable returns a mutable reference to a composite type. -// -// If the field is unpopulated, it may allocate a composite value. -// For a field belonging to a oneof, it implicitly clears any other field -// that may be currently set within the same oneof. -// For extension fields, it implicitly stores the provided ExtensionType -// if not already stored. -// It panics if the field does not contain a composite type. -// -// Mutable is a mutating operation and unsafe for concurrent use. -func (x *fastReflection_EchoResponse) Mutable(fd protoreflect.FieldDescriptor) protoreflect.Value { - switch fd.FullName() { - case "testpb.EchoResponse.request": - if x.Request == nil { - x.Request = new(EchoRequest) - } - return protoreflect.ValueOfMessage(x.Request.ProtoReflect()) - default: - if fd.IsExtension() { - panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.EchoResponse")) - } - panic(fmt.Errorf("message testpb.EchoResponse does not contain field %s", fd.FullName())) - } -} - -// NewField returns a new value that is assignable to the field -// for the given descriptor. For scalars, this returns the default value. -// For lists, maps, and messages, this returns a new, empty, mutable value. -func (x *fastReflection_EchoResponse) NewField(fd protoreflect.FieldDescriptor) protoreflect.Value { - switch fd.FullName() { - case "testpb.EchoResponse.request": - m := new(EchoRequest) - return protoreflect.ValueOfMessage(m.ProtoReflect()) - default: - if fd.IsExtension() { - panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.EchoResponse")) - } - panic(fmt.Errorf("message testpb.EchoResponse does not contain field %s", fd.FullName())) - } -} - -// WhichOneof reports which field within the oneof is populated, -// returning nil if none are populated. -// It panics if the oneof descriptor does not belong to this message. -func (x *fastReflection_EchoResponse) WhichOneof(d protoreflect.OneofDescriptor) protoreflect.FieldDescriptor { - switch d.FullName() { - default: - panic(fmt.Errorf("%s is not a oneof field in testpb.EchoResponse", d.FullName())) - } - panic("unreachable") -} - -// GetUnknown retrieves the entire list of unknown fields. -// The caller may only mutate the contents of the RawFields -// if the mutated bytes are stored back into the message with SetUnknown. -func (x *fastReflection_EchoResponse) GetUnknown() protoreflect.RawFields { - return x.unknownFields -} - -// SetUnknown stores an entire list of unknown fields. -// The raw fields must be syntactically valid according to the wire format. -// An implementation may panic if this is not the case. -// Once stored, the caller must not mutate the content of the RawFields. -// An empty RawFields may be passed to clear the fields. -// -// SetUnknown is a mutating operation and unsafe for concurrent use. -func (x *fastReflection_EchoResponse) SetUnknown(fields protoreflect.RawFields) { - x.unknownFields = fields -} - -// IsValid reports whether the message is valid. -// -// An invalid message is an empty, read-only value. -// -// An invalid message often corresponds to a nil pointer of the concrete -// message type, but the details are implementation dependent. -// Validity is not part of the protobuf data model, and may not -// be preserved in marshaling or other operations. -func (x *fastReflection_EchoResponse) IsValid() bool { - return x != nil -} - -// ProtoMethods returns optional fastReflectionFeature-path implementations of various operations. -// This method may return nil. -// -// The returned methods type is identical to -// "google.golang.org/protobuf/runtime/protoiface".Methods. -// Consult the protoiface package documentation for details. -func (x *fastReflection_EchoResponse) ProtoMethods() *protoiface.Methods { - size := func(input protoiface.SizeInput) protoiface.SizeOutput { - x := input.Message.Interface().(*EchoResponse) - if x == nil { - return protoiface.SizeOutput{ - NoUnkeyedLiterals: input.NoUnkeyedLiterals, - Size: 0, - } - } - options := runtime.SizeInputToOptions(input) - _ = options - var n int - var l int - _ = l - if x.Request != nil { - l = options.Size(x.Request) - n += 1 + l + runtime.Sov(uint64(l)) - } - if x.unknownFields != nil { - n += len(x.unknownFields) - } - return protoiface.SizeOutput{ - NoUnkeyedLiterals: input.NoUnkeyedLiterals, - Size: n, - } - } - - marshal := func(input protoiface.MarshalInput) (protoiface.MarshalOutput, error) { - x := input.Message.Interface().(*EchoResponse) - if x == nil { - return protoiface.MarshalOutput{ - NoUnkeyedLiterals: input.NoUnkeyedLiterals, - Buf: input.Buf, - }, nil - } - options := runtime.MarshalInputToOptions(input) - _ = options - size := options.Size(x) - dAtA := make([]byte, size) - i := len(dAtA) - _ = i - var l int - _ = l - if x.unknownFields != nil { - i -= len(x.unknownFields) - copy(dAtA[i:], x.unknownFields) - } - if x.Request != nil { - encoded, err := options.Marshal(x.Request) - if err != nil { - return protoiface.MarshalOutput{ - NoUnkeyedLiterals: input.NoUnkeyedLiterals, - Buf: input.Buf, - }, err - } - i -= len(encoded) - copy(dAtA[i:], encoded) - i = runtime.EncodeVarint(dAtA, i, uint64(len(encoded))) - i-- - dAtA[i] = 0xa - } - if input.Buf != nil { - input.Buf = append(input.Buf, dAtA...) - } else { - input.Buf = dAtA - } - return protoiface.MarshalOutput{ - NoUnkeyedLiterals: input.NoUnkeyedLiterals, - Buf: input.Buf, - }, nil - } - unmarshal := func(input protoiface.UnmarshalInput) (protoiface.UnmarshalOutput, error) { - x := input.Message.Interface().(*EchoResponse) - if x == nil { - return protoiface.UnmarshalOutput{ - NoUnkeyedLiterals: input.NoUnkeyedLiterals, - Flags: input.Flags, - }, nil - } - options := runtime.UnmarshalInputToOptions(input) - _ = options - dAtA := input.Buf - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: EchoResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: EchoResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Request", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow - } - if iNdEx >= l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - if postIndex > l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - if x.Request == nil { - x.Request = &EchoRequest{} - } - if err := options.Unmarshal(dAtA[iNdEx:postIndex], x.Request); err != nil { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := runtime.Skip(dAtA[iNdEx:]) - if err != nil { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength - } - if (iNdEx + skippy) > l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - if !options.DiscardUnknown { - x.unknownFields = append(x.unknownFields, dAtA[iNdEx:iNdEx+skippy]...) - } - iNdEx += skippy - } - } - - if iNdEx > l { - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF - } - return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, nil - } - return &protoiface.Methods{ - NoUnkeyedLiterals: struct{}{}, - Flags: protoiface.SupportMarshalDeterministic | protoiface.SupportUnmarshalDiscardUnknown, - Size: size, - Marshal: marshal, - Unmarshal: unmarshal, - Merge: nil, - CheckInitialized: nil, - } -} - -// Code generated by protoc-gen-go. DO NOT EDIT. -// versions: -// protoc-gen-go v1.27.0 -// protoc (unknown) -// source: testpb/query.proto - -const ( - // Verify that this generated code is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) - // Verify that runtime/protoimpl is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) -) - -type Enum int32 - -const ( - Enum_ENUM_UNSPECIFIED Enum = 0 - Enum_ENUM_ONE Enum = 1 - Enum_ENUM_TWO Enum = 2 - Enum_ENUM_FIVE Enum = 5 - Enum_ENUM_NEG_THREE Enum = -3 -) - -// Enum value maps for Enum. -var ( - Enum_name = map[int32]string{ - 0: "ENUM_UNSPECIFIED", - 1: "ENUM_ONE", - 2: "ENUM_TWO", - 5: "ENUM_FIVE", - -3: "ENUM_NEG_THREE", - } - Enum_value = map[string]int32{ - "ENUM_UNSPECIFIED": 0, - "ENUM_ONE": 1, - "ENUM_TWO": 2, - "ENUM_FIVE": 5, - "ENUM_NEG_THREE": -3, - } -) - -func (x Enum) Enum() *Enum { - p := new(Enum) - *p = x - return p -} - -func (x Enum) String() string { - return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) -} - -func (Enum) Descriptor() protoreflect.EnumDescriptor { - return file_testpb_query_proto_enumTypes[0].Descriptor() -} - -func (Enum) Type() protoreflect.EnumType { - return &file_testpb_query_proto_enumTypes[0] -} - -func (x Enum) Number() protoreflect.EnumNumber { - return protoreflect.EnumNumber(x) -} - -// Deprecated: Use Enum.Descriptor instead. -func (Enum) EnumDescriptor() ([]byte, []int) { - return file_testpb_query_proto_rawDescGZIP(), []int{0} -} - -type AMessage struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Bar string `protobuf:"bytes,1,opt,name=bar,proto3" json:"bar,omitempty"` - Baz int32 `protobuf:"varint,2,opt,name=baz,proto3" json:"baz,omitempty"` -} - -func (x *AMessage) Reset() { - *x = AMessage{} - if protoimpl.UnsafeEnabled { - mi := &file_testpb_query_proto_msgTypes[0] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *AMessage) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*AMessage) ProtoMessage() {} - -// Deprecated: Use AMessage.ProtoReflect.Descriptor instead. -func (*AMessage) Descriptor() ([]byte, []int) { - return file_testpb_query_proto_rawDescGZIP(), []int{0} -} - -func (x *AMessage) GetBar() string { - if x != nil { - return x.Bar - } - return "" -} - -func (x *AMessage) GetBaz() int32 { - if x != nil { - return x.Baz - } - return 0 -} - -type EchoRequest struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - // u32 is an uint32 - U32 uint32 `protobuf:"varint,1,opt,name=u32,proto3" json:"u32,omitempty"` - U64 uint64 `protobuf:"varint,2,opt,name=u64,proto3" json:"u64,omitempty"` - Str string `protobuf:"bytes,3,opt,name=str,proto3" json:"str,omitempty"` - Bz []byte `protobuf:"bytes,4,opt,name=bz,proto3" json:"bz,omitempty"` - Timestamp *timestamppb.Timestamp `protobuf:"bytes,5,opt,name=timestamp,proto3" json:"timestamp,omitempty"` - Duration *durationpb.Duration `protobuf:"bytes,6,opt,name=duration,proto3" json:"duration,omitempty"` - I32 int32 `protobuf:"varint,7,opt,name=i32,proto3" json:"i32,omitempty"` - I64 int64 `protobuf:"varint,10,opt,name=i64,proto3" json:"i64,omitempty"` - ABool bool `protobuf:"varint,15,opt,name=a_bool,json=aBool,proto3" json:"a_bool,omitempty"` - AnEnum Enum `protobuf:"varint,16,opt,name=an_enum,json=anEnum,proto3,enum=testpb.Enum" json:"an_enum,omitempty"` - AMessage *AMessage `protobuf:"bytes,17,opt,name=a_message,json=aMessage,proto3" json:"a_message,omitempty"` - ACoin *v1beta1.Coin `protobuf:"bytes,18,opt,name=a_coin,json=aCoin,proto3" json:"a_coin,omitempty"` - AnAddress string `protobuf:"bytes,19,opt,name=an_address,json=anAddress,proto3" json:"an_address,omitempty"` - Page *v1beta11.PageRequest `protobuf:"bytes,20,opt,name=page,proto3" json:"page,omitempty"` - Bools []bool `protobuf:"varint,21,rep,packed,name=bools,proto3" json:"bools,omitempty"` - Uints []uint32 `protobuf:"varint,22,rep,packed,name=uints,proto3" json:"uints,omitempty"` - Strings []string `protobuf:"bytes,23,rep,name=strings,proto3" json:"strings,omitempty"` - Enums []Enum `protobuf:"varint,24,rep,packed,name=enums,proto3,enum=testpb.Enum" json:"enums,omitempty"` - Durations []*durationpb.Duration `protobuf:"bytes,25,rep,name=durations,proto3" json:"durations,omitempty"` - SomeMessages []*AMessage `protobuf:"bytes,26,rep,name=some_messages,json=someMessages,proto3" json:"some_messages,omitempty"` - Positional1 int32 `protobuf:"varint,27,opt,name=positional1,proto3" json:"positional1,omitempty"` - Positional2 string `protobuf:"bytes,28,opt,name=positional2,proto3" json:"positional2,omitempty"` - Positional3Varargs []*v1beta1.Coin `protobuf:"bytes,29,rep,name=positional3_varargs,json=positional3Varargs,proto3" json:"positional3_varargs,omitempty"` - DeprecatedField string `protobuf:"bytes,30,opt,name=deprecated_field,json=deprecatedField,proto3" json:"deprecated_field,omitempty"` - ShorthandDeprecatedField string `protobuf:"bytes,31,opt,name=shorthand_deprecated_field,json=shorthandDeprecatedField,proto3" json:"shorthand_deprecated_field,omitempty"` - HiddenBool bool `protobuf:"varint,32,opt,name=hidden_bool,json=hiddenBool,proto3" json:"hidden_bool,omitempty"` - MapStringString map[string]string `protobuf:"bytes,33,rep,name=map_string_string,json=mapStringString,proto3" json:"map_string_string,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` - MapStringUint32 map[string]uint32 `protobuf:"bytes,34,rep,name=map_string_uint32,json=mapStringUint32,proto3" json:"map_string_uint32,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3"` - MapStringCoin map[string]*v1beta1.Coin `protobuf:"bytes,35,rep,name=map_string_coin,json=mapStringCoin,proto3" json:"map_string_coin,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` - AValidatorAddress string `protobuf:"bytes,36,opt,name=a_validator_address,json=aValidatorAddress,proto3" json:"a_validator_address,omitempty"` - AConsensusAddress string `protobuf:"bytes,37,opt,name=a_consensus_address,json=aConsensusAddress,proto3" json:"a_consensus_address,omitempty"` - Coins []*v1beta1.Coin `protobuf:"bytes,38,rep,name=coins,proto3" json:"coins,omitempty"` -} - -func (x *EchoRequest) Reset() { - *x = EchoRequest{} - if protoimpl.UnsafeEnabled { - mi := &file_testpb_query_proto_msgTypes[1] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *EchoRequest) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*EchoRequest) ProtoMessage() {} - -// Deprecated: Use EchoRequest.ProtoReflect.Descriptor instead. -func (*EchoRequest) Descriptor() ([]byte, []int) { - return file_testpb_query_proto_rawDescGZIP(), []int{1} -} - -func (x *EchoRequest) GetU32() uint32 { - if x != nil { - return x.U32 - } - return 0 -} - -func (x *EchoRequest) GetU64() uint64 { - if x != nil { - return x.U64 - } - return 0 -} - -func (x *EchoRequest) GetStr() string { - if x != nil { - return x.Str - } - return "" -} - -func (x *EchoRequest) GetBz() []byte { - if x != nil { - return x.Bz - } - return nil -} - -func (x *EchoRequest) GetTimestamp() *timestamppb.Timestamp { - if x != nil { - return x.Timestamp - } - return nil -} - -func (x *EchoRequest) GetDuration() *durationpb.Duration { - if x != nil { - return x.Duration - } - return nil -} - -func (x *EchoRequest) GetI32() int32 { - if x != nil { - return x.I32 - } - return 0 -} - -func (x *EchoRequest) GetI64() int64 { - if x != nil { - return x.I64 - } - return 0 -} - -func (x *EchoRequest) GetABool() bool { - if x != nil { - return x.ABool - } - return false -} - -func (x *EchoRequest) GetAnEnum() Enum { - if x != nil { - return x.AnEnum - } - return Enum_ENUM_UNSPECIFIED -} - -func (x *EchoRequest) GetAMessage() *AMessage { - if x != nil { - return x.AMessage - } - return nil -} - -func (x *EchoRequest) GetACoin() *v1beta1.Coin { - if x != nil { - return x.ACoin - } - return nil -} - -func (x *EchoRequest) GetAnAddress() string { - if x != nil { - return x.AnAddress - } - return "" -} - -func (x *EchoRequest) GetPage() *v1beta11.PageRequest { - if x != nil { - return x.Page - } - return nil -} - -func (x *EchoRequest) GetBools() []bool { - if x != nil { - return x.Bools - } - return nil -} - -func (x *EchoRequest) GetUints() []uint32 { - if x != nil { - return x.Uints - } - return nil -} - -func (x *EchoRequest) GetStrings() []string { - if x != nil { - return x.Strings - } - return nil -} - -func (x *EchoRequest) GetEnums() []Enum { - if x != nil { - return x.Enums - } - return nil -} - -func (x *EchoRequest) GetDurations() []*durationpb.Duration { - if x != nil { - return x.Durations - } - return nil -} - -func (x *EchoRequest) GetSomeMessages() []*AMessage { - if x != nil { - return x.SomeMessages - } - return nil -} - -func (x *EchoRequest) GetPositional1() int32 { - if x != nil { - return x.Positional1 - } - return 0 -} - -func (x *EchoRequest) GetPositional2() string { - if x != nil { - return x.Positional2 - } - return "" -} - -func (x *EchoRequest) GetPositional3Varargs() []*v1beta1.Coin { - if x != nil { - return x.Positional3Varargs - } - return nil -} - -func (x *EchoRequest) GetDeprecatedField() string { - if x != nil { - return x.DeprecatedField - } - return "" -} - -func (x *EchoRequest) GetShorthandDeprecatedField() string { - if x != nil { - return x.ShorthandDeprecatedField - } - return "" -} - -func (x *EchoRequest) GetHiddenBool() bool { - if x != nil { - return x.HiddenBool - } - return false -} - -func (x *EchoRequest) GetMapStringString() map[string]string { - if x != nil { - return x.MapStringString - } - return nil -} - -func (x *EchoRequest) GetMapStringUint32() map[string]uint32 { - if x != nil { - return x.MapStringUint32 - } - return nil -} - -func (x *EchoRequest) GetMapStringCoin() map[string]*v1beta1.Coin { - if x != nil { - return x.MapStringCoin - } - return nil -} - -func (x *EchoRequest) GetAValidatorAddress() string { - if x != nil { - return x.AValidatorAddress - } - return "" -} - -func (x *EchoRequest) GetAConsensusAddress() string { - if x != nil { - return x.AConsensusAddress - } - return "" -} - -func (x *EchoRequest) GetCoins() []*v1beta1.Coin { - if x != nil { - return x.Coins - } - return nil -} - -type EchoResponse struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Request *EchoRequest `protobuf:"bytes,1,opt,name=request,proto3" json:"request,omitempty"` -} - -func (x *EchoResponse) Reset() { - *x = EchoResponse{} - if protoimpl.UnsafeEnabled { - mi := &file_testpb_query_proto_msgTypes[2] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *EchoResponse) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*EchoResponse) ProtoMessage() {} - -// Deprecated: Use EchoResponse.ProtoReflect.Descriptor instead. -func (*EchoResponse) Descriptor() ([]byte, []int) { - return file_testpb_query_proto_rawDescGZIP(), []int{2} -} - -func (x *EchoResponse) GetRequest() *EchoRequest { - if x != nil { - return x.Request - } - return nil -} - -var File_testpb_query_proto protoreflect.FileDescriptor - -var file_testpb_query_proto_rawDesc = []byte{ - 0x0a, 0x12, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x2f, 0x71, 0x75, 0x65, 0x72, 0x79, 0x2e, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x06, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x1a, 0x1f, 0x67, 0x6f, - 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x74, 0x69, - 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1e, 0x67, - 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x64, - 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x19, 0x63, - 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x5f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x63, 0x6f, 0x73, 0x6d, - 0x6f, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x2a, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, - 0x2f, 0x62, 0x61, 0x73, 0x65, 0x2f, 0x71, 0x75, 0x65, 0x72, 0x79, 0x2f, 0x76, 0x31, 0x62, 0x65, - 0x74, 0x61, 0x31, 0x2f, 0x70, 0x61, 0x67, 0x69, 0x6e, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x62, 0x61, 0x73, - 0x65, 0x2f, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x2f, 0x63, 0x6f, 0x69, 0x6e, 0x2e, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x2e, 0x0a, 0x08, 0x41, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, - 0x12, 0x10, 0x0a, 0x03, 0x62, 0x61, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x62, - 0x61, 0x72, 0x12, 0x10, 0x0a, 0x03, 0x62, 0x61, 0x7a, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, - 0x03, 0x62, 0x61, 0x7a, 0x22, 0xa8, 0x0d, 0x0a, 0x0b, 0x45, 0x63, 0x68, 0x6f, 0x52, 0x65, 0x71, - 0x75, 0x65, 0x73, 0x74, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x33, 0x32, 0x18, 0x01, 0x20, 0x01, 0x28, - 0x0d, 0x52, 0x03, 0x75, 0x33, 0x32, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x36, 0x34, 0x18, 0x02, 0x20, - 0x01, 0x28, 0x04, 0x52, 0x03, 0x75, 0x36, 0x34, 0x12, 0x10, 0x0a, 0x03, 0x73, 0x74, 0x72, 0x18, - 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x73, 0x74, 0x72, 0x12, 0x0e, 0x0a, 0x02, 0x62, 0x7a, - 0x18, 0x04, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x02, 0x62, 0x7a, 0x12, 0x38, 0x0a, 0x09, 0x74, 0x69, - 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, - 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, - 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x09, 0x74, 0x69, 0x6d, 0x65, 0x73, - 0x74, 0x61, 0x6d, 0x70, 0x12, 0x35, 0x0a, 0x08, 0x64, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, - 0x18, 0x06, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, - 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x44, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, - 0x6e, 0x52, 0x08, 0x64, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x10, 0x0a, 0x03, 0x69, - 0x33, 0x32, 0x18, 0x07, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x69, 0x33, 0x32, 0x12, 0x10, 0x0a, - 0x03, 0x69, 0x36, 0x34, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x03, 0x52, 0x03, 0x69, 0x36, 0x34, 0x12, - 0x15, 0x0a, 0x06, 0x61, 0x5f, 0x62, 0x6f, 0x6f, 0x6c, 0x18, 0x0f, 0x20, 0x01, 0x28, 0x08, 0x52, - 0x05, 0x61, 0x42, 0x6f, 0x6f, 0x6c, 0x12, 0x25, 0x0a, 0x07, 0x61, 0x6e, 0x5f, 0x65, 0x6e, 0x75, - 0x6d, 0x18, 0x10, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x0c, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, - 0x2e, 0x45, 0x6e, 0x75, 0x6d, 0x52, 0x06, 0x61, 0x6e, 0x45, 0x6e, 0x75, 0x6d, 0x12, 0x2d, 0x0a, - 0x09, 0x61, 0x5f, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x11, 0x20, 0x01, 0x28, 0x0b, - 0x32, 0x10, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x2e, 0x41, 0x4d, 0x65, 0x73, 0x73, 0x61, - 0x67, 0x65, 0x52, 0x08, 0x61, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x30, 0x0a, 0x06, - 0x61, 0x5f, 0x63, 0x6f, 0x69, 0x6e, 0x18, 0x12, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x63, - 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x76, 0x31, 0x62, 0x65, 0x74, - 0x61, 0x31, 0x2e, 0x43, 0x6f, 0x69, 0x6e, 0x52, 0x05, 0x61, 0x43, 0x6f, 0x69, 0x6e, 0x12, 0x37, - 0x0a, 0x0a, 0x61, 0x6e, 0x5f, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, 0x13, 0x20, 0x01, - 0x28, 0x09, 0x42, 0x18, 0xd2, 0xb4, 0x2d, 0x14, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x41, - 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x52, 0x09, 0x61, 0x6e, - 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x12, 0x3a, 0x0a, 0x04, 0x70, 0x61, 0x67, 0x65, 0x18, - 0x14, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x26, 0x2e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x62, - 0x61, 0x73, 0x65, 0x2e, 0x71, 0x75, 0x65, 0x72, 0x79, 0x2e, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, - 0x31, 0x2e, 0x50, 0x61, 0x67, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x52, 0x04, 0x70, - 0x61, 0x67, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x62, 0x6f, 0x6f, 0x6c, 0x73, 0x18, 0x15, 0x20, 0x03, - 0x28, 0x08, 0x52, 0x05, 0x62, 0x6f, 0x6f, 0x6c, 0x73, 0x12, 0x14, 0x0a, 0x05, 0x75, 0x69, 0x6e, - 0x74, 0x73, 0x18, 0x16, 0x20, 0x03, 0x28, 0x0d, 0x52, 0x05, 0x75, 0x69, 0x6e, 0x74, 0x73, 0x12, - 0x18, 0x0a, 0x07, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x73, 0x18, 0x17, 0x20, 0x03, 0x28, 0x09, - 0x52, 0x07, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x73, 0x12, 0x22, 0x0a, 0x05, 0x65, 0x6e, 0x75, - 0x6d, 0x73, 0x18, 0x18, 0x20, 0x03, 0x28, 0x0e, 0x32, 0x0c, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x70, - 0x62, 0x2e, 0x45, 0x6e, 0x75, 0x6d, 0x52, 0x05, 0x65, 0x6e, 0x75, 0x6d, 0x73, 0x12, 0x37, 0x0a, - 0x09, 0x64, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0x19, 0x20, 0x03, 0x28, 0x0b, - 0x32, 0x19, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, - 0x75, 0x66, 0x2e, 0x44, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x09, 0x64, 0x75, 0x72, - 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x35, 0x0a, 0x0d, 0x73, 0x6f, 0x6d, 0x65, 0x5f, 0x6d, - 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x73, 0x18, 0x1a, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x10, 0x2e, - 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x2e, 0x41, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x52, - 0x0c, 0x73, 0x6f, 0x6d, 0x65, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x73, 0x12, 0x20, 0x0a, - 0x0b, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x61, 0x6c, 0x31, 0x18, 0x1b, 0x20, 0x01, - 0x28, 0x05, 0x52, 0x0b, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x61, 0x6c, 0x31, 0x12, - 0x20, 0x0a, 0x0b, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x61, 0x6c, 0x32, 0x18, 0x1c, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x61, 0x6c, - 0x32, 0x12, 0x4a, 0x0a, 0x13, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x61, 0x6c, 0x33, - 0x5f, 0x76, 0x61, 0x72, 0x61, 0x72, 0x67, 0x73, 0x18, 0x1d, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x19, - 0x2e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x76, 0x31, 0x62, - 0x65, 0x74, 0x61, 0x31, 0x2e, 0x43, 0x6f, 0x69, 0x6e, 0x52, 0x12, 0x70, 0x6f, 0x73, 0x69, 0x74, - 0x69, 0x6f, 0x6e, 0x61, 0x6c, 0x33, 0x56, 0x61, 0x72, 0x61, 0x72, 0x67, 0x73, 0x12, 0x29, 0x0a, - 0x10, 0x64, 0x65, 0x70, 0x72, 0x65, 0x63, 0x61, 0x74, 0x65, 0x64, 0x5f, 0x66, 0x69, 0x65, 0x6c, - 0x64, 0x18, 0x1e, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0f, 0x64, 0x65, 0x70, 0x72, 0x65, 0x63, 0x61, - 0x74, 0x65, 0x64, 0x46, 0x69, 0x65, 0x6c, 0x64, 0x12, 0x3c, 0x0a, 0x1a, 0x73, 0x68, 0x6f, 0x72, - 0x74, 0x68, 0x61, 0x6e, 0x64, 0x5f, 0x64, 0x65, 0x70, 0x72, 0x65, 0x63, 0x61, 0x74, 0x65, 0x64, - 0x5f, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x18, 0x1f, 0x20, 0x01, 0x28, 0x09, 0x52, 0x18, 0x73, 0x68, - 0x6f, 0x72, 0x74, 0x68, 0x61, 0x6e, 0x64, 0x44, 0x65, 0x70, 0x72, 0x65, 0x63, 0x61, 0x74, 0x65, - 0x64, 0x46, 0x69, 0x65, 0x6c, 0x64, 0x12, 0x1f, 0x0a, 0x0b, 0x68, 0x69, 0x64, 0x64, 0x65, 0x6e, - 0x5f, 0x62, 0x6f, 0x6f, 0x6c, 0x18, 0x20, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0a, 0x68, 0x69, 0x64, - 0x64, 0x65, 0x6e, 0x42, 0x6f, 0x6f, 0x6c, 0x12, 0x54, 0x0a, 0x11, 0x6d, 0x61, 0x70, 0x5f, 0x73, - 0x74, 0x72, 0x69, 0x6e, 0x67, 0x5f, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x18, 0x21, 0x20, 0x03, - 0x28, 0x0b, 0x32, 0x28, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x2e, 0x45, 0x63, 0x68, 0x6f, - 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x2e, 0x4d, 0x61, 0x70, 0x53, 0x74, 0x72, 0x69, 0x6e, - 0x67, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x0f, 0x6d, 0x61, - 0x70, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x12, 0x54, 0x0a, - 0x11, 0x6d, 0x61, 0x70, 0x5f, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x5f, 0x75, 0x69, 0x6e, 0x74, - 0x33, 0x32, 0x18, 0x22, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x28, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x70, - 0x62, 0x2e, 0x45, 0x63, 0x68, 0x6f, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x2e, 0x4d, 0x61, - 0x70, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x55, 0x69, 0x6e, 0x74, 0x33, 0x32, 0x45, 0x6e, 0x74, - 0x72, 0x79, 0x52, 0x0f, 0x6d, 0x61, 0x70, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x55, 0x69, 0x6e, - 0x74, 0x33, 0x32, 0x12, 0x4e, 0x0a, 0x0f, 0x6d, 0x61, 0x70, 0x5f, 0x73, 0x74, 0x72, 0x69, 0x6e, - 0x67, 0x5f, 0x63, 0x6f, 0x69, 0x6e, 0x18, 0x23, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x26, 0x2e, 0x74, - 0x65, 0x73, 0x74, 0x70, 0x62, 0x2e, 0x45, 0x63, 0x68, 0x6f, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, - 0x74, 0x2e, 0x4d, 0x61, 0x70, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x43, 0x6f, 0x69, 0x6e, 0x45, - 0x6e, 0x74, 0x72, 0x79, 0x52, 0x0d, 0x6d, 0x61, 0x70, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x43, - 0x6f, 0x69, 0x6e, 0x12, 0x51, 0x0a, 0x13, 0x61, 0x5f, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, - 0x6f, 0x72, 0x5f, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, 0x24, 0x20, 0x01, 0x28, 0x09, - 0x42, 0x21, 0xd2, 0xb4, 0x2d, 0x1d, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x56, 0x61, 0x6c, - 0x69, 0x64, 0x61, 0x74, 0x6f, 0x72, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x53, 0x74, 0x72, - 0x69, 0x6e, 0x67, 0x52, 0x11, 0x61, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x6f, 0x72, 0x41, - 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x12, 0x51, 0x0a, 0x13, 0x61, 0x5f, 0x63, 0x6f, 0x6e, 0x73, - 0x65, 0x6e, 0x73, 0x75, 0x73, 0x5f, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, 0x25, 0x20, - 0x01, 0x28, 0x09, 0x42, 0x21, 0xd2, 0xb4, 0x2d, 0x1d, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, - 0x43, 0x6f, 0x6e, 0x73, 0x65, 0x6e, 0x73, 0x75, 0x73, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, - 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x52, 0x11, 0x61, 0x43, 0x6f, 0x6e, 0x73, 0x65, 0x6e, 0x73, - 0x75, 0x73, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x12, 0x2f, 0x0a, 0x05, 0x63, 0x6f, 0x69, - 0x6e, 0x73, 0x18, 0x26, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, - 0x73, 0x2e, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x2e, 0x43, - 0x6f, 0x69, 0x6e, 0x52, 0x05, 0x63, 0x6f, 0x69, 0x6e, 0x73, 0x1a, 0x42, 0x0a, 0x14, 0x4d, 0x61, - 0x70, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x45, 0x6e, 0x74, - 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x1a, 0x42, - 0x0a, 0x14, 0x4d, 0x61, 0x70, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x55, 0x69, 0x6e, 0x74, 0x33, - 0x32, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, - 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, - 0x38, 0x01, 0x1a, 0x5b, 0x0a, 0x12, 0x4d, 0x61, 0x70, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x43, - 0x6f, 0x69, 0x6e, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x2f, 0x0a, 0x05, 0x76, 0x61, - 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x63, 0x6f, 0x73, 0x6d, - 0x6f, 0x73, 0x2e, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x2e, - 0x43, 0x6f, 0x69, 0x6e, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, - 0x3d, 0x0a, 0x0c, 0x45, 0x63, 0x68, 0x6f, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, - 0x2d, 0x0a, 0x07, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, - 0x32, 0x13, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x2e, 0x45, 0x63, 0x68, 0x6f, 0x52, 0x65, - 0x71, 0x75, 0x65, 0x73, 0x74, 0x52, 0x07, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x2a, 0x64, - 0x0a, 0x04, 0x45, 0x6e, 0x75, 0x6d, 0x12, 0x14, 0x0a, 0x10, 0x45, 0x4e, 0x55, 0x4d, 0x5f, 0x55, - 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, 0x00, 0x12, 0x0c, 0x0a, 0x08, - 0x45, 0x4e, 0x55, 0x4d, 0x5f, 0x4f, 0x4e, 0x45, 0x10, 0x01, 0x12, 0x0c, 0x0a, 0x08, 0x45, 0x4e, - 0x55, 0x4d, 0x5f, 0x54, 0x57, 0x4f, 0x10, 0x02, 0x12, 0x0d, 0x0a, 0x09, 0x45, 0x4e, 0x55, 0x4d, - 0x5f, 0x46, 0x49, 0x56, 0x45, 0x10, 0x05, 0x12, 0x1b, 0x0a, 0x0e, 0x45, 0x4e, 0x55, 0x4d, 0x5f, - 0x4e, 0x45, 0x47, 0x5f, 0x54, 0x48, 0x52, 0x45, 0x45, 0x10, 0xfd, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0x01, 0x32, 0x3a, 0x0a, 0x05, 0x51, 0x75, 0x65, 0x72, 0x79, 0x12, 0x31, 0x0a, - 0x04, 0x45, 0x63, 0x68, 0x6f, 0x12, 0x13, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x2e, 0x45, - 0x63, 0x68, 0x6f, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x14, 0x2e, 0x74, 0x65, 0x73, - 0x74, 0x70, 0x62, 0x2e, 0x45, 0x63, 0x68, 0x6f, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, - 0x42, 0x88, 0x01, 0x0a, 0x0a, 0x63, 0x6f, 0x6d, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x42, - 0x0a, 0x51, 0x75, 0x65, 0x72, 0x79, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x36, 0x67, - 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, - 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2d, 0x73, 0x64, 0x6b, 0x2f, 0x63, 0x6c, 0x69, 0x65, - 0x6e, 0x74, 0x2f, 0x76, 0x32, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x74, - 0x65, 0x73, 0x74, 0x70, 0x62, 0xa2, 0x02, 0x03, 0x54, 0x58, 0x58, 0xaa, 0x02, 0x06, 0x54, 0x65, - 0x73, 0x74, 0x70, 0x62, 0xca, 0x02, 0x06, 0x54, 0x65, 0x73, 0x74, 0x70, 0x62, 0xe2, 0x02, 0x12, - 0x54, 0x65, 0x73, 0x74, 0x70, 0x62, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, - 0x74, 0x61, 0xea, 0x02, 0x06, 0x54, 0x65, 0x73, 0x74, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x33, -} - -var ( - file_testpb_query_proto_rawDescOnce sync.Once - file_testpb_query_proto_rawDescData = file_testpb_query_proto_rawDesc -) - -func file_testpb_query_proto_rawDescGZIP() []byte { - file_testpb_query_proto_rawDescOnce.Do(func() { - file_testpb_query_proto_rawDescData = protoimpl.X.CompressGZIP(file_testpb_query_proto_rawDescData) - }) - return file_testpb_query_proto_rawDescData -} - -var file_testpb_query_proto_enumTypes = make([]protoimpl.EnumInfo, 1) -var file_testpb_query_proto_msgTypes = make([]protoimpl.MessageInfo, 6) -var file_testpb_query_proto_goTypes = []interface{}{ - (Enum)(0), // 0: testpb.Enum - (*AMessage)(nil), // 1: testpb.AMessage - (*EchoRequest)(nil), // 2: testpb.EchoRequest - (*EchoResponse)(nil), // 3: testpb.EchoResponse - nil, // 4: testpb.EchoRequest.MapStringStringEntry - nil, // 5: testpb.EchoRequest.MapStringUint32Entry - nil, // 6: testpb.EchoRequest.MapStringCoinEntry - (*timestamppb.Timestamp)(nil), // 7: google.protobuf.Timestamp - (*durationpb.Duration)(nil), // 8: google.protobuf.Duration - (*v1beta1.Coin)(nil), // 9: cosmos.base.v1beta1.Coin - (*v1beta11.PageRequest)(nil), // 10: cosmos.base.query.v1beta1.PageRequest -} -var file_testpb_query_proto_depIdxs = []int32{ - 7, // 0: testpb.EchoRequest.timestamp:type_name -> google.protobuf.Timestamp - 8, // 1: testpb.EchoRequest.duration:type_name -> google.protobuf.Duration - 0, // 2: testpb.EchoRequest.an_enum:type_name -> testpb.Enum - 1, // 3: testpb.EchoRequest.a_message:type_name -> testpb.AMessage - 9, // 4: testpb.EchoRequest.a_coin:type_name -> cosmos.base.v1beta1.Coin - 10, // 5: testpb.EchoRequest.page:type_name -> cosmos.base.query.v1beta1.PageRequest - 0, // 6: testpb.EchoRequest.enums:type_name -> testpb.Enum - 8, // 7: testpb.EchoRequest.durations:type_name -> google.protobuf.Duration - 1, // 8: testpb.EchoRequest.some_messages:type_name -> testpb.AMessage - 9, // 9: testpb.EchoRequest.positional3_varargs:type_name -> cosmos.base.v1beta1.Coin - 4, // 10: testpb.EchoRequest.map_string_string:type_name -> testpb.EchoRequest.MapStringStringEntry - 5, // 11: testpb.EchoRequest.map_string_uint32:type_name -> testpb.EchoRequest.MapStringUint32Entry - 6, // 12: testpb.EchoRequest.map_string_coin:type_name -> testpb.EchoRequest.MapStringCoinEntry - 9, // 13: testpb.EchoRequest.coins:type_name -> cosmos.base.v1beta1.Coin - 2, // 14: testpb.EchoResponse.request:type_name -> testpb.EchoRequest - 9, // 15: testpb.EchoRequest.MapStringCoinEntry.value:type_name -> cosmos.base.v1beta1.Coin - 2, // 16: testpb.Query.Echo:input_type -> testpb.EchoRequest - 3, // 17: testpb.Query.Echo:output_type -> testpb.EchoResponse - 17, // [17:18] is the sub-list for method output_type - 16, // [16:17] is the sub-list for method input_type - 16, // [16:16] is the sub-list for extension type_name - 16, // [16:16] is the sub-list for extension extendee - 0, // [0:16] is the sub-list for field type_name -} - -func init() { file_testpb_query_proto_init() } -func file_testpb_query_proto_init() { - if File_testpb_query_proto != nil { - return - } - if !protoimpl.UnsafeEnabled { - file_testpb_query_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*AMessage); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_testpb_query_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*EchoRequest); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_testpb_query_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*EchoResponse); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - } - type x struct{} - out := protoimpl.TypeBuilder{ - File: protoimpl.DescBuilder{ - GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_testpb_query_proto_rawDesc, - NumEnums: 1, - NumMessages: 6, - NumExtensions: 0, - NumServices: 1, - }, - GoTypes: file_testpb_query_proto_goTypes, - DependencyIndexes: file_testpb_query_proto_depIdxs, - EnumInfos: file_testpb_query_proto_enumTypes, - MessageInfos: file_testpb_query_proto_msgTypes, - }.Build() - File_testpb_query_proto = out.File - file_testpb_query_proto_rawDesc = nil - file_testpb_query_proto_goTypes = nil - file_testpb_query_proto_depIdxs = nil -} diff --git a/connect/internal/testpb/query_grpc.pb.go b/connect/internal/testpb/query_grpc.pb.go deleted file mode 100644 index 7b31c042..00000000 --- a/connect/internal/testpb/query_grpc.pb.go +++ /dev/null @@ -1,123 +0,0 @@ -// Code generated by protoc-gen-go-grpc. DO NOT EDIT. -// versions: -// - protoc-gen-go-grpc v1.5.1 -// - protoc (unknown) -// source: testpb/query.proto - -package testpb - -import ( - context "context" - grpc "google.golang.org/grpc" - codes "google.golang.org/grpc/codes" - status "google.golang.org/grpc/status" -) - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the grpc package it is being compiled against. -// Requires gRPC-Go v1.64.0 or later. -const _ = grpc.SupportPackageIsVersion9 - -const ( - Query_Echo_FullMethodName = "/testpb.Query/Echo" -) - -// QueryClient is the client API for Query service. -// -// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. -type QueryClient interface { - // Echo returns the request in the response - Echo(ctx context.Context, in *EchoRequest, opts ...grpc.CallOption) (*EchoResponse, error) -} - -type queryClient struct { - cc grpc.ClientConnInterface -} - -func NewQueryClient(cc grpc.ClientConnInterface) QueryClient { - return &queryClient{cc} -} - -func (c *queryClient) Echo(ctx context.Context, in *EchoRequest, opts ...grpc.CallOption) (*EchoResponse, error) { - cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) - out := new(EchoResponse) - err := c.cc.Invoke(ctx, Query_Echo_FullMethodName, in, out, cOpts...) - if err != nil { - return nil, err - } - return out, nil -} - -// QueryServer is the server API for Query service. -// All implementations must embed UnimplementedQueryServer -// for forward compatibility. -type QueryServer interface { - // Echo returns the request in the response - Echo(context.Context, *EchoRequest) (*EchoResponse, error) - mustEmbedUnimplementedQueryServer() -} - -// UnimplementedQueryServer must be embedded to have -// forward compatible implementations. -// -// NOTE: this should be embedded by value instead of pointer to avoid a nil -// pointer dereference when methods are called. -type UnimplementedQueryServer struct{} - -func (UnimplementedQueryServer) Echo(context.Context, *EchoRequest) (*EchoResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method Echo not implemented") -} -func (UnimplementedQueryServer) mustEmbedUnimplementedQueryServer() {} -func (UnimplementedQueryServer) testEmbeddedByValue() {} - -// UnsafeQueryServer may be embedded to opt out of forward compatibility for this service. -// Use of this interface is not recommended, as added methods to QueryServer will -// result in compilation errors. -type UnsafeQueryServer interface { - mustEmbedUnimplementedQueryServer() -} - -func RegisterQueryServer(s grpc.ServiceRegistrar, srv QueryServer) { - // If the following call pancis, it indicates UnimplementedQueryServer was - // embedded by pointer and is nil. This will cause panics if an - // unimplemented method is ever invoked, so we test this at initialization - // time to prevent it from happening at runtime later due to I/O. - if t, ok := srv.(interface{ testEmbeddedByValue() }); ok { - t.testEmbeddedByValue() - } - s.RegisterService(&Query_ServiceDesc, srv) -} - -func _Query_Echo_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(EchoRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(QueryServer).Echo(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: Query_Echo_FullMethodName, - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(QueryServer).Echo(ctx, req.(*EchoRequest)) - } - return interceptor(ctx, in, info, handler) -} - -// Query_ServiceDesc is the grpc.ServiceDesc for Query service. -// It's only intended for direct use with grpc.RegisterService, -// and not to be introspected or modified (even as a copy) -var Query_ServiceDesc = grpc.ServiceDesc{ - ServiceName: "testpb.Query", - HandlerType: (*QueryServer)(nil), - Methods: []grpc.MethodDesc{ - { - MethodName: "Echo", - Handler: _Query_Echo_Handler, - }, - }, - Streams: []grpc.StreamDesc{}, - Metadata: "testpb/query.proto", -} diff --git a/connect/internal/tx/README.md b/connect/internal/tx/README.md deleted file mode 100644 index 6d196b1e..00000000 --- a/connect/internal/tx/README.md +++ /dev/null @@ -1,465 +0,0 @@ -The tx package provides a robust set of tools for building, signing, and managing transactions in a Cosmos SDK-based blockchain application. - -## Overview - -This package includes several key components: - -1. Transaction Factory -2. Transaction Config -3. Transaction Encoder/Decoder -4. Signature Handling - -## Architecture - -```mermaid -graph TD - A[Client] --> B[Factory] - B --> D[TxConfig] - D --> E[TxEncodingConfig] - D --> F[TxSigningConfig] - B --> G[Tx] - G --> H[Encoder] - G --> I[Decoder] - F --> J[SignModeHandler] - F --> K[SigningContext] - B --> L[AuxTxBuilder] -``` - -## Key Components - -### TxConfig - -`TxConfig` provides configuration for transaction handling, including: - -- Encoding and decoding -- Sign mode handling -- Signature JSON marshaling/unmarshaling - -```mermaid -classDiagram - class TxConfig { - <> - TxEncodingConfig - TxSigningConfig - } - - class TxEncodingConfig { - <> - TxEncoder() txEncoder - TxDecoder() txDecoder - TxJSONEncoder() txEncoder - TxJSONDecoder() txDecoder - Decoder() Decoder - } - - class TxSigningConfig { - <> - SignModeHandler() *signing.HandlerMap - SigningContext() *signing.Context - MarshalSignatureJSON([]Signature) ([]byte, error) - UnmarshalSignatureJSON([]byte) ([]Signature, error) - } - - class txConfig { - TxEncodingConfig - TxSigningConfig - } - - class defaultEncodingConfig { - cdc codec.BinaryCodec - decoder Decoder - TxEncoder() txEncoder - TxDecoder() txDecoder - TxJSONEncoder() txEncoder - TxJSONDecoder() txDecoder - } - - class defaultTxSigningConfig { - signingCtx *signing.Context - handlerMap *signing.HandlerMap - cdc codec.BinaryCodec - SignModeHandler() *signing.HandlerMap - SigningContext() *signing.Context - MarshalSignatureJSON([]Signature) ([]byte, error) - UnmarshalSignatureJSON([]byte) ([]Signature, error) - } - - TxConfig <|-- txConfig - TxEncodingConfig <|.. defaultEncodingConfig - TxSigningConfig <|.. defaultTxSigningConfig - txConfig *-- defaultEncodingConfig - txConfig *-- defaultTxSigningConfig -``` - -### Factory - -The `Factory` is the main entry point for creating and managing transactions. It handles: - -- Account preparation -- Gas calculation -- Unsigned transaction building -- Transaction signing -- Transaction simulation -- Transaction broadcasting - -```mermaid -classDiagram - class Factory { - keybase keyring.Keyring - cdc codec.BinaryCodec - accountRetriever account.AccountRetriever - ac address.Codec - conn gogogrpc.ClientConn - txConfig TxConfig - txParams TxParameters - tx txState - - NewFactory(keybase, cdc, accRetriever, txConfig, ac, conn, parameters) Factory - Prepare() error - BuildUnsignedTx(msgs ...sdk.Msg) error - BuildsSignedTx(ctx context.Context, msgs ...sdk.Msg) (Tx, error) - calculateGas(msgs ...sdk.Msg) error - Simulate(msgs ...sdk.Msg) (*apitx.SimulateResponse, uint64, error) - UnsignedTxString(msgs ...sdk.Msg) (string, error) - BuildSimTx(msgs ...sdk.Msg) ([]byte, error) - sign(ctx context.Context, overwriteSig bool) (Tx, error) - WithGas(gas uint64) - WithSequence(sequence uint64) - WithAccountNumber(accnum uint64) - getTx() (Tx, error) - getFee() (*apitx.Fee, error) - getSigningTxData() (signing.TxData, error) - setSignatures(...Signature) error - } - - class TxParameters { - <> - chainID string - AccountConfig - GasConfig - FeeConfig - SignModeConfig - TimeoutConfig - MemoConfig - } - - class TxConfig { - <> - } - - class Tx { - <> - } - - class txState { - <> - msgs []sdk.Msg - memo string - fees []*base.Coin - gasLimit uint64 - feeGranter []byte - feePayer []byte - timeoutHeight uint64 - unordered bool - timeoutTimestamp uint64 - signatures []Signature - signerInfos []*apitx.SignerInfo - } - - Factory *-- TxParameters - Factory *-- TxConfig - Factory *-- txState - Factory ..> Tx : creates -``` - -### Encoder/Decoder - -The package includes functions for encoding and decoding transactions in both binary and JSON formats. - -```mermaid -classDiagram - class Decoder { - <> - Decode(txBytes []byte) (*txdecode.DecodedTx, error) - } - - class txDecoder { - <> - decode(txBytes []byte) (Tx, error) - } - - class txEncoder { - <> - encode(tx Tx) ([]byte, error) - } - - class EncoderUtils { - <> - decodeTx(cdc codec.BinaryCodec, decoder Decoder) txDecoder - encodeTx(tx Tx) ([]byte, error) - decodeJsonTx(cdc codec.BinaryCodec, decoder Decoder) txDecoder - encodeJsonTx(tx Tx) ([]byte, error) - protoTxBytes(tx *txv1beta1.Tx) ([]byte, error) - } - - class MarshalOptions { - <> - Deterministic bool - } - - class JSONMarshalOptions { - <> - Indent string - UseProtoNames bool - UseEnumNumbers bool - } - - Decoder <.. EncoderUtils : uses - txDecoder <.. EncoderUtils : creates - txEncoder <.. EncoderUtils : implements - EncoderUtils ..> MarshalOptions : uses - EncoderUtils ..> JSONMarshalOptions : uses -``` - -### Sequence Diagrams - -#### Generate Aux Signer Data -```mermaid -sequenceDiagram - participant User - participant GenerateOrBroadcastTxCLI - participant generateAuxSignerData - participant makeAuxSignerData - participant AuxTxBuilder - participant ctx.PrintProto - - User->>GenerateOrBroadcastTxCLI: Call with isAux flag - GenerateOrBroadcastTxCLI->>generateAuxSignerData: Call - - generateAuxSignerData->>makeAuxSignerData: Call - makeAuxSignerData->>AuxTxBuilder: NewAuxTxBuilder() - - makeAuxSignerData->>AuxTxBuilder: SetAddress(f.txParams.fromAddress) - - alt f.txParams.offline - makeAuxSignerData->>AuxTxBuilder: SetAccountNumber(f.AccountNumber()) - makeAuxSignerData->>AuxTxBuilder: SetSequence(f.Sequence()) - else - makeAuxSignerData->>f.accountRetriever: GetAccountNumberSequence() - makeAuxSignerData->>AuxTxBuilder: SetAccountNumber(accNum) - makeAuxSignerData->>AuxTxBuilder: SetSequence(seq) - end - - makeAuxSignerData->>AuxTxBuilder: SetMsgs(msgs...) - makeAuxSignerData->>AuxTxBuilder: SetSignMode(f.SignMode()) - - makeAuxSignerData->>f.keybase: GetPubKey(f.txParams.fromName) - makeAuxSignerData->>AuxTxBuilder: SetPubKey(pubKey) - - makeAuxSignerData->>AuxTxBuilder: SetChainID(f.txParams.chainID) - makeAuxSignerData->>AuxTxBuilder: GetSignBytes() - - makeAuxSignerData->>f.keybase: Sign(f.txParams.fromName, signBz, f.SignMode()) - makeAuxSignerData->>AuxTxBuilder: SetSignature(sig) - - makeAuxSignerData->>AuxTxBuilder: GetAuxSignerData() - AuxTxBuilder-->>makeAuxSignerData: Return AuxSignerData - makeAuxSignerData-->>generateAuxSignerData: Return AuxSignerData - - generateAuxSignerData->>ctx.PrintProto: Print AuxSignerData - ctx.PrintProto-->>GenerateOrBroadcastTxCLI: Return result - GenerateOrBroadcastTxCLI-->>User: Return result -``` - -#### Generate Only -```mermaid -sequenceDiagram - participant User - participant GenerateOrBroadcastTxCLI - participant generateOnly - participant Factory - participant ctx.PrintString - - User->>GenerateOrBroadcastTxCLI: Call with generateOnly flag - GenerateOrBroadcastTxCLI->>generateOnly: Call - - generateOnly->>Factory: Prepare() - alt Error in Prepare - Factory-->>generateOnly: Return error - generateOnly-->>GenerateOrBroadcastTxCLI: Return error - GenerateOrBroadcastTxCLI-->>User: Return error - end - - generateOnly->>Factory: UnsignedTxString(msgs...) - Factory->>Factory: BuildUnsignedTx(msgs...) - Factory->>Factory: setMsgs(msgs...) - Factory->>Factory: setMemo(f.txParams.memo) - Factory->>Factory: setFees(f.txParams.gasPrices) - Factory->>Factory: setGasLimit(f.txParams.gas) - Factory->>Factory: setFeeGranter(f.txParams.feeGranter) - Factory->>Factory: setFeePayer(f.txParams.feePayer) - Factory->>Factory: setTimeoutHeight(f.txParams.timeoutHeight) - - Factory->>Factory: getTx() - Factory->>Factory: txConfig.TxJSONEncoder() - Factory->>Factory: encoder(tx) - - Factory-->>generateOnly: Return unsigned tx string - generateOnly->>ctx.PrintString: Print unsigned tx string - ctx.PrintString-->>generateOnly: Return result - generateOnly-->>GenerateOrBroadcastTxCLI: Return result - GenerateOrBroadcastTxCLI-->>User: Return result -``` - -#### DryRun -```mermaid -sequenceDiagram - participant User - participant GenerateOrBroadcastTxCLI - participant dryRun - participant Factory - participant os.Stderr - - User->>GenerateOrBroadcastTxCLI: Call with dryRun flag - GenerateOrBroadcastTxCLI->>dryRun: Call - - dryRun->>Factory: Prepare() - alt Error in Prepare - Factory-->>dryRun: Return error - dryRun-->>GenerateOrBroadcastTxCLI: Return error - GenerateOrBroadcastTxCLI-->>User: Return error - end - - dryRun->>Factory: Simulate(msgs...) - Factory->>Factory: BuildSimTx(msgs...) - Factory->>Factory: BuildUnsignedTx(msgs...) - Factory->>Factory: getSimPK() - Factory->>Factory: getSimSignatureData(pk) - Factory->>Factory: setSignatures(sig) - Factory->>Factory: getTx() - Factory->>Factory: txConfig.TxEncoder()(tx) - - Factory->>ServiceClient: Simulate(context.Background(), &apitx.SimulateRequest{}) - ServiceClient->>Factory: Return result - - Factory-->>dryRun: Return (simulation, gas, error) - alt Error in Simulate - dryRun-->>GenerateOrBroadcastTxCLI: Return error - GenerateOrBroadcastTxCLI-->>User: Return error - end - - dryRun->>os.Stderr: Fprintf(GasEstimateResponse{GasEstimate: gas}) - os.Stderr-->>dryRun: Return result - dryRun-->>GenerateOrBroadcastTxCLI: Return result - GenerateOrBroadcastTxCLI-->>User: Return result -``` - -#### Generate and Broadcast Tx -```mermaid -sequenceDiagram - participant User - participant GenerateOrBroadcastTxCLI - participant BroadcastTx - participant Factory - participant clientCtx - - User->>GenerateOrBroadcastTxCLI: Call - GenerateOrBroadcastTxCLI->>BroadcastTx: Call - - BroadcastTx->>Factory: Prepare() - alt Error in Prepare - Factory-->>BroadcastTx: Return error - BroadcastTx-->>GenerateOrBroadcastTxCLI: Return error - GenerateOrBroadcastTxCLI-->>User: Return error - end - - alt SimulateAndExecute is true - BroadcastTx->>Factory: calculateGas(msgs...) - Factory->>Factory: Simulate(msgs...) - Factory->>Factory: WithGas(adjusted) - end - - BroadcastTx->>Factory: BuildUnsignedTx(msgs...) - Factory->>Factory: setMsgs(msgs...) - Factory->>Factory: setMemo(f.txParams.memo) - Factory->>Factory: setFees(f.txParams.gasPrices) - Factory->>Factory: setGasLimit(f.txParams.gas) - Factory->>Factory: setFeeGranter(f.txParams.feeGranter) - Factory->>Factory: setFeePayer(f.txParams.feePayer) - Factory->>Factory: setTimeoutHeight(f.txParams.timeoutHeight) - - alt !clientCtx.SkipConfirm - BroadcastTx->>Factory: getTx() - BroadcastTx->>Factory: txConfig.TxJSONEncoder() - BroadcastTx->>clientCtx: PrintRaw(txBytes) - BroadcastTx->>clientCtx: Input.GetConfirmation() - alt Not confirmed - BroadcastTx-->>GenerateOrBroadcastTxCLI: Return error - GenerateOrBroadcastTxCLI-->>User: Return error - end - end - - BroadcastTx->>Factory: BuildsSignedTx(ctx, msgs...) - Factory->>Factory: sign(ctx, true) - Factory->>Factory: keybase.GetPubKey(fromName) - Factory->>Factory: getSignBytesAdapter() - Factory->>Factory: keybase.Sign(fromName, bytesToSign, signMode) - Factory->>Factory: setSignatures(sig) - Factory->>Factory: getTx() - - BroadcastTx->>Factory: txConfig.TxEncoder() - BroadcastTx->>clientCtx: BroadcastTx(txBytes) - - alt Error in BroadcastTx - clientCtx-->>BroadcastTx: Return error - BroadcastTx-->>GenerateOrBroadcastTxCLI: Return error - GenerateOrBroadcastTxCLI-->>User: Return error - end - - BroadcastTx->>clientCtx: OutputTx(res) - clientCtx-->>BroadcastTx: Return result - BroadcastTx-->>GenerateOrBroadcastTxCLI: Return result - GenerateOrBroadcastTxCLI-->>User: Return result -``` - -## Usage - -To use the `tx` package, typically you would: - -1. Create a `Factory` -2. Simulate the transaction (optional) -3. Build a signed transaction -4. Encode the transaction -5. Broadcast the transaction - -Here's a simplified example: - -```go -// Create a Factory -factory, err := NewFactory(keybase, cdc, accountRetriever, txConfig, addressCodec, conn, txParameters) -if err != nil { - return err -} - -// Simulate the transaction (optional) -simRes, gas, err := factory.Simulate(msgs...) -if err != nil { - return err -} -factory.WithGas(gas) - -// Build a signed transaction -signedTx, err := factory.BuildsSignedTx(context.Background(), msgs...) -if err != nil { - return err -} - -// Encode the transaction -txBytes, err := factory.txConfig.TxEncoder()(signedTx) -if err != nil { - return err -} - -// Broadcast the transaction -// (This step depends on your specific client implementation) -``` \ No newline at end of file diff --git a/connect/internal/tx/broadcaster.go b/connect/internal/tx/broadcaster.go deleted file mode 100644 index 7f871d5e..00000000 --- a/connect/internal/tx/broadcaster.go +++ /dev/null @@ -1,15 +0,0 @@ -package tx - -import "context" - -// Broadcaster defines an interface for broadcasting transactions to the consensus engine. -type Broadcaster interface { - // Broadcast sends a transaction to the network and returns the result. - // - // It returns a byte slice containing the formatted result that will be - // passed to the output writer, and an error if the broadcast failed. - Broadcast(ctx context.Context, txBytes []byte) ([]byte, error) - - // Consensus returns the consensus engine identifier for this Broadcaster. - Consensus() string -} diff --git a/connect/internal/tx/comet_broadcaster.go b/connect/internal/tx/comet_broadcaster.go deleted file mode 100644 index a66a7802..00000000 --- a/connect/internal/tx/comet_broadcaster.go +++ /dev/null @@ -1,196 +0,0 @@ -package tx - -import ( - "context" - "encoding/json" - "errors" - "fmt" - "strings" - - "github.com/cometbft/cometbft/mempool" - rpcclient "github.com/cometbft/cometbft/rpc/client" - rpchttp "github.com/cometbft/cometbft/rpc/client/http" - coretypes "github.com/cometbft/cometbft/rpc/core/types" - cmttypes "github.com/cometbft/cometbft/types" - - apiacbci "cosmossdk.io/api/cosmos/base/abci/v1beta1" - - "github.com/cosmos/cosmos-sdk/codec" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" -) - -const ( - // BroadcastSync defines a tx broadcasting mode where the client waits for - // a CheckTx execution response only. - BroadcastSync = "sync" - // BroadcastAsync defines a tx broadcasting mode where the client returns - // immediately. - BroadcastAsync = "async" - - // cometBftConsensus is the identifier for the CometBFT consensus engine. - cometBFTConsensus = "comet" -) - -// CometRPC defines the interface of a CometBFT RPC client needed for -// queries and transaction handling. -type CometRPC interface { - rpcclient.ABCIClient - - Validators(ctx context.Context, height *int64, page, perPage *int) (*coretypes.ResultValidators, error) - Status(context.Context) (*coretypes.ResultStatus, error) - Block(ctx context.Context, height *int64) (*coretypes.ResultBlock, error) - BlockByHash(ctx context.Context, hash []byte) (*coretypes.ResultBlock, error) - BlockResults(ctx context.Context, height *int64) (*coretypes.ResultBlockResults, error) - BlockchainInfo(ctx context.Context, minHeight, maxHeight int64) (*coretypes.ResultBlockchainInfo, error) - Commit(ctx context.Context, height *int64) (*coretypes.ResultCommit, error) - Tx(ctx context.Context, hash []byte, prove bool) (*coretypes.ResultTx, error) - TxSearch( - ctx context.Context, - query string, - prove bool, - page, perPage *int, - orderBy string, - ) (*coretypes.ResultTxSearch, error) - BlockSearch( - ctx context.Context, - query string, - page, perPage *int, - orderBy string, - ) (*coretypes.ResultBlockSearch, error) -} - -// CometBFTBroadcaster implements the Broadcaster interface for CometBFT consensus engine. -type CometBFTBroadcaster struct { - rpcClient CometRPC - mode string - cdc codec.Codec -} - -// NewCometBFTBroadcaster creates a new CometBFTBroadcaster. -func NewCometBFTBroadcaster(rpcURL, mode string, cdc codec.Codec) (*CometBFTBroadcaster, error) { - if cdc == nil { - return nil, errors.New("codec can't be nil") - } - - if mode == "" { - mode = BroadcastSync - } - - rpcClient, err := rpchttp.New(rpcURL, "/websocket") - if err != nil { - return nil, fmt.Errorf("failed to create CometBft RPC client: %w", err) - } - - return &CometBFTBroadcaster{ - rpcClient: rpcClient, - mode: mode, - cdc: cdc, - }, nil -} - -// Consensus returns the consensus engine name used by the broadcaster. -// It always returns "comet" for CometBFTBroadcaster. -func (c *CometBFTBroadcaster) Consensus() string { - return cometBFTConsensus -} - -// Broadcast sends a transaction to the network and returns the result. -// returns a byte slice containing the JSON-encoded result and an error if the broadcast failed. -func (c *CometBFTBroadcaster) Broadcast(ctx context.Context, txBytes []byte) ([]byte, error) { - if c.cdc == nil { - return []byte{}, fmt.Errorf("JSON codec is not initialized") - } - - var broadcastFunc func(ctx context.Context, tx cmttypes.Tx) (*coretypes.ResultBroadcastTx, error) - switch c.mode { - case BroadcastSync: - broadcastFunc = c.rpcClient.BroadcastTxSync - case BroadcastAsync: - broadcastFunc = c.rpcClient.BroadcastTxAsync - default: - return []byte{}, fmt.Errorf("unknown broadcast mode: %s", c.mode) - } - - res, err := c.broadcast(ctx, txBytes, broadcastFunc) - if err != nil { - return []byte{}, err - } - - return c.cdc.MarshalJSON(res) -} - -// broadcast sends a transaction to the CometBFT network using the provided function. -func (c *CometBFTBroadcaster) broadcast(ctx context.Context, txBytes []byte, - fn func(ctx context.Context, tx cmttypes.Tx) (*coretypes.ResultBroadcastTx, error), -) (*apiacbci.TxResponse, error) { - res, err := fn(ctx, txBytes) - if errRes := checkCometError(err, txBytes); errRes != nil { - return errRes, nil - } - - if res == nil { - return nil, err - } - - parsedLogs, _ := parseABCILogs(res.Log) - return &apiacbci.TxResponse{ - Code: res.Code, - Codespace: res.Codespace, - Data: res.Data.String(), - RawLog: res.Log, - Logs: parsedLogs, - Txhash: res.Hash.String(), - }, err -} - -// checkCometError checks for errors returned by the CometBFT network and returns an appropriate TxResponse. -// It extracts error information and constructs a TxResponse with the error details. -func checkCometError(err error, tx cmttypes.Tx) *apiacbci.TxResponse { - if err == nil { - return nil - } - - errStr := strings.ToLower(err.Error()) - txHash := fmt.Sprintf("%X", tx.Hash()) - - switch { - case strings.Contains(errStr, strings.ToLower(mempool.ErrTxInCache.Error())) || - strings.Contains(errStr, strings.ToLower(sdkerrors.ErrTxInMempoolCache.Error())): - return &apiacbci.TxResponse{ - Code: sdkerrors.ErrTxInMempoolCache.ABCICode(), - Codespace: sdkerrors.ErrTxInMempoolCache.Codespace(), - Txhash: txHash, - } - - case strings.Contains(errStr, "mempool is full"): - return &apiacbci.TxResponse{ - Code: sdkerrors.ErrMempoolIsFull.ABCICode(), - Codespace: sdkerrors.ErrMempoolIsFull.Codespace(), - Txhash: txHash, - } - - case strings.Contains(errStr, "tx too large"): - return &apiacbci.TxResponse{ - Code: sdkerrors.ErrTxTooLarge.ABCICode(), - Codespace: sdkerrors.ErrTxTooLarge.Codespace(), - Txhash: txHash, - } - - case strings.Contains(errStr, "no signatures supplied"): - return &apiacbci.TxResponse{ - Code: sdkerrors.ErrNoSignatures.ABCICode(), - Codespace: sdkerrors.ErrNoSignatures.Codespace(), - Txhash: txHash, - } - - default: - return nil - } -} - -// parseABCILogs attempts to parse a stringified ABCI tx log into a slice of -// ABCIMessageLog types. It returns an error upon JSON decoding failure. -func parseABCILogs(logs string) (res []*apiacbci.ABCIMessageLog, err error) { - err = json.Unmarshal([]byte(logs), &res) - return res, err -} diff --git a/connect/internal/tx/comet_client_conn.go b/connect/internal/tx/comet_client_conn.go deleted file mode 100644 index 93f5b4f3..00000000 --- a/connect/internal/tx/comet_client_conn.go +++ /dev/null @@ -1,146 +0,0 @@ -package tx - -import ( - "context" - "errors" - "strconv" - - abci "github.com/cometbft/cometbft/abci/types" - rpcclient "github.com/cometbft/cometbft/rpc/client" - gogogrpc "github.com/cosmos/gogoproto/grpc" - "google.golang.org/grpc" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/encoding" - "google.golang.org/grpc/metadata" - "google.golang.org/grpc/status" - - errorsmod "cosmossdk.io/errors" - - "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/codec/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" -) - -const grpcBlockHeightHeader = "x-cosmos-block-height" - -var ( - _ gogogrpc.ClientConn = &CometBFTBroadcaster{} - _ grpc.ClientConnInterface = &CometBFTBroadcaster{} -) - -func (c *CometBFTBroadcaster) NewStream(_ context.Context, _ *grpc.StreamDesc, _ string, _ ...grpc.CallOption) (grpc.ClientStream, error) { - return nil, errors.New("not implemented") -} - -// Invoke implements the gRPC ClientConn interface by forwarding the RPC call to CometBFT's ABCI Query. -// It marshals the request, sends it as an ABCI query, and unmarshals the response. -func (c *CometBFTBroadcaster) Invoke(ctx context.Context, method string, req, reply interface{}, opts ...grpc.CallOption) (err error) { - reqBz, err := c.getRPCCodec().Marshal(req) - if err != nil { - return err - } - - // parse height header - md, _ := metadata.FromOutgoingContext(ctx) - var height int64 - if heights := md.Get(grpcBlockHeightHeader); len(heights) > 0 { - height, err = strconv.ParseInt(heights[0], 10, 64) - if err != nil { - return err - } - if height < 0 { - return errorsmod.Wrapf( - sdkerrors.ErrInvalidRequest, - "Invoke: height (%d) from %q must be >= 0", height, grpcBlockHeightHeader) - } - } - - abciR := abci.RequestQuery{ - Path: method, - Data: reqBz, - Height: height, - } - - res, err := c.queryABCI(ctx, abciR) - if err != nil { - return err - } - - err = c.getRPCCodec().Unmarshal(res.Value, reply) - if err != nil { - return err - } - - // Create header metadata. For now the headers contain: - // - block height - // We then parse all the call options, if the call option is a - // HeaderCallOption, then we manually set the value of that header to the - // metadata. - md = metadata.Pairs(grpcBlockHeightHeader, strconv.FormatInt(res.Height, 10)) - for _, callOpt := range opts { - header, ok := callOpt.(grpc.HeaderCallOption) - if !ok { - continue - } - - *header.HeaderAddr = md - } - - if c.cdc.InterfaceRegistry() != nil { - return types.UnpackInterfaces(reply, c.cdc.InterfaceRegistry()) - } - - return nil -} - -// queryABCI performs an ABCI query request to the CometBFT RPC client. -// If the RPC query fails or returns a non-OK response, it will return an error. -// The response is converted from ABCI error codes to gRPC status errors. -func (c *CometBFTBroadcaster) queryABCI(ctx context.Context, req abci.RequestQuery) (abci.ResponseQuery, error) { - opts := rpcclient.ABCIQueryOptions{ - Height: req.Height, - Prove: req.Prove, - } - - result, err := c.rpcClient.ABCIQueryWithOptions(ctx, req.Path, req.Data, opts) - if err != nil { - return abci.ResponseQuery{}, err - } - - if !result.Response.IsOK() { - return abci.ResponseQuery{}, sdkErrorToGRPCError(result.Response) - } - - return result.Response, nil -} - -// sdkErrorToGRPCError converts an ABCI query response error code to an appropriate gRPC status error. -// It maps common SDK error codes to their gRPC equivalents: -// - ErrInvalidRequest -> InvalidArgument -// - ErrUnauthorized -> Unauthenticated -// - ErrKeyNotFound -> NotFound -// Any other error codes are mapped to Unknown. -func sdkErrorToGRPCError(resp abci.ResponseQuery) error { - switch resp.Code { - case sdkerrors.ErrInvalidRequest.ABCICode(): - return status.Error(codes.InvalidArgument, resp.Log) - case sdkerrors.ErrUnauthorized.ABCICode(): - return status.Error(codes.Unauthenticated, resp.Log) - case sdkerrors.ErrKeyNotFound.ABCICode(): - return status.Error(codes.NotFound, resp.Log) - default: - return status.Error(codes.Unknown, resp.Log) - } -} - -// getRPCCodec returns the gRPC codec for the CometBFT broadcaster. -// If the broadcaster's codec implements GRPCCodecProvider, it returns its gRPC codec. -// Otherwise, it creates a new ProtoCodec with the broadcaster's interface registry and returns its gRPC codec. -func (c *CometBFTBroadcaster) getRPCCodec() encoding.Codec { - cdc, ok := c.cdc.(codec.GRPCCodecProvider) - if !ok { - return codec.NewProtoCodec(c.cdc.InterfaceRegistry()).GRPCCodec() - } - - return cdc.GRPCCodec() -} diff --git a/connect/internal/tx/common_test.go b/connect/internal/tx/common_test.go deleted file mode 100644 index 864a1153..00000000 --- a/connect/internal/tx/common_test.go +++ /dev/null @@ -1,116 +0,0 @@ -package tx - -import ( - "context" - - "google.golang.org/grpc" - - abciv1beta1 "cosmossdk.io/api/cosmos/base/abci/v1beta1" - apitx "cosmossdk.io/api/cosmos/tx/v1beta1" - txdecode "cosmossdk.io/x/tx/decode" - "cosmossdk.io/x/tx/signing" - "github.com/ignite/apps/connect/internal/account" - "github.com/ignite/apps/connect/internal/autocli/keyring" - - "github.com/cosmos/cosmos-sdk/codec" - addrcodec "github.com/cosmos/cosmos-sdk/codec/address" - codectypes "github.com/cosmos/cosmos-sdk/codec/types" - codec2 "github.com/cosmos/cosmos-sdk/crypto/codec" - "github.com/cosmos/cosmos-sdk/crypto/hd" - cryptoKeyring "github.com/cosmos/cosmos-sdk/crypto/keyring" - cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" - "github.com/cosmos/cosmos-sdk/types" -) - -var ( - cdc = codec.NewProtoCodec(codectypes.NewInterfaceRegistry()) - ac = addrcodec.NewBech32Codec("cosmos") - valCodec = addrcodec.NewBech32Codec("cosmosval") - signingOptions = signing.Options{ - AddressCodec: ac, - ValidatorAddressCodec: valCodec, - } - signingContext, _ = signing.NewContext(signingOptions) - decodeOptions = txdecode.Options{SigningContext: signingContext} - decoder, _ = txdecode.NewDecoder(decodeOptions) - - k = cryptoKeyring.NewInMemory(cdc) - keybase, _ = keyring.NewAutoCLIKeyring(k, ac) - txConf, _ = NewTxConfig(ConfigOptions{ - AddressCodec: ac, - Cdc: cdc, - ValidatorAddressCodec: valCodec, - }) -) - -func setKeyring() keyring.Keyring { - registry := codectypes.NewInterfaceRegistry() - codec2.RegisterInterfaces(registry) - cdc := codec.NewProtoCodec(registry) - k := cryptoKeyring.NewInMemory(cdc) - _, err := k.NewAccount("alice", "equip will roof matter pink blind book anxiety banner elbow sun young", "", "m/44'/118'/0'/0/0", hd.Secp256k1) - if err != nil { - panic(err) - } - keybase, err := keyring.NewAutoCLIKeyring(k, ac) - if err != nil { - panic(err) - } - return keybase -} - -type mockAccount struct { - addr []byte -} - -func (m mockAccount) GetAddress() types.AccAddress { - return m.addr -} - -func (m mockAccount) GetPubKey() cryptotypes.PubKey { - return nil -} - -func (m mockAccount) GetAccountNumber() uint64 { - return 1 -} - -func (m mockAccount) GetSequence() uint64 { - return 0 -} - -type mockAccountRetriever struct{} - -func (m mockAccountRetriever) GetAccount(_ context.Context, address []byte) (account.Account, error) { - return mockAccount{addr: address}, nil -} - -func (m mockAccountRetriever) GetAccountWithHeight(_ context.Context, address []byte) (account.Account, int64, error) { - return mockAccount{addr: address}, 0, nil -} - -func (m mockAccountRetriever) EnsureExists(_ context.Context, _ []byte) error { - return nil -} - -func (m mockAccountRetriever) GetAccountNumberSequence(_ context.Context, _ []byte) (accNum, accSeq uint64, err error) { - return accNum, accSeq, nil -} - -type mockClientConn struct{} - -func (m mockClientConn) Invoke(_ context.Context, _ string, _, reply interface{}, _ ...grpc.CallOption) error { - simResponse := apitx.SimulateResponse{ - GasInfo: &abciv1beta1.GasInfo{ - GasWanted: 10000, - GasUsed: 7500, - }, - Result: nil, - } - *reply.(*apitx.SimulateResponse) = simResponse // nolint:govet // ignore linting error - return nil -} - -func (m mockClientConn) NewStream(_ context.Context, _ *grpc.StreamDesc, _ string, _ ...grpc.CallOption) (grpc.ClientStream, error) { - return nil, nil -} diff --git a/connect/internal/tx/config.go b/connect/internal/tx/config.go deleted file mode 100644 index d7008be5..00000000 --- a/connect/internal/tx/config.go +++ /dev/null @@ -1,325 +0,0 @@ -package tx - -import ( - "errors" - - "google.golang.org/protobuf/encoding/protojson" - "google.golang.org/protobuf/reflect/protoreflect" - "google.golang.org/protobuf/types/known/anypb" - - apitxsigning "cosmossdk.io/api/cosmos/tx/signing/v1beta1" - "cosmossdk.io/core/address" - txdecode "cosmossdk.io/x/tx/decode" - "cosmossdk.io/x/tx/signing" - "cosmossdk.io/x/tx/signing/aminojson" - "cosmossdk.io/x/tx/signing/direct" - "cosmossdk.io/x/tx/signing/directaux" - - "github.com/cosmos/cosmos-sdk/codec" - codectypes "github.com/cosmos/cosmos-sdk/codec/types" - cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" -) - -var ( - _ TxConfig = txConfig{} - _ TxEncodingConfig = defaultEncodingConfig{} - _ TxSigningConfig = defaultTxSigningConfig{} -) - -// TxConfig is an interface that a client can use to generate a concrete transaction type -// defined by the application. -type TxConfig interface { - TxEncodingConfig - TxSigningConfig -} - -// TxEncodingConfig defines the interface for transaction encoding and decoding. -// It provides methods for both binary and JSON encoding/decoding. -type TxEncodingConfig interface { - // TxEncoder returns an encoder for binary transaction encoding. - TxEncoder() txEncoder - // TxDecoder returns a decoder for binary transaction decoding. - TxDecoder() txDecoder - // TxJSONEncoder returns an encoder for JSON transaction encoding. - TxJSONEncoder() txEncoder - // TxJSONDecoder returns a decoder for JSON transaction decoding. - TxJSONDecoder() txDecoder - // TxTextEncoder returns an encoder for text transaction encoding. - TxTextEncoder() txEncoder - // TxTextDecoder returns a decoder for text transaction decoding. - TxTextDecoder() txDecoder - // Decoder returns the Decoder interface for decoding transaction bytes into a DecodedTx. - Decoder() Decoder -} - -// TxSigningConfig defines the interface for transaction signing configurations. -type TxSigningConfig interface { - // SignModeHandler returns a reference to the HandlerMap which manages the different signing modes. - SignModeHandler() *signing.HandlerMap - // SigningContext returns a reference to the Context which holds additional data required during signing. - SigningContext() *signing.Context - // MarshalSignatureJSON takes a slice of Signature objects and returns their JSON encoding. - MarshalSignatureJSON([]Signature) ([]byte, error) - // UnmarshalSignatureJSON takes a JSON byte slice and returns a slice of Signature objects. - UnmarshalSignatureJSON([]byte) ([]Signature, error) -} - -// ConfigOptions defines the configuration options for transaction processing. -type ConfigOptions struct { - AddressCodec address.Codec - Decoder Decoder - Cdc codec.BinaryCodec - - ValidatorAddressCodec address.Codec - FileResolver signing.ProtoFileResolver - TypeResolver signing.TypeResolver - CustomGetSigner map[protoreflect.FullName]signing.GetSignersFunc - MaxRecursionDepth int - - CustomSignModes []signing.SignModeHandler -} - -// validate checks the ConfigOptions for required fields and sets default values where necessary. -// It returns an error if any required field is missing. -func (c *ConfigOptions) validate() error { - if c.AddressCodec == nil { - return errors.New("address codec cannot be nil") - } - - if c.ValidatorAddressCodec == nil { - return errors.New("validator address codec cannot be nil") - } - - if c.Cdc == nil { - return errors.New("codec cannot be nil") - } - - return nil -} - -// txConfig is a struct that embeds TxEncodingConfig and TxSigningConfig interfaces. -type txConfig struct { - TxEncodingConfig - TxSigningConfig -} - -// NewTxConfig creates a new TxConfig instance using the provided ConfigOptions. -// It validates the options, initializes the signing context, and sets up the decoder if not provided. -func NewTxConfig(options ConfigOptions) (TxConfig, error) { - err := options.validate() - if err != nil { - return nil, err - } - - signingCtx, err := newDefaultTxSigningConfig(options) - if err != nil { - return nil, err - } - - if options.Decoder == nil { - options.Decoder, err = txdecode.NewDecoder(txdecode.Options{ - SigningContext: signingCtx.SigningContext(), - }) - if err != nil { - return nil, err - } - } - - return &txConfig{ - TxEncodingConfig: defaultEncodingConfig{ - cdc: options.Cdc, - decoder: options.Decoder, - }, - TxSigningConfig: signingCtx, - }, nil -} - -// defaultEncodingConfig is an empty struct that implements the TxEncodingConfig interface. -type defaultEncodingConfig struct { - cdc codec.BinaryCodec - decoder Decoder -} - -// TxEncoder returns the default transaction encoder. -func (t defaultEncodingConfig) TxEncoder() txEncoder { - return encodeTx -} - -// TxDecoder returns the default transaction decoder. -func (t defaultEncodingConfig) TxDecoder() txDecoder { - return decodeTx(t.cdc, t.decoder) -} - -// TxJSONEncoder returns the default JSON transaction encoder. -func (t defaultEncodingConfig) TxJSONEncoder() txEncoder { - return encodeJsonTx -} - -// TxJSONDecoder returns the default JSON transaction decoder. -func (t defaultEncodingConfig) TxJSONDecoder() txDecoder { - return decodeJsonTx(t.cdc, t.decoder) -} - -// TxTextEncoder returns the default text transaction encoder. -func (t defaultEncodingConfig) TxTextEncoder() txEncoder { - return encodeTextTx -} - -// TxTextDecoder returns the default text transaction decoder. -func (t defaultEncodingConfig) TxTextDecoder() txDecoder { - return decodeTextTx(t.cdc, t.decoder) -} - -// Decoder returns the Decoder instance associated with this encoding configuration. -func (t defaultEncodingConfig) Decoder() Decoder { - return t.decoder -} - -// defaultTxSigningConfig is a struct that holds the signing context and handler map. -type defaultTxSigningConfig struct { - signingCtx *signing.Context - handlerMap *signing.HandlerMap - cdc codec.BinaryCodec -} - -// newDefaultTxSigningConfig creates a new defaultTxSigningConfig instance using the provided ConfigOptions. -// It initializes the signing context and handler map. -func newDefaultTxSigningConfig(opts ConfigOptions) (*defaultTxSigningConfig, error) { - signingCtx, err := newSigningContext(opts) - if err != nil { - return nil, err - } - - handlerMap, err := newHandlerMap(opts, signingCtx) - if err != nil { - return nil, err - } - - return &defaultTxSigningConfig{ - signingCtx: signingCtx, - handlerMap: handlerMap, - cdc: opts.Cdc, - }, nil -} - -// SignModeHandler returns the handler map that manages the different signing modes. -func (t defaultTxSigningConfig) SignModeHandler() *signing.HandlerMap { - return t.handlerMap -} - -// SigningContext returns the signing context that holds additional data required during signing. -func (t defaultTxSigningConfig) SigningContext() *signing.Context { - return t.signingCtx -} - -// MarshalSignatureJSON takes a slice of Signature objects and returns their JSON encoding. -// This method is not yet implemented and will panic if called. -func (t defaultTxSigningConfig) MarshalSignatureJSON(signatures []Signature) ([]byte, error) { - descriptor := make([]*apitxsigning.SignatureDescriptor, len(signatures)) - - for i, sig := range signatures { - descData, err := signatureDataToProto(sig.Data) - if err != nil { - return nil, err - } - - anyPk, err := codectypes.NewAnyWithValue(sig.PubKey) - if err != nil { - return nil, err - } - - descriptor[i] = &apitxsigning.SignatureDescriptor{ - PublicKey: &anypb.Any{ - TypeUrl: codectypes.MsgTypeURL(sig.PubKey), - Value: anyPk.Value, - }, - Data: descData, - Sequence: sig.Sequence, - } - } - - return jsonMarshalOptions.Marshal(&apitxsigning.SignatureDescriptors{Signatures: descriptor}) -} - -// UnmarshalSignatureJSON takes a JSON byte slice and returns a slice of Signature objects. -// This method is not yet implemented and will panic if called. -func (t defaultTxSigningConfig) UnmarshalSignatureJSON(bz []byte) ([]Signature, error) { - var descriptor apitxsigning.SignatureDescriptors - - err := protojson.UnmarshalOptions{}.Unmarshal(bz, &descriptor) - if err != nil { - return nil, err - } - - sigs := make([]Signature, len(descriptor.Signatures)) - for i, desc := range descriptor.Signatures { - var pubkey cryptotypes.PubKey - - anyPk := &codectypes.Any{ - TypeUrl: desc.PublicKey.TypeUrl, - Value: desc.PublicKey.Value, - } - - err = t.cdc.UnpackAny(anyPk, &pubkey) - if err != nil { - return nil, err - } - - data, err := SignatureDataFromProto(desc.Data) - if err != nil { - return nil, err - } - - sigs[i] = Signature{ - PubKey: pubkey, - Data: data, - Sequence: desc.Sequence, - } - } - - return sigs, nil -} - -// newSigningContext creates a new signing context using the provided ConfigOptions. -// Returns a signing.Context instance or an error if initialization fails. -func newSigningContext(opts ConfigOptions) (*signing.Context, error) { - return signing.NewContext(signing.Options{ - FileResolver: opts.FileResolver, - TypeResolver: opts.TypeResolver, - AddressCodec: opts.AddressCodec, - ValidatorAddressCodec: opts.ValidatorAddressCodec, - CustomGetSigners: opts.CustomGetSigner, - MaxRecursionDepth: opts.MaxRecursionDepth, - }) -} - -// newHandlerMap constructs a new HandlerMap based on the provided ConfigOptions and signing context. -// It initializes handlers for each enabled and custom sign mode specified in the options. -func newHandlerMap(opts ConfigOptions, signingCtx *signing.Context) (hm *signing.HandlerMap, err error) { - lenSignModes := 3 - handlers := make([]signing.SignModeHandler, lenSignModes+len(opts.CustomSignModes)) - - // sign mode direct - handlers[0] = &direct.SignModeHandler{} - // sign mode direct aux - handlers[1], err = directaux.NewSignModeHandler(directaux.SignModeHandlerOptions{ - TypeResolver: signingCtx.TypeResolver(), - SignersContext: signingCtx, - }) - if err != nil { - return nil, err - } - // sign mode amino json - handlers[2] = aminojson.NewSignModeHandler(aminojson.SignModeHandlerOptions{ - FileResolver: signingCtx.FileResolver(), - TypeResolver: opts.TypeResolver, - }) - - for i, m := range opts.CustomSignModes { - handlers[i+lenSignModes] = m - } - - hm = signing.NewHandlerMap(handlers...) - - return hm, nil -} diff --git a/connect/internal/tx/config_test.go b/connect/internal/tx/config_test.go deleted file mode 100644 index ad91c4bd..00000000 --- a/connect/internal/tx/config_test.go +++ /dev/null @@ -1,242 +0,0 @@ -package tx - -import ( - "context" - "testing" - - "github.com/stretchr/testify/require" - - apicrypto "cosmossdk.io/api/cosmos/crypto/multisig/v1beta1" - _ "cosmossdk.io/api/cosmos/crypto/secp256k1" - apitxsigning "cosmossdk.io/api/cosmos/tx/signing/v1beta1" - "cosmossdk.io/x/tx/signing" - - "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/codec/address" - codectypes "github.com/cosmos/cosmos-sdk/codec/types" - codec2 "github.com/cosmos/cosmos-sdk/crypto/codec" - kmultisig "github.com/cosmos/cosmos-sdk/crypto/keys/multisig" - "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" - cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" -) - -type mockModeHandler struct{} - -func (t mockModeHandler) Mode() apitxsigning.SignMode { - return apitxsigning.SignMode_SIGN_MODE_DIRECT -} - -func (t mockModeHandler) GetSignBytes(_ context.Context, _ signing.SignerData, _ signing.TxData) ([]byte, error) { - return []byte{}, nil -} - -func TestConfigOptions_validate(t *testing.T) { - tests := []struct { - name string - opts ConfigOptions - wantErr bool - }{ - { - name: "valid options", - opts: ConfigOptions{ - AddressCodec: address.NewBech32Codec("cosmos"), - Decoder: decoder, - Cdc: cdc, - ValidatorAddressCodec: address.NewBech32Codec("cosmosvaloper"), - }, - }, - { - name: "missing address codec", - opts: ConfigOptions{ - Decoder: decoder, - Cdc: cdc, - ValidatorAddressCodec: address.NewBech32Codec("cosmosvaloper"), - }, - wantErr: true, - }, - { - name: "missing decoder", - opts: ConfigOptions{ - AddressCodec: address.NewBech32Codec("cosmos"), - Cdc: cdc, - ValidatorAddressCodec: address.NewBech32Codec("cosmosvaloper"), - }, - }, - { - name: "missing codec", - opts: ConfigOptions{ - AddressCodec: address.NewBech32Codec("cosmos"), - Decoder: decoder, - ValidatorAddressCodec: address.NewBech32Codec("cosmosvaloper"), - }, - wantErr: true, - }, - { - name: "missing validator address codec", - opts: ConfigOptions{ - AddressCodec: address.NewBech32Codec("cosmos"), - Decoder: decoder, - Cdc: cdc, - }, - wantErr: true, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if err := tt.opts.validate(); (err != nil) != tt.wantErr { - t.Errorf("validate() error = %v, wantErr %v", err, tt.wantErr) - } - }) - } -} - -func TestNewTxConfig(t *testing.T) { - tests := []struct { - name string - options ConfigOptions - wantErr bool - }{ - { - name: "valid options", - options: ConfigOptions{ - AddressCodec: ac, - Cdc: cdc, - ValidatorAddressCodec: valCodec, - }, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - got, err := NewTxConfig(tt.options) - if (err != nil) != tt.wantErr { - t.Errorf("NewTxConfig() error = %v, wantErr %v", err, tt.wantErr) - return - } - require.NotNil(t, got) - }) - } -} - -func Test_defaultTxSigningConfig_MarshalSignatureJSON(t *testing.T) { - tests := []struct { - name string - options ConfigOptions - signatures func(t *testing.T) []Signature - }{ - { - name: "single signature", - options: ConfigOptions{ - AddressCodec: ac, - Cdc: cdc, - ValidatorAddressCodec: valCodec, - }, - signatures: func(t *testing.T) []Signature { - t.Helper() - - k := setKeyring() - pk, err := k.GetPubKey("alice") - require.NoError(t, err) - signature, err := k.Sign("alice", make([]byte, 10), apitxsigning.SignMode_SIGN_MODE_DIRECT) - require.NoError(t, err) - return []Signature{ - { - PubKey: pk, - Data: &SingleSignatureData{ - SignMode: apitxsigning.SignMode_SIGN_MODE_DIRECT, - Signature: signature, - }, - }, - } - }, - }, - { - name: "multisig signatures", - options: ConfigOptions{ - AddressCodec: ac, - Cdc: cdc, - ValidatorAddressCodec: valCodec, - }, - signatures: func(t *testing.T) []Signature { - t.Helper() - - n := 2 - pubKeys := make([]cryptotypes.PubKey, n) - sigs := make([]SignatureData, n) - for i := 0; i < n; i++ { - sk := secp256k1.GenPrivKey() - pubKeys[i] = sk.PubKey() - msg, err := sk.Sign(make([]byte, 10)) - require.NoError(t, err) - sigs[i] = &SingleSignatureData{ - SignMode: apitxsigning.SignMode_SIGN_MODE_DIRECT, - Signature: msg, - } - } - bitArray := cryptotypes.NewCompactBitArray(n) - mKey := kmultisig.NewLegacyAminoPubKey(n, pubKeys) - return []Signature{ - { - PubKey: mKey, - Data: &MultiSignatureData{ - BitArray: &apicrypto.CompactBitArray{ - ExtraBitsStored: bitArray.ExtraBitsStored, - Elems: bitArray.Elems, - }, - Signatures: sigs, - }, - }, - } - }, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - config, err := NewTxConfig(tt.options) - require.NoError(t, err) - - got, err := config.MarshalSignatureJSON(tt.signatures(t)) - require.NoError(t, err) - require.NotNil(t, got) - }) - } -} - -func Test_defaultTxSigningConfig_UnmarshalSignatureJSON(t *testing.T) { - registry := codectypes.NewInterfaceRegistry() - codec2.RegisterInterfaces(registry) - cdc := codec.NewProtoCodec(registry) - tests := []struct { - name string - options ConfigOptions - bz []byte - }{ - { - name: "single signature", - options: ConfigOptions{ - AddressCodec: ac, - Cdc: cdc, - ValidatorAddressCodec: valCodec, - }, - bz: []byte(`{"signatures":[{"public_key":{"@type":"/cosmos.crypto.secp256k1.PubKey", "key":"A0/vnNfExjWI07A/61KBudIyy6NNbz1xruWSEf+/4f6H"}, "data":{"single":{"mode":"SIGN_MODE_DIRECT", "signature":"usUTJwdc4PWPuox0Y0G/RuHoxyj+QpUcBGvXyNdDX1FOdoVj0tg4TGKT2NnM3QP6wCNbubjHuMOhTtqfW8SkYg=="}}}]}`), - }, - { - name: "multisig signatures", - options: ConfigOptions{ - AddressCodec: ac, - Cdc: cdc, - ValidatorAddressCodec: valCodec, - }, - bz: []byte(`{"signatures":[{"public_key":{"@type":"/cosmos.crypto.multisig.LegacyAminoPubKey","threshold":2,"public_keys":[{"@type":"/cosmos.crypto.secp256k1.PubKey","key":"A4Bs9huvS/COpZNhVhTnhgc8YR6VrSQ8hLQIHgnA+m3w"},{"@type":"/cosmos.crypto.secp256k1.PubKey","key":"AuNz2lFkLn3sKNjC5r4OWhgkWg5DZpGUiR9OdpzXspnp"}]},"data":{"multi":{"bitarray":{"extra_bits_stored":2,"elems":"AA=="},"signatures":[{"single":{"mode":"SIGN_MODE_DIRECT","signature":"vng4IlPzLH3fDFpikM5y1SfXFGny4BcLGwIFU0Ty4yoWjIxjTS4m6fgDB61sxEkV5DK/CD7gUwenGuEpzJ2IGw=="}},{"single":{"mode":"SIGN_MODE_DIRECT","signature":"2dsGmr13bq/mPxbk9AgqcFpuvk4beszWu6uxkx+EhTMdVGp4J8FtjZc8xs/Pp3oTWY4ScAORYQHxwqN4qwMXGg=="}}]}}}]}`), - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - config, err := NewTxConfig(tt.options) - require.NoError(t, err) - - got, err := config.UnmarshalSignatureJSON(tt.bz) - require.NoError(t, err) - require.NotNil(t, got) - }) - } -} diff --git a/connect/internal/tx/context.go b/connect/internal/tx/context.go deleted file mode 100644 index 1da1ddbc..00000000 --- a/connect/internal/tx/context.go +++ /dev/null @@ -1,51 +0,0 @@ -package tx - -import ( - "context" - "errors" - - "github.com/spf13/pflag" - - "cosmossdk.io/core/address" - "github.com/ignite/apps/connect/internal/autocli/keyring" - - "github.com/cosmos/cosmos-sdk/codec" -) - -// ContextKey is a key used to store and retrieve Context from a Go context.Context. -var ContextKey contextKey - -// contextKey is an empty struct used as a key type for storing Context in a context.Context. -type contextKey struct{} - -// Context represents the client context used in autocli commands. -// It contains various components needed for command execution. -type Context struct { - Flags *pflag.FlagSet - - AddressCodec address.Codec - ValidatorAddressCodec address.Codec - ConsensusAddressCodec address.Codec - - Cdc codec.Codec - Keyring keyring.Keyring -} - -// SetContext sets client context in the go context. -func SetContext(goCtx context.Context, ctx Context) context.Context { - return context.WithValue(goCtx, ContextKey, ctx) -} - -// GetContext gets the context from the go context. -func GetContext(goCtx context.Context) (Context, error) { - if c := goCtx.Value(ContextKey); c != nil { - ctx, ok := c.(Context) - if !ok { - return Context{}, errors.New("context value is not of type autocli context") - } - - return ctx, nil - } - - return Context{}, errors.New("context does not contain autocli context value") -} diff --git a/connect/internal/tx/encoder.go b/connect/internal/tx/encoder.go deleted file mode 100644 index 09011c83..00000000 --- a/connect/internal/tx/encoder.go +++ /dev/null @@ -1,159 +0,0 @@ -package tx - -import ( - "fmt" - - "google.golang.org/protobuf/encoding/protojson" - "google.golang.org/protobuf/encoding/prototext" - protov2 "google.golang.org/protobuf/proto" - - txv1beta1 "cosmossdk.io/api/cosmos/tx/v1beta1" - txdecode "cosmossdk.io/x/tx/decode" - - "github.com/cosmos/cosmos-sdk/codec" -) - -var ( - // marshalOption configures protobuf marshaling to be deterministic. - marshalOption = protov2.MarshalOptions{Deterministic: true} - - // jsonMarshalOptions configures JSON marshaling for protobuf messages. - jsonMarshalOptions = protojson.MarshalOptions{ - Indent: "", - UseProtoNames: true, - UseEnumNumbers: false, - EmitUnpopulated: true, - } - - // textMarshalOptions - textMarshalOptions = prototext.MarshalOptions{ - Indent: "", - } -) - -// Decoder defines the interface for decoding transaction bytes into a DecodedTx. -type Decoder interface { - Decode(txBytes []byte) (*txdecode.DecodedTx, error) -} - -// txDecoder is a function type that unmarshals transaction bytes into an API Tx type. -type txDecoder func(txBytes []byte) (Tx, error) - -// txEncoder is a function type that marshals a transaction into bytes. -type txEncoder func(tx Tx) ([]byte, error) - -// decodeTx decodes transaction bytes into an apitx.Tx structure. -func decodeTx(cdc codec.BinaryCodec, decoder Decoder) txDecoder { - return func(txBytes []byte) (Tx, error) { - tx := new(txv1beta1.Tx) - err := protov2.Unmarshal(txBytes, tx) - if err != nil { - return nil, err - } - - pTxBytes, err := protoTxBytes(tx) - if err != nil { - return nil, err - } - - decodedTx, err := decoder.Decode(pTxBytes) - if err != nil { - return nil, err - } - return newWrapperTx(cdc, decodedTx), nil - } -} - -// encodeTx encodes an apitx.Tx into bytes using protobuf marshaling options. -func encodeTx(tx Tx) ([]byte, error) { - wTx, ok := tx.(*wrappedTx) - if !ok { - return nil, fmt.Errorf("unexpected tx type: %T", tx) - } - return marshalOption.Marshal(wTx.Tx) -} - -// decodeJsonTx decodes transaction bytes into an apitx.Tx structure using JSON format. -func decodeJsonTx(cdc codec.BinaryCodec, decoder Decoder) txDecoder { - return func(txBytes []byte) (Tx, error) { - jsonTx := new(txv1beta1.Tx) - err := protojson.UnmarshalOptions{ - AllowPartial: false, - DiscardUnknown: false, - }.Unmarshal(txBytes, jsonTx) - if err != nil { - return nil, err - } - - pTxBytes, err := protoTxBytes(jsonTx) - if err != nil { - return nil, err - } - - decodedTx, err := decoder.Decode(pTxBytes) - if err != nil { - return nil, err - } - return newWrapperTx(cdc, decodedTx), nil - } -} - -// encodeJsonTx encodes an apitx.Tx into bytes using JSON marshaling options. -func encodeJsonTx(tx Tx) ([]byte, error) { - wTx, ok := tx.(*wrappedTx) - if !ok { - return nil, fmt.Errorf("unexpected tx type: %T", tx) - } - return jsonMarshalOptions.Marshal(wTx.Tx) -} - -func encodeTextTx(tx Tx) ([]byte, error) { - wTx, ok := tx.(*wrappedTx) - if !ok { - return nil, fmt.Errorf("unexpected tx type: %T", tx) - } - return textMarshalOptions.Marshal(wTx.Tx) -} - -// decodeJsonTx decodes transaction bytes into an apitx.Tx structure using JSON format. -func decodeTextTx(cdc codec.BinaryCodec, decoder Decoder) txDecoder { - return func(txBytes []byte) (Tx, error) { - jsonTx := new(txv1beta1.Tx) - err := prototext.UnmarshalOptions{ - AllowPartial: false, - DiscardUnknown: false, - }.Unmarshal(txBytes, jsonTx) - if err != nil { - return nil, err - } - - pTxBytes, err := protoTxBytes(jsonTx) - if err != nil { - return nil, err - } - - decodedTx, err := decoder.Decode(pTxBytes) - if err != nil { - return nil, err - } - return newWrapperTx(cdc, decodedTx), nil - } -} - -func protoTxBytes(tx *txv1beta1.Tx) ([]byte, error) { - bodyBytes, err := marshalOption.Marshal(tx.Body) - if err != nil { - return nil, err - } - - authInfoBytes, err := marshalOption.Marshal(tx.AuthInfo) - if err != nil { - return nil, err - } - - return marshalOption.Marshal(&txv1beta1.TxRaw{ - BodyBytes: bodyBytes, - AuthInfoBytes: authInfoBytes, - Signatures: tx.Signatures, - }) -} diff --git a/connect/internal/tx/encoder_test.go b/connect/internal/tx/encoder_test.go deleted file mode 100644 index 16dea70d..00000000 --- a/connect/internal/tx/encoder_test.go +++ /dev/null @@ -1,108 +0,0 @@ -package tx - -import ( - "testing" - - "github.com/stretchr/testify/require" - - bankv1beta1 "cosmossdk.io/api/cosmos/bank/v1beta1" - base "cosmossdk.io/api/cosmos/base/v1beta1" - apisigning "cosmossdk.io/api/cosmos/tx/signing/v1beta1" - sdk "github.com/cosmos/cosmos-sdk/types" - - "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" -) - -func getWrappedTx(t *testing.T) *wrappedTx { - t.Helper() - - f, err := NewFactory(keybase, cdc, mockAccountRetriever{}, txConf, ac, mockClientConn{}, TxParameters{}) - require.NoError(t, err) - - pk := secp256k1.GenPrivKey().PubKey() - addr, _ := ac.BytesToString(pk.Address()) - - f.tx.msgs = []sdk.Msg{&bankv1beta1.MsgSend{ - FromAddress: addr, - ToAddress: addr, - Amount: []*base.Coin{}, - }} - require.NoError(t, err) - - err = f.setFeePayer(addr) - require.NoError(t, err) - - f.tx.fees = []*base.Coin{{ - Denom: "cosmos", - Amount: "1000", - }} - - err = f.setSignatures([]Signature{{ - PubKey: pk, - Data: &SingleSignatureData{ - SignMode: apisigning.SignMode_SIGN_MODE_DIRECT, - Signature: nil, - }, - Sequence: 0, - }}...) - require.NoError(t, err) - wTx, err := f.getTx() - require.NoError(t, err) - return wTx -} - -func Test_txEncoder_txDecoder(t *testing.T) { - wTx := getWrappedTx(t) - - encodedTx, err := encodeTx(wTx) - require.NoError(t, err) - require.NotNil(t, encodedTx) - - isDeterministic, err := encodeTx(wTx) - require.NoError(t, err) - require.NotNil(t, encodedTx) - require.Equal(t, encodedTx, isDeterministic) - - f := decodeTx(cdc, decoder) - decodedTx, err := f(encodedTx) - require.NoError(t, err) - require.NotNil(t, decodedTx) - - dTx, ok := decodedTx.(*wrappedTx) - require.True(t, ok) - require.Equal(t, wTx.TxRaw, dTx.TxRaw) - require.Equal(t, wTx.Tx.AuthInfo.String(), dTx.Tx.AuthInfo.String()) - require.Equal(t, wTx.Tx.Body.String(), dTx.Tx.Body.String()) - require.Equal(t, wTx.Tx.Signatures, dTx.Tx.Signatures) -} - -func Test_txJsonEncoder_txJsonDecoder(t *testing.T) { - tests := []struct { - name string - }{ - { - name: "json encode and decode tx", - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - wTx := getWrappedTx(t) - - encodedTx, err := encodeJsonTx(wTx) - require.NoError(t, err) - require.NotNil(t, encodedTx) - - f := decodeJsonTx(cdc, decoder) - decodedTx, err := f(encodedTx) - require.NoError(t, err) - require.NotNil(t, decodedTx) - - dTx, ok := decodedTx.(*wrappedTx) - require.True(t, ok) - require.Equal(t, wTx.TxRaw, dTx.TxRaw) - require.Equal(t, wTx.Tx.AuthInfo.String(), dTx.Tx.AuthInfo.String()) - require.Equal(t, wTx.Tx.Body.String(), dTx.Tx.Body.String()) - require.Equal(t, wTx.Tx.Signatures, dTx.Tx.Signatures) - }) - } -} diff --git a/connect/internal/tx/factory.go b/connect/internal/tx/factory.go deleted file mode 100644 index cb489150..00000000 --- a/connect/internal/tx/factory.go +++ /dev/null @@ -1,757 +0,0 @@ -package tx - -import ( - "context" - "errors" - "fmt" - "math/big" - "strings" - - "github.com/cosmos/go-bip39" - gogogrpc "github.com/cosmos/gogoproto/grpc" - "github.com/spf13/pflag" - "google.golang.org/protobuf/types/known/anypb" - - base "cosmossdk.io/api/cosmos/base/v1beta1" - apicrypto "cosmossdk.io/api/cosmos/crypto/multisig/v1beta1" - apitxsigning "cosmossdk.io/api/cosmos/tx/signing/v1beta1" - apitx "cosmossdk.io/api/cosmos/tx/v1beta1" - "cosmossdk.io/core/address" - "cosmossdk.io/math" - "cosmossdk.io/x/tx/signing" - flags2 "github.com/cosmos/cosmos-sdk/client/flags" - "github.com/cosmos/cosmos-sdk/codec" - codectypes "github.com/cosmos/cosmos-sdk/codec/types" - "github.com/cosmos/cosmos-sdk/crypto/keys/multisig" - "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" - cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" - sdk "github.com/cosmos/cosmos-sdk/types" - - "github.com/ignite/apps/connect/internal/account" - "github.com/ignite/apps/connect/internal/autocli/keyring" - "github.com/ignite/apps/connect/internal/coins" -) - -// Factory defines a client transaction factory that facilitates generating and -// signing an application-specific transaction. -type Factory struct { - keybase keyring.Keyring - cdc codec.BinaryCodec - accountRetriever account.AccountRetriever - ac address.Codec - conn gogogrpc.ClientConn - txConfig TxConfig - txParams TxParameters - - tx *txState -} - -func NewFactoryFromFlagSet(f *pflag.FlagSet, keybase keyring.Keyring, cdc codec.BinaryCodec, accRetriever account.AccountRetriever, - txConfig TxConfig, ac address.Codec, conn gogogrpc.ClientConn, -) (Factory, error) { - offline, _ := f.GetBool(FlagOffline) - if err := validateFlagSet(f, offline); err != nil { - return Factory{}, err - } - - params, err := txParamsFromFlagSet(f, keybase, ac) - if err != nil { - return Factory{}, err - } - - params, err = prepareTxParams(params, accRetriever, offline) - if err != nil { - return Factory{}, err - } - - return NewFactory(keybase, cdc, accRetriever, txConfig, ac, conn, params) -} - -// NewFactory returns a new instance of Factory. -func NewFactory(keybase keyring.Keyring, cdc codec.BinaryCodec, accRetriever account.AccountRetriever, - txConfig TxConfig, ac address.Codec, conn gogogrpc.ClientConn, parameters TxParameters, -) (Factory, error) { - return Factory{ - keybase: keybase, - cdc: cdc, - accountRetriever: accRetriever, - ac: ac, - conn: conn, - txConfig: txConfig, - txParams: parameters, - - tx: &txState{}, - }, nil -} - -// validateFlagSet checks the provided flags for consistency and requirements based on the operation mode. -func validateFlagSet(f *pflag.FlagSet, offline bool) error { - dryRun, _ := f.GetBool(FlagDryRun) - if offline && dryRun { - return errors.New("dry-run: cannot use offline mode") - } - - generateOnly, _ := f.GetBool(FlagGenerateOnly) - chainID, _ := f.GetString(FlagChainID) - if offline { - if !generateOnly && (!f.Changed(FlagAccountNumber) || !f.Changed(FlagSequence)) { - return errors.New("account-number and sequence must be set in offline mode") - } - - if generateOnly && chainID != "" { - return errors.New("chain ID cannot be used when offline and generate-only flags are set") - } - - gas, _ := f.GetString(FlagGas) - gasSetting, _ := flags2.ParseGasSetting(gas) - if gasSetting.Simulate { - return errors.New("simulate and offline flags cannot be set at the same time") - } - } else if chainID == "" { - return errors.New("chain ID required but not specified") - } - - return nil -} - -// prepareTxParams ensures the account defined by ctx.GetFromAddress() exists and -// if the account number and/or the account sequence number are zero (not set), -// they will be queried for and set on the provided Factory. -func prepareTxParams(parameters TxParameters, accRetriever account.AccountRetriever, offline bool) (TxParameters, error) { - if offline { - return parameters, nil - } - - if len(parameters.Address) == 0 { - return parameters, errors.New("missing 'from address' field") - } - - if parameters.AccountNumber == 0 || parameters.Sequence == 0 { - num, seq, err := accRetriever.GetAccountNumberSequence(context.Background(), parameters.Address) - if err != nil { - return parameters, err - } - - if parameters.AccountNumber == 0 { - parameters.AccountNumber = num - } - - if parameters.Sequence == 0 { - parameters.Sequence = seq - } - } - - return parameters, nil -} - -// BuildUnsignedTx builds a transaction to be signed given a set of messages. -// Once created, the fee, memo, and messages are set. -func (f *Factory) BuildUnsignedTx(msgs ...sdk.Msg) error { - fees := f.txParams.fees - - isGasPriceZero, err := coins.IsZero(f.txParams.gasPrices) - if err != nil { - return err - } - if !isGasPriceZero { - areFeesZero, err := coins.IsZero(fees) - if err != nil { - return err - } - if !areFeesZero { - return errors.New("cannot provide both fees and gas prices") - } - - // f.gas is an uint64 and we should convert to LegacyDec - // without the risk of under/overflow via uint64->int64. - glDec := math.LegacyNewDecFromBigInt(new(big.Int).SetUint64(f.txParams.gas)) - - // Derive the fees based on the provided gas prices, where - // fee = ceil(gasPrice * gasLimit). - fees = make([]*base.Coin, len(f.txParams.gasPrices)) - - for i, gp := range f.txParams.gasPrices { - fee, err := math.LegacyNewDecFromStr(gp.Amount) - if err != nil { - return err - } - fee = fee.Mul(glDec) - fees[i] = &base.Coin{Denom: gp.Denom, Amount: fee.Ceil().RoundInt().String()} - } - } - - if err := validateMemo(f.txParams.memo); err != nil { - return err - } - - f.tx.msgs = msgs - f.tx.memo = f.txParams.memo - f.tx.fees = fees - f.tx.gasLimit = f.txParams.gas - f.tx.unordered = f.txParams.unordered - f.tx.timeoutTimestamp = f.txParams.timeoutTimestamp - - err = f.setFeeGranter(f.txParams.feeGranter) - if err != nil { - return err - } - err = f.setFeePayer(f.txParams.feePayer) - if err != nil { - return err - } - - return nil -} - -func (f *Factory) BuildsSignedTx(ctx context.Context, msgs ...sdk.Msg) (Tx, error) { - err := f.BuildUnsignedTx(msgs...) - if err != nil { - return nil, err - } - - return f.sign(ctx, true) -} - -// calculateGas calculates the gas required for the given messages. -func (f *Factory) calculateGas(msgs ...sdk.Msg) error { - _, adjusted, err := f.Simulate(msgs...) - if err != nil { - return err - } - - f.WithGas(adjusted) - - return nil -} - -// Simulate simulates the execution of a transaction and returns the -// simulation response obtained by the query and the adjusted gas amount. -func (f *Factory) Simulate(msgs ...sdk.Msg) (*apitx.SimulateResponse, uint64, error) { - txBytes, err := f.BuildSimTx(msgs...) - if err != nil { - return nil, 0, err - } - - txSvcClient := apitx.NewServiceClient(f.conn) - simRes, err := txSvcClient.Simulate(context.Background(), &apitx.SimulateRequest{ - TxBytes: txBytes, - }) - if err != nil { - return nil, 0, err - } - - return simRes, uint64(f.gasAdjustment() * float64(simRes.GasInfo.GasUsed)), nil -} - -// UnsignedTxString will generate an unsigned transaction and print it to the writer -// specified by ctx.Output. If simulation was requested, the gas will be -// simulated and also printed to the same writer before the transaction is -// printed. -func (f *Factory) UnsignedTxString(msgs ...sdk.Msg) (string, error) { - if f.simulateAndExecute() { - err := f.calculateGas(msgs...) - if err != nil { - return "", err - } - } - - err := f.BuildUnsignedTx(msgs...) - if err != nil { - return "", err - } - - encoder := f.txConfig.TxJSONEncoder() - if encoder == nil { - return "", errors.New("cannot print unsigned tx: tx json encoder is nil") - } - - tx, err := f.getTx() - if err != nil { - return "", err - } - - json, err := encoder(tx) - if err != nil { - return "", err - } - - return fmt.Sprintf("%s\n", json), nil -} - -// BuildSimTx creates an unsigned tx with an empty single signature and returns -// the encoded transaction or an error if the unsigned transaction cannot be -// built. -func (f *Factory) BuildSimTx(msgs ...sdk.Msg) ([]byte, error) { - err := f.BuildUnsignedTx(msgs...) - if err != nil { - return nil, err - } - - pk, err := f.getSimPK() - if err != nil { - return nil, err - } - - // Create an empty signature literal as the ante handler will populate with a - // sentinel pubkey. - sig := Signature{ - PubKey: pk, - Data: f.getSimSignatureData(pk), - Sequence: f.sequence(), - } - if err := f.setSignatures(sig); err != nil { - return nil, err - } - - encoder := f.txConfig.TxEncoder() - if encoder == nil { - return nil, fmt.Errorf("cannot simulate tx: tx encoder is nil") - } - - tx, err := f.getTx() - if err != nil { - return nil, err - } - return encoder(tx) -} - -// sign signs a given tx with a named key. The bytes signed over are canonical. -// The resulting signature will be added to the transaction builder overwriting the previous -// ones if overwrite=true (otherwise, the signature will be appended). -// Signing a transaction with multiple signers in the DIRECT mode is not supported and will -// return an error. -func (f *Factory) sign(ctx context.Context, overwriteSig bool) (Tx, error) { - if f.keybase == nil { - return nil, errors.New("keybase must be set prior to signing a transaction") - } - - var err error - if f.txParams.SignMode == apitxsigning.SignMode_SIGN_MODE_UNSPECIFIED { - f.txParams.SignMode = f.txConfig.SignModeHandler().DefaultMode() - } - - pubKey, err := f.keybase.GetPubKey(f.txParams.FromName) - if err != nil { - return nil, err - } - - addr, err := f.ac.BytesToString(pubKey.Address()) - if err != nil { - return nil, err - } - - signerData := signing.SignerData{ - ChainID: f.txParams.ChainID, - AccountNumber: f.txParams.AccountNumber, - Sequence: f.txParams.Sequence, - PubKey: &anypb.Any{ - TypeUrl: codectypes.MsgTypeURL(pubKey), - Value: pubKey.Bytes(), - }, - Address: addr, - } - - // For SIGN_MODE_DIRECT, we need to set the SignerInfos before generating - // the sign bytes. This is done by calling setSignatures with a nil - // signature, which in turn calls setSignerInfos internally. - // - // For SIGN_MODE_LEGACY_AMINO, this step is not strictly necessary, - // but we include it for consistency across all sign modes. - // It does not affect the generated sign bytes for LEGACY_AMINO. - // - // By setting the signatures here, we ensure that the correct SignerInfos - // are in place for all subsequent operations, regardless of the sign mode. - sigData := SingleSignatureData{ - SignMode: f.txParams.SignMode, - Signature: nil, - } - sig := Signature{ - PubKey: pubKey, - Data: &sigData, - Sequence: f.txParams.Sequence, - } - - var prevSignatures []Signature - if !overwriteSig { - tx, err := f.getTx() - if err != nil { - return nil, err - } - - prevSignatures, err = tx.GetSignatures() - if err != nil { - return nil, err - } - } - // Overwrite or append signer infos. - var sigs []Signature - if overwriteSig { - sigs = []Signature{sig} - } else { - sigs = append(sigs, prevSignatures...) - sigs = append(sigs, sig) - } - if err := f.setSignatures(sigs...); err != nil { - return nil, err - } - - tx, err := f.getTx() - if err != nil { - return nil, err - } - - if err := checkMultipleSigners(tx); err != nil { - return nil, err - } - - bytesToSign, err := f.getSignBytesAdapter(ctx, signerData) - if err != nil { - return nil, err - } - - // Sign those bytes - sigBytes, err := f.keybase.Sign(f.txParams.FromName, bytesToSign, f.txParams.SignMode) - if err != nil { - return nil, err - } - - // Construct the SignatureV2 struct - sigData = SingleSignatureData{ - SignMode: f.signMode(), - Signature: sigBytes, - } - sig = Signature{ - PubKey: pubKey, - Data: &sigData, - Sequence: f.txParams.Sequence, - } - - if overwriteSig { - err = f.setSignatures(sig) - } else { - prevSignatures = append(prevSignatures, sig) - err = f.setSignatures(prevSignatures...) - } - - if err != nil { - return nil, fmt.Errorf("unable to set signatures on payload: %w", err) - } - - return f.getTx() -} - -// getSignBytesAdapter returns the sign bytes for a given transaction and sign mode. -func (f *Factory) getSignBytesAdapter(ctx context.Context, signerData signing.SignerData) ([]byte, error) { - txData, err := f.getSigningTxData() - if err != nil { - return nil, err - } - - // Generate the bytes to be signed. - return f.txConfig.SignModeHandler().GetSignBytes(ctx, f.signMode(), signerData, *txData) -} - -// WithGas returns a copy of the Factory with an updated gas value. -func (f *Factory) WithGas(gas uint64) { - f.txParams.gas = gas -} - -// WithSequence returns a copy of the Factory with an updated sequence number. -func (f *Factory) WithSequence(sequence uint64) { - f.txParams.Sequence = sequence -} - -// WithAccountNumber returns a copy of the Factory with an updated account number. -func (f *Factory) WithAccountNumber(accnum uint64) { - f.txParams.AccountNumber = accnum -} - -// sequence returns the sequence number. -func (f *Factory) sequence() uint64 { return f.txParams.Sequence } - -// gasAdjustment returns the gas adjustment value. -func (f *Factory) gasAdjustment() float64 { return f.txParams.gasAdjustment } - -// simulateAndExecute returns whether to simulate and execute. -func (f *Factory) simulateAndExecute() bool { return f.txParams.simulateAndExecute } - -// signMode returns the sign mode. -func (f *Factory) signMode() apitxsigning.SignMode { return f.txParams.SignMode } - -// getSimPK gets the public key to use for building a simulation tx. -// Note, we should only check for keys in the keybase if we are in simulate and execute mode, -// e.g. when using --gas=auto. -// When using --dry-run, we are is simulation mode only and should not check the keybase. -// Ref: https://github.com/cosmos/cosmos-sdk/issues/11283 -func (f *Factory) getSimPK() (cryptotypes.PubKey, error) { - var ( - err error - pk cryptotypes.PubKey = &secp256k1.PubKey{} - ) - - if f.txParams.simulateAndExecute && f.keybase != nil { - pk, err = f.keybase.GetPubKey(f.txParams.FromName) - if err != nil { - return nil, err - } - } else { - // When in dry-run mode, attempt to retrieve the account using the provided address. - // If the account retrieval fails, the default public key is used. - acc, err := f.accountRetriever.GetAccount(context.Background(), f.txParams.Address) - if err != nil { - // If there is an error retrieving the account, return the default public key. - return pk, nil - } - // If the account is successfully retrieved, use its public key. - pk = acc.GetPubKey() - } - - return pk, nil -} - -// getSimSignatureData based on the pubKey type gets the correct SignatureData type -// to use for building a simulation tx. -func (f *Factory) getSimSignatureData(pk cryptotypes.PubKey) SignatureData { - multisigPubKey, ok := pk.(*multisig.LegacyAminoPubKey) - if !ok { - return &SingleSignatureData{SignMode: f.txParams.SignMode} - } - - multiSignatureData := make([]SignatureData, 0, multisigPubKey.Threshold) - for i := uint32(0); i < multisigPubKey.Threshold; i++ { - multiSignatureData = append(multiSignatureData, &SingleSignatureData{ - SignMode: f.signMode(), - }) - } - - return &MultiSignatureData{ - BitArray: &apicrypto.CompactBitArray{}, - Signatures: multiSignatureData, - } -} - -func (f *Factory) getTx() (*wrappedTx, error) { - msgs, err := msgsV1toAnyV2(f.tx.msgs) - if err != nil { - return nil, err - } - - body := &apitx.TxBody{ - Messages: msgs, - Memo: f.tx.memo, - TimeoutHeight: f.tx.timeoutHeight, - ExtensionOptions: f.tx.extensionOptions, - NonCriticalExtensionOptions: f.tx.nonCriticalExtensionOptions, - } - - fee, err := f.getFee() - if err != nil { - return nil, err - } - - authInfo := &apitx.AuthInfo{ - SignerInfos: f.tx.signerInfos, - Fee: fee, - } - - bodyBytes, err := marshalOption.Marshal(body) - if err != nil { - return nil, err - } - - authInfoBytes, err := marshalOption.Marshal(authInfo) - if err != nil { - return nil, err - } - - txRawBytes, err := marshalOption.Marshal(&apitx.TxRaw{ - BodyBytes: bodyBytes, - AuthInfoBytes: authInfoBytes, - Signatures: f.tx.signatures, - }) - if err != nil { - return nil, err - } - - decodedTx, err := f.txConfig.Decoder().Decode(txRawBytes) - if err != nil { - return nil, err - } - - return newWrapperTx(f.cdc, decodedTx), nil -} - -// getSigningTxData returns a TxData with the current txState info. -func (f *Factory) getSigningTxData() (*signing.TxData, error) { - tx, err := f.getTx() - if err != nil { - return nil, err - } - - return &signing.TxData{ - Body: tx.Tx.Body, - AuthInfo: tx.Tx.AuthInfo, - BodyBytes: tx.TxRaw.BodyBytes, - AuthInfoBytes: tx.TxRaw.AuthInfoBytes, - BodyHasUnknownNonCriticals: tx.TxBodyHasUnknownNonCriticals, - }, nil -} - -// setSignatures sets the signatures for the transaction builder. -// It takes a variable number of Signature arguments and processes each one to extract the mode information and raw signature. -// It also converts the public key to the appropriate format and sets the signer information. -func (f *Factory) setSignatures(signatures ...Signature) error { - n := len(signatures) - signerInfos := make([]*apitx.SignerInfo, n) - rawSignatures := make([][]byte, n) - - for i, sig := range signatures { - var ( - modeInfo *apitx.ModeInfo - pubKey *codectypes.Any - err error - anyPk *anypb.Any - ) - - modeInfo, rawSignatures[i] = signatureDataToModeInfoAndSig(sig.Data) - if sig.PubKey != nil { - pubKey, err = codectypes.NewAnyWithValue(sig.PubKey) - if err != nil { - return err - } - anyPk = &anypb.Any{ - TypeUrl: pubKey.TypeUrl, - Value: pubKey.Value, - } - } - - signerInfos[i] = &apitx.SignerInfo{ - PublicKey: anyPk, - ModeInfo: modeInfo, - Sequence: sig.Sequence, - } - } - - f.tx.signerInfos = signerInfos - f.tx.signatures = rawSignatures - - return nil -} - -// getFee computes the transaction fee information. -// It returns a pointer to an apitx.Fee struct containing the fee amount, gas limit, payer, and granter information. -// If the granter or payer addresses are set, it converts them from bytes to string using the addressCodec. -func (f *Factory) getFee() (fee *apitx.Fee, err error) { - granterStr := "" - if f.tx.granter != nil { - granterStr, err = f.ac.BytesToString(f.tx.granter) - if err != nil { - return nil, err - } - } - - payerStr := "" - if f.tx.payer != nil { - payerStr, err = f.ac.BytesToString(f.tx.payer) - if err != nil { - return nil, err - } - } - - fee = &apitx.Fee{ - Amount: f.tx.fees, - GasLimit: f.tx.gasLimit, - Payer: payerStr, - Granter: granterStr, - } - - return fee, nil -} - -// setFeePayer sets the fee payer for the transaction. -func (f *Factory) setFeePayer(feePayer string) error { - if feePayer == "" { - return nil - } - - addr, err := f.ac.StringToBytes(feePayer) - if err != nil { - return err - } - f.tx.payer = addr - return nil -} - -// setFeeGranter sets the fee granter's address in the transaction builder. -// If the feeGranter string is empty, the function returns nil without setting an address. -// It converts the feeGranter string to bytes using the address codec and sets it as the granter address. -// Returns an error if the conversion fails. -func (f *Factory) setFeeGranter(feeGranter string) error { - if feeGranter == "" { - return nil - } - - addr, err := f.ac.StringToBytes(feeGranter) - if err != nil { - return err - } - f.tx.granter = addr - - return nil -} - -// msgsV1toAnyV2 converts a slice of sdk.Msg (v1) to a slice of anypb.Any (v2). -// It first converts each sdk.Msg into a codectypes.Any and then converts -// these into anypb.Any. -func msgsV1toAnyV2(msgs []sdk.Msg) ([]*anypb.Any, error) { - anys := make([]*codectypes.Any, len(msgs)) - for i, msg := range msgs { - anyMsg, err := codectypes.NewAnyWithValue(msg) - if err != nil { - return nil, err - } - anys[i] = anyMsg - } - - return intoAnyV2(anys), nil -} - -// intoAnyV2 converts a slice of codectypes.Any (v1) to a slice of anypb.Any (v2). -func intoAnyV2(v1s []*codectypes.Any) []*anypb.Any { - v2s := make([]*anypb.Any, len(v1s)) - for i, v1 := range v1s { - v2s[i] = &anypb.Any{ - TypeUrl: v1.TypeUrl, - Value: v1.Value, - } - } - return v2s -} - -// checkMultipleSigners checks that there can be maximum one DIRECT signer in -// a tx. -func checkMultipleSigners(tx Tx) error { - directSigners := 0 - sigsV2, err := tx.GetSignatures() - if err != nil { - return err - } - for _, sig := range sigsV2 { - directSigners += countDirectSigners(sig.Data) - if directSigners > 1 { - return errors.New("txs signed with CLI can have maximum 1 DIRECT signer") - } - } - - return nil -} - -// validateMemo validates the memo field. -func validateMemo(memo string) error { - // Prevent simple inclusion of a valid mnemonic in the memo field - if memo != "" && bip39.IsMnemonicValid(strings.ToLower(memo)) { - return errors.New("cannot provide a valid mnemonic seed in the memo field") - } - - return nil -} diff --git a/connect/internal/tx/factory_test.go b/connect/internal/tx/factory_test.go deleted file mode 100644 index 4bf4fc1a..00000000 --- a/connect/internal/tx/factory_test.go +++ /dev/null @@ -1,907 +0,0 @@ -package tx - -import ( - "context" - "testing" - - "github.com/stretchr/testify/require" - "google.golang.org/protobuf/types/known/anypb" - - banktypes "cosmossdk.io/api/cosmos/bank/v1beta1" - base "cosmossdk.io/api/cosmos/base/v1beta1" - apitxsigning "cosmossdk.io/api/cosmos/tx/signing/v1beta1" - "cosmossdk.io/x/tx/signing" - - codectypes "github.com/cosmos/cosmos-sdk/codec/types" - cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" - "github.com/cosmos/cosmos-sdk/crypto/keys/multisig" - "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" - cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" - sdk "github.com/cosmos/cosmos-sdk/types" -) - -var ( - FromAddress = "cosmos1zglwfu6xjzvzagqcmvzewyzjp9xwqw5qwrr8n9" - addr, _ = ac.StringToBytes(FromAddress) -) - -func TestFactory_prepareTxParams(t *testing.T) { - tests := []struct { - name string - txParams TxParameters - error bool - }{ - { - name: "no error", - txParams: TxParameters{ - AccountConfig: AccountConfig{ - Address: addr, - }, - }, - }, - { - name: "without account", - txParams: TxParameters{}, - error: true, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - var err error - tt.txParams, err = prepareTxParams(tt.txParams, mockAccountRetriever{}, false) - if (err != nil) != tt.error { - t.Errorf("Prepare() error = %v, wantErr %v", err, tt.error) - } - }) - } -} - -func TestFactory_BuildUnsignedTx(t *testing.T) { - tests := []struct { - name string - txParams TxParameters - msgs []sdk.Msg - error bool - }{ - { - name: "no error", - txParams: TxParameters{ - ChainID: "demo", - AccountConfig: AccountConfig{ - Address: addr, - }, - }, - msgs: []sdk.Msg{ - &banktypes.MsgSend{ - FromAddress: FromAddress, - }, - }, - }, - { - name: "fees and gas price provided", - txParams: TxParameters{ - ChainID: "demo", - AccountConfig: AccountConfig{ - Address: addr, - }, - GasConfig: GasConfig{ - gasPrices: []*base.DecCoin{ - { - Amount: "1000", - Denom: "stake", - }, - }, - }, - FeeConfig: FeeConfig{ - fees: []*base.Coin{ - { - Amount: "1000", - Denom: "stake", - }, - }, - }, - }, - msgs: []sdk.Msg{}, - error: true, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - f, err := NewFactory(keybase, cdc, mockAccountRetriever{}, txConf, ac, mockClientConn{}, tt.txParams) - require.NoError(t, err) - require.NotNil(t, f) - err = f.BuildUnsignedTx(tt.msgs...) - if tt.error { - require.Error(t, err) - } else { - require.NoError(t, err) - require.Nil(t, f.tx.signatures) - } - }) - } -} - -func TestFactory_calculateGas(t *testing.T) { - tests := []struct { - name string - txParams TxParameters - msgs []sdk.Msg - error bool - }{ - { - name: "no error", - txParams: TxParameters{ - ChainID: "demo", - AccountConfig: AccountConfig{ - Address: addr, - }, - GasConfig: GasConfig{ - gasAdjustment: 1, - }, - }, - msgs: []sdk.Msg{ - &banktypes.MsgSend{ - FromAddress: FromAddress, - }, - }, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - f, err := NewFactory(keybase, cdc, mockAccountRetriever{}, txConf, ac, mockClientConn{}, tt.txParams) - require.NoError(t, err) - require.NotNil(t, f) - err = f.calculateGas(tt.msgs...) - if tt.error { - require.Error(t, err) - } else { - require.NoError(t, err) - require.NotZero(t, f.txParams.GasConfig) - } - }) - } -} - -func TestFactory_Simulate(t *testing.T) { - tests := []struct { - name string - txParams TxParameters - msgs []sdk.Msg - error bool - }{ - { - name: "no error", - txParams: TxParameters{ - ChainID: "demo", - AccountConfig: AccountConfig{ - Address: addr, - }, - GasConfig: GasConfig{ - gasAdjustment: 1, - }, - }, - msgs: []sdk.Msg{ - &banktypes.MsgSend{ - FromAddress: FromAddress, - }, - }, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - f, err := NewFactory(keybase, cdc, mockAccountRetriever{}, txConf, ac, mockClientConn{}, tt.txParams) - require.NoError(t, err) - require.NotNil(t, f) - got, got1, err := f.Simulate(tt.msgs...) - if tt.error { - require.Error(t, err) - } else { - require.NoError(t, err) - require.NotNil(t, got) - require.NotZero(t, got1) - } - }) - } -} - -func TestFactory_BuildSimTx(t *testing.T) { - tests := []struct { - name string - txParams TxParameters - msgs []sdk.Msg - want []byte - error bool - }{ - { - name: "no error", - txParams: TxParameters{ - ChainID: "demo", - AccountConfig: AccountConfig{ - Address: addr, - }, - }, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - f, err := NewFactory(keybase, cdc, mockAccountRetriever{}, txConf, ac, mockClientConn{}, tt.txParams) - require.NoError(t, err) - require.NotNil(t, f) - got, err := f.BuildSimTx(tt.msgs...) - if tt.error { - require.Error(t, err) - } else { - require.NoError(t, err) - require.NotNil(t, got) - } - }) - } -} - -func TestFactory_Sign(t *testing.T) { - tests := []struct { - name string - txParams TxParameters - wantErr bool - }{ - { - name: "no error", - txParams: TxParameters{ - ChainID: "demo", - AccountConfig: AccountConfig{ - FromName: "alice", - Address: addr, - }, - }, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - f, err := NewFactory(setKeyring(), cdc, mockAccountRetriever{}, txConf, ac, mockClientConn{}, tt.txParams) - require.NoError(t, err) - require.NotNil(t, f) - - err = f.BuildUnsignedTx([]sdk.Msg{ - &banktypes.MsgSend{ - FromAddress: FromAddress, - }, - }...) - require.NoError(t, err) - - require.Nil(t, f.tx.signatures) - - tx, err := f.sign(context.Background(), true) - if tt.wantErr { - require.Error(t, err) - } else { - require.NoError(t, err) - sigs, err := tx.GetSignatures() - require.NoError(t, err) - require.NotNil(t, sigs) - } - }) - } -} - -func TestFactory_getSignBytesAdapter(t *testing.T) { - tests := []struct { - name string - txParams TxParameters - error bool - }{ - { - name: "no error", - txParams: TxParameters{ - ChainID: "demo", - SignMode: apitxsigning.SignMode_SIGN_MODE_DIRECT, - AccountConfig: AccountConfig{ - Address: addr, - }, - }, - }, - { - name: "signMode not specified", - txParams: TxParameters{ - ChainID: "demo", - AccountConfig: AccountConfig{ - Address: addr, - }, - }, - error: true, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - f, err := NewFactory(setKeyring(), cdc, mockAccountRetriever{}, txConf, ac, mockClientConn{}, tt.txParams) - require.NoError(t, err) - require.NotNil(t, f) - - err = f.BuildUnsignedTx([]sdk.Msg{ - &banktypes.MsgSend{ - FromAddress: FromAddress, - }, - }...) - require.NoError(t, err) - - pk, err := f.keybase.GetPubKey("alice") - require.NoError(t, err) - require.NotNil(t, pk) - - addr, err := f.ac.BytesToString(pk.Address()) - require.NoError(t, err) - require.NotNil(t, addr) - - FromAddressData := signing.SignerData{ - Address: addr, - ChainID: f.txParams.ChainID, - AccountNumber: 0, - Sequence: 0, - PubKey: &anypb.Any{ - TypeUrl: codectypes.MsgTypeURL(pk), - Value: pk.Bytes(), - }, - } - - got, err := f.getSignBytesAdapter(context.Background(), FromAddressData) - if tt.error { - require.Error(t, err) - } else { - require.NoError(t, err) - require.NotNil(t, got) - } - }) - } -} - -func Test_validateMemo(t *testing.T) { - tests := []struct { - name string - memo string - wantErr bool - }{ - { - name: "empty memo", - memo: "", - }, - { - name: "valid memo", - memo: "11245", - }, - { - name: "invalid Memo", - memo: "echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo", - wantErr: true, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if err := validateMemo(tt.memo); (err != nil) != tt.wantErr { - t.Errorf("validateMemo() error = %v, wantErr %v", err, tt.wantErr) - } - }) - } -} - -func TestFactory_WithFunctions(t *testing.T) { - tests := []struct { - name string - txParams TxParameters - withFunc func(*Factory) - checkFunc func(*Factory) bool - }{ - { - name: "with gas", - txParams: TxParameters{ - AccountConfig: AccountConfig{ - Address: addr, - }, - }, - withFunc: func(f *Factory) { - f.WithGas(1000) - }, - checkFunc: func(f *Factory) bool { - return f.txParams.GasConfig.gas == 1000 - }, - }, - { - name: "with sequence", - txParams: TxParameters{ - AccountConfig: AccountConfig{ - Address: addr, - }, - }, - withFunc: func(f *Factory) { - f.WithSequence(10) - }, - checkFunc: func(f *Factory) bool { - return f.txParams.AccountConfig.Sequence == 10 - }, - }, - { - name: "with account number", - txParams: TxParameters{ - AccountConfig: AccountConfig{ - Address: addr, - }, - }, - withFunc: func(f *Factory) { - f.WithAccountNumber(123) - }, - checkFunc: func(f *Factory) bool { - return f.txParams.AccountConfig.AccountNumber == 123 - }, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - f, err := NewFactory(setKeyring(), cdc, mockAccountRetriever{}, txConf, ac, mockClientConn{}, tt.txParams) - require.NoError(t, err) - require.NotNil(t, f) - - tt.withFunc(&f) - require.True(t, tt.checkFunc(&f)) - }) - } -} - -func TestFactory_getTx(t *testing.T) { - tests := []struct { - name string - txSetter func(f *Factory) - checkResult func(Tx) - }{ - { - name: "empty tx", - txSetter: func(f *Factory) { - }, - checkResult: func(tx Tx) { - wTx, ok := tx.(*wrappedTx) - require.True(t, ok) - // require.Equal(t, []*anypb.Any(nil), wTx.Tx.Body.Messages) - require.Nil(t, wTx.Tx.Body.Messages) - require.Empty(t, wTx.Tx.Body.Memo) - require.Equal(t, uint64(0), wTx.Tx.Body.TimeoutHeight) - require.Nil(t, wTx.Tx.Body.ExtensionOptions) - require.Nil(t, wTx.Tx.Body.NonCriticalExtensionOptions) - - require.Nil(t, wTx.Tx.AuthInfo.Fee.Amount) - require.Equal(t, uint64(0), wTx.Tx.AuthInfo.Fee.GasLimit) - require.Empty(t, wTx.Tx.AuthInfo.Fee.Payer) - require.Empty(t, wTx.Tx.AuthInfo.Fee.Granter) - - require.Nil(t, wTx.Tx.Signatures) - }, - }, - { - name: "full tx", - txSetter: func(f *Factory) { - pk := secp256k1.GenPrivKey().PubKey() - addr, _ := f.ac.BytesToString(pk.Address()) - - f.tx.msgs = []sdk.Msg{&banktypes.MsgSend{ - FromAddress: addr, - }} - - err := f.setFeePayer(addr) - require.NoError(t, err) - - f.tx.fees = []*base.Coin{{ - Denom: "cosmos", - Amount: "1000", - }} - - err = f.setSignatures([]Signature{{ - PubKey: pk, - Data: &SingleSignatureData{ - SignMode: apitxsigning.SignMode_SIGN_MODE_DIRECT, - Signature: nil, - }, - Sequence: 0, - }}...) - require.NoError(t, err) - }, - checkResult: func(tx Tx) { - wTx, ok := tx.(*wrappedTx) - require.True(t, ok) - require.True(t, len(wTx.Tx.Body.Messages) == 1) - - require.NotNil(t, wTx.Tx.AuthInfo.Fee.Amount) - require.NotNil(t, wTx.Tx.Signatures) - }, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - f, err := NewFactory(keybase, cdc, mockAccountRetriever{}, txConf, ac, mockClientConn{}, TxParameters{}) - require.NoError(t, err) - tt.txSetter(&f) - got, err := f.getTx() - require.NoError(t, err) - require.NotNil(t, got) - tt.checkResult(got) - }) - } -} - -func TestFactory_getFee(t *testing.T) { - tests := []struct { - name string - feeAmount []*base.Coin - feeGranter string - feePayer string - }{ - { - name: "get fee with payer", - feeAmount: []*base.Coin{ - { - Denom: "cosmos", - Amount: "1000", - }, - }, - feeGranter: "", - feePayer: "cosmos1zglwfu6xjzvzagqcmvzewyzjp9xwqw5qwrr8n9", - }, - { - name: "get fee with granter", - feeAmount: []*base.Coin{ - { - Denom: "cosmos", - Amount: "1000", - }, - }, - feeGranter: "cosmos1zglwfu6xjzvzagqcmvzewyzjp9xwqw5qwrr8n9", - feePayer: "", - }, - { - name: "get fee with granter and granter", - feeAmount: []*base.Coin{ - { - Denom: "cosmos", - Amount: "1000", - }, - }, - feeGranter: "cosmos1zglwfu6xjzvzagqcmvzewyzjp9xwqw5qwrr8n9", - feePayer: "cosmos1zglwfu6xjzvzagqcmvzewyzjp9xwqw5qwrr8n9", - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - f, err := NewFactory(keybase, cdc, mockAccountRetriever{}, txConf, ac, mockClientConn{}, TxParameters{}) - require.NoError(t, err) - f.tx.fees = tt.feeAmount - err = f.setFeeGranter(tt.feeGranter) - require.NoError(t, err) - err = f.setFeePayer(tt.feePayer) - require.NoError(t, err) - - fee, err := f.getFee() - require.NoError(t, err) - require.NotNil(t, fee) - - require.Equal(t, fee.Amount, tt.feeAmount) - require.Equal(t, fee.Granter, tt.feeGranter) - require.Equal(t, fee.Payer, tt.feePayer) - }) - } -} - -func TestFactory_getSigningTxData(t *testing.T) { - tests := []struct { - name string - txSetter func(f *Factory) - }{ - { - name: "empty tx", - txSetter: func(f *Factory) {}, - }, - { - name: "full tx", - txSetter: func(f *Factory) { - pk := secp256k1.GenPrivKey().PubKey() - addr, _ := ac.BytesToString(pk.Address()) - - f.tx.msgs = []sdk.Msg{&banktypes.MsgSend{ - FromAddress: addr, - }} - - err := f.setFeePayer(addr) - require.NoError(t, err) - - f.tx.fees = []*base.Coin{{ - Denom: "cosmos", - Amount: "1000", - }} - - err = f.setSignatures([]Signature{{ - PubKey: pk, - Data: &SingleSignatureData{ - SignMode: apitxsigning.SignMode_SIGN_MODE_DIRECT, - Signature: []byte("signature"), - }, - Sequence: 0, - }}...) - require.NoError(t, err) - }, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - f, err := NewFactory(keybase, cdc, mockAccountRetriever{}, txConf, ac, mockClientConn{}, TxParameters{}) - require.NoError(t, err) - tt.txSetter(&f) - got, err := f.getSigningTxData() - require.NoError(t, err) - require.NotNil(t, got) - }) - } -} - -func TestFactory_setMsgs(t *testing.T) { - tests := []struct { - name string - msgs []sdk.Msg - wantErr bool - }{ - { - name: "set msgs", - msgs: []sdk.Msg{ - &banktypes.MsgSend{ - FromAddress: "cosmos1zglwfu6xjzvzagqcmvzewyzjp9xwqw5qwrr8n9", - ToAddress: "cosmos1zglwfu6xjzvzagqcmvzewyzjp9xwqw5qwrr8n9", - }, - &banktypes.MsgSend{ - FromAddress: "cosmos1zglwfu6xjzvzagqcmvzewyzjp9xwqw5qwrr8n9", - ToAddress: "cosmos1zglwfu6xjzvzagqcmvzewyzjp9xwqw5qwrr8n9", - }, - }, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - f, err := NewFactory(keybase, cdc, mockAccountRetriever{}, txConf, ac, mockClientConn{}, TxParameters{}) - require.NoError(t, err) - f.tx.msgs = tt.msgs - require.NoError(t, err) - require.Equal(t, len(tt.msgs), len(f.tx.msgs)) - - for i, msg := range tt.msgs { - require.Equal(t, msg, f.tx.msgs[i]) - } - }) - } -} - -func TestFactory_SetMemo(t *testing.T) { - tests := []struct { - name string - memo string - }{ - { - name: "set memo", - memo: "test", - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - f, err := NewFactory(keybase, cdc, mockAccountRetriever{}, txConf, ac, mockClientConn{}, TxParameters{}) - require.NoError(t, err) - f.tx.memo = tt.memo - require.Equal(t, f.tx.memo, tt.memo) - }) - } -} - -func TestFactory_SetFeeAmount(t *testing.T) { - tests := []struct { - name string - coins []*base.Coin - }{ - { - name: "set coins", - coins: []*base.Coin{ - { - Denom: "cosmos", - Amount: "1000", - }, - }, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - f, err := NewFactory(keybase, cdc, mockAccountRetriever{}, txConf, ac, mockClientConn{}, TxParameters{}) - require.NoError(t, err) - f.tx.fees = tt.coins - require.Equal(t, len(tt.coins), len(f.tx.fees)) - - for i, coin := range tt.coins { - require.Equal(t, coin.Amount, f.tx.fees[i].Amount) - } - }) - } -} - -func TestFactory_SetGasLimit(t *testing.T) { - tests := []struct { - name string - gasLimit uint64 - }{ - { - name: "set gas limit", - gasLimit: 1, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - f, err := NewFactory(keybase, cdc, mockAccountRetriever{}, txConf, ac, mockClientConn{}, TxParameters{}) - require.NoError(t, err) - f.tx.gasLimit = tt.gasLimit - require.Equal(t, f.tx.gasLimit, tt.gasLimit) - }) - } -} - -func TestFactory_SetUnordered(t *testing.T) { - tests := []struct { - name string - unordered bool - }{ - { - name: "unordered", - unordered: true, - }, - { - name: "not unordered", - unordered: false, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - f, err := NewFactory(keybase, cdc, mockAccountRetriever{}, txConf, ac, mockClientConn{}, TxParameters{}) - require.NoError(t, err) - f.tx.unordered = tt.unordered - require.Equal(t, f.tx.unordered, tt.unordered) - }) - } -} - -func TestFactory_setSignatures(t *testing.T) { - tests := []struct { - name string - signatures func() []Signature - }{ - { - name: "set empty single signature", - signatures: func() []Signature { - return []Signature{{ - PubKey: secp256k1.GenPrivKey().PubKey(), - Data: &SingleSignatureData{ - SignMode: apitxsigning.SignMode_SIGN_MODE_DIRECT, - Signature: nil, - }, - Sequence: 0, - }} - }, - }, - { - name: "set single signature", - signatures: func() []Signature { - return []Signature{{ - PubKey: secp256k1.GenPrivKey().PubKey(), - Data: &SingleSignatureData{ - SignMode: apitxsigning.SignMode_SIGN_MODE_DIRECT, - Signature: []byte("signature"), - }, - Sequence: 0, - }} - }, - }, - { - name: "set empty multi signature", - signatures: func() []Signature { - return []Signature{{ - PubKey: multisig.NewLegacyAminoPubKey(1, []cryptotypes.PubKey{secp256k1.GenPrivKey().PubKey()}), - Data: &MultiSignatureData{ - BitArray: nil, - Signatures: []SignatureData{ - &SingleSignatureData{ - SignMode: apitxsigning.SignMode_SIGN_MODE_DIRECT, - Signature: nil, - }, - }, - }, - Sequence: 0, - }} - }, - }, - { - name: "set multi signature", - signatures: func() []Signature { - return []Signature{{ - PubKey: multisig.NewLegacyAminoPubKey(1, []cryptotypes.PubKey{secp256k1.GenPrivKey().PubKey()}), - Data: &MultiSignatureData{ - BitArray: nil, - Signatures: []SignatureData{ - &SingleSignatureData{ - SignMode: apitxsigning.SignMode_SIGN_MODE_DIRECT, - Signature: []byte("signature"), - }, - }, - }, - Sequence: 0, - }} - }, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - cryptocodec.RegisterInterfaces(cdc.InterfaceRegistry()) - f, err := NewFactory(keybase, cdc, mockAccountRetriever{}, txConf, ac, mockClientConn{}, TxParameters{}) - require.NoError(t, err) - sigs := tt.signatures() - err = f.setSignatures(sigs...) - require.NoError(t, err) - tx, err := f.getTx() - require.NoError(t, err) - signatures, err := tx.GetSignatures() - require.NoError(t, err) - require.Equal(t, len(sigs), len(signatures)) - for i := range signatures { - require.Equal(t, sigs[i].PubKey, signatures[i].PubKey) - } - }) - } -} - -/////////////////////// - -func Test_msgsV1toAnyV2(t *testing.T) { - tests := []struct { - name string - msgs []sdk.Msg - }{ - { - name: "convert msgV1 to V2", - msgs: []sdk.Msg{ - &banktypes.MsgSend{ - FromAddress: "cosmos1zglwfu6xjzvzagqcmvzewyzjp9xwqw5qwrr8n9", - ToAddress: "cosmos1zglwfu6xjzvzagqcmvzewyzjp9xwqw5qwrr8n9", - }, - }, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - got, err := msgsV1toAnyV2(tt.msgs) - require.NoError(t, err) - require.NotNil(t, got) - }) - } -} - -func Test_intoAnyV2(t *testing.T) { - tests := []struct { - name string - msgs []*codectypes.Any - }{ - { - name: "any to v2", - msgs: []*codectypes.Any{ - { - TypeUrl: "/random/msg", - Value: []byte("random message"), - }, - }, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - got := intoAnyV2(tt.msgs) - require.NotNil(t, got) - require.Equal(t, len(got), len(tt.msgs)) - for i, msg := range got { - require.Equal(t, msg.TypeUrl, tt.msgs[i].TypeUrl) - require.Equal(t, msg.Value, tt.msgs[i].Value) - } - }) - } -} diff --git a/connect/internal/tx/flags.go b/connect/internal/tx/flags.go deleted file mode 100644 index 9d0a7c4a..00000000 --- a/connect/internal/tx/flags.go +++ /dev/null @@ -1,52 +0,0 @@ -package tx - -import ( - "fmt" - "strconv" -) - -// Flag constants for transaction-related flags -const ( - defaultGasLimit = 200000 - gasFlagAuto = "auto" - - FlagTimeoutTimestamp = "timeout-timestamp" - FlagChainID = "chain-id" - FlagNote = "note" - FlagSignMode = "sign-mode" - FlagAccountNumber = "account-number" - FlagSequence = "sequence" - FlagFrom = "from" - FlagDryRun = "dry-run" - FlagGas = "gas" - FlagGasAdjustment = "gas-adjustment" - FlagGasPrices = "gas-prices" - FlagFees = "fees" - FlagFeePayer = "fee-payer" - FlagFeeGranter = "fee-granter" - FlagUnordered = "unordered" - FlagOffline = "offline" - FlagGenerateOnly = "generate-only" -) - -// parseGasSetting parses a string gas value. The value may either be 'auto', -// which indicates a transaction should be executed in simulate mode to -// automatically find a sufficient gas value, or a string integer. It returns an -// error if a string integer is provided which cannot be parsed. -func parseGasSetting(gasStr string) (bool, uint64, error) { - switch gasStr { - case "": - return false, defaultGasLimit, nil - - case gasFlagAuto: - return true, 0, nil - - default: - gas, err := strconv.ParseUint(gasStr, 10, 64) - if err != nil { - return false, 0, fmt.Errorf("gas must be either integer or %s", gasFlagAuto) - } - - return false, gas, nil - } -} diff --git a/connect/internal/tx/from.go b/connect/internal/tx/from.go deleted file mode 100644 index faeae731..00000000 --- a/connect/internal/tx/from.go +++ /dev/null @@ -1,80 +0,0 @@ -package tx - -import ( - "fmt" - - "cosmossdk.io/core/address" - "github.com/spf13/cobra" - - "github.com/cosmos/cosmos-sdk/client/flags" - - sdkkeyring "github.com/cosmos/cosmos-sdk/crypto/keyring" - sdk "github.com/cosmos/cosmos-sdk/types" -) - -// GetFromAddress gets the from address from the cobra command. -func GetFromAddress(cmd *cobra.Command, addressCodec address.Codec) (string, error) { - from, err := cmd.Flags().GetString(flags.FlagFrom) - if err != nil { - return "", err - } - - txCtx, err := GetContext(cmd.Context()) - if err != nil { - return "", err - } - - fromAddr, keyType, err := GetFromFields(txCtx, from) - if err != nil { - return "", fmt.Errorf("failed to convert address field to address: %w", err) - } - - if keyType == sdkkeyring.TypeLedger { - // Set sign-mode flag to legacy Amino JSON when using a Ledger key. - _ = cmd.Flags().Set(flags.FlagSignMode, flags.SignModeLegacyAminoJSON) - } - - fromAddrStr, err := addressCodec.BytesToString(fromAddr) - if err != nil { - return "", fmt.Errorf("failed to convert address to string: %w", err) - } - - return fromAddrStr, nil -} - -// GetFromFields returns a from account address and keyring type, given either an address or key name. -func GetFromFields(ctx Context, from string) (sdk.AccAddress, sdkkeyring.KeyType, error) { - if from == "" { - from = ctx.Keyring.DefaultKey() - if from == "" { - return nil, 0, fmt.Errorf("no key name or address provided") - } - } - - addr, err := ctx.AddressCodec.StringToBytes(from) - var k *sdkkeyring.Record - - sdkKeyring, ok := ctx.Keyring.Impl().(sdkkeyring.Keyring) - if !ok { - return nil, 0, fmt.Errorf("keyring does not implement sdkkeyring.Keyring") - } - - if err == nil { - k, err = sdkKeyring.KeyByAddress(sdk.AccAddress(addr)) - if err != nil { - return nil, 0, err - } - } else { - k, err = sdkKeyring.Key(from) - if err != nil { - return nil, 0, err - } - } - - addr, err = k.GetAddress() - if err != nil { - return nil, 0, err - } - - return addr, k.GetType(), nil -} diff --git a/connect/internal/tx/signature.go b/connect/internal/tx/signature.go deleted file mode 100644 index 66235380..00000000 --- a/connect/internal/tx/signature.go +++ /dev/null @@ -1,197 +0,0 @@ -package tx - -import ( - "errors" - "fmt" - - apicrypto "cosmossdk.io/api/cosmos/crypto/multisig/v1beta1" - apitxsigning "cosmossdk.io/api/cosmos/tx/signing/v1beta1" - apitx "cosmossdk.io/api/cosmos/tx/v1beta1" - - cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" -) - -// Signature holds the necessary components to verify transaction signatures. -type Signature struct { - PubKey cryptotypes.PubKey // Public key for signature verification. - Data SignatureData // Signature data containing the actual signatures. - Sequence uint64 // Account sequence, relevant for SIGN_MODE_DIRECT. -} - -// SignatureData defines an interface for different signature data types. -type SignatureData interface { - isSignatureData() -} - -// SingleSignatureData stores a single signer's signature and its mode. -type SingleSignatureData struct { - SignMode apitxsigning.SignMode // Mode of the signature. - Signature []byte // Actual binary signature. -} - -// MultiSignatureData encapsulates signatures from a multisig transaction. -type MultiSignatureData struct { - BitArray *apicrypto.CompactBitArray // Bitmap of signers. - Signatures []SignatureData // Individual signatures. -} - -func (m *SingleSignatureData) isSignatureData() {} -func (m *MultiSignatureData) isSignatureData() {} - -// signatureDataToModeInfoAndSig converts SignatureData to ModeInfo and its corresponding raw signature. -func signatureDataToModeInfoAndSig(data SignatureData) (*apitx.ModeInfo, []byte) { - if data == nil { - return nil, nil - } - - switch data := data.(type) { - case *SingleSignatureData: - return &apitx.ModeInfo{ - Sum: &apitx.ModeInfo_Single_{ - Single: &apitx.ModeInfo_Single{Mode: data.SignMode}, - }, - }, data.Signature - case *MultiSignatureData: - modeInfos := make([]*apitx.ModeInfo, len(data.Signatures)) - sigs := make([][]byte, len(data.Signatures)) - - for i, d := range data.Signatures { - modeInfos[i], sigs[i] = signatureDataToModeInfoAndSig(d) - } - - multisig := cryptotypes.MultiSignature{Signatures: sigs} - sig, err := multisig.Marshal() - if err != nil { - panic(err) - } - - return &apitx.ModeInfo{ - Sum: &apitx.ModeInfo_Multi_{ - Multi: &apitx.ModeInfo_Multi{ - Bitarray: data.BitArray, - ModeInfos: modeInfos, - }, - }, - }, sig - default: - panic(fmt.Sprintf("unexpected signature data type %T", data)) - } -} - -// modeInfoAndSigToSignatureData converts ModeInfo and a raw signature to SignatureData. -func modeInfoAndSigToSignatureData(modeInfo *apitx.ModeInfo, sig []byte) (SignatureData, error) { - switch mi := modeInfo.Sum.(type) { - case *apitx.ModeInfo_Single_: - return &SingleSignatureData{ - SignMode: mi.Single.Mode, - Signature: sig, - }, nil - - case *apitx.ModeInfo_Multi_: - multi := mi.Multi - - sigs, err := decodeMultiSignatures(sig) - if err != nil { - return nil, err - } - - sigsV2 := make([]SignatureData, len(sigs)) - for i, mi := range multi.ModeInfos { - sigsV2[i], err = modeInfoAndSigToSignatureData(mi, sigs[i]) - if err != nil { - return nil, err - } - } - return &MultiSignatureData{ - BitArray: multi.Bitarray, - Signatures: sigsV2, - }, nil - } - - return nil, fmt.Errorf("unsupported ModeInfo type %T", modeInfo) -} - -// decodeMultiSignatures decodes a byte array into individual signatures. -func decodeMultiSignatures(bz []byte) ([][]byte, error) { - multisig := cryptotypes.MultiSignature{} - - err := multisig.Unmarshal(bz) - if err != nil { - return nil, err - } - - if len(multisig.XXX_unrecognized) > 0 { - return nil, errors.New("unrecognized fields in MultiSignature") - } - return multisig.Signatures, nil -} - -// signatureDataToProto converts a SignatureData interface to a protobuf SignatureDescriptor_Data. -// This function supports both SingleSignatureData and MultiSignatureData types. -// For SingleSignatureData, it directly maps the signature mode and signature bytes to the protobuf structure. -// For MultiSignatureData, it recursively converts each signature in the collection to the corresponding protobuf structure. -func signatureDataToProto(data SignatureData) (*apitxsigning.SignatureDescriptor_Data, error) { - switch data := data.(type) { - case *SingleSignatureData: - // Handle single signature data conversion. - return &apitxsigning.SignatureDescriptor_Data{ - Sum: &apitxsigning.SignatureDescriptor_Data_Single_{ - Single: &apitxsigning.SignatureDescriptor_Data_Single{ - Mode: data.SignMode, - Signature: data.Signature, - }, - }, - }, nil - case *MultiSignatureData: - var err error - descDatas := make([]*apitxsigning.SignatureDescriptor_Data, len(data.Signatures)) - - for i, j := range data.Signatures { - descDatas[i], err = signatureDataToProto(j) - if err != nil { - return nil, err - } - } - return &apitxsigning.SignatureDescriptor_Data{ - Sum: &apitxsigning.SignatureDescriptor_Data_Multi_{ - Multi: &apitxsigning.SignatureDescriptor_Data_Multi{ - Bitarray: data.BitArray, - Signatures: descDatas, - }, - }, - }, nil - } - - // Return an error if the data type is not supported. - return nil, fmt.Errorf("unexpected signature data type %T", data) -} - -// SignatureDataFromProto converts a protobuf SignatureDescriptor_Data to a SignatureData interface. -// This function supports both Single and Multi signature data types. -func SignatureDataFromProto(descData *apitxsigning.SignatureDescriptor_Data) (SignatureData, error) { - switch descData := descData.Sum.(type) { - case *apitxsigning.SignatureDescriptor_Data_Single_: - return &SingleSignatureData{ - SignMode: descData.Single.Mode, - Signature: descData.Single.Signature, - }, nil - case *apitxsigning.SignatureDescriptor_Data_Multi_: - var err error - multi := descData.Multi - data := make([]SignatureData, len(multi.Signatures)) - - for i, j := range multi.Signatures { - data[i], err = SignatureDataFromProto(j) - if err != nil { - return nil, err - } - } - - return &MultiSignatureData{ - BitArray: multi.Bitarray, - Signatures: data, - }, nil - } - - return nil, fmt.Errorf("unexpected signature data type %T", descData) -} diff --git a/connect/internal/tx/signature_test.go b/connect/internal/tx/signature_test.go deleted file mode 100644 index dd78add3..00000000 --- a/connect/internal/tx/signature_test.go +++ /dev/null @@ -1,143 +0,0 @@ -package tx - -import ( - "reflect" - "testing" - - "github.com/stretchr/testify/require" - - apimultisig "cosmossdk.io/api/cosmos/crypto/multisig/v1beta1" - apisigning "cosmossdk.io/api/cosmos/tx/signing/v1beta1" - apitx "cosmossdk.io/api/cosmos/tx/v1beta1" -) - -func TestSignatureDataToModeInfoAndSig(t *testing.T) { - tests := []struct { - name string - data SignatureData - mIResult *apitx.ModeInfo - sigResult []byte - }{ - { - name: "single signature", - data: &SingleSignatureData{ - SignMode: apisigning.SignMode_SIGN_MODE_DIRECT, - Signature: []byte("signature"), - }, - mIResult: &apitx.ModeInfo{ - Sum: &apitx.ModeInfo_Single_{ - Single: &apitx.ModeInfo_Single{Mode: apisigning.SignMode_SIGN_MODE_DIRECT}, - }, - }, - sigResult: []byte("signature"), - }, - { - name: "multi signature", - data: &MultiSignatureData{ - BitArray: nil, - Signatures: []SignatureData{ - &SingleSignatureData{ - SignMode: apisigning.SignMode_SIGN_MODE_DIRECT, - Signature: []byte("signature"), - }, - }, - }, - mIResult: &apitx.ModeInfo{ - Sum: &apitx.ModeInfo_Multi_{ - Multi: &apitx.ModeInfo_Multi{ - Bitarray: nil, - ModeInfos: []*apitx.ModeInfo{ - { - Sum: &apitx.ModeInfo_Single_{ - Single: &apitx.ModeInfo_Single{Mode: apisigning.SignMode_SIGN_MODE_DIRECT}, - }, - }, - }, - }, - }, - }, - sigResult: []byte("\n\tsignature"), - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - modeInfo, signature := signatureDataToModeInfoAndSig(tt.data) - require.Equal(t, tt.mIResult, modeInfo) - require.Equal(t, tt.sigResult, signature) - }) - } -} - -func TestModeInfoAndSigToSignatureData(t *testing.T) { - type args struct { - modeInfo func() *apitx.ModeInfo - sig []byte - } - tests := []struct { - name string - args args - want SignatureData - wantErr bool - }{ - { - name: "to SingleSignatureData", - args: args{ - modeInfo: func() *apitx.ModeInfo { - return &apitx.ModeInfo{ - Sum: &apitx.ModeInfo_Single_{ - Single: &apitx.ModeInfo_Single{Mode: apisigning.SignMode_SIGN_MODE_DIRECT}, - }, - } - }, - sig: []byte("signature"), - }, - want: &SingleSignatureData{ - SignMode: apisigning.SignMode_SIGN_MODE_DIRECT, - Signature: []byte("signature"), - }, - }, - { - name: "to MultiSignatureData", - args: args{ - modeInfo: func() *apitx.ModeInfo { - return &apitx.ModeInfo{ - Sum: &apitx.ModeInfo_Multi_{ - Multi: &apitx.ModeInfo_Multi{ - Bitarray: &apimultisig.CompactBitArray{}, - ModeInfos: []*apitx.ModeInfo{ - { - Sum: &apitx.ModeInfo_Single_{ - Single: &apitx.ModeInfo_Single{Mode: apisigning.SignMode_SIGN_MODE_DIRECT}, - }, - }, - }, - }, - }, - } - }, - sig: []byte("\n\tsignature"), - }, - want: &MultiSignatureData{ // Changed from SingleSignatureData to MultiSignatureData - BitArray: &apimultisig.CompactBitArray{}, - Signatures: []SignatureData{ - &SingleSignatureData{ - SignMode: apisigning.SignMode_SIGN_MODE_DIRECT, - Signature: []byte("signature"), - }, - }, - }, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - got, err := modeInfoAndSigToSignatureData(tt.args.modeInfo(), tt.args.sig) - if (err != nil) != tt.wantErr { - t.Errorf("ModeInfoAndSigToSignatureData() error = %v, wantErr %v", err, tt.wantErr) - return - } - if !reflect.DeepEqual(got, tt.want) { - t.Errorf("ModeInfoAndSigToSignatureData() got = %v, want %v", got, tt.want) - } - }) - } -} diff --git a/connect/internal/tx/tx.go b/connect/internal/tx/tx.go deleted file mode 100644 index 57a3ef85..00000000 --- a/connect/internal/tx/tx.go +++ /dev/null @@ -1,312 +0,0 @@ -package tx - -import ( - "context" - "errors" - "fmt" - - apitxsigning "cosmossdk.io/api/cosmos/tx/signing/v1beta1" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/gogoproto/grpc" - "github.com/cosmos/gogoproto/proto" - - "github.com/ignite/apps/connect/internal/account" - "github.com/ignite/apps/connect/internal/flags" -) - -// GenerateAndBroadcastTxCLI will either generate and print an unsigned transaction -// or sign it and broadcast it using default CometBFT broadcaster, returning an error upon failure. -func GenerateAndBroadcastTxCLI(ctx context.Context, conn grpc.ClientConn, msgs ...sdk.Msg) ([]byte, error) { - txCtx, err := GetContext(ctx) - if err != nil { - return nil, err - } - - txf, err := initFactory(txCtx, conn, msgs...) - if err != nil { - return nil, err - } - - if err := generateTx(txf, msgs...); err != nil { - return nil, err - } - - cBroadcaster, err := cometBroadcaster(txCtx) - if err != nil { - return nil, err - } - - return BroadcastTx(ctx, txf, cBroadcaster) -} - -// GenerateAndBroadcastTxCLIWithPrompt generates, signs and broadcasts a transaction after prompting the user for confirmation. -// It takes a context, gRPC client connection, prompt function for user confirmation, and transaction messages. -// The prompt function receives the unsigned transaction bytes and returns a boolean indicating user confirmation and any error. -// Returns the broadcast response bytes and any error encountered. -func GenerateAndBroadcastTxCLIWithPrompt( - ctx context.Context, - conn grpc.ClientConn, - prompt func([]byte) (bool, error), - msgs ...sdk.Msg, -) ([]byte, error) { - txCtx, err := GetContext(ctx) - if err != nil { - return nil, err - } - - txf, err := initFactory(txCtx, conn, msgs...) - if err != nil { - return nil, err - } - - err = generateTx(txf, msgs...) - if err != nil { - return nil, err - } - - confirmed, err := askConfirmation(txf, prompt) - if err != nil { - return nil, err - } - - if !confirmed { - return nil, nil - } - - cBroadcaster, err := cometBroadcaster(txCtx) - if err != nil { - return nil, err - } - - return BroadcastTx(ctx, txf, cBroadcaster) -} - -// GenerateOnly generates an unsigned transaction without broadcasting it. -// It initializes a transaction factory using the provided context, connection and messages, -// then generates an unsigned transaction. -// Returns the unsigned transaction bytes and any error encountered. -func GenerateOnly(ctx context.Context, conn grpc.ClientConn, msgs ...sdk.Msg) ([]byte, error) { - txCtx, err := GetContext(ctx) - if err != nil { - return nil, err - } - - txf, err := initFactory(txCtx, conn) - if err != nil { - return nil, err - } - - return generateOnly(txf, msgs...) -} - -// DryRun simulates a transaction without broadcasting it to the network. -// It initializes a transaction factory using the provided context, connection and messages, -// then performs a dry run simulation of the transaction. -// Returns the simulation response bytes and any error encountered. -func DryRun(ctx context.Context, conn grpc.ClientConn, msgs ...sdk.Msg) ([]byte, error) { - txCtx, err := GetContext(ctx) - if err != nil { - return nil, err - } - - txf, err := initFactory(txCtx, conn, msgs...) - if err != nil { - return nil, err - } - - return dryRun(txf, msgs...) -} - -// initFactory initializes a new transaction Factory and validates the provided messages. -// It retrieves the client v2 context from the provided context, validates all messages, -// and creates a new transaction Factory using the client context and connection. -// Returns the initialized Factory and any error encountered. -func initFactory(ctx Context, conn grpc.ClientConn, msgs ...sdk.Msg) (Factory, error) { - if err := validateMessages(msgs...); err != nil { - return Factory{}, err - } - - txf, err := newFactory(ctx, conn) - if err != nil { - return Factory{}, err - } - - return txf, nil -} - -// newFactory creates a new transaction Factory based on the provided context and flag set. -// It initializes a new CLI keyring, extracts transaction parameters from the flag set, -// configures transaction settings, and sets up an account retriever for the transaction Factory. -func newFactory(ctx Context, conn grpc.ClientConn) (Factory, error) { - txConfig, err := NewTxConfig(ConfigOptions{ - AddressCodec: ctx.AddressCodec, - Cdc: ctx.Cdc, - ValidatorAddressCodec: ctx.ValidatorAddressCodec, - }) - if err != nil { - return Factory{}, err - } - - accRetriever := account.NewAccountRetriever(ctx.AddressCodec, conn, ctx.Cdc.InterfaceRegistry()) - - txf, err := NewFactoryFromFlagSet(ctx.Flags, ctx.Keyring, ctx.Cdc, accRetriever, txConfig, ctx.AddressCodec, conn) - if err != nil { - return Factory{}, err - } - - return txf, nil -} - -// validateMessages validates all msgs before generating or broadcasting the tx. -// We were calling ValidateBasic separately in each CLI handler before. -// Right now, we're factorizing that call inside this function. -// ref: https://github.com/cosmos/cosmos-sdk/pull/9236#discussion_r623803504 -func validateMessages(msgs ...sdk.Msg) error { - for _, msg := range msgs { - m, ok := msg.(HasValidateBasic) - if !ok { - continue - } - - if err := m.ValidateBasic(); err != nil { - return err - } - } - - return nil -} - -// generateOnly prepares the transaction and prints the unsigned transaction string. -// It first calls Prepare on the transaction factory to set up any necessary pre-conditions. -// If preparation is successful, it generates an unsigned transaction string using the provided messages. -func generateOnly(txf Factory, msgs ...sdk.Msg) ([]byte, error) { - uTx, err := txf.UnsignedTxString(msgs...) - if err != nil { - return nil, err - } - - return []byte(uTx), nil -} - -// dryRun performs a dry run of the transaction to estimate the gas required. -// It prepares the transaction factory and simulates the transaction with the provided messages. -func dryRun(txf Factory, msgs ...sdk.Msg) ([]byte, error) { - _, gas, err := txf.Simulate(msgs...) - if err != nil { - return nil, err - } - - return []byte(fmt.Sprintf(`{"gas_estimate": %d}`, gas)), nil -} - -// SimulateTx simulates a tx and returns the simulation response obtained by the query. -func SimulateTx(ctx Context, conn grpc.ClientConn, msgs ...sdk.Msg) (proto.Message, error) { - txf, err := newFactory(ctx, conn) - if err != nil { - return nil, err - } - - simulation, _, err := txf.Simulate(msgs...) - return simulation, err -} - -// generateTx generates an unsigned transaction using the provided transaction factory and messages. -// If simulation and execution are enabled, it first calculates the gas requirements. -// It then builds the unsigned transaction with the provided messages. -func generateTx(txf Factory, msgs ...sdk.Msg) error { - if txf.simulateAndExecute() { - err := txf.calculateGas(msgs...) - if err != nil { - return err - } - } - - return txf.BuildUnsignedTx(msgs...) -} - -// BroadcastTx attempts to sign and broadcast a transaction using the provided factory and broadcaster. -// GenerateTx must be called first to prepare the transaction for signing. -// This function then signs the transaction using the factory's signing capabilities, encodes it, -// and finally broadcasts it using the provided broadcaster. -func BroadcastTx(ctx context.Context, txf Factory, broadcaster Broadcaster) ([]byte, error) { - if len(txf.tx.msgs) == 0 { - return nil, errors.New("no messages to broadcast") - } - - signedTx, err := txf.sign(ctx, true) - if err != nil { - return nil, err - } - - txBytes, err := txf.txConfig.TxEncoder()(signedTx) - if err != nil { - return nil, err - } - - return broadcaster.Broadcast(ctx, txBytes) -} - -// countDirectSigners counts the number of DIRECT signers in a signature data. -func countDirectSigners(sigData SignatureData) int { - switch data := sigData.(type) { - case *SingleSignatureData: - if data.SignMode == apitxsigning.SignMode_SIGN_MODE_DIRECT { - return 1 - } - - return 0 - case *MultiSignatureData: - directSigners := 0 - for _, d := range data.Signatures { - directSigners += countDirectSigners(d) - } - - return directSigners - default: - panic("unreachable case") - } -} - -// cometBroadcaster returns a broadcast.Broadcaster implementation that uses the CometBFT RPC client. -// It extracts the client context from the provided context and uses it to create a CometBFT broadcaster. -func cometBroadcaster(ctx Context) (Broadcaster, error) { - url, _ := ctx.Flags.GetString(flags.FlagNode) - mode, _ := ctx.Flags.GetString(flags.FlagBroadcastMode) - - return NewCometBFTBroadcaster(url, mode, ctx.Cdc) -} - -// askConfirmation encodes the transaction as JSON and prompts the user for confirmation using the provided prompter function. -// It returns the user's confirmation response and any error that occurred during the process. -func askConfirmation(txf Factory, prompter func([]byte) (bool, error)) (bool, error) { - encoder := txf.txConfig.TxJSONEncoder() - if encoder == nil { - return false, errors.New("failed to encode transaction: tx json encoder is nil") - } - - tx, err := txf.getTx() - if err != nil { - return false, err - } - - txBytes, err := encoder(tx) - if err != nil { - return false, fmt.Errorf("failed to encode transaction: %w", err) - } - - return prompter(txBytes) -} - -// getSignMode returns the corresponding apitxsigning.SignMode based on the provided mode string. -func getSignMode(mode string) apitxsigning.SignMode { - switch mode { - case "direct": - return apitxsigning.SignMode_SIGN_MODE_DIRECT - case "direct-aux": - return apitxsigning.SignMode_SIGN_MODE_DIRECT_AUX - case "amino-json": - return apitxsigning.SignMode_SIGN_MODE_LEGACY_AMINO_JSON - } - - return apitxsigning.SignMode_SIGN_MODE_UNSPECIFIED -} diff --git a/connect/internal/tx/types.go b/connect/internal/tx/types.go deleted file mode 100644 index fd3b255b..00000000 --- a/connect/internal/tx/types.go +++ /dev/null @@ -1,218 +0,0 @@ -package tx - -import ( - "fmt" - "time" - - "github.com/spf13/pflag" - "google.golang.org/protobuf/types/known/anypb" - - base "cosmossdk.io/api/cosmos/base/v1beta1" - apitxsigning "cosmossdk.io/api/cosmos/tx/signing/v1beta1" - apitx "cosmossdk.io/api/cosmos/tx/v1beta1" - "cosmossdk.io/core/address" - "cosmossdk.io/x/tx/signing" - cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" - sdk "github.com/cosmos/cosmos-sdk/types" - - "github.com/ignite/apps/connect/internal/autocli/keyring" - "github.com/ignite/apps/connect/internal/coins" -) - -// HasValidateBasic is a copy of types.HasValidateBasic to avoid sdk import. -type HasValidateBasic interface { - // ValidateBasic does a simple validation check that - // doesn't require access to any other information. - ValidateBasic() error -} - -// TxParameters defines the parameters required for constructing a transaction. -type TxParameters struct { - timeoutTimestamp time.Time // timeoutTimestamp indicates a timestamp after which the transaction is no longer valid. - ChainID string // ChainID specifies the unique identifier of the blockchain where the transaction will be processed. - memo string // memo contains any arbitrary memo to be attached to the transaction. - SignMode apitxsigning.SignMode // signMode determines the signing mode to be used for the transaction. - - AccountConfig // AccountConfig includes information about the transaction originator's account. - GasConfig // GasConfig specifies the gas settings for the transaction. - FeeConfig // FeeConfig details the fee associated with the transaction. - ExecutionOptions // ExecutionOptions includes settings that modify how the transaction is executed. -} - -// AccountConfig defines the 'account' related fields in a transaction. -type AccountConfig struct { - // accountNumber is the unique identifier for the account. - AccountNumber uint64 - // sequence is the sequence number of the transaction. - Sequence uint64 - // fromName is the name of the account sending the transaction. - FromName string - // fromAddress is the address of the account sending the transaction. - FromAddress string - // address is the byte representation of the account address. - Address []byte -} - -// GasConfig defines the 'gas' related fields in a transaction. -// GasConfig defines the gas-related settings for a transaction. -type GasConfig struct { - gas uint64 // gas is the amount of gas requested for the transaction. - gasAdjustment float64 // gasAdjustment is the factor by which the estimated gas is multiplied to calculate the final gas limit. - gasPrices []*base.DecCoin // gasPrices is a list of denominations of DecCoin used to calculate the fee paid for the gas. -} - -// NewGasConfig creates a new GasConfig with the specified gas, gasAdjustment, and gasPrices. -// If the provided gas value is zero, it defaults to a predefined value (defaultGas). -// The gasPrices string is parsed into a slice of DecCoin. -func NewGasConfig(gas uint64, gasAdjustment float64, gasPrices string) (GasConfig, error) { - parsedGasPrices, err := coins.ParseDecCoins(gasPrices) - if err != nil { - return GasConfig{}, err - } - - return GasConfig{ - gas: gas, - gasAdjustment: gasAdjustment, - gasPrices: parsedGasPrices, - }, nil -} - -// FeeConfig holds the fee details for a transaction. -type FeeConfig struct { - fees []*base.Coin // fees are the amounts paid for the transaction. - feePayer string // feePayer is the account responsible for paying the fees. - feeGranter string // feeGranter is the account granting the fee payment if different from the payer. -} - -// NewFeeConfig creates a new FeeConfig with the specified fees, feePayer, and feeGranter. -// It parses the fees string into a slice of Coin, handling normalization. -func NewFeeConfig(fees, feePayer, feeGranter string) (FeeConfig, error) { - parsedFees, err := coins.ParseCoinsNormalized(fees) - if err != nil { - return FeeConfig{}, err - } - - return FeeConfig{ - fees: parsedFees, - feePayer: feePayer, - feeGranter: feeGranter, - }, nil -} - -// ExecutionOptions defines the transaction execution options ran by the client -type ExecutionOptions struct { - unordered bool // unordered indicates if the transaction execution order is not guaranteed. - simulateAndExecute bool // simulateAndExecute indicates if the transaction should be simulated before execution. -} - -// GasEstimateResponse defines a response definition for tx gas estimation. -type GasEstimateResponse struct { - GasEstimate uint64 `json:"gas_estimate" yaml:"gas_estimate"` -} - -func (gr GasEstimateResponse) String() string { - return fmt.Sprintf("gas estimate: %d", gr.GasEstimate) -} - -// txState represents the internal state of a transaction. -type txState struct { - msgs []sdk.Msg - timeoutHeight uint64 - timeoutTimestamp time.Time - granter []byte - payer []byte - unordered bool - memo string - gasLimit uint64 - fees []*base.Coin - signerInfos []*apitx.SignerInfo - signatures [][]byte - - extensionOptions []*anypb.Any - nonCriticalExtensionOptions []*anypb.Any -} - -// Tx defines the interface for transaction operations. -type Tx interface { - sdk.Tx - - // GetSigners fetches the addresses of the signers of the transaction. - GetSigners() ([][]byte, error) - // GetPubKeys retrieves the public keys of the signers of the transaction. - GetPubKeys() ([]cryptotypes.PubKey, error) - // GetSignatures fetches the signatures attached to the transaction. - GetSignatures() ([]Signature, error) - // GetSigningTxData returns the signing.TxData for the transaction. - GetSigningTxData() (signing.TxData, error) -} - -// txParamsFromFlagSet extracts the transaction parameters from the provided FlagSet. -func txParamsFromFlagSet(flags *pflag.FlagSet, keybase keyring.Keyring, ac address.Codec) (params TxParameters, err error) { - timestampUnix, _ := flags.GetInt64(FlagTimeoutTimestamp) - timeoutTimestamp := time.Unix(timestampUnix, 0) - chainID, _ := flags.GetString(FlagChainID) - memo, _ := flags.GetString(FlagNote) - signMode, _ := flags.GetString(FlagSignMode) - - accNumber, _ := flags.GetUint64(FlagAccountNumber) - sequence, _ := flags.GetUint64(FlagSequence) - from, _ := flags.GetString(FlagFrom) - - var fromName, fromAddress string - var addr []byte - isDryRun, _ := flags.GetBool(FlagDryRun) - generateOnly, _ := flags.GetBool(FlagGenerateOnly) - if isDryRun || generateOnly { - addr, err = ac.StringToBytes(from) - } else { - fromName, fromAddress, _, err = keybase.KeyInfo(from) - if err == nil { - addr, err = ac.StringToBytes(fromAddress) - } - } - if err != nil { - return params, err - } - - gas, _ := flags.GetString(FlagGas) - simulate, gasValue, _ := parseGasSetting(gas) - gasAdjustment, _ := flags.GetFloat64(FlagGasAdjustment) - gasPrices, _ := flags.GetString(FlagGasPrices) - - fees, _ := flags.GetString(FlagFees) - feePayer, _ := flags.GetString(FlagFeePayer) - feeGranter, _ := flags.GetString(FlagFeeGranter) - - unordered, _ := flags.GetBool(FlagUnordered) - - gasConfig, err := NewGasConfig(gasValue, gasAdjustment, gasPrices) - if err != nil { - return params, err - } - feeConfig, err := NewFeeConfig(fees, feePayer, feeGranter) - if err != nil { - return params, err - } - - txParams := TxParameters{ - timeoutTimestamp: timeoutTimestamp, - ChainID: chainID, - memo: memo, - SignMode: getSignMode(signMode), - AccountConfig: AccountConfig{ - AccountNumber: accNumber, - Sequence: sequence, - FromName: fromName, - FromAddress: fromAddress, - Address: addr, - }, - GasConfig: gasConfig, - FeeConfig: feeConfig, - ExecutionOptions: ExecutionOptions{ - unordered: unordered, - simulateAndExecute: simulate, - }, - } - - return txParams, nil -} diff --git a/connect/internal/tx/wrapper.go b/connect/internal/tx/wrapper.go deleted file mode 100644 index 8a3c97e2..00000000 --- a/connect/internal/tx/wrapper.go +++ /dev/null @@ -1,139 +0,0 @@ -package tx - -import ( - "fmt" - "reflect" - "strings" - - "github.com/cosmos/gogoproto/proto" - protov2 "google.golang.org/protobuf/proto" - "google.golang.org/protobuf/types/known/anypb" - - "cosmossdk.io/x/tx/decode" - "cosmossdk.io/x/tx/signing" - - "github.com/cosmos/cosmos-sdk/codec" - cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" - sdk "github.com/cosmos/cosmos-sdk/types" -) - -var _ Tx = wrappedTx{} - -// wrappedTx wraps a transaction and provides a codec for binary encoding/decoding. -type wrappedTx struct { - *decode.DecodedTx - - cdc codec.BinaryCodec -} - -func newWrapperTx(cdc codec.BinaryCodec, decodedTx *decode.DecodedTx) *wrappedTx { - return &wrappedTx{ - DecodedTx: decodedTx, - cdc: cdc, - } -} - -// GetSigners fetches the addresses of the signers of the transaction. -func (w wrappedTx) GetSigners() ([][]byte, error) { - return w.Signers, nil -} - -// GetPubKeys retrieves the public keys of the signers from the transaction's SignerInfos. -func (w wrappedTx) GetPubKeys() ([]cryptotypes.PubKey, error) { - signerInfos := w.Tx.AuthInfo.SignerInfos - pks := make([]cryptotypes.PubKey, len(signerInfos)) - - for i, si := range signerInfos { - // NOTE: it is okay to leave this nil if there is no PubKey in the SignerInfo. - // PubKey's can be left unset in SignerInfo. - if si.PublicKey == nil { - continue - } - maybePk, err := w.decodeAny(si.PublicKey) - if err != nil { - return nil, err - } - pk, ok := maybePk.(cryptotypes.PubKey) - if !ok { - return nil, fmt.Errorf("invalid public key type: %T", maybePk) - } - pks[i] = pk - } - - return pks, nil -} - -// GetSignatures fetches the signatures attached to the transaction. -func (w wrappedTx) GetSignatures() ([]Signature, error) { - signerInfos := w.Tx.AuthInfo.SignerInfos - sigs := w.Tx.Signatures - - pubKeys, err := w.GetPubKeys() - if err != nil { - return nil, err - } - signatures := make([]Signature, len(sigs)) - - for i, si := range signerInfos { - if si.ModeInfo == nil || si.ModeInfo.Sum == nil { - signatures[i] = Signature{ - PubKey: pubKeys[i], - } - } else { - sigData, err := modeInfoAndSigToSignatureData(si.ModeInfo, sigs[i]) - if err != nil { - return nil, err - } - signatures[i] = Signature{ - PubKey: pubKeys[i], - Data: sigData, - Sequence: si.GetSequence(), - } - } - } - - return signatures, nil -} - -func (w wrappedTx) GetSigningTxData() (signing.TxData, error) { - return signing.TxData{ - Body: w.Tx.Body, - AuthInfo: w.Tx.AuthInfo, - BodyBytes: w.TxRaw.BodyBytes, - AuthInfoBytes: w.TxRaw.AuthInfoBytes, - BodyHasUnknownNonCriticals: w.TxBodyHasUnknownNonCriticals, - }, nil -} - -// GetMsgs implements Tx. -func (w wrappedTx) GetMsgs() []sdk.Msg { - panic("not implemented") -} - -// GetMsgsV2 implements Tx. -func (w wrappedTx) GetMsgsV2() ([]protov2.Message, error) { - msgs := make([]protov2.Message, len(w.Tx.Body.Messages)) - for i, msg := range w.Tx.Body.Messages { - msgs[i] = msg - } - - return msgs, nil -} - -// decodeAny decodes a protobuf Any message into a concrete proto.Message. -func (w wrappedTx) decodeAny(anyPb *anypb.Any) (proto.Message, error) { - name := anyPb.GetTypeUrl() - if i := strings.LastIndexByte(name, '/'); i >= 0 { - name = name[i+len("/"):] - } - typ := proto.MessageType(name) - if typ == nil { - return nil, fmt.Errorf("unknown type: %s", name) - } - v1 := reflect.New(typ.Elem()).Interface().(proto.Message) - err := w.cdc.Unmarshal(anyPb.GetValue(), v1) - if err != nil { - return nil, err - } - return v1, nil -} diff --git a/connect/internal/util/util.go b/connect/internal/util/util.go deleted file mode 100644 index 9bb3c467..00000000 --- a/connect/internal/util/util.go +++ /dev/null @@ -1,96 +0,0 @@ -package util - -import ( - "regexp" - "runtime/debug" - "strings" - - cosmos_proto "github.com/cosmos/cosmos-proto" - "google.golang.org/protobuf/proto" - "google.golang.org/protobuf/reflect/protoreflect" - "google.golang.org/protobuf/reflect/protoregistry" - "google.golang.org/protobuf/types/dynamicpb" - - "github.com/ignite/apps/connect/internal/strcase" -) - -// get build info to verify later if comment is supported -// this is a hack in because of the global api module package -// later versions unsupported by the current version can be added -var buildInfo, _ = debug.ReadBuildInfo() - -// DescriptorKebabName returns the name of the descriptor in kebab case. -func DescriptorKebabName(descriptor protoreflect.Descriptor) string { - return strcase.ToKebab(string(descriptor.Name())) -} - -func ResolveMessageType(resolver protoregistry.MessageTypeResolver, descriptor protoreflect.MessageDescriptor) protoreflect.MessageType { - typ, err := resolver.FindMessageByName(descriptor.FullName()) - if err == nil { - return typ - } - - return dynamicpb.NewMessageType(descriptor) -} - -// IsSupportedVersion is used to determine in which version of a module / sdk a rpc was introduced. -// It returns false if the rpc has comment for an higher version than the current one. -// It returns true if the method descriptor contains no annotation. -func IsSupportedVersion(methodDesc protoreflect.MethodDescriptor) bool { - return isSupportedVersion(methodDesc, buildInfo) -} - -// isSupportedVersion is used to determine in which version of a module / sdk a rpc was introduced. -// It returns false if the rpc has comment for an higher version than the current one. -// It returns true if the method descriptor contains no annotation. -// It takes a buildInfo as argument to be able to test it. -func isSupportedVersion(methodDesc protoreflect.MethodDescriptor, buildInfo *debug.BuildInfo) bool { - hasVersion := proto.HasExtension(methodDesc.Options(), cosmos_proto.E_MethodAddedIn) - if !hasVersion || buildInfo == nil || len(buildInfo.Deps) == 0 { - return true - } - - version := proto.GetExtension(methodDesc.Options(), cosmos_proto.E_MethodAddedIn).(string) - moduleName, version := parseVersion(version) - if moduleName == "" || version == "" { - return true // if no comment consider it's supported - } - - for _, dep := range buildInfo.Deps { - if !strings.Contains(dep.Path, moduleName) { - continue - } - - return version <= dep.Version - } - - // if cannot find the module consider it isn't supported - // for instance the x/gov module wasn't extracted in v0.50 - // so it isn't present in the build info, however, that means - // it isn't supported in v0.50. - return false -} - -var sinceCommentRegex = regexp.MustCompile(`(\S+) (\S+)`) - -// parseVersion parses the `cosmos-sdk v0.xx` comment on rpc. -func parseVersion(input string) (string, string) { - var ( - moduleName string - version string - ) - - input = strings.ToLower(input) - input = strings.ReplaceAll(input, "cosmos sdk", "cosmos-sdk") - - matches := sinceCommentRegex.FindStringSubmatch(input) - if len(matches) >= 3 { - moduleName, version = strings.TrimPrefix(matches[1], "x/"), matches[2] - - if !strings.HasPrefix(version, "v") { - version = "v" + version - } - } - - return moduleName, version -} diff --git a/connect/internal/util/util_test.go b/connect/internal/util/util_test.go deleted file mode 100644 index 76c6b720..00000000 --- a/connect/internal/util/util_test.go +++ /dev/null @@ -1,125 +0,0 @@ -package util - -import ( - "runtime/debug" - "testing" - - "google.golang.org/protobuf/reflect/protoreflect" - "google.golang.org/protobuf/reflect/protoregistry" - - _ "github.com/ignite/apps/connect/internal/testpb" -) - -func TestIsSupportedVersion(t *testing.T) { - mockBuildInfo := &debug.BuildInfo{ - Deps: []*debug.Module{ - { - Path: "github.com/cosmos/cosmos-sdk", - Version: "v0.50.0", - }, - { - Path: "cosmossdk.io/feegrant", - Version: "v0.1.0", - }, - }, - } - - cases := []struct { - messageName string - expected bool - }{ - { - messageName: "testpb.Msg.Send", - expected: true, - }, - { - messageName: "testpb.Query.Echo", - expected: true, - }, - { - messageName: "testpb.Msg.Clawback", - expected: false, - }, - } - - for _, tc := range cases { - t.Run(tc.messageName, func(t *testing.T) { - desc, err := protoregistry.GlobalFiles.FindDescriptorByName(protoreflect.FullName(tc.messageName)) - if err != nil { - t.Fatal(err) - } - - methodDesc := desc.(protoreflect.MethodDescriptor) - isSupported := isSupportedVersion(methodDesc, mockBuildInfo) - if isSupported != tc.expected { - t.Errorf("expected %v, got %v for %s", tc.expected, isSupported, methodDesc.FullName()) - } - }) - } -} - -func TestParseVersion(t *testing.T) { - cases := []struct { - input string - expectedModuleName string - expectedVersion string - }{ - { - input: "", - expectedModuleName: "", - expectedVersion: "", - }, - { - input: "Cosmos SDK 0.50", - expectedModuleName: "cosmos-sdk", - expectedVersion: "v0.50", - }, - { - input: "cosmos sdk 0.50", - expectedModuleName: "cosmos-sdk", - expectedVersion: "v0.50", - }, - { - input: "Cosmos-SDK 0.50", - expectedModuleName: "cosmos-sdk", - expectedVersion: "v0.50", - }, - { - input: "cosmos-sdk v0.50", - expectedModuleName: "cosmos-sdk", - expectedVersion: "v0.50", - }, - { - input: "cosmos-sdk v0.50.1", - expectedModuleName: "cosmos-sdk", - expectedVersion: "v0.50.1", - }, - { - input: "cosmos-sdk 0.47.0-veronica", - expectedModuleName: "cosmos-sdk", - expectedVersion: "v0.47.0-veronica", - }, - { - input: "x/feegrant v0.1.0", - expectedModuleName: "feegrant", - expectedVersion: "v0.1.0", - }, - { - input: "x/feegrant 0.1", - expectedModuleName: "feegrant", - expectedVersion: "v0.1", - }, - } - - for _, tc := range cases { - t.Run(tc.input, func(t *testing.T) { - moduleName, version := parseVersion(tc.input) - if moduleName != tc.expectedModuleName { - t.Errorf("expected module name %s, got %s", tc.expectedModuleName, moduleName) - } - if version != tc.expectedVersion { - t.Errorf("expected version %s, got %s", tc.expectedVersion, version) - } - }) - } -} diff --git a/connect/main.go b/connect/main.go index e2e640f9..1d912e0f 100644 --- a/connect/main.go +++ b/connect/main.go @@ -18,18 +18,24 @@ var _ plugin.Interface = app{} type app struct{} -func (app) Manifest(context.Context) (*plugin.Manifest, error) { - var availableChains []string +func (app) Manifest(ctx context.Context) (*plugin.Manifest, error) { + m := &plugin.Manifest{ + Name: "connect", + Commands: cmd.GetCommands(), + } + if cfg, err := chains.ReadConfig(); err == nil { - for name := range cfg.Chains { - availableChains = append(availableChains, name) + for chainName, chainCfg := range cfg.Chains { + cobraCmd, err := cmd.AppHandler(ctx, chainName, chainCfg) + if err != nil { + return nil, err + } + + m.ImportCobraCommand(cobraCmd, m.Name) } } - return &plugin.Manifest{ - Name: "connect", - Commands: cmd.GetCommands(availableChains), - }, nil + return m, nil } func (app) Execute(ctx context.Context, c *plugin.ExecutedCommand, _ plugin.ClientAPI) error { From 9f6da6e1543ffe99575b37db2945930ecf2c6757 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Fri, 4 Apr 2025 10:24:11 +0200 Subject: [PATCH 15/17] simplify --- connect/cmd/app.go | 29 +++++++++++++----- connect/go.mod | 4 +-- connect/internal/flags/flags.go | 52 --------------------------------- connect/internal/keyring.go | 8 +++-- 4 files changed, 28 insertions(+), 65 deletions(-) delete mode 100644 connect/internal/flags/flags.go diff --git a/connect/cmd/app.go b/connect/cmd/app.go index 825520eb..df785ba8 100644 --- a/connect/cmd/app.go +++ b/connect/cmd/app.go @@ -6,6 +6,7 @@ import ( "strings" "cosmossdk.io/core/address" + "github.com/cosmos/cosmos-sdk/client" sdkflags "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/grpc/cmtservice" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" @@ -19,6 +20,7 @@ import ( "cosmossdk.io/client/v2/autocli" "cosmossdk.io/client/v2/autocli/flag" "github.com/ignite/apps/connect/chains" + "github.com/ignite/apps/connect/internal" ) func AppHandler(ctx context.Context, name string, cfg *chains.ChainConfig, args ...string) (*cobra.Command, error) { @@ -64,21 +66,32 @@ func AppHandler(ctx context.Context, name string, cfg *chains.ChainConfig, args cometCmds := cmtservice.NewCometBFTCommands() conn.ModuleOptions[cometCmds.Name()] = cometCmds.AutoCLIOptions() - // k, err := internal.NewKeyring(chainCmd.Flags(), addressCodec, cfg.Bech32Prefix) - // if err != nil { - // return nil, err - // } - // clientCtx := client.Context{}.WithKeyring(k) - // add autocli commands - autocliOptions := &autocli.AppOptions{ + appOpts := &autocli.AppOptions{ ModuleOptions: conn.ModuleOptions, AddressCodec: addressCodec, ValidatorAddressCodec: validatorAddressCodec, ConsensusAddressCodec: consensusAddressCodec, } - err = autocliOptions.EnhanceRootCommandWithBuilder(chainCmd, builder) + // keyring config + k, err := internal.NewKeyring(chainCmd.Flags(), addressCodec, cfg.Bech32Prefix) + if err != nil { + return nil, err + } + + // create client context + clientCtx := client.Context{}. + WithKeyring(k) + + // add to root command (autocli expects it there) + chainCmd.SetContext(context.WithValue( + context.Background(), + client.ClientContextKey, + &clientCtx, + )) + + err = appOpts.EnhanceRootCommandWithBuilder(chainCmd, builder) if err != nil { return nil, err } diff --git a/connect/go.mod b/connect/go.mod index 2bbacbda..af89d7fd 100644 --- a/connect/go.mod +++ b/connect/go.mod @@ -1,8 +1,6 @@ module github.com/ignite/apps/connect -go 1.23.2 - -toolchain go1.24.1 +go 1.24.1 replace github.com/cosmos/cosmos-sdk => github.com/cosmos/cosmos-sdk v0.50.13 diff --git a/connect/internal/flags/flags.go b/connect/internal/flags/flags.go deleted file mode 100644 index a8a98aba..00000000 --- a/connect/internal/flags/flags.go +++ /dev/null @@ -1,52 +0,0 @@ -package flags - -// This defines flag names that can be used in autocli. -const ( - // FlagHome is the flag to specify the home dir of the app. - FlagHome = "home" - - // FlagChainID is the flag to specify the chain ID of the network. - FlagChainID = "chain-id" - - // FlagFrom is the flag to set the from address with which to sign the transaction. - FlagFrom = "from" - - // FlagOutput is the flag to set the output format. - FlagOutput = "output" - - // FlagNoIndent is the flag to not indent the output. - FlagNoIndent = "no-indent" - - // FlagNoPrompt is the flag to not use a prompt for commands. - FlagNoPrompt = "no-prompt" - - // FlagKeyringDir is the flag to specify the directory where the keyring is stored. - FlagKeyringDir = "keyring-dir" - // FlagKeyringBackend is the flag to specify which backend to use for the keyring (e.g. os, file, test). - FlagKeyringBackend = "keyring-backend" - - // FlagNoProposal is the flag convert a gov proposal command into a normal command. - // This is used to allow user of chains with custom authority to not use gov submit proposals for usual proposal commands. - FlagNoProposal = "no-proposal" - - // FlagNode is the flag to specify the node address to connect to. - FlagNode = "node" - - // FlagBroadcastMode is the flag to specify the broadcast mode for transactions. - FlagBroadcastMode = "broadcast-mode" - - // FlagGrpcAddress is the flag to specify the gRPC server address to connect to. - FlagGrpcAddress = "grpc-addr" - - // FlagGrpcInsecure is the flag to allow insecure gRPC connections. - FlagGrpcInsecure = "grpc-insecure" - - // FlagHeight is the flag to specify the height at which to query the state. - FlagHeight = "height" -) - -// List of supported output formats -const ( - OutputFormatJSON = "json" - OutputFormatText = "text" -) diff --git a/connect/internal/keyring.go b/connect/internal/keyring.go index 338a79ce..1dd502fe 100644 --- a/connect/internal/keyring.go +++ b/connect/internal/keyring.go @@ -6,17 +6,21 @@ import ( "cosmossdk.io/core/address" "github.com/cosmos/cosmos-sdk/crypto/keyring" - "github.com/ignite/apps/connect/internal/flags" "github.com/ignite/cli/v28/ignite/pkg/cosmosaccount" ) +const ( + // flagKeyringBackend is the flag for the keyring backend. + flagKeyringBackend = "keyring-backend" +) + // NewKeyring creates a new keyring instance based on command-line flags. func NewKeyring( flagSet *pflag.FlagSet, addressCodec address.Codec, bech32Prefix string, ) (keyring.Keyring, error) { - keyringBackend, err := flagSet.GetString(flags.FlagKeyringBackend) + keyringBackend, err := flagSet.GetString(flagKeyringBackend) if err != nil { return nil, err } else if keyringBackend == "" { From 04a5f9fc27f16fe0cca18ab54bc406f56f71edc1 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Fri, 4 Apr 2025 17:11:17 +0200 Subject: [PATCH 16/17] updates --- connect/cmd/app.go | 7 ++++++- connect/go.mod | 2 +- connect/go.sum | 24 ++++++++++++------------ 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/connect/cmd/app.go b/connect/cmd/app.go index df785ba8..44b4685c 100644 --- a/connect/cmd/app.go +++ b/connect/cmd/app.go @@ -3,6 +3,7 @@ package cmd import ( "context" "fmt" + "os" "strings" "cosmossdk.io/core/address" @@ -11,6 +12,7 @@ import ( "github.com/cosmos/cosmos-sdk/client/grpc/cmtservice" addresscodec "github.com/cosmos/cosmos-sdk/codec/address" sdk "github.com/cosmos/cosmos-sdk/types" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/spf13/cobra" "google.golang.org/grpc" "google.golang.org/protobuf/reflect/protoreflect" @@ -82,7 +84,10 @@ func AppHandler(ctx context.Context, name string, cfg *chains.ChainConfig, args // create client context clientCtx := client.Context{}. - WithKeyring(k) + WithKeyring(k). + WithInput(os.Stdin). + WithAccountRetriever(authtypes.AccountRetriever{}). + WithViper("") // add to root command (autocli expects it there) chainCmd.SetContext(context.WithValue( diff --git a/connect/go.mod b/connect/go.mod index af89d7fd..c56b6460 100644 --- a/connect/go.mod +++ b/connect/go.mod @@ -2,7 +2,7 @@ module github.com/ignite/apps/connect go 1.24.1 -replace github.com/cosmos/cosmos-sdk => github.com/cosmos/cosmos-sdk v0.50.13 +// replace github.com/cosmos/cosmos-sdk => github.com/cosmos/cosmos-sdk v0.50.13 require ( cosmossdk.io/api v0.9.0 diff --git a/connect/go.sum b/connect/go.sum index 8bbdc8d2..1997de40 100644 --- a/connect/go.sum +++ b/connect/go.sum @@ -87,16 +87,16 @@ github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6r github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= github.com/bgentry/speakeasy v0.2.0 h1:tgObeVOf8WAvtuAX6DhJ4xks4CFNwPDZiqzGqIHE51E= github.com/bgentry/speakeasy v0.2.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= -github.com/bits-and-blooms/bitset v1.8.0 h1:FD+XqgOZDUxxZ8hzoBFuV9+cGWY9CslN6d5MS5JVb4c= -github.com/bits-and-blooms/bitset v1.8.0/go.mod h1:7hO7Gc7Pp1vODcmWvKMRA9BNmbv6a/7QIWpPxHddWR8= +github.com/bits-and-blooms/bitset v1.22.0 h1:Tquv9S8+SGaS3EhyA+up3FXzmkhxPGjQQCkcs2uw7w4= +github.com/bits-and-blooms/bitset v1.22.0/go.mod h1:7hO7Gc7Pp1vODcmWvKMRA9BNmbv6a/7QIWpPxHddWR8= github.com/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM= github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ= -github.com/btcsuite/btcd/btcec/v2 v2.3.4 h1:3EJjcN70HCu/mwqlUsGK8GcNVyLVxFDlWurTXGPFfiQ= -github.com/btcsuite/btcd/btcec/v2 v2.3.4/go.mod h1:zYzJ8etWJQIv1Ogk7OzpWjowwOdXY1W/17j2MW85J04= +github.com/btcsuite/btcd/btcec/v2 v2.3.2 h1:5n0X6hX0Zk+6omWcihdYvdAlGf2DfasC0GMf7DClJ3U= +github.com/btcsuite/btcd/btcec/v2 v2.3.2/go.mod h1:zYzJ8etWJQIv1Ogk7OzpWjowwOdXY1W/17j2MW85J04= github.com/btcsuite/btcd/btcutil v1.1.6 h1:zFL2+c3Lb9gEgqKNzowKUPQNb8jV7v5Oaodi/AYFd6c= github.com/btcsuite/btcd/btcutil v1.1.6/go.mod h1:9dFymx8HpuLqBnsPELrImQeTQfKBQqzqGbbV3jK55aE= -github.com/bufbuild/protocompile v0.14.0 h1:z3DW4IvXE5G/uTOnSQn+qwQQxvhckkTWLS/0No/o7KU= -github.com/bufbuild/protocompile v0.14.0/go.mod h1:N6J1NYzkspJo3ZwyL4Xjvli86XOj1xq4qAasUFxGups= +github.com/bufbuild/protocompile v0.14.1 h1:iA73zAf/fyljNjQKwYzUHD6AD4R8KMasmwa/FBatYVw= +github.com/bufbuild/protocompile v0.14.1/go.mod h1:ppVdAIhbr2H8asPk6k4pY7t9zB1OU5DoEw9xY/FUi1c= github.com/bytedance/sonic v1.13.1 h1:Jyd5CIvdFnkOWuKXr+wm4Nyk2h0yAFsr8ucJgEasO3g= github.com/bytedance/sonic v1.13.1/go.mod h1:o68xyaF9u2gvVBuGHPlUVCy+ZfmNNO5ETf1+KgkJhz4= github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU= @@ -185,8 +185,8 @@ github.com/cosmos/cosmos-db v1.1.1 h1:FezFSU37AlBC8S98NlSagL76oqBRWq/prTPvFcEJNC github.com/cosmos/cosmos-db v1.1.1/go.mod h1:AghjcIPqdhSLP/2Z0yha5xPH3nLnskz81pBx3tcVSAw= github.com/cosmos/cosmos-proto v1.0.0-beta.5 h1:eNcayDLpip+zVLRLYafhzLvQlSmyab+RC5W7ZfmxJLA= github.com/cosmos/cosmos-proto v1.0.0-beta.5/go.mod h1:hQGLpiIUloJBMdQMMWb/4wRApmI9hjHH05nefC0Ojec= -github.com/cosmos/cosmos-sdk v0.50.13 h1:xQ32hhzVy7agEe7behMdZN0ezWhPss3KoLZsF9KoBnw= -github.com/cosmos/cosmos-sdk v0.50.13/go.mod h1:hrWEFMU1eoXqLJeE6VVESpJDQH67FS1nnMrQIjO2daw= +github.com/cosmos/cosmos-sdk v0.53.0-rc.2 h1:KdQRIp6z/hQK9VppPU1exuXobLLwhrrRIrAOlzzaIf0= +github.com/cosmos/cosmos-sdk v0.53.0-rc.2/go.mod h1:GCGPg/EJ9FCygDZ8yHxuq3aM577FC706LpXwl2LbXKQ= github.com/cosmos/go-bip39 v1.0.0 h1:pcomnQdrdH22njcAatO0yWojsUnCO3y2tNoV1cb6hHY= github.com/cosmos/go-bip39 v1.0.0/go.mod h1:RNJv0H/pOIVgxw6KS7QeX2a0Uo0aKUlfhZ4xuwvCdJw= github.com/cosmos/gogogateway v1.2.0 h1:Ae/OivNhp8DqBi/sh2A8a1D0y638GpL3tkmLQAiKxTE= @@ -527,8 +527,8 @@ github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLf github.com/influxdata/influxdb1-client v0.0.0-20191209144304-8bf82d3c094d/go.mod h1:qj24IKcXYK6Iy9ceXlo3Tc+vtHo9lIhSX5JddghvEPo= github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A= github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo= -github.com/jhump/protoreflect v1.15.3 h1:6SFRuqU45u9hIZPJAoZ8c28T3nK64BNdp9w6jFonzls= -github.com/jhump/protoreflect v1.15.3/go.mod h1:4ORHmSBmlCW8fh3xHmJMGyul1zNqZK4Elxc8qKP+p1k= +github.com/jhump/protoreflect v1.17.0 h1:qOEr613fac2lOuTgWN4tPAtLL7fUSbuJL5X5XumQh94= +github.com/jhump/protoreflect v1.17.0/go.mod h1:h9+vUUL38jiBzck8ck+6G/aeMX8Z4QUY/NiJPwPNi+8= github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= github.com/jmhodges/levigo v1.0.0 h1:q5EC36kV79HWeTBWsod3mG11EgStG3qArTKcvlksN1U= github.com/jmhodges/levigo v1.0.0/go.mod h1:Q6Qx+uH3RAqyK4rFQroq9RL7mdkABMcfhEI+nNuzMJQ= @@ -584,8 +584,8 @@ github.com/lucasb-eyer/go-colorful v1.0.3/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY= github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= github.com/lyft/protoc-gen-validate v0.0.13/go.mod h1:XbGvPuh87YZc5TdIa2/I4pLk0QoUACkjt2znoq26NVQ= -github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY= -github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= +github.com/magiconair/properties v1.8.9 h1:nWcCbLq1N2v/cpNsy5WvQ37Fb+YElfq20WJ/a8RkpQM= +github.com/magiconair/properties v1.8.9/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= github.com/manifoldco/promptui v0.9.0 h1:3V4HzJk1TtXW1MTZMP7mdlwbBpIinw3HztaIlYthEiA= github.com/manifoldco/promptui v0.9.0/go.mod h1:ka04sppxSGFAtxX0qhlYQjISsg9mR4GWtQEhdbn6Pgg= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= From 195a240090f62a06f9efac6a12f6a05738a488cd Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 22 May 2025 22:25:17 +0200 Subject: [PATCH 17/17] updates --- connect/cmd/app.go | 9 ++++ connect/go.mod | 47 ++++++++--------- connect/go.sum | 101 ++++++++++++++++++------------------ connect/internal/keyring.go | 6 +-- connect/main.go | 2 +- 5 files changed, 84 insertions(+), 81 deletions(-) diff --git a/connect/cmd/app.go b/connect/cmd/app.go index 44b4685c..fec7ec04 100644 --- a/connect/cmd/app.go +++ b/connect/cmd/app.go @@ -25,6 +25,15 @@ import ( "github.com/ignite/apps/connect/internal" ) +func AppManifest(ctx context.Context, name string, cfg *chains.ChainConfig) (*cobra.Command, error) { + chainCmd := &cobra.Command{ + Use: name, + Short: fmt.Sprintf("Commands for %s chain", name), + } + + return chainCmd, nil +} + func AppHandler(ctx context.Context, name string, cfg *chains.ChainConfig, args ...string) (*cobra.Command, error) { chainCmd := &cobra.Command{ Use: name, diff --git a/connect/go.mod b/connect/go.mod index c56b6460..c371610e 100644 --- a/connect/go.mod +++ b/connect/go.mod @@ -2,40 +2,38 @@ module github.com/ignite/apps/connect go 1.24.1 -// replace github.com/cosmos/cosmos-sdk => github.com/cosmos/cosmos-sdk v0.50.13 - require ( - cosmossdk.io/api v0.9.0 + cosmossdk.io/api v0.9.2 cosmossdk.io/client/v2 v2.0.0-beta.8.0.20250403203325-d6f3ede8dc11 cosmossdk.io/core v0.11.3 github.com/charmbracelet/bubbles v0.7.6 github.com/charmbracelet/bubbletea v1.2.4 - github.com/cosmos/cosmos-sdk v0.53.0-rc.2 + github.com/cosmos/cosmos-sdk v0.53.0 github.com/hashicorp/go-plugin v1.6.3 github.com/ignite/cli/v28 v28.8.2 github.com/spf13/cobra v1.9.1 github.com/spf13/pflag v1.0.6 github.com/stretchr/testify v1.10.0 - google.golang.org/grpc v1.71.1 + google.golang.org/grpc v1.72.0 google.golang.org/protobuf v1.36.6 gopkg.in/yaml.v3 v3.0.1 ) require ( cosmossdk.io/collections v1.2.0 // indirect - cosmossdk.io/depinject v1.2.0-rc.1 // indirect + cosmossdk.io/depinject v1.2.0 // indirect cosmossdk.io/errors v1.0.2 // indirect cosmossdk.io/log v1.5.1 // indirect - cosmossdk.io/math v1.5.2 // indirect - cosmossdk.io/schema v1.0.0 // indirect + cosmossdk.io/math v1.5.3 // indirect + cosmossdk.io/schema v1.1.0 // indirect cosmossdk.io/store v1.1.2 // indirect - cosmossdk.io/x/tx v0.14.0-rc.1 // indirect + cosmossdk.io/x/tx v0.14.0 // indirect dario.cat/mergo v1.0.1 // indirect filippo.io/edwards25519 v1.1.0 // indirect github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect github.com/99designs/keyring v1.2.2 // indirect github.com/DataDog/datadog-go v3.2.0+incompatible // indirect - github.com/DataDog/zstd v1.5.6 // indirect + github.com/DataDog/zstd v1.5.7 // indirect github.com/Microsoft/go-winio v0.6.1 // indirect github.com/ProtonMail/go-crypto v1.1.5 // indirect github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect @@ -43,7 +41,7 @@ require ( github.com/beorn7/perks v1.0.1 // indirect github.com/bgentry/speakeasy v0.2.0 // indirect github.com/blang/semver/v4 v4.0.0 // indirect - github.com/bytedance/sonic v1.13.1 // indirect + github.com/bytedance/sonic v1.13.2 // indirect github.com/bytedance/sonic/loader v0.2.4 // indirect github.com/cenkalti/backoff v2.2.1+incompatible // indirect github.com/cenkalti/backoff/v4 v4.3.0 // indirect @@ -54,12 +52,11 @@ require ( github.com/chzyer/readline v1.5.1 // indirect github.com/cloudflare/circl v1.3.7 // indirect github.com/cloudwego/base64x v0.1.5 // indirect - github.com/cockroachdb/apd/v3 v3.2.1 // indirect github.com/cockroachdb/errors v1.11.3 // indirect github.com/cockroachdb/fifo v0.0.0-20240606204812-0bbfbd93a7ce // indirect github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect - github.com/cockroachdb/pebble v1.1.2 // indirect - github.com/cockroachdb/redact v1.1.5 // indirect + github.com/cockroachdb/pebble v1.1.5 // indirect + github.com/cockroachdb/redact v1.1.6 // indirect github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect github.com/cometbft/cometbft v0.38.17 // indirect github.com/cometbft/cometbft-db v0.14.1 // indirect @@ -87,7 +84,7 @@ require ( github.com/fatih/color v1.17.0 // indirect github.com/fatih/structs v1.1.0 // indirect github.com/felixge/httpsnoop v1.0.4 // indirect - github.com/fsnotify/fsnotify v1.8.0 // indirect + github.com/fsnotify/fsnotify v1.9.0 // indirect github.com/getsentry/sentry-go v0.27.0 // indirect github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect github.com/go-git/go-billy/v5 v5.6.2 // indirect @@ -132,7 +129,7 @@ require ( github.com/hashicorp/go-metrics v0.5.4 // indirect github.com/hashicorp/golang-lru v1.0.2 // indirect github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect - github.com/hashicorp/yamux v0.1.1 // indirect + github.com/hashicorp/yamux v0.1.2 // indirect github.com/hdevalence/ed25519consensus v0.2.0 // indirect github.com/huandu/skiplist v1.2.1 // indirect github.com/iancoleman/strcase v0.3.0 // indirect @@ -165,12 +162,12 @@ require ( github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/oasisprotocol/curve25519-voi v0.0.0-20230904125328-1f23a7beb09a // indirect github.com/oklog/run v1.1.0 // indirect - github.com/pelletier/go-toml/v2 v2.2.3 // indirect + github.com/pelletier/go-toml/v2 v2.2.4 // indirect github.com/petermattis/goid v0.0.0-20240813172612-4fcff4a6cae7 // indirect github.com/pjbgf/sha1cd v0.3.2 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect - github.com/prometheus/client_golang v1.21.1 // indirect + github.com/prometheus/client_golang v1.22.0 // indirect github.com/prometheus/client_model v0.6.1 // indirect github.com/prometheus/common v0.63.0 // indirect github.com/prometheus/procfs v0.15.1 // indirect @@ -202,19 +199,19 @@ require ( go.opencensus.io v0.24.0 // indirect go.uber.org/multierr v1.11.0 // indirect golang.org/x/arch v0.15.0 // indirect - golang.org/x/crypto v0.36.0 // indirect + golang.org/x/crypto v0.37.0 // indirect golang.org/x/exp v0.0.0-20250305212735-054e65f0b394 // indirect golang.org/x/mod v0.24.0 // indirect - golang.org/x/net v0.38.0 // indirect - golang.org/x/sync v0.12.0 // indirect - golang.org/x/sys v0.31.0 // indirect - golang.org/x/term v0.30.0 // indirect - golang.org/x/text v0.23.0 // indirect + golang.org/x/net v0.39.0 // indirect + golang.org/x/sync v0.13.0 // indirect + golang.org/x/sys v0.32.0 // indirect + golang.org/x/term v0.31.0 // indirect + golang.org/x/text v0.24.0 // indirect golang.org/x/tools v0.31.0 // indirect golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect google.golang.org/genproto v0.0.0-20241118233622-e639e219e697 // indirect google.golang.org/genproto/googleapis/api v0.0.0-20250324211829-b45e905df463 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20250324211829-b45e905df463 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20250422160041-2d3770c4ea7f // indirect gopkg.in/warnings.v0 v0.1.2 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gotest.tools/v3 v3.5.2 // indirect diff --git a/connect/go.sum b/connect/go.sum index 1997de40..5c2fdc8f 100644 --- a/connect/go.sum +++ b/connect/go.sum @@ -1,27 +1,27 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -cosmossdk.io/api v0.9.0 h1:QYs9APeSlDNGbsBOBFjp3jXgGd4hnEPnnku3+W3tT4Y= -cosmossdk.io/api v0.9.0/go.mod h1:pLkU/NSqYHWxyN7XftVt8iD7oldKJzqMZgzeiOmT2nk= +cosmossdk.io/api v0.9.2 h1:9i9ptOBdmoIEVEVWLtYYHjxZonlF/aOVODLFaxpmNtg= +cosmossdk.io/api v0.9.2/go.mod h1:CWt31nVohvoPMTlPv+mMNCtC0a7BqRdESjCsstHcTkU= cosmossdk.io/client/v2 v2.0.0-beta.8.0.20250403203325-d6f3ede8dc11 h1:bKUGZ6U3IAsfYIlJcIAvttw/9VwmGPniadR104NjMro= cosmossdk.io/client/v2 v2.0.0-beta.8.0.20250403203325-d6f3ede8dc11/go.mod h1:Gm12rSvOYtgoGk2BH2o5nYVjPrwmFeSJqNtD/5CVFj4= cosmossdk.io/collections v1.2.0 h1:IesfVG8G/+FYCMVMP01frS/Cw99Omk5vBh3cHbO01Gg= cosmossdk.io/collections v1.2.0/go.mod h1:4NkMoYw6qRA8fnSH/yn1D/MOutr8qyQnwsO50Mz9ItU= cosmossdk.io/core v0.11.3 h1:mei+MVDJOwIjIniaKelE3jPDqShCc/F4LkNNHh+4yfo= cosmossdk.io/core v0.11.3/go.mod h1:9rL4RE1uDt5AJ4Tg55sYyHWXA16VmpHgbe0PbJc6N2Y= -cosmossdk.io/depinject v1.2.0-rc.1 h1:Q7qfs+j8MuFPpogx4ohiSXmFvw0Ns2wcBAYU8wIZRbg= -cosmossdk.io/depinject v1.2.0-rc.1/go.mod h1:SMffgggZXkCAbLbJ65pHELkB1Z6cpFbY4CNohGojAz4= +cosmossdk.io/depinject v1.2.0 h1:6NW/FSK1IkWTrX7XxUpBmX1QMBozpEI9SsWkKTBc5zw= +cosmossdk.io/depinject v1.2.0/go.mod h1:pvitjtUxZZZTQESKNS9KhGjWVslJZxtO9VooRJYyPjk= cosmossdk.io/errors v1.0.2 h1:wcYiJz08HThbWxd/L4jObeLaLySopyyuUFB5w4AGpCo= cosmossdk.io/errors v1.0.2/go.mod h1:0rjgiHkftRYPj//3DrD6y8hcm40HcPv/dR4R/4efr0k= cosmossdk.io/log v1.5.1 h1:wLwiYXmfrort/O+j6EkjF+HvbdrRQd+4cYCPKFSm+zM= cosmossdk.io/log v1.5.1/go.mod h1:5cXXBvfBkR2/BcXmosdCSLXllvgSjphrrDVdfVRmBGM= -cosmossdk.io/math v1.5.2 h1:PIhyy1JzmgPA712ewaYRjs+Hhh0iNuM8+fH18WPSejU= -cosmossdk.io/math v1.5.2/go.mod h1:ToembcWID/wR94cucsMD+2gq6xrlBBOfWcGwC7ZdwZA= -cosmossdk.io/schema v1.0.0 h1:/diH4XJjpV1JQwuIozwr+A4uFuuwanFdnw2kKeiXwwQ= -cosmossdk.io/schema v1.0.0/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= +cosmossdk.io/math v1.5.3 h1:WH6tu6Z3AUCeHbeOSHg2mt9rnoiUWVWaQ2t6Gkll96U= +cosmossdk.io/math v1.5.3/go.mod h1:uqcZv7vexnhMFJF+6zh9EWdm/+Ylyln34IvPnBauPCQ= +cosmossdk.io/schema v1.1.0 h1:mmpuz3dzouCoyjjcMcA/xHBEmMChN+EHh8EHxHRHhzE= +cosmossdk.io/schema v1.1.0/go.mod h1:Gb7pqO+tpR+jLW5qDcNOSv0KtppYs7881kfzakguhhI= cosmossdk.io/store v1.1.2 h1:3HOZG8+CuThREKv6cn3WSohAc6yccxO3hLzwK6rBC7o= cosmossdk.io/store v1.1.2/go.mod h1:60rAGzTHevGm592kFhiUVkNC9w7gooSEn5iUBPzHQ6A= -cosmossdk.io/x/tx v0.14.0-rc.1 h1:EEYTknUALt7PEK7b3Q8RVDQ2vDA5A+DGFlEvVcUWjqA= -cosmossdk.io/x/tx v0.14.0-rc.1/go.mod h1:MKYHaI9c1PVM3Qns4c/7PfdbO4OaGvtaP9BmAbv8APo= +cosmossdk.io/x/tx v0.14.0 h1:hB3O25kIcyDW/7kMTLMaO8Ripj3yqs5imceVd6c/heA= +cosmossdk.io/x/tx v0.14.0/go.mod h1:Tn30rSRA1PRfdGB3Yz55W4Sn6EIutr9xtMKSHij+9PM= dario.cat/mergo v1.0.1 h1:Ra4+bf83h2ztPIQYNP99R6m+Y7KfnARDfID+a+vLl4s= dario.cat/mergo v1.0.1/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= @@ -37,8 +37,8 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03 github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/DataDog/datadog-go v3.2.0+incompatible h1:qSG2N4FghB1He/r2mFrWKCaL7dXCilEuNEeAn20fdD4= github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ= -github.com/DataDog/zstd v1.5.6 h1:LbEglqepa/ipmmQJUDnSsfvA8e8IStVcGaFWDuxvGOY= -github.com/DataDog/zstd v1.5.6/go.mod h1:g4AWEaM3yOg3HYfnJ3YIawPnVdXJh9QME85blwSAmyw= +github.com/DataDog/zstd v1.5.7 h1:ybO8RBeh29qrxIhCA9E8gKY6xfONU9T6G6aP9DTKfLE= +github.com/DataDog/zstd v1.5.7/go.mod h1:g4AWEaM3yOg3HYfnJ3YIawPnVdXJh9QME85blwSAmyw= github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0= github.com/Microsoft/go-winio v0.5.2/go.mod h1:WpS1mjBmmwHBEWmogvA2mj8546UReBk4v8QkMxJ6pZY= github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow= @@ -97,8 +97,8 @@ github.com/btcsuite/btcd/btcutil v1.1.6 h1:zFL2+c3Lb9gEgqKNzowKUPQNb8jV7v5Oaodi/ github.com/btcsuite/btcd/btcutil v1.1.6/go.mod h1:9dFymx8HpuLqBnsPELrImQeTQfKBQqzqGbbV3jK55aE= github.com/bufbuild/protocompile v0.14.1 h1:iA73zAf/fyljNjQKwYzUHD6AD4R8KMasmwa/FBatYVw= github.com/bufbuild/protocompile v0.14.1/go.mod h1:ppVdAIhbr2H8asPk6k4pY7t9zB1OU5DoEw9xY/FUi1c= -github.com/bytedance/sonic v1.13.1 h1:Jyd5CIvdFnkOWuKXr+wm4Nyk2h0yAFsr8ucJgEasO3g= -github.com/bytedance/sonic v1.13.1/go.mod h1:o68xyaF9u2gvVBuGHPlUVCy+ZfmNNO5ETf1+KgkJhz4= +github.com/bytedance/sonic v1.13.2 h1:8/H1FempDZqC4VqjptGo14QQlJx8VdZJegxs6wwfqpQ= +github.com/bytedance/sonic v1.13.2/go.mod h1:o68xyaF9u2gvVBuGHPlUVCy+ZfmNNO5ETf1+KgkJhz4= github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU= github.com/bytedance/sonic/loader v0.2.4 h1:ZWCw4stuXUsn1/+zQDqeE7JKP+QO47tz7QCNan80NzY= github.com/bytedance/sonic/loader v0.2.4/go.mod h1:N8A3vUdtUebEY2/VQC0MyhYeKUFosQU6FxH2JmUe6VI= @@ -150,8 +150,6 @@ github.com/cncf/xds/go v0.0.0-20211001041855-01bcc9b48dfe/go.mod h1:eXthEFrGJvWH github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= github.com/cockroachdb/apd/v2 v2.0.2 h1:weh8u7Cneje73dDh+2tEVLUvyBc89iwepWCD8b8034E= github.com/cockroachdb/apd/v2 v2.0.2/go.mod h1:DDxRlzC2lo3/vSlmSoS7JkqbbrARPuFOGr0B9pvN3Gw= -github.com/cockroachdb/apd/v3 v3.2.1 h1:U+8j7t0axsIgvQUqthuNm82HIrYXodOV2iWLWtEaIwg= -github.com/cockroachdb/apd/v3 v3.2.1/go.mod h1:klXJcjp+FffLTHlhIG69tezTDvdP065naDsHzKhYSqc= github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8= github.com/cockroachdb/datadriven v1.0.3-0.20230413201302-be42291fc80f h1:otljaYPt5hWxV3MUfO5dFPFiOXg9CyG5/kCfayTqsJ4= github.com/cockroachdb/datadriven v1.0.3-0.20230413201302-be42291fc80f/go.mod h1:a9RdTaap04u637JoCzcUoIcDmvwSUtcUFtT/C3kJlTU= @@ -161,10 +159,10 @@ github.com/cockroachdb/fifo v0.0.0-20240606204812-0bbfbd93a7ce h1:giXvy4KSc/6g/e github.com/cockroachdb/fifo v0.0.0-20240606204812-0bbfbd93a7ce/go.mod h1:9/y3cnZ5GKakj/H4y9r9GTjCvAFta7KLgSHPJJYc52M= github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b h1:r6VH0faHjZeQy818SGhaone5OnYfxFR/+AzdY3sf5aE= github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b/go.mod h1:Vz9DsVWQQhf3vs21MhPMZpMGSht7O/2vFW2xusFUVOs= -github.com/cockroachdb/pebble v1.1.2 h1:CUh2IPtR4swHlEj48Rhfzw6l/d0qA31fItcIszQVIsA= -github.com/cockroachdb/pebble v1.1.2/go.mod h1:4exszw1r40423ZsmkG/09AFEG83I0uDgfujJdbL6kYU= -github.com/cockroachdb/redact v1.1.5 h1:u1PMllDkdFfPWaNGMyLD1+so+aq3uUItthCFqzwPJ30= -github.com/cockroachdb/redact v1.1.5/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZZ2lK+dpvRg= +github.com/cockroachdb/pebble v1.1.5 h1:5AAWCBWbat0uE0blr8qzufZP5tBjkRyy/jWe1QWLnvw= +github.com/cockroachdb/pebble v1.1.5/go.mod h1:17wO9el1YEigxkP/YtV8NtCivQDgoCyBg5c4VR/eOWo= +github.com/cockroachdb/redact v1.1.6 h1:zXJBwDZ84xJNlHl1rMyCojqyIxv+7YUpQiJLQ7n4314= +github.com/cockroachdb/redact v1.1.6/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZZ2lK+dpvRg= github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 h1:zuQyyAKVxetITBuuhv3BI9cMrmStnpT18zmgmTxunpo= github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06/go.mod h1:7nc4anLGjupUW/PeY5qiNYsdNXj7zopG+eqsS7To5IQ= github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI= @@ -185,8 +183,8 @@ github.com/cosmos/cosmos-db v1.1.1 h1:FezFSU37AlBC8S98NlSagL76oqBRWq/prTPvFcEJNC github.com/cosmos/cosmos-db v1.1.1/go.mod h1:AghjcIPqdhSLP/2Z0yha5xPH3nLnskz81pBx3tcVSAw= github.com/cosmos/cosmos-proto v1.0.0-beta.5 h1:eNcayDLpip+zVLRLYafhzLvQlSmyab+RC5W7ZfmxJLA= github.com/cosmos/cosmos-proto v1.0.0-beta.5/go.mod h1:hQGLpiIUloJBMdQMMWb/4wRApmI9hjHH05nefC0Ojec= -github.com/cosmos/cosmos-sdk v0.53.0-rc.2 h1:KdQRIp6z/hQK9VppPU1exuXobLLwhrrRIrAOlzzaIf0= -github.com/cosmos/cosmos-sdk v0.53.0-rc.2/go.mod h1:GCGPg/EJ9FCygDZ8yHxuq3aM577FC706LpXwl2LbXKQ= +github.com/cosmos/cosmos-sdk v0.53.0 h1:ZsB2tnBVudumV059oPuElcr0K1lLOutaI6WJ+osNTbI= +github.com/cosmos/cosmos-sdk v0.53.0/go.mod h1:UPcRyFwOUy2PfSFBWxBceO/HTjZOuBVqY583WyazIGs= github.com/cosmos/go-bip39 v1.0.0 h1:pcomnQdrdH22njcAatO0yWojsUnCO3y2tNoV1cb6hHY= github.com/cosmos/go-bip39 v1.0.0/go.mod h1:RNJv0H/pOIVgxw6KS7QeX2a0Uo0aKUlfhZ4xuwvCdJw= github.com/cosmos/gogogateway v1.2.0 h1:Ae/OivNhp8DqBi/sh2A8a1D0y638GpL3tkmLQAiKxTE= @@ -273,8 +271,8 @@ github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7z github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU= -github.com/fsnotify/fsnotify v1.8.0 h1:dAwr6QBTBZIkG8roQaJjGof0pp0EeF+tNV7YBP3F/8M= -github.com/fsnotify/fsnotify v1.8.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0= +github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k= +github.com/fsnotify/fsnotify v1.9.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0= github.com/getsentry/sentry-go v0.27.0 h1:Pv98CIbtB3LkMWmXi4Joa5OOcwbmnX88sF5qbK3r3Ps= github.com/getsentry/sentry-go v0.27.0/go.mod h1:lc76E2QywIyW8WuBnwl8Lc4bkmQH4+w1gwTf25trprY= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= @@ -502,8 +500,8 @@ github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0mNTz8vQ= github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I= github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc= -github.com/hashicorp/yamux v0.1.1 h1:yrQxtgseBDrq9Y652vSRDvsKCJKOUD+GzTS4Y0Y8pvE= -github.com/hashicorp/yamux v0.1.1/go.mod h1:CtWFDAQgb7dxtzFs4tWbplKIe2jSi3+5vKbgIO0SLnQ= +github.com/hashicorp/yamux v0.1.2 h1:XtB8kyFOyHXYVFnwT5C3+Bdo8gArse7j2AQ0DA0Uey8= +github.com/hashicorp/yamux v0.1.2/go.mod h1:C+zze2n6e/7wshOZep2A70/aQU6QBRWJO/G6FT1wIns= github.com/hdevalence/ed25519consensus v0.2.0 h1:37ICyZqdyj0lAZ8P4D1d1id3HqbbG1N3iBb1Tb4rdcU= github.com/hdevalence/ed25519consensus v0.2.0/go.mod h1:w3BHWjwJbFU29IRHL1Iqkw3sus+7FctEyM4RqDxYNzo= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= @@ -584,8 +582,8 @@ github.com/lucasb-eyer/go-colorful v1.0.3/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY= github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= github.com/lyft/protoc-gen-validate v0.0.13/go.mod h1:XbGvPuh87YZc5TdIa2/I4pLk0QoUACkjt2znoq26NVQ= -github.com/magiconair/properties v1.8.9 h1:nWcCbLq1N2v/cpNsy5WvQ37Fb+YElfq20WJ/a8RkpQM= -github.com/magiconair/properties v1.8.9/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= +github.com/magiconair/properties v1.8.10 h1:s31yESBquKXCV9a/ScB3ESkOjUYYv+X0rg8SYxI99mE= +github.com/magiconair/properties v1.8.10/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= github.com/manifoldco/promptui v0.9.0 h1:3V4HzJk1TtXW1MTZMP7mdlwbBpIinw3HztaIlYthEiA= github.com/manifoldco/promptui v0.9.0/go.mod h1:ka04sppxSGFAtxX0qhlYQjISsg9mR4GWtQEhdbn6Pgg= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= @@ -661,8 +659,9 @@ github.com/nats-io/nkeys v0.1.3/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxzi github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= -github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU= +github.com/nxadm/tail v1.4.11 h1:8feyoE3OzPrcshW5/MJ4sGESc5cqmGkGCWlco4l0bqY= +github.com/nxadm/tail v1.4.11/go.mod h1:OTaG3NK980DZzxbRq6lEuzgU+mug70nY11sMd4JXXHc= github.com/oasisprotocol/curve25519-voi v0.0.0-20230904125328-1f23a7beb09a h1:dlRvE5fWabOchtH7znfiFCcOvmIYgOeAS5ifBXBlh9Q= github.com/oasisprotocol/curve25519-voi v0.0.0-20230904125328-1f23a7beb09a/go.mod h1:hVoHR2EVESiICEMbg137etN/Lx+lSrHPTD39Z/uE+2s= github.com/oklog/oklog v0.3.2/go.mod h1:FCV+B7mhrz4o+ueLpx+KqkyXRGMWOYEvfiXtdGtbWGs= @@ -706,8 +705,8 @@ github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FI github.com/pascaldekloe/goe v0.1.0 h1:cBOtyMzM9HTpWjXfbbunk26uA6nG3a8n06Wieeh0MwY= github.com/pascaldekloe/goe v0.1.0/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k= -github.com/pelletier/go-toml/v2 v2.2.3 h1:YmeHyLY8mFWbdkNWwpr+qIL2bEqT0o95WSdkNHvL12M= -github.com/pelletier/go-toml/v2 v2.2.3/go.mod h1:MfCQTFTvCcUyyvvwm1+G6H/jORL20Xlb6rzQu9GuUkc= +github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4= +github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY= github.com/performancecopilot/speed v3.0.0+incompatible/go.mod h1:/CLtqpZ5gBg1M9iaPbIdPPGyKcA8hKdoy6hAWba7Yac= github.com/petermattis/goid v0.0.0-20240813172612-4fcff4a6cae7 h1:Dx7Ovyv/SFnMFw3fD4oEoeorXc6saIiQ23LrGLth0Gw= github.com/petermattis/goid v0.0.0-20240813172612-4fcff4a6cae7/go.mod h1:pxMtw7cyUw6B2bRH0ZBANSPg+AoSud1I1iyJHI69jH4= @@ -734,8 +733,8 @@ github.com/prometheus/client_golang v1.3.0/go.mod h1:hJaj2vgQTGQmVCsAACORcieXFeD github.com/prometheus/client_golang v1.4.0/go.mod h1:e9GMxYsXl05ICDXkRhurwBS4Q3OK1iX/F2sw+iXX5zU= github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M= github.com/prometheus/client_golang v1.11.1/go.mod h1:Z6t4BnS23TR94PD6BsDNk8yVqroYurpAkEiz0P2BEV0= -github.com/prometheus/client_golang v1.21.1 h1:DOvXXTqVzvkIewV/CDPFdejpMCGeMcbGCQ8YOmu+Ibk= -github.com/prometheus/client_golang v1.21.1/go.mod h1:U9NM32ykUErtVBxdvD3zfi+EuFkkaBvMb09mIfe0Zgg= +github.com/prometheus/client_golang v1.22.0 h1:rb93p9lokFEsctTys46VnV1kLCDpVZ0a/Y92Vm0Zc6Q= +github.com/prometheus/client_golang v1.22.0/go.mod h1:R7ljNsLXhuQXYZYtw6GAE9AZg8Y7vEW5scdCXrWRXC0= github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= github.com/prometheus/client_model v0.0.0-20190115171406-56726106282f/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= @@ -905,8 +904,8 @@ go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/goleak v1.1.10/go.mod h1:8a7PlsEVH3e/a/GLqe5IIrQx6GzcnRmZEufDUTk4A7A= -go.uber.org/mock v0.5.0 h1:KAMbZvZPyBPWgD14IrIQ38QCyjwpvVVV6K/bHl1IwQU= -go.uber.org/mock v0.5.0/go.mod h1:ge71pBPLYDk7QIi1LupWxdAykm7KIEFchiOqd6z7qMM= +go.uber.org/mock v0.5.2 h1:LbtPTcP8A5k9WPXj54PPPbjcI4Y6lhyOZXn+VS7wNko= +go.uber.org/mock v0.5.2/go.mod h1:wLlUxC2vVTPTaE3UD51E0BGOAElKrILxhVSDYQLld5o= go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= go.uber.org/multierr v1.3.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4= go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU= @@ -930,8 +929,8 @@ golang.org/x/crypto v0.0.0-20201012173705-84dcc777aaee/go.mod h1:LzIPMQfyMNhhGPh golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= -golang.org/x/crypto v0.36.0 h1:AnAEvhDddvBdpY+uR+MyHmuZzzNqXSe/GvuDeob5L34= -golang.org/x/crypto v0.36.0/go.mod h1:Y4J0ReaxCR1IMaabaSMugxJES1EpwhBHhv2bDHklZvc= +golang.org/x/crypto v0.37.0 h1:kJNSjF/Xp7kU0iB2Z+9viTPMW4EqqsrywMXLJOOsXSE= +golang.org/x/crypto v0.37.0/go.mod h1:vg+k43peMZ0pUMhYmVAWysMK35e6ioLh3wB8ZCAfbVc= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20200331195152-e8c3332aa8e5/go.mod h1:4M0jN8W1tt0AVLNr8HDosyJCDCDuyL9N9+3m7wDWgKw= @@ -987,8 +986,8 @@ golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug golang.org/x/net v0.0.0-20220826154423-83b083e8dc8b/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk= golang.org/x/net v0.0.0-20221002022538-bcab6841153b/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk= golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= -golang.org/x/net v0.38.0 h1:vRMAPTMaeGqVhG5QyLJHqNDwecKTomGeqbnfZyKlBI8= -golang.org/x/net v0.38.0/go.mod h1:ivrbrMbzFq5J41QOQh0siUuly180yBYtLp+CKbEaFx8= +golang.org/x/net v0.39.0 h1:ZCu7HMWDxpXpaiKdhzIfaltL9Lp31x/3fCP11bc6/fY= +golang.org/x/net v0.39.0/go.mod h1:X7NRbYVEA+ewNkCNyJ513WmMdQ3BineSwVtN2zD/d+E= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -1003,8 +1002,8 @@ golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220929204114-8fcdb60fdcc0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= -golang.org/x/sync v0.12.0 h1:MHc5BpPuC30uJk597Ri8TV3CNZcTLu6B6z4lJy+g6Jw= -golang.org/x/sync v0.12.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA= +golang.org/x/sync v0.13.0 h1:AauUjRAJ9OSnvULf/ARrrVywoJDy0YS2AwQ98I37610= +golang.org/x/sync v0.13.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -1067,14 +1066,14 @@ golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik= -golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= +golang.org/x/sys v0.32.0 h1:s77OFDvIQeibCmezSnk/q6iAfkdiQaJi4VzroCFrN20= +golang.org/x/sys v0.32.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.0.0-20220722155259-a9ba230a4035/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= -golang.org/x/term v0.30.0 h1:PQ39fJZ+mfadBm0y5WlL4vlM7Sx1Hgf13sMIY2+QS9Y= -golang.org/x/term v0.30.0/go.mod h1:NYYFdzHoI5wRh/h5tDMdMqCqPJZEuNqVR5xJLd/n67g= +golang.org/x/term v0.31.0 h1:erwDkOK1Msy6offm1mOgvspSkslFnIGsFnxOKoufg3o= +golang.org/x/term v0.31.0/go.mod h1:R4BeIy7D95HzImkxGkTW1UQTtP54tio2RyHz7PwK0aw= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= @@ -1082,8 +1081,8 @@ golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= -golang.org/x/text v0.23.0 h1:D71I7dUrlY+VX0gQShAThNGHFxZ13dGLBHQLVl1mJlY= -golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4= +golang.org/x/text v0.24.0 h1:dd5Bzh4yt5KYA8f9CJHCP4FB4D51c2c6JvN37xJJkJ0= +golang.org/x/text v0.24.0/go.mod h1:L8rBsPeo2pSS+xqN0d5u2ikmjtmoJbDBT1b7nHvFCdU= golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= @@ -1135,8 +1134,8 @@ google.golang.org/genproto v0.0.0-20241118233622-e639e219e697 h1:ToEetK57OidYuqD google.golang.org/genproto v0.0.0-20241118233622-e639e219e697/go.mod h1:JJrvXBWRZaFMxBufik1a4RpFw4HhgVtBBWQeQgUj2cc= google.golang.org/genproto/googleapis/api v0.0.0-20250324211829-b45e905df463 h1:hE3bRWtU6uceqlh4fhrSnUyjKHMKB9KrTLLG+bc0ddM= google.golang.org/genproto/googleapis/api v0.0.0-20250324211829-b45e905df463/go.mod h1:U90ffi8eUL9MwPcrJylN5+Mk2v3vuPDptd5yyNUiRR8= -google.golang.org/genproto/googleapis/rpc v0.0.0-20250324211829-b45e905df463 h1:e0AIkUUhxyBKh6ssZNrAMeqhA7RKUj42346d1y02i2g= -google.golang.org/genproto/googleapis/rpc v0.0.0-20250324211829-b45e905df463/go.mod h1:qQ0YXyHHx3XkvlzUtpXDkS29lDSafHMZBAZDc03LQ3A= +google.golang.org/genproto/googleapis/rpc v0.0.0-20250422160041-2d3770c4ea7f h1:N/PrbTw4kdkqNRzVfWPrBekzLuarFREcbFOiOLkXon4= +google.golang.org/genproto/googleapis/rpc v0.0.0-20250422160041-2d3770c4ea7f/go.mod h1:qQ0YXyHHx3XkvlzUtpXDkS29lDSafHMZBAZDc03LQ3A= google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.20.0/go.mod h1:chYK+tFQF0nDUGJgXMSgLCQk3phJEuONr2DCgLDdAQM= @@ -1155,8 +1154,8 @@ google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= google.golang.org/grpc v1.45.0/go.mod h1:lN7owxKUQEqMfSyQikvvk5tf/6zMPsrK+ONuO11+0rQ= google.golang.org/grpc v1.49.0/go.mod h1:ZgQEeidpAuNRZ8iRrlBKXZQP1ghovWIVhdJRyCDK+GI= -google.golang.org/grpc v1.71.1 h1:ffsFWr7ygTUscGPI0KKK6TLrGz0476KUvvsbqWK0rPI= -google.golang.org/grpc v1.71.1/go.mod h1:H0GRtasmQOh9LkFoCPDu3ZrwUtD1YGE+b2vYBYd/8Ec= +google.golang.org/grpc v1.72.0 h1:S7UkcVa60b5AAQTaO6ZKamFp1zMZSU0fGDK2WZLbBnM= +google.golang.org/grpc v1.72.0/go.mod h1:wH5Aktxcg25y1I3w7H69nHfXdOG3UiadoBtjh3izSDM= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= diff --git a/connect/internal/keyring.go b/connect/internal/keyring.go index 1dd502fe..bfcba819 100644 --- a/connect/internal/keyring.go +++ b/connect/internal/keyring.go @@ -20,10 +20,8 @@ func NewKeyring( addressCodec address.Codec, bech32Prefix string, ) (keyring.Keyring, error) { - keyringBackend, err := flagSet.GetString(flagKeyringBackend) - if err != nil { - return nil, err - } else if keyringBackend == "" { + keyringBackend, _ := flagSet.GetString(flagKeyringBackend) + if keyringBackend == "" { keyringBackend = keyring.BackendTest } diff --git a/connect/main.go b/connect/main.go index 36b9ca08..be5a132a 100644 --- a/connect/main.go +++ b/connect/main.go @@ -26,7 +26,7 @@ func (app) Manifest(ctx context.Context) (*plugin.Manifest, error) { if cfg, err := chains.ReadConfig(); err == nil { for chainName, chainCfg := range cfg.Chains { - cobraCmd, err := cmd.AppHandler(ctx, chainName, chainCfg) + cobraCmd, err := cmd.AppManifest(ctx, chainName, chainCfg) if err != nil { return nil, err }