diff --git a/CHANGELOG.md b/CHANGELOG.md index f66d5c6..675d649 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ 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.10](https://github.com/DIG-Network/dig-chia-sdk/compare/v0.0.1-alpha.9...v0.0.1-alpha.10) (2024-09-10) + + +### Bug Fixes + +* better trusted node handling ([0b1fefe](https://github.com/DIG-Network/dig-chia-sdk/commit/0b1fefebbf4b8b3a27a0d8b7af0afe59bc457aef)) + ### [0.0.1-alpha.9](https://github.com/DIG-Network/dig-chia-sdk/compare/v0.0.1-alpha.8...v0.0.1-alpha.9) (2024-09-10) diff --git a/package-lock.json b/package-lock.json index dba86fe..d9fc7e1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@dignetwork/dig-sdk", - "version": "0.0.1-alpha.9", + "version": "0.0.1-alpha.10", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@dignetwork/dig-sdk", - "version": "0.0.1-alpha.9", + "version": "0.0.1-alpha.10", "license": "ISC", "dependencies": { "bip39": "^3.1.0", diff --git a/package.json b/package.json index c94ef06..ffc6542 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@dignetwork/dig-sdk", - "version": "0.0.1-alpha.9", + "version": "0.0.1-alpha.10", "description": "", "type": "commonjs", "main": "./dist/index.js", diff --git a/src/blockchain/FullNodePeer.ts b/src/blockchain/FullNodePeer.ts index 3c47cb5..8196b46 100644 --- a/src/blockchain/FullNodePeer.ts +++ b/src/blockchain/FullNodePeer.ts @@ -60,18 +60,31 @@ export class FullNodePeer { private static isValidIpAddress(ip: string): boolean { const ipv4Regex = /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/; - return ipv4Regex.test(ip); } - private static async fetchNewPeerIPs(): Promise { + /** + * Retrieves the TRUSTED_FULLNODE IP from the environment + * and verifies if it is a valid IP address. + * + * @returns {string | null} The valid IP address or null if invalid + */ + private static getTrustedFullNode(): string | null { const trustedNodeIp = process.env.TRUSTED_FULLNODE || null; + + if (trustedNodeIp && FullNodePeer.isValidIpAddress(trustedNodeIp)) { + return trustedNodeIp; + } + return null; + } + + private static async fetchNewPeerIPs(): Promise { + const trustedNodeIp = FullNodePeer.getTrustedFullNode(); const priorityIps: string[] = []; // Prioritize trustedNodeIp if ( trustedNodeIp && - FullNodePeer.isValidIpAddress(trustedNodeIp) && (await FullNodePeer.isPortReachable(trustedNodeIp, FULLNODE_PORT)) ) { priorityIps.push(trustedNodeIp);