1- import { exec } from "child_process" ;
2- import { promisify } from "util" ;
1+ import { Ethereum } from "../utils/ethereum.js" ;
32
43type ChainInfo = {
54 pendingBlockNum : string ;
@@ -12,39 +11,47 @@ type ChainInfo = {
1211 proposerNow : string ;
1312} ;
1413
15- const execAsync = promisify ( exec ) ;
16-
1714export class ChainInfoService {
1815 static async getInfo ( ) : Promise < ChainInfo > {
1916 try {
20- // Add validator to the set
21- const command = `docker run --rm aztecprotocol/aztec:unhinged-unicorn debug-rollup -u ${ process . env . ETHEREUM_HOST } --rollup ${ process . env . ETHEREUM_ROLLUP_ADDRESS } --l1-chain-id ${ process . env . ETHEREUM_CHAIN_ID } ` ;
22- const { stdout, stderr } = await execAsync ( command ) ;
17+ const ethereum = new Ethereum ( ) ;
18+ const rollup = ethereum . getRollupContract ( ) ;
19+ const [
20+ pendingNum ,
21+ provenNum ,
22+ validators ,
23+ committee ,
24+ archive ,
25+ epochNum ,
26+ slot ,
27+ nextBlockTS ,
28+ ] = await Promise . all ( [
29+ rollup . read . getPendingBlockNumber ( ) ,
30+ rollup . read . getProvenBlockNumber ( ) ,
31+ rollup . read . getAttesters ( ) ,
32+ rollup . read . getCurrentEpochCommittee ( ) ,
33+ rollup . read . archive ( ) ,
34+ rollup . read . getCurrentEpoch ( ) ,
35+ rollup . read . getCurrentSlot ( ) ,
36+ rollup . read . getCurrentProposer ( ) ,
37+ ( async ( ) => {
38+ const block = await ethereum . getPublicClient ( ) . getBlock ( ) ;
39+ return BigInt ( block . timestamp + BigInt ( 12 ) ) ;
40+ } ) ( ) ,
41+ ] ) ;
2342
24- if ( stderr ) {
25- throw new Error ( stderr ) ;
26- }
43+ const proposer = await rollup . read . getProposerAt ( [ nextBlockTS ] ) ;
2744
28- // looks like hell, but it just parses the output of the command
29- // into a key-value object
30- const info = stdout
31- . split ( "\n" )
32- . map ( ( line ) => line . trim ( ) )
33- . filter ( Boolean )
34- . reduce ( ( acc , s ) => {
35- let [ key , value ] = s . split ( ": " ) ;
36- const sanitizedKey = key
37- . toLowerCase ( )
38- . replace ( / \s + ( .) / g, ( _ , c ) => c . toUpperCase ( ) ) ;
39- return { ...acc , [ sanitizedKey ] : value } ;
40- } , { } ) as ChainInfo ;
41- if ( typeof info . validators === "string" ) {
42- info . validators = info . validators . split ( ", " ) . map ( String ) ;
43- }
44- if ( typeof info . committee === "string" ) {
45- info . committee = info . committee . split ( ", " ) . map ( String ) ;
46- }
47- return info as ChainInfo ;
45+ return {
46+ pendingBlockNum : pendingNum as string ,
47+ provenBlockNum : provenNum as string ,
48+ validators : validators as string [ ] ,
49+ committee : committee as string [ ] ,
50+ archive : archive as string [ ] ,
51+ currentEpoch : epochNum as string ,
52+ currentSlot : slot as string ,
53+ proposerNow : proposer as string ,
54+ } ;
4855 } catch ( error ) {
4956 console . error ( "Error getting chain info:" , error ) ;
5057 throw error ;
0 commit comments