Rename st -> query (#269)
This commit is contained in:
committed by
Amaury Martiny
parent
b913ace9be
commit
fb528d051c
@@ -7,7 +7,7 @@ The API wrappers provide a standard interface for use -
|
||||
- A static `.create(<optional WsProvider>)` that returns an API istance when connected, decorated and ready-to use
|
||||
- The above is just a wrapper for `new Api(<optional WsProvider>) `, exposing the `isReady` getter
|
||||
- `api.rpc.<section>.<method>` provides access to actual RPC calls, be it for queries, submission or retrieving chain information
|
||||
- `api.st.<section>.<method>` provides access to chain state queries. These are dynamically populated based on what the runtime provides
|
||||
- `api.query.<section>.<method>` provides access to chain state queries. These are dynamically populated based on what the runtime provides
|
||||
- `api.tx.<section>.<method>` provides the ability to create transaction, like chain state, this list is populated from a runtime query
|
||||
|
||||
## API Selection
|
||||
|
||||
@@ -115,13 +115,13 @@ export default abstract class ApiBase<R, S, E> implements ApiBaseInterface<R, S,
|
||||
/**
|
||||
* @description Contains all the chain state modules and their subsequent methods in the API. These are attached dynamically from the runtime metadata.
|
||||
*
|
||||
* All calls inside the namespace, is denoted by `section`.`method` and may take an optional query parameter. As an example, `api.st.timestamp.now()` (current block timestamp) does not take parameters, while `api.st.system.accountNonce(<accountId>)` (retrieving the associated nonce for an account), takes the `AccountId` as a parameter.
|
||||
* All calls inside the namespace, is denoted by `section`.`method` and may take an optional query parameter. As an example, `api.query.timestamp.now()` (current block timestamp) does not take parameters, while `api.query.system.accountNonce(<accountId>)` (retrieving the associated nonce for an account), takes the `AccountId` as a parameter.
|
||||
*
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* api.st.balances
|
||||
* api.query.balances
|
||||
* .freeBalance(<accountId>)
|
||||
* .subscribe((balance) => {
|
||||
* console.log('new balance', balance);
|
||||
|
||||
@@ -61,11 +61,11 @@ import { StorageFunction } from '@polkadot/types/StorageKey';
|
||||
* const api = await new ApiPromise(provider).isReady;
|
||||
*
|
||||
* // retrieve the block target time
|
||||
* const blockPeriod = await api.st.timestamp.blockPeriod().toNumber();
|
||||
* const blockPeriod = await api.query.timestamp.blockPeriod().toNumber();
|
||||
* let last = 0;
|
||||
*
|
||||
* // subscribe to the current block timestamp, updates automatically (callback provided)
|
||||
* api.st.timestamp.now((timestamp) => {
|
||||
* api.query.timestamp.now((timestamp) => {
|
||||
* const elapsed = last
|
||||
* ? `, ${timestamp.toNumber() - last}s since last`
|
||||
* : '';
|
||||
@@ -83,7 +83,7 @@ import { StorageFunction } from '@polkadot/types/StorageKey';
|
||||
* import ApiPromise from '@polkadot/api/promise';
|
||||
*
|
||||
* ApiPromise.create().then((api) => {
|
||||
* const nonce = await api.st.system.accountNonce(keyring.alice.address());
|
||||
* const nonce = await api.query.system.accountNonce(keyring.alice.address());
|
||||
*
|
||||
* api.tx.balances
|
||||
* // create transfer
|
||||
@@ -116,7 +116,7 @@ export default class ApiPromise extends ApiBase<Rpc, QueryableStorage, Submittab
|
||||
* import Api from '@polkadot/api/promise';
|
||||
*
|
||||
* Api.create().then(async (api) => {
|
||||
* const timestamp = await api.st.timestamp.now();
|
||||
* const timestamp = await api.query.timestamp.now();
|
||||
*
|
||||
* console.log(`lastest block timestamp ${timestamp}`);
|
||||
* });
|
||||
|
||||
@@ -72,8 +72,8 @@ const l = logger('api-rx');
|
||||
* .pipe(
|
||||
* switchMap((api) =>
|
||||
* combineLatest([
|
||||
* api.st.timestamp.blockPeriod(),
|
||||
* api.st.timestamp.now()
|
||||
* api.query.timestamp.blockPeriod(),
|
||||
* api.query.timestamp.now()
|
||||
* ])
|
||||
* )
|
||||
* .subscribe(([blockPeriod, timestamp]) => {
|
||||
@@ -97,7 +97,7 @@ const l = logger('api-rx');
|
||||
* const api = await ApiRx.create().toPromise();
|
||||
*
|
||||
* // retrieve nonce for the account
|
||||
* api.st.system
|
||||
* api.query.system
|
||||
* .accountNonce(keyring.alice.address())
|
||||
* .pipe(
|
||||
* // pipe nonce into transfer
|
||||
@@ -132,7 +132,7 @@ export default class ApiRx extends ApiBase<RpcRx, QueryableStorage, SubmittableE
|
||||
* import Api from '@polkadot/api/rx';
|
||||
*
|
||||
* Api.create().subscribe((api) => {
|
||||
* api.st.timestamp.now.subscribe((timestamp) => {
|
||||
* api.query.timestamp.now.subscribe((timestamp) => {
|
||||
* console.log(`lastest block timestamp ${timestamp}`);
|
||||
* });
|
||||
* });
|
||||
|
||||
@@ -27,7 +27,7 @@ describe.skip('e2e queries', () => {
|
||||
});
|
||||
|
||||
it('queries state for a balance', async () => {
|
||||
const balance = await api.st.balances.freeBalance(keyring.alice.address());
|
||||
const balance = await api.query.balances.freeBalance(keyring.alice.address());
|
||||
|
||||
expect(
|
||||
balance.isZero()
|
||||
|
||||
@@ -16,7 +16,7 @@ describe.skip('e2e transfer', () => {
|
||||
});
|
||||
|
||||
it('makes a transfer', async () => {
|
||||
const nonce = await api.st.system.accountNonce(keyring.alice.address());
|
||||
const nonce = await api.query.system.accountNonce(keyring.alice.address());
|
||||
const hash = await api.tx.balances
|
||||
.transfer(keyring.bob.address(), 12345)
|
||||
.sign(keyring.alice, nonce)
|
||||
|
||||
@@ -27,7 +27,7 @@ describe.skip('e2e queries', () => {
|
||||
});
|
||||
|
||||
it('queries state for a balance', (done) => {
|
||||
api.st.balances.freeBalance(keyring.alice.address()).subscribe((balance) => {
|
||||
api.query.balances.freeBalance(keyring.alice.address()).subscribe((balance) => {
|
||||
expect(
|
||||
balance.isZero()
|
||||
).toBe(false);
|
||||
|
||||
@@ -17,7 +17,7 @@ describe.skip('e2e transfer', () => {
|
||||
});
|
||||
|
||||
it('makes a transfer', (done) => {
|
||||
api.st.system
|
||||
api.query.system
|
||||
.accountNonce(keyring.alice.address())
|
||||
.pipe(
|
||||
switchMap((nonce) =>
|
||||
|
||||
Reference in New Issue
Block a user