get_interchain: per_chain + chains options (default first anchor per chain); bump 0.5.0
All checks were successful
Publish to PyPI Registry / publish (release) Successful in 23s
All checks were successful
Publish to PyPI Registry / publish (release) Successful in 23s
transaction.get_interchain / block.get_interchain take per_chain= and chains= kwargs mapping to prime-node's ?perChain=&chains= params. Default (no kwargs) returns one anchor per chain. Shared interchain_query() helper, exported; pytest.
This commit is contained in:
27
prime_sdk/interchain.py
Normal file
27
prime_sdk/interchain.py
Normal file
@@ -0,0 +1,27 @@
|
||||
"""Query builder for the interchain-trace endpoints.
|
||||
|
||||
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.
|
||||
"""
|
||||
|
||||
from typing import List, Optional
|
||||
from urllib.parse import quote
|
||||
|
||||
|
||||
def interchain_query(
|
||||
per_chain: Optional[int] = None, chains: Optional[List[str]] = None
|
||||
) -> str:
|
||||
"""Build the "?perChain=...&chains=..." suffix for the interchain trace
|
||||
endpoints.
|
||||
|
||||
Returns "" when nothing is set (the server then applies its defaults: one
|
||||
anchor per chain, all chains). ``per_chain`` caps anchors per public chain,
|
||||
earliest-first (1 = first per chain; 0 = all). ``chains`` restricts to the
|
||||
given chain ids ("1" = ETH mainnet, "0" = BTC; testnet ids differ).
|
||||
"""
|
||||
parts: List[str] = []
|
||||
if per_chain is not None:
|
||||
parts.append(f"perChain={int(per_chain)}")
|
||||
if chains:
|
||||
parts.append("chains=" + ",".join(quote(str(c), safe="") for c in chains))
|
||||
return "?" + "&".join(parts) if parts else ""
|
||||
Reference in New Issue
Block a user