mirror of
https://github.com/arnaucube/hermez-node.git
synced 2026-02-07 03:16:45 +01:00
Merge pull request #473 from hermeznetwork/feature/buckets-update
Update buckets withdrawals on API
This commit is contained in:
@@ -1362,6 +1362,12 @@ func (hdb *HistoryDB) addBucketUpdates(d meddler.DB, bucketUpdates []common.Buck
|
||||
))
|
||||
}
|
||||
|
||||
// AddBucketUpdatesTest allows call to unexported method
|
||||
// only for internal testing purposes
|
||||
func (hdb *HistoryDB) AddBucketUpdatesTest(d meddler.DB, bucketUpdates []common.BucketUpdate) error {
|
||||
return hdb.addBucketUpdates(d, bucketUpdates)
|
||||
}
|
||||
|
||||
// GetAllBucketUpdates retrieves all the bucket updates
|
||||
func (hdb *HistoryDB) GetAllBucketUpdates() ([]common.BucketUpdate, error) {
|
||||
var bucketUpdates []*common.BucketUpdate
|
||||
@@ -1373,6 +1379,19 @@ func (hdb *HistoryDB) GetAllBucketUpdates() ([]common.BucketUpdate, error) {
|
||||
return db.SlicePtrsToSlice(bucketUpdates).([]common.BucketUpdate), tracerr.Wrap(err)
|
||||
}
|
||||
|
||||
// GetBucketUpdates retrieves latest values for each bucket
|
||||
func (hdb *HistoryDB) GetBucketUpdates() ([]common.BucketUpdate, error) {
|
||||
var bucketUpdates []*common.BucketUpdate
|
||||
err := meddler.QueryAll(
|
||||
hdb.db, &bucketUpdates,
|
||||
`SELECT num_bucket, withdrawals FROM bucket_update
|
||||
WHERE item_id in(SELECT max(item_id) FROM bucket_update
|
||||
group by num_bucket)
|
||||
ORDER BY num_bucket ASC;`,
|
||||
)
|
||||
return db.SlicePtrsToSlice(bucketUpdates).([]common.BucketUpdate), tracerr.Wrap(err)
|
||||
}
|
||||
|
||||
func (hdb *HistoryDB) addTokenExchanges(d meddler.DB, tokenExchanges []common.TokenExchange) error {
|
||||
if len(tokenExchanges) == 0 {
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user