Skip to content

Commit

Permalink
Asset: Separate preparation of creation of VC Asset from dispatch (#215)
Browse files Browse the repository at this point in the history
  • Loading branch information
masterismail authored Jul 10, 2024
1 parent a7befe0 commit ce90fc4
Showing 1 changed file with 44 additions and 21 deletions.
65 changes: 44 additions & 21 deletions packages/asset/src/Asset.chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export async function dispatchCreateToChain(
signCallback: SignExtrinsicCallback
): Promise<AssetUri> {
try {

const extrinsic = await prepareCreateExtrinsic(
assetEntry,
authorAccount,
Expand All @@ -103,41 +103,64 @@ 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<AssetUri> {
): Promise<SubmittableExtrinsic> {
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,
tx,
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)
export async function dispatchCreateVcToChain(
assetQty: number,
digest: string,
creator: DidUri,
authorAccount: CordKeyringPair,
authorizationUri: AuthorizationUri,
assetEntryUri: AssetUri,
signCallback: SignExtrinsicCallback
): Promise<AssetUri> {
try {
const extrinsic = await prepareCreateVcExtrinsic(
assetQty,
digest,
creator,
authorAccount,
authorizationUri,
signCallback
);

await Chain.signAndSubmitTx(extrinsic, authorAccount);

return assetEntryUri
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}".`
)
);
}
}

Expand Down Expand Up @@ -167,8 +190,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}".`
)
Expand All @@ -183,7 +206,7 @@ export async function dispatchIssueToChain(
): Promise<AssetUri> {
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
Expand Down Expand Up @@ -222,8 +245,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}".`
)
Expand All @@ -238,7 +261,7 @@ export async function dispatchIssueVcToChain(
): Promise<AssetUri> {
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
Expand Down

0 comments on commit ce90fc4

Please sign in to comment.