From 3a7bb97ad1182eb9c718797bda8dca5eb5d7f9cd Mon Sep 17 00:00:00 2001 From: Alex Browne Date: Wed, 3 Oct 2018 16:21:17 -0700 Subject: Remove artifacts from migrations package and update contract-wrappers accordingly --- .../src/contract_wrappers/contract_wrapper.ts | 59 +--------------------- 1 file changed, 1 insertion(+), 58 deletions(-) (limited to 'packages/contract-wrappers/src/contract_wrappers/contract_wrapper.ts') diff --git a/packages/contract-wrappers/src/contract_wrappers/contract_wrapper.ts b/packages/contract-wrappers/src/contract_wrappers/contract_wrapper.ts index f7a89e3be..aed9d44db 100644 --- a/packages/contract-wrappers/src/contract_wrappers/contract_wrapper.ts +++ b/packages/contract-wrappers/src/contract_wrappers/contract_wrapper.ts @@ -3,7 +3,6 @@ import { marshaller, Web3Wrapper } from '@0xproject/web3-wrapper'; import { BlockParamLiteral, ContractAbi, - ContractArtifact, FilterObject, LogEntry, LogWithDecodedArgs, @@ -24,22 +23,9 @@ import { import { constants } from '../utils/constants'; import { filterUtils } from '../utils/filter_utils'; -const CONTRACT_NAME_TO_NOT_FOUND_ERROR: { - [contractName: string]: ContractWrappersError; -} = { - ZRX: ContractWrappersError.ZRXContractDoesNotExist, - EtherToken: ContractWrappersError.EtherTokenContractDoesNotExist, - ERC20Token: ContractWrappersError.ERC20TokenContractDoesNotExist, - ERC20Proxy: ContractWrappersError.ERC20ProxyContractDoesNotExist, - ERC721Token: ContractWrappersError.ERC721TokenContractDoesNotExist, - ERC721Proxy: ContractWrappersError.ERC721ProxyContractDoesNotExist, - Exchange: ContractWrappersError.ExchangeContractDoesNotExist, -}; - export abstract class ContractWrapper { public abstract abi: ContractAbi; protected _web3Wrapper: Web3Wrapper; - protected _networkId: number; private _blockAndLogStreamerIfExists: BlockAndLogStreamer | undefined; private _blockPollingIntervalMs: number; private _blockAndLogStreamIntervalIfExists?: NodeJS.Timer; @@ -56,9 +42,8 @@ export abstract class ContractWrapper { logUtils.warn(err); } } - constructor(web3Wrapper: Web3Wrapper, networkId: number, blockPollingIntervalMs?: number) { + constructor(web3Wrapper: Web3Wrapper, blockPollingIntervalMs?: number) { this._web3Wrapper = web3Wrapper; - this._networkId = networkId; this._blockPollingIntervalMs = _.isUndefined(blockPollingIntervalMs) ? constants.DEFAULT_BLOCK_POLLING_INTERVAL : blockPollingIntervalMs; @@ -124,40 +109,6 @@ export abstract class ContractWrapper { const logWithDecodedArgs = abiDecoder.tryToDecodeLogOrNoop(log); return logWithDecodedArgs; } - protected async _getContractAbiAndAddressFromArtifactsAsync( - artifact: ContractArtifact, - addressIfExists?: string, - ): Promise<[ContractAbi, string]> { - let contractAddress: string; - if (_.isUndefined(addressIfExists)) { - if (_.isUndefined(artifact.networks[this._networkId])) { - throw new Error(ContractWrappersError.ContractNotDeployedOnNetwork); - } - contractAddress = artifact.networks[this._networkId].address.toLowerCase(); - } else { - contractAddress = addressIfExists; - } - const doesContractExist = await this._web3Wrapper.doesContractExistAtAddressAsync(contractAddress); - if (!doesContractExist) { - throw new Error(CONTRACT_NAME_TO_NOT_FOUND_ERROR[artifact.contractName]); - } - const abiAndAddress: [ContractAbi, string] = [artifact.compilerOutput.abi, contractAddress]; - return abiAndAddress; - } - protected _getContractAddress(artifact: ContractArtifact, addressIfExists?: string): string { - if (_.isUndefined(addressIfExists)) { - if (_.isUndefined(artifact.networks[this._networkId])) { - throw new Error(ContractWrappersError.ContractNotDeployedOnNetwork); - } - const contractAddress = artifact.networks[this._networkId].address; - if (_.isUndefined(contractAddress)) { - throw new Error(CONTRACT_NAME_TO_NOT_FOUND_ERROR[artifact.contractName]); - } - return contractAddress; - } else { - return addressIfExists; - } - } private _onLogStateChanged(isRemoved: boolean, rawLog: RawLogEntry): void { const log: LogEntry = marshaller.unmarshalLog(rawLog); _.forEach(this._filters, (filter: FilterObject, filterToken: string) => { @@ -222,14 +173,6 @@ export abstract class ContractWrapper { }); return logs as RawLogEntry[]; } - // HACK: This should be a package-scoped method (which doesn't exist in TS) - // We don't want this method available in the public interface for all classes - // who inherit from ContractWrapper, and it is only used by the internal implementation - // of those higher classes. - // tslint:disable-next-line:no-unused-variable - private _setNetworkId(networkId: number): void { - this._networkId = networkId; - } private _stopBlockAndLogStream(): void { if (_.isUndefined(this._blockAndLogStreamerIfExists)) { throw new Error(ContractWrappersError.SubscriptionNotFound); -- cgit v1.2.3 From 1e9ea09f087c7b3120e758d931a88812b655da08 Mon Sep 17 00:00:00 2001 From: Alex Browne Date: Tue, 9 Oct 2018 23:10:33 -0700 Subject: Introduce new contract-addresses package and use it everywhere --- .../contract-wrappers/src/contract_wrappers/contract_wrapper.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'packages/contract-wrappers/src/contract_wrappers/contract_wrapper.ts') diff --git a/packages/contract-wrappers/src/contract_wrappers/contract_wrapper.ts b/packages/contract-wrappers/src/contract_wrappers/contract_wrapper.ts index aed9d44db..30095e002 100644 --- a/packages/contract-wrappers/src/contract_wrappers/contract_wrapper.ts +++ b/packages/contract-wrappers/src/contract_wrappers/contract_wrapper.ts @@ -1,3 +1,4 @@ +import { ContractAddresses, getContractAddressesForNetwork } from '@0xproject/contract-addresses'; import { AbiDecoder, intervalUtils, logUtils } from '@0xproject/utils'; import { marshaller, Web3Wrapper } from '@0xproject/web3-wrapper'; import { @@ -25,6 +26,7 @@ import { filterUtils } from '../utils/filter_utils'; export abstract class ContractWrapper { public abstract abi: ContractAbi; + protected _networkId: number; protected _web3Wrapper: Web3Wrapper; private _blockAndLogStreamerIfExists: BlockAndLogStreamer | undefined; private _blockPollingIntervalMs: number; @@ -42,8 +44,9 @@ export abstract class ContractWrapper { logUtils.warn(err); } } - constructor(web3Wrapper: Web3Wrapper, blockPollingIntervalMs?: number) { + constructor(web3Wrapper: Web3Wrapper, networkId: number, blockPollingIntervalMs?: number) { this._web3Wrapper = web3Wrapper; + this._networkId = networkId; this._blockPollingIntervalMs = _.isUndefined(blockPollingIntervalMs) ? constants.DEFAULT_BLOCK_POLLING_INTERVAL : blockPollingIntervalMs; @@ -109,6 +112,9 @@ export abstract class ContractWrapper { const logWithDecodedArgs = abiDecoder.tryToDecodeLogOrNoop(log); return logWithDecodedArgs; } + protected _getDefaultContractAddresses(): ContractAddresses { + return getContractAddressesForNetwork(this._networkId); + } private _onLogStateChanged(isRemoved: boolean, rawLog: RawLogEntry): void { const log: LogEntry = marshaller.unmarshalLog(rawLog); _.forEach(this._filters, (filter: FilterObject, filterToken: string) => { -- cgit v1.2.3 From 974ec23ecd2a445523e0550c0a7f69329d6959f1 Mon Sep 17 00:00:00 2001 From: Alex Browne Date: Wed, 10 Oct 2018 16:04:37 -0700 Subject: Apply various PR feedback --- packages/contract-wrappers/src/contract_wrappers/contract_wrapper.ts | 1 + 1 file changed, 1 insertion(+) (limited to 'packages/contract-wrappers/src/contract_wrappers/contract_wrapper.ts') diff --git a/packages/contract-wrappers/src/contract_wrappers/contract_wrapper.ts b/packages/contract-wrappers/src/contract_wrappers/contract_wrapper.ts index 30095e002..3d37e446c 100644 --- a/packages/contract-wrappers/src/contract_wrappers/contract_wrapper.ts +++ b/packages/contract-wrappers/src/contract_wrappers/contract_wrapper.ts @@ -113,6 +113,7 @@ export abstract class ContractWrapper { return logWithDecodedArgs; } protected _getDefaultContractAddresses(): ContractAddresses { + // TODO(albrow): Figure out better error handling here. return getContractAddressesForNetwork(this._networkId); } private _onLogStateChanged(isRemoved: boolean, rawLog: RawLogEntry): void { -- cgit v1.2.3 From c83dec22c9e70cec2b75c9e5051f37124baa2761 Mon Sep 17 00:00:00 2001 From: Alex Browne Date: Wed, 10 Oct 2018 16:52:35 -0700 Subject: Improve error handling for unknown network ids in contract-wrappers --- .../contract-wrappers/src/contract_wrappers/contract_wrapper.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'packages/contract-wrappers/src/contract_wrappers/contract_wrapper.ts') diff --git a/packages/contract-wrappers/src/contract_wrappers/contract_wrapper.ts b/packages/contract-wrappers/src/contract_wrappers/contract_wrapper.ts index 3d37e446c..72f5aa629 100644 --- a/packages/contract-wrappers/src/contract_wrappers/contract_wrapper.ts +++ b/packages/contract-wrappers/src/contract_wrappers/contract_wrapper.ts @@ -1,4 +1,4 @@ -import { ContractAddresses, getContractAddressesForNetwork } from '@0xproject/contract-addresses'; +import { ContractAddresses, getContractAddressesForNetwork, NetworkId } from '@0xproject/contract-addresses'; import { AbiDecoder, intervalUtils, logUtils } from '@0xproject/utils'; import { marshaller, Web3Wrapper } from '@0xproject/web3-wrapper'; import { @@ -112,10 +112,6 @@ export abstract class ContractWrapper { const logWithDecodedArgs = abiDecoder.tryToDecodeLogOrNoop(log); return logWithDecodedArgs; } - protected _getDefaultContractAddresses(): ContractAddresses { - // TODO(albrow): Figure out better error handling here. - return getContractAddressesForNetwork(this._networkId); - } private _onLogStateChanged(isRemoved: boolean, rawLog: RawLogEntry): void { const log: LogEntry = marshaller.unmarshalLog(rawLog); _.forEach(this._filters, (filter: FilterObject, filterToken: string) => { -- cgit v1.2.3 From 38b146c395429f860f57fa1865e01175eee39e62 Mon Sep 17 00:00:00 2001 From: Alex Browne Date: Mon, 15 Oct 2018 14:22:48 -0700 Subject: Add OrThrow suffix to getContractAddressesForNetwork --- packages/contract-wrappers/src/contract_wrappers/contract_wrapper.ts | 1 - 1 file changed, 1 deletion(-) (limited to 'packages/contract-wrappers/src/contract_wrappers/contract_wrapper.ts') diff --git a/packages/contract-wrappers/src/contract_wrappers/contract_wrapper.ts b/packages/contract-wrappers/src/contract_wrappers/contract_wrapper.ts index 72f5aa629..e03e4188b 100644 --- a/packages/contract-wrappers/src/contract_wrappers/contract_wrapper.ts +++ b/packages/contract-wrappers/src/contract_wrappers/contract_wrapper.ts @@ -1,4 +1,3 @@ -import { ContractAddresses, getContractAddressesForNetwork, NetworkId } from '@0xproject/contract-addresses'; import { AbiDecoder, intervalUtils, logUtils } from '@0xproject/utils'; import { marshaller, Web3Wrapper } from '@0xproject/web3-wrapper'; import { -- cgit v1.2.3