From d7d9ebd73489249e5e4052fb8a3c05e59b06c389 Mon Sep 17 00:00:00 2001 From: William Hua Date: Thu, 12 Dec 2024 10:58:29 -0500 Subject: [PATCH] pnpm format && pnpm lint:fix --- packages/builder/src/builder.gen.ts | 286 ++++++++++-------- packages/indexer/src/indexergw.gen.ts | 410 ++++++++++++++------------ packages/waas-ethers/src/signer.ts | 2 +- 3 files changed, 378 insertions(+), 320 deletions(-) diff --git a/packages/builder/src/builder.gen.ts b/packages/builder/src/builder.gen.ts index aac8ab5b5..66d533669 100644 --- a/packages/builder/src/builder.gen.ts +++ b/packages/builder/src/builder.gen.ts @@ -3,65 +3,65 @@ // surface area of the client. // // In the future we can include additional interfaces as needed. -export const WebrpcHeader = "Webrpc" +export const WebrpcHeader = 'Webrpc' -export const WebrpcHeaderValue = "webrpc@v0.22.0;gen-typescript@v0.16.1;sequence-builder@v0.1.0" +export const WebrpcHeaderValue = 'webrpc@v0.22.0;gen-typescript@v0.16.1;sequence-builder@v0.1.0' // WebRPC description and code-gen version -export const WebRPCVersion = "v1" +export const WebRPCVersion = 'v1' // Schema version of your RIDL schema -export const WebRPCSchemaVersion = "v0.1.0" +export const WebRPCSchemaVersion = 'v0.1.0' // Schema hash generated from your RIDL schema -export const WebRPCSchemaHash = "5b580e1afeb26e0b4a8ee026271e2466760da0aa" +export const WebRPCSchemaHash = '5b580e1afeb26e0b4a8ee026271e2466760da0aa' type WebrpcGenVersions = { - webrpcGenVersion: string; - codeGenName: string; - codeGenVersion: string; - schemaName: string; - schemaVersion: string; -}; + webrpcGenVersion: string + codeGenName: string + codeGenVersion: string + schemaName: string + schemaVersion: string +} export function VersionFromHeader(headers: Headers): WebrpcGenVersions { - const headerValue = headers.get(WebrpcHeader); + const headerValue = headers.get(WebrpcHeader) if (!headerValue) { return { - webrpcGenVersion: "", - codeGenName: "", - codeGenVersion: "", - schemaName: "", - schemaVersion: "", - }; + webrpcGenVersion: '', + codeGenName: '', + codeGenVersion: '', + schemaName: '', + schemaVersion: '' + } } - return parseWebrpcGenVersions(headerValue); + return parseWebrpcGenVersions(headerValue) } function parseWebrpcGenVersions(header: string): WebrpcGenVersions { - const versions = header.split(";"); + const versions = header.split(';') if (versions.length < 3) { return { - webrpcGenVersion: "", - codeGenName: "", - codeGenVersion: "", - schemaName: "", - schemaVersion: "", - }; + webrpcGenVersion: '', + codeGenName: '', + codeGenVersion: '', + schemaName: '', + schemaVersion: '' + } } - const [_, webrpcGenVersion] = versions[0].split("@"); - const [codeGenName, codeGenVersion] = versions[1].split("@"); - const [schemaName, schemaVersion] = versions[2].split("@"); + const [_, webrpcGenVersion] = versions[0].split('@') + const [codeGenName, codeGenVersion] = versions[1].split('@') + const [schemaName, schemaVersion] = versions[2].split('@') return { webrpcGenVersion, codeGenName, codeGenVersion, schemaName, - schemaVersion, - }; + schemaVersion + } } // @@ -93,17 +93,32 @@ export interface WalletProof { export interface Builder { ping(headers?: object, signal?: AbortSignal): Promise - registerAudienceContact(args: RegisterAudienceContactArgs, headers?: object, signal?: AbortSignal): Promise - getRegisteredAudienceContact(args: GetRegisteredAudienceContactArgs, headers?: object, signal?: AbortSignal): Promise - getAudienceRegistrationPublicStatus(args: GetAudienceRegistrationPublicStatusArgs, headers?: object, signal?: AbortSignal): Promise - isAudienceContactRegistered(args: IsAudienceContactRegisteredArgs, headers?: object, signal?: AbortSignal): Promise -} - -export interface PingArgs { -} + registerAudienceContact( + args: RegisterAudienceContactArgs, + headers?: object, + signal?: AbortSignal + ): Promise + getRegisteredAudienceContact( + args: GetRegisteredAudienceContactArgs, + headers?: object, + signal?: AbortSignal + ): Promise + getAudienceRegistrationPublicStatus( + args: GetAudienceRegistrationPublicStatusArgs, + headers?: object, + signal?: AbortSignal + ): Promise + isAudienceContactRegistered( + args: IsAudienceContactRegisteredArgs, + headers?: object, + signal?: AbortSignal + ): Promise +} + +export interface PingArgs {} export interface PingReturn { - status: boolean + status: boolean } export interface RegisterAudienceContactArgs { @@ -114,7 +129,7 @@ export interface RegisterAudienceContactArgs { } export interface RegisterAudienceContactReturn { - ok: boolean + ok: boolean } export interface GetRegisteredAudienceContactArgs { projectId: number @@ -123,7 +138,7 @@ export interface GetRegisteredAudienceContactArgs { } export interface GetRegisteredAudienceContactReturn { - contact: AudienceContact + contact: AudienceContact } export interface GetAudienceRegistrationPublicStatusArgs { projectId: number @@ -131,7 +146,7 @@ export interface GetAudienceRegistrationPublicStatusArgs { } export interface GetAudienceRegistrationPublicStatusReturn { - status: AudienceRegistrationStatus + status: AudienceRegistrationStatus } export interface IsAudienceContactRegisteredArgs { projectId: number @@ -140,10 +155,9 @@ export interface IsAudienceContactRegisteredArgs { } export interface IsAudienceContactRegisteredReturn { - registered: boolean + registered: boolean } - // // Client // @@ -160,82 +174,101 @@ export class Builder implements Builder { private url(name: string): string { return this.hostname + this.path + name } - + ping = (headers?: object, signal?: AbortSignal): Promise => { - return this.fetch( - this.url('Ping'), - createHTTPRequest({}, headers, signal) - ).then((res) => { - return buildResponse(res).then(_data => { - return { - status: (_data.status), - } - }) - }, (error) => { - throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) - }) - } - - registerAudienceContact = (args: RegisterAudienceContactArgs, headers?: object, signal?: AbortSignal): Promise => { - return this.fetch( - this.url('RegisterAudienceContact'), - createHTTPRequest(args, headers, signal)).then((res) => { - return buildResponse(res).then(_data => { - return { - ok: (_data.ok), - } - }) - }, (error) => { - throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) - }) - } - - getRegisteredAudienceContact = (args: GetRegisteredAudienceContactArgs, headers?: object, signal?: AbortSignal): Promise => { - return this.fetch( - this.url('GetRegisteredAudienceContact'), - createHTTPRequest(args, headers, signal)).then((res) => { - return buildResponse(res).then(_data => { - return { - contact: (_data.contact), - } - }) - }, (error) => { - throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) - }) - } - - getAudienceRegistrationPublicStatus = (args: GetAudienceRegistrationPublicStatusArgs, headers?: object, signal?: AbortSignal): Promise => { - return this.fetch( - this.url('GetAudienceRegistrationPublicStatus'), - createHTTPRequest(args, headers, signal)).then((res) => { - return buildResponse(res).then(_data => { - return { - status: (_data.status), - } - }) - }, (error) => { - throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) - }) - } - - isAudienceContactRegistered = (args: IsAudienceContactRegisteredArgs, headers?: object, signal?: AbortSignal): Promise => { - return this.fetch( - this.url('IsAudienceContactRegistered'), - createHTTPRequest(args, headers, signal)).then((res) => { - return buildResponse(res).then(_data => { - return { - registered: (_data.registered), - } - }) - }, (error) => { - throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) - }) + return this.fetch(this.url('Ping'), createHTTPRequest({}, headers, signal)).then( + res => { + return buildResponse(res).then(_data => { + return { + status: _data.status + } + }) + }, + error => { + throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) + } + ) + } + + registerAudienceContact = ( + args: RegisterAudienceContactArgs, + headers?: object, + signal?: AbortSignal + ): Promise => { + return this.fetch(this.url('RegisterAudienceContact'), createHTTPRequest(args, headers, signal)).then( + res => { + return buildResponse(res).then(_data => { + return { + ok: _data.ok + } + }) + }, + error => { + throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) + } + ) + } + + getRegisteredAudienceContact = ( + args: GetRegisteredAudienceContactArgs, + headers?: object, + signal?: AbortSignal + ): Promise => { + return this.fetch(this.url('GetRegisteredAudienceContact'), createHTTPRequest(args, headers, signal)).then( + res => { + return buildResponse(res).then(_data => { + return { + contact: _data.contact + } + }) + }, + error => { + throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) + } + ) + } + + getAudienceRegistrationPublicStatus = ( + args: GetAudienceRegistrationPublicStatusArgs, + headers?: object, + signal?: AbortSignal + ): Promise => { + return this.fetch(this.url('GetAudienceRegistrationPublicStatus'), createHTTPRequest(args, headers, signal)).then( + res => { + return buildResponse(res).then(_data => { + return { + status: _data.status + } + }) + }, + error => { + throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) + } + ) + } + + isAudienceContactRegistered = ( + args: IsAudienceContactRegisteredArgs, + headers?: object, + signal?: AbortSignal + ): Promise => { + return this.fetch(this.url('IsAudienceContactRegistered'), createHTTPRequest(args, headers, signal)).then( + res => { + return buildResponse(res).then(_data => { + return { + registered: _data.registered + } + }) + }, + error => { + throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) + } + ) } - } - const createHTTPRequest = (body: object = {}, headers: object = {}, signal: AbortSignal | null = null): object => { - const reqHeaders: {[key: string]: string} = { ...headers, 'Content-Type': 'application/json' } +const createHTTPRequest = (body: object = {}, headers: object = {}, signal: AbortSignal | null = null): object => { + const reqHeaders: { [key: string]: string } = { ...headers, 'Content-Type': 'application/json' } reqHeaders[WebrpcHeader] = WebrpcHeaderValue return { @@ -251,18 +284,18 @@ const buildResponse = (res: Response): Promise => { let data try { data = JSON.parse(text) - } catch(error) { + } catch (error) { let message = '' - if (error instanceof Error) { + if (error instanceof Error) { message = error.message } throw WebrpcBadResponseError.new({ status: res.status, - cause: `JSON.parse(): ${message}: response text: ${text}`}, - ) + cause: `JSON.parse(): ${message}: response text: ${text}` + }) } if (!res.ok) { - const code: number = (typeof data.code === 'number') ? data.code : 0 + const code: number = typeof data.code === 'number' ? data.code : 0 throw (webrpcErrorByCode[code] || WebrpcError).new(data) } return data @@ -444,7 +477,6 @@ export class WebrpcStreamFinishedError extends WebrpcError { } } - // Schema errors export class UnauthorizedError extends WebrpcError { @@ -603,7 +635,6 @@ export class AlreadyCollaboratorError extends WebrpcError { } } - export enum errors { WebrpcEndpoint = 'WebrpcEndpoint', WebrpcRequestFailed = 'WebrpcRequestFailed', @@ -626,7 +657,7 @@ export enum errors { InvalidArgument = 'InvalidArgument', NotFound = 'NotFound', UserNotFound = 'UserNotFound', - ProjectNotFound = 'ProjectNotFound', + ProjectNotFound = 'ProjectNotFound' } export enum WebrpcErrorCodes { @@ -651,7 +682,7 @@ export enum WebrpcErrorCodes { InvalidArgument = 2001, NotFound = 3000, UserNotFound = 3001, - ProjectNotFound = 3002, + ProjectNotFound = 3002 } export const webrpcErrorByCode: { [code: number]: any } = { @@ -676,8 +707,7 @@ export const webrpcErrorByCode: { [code: number]: any } = { [2001]: InvalidArgumentError, [3000]: NotFoundError, [3001]: UserNotFoundError, - [3002]: ProjectNotFoundError, + [3002]: ProjectNotFoundError } export type Fetch = (input: RequestInfo, init?: RequestInit) => Promise - diff --git a/packages/indexer/src/indexergw.gen.ts b/packages/indexer/src/indexergw.gen.ts index 733c06e85..5dbec7024 100644 --- a/packages/indexer/src/indexergw.gen.ts +++ b/packages/indexer/src/indexergw.gen.ts @@ -5,72 +5,71 @@ // // webrpc-gen -schema=indexer.ridl -service=IndexerGateway -target=typescript -client -out=./clients/indexergw/indexer.gen.ts -export const WebrpcHeader = "Webrpc" +export const WebrpcHeader = 'Webrpc' -export const WebrpcHeaderValue = "webrpc@v0.21.1;gen-typescript@v0.15.1;sequence-indexer@v0.4.0" +export const WebrpcHeaderValue = 'webrpc@v0.21.1;gen-typescript@v0.15.1;sequence-indexer@v0.4.0' // WebRPC description and code-gen version -export const WebRPCVersion = "v1" +export const WebRPCVersion = 'v1' // Schema version of your RIDL schema -export const WebRPCSchemaVersion = "v0.4.0" +export const WebRPCSchemaVersion = 'v0.4.0' // Schema hash generated from your RIDL schema -export const WebRPCSchemaHash = "71cd081c5ca2372bf92a897ae1aa4ebf93ffd0fc" +export const WebRPCSchemaHash = '71cd081c5ca2372bf92a897ae1aa4ebf93ffd0fc' type WebrpcGenVersions = { - webrpcGenVersion: string; - codeGenName: string; - codeGenVersion: string; - schemaName: string; - schemaVersion: string; -}; + webrpcGenVersion: string + codeGenName: string + codeGenVersion: string + schemaName: string + schemaVersion: string +} export function VersionFromHeader(headers: Headers): WebrpcGenVersions { - const headerValue = headers.get(WebrpcHeader); + const headerValue = headers.get(WebrpcHeader) if (!headerValue) { return { - webrpcGenVersion: "", - codeGenName: "", - codeGenVersion: "", - schemaName: "", - schemaVersion: "", - }; + webrpcGenVersion: '', + codeGenName: '', + codeGenVersion: '', + schemaName: '', + schemaVersion: '' + } } - return parseWebrpcGenVersions(headerValue); + return parseWebrpcGenVersions(headerValue) } function parseWebrpcGenVersions(header: string): WebrpcGenVersions { - const versions = header.split(";"); + const versions = header.split(';') if (versions.length < 3) { return { - webrpcGenVersion: "", - codeGenName: "", - codeGenVersion: "", - schemaName: "", - schemaVersion: "", - }; + webrpcGenVersion: '', + codeGenName: '', + codeGenVersion: '', + schemaName: '', + schemaVersion: '' + } } - const [_, webrpcGenVersion] = versions[0].split("@"); - const [codeGenName, codeGenVersion] = versions[1].split("@"); - const [schemaName, schemaVersion] = versions[2].split("@"); + const [_, webrpcGenVersion] = versions[0].split('@') + const [codeGenName, codeGenVersion] = versions[1].split('@') + const [schemaName, schemaVersion] = versions[2].split('@') return { webrpcGenVersion, codeGenName, codeGenVersion, schemaName, - schemaVersion, - }; + schemaVersion + } } // // Types // - export interface ContractInfo { chainId: number address: string @@ -104,8 +103,8 @@ export interface TokenMetadata { image?: string video?: string audio?: string - properties?: {[key: string]: any} - attributes: Array<{[key: string]: any}> + properties?: { [key: string]: any } + attributes: Array<{ [key: string]: any }> image_data?: string external_url?: string background_color?: string @@ -238,7 +237,7 @@ export interface DiskUsage { used: number size: number percent: number - dirs: {[key: string]: string} + dirs: { [key: string]: string } } export interface Bond { @@ -303,7 +302,7 @@ export interface EventLog { logDataType: EventLogDataType ts: string txnInfo?: TxnInfo - rawLog?: {[key: string]: any} + rawLog?: { [key: string]: any } event?: EventDecoded } @@ -404,7 +403,7 @@ export interface TxnTransfer { amounts: Array logIndex: number contractInfo?: ContractInfo - tokenMetadata?: {[key: string]: TokenMetadata} + tokenMetadata?: { [key: string]: TokenMetadata } } export interface TransactionHistoryFilter { @@ -530,11 +529,27 @@ export interface GatewayTokenBalance { } export interface IndexerGateway { - getNativeTokenBalance(args: GetNativeTokenBalanceArgs, headers?: object, signal?: AbortSignal): Promise + getNativeTokenBalance( + args: GetNativeTokenBalanceArgs, + headers?: object, + signal?: AbortSignal + ): Promise getTokenBalances(args: GetTokenBalancesArgs, headers?: object, signal?: AbortSignal): Promise - getTokenBalancesSummary(args: GetTokenBalancesSummaryArgs, headers?: object, signal?: AbortSignal): Promise - getTokenBalancesDetails(args: GetTokenBalancesDetailsArgs, headers?: object, signal?: AbortSignal): Promise - getTokenBalancesByContract(args: GetTokenBalancesByContractArgs, headers?: object, signal?: AbortSignal): Promise + getTokenBalancesSummary( + args: GetTokenBalancesSummaryArgs, + headers?: object, + signal?: AbortSignal + ): Promise + getTokenBalancesDetails( + args: GetTokenBalancesDetailsArgs, + headers?: object, + signal?: AbortSignal + ): Promise + getTokenBalancesByContract( + args: GetTokenBalancesByContractArgs, + headers?: object, + signal?: AbortSignal + ): Promise getBalanceUpdates(args: GetBalanceUpdatesArgs, headers?: object, signal?: AbortSignal): Promise ping(headers?: object, signal?: AbortSignal): Promise version(headers?: object, signal?: AbortSignal): Promise @@ -547,7 +562,7 @@ export interface GetNativeTokenBalanceArgs { } export interface GetNativeTokenBalanceReturn { - balances: Array + balances: Array } export interface GetTokenBalancesArgs { chainIds?: Array @@ -562,7 +577,7 @@ export interface GetTokenBalancesArgs { export interface GetTokenBalancesReturn { page: Page - balances: Array + balances: Array } export interface GetTokenBalancesSummaryArgs { chainIds?: Array @@ -573,7 +588,7 @@ export interface GetTokenBalancesSummaryArgs { export interface GetTokenBalancesSummaryReturn { page: Page - balances: Array + balances: Array } export interface GetTokenBalancesDetailsArgs { chainIds?: Array @@ -584,7 +599,7 @@ export interface GetTokenBalancesDetailsArgs { export interface GetTokenBalancesDetailsReturn { page: Page - balances: Array + balances: Array } export interface GetTokenBalancesByContractArgs { chainIds?: Array @@ -595,7 +610,7 @@ export interface GetTokenBalancesByContractArgs { export interface GetTokenBalancesByContractReturn { page: Page - balances: Array + balances: Array } export interface GetBalanceUpdatesArgs { chainIds?: Array @@ -607,29 +622,24 @@ export interface GetBalanceUpdatesArgs { export interface GetBalanceUpdatesReturn { page: Page - balances: Array -} -export interface PingArgs { + balances: Array } +export interface PingArgs {} export interface PingReturn { - status: boolean -} -export interface VersionArgs { + status: boolean } +export interface VersionArgs {} export interface VersionReturn { - version: Version -} -export interface RuntimeStatusArgs { + version: Version } +export interface RuntimeStatusArgs {} export interface RuntimeStatusReturn { - status: RuntimeStatus + status: RuntimeStatus } - - // // Client // @@ -646,145 +656,166 @@ export class IndexerGateway implements IndexerGateway { private url(name: string): string { return this.hostname + this.path + name } - - getNativeTokenBalance = (args: GetNativeTokenBalanceArgs, headers?: object, signal?: AbortSignal): Promise => { - return this.fetch( - this.url('GetNativeTokenBalance'), - createHTTPRequest(args, headers, signal)).then((res) => { - return buildResponse(res).then(_data => { - return { - balances: >(_data.balances), - } - }) - }, (error) => { - throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) - }) + + getNativeTokenBalance = ( + args: GetNativeTokenBalanceArgs, + headers?: object, + signal?: AbortSignal + ): Promise => { + return this.fetch(this.url('GetNativeTokenBalance'), createHTTPRequest(args, headers, signal)).then( + res => { + return buildResponse(res).then(_data => { + return { + balances: >_data.balances + } + }) + }, + error => { + throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) + } + ) } - + getTokenBalances = (args: GetTokenBalancesArgs, headers?: object, signal?: AbortSignal): Promise => { - return this.fetch( - this.url('GetTokenBalances'), - createHTTPRequest(args, headers, signal)).then((res) => { - return buildResponse(res).then(_data => { - return { - page: (_data.page), - balances: >(_data.balances), - } - }) - }, (error) => { - throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) - }) + return this.fetch(this.url('GetTokenBalances'), createHTTPRequest(args, headers, signal)).then( + res => { + return buildResponse(res).then(_data => { + return { + page: _data.page, + balances: >_data.balances + } + }) + }, + error => { + throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) + } + ) } - - getTokenBalancesSummary = (args: GetTokenBalancesSummaryArgs, headers?: object, signal?: AbortSignal): Promise => { - return this.fetch( - this.url('GetTokenBalancesSummary'), - createHTTPRequest(args, headers, signal)).then((res) => { - return buildResponse(res).then(_data => { - return { - page: (_data.page), - balances: >(_data.balances), - } - }) - }, (error) => { - throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) - }) + + getTokenBalancesSummary = ( + args: GetTokenBalancesSummaryArgs, + headers?: object, + signal?: AbortSignal + ): Promise => { + return this.fetch(this.url('GetTokenBalancesSummary'), createHTTPRequest(args, headers, signal)).then( + res => { + return buildResponse(res).then(_data => { + return { + page: _data.page, + balances: >_data.balances + } + }) + }, + error => { + throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) + } + ) } - - getTokenBalancesDetails = (args: GetTokenBalancesDetailsArgs, headers?: object, signal?: AbortSignal): Promise => { - return this.fetch( - this.url('GetTokenBalancesDetails'), - createHTTPRequest(args, headers, signal)).then((res) => { - return buildResponse(res).then(_data => { - return { - page: (_data.page), - balances: >(_data.balances), - } - }) - }, (error) => { - throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) - }) + + getTokenBalancesDetails = ( + args: GetTokenBalancesDetailsArgs, + headers?: object, + signal?: AbortSignal + ): Promise => { + return this.fetch(this.url('GetTokenBalancesDetails'), createHTTPRequest(args, headers, signal)).then( + res => { + return buildResponse(res).then(_data => { + return { + page: _data.page, + balances: >_data.balances + } + }) + }, + error => { + throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) + } + ) } - - getTokenBalancesByContract = (args: GetTokenBalancesByContractArgs, headers?: object, signal?: AbortSignal): Promise => { - return this.fetch( - this.url('GetTokenBalancesByContract'), - createHTTPRequest(args, headers, signal)).then((res) => { - return buildResponse(res).then(_data => { - return { - page: (_data.page), - balances: >(_data.balances), - } - }) - }, (error) => { - throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) - }) + + getTokenBalancesByContract = ( + args: GetTokenBalancesByContractArgs, + headers?: object, + signal?: AbortSignal + ): Promise => { + return this.fetch(this.url('GetTokenBalancesByContract'), createHTTPRequest(args, headers, signal)).then( + res => { + return buildResponse(res).then(_data => { + return { + page: _data.page, + balances: >_data.balances + } + }) + }, + error => { + throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) + } + ) } - + getBalanceUpdates = (args: GetBalanceUpdatesArgs, headers?: object, signal?: AbortSignal): Promise => { - return this.fetch( - this.url('GetBalanceUpdates'), - createHTTPRequest(args, headers, signal)).then((res) => { - return buildResponse(res).then(_data => { - return { - page: (_data.page), - balances: >(_data.balances), - } - }) - }, (error) => { - throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) - }) + return this.fetch(this.url('GetBalanceUpdates'), createHTTPRequest(args, headers, signal)).then( + res => { + return buildResponse(res).then(_data => { + return { + page: _data.page, + balances: >_data.balances + } + }) + }, + error => { + throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) + } + ) } - + ping = (headers?: object, signal?: AbortSignal): Promise => { - return this.fetch( - this.url('Ping'), - createHTTPRequest({}, headers, signal) - ).then((res) => { - return buildResponse(res).then(_data => { - return { - status: (_data.status), - } - }) - }, (error) => { - throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) - }) + return this.fetch(this.url('Ping'), createHTTPRequest({}, headers, signal)).then( + res => { + return buildResponse(res).then(_data => { + return { + status: _data.status + } + }) + }, + error => { + throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) + } + ) } - + version = (headers?: object, signal?: AbortSignal): Promise => { - return this.fetch( - this.url('Version'), - createHTTPRequest({}, headers, signal) - ).then((res) => { - return buildResponse(res).then(_data => { - return { - version: (_data.version), - } - }) - }, (error) => { - throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) - }) + return this.fetch(this.url('Version'), createHTTPRequest({}, headers, signal)).then( + res => { + return buildResponse(res).then(_data => { + return { + version: _data.version + } + }) + }, + error => { + throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) + } + ) } - + runtimeStatus = (headers?: object, signal?: AbortSignal): Promise => { - return this.fetch( - this.url('RuntimeStatus'), - createHTTPRequest({}, headers, signal) - ).then((res) => { - return buildResponse(res).then(_data => { - return { - status: (_data.status), - } - }) - }, (error) => { - throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) - }) + return this.fetch(this.url('RuntimeStatus'), createHTTPRequest({}, headers, signal)).then( + res => { + return buildResponse(res).then(_data => { + return { + status: _data.status + } + }) + }, + error => { + throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` }) + } + ) } - } - const createHTTPRequest = (body: object = {}, headers: object = {}, signal: AbortSignal | null = null): object => { - const reqHeaders: {[key: string]: string} = { ...headers, 'Content-Type': 'application/json' } +const createHTTPRequest = (body: object = {}, headers: object = {}, signal: AbortSignal | null = null): object => { + const reqHeaders: { [key: string]: string } = { ...headers, 'Content-Type': 'application/json' } reqHeaders[WebrpcHeader] = WebrpcHeaderValue return { @@ -800,18 +831,18 @@ const buildResponse = (res: Response): Promise => { let data try { data = JSON.parse(text) - } catch(error) { + } catch (error) { let message = '' - if (error instanceof Error) { + if (error instanceof Error) { message = error.message } throw WebrpcBadResponseError.new({ status: res.status, - cause: `JSON.parse(): ${message}: response text: ${text}`}, - ) + cause: `JSON.parse(): ${message}: response text: ${text}` + }) } if (!res.ok) { - const code: number = (typeof data.code === 'number') ? data.code : 0 + const code: number = typeof data.code === 'number' ? data.code : 0 throw (webrpcErrorByCode[code] || WebrpcError).new(data) } return data @@ -993,7 +1024,6 @@ export class WebrpcStreamFinishedError extends WebrpcError { } } - // Schema errors export class UnauthorizedError extends WebrpcError { @@ -1334,7 +1364,6 @@ export class MetadataCallFailedError extends WebrpcError { } } - export enum errors { WebrpcEndpoint = 'WebrpcEndpoint', WebrpcRequestFailed = 'WebrpcRequestFailed', @@ -1372,7 +1401,7 @@ export enum errors { QueryFailed = 'QueryFailed', ResourceExhausted = 'ResourceExhausted', NotFound = 'NotFound', - MetadataCallFailed = 'MetadataCallFailed', + MetadataCallFailed = 'MetadataCallFailed' } const webrpcErrorByCode: { [code: number]: any } = { @@ -1412,8 +1441,7 @@ const webrpcErrorByCode: { [code: number]: any } = { [2003]: QueryFailedError, [2004]: ResourceExhaustedError, [3000]: NotFoundError, - [3003]: MetadataCallFailedError, + [3003]: MetadataCallFailedError } export type Fetch = (input: RequestInfo, init?: RequestInit) => Promise - diff --git a/packages/waas-ethers/src/signer.ts b/packages/waas-ethers/src/signer.ts index 34a8e652b..946eb49c2 100644 --- a/packages/waas-ethers/src/signer.ts +++ b/packages/waas-ethers/src/signer.ts @@ -58,7 +58,7 @@ export class SequenceSigner extends ethers.AbstractSigner { await this._ensureNetworkValid(false) const typedDataDigest = ethers.TypedDataEncoder.encode(domain, types, value) - + const args = { message: typedDataDigest, network: await this.getSimpleNetwork(),