Skip to content

Commit

Permalink
wip: ~50 type checks down in src/
Browse files Browse the repository at this point in the history
  • Loading branch information
egasimus committed Aug 18, 2024
1 parent 020906b commit ccad7f2
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 16 deletions.
3 changes: 2 additions & 1 deletion src/impl/fetchCodeInfo.ts
Original file line number Diff line number Diff line change
@@ -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<Chain["fetchCodeInfo"]>|[]
Expand Down
3 changes: 2 additions & 1 deletion src/impl/fetchCodeInstances.ts
Original file line number Diff line number Diff line change
@@ -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<Chain["fetchCodeInstances"]>
Expand Down
2 changes: 1 addition & 1 deletion src/impl/fetchCompiledCode.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { CompiledCode } from '../API'
import { Console } from '../util'
import { Console, bold } from '../Util'

export async function fetchCompiledCode (code: CompiledCode) {

Expand Down
2 changes: 1 addition & 1 deletion src/impl/fetchCompiledCodeLocal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/impl/fetchContractInfo.ts
Original file line number Diff line number Diff line change
@@ -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<Chain["fetchContractInfo"]>
Expand Down
2 changes: 1 addition & 1 deletion src/impl/fetchNextBlock.ts
Original file line number Diff line number Diff line change
@@ -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<bigint> {
Expand Down Expand Up @@ -32,4 +33,3 @@ export async function fetchNextBlock (chain: Chain): Promise<bigint> {
})

}

12 changes: 7 additions & 5 deletions src/impl/instantiate.ts
Original file line number Diff line number Diff line change
@@ -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<Agent["instantiate"]>) {

let [contract, options] = args

if (typeof contract === 'string') {
contract = new UploadedCode({ codeId: contract })
contract = { codeId: contract }
}

if (isNaN(Number(contract.codeId))) {
Expand Down Expand Up @@ -41,9 +42,10 @@ export async function instantiate (agent: Agent, ...args: Parameters<Agent["inst
)
})

return new Contract({
...options, ...result
}) as Contract & {
return {
...options,
...result,
} as Contract & {
address: Address
}

Expand Down
1 change: 1 addition & 0 deletions src/impl/send.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Agent } from '../API'
import { bold, timed } from '../Util'

export async function send (agent: Agent, ...args: Parameters<Agent["send"]>) {

Expand Down
7 changes: 2 additions & 5 deletions src/impl/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@ export async function upload (agent: Agent, ...args: Parameters<Agent["upload"]>
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()
Expand Down

0 comments on commit ccad7f2

Please sign in to comment.