@mainsail/blockchain-utils 0.0.1-evm.18 → 0.0.1-evm.19
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.
- package/distribution/index.d.ts.map +1 -1
- package/distribution/index.js +13 -4
- package/distribution/index.js.map +1 -1
- package/distribution/is-majority.d.ts +1 -1
- package/distribution/is-majority.d.ts.map +1 -1
- package/distribution/is-majority.js +1 -1
- package/distribution/is-majority.js.map +1 -1
- package/distribution/is-minority.d.ts +1 -1
- package/distribution/is-minority.d.ts.map +1 -1
- package/distribution/is-minority.js +1 -1
- package/distribution/is-minority.js.map +1 -1
- package/distribution/proposer-calculator.d.ts +0 -1
- package/distribution/proposer-calculator.d.ts.map +1 -1
- package/distribution/proposer-calculator.js +2 -10
- package/distribution/proposer-calculator.js.map +1 -1
- package/distribution/round-calculator.js +18 -18
- package/distribution/round-calculator.js.map +1 -1
- package/package.json +6 -6
- package/distribution/supply-calculator.d.ts +0 -7
- package/distribution/supply-calculator.d.ts.map +0 -1
- package/distribution/supply-calculator.js +0 -48
- package/distribution/supply-calculator.js.map +0 -1
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../source/index.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../source/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAO7C,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,8BAA8B,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvF,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,qBACa,eAAgB,SAAQ,SAAS,CAAC,eAAe;IAChD,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;CAMtC"}
|
package/distribution/index.js
CHANGED
@@ -1,21 +1,30 @@
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
6
|
+
};
|
7
|
+
import { injectable } from "@mainsail/container";
|
1
8
|
import { Identifiers } from "@mainsail/contracts";
|
2
9
|
import { Providers } from "@mainsail/kernel";
|
3
10
|
import { FeeCalculator } from "./fee-calculator.js";
|
4
11
|
import { ProposerCalculator } from "./proposer-calculator.js";
|
5
12
|
import { RoundCalculator } from "./round-calculator.js";
|
6
|
-
import { SupplyCalculator } from "./supply-calculator.js";
|
7
13
|
import { TimestampCalculator } from "./timestamp-calculator.js";
|
8
14
|
export { formatCurrency } from "./format-currency.js";
|
9
15
|
export { getBlockNotChainedErrorMessage, isBlockChained } from "./is-block-chained.js";
|
10
16
|
export { isMajority } from "./is-majority.js";
|
11
17
|
export { isMinority } from "./is-minority.js";
|
12
|
-
|
18
|
+
let ServiceProvider = class ServiceProvider extends Providers.ServiceProvider {
|
13
19
|
async register() {
|
14
20
|
this.app.bind(Identifiers.BlockchainUtils.ProposerCalculator).to(ProposerCalculator).inSingletonScope();
|
15
21
|
this.app.bind(Identifiers.BlockchainUtils.FeeCalculator).to(FeeCalculator).inSingletonScope();
|
16
22
|
this.app.bind(Identifiers.BlockchainUtils.RoundCalculator).to(RoundCalculator).inSingletonScope();
|
17
|
-
this.app.bind(Identifiers.BlockchainUtils.SupplyCalculator).to(SupplyCalculator).inSingletonScope();
|
18
23
|
this.app.bind(Identifiers.BlockchainUtils.TimestampCalculator).to(TimestampCalculator).inSingletonScope();
|
19
24
|
}
|
20
|
-
}
|
25
|
+
};
|
26
|
+
ServiceProvider = __decorate([
|
27
|
+
injectable()
|
28
|
+
], ServiceProvider);
|
29
|
+
export { ServiceProvider };
|
21
30
|
//# sourceMappingURL=index.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../source/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAE7C,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../source/index.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAE7C,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAEhE,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,8BAA8B,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvF,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAGvC,IAAM,eAAe,GAArB,MAAM,eAAgB,SAAQ,SAAS,CAAC,eAAe;IACtD,KAAK,CAAC,QAAQ;QACpB,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,eAAe,CAAC,kBAAkB,CAAC,CAAC,EAAE,CAAC,kBAAkB,CAAC,CAAC,gBAAgB,EAAE,CAAC;QACxG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,eAAe,CAAC,aAAa,CAAC,CAAC,EAAE,CAAC,aAAa,CAAC,CAAC,gBAAgB,EAAE,CAAC;QAC9F,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,eAAe,CAAC,eAAe,CAAC,CAAC,EAAE,CAAC,eAAe,CAAC,CAAC,gBAAgB,EAAE,CAAC;QAClG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,eAAe,CAAC,mBAAmB,CAAC,CAAC,EAAE,CAAC,mBAAmB,CAAC,CAAC,gBAAgB,EAAE,CAAC;IAC3G,CAAC;CACD,CAAA;AAPY,eAAe;IAD3B,UAAU,EAAE;GACA,eAAe,CAO3B"}
|
@@ -1,2 +1,2 @@
|
|
1
|
-
export declare const isMajority: (size: number,
|
1
|
+
export declare const isMajority: (size: number, roundValidators: number) => boolean;
|
2
2
|
//# sourceMappingURL=is-majority.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"is-majority.d.ts","sourceRoot":"","sources":["../source/is-majority.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,UAAU,GAAI,MAAM,MAAM,EAAE,
|
1
|
+
{"version":3,"file":"is-majority.d.ts","sourceRoot":"","sources":["../source/is-majority.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,UAAU,GAAI,MAAM,MAAM,EAAE,iBAAiB,MAAM,KAAG,OAA2C,CAAC"}
|
@@ -1,2 +1,2 @@
|
|
1
|
-
export const isMajority = (size,
|
1
|
+
export const isMajority = (size, roundValidators) => size > (roundValidators / 3) * 2;
|
2
2
|
//# sourceMappingURL=is-majority.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"is-majority.js","sourceRoot":"","sources":["../source/is-majority.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,IAAY,EAAE,
|
1
|
+
{"version":3,"file":"is-majority.js","sourceRoot":"","sources":["../source/is-majority.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,IAAY,EAAE,eAAuB,EAAW,EAAE,CAAC,IAAI,GAAG,CAAC,eAAe,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC"}
|
@@ -1,2 +1,2 @@
|
|
1
|
-
export declare const isMinority: (size: number,
|
1
|
+
export declare const isMinority: (size: number, roundValidators: number) => boolean;
|
2
2
|
//# sourceMappingURL=is-minority.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"is-minority.d.ts","sourceRoot":"","sources":["../source/is-minority.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,UAAU,GAAI,MAAM,MAAM,EAAE,
|
1
|
+
{"version":3,"file":"is-minority.d.ts","sourceRoot":"","sources":["../source/is-minority.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,UAAU,GAAI,MAAM,MAAM,EAAE,iBAAiB,MAAM,KAAG,OAAqC,CAAC"}
|
@@ -1,2 +1,2 @@
|
|
1
|
-
export const isMinority = (size,
|
1
|
+
export const isMinority = (size, roundValidators) => size > roundValidators / 3;
|
2
2
|
//# sourceMappingURL=is-minority.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"is-minority.js","sourceRoot":"","sources":["../source/is-minority.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,IAAY,EAAE,
|
1
|
+
{"version":3,"file":"is-minority.js","sourceRoot":"","sources":["../source/is-minority.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,IAAY,EAAE,eAAuB,EAAW,EAAE,CAAC,IAAI,GAAG,eAAe,GAAG,CAAC,CAAC"}
|
@@ -2,7 +2,6 @@ import { Contracts } from "@mainsail/contracts";
|
|
2
2
|
export declare class ProposerCalculator implements Contracts.BlockchainUtils.ProposerCalculator {
|
3
3
|
private readonly configuration;
|
4
4
|
private readonly stateStore;
|
5
|
-
private validatorMatrix;
|
6
5
|
getValidatorIndex(round: number): number;
|
7
6
|
}
|
8
7
|
//# sourceMappingURL=proposer-calculator.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"proposer-calculator.d.ts","sourceRoot":"","sources":["../source/proposer-calculator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAe,MAAM,qBAAqB,CAAC;
|
1
|
+
{"version":3,"file":"proposer-calculator.d.ts","sourceRoot":"","sources":["../source/proposer-calculator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAe,MAAM,qBAAqB,CAAC;AAE7D,qBACa,kBAAmB,YAAW,SAAS,CAAC,eAAe,CAAC,kBAAkB;IAEtF,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAkC;IAGhE,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAyB;IAE7C,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;CAK/C"}
|
@@ -9,18 +9,10 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
9
|
};
|
10
10
|
import { inject, injectable } from "@mainsail/container";
|
11
11
|
import { Contracts, Identifiers } from "@mainsail/contracts";
|
12
|
-
import { assert } from "@mainsail/utils";
|
13
12
|
let ProposerCalculator = class ProposerCalculator {
|
14
|
-
constructor() {
|
15
|
-
// TODO: Support validator changes
|
16
|
-
this.validatorMatrix = [...Array.from({ length: 53 }).keys()];
|
17
|
-
}
|
18
13
|
getValidatorIndex(round) {
|
19
|
-
const {
|
20
|
-
|
21
|
-
const result = this.validatorMatrix[offset % activeValidators];
|
22
|
-
assert.number(result);
|
23
|
-
return result;
|
14
|
+
const { roundValidators } = this.configuration.getMilestone();
|
15
|
+
return (this.stateStore.getTotalRound() + round) % roundValidators; // This method will work fine on roundValidators change. We are not trying to get sequential indexes on value change, because validators are randomized every round.
|
24
16
|
}
|
25
17
|
};
|
26
18
|
__decorate([
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"proposer-calculator.js","sourceRoot":"","sources":["../source/proposer-calculator.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;
|
1
|
+
{"version":3,"file":"proposer-calculator.js","sourceRoot":"","sources":["../source/proposer-calculator.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAGtD,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;IAOvB,iBAAiB,CAAC,KAAa;QACrC,MAAM,EAAE,eAAe,EAAE,GAAG,IAAI,CAAC,aAAa,CAAC,YAAY,EAAE,CAAC;QAE9D,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,aAAa,EAAE,GAAG,KAAK,CAAC,GAAG,eAAe,CAAC,CAAC,oKAAoK;IACzO,CAAC;CACD,CAAA;AAViB;IADhB,MAAM,CAAC,WAAW,CAAC,YAAY,CAAC,aAAa,CAAC;;yDACiB;AAG/C;IADhB,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,KAAK,CAAC;;sDACoB;AALxC,kBAAkB;IAD9B,UAAU,EAAE;GACA,kBAAkB,CAY9B"}
|
@@ -16,15 +16,15 @@ let RoundCalculator = class RoundCalculator {
|
|
16
16
|
const genesisHeight = this.configuration.getGenesisHeight();
|
17
17
|
const milestones = [
|
18
18
|
{
|
19
|
-
data: configuration.getMilestone(genesisHeight).
|
19
|
+
data: configuration.getMilestone(genesisHeight).roundValidators,
|
20
20
|
found: true,
|
21
21
|
height: genesisHeight,
|
22
22
|
},
|
23
23
|
];
|
24
|
-
let nextMilestone = configuration.getNextMilestoneWithNewKey(genesisHeight, "
|
24
|
+
let nextMilestone = configuration.getNextMilestoneWithNewKey(genesisHeight, "roundValidators");
|
25
25
|
while (nextMilestone.found) {
|
26
26
|
milestones.push(nextMilestone);
|
27
|
-
nextMilestone = configuration.getNextMilestoneWithNewKey(nextMilestone.height, "
|
27
|
+
nextMilestone = configuration.getNextMilestoneWithNewKey(nextMilestone.height, "roundValidators");
|
28
28
|
}
|
29
29
|
return milestones;
|
30
30
|
};
|
@@ -39,19 +39,19 @@ let RoundCalculator = class RoundCalculator {
|
|
39
39
|
if (temporary.height > height) {
|
40
40
|
continue;
|
41
41
|
}
|
42
|
-
if (!milestone || temporary.
|
42
|
+
if (!milestone || temporary.roundValidators === milestone.roundValidators) {
|
43
43
|
milestone = temporary;
|
44
44
|
}
|
45
45
|
else {
|
46
46
|
break;
|
47
47
|
}
|
48
48
|
}
|
49
|
-
return height === genesisHeight || (height - Math.max(milestone.height, 1)) % milestone.
|
49
|
+
return height === genesisHeight || (height - Math.max(milestone.height, 1)) % milestone.roundValidators === 0;
|
50
50
|
}
|
51
51
|
calculateRound(height) {
|
52
52
|
const genesisHeight = this.configuration.getGenesisHeight();
|
53
|
-
let nextMilestone = this.configuration.getNextMilestoneWithNewKey(genesisHeight, "
|
54
|
-
let
|
53
|
+
let nextMilestone = this.configuration.getNextMilestoneWithNewKey(genesisHeight, "roundValidators");
|
54
|
+
let roundValidators = this.configuration.getMilestone(genesisHeight).roundValidators;
|
55
55
|
// Genesis round requires special treatment
|
56
56
|
if (height === genesisHeight) {
|
57
57
|
return { maxValidators: 0, nextRound: 1, round: 0, roundHeight: genesisHeight };
|
@@ -69,25 +69,25 @@ let RoundCalculator = class RoundCalculator {
|
|
69
69
|
break;
|
70
70
|
}
|
71
71
|
const spanHeight = nextMilestone.height - milestoneHeight - 1;
|
72
|
-
if (milestoneHeight > genesisHeight && spanHeight %
|
72
|
+
if (milestoneHeight > genesisHeight && spanHeight % roundValidators !== 0) {
|
73
73
|
throw new Exceptions.InvalidMilestoneConfigurationError(`Bad milestone at height: ${height}. The number of validators can only be changed at the beginning of a new round.`);
|
74
74
|
}
|
75
|
-
result.round += spanHeight / Math.max(1,
|
75
|
+
result.round += spanHeight / Math.max(1, roundValidators);
|
76
76
|
result.roundHeight = nextMilestone.height;
|
77
77
|
assert.number(nextMilestone.data);
|
78
78
|
result.maxValidators = nextMilestone.data;
|
79
|
-
|
79
|
+
roundValidators = nextMilestone.data;
|
80
80
|
milestoneHeight = nextMilestone.height - 1;
|
81
|
-
nextMilestone = this.configuration.getNextMilestoneWithNewKey(nextMilestone.height, "
|
81
|
+
nextMilestone = this.configuration.getNextMilestoneWithNewKey(nextMilestone.height, "roundValidators");
|
82
82
|
}
|
83
|
-
const
|
83
|
+
const minRoundValidators = Math.max(1, roundValidators);
|
84
84
|
const heightFromLastSpan = height - milestoneHeight - 1;
|
85
|
-
const roundIncrease = Math.floor(heightFromLastSpan /
|
86
|
-
const nextRoundIncrease = (heightFromLastSpan + 1) %
|
85
|
+
const roundIncrease = Math.floor(heightFromLastSpan / minRoundValidators);
|
86
|
+
const nextRoundIncrease = (heightFromLastSpan + 1) % minRoundValidators === 0 ? 1 : 0;
|
87
87
|
result.round += roundIncrease;
|
88
|
-
result.roundHeight += roundIncrease *
|
88
|
+
result.roundHeight += roundIncrease * minRoundValidators;
|
89
89
|
result.nextRound = result.round + nextRoundIncrease;
|
90
|
-
result.maxValidators =
|
90
|
+
result.maxValidators = minRoundValidators;
|
91
91
|
return result;
|
92
92
|
}
|
93
93
|
calculateRoundInfoByRound(round) {
|
@@ -100,8 +100,8 @@ let RoundCalculator = class RoundCalculator {
|
|
100
100
|
let maxValidators = 0;
|
101
101
|
for (let index = 1; index < milestones.length - 1; index++) {
|
102
102
|
const milestone = milestones[index];
|
103
|
-
maxValidators = milestone.
|
104
|
-
roundHeight += (round - 1) * milestone.
|
103
|
+
maxValidators = milestone.roundValidators;
|
104
|
+
roundHeight += (round - 1) * milestone.roundValidators;
|
105
105
|
}
|
106
106
|
return {
|
107
107
|
maxValidators,
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"round-calculator.js","sourceRoot":"","sources":["../source/round-calculator.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACzE,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AASlC,IAAM,eAAe,GAArB,MAAM,eAAe;IAArB;QA2GC,iDAA4C,GAAG,CACrD,aAA6C,EACd,EAAE;YACjC,MAAM,aAAa,GAAG,IAAI,CAAC,aAAa,CAAC,gBAAgB,EAAE,CAAC;YAE5D,MAAM,UAAU,GAAiC;gBAChD;oBACC,IAAI,EAAE,aAAa,CAAC,YAAY,CAAC,aAAa,CAAC,CAAC,
|
1
|
+
{"version":3,"file":"round-calculator.js","sourceRoot":"","sources":["../source/round-calculator.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACzE,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AASlC,IAAM,eAAe,GAArB,MAAM,eAAe;IAArB;QA2GC,iDAA4C,GAAG,CACrD,aAA6C,EACd,EAAE;YACjC,MAAM,aAAa,GAAG,IAAI,CAAC,aAAa,CAAC,gBAAgB,EAAE,CAAC;YAE5D,MAAM,UAAU,GAAiC;gBAChD;oBACC,IAAI,EAAE,aAAa,CAAC,YAAY,CAAC,aAAa,CAAC,CAAC,e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C;QAED,MAAM,UAAU,GAAG,IAAI,CAAC,aAAa,CAAC,aAAa,EAAE,CAAC;QAEtD,IAAI,WAAW,GAAG,CAAC,CAAC;QACpB,IAAI,aAAa,GAAG,CAAC,CAAC;QACtB,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC;YAC5D,MAAM,SAAS,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC;YACpC,aAAa,GAAG,SAAS,CAAC,eAAe,CAAC;YAC1C,WAAW,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,SAAS,CAAC,eAAe,CAAC;QACxD,CAAC;QAED,OAAO;YACN,aAAa;YACb,SAAS,EAAE,KAAK;YAChB,KAAK;YACL,WAAW;SACX,CAAC;IACH,CAAC;CAwBD,CAAA;AA/HiB;IADhB,MAAM,CAAC,WAAW,CAAC,YAAY,CAAC,aAAa,CAAC;;sDACiB;AAFpD,eAAe;IAD3B,UAAU,EAAE;GACA,eAAe,CAiI3B"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@mainsail/blockchain-utils",
|
3
|
-
"version": "0.0.1-evm.
|
3
|
+
"version": "0.0.1-evm.19",
|
4
4
|
"description": "Common blockchain utils for the Mainsail blockchain.",
|
5
5
|
"license": "GPL-3.0-only",
|
6
6
|
"contributors": [],
|
@@ -11,10 +11,10 @@
|
|
11
11
|
"/distribution"
|
12
12
|
],
|
13
13
|
"dependencies": {
|
14
|
-
"@mainsail/
|
15
|
-
"@mainsail/
|
16
|
-
"@mainsail/
|
17
|
-
"@mainsail/
|
14
|
+
"@mainsail/container": "0.0.1-evm.19",
|
15
|
+
"@mainsail/utils": "0.0.1-evm.19",
|
16
|
+
"@mainsail/kernel": "0.0.1-evm.19",
|
17
|
+
"@mainsail/contracts": "0.0.1-evm.19"
|
18
18
|
},
|
19
19
|
"devDependencies": {
|
20
20
|
"uvu": "0.5.6"
|
@@ -28,7 +28,7 @@
|
|
28
28
|
"clean": "del distribution",
|
29
29
|
"release": "pnpm publish --access public",
|
30
30
|
"test": "pnpm run uvu source .test.ts",
|
31
|
-
"test:coverage": "c8 pnpm run test",
|
31
|
+
"test:coverage": "c8 -r=text -r=lcov --all pnpm run test",
|
32
32
|
"test:coverage:html": "c8 -r html --all pnpm run test",
|
33
33
|
"test:file": "pnpm run uvu source",
|
34
34
|
"uvu": "tsx --tsconfig ../../tsconfig.test.json ./node_modules/uvu/bin.js"
|
@@ -1,7 +0,0 @@
|
|
1
|
-
import { Contracts } from "@mainsail/contracts";
|
2
|
-
import { BigNumber } from "@mainsail/utils";
|
3
|
-
export declare class SupplyCalculator implements Contracts.BlockchainUtils.SupplyCalculator {
|
4
|
-
private readonly configuration;
|
5
|
-
calculateSupply(height: number): BigNumber;
|
6
|
-
}
|
7
|
-
//# sourceMappingURL=supply-calculator.d.ts.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"supply-calculator.d.ts","sourceRoot":"","sources":["../source/supply-calculator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAe,MAAM,qBAAqB,CAAC;AAC7D,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,qBACa,gBAAiB,YAAW,SAAS,CAAC,eAAe,CAAC,gBAAgB;IAElF,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAkC;IAEhE,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS;CAkC1C"}
|
@@ -1,48 +0,0 @@
|
|
1
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
4
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
6
|
-
};
|
7
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
8
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
9
|
-
};
|
10
|
-
import { inject, injectable } from "@mainsail/container";
|
11
|
-
import { Contracts, Identifiers } from "@mainsail/contracts";
|
12
|
-
import { BigNumber } from "@mainsail/utils";
|
13
|
-
let SupplyCalculator = class SupplyCalculator {
|
14
|
-
calculateSupply(height) {
|
15
|
-
const initialSupply = BigNumber.make(this.configuration.get("genesisBlock.block.amount"));
|
16
|
-
const milestones = this.configuration.get("milestones");
|
17
|
-
const genesisHeight = this.configuration.getGenesisHeight();
|
18
|
-
if (height === genesisHeight || milestones.length === 0) {
|
19
|
-
return initialSupply;
|
20
|
-
}
|
21
|
-
let accumulatedRewards = BigNumber.ZERO;
|
22
|
-
let currentHeight = 0;
|
23
|
-
let constantIndex = 0;
|
24
|
-
while (currentHeight < height) {
|
25
|
-
const constants = milestones[constantIndex];
|
26
|
-
const nextConstants = milestones[constantIndex + 1];
|
27
|
-
let heightJump = height - currentHeight;
|
28
|
-
if (nextConstants && height >= nextConstants.height && currentHeight < nextConstants.height - 1) {
|
29
|
-
heightJump = nextConstants.height - 1 - currentHeight;
|
30
|
-
constantIndex += 1;
|
31
|
-
}
|
32
|
-
currentHeight += heightJump;
|
33
|
-
if (currentHeight >= constants.height) {
|
34
|
-
accumulatedRewards = accumulatedRewards.plus(BigNumber.make(constants.reward).times(heightJump));
|
35
|
-
}
|
36
|
-
}
|
37
|
-
return initialSupply.plus(accumulatedRewards);
|
38
|
-
}
|
39
|
-
};
|
40
|
-
__decorate([
|
41
|
-
inject(Identifiers.Cryptography.Configuration),
|
42
|
-
__metadata("design:type", Object)
|
43
|
-
], SupplyCalculator.prototype, "configuration", void 0);
|
44
|
-
SupplyCalculator = __decorate([
|
45
|
-
injectable()
|
46
|
-
], SupplyCalculator);
|
47
|
-
export { SupplyCalculator };
|
48
|
-
//# sourceMappingURL=supply-calculator.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"supply-calculator.js","sourceRoot":"","sources":["../source/supply-calculator.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAGrC,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;IAI5B,eAAe,CAAC,MAAc;QAC7B,MAAM,aAAa,GAAG,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,2BAA2B,CAAC,CAAC,CAAC;QAE1F,MAAM,UAAU,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;QACxD,MAAM,aAAa,GAAG,IAAI,CAAC,aAAa,CAAC,gBAAgB,EAAE,CAAC;QAE5D,IAAI,MAAM,KAAK,aAAa,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACzD,OAAO,aAAa,CAAC;QACtB,CAAC;QAED,IAAI,kBAAkB,GAAG,SAAS,CAAC,IAAI,CAAC;QACxC,IAAI,aAAa,GAAG,CAAC,CAAC;QACtB,IAAI,aAAa,GAAG,CAAC,CAAC;QAEtB,OAAO,aAAa,GAAG,MAAM,EAAE,CAAC;YAC/B,MAAM,SAAS,GAAG,UAAU,CAAC,aAAa,CAAC,CAAC;YAC5C,MAAM,aAAa,GAAG,UAAU,CAAC,aAAa,GAAG,CAAC,CAAC,CAAC;YAEpD,IAAI,UAAU,GAAW,MAAM,GAAG,aAAa,CAAC;YAEhD,IAAI,aAAa,IAAI,MAAM,IAAI,aAAa,CAAC,MA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