From 8187f208ec0fecc45a3c193dc4af888d0a6dfb60 Mon Sep 17 00:00:00 2001 From: Eugene Melnikov Date: Thu, 15 Aug 2019 14:04:49 +0300 Subject: [PATCH] Support private contracts on Quorum --- packages/cli/src/bin/options.ts | 12 ++++++++++++ packages/cli/src/commands/create.ts | 1 + packages/cli/src/commands/create2.ts | 1 + packages/cli/src/commands/freeze.ts | 1 + packages/cli/src/commands/link.ts | 1 + packages/cli/src/commands/publish.ts | 3 ++- packages/cli/src/commands/push.ts | 1 + packages/cli/src/commands/set-admin.ts | 1 + packages/cli/src/commands/unlink.ts | 1 + packages/cli/src/commands/update.ts | 1 + packages/cli/src/models/config/ConfigManager.ts | 3 ++- packages/cli/src/models/network/Session.ts | 1 + 12 files changed, 25 insertions(+), 2 deletions(-) diff --git a/packages/cli/src/bin/options.ts b/packages/cli/src/bin/options.ts index b57fbbed3..51b174844 100644 --- a/packages/cli/src/bin/options.ts +++ b/packages/cli/src/bin/options.ts @@ -1,6 +1,14 @@ import program, { Command } from 'commander'; import { DEFAULT_TX_TIMEOUT } from '../models/network/Session'; +function appender(xs?: string[]) { + xs = xs || []; + return function(x: string) { + xs.push(x); + return xs; + }; +} + program.Command.prototype.withNetworkTimeoutOption = function(): Command { return this.option( '--timeout ', @@ -28,3 +36,7 @@ program.Command.prototype.withNonInteractiveOption = function(): Command { program.Command.prototype.withSkipCompileOption = function(): Command { return this.option('--skip-compile', 'skips contract compilation'); }; + +program.Command.prototype.withPrivateForOption = function(): Command { + return this.option('--privateFor ', 'array of public keys for Quorum networks', appender(), []); +}; diff --git a/packages/cli/src/commands/create.ts b/packages/cli/src/commands/create.ts index d178ada0e..594432ba7 100644 --- a/packages/cli/src/commands/create.ts +++ b/packages/cli/src/commands/create.ts @@ -34,6 +34,7 @@ const register: (program: any) => any = program => .option('--args ', 'provide initialization arguments for your contract if required') .option('--force', 'force creation even if contracts have local modifications') .option('--minimal', 'creates a cheaper but non-upgradeable instance instead, using a minimal proxy') + .withPrivateForOption() .withNetworkOptions() .withSkipCompileOption() .withNonInteractiveOption() diff --git a/packages/cli/src/commands/create2.ts b/packages/cli/src/commands/create2.ts index 461722540..60004dade 100644 --- a/packages/cli/src/commands/create2.ts +++ b/packages/cli/src/commands/create2.ts @@ -36,6 +36,7 @@ const register: (program: any) => any = program => `signature of the request, uses the signer to derive the deployment address (uses the sender to derive deployment address if not set)`, ) .option('--force', 'force creation even if contracts have local modifications') + .withPrivateForOption() .withNetworkOptions() .action(action); diff --git a/packages/cli/src/commands/freeze.ts b/packages/cli/src/commands/freeze.ts index 4f6b79a8b..d72a58ce4 100644 --- a/packages/cli/src/commands/freeze.ts +++ b/packages/cli/src/commands/freeze.ts @@ -10,6 +10,7 @@ const register: (program: any) => any = program => .command(signature, undefined, { noHelp: true }) .usage('--network [options]') .description(description) + .withPrivateForOption() .withNetworkOptions() .action(action); diff --git a/packages/cli/src/commands/link.ts b/packages/cli/src/commands/link.ts index e96f820e7..b9d61c1e9 100644 --- a/packages/cli/src/commands/link.ts +++ b/packages/cli/src/commands/link.ts @@ -15,6 +15,7 @@ const register: (program: any) => any = program => .usage('[dependencyName1 ... dependencyNameN] [options]') .description(description) .option('--no-install', 'skip installing packages dependencies locally') + .withPrivateForOption() .withPushOptions() .withNonInteractiveOption() .action(action); diff --git a/packages/cli/src/commands/publish.ts b/packages/cli/src/commands/publish.ts index 5ec1c6124..e782febf9 100644 --- a/packages/cli/src/commands/publish.ts +++ b/packages/cli/src/commands/publish.ts @@ -13,6 +13,7 @@ const register: (program: any) => any = program => .command(signature, undefined, { noHelp: true }) .usage('--network [options]') .description(description) + .withPrivateForOption() .withNetworkOptions() .withNonInteractiveOption() .action(action); @@ -25,7 +26,7 @@ async function action(options: any): Promise { const props = getCommandProps(); const promptedOpts = await promptIfNeeded({ opts, defaults, props }, interactive); - const { network, txParams } = await ConfigManager.initNetworkConfiguration(promptedOpts); + const { network, txParams } = await ConfigManager.initNetworkConfiguration(Object.assign({}, options, promptedOpts)); if (!(await hasToMigrateProject(network))) process.exit(0); await publish({ network, txParams }); diff --git a/packages/cli/src/commands/push.ts b/packages/cli/src/commands/push.ts index 7796ee3fe..152ab862e 100644 --- a/packages/cli/src/commands/push.ts +++ b/packages/cli/src/commands/push.ts @@ -34,6 +34,7 @@ const register: (program: any) => any = program => '--deploy-proxy-factory', "eagerly deploys the project's proxy factory (if not deployed yet on the provided network)", ) + .withPrivateForOption() .withNetworkOptions() .withNonInteractiveOption() .action(commandActions); diff --git a/packages/cli/src/commands/set-admin.ts b/packages/cli/src/commands/set-admin.ts index 5f613a29a..9c15fedac 100644 --- a/packages/cli/src/commands/set-admin.ts +++ b/packages/cli/src/commands/set-admin.ts @@ -26,6 +26,7 @@ const register: (program: any) => any = program => .usage('[alias-or-address] [new-admin-address] --network [options]') .description(description) .option('--force', 'bypass a manual check') + .withPrivateForOption() .withNetworkOptions() .withNonInteractiveOption() .action(action); diff --git a/packages/cli/src/commands/unlink.ts b/packages/cli/src/commands/unlink.ts index d0717eb3e..e9c0e1ed3 100644 --- a/packages/cli/src/commands/unlink.ts +++ b/packages/cli/src/commands/unlink.ts @@ -12,6 +12,7 @@ const register: (program: any) => any = program => .command(signature, undefined, { noHelp: true }) .usage('[dependencyName1... dependencyNameN]') .description(description) + .withPrivateForOption() .withPushOptions() .withNonInteractiveOption() .action(action); diff --git a/packages/cli/src/commands/update.ts b/packages/cli/src/commands/update.ts index a52552f73..e2513e37b 100644 --- a/packages/cli/src/commands/update.ts +++ b/packages/cli/src/commands/update.ts @@ -36,6 +36,7 @@ const register: (program: any) => any = program => .option('--args ', 'provide initialization arguments for your contract if required') .option('--all', 'upgrade all contracts in the application') .option('--force', 'force creation even if contracts have local modifications') + .withPrivateForOption() .withNetworkOptions() .withSkipCompileOption() .withNonInteractiveOption() diff --git a/packages/cli/src/models/config/ConfigManager.ts b/packages/cli/src/models/config/ConfigManager.ts index dd2221562..81275d5bc 100644 --- a/packages/cli/src/models/config/ConfigManager.ts +++ b/packages/cli/src/models/config/ConfigManager.ts @@ -22,7 +22,7 @@ const ConfigManager = { root: string = process.cwd(), ): Promise<{ network: string; txParams: TxParams } | never> { this.initStaticConfiguration(root); - const { network: networkName, from, timeout } = Session.getOptions(options, silent); + const { network: networkName, from, timeout, privateFor } = Session.getOptions(options, silent); Session.setDefaultNetworkIfNeeded(options.network); if (!networkName) throw Error('A network name must be provided to execute the requested action.'); @@ -38,6 +38,7 @@ const ConfigManager = { const txParams = { from: ZWeb3.toChecksumAddress(from || artifactDefaults.from || (await ZWeb3.defaultAccount())), }; + if (privateFor && privateFor.length > 0) txParams['privateFor'] = privateFor; return { network: await ZWeb3.getNetworkName(), txParams }; } catch (error) { diff --git a/packages/cli/src/models/network/Session.ts b/packages/cli/src/models/network/Session.ts index a0b60581c..eff7730d5 100644 --- a/packages/cli/src/models/network/Session.ts +++ b/packages/cli/src/models/network/Session.ts @@ -18,6 +18,7 @@ interface SessionOptions { from?: string; timeout?: number; expires?: Date; + privateFor?: string[]; } const Session = {