@cardano-sdk/blockfrost
Advanced tools
Comparing version 0.1.3 to 0.1.4
{ | ||
"name": "@cardano-sdk/blockfrost", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"description": "Blockfrost provider for Cardano JS SDK", | ||
@@ -27,4 +27,4 @@ "engines": { | ||
"@cardano-ogmios/schema": "4.1.0", | ||
"@cardano-sdk/core": "0.1.3" | ||
"@cardano-sdk/core": "0.1.4" | ||
} | ||
} |
@@ -1,6 +0,50 @@ | ||
import { CardanoProvider } from '@cardano-sdk/core'; | ||
import { BlockFrostAPI } from '@blockfrost/blockfrost-js'; | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
import { CardanoProvider, ProviderError, ProviderFailure } from '@cardano-sdk/core'; | ||
import { BlockFrostAPI, Error as BlockfrostError } from '@blockfrost/blockfrost-js'; | ||
import { Options } from '@blockfrost/blockfrost-js/lib/types'; | ||
import { BlockfrostToOgmios } from './BlockfrostToOgmios'; | ||
const formatBlockfrostError = (error: unknown) => { | ||
const blockfrostError = error as BlockfrostError; | ||
if (typeof blockfrostError === 'string') { | ||
throw new ProviderError(ProviderFailure.Unknown, error, blockfrostError); | ||
} | ||
if (typeof blockfrostError !== 'object') { | ||
throw new ProviderError(ProviderFailure.Unknown, error, 'failed to parse error (response type)'); | ||
} | ||
const errorAsType1 = blockfrostError as { | ||
status_code: number; | ||
message: string; | ||
error: string; | ||
}; | ||
if (errorAsType1.status_code) { | ||
return errorAsType1; | ||
} | ||
const errorAsType2 = blockfrostError as { | ||
errno: number; | ||
message: string; | ||
code: string; | ||
}; | ||
if (errorAsType2.code) { | ||
const status_code = Number.parseInt(errorAsType2.code); | ||
if (!status_code) { | ||
throw new ProviderError(ProviderFailure.Unknown, error, 'failed to parse error (status code)'); | ||
} | ||
return { | ||
status_code, | ||
message: errorAsType1.message, | ||
error: errorAsType2.errno.toString() | ||
}; | ||
} | ||
throw new ProviderError(ProviderFailure.Unknown, error, 'failed to parse error (response json)'); | ||
}; | ||
const toProviderError = (error: unknown) => { | ||
const { status_code } = formatBlockfrostError(error); | ||
if (status_code === 404) { | ||
throw new ProviderError(ProviderFailure.NotFound); | ||
} | ||
throw new ProviderError(ProviderFailure.Unknown, error, `status_code: ${status_code}`); | ||
}; | ||
/** | ||
@@ -12,3 +56,2 @@ * Connect to the [Blockfrost service](https://docs.blockfrost.io/) | ||
*/ | ||
export const blockfrostProvider = (options: Options): CardanoProvider => { | ||
@@ -66,9 +109,3 @@ const blockfrost = new BlockFrostAPI(options); | ||
const submitTx: CardanoProvider['submitTx'] = async (signedTransaction) => { | ||
try { | ||
const hash = await blockfrost.txSubmit(signedTransaction.to_bytes()); | ||
return !!hash; | ||
} catch { | ||
return false; | ||
} | ||
await blockfrost.txSubmit(signedTransaction.to_bytes()); | ||
}; | ||
@@ -121,3 +158,3 @@ | ||
return { | ||
const providerFunctions = { | ||
ledgerTip, | ||
@@ -131,3 +168,8 @@ networkInfo, | ||
currentWalletProtocolParameters | ||
}; | ||
} as any; | ||
return Object.keys(providerFunctions).reduce((provider, key) => { | ||
provider[key] = (...args: any[]) => providerFunctions[key](...args).catch(toProviderError); | ||
return provider; | ||
}, {} as any) as CardanoProvider; | ||
}; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
26395
11
675
+ Added@cardano-sdk/core@0.1.4(transitive)
- Removed@cardano-sdk/core@0.1.3(transitive)
Updated@cardano-sdk/core@0.1.4