mirror of
https://github.com/lightninglabs/loop.git
synced 2026-08-13 12:33:03 +02:00
loopdb: extract update deserialization
Preparation to prevent code duplication in future refactoring.
This commit is contained in:
parent
ba5577748b
commit
9927139dd3
1 changed files with 30 additions and 19 deletions
|
|
@ -180,25 +180,7 @@ func (s *boltSwapStore) fetchSwaps(bucketKey []byte,
|
|||
return errors.New("contract not found")
|
||||
}
|
||||
|
||||
// Once we have the raw swap, we'll also need to decode
|
||||
// each of the past updates to the swap itself.
|
||||
stateBucket := swapBucket.Bucket(updatesBucketKey)
|
||||
if stateBucket == nil {
|
||||
return errors.New("updates bucket not found")
|
||||
}
|
||||
|
||||
// De serialize and collect each swap update into our
|
||||
// slice of swap events.
|
||||
var updates []*LoopEvent
|
||||
err := stateBucket.ForEach(func(k, v []byte) error {
|
||||
event, err := deserializeLoopEvent(v)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
updates = append(updates, event)
|
||||
return nil
|
||||
})
|
||||
updates, err := deserializeUpdates(swapBucket)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -216,6 +198,35 @@ func (s *boltSwapStore) fetchSwaps(bucketKey []byte,
|
|||
})
|
||||
}
|
||||
|
||||
// deserializeUpdates deserializes the list of swap updates that are stored as a
|
||||
// key of the given bucket.
|
||||
func deserializeUpdates(swapBucket *bbolt.Bucket) ([]*LoopEvent, error) {
|
||||
// Once we have the raw swap, we'll also need to decode
|
||||
// each of the past updates to the swap itself.
|
||||
stateBucket := swapBucket.Bucket(updatesBucketKey)
|
||||
if stateBucket == nil {
|
||||
return nil, errors.New("updates bucket not found")
|
||||
}
|
||||
|
||||
// Deserialize and collect each swap update into our slice of swap
|
||||
// events.
|
||||
var updates []*LoopEvent
|
||||
err := stateBucket.ForEach(func(_, v []byte) error {
|
||||
event, err := deserializeLoopEvent(v)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
updates = append(updates, event)
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return updates, nil
|
||||
}
|
||||
|
||||
// FetchLoopOutSwaps returns all loop out swaps currently in the store.
|
||||
//
|
||||
// NOTE: Part of the loopdb.SwapStore interface.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue