Skip to content

feat: add WebSocket subscription support for consensus events#129

Draft
AgustinRamiroDiaz wants to merge 3 commits intomainfrom
new-features-for-appealers
Draft

feat: add WebSocket subscription support for consensus events#129
AgustinRamiroDiaz wants to merge 3 commits intomainfrom
new-features-for-appealers

Conversation

@AgustinRamiroDiaz
Copy link
Collaborator

Summary

  • Add WebSocket-based event subscription methods to GenLayerClient for real-time consensus event streaming
  • New subscription methods: subscribeToNewTransaction, subscribeToTransactionAccepted, subscribeToTransactionActivated, subscribeToTransactionUndetermined, subscribeToTransactionLeaderTimeout
  • Returns typed async iterable streams (ConsensusEventStream<T>) that can be consumed with for await...of
  • Add webSocketEndpoint config option to createClient()

Features

  • Typed event streams: Each subscription returns a strongly-typed ConsensusEventStream<T>
  • Shared WebSocket client: Uses WeakMap cache to share a single WS connection per GenLayerClient
  • Memory safety: Bounded event queue (max 1000 events) prevents unbounded memory growth
  • Error handling: Errors propagate through the async iterator with proper logging
  • Clean unsubscribe: Call stream.unsubscribe() to stop listening and clean up resources

Usage

const client = createClient({
  chain: testnetAsimov,
  webSocketEndpoint: 'wss://genlayer-testnet.rpc.caldera.xyz/ws',
});

// Subscribe to new transactions
const stream = client.subscribeToNewTransaction();

for await (const event of stream) {
  console.log('New tx:', event.txId, event.recipient);
}

// Or manually control the subscription
stream.unsubscribe();

Test plan

  • Build passes (npm run build)
  • TypeScript compiles (tsc --noEmit)
  • Lint passes (npm run lint)
  • Unit tests pass (npm test)
  • Manual test with actual WebSocket endpoint

🤖 Generated with Claude Code

Add subscription methods to GenLayerClient for real-time consensus
event streaming via WebSocket:

- subscribeToNewTransaction
- subscribeToTransactionAccepted
- subscribeToTransactionActivated
- subscribeToTransactionUndetermined
- subscribeToTransactionLeaderTimeout

Features:
- Typed async iterable streams (ConsensusEventStream<T>)
- Shared WebSocket client per GenLayerClient (WeakMap cache)
- Bounded event queue (max 1000) to prevent memory leaks
- Error propagation via async iterator
- webSocketEndpoint config option for createClient()

Throws WebSocketNotConfiguredError if no WS URL is configured.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@coderabbitai
Copy link

coderabbitai bot commented Feb 5, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

  • 🔍 Trigger a full review
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch new-features-for-appealers

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

AgustinRamiroDiaz and others added 2 commits February 5, 2026 14:49
Add genCall method to genlayer-js client for direct gen_call RPC access:
- Supports read, write, and deploy transaction types
- Leader/validator mode via leader_results parameter
- Returns full response: data, status, stdout, stderr, logs, events, messages
- Add GenCallResult, GenCallStatus, GenCallEvent, GenCallMessage types

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add GenCallStatusCode enum with SUCCESS, USER_ERROR, VM_ERROR,
  INTERNAL_ERROR values for type-safe status code handling
- Update GenCallStatus.code to use enum type instead of number
- Add 12 unit tests covering:
  - Basic request/response handling
  - Account resolution (client, explicit, zero address)
  - Optional parameters (value, gas, blockNumber, status)
  - leaderResults → leader_results conversion
  - Response data normalization (0x prefix handling)
  - Default values for missing response fields
  - Error status codes
  - Deploy transaction type

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant