Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
mixmix committed Aug 22, 2024
1 parent 014062a commit 5bdfccf
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 28 deletions.
10 changes: 6 additions & 4 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import * as config from './config'
import { cliListAccounts } from './flows/manage-accounts/cli'
import { cliSign } from './flows/sign/cli'

import { cliWrite, passwordOption, endpointOption, currentAccountAddressOption } from './cli/util'
import { entropyProgram } from './cli/commands' // TODO move
import { getSelectedAccount, stringify } from './common/utils'
import { cliWrite, passwordOption, endpointOption, currentAccountAddressOption } from './common/utils-cli'
import { entropyProgramCommand } from './program/command'
import { getSelectedAccount, stringify, } from './common/utils'
import Entropy from '@entropyxyz/sdk'
import { initializeEntropy } from './common/initializeEntropy'
import { BalanceCommand } from './balance/command'
Expand Down Expand Up @@ -57,6 +57,8 @@ program
.env('DEV_MODE')
.hideHelp()
)
// NOTE: I think this hook is gonna need to be on every command? TO BE TESTED
// If it is, then extract the hook fn, and loadEntropy out into src/common/utils-cli.ts
.hook('preAction', async (_thisCommand, actionCommand) => {
if (!entropy || (entropy.keyring.accounts.registration.address !== actionCommand.args[0] || entropy.keyring.accounts.registration.address !== actionCommand.opts().account)) {
// balance includes an address argument, use that address to instantiate entropy
Expand All @@ -78,7 +80,7 @@ program
// entropyBalance(program)
// entropySession(program)
// entropySign(program)
entropyProgram(program)
entropyProgramCommand(entropy, program) // WARNING this has been written to need access to entropy... but that's not defined yet?
// entropyTransfar(program)

/* list */
Expand Down
1 change: 0 additions & 1 deletion src/cli/commands/index.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/cli/util.ts → src/common/utils-cli.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { Option } from 'commander'
import { stringify } from './utils'
import * as config from '../config'
import { stringify } from '../common/utils'

export function cliWrite (result) {
const prettyResult = stringify(result)
process.stdout.write(prettyResult)
}


export function endpointOption () {
return new Option(
'-e, --endpoint <endpoint>',
Expand Down Expand Up @@ -67,4 +68,3 @@ export function aliasOrAddressOption () {
// QUESTION: as this is a function, this could be a viable way to set the VK?
// .default(process.env.ENTROPY_SESSION)
}

1 change: 1 addition & 0 deletions src/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,4 @@ export function getSelectedAccount (accounts: EntropyAccountConfig[], aliasOrAdd
accounts.find(account => account.name === aliasOrAddress)
)
}

28 changes: 7 additions & 21 deletions src/cli/commands/entropy-program.ts → src/program/command.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,19 @@
import { Command } from 'commander'
import { aliasOrAddressOption, cliWrite, endpointOption } from '../util'
import { initializeEntropy } from "../../common/initializeEntropy"
import { getSelectedAccount } from "../../common/utils"
import * as config from "../../config"
import { Entropy } from '@entropyxyz/sdk'
import { aliasOrAddressOption, cliWrite, endpointOption } from '../common/utils-cli'

import { deployProgram } from '../../flows/programs/deploy'
import { deployProgram } from '../flows/programs/deploy'

async function getEntropy ({ address, endpoint }) {
const storedConfig = await config.get()
const selectedAccount = getSelectedAccount(storedConfig.accounts, address)

return initializeEntropy({
keyMaterial: selectedAccount.data,
endpoint
})
}

export function entropyProgram (rootCommand: Command) {
export function entropyProgramCommand (entropy: Entropy, rootCommand: Command) {
const programCommand = rootCommand.command('program')
.description('Commands for working with programs deployed to the Entropy Network')

entropyProgramDeploy(programCommand)
entropyProgramDeploy(entropy, programCommand)
// entropyProgramGet(program)
// entropyProgramRemove(program)
}

function entropyProgramDeploy (programCommand: Command) {
function entropyProgramDeploy (entropy: Entropy, programCommand: Command) {
programCommand.command('deploy')
.description([
'Deploys a program to the Entropy network.',
Expand Down Expand Up @@ -55,9 +43,7 @@ function entropyProgramDeploy (programCommand: Command) {
.addOption(aliasOrAddressOption())
.addOption(endpointOption())

.action(async (bytecodePath, configurationSchemaPath, auxillaryDataSchemaPath, opts) => {
const entropy = await getEntropy(opts)

.action(async (bytecodePath, configurationSchemaPath, auxillaryDataSchemaPath, opts) => { // eslint-disable-line
const pointer = await deployProgram(entropy, {
bytecodePath,
configurationSchemaPath,
Expand Down

0 comments on commit 5bdfccf

Please sign in to comment.