wtxmgr: add ListLeases
This commit is contained in:
parent
39cbb7bdd9
commit
ff2577a0e7
3 changed files with 52 additions and 8 deletions
|
@ -2659,6 +2659,19 @@ func (w *Wallet) ListUnspent(minconf, maxconf int32,
|
|||
return results, err
|
||||
}
|
||||
|
||||
// ListLeasedOutputs returns a list of objects representing the currently locked
|
||||
// utxos.
|
||||
func (w *Wallet) ListLeasedOutputs() ([]*wtxmgr.LockedOutput, error) {
|
||||
var outputs []*wtxmgr.LockedOutput
|
||||
err := walletdb.View(w.db, func(tx walletdb.ReadTx) error {
|
||||
ns := tx.ReadBucket(wtxmgrNamespaceKey)
|
||||
var err error
|
||||
outputs, err = w.TxStore.ListLockedOutputs(ns)
|
||||
return err
|
||||
})
|
||||
return outputs, err
|
||||
}
|
||||
|
||||
// DumpPrivKeys returns the WIF-encoded private keys for all addresses with
|
||||
// private keys in a wallet.
|
||||
func (w *Wallet) DumpPrivKeys() ([]string, error) {
|
||||
|
|
30
wtxmgr/tx.go
30
wtxmgr/tx.go
|
@ -125,6 +125,14 @@ type TxRecord struct {
|
|||
SerializedTx []byte // Optional: may be nil
|
||||
}
|
||||
|
||||
// LockedOutput is a type that contains an outpoint of an UTXO and its lock
|
||||
// lease information.
|
||||
type LockedOutput struct {
|
||||
Outpoint wire.OutPoint
|
||||
LockID LockID
|
||||
Expiration time.Time
|
||||
}
|
||||
|
||||
// NewTxRecord creates a new transaction record that may be inserted into the
|
||||
// store. It uses memoization to save the transaction hash and the serialized
|
||||
// transaction.
|
||||
|
@ -1226,3 +1234,25 @@ func (s *Store) DeleteExpiredLockedOutputs(ns walletdb.ReadWriteBucket) error {
|
|||
|
||||
return nil
|
||||
}
|
||||
|
||||
// ListLockedOutputs returns a list of objects representing the currently locked
|
||||
// utxos.
|
||||
func (s *Store) ListLockedOutputs(ns walletdb.ReadBucket) ([]*LockedOutput,
|
||||
error) {
|
||||
|
||||
var outputs []*LockedOutput
|
||||
err := forEachLockedOutput(
|
||||
ns, func(op wire.OutPoint, id LockID, expiration time.Time) {
|
||||
outputs = append(outputs, &LockedOutput{
|
||||
Outpoint: op,
|
||||
LockID: id,
|
||||
Expiration: expiration,
|
||||
})
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return outputs, nil
|
||||
}
|
||||
|
|
|
@ -2425,19 +2425,20 @@ func assertOutputLocksExist(t *testing.T, s *Store, ns walletdb.ReadBucket,
|
|||
|
||||
t.Helper()
|
||||
|
||||
var found []wire.OutPoint
|
||||
forEachLockedOutput(ns, func(op wire.OutPoint, _ LockID, _ time.Time) {
|
||||
found = append(found, op)
|
||||
})
|
||||
if len(found) != len(exp) {
|
||||
outputs, err := s.ListLockedOutputs(ns)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if len(outputs) != len(exp) {
|
||||
t.Fatalf("expected to find %v locked output(s), found %v",
|
||||
len(exp), len(found))
|
||||
len(exp), len(outputs))
|
||||
}
|
||||
|
||||
for _, expOp := range exp {
|
||||
exists := false
|
||||
for _, foundOp := range found {
|
||||
if expOp == foundOp {
|
||||
for _, found := range outputs {
|
||||
if expOp == found.Outpoint {
|
||||
exists = true
|
||||
break
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue