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 avax bugs #1578

Merged
merged 1 commit into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
Binary file added images/walletList/walletListCore.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 2 additions & 7 deletions rust/apps/avalanche/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,14 @@
#[allow(unused_imports)]
#[macro_use]
extern crate alloc;
use alloc::{
string::{String},
vec::Vec,
};
use alloc::{string::String, vec::Vec};

pub use address::get_address;
use bytes::{Buf, Bytes};
use transactions::tx_header::Header;

use crate::errors::{AvaxError, Result};
use core::{
convert::TryFrom,
};
use core::convert::TryFrom;

pub mod constants;
pub mod errors;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ mod tests {
#[test]
fn test_add_permissionless_validator() {
// 23HbZUQ7ijjrDHfqnjKpd4MTMRY18Gc2JxCz79ZBwZAsCLfntb
let input_bytes = "000000000019000000050000000000000000000000000000000000000000000000000000000000000000000000013d9bdac0ed1d761330cf680efdeb1a42159eb387d6d2950c96f7d28f61bbe2aa000000070000000005e57a370000000000000000000000010000000161cd7d26c72edc631d4114d6eef2c4e069ec9206000000020033b7653ffbf19a2352591e8b6aea8e7c75f38d8e8f5f781cf15aad8425010a000000003d9bdac0ed1d761330cf680efdeb1a42159eb387d6d2950c96f7d28f61bbe2aa00000005000000003b9ab9d9000000010000000029ec95b1c9df6cd2598852d78fea7766c1aece1a7b5d24f6cf58adc98107f927000000003d9bdac0ed1d761330cf680efdeb1a42159eb387d6d2950c96f7d28f61bbe2aa00000005000000003b8ab46a0000000100000000000000009e843011540909cc62c64dc85a8a1507813777410000000067614160000000006851245000000000713fb30000000000000000000000000000000000000000000000000000000000000000000000001c87c87cef2e92bface778c711c752168a6e858d58ba62463e8bab336f9b05c98c695acf3c7da02b05c667ce5627e63a60ad53ad7da84734084394dedf6b3c4bb6c85922c2b08b09c55508d49d348ad0dcd9678be58197fef69bad862b1d170f4b0c24f189d9d4b6b5103d28b5e8146d305e28d3dcfb3279f089c7152535a24800c7a1a212868a5c76e3559ea9d4a64d9d000000013d9bdac0ed1d761330cf680efdeb1a42159eb387d6d2950c96f7d28f61bbe2aa0000000700000000713fb3000000000000000000000000010000000161cd7d26c72edc631d4114d6eef2c4e069ec92060000000b0000000000000000000000010000000161cd7d26c72edc631d4114d6eef2c4e069ec92060000000b0000000000000000000000010000000161cd7d26c72edc631d4114d6eef2c4e069ec92060000c350000000020000000900000001b52c42f9bfd2c417d2e4c3251f3ea17ce969ae0579011989a57a3e023793d2226103151470494540b3386a10907ec483c6678ae0fd2681b22a57025632321407000000000900000001b52c42f9bfd2c417d2e4c3251f3ea17ce969ae0579011989a57a3e023793d2226103151470494540b3386a10907ec483c6678ae0fd2681b22a5702563232140700f62a80bf";
let input_bytes = "000000000019000000050000000000000000000000000000000000000000000000000000000000000000000000013d9bdac0ed1d761330cf680efdeb1a42159eb387d6d2950c96f7d28f61bbe2aa000000070000000005e57a370000000000000000000000010000000161cd7d26c72edc631d4114d6eef2c4e069ec9206000000020033b7653ffbf19a2352591e8b6aea8e7c75f38d8e8f5f781cf15aad8425010a000000003d9bdac0ed1d761330cf680efdeb1a42159eb387d6d2950c96f7d28f61bbe2aa00000005000000003b9ab9d9000000010000000029ec95b1c9df6cd2598852d78fea7766c1aece1a7b5d24f6cf58adc98107f927000000003d9bdac0ed1d761330cf680efdeb1a42159eb387d6d2950c96f7d28f61bbe2aa00000005000000003b8ab46a0000000100000000000000009e843011540909cc62c64dc85a8a1507813777410000000067614160000000006851245000000000713fb30000000000000000000000000000000000000000000000000000000000000000000000001c87c87cef2e92bface778c711c752168a6e858d58ba62463e8bab336f9b05c98c695acf3c7da02b05c667ce5627e63a60ad53ad7da84734084394dedf6b3c4bb6c85922c2b08b09c55508d49d348ad0dcd9678be58197fef69bad862b1d170f4b0c24f189d9d4b6b5103d28b5e8146d305e28d3dcfb3279f089c7152535a24800c7a1a212868a5c76e3559ea9d4a64d9d000000013d9bdac0ed1d761330cf680efdeb1a42159eb387d6d2950c96f7d28f61bbe2aa0000000700000000713fb3000000000000000000000000010000000161cd7d26c72edc631d4114d6eef2c4e069ec92060000000b0000000000000000000000010000000161cd7d26c72edc631d4114d6eef2c4e069ec92060000000b0000000000000000000000010000000161cd7d26c72edc631d4114d6eef2c4e069ec92060000c350";
let mut bytes = Bytes::from(hex::decode(input_bytes).expect("Failed to decode hex string"));
let result = AddPermissLessionValidatorTx::try_from(bytes.clone()).unwrap();
assert_eq!(
Expand Down
6 changes: 3 additions & 3 deletions rust/apps/avalanche/src/transactions/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl AvaxTxInfo for ImportTx {
let method = match self.source_chain {
X_BLOCKCHAIN_ID | X_TEST_BLOCKCHAIN_ID => "Sending from X-Chain",
P_BLOCKCHAIN_ID => "Sending from P-Chain",
C_BLOCKCHAIN_ID => "Sending from C-Chain",
C_BLOCKCHAIN_ID | C_TEST_BLOCKCHAIN_ID => "Sending from C-Chain",
_ => "Unknown",
};

Expand All @@ -52,8 +52,8 @@ impl AvaxTxInfo for ImportTx {
}

impl ImportTx {
fn get_base_tx(&self) -> &BaseTx {
&self.base_tx
pub fn get_source_chain_id(&self) -> [u8; BLOCKCHAIN_ID_LEN] {
self.source_chain
}
}

Expand Down
2 changes: 1 addition & 1 deletion rust/apps/avalanche/src/transactions/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pub trait AvaxTxInfo {
fn get_output_amount(&self, address: String) -> u64 {
self.get_outputs_addresses()
.iter()
.find(|info| {info.address[0] == address})
.find(|info| info.address[0] == address)
.map(|info| info.amount)
.unwrap_or(0)
}
Expand Down
4 changes: 2 additions & 2 deletions rust/apps/wallets/src/core_wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ fn get_device_id(serial_number: &str) -> String {
hex::encode(&sha256(&sha256(serial_number.as_bytes()))[0..20])
}

const AVAX_STANDARD_PREFIX: &str = "m/44'/60'/0'";
const AVAX_X_P_PREFIX: &str = "m/44'/9000'/0'";
const AVAX_STANDARD_PREFIX: &str = "44'/60'/0'";
const AVAX_X_P_PREFIX: &str = "44'/9000'/0'";

pub fn generate_crypto_multi_accounts(
master_fingerprint: [u8; 4],
Expand Down
37 changes: 19 additions & 18 deletions rust/rust_c/src/avalanche/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,36 +172,37 @@ pub fn determine_derivation_path(
wallet_index: u64,
) -> Result<DerivationPath, AvaxError> {
let wallet_suffix = format!("/0/{}", wallet_index);
let blockchain_id = get_avax_tx_header(sign_request.get_tx_data())?.get_blockchain_id();
let is_c_chain = |id: &[u8; 32]| *id == C_BLOCKCHAIN_ID || *id == C_TEST_BLOCKCHAIN_ID;

let (base_path, full_path) = match type_id {
TypeId::CchainExportTx => (
C_CHAIN_PREFIX,
format!("{}{}", C_CHAIN_PREFIX, wallet_suffix),
),
TypeId::BaseTx => {
let blockchain_id = get_avax_tx_header(sign_request.get_tx_data())?.get_blockchain_id();

if blockchain_id == C_BLOCKCHAIN_ID || blockchain_id == C_TEST_BLOCKCHAIN_ID {
(
C_CHAIN_PREFIX,
format!("{}{}", C_CHAIN_PREFIX, wallet_suffix),
)
TypeId::XchainImportTx | TypeId::PchainImportTx => {
let source_chain_id =
parse_avax_tx::<ImportTx>(sign_request.get_tx_data())?.get_source_chain_id();
let prefix = if is_c_chain(&source_chain_id) {
C_CHAIN_PREFIX
} else {
(
X_P_CHAIN_PREFIX,
format!("{}{}", X_P_CHAIN_PREFIX, wallet_suffix),
)
}
X_P_CHAIN_PREFIX
};
(prefix, format!("{}{}", prefix, wallet_suffix))
}
_ => {
let prefix = if is_c_chain(&blockchain_id) {
C_CHAIN_PREFIX
} else {
X_P_CHAIN_PREFIX
};
(prefix, format!("{}{}", prefix, wallet_suffix))
}
_ => (
X_P_CHAIN_PREFIX,
format!("{}{}", X_P_CHAIN_PREFIX, wallet_suffix),
),
};

Ok(DerivationPath {
base_path: base_path.to_string(),
full_path: full_path,
full_path,
})
}

Expand Down
17 changes: 11 additions & 6 deletions rust/rust_c/src/avalanche/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,20 @@ impl_c_ptr!(DisplayAvaxFromToInfo);
impl DisplayAvaxFromToInfo {
fn from_index(value: &AvaxFromToInfo, wallet_index: u64, from_address: String) -> Self {
let address = value.address.get(0).unwrap().clone();
let is_change = address == from_address;
let path = if is_change == false {
null_mut()
} else {
convert_c_char(format!("{}/0/{}", value.path_prefix, wallet_index))
};
DisplayAvaxFromToInfo {
address: convert_c_char(address.clone()),
amount: convert_c_char(format!(
"{} AVAX",
value.amount as f64 / NAVAX_TO_AVAX_RATIO
)),
path: convert_c_char(format!("{}/0/{}", value.path_prefix, wallet_index)),
is_change: address == from_address,
is_change,
path,
}
}
}
Expand Down Expand Up @@ -147,10 +153,9 @@ impl DisplayTxAvaxData {
}
.c_ptr(),
amount: convert_c_char(format!(
"{} AVAX",value.get_output_amount(
from_address.clone()
) as f64
/ NAVAX_TO_AVAX_RATIO)),
"{} AVAX",
value.get_output_amount(from_address.clone()) as f64 / NAVAX_TO_AVAX_RATIO
)),

total_input_amount: convert_c_char(format!(
"{} AVAX",
Expand Down
5 changes: 0 additions & 5 deletions src/ui/gui_analyze/gui_resolve_ur.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,9 @@ static SetChainData_t g_chainViewArray[] = {

void HandleDefaultViewType(URParseResult *urResult, URParseMultiResult *urMultiResult, UrViewType_t urViewType, bool is_multi)
{
printf("%s %d.\n", __func__, __LINE__);
GuiRemapViewType viewType = ViewTypeReMap(urViewType.viewType);
printf("%s %d.\n", __func__, __LINE__);
printf("viewType=%d\r\n", viewType);
for (int i = 0; i < NUMBER_OF_ARRAYS(g_chainViewArray); i++) {
if (g_chainViewArray[i].chain == viewType) {
printf("%s %d.\n", __func__, __LINE__);
printf("g_chainViewArray[i].type=%d\r\n", g_chainViewArray[i].chain);
g_chainViewArray[viewType].func(urResult, urMultiResult, is_multi);
break;
}
Expand Down
Loading
Loading