Commit 28fd68bd authored by linj's avatar linj Committed by vipwzw

impl cli with rpc call

parent 9b6676cd
...@@ -128,18 +128,15 @@ func fixAmount(cmd *cobra.Command, args []string) { ...@@ -128,18 +128,15 @@ func fixAmount(cmd *cobra.Command, args []string) {
create.Means = pty.FixAmountX create.Means = pty.FixAmountX
create.MeansOpt = &pty.UnfreezeCreate_FixAmount{FixAmount: &pty.FixAmount{Period: period, Amount: amountInt64}} create.MeansOpt = &pty.UnfreezeCreate_FixAmount{FixAmount: &pty.FixAmount{Period: period, Amount: amountInt64}}
paraName, _ := cmd.Flags().GetString("paraName") params := &rpctypes.CreateTxIn{
tx, err := pty.CreateUnfreezeCreateTx(paraName, create) Execer: types.ExecName(pty.UnfreezeX),
if err != nil { ActionName: "createUnfreeze",
fmt.Fprintf(os.Stderr,"Create Tx frailed: %s", err) Payload: types.MustPBToJSON(create),
return
} }
outputTx(tx)
}
func outputTx(tx *types.Transaction) { rpcLaddr, _ := cmd.Flags().GetString("rpc_laddr")
txHex := types.Encode(tx) ctx := jsonclient.NewRPCCtx(rpcLaddr, "Chain33.CreateTransaction", params, nil)
fmt.Println(hex.EncodeToString(txHex)) ctx.RunWithoutMarshal()
} }
func leftCmd() *cobra.Command { func leftCmd() *cobra.Command {
...@@ -170,13 +167,15 @@ func left(cmd *cobra.Command, args []string) { ...@@ -170,13 +167,15 @@ func left(cmd *cobra.Command, args []string) {
create.MeansOpt = &pty.UnfreezeCreate_LeftProportion{ create.MeansOpt = &pty.UnfreezeCreate_LeftProportion{
LeftProportion: &pty.LeftProportion{Period: period, TenThousandth: tenThousandth}} LeftProportion: &pty.LeftProportion{Period: period, TenThousandth: tenThousandth}}
paraName, _ := cmd.Flags().GetString("paraName") params := &rpctypes.CreateTxIn{
tx, err := pty.CreateUnfreezeCreateTx(paraName, create) Execer: types.ExecName(pty.UnfreezeX),
if err != nil { ActionName: pty.Action_CreateUnfreeze,
fmt.Fprintf(os.Stderr,"Create Tx frailed: %s", err) Payload: types.MustPBToJSON(create),
return
} }
outputTx(tx)
rpcLaddr, _ := cmd.Flags().GetString("rpc_laddr")
ctx := jsonclient.NewRPCCtx(rpcLaddr, "Chain33.CreateTransaction", params, nil)
ctx.RunWithoutMarshal()
} }
func withdrawCmd() *cobra.Command { func withdrawCmd() *cobra.Command {
...@@ -229,24 +228,30 @@ func queryWithdrawCmd() *cobra.Command { ...@@ -229,24 +228,30 @@ func queryWithdrawCmd() *cobra.Command {
func withdraw(cmd *cobra.Command, args []string) { func withdraw(cmd *cobra.Command, args []string) {
id, _ := cmd.Flags().GetString("id") id, _ := cmd.Flags().GetString("id")
paraName, _ := cmd.Flags().GetString("paraName")
tx, err := pty.CreateUnfreezeWithdrawTx(paraName, &pty.UnfreezeWithdraw{UnfreezeID: id}) params := &rpctypes.CreateTxIn{
if err != nil { Execer: types.ExecName(pty.UnfreezeX),
fmt.Printf("Create Tx frailed: %s", err) ActionName: pty.Action_WithdrawUnfreeze,
return Payload: types.MustPBToJSON(&pty.UnfreezeWithdraw{UnfreezeID: id}),
} }
outputTx(tx)
rpcLaddr, _ := cmd.Flags().GetString("rpc_laddr")
ctx := jsonclient.NewRPCCtx(rpcLaddr, "Chain33.CreateTransaction", params, nil)
ctx.RunWithoutMarshal()
} }
func terminate(cmd *cobra.Command, args []string) { func terminate(cmd *cobra.Command, args []string) {
id, _ := cmd.Flags().GetString("id") id, _ := cmd.Flags().GetString("id")
paraName, _ := cmd.Flags().GetString("paraName")
tx, err := pty.CreateUnfreezeTerminateTx(paraName, &pty.UnfreezeTerminate{UnfreezeID: id}) params := &rpctypes.CreateTxIn{
if err != nil { Execer: types.ExecName(pty.UnfreezeX),
fmt.Printf("Create Tx frailed: %s", err) ActionName: pty.Action_TerminateUnfreeze,
return Payload: types.MustPBToJSON(&pty.UnfreezeTerminate{UnfreezeID: id}),
} }
outputTx(tx)
rpcLaddr, _ := cmd.Flags().GetString("rpc_laddr")
ctx := jsonclient.NewRPCCtx(rpcLaddr, "Chain33.CreateTransaction", params, nil)
ctx.RunWithoutMarshal()
} }
func queryWithdraw(cmd *cobra.Command, args []string) { func queryWithdraw(cmd *cobra.Command, args []string) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment