mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-02-24 06:47:44 +01:00
walletrpc: use locked utxo struct from wtxmgr
This commit is contained in:
parent
927f17be32
commit
37331a5ab2
2 changed files with 15 additions and 23 deletions
|
@ -23,14 +23,6 @@ var (
|
||||||
DefaultLockDuration = 10 * time.Minute
|
DefaultLockDuration = 10 * time.Minute
|
||||||
)
|
)
|
||||||
|
|
||||||
// utxoLock is a type that contains an outpoint of an UTXO and its lock lease
|
|
||||||
// information.
|
|
||||||
type utxoLock struct {
|
|
||||||
lockID wtxmgr.LockID
|
|
||||||
outpoint wire.OutPoint
|
|
||||||
expiration time.Time
|
|
||||||
}
|
|
||||||
|
|
||||||
// verifyInputsUnspent checks that all inputs are contained in the list of
|
// verifyInputsUnspent checks that all inputs are contained in the list of
|
||||||
// known, non-locked UTXOs given.
|
// known, non-locked UTXOs given.
|
||||||
func verifyInputsUnspent(inputs []*wire.TxIn, utxos []*lnwallet.Utxo) error {
|
func verifyInputsUnspent(inputs []*wire.TxIn, utxos []*lnwallet.Utxo) error {
|
||||||
|
@ -55,18 +47,18 @@ func verifyInputsUnspent(inputs []*wire.TxIn, utxos []*lnwallet.Utxo) error {
|
||||||
|
|
||||||
// lockInputs requests a lock lease for all inputs specified in a PSBT packet
|
// lockInputs requests a lock lease for all inputs specified in a PSBT packet
|
||||||
// by using the internal, static lock ID of lnd's wallet.
|
// by using the internal, static lock ID of lnd's wallet.
|
||||||
func lockInputs(w lnwallet.WalletController, packet *psbt.Packet) ([]*utxoLock,
|
func lockInputs(w lnwallet.WalletController, packet *psbt.Packet) (
|
||||||
error) {
|
[]*wtxmgr.LockedOutput, error) {
|
||||||
|
|
||||||
locks := make([]*utxoLock, len(packet.UnsignedTx.TxIn))
|
locks := make([]*wtxmgr.LockedOutput, len(packet.UnsignedTx.TxIn))
|
||||||
for idx, rawInput := range packet.UnsignedTx.TxIn {
|
for idx, rawInput := range packet.UnsignedTx.TxIn {
|
||||||
lock := &utxoLock{
|
lock := &wtxmgr.LockedOutput{
|
||||||
lockID: LndInternalLockID,
|
LockID: LndInternalLockID,
|
||||||
outpoint: rawInput.PreviousOutPoint,
|
Outpoint: rawInput.PreviousOutPoint,
|
||||||
}
|
}
|
||||||
|
|
||||||
expiration, err := w.LeaseOutput(
|
expiration, err := w.LeaseOutput(
|
||||||
lock.lockID, lock.outpoint, DefaultLockDuration,
|
lock.LockID, lock.Outpoint, DefaultLockDuration,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// If we run into a problem with locking one output, we
|
// If we run into a problem with locking one output, we
|
||||||
|
@ -74,7 +66,7 @@ func lockInputs(w lnwallet.WalletController, packet *psbt.Packet) ([]*utxoLock,
|
||||||
// locked so far. If that fails as well, there's not
|
// locked so far. If that fails as well, there's not
|
||||||
// much we can do.
|
// much we can do.
|
||||||
for i := 0; i < idx; i++ {
|
for i := 0; i < idx; i++ {
|
||||||
op := locks[i].outpoint
|
op := locks[i].Outpoint
|
||||||
if err := w.ReleaseOutput(
|
if err := w.ReleaseOutput(
|
||||||
LndInternalLockID, op,
|
LndInternalLockID, op,
|
||||||
); err != nil {
|
); err != nil {
|
||||||
|
@ -88,7 +80,7 @@ func lockInputs(w lnwallet.WalletController, packet *psbt.Packet) ([]*utxoLock,
|
||||||
"UTXO: %v", err)
|
"UTXO: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
lock.expiration = expiration
|
lock.Expiration = expiration
|
||||||
locks[idx] = lock
|
locks[idx] = lock
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -917,7 +917,7 @@ func (w *WalletKit) FundPsbt(_ context.Context,
|
||||||
err error
|
err error
|
||||||
packet *psbt.Packet
|
packet *psbt.Packet
|
||||||
feeSatPerKW chainfee.SatPerKWeight
|
feeSatPerKW chainfee.SatPerKWeight
|
||||||
locks []*utxoLock
|
locks []*wtxmgr.LockedOutput
|
||||||
rawPsbt bytes.Buffer
|
rawPsbt bytes.Buffer
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1081,13 +1081,13 @@ func (w *WalletKit) FundPsbt(_ context.Context,
|
||||||
rpcLocks := make([]*UtxoLease, len(locks))
|
rpcLocks := make([]*UtxoLease, len(locks))
|
||||||
for idx, lock := range locks {
|
for idx, lock := range locks {
|
||||||
rpcLocks[idx] = &UtxoLease{
|
rpcLocks[idx] = &UtxoLease{
|
||||||
Id: lock.lockID[:],
|
Id: lock.LockID[:],
|
||||||
Outpoint: &lnrpc.OutPoint{
|
Outpoint: &lnrpc.OutPoint{
|
||||||
TxidBytes: lock.outpoint.Hash[:],
|
TxidBytes: lock.Outpoint.Hash[:],
|
||||||
TxidStr: lock.outpoint.Hash.String(),
|
TxidStr: lock.Outpoint.Hash.String(),
|
||||||
OutputIndex: lock.outpoint.Index,
|
OutputIndex: lock.Outpoint.Index,
|
||||||
},
|
},
|
||||||
Expiration: uint64(lock.expiration.Unix()),
|
Expiration: uint64(lock.Expiration.Unix()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue