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

Created of new export function named prepareCreateExtrinsic() #211

Merged
merged 1 commit into from
Apr 30, 2024
Merged
Changes from all commits
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
35 changes: 30 additions & 5 deletions packages/asset/src/Asset.chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,27 +43,52 @@ export async function isAssetStored(assetUri: AssetUri): Promise<boolean> {
}
}

export async function dispatchCreateToChain(
export async function prepareCreateExtrinsic(
assetEntry: IAssetEntry,
authorAccount: CordKeyringPair,
authorizationUri: AuthorizationUri,
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.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<AssetUri> {
try {

const extrinsic = await prepareCreateExtrinsic(
assetEntry,
authorAccount,
authorizationUri,
signCallback
)

await Chain.signAndSubmitTx(extrinsic, authorAccount)
Expand Down