Skip to content

Commit c2a5227

Browse files
authored
Merge pull request #1032 from Roasbeef/list-utxos-lease-info
tapdb+rpc: return lease owner and expiry for managed UTXOs
2 parents b154a99 + 593271a commit c2a5227

File tree

6 files changed

+736
-677
lines changed

6 files changed

+736
-677
lines changed

rpcserver.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,6 +1179,8 @@ func (r *rpcServer) ListUtxos(ctx context.Context,
11791179
InternalKey: u.InternalKey.PubKey.SerializeCompressed(),
11801180
TaprootAssetRoot: u.TaprootAssetRoot,
11811181
MerkleRoot: u.MerkleRoot,
1182+
LeaseOwner: u.LeaseOwner[:],
1183+
LeaseExpiryUnix: u.LeaseExpiry.Unix(),
11821184
}
11831185
}
11841186

tapdb/assets_store.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,14 @@ type ManagedUTXO struct {
417417
// TapscriptSibling is the serialized tapscript sibling preimage of
418418
// this asset. This will usually be blank.
419419
TapscriptSibling []byte
420+
421+
// LeaseOwner is the identifier of the lease owner of this UTXO. If
422+
// blank, this UTXO isn't leased.
423+
LeaseOwner []byte
424+
425+
// LeaseExpiry is the expiry time of the lease on this UTXO. If the
426+
// zero, then this UTXO isn't leased.
427+
LeaseExpiry time.Time
420428
}
421429

422430
// AssetHumanReadable is a subset of the base asset struct that only includes
@@ -1125,7 +1133,7 @@ func (a *AssetStore) FetchManagedUTXOs(ctx context.Context) (
11251133
return nil, err
11261134
}
11271135

1128-
managedUtxos[i] = &ManagedUTXO{
1136+
utxo := &ManagedUTXO{
11291137
OutPoint: anchorPoint,
11301138
OutputValue: btcutil.Amount(u.AmtSats),
11311139
InternalKey: keychain.KeyDescriptor{
@@ -1140,7 +1148,13 @@ func (a *AssetStore) FetchManagedUTXOs(ctx context.Context) (
11401148
TaprootAssetRoot: u.TaprootAssetRoot,
11411149
MerkleRoot: u.MerkleRoot,
11421150
TapscriptSibling: u.TapscriptSibling,
1151+
LeaseOwner: u.LeaseOwner,
11431152
}
1153+
if u.LeaseExpiry.Valid {
1154+
utxo.LeaseExpiry = u.LeaseExpiry.Time
1155+
}
1156+
1157+
managedUtxos[i] = utxo
11441158
}
11451159

11461160
return managedUtxos, nil

tapdb/assets_store_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1466,8 +1466,11 @@ func TestAssetExportLog(t *testing.T) {
14661466
require.NoError(t, err)
14671467
require.Len(t, utxos, 3)
14681468

1469-
// First UTXO should remain unchanged.
1469+
// First UTXO should remain unchanged. It should now have a lease
1470+
// expiry and owner set.
14701471
require.Equal(t, assetGen.anchorPoints[0], utxos[0].OutPoint)
1472+
require.Equal(t, leaseOwner[:], utxos[0].LeaseOwner[:])
1473+
require.NotZero(t, utxos[0].LeaseExpiry)
14711474

14721475
// Second UTXO will be our new one.
14731476
newUtxo := utxos[1]

0 commit comments

Comments
 (0)