Skip to content

Commit 7ca28b5

Browse files
OttoAllmendingeraider
andcommitted
feat(abstract-utxo): add UtxoCoinName type
Issue: BTC-1801 Co-authored-by: aider <[email protected]>
1 parent 172c85c commit 7ca28b5

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

modules/abstract-utxo/src/names.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,35 @@
11
import * as utxolib from '@bitgo/utxo-lib';
22

3+
export const utxoCoinsMainnet = ['btc', 'bch', 'bcha', 'bsv', 'btg', 'dash', 'doge', 'ltc', 'zec'] as const;
4+
export const utxoCoinsTestnet = [
5+
'tbtc',
6+
'tbch',
7+
'tbsv',
8+
'tdash',
9+
'tdoge',
10+
'tltc',
11+
'tzec',
12+
'tbtcsig',
13+
'tbtc4',
14+
'tbtcbgsig',
15+
] as const;
16+
17+
export type UtxoCoinNameMainnet = (typeof utxoCoinsMainnet)[number];
18+
export type UtxoCoinNameTestnet = (typeof utxoCoinsTestnet)[number];
19+
export type UtxoCoinName = UtxoCoinNameMainnet | UtxoCoinNameTestnet;
20+
21+
export function isUtxoCoinNameMainnet(coinName: string): coinName is UtxoCoinNameMainnet {
22+
return utxoCoinsMainnet.includes(coinName as UtxoCoinNameMainnet);
23+
}
24+
25+
export function isUtxoCoinNameTestnet(coinName: string): coinName is UtxoCoinNameTestnet {
26+
return utxoCoinsTestnet.includes(coinName as UtxoCoinNameTestnet);
27+
}
28+
29+
export function isUtxoCoinName(coinName: string): coinName is UtxoCoinName {
30+
return isUtxoCoinNameMainnet(coinName) || isUtxoCoinNameTestnet(coinName);
31+
}
32+
333
function getNetworkName(n: utxolib.Network): utxolib.NetworkName {
434
const name = utxolib.getNetworkName(n);
535
if (!name) {
@@ -12,7 +42,7 @@ function getNetworkName(n: utxolib.Network): utxolib.NetworkName {
1242
* @param n
1343
* @returns the family name for a network. Testnets and mainnets of the same coin share the same family name.
1444
*/
15-
export function getFamilyFromNetwork(n: utxolib.Network): string {
45+
export function getFamilyFromNetwork(n: utxolib.Network): UtxoCoinNameMainnet {
1646
switch (getNetworkName(n)) {
1747
case 'bitcoin':
1848
case 'testnet':

0 commit comments

Comments
 (0)