From afefe63c45eac5f7486005afa85f1b765e5267f7 Mon Sep 17 00:00:00 2001 From: SHARJIDH Date: Sat, 27 Apr 2024 04:28:17 +0530 Subject: [PATCH] asset: prepareCreateExtrinsic made as a separate method fixes: #209 --- packages/asset/src/Asset.chain.ts | 35 +++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/packages/asset/src/Asset.chain.ts b/packages/asset/src/Asset.chain.ts index 8b63a394..e0688f67 100644 --- a/packages/asset/src/Asset.chain.ts +++ b/packages/asset/src/Asset.chain.ts @@ -42,28 +42,51 @@ export async function isAssetStored(assetUri: AssetUri): Promise { ) } } - -export async function dispatchCreateToChain( +export async function prepareCreateExtrinsic( assetEntry: IAssetEntry, authorAccount: CordKeyringPair, authorizationUri: AuthorizationUri, 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.create( assetEntry.entry, assetEntry.digest, authorizationId - ) + ); const extrinsic = await Did.authorizeTx( assetEntry.creator, tx, signCallback, authorAccount.address + ); + + return extrinsic; + } catch (error) { + const errorMessage = + error instanceof Error ? error.message : JSON.stringify(error); + throw new SDKErrors.CordDispatchError( + `Error preparing extrinsic: "${errorMessage}".` + ); + } +} +export async function dispatchCreateToChain( + assetEntry: IAssetEntry, + authorAccount: CordKeyringPair, + authorizationUri: AuthorizationUri, + signCallback: SignExtrinsicCallback +): Promise { + try { + + const extrinsic = await prepareCreateExtrinsic( + assetEntry, + authorAccount, + authorizationUri, + signCallback ) await Chain.signAndSubmitTx(extrinsic, authorAccount)