mutli: move parse upfront shutdown out of rpcserver
This commit is contained in:
parent
38fd7d206f
commit
0d35ce7561
@ -4,6 +4,8 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/btcsuite/btcd/chaincfg"
|
||||||
|
"github.com/btcsuite/btcd/txscript"
|
||||||
"github.com/btcsuite/btcd/wire"
|
"github.com/btcsuite/btcd/wire"
|
||||||
"github.com/btcsuite/btcutil"
|
"github.com/btcsuite/btcutil"
|
||||||
"github.com/davecgh/go-spew/spew"
|
"github.com/davecgh/go-spew/spew"
|
||||||
@ -717,3 +719,23 @@ func calcCompromiseFee(chanPoint wire.OutPoint, ourIdealFee, lastSentFee,
|
|||||||
return remoteFee
|
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)
|
||||||
|
}
|
||||||
|
23
rpcserver.go
23
rpcserver.go
@ -56,6 +56,7 @@ import (
|
|||||||
"github.com/lightningnetwork/lnd/lnwallet"
|
"github.com/lightningnetwork/lnd/lnwallet"
|
||||||
"github.com/lightningnetwork/lnd/lnwallet/btcwallet"
|
"github.com/lightningnetwork/lnd/lnwallet/btcwallet"
|
||||||
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
|
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
|
||||||
|
"github.com/lightningnetwork/lnd/lnwallet/chancloser"
|
||||||
"github.com/lightningnetwork/lnd/lnwallet/chanfunding"
|
"github.com/lightningnetwork/lnd/lnwallet/chanfunding"
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
"github.com/lightningnetwork/lnd/macaroons"
|
"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",
|
rpcsLog.Debugf("[openchannel]: using fee of %v sat/kw for funding tx",
|
||||||
int64(feeRate))
|
int64(feeRate))
|
||||||
|
|
||||||
script, err := parseUpfrontShutdownAddress(
|
script, err := chancloser.ParseUpfrontShutdownAddress(
|
||||||
in.CloseAddress, r.cfg.ActiveNetParams.Params,
|
in.CloseAddress, r.cfg.ActiveNetParams.Params,
|
||||||
)
|
)
|
||||||
if err != nil {
|
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
|
// GetChanPointFundingTxid returns the given channel point's funding txid in
|
||||||
// raw bytes.
|
// raw bytes.
|
||||||
func GetChanPointFundingTxid(chanPoint *lnrpc.ChannelPoint) (*chainhash.Hash, error) {
|
func GetChanPointFundingTxid(chanPoint *lnrpc.ChannelPoint) (*chainhash.Hash, error) {
|
||||||
|
Loading…
Reference in New Issue
Block a user