Merge pull request #407 from hermeznetwork/fix/api-coordinator

Add bootCoord to coord table, get coord by forgerAddr
This commit is contained in:
Eduard S
2020-12-23 11:10:23 +01:00
committed by GitHub
7 changed files with 80 additions and 78 deletions

View File

@@ -1621,15 +1621,38 @@ func (hdb *HistoryDB) GetCoordinatorAPI(bidderAddr ethCommon.Address) (*Coordina
}
// GetCoordinatorsAPI returns a list of coordinators from the DB and pagination info
func (hdb *HistoryDB) GetCoordinatorsAPI(fromItem, limit *uint, order string) ([]CoordinatorAPI, uint64, error) {
func (hdb *HistoryDB) GetCoordinatorsAPI(
bidderAddr, forgerAddr *ethCommon.Address,
fromItem, limit *uint, order string,
) ([]CoordinatorAPI, uint64, error) {
var query string
var args []interface{}
queryStr := `SELECT coordinator.*,
COUNT(*) OVER() AS total_items
FROM coordinator `
// Apply filters
nextIsAnd := false
if bidderAddr != nil {
queryStr += "WHERE bidder_addr = ? "
nextIsAnd = true
args = append(args, bidderAddr)
}
if forgerAddr != nil {
if nextIsAnd {
queryStr += "AND "
} else {
queryStr += "WHERE "
}
queryStr += "forger_addr = ? "
nextIsAnd = true
args = append(args, forgerAddr)
}
if fromItem != nil {
queryStr += "WHERE "
if nextIsAnd {
queryStr += "AND "
} else {
queryStr += "WHERE "
}
if order == OrderAsc {
queryStr += "coordinator.item_id >= ? "
} else {