-
Notifications
You must be signed in to change notification settings - Fork 339
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
623 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
ISC License (ISC) | ||
|
||
Copyright 2017-2018 @polkadot/api authors & contributors | ||
|
||
Permission to use, copy, modify, and/or distribute this software for any | ||
purpose with or without fee is hereby granted, provided that the above | ||
copyright notice and this permission notice appear in all copies. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH | ||
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND | ||
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, | ||
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM | ||
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR | ||
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR | ||
PERFORMANCE OF THIS SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
[![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-observable.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 | ||
|
||
An RxJs wrapper around [@polkadot/rpc-core](../rpc-core). | ||
|
||
# Usage | ||
|
||
Installation - | ||
|
||
``` | ||
npm install --save @polkadot/api/rx | ||
``` | ||
|
||
Making rpc calls - | ||
|
||
```javascript | ||
import ApiRx from '@polkadot/api/rx'; | ||
// alternatively | ||
// import { ApiRx } from '@polkadot/api'; | ||
|
||
// initialise via Promise & static create | ||
const api = await ApiRx.create().toPromise(); | ||
|
||
// make a call to retrieve the current network head | ||
api.rpc.chain.newHead().subscribe((header) => { | ||
console.log(`Chain is at #${header.blockNumber}`); | ||
}); | ||
``` | ||
|
||
Subscribing to chain state - | ||
|
||
```javascript | ||
import Api from '@polkadot/api'; | ||
|
||
// initialise via isReady & new | ||
new Api().isReady.subscribe((api) => { | ||
// make a call to retrieve the current network head | ||
api.st.timestamp.now().subscribe((timestamp) => { | ||
console.log(`Current block timestamp ${timestamp}`); | ||
}); | ||
}); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{ | ||
"name": "@polkadot/api", | ||
"version": "0.31.0", | ||
"description": "An RxJS wrapper around the Polkadot JS RPC", | ||
"main": "index.js", | ||
"keywords": [ | ||
"Polkadot", | ||
"RxJs" | ||
], | ||
"author": "Jaco Greeff <jacogr@gmail.com>", | ||
"maintainers": [ | ||
"Jaco Greeff <jacogr@gmail.com>" | ||
], | ||
"contributors": [], | ||
"license": "ISC", | ||
"engines": { | ||
"node": ">=8.0" | ||
}, | ||
"publishConfig": { | ||
"access": "public", | ||
"registry": "https://registry.npmjs.org" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/polkadot-js/api.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/polkadot-js/api/issues" | ||
}, | ||
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/api#readme", | ||
"dependencies": { | ||
"@babel/runtime": "^7.0.0", | ||
"@polkadot/rpc-rx": "^0.31.0", | ||
"@polkadot/rpc-provider": "^0.31.0", | ||
"@polkadot/extrinsics": "^0.31.0", | ||
"@polkadot/storage": "^0.31.0", | ||
"@types/rx": "^4.1.1", | ||
"rxjs": "^6.3.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// Copyright 2017-2018 @polkadot/api authors & contributors | ||
// This software may be modified and distributed under the terms | ||
// of the ISC license. See the LICENSE file for details. | ||
|
||
export { default as ApiRx } from './rx'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright 2017-2018 @polkadot/api authors & contributors | ||
// This software may be modified and distributed under the terms | ||
// of the ISC license. See the LICENSE file for details. | ||
|
||
import { KeyringPair } from '@polkadot/util-keyring/types'; | ||
import { AnyNumber, AnyU8a } from '@polkadot/types/types'; | ||
import { RxApiInterface } from './types'; | ||
|
||
import { Observable } from 'rxjs'; | ||
import { Extrinsic } from '@polkadot/types/index'; | ||
|
||
export default class SubmittableExtrinsic extends Extrinsic { | ||
private _api: RxApiInterface; | ||
|
||
constructor (api: RxApiInterface, extrinsic: Extrinsic) { | ||
super({ | ||
method: extrinsic.method, | ||
signature: extrinsic.signature | ||
}); | ||
|
||
this._api = api; | ||
} | ||
|
||
// TODO needs to be submitAndWatch | ||
send (): Observable<any> { | ||
return this._api.rpc.author.submitExtrinsic(this); | ||
} | ||
|
||
sign (signerPair: KeyringPair, nonce: AnyNumber, blockHash?: AnyU8a): SubmittableExtrinsic { | ||
super.sign(signerPair, nonce, blockHash || this._api.genesisHash); | ||
|
||
return this; | ||
} | ||
} |
Oops, something went wrong.