-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add deploy to CLI, including start of CLI refactor
- Loading branch information
Showing
8 changed files
with
145 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
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 { 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) { | ||
const programCommand = rootCommand.command('program') | ||
.description('Commands for working with programs deployed to the Entropy Network') | ||
|
||
entropyProgramDeploy(programCommand) | ||
// entropyProgramGet(program) | ||
// entropyProgramRemove(program) | ||
} | ||
|
||
function entropyProgramDeploy (programCommand: Command) { | ||
programCommand.command('deploy') | ||
.description([ | ||
'Deploys a program to the Entropy network.', | ||
'Requires funds.' | ||
].join(' ')) | ||
.argument( | ||
'bytecode', | ||
[ | ||
'The path to your program bytecode.', | ||
'Must be a .wasm file.' | ||
].join(' ') | ||
) | ||
.argument( | ||
'configurationSchema', | ||
[ | ||
'The path to the JSON Schema for validating configurations passed in by users installing this program.', | ||
'Must be a .json file.' | ||
].join(' ') | ||
) | ||
.argument( | ||
'auxillaryDataSchema', | ||
[ | ||
'The path to the JSON Schema for validating auxillary data passed to the program on calls to "sign".', | ||
'Must be a .json file.' | ||
].join(' ') | ||
) | ||
.addOption(aliasOrAddressOption()) | ||
.addOption(endpointOption()) | ||
|
||
.action(async (bytecodePath, configurationSchemaPath, auxillaryDataSchemaPath, opts) => { | ||
const entropy = await getEntropy(opts) | ||
|
||
const pointer = await deployProgram(entropy, { | ||
bytecodePath, | ||
configurationSchemaPath, | ||
auxillaryDataSchemaPath | ||
}) | ||
cliWrite(pointer) | ||
|
||
process.exit(0) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './entropy-program' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { Option } from 'commander' | ||
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>', | ||
[ | ||
'Runs entropy with the given endpoint and ignores network endpoints in config.', | ||
'Can also be given a stored endpoint name from config eg: `entropy --endpoint test-net`.' | ||
].join(' ') | ||
) | ||
.env('ENDPOINT') | ||
.argParser(aliasOrEndpoint => { | ||
/* see if it's a raw endpoint */ | ||
if (aliasOrEndpoint.match(/^wss?:\/\//)) return aliasOrEndpoint | ||
|
||
/* look up endpoint-alias */ | ||
const storedConfig = config.getSync() | ||
const endpoint = storedConfig.endpoints[aliasOrEndpoint] | ||
if (!endpoint) throw Error('unknown endpoint alias: ' + aliasOrEndpoint) | ||
|
||
return endpoint | ||
}) | ||
.default('ws://testnet.entropy.xyz:9944/') | ||
// NOTE: argParser is only run IF an option is provided, so this cannot be 'test-net' | ||
} | ||
|
||
export function passwordOption (description?: string) { | ||
return new Option( | ||
'-p, --password <password>', | ||
description || 'Password for the account' | ||
) | ||
} | ||
|
||
export function aliasOrAddressOption () { | ||
return new Option( | ||
'-a, --address <aliasOrAddress>', | ||
'The alias or address of the verifying key to use for this command. Can be an alias or hex address.' | ||
// TODO: describe default behaviour when "sessions" are introduced? | ||
) | ||
// QUESTION: as this is a function, this could be a viable way to set the VK? | ||
// .default(process.env.ENTROPY_SESSION) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters