Commit d32b6dce authored by 张振华's avatar 张振华

refactor to use new execapi to query data from main chain

parent efb27f35
...@@ -5,18 +5,14 @@ ...@@ -5,18 +5,14 @@
package executor package executor
import ( import (
"context"
"fmt" "fmt"
"strings" "github.com/33cn/chain33/client/api"
"time"
"github.com/33cn/chain33/common/db" "github.com/33cn/chain33/common/db"
"github.com/33cn/chain33/common/db/table" "github.com/33cn/chain33/common/db/table"
"strings"
"github.com/33cn/chain33/client"
"google.golang.org/grpc"
"github.com/33cn/chain33/account" "github.com/33cn/chain33/account"
"github.com/33cn/chain33/client"
"github.com/33cn/chain33/common" "github.com/33cn/chain33/common"
dbm "github.com/33cn/chain33/common/db" dbm "github.com/33cn/chain33/common/db"
"github.com/33cn/chain33/system/dapp" "github.com/33cn/chain33/system/dapp"
...@@ -48,12 +44,6 @@ const ( ...@@ -48,12 +44,6 @@ const (
//MaxExpireHeight 距离游戏创建区块的最大过期高度差 //MaxExpireHeight 距离游戏创建区块的最大过期高度差
MaxExpireHeight = 1000000 MaxExpireHeight = 1000000
//grpcRecSize 接收缓冲大小
grpcRecSize int = 30 * 1024 * 1024
//retryNum 失败时的重试次数
retryNum = 10
) )
//Action 具体动作执行 //Action 具体动作执行
...@@ -68,8 +58,7 @@ type Action struct { ...@@ -68,8 +58,7 @@ type Action struct {
localDB dbm.KVDB localDB dbm.KVDB
index int index int
api client.QueueProtocolAPI api client.QueueProtocolAPI
conn *grpc.ClientConn execApi api.ExecutorAPI
grpcClient types.Chain33Client
} }
//NewAction 生成Action对象 //NewAction 生成Action对象
...@@ -77,19 +66,6 @@ func NewAction(guess *Guess, tx *types.Transaction, index int) *Action { ...@@ -77,19 +66,6 @@ func NewAction(guess *Guess, tx *types.Transaction, index int) *Action {
hash := tx.Hash() hash := tx.Hash()
fromAddr := tx.From() fromAddr := tx.From()
msgRecvOp := grpc.WithMaxMsgSize(grpcRecSize)
paraRemoteGrpcClient := types.Conf("config.consensus.sub.para").GStr("ParaRemoteGrpcClient")
if types.IsPara() && paraRemoteGrpcClient == "" {
panic("ParaRemoteGrpcClient error")
}
conn, err := grpc.Dial(paraRemoteGrpcClient, grpc.WithInsecure(), msgRecvOp)
if err != nil {
panic(err)
}
grpcClient := types.NewChain33Client(conn)
return &Action{ return &Action{
coinsAccount: guess.GetCoinsAccount(), coinsAccount: guess.GetCoinsAccount(),
db: guess.GetStateDB(), db: guess.GetStateDB(),
...@@ -101,8 +77,7 @@ func NewAction(guess *Guess, tx *types.Transaction, index int) *Action { ...@@ -101,8 +77,7 @@ func NewAction(guess *Guess, tx *types.Transaction, index int) *Action {
localDB: guess.GetLocalDB(), localDB: guess.GetLocalDB(),
index: index, index: index,
api: guess.GetAPI(), api: guess.GetAPI(),
conn: conn, execApi: guess.GetExecutorAPI(),
grpcClient: grpcClient,
} }
} }
...@@ -902,15 +877,11 @@ func (action *Action) checkTime(start *gty.GuessGameStart) bool { ...@@ -902,15 +877,11 @@ func (action *Action) checkTime(start *gty.GuessGameStart) bool {
// GetMainHeightByTxHash get Block height // GetMainHeightByTxHash get Block height
func (action *Action) GetMainHeightByTxHash(txHash []byte) int64 { func (action *Action) GetMainHeightByTxHash(txHash []byte) int64 {
for i := 0; i < retryNum; i++ { req := &types.ReqHash{Hash: txHash}
req := &types.ReqHash{Hash: txHash} txDetail, err := action.execApi.QueryTx(req)
txDetail, err := action.grpcClient.QueryTransaction(context.Background(), req) if err != nil {
if err != nil { return -1
time.Sleep(time.Second)
} else {
return txDetail.GetHeight()
}
} }
return -1 return txDetail.GetHeight()
} }
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