Skip to content

Commit e05d68a

Browse files
refactor(crypto-configuration): replace get with getGenesisCommit & getNetwork (#1277)
* Add getGenesisCommit abd getNetwork * Update usages * Fix crypto transaction * Fix p2p tests * Fix bootstrapper tests * Fix database tests * Fix network-generator tests * Fix api-evm tests * Fix crypto-config tests * style: resolve style guide violations [ci-lint-fix] * Fix deps
1 parent a7974a2 commit e05d68a

35 files changed

Lines changed: 103 additions & 111 deletions

File tree

packages/api-evm/source/actions/eth-chain-id.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ export class EthChainIdAction implements Contracts.Api.RPC.Action {
1717
};
1818

1919
public async handle(parameters: []): Promise<string> {
20-
return `0x${this.configuration.get<number>("network.chainId").toString(16)}`;
20+
return `0x${this.configuration.getNetwork().chainId.toString(16)}`;
2121
}
2222
}

packages/api-evm/source/actions/net-version.test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ describe<{
1515
context.app = new Application();
1616

1717
context.app.bind(Identifiers.Cryptography.Configuration).toConstantValue({
18-
get: () => "nethash",
18+
getNetwork: () => {
19+
return {
20+
chainId: 123,
21+
};
22+
},
1923
});
2024

2125
context.action = context.app.resolve(NetVersion);
@@ -41,6 +45,6 @@ describe<{
4145
});
4246

4347
it("should return the web3 client version", async ({ action }) => {
44-
assert.equal(await action.handle([]), `nethash`);
48+
assert.equal(await action.handle([]), `123`);
4549
});
4650
});

packages/api-evm/source/actions/net-version.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ export class NetVersion implements Contracts.Api.RPC.Action {
1717
};
1818

1919
public async handle(parameters: []): Promise<string> {
20-
return this.configuration.get<number>("network.chainId").toString();
20+
return this.configuration.getNetwork().chainId.toString();
2121
}
2222
}

packages/blockchain-utils/source/format.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export const formatCurrency = (configuration: Contracts.Crypto.Configuration, am
99
minimumFractionDigits: 0,
1010
});
1111

12-
return `${localeString} ${configuration.get("network.client.symbol")}`;
12+
return `${localeString} ${configuration.getNetwork().client.symbol}`;
1313
};
1414

1515
export const formatNumber = (value: number): string => value.toLocaleString("en");

packages/blockchain-utils/source/round-calculator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export class RoundCalculator implements Contracts.BlockchainUtils.RoundCalculato
1717
private readonly configuration!: Contracts.Crypto.Configuration;
1818

1919
public isNewRound(height: number): boolean {
20-
const milestones = this.configuration.get<Contracts.Crypto.Milestone[]>("milestones");
20+
const milestones = this.configuration.getMilestones();
2121
const genesisHeight = this.configuration.getGenesisHeight();
2222

2323
// Since milestones are merged, find the first milestone to introduce the validator count.

packages/bootstrap/source/bootstrapper.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ describe<{
3535

3636
beforeEach((context) => {
3737
context.configuration = {
38-
get: () => genesisCommitJson,
38+
getGenesisCommit: () => genesisCommitJson,
3939
getGenesisHeight: () => 1,
4040
getMilestone: () => {},
4141
};

packages/bootstrap/source/bootstrapper.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,9 @@ export class Bootstrapper {
8484
}
8585

8686
async #setGenesisCommit(): Promise<void> {
87-
const genesisBlockJson = this.configuration.get<Contracts.Crypto.CommitJson>("genesisBlock");
88-
const genesisBlock = await this.commitFactory.fromJson(genesisBlockJson);
89-
90-
this.stateStore.setGenesisCommit(genesisBlock);
87+
const genesisCommitJson = this.configuration.getGenesisCommit();
88+
const genesisCommit = await this.commitFactory.fromJson(genesisCommitJson);
89+
this.stateStore.setGenesisCommit(genesisCommit);
9190
}
9291

9392
async #checkStoredGenesisCommit(): Promise<void> {

packages/configuration-generator/source/generators/genesis-block.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ describe<{
2424

2525
context.app = app;
2626

27-
// @ts-ignore
2827
app.get<Contracts.Crypto.Configuration>(AppIdentifiers.Cryptography.Configuration).setConfig(
2928
{
3029
genesisBlock: {
@@ -51,6 +50,9 @@ describe<{
5150
validatorRegistrationFee: "250",
5251
},
5352
],
53+
network: {
54+
chainId: 123,
55+
},
5456
},
5557
false,
5658
);

packages/contracts/source/contracts/crypto/commit.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
import type { CommitStorageData } from "../evm/storage.js";
2-
import type { Block, BlockData, BlockJson } from "./block.js";
2+
import type { Block, BlockData, BlockJson, BlockJsonCrypto } from "./block.js";
33

44
export interface CommitJson {
55
readonly block: BlockJson;
66
readonly proof: CommitProof;
77
readonly serialized: string;
88
}
99

10+
export interface CommitJsonCrypto {
11+
readonly block: BlockJsonCrypto;
12+
readonly proof: CommitProof;
13+
readonly serialized: string;
14+
}
15+
1016
export type CommitSerializable = {
1117
readonly block: Block;
1218
readonly proof: CommitProof;

packages/contracts/source/contracts/crypto/config.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
1+
import type { CommitJsonCrypto } from "./commit.js";
12
import type {
23
Milestone,
34
MilestoneDiff,
45
MilestoneKey,
56
MilestoneSearchResult,
7+
Network,
68
NetworkConfig,
79
NetworkConfigPartial,
810
} from "./networks.js";
911

1012
export interface Configuration {
1113
setConfig(config: NetworkConfigPartial, verify?: boolean): void;
1214

13-
all(): NetworkConfig | undefined;
15+
all(): NetworkConfig;
1416

1517
set<T = unknown>(key: string, value: T): void;
1618

17-
get<T = unknown>(key: string): T;
19+
getGenesisCommit(): CommitJsonCrypto;
20+
21+
getNetwork(): Network;
1822

1923
setHeight(value: number): void;
2024

0 commit comments

Comments
 (0)