Skip to content

Commit

Permalink
Merge pull request #1539 from Phala-Network/fix-jssdk-type-hinting
Browse files Browse the repository at this point in the history
Fix jssdk type hinting
  • Loading branch information
Leechael authored Feb 28, 2024
2 parents 764e744 + 7a5452b commit c3fca0d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 33 deletions.
2 changes: 1 addition & 1 deletion frontend/packages/sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@phala/sdk",
"version": "0.5.8",
"version": "0.5.9",
"description": "Phala Phat Contract JS SDK",
"license": "Apache-2.0",
"author": [
Expand Down
11 changes: 9 additions & 2 deletions frontend/packages/sdk/src/OnChainRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,12 @@ export interface CreateOptions {
pruntimeURL?: string
systemContractId?: string
skipCheck?: boolean
strategy?: 'ack-first' | (() => Promise<Readonly<[string, string, ReturnType<typeof createPruntimeClient>]>>)
strategy?:
| 'ack-first'
| ((
api: ApiPromise,
clusterId: string
) => Promise<Readonly<[string, string, ReturnType<typeof createPruntimeClient>]>>)
}

export interface WorkerInfo {
Expand All @@ -61,7 +66,9 @@ export interface PartialWorkerInfo {

export interface StrategicWorkerInfo {
clusterId?: string
strategy: 'ack-first' | (() => Promise<Readonly<[string, ReturnType<typeof createPruntimeClient>]>>)
strategy:
| 'ack-first'
| ((api: ApiPromise, clusterId: string) => Promise<Readonly<[string, ReturnType<typeof createPruntimeClient>]>>)
}

export class OnChainRegistry {
Expand Down
30 changes: 0 additions & 30 deletions frontend/packages/sdk/src/abis/fetchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,6 @@ export async function unsafeGetContractCodeHash(
return payload?.contracts[0]?.codeHash || null
}

export async function unsafeGetAbiFromPatronByCodeHash(codeHash: string): Promise<Record<string, unknown>> {
const codeHashWithoutPrefix = codeHash.indexOf('0x') === 0 ? codeHash.replace('0x', '') : codeHash
const resp = await fetch(`https://api.patron.works/buildSessions/metadata/${codeHashWithoutPrefix}`)
if (resp.status !== 200) {
let payload
try {
payload = await resp.json()
} catch (_err1) {
try {
const text = await resp.text()
throw new Error(`Failed to get abi from Patron: ${resp.status}: ${text}`)
} catch (_err2) {
throw new Error(`Unknown Error: ${resp.status}: ${_err2}`)
}
}
throw new Error(`Failed to get abi from Patron: ${resp.status}: ${(payload as any)?.error || 'Unknown Error'}`)
}
return (await resp.json()) as Record<string, unknown>
}

export async function unsafeGetAbiFromGitHubRepoByCodeHash(codeHash: string): Promise<Record<string, unknown>> {
const codeHashWithPrefix = codeHash.indexOf('0x') !== 0 ? `0x${codeHash}` : codeHash
const resp = await fetch(`${OFFICIAL_ARTIFACTS_URL}/artifacts/${codeHashWithPrefix}/metadata.json`)
Expand All @@ -61,16 +41,6 @@ export async function unsafeGetAbiFromGitHubRepoByCodeHash(codeHash: string): Pr
return (await resp.json()) as Record<string, unknown>
}

export async function unsafeGetWasmFromPatronByCodeHash(codeHash: string): Promise<Uint8Array> {
const codeHashWithoutPrefix = codeHash.indexOf('0x') === 0 ? codeHash.replace('0x', '') : codeHash
const resp = await fetch(`https://api.patron.works/buildSessions/wasm/${codeHashWithoutPrefix}`)
if (resp.status !== 200) {
throw new Error(`Failed to get wasm from Patron: ${resp.status}`)
}
const buffer = await resp.arrayBuffer()
return new Uint8Array(buffer)
}

export async function unsafeGetWasmFromGithubRepoByCodeHash(codeHash: string): Promise<Uint8Array> {
const codeHashWithPrefix = codeHash.indexOf('0x') !== 0 ? `0x${codeHash}` : codeHash
const resp = await fetch(`${OFFICIAL_ARTIFACTS_URL}/artifacts/${codeHashWithPrefix}/out.wasm`)
Expand Down

0 comments on commit c3fca0d

Please sign in to comment.