@ -106,14 +106,14 @@ func (hdb *HistoryDB) GetBlock(blockNum int64) (*common.Block, error) {
}
}
// GetBlocks retrieve blocks from the DB, given a range of block numbers defined by from and to
// GetBlocks retrieve blocks from the DB, given a range of block numbers defined by from and to
func ( hdb * HistoryDB ) GetBlocks ( from , to int64 ) ( [ ] * common . Block , error ) {
func ( hdb * HistoryDB ) GetBlocks ( from , to int64 ) ( [ ] common . Block , error ) {
var blocks [ ] * common . Block
var blocks [ ] * common . Block
err := meddler . QueryAll (
err := meddler . QueryAll (
hdb . db , & blocks ,
hdb . db , & blocks ,
"SELECT * FROM block WHERE $1 <= eth_block_num AND eth_block_num < $2;" ,
"SELECT * FROM block WHERE $1 <= eth_block_num AND eth_block_num < $2;" ,
from , to ,
from , to ,
)
)
return blocks , err
return db . SlicePtrsToSlice ( blocks ) . ( [ ] common . Block ) , err
}
}
// GetLastBlock retrieve the block with the highest block number from the DB
// GetLastBlock retrieve the block with the highest block number from the DB
@ -155,14 +155,14 @@ func (hdb *HistoryDB) addBatches(d meddler.DB, batches []common.Batch) error {
}
}
// GetBatches retrieve batches from the DB, given a range of batch numbers defined by from and to
// GetBatches retrieve batches from the DB, given a range of batch numbers defined by from and to
func ( hdb * HistoryDB ) GetBatches ( from , to common . BatchNum ) ( [ ] * common . Batch , error ) {
func ( hdb * HistoryDB ) GetBatches ( from , to common . BatchNum ) ( [ ] common . Batch , error ) {
var batches [ ] * common . Batch
var batches [ ] * common . Batch
err := meddler . QueryAll (
err := meddler . QueryAll (
hdb . db , & batches ,
hdb . db , & batches ,
"SELECT * FROM batch WHERE $1 <= batch_num AND batch_num < $2;" ,
"SELECT * FROM batch WHERE $1 <= batch_num AND batch_num < $2;" ,
from , to ,
from , to ,
)
)
return batches , err
return db . SlicePtrsToSlice ( batches ) . ( [ ] common . Batch ) , err
}
}
// GetLastBatchNum returns the BatchNum of the latest forged batch
// GetLastBatchNum returns the BatchNum of the latest forged batch
@ -215,13 +215,13 @@ func (hdb *HistoryDB) addBids(d meddler.DB, bids []common.Bid) error {
}
}
// GetBids return the bids
// GetBids return the bids
func ( hdb * HistoryDB ) GetBids ( ) ( [ ] * common . Bid , error ) {
func ( hdb * HistoryDB ) GetBids ( ) ( [ ] common . Bid , error ) {
var bids [ ] * common . Bid
var bids [ ] * common . Bid
err := meddler . QueryAll (
err := meddler . QueryAll (
hdb . db , & bids ,
hdb . db , & bids ,
"SELECT * FROM bid;" ,
"SELECT * FROM bid;" ,
)
)
return bids , err
return db . SlicePtrsToSlice ( bids ) . ( [ ] common . Bid ) , err
}
}
// AddCoordinators insert Coordinators into the DB
// AddCoordinators insert Coordinators into the DB
@ -283,13 +283,13 @@ func (hdb *HistoryDB) UpdateTokenValue(tokenSymbol string, value float64) error
}
}
// GetTokens returns a list of tokens from the DB
// GetTokens returns a list of tokens from the DB
func ( hdb * HistoryDB ) GetTokens ( ) ( [ ] * common . Token , error ) {
func ( hdb * HistoryDB ) GetTokens ( ) ( [ ] common . Token , error ) {
var tokens [ ] * common . Token
var tokens [ ] * common . Token
err := meddler . QueryAll (
err := meddler . QueryAll (
hdb . db , & tokens ,
hdb . db , & tokens ,
"SELECT * FROM token ORDER BY token_id;" ,
"SELECT * FROM token ORDER BY token_id;" ,
)
)
return tokens , err
return db . SlicePtrsToSlice ( tokens ) . ( [ ] common . Token ) , err
}
}
// GetTokenSymbols returns all the token symbols from the DB
// GetTokenSymbols returns all the token symbols from the DB
@ -329,13 +329,13 @@ func (hdb *HistoryDB) addAccounts(d meddler.DB, accounts []common.Account) error
}
}
// GetAccounts returns a list of accounts from the DB
// GetAccounts returns a list of accounts from the DB
func ( hdb * HistoryDB ) GetAccounts ( ) ( [ ] * common . Account , error ) {
func ( hdb * HistoryDB ) GetAccounts ( ) ( [ ] common . Account , error ) {
var accs [ ] * common . Account
var accs [ ] * common . Account
err := meddler . QueryAll (
err := meddler . QueryAll (
hdb . db , & accs ,
hdb . db , & accs ,
"SELECT * FROM account ORDER BY idx;" ,
"SELECT * FROM account ORDER BY idx;" ,
)
)
return accs , err
return db . SlicePtrsToSlice ( accs ) . ( [ ] common . Account ) , err
}
}
// AddL1Txs inserts L1 txs to the DB. USD and LoadAmountUSD will be set automatically before storing the tx.
// AddL1Txs inserts L1 txs to the DB. USD and LoadAmountUSD will be set automatically before storing the tx.
@ -398,14 +398,14 @@ func (hdb *HistoryDB) addTxs(d meddler.DB, txs []common.Tx) error {
}
}
// GetTxs returns a list of txs from the DB
// GetTxs returns a list of txs from the DB
func ( hdb * HistoryDB ) GetTxs ( ) ( [ ] * common . Tx , error ) {
func ( hdb * HistoryDB ) GetTxs ( ) ( [ ] common . Tx , error ) {
var txs [ ] * common . Tx
var txs [ ] * common . Tx
err := meddler . QueryAll (
err := meddler . QueryAll (
hdb . db , & txs ,
hdb . db , & txs ,
` SELECT * FROM tx
` SELECT * FROM tx
ORDER BY ( batch_num , position ) ASC ` ,
ORDER BY ( batch_num , position ) ASC ` ,
)
)
return txs , err
return db . SlicePtrsToSlice ( txs ) . ( [ ] common . Tx ) , err
}
}
// GetHistoryTxs returns a list of txs from the DB using the HistoryTx struct
// GetHistoryTxs returns a list of txs from the DB using the HistoryTx struct
@ -413,7 +413,7 @@ func (hdb *HistoryDB) GetHistoryTxs(
ethAddr * ethCommon . Address , bjj * babyjub . PublicKey ,
ethAddr * ethCommon . Address , bjj * babyjub . PublicKey ,
tokenID , idx , batchNum * uint , txType * common . TxType ,
tokenID , idx , batchNum * uint , txType * common . TxType ,
offset , limit * uint , last bool ,
offset , limit * uint , last bool ,
) ( [ ] * HistoryTx , int , error ) {
) ( [ ] HistoryTx , int , error ) {
if ethAddr != nil && bjj != nil {
if ethAddr != nil && bjj != nil {
return nil , 0 , errors . New ( "ethAddr and bjj are incompatible" )
return nil , 0 , errors . New ( "ethAddr and bjj are incompatible" )
}
}
@ -495,14 +495,15 @@ func (hdb *HistoryDB) GetHistoryTxs(
queryStr += fmt . Sprintf ( "LIMIT %d;" , * limit )
queryStr += fmt . Sprintf ( "LIMIT %d;" , * limit )
query = hdb . db . Rebind ( queryStr )
query = hdb . db . Rebind ( queryStr )
// log.Debug(query)
// log.Debug(query)
txs := [ ] * HistoryTx { }
if err := meddler . QueryAll ( hdb . db , & txs , query , args ... ) ; err != nil {
txsPtrs := [ ] * HistoryTx { }
if err := meddler . QueryAll ( hdb . db , & txsPtrs , query , args ... ) ; err != nil {
return nil , 0 , err
return nil , 0 , err
}
}
txs := db . SlicePtrsToSlice ( txsPtrs ) . ( [ ] HistoryTx )
if len ( txs ) == 0 {
if len ( txs ) == 0 {
return nil , 0 , sql . ErrNoRows
return nil , 0 , sql . ErrNoRows
} else if last {
} else if last {
tmp := [ ] * HistoryTx { }
tmp := [ ] HistoryTx { }
for i := len ( txs ) - 1 ; i >= 0 ; i -- {
for i := len ( txs ) - 1 ; i >= 0 ; i -- {
tmp = append ( tmp , txs [ i ] )
tmp = append ( tmp , txs [ i ] )
}
}