Skip to content

Add initial blockchain adapter with live block subscription #2557

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

Merged
merged 8 commits into from
Apr 26, 2025

Conversation

filipmacek
Copy link
Member

Pull Request

  • Created new blockchain adapter crate
  • Implemented BlockchainDataClient which connects to RPC client of the target chain, it can subscribes to live block events, and processes them
  • Core implementation uses CoreBlockchainRpcClient with blockchain-specific clients inheriting from this struct
  • Created BlockchainRpcClient trait with specific implementations for Ethereum, Base, Polygon, and Arbitrum to handle possible differences in RPC implementations
  • Added script watch_live_blocks that connects to a target blockchain RPC and logs newly minted blocks
  • Included README with instructions for running blockchain adapter scripts

Demo

Ethereum

CHAIN=Ethereum RPC_WSS_URL=wss://mainnet.infura.io/ws/v3/INFURA_API_KEY cargo run --bin live_blocks

Screenshot 2025-04-25 at 17 23 46

https://etherscan.io/block/22346902
https://etherscan.io/block/22346903
https://etherscan.io/block/22346904

Polygon

2025-04-25T15:25:31.816756000Z [INFO] TRADER-001.nautilus_blockchain::rpc::core: Subscribing to new blocks on chain Polygon
2025-04-25T15:25:32.584068000Z [INFO] TRADER-001.nautilus_blockchain::data: Block(chain=Polygon, number=70741230, timestamp=2025-04-25T15:25:32+00:00, hash=0x89869b3a7cf2105845e9c103f0a171b8dc58c08ff161a952183aa45366c5c628)
2025-04-25T15:25:34.561056000Z [INFO] TRADER-001.nautilus_blockchain::data: Block(chain=Polygon, number=70741231, timestamp=2025-04-25T15:25:34+00:00, hash=0x9b43212c2bc210c42e2d3e7c2777496d1551197a7e4cb8ff9bb812e303391d24)
2025-04-25T15:25:38.339429000Z [INFO] TRADER-001.nautilus_blockchain::data: Block(chain=Polygon, number=70741232, timestamp=2025-04-25T15:25:38+00:00, hash=0x91f12188bbb3355822998a21bd92bdabf6b5cdcb63e2e468d3ba5620a8855655)
2025-04-25T15:25:40.411663000Z [INFO] TRADER-001.nautilus_blockchain::data: Block(chain=Polygon, number=70741233, timestamp=2025-04-25T15:25:40+00:00, hash=0x1fe11ff30537222ff8ebdb209063f76dc80d72f1c0c15a34d0d801bcbd9b1f47)
^C2025-04-25T15:25:41.548070000Z [INFO] TRADER-001.live_blocks: Shutdown signal received, shutting down...

https://polygonscan.com/block/70741230
https://polygonscan.com/block/70741231
https://polygonscan.com/block/70741232
https://polygonscan.com/block/70741233

Arbitrum

2025-04-25T15:28:37.155275000Z [INFO] TRADER-001.nautilus_blockchain::rpc::core: Subscribing to new blocks on chain Arbitrum
2025-04-25T15:28:37.352114000Z [INFO] TRADER-001.nautilus_blockchain::data: Block(chain=Arbitrum, number=330108033, timestamp=2025-04-25T15:28:36+00:00, hash=0x390ac7314252aeed237a828ec026a85dba64b971728d8d28b523f6f6208af850)
2025-04-25T15:28:37.745130000Z [INFO] TRADER-001.nautilus_blockchain::data: Block(chain=Arbitrum, number=330108034, timestamp=2025-04-25T15:28:37+00:00, hash=0x9c30904c28d1809f9cfdda9541c72c90ed7ef9a5eecaddd2f0780a07a346c935)
2025-04-25T15:28:37.798959000Z [INFO] TRADER-001.nautilus_blockchain::data: Block(chain=Arbitrum, number=330108035, timestamp=2025-04-25T15:28:37+00:00, hash=0x1feea6daea3cc8a5676585f02813d6ec7e8da584f10dc1e8a237ed13af2f3309)
2025-04-25T15:28:38.056117000Z [INFO] TRADER-001.nautilus_blockchain::data: Block(chain=Arbitrum, number=330108036, timestamp=2025-04-25T15:28:37+00:00, hash=0xf9ad282001c7c0c01771ef017580e4e6dd30b3c2eb6622b24932f9d9f0ecddff)
2025-04-25T15:28:38.327119000Z [INFO] TRADER-001.nautilus_blockchain::data: Block(chain=Arbitrum, number=330108037, timestamp=2025-04-25T15:28:37+00:00, hash=0x6053fb3a4aefd353dbb172b2cca945f4b92ccab74b5263705acea6074105597b)
^C2025-04-25T15:28:38.407863000Z [INFO] TRADER-001.live_blocks: Shutdown signal received, shutting down...

https://arbiscan.io/block/330108033
https://arbiscan.io/block/330108034
https://arbiscan.io/block/330108035
https://arbiscan.io/block/330108036
https://arbiscan.io/block/330108037

Base

2025-04-25T15:31:08.712094000Z [INFO] TRADER-001.nautilus_blockchain::rpc::core: Subscribing to new blocks on chain Base
2025-04-25T15:31:10.548642000Z [INFO] TRADER-001.nautilus_blockchain::data: Block(chain=Base, number=29402861, timestamp=2025-04-25T15:31:09+00:00, hash=0xaad759adbcd11e86a6c5151bcea6d4b54f72f2764c60427e08165d3da51805a0)
2025-04-25T15:31:12.237541000Z [INFO] TRADER-001.nautilus_blockchain::data: Block(chain=Base, number=29402862, timestamp=2025-04-25T15:31:11+00:00, hash=0x1adfdfe90199ec31a0e07d9beb555d521f20669492b16ba92b5115322888ac8e)
2025-04-25T15:31:14.424594000Z [INFO] TRADER-001.nautilus_blockchain::data: Block(chain=Base, number=29402863, timestamp=2025-04-25T15:31:13+00:00, hash=0xa6c7612247311c4aefbf8c4ad17715236f7b9ef3fcc376c7d6ba02ffa8ed45d3)
^C2025-04-25T15:31:15.672135000Z [INFO] TRADER-001.live_blocks: Shutdown signal received, shutting down...

https://basescan.org/block/29402861
https://basescan.org/block/29402862
https://basescan.org/block/29402863

@filipmacek filipmacek added the rust Relating to the Rust core label Apr 25, 2025
@filipmacek filipmacek requested a review from cjdsellers April 25, 2025 15:34
@filipmacek filipmacek self-assigned this Apr 25, 2025
@filipmacek filipmacek force-pushed the blockchain-adapter-live-blocks branch from e66ffe7 to 8cb2159 Compare April 26, 2025 09:59
Copy link
Member

@cjdsellers cjdsellers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌

@cjdsellers cjdsellers changed the title Create initial blockchain adapter with live block subscription Add initial blockchain adapter with live block subscription Apr 26, 2025
@cjdsellers cjdsellers merged commit fc6f9cb into develop Apr 26, 2025
17 checks passed
@cjdsellers cjdsellers deleted the blockchain-adapter-live-blocks branch April 26, 2025 22:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rust Relating to the Rust core
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants