Skip to content

Commit

Permalink
Merge pull request #26031 from hardforkio/feature/add-web3
Browse files Browse the repository at this point in the history
Add support for web3
  • Loading branch information
armanio123 committed Jun 7, 2018
2 parents 1b5546a + 2a5507a commit ebadb72
Show file tree
Hide file tree
Showing 13 changed files with 829 additions and 0 deletions.
40 changes: 40 additions & 0 deletions types/web3/eth/abi.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
export interface ABIDefinition {
constant?: boolean;
payable?: boolean;
anonymous?: boolean;
inputs?: Array<{ name: string; type: ABIDataTypes; indexed?: boolean }>;
name?: string;
outputs?: Array<{ name: string; type: ABIDataTypes }>;
type: "function" | "constructor" | "event" | "fallback";
}

type ABIDataTypes = "uint256" | "boolean" | "string" | "bytes" | string; // TODO complete list

export default interface ABI {
decodeLog(inputs: object, hexString: string, topics: string[]): object;
encodeParameter(type: string, parameter: any): string;
encodeParameters(types: string[], paramaters: any[]): string;
encodeEventSignature(name: string | object): string;
encodeFunctionCall(jsonInterface: object, parameters: any[]): string;
encodeFunctionSignature(name: string | object): string;
decodeParameter(type: string, hex: string): any;
decodeParameters(
types: string[],
hex: string
): EthAbiDecodeParametersResultArray;
decodeParameters(
types: EthAbiDecodeParametersType[],
hex: string
): EthAbiDecodeParametersResultObject;
}

interface EthAbiDecodeParametersType {
name: string;
type: string;
}
interface EthAbiDecodeParametersResultArray {
[index: number]: any;
}
type EthAbiDecodeParametersResultObject = EthAbiDecodeParametersResultArray & {
[key: string]: any;
};
71 changes: 71 additions & 0 deletions types/web3/eth/accounts.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { Tx } from "./types";

export interface Account {
address: string;
privateKey: string;
publicKey: string;
}

export interface Signature {
message: string;
hash: string;
r: string;
s: string;
v: string;
}

export interface PrivateKey {
address: string;
Crypto: {
cipher: string;
ciphertext: string;
cipherparams: {
iv: string;
};
kdf: string;
kdfparams: {
dklen: number;
n: number;
p: number;
r: number;
salt: string;
};
mac: string;
};
id: string;
version: number;
}

export default interface Accounts {
create(entropy?: string): Account;
privateKeyToAccount(privKey: string): Account;
publicToAddress(key: string): string;
signTransaction(
tx: Tx,
privateKey: string,
returnSignature?: boolean,
cb?: (err: Error, result: string | Signature) => void
): Promise<string> | Signature;
recoverTransaction(signature: string | Signature): string;
sign(
data: string,
privateKey: string,
returnSignature?: boolean
): string | Signature;
recover(
sigOrHash: string | Signature,
sigOrV?: string,
r?: string,
s?: string
): string;
encrypt(privateKey: string, password: string): PrivateKey;
decrypt(privateKey: PrivateKey, password: string): Account;
wallet: {
create(numberOfAccounts: number, entropy: string): Account[];
add(account: string | Account): any;
remove(account: string | number): any;
save(password: string, keyname?: string): string;
load(password: string, keyname: string): any;
clear(): any;
};
}
68 changes: 68 additions & 0 deletions types/web3/eth/contract.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { Callback, EventLog, EventEmitter } from "../types";
import { TransactionObject, BlockType } from "./types";
import { ABIDefinition } from "./abi";
import BigNumber = require("bn.js");
import { Provider } from "../providers";

interface CustomOptions {
address?: string;
jsonInterface?: ABIDefinition[];
data?: string;
from?: string;
gasPrice?: string;
gas?: number;
}

interface contractOptions {
address: string;
jsonInterface: ABIDefinition[];
data: string;
from: string;
gasPrice: string;
gas: number;
}

export default class Contract {
constructor(
jsonInterface: any[],
address?: string,
options?: CustomOptions
);
options: contractOptions;
methods: {
[fnName: string]: (...args: any[]) => TransactionObject<any>;
};
deploy(options: {
data: string;
arguments: any[];
}): TransactionObject<Contract>;
events: {
[eventName: string]: (
options?: {
filter?: object;
fromBlock?: BlockType;
topics?: string[];
},
cb?: Callback<EventLog>
) => EventEmitter;
allEvents: (
options?: {
filter?: object;
fromBlock?: BlockType;
topics?: string[];
},
cb?: Callback<EventLog>
) => EventEmitter;
};
getPastEvents(
event: string,
options?: {
filter?: object;
fromBlock?: BlockType;
toBlock?: BlockType;
topics?: string[];
},
cb?: Callback<EventLog[]>
): Promise<EventLog[]>;
setProvider(provider: Provider): void;
}
185 changes: 185 additions & 0 deletions types/web3/eth/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
import BigNumber = require("bn.js");
import { Provider } from "../providers";
import Contract, { CustomOptions as CustomContractOptions } from "./contract";
import PromiEvent from "../promiEvent";
import ABI from "./abi";
import Accounts from "./accounts";
import {
BatchRequest,
Iban,
BlockHeader,
CompileResult,
Block,
Transaction,
Tx,
BlockType,
Net,
Personal
} from "./types";
import {
Callback,
TransactionReceipt,
Logs,
Log,
Subscribe,
EncodedTransaction
} from "../types";

export default interface Eth {
defaultAccount: string;
defaultBlock: BlockType;
BatchRequest: new () => BatchRequest;
Iban: Iban;
Contract: new (
jsonInterface: any[],
address?: string,
options?: CustomContractOptions
) => Contract;
abi: ABI;
setProvider: (provider: Provider) => void;
accounts: Accounts;
call(
callObject: Tx,
defaultBloc?: BlockType,
callBack?: Callback<string>
): Promise<string>;
clearSubscriptions(): boolean;
subscribe(
type: "logs",
options?: Logs,
callback?: Callback<Subscribe<Log>>
): Promise<Subscribe<Log>>;
subscribe(
type: "syncing",
callback?: Callback<Subscribe<any>>
): Promise<Subscribe<any>>;
subscribe(
type: "newBlockHeaders",
callback?: Callback<Subscribe<BlockHeader>>
): Promise<Subscribe<BlockHeader>>;
subscribe(
type: "pendingTransactions",
callback?: Callback<Subscribe<Transaction>>
): Promise<Subscribe<Transaction>>;
subscribe(
type: "pendingTransactions" | "newBlockHeaders" | "syncing" | "logs",
options?: Logs,
callback?: Callback<Subscribe<any>>
): Promise<Subscribe<any>>;

unsubscribe(callBack: Callback<boolean>): void | boolean;
compile: {
solidity(
source: string,
callback?: Callback<CompileResult>
): Promise<CompileResult>;
lll(
source: string,
callback?: Callback<CompileResult>
): Promise<CompileResult>;
serpent(
source: string,
callback?: Callback<CompileResult>
): Promise<CompileResult>;
};
currentProvider: Provider;
estimateGas(tx: Tx, callback?: Callback<number>): Promise<number>;
getAccounts(cb?: Callback<string[]>): Promise<string[]>;
getBalance(
address: string,
defaultBlock?: BlockType,
cb?: Callback<number>
): Promise<number>;
getBlock(
number: BlockType,
returnTransactionObjects?: boolean,
cb?: Callback<Block>
): Promise<Block>;
getBlockNumber(callback?: Callback<number>): Promise<number>;
getBlockTransactionCount(
number: BlockType | string,
cb?: Callback<number>
): Promise<number>;
getBlockUncleCount(
number: BlockType | string,
cb?: Callback<number>
): Promise<number>;
getCode(
address: string,
defaultBlock?: BlockType,
cb?: Callback<string>
): Promise<string>;
getCoinbase(cb?: Callback<string>): Promise<string>;
getCompilers(cb?: Callback<string[]>): Promise<string[]>;
getGasPrice(cb?: Callback<number>): Promise<number>;
getHashrate(cb?: Callback<number>): Promise<number>;
getPastLogs(
options: {
fromBlock?: BlockType;
toBlock?: BlockType;
address: string;
topics?: Array<string | string[]>;
},
cb?: Callback<Log[]>
): Promise<Log[]>;
getProtocolVersion(cb?: Callback<string>): Promise<string>;
getStorageAt(
address: string,
defaultBlock?: BlockType,
cb?: Callback<string>
): Promise<string>;
getTransactionReceipt(
hash: string,
cb?: Callback<TransactionReceipt>
): Promise<TransactionReceipt>;
getTransaction(
hash: string,
cb?: Callback<Transaction>
): Promise<Transaction>;
getTransactionCount(
address: string,
defaultBlock?: BlockType,
cb?: Callback<number>
): Promise<number>;
getTransactionFromBlock(
block: BlockType,
index: number,
cb?: Callback<Transaction>
): Promise<Transaction>;
getUncle(
blockHashOrBlockNumber: BlockType | string,
uncleIndex: number,
returnTransactionObjects?: boolean,
cb?: Callback<Block>
): Promise<Block>;
getWork(cb?: Callback<string[]>): Promise<string[]>;
givenProvider: Provider;
isMining(cb?: Callback<boolean>): Promise<boolean>;
isSyncing(cb?: Callback<boolean>): Promise<boolean>;
net: Net;
personal: Personal;
signTransaction(
tx: Tx,
address?: string,
cb?: Callback<string>
): Promise<EncodedTransaction>;
sendSignedTransaction(
data: string,
cb?: Callback<string>
): PromiEvent<TransactionReceipt>;
sendTransaction(
tx: Tx,
cb?: Callback<string>
): PromiEvent<TransactionReceipt>;
submitWork(
nonce: string,
powHash: string,
digest: string,
cb?: Callback<boolean>
): Promise<boolean>;
sign(
address: string,
dataToSign: string,
cb?: Callback<string>
): Promise<string>;
}

0 comments on commit ebadb72

Please sign in to comment.