Skip to content

Commit

Permalink
refactor: remove comment code and error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
bucurdavid committed Sep 21, 2023
1 parent 61a5b65 commit df88714
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 63 deletions.
12 changes: 1 addition & 11 deletions src/common/mint-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,10 @@ export async function dataNFTDataStreamAdvertise(
dataNftStreamUrlEncrypted: data.encryptedMessage
};
} else {
throw new Error('Issue with data marshal generate payload');
// throw new ErrFailedOperation(this.dataNFTDataStreamAdvertise.name);
throw new Error('Issue with data marshal generating payload');
}
} catch (error) {
throw error;
// if (error instanceof Error) {
// throw new ErrFailedOperation(
// this.dataNFTDataStreamAdvertise.name,
// error
// );
// } else {
// throw new ErrFailedOperation(this.dataNFTDataStreamAdvertise.name);
// }
}
}

Expand All @@ -54,7 +45,6 @@ export async function storeToIpfs(
res = await nftstorage.storeDirectory(dir);
} catch (error) {
throw error;
// throw new ErrFailedOperation(this.storeToIpfs.name);
}
return {
imageOnIpfsUrl: `https://ipfs.io/ipfs/${res}/image.png`,
Expand Down
3 changes: 2 additions & 1 deletion src/minter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ export abstract class Minter {
return new BooleanValue(returnValue).valueOf();
} else {
throw new ErrContractQuery(
'Error while retrieving the contract pause state'
'viewContractPauseState',
returnCode.toString()
);
}
}
Expand Down
47 changes: 17 additions & 30 deletions src/nft-minter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ import {
storeToIpfs
} from './common/mint-utils';
import { ContractConfiguration } from './interfaces';
import { ErrArgumentNotSet } from './errors';
import {
ErrArgumentNotSet,
ErrAttributeNotSet,
ErrContractQuery
} from './errors';

export class NftMinter extends Minter {
/**
Expand Down Expand Up @@ -206,10 +210,6 @@ export class NftMinter extends Minter {

if (!allPassed) {
throw new Error(`Params have validation issues = ${validationMessages}`);
// throw new ErrFailedOperation(
// this.mint.name,
// new Error(`params have validation issues = ${validationMessages}`)
// );
}
// E: run any format specific validation...

Expand All @@ -220,11 +220,6 @@ export class NftMinter extends Minter {
await checkUrlIsUp(dataMarshalUrl + '/health-check', [200]);
} catch (error) {
throw error;
// if (error instanceof Error) {
// throw new ErrFailedOperation(this.mint.name, error);
// } else {
// throw new ErrFailedOperation(this.mint.name);
// }
}

let imageOnIpfsUrl: string;
Expand Down Expand Up @@ -257,11 +252,10 @@ export class NftMinter extends Minter {
metadataOnIpfsUrl = metadataIpfsUrl;
} else {
if (!traitsUrl) {
throw new Error('Traits URL is required when using custom image');
// throw new ErrArgumentNotSet(
// 'traitsUrl',
// 'Traits URL is required when using custom image'
// );
throw new ErrArgumentNotSet(
'traitsUrl',
'Traits URL is required when using custom image'
);
}

await checkTraitsUrl(traitsUrl);
Expand Down Expand Up @@ -459,10 +453,10 @@ export class NftMinter extends Minter {
};
return contractConfiguration;
} else {
throw new Error('Error while retrieving the contract pause state');
// throw new ErrContractQuery(
// 'Error while retrieving the contract pause state'
// );
throw new ErrContractQuery(
'viewContractConfiguration',
returnCode.toString()
);
}
}

Expand All @@ -486,12 +480,7 @@ export class NftMinter extends Minter {
);
return addressesWithTransferRole;
} else {
throw new Error(
'Error while retrieving the addresses with transfer roles'
);
// throw new ErrContractQuery(
// 'Error while retrieving the addresses with transfer roles'
// );
throw new ErrContractQuery('viewTransferRoles', returnCode.toString());
}
}

Expand All @@ -515,12 +504,10 @@ export class NftMinter extends Minter {
);
return addressesWithUpdateAttributesRole;
} else {
throw new Error(
'Error while retrieving the addresses with update attributes roles'
throw new ErrContractQuery(
'viewUpdateAttributesRoles',
returnCode.toString()
);
// throw new ErrContractQuery(
// 'Error while retrieving the addresses with update attributes roles'
// );
}
}
}
28 changes: 7 additions & 21 deletions src/sft-minter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
dataNFTDataStreamAdvertise,
storeToIpfs
} from './common/mint-utils';
import { ErrArgumentNotSet } from './errors';

export class SftMinter extends Minter {
/**
Expand All @@ -44,8 +45,6 @@ export class SftMinter extends Minter {
);
}

// [TO DO] Initialize the contract for sft minter

/**
* Creates an initialize contract transaction for the contract
* @param senderAddress The address of the sender, must be the admin of the contract
Expand Down Expand Up @@ -202,10 +201,6 @@ export class SftMinter extends Minter {

if (!allPassed) {
throw new Error(`Params have validation issues = ${validationMessages}`);
// throw new ErrFailedOperation(
// this.mint.name,
// new Error(`params have validation issues = ${validationMessages}`)
// );
}
// E: run any format specific validation...

Expand All @@ -216,11 +211,6 @@ export class SftMinter extends Minter {
await checkUrlIsUp(dataMarshalUrl + '/health-check', [200]);
} catch (error) {
throw error;
// if (error instanceof Error) {
// throw new ErrFailedOperation(this.mint.name, error);
// } else {
// throw new ErrFailedOperation(this.mint.name);
// }
}

let imageOnIpfsUrl: string;
Expand All @@ -231,13 +221,10 @@ export class SftMinter extends Minter {

if (!imageUrl) {
if (!nftStorageToken) {
throw new Error(
throw new ErrArgumentNotSet(
'nftStorageToken',
'NFT Storage token is required when not using custom image and traits'
);
// throw new ErrArgumentNotSet(
// 'nftStorageToken',
// 'NFT Storage token is required when not using custom image and traits'
// );
}
const { image, traits } = await createFileFromUrl(
`${this.imageServiceUrl}/v1/generateNFTArt?hash=${dataNftHash}`,
Expand All @@ -256,11 +243,10 @@ export class SftMinter extends Minter {
metadataOnIpfsUrl = metadataIpfsUrl;
} else {
if (!traitsUrl) {
throw new Error('Traits URL is required when using custom image');
// throw new ErrArgumentNotSet(
// 'traitsUrl',
// 'Traits URL is required when using custom image'
// );
throw new ErrArgumentNotSet(
'traitsUrl',
'Traits URL is required when using custom image'
);
}

await checkTraitsUrl(traitsUrl);
Expand Down
File renamed without changes.

0 comments on commit df88714

Please sign in to comment.