Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jimchan3301 committed Oct 26, 2021
0 parents commit ba0288c
Show file tree
Hide file tree
Showing 22 changed files with 2,840 additions and 0 deletions.
12 changes: 12 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "web3cocos",
"version": "0.1.0",
"description": "A web3.js port for cocos creator 3",
"main": "web3.cjs.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Jim Chan",
"license": "ISC",
"types": "./types/web3/types/index.d.ts"
}
40 changes: 40 additions & 0 deletions types/web3-bzz/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
This file is part of web3.js.
web3.js is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
web3.js is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @file index.d.ts
* @author Josh Stevens <[email protected]>
* @date 2018
*/

export class Bzz {
constructor();
constructor(provider: any);

readonly givenProvider: any;
static readonly givenProvider: any;
readonly currentProvider: any;
setProvider(provider: any): boolean;

upload(data: any): Promise<string>;

download(bzzHash: string, localPath?: string): Promise<any>;

pick: Pick;
}

export interface Pick {
file: () => Promise<any>;
directory: () => Promise<any>;
data: () => Promise<any>;
}
252 changes: 252 additions & 0 deletions types/web3-core-helpers/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,252 @@
/*
This file is part of web3.js.
web3.js is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
web3.js is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @file index.d.ts
* @author Josh Stevens <[email protected]>
* @date 2018
*/

import * as net from 'net';
import * as http from 'http';
import * as https from 'https';

export class formatters {
static outputBigNumberFormatter(number: number): number;

static inputSignFormatter(data: string): string;

static inputAddressFormatter(address: string): string;

static isPredefinedBlockNumber(blockNumber: string): boolean;

static inputDefaultBlockNumberFormatter(blockNumber: string): string;

static inputBlockNumberFormatter(blockNumber: string | number): string | number;

static outputBlockFormatter(block: any): any; // TODO: Create Block interface

static txInputFormatter(txObject: any): any;

static inputCallFormatter(txObject: any): any;

static inputTransactionFormatter(txObject: any): any;

static outputTransactionFormatter(receipt: any): any;

static outputTransactionReceiptFormatter(receipt: any): any;

static inputLogFormatter(log: any): any;

static outputLogFormatter(log: any): any;

static inputPostFormatter(post: any): any; // TODO: Create Post interface

static outputPostFormatter(post: any): any; // TODO: Create Post interface

static outputSyncingFormatter(result: any): any; // TODO: Create SyncLog interface
}

export class errors {
static ErrorResponse(result: Error): Error;
static InvalidNumberOfParams(
got: number,
expected: number,
method: string
): Error;
static InvalidConnection(host: string, event?: WebSocketEvent): ConnectionError;
static InvalidProvider(): Error;
static InvalidResponse(result: Error): Error;
static ConnectionTimeout(ms: string): Error;
static ConnectionNotOpenError(): Error;
static ConnectionCloseError(event: WebSocketEvent | boolean): Error | ConnectionError;
static MaxAttemptsReachedOnReconnectingError(): Error;
static PendingRequestsOnReconnectingError(): Error;
static ConnectionError(msg: string, event?: WebSocketEvent): ConnectionError;
static RevertInstructionError(reason: string, signature: string): RevertInstructionError
static TransactionRevertInstructionError(reason: string, signature: string, receipt: object): TransactionRevertInstructionError
static TransactionError(message: string, receipt: object): TransactionError
static NoContractAddressFoundError(receipt: object): TransactionError
static ContractCodeNotStoredError(receipt: object): TransactionError
static TransactionRevertedWithoutReasonError(receipt: object): TransactionError
static TransactionOutOfGasError(receipt: object): TransactionError
static ResolverMethodMissingError(address: string, name: string): Error
static ContractMissingABIError(): Error
static ContractOnceRequiresCallbackError(): Error
static ContractEventDoesNotExistError(eventName: string): Error
static ContractReservedEventError(type: string): Error
static ContractMissingDeployDataError(): Error
static ContractNoAddressDefinedError(): Error
static ContractNoFromAddressDefinedError(): Error
}

export class WebsocketProviderBase {
constructor(host: string, options?: WebsocketProviderOptions);

isConnecting(): boolean;

requestQueue: Map<string, RequestItem>;
responseQueue: Map<string, RequestItem>;
connected: boolean;
connection: any;

supportsSubscriptions(): boolean;

send(
payload: JsonRpcPayload,
callback: (error: Error | null, result?: JsonRpcResponse) => void
): void;

on(type: string, callback: () => void): void;

once(type: string, callback: () => void): void;

removeListener(type: string, callback: () => void): void;

removeAllListeners(type: string): void;

reset(): void;

disconnect(code: number, reason: string): void;

connect(): void;

reconnect(): void;
}

export class IpcProviderBase {
constructor(path: string, net: net.Server);

responseCallbacks: any;
notificationCallbacks: any;
connected: boolean;
connection: any;

addDefaultEvents(): void;

supportsSubscriptions(): boolean;

send(
payload: JsonRpcPayload,
callback: (error: Error | null, result?: JsonRpcResponse) => void
): void;

on(type: string, callback: () => void): void;

once(type: string, callback: () => void): void;

removeListener(type: string, callback: () => void): void;

removeAllListeners(type: string): void;

reset(): void;

reconnect(): void;
}

export class HttpProviderBase {
constructor(host: string, options?: HttpProviderOptions);

host: string;
connected: boolean;

supportsSubscriptions(): boolean;

send(
payload: JsonRpcPayload,
callback: (error: Error | null, result?: JsonRpcResponse) => void
): void;

disconnect(): boolean;
}

export interface HttpProviderOptions {
keepAlive?: boolean;
timeout?: number;
headers?: HttpHeader[];
withCredentials?: boolean;
agent?: HttpAgent
}

export interface HttpAgent {
http?: http.Agent;
https?: https.Agent;
baseUrl?: string;
}

export interface HttpHeader {
name: string;
value: string;
}

export interface WebsocketProviderOptions {
host?: string;
timeout?: number;
reconnectDelay?: number;
headers?: any;
protocol?: string;
clientConfig?: object;
requestOptions?: any;
origin?: string;
reconnect?: ReconnectOptions;
}

export interface ReconnectOptions {
auto?: boolean;
delay?: number;
maxAttempts?: number;
onTimeout?: boolean;
}

export interface RequestItem {
payload: JsonRpcPayload;
callback: (error: any, result: any) => void;
}

export interface JsonRpcPayload {
jsonrpc: string;
method: string;
params: any[];
id?: string | number;
}

export interface JsonRpcResponse {
jsonrpc: string;
id: number;
result?: any;
error?: string;
}

export interface RevertInstructionError extends Error {
reason: string;
signature: string;
}

export interface TransactionRevertInstructionError extends Error {
reason: string;
signature: string;
}

export interface TransactionError extends Error {
receipt: object;
}

export interface ConnectionError extends Error {
code: string | undefined;
reason: string | undefined;
}

export interface WebSocketEvent {
code?: number;
reason?: string;
}
34 changes: 34 additions & 0 deletions types/web3-core-method/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
This file is part of web3.js.
web3.js is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
web3.js is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @file index.d.ts
* @author Samuel Furter <[email protected]>
* @date 2018
*/

import {JsonRpcPayload} from 'web3-core-helpers';

export interface Method {
name: string;
call: string;
params?: number;
inputFormatter?: Array<(() => void) | null>;
outputFormatter?: () => void;
transformPayload?: () => void;
extraFormatters?: any;
defaultBlock?: string;
defaultAccount?: string | null;
abiCoder?: any;
handleRevert?: boolean;
}
Loading

0 comments on commit ba0288c

Please sign in to comment.