1515package utxorpc
1616
1717import (
18+ "bytes"
1819 "context"
1920 "encoding/hex"
2021 "fmt"
@@ -192,8 +193,10 @@ func (s *queryServiceServer) SearchUtxos(
192193 return nil , fmt .Errorf ("ERROR: empty predicate: %v" , predicate )
193194 }
194195
195- var addresses []common.Address
196196 addressPattern := predicate .GetMatch ().GetCardano ().GetAddress ()
197+ assetPattern := predicate .GetMatch ().GetCardano ().GetAsset ()
198+
199+ var addresses []common.Address
197200 if addressPattern != nil {
198201 // Handle Exact Address
199202 exactAddressBytes := addressPattern .GetExactAddress ()
@@ -263,6 +266,7 @@ func (s *queryServiceServer) SearchUtxos(
263266 return nil , err
264267 }
265268
269+ // Proceed to include the UTxO in the response
266270 for utxoId , utxo := range utxos .Results {
267271 var aud query.AnyUtxoData
268272 var audc query.AnyUtxoData_Cardano
@@ -273,8 +277,32 @@ func (s *queryServiceServer) SearchUtxos(
273277 aud .NativeBytes = utxo .Cbor ()
274278 audc .Cardano = utxo .Utxorpc ()
275279 aud .ParsedState = & audc
280+
281+ // If AssetPattern is specified, filter based on it
282+ if assetPattern != nil {
283+ assetFound := false
284+ for _ , multiasset := range audc .Cardano .Assets {
285+ if bytes .Equal (multiasset .PolicyId , assetPattern .PolicyId ) {
286+ for _ , asset := range multiasset .Assets {
287+ if bytes .Equal (asset .Name , assetPattern .AssetName ) {
288+ assetFound = true
289+ break
290+ }
291+ }
292+ }
293+ if assetFound {
294+ break
295+ }
296+ }
297+
298+ // Asset not found; skip this UTxO
299+ if ! assetFound {
300+ continue
301+ }
302+ }
276303 resp .Items = append (resp .Items , & aud )
277304 }
305+
278306 resp .LedgerTip = & query.ChainPoint {
279307 Slot : point .Slot ,
280308 Hash : point .Hash ,
0 commit comments