-
Notifications
You must be signed in to change notification settings - Fork 330
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement sub command to generate a MsgWirePayForMessage from the cli
- Loading branch information
1 parent
83e51ec
commit 7adb975
Showing
2 changed files
with
82 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package cli | ||
|
||
import ( | ||
"encoding/hex" | ||
"errors" | ||
|
||
"github.com/cosmos/cosmos-sdk/client" | ||
"github.com/cosmos/cosmos-sdk/client/flags" | ||
"github.com/cosmos/cosmos-sdk/client/tx" | ||
"github.com/lazyledger/lazyledger-app/x/lazyledgerapp/types" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// CmdCreatePayForMessage returns a cobra command that uses the key ring backend | ||
// and locally running node to create and broadcast a new WirePayForMessage | ||
// transaction. | ||
func CmdCreatePayForMessage() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "payForMessage [hexNamespace] [hexMessage]", | ||
Short: "Creates a new WirePayForMessage", | ||
Args: cobra.ExactArgs(2), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
clientCtx, err := client.GetClientTxContext(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// get the account name | ||
accName := clientCtx.GetFromName() | ||
if accName == "" { | ||
return errors.New("no account name provided, please use the --from flag") | ||
} | ||
|
||
// get info on the key | ||
keyInfo, err := clientCtx.Keyring.Key(accName) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// decode the namespace | ||
namespace, err := hex.DecodeString(args[0]) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// decode the message | ||
message, err := hex.DecodeString(args[1]) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// create the PayForMessage | ||
pfmMsg, err := types.NewMsgWirePayForMessage( | ||
namespace, | ||
message, | ||
keyInfo.GetPubKey().Bytes(), | ||
&types.TransactionFee{}, // transaction fee is not yet used | ||
types.SquareSize, | ||
) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// sign the PayForMessage's ShareCommitments | ||
err = pfmMsg.SignShareCommitments(accName, clientCtx.Keyring) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// run message checks | ||
if err = pfmMsg.ValidateBasic(); err != nil { | ||
return err | ||
} | ||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), pfmMsg) | ||
}, | ||
} | ||
|
||
flags.AddTxFlagsToCmd(cmd) | ||
|
||
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