Skip to content

Commit fe9de38

Browse files
committed
feat: change fn that checks blockchain client is connected, add more logs
1 parent 9b8bea4 commit fe9de38

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

packages/cli/package/src/lib/dealClient.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,23 +140,36 @@ export async function resolveDeployment() {
140140

141141
async function createContracts(signerOrProvider: Provider | Signer) {
142142
const { Contracts } = await import("@fluencelabs/deal-ts-clients");
143-
const contracts = new Contracts(signerOrProvider, await resolveDeployment());
143+
144+
const newContracts = new Contracts(
145+
signerOrProvider,
146+
await resolveDeployment(),
147+
);
148+
149+
if (contracts !== undefined || readonlyContracts !== undefined) {
150+
return newContracts;
151+
}
144152

145153
await setTryTimeout(
146154
"check if blockchain client is connected",
147155
async () => {
156+
dbg(
157+
"Going to run contracts.diamond.bytesPerRam() to check if blockchain client is connected",
158+
);
159+
148160
// By calling this method we ensure that the blockchain client is connected
149-
await contracts.diamond.minDealDepositedEpochs();
161+
await newContracts.diamond.bytesPerRam();
162+
dbg("Blockchain client is connected");
150163
},
151164
(err) => {
152165
commandObj.error(
153-
`Check if blockchain client is connected by running contracts.diamond.minDealDepositedEpochs() failed: ${stringifyUnknown(err)}`,
166+
`Check if blockchain client is connected by running contracts.diamond.bytesPerRam() failed: ${stringifyUnknown(err)}`,
154167
);
155168
},
156169
1000 * 5, // 5 seconds
157170
);
158171

159-
return contracts;
172+
return newContracts;
160173
}
161174

162175
export async function ensureJsonRpcProvider(): Promise<Provider> {

packages/cli/package/src/lib/helpers/setTryTimeout.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,17 @@ export async function setTryTimeout<T, U>(
4848
try {
4949
dbg(`Trying to ${yellowMessage}`);
5050
const res = await callbackToTry();
51-
clearTimeout(timeout);
52-
isTrying = false;
5351

5452
if (attemptCounter > 1) {
5553
commandObj.logToStderr(
5654
`Succeeded to ${yellowMessage} after ${numToStr(attemptCounter)} attempts`,
5755
);
56+
} else {
57+
dbg(`Succeeded to ${yellowMessage}`);
5858
}
5959

60+
clearTimeout(timeout);
61+
isTrying = false;
6062
return res;
6163
} catch (e) {
6264
if (failCondition !== undefined && failCondition(e)) {

0 commit comments

Comments
 (0)