aboutsummaryrefslogblamecommitdiffstats
path: root/packages/sol-compiler/src/utils/encoder.ts
blob: 40b103fd5582bb77ae8498e8d2b2dd662d5279bc (plain) (tree)
1
2
3
4
5
6
7
8
9
                                                                                               
                            

                                        
                        
                                                                         
                                              
                                                 
                                                       
                                                                         

                                                                   







                                                                                   
import { AbiDefinition, AbiType, ConstructorAbi, ContractAbi, DataItem } from 'ethereum-types';
import * as _ from 'lodash';
import * as web3Abi from 'web3-eth-abi';

export const encoder = {
    encodeConstructorArgsFromAbi(args: any[], abi: ContractAbi): string {
        const constructorTypes: string[] = [];
        _.each(abi, (element: AbiDefinition) => {
            if (element.type === AbiType.Constructor) {
                // tslint:disable-next-line:no-unnecessary-type-assertion
                const constuctorAbi = element as ConstructorAbi;
                _.each(constuctorAbi.inputs, (input: DataItem) => {
                    constructorTypes.push(input.type);
                });
            }
        });
        const encodedParameters = web3Abi.encodeParameters(constructorTypes, args);
        return encodedParameters;
    },
};