aboutsummaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2017-12-02 12:47:05 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2017-12-02 13:31:50 +0800
commiteb667f653c4ee87132390844afaecf409c7575c8 (patch)
treed2d3c9b1a44bc9a93442617b0e2892cc901c5612 /packages
parent6cbd0d4537be3e51866c407dc01fb0efca0b50c2 (diff)
downloaddexon-sol-tools-eb667f653c4ee87132390844afaecf409c7575c8.tar
dexon-sol-tools-eb667f653c4ee87132390844afaecf409c7575c8.tar.gz
dexon-sol-tools-eb667f653c4ee87132390844afaecf409c7575c8.tar.bz2
dexon-sol-tools-eb667f653c4ee87132390844afaecf409c7575c8.tar.lz
dexon-sol-tools-eb667f653c4ee87132390844afaecf409c7575c8.tar.xz
dexon-sol-tools-eb667f653c4ee87132390844afaecf409c7575c8.tar.zst
dexon-sol-tools-eb667f653c4ee87132390844afaecf409c7575c8.zip
Adjust 0x.js to use generated wrappers
Diffstat (limited to 'packages')
-rw-r--r--packages/0x.js/src/contract_wrappers/contract_wrapper.ts12
-rw-r--r--packages/0x.js/src/contract_wrappers/ether_token_wrapper.ts6
-rw-r--r--packages/0x.js/src/contract_wrappers/exchange_wrapper.ts5
-rw-r--r--packages/0x.js/src/contract_wrappers/token_registry_wrapper.ts8
-rw-r--r--packages/0x.js/src/contract_wrappers/token_transfer_proxy_wrapper.ts8
-rw-r--r--packages/0x.js/src/contract_wrappers/token_wrapper.ts7
-rw-r--r--packages/0x.js/src/web3_wrapper.ts21
7 files changed, 43 insertions, 24 deletions
diff --git a/packages/0x.js/src/contract_wrappers/contract_wrapper.ts b/packages/0x.js/src/contract_wrappers/contract_wrapper.ts
index 8c92931b4..5e5a38f8c 100644
--- a/packages/0x.js/src/contract_wrappers/contract_wrapper.ts
+++ b/packages/0x.js/src/contract_wrappers/contract_wrapper.ts
@@ -90,11 +90,13 @@ export class ContractWrapper {
const logWithDecodedArgs = this._abiDecoder.tryToDecodeLogOrNoop(log);
return logWithDecodedArgs;
}
- protected async _instantiateContractIfExistsAsync<ContractType extends Web3.ContractInstance>(
- artifact: Artifact, addressIfExists?: string): Promise<ContractType> {
- const contractInstance =
- await this._web3Wrapper.getContractInstanceFromArtifactAsync<ContractType>(artifact, addressIfExists);
- return contractInstance;
+ protected async _instantiateContractIfExistsAsync(
+ artifact: Artifact, addressIfExists?: string,
+ ): Promise<Web3.ContractInstance> {
+ const web3ContractInstance = await this._web3Wrapper.getContractInstanceFromArtifactAsync(
+ artifact, addressIfExists,
+ );
+ return web3ContractInstance;
}
protected _getContractAddress(artifact: Artifact, addressIfExists?: string): string {
if (_.isUndefined(addressIfExists)) {
diff --git a/packages/0x.js/src/contract_wrappers/ether_token_wrapper.ts b/packages/0x.js/src/contract_wrappers/ether_token_wrapper.ts
index ede0460bd..26025f6f9 100644
--- a/packages/0x.js/src/contract_wrappers/ether_token_wrapper.ts
+++ b/packages/0x.js/src/contract_wrappers/ether_token_wrapper.ts
@@ -2,11 +2,12 @@ import BigNumber from 'bignumber.js';
import * as _ from 'lodash';
import {artifacts} from '../artifacts';
-import {EtherTokenContract, TransactionOpts, ZeroExError} from '../types';
+import {TransactionOpts, ZeroExError} from '../types';
import {assert} from '../utils/assert';
import {Web3Wrapper} from '../web3_wrapper';
import {ContractWrapper} from './contract_wrapper';
+import {EtherTokenContract} from './generated/ether_token';
import {TokenWrapper} from './token_wrapper';
/**
@@ -92,9 +93,10 @@ export class EtherTokenWrapper extends ContractWrapper {
if (!_.isUndefined(this._etherTokenContractIfExists)) {
return this._etherTokenContractIfExists;
}
- const contractInstance = await this._instantiateContractIfExistsAsync<EtherTokenContract>(
+ const web3ContractInstance = await this._instantiateContractIfExistsAsync(
artifacts.EtherTokenArtifact, this._contractAddressIfExists,
);
+ const contractInstance = new EtherTokenContract(web3ContractInstance, this._web3Wrapper.getContractDefaults());
this._etherTokenContractIfExists = contractInstance;
return this._etherTokenContractIfExists;
}
diff --git a/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts b/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts
index 273b348ff..aaf6256a3 100644
--- a/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts
+++ b/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts
@@ -9,7 +9,6 @@ import {
DecodedLogArgs,
ECSignature,
EventCallback,
- ExchangeContract,
ExchangeContractErrCodes,
ExchangeContractErrs,
ExchangeContractEventArgs,
@@ -40,6 +39,7 @@ import {utils} from '../utils/utils';
import {Web3Wrapper} from '../web3_wrapper';
import {ContractWrapper} from './contract_wrapper';
+import {ExchangeContract} from './generated/exchange';
import {TokenWrapper} from './token_wrapper';
const SHOULD_VALIDATE_BY_DEFAULT = true;
@@ -789,9 +789,10 @@ export class ExchangeWrapper extends ContractWrapper {
if (!_.isUndefined(this._exchangeContractIfExists)) {
return this._exchangeContractIfExists;
}
- const contractInstance = await this._instantiateContractIfExistsAsync<ExchangeContract>(
+ const web3ContractInstance = await this._instantiateContractIfExistsAsync(
artifacts.ExchangeArtifact, this._contractAddressIfExists,
);
+ const contractInstance = new ExchangeContract(web3ContractInstance, this._web3Wrapper.getContractDefaults());
this._exchangeContractIfExists = contractInstance;
return this._exchangeContractIfExists;
}
diff --git a/packages/0x.js/src/contract_wrappers/token_registry_wrapper.ts b/packages/0x.js/src/contract_wrappers/token_registry_wrapper.ts
index 35337fa35..27ecb8bde 100644
--- a/packages/0x.js/src/contract_wrappers/token_registry_wrapper.ts
+++ b/packages/0x.js/src/contract_wrappers/token_registry_wrapper.ts
@@ -1,12 +1,13 @@
import * as _ from 'lodash';
import {artifacts} from '../artifacts';
-import {Token, TokenMetadata, TokenRegistryContract, ZeroExError} from '../types';
+import {Token, TokenMetadata, ZeroExError} from '../types';
import {assert} from '../utils/assert';
import {constants} from '../utils/constants';
import {Web3Wrapper} from '../web3_wrapper';
import {ContractWrapper} from './contract_wrapper';
+import {TokenRegistryContract} from './generated/token_registry';
/**
* This class includes all the functionality related to interacting with the 0x Token Registry smart contract.
@@ -116,9 +117,12 @@ export class TokenRegistryWrapper extends ContractWrapper {
if (!_.isUndefined(this._tokenRegistryContractIfExists)) {
return this._tokenRegistryContractIfExists;
}
- const contractInstance = await this._instantiateContractIfExistsAsync<TokenRegistryContract>(
+ const web3ContractInstance = await this._instantiateContractIfExistsAsync(
artifacts.TokenRegistryArtifact, this._contractAddressIfExists,
);
+ const contractInstance = new TokenRegistryContract(
+ web3ContractInstance, this._web3Wrapper.getContractDefaults(),
+ );
this._tokenRegistryContractIfExists = contractInstance;
return this._tokenRegistryContractIfExists;
}
diff --git a/packages/0x.js/src/contract_wrappers/token_transfer_proxy_wrapper.ts b/packages/0x.js/src/contract_wrappers/token_transfer_proxy_wrapper.ts
index c3df7d3eb..edc702672 100644
--- a/packages/0x.js/src/contract_wrappers/token_transfer_proxy_wrapper.ts
+++ b/packages/0x.js/src/contract_wrappers/token_transfer_proxy_wrapper.ts
@@ -1,10 +1,11 @@
import * as _ from 'lodash';
import {artifacts} from '../artifacts';
-import {TokenTransferProxyContract, ZeroExError} from '../types';
+import {ZeroExError} from '../types';
import {Web3Wrapper} from '../web3_wrapper';
import {ContractWrapper} from './contract_wrapper';
+import {TokenTransferProxyContract} from './generated/token_transfer_proxy';
/**
* This class includes the functionality related to interacting with the TokenTransferProxy contract.
@@ -53,9 +54,12 @@ export class TokenTransferProxyWrapper extends ContractWrapper {
if (!_.isUndefined(this._tokenTransferProxyContractIfExists)) {
return this._tokenTransferProxyContractIfExists;
}
- const contractInstance = await this._instantiateContractIfExistsAsync<TokenTransferProxyContract>(
+ const web3ContractInstance = await this._instantiateContractIfExistsAsync(
artifacts.TokenTransferProxyArtifact, this._contractAddressIfExists,
);
+ const contractInstance = new TokenTransferProxyContract(
+ web3ContractInstance, this._web3Wrapper.getContractDefaults(),
+ );
this._tokenTransferProxyContractIfExists = contractInstance;
return this._tokenTransferProxyContractIfExists;
}
diff --git a/packages/0x.js/src/contract_wrappers/token_wrapper.ts b/packages/0x.js/src/contract_wrappers/token_wrapper.ts
index 4a1dfcf8d..630ab6e3b 100644
--- a/packages/0x.js/src/contract_wrappers/token_wrapper.ts
+++ b/packages/0x.js/src/contract_wrappers/token_wrapper.ts
@@ -9,7 +9,6 @@ import {
LogWithDecodedArgs,
MethodOpts,
SubscriptionOpts,
- TokenContract,
TokenContractEventArgs,
TokenEvents,
TransactionOpts,
@@ -21,6 +20,7 @@ import {constants} from '../utils/constants';
import {Web3Wrapper} from '../web3_wrapper';
import {ContractWrapper} from './contract_wrapper';
+import {TokenContract} from './generated/token';
import {TokenTransferProxyWrapper} from './token_transfer_proxy_wrapper';
const ALLOWANCE_TO_ZERO_GAS_AMOUNT = 47275;
@@ -313,9 +313,12 @@ export class TokenWrapper extends ContractWrapper {
if (!_.isUndefined(tokenContract)) {
return tokenContract;
}
- const contractInstance = await this._instantiateContractIfExistsAsync<TokenContract>(
+ const web3ContractInstance = await this._instantiateContractIfExistsAsync(
artifacts.TokenArtifact, tokenAddress,
);
+ const contractInstance = new TokenContract(
+ web3ContractInstance, this._web3Wrapper.getContractDefaults(),
+ );
tokenContract = contractInstance;
this._tokenContractsByAddress[tokenAddress] = tokenContract;
return tokenContract;
diff --git a/packages/0x.js/src/web3_wrapper.ts b/packages/0x.js/src/web3_wrapper.ts
index a031de486..0f23272a7 100644
--- a/packages/0x.js/src/web3_wrapper.ts
+++ b/packages/0x.js/src/web3_wrapper.ts
@@ -4,7 +4,7 @@ import * as _ from 'lodash';
import * as Web3 from 'web3';
import {Contract} from './contract';
-import {Artifact, ArtifactContractName, TransactionReceipt, ZeroExError} from './types';
+import {Artifact, ArtifactContractName, TransactionReceipt, TxData, ZeroExError} from './types';
interface RawLogEntry {
logIndex: string|null;
@@ -29,9 +29,9 @@ const CONTRACT_NAME_TO_NOT_FOUND_ERROR: {[contractName: string]: ZeroExError} =
export class Web3Wrapper {
private web3: Web3;
private networkId: number;
- private defaults: Partial<Web3.TxData>;
+ private defaults: Partial<TxData>;
private jsonRpcRequestId: number;
- constructor(provider: Web3.Provider, networkId: number, defaults?: Partial<Web3.TxData>) {
+ constructor(provider: Web3.Provider, networkId: number, defaults?: Partial<TxData>) {
if (_.isUndefined((provider as any).sendAsync)) {
// Web3@1.0 provider doesn't support synchronous http requests,
// so it only has an async `send` method, instead of a `send` and `sendAsync` in web3@0.x.x`
@@ -44,6 +44,9 @@ export class Web3Wrapper {
this.defaults = defaults || {};
this.jsonRpcRequestId = 0;
}
+ public getContractDefaults(): Partial<TxData> {
+ return this.defaults;
+ }
public setProvider(provider: Web3.Provider, networkId: number) {
this.networkId = networkId;
this.web3.setProvider(provider);
@@ -72,8 +75,9 @@ export class Web3Wrapper {
public getNetworkId(): number {
return this.networkId;
}
- public async getContractInstanceFromArtifactAsync<A extends Web3.ContractInstance>(artifact: Artifact,
- address?: string): Promise<A> {
+ public async getContractInstanceFromArtifactAsync(
+ artifact: Artifact, address?: string,
+ ): Promise<Web3.ContractInstance> {
let contractAddress: string;
if (_.isUndefined(address)) {
const networkId = this.getNetworkId();
@@ -88,7 +92,7 @@ export class Web3Wrapper {
if (!doesContractExist) {
throw new Error(CONTRACT_NAME_TO_NOT_FOUND_ERROR[artifact.contract_name]);
}
- const contractInstance = this.getContractInstance<A>(
+ const contractInstance = this.getContractInstance(
artifact.abi, contractAddress,
);
return contractInstance;
@@ -152,10 +156,9 @@ export class Web3Wrapper {
const formattedLogs = _.map(rawLogs, this.formatLog.bind(this));
return formattedLogs;
}
- private getContractInstance<A extends Web3.ContractInstance>(abi: Web3.ContractAbi, address: string): A {
+ private getContractInstance(abi: Web3.ContractAbi, address: string): Web3.ContractInstance {
const web3ContractInstance = this.web3.eth.contract(abi).at(address);
- const contractInstance = new Contract(web3ContractInstance, this.defaults) as any as A;
- return contractInstance;
+ return web3ContractInstance;
}
private async getNetworkAsync(): Promise<number> {
const networkId = await promisify(this.web3.version.getNetwork)();