Browse Source

determine bitcoin network based on config file instead of cli argument

umbrel
kenshin-samourai 4 years ago
parent
commit
b0a32dd42f
  1. 8
      docker/my-dojo/node/restart.sh
  2. 1
      keys/index-example.js
  3. 21
      lib/bitcoin/network.js
  4. 2
      lib/db/mysql-db-wrapper.js

8
docker/my-dojo/node/restart.sh

@ -1,14 +1,14 @@
#!/bin/bash
cd /home/node/app/accounts
forever start -a -l /dev/stdout -o /dev/null -e /dev/null index.js "$COMMON_BTC_NETWORK"
forever start -a -l /dev/stdout -o /dev/null -e /dev/null index.js
cd /home/node/app/pushtx
forever start -a -l /dev/stdout -o /dev/null -e /dev/null index.js "$COMMON_BTC_NETWORK"
forever start -a -l /dev/stdout -o /dev/null -e /dev/null index-orchestrator.js "$COMMON_BTC_NETWORK"
forever start -a -l /dev/stdout -o /dev/null -e /dev/null index.js
forever start -a -l /dev/stdout -o /dev/null -e /dev/null index-orchestrator.js
cd /home/node/app/tracker
forever start -a -l /dev/stdout -o /dev/null -e /dev/null index.js "$COMMON_BTC_NETWORK"
forever start -a -l /dev/stdout -o /dev/null -e /dev/null index.js
# Keep the container up
while true

1
keys/index-example.js

@ -6,6 +6,7 @@
/**
* Desired structure of /keys/index.js, which is ignored in the repository.
* index.js should store only one of the 2 sets of parameters (mainnet or testnet)
*/
module.exports = {
/*

21
lib/bitcoin/network.js

@ -5,8 +5,16 @@
'use strict'
const bitcoin = require('bitcoinjs-lib')
const keys = require('../../keys/')
/**
* A set of keywords encoding for mainnet
*/
const MAINNET_KEY = [
'bitcoin'
]
/**
* A set of keywords encoding for testnet
*/
@ -26,15 +34,20 @@ 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
for (let kw of TESTNET_KEY) {
// Calling like 'node file.js arg1 arg2'
if (process.argv.indexOf(kw) > 1) {
if (kw in keys) {
this.key = 'testnet'
this.network = bitcoin.networks.testnet
break
return
}
}
}

2
lib/db/mysql-db-wrapper.js

@ -5,14 +5,12 @@
'use strict'
const mysql = require('mysql')
const path = require('path')
const Logger = require('../logger')
const util = require('../util')
const errors = require('../errors')
const hdaHelper = require('../bitcoin/hd-accounts-helper')
const network = require('../bitcoin/network')
const keys = require('../../keys/')[network.key]
const keysDb = keys.db
const debug = !!(process.argv.indexOf('db-debug') > -1)
const queryDebug = !!(process.argv.indexOf('dbquery-debug') > -1)

Loading…
Cancel
Save