Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@0x/abi-gen

Package Overview
Dependencies
Maintainers
6
Versions
87
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@0x/abi-gen - npm Package Compare versions

Comparing version 3.1.2 to 4.1.0

59

CHANGELOG.json
[
{
"timestamp": 1564604963,
"version": "4.1.0",
"changes": [
{
"note": "Updated expected typescript output for cli tests to include `getABIDecodedTransactionData` and `getABIDecodedReturnData`",
"pr": 2018
},
{
"note": "Added tests for`getABIDecodedTransactionData` and `getABIDecodedReturnData` in contract wrappers.",
"pr": 2018
}
],
"timestamp": 1565296576
},
{
"version": "4.0.0",
"changes": [
{
"note": "whitespace changes to generated Python code",
"pr": 1996
},
{
"note": "move Python Validator base class from generated code to common package",
"pr": 1996
},
{
"note": "Changed fundamental thing-to-be-wrapped from the contract to the contract method. That is, now there is a base contract method wrapper class rather than a base contract wrapper class, and individual contract methods are represented by named classes inheriting from that base, and the different operations on a method are now represented by a nested-object dot notation, ie, WrappedContract.ContractMethod.call() and WrappedContract.ContractMethod.send_transaction().",
"pr": 1996
},
{
"note": "added gas estimation functionality to contract methods",
"pr": 1996
},
{
"note": "Python: fixed bug with methods returning multiple values",
"pr": 1996
},
{
"note": "Python: fixed bug with methods returning arrays of structs",
"pr": 1996
},
{
"note": "Python: fixed bug with methods that return a struct that contains another struct where the inner struct was not otherwise directly referenced by any method",
"pr": 1996
},
{
"note": "Python: fixed bug with tuples sometimes being used before they were declared",
"pr": 1996
},
{
"note": "Python: fixed bug with supporting overloaded methods",
"pr": 1996
}
]
},
{
"version": "3.1.2",

@@ -9,3 +63,4 @@ "changes": [

}
]
],
"timestamp": 1564604963
},

@@ -12,0 +67,0 @@ {

@@ -8,2 +8,19 @@ <!--

## v4.1.0 - _August 8, 2019_
* Updated expected typescript output for cli tests to include `getABIDecodedTransactionData` and `getABIDecodedReturnData` (#2018)
* Added tests for`getABIDecodedTransactionData` and `getABIDecodedReturnData` in contract wrappers. (#2018)
## v4.0.0 - _Invalid date_
* whitespace changes to generated Python code (#1996)
* move Python Validator base class from generated code to common package (#1996)
* Changed fundamental thing-to-be-wrapped from the contract to the contract method. That is, now there is a base contract method wrapper class rather than a base contract wrapper class, and individual contract methods are represented by named classes inheriting from that base, and the different operations on a method are now represented by a nested-object dot notation, ie, WrappedContract.ContractMethod.call() and WrappedContract.ContractMethod.send_transaction(). (#1996)
* added gas estimation functionality to contract methods (#1996)
* Python: fixed bug with methods returning multiple values (#1996)
* Python: fixed bug with methods returning arrays of structs (#1996)
* Python: fixed bug with methods that return a struct that contains another struct where the inner struct was not otherwise directly referenced by any method (#1996)
* Python: fixed bug with tuples sometimes being used before they were declared (#1996)
* Python: fixed bug with supporting overloaded methods (#1996)
## v3.1.2 - _July 31, 2019_

@@ -10,0 +27,0 @@

@@ -54,2 +54,3 @@ #!/usr/bin/env node

var mkdirp = require("mkdirp");
var toposort = require("toposort");
var yargs = require("yargs");

@@ -138,2 +139,28 @@ var types_1 = require("./types");

});
// Format docstring for method description
Handlebars.registerHelper('formatDocstringForMethodTs', function (docString) {
// preserve newlines
var regex = /([ ]{4,})+/gi;
var formatted = docString.replace(regex, '\n * ');
return new Handlebars.SafeString(formatted);
});
// Get docstring for method param
Handlebars.registerHelper('getDocstringForParamTs', function (paramName, devdocParamsObj) {
if (devdocParamsObj === undefined || devdocParamsObj[paramName] === undefined) {
return undefined;
}
return new Handlebars.SafeString("" + devdocParamsObj[paramName]);
});
// Format docstring for method param
Handlebars.registerHelper('formatDocstringForParamTs', function (paramName, desc) {
var docString = "@param " + paramName + " " + desc;
var hangingIndentLength = 4;
var config = {
width: 80,
paddingLeft: ' * ',
hangingIndent: ' '.repeat(hangingIndentLength),
ansi: false,
};
return new Handlebars.SafeString("" + cliFormat.wrap(docString, config));
});
}

@@ -150,3 +177,8 @@ function registerPythonHelpers() {

// wrap to 80 columns, assuming given indent, so that generated
// docstrings can pass pycodestyle checks.
// docstrings can pass pycodestyle checks. also, replace repeated
// spaces, likely caused by leading indents in the Solidity, because
// they cause repeated spaces in the output, and in particular they may
// cause repeated spaces at the beginning of a line in the docstring,
// which leads to "unexpected indent" errors when generating
// documentation.
if (devdocDetails === undefined || devdocDetails.length === 0) {

@@ -156,3 +188,3 @@ return '';

var columnsPerRow = 80;
return new Handlebars.SafeString("\n" + cliFormat.wrap(devdocDetails || '', {
return new Handlebars.SafeString("\n" + cliFormat.wrap(devdocDetails.replace(/ +/g, ' ') || '', {
paddingLeft: ' '.repeat(indent),

@@ -177,9 +209,14 @@ width: columnsPerRow,

Handlebars.registerHelper('tupleDefinitions', function (abisJSON) {
var e_3, _a, e_4, _b;
var e_3, _a, e_4, _b, e_5, _c;
var abis = JSON.parse(abisJSON);
// build an array of objects, each of which has one key, the Python
// name of a tuple, with a string value holding the Python
// definition of that tuple. Using a key-value object conveniently
// name of a tuple, with a string value holding the body of a Python
// class representing that tuple. Using a key-value object conveniently
// filters duplicate references to the same tuple.
var tupleDefinitions = {};
var tupleBodies = {};
// build an array of tuple dependencies, whose format conforms to the
// expected input to toposort, a function to do a topological sort,
// which will help us declare tuples in the proper order, avoiding
// references to tuples that haven't been declared yet.
var tupleDependencies = [];
try {

@@ -210,5 +247,3 @@ for (var abis_1 = __values(abis), abis_1_1 = abis_1.next(); !abis_1_1.done; abis_1_1 = abis_1.next()) {

var parameter = parameters_1_1.value;
if (parameter.type === 'tuple') {
tupleDefinitions[utils_2.utils.makePythonTupleName(parameter.components)] = utils_2.utils.makePythonTupleClassBody(parameter.components);
}
utils_2.utils.extractTuples(parameter, tupleBodies, tupleDependencies);
}

@@ -232,12 +267,38 @@ }

}
// build up a list of tuples to declare. the order they're pushed into
// this array is the order they will be declared.
var tuplesToDeclare = [];
// first push the ones that have dependencies
tuplesToDeclare.push.apply(tuplesToDeclare, __spread(toposort(tupleDependencies)));
// then push any remaining bodies (the ones that DON'T have
// dependencies)
for (var pythonTupleName in tupleBodies) {
if (!tuplesToDeclare.includes(pythonTupleName)) {
tuplesToDeclare.push(pythonTupleName);
}
}
// now iterate over those ordered tuples-to-declare, and prefix the
// corresponding class bodies with their class headers, to form full
// class declarations.
var tupleDeclarations = [];
for (var pythonTupleName in tupleDefinitions) {
if (tupleDefinitions[pythonTupleName]) {
tupleDeclarations.push("class " + pythonTupleName + "(TypedDict):\n \"\"\"Python representation of a tuple or struct.\n\n A tuple found in an ABI may have been written in Solidity as a literal\n tuple, or it may have been written as a parameter with a Solidity\n `struct`:code: data type; there's no way to tell which, based solely on the\n ABI, and the name of a Solidity `struct`:code: is not conveyed through the\n ABI. This class represents a tuple that appeared in a method definition.\n Its name is derived from a hash of that tuple's field names, and every\n method whose ABI refers to a tuple with that same list of field names will\n have a generated wrapper method that refers to this class.\n\n Any members of type `bytes`:code: should be encoded as UTF-8, which can be\n accomplished via `str.encode(\"utf_8\")`:code:\n \"\"\"" + tupleDefinitions[pythonTupleName]);
try {
for (var tuplesToDeclare_1 = __values(tuplesToDeclare), tuplesToDeclare_1_1 = tuplesToDeclare_1.next(); !tuplesToDeclare_1_1.done; tuplesToDeclare_1_1 = tuplesToDeclare_1.next()) {
var pythonTupleName = tuplesToDeclare_1_1.value;
if (tupleBodies[pythonTupleName]) {
tupleDeclarations.push("class " + pythonTupleName + "(TypedDict):\n \"\"\"Python representation of a tuple or struct.\n\n Solidity compiler output does not include the names of structs that appear\n in method definitions. A tuple found in an ABI may have been written in\n Solidity as a literal, anonymous tuple, or it may have been written as a\n named `struct`:code:, but there is no way to tell from the compiler\n output. This class represents a tuple that appeared in a method\n definition. Its name is derived from a hash of that tuple's field names,\n and every method whose ABI refers to a tuple with that same list of field\n names will have a generated wrapper method that refers to this class.\n\n Any members of type `bytes`:code: should be encoded as UTF-8, which can be\n accomplished via `str.encode(\"utf_8\")`:code:\n \"\"\"" + tupleBodies[pythonTupleName]);
}
}
}
return new Handlebars.SafeString(tupleDeclarations.join('\n\n'));
catch (e_5_1) { e_5 = { error: e_5_1 }; }
finally {
try {
if (tuplesToDeclare_1_1 && !tuplesToDeclare_1_1.done && (_c = tuplesToDeclare_1.return)) _c.call(tuplesToDeclare_1);
}
finally { if (e_5) throw e_5.error; }
}
// finally, join the class declarations together for the output file
return new Handlebars.SafeString(tupleDeclarations.join('\n\n\n'));
});
Handlebars.registerHelper('docBytesIfNecessary', function (abisJSON) {
var e_5, _a, e_6, _b;
var e_6, _a, e_7, _b;
var abis = JSON.parse(abisJSON);

@@ -267,3 +328,3 @@ try {

}
catch (e_6_1) { e_6 = { error: e_6_1 }; }
catch (e_7_1) { e_7 = { error: e_7_1 }; }
finally {

@@ -273,3 +334,3 @@ try {

}
finally { if (e_6) throw e_6.error; }
finally { if (e_7) throw e_7.error; }
}

@@ -280,3 +341,3 @@ }

}
catch (e_5_1) { e_5 = { error: e_5_1 }; }
catch (e_6_1) { e_6 = { error: e_6_1 }; }
finally {

@@ -286,6 +347,7 @@ try {

}
finally { if (e_5) throw e_5.error; }
finally { if (e_6) throw e_6.error; }
}
return '';
});
Handlebars.registerHelper('toPythonClassname', function (sourceName) { return new Handlebars.SafeString(changeCase.pascal(sourceName)); });
}

@@ -292,0 +354,0 @@ if (args.language === 'TypeScript') {

@@ -43,3 +43,6 @@ import { ConstructorAbi, DataItem } from 'ethereum-types';

wrapPythonDocstringRole(docstring: string, indent: number): string;
extractTuples(parameter: DataItem, tupleBodies: {
[pythonTupleName: string]: string;
}, tupleDependencies: [string, string][]): void;
};
//# sourceMappingURL=utils.d.ts.map

@@ -401,3 +401,35 @@ "use strict";

},
extractTuples: function (parameter, tupleBodies, // output
tupleDependencies) {
var e_5, _a;
if (parameter.type === 'tuple' || parameter.type === 'tuple[]') {
var tupleDataItem = parameter; // tslint:disable-line:no-unnecessary-type-assertion
// without the above cast (which tslint complains about), tsc says
// Argument of type 'DataItem[] | undefined' is not assignable to parameter of type 'DataItem[]'.
// Type 'undefined' is not assignable to type 'DataItem[]'
// when the code below tries to access tupleDataItem.components.
var pythonTupleName = exports.utils.makePythonTupleName(tupleDataItem.components);
tupleBodies[pythonTupleName] = exports.utils.makePythonTupleClassBody(tupleDataItem.components);
try {
for (var _b = __values(tupleDataItem.components), _c = _b.next(); !_c.done; _c = _b.next()) {
var component = _c.value;
if (component.type === 'tuple' || component.type === 'tuple[]') {
tupleDependencies.push([
exports.utils.makePythonTupleName(component.components),
pythonTupleName,
]);
exports.utils.extractTuples(component, tupleBodies, tupleDependencies);
}
}
}
catch (e_5_1) { e_5 = { error: e_5_1 }; }
finally {
try {
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
}
finally { if (e_5) throw e_5.error; }
}
}
},
};
//# sourceMappingURL=utils.js.map

21

package.json
{
"name": "@0x/abi-gen",
"version": "3.1.2",
"version": "4.1.0",
"engines": {

@@ -26,2 +26,3 @@ "node": ">=6.12"

"test_cli:run_mocha": "mocha --require source-map-support/register --require make-promises-safe test-cli/test_typescript/lib/**/*_test.js --timeout 100000 --bail --exit",
"test_cli:test_python": "black --check test-cli/output/python/**/__init__.py; test $? -le 1 # just make sure black can parse the output",
"rebuild_and_test": "run-s build test",

@@ -62,3 +63,4 @@ "test:profiler": "SOLIDITY_PROFILER=true run-s build run_mocha profiler:report:html",

"@0x/typescript-typings": "^4.2.4",
"@0x/utils": "^4.4.2",
"@0x/utils": "^4.5.0",
"@types/toposort": "^2.0.1",
"chalk": "^2.3.0",

@@ -74,12 +76,13 @@ "change-case": "^3.0.2",

"to-snake-case": "^1.0.0",
"toposort": "^2.0.2",
"yargs": "^10.0.3"
},
"devDependencies": {
"@0x/base-contract": "^5.3.0",
"@0x/contracts-gen": "^1.0.12",
"@0x/dev-utils": "^2.2.6",
"@0x/sol-compiler": "^3.1.11",
"@0x/subproviders": "^5.0.0",
"@0x/base-contract": "^5.3.1",
"@0x/contracts-gen": "^1.0.13",
"@0x/dev-utils": "^2.3.0",
"@0x/sol-compiler": "^3.1.12",
"@0x/subproviders": "^5.0.1",
"@0x/tslint-config": "^3.0.1",
"@0x/web3-wrapper": "^6.0.9",
"@0x/web3-wrapper": "^6.0.10",
"@types/glob": "5.0.35",

@@ -107,3 +110,3 @@ "@types/mkdirp": "^0.5.2",

},
"gitHead": "d36eb04ae83e35e918f1497c86e0cc7a92e124c5"
"gitHead": "f394d7dba9d9cdf31d5793ace9ebe605d5a2c24c"
}

@@ -113,3 +113,3 @@ # ABI Gen

```
yarn test_cli:prebuild
yarn compile:sol
```

@@ -116,0 +116,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc