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:
5 files changed
+59
-29
No files matched your search
@@ -919,30 +919,43 @@ func (b *BtcWallet) UnlockOutpoint(o wire.OutPoint) {
|
||||
//
|
||||
// NOTE: This method requires the global coin selection lock to be held.
|
||||
func (b *BtcWallet) LeaseOutput(id wtxmgr.LockID, op wire.OutPoint,
|
||||
duration time.Duration) (time.Time, error) {
|
||||
duration time.Duration) (time.Time, []byte, btcutil.Amount, error) {
|
||||
|
||||
// Make sure we don't attempt to double lock an output that's been
|
||||
// locked by the in-memory implementation.
|
||||
if b.wallet.LockedOutpoint(op) {
|
||||
return time.Time{}, wtxmgr.ErrOutputAlreadyLocked
|
||||
return time.Time{}, nil, 0, wtxmgr.ErrOutputAlreadyLocked
|
||||
}
|
||||
|
||||
return b.wallet.LeaseOutput(id, op, duration)
|
||||
lockedUntil, err := b.wallet.LeaseOutput(id, op, duration)
|
||||
if err != nil {
|
||||
return time.Time{}, nil, 0, err
|
||||
}
|
||||
|
||||
// Get the pkScript and value for this lock from the list of all leased
|
||||
// outputs.
|
||||
allLeases, err := b.wallet.ListLeasedOutputs()
|
||||
if err != nil {
|
||||
return time.Time{}, nil, 0, err
|
||||
}
|
||||
|
||||
for _, lease := range allLeases {
|
||||
if lease.Outpoint == op {
|
||||
return lockedUntil, lease.PkScript,
|
||||
btcutil.Amount(lease.Value), nil
|
||||
}
|
||||
}
|
||||
|
||||
// We MUST find the leased output in the loop above, otherwise something
|
||||
// is seriously wrong.
|
||||
return time.Time{}, nil, 0, wtxmgr.ErrUnknownOutput
|
||||
}
|
||||
|
||||
// ListLeasedOutputs returns a list of all currently locked outputs.
|
||||
func (b *BtcWallet) ListLeasedOutputs() ([]*wtxmgr.LockedOutput, error) {
|
||||
leasedOutputs, err := b.wallet.ListLeasedOutputs()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
func (b *BtcWallet) ListLeasedOutputs() ([]*base.ListLeasedOutputResult,
|
||||
error) {
|
||||
|
||||
lockedOutputs := make([]*wtxmgr.LockedOutput, len(leasedOutputs))
|
||||
for i, output := range leasedOutputs {
|
||||
lockedOutputs[i] = output.LockedOutput
|
||||
}
|
||||
|
||||
return lockedOutputs, nil
|
||||
return b.wallet.ListLeasedOutputs()
|
||||
}
|
||||
|
||||
// ReleaseOutput unlocks an output, allowing it to be available for coin
|
||||
|
||||
@@ -15,6 +15,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/wallet/txauthor"
|
||||
"github.com/btcsuite/btcwallet/wtxmgr"
|
||||
"github.com/lightningnetwork/lnd/keychain"
|
||||
@@ -338,7 +339,8 @@ type WalletController interface {
|
||||
//
|
||||
// NOTE: This method requires the global coin selection lock to be held.
|
||||
LeaseOutput(id wtxmgr.LockID, op wire.OutPoint,
|
||||
duration time.Duration) (time.Time, error)
|
||||
duration time.Duration) (time.Time, []byte, btcutil.Amount,
|
||||
error)
|
||||
|
||||
// ReleaseOutput unlocks an output, allowing it to be available for coin
|
||||
// selection if it remains unspent. The ID should match the one used to
|
||||
@@ -348,7 +350,7 @@ type WalletController interface {
|
||||
ReleaseOutput(id wtxmgr.LockID, op wire.OutPoint) error
|
||||
|
||||
// ListLeasedOutputs returns a list of all currently locked outputs.
|
||||
ListLeasedOutputs() ([]*wtxmgr.LockedOutput, error)
|
||||
ListLeasedOutputs() ([]*base.ListLeasedOutputResult, error)
|
||||
|
||||
// PublishTransaction performs cursory validation (dust checks, etc),
|
||||
// then finally broadcasts the passed transaction to the Bitcoin network.
|
||||
|
||||
Reference in new issue
Block a user