Skip to content

Commit

Permalink
fix: Rename account to address in balance increase (#463)
Browse files Browse the repository at this point in the history
* fix: Rename account to address in balance increase

* Rename

* Continue renaming
  • Loading branch information
rzadp authored Mar 1, 2022
1 parent 170b56e commit 831022e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion docs/content/profile-keys-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ address 5EpqhyY9AfHgmrqwFs7tFh3V89ktNamgTP3TWM5zgeQM8y7a
To add funds to a newly created DXNS account using faucet:

```
dx dxns balance increase --faucet https://dxns2.kube.dxos.network/kube/faucet --account 5EpqhyY9AfHgmrqwFs7tFh3V89ktNamgTP3TWM5zgeQM8y7a
dx dxns balance increase --faucet https://dxns2.kube.dxos.network/kube/faucet --address 5EpqhyY9AfHgmrqwFs7tFh3V89ktNamgTP3TWM5zgeQM8y7a
```

To check balance:
Expand Down
16 changes: 8 additions & 8 deletions packages/cli-dxns/src/handlers/balance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ export const getBalance = (params: Params) => async (argv: any) => {
const { getDXNSClient } = params;

const client = await getDXNSClient();
const { account = client.keypair?.address, json } = argv;
const { address = client.keypair?.address, json } = argv;

assert(account, 'Account should be provided.');
assert(address, 'Address should be provided.');

const currentFree = (await client.apiRaw.query.system.account(account)).data.free;
const currentFree = (await client.apiRaw.query.system.account(address)).data.free;

const balance = currentFree.toString();

Expand All @@ -30,16 +30,16 @@ export const increaseBalance = (params: Params) => async (argv: any) => {

const client = await getDXNSClient();
const { apiRaw, keypair, keyring, transactionHandler } = client;
const { account = keypair?.address, amount, mnemonic, json, faucet } = argv;
const { address = keypair?.address, amount, mnemonic, json, faucet } = argv;

assert(account, 'Account should be provided.');
assert(address, 'Address should be provided.');

if (mnemonic) {
const sudoer = keyring.addFromUri(mnemonic.join(' '));

const { free: previousFree, reserved: previousReserved } = (await apiRaw.query.system.account(account)).data;
const { free: previousFree, reserved: previousReserved } = (await apiRaw.query.system.account(address)).data;
const requestedFree = previousFree.add(new BN(amount));
const setBalanceTx = apiRaw.tx.balances.setBalance(account, requestedFree, previousReserved);
const setBalanceTx = apiRaw.tx.balances.setBalance(address, requestedFree, previousReserved);

const { events } = await transactionHandler.sendSudoTransaction(setBalanceTx, sudoer);
const event = events.map((e: any) => e.event).find(apiRaw.events.balances.BalanceSet.is);
Expand All @@ -63,7 +63,7 @@ export const increaseBalance = (params: Params) => async (argv: any) => {
const response = await fetch(faucet, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ account })
body: JSON.stringify({ account: address })
});
const result = await response.json();

Expand Down
12 changes: 6 additions & 6 deletions packages/cli-dxns/src/modules/commands/balance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ export const balanceCommand = (params: Params): CommandModule => ({
handler: () => {},
builder: yargs => yargs
.command({
command: ['get [account]'],
describe: 'Get account balance.',
command: ['get [address]'],
describe: 'Get address balance.',
builder: yargs => yargs
.option('account', { type: 'string' }),
.option('address', { type: 'string' }),

handler: asyncHandler(getBalance(params))
})

.command({
command: ['increase [account]'],
describe: 'Increase account balance.',
command: ['increase [address]'],
describe: 'Increase address balance.',
builder: yargs => yargs
.option('account', { type: 'string' })
.option('address', { type: 'string' })
.option('amount', { type: 'string' })
.option('faucet', { type: 'string' }),

Expand Down

0 comments on commit 831022e

Please sign in to comment.