Skip to content

Commit

Permalink
api-server: only return data for enabled chains
Browse files Browse the repository at this point in the history
this commit touches balances, staking balances, account numbers and chains
  • Loading branch information
gsora committed May 21, 2021
1 parent dcfa7bd commit 9295877
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion api/database/balances.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
func (d *Database) Balances(address string) ([]models.BalanceRow, error) {
var balances []models.BalanceRow

q := "SELECT * FROM tracelistener.balances WHERE address=?;"
q := "SELECT * FROM tracelistener.balances WHERE address=? and chain_name in (select chain_name from cns.chains where enabled=true);"

q = d.dbi.DB.Rebind(q)

Expand Down
4 changes: 2 additions & 2 deletions api/database/chains.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "github.com/allinbits/demeris-backend/models"
func (d *Database) Chain(name string) (models.Chain, error) {
var c models.Chain

n, err := d.dbi.DB.PrepareNamed("select * from cns.chains where chain_name=:name limit 1")
n, err := d.dbi.DB.PrepareNamed("select * from cns.chains where chain_name=:name and enabled=TRUE limit 1")
if err != nil {
return models.Chain{}, err
}
Expand All @@ -17,7 +17,7 @@ func (d *Database) Chain(name string) (models.Chain, error) {

func (d *Database) Chains() ([]models.Chain, error) {
var c []models.Chain
return c, d.dbi.Exec("select * from cns.chains", nil, &c)
return c, d.dbi.Exec("select * from cns.chains where enabled=TRUE", nil, &c)
}

func (d *Database) PrimaryChannelCounterparty(chainName, counterparty string) (models.ChannelQuery, error) {
Expand Down
2 changes: 1 addition & 1 deletion api/database/delegations.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
func (d *Database) Delegations(address string) ([]models.DelegationRow, error) {
var delegations []models.DelegationRow

q, args, err := sqlx.In("SELECT * FROM tracelistener.delegations WHERE delegator_address IN (?);", []string{address})
q, args, err := sqlx.In("SELECT * FROM tracelistener.delegations WHERE delegator_address IN (?) and chain_name in (select chain_name from cns.chains where enabled=true);", []string{address})
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion api/database/numbers.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
func (d *Database) Numbers(address string) ([]models.AuthRow, error) {
var numbers []models.AuthRow

q, args, err := sqlx.In("SELECT * FROM tracelistener.auth WHERE address IN (?);", []string{address})
q, args, err := sqlx.In("SELECT * FROM tracelistener.auth WHERE address IN (?) and chain_name in (select chain_name from cns.chains where enabled=true);", []string{address})
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 9295877

Please sign in to comment.