Commit 3c399015 authored by wjx@disanbo.com's avatar wjx@disanbo.com Committed by vipwzw

add query item

parent 1fb4c5b2
...@@ -180,7 +180,7 @@ func (lott *Lottery) updateLotteryBuy(lotterylog *pty.ReceiptLottery, isAdd bool ...@@ -180,7 +180,7 @@ func (lott *Lottery) updateLotteryBuy(lotterylog *pty.ReceiptLottery, isAdd bool
func (lott *Lottery) saveLotteryDraw(lotterylog *pty.ReceiptLottery) (kvs []*types.KeyValue) { func (lott *Lottery) saveLotteryDraw(lotterylog *pty.ReceiptLottery) (kvs []*types.KeyValue) {
key := calcLotteryDrawKey(lotterylog.LotteryId, lotterylog.Round) key := calcLotteryDrawKey(lotterylog.LotteryId, lotterylog.Round)
record := &pty.LotteryDrawRecord{Number: lotterylog.LuckyNumber, Round: lotterylog.Round, Time: lotterylog.Time, TxHash: lotterylog.TxHash} record := &pty.LotteryDrawRecord{Number: lotterylog.LuckyNumber, Round: lotterylog.Round, Time: lotterylog.Time, TxHash: lotterylog.TxHash, TotalAddrNum: lotterylog.TotalAddrNum, BuyAmount: lotterylog.BuyAmount}
kv := &types.KeyValue{Key: key, Value: types.Encode(record)} kv := &types.KeyValue{Key: key, Value: types.Encode(record)}
kvs = append(kvs, kv) kvs = append(kvs, kv)
return kvs return kvs
......
...@@ -149,38 +149,79 @@ func NewLotteryAction(l *Lottery, tx *types.Transaction, index int) *Action { ...@@ -149,38 +149,79 @@ func NewLotteryAction(l *Lottery, tx *types.Transaction, index int) *Action {
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}
} }
// GetReceiptLog generate logs for all lottery action // GetLottCommonRecipt generate logs for lottery common action
func (action *Action) GetReceiptLog(lottery *pty.Lottery, preStatus int32, logTy int32, func (action *Action) GetLottCommonRecipt(lottery *pty.Lottery, preStatus int32) *pty.ReceiptLottery {
round int64, buyNumber int64, amount int64, way int64, luckyNum int64, updateInfo *pty.LotteryUpdateBuyInfo) *types.ReceiptLog {
log := &types.ReceiptLog{}
l := &pty.ReceiptLottery{} l := &pty.ReceiptLottery{}
log.Ty = logTy
l.LotteryId = lottery.LotteryId l.LotteryId = lottery.LotteryId
l.Status = lottery.Status l.Status = lottery.Status
l.PrevStatus = preStatus l.PrevStatus = preStatus
if logTy == pty.TyLogLotteryBuy { return l
l.Round = round }
l.Number = buyNumber
l.Amount = amount // GetCreateReceiptLog generate logs for lottery create action
l.Addr = action.fromaddr func (action *Action) GetCreateReceiptLog(lottery *pty.Lottery, preStatus int32) *types.ReceiptLog {
l.Way = way log := &types.ReceiptLog{}
l.Index = action.GetIndex() log.Ty = pty.TyLogLotteryCreate
l.Time = action.blocktime
l.TxHash = common.ToHex(action.txhash) l := action.GetLottCommonRecipt(lottery, preStatus)
}
if logTy == pty.TyLogLotteryDraw { log.Log = types.Encode(l)
l.Round = round
l.LuckyNumber = luckyNum return log
l.Time = action.blocktime }
l.TxHash = common.ToHex(action.txhash)
if len(updateInfo.BuyInfo) > 0 { // GetBuyReceiptLog generate logs for lottery buy action
l.UpdateInfo = updateInfo func (action *Action) GetBuyReceiptLog(lottery *pty.Lottery, preStatus int32, round int64, buyNumber int64, amount int64, way int64) *types.ReceiptLog {
} log := &types.ReceiptLog{}
log.Ty = pty.TyLogLotteryBuy
l := action.GetLottCommonRecipt(lottery, preStatus)
l.Round = round
l.Number = buyNumber
l.Amount = amount
l.Addr = action.fromaddr
l.Way = way
l.Index = action.GetIndex()
l.Time = action.blocktime
l.TxHash = common.ToHex(action.txhash)
log.Log = types.Encode(l)
return log
}
// GetDrawReceiptLog generate logs for lottery draw action
func (action *Action) GetDrawReceiptLog(lottery *pty.Lottery, preStatus int32, round int64, luckyNum int64, updateInfo *pty.LotteryUpdateBuyInfo, addrNumThisRound int64, buyAmountThisRound int64) *types.ReceiptLog {
log := &types.ReceiptLog{}
log.Ty = pty.TyLogLotteryDraw
l := action.GetLottCommonRecipt(lottery, preStatus)
l.Round = round
l.LuckyNumber = luckyNum
l.Time = action.blocktime
l.TxHash = common.ToHex(action.txhash)
l.TotalAddrNum = addrNumThisRound
l.BuyAmount = buyAmountThisRound
if len(updateInfo.BuyInfo) > 0 {
l.UpdateInfo = updateInfo
} }
log.Log = types.Encode(l) log.Log = types.Encode(l)
return log
}
// GetCloseReceiptLog generate logs for lottery close action
func (action *Action) GetCloseReceiptLog(lottery *pty.Lottery, preStatus int32) *types.ReceiptLog {
log := &types.ReceiptLog{}
log.Ty = pty.TyLogLotteryClose
l := action.GetLottCommonRecipt(lottery, preStatus)
log.Log = types.Encode(l)
return log return log
} }
...@@ -228,6 +269,8 @@ func (action *Action) LotteryCreate(create *pty.LotteryCreate) (*types.Receipt, ...@@ -228,6 +269,8 @@ func (action *Action) LotteryCreate(create *pty.LotteryCreate) (*types.Receipt,
lott.OpRewardRatio = create.OpRewardRatio lott.OpRewardRatio = create.OpRewardRatio
lott.DevRewardRatio = create.DevRewardRatio lott.DevRewardRatio = create.DevRewardRatio
lott.TotalAddrNum = 0
lott.BuyAmount = 0
llog.Debug("LotteryCreate", "OpRewardRatio", lott.OpRewardRatio, "DevRewardRatio", lott.DevRewardRatio) llog.Debug("LotteryCreate", "OpRewardRatio", lott.OpRewardRatio, "DevRewardRatio", lott.DevRewardRatio)
if types.IsPara() { if types.IsPara() {
mainHeight := action.GetMainHeightByTxHash(action.txhash) mainHeight := action.GetMainHeightByTxHash(action.txhash)
...@@ -243,7 +286,7 @@ func (action *Action) LotteryCreate(create *pty.LotteryCreate) (*types.Receipt, ...@@ -243,7 +286,7 @@ func (action *Action) LotteryCreate(create *pty.LotteryCreate) (*types.Receipt,
lott.Save(action.db) lott.Save(action.db)
kv = append(kv, lott.GetKVSet()...) kv = append(kv, lott.GetKVSet()...)
receiptLog := action.GetReceiptLog(&lott.Lottery, 0, pty.TyLogLotteryCreate, 0, 0, 0, 0, 0, nil) receiptLog := action.GetCreateReceiptLog(&lott.Lottery, 0)
logs = append(logs, receiptLog) logs = append(logs, receiptLog)
receipt = &types.Receipt{Ty: types.ExecOk, KV: kv, Logs: logs} receipt = &types.Receipt{Ty: types.ExecOk, KV: kv, Logs: logs}
...@@ -352,6 +395,7 @@ func (action *Action) LotteryBuy(buy *pty.LotteryBuy) (*types.Receipt, error) { ...@@ -352,6 +395,7 @@ func (action *Action) LotteryBuy(buy *pty.LotteryBuy) (*types.Receipt, error) {
kv = append(kv, receipt.KV...) kv = append(kv, receipt.KV...)
lott.Fund += buy.GetAmount() lott.Fund += buy.GetAmount()
lott.BuyAmount += buy.GetAmount()
lott.TotalPurchasedTxNum++ lott.TotalPurchasedTxNum++
newAddr := true newAddr := true
...@@ -370,12 +414,13 @@ func (action *Action) LotteryBuy(buy *pty.LotteryBuy) (*types.Receipt, error) { ...@@ -370,12 +414,13 @@ func (action *Action) LotteryBuy(buy *pty.LotteryBuy) (*types.Receipt, error) {
initrecord.AmountOneRound = buy.Amount initrecord.AmountOneRound = buy.Amount
initrecord.Addr = action.fromaddr initrecord.Addr = action.fromaddr
lott.PurRecords = append(lott.PurRecords, initrecord) lott.PurRecords = append(lott.PurRecords, initrecord)
lott.TotalAddrNum++
} }
lott.Save(action.db) lott.Save(action.db)
kv = append(kv, lott.GetKVSet()...) kv = append(kv, lott.GetKVSet()...)
receiptLog := action.GetReceiptLog(&lott.Lottery, preStatus, pty.TyLogLotteryBuy, lott.Round, buy.GetNumber(), buy.GetAmount(), buy.GetWay(), 0, nil) receiptLog := action.GetBuyReceiptLog(&lott.Lottery, preStatus, lott.Round, buy.GetNumber(), buy.GetAmount(), buy.GetWay())
logs = append(logs, receiptLog) logs = append(logs, receiptLog)
receipt = &types.Receipt{Ty: types.ExecOk, KV: kv, Logs: logs} receipt = &types.Receipt{Ty: types.ExecOk, KV: kv, Logs: logs}
...@@ -427,6 +472,10 @@ func (action *Action) LotteryDraw(draw *pty.LotteryDraw) (*types.Receipt, error) ...@@ -427,6 +472,10 @@ func (action *Action) LotteryDraw(draw *pty.LotteryDraw) (*types.Receipt, error)
//} //}
} }
//record addr and amount this round
addrNumThisRound := lott.TotalAddrNum
buyAmountThisRound := lott.BuyAmount
rec, updateInfo, err := action.checkDraw(lott) rec, updateInfo, err := action.checkDraw(lott)
if err != nil { if err != nil {
return nil, err return nil, err
...@@ -437,7 +486,7 @@ func (action *Action) LotteryDraw(draw *pty.LotteryDraw) (*types.Receipt, error) ...@@ -437,7 +486,7 @@ func (action *Action) LotteryDraw(draw *pty.LotteryDraw) (*types.Receipt, error)
lott.Save(action.db) lott.Save(action.db)
kv = append(kv, lott.GetKVSet()...) kv = append(kv, lott.GetKVSet()...)
receiptLog := action.GetReceiptLog(&lott.Lottery, preStatus, pty.TyLogLotteryDraw, lott.Round, 0, 0, 0, lott.LuckyNumber, updateInfo) receiptLog := action.GetDrawReceiptLog(&lott.Lottery, preStatus, lott.Round, lott.LuckyNumber, updateInfo, addrNumThisRound, buyAmountThisRound)
logs = append(logs, receiptLog) logs = append(logs, receiptLog)
receipt = &types.Receipt{Ty: types.ExecOk, KV: kv, Logs: logs} receipt = &types.Receipt{Ty: types.ExecOk, KV: kv, Logs: logs}
...@@ -508,7 +557,7 @@ func (action *Action) LotteryClose(draw *pty.LotteryClose) (*types.Receipt, erro ...@@ -508,7 +557,7 @@ func (action *Action) LotteryClose(draw *pty.LotteryClose) (*types.Receipt, erro
lott.Save(action.db) lott.Save(action.db)
kv = append(kv, lott.GetKVSet()...) kv = append(kv, lott.GetKVSet()...)
receiptLog := action.GetReceiptLog(&lott.Lottery, preStatus, pty.TyLogLotteryClose, 0, 0, 0, 0, 0, nil) receiptLog := action.GetCloseReceiptLog(&lott.Lottery, preStatus)
logs = append(logs, receiptLog) logs = append(logs, receiptLog)
return &types.Receipt{Ty: types.ExecOk, KV: kv, Logs: logs}, nil return &types.Receipt{Ty: types.ExecOk, KV: kv, Logs: logs}, nil
...@@ -677,6 +726,8 @@ func (action *Action) checkDraw(lott *LotteryDB) (*types.Receipt, *pty.LotteryUp ...@@ -677,6 +726,8 @@ func (action *Action) checkDraw(lott *LotteryDB) (*types.Receipt, *pty.LotteryUp
lott.Status = pty.LotteryDrawed lott.Status = pty.LotteryDrawed
lott.TotalPurchasedTxNum = 0 lott.TotalPurchasedTxNum = 0
lott.LuckyNumber = luckynum lott.LuckyNumber = luckynum
lott.TotalAddrNum = 0
lott.BuyAmount = 0
action.recordMissing(lott) action.recordMissing(lott)
if types.IsPara() { if types.IsPara() {
......
...@@ -55,7 +55,8 @@ func (l *Lottery) Query_GetLotteryCurrentInfo(param *pty.ReqLotteryInfo) (types. ...@@ -55,7 +55,8 @@ func (l *Lottery) Query_GetLotteryCurrentInfo(param *pty.ReqLotteryInfo) (types.
PurBlockNum: lottery.PurBlockNum, PurBlockNum: lottery.PurBlockNum,
DrawBlockNum: lottery.DrawBlockNum, DrawBlockNum: lottery.DrawBlockNum,
MissingRecords: lottery.MissingRecords, MissingRecords: lottery.MissingRecords,
} TotalAddrNum: lottery.TotalAddrNum,
BuyAmount: lottery.BuyAmount}
return reply, nil return reply, nil
} }
......
...@@ -37,6 +37,8 @@ message Lottery { ...@@ -37,6 +37,8 @@ message Lottery {
int64 opRewardRatio = 18; int64 opRewardRatio = 18;
int64 devRewardRatio = 19; int64 devRewardRatio = 19;
repeated PurchaseRecords purRecords = 20; repeated PurchaseRecords purRecords = 20;
int64 totalAddrNum = 21;
int64 buyAmount = 22;
} }
message MissingRecord { message MissingRecord {
...@@ -76,19 +78,21 @@ message LotteryClose { ...@@ -76,19 +78,21 @@ message LotteryClose {
} }
message ReceiptLottery { message ReceiptLottery {
string lotteryId = 1; string lotteryId = 1;
int32 status = 2; int32 status = 2;
int32 prevStatus = 3; int32 prevStatus = 3;
string addr = 4; string addr = 4;
int64 round = 5; int64 round = 5;
int64 number = 6; int64 number = 6;
int64 amount = 7; int64 amount = 7;
int64 luckyNumber = 8; int64 luckyNumber = 8;
int64 time = 9; int64 time = 9;
string txHash = 10; string txHash = 10;
LotteryUpdateBuyInfo updateInfo = 11; LotteryUpdateBuyInfo updateInfo = 11;
int64 way = 12; int64 way = 12;
int64 index = 13; int64 index = 13;
int64 totalAddrNum = 14;
int64 buyAmount = 15;
} }
message ReqLotteryInfo { message ReqLotteryInfo {
...@@ -144,6 +148,8 @@ message ReplyLotteryCurrentInfo { ...@@ -144,6 +148,8 @@ message ReplyLotteryCurrentInfo {
int64 purBlockNum = 10; int64 purBlockNum = 10;
int64 drawBlockNum = 11; int64 drawBlockNum = 11;
repeated MissingRecord missingRecords = 12; repeated MissingRecord missingRecords = 12;
int64 totalAddrNum = 13;
int64 buyAmount = 14;
} }
message ReplyLotteryHistoryLuckyNumber { message ReplyLotteryHistoryLuckyNumber {
...@@ -176,10 +182,12 @@ message LotteryBuyRecords { ...@@ -176,10 +182,12 @@ message LotteryBuyRecords {
} }
message LotteryDrawRecord { message LotteryDrawRecord {
int64 number = 1; int64 number = 1;
int64 round = 2; int64 round = 2;
int64 time = 3; int64 time = 3;
string txHash = 4; string txHash = 4;
int64 totalAddrNum = 5;
int64 buyAmount = 6;
} }
message LotteryDrawRecords { message LotteryDrawRecords {
......
This diff is collapsed.
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