diff --git a/CHANGELOG.md b/CHANGELOG.md index 0bfb8dd1b..b57ca86fa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -92,6 +92,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - [#1735](https://github.com/NibiruChain/nibiru/pull/1735) - test(sim): fix simulation tests - [#1736](https://github.com/NibiruChain/nibiru/pull/1736) - test(sim): add sim genesis state for all cusom modules - [#1754](https://github.com/NibiruChain/nibiru/pull/1754) - refactor(decode-base64): clean code improvements and fn docs +* [#1769](https://github.com/NibiruChain/nibiru/pull/1769) - feat: cherrypick GetBuildWasmMsg() to main branch - [#1778](https://github.com/NibiruChain/nibiru/pull/1778) - chore: bump librocksdb to v8.9.1 ### Dependencies diff --git a/cmd/nibid/cmd/base64.go b/cmd/nibid/cmd/base64.go new file mode 100644 index 000000000..5f235d3ea --- /dev/null +++ b/cmd/nibid/cmd/base64.go @@ -0,0 +1,53 @@ +package cmd + +import ( + "encoding/base64" + "encoding/json" + "fmt" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/spf13/cobra" +) + +func GetBuildWasmMsg() *cobra.Command { + cmd := &cobra.Command{ + Use: "build-stargate-wasm [message data]", + Short: "Build wasm Stargate message in Base64", + Long: `This message is used to build a Cosmos SDK, + in the format used to be sent as a Stargate message in a CosmWasm transaction.`, + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx := client.GetClientContextFromCmd(cmd) + + theMsg := args[0] + + anyMsg := types.Any{} + err := clientCtx.Codec.UnmarshalJSON([]byte(theMsg), &anyMsg) + if err != nil { + return err + } + + type stargateMessage struct { + TypeURL string `json:"type_url,omitempty"` + Value string `json:"value,omitempty"` + } + + js, err := json.Marshal(map[string]interface{}{ + "stargate": stargateMessage{ + TypeURL: anyMsg.TypeUrl, + Value: base64.StdEncoding.EncodeToString(anyMsg.Value), + }, + }) + if err != nil { + return err + } + + fmt.Println(string(js)) + + return nil + }, + } + + return cmd +} diff --git a/cmd/nibid/cmd/root.go b/cmd/nibid/cmd/root.go index 140c3d758..72587fac6 100644 --- a/cmd/nibid/cmd/root.go +++ b/cmd/nibid/cmd/root.go @@ -139,6 +139,7 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig app.EncodingConfig) { rootCmd.AddCommand( InitCmd(app.ModuleBasics, app.DefaultNodeHome), AddGenesisAccountCmd(app.DefaultNodeHome), + GetBuildWasmMsg(), DecodeBase64Cmd(app.DefaultNodeHome), tmcli.NewCompletionCmd(rootCmd, true), testnetCmd(app.ModuleBasics, banktypes.GenesisBalancesIterator{}),