Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Asset: Separate preparation of creation of VC Asset from dispatch #215

Merged
merged 4 commits into from
Jul 10, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 44 additions & 22 deletions packages/asset/src/Asset.chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,44 +78,66 @@ 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)

return assetEntryUri
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,
authorizationUri,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prepareVcExtrinsic expects authorAccount as a parameter after creator, which is missing while calling the method.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done !

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,
Expand All @@ -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}".`
)
Expand All @@ -158,7 +180,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 @@ -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}".`
)
Expand All @@ -213,7 +235,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 Expand Up @@ -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.");
Expand Down
Loading