Source:
dev b733b3c
This module is currently under active development and not ready for production use. Please do not use this module until a stable release is published.
@railgun-reloaded/scannerUnified blockchain data abstraction layer for RAILGUN events
The scanner module provides a pluggable data source interface for fetching and processing RAILGUN events from multiple backends. It abstracts away the complexity of different data providers (Subsquid indexers, IPFS snapshots, RPC nodes) behind a unified async iterator API.
DataSource<T>npm install @railgun-reloaded/scanner
Fast, indexed historical data from Subsquid GraphQL endpoints.
It reads evmBlocksConnection. Of the hosted squids, only the Sepolia squid
serves it; the mainnet squids serve the entity schema only. For another chain,
pass customSubsquidUrl of an endpoint that serves the block layer.
import { SubsquidProvider } from '@railgun-reloaded/scanner'
const provider = new SubsquidProvider({ network: 'ethereumSepolia' })
// A custom deployment can supply its endpoint explicitly instead:
const customProvider = new SubsquidProvider({
customSubsquidUrl: 'https://squid.subsquid.io/railgun-eth/graphql'
})
const iterator = provider.from({
startHeight: 10000000n,
endHeight: 15001000n,
chunkSize: 100n,
liveSync: false // Subsquid does not support live sync
})
for await (const block of iterator) {
console.log(`Block ${block.number}: ${block.transactions.length} transactions`)
for (const tx of block.transactions) {
for (const actions of tx.actions) {
// Process Shield, Unshield, Transact events
}
}
}
Provider guarantees, current readiness, composition semantics, and known
canonicalization gaps are documented in
src/sources/README.md.
All providers implement the DataSource<T> interface:
interface DataSource<T extends EVMBlock> {
isLiveProvider: boolean
head(): Promise<bigint>
from(options: SyncOptions): AsyncGenerator<T>
destroy(): void
}
type SyncOptions = {
startHeight: bigint // Starting block number
endHeight?: bigint // Ending block number (optional)
chunkSize: bigint // Number of blocks per request
liveSync?: boolean // Enable real-time streaming (RPC only)
}
The scanner normalizes all events into typed structures:
type EVMBlock = {
number: bigint
hash: Uint8Array
timestamp: bigint
transactions: EVMTransaction[]
}
type EVMTransaction = {
hash: Uint8Array
index: number
from: Uint8Array
actions: Action[][] // Nested array of Shield/Unshield/Transact events
}
type Action = Shield | Unshield | Transact
enum ActionType {
Unshield = 'Unshield',
GeneratedCommitment = 'GeneratedCommitment',
ShieldCommitment = 'ShieldCommitment',
EncryptedCommitment = 'EncryptedCommitment',
TransactCommitment = 'TransactCommitment'
}
npm run build
npm test