Skip to content

Commit

Permalink
Merge 452fc7b into cd5e8b8
Browse files Browse the repository at this point in the history
  • Loading branch information
zaSmilingIdiot committed Mar 14, 2019
2 parents cd5e8b8 + 452fc7b commit 8e8891b
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 36 deletions.
64 changes: 35 additions & 29 deletions modules/daemon/daemonConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ if (isEmptyObject(_options)) {
}

const conFilePath = path.join( cookie.getParticlPath(_options), 'particl.conf');
const IPC_CHANNEL = 'rpc-configuration';
const IPC_CHANNEL_PUB = 'rpc-configuration';
const IPC_CHANNEL_LISTEN = 'request-configuration';

const SAFE_KEYS = ['addressindex'];

let STORED_CONFIGURATION = {};
Expand Down Expand Up @@ -258,36 +260,11 @@ const getConfiguration = () => {
}


const initializeIpcListener = (mainWindow) => {
if (mainWindowRef === null) {
mainWindowRef = mainWindow;
}
removeIpcListener();

rxIpc.registerListener(IPC_CHANNEL, () => {
let settings = getConfiguration();
return Observable.create(observer => {
observer.next(settings);
observer.complete();
});
});
}


const removeIpcListener = () => {
rxIpc.removeListeners(IPC_CHANNEL);
}


const emitConfiguration = () => {
let settings = getConfiguration();

if (!settings.auth) {
setTimeout(emitConfiguration, 1000);
return;
}
try {
rxIpc.runCommand(IPC_CHANNEL, mainWindowRef.webContents, settings)
rxIpc.runCommand(IPC_CHANNEL_PUB, mainWindowRef.webContents, settings)
.subscribe(
(returnData) => {
// no return data
Expand All @@ -305,9 +282,38 @@ const emitConfiguration = () => {
}


const destroyIpcChannels = () => {
rxIpc.removeListeners(IPC_CHANNEL_PUB);
rxIpc.removeListeners(IPC_CHANNEL_LISTEN);
}


const initializeIpcChannels = (mainWindow) => {
if (mainWindowRef === null) {
mainWindowRef = mainWindow;
}
destroyIpcChannels();

rxIpc.registerListener(IPC_CHANNEL_PUB, () => {
let settings = getConfiguration();
return Observable.create(observer => {
observer.next(settings);
observer.complete();
});
});

rxIpc.registerListener(IPC_CHANNEL_LISTEN, () => {
emitConfiguration();
return Observable.create(observer => {
observer.complete(true);
});
});
}


exports.getConfiguration = getConfiguration;
exports.init = initializeIpcListener;
exports.destroy = removeIpcListener;
exports.init = initializeIpcChannels;
exports.destroy = destroyIpcChannels;
exports.getSettings = getSettings;
exports.saveSettings = saveSettings;
exports.send = emitConfiguration;
1 change: 1 addition & 0 deletions preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ window.ipc = new SafeIpcRenderer([
'zmq',
'rpc-channel',
'rpc-configuration',
'request-configuration',

'rx-ipc-check-reply',
'rx-ipc-check-listener'
Expand Down
18 changes: 16 additions & 2 deletions src/app/core/rpc/rpc.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,11 @@ export class RpcService implements OnDestroy {
private _ipc: IpcService
) {
this.isElectron = false; // window.electron
if (environment.isTesting) {
if (environment.isTesting || !window.electron) {
this.isInitialized = true;
} else {
this._ipc.registerListener(this.DAEMON_CHANNEL, this.daemonListener.bind(this));
this.requestConfiguration();
}
}

Expand Down Expand Up @@ -125,7 +126,9 @@ export class RpcService implements OnDestroy {

private daemonListener(config: any): Observable<any> {
return Observable.create(observer => {
if (config.auth && (config.auth !== this.authorization)) {
const isValid = config.auth && (config.auth !== this.authorization);
this.log.d(`Recieved RPC configuration: details are valid: ${isValid}`);
if (isValid) {
this.hostname = config.rpcbind || 'localhost';
this.port = config.port ? config.port : this.port;
this.authorization = config.auth ? config.auth : this.authorization;
Expand All @@ -137,4 +140,15 @@ export class RpcService implements OnDestroy {
});
}

private requestConfiguration(): void {
setTimeout(() => {
this.log.d('Checking if RPC configuration is valid');
if (!this.isInitialized) {
this.log.d('Requesting valid RPC configuration');
this._ipc.runCommand('request-configuration', null, null);
this.requestConfiguration();
}
}, 5000);
}

}
13 changes: 8 additions & 5 deletions src/app/wallet/wallet/shared/transaction.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,14 @@ export class TransactionService implements OnDestroy {
Object.keys(this.filters).map(filter => options[filter] = this.filters[filter]);

this.rpc.call('filtertransactions', [options])
.subscribe((txResponse: Array<Object>) => {
this.log.d(`countTransactions, number of transactions after filter: ${txResponse.length}`);
this.txCount = txResponse.length;
return;
});
.subscribe(
(txResponse: Array<Object>) => {
this.log.d(`countTransactions, number of transactions after filter: ${txResponse.length}`);
this.txCount = txResponse.length;
return;
},
(err) => this.log.d('filtertransactions call failed!')
);
}

// TODO: remove shitty hack
Expand Down

0 comments on commit 8e8891b

Please sign in to comment.