Skip to content

refactor(web): extract shared getVouches helper to eliminate duplication (fixes #66) - #301

Open
NePreby wants to merge 1 commit into
vouchlabsio:mainfrom
NePreby:refactor/extract-shared-get-vouches-helper
Open

NePreby wants to merge 1 commit into
vouchlabsio:mainfrom
NePreby:refactor/extract-shared-get-vouches-helper

Conversation

@NePreby

@NePreby NePreby commented Nov 9, 2026

Copy link
Copy Markdown

Overview

Resolves #66 by eliminating the duplicated get_vouches contract simulation across client and server runtimes, extracting a single, unified, server-safe read helper.

Changes Made

  1. Shared Read Helper (packages/web/lib/shared/getVouches.ts):
    • Implemented simulateGetVouches(params: GetVouchesParams) as the single source of truth for constructing Contract("get_vouches"), setting fee and timeout options, executing simulateTransaction, validating simulation errors via Api.isSimulationError, and unpacking scValToNative.
    • Free of Node-only dependencies (Buffer, node:crypto) so it can be safely imported by browser bundles.
  2. Browser Layer (packages/web/lib/stellar.js):
    • Refactored getVouches(cfg, _sourceAddress, contentHash32) to delegate simulation to simulateGetVouches.
  3. Server Layer (packages/web/server/utils/chain.ts):
    • Cleaned up broken merge artifacts and removed the duplicate const account declaration.
    • Refactored getVouchesOnChain(cfg, contentField) to convert contentField to fieldToBytes32 and delegate simulation to simulateGetVouches with cached getReadSourceAccount.
  4. Verification:
    • Verified clean execution across all unit tests (stellar.test.js, chain.test.js, and chain.test.ts), with 9 of 9 tests passing offline.

Closes #66


Contributor Payout

  • Network: TRX Tron (TRC20)
  • Address: TMqmJjRgVS21NL2eFtfyHciTxvE4BqGmEv

…ion (fixes vouchlabsio#66)

- Extract single implementation of get_vouches simulation into simulateGetVouches in packages/web/lib/shared/getVouches.ts
- Update packages/web/lib/stellar.js getVouches to delegate to simulateGetVouches
- Remove duplicate account declaration in packages/web/server/utils/chain.ts and delegate getVouchesOnChain to simulateGetVouches
- Ensure browser bundle remains clean of Node-only imports
- Verify all 9 vitest unit tests across stellar.test.js, chain.test.js, and chain.test.ts pass

Closes vouchlabsio#66
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.

[Bounty: $70] Remove the duplicated getVouches implementation

1 participant