diff --git a/CHANGELOG.md b/CHANGELOG.md index 138236c..ca12587 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,14 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +### [0.0.1-alpha.166](https://github.com/DIG-Network/dig-chia-sdk/compare/v0.0.1-alpha.165...v0.0.1-alpha.166) (2024-10-08) + + +### Bug Fixes + +* get coin state to the right folder ([050586c](https://github.com/DIG-Network/dig-chia-sdk/commit/050586cd1d25f4ce0ce98128f519e390303834ee)) +* wait for confirmation ([dc704ad](https://github.com/DIG-Network/dig-chia-sdk/commit/dc704ad32390de2a9252206b4a6dc38e110319dc)) + ### [0.0.1-alpha.165](https://github.com/DIG-Network/dig-chia-sdk/compare/v0.0.1-alpha.164...v0.0.1-alpha.165) (2024-10-08) diff --git a/package-lock.json b/package-lock.json index 00ea1ef..c2d6395 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@dignetwork/dig-sdk", - "version": "0.0.1-alpha.165", + "version": "0.0.1-alpha.166", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@dignetwork/dig-sdk", - "version": "0.0.1-alpha.165", + "version": "0.0.1-alpha.166", "license": "ISC", "dependencies": { "@dignetwork/datalayer-driver": "^0.1.29", diff --git a/package.json b/package.json index 1d9af6f..ff6ec1b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@dignetwork/dig-sdk", - "version": "0.0.1-alpha.165", + "version": "0.0.1-alpha.166", "description": "", "type": "commonjs", "main": "./dist/index.js", diff --git a/src/blockchain/FullNodePeer.ts b/src/blockchain/FullNodePeer.ts index a400a53..7187de3 100644 --- a/src/blockchain/FullNodePeer.ts +++ b/src/blockchain/FullNodePeer.ts @@ -293,10 +293,7 @@ export class FullNodePeer { private static initializePeerWeights(peerIPs: string[]): void { for (const ip of peerIPs) { if (!FullNodePeer.peerWeights.has(ip)) { - if ( - ip === LOCALHOST || - ip === FullNodePeer.getTrustedFullNode() - ) { + if (ip === LOCALHOST || ip === FullNodePeer.getTrustedFullNode()) { FullNodePeer.peerWeights.set(ip, 5); // Higher weight for prioritized peers } else { FullNodePeer.peerWeights.set(ip, 1); // Default weight @@ -518,40 +515,19 @@ export class FullNodePeer { parentCoinInfo: Buffer ): Promise { const spinner = createSpinner("Waiting for confirmation...").start(); - let peer: Peer; - - try { - peer = await FullNodePeer.connect(); - } catch (error: any) { - spinner.error({ text: "Failed to connect to a fullnode peer." }); - console.error(`waitForConfirmation connection error: ${error.message}`); - throw error; - } - - // Extract peer IP to access the corresponding limiter - const peerIP = FullNodePeer.extractPeerIP(peer); - if (!peerIP) { - spinner.error({ text: "Failed to extract fullnode peer IP." }); - throw new Error("Failed to extract peer IP."); - } + const peer = await FullNodePeer.connect(); try { while (true) { // Schedule the isCoinSpent method call through the limiter - const confirmed = await peer.isCoinSpent( + await peer.waitForCoinToBeSpent( parentCoinInfo, MIN_HEIGHT, Buffer.from(MIN_HEIGHT_HEADER_HASH, "hex") ); - if (confirmed) { - spinner.success({ text: "Coin confirmed!" }); - return true; - } - - // Wait for 5 seconds before the next check - await new Promise((resolve) => setTimeout(resolve, 5000)); + spinner.success({ text: "Coin confirmed!" }); } } catch (error: any) { spinner.error({ text: "Error while waiting for confirmation." }); diff --git a/src/utils/config.ts b/src/utils/config.ts index 33fa406..38826aa 100644 --- a/src/utils/config.ts +++ b/src/utils/config.ts @@ -81,7 +81,7 @@ export const getCoinState = ( description: string; }; } => { - const stateFile = path.join(STORE_PATH, `${storeId}.json`); + const stateFile = path.join(USER_DIR_PATH, `${storeId}.json`); if (!fs.existsSync(stateFile)) { return { metadata: { rootHash: "", bytes: "", label: "", description: "" },