Skip to content

Commit

Permalink
NFC: Move previously added code from Move crates to extensions for So…
Browse files Browse the repository at this point in the history
…lana (#77)

071124-remove-code-from-sui-crates: ini
  • Loading branch information
jcivlin authored Jul 12, 2024
1 parent bbf963f commit f9629c8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,18 +104,6 @@ impl From<&u256::U256> for Constant {
Constant::U256(U256::from(n))
}
}
impl From<&Vec<u8>> for Constant {
fn from(v: &Vec<u8>) -> Constant {
Constant::ByteArray(v.clone())
}
}

pub fn transform_bytearray_to_vec(val_vec: &[Constant]) -> Option<&Vec<u8>> {
if let Some(Constant::ByteArray(ref vec)) = val_vec.first() {
return Some(vec);
}
None
}

/// An operation -- target of a call. This contains user functions, builtin functions, and
/// operators.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
//! Extension traits for foreign types.
use crate::stackless::llvm;
use move_stackless_bytecode::stackless_bytecode as sbc;
use extension_trait::extension_trait;
use move_binary_format::file_format::SignatureToken;
use move_core_types::account_address;
Expand Down Expand Up @@ -251,6 +252,20 @@ pub impl SignatureTokenExt for SignatureToken {
}
}

#[extension_trait]
pub impl ConstantExtensions for sbc::Constant {
fn from_vec_u8(v: &Vec<u8>) -> sbc::Constant {
sbc::Constant::ByteArray(v.clone())
}
}

pub fn transform_bytearray_to_vec(val_vec: &[sbc::Constant]) -> Option<&Vec<u8>> {
if let Some(sbc::Constant::ByteArray(ref vec)) = val_vec.first() {
return Some(vec);
}
None
}

#[test]
fn test_symbol_name() {
use move_compiler::shared::PackagePaths;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1899,7 +1899,7 @@ impl<'mm, 'up> FunctionContext<'mm, 'up> {
assert!(matches!(val_vec[0], Constant::ByteArray(_)));
}

let vec = match move_stackless_bytecode::stackless_bytecode::transform_bytearray_to_vec(&val_vec) {
let vec = match transform_bytearray_to_vec(&val_vec) {
Some(v) => v.clone(),
None => {
debug!(target: "constant", "No ByteArray found, using empty vector");
Expand Down

0 comments on commit f9629c8

Please sign in to comment.