Commit 8b29c90a authored by wjx@disanbo.com's avatar wjx@disanbo.com Committed by vipwzw

update lottery

parent 8222696c
......@@ -9,59 +9,10 @@ import (
"time"
"github.com/33cn/chain33/types"
pty "github.com/33cn/plugin/plugin/dapp/lottery/types"
tickettypes "github.com/33cn/plugin/plugin/dapp/ticket/types"
)
const retryNum = 10
//different impl on main chain and parachain
func (action *Action) getTxActions(height int64, blockNum int64) ([]*tickettypes.TicketAction, error) {
var txActions []*tickettypes.TicketAction
llog.Error("getTxActions", "height", height, "blockNum", blockNum)
if !types.IsPara() {
req := &types.ReqBlocks{Start: height - blockNum + 1, End: height, IsDetail: false, Pid: []string{""}}
blockDetails, err := action.api.GetBlocks(req)
if err != nil {
llog.Error("getTxActions", "height", height, "blockNum", blockNum, "err", err)
return txActions, err
}
for _, block := range blockDetails.Items {
llog.Debug("getTxActions", "blockHeight", block.Block.Height, "blockhash", block.Block.Hash())
ticketAction, err := action.getMinerTx(block.Block)
if err != nil {
return txActions, err
}
txActions = append(txActions, ticketAction)
}
return txActions, nil
}
//block height on main
mainHeight := action.GetMainHeightByTxHash(action.txhash)
if mainHeight < 0 {
llog.Error("LotteryCreate", "mainHeight", mainHeight)
return nil, pty.ErrLotteryStatus
}
blockDetails, err := action.GetBlocksOnMain(mainHeight-blockNum, mainHeight-1)
if err != nil {
llog.Error("LotteryCreate", "mainHeight", mainHeight)
return nil, pty.ErrLotteryStatus
}
for _, block := range blockDetails.Items {
ticketAction, err := action.getMinerTx(block.Block)
if err != nil {
return txActions, err
}
txActions = append(txActions, ticketAction)
}
return txActions, nil
}
// GetMainHeightByTxHash get Block height
func (action *Action) GetMainHeightByTxHash(txHash []byte) int64 {
for i := 0; i < retryNum; i++ {
......@@ -76,58 +27,3 @@ func (action *Action) GetMainHeightByTxHash(txHash []byte) int64 {
return -1
}
// GetBlocksOnMain get Block from main chain
func (action *Action) GetBlocksOnMain(start int64, end int64) (*types.BlockDetails, error) {
req := &types.ReqBlocks{Start: start, End: end, IsDetail: false, Pid: []string{""}}
getBlockSucc := false
var reply *types.Reply
var err error
for i := 0; i < retryNum; i++ {
reply, err = action.grpcClient.GetBlocks(context.Background(), req)
if err != nil {
llog.Error("GetBlocksOnMain", "start", start, "end", end, "err", err)
time.Sleep(time.Second)
} else {
getBlockSucc = true
break
}
}
if !getBlockSucc {
return nil, err
}
var blockDetails types.BlockDetails
err = types.Decode(reply.Msg, &blockDetails)
if err != nil {
llog.Error("GetBlocksOnMain", "err", err)
return nil, err
}
return &blockDetails, nil
}
func (action *Action) getMinerTx(current *types.Block) (*tickettypes.TicketAction, error) {
//检查第一个笔交易的execs, 以及执行状态
if len(current.Txs) == 0 {
return nil, types.ErrEmptyTx
}
baseTx := current.Txs[0]
//判断交易类型和执行情况
var ticketAction tickettypes.TicketAction
err := types.Decode(baseTx.GetPayload(), &ticketAction)
if err != nil {
return nil, err
}
if ticketAction.GetTy() != tickettypes.TicketActionMiner {
return nil, types.ErrCoinBaseTxType
}
//判断交易执行是否OK
if ticketAction.GetMiner() == nil {
return nil, tickettypes.ErrEmptyMinerTx
}
return &ticketAction, nil
}
This diff is collapsed.
......@@ -16,9 +16,11 @@ func (l *Lottery) Query_GetLotteryNormalInfo(param *pty.ReqLotteryInfo) (types.M
return nil, err
}
return &pty.ReplyLotteryNormalInfo{CreateHeight: lottery.CreateHeight,
PurBlockNum: lottery.PurBlockNum,
DrawBlockNum: lottery.DrawBlockNum,
CreateAddr: lottery.CreateAddr}, nil
PurBlockNum: lottery.PurBlockNum,
DrawBlockNum: lottery.DrawBlockNum,
CreateAddr: lottery.CreateAddr,
OpRewardRatio: lottery.OpRewardRatio,
DevRewardRatio: lottery.DevRewardRatio}, nil
}
// Query_GetLotteryPurchaseAddr for current round
......@@ -28,8 +30,8 @@ func (l *Lottery) Query_GetLotteryPurchaseAddr(param *pty.ReqLotteryInfo) (types
return nil, err
}
reply := &pty.ReplyLotteryPurchaseAddr{}
for addr := range lottery.Records {
reply.Address = append(reply.Address, addr)
for _, recs := range lottery.PurRecords {
reply.Address = append(reply.Address, recs.Addr)
}
//lottery.Records
return reply, nil
......
......@@ -13,6 +13,7 @@ message PurchaseRecords {
repeated PurchaseRecord record = 1;
int64 fundWin = 2;
int64 amountOneRound = 3;
string addr = 4;
}
message Lottery {
......@@ -24,7 +25,7 @@ message Lottery {
int64 drawBlockNum = 6;
int64 lastTransToPurState = 7;
int64 lastTransToDrawState = 8;
map<string, PurchaseRecords> records = 9;
//map<string, PurchaseRecords> records = 9;
int64 totalPurchasedTxNum = 10;
string createAddr = 11;
int64 round = 12;
......@@ -33,6 +34,9 @@ message Lottery {
int64 lastTransToPurStateOnMain = 15;
int64 lastTransToDrawStateOnMain = 16;
repeated MissingRecord missingRecords = 17;
int64 opRewardRatio = 18;
int64 devRewardRatio = 19;
repeated PurchaseRecords purRecords = 20;
}
message MissingRecord {
......@@ -50,8 +54,10 @@ message LotteryAction {
}
message LotteryCreate {
int64 purBlockNum = 1;
int64 drawBlockNum = 2;
int64 purBlockNum = 1;
int64 drawBlockNum = 2;
int64 opRewardRatio = 3;
int64 devRewardRatio = 4;
}
message LotteryBuy {
......@@ -117,10 +123,12 @@ message ReqLotteryLuckyHistory {
}
message ReplyLotteryNormalInfo {
int64 createHeight = 1;
int64 purBlockNum = 2;
int64 drawBlockNum = 3;
string createAddr = 4;
int64 createHeight = 1;
int64 purBlockNum = 2;
int64 drawBlockNum = 3;
string createAddr = 4;
int64 opRewardRatio = 5;
int64 devRewardRatio = 6;
}
message ReplyLotteryCurrentInfo {
......
......@@ -25,4 +25,5 @@ var (
ErrLotteryErrUnableClose = errors.New("ErrLotteryErrUnableClose")
ErrNodeNotExist = errors.New("ErrNodeNotExist")
ErrEmptyMinerTx = errors.New("ErrEmptyMinerTx")
ErrRewardFactor = errors.New("ErrRewardFactor")
)
This diff is collapsed.
......@@ -9,6 +9,8 @@ type LotteryCreateTx struct {
PurBlockNum int64 `json:"purBlockNum"`
DrawBlockNum int64 `json:"drawBlockNum"`
Fee int64 `json:"fee"`
OpRewardRatio int64 `json:"opRewardRatio"`
DevRewardRatio int64 `json:"devRewardRatio"`
}
// LotteryBuyTx for construction
......
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