-
Notifications
You must be signed in to change notification settings - Fork 202
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: cherrypick GetBuildWasmMsg() to main branch (#1769)
* Add GetBuildWasmMsg() command to rootCmd * chore: update CHANGELOG with latest changes --------- Co-authored-by: Kevin Yang <[email protected]>
- Loading branch information
Showing
3 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters