Commit 1d8ddb8c authored by harrylee2015's avatar harrylee2015 Committed by vipwzw

rejust para rpc query

parent 6811bb28
......@@ -11,6 +11,7 @@ import (
"os"
"strings"
"github.com/33cn/chain33/rpc/jsonclient"
"github.com/33cn/chain33/types"
pt "github.com/33cn/plugin/plugin/dapp/paracross/types"
"github.com/spf13/cobra"
......@@ -29,6 +30,7 @@ func ParcCmd() *cobra.Command {
CreateRawTransferCmd(),
CreateRawWithdrawCmd(),
CreateRawTransferToExecCmd(),
IsSyncCmd(),
)
return cmd
}
......@@ -281,3 +283,20 @@ func createTransferTx(cmd *cobra.Command, isWithdraw bool) (string, error) {
txHex := types.Encode(tx)
return hex.EncodeToString(txHex), nil
}
// IsSyncCmd query parachain is sync
func IsSyncCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "is_sync",
Short: "query parachain is sync",
Run: isSync,
}
return cmd
}
func isSync(cmd *cobra.Command, args []string) {
rpcLaddr, _ := cmd.Flags().GetString("rpc_laddr")
var res bool
ctx := jsonclient.NewRPCCtx(rpcLaddr, "paracross.IsSync", nil, &res)
ctx.Run()
}
......@@ -91,3 +91,26 @@ func (c *Jrpc) GetAssetTxResult(req *types.ReqHash, result *interface{}) error {
*result = data
return err
}
// IsSync query is sync
func (g *channelClient) IsSync(ctx context.Context, in *types.ReqNil) (*types.IsCaughtUp, error) {
data, err := g.QueryConsensusFunc("para", "IsCaughtUp", &types.ReqNil{})
if err != nil {
return nil, err
}
return data.(*types.IsCaughtUp), nil
}
// IsSync query is sync
func (c *Jrpc) IsSync(in *types.ReqNil, result *bool) error {
//TODO consensus and paracross are not the same registered names ?
data, err := c.cli.QueryConsensusFunc("para", "IsCaughtUp", &types.ReqNil{})
*result = false
if err != nil {
return err
}
if reply, ok := data.(*types.IsCaughtUp); ok {
*result = reply.Iscaughtup
}
return nil
}
......@@ -678,13 +678,7 @@ func (q *QueueProtocol) DumpPrivkey(param *types.ReqString) (*types.ReplyString,
// IsSync query the blockchain sync state
func (q *QueueProtocol) IsSync() (*types.Reply, error) {
var msg queue.Message
var err error
if types.IsPara() {
msg, err = q.query(consensusKey, types.EventIsSync, &types.ReqNil{})
} else {
msg, err = q.query(blockchainKey, types.EventIsSync, &types.ReqNil{})
}
msg, err := q.query(blockchainKey, types.EventIsSync, &types.ReqNil{})
if err != nil {
log.Error("IsSync", "Error", err.Error())
return nil, err
......
......@@ -216,23 +216,6 @@ func (bc *BaseClient) EventLoop() {
block := msg.GetData().(*types.BlockDetail)
err := bc.CheckBlock(block)
msg.ReplyErr("EventCheckBlock", err)
} else if msg.Ty == types.EventIsSync {
if types.IsPara() {
reply, err := QueryData.Call("para", "IsCaughtUp", &types.ReqNil{})
if err != nil {
msg.Reply(bc.api.NewMessage("", types.EventReplyIsSync, err))
} else {
if isCaughtUp, ok := reply.(*types.IsCaughtUp); ok {
msg.Reply(bc.api.NewMessage("", types.EventReplyIsSync, isCaughtUp))
} else {
err = types.ErrTypeAsset
msg.Reply(bc.api.NewMessage("", types.EventReplyIsSync, err))
}
}
} else {
msg.Reply(bc.api.NewMessage("", types.EventReplyIsSync, &types.IsCaughtUp{Iscaughtup: bc.IsCaughtUp()}))
}
} else if msg.Ty == types.EventMinerStart {
if !atomic.CompareAndSwapInt32(&bc.minerStart, 0, 1) {
msg.ReplyErr("EventMinerStart", types.ErrMinerIsStared)
......
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