mirror of
https://github.com/arnaucube/hermez-node.git
synced 2026-02-07 11:26:44 +01:00
implemented get pool txs endpoint
This commit is contained in:
@@ -127,3 +127,41 @@ func (l2db *L2DB) GetTxAPI(txID common.TxID) (*PoolTxAPI, error) {
|
||||
txID,
|
||||
))
|
||||
}
|
||||
|
||||
func (l2db *L2DB) GetPoolTxs(idx *common.Idx, state *common.PoolL2TxState) ([]*PoolTxAPI, error) {
|
||||
cancel, err := l2db.apiConnCon.Acquire()
|
||||
defer cancel()
|
||||
if err != nil {
|
||||
return nil, tracerr.Wrap(err)
|
||||
}
|
||||
defer l2db.apiConnCon.Release()
|
||||
// Apply filters
|
||||
nextIsAnd := false
|
||||
queryStr := selectPoolTxAPI
|
||||
var args []interface{}
|
||||
if state != nil {
|
||||
queryStr += "WHERE state = ? "
|
||||
args = append(args, state)
|
||||
nextIsAnd = true
|
||||
}
|
||||
if idx != nil {
|
||||
if nextIsAnd {
|
||||
queryStr += "AND ("
|
||||
} else {
|
||||
queryStr += "WHERE ("
|
||||
}
|
||||
queryStr += "tx_pool.from_idx = ? "
|
||||
queryStr += "OR tx_pool.to_idx = ?) "
|
||||
args = append(args, idx)
|
||||
args = append(args, idx)
|
||||
nextIsAnd = true
|
||||
}
|
||||
queryStr += "AND NOT external_delete;"
|
||||
query := l2db.dbRead.Rebind(queryStr)
|
||||
txs := []*PoolTxAPI{}
|
||||
err = meddler.QueryAll(
|
||||
l2db.dbRead, &txs,
|
||||
query,
|
||||
args...)
|
||||
return txs, tracerr.Wrap(err)
|
||||
}
|
||||
|
||||
@@ -311,6 +311,27 @@ func TestGetPending(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestL2DB_GetPoolTxs(t *testing.T) {
|
||||
err := prepareHistoryDB(historyDB)
|
||||
if err != nil {
|
||||
log.Error("Error prepare historyDB", err)
|
||||
}
|
||||
poolL2Txs, err := generatePoolL2Txs()
|
||||
state := common.PoolL2TxState("pend")
|
||||
idx := common.Idx(256)
|
||||
var pendingTxs []*common.PoolL2Tx
|
||||
for i := range poolL2Txs {
|
||||
if poolL2Txs[i].FromIdx == idx || poolL2Txs[i].ToIdx == idx {
|
||||
err := l2DB.AddTxTest(&poolL2Txs[i])
|
||||
require.NoError(t, err)
|
||||
pendingTxs = append(pendingTxs, &poolL2Txs[i])
|
||||
}
|
||||
}
|
||||
fetchedTxs, err := l2DBWithACC.GetPoolTxs(&idx, &state)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, len(pendingTxs), len(fetchedTxs))
|
||||
}
|
||||
|
||||
func TestStartForging(t *testing.T) {
|
||||
// Generate txs
|
||||
var fakeBatchNum common.BatchNum = 33
|
||||
|
||||
Reference in New Issue
Block a user