Unfinalized program format is now same as mvir compiler outputs (#5458)
This commit is contained in:
@ -9,6 +9,7 @@ use stdlib::stdlib_modules;
|
||||
use types::{
|
||||
account_address::AccountAddress,
|
||||
byte_array::ByteArray,
|
||||
transaction::Program,
|
||||
write_set::{WriteOp, WriteSet},
|
||||
};
|
||||
use vm::{
|
||||
@ -38,11 +39,8 @@ fn to_array_32(array: &[u8]) -> &[u8; 32] {
|
||||
pub enum LibraAccountState {
|
||||
/// No data for this account yet
|
||||
Unallocated,
|
||||
/// Serialized compiled program bytes
|
||||
CompiledProgram {
|
||||
script_bytes: Vec<u8>,
|
||||
modules_bytes: Vec<Vec<u8>>,
|
||||
},
|
||||
/// Json string representation of types::transaction::Program
|
||||
CompiledProgram(String),
|
||||
/// Serialized verified program bytes
|
||||
VerifiedProgram {
|
||||
script_bytes: Vec<u8>,
|
||||
@ -101,10 +99,9 @@ impl LibraAccountState {
|
||||
.expect("Unable to serialize module");
|
||||
modules_bytes.push(buf);
|
||||
}
|
||||
LibraAccountState::CompiledProgram {
|
||||
script_bytes,
|
||||
modules_bytes,
|
||||
}
|
||||
LibraAccountState::CompiledProgram(
|
||||
serde_json::to_string(&Program::new(script_bytes, modules_bytes, vec![])).unwrap(),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn create_user(owner: &Pubkey, write_set: WriteSet) -> Self {
|
||||
|
@ -25,6 +25,11 @@ pub fn map_data_error(err: std::boxed::Box<bincode::ErrorKind>) -> InstructionEr
|
||||
debug!("Error: Account data: {:?}", err);
|
||||
InstructionError::InvalidAccountData
|
||||
}
|
||||
#[allow(clippy::needless_pass_by_value)]
|
||||
pub fn map_json_error(err: serde_json::error::Error) -> InstructionError {
|
||||
debug!("Error: serde_json: {:?}", err);
|
||||
InstructionError::InvalidAccountData
|
||||
}
|
||||
pub fn map_vm_verification_error(
|
||||
err: (CompiledModule, Vec<vm::errors::VerificationError>),
|
||||
) -> InstructionError {
|
||||
|
@ -11,7 +11,7 @@ use solana_sdk::{
|
||||
};
|
||||
use types::{
|
||||
account_address::AccountAddress,
|
||||
transaction::{TransactionArgument, TransactionOutput},
|
||||
transaction::{Program, TransactionArgument, TransactionOutput},
|
||||
};
|
||||
use vm::{
|
||||
access::ModuleAccess,
|
||||
@ -123,51 +123,51 @@ impl MoveProcessor {
|
||||
fn deserialize_compiled_program(
|
||||
data: &[u8],
|
||||
) -> Result<(CompiledScript, Vec<CompiledModule>), InstructionError> {
|
||||
let (script_bytes, modules_bytes) =
|
||||
match bincode::deserialize(data).map_err(map_data_error)? {
|
||||
LibraAccountState::CompiledProgram {
|
||||
script_bytes,
|
||||
modules_bytes,
|
||||
} => (script_bytes, modules_bytes),
|
||||
_ => {
|
||||
debug!("Error: Program account does not contain a program");
|
||||
return Err(InstructionError::InvalidArgument);
|
||||
}
|
||||
};
|
||||
match bincode::deserialize(data).map_err(map_data_error)? {
|
||||
LibraAccountState::CompiledProgram(string) => {
|
||||
let program: Program = serde_json::from_str(&string).map_err(map_json_error)?;
|
||||
|
||||
let script = CompiledScript::deserialize(&script_bytes).map_err(map_vm_binary_error)?;
|
||||
let modules = modules_bytes
|
||||
.iter()
|
||||
.map(|bytes| CompiledModule::deserialize(&bytes))
|
||||
.collect::<Result<Vec<_>, _>>()
|
||||
.map_err(map_vm_binary_error)?;
|
||||
let script =
|
||||
CompiledScript::deserialize(&program.code()).map_err(map_vm_binary_error)?;
|
||||
let modules = program
|
||||
.modules()
|
||||
.iter()
|
||||
.map(|bytes| CompiledModule::deserialize(&bytes))
|
||||
.collect::<Result<Vec<_>, _>>()
|
||||
.map_err(map_vm_binary_error)?;
|
||||
|
||||
Ok((script, modules))
|
||||
Ok((script, modules))
|
||||
}
|
||||
_ => {
|
||||
debug!("Error: Program account does not contain a program");
|
||||
Err(InstructionError::InvalidArgument)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn deserialize_verified_program(
|
||||
data: &[u8],
|
||||
) -> Result<(VerifiedScript, Vec<VerifiedModule>), InstructionError> {
|
||||
let (script_bytes, modules_bytes) =
|
||||
match bincode::deserialize(data).map_err(map_data_error)? {
|
||||
LibraAccountState::VerifiedProgram {
|
||||
script_bytes,
|
||||
modules_bytes,
|
||||
} => (script_bytes, modules_bytes),
|
||||
_ => {
|
||||
debug!("Error: Program account does not contain a program");
|
||||
return Err(InstructionError::InvalidArgument);
|
||||
}
|
||||
};
|
||||
match bincode::deserialize(data).map_err(map_data_error)? {
|
||||
LibraAccountState::VerifiedProgram {
|
||||
script_bytes,
|
||||
modules_bytes,
|
||||
} => {
|
||||
let script =
|
||||
VerifiedScript::deserialize(&script_bytes).map_err(map_vm_binary_error)?;
|
||||
let modules = modules_bytes
|
||||
.iter()
|
||||
.map(|bytes| VerifiedModule::deserialize(&bytes))
|
||||
.collect::<Result<Vec<_>, _>>()
|
||||
.map_err(map_vm_binary_error)?;
|
||||
|
||||
let script = VerifiedScript::deserialize(&script_bytes).map_err(map_vm_binary_error)?;
|
||||
let modules = modules_bytes
|
||||
.iter()
|
||||
.map(|bytes| VerifiedModule::deserialize(&bytes))
|
||||
.collect::<Result<Vec<_>, _>>()
|
||||
.map_err(map_vm_binary_error)?;
|
||||
|
||||
Ok((script, modules))
|
||||
Ok((script, modules))
|
||||
}
|
||||
_ => {
|
||||
debug!("Error: Program account does not contain a program");
|
||||
Err(InstructionError::InvalidArgument)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn execute(
|
||||
|
Reference in New Issue
Block a user