Browse Source

Merge pull request #68 from LN-Zap/fix/main.dev.js

Fix/main.dev.js
renovate/lint-staged-8.x
JimmyMow 7 years ago
committed by GitHub
parent
commit
511aecaa0b
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. BIN
      app/app.icns
  2. 16
      app/components/LndSyncing/LndSyncing.js
  3. 15
      app/components/LndSyncing/LndSyncing.scss
  4. BIN
      app/icons/zap.icns
  5. 5
      app/lnd/lib/lightning.js
  6. 177
      app/main.dev.js
  7. 20
      app/reducers/lnd.js
  8. 1
      app/routes/app/components/App.js
  9. 8
      package.json
  10. BIN
      resources/icon.icns
  11. BIN
      resources/icon.ico
  12. BIN
      resources/icon.png
  13. 12
      resources/scripts/darwin_generate_certs.sh
  14. 11
      resources/scripts/linux_generate_certs.sh
  15. 11
      resources/scripts/win32_generate_certs.sh

BIN
app/app.icns

Binary file not shown.

16
app/components/LndSyncing/LndSyncing.js

@ -8,20 +8,20 @@ class LndSyncing extends Component {
this.state = {
facts: [
{
title: 'No2x',
description: 'Segwit2x is a hard fork proposal led by Barry Silbert and the NYA signers. The idea was drawn up and signed in a locked hotel room with select individuals and goes against everything that Bitcoin stands for. There is no favoritism in Bitcoin. There are no politicians. Hash power and business don\'t speak for us. Don\'t trust, verify.' // eslint-disable-line
title: 'The Lightning Network',
description: 'The Lightning Network is a second layer solution built on top of the Bitcoin block chain that attempts to increase Bitcoin\'s scalability and privacy' // eslint-disable-line
},
{
title: 'Gang',
description: 'Segwit2x is a hard fork proposal led by Barry Silbert and the NYA. It is bullshit. Fuck that shit.'
title: 'Payment Channel',
description: 'A payment channel is a class of techniques designed to allow users to make multiple Bitcoin transactions without commiting all of the transactions to the Bitcoin block chain. You can think of payment channels like tubes of money' // eslint-disable-line
},
{
title: 'Yo',
description: 'Segwit2x is a hard fork proposal led by Barry Silbert and the NYA. It is bullshit. Fuck that shit.'
title: 'HTLC',
description: 'Hashed TimeLock Contracts is a class of payments that use hashlocks and timelocks to require the receiver of a payment either acknowledge receiving the payment before a deadline or forfeit the ability to claim the payment. HTLCs are useful within the Lightning Network for routing payments accross two or more payment channels' // eslint-disable-line
},
{
title: 'Liiiiit',
description: 'Segwit2x is a hard fork proposal led by Barry Silbert and the NYA. It is bullshit. Fuck that shit.'
title: 'Onion Routing',
description: 'Onion routing is a technique for anonymous communication over a computer network. In an onion network, messages are encapsulated in layers of encryption, analogous to layers of an onion.' // eslint-diabale-line
}
],
currentFact: 0

15
app/components/LndSyncing/LndSyncing.scss

@ -3,9 +3,11 @@
.container {
height: 100vh;
padding: 100px;
background: $secondary;
h3 {
font-size: 50px;
color: $white;
}
.loading {
@ -18,16 +20,19 @@
min-width: 100px;
top: calc(50% - 30px);
left: calc(50% - 48px);
color: $main;
}
h1 {
margin-top: 25px;
color: $main;
}
}
.facts {
position: absolute;
bottom: 10%;
color: $white;
.fact {
transition: all 0.25s;
@ -51,24 +56,24 @@
display: inline-block;
width: 20px;
height: 20px;
background: $black;
background: $white;
opacity: 0.5;
border-radius: 50%;
margin: 0 5px;
&:hover {
opacity: 0.25;
opacity: 0.75;
}
&.active {
opacity: 0.25;
opacity: 1;
}
}
}
.spinner {
border: 1px solid rgba(0, 0, 0, 0.1);
border-left-color: rgba(0, 0, 0, 0.4);
border: 1px solid rgba(235, 184, 100, 0.1);
border-left-color: rgba(235, 184, 100, 0.4);
-webkit-border-radius: 999px;
-moz-border-radius: 999px;
border-radius: 999px;

BIN
app/icons/zap.icns

Binary file not shown.

5
app/lnd/lib/lightning.js

@ -4,11 +4,10 @@ import grpc from 'grpc'
import config from '../config'
module.exports = (rpcpath, host) => {
process.env.GRPC_SSL_CIPHER_SUITES = 'HIGH+ECDSA'
const rpc = grpc.load(path.join(__dirname, 'rpc.proto'))
const lndCert = fs.readFileSync(config.cert)
const credentials = grpc.credentials.createSsl(lndCert)
const rpc = grpc.load(path.join(__dirname, 'rpc.proto'))
return new rpc.lnrpc.Lightning(host, credentials)
}

177
app/main.dev.js

@ -16,15 +16,20 @@ import fs from 'fs'
import path from 'path'
import { spawn, exec } from 'child_process'
import { lookup } from 'ps-node'
import { platform } from 'os'
import os from 'os'
import MenuBuilder from './menu'
import lnd from './lnd'
const plat = platform()
const plat = os.platform()
const homedir = os.homedir()
let mainWindow = null
let neutrino = null
let syncing = false
let lndPath
let certPath
let certInterval
if (process.env.NODE_ENV === 'production') {
const sourceMapSupport = require('source-map-support');
@ -60,9 +65,9 @@ app.on('window-all-closed', () => {
// Respect the OSX convention of having the application in memory even
// after all windows have been closed
if (process.platform !== 'darwin') {
app.quit();
app.quit()
}
});
})
app.on('ready', async () => {
@ -70,14 +75,18 @@ app.on('ready', async () => {
await installExtensions();
}
let icon = path.join(__dirname, '..', 'resources', 'icon.icns')
console.log('icon: ', icon)
mainWindow = new BrowserWindow({
show: false,
frame: false
});
frame: false,
nodeIntegration: false,
icon: icon
})
mainWindow.maximize();
mainWindow.loadURL(`file://${__dirname}/app.html`);
mainWindow.loadURL(`file://${__dirname}/app.html`)
// @TODO: Use 'ready-to-show' event
// https://github.com/electron/electron/blob/master/docs/api/browser-window.md#using-ready-to-show-event
@ -106,78 +115,32 @@ app.on('ready', async () => {
// There was an error checking for the LND process
if (err) { throw new Error( err ) }
console.log('results: ', results)
// No LND process was found
if (!results.length) {
// Let the front end know we have started syncing LND
syncing = true
// Run a bash script that checks for the LND folder and generates Node.js compatible certs
console.log('CHECKING/GENERATING CERTS')
exec(`sh ${path.join(__dirname, '..', 'resources', 'scripts', `${plat}_generate_certs.sh`)}`)
// After the certs are generated, it's time to start LND
console.log('STARTING LND')
const lndPath = path.join(__dirname, '..', 'resources', 'bin', plat, plat === 'win32' ? 'lnd.exe' : 'lnd')
neutrino = spawn(lndPath,
[
'--bitcoin.active',
'--bitcoin.testnet',
'--neutrino.active',
'--neutrino.connect=faucet.lightning.community:18333',
'--autopilot.active',
'--debuglevel=debug',
'--no-macaroons',
'--noencryptwallet'
]
)
.on('error', error => console.log(`lnd error: ${error}`))
.on('close', code => console.log(`lnd shutting down ${code}`))
// Listen for when neutrino prints out data
neutrino.stdout.on('data', data => {
// Data stored in variable line, log line to the console
let line = data.toString('utf8')
console.log(line)
// Pass current clock height progress to front end for loading state UX
if (line.includes('Caught up to height')) {
const blockHeight = line.slice(line.indexOf('Caught up to height') + 'Caught up to height'.length).trim()
mainWindow.webContents.send('lndStdout', blockHeight)
}
// When LND is all caught up to the blockchain
if (line.includes('Done catching up block hashes')) {
// Log that LND is caught up to the current block height
console.log('DONE CATCHING UP BLOCK HASHES')
// Call lnd
lnd((lndSubscribe, lndMethods) => {
// Subscribe to bi-directional streams
lndSubscribe(mainWindow)
// Listen for all gRPC restful methods
ipcMain.on('lnd', (event, { msg, data }) => {
lndMethods(event, msg, data)
})
// Let the front end know we have stopped syncing LND
syncing = false
mainWindow.webContents.send('lndSynced')
})
}
})
// Assign path to certs to certPath
switch (os.platform()) {
case 'darwin':
certPath = path.join(homedir, 'Library/Application\ Support/Lnd/tls.cert')
break
case 'linux':
certPath = path.join(homedir, '.lnd/tls.cert')
break
case 'win32':
certPath = path.join(homedir, 'AppData', 'Local', 'Lnd', 'tls.cert')
break
default:
break
}
// Start LND
startLnd()
} else {
// An LND process was found, no need to start our own
console.log('LND ALREADY RUNNING')
// Call lnd
lnd((lndSubscribe, lndMethods) => {
// Subscribe to bi-directional streams
lndSubscribe(mainWindow)
// Listen for all gRPC restful methods
ipcMain.on('lnd', (event, { msg, data }) => {
lndMethods(event, msg, data)
})
})
startGrpc()
}
})
});
@ -191,3 +154,73 @@ app.on('open-url', function (event, url) {
mainWindow.webContents.send('lightningPaymentUri', { payreq })
mainWindow.show()
})
// Starts the LND node
const startLnd = () => {
lndPath = path.join(__dirname, '..', 'resources', 'bin', plat, plat === 'win32' ? 'lnd.exe' : 'lnd')
neutrino = spawn(lndPath,
[
'--bitcoin.active',
'--bitcoin.testnet',
'--neutrino.active',
'--neutrino.connect=faucet.lightning.community:18333',
'--autopilot.active',
'--debuglevel=debug',
'--no-macaroons',
'--noencryptwallet'
]
)
.on('error', error => console.log(`lnd error: ${error}`))
.on('close', code => console.log(`lnd shutting down ${code}`))
// Listen for when neutrino prints out data
neutrino.stdout.on('data', data => {
// Data stored in variable line, log line to the console
let line = data.toString('utf8')
if (process.env.NODE_ENV === 'development') { console.log(line) }
// If the gRPC proxy has started we can start ours
if (line.includes('gRPC proxy started')) {
certInterval = setInterval(() => {
if (fs.existsSync(certPath)) {
clearInterval(certInterval)
console.log('CERT EXISTS, STARTING GRPC')
startGrpc()
}
}, 1000)
}
// Pass current clock height progress to front end for loading state UX
if (line.includes('Caught up to height') || line.includes('Catching up block hashes to height')) {
// const blockHeight = line.slice(line.indexOf('Caught up to height') + 'Caught up to height'.length).trim()
const blockHeight = line.slice(line.indexOf('Caught up to height') + 'Caught up to height'.length).trim()
mainWindow.webContents.send('lndStdout', line)
}
// When LND is all caught up to the blockchain
if (line.includes('Chain backend is fully synced')) {
// Log that LND is caught up to the current block height
console.log('NEUTRINO IS SYNCED')
// Let the front end know we have stopped syncing LND
syncing = false
mainWindow.webContents.send('lndSynced')
}
})
}
// Create and subscribe the grpc object
const startGrpc = () => {
lnd((lndSubscribe, lndMethods) => {
// Subscribe to bi-directional streams
lndSubscribe(mainWindow)
// Listen for all gRPC restful methods
ipcMain.on('lnd', (event, { msg, data }) => {
lndMethods(event, msg, data)
})
})
}

20
app/reducers/lnd.js

@ -32,9 +32,23 @@ export const lndSynced = () => (dispatch) => {
}
// Receive IPC event for LND streaming a line
export const lndStdout = (event, lndBlockHeight) => dispatch => (
dispatch({ type: RECEIVE_LINE, lndBlockHeight: lndBlockHeight.split(' ')[0].split(/(\r\n|\n|\r)/gm)[0] })
)
export const lndStdout = (event, line) => dispatch => {
let height
let trimmed
if (line.includes('Caught up to height')) {
trimmed = line.slice(line.indexOf('Caught up to height') + 'Caught up to height'.length).trim()
height = trimmed.split(' ')[0].split(/(\r\n|\n|\r)/gm)[0]
}
if (line.includes('Catching up block hashes to height')) {
trimmed = line.slice(line.indexOf('Catching up block hashes to height') + 'Catching up block hashes to height'.length).trim()
height = trimmed.match(/[-]{0,1}[\d.]*[\d]+/g)[0]
}
dispatch({ type: RECEIVE_LINE, lndBlockHeight: height })
}
export function getBlockHeight() {
return {

1
app/routes/app/components/App.js

@ -58,7 +58,6 @@ class App extends Component {
}
if (!currentTicker || balance.balanceLoading) { return <LoadingBolt /> }
// return <LoadingBolt />
return (
<div>

8
package.json

@ -36,9 +36,6 @@
"appId": "org.develar.ZapDesktop",
"files": [
"dist/",
"resources/",
"resources/icons/wallet.svg",
"resources/icons/peers.svg",
"node_modules/",
"app.html",
"main.prod.js",
@ -47,6 +44,7 @@
"rpc.proto"
],
"dmg": {
"icon": "./resources/icon.icns",
"contents": [
{
"x": 130,
@ -76,9 +74,7 @@
"output": "release"
},
"extraResources": [
"**/resources/bin/darwin/lnd",
"**/resources/scripts/darwin_generate_certs.sh",
"**/resources/icons/*"
"**/resources/bin/darwin/lnd"
]
},
"repository": {

BIN
resources/icon.icns

Binary file not shown.

BIN
resources/icon.ico

Binary file not shown.

Before

Width:  |  Height:  |  Size: 361 KiB

BIN
resources/icon.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 32 KiB

12
resources/scripts/darwin_generate_certs.sh

@ -1,12 +0,0 @@
# Generate Node.js compatible certs
# If Lnd folder doesn't exist we have to create it
if [ ! -d ~/Library/Application\ Support/Lnd ]; then
mkdir -p ~/Library/Application\ Support/Lnd;
fi
# Generate compatible certs
openssl ecparam -genkey -name prime256v1 -out ~/Library/Application\ Support/Lnd/tls.key
openssl req -new -sha256 -key ~/Library/Application\ Support/Lnd/tls.key -out ~/Library/Application\ Support/Lnd/csr.csr -subj '/CN=localhost/O=lnd'
openssl req -x509 -sha256 -days 3650 -key ~/Library/Application\ Support/Lnd/tls.key -in ~/Library/Application\ Support/Lnd/csr.csr -out ~/Library/Application\ Support/Lnd/tls.cert
rm ~/Library/Application\ Support/Lnd/csr.csr

11
resources/scripts/linux_generate_certs.sh

@ -1,11 +0,0 @@
# Generate Node.js compatible certs
# If Lnd folder doesn't exist we have to create it
if [ ! -d ~/Library/Application\ Support/Lnd ]; then
mkdir -p ~/.lnd;
fi
# Generate compatible certs
openssl ecparam -genkey -name prime256v1 -out ~/Library/Application\ Support/Lnd/tls.key
openssl req -new -sha256 -key ~/Library/Application\ Support/Lnd/tls.key -out ~/Library/Application\ Support/Lnd/csr.csr -subj '/CN=localhost/O=lnd'
openssl req -x509 -sha256 -days 3650 -key ~/Library/Application\ Support/Lnd/tls.key -in ~/Library/Application\ Support/Lnd/csr.csr -out ~/Library/Application\ Support/Lnd/tls.cert
rm ~/Library/Application\ Support/Lnd/csr.csr

11
resources/scripts/win32_generate_certs.sh

@ -1,11 +0,0 @@
# Generate Node.js compatible certs
# If Lnd folder doesn't exist we have to create it
if [ ! -d ~/Library/Application\ Support/Lnd ]; then
mkdir -p ~/AppData/Local/Lnd;
fi
# Generate compatible certs
openssl ecparam -genkey -name prime256v1 -out ~/Library/Application\ Support/Lnd/tls.key
openssl req -new -sha256 -key ~/Library/Application\ Support/Lnd/tls.key -out ~/Library/Application\ Support/Lnd/csr.csr -subj '/CN=localhost/O=lnd'
openssl req -x509 -sha256 -days 3650 -key ~/Library/Application\ Support/Lnd/tls.key -in ~/Library/Application\ Support/Lnd/csr.csr -out ~/Library/Application\ Support/Lnd/tls.cert
rm ~/Library/Application\ Support/Lnd/csr.csr
Loading…
Cancel
Save