1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-17 21:22:10 +00:00

feat(core,legacy): display only sat instead of sat BTC

This commit is contained in:
Martin Novak 2022-09-09 13:20:33 +02:00 committed by marnova
parent f44ee9b665
commit dd168d2893
6 changed files with 68 additions and 14 deletions

View File

@ -0,0 +1 @@
Display only sat instead of sat BTC

View File

@ -29,7 +29,9 @@ def format_coin_amount(amount: int, coin: CoinInfo, amount_unit: AmountUnit) ->
decimals, shortcut = coin.decimals, coin.coin_shortcut
if amount_unit == AmountUnit.SATOSHI:
decimals = 0
shortcut = "sat " + shortcut
shortcut = "sat"
if coin.coin_shortcut != "BTC":
shortcut += " " + coin.coin_shortcut
elif amount_unit == AmountUnit.MICROBITCOIN and decimals >= 6:
decimals -= 6
shortcut = "u" + shortcut

View File

@ -0,0 +1 @@
Display only sat instead of sat BTC

View File

@ -380,8 +380,11 @@ static size_t format_coin_amount(uint64_t amount, const char *prefix,
switch (amount_unit) {
case AmountUnit_SATOSHI:
decimals = 0;
strlcpy(suffix + 1, "sat ", sizeof(suffix) - 1);
strlcpy(suffix + 5, coin->coin_shortcut, sizeof(suffix) - 5);
strlcpy(suffix + 1, "sat", sizeof(suffix) - 1);
if (strcmp(coin->coin_shortcut, "BTC") != 0) {
strlcpy(suffix + 4, " ", sizeof(suffix) - 4);
strlcpy(suffix + 5, coin->coin_shortcut, sizeof(suffix) - 5);
}
break;
case AmountUnit_MILLIBITCOIN:
if (decimals >= 6) {

View File

@ -28,6 +28,9 @@ TX_API = TxCache("Testnet")
TXHASH_b36780 = bytes.fromhex(
"b36780ceb86807ca6e7535a6fd418b1b788cb9b227d2c8a26a0de295e523219e"
)
TXHASH_0dac36 = bytes.fromhex(
"0dac366fd8a67b2a89fbb0d31086e7acded7a5bbf9ef9daa935bc873229ef5b5"
)
VECTORS = ( # amount_unit
None,
@ -39,7 +42,7 @@ VECTORS = ( # amount_unit
@pytest.mark.parametrize("amount_unit", VECTORS)
def test_signtx(client: Client, amount_unit):
def test_signtx_testnet(client: Client, amount_unit):
inp1 = messages.TxInputType(
# tb1qajr3a3y5uz27lkxrmn7ck8lp22dgytvagr5nqy
address_n=parse_path("m/84h/1h/0h/0/87"),
@ -73,3 +76,37 @@ def test_signtx(client: Client, amount_unit):
hash_link="https://tbtc1.trezor.io/api/tx/65047a2b107d6301d72d4a1e49e7aea9cf06903fdc4ae74a4a9bba9bc1a414d2",
tx_hex="010000000001019e2123e595e20d6aa2c8d227b2b98c781b8b41fda635756eca0768b8ce8067b30000000000ffffffff02409c00000000000017a9147a55d61848e77ca266e79a39bfc85c580a6426c98750c3000000000000160014cd4ee15090b177f15ed0760d85956d93b5990d5f0247304402200c734ed16a9226162a29133c14fad3565332c60346050ceb9246e73a2fc8485002203463d40cf78eb5cc9718d6617d9f251b987e96cb58525795a507acb9b91696c7012103f60fc56bf7b5326537c7e86e0a63b6cd008eeb87d39af324cee5bcc3424bf4d000000000",
)
@pytest.mark.parametrize("amount_unit", VECTORS)
def test_signtx_btc(client: Client, amount_unit):
# input tx: 0dac366fd8a67b2a89fbb0d31086e7acded7a5bbf9ef9daa935bc873229ef5b5
inp1 = messages.TxInputType(
address_n=parse_path("m/44h/0h/5h/0/9"), # 1H2CRJBrDMhkvCGZMW7T4oQwYbL8eVuh7p
amount=63_988,
prev_hash=TXHASH_0dac36,
prev_index=0,
)
out1 = messages.TxOutputType(
address="13Hbso8zgV5Wmqn3uA7h3QVtmPzs47wcJ7",
amount=50_248,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
with client:
_, serialized_tx = btc.sign_tx(
client,
"Bitcoin",
[inp1],
[out1],
prev_txes=TxCache("Bitcoin"),
amount_unit=amount_unit,
)
assert_tx_matches(
serialized_tx,
hash_link="https://btc1.trezor.io/api/tx/b893aeed4b12227b6f5348d7f6cb84ba2cda2ba70a41933a25f363b9d2fc2cf9",
tx_hex="0100000001b5f59e2273c85b93aa9deff9bba5d7deace78610d3b0fb892a7ba6d86f36ac0d000000006b483045022100dd4dd136a70371bc9884c3c51fd52f4aed9ab8ee98f3ac7367bb19e6538096e702200c56be09c4359fc7eb494b4bdf8f2b72706b0575c4021373345b593e9661c7b6012103d7f3a07085bee09697cf03125d5c8760dfed65403dba787f1d1d8b1251af2cbeffffffff0148c40000000000001976a91419140511436e947448be994ab7fda9f98623e68e88ac00000000",
)

View File

@ -246,11 +246,16 @@
"T1_bitcoin-test_signtx.py::test_testnet_one_two_fee": "5a309a1de343c16239ab822e0434afe0cee621c09c6b4aa882ca7bbd81f4c4a4",
"T1_bitcoin-test_signtx.py::test_two_changes": "61e8de6771877b747d58272920e47671d4cc6f0de0643c0932dba2d7a64aee31",
"T1_bitcoin-test_signtx.py::test_two_two": "b36dd56051cd48c8a94257f8973e0b29aeaf2a84044fb00b9286ff19ed63ea63",
"T1_bitcoin-test_signtx_amount_unit.py::test_signtx[AmountUnit.BITCOIN]": "f2be7c23251127b50596f1a772a9eb933e0b1cef4c30afbc912930d1413f8694",
"T1_bitcoin-test_signtx_amount_unit.py::test_signtx[AmountUnit.MICROBITCOIN]": "383c397a6d5aad1cc45e4883bfb314264161492a508de9e93c3cdb70c3975ed0",
"T1_bitcoin-test_signtx_amount_unit.py::test_signtx[AmountUnit.MILLIBITCOIN]": "37ed5d570b29eef47131d1b1a48bc13173af15e499462077437dead863339691",
"T1_bitcoin-test_signtx_amount_unit.py::test_signtx[AmountUnit.SATOSHI]": "177fd9048c7661977db228678f9be74b1e769deb4cec87aa146ef51d20c604a1",
"T1_bitcoin-test_signtx_amount_unit.py::test_signtx[None]": "f2be7c23251127b50596f1a772a9eb933e0b1cef4c30afbc912930d1413f8694",
"T1_bitcoin-test_signtx_amount_unit.py::test_signtx_btc[AmountUnit.BITCOIN]": "013ca83fd68c5b3d74b66b90a9485392543c95b792e97110142c34def21914ee",
"T1_bitcoin-test_signtx_amount_unit.py::test_signtx_btc[AmountUnit.MICROBITCOIN]": "c428485bdad8a17add6fb43a9ab1958deb5aef57193e02a9e43f52017a4964a3",
"T1_bitcoin-test_signtx_amount_unit.py::test_signtx_btc[AmountUnit.MILLIBITCOIN]": "e347fc9f97f5c400600bb6031a52b5a1755b938ea5e91e2c17a1045e63c24be6",
"T1_bitcoin-test_signtx_amount_unit.py::test_signtx_btc[AmountUnit.SATOSHI]": "eda8047aeed75b8a47a46c74ada5498bbcdba84b1877ed12b687267ad1732e1d",
"T1_bitcoin-test_signtx_amount_unit.py::test_signtx_btc[None]": "013ca83fd68c5b3d74b66b90a9485392543c95b792e97110142c34def21914ee",
"T1_bitcoin-test_signtx_amount_unit.py::test_signtx_testnet[AmountUnit.BITCOIN]": "f2be7c23251127b50596f1a772a9eb933e0b1cef4c30afbc912930d1413f8694",
"T1_bitcoin-test_signtx_amount_unit.py::test_signtx_testnet[AmountUnit.MICROBITCOIN]": "383c397a6d5aad1cc45e4883bfb314264161492a508de9e93c3cdb70c3975ed0",
"T1_bitcoin-test_signtx_amount_unit.py::test_signtx_testnet[AmountUnit.MILLIBITCOIN]": "37ed5d570b29eef47131d1b1a48bc13173af15e499462077437dead863339691",
"T1_bitcoin-test_signtx_amount_unit.py::test_signtx_testnet[AmountUnit.SATOSHI]": "177fd9048c7661977db228678f9be74b1e769deb4cec87aa146ef51d20c604a1",
"T1_bitcoin-test_signtx_amount_unit.py::test_signtx_testnet[None]": "f2be7c23251127b50596f1a772a9eb933e0b1cef4c30afbc912930d1413f8694",
"T1_bitcoin-test_signtx_external.py::test_p2tr_external_unverified": "19e56e826e17f0b5cb5ab26d684dd4d1ef73da2711edc8bef2a086962c1382b0",
"T1_bitcoin-test_signtx_external.py::test_p2wpkh_external_unverified": "6695ba71c171c82c4335db3f70dbb5f861c44141ea0eeea98e295ab6b51da3bb",
"T1_bitcoin-test_signtx_invalid_path.py::test_attack_path_segwit": "ee152e7534c4dd60f939b7403a8169eb7d1703e3bdab819a575bc80f261212a9",
@ -901,11 +906,16 @@
"TT_bitcoin-test_signtx.py::test_testnet_one_two_fee": "0ba8136fb2078c08f1059ad099fe2ca69a49d76c8aa846367b605f9f42493663",
"TT_bitcoin-test_signtx.py::test_two_changes": "0b9072f425c58bb12f7eb96bf99da624fc1fb0bca4927385489fe93717c52b1b",
"TT_bitcoin-test_signtx.py::test_two_two": "422ee61e55fb4132d4900f9ac10ea27e45b56e1f36b7df533b320f86d7ca886f",
"TT_bitcoin-test_signtx_amount_unit.py::test_signtx[AmountUnit.BITCOIN]": "6be7e3871f03fe7c8c34b2d20a43a2650595c938e7ccc4169f173bef3de677d8",
"TT_bitcoin-test_signtx_amount_unit.py::test_signtx[AmountUnit.MICROBITCOIN]": "00e46e724ada6a9622868fd0bc7e493587b3fd280b10423a708684483a26d7ad",
"TT_bitcoin-test_signtx_amount_unit.py::test_signtx[AmountUnit.MILLIBITCOIN]": "2950f443980e934672fcc11d9be5128282446466e3d0b6d0b1a754cf16295721",
"TT_bitcoin-test_signtx_amount_unit.py::test_signtx[AmountUnit.SATOSHI]": "99189ac7a561ded344b460216680d326bb0486dfe27adf40b8c570dd9e0dbdb9",
"TT_bitcoin-test_signtx_amount_unit.py::test_signtx[None]": "6be7e3871f03fe7c8c34b2d20a43a2650595c938e7ccc4169f173bef3de677d8",
"TT_bitcoin-test_signtx_amount_unit.py::test_signtx_btc[AmountUnit.BITCOIN]": "f227fdd9ff1c5a266ad6aa876321325cda3c8be1939c757b4c67dd7d5467c9cf",
"TT_bitcoin-test_signtx_amount_unit.py::test_signtx_btc[AmountUnit.MICROBITCOIN]": "54bec4d63f211bfe76c89e48ddee5ad277af3e9b4b2d28c1e42ae4144453537b",
"TT_bitcoin-test_signtx_amount_unit.py::test_signtx_btc[AmountUnit.MILLIBITCOIN]": "e56cc3ebebe34637fdfa543f422bfe964b2d695c0bbac1c11ae04327772f54ba",
"TT_bitcoin-test_signtx_amount_unit.py::test_signtx_btc[AmountUnit.SATOSHI]": "30dd433c586eef18e5e4134f3243ad8222b2d0ea093b18559043ba5e756aed33",
"TT_bitcoin-test_signtx_amount_unit.py::test_signtx_btc[None]": "f227fdd9ff1c5a266ad6aa876321325cda3c8be1939c757b4c67dd7d5467c9cf",
"TT_bitcoin-test_signtx_amount_unit.py::test_signtx_testnet[AmountUnit.BITCOIN]": "6be7e3871f03fe7c8c34b2d20a43a2650595c938e7ccc4169f173bef3de677d8",
"TT_bitcoin-test_signtx_amount_unit.py::test_signtx_testnet[AmountUnit.MICROBITCOIN]": "00e46e724ada6a9622868fd0bc7e493587b3fd280b10423a708684483a26d7ad",
"TT_bitcoin-test_signtx_amount_unit.py::test_signtx_testnet[AmountUnit.MILLIBITCOIN]": "2950f443980e934672fcc11d9be5128282446466e3d0b6d0b1a754cf16295721",
"TT_bitcoin-test_signtx_amount_unit.py::test_signtx_testnet[AmountUnit.SATOSHI]": "99189ac7a561ded344b460216680d326bb0486dfe27adf40b8c570dd9e0dbdb9",
"TT_bitcoin-test_signtx_amount_unit.py::test_signtx_testnet[None]": "6be7e3871f03fe7c8c34b2d20a43a2650595c938e7ccc4169f173bef3de677d8",
"TT_bitcoin-test_signtx_external.py::test_p2pkh_presigned": "8dd8089941ceb0d82c9425c69d54240f99e3ae7932ef24acd49313d28389b683",
"TT_bitcoin-test_signtx_external.py::test_p2pkh_with_proof": "c09de07fbbf1e047442180e2facb5482d06a1a428891b875b7dd93c9e4704ae1",
"TT_bitcoin-test_signtx_external.py::test_p2tr_external_presigned": "c714c4a4ea8b98dfbdd8185925adafbafc62570f415688972d6003a19d7b4d23",