Add documentation and examples (#145)

* Add documentation

* Justification u8a decoding and json encoding (#146)

* Decode Justifications

* Json encoding for justifications

* Bump deps

* Allow extrinsic length encoding to operate on u8a[] (#148)

* Fix config and move generated doc to a subfolder

* Cleanup extrinsic encoding (#150)

* Cleanup extrinsic encoding

* Removed now-defunct type

* Add uncheckedLength encoding

* Add examples

* Ignore package-lock since we use yarn

* Cleanup examples

* Add gitbook config and some base files for the doc

* Do not make full doc mandatory for now

* Add contributing guide, polish doc and samples

* Update the deps of all samples and add yarn scripts
Fix and regenerate the doc

* Fix Contributing guide
This commit is contained in:
Chevdor
2018-09-15 09:11:56 +02:00
committed by Jaco Greeff
parent 7fffcb3747
commit 0981a30d84
61 changed files with 6937 additions and 105 deletions
+223
View File
@@ -0,0 +1,223 @@
[![polkadotjs](https://img.shields.io/badge/polkadot-js-orange.svg?style=flat-square)](https://polkadot.js.org) ![isc](https://img.shields.io/badge/license-ISC-lightgrey.svg?style=flat-square) [![style](https://img.shields.io/badge/code%20style-semistandard-lightgrey.svg?style=flat-square)](https://github.com/Flet/semistandard) [![npm](https://img.shields.io/npm/v/@polkadot/api.svg?style=flat-square)](https://www.npmjs.com/package/@polkadot/api) [![travis](https://img.shields.io/travis/polkadot-js/api.svg?style=flat-square)](https://travis-ci.org/polkadot-js/api) [![maintainability](https://img.shields.io/codeclimate/maintainability/polkadot-js/api.svg?style=flat-square)](https://codeclimate.com/github/polkadot-js/api/maintainability) [![coverage](https://img.shields.io/coveralls/polkadot-js/api.svg?style=flat-square)](https://coveralls.io/github/polkadot-js/api?branch=master) [![dependency](https://david-dm.org/polkadot-js/api.svg?style=flat-square&path=packages/api)](https://david-dm.org/polkadot-js/api?path=packages/api) [![devDependency](https://david-dm.org/polkadot-js/api/dev-status.svg?style=flat-square&path=packages/api)](https://david-dm.org/polkadot-js/api?path=packages/api#info=devDependencies)
@polkadot/api
=============
Warning - currently this does not actually do all that much, it is an attempt to put into code some thoughts about how to maintain the endpoints. This library provides a clean wrapper around all the methods exposed by a Polkadot network client.
Methods are auto-generated for the [JsonRPC interface definitions](https://github.com/polkadot-js/api/packages/type-jsonrpc), containing a full list of all sections and the methods contained within.
Usage
-----
Installation -
```
npm install --save @polkadot/api
```
Initialisation -
```js
import Api from '@polkadot/api';
import WsProvider from '@polkadot/api-provider/ws';
const provider = new WsProvider('http://127.0.0.1:9944');
const api = new Api(provider);
```
Making calls -
```js
api.chain
.getHeader('0x1234567890')
.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);
});
```
## Index
### Classes
* [Api](classes/api.md)
### Interfaces
* [ApiInterface$Section$Method](interfaces/apiinterface_section_method.md)
### Type aliases
* [ApiInterface](#apiinterface)
* [ApiInterface$Section](#apiinterface_section)
### Functions
* [createInterface](#createinterface)
* [createMethodSend](#createmethodsend)
* [createParams](#createparams)
* [formatResult](#formatresult)
* [methodSubscribe](#methodsubscribe)
---
## Type aliases
<a id="apiinterface"></a>
### ApiInterface
**Ƭ ApiInterface**: *`object`*
*Defined in [types.d.ts:18](https://github.com/chevdor/polkadot-js-api/blob/461228c/packages/api/src/types.d.ts#L18)*
#### Type declaration
___
<a id="apiinterface_section"></a>
### ApiInterface$Section
**Ƭ ApiInterface$Section**: *`object`*
*Defined in [types.d.ts:14](https://github.com/chevdor/polkadot-js-api/blob/461228c/packages/api/src/types.d.ts#L14)*
#### Type declaration
[index: `string`]: [ApiInterface$Section$Method](interfaces/apiinterface_section_method.md)
___
## Functions
<a id="createinterface"></a>
### createInterface
▸ **createInterface**(provider: *`ProviderInterface`*, section: *`Interface$Sections`*): [ApiInterface$Section](#apiinterface_section)
*Defined in [create/interface.ts:16](https://github.com/chevdor/polkadot-js-api/blob/461228c/packages/api/src/create/interface.ts#L16)*
**Parameters:**
| Param | Type |
| ------ | ------ |
| provider | `ProviderInterface` |
| section | `Interface$Sections` |
**Returns:** [ApiInterface$Section](#apiinterface_section)
___
<a id="createmethodsend"></a>
### createMethodSend
▸ **createMethodSend**(provider: *`ProviderInterface`*, rpcName: *`string`*, method: *`SectionItem`<`Interfaces`>*): [ApiInterface$Section$Method](interfaces/apiinterface_section_method.md)
*Defined in [create/methodSend.ts:16](https://github.com/chevdor/polkadot-js-api/blob/461228c/packages/api/src/create/methodSend.ts#L16)*
**Parameters:**
| Param | Type |
| ------ | ------ |
| provider | `ProviderInterface` |
| rpcName | `string` |
| method | `SectionItem`<`Interfaces`> |
**Returns:** [ApiInterface$Section$Method](interfaces/apiinterface_section_method.md)
___
<a id="createparams"></a>
### createParams
▸ **createParams**(params: *`Params`*, values: *`Array`<`any`>*): `Array`<`any`>
*Defined in [create/params.ts:10](https://github.com/chevdor/polkadot-js-api/blob/461228c/packages/api/src/create/params.ts#L10)*
**Parameters:**
| Param | Type |
| ------ | ------ |
| params | `Params` |
| values | `Array`<`any`> |
**Returns:** `Array`<`any`>
___
<a id="formatresult"></a>
### formatResult
▸ **formatResult**(method: *`SectionItem`<`Interfaces`>*, params: *`Array`<`any`>*, inputs: *`Array`<`any`>*, result?: *`any`*): `any`
*Defined in [create/formatResult.ts:16](https://github.com/chevdor/polkadot-js-api/blob/461228c/packages/api/src/create/formatResult.ts#L16)*
**Parameters:**
| Param | Type |
| ------ | ------ |
| method | `SectionItem`<`Interfaces`> |
| params | `Array`<`any`> |
| inputs | `Array`<`any`> |
| `Optional` result | `any` |
**Returns:** `any`
___
<a id="methodsubscribe"></a>
### methodSubscribe
▸ **methodSubscribe**(provider: *`ProviderInterface`*, rpcName: *`string`*, method: *`SectionItem`<`Interfaces`>*): [ApiInterface$Section$Method](interfaces/apiinterface_section_method.md)
*Defined in [create/methodSubscribe.ts:18](https://github.com/chevdor/polkadot-js-api/blob/461228c/packages/api/src/create/methodSubscribe.ts#L18)*
**Parameters:**
| Param | Type |
| ------ | ------ |
| provider | `ProviderInterface` |
| rpcName | `string` |
| method | `SectionItem`<`Interfaces`> |
**Returns:** [ApiInterface$Section$Method](interfaces/apiinterface_section_method.md)
___
+95
View File
@@ -0,0 +1,95 @@
[Polkadot JS API](../README.md) > [Api](../classes/api.md)
# Class: Api
*__example__*: ```javascript
import Api from '@polkadot/api';
import WsProvider from '@polkadot/api-provider/ws';
const provider = new WsProvider('http://127.0.0.1:9944');
const api = new Api(provider);
```
## Hierarchy
**Api**
## Implements
* `object`
## Index
### Constructors
* [constructor](api.md#constructor)
### Properties
* [author](api.md#author)
* [chain](api.md#chain)
* [state](api.md#state)
* [system](api.md#system)
---
## Constructors
<a id="constructor"></a>
### constructor
⊕ **new Api**(provider: *`ProviderInterface`*): [Api](api.md)
*Defined in [index.ts:26](https://github.com/chevdor/polkadot-js-api/blob/461228c/packages/api/src/index.ts#L26)*
*__constructor__*: Default constructor for the Api Object
**Parameters:**
| Param | Type | Description |
| ------ | ------ | ------ |
| provider | `ProviderInterface` | An API provider using HTTP or WebSocket |
**Returns:** [Api](api.md)
___
## Properties
<a id="author"></a>
### author
**● author**: *[ApiInterface$Section](../#apiinterface_section)*
*Defined in [index.ts:23](https://github.com/chevdor/polkadot-js-api/blob/461228c/packages/api/src/index.ts#L23)*
___
<a id="chain"></a>
### chain
**● chain**: *[ApiInterface$Section](../#apiinterface_section)*
*Defined in [index.ts:24](https://github.com/chevdor/polkadot-js-api/blob/461228c/packages/api/src/index.ts#L24)*
___
<a id="state"></a>
### state
**● state**: *[ApiInterface$Section](../#apiinterface_section)*
*Defined in [index.ts:25](https://github.com/chevdor/polkadot-js-api/blob/461228c/packages/api/src/index.ts#L25)*
___
<a id="system"></a>
### system
**● system**: *[ApiInterface$Section](../#apiinterface_section)*
*Defined in [index.ts:26](https://github.com/chevdor/polkadot-js-api/blob/461228c/packages/api/src/index.ts#L26)*
___
@@ -0,0 +1,62 @@
[Polkadot JS API](../README.md) > [ApiInterface$Section$Method](../interfaces/apiinterface_section_method.md)
# Interface: ApiInterface$Section$Method
## Hierarchy
**ApiInterface$Section$Method**
## Callable
▸ **__call**(...params: *`Array`<`any`>*): `Promise`<`any`>
*Defined in [types.d.ts:7](https://github.com/chevdor/polkadot-js-api/blob/461228c/packages/api/src/types.d.ts#L7)*
**Parameters:**
| Param | Type |
| ------ | ------ |
| `Rest` params | `Array`<`any`> |
**Returns:** `Promise`<`any`>
## Index
### Properties
* [subscription](apiinterface_section_method.md#subscription)
* [unsubscribe](apiinterface_section_method.md#unsubscribe)
---
## Properties
<a id="subscription"></a>
### subscription
**● subscription**: *`string`*
*Defined in [types.d.ts:10](https://github.com/chevdor/polkadot-js-api/blob/461228c/packages/api/src/types.d.ts#L10)*
___
<a id="unsubscribe"></a>
### unsubscribe
**● unsubscribe**: *`function`*
*Defined in [types.d.ts:11](https://github.com/chevdor/polkadot-js-api/blob/461228c/packages/api/src/types.d.ts#L11)*
#### Type declaration
▸(id: *`number`*): `Promise`<`any`>
**Parameters:**
| Param | Type |
| ------ | ------ |
| id | `number` |
**Returns:** `Promise`<`any`>
___