-
Notifications
You must be signed in to change notification settings - Fork 215
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- helper function that takes chainInfo and assetInfo and registers the data in ChainHub
- Loading branch information
1 parent
c1b406c
commit e72782d
Showing
6 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Binary file modified
BIN
+47 Bytes
(100%)
packages/builders/test/snapshots/orchestration-imports.test.js.snap
Binary file not shown.
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/** | ||
* @import {ChainHub, CosmosChainInfo, Denom, DenomDetail} from '../types.js'; | ||
*/ | ||
|
||
/** | ||
* Registers chains, connections, assets in the provided chainHub. | ||
* | ||
* If either is not provided, registration will be skipped. | ||
* | ||
* @param {ChainHub} chainHub | ||
* @param {Record<string, Brand<'nat'>>} brands | ||
* @param {Record<string, CosmosChainInfo> | undefined} chainInfo | ||
* @param {Record<Denom, DenomDetail & { brandKey?: string }> | undefined} assetInfo | ||
*/ | ||
export const registerChainsAndAssets = ( | ||
chainHub, | ||
brands, | ||
chainInfo, | ||
assetInfo, | ||
) => { | ||
if (!chainInfo) { | ||
console.log('No chain info provided, returning early.'); | ||
return; | ||
} | ||
|
||
const conns = {}; | ||
for (const [chainName, allInfo] of Object.entries(chainInfo)) { | ||
const { connections, ...info } = allInfo; | ||
chainHub.registerChain(chainName, info); | ||
conns[info.chainId] = connections; | ||
} | ||
const registeredPairs = new Set(); | ||
for (const [pChainId, connInfos] of Object.entries(conns)) { | ||
for (const [cChainId, connInfo] of Object.entries(connInfos)) { | ||
const pair = [pChainId, cChainId].sort().join(''); | ||
if (!registeredPairs.has(pair)) { | ||
chainHub.registerConnection(pChainId, cChainId, connInfo); | ||
registeredPairs.add(pair); | ||
} | ||
} | ||
} | ||
|
||
if (!assetInfo) { | ||
console.log('No asset info provided, returning early.'); | ||
return; | ||
} | ||
for (const [denom, info] of Object.entries(assetInfo)) { | ||
const infoWithBrand = info.brandKey | ||
? { ...info, brand: brands[info.brandKey] } | ||
: info; | ||
chainHub.registerAsset(denom, infoWithBrand); | ||
} | ||
}; |
This file contains 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
Binary file modified
BIN
+41 Bytes
(110%)
packages/orchestration/test/snapshots/exports.test.ts.snap
Binary file not shown.