Skip to content

Commit

Permalink
Merge pull request #1032 from Roasbeef/list-utxos-lease-info
Browse files Browse the repository at this point in the history
tapdb+rpc: return lease owner and expiry for managed UTXOs
  • Loading branch information
Roasbeef authored Jul 22, 2024
2 parents b154a99 + 593271a commit c2a5227
Show file tree
Hide file tree
Showing 6 changed files with 736 additions and 677 deletions.
2 changes: 2 additions & 0 deletions rpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -1179,6 +1179,8 @@ func (r *rpcServer) ListUtxos(ctx context.Context,
InternalKey: u.InternalKey.PubKey.SerializeCompressed(),
TaprootAssetRoot: u.TaprootAssetRoot,
MerkleRoot: u.MerkleRoot,
LeaseOwner: u.LeaseOwner[:],
LeaseExpiryUnix: u.LeaseExpiry.Unix(),
}
}

Expand Down
16 changes: 15 additions & 1 deletion tapdb/assets_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,14 @@ type ManagedUTXO struct {
// TapscriptSibling is the serialized tapscript sibling preimage of
// this asset. This will usually be blank.
TapscriptSibling []byte

// LeaseOwner is the identifier of the lease owner of this UTXO. If
// blank, this UTXO isn't leased.
LeaseOwner []byte

// LeaseExpiry is the expiry time of the lease on this UTXO. If the
// zero, then this UTXO isn't leased.
LeaseExpiry time.Time
}

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

managedUtxos[i] = &ManagedUTXO{
utxo := &ManagedUTXO{
OutPoint: anchorPoint,
OutputValue: btcutil.Amount(u.AmtSats),
InternalKey: keychain.KeyDescriptor{
Expand All @@ -1140,7 +1148,13 @@ func (a *AssetStore) FetchManagedUTXOs(ctx context.Context) (
TaprootAssetRoot: u.TaprootAssetRoot,
MerkleRoot: u.MerkleRoot,
TapscriptSibling: u.TapscriptSibling,
LeaseOwner: u.LeaseOwner,
}
if u.LeaseExpiry.Valid {
utxo.LeaseExpiry = u.LeaseExpiry.Time
}

managedUtxos[i] = utxo
}

return managedUtxos, nil
Expand Down
5 changes: 4 additions & 1 deletion tapdb/assets_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1466,8 +1466,11 @@ func TestAssetExportLog(t *testing.T) {
require.NoError(t, err)
require.Len(t, utxos, 3)

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

// Second UTXO will be our new one.
newUtxo := utxos[1]
Expand Down
Loading

0 comments on commit c2a5227

Please sign in to comment.