Skip to content

Commit c6afa6b

Browse files
OttoAllmendingerllm-git
andcommitted
feat(abstract-utxo): use coin name to determine coin full name
Replace the deprecated `getFullNameFromNetwork` with the new `getFullNameFromCoinName` function that determines the full coin name directly from the coin name rather than the network object. Issue: BTC-2909 Co-authored-by: llm-git <[email protected]>
1 parent 868d070 commit c6afa6b

File tree

2 files changed

+37
-47
lines changed

2 files changed

+37
-47
lines changed

modules/abstract-utxo/src/abstractUtxoCoin.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ import {
7777
} from './transaction/descriptor/verifyTransaction';
7878
import { assertDescriptorWalletAddress, getDescriptorMapFromWallet, isDescriptorWallet } from './descriptor';
7979
import {
80-
getFullNameFromNetwork,
80+
getFullNameFromCoinName,
8181
getMainnetCoinName,
8282
getNetworkFromCoinName,
8383
UtxoCoinName,
@@ -401,7 +401,7 @@ export abstract class AbstractUtxoCoin
401401
}
402402

403403
getFullName(): string {
404-
return getFullNameFromNetwork(this.network);
404+
return getFullNameFromCoinName(this.name);
405405
}
406406

407407
/** Indicates whether the coin supports a block target */

modules/abstract-utxo/src/names.ts

Lines changed: 35 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ function getNetworkName(n: utxolib.Network): utxolib.NetworkName {
5555
}
5656

5757
/**
58+
* @deprecated - will be removed when we drop support for utxolib
5859
* @param n
5960
* @returns the family name for a network. Testnets and mainnets of the same coin share the same family name.
6061
*/
@@ -146,60 +147,49 @@ export function getNetworkFromCoinName(coinName: string): utxolib.Network {
146147
/** @deprecated - use getNetworkFromCoinName instead */
147148
export const getNetworkFromChain = getNetworkFromCoinName;
148149

149-
export function getFullNameFromNetwork(n: utxolib.Network): string {
150-
const name = getNetworkName(n);
150+
function getBaseNameFromMainnet(coinName: UtxoCoinNameMainnet): string {
151+
switch (coinName) {
152+
case 'btc':
153+
return 'Bitcoin';
154+
case 'bch':
155+
return 'Bitcoin Cash';
156+
case 'bcha':
157+
return 'Bitcoin ABC';
158+
case 'btg':
159+
return 'Bitcoin Gold';
160+
case 'bsv':
161+
return 'Bitcoin SV';
162+
case 'dash':
163+
return 'Dash';
164+
case 'doge':
165+
return 'Dogecoin';
166+
case 'ltc':
167+
return 'Litecoin';
168+
case 'zec':
169+
return 'ZCash';
170+
}
171+
}
151172

173+
export function getFullNameFromCoinName(coinName: UtxoCoinName): string {
152174
let prefix: string;
153-
switch (name) {
154-
case 'bitcoinTestnet4':
175+
switch (coinName) {
176+
case 'tbtc4':
155177
prefix = 'Testnet4 ';
156178
break;
157-
case 'bitcoinPublicSignet':
179+
case 'tbtcsig':
158180
prefix = 'Public Signet ';
159181
break;
160-
case 'bitcoinBitGoSignet':
182+
case 'tbtcbgsig':
161183
prefix = 'BitGo Signet ';
162184
break;
163185
default:
164-
if (utxolib.isTestnet(n)) {
165-
prefix = 'Testnet ';
166-
} else {
167-
prefix = '';
168-
}
186+
prefix = isUtxoCoinNameTestnet(coinName) ? 'Testnet ' : '';
169187
}
170188

171-
switch (name) {
172-
case 'bitcoin':
173-
case 'testnet':
174-
case 'bitcoinTestnet4':
175-
case 'bitcoinPublicSignet':
176-
case 'bitcoinBitGoSignet':
177-
return prefix + 'Bitcoin';
178-
case 'bitcoincash':
179-
case 'bitcoincashTestnet':
180-
return prefix + 'Bitcoin Cash';
181-
case 'ecash':
182-
case 'ecashTest':
183-
return prefix + 'Bitcoin ABC';
184-
case 'bitcoingold':
185-
case 'bitcoingoldTestnet':
186-
return prefix + 'Bitcoin Gold';
187-
case 'bitcoinsv':
188-
case 'bitcoinsvTestnet':
189-
return prefix + 'Bitcoin SV';
190-
case 'dash':
191-
case 'dashTest':
192-
return prefix + 'Dash';
193-
case 'dogecoin':
194-
case 'dogecoinTest':
195-
return prefix + 'Dogecoin';
196-
case 'litecoin':
197-
case 'litecoinTest':
198-
return prefix + 'Litecoin';
199-
case 'zcash':
200-
case 'zcashTest':
201-
return prefix + 'ZCash';
202-
default:
203-
throw new Error('Unknown network');
204-
}
189+
return prefix + getBaseNameFromMainnet(getMainnetCoinName(coinName));
190+
}
191+
192+
/** @deprecated - use getFullNameFromCoinName instead */
193+
export function getFullNameFromNetwork(n: utxolib.Network): string {
194+
return getFullNameFromCoinName(getCoinName(n));
205195
}

0 commit comments

Comments
 (0)