From 4022daf5d8315fed23c0b4ca7081840c990a4ad1 Mon Sep 17 00:00:00 2001 From: Mohammed Ismail Date: Tue, 30 Apr 2024 09:59:27 +0530 Subject: [PATCH 1/3] solves issue : 213 --- packages/asset/src/Asset.chain.ts | 66 ++++++++++++++++++++----------- 1 file changed, 44 insertions(+), 22 deletions(-) diff --git a/packages/asset/src/Asset.chain.ts b/packages/asset/src/Asset.chain.ts index 3ccc3ea6..69b06b16 100644 --- a/packages/asset/src/Asset.chain.ts +++ b/packages/asset/src/Asset.chain.ts @@ -78,24 +78,19 @@ export async function dispatchCreateToChain( } } -export async function dispatchCreateVcToChain( +export async function prepareCreateVcExtrinsic( assetQty: number, digest: string, creator: DidUri, authorAccount: CordKeyringPair, authorizationUri: AuthorizationUri, - assetEntryUri: AssetUri, signCallback: SignExtrinsicCallback -): Promise { +): Promise { try { - const api = ConfigService.get('api') - const authorizationId: AuthorizationId = uriToIdentifier(authorizationUri) + const api = ConfigService.get('api'); + const authorizationId: AuthorizationId = uriToIdentifier(authorizationUri); - const tx = api.tx.asset.vcCreate( - assetQty, - digest, - authorizationId - ) + const tx = api.tx.asset.vcCreate(assetQty, digest, authorizationId); const extrinsic = await Did.authorizeTx( creator, @@ -103,19 +98,46 @@ export async function dispatchCreateVcToChain( signCallback, authorAccount.address ) + return extrinsic; + } catch (error) { + const errorMessage = + error instanceof Error ? error.message : JSON.stringify(error); + throw new SDKErrors.CordDispatchError( + `Error preparing VC Asset Entry extrinsic: "${errorMessage}".` + ); + } +} - await Chain.signAndSubmitTx(extrinsic, authorAccount) - return assetEntryUri +export async function dispatchCreateVcToChain( + assetQty: number, + digest: string, + creator: DidUri, + authorAccount: CordKeyringPair, + authorizationUri: AuthorizationUri, + assetEntryUri: AssetUri, + signCallback: SignExtrinsicCallback +): Promise { + try { + const extrinsic = await prepareCreateVcExtrinsic( + assetQty, + digest, + creator, + authorizationUri, + signCallback + ); + + await Chain.signAndSubmitTx(extrinsic, authorAccount); + + return assetEntryUri; } catch (error) { const errorMessage = - error instanceof Error ? error.message : JSON.stringify(error) + error instanceof Error ? error.message : JSON.stringify(error); throw new SDKErrors.CordDispatchError( `Error dispatching to chain: "${errorMessage}".` - ) + ); } } - export async function prepareExtrinsic( assetEntry: IAssetIssuance, authorAccount: CordKeyringPair, @@ -142,8 +164,8 @@ export async function prepareExtrinsic( return extrinsic } catch (error) { - const errorMessage = - error instanceof Error ? error.message : JSON.stringify(error) + const errorMessage = + error instanceof Error ? error.message : JSON.stringify(error) throw new SDKErrors.CordDispatchError( `Error preparing extrinsic: "${errorMessage}".` ) @@ -158,7 +180,7 @@ export async function dispatchIssueToChain( ): Promise { try { - const extrinsic = await prepareExtrinsic(assetEntry, authorAccount, authorizationUri, signCallback) + const extrinsic = await prepareExtrinsic(assetEntry, authorAccount, authorizationUri, signCallback) await Chain.signAndSubmitTx(extrinsic, authorAccount) return assetEntry.uri @@ -197,8 +219,8 @@ export async function prepareVcExtrinsic( return extrinsic } catch (error) { - const errorMessage = - error instanceof Error ? error.message : JSON.stringify(error) + const errorMessage = + error instanceof Error ? error.message : JSON.stringify(error) throw new SDKErrors.CordDispatchError( `Error preparing extrinsic: "${errorMessage}".` ) @@ -213,7 +235,7 @@ export async function dispatchIssueVcToChain( ): Promise { try { - const extrinsic = await prepareVcExtrinsic(assetEntry, authorAccount, authorizationUri, signCallback) + const extrinsic = await prepareVcExtrinsic(assetEntry, authorAccount, authorizationUri, signCallback) await Chain.signAndSubmitTx(extrinsic, authorAccount) return assetEntry.uri @@ -366,7 +388,7 @@ export async function dispatchAssetStatusChangeVcToChain( try { const api = ConfigService.get('api') let tx - + /* Check if assetStatusType is undefined */ if (newStatus === undefined) { throw new SDKErrors.InvalidAssetStatus("Asset status is undefined."); From 0708c96a4d0acac5627a546b27ac7254de91efd3 Mon Sep 17 00:00:00 2001 From: Mohammed Ismail Date: Tue, 30 Apr 2024 11:03:05 +0530 Subject: [PATCH 2/3] yarn and yarn build passing, linting done --- packages/asset/src/Asset.chain.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/asset/src/Asset.chain.ts b/packages/asset/src/Asset.chain.ts index 69b06b16..9ddda65d 100644 --- a/packages/asset/src/Asset.chain.ts +++ b/packages/asset/src/Asset.chain.ts @@ -108,7 +108,6 @@ export async function prepareCreateVcExtrinsic( } } - export async function dispatchCreateVcToChain( assetQty: number, digest: string, @@ -123,6 +122,7 @@ export async function dispatchCreateVcToChain( assetQty, digest, creator, + authorAccount, authorizationUri, signCallback ); @@ -138,6 +138,7 @@ export async function dispatchCreateVcToChain( ); } } + export async function prepareExtrinsic( assetEntry: IAssetIssuance, authorAccount: CordKeyringPair, From 8eb6d52dcacb65ff0d752250891718e35e8b909e Mon Sep 17 00:00:00 2001 From: Mohammed Ismail Date: Wed, 1 May 2024 09:17:09 +0530 Subject: [PATCH 3/3] fixed failing tests --- packages/asset/src/Asset.chain.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/asset/src/Asset.chain.ts b/packages/asset/src/Asset.chain.ts index 6c55d145..b06f66b1 100644 --- a/packages/asset/src/Asset.chain.ts +++ b/packages/asset/src/Asset.chain.ts @@ -427,8 +427,12 @@ export async function dispatchAssetStatusChangeVcToChain( assetInstanceId?: string ): Promise { try { - const api = ConfigService.get('api') - let tx + const api = ConfigService.get("api"); + let tx; + const assetId = uriToIdentifier(assetUri); + const assetIssuerDid = Did.toChain(assetIssuerDidUri); + + assetInstanceId = assetInstanceId?.split(":").pop(); /* Check if assetStatusType is undefined */ if (newStatus === undefined) {