Commit e010ff88 authored by mdj33's avatar mdj33 Committed by vipwzw

paracross add query

parent 0ed57c0e
......@@ -446,7 +446,7 @@ func paraInfo(cmd *cobra.Command, args []string) {
Title: title,
Height: height,
}
var res pt.RespParacrossDone
var res pt.ParacrossHeightStatusRsp
ctx := jsonclient.NewRPCCtx(rpcLaddr, "paracross.GetTitleHeight", params, &res)
ctx.Run()
}
......
......@@ -344,6 +344,7 @@ func (a *action) Commit(commit *pt.ParacrossCommitAction) (*types.Receipt, error
}
if a.exec.GetMainHeight() >= getDappForkHeight(pt.ForkCommitTx) {
stat.MainHeight = commit.Status.MainBlockHeight
stat.MainHash = commit.Status.MainBlockHash
}
receipt = makeCommitReceipt(a.fromaddr, commit, nil, stat)
} else {
......@@ -384,8 +385,7 @@ func (a *action) Commit(commit *pt.ParacrossCommitAction) (*types.Receipt, error
}
//add commit done receipt
receiptDone := makeDoneReceipt(a.fromaddr, commit, stat, int32(most), int32(commitCount), int32(len(nodes)))
receipt.KV = append(receipt.KV, receiptDone.KV...)
receipt.Logs = append(receipt.Logs, receiptDone.Logs...)
receipt = mergeReceipt(receipt, receiptDone)
//平行连进行奖励分配,考虑可能的失败,需要在保存共识高度等数据之前处理
if types.IsPara() {
......
......@@ -12,6 +12,7 @@ import (
"github.com/33cn/chain33/types"
pt "github.com/33cn/plugin/plugin/dapp/paracross/types"
"github.com/pkg/errors"
"github.com/33cn/chain33/common"
)
// Query_GetTitle query paracross title
......@@ -22,6 +23,31 @@ func (p *Paracross) Query_GetTitle(in *types.ReqString) (types.Message, error) {
return p.paracrossGetHeight(in.GetData())
}
// Query_GetTitleHeight query paracross status with title and height
func (p *Paracross) Query_GetTitleHeight(in *pt.ReqParacrossTitleHeight) (types.Message, error) {
if in == nil {
return nil, types.ErrInvalidParam
}
stat,err:= p.paracrossGetStateTitleHeight(in.Title,in.Height)
if err != nil {
clog.Error("paracross.GetTitleHeight", "title", title, "height", in.Height, "err", err.Error())
return nil,err
}
status := stat.(*pt.ParacrossHeightStatus)
res := &pt.ParacrossHeightStatusRsp{
Status:status.Status,
Title:status.Title,
Height:status.Height,
MainHeight:status.MainHeight,
MainHash:common.ToHex(status.MainHash),
}
for i,addr := range status.Details.Addrs{
res.CommitAddrs = append(res.CommitAddrs, addr)
res.CommitBlockHash = append(res.CommitBlockHash,common.ToHex(status.Details.BlockHash[i]))
}
return res,nil
}
// Query_GetTitleByHash query paracross title by block hash
func (p *Paracross) Query_GetTitleByHash(in *pt.ReqParacrossTitleHash) (types.Message, error) {
if in == nil {
......@@ -99,8 +125,8 @@ func (p *Paracross) Query_ListTitles(in *types.ReqNil) (types.Message, error) {
return p.paracrossListTitles()
}
// Query_GetTitleHeight query title height
func (p *Paracross) Query_GetTitleHeight(in *pt.ReqParacrossTitleHeight) (types.Message, error) {
// Query_GetDoneTitleHeight query title height
func (p *Paracross) Query_GetDoneTitleHeight(in *pt.ReqParacrossTitleHeight) (types.Message, error) {
if in == nil {
return nil, types.ErrInvalidParam
}
......
......@@ -20,6 +20,18 @@ message ParacrossHeightStatus {
int64 height = 3;
ParacrossStatusDetails details = 4;
int64 mainHeight = 5;
bytes mainHash = 6;
}
message ParacrossHeightStatusRsp {
int32 status = 1;
string title = 2;
int64 height = 3;
int64 mainHeight = 4;
string mainHash = 5;
repeated string commitAddrs = 6;
repeated string commitBlockHash = 7;
}
message ParacrossStatus {
......@@ -263,7 +275,8 @@ message ParacrossAsset {
service paracross {
rpc GetTitle(ReqString) returns (ParacrossConsensusStatus) {}
rpc ListTitles(ReqNil) returns (RespParacrossTitles) {}
rpc GetTitleHeight(ReqParacrossTitleHeight) returns (RespParacrossDone) {}
rpc GetDoneTitleHeight(ReqParacrossTitleHeight) returns (RespParacrossDone) {}
rpc GetTitleHeight(ReqParacrossTitleHeight) returns (ParacrossHeightStatusRsp) {}
rpc GetAssetTxResult(ReqHash) returns (ParacrossAsset) {}
rpc IsSync(ReqNil) returns (IsCaughtUp) {}
}
\ No newline at end of file
......@@ -72,12 +72,12 @@ func (c *Jrpc) ListTitles(req *types.ReqNil, result *interface{}) error {
return err
}
func (c *channelClient) GetTitleHeight(ctx context.Context, req *pt.ReqParacrossTitleHeight) (*pt.RespParacrossDone, error) {
func (c *channelClient) GetTitleHeight(ctx context.Context, req *pt.ReqParacrossTitleHeight) (*pt.ParacrossHeightStatusRsp, error) {
data, err := c.Query(pt.GetExecName(), "GetTitleHeight", req)
if err != nil {
return nil, err
}
if resp, ok := data.(*pt.RespParacrossDone); ok {
if resp, ok := data.(*pt.ParacrossHeightStatusRsp); ok {
return resp, nil
}
return nil, types.ErrDecode
......@@ -93,6 +93,18 @@ func (c *Jrpc) GetTitleHeight(req *pt.ReqParacrossTitleHeight, result *interface
return err
}
func (c *channelClient) GetDoneTitleHeight(ctx context.Context, req *pt.ReqParacrossTitleHeight) (*pt.RespParacrossDone, error) {
data, err := c.Query(pt.GetExecName(), "GetDoneTitleHeight", req)
if err != nil {
return nil, err
}
if resp, ok := data.(*pt.RespParacrossDone); ok {
return resp, nil
}
return nil, types.ErrDecode
}
func (c *channelClient) GetAssetTxResult(ctx context.Context, req *types.ReqHash) (*pt.ParacrossAsset, error) {
data, err := c.Query(pt.GetExecName(), "GetAssetTxResult", req)
if err != 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