|
|
@ -1,7 +1,7 @@ |
|
|
|
import { debug } from 'electron-log'; |
|
|
|
import { join } from 'path'; |
|
|
|
import { IChart } from '@mrblenny/react-flow-chart'; |
|
|
|
import { BitcoinNode, LightningNode } from 'shared/types'; |
|
|
|
import { LndNode } from 'shared/types'; |
|
|
|
import { Network, NetworksFile } from 'types'; |
|
|
|
import { networksPath } from './config'; |
|
|
|
import { APP_VERSION } from './constants'; |
|
|
@ -15,13 +15,17 @@ import { getLndFilePaths } from './network'; |
|
|
|
*/ |
|
|
|
const migrateCharts = (charts: Record<number, IChart>): Record<number, IChart> => { |
|
|
|
Object.entries(charts).forEach(([id, chart]) => { |
|
|
|
debug(`Migrating chart for network with id #${id}`); |
|
|
|
Object.values(chart.nodes).forEach(node => { |
|
|
|
if (node.type === 'bitcoin') { |
|
|
|
debug(`Migrating chart for network ID #${id}`); |
|
|
|
debug(`adding peer-left port to ${node.id}`); |
|
|
|
node.ports['peer-left'] = { id: 'peer-left', type: 'left' }; |
|
|
|
debug(`adding peer-right port to ${node.id}`); |
|
|
|
node.ports['peer-right'] = { id: 'peer-right', type: 'right' }; |
|
|
|
if (!node.ports['peer-left']) { |
|
|
|
debug(`[v0.2.0] adding peer-left port to ${node.id} in chart`); |
|
|
|
node.ports['peer-left'] = { id: 'peer-left', type: 'left' }; |
|
|
|
} |
|
|
|
if (!node.ports['peer-right']) { |
|
|
|
debug(`[v0.2.0] adding peer-right port to ${node.id} in chart`); |
|
|
|
node.ports['peer-right'] = { id: 'peer-right', type: 'right' }; |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
@ -29,50 +33,51 @@ const migrateCharts = (charts: Record<number, IChart>): Record<number, IChart> = |
|
|
|
}; |
|
|
|
|
|
|
|
/** |
|
|
|
* In the upgrade from v0.1.0 to v0.2.0, the path where network data is stored |
|
|
|
* v0.1.0 -> v0.2.0: the path where network data is stored |
|
|
|
* was moved to a different path. This function ensures that the paths set for |
|
|
|
* the network and the nodes are correct, as the networks folder could have |
|
|
|
* been moved manually |
|
|
|
* v0.2.1 -> 0.3.0: the docker property was added to bitcoin and lightning |
|
|
|
* nodes to save a custom startup command |
|
|
|
* @param networks the list of networks to migrate |
|
|
|
*/ |
|
|
|
const migrateNetworks = (networks: Network[]): Network[] => { |
|
|
|
const migrateBitcoinNodes = (network: Network): BitcoinNode[] => { |
|
|
|
return network.nodes.bitcoin.map(node => { |
|
|
|
debug(`updated Bitcoin node peers for ${node.name}`); |
|
|
|
return { |
|
|
|
...node, |
|
|
|
peers: [], |
|
|
|
}; |
|
|
|
networks.forEach(network => { |
|
|
|
debug(`Migrating network '${network.name}' id #${network.id}`); |
|
|
|
const newPath = join(networksPath, network.id.toString()); |
|
|
|
if (network.path !== newPath) { |
|
|
|
debug(`[v0.2.0] updating network path from '${network.path}' to '${newPath}'`); |
|
|
|
network.path = newPath; |
|
|
|
} |
|
|
|
network.nodes.bitcoin.forEach(node => { |
|
|
|
if (!node.peers) { |
|
|
|
debug(`[v0.2.0] set default peers for Bitcoin node ${node.name}`); |
|
|
|
node.peers = []; |
|
|
|
} |
|
|
|
if (!node.docker) { |
|
|
|
debug(`[v0.3.0] set docker command for Bitcoin node ${node.name}`); |
|
|
|
node.docker = { command: '' }; |
|
|
|
} |
|
|
|
}); |
|
|
|
}; |
|
|
|
const migrateLightningNodes = (network: Network): LightningNode[] => { |
|
|
|
return network.nodes.lightning.map(node => { |
|
|
|
network.nodes.lightning.forEach(node => { |
|
|
|
if (!node.docker) { |
|
|
|
debug(`[v0.3.0] set docker command for ${node.implementation} node ${node.name}`); |
|
|
|
node.docker = { command: '' }; |
|
|
|
} |
|
|
|
if (node.implementation === 'LND') { |
|
|
|
debug(`updated LND node paths for ${node.name}`); |
|
|
|
return { |
|
|
|
...node, |
|
|
|
paths: getLndFilePaths(node.name, network), |
|
|
|
}; |
|
|
|
const newPaths = getLndFilePaths(node.name, network); |
|
|
|
if ((node as LndNode).paths.tlsCert !== newPaths.tlsCert) { |
|
|
|
debug(`[v0.2.0] updated LND node paths for ${node.name}`); |
|
|
|
(node as LndNode).paths = newPaths; |
|
|
|
} |
|
|
|
} |
|
|
|
return node; |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
|
return networks.map(n => { |
|
|
|
debug(`Migrating paths in network ${n.name} #${n.id}`); |
|
|
|
const network = { |
|
|
|
...n, |
|
|
|
path: join(networksPath, n.id.toString()), |
|
|
|
}; |
|
|
|
debug(`updated network path from '${n.path}' to '${network.path}'`); |
|
|
|
network.nodes.bitcoin = migrateBitcoinNodes(network); |
|
|
|
network.nodes.lightning = migrateLightningNodes(network); |
|
|
|
return network; |
|
|
|
}); |
|
|
|
return networks; |
|
|
|
}; |
|
|
|
|
|
|
|
/** |
|
|
|
* Migrates network and chart data that was created in v0.1.0 to work with v0.2.0 |
|
|
|
* Migrates network and chart data from a previous app version |
|
|
|
* @param file the data from the `networks.json` file |
|
|
|
*/ |
|
|
|
export const migrateNetworksFile = (file: NetworksFile): NetworksFile => { |
|
|
@ -82,6 +87,6 @@ export const migrateNetworksFile = (file: NetworksFile): NetworksFile => { |
|
|
|
networks: migrateNetworks(file.networks), |
|
|
|
charts: migrateCharts(file.charts), |
|
|
|
}; |
|
|
|
debug('migrations complete'); |
|
|
|
debug('Migrations complete'); |
|
|
|
return migrated; |
|
|
|
}; |
|
|
|