walletrpc: use locked utxo struct from wtxmgr

This commit is contained in:
Joost Jager 2021-03-12 09:14:58 +01:00
parent 927f17be32
commit 37331a5ab2
2 changed files with 15 additions and 23 deletions

@ -23,14 +23,6 @@ var (
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
// known, non-locked UTXOs given.
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
// by using the internal, static lock ID of lnd's wallet.
func lockInputs(w lnwallet.WalletController, packet *psbt.Packet) ([]*utxoLock,
error) {
func lockInputs(w lnwallet.WalletController, packet *psbt.Packet) (
[]*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 {
lock := &utxoLock{
lockID: LndInternalLockID,
outpoint: rawInput.PreviousOutPoint,
lock := &wtxmgr.LockedOutput{
LockID: LndInternalLockID,
Outpoint: rawInput.PreviousOutPoint,
}
expiration, err := w.LeaseOutput(
lock.lockID, lock.outpoint, DefaultLockDuration,
lock.LockID, lock.Outpoint, DefaultLockDuration,
)
if err != nil {
// 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
// much we can do.
for i := 0; i < idx; i++ {
op := locks[i].outpoint
op := locks[i].Outpoint
if err := w.ReleaseOutput(
LndInternalLockID, op,
); err != nil {
@ -88,7 +80,7 @@ func lockInputs(w lnwallet.WalletController, packet *psbt.Packet) ([]*utxoLock,
"UTXO: %v", err)
}
lock.expiration = expiration
lock.Expiration = expiration
locks[idx] = lock
}

@ -917,7 +917,7 @@ func (w *WalletKit) FundPsbt(_ context.Context,
err error
packet *psbt.Packet
feeSatPerKW chainfee.SatPerKWeight
locks []*utxoLock
locks []*wtxmgr.LockedOutput
rawPsbt bytes.Buffer
)
@ -1081,13 +1081,13 @@ func (w *WalletKit) FundPsbt(_ context.Context,
rpcLocks := make([]*UtxoLease, len(locks))
for idx, lock := range locks {
rpcLocks[idx] = &UtxoLease{
Id: lock.lockID[:],
Id: lock.LockID[:],
Outpoint: &lnrpc.OutPoint{
TxidBytes: lock.outpoint.Hash[:],
TxidStr: lock.outpoint.Hash.String(),
OutputIndex: lock.outpoint.Index,
TxidBytes: lock.Outpoint.Hash[:],
TxidStr: lock.Outpoint.Hash.String(),
OutputIndex: lock.Outpoint.Index,
},
Expiration: uint64(lock.expiration.Unix()),
Expiration: uint64(lock.Expiration.Unix()),
}
}