Offer API for last payouts from height / timestamp
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
f348588b37
commit
f35fd872a5
|
@ -882,23 +882,38 @@ func main() {
|
|||
|
||||
params := request.URL.Query()
|
||||
|
||||
var limit uint64 = 10
|
||||
var limit, timestamp, height uint64 = 10, 0, 0
|
||||
|
||||
if params.Has("search_limit") {
|
||||
if i, err := strconv.Atoi(params.Get("search_limit")); err == nil {
|
||||
limit = uint64(i)
|
||||
}
|
||||
}
|
||||
|
||||
if params.Has("limit") {
|
||||
if i, err := strconv.Atoi(params.Get("limit")); err == nil {
|
||||
limit = uint64(i)
|
||||
}
|
||||
}
|
||||
if params.Has("from_timestamp") {
|
||||
if i, err := strconv.Atoi(params.Get("from_timestamp")); err == nil {
|
||||
timestamp = uint64(i)
|
||||
}
|
||||
}
|
||||
if params.Has("from_height") {
|
||||
if i, err := strconv.Atoi(params.Get("from_height")); err == nil {
|
||||
height = uint64(i)
|
||||
}
|
||||
}
|
||||
|
||||
writer.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
writer.WriteHeader(http.StatusOK)
|
||||
_ = cmdutils.StreamJsonSlice(request, writer, indexDb.GetPayoutsByMinerId(miner.Id(), limit))
|
||||
if timestamp > 0 {
|
||||
_ = cmdutils.StreamJsonSlice(request, writer, indexDb.GetPayoutsByMinerIdFromTimestamp(miner.Id(), timestamp))
|
||||
} else if height > 0 {
|
||||
_ = cmdutils.StreamJsonSlice(request, writer, indexDb.GetPayoutsByMinerIdFromHeight(miner.Id(), height))
|
||||
} else {
|
||||
_ = cmdutils.StreamJsonSlice(request, writer, indexDb.GetPayoutsByMinerId(miner.Id(), limit))
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
|
|
|
@ -845,13 +845,55 @@ func main() {
|
|||
var lastFound []*index.FoundBlock
|
||||
var payouts []*index.Payout
|
||||
var sweeps []*index.MainLikelySweepTransaction
|
||||
|
||||
var raw *sidechain.PoolBlock
|
||||
|
||||
if miner.Id != 0 {
|
||||
shares = getSideBlocksFromAPI(fmt.Sprintf("side_blocks_in_window/%d?from=%d&window=%d&noMiner&noMainStatus&noUncles", miner.Id, tipHeight, wsize))
|
||||
payouts = getSliceFromAPI[*index.Payout](fmt.Sprintf("payouts/%d?search_limit=1000", miner.Id))
|
||||
lastShares = getSideBlocksFromAPI(fmt.Sprintf("side_blocks?limit=50&miner=%d", miner.Id))
|
||||
lastOrphanedShares = getSideBlocksFromAPI(fmt.Sprintf("side_blocks?limit=10&miner=%d&inclusion=%d", miner.Id, index.InclusionOrphan))
|
||||
lastFound = getSliceFromAPI[*index.FoundBlock](fmt.Sprintf("found_blocks?limit=10&miner=%d", miner.Id))
|
||||
sweeps = getSliceFromAPI[*index.MainLikelySweepTransaction](fmt.Sprintf("sweeps/%d?limit=5", miner.Id))
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
shares = getSideBlocksFromAPI(fmt.Sprintf("side_blocks_in_window/%d?from=%d&window=%d&noMiner&noMainStatus&noUncles", miner.Id, tipHeight, wsize))
|
||||
}()
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
lastShares = getSideBlocksFromAPI(fmt.Sprintf("side_blocks?limit=50&miner=%d", miner.Id))
|
||||
|
||||
if len(lastShares) > 0 {
|
||||
raw = getTypeFromAPI[sidechain.PoolBlock](fmt.Sprintf("block_by_id/%s/light", lastShares[0].MainId))
|
||||
if raw == nil || raw.ShareVersion() == sidechain.ShareVersion_None {
|
||||
raw = nil
|
||||
}
|
||||
}
|
||||
}()
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
lastOrphanedShares = getSideBlocksFromAPI(fmt.Sprintf("side_blocks?limit=10&miner=%d&inclusion=%d", miner.Id, index.InclusionOrphan))
|
||||
}()
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
lastFound = getSliceFromAPI[*index.FoundBlock](fmt.Sprintf("found_blocks?limit=10&miner=%d", miner.Id))
|
||||
}()
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
sweeps = getSliceFromAPI[*index.MainLikelySweepTransaction](fmt.Sprintf("sweeps/%d?limit=5", miner.Id))
|
||||
}()
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
shares = getSideBlocksFromAPI(fmt.Sprintf("side_blocks_in_window/%d?from=%d&window=%d&noMiner&noMainStatus&noUncles", miner.Id, tipHeight, wsize))
|
||||
}()
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
//get a bit over the expected required
|
||||
payouts = getSliceFromAPI[*index.Payout](fmt.Sprintf("payouts/%d?from_timestamp=%d", miner.Id, uint64(time.Now().Unix())-(consensus.ChainWindowSize*consensus.TargetBlockTime*(totalWindows+1))))
|
||||
}()
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
sharesFound := cmdutils.NewPositionChart(30*totalWindows, consensus.ChainWindowSize*totalWindows)
|
||||
|
@ -867,15 +909,6 @@ func main() {
|
|||
foundPayout.Add(int(int64(tipHeight)-int64(p.SideHeight)), 1)
|
||||
}
|
||||
|
||||
var raw *sidechain.PoolBlock
|
||||
|
||||
if len(lastShares) > 0 {
|
||||
raw = getTypeFromAPI[sidechain.PoolBlock](fmt.Sprintf("block_by_id/%s/light", lastShares[0].MainId))
|
||||
if raw == nil || raw.ShareVersion() == sidechain.ShareVersion_None {
|
||||
raw = nil
|
||||
}
|
||||
}
|
||||
|
||||
for _, share := range shares {
|
||||
if share.IsUncle() {
|
||||
|
||||
|
|
|
@ -793,6 +793,52 @@ func (i *Index) GetPayoutsByMinerId(minerId uint64, limit uint64) chan *Payout {
|
|||
return out
|
||||
}
|
||||
|
||||
func (i *Index) GetPayoutsByMinerIdFromHeight(minerId uint64, height uint64) chan *Payout {
|
||||
out := make(chan *Payout, 1)
|
||||
|
||||
go func() {
|
||||
defer close(out)
|
||||
|
||||
resultFunc := func(row RowScanInterface) error {
|
||||
p := &Payout{}
|
||||
if err := p.ScanFromRow(i, row); err != nil {
|
||||
return err
|
||||
}
|
||||
out <- p
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := i.Query("SELECT * FROM "+i.views["payouts"]+" WHERE miner = $1 AND main_height >= $2 ORDER BY main_height DESC;", resultFunc, minerId, height); err != nil {
|
||||
return
|
||||
}
|
||||
}()
|
||||
|
||||
return out
|
||||
}
|
||||
|
||||
func (i *Index) GetPayoutsByMinerIdFromTimestamp(minerId uint64, timestamp uint64) chan *Payout {
|
||||
out := make(chan *Payout, 1)
|
||||
|
||||
go func() {
|
||||
defer close(out)
|
||||
|
||||
resultFunc := func(row RowScanInterface) error {
|
||||
p := &Payout{}
|
||||
if err := p.ScanFromRow(i, row); err != nil {
|
||||
return err
|
||||
}
|
||||
out <- p
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := i.Query("SELECT * FROM "+i.views["payouts"]+" WHERE miner = $1 AND timestamp >= $2 ORDER BY main_height DESC;", resultFunc, minerId, timestamp); err != nil {
|
||||
return
|
||||
}
|
||||
}()
|
||||
|
||||
return out
|
||||
}
|
||||
|
||||
func (i *Index) GetPayoutsBySideBlock(b *SideBlock) chan *Payout {
|
||||
out := make(chan *Payout, 1)
|
||||
|
||||
|
|
Loading…
Reference in a new issue