aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLeonid <logvinov.leon@gmail.com>2018-01-05 19:49:51 +0800
committerGitHub <noreply@github.com>2018-01-05 19:49:51 +0800
commit35e0b6143ab1405259471e1c9c698bfcd869df5a (patch)
treec9acc3f7a1dbccaf10c8616289de61f2dc879236
parentce6abad97f248a3557390dd1e1ff3ae84662838f (diff)
parente019ae4aed610c4645894c2999871fd3c0b57388 (diff)
downloaddexon-sol-tools-35e0b6143ab1405259471e1c9c698bfcd869df5a.tar
dexon-sol-tools-35e0b6143ab1405259471e1c9c698bfcd869df5a.tar.gz
dexon-sol-tools-35e0b6143ab1405259471e1c9c698bfcd869df5a.tar.bz2
dexon-sol-tools-35e0b6143ab1405259471e1c9c698bfcd869df5a.tar.lz
dexon-sol-tools-35e0b6143ab1405259471e1c9c698bfcd869df5a.tar.xz
dexon-sol-tools-35e0b6143ab1405259471e1c9c698bfcd869df5a.tar.zst
dexon-sol-tools-35e0b6143ab1405259471e1c9c698bfcd869df5a.zip
Merge pull request #304 from joincivil/ritave/feature/abi-gen-constructor
Added constructor ABIs to abi-gen
-rw-r--r--packages/abi-gen/CHANGELOG.md1
-rw-r--r--packages/abi-gen/package.json2
-rw-r--r--packages/abi-gen/src/index.ts7
-rw-r--r--packages/abi-gen/src/utils.ts9
-rw-r--r--yarn.lock6
5 files changed, 24 insertions, 1 deletions
diff --git a/packages/abi-gen/CHANGELOG.md b/packages/abi-gen/CHANGELOG.md
index 346bba4bf..0afd6abd4 100644
--- a/packages/abi-gen/CHANGELOG.md
+++ b/packages/abi-gen/CHANGELOG.md
@@ -4,3 +4,4 @@ v0.x.x - _TBD, 2018_
------------------------
* Fixed array typings with union types (#295)
* Add event ABIs to context data passed to templates (#302)
+* Add constructor ABIs to context data passed to templates (#304) \ No newline at end of file
diff --git a/packages/abi-gen/package.json b/packages/abi-gen/package.json
index db429d9a9..fbf3db687 100644
--- a/packages/abi-gen/package.json
+++ b/packages/abi-gen/package.json
@@ -43,6 +43,6 @@
"shx": "^0.2.2",
"tslint": "5.8.0",
"typescript": "~2.6.1",
- "web3-typescript-typings": "^0.7.2"
+ "web3-typescript-typings": "^0.9.0"
}
}
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 764daa142..524c54a5e 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';
@@ -56,4 +57,12 @@ export const utils = {
throw new Error(`Failed to read ${filename}: ${err}`);
}
},
+ getEmptyConstructor(): Web3.ConstructorAbi {
+ return {
+ type: 'constructor',
+ stateMutability: 'nonpayable',
+ payable: false,
+ inputs: [],
+ };
+ },
};
diff --git a/yarn.lock b/yarn.lock
index 1d3824de1..e7d64bbcc 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -9450,6 +9450,12 @@ web3-typescript-typings@^0.7.2:
dependencies:
bignumber.js "^4.0.2"
+web3-typescript-typings@^0.9.0:
+ version "0.9.0"
+ resolved "https://registry.yarnpkg.com/web3-typescript-typings/-/web3-typescript-typings-0.9.0.tgz#c658db3c84427d9c05a93613e35e6d8147c931c4"
+ dependencies:
+ bignumber.js "^4.0.2"
+
web3-utils@^1.0.0-beta.26:
version "1.0.0-beta.26"
resolved "https://registry.yarnpkg.com/web3-utils/-/web3-utils-1.0.0-beta.26.tgz#f04ad8c144b1781c6b20c2818e0532cb9e6dca15"