Skip to content

Commit

Permalink
basic things working
Browse files Browse the repository at this point in the history
Signed-off-by: Amar Tumballi <[email protected]>
  • Loading branch information
amarts committed Mar 7, 2024
1 parent 78f9bf1 commit f4406a9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 36 deletions.
36 changes: 17 additions & 19 deletions demo/src/asset-working-benchmark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,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 = 50;
// Step 1: Setup Identities
console.log(`\n❄️ Identities`);
const networkAuthorityIdentity = Cord.Utils.Crypto.makeKeypairFromUri(
Expand Down Expand Up @@ -84,7 +84,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 +100,7 @@ async function main() {
await Cord.ChainSpace.sudoApproveChainSpace(
networkAuthorityIdentity,
space.uri,
100
100000
)
console.log(`✅ Chain Space Approved`)

Expand Down Expand Up @@ -136,15 +136,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 +166,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 +174,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 +195,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 +209,17 @@ 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]);

await tx.signAsync(issuerIdentity, { nonce: j + 1 })
const send = new Promise((resolve) => tx.send((result) => {
if (result.status.isReady)
//if (result.isInBlock)
const tx = await api.tx.utility.batchAll(tx_batch[j]);
await tx.signAsync(issuerIdentity, {nonce: j+2})
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 +242,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 f4406a9

Please sign in to comment.