Remove balances.freeBalance & system.accountNonce refs (#1847)

* Remove freeBalance references

* Cleanup placeholders

* Add substrate templates to .gitignore

* Swap all use of system.accountNonce

* typo
This commit is contained in:
Jaco Greeff
2020-02-14 13:52:45 +01:00
committed by GitHub
parent 679e31668e
commit 5c4920db6f
31 changed files with 95 additions and 1703 deletions
+6 -6
View File
@@ -123,14 +123,14 @@ export default abstract class ApiBase<ApiType extends ApiTypes> extends Init<Api
/**
* @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.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.
* 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.account(<accountId>)` (retrieving the associated nonce & balances for an account), takes the `AccountId` as a parameter.
*
* @example
* <BR>
*
* ```javascript
* api.query.balances.freeBalance(<accountId>, (balance) => {
* console.log('new balance', balance);
* api.query.system.account(<accountId>, ([nonce, balance]) => {
* console.log('new free balance', balance.free, 'new nonce', nonce);
* });
* ```
*/
@@ -150,10 +150,10 @@ export default abstract class ApiBase<ApiType extends ApiTypes> extends Init<Api
* // you can include the storage without any parameters
* api.query.balances.totalIssuance,
* // or you can pass parameters to the storage query
* [api.query.balances.freeBalance, '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY']
* [api.query.system.account, '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY']
* ],
* ([existential, balance]) => {
* console.log(`You have ${balance.sub(existential)} more than the existential deposit`);
* ([existential, [, { free }]]) => {
* console.log(`You have ${free.sub(existential)} more than the existential deposit`);
*
* unsub();
* }
+5 -4
View File
@@ -45,16 +45,17 @@ async function query (api: ApiPromise, keyring: TestKeyringMap): Promise<void> {
const override = await api.query.balances.totalIssuance<Header>(); // override is still available
const oldBal = await api.query.balances.totalIssuance.at('abcd');
// It's hard to correctly type .multi. Expected: `Balance[]`, actual: Codec[].
// In the meantime, we can case with `<Balance>`
// In the meantime, we can case with `<Balance>` (this is not available on recent chains)
const multi = await api.query.balances.freeBalance.multi<Balance>([keyring.alice.address, keyring.bob.address]);
console.log('query types:', bar, bal, bal2, override, oldBal, multi);
// check multi for unsub
const multiUnsub = await api.queryMulti([
[api.query.system.accountNonce, keyring.eve.address],
[api.query.system.account, keyring.eve.address],
// older chains only
[api.query.system.accountNonce, keyring.bob.address]
], (balances): void => {
console.log('balances', balances);
], (values): void => {
console.log('values', values);
multiUnsub();
});
+4 -5
View File
@@ -154,7 +154,7 @@ export function decorateMethod<Method extends AnyFunction> (method: Method, opti
* import ApiPromise from '@polkadot/api/promise';
*
* ApiPromise.create().then((api) => {
* const nonce = await api.query.system.accountNonce(keyring.alice.address);
* const [nonce] = await api.query.system.account(keyring.alice.address);
*
* api.tx.balances
* // create transfer
@@ -256,10 +256,9 @@ export default class ApiPromise extends ApiBase<'promise'> {
* // combines values from balance & nonce as it updates
* api.combineLatest([
* api.rpc.chain.subscribeNewHeads,
* [api.query.balances.freeBalance, address],
* (cb) => api.query.system.accountNonce(address, cb)
* ], ([head, balance, nonce]) => {
* console.log(`#${head.number}: You have ${balance} units, with ${nonce} transactions sent`);
* (cb) => api.query.system.account(address, cb)
* ], ([head, [balance, nonce]]) => {
* console.log(`#${head.number}: You have ${balance.free} units, with ${nonce} transactions sent`);
* });
* ```
*/
+2 -2
View File
@@ -91,11 +91,11 @@ export function decorateMethod <Method extends AnyFunction> (method: Method): Me
*
* // retrieve nonce for the account
* api.query.system
* .accountNonce(keyring.alice.address)
* .account(keyring.alice.address)
* .pipe(
* first(),
* // pipe nonce into transfer
* switchMap((nonce) =>
* switchMap(([nonce]) =>
* api.tx.balances
* // create transfer
* .transfer(keyring.bob.address, 12345)