Skip to content

Commit 87f5f9d

Browse files
neithanmochcmedeiros
authored andcommitted
fix(magic_number): Define constant to account for extra formatting bytes
1 parent eb2ab36 commit 87f5f9d

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

app/rust/src/parser/transaction_payload/contract_call.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ pub const MAX_STRING_ASCII_TO_SHOW: usize = 60;
1919
// The items in contract_call transactions are
2020
// contract_address, contract_name and function_name
2121
pub const CONTRACT_CALL_BASE_ITEMS: u8 = 3;
22+
// 1 for space, 1 for '(', 1 for ')'
23+
// for example for ammount formatting:
24+
// 123 (STX)
25+
const EXTRA_CHARS_FOR_FORMAT: usize = 3;
2226

2327
const ADDR_STACKING1: &str = "SP000000000000000000002Q6VF78";
2428
const ADDR_STACKING2: &str = "ST000000000000000000002AMW42H";
@@ -377,11 +381,11 @@ impl<'a> TransactionContractCall<'a> {
377381

378382
// Create a buffer for the formatted display
379383
let mut display_buffer =
380-
[0u8; MAX_U128_FORMATTED_SIZE_DECIMAL + TOKEN_SYMBOL_MAX_LEN + 3];
384+
[0u8; MAX_U128_FORMATTED_SIZE_DECIMAL + TOKEN_SYMBOL_MAX_LEN + EXTRA_CHARS_FOR_FORMAT];
381385
let mut pos = 0;
382386

383387
// Copy the formatted amount
384-
if formatted_amount.len() > display_buffer.len() - 3 - token_info.token_symbol.len()
388+
if formatted_amount.len() > display_buffer.len() - EXTRA_CHARS_FOR_FORMAT - token_info.token_symbol.len()
385389
{
386390
return Err(ParserError::UnexpectedBufferEnd);
387391
}
@@ -423,6 +427,7 @@ impl<'a> TransactionContractCall<'a> {
423427
zxformat::pageString(out_value, &address[..address.len()], page_idx)
424428
}
425429
ValueId::ContractPrincipal => {
430+
// holds principal_encoded address + '.' + contract_name + null terminator
426431
let mut data =
427432
[0; C32_ENCODED_ADDRS_LENGTH + ClarityName::MAX_LEN as usize + 1];
428433
let (_, principal) = PrincipalData::contract_principal_from_bytes(payload)?;

0 commit comments

Comments
 (0)