Skip to content

Commit

Permalink
added register back to command, specifically to register with default…
Browse files Browse the repository at this point in the history
… program
  • Loading branch information
rh0delta committed Aug 29, 2024
1 parent b013ce3 commit 42a0d67
Showing 1 changed file with 26 additions and 36 deletions.
62 changes: 26 additions & 36 deletions src/account/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { Command, Option } from 'commander'
import { EntropyAccount } from "./main";
import { ACCOUNTS_CONTENT } from './constants'
import * as config from '../config'
import { cliWrite, passwordOption } from "../common/utils-cli";
import { updateConfig } from "src/common/utils";
import { cliWrite, currentAccountAddressOption, endpointOption, passwordOption } from "../common/utils-cli";
import { getSelectedAccount, updateConfig } from "src/common/utils";

export async function entropyAccountCommand (entropy: Entropy, rootCommand: Command) {
const accountCommand = rootCommand.command('account')
Expand All @@ -13,6 +13,7 @@ export async function entropyAccountCommand (entropy: Entropy, rootCommand: Comm
entropyAccountCreate(accountCommand)
entropyAccountImport(accountCommand)
entropyAccountList(accountCommand)
entropyAccountRegister(entropy, accountCommand)
}

function entropyAccountCreate (accountCommand: Command) {
Expand Down Expand Up @@ -96,37 +97,26 @@ function entropyAccountList (accountCommand: Command) {
})
}

/* register */
// program.command('register')
// .description('Register an entropy account with a program')
// .argument('address', 'Address of existing entropy account')
// .addOption(passwordOption())
// .addOption(endpointOption())
// .addOption(
// new Option(
// '-pointer, --pointer',
// 'Program pointer of program to be used for registering'
// )
// )
// .addOption(
// new Option(
// '-data, --program-data',
// 'Path to file containing program data in JSON format'
// )
// )
// .action(async (address, opts) => {
// const storedConfig = await config.get()
// const { accounts } = storedConfig
// const accountsCommand = new EntropyAccount(entropy, opts.endpoint)
// writeOut('Attempting to register account with addtess: ' + address)
// const accountToRegister = getSelectedAccount(accounts, address)
// if (!accountToRegister) {
// throw new Error('AccountError: Unable to register non-existent account')
// }
// const updatedAccount = await accountsCommand.registerAccount(accountToRegister)
// const arrIdx = accounts.indexOf(accountToRegister)
// accounts.splice(arrIdx, 1, updatedAccount)
// await updateConfig(storedConfig, { accounts, selectedAccount: updatedAccount.address })
// writeOut("Your address" + updatedAccount.address + "has been successfully registered.")
// process.exit(0)
// })
function entropyAccountRegister (entropy: Entropy, accountCommand: Command) {
accountCommand.command('register')
.description('Regsiter the currently selected Entropy Account with the default program')
.addOption(passwordOption())
.addOption(endpointOption())
.addOption(currentAccountAddressOption())
.action(async (opts) => {
const AccountService = new EntropyAccount(entropy, opts.endpoint)
const storedConfig = await config.get()
const { accounts } = storedConfig
cliWrite('Attempting to register account with address: ' + opts.account)
const accountToRegister = getSelectedAccount(accounts, opts.account)
// if (!accountToRegister) {
// throw new Error('AccountError: Unable to register non-existent account')
// }
const updatedAccount = await AccountService.registerAccount(accountToRegister)
const arrIdx = accounts.indexOf(accountToRegister)
accounts.splice(arrIdx, 1, updatedAccount)
await updateConfig(storedConfig, { accounts, selectedAccount: updatedAccount.address })
cliWrite("Your address" + updatedAccount.address + "has been successfully registered.")
process.exit(0)
})
}

0 comments on commit 42a0d67

Please sign in to comment.