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

Commit

Permalink
Add parity_defaultAccount RPC (with subscription) (#4383)
Browse files Browse the repository at this point in the history
* Add parity_defaultAccount RPC (with subscription)

* Add jsonrpc interface
  • Loading branch information
jacogr authored Feb 1, 2017
1 parent ed09a76 commit 04fb2af
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 11 deletions.
11 changes: 6 additions & 5 deletions js/src/api/rpc/parity/parity.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ export default class Parity {
.execute('parity_decryptMessage', inAddress(address), inHex(data));
}

defaultAccount () {
return this._transport
.execute('parity_defaultAccount')
.then(outAddress);
}

defaultExtraData () {
return this._transport
.execute('parity_defaultExtraData');
Expand Down Expand Up @@ -307,11 +313,6 @@ export default class Parity {
.execute('parity_postTransaction', inOptions(options));
}

postSign (from, message) {
return this._transport
.execute('parity_postSign', from, message);
}

registryAddress () {
return this._transport
.execute('parity_registryAddress')
Expand Down
1 change: 1 addition & 0 deletions js/src/api/subscriptions/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const events = {
'eth_blockNumber': { module: 'eth' },
'parity_accountsInfo': { module: 'personal' },
'parity_allAccountsInfo': { module: 'personal' },
'parity_defaultAccount': { module: 'personal' },
'eth_accounts': { module: 'personal' },
'signer_requestsToConfirm': { module: 'signer' }
};
Expand Down
14 changes: 14 additions & 0 deletions js/src/api/subscriptions/personal.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,21 @@ export default class Personal {
this._started = true;

return Promise.all([
this._defaultAccount(),
this._listAccounts(),
this._accountsInfo(),
this._loggingSubscribe()
]);
}

_defaultAccount = () => {
return this._api.parity
.defaultAccount()
.then((defaultAccount) => {
this._updateSubscriptions('parity_defaultAccount', null, defaultAccount);
});
}

_listAccounts = () => {
return this._api.eth
.accounts()
Expand Down Expand Up @@ -77,6 +86,11 @@ export default class Personal {
case 'parity_setAccountMeta':
this._accountsInfo();
return;

case 'parity_setDappsAddresses':
case 'parity_setNewDappsWhitelist':
this._defaultAccount();
return;
}
});
}
Expand Down
25 changes: 19 additions & 6 deletions js/src/api/subscriptions/personal.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,20 @@ import sinon from 'sinon';

import Personal from './personal';

const TEST_DEFAULT = '0xfa64203C044691aA57251aF95f4b48d85eC00Dd5';
const TEST_INFO = {
'0xfa64203C044691aA57251aF95f4b48d85eC00Dd5': {
[TEST_DEFAULT]: {
name: 'test'
}
};
const TEST_LIST = ['0xfa64203C044691aA57251aF95f4b48d85eC00Dd5'];
const TEST_LIST = [TEST_DEFAULT];

function stubApi (accounts, info) {
const _calls = {
accountsInfo: [],
allAccountsInfo: [],
listAccounts: []
listAccounts: [],
defaultAccount: []
};

return {
Expand All @@ -46,6 +48,12 @@ function stubApi (accounts, info) {

_calls.allAccountsInfo.push(stub);
return stub;
},
defaultAccount: () => {
const stub = sinon.stub().resolves(Object.keys(info || TEST_INFO)[0])();

_calls.defaultAccount.push(stub);
return stub;
}
},
eth: {
Expand Down Expand Up @@ -107,9 +115,10 @@ describe('api/subscriptions/personal', () => {
});

it('updates subscribers', () => {
expect(cb.firstCall).to.have.been.calledWith('eth_accounts', null, TEST_LIST);
expect(cb.secondCall).to.have.been.calledWith('parity_accountsInfo', null, TEST_INFO);
expect(cb.thirdCall).to.have.been.calledWith('parity_allAccountsInfo', null, TEST_INFO);
expect(cb).to.have.been.calledWith('parity_defaultAccount', null, TEST_DEFAULT);
expect(cb).to.have.been.calledWith('eth_accounts', null, TEST_LIST);
expect(cb).to.have.been.calledWith('parity_accountsInfo', null, TEST_INFO);
expect(cb).to.have.been.calledWith('parity_allAccountsInfo', null, TEST_INFO);
});
});

Expand All @@ -124,6 +133,10 @@ describe('api/subscriptions/personal', () => {
expect(personal.isStarted).to.be.true;
});

it('calls parity_defaultAccount', () => {
expect(api._calls.defaultAccount.length).to.be.ok;
});

it('calls personal_accountsInfo', () => {
expect(api._calls.accountsInfo.length).to.be.ok;
});
Expand Down
11 changes: 11 additions & 0 deletions js/src/jsonrpc/interfaces/parity.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,17 @@ export default {
}
},

defaultAccount: {
section: SECTION_ACCOUNTS,
desc: 'Returns the defaultAccount that is to be used with transactions',
params: [],
returns: {
type: Address,
desc: 'The account address',
example: '0x63Cf90D3f0410092FC0fca41846f596223979195'
}
},

defaultExtraData: {
section: SECTION_MINING,
desc: 'Returns the default extra data',
Expand Down

0 comments on commit 04fb2af

Please sign in to comment.