@dignetwork/dig-sdk 0.0.1-alpha.24 → 0.0.1-alpha.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -12,12 +12,18 @@ export declare class ServerCoin {
12
12
  getActiveEpochPeers(blacklist?: string[]): Promise<string[]>;
13
13
  sampleCurrentEpoch(sampleSize?: number, blacklist?: string[]): Promise<string[]>;
14
14
  sampleServerCoinsByEpoch(epoch: number, sampleSize?: number, blacklist?: string[]): Promise<string[]>;
15
- static getCurrentEpoch(): number;
15
+ static getCurrentEpoch(): {
16
+ epoch: number;
17
+ round: number;
18
+ };
16
19
  ensureServerCoinExists(peerIp: string): Promise<void>;
17
20
  meltOutdatedEpochs(peerIp: string): Promise<void>;
18
21
  static meltUntrackedStoreCoins(): Promise<void>;
19
22
  private getServerCoinsForStore;
20
23
  hasEpochCoinBeenCreated(currentEpoch: number, peerIp: string): Promise<boolean>;
21
- static calculateEpoch(currentTimestampUTC: Date): number;
24
+ static calculateEpochAndRound(currentTimestampUTC: Date): {
25
+ epoch: number;
26
+ round: number;
27
+ };
22
28
  }
23
29
  //# sourceMappingURL=ServerCoin.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ServerCoin.d.ts","sourceRoot":"","sources":["../../src/blockchain/ServerCoin.ts"],"names":[],"mappings":"AACA,OAAO,EAML,UAAU,IAAI,gBAAgB,EAE/B,MAAM,kBAAkB,CAAC;AAI1B,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAMrD,qBAAa,UAAU;IACrB,OAAO,CAAC,OAAO,CAAS;IACxB,gBAAuB,iBAAiB,eAEtC;gBAEU,OAAO,EAAE,MAAM;IAKd,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC;IA2DzD,kBAAkB,CAC7B,UAAU,EAAE,gBAAgB,EAC5B,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,GACb,OAAO,CA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24
  const publicSyntheticKey = await wallet.getPublicSyntheticKey();
25
25
  const serverCoinCreationCoins = await (0, coins_1.selectUnspentCoins)(peer, BigInt(serverCoinCollateral), BigInt(1000000));
26
- const currentEpoch = ServerCoin.getCurrentEpoch();
26
+ const { epoch: currentEpoch } = ServerCoin.getCurrentEpoch();
27
27
  const epochBasedHint = (0, datalayer_driver_1.morphLauncherId)(Buffer.from(this.storeId, "hex"), BigInt(currentEpoch));
28
28
  const newServerCoin = (0, datalayer_driver_1.createServerCoin)(publicSyntheticKey, serverCoinCreationCoins, epochBasedHint, [peerIp], BigInt(serverCoinCollateral), BigInt(1000000));
29
29
  const combinedCoinSpends = [...newServerCoin.coinSpends];
@@ -115,12 +115,12 @@ class ServerCoin {
115
115
  return Array.from(serverCoinPeers);
116
116
  }
117
117
  async getActiveEpochPeers(blacklist = []) {
118
- const epoch = ServerCoin.getCurrentEpoch();
118
+ const { epoch } = ServerCoin.getCurrentEpoch();
119
119
  return this.getAllEpochPeers(epoch, blacklist);
120
120
  }
121
121
  // Sample server coins for the current epoch
122
122
  async sampleCurrentEpoch(sampleSize = 5, blacklist = []) {
123
- const epoch = ServerCoin.getCurrentEpoch();
123
+ const { epoch } = ServerCoin.getCurrentEpoch();
124
124
  return this.sampleServerCoinsByEpoch(epoch, sampleSize, blacklist);
125
125
  }
126
126
  // Sample server coins by epoch
@@ -130,13 +130,13 @@ class ServerCoin {
130
130
  }
131
131
  // Get the current epoch based on the current timestamp
132
132
  static getCurrentEpoch() {
133
- return ServerCoin.calculateEpoch(new Date());
133
+ return ServerCoin.calculateEpochAndRound(new Date());
134
134
  }
135
135
  // Ensure server coin exists for the current epoch
136
136
  async ensureServerCoinExists(peerIp) {
137
137
  try {
138
138
  console.log(`Ensuring server coin exists for store ${this.storeId}...`);
139
- const currentEpoch = ServerCoin.getCurrentEpoch();
139
+ const { epoch: currentEpoch } = ServerCoin.getCurrentEpoch();
140
140
  const serverCoins = await this.getServerCoinsForStore(peerIp);
141
141
  // Check if a server coin already exists for the current epoch
142
142
  const existingCoin = serverCoins.find((coin) => coin.epoch === currentEpoch);
@@ -167,7 +167,7 @@ class ServerCoin {
167
167
  // Melt outdated server coins
168
168
  async meltOutdatedEpochs(peerIp) {
169
169
  try {
170
- const currentEpoch = ServerCoin.getCurrentEpoch();
170
+ const { epoch: currentEpoch } = ServerCoin.getCurrentEpoch();
171
171
  let serverCoins = await this.getServerCoinsForStore(peerIp);
172
172
  // Filter out coins that are not in the current epoch
173
173
  const outdatedCoins = serverCoins.filter((coin) => coin.epoch < currentEpoch);
@@ -251,17 +251,23 @@ class ServerCoin {
251
251
  }
252
252
  }
253
253
  // Static method to calculate the current epoch
254
- static calculateEpoch(currentTimestampUTC) {
254
+ static calculateEpochAndRound(currentTimestampUTC) {
255
255
  const firstEpochStart = new Date(Date.UTC(2024, 8, 3, 0, 0)); // Sept 3, 2024, 00:00 UTC
256
256
  // Convert the current timestamp to milliseconds
257
257
  const currentTimestampMillis = currentTimestampUTC.getTime();
258
258
  // Calculate the number of milliseconds in one epoch (7 days)
259
- const millisecondsInEpoch = 7 * 24 * 60 * 60 * 1000;
259
+ const millisecondsInEpoch = 7 * 24 * 60 * 60 * 1000; // 7 days in milliseconds
260
260
  // Calculate the difference in milliseconds between the current timestamp and the first epoch start
261
261
  const differenceMillis = currentTimestampMillis - firstEpochStart.getTime();
262
262
  // Calculate the current epoch number
263
263
  const epochNumber = Math.floor(differenceMillis / millisecondsInEpoch) + 1;
264
- return epochNumber;
264
+ // Calculate the milliseconds elapsed since the start of the current epoch
265
+ const elapsedMillisInCurrentEpoch = differenceMillis % millisecondsInEpoch;
266
+ // Calculate the number of milliseconds in a round (10 minutes)
267
+ const millisecondsInRound = 10 * 60 * 1000; // 10 minutes in milliseconds
268
+ // Calculate the current round number
269
+ const roundNumber = Math.floor(elapsedMillisInCurrentEpoch / millisecondsInRound) + 1;
270
+ return { epoch: epochNumber, round: roundNumber };
265
271
  }
266
272
  }
267
273
  exports.ServerCoin = ServerCoin;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dignetwork/dig-sdk",
3
- "version": "0.0.1-alpha.24",
3
+ "version": "0.0.1-alpha.25",
4
4
  "description": "",
5
5
  "type": "commonjs",
6
6
  "main": "./dist/index.js",