htlcswitch: convert to use new kvdb abstraction

This commit is contained in:
Olaoluwa Osuntokun
2020-01-09 18:44:27 -08:00
parent 320101d054
commit 4e68914e9d
7 changed files with 61 additions and 58 deletions

View File

@@ -7,8 +7,8 @@ import (
"io"
"sync"
"github.com/coreos/bbolt"
"github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/channeldb/kvdb"
"github.com/lightningnetwork/lnd/lnwire"
"github.com/lightningnetwork/lnd/multimutex"
)
@@ -137,8 +137,8 @@ func (store *networkResultStore) storeResult(paymentID uint64,
var paymentIDBytes [8]byte
binary.BigEndian.PutUint64(paymentIDBytes[:], paymentID)
err := store.db.Batch(func(tx *bbolt.Tx) error {
networkResults, err := tx.CreateBucketIfNotExists(
err := kvdb.Batch(store.db.Backend, func(tx kvdb.RwTx) error {
networkResults, err := tx.CreateTopLevelBucket(
networkResultStoreBucketKey,
)
if err != nil {
@@ -180,7 +180,7 @@ func (store *networkResultStore) subscribeResult(paymentID uint64) (
resultChan = make(chan *networkResult, 1)
)
err := store.db.View(func(tx *bbolt.Tx) error {
err := kvdb.View(store.db, func(tx kvdb.ReadTx) error {
var err error
result, err = fetchResult(tx, paymentID)
switch {
@@ -226,7 +226,7 @@ func (store *networkResultStore) getResult(pid uint64) (
*networkResult, error) {
var result *networkResult
err := store.db.View(func(tx *bbolt.Tx) error {
err := kvdb.View(store.db, func(tx kvdb.ReadTx) error {
var err error
result, err = fetchResult(tx, pid)
return err
@@ -238,11 +238,11 @@ func (store *networkResultStore) getResult(pid uint64) (
return result, nil
}
func fetchResult(tx *bbolt.Tx, pid uint64) (*networkResult, error) {
func fetchResult(tx kvdb.ReadTx, pid uint64) (*networkResult, error) {
var paymentIDBytes [8]byte
binary.BigEndian.PutUint64(paymentIDBytes[:], pid)
networkResults := tx.Bucket(networkResultStoreBucketKey)
networkResults := tx.ReadBucket(networkResultStoreBucketKey)
if networkResults == nil {
return nil, ErrPaymentIDNotFound
}