aboutsummaryrefslogtreecommitdiffstats
path: root/packages/abi-gen/src
diff options
context:
space:
mode:
Diffstat (limited to 'packages/abi-gen/src')
-rw-r--r--packages/abi-gen/src/index.ts7
-rw-r--r--packages/abi-gen/src/utils.ts9
2 files changed, 16 insertions, 0 deletions
diff --git a/packages/abi-gen/src/index.ts b/packages/abi-gen/src/index.ts
index ed71087b2..527af32b1 100644
--- a/packages/abi-gen/src/index.ts
+++ b/packages/abi-gen/src/index.ts
@@ -14,6 +14,7 @@ import * as Web3 from 'web3';
import { ContextData, ParamKind } from './types';
import { utils } from './utils';
+const ABI_TYPE_CONSTRUCTOR = 'constructor';
const ABI_TYPE_METHOD = 'function';
const ABI_TYPE_EVENT = 'event';
const MAIN_TEMPLATE_NAME = 'contract.mustache';
@@ -75,6 +76,11 @@ for (const abiFileName of abiFileNames) {
process.exit(1);
}
+ let ctor = ABI.find((abi: Web3.AbiDefinition) => abi.type === ABI_TYPE_CONSTRUCTOR) as Web3.ConstructorAbi;
+ if (_.isUndefined(ctor)) {
+ ctor = utils.getEmptyConstructor(); // The constructor exists, but it's implicit in JSON's ABI definition
+ }
+
const methodAbis = ABI.filter((abi: Web3.AbiDefinition) => abi.type === ABI_TYPE_METHOD) as Web3.MethodAbi[];
const methodsData = _.map(methodAbis, methodAbi => {
_.map(methodAbi.inputs, input => {
@@ -95,6 +101,7 @@ for (const abiFileName of abiFileNames) {
const contextData = {
contractName: namedContent.name,
+ ctor,
methods: methodsData,
events: eventAbis,
};
diff --git a/packages/abi-gen/src/utils.ts b/packages/abi-gen/src/utils.ts
index edda016b5..f6291d98d 100644
--- a/packages/abi-gen/src/utils.ts
+++ b/packages/abi-gen/src/utils.ts
@@ -1,6 +1,7 @@
import * as fs from 'fs';
import * as _ from 'lodash';
import * as path from 'path';
+import * as Web3 from 'web3';
import { ParamKind } from './types';
@@ -61,4 +62,12 @@ export const utils = {
throw new Error(`Failed to read ${filename}: ${err}`);
}
},
+ getEmptyConstructor(): Web3.ConstructorAbi {
+ return {
+ type: 'constructor',
+ stateMutability: 'nonpayable',
+ payable: false,
+ inputs: [],
+ };
+ },
};