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 { 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 { //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 { 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();