aboutsummaryrefslogtreecommitdiffstats
path: root/packages/utils/src/zeroex_transaction_decoder.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/utils/src/zeroex_transaction_decoder.ts')
-rw-r--r--packages/utils/src/zeroex_transaction_decoder.ts55
1 files changed, 32 insertions, 23 deletions
diff --git a/packages/utils/src/zeroex_transaction_decoder.ts b/packages/utils/src/zeroex_transaction_decoder.ts
index 049596770..f236257cb 100644
--- a/packages/utils/src/zeroex_transaction_decoder.ts
+++ b/packages/utils/src/zeroex_transaction_decoder.ts
@@ -1,16 +1,31 @@
-import { TransactionDecoder } from './transaction_decoder';
import { getContractAddressesForNetworkOrThrow, NetworkId } from '@0x/contract-addresses';
import * as ContractArtifacts from '@0x/contract-artifacts';
import { SimpleContractArtifact } from '@0x/types';
import { AbiDefinition, ContractAbi } from 'ethereum-types';
-import { TransactionData, DeployedContractInfo, DeployedContractInfoByName, TransactionProperties } from './types';
import * as _ from 'lodash';
+import { TransactionDecoder } from './transaction_decoder';
+import { DeployedContractInfo, DeployedContractInfoByName, TransactionData, TransactionProperties } from './types';
+
export class ZeroExTransactionDecoder extends TransactionDecoder {
- private readonly _deployedContractInfoByName = {} as DeployedContractInfoByName;
private static _instance: ZeroExTransactionDecoder;
- private static getInstance(): ZeroExTransactionDecoder {
+ public static addABI(
+ abiArray: AbiDefinition[],
+ contractName: string,
+ deploymentInfos?: DeployedContractInfo[],
+ ): void {
+ const instance = ZeroExTransactionDecoder._getInstance();
+ instance.addABI(abiArray, contractName, deploymentInfos);
+ }
+
+ public static decode(calldata: string, txProperties?: TransactionProperties): TransactionData {
+ const instance = ZeroExTransactionDecoder._getInstance();
+ const decodedCalldata = instance.decode(calldata, txProperties);
+ return decodedCalldata;
+ }
+
+ private static _getInstance(): ZeroExTransactionDecoder {
if (!ZeroExTransactionDecoder._instance) {
ZeroExTransactionDecoder._instance = new ZeroExTransactionDecoder();
}
@@ -20,16 +35,21 @@ export class ZeroExTransactionDecoder extends TransactionDecoder {
private constructor() {
super();
// Load addresses by contract name
+ const deployedContractInfoByName: DeployedContractInfoByName = {};
_.each(NetworkId, (networkId: any) => {
- if (typeof networkId !== 'number') return;
- const networkIdAsNumber = networkId as number;
- const contractAddressesForNetwork = getContractAddressesForNetworkOrThrow(networkIdAsNumber);
+ if (typeof networkId !== 'number') {
+ return;
+ }
+ const contractAddressesForNetwork = getContractAddressesForNetworkOrThrow(networkId);
_.each(contractAddressesForNetwork, (contractAddress: string, contractName: string) => {
const contractNameLowercase = _.toLower(contractName);
- if (_.isUndefined(this._deployedContractInfoByName[contractNameLowercase])) {
- this._deployedContractInfoByName[contractNameLowercase] = [];
+ if (_.isUndefined(deployedContractInfoByName[contractNameLowercase])) {
+ deployedContractInfoByName[contractNameLowercase] = [];
}
- this._deployedContractInfoByName[contractNameLowercase].push({contractAddress, networkId: networkIdAsNumber});
+ deployedContractInfoByName[contractNameLowercase].push({
+ contractAddress,
+ networkId,
+ });
});
});
// Load contract artifacts
@@ -38,18 +58,7 @@ export class ZeroExTransactionDecoder extends TransactionDecoder {
const contractName = conractArtifact.contractName;
const contractNameLowercase = _.toLower(contractName);
const contractAbi: ContractAbi = conractArtifact.compilerOutput.abi;
- this.addABI(contractAbi, contractName, this._deployedContractInfoByName[contractNameLowercase]);
+ this.addABI(contractAbi, contractName, deployedContractInfoByName[contractNameLowercase]);
});
}
-
- public static addABI(abiArray: AbiDefinition[], contractName: string, deploymentInfos?: DeployedContractInfo[]): void {
- const instance = ZeroExTransactionDecoder.getInstance();
- instance.addABI(abiArray, contractName, deploymentInfos);
- }
-
- public static decode(calldata: string, txProperties?: TransactionProperties): TransactionData {
- const instance = ZeroExTransactionDecoder.getInstance();
- const decodedCalldata = instance.decode(calldata, txProperties);
- return decodedCalldata;
- }
-} \ No newline at end of file
+}