Skip to content

Commit

Permalink
Merge pull request #13 from sapio-lang/rpc-connection
Browse files Browse the repository at this point in the history
Rename App; Add config file for connection
  • Loading branch information
JeremyRubin committed Dec 3, 2020
2 parents b6a1564 + 1f08b2d commit 992ad91
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 9 deletions.
44 changes: 36 additions & 8 deletions desktop/main.js
@@ -1,10 +1,46 @@
const { app, BrowserWindow, ipcMain } = require('electron');
const path = require('path');
const url = require('url');
const fs = require('fs');

let mainWindow;
const Client = require('bitcoin-core');

let client;
function load_settings() {
const udata = app.getPath('userData');
const config = path.join(udata, 'config.json');
if (!fs.existsSync(udata)) {
let dir = fs.mkdirSync(udata);
}

if (!fs.existsSync(config)) {
let f = fs.openSync(config, 'wx+');
let settings = JSON.stringify({
clients: [
{
nickname: 'default',
network: 'regtest',
username: 'btcusr',
password:
'261299cf4f162e6d8e870760ee88b29537617c6aadc45f5ffd249b2309ca47fd',
},
],
});
fs.writeSync(f, settings);
}
let data = fs.readFileSync(config);
const settings = JSON.parse(data);
const default_client = settings['clients'][0];
client = new Client({
network: default_client['network'],
username: default_client['rpcuser'],
password: default_client['password'],
});
}

function createWindow() {
load_settings();
const startUrl =
process.env.ELECTRON_START_URL ||
url.format({
Expand Down Expand Up @@ -45,14 +81,6 @@ app.on('activate', function () {
}
});

const Client = require('bitcoin-core');

const client = new Client({
network: 'regtest',
username: 'btcusr',
password:
'261299cf4f162e6d8e870760ee88b29537617c6aadc45f5ffd249b2309ca47fd',
});
ipcMain.handle('bitcoin-command', async (event, arg) => {
let result = await client.command(arg);
return result;
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,5 +1,5 @@
{
"name": "vaults",
"name": "org.judica.os",
"version": "0.1.0",
"private": true,
"dependencies": {
Expand Down

0 comments on commit 992ad91

Please sign in to comment.