diff --git a/ironfish/src/assets/assetsVerificationApi.ts b/ironfish/src/assets/assetsVerificationApi.ts index f9b2dc0286..76eca40b40 100644 --- a/ironfish/src/assets/assetsVerificationApi.ts +++ b/ironfish/src/assets/assetsVerificationApi.ts @@ -47,13 +47,6 @@ export class VerifiedAssets { return verifiedAssets } - isVerified(assetId: Buffer | string): boolean { - if (!(typeof assetId === 'string')) { - assetId = assetId.toString('hex') - } - return this.assets.has(assetId) - } - getAssetData(assetId: Buffer | string): VerifiedAssetMetadata | undefined { if (!(typeof assetId === 'string')) { assetId = assetId.toString('hex') diff --git a/ironfish/src/assets/assetsVerifier.ts b/ironfish/src/assets/assetsVerifier.ts index 1720dbff88..5d7652adf7 100644 --- a/ironfish/src/assets/assetsVerifier.ts +++ b/ironfish/src/assets/assetsVerifier.ts @@ -16,7 +16,7 @@ import { export type AssetVerification = { status: 'verified' | 'unverified' | 'unknown' -} +} & Partial export class AssetsVerifier { private readonly REFRESH_INTERVAL = 6 * 60 * 60 * 1000 // 6 hours @@ -108,43 +108,26 @@ export class AssetsVerifier { return this.cache.save() } + getAssetData(assetId: Buffer | string): VerifiedAssetMetadata | undefined { + return this.verifiedAssets?.getAssetData(assetId) + } + verify(assetId: Buffer | string): AssetVerification { if (!this.verifiedAssets) { return { status: 'unknown' } } - if (this.verifiedAssets.isVerified(assetId)) { - return { status: 'verified' } + const assetData = this.getAssetData(assetId) + if (assetData) { + return { + status: 'verified', + symbol: assetData.symbol, + decimals: assetData.decimals, + logoURI: assetData.logoURI, + website: assetData.website, + } } else { return { status: 'unverified' } } } - - getAssetData(assetId: Buffer | string): VerifiedAssetMetadata | undefined { - return this.verifiedAssets?.getAssetData(assetId) - } - - verifyWithMetadata( - assetId: Buffer | string, - ): - | { verification: AssetVerification } - | ({ verification: AssetVerification } & AdditionalAssetData) { - const verification = this.verify(assetId) - if (verification.status === 'verified') { - const assetData = this.getAssetData(assetId) - if (assetData) { - return { - verification, - symbol: assetData.symbol, - decimals: assetData.decimals, - logoURI: assetData.logoURI, - website: assetData.website, - } - } - } - - return { - verification, - } - } } diff --git a/ironfish/src/rpc/routes/chain/getAsset.ts b/ironfish/src/rpc/routes/chain/getAsset.ts index 0fa28c044a..1a7135bf89 100644 --- a/ironfish/src/rpc/routes/chain/getAsset.ts +++ b/ironfish/src/rpc/routes/chain/getAsset.ts @@ -83,7 +83,7 @@ routes.register( owner: asset.owner.toString('hex'), supply: CurrencyUtils.encode(asset.supply), status: await getAssetStatus(node, asset), - ...node.assetsVerifier.verifyWithMetadata(asset.id), + verification: node.assetsVerifier.verify(asset.id), }) }, ) diff --git a/ironfish/src/rpc/routes/types.ts b/ironfish/src/rpc/routes/types.ts index 1405279e7f..4c7e1391b3 100644 --- a/ironfish/src/rpc/routes/types.ts +++ b/ironfish/src/rpc/routes/types.ts @@ -79,10 +79,6 @@ export type RpcAsset = { metadata: string createdTransactionHash: string verification: AssetVerification - symbol?: string - decimals?: number - logoURI?: string - website?: string supply?: string /** * @deprecated query for the transaction to find it's status @@ -98,16 +94,18 @@ export const RpcAssetSchema: yup.ObjectSchema = yup nonce: yup.number().required(), creator: yup.string().required(), verification: yup - .object({ status: yup.string().oneOf(['verified', 'unverified', 'unknown']).defined() }) + .object({ + status: yup.string().oneOf(['verified', 'unverified', 'unknown']).defined(), + symbol: yup.string().optional(), + decimals: yup.number().optional(), + logoURI: yup.string().optional(), + website: yup.string().optional(), + }) .defined(), status: yup.string().defined(), supply: yup.string().optional(), owner: yup.string().defined(), createdTransactionHash: yup.string().defined(), - symbol: yup.string().optional(), - decimals: yup.number().optional(), - logoURI: yup.string().optional(), - website: yup.string().optional(), }) .defined() diff --git a/ironfish/src/rpc/routes/wallet/burnAsset.ts b/ironfish/src/rpc/routes/wallet/burnAsset.ts index a55d3be276..286d5d35cd 100644 --- a/ironfish/src/rpc/routes/wallet/burnAsset.ts +++ b/ironfish/src/rpc/routes/wallet/burnAsset.ts @@ -109,7 +109,7 @@ routes.register( confirmations: request.data.confirmations, }), createdTransactionHash: asset.createdTransactionHash.toString('hex'), - ...context.assetsVerifier.verifyWithMetadata(asset.id), + verification: context.assetsVerifier.verify(asset.id), }, transaction: await serializeRpcWalletTransaction( context.config, diff --git a/ironfish/src/rpc/routes/wallet/getAsset.ts b/ironfish/src/rpc/routes/wallet/getAsset.ts index fa8b1dbfd8..70496ea324 100644 --- a/ironfish/src/rpc/routes/wallet/getAsset.ts +++ b/ironfish/src/rpc/routes/wallet/getAsset.ts @@ -63,7 +63,7 @@ routes.register( confirmations: request.data.confirmations, }), supply: asset.supply ? CurrencyUtils.encode(asset.supply) : undefined, - ...node.assetsVerifier.verifyWithMetadata(asset.id), + verification: node.assetsVerifier.verify(asset.id), }) }, ) diff --git a/ironfish/src/rpc/routes/wallet/getAssets.ts b/ironfish/src/rpc/routes/wallet/getAssets.ts index 9a2a744d06..0e51beb0d6 100644 --- a/ironfish/src/rpc/routes/wallet/getAssets.ts +++ b/ironfish/src/rpc/routes/wallet/getAssets.ts @@ -52,7 +52,7 @@ routes.register( }), supply: asset.supply !== null ? CurrencyUtils.encode(asset.supply) : undefined, createdTransactionHash: asset.createdTransactionHash.toString('hex'), - ...node.assetsVerifier.verifyWithMetadata(asset.id), + verification: node.assetsVerifier.verify(asset.id), }) } diff --git a/ironfish/src/rpc/routes/wallet/getBalance.ts b/ironfish/src/rpc/routes/wallet/getBalance.ts index 4ee4f2afe4..e308c0681d 100644 --- a/ironfish/src/rpc/routes/wallet/getBalance.ts +++ b/ironfish/src/rpc/routes/wallet/getBalance.ts @@ -84,7 +84,7 @@ routes.register( request.end({ account: account.name, assetId: assetId.toString('hex'), - assetVerification: node.assetsVerifier.verify(assetId), + assetVerification: { status: node.assetsVerifier.verify(assetId).status }, confirmed: balance.confirmed.toString(), unconfirmed: balance.unconfirmed.toString(), unconfirmedCount: balance.unconfirmedCount, diff --git a/ironfish/src/rpc/routes/wallet/getBalances.ts b/ironfish/src/rpc/routes/wallet/getBalances.ts index e5c28bf185..8281db9aae 100644 --- a/ironfish/src/rpc/routes/wallet/getBalances.ts +++ b/ironfish/src/rpc/routes/wallet/getBalances.ts @@ -109,7 +109,7 @@ routes.register( assetName: asset?.name.toString('hex') ?? '', assetCreator: asset?.creator.toString('hex') ?? '', assetOwner: asset?.owner.toString('hex') ?? '', - assetVerification: context.assetsVerifier.verify(balance.assetId), + assetVerification: { status: context.assetsVerifier.verify(balance.assetId).status }, blockHash: balance.blockHash?.toString('hex') ?? null, confirmed: CurrencyUtils.encode(balance.confirmed), sequence: balance.sequence, diff --git a/ironfish/src/rpc/routes/wallet/mintAsset.ts b/ironfish/src/rpc/routes/wallet/mintAsset.ts index ad674b271b..ee09163ffa 100644 --- a/ironfish/src/rpc/routes/wallet/mintAsset.ts +++ b/ironfish/src/rpc/routes/wallet/mintAsset.ts @@ -147,7 +147,7 @@ routes.register( confirmations: request.data.confirmations, }), createdTransactionHash: asset.createdTransactionHash.toString('hex'), - ...context.assetsVerifier.verifyWithMetadata(mint.asset.id()), + verification: context.assetsVerifier.verify(mint.asset.id()), }, transaction: await serializeRpcWalletTransaction( context.config,