diff --git a/js/npm/parity/README.md b/js/npm/parity/README.md index 2c5396e2d..9ba3b6382 100644 --- a/js/npm/parity/README.md +++ b/js/npm/parity/README.md @@ -17,8 +17,8 @@ Install the package with `npm install --save @parity/parity.js` import { Api } from '@parity/parity.js'; // do the setup -const transport = new Api.Transport.Http('http://localhost:8545'); -const api = new Api(transport); +const provider = new Api.Provider.Http('http://localhost:8545'); +const api = new Api(provider); ``` ### making calls diff --git a/js/src/api/README.md b/js/src/api/README.md index 1a2051eaf..1f8238bd1 100644 --- a/js/src/api/README.md +++ b/js/src/api/README.md @@ -28,8 +28,8 @@ Install the package with `npm install --save ethapi-js` from the [npm registry e import EthApi from 'ethapi-js'; // do the setup -const transport = new EthApi.Transport.Http('http://localhost:8545'); // or .Ws('ws://localhost:8546') -const ethapi = new EthApi(transport); +const provider = new EthApi.Provider.Http('http://localhost:8545'); // or .Ws('ws://localhost:8546') +const ethapi = new EthApi(provider); ``` You will require native Promises and fetch support (latest browsers only), they can be utilised by diff --git a/js/src/api/api.js b/js/src/api/api.js index 0b6e444c8..1d7deea3a 100644 --- a/js/src/api/api.js +++ b/js/src/api/api.js @@ -16,8 +16,9 @@ import EventEmitter from 'eventemitter3'; -import { Http, Ws } from './transport'; import Contract from './contract'; +import { PromiseWrapper, Http as HttpProvider, Ws as WsProvider } from './provider'; +import { Http as HttpTransport, Ws as WsTransport } from './transport'; import { Db, Eth, Parity, Net, Personal, Shh, Signer, Trace, Web3 } from './rpc'; import Subscriptions from './subscriptions'; @@ -26,24 +27,28 @@ import { isFunction } from './util/types'; // import { LocalAccountsMiddleware } from './local'; export default class Api extends EventEmitter { - constructor (transport, allowSubscriptions = true) { + constructor (provider, allowSubscriptions = true) { super(); - if (!transport || !isFunction(transport.execute)) { - throw new Error('EthApi needs transport with execute() function defined'); + if (!provider || (!isFunction(provider.send) && !isFunction(provider.execute))) { + throw new Error('Api needs provider with send() function'); } - this._transport = transport; + if (!isFunction(provider.send)) { + console.warn(new Error('deprecated: Api needs provider with send() function, old-style Transport found instead')); + } - this._db = new Db(transport); - this._eth = new Eth(transport); - this._net = new Net(transport); - this._parity = new Parity(transport); - this._personal = new Personal(transport); - this._shh = new Shh(transport); - this._signer = new Signer(transport); - this._trace = new Trace(transport); - this._web3 = new Web3(transport); + this._provider = new PromiseWrapper(provider); + + this._db = new Db(this._provider); + this._eth = new Eth(this._provider); + this._net = new Net(this._provider); + this._parity = new Parity(this._provider); + this._personal = new Personal(this._provider); + this._shh = new Shh(this._provider); + this._signer = new Signer(this._provider); + this._trace = new Trace(this._provider); + this._web3 = new Web3(this._provider); if (allowSubscriptions) { this._subscriptions = new Subscriptions(this); @@ -62,7 +67,7 @@ export default class Api extends EventEmitter { }) .catch(() => null); - transport.addMiddleware(middleware); + provider.addMiddleware(middleware); } } @@ -86,6 +91,10 @@ export default class Api extends EventEmitter { return this._personal; } + get provider () { + return this._provider.provider; + } + get shh () { return this._shh; } @@ -99,7 +108,7 @@ export default class Api extends EventEmitter { } get transport () { - return this._transport; + return this.provider; } get web3 () { @@ -160,8 +169,14 @@ export default class Api extends EventEmitter { static util = util + static Provider = { + Http: HttpProvider, + Ws: WsProvider + } + + // NOTE: kept for backwards compatibility static Transport = { - Http: Http, - Ws: Ws + Http: HttpTransport, + Ws: WsTransport } } diff --git a/js/src/api/api.spec.js b/js/src/api/api.spec.js index aa18333a0..7dd4981d7 100644 --- a/js/src/api/api.spec.js +++ b/js/src/api/api.spec.js @@ -23,19 +23,19 @@ import Api from './api'; describe('api/Api', () => { describe('constructor', () => { - it('requires defined/non-null transport object', () => { - expect(() => new Api()).to.throw(/Api needs transport/); - expect(() => new Api(null)).to.throw(/Api needs transport/); + it('requires defined/non-null provider object', () => { + expect(() => new Api()).to.throw(/Api needs provider/); + expect(() => new Api(null)).to.throw(/Api needs provider/); }); - it('requires an execute function on the transport object', () => { - expect(() => new Api({})).to.throw(/Api needs transport/); - expect(() => new Api({ execute: true })).to.throw(/Api needs transport/); + it('requires an send function on the transport object', () => { + expect(() => new Api({})).to.throw(/Api needs provider/); + expect(() => new Api({ send: true })).to.throw(/Api needs provider/); }); }); describe('interface', () => { - const api = new Api(new Api.Transport.Http(TEST_HTTP_URL, -1)); + const api = new Api(new Api.Provider.Http(TEST_HTTP_URL, -1)); Object.keys(ethereumRpc).sort().forEach((endpoint) => { describe(endpoint, () => { diff --git a/js/src/api/contract/contract.spec.js b/js/src/api/contract/contract.spec.js index 53889e320..e2679f69b 100644 --- a/js/src/api/contract/contract.spec.js +++ b/js/src/api/contract/contract.spec.js @@ -27,8 +27,8 @@ import Api from '../api'; import Contract from './contract'; import { isInstanceOf, isFunction } from '../util/types'; -const transport = new Api.Transport.Http(TEST_HTTP_URL, -1); -const eth = new Api(transport); +const provider = new Api.Provider.Http(TEST_HTTP_URL, -1); +const eth = new Api(provider); describe('api/contract/Contract', () => { const ADDR = '0x0123456789'; diff --git a/js/src/api/local/localAccountsMiddleware.spec.js b/js/src/api/local/localAccountsMiddleware.spec.js index 7408b4b1e..00f5f4dca 100644 --- a/js/src/api/local/localAccountsMiddleware.spec.js +++ b/js/src/api/local/localAccountsMiddleware.spec.js @@ -43,7 +43,7 @@ describe('api/local/LocalAccountsMiddleware', function () { // Same as `parity_newAccountFromPhrase` with empty phrase return transport - .execute('parity_newAccountFromSecret', SECRET, PASSWORD) + .execute('parity_newAccountFromSecret', [SECRET, PASSWORD]) .catch((_err) => { // Ignore the error - all instances of LocalAccountsMiddleware // share account storage @@ -91,7 +91,7 @@ describe('api/local/LocalAccountsMiddleware', function () { it('allows non-registered methods through', () => { return transport - .execute('eth_getBalance', '0x407d73d8a49eeb85d32cf465507dd71d507100c1') + .execute('eth_getBalance', ['0x407d73d8a49eeb85d32cf465507dd71d507100c1']) .then((result) => { expect(result).to.be.equal(RPC_RESPONSE); }); @@ -116,11 +116,11 @@ describe('api/local/LocalAccountsMiddleware', function () { it('can handle `parity_phraseToAddress`', () => { return transport - .execute('parity_phraseToAddress', '') + .execute('parity_phraseToAddress', ['']) .then((address) => { expect(address).to.be.equal(ADDRESS); - return transport.execute('parity_phraseToAddress', FOO_PHRASE); + return transport.execute('parity_phraseToAddress', [FOO_PHRASE]); }) .then((address) => { expect(address).to.be.equal(FOO_ADDRESS); @@ -129,7 +129,7 @@ describe('api/local/LocalAccountsMiddleware', function () { it('can create and kill an account', () => { return transport - .execute('parity_newAccountFromPhrase', FOO_PHRASE, FOO_PASSWORD) + .execute('parity_newAccountFromPhrase', [FOO_PHRASE, FOO_PASSWORD]) .then((address) => { expect(address).to.be.equal(FOO_ADDRESS); @@ -139,7 +139,7 @@ describe('api/local/LocalAccountsMiddleware', function () { expect(accounts.length).to.be.equal(2); expect(accounts.includes(FOO_ADDRESS)).to.be.true; - return transport.execute('parity_killAccount', FOO_ADDRESS, FOO_PASSWORD); + return transport.execute('parity_killAccount', [FOO_ADDRESS, FOO_PASSWORD]); }) .then((result) => { expect(result).to.be.true; diff --git a/js/src/api/provider/http.js b/js/src/api/provider/http.js new file mode 100644 index 000000000..b59f4bf8a --- /dev/null +++ b/js/src/api/provider/http.js @@ -0,0 +1,26 @@ +// Copyright 2015-2017 Parity Technologies (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 . + +import { Http as Transport } from '../transport'; + +export default class Http extends Transport { + send = (method, params, callback) => { + this + ._execute(method, params) + .then((result) => callback(null, result)) + .catch((error) => callback(error)); + } +} diff --git a/js/src/api/provider/index.js b/js/src/api/provider/index.js new file mode 100644 index 000000000..923a549c8 --- /dev/null +++ b/js/src/api/provider/index.js @@ -0,0 +1,20 @@ +// Copyright 2015-2017 Parity Technologies (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 . + +export PromiseWrapper from './promiseWrapper'; + +export Http from './http'; +export Ws from './ws'; diff --git a/js/src/api/provider/promiseWrapper.js b/js/src/api/provider/promiseWrapper.js new file mode 100644 index 000000000..3241c7b59 --- /dev/null +++ b/js/src/api/provider/promiseWrapper.js @@ -0,0 +1,38 @@ +// Copyright 2015-2017 Parity Technologies (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 . + +export default class PromiseWrapper { + constructor (provider) { + this.provider = provider; + } + + send = (method, ...params) => { + if (!this.provider.send) { + // old-style transport interface for backwards compatibility + return this.provider.execute(method, params); + } + + return new Promise((resolve, reject) => { + this.provider.send(method, params, (error, result) => { + if (error) { + reject(error); + } else { + resolve(result); + } + }); + }); + } +} diff --git a/js/src/api/provider/ws.js b/js/src/api/provider/ws.js new file mode 100644 index 000000000..2a399d309 --- /dev/null +++ b/js/src/api/provider/ws.js @@ -0,0 +1,26 @@ +// Copyright 2015-2017 Parity Technologies (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 . + +import { Ws as Transport } from '../transport'; + +export default class Ws extends Transport { + send = (method, params, callback) => { + this + ._execute(method, params) + .then((result) => callback(null, result)) + .catch((error) => callback(error)); + } +} diff --git a/js/src/api/rpc/db/db.js b/js/src/api/rpc/db/db.js index c87911b8d..50e951244 100644 --- a/js/src/api/rpc/db/db.js +++ b/js/src/api/rpc/db/db.js @@ -23,21 +23,21 @@ export default class Db { getHex (dbName, keyName) { return this._transport - .execute('db_getHex', dbName, keyName); + .send('db_getHex', dbName, keyName); } getString (dbName, keyName) { return this._transport - .execute('db_getString', dbName, keyName); + .send('db_getString', dbName, keyName); } putHex (dbName, keyName, hexData) { return this._transport - .execute('db_putHex', dbName, keyName, inHex(hexData)); + .send('db_putHex', dbName, keyName, inHex(hexData)); } putString (dbName, keyName, stringData) { return this._transport - .execute('db_putString', dbName, keyName, stringData); + .send('db_putString', dbName, keyName, stringData); } } diff --git a/js/src/api/rpc/db/db.spec.js b/js/src/api/rpc/db/db.spec.js index 94256931b..86105127b 100644 --- a/js/src/api/rpc/db/db.spec.js +++ b/js/src/api/rpc/db/db.spec.js @@ -16,10 +16,10 @@ import { TEST_HTTP_URL, mockHttp } from '../../../../test/mockRpc'; -import Http from '../../transport/http'; +import { Http, PromiseWrapper } from '../../provider'; import Db from './db'; -const instance = new Db(new Http(TEST_HTTP_URL, -1)); +const instance = new Db(new PromiseWrapper(new Http(TEST_HTTP_URL, -1))); describe('api/rpc/Db', () => { let scope; diff --git a/js/src/api/rpc/eth/eth.js b/js/src/api/rpc/eth/eth.js index ffde938ea..2163bef0b 100644 --- a/js/src/api/rpc/eth/eth.js +++ b/js/src/api/rpc/eth/eth.js @@ -18,304 +18,304 @@ import { inAddress, inBlockNumber, inData, inFilter, inHash, inHex, inNumber16, import { outAddress, outBlock, outLog, outNumber, outReceipt, outSyncing, outTransaction } from '../../format/output'; export default class Eth { - constructor (transport) { - this._transport = transport; + constructor (provider) { + this._provider = provider; } accounts () { - return this._transport - .execute('eth_accounts') + return this._provider + .send('eth_accounts') .then((accounts) => (accounts || []).map(outAddress)); } blockNumber () { - return this._transport - .execute('eth_blockNumber') + return this._provider + .send('eth_blockNumber') .then(outNumber); } call (options, blockNumber = 'latest') { - return this._transport - .execute('eth_call', inOptions(options), inBlockNumber(blockNumber)); + return this._provider + .send('eth_call', inOptions(options), inBlockNumber(blockNumber)); } coinbase () { - return this._transport - .execute('eth_coinbase') + return this._provider + .send('eth_coinbase') .then(outAddress); } compileLLL (code) { - return this._transport - .execute('eth_compileLLL', inData(code)); + return this._provider + .send('eth_compileLLL', inData(code)); } compileSerpent (code) { - return this._transport - .execute('eth_compileSerpent', inData(code)); + return this._provider + .send('eth_compileSerpent', inData(code)); } compileSolidity (code) { - return this._transport - .execute('eth_compileSolidity', inData(code)); + return this._provider + .send('eth_compileSolidity', inData(code)); } estimateGas (options) { - return this._transport - .execute('eth_estimateGas', inOptions(options)) + return this._provider + .send('eth_estimateGas', inOptions(options)) .then(outNumber); } fetchQueuedTransactions () { - return this._transport - .execute('eth_fetchQueuedTransactions'); + return this._provider + .send('eth_fetchQueuedTransactions'); } flush () { - return this._transport - .execute('eth_flush'); + return this._provider + .send('eth_flush'); } gasPrice () { - return this._transport - .execute('eth_gasPrice') + return this._provider + .send('eth_gasPrice') .then(outNumber); } getBalance (address, blockNumber = 'latest') { - return this._transport - .execute('eth_getBalance', inAddress(address), inBlockNumber(blockNumber)) + return this._provider + .send('eth_getBalance', inAddress(address), inBlockNumber(blockNumber)) .then(outNumber); } getBlockByHash (hash, full = false) { - return this._transport - .execute('eth_getBlockByHash', inHex(hash), full) + return this._provider + .send('eth_getBlockByHash', inHex(hash), full) .then(outBlock); } getBlockByNumber (blockNumber = 'latest', full = false) { - return this._transport - .execute('eth_getBlockByNumber', inBlockNumber(blockNumber), full) + return this._provider + .send('eth_getBlockByNumber', inBlockNumber(blockNumber), full) .then(outBlock); } getBlockTransactionCountByHash (hash) { - return this._transport - .execute('eth_getBlockTransactionCountByHash', inHex(hash)) + return this._provider + .send('eth_getBlockTransactionCountByHash', inHex(hash)) .then(outNumber); } getBlockTransactionCountByNumber (blockNumber = 'latest') { - return this._transport - .execute('eth_getBlockTransactionCountByNumber', inBlockNumber(blockNumber)) + return this._provider + .send('eth_getBlockTransactionCountByNumber', inBlockNumber(blockNumber)) .then(outNumber); } getCode (address, blockNumber = 'latest') { - return this._transport - .execute('eth_getCode', inAddress(address), inBlockNumber(blockNumber)); + return this._provider + .send('eth_getCode', inAddress(address), inBlockNumber(blockNumber)); } getCompilers () { - return this._transport - .execute('eth_getCompilers'); + return this._provider + .send('eth_getCompilers'); } getFilterChanges (filterId) { - return this._transport - .execute('eth_getFilterChanges', inNumber16(filterId)) + return this._provider + .send('eth_getFilterChanges', inNumber16(filterId)) .then((logs) => logs.map(outLog)); } getFilterChangesEx (filterId) { - return this._transport - .execute('eth_getFilterChangesEx', inNumber16(filterId)); + return this._provider + .send('eth_getFilterChangesEx', inNumber16(filterId)); } getFilterLogs (filterId) { - return this._transport - .execute('eth_getFilterLogs', inNumber16(filterId)) + return this._provider + .send('eth_getFilterLogs', inNumber16(filterId)) .then((logs) => logs.map(outLog)); } getFilterLogsEx (filterId) { - return this._transport - .execute('eth_getFilterLogsEx', inNumber16(filterId)); + return this._provider + .send('eth_getFilterLogsEx', inNumber16(filterId)); } getLogs (options) { - return this._transport - .execute('eth_getLogs', inFilter(options)) + return this._provider + .send('eth_getLogs', inFilter(options)) .then((logs) => logs.map(outLog)); } getLogsEx (options) { - return this._transport - .execute('eth_getLogsEx', inFilter(options)); + return this._provider + .send('eth_getLogsEx', inFilter(options)); } getStorageAt (address, index = 0, blockNumber = 'latest') { - return this._transport - .execute('eth_getStorageAt', inAddress(address), inNumber16(index), inBlockNumber(blockNumber)); + return this._provider + .send('eth_getStorageAt', inAddress(address), inNumber16(index), inBlockNumber(blockNumber)); } getTransactionByBlockHashAndIndex (hash, index = 0) { - return this._transport - .execute('eth_getTransactionByBlockHashAndIndex', inHex(hash), inNumber16(index)) + return this._provider + .send('eth_getTransactionByBlockHashAndIndex', inHex(hash), inNumber16(index)) .then(outTransaction); } getTransactionByBlockNumberAndIndex (blockNumber = 'latest', index = 0) { - return this._transport - .execute('eth_getTransactionByBlockNumberAndIndex', inBlockNumber(blockNumber), inNumber16(index)) + return this._provider + .send('eth_getTransactionByBlockNumberAndIndex', inBlockNumber(blockNumber), inNumber16(index)) .then(outTransaction); } getTransactionByHash (hash) { - return this._transport - .execute('eth_getTransactionByHash', inHex(hash)) + return this._provider + .send('eth_getTransactionByHash', inHex(hash)) .then(outTransaction); } getTransactionCount (address, blockNumber = 'latest') { - return this._transport - .execute('eth_getTransactionCount', inAddress(address), inBlockNumber(blockNumber)) + return this._provider + .send('eth_getTransactionCount', inAddress(address), inBlockNumber(blockNumber)) .then(outNumber); } getTransactionReceipt (txhash) { - return this._transport - .execute('eth_getTransactionReceipt', inHex(txhash)) + return this._provider + .send('eth_getTransactionReceipt', inHex(txhash)) .then(outReceipt); } getUncleByBlockHashAndIndex (hash, index = 0) { - return this._transport - .execute('eth_getUncleByBlockHashAndIndex', inHex(hash), inNumber16(index)); + return this._provider + .send('eth_getUncleByBlockHashAndIndex', inHex(hash), inNumber16(index)); } getUncleByBlockNumberAndIndex (blockNumber = 'latest', index = 0) { - return this._transport - .execute('eth_getUncleByBlockNumberAndIndex', inBlockNumber(blockNumber), inNumber16(index)); + return this._provider + .send('eth_getUncleByBlockNumberAndIndex', inBlockNumber(blockNumber), inNumber16(index)); } getUncleCountByBlockHash (hash) { - return this._transport - .execute('eth_getUncleCountByBlockHash', inHex(hash)) + return this._provider + .send('eth_getUncleCountByBlockHash', inHex(hash)) .then(outNumber); } getUncleCountByBlockNumber (blockNumber = 'latest') { - return this._transport - .execute('eth_getUncleCountByBlockNumber', inBlockNumber(blockNumber)) + return this._provider + .send('eth_getUncleCountByBlockNumber', inBlockNumber(blockNumber)) .then(outNumber); } getWork () { - return this._transport - .execute('eth_getWork'); + return this._provider + .send('eth_getWork'); } hashrate () { - return this._transport - .execute('eth_hashrate') + return this._provider + .send('eth_hashrate') .then(outNumber); } inspectTransaction () { - return this._transport - .execute('eth_inspectTransaction'); + return this._provider + .send('eth_inspectTransaction'); } mining () { - return this._transport - .execute('eth_mining'); + return this._provider + .send('eth_mining'); } newBlockFilter () { - return this._transport - .execute('eth_newBlockFilter'); + return this._provider + .send('eth_newBlockFilter'); } newFilter (options) { - return this._transport - .execute('eth_newFilter', inFilter(options)); + return this._provider + .send('eth_newFilter', inFilter(options)); } newFilterEx (options) { - return this._transport - .execute('eth_newFilterEx', inFilter(options)); + return this._provider + .send('eth_newFilterEx', inFilter(options)); } newPendingTransactionFilter () { - return this._transport - .execute('eth_newPendingTransactionFilter'); + return this._provider + .send('eth_newPendingTransactionFilter'); } notePassword () { - return this._transport - .execute('eth_notePassword'); + return this._provider + .send('eth_notePassword'); } pendingTransactions () { - return this._transport - .execute('eth_pendingTransactions'); + return this._provider + .send('eth_pendingTransactions'); } protocolVersion () { - return this._transport - .execute('eth_protocolVersion'); + return this._provider + .send('eth_protocolVersion'); } register () { - return this._transport - .execute('eth_register'); + return this._provider + .send('eth_register'); } sendRawTransaction (data) { - return this._transport - .execute('eth_sendRawTransaction', inData(data)); + return this._provider + .send('eth_sendRawTransaction', inData(data)); } sendTransaction (options) { - return this._transport - .execute('eth_sendTransaction', inOptions(options)); + return this._provider + .send('eth_sendTransaction', inOptions(options)); } sign (address, hash) { - return this._transport - .execute('eth_sign', inAddress(address), inHash(hash)); + return this._provider + .send('eth_sign', inAddress(address), inHash(hash)); } signTransaction (options) { - return this._transport - .execute('eth_signTransaction', inOptions(options)); + return this._provider + .send('eth_signTransaction', inOptions(options)); } submitHashrate (hashrate, clientId) { - return this._transport - .execute('eth_submitHashrate', inNumber16(hashrate), clientId); + return this._provider + .send('eth_submitHashrate', inNumber16(hashrate), clientId); } submitWork (nonce, powHash, mixDigest) { - return this._transport - .execute('eth_submitWork', inNumber16(nonce), powHash, mixDigest); + return this._provider + .send('eth_submitWork', inNumber16(nonce), powHash, mixDigest); } syncing () { - return this._transport - .execute('eth_syncing') + return this._provider + .send('eth_syncing') .then(outSyncing); } uninstallFilter (filterId) { - return this._transport - .execute('eth_uninstallFilter', inHex(filterId)); + return this._provider + .send('eth_uninstallFilter', inHex(filterId)); } unregister () { - return this._transport - .execute('eth_unregister'); + return this._provider + .send('eth_unregister'); } } diff --git a/js/src/api/rpc/eth/eth.spec.js b/js/src/api/rpc/eth/eth.spec.js index 2738fd2de..b88ac390f 100644 --- a/js/src/api/rpc/eth/eth.spec.js +++ b/js/src/api/rpc/eth/eth.spec.js @@ -17,10 +17,10 @@ import { TEST_HTTP_URL, mockHttp } from '../../../../test/mockRpc'; import { isBigNumber } from '../../../../test/types'; -import Http from '../../transport/http'; +import { Http, PromiseWrapper } from '../../provider'; import Eth from './eth'; -const instance = new Eth(new Http(TEST_HTTP_URL, -1)); +const instance = new Eth(new PromiseWrapper(new Http(TEST_HTTP_URL, -1))); describe('rpc/Eth', () => { const address = '0x63Cf90D3f0410092FC0fca41846f596223979195'; diff --git a/js/src/api/rpc/net/net.js b/js/src/api/rpc/net/net.js index 9b14f69d5..e9a050f14 100644 --- a/js/src/api/rpc/net/net.js +++ b/js/src/api/rpc/net/net.js @@ -17,23 +17,23 @@ import { outNumber } from '../../format/output'; export default class Net { - constructor (transport) { - this._transport = transport; + constructor (provider) { + this._provider = provider; } listening () { - return this._transport - .execute('net_listening'); + return this._provider + .send('net_listening'); } peerCount () { - return this._transport - .execute('net_peerCount') + return this._provider + .send('net_peerCount') .then(outNumber); } version () { - return this._transport - .execute('net_version'); + return this._provider + .send('net_version'); } } diff --git a/js/src/api/rpc/net/net.spec.js b/js/src/api/rpc/net/net.spec.js index 07ad52076..1aeae2f79 100644 --- a/js/src/api/rpc/net/net.spec.js +++ b/js/src/api/rpc/net/net.spec.js @@ -17,10 +17,10 @@ import { TEST_HTTP_URL, mockHttp } from '../../../../test/mockRpc'; import { isBigNumber } from '../../../../test/types'; -import Http from '../../transport/http'; +import { Http, PromiseWrapper } from '../../provider'; import Net from './net'; -const instance = new Net(new Http(TEST_HTTP_URL, -1)); +const instance = new Net(new PromiseWrapper(new Http(TEST_HTTP_URL, -1))); describe('api/rpc/Net', () => { describe('peerCount', () => { diff --git a/js/src/api/rpc/parity/parity.js b/js/src/api/rpc/parity/parity.js index 4fdaf5b1b..40f67f3d0 100644 --- a/js/src/api/rpc/parity/parity.js +++ b/js/src/api/rpc/parity/parity.js @@ -18,283 +18,283 @@ import { inAddress, inAddresses, inBlockNumber, inData, inDeriveHash, inDeriveIn import { outAccountInfo, outAddress, outAddresses, outBlock, outChainStatus, outHistogram, outHwAccountInfo, outNodeKind, outNumber, outPeers, outRecentDapps, outTransaction, outVaultMeta } from '../../format/output'; export default class Parity { - constructor (transport) { - this._transport = transport; + constructor (provider) { + this._provider = provider; } acceptNonReservedPeers () { - return this._transport - .execute('parity_acceptNonReservedPeers'); + return this._provider + .send('parity_acceptNonReservedPeers'); } accountsInfo () { - return this._transport - .execute('parity_accountsInfo') + return this._provider + .send('parity_accountsInfo') .then(outAccountInfo); } allAccountsInfo () { - return this._transport - .execute('parity_allAccountsInfo') + return this._provider + .send('parity_allAccountsInfo') .then(outAccountInfo); } addReservedPeer (enode) { - return this._transport - .execute('parity_addReservedPeer', enode); + return this._provider + .send('parity_addReservedPeer', enode); } chainStatus () { - return this._transport - .execute('parity_chainStatus') + return this._provider + .send('parity_chainStatus') .then(outChainStatus); } changePassword (account, password, newPassword) { - return this._transport - .execute('parity_changePassword', inAddress(account), password, newPassword); + return this._provider + .send('parity_changePassword', inAddress(account), password, newPassword); } changeVault (account, vaultName) { - return this._transport - .execute('parity_changeVault', inAddress(account), vaultName); + return this._provider + .send('parity_changeVault', inAddress(account), vaultName); } changeVaultPassword (vaultName, password) { - return this._transport - .execute('parity_changeVaultPassword', vaultName, password); + return this._provider + .send('parity_changeVaultPassword', vaultName, password); } checkRequest (requestId) { - return this._transport - .execute('parity_checkRequest', inNumber16(requestId)); + return this._provider + .send('parity_checkRequest', inNumber16(requestId)); } cidV0 (data) { - return this._transport - .execute('parity_cidV0', inData(data)); + return this._provider + .send('parity_cidV0', inData(data)); } closeVault (vaultName) { - return this._transport - .execute('parity_closeVault', vaultName); + return this._provider + .send('parity_closeVault', vaultName); } composeTransaction (options) { - return this._transport - .execute('parity_composeTransaction', inOptions(options)); + return this._provider + .send('parity_composeTransaction', inOptions(options)); } consensusCapability () { - return this._transport - .execute('parity_consensusCapability'); + return this._provider + .send('parity_consensusCapability'); } dappsList () { - return this._transport - .execute('parity_dappsList'); + return this._provider + .send('parity_dappsList'); } dappsUrl () { - return this._transport - .execute('parity_dappsUrl'); + return this._provider + .send('parity_dappsUrl'); } decryptMessage (address, data) { - return this._transport - .execute('parity_decryptMessage', inAddress(address), inHex(data)); + return this._provider + .send('parity_decryptMessage', inAddress(address), inHex(data)); } defaultAccount () { - return this._transport - .execute('parity_defaultAccount') + return this._provider + .send('parity_defaultAccount') .then(outAddress); } defaultExtraData () { - return this._transport - .execute('parity_defaultExtraData'); + return this._provider + .send('parity_defaultExtraData'); } devLogs () { - return this._transport - .execute('parity_devLogs'); + return this._provider + .send('parity_devLogs'); } devLogsLevels () { - return this._transport - .execute('parity_devLogsLevels'); + return this._provider + .send('parity_devLogsLevels'); } deriveAddressHash (address, password, hash, shouldSave) { - return this._transport - .execute('parity_deriveAddressHash', inAddress(address), password, inDeriveHash(hash), !!shouldSave) + return this._provider + .send('parity_deriveAddressHash', inAddress(address), password, inDeriveHash(hash), !!shouldSave) .then(outAddress); } deriveAddressIndex (address, password, index, shouldSave) { - return this._transport - .execute('parity_deriveAddressIndex', inAddress(address), password, inDeriveIndex(index), !!shouldSave) + return this._provider + .send('parity_deriveAddressIndex', inAddress(address), password, inDeriveIndex(index), !!shouldSave) .then(outAddress); } dropNonReservedPeers () { - return this._transport - .execute('parity_dropNonReservedPeers'); + return this._provider + .send('parity_dropNonReservedPeers'); } enode () { - return this._transport - .execute('parity_enode'); + return this._provider + .send('parity_enode'); } encryptMessage (pubkey, data) { - return this._transport - .execute('parity_encryptMessage', inHex(pubkey), inHex(data)); + return this._provider + .send('parity_encryptMessage', inHex(pubkey), inHex(data)); } executeUpgrade () { - return this._transport - .execute('parity_executeUpgrade'); + return this._provider + .send('parity_executeUpgrade'); } exportAccount (address, password) { - return this._transport - .execute('parity_exportAccount', inAddress(address), password); + return this._provider + .send('parity_exportAccount', inAddress(address), password); } extraData () { - return this._transport - .execute('parity_extraData'); + return this._provider + .send('parity_extraData'); } futureTransactions () { - return this._transport - .execute('parity_futureTransactions'); + return this._provider + .send('parity_futureTransactions'); } gasCeilTarget () { - return this._transport - .execute('parity_gasCeilTarget') + return this._provider + .send('parity_gasCeilTarget') .then(outNumber); } gasFloorTarget () { - return this._transport - .execute('parity_gasFloorTarget') + return this._provider + .send('parity_gasFloorTarget') .then(outNumber); } gasPriceHistogram () { - return this._transport - .execute('parity_gasPriceHistogram') + return this._provider + .send('parity_gasPriceHistogram') .then(outHistogram); } generateSecretPhrase () { - return this._transport - .execute('parity_generateSecretPhrase'); + return this._provider + .send('parity_generateSecretPhrase'); } getBlockHeaderByNumber (blockNumber = 'latest') { - return this._transport - .execute('parity_getBlockHeaderByNumber', inBlockNumber(blockNumber)) + return this._provider + .send('parity_getBlockHeaderByNumber', inBlockNumber(blockNumber)) .then(outBlock); } getDappAddresses (dappId) { - return this._transport - .execute('parity_getDappAddresses', dappId) + return this._provider + .send('parity_getDappAddresses', dappId) .then(outAddresses); } getDappDefaultAddress (dappId) { - return this._transport - .execute('parity_getDappDefaultAddress', dappId) + return this._provider + .send('parity_getDappDefaultAddress', dappId) .then(outAddress); } getNewDappsAddresses () { - return this._transport - .execute('parity_getNewDappsAddresses') + return this._provider + .send('parity_getNewDappsAddresses') .then((addresses) => addresses ? addresses.map(outAddress) : null); } getNewDappsDefaultAddress () { - return this._transport - .execute('parity_getNewDappsDefaultAddress') + return this._provider + .send('parity_getNewDappsDefaultAddress') .then(outAddress); } getVaultMeta (vaultName) { - return this._transport - .execute('parity_getVaultMeta', vaultName) + return this._provider + .send('parity_getVaultMeta', vaultName) .then(outVaultMeta); } hardwareAccountsInfo () { - return this._transport - .execute('parity_hardwareAccountsInfo') + return this._provider + .send('parity_hardwareAccountsInfo') .then(outHwAccountInfo); } hashContent (url) { - return this._transport - .execute('parity_hashContent', url); + return this._provider + .send('parity_hashContent', url); } importGethAccounts (accounts) { - return this._transport - .execute('parity_importGethAccounts', inAddresses(accounts)) + return this._provider + .send('parity_importGethAccounts', inAddresses(accounts)) .then(outAddresses); } killAccount (account, password) { - return this._transport - .execute('parity_killAccount', inAddress(account), password); + return this._provider + .send('parity_killAccount', inAddress(account), password); } listAccounts (count, offset = null, blockNumber = 'latest') { - return this._transport - .execute('parity_listAccounts', count, inAddress(offset), inBlockNumber(blockNumber)) + return this._provider + .send('parity_listAccounts', count, inAddress(offset), inBlockNumber(blockNumber)) .then((accounts) => (accounts || []).map(outAddress)); } listOpenedVaults () { - return this._transport - .execute('parity_listOpenedVaults'); + return this._provider + .send('parity_listOpenedVaults'); } listVaults () { - return this._transport - .execute('parity_listVaults'); + return this._provider + .send('parity_listVaults'); } listRecentDapps () { - return this._transport - .execute('parity_listRecentDapps') + return this._provider + .send('parity_listRecentDapps') .then(outRecentDapps); } listStorageKeys (address, count, hash = null, blockNumber = 'latest') { - return this._transport - .execute('parity_listStorageKeys', inAddress(address), count, inHex(hash), inBlockNumber(blockNumber)); + return this._provider + .send('parity_listStorageKeys', inAddress(address), count, inHex(hash), inBlockNumber(blockNumber)); } removeAddress (address) { - return this._transport - .execute('parity_removeAddress', inAddress(address)); + return this._provider + .send('parity_removeAddress', inAddress(address)); } listGethAccounts () { - return this._transport - .execute('parity_listGethAccounts') + return this._provider + .send('parity_listGethAccounts') .then(outAddresses); } localTransactions () { - return this._transport - .execute('parity_localTransactions') + return this._provider + .send('parity_localTransactions') .then(transactions => { Object.values(transactions) .filter(tx => tx.transaction) @@ -306,263 +306,263 @@ export default class Parity { } minGasPrice () { - return this._transport - .execute('parity_minGasPrice') + return this._provider + .send('parity_minGasPrice') .then(outNumber); } mode () { - return this._transport - .execute('parity_mode'); + return this._provider + .send('parity_mode'); } // DEPRECATED - use chain instead. netChain () { - return this._transport - .execute('parity_chain'); + return this._provider + .send('parity_chain'); } nodeKind () { - return this._transport - .execute('parity_nodeKind') + return this._provider + .send('parity_nodeKind') .then(outNodeKind); } chain () { - return this._transport - .execute('parity_chain'); + return this._provider + .send('parity_chain'); } netPeers () { - return this._transport - .execute('parity_netPeers') + return this._provider + .send('parity_netPeers') .then(outPeers); } netMaxPeers () { - return this._transport - .execute('parity_netMaxPeers') + return this._provider + .send('parity_netMaxPeers') .then(outNumber); } netPort () { - return this._transport - .execute('parity_netPort') + return this._provider + .send('parity_netPort') .then(outNumber); } newAccountFromPhrase (phrase, password) { - return this._transport - .execute('parity_newAccountFromPhrase', phrase, password) + return this._provider + .send('parity_newAccountFromPhrase', phrase, password) .then(outAddress); } newAccountFromSecret (secret, password) { - return this._transport - .execute('parity_newAccountFromSecret', inHex(secret), password) + return this._provider + .send('parity_newAccountFromSecret', inHex(secret), password) .then(outAddress); } newAccountFromWallet (json, password) { - return this._transport - .execute('parity_newAccountFromWallet', json, password) + return this._provider + .send('parity_newAccountFromWallet', json, password) .then(outAddress); } newVault (vaultName, password) { - return this._transport - .execute('parity_newVault', vaultName, password); + return this._provider + .send('parity_newVault', vaultName, password); } nextNonce (account) { - return this._transport - .execute('parity_nextNonce', inAddress(account)) + return this._provider + .send('parity_nextNonce', inAddress(account)) .then(outNumber); } nodeName () { - return this._transport - .execute('parity_nodeName'); + return this._provider + .send('parity_nodeName'); } openVault (vaultName, password) { - return this._transport - .execute('parity_openVault', vaultName, password); + return this._provider + .send('parity_openVault', vaultName, password); } pendingTransactions () { - return this._transport - .execute('parity_pendingTransactions') + return this._provider + .send('parity_pendingTransactions') .then(data => data.map(outTransaction)); } pendingTransactionsStats () { - return this._transport - .execute('parity_pendingTransactionsStats'); + return this._provider + .send('parity_pendingTransactionsStats'); } phraseToAddress (phrase) { - return this._transport - .execute('parity_phraseToAddress', phrase) + return this._provider + .send('parity_phraseToAddress', phrase) .then(outAddress); } postSign (address, hash) { - return this._transport - .execute('parity_postSign', inAddress(address), inHex(hash)); + return this._provider + .send('parity_postSign', inAddress(address), inHex(hash)); } postTransaction (options = {}) { - return this._transport - .execute('parity_postTransaction', inOptions(options)); + return this._provider + .send('parity_postTransaction', inOptions(options)); } registryAddress () { - return this._transport - .execute('parity_registryAddress') + return this._provider + .send('parity_registryAddress') .then(outAddress); } releasesInfo () { - return this._transport - .execute('parity_releasesInfo'); + return this._provider + .send('parity_releasesInfo'); } removeReservedPeer (enode) { - return this._transport - .execute('parity_removeReservedPeer', enode); + return this._provider + .send('parity_removeReservedPeer', enode); } removeTransaction (hash) { - return this._transport - .execute('parity_removeTransaction', inHex(hash)) + return this._provider + .send('parity_removeTransaction', inHex(hash)) .then(outTransaction); } rpcSettings () { - return this._transport - .execute('parity_rpcSettings'); + return this._provider + .send('parity_rpcSettings'); } setAccountName (address, name) { - return this._transport - .execute('parity_setAccountName', inAddress(address), name); + return this._provider + .send('parity_setAccountName', inAddress(address), name); } setAccountMeta (address, meta) { - return this._transport - .execute('parity_setAccountMeta', inAddress(address), JSON.stringify(meta)); + return this._provider + .send('parity_setAccountMeta', inAddress(address), JSON.stringify(meta)); } setAuthor (address) { - return this._transport - .execute('parity_setAuthor', inAddress(address)); + return this._provider + .send('parity_setAuthor', inAddress(address)); } setDappAddresses (dappId, addresses) { - return this._transport - .execute('parity_setDappAddresses', dappId, inAddresses(addresses)); + return this._provider + .send('parity_setDappAddresses', dappId, inAddresses(addresses)); } setDappDefaultAddress (dappId, address) { - return this._transport - .execute('parity_setDappDefaultAddress', dappId, address ? inAddress(address) : null); + return this._provider + .send('parity_setDappDefaultAddress', dappId, address ? inAddress(address) : null); } setEngineSigner (address, password) { - return this._transport - .execute('parity_setEngineSigner', inAddress(address), password); + return this._provider + .send('parity_setEngineSigner', inAddress(address), password); } setExtraData (data) { - return this._transport - .execute('parity_setExtraData', inData(data)); + return this._provider + .send('parity_setExtraData', inData(data)); } setGasCeilTarget (quantity) { - return this._transport - .execute('parity_setGasCeilTarget', inNumber16(quantity)); + return this._provider + .send('parity_setGasCeilTarget', inNumber16(quantity)); } setGasFloorTarget (quantity) { - return this._transport - .execute('parity_setGasFloorTarget', inNumber16(quantity)); + return this._provider + .send('parity_setGasFloorTarget', inNumber16(quantity)); } setMaxTransactionGas (quantity) { - return this._transport - .execute('parity_setMaxTransactionGas', inNumber16(quantity)); + return this._provider + .send('parity_setMaxTransactionGas', inNumber16(quantity)); } setMinGasPrice (quantity) { - return this._transport - .execute('parity_setMinGasPrice', inNumber16(quantity)); + return this._provider + .send('parity_setMinGasPrice', inNumber16(quantity)); } setMode (mode) { - return this._transport - .execute('parity_setMode', mode); + return this._provider + .send('parity_setMode', mode); } setChain (specName) { - return this._transport - .execute('parity_setChain', specName); + return this._provider + .send('parity_setChain', specName); } setNewDappsAddresses (addresses) { - return this._transport - .execute('parity_setNewDappsAddresses', addresses ? inAddresses(addresses) : null); + return this._provider + .send('parity_setNewDappsAddresses', addresses ? inAddresses(addresses) : null); } setNewDappsDefaultAddress (address) { - return this._transport - .execute('parity_setNewDappsDefaultAddress', inAddress(address)); + return this._provider + .send('parity_setNewDappsDefaultAddress', inAddress(address)); } setTransactionsLimit (quantity) { - return this._transport - .execute('parity_setTransactionsLimit', inNumber16(quantity)); + return this._provider + .send('parity_setTransactionsLimit', inNumber16(quantity)); } setVaultMeta (vaultName, meta) { - return this._transport - .execute('parity_setVaultMeta', vaultName, JSON.stringify(meta)); + return this._provider + .send('parity_setVaultMeta', vaultName, JSON.stringify(meta)); } signMessage (address, password, messageHash) { - return this._transport - .execute('parity_signMessage', inAddress(address), password, inHex(messageHash)); + return this._provider + .send('parity_signMessage', inAddress(address), password, inHex(messageHash)); } testPassword (account, password) { - return this._transport - .execute('parity_testPassword', inAddress(account), password); + return this._provider + .send('parity_testPassword', inAddress(account), password); } transactionsLimit () { - return this._transport - .execute('parity_transactionsLimit') + return this._provider + .send('parity_transactionsLimit') .then(outNumber); } unsignedTransactionsCount () { - return this._transport - .execute('parity_unsignedTransactionsCount') + return this._provider + .send('parity_unsignedTransactionsCount') .then(outNumber); } upgradeReady () { - return this._transport - .execute('parity_upgradeReady'); + return this._provider + .send('parity_upgradeReady'); } versionInfo () { - return this._transport - .execute('parity_versionInfo'); + return this._provider + .send('parity_versionInfo'); } wsUrl () { - return this._transport - .execute('parity_wsUrl'); + return this._provider + .send('parity_wsUrl'); } } diff --git a/js/src/api/rpc/parity/parity.spec.js b/js/src/api/rpc/parity/parity.spec.js index d7eb41047..f835318ce 100644 --- a/js/src/api/rpc/parity/parity.spec.js +++ b/js/src/api/rpc/parity/parity.spec.js @@ -18,10 +18,10 @@ import BigNumber from 'bignumber.js'; import { TEST_HTTP_URL, mockHttp } from '../../../../test/mockRpc'; import { isBigNumber } from '../../../../test/types'; -import Http from '../../transport/http'; +import { Http, PromiseWrapper } from '../../provider'; import Parity from './parity'; -const instance = new Parity(new Http(TEST_HTTP_URL, -1)); +const instance = new Parity(new PromiseWrapper(new Http(TEST_HTTP_URL, -1))); describe('api/rpc/parity', () => { describe('accountsInfo', () => { diff --git a/js/src/api/rpc/personal/personal.js b/js/src/api/rpc/personal/personal.js index dd9c40f62..ecdbb7ae8 100644 --- a/js/src/api/rpc/personal/personal.js +++ b/js/src/api/rpc/personal/personal.js @@ -18,29 +18,29 @@ import { inAddress, inNumber10, inOptions } from '../../format/input'; import { outAddress } from '../../format/output'; export default class Personal { - constructor (transport) { - this._transport = transport; + constructor (provider) { + this._provider = provider; } listAccounts () { - return this._transport - .execute('personal_listAccounts') + return this._provider + .send('personal_listAccounts') .then((accounts) => (accounts || []).map(outAddress)); } newAccount (password) { - return this._transport - .execute('personal_newAccount', password) + return this._provider + .send('personal_newAccount', password) .then(outAddress); } sendTransaction (options, password) { - return this._transport - .execute('personal_sendTransaction', inOptions(options), password); + return this._provider + .send('personal_sendTransaction', inOptions(options), password); } unlockAccount (account, password, duration = 1) { - return this._transport - .execute('personal_unlockAccount', inAddress(account), password, inNumber10(duration)); + return this._provider + .send('personal_unlockAccount', inAddress(account), password, inNumber10(duration)); } } diff --git a/js/src/api/rpc/personal/personal.spec.js b/js/src/api/rpc/personal/personal.spec.js index d67bb9dec..359e35929 100644 --- a/js/src/api/rpc/personal/personal.spec.js +++ b/js/src/api/rpc/personal/personal.spec.js @@ -16,10 +16,10 @@ import { TEST_HTTP_URL, mockHttp } from '../../../../test/mockRpc'; -import Http from '../../transport/http'; +import { Http, PromiseWrapper } from '../../provider'; import Personal from './personal'; -const instance = new Personal(new Http(TEST_HTTP_URL, -1)); +const instance = new Personal(new PromiseWrapper(new Http(TEST_HTTP_URL, -1))); describe('rpc/Personal', () => { const account = '0x63cf90d3f0410092fc0fca41846f596223979195'; diff --git a/js/src/api/rpc/shh/shh.js b/js/src/api/rpc/shh/shh.js index 9312df6c1..b63674a34 100644 --- a/js/src/api/rpc/shh/shh.js +++ b/js/src/api/rpc/shh/shh.js @@ -15,57 +15,57 @@ // along with Parity. If not, see . export default class Personal { - constructor (transport) { - this._transport = transport; + constructor (provider) { + this._provider = provider; } addToGroup (identity) { - return this._transport - .execute('shh_addToGroup', identity); + return this._provider + .send('shh_addToGroup', identity); } getFilterChanges (filterId) { - return this._transport - .execute('shh_getFilterChanges', filterId); + return this._provider + .send('shh_getFilterChanges', filterId); } getMessages (filterId) { - return this._transport - .execute('shh_getMessages', filterId); + return this._provider + .send('shh_getMessages', filterId); } hasIdentity (identity) { - return this._transport - .execute('shh_hasIdentity', identity); + return this._provider + .send('shh_hasIdentity', identity); } newFilter (options) { - return this._transport - .execute('shh_newFilter', options); + return this._provider + .send('shh_newFilter', options); } newGroup () { - return this._transport - .execute('shh_newGroup'); + return this._provider + .send('shh_newGroup'); } newIdentity () { - return this._transport - .execute('shh_newIdentity'); + return this._provider + .send('shh_newIdentity'); } post (options) { - return this._transport - .execute('shh_post', options); + return this._provider + .send('shh_post', options); } uninstallFilter (filterId) { - return this._transport - .execute('shh_uninstallFilter', filterId); + return this._provider + .send('shh_uninstallFilter', filterId); } version () { - return this._transport - .execute('shh_version'); + return this._provider + .send('shh_version'); } } diff --git a/js/src/api/rpc/signer/signer.js b/js/src/api/rpc/signer/signer.js index 3beef5747..c1844b9e2 100644 --- a/js/src/api/rpc/signer/signer.js +++ b/js/src/api/rpc/signer/signer.js @@ -18,48 +18,48 @@ import { inData, inNumber16, inOptions } from '../../format/input'; import { outSignerRequest } from '../../format/output'; export default class Signer { - constructor (transport) { - this._transport = transport; + constructor (provider) { + this._provider = provider; } confirmRequest (requestId, options, password) { - return this._transport - .execute('signer_confirmRequest', inNumber16(requestId), inOptions(options), password); + return this._provider + .send('signer_confirmRequest', inNumber16(requestId), inOptions(options), password); } confirmRequestRaw (requestId, data) { - return this._transport - .execute('signer_confirmRequestRaw', inNumber16(requestId), inData(data)); + return this._provider + .send('signer_confirmRequestRaw', inNumber16(requestId), inData(data)); } confirmRequestWithToken (requestId, options, password) { - return this._transport - .execute('signer_confirmRequestWithToken', inNumber16(requestId), inOptions(options), password); + return this._provider + .send('signer_confirmRequestWithToken', inNumber16(requestId), inOptions(options), password); } generateAuthorizationToken () { - return this._transport - .execute('signer_generateAuthorizationToken'); + return this._provider + .send('signer_generateAuthorizationToken'); } generateWebProxyAccessToken () { - return this._transport - .execute('signer_generateWebProxyAccessToken'); + return this._provider + .send('signer_generateWebProxyAccessToken'); } rejectRequest (requestId) { - return this._transport - .execute('signer_rejectRequest', inNumber16(requestId)); + return this._provider + .send('signer_rejectRequest', inNumber16(requestId)); } requestsToConfirm () { - return this._transport - .execute('signer_requestsToConfirm') + return this._provider + .send('signer_requestsToConfirm') .then((requests) => (requests || []).map(outSignerRequest)); } signerEnabled () { - return this._transport - .execute('signer_signerEnabled'); + return this._provider + .send('signer_signerEnabled'); } } diff --git a/js/src/api/rpc/trace/trace.js b/js/src/api/rpc/trace/trace.js index 29494a9ae..8e77996bf 100644 --- a/js/src/api/rpc/trace/trace.js +++ b/js/src/api/rpc/trace/trace.js @@ -18,49 +18,49 @@ import { inBlockNumber, inData, inHex, inNumber16, inOptions, inTraceFilter, inT import { outTraces, outTraceReplay } from '../../format/output'; export default class Trace { - constructor (transport) { - this._transport = transport; + constructor (provider) { + this._provider = provider; } block (blockNumber = 'latest') { - return this._transport - .execute('trace_block', inBlockNumber(blockNumber)) + return this._provider + .send('trace_block', inBlockNumber(blockNumber)) .then(outTraces); } call (options, blockNumber = 'latest', whatTrace = ['trace']) { - return this._transport - .execute('trace_call', inOptions(options), inBlockNumber(blockNumber), inTraceType(whatTrace)) + return this._provider + .send('trace_call', inOptions(options), inBlockNumber(blockNumber), inTraceType(whatTrace)) .then(outTraceReplay); } filter (filterObj) { - return this._transport - .execute('trace_filter', inTraceFilter(filterObj)) + return this._provider + .send('trace_filter', inTraceFilter(filterObj)) .then(outTraces); } get (txHash, position) { - return this._transport - .execute('trace_get', inHex(txHash), inNumber16(position)) + return this._provider + .send('trace_get', inHex(txHash), inNumber16(position)) .then(outTraces); } rawTransaction (data, whatTrace = ['trace']) { - return this._transport - .execute('trace_rawTransaction', inData(data), inTraceType(whatTrace)) + return this._provider + .send('trace_rawTransaction', inData(data), inTraceType(whatTrace)) .then(outTraceReplay); } replayTransaction (txHash, whatTrace = ['trace']) { - return this._transport - .execute('trace_replayTransaction', txHash, inTraceType(whatTrace)) + return this._provider + .send('trace_replayTransaction', txHash, inTraceType(whatTrace)) .then(outTraceReplay); } transaction (txHash) { - return this._transport - .execute('trace_transaction', inHex(txHash)) + return this._provider + .send('trace_transaction', inHex(txHash)) .then(outTraces); } } diff --git a/js/src/api/rpc/trace/trace.spec.js b/js/src/api/rpc/trace/trace.spec.js index 267d1240f..fff6d76c7 100644 --- a/js/src/api/rpc/trace/trace.spec.js +++ b/js/src/api/rpc/trace/trace.spec.js @@ -16,10 +16,10 @@ import { TEST_HTTP_URL, mockHttp } from '../../../../test/mockRpc'; -import Http from '../../transport/http'; +import { Http, PromiseWrapper } from '../../provider'; import Trace from './trace'; -const instance = new Trace(new Http(TEST_HTTP_URL, -1)); +const instance = new Trace(new PromiseWrapper(new Http(TEST_HTTP_URL, -1))); describe('api/rpc/Trace', () => { let scope; diff --git a/js/src/api/rpc/web3/web3.js b/js/src/api/rpc/web3/web3.js index 21b2d77f1..21e986c97 100644 --- a/js/src/api/rpc/web3/web3.js +++ b/js/src/api/rpc/web3/web3.js @@ -17,17 +17,17 @@ import { inHex } from '../../format/input'; export default class Web3 { - constructor (transport) { - this._transport = transport; + constructor (provider) { + this._provider = provider; } clientVersion () { - return this._transport - .execute('web3_clientVersion'); + return this._provider + .send('web3_clientVersion'); } sha3 (hexStr) { - return this._transport - .execute('web3_sha3', inHex(hexStr)); + return this._provider + .send('web3_sha3', inHex(hexStr)); } } diff --git a/js/src/api/rpc/web3/web3.spec.js b/js/src/api/rpc/web3/web3.spec.js index b46679b82..ba5c263d0 100644 --- a/js/src/api/rpc/web3/web3.spec.js +++ b/js/src/api/rpc/web3/web3.spec.js @@ -16,10 +16,10 @@ import { TEST_HTTP_URL, mockHttp } from '../../../../test/mockRpc'; -import Http from '../../transport/http'; +import { Http, PromiseWrapper } from '../../provider'; import Web3 from './web3'; -const instance = new Web3(new Http(TEST_HTTP_URL, -1)); +const instance = new Web3(new PromiseWrapper(new Http(TEST_HTTP_URL, -1))); describe('api/rpc/Web3', () => { let scope; diff --git a/js/src/api/transport/http/http.spec.js b/js/src/api/transport/http/http.spec.js index 3d08e17a4..6ebb52372 100644 --- a/js/src/api/transport/http/http.spec.js +++ b/js/src/api/transport/http/http.spec.js @@ -67,7 +67,7 @@ describe('api/transport/Http', () => { scope = mockHttp([{ method: 'eth_call', reply: { result: RESULT } }]); return transport - .execute('eth_call', 1, 2, 3, 'test') + .execute('eth_call', [1, 2, 3, 'test']) .then((_result) => { result = _result; }); diff --git a/js/src/api/transport/jsonRpcBase.js b/js/src/api/transport/jsonRpcBase.js index 819e1f496..93f63e37a 100644 --- a/js/src/api/transport/jsonRpcBase.js +++ b/js/src/api/transport/jsonRpcBase.js @@ -74,7 +74,7 @@ export default class JsonRpcBase extends EventEmitter { }; } - execute (method, ...params) { + execute (method, params) { return this._middlewareList.then((middlewareList) => { for (const middleware of middlewareList) { const res = middleware.handle(method, params); diff --git a/js/src/api/transport/middleware.spec.js b/js/src/api/transport/middleware.spec.js index 4ae894135..e8400089b 100644 --- a/js/src/api/transport/middleware.spec.js +++ b/js/src/api/transport/middleware.spec.js @@ -43,19 +43,19 @@ describe('api/transport/Middleware', () => { }); it('Routes requests to middleware', () => { - return transport.execute('mock_rpc', 100).then((num) => { + return transport.execute('mock_rpc', [100]).then((num) => { expect(num).to.be.equal(100); }); }); it('Passes non-mocked requests through', () => { - return transport.execute('not_moced', 200).then((result) => { + return transport.execute('not_moced', [200]).then((result) => { expect(result).to.be.equal(MOCKED); }); }); it('Passes mocked requests through, if middleware returns null', () => { - return transport.execute('mock_null', 300).then((result) => { + return transport.execute('mock_null', [300]).then((result) => { expect(result).to.be.equal(MOCKED); }); }); diff --git a/js/src/api/transport/ws/ws.spec.js b/js/src/api/transport/ws/ws.spec.js index 0d3c9836f..6f939c584 100644 --- a/js/src/api/transport/ws/ws.spec.js +++ b/js/src/api/transport/ws/ws.spec.js @@ -60,7 +60,7 @@ describe('api/transport/Ws', () => { transport = new Ws(TEST_WS_URL); return transport - .execute('test_anyCall', 1, 2, 3) + .execute('test_anyCall', [1, 2, 3]) .then((_result) => { result = _result; }); diff --git a/js/src/parity.js b/js/src/parity.js index 9d414f90e..55d04d2f5 100644 --- a/js/src/parity.js +++ b/js/src/parity.js @@ -23,7 +23,7 @@ import Api from './api'; import './dev.parity.html'; -const api = new Api(new Api.Transport.Http('/rpc/')); +const api = new Api(new Api.Provider.Http('/rpc/')); window.parity = { Api, diff --git a/js/src/secureApi.js b/js/src/secureApi.js index 8fef6c99f..75a7a0508 100644 --- a/js/src/secureApi.js +++ b/js/src/secureApi.js @@ -30,10 +30,10 @@ export default class SecureApi extends Api { _dappsUrl = null; _wsUrl = null; - static getTransport (url, sysuiToken, protocol) { + static getProvider (url, sysuiToken, protocol) { const proto = protocol() === 'https:' ? 'wss:' : 'ws:'; - return new Api.Transport.Ws(`${proto}//${url}`, sysuiToken, false); + return new Api.Provider.Ws(`${proto}//${url}`, sysuiToken, false); } // Returns a protocol with `:` at the end. @@ -41,11 +41,11 @@ export default class SecureApi extends Api { return window.location.protocol; } - constructor (url, nextToken, getTransport = SecureApi.getTransport, protocol = SecureApi.protocol) { + constructor (url, nextToken, getProvider = SecureApi.getProvider, protocol = SecureApi.protocol) { const sysuiToken = store.get('sysuiToken'); - const transport = getTransport(url, sysuiToken, protocol); + const provider = getProvider(url, sysuiToken, protocol); - super(transport); + super(provider); this._wsUrl = url; this.protocol = protocol; @@ -55,7 +55,8 @@ export default class SecureApi extends Api { .map((token) => ({ value: token, tried: false })); // When the transport is closed, try to reconnect - transport.on('close', this.connect, this); + console.log('this.provider', this.provider); + this.provider.on('close', this.connect, this); this.connect(); } @@ -105,7 +106,7 @@ export default class SecureApi extends Api { } get isConnected () { - return this._transport.isConnected; + return this.provider.isConnected; } get needsToken () { @@ -113,7 +114,7 @@ export default class SecureApi extends Api { } get secureToken () { - return this._transport.token; + return this.provider.token; } /** @@ -260,10 +261,10 @@ export default class SecureApi extends Api { const token = this._sanitiseToken(_token); // Update the token in the transport layer - this.transport.updateToken(token, false); + this.provider.updateToken(token, false); log.debug('connecting with token', token); - const connectPromise = this.transport.connect() + const connectPromise = this.provider.connect() .then(() => { log.debug('connected with', token); diff --git a/js/src/ui/TxList/TxRow/txRow.spec.js b/js/src/ui/TxList/TxRow/txRow.spec.js index dbe4f5dea..63d17a350 100644 --- a/js/src/ui/TxList/TxRow/txRow.spec.js +++ b/js/src/ui/TxList/TxRow/txRow.spec.js @@ -23,7 +23,7 @@ import Api from '@parity/api'; import TxRow from './txRow'; -const api = new Api({ execute: sinon.stub() }); +const api = new Api({ send: sinon.stub() }); const STORE = { dispatch: sinon.stub(), diff --git a/js/src/ui/TxList/txList.spec.js b/js/src/ui/TxList/txList.spec.js index 6a60f07b0..6438591a9 100644 --- a/js/src/ui/TxList/txList.spec.js +++ b/js/src/ui/TxList/txList.spec.js @@ -22,7 +22,7 @@ import Api from '@parity/api'; import TxList from './txList'; -const api = new Api({ execute: sinon.stub() }); +const api = new Api({ send: sinon.stub() }); const STORE = { dispatch: sinon.stub(), diff --git a/js/test/e2e/ethapi.js b/js/test/e2e/ethapi.js index 44e910722..e8ed540a9 100644 --- a/js/test/e2e/ethapi.js +++ b/js/test/e2e/ethapi.js @@ -25,9 +25,9 @@ function createApi (transport) { } export function createHttpApi () { - return createApi(new Api.Transport.Http('http://localhost:8545')); + return createApi(new Api.Provider.Http('http://localhost:8545')); } export function createWsApi () { - return createApi(new Api.Transport.Ws('ws://localhost:8546')); + return createApi(new Api.Provider.Ws('ws://localhost:8546')); } diff --git a/js/test/npmParity.js b/js/test/npmParity.js index 9ff3a74e2..0294aa57f 100644 --- a/js/test/npmParity.js +++ b/js/test/npmParity.js @@ -26,7 +26,7 @@ try { throw new Error('No Abi'); } - var transport = new Api.Transport.Http('http://localhost:8545'); + var transport = new Api.Provider.Http('http://localhost:8545'); var api = new Api(transport); api.eth