Skip to content

Commit

Permalink
asset: Separate prepareCreateExtrinsic from dispatch to chain (#211)
Browse files Browse the repository at this point in the history
fixes: #209
  • Loading branch information
SHARJIDH authored Apr 30, 2024
1 parent b4a3392 commit 7b2d45d
Showing 1 changed file with 30 additions and 5 deletions.
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

0 comments on commit 7b2d45d

Please sign in to comment.