lnrpc: add upfront shutdown address to open channel request

This commit is contained in:
carla 2019-12-17 21:58:28 +02:00
parent fd4153851d
commit a2f029caca
No known key found for this signature in database
GPG Key ID: 4CA7FE54A6213C91
4 changed files with 641 additions and 578 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1643,6 +1643,18 @@ message OpenChannelRequest {
/// Whether unconfirmed outputs should be used as inputs for the funding transaction.
bool spend_unconfirmed = 12 [json_name = "spend_unconfirmed"];
/*
Close address is an optional address which specifies the address to which
funds should be paid out to upon cooperative close. This field may only be
set if the peer supports the option upfront feature bit (call listpeers
to check). The remote peer will only accept cooperative closes to this
address if it is set.
Note: If this value is set on channel creation, you will *not* be able to
cooperatively close out to a different address.
*/
string close_address = 13[json_name = "close_address"];
}
message OpenStatusUpdate {
oneof update {

View File

@ -3233,6 +3233,10 @@
"type": "boolean",
"format": "boolean",
"description": "/ Whether unconfirmed outputs should be used as inputs for the funding transaction."
},
"close_address": {
"type": "string",
"description": "Close address is an optional address which specifies the address to which\nfunds should be paid out to upon cooperative close. This field may only be\nset if the peer supports the option upfront feature bit (call listpeers\nto check). The remote peer will only accept cooperative closes to this\naddress if it is set.\n\nNote: If this value is set on channel creation, you will *not* be able to\ncooperatively close out to a different address."
}
}
},

View File

@ -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) {