From ed6dbb84eb67783ff7d333b0a27248be578b337d Mon Sep 17 00:00:00 2001 From: Matias Volpe Date: Wed, 14 Jun 2023 10:09:09 -0300 Subject: [PATCH 1/5] feat: improve capi bundle size --- mod.ts | 3 +-- nets.ts | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/mod.ts b/mod.ts index 10cf32945..6da3e10f9 100644 --- a/mod.ts +++ b/mod.ts @@ -6,14 +6,13 @@ if (CAPI_MARKER in globalThis) { export * as $ from "./deps/scale.ts" export { BitSequence } from "./deps/scale.ts" -export * from "./server/client/mod.ts" +export * from "./server/client/detectConnect.ts" // moderate --exclude main.ts nets.ts util server export * from "./crypto/mod.ts" export * from "./fluent/mod.ts" export * from "./frame_metadata/mod.ts" -export * from "./nets/mod.ts" export * from "./rpc/mod.ts" export * from "./rune/mod.ts" export * from "./scale_info/mod.ts" diff --git a/nets.ts b/nets.ts index f9b352163..678798290 100644 --- a/nets.ts +++ b/nets.ts @@ -1,4 +1,4 @@ -import { bins, net } from "./mod.ts" +import { bins, net } from "./nets/mod.ts" const bin = bins({ polkadot: ["polkadot-fast", "v0.9.38"], From 1e7fe8424fdfb2fe1343c79334701307d8a3cde0 Mon Sep 17 00:00:00 2001 From: Matias Volpe Date: Wed, 14 Jun 2023 14:34:09 -0300 Subject: [PATCH 2/5] feat: re-export createDevUsers --- mod.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/mod.ts b/mod.ts index 6da3e10f9..11cf501d9 100644 --- a/mod.ts +++ b/mod.ts @@ -6,6 +6,7 @@ if (CAPI_MARKER in globalThis) { export * as $ from "./deps/scale.ts" export { BitSequence } from "./deps/scale.ts" +export * from "./server/client/createDevUsers.ts" export * from "./server/client/detectConnect.ts" // moderate --exclude main.ts nets.ts util server From f84b81d0db601c8bb4482a3b0355a1c30bad7129 Mon Sep 17 00:00:00 2001 From: Matias Volpe Date: Wed, 14 Jun 2023 14:54:04 -0300 Subject: [PATCH 3/5] feat: move devUser to createDevUsers --- _tasks/generate_artifacts.ts | 2 +- nets/chain_spec/addDevUsers.ts | 6 +----- server/client/createDevUsers.ts | 7 +++++-- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/_tasks/generate_artifacts.ts b/_tasks/generate_artifacts.ts index 7eae754cb..cdc1c922d 100755 --- a/_tasks/generate_artifacts.ts +++ b/_tasks/generate_artifacts.ts @@ -3,7 +3,7 @@ import * as $ from "../deps/scale.ts" import { emptyDir } from "../deps/std/fs.ts" import * as path from "../deps/std/path.ts" import dprintConfig from "../dprint.json" assert { type: "json" } -import { devUser } from "../nets/chain_spec/addDevUsers.ts" +import { devUser } from "../mod.ts" import { compress } from "../util/compression.ts" export const DEV_USER_COUNT = 10_000 diff --git a/nets/chain_spec/addDevUsers.ts b/nets/chain_spec/addDevUsers.ts index 681177222..da29ae21c 100644 --- a/nets/chain_spec/addDevUsers.ts +++ b/nets/chain_spec/addDevUsers.ts @@ -1,4 +1,4 @@ -import { blake2_512, Sr25519, ss58 } from "../../crypto/mod.ts" +import { ss58 } from "../../crypto/mod.ts" import * as $ from "../../deps/scale.ts" import { devUserPublicKeysData } from "../../util/_artifacts/devUserPublicKeysData.ts" import { GenesisConfig } from "./ChainSpec.ts" @@ -15,7 +15,3 @@ export function addDevUsers(genesisConfig: GenesisConfig) { balances.push([ss58.encode(networkPrefix, publicKey), devUserInitialFunds]) } } - -export function devUser(userId: number) { - return Sr25519.fromSeed64(blake2_512.hash(new TextEncoder().encode(`capi-dev-user-${userId}`))) -} diff --git a/server/client/createDevUsers.ts b/server/client/createDevUsers.ts index 86741f5a1..578855d85 100644 --- a/server/client/createDevUsers.ts +++ b/server/client/createDevUsers.ts @@ -1,8 +1,11 @@ -import { Sr25519 } from "../../crypto/mod.ts" -import { devUser } from "../../nets/mod.ts" +import { blake2_512, Sr25519 } from "../../crypto/mod.ts" import { ArrayOfLength } from "../../util/ArrayOfLength.ts" import { detectServer } from "./detectServer.ts" +export function devUser(userId: number) { + return Sr25519.fromSeed64(blake2_512.hash(new TextEncoder().encode(`capi-dev-user-${userId}`))) +} + export function createDevUsers(): Promise> export function createDevUsers(count: N): Promise> export async function createDevUsers(count?: number): Promise | Sr25519[]> { From 7b4319189f0e7ff8824b634c631fcecdfc63ff40 Mon Sep 17 00:00:00 2001 From: Matias Volpe Date: Wed, 14 Jun 2023 14:59:35 -0300 Subject: [PATCH 4/5] feat: update capi init nets.ts codegen --- cli/init.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cli/init.ts b/cli/init.ts index 1a6524d49..dc61ca42f 100644 --- a/cli/init.ts +++ b/cli/init.ts @@ -38,7 +38,7 @@ async function runInitNode(packageJsonPath: string) { scripts["capi:sync"] = "capi sync node" scripts["capi:serve"] = "capi serve" Deno.writeTextFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2)) - await Promise.all([netsInit("capi"), updateGitignore()]) + await Promise.all([netsInit("capi/nets"), updateGitignore()]) } async function runInitDeno(denoJsonPath: string) { @@ -46,12 +46,12 @@ async function runInitDeno(denoJsonPath: string) { assertManifest(denoJson) const tasks = denoJson.tasks ??= {} const version = detectVersion() - const versioned = `http://deno.land/x/capi${version ? `@${version}` : ""}/main.ts` - tasks["capi"] = `deno run -A ${versioned}` + const versioned = `http://deno.land/x/capi${version ? `@${version}` : ""}` + tasks["capi"] = `deno run -A ${versioned}/main.ts` tasks["capi:sync"] = "deno task capi sync node" tasks["capi:serve"] = "deno task capi serve" Deno.writeTextFileSync(denoJsonPath, JSON.stringify(denoJson, null, 2)) - await Promise.all([netsInit(versioned), updateGitignore()]) + await Promise.all([netsInit(`${versioned}/nets/mod.ts`), updateGitignore()]) } async function netsInit(specifier: string) { From 77ee87d1943210dcaf1cf135836306f5f94fce7a Mon Sep 17 00:00:00 2001 From: Matias Volpe Date: Wed, 14 Jun 2023 15:50:06 -0300 Subject: [PATCH 5/5] Update mod.ts Co-authored-by: T6 --- mod.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mod.ts b/mod.ts index 11cf501d9..974e95b24 100644 --- a/mod.ts +++ b/mod.ts @@ -9,7 +9,7 @@ export { BitSequence } from "./deps/scale.ts" export * from "./server/client/createDevUsers.ts" export * from "./server/client/detectConnect.ts" -// moderate --exclude main.ts nets.ts util server +// moderate --exclude main.ts nets.ts util server nets export * from "./crypto/mod.ts" export * from "./fluent/mod.ts"