Make Deployer configurable by jsonrpcUrl instead of jsonrpcPort

This commit is contained in:
Leonid Logvinov 2018-03-12 03:19:39 +01:00
parent 7143996d26
commit c4a18ee64b
No known key found for this signature in database
GPG Key ID: 0DD294BFDE8C95D4
8 changed files with 22 additions and 20 deletions

View File

@ -8,7 +8,7 @@ import { runMigrationsAsync } from './migrate';
const deployerOpts = { const deployerOpts = {
artifactsDir: path.resolve('src', 'artifacts'), artifactsDir: path.resolve('src', 'artifacts'),
jsonrpcPort: devConstants.RPC_PORT, jsonrpcUrl: devConstants.RPC_URL,
networkId: constants.TESTRPC_NETWORK_ID, networkId: constants.TESTRPC_NETWORK_ID,
defaults: { defaults: {
gas: devConstants.GAS_ESTIMATE, gas: devConstants.GAS_ESTIMATE,

View File

@ -9,7 +9,7 @@ import { web3 } from './web3_wrapper';
const deployerOpts = { const deployerOpts = {
web3Provider: web3.currentProvider, web3Provider: web3.currentProvider,
artifactsDir: path.resolve('src', 'artifacts'), artifactsDir: path.resolve('src', 'artifacts'),
jsonrpcPort: devConstants.RPC_PORT, jsonrpcUrl: devConstants.RPC_URL,
networkId: constants.TESTRPC_NETWORK_ID, networkId: constants.TESTRPC_NETWORK_ID,
defaults: { defaults: {
gas: devConstants.GAS_ESTIMATE, gas: devConstants.GAS_ESTIMATE,

View File

@ -3,6 +3,8 @@
## v0.3.0 - _TBD, 2018_ ## v0.3.0 - _TBD, 2018_
* Add support for Solidity 0.4.20 and 0.4.21 * Add support for Solidity 0.4.20 and 0.4.21
* Replace `jsonrpcPort` config by `jsonrpcUrl` (#426)
* Replace `jsonrpc-port` CLI option by `jsonrpc-url` (#426)
## v0.2.0 - _March 4, 2018_ ## v0.2.0 - _March 4, 2018_

View File

@ -13,7 +13,7 @@ const DEFAULT_OPTIMIZER_ENABLED = false;
const DEFAULT_CONTRACTS_DIR = path.resolve('src/contracts'); const DEFAULT_CONTRACTS_DIR = path.resolve('src/contracts');
const DEFAULT_ARTIFACTS_DIR = path.resolve('src/artifacts'); const DEFAULT_ARTIFACTS_DIR = path.resolve('src/artifacts');
const DEFAULT_NETWORK_ID = 50; const DEFAULT_NETWORK_ID = 50;
const DEFAULT_JSONRPC_PORT = 8545; const DEFAULT_JSONRPC_URL = 'http://localhost:8545';
const DEFAULT_GAS_PRICE = (10 ** 9 * 2).toString(); const DEFAULT_GAS_PRICE = (10 ** 9 * 2).toString();
const DEFAULT_CONTRACTS_LIST = '*'; const DEFAULT_CONTRACTS_LIST = '*';
@ -36,7 +36,7 @@ async function onCompileCommand(argv: CliOptions): Promise<void> {
* @param argv Instance of process.argv provided by yargs. * @param argv Instance of process.argv provided by yargs.
*/ */
async function onDeployCommand(argv: CliOptions): Promise<void> { async function onDeployCommand(argv: CliOptions): Promise<void> {
const url = `http://localhost:${argv.jsonrpcPort}`; const url = argv.jsonrpcUrl;
const web3Provider = new Web3.providers.HttpProvider(url); const web3Provider = new Web3.providers.HttpProvider(url);
const web3Wrapper = new Web3Wrapper(web3Provider); const web3Wrapper = new Web3Wrapper(web3Provider);
const networkId = await web3Wrapper.getNetworkIdAsync(); const networkId = await web3Wrapper.getNetworkIdAsync();
@ -55,7 +55,7 @@ async function onDeployCommand(argv: CliOptions): Promise<void> {
}; };
const deployerOpts: DeployerOptions = { const deployerOpts: DeployerOptions = {
artifactsDir: argv.artifactsDir, artifactsDir: argv.artifactsDir,
jsonrpcPort: argv.jsonrpcPort, jsonrpcUrl: argv.jsonrpcUrl,
networkId, networkId,
defaults, defaults,
}; };
@ -120,10 +120,10 @@ function deployCommandBuilder(yargsInstance: any) {
default: DEFAULT_ARTIFACTS_DIR, default: DEFAULT_ARTIFACTS_DIR,
description: 'path to write contracts artifacts to', description: 'path to write contracts artifacts to',
}) })
.option('jsonrpc-port', { .option('jsonrpc-url', {
type: 'number', type: 'string',
default: DEFAULT_JSONRPC_PORT, default: DEFAULT_JSONRPC_URL,
description: 'port connected to JSON RPC', description: 'url of JSON RPC',
}) })
.option('gas-price', { .option('gas-price', {
type: 'string', type: 'string',

View File

@ -10,7 +10,7 @@ import {
ContractArtifact, ContractArtifact,
ContractNetworkData, ContractNetworkData,
DeployerOptions, DeployerOptions,
PortDeployerOptions, UrlDeployerOptions,
ProviderDeployerOptions, ProviderDeployerOptions,
} from './utils/types'; } from './utils/types';
import { utils } from './utils/utils'; import { utils } from './utils/utils';
@ -30,13 +30,13 @@ export class Deployer {
this._defaults = opts.defaults; this._defaults = opts.defaults;
let web3Provider: Web3.Provider; let web3Provider: Web3.Provider;
if (_.isUndefined((opts as ProviderDeployerOptions).web3Provider)) { if (_.isUndefined((opts as ProviderDeployerOptions).web3Provider)) {
const jsonrpcPort = (opts as PortDeployerOptions).jsonrpcPort; const jsonrpcUrl = (opts as UrlDeployerOptions).jsonrpcUrl;
if (_.isUndefined(jsonrpcPort)) { if (_.isUndefined(jsonrpcUrl)) {
throw new Error( throw new Error(
`Deployer options don't have neither web3Provider nor jsonrpcPort. Please pass one of them`, `Deployer options don't have neither web3Provider nor jsonrpcUrl. Please pass one of them`,
); );
} }
web3Provider = new Web3.providers.HttpProvider(`http://localhost:${jsonrpcPort}`); web3Provider = new Web3.providers.HttpProvider(jsonrpcUrl);
} else { } else {
web3Provider = (opts as ProviderDeployerOptions).web3Provider; web3Provider = (opts as ProviderDeployerOptions).web3Provider;
} }

View File

@ -41,7 +41,7 @@ export interface SolcErrors {
export interface CliOptions extends yargs.Arguments { export interface CliOptions extends yargs.Arguments {
artifactsDir: string; artifactsDir: string;
contractsDir: string; contractsDir: string;
jsonrpcPort: number; jsonrpcUrl: string;
networkId: number; networkId: number;
shouldOptimize: boolean; shouldOptimize: boolean;
gasPrice: string; gasPrice: string;
@ -68,11 +68,11 @@ export interface ProviderDeployerOptions extends BaseDeployerOptions {
web3Provider: Web3.Provider; web3Provider: Web3.Provider;
} }
export interface PortDeployerOptions extends BaseDeployerOptions { export interface UrlDeployerOptions extends BaseDeployerOptions {
jsonrpcPort: number; jsonrpcUrl: string;
} }
export type DeployerOptions = PortDeployerOptions | ProviderDeployerOptions; export type DeployerOptions = UrlDeployerOptions | ProviderDeployerOptions;
export interface ContractSources { export interface ContractSources {
[key: string]: string; [key: string]: string;

View File

@ -24,7 +24,7 @@ const compiler = new Compiler(compilerOpts);
const deployerOpts = { const deployerOpts = {
artifactsDir, artifactsDir,
networkId: constants.networkId, networkId: constants.networkId,
jsonrpcPort: constants.jsonrpcPort, jsonrpcUrl: constants.jsonrpcUrl,
defaults: { defaults: {
gasPrice: constants.gasPrice, gasPrice: constants.gasPrice,
}, },

View File

@ -2,7 +2,7 @@ import { BigNumber } from '@0xproject/utils';
export const constants = { export const constants = {
networkId: 0, networkId: 0,
jsonrpcPort: 8545, jsonrpcUrl: 'http://localhost:8545',
optimizerEnabled: 0, optimizerEnabled: 0,
gasPrice: new BigNumber(20000000000), gasPrice: new BigNumber(20000000000),
timeoutMs: 20000, timeoutMs: 20000,