Commit 32bffbbb authored by linj's avatar linj

add rpc, command

parent 81752197
...@@ -42,6 +42,8 @@ func TokenCmd() *cobra.Command { ...@@ -42,6 +42,8 @@ func TokenCmd() *cobra.Command {
CreateRawTokenFinishTxCmd(), CreateRawTokenFinishTxCmd(),
CreateRawTokenRevokeTxCmd(), CreateRawTokenRevokeTxCmd(),
CreateTokenTransferExecCmd(), CreateTokenTransferExecCmd(),
CreateRawTokenMintTxCmd(),
GetTokenLogsCmd(),
) )
return cmd return cmd
...@@ -465,3 +467,84 @@ func tokenRevoke(cmd *cobra.Command, args []string) { ...@@ -465,3 +467,84 @@ func tokenRevoke(cmd *cobra.Command, args []string) {
ctx := jsonclient.NewRPCCtx(rpcLaddr, "token.CreateRawTokenRevokeTx", params, nil) ctx := jsonclient.NewRPCCtx(rpcLaddr, "token.CreateRawTokenRevokeTx", params, nil)
ctx.RunWithoutMarshal() ctx.RunWithoutMarshal()
} }
// CreateRawTokenMintTxCmd create raw token finish create transaction
func CreateRawTokenMintTxCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "mint",
Short: "Create a mint token transaction",
Run: tokenMint,
}
addTokenMintFlags(cmd)
return cmd
}
func addTokenMintFlags(cmd *cobra.Command) {
cmd.Flags().StringP("symbol", "a", "", "token symbol")
cmd.MarkFlagRequired("symbol")
cmd.Flags().Float64P("amount", "a", 0, "amount of mintage")
cmd.MarkFlagRequired("amount")
cmd.Flags().Float64P("fee", "f", 0, "token transaction fee")
}
func tokenMint(cmd *cobra.Command, args []string) {
rpcLaddr, _ := cmd.Flags().GetString("rpc_laddr")
symbol, _ := cmd.Flags().GetString("symbol")
amount, _ := cmd.Flags().GetFloat64("owner_addr")
params := &tokenty.TokenMint{
Symbol: symbol,
Amount: int64((amount + 0.000001) * 1e4) * 1e4,
}
ctx := jsonclient.NewRPCCtx(rpcLaddr, "token.CreateRawTokenMintTx", params, nil)
ctx.RunWithoutMarshal()
}
// GetTokenLogsCmd get logs of token
func GetTokenLogsCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "get_token_logs",
Short: "Get logs of token",
Run: getTokenLogs,
}
getTokenLogsFlags(cmd)
return cmd
}
func getTokenLogs(cmd *cobra.Command, args []string) {
rpcLaddr, _ := cmd.Flags().GetString("rpc_laddr")
paraName, _ := cmd.Flags().GetString("paraName")
symbol, _ := cmd.Flags().GetString("symbol")
var params rpctypes.Query4Jrpc
params.Execer = getRealExecName(paraName, "token")
params.FuncName = "GetTokenHistory"
params.Payload = types.MustPBToJSON(&types.ReqString{Data:symbol})
rpc, err := jsonclient.NewJSONClient(rpcLaddr)
if err != nil {
fmt.Fprintln(os.Stderr, err)
return
}
var res tokenty.ReplyTokenLogs
err = rpc.Call("Chain33.Query", params, &res)
if err != nil {
fmt.Fprintln(os.Stderr, err)
return
}
data, err := json.MarshalIndent(res, "", " ")
if err != nil {
fmt.Fprintln(os.Stderr, err)
return
}
fmt.Println(string(data))
}
func getTokenLogsFlags(cmd *cobra.Command) {
cmd.Flags().StringP("symbol", "s", "", "token symbol")
cmd.MarkFlagRequired("symbol")
}
...@@ -121,3 +121,16 @@ func (c *Jrpc) CreateRawTokenRevokeTx(param *tokenty.TokenRevokeCreate, result * ...@@ -121,3 +121,16 @@ func (c *Jrpc) CreateRawTokenRevokeTx(param *tokenty.TokenRevokeCreate, result *
*result = hex.EncodeToString(data) *result = hex.EncodeToString(data)
return nil return nil
} }
// CreateRawTokenMintTx 创建未签名的mint Token交易
func (c *Jrpc) CreateRawTokenMintTx(param *tokenty.TokenMint, result *interface{}) error {
if param == nil || param.Symbol == "" || param.Amount > 0 {
return types.ErrInvalidParam
}
data, err := types.CallCreateTx(types.ExecName(tokenty.TokenX), "TokenMint", param)
if err != nil {
return err
}
*result = hex.EncodeToString(data)
return nil
}
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