Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release/v0.0.1 alpha.22 #22

Merged
merged 2 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)


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.21",
"version": "0.0.1-alpha.22",
"description": "",
"type": "commonjs",
"main": "./dist/index.js",
Expand Down
57 changes: 39 additions & 18 deletions src/blockchain/ServerCoin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -178,19 +179,8 @@ export class ServerCoin {
);
}

// Sample server coins for the current epoch
public async sampleCurrentEpoch(
sampleSize: number = 5,
blacklist: string[] = []
): Promise<string[]> {
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<string[]> {
const epochBasedHint = morphLauncherId(
Expand Down Expand Up @@ -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<string[]> {
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<string[]> {
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<string[]> {
const serverCoinPeers = await this.getAllEpochPeers(epoch, blacklist);
return _.sampleSize(serverCoinPeers, sampleSize);
}

// Get the current epoch based on the current timestamp
Expand Down Expand Up @@ -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
Expand All @@ -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
);
}
}
}
Expand Down
Loading