Generate wrappers for all contracts (#2010)

* abi-gen/Py: fix return type for multi-val returns

Methods that return multiple values were broken in two ways.  One: a
spurious newline was being injected between the return type and the
colon ending the Python method prototype.  Two: the return type was
being generated as just `[TypeA, TypeB]`, whereas it should be
`Tuple[TypeA, TypeB]`.

* abi-gen/Py: fix support for arrays of structs

* abi-gen/Py: FAILING test case nested unrefd struct

When a struct contains another struct, and the inner struct is not
directly referenced by any method interface, wrapper generation is
failing to render a class to represent the inner struct.

This won't fail in CI because at this time CI doesn't run any native
Python tooling to analyze the generated code.  Running mypy locally on
the files in this commit produces the following output:

test-cli/output/python/abi_gen_dummy/__init__.py:76: error: Name 'Tuple0x246f9407' is not defined

This problem affects the generation of wrappers for the DutchAuction
contract.

* abi-gen/Py: fix nested unref'd struct failure

* abi-gen/Py: introduce newlines to quiet linter

When generating contracts with long names (eg
CoordinatorRegistryValidator), the `black` reformatter was introducing
these newlines for us, and it was moving the `# type: ignore` comment in
there such that it no longer was on the line it needed to be on.
Introducing these newlines manually (instead of letting black inject
them) allows the linter directive to stay where it needs to be.

* abi-gen/Py: declare tuples in dependency order

* abi-gen/Py: fix support for overloaded methods

* contract_wrappers.py: pylint: permit 2-char args

By default pylint says that 2 characters is too short for an argument
name, but we have some contract methods with 2-character argument names
(eg `to` in `AssetProxyOwner.getTransactionIds()`), so we want to permit
them.

* contract_wrappers.py: include all contracts

* Update CHANGELOGs

* abi-gen: rename variable

* abi-gen: refine comments

* abi-gen/Py: reword tuple class docstring
This commit is contained in:
F. Eugene Aumson 2019-08-07 12:44:16 -04:00 committed by GitHub
parent e682b82ca8
commit 5ac7ff7084
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
37 changed files with 1062 additions and 107 deletions

18
.gitignore vendored
View File

@ -114,6 +114,24 @@ contracts/exchange-forwarder/generated-wrappers/
contracts/dev-utils/generated-wrappers/
python-packages/contract_wrappers/src/zero_ex/contract_wrappers/erc20_token/__init__.py
python-packages/contract_wrappers/src/zero_ex/contract_wrappers/exchange/__init__.py
python-packages/contract_wrappers/src/zero_ex/contract_wrappers/asset_proxy_owner/__init__.py
python-packages/contract_wrappers/src/zero_ex/contract_wrappers/coordinator/__init__.py
python-packages/contract_wrappers/src/zero_ex/contract_wrappers/coordinator_registry/__init__.py
python-packages/contract_wrappers/src/zero_ex/contract_wrappers/dummy_erc20_token/__init__.py
python-packages/contract_wrappers/src/zero_ex/contract_wrappers/dummy_erc721_token/__init__.py
python-packages/contract_wrappers/src/zero_ex/contract_wrappers/dutch_auction/__init__.py
python-packages/contract_wrappers/src/zero_ex/contract_wrappers/erc20_proxy/__init__.py
python-packages/contract_wrappers/src/zero_ex/contract_wrappers/erc721_proxy/__init__.py
python-packages/contract_wrappers/src/zero_ex/contract_wrappers/erc721_token/__init__.py
python-packages/contract_wrappers/src/zero_ex/contract_wrappers/eth_balance_checker/__init__.py
python-packages/contract_wrappers/src/zero_ex/contract_wrappers/forwarder/__init__.py
python-packages/contract_wrappers/src/zero_ex/contract_wrappers/i_asset_proxy/__init__.py
python-packages/contract_wrappers/src/zero_ex/contract_wrappers/i_validator/__init__.py
python-packages/contract_wrappers/src/zero_ex/contract_wrappers/i_wallet/__init__.py
python-packages/contract_wrappers/src/zero_ex/contract_wrappers/multi_asset_proxy/__init__.py
python-packages/contract_wrappers/src/zero_ex/contract_wrappers/order_validator/__init__.py
python-packages/contract_wrappers/src/zero_ex/contract_wrappers/weth9/__init__.py
python-packages/contract_wrappers/src/zero_ex/contract_wrappers/zrx_token/__init__.py
# cli test output
packages/abi-gen/test-cli/output

View File

@ -34,7 +34,9 @@ try:
)
except ImportError:
class {{contractName}}Validator(Validator): # type: ignore
class {{contractName}}Validator( # type: ignore
Validator
):
"""No-op input validator."""
@ -48,7 +50,7 @@ except ImportError:
class {{contractName}}:
"""Wrapper class for {{contractName}} Solidity contract.{{docBytesIfNecessary ABIString}}"""
{{#each methods}}
{{toPythonIdentifier this.name}}: {{toPythonClassname this.name}}Method
{{toPythonIdentifier this.languageSpecificName}}: {{toPythonClassname this.languageSpecificName}}Method
{{/each}}
def __init__(
@ -75,7 +77,7 @@ class {{contractName}}:
functions = self._web3_eth.contract(address=to_checksum_address(contract_address), abi={{contractName}}.abi()).functions
{{#each methods}}
self.{{toPythonIdentifier this.name}} = {{toPythonClassname this.name}}Method(provider, contract_address, functions.{{this.name}}, validator)
self.{{toPythonIdentifier this.languageSpecificName}} = {{toPythonClassname this.languageSpecificName}}Method(provider, contract_address, functions.{{this.name}}, validator)
{{/each}}
{{#each events}}

View File

@ -1,5 +1,5 @@
class {{toPythonClassname this.name}}Method(ContractMethod):
class {{toPythonClassname this.languageSpecificName}}Method(ContractMethod):
"""Various interfaces to the {{this.name}} method."""
def __init__(self, provider: BaseProvider, contract_address: str, contract_function: ContractFunction, validator: Validator=None):

View File

@ -7,8 +7,8 @@ Union[
{{#returnType outputs.0.type outputs.0.components}}{{~/returnType~}}
{{/singleReturnValue}}
{{^singleReturnValue}}
[{{#each outputs}}{{#returnType type components}}{{/returnType}}{{#unless @last}}, {{/unless}}{{/each}}]
{{/singleReturnValue}}
Tuple[{{#each outputs}}{{#returnType type components}}{{/returnType}}{{#unless @last}}, {{/unless}}{{/each}}]
{{~/singleReturnValue}}
{{else}}None
{{/if}}{{^if this.constant}}, Union[HexBytes, bytes]]{{/if~}}
{{else}}{{#if this.constant}}None{{else}}Union[None, Union[HexBytes, bytes]]{{/if}}{{/if~}}

View File

@ -30,6 +30,26 @@
{
"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
}
]
},

View File

@ -60,6 +60,7 @@
"@0x/types": "^2.4.1",
"@0x/typescript-typings": "^4.2.4",
"@0x/utils": "^4.4.2",
"@types/toposort": "^2.0.1",
"chalk": "^2.3.0",
"change-case": "^3.0.2",
"cli-format": "^3.0.9",
@ -70,6 +71,7 @@
"mkdirp": "^0.5.1",
"tmp": "^0.0.33",
"to-snake-case": "^1.0.0",
"toposort": "^2.0.2",
"yargs": "^10.0.3"
},
"devDependencies": {

View File

@ -12,12 +12,12 @@ import {
DevdocOutput,
EventAbi,
MethodAbi,
TupleDataItem,
} from 'ethereum-types';
import { sync as globSync } from 'glob';
import * as Handlebars from 'handlebars';
import * as _ from 'lodash';
import * as mkdirp from 'mkdirp';
import toposort = require('toposort');
import * as yargs from 'yargs';
import { ContextData, ContractsBackend, ParamKind } from './types';
@ -191,10 +191,15 @@ function registerPythonHelpers(): void {
Handlebars.registerHelper('tupleDefinitions', (abisJSON: string) => {
const abis: AbiDefinition[] = 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.
const tupleDefinitions: { [pythonTupleName: string]: string } = {};
const tupleBodies: { [pythonTupleName: string]: string } = {};
// 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.
const tupleDependencies: Array<[string, string]> = [];
for (const abi of abis) {
let parameters: DataItem[] = [];
if (abi.hasOwnProperty('inputs')) {
@ -216,24 +221,36 @@ function registerPythonHelpers(): void {
parameters = parameters.concat((abi as MethodAbi).outputs);
}
for (const parameter of parameters) {
if (parameter.type === 'tuple') {
tupleDefinitions[
utils.makePythonTupleName((parameter as TupleDataItem).components)
] = utils.makePythonTupleClassBody((parameter as TupleDataItem).components);
}
utils.extractTuples(parameter, tupleBodies, tupleDependencies);
}
}
// build up a list of tuples to declare. the order they're pushed into
// this array is the order they will be declared.
const tuplesToDeclare = [];
// first push the ones that have dependencies
tuplesToDeclare.push(...toposort(tupleDependencies));
// then push any remaining bodies (the ones that DON'T have
// dependencies)
for (const 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.
const tupleDeclarations = [];
for (const pythonTupleName in tupleDefinitions) {
if (tupleDefinitions[pythonTupleName]) {
for (const pythonTupleName of tuplesToDeclare) {
if (tupleBodies[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]
`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'));
// finally, join the class declarations together for the output file
return new Handlebars.SafeString(tupleDeclarations.join('\n\n\n'));
});
Handlebars.registerHelper('docBytesIfNecessary', (abisJSON: string) => {
const abis: AbiDefinition[] = JSON.parse(abisJSON);

View File

@ -2,7 +2,7 @@ import { createHash } from 'crypto';
import * as changeCase from 'change-case';
import * as cliFormat from 'cli-format';
import { AbiType, ConstructorAbi, DataItem } from 'ethereum-types';
import { AbiType, ConstructorAbi, DataItem, TupleDataItem } from 'ethereum-types';
import * as fs from 'fs';
import * as _ from 'lodash';
import * as path from 'path';
@ -350,4 +350,28 @@ export const utils = {
hangingIndent: ' '.repeat(columnsPerIndent),
});
},
extractTuples(
parameter: DataItem,
tupleBodies: { [pythonTupleName: string]: string }, // output
tupleDependencies: Array<[string, string]>, // output
): void {
if (parameter.type === 'tuple' || parameter.type === 'tuple[]') {
const tupleDataItem = parameter as TupleDataItem; // 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.
const pythonTupleName = utils.makePythonTupleName(tupleDataItem.components);
tupleBodies[pythonTupleName] = utils.makePythonTupleClassBody(tupleDataItem.components);
for (const component of tupleDataItem.components) {
if (component.type === 'tuple' || component.type === 'tuple[]') {
tupleDependencies.push([
utils.makePythonTupleName((component as TupleDataItem).components), // tslint:disable-line:no-unnecessary-type-assertion
pythonTupleName,
]);
utils.extractTuples(component, tupleBodies, tupleDependencies);
}
}
}
},
};

File diff suppressed because one or more lines are too long

View File

@ -34,7 +34,9 @@ try:
)
except ImportError:
class LibDummyValidator(Validator): # type: ignore
class LibDummyValidator( # type: ignore
Validator
):
"""No-op input validator."""

View File

@ -34,7 +34,9 @@ try:
)
except ImportError:
class TestLibDummyValidator(Validator): # type: ignore
class TestLibDummyValidator( # type: ignore
Validator
):
"""No-op input validator."""

View File

@ -836,6 +836,79 @@ export class AbiGenDummyContract extends BaseContract {
return abiDecodedReturnData;
},
};
public methodUsingNestedStructWithInnerStructNotUsedElsewhere = {
/**
* Sends a read-only call to the contract method. Returns the result that would happen if one were to send an
* Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas
* since they don't modify state.
*/
async callAsync(
callData: Partial<CallData> = {},
defaultBlock?: BlockParam,
): Promise<{ innerStruct: { aField: BigNumber } }> {
assert.doesConformToSchema('callData', callData, schemas.callDataSchema, [
schemas.addressSchema,
schemas.numberSchema,
schemas.jsNumber,
]);
if (defaultBlock !== undefined) {
assert.isBlockParam('defaultBlock', defaultBlock);
}
const self = (this as any) as AbiGenDummyContract;
const encodedData = self._strictEncodeArguments(
'methodUsingNestedStructWithInnerStructNotUsedElsewhere()',
[],
);
const callDataWithDefaults = await BaseContract._applyDefaultsToTxDataAsync(
{
to: self.address,
...callData,
data: encodedData,
},
self._web3Wrapper.getContractDefaults(),
);
callDataWithDefaults.from = callDataWithDefaults.from
? callDataWithDefaults.from.toLowerCase()
: callDataWithDefaults.from;
const rawCallResult = await self._web3Wrapper.callAsync(callDataWithDefaults, defaultBlock);
BaseContract._throwIfRevertWithReasonCallResult(rawCallResult);
const abiEncoder = self._lookupAbiEncoder('methodUsingNestedStructWithInnerStructNotUsedElsewhere()');
// tslint:disable boolean-naming
const result = abiEncoder.strictDecodeReturnValue<{ innerStruct: { aField: BigNumber } }>(rawCallResult);
// tslint:enable boolean-naming
return result;
},
/**
* Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before
* sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used
* to create a 0x transaction (see protocol spec for more details).
*/
getABIEncodedTransactionData(): string {
const self = (this as any) as AbiGenDummyContract;
const abiEncodedTransactionData = self._strictEncodeArguments(
'methodUsingNestedStructWithInnerStructNotUsedElsewhere()',
[],
);
return abiEncodedTransactionData;
},
getABIDecodedTransactionData(callData: string): { innerStruct: { aField: BigNumber } } {
const self = (this as any) as AbiGenDummyContract;
const abiEncoder = self._lookupAbiEncoder('methodUsingNestedStructWithInnerStructNotUsedElsewhere()');
// tslint:disable boolean-naming
const abiDecodedCallData = abiEncoder.strictDecode<{ innerStruct: { aField: BigNumber } }>(callData);
return abiDecodedCallData;
},
getABIDecodedReturnData(returnData: string): { innerStruct: { aField: BigNumber } } {
const self = (this as any) as AbiGenDummyContract;
const abiEncoder = self._lookupAbiEncoder('methodUsingNestedStructWithInnerStructNotUsedElsewhere()');
// tslint:disable boolean-naming
const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue<{ innerStruct: { aField: BigNumber } }>(
returnData,
);
return abiDecodedReturnData;
},
};
public nestedStructOutput = {
/**
* Sends a read-only call to the contract method. Returns the result that would happen if one were to send an
@ -1794,6 +1867,143 @@ export class AbiGenDummyContract extends BaseContract {
return abiDecodedReturnData;
},
};
public methodReturningMultipleValues = {
/**
* Sends a read-only call to the contract method. Returns the result that would happen if one were to send an
* Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas
* since they don't modify state.
*/
async callAsync(callData: Partial<CallData> = {}, defaultBlock?: BlockParam): Promise<[BigNumber, string]> {
assert.doesConformToSchema('callData', callData, schemas.callDataSchema, [
schemas.addressSchema,
schemas.numberSchema,
schemas.jsNumber,
]);
if (defaultBlock !== undefined) {
assert.isBlockParam('defaultBlock', defaultBlock);
}
const self = (this as any) as AbiGenDummyContract;
const encodedData = self._strictEncodeArguments('methodReturningMultipleValues()', []);
const callDataWithDefaults = await BaseContract._applyDefaultsToTxDataAsync(
{
to: self.address,
...callData,
data: encodedData,
},
self._web3Wrapper.getContractDefaults(),
);
callDataWithDefaults.from = callDataWithDefaults.from
? callDataWithDefaults.from.toLowerCase()
: callDataWithDefaults.from;
const rawCallResult = await self._web3Wrapper.callAsync(callDataWithDefaults, defaultBlock);
BaseContract._throwIfRevertWithReasonCallResult(rawCallResult);
const abiEncoder = self._lookupAbiEncoder('methodReturningMultipleValues()');
// tslint:disable boolean-naming
const result = abiEncoder.strictDecodeReturnValue<[BigNumber, string]>(rawCallResult);
// tslint:enable boolean-naming
return result;
},
/**
* Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before
* sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used
* to create a 0x transaction (see protocol spec for more details).
*/
getABIEncodedTransactionData(): string {
const self = (this as any) as AbiGenDummyContract;
const abiEncodedTransactionData = self._strictEncodeArguments('methodReturningMultipleValues()', []);
return abiEncodedTransactionData;
},
getABIDecodedTransactionData(callData: string): [BigNumber, string] {
const self = (this as any) as AbiGenDummyContract;
const abiEncoder = self._lookupAbiEncoder('methodReturningMultipleValues()');
// tslint:disable boolean-naming
const abiDecodedCallData = abiEncoder.strictDecode<[BigNumber, string]>(callData);
return abiDecodedCallData;
},
getABIDecodedReturnData(returnData: string): [BigNumber, string] {
const self = (this as any) as AbiGenDummyContract;
const abiEncoder = self._lookupAbiEncoder('methodReturningMultipleValues()');
// tslint:disable boolean-naming
const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue<[BigNumber, string]>(returnData);
return abiDecodedReturnData;
},
};
public methodReturningArrayOfStructs = {
/**
* Sends a read-only call to the contract method. Returns the result that would happen if one were to send an
* Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas
* since they don't modify state.
*/
async callAsync(
callData: Partial<CallData> = {},
defaultBlock?: BlockParam,
): Promise<Array<{ someBytes: string; anInteger: number; aDynamicArrayOfBytes: string[]; aString: string }>> {
assert.doesConformToSchema('callData', callData, schemas.callDataSchema, [
schemas.addressSchema,
schemas.numberSchema,
schemas.jsNumber,
]);
if (defaultBlock !== undefined) {
assert.isBlockParam('defaultBlock', defaultBlock);
}
const self = (this as any) as AbiGenDummyContract;
const encodedData = self._strictEncodeArguments('methodReturningArrayOfStructs()', []);
const callDataWithDefaults = await BaseContract._applyDefaultsToTxDataAsync(
{
to: self.address,
...callData,
data: encodedData,
},
self._web3Wrapper.getContractDefaults(),
);
callDataWithDefaults.from = callDataWithDefaults.from
? callDataWithDefaults.from.toLowerCase()
: callDataWithDefaults.from;
const rawCallResult = await self._web3Wrapper.callAsync(callDataWithDefaults, defaultBlock);
BaseContract._throwIfRevertWithReasonCallResult(rawCallResult);
const abiEncoder = self._lookupAbiEncoder('methodReturningArrayOfStructs()');
// tslint:disable boolean-naming
const result = abiEncoder.strictDecodeReturnValue<
Array<{ someBytes: string; anInteger: number; aDynamicArrayOfBytes: string[]; aString: string }>
>(rawCallResult);
// tslint:enable boolean-naming
return result;
},
/**
* Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before
* sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used
* to create a 0x transaction (see protocol spec for more details).
*/
getABIEncodedTransactionData(): string {
const self = (this as any) as AbiGenDummyContract;
const abiEncodedTransactionData = self._strictEncodeArguments('methodReturningArrayOfStructs()', []);
return abiEncodedTransactionData;
},
getABIDecodedTransactionData(
callData: string,
): Array<{ someBytes: string; anInteger: number; aDynamicArrayOfBytes: string[]; aString: string }> {
const self = (this as any) as AbiGenDummyContract;
const abiEncoder = self._lookupAbiEncoder('methodReturningArrayOfStructs()');
// tslint:disable boolean-naming
const abiDecodedCallData = abiEncoder.strictDecode<
Array<{ someBytes: string; anInteger: number; aDynamicArrayOfBytes: string[]; aString: string }>
>(callData);
return abiDecodedCallData;
},
getABIDecodedReturnData(
returnData: string,
): Array<{ someBytes: string; anInteger: number; aDynamicArrayOfBytes: string[]; aString: string }> {
const self = (this as any) as AbiGenDummyContract;
const abiEncoder = self._lookupAbiEncoder('methodReturningArrayOfStructs()');
// tslint:disable boolean-naming
const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue<
Array<{ someBytes: string; anInteger: number; aDynamicArrayOfBytes: string[]; aString: string }>
>(returnData);
return abiDecodedReturnData;
},
};
/**
* a method that returns a struct
*/
@ -2015,6 +2225,134 @@ export class AbiGenDummyContract extends BaseContract {
return abiDecodedReturnData;
},
};
public overloadedMethod2 = {
/**
* Sends a read-only call to the contract method. Returns the result that would happen if one were to send an
* Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas
* since they don't modify state.
*/
async callAsync(a: string, callData: Partial<CallData> = {}, defaultBlock?: BlockParam): Promise<void> {
assert.isString('a', a);
assert.doesConformToSchema('callData', callData, schemas.callDataSchema, [
schemas.addressSchema,
schemas.numberSchema,
schemas.jsNumber,
]);
if (defaultBlock !== undefined) {
assert.isBlockParam('defaultBlock', defaultBlock);
}
const self = (this as any) as AbiGenDummyContract;
const encodedData = self._strictEncodeArguments('overloadedMethod(string)', [a]);
const callDataWithDefaults = await BaseContract._applyDefaultsToTxDataAsync(
{
to: self.address,
...callData,
data: encodedData,
},
self._web3Wrapper.getContractDefaults(),
);
callDataWithDefaults.from = callDataWithDefaults.from
? callDataWithDefaults.from.toLowerCase()
: callDataWithDefaults.from;
const rawCallResult = await self._web3Wrapper.callAsync(callDataWithDefaults, defaultBlock);
BaseContract._throwIfRevertWithReasonCallResult(rawCallResult);
const abiEncoder = self._lookupAbiEncoder('overloadedMethod(string)');
// tslint:disable boolean-naming
const result = abiEncoder.strictDecodeReturnValue<void>(rawCallResult);
// tslint:enable boolean-naming
return result;
},
/**
* Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before
* sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used
* to create a 0x transaction (see protocol spec for more details).
*/
getABIEncodedTransactionData(a: string): string {
assert.isString('a', a);
const self = (this as any) as AbiGenDummyContract;
const abiEncodedTransactionData = self._strictEncodeArguments('overloadedMethod(string)', [a]);
return abiEncodedTransactionData;
},
getABIDecodedTransactionData(callData: string): void {
const self = (this as any) as AbiGenDummyContract;
const abiEncoder = self._lookupAbiEncoder('overloadedMethod(string)');
// tslint:disable boolean-naming
const abiDecodedCallData = abiEncoder.strictDecode<void>(callData);
return abiDecodedCallData;
},
getABIDecodedReturnData(returnData: string): void {
const self = (this as any) as AbiGenDummyContract;
const abiEncoder = self._lookupAbiEncoder('overloadedMethod(string)');
// tslint:disable boolean-naming
const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue<void>(returnData);
return abiDecodedReturnData;
},
};
public overloadedMethod1 = {
/**
* Sends a read-only call to the contract method. Returns the result that would happen if one were to send an
* Ethereum transaction to this method, given the current state of the blockchain. Calls do not cost gas
* since they don't modify state.
*/
async callAsync(a: BigNumber, callData: Partial<CallData> = {}, defaultBlock?: BlockParam): Promise<void> {
assert.isBigNumber('a', a);
assert.doesConformToSchema('callData', callData, schemas.callDataSchema, [
schemas.addressSchema,
schemas.numberSchema,
schemas.jsNumber,
]);
if (defaultBlock !== undefined) {
assert.isBlockParam('defaultBlock', defaultBlock);
}
const self = (this as any) as AbiGenDummyContract;
const encodedData = self._strictEncodeArguments('overloadedMethod(int256)', [a]);
const callDataWithDefaults = await BaseContract._applyDefaultsToTxDataAsync(
{
to: self.address,
...callData,
data: encodedData,
},
self._web3Wrapper.getContractDefaults(),
);
callDataWithDefaults.from = callDataWithDefaults.from
? callDataWithDefaults.from.toLowerCase()
: callDataWithDefaults.from;
const rawCallResult = await self._web3Wrapper.callAsync(callDataWithDefaults, defaultBlock);
BaseContract._throwIfRevertWithReasonCallResult(rawCallResult);
const abiEncoder = self._lookupAbiEncoder('overloadedMethod(int256)');
// tslint:disable boolean-naming
const result = abiEncoder.strictDecodeReturnValue<void>(rawCallResult);
// tslint:enable boolean-naming
return result;
},
/**
* Returns the ABI encoded transaction data needed to send an Ethereum transaction calling this method. Before
* sending the Ethereum tx, this encoded tx data can first be sent to a separate signing service or can be used
* to create a 0x transaction (see protocol spec for more details).
*/
getABIEncodedTransactionData(a: BigNumber): string {
assert.isBigNumber('a', a);
const self = (this as any) as AbiGenDummyContract;
const abiEncodedTransactionData = self._strictEncodeArguments('overloadedMethod(int256)', [a]);
return abiEncodedTransactionData;
},
getABIDecodedTransactionData(callData: string): void {
const self = (this as any) as AbiGenDummyContract;
const abiEncoder = self._lookupAbiEncoder('overloadedMethod(int256)');
// tslint:disable boolean-naming
const abiDecodedCallData = abiEncoder.strictDecode<void>(callData);
return abiDecodedCallData;
},
getABIDecodedReturnData(returnData: string): void {
const self = (this as any) as AbiGenDummyContract;
const abiEncoder = self._lookupAbiEncoder('overloadedMethod(int256)');
// tslint:disable boolean-naming
const abiDecodedReturnData = abiEncoder.strictDecodeReturnValue<void>(returnData);
return abiDecodedReturnData;
},
};
private readonly _subscriptionManager: SubscriptionManager<AbiGenDummyEventArgs, AbiGenDummyEvents>;
public static async deployFrom0xArtifactAsync(
artifact: ContractArtifact | SimpleContractArtifact,
@ -2251,6 +2589,32 @@ export class AbiGenDummyContract extends BaseContract {
stateMutability: 'pure',
type: 'function',
},
{
constant: true,
inputs: [],
name: 'methodUsingNestedStructWithInnerStructNotUsedElsewhere',
outputs: [
{
name: '',
type: 'tuple',
components: [
{
name: 'innerStruct',
type: 'tuple',
components: [
{
name: 'aField',
type: 'uint256',
},
],
},
],
},
],
payable: false,
stateMutability: 'pure',
type: 'function',
},
{
constant: true,
inputs: [],
@ -2541,6 +2905,56 @@ export class AbiGenDummyContract extends BaseContract {
stateMutability: 'pure',
type: 'function',
},
{
constant: true,
inputs: [],
name: 'methodReturningMultipleValues',
outputs: [
{
name: '',
type: 'uint256',
},
{
name: '',
type: 'string',
},
],
payable: false,
stateMutability: 'pure',
type: 'function',
},
{
constant: true,
inputs: [],
name: 'methodReturningArrayOfStructs',
outputs: [
{
name: '',
type: 'tuple[]',
components: [
{
name: 'someBytes',
type: 'bytes',
},
{
name: 'anInteger',
type: 'uint32',
},
{
name: 'aDynamicArrayOfBytes',
type: 'bytes[]',
},
{
name: 'aString',
type: 'string',
},
],
},
],
payable: false,
stateMutability: 'pure',
type: 'function',
},
{
constant: true,
inputs: [],
@ -2601,6 +3015,34 @@ export class AbiGenDummyContract extends BaseContract {
stateMutability: 'pure',
type: 'function',
},
{
constant: true,
inputs: [
{
name: 'a',
type: 'string',
},
],
name: 'overloadedMethod',
outputs: [],
payable: false,
stateMutability: 'pure',
type: 'function',
},
{
constant: true,
inputs: [
{
name: 'a',
type: 'int256',
},
],
name: 'overloadedMethod',
outputs: [],
payable: false,
stateMutability: 'pure',
type: 'function',
},
{
anonymous: false,
inputs: [

File diff suppressed because one or more lines are too long

View File

@ -145,6 +145,8 @@ contract AbiGenDummy
});
}
function methodReturningArrayOfStructs() public pure returns(Struct[] memory) {}
struct NestedStruct {
Struct innerStruct;
string description;
@ -153,10 +155,31 @@ contract AbiGenDummy
function nestedStructInput(NestedStruct memory n) public pure {}
function nestedStructOutput() public pure returns(NestedStruct memory) {}
struct StructNotDirectlyUsedAnywhere {
uint256 aField;
}
struct NestedStructWithInnerStructNotUsedElsewhere {
StructNotDirectlyUsedAnywhere innerStruct;
}
function methodUsingNestedStructWithInnerStructNotUsedElsewhere()
public pure returns(NestedStructWithInnerStructNotUsedElsewhere memory)
{}
uint someState;
function nonPureMethod() public returns(uint) { return someState += 1; }
function nonPureMethodThatReturnsNothing() public { someState += 1; }
function methodReturningMultipleValues()
public pure returns (uint256, string memory)
{
return (1, "hello");
}
function overloadedMethod(int a) public pure {}
function overloadedMethod(string memory a) public pure {}
// begin tests for `decodeTransactionData`, `decodeReturnData`
/// @dev complex input is dynamic and more difficult to decode than simple input.

View File

@ -13,7 +13,7 @@
"clean": "shx rm -rf generated"
},
"config": {
"abis": "../contract-artifacts/artifacts/{Exchange,ERC20Token}.json"
"abis": "../contract-artifacts/artifacts/{AssetProxyOwner,Coordinator,CoordinatorRegistry,DummyERC20Token,DummyERC721Token,DutchAuction,ERC20Proxy,ERC20Token,ERC721Proxy,ERC721Token,EthBalanceChecker,Exchange,Forwarder,IAssetProxy,IValidator,IWallet,MultiAssetProxy,OrderValidator,WETH9,ZRXToken}.json"
},
"repository": {
"type": "git",

View File

@ -1,3 +1,7 @@
[MESSAGES CONTROL]
disable=C0330,line-too-long,fixme,too-few-public-methods,too-many-ancestors,duplicate-code
# C0330 is "bad hanging indent". we use indents per `black`.
[BASIC]
argument-rgx=[a-z_][a-z0-9_]{1,31}$
# above differs from the default only in that it allows 2-character names

View File

@ -3,6 +3,7 @@
## 2.0.0 - TBD
- Completely new implementation of the Exchange wrapper, virtually all auto-generated from the Solidity contract. Breaking changes include method parameter name changes and accepting of signatures as bytes.
- Introduction of wrappers for all 0x contracts.
## 1.0.0 - 2019-04-30

View File

@ -15,7 +15,7 @@ from setuptools import find_packages, setup
from setuptools.command.test import test as TestCommand
BLACK_COMMAND = "black --line-length 79"
BLACK_COMMAND = "black --line-length 79 "
class PreInstallCommand(distutils.command.build_py.build_py):
@ -26,42 +26,66 @@ class PreInstallCommand(distutils.command.build_py.build_py):
def run(self):
"""Copy files from TS build area to local src, & `black` them."""
pkgdir = path.dirname(path.realpath(argv[0]))
copy(
path.join(
pkgdir,
"..",
"..",
"packages",
"python-contract-wrappers",
"generated",
"erc20_token",
"__init__.py",
),
path.join(
pkgdir, "src", "zero_ex", "contract_wrappers", "erc20_token"
),
)
copy(
path.join(
pkgdir,
"..",
"..",
"packages",
"python-contract-wrappers",
"generated",
"exchange",
"__init__.py",
),
path.join(
pkgdir, "src", "zero_ex", "contract_wrappers", "exchange"
),
)
contracts = [
"asset_proxy_owner",
"coordinator",
"coordinator_registry",
"dummy_erc20_token",
"dummy_erc721_token",
"dutch_auction",
"erc20_proxy",
"erc20_token",
"erc721_proxy",
"erc721_token",
"eth_balance_checker",
"exchange",
"forwarder",
"i_asset_proxy",
"i_validator",
"i_wallet",
"multi_asset_proxy",
"order_validator",
"weth9",
"zrx_token",
]
for contract in contracts:
copy(
path.join(
pkgdir,
"..",
"..",
"packages",
"python-contract-wrappers",
"generated",
contract,
"__init__.py",
),
path.join(
pkgdir, "src", "zero_ex", "contract_wrappers", contract
),
)
copy(
path.join(
pkgdir,
"..",
"..",
"packages",
"python-contract-wrappers",
"generated",
contract,
"__init__.py",
),
path.join(
pkgdir, "src", "zero_ex", "contract_wrappers", contract
),
)
if find_spec("black") is None:
subprocess.check_call("pip install black".split()) # nosec
black_command = (
BLACK_COMMAND
+ " src/zero_ex/contract_wrappers/erc20_token/__init__.py"
+ " src/zero_ex/contract_wrappers/exchange/__init__.py"
black_command = BLACK_COMMAND + " ".join(
[
f"src/zero_ex/contract_wrappers/{contract}/__init__.py"
for contract in contracts
]
)
print(f"Running command `{black_command}`...")
subprocess.check_call(black_command.split()) # nosec

View File

@ -2137,6 +2137,11 @@
version "0.0.33"
resolved "https://registry.yarnpkg.com/@types/tmp/-/tmp-0.0.33.tgz#1073c4bc824754ae3d10cfab88ab0237ba964e4d"
"@types/toposort@^2.0.1":
version "2.0.1"
resolved "https://registry.yarnpkg.com/@types/toposort/-/toposort-2.0.1.tgz#d950563ae45147fc28866fe66f3712e9b2a90f88"
integrity sha512-u9mzB6WehAYUw6RJLGO2IbxNpg1ec/ooBfLxjYCAsanETh5M3GVG8dijvwyGzXEdgdWxcIBKnOkeaLnZg+VO8g==
"@types/uglify-js@*":
version "3.0.4"
resolved "https://registry.yarnpkg.com/@types/uglify-js/-/uglify-js-3.0.4.tgz#96beae23df6f561862a830b4288a49e86baac082"
@ -8811,10 +8816,27 @@ got@^6.7.1:
unzip-response "^2.0.1"
url-parse-lax "^1.0.0"
graceful-fs@4.1.15, graceful-fs@^3.0.0, graceful-fs@^4.0.0, graceful-fs@^4.1.10, graceful-fs@^4.1.11, graceful-fs@^4.1.15, graceful-fs@^4.1.2, graceful-fs@^4.1.6, graceful-fs@^4.1.9, graceful-fs@^4.2.0, graceful-fs@~1.2.0:
graceful-fs@^3.0.0:
version "3.0.11"
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-3.0.11.tgz#7613c778a1afea62f25c630a086d7f3acbbdd818"
integrity sha1-dhPHeKGv6mLyXGMKCG1/Osu92Bg=
dependencies:
natives "^1.1.0"
graceful-fs@^4.0.0, graceful-fs@^4.1.10, graceful-fs@^4.1.11, graceful-fs@^4.1.15, graceful-fs@^4.1.2, graceful-fs@^4.1.6, graceful-fs@^4.1.9:
version "4.1.15"
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.1.15.tgz#ffb703e1066e8a0eeaa4c8b80ba9253eeefbfb00"
graceful-fs@^4.2.0:
version "4.2.0"
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.0.tgz#8d8fdc73977cb04104721cb53666c1ca64cd328b"
integrity sha512-jpSvDPV4Cq/bgtpndIWbI5hmYxhQGHPC4d4cqBPb4DLniCfhJokdXhwhaDuLBGLQdvvRum/UiX6ECVIPvDXqdg==
graceful-fs@~1.2.0:
version "1.2.3"
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-1.2.3.tgz#15a4806a57547cb2d2dbf27f42e89a8c3451b364"
integrity sha1-FaSAaldUfLLS2/J/QuiajDRRs2Q=
"graceful-readlink@>= 1.0.0":
version "1.0.1"
resolved "https://registry.yarnpkg.com/graceful-readlink/-/graceful-readlink-1.0.1.tgz#4cafad76bc62f02fa039b2f94e9a3dd3a391a725"
@ -12429,6 +12451,11 @@ nanomatch@^1.2.9:
snapdragon "^0.8.1"
to-regex "^3.0.1"
natives@^1.1.0:
version "1.1.6"
resolved "https://registry.yarnpkg.com/natives/-/natives-1.1.6.tgz#a603b4a498ab77173612b9ea1acdec4d980f00bb"
integrity sha512-6+TDFewD4yxY14ptjKaS63GVdtKiES1pTPyxn9Jb0rBqPMZ7VcCiooEhPNsr+mqHtMGxa/5c/HhcC4uPEUw/nA==
natural-compare@^1.4.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/natural-compare/-/natural-compare-1.4.0.tgz#4abebfeed7541f2c27acfb29bdbbd15c8d5ba4f7"
@ -14807,6 +14834,8 @@ react-highlight@0xproject/react-highlight#react-peer-deps:
dependencies:
highlight.js "^9.11.0"
highlightjs-solidity "^1.0.5"
react "^16.5.2"
react-dom "^16.5.2"
react-hot-loader@^4.3.3:
version "4.3.4"
@ -17595,6 +17624,11 @@ toposort@^1.0.0:
version "1.0.7"
resolved "https://registry.yarnpkg.com/toposort/-/toposort-1.0.7.tgz#2e68442d9f64ec720b8cc89e6443ac6caa950029"
toposort@^2.0.2:
version "2.0.2"
resolved "https://registry.yarnpkg.com/toposort/-/toposort-2.0.2.tgz#ae21768175d1559d48bef35420b2f4962f09c330"
integrity sha1-riF2gXXRVZ1IvvNUILL0li8JwzA=
touch@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/touch/-/touch-3.1.0.tgz#fe365f5f75ec9ed4e56825e0bb76d24ab74af83b"