Add parity_defaultAccount RPC (with subscription) (#4383)

* Add parity_defaultAccount RPC (with subscription)

* Add jsonrpc interface
This commit is contained in:
Jaco Greeff 2017-02-01 14:52:15 +01:00 committed by GitHub
parent ed09a76c91
commit 04fb2afba1
5 changed files with 51 additions and 11 deletions

View File

@ -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');
@ -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')

View File

@ -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' }
};

View File

@ -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()
@ -77,6 +86,11 @@ export default class Personal {
case 'parity_setAccountMeta':
this._accountsInfo();
return;
case 'parity_setDappsAddresses':
case 'parity_setNewDappsWhitelist':
this._defaultAccount();
return;
}
});
}

View File

@ -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 {
@ -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: {
@ -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);
});
});
@ -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;
});

View File

@ -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',