@polkadot/api/rx (#233)

* api-rx (new)

* Update SubmittableExtrinsic.ts

* Update types.d.ts

* Update index.ts

* Retrieve genesisHash

* extrinsics -> tx, state -> st

* Update index.ts

* Type cleanup

* Update index.ts

* Update index.ts

* Update index.ts

* Sign returns SubmittableExtrinsic

* Example cleanup

* Move to api-rx package

* Add connected/disconnected events

* Expand storage creation

* isReady/isConnected

* Add static create

* Cleanup docs

* Cleanups

* ReplaySubjects

* Basic tests

* Add runtimeVersion

* Test for version, meta & hash

* Package location

* Expand README

* 2 ways of init

* whenReady -> isReady

* api-rx -> api/rx

* Namings
This commit is contained in:
Jaco Greeff
2018-10-10 20:18:48 +02:00
committed by GitHub
parent c30c66e2de
commit 7180f8958e
18 changed files with 623 additions and 44 deletions
+8 -1
View File
@@ -12,7 +12,7 @@ import extrinsicsStatic from '@polkadot/extrinsics/static';
import storageFromMeta from '@polkadot/storage/fromMetadata';
import storageStatic from '@polkadot/storage/static';
import { Vector } from '@polkadot/types/codec';
import { Hash } from '@polkadot/types/index';
import { Hash, Method } from '@polkadot/types/index';
import { StorageFunction } from '@polkadot/types/StorageKey';
import assert from '@polkadot/util/assert';
import isUndefined from '@polkadot/util/is/undefined';
@@ -40,6 +40,8 @@ export default class ApiBase {
static extrinsics = extrinsicsStatic;
static storage = storageStatic;
// FIXME This logic is duplicated in api-rx, since that should derive
// from that base, it should be removed when the actual extend is done
private init (): Promise<boolean> {
let isReady: boolean = false;
@@ -56,9 +58,12 @@ export default class ApiBase {
const meta = await this._api.state.getMetadata().toPromise();
this._genesisHash = await this._api.chain.getBlockHash(0).toPromise();
ApiBase.extrinsics = extrinsicsFromMeta(meta);
ApiBase.storage = storageFromMeta(meta);
Method.injectExtrinsics(ApiBase.extrinsics);
if (!isReady) {
isReady = true;
resolveReady(true);
@@ -97,6 +102,7 @@ export default class ApiBase {
return fn.apply(null, params);
}
// FIXME Remove when extending from api-rx
rawStorage = <T> (key: StorageFunction, ...params: Array<any>): Observable<T | undefined> => {
return this
.rawStorageMulti([key, ...params] as [StorageFunction, any])
@@ -109,6 +115,7 @@ export default class ApiBase {
);
}
// FIXME Remove when extending from api-rx
rawStorageMulti = <T extends []> (...keys: Array<[StorageFunction] | [StorageFunction, any]>): Observable<T> => {
let observable;