Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements for scheduled miniblocks and getShards call #25

Merged
merged 3 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion example/crons/transaction.processor.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class TransactionProcessorService {
async handleNewMultiversxTransactions() {
Locker.lock('newMultiversxTransactions', async () => {
await this.transactionProcessor.start({
mode: TransactionProcessorMode.Hyperblock,
mode: TransactionProcessorMode.Shardblock,
gatewayUrl: 'https://gateway.multiversx.com', // mainnet
getLastProcessedNonce: async (_shardId: number, _currentNonce: number) => {
// In ProcessByHyperblockTransactions shardId will always be METACHAIN
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@multiversx/sdk-transaction-processor",
"version": "0.1.34",
"version": "0.1.35",
"description": "Real-time transaction processor",
"main": "lib/transaction.processor.js",
"types": "lib/transaction.processor.d.ts",
Expand Down
34 changes: 34 additions & 0 deletions src/shards-maintainer.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { METACHAIN } from "./utils/constants";
import { HttpService } from "./utils/http.service";

export class ShardsMaintainerService {
private shardIds: number[] | undefined = undefined;

async get(
baseUrl: string | undefined,
timeout: number | undefined,
) {
if (this.shardIds != null) {
return this.shardIds;
}

return this.shardIds = await this.getShards(baseUrl, timeout);
}

private async getShards(
baseUrl: string | undefined,
timeout: number | undefined,
): Promise<number[]> {
const httpService = new HttpService(baseUrl, timeout);
const networkConfig = await httpService.get('network/config');
const shardCount = networkConfig.config.erd_num_shards_without_meta;

const result = [];
for (let i = 0; i < shardCount; i++) {
result.push(i);
}
result.push(METACHAIN);

return result;
}
}
Loading