Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NFC: Move previously added code from Move crates to extensions for Solana #77

Merged
merged 1 commit into from
Jul 12, 2024
Merged
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
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
Loading