API docs -> WS (#141)
* API docs -> WS * API docs update * HttpProvider -> WsProvider * sub<something> -> subscribing * Update dependencies * Test message checks update
This commit is contained in:
@@ -32,7 +32,7 @@
|
||||
"@babel/runtime": "^7.0.0-rc.1",
|
||||
"@polkadot/jsonrpc": "^0.28.22",
|
||||
"@polkadot/primitives": "^0.28.22",
|
||||
"@polkadot/util": "^0.28.7",
|
||||
"@polkadot/util-keyring": "^0.28.7"
|
||||
"@polkadot/util": "^0.28.14",
|
||||
"@polkadot/util-keyring": "^0.28.14"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,9 +23,9 @@ npm install --save @polkadot/api-provider
|
||||
Initialisation -
|
||||
|
||||
```js
|
||||
import HttpProvider from '@polkadot/api-provider/http';
|
||||
import WsProvider from '@polkadot/api-provider/ws';
|
||||
|
||||
const provider = new HttpProvider('http://127.0.0.1:9933');
|
||||
const provider = new WsProvider('http://127.0.0.1:9944');
|
||||
const version = await provider.send('client_version', []);
|
||||
|
||||
console.log('clientVersion', version);
|
||||
|
||||
@@ -35,9 +35,9 @@
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.0.0-rc.1",
|
||||
"@polkadot/storage": "^0.28.22",
|
||||
"@polkadot/util": "^0.28.7",
|
||||
"@polkadot/util-crypto": "^0.28.7",
|
||||
"@polkadot/util-keyring": "^0.28.7",
|
||||
"@polkadot/util": "^0.28.14",
|
||||
"@polkadot/util-crypto": "^0.28.14",
|
||||
"@polkadot/util-keyring": "^0.28.14",
|
||||
"@types/nock": "^9.1.3",
|
||||
"eventemitter3": "^3.1.0",
|
||||
"isomorphic-fetch": "^2.2.1",
|
||||
|
||||
@@ -31,13 +31,13 @@ describe('Http', () => {
|
||||
|
||||
it('does not (yet) support subscribe', () => {
|
||||
return http.subscribe().catch((error) => {
|
||||
expect(error.message).toMatch(/has not been implemented/);
|
||||
expect(error.message).toMatch(/does not have subscriptions/);
|
||||
});
|
||||
});
|
||||
|
||||
it('does not (yet) support unsubscribe', () => {
|
||||
return http.unsubscribe().catch((error) => {
|
||||
expect(error.message).toMatch(/has not been implemented/);
|
||||
expect(error.message).toMatch(/does not have subscriptions/);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -13,6 +13,8 @@ import logger from '@polkadot/util/logger';
|
||||
|
||||
import coder from '../coder/json';
|
||||
|
||||
const ERROR_SUBSCRIBE = 'HTTP Provider does not have subscriptions, use WebSockets instead';
|
||||
|
||||
export default class HttpProvider implements ProviderInterface {
|
||||
private coder: RpcCoder;
|
||||
private endpoint: string;
|
||||
@@ -31,7 +33,7 @@ export default class HttpProvider implements ProviderInterface {
|
||||
}
|
||||
|
||||
on (type: ProviderInterface$Emitted, sub: ProviderInterface$EmitCb): void {
|
||||
this.l.error(`Provider does not have 'on' emitters for type '${type}'`);
|
||||
this.l.error(`HTTP Provider does not have 'on' emitters, use WebSockets instead`);
|
||||
}
|
||||
|
||||
async send (method: string, params: Array<any>): Promise<any> {
|
||||
@@ -54,10 +56,14 @@ export default class HttpProvider implements ProviderInterface {
|
||||
}
|
||||
|
||||
async subscribe (types: string, method: string, params: Array<any>, cb: ProviderInterface$Callback): Promise<number> {
|
||||
throw new Error('Subscriptions has not been implemented');
|
||||
this.l.error(ERROR_SUBSCRIBE);
|
||||
|
||||
throw new Error(ERROR_SUBSCRIBE);
|
||||
}
|
||||
|
||||
async unsubscribe (type: string, method: string, id: number): Promise<boolean> {
|
||||
throw new Error('Subscriptions has not been implemented');
|
||||
this.l.error(ERROR_SUBSCRIBE);
|
||||
|
||||
throw new Error(ERROR_SUBSCRIBE);
|
||||
}
|
||||
}
|
||||
|
||||
+38
-2
@@ -26,9 +26,9 @@ Initialisation -
|
||||
|
||||
```js
|
||||
import createApi from '@polkadot/api';
|
||||
import HttpProvider from '@polkadot/api-provider/http';
|
||||
import WsProvider from '@polkadot/api-provider/ws';
|
||||
|
||||
const provider = new HttpProvider('http://127.0.0.1:9933');
|
||||
const provider = new WsProvider('http://127.0.0.1:9944');
|
||||
const api = createApi(provider);
|
||||
```
|
||||
|
||||
@@ -40,3 +40,39 @@ api.chain
|
||||
.then((header) => console.log(header))
|
||||
.catch((error) => console.error(error));
|
||||
```
|
||||
|
||||
Retrieving the best block (once-off) -
|
||||
|
||||
```js
|
||||
api.chain
|
||||
.getHead()
|
||||
.then((headerHash) => {
|
||||
return api.chain.getHeader(headerHash);
|
||||
})
|
||||
.then((header) => {
|
||||
console.log(`best #${header.number.toString()}`);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error('error:', error);
|
||||
});
|
||||
```
|
||||
|
||||
Retrieving best header via subscription -
|
||||
|
||||
```js
|
||||
api.chain
|
||||
.newHead((error, header) => {
|
||||
if (error) {
|
||||
console.error('error:', error);
|
||||
}
|
||||
|
||||
console.log(`best #${header.number.toString()}`);
|
||||
})
|
||||
.then((subscriptionId) => {
|
||||
// id for the subscription, can unsubscribe via
|
||||
// api.chain.newHead.unsubscribe(subscriptionId)
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error('error subscribing:', error);
|
||||
});
|
||||
```
|
||||
|
||||
@@ -34,6 +34,6 @@
|
||||
"@polkadot/api-provider": "^0.28.22",
|
||||
"@polkadot/jsonrpc": "^0.28.22",
|
||||
"@polkadot/params": "^0.28.22",
|
||||
"@polkadot/util": "^0.28.7"
|
||||
"@polkadot/util": "^0.28.14"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,6 @@
|
||||
"@babel/runtime": "^7.0.0-rc.1",
|
||||
"@polkadot/params": "^0.28.22",
|
||||
"@polkadot/primitives": "^0.28.22",
|
||||
"@polkadot/util": "^0.28.7"
|
||||
"@polkadot/util": "^0.28.14"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
"@polkadot/extrinsics": "^0.28.22",
|
||||
"@polkadot/params": "^0.28.22",
|
||||
"@polkadot/primitives": "^0.28.22",
|
||||
"@polkadot/util": "^0.28.7",
|
||||
"@polkadot/util-keyring": "^0.28.7"
|
||||
"@polkadot/util": "^0.28.14",
|
||||
"@polkadot/util-keyring": "^0.28.14"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,8 +29,8 @@
|
||||
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/type-primitives#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.0.0-rc.1",
|
||||
"@polkadot/trie-hash": "^0.28.7",
|
||||
"@polkadot/util": "^0.28.7"
|
||||
"@polkadot/trie-hash": "^0.28.14",
|
||||
"@polkadot/util": "^0.28.14"
|
||||
},
|
||||
"devDependencies": {
|
||||
"bn.js": "^4.11.8"
|
||||
|
||||
@@ -32,8 +32,8 @@
|
||||
"@babel/runtime": "^7.0.0-rc.1",
|
||||
"@polkadot/params": "^0.28.22",
|
||||
"@polkadot/primitives": "^0.28.22",
|
||||
"@polkadot/util": "^0.28.7",
|
||||
"@polkadot/util-crypto": "^0.28.7",
|
||||
"@polkadot/util-keyring": "^0.28.7"
|
||||
"@polkadot/util": "^0.28.14",
|
||||
"@polkadot/util-crypto": "^0.28.14",
|
||||
"@polkadot/util-keyring": "^0.28.14"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1291,50 +1291,50 @@
|
||||
typedoc-plugin-markdown "^1.1.13"
|
||||
typescript "^3.0.1"
|
||||
|
||||
"@polkadot/trie-hash@^0.28.7":
|
||||
version "0.28.7"
|
||||
resolved "https://registry.yarnpkg.com/@polkadot/trie-hash/-/trie-hash-0.28.7.tgz#c1a91b0f2bf6e579c78d108a8e74cc1718464a5e"
|
||||
"@polkadot/trie-hash@^0.28.14":
|
||||
version "0.28.14"
|
||||
resolved "https://registry.yarnpkg.com/@polkadot/trie-hash/-/trie-hash-0.28.14.tgz#3a044ec108fd8a89e5119b9da8d8f42b73438c67"
|
||||
dependencies:
|
||||
"@babel/runtime" "^7.0.0-rc.1"
|
||||
"@polkadot/util" "^0.28.7"
|
||||
"@polkadot/util-crypto" "^0.28.7"
|
||||
"@polkadot/util-rlp" "^0.28.7"
|
||||
"@polkadot/util" "^0.28.14"
|
||||
"@polkadot/util-crypto" "^0.28.14"
|
||||
"@polkadot/util-rlp" "^0.28.14"
|
||||
|
||||
"@polkadot/ts@^0.1.17":
|
||||
version "0.1.17"
|
||||
resolved "https://registry.yarnpkg.com/@polkadot/ts/-/ts-0.1.17.tgz#0d85085038ae7e6757e059d07c8e9c54596919b3"
|
||||
|
||||
"@polkadot/util-crypto@^0.28.7":
|
||||
version "0.28.7"
|
||||
resolved "https://registry.yarnpkg.com/@polkadot/util-crypto/-/util-crypto-0.28.7.tgz#f75f51be7ba27b21ea4d76e5099f894c16111fc8"
|
||||
"@polkadot/util-crypto@^0.28.14":
|
||||
version "0.28.14"
|
||||
resolved "https://registry.yarnpkg.com/@polkadot/util-crypto/-/util-crypto-0.28.14.tgz#552df2c403f0db0c601614bf2895f119fa7f26aa"
|
||||
dependencies:
|
||||
"@babel/runtime" "^7.0.0-rc.1"
|
||||
"@polkadot/util" "^0.28.7"
|
||||
"@polkadot/util" "^0.28.14"
|
||||
blakejs "^1.1.0"
|
||||
js-sha3 "^0.8.0"
|
||||
tweetnacl "^1.0.0"
|
||||
xxhashjs "^0.2.2"
|
||||
|
||||
"@polkadot/util-keyring@^0.28.7":
|
||||
version "0.28.7"
|
||||
resolved "https://registry.yarnpkg.com/@polkadot/util-keyring/-/util-keyring-0.28.7.tgz#c82390c18e719e57b4f65295e43fff7d7384519f"
|
||||
"@polkadot/util-keyring@^0.28.14":
|
||||
version "0.28.14"
|
||||
resolved "https://registry.yarnpkg.com/@polkadot/util-keyring/-/util-keyring-0.28.14.tgz#924df918e4eb5b476d47c643d40f82f6b7dc4ce1"
|
||||
dependencies:
|
||||
"@babel/runtime" "^7.0.0-rc.1"
|
||||
"@polkadot/util" "^0.28.7"
|
||||
"@polkadot/util-crypto" "^0.28.7"
|
||||
"@polkadot/util" "^0.28.14"
|
||||
"@polkadot/util-crypto" "^0.28.14"
|
||||
"@types/bs58" "^3.0.30"
|
||||
bs58 "^4.0.1"
|
||||
|
||||
"@polkadot/util-rlp@^0.28.7":
|
||||
version "0.28.7"
|
||||
resolved "https://registry.yarnpkg.com/@polkadot/util-rlp/-/util-rlp-0.28.7.tgz#58d6661be3e9b4a66570efe5255776859476ab80"
|
||||
"@polkadot/util-rlp@^0.28.14":
|
||||
version "0.28.14"
|
||||
resolved "https://registry.yarnpkg.com/@polkadot/util-rlp/-/util-rlp-0.28.14.tgz#88cb3912430993bf03c9c7c9838a58c53416f7ed"
|
||||
dependencies:
|
||||
"@babel/runtime" "^7.0.0-rc.1"
|
||||
"@polkadot/util" "^0.28.7"
|
||||
"@polkadot/util" "^0.28.14"
|
||||
|
||||
"@polkadot/util@^0.28.7":
|
||||
version "0.28.7"
|
||||
resolved "https://registry.yarnpkg.com/@polkadot/util/-/util-0.28.7.tgz#abcf4e1735690e6a15a5fe44e5697b2911acf626"
|
||||
"@polkadot/util@^0.28.14":
|
||||
version "0.28.14"
|
||||
resolved "https://registry.yarnpkg.com/@polkadot/util/-/util-0.28.14.tgz#994436b65cb7edbd88820d6a09a187c4438f10a5"
|
||||
dependencies:
|
||||
"@babel/runtime" "^7.0.0-rc.1"
|
||||
"@types/bn.js" "^4.11.1"
|
||||
|
||||
Reference in New Issue
Block a user