UI 2 Api providers (#5714)

* Add providers

* Convert rpc calls to use provider

* Update SecureApi for provider
This commit is contained in:
Jaco Greeff 2017-05-31 12:08:04 +02:00 committed by GitHub
parent 265618f306
commit a328eef8d9
36 changed files with 597 additions and 471 deletions

View File

@ -17,8 +17,8 @@ Install the package with `npm install --save @parity/parity.js`
import { Api } from '@parity/parity.js'; import { Api } from '@parity/parity.js';
// do the setup // do the setup
const transport = new Api.Transport.Http('http://localhost:8545'); const provider = new Api.Provider.Http('http://localhost:8545');
const api = new Api(transport); const api = new Api(provider);
``` ```
### making calls ### making calls

View File

@ -28,8 +28,8 @@ Install the package with `npm install --save ethapi-js` from the [npm registry e
import EthApi from 'ethapi-js'; import EthApi from 'ethapi-js';
// do the setup // do the setup
const transport = new EthApi.Transport.Http('http://localhost:8545'); // or .Ws('ws://localhost:8546') const provider = new EthApi.Provider.Http('http://localhost:8545'); // or .Ws('ws://localhost:8546')
const ethapi = new EthApi(transport); const ethapi = new EthApi(provider);
``` ```
You will require native Promises and fetch support (latest browsers only), they can be utilised by You will require native Promises and fetch support (latest browsers only), they can be utilised by

View File

@ -16,8 +16,9 @@
import EventEmitter from 'eventemitter3'; import EventEmitter from 'eventemitter3';
import { Http, Ws } from './transport';
import Contract from './contract'; 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 { Db, Eth, Parity, Net, Personal, Shh, Signer, Trace, Web3 } from './rpc';
import Subscriptions from './subscriptions'; import Subscriptions from './subscriptions';
@ -26,24 +27,28 @@ import { isFunction } from './util/types';
// import { LocalAccountsMiddleware } from './local'; // import { LocalAccountsMiddleware } from './local';
export default class Api extends EventEmitter { export default class Api extends EventEmitter {
constructor (transport, allowSubscriptions = true) { constructor (provider, allowSubscriptions = true) {
super(); super();
if (!transport || !isFunction(transport.execute)) { if (!provider || (!isFunction(provider.send) && !isFunction(provider.execute))) {
throw new Error('EthApi needs transport with execute() function defined'); 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._provider = new PromiseWrapper(provider);
this._eth = new Eth(transport);
this._net = new Net(transport); this._db = new Db(this._provider);
this._parity = new Parity(transport); this._eth = new Eth(this._provider);
this._personal = new Personal(transport); this._net = new Net(this._provider);
this._shh = new Shh(transport); this._parity = new Parity(this._provider);
this._signer = new Signer(transport); this._personal = new Personal(this._provider);
this._trace = new Trace(transport); this._shh = new Shh(this._provider);
this._web3 = new Web3(transport); this._signer = new Signer(this._provider);
this._trace = new Trace(this._provider);
this._web3 = new Web3(this._provider);
if (allowSubscriptions) { if (allowSubscriptions) {
this._subscriptions = new Subscriptions(this); this._subscriptions = new Subscriptions(this);
@ -62,7 +67,7 @@ export default class Api extends EventEmitter {
}) })
.catch(() => null); .catch(() => null);
transport.addMiddleware(middleware); provider.addMiddleware(middleware);
} }
} }
@ -86,6 +91,10 @@ export default class Api extends EventEmitter {
return this._personal; return this._personal;
} }
get provider () {
return this._provider.provider;
}
get shh () { get shh () {
return this._shh; return this._shh;
} }
@ -99,7 +108,7 @@ export default class Api extends EventEmitter {
} }
get transport () { get transport () {
return this._transport; return this.provider;
} }
get web3 () { get web3 () {
@ -160,8 +169,14 @@ export default class Api extends EventEmitter {
static util = util static util = util
static Provider = {
Http: HttpProvider,
Ws: WsProvider
}
// NOTE: kept for backwards compatibility
static Transport = { static Transport = {
Http: Http, Http: HttpTransport,
Ws: Ws Ws: WsTransport
} }
} }

View File

@ -23,19 +23,19 @@ import Api from './api';
describe('api/Api', () => { describe('api/Api', () => {
describe('constructor', () => { describe('constructor', () => {
it('requires defined/non-null transport object', () => { it('requires defined/non-null provider object', () => {
expect(() => new Api()).to.throw(/Api needs transport/); expect(() => new Api()).to.throw(/Api needs provider/);
expect(() => new Api(null)).to.throw(/Api needs transport/); expect(() => new Api(null)).to.throw(/Api needs provider/);
}); });
it('requires an execute function on the transport object', () => { it('requires an send function on the transport object', () => {
expect(() => new Api({})).to.throw(/Api needs transport/); expect(() => new Api({})).to.throw(/Api needs provider/);
expect(() => new Api({ execute: true })).to.throw(/Api needs transport/); expect(() => new Api({ send: true })).to.throw(/Api needs provider/);
}); });
}); });
describe('interface', () => { 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) => { Object.keys(ethereumRpc).sort().forEach((endpoint) => {
describe(endpoint, () => { describe(endpoint, () => {

View File

@ -27,8 +27,8 @@ import Api from '../api';
import Contract from './contract'; import Contract from './contract';
import { isInstanceOf, isFunction } from '../util/types'; import { isInstanceOf, isFunction } from '../util/types';
const transport = new Api.Transport.Http(TEST_HTTP_URL, -1); const provider = new Api.Provider.Http(TEST_HTTP_URL, -1);
const eth = new Api(transport); const eth = new Api(provider);
describe('api/contract/Contract', () => { describe('api/contract/Contract', () => {
const ADDR = '0x0123456789'; const ADDR = '0x0123456789';

View File

@ -43,7 +43,7 @@ describe('api/local/LocalAccountsMiddleware', function () {
// Same as `parity_newAccountFromPhrase` with empty phrase // Same as `parity_newAccountFromPhrase` with empty phrase
return transport return transport
.execute('parity_newAccountFromSecret', SECRET, PASSWORD) .execute('parity_newAccountFromSecret', [SECRET, PASSWORD])
.catch((_err) => { .catch((_err) => {
// Ignore the error - all instances of LocalAccountsMiddleware // Ignore the error - all instances of LocalAccountsMiddleware
// share account storage // share account storage
@ -91,7 +91,7 @@ describe('api/local/LocalAccountsMiddleware', function () {
it('allows non-registered methods through', () => { it('allows non-registered methods through', () => {
return transport return transport
.execute('eth_getBalance', '0x407d73d8a49eeb85d32cf465507dd71d507100c1') .execute('eth_getBalance', ['0x407d73d8a49eeb85d32cf465507dd71d507100c1'])
.then((result) => { .then((result) => {
expect(result).to.be.equal(RPC_RESPONSE); expect(result).to.be.equal(RPC_RESPONSE);
}); });
@ -116,11 +116,11 @@ describe('api/local/LocalAccountsMiddleware', function () {
it('can handle `parity_phraseToAddress`', () => { it('can handle `parity_phraseToAddress`', () => {
return transport return transport
.execute('parity_phraseToAddress', '') .execute('parity_phraseToAddress', [''])
.then((address) => { .then((address) => {
expect(address).to.be.equal(ADDRESS); expect(address).to.be.equal(ADDRESS);
return transport.execute('parity_phraseToAddress', FOO_PHRASE); return transport.execute('parity_phraseToAddress', [FOO_PHRASE]);
}) })
.then((address) => { .then((address) => {
expect(address).to.be.equal(FOO_ADDRESS); expect(address).to.be.equal(FOO_ADDRESS);
@ -129,7 +129,7 @@ describe('api/local/LocalAccountsMiddleware', function () {
it('can create and kill an account', () => { it('can create and kill an account', () => {
return transport return transport
.execute('parity_newAccountFromPhrase', FOO_PHRASE, FOO_PASSWORD) .execute('parity_newAccountFromPhrase', [FOO_PHRASE, FOO_PASSWORD])
.then((address) => { .then((address) => {
expect(address).to.be.equal(FOO_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.length).to.be.equal(2);
expect(accounts.includes(FOO_ADDRESS)).to.be.true; 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) => { .then((result) => {
expect(result).to.be.true; expect(result).to.be.true;

View File

@ -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 <http://www.gnu.org/licenses/>.
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));
}
}

View File

@ -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 <http://www.gnu.org/licenses/>.
export PromiseWrapper from './promiseWrapper';
export Http from './http';
export Ws from './ws';

View File

@ -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 <http://www.gnu.org/licenses/>.
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);
}
});
});
}
}

26
js/src/api/provider/ws.js Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
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));
}
}

View File

@ -23,21 +23,21 @@ export default class Db {
getHex (dbName, keyName) { getHex (dbName, keyName) {
return this._transport return this._transport
.execute('db_getHex', dbName, keyName); .send('db_getHex', dbName, keyName);
} }
getString (dbName, keyName) { getString (dbName, keyName) {
return this._transport return this._transport
.execute('db_getString', dbName, keyName); .send('db_getString', dbName, keyName);
} }
putHex (dbName, keyName, hexData) { putHex (dbName, keyName, hexData) {
return this._transport return this._transport
.execute('db_putHex', dbName, keyName, inHex(hexData)); .send('db_putHex', dbName, keyName, inHex(hexData));
} }
putString (dbName, keyName, stringData) { putString (dbName, keyName, stringData) {
return this._transport return this._transport
.execute('db_putString', dbName, keyName, stringData); .send('db_putString', dbName, keyName, stringData);
} }
} }

View File

@ -16,10 +16,10 @@
import { TEST_HTTP_URL, mockHttp } from '../../../../test/mockRpc'; import { TEST_HTTP_URL, mockHttp } from '../../../../test/mockRpc';
import Http from '../../transport/http'; import { Http, PromiseWrapper } from '../../provider';
import Db from './db'; 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', () => { describe('api/rpc/Db', () => {
let scope; let scope;

View File

@ -18,304 +18,304 @@ import { inAddress, inBlockNumber, inData, inFilter, inHash, inHex, inNumber16,
import { outAddress, outBlock, outLog, outNumber, outReceipt, outSyncing, outTransaction } from '../../format/output'; import { outAddress, outBlock, outLog, outNumber, outReceipt, outSyncing, outTransaction } from '../../format/output';
export default class Eth { export default class Eth {
constructor (transport) { constructor (provider) {
this._transport = transport; this._provider = provider;
} }
accounts () { accounts () {
return this._transport return this._provider
.execute('eth_accounts') .send('eth_accounts')
.then((accounts) => (accounts || []).map(outAddress)); .then((accounts) => (accounts || []).map(outAddress));
} }
blockNumber () { blockNumber () {
return this._transport return this._provider
.execute('eth_blockNumber') .send('eth_blockNumber')
.then(outNumber); .then(outNumber);
} }
call (options, blockNumber = 'latest') { call (options, blockNumber = 'latest') {
return this._transport return this._provider
.execute('eth_call', inOptions(options), inBlockNumber(blockNumber)); .send('eth_call', inOptions(options), inBlockNumber(blockNumber));
} }
coinbase () { coinbase () {
return this._transport return this._provider
.execute('eth_coinbase') .send('eth_coinbase')
.then(outAddress); .then(outAddress);
} }
compileLLL (code) { compileLLL (code) {
return this._transport return this._provider
.execute('eth_compileLLL', inData(code)); .send('eth_compileLLL', inData(code));
} }
compileSerpent (code) { compileSerpent (code) {
return this._transport return this._provider
.execute('eth_compileSerpent', inData(code)); .send('eth_compileSerpent', inData(code));
} }
compileSolidity (code) { compileSolidity (code) {
return this._transport return this._provider
.execute('eth_compileSolidity', inData(code)); .send('eth_compileSolidity', inData(code));
} }
estimateGas (options) { estimateGas (options) {
return this._transport return this._provider
.execute('eth_estimateGas', inOptions(options)) .send('eth_estimateGas', inOptions(options))
.then(outNumber); .then(outNumber);
} }
fetchQueuedTransactions () { fetchQueuedTransactions () {
return this._transport return this._provider
.execute('eth_fetchQueuedTransactions'); .send('eth_fetchQueuedTransactions');
} }
flush () { flush () {
return this._transport return this._provider
.execute('eth_flush'); .send('eth_flush');
} }
gasPrice () { gasPrice () {
return this._transport return this._provider
.execute('eth_gasPrice') .send('eth_gasPrice')
.then(outNumber); .then(outNumber);
} }
getBalance (address, blockNumber = 'latest') { getBalance (address, blockNumber = 'latest') {
return this._transport return this._provider
.execute('eth_getBalance', inAddress(address), inBlockNumber(blockNumber)) .send('eth_getBalance', inAddress(address), inBlockNumber(blockNumber))
.then(outNumber); .then(outNumber);
} }
getBlockByHash (hash, full = false) { getBlockByHash (hash, full = false) {
return this._transport return this._provider
.execute('eth_getBlockByHash', inHex(hash), full) .send('eth_getBlockByHash', inHex(hash), full)
.then(outBlock); .then(outBlock);
} }
getBlockByNumber (blockNumber = 'latest', full = false) { getBlockByNumber (blockNumber = 'latest', full = false) {
return this._transport return this._provider
.execute('eth_getBlockByNumber', inBlockNumber(blockNumber), full) .send('eth_getBlockByNumber', inBlockNumber(blockNumber), full)
.then(outBlock); .then(outBlock);
} }
getBlockTransactionCountByHash (hash) { getBlockTransactionCountByHash (hash) {
return this._transport return this._provider
.execute('eth_getBlockTransactionCountByHash', inHex(hash)) .send('eth_getBlockTransactionCountByHash', inHex(hash))
.then(outNumber); .then(outNumber);
} }
getBlockTransactionCountByNumber (blockNumber = 'latest') { getBlockTransactionCountByNumber (blockNumber = 'latest') {
return this._transport return this._provider
.execute('eth_getBlockTransactionCountByNumber', inBlockNumber(blockNumber)) .send('eth_getBlockTransactionCountByNumber', inBlockNumber(blockNumber))
.then(outNumber); .then(outNumber);
} }
getCode (address, blockNumber = 'latest') { getCode (address, blockNumber = 'latest') {
return this._transport return this._provider
.execute('eth_getCode', inAddress(address), inBlockNumber(blockNumber)); .send('eth_getCode', inAddress(address), inBlockNumber(blockNumber));
} }
getCompilers () { getCompilers () {
return this._transport return this._provider
.execute('eth_getCompilers'); .send('eth_getCompilers');
} }
getFilterChanges (filterId) { getFilterChanges (filterId) {
return this._transport return this._provider
.execute('eth_getFilterChanges', inNumber16(filterId)) .send('eth_getFilterChanges', inNumber16(filterId))
.then((logs) => logs.map(outLog)); .then((logs) => logs.map(outLog));
} }
getFilterChangesEx (filterId) { getFilterChangesEx (filterId) {
return this._transport return this._provider
.execute('eth_getFilterChangesEx', inNumber16(filterId)); .send('eth_getFilterChangesEx', inNumber16(filterId));
} }
getFilterLogs (filterId) { getFilterLogs (filterId) {
return this._transport return this._provider
.execute('eth_getFilterLogs', inNumber16(filterId)) .send('eth_getFilterLogs', inNumber16(filterId))
.then((logs) => logs.map(outLog)); .then((logs) => logs.map(outLog));
} }
getFilterLogsEx (filterId) { getFilterLogsEx (filterId) {
return this._transport return this._provider
.execute('eth_getFilterLogsEx', inNumber16(filterId)); .send('eth_getFilterLogsEx', inNumber16(filterId));
} }
getLogs (options) { getLogs (options) {
return this._transport return this._provider
.execute('eth_getLogs', inFilter(options)) .send('eth_getLogs', inFilter(options))
.then((logs) => logs.map(outLog)); .then((logs) => logs.map(outLog));
} }
getLogsEx (options) { getLogsEx (options) {
return this._transport return this._provider
.execute('eth_getLogsEx', inFilter(options)); .send('eth_getLogsEx', inFilter(options));
} }
getStorageAt (address, index = 0, blockNumber = 'latest') { getStorageAt (address, index = 0, blockNumber = 'latest') {
return this._transport return this._provider
.execute('eth_getStorageAt', inAddress(address), inNumber16(index), inBlockNumber(blockNumber)); .send('eth_getStorageAt', inAddress(address), inNumber16(index), inBlockNumber(blockNumber));
} }
getTransactionByBlockHashAndIndex (hash, index = 0) { getTransactionByBlockHashAndIndex (hash, index = 0) {
return this._transport return this._provider
.execute('eth_getTransactionByBlockHashAndIndex', inHex(hash), inNumber16(index)) .send('eth_getTransactionByBlockHashAndIndex', inHex(hash), inNumber16(index))
.then(outTransaction); .then(outTransaction);
} }
getTransactionByBlockNumberAndIndex (blockNumber = 'latest', index = 0) { getTransactionByBlockNumberAndIndex (blockNumber = 'latest', index = 0) {
return this._transport return this._provider
.execute('eth_getTransactionByBlockNumberAndIndex', inBlockNumber(blockNumber), inNumber16(index)) .send('eth_getTransactionByBlockNumberAndIndex', inBlockNumber(blockNumber), inNumber16(index))
.then(outTransaction); .then(outTransaction);
} }
getTransactionByHash (hash) { getTransactionByHash (hash) {
return this._transport return this._provider
.execute('eth_getTransactionByHash', inHex(hash)) .send('eth_getTransactionByHash', inHex(hash))
.then(outTransaction); .then(outTransaction);
} }
getTransactionCount (address, blockNumber = 'latest') { getTransactionCount (address, blockNumber = 'latest') {
return this._transport return this._provider
.execute('eth_getTransactionCount', inAddress(address), inBlockNumber(blockNumber)) .send('eth_getTransactionCount', inAddress(address), inBlockNumber(blockNumber))
.then(outNumber); .then(outNumber);
} }
getTransactionReceipt (txhash) { getTransactionReceipt (txhash) {
return this._transport return this._provider
.execute('eth_getTransactionReceipt', inHex(txhash)) .send('eth_getTransactionReceipt', inHex(txhash))
.then(outReceipt); .then(outReceipt);
} }
getUncleByBlockHashAndIndex (hash, index = 0) { getUncleByBlockHashAndIndex (hash, index = 0) {
return this._transport return this._provider
.execute('eth_getUncleByBlockHashAndIndex', inHex(hash), inNumber16(index)); .send('eth_getUncleByBlockHashAndIndex', inHex(hash), inNumber16(index));
} }
getUncleByBlockNumberAndIndex (blockNumber = 'latest', index = 0) { getUncleByBlockNumberAndIndex (blockNumber = 'latest', index = 0) {
return this._transport return this._provider
.execute('eth_getUncleByBlockNumberAndIndex', inBlockNumber(blockNumber), inNumber16(index)); .send('eth_getUncleByBlockNumberAndIndex', inBlockNumber(blockNumber), inNumber16(index));
} }
getUncleCountByBlockHash (hash) { getUncleCountByBlockHash (hash) {
return this._transport return this._provider
.execute('eth_getUncleCountByBlockHash', inHex(hash)) .send('eth_getUncleCountByBlockHash', inHex(hash))
.then(outNumber); .then(outNumber);
} }
getUncleCountByBlockNumber (blockNumber = 'latest') { getUncleCountByBlockNumber (blockNumber = 'latest') {
return this._transport return this._provider
.execute('eth_getUncleCountByBlockNumber', inBlockNumber(blockNumber)) .send('eth_getUncleCountByBlockNumber', inBlockNumber(blockNumber))
.then(outNumber); .then(outNumber);
} }
getWork () { getWork () {
return this._transport return this._provider
.execute('eth_getWork'); .send('eth_getWork');
} }
hashrate () { hashrate () {
return this._transport return this._provider
.execute('eth_hashrate') .send('eth_hashrate')
.then(outNumber); .then(outNumber);
} }
inspectTransaction () { inspectTransaction () {
return this._transport return this._provider
.execute('eth_inspectTransaction'); .send('eth_inspectTransaction');
} }
mining () { mining () {
return this._transport return this._provider
.execute('eth_mining'); .send('eth_mining');
} }
newBlockFilter () { newBlockFilter () {
return this._transport return this._provider
.execute('eth_newBlockFilter'); .send('eth_newBlockFilter');
} }
newFilter (options) { newFilter (options) {
return this._transport return this._provider
.execute('eth_newFilter', inFilter(options)); .send('eth_newFilter', inFilter(options));
} }
newFilterEx (options) { newFilterEx (options) {
return this._transport return this._provider
.execute('eth_newFilterEx', inFilter(options)); .send('eth_newFilterEx', inFilter(options));
} }
newPendingTransactionFilter () { newPendingTransactionFilter () {
return this._transport return this._provider
.execute('eth_newPendingTransactionFilter'); .send('eth_newPendingTransactionFilter');
} }
notePassword () { notePassword () {
return this._transport return this._provider
.execute('eth_notePassword'); .send('eth_notePassword');
} }
pendingTransactions () { pendingTransactions () {
return this._transport return this._provider
.execute('eth_pendingTransactions'); .send('eth_pendingTransactions');
} }
protocolVersion () { protocolVersion () {
return this._transport return this._provider
.execute('eth_protocolVersion'); .send('eth_protocolVersion');
} }
register () { register () {
return this._transport return this._provider
.execute('eth_register'); .send('eth_register');
} }
sendRawTransaction (data) { sendRawTransaction (data) {
return this._transport return this._provider
.execute('eth_sendRawTransaction', inData(data)); .send('eth_sendRawTransaction', inData(data));
} }
sendTransaction (options) { sendTransaction (options) {
return this._transport return this._provider
.execute('eth_sendTransaction', inOptions(options)); .send('eth_sendTransaction', inOptions(options));
} }
sign (address, hash) { sign (address, hash) {
return this._transport return this._provider
.execute('eth_sign', inAddress(address), inHash(hash)); .send('eth_sign', inAddress(address), inHash(hash));
} }
signTransaction (options) { signTransaction (options) {
return this._transport return this._provider
.execute('eth_signTransaction', inOptions(options)); .send('eth_signTransaction', inOptions(options));
} }
submitHashrate (hashrate, clientId) { submitHashrate (hashrate, clientId) {
return this._transport return this._provider
.execute('eth_submitHashrate', inNumber16(hashrate), clientId); .send('eth_submitHashrate', inNumber16(hashrate), clientId);
} }
submitWork (nonce, powHash, mixDigest) { submitWork (nonce, powHash, mixDigest) {
return this._transport return this._provider
.execute('eth_submitWork', inNumber16(nonce), powHash, mixDigest); .send('eth_submitWork', inNumber16(nonce), powHash, mixDigest);
} }
syncing () { syncing () {
return this._transport return this._provider
.execute('eth_syncing') .send('eth_syncing')
.then(outSyncing); .then(outSyncing);
} }
uninstallFilter (filterId) { uninstallFilter (filterId) {
return this._transport return this._provider
.execute('eth_uninstallFilter', inHex(filterId)); .send('eth_uninstallFilter', inHex(filterId));
} }
unregister () { unregister () {
return this._transport return this._provider
.execute('eth_unregister'); .send('eth_unregister');
} }
} }

View File

@ -17,10 +17,10 @@
import { TEST_HTTP_URL, mockHttp } from '../../../../test/mockRpc'; import { TEST_HTTP_URL, mockHttp } from '../../../../test/mockRpc';
import { isBigNumber } from '../../../../test/types'; import { isBigNumber } from '../../../../test/types';
import Http from '../../transport/http'; import { Http, PromiseWrapper } from '../../provider';
import Eth from './eth'; 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', () => { describe('rpc/Eth', () => {
const address = '0x63Cf90D3f0410092FC0fca41846f596223979195'; const address = '0x63Cf90D3f0410092FC0fca41846f596223979195';

View File

@ -17,23 +17,23 @@
import { outNumber } from '../../format/output'; import { outNumber } from '../../format/output';
export default class Net { export default class Net {
constructor (transport) { constructor (provider) {
this._transport = transport; this._provider = provider;
} }
listening () { listening () {
return this._transport return this._provider
.execute('net_listening'); .send('net_listening');
} }
peerCount () { peerCount () {
return this._transport return this._provider
.execute('net_peerCount') .send('net_peerCount')
.then(outNumber); .then(outNumber);
} }
version () { version () {
return this._transport return this._provider
.execute('net_version'); .send('net_version');
} }
} }

View File

@ -17,10 +17,10 @@
import { TEST_HTTP_URL, mockHttp } from '../../../../test/mockRpc'; import { TEST_HTTP_URL, mockHttp } from '../../../../test/mockRpc';
import { isBigNumber } from '../../../../test/types'; import { isBigNumber } from '../../../../test/types';
import Http from '../../transport/http'; import { Http, PromiseWrapper } from '../../provider';
import Net from './net'; 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('api/rpc/Net', () => {
describe('peerCount', () => { describe('peerCount', () => {

View File

@ -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'; import { outAccountInfo, outAddress, outAddresses, outBlock, outChainStatus, outHistogram, outHwAccountInfo, outNodeKind, outNumber, outPeers, outRecentDapps, outTransaction, outVaultMeta } from '../../format/output';
export default class Parity { export default class Parity {
constructor (transport) { constructor (provider) {
this._transport = transport; this._provider = provider;
} }
acceptNonReservedPeers () { acceptNonReservedPeers () {
return this._transport return this._provider
.execute('parity_acceptNonReservedPeers'); .send('parity_acceptNonReservedPeers');
} }
accountsInfo () { accountsInfo () {
return this._transport return this._provider
.execute('parity_accountsInfo') .send('parity_accountsInfo')
.then(outAccountInfo); .then(outAccountInfo);
} }
allAccountsInfo () { allAccountsInfo () {
return this._transport return this._provider
.execute('parity_allAccountsInfo') .send('parity_allAccountsInfo')
.then(outAccountInfo); .then(outAccountInfo);
} }
addReservedPeer (enode) { addReservedPeer (enode) {
return this._transport return this._provider
.execute('parity_addReservedPeer', enode); .send('parity_addReservedPeer', enode);
} }
chainStatus () { chainStatus () {
return this._transport return this._provider
.execute('parity_chainStatus') .send('parity_chainStatus')
.then(outChainStatus); .then(outChainStatus);
} }
changePassword (account, password, newPassword) { changePassword (account, password, newPassword) {
return this._transport return this._provider
.execute('parity_changePassword', inAddress(account), password, newPassword); .send('parity_changePassword', inAddress(account), password, newPassword);
} }
changeVault (account, vaultName) { changeVault (account, vaultName) {
return this._transport return this._provider
.execute('parity_changeVault', inAddress(account), vaultName); .send('parity_changeVault', inAddress(account), vaultName);
} }
changeVaultPassword (vaultName, password) { changeVaultPassword (vaultName, password) {
return this._transport return this._provider
.execute('parity_changeVaultPassword', vaultName, password); .send('parity_changeVaultPassword', vaultName, password);
} }
checkRequest (requestId) { checkRequest (requestId) {
return this._transport return this._provider
.execute('parity_checkRequest', inNumber16(requestId)); .send('parity_checkRequest', inNumber16(requestId));
} }
cidV0 (data) { cidV0 (data) {
return this._transport return this._provider
.execute('parity_cidV0', inData(data)); .send('parity_cidV0', inData(data));
} }
closeVault (vaultName) { closeVault (vaultName) {
return this._transport return this._provider
.execute('parity_closeVault', vaultName); .send('parity_closeVault', vaultName);
} }
composeTransaction (options) { composeTransaction (options) {
return this._transport return this._provider
.execute('parity_composeTransaction', inOptions(options)); .send('parity_composeTransaction', inOptions(options));
} }
consensusCapability () { consensusCapability () {
return this._transport return this._provider
.execute('parity_consensusCapability'); .send('parity_consensusCapability');
} }
dappsList () { dappsList () {
return this._transport return this._provider
.execute('parity_dappsList'); .send('parity_dappsList');
} }
dappsUrl () { dappsUrl () {
return this._transport return this._provider
.execute('parity_dappsUrl'); .send('parity_dappsUrl');
} }
decryptMessage (address, data) { decryptMessage (address, data) {
return this._transport return this._provider
.execute('parity_decryptMessage', inAddress(address), inHex(data)); .send('parity_decryptMessage', inAddress(address), inHex(data));
} }
defaultAccount () { defaultAccount () {
return this._transport return this._provider
.execute('parity_defaultAccount') .send('parity_defaultAccount')
.then(outAddress); .then(outAddress);
} }
defaultExtraData () { defaultExtraData () {
return this._transport return this._provider
.execute('parity_defaultExtraData'); .send('parity_defaultExtraData');
} }
devLogs () { devLogs () {
return this._transport return this._provider
.execute('parity_devLogs'); .send('parity_devLogs');
} }
devLogsLevels () { devLogsLevels () {
return this._transport return this._provider
.execute('parity_devLogsLevels'); .send('parity_devLogsLevels');
} }
deriveAddressHash (address, password, hash, shouldSave) { deriveAddressHash (address, password, hash, shouldSave) {
return this._transport return this._provider
.execute('parity_deriveAddressHash', inAddress(address), password, inDeriveHash(hash), !!shouldSave) .send('parity_deriveAddressHash', inAddress(address), password, inDeriveHash(hash), !!shouldSave)
.then(outAddress); .then(outAddress);
} }
deriveAddressIndex (address, password, index, shouldSave) { deriveAddressIndex (address, password, index, shouldSave) {
return this._transport return this._provider
.execute('parity_deriveAddressIndex', inAddress(address), password, inDeriveIndex(index), !!shouldSave) .send('parity_deriveAddressIndex', inAddress(address), password, inDeriveIndex(index), !!shouldSave)
.then(outAddress); .then(outAddress);
} }
dropNonReservedPeers () { dropNonReservedPeers () {
return this._transport return this._provider
.execute('parity_dropNonReservedPeers'); .send('parity_dropNonReservedPeers');
} }
enode () { enode () {
return this._transport return this._provider
.execute('parity_enode'); .send('parity_enode');
} }
encryptMessage (pubkey, data) { encryptMessage (pubkey, data) {
return this._transport return this._provider
.execute('parity_encryptMessage', inHex(pubkey), inHex(data)); .send('parity_encryptMessage', inHex(pubkey), inHex(data));
} }
executeUpgrade () { executeUpgrade () {
return this._transport return this._provider
.execute('parity_executeUpgrade'); .send('parity_executeUpgrade');
} }
exportAccount (address, password) { exportAccount (address, password) {
return this._transport return this._provider
.execute('parity_exportAccount', inAddress(address), password); .send('parity_exportAccount', inAddress(address), password);
} }
extraData () { extraData () {
return this._transport return this._provider
.execute('parity_extraData'); .send('parity_extraData');
} }
futureTransactions () { futureTransactions () {
return this._transport return this._provider
.execute('parity_futureTransactions'); .send('parity_futureTransactions');
} }
gasCeilTarget () { gasCeilTarget () {
return this._transport return this._provider
.execute('parity_gasCeilTarget') .send('parity_gasCeilTarget')
.then(outNumber); .then(outNumber);
} }
gasFloorTarget () { gasFloorTarget () {
return this._transport return this._provider
.execute('parity_gasFloorTarget') .send('parity_gasFloorTarget')
.then(outNumber); .then(outNumber);
} }
gasPriceHistogram () { gasPriceHistogram () {
return this._transport return this._provider
.execute('parity_gasPriceHistogram') .send('parity_gasPriceHistogram')
.then(outHistogram); .then(outHistogram);
} }
generateSecretPhrase () { generateSecretPhrase () {
return this._transport return this._provider
.execute('parity_generateSecretPhrase'); .send('parity_generateSecretPhrase');
} }
getBlockHeaderByNumber (blockNumber = 'latest') { getBlockHeaderByNumber (blockNumber = 'latest') {
return this._transport return this._provider
.execute('parity_getBlockHeaderByNumber', inBlockNumber(blockNumber)) .send('parity_getBlockHeaderByNumber', inBlockNumber(blockNumber))
.then(outBlock); .then(outBlock);
} }
getDappAddresses (dappId) { getDappAddresses (dappId) {
return this._transport return this._provider
.execute('parity_getDappAddresses', dappId) .send('parity_getDappAddresses', dappId)
.then(outAddresses); .then(outAddresses);
} }
getDappDefaultAddress (dappId) { getDappDefaultAddress (dappId) {
return this._transport return this._provider
.execute('parity_getDappDefaultAddress', dappId) .send('parity_getDappDefaultAddress', dappId)
.then(outAddress); .then(outAddress);
} }
getNewDappsAddresses () { getNewDappsAddresses () {
return this._transport return this._provider
.execute('parity_getNewDappsAddresses') .send('parity_getNewDappsAddresses')
.then((addresses) => addresses ? addresses.map(outAddress) : null); .then((addresses) => addresses ? addresses.map(outAddress) : null);
} }
getNewDappsDefaultAddress () { getNewDappsDefaultAddress () {
return this._transport return this._provider
.execute('parity_getNewDappsDefaultAddress') .send('parity_getNewDappsDefaultAddress')
.then(outAddress); .then(outAddress);
} }
getVaultMeta (vaultName) { getVaultMeta (vaultName) {
return this._transport return this._provider
.execute('parity_getVaultMeta', vaultName) .send('parity_getVaultMeta', vaultName)
.then(outVaultMeta); .then(outVaultMeta);
} }
hardwareAccountsInfo () { hardwareAccountsInfo () {
return this._transport return this._provider
.execute('parity_hardwareAccountsInfo') .send('parity_hardwareAccountsInfo')
.then(outHwAccountInfo); .then(outHwAccountInfo);
} }
hashContent (url) { hashContent (url) {
return this._transport return this._provider
.execute('parity_hashContent', url); .send('parity_hashContent', url);
} }
importGethAccounts (accounts) { importGethAccounts (accounts) {
return this._transport return this._provider
.execute('parity_importGethAccounts', inAddresses(accounts)) .send('parity_importGethAccounts', inAddresses(accounts))
.then(outAddresses); .then(outAddresses);
} }
killAccount (account, password) { killAccount (account, password) {
return this._transport return this._provider
.execute('parity_killAccount', inAddress(account), password); .send('parity_killAccount', inAddress(account), password);
} }
listAccounts (count, offset = null, blockNumber = 'latest') { listAccounts (count, offset = null, blockNumber = 'latest') {
return this._transport return this._provider
.execute('parity_listAccounts', count, inAddress(offset), inBlockNumber(blockNumber)) .send('parity_listAccounts', count, inAddress(offset), inBlockNumber(blockNumber))
.then((accounts) => (accounts || []).map(outAddress)); .then((accounts) => (accounts || []).map(outAddress));
} }
listOpenedVaults () { listOpenedVaults () {
return this._transport return this._provider
.execute('parity_listOpenedVaults'); .send('parity_listOpenedVaults');
} }
listVaults () { listVaults () {
return this._transport return this._provider
.execute('parity_listVaults'); .send('parity_listVaults');
} }
listRecentDapps () { listRecentDapps () {
return this._transport return this._provider
.execute('parity_listRecentDapps') .send('parity_listRecentDapps')
.then(outRecentDapps); .then(outRecentDapps);
} }
listStorageKeys (address, count, hash = null, blockNumber = 'latest') { listStorageKeys (address, count, hash = null, blockNumber = 'latest') {
return this._transport return this._provider
.execute('parity_listStorageKeys', inAddress(address), count, inHex(hash), inBlockNumber(blockNumber)); .send('parity_listStorageKeys', inAddress(address), count, inHex(hash), inBlockNumber(blockNumber));
} }
removeAddress (address) { removeAddress (address) {
return this._transport return this._provider
.execute('parity_removeAddress', inAddress(address)); .send('parity_removeAddress', inAddress(address));
} }
listGethAccounts () { listGethAccounts () {
return this._transport return this._provider
.execute('parity_listGethAccounts') .send('parity_listGethAccounts')
.then(outAddresses); .then(outAddresses);
} }
localTransactions () { localTransactions () {
return this._transport return this._provider
.execute('parity_localTransactions') .send('parity_localTransactions')
.then(transactions => { .then(transactions => {
Object.values(transactions) Object.values(transactions)
.filter(tx => tx.transaction) .filter(tx => tx.transaction)
@ -306,263 +306,263 @@ export default class Parity {
} }
minGasPrice () { minGasPrice () {
return this._transport return this._provider
.execute('parity_minGasPrice') .send('parity_minGasPrice')
.then(outNumber); .then(outNumber);
} }
mode () { mode () {
return this._transport return this._provider
.execute('parity_mode'); .send('parity_mode');
} }
// DEPRECATED - use chain instead. // DEPRECATED - use chain instead.
netChain () { netChain () {
return this._transport return this._provider
.execute('parity_chain'); .send('parity_chain');
} }
nodeKind () { nodeKind () {
return this._transport return this._provider
.execute('parity_nodeKind') .send('parity_nodeKind')
.then(outNodeKind); .then(outNodeKind);
} }
chain () { chain () {
return this._transport return this._provider
.execute('parity_chain'); .send('parity_chain');
} }
netPeers () { netPeers () {
return this._transport return this._provider
.execute('parity_netPeers') .send('parity_netPeers')
.then(outPeers); .then(outPeers);
} }
netMaxPeers () { netMaxPeers () {
return this._transport return this._provider
.execute('parity_netMaxPeers') .send('parity_netMaxPeers')
.then(outNumber); .then(outNumber);
} }
netPort () { netPort () {
return this._transport return this._provider
.execute('parity_netPort') .send('parity_netPort')
.then(outNumber); .then(outNumber);
} }
newAccountFromPhrase (phrase, password) { newAccountFromPhrase (phrase, password) {
return this._transport return this._provider
.execute('parity_newAccountFromPhrase', phrase, password) .send('parity_newAccountFromPhrase', phrase, password)
.then(outAddress); .then(outAddress);
} }
newAccountFromSecret (secret, password) { newAccountFromSecret (secret, password) {
return this._transport return this._provider
.execute('parity_newAccountFromSecret', inHex(secret), password) .send('parity_newAccountFromSecret', inHex(secret), password)
.then(outAddress); .then(outAddress);
} }
newAccountFromWallet (json, password) { newAccountFromWallet (json, password) {
return this._transport return this._provider
.execute('parity_newAccountFromWallet', json, password) .send('parity_newAccountFromWallet', json, password)
.then(outAddress); .then(outAddress);
} }
newVault (vaultName, password) { newVault (vaultName, password) {
return this._transport return this._provider
.execute('parity_newVault', vaultName, password); .send('parity_newVault', vaultName, password);
} }
nextNonce (account) { nextNonce (account) {
return this._transport return this._provider
.execute('parity_nextNonce', inAddress(account)) .send('parity_nextNonce', inAddress(account))
.then(outNumber); .then(outNumber);
} }
nodeName () { nodeName () {
return this._transport return this._provider
.execute('parity_nodeName'); .send('parity_nodeName');
} }
openVault (vaultName, password) { openVault (vaultName, password) {
return this._transport return this._provider
.execute('parity_openVault', vaultName, password); .send('parity_openVault', vaultName, password);
} }
pendingTransactions () { pendingTransactions () {
return this._transport return this._provider
.execute('parity_pendingTransactions') .send('parity_pendingTransactions')
.then(data => data.map(outTransaction)); .then(data => data.map(outTransaction));
} }
pendingTransactionsStats () { pendingTransactionsStats () {
return this._transport return this._provider
.execute('parity_pendingTransactionsStats'); .send('parity_pendingTransactionsStats');
} }
phraseToAddress (phrase) { phraseToAddress (phrase) {
return this._transport return this._provider
.execute('parity_phraseToAddress', phrase) .send('parity_phraseToAddress', phrase)
.then(outAddress); .then(outAddress);
} }
postSign (address, hash) { postSign (address, hash) {
return this._transport return this._provider
.execute('parity_postSign', inAddress(address), inHex(hash)); .send('parity_postSign', inAddress(address), inHex(hash));
} }
postTransaction (options = {}) { postTransaction (options = {}) {
return this._transport return this._provider
.execute('parity_postTransaction', inOptions(options)); .send('parity_postTransaction', inOptions(options));
} }
registryAddress () { registryAddress () {
return this._transport return this._provider
.execute('parity_registryAddress') .send('parity_registryAddress')
.then(outAddress); .then(outAddress);
} }
releasesInfo () { releasesInfo () {
return this._transport return this._provider
.execute('parity_releasesInfo'); .send('parity_releasesInfo');
} }
removeReservedPeer (enode) { removeReservedPeer (enode) {
return this._transport return this._provider
.execute('parity_removeReservedPeer', enode); .send('parity_removeReservedPeer', enode);
} }
removeTransaction (hash) { removeTransaction (hash) {
return this._transport return this._provider
.execute('parity_removeTransaction', inHex(hash)) .send('parity_removeTransaction', inHex(hash))
.then(outTransaction); .then(outTransaction);
} }
rpcSettings () { rpcSettings () {
return this._transport return this._provider
.execute('parity_rpcSettings'); .send('parity_rpcSettings');
} }
setAccountName (address, name) { setAccountName (address, name) {
return this._transport return this._provider
.execute('parity_setAccountName', inAddress(address), name); .send('parity_setAccountName', inAddress(address), name);
} }
setAccountMeta (address, meta) { setAccountMeta (address, meta) {
return this._transport return this._provider
.execute('parity_setAccountMeta', inAddress(address), JSON.stringify(meta)); .send('parity_setAccountMeta', inAddress(address), JSON.stringify(meta));
} }
setAuthor (address) { setAuthor (address) {
return this._transport return this._provider
.execute('parity_setAuthor', inAddress(address)); .send('parity_setAuthor', inAddress(address));
} }
setDappAddresses (dappId, addresses) { setDappAddresses (dappId, addresses) {
return this._transport return this._provider
.execute('parity_setDappAddresses', dappId, inAddresses(addresses)); .send('parity_setDappAddresses', dappId, inAddresses(addresses));
} }
setDappDefaultAddress (dappId, address) { setDappDefaultAddress (dappId, address) {
return this._transport return this._provider
.execute('parity_setDappDefaultAddress', dappId, address ? inAddress(address) : null); .send('parity_setDappDefaultAddress', dappId, address ? inAddress(address) : null);
} }
setEngineSigner (address, password) { setEngineSigner (address, password) {
return this._transport return this._provider
.execute('parity_setEngineSigner', inAddress(address), password); .send('parity_setEngineSigner', inAddress(address), password);
} }
setExtraData (data) { setExtraData (data) {
return this._transport return this._provider
.execute('parity_setExtraData', inData(data)); .send('parity_setExtraData', inData(data));
} }
setGasCeilTarget (quantity) { setGasCeilTarget (quantity) {
return this._transport return this._provider
.execute('parity_setGasCeilTarget', inNumber16(quantity)); .send('parity_setGasCeilTarget', inNumber16(quantity));
} }
setGasFloorTarget (quantity) { setGasFloorTarget (quantity) {
return this._transport return this._provider
.execute('parity_setGasFloorTarget', inNumber16(quantity)); .send('parity_setGasFloorTarget', inNumber16(quantity));
} }
setMaxTransactionGas (quantity) { setMaxTransactionGas (quantity) {
return this._transport return this._provider
.execute('parity_setMaxTransactionGas', inNumber16(quantity)); .send('parity_setMaxTransactionGas', inNumber16(quantity));
} }
setMinGasPrice (quantity) { setMinGasPrice (quantity) {
return this._transport return this._provider
.execute('parity_setMinGasPrice', inNumber16(quantity)); .send('parity_setMinGasPrice', inNumber16(quantity));
} }
setMode (mode) { setMode (mode) {
return this._transport return this._provider
.execute('parity_setMode', mode); .send('parity_setMode', mode);
} }
setChain (specName) { setChain (specName) {
return this._transport return this._provider
.execute('parity_setChain', specName); .send('parity_setChain', specName);
} }
setNewDappsAddresses (addresses) { setNewDappsAddresses (addresses) {
return this._transport return this._provider
.execute('parity_setNewDappsAddresses', addresses ? inAddresses(addresses) : null); .send('parity_setNewDappsAddresses', addresses ? inAddresses(addresses) : null);
} }
setNewDappsDefaultAddress (address) { setNewDappsDefaultAddress (address) {
return this._transport return this._provider
.execute('parity_setNewDappsDefaultAddress', inAddress(address)); .send('parity_setNewDappsDefaultAddress', inAddress(address));
} }
setTransactionsLimit (quantity) { setTransactionsLimit (quantity) {
return this._transport return this._provider
.execute('parity_setTransactionsLimit', inNumber16(quantity)); .send('parity_setTransactionsLimit', inNumber16(quantity));
} }
setVaultMeta (vaultName, meta) { setVaultMeta (vaultName, meta) {
return this._transport return this._provider
.execute('parity_setVaultMeta', vaultName, JSON.stringify(meta)); .send('parity_setVaultMeta', vaultName, JSON.stringify(meta));
} }
signMessage (address, password, messageHash) { signMessage (address, password, messageHash) {
return this._transport return this._provider
.execute('parity_signMessage', inAddress(address), password, inHex(messageHash)); .send('parity_signMessage', inAddress(address), password, inHex(messageHash));
} }
testPassword (account, password) { testPassword (account, password) {
return this._transport return this._provider
.execute('parity_testPassword', inAddress(account), password); .send('parity_testPassword', inAddress(account), password);
} }
transactionsLimit () { transactionsLimit () {
return this._transport return this._provider
.execute('parity_transactionsLimit') .send('parity_transactionsLimit')
.then(outNumber); .then(outNumber);
} }
unsignedTransactionsCount () { unsignedTransactionsCount () {
return this._transport return this._provider
.execute('parity_unsignedTransactionsCount') .send('parity_unsignedTransactionsCount')
.then(outNumber); .then(outNumber);
} }
upgradeReady () { upgradeReady () {
return this._transport return this._provider
.execute('parity_upgradeReady'); .send('parity_upgradeReady');
} }
versionInfo () { versionInfo () {
return this._transport return this._provider
.execute('parity_versionInfo'); .send('parity_versionInfo');
} }
wsUrl () { wsUrl () {
return this._transport return this._provider
.execute('parity_wsUrl'); .send('parity_wsUrl');
} }
} }

View File

@ -18,10 +18,10 @@ import BigNumber from 'bignumber.js';
import { TEST_HTTP_URL, mockHttp } from '../../../../test/mockRpc'; import { TEST_HTTP_URL, mockHttp } from '../../../../test/mockRpc';
import { isBigNumber } from '../../../../test/types'; import { isBigNumber } from '../../../../test/types';
import Http from '../../transport/http'; import { Http, PromiseWrapper } from '../../provider';
import Parity from './parity'; 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('api/rpc/parity', () => {
describe('accountsInfo', () => { describe('accountsInfo', () => {

View File

@ -18,29 +18,29 @@ import { inAddress, inNumber10, inOptions } from '../../format/input';
import { outAddress } from '../../format/output'; import { outAddress } from '../../format/output';
export default class Personal { export default class Personal {
constructor (transport) { constructor (provider) {
this._transport = transport; this._provider = provider;
} }
listAccounts () { listAccounts () {
return this._transport return this._provider
.execute('personal_listAccounts') .send('personal_listAccounts')
.then((accounts) => (accounts || []).map(outAddress)); .then((accounts) => (accounts || []).map(outAddress));
} }
newAccount (password) { newAccount (password) {
return this._transport return this._provider
.execute('personal_newAccount', password) .send('personal_newAccount', password)
.then(outAddress); .then(outAddress);
} }
sendTransaction (options, password) { sendTransaction (options, password) {
return this._transport return this._provider
.execute('personal_sendTransaction', inOptions(options), password); .send('personal_sendTransaction', inOptions(options), password);
} }
unlockAccount (account, password, duration = 1) { unlockAccount (account, password, duration = 1) {
return this._transport return this._provider
.execute('personal_unlockAccount', inAddress(account), password, inNumber10(duration)); .send('personal_unlockAccount', inAddress(account), password, inNumber10(duration));
} }
} }

View File

@ -16,10 +16,10 @@
import { TEST_HTTP_URL, mockHttp } from '../../../../test/mockRpc'; import { TEST_HTTP_URL, mockHttp } from '../../../../test/mockRpc';
import Http from '../../transport/http'; import { Http, PromiseWrapper } from '../../provider';
import Personal from './personal'; 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', () => { describe('rpc/Personal', () => {
const account = '0x63cf90d3f0410092fc0fca41846f596223979195'; const account = '0x63cf90d3f0410092fc0fca41846f596223979195';

View File

@ -15,57 +15,57 @@
// along with Parity. If not, see <http://www.gnu.org/licenses/>. // along with Parity. If not, see <http://www.gnu.org/licenses/>.
export default class Personal { export default class Personal {
constructor (transport) { constructor (provider) {
this._transport = transport; this._provider = provider;
} }
addToGroup (identity) { addToGroup (identity) {
return this._transport return this._provider
.execute('shh_addToGroup', identity); .send('shh_addToGroup', identity);
} }
getFilterChanges (filterId) { getFilterChanges (filterId) {
return this._transport return this._provider
.execute('shh_getFilterChanges', filterId); .send('shh_getFilterChanges', filterId);
} }
getMessages (filterId) { getMessages (filterId) {
return this._transport return this._provider
.execute('shh_getMessages', filterId); .send('shh_getMessages', filterId);
} }
hasIdentity (identity) { hasIdentity (identity) {
return this._transport return this._provider
.execute('shh_hasIdentity', identity); .send('shh_hasIdentity', identity);
} }
newFilter (options) { newFilter (options) {
return this._transport return this._provider
.execute('shh_newFilter', options); .send('shh_newFilter', options);
} }
newGroup () { newGroup () {
return this._transport return this._provider
.execute('shh_newGroup'); .send('shh_newGroup');
} }
newIdentity () { newIdentity () {
return this._transport return this._provider
.execute('shh_newIdentity'); .send('shh_newIdentity');
} }
post (options) { post (options) {
return this._transport return this._provider
.execute('shh_post', options); .send('shh_post', options);
} }
uninstallFilter (filterId) { uninstallFilter (filterId) {
return this._transport return this._provider
.execute('shh_uninstallFilter', filterId); .send('shh_uninstallFilter', filterId);
} }
version () { version () {
return this._transport return this._provider
.execute('shh_version'); .send('shh_version');
} }
} }

View File

@ -18,48 +18,48 @@ import { inData, inNumber16, inOptions } from '../../format/input';
import { outSignerRequest } from '../../format/output'; import { outSignerRequest } from '../../format/output';
export default class Signer { export default class Signer {
constructor (transport) { constructor (provider) {
this._transport = transport; this._provider = provider;
} }
confirmRequest (requestId, options, password) { confirmRequest (requestId, options, password) {
return this._transport return this._provider
.execute('signer_confirmRequest', inNumber16(requestId), inOptions(options), password); .send('signer_confirmRequest', inNumber16(requestId), inOptions(options), password);
} }
confirmRequestRaw (requestId, data) { confirmRequestRaw (requestId, data) {
return this._transport return this._provider
.execute('signer_confirmRequestRaw', inNumber16(requestId), inData(data)); .send('signer_confirmRequestRaw', inNumber16(requestId), inData(data));
} }
confirmRequestWithToken (requestId, options, password) { confirmRequestWithToken (requestId, options, password) {
return this._transport return this._provider
.execute('signer_confirmRequestWithToken', inNumber16(requestId), inOptions(options), password); .send('signer_confirmRequestWithToken', inNumber16(requestId), inOptions(options), password);
} }
generateAuthorizationToken () { generateAuthorizationToken () {
return this._transport return this._provider
.execute('signer_generateAuthorizationToken'); .send('signer_generateAuthorizationToken');
} }
generateWebProxyAccessToken () { generateWebProxyAccessToken () {
return this._transport return this._provider
.execute('signer_generateWebProxyAccessToken'); .send('signer_generateWebProxyAccessToken');
} }
rejectRequest (requestId) { rejectRequest (requestId) {
return this._transport return this._provider
.execute('signer_rejectRequest', inNumber16(requestId)); .send('signer_rejectRequest', inNumber16(requestId));
} }
requestsToConfirm () { requestsToConfirm () {
return this._transport return this._provider
.execute('signer_requestsToConfirm') .send('signer_requestsToConfirm')
.then((requests) => (requests || []).map(outSignerRequest)); .then((requests) => (requests || []).map(outSignerRequest));
} }
signerEnabled () { signerEnabled () {
return this._transport return this._provider
.execute('signer_signerEnabled'); .send('signer_signerEnabled');
} }
} }

View File

@ -18,49 +18,49 @@ import { inBlockNumber, inData, inHex, inNumber16, inOptions, inTraceFilter, inT
import { outTraces, outTraceReplay } from '../../format/output'; import { outTraces, outTraceReplay } from '../../format/output';
export default class Trace { export default class Trace {
constructor (transport) { constructor (provider) {
this._transport = transport; this._provider = provider;
} }
block (blockNumber = 'latest') { block (blockNumber = 'latest') {
return this._transport return this._provider
.execute('trace_block', inBlockNumber(blockNumber)) .send('trace_block', inBlockNumber(blockNumber))
.then(outTraces); .then(outTraces);
} }
call (options, blockNumber = 'latest', whatTrace = ['trace']) { call (options, blockNumber = 'latest', whatTrace = ['trace']) {
return this._transport return this._provider
.execute('trace_call', inOptions(options), inBlockNumber(blockNumber), inTraceType(whatTrace)) .send('trace_call', inOptions(options), inBlockNumber(blockNumber), inTraceType(whatTrace))
.then(outTraceReplay); .then(outTraceReplay);
} }
filter (filterObj) { filter (filterObj) {
return this._transport return this._provider
.execute('trace_filter', inTraceFilter(filterObj)) .send('trace_filter', inTraceFilter(filterObj))
.then(outTraces); .then(outTraces);
} }
get (txHash, position) { get (txHash, position) {
return this._transport return this._provider
.execute('trace_get', inHex(txHash), inNumber16(position)) .send('trace_get', inHex(txHash), inNumber16(position))
.then(outTraces); .then(outTraces);
} }
rawTransaction (data, whatTrace = ['trace']) { rawTransaction (data, whatTrace = ['trace']) {
return this._transport return this._provider
.execute('trace_rawTransaction', inData(data), inTraceType(whatTrace)) .send('trace_rawTransaction', inData(data), inTraceType(whatTrace))
.then(outTraceReplay); .then(outTraceReplay);
} }
replayTransaction (txHash, whatTrace = ['trace']) { replayTransaction (txHash, whatTrace = ['trace']) {
return this._transport return this._provider
.execute('trace_replayTransaction', txHash, inTraceType(whatTrace)) .send('trace_replayTransaction', txHash, inTraceType(whatTrace))
.then(outTraceReplay); .then(outTraceReplay);
} }
transaction (txHash) { transaction (txHash) {
return this._transport return this._provider
.execute('trace_transaction', inHex(txHash)) .send('trace_transaction', inHex(txHash))
.then(outTraces); .then(outTraces);
} }
} }

View File

@ -16,10 +16,10 @@
import { TEST_HTTP_URL, mockHttp } from '../../../../test/mockRpc'; import { TEST_HTTP_URL, mockHttp } from '../../../../test/mockRpc';
import Http from '../../transport/http'; import { Http, PromiseWrapper } from '../../provider';
import Trace from './trace'; 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', () => { describe('api/rpc/Trace', () => {
let scope; let scope;

View File

@ -17,17 +17,17 @@
import { inHex } from '../../format/input'; import { inHex } from '../../format/input';
export default class Web3 { export default class Web3 {
constructor (transport) { constructor (provider) {
this._transport = transport; this._provider = provider;
} }
clientVersion () { clientVersion () {
return this._transport return this._provider
.execute('web3_clientVersion'); .send('web3_clientVersion');
} }
sha3 (hexStr) { sha3 (hexStr) {
return this._transport return this._provider
.execute('web3_sha3', inHex(hexStr)); .send('web3_sha3', inHex(hexStr));
} }
} }

View File

@ -16,10 +16,10 @@
import { TEST_HTTP_URL, mockHttp } from '../../../../test/mockRpc'; import { TEST_HTTP_URL, mockHttp } from '../../../../test/mockRpc';
import Http from '../../transport/http'; import { Http, PromiseWrapper } from '../../provider';
import Web3 from './web3'; 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', () => { describe('api/rpc/Web3', () => {
let scope; let scope;

View File

@ -67,7 +67,7 @@ describe('api/transport/Http', () => {
scope = mockHttp([{ method: 'eth_call', reply: { result: RESULT } }]); scope = mockHttp([{ method: 'eth_call', reply: { result: RESULT } }]);
return transport return transport
.execute('eth_call', 1, 2, 3, 'test') .execute('eth_call', [1, 2, 3, 'test'])
.then((_result) => { .then((_result) => {
result = _result; result = _result;
}); });

View File

@ -74,7 +74,7 @@ export default class JsonRpcBase extends EventEmitter {
}; };
} }
execute (method, ...params) { execute (method, params) {
return this._middlewareList.then((middlewareList) => { return this._middlewareList.then((middlewareList) => {
for (const middleware of middlewareList) { for (const middleware of middlewareList) {
const res = middleware.handle(method, params); const res = middleware.handle(method, params);

View File

@ -43,19 +43,19 @@ describe('api/transport/Middleware', () => {
}); });
it('Routes requests to 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); expect(num).to.be.equal(100);
}); });
}); });
it('Passes non-mocked requests through', () => { 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); expect(result).to.be.equal(MOCKED);
}); });
}); });
it('Passes mocked requests through, if middleware returns null', () => { 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); expect(result).to.be.equal(MOCKED);
}); });
}); });

View File

@ -60,7 +60,7 @@ describe('api/transport/Ws', () => {
transport = new Ws(TEST_WS_URL); transport = new Ws(TEST_WS_URL);
return transport return transport
.execute('test_anyCall', 1, 2, 3) .execute('test_anyCall', [1, 2, 3])
.then((_result) => { .then((_result) => {
result = _result; result = _result;
}); });

View File

@ -23,7 +23,7 @@ import Api from './api';
import './dev.parity.html'; import './dev.parity.html';
const api = new Api(new Api.Transport.Http('/rpc/')); const api = new Api(new Api.Provider.Http('/rpc/'));
window.parity = { window.parity = {
Api, Api,

View File

@ -30,10 +30,10 @@ export default class SecureApi extends Api {
_dappsUrl = null; _dappsUrl = null;
_wsUrl = null; _wsUrl = null;
static getTransport (url, sysuiToken, protocol) { static getProvider (url, sysuiToken, protocol) {
const proto = protocol() === 'https:' ? 'wss:' : 'ws:'; 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. // Returns a protocol with `:` at the end.
@ -41,11 +41,11 @@ export default class SecureApi extends Api {
return window.location.protocol; 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 sysuiToken = store.get('sysuiToken');
const transport = getTransport(url, sysuiToken, protocol); const provider = getProvider(url, sysuiToken, protocol);
super(transport); super(provider);
this._wsUrl = url; this._wsUrl = url;
this.protocol = protocol; this.protocol = protocol;
@ -55,7 +55,8 @@ export default class SecureApi extends Api {
.map((token) => ({ value: token, tried: false })); .map((token) => ({ value: token, tried: false }));
// When the transport is closed, try to reconnect // 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(); this.connect();
} }
@ -105,7 +106,7 @@ export default class SecureApi extends Api {
} }
get isConnected () { get isConnected () {
return this._transport.isConnected; return this.provider.isConnected;
} }
get needsToken () { get needsToken () {
@ -113,7 +114,7 @@ export default class SecureApi extends Api {
} }
get secureToken () { 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); const token = this._sanitiseToken(_token);
// Update the token in the transport layer // Update the token in the transport layer
this.transport.updateToken(token, false); this.provider.updateToken(token, false);
log.debug('connecting with token', token); log.debug('connecting with token', token);
const connectPromise = this.transport.connect() const connectPromise = this.provider.connect()
.then(() => { .then(() => {
log.debug('connected with', token); log.debug('connected with', token);

View File

@ -23,7 +23,7 @@ import Api from '@parity/api';
import TxRow from './txRow'; import TxRow from './txRow';
const api = new Api({ execute: sinon.stub() }); const api = new Api({ send: sinon.stub() });
const STORE = { const STORE = {
dispatch: sinon.stub(), dispatch: sinon.stub(),

View File

@ -22,7 +22,7 @@ import Api from '@parity/api';
import TxList from './txList'; import TxList from './txList';
const api = new Api({ execute: sinon.stub() }); const api = new Api({ send: sinon.stub() });
const STORE = { const STORE = {
dispatch: sinon.stub(), dispatch: sinon.stub(),

View File

@ -25,9 +25,9 @@ function createApi (transport) {
} }
export function createHttpApi () { export function createHttpApi () {
return createApi(new Api.Transport.Http('http://localhost:8545')); return createApi(new Api.Provider.Http('http://localhost:8545'));
} }
export function createWsApi () { export function createWsApi () {
return createApi(new Api.Transport.Ws('ws://localhost:8546')); return createApi(new Api.Provider.Ws('ws://localhost:8546'));
} }

View File

@ -26,7 +26,7 @@ try {
throw new Error('No Abi'); 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); var api = new Api(transport);
api.eth api.eth