From 690ca14ac0900850d0bf570838181ff37b1affec Mon Sep 17 00:00:00 2001 From: Shreevatsa N Date: Sat, 9 Mar 2024 16:06:05 +0530 Subject: [PATCH] [wip]: use 'authorizeBatch' Signed-off-by: Shreevatsa N --- demo/src/asset-working-benchmark.ts | 91 ++++++++++++++++++++--------- 1 file changed, 62 insertions(+), 29 deletions(-) diff --git a/demo/src/asset-working-benchmark.ts b/demo/src/asset-working-benchmark.ts index 98c7e3b7..8e7ac4a9 100644 --- a/demo/src/asset-working-benchmark.ts +++ b/demo/src/asset-working-benchmark.ts @@ -41,8 +41,8 @@ async function main() { const api = Cord.ConfigService.get("api"); // Restore console.log console.log = originalConsoleLog; - const txCount = 1000; - const perBlock = 350; + const txCount = 100; + const perBlock = 100; // Step 1: Setup Identities console.log(`\n❄️ Identities`); const networkAuthorityIdentity = Cord.Utils.Crypto.makeKeypairFromUri( @@ -205,39 +205,72 @@ async function main() { // console.log = () => {}; // Cord.ConfigService.set({ submitTxResolveOn: Cord.Chain.IS_FINALIZED }); - console.log = originalConsoleLog; - let batchAncStartTime = moment(); - let promises = []; - for (let j = 0; j < tx_batch.length; j++) { - try { - const tx = await api.tx.utility.batchAll(tx_batch[j]); - //await tx.signAsync(issuerIdentity, {nonce: -1}) - - const authorizedBatch = await Cord.Did.authorizeBatch({ - batchFunction: api.tx.utility.batchAll, - did: issuerIdentity, - extrinsics: tx_batch[j], - sign: async ({ data }) => ({ + // console.log = originalConsoleLog; + // let batchAncStartTime = moment(); + // let promises = []; + // for (let j = 0; j < tx_batch.length; j++) { + // try { + // const tx = await api.tx.utility.batchAll(tx_batch[j]); + // await tx.signAsync(issuerIdentity, {nonce: -1}) + + // // const authorizedBatch = await Cord.Did.authorizeBatch({ + // // batchFunction: api.tx.utility.batchAll, + // // did: issuerDid.uri, + // // extrinsics: tx_batch[j], + // // sign: async ({ data }) => ({ + // // signature: issuerKeys.authentication.sign(data), + // // keyType: issuerKeys.authentication.type, + // // }), + // // submitter: issuerIdentity.address + // // }) + + // const send = new Promise((resolve) => tx.send((result) => { + // if (result.status.isReady) + // //if (result.isInBlock) + // //if (result.isFinalized) + // return resolve(true); + // })); + // promises.push(send); + + // //await Cord.Chain.signAndSubmitTx(tx, issuerIdentity); + // } catch (e: any) { + // console.log(e.errorCode, "-", e.message); + // } + // } + // await Promise.all(promises); + + /* attempt without loop */ + let extSignCallback: Cord.SignExtrinsicCallback = async ({ data }) => ({ signature: issuerKeys.authentication.sign(data), keyType: issuerKeys.authentication.type, - }), - submitter: issuerIdentity.address - }) + }) + + const authorizedBatch = await Cord.Did.authorizeBatch({ + batchFunction: api.tx.utility.batchAll, + did: issuerDid.uri, + extrinsics: tx_batch, + sign: extSignCallback, + submitter: issuerIdentity, + }) - const send = new Promise((resolve) => tx.send((result) => { - if (result.status.isReady) - //if (result.isInBlock) - //if (result.isFinalized) - return resolve(true); - })); - promises.push(send); + let batchAncStartTime = moment() + + try { + // await Cord.Chain.signAndSubmitTx(authorizedBatch, networkAddress, { + // resolveOn: Cord.Chain.IS_READY, + // rejectOn: Cord.Chain.IS_ERROR, + // }) + + await Cord.Chain.signAndSubmitTx(authorizedBatch, issuerIdentity) - //await Cord.Chain.signAndSubmitTx(tx, issuerIdentity); } catch (e: any) { - console.log(e.errorCode, "-", e.message); + console.log(e.errorCode, '-', e.message) } - } - await Promise.all(promises); + + // let batchAncEndTime = moment() + // var batchAncDuration = moment.duration( + // batchAncEndTime.diff(batchAncStartTime) + // ) var batchAncDuration = moment .duration(moment().diff(batchAncStartTime))