Skip to content

Commit 47334da

Browse files
Merge pull request #22 from DIG-Network/release/v0.0.1-alpha.22
Release/v0.0.1 alpha.22
2 parents 7006895 + 123098c commit 47334da

File tree

4 files changed

+49
-21
lines changed

4 files changed

+49
-21
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
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.
44

5+
### [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)
6+
7+
8+
### Features
9+
10+
* add getAllEpochPeers and getActiveEpochPeers to ServerCoin class ([1228ad0](https://github.com/DIG-Network/dig-chia-sdk/commit/1228ad03eb6bd609e6cd7ab1aa687c4f4e5d264c))
11+
512
### [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)
613

714

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@dignetwork/dig-sdk",
3-
"version": "0.0.1-alpha.21",
3+
"version": "0.0.1-alpha.22",
44
"description": "",
55
"type": "commonjs",
66
"main": "./dist/index.js",

src/blockchain/ServerCoin.ts

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ const serverCoinCollateral = 300_000_000;
1919

2020
export class ServerCoin {
2121
private storeId: string;
22-
public static readonly serverCoinManager = new NconfManager("server_coin.json");
23-
22+
public static readonly serverCoinManager = new NconfManager(
23+
"server_coin.json"
24+
);
2425

2526
constructor(storeId: string) {
2627
this.storeId = storeId;
@@ -178,19 +179,8 @@ export class ServerCoin {
178179
);
179180
}
180181

181-
// Sample server coins for the current epoch
182-
public async sampleCurrentEpoch(
183-
sampleSize: number = 5,
184-
blacklist: string[] = []
185-
): Promise<string[]> {
186-
const epoch = ServerCoin.getCurrentEpoch();
187-
return this.sampleServerCoinsByEpoch(epoch, sampleSize, blacklist);
188-
}
189-
190-
// Sample server coins by epoch
191-
public async sampleServerCoinsByEpoch(
182+
public async getAllEpochPeers(
192183
epoch: number,
193-
sampleSize: number = 5,
194184
blacklist: string[] = []
195185
): Promise<string[]> {
196186
const epochBasedHint = morphLauncherId(
@@ -225,8 +215,33 @@ export class ServerCoin {
225215
console.log("Server Coin Peers: ", serverCoinPeers);
226216
}
227217

228-
// Convert the Set back to an array if needed
229-
return _.sampleSize(Array.from(serverCoinPeers), sampleSize);
218+
return Array.from(serverCoinPeers);
219+
}
220+
221+
public async getActiveEpochPeers(
222+
blacklist: string[] = []
223+
): Promise<string[]> {
224+
const epoch = ServerCoin.getCurrentEpoch();
225+
return this.getAllEpochPeers(epoch, blacklist);
226+
}
227+
228+
// Sample server coins for the current epoch
229+
public async sampleCurrentEpoch(
230+
sampleSize: number = 5,
231+
blacklist: string[] = []
232+
): Promise<string[]> {
233+
const epoch = ServerCoin.getCurrentEpoch();
234+
return this.sampleServerCoinsByEpoch(epoch, sampleSize, blacklist);
235+
}
236+
237+
// Sample server coins by epoch
238+
public async sampleServerCoinsByEpoch(
239+
epoch: number,
240+
sampleSize: number = 5,
241+
blacklist: string[] = []
242+
): Promise<string[]> {
243+
const serverCoinPeers = await this.getAllEpochPeers(epoch, blacklist);
244+
return _.sampleSize(serverCoinPeers, sampleSize);
230245
}
231246

232247
// Get the current epoch based on the current timestamp
@@ -352,7 +367,10 @@ export class ServerCoin {
352367
coins = coins.filter((c: Coin) => c !== coinInfo);
353368

354369
// Update the config to reflect the remaining coins for this IP
355-
await ServerCoin.serverCoinManager.setConfigValue(`${storeCoin}:${ip}`, coins);
370+
await ServerCoin.serverCoinManager.setConfigValue(
371+
`${storeCoin}:${ip}`,
372+
coins
373+
);
356374
}
357375

358376
// If no coins are left for this IP, optionally remove the entire IP entry
@@ -368,7 +386,10 @@ export class ServerCoin {
368386
// If no IPs are left for this store, optionally remove the store entry
369387
if (Object.keys(allServerCoins[storeCoin]).length === 0) {
370388
delete allServerCoins[storeCoin];
371-
await ServerCoin.serverCoinManager.setConfigValue(storeCoin, undefined);
389+
await ServerCoin.serverCoinManager.setConfigValue(
390+
storeCoin,
391+
undefined
392+
);
372393
}
373394
}
374395
}

0 commit comments

Comments
 (0)