Skip to content

Commit 136dbce

Browse files
committed
refactor: improve error logging
1 parent d2e8d5b commit 136dbce

File tree

1 file changed

+66
-40
lines changed

1 file changed

+66
-40
lines changed

packages/sequencer/src/settlement/SettlementModule.ts

Lines changed: 66 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,15 @@ import {
99
SettlementSmartContractBase,
1010
DynamicBlockProof,
1111
} from "@proto-kit/protocol";
12-
import { AccountUpdate, fetchAccount, Field, Mina, PublicKey, TokenContract, TokenId } from "o1js";
12+
import {
13+
AccountUpdate,
14+
fetchAccount,
15+
Field,
16+
Mina,
17+
PublicKey,
18+
TokenContract,
19+
TokenId,
20+
} from "o1js";
1321
import { inject } from "tsyringe";
1422
import {
1523
EventEmitter,
@@ -351,53 +359,71 @@ export class SettlementModule
351359
).bridgeContractMina(),
352360
};
353361
}
354-
362+
355363
public async checkDeployment(
356-
tokenBridges?: Array<{ address: PublicKey; tokenId: Field }>
357-
): Promise<void | never> {
358-
const contractAddresses = this.getContractAddresses();
359-
360-
if (this.baseLayer.config.network.type !== 'local') {
361-
// Check main contracts
362-
await Promise.all(
363-
contractAddresses.map(async (pubKey) => {
364-
const { account, error } = await fetchAccount({ publicKey: pubKey });
365-
if (!account || !!error) {
366-
throw new Error(`Error finding account ${pubKey.toBase58()}`);
367-
}
368-
})
369-
);
370-
371-
// Check token bridges with their tokenIds
372-
if (tokenBridges) {
364+
tokenBridges?: Array<{ address: PublicKey; tokenId: Field }>
365+
): Promise<void | never> {
366+
const contractAddresses = this.getContractAddresses();
367+
368+
if (this.baseLayer.config.network.type !== "local") {
369+
// Check main contracts
373370
await Promise.all(
374-
tokenBridges.map(async ({ address, tokenId }) => {
375-
const { account, error } = await fetchAccount({
376-
publicKey: address,
377-
tokenId
378-
});
379-
if (!account || !!error) {
380-
throw new Error(`Error finding token bridge ${address.toBase58()} @ ${tokenId.toString()}`);
371+
contractAddresses.map(async (pubKey) => {
372+
const { account, error } = await fetchAccount({ publicKey: pubKey });
373+
374+
if (!account) {
375+
let message = `Account ${pubKey.toBase58()} not found on chain`;
376+
377+
if (error !== undefined) {
378+
message += `: ${error.statusText}`;
379+
}
380+
381+
throw new Error(message);
381382
}
382383
})
383384
);
384-
}
385-
} else {
386-
// Local network
387-
contractAddresses.forEach((pubKey) => {
388-
if (!Mina.hasAccount(pubKey)) {
389-
throw new Error(`Contract ${pubKey.toBase58()} not found on local chain`);
385+
386+
// Check token bridges with their tokenIds
387+
if (tokenBridges) {
388+
await Promise.all(
389+
tokenBridges.map(async ({ address, tokenId }) => {
390+
const { account, error } = await fetchAccount({
391+
publicKey: address,
392+
tokenId,
393+
});
394+
395+
if (!account) {
396+
let message = `Account ${address.toBase58()} not found on chain`;
397+
398+
if (error !== undefined) {
399+
message += `: ${error.statusText}`;
400+
}
401+
402+
throw new Error(message);
403+
}
404+
})
405+
);
390406
}
391-
});
392-
393-
// Check token bridges
394-
if (tokenBridges) {
395-
tokenBridges.forEach(({ address, tokenId }) => {
396-
if (!Mina.hasAccount(address, tokenId)) {
397-
throw new Error(`Token bridge ${address.toBase58()} @ ${tokenId.toString()} not found`);
407+
} else {
408+
// Local network
409+
contractAddresses.forEach((pubKey) => {
410+
if (!Mina.hasAccount(pubKey)) {
411+
throw new Error(
412+
`Contract ${pubKey.toBase58()} not found on local chain`
413+
);
398414
}
399415
});
416+
417+
// Check token bridges
418+
if (tokenBridges) {
419+
tokenBridges.forEach(({ address, tokenId }) => {
420+
if (!Mina.hasAccount(address, tokenId)) {
421+
throw new Error(
422+
`Token bridge ${address.toBase58()} @ ${tokenId.toString()} not found`
423+
);
424+
}
425+
});
426+
}
400427
}
401428
}
402429
}
403-
}

0 commit comments

Comments
 (0)