This repository has been archived by the owner on Jan 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
src/networks.js: define coin network names
We need to describe some more relationships between networks. For instance, it is very useful to define `getMainnet(network)` and `getTestnet(network)`. These methods would fit well in `coins.js` and can be implemented using object equality on the constants defined in `network.js`. However, importing `network.js` from `coins.js` would lead to a circular import. This change allows using `coin.js` to contain utility methods for `network.js` without having circular import problems.
- Loading branch information
1 parent
d0cc345
commit 06f0b92
Showing
2 changed files
with
79 additions
and
32 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,89 @@ | ||
// Coins supported by bitgo-bitcoinjs-lib | ||
const typeforce = require('typeforce') | ||
|
||
const coins = { | ||
BCH: 'bch', | ||
BSV: 'bsv', | ||
BTC: 'btc', | ||
BTG: 'btg', | ||
LTC: 'ltc', | ||
ZEC: 'zec', | ||
DASH: 'dash' | ||
} | ||
const networks = require('./networks') | ||
|
||
coins.isBitcoin = function (network) { | ||
return typeforce.value(coins.BTC)(network.coin) | ||
function isBitcoin (network) { | ||
return typeforce.value(networks.bitcoin.coin)(network.coin) | ||
} | ||
|
||
coins.isBitcoinCash = function (network) { | ||
return typeforce.value(coins.BCH)(network.coin) | ||
/** | ||
* @param network | ||
* @returns {boolean} true iff network is bitcoincash or bitcoincashTestnet | ||
*/ | ||
function isBitcoinCash (network) { | ||
return typeforce.value(networks.bitcoincash.coin)(network.coin) | ||
} | ||
|
||
coins.isBitcoinSV = function (network) { | ||
return typeforce.value(coins.BSV)(network.coin) | ||
/** | ||
* @param network | ||
* @returns {boolean} true iff network is bitcoingold | ||
*/ | ||
function isBitcoinGold (network) { | ||
return typeforce.value(networks.bitcoingold.coin)(network.coin) | ||
} | ||
|
||
coins.isBitcoinGold = function (network) { | ||
return typeforce.value(coins.BTG)(network.coin) | ||
/** | ||
* @param network | ||
* @returns {boolean} true iff network is bitcoinsv or bitcoinsvTestnet | ||
*/ | ||
function isBitcoinSV (network) { | ||
return typeforce.value(networks.bitcoinsv.coin)(network.coin) | ||
} | ||
|
||
coins.isDash = function (network) { | ||
return typeforce.value(coins.DASH)(network.coin) | ||
/** | ||
* @param network | ||
* @returns {boolean} true iff network is dash or dashTest | ||
*/ | ||
function isDash (network) { | ||
return typeforce.value(networks.dash.coin)(network.coin) | ||
} | ||
|
||
coins.isLitecoin = function (network) { | ||
return typeforce.value(coins.LTC)(network.coin) | ||
/** | ||
* @param network | ||
* @returns {boolean} true iff network is litecoin or litecoinTest | ||
*/ | ||
function isLitecoin (network) { | ||
return typeforce.value(networks.litecoin.coin)(network.coin) | ||
} | ||
|
||
coins.isZcash = function (network) { | ||
return typeforce.value(coins.ZEC)(network.coin) | ||
/** | ||
* @param network | ||
* @returns {boolean} true iff network is zcash or zcashTest | ||
*/ | ||
function isZcash (network) { | ||
return typeforce.value(networks.zcash.coin)(network.coin) | ||
} | ||
|
||
coins.isValidCoin = typeforce.oneOf( | ||
coins.isBitcoin, | ||
coins.isBitcoinCash, | ||
coins.isBitcoinSV, | ||
coins.isBitcoinGold, | ||
coins.isLitecoin, | ||
coins.isZcash | ||
isValidCoin = typeforce.oneOf( | ||
isBitcoin, | ||
isBitcoinCash, | ||
isBitcoinSV, | ||
isBitcoinGold, | ||
isLitecoin, | ||
isZcash | ||
) | ||
|
||
module.exports = coins | ||
module.exports = { | ||
BTC: networks.bitcoin.coin, | ||
BCH: networks.bitcoincash.coin, | ||
BSV: networks.bitcoinsv.coin, | ||
BTG: networks.bitcoingold.coin, | ||
DASH: networks.dash.coin, | ||
LTC: networks.litecoin.coin, | ||
ZEC: networks.zcash.coin, | ||
|
||
getMainnet, | ||
isMainnet, | ||
getTestnet, | ||
isTestnet, | ||
|
||
isBitcoin, | ||
isBitcoinCash, | ||
isBitcoinGold, | ||
isBitcoinSV, | ||
isDash, | ||
isLitecoin, | ||
isZcash, | ||
isValidCoin | ||
} |
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