Skip to content
This repository has been archived by the owner on Oct 4, 2024. It is now read-only.

Commit

Permalink
move logic to commands/delete-key.js
Browse files Browse the repository at this point in the history
  • Loading branch information
mikedotexe committed May 22, 2020
1 parent 1dd9530 commit 4691e46
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 23 deletions.
14 changes: 1 addition & 13 deletions bin/near-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,18 +91,6 @@ const stake = {
handler: exitOnError(main.stake)
};

const deleteAccessKey = {
command: 'delete-key [accessKey]',
desc: 'delete access key',
builder: (yargs) => yargs
.option('accessKey', {
desc: 'Public key to delete (base58 encoded)',
type: 'string',
required: true,
}),
handler: exitOnError(main.deleteAccessKey)
};

// For contract:
const deploy = {
command: 'deploy',
Expand Down Expand Up @@ -203,10 +191,10 @@ yargs // eslint-disable-line
.command(sendMoney)
.command(clean)
.command(stake)
.command(deleteAccessKey)
.command(login)
.command(require('../commands/repl'))
.command(require('../commands/generate-key'))
.command(require('../commands/delete-key'))
.command(require('../commands/validators'))
.command(require('../commands/proposals'))
.config(config)
Expand Down
26 changes: 26 additions & 0 deletions commands/delete-key.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const exitOnError = require('../utils/exit-on-error');
const connect = require('../utils/connect');
const eventtracking = require('../utils/eventtracking');
const inspectResponse = require('../utils/inspect-response');

module.exports = {
command: 'delete-key [accessKey]',
desc: 'delete access key',
builder: (yargs) => yargs
.option('accessKey', {
desc: 'Public key to delete (base58 encoded)',
type: 'string',
required: true,
}),
handler: exitOnError(deleteAccessKey)
};

async function deleteAccessKey(options) {
await eventtracking.track(eventtracking.EVENT_ID_DELETE_KEY_START, { node: options.nodeUrl, amount: options.amount });
console.log(`Deleting key = ${options.accessKey} on ${options.accountId}.`);
const near = await connect(options);
const account = await near.account(options.accountId);
const result = await account.deleteKey(options.accessKey);
console.log(inspectResponse(result));
await eventtracking.track(eventtracking.EVENT_ID_DELETE_KEY_END, { node: options.nodeUrl, success: true });
}
10 changes: 0 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,16 +199,6 @@ exports.sendMoney = async function (options) {
await eventtracking.track(eventtracking.EVENT_ID_SEND_TOKENS_END, { node: options.nodeUrl, success: true });
};

exports.deleteAccessKey = async function (options) {
await eventtracking.track(eventtracking.EVENT_ID_DELETE_KEY_START, { node: options.nodeUrl, amount: options.amount });
console.log(`Deleting key = ${options.accessKey} on ${options.accountId}.`);
const near = await connect(options);
const account = await near.account(options.accountId);
const result = await account.deleteKey(options.accessKey);
console.log(inspectResponse(result));
await eventtracking.track(eventtracking.EVENT_ID_DELETE_KEY_END, { node: options.nodeUrl, success: true });
};

exports.stake = async function (options) {
await eventtracking.track(eventtracking.EVENT_ID_STAKE_START, { node: options.nodeUrl, amount: options.amount });
console.log(`Staking ${options.amount} (${utils.format.parseNearAmount(options.amount)}) on ${options.accountId} with public key = ${options.stakingKey}.`);
Expand Down

0 comments on commit 4691e46

Please sign in to comment.