instantout: add addr to send funds to

This commit is contained in:
sputn1ck 2024-03-01 16:56:22 +01:00
parent c19781bd13
commit 6a62be0d09
No known key found for this signature in database
GPG key ID: 671103D881A5F0E4
6 changed files with 233 additions and 187 deletions

View file

@ -19,6 +19,7 @@ import (
"github.com/lightningnetwork/lnd/lnrpc"
"github.com/lightningnetwork/lnd/lnrpc/walletrpc"
"github.com/lightningnetwork/lnd/lntypes"
"github.com/lightningnetwork/lnd/lnwallet"
)
const (
@ -59,6 +60,7 @@ type InitInstantOutCtx struct {
initationHeight int32
outgoingChanSet loopdb.ChannelSet
protocolVersion ProtocolVersion
sweepAddress btcutil.Address
}
// InitInstantOutAction is the first action that is executed when the instant
@ -165,11 +167,15 @@ func (f *FSM) InitInstantOutAction(eventCtx fsm.EventContext) fsm.EventType {
}
// Create the address that we'll send the funds to.
sweepAddress, err := f.cfg.Wallet.NextAddr(
f.ctx, "", walletrpc.AddressType_TAPROOT_PUBKEY, false,
)
if err != nil {
return f.HandleError(err)
sweepAddress := initCtx.sweepAddress
if sweepAddress == nil {
sweepAddress, err = f.cfg.Wallet.NextAddr(
f.ctx, lnwallet.DefaultAccountName,
walletrpc.AddressType_TAPROOT_PUBKEY, false,
)
if err != nil {
return f.HandleError(err)
}
}
// Now we can create the instant out.

View file

@ -137,7 +137,20 @@ func (m *Manager) recoverInstantOuts(ctx context.Context) error {
// NewInstantOut creates a new instantout.
func (m *Manager) NewInstantOut(ctx context.Context,
reservations []reservation.ID) (*FSM, error) {
reservations []reservation.ID, sweepAddress string) (*FSM, error) {
var (
sweepAddr btcutil.Address
err error
)
if sweepAddress != "" {
sweepAddr, err = btcutil.DecodeAddress(
sweepAddress, m.cfg.Network,
)
if err != nil {
return nil, err
}
}
m.Lock()
// Create the instantout request.
@ -146,6 +159,7 @@ func (m *Manager) NewInstantOut(ctx context.Context,
reservations: reservations,
initationHeight: m.currentHeight,
protocolVersion: CurrentProtocolVersion(),
sweepAddress: sweepAddr,
}
instantOut, err := NewFSM(