aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contracts/deploy/src/deployer.ts
diff options
context:
space:
mode:
authorBrandon Millman <brandon.millman@gmail.com>2017-12-20 13:44:08 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2017-12-20 22:30:25 +0800
commitcb11aec84df346d5180c7d5874859c1c34f0bf1c (patch)
treeb959a65bdcfc3e8b01dca1bc160f93a0df8a4bf9 /packages/contracts/deploy/src/deployer.ts
parent972e1675f6490bc10e8d9fd64cce2f7945cd4840 (diff)
downloaddexon-0x-contracts-cb11aec84df346d5180c7d5874859c1c34f0bf1c.tar.gz
dexon-0x-contracts-cb11aec84df346d5180c7d5874859c1c34f0bf1c.tar.zst
dexon-0x-contracts-cb11aec84df346d5180c7d5874859c1c34f0bf1c.zip
Add new underscore-privates rule to @0xproject/tslint-config and fix lint errors
Diffstat (limited to 'packages/contracts/deploy/src/deployer.ts')
-rw-r--r--packages/contracts/deploy/src/deployer.ts66
1 files changed, 33 insertions, 33 deletions
diff --git a/packages/contracts/deploy/src/deployer.ts b/packages/contracts/deploy/src/deployer.ts
index 991504972..ea1de59d3 100644
--- a/packages/contracts/deploy/src/deployer.ts
+++ b/packages/contracts/deploy/src/deployer.ts
@@ -18,19 +18,19 @@ const EXTRA_GAS = 200000;
export class Deployer {
public web3Wrapper: Web3Wrapper;
- private artifactsDir: string;
- private jsonrpcPort: number;
- private networkId: number;
- private defaults: Partial<TxData>;
+ private _artifactsDir: string;
+ private _jsonrpcPort: number;
+ private _networkId: number;
+ private _defaults: Partial<TxData>;
constructor(opts: DeployerOptions) {
- this.artifactsDir = opts.artifactsDir;
- this.jsonrpcPort = opts.jsonrpcPort;
- this.networkId = opts.networkId;
- const jsonrpcUrl = `http://localhost:${this.jsonrpcPort}`;
+ this._artifactsDir = opts.artifactsDir;
+ this._jsonrpcPort = opts.jsonrpcPort;
+ this._networkId = opts.networkId;
+ const jsonrpcUrl = `http://localhost:${this._jsonrpcPort}`;
const web3Provider = new Web3.providers.HttpProvider(jsonrpcUrl);
- this.defaults = opts.defaults;
- this.web3Wrapper = new Web3Wrapper(web3Provider, this.defaults);
+ this._defaults = opts.defaults;
+ this.web3Wrapper = new Web3Wrapper(web3Provider, this._defaults);
}
/**
* Loads contract artifact and deploys contract with given arguments.
@@ -39,21 +39,21 @@ export class Deployer {
* @return Deployed contract instance.
*/
public async deployAsync(contractName: string, args: any[] = []): Promise<Web3.ContractInstance> {
- const contractArtifact: ContractArtifact = this.loadContractArtifactIfExists(contractName);
- const contractData: ContractData = this.getContractDataFromArtifactIfExists(contractArtifact);
+ const contractArtifact: ContractArtifact = this._loadContractArtifactIfExists(contractName);
+ const contractData: ContractData = this._getContractDataFromArtifactIfExists(contractArtifact);
const data = contractData.unlinked_binary;
- const from = await this.getFromAddressAsync();
- const gas = await this.getAllowableGasEstimateAsync(data);
+ const from = await this._getFromAddressAsync();
+ const gas = await this._getAllowableGasEstimateAsync(data);
const txData = {
- gasPrice: this.defaults.gasPrice,
+ gasPrice: this._defaults.gasPrice,
from,
data,
gas,
};
const abi = contractData.abi;
- const web3ContractInstance = await this.deployFromAbiAsync(abi, args, txData);
+ const web3ContractInstance = await this._deployFromAbiAsync(abi, args, txData);
utils.consoleLog(`${contractName}.sol successfully deployed at ${web3ContractInstance.address}`);
- const contractInstance = new Contract(web3ContractInstance, this.defaults);
+ const contractInstance = new Contract(web3ContractInstance, this._defaults);
return contractInstance;
}
/**
@@ -64,7 +64,7 @@ export class Deployer {
*/
public async deployAndSaveAsync(contractName: string, args: any[] = []): Promise<Web3.ContractInstance> {
const contractInstance = await this.deployAsync(contractName, args);
- await this.saveContractDataToArtifactAsync(contractName, contractInstance.address, args);
+ await this._saveContractDataToArtifactAsync(contractName, contractInstance.address, args);
return contractInstance;
}
/**
@@ -74,7 +74,7 @@ export class Deployer {
* @param txData Tx options used for deployment.
* @return Promise that resolves to a web3 contract instance.
*/
- private async deployFromAbiAsync(abi: Web3.ContractAbi, args: any[], txData: Web3.TxData): Promise<any> {
+ private async _deployFromAbiAsync(abi: Web3.ContractAbi, args: any[], txData: Web3.TxData): Promise<any> {
const contract: Web3.Contract<Web3.ContractInstance> = this.web3Wrapper.getContractFromAbi(abi);
const deployPromise = new Promise((resolve, reject) => {
/**
@@ -99,10 +99,10 @@ export class Deployer {
* @param contractAddress Contract address to save to artifact.
* @param args Contract constructor arguments that will be encoded and saved to artifact.
*/
- private async saveContractDataToArtifactAsync(contractName: string,
- contractAddress: string, args: any[]): Promise<void> {
- const contractArtifact: ContractArtifact = this.loadContractArtifactIfExists(contractName);
- const contractData: ContractData = this.getContractDataFromArtifactIfExists(contractArtifact);
+ private async _saveContractDataToArtifactAsync(contractName: string,
+ contractAddress: string, args: any[]): Promise<void> {
+ const contractArtifact: ContractArtifact = this._loadContractArtifactIfExists(contractName);
+ const contractData: ContractData = this._getContractDataFromArtifactIfExists(contractArtifact);
const abi = contractData.abi;
const encodedConstructorArgs = encoder.encodeConstructorArgsFromAbi(args, abi);
const newContractData = {
@@ -114,11 +114,11 @@ export class Deployer {
...contractArtifact,
networks: {
...contractArtifact.networks,
- [this.networkId]: newContractData,
+ [this._networkId]: newContractData,
},
};
const artifactString = utils.stringifyWithFormatting(newArtifact);
- const artifactPath = `${this.artifactsDir}/${contractName}.json`;
+ const artifactPath = `${this._artifactsDir}/${contractName}.json`;
await fsWrapper.writeFileAsync(artifactPath, artifactString);
}
/**
@@ -126,8 +126,8 @@ export class Deployer {
* @param contractName Name of the contract, without the extension.
* @return The contract artifact.
*/
- private loadContractArtifactIfExists(contractName: string): ContractArtifact {
- const artifactPath = `${this.artifactsDir}/${contractName}.json`;
+ private _loadContractArtifactIfExists(contractName: string): ContractArtifact {
+ const artifactPath = `${this._artifactsDir}/${contractName}.json`;
try {
const contractArtifact: ContractArtifact = require(artifactPath);
return contractArtifact;
@@ -140,8 +140,8 @@ export class Deployer {
* @param contractArtifact The contract artifact.
* @return Network specific contract data.
*/
- private getContractDataFromArtifactIfExists(contractArtifact: ContractArtifact): ContractData {
- const contractData = contractArtifact.networks[this.networkId];
+ private _getContractDataFromArtifactIfExists(contractArtifact: ContractArtifact): ContractData {
+ const contractData = contractArtifact.networks[this._networkId];
if (_.isUndefined(contractData)) {
throw new Error(`Data not found in artifact for contract: ${contractArtifact.contract_name}`);
}
@@ -151,13 +151,13 @@ export class Deployer {
* Gets the address to use for sending a transaction.
* @return The default from address. If not specified, returns the first address accessible by web3.
*/
- private async getFromAddressAsync(): Promise<string> {
+ private async _getFromAddressAsync(): Promise<string> {
let from: string;
- if (_.isUndefined(this.defaults.from)) {
+ if (_.isUndefined(this._defaults.from)) {
const accounts = await this.web3Wrapper.getAvailableAddressesAsync();
from = accounts[0];
} else {
- from = this.defaults.from;
+ from = this._defaults.from;
}
return from;
}
@@ -167,7 +167,7 @@ export class Deployer {
* @param data Bytecode to estimate gas for.
* @return Gas estimate for transaction data.
*/
- private async getAllowableGasEstimateAsync(data: string): Promise<number> {
+ private async _getAllowableGasEstimateAsync(data: string): Promise<number> {
const block = await this.web3Wrapper.getBlockAsync('latest');
let gas: number;
try {