Skip to content

Commit

Permalink
Merge pull request #648 from EspressoSystems/feat/block-scanner
Browse files Browse the repository at this point in the history
Block scanner improvements
  • Loading branch information
sveitser authored Oct 3, 2023
2 parents d5a86d8 + 4151bc4 commit 6dcde47
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions scripts/espresso_block_scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
### For each found transaction, display the VM block containing that transaction, including inclusion proofs for transactions in the Espresso block.

import argparse
from datetime import datetime
import urllib.request
import json
import time
import datetime
import sys

parser = argparse.ArgumentParser(
Expand All @@ -24,8 +24,12 @@
# Keep track of transaction to avoid showing duplicates
payloads = set()

# Find the current block number.
res = urllib.request.urlopen(f"{args.url}/status/latest_block_height")
block_number = int(res.read())
print(f"scanning from block {block_number}")

# Scan block by block
block_number = 0
while True:
try:
page = urllib.request.urlopen(f"{url}{block_number}")
Expand All @@ -44,6 +48,7 @@
# We are Ok Espresso block found in page
# If block contains transactions, extract Rollup id and find block with inclusion proofs for the rollup

received = datetime.now()
block = page.read()
struct = json.loads(block)

Expand All @@ -66,7 +71,7 @@
seen_vms.add(vm)

print(
f"### New transactions for vm {vm} found on Espresso Block {block_number} ###"
f"### New transactions for vm {vm} found on Espresso Block {block_number} received at {received} ###"
)
namespace_block_url = f"{url}{block_number}/namespace/{vm}"
print("GET " + namespace_block_url)
Expand Down Expand Up @@ -112,7 +117,7 @@

# transform unix timespamp to date
timestamp = vm_block_struct["header"]["metadata"]["timestamp"]
date = datetime.datetime.fromtimestamp(timestamp)
date = datetime.fromtimestamp(timestamp)
vm_block_struct["header"]["metadata"]["timestamp"] = str(date)

# print trimmed block
Expand Down

0 comments on commit 6dcde47

Please sign in to comment.