added fromIdx and toIdx to transactionHistory

This commit is contained in:
Mikelle
2021-03-31 12:33:57 +03:00
parent 22ffd93292
commit 8d087e2727
8 changed files with 81 additions and 18 deletions

View File

@@ -456,7 +456,7 @@ func (hdb *HistoryDB) GetTxAPI(txID common.TxID) (*TxAPI, error) {
// and pagination info
func (hdb *HistoryDB) GetTxsAPI(
ethAddr *ethCommon.Address, bjj *babyjub.PublicKeyComp,
tokenID *common.TokenID, idx *common.Idx, batchNum *uint, txType *common.TxType,
tokenID *common.TokenID, fromIdx, toIdx *common.Idx, batchNum *uint, txType *common.TxType,
fromItem, limit *uint, order string,
) ([]TxAPI, uint64, error) {
// Warning: amount_success and deposit_amount_success have true as default for
@@ -508,14 +508,32 @@ func (hdb *HistoryDB) GetTxsAPI(
nextIsAnd = true
}
// idx filter
if idx != nil {
if fromIdx != nil && toIdx != nil {
if nextIsAnd {
queryStr += "AND "
} else {
queryStr += "WHERE "
}
queryStr += "(tx.effective_from_idx = ? OR tx.to_idx = ?) "
args = append(args, idx, idx)
queryStr += "(tx.effective_from_idx = ? "
queryStr += "OR tx.to_idx = ?) "
args = append(args, fromIdx, toIdx)
nextIsAnd = true
} else if fromIdx != nil {
if nextIsAnd {
queryStr += "AND "
} else {
queryStr += "WHERE "
}
queryStr += "tx.effective_from_idx = ? "
nextIsAnd = true
} else if toIdx != nil {
if nextIsAnd {
queryStr += "AND "
} else {
queryStr += "WHERE "
}
queryStr += "tx.to_idx = ? "
args = append(args, toIdx)
nextIsAnd = true
}
// batchNum filter

View File

@@ -154,15 +154,14 @@ func (l2db *L2DB) GetPoolTxs(fromIdx, toIdx *common.Idx, state *common.PoolL2TxS
}
queryStr += "tx_pool.from_idx = ? "
queryStr += "OR tx_pool.to_idx = ?) "
args = append(args, fromIdx)
args = append(args, toIdx)
args = append(args, fromIdx, toIdx)
} else if fromIdx != nil {
if nextIsAnd {
queryStr += "AND "
} else {
queryStr += "WHERE "
}
queryStr += "tx_pool.from_idx = ?"
queryStr += "tx_pool.from_idx = ? "
args = append(args, fromIdx)
} else if toIdx != nil {
if nextIsAnd {
@@ -170,7 +169,7 @@ func (l2db *L2DB) GetPoolTxs(fromIdx, toIdx *common.Idx, state *common.PoolL2TxS
} else {
queryStr += "WHERE "
}
queryStr += "tx_pool.to_idx = ?"
queryStr += "tx_pool.to_idx = ? "
args = append(args, toIdx)
}
queryStr += "AND NOT external_delete;"