Skip to content

Commit

Permalink
Default to using the bitcoin mainnet network subdirectory
Browse files Browse the repository at this point in the history
To ease migration for c-lightning v0.8.0 users.

See ElementsProject/lightning-charge#69

Resolves ElementsProject/lightning-charge#70
and shesek/spark-wallet#130
  • Loading branch information
shesek committed Dec 17, 2019
1 parent 0dfc1d2 commit a39f373
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,36 @@

const path = require('path');
const net = require('net');
const fs = require('fs');
const readline = require('readline');
const debug = require('debug')('clightning-client');
const {EventEmitter} = require('events');
const LightningError = require('error/typed')({ type: 'lightning', message: 'lightning-client error' })
const methods = require('./methods');

const defaultRpcPath = path.join(require('os').homedir(), '.lightning')
, fStat = (...p) => fs.statSync(path.join(...p))
, fExists = (...p) => fs.existsSync(path.join(...p))

class LightningClient extends EventEmitter {
constructor(rpcPath=defaultRpcPath) {
if (!path.isAbsolute(rpcPath)) {
throw new Error('The rpcPath must be an absolute path');
}

if (rpcPath.slice(-14) !== '/lightning-rpc') {
rpcPath = path.join(rpcPath, '/lightning-rpc');
if (!fExists(rpcPath) || !fStat(rpcPath).isSocket()) {
// network directory provided, use the lightning-rpc within in
if (fExists(rpcPath, 'lightning-rpc')) {
rpcPath = path.join(rpcPath, 'lightning-rpc');
}

// main data directory provided, default to using the bitcoin mainnet subdirectory
// to be removed in v0.2.0
else if (fExists(rpcPath, 'bitcoin', 'lightning-rpc')) {
console.error(`WARN: ${rpcPath}/lightning-rpc is missing, using the bitcoin mainnet subdirectory at ${rpcPath}/bitcoin instead.`)
console.error(`WARN: specifying the main lightning data directory is deprecated, please specify the network directory explicitly with "--ln-path ${rpcPath}/<network>".\n`)
rpcPath = path.join(rpcPath, 'bitcoin', 'lightning-rpc')
}
}

debug(`Connecting to ${rpcPath}`);
Expand Down

0 comments on commit a39f373

Please sign in to comment.