Skip to content

Commit

Permalink
Fixes dhiway#197
Browse files Browse the repository at this point in the history
  • Loading branch information
hardiksharma11 committed Apr 12, 2024
1 parent 340f366 commit fcf81e1
Showing 1 changed file with 29 additions and 13 deletions.
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}".`
);
}
}

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

0 comments on commit fcf81e1

Please sign in to comment.