Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Merge pull request #2565 from ethcore/jg-polling
Browse files Browse the repository at this point in the history
Ensure polling is only done when connected
  • Loading branch information
jacogr authored Oct 11, 2016
2 parents ea92124 + 2aa4066 commit 5cbf5d9
Show file tree
Hide file tree
Showing 45 changed files with 174 additions and 1,239 deletions.
18 changes: 18 additions & 0 deletions js/src/api/format/output.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,24 @@ export function outReceipt (receipt) {
return receipt;
}

export function outSignerRequest (request) {
if (request) {
Object.keys(request).forEach((key) => {
switch (key) {
case 'id':
request[key] = outNumber(request[key]);
break;

case 'payload':
request[key].transaction = outTransaction(request[key].transaction);
break;
}
});
}

return request;
}

export function outTransaction (tx) {
if (tx) {
Object.keys(tx).forEach((key) => {
Expand Down
20 changes: 18 additions & 2 deletions js/src/api/rpc/personal/personal.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.

import { inAddress, inNumber10, inOptions } from '../../format/input';
import { outAccountInfo, outAddress } from '../../format/output';
import { inAddress, inNumber10, inNumber16, inOptions } from '../../format/input';
import { outAccountInfo, outAddress, outSignerRequest } from '../../format/output';

export default class Personal {
constructor (transport) {
Expand All @@ -28,6 +28,11 @@ export default class Personal {
.then(outAccountInfo);
}

confirmRequest (requestId) {
return this._transport
.execute('personal_confirmRequest', inNumber16(requestId));
}

generateAuthorizationToken () {
return this._transport
.execute('personal_generateAuthorizationToken');
Expand Down Expand Up @@ -69,6 +74,17 @@ export default class Personal {
.then(outAddress);
}

rejectRequest (requestId) {
return this._transport
.execute('personal_rejectRequest', inNumber16(requestId));
}

requestsToConfirm () {
return this._transport
.execute('personal_requestsToConfirm')
.then((requests) => (requests || []).map(outSignerRequest));
}

setAccountName (address, name) {
return this._transport
.execute('personal_setAccountName', inAddress(address), name);
Expand Down
9 changes: 8 additions & 1 deletion js/src/api/subscriptions/eth.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,14 @@ export default class Eth {
}

_blockNumber = () => {
const nextTimeout = () => setTimeout(() => this._blockNumber(), 1000);
const nextTimeout = (timeout = 1000) => {
setTimeout(() => this._blockNumber(), timeout);
};

if (!this._api.transport.isConnected()) {
nextTimeout(500);
return;
}

return this._api.eth
.blockNumber()
Expand Down
2 changes: 2 additions & 0 deletions js/src/api/subscriptions/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { isError } from '../util/types';
import Eth from './eth';
import Logging from './logging';
import Personal from './personal';
import Signer from './signer';

const events = [
'logging',
Expand Down Expand Up @@ -48,6 +49,7 @@ export default class Manager {
this._logging = new Logging(this._updateSubscriptions);
this._eth = new Eth(this._updateSubscriptions, api);
this._personal = new Personal(this._updateSubscriptions, api, this);
this._signer = new Signer(this._updateSubscriptions, api, this);
}

_validateType (_subscriptionName) {
Expand Down
61 changes: 61 additions & 0 deletions js/src/api/subscriptions/signer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Copyright 2015, 2016 Ethcore (UK) Ltd.
// This file is part of Parity.

// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.

export default class Signer {
constructor (updateSubscriptions, api, subscriber) {
this._subscriber = subscriber;
this._api = api;
this._updateSubscriptions = updateSubscriptions;
this._started = false;
}

get isStarted () {
return this._started;
}

start () {
this._started = true;

return Promise.all([
this._listRequests(),
this._loggingSubscribe()
]);
}

_listRequests = () => {
return this._api.personal
.requestsToConfirm()
.then((requests) => {
this._updateSubscriptions('personal_requestsToConfirm', null, requests);
});
}

_loggingSubscribe () {
return this._subscriber.subscribe('logging', (error, data) => {
if (error || !data) {
return;
}

switch (data.method) {
case 'eth_postTransaction':
case 'eth_sendTranasction':
case 'eth_sendRawTransaction':
this._listRequests();
return;
}
});
}
}
3 changes: 1 addition & 2 deletions js/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import { Accounts, Account, Addresses, Address, Application, Contract, Contracts
// TODO: This is VERY messy, just dumped here to get the Signer going
import { Web3Provider as SignerWeb3Provider, web3Extension as statusWeb3Extension } from './views/Signer/components';
import { WebSocketsProvider, Ws } from './views/Signer/utils';
import { SignerDataProvider, WsDataProvider } from './views/Signer/providers';
import { WsDataProvider } from './views/Signer/providers';

import './environment';

Expand Down Expand Up @@ -71,7 +71,6 @@ store.dispatch({ type: 'initAll', api });

// signer
new WsDataProvider(store, ws); // eslint-disable-line no-new
new SignerDataProvider(store, ws); // eslint-disable-line no-new

const routerHistory = useRouterHistory(createHashHistory)({});

Expand Down
46 changes: 46 additions & 0 deletions js/src/jsonrpc/interfaces/personal.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,52 @@ export default {
}
},

generateAuthorizationToken: {
desc: 'Generates a new authorization token',
params: [],
returns: {
type: String,
desc: 'The new authorization token'
}
},

requestsToConfirm: {
desc: 'Returns a list of the transactions requiring authorization',
params: [],
returns: {
type: Array,
desc: 'A list of the outstanding transactions'
}
},

confirmRequest: {
desc: 'Confirm a request in the signer queue',
params: [
{
type: Quantity,
desc: 'The request id'
}
],
returns: {
type: Boolean,
desc: 'The status of the confirmation'
}
},

rejectRequest: {
desc: 'Rejects a request in the signer queue',
params: [
{
type: Quantity,
desc: 'The request id'
}
],
returns: {
type: Boolean,
desc: 'The status of the rejection'
}
},

listAccounts: {
desc: 'Returns a list of addresses owned by client.',
params: [],
Expand Down
5 changes: 4 additions & 1 deletion js/src/redux/providers/status.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,15 @@ export default class Status {
}

_pollStatus = () => {
const nextTimeout = (timeout = 1000) => setTimeout(this._pollStatus, timeout);
const { secureToken, isConnected, isConnecting, needsToken } = this._api;
const nextTimeout = (timeout = 1000) => {
setTimeout(this._pollStatus, timeout);
};

this._store.dispatch(statusCollection({ isConnected, isConnecting, needsToken, secureToken }));
if (!isConnected) {
nextTimeout(250);
return;
}

Promise
Expand Down
6 changes: 1 addition & 5 deletions js/src/redux/reducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ import { errorReducer } from '../ui/Errors';
import { settingsReducer } from '../views/Settings';
import { tooltipReducer } from '../ui/Tooltips';

import {
signer as signerReducer,
requests as signerRequestsReducer
} from '../views/Signer/reducers';
import { requests as signerRequestsReducer } from '../views/Signer/reducers';

export default function () {
return combineReducers({
Expand All @@ -40,7 +37,6 @@ export default function () {
nodeStatus: nodeStatusReducer,
personal: personalReducer,

signer: signerReducer,
signerRequests: signerRequestsReducer
});
}

This file was deleted.

36 changes: 0 additions & 36 deletions js/src/views/Signer/containers/--remove-LoadingPage/LoadingPage.js

This file was deleted.

17 changes: 0 additions & 17 deletions js/src/views/Signer/containers/--remove-LoadingPage/index.js

This file was deleted.

Loading

0 comments on commit 5cbf5d9

Please sign in to comment.