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.
This commit is contained in:
37
src/interchain.ts
Normal file
37
src/interchain.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
* 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('&')}` : '';
|
||||
}
|
||||
Reference in New Issue
Block a user