Skip to content

Commit

Permalink
feat: Seperated creation of extrinsic from
Browse files Browse the repository at this point in the history
Signed-off-by: vikastc <[email protected]>
  • Loading branch information
Vikastc committed Mar 11, 2024
1 parent 83e0dcf commit 0e56e79
Showing 1 changed file with 27 additions and 16 deletions.
43 changes: 27 additions & 16 deletions packages/statement/src/Statement.chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,32 @@ export async function dispatchRegisterToChain(
}
}

async function createExtrinsic(
stmtEntry: IStatementEntry,
authorizationId: AuthorizationId
) {
const api = ConfigService.get('api')

const schemaId =
stmtEntry.schemaUri !== undefined
? stmtEntry.schemaUri && uriToIdentifier(stmtEntry.schemaUri)
: undefined

const exists = await isStatementStored(stmtEntry.digest, stmtEntry.spaceUri)

if (exists) {
throw new SDKErrors.DuplicateStatementError(
`The statement is already anchored in the chain\nIdentifier: ${stmtEntry.elementUri}`
)
}

const tx = schemaId
? api.tx.statement.register(stmtEntry.digest, authorizationId, schemaId)
: api.tx.statement.register(stmtEntry.digest, authorizationId, null)

return tx
}

/**
* This function prepares and returns a SubmittableExtrinsic for registering a statement on
* the blockchain.
Expand Down Expand Up @@ -264,24 +290,9 @@ export async function prepareExtrinsicToRegister(
signCallback: SignExtrinsicCallback
): Promise<SubmittableExtrinsic> {
try {
const api = ConfigService.get('api')
const authorizationId: AuthorizationId = uriToIdentifier(authorizationUri)
const schemaId =
stmtEntry.schemaUri !== undefined
? stmtEntry.schemaUri && uriToIdentifier(stmtEntry.schemaUri)
: undefined

const exists = await isStatementStored(stmtEntry.digest, stmtEntry.spaceUri)

if (exists) {
throw new SDKErrors.DuplicateStatementError(
`The statement is already anchored in the chain\nIdentifier: ${stmtEntry.elementUri}`
)
}

const tx = schemaId
? api.tx.statement.register(stmtEntry.digest, authorizationId, schemaId)
: api.tx.statement.register(stmtEntry.digest, authorizationId, null)
const tx = await createExtrinsic(stmtEntry, authorizationId)

const extrinsic = await Did.authorizeTx(
creatorUri,
Expand Down

0 comments on commit 0e56e79

Please sign in to comment.