multi: return more information in list of leased outputs

With this commit we return the additional information the wallet now
provides about locked/leased outputs.
This commit is contained in:
Oliver Gugger committed 2022-05-12 10:24:40 +02:00
1 parent a25d5255fb
commit 70103a1838
5 files changed
+59 -29

No files matched your search

+14 -7
View File
@@ -10,6 +10,7 @@ import (
"github.com/btcsuite/btcd/btcutil/psbt"
"github.com/btcsuite/btcd/wire"
base "github.com/btcsuite/btcwallet/wallet"
"github.com/btcsuite/btcwallet/wtxmgr"
"github.com/lightningnetwork/lnd/lnwallet"
)
@@ -47,17 +48,21 @@ func verifyInputsUnspent(inputs []*wire.TxIn, utxos []*lnwallet.Utxo) error {
// lockInputs requests a lock lease for all inputs specified in a PSBT packet
// by using the internal, static lock ID of lnd's wallet.
func lockInputs(w lnwallet.WalletController, packet *psbt.Packet) (
[]*wtxmgr.LockedOutput, error) {
func lockInputs(w lnwallet.WalletController,
packet *psbt.Packet) ([]*base.ListLeasedOutputResult, error) {
locks := make([]*wtxmgr.LockedOutput, len(packet.UnsignedTx.TxIn))
locks := make(
[]*base.ListLeasedOutputResult, len(packet.UnsignedTx.TxIn),
)
for idx, rawInput := range packet.UnsignedTx.TxIn {
lock := &wtxmgr.LockedOutput{
LockID: LndInternalLockID,
Outpoint: rawInput.PreviousOutPoint,
lock := &base.ListLeasedOutputResult{
LockedOutput: &wtxmgr.LockedOutput{
LockID: LndInternalLockID,
Outpoint: rawInput.PreviousOutPoint,
},
}
expiration, err := w.LeaseOutput(
expiration, pkScript, value, err := w.LeaseOutput(
lock.LockID, lock.Outpoint, DefaultLockDuration,
)
if err != nil {
@@ -80,6 +85,8 @@ func lockInputs(w lnwallet.WalletController, packet *psbt.Packet) (
}
lock.Expiration = expiration
lock.PkScript = pkScript
lock.Value = int64(value)
locks[idx] = lock
}
+8 -3
View File
@@ -23,6 +23,7 @@ import (
"github.com/btcsuite/btcd/txscript"
"github.com/btcsuite/btcd/wire"
"github.com/btcsuite/btcwallet/waddrmgr"
base "github.com/btcsuite/btcwallet/wallet"
"github.com/btcsuite/btcwallet/wtxmgr"
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
"github.com/lightningnetwork/lnd/input"
@@ -423,7 +424,7 @@ func (w *WalletKit) LeaseOutput(ctx context.Context,
// other concurrent processes attempting to lease the same UTXO.
var expiration time.Time
err = w.cfg.CoinSelectionLocker.WithCoinSelectLock(func() error {
expiration, err = w.cfg.Wallet.LeaseOutput(
expiration, _, _, err = w.cfg.Wallet.LeaseOutput(
lockID, *op, duration,
)
return err
@@ -1003,7 +1004,7 @@ func (w *WalletKit) FundPsbt(_ context.Context,
err error
packet *psbt.Packet
feeSatPerKW chainfee.SatPerKWeight
locks []*wtxmgr.LockedOutput
locks []*base.ListLeasedOutputResult
rawPsbt bytes.Buffer
)
@@ -1189,9 +1190,11 @@ func (w *WalletKit) FundPsbt(_ context.Context,
}
// marshallLeases converts the lock leases to the RPC format.
func marshallLeases(locks []*wtxmgr.LockedOutput) []*UtxoLease {
func marshallLeases(locks []*base.ListLeasedOutputResult) []*UtxoLease {
rpcLocks := make([]*UtxoLease, len(locks))
for idx, lock := range locks {
lock := lock
rpcLocks[idx] = &UtxoLease{
Id: lock.LockID[:],
Outpoint: &lnrpc.OutPoint{
@@ -1200,6 +1203,8 @@ func marshallLeases(locks []*wtxmgr.LockedOutput) []*UtxoLease {
OutputIndex: lock.Outpoint.Index,
},
Expiration: uint64(lock.Expiration.Unix()),
PkScript: lock.PkScript,
Value: uint64(lock.Value),
}
}