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:
@@ -13,21 +13,23 @@ 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 previous = await api.query.balances.freeBalance(Alice);
|
||||
let [previousNonce, { free: previousFree }] = await api.query.system.account(Alice);
|
||||
|
||||
console.log(`${Alice} has a balance of ${previous}`);
|
||||
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.balances.freeBalance(Alice, (current) => {
|
||||
api.query.system.account(Alice, ([currentNonce, { free: currentFree }]) => {
|
||||
// Calculate the delta
|
||||
const change = current.sub(previous);
|
||||
const change = currentFree.sub(previousFree);
|
||||
|
||||
// Only display positive value changes (Since we are pulling `previous` above already,
|
||||
// the initial balance change will also be zero)
|
||||
if (!change.isZero()) {
|
||||
previous = current;
|
||||
console.log(`New balance change of: ${change}`);
|
||||
console.log(`New balance change of ${change}, nonce ${currentNonce}`);
|
||||
|
||||
previousFree = currentFree;
|
||||
previousNonce = currentNonce;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -15,8 +15,8 @@ async function main () {
|
||||
console.log('Tracking balances for:', [ALICE, BOB]);
|
||||
|
||||
// Subscribe and listen to several balance changes
|
||||
api.query.balances.freeBalance.multi([ALICE, BOB], (balances) => {
|
||||
console.log('Change detected, new balances: ', balances);
|
||||
api.query.system.account.multi([ALICE, BOB], (balances) => {
|
||||
console.log('Change detected, new balances: ', balances.map(([, { free }]) => free));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -12,8 +12,8 @@ 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([
|
||||
api.query.system.accountNonce(ALICE),
|
||||
const [[accountNonce], now, validators] = await Promise.all([
|
||||
api.query.system.account(ALICE),
|
||||
api.query.timestamp.now(),
|
||||
api.query.session.validators()
|
||||
]);
|
||||
@@ -25,14 +25,15 @@ async function main () {
|
||||
// Retrieve the balances for all validators
|
||||
const validatorBalances = await Promise.all(
|
||||
validators.map(authorityId =>
|
||||
api.query.balances.freeBalance(authorityId)
|
||||
api.query.system.account(authorityId)
|
||||
)
|
||||
);
|
||||
|
||||
// Print out the authorityIds and balances of all validators
|
||||
console.log('validators', validators.map((authorityId, index) => ({
|
||||
address: authorityId.toString(),
|
||||
balance: validatorBalances[index].toString()
|
||||
balance: validatorBalances[index][1].free.toString(),
|
||||
nonce: validatorBalances[index][0].toString()
|
||||
})));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,14 +19,14 @@ async function main () {
|
||||
|
||||
// Retrieve the balance at the preceding block for Alice. For at queries
|
||||
// the format is always `.at(<blockhash>, ...params)`
|
||||
const balance = await api.query.balances.freeBalance.at(parentHash, ALICE);
|
||||
const balance = await api.query.system.account.at(parentHash, ALICE);
|
||||
|
||||
console.log(`Alice's balance at ${parentHash.toHex()} was ${balance}`);
|
||||
console.log(`Alice's balance at ${parentHash.toHex()} was ${balance[1].free}`);
|
||||
|
||||
// Now perform a multi query, returning multiple balances at once
|
||||
const balances = await api.query.balances.freeBalance.multi([ALICE, BOB]);
|
||||
const balances = await api.query.system.account.multi([ALICE, BOB]);
|
||||
|
||||
console.log(`Current balances for Alice and Bob are ${balances[0]} and ${balances[1]}`);
|
||||
console.log(`Current balances for Alice and Bob are ${balances[0][1].free} and ${balances[1][1].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.accountNonce(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.accountNonce(ALICE);
|
||||
const [nonce] = await api.query.system.account(ALICE);
|
||||
|
||||
// Find the actual keypair in the keyring
|
||||
const alicePair = keyring.getPair(ALICE);
|
||||
|
||||
Reference in New Issue
Block a user