Clean up docs before publish

This commit is contained in:
F. Eugene Aumson 2019-01-09 12:12:20 -05:00
parent 5b8c9122a2
commit e39ef60775
No known key found for this signature in database
GPG Key ID: 23E6737B1374A24A
5 changed files with 70 additions and 21 deletions

View File

@ -188,6 +188,7 @@ setup(
"pylint", "pylint",
"pytest", "pytest",
"sphinx", "sphinx",
"sphinx-autodoc-typehints",
"tox", "tox",
"twine", "twine",
] ]

View File

@ -22,6 +22,7 @@ extensions = [
"sphinx.ext.intersphinx", "sphinx.ext.intersphinx",
"sphinx.ext.coverage", "sphinx.ext.coverage",
"sphinx.ext.viewcode", "sphinx.ext.viewcode",
"sphinx_autodoc_typehints",
] ]
templates_path = ["doc_templates"] templates_path = ["doc_templates"]

View File

@ -7,21 +7,27 @@ Python zero_ex.order_utils
:maxdepth: 2 :maxdepth: 2
:caption: Contents: :caption: Contents:
.. autoclass:: zero_ex.order_utils.Order
:members:
See source for class properties. Sphinx does not easily generate class property docs; pull requests welcome.
.. automodule:: zero_ex.order_utils .. automodule:: zero_ex.order_utils
:members: :members:
.. autoclass:: zero_ex.order_utils.Order
See source for class properties. Sphinx is having problems generating docs for ``TypedDict`` declarations; pull requests welcome.
zero_ex.order_utils.asset_data_utils
------------------------------------
.. automodule:: zero_ex.order_utils.asset_data_utils .. automodule:: zero_ex.order_utils.asset_data_utils
:members: :members:
.. autoclass:: zero_ex.order_utils.asset_data_utils.ERC20AssetData .. autoclass:: zero_ex.order_utils.asset_data_utils.ERC20AssetData
See source for class properties. Sphinx is having problems generating docs for ``TypedDict`` declarations; pull requests welcome.
.. autoclass:: zero_ex.order_utils.asset_data_utils.ERC721AssetData .. autoclass:: zero_ex.order_utils.asset_data_utils.ERC721AssetData
See source for class properties. Sphinx is having problems generating docs for ``TypedDict`` declarations; pull requests welcome.
Indices and tables Indices and tables
================== ==================

View File

@ -1,13 +1,11 @@
"""Order utilities for 0x applications. """Order utilities for 0x applications.
Some methods require the caller to pass in a `Web3.HTTPProvider` object. For Some methods require the caller to pass in a `Web3.BaseProvider`:code: object.
local testing one may construct such a provider pointing at an instance of For local testing one may construct such a provider pointing at an instance of
`ganache-cli <https://www.npmjs.com/package/ganache-cli>`_ which has the 0x `ganache-cli <https://www.npmjs.com/package/ganache-cli>`_ which has the 0x
contracts deployed on it. For convenience, a docker container is provided for contracts deployed on it. For convenience, a docker container is provided for
just this purpose. To start it: ``docker run -d -p 8545:8545 0xorg/ganache-cli just this purpose. To start it:
--gasLimit 10000000 --db /snapshot --noVMErrorsOnRPCResponse -p 8545 `docker run -d -p 8545:8545 0xorg/ganache-cli:2.2.2`:code:.
--networkId 50 -m "concert load couple harbor equip island argue ramp clarify
fence smart topic"``.
""" """
from copy import copy from copy import copy
@ -85,17 +83,53 @@ class Order(TypedDict): # pylint: disable=too-many-instance-attributes
"""A Web3-compatible representation of the Exchange.Order struct.""" """A Web3-compatible representation of the Exchange.Order struct."""
makerAddress: str makerAddress: str
"""Address that created the order."""
takerAddress: str takerAddress: str
"""Address that is allowed to fill the order.
If set to 0, any address is allowed to fill the order.
"""
feeRecipientAddress: str feeRecipientAddress: str
"""Address that will recieve fees when order is filled."""
senderAddress: str senderAddress: str
"""Address that is allowed to call Exchange contract methods that affect
this order. If set to 0, any address is allowed to call these methods.
"""
makerAssetAmount: int makerAssetAmount: int
"""Amount of makerAsset being offered by maker. Must be greater than 0."""
takerAssetAmount: int takerAssetAmount: int
"""Amount of takerAsset being bid on by maker. Must be greater than 0."""
makerFee: int makerFee: int
"""Amount of ZRX paid to feeRecipient by maker when order is filled. If
set to 0, no transfer of ZRX from maker to feeRecipient will be attempted.
"""
takerFee: int takerFee: int
"""Amount of ZRX paid to feeRecipient by taker when order is filled. If
set to 0, no transfer of ZRX from taker to feeRecipient will be attempted.
"""
expirationTimeSeconds: int expirationTimeSeconds: int
"""Timestamp in seconds at which order expires."""
salt: int salt: int
"""Arbitrary number to facilitate uniqueness of the order's hash."""
makerAssetData: bytes makerAssetData: bytes
"""Encoded data that can be decoded by a specified proxy contract when
transferring makerAsset. The last byte references the id of this proxy.
"""
takerAssetData: bytes takerAssetData: bytes
"""Encoded data that can be decoded by a specified proxy contract when
transferring takerAsset. The last byte references the id of this proxy.
"""
def make_empty_order() -> Order: def make_empty_order() -> Order:
@ -125,7 +159,7 @@ def order_to_jsdict(
) -> dict: ) -> dict:
"""Convert a Web3-compatible order struct to a JSON-schema-compatible dict. """Convert a Web3-compatible order struct to a JSON-schema-compatible dict.
More specifically, do explicit decoding for the `bytes` fields. More specifically, do explicit decoding for the `bytes`:code: fields.
>>> import pprint >>> import pprint
>>> pprint.pprint(order_to_jsdict( >>> pprint.pprint(order_to_jsdict(
@ -175,7 +209,7 @@ def order_to_jsdict(
def jsdict_order_to_struct(jsdict: dict) -> Order: def jsdict_order_to_struct(jsdict: dict) -> Order:
r"""Convert a JSON-schema-compatible dict order to a Web3-compatible struct. r"""Convert a JSON-schema-compatible dict order to a Web3-compatible struct.
More specifically, do explicit encoding of the `bytes` fields. More specifically, do explicit encoding of the `bytes`:code: fields.
>>> import pprint >>> import pprint
>>> pprint.pprint(jsdict_order_to_struct( >>> pprint.pprint(jsdict_order_to_struct(
@ -234,7 +268,7 @@ def generate_order_hash_hex(order: Order, exchange_address: str) -> str:
:param order: The order to be hashed. Must conform to `the 0x order JSON schema <https://github.com/0xProject/0x-monorepo/blob/development/packages/json-schemas/schemas/order_schema.json>`_. :param order: The order to be hashed. Must conform to `the 0x order JSON schema <https://github.com/0xProject/0x-monorepo/blob/development/packages/json-schemas/schemas/order_schema.json>`_.
:param exchange_address: The address to which the 0x Exchange smart :param exchange_address: The address to which the 0x Exchange smart
contract has been deployed. contract has been deployed.
:rtype: A string, of ASCII hex digits, representing the order hash. :returns: A string, of ASCII hex digits, representing the order hash.
>>> generate_order_hash_hex( >>> generate_order_hash_hex(
... { ... {
@ -296,8 +330,13 @@ class OrderInfo(NamedTuple):
"""A Web3-compatible representation of the Exchange.OrderInfo struct.""" """A Web3-compatible representation of the Exchange.OrderInfo struct."""
order_status: str order_status: str
"""A `str`:code: describing the order's validity and fillability."""
order_hash: bytes order_hash: bytes
"""A `bytes`:code: object representing the EIP712 hash of the order."""
order_taker_asset_filled_amount: int order_taker_asset_filled_amount: int
"""An `int`:code: indicating the amount that has already been filled."""
def is_valid_signature( def is_valid_signature(
@ -305,15 +344,15 @@ def is_valid_signature(
) -> Tuple[bool, str]: ) -> Tuple[bool, str]:
"""Check the validity of the supplied signature. """Check the validity of the supplied signature.
Check if the supplied ``signature`` corresponds to signing ``data`` with Check if the supplied `signature`:code: corresponds to signing `data`:code:
the private key corresponding to ``signer_address``. with the private key corresponding to `signer_address`:code:.
:param provider: A Web3 provider able to access the 0x Exchange contract. :param provider: A Web3 provider able to access the 0x Exchange contract.
:param data: The hex encoded data signed by the supplied signature. :param data: The hex encoded data signed by the supplied signature.
:param signature: The hex encoded signature. :param signature: The hex encoded signature.
:param signer_address: The hex encoded address that signed the data to :param signer_address: The hex encoded address that signed the data to
produce the supplied signature. produce the supplied signature.
:rtype: Tuple consisting of a boolean and a string. Boolean is true if :returns: Tuple consisting of a boolean and a string. Boolean is true if
valid, false otherwise. If false, the string describes the reason. valid, false otherwise. If false, the string describes the reason.
>>> is_valid_signature( >>> is_valid_signature(
@ -428,8 +467,8 @@ def sign_hash(
:param provider: A Web3 provider. :param provider: A Web3 provider.
:param signer_address: The address of the signing account. :param signer_address: The address of the signing account.
:param hash_hex: A hex string representing the hash, like that returned :param hash_hex: A hex string representing the hash, like that returned
from `generate_order_hash_hex()`. from `generate_order_hash_hex()`:code:.
:rtype: A string, of ASCII hex digits, representing the signature. :returns: A string, of ASCII hex digits, representing the signature.
>>> provider = Web3.HTTPProvider("http://127.0.0.1:8545") >>> provider = Web3.HTTPProvider("http://127.0.0.1:8545")
>>> sign_hash( >>> sign_hash(

View File

@ -17,6 +17,8 @@ class ERC20AssetData(TypedDict):
"""Object interface to ERC20 asset data.""" """Object interface to ERC20 asset data."""
asset_proxy_id: str asset_proxy_id: str
"""asset proxy id"""
token_address: str token_address: str
@ -32,7 +34,7 @@ def encode_erc20_asset_data(token_address: str) -> str:
"""Encode an ERC20 token address into an asset data string. """Encode an ERC20 token address into an asset data string.
:param token_address: the ERC20 token's contract address. :param token_address: the ERC20 token's contract address.
:rtype: hex encoded asset data string, usable in the makerAssetData or :returns: hex encoded asset data string, usable in the makerAssetData or
takerAssetData fields in a 0x order. takerAssetData fields in a 0x order.
>>> encode_erc20_asset_data('0x1dc4c1cefef38a777b15aa20260a54e584b16c48') >>> encode_erc20_asset_data('0x1dc4c1cefef38a777b15aa20260a54e584b16c48')
@ -85,7 +87,7 @@ def encode_erc721_asset_data(token_address: str, token_id: int) -> str:
:param token_address: the ERC721 token's contract address. :param token_address: the ERC721 token's contract address.
:param token_id: the identifier of the asset's instance of the token. :param token_id: the identifier of the asset's instance of the token.
:rtype: hex encoded asset data string, usable in the makerAssetData or :returns: hex encoded asset data string, usable in the makerAssetData or
takerAssetData fields in a 0x order. takerAssetData fields in a 0x order.
>>> encode_erc721_asset_data('0x1dc4c1cefef38a777b15aa20260a54e584b16c48', 1) >>> encode_erc721_asset_data('0x1dc4c1cefef38a777b15aa20260a54e584b16c48', 1)