From 161a9d6ad20d7b127ef41a55dc12892e809127e5 Mon Sep 17 00:00:00 2001 From: Olaf Tomalka Date: Sat, 30 Dec 2017 16:13:32 +0100 Subject: Added Event generation to abi-gen --- packages/abi-gen/src/index.ts | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'packages/abi-gen/src/index.ts') diff --git a/packages/abi-gen/src/index.ts b/packages/abi-gen/src/index.ts index 19d289e49..6bd8bfe94 100644 --- a/packages/abi-gen/src/index.ts +++ b/packages/abi-gen/src/index.ts @@ -15,6 +15,7 @@ import {ContextData, ParamKind} from './types'; import {utils} from './utils'; const ABI_TYPE_METHOD = 'function'; +const ABI_TYPE_EVENT = 'event'; const MAIN_TEMPLATE_NAME = 'contract.mustache'; const args = yargs @@ -74,6 +75,7 @@ for (const abiFileName of abiFileNames) { utils.log(`Please make sure your ABI file is either an array with ABI entries or an object with the abi key`); process.exit(1); } + const methodAbis = ABI.filter((abi: Web3.AbiDefinition) => abi.type === ABI_TYPE_METHOD) as Web3.MethodAbi[]; const methodsData = _.map(methodAbis, methodAbi => { _.map(methodAbi.inputs, input => { @@ -89,9 +91,13 @@ for (const abiFileName of abiFileNames) { }; return methodData; }); + + const eventAbis = ABI.filter((abi: Web3.AbiDefinition) => abi.type === ABI_TYPE_EVENT) as Web3.MethodAbi[]; + const contextData = { contractName: namedContent.name, methods: methodsData, + events: eventAbis, }; const renderedTsCode = template(contextData); writeOutputFile(namedContent.name, renderedTsCode); -- cgit v1.2.3 From e744e4cd989bd3ae1070c59f7baa8097f18b8b06 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Fri, 22 Dec 2017 15:05:32 +0100 Subject: Apply prettier config --- packages/abi-gen/src/index.ts | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'packages/abi-gen/src/index.ts') diff --git a/packages/abi-gen/src/index.ts b/packages/abi-gen/src/index.ts index 19d289e49..a74bdf8c4 100644 --- a/packages/abi-gen/src/index.ts +++ b/packages/abi-gen/src/index.ts @@ -2,7 +2,7 @@ import chalk from 'chalk'; import * as fs from 'fs'; -import {sync as globSync} from 'glob'; +import { sync as globSync } from 'glob'; import * as Handlebars from 'handlebars'; import * as _ from 'lodash'; import * as mkdirp from 'mkdirp'; @@ -11,8 +11,8 @@ import * as yargs from 'yargs'; import toSnakeCase = require('to-snake-case'); import * as Web3 from 'web3'; -import {ContextData, ParamKind} from './types'; -import {utils} from './utils'; +import { ContextData, ParamKind } from './types'; +import { utils } from './utils'; const ABI_TYPE_METHOD = 'function'; const MAIN_TEMPLATE_NAME = 'contract.mustache'; @@ -32,8 +32,7 @@ const args = yargs describe: 'Folder where to put the output files', type: 'string', demand: true, - }) - .argv; + }).argv; function writeOutputFile(name: string, renderedTsCode: string): void { const fileName = toSnakeCase(name); @@ -66,9 +65,9 @@ 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 + const ABI = _.isArray(parsedContent) + ? parsedContent // ABI file + : parsedContent.abi; // Truffle contracts file 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`); -- cgit v1.2.3 From 94c75b5262a4837490de33d0968462d6b46546b6 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Wed, 3 Jan 2018 12:05:44 +0100 Subject: Add #302 description to changelog --- packages/abi-gen/src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages/abi-gen/src/index.ts') diff --git a/packages/abi-gen/src/index.ts b/packages/abi-gen/src/index.ts index bcb4a468b..ed71087b2 100644 --- a/packages/abi-gen/src/index.ts +++ b/packages/abi-gen/src/index.ts @@ -91,7 +91,7 @@ for (const abiFileName of abiFileNames) { return methodData; }); - const eventAbis = ABI.filter((abi: Web3.AbiDefinition) => abi.type === ABI_TYPE_EVENT) as Web3.MethodAbi[]; + const eventAbis = ABI.filter((abi: Web3.AbiDefinition) => abi.type === ABI_TYPE_EVENT) as Web3.EventAbi[]; const contextData = { contractName: namedContent.name, -- cgit v1.2.3 From f3b8bac47787a13ea4360b992bbe550bec2c3e19 Mon Sep 17 00:00:00 2001 From: Olaf Tomalka Date: Wed, 3 Jan 2018 15:48:29 +0100 Subject: Added constructor ABIs to abi-gen Additionally if the constructor is not existent in JSON, meaning it's implcite with no parameters, we're explicitly creating one, with actual JSON parameters that it should have. --- packages/abi-gen/src/index.ts | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'packages/abi-gen/src/index.ts') diff --git a/packages/abi-gen/src/index.ts b/packages/abi-gen/src/index.ts index ed71087b2..65dc1c607 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 constructor = ABI.find((abi: Web3.AbiDefinition) => abi.type === ABI_TYPE_CONSTRUCTOR) as Web3.ConstructorAbi; + if (!constructor) { + constructor = 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, + constructor, methods: methodsData, events: eventAbis, }; -- cgit v1.2.3 From e019ae4aed610c4645894c2999871fd3c0b57388 Mon Sep 17 00:00:00 2001 From: Olaf Tomalka Date: Fri, 5 Jan 2018 02:07:25 +0100 Subject: Changes to abi-gen after code review * Added change to CHANGELOG * Renamed variable and context to ctor to avoid keyword * Used lodash' isUndefined to better check ctor --- packages/abi-gen/src/index.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'packages/abi-gen/src/index.ts') diff --git a/packages/abi-gen/src/index.ts b/packages/abi-gen/src/index.ts index 65dc1c607..527af32b1 100644 --- a/packages/abi-gen/src/index.ts +++ b/packages/abi-gen/src/index.ts @@ -76,9 +76,9 @@ for (const abiFileName of abiFileNames) { process.exit(1); } - let constructor = ABI.find((abi: Web3.AbiDefinition) => abi.type === ABI_TYPE_CONSTRUCTOR) as Web3.ConstructorAbi; - if (!constructor) { - constructor = utils.getEmptyConstructor(); // The constructor exists, but it's implicit in JSON's ABI definition + 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[]; @@ -101,7 +101,7 @@ for (const abiFileName of abiFileNames) { const contextData = { contractName: namedContent.name, - constructor, + ctor, methods: methodsData, events: eventAbis, }; -- cgit v1.2.3