Skip to content
This repository has been archived by the owner on Aug 22, 2024. It is now read-only.

feat: impl larger buffs for FunctionCall on nanosp and nanox #45

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
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
4 changes: 2 additions & 2 deletions src/app_ui/sign/common/action/function_call_bin.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::app_ui::fields_writer::FieldsWriter;
use crate::parsing::types::common::action::function_call::ArgsBinaryRepresentation;
use crate::utils::types::elipsis_fields::ElipsisFields;
use crate::utils::types::hex_display::HexDisplay;

pub struct FieldsContext {
pub args_display_buf: [u8; 20],
Expand All @@ -14,7 +14,7 @@ impl FieldsContext {
}
}
pub fn format<'b, 'a: 'b>(
args: &'b HexDisplay<200>,
args: &'b ArgsBinaryRepresentation,
field_context: &'a mut FieldsContext,
writer: &'_ mut FieldsWriter<'b, 7>,
) {
Expand Down
5 changes: 1 addition & 4 deletions src/app_ui/sign/common/action/function_call_common.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use crate::{
parsing::{self},
utils::types::elipsis_fields::ElipsisFields,
};
use crate::{parsing, utils::types::elipsis_fields::ElipsisFields};
use fmt_buffer::Buffer;
use ledger_device_sdk::ui::gadgets::Field;

Expand Down
4 changes: 2 additions & 2 deletions src/app_ui/sign/common/action/function_call_str.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::utils::types::capped_string::CappedString;
use crate::parsing::types::common::action::function_call::ArgsStringRepresentation;

use crate::app_ui::fields_writer::FieldsWriter;
use crate::utils::types::elipsis_fields::ElipsisFields;
Expand All @@ -15,7 +15,7 @@ impl FieldsContext {
}
}
pub fn format<'b, 'a: 'b>(
args: &'b CappedString<200>,
args: &'b ArgsStringRepresentation,
field_context: &'a mut FieldsContext,
writer: &'_ mut FieldsWriter<'b, 7>,
) {
Expand Down
7 changes: 3 additions & 4 deletions src/app_ui/sign/common/action/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use crate::{
app_ui::fields_writer::FieldsWriter,
handlers::common::action::ActionParams,
parsing,
utils::types::{capped_string::CappedString, hex_display::HexDisplay},
parsing::{self, types::common::action::function_call::{ArgsBinaryRepresentation, ArgsStringRepresentation}},
};
use fmt_buffer::Buffer;

Expand Down Expand Up @@ -124,7 +123,7 @@ pub fn ui_display_deploy_contract(

pub fn ui_display_function_call_str(
func_call_common: &parsing::types::FunctionCallCommon,
args: &CappedString<200>,
args: &ArgsStringRepresentation,
params: ActionParams,
) -> bool {
let mut writer: FieldsWriter<'_, 7> = FieldsWriter::new();
Expand All @@ -141,7 +140,7 @@ pub fn ui_display_function_call_str(

pub fn ui_display_function_call_bin(
func_call_common: &parsing::types::FunctionCallCommon,
args: &HexDisplay<200>,
args: &ArgsBinaryRepresentation,
params: ActionParams,
) -> bool {
let mut writer: FieldsWriter<'_, 7> = FieldsWriter::new();
Expand Down
17 changes: 11 additions & 6 deletions src/handlers/common/action/function_call.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
use crate::parsing::types::common::action::function_call::{
ArgsBinaryRepresentation, ArgsStringRepresentation,
};
use crate::parsing::types::FunctionCallCommon;
use crate::sign_ui;
use crate::utils::types::capped_string::CappedString;
Expand Down Expand Up @@ -31,11 +34,13 @@ pub fn handle(
{
// '{' char
Some(123) => {
let mut args_str: CappedString<200> = CappedString::new();
let mut args_str: ArgsStringRepresentation = CappedString::new();
match args_str.deserialize_with_bytes_count(stream, args_bytes_count) {
Err(err) if err.kind() == ErrorKind::InvalidData => {
let mut args_bin: HexDisplay<200> = unsafe {
core::mem::transmute::<CappedString<200>, HexDisplay<200>>(args_str)
let mut args_bin: ArgsBinaryRepresentation = unsafe {
core::mem::transmute::<ArgsStringRepresentation, ArgsBinaryRepresentation>(
args_str,
)
};
args_bin.reformat();
ArgsRepr::BinHex(args_bin)
Expand All @@ -47,7 +52,7 @@ pub fn handle(
}
}
Some(_first_byte) => {
let mut args_bin: HexDisplay<200> = HexDisplay::new();
let mut args_bin: ArgsBinaryRepresentation = HexDisplay::new();
args_bin
.deserialize_with_bytes_count(stream, args_bytes_count)
.map_err(|_err| AppSW::TxParsingFail)?;
Expand Down Expand Up @@ -85,6 +90,6 @@ fn handle_common(
}

enum ArgsRepr {
String(CappedString<200>),
BinHex(HexDisplay<200>),
String(ArgsStringRepresentation),
BinHex(ArgsBinaryRepresentation),
}
14 changes: 14 additions & 0 deletions src/parsing/types/common/action/function_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,23 @@ use near_gas::NearGas;
use near_token::NearToken;

use crate::utils::types::capped_string::CappedString;
use crate::utils::types::hex_display::HexDisplay;
use borsh::io::{Read, Result};
use borsh::BorshDeserialize;

#[cfg(target_os = "nanos")]
pub type ArgsStringRepresentation = CappedString<200>;
#[cfg(target_os = "nanos")]
pub type ArgsBinaryRepresentation = HexDisplay<200>;
#[cfg(target_os = "nanosplus")]
pub type ArgsStringRepresentation = CappedString<1000>;
#[cfg(target_os = "nanosplus")]
pub type ArgsBinaryRepresentation = HexDisplay<1000>;
#[cfg(target_os = "nanox")]
pub type ArgsStringRepresentation = CappedString<1000>;
#[cfg(target_os = "nanox")]
pub type ArgsBinaryRepresentation = HexDisplay<1000>;

pub struct FunctionCallCommon {
pub method_name: CappedString<50>,
pub gas: NearGas,
Expand Down
Loading