mirror of
https://github.com/arnaucube/hermez-node.git
synced 2026-02-07 03:16:45 +01:00
Replace all []*Foo by []Foo in sql db return values
- Implement SlicePtrsToSlice and use it in all `meddler.QueryAll` sql db functions to always return []Foo instead of []*Foo
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
|
||||
ethCommon "github.com/ethereum/go-ethereum/common"
|
||||
"github.com/hermeznetwork/hermez-node/common"
|
||||
"github.com/hermeznetwork/hermez-node/db"
|
||||
"github.com/hermeznetwork/hermez-node/log"
|
||||
"github.com/iden3/go-iden3-crypto/babyjub"
|
||||
"github.com/jmoiron/sqlx"
|
||||
@@ -134,14 +135,14 @@ func (l2db *L2DB) GetTx(txID common.TxID) (*common.PoolL2Tx, error) {
|
||||
}
|
||||
|
||||
// GetPendingTxs return all the pending txs of the L2DB, that have a non NULL AbsoluteFee
|
||||
func (l2db *L2DB) GetPendingTxs() ([]*common.PoolL2Tx, error) {
|
||||
func (l2db *L2DB) GetPendingTxs() ([]common.PoolL2Tx, error) {
|
||||
var txs []*common.PoolL2Tx
|
||||
err := meddler.QueryAll(
|
||||
l2db.db, &txs,
|
||||
selectPoolTx+"WHERE state = $1 AND token.usd IS NOT NULL",
|
||||
common.PoolL2TxStatePending,
|
||||
)
|
||||
return txs, err
|
||||
return db.SlicePtrsToSlice(txs).([]common.PoolL2Tx), err
|
||||
}
|
||||
|
||||
// StartForging updates the state of the transactions that will begin the forging process.
|
||||
|
||||
@@ -111,8 +111,8 @@ func TestGetPending(t *testing.T) {
|
||||
fetchedTxs, err := l2DB.GetPendingTxs()
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, len(pendingTxs), len(fetchedTxs))
|
||||
for i, fetchedTx := range fetchedTxs {
|
||||
assertTx(t, pendingTxs[i], fetchedTx)
|
||||
for i := range fetchedTxs {
|
||||
assertTx(t, pendingTxs[i], &fetchedTxs[i])
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user