Skip to content

Commit

Permalink
asset: prepareCreateExtrinsic made as a separate method
Browse files Browse the repository at this point in the history
fixes: #209
  • Loading branch information
SHARJIDH authored and amarts committed Apr 29, 2024
1 parent 340f366 commit afefe63
Showing 1 changed file with 29 additions and 6 deletions.
35 changes: 29 additions & 6 deletions packages/asset/src/Asset.chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,28 +42,51 @@ 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 afefe63

Please sign in to comment.