Skip to content

Commit

Permalink
chore: update sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelTaylor3D committed Oct 3, 2024
1 parent 09c17a7 commit ed5f7ab
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions src/blockchain/StoreInfoCacheUpdater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
Peer,
getMainnetGenesisChallenge,
} from "@dignetwork/datalayer-driver";
import { get } from "lodash";

export class StoreInfoCacheUpdater {
private static instance: StoreInfoCacheUpdater;
Expand Down Expand Up @@ -52,7 +53,7 @@ export class StoreInfoCacheUpdater {
private async startMonitors() {
try {
console.log("Checking if lockfile exists...");

// Check if the lock file exists
if (!fs.existsSync(this.lockFilePath)) {
console.log("Lockfile does not exist. Proceeding without lock.");
Expand Down Expand Up @@ -80,7 +81,7 @@ export class StoreInfoCacheUpdater {
});

console.log("Lock acquired, starting monitors...");

// Renew the lock every minute by reacquiring it
this.renewLock();

Expand Down Expand Up @@ -190,12 +191,29 @@ export class StoreInfoCacheUpdater {

console.log(`Waiting for coin to be spent: ${coinId.toString("hex")}`);

// Wait for the coin to be spent
await peer.waitForCoinToBeSpent(
coinId,
latestHeight,
Buffer.from(latestHash, "hex")
);
try {
// Wait for the coin to be spent
await peer.waitForCoinToBeSpent(
coinId,
latestHeight,
Buffer.from(latestHash, "hex")
);
} catch {
const genesisChallenge = await getMainnetGenesisChallenge();
const storeInfo = await withTimeout(
peer.syncStore(latestStore, null, genesisChallenge, false),
60000,
`Timeout syncing store for storeId ${storeId}`
);

const headerHash = await peer.getHeaderHash(storeInfo.latestHeight);

await peer.waitForCoinToBeSpent(
getCoinId(storeInfo.latestStore.coin),
storeInfo.latestHeight,
headerHash
);
}

console.log(`Detected Coin Spend: ${coinId.toString("hex")}`);

Expand Down

0 comments on commit ed5f7ab

Please sign in to comment.