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 new function prepareCreateSubSpaceExtrinsic() #206

Merged
merged 2 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
44 changes: 40 additions & 4 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 @@ -308,6 +309,42 @@ export async function dispatchSubspaceCreateToChain(
authorization: chainSpace.authorizationUri,
}

try {

const extrinsic = await prepareCreateSubSpaceExtrinsic(
chainSpace,
authorAccount,
count,
parent,
creatorUri,
signCallback
)
await Chain.signAndSubmitTx(extrinsic, authorAccount)

return returnObject;
} catch (error) {
throw new SDKErrors.CordDispatchError(
`Error dispatching to chain: "${error}".`
)
}
}

/**
* Prepares the creation of a sub-space extrinsic for later dispatch to the blockchain.
* @param chainSpace - The ChainSpace object containing necessary information for creating the ChainSpace on the blockchain.
* @param authorAccount - The blockchain account used for signing and submitting the transaction.
* @param count - The count of subspaces to be created.
* @param creatorUri - The DID URI of the creator, used to authorize the transaction.
* @returns The prepared extrinsic ready for batch signing and submitting.
*/
export async function prepareCreateSubSpaceExtrinsic(
chainSpace: IChainSpace,
authorAccount: CordKeyringPair,
count: number,
Copy link
Member

@vatsa287 vatsa287 Apr 22, 2024

Choose a reason for hiding this comment

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

count here refers to count of transactions permitted to be performed on the chain for the subspace.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated, thanks for the review!

parent: SpaceUri,
creatorUri: DidUri,
signCallback: SignExtrinsicCallback
): Promise<SubmittableExtrinsic> {
try {
const api = ConfigService.get('api')

Expand All @@ -319,17 +356,16 @@ export async function dispatchSubspaceCreateToChain(
authorAccount.address
)

await Chain.signAndSubmitTx(extrinsic, authorAccount)

return returnObject;
return extrinsic;
} catch (error) {
throw new SDKErrors.CordDispatchError(
`Error dispatching to chain: "${error}".`
`Error preparing extrinsic: "${error}".`
)
}
}



/**
* Approves a ChainSpace on the CORD blockchain using sudo privileges.
*
Expand Down