| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- import * as fs from 'fs';
- import {toUtf8String,parseUnits,ContractFactory, parseEther,JsonRpcProvider, ethers ,Contract, JsonRpcSigner, Wallet,ContractTransactionResponse, MaxInt256
- ,Transaction,formatEther,
- decodeBase64
- } from 'ethers'
-
- // const chainRpc = 'http://193.123.252.127';
- // const port = ':80';
- const chainRpc = 'http://localhost';
- const port = ':21001';
-
- // const chainRpc = 'http://10.96.35.108';
- // const port = ':8545';
-
- const rpcUrl = chainRpc + port;
- const provider = new JsonRpcProvider(rpcUrl);
-
-
- async function getValidators(): Promise<any> {
- const url = rpcUrl;
- const res = await fetch(url,{
- method: 'POST',
- headers: {
- 'Content-Type' :'application/json',
- },
- body: JSON.stringify({
- jsonrpc: "2.0",
- id: 1,
- method: "qbft_getValidatorsByBlockNumber",
- params: ["latest"]
- })
- });
-
- const json = await res.json();
- // console.log(await res.json());
-
- return json;
- }
-
- async function getBlockNumber(validatorAddress: string) : Promise<number> {
-
- //eth_blockNumber
- const url = rpcUrl;
- const res = await fetch(url,{
- method: 'POST',
- headers: {
- 'Content-Type' :'application/json',
- },
- body: JSON.stringify({
- jsonrpc: "2.0",
- id: 1,
- method: "eth_blockNumber",
- params: [""]
- })
- });
-
- const json = await res.json();
- //console.log(await res.json());
-
- return json.result;
-
- return 0;
- }
-
- async function getAddress(privateKey: string): Promise<string> {
-
- const wallet = new Wallet(privateKey, provider);
- return wallet.address;
- }
-
-
-
- const genesisFile = './blockchain-info/genesis.json';
- const secretsFile = './blockchain-info/validator1.secret.json';
- async function main() {
-
- // let json = fs.readFileSync(genesisFile);
- // const genesis = JSON.parse(json.toString());
- // console.log('genesis.json 정보')
- // console.log('genesis.config = ')
- // console.log(genesis.config);
- // console.log(`최대 블록 크기 (gasLimit) : ${genesis.gasLimit}`);
-
- // // 벨리데이터 노드 어드레스 가져오기
- // const validators = (await getValidators()).result;
- // console.log(validators);
-
- // // validator 1 노드의 노드키에서 유도된 주소를 확인 (벨리데이터 노드의 주소목록에 있는지 확인)
- // json = fs.readFileSync(secretsFile);
- // const secrets = JSON.parse(json.toString());
- // let nodeAddress = Buffer.from(secrets.data.nodekey,'base64').toString('utf8');
- // nodeAddress = await getAddress(nodeAddress);
- // console.log(nodeAddress);
-
- // const found = validators.find((el) => el == nodeAddress.toLowerCase());
- // console.log(`node address ${found} is found on validators`);
-
- let bn = await getBlockNumber(chainRpc + '21001');
- console.log(bn);
-
- bn = await getBlockNumber(chainRpc + '21002');
- console.log(bn);
-
- bn = await getBlockNumber(chainRpc + '21003');
- console.log(bn);
-
- bn = await getBlockNumber(chainRpc + '21004');
- console.log(bn);
-
- }
-
- main();
|