mirror of
https://github.com/lightninglabs/loop.git
synced 2026-08-19 13:17:50 +02:00
multi: always supply chain params when decoding addresses
This commit is contained in:
parent
ec40647147
commit
9a1b60b4be
8 changed files with 35 additions and 22 deletions
|
|
@ -7,6 +7,7 @@ import (
|
|||
"io"
|
||||
"time"
|
||||
|
||||
"github.com/btcsuite/btcd/chaincfg"
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
"github.com/btcsuite/btcutil"
|
||||
"github.com/lightningnetwork/lnd/lntypes"
|
||||
|
|
@ -139,7 +140,9 @@ func (s *LoopOut) LastUpdateTime() time.Time {
|
|||
return lastUpdate.Time
|
||||
}
|
||||
|
||||
func deserializeLoopOutContract(value []byte) (*LoopOutContract, error) {
|
||||
func deserializeLoopOutContract(value []byte, chainParams *chaincfg.Params) (
|
||||
*LoopOutContract, error) {
|
||||
|
||||
r := bytes.NewReader(value)
|
||||
|
||||
contract, err := deserializeContract(r)
|
||||
|
|
@ -155,7 +158,7 @@ func deserializeLoopOutContract(value []byte) (*LoopOutContract, error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
swap.DestAddr, err = btcutil.DecodeAddress(addr, nil)
|
||||
swap.DestAddr, err = btcutil.DecodeAddress(addr, chainParams)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import (
|
|||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/btcsuite/btcd/chaincfg"
|
||||
"github.com/coreos/bbolt"
|
||||
"github.com/lightningnetwork/lnd/lntypes"
|
||||
)
|
||||
|
|
@ -60,7 +61,8 @@ func fileExists(path string) bool {
|
|||
|
||||
// boltSwapStore stores swap data in boltdb.
|
||||
type boltSwapStore struct {
|
||||
db *bbolt.DB
|
||||
db *bbolt.DB
|
||||
chainParams *chaincfg.Params
|
||||
}
|
||||
|
||||
// A compile-time flag to ensure that boltSwapStore implements the SwapStore
|
||||
|
|
@ -68,7 +70,9 @@ type boltSwapStore struct {
|
|||
var _ = (*boltSwapStore)(nil)
|
||||
|
||||
// NewBoltSwapStore creates a new client swap store.
|
||||
func NewBoltSwapStore(dbPath string) (*boltSwapStore, error) {
|
||||
func NewBoltSwapStore(dbPath string, chainParams *chaincfg.Params) (
|
||||
*boltSwapStore, error) {
|
||||
|
||||
// If the target path for the swap store doesn't exist, then we'll
|
||||
// create it now before we proceed.
|
||||
if !fileExists(dbPath) {
|
||||
|
|
@ -114,7 +118,8 @@ func NewBoltSwapStore(dbPath string) (*boltSwapStore, error) {
|
|||
}
|
||||
|
||||
return &boltSwapStore{
|
||||
db: bdb,
|
||||
db: bdb,
|
||||
chainParams: chainParams,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
|
@ -155,7 +160,7 @@ func (s *boltSwapStore) FetchLoopOutSwaps() ([]*LoopOut, error) {
|
|||
return errors.New("contract not found")
|
||||
}
|
||||
contract, err := deserializeLoopOutContract(
|
||||
contractBytes,
|
||||
contractBytes, s.chainParams,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/btcsuite/btcd/chaincfg"
|
||||
"github.com/lightninglabs/loop/test"
|
||||
"github.com/lightningnetwork/lnd/lntypes"
|
||||
)
|
||||
|
|
@ -42,7 +43,7 @@ func TestBoltSwapStore(t *testing.T) {
|
|||
}
|
||||
defer os.RemoveAll(tempDirName)
|
||||
|
||||
store, err := NewBoltSwapStore(tempDirName)
|
||||
store, err := NewBoltSwapStore(tempDirName, &chaincfg.MainNetParams)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
@ -150,7 +151,7 @@ func TestBoltSwapStore(t *testing.T) {
|
|||
|
||||
// If we re-open the same store, then the state of the current swap
|
||||
// should be the same.
|
||||
store, err = NewBoltSwapStore(tempDirName)
|
||||
store, err = NewBoltSwapStore(tempDirName, &chaincfg.MainNetParams)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue