Skip to content

Commit

Permalink
Add swap_return() function to wrap unsafe calls
Browse files Browse the repository at this point in the history
  • Loading branch information
yogh333 committed Dec 13, 2024
1 parent dd96b2a commit b5cd3c9
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions ledger_device_sdk/src/libcall/swap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,29 @@ pub fn sign_tx_params(arg0: u32) -> CreateTxParams {
create_tx_params
}
}

pub enum SwapResult<'a> {
CheckAddressResult(&'a mut CheckAddressParams, i32),
PrintableAmountResult(&'a mut PrintableAmountParams, &'a str),
CreateTxResult(&'a mut CreateTxParams, u8),
}

pub fn swap_return(res: SwapResult) {
unsafe {
match res {
SwapResult::CheckAddressResult(&mut ref p, r) => {
*(p.result) = r;
}
SwapResult::PrintableAmountResult(&mut ref p, s) => {
for (i, c) in s.chars().enumerate() {
*(p.amount_str.add(i)) = c as i8;
}
*(p.amount_str.add(s.len())) = '\0' as i8;
}
SwapResult::CreateTxResult(&mut ref p, r) => {
*(p.result) = r;
}
}
ledger_secure_sdk_sys::os_lib_end();
}
}

0 comments on commit b5cd3c9

Please sign in to comment.