Skip to content

Commit

Permalink
query v53
Browse files Browse the repository at this point in the history
  • Loading branch information
buck54321 committed May 10, 2021
1 parent eef4010 commit 200e5f5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
4 changes: 2 additions & 2 deletions db/dcrpg/internal/treasury.go
Expand Up @@ -57,9 +57,9 @@ const (
SelectTreasuryBalance = `SELECT
tx_type,
COUNT(CASE WHEN block_height <= $1 THEN 1 END),
COUNT(CASE WHEN block_height > $1 THEN 1 END),
COUNT(1),
SUM(CASE WHEN block_height <= $1 THEN value ELSE 0 END),
SUM(CASE WHEN block_height > $1 THEN value ELSE 0 END)
SUM(value)
FROM treasury
WHERE is_mainchain
GROUP BY tx_type;`
Expand Down
23 changes: 13 additions & 10 deletions db/dcrpg/pgblockchain.go
Expand Up @@ -1819,24 +1819,27 @@ func (pgb *ChainDB) TreasuryBalance() (_ *dbtypes.TreasuryBalance, err error) {
defer rows.Close()

for rows.Next() {
var txType, matureCount, imCount, matureValue, imValue sql.NullInt64
if err = rows.Scan(&txType, &matureCount, &imCount, &matureValue, &imValue); err != nil {
var txType, matureCount, allCount, matureValue, allValue sql.NullInt64
if err = rows.Scan(&txType, &matureCount, &allCount, &matureValue, &allValue); err != nil {
return
}

imCount := allCount.Int64 - matureCount.Int64
imValue := allValue.Int64 - matureValue.Int64

switch stake.TxType(txType.Int64) {
case stake.TxTypeTSpend:
spendCount = matureCount.Int64 + imCount.Int64
spent = -matureValue.Int64 - imValue.Int64
spendCount = allCount.Int64
spent = -allCount.Int64
case stake.TxTypeTAdd:
immatureCount += imCount.Int64
immature += imValue.Int64
addCount = matureCount.Int64 + imCount.Int64
immatureCount += imCount
immature += imValue
addCount = allCount.Int64
added = matureValue.Int64
case stake.TxTypeTreasuryBase:
immatureCount += imCount.Int64
immature += imValue.Int64
genCount = matureCount.Int64 + imCount.Int64
immatureCount += imCount
immature += imValue
genCount = allCount.Int64
gen = matureValue.Int64
}
}
Expand Down

0 comments on commit 200e5f5

Please sign in to comment.