From 7e1d801ac0712e080023e0115dd173299c369ad1 Mon Sep 17 00:00:00 2001 From: leo42 Date: Mon, 21 Aug 2023 12:51:31 +0200 Subject: [PATCH 1/2] Resolve CIP-68 Handles --- server/utils/helpers.ts | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/server/utils/helpers.ts b/server/utils/helpers.ts index 0e05209d..9d82c7f1 100644 --- a/server/utils/helpers.ts +++ b/server/utils/helpers.ts @@ -70,21 +70,31 @@ export async function translateAdaHandle( "Handle is malformed" ); } - const handleInHex = Buffer.from(handle).toString("hex"); - const url = `${koiosUrl}/asset_address_list?_asset_policy=${policyId}&_asset_name=${handleInHex}`; - - const data = (await axios.get(url)).data; - - if (data.length === 0) { - throw createErrorWithCode( - HttpStatusCode.NOT_FOUND, - "Handle does not exist" - ); + const address222 = await resolveAddress("000de140"+handleInHex); + if (address222) return address222; + const address314 = await resolveAddress("0013ab30"+handleInHex); + if (address314) return address314; + + const address = await resolveAddress(handleInHex); + if (address) return address; else throw createErrorWithCode( + HttpStatusCode.NOT_FOUND, + "Handle does not exist" + ); + + + async function resolveAddress(handleInHex: string){ + const url = `${koiosUrl}/asset_address_list?_asset_policy=${policyId}&_asset_name=${handleInHex}`; + + const data = (await axios.get(url)).data; + + if (data.length === 0) { + return null; + } + + const address = data[0].payment_address; + return address; } - - const address = data[0].payment_address; - return address; } export async function getFromVM(params: any) { From 5f049de473201475b535adc243538d65280ef16d Mon Sep 17 00:00:00 2001 From: leo42 Date: Mon, 21 Aug 2023 22:46:35 +0200 Subject: [PATCH 2/2] Update helpers.ts --- server/utils/helpers.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/server/utils/helpers.ts b/server/utils/helpers.ts index 9d82c7f1..c228ba67 100644 --- a/server/utils/helpers.ts +++ b/server/utils/helpers.ts @@ -47,7 +47,7 @@ export async function translateAdaHandle( network: any, koiosUrl: string ) { - let urlPrefix, policyId; + let urlPrefix, policyId : string; handle = handle.toLowerCase(); @@ -70,20 +70,20 @@ export async function translateAdaHandle( "Handle is malformed" ); } - const handleInHex = Buffer.from(handle).toString("hex"); - const address222 = await resolveAddress("000de140"+handleInHex); + const handleInHex : string = Buffer.from(handle).toString("hex"); + const address222 : string = await resolveAddress("000de140"+handleInHex, policyId , koiosUrl); if (address222) return address222; - const address314 = await resolveAddress("0013ab30"+handleInHex); - if (address314) return address314; + const address314 : string = await resolveAddress("0013ab30"+handleInHex , policyId , koiosUrl); + if (address314) return address314; - const address = await resolveAddress(handleInHex); + const address = await resolveAddress(handleInHex , policyId , koiosUrl); if (address) return address; else throw createErrorWithCode( HttpStatusCode.NOT_FOUND, "Handle does not exist" ); - async function resolveAddress(handleInHex: string){ + async function resolveAddress(handleInHex: string , policyId: string , koiosUrl: string ){ const url = `${koiosUrl}/asset_address_list?_asset_policy=${policyId}&_asset_name=${handleInHex}`; const data = (await axios.get(url)).data;