Update docs for system.account (#1944)

This commit is contained in:
Jaco Greeff
2020-02-25 17:01:41 +01:00
committed by GitHub
parent 67841a9212
commit c17f93a3ec
14 changed files with 24 additions and 24 deletions
@@ -13,13 +13,13 @@ async function main () {
// Retrieve the initial balance. Since the call has no callback, it is simply a promise
// that resolves to the current on-chain value
let [previousNonce, { free: previousFree }] = await api.query.system.account(Alice);
let { nonce: previousNonce, data: { free: previousFree } } = await api.query.system.account(Alice);
console.log(`${Alice} has a balance of ${previousFree}, nonce ${previousNonce}`);
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 update the on-screen value
api.query.system.account(Alice, ([currentNonce, { free: currentFree }]) => {
api.query.system.account(Alice, ({ nonce: currentNonce, data: { free: currentFree } }) => {
// Calculate the delta
const change = currentFree.sub(previousFree);
@@ -16,7 +16,7 @@ async function main () {
// Subscribe and listen to several balance changes
api.query.system.account.multi([ALICE, BOB], (balances) => {
console.log('Change detected, new balances: ', balances.map(([, { free }]) => free));
console.log('Change detected, new balances: ', balances.map(({ data: { free } }) => free));
});
}
@@ -12,7 +12,7 @@ async function main () {
const api = await ApiPromise.create();
// Make our basic chain state/storage queries, all in one go
const [[accountNonce], now, validators] = await Promise.all([
const [{ nonce: accountNonce }, now, validators] = await Promise.all([
api.query.system.account(ALICE),
api.query.timestamp.now(),
api.query.session.validators()
@@ -32,8 +32,8 @@ async function main () {
// Print out the authorityIds and balances of all validators
console.log('validators', validators.map((authorityId, index) => ({
address: authorityId.toString(),
balance: validatorBalances[index][1].free.toString(),
nonce: validatorBalances[index][0].toString()
balance: validatorBalances[index].data.free.toHuman(),
nonce: validatorBalances[index].nonce.toHuman()
})));
}
}
@@ -21,12 +21,12 @@ async function main () {
// the format is always `.at(<blockhash>, ...params)`
const balance = await api.query.system.account.at(parentHash, ALICE);
console.log(`Alice's balance at ${parentHash.toHex()} was ${balance[1].free}`);
console.log(`Alice's balance at ${parentHash.toHex()} was ${balance.data.free}`);
// Now perform a multi query, returning multiple balances at once
const balances = await api.query.system.account.multi([ALICE, BOB]);
console.log(`Current balances for Alice and Bob are ${balances[0][1].free} and ${balances[1][1].free}`);
console.log(`Current balances for Alice and Bob are ${balances[0].data.free} and ${balances[1].data.free}`);
}
main().catch(console.error).finally(() => process.exit());
@@ -19,7 +19,7 @@ async function main () {
const alice = keyring.addFromUri('//Alice');
// Get nonce for account
const [nonce] = await api.query.system.account(alice.address);
const [{ nonce } = await api.query.system.account(alice.address);
// Get current block
const signedBlock = await api.rpc.chain.getBlock();
@@ -24,7 +24,7 @@ async function main () {
const keyring = testKeyring.default();
// Get the nonce for the admin key
const [nonce] = await api.query.system.account(ALICE);
const { nonce } = await api.query.system.account(ALICE);
// Find the actual keypair in the keyring
const alicePair = keyring.getPair(ALICE);
@@ -25,12 +25,12 @@ async function main () {
if (balance[0] === '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.
console.log(`Alice ${Alice} has a balance of ${balance[1][1].free}`);
console.log(`Alice ${Alice} has a balance of ${balance[1].data.free}`);
console.log('You may leave this example running and start the "Make a transfer" example or transfer any value to Alice address');
return;
}
const change = balance[1][1].free.sub(balance[0][1].free);
const change = balance[1].data.free.sub(balance[0].date.free);
// Only display value changes
if (!change.isZero()) {
+4 -4
View File
@@ -36,16 +36,16 @@ function main () {
})
)
// Then we're subscribing to the emitted results
.subscribe(([[accountNonce], blockPeriod, validators, validatorBalances]) => {
console.log(`accountNonce(${Alice}) ${accountNonce}`);
.subscribe(([{ nonce }, blockPeriod, validators, validatorBalances]) => {
console.log(`accountNonce(${Alice}) ${nonce}`);
console.log(`blockPeriod ${blockPeriod.toNumber()} seconds`);
if (validatorBalances) {
// And lastly we print out the authorityIds and balances of all validators
console.log('validators', validators.map((authorityId, index) => ({
address: authorityId.toString(),
balance: validatorBalances[index][1].free.toString(),
nonce: validatorBalances[index][0].toString()
balance: validatorBalances[index].data.free.toString(),
nonce: validatorBalances[index].data.toString()
})));
}
});