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.
44 lines
751 B
44 lines
751 B
/*!
|
|
* lib/bitcoin/network.js
|
|
* Copyright © 2019 – Katana Cryptographic Ltd. All Rights Reserved.
|
|
*/
|
|
'use strict'
|
|
|
|
const bitcoin = require('bitcoinjs-lib')
|
|
|
|
|
|
/**
|
|
* 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() {
|
|
this.key = 'bitcoin'
|
|
this.network = bitcoin.networks.bitcoin
|
|
|
|
for (let kw of TESTNET_KEY) {
|
|
// Calling like 'node file.js arg1 arg2'
|
|
if (process.argv.indexOf(kw) > 1) {
|
|
this.key = 'testnet'
|
|
this.network = bitcoin.networks.testnet
|
|
break
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
module.exports = new Network()
|
|
|