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

ChainSpace: Separate preparation of create chainspace extrinsic from chain dispatch Issue #197 #203

Merged
merged 3 commits into from
Apr 29, 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
42 changes: 29 additions & 13 deletions packages/chain-space/src/ChainSpace.chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import type {
SpaceDigest,
AuthorizationUri,
SpaceUri,
SubmittableExtrinsic
} from '@cord.network/types'
import { SDKErrors, DecoderUtils } from '@cord.network/utils'
import {
Expand Down Expand Up @@ -240,20 +241,9 @@ export async function dispatchToChain(
}

try {
const api = ConfigService.get('api')

const exists = await isChainSpaceStored(chainSpace.uri)
if (!exists) {
const tx = api.tx.chainSpace.create(chainSpace.digest)
const extrinsic = await Did.authorizeTx(
creatorUri,
tx,
signCallback,
authorAccount.address
)

await Chain.signAndSubmitTx(extrinsic, authorAccount)
}
const extrinsic = await prepareCreateSpaceExtrinsic(chainSpace, creatorUri, signCallback, authorAccount)
await Chain.signAndSubmitTx(extrinsic, authorAccount)

return returnObject
} catch (error) {
Expand All @@ -263,6 +253,32 @@ export async function dispatchToChain(
}
}

export async function prepareCreateSpaceExtrinsic(
chainSpace: IChainSpace,
creatorUri: DidUri,
signCallback: SignExtrinsicCallback,
authorAccount: CordKeyringPair
): Promise<SubmittableExtrinsic> {
try {
const api = ConfigService.get('api')

const tx = api.tx.chainSpace.create(chainSpace.digest)
const extrinsic = await Did.authorizeTx(
creatorUri,
tx,
signCallback,
authorAccount.address
)
return extrinsic;


} catch (error) {
throw new SDKErrors.CordDispatchError(
`Error preparing extrinsic for creation: "${error}".`
Copy link
Member

Choose a reason for hiding this comment

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

nit: Error preparing extrinsic for creation of chainspace

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

);
}
}

/**
* Dispatches a Sub-ChainSpace creation transaction to the CORD blockchain.
*
Expand Down