multi: always supply chain params when decoding addresses

pull/31/head
Joost Jager 5 years ago
parent ec40647147
commit 9a1b60b4be
No known key found for this signature in database
GPG Key ID: A61B9D4C393C59C7

@ -67,7 +67,7 @@ type Client struct {
func NewClient(dbDir string, serverAddress string, insecure bool,
lnd *lndclient.LndServices) (*Client, func(), error) {
store, err := loopdb.NewBoltSwapStore(dbDir)
store, err := loopdb.NewBoltSwapStore(dbDir, lnd.ChainParams)
if err != nil {
return nil, nil, err
}

@ -7,6 +7,7 @@ import (
"errors"
"testing"
"github.com/btcsuite/btcd/chaincfg"
"github.com/btcsuite/btcutil"
"github.com/lightninglabs/loop/lndclient"
"github.com/lightninglabs/loop/loopdb"
@ -15,8 +16,9 @@ import (
)
var (
testAddr, _ = btcutil.DecodeAddress(
"rbsHiPKwAgxeo1EQYiyzJTkA8XEmWSVAKx", nil)
testAddr, _ = btcutil.NewAddressScriptHash(
[]byte{123}, &chaincfg.TestNet3Params,
)
testRequest = &OutRequest{
Amount: btcutil.Amount(50000),

@ -44,7 +44,9 @@ func (s *swapClientServer) LoopOut(ctx context.Context,
}
} else {
var err error
sweepAddr, err = btcutil.DecodeAddress(in.Dest, nil)
sweepAddr, err = btcutil.DecodeAddress(
in.Dest, s.lnd.ChainParams,
)
if err != nil {
return nil, fmt.Errorf("decode address: %v", err)
}

@ -3,14 +3,13 @@ module github.com/lightninglabs/loop
require (
github.com/btcsuite/btcd v0.0.0-20190315201642-aa6e0f35703c
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f
github.com/btcsuite/btcutil v0.0.0-20190207003914-4c204d697803
github.com/btcsuite/btcutil v0.0.0-20190316010144-3ac1210f4b38
github.com/coreos/bbolt v1.3.2
github.com/fortytw2/leaktest v1.3.0
github.com/golang/protobuf v1.3.1
github.com/grpc-ecosystem/grpc-gateway v1.8.5
github.com/jessevdk/go-flags v1.4.0
github.com/lightninglabs/neutrino v0.0.0-20190314214430-643615b8c132 // indirect
github.com/lightningnetwork/lnd v0.0.0-20190314214430-b4a1024ac74fc576c65c8074288a5ffaf6bd1ec4
github.com/lightningnetwork/lnd v0.5.1-beta.0.20190322220528-6ad8be25e1aa
github.com/lightningnetwork/lnd/queue v1.0.1
github.com/urfave/cli v1.20.0
golang.org/x/net v0.0.0-20190313220215-9f648a60d977

@ -23,10 +23,12 @@ github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f/go.mod h1:TdznJufo
github.com/btcsuite/btcutil v0.0.0-20180706230648-ab6388e0c60a/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg=
github.com/btcsuite/btcutil v0.0.0-20190207003914-4c204d697803 h1:j3AgPKKZtZStM2nyhrDSLSYgT7YHrZKdSkq1OYeLjvM=
github.com/btcsuite/btcutil v0.0.0-20190207003914-4c204d697803/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg=
github.com/btcsuite/btcutil v0.0.0-20190316010144-3ac1210f4b38 h1:GbQHMJ2u/geMPV1tbN7i7zARSoPAPuXWa44V0KYvJXU=
github.com/btcsuite/btcutil v0.0.0-20190316010144-3ac1210f4b38/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg=
github.com/btcsuite/btcwallet v0.0.0-20180904010540-284e2e0e696e33d5be388f7f3d9a26db703e0c06/go.mod h1:/d7QHZsfUAruXuBhyPITqoYOmJ+nq35qPsJjz/aSpCg=
github.com/btcsuite/btcwallet v0.0.0-20190313032608-acf3b04b0273/go.mod h1:mkOYY8/psBiL5E+Wb0V7M0o+N7NXi2SZJz6+RKkncIc=
github.com/btcsuite/btcwallet v0.0.0-20190313041134-68fc7c82e131 h1:BhBlN90EcFIWGSduKOGckSwBQC1kBeavQ16DqzFj+gw=
github.com/btcsuite/btcwallet v0.0.0-20190313041134-68fc7c82e131/go.mod h1:qMi4jGpAO6YRsd81RYDG7o5pBIGqN9faCioJdagLu64=
github.com/btcsuite/btcwallet v0.0.0-20190319010515-89ab2044f962 h1:/6EtNbubaGgo10bFyYyE6S6yXfxtc3dxKpvLHxMt5rg=
github.com/btcsuite/btcwallet v0.0.0-20190319010515-89ab2044f962/go.mod h1:qMi4jGpAO6YRsd81RYDG7o5pBIGqN9faCioJdagLu64=
github.com/btcsuite/fastsha256 v0.0.0-20160815193821-637e65642941 h1:kij1x2aL7VE6gtx8KMIt8PGPgI5GV9LgtHFG5KaEMPY=
github.com/btcsuite/fastsha256 v0.0.0-20160815193821-637e65642941/go.mod h1:QcFA8DZHtuIAdYKCq/BzELOaznRsCvwf4zTPmaYwaig=
github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd h1:R/opQEbFEy9JGkIguV40SvRY1uliPX8ifOvi6ICsFCw=
@ -112,13 +114,12 @@ github.com/lightninglabs/gozmq v0.0.0-20180324010646-462a8a753885/go.mod h1:KUh1
github.com/lightninglabs/neutrino v0.0.0-20181017011010-4d6069299130/go.mod h1:KJq43Fu9ceitbJsSXMILcT4mGDNI/crKmPIkDOZXFyM=
github.com/lightninglabs/neutrino v0.0.0-20190213031021-ae4583a89cfb/go.mod h1:g6cMQd+hfAU8pQTJAdjm6/EQREhupyd22f+CL0qYFOE=
github.com/lightninglabs/neutrino v0.0.0-20190313035638-e1ad4c33fb18/go.mod h1:v6tz6jbuAubTrRpX8ke2KH9sJxml8KlPQTKgo9mAp1Q=
github.com/lightninglabs/neutrino v0.0.0-20190313220016-a6cc2a8361d5/go.mod h1:NXpKUhcszEdn7v7ze5vsnSHI1KX6HqFdNRu0eqhkJzk=
github.com/lightninglabs/neutrino v0.0.0-20190314214430-643615b8c132 h1:yaKXc3D/qeEy2wv+bIQwmrq+kThdbWg0p2ggea3RAsg=
github.com/lightninglabs/neutrino v0.0.0-20190314214430-643615b8c132/go.mod h1:NXpKUhcszEdn7v7ze5vsnSHI1KX6HqFdNRu0eqhkJzk=
github.com/lightninglabs/neutrino v0.0.0-20190321023416-6dac90b98052 h1:YVi5x7xCumfIVtEejy3zBAej+NqY9EONy/fRim2+azQ=
github.com/lightninglabs/neutrino v0.0.0-20190321023416-6dac90b98052/go.mod h1:IcX2/lKnXpLkF4XzefhiJOPn5he2+kZyJE32dxX4F4E=
github.com/lightningnetwork/lightning-onion v0.0.0-20180605012408-ac4d9da8f1d6 h1:ONLGrYJVQdbtP6CE/ff1KNWZtygRGEh12RzonTiCzPs=
github.com/lightningnetwork/lightning-onion v0.0.0-20180605012408-ac4d9da8f1d6/go.mod h1:8EgEt4a/NUOVQd+3kk6n9aZCJ1Ssj96Pb6lCrci+6oc=
github.com/lightningnetwork/lnd v0.0.0-20190314214430-b4a1024ac74fc576c65c8074288a5ffaf6bd1ec4 h1:p0q8uatpsCBEy5ButuHg48Pnd9hEW7taNgg1vAU4TWA=
github.com/lightningnetwork/lnd v0.0.0-20190314214430-b4a1024ac74fc576c65c8074288a5ffaf6bd1ec4/go.mod h1:j+mj4paxWE0RR/nJrMCBPlDHhaxVXwttXizKuhmc6IQ=
github.com/lightningnetwork/lnd v0.5.1-beta.0.20190322220528-6ad8be25e1aa h1:nYDuZ0vMAZ2DVIMmc/B8dNrmZ3YGxe7pwD/4DxG4rxQ=
github.com/lightningnetwork/lnd v0.5.1-beta.0.20190322220528-6ad8be25e1aa/go.mod h1:Xwk2vsL5uUgfMDQ7oHfltFZIYX5T74Htk0AA8NPzXlE=
github.com/lightningnetwork/lnd/queue v1.0.1 h1:jzJKcTy3Nj5lQrooJ3aaw9Lau3I0IwvQR5sqtjdv2R0=
github.com/lightningnetwork/lnd/queue v1.0.1/go.mod h1:vaQwexir73flPW43Mrm7JOgJHmcEFBWWSl9HlyASoms=
github.com/lightningnetwork/lnd/ticker v1.0.0 h1:S1b60TEGoTtCe2A0yeB+ecoj/kkS4qpwh6l+AkQEZwU=

@ -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…
Cancel
Save