|
1 | 1 | package rfqmsg |
2 | 2 |
|
| 3 | +import ( |
| 4 | + "strings" |
| 5 | + |
| 6 | + "github.com/lightninglabs/taproot-assets/asset" |
| 7 | + "github.com/lightninglabs/taproot-assets/fn" |
| 8 | +) |
| 9 | + |
3 | 10 | // JsonAssetBalance is a struct that represents the balance of a single asset ID |
4 | 11 | // within a channel. |
5 | 12 | type JsonAssetBalance struct { |
@@ -44,6 +51,33 @@ type JsonAssetChannel struct { |
44 | 51 | IncomingHtlcBalance uint64 `json:"incoming_htlc_balance"` |
45 | 52 | } |
46 | 53 |
|
| 54 | +// HasAllAssetIDs checks if the OpenChannel contains all asset IDs in the |
| 55 | +// provided set. It returns true if all asset IDs are present, false otherwise. |
| 56 | +func (c *JsonAssetChannel) HasAllAssetIDs(ids fn.Set[asset.ID]) bool { |
| 57 | + // There is a possibility that we're checking the asset ID from an HTLC |
| 58 | + // that hasn't been materialized yet and could actually contain a group |
| 59 | + // key x-coordinate. That should only be the case if there is a single |
| 60 | + // asset ID. |
| 61 | + if len(ids) == 1 && c.GroupKey != "" { |
| 62 | + assetID := ids.ToSlice()[0] |
| 63 | + if strings.Contains(c.GroupKey, assetID.String()) { |
| 64 | + return true |
| 65 | + } |
| 66 | + } |
| 67 | + |
| 68 | + availableIDStrings := fn.NewSet(fn.Map( |
| 69 | + c.FundingAssets, func(fundingAsset JsonAssetUtxo) string { |
| 70 | + return fundingAsset.AssetGenesis.AssetID |
| 71 | + }, |
| 72 | + )...) |
| 73 | + targetIDStrings := fn.NewSet(fn.Map( |
| 74 | + ids.ToSlice(), func(id asset.ID) string { |
| 75 | + return id.String() |
| 76 | + }, |
| 77 | + )...) |
| 78 | + return targetIDStrings.Subset(availableIDStrings) |
| 79 | +} |
| 80 | + |
47 | 81 | // JsonAssetChannelBalances is a struct that represents the balance information |
48 | 82 | // of all assets within open and pending channels. |
49 | 83 | type JsonAssetChannelBalances struct { |
|
0 commit comments