You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1014 B

6 years ago
/*!
* lib/bitcoin/network.js
* Copyright © 2019 Katana Cryptographic Ltd. All Rights Reserved.
*/
'use strict'
const bitcoin = require('bitcoinjs-lib')
const keys = require('../../keys/')
6 years ago
/**
* A set of keywords encoding for mainnet
*/
const MAINNET_KEY = [
'bitcoin'
]
6 years ago
/**
* A set of keywords encoding for testnet
*/
const TESTNET_KEY = [
'testnet',
'testing',
'test'
]
/**
* A singleton determining which network to run: bitcoin or testnet
*/
class Network {
/**
* Constructor
*/
constructor() {
// Check if mainnet config is detected in index.js
for (let kw of MAINNET_KEY) {
if (kw in keys) {
this.key = 'bitcoin'
this.network = bitcoin.networks.bitcoin
return
}
}
// Check if testnet config is detected in index.js
6 years ago
for (let kw of TESTNET_KEY) {
if (kw in keys) {
6 years ago
this.key = 'testnet'
this.network = bitcoin.networks.testnet
return
6 years ago
}
}
}
}
module.exports = new Network()