+ initial import
This commit is contained in:
63
modules/database.js
Normal file
63
modules/database.js
Normal file
@@ -0,0 +1,63 @@
|
||||
const {app, ipcMain} = require('electron');
|
||||
const storage = require('electron-storage');
|
||||
const datastore = require('nedb');
|
||||
const path = require('path');
|
||||
|
||||
const dbPath = path.join(app.getPath('userData'), 'storage.db');
|
||||
const db = new datastore({ filename: dbPath });
|
||||
db.loadDatabase(function (err) {
|
||||
// Now commands will be executed
|
||||
});
|
||||
|
||||
db.ensureIndex({ fieldName: 'block' }, function (err) {
|
||||
// If there was an error, err is not null
|
||||
});
|
||||
|
||||
ipcMain.on('storeTransaction', (event, arg) => {
|
||||
db.find({ block: arg.block, fromaddr: arg.fromaddr, toaddr: arg.toaddr }, function (err, docs) {
|
||||
if (docs.length == 0) {
|
||||
db.insert(arg, function (err, newDoc) {
|
||||
// do nothing
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
ipcMain.on('getTransactions', (event, arg) => {
|
||||
db.find({}).sort({ block: 1 }).exec(function (err, docs) {
|
||||
ResultData = [];
|
||||
|
||||
for (i = 0; i < 500; i++) {
|
||||
ResultData.push([
|
||||
docs[i].block,
|
||||
docs[i].timestamp,
|
||||
docs[i].fromaddr,
|
||||
docs[i].toaddr,
|
||||
docs[i].value
|
||||
]);
|
||||
}
|
||||
|
||||
// return the transactions data
|
||||
event.returnValue = ResultData;
|
||||
});
|
||||
});
|
||||
|
||||
ipcMain.on('getJSONFile', (event, arg) => {
|
||||
storage.get(arg, (err, data) => {
|
||||
if (err) {
|
||||
event.returnValue = null;
|
||||
} else {
|
||||
event.returnValue = data;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
ipcMain.on('setJSONFile', (event, arg) => {
|
||||
storage.set(arg.file, arg.data, (err) => {
|
||||
if (err) {
|
||||
event.returnValue = { success: false, error: err };
|
||||
} else {
|
||||
event.returnValue = { success: true, error: null };
|
||||
}
|
||||
});
|
||||
});
|
||||
35
modules/geth.js
Normal file
35
modules/geth.js
Normal file
@@ -0,0 +1,35 @@
|
||||
const {app, dialog, BrowserWindow} = require('electron')
|
||||
const child_process = require('child_process');
|
||||
const path = require('path');
|
||||
|
||||
class Geth {
|
||||
constructor() {
|
||||
this.gethProcess = null;
|
||||
}
|
||||
|
||||
startGeth() {
|
||||
// get the path of get and execute the child process
|
||||
try {
|
||||
const gethPath = path.join(app.getPath('userData'), 'geth');
|
||||
this.gethProcess = child_process.spawn(gethPath, ['--ws', '--wsorigins', '*', '--wsaddr', '127.0.0.1', '--wsport', '8546', '--wsapi', 'admin,db,eth,net,miner,personal,web3']);
|
||||
this.gethProcess.on('error', function(err) {
|
||||
dialog.showErrorBox("Error starting application", "Geth failed to start!");
|
||||
});
|
||||
this.gethProcess.stderr.on('data', function(data) {
|
||||
console.log(data.toString());
|
||||
});
|
||||
this.gethProcess.stdout.on('data', function(data) {
|
||||
console.log(data.toString());
|
||||
});
|
||||
} catch (e) {
|
||||
dialog.showErrorBox("Error starting application", e);
|
||||
app.quit();
|
||||
}
|
||||
}
|
||||
|
||||
stopGeth() {
|
||||
this.gethProcess.kill('SIGINT');
|
||||
}
|
||||
}
|
||||
|
||||
EthoGeth = new Geth();
|
||||
Reference in New Issue
Block a user