Skip to content

Commit

Permalink
fix(cli): commands config actualized (#539)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xDmitry authored and StuartGavidia committed Oct 28, 2023
1 parent 2b0de97 commit c3db97d
Show file tree
Hide file tree
Showing 2 changed files with 122 additions and 117 deletions.
36 changes: 35 additions & 1 deletion packages/cli/src/commandsConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,29 @@ const commandsConfig = {
},
],
},
fetch: {
description: 'Fetch cannon package data from an IPFS hash and store it in the local registry.',
arguments: [
{
flags: '<packageName>',
description: 'Name of the package to fetch data for',
},
{
flags: '<ipfsHash>',
description: 'IPFS hash to fetch deployment data from',
},
],
options: [
{
flags: '-c --chain-id <chainId>',
description: 'Chain ID of deployment to fetch',
},
{
flags: '--meta-hash <metaHash>',
description: 'IPFS hash to fetch deployment metadata from',
},
],
},
publish: {
description: 'Publish a Cannon package to the registry',
arguments: [
Expand Down Expand Up @@ -221,12 +244,15 @@ const commandsConfig = {
{
flags: '-t --tags <tags>',
description: 'Comma separated list of labels for your package',
defaultValue: 'latest',
},
{
flags: '--gas-limit <gasLimit>',
description: 'The maximum units of gas spent for the registration transaction',
},
{
flags: '--value <value>',
description: 'Value in wei to send with the transaction',
},
{
flags: '--max-fee-per-gas <maxFeePerGas>',
description: 'The maximum value (in gwei) for the base fee when submitting the registry transaction',
Expand All @@ -239,6 +265,14 @@ const commandsConfig = {
flags: '-q --quiet',
description: 'Only output final JSON object at the end, no human readable output',
},
{
flags: '--include-provisioned',
description: 'Includes provisioned packages when publishing to the registry',
},
{
flags: '--skip-confirm',
description: 'Skip confirmation and package selection prompts',
},
],
},
inspect: {
Expand Down
203 changes: 87 additions & 116 deletions packages/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,142 +327,113 @@ applyCommandsConfig(program.command('alter'), commandsConfig.alter).action(async
});
});

program
.command('fetch')
.description('Fetch cannon package data from an IPFS hash and store it in the local registry.')
.argument('<packageName>', 'Name of the package to fetch data for')
.argument('<ipfsHash>', 'IPFS hash to fetch deployment data from')
.option('-c --chain-id <chainId>', 'Chain ID of deployment to fetch')
.option('--meta-hash <metaHash>', 'IPFS hash to fetch deployment metadata from')
.action(async function (packageName, ipfsHash, options) {
const { fetch } = await import('./commands/fetch');

if (!options.chainId) {
const chainIdPrompt = await prompts({
type: 'number',
name: 'value',
message: 'Please provide the Chain ID for the deployment you want to fetch',
initial: 13370,
});

if (!chainIdPrompt.value) {
console.log('Chain ID is required.');
process.exit(1);
}
applyCommandsConfig(program.command('fetch'), commandsConfig.fetch).action(async function (packageName, ipfsHash, options) {
const { fetch } = await import('./commands/fetch');

if (!options.chainId) {
const chainIdPrompt = await prompts({
type: 'number',
name: 'value',
message: 'Please provide the Chain ID for the deployment you want to fetch',
initial: 13370,
});

options.chainId = chainIdPrompt.value;
if (!chainIdPrompt.value) {
console.log('Chain ID is required.');
process.exit(1);
}

await fetch(packageName, options.chainId, ipfsHash, options.metaHash);
});
options.chainId = chainIdPrompt.value;
}

program
.command('publish')
.description('Publish a Cannon package to the registry')
.argument('<packageName>', 'Name and version of the package to publish')
.option('-n --registry-provider-url [url]', 'RPC endpoint to publish to')
.option('--private-key <key>', 'Private key to use for publishing the registry package')
.option('--chain-id <number>', 'The chain ID of the package to publish')
.option('--preset <preset>', 'The preset of the packages to publish')
.option('-t --tags <tags>', 'Comma separated list of labels for your package')
.option('--gas-limit <gasLimit>', 'The maximum units of gas spent for the registration transaction')
.option('--value <value>', 'Value in wei to send with the transaction')
.option(
'--max-fee-per-gas <maxFeePerGas>',
'The maximum value (in gwei) for the base fee when submitting the registry transaction'
)
.option(
'--max-priority-fee-per-gas <maxPriorityFeePerGas>',
'The maximum value (in gwei) for the miner tip when submitting the registry transaction'
)
.option('-q --quiet', 'Only output final JSON object at the end, no human readable output')
.option('--include-provisioned', 'Includes provisioned packages when publishing to the registry')
.option('--skip-confirm', 'Skip confirmation and package selection prompts')
.action(async function (packageRef, options) {
const { publish } = await import('./commands/publish');

if (!options.chainId) {
const chainIdPrompt = await prompts({
type: 'number',
name: 'value',
message: 'Please provide the Chain ID for the package you want to publish',
initial: 13370,
});
await fetch(packageName, options.chainId, ipfsHash, options.metaHash);
});

if (!chainIdPrompt.value) {
console.log('Chain ID is required.');
process.exit(1);
}
applyCommandsConfig(program.command('publish'), commandsConfig.publish).action(async function (packageRef, options) {
const { publish } = await import('./commands/publish');

options.chainId = chainIdPrompt.value;
}
if (!options.chainId) {
const chainIdPrompt = await prompts({
type: 'number',
name: 'value',
message: 'Please provide the Chain ID for the package you want to publish',
initial: 13370,
});

if (!options.privateKey && !process.env.PRIVATE_KEY) {
const validatePrivateKey = (privateKey: string) => {
if (ethers.utils.isHexString(privateKey)) {
return true;
} else {
if (privateKey.length === 64) {
return ethers.utils.isHexString(`0x${privateKey}`);
}
return false;
}
};
if (!chainIdPrompt.value) {
console.log('Chain ID is required.');
process.exit(1);
}

const keyPrompt = await prompts({
type: 'text',
name: 'value',
message: 'Please provide a Private Key',
style: 'password',
validate: (key) => (!validatePrivateKey(key) ? 'Private key is not valid' : true),
});
options.chainId = chainIdPrompt.value;
}

if (!keyPrompt.value) {
console.log('Private Key is required.');
process.exit(1);
if (!options.privateKey && !process.env.PRIVATE_KEY) {
const validatePrivateKey = (privateKey: string) => {
if (ethers.utils.isHexString(privateKey)) {
return true;
} else {
if (privateKey.length === 64) {
return ethers.utils.isHexString(`0x${privateKey}`);
}
return false;
}
};

const keyPrompt = await prompts({
type: 'text',
name: 'value',
message: 'Please provide a Private Key',
style: 'password',
validate: (key) => (!validatePrivateKey(key) ? 'Private key is not valid' : true),
});

options.privateKey = keyPrompt.value;
if (!keyPrompt.value) {
console.log('Private Key is required.');
process.exit(1);
}

const cliSettings = resolveCliSettings(options);
const p = await resolveRegistryProvider(cliSettings);
options.privateKey = keyPrompt.value;
}

const overrides: ethers.PayableOverrides = {};
const cliSettings = resolveCliSettings(options);
const p = await resolveRegistryProvider(cliSettings);

if (options.maxFeePerGas) {
overrides.maxFeePerGas = ethers.utils.parseUnits(options.maxFeePerGas, 'gwei');
}
const overrides: ethers.PayableOverrides = {};

if (options.gasLimit) {
overrides.gasLimit = options.gasLimit;
}
if (options.maxFeePerGas) {
overrides.maxFeePerGas = ethers.utils.parseUnits(options.maxFeePerGas, 'gwei');
}

if (options.value) {
overrides.value = options.value;
}
if (options.gasLimit) {
overrides.gasLimit = options.gasLimit;
}

console.log(
`\nSettings:\n - Max Fee Per Gas: ${
overrides.maxFeePerGas ? overrides.maxFeePerGas.toString() : 'default'
}\n - Max Priority Fee Per Gas: ${
overrides.maxPriorityFeePerGas ? overrides.maxPriorityFeePerGas.toString() : 'default'
}\n - Gas Limit: ${overrides.gasLimit ? overrides.gasLimit : 'default'}\n` +
" - To alter these settings use the parameters '--max-fee-per-gas', '--max-priority-fee-per-gas', '--gas-limit'.\n"
);
if (options.value) {
overrides.value = options.value;
}

await publish({
packageRef,
signer: p.signers[0],
tags: options.tags ? options.tags.split(',') : [],
chainId: options.chainId ? Number.parseInt(options.chainId) : undefined,
presetArg: options.preset ? (options.preset as string) : undefined,
quiet: options.quiet,
includeProvisioned: options.includeProvisioned,
skipConfirm: options.skipConfirm,
overrides,
});
console.log(
`\nSettings:\n - Max Fee Per Gas: ${
overrides.maxFeePerGas ? overrides.maxFeePerGas.toString() : 'default'
}\n - Max Priority Fee Per Gas: ${
overrides.maxPriorityFeePerGas ? overrides.maxPriorityFeePerGas.toString() : 'default'
}\n - Gas Limit: ${overrides.gasLimit ? overrides.gasLimit : 'default'}\n` +
" - To alter these settings use the parameters '--max-fee-per-gas', '--max-priority-fee-per-gas', '--gas-limit'.\n"
);

await publish({
packageRef,
signer: p.signers[0],
tags: options.tags ? options.tags.split(',') : [],
chainId: options.chainId ? Number.parseInt(options.chainId) : undefined,
presetArg: options.preset ? (options.preset as string) : undefined,
quiet: options.quiet,
includeProvisioned: options.includeProvisioned,
skipConfirm: options.skipConfirm,
overrides,
});
});

applyCommandsConfig(program.command('inspect'), commandsConfig.inspect).action(async function (packageName, options) {
const { inspect } = await import('./commands/inspect');
Expand Down

0 comments on commit c3db97d

Please sign in to comment.