1 | import { Account, AddressString, Block, ClaimTransaction, Hash256String, InvocationTransaction, NetworkType, RawCallReceipt, SmartContractDefinition, Transaction, TransactionOptions, TransactionReceipt, TransactionResult, Transfer, UpdateAccountNameOptions, UserAccount, UserAccountID, UserAccountProvider, UserAccountProviders } from '@neo-one/client-common';
|
2 | import { Monitor } from '@neo-one/monitor';
|
3 | import BigNumber from 'bignumber.js';
|
4 | import { BehaviorSubject, Observable } from 'rxjs';
|
5 | import { AsyncParallelHook } from 'tapable';
|
6 | import { SmartContract, SmartContractAny } from './types';
|
7 |
|
8 |
|
9 |
|
10 | export interface ClientHooks {
|
11 | |
12 |
|
13 |
|
14 | readonly beforeRelay: AsyncParallelHook<TransactionOptions>;
|
15 | |
16 |
|
17 |
|
18 | readonly relayError: AsyncParallelHook<Error>;
|
19 | |
20 |
|
21 |
|
22 | readonly afterRelay: AsyncParallelHook<Transaction>;
|
23 | |
24 |
|
25 |
|
26 | readonly beforeConfirmed: AsyncParallelHook<Transaction>;
|
27 | |
28 |
|
29 |
|
30 | readonly confirmedError: AsyncParallelHook<Transaction, Error>;
|
31 | |
32 |
|
33 |
|
34 | readonly afterConfirmed: AsyncParallelHook<Transaction, TransactionReceipt>;
|
35 | |
36 |
|
37 |
|
38 | readonly afterCall: AsyncParallelHook<RawCallReceipt>;
|
39 | |
40 |
|
41 |
|
42 | readonly callError: AsyncParallelHook<Error>;
|
43 | }
|
44 |
|
45 |
|
46 |
|
47 | export interface UserAccountFeatures {
|
48 | |
49 |
|
50 |
|
51 | readonly delete: boolean;
|
52 | |
53 |
|
54 |
|
55 | readonly updateName: boolean;
|
56 | }
|
57 |
|
58 |
|
59 |
|
60 | export interface BlockEntry {
|
61 | |
62 |
|
63 |
|
64 | readonly block: Block;
|
65 | |
66 |
|
67 |
|
68 | readonly network: NetworkType;
|
69 | }
|
70 |
|
71 |
|
72 |
|
73 | export interface AccountStateEntry {
|
74 | |
75 |
|
76 |
|
77 | readonly currentUserAccount: UserAccount;
|
78 | |
79 |
|
80 |
|
81 | readonly account: Account;
|
82 | }
|
83 |
|
84 |
|
85 |
|
86 |
|
87 |
|
88 | export declare class Client<TUserAccountProvider extends UserAccountProvider = any, TUserAccountProviders extends UserAccountProviders<TUserAccountProvider> = any> {
|
89 | |
90 |
|
91 |
|
92 | readonly hooks: ClientHooks;
|
93 | |
94 |
|
95 |
|
96 |
|
97 |
|
98 | readonly currentUserAccount$: Observable<UserAccount | undefined>;
|
99 | |
100 |
|
101 |
|
102 |
|
103 |
|
104 | readonly userAccounts$: Observable<readonly UserAccount[]>;
|
105 | |
106 |
|
107 |
|
108 |
|
109 |
|
110 | readonly currentNetwork$: Observable<NetworkType>;
|
111 | |
112 |
|
113 |
|
114 |
|
115 |
|
116 | readonly networks$: Observable<readonly NetworkType[]>;
|
117 | protected readonly providers$: BehaviorSubject<TUserAccountProviders>;
|
118 | protected readonly selectedProvider$: BehaviorSubject<TUserAccountProvider>;
|
119 | private readonly currentNetworkInternal$;
|
120 | private readonly reset$;
|
121 | |
122 |
|
123 |
|
124 |
|
125 |
|
126 | readonly block$: Observable<BlockEntry>;
|
127 | |
128 |
|
129 |
|
130 |
|
131 |
|
132 | readonly accountState$: Observable<AccountStateEntry | undefined>;
|
133 | constructor(providersIn: TUserAccountProviders);
|
134 | /**
|
135 | * The configured `UserAccountProvider`s for this `Client` instance.
|
136 | */
|
137 | readonly providers: TUserAccountProviders;
|
138 | /**
|
139 | * Get the details of the `UserAccount` for a given `UserAccountID`.
|
140 | *
|
141 | * @param idIn `UserAccountID` to find the `UserAccount` for
|
142 | * @returns `UserAccount` or throws an `UnknownAccountError` if one could not be found.
|
143 | */
|
144 | getUserAccount(idIn: UserAccountID): UserAccount;
|
145 | /**
|
146 | * Sets a `UserAccountID` as the currently selected `UserAccountID`.
|
147 | *
|
148 | * @param idIn `UserAccountID` to select, or `undefined` to deselect the current `UserAccountID`.
|
149 | */
|
150 | selectUserAccount(idIn?: UserAccountID): Promise<void>;
|
151 | /**
|
152 | * Sets a `NetworkType` as the currently selected `NetworkType`.
|
153 | *
|
154 | * @param networkIn `NetworkType` to select.
|
155 | */
|
156 | selectNetwork(networkIn: NetworkType): Promise<void>;
|
157 | /**
|
158 | * @returns `Promise` which resolves to the `UserAccountFeatures` supported by the given `UserAccountID`.
|
159 | */
|
160 | getSupportedFeatures(idIn: UserAccountID): Promise<UserAccountFeatures>;
|
161 | /**
|
162 | * Deletes the `UserAccountID` from its underlying provider. Throws an `DeleteUserAccountUnsupportedError` if the operation is unsupported.
|
163 | *
|
164 | * Users should check `getSupportedFeatures` before calling this method.
|
165 | */
|
166 | deleteUserAccount(idIn: UserAccountID): Promise<void>;
|
167 | /**
|
168 | * Updates the name of the `UserAccountID` in the underlying provider. Throws an `UpdateUserAccountUnsupportedError` if the operation is unsupported.
|
169 | *
|
170 | * Users should check `getSupportedFeatures` before calling this method.
|
171 | */
|
172 | updateUserAccountName(options: UpdateAccountNameOptions): Promise<void>;
|
173 | /**
|
174 | * @returns the currently selected `UserAccount` or `undefined` if there are no `UserAccount`s.
|
175 | */
|
176 | getCurrentUserAccount(): UserAccount | undefined;
|
177 | /**
|
178 | * @returns the currently selected `NetworkType`
|
179 | */
|
180 | getCurrentNetwork(): NetworkType;
|
181 | /**
|
182 | * @returns a list of all available `UserAccount`s
|
183 | */
|
184 | getUserAccounts(): readonly UserAccount[];
|
185 | /**
|
186 | * @returns a list of all available `NetworkType`s
|
187 | */
|
188 | getNetworks(): readonly NetworkType[];
|
189 | /**
|
190 | * Constructs a `SmartContract` instance for the provided `definition` backed by this `Client` instance.
|
191 | */
|
192 | smartContract<T extends SmartContract<any, any> = SmartContractAny>(definition: SmartContractDefinition): T;
|
193 | /**
|
194 | * Transfer native assets in the specified amount(s) to the specified Address(es).
|
195 | *
|
196 | * Accepts either a single transfer or an array of transfer objects.
|
197 | *
|
198 | * Note that we use an `InvocationTransaction` for transfers in order to reduce the overall bundle size since they can be used equivalently to `ContractTransaction`s.
|
199 | *
|
200 | * @returns `Promise<TransactionResult<TransactionReceipt, InvocationTransaction>>`.
|
201 | */
|
202 | transfer(amount: BigNumber, asset: Hash256String, to: AddressString, options?: TransactionOptions): Promise<TransactionResult<TransactionReceipt, InvocationTransaction>>;
|
203 | transfer(transfers: readonly Transfer[], options?: TransactionOptions): Promise<TransactionResult>;
|
204 | /**
|
205 | * Claim all available unclaimed `GAS` for the currently selected account (or the specified `from` `UserAccountID`).
|
206 | */
|
207 | claim(optionsIn?: TransactionOptions): Promise<TransactionResult<TransactionReceipt, ClaimTransaction>>;
|
208 | /**
|
209 | * @returns `Promise` which resolves to an `Account` object for the provided `UserAccountID`.
|
210 | */
|
211 | getAccount(id: UserAccountID, monitor?: Monitor): Promise<Account>;
|
212 | protected getProvider(options?: TransactionOptions): TUserAccountProvider;
|
213 | protected getNetworkProvider(network: NetworkType): TUserAccountProvider;
|
214 | protected applyBeforeRelayHook(options: TransactionOptions): Promise<void>;
|
215 | protected addTransactionHooks<TTransactionResult extends TransactionResult>(res: Promise<TTransactionResult>): Promise<TTransactionResult>;
|
216 | protected getTransfersOptions(argsIn: readonly any[]): {
|
217 | readonly transfers: readonly Transfer[];
|
218 | readonly options: TransactionOptions;
|
219 | };
|
220 | }
|