UNPKG

3.79 kBTypeScriptView Raw
1// import Big from 'big.mjs';
2// export type Hash = string;
3
4type Big = number;
5type Provider = any;
6type stringOrNumber = string | number;
7type stringOrBuffer = string | Buffer;
8
9export type CFXTAG = 'earliest' | 'latest_mined' | 'latest_state' | 'latest_checkpoint';
10export type Address = string;
11export type Quantity = string | number | Big; // 0x0 | normal number | big number
12export type EpochNumber = string | number | CFXTAG;
13
14export interface ConfluxOption {
15 url: string,
16 defaultEpoch: stringOrNumber, // default 'latest_state'
17 defaultGasPrice: stringOrNumber,
18 defaultGas: stringOrNumber,
19 defaultStorageLimit: stringOrNumber,
20 defaultChainId: number,
21}
22
23export 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
58export 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
73export 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
83export 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
98export 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
108export 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
119export class HttpProvider {
120 constructor(url: string, options: any);
121 call(method: string, ...params: any[]): any; // params can be multiple
122}
123
124export interface ContractOption {
125 abi: [];
126 address: string;
127 bytecode: string;
128}
129
130export class Contract {
131 constructor(cfx: Conflux, options: ContractOption);
132 abi: any;
133 address: string;
134}