aboutsummaryrefslogtreecommitdiffstats
path: root/packages/abi-gen
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2018-02-24 04:20:59 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2018-02-28 04:05:23 +0800
commitfe8f2d8d898e9909636366c9ceee37a5e9481573 (patch)
tree16be81a7d12e527c65084b972b39a4fe27c3267f /packages/abi-gen
parent2d561bc8a05e8d1fca91cde93bae2080d87be926 (diff)
downloaddexon-sol-tools-fe8f2d8d898e9909636366c9ceee37a5e9481573.tar
dexon-sol-tools-fe8f2d8d898e9909636366c9ceee37a5e9481573.tar.gz
dexon-sol-tools-fe8f2d8d898e9909636366c9ceee37a5e9481573.tar.bz2
dexon-sol-tools-fe8f2d8d898e9909636366c9ceee37a5e9481573.tar.lz
dexon-sol-tools-fe8f2d8d898e9909636366c9ceee37a5e9481573.tar.xz
dexon-sol-tools-fe8f2d8d898e9909636366c9ceee37a5e9481573.tar.zst
dexon-sol-tools-fe8f2d8d898e9909636366c9ceee37a5e9481573.zip
Add support for ABIv2 to abi-gen
Diffstat (limited to 'packages/abi-gen')
-rw-r--r--packages/abi-gen/CHANGELOG.md1
-rw-r--r--packages/abi-gen/src/utils.ts34
2 files changed, 30 insertions, 5 deletions
diff --git a/packages/abi-gen/CHANGELOG.md b/packages/abi-gen/CHANGELOG.md
index 7e589551e..17186570e 100644
--- a/packages/abi-gen/CHANGELOG.md
+++ b/packages/abi-gen/CHANGELOG.md
@@ -3,6 +3,7 @@
## v0.2.3 - _TBD, 2018_
* Add a `backend` parameter that allows you to specify your backend (web3 or ethers). Ethers auto-converts small ints to numbers (#TBD)
+ * Add support for ABIv2 (#TBD)
## v0.2.1 - _February 9, 2018_
diff --git a/packages/abi-gen/src/utils.ts b/packages/abi-gen/src/utils.ts
index dc2c5390e..349604aec 100644
--- a/packages/abi-gen/src/utils.ts
+++ b/packages/abi-gen/src/utils.ts
@@ -6,14 +6,20 @@ import * as Web3 from 'web3';
import { AbiType, ContractsBackend, ParamKind } from './types';
export const utils = {
- solTypeToTsType(paramKind: ParamKind, backend: ContractsBackend, solType: string): string {
+ solTypeToTsType(
+ paramKind: ParamKind,
+ backend: ContractsBackend,
+ solType: string,
+ components?: Web3.DataItem[],
+ ): string {
const trailingArrayRegex = /\[\d*\]$/;
if (solType.match(trailingArrayRegex)) {
const arrayItemSolType = solType.replace(trailingArrayRegex, '');
- const arrayItemTsType = utils.solTypeToTsType(paramKind, backend, arrayItemSolType);
- const arrayTsType = utils.isUnionType(arrayItemTsType)
- ? `Array<${arrayItemTsType}>`
- : `${arrayItemTsType}[]`;
+ const arrayItemTsType = utils.solTypeToTsType(paramKind, backend, arrayItemSolType, components);
+ const arrayTsType =
+ utils.isUnionType(arrayItemTsType) || utils.isObjectType(arrayItemTsType)
+ ? `Array<${arrayItemTsType}>`
+ : `${arrayItemTsType}[]`;
return arrayTsType;
} else {
const solTypeRegexToTsType = [
@@ -45,12 +51,30 @@ export const utils = {
return tsType;
}
}
+ const TUPLE_TYPE_REGEX = '^tuple$';
+ if (solType.match(TUPLE_TYPE_REGEX)) {
+ const componentsType = _.map(components, component => {
+ const componentValueType = utils.solTypeToTsType(
+ paramKind,
+ backend,
+ component.type,
+ component.components,
+ );
+ const componentType = `${component.name}: ${componentValueType}`;
+ return componentType;
+ });
+ const tsType = `{${componentsType}}`;
+ return tsType;
+ }
throw new Error(`Unknown Solidity type found: ${solType}`);
}
},
isUnionType(tsType: string): boolean {
return tsType === 'number|BigNumber';
},
+ isObjectType(tsType: string): boolean {
+ return /^{.*}$/.test(tsType);
+ },
log(...args: any[]): void {
console.log(...args); // tslint:disable-line:no-console
},