mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-06-23 15:22:38 +02:00
lnd: handles selected outpoints in parseOpenChannelReq
This commit is contained in:
parent
d327c92188
commit
e4f0e58214
@ -276,6 +276,13 @@ type InitFundingMsg struct {
|
|||||||
// minimum amount to commit to.
|
// minimum amount to commit to.
|
||||||
MinFundAmt btcutil.Amount
|
MinFundAmt btcutil.Amount
|
||||||
|
|
||||||
|
// Outpoints is a list of client-selected outpoints that should be used
|
||||||
|
// for funding a channel. If LocalFundingAmt is specified then this
|
||||||
|
// amount is allocated from the sum of outpoints towards funding. If
|
||||||
|
// the FundUpToMaxAmt is specified the entirety of selected funds is
|
||||||
|
// allocated towards channel funding.
|
||||||
|
Outpoints []wire.OutPoint
|
||||||
|
|
||||||
// ChanFunder is an optional channel funder that allows the caller to
|
// ChanFunder is an optional channel funder that allows the caller to
|
||||||
// control exactly how the channel funding is carried out. If not
|
// control exactly how the channel funding is carried out. If not
|
||||||
// specified, then the default chanfunding.WalletAssembler will be
|
// specified, then the default chanfunding.WalletAssembler will be
|
||||||
@ -3973,6 +3980,7 @@ func (f *Manager) handleInitFundingMsg(msg *InitFundingMsg) {
|
|||||||
maxHtlcs = msg.MaxHtlcs
|
maxHtlcs = msg.MaxHtlcs
|
||||||
maxCSV = msg.MaxLocalCsv
|
maxCSV = msg.MaxLocalCsv
|
||||||
chanReserve = msg.RemoteChanReserve
|
chanReserve = msg.RemoteChanReserve
|
||||||
|
outpoints = msg.Outpoints
|
||||||
)
|
)
|
||||||
|
|
||||||
// If no maximum CSV delay was set for this channel, we use our default
|
// If no maximum CSV delay was set for this channel, we use our default
|
||||||
@ -4101,6 +4109,7 @@ func (f *Manager) handleInitFundingMsg(msg *InitFundingMsg) {
|
|||||||
FundUpToMaxAmt: msg.FundUpToMaxAmt,
|
FundUpToMaxAmt: msg.FundUpToMaxAmt,
|
||||||
MinFundAmt: msg.MinFundAmt,
|
MinFundAmt: msg.MinFundAmt,
|
||||||
RemoteChanReserve: chanReserve,
|
RemoteChanReserve: chanReserve,
|
||||||
|
Outpoints: outpoints,
|
||||||
CommitFeePerKw: commitFeePerKw,
|
CommitFeePerKw: commitFeePerKw,
|
||||||
FundingFeePerKw: msg.FundingFeePerKw,
|
FundingFeePerKw: msg.FundingFeePerKw,
|
||||||
PushMSat: msg.PushAmt,
|
PushMSat: msg.PushAmt,
|
||||||
|
29
rpcserver.go
29
rpcserver.go
@ -2145,6 +2145,15 @@ func (r *rpcServer) parseOpenChannelReq(in *lnrpc.OpenChannelRequest,
|
|||||||
"exceeds %d", in.Memo, len(in.Memo), maxMemoLength)
|
"exceeds %d", in.Memo, len(in.Memo), maxMemoLength)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check, if manually selected outpoints are present to fund a channel.
|
||||||
|
var outpoints []wire.OutPoint
|
||||||
|
if len(in.Outpoints) > 0 {
|
||||||
|
outpoints, err = toWireOutpoints(in.Outpoints)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("can't create outpoints %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Instruct the server to trigger the necessary events to attempt to
|
// Instruct the server to trigger the necessary events to attempt to
|
||||||
// open a new channel. A stream is returned in place, this stream will
|
// 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.
|
// be used to consume updates of the state of the pending channel.
|
||||||
@ -2171,9 +2180,29 @@ func (r *rpcServer) parseOpenChannelReq(in *lnrpc.OpenChannelRequest,
|
|||||||
FundUpToMaxAmt: fundUpToMaxAmt,
|
FundUpToMaxAmt: fundUpToMaxAmt,
|
||||||
MinFundAmt: minFundAmt,
|
MinFundAmt: minFundAmt,
|
||||||
Memo: []byte(in.Memo),
|
Memo: []byte(in.Memo),
|
||||||
|
Outpoints: outpoints,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// toWireOutpoints converts a list of outpoints from the rpc format to the wire
|
||||||
|
// format.
|
||||||
|
func toWireOutpoints(outpoints []*lnrpc.OutPoint) ([]wire.OutPoint, error) {
|
||||||
|
var wireOutpoints []wire.OutPoint
|
||||||
|
for _, outpoint := range outpoints {
|
||||||
|
hash, err := chainhash.NewHashFromStr(outpoint.TxidStr)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("cannot create chainhash")
|
||||||
|
}
|
||||||
|
|
||||||
|
wireOutpoint := wire.NewOutPoint(
|
||||||
|
hash, outpoint.OutputIndex,
|
||||||
|
)
|
||||||
|
wireOutpoints = append(wireOutpoints, *wireOutpoint)
|
||||||
|
}
|
||||||
|
|
||||||
|
return wireOutpoints, nil
|
||||||
|
}
|
||||||
|
|
||||||
// OpenChannel attempts to open a singly funded channel specified in the
|
// OpenChannel attempts to open a singly funded channel specified in the
|
||||||
// request to a remote peer.
|
// request to a remote peer.
|
||||||
func (r *rpcServer) OpenChannel(in *lnrpc.OpenChannelRequest,
|
func (r *rpcServer) OpenChannel(in *lnrpc.OpenChannelRequest,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user