[Docs] Re-applied lost changes from PR #616 (#623)

* [Docs] Re-applied lost changes from PR #616

* [Docs] Changed submittable extrinsics example to signAndSend()
This commit is contained in:
Stefanie Doll
2019-01-23 13:26:16 +01:00
committed by GitHub
parent 69d92c8f3b
commit 83a1b975ce
3 changed files with 33 additions and 22 deletions
@@ -22,7 +22,7 @@ async function main () {
if (balance[0] === 'first') { if (balance[0] === 'first') {
// Now we know that if the previous value emitted as balance[0] is `first`, // Now we know that if the previous value emitted as balance[0] is `first`,
// then balance[1] is the initial value of Alice account. // then balance[1] is the initial value of Alice account.
console.log(`<b>Alice</b> ${Alice} has a balance of ${balance[1]}`); console.log(`Alice ${Alice} has a balance of ${balance[1]}`);
console.log('You may leave this example running and start the "Make a transfer" example or transfer any value to Alice address'); console.log('You may leave this example running and start the "Make a transfer" example or transfer any value to Alice address');
return; return;
} }
+2 -3
View File
@@ -205,9 +205,8 @@ export default abstract class ApiBase<OnCall> implements ApiBaseInterface<OnCall
* ```javascript * ```javascript
* api.tx.balances * api.tx.balances
* .transfer(<recipientId>, <balance>) * .transfer(<recipientId>, <balance>)
* .sign(<keyPair>, <accountNonce>, <blockHash (optional)>) * .signAndSend(<keyPair>, ({status}) => {
* .send((status) => { * console.log('tx status', status.asFinalised.toHex());
* console.log('tx status', status);
* }); * });
* ``` * ```
*/ */
+30 -18
View File
@@ -48,11 +48,10 @@ import ApiBase from '../Base';
* *
* ```javascript * ```javascript
* import { combineLatest } from 'rxjs'; * import { combineLatest } from 'rxjs';
* import { pairwise, switchMap } from 'rxjs/operators';
* import { ApiRx } from '@polkadot/api'; * import { ApiRx } from '@polkadot/api';
* import { WsProvider } from '@polkadot/rpc-provider'; * import { WsProvider } from '@polkadot/rpc-provider';
* *
* // last block timestamp
* let last = 0;
* *
* // initialise a provider with a specific endpoint * // initialise a provider with a specific endpoint
* const provider = new WsProvider('wss://example.com:9944') * const provider = new WsProvider('wss://example.com:9944')
@@ -64,16 +63,13 @@ import ApiBase from '../Base';
* switchMap((api) => * switchMap((api) =>
* combineLatest([ * combineLatest([
* api.query.timestamp.blockPeriod(), * api.query.timestamp.blockPeriod(),
* api.query.timestamp.now() * api.query.timestamp.now().pipe(pairwise())
* ]) * ])
* )
* ) * )
* .subscribe(([blockPeriod, timestamp]) => { * .subscribe(([blockPeriod, timestamp]) => {
* const elapsed = last * const elapsed = timestamp[1].toNumber() - timestamp[0].toNumber();
* ? `, ${timestamp.toNumber() - last}s since last` * console.log(`timestamp ${timestamp[1]} \nelapsed ${elapsed} \n(${blockPeriod}s target)`);
* : '';
*
* last = timestamp.toNumber();
* console.log(`timestamp ${timestamp}${elapsed} (${blockPeriod}s target)`);
* }); * });
* ``` * ```
* <BR> * <BR>
@@ -82,8 +78,13 @@ import ApiBase from '../Base';
* <BR> * <BR>
* *
* ```javascript * ```javascript
* import { first, switchMap } from 'rxjs/operators';
* import ApiRx from '@polkadot/api/rx'; * import ApiRx from '@polkadot/api/rx';
* *
* // import the test keyring (already has dev keys for Alice, Bob, Charlie, Eve & Ferdie)
* import testingPairs from '@polkadot/keyring/testingPairs';
* const keyring = testingPairs();
*
* // get api via Promise * // get api via Promise
* const api = await ApiRx.create().toPromise(); * const api = await ApiRx.create().toPromise();
* *
@@ -91,6 +92,7 @@ import ApiBase from '../Base';
* api.query.system * api.query.system
* .accountNonce(keyring.alice.address()) * .accountNonce(keyring.alice.address())
* .pipe( * .pipe(
* first(),
* // pipe nonce into transfer * // pipe nonce into transfer
* switchMap((nonce) => * switchMap((nonce) =>
* api.tx.balances * api.tx.balances
@@ -103,8 +105,10 @@ import ApiBase from '../Base';
* ) * )
* ) * )
* // subscribe to overall result * // subscribe to overall result
* .subscribe((hash) => { * .subscribe(({ status, type }) => {
* console.log(`submitted with hash ${hash}`); * if (type === 'Finalised') {
* console.log('Completed at block hash', status.asFinalised.toHex());
* }
* }); * });
* ``` * ```
*/ */
@@ -120,13 +124,17 @@ export default class ApiRx extends ApiBase<OnCall> implements ApiRxInterface {
* <BR> * <BR>
* *
* ```javascript * ```javascript
* import { switchMap } from 'rxjs/operators';
* import Api from '@polkadot/api/rx'; * import Api from '@polkadot/api/rx';
* *
* Api.create().subscribe((api) => { * Api.create()
* api.query.timestamp.now.subscribe((timestamp) => { * .pipe(
* console.log(`lastest block timestamp ${timestamp}`); * switchMap((api) =>
* api.rpc.chain.subscribeNewHead()
* ))
* .subscribe((header) => {
* console.log(`new block #${header.blockNumber.toNumber()}`);
* }); * });
* });
* ``` * ```
*/ */
static create (options?: ApiOptions | ProviderInterface): Observable<ApiRx> { static create (options?: ApiOptions | ProviderInterface): Observable<ApiRx> {
@@ -142,13 +150,17 @@ export default class ApiRx extends ApiBase<OnCall> implements ApiRxInterface {
* <BR> * <BR>
* *
* ```javascript * ```javascript
* import { switchMap } from 'rxjs/operators';
* import Api from '@polkadot/api/rx'; * import Api from '@polkadot/api/rx';
* *
* new Api().isReady.subscribe((api) => { * new Api().isReady
* api.rpc.subscribeNewHead().subscribe((header) => { * .pipe(
* switchMap((api) =>
* api.rpc.chain.subscribeNewHead()
* ))
* .subscribe((header) => {
* console.log(`new block #${header.blockNumber.toNumber()}`); * console.log(`new block #${header.blockNumber.toNumber()}`);
* }); * });
* });
* ``` * ```
*/ */
constructor (provider?: ApiOptions | ProviderInterface) { constructor (provider?: ApiOptions | ProviderInterface) {