aboutsummaryrefslogtreecommitdiffstats
path: root/packages/deployer/src/utils
diff options
context:
space:
mode:
Diffstat (limited to 'packages/deployer/src/utils')
-rw-r--r--packages/deployer/src/utils/compiler.ts107
-rw-r--r--packages/deployer/src/utils/constants.ts4
-rw-r--r--packages/deployer/src/utils/contract.ts80
-rw-r--r--packages/deployer/src/utils/encoder.ts18
-rw-r--r--packages/deployer/src/utils/error_reporter.ts18
-rw-r--r--packages/deployer/src/utils/fs_wrapper.ts12
-rw-r--r--packages/deployer/src/utils/types.ts95
-rw-r--r--packages/deployer/src/utils/utils.ts8
8 files changed, 0 insertions, 342 deletions
diff --git a/packages/deployer/src/utils/compiler.ts b/packages/deployer/src/utils/compiler.ts
deleted file mode 100644
index c571b2581..000000000
--- a/packages/deployer/src/utils/compiler.ts
+++ /dev/null
@@ -1,107 +0,0 @@
-import { ContractSource, ContractSources } from '@0xproject/sol-resolver';
-import { logUtils } from '@0xproject/utils';
-import * as _ from 'lodash';
-import * as path from 'path';
-import * as solc from 'solc';
-
-import { constants } from './constants';
-import { fsWrapper } from './fs_wrapper';
-import { ContractArtifact } from './types';
-
-/**
- * Gets contract data on network or returns if an artifact does not exist.
- * @param artifactsDir Path to the artifacts directory.
- * @param contractName Name of contract.
- * @return Contract data on network or undefined.
- */
-export async function getContractArtifactIfExistsAsync(
- artifactsDir: string,
- contractName: string,
-): Promise<ContractArtifact | void> {
- let contractArtifact;
- const currentArtifactPath = `${artifactsDir}/${contractName}.json`;
- try {
- const opts = {
- encoding: 'utf8',
- };
- const contractArtifactString = await fsWrapper.readFileAsync(currentArtifactPath, opts);
- contractArtifact = JSON.parse(contractArtifactString);
- return contractArtifact;
- } catch (err) {
- logUtils.log(`Artifact for ${contractName} does not exist`);
- return undefined;
- }
-}
-
-/**
- * Creates a directory if it does not already exist.
- * @param artifactsDir Path to the directory.
- */
-export async function createDirIfDoesNotExistAsync(dirPath: string): Promise<void> {
- if (!fsWrapper.doesPathExistSync(dirPath)) {
- logUtils.log(`Creating directory at ${dirPath}...`);
- await fsWrapper.mkdirAsync(dirPath);
- }
-}
-
-/**
- * Searches Solidity source code for compiler version range.
- * @param source Source code of contract.
- * @return Solc compiler version range.
- */
-export function parseSolidityVersionRange(source: string): string {
- const SOLIDITY_VERSION_RANGE_REGEX = /pragma\s+solidity\s+(.*);/;
- const solcVersionRangeMatch = source.match(SOLIDITY_VERSION_RANGE_REGEX);
- if (_.isNull(solcVersionRangeMatch)) {
- throw new Error('Could not find Solidity version range in source');
- }
- const solcVersionRange = solcVersionRangeMatch[1];
- return solcVersionRange;
-}
-
-/**
- * Normalizes the path found in the error message.
- * Example: converts 'base/Token.sol:6:46: Warning: Unused local variable'
- * to 'Token.sol:6:46: Warning: Unused local variable'
- * This is used to prevent logging the same error multiple times.
- * @param errMsg An error message from the compiled output.
- * @return The error message with directories truncated from the contract path.
- */
-export function getNormalizedErrMsg(errMsg: string): string {
- const SOLIDITY_FILE_EXTENSION_REGEX = /(.*\.sol)/;
- const errPathMatch = errMsg.match(SOLIDITY_FILE_EXTENSION_REGEX);
- if (_.isNull(errPathMatch)) {
- throw new Error('Could not find a path in error message');
- }
- const errPath = errPathMatch[0];
- const baseContract = path.basename(errPath);
- const normalizedErrMsg = errMsg.replace(errPath, baseContract);
- return normalizedErrMsg;
-}
-
-/**
- * Parses the contract source code and extracts the dendencies
- * @param source Contract source code
- * @return List of dependendencies
- */
-export function parseDependencies(contractSource: ContractSource): string[] {
- // TODO: Use a proper parser
- const source = contractSource.source;
- const IMPORT_REGEX = /(import\s)/;
- const DEPENDENCY_PATH_REGEX = /"([^"]+)"/; // Source: https://github.com/BlockChainCompany/soljitsu/blob/master/lib/shared.js
- const dependencies: string[] = [];
- const lines = source.split('\n');
- _.forEach(lines, line => {
- if (!_.isNull(line.match(IMPORT_REGEX))) {
- const dependencyMatch = line.match(DEPENDENCY_PATH_REGEX);
- if (!_.isNull(dependencyMatch)) {
- let dependencyPath = dependencyMatch[1];
- if (dependencyPath.startsWith('.')) {
- dependencyPath = path.join(path.dirname(contractSource.path), dependencyPath);
- }
- dependencies.push(dependencyPath);
- }
- }
- });
- return dependencies;
-}
diff --git a/packages/deployer/src/utils/constants.ts b/packages/deployer/src/utils/constants.ts
deleted file mode 100644
index 6f9dfb994..000000000
--- a/packages/deployer/src/utils/constants.ts
+++ /dev/null
@@ -1,4 +0,0 @@
-export const constants = {
- SOLIDITY_FILE_EXTENSION: '.sol',
- BASE_COMPILER_URL: 'https://ethereum.github.io/solc-bin/bin/',
-};
diff --git a/packages/deployer/src/utils/contract.ts b/packages/deployer/src/utils/contract.ts
deleted file mode 100644
index e8dd5218a..000000000
--- a/packages/deployer/src/utils/contract.ts
+++ /dev/null
@@ -1,80 +0,0 @@
-import { schemas, SchemaValidator } from '@0xproject/json-schemas';
-import { AbiType, ContractAbi, EventAbi, FunctionAbi, MethodAbi, TxData } from '@0xproject/types';
-import { promisify } from '@0xproject/utils';
-import * as _ from 'lodash';
-import * as Web3 from 'web3';
-
-export class Contract implements Web3.ContractInstance {
- public address: string;
- public abi: ContractAbi;
- private _contract: Web3.ContractInstance;
- private _defaults: Partial<TxData>;
- private _validator: SchemaValidator;
- // This class instance is going to be populated with functions and events depending on the ABI
- // and we don't know their types in advance
- [name: string]: any;
- constructor(web3ContractInstance: Web3.ContractInstance, defaults: Partial<TxData>) {
- this._contract = web3ContractInstance;
- this.address = web3ContractInstance.address;
- this.abi = web3ContractInstance.abi;
- this._defaults = defaults;
- this._populateEvents();
- this._populateFunctions();
- this._validator = new SchemaValidator();
- }
- private _populateFunctions(): void {
- const functionsAbi = _.filter(this.abi, abiPart => abiPart.type === AbiType.Function) as FunctionAbi[];
- _.forEach(functionsAbi, (functionAbi: MethodAbi) => {
- if (functionAbi.constant) {
- const cbStyleCallFunction = this._contract[functionAbi.name].call;
- this[functionAbi.name] = promisify(cbStyleCallFunction, this._contract);
- this[functionAbi.name].call = promisify(cbStyleCallFunction, this._contract);
- } else {
- const cbStyleFunction = this._contract[functionAbi.name];
- const cbStyleCallFunction = this._contract[functionAbi.name].call;
- const cbStyleEstimateGasFunction = this._contract[functionAbi.name].estimateGas;
- this[functionAbi.name] = this._promisifyWithDefaultParams(cbStyleFunction);
- this[functionAbi.name].estimateGasAsync = promisify(cbStyleEstimateGasFunction);
- this[functionAbi.name].sendTransactionAsync = this._promisifyWithDefaultParams(cbStyleFunction);
- this[functionAbi.name].call = promisify(cbStyleCallFunction, this._contract);
- }
- });
- }
- private _populateEvents(): void {
- const eventsAbi = _.filter(this.abi, abiPart => abiPart.type === AbiType.Event) as EventAbi[];
- _.forEach(eventsAbi, (eventAbi: EventAbi) => {
- this[eventAbi.name] = this._contract[eventAbi.name];
- });
- }
- private _promisifyWithDefaultParams(fn: (...args: any[]) => void): (...args: any[]) => Promise<any> {
- const promisifiedWithDefaultParams = async (...args: any[]) => {
- const promise = new Promise((resolve, reject) => {
- const lastArg = args[args.length - 1];
- let txData: Partial<TxData> = {};
- if (this._isTxData(lastArg)) {
- txData = args.pop();
- }
- txData = {
- ...this._defaults,
- ...txData,
- };
- const callback = (err: Error, data: any) => {
- if (_.isNull(err)) {
- resolve(data);
- } else {
- reject(err);
- }
- };
- args.push(txData);
- args.push(callback);
- fn.apply(this._contract, args);
- });
- return promise;
- };
- return promisifiedWithDefaultParams;
- }
- private _isTxData(lastArg: any): boolean {
- const isValid = this._validator.isValid(lastArg, schemas.txDataSchema);
- return isValid;
- }
-}
diff --git a/packages/deployer/src/utils/encoder.ts b/packages/deployer/src/utils/encoder.ts
deleted file mode 100644
index 806efbbca..000000000
--- a/packages/deployer/src/utils/encoder.ts
+++ /dev/null
@@ -1,18 +0,0 @@
-import { AbiDefinition, AbiType, ContractAbi, DataItem } from '@0xproject/types';
-import * as _ from 'lodash';
-import * as web3Abi from 'web3-eth-abi';
-
-export const encoder = {
- encodeConstructorArgsFromAbi(args: any[], abi: ContractAbi): string {
- const constructorTypes: string[] = [];
- _.each(abi, (element: AbiDefinition) => {
- if (element.type === AbiType.Constructor) {
- _.each(element.inputs, (input: DataItem) => {
- constructorTypes.push(input.type);
- });
- }
- });
- const encodedParameters = web3Abi.encodeParameters(constructorTypes, args);
- return encodedParameters;
- },
-};
diff --git a/packages/deployer/src/utils/error_reporter.ts b/packages/deployer/src/utils/error_reporter.ts
deleted file mode 100644
index 4e73307f0..000000000
--- a/packages/deployer/src/utils/error_reporter.ts
+++ /dev/null
@@ -1,18 +0,0 @@
-import { logUtils } from '@0xproject/utils';
-
-/**
- * Makes an async function no-throw printing errors to the console
- * @param asyncFn async function to wrap
- * @return Wrapped version of the passed function
- */
-export function consoleReporter<T>(asyncFn: (arg: T) => Promise<void>): (arg: T) => Promise<void> {
- const noThrowFnAsync = async (arg: T) => {
- try {
- const result = await asyncFn(arg);
- return result;
- } catch (err) {
- logUtils.log(`${err}`);
- }
- };
- return noThrowFnAsync;
-}
diff --git a/packages/deployer/src/utils/fs_wrapper.ts b/packages/deployer/src/utils/fs_wrapper.ts
deleted file mode 100644
index e02c83f27..000000000
--- a/packages/deployer/src/utils/fs_wrapper.ts
+++ /dev/null
@@ -1,12 +0,0 @@
-import { promisify } from '@0xproject/utils';
-import * as fs from 'fs';
-
-export const fsWrapper = {
- readdirAsync: promisify<string[]>(fs.readdir),
- readFileAsync: promisify<string>(fs.readFile),
- writeFileAsync: promisify<undefined>(fs.writeFile),
- mkdirAsync: promisify<undefined>(fs.mkdir),
- doesPathExistSync: fs.existsSync,
- rmdirSync: fs.rmdirSync,
- removeFileAsync: promisify<undefined>(fs.unlink),
-};
diff --git a/packages/deployer/src/utils/types.ts b/packages/deployer/src/utils/types.ts
deleted file mode 100644
index a20d0f627..000000000
--- a/packages/deployer/src/utils/types.ts
+++ /dev/null
@@ -1,95 +0,0 @@
-import { ContractAbi, Provider, TxData } from '@0xproject/types';
-import * as Web3 from 'web3';
-import * as yargs from 'yargs';
-
-export enum AbiType {
- Function = 'function',
- Constructor = 'constructor',
- Event = 'event',
- Fallback = 'fallback',
-}
-
-export interface ContractArtifact {
- contract_name: string;
- networks: ContractNetworks;
-}
-
-export interface ContractNetworks {
- [key: number]: ContractNetworkData;
-}
-
-export interface ContractNetworkData {
- solc_version: string;
- optimizer_enabled: boolean;
- source_tree_hash: string;
- abi: ContractAbi;
- bytecode: string;
- runtime_bytecode: string;
- address?: string;
- constructor_args?: string;
- updated_at: number;
- source_map: string;
- source_map_runtime: string;
- sources: string[];
-}
-
-export interface SolcErrors {
- [key: string]: boolean;
-}
-
-export interface CliOptions extends yargs.Arguments {
- artifactsDir: string;
- contractsDir: string;
- jsonrpcUrl: string;
- networkId: number;
- shouldOptimize: boolean;
- gasPrice: string;
- account?: string;
- contract?: string;
- args?: string;
-}
-
-export interface CompilerOptions {
- contractsDir: string;
- networkId: number;
- optimizerEnabled: boolean;
- artifactsDir: string;
- specifiedContracts: Set<string>;
-}
-
-export interface BaseDeployerOptions {
- artifactsDir: string;
- networkId: number;
- defaults: Partial<TxData>;
-}
-
-export interface ProviderDeployerOptions extends BaseDeployerOptions {
- provider: Provider;
-}
-
-export interface UrlDeployerOptions extends BaseDeployerOptions {
- jsonrpcUrl: string;
-}
-
-export type DeployerOptions = UrlDeployerOptions | ProviderDeployerOptions;
-
-export interface ContractSourceData {
- [contractName: string]: ContractSpecificSourceData;
-}
-
-export interface ContractSpecificSourceData {
- solcVersionRange: string;
- sourceHash: Buffer;
- sourceTreeHash: Buffer;
-}
-
-export interface Token {
- address?: string;
- name: string;
- symbol: string;
- decimals: number;
- ipfsHash: string;
- swarmHash: string;
-}
-
-export type DoneCallback = (err?: Error) => void;
diff --git a/packages/deployer/src/utils/utils.ts b/packages/deployer/src/utils/utils.ts
deleted file mode 100644
index 9b1e59f9d..000000000
--- a/packages/deployer/src/utils/utils.ts
+++ /dev/null
@@ -1,8 +0,0 @@
-export const utils = {
- stringifyWithFormatting(obj: any): string {
- const jsonReplacer: null = null;
- const numberOfJsonSpaces = 4;
- const stringifiedObj = JSON.stringify(obj, jsonReplacer, numberOfJsonSpaces);
- return stringifiedObj;
- },
-};