Rename st -> query (#269)

This commit is contained in:
Jaco Greeff
2018-10-12 16:46:28 +02:00
committed by Amaury Martiny
parent b913ace9be
commit fb528d051c
11 changed files with 22 additions and 22 deletions
@@ -10,13 +10,13 @@ async function main () {
// Retrieve the initial balance. Since the call has no callback, it is simply a promise
// the resolves to the current on-chain value
let previous = await api.st.balances.freeBalance(Alice);
let previous = await api.query.balances.freeBalance(Alice);
console.log(`${Alice} has an ${previous} balance`);
console.log(`You may leave this example running and start example 06 or transfer any value to ${Alice}`);
// Here we subscribe to any balance changes and updates the on-screen value
api.st.balances.freeBalance(Alice, (current) => {
api.query.balances.freeBalance(Alice, (current) => {
// Calculate the delta
const change = current.sub(previous);
@@ -10,9 +10,9 @@ async function main () {
// Make our basic chain state/storage queries, all in one go
const [accountNonce, blockPeriod, validators] = await Promise.all([
api.st.system.accountNonce(Alice),
api.st.timestamp.blockPeriod(),
api.st.session.validators()
api.query.system.accountNonce(Alice),
api.query.timestamp.blockPeriod(),
api.query.session.validators()
]);
console.log(`accountNonce(${Alice}) ${accountNonce}`);
@@ -21,7 +21,7 @@ async function main () {
// get the balances for all validators
const validatorBalances = await Promise.all(
validators.map((authorityId) =>
api.st.balances.freeBalance(authorityId)
api.query.balances.freeBalance(authorityId)
)
);
@@ -17,7 +17,7 @@ async function main () {
const api = await ApiPromise.create();
// retrieve the nonce for Alice, used to sign the transaction
const aliceNonce = await api.st.system.accountNonce(alice.address());
const aliceNonce = await api.query.system.accountNonce(alice.address());
// Create a extrinsic, transferring 12345 units to Bob. We can also create,
// sign and send in one operation (as per the samples in the Api documentation),
+1 -1
View File
@@ -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
+2 -2
View File
@@ -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);
+4 -4
View File
@@ -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}`);
* });
+4 -4
View File
@@ -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)
+1 -1
View File
@@ -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);
+1 -1
View File
@@ -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) =>