From 9b6e8355d1cd27208c1444219651a77e4568d012 Mon Sep 17 00:00:00 2001 From: Branko Bosnic Date: Fri, 23 Feb 2024 11:53:55 +0100 Subject: [PATCH] feat: add search by delegation id --- api/src/services/nova/novaApiService.ts | 19 +++++++++++++++++++ api/src/utils/nova/searchExecutor.ts | 15 +++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/api/src/services/nova/novaApiService.ts b/api/src/services/nova/novaApiService.ts index 48d25f8fe..6da284316 100644 --- a/api/src/services/nova/novaApiService.ts +++ b/api/src/services/nova/novaApiService.ts @@ -158,6 +158,25 @@ export class NovaApiService { } } + /** + * Get the delegation output details. + * @param delegationId The delegationId to get the output details for. + * @returns The delegation output details. + */ + public async delegationDetails(delegationId: string): Promise { + try { + const delegationOutputId = await this.client.delegationOutputId(delegationId); + + if (delegationOutputId) { + const outputResponse = await this.outputDetails(delegationOutputId); + + return outputResponse.error ? { error: outputResponse.error } : { output: outputResponse.output }; + } + } catch { + return { message: "Delegation output not found" }; + } + } + /** * Get controlled Foundry output id by controller Account address * @param accountAddress The bech32 account address to get the controlled Foundries for. diff --git a/api/src/utils/nova/searchExecutor.ts b/api/src/utils/nova/searchExecutor.ts index 9c276abba..5e2d7fbbc 100644 --- a/api/src/utils/nova/searchExecutor.ts +++ b/api/src/utils/nova/searchExecutor.ts @@ -97,6 +97,21 @@ export class SearchExecutor { ); } + if (searchQuery.delegationId) { + promises.push( + this.executeQuery( + this.apiService.delegationDetails(searchQuery.delegationId), + (response) => { + promisesResult = { + output: response.output, + error: response.error || response.message, + }; + }, + "Delegation id fetch failed", + ), + ); + } + await Promise.any(promises).catch((_) => {}); if (promisesResult !== null) {