OpChan/src/lib/identity/ordinal.ts
Ashis Kumar Naik c9e53ca285 dev: bypass verification in dev env
Signed-off-by: Ashis Kumar Naik <ashishami2002@gmail.com>
2025-06-18 18:59:29 +05:30

48 lines
1.5 KiB
TypeScript

import { OrdinalApiResponse } from './types';
const BASE_URL = 'https://exit-test-567058b69f45.herokuapp.com/api/operators/wallet';
export class OrdinalAPI {
/**
* Fetches Ordinal operator details for a given Bitcoin address.
* @param address - The Bitcoin address to query.
* @returns A promise that resolves with the API response.
*/
async getOperatorDetails(address: string): Promise<OrdinalApiResponse> {
// Optionally Uncomment to bypass verification in development mode
// if (process.env.NODE_ENV === 'development') {
// console.log(`[DEV] Bypassing ordinal verification for address: ${address}`);
// return {
// has_operators: true,
// error_message: '',
// data: []
// };
// }
const url = `${BASE_URL}/${address}/detail/`;
try {
const response = await fetch(url, {
method: 'GET',
headers: { 'Accept': 'application/json' },
});
if (!response.ok) {
const errorBody = await response.text().catch(() => '');
throw new Error(`HTTP error! status: ${response.status}, message: ${errorBody || response.statusText}`);
}
const data: OrdinalApiResponse = await response.json();
if (data.error_message) {
console.warn(`API returned an error message for address ${address}: ${data.error_message}`);
}
return data;
} catch (error) {
console.error(`Failed to fetch ordinal details for address ${address}:`, error);
throw error;
}
}
}