Skip to content

Commit

Permalink
basic things working
Browse files Browse the repository at this point in the history
Signed-off-by: Amar Tumballi <amar@dhiway.com>
  • Loading branch information
amarts authored and vatsa287 committed Mar 7, 2024
1 parent 78f9bf1 commit 73a9fa2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 33 deletions.
43 changes: 27 additions & 16 deletions demo/src/asset-working-benchmark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { createDid } from "./utils/generateDid";
// import { AssetTypeOf, IAssetProperties } from "./utils/asset-types.js";

import moment from "moment";
import { Address } from '../../packages/utils/lib/esm/Crypto';

const { NETWORK_ADDRESS, ANCHOR_URI } = process.env;

Expand All @@ -40,8 +41,8 @@ async function main() {
const api = Cord.ConfigService.get("api");
// Restore console.log
console.log = originalConsoleLog;
const txCount = 10000;
const perBlock = 1000;
const txCount = 1000;
const perBlock = 350;
// Step 1: Setup Identities
console.log(`\n❄️ Identities`);
const networkAuthorityIdentity = Cord.Utils.Crypto.makeKeypairFromUri(
Expand Down Expand Up @@ -84,7 +85,7 @@ async function main() {
const space = await Cord.ChainSpace.dispatchToChain(
spaceProperties,
issuerDid.uri,
networkAuthorityIdentity,
issuerIdentity,
async ({ data }) => ({
signature: issuerKeys.authentication.sign(data),
keyType: issuerKeys.authentication.type,
Expand All @@ -100,7 +101,7 @@ async function main() {
await Cord.ChainSpace.sudoApproveChainSpace(
networkAuthorityIdentity,
space.uri,
100
100000
)
console.log(`✅ Chain Space Approved`)

Expand Down Expand Up @@ -136,15 +137,14 @@ async function main() {

const extrinsic = await Cord.Asset.dispatchCreateToChain(
assetEntry,
networkAuthorityIdentity,
issuerIdentity,
space.authorization,
async ({ data }) => ({
signature: issuerKeys.authentication.sign(data),
keyType: issuerKeys.authentication.type,
}),
)

console.log("Asset Entry Local:", assetEntry)

console.log("✅ Asset created!");

Expand All @@ -167,9 +167,6 @@ async function main() {
// `🏛 Holder (${holderDid?.assertionMethod![0].type}): ${holderDid.uri}`
// )

// console.log(`holderDid.uri: ${holderDid.uri}`)

console.log(`\n❄️ Issue Asset to Holder - Issuer Action `);
const assetIssuance = await Cord.Asset.buildFromIssueProperties(
assetEntry.uri,
`did:cord:${holderIdentity.address}`,
Expand All @@ -178,11 +175,9 @@ async function main() {
space.uri,
);

console.log("AssetIssuance Local:", assetIssuance)

const issueExtrinsic = await Cord.Asset.prepareExtrinsic(
assetIssuance,
networkAuthorityIdentity,
issuerIdentity,
space.authorization,
async ({ data }) => ({
signature: issuerKeys.authentication.sign(data),
Expand All @@ -201,6 +196,7 @@ async function main() {
);
}
tx_batch[j] = tx_batch1;
console.log("j ", j);
}
} catch (e: any) {
console.log(e.errorCode, "-", e.message);
Expand All @@ -214,17 +210,29 @@ async function main() {
let promises = [];
for (let j = 0; j < tx_batch.length; j++) {
try {
const tx = await api.tx.utility
.batchAll(tx_batch[j]);
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 }) => ({
signature: issuerKeys.authentication.sign(data),
keyType: issuerKeys.authentication.type,
}),
submitter: issuerIdentity.address
})

await tx.signAsync(issuerIdentity, { nonce: j + 1 })
const send = new Promise((resolve) => tx.send((result) => {
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);
}
Expand All @@ -247,6 +255,9 @@ async function main() {
);

await sleep(1000);
// await sleep(10000);
// await sleep(10000);
// await sleep(10000);
await api.disconnect();
}
main()
Expand Down
17 changes: 0 additions & 17 deletions packages/asset/src/Asset.chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,11 @@ export async function isAssetStored(assetUri: AssetUri): Promise<boolean> {
try {
const api = ConfigService.get('api')

console.log("AssetUri Local:", assetUri)

const identifier = uriToIdentifier(assetUri)

console.log("identifier Local:", identifier)

const encoded = (await api.query.asset.assets(
identifier
)) as Option<PalletAssetAssetEntry>
console.log("encoded Local:", encoded)

return encoded.isSome
} catch (error) {
Expand All @@ -57,10 +52,6 @@ export async function dispatchCreateToChain(
try {
const api = ConfigService.get('api')
const authorizationId: AuthorizationId = uriToIdentifier(authorizationUri)
const exists = await isAssetStored(assetEntry.uri)
if (exists) {
return assetEntry.uri
}

const tx = api.tx.asset.create(
assetEntry.entry,
Expand Down Expand Up @@ -98,14 +89,6 @@ export async function prepareExtrinsic(

const authorizationId: AuthorizationId = uriToIdentifier(authorizationUri)

const exists = await isAssetStored(assetEntry.entry.assetId as AssetUri)

console.log("exists Local:", exists, assetEntry)

if (!exists) {
throw new SDKErrors.CordDispatchError(`Asset Entry not found on chain.`)
}

const tx = api.tx.asset.issue(
assetEntry.entry,
assetEntry.digest,
Expand Down

0 comments on commit 73a9fa2

Please sign in to comment.