Skip to content

Commit

Permalink
fix styling
Browse files Browse the repository at this point in the history
  • Loading branch information
OBorce committed Dec 23, 2024
1 parent dbde1a6 commit 40022df
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 40 deletions.
7 changes: 0 additions & 7 deletions common/defs/misc/misc.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,5 @@
"slip44": 501,
"curve": "ed25519",
"decimals": 9
},
{
"name": "Mintlayer",
"shortcut": "ML",
"slip44": 19788,
"curve": "secp256k1",
"decimals": 11
}
]
3 changes: 1 addition & 2 deletions core/SConscript.bootloader
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,7 @@ def cargo_build():
'--no-default-features',
'--features ' + ','.join(features),
'-Z build-std=core',
'-Z build-std=alloc',
'-Z build-std=panic_abort',
'-Z build-std-features=panic_immediate_abort',
]

bindgen_macros = tools.get_bindgen_defines(env.get("CPPDEFINES"), ALLPATHS)
Expand Down
5 changes: 2 additions & 3 deletions core/SConscript.firmware
Original file line number Diff line number Diff line change
Expand Up @@ -861,9 +861,8 @@ def cargo_build():
f'--target-dir=../../build/firmware/rust',
'--no-default-features',
'--features ' + ','.join(features),
'-Z build-std=core',
'-Z build-std=alloc',
'-Z build-std=panic_abort',
'-Z build-std=core,alloc',
'-Z build-std-features=panic_immediate_abort',
]

env.get('ENV')['TREZOR_MODEL'] = TREZOR_MODEL
Expand Down
7 changes: 4 additions & 3 deletions core/embed/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ test = [
"ui_empty_lock",
"universal_fw",
]
universal_fw = []
universal_fw = ["mintlayer"]
mintlayer = ["dep:ml_common", "dep:parity-scale-codec"]

[lib]
crate-type = ["staticlib"]
Expand Down Expand Up @@ -101,8 +102,8 @@ ufmt = "0.2.0"
zeroize = { version = "1.7.0", default-features = false, optional = true }

# minlayer
parity-scale-codec = { version = "3.1", default-features = false, features = ["derive", "chain-error"] }
ml_common = { git = "https://github.com/mintlayer/mintlayer-core", package = "trezor-common", branch = "feature/trezor-common" }
parity-scale-codec = { version = "3.1", default-features = false, features = ["derive", "chain-error"], optional = true }
ml_common = { git = "https://github.com/mintlayer/mintlayer-core", package = "trezor-common", branch = "feature/trezor-common", optional = true }

# Runtime dependencies

Expand Down
1 change: 1 addition & 0 deletions core/embed/rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ mod trezorhal;
pub mod ui;

#[cfg(feature = "micropython")]
#[cfg(feature = "mintlayer")]
pub mod mintlayer;

#[cfg(feature = "debug")]
Expand Down
45 changes: 31 additions & 14 deletions core/src/apps/mintlayer/sign_tx/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,12 @@ def _sanitize_tx_input(txi: MintlayerTxInput) -> MintlayerTxInput:
elif txi.account:
if txi.account.addresses is None:
raise DataError("Input's addresses must be present for signing.")

if txi.account.delegation_balance:
pass
else:
raise DataError("No account spending is set")

else:
raise DataError(
"No input type present either utxo, account_command or account must be present"
Expand All @@ -181,22 +187,33 @@ def _sanitize_tx_output(txo: MintlayerTxOutput) -> MintlayerTxOutput:
from trezor.wire import DataError # local_cache_global

if txo.transfer:
x = txo.transfer
if x.value is None:
raise DataError("Missing amount field.")

if not x.address:
raise DataError("Missing address")
pass
elif txo.lock_then_transfer:
x = txo.lock_then_transfer
if x.value is None:
raise DataError("Missing amount field.")

if not x.address:
raise DataError("Missing address")
else:
# TODO: senitize other tx outputs
pass
elif txo.burn:
pass
elif txo.issue_nft:
pass
elif txo.create_stake_pool:
pass
elif txo.produce_block_from_stake:
raise DataError("Cannot create a ProduceBlockFromStake output in a transaction")
elif txo.create_delegation_id:
pass
elif txo.delegate_staking:
pass
elif txo.issue_fungible_token:
pass
elif txo.issue_nft:
pass
elif txo.data_deposit:
pass
elif txo.htlc:
pass
elif txo.create_order:
pass
else:
raise DataError("Tx Output not set")

return txo

Expand Down
2 changes: 1 addition & 1 deletion core/src/apps/mintlayer/sign_tx/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def format_coin_amount(
name = coininfo.coin_shortcut
else:
decimals = token.number_of_decimals
name = "ML Token: " + token.token_ticker.decode("utf-8")
name = f"Unknown Token wih ID: {token.token_id} and ticker {token.token_ticker.decode("utf-8")}"

amount_int = int.from_bytes(amount, "big")
amount_str = format_amount(amount_int, decimals)
Expand Down
4 changes: 0 additions & 4 deletions core/src/apps/mintlayer/sign_tx/signer.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,6 @@ def add_input(
def add_output(self, txo: MintlayerTxOutput):
self.outputs.append(txo)

def number_of_utxos(self) -> int:
return sum([1 for inp in self.inputs if inp.utxo is not None])


class Mintlayer:
def init_signing(self) -> None:
Expand Down Expand Up @@ -164,7 +161,6 @@ def __init__(
) -> None:
from trezor.messages import MintlayerTxRequest, MintlayerTxRequestDetailsType


self.progress = Progress()
self.coininfo = find_coin_by_name(tx.coin_name)
self.tx_info = TxInfo(tx=tx, inputs=[], outputs=[])
Expand Down
2 changes: 1 addition & 1 deletion core/src/apps/workflow_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def _find_message_handler_module(msg_type: int) -> str:
- collecting everything as strings instead of importing directly means that we don't
need to load any of the modules into memory until we actually need them
"""
from trezor import log, utils
from trezor import utils
from trezor.enums import MessageType

# debug
Expand Down
28 changes: 23 additions & 5 deletions python/src/trezorlib/cli/mintlayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ def cli() -> None:


@cli.command()
@click.option("-c", "--coin", required=True, help="coin name")
@click.option("-n", "--address", required=True, help="BIP-32 path")
@click.option("-d", "--show-display", is_flag=True)
@click.option("-C", "--chunkify", is_flag=True)
@with_client
def get_address(
client: "TrezorClient",
coin: str,
address: str,
show_display: bool,
chunkify: bool,
Expand All @@ -37,17 +39,20 @@ def get_address(
return mintlayer.get_address(
client,
address_n,
coin,
show_display,
chunkify=chunkify,
)


@cli.command()
@click.option("-c", "--coin", required=True, help="coin name")
@click.option("-n", "--address", required=True, help="BIP-32 path, e.g. m/44h/0h/0h")
@click.option("-d", "--show-display", is_flag=True)
@with_client
def get_public_key(
client: "TrezorClient",
coin: str,
address: str,
show_display: bool,
) -> dict:
Expand All @@ -60,6 +65,7 @@ def get_public_key(
result = mintlayer.get_public_key(
client,
address_n,
coin,
show_display=show_display,
)
if isinstance(result, messages.MintlayerPublicKey):
Expand All @@ -72,21 +78,29 @@ def get_public_key(


@cli.command()
@click.option("-c", "--coin", required=True, help="coin name")
@click.option("-n", "--address_n", required=True, help="BIP-32 path")
@click.option("-a", "--address", required=True, help="bech32 encoded address")
@click.option(
"-a",
"--address-type",
required=True,
help="Address type PUBLIC_KEY or PUBLIC_KEY_HASH",
)
@click.argument("message")
@with_client
def sign_message(
client: "TrezorClient",
coin: str,
address_n: str,
address: str,
address_type: str,
message: str,
) -> dict:
"""Sign message using address of given path."""
result = mintlayer.sign_message(
client,
coin_name=coin,
address_n=tools.parse_path(address_n),
address=address,
address_type=address_type,
message=message.encode(),
)
if isinstance(result, messages.MessageSignature):
Expand All @@ -100,10 +114,13 @@ def sign_message(


@cli.command()
@click.option("-c", "--coin", required=True, help="coin name")
@click.option("-C", "--chunkify", is_flag=True)
@click.argument("json_file", type=click.File())
@with_client
def sign_tx(client: "TrezorClient", json_file: TextIO, chunkify: bool) -> None:
def sign_tx(
client: "TrezorClient", coin: str, json_file: TextIO, chunkify: bool
) -> None:
"""Sign transaction.
Transaction data must be provided in a JSON file. The structure of the JSON matches the shape of the relevant protobuf messages. See
Expand All @@ -129,6 +146,7 @@ def sign_tx(client: "TrezorClient", json_file: TextIO, chunkify: bool) -> None:

results = mintlayer.sign_tx(
client,
coin,
inputs,
outputs,
prev_txs=prev_txes,
Expand All @@ -139,7 +157,7 @@ def sign_tx(client: "TrezorClient", json_file: TextIO, chunkify: bool) -> None:
click.echo()
click.echo("Signed signatures:")
for res in results:
click.echo(f"signature index: {res.signature_index}")
click.echo(f"input index: {res.input_index}")
click.echo("signature:")
for sig in res.signatures:
if sig.multisig_idx is not None:
Expand Down

0 comments on commit 40022df

Please sign in to comment.