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 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
52 changes: 44 additions & 8 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 @@ -263,6 +264,41 @@ export async function dispatchToChain(
}
}

/**
* 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 transactions permitted to be performed on the chain for the subspace.
* @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,
parent: SpaceUri,
creatorUri: DidUri,
signCallback: SignExtrinsicCallback
): Promise<SubmittableExtrinsic> {
try {
const api = ConfigService.get('api')

const tx = api.tx.chainSpace.subspaceCreate(chainSpace.digest, count, parent?.replace('space:cord:', ''))
const extrinsic = await Did.authorizeTx(
creatorUri,
tx,
signCallback,
authorAccount.address
)

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

/**
* Dispatches a Sub-ChainSpace creation transaction to the CORD blockchain.
*
Expand Down Expand Up @@ -309,16 +345,15 @@ export async function dispatchSubspaceCreateToChain(
}

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

const tx = api.tx.chainSpace.subspaceCreate(chainSpace.digest, count, parent?.replace('space:cord:', ''))
const extrinsic = await Did.authorizeTx(

const extrinsic = await prepareCreateSubSpaceExtrinsic(
chainSpace,
authorAccount,
count,
parent,
creatorUri,
tx,
signCallback,
authorAccount.address
signCallback
)

await Chain.signAndSubmitTx(extrinsic, authorAccount)

return returnObject;
Expand All @@ -330,6 +365,7 @@ export async function dispatchSubspaceCreateToChain(
}



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