Skip to content

Commit

Permalink
Merge pull request #150 from DIG-Network/release/v0.0.1-alpha.166
Browse files Browse the repository at this point in the history
Release/v0.0.1 alpha.166
  • Loading branch information
MichaelTaylor3D authored Oct 8, 2024
2 parents e5f75d8 + 5a900d5 commit f1add00
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 32 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
32 changes: 4 additions & 28 deletions src/blockchain/FullNodePeer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -518,40 +515,19 @@ export class FullNodePeer {
parentCoinInfo: Buffer
): Promise<boolean> {
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." });
Expand Down
2 changes: 1 addition & 1 deletion src/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: "" },
Expand Down

0 comments on commit f1add00

Please sign in to comment.