Skip to content

Commit

Permalink
feat: cherrypick GetBuildWasmMsg() to main branch (#1769)
Browse files Browse the repository at this point in the history
* Add GetBuildWasmMsg() command to rootCmd

* chore: update CHANGELOG with latest changes

---------

Co-authored-by: Kevin Yang <[email protected]>
  • Loading branch information
jgimeno and k-yang authored Jan 27, 2024
1 parent 8fb9aa8 commit 7bf54d9
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
53 changes: 53 additions & 0 deletions cmd/nibid/cmd/base64.go
Original file line number Diff line number Diff line change
@@ -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
}
1 change: 1 addition & 0 deletions cmd/nibid/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}),
Expand Down

0 comments on commit 7bf54d9

Please sign in to comment.