Consolidate the event layer, single-source the network config, and validate build args (#108, #109, #111, #112) - #202
Open
mhikel66 wants to merge 10 commits into
Conversation
…union parseEvent (trustflow-protocol#108, trustflow-protocol#112) `src/events.ts` is now the single source of the event vocabulary (underscore-separated, matching the emitted Soroban topic) and payload shapes. `parseEvent` returns `ParsedTrustFlowEvent`, a discriminated union keyed on `type` — the three typed branches previously failed `tsc` with TS2322 because `EscrowCreatedData` etc. have no index signature and so did not match the `ParsedEvent<Record<string, unknown>>` default. Callers now narrow `.data` by switching on `.type`, no cast. Refs trustflow-protocol#108, trustflow-protocol#112
…ustFlowEvent aliases ParsedEvent (trustflow-protocol#108) The duplicate `TrustFlowEventType` (dot-notation) and the `{ escrowId, payload, blockNumber, txHash }` shape are removed. `TrustFlowEvent` is now an alias of the parser's discriminated union and `EventHandler` takes it, so the two `TrustFlowEventType` names no longer collide and the monitor speaks the parser's language. Refs trustflow-protocol#108
`EscrowMonitor` handlers now receive `ParsedTrustFlowEvent` — exactly what `parseEvents(rawEvents, contractId)` produces — so there is no translation step. `deliver(events)` dispatches a pre-parsed batch (used by `startPolling` and callable directly). Monitor test updated to the canonical vocabulary and shape. Closes trustflow-protocol#108
…he package root (trustflow-protocol#112) The types already reach the root via `export * from './types/events'`; add the parser functions so consumers can call them and get the discriminated-union narrowing. Refs trustflow-protocol#112
…rustflow-protocol#108, trustflow-protocol#112) Feeds a `parseEvents` output straight into an `EscrowMonitor` handler, asserts the handler receives a narrowed `escrow_created` event, and covers the unknown-type fallback and cross-contract filtering. Closes trustflow-protocol#108, closes trustflow-protocol#112
…_CONFIGS (trustflow-protocol#109) `HORIZON_URLS` / `SOROBAN_RPC_URLS` and a new `NETWORK_PASSPHRASES` are now a view of `src/stellar/network.ts`'s `NETWORK_CONFIGS` — the canonical source (it already carries the passphrase) — rather than a second copy of the URL literals. Refs trustflow-protocol#109
…source (trustflow-protocol#109) `TrustFlowClient.getNetworkPassphrase()` returned two hard-coded strings — a third copy. It now returns `NETWORK_PASSPHRASES[this.network]`, the same canonical source the URL maps use. Closes trustflow-protocol#109
…onstruction (trustflow-protocol#111) `buildCreateEscrowArgs`, `buildReleaseArgs`, and `buildDisputeArgs` now call `assertStellarAddress` / an `isValidEscrowId` guard up front, so a malformed input throws `TrustFlowError.validation(...)` — consistent with `escrow/create.ts` — instead of whatever `new Address()` throws. Closes trustflow-protocol#111
|
@mhikel66 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Four SDK issues — two type-check bugs in the event layer, a network-config duplication, and missing input validation.
#108 — two conflicting
TrustFlowEventTypesystemssrc/events.ts(the real XDR parser) usedescrow_created+ParsedEvent;src/types/events.ts+EscrowMonitorindependently usedescrow.created+ a differentTrustFlowEventshape. The names collided when both were imported, andparseEvent's output could not be fed into a monitor handler.src/events.tsis the single source — underscore vocabulary (matching the emitted SorobanSymboltopic), oneParsedEvent/ParsedEventBaseshape, one set of payload types.src/types/events.tsre-exports those;TrustFlowEventis now an alias of the parser's discriminated union andEventHandlertakes it. The dot-notation type and{ escrowId, payload, blockNumber, txHash }shape are gone.EscrowMonitorhandlers receiveParsedTrustFlowEventdirectly. Newdeliver(events)dispatches a pre-parsed batch (used bystartPolling, callable on its own).parseEvents([raw], contractId)→monitor.deliver(...)→ handler receives a narrowedescrow_createdevent, no adapter.#112 —
ParsedEvent<T>generic errors insrc/events.tsparseEvent's three typed branches (escrow_created,escrow_released,dispute_raised) failedtscwithTS2322—EscrowCreatedDataetc. have no index signature, so they don't structurally match theRecord<string, unknown>defaultT.Fixed via the better option from the issue:
parseEventnow returnsParsedTrustFlowEvent, a discriminated union keyed ontype. Each branch is correctly typed with noascast, and callers get.datanarrowing from aswitch/ifon.type. The parser functions are exported from the package root.#109 — three copies of the Stellar network config
src/constants.ts(HORIZON_URLS,SOROBAN_RPC_URLS),src/stellar/network.ts(NETWORK_CONFIGS, which also has the passphrase), andTrustFlowClient.getNetworkPassphrase()(inline strings) all encoded the same TESTNET/MAINNET values.NETWORK_CONFIGSis canonical.HORIZON_URLS/SOROBAN_RPC_URLSand a newNETWORK_PASSPHRASESinconstants.tsare a view of it (NETWORK_CONFIGS.TESTNET.horizonUrl, …), not a copy.getNetworkPassphrase()returnsNETWORK_PASSPHRASES[this.network].constants,TrustFlowClient, andNETWORK_CONFIGSresolve identically for both networks — by construction, not coincidence.constants.ts→stellar/network.tsis a one-way import (network.tsimports nothing), so no cycle.#111 — no address validation before
ScValconstructionbuildCreateEscrowArgs,buildReleaseArgs,buildDisputeArgsfed caller strings straight intonew Address(...).toScVal(). A malformed address surfaced as a raw@stellar/stellar-sdkerror, not aTrustFlowError.All three now call
assertStellarAddress(...)/ anisValidEscrowIdguard up front and throwTrustFlowError.validation(...)— consistent withescrow/create.ts/escrow/client.ts. Tests cover invalid sender / recipient / caller / escrowId for each.Not built or run in this environment (per your instruction). All
srcchanges are typed fortsc --noEmit;tests/monitor.test.tsis updated for the new event shape. No version bump.Closes #108, closes #109, closes #111, closes #112