Commit 039dc644 authored by jixing wei's avatar jixing wei Committed by vipwzw

get mainblockhash from paracross

parent 5d2d1be2
......@@ -127,6 +127,7 @@ type Action struct {
conn *grpc.ClientConn
grpcClient types.Chain33Client
index int
lottery *Lottery
}
// NewLotteryAction generate New Action
......@@ -145,7 +146,7 @@ func NewLotteryAction(l *Lottery, tx *types.Transaction, index int) *Action {
grpcClient := types.NewChain33Client(conn)
return &Action{l.GetCoinsAccount(), l.GetStateDB(), hash, fromaddr, l.GetBlockTime(),
l.GetHeight(), dapp.ExecAddress(string(tx.Execer)), l.GetDifficulty(), l.GetAPI(), conn, grpcClient, index}
l.GetHeight(), dapp.ExecAddress(string(tx.Execer)), l.GetDifficulty(), l.GetAPI(), conn, grpcClient, index, l}
}
// GetLottCommonRecipt generate logs for lottery common action
......@@ -590,18 +591,19 @@ func (action *Action) findLuckyNum(isSolo bool, lott *LotteryDB) int64 {
reply := msg.(*types.ReplyHash)
hash = reply.Hash
} else {
mainHeight := action.GetMainHeightByTxHash(action.txhash)
if mainHeight < 0 {
llog.Error("findLuckyNum", "mainHeight", mainHeight)
txs := action.lottery.GetTxs()
if len(txs) < action.index+1 {
llog.Error("findLuckyNum", "len(txs)", len(txs), "index", action.index)
return -1
}
mainBlockHash, err := action.GetMainBlockHashByHeight(mainHeight)
msg, err := action.api.Query("paracross", "GetMainBlockHash", txs[0])
if err != nil {
llog.Error("findLuckyNum", "err", err)
return -1
}
queryReply := msg.(*types.ReplyHash)
mainBlockHash := queryReply.Hash
req := &types.ReqRandHash{ExecName: "ticket", Hash: mainBlockHash, BlockNum: blockNum}
reply, err := action.grpcClient.QueryRandNum(context.Background(), req)
if err != nil {
......
......@@ -40,6 +40,38 @@ func (p *Paracross) Query_GetAssetTxResult(in *types.ReqHash) (types.Message, er
return p.paracrossGetAssetTxResult(in.Hash)
}
// Query_GetMainBlockHash query get mainblockHash by tx
func (p *Paracross) Query_GetMainBlockHash(in *types.Transaction) (types.Message, error) {
if in == nil {
return nil, types.ErrInvalidParam
}
return p.paracrossGetMainBlockHash(in)
}
func (p *Paracross) paracrossGetMainBlockHash(tx *types.Transaction) (types.Message, error) {
var paraAction pt.ParacrossAction
err := types.Decode(tx.GetPayload(), &paraAction)
if err != nil {
return nil, err
}
if paraAction.GetTy() != pt.ParacrossActionMiner {
return nil, types.ErrCoinBaseTxType
}
if paraAction.GetMiner() == nil {
return nil, pt.ErrParaEmptyMinerTx
}
paraNodeStatus := paraAction.GetMiner().GetStatus()
if paraNodeStatus == nil {
return nil, types.ErrCoinBaseTxType
}
mainHashFromNode := paraNodeStatus.MainBlockHash
return &types.ReplyHash{Hash: mainHashFromNode}, nil
}
func (p *Paracross) paracrossGetHeight(title string) (types.Message, error) {
ret, err := getTitle(p.GetStateDB(), calcTitleKey(title))
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