diff options
author | Amir Bandeali <abandeali1@gmail.com> | 2018-02-06 05:02:48 +0800 |
---|---|---|
committer | Amir Bandeali <abandeali1@gmail.com> | 2018-02-07 09:26:12 +0800 |
commit | 897515c00207a11f7a45932d3c526a5eaf961635 (patch) | |
tree | 9282ffabd4242c73af49154fa963ebc3378bd935 /packages/abi-gen | |
parent | 4c9c4c487a034d926443eeb8a0154fd38c97aca3 (diff) | |
download | dexon-sol-tools-897515c00207a11f7a45932d3c526a5eaf961635.tar dexon-sol-tools-897515c00207a11f7a45932d3c526a5eaf961635.tar.gz dexon-sol-tools-897515c00207a11f7a45932d3c526a5eaf961635.tar.bz2 dexon-sol-tools-897515c00207a11f7a45932d3c526a5eaf961635.tar.lz dexon-sol-tools-897515c00207a11f7a45932d3c526a5eaf961635.tar.xz dexon-sol-tools-897515c00207a11f7a45932d3c526a5eaf961635.tar.zst dexon-sol-tools-897515c00207a11f7a45932d3c526a5eaf961635.zip |
Add CLI option for networkId, add abi-gen to contracts package
Diffstat (limited to 'packages/abi-gen')
-rw-r--r-- | packages/abi-gen/CHANGELOG.md | 1 | ||||
-rw-r--r-- | packages/abi-gen/src/index.ts | 18 |
2 files changed, 16 insertions, 3 deletions
diff --git a/packages/abi-gen/CHANGELOG.md b/packages/abi-gen/CHANGELOG.md index ffa8a7a35..570c76bdd 100644 --- a/packages/abi-gen/CHANGELOG.md +++ b/packages/abi-gen/CHANGELOG.md @@ -3,6 +3,7 @@ ## v0.2.0 - _???_ * Added CLI options for explicit specifying location of partials and main template (#346) +* Added CLI option to specify networkId, adding support for the JSON artifact format found in @0xproject/contracts ## v0.1.0 - _January 11, 2018_ diff --git a/packages/abi-gen/src/index.ts b/packages/abi-gen/src/index.ts index fe2b56524..85cc67daf 100644 --- a/packages/abi-gen/src/index.ts +++ b/packages/abi-gen/src/index.ts @@ -17,6 +17,7 @@ import { utils } from './utils'; const ABI_TYPE_CONSTRUCTOR = 'constructor'; const ABI_TYPE_METHOD = 'function'; const ABI_TYPE_EVENT = 'event'; +const DEFAULT_NETWORK_ID = 50; const args = yargs .option('abis', { @@ -42,6 +43,12 @@ const args = yargs demandOption: true, normalize: true, }) + .option('network-id', { + describe: 'ID of the network where contract ABIs are nested in artifacts', + type: 'number', + default: DEFAULT_NETWORK_ID, + + }) .example( "$0 --abis 'src/artifacts/**/*.json' --out 'src/contracts/generated/' --partials 'src/templates/partials/**/*.handlebars' --template 'src/templates/contract.handlebars'", 'Full usage example', @@ -87,9 +94,14 @@ for (const abiFileName of abiFileNames) { const namedContent = utils.getNamedContent(abiFileName); utils.log(`Processing: ${chalk.bold(namedContent.name)}...`); const parsedContent = JSON.parse(namedContent.content); - const ABI = _.isArray(parsedContent) - ? parsedContent // ABI file - : parsedContent.abi; // Truffle contracts file + let ABI; + if (_.isArray(parsedContent)) { + ABI = parsedContent; // ABI file + } else if (!_.isUndefined(parsedContent.abi)) { + ABI = parsedContent.abi; // Truffle artifact + } else if (!_.isUndefined(parsedContent.networks) && !_.isUndefined(parsedContent.networks[args.networkId])) { + ABI = parsedContent.networks[args.networkId]; // 0x contracts package artifact + } if (_.isUndefined(ABI)) { utils.log(`${chalk.red(`ABI not found in ${abiFileName}.`)}`); utils.log(`Please make sure your ABI file is either an array with ABI entries or an object with the abi key`); |