Skip to content

Commit f88979b

Browse files
chore: migration to typescript privacy modifier style (#309)
1 parent df3a695 commit f88979b

File tree

6 files changed

+137
-161
lines changed

6 files changed

+137
-161
lines changed

src/network/createNetworkProvider.ts

Lines changed: 58 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,14 @@ export type Args = arg.Result<typeof argSpec>;
7272
type ContractProviderFactory = (params: { address: Address; init?: StateInit | null }) => ContractProvider;
7373

7474
class SendProviderSender implements SenderWithSendResult {
75-
#provider: SendProvider;
7675
readonly address?: Address;
7776

78-
#lastSendResult?: unknown;
77+
private _lastSendResult?: unknown;
7978
get lastSendResult() {
80-
return this.#lastSendResult;
79+
return this._lastSendResult;
8180
}
8281

83-
constructor(provider: SendProvider) {
84-
this.#provider = provider;
82+
constructor(private readonly provider: SendProvider) {
8583
this.address = provider.address();
8684
}
8785

@@ -97,7 +95,7 @@ class SendProviderSender implements SenderWithSendResult {
9795
throw new Error('Deployer sender does not support `sendMode` other than `PAY_GAS_SEPARATELY`');
9896
}
9997

100-
this.#lastSendResult = await this.#provider.sendTransaction(
98+
this._lastSendResult = await this.provider.sendTransaction(
10199
args.to,
102100
args.value,
103101
args.body ?? undefined,
@@ -107,28 +105,29 @@ class SendProviderSender implements SenderWithSendResult {
107105
}
108106

109107
class WrappedContractProvider implements ContractProvider {
110-
#address: Address;
111-
#provider: ContractProvider;
112-
#init?: StateInit | null;
113-
#factory: ContractProviderFactory;
108+
private readonly provider: ContractProvider;
114109

115-
constructor(address: Address, factory: ContractProviderFactory, init?: StateInit | null) {
116-
this.#address = address;
117-
this.#provider = factory({ address, init });
118-
this.#init = init;
119-
this.#factory = factory;
110+
constructor(
111+
private readonly address: Address,
112+
private readonly factory: ContractProviderFactory,
113+
private readonly init: StateInit | null = null,
114+
) {
115+
this.address = address;
116+
this.provider = factory({ address, init });
117+
this.init = init;
118+
this.factory = factory;
120119
}
121120

122121
async getState() {
123-
return await this.#provider.getState();
122+
return await this.provider.getState();
124123
}
125124

126125
async get(name: string, args: TupleItem[]) {
127-
return await this.#provider.get(name, args);
126+
return await this.provider.get(name, args);
128127
}
129128

130129
async external(message: Cell) {
131-
return await this.#provider.external(message);
130+
return await this.provider.external(message);
132131
}
133132

134133
async internal(
@@ -140,10 +139,10 @@ class WrappedContractProvider implements ContractProvider {
140139
body: string | Cell | undefined | null;
141140
},
142141
) {
143-
const init = this.#init && (await this.getState()).state.type !== 'active' ? this.#init : undefined;
142+
const init = this.init && (await this.getState()).state.type !== 'active' ? this.init : undefined;
144143

145144
return await via.send({
146-
to: this.#address,
145+
to: this.address,
147146
value: typeof args.value === 'string' ? toNano(args.value) : args.value,
148147
sendMode: args.sendMode,
149148
bounce: args.bounce,
@@ -155,55 +154,43 @@ class WrappedContractProvider implements ContractProvider {
155154
open<T extends Contract>(contract: T): OpenedContract<T> {
156155
return openContract(
157156
contract,
158-
(params) => new WrappedContractProvider(params.address, this.#factory, params.init),
157+
(params) => new WrappedContractProvider(params.address, this.factory, params.init),
159158
);
160159
}
161160

162161
getTransactions(address: Address, lt: bigint, hash: Buffer, limit?: number): Promise<Transaction[]> {
163-
return this.#provider.getTransactions(address, lt, hash, limit);
162+
return this.provider.getTransactions(address, lt, hash, limit);
164163
}
165164
}
166165

167166
class NetworkProviderImpl implements NetworkProvider {
168-
#tc: BlueprintTonClient;
169-
#sender: SenderWithSendResult;
170-
#network: Network;
171-
#explorer: Explorer;
172-
#ui: UIProvider;
173-
174167
constructor(
175-
tc: BlueprintTonClient,
176-
sender: SenderWithSendResult,
177-
network: Network,
178-
explorer: Explorer,
179-
ui: UIProvider,
180-
) {
181-
this.#tc = tc;
182-
this.#sender = sender;
183-
this.#network = network;
184-
this.#explorer = explorer;
185-
this.#ui = ui;
186-
}
168+
private readonly _tc: BlueprintTonClient,
169+
private readonly _sender: SenderWithSendResult,
170+
private readonly _network: Network,
171+
private readonly _explorer: Explorer,
172+
private readonly _ui: UIProvider,
173+
) {}
187174

188175
network(): 'mainnet' | 'testnet' | 'custom' {
189-
return this.#network;
176+
return this._network;
190177
}
191178

192-
explorer(): Explorer {
193-
return this.#explorer;
179+
explorer(): 'tonscan' | 'tonviewer' | 'toncx' | 'dton' {
180+
return this._explorer;
194181
}
195182

196183
sender(): SenderWithSendResult {
197-
return this.#sender;
184+
return this._sender;
198185
}
199186

200187
api(): BlueprintTonClient {
201-
return this.#tc;
188+
return this._tc;
202189
}
203190

204191
provider(address: Address, init?: StateInit | null): ContractProvider {
205192
const factory = (params: { address: Address; init?: StateInit | null }) =>
206-
this.#tc.provider(
193+
this._tc.provider(
207194
params.address,
208195
params.init && {
209196
...params.init,
@@ -215,7 +202,7 @@ class NetworkProviderImpl implements NetworkProvider {
215202
}
216203

217204
async isContractDeployed(address: Address): Promise<boolean> {
218-
return (await this.#tc.provider(address).getState()).state.type === 'active';
205+
return (await this._tc.provider(address).getState()).state.type === 'active';
219206
}
220207

221208
async getConfig(address: Address = CONFIG_ADDRESS) {
@@ -239,7 +226,7 @@ class NetworkProviderImpl implements NetworkProvider {
239226
}
240227

241228
async getContractState(address: Address): Promise<ContractState> {
242-
return await this.#tc.provider(address).getState();
229+
return await this._tc.provider(address).getState();
243230
}
244231

245232
async waitForDeploy(address: Address, attempts: number = 20, sleepDuration: number = 2000) {
@@ -248,27 +235,27 @@ class NetworkProviderImpl implements NetworkProvider {
248235
}
249236

250237
for (let i = 1; i <= attempts; i++) {
251-
this.#ui.setActionPrompt(`Awaiting contract deployment... [Attempt ${i}/${attempts}]`);
238+
this._ui.setActionPrompt(`Awaiting contract deployment... [Attempt ${i}/${attempts}]`);
252239
const isDeployed = await this.isContractDeployed(address);
253240
if (isDeployed) {
254-
const formattedAddress = address.toString({ testOnly: this.#network === 'testnet' });
241+
const formattedAddress = address.toString({ testOnly: this._network === 'testnet' });
255242

256-
this.#ui.clearActionPrompt();
257-
this.#ui.write(`Contract deployed at address ${formattedAddress}`);
258-
this.#ui.write(
259-
`You can view it at ${getExplorerLink(formattedAddress, this.#network, this.#explorer)}`,
243+
this._ui.clearActionPrompt();
244+
this._ui.write(`Contract deployed at address ${formattedAddress}`);
245+
this._ui.write(
246+
`You can view it at ${getExplorerLink(formattedAddress, this._network, this._explorer)}`,
260247
);
261248
return;
262249
}
263250
await sleep(sleepDuration);
264251
}
265252

266-
this.#ui.clearActionPrompt();
253+
this._ui.clearActionPrompt();
267254
throw new Error("Contract was not deployed. Check your wallet's transactions");
268255
}
269256

270257
private obtainInMessageHash() {
271-
const { lastSendResult } = this.#sender;
258+
const { lastSendResult } = this._sender;
272259
if (
273260
typeof lastSendResult === 'object' &&
274261
lastSendResult !== null &&
@@ -284,11 +271,11 @@ class NetworkProviderImpl implements NetworkProvider {
284271
}
285272

286273
private async getLastTransactions(address: Address): Promise<Transaction[]> {
287-
if (this.#tc instanceof TonClient) {
288-
return this.#tc.getTransactions(address, { limit: 100, archival: true }); // without archival not working with tonclient
274+
if (this._tc instanceof TonClient) {
275+
return this._tc.getTransactions(address, { limit: 100, archival: true }); // without archival not working with tonclient
289276
}
290277

291-
const provider = this.#tc.provider(address);
278+
const provider = this._tc.provider(address);
292279
const { last } = await provider.getState();
293280
if (!last) {
294281
return [];
@@ -301,7 +288,7 @@ class NetworkProviderImpl implements NetworkProvider {
301288
address: Address,
302289
targetInMessageHash: Buffer,
303290
): Promise<{ isApplied: false } | { isApplied: true; transaction: Transaction }> {
304-
const provider = this.#tc.provider(address);
291+
const provider = this._tc.provider(address);
305292
const { last } = await provider.getState();
306293
if (!last) {
307294
return { isApplied: false };
@@ -333,28 +320,28 @@ class NetworkProviderImpl implements NetworkProvider {
333320
if (attempts <= 0) {
334321
throw new Error('Attempt number must be positive');
335322
}
336-
if (!this.#sender.address) {
323+
if (!this._sender.address) {
337324
throw new Error('Sender must have an address');
338325
}
339326

340327
const inMessageHash = this.obtainInMessageHash();
341328

342329
for (let i = 1; i <= attempts; i++) {
343-
this.#ui.setActionPrompt(`Awaiting transaction... [Attempt ${i}/${attempts}]`);
344-
const result = await this.isTransactionApplied(this.#sender.address, inMessageHash);
330+
this._ui.setActionPrompt(`Awaiting transaction... [Attempt ${i}/${attempts}]`);
331+
const result = await this.isTransactionApplied(this._sender.address, inMessageHash);
345332
if (result.isApplied) {
346333
const { transaction } = result;
347-
this.#ui.clearActionPrompt();
348-
this.#ui.write(`Transaction ${inMessageHash.toString('hex')} successfully applied!`);
349-
this.#ui.write(
334+
this._ui.clearActionPrompt();
335+
this._ui.write(`Transaction ${inMessageHash.toString('hex')} successfully applied!`);
336+
this._ui.write(
350337
`You can view it at ${getTransactionLink(
351338
{
352339
...transaction,
353340
hash: transaction.hash(),
354-
address: this.#sender.address,
341+
address: this._sender.address,
355342
},
356-
this.#network,
357-
this.#explorer,
343+
this._network,
344+
this._explorer,
358345
)}`,
359346
);
360347
return;
@@ -381,7 +368,7 @@ class NetworkProviderImpl implements NetworkProvider {
381368
throw new Error('Contract has no init!');
382369
}
383370

384-
await this.#sender.send({
371+
await this._sender.send({
385372
to: contract.address,
386373
value,
387374
body,
@@ -398,7 +385,7 @@ class NetworkProviderImpl implements NetworkProvider {
398385
}
399386

400387
ui(): UIProvider {
401-
return this.#ui;
388+
return this._ui;
402389
}
403390
}
404391

src/network/send/DeeplinkProvider.ts

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,10 @@ import { UIProvider } from '../../ui/UIProvider';
77
import { Network } from '../Network';
88

99
export class DeeplinkProvider implements SendProvider {
10-
#network: Network;
11-
#ui: UIProvider;
12-
13-
constructor(network: Network, ui: UIProvider) {
14-
this.#network = network;
15-
this.#ui = ui;
16-
}
10+
constructor(
11+
private readonly network: Network,
12+
private readonly ui: UIProvider,
13+
) {}
1714

1815
async connect(): Promise<void> {
1916
return;
@@ -25,23 +22,23 @@ export class DeeplinkProvider implements SendProvider {
2522
amount,
2623
payload,
2724
stateInit ? beginCell().storeWritable(storeStateInit(stateInit)).endCell() : undefined,
28-
this.#network === 'testnet',
25+
this.network === 'testnet',
2926
);
3027

3128
try {
32-
this.#ui.write('\n');
33-
qrcode.generate(deepLink, { small: true }, (qr) => this.#ui.write(qr));
34-
this.#ui.write('\n');
35-
this.#ui.write(deepLink);
36-
this.#ui.write('\nScan the QR code above, or open the ton:// link to send this transaction');
29+
this.ui.write('\n');
30+
qrcode.generate(deepLink, { small: true }, (qr) => this.ui.write(qr));
31+
this.ui.write('\n');
32+
this.ui.write(deepLink);
33+
this.ui.write('\nScan the QR code above, or open the ton:// link to send this transaction');
3734

38-
await this.#ui.prompt('Press enter when transaction was issued');
35+
await this.ui.prompt('Press enter when transaction was issued');
3936
} catch (err: unknown) {
40-
this.#ui.write(deepLink);
41-
this.#ui.write('\n');
37+
this.ui.write(deepLink);
38+
this.ui.write('\n');
4239

4340
if (err instanceof Error && err.message.includes('code length overflow')) {
44-
this.#ui.write(
41+
this.ui.write(
4542
'Message is too large to be sent via QR code. Please use the ton:// link or another method.',
4643
);
4744
process.exit(1);

0 commit comments

Comments
 (0)