From ccad7f2d7c1d2e97d4d9b456c424920d7be5d7c0 Mon Sep 17 00:00:00 2001 From: Adam A Date: Sun, 18 Aug 2024 21:49:11 +0300 Subject: [PATCH] wip: ~50 type checks down in src/ --- src/impl/fetchCodeInfo.ts | 3 ++- src/impl/fetchCodeInstances.ts | 3 ++- src/impl/fetchCompiledCode.ts | 2 +- src/impl/fetchCompiledCodeLocal.ts | 2 +- src/impl/fetchContractInfo.ts | 3 ++- src/impl/fetchNextBlock.ts | 2 +- src/impl/instantiate.ts | 12 +++++++----- src/impl/send.ts | 1 + src/impl/upload.ts | 7 ++----- 9 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/impl/fetchCodeInfo.ts b/src/impl/fetchCodeInfo.ts index 501a4a1c62..833a6d8959 100644 --- a/src/impl/fetchCodeInfo.ts +++ b/src/impl/fetchCodeInfo.ts @@ -1,4 +1,5 @@ -import type { Chain } from '../API' +import type { Chain, CodeId } from '../API' +import { bold, timed } from '../Util' export async function fetchCodeInfo ( chain: Chain, ...args: Parameters|[] diff --git a/src/impl/fetchCodeInstances.ts b/src/impl/fetchCodeInstances.ts index 02ba2a0489..da15f7cc67 100644 --- a/src/impl/fetchCodeInstances.ts +++ b/src/impl/fetchCodeInstances.ts @@ -1,4 +1,5 @@ -import type { Chain } from '../API' +import type { Chain, CodeId, Address, Contract } from '../API' +import { timed } from '../Util' export async function fetchCodeInstances ( chain: Chain, ...args: Parameters diff --git a/src/impl/fetchCompiledCode.ts b/src/impl/fetchCompiledCode.ts index 7f4d7492e9..2c0031cf7f 100644 --- a/src/impl/fetchCompiledCode.ts +++ b/src/impl/fetchCompiledCode.ts @@ -1,5 +1,5 @@ import type { CompiledCode } from '../API' -import { Console } from '../util' +import { Console, bold } from '../Util' export async function fetchCompiledCode (code: CompiledCode) { diff --git a/src/impl/fetchCompiledCodeLocal.ts b/src/impl/fetchCompiledCodeLocal.ts index 284d5f5fc5..5b0a73de5e 100644 --- a/src/impl/fetchCompiledCodeLocal.ts +++ b/src/impl/fetchCompiledCodeLocal.ts @@ -13,7 +13,7 @@ export async function fetchCompiledCodeLocal (code: CompiledCode) { if (code.codePath.protocol === 'file:') { return await readFile(fileURLToPath(code.codePath)) } else { - return super.fetchImpl() + return fetchCompiledCode(code) } } diff --git a/src/impl/fetchContractInfo.ts b/src/impl/fetchContractInfo.ts index 3d1ebb330f..358c149c15 100644 --- a/src/impl/fetchContractInfo.ts +++ b/src/impl/fetchContractInfo.ts @@ -1,4 +1,5 @@ -import type { Chain } from '../API' +import type { Chain, Address } from '../API' +import { bold, timed } from '../Util' export async function fetchContractInfo ( chain: Chain, ...args: Parameters diff --git a/src/impl/fetchNextBlock.ts b/src/impl/fetchNextBlock.ts index 5ede4a279d..2e353fb0d4 100644 --- a/src/impl/fetchNextBlock.ts +++ b/src/impl/fetchNextBlock.ts @@ -1,4 +1,5 @@ import type { Chain } from '../API' +import { bold } from '../Util' /** Implementation of Chain#fetchNextBlock -> Connection#fetchNextBlockImpl */ export async function fetchNextBlock (chain: Chain): Promise { @@ -32,4 +33,3 @@ export async function fetchNextBlock (chain: Chain): Promise { }) } - diff --git a/src/impl/instantiate.ts b/src/impl/instantiate.ts index 2359832673..7f858563a3 100644 --- a/src/impl/instantiate.ts +++ b/src/impl/instantiate.ts @@ -1,11 +1,12 @@ -import type { Agent } from '../API' +import type { Agent, Address, Contract } from '../API' +import { bold, timed, into } from '../Util' export async function instantiate (agent: Agent, ...args: Parameters) { let [contract, options] = args if (typeof contract === 'string') { - contract = new UploadedCode({ codeId: contract }) + contract = { codeId: contract } } if (isNaN(Number(contract.codeId))) { @@ -41,9 +42,10 @@ export async function instantiate (agent: Agent, ...args: Parameters) { diff --git a/src/impl/upload.ts b/src/impl/upload.ts index 0098a43224..c77feb87b0 100644 --- a/src/impl/upload.ts +++ b/src/impl/upload.ts @@ -7,12 +7,9 @@ export async function upload (agent: Agent, ...args: Parameters if (code instanceof Uint8Array) { template = code } else { - const { CompiledCode } = _$_HACK_$_ if (typeof code === 'string' || code instanceof URL) { - code = new CompiledCode({ codePath: code }) - } else { - code = new CompiledCode(code) - } + code = { codePath: code } + } const t0 = performance.now() code = code as CompiledCode template = await (code as any).fetch()