Files
prime-sdk-node/src/interchain.ts
Andrew Miller 5ae6dbfc3f
Some checks failed
Build and Test / build (20.x) (push) Failing after 41s
Build and Test / build (18.x) (push) Failing after 44s
Publish to NPM Registry / publish (release) Successful in 51s
Build and Test / build (16.x) (push) Failing after 47s
getInterchain: perChain + chains options (default first anchor per chain); bump 1.5.0
transaction.getInterchain / block.getInterchain take an optional
{ perChain?, chains? } that maps to prime-node's ?perChain=&chains= params.
Default (no options) returns one anchor per chain. Shared buildInterchainQuery
helper + InterchainOptions type, exported; jest-tested.
2026-06-05 10:55:30 -04:00

38 lines
1.3 KiB
TypeScript

/**
* Options + query builder for the interchain-trace endpoints
* (transaction.getInterchain / block.getInterchain).
*
* Anchor proofs are chained, so by default the trace returns the first anchor
* per public chain; these options change how many and which chains are returned.
*/
export interface InterchainOptions {
/**
* Max interchain anchors returned per public chain, earliest-first.
* 1 = the first anchor per chain (the service default); 0 = all anchors.
*/
perChain?: number;
/**
* Interchain chain ids to include ("1" = ETH mainnet, "0" = BTC; testnet ids
* differ). Omit to include every chain found.
*/
chains?: string[];
}
/**
* Builds the "?perChain=...&chains=..." suffix for the interchain trace
* endpoints. Returns "" when no options are set (the server then applies its
* defaults: one anchor per chain, all chains).
*/
export function buildInterchainQuery(options?: InterchainOptions): string {
if (!options) return '';
const parts: string[] = [];
if (options.perChain !== undefined) {
parts.push(`perChain=${encodeURIComponent(String(options.perChain))}`);
}
if (options.chains && options.chains.length > 0) {
parts.push(`chains=${options.chains.map(encodeURIComponent).join(',')}`);
}
return parts.length ? `?${parts.join('&')}` : '';
}