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

Commit

Permalink
add delete-key command to delete access key
Browse files Browse the repository at this point in the history
  • Loading branch information
mikedotexe committed May 21, 2020
1 parent fc21a38 commit 5ad4ae3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
14 changes: 13 additions & 1 deletion bin/near-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,18 @@ const stake = {
handler: exitOnError(main.stake)
};

const deleteAccessKey = {
command: 'delete-key [publicKey]',
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 All @@ -114,7 +126,6 @@ const callViewFunction = {
handler: exitOnError(main.callViewFunction)
};


const build = {
command: 'build',
desc: 'build your smart contract',
Expand Down Expand Up @@ -192,6 +203,7 @@ yargs // eslint-disable-line
.command(sendMoney)
.command(clean)
.command(stake)
.command(deleteAccessKey)
.command(login)
.command(require('../commands/repl'))
.command(require('../commands/generate-key'))
Expand Down
10 changes: 10 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,16 @@ 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
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 5ad4ae3

Please sign in to comment.