Skip to content

Commit

Permalink
code dedup
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei-marinica committed Dec 27, 2024
1 parent 156c06b commit 8190260
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 18 deletions.
6 changes: 4 additions & 2 deletions chain/vm/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ pub type RawHandle = i32;
use num_bigint::BigUint;
use num_traits::Zero;

pub(crate) fn top_encode_u64(value: u64) -> Vec<u8> {
/// Helper function to quickly encode a u64 value, according to the MultiversX codec format.
pub fn top_encode_u64(value: u64) -> Vec<u8> {
top_encode_big_uint(&BigUint::from(value))
}

pub(crate) fn top_encode_big_uint(value: &BigUint) -> Vec<u8> {
/// Helper function to quickly encode a BigUint value, according to the MultiversX codec format.
pub fn top_encode_big_uint(value: &BigUint) -> Vec<u8> {
if value.is_zero() {
Vec::new()
} else {
Expand Down
17 changes: 1 addition & 16 deletions framework/scenario/src/scenario/model/transaction/tx_call.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use multiversx_chain_vm::types::{top_encode_big_uint, top_encode_u64};
use multiversx_sc::api::{
ESDT_MULTI_TRANSFER_FUNC_NAME, ESDT_NFT_TRANSFER_FUNC_NAME, ESDT_TRANSFER_FUNC_NAME,
};
use num_bigint::BigUint;

use crate::{
api::StaticApi,
Expand Down Expand Up @@ -235,18 +235,3 @@ impl TxCall {
(ESDT_MULTI_TRANSFER_FUNC_NAME.to_owned(), arguments, true)
}
}

// TODO: dedup
fn top_encode_u64(value: u64) -> Vec<u8> {
top_encode_big_uint(&BigUint::from(value))
}

// TODO: dedup
fn top_encode_big_uint(value: &BigUint) -> Vec<u8> {
use num_traits::Zero;
if value.is_zero() {
Vec::new()
} else {
value.to_bytes_be()
}
}

0 comments on commit 8190260

Please sign in to comment.