1 |
|
2 |
|
3 |
|
4 | type Big = number;
|
5 | type Provider = any;
|
6 | type stringOrNumber = string | number;
|
7 | type stringOrBuffer = string | Buffer;
|
8 |
|
9 | export type CFXTAG = 'earliest' | 'latest_mined' | 'latest_state' | 'latest_checkpoint';
|
10 | export type Address = string;
|
11 | export type Quantity = string | number | Big;
|
12 | export type EpochNumber = string | number | CFXTAG;
|
13 |
|
14 | export interface ConfluxOption {
|
15 | url: string,
|
16 | defaultEpoch: stringOrNumber,
|
17 | defaultGasPrice: stringOrNumber,
|
18 | defaultGas: stringOrNumber,
|
19 | defaultStorageLimit: stringOrNumber,
|
20 | defaultChainId: number,
|
21 | }
|
22 |
|
23 | export class Conflux {
|
24 | constructor(options: ConfluxOption);
|
25 | provider: Provider;
|
26 | defaultEpoch: stringOrNumber;
|
27 | defaultGasPrice: stringOrNumber;
|
28 | defaultGas: stringOrNumber;
|
29 | defaultStorageLimit: stringOrNumber;
|
30 | defaultChainId: number;
|
31 |
|
32 | setProvider(provider: Provider): Provider;
|
33 | Account(string: string): any;
|
34 | Contract(options: any): any;
|
35 | close():any;
|
36 |
|
37 | getStatus(): Promise<any>;
|
38 | getGasPrice(): string;
|
39 | getEpochNumber(epochNumber: EpochNumber): EpochNumber;
|
40 | getLogs(options: any): any;
|
41 | getBalance(address: string, epochNumber: EpochNumber): string;
|
42 | getNextNonce(): Promise<number>;
|
43 | getConfirmationRiskByHash():Promise<number|null>;
|
44 | getBlockByEpochNumber(): Promise<object|null>;
|
45 | getBlocksByEpochNumber(): Promise<string[]>;
|
46 | getBestBlockHash(): string;
|
47 | getBlockByHash(): Promise<object|null>;
|
48 | getBlockByHashWithPivotAssumption(): any;
|
49 | getTransactionByHash(): Promise<object|null>;
|
50 | getTransactionReceipt(): Promise<object|null>;
|
51 | sendTransaction(): any;
|
52 | sendRawTransaction(): any;
|
53 | getCode(): Promise<string>;
|
54 | call(): Promise<string>;
|
55 | estimateGasAndCollateral(options: any): Promise<object>;
|
56 | }
|
57 |
|
58 | export class Account {
|
59 | constructor(privateKey: string);
|
60 | privateKey: any;
|
61 | publicKey: any;
|
62 | address: any;
|
63 |
|
64 | static random: (entropy: any) => Account;
|
65 | static decrypt: (password: string, info: any) => Account;
|
66 |
|
67 | encrypt(password: string): any;
|
68 | signTransaction(options: any): any;
|
69 | signMessage(message: string): any;
|
70 | toString(): string;
|
71 | }
|
72 |
|
73 | export class Message {
|
74 | constructor(message: string);
|
75 |
|
76 | static sign: (privateKey: any, messageHash: any) => string;
|
77 | static recover: (signature: any, messageHash: any) => any;
|
78 |
|
79 | sign(privateKey: any): Message;
|
80 | // TODO get: from, r, s, v, hash
|
81 | }
|
82 |
|
83 | export interface TransactionOption {
|
84 | nonce: stringOrNumber;
|
85 | gasPrice: stringOrNumber;
|
86 | gas: stringOrNumber;
|
87 | to: string;
|
88 | value: stringOrNumber;
|
89 | storageLimit: stringOrNumber;
|
90 | epochHeight: stringOrNumber;
|
91 | chainId: stringOrNumber;
|
92 | data: stringOrBuffer;
|
93 | r: stringOrBuffer;
|
94 | s: stringOrBuffer;
|
95 | v: number;
|
96 | }
|
97 |
|
98 | export class Transaction {
|
99 | constructor(options: any);
|
100 |
|
101 | sign(privateKey: string): Transaction;
|
102 | recover(): string;
|
103 | encode(includeSignature: boolean): Buffer;
|
104 | serialize(): string;
|
105 | // TODO get: hash, from
|
106 | }
|
107 |
|
108 | export class BaseProvider {
|
109 | constructor(url: string, options: any);
|
110 | url: string;
|
111 | timeout: number;
|
112 | logger: any;
|
113 |
|
114 | requestId(): string;
|
115 | call(): any;
|
116 | close(): any;
|
117 | }
|
118 |
|
119 | export class HttpProvider {
|
120 | constructor(url: string, options: any);
|
121 | call(method: string, ...params: any[]): any; // params can be multiple
|
122 | }
|
123 |
|
124 | export interface ContractOption {
|
125 | abi: [];
|
126 | address: string;
|
127 | bytecode: string;
|
128 | }
|
129 |
|
130 | export class Contract {
|
131 | constructor(cfx: Conflux, options: ContractOption);
|
132 | abi: any;
|
133 | address: string;
|
134 | }
|