Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cardano): transaction error #188

Merged
merged 2 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions rust/apps/cardano/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions rust/apps/cardano/src/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ impl ParsedCardanoTx {
let cert = _certs.get(i);
if let Some(_cert) = cert.as_stake_delegation() {
certs.push(CardanoCertificate::new(
"stake delegation".to_string(),
"Stake Pool Delegation".to_string(),
RewardAddress::new(network_id, &_cert.stake_credential())
.to_address()
.to_bech32(None)
Expand All @@ -244,7 +244,7 @@ impl ParsedCardanoTx {
}
if let Some(_cert) = cert.as_stake_deregistration() {
certs.push(CardanoCertificate::new(
"stake deregistration".to_string(),
"Stake Deregistration".to_string(),
RewardAddress::new(network_id, &_cert.stake_credential())
.to_address()
.to_bech32(None)
Expand All @@ -254,7 +254,7 @@ impl ParsedCardanoTx {
}
if let Some(_cert) = cert.as_stake_registration() {
certs.push(CardanoCertificate::new(
"stake registration".to_string(),
"Stake Registration".to_string(),
RewardAddress::new(network_id, &_cert.stake_credential())
.to_address()
.to_bech32(None)
Expand Down Expand Up @@ -527,7 +527,7 @@ impl ParsedCardanoTx {
let multi_asset = ParsedCardanoMultiAsset {
policy_id: policy_id.clone().to_bytes(),
name: name.to_bytes(),
amount: normalize_value(from_bignum(&asset_value)),
amount: normalize_coin(from_bignum(&asset_value)),
value: from_bignum(&asset_value),
id: format!(
"{}#{}",
Expand Down
25 changes: 23 additions & 2 deletions rust/rust_c/src/interfaces/cardano/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::interfaces::types::{Ptr, PtrBytes, PtrString, PtrT, PtrUR};
use crate::interfaces::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT};
use crate::interfaces::utils::{convert_c_char, recover_c_char};
use alloc::format;
use alloc::string::ToString;
use alloc::string::{String, ToString};

use alloc::vec::Vec;
use app_cardano::errors::CardanoError;
Expand Down Expand Up @@ -48,7 +48,13 @@ pub extern "C" fn cardano_get_path(ptr: PtrUR) -> Ptr<SimpleResponse<c_char>> {
let cardano_sign_reqeust = extract_ptr_with_type!(ptr, CardanoSignRequest);
match cardano_sign_reqeust.get_utxos().get(0) {
Some(_data) => match _data.get_key_path().get_path() {
Some(_path) => SimpleResponse::success(convert_c_char(_path)).simple_c_ptr(),
Some(_path) => {
if let Some(path) = parse_cardano_root_path(_path) {
return SimpleResponse::success(convert_c_char(path)).simple_c_ptr();
}
SimpleResponse::from(CardanoError::InvalidTransaction(format!("invalid utxo")))
.simple_c_ptr()
}
None => SimpleResponse::from(CardanoError::InvalidTransaction(format!("invalid utxo")))
.simple_c_ptr(),
},
Expand All @@ -57,6 +63,21 @@ pub extern "C" fn cardano_get_path(ptr: PtrUR) -> Ptr<SimpleResponse<c_char>> {
}
}

fn parse_cardano_root_path(path: String) -> Option<String> {
let root_path = "1852'/1815'/";
match path.strip_prefix(root_path) {
Some(path) => {
if let Some(index) = path.find("/") {
let sub_path = &path[..index];
Some(format!("{}{}", root_path, sub_path))
} else {
None
}
}
None => None,
}
}

#[no_mangle]
pub extern "C" fn cardano_parse_tx(
ptr: PtrUR,
Expand Down
2 changes: 1 addition & 1 deletion src/ui/gui_widgets/gui_multi_accounts_receive_widgets.c
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ static void GuiCreateGotoAddressWidgets(lv_obj_t *parent)
label = GuiCreateLabelWithFont(cont, _("receive_btc_receive_change_address_title"), &openSans_20);
lv_obj_align(label, LV_ALIGN_TOP_LEFT, 36, 30 + 270);
lv_obj_set_style_text_opa(label, LV_OPA_56, LV_PART_MAIN);
label = GuiCreateLabelWithFont(cont, "Account-", &openSans_24);
label = GuiCreateLabelWithFont(cont, "Address-", &openSans_24);
lv_obj_align(label, LV_ALIGN_TOP_LEFT, 36, 108 + 270);
lv_obj_set_style_text_opa(label, LV_OPA_56, LV_PART_MAIN);
g_multiAccountsReceiveWidgets.inputAccountLabel = GuiCreateLabelWithFont(cont, "", &openSans_24);
Expand Down
Loading