diff --git a/js/src/api/rpc/parity/parity.js b/js/src/api/rpc/parity/parity.js index 174ad3fbf94..160e7513a67 100644 --- a/js/src/api/rpc/parity/parity.js +++ b/js/src/api/rpc/parity/parity.js @@ -1,4 +1,4 @@ -// Copyright 2015, 2016 Parity Technologies (UK) Ltd. +// Copyright 2015-2017 Parity Technologies (UK) Ltd. // This file is part of Parity. // Parity is free software: you can redistribute it and/or modify @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . -import { inAddress, inAddresses, inData, inHex, inNumber16, inOptions } from '../../format/input'; +import { inAddress, inAddresses, inData, inHex, inNumber16, inOptions, inBlockNumber } from '../../format/input'; import { outAccountInfo, outAddress, outAddresses, outChainStatus, outHistogram, outNumber, outPeers, outTransaction } from '../../format/output'; export default class Parity { @@ -76,6 +76,17 @@ export default class Parity { .execute('parity_dappsInterface'); } + decryptMessage (address, data) { + return this._transport + .execute('parity_decryptMessage', inAddress(address), inHex(data)); + } + + defaultAccount () { + return this._transport + .execute('parity_defaultAccount') + .then(outAddress); + } + defaultExtraData () { return this._transport .execute('parity_defaultExtraData'); @@ -101,6 +112,11 @@ export default class Parity { .execute('parity_enode'); } + encryptMessage (pubkey, data) { + return this._transport + .execute('parity_encryptMessage', inHex(pubkey), inHex(data)); + } + executeUpgrade () { return this._transport .execute('parity_executeUpgrade'); @@ -111,6 +127,17 @@ export default class Parity { .execute('parity_extraData'); } + futureTransactions () { + return this._transport + .execute('parity_futureTransactions'); + } + + gasCeilTarget () { + return this._transport + .execute('parity_gasCeilTarget') + .then(outNumber); + } + gasFloorTarget () { return this._transport .execute('parity_gasFloorTarget') @@ -156,11 +183,22 @@ export default class Parity { .execute('parity_killAccount', inAddress(account), password); } + listAccounts (count, offset = null, blockNumber = 'latest') { + return this._transport + .execute('parity_listAccounts', count, inAddress(offset), inBlockNumber(blockNumber)) + .then((accounts) => (accounts || []).map(outAddress)); + } + listRecentDapps () { return this._transport .execute('parity_listRecentDapps'); } + listStorageKeys (address, count, hash = null, blockNumber = 'latest') { + return this._transport + .execute('parity_listStorageKeys', inAddress(address), count, inHex(hash), inBlockNumber(blockNumber)); + } + removeAddress (address) { return this._transport .execute('parity_removeAddress', inAddress(address)); @@ -265,6 +303,11 @@ export default class Parity { .then(outAddress); } + postSign (address, hash) { + return this._transport + .execute('parity_postSign', inAddress(address), inHex(hash)); + } + postTransaction (options) { return this._transport .execute('parity_postTransaction', inOptions(options)); @@ -311,16 +354,31 @@ export default class Parity { .execute('parity_setDappsAddresses', dappId, inAddresses(addresses)); } + setEngineSigner (address, password) { + return this._transport + .execute('parity_setEngineSigner', inAddress(address), password); + } + setExtraData (data) { return this._transport .execute('parity_setExtraData', inData(data)); } + setGasCeilTarget (quantity) { + return this._transport + .execute('parity_setGasCeilTarget', inNumber16(quantity)); + } + setGasFloorTarget (quantity) { return this._transport .execute('parity_setGasFloorTarget', inNumber16(quantity)); } + setMaxTransactionGas (quantity) { + return this._transport + .execute('parity_setMaxTransactionGas', inNumber16(quantity)); + } + setMinGasPrice (quantity) { return this._transport .execute('parity_setMinGasPrice', inNumber16(quantity)); diff --git a/js/src/api/subscriptions/manager.js b/js/src/api/subscriptions/manager.js index 7a7a61bfa6d..b5cf9d70450 100644 --- a/js/src/api/subscriptions/manager.js +++ b/js/src/api/subscriptions/manager.js @@ -25,6 +25,7 @@ const events = { 'logging': { module: 'logging' }, 'eth_blockNumber': { module: 'eth' }, 'parity_allAccountsInfo': { module: 'personal' }, + 'parity_defaultAccount': { module: 'personal' }, 'eth_accounts': { module: 'personal' }, 'signer_requestsToConfirm': { module: 'signer' } }; diff --git a/js/src/api/subscriptions/personal.js b/js/src/api/subscriptions/personal.js index 5e328042477..06766286f81 100644 --- a/js/src/api/subscriptions/personal.js +++ b/js/src/api/subscriptions/personal.js @@ -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() @@ -73,6 +82,11 @@ export default class Personal { case 'parity_setAccountMeta': this._accountsInfo(); return; + + case 'parity_setDappsAddresses': + case 'parity_setNewDappsWhitelist': + this._defaultAccount(); + return; } }); } diff --git a/js/src/api/subscriptions/personal.spec.js b/js/src/api/subscriptions/personal.spec.js index 2359192f09e..3b8449efcce 100644 --- a/js/src/api/subscriptions/personal.spec.js +++ b/js/src/api/subscriptions/personal.spec.js @@ -18,17 +18,19 @@ 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 = { allAccountsInfo: [], - listAccounts: [] + listAccounts: [], + defaultAccount: [] }; return { @@ -38,6 +40,12 @@ function stubApi (accounts, info) { const stub = sinon.stub().resolves(info || TEST_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: { @@ -94,8 +102,15 @@ describe('api/subscriptions/personal', () => { }); it('updates subscribers', () => { +<<<<<<< HEAD expect(cb.firstCall).to.have.been.calledWith('eth_accounts', null, TEST_LIST); expect(cb.secondCall).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); +>>>>>>> 04fb2af... Add parity_defaultAccount RPC (with subscription) (#4383) }); }); @@ -110,6 +125,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.allAccountsInfo.length).to.be.ok; }); diff --git a/js/src/jsonrpc/interfaces/parity.js b/js/src/jsonrpc/interfaces/parity.js index 1f6caca4a11..d46b2324f34 100644 --- a/js/src/jsonrpc/interfaces/parity.js +++ b/js/src/jsonrpc/interfaces/parity.js @@ -135,6 +135,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: { desc: 'Returns the default extra data', params: [],