Commit d61ed2a0 authored by szh's avatar szh

update

parent 34b561cd
...@@ -6,26 +6,26 @@ import ( ...@@ -6,26 +6,26 @@ import (
type RaspMinerTxs struct { type RaspMinerTxs struct {
//Model //Model
Miner string `json:"miner";gorm:"INDEX"` Miner string `json:"miner";gorm:"INDEX"`
ReturnAddr string `json:"return_addr"` ReturnAddr string `json:"return_addr"`
Amount int64 `json:"amount"` Amount int64 `json:"amount"`
Height int64 `json:"height"` Height int64 `json:"height"`
Hash string `json:"hash"` Hash string `json:"hash"`
Time int64 `json:"time"` Time int64 `json:"time"`
} }
type ReqTicketInfo struct { type ReqTicketInfo struct {
Addr string `json:"addr" binding:"required"` Addr string `json:"addr" binding:"required"`
Page int32 `json:"page"` Page int32 `json:"page"`
Pagesize int32 `json:"pagesize"` Pagesize int32 `json:"pagesize"`
Detail bool `json:"detail"` Detail bool `json:"detail"`
Order string `json:"order"` Order string `json:"order"`
} }
// ExistByAddr checks if an addr exists based on addr // ExistByAddr checks if an addr exists based on addr
func ExistByAddrHeight(addr string,height int64) (bool, error) { func ExistByAddrHeight(addr string, height int64) (bool, error) {
var txs RaspMinerTxs var txs RaspMinerTxs
err := db.Select("miner").Where("miner = ? and height = ?", addr,height).First(&txs).Error err := db.Select("miner").Where("miner = ? and height = ?", addr, height).First(&txs).Error
if err != nil && err != gorm.ErrRecordNotFound { if err != nil && err != gorm.ErrRecordNotFound {
return false, err return false, err
} }
...@@ -40,7 +40,7 @@ func ExistByAddrHeight(addr string,height int64) (bool, error) { ...@@ -40,7 +40,7 @@ func ExistByAddrHeight(addr string,height int64) (bool, error) {
// GetAddrTotal gets the total number of addr based on the constraints // GetAddrTotal gets the total number of addr based on the constraints
func GetMinerTxsTotal(addr string) (int64, error) { func GetMinerTxsTotal(addr string) (int64, error) {
var count int64 var count int64
if err := db.Model(&RaspMinerTxs{}).Where("return_addr = ? ",addr).Count(&count).Error; err != nil { if err := db.Model(&RaspMinerTxs{}).Where("return_addr = ? ", addr).Count(&count).Error; err != nil {
return 0, err return 0, err
} }
...@@ -53,8 +53,8 @@ func GetMinerTxs(req *ReqTicketInfo) ([]*RaspMinerTxs, error) { ...@@ -53,8 +53,8 @@ func GetMinerTxs(req *ReqTicketInfo) ([]*RaspMinerTxs, error) {
if req.Order == "" { if req.Order == "" {
req.Order = "desc" req.Order = "desc"
} }
maps := map[string]interface{}{"return_addr":req.Addr} maps := map[string]interface{}{"return_addr": req.Addr}
err := db.Where(maps).Order("time "+req.Order).Offset((req.Page-1)*req.Pagesize).Limit(req.Pagesize).Find(&txs).Error err := db.Where(maps).Order("height " + req.Order).Offset((req.Page - 1) * req.Pagesize).Limit(req.Pagesize).Find(&txs).Error
if err != nil && err != gorm.ErrRecordNotFound { if err != nil && err != gorm.ErrRecordNotFound {
return nil, err return nil, err
} }
...@@ -65,12 +65,12 @@ func GetMinerTxs(req *ReqTicketInfo) ([]*RaspMinerTxs, error) { ...@@ -65,12 +65,12 @@ func GetMinerTxs(req *ReqTicketInfo) ([]*RaspMinerTxs, error) {
// AddAddr add a single addr // AddAddr add a single addr
func AddMinerTxs(data map[string]interface{}) error { func AddMinerTxs(data map[string]interface{}) error {
tx := RaspMinerTxs{ tx := RaspMinerTxs{
Miner: data["addr"].(string), Miner: data["addr"].(string),
ReturnAddr: data["return_addr"].(string), ReturnAddr: data["return_addr"].(string),
Amount: data["amount"].(int64), Amount: data["amount"].(int64),
Height: data["height"].(int64), Height: data["height"].(int64),
Hash:data["hash"].(string), Hash: data["hash"].(string),
Time: data["time"].(int64), Time: data["time"].(int64),
} }
if err := db.Create(&tx).Error; err != nil { if err := db.Create(&tx).Error; err != nil {
return err return err
...@@ -78,4 +78,3 @@ func AddMinerTxs(data map[string]interface{}) error { ...@@ -78,4 +78,3 @@ func AddMinerTxs(data map[string]interface{}) error {
return nil return nil
} }
...@@ -185,14 +185,14 @@ func (p *Pai) GetTicketInfo(req *models.ReqTicketInfo) (*MinedInfo, error) { ...@@ -185,14 +185,14 @@ func (p *Pai) GetTicketInfo(req *models.ReqTicketInfo) (*MinedInfo, error) {
for _, v := range txs { for _, v := range txs {
var t MinedTxInfo var t MinedTxInfo
t.Height = v.Height t.Height = v.Height
t.Amount = v.Amount t.Amount = v.Amount / 1e8
t.BlockTime = v.Time t.BlockTime = v.Time
t.Hash = v.Hash t.Hash = v.Hash
txsList = append(txsList, &t) txsList = append(txsList, &t)
} }
// info.MinedTotal = count // info.MinedTotal = count
} }
info.MinedAmount = stat.MinedAmount info.MinedAmount = stat.MinedAmount / 1e8
info.MinedTicketCount = stat.MinedTicketCount info.MinedTicketCount = stat.MinedTicketCount
info.MiningTicketCount = stat.MiningTicketCount info.MiningTicketCount = stat.MiningTicketCount
info.MinerStartTime = stat.MinerStartTime info.MinerStartTime = stat.MinerStartTime
......
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