From 0d35ce7561e23d1614c798d4c66be1d4148e76f4 Mon Sep 17 00:00:00 2001 From: carla Date: Mon, 9 Nov 2020 09:34:51 +0200 Subject: [PATCH] mutli: move parse upfront shutdown out of rpcserver --- lnwallet/chancloser/chancloser.go | 22 ++++++++++++++++++++++ rpcserver.go | 23 ++--------------------- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/lnwallet/chancloser/chancloser.go b/lnwallet/chancloser/chancloser.go index 0b073bf7..0fe643bc 100644 --- a/lnwallet/chancloser/chancloser.go +++ b/lnwallet/chancloser/chancloser.go @@ -4,6 +4,8 @@ import ( "bytes" "fmt" + "github.com/btcsuite/btcd/chaincfg" + "github.com/btcsuite/btcd/txscript" "github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcutil" "github.com/davecgh/go-spew/spew" @@ -717,3 +719,23 @@ func calcCompromiseFee(chanPoint wire.OutPoint, ourIdealFee, lastSentFee, return remoteFee } } + +// ParseUpfrontShutdownAddress attempts to parse an upfront shutdown address. +// If the address is empty, it returns nil. If it successfully decoded the +// address, it returns a script that pays out to the address. +func ParseUpfrontShutdownAddress(address string, + params *chaincfg.Params) (lnwire.DeliveryAddress, error) { + + if len(address) == 0 { + return nil, nil + } + + addr, err := btcutil.DecodeAddress( + address, params, + ) + if err != nil { + return nil, fmt.Errorf("invalid address: %v", err) + } + + return txscript.PayToAddrScript(addr) +} diff --git a/rpcserver.go b/rpcserver.go index 57706243..b9dc062d 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -56,6 +56,7 @@ import ( "github.com/lightningnetwork/lnd/lnwallet" "github.com/lightningnetwork/lnd/lnwallet/btcwallet" "github.com/lightningnetwork/lnd/lnwallet/chainfee" + "github.com/lightningnetwork/lnd/lnwallet/chancloser" "github.com/lightningnetwork/lnd/lnwallet/chanfunding" "github.com/lightningnetwork/lnd/lnwire" "github.com/lightningnetwork/lnd/macaroons" @@ -1876,7 +1877,7 @@ func (r *rpcServer) parseOpenChannelReq(in *lnrpc.OpenChannelRequest, rpcsLog.Debugf("[openchannel]: using fee of %v sat/kw for funding tx", int64(feeRate)) - script, err := parseUpfrontShutdownAddress( + script, err := chancloser.ParseUpfrontShutdownAddress( in.CloseAddress, r.cfg.ActiveNetParams.Params, ) if err != nil { @@ -2051,26 +2052,6 @@ func (r *rpcServer) OpenChannelSync(ctx context.Context, } } -// parseUpfrontShutdownScript attempts to parse an upfront shutdown address. -// If the address is empty, it returns nil. If it successfully decoded the -// address, it returns a script that pays out to the address. -func parseUpfrontShutdownAddress(address string, - params *chaincfg.Params) (lnwire.DeliveryAddress, error) { - - if len(address) == 0 { - return nil, nil - } - - addr, err := btcutil.DecodeAddress( - address, params, - ) - if err != nil { - return nil, fmt.Errorf("invalid address: %v", err) - } - - return txscript.PayToAddrScript(addr) -} - // GetChanPointFundingTxid returns the given channel point's funding txid in // raw bytes. func GetChanPointFundingTxid(chanPoint *lnrpc.ChannelPoint) (*chainhash.Hash, error) {