Commit 3abdcf52 authored by madengji's avatar madengji Committed by 33cn

para bind miner cmd

parent 073e10e3
...@@ -321,11 +321,13 @@ func superNodeCmd() *cobra.Command { ...@@ -321,11 +321,13 @@ func superNodeCmd() *cobra.Command {
cmd.AddCommand(nodeVoteCmd()) cmd.AddCommand(nodeVoteCmd())
cmd.AddCommand(nodeQuitCmd()) cmd.AddCommand(nodeQuitCmd())
cmd.AddCommand(nodeCancelCmd()) cmd.AddCommand(nodeCancelCmd())
cmd.AddCommand(nodeBindCmd())
cmd.AddCommand(getNodeInfoCmd()) cmd.AddCommand(getNodeInfoCmd())
cmd.AddCommand(getNodeIDInfoCmd()) cmd.AddCommand(getNodeIDInfoCmd())
cmd.AddCommand(getNodeListCmd()) cmd.AddCommand(getNodeListCmd())
cmd.AddCommand(nodeModifyCmd()) cmd.AddCommand(nodeModifyCmd())
cmd.AddCommand(getNodeBindListCmd())
return cmd return cmd
} }
...@@ -518,6 +520,87 @@ func createNodeModifyTx(cmd *cobra.Command, args []string) { ...@@ -518,6 +520,87 @@ func createNodeModifyTx(cmd *cobra.Command, args []string) {
} }
func nodeBindCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "bind",
Short: "bind miner for specific account",
Run: createNodeBindTx,
}
addNodeBindFlags(cmd)
return cmd
}
func addNodeBindFlags(cmd *cobra.Command) {
cmd.Flags().Uint32P("action", "a", 1, "action bind:1 or unbind:2")
cmd.MarkFlagRequired("action")
cmd.Flags().Uint64P("coins", "c", 0, "bind coins, unbind not needed")
cmd.Flags().StringP("node", "n", "", "target node to bind/unbind miner")
cmd.MarkFlagRequired("node")
}
func createNodeBindTx(cmd *cobra.Command, args []string) {
paraName, _ := cmd.Flags().GetString("paraName")
action, _ := cmd.Flags().GetUint32("action")
node, _ := cmd.Flags().GetString("node")
coins, _ := cmd.Flags().GetUint32("coins")
if !strings.HasPrefix(paraName, "user.p") {
fmt.Fprintln(os.Stderr, "paraName is not right, paraName format like `user.p.guodun.`")
return
}
if action == 1 && coins == 0 {
fmt.Fprintln(os.Stderr, "coins should bigger than 0")
}
payload := &pt.ParaBindMinerInfo{BindAction: int32(action), BindCount: int64(coins), TargetAddr: node}
params := &rpctypes.CreateTxIn{
Execer: getRealExecName(paraName, pt.ParaX),
ActionName: "ParaBindMiner",
Payload: types.MustPBToJSON(payload),
}
rpcLaddr, _ := cmd.Flags().GetString("rpc_laddr")
ctx := jsonclient.NewRPCCtx(rpcLaddr, "Chain33.CreateTransaction", params, nil)
ctx.RunWithoutMarshal()
}
func getNodeBindListCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "bind_list",
Short: "Get node bind miner account list",
Run: nodeBindInfo,
}
addNodeBindCmdFlags(cmd)
return cmd
}
func addNodeBindCmdFlags(cmd *cobra.Command) {
cmd.Flags().StringP("node", "n", "", "super node addr to bind miner")
cmd.MarkFlagRequired("node")
}
func nodeBindInfo(cmd *cobra.Command, args []string) {
rpcLaddr, _ := cmd.Flags().GetString("rpc_laddr")
addr, _ := cmd.Flags().GetString("addr")
var params rpctypes.Query4Jrpc
params.Execer = pt.ParaX
params.FuncName = "GetNodeBindMinerList"
params.Payload = types.MustPBToJSON(&types.ReqString{Data: addr})
var res pt.RespParaNodeBindList
ctx := jsonclient.NewRPCCtx(rpcLaddr, "Chain33.Query", params, &res)
ctx.Run()
}
// getNodeInfoCmd get node current status // getNodeInfoCmd get node current status
func getNodeInfoCmd() *cobra.Command { func getNodeInfoCmd() *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
......
...@@ -533,3 +533,28 @@ func (p *Paracross) Query_GetHeight(req *types.ReqString) (*pt.ParacrossConsensu ...@@ -533,3 +533,28 @@ func (p *Paracross) Query_GetHeight(req *types.ReqString) (*pt.ParacrossConsensu
} }
return nil, types.ErrDecode return nil, types.ErrDecode
} }
// Query_GetNodeBindMinerList query get super node bind miner list
func (p *Paracross) Query_GetNodeBindMinerList(in *types.ReqString) (types.Message, error) {
if in == nil || len(in.Data) == 0 {
return nil, errors.Wrapf(types.ErrInvalidParam, "in=%v", in)
}
list, err := getBindNodeInfo(p.GetStateDB(), in.Data)
if err != nil {
return nil, err
}
var resp pt.RespParaNodeBindList
resp.List = list
for _, addr := range list.Miners {
info, err := getBindAddrInfo(p.GetStateDB(), in.Data, addr)
if err != nil {
return nil, err
}
resp.Details = append(resp.Details, info)
}
return &resp, nil
}
This diff is collapsed.
...@@ -161,10 +161,11 @@ message RespParacrossNodeGroups { ...@@ -161,10 +161,11 @@ message RespParacrossNodeGroups {
//para bind miner //para bind miner
message ParaBindMinerInfo{ message ParaBindMinerInfo{
string addr = 1; // miner addr string addr = 1; // miner addr
int32 bindStatus = 2; // 0: init, 1: bind, 2:unbind int32 bindAction = 2; // 1: bind, 2:unbind
int64 bindCount = 3; // bind coins count int64 bindCount = 3; // bind coins count
int64 blockTime = 4; // status bind block time string targetAddr = 4; // super node addr
string targetAddr = 5; // super node addr int64 blockTime = 5; // action bind block time
int64 blockHeight = 6; // action bind block height
} }
message ReceiptParaBindMinerInfo{ message ReceiptParaBindMinerInfo{
...@@ -183,6 +184,11 @@ message ReceiptParaNodeBindListUpdate{ ...@@ -183,6 +184,11 @@ message ReceiptParaNodeBindListUpdate{
ParaNodeBindList current = 2; ParaNodeBindList current = 2;
} }
message RespParaNodeBindList{
ParaNodeBindList list = 1;
repeated ParaBindMinerInfo details = 2;
}
message ParaBlock2MainMap { message ParaBlock2MainMap {
int64 height = 1; int64 height = 1;
string blockHash = 2; string blockHash = 2;
......
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