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:
Eduard S
2020-10-07 16:39:48 +02:00
parent 0277210c39
commit b14495cfcc
14 changed files with 124 additions and 54 deletions

View File

@@ -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.

View File

@@ -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])
}
}