Skip to content

Commit

Permalink
fix: linting via black
Browse files Browse the repository at this point in the history
  • Loading branch information
xeroc committed May 13, 2022
1 parent 0eedb6d commit 6b4ac7f
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 51 deletions.
8 changes: 4 additions & 4 deletions bitshares/aio/price.py
Expand Up @@ -259,11 +259,11 @@ def __repr__(self):


class UpdateCallOrder(Price):
""" This class inherits :class:`bitshares.price.Price` but has the ``base``
and ``quote`` Amounts not only be used to represent the **call
price** (as a ratio of base and quote).
"""This class inherits :class:`bitshares.price.Price` but has the ``base``
and ``quote`` Amounts not only be used to represent the **call
price** (as a ratio of base and quote).
:param bitshares.aio.bitshares.BitShares blockchain_instance: BitShares instance
:param bitshares.aio.bitshares.BitShares blockchain_instance: BitShares instance
"""

async def __init__(self, call, **kwargs):
Expand Down
85 changes: 46 additions & 39 deletions bitshares/bitshares.py
Expand Up @@ -1566,7 +1566,7 @@ def htlc_create(
self,
amount,
to,
*args, # force remaining args to be named not positional
*args, # force remaining args to be named not positional
hash_type=None,
hash_hex=None,
expiration=60 * 60,
Expand All @@ -1575,7 +1575,8 @@ def htlc_create(
account=None,
**kwargs
):
"""Create an HTLC contract.
"""
Create an HTLC contract.
:param Amount amount: Amount to lock
:param str to: Recipient
Expand Down Expand Up @@ -1634,9 +1635,9 @@ def htlc_create(
elif hash_type == "sha256":
preimage_hash = hashlib.sha256(bytes(preimage, "utf-8")).hexdigest()
elif hash_type == "hash160":
preimage_hash = hexlify(ripemd160(
hashlib.sha256(bytes(preimage, "utf-8")).hexdigest()
)).decode("ascii")
preimage_hash = hexlify(
ripemd160(hashlib.sha256(bytes(preimage, "utf-8")).hexdigest())
).decode("ascii")
elif hash_hex is not None:
preimage_hash = hexlify(bytes.fromhex(hash_hex)).decode("ascii")
preimage_size = preimage_length
Expand All @@ -1657,9 +1658,9 @@ def htlc_create(
)
return self.finalizeOp(op, account, "active", **kwargs)


def htlc_redeem(self, htlc_id, preimage, encoding="utf-8", account=None, **kwargs):
"""Redeem an htlc contract
"""
Redeem an htlc contract.
:param str preimage: The preimage that unlocks the htlc
:param str encoding: "utf-8", ..., or "hex"
Expand All @@ -1674,7 +1675,7 @@ def htlc_redeem(self, htlc_id, preimage, encoding="utf-8", account=None, **kwarg
account = htlc["to"]
account = Account(account, blockchain_instance=self)

if encoding=="hex":
if encoding == "hex":
preimage_hex = hexlify(bytes.fromhex(preimage)).decode("ascii")
else:
preimage_hex = hexlify(bytes(preimage, encoding)).decode("ascii")
Expand All @@ -1690,9 +1691,9 @@ def htlc_redeem(self, htlc_id, preimage, encoding="utf-8", account=None, **kwarg
)
return self.finalizeOp(op, account, "active", **kwargs)


def create_voting_ticket(self, target_type, amount_to_lock, account=None, **kwargs):
""" Create a voting ticket
"""
Create a voting ticket.
:param int,str target_type: Lock period target. Should be a string from
operations.ticket_type_strings or the index of the intended
Expand Down Expand Up @@ -1723,10 +1724,11 @@ def create_voting_ticket(self, target_type, amount_to_lock, account=None, **kwar
)
return self.finalizeOp(op, account, "active", **kwargs)


def update_voting_ticket(self, ticket_id, new_target_type, amount_to_update,
account=None, **kwargs):
"""Update a voting ticket
def update_voting_ticket(
self, ticket_id, new_target_type, amount_to_update, account=None, **kwargs
):
"""
Update a voting ticket.
:param str ticket_id: Id (e.g. "1.18.xxx") of the ticket to update.
Expand All @@ -1751,7 +1753,7 @@ def update_voting_ticket(self, ticket_id, new_target_type, amount_to_update,
elif amount_to_update is not None:
raise ValueError("'amount_to_update' must be of type Amount or None")
else:
pass # None is a valid value for optional field
pass # None is a valid value for optional field

op = operations.Ticket_update_operation(
**{
Expand All @@ -1765,11 +1767,18 @@ def update_voting_ticket(self, ticket_id, new_target_type, amount_to_update,
)
return self.finalizeOp(op, account, "active", **kwargs)


def create_liquidity_pool(self, asset_a, asset_b, share_asset,
taker_fee_percent, withdrawal_fee_percent,
account=None, **kwargs):
"""Create a liquidity pool
def create_liquidity_pool(
self,
asset_a,
asset_b,
share_asset,
taker_fee_percent,
withdrawal_fee_percent,
account=None,
**kwargs
):
"""
Create a liquidity pool.
:param str asset_a: First asset in the pool pair.
:param str asset_b: Second asset in the pool pair.
Expand All @@ -1785,7 +1794,6 @@ def create_liquidity_pool(self, asset_a, asset_b, share_asset,
For percentages, meaningful range is [0.00, 100.00], where 1% is
represented as 1.0. Smallest non-zero value recognized by BitShares
chain is 0.01 for 0.01%.
"""
if not account:
if "default_account" in self.config:
Expand All @@ -1798,9 +1806,9 @@ def create_liquidity_pool(self, asset_a, asset_b, share_asset,
asset_b = Asset(asset_b)["id"]
share_asset = Asset(share_asset)["id"]

if not (taker_fee_percent >=0 and taker_fee_percent <= 100):
if not (taker_fee_percent >= 0 and taker_fee_percent <= 100):
raise ValueError("Percentages must be in range [0.00, 100.00].")
if not (withdrawal_fee_percent >=0 and withdrawal_fee_percent <= 100):
if not (withdrawal_fee_percent >= 0 and withdrawal_fee_percent <= 100):
raise ValueError("Percentages must be in range [0.00, 100.00].")
graphene_1_percent = 100
taker_fee_percent = int(taker_fee_percent * graphene_1_percent)
Expand All @@ -1820,7 +1828,6 @@ def create_liquidity_pool(self, asset_a, asset_b, share_asset,
)
return self.finalizeOp(op, account, "active", **kwargs)


def _find_liquidity_pool(self, pool):
# Ad-hoc helper for the liquidity pool verbs. It locates a pool id
# irrespective of whether 'pool' is already a pool id, or perhaps an
Expand All @@ -1842,14 +1849,13 @@ def _find_liquidity_pool(self, pool):
raise ValueError("Asset is not a share asset for a pool.")
return pool_id


def delete_liquidity_pool(self, pool, account=None, **kwargs):
"""Delete a liquidity pool
"""
Delete a liquidity pool.
:param str,Asset pool: The liquidity pool to delete. Can be the pool id
as a string, or can be an Asset, asset_id, or symbol of the
share asset for the pool.
"""
if not account:
if "default_account" in self.config:
Expand All @@ -1870,17 +1876,18 @@ def delete_liquidity_pool(self, pool, account=None, **kwargs):
)
return self.finalizeOp(op, account, "active", **kwargs)


def deposit_into_liquidity_pool(self, pool, amount_a, amount_b, account=None, **kwargs):
"""Deposit assets into a liquidity pool
def deposit_into_liquidity_pool(
self, pool, amount_a, amount_b, account=None, **kwargs
):
"""
Deposit assets into a liquidity pool.
:param str,Asset pool: The liquidity pool to use. Can be the pool id
as a string, or can be an Asset, asset_id, or symbol of the
share asset for the pool.
:param Amount amount_a:
:param Amount amount_b:
"""
if not account:
if "default_account" in self.config:
Expand All @@ -1893,7 +1900,7 @@ def deposit_into_liquidity_pool(self, pool, amount_a, amount_b, account=None, **

num_id_a = int(amount_a.asset["id"].split(".")[-1])
num_id_b = int(amount_b.asset["id"].split(".")[-1])
if(num_id_b < num_id_a):
if num_id_b < num_id_a:
amount_a, amount_b = amount_b, amount_a

op = operations.Liquidity_pool_deposit(
Expand All @@ -1908,17 +1915,16 @@ def deposit_into_liquidity_pool(self, pool, amount_a, amount_b, account=None, **
)
return self.finalizeOp(op, account, "active", **kwargs)


def withdraw_from_liquidity_pool(self, pool, share_amount, account=None, **kwargs):
"""Withdraw stake from a liquidity pool
"""
Withdraw stake from a liquidity pool.
:param str,Asset pool: The liquidity pool to use. Can be the pool id
as a string, or can be an Asset, asset_id, or symbol of the
share asset for the pool.
:param Amount share_amount: Amount of share asset to redeem. Must be a
quantity of the pool's share_asset.
"""
if not account:
if "default_account" in self.config:
Expand All @@ -1940,17 +1946,18 @@ def withdraw_from_liquidity_pool(self, pool, share_amount, account=None, **kwarg
)
return self.finalizeOp(op, account, "active", **kwargs)


def exchange_with_liquidity_pool(self, pool, amount_to_sell, min_to_receive, account=None, **kwargs):
"""Exchange assets against a liquidity pool
def exchange_with_liquidity_pool(
self, pool, amount_to_sell, min_to_receive, account=None, **kwargs
):
"""
Exchange assets against a liquidity pool.
:param str,Asset pool: The liquidity pool to use. Can be the pool id
as a string, or can be an Asset, asset_id, or symbol of the
share asset for the pool.
:param Amount amount_to_sell:
:param Amount min_to_receive:
"""
if not account:
if "default_account" in self.config:
Expand Down
8 changes: 4 additions & 4 deletions bitshares/price.py
Expand Up @@ -308,11 +308,11 @@ def __repr__(self):


class UpdateCallOrder(Price):
""" This class inherits :class:`bitshares.price.Price` but has the ``base``
and ``quote`` Amounts not only be used to represent the **call
price** (as a ratio of base and quote).
"""This class inherits :class:`bitshares.price.Price` but has the ``base``
and ``quote`` Amounts not only be used to represent the **call
price** (as a ratio of base and quote).
:param bitshares.bitshares.BitShares blockchain_instance: BitShares instance
:param bitshares.bitshares.BitShares blockchain_instance: BitShares instance
"""

def __init__(self, call, **kwargs):
Expand Down
16 changes: 14 additions & 2 deletions bitsharesbase/operations.py
Expand Up @@ -1043,7 +1043,15 @@ def __init__(self, *args, **kwargs):
)
)

ticket_type_strings = ['liquid', 'lock_180_days', 'lock_360_days', 'lock_720_days', 'lock_forever']

ticket_type_strings = [
"liquid",
"lock_180_days",
"lock_360_days",
"lock_720_days",
"lock_forever",
]


class Ticket_create_operation(GrapheneObject):
def __init__(self, *args, **kwargs):
Expand All @@ -1070,6 +1078,7 @@ def __init__(self, *args, **kwargs):
)
)


class Ticket_update_operation(GrapheneObject):
def __init__(self, *args, **kwargs):
if isArgsThisClass(self, args):
Expand Down Expand Up @@ -1119,7 +1128,10 @@ def __init__(self, *args, **kwargs):
("asset_b", ObjectId(kwargs["asset_b"], "asset")),
("share_asset", ObjectId(kwargs["share_asset"], "asset")),
("taker_fee_percent", Uint16(kwargs["taker_fee_percent"])),
("withdrawal_fee_percent", Uint16(kwargs["withdrawal_fee_percent"])),
(
"withdrawal_fee_percent",
Uint16(kwargs["withdrawal_fee_percent"]),
),
("extensions", Set([])),
]
)
Expand Down
4 changes: 2 additions & 2 deletions setup.cfg
Expand Up @@ -31,15 +31,15 @@ exclude_lines =

[flake8]
select = C,E,F,W,B,B950
ignore = E501,F401,E203,W503
ignore = E501,F401,E203,W503,B950,E722,B001
exclude =
# No need to traverse our git directory
.git,
# There's no value in checking cache directories
__pycache__,
# The conf file is mostly autogenerated, ignore it
docs/conf.py,
max-complexity = 15
max-complexity = 20
max-line-length = 88

[isort]
Expand Down

0 comments on commit 6b4ac7f

Please sign in to comment.