diff --git a/CHANGELOG.md b/CHANGELOG.md index 38b42fa..edf7c9c 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.22](https://github.com/DIG-Network/dig-chia-sdk/compare/v0.0.1-alpha.21...v0.0.1-alpha.22) (2024-09-17) + + +### Features + +* add getAllEpochPeers and getActiveEpochPeers to ServerCoin class ([1228ad0](https://github.com/DIG-Network/dig-chia-sdk/commit/1228ad03eb6bd609e6cd7ab1aa687c4f4e5d264c)) + ### [0.0.1-alpha.21](https://github.com/DIG-Network/dig-chia-sdk/compare/v0.0.1-alpha.20...v0.0.1-alpha.21) (2024-09-16) diff --git a/package-lock.json b/package-lock.json index e4e234c..ec17fe0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@dignetwork/dig-sdk", - "version": "0.0.1-alpha.21", + "version": "0.0.1-alpha.22", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@dignetwork/dig-sdk", - "version": "0.0.1-alpha.21", + "version": "0.0.1-alpha.22", "license": "ISC", "dependencies": { "bip39": "^3.1.0", diff --git a/package.json b/package.json index 05b08a1..389e49b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@dignetwork/dig-sdk", - "version": "0.0.1-alpha.21", + "version": "0.0.1-alpha.22", "description": "", "type": "commonjs", "main": "./dist/index.js", diff --git a/src/blockchain/ServerCoin.ts b/src/blockchain/ServerCoin.ts index 6b68200..80523a1 100644 --- a/src/blockchain/ServerCoin.ts +++ b/src/blockchain/ServerCoin.ts @@ -19,8 +19,9 @@ const serverCoinCollateral = 300_000_000; export class ServerCoin { private storeId: string; - public static readonly serverCoinManager = new NconfManager("server_coin.json"); - + public static readonly serverCoinManager = new NconfManager( + "server_coin.json" + ); constructor(storeId: string) { this.storeId = storeId; @@ -178,19 +179,8 @@ export class ServerCoin { ); } - // Sample server coins for the current epoch - public async sampleCurrentEpoch( - sampleSize: number = 5, - blacklist: string[] = [] - ): Promise { - const epoch = ServerCoin.getCurrentEpoch(); - return this.sampleServerCoinsByEpoch(epoch, sampleSize, blacklist); - } - - // Sample server coins by epoch - public async sampleServerCoinsByEpoch( + public async getAllEpochPeers( epoch: number, - sampleSize: number = 5, blacklist: string[] = [] ): Promise { const epochBasedHint = morphLauncherId( @@ -225,8 +215,33 @@ export class ServerCoin { console.log("Server Coin Peers: ", serverCoinPeers); } - // Convert the Set back to an array if needed - return _.sampleSize(Array.from(serverCoinPeers), sampleSize); + return Array.from(serverCoinPeers); + } + + public async getActiveEpochPeers( + blacklist: string[] = [] + ): Promise { + const epoch = ServerCoin.getCurrentEpoch(); + return this.getAllEpochPeers(epoch, blacklist); + } + + // Sample server coins for the current epoch + public async sampleCurrentEpoch( + sampleSize: number = 5, + blacklist: string[] = [] + ): Promise { + const epoch = ServerCoin.getCurrentEpoch(); + return this.sampleServerCoinsByEpoch(epoch, sampleSize, blacklist); + } + + // Sample server coins by epoch + public async sampleServerCoinsByEpoch( + epoch: number, + sampleSize: number = 5, + blacklist: string[] = [] + ): Promise { + const serverCoinPeers = await this.getAllEpochPeers(epoch, blacklist); + return _.sampleSize(serverCoinPeers, sampleSize); } // Get the current epoch based on the current timestamp @@ -352,7 +367,10 @@ export class ServerCoin { coins = coins.filter((c: Coin) => c !== coinInfo); // Update the config to reflect the remaining coins for this IP - await ServerCoin.serverCoinManager.setConfigValue(`${storeCoin}:${ip}`, coins); + await ServerCoin.serverCoinManager.setConfigValue( + `${storeCoin}:${ip}`, + coins + ); } // If no coins are left for this IP, optionally remove the entire IP entry @@ -368,7 +386,10 @@ export class ServerCoin { // If no IPs are left for this store, optionally remove the store entry if (Object.keys(allServerCoins[storeCoin]).length === 0) { delete allServerCoins[storeCoin]; - await ServerCoin.serverCoinManager.setConfigValue(storeCoin, undefined); + await ServerCoin.serverCoinManager.setConfigValue( + storeCoin, + undefined + ); } } }