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

Release 3.2.4 #35

Merged
merged 1 commit into from
Aug 20, 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 package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "dashboard-creator-server",
"private": false,
"version": "3.2.3",
"version": "3.2.4",
"license": "MIT",
"main": "src/server.ts",
"engines": {
Expand Down
24 changes: 17 additions & 7 deletions src/components/node-api/chainstate.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,32 @@
import { ApiPromise, WsProvider } from '@polkadot/api';
import { ethers } from 'ethers';

const rpcEndpoints: { [key: string]: string } = {
polkadot: 'wss://rpc.polkadot.io',
kusama: 'wss://kusama-rpc.polkadot.io',
'aleph-zero': 'wss://rpc.azero.dev',
moonbeam: 'wss://moonbeam.api.onfinality.io/public-ws',
'arbitrum-one': 'wss://arbitrum-one.public.blastapi.io',
'arbitrum-one': 'https://arbitrum.api.onfinality.io/public',
};

export async function getCurrentBlock(chain: string) {
export async function getCurrentBlock(chain: string): Promise<number> {
const endpoint = rpcEndpoints[chain];
if (!endpoint) {
throw new Error(`RPC endpoint for chain ${chain} not found`);
}

const wsProvider = new WsProvider(endpoint);
const api = await ApiPromise.create({ provider: wsProvider });

const currentBlock = await api.rpc.chain.getHeader();
return currentBlock.number.toNumber();
if (['polkadot', 'kusama', 'aleph-zero', 'moonbeam'].includes(chain)) {
// Substrate-based chains
const wsProvider = new WsProvider(endpoint);
const api = await ApiPromise.create({ provider: wsProvider });
const currentBlock = await api.rpc.chain.getHeader();
return currentBlock.number.toNumber();
} else if (['arbitrum-one'].includes(chain)) {
// Ethereum-compatible chains (e.g., Arbitrum)
const provider = new ethers.JsonRpcProvider(endpoint);
const currentBlockNumber = await provider.getBlockNumber();
return currentBlockNumber;
} else {
throw new Error(`Chain ${chain} is not supported`);
}
}
Loading