multi: Use user provided close address for cooperative closes

This commit is adapted from @Bluetegu's original
pull request #1462.

This commit reads an optional address to pay funds out to
from a user iniitiated close channel address. If the channel
already has a shutdown script set, the request will fail if
an address is provided. Otherwise, the cooperative close will
pay out to the address provided.
This commit is contained in:
carla
2019-12-09 15:44:00 +02:00
parent ef4d9334b7
commit 94d3eb60a4
7 changed files with 367 additions and 41 deletions

View File

@@ -1881,8 +1881,28 @@ func (r *rpcServer) CloseChannel(in *lnrpc.CloseChannelRequest,
// cooperative channel closure. So we'll forward the request to
// the htlc switch which will handle the negotiation and
// broadcast details.
var deliveryScript lnwire.DeliveryAddress
// If a delivery address to close out to was specified, decode it.
if len(in.DeliveryAddress) > 0 {
// Decode the address provided.
addr, err := btcutil.DecodeAddress(
in.DeliveryAddress, activeNetParams.Params,
)
if err != nil {
return fmt.Errorf("invalid delivery address: %v", err)
}
// Create a script to pay out to the address provided.
deliveryScript, err = txscript.PayToAddrScript(addr)
if err != nil {
return err
}
}
updateChan, errChan = r.server.htlcSwitch.CloseLink(
chanPoint, htlcswitch.CloseRegular, feeRate,
chanPoint, htlcswitch.CloseRegular, feeRate, deliveryScript,
)
}
out: