Skip to content

Commit a54e026

Browse files
committed
feat(Epoch): applied feedback from Hannsen
1 parent b0810f1 commit a54e026

File tree

2 files changed

+8
-13
lines changed

2 files changed

+8
-13
lines changed

packages/core/src/ckb/epoch.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ export class Epoch extends mol.Entity.Base<EpochLike, Epoch>() {
132132
}
133133

134134
let number: NumLike, index: NumLike, length: NumLike;
135-
if (epochLike instanceof Array) {
135+
if (Array.isArray(epochLike)) {
136136
[number, index, length] = epochLike;
137137
} else {
138138
({ number, index, length } = epochLike);
@@ -148,13 +148,6 @@ export class Epoch extends mol.Entity.Base<EpochLike, Epoch>() {
148148
return new Epoch(0n, 0n, numFrom(1));
149149
}
150150

151-
/**
152-
* Return an epoch representing one (1 + 0/1).
153-
*/
154-
static one(): Epoch {
155-
return new Epoch(numFrom(1), 0n, numFrom(1));
156-
}
157-
158151
/**
159152
* Return an epoch representing one cycle (180 + 0/1).
160153
*
@@ -281,8 +274,8 @@ export class Epoch extends mol.Entity.Base<EpochLike, Epoch>() {
281274

282275
return (
283276
reference.timestamp +
284-
epochInMilliseconds * number +
285-
(epochInMilliseconds * index) / length
277+
EPOCH_IN_MILLISECONDS * number +
278+
(EPOCH_IN_MILLISECONDS * index) / length
286279
);
287280
}
288281
}
@@ -293,4 +286,4 @@ export class Epoch extends mol.Entity.Base<EpochLike, Epoch>() {
293286
* Calculated as 4 hours in milliseconds:
294287
* 4 hours * 60 minutes per hour * 60 seconds per minute * 1000 milliseconds per second.
295288
*/
296-
const epochInMilliseconds = numFrom(14400000); // (Number.isSafeInteger(14400000) === true)
289+
const EPOCH_IN_MILLISECONDS = numFrom(4 * 60 * 60 * 1000);

packages/core/src/utils/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,13 +267,15 @@ export function stringify(val: unknown) {
267267
}
268268

269269
/**
270-
* Calculate the greatest common divisor (GCD) of two Num values using the Euclidean algorithm.
270+
* Calculate the greatest common divisor (GCD) of two NumLike values using the Euclidean algorithm.
271271
*
272272
* @param a - First operand.
273273
* @param b - Second operand.
274274
* @returns GCD(a, b) as a Num.
275275
*/
276-
export function gcd(a: Num, b: Num): Num {
276+
export function gcd(a: NumLike, b: NumLike): Num {
277+
a = numFrom(a);
278+
b = numFrom(b);
277279
a = a < Zero ? -a : a;
278280
b = b < Zero ? -b : b;
279281
while (b !== Zero) {

0 commit comments

Comments
 (0)