@@ -35,6 +35,12 @@ import {
3535} from "@blockfrost/blockfrost-js" ;
3636import { InvalidIntegration , InvalidSignature } from "../errors/integrations" ;
3737import { ADDRESSES } from "../globals" ;
38+ import {
39+ CouldNotFetchSlot ,
40+ CouldNotFetchStakeAddress ,
41+ CouldNotHashStakeKey , NoRewardAddressFound ,
42+ NoStakeAddressFound , NotEnoughFunds ,
43+ } from "../errors/ada" ;
3844
3945const CARDANO_PARAMS = {
4046 COINS_PER_UTXO_WORD : '34482' ,
@@ -75,12 +81,12 @@ export class AdaService extends Service {
7581 const utxos = await this . getUtxos ( walletAddress ) ;
7682 const address = await this . client . addresses ( walletAddress ) ;
7783 if ( ! address . stake_address ) {
78- throw Error ( 'Could not fetch stake address' ) ;
84+ throw new CouldNotFetchStakeAddress ( 'Could not fetch stake address' ) ;
7985 }
8086
8187 const stakeKeyHash = await this . getStakeKeyHash ( address . stake_address ) ;
8288 if ( ! stakeKeyHash ) {
83- throw Error ( 'Could not hash stake key' ) ;
89+ throw new CouldNotHashStakeKey ( 'Could not hash stake key' ) ;
8490 }
8591 const certificates = Certificates . new ( ) ;
8692
@@ -136,19 +142,19 @@ export class AdaService extends Service {
136142 const utxos = await this . getUtxos ( walletAddress ) ;
137143 const address = await this . client . addresses ( walletAddress ) ;
138144 if ( ! address . stake_address ) {
139- throw Error ( 'No stake address' ) ;
145+ throw new NoStakeAddressFound ( 'No stake address' ) ;
140146 }
141147
142148 const stakeKeyHash = await this . getStakeKeyHash ( address . stake_address ) ;
143149 if ( ! stakeKeyHash ) {
144- throw Error ( 'Could not hash stake key' ) ;
150+ throw new CouldNotHashStakeKey ( 'Could not hash stake key' ) ;
145151 }
146152
147153 const withdrawals = Withdrawals . new ( ) ;
148154 const rewardAddress = RewardAddress . from_address ( Address . from_bech32 ( address . stake_address ) ) ;
149155
150156 if ( ! rewardAddress ) {
151- throw Error ( 'Could not retrieve rewards address' ) ;
157+ throw new NoRewardAddressFound ( 'Could not retrieve rewards address' ) ;
152158 }
153159
154160 const availableRewards = await this . getAvailableRewards ( address . stake_address ) ;
@@ -178,19 +184,19 @@ export class AdaService extends Service {
178184 const utxos = await this . getUtxos ( walletAddress ) ;
179185 const address = await this . client . addresses ( walletAddress ) ;
180186 if ( ! address . stake_address ) {
181- throw Error ( 'No stake address' ) ;
187+ throw new NoStakeAddressFound ( 'No stake address' ) ;
182188 }
183189
184190 const stakeKeyHash = await this . getStakeKeyHash ( address . stake_address ) ;
185191 if ( ! stakeKeyHash ) {
186- throw Error ( 'Could not hash stake key' ) ;
192+ throw new CouldNotHashStakeKey ( 'Could not hash stake key' ) ;
187193 }
188194
189195 const withdrawals = Withdrawals . new ( ) ;
190196 const rewardAddress = RewardAddress . from_address ( Address . from_bech32 ( address . stake_address ) ) ;
191197
192198 if ( ! rewardAddress ) {
193- throw Error ( 'Could not retrieve rewards address' ) ;
199+ throw new NoRewardAddressFound ( 'Could not retrieve rewards address' ) ;
194200 }
195201
196202
@@ -306,7 +312,7 @@ export class AdaService extends Service {
306312 const latestBlock = await this . client . blocksLatest ( ) ;
307313 const currentSlot = latestBlock . slot ;
308314 if ( ! currentSlot ) {
309- throw Error ( 'Failed to fetch slot number' ) ;
315+ throw new CouldNotFetchSlot ( 'Failed to fetch slot number' ) ;
310316 }
311317 // Current slot + 2h
312318 const ttl = currentSlot + 7200 ;
@@ -332,7 +338,7 @@ export class AdaService extends Service {
332338 utxo = await this . client . addressesUtxos ( walletAddress ) ;
333339 } catch ( error ) {
334340 if ( error instanceof BlockfrostServerError && error . status_code === 404 ) {
335- throw new Error ( `You should send ADA to ${ walletAddress } to have enough funds to sent a transaction` ) ;
341+ throw new NotEnoughFunds ( `You should send ADA to ${ walletAddress } to have enough funds to sent a transaction` ) ;
336342 } else {
337343 throw error ;
338344 }
0 commit comments