mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-10-09 20:23:24 +02:00
lnrpc: add upfront shutdown address to open channel request
This commit is contained in:
30
rpcserver.go
30
rpcserver.go
@@ -1537,6 +1537,11 @@ func (r *rpcServer) OpenChannel(in *lnrpc.OpenChannelRequest,
|
||||
rpcsLog.Debugf("[openchannel]: using fee of %v sat/kw for funding tx",
|
||||
int64(feeRate))
|
||||
|
||||
script, err := parseUpfrontShutdownAddress(in.CloseAddress)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error parsing upfront shutdown: %v", err)
|
||||
}
|
||||
|
||||
// Instruct the server to trigger the necessary events to attempt to
|
||||
// open a new channel. A stream is returned in place, this stream will
|
||||
// be used to consume updates of the state of the pending channel.
|
||||
@@ -1550,6 +1555,7 @@ func (r *rpcServer) OpenChannel(in *lnrpc.OpenChannelRequest,
|
||||
private: in.Private,
|
||||
remoteCsvDelay: remoteCsvDelay,
|
||||
minConfs: minConfs,
|
||||
shutdownScript: script,
|
||||
}
|
||||
|
||||
updateChan, errChan := r.server.OpenChannel(req)
|
||||
@@ -1682,6 +1688,11 @@ func (r *rpcServer) OpenChannelSync(ctx context.Context,
|
||||
rpcsLog.Tracef("[openchannel] target sat/kw for funding tx: %v",
|
||||
int64(feeRate))
|
||||
|
||||
script, err := parseUpfrontShutdownAddress(in.CloseAddress)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error parsing upfront shutdown: %v", err)
|
||||
}
|
||||
|
||||
req := &openChanReq{
|
||||
targetPubkey: nodepubKey,
|
||||
chainHash: *activeNetParams.GenesisHash,
|
||||
@@ -1692,6 +1703,7 @@ func (r *rpcServer) OpenChannelSync(ctx context.Context,
|
||||
private: in.Private,
|
||||
remoteCsvDelay: remoteCsvDelay,
|
||||
minConfs: minConfs,
|
||||
shutdownScript: script,
|
||||
}
|
||||
|
||||
updateChan, errChan := r.server.OpenChannel(req)
|
||||
@@ -1725,6 +1737,24 @@ 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) (lnwire.DeliveryAddress, error) {
|
||||
if len(address) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
addr, err := btcutil.DecodeAddress(
|
||||
address, activeNetParams.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) {
|
||||
|
Reference in New Issue
Block a user