Add parity_defaultAccount RPC (with subscription) (#4383)
* Add parity_defaultAccount RPC (with subscription) * Add jsonrpc interface
This commit is contained in:
parent
ed09a76c91
commit
04fb2afba1
@ -81,6 +81,12 @@ export default class Parity {
|
|||||||
.execute('parity_decryptMessage', inAddress(address), inHex(data));
|
.execute('parity_decryptMessage', inAddress(address), inHex(data));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
defaultAccount () {
|
||||||
|
return this._transport
|
||||||
|
.execute('parity_defaultAccount')
|
||||||
|
.then(outAddress);
|
||||||
|
}
|
||||||
|
|
||||||
defaultExtraData () {
|
defaultExtraData () {
|
||||||
return this._transport
|
return this._transport
|
||||||
.execute('parity_defaultExtraData');
|
.execute('parity_defaultExtraData');
|
||||||
@ -307,11 +313,6 @@ export default class Parity {
|
|||||||
.execute('parity_postTransaction', inOptions(options));
|
.execute('parity_postTransaction', inOptions(options));
|
||||||
}
|
}
|
||||||
|
|
||||||
postSign (from, message) {
|
|
||||||
return this._transport
|
|
||||||
.execute('parity_postSign', from, message);
|
|
||||||
}
|
|
||||||
|
|
||||||
registryAddress () {
|
registryAddress () {
|
||||||
return this._transport
|
return this._transport
|
||||||
.execute('parity_registryAddress')
|
.execute('parity_registryAddress')
|
||||||
|
@ -26,6 +26,7 @@ const events = {
|
|||||||
'eth_blockNumber': { module: 'eth' },
|
'eth_blockNumber': { module: 'eth' },
|
||||||
'parity_accountsInfo': { module: 'personal' },
|
'parity_accountsInfo': { module: 'personal' },
|
||||||
'parity_allAccountsInfo': { module: 'personal' },
|
'parity_allAccountsInfo': { module: 'personal' },
|
||||||
|
'parity_defaultAccount': { module: 'personal' },
|
||||||
'eth_accounts': { module: 'personal' },
|
'eth_accounts': { module: 'personal' },
|
||||||
'signer_requestsToConfirm': { module: 'signer' }
|
'signer_requestsToConfirm': { module: 'signer' }
|
||||||
};
|
};
|
||||||
|
@ -30,12 +30,21 @@ export default class Personal {
|
|||||||
this._started = true;
|
this._started = true;
|
||||||
|
|
||||||
return Promise.all([
|
return Promise.all([
|
||||||
|
this._defaultAccount(),
|
||||||
this._listAccounts(),
|
this._listAccounts(),
|
||||||
this._accountsInfo(),
|
this._accountsInfo(),
|
||||||
this._loggingSubscribe()
|
this._loggingSubscribe()
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_defaultAccount = () => {
|
||||||
|
return this._api.parity
|
||||||
|
.defaultAccount()
|
||||||
|
.then((defaultAccount) => {
|
||||||
|
this._updateSubscriptions('parity_defaultAccount', null, defaultAccount);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
_listAccounts = () => {
|
_listAccounts = () => {
|
||||||
return this._api.eth
|
return this._api.eth
|
||||||
.accounts()
|
.accounts()
|
||||||
@ -77,6 +86,11 @@ export default class Personal {
|
|||||||
case 'parity_setAccountMeta':
|
case 'parity_setAccountMeta':
|
||||||
this._accountsInfo();
|
this._accountsInfo();
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
case 'parity_setDappsAddresses':
|
||||||
|
case 'parity_setNewDappsWhitelist':
|
||||||
|
this._defaultAccount();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -18,18 +18,20 @@ import sinon from 'sinon';
|
|||||||
|
|
||||||
import Personal from './personal';
|
import Personal from './personal';
|
||||||
|
|
||||||
|
const TEST_DEFAULT = '0xfa64203C044691aA57251aF95f4b48d85eC00Dd5';
|
||||||
const TEST_INFO = {
|
const TEST_INFO = {
|
||||||
'0xfa64203C044691aA57251aF95f4b48d85eC00Dd5': {
|
[TEST_DEFAULT]: {
|
||||||
name: 'test'
|
name: 'test'
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const TEST_LIST = ['0xfa64203C044691aA57251aF95f4b48d85eC00Dd5'];
|
const TEST_LIST = [TEST_DEFAULT];
|
||||||
|
|
||||||
function stubApi (accounts, info) {
|
function stubApi (accounts, info) {
|
||||||
const _calls = {
|
const _calls = {
|
||||||
accountsInfo: [],
|
accountsInfo: [],
|
||||||
allAccountsInfo: [],
|
allAccountsInfo: [],
|
||||||
listAccounts: []
|
listAccounts: [],
|
||||||
|
defaultAccount: []
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@ -46,6 +48,12 @@ function stubApi (accounts, info) {
|
|||||||
|
|
||||||
_calls.allAccountsInfo.push(stub);
|
_calls.allAccountsInfo.push(stub);
|
||||||
return stub;
|
return stub;
|
||||||
|
},
|
||||||
|
defaultAccount: () => {
|
||||||
|
const stub = sinon.stub().resolves(Object.keys(info || TEST_INFO)[0])();
|
||||||
|
|
||||||
|
_calls.defaultAccount.push(stub);
|
||||||
|
return stub;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
eth: {
|
eth: {
|
||||||
@ -107,9 +115,10 @@ describe('api/subscriptions/personal', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('updates subscribers', () => {
|
it('updates subscribers', () => {
|
||||||
expect(cb.firstCall).to.have.been.calledWith('eth_accounts', null, TEST_LIST);
|
expect(cb).to.have.been.calledWith('parity_defaultAccount', null, TEST_DEFAULT);
|
||||||
expect(cb.secondCall).to.have.been.calledWith('parity_accountsInfo', null, TEST_INFO);
|
expect(cb).to.have.been.calledWith('eth_accounts', null, TEST_LIST);
|
||||||
expect(cb.thirdCall).to.have.been.calledWith('parity_allAccountsInfo', null, TEST_INFO);
|
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;
|
expect(personal.isStarted).to.be.true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('calls parity_defaultAccount', () => {
|
||||||
|
expect(api._calls.defaultAccount.length).to.be.ok;
|
||||||
|
});
|
||||||
|
|
||||||
it('calls personal_accountsInfo', () => {
|
it('calls personal_accountsInfo', () => {
|
||||||
expect(api._calls.accountsInfo.length).to.be.ok;
|
expect(api._calls.accountsInfo.length).to.be.ok;
|
||||||
});
|
});
|
||||||
|
@ -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: {
|
defaultExtraData: {
|
||||||
section: SECTION_MINING,
|
section: SECTION_MINING,
|
||||||
desc: 'Returns the default extra data',
|
desc: 'Returns the default extra data',
|
||||||
|
Loading…
Reference in New Issue
Block a user