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 a new function prepareUpdateTxCapacityExtrinsic() #205

Merged
merged 1 commit 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
50 changes: 40 additions & 10 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 @@ -779,6 +780,43 @@ export async function fetchAuthorizationFromChain(
}
}

/**
* Prepares an update transaction capacity extrinsic for later dispatch to the blockchain.
* @param spaceUri - The URI of the space to update transaction capacity.
* @param new_capacity - The new capacity to be updated.
* @param creatorUri - The DID URI of the creator, used to authorize the transaction.
* @param signCallback - The callback function for signing the transaction.
* @param authorAccount - The blockchain account used for signing and submitting the transaction.
* @returns The prepared extrinsic ready for batch signing and submitting.
*/

export async function prepareUpdateTxCapacityExtrinsic(
spaceUri: SpaceUri,
new_capacity: number,
creatorUri: DidUri,
signCallback: SignExtrinsicCallback,
authorAccount: CordKeyringPair
): Promise<SubmittableExtrinsic> {
try {
const api = ConfigService.get('api')

const tx = api.tx.chainSpace.updateTransactionCapacitySub(spaceUri.replace('space:cord:', ''), new_capacity)
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 @@ -823,16 +861,7 @@ export async function dispatchUpdateTxCapacityToChain(
}

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

const tx = api.tx.chainSpace.updateTransactionCapacitySub(space.replace('space:cord:', ''), new_capacity)
const extrinsic = await Did.authorizeTx(
creatorUri,
tx,
signCallback,
authorAccount.address
)

const extrinsic = await prepareUpdateTxCapacityExtrinsic(space, new_capacity, creatorUri, signCallback, authorAccount)
await Chain.signAndSubmitTx(extrinsic, authorAccount)

return returnObject;
Expand All @@ -842,3 +871,4 @@ export async function dispatchUpdateTxCapacityToChain(
)
}
}