From 4b3e0383235ca4ca0127f24c2e05543bb45a56bb Mon Sep 17 00:00:00 2001 From: Amir Bandeali Date: Wed, 29 Nov 2017 22:02:43 -0800 Subject: Add contracts to packages, fix most linting errors --- packages/contracts/deploy/src/utils/encoder.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 packages/contracts/deploy/src/utils/encoder.ts (limited to 'packages/contracts/deploy/src/utils/encoder.ts') diff --git a/packages/contracts/deploy/src/utils/encoder.ts b/packages/contracts/deploy/src/utils/encoder.ts new file mode 100644 index 000000000..0248e9f03 --- /dev/null +++ b/packages/contracts/deploy/src/utils/encoder.ts @@ -0,0 +1,20 @@ +import * as _ from 'lodash'; +import * as Web3 from 'web3'; +import * as web3Abi from 'web3-eth-abi'; + +import {AbiType} from './types'; + +export const encoder = { + encodeConstructorArgsFromAbi(args: any[], abi: Web3.ContractAbi): string { + const constructorTypes: string[] = []; + _.each(abi, (element: Web3.AbiDefinition) => { + if (element.type === AbiType.Constructor) { + _.each(element.inputs, (input: Web3.FunctionParameter) => { + constructorTypes.push(input.type); + }); + } + }); + const encodedParameters = web3Abi.encodeParameters(constructorTypes, args); + return encodedParameters; + }, +}; -- cgit v1.2.3