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

Commit

Permalink
Merge pull request #383 from near/hotfix/353-delete-access-key
Browse files Browse the repository at this point in the history
add delete-key command to delete access key
  • Loading branch information
vgrichina authored May 22, 2020
2 parents fc21a38 + 4691e46 commit 46d3f14
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion bin/near-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ const callViewFunction = {
handler: exitOnError(main.callViewFunction)
};


const build = {
command: 'build',
desc: 'build your smart contract',
Expand Down Expand Up @@ -195,6 +194,7 @@ yargs // eslint-disable-line
.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 });
}
2 changes: 2 additions & 0 deletions utils/eventtracking.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,5 +109,7 @@ module.exports = {
EVENT_ID_REPL_END: 'shell_repl_end',
EVENT_ID_GENERATE_KEY_START: 'shell_generate_key_start',
EVENT_ID_GENERATE_KEY_END: 'shell_id_generate_key_end',
EVENT_ID_DELETE_KEY_START: 'event_id_delete_key_start',
EVENT_ID_DELETE_KEY_END: 'event_id_delete_key_end',
EVENT_ID_ERROR: 'shell_error' // This is not used right now because of mixpanel bug.
};

0 comments on commit 46d3f14

Please sign in to comment.