@mainsail/evm-consensus 0.0.1-evm.6 → 0.0.1-evm.7
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/deployer.d.ts.map +1 -1
- package/distribution/deployer.js +3 -3
- package/distribution/deployer.js.map +1 -1
- package/distribution/index.d.ts.map +1 -1
- package/distribution/index.js +2 -0
- package/distribution/index.js.map +1 -1
- package/distribution/services/consensus-contract-service.d.ts +12 -0
- package/distribution/services/consensus-contract-service.d.ts.map +1 -0
- package/distribution/services/consensus-contract-service.js +121 -0
- package/distribution/services/consensus-contract-service.js.map +1 -0
- package/distribution/services/rounds-iterator.d.ts +11 -0
- package/distribution/services/rounds-iterator.d.ts.map +1 -0
- package/distribution/services/rounds-iterator.js +104 -0
- package/distribution/services/rounds-iterator.js.map +1 -0
- package/distribution/services/votes-iterator.d.ts +11 -0
- package/distribution/services/votes-iterator.d.ts.map +1 -0
- package/distribution/services/votes-iterator.js +85 -0
- package/distribution/services/votes-iterator.js.map +1 -0
- package/distribution/validator-set.d.ts +1 -2
- package/distribution/validator-set.d.ts.map +1 -1
- package/distribution/validator-set.js +7 -75
- package/distribution/validator-set.js.map +1 -1
- package/package.json +6 -5
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"deployer.d.ts","sourceRoot":"","sources":["../source/deployer.ts"],"names":[],"mappings":"AAWA,qBACa,QAAQ;;IAEpB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAgC;IAGpD,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAkC;IAGhE,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA2B;IAIlD,OAAO,CAAC,QAAQ,CAAC,GAAG,CAA0B;
|
1
|
+
{"version":3,"file":"deployer.d.ts","sourceRoot":"","sources":["../source/deployer.ts"],"names":[],"mappings":"AAWA,qBACa,QAAQ;;IAEpB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAgC;IAGpD,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAkC;IAGhE,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA2B;IAIlD,OAAO,CAAC,QAAQ,CAAC,GAAG,CAA0B;IAOjC,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;CAuEpC"}
|
package/distribution/deployer.js
CHANGED
@@ -39,7 +39,7 @@ let Deployer = class Deployer {
|
|
39
39
|
Utils.assert.defined(genesisBlock);
|
40
40
|
const validatorContractAddress = ethers.getCreateAddress({ from: __classPrivateFieldGet(this, _Deployer_deployerAddress, "f"), nonce: 0 });
|
41
41
|
const genesisInfo = {
|
42
|
-
account: genesisBlock.block.generatorAddress
|
42
|
+
account: genesisBlock.block.generatorAddress,
|
43
43
|
deployerAccount: __classPrivateFieldGet(this, _Deployer_deployerAddress, "f"),
|
44
44
|
initialSupply: Utils.BigNumber.make(genesisBlock.block.totalAmount).toBigInt(),
|
45
45
|
validatorContract: validatorContractAddress,
|
@@ -54,8 +54,8 @@ let Deployer = class Deployer {
|
|
54
54
|
timestamp: BigInt(genesisBlock.block.timestamp),
|
55
55
|
validatorAddress: __classPrivateFieldGet(this, _Deployer_deployerAddress, "f"),
|
56
56
|
};
|
57
|
-
const
|
58
|
-
const constructorArguments = new ethers.AbiCoder().encode(["uint8"], [
|
57
|
+
const activeValidators = this.configuration.getMilestone(1).activeValidators; // TODO update on milestone change
|
58
|
+
const constructorArguments = new ethers.AbiCoder().encode(["uint8"], [activeValidators]).slice(2);
|
59
59
|
const nonce = BigInt(__classPrivateFieldGet(this, _Deployer_nonce, "f"));
|
60
60
|
const result = await this.evm.process({
|
61
61
|
blockContext,
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"deployer.js","sourceRoot":"","sources":["../source/deployer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AACjE,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,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AC,uBAAA,IAAI,iCAAiB,CAAC,CAAC;QAE1G,IAAI,CAAC,GAAG;aACN,IAAI,CAAC,uBAAuB,CAAC,SAAS,CAAC,SAAS,CAAC,SAAS,CAAC;aAC3D,eAAe,CAAC,MAAM,CAAC,OAAO,CAAC,uBAAwB,CAAC,CAAC;QAE3D,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,uBAAuB,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,eAAe,CAAC,WAAW,CAAC,CAAC;QAEzF,MAAM,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC;YACvB,GAAG,SAAS;YACZ,QAAQ,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;YAChD,iBAAiB,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC;SACtB,CAAC,CAAC;IACX,CAAC;CACD,CAAA;;;;AAxFiB;IADhB,MAAM,CAAC,WAAW,CAAC,WAAW,CAAC,QAAQ,CAAC;;qCACW;AAGnC;IADhB,MAAM,CAAC,WAAW,CAAC,YAAY,CAAC,aAAa,CAAC;;+CACiB;AAG/C;IADhB,MAAM,CAAC,WAAW,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC;;wCACS;AAIjC;IAFhB,MAAM,CAAC,WAAW,CAAC,GAAG,CAAC,QAAQ,CAAC;IAChC,MAAM,CAAC,UAAU,EAAE,KAAK,CAAC;;qCACoB;AAZlC,QAAQ;IADpB,UAAU,EAAE;GACA,QAAQ,CA0FpB"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../source/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;
|
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,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,qBACa,eAAgB,SAAQ,SAAS,CAAC,eAAe;IAChD,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAOzB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;CAKlC"}
|
package/distribution/index.js
CHANGED
@@ -9,12 +9,14 @@ import { Identifiers } from "@mainsail/contracts";
|
|
9
9
|
import { Providers } from "@mainsail/kernel";
|
10
10
|
import { Deployer } from "./deployer.js";
|
11
11
|
import { Selector } from "./selector.js";
|
12
|
+
import { ConsensusContractService } from "./services/consensus-contract-service.js";
|
12
13
|
import { ValidatorSet } from "./validator-set.js";
|
13
14
|
export { Identifiers } from "./identifiers.js";
|
14
15
|
let ServiceProvider = class ServiceProvider extends Providers.ServiceProvider {
|
15
16
|
async register() {
|
16
17
|
this.app.bind(Identifiers.ValidatorSet.Service).to(ValidatorSet).inSingletonScope();
|
17
18
|
this.app.bind(Identifiers.Proposer.Selector).to(Selector).inSingletonScope();
|
19
|
+
this.app.bind(Identifiers.Evm.ContractService.Consensus).to(ConsensusContractService);
|
18
20
|
}
|
19
21
|
async boot() {
|
20
22
|
this.app.get(Identifiers.Services.Log.Service).info("Booting EVM Consensus...");
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../source/index.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAa,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAE7C,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,OAAO,EAAE,WAAW,EAAE,MA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IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,wBAAwB,CAAC,CAAC;IACvF,CAAC;IAEM,KAAK,CAAC,IAAI;QAChB,IAAI,CAAC,GAAG,CAAC,GAAG,CAA0B,WAAW,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,0BAA0B,CAAC,CAAC;QAEzG,MAAM,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,MAAM,EAAE,CAAC;IAC3C,CAAC;CACD,CAAA;AAbY,eAAe;IAD3B,UAAU,EAAE;GACA,eAAe,CAa3B"}
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import { Contracts } from "@mainsail/contracts";
|
2
|
+
export declare class ConsensusContractService implements Contracts.Evm.ConsensusContractService {
|
3
|
+
private readonly app;
|
4
|
+
private readonly configuration;
|
5
|
+
private readonly evm;
|
6
|
+
getActiveValidators(): Promise<Contracts.State.ValidatorWallet[]>;
|
7
|
+
getAllValidators(): Promise<Contracts.State.ValidatorWallet[]>;
|
8
|
+
getValidatorRounds(): AsyncIterable<Contracts.Evm.ValidatorRound>;
|
9
|
+
getVotesCount(): Promise<number>;
|
10
|
+
getVotes(): AsyncIterable<Contracts.Evm.Vote>;
|
11
|
+
}
|
12
|
+
//# sourceMappingURL=consensus-contract-service.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"consensus-contract-service.d.ts","sourceRoot":"","sources":["../../source/services/consensus-contract-service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAe,MAAM,qBAAqB,CAAC;AAS7D,qBACa,wBAAyB,YAAW,SAAS,CAAC,GAAG,CAAC,wBAAwB;IAEtF,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAgC;IAGpD,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAkC;IAIhE,OAAO,CAAC,QAAQ,CAAC,GAAG,CAA0B;IAExC,mBAAmB,IAAI,OAAO,CAAC,SAAS,CAAC,KAAK,CAAC,eAAe,EAAE,CAAC;IAuCjE,gBAAgB,IAAI,OAAO,CAAC,SAAS,CAAC,KAAK,CAAC,eAAe,EAAE,CAAC;IAuCpE,kBAAkB,IAAI,aAAa,CAAC,SAAS,CAAC,GAAG,CAAC,cAAc,CAAC;IAI3D,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC;IAwBtC,QAAQ,IAAI,aAAa,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC;CAG7C"}
|
@@ -0,0 +1,121 @@
|
|
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, tagged } from "@mainsail/container";
|
11
|
+
import { Contracts, Identifiers } from "@mainsail/contracts";
|
12
|
+
import { ConsensusAbi } from "@mainsail/evm-contracts";
|
13
|
+
import { BigNumber } from "@mainsail/utils";
|
14
|
+
import { ethers } from "ethers";
|
15
|
+
import { Identifiers as EvmConsensusIdentifiers } from "../identifiers.js";
|
16
|
+
import { AsyncValidatorRoundsIterator } from "./rounds-iterator.js";
|
17
|
+
import { AsyncVotesIterator } from "./votes-iterator.js";
|
18
|
+
let ConsensusContractService = class ConsensusContractService {
|
19
|
+
async getActiveValidators() {
|
20
|
+
const consensusContractAddress = this.app.get(EvmConsensusIdentifiers.Contracts.Addresses.Consensus);
|
21
|
+
const deployerAddress = this.app.get(EvmConsensusIdentifiers.Internal.Addresses.Deployer);
|
22
|
+
const { evmSpec } = this.configuration.getMilestone();
|
23
|
+
const iface = new ethers.Interface(ConsensusAbi.abi);
|
24
|
+
const data = iface.encodeFunctionData("getTopValidators").slice(2);
|
25
|
+
const result = await this.evm.view({
|
26
|
+
caller: deployerAddress,
|
27
|
+
data: Buffer.from(data, "hex"),
|
28
|
+
recipient: consensusContractAddress,
|
29
|
+
specId: evmSpec,
|
30
|
+
});
|
31
|
+
if (!result.success) {
|
32
|
+
await this.app.terminate("getTopValidators failed");
|
33
|
+
}
|
34
|
+
const [validators] = iface.decodeFunctionResult("getTopValidators", result.output);
|
35
|
+
const validatorWallets = [];
|
36
|
+
for (const [, validator] of validators.entries()) {
|
37
|
+
const [address, [votersCount, voteBalance, isResigned, blsPublicKey]] = validator;
|
38
|
+
const validatorWallet = {
|
39
|
+
address,
|
40
|
+
blsPublicKey: blsPublicKey.slice(2),
|
41
|
+
isResigned,
|
42
|
+
voteBalance: BigNumber.make(voteBalance),
|
43
|
+
votersCount: Number(votersCount),
|
44
|
+
};
|
45
|
+
validatorWallets.push(validatorWallet);
|
46
|
+
}
|
47
|
+
return validatorWallets;
|
48
|
+
}
|
49
|
+
async getAllValidators() {
|
50
|
+
const consensusContractAddress = this.app.get(EvmConsensusIdentifiers.Contracts.Addresses.Consensus);
|
51
|
+
const deployerAddress = this.app.get(EvmConsensusIdentifiers.Internal.Addresses.Deployer);
|
52
|
+
const { evmSpec } = this.configuration.getMilestone();
|
53
|
+
const iface = new ethers.Interface(ConsensusAbi.abi);
|
54
|
+
const data = iface.encodeFunctionData("getAllValidators").slice(2);
|
55
|
+
const result = await this.evm.view({
|
56
|
+
caller: deployerAddress,
|
57
|
+
data: Buffer.from(data, "hex"),
|
58
|
+
recipient: consensusContractAddress,
|
59
|
+
specId: evmSpec,
|
60
|
+
});
|
61
|
+
if (!result.success) {
|
62
|
+
await this.app.terminate("getAllValidators failed");
|
63
|
+
}
|
64
|
+
const [validators] = iface.decodeFunctionResult("getAllValidators", result.output);
|
65
|
+
const validatorWallets = [];
|
66
|
+
for (const [, validator] of validators.entries()) {
|
67
|
+
const [address, [votersCount, voteBalance, isResigned, blsPublicKey]] = validator;
|
68
|
+
const validatorWallet = {
|
69
|
+
address,
|
70
|
+
blsPublicKey: blsPublicKey.slice(2),
|
71
|
+
isResigned,
|
72
|
+
voteBalance: BigNumber.make(voteBalance),
|
73
|
+
votersCount: Number(votersCount),
|
74
|
+
};
|
75
|
+
validatorWallets.push(validatorWallet);
|
76
|
+
}
|
77
|
+
return validatorWallets;
|
78
|
+
}
|
79
|
+
getValidatorRounds() {
|
80
|
+
return this.app.resolve(AsyncValidatorRoundsIterator);
|
81
|
+
}
|
82
|
+
async getVotesCount() {
|
83
|
+
const consensusContractAddress = this.app.get(EvmConsensusIdentifiers.Contracts.Addresses.Consensus);
|
84
|
+
const deployerAddress = this.app.get(EvmConsensusIdentifiers.Internal.Addresses.Deployer);
|
85
|
+
const { evmSpec } = this.configuration.getMilestone();
|
86
|
+
const iface = new ethers.Interface(ConsensusAbi.abi);
|
87
|
+
const data = iface.encodeFunctionData("getVotesCount").slice(2);
|
88
|
+
const result = await this.evm.view({
|
89
|
+
caller: deployerAddress,
|
90
|
+
data: Buffer.from(data, "hex"),
|
91
|
+
recipient: consensusContractAddress,
|
92
|
+
specId: evmSpec,
|
93
|
+
});
|
94
|
+
if (!result.success) {
|
95
|
+
await this.app.terminate("getVotesCount failed");
|
96
|
+
}
|
97
|
+
const [voters] = iface.decodeFunctionResult("getVotesCount", result.output);
|
98
|
+
return Number(voters);
|
99
|
+
}
|
100
|
+
getVotes() {
|
101
|
+
return this.app.resolve(AsyncVotesIterator);
|
102
|
+
}
|
103
|
+
};
|
104
|
+
__decorate([
|
105
|
+
inject(Identifiers.Application.Instance),
|
106
|
+
__metadata("design:type", Object)
|
107
|
+
], ConsensusContractService.prototype, "app", void 0);
|
108
|
+
__decorate([
|
109
|
+
inject(Identifiers.Cryptography.Configuration),
|
110
|
+
__metadata("design:type", Object)
|
111
|
+
], ConsensusContractService.prototype, "configuration", void 0);
|
112
|
+
__decorate([
|
113
|
+
inject(Identifiers.Evm.Instance),
|
114
|
+
tagged("instance", "evm"),
|
115
|
+
__metadata("design:type", Object)
|
116
|
+
], ConsensusContractService.prototype, "evm", void 0);
|
117
|
+
ConsensusContractService = __decorate([
|
118
|
+
injectable()
|
119
|
+
], ConsensusContractService);
|
120
|
+
export { ConsensusContractService };
|
121
|
+
//# sourceMappingURL=consensus-contract-service.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"consensus-contract-service.js","sourceRoot":"","sources":["../../source/services/consensus-contract-service.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AACjE,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,WAAW,IAAI,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAC3E,OAAO,EAAE,4BAA4B,EAAE,MAAM,sBAAsB,CAAC;AACpE,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAGlD,IAAM,wBAAwB,GAA9B,MAAM,wBAAwB;IAWpC,KAAK,CAAC,mBAAmB;QACxB,MAAM,wBAAwB,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAS,uBAAuB,CAAC,SAAS,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;QAC7G,MAAM,eAAe,GAAG,IAAI,C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E,wBAAwB;YACnC,MAAM,EAAE,OAAO;SACf,CAAC,CAAC;QAEH,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;YACrB,MAAM,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,sBAAsB,CAAC,CAAC;QAClD,CAAC;QAED,MAAM,CAAC,MAAM,CAAC,GAAG,KAAK,CAAC,oBAAoB,CAAC,eAAe,EAAE,MAAM,CAAC,MAAO,CAAC,CAAC;QAE7E,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC;IACvB,CAAC;IAED,QAAQ;QACP,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC;IAC7C,CAAC;CACD,CAAA;AAtHiB;IADhB,MAAM,CAAC,WAAW,CAAC,WAAW,CAAC,QAAQ,CAAC;;qDACW;AAGnC;IADhB,MAAM,CAAC,WAAW,CAAC,YAAY,CAAC,aAAa,CAAC;;+DACiB;AAI/C;IAFhB,MAAM,CAAC,WAAW,CAAC,GAAG,CAAC,QAAQ,CAAC;IAChC,MAAM,CAAC,UAAU,EAAE,KAAK,CAAC;;qDACoB;AATlC,wBAAwB;IADpC,UAAU,EAAE;GACA,wBAAwB,CAwHpC"}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import { Contracts } from "@mainsail/contracts";
|
2
|
+
export declare class AsyncValidatorRoundsIterator implements AsyncIterable<Contracts.Evm.ValidatorRound> {
|
3
|
+
#private;
|
4
|
+
private readonly app;
|
5
|
+
private readonly configuration;
|
6
|
+
private readonly evm;
|
7
|
+
[Symbol.asyncIterator](): AsyncIterator<Contracts.Evm.ValidatorRound>;
|
8
|
+
next(): Promise<IteratorResult<Contracts.Evm.ValidatorRound>>;
|
9
|
+
private getRounds;
|
10
|
+
}
|
11
|
+
//# sourceMappingURL=rounds-iterator.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"rounds-iterator.d.ts","sourceRoot":"","sources":["../../source/services/rounds-iterator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAe,MAAM,qBAAqB,CAAC;AAU7D,qBACa,4BAA6B,YAAW,aAAa,CAAC,SAAS,CAAC,GAAG,CAAC,cAAc,CAAC;;IAE/F,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAgC;IAGpD,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAkC;IAIhE,OAAO,CAAC,QAAQ,CAAC,GAAG,CAA0B;IAM9C,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,aAAa,CAAC,SAAS,CAAC,GAAG,CAAC,cAAc,CAAC;IAI/D,IAAI,IAAI,OAAO,CAAC,cAAc,CAAC,SAAS,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;YAerD,SAAS;CA4CvB"}
|
@@ -0,0 +1,104 @@
|
|
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
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
11
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
12
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
13
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
14
|
+
};
|
15
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
16
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
17
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
18
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
19
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
20
|
+
};
|
21
|
+
var _AsyncValidatorRoundsIterator_rounds, _AsyncValidatorRoundsIterator_index, _AsyncValidatorRoundsIterator_offset;
|
22
|
+
import { inject, injectable, tagged } from "@mainsail/container";
|
23
|
+
import { Contracts, Identifiers } from "@mainsail/contracts";
|
24
|
+
import { ConsensusAbi } from "@mainsail/evm-contracts";
|
25
|
+
import { Utils } from "@mainsail/kernel";
|
26
|
+
import { BigNumber } from "@mainsail/utils";
|
27
|
+
import { ethers } from "ethers";
|
28
|
+
import { Identifiers as EvmConsensusIdentifiers } from "../identifiers.js";
|
29
|
+
const ROUNDS_PER_REQUEST = 10_000;
|
30
|
+
let AsyncValidatorRoundsIterator = class AsyncValidatorRoundsIterator {
|
31
|
+
constructor() {
|
32
|
+
_AsyncValidatorRoundsIterator_rounds.set(this, []);
|
33
|
+
_AsyncValidatorRoundsIterator_index.set(this, 0); // Index of returned round in chunk
|
34
|
+
_AsyncValidatorRoundsIterator_offset.set(this, 0); // Offset for querying rounds
|
35
|
+
}
|
36
|
+
[(_AsyncValidatorRoundsIterator_rounds = new WeakMap(), _AsyncValidatorRoundsIterator_index = new WeakMap(), _AsyncValidatorRoundsIterator_offset = new WeakMap(), Symbol.asyncIterator)]() {
|
37
|
+
return this;
|
38
|
+
}
|
39
|
+
async next() {
|
40
|
+
var _a, _b;
|
41
|
+
if (__classPrivateFieldGet(this, _AsyncValidatorRoundsIterator_rounds, "f").length === __classPrivateFieldGet(this, _AsyncValidatorRoundsIterator_index, "f")) {
|
42
|
+
__classPrivateFieldSet(this, _AsyncValidatorRoundsIterator_rounds, await this.getRounds(), "f");
|
43
|
+
if (__classPrivateFieldGet(this, _AsyncValidatorRoundsIterator_rounds, "f").length === 0) {
|
44
|
+
return { done: true, value: undefined };
|
45
|
+
}
|
46
|
+
__classPrivateFieldSet(this, _AsyncValidatorRoundsIterator_index, 0, "f");
|
47
|
+
__classPrivateFieldSet(this, _AsyncValidatorRoundsIterator_offset, __classPrivateFieldGet(this, _AsyncValidatorRoundsIterator_offset, "f") + __classPrivateFieldGet(this, _AsyncValidatorRoundsIterator_rounds, "f").length, "f");
|
48
|
+
}
|
49
|
+
return { done: false, value: __classPrivateFieldGet(this, _AsyncValidatorRoundsIterator_rounds, "f")[__classPrivateFieldSet(this, _AsyncValidatorRoundsIterator_index, (_b = __classPrivateFieldGet(this, _AsyncValidatorRoundsIterator_index, "f"), _a = _b++, _b), "f"), _a] };
|
50
|
+
}
|
51
|
+
async getRounds() {
|
52
|
+
const consensusContractAddress = this.app.get(EvmConsensusIdentifiers.Contracts.Addresses.Consensus);
|
53
|
+
const deployerAddress = this.app.get(EvmConsensusIdentifiers.Internal.Addresses.Deployer);
|
54
|
+
const { evmSpec } = this.configuration.getMilestone();
|
55
|
+
const iface = new ethers.Interface(ConsensusAbi.abi);
|
56
|
+
const data = iface.encodeFunctionData("getRounds", [__classPrivateFieldGet(this, _AsyncValidatorRoundsIterator_offset, "f"), ROUNDS_PER_REQUEST]).slice(2);
|
57
|
+
const result = await this.evm.view({
|
58
|
+
caller: deployerAddress,
|
59
|
+
data: Buffer.from(data, "hex"),
|
60
|
+
recipient: consensusContractAddress,
|
61
|
+
specId: evmSpec,
|
62
|
+
});
|
63
|
+
if (!result.success) {
|
64
|
+
await this.app.terminate("getRounds failed");
|
65
|
+
}
|
66
|
+
const [results] = iface.decodeFunctionResult("getRounds", result.output);
|
67
|
+
const validatorRounds = [];
|
68
|
+
for (const validatorRound of results) {
|
69
|
+
const [round, validators] = validatorRound;
|
70
|
+
const roundNumber = Number(round);
|
71
|
+
validatorRounds.push({
|
72
|
+
round: roundNumber,
|
73
|
+
roundHeight: Utils.roundCalculator.calculateRoundInfoByRound(roundNumber, this.configuration)
|
74
|
+
.roundHeight,
|
75
|
+
validators: validators.map((validator) => {
|
76
|
+
const [validatorAddress, voteBalance] = validator;
|
77
|
+
return {
|
78
|
+
address: validatorAddress,
|
79
|
+
voteBalance: BigNumber.make(voteBalance),
|
80
|
+
};
|
81
|
+
}),
|
82
|
+
});
|
83
|
+
}
|
84
|
+
return validatorRounds;
|
85
|
+
}
|
86
|
+
};
|
87
|
+
__decorate([
|
88
|
+
inject(Identifiers.Application.Instance),
|
89
|
+
__metadata("design:type", Object)
|
90
|
+
], AsyncValidatorRoundsIterator.prototype, "app", void 0);
|
91
|
+
__decorate([
|
92
|
+
inject(Identifiers.Cryptography.Configuration),
|
93
|
+
__metadata("design:type", Object)
|
94
|
+
], AsyncValidatorRoundsIterator.prototype, "configuration", void 0);
|
95
|
+
__decorate([
|
96
|
+
inject(Identifiers.Evm.Instance),
|
97
|
+
tagged("instance", "evm"),
|
98
|
+
__metadata("design:type", Object)
|
99
|
+
], AsyncValidatorRoundsIterator.prototype, "evm", void 0);
|
100
|
+
AsyncValidatorRoundsIterator = __decorate([
|
101
|
+
injectable()
|
102
|
+
], AsyncValidatorRoundsIterator);
|
103
|
+
export { AsyncValidatorRoundsIterator };
|
104
|
+
//# sourceMappingURL=rounds-iterator.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"rounds-iterator.js","sourceRoot":"","sources":["../../source/services/rounds-iterator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AACjE,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC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CAAC,yBAAyB,CAAC,WAAW,EAAE,IAAI,CAAC,aAAa,CAAC;qBAC3F,WAAW;gBACb,UAAU,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE;oBACxC,MAAM,CAAC,gBAAgB,EAAE,WAAW,CAAC,GAAG,SAAS,CAAC;oBAElD,OAAO;wBACN,OAAO,EAAE,gBAAgB;wBACzB,WAAW,EAAE,SAAS,CAAC,IAAI,CAAC,WAAW,CAAC;qBACxC,CAAC;gBACH,CAAC,CAAC;aACF,CAAC,CAAC;QACJ,CAAC;QAED,OAAO,eAAe,CAAC;IACxB,CAAC;CACD,CAAA;AA5EiB;IADhB,MAAM,CAAC,WAAW,CAAC,WAAW,CAAC,QAAQ,CAAC;;yDACW;AAGnC;IADhB,MAAM,CAAC,WAAW,CAAC,YAAY,CAAC,aAAa,CAAC;;mEACiB;AAI/C;IAFhB,MAAM,CAAC,WAAW,CAAC,GAAG,CAAC,QAAQ,CAAC;IAChC,MAAM,CAAC,UAAU,EAAE,KAAK,CAAC;;yDACoB;AATlC,4BAA4B;IADxC,UAAU,EAAE;GACA,4BAA4B,CA8ExC"}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import { Contracts } from "@mainsail/contracts";
|
2
|
+
export declare class AsyncVotesIterator implements AsyncIterable<Contracts.Evm.Vote> {
|
3
|
+
#private;
|
4
|
+
private readonly app;
|
5
|
+
private readonly configuration;
|
6
|
+
private readonly evm;
|
7
|
+
[Symbol.asyncIterator](): AsyncIterator<Contracts.Evm.Vote>;
|
8
|
+
next(): Promise<IteratorResult<Contracts.Evm.Vote>>;
|
9
|
+
private getVotes;
|
10
|
+
}
|
11
|
+
//# sourceMappingURL=votes-iterator.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"votes-iterator.d.ts","sourceRoot":"","sources":["../../source/services/votes-iterator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAe,MAAM,qBAAqB,CAAC;AAQ7D,qBACa,kBAAmB,YAAW,aAAa,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC;;IAE3E,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAgC;IAGpD,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAkC;IAIhE,OAAO,CAAC,QAAQ,CAAC,GAAG,CAA0B;IAM9C,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,aAAa,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC;IAIrD,IAAI,IAAI,OAAO,CAAC,cAAc,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;YAe3C,QAAQ;CAuBtB"}
|
@@ -0,0 +1,85 @@
|
|
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
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
11
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
12
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
13
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
14
|
+
};
|
15
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
16
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
17
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
18
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
19
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
20
|
+
};
|
21
|
+
var _AsyncVotesIterator_address, _AsyncVotesIterator_votes, _AsyncVotesIterator_index;
|
22
|
+
import { inject, injectable, tagged } from "@mainsail/container";
|
23
|
+
import { Contracts, Identifiers } from "@mainsail/contracts";
|
24
|
+
import { ConsensusAbi } from "@mainsail/evm-contracts";
|
25
|
+
import { ethers } from "ethers";
|
26
|
+
import { Identifiers as EvmConsensusIdentifiers } from "../identifiers.js";
|
27
|
+
const VOTES_PER_REQUEST = 10_000;
|
28
|
+
let AsyncVotesIterator = class AsyncVotesIterator {
|
29
|
+
constructor() {
|
30
|
+
_AsyncVotesIterator_address.set(this, "0x0000000000000000000000000000000000000000");
|
31
|
+
_AsyncVotesIterator_votes.set(this, []);
|
32
|
+
_AsyncVotesIterator_index.set(this, 0);
|
33
|
+
}
|
34
|
+
[(_AsyncVotesIterator_address = new WeakMap(), _AsyncVotesIterator_votes = new WeakMap(), _AsyncVotesIterator_index = new WeakMap(), Symbol.asyncIterator)]() {
|
35
|
+
return this;
|
36
|
+
}
|
37
|
+
async next() {
|
38
|
+
var _a, _b;
|
39
|
+
if (__classPrivateFieldGet(this, _AsyncVotesIterator_votes, "f").length === __classPrivateFieldGet(this, _AsyncVotesIterator_index, "f")) {
|
40
|
+
__classPrivateFieldSet(this, _AsyncVotesIterator_votes, await this.getVotes(), "f");
|
41
|
+
if (__classPrivateFieldGet(this, _AsyncVotesIterator_votes, "f").length === 0) {
|
42
|
+
return { done: true, value: undefined };
|
43
|
+
}
|
44
|
+
__classPrivateFieldSet(this, _AsyncVotesIterator_index, 0, "f");
|
45
|
+
__classPrivateFieldSet(this, _AsyncVotesIterator_address, __classPrivateFieldGet(this, _AsyncVotesIterator_votes, "f").at(-1).voterAddress, "f");
|
46
|
+
}
|
47
|
+
return { done: false, value: __classPrivateFieldGet(this, _AsyncVotesIterator_votes, "f")[__classPrivateFieldSet(this, _AsyncVotesIterator_index, (_b = __classPrivateFieldGet(this, _AsyncVotesIterator_index, "f"), _a = _b++, _b), "f"), _a] };
|
48
|
+
}
|
49
|
+
async getVotes() {
|
50
|
+
const consensusContractAddress = this.app.get(EvmConsensusIdentifiers.Contracts.Addresses.Consensus);
|
51
|
+
const deployerAddress = this.app.get(EvmConsensusIdentifiers.Internal.Addresses.Deployer);
|
52
|
+
const { evmSpec } = this.configuration.getMilestone();
|
53
|
+
const iface = new ethers.Interface(ConsensusAbi.abi);
|
54
|
+
const data = iface.encodeFunctionData("getVotes", [__classPrivateFieldGet(this, _AsyncVotesIterator_address, "f"), VOTES_PER_REQUEST]).slice(2);
|
55
|
+
const result = await this.evm.view({
|
56
|
+
caller: deployerAddress,
|
57
|
+
data: Buffer.from(data, "hex"),
|
58
|
+
recipient: consensusContractAddress,
|
59
|
+
specId: evmSpec,
|
60
|
+
});
|
61
|
+
if (!result.success) {
|
62
|
+
await this.app.terminate("getVotes failed");
|
63
|
+
}
|
64
|
+
const [votes] = iface.decodeFunctionResult("getVotes", result.output);
|
65
|
+
return votes.map((vote) => ({ validatorAddress: vote[1], voterAddress: vote[0] }));
|
66
|
+
}
|
67
|
+
};
|
68
|
+
__decorate([
|
69
|
+
inject(Identifiers.Application.Instance),
|
70
|
+
__metadata("design:type", Object)
|
71
|
+
], AsyncVotesIterator.prototype, "app", void 0);
|
72
|
+
__decorate([
|
73
|
+
inject(Identifiers.Cryptography.Configuration),
|
74
|
+
__metadata("design:type", Object)
|
75
|
+
], AsyncVotesIterator.prototype, "configuration", void 0);
|
76
|
+
__decorate([
|
77
|
+
inject(Identifiers.Evm.Instance),
|
78
|
+
tagged("instance", "evm"),
|
79
|
+
__metadata("design:type", Object)
|
80
|
+
], AsyncVotesIterator.prototype, "evm", void 0);
|
81
|
+
AsyncVotesIterator = __decorate([
|
82
|
+
injectable()
|
83
|
+
], AsyncVotesIterator);
|
84
|
+
export { AsyncVotesIterator };
|
85
|
+
//# sourceMappingURL=votes-iterator.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"votes-iterator.js","sourceRoot":"","sources":["../../source/services/votes-iterator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AACjE,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,WAAW,IAAI,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAE3E,MAAM,iBAAiB,GAAG,MAAM,CAAC;AAG1B,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;IAAxB;QAWN,sCAAW,4CAA4C,EAAC;QACxD,oCAA+B,EAAE,EAAC;QAClC,oCAAS,CAAC,EAAC;IA4CZ,CAAC;IA1CA,qIAAC,MAAM,CAAC,aAAa,EAAC;QACrB,OAAO,IAAI,CAAC;IACb,CAAC;IAED,KAAK,CAAC,IAAI;;QACT,IAAI,uBAAA,IAAI,iCAAO,CAAC,MAAM,KAAK,uBAAA,IAAI,iCAAO,EAAE,CAAC;YACxC,uBAAA,IAAI,6BAAU,MAAM,IAAI,CAAC,QAAQ,EAAE,MAAA,CAAC;YAEpC,IAAI,uBAAA,IAAI,iCAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBAC9B,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;YACzC,CAAC;YAED,uBAAA,IAAI,6BA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AAC;QAC7C,CAAC;QAED,MAAM,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC,oBAAoB,CAAC,UAAU,EAAE,MAAM,CAAC,MAAO,CAAC,CAAC;QAEvE,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,IAAc,EAAE,EAAE,CAAC,CAAC,EAAE,gBAAgB,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAC9F,CAAC;CACD,CAAA;AAvDiB;IADhB,MAAM,CAAC,WAAW,CAAC,WAAW,CAAC,QAAQ,CAAC;;+CACW;AAGnC;IADhB,MAAM,CAAC,WAAW,CAAC,YAAY,CAAC,aAAa,CAAC;;yDACiB;AAI/C;IAFhB,MAAM,CAAC,WAAW,CAAC,GAAG,CAAC,QAAQ,CAAC;IAChC,MAAM,CAAC,UAAU,EAAE,KAAK,CAAC;;+CACoB;AATlC,kBAAkB;IAD9B,UAAU,EAAE;GACA,kBAAkB,CAyD9B"}
|
@@ -1,9 +1,8 @@
|
|
1
1
|
import { Contracts } from "@mainsail/contracts";
|
2
2
|
export declare class ValidatorSet implements Contracts.ValidatorSet.Service {
|
3
3
|
#private;
|
4
|
-
private readonly app;
|
5
4
|
private readonly configuration;
|
6
|
-
private readonly
|
5
|
+
private readonly consensusContractService;
|
7
6
|
restore(): Promise<void>;
|
8
7
|
onCommit(unit: Contracts.Processor.ProcessableUnit): Promise<void>;
|
9
8
|
getAllValidators(): Contracts.State.ValidatorWallet[];
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"validator-set.d.ts","sourceRoot":"","sources":["../source/validator-set.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAA2B,MAAM,qBAAqB,CAAC;
|
1
|
+
{"version":3,"file":"validator-set.d.ts","sourceRoot":"","sources":["../source/validator-set.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAA2B,MAAM,qBAAqB,CAAC;AAGzE,qBACa,YAAa,YAAW,SAAS,CAAC,YAAY,CAAC,OAAO;;IAElE,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAkC;IAGhE,OAAO,CAAC,QAAQ,CAAC,wBAAwB,CAA0C;IAQtE,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAOxB,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC,SAAS,CAAC,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC;IAQxE,gBAAgB,IAAI,SAAS,CAAC,KAAK,CAAC,eAAe,EAAE;IAIrD,kBAAkB,IAAI,SAAS,CAAC,KAAK,CAAC,eAAe,EAAE;IAIvD,mBAAmB,IAAI,SAAS,CAAC,KAAK,CAAC,eAAe,EAAE;IAUxD,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC,KAAK,CAAC,eAAe;IAI5D,gCAAgC,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM;CAwCtE"}
|
@@ -18,13 +18,10 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
|
|
18
18
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
19
19
|
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
20
20
|
};
|
21
|
-
var _ValidatorSet_instances, _ValidatorSet_topValidators, _ValidatorSet_indexByAddress, _ValidatorSet_allValidators, _ValidatorSet_dirtyValidators, _ValidatorSet_buildActiveValidators, _ValidatorSet_calculateChangedValidators
|
22
|
-
import { inject, injectable
|
21
|
+
var _ValidatorSet_instances, _ValidatorSet_topValidators, _ValidatorSet_indexByAddress, _ValidatorSet_allValidators, _ValidatorSet_dirtyValidators, _ValidatorSet_buildActiveValidators, _ValidatorSet_calculateChangedValidators;
|
22
|
+
import { inject, injectable } from "@mainsail/container";
|
23
23
|
import { Contracts, Exceptions, Identifiers } from "@mainsail/contracts";
|
24
|
-
import { ConsensusAbi } from "@mainsail/evm-contracts";
|
25
24
|
import { Utils } from "@mainsail/kernel";
|
26
|
-
import { ethers } from "ethers";
|
27
|
-
import { Identifiers as EvmConsensusIdentifiers } from "./identifiers.js";
|
28
25
|
let ValidatorSet = class ValidatorSet {
|
29
26
|
constructor() {
|
30
27
|
_ValidatorSet_instances.add(this);
|
@@ -35,7 +32,7 @@ let ValidatorSet = class ValidatorSet {
|
|
35
32
|
}
|
36
33
|
async restore() {
|
37
34
|
await __classPrivateFieldGet(this, _ValidatorSet_instances, "m", _ValidatorSet_buildActiveValidators).call(this);
|
38
|
-
const validators = await
|
35
|
+
const validators = await this.consensusContractService.getAllValidators();
|
39
36
|
__classPrivateFieldSet(this, _ValidatorSet_allValidators, new Map(validators.map((validator) => [validator.address, validator])), "f");
|
40
37
|
}
|
41
38
|
async onCommit(unit) {
|
@@ -75,7 +72,7 @@ _ValidatorSet_dirtyValidators = new WeakMap();
|
|
75
72
|
_ValidatorSet_instances = new WeakSet();
|
76
73
|
_ValidatorSet_buildActiveValidators = async function _ValidatorSet_buildActiveValidators() {
|
77
74
|
const { activeValidators } = this.configuration.getMilestone();
|
78
|
-
const validators = await
|
75
|
+
const validators = await this.consensusContractService.getActiveValidators();
|
79
76
|
if (validators.length < activeValidators) {
|
80
77
|
throw new Exceptions.NotEnoughActiveValidatorsError(__classPrivateFieldGet(this, _ValidatorSet_topValidators, "f").length, activeValidators);
|
81
78
|
}
|
@@ -84,7 +81,7 @@ _ValidatorSet_buildActiveValidators = async function _ValidatorSet_buildActiveVa
|
|
84
81
|
};
|
85
82
|
_ValidatorSet_calculateChangedValidators = async function _ValidatorSet_calculateChangedValidators() {
|
86
83
|
__classPrivateFieldSet(this, _ValidatorSet_dirtyValidators, [], "f");
|
87
|
-
const validators = await
|
84
|
+
const validators = await this.consensusContractService.getAllValidators();
|
88
85
|
for (const validator of validators) {
|
89
86
|
const currentValidator = __classPrivateFieldGet(this, _ValidatorSet_allValidators, "f").get(validator.address);
|
90
87
|
if (!currentValidator ||
|
@@ -97,79 +94,14 @@ _ValidatorSet_calculateChangedValidators = async function _ValidatorSet_calculat
|
|
97
94
|
}
|
98
95
|
__classPrivateFieldSet(this, _ValidatorSet_allValidators, new Map(validators.map((validator) => [validator.address, validator])), "f");
|
99
96
|
};
|
100
|
-
_ValidatorSet_getActiveValidators = async function _ValidatorSet_getActiveValidators() {
|
101
|
-
const consensusContractAddress = this.app.get(EvmConsensusIdentifiers.Contracts.Addresses.Consensus);
|
102
|
-
const deployerAddress = this.app.get(EvmConsensusIdentifiers.Internal.Addresses.Deployer);
|
103
|
-
const { evmSpec } = this.configuration.getMilestone();
|
104
|
-
const iface = new ethers.Interface(ConsensusAbi.abi);
|
105
|
-
const data = iface.encodeFunctionData("getTopValidators").slice(2);
|
106
|
-
const result = await this.evm.view({
|
107
|
-
caller: deployerAddress,
|
108
|
-
data: Buffer.from(data, "hex"),
|
109
|
-
recipient: consensusContractAddress,
|
110
|
-
specId: evmSpec,
|
111
|
-
});
|
112
|
-
if (!result.success) {
|
113
|
-
this.app.terminate("getTopValidators failed");
|
114
|
-
}
|
115
|
-
const [validators] = iface.decodeFunctionResult("getTopValidators", result.output);
|
116
|
-
const validatorWallets = [];
|
117
|
-
for (const [, validator] of validators.entries()) {
|
118
|
-
const [address, [votersCount, voteBalance, isResigned, blsPublicKey]] = validator;
|
119
|
-
const validatorWallet = {
|
120
|
-
address,
|
121
|
-
blsPublicKey: blsPublicKey.slice(2),
|
122
|
-
isResigned,
|
123
|
-
voteBalance: Utils.BigNumber.make(voteBalance),
|
124
|
-
votersCount: Number(votersCount),
|
125
|
-
};
|
126
|
-
validatorWallets.push(validatorWallet);
|
127
|
-
}
|
128
|
-
return validatorWallets;
|
129
|
-
};
|
130
|
-
_ValidatorSet_getAllValidators = async function _ValidatorSet_getAllValidators() {
|
131
|
-
const consensusContractAddress = this.app.get(EvmConsensusIdentifiers.Contracts.Addresses.Consensus);
|
132
|
-
const deployerAddress = this.app.get(EvmConsensusIdentifiers.Internal.Addresses.Deployer);
|
133
|
-
const { evmSpec } = this.configuration.getMilestone();
|
134
|
-
const iface = new ethers.Interface(ConsensusAbi.abi);
|
135
|
-
const data = iface.encodeFunctionData("getAllValidators").slice(2);
|
136
|
-
const result = await this.evm.view({
|
137
|
-
caller: deployerAddress,
|
138
|
-
data: Buffer.from(data, "hex"),
|
139
|
-
recipient: consensusContractAddress,
|
140
|
-
specId: evmSpec,
|
141
|
-
});
|
142
|
-
if (!result.success) {
|
143
|
-
this.app.terminate("getAllValidators failed");
|
144
|
-
}
|
145
|
-
const [validators] = iface.decodeFunctionResult("getAllValidators", result.output);
|
146
|
-
const validatorWallets = [];
|
147
|
-
for (const [, validator] of validators.entries()) {
|
148
|
-
const [address, [votersCount, voteBalance, isResigned, blsPublicKey]] = validator;
|
149
|
-
const validatorWallet = {
|
150
|
-
address,
|
151
|
-
blsPublicKey: blsPublicKey.slice(2),
|
152
|
-
isResigned,
|
153
|
-
voteBalance: Utils.BigNumber.make(voteBalance),
|
154
|
-
votersCount: Number(votersCount),
|
155
|
-
};
|
156
|
-
validatorWallets.push(validatorWallet);
|
157
|
-
}
|
158
|
-
return validatorWallets;
|
159
|
-
};
|
160
|
-
__decorate([
|
161
|
-
inject(Identifiers.Application.Instance),
|
162
|
-
__metadata("design:type", Object)
|
163
|
-
], ValidatorSet.prototype, "app", void 0);
|
164
97
|
__decorate([
|
165
98
|
inject(Identifiers.Cryptography.Configuration),
|
166
99
|
__metadata("design:type", Object)
|
167
100
|
], ValidatorSet.prototype, "configuration", void 0);
|
168
101
|
__decorate([
|
169
|
-
inject(Identifiers.Evm.
|
170
|
-
tagged("instance", "evm"),
|
102
|
+
inject(Identifiers.Evm.ContractService.Consensus),
|
171
103
|
__metadata("design:type", Object)
|
172
|
-
], ValidatorSet.prototype, "
|
104
|
+
], ValidatorSet.prototype, "consensusContractService", void 0);
|
173
105
|
ValidatorSet = __decorate([
|
174
106
|
injectable()
|
175
107
|
], ValidatorSet);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"validator-set.js","sourceRoot":"","sources":["../source/validator-set.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,
|
1
|
+
{"version":3,"file":"validator-set.js","sourceRoot":"","sources":["../source/validator-set.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,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAGlC,IAAM,YAAY,GAAlB,MAAM,YAAY;IAAlB;;QAON,sCAAoD,EAAE,EAAC;QACvD,uCAAuC,IAAI,GAAG,EAAE,EAAC;QAEjD,sCAA+D,IAAI,GAAG,EAAE,EAAC;QACzE,wCAAsD,EAAE,EAAC;IA+E1D,CAAC;IA7EO,KAAK,CAAC,OAAO;QACnB,MAAM,uBAAA,IAAI,oEAAuB,MAA3B,IAAI,CAAyB,CAAC;QAEpC,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,wBAAwB,CAAC,gBAAgB,EAAE,CAAC;QAC1E,uBAAA,IAAI,+BAAkB,IAAI,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,SAAS,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC,CAAC,MAAA,CAAC;IAC9F,CAAC;IAEM,KAAK,CAAC,QAAQ,CAAC,IAAyC;QAC9D,IAAI,KAAK,CAAC,eAAe,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,IAAI,CAAC,aAAa,CAAC,EAAE,CAAC;YAC3E,MAAM,uBAAA,IAAI,oEAAuB,MAA3B,IAAI,CAAyB,CAAC;QACrC,CAAC;QAED,MAAM,uBAAA,IAAI,yEAA4B,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AAa,CAAC;;mDACiB;AAG/C;IADhB,MAAM,CAAC,WAAW,CAAC,GAAG,CAAC,eAAe,CAAC,SAAS,CAAC;;8DACiC;AALvE,YAAY;IADxB,UAAU,EAAE;GACA,YAAY,CA0FxB"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@mainsail/evm-consensus",
|
3
|
-
"version": "0.0.1-evm.
|
3
|
+
"version": "0.0.1-evm.7",
|
4
4
|
"description": "EVM development support for the Mainsail blockchain",
|
5
5
|
"license": "GPL-3.0-only",
|
6
6
|
"contributors": [],
|
@@ -12,10 +12,11 @@
|
|
12
12
|
],
|
13
13
|
"dependencies": {
|
14
14
|
"ethers": "^6.11.0",
|
15
|
-
"@mainsail/container": "0.0.1-evm.
|
16
|
-
"@mainsail/contracts": "0.0.1-evm.
|
17
|
-
"@mainsail/
|
18
|
-
"@mainsail/
|
15
|
+
"@mainsail/container": "0.0.1-evm.7",
|
16
|
+
"@mainsail/contracts": "0.0.1-evm.7",
|
17
|
+
"@mainsail/kernel": "0.0.1-evm.7",
|
18
|
+
"@mainsail/utils": "0.0.1-evm.7",
|
19
|
+
"@mainsail/evm-contracts": "0.0.1-evm.7"
|
19
20
|
},
|
20
21
|
"devDependencies": {
|
21
22
|
"@types/seedrandom": "^3.0.8",
|