Skip to content

Commit

Permalink
fix style
Browse files Browse the repository at this point in the history
  • Loading branch information
Roznovjak committed Aug 13, 2019
1 parent c5cb9af commit 6106bca
Show file tree
Hide file tree
Showing 9 changed files with 124 additions and 153 deletions.
14 changes: 7 additions & 7 deletions core/src/apps/decent/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ def base58_encode(prefix: str, data: bytes) -> str:
return prefix + b58


def account_id_to_string(id) -> str:
return "1.2." + str(id)
def account_id_to_string(id_) -> str:
return "1.2." + str(id_)


def object_id_to_string(id: DecentObjectId) -> str:
object_space = id.id >> 56
object_type = id.id >> 48 & 0x00ff
object_id = id.id & 0xffffffffffff
def object_id_to_string(id_: DecentObjectId) -> str:
object_space = id_.id >> 56
object_type = id_.id >> 48 & 0x00FF
object_id = id_.id & 0xFFFFFFFFFFFF
return ".".join([str(object_space), str(object_type), str(object_id)])


Expand All @@ -25,7 +25,7 @@ def asset_id_to_string(asset_id) -> str:


def vote_id_to_string(vote_id) -> str:
vote_type = vote_id & 0xff
vote_type = vote_id & 0xFF
vote_instance = vote_id >> 8
return str(vote_type) + ":" + str(vote_instance)

Expand Down
26 changes: 15 additions & 11 deletions core/src/apps/decent/operations/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
from micropython import const
from trezor.messages.MessageType import DecentTxOperationAck

DECENT_OP_ID_TRANSFER = const(39)
DECENT_OP_ID_ACCOUNT_CREATE = const(1)
DECENT_OP_ID_ACCOUNT_UPDATE = const(2)

from apps.decent import writers
from apps.decent.operations import layout

Expand All @@ -15,13 +10,13 @@ async def process_operation(ctx, sha, operation: DecentTxOperationAck):
raise ValueError("Invalid action")

w = bytearray()
if operation.operation_id == DECENT_OP_ID_TRANSFER:
if operation.operation_id == writers.DECENT_OP_ID_TRANSFER:
await layout.confirm_operation_transfer(ctx, operation.transfer)
writers.write_operation_transfer(w, operation.transfer)
elif operation.operation_id == DECENT_OP_ID_ACCOUNT_CREATE:
elif operation.operation_id == writers.DECENT_OP_ID_ACCOUNT_CREATE:
await layout.confirm_operation_account_create(ctx, operation.account_create)
writers.write_operation_account_create(w, operation.account_create)
elif operation.operation_id == DECENT_OP_ID_ACCOUNT_UPDATE:
elif operation.operation_id == writers.DECENT_OP_ID_ACCOUNT_UPDATE:
await layout.confirm_operation_account_update(ctx, operation.account_update)
writers.write_operation_account_update(w, operation.account_update)
else:
Expand All @@ -32,9 +27,18 @@ async def process_operation(ctx, sha, operation: DecentTxOperationAck):

def check_operation(operation: DecentTxOperationAck):
if (
(operation.operation_id == DECENT_OP_ID_TRANSFER and operation.transfer is not None)
or (operation.operation_id == DECENT_OP_ID_ACCOUNT_CREATE and operation.account_create is not None)
or (operation.operation_id == DECENT_OP_ID_ACCOUNT_UPDATE and operation.account_update is not None)
(
operation.operation_id == writers.DECENT_OP_ID_TRANSFER
and operation.transfer is not None
)
or (
operation.operation_id == writers.DECENT_OP_ID_ACCOUNT_CREATE
and operation.account_create is not None
)
or (
operation.operation_id == writers.DECENT_OP_ID_ACCOUNT_UPDATE
and operation.account_update is not None
)
):
return True
else:
Expand Down
4 changes: 2 additions & 2 deletions core/src/apps/decent/operations/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
from trezor import ui, wire
from trezor.messages import (
ButtonRequestType,
DecentOperationTransfer,
DecentOperationAccountCreate,
DecentOperationAccountUpdate,
DecentOperationTransfer,
MessageType,
)
from trezor.messages.ButtonRequest import ButtonRequest
Expand Down Expand Up @@ -46,7 +46,7 @@ async def confirm_operation_transfer(ctx, msg: DecentOperationTransfer):

if msg.memo:
fields.append("Memo:")
fields += split_data(hexlify(msg.memo.message[:512]).decode('ascii'))
fields += split_data(hexlify(msg.memo.message[:512]).decode("ascii"))

pages = list(chunks(fields, _FOUR_FIELDS_PER_PAGE))

Expand Down
8 changes: 4 additions & 4 deletions core/src/apps/decent/sign_tx.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from ubinascii import hexlify

from trezor import wire
from trezor.crypto.curve import secp256k1
from trezor.crypto.hashlib import sha256
Expand All @@ -9,11 +11,9 @@

from apps.common import paths
from apps.decent import CURVE, writers
from apps.decent.operations import process_operation
from apps.decent.helpers import validate_full_path
from apps.decent.layout import require_sign_tx

from ubinascii import hexlify
from apps.decent.operations import process_operation


async def sign_tx(ctx, msg: DecentSignTx, keychain):
Expand All @@ -36,7 +36,7 @@ async def sign_tx(ctx, msg: DecentSignTx, keychain):
node.private_key(), digest, True, secp256k1.CANONICAL_SIG_EOS
)

return DecentSignedTx(signature=hexlify(signature).decode('ascii'))
return DecentSignedTx(signature=hexlify(signature).decode("ascii"))


async def _init(ctx, sha, msg):
Expand Down
20 changes: 10 additions & 10 deletions core/src/apps/decent/writers.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
from micropython import const

from trezor.messages import (
DecentOperationTransfer,
DecentAccountOptions,
DecentAsset,
DecentAuthority,
DecentMemo,
DecentOperationAccountCreate,
DecentOperationAccountUpdate,
DecentAsset,
DecentOperationTransfer,
DecentTxHeader,
DecentMemo,
DecentAuthority,
DecentAccountOptions,
)
from trezor.utils import HashWriter

Expand All @@ -18,11 +20,9 @@
write_uint64_le,
)

from apps.decent.operations import (
DECENT_OP_ID_TRANSFER,
DECENT_OP_ID_ACCOUNT_CREATE,
DECENT_OP_ID_ACCOUNT_UPDATE,
)
DECENT_OP_ID_ACCOUNT_CREATE = const(1)
DECENT_OP_ID_ACCOUNT_UPDATE = const(2)
DECENT_OP_ID_TRANSFER = const(39)


def write_variant32(w: bytearray, value: int) -> int:
Expand Down
10 changes: 5 additions & 5 deletions core/tests/test_apps.decent.check_operation.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from common import *

from apps.decent.operations import (check_operation,
DECENT_OP_ID_TRANSFER,
DECENT_OP_ID_ACCOUNT_CREATE,
DECENT_OP_ID_ACCOUNT_UPDATE
)
from apps.decent.writers import (DECENT_OP_ID_ACCOUNT_CREATE,
DECENT_OP_ID_ACCOUNT_UPDATE,
DECENT_OP_ID_TRANSFER,
)
from apps.decent.operations import check_operation
from trezor.messages.DecentTxOperationAck import DecentTxOperationAck
from trezor.messages.DecentOperationTransfer import DecentOperationTransfer
from trezor.messages.DecentOperationAccountCreate import DecentOperationAccountCreate
Expand Down
4 changes: 3 additions & 1 deletion python/trezorctl
Original file line number Diff line number Diff line change
Expand Up @@ -1498,7 +1498,9 @@ def decent_sign_transaction(connect, address, file):
tx_json = json.load(file)

address_n = tools.parse_path(address)
return decent.sign_tx(client, address_n, tx_json["transaction"], tx_json["chain_id"])
return decent.sign_tx(
client, address_n, tx_json["transaction"], tx_json["chain_id"]
)


#
Expand Down
42 changes: 25 additions & 17 deletions python/trezorlib/decent.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ def parse_object_id(object_num: str):


def parse_asset(asset):
return messages.DecentAsset(amount=int(asset["amount"]), asset_id=parse_id(asset["asset_id"]))
return messages.DecentAsset(
amount=int(asset["amount"]), asset_id=parse_id(asset["asset_id"])
)


def public_key_to_buffer(pub_key):
Expand Down Expand Up @@ -52,8 +54,7 @@ def parse_authority(data):
account, weight = item
accounts.append(
messages.DecentAuthorityAccount(
account=messages.DecentAccountId(parse_id(account)),
weight=int(weight)
account=messages.DecentAccountId(parse_id(account)), weight=int(weight)
)
)

Expand All @@ -62,12 +63,13 @@ def parse_authority(data):
key, weight = item
keys.append(
messages.DecentAuthorityKey(
key=public_key_to_buffer(key),
weight=int(weight)
key=public_key_to_buffer(key), weight=int(weight)
)
)

return messages.DecentAuthority(threshold=int(data["weight_threshold"]), accounts=accounts, keys=keys)
return messages.DecentAuthority(
threshold=int(data["weight_threshold"]), accounts=accounts, keys=keys
)


def parse_vote(vote: str):
Expand All @@ -86,13 +88,15 @@ def parse_account_options(data):
price_per_subscribe = parse_asset(data["price_per_subscribe"])
subscription_period = int(data["subscription_period"])

return messages.DecentAccountOptions(memo,
voting_account,
num_miner,
votes,
allow_subscription,
price_per_subscribe,
subscription_period)
return messages.DecentAccountOptions(
memo,
voting_account,
num_miner,
votes,
allow_subscription,
price_per_subscribe,
subscription_period,
)


def parse_account_create(data):
Expand All @@ -103,7 +107,9 @@ def parse_account_create(data):
active = parse_authority(data["active"])
options = parse_account_options(data["options"])

return messages.DecentOperationAccountCreate(fee, registrar, name, owner, active, options)
return messages.DecentOperationAccountCreate(
fee, registrar, name, owner, active, options
)


def parse_account_update(data):
Expand All @@ -121,7 +127,9 @@ def parse_account_update(data):
if data.get("new_options"):
new_options = parse_account_options(data["new_options"])

return messages.DecentOperationAccountUpdate(fee, account, owner, active, new_options)
return messages.DecentOperationAccountUpdate(
fee, account, owner, active, new_options
)


def parse_operation(operation):
Expand All @@ -148,8 +156,8 @@ def parse_transaction_json(transaction):
header.ref_block_prefix = int(transaction["ref_block_prefix"])
header.expiration = int(
(
datetime.strptime(transaction["expiration"], "%Y-%m-%dT%H:%M:%S")
- datetime(1970, 1, 1)
datetime.strptime(transaction["expiration"], "%Y-%m-%dT%H:%M:%S")
- datetime(1970, 1, 1)
).total_seconds()
)

Expand Down
Loading

0 comments on commit 6106bca

Please sign in to comment.