diff --git a/crates/codec/src/api/json/receipt.rs b/crates/codec/src/api/json/receipt.rs index 22d852047..d8bbe9a65 100644 --- a/crates/codec/src/api/json/receipt.rs +++ b/crates/codec/src/api/json/receipt.rs @@ -4,9 +4,9 @@ use crate::api::json::{self, JsonError}; use crate::receipt; use svm_types::RuntimeError; -use svm_types::{CallReceipt, Receipt, ReceiptLog, SpawnReceipt, TemplateReceipt}; +use svm_types::{CallReceipt, DeployReceipt, Receipt, ReceiptLog, SpawnReceipt}; -/// Given a binary Receipt wrappend inside a JSON, +/// Given a binary Receipt wrapped inside a JSON, /// decodes it into a user-friendly JSON. pub fn decode_receipt(json: &Value) -> Result { let data = json::as_string(json, "data")?; @@ -19,9 +19,9 @@ pub fn decode_receipt(json: &Value) -> Result { let json = if receipt.success() { match receipt { - Receipt::DeployTemplate(receipt) => decode_deploy_template(&receipt, ty), - Receipt::SpawnApp(receipt) => decode_spawn_app(&receipt, ty), - Receipt::ExecApp(receipt) => decode_exe_app(&receipt, ty), + Receipt::Deploy(receipt) => decode_deploy_template(&receipt, ty), + Receipt::Spawn(receipt) => decode_spawn_app(&receipt, ty), + Receipt::Call(receipt) => decode_exe_app(&receipt, ty), } } else { let ty = receipt_type(&receipt); @@ -36,9 +36,9 @@ pub fn decode_receipt(json: &Value) -> Result { fn receipt_type(receipt: &Receipt) -> &'static str { match receipt { - Receipt::DeployTemplate(..) => "deploy-template", - Receipt::SpawnApp(..) => "spawn-app", - Receipt::ExecApp(..) => "exec-app", + Receipt::Deploy(..) => "deploy-template", + Receipt::Spawn(..) => "spawn-app", + Receipt::Call(..) => "exec-app", } } @@ -135,11 +135,11 @@ fn decode_error(ty: &'static str, err: &RuntimeError, logs: &[ReceiptLog]) -> Va map.into() } -fn decode_deploy_template(receipt: &TemplateReceipt, ty: &'static str) -> Value { +fn decode_deploy_template(receipt: &DeployReceipt, ty: &'static str) -> Value { debug_assert!(receipt.success); debug_assert!(receipt.error.is_none()); - let TemplateReceipt { + let DeployReceipt { addr, gas_used, logs, @@ -224,7 +224,7 @@ mod tests { }, ]; - let receipt = TemplateReceipt { + let receipt = DeployReceipt { version: 0, success: true, error: None, diff --git a/crates/codec/src/receipt/deploy_template.rs b/crates/codec/src/receipt/deploy_template.rs index 624248018..7b81d7f3b 100644 --- a/crates/codec/src/receipt/deploy_template.rs +++ b/crates/codec/src/receipt/deploy_template.rs @@ -13,7 +13,7 @@ use std::io::Cursor; -use svm_types::TemplateReceipt; +use svm_types::DeployReceipt; use super::{decode_error, encode_error, gas, logs, types}; @@ -21,7 +21,7 @@ use crate::version; use crate::{ReadExt, WriteExt}; /// Encodes a `deploy-template` into its binary format. -pub fn encode_template_receipt(receipt: &TemplateReceipt) -> Vec { +pub fn encode_template_receipt(receipt: &DeployReceipt) -> Vec { let mut w = Vec::new(); w.write_byte(types::DEPLOY_TEMPLATE); @@ -42,7 +42,7 @@ pub fn encode_template_receipt(receipt: &TemplateReceipt) -> Vec { } /// Decodes a binary `deploy-template` transaction into its Rust struct. -pub fn decode_template_receipt(bytes: &[u8]) -> TemplateReceipt { +pub fn decode_template_receipt(bytes: &[u8]) -> DeployReceipt { let mut cursor = Cursor::new(bytes); let ty = cursor.read_byte().unwrap(); @@ -57,14 +57,14 @@ pub fn decode_template_receipt(bytes: &[u8]) -> TemplateReceipt { false => { let (err, logs) = decode_error(&mut cursor); - TemplateReceipt::from_err(err, logs) + DeployReceipt::from_err(err, logs) } true => { let addr = cursor.read_address().expect("expected an address"); let gas_used = gas::decode_gas_used(&mut cursor).unwrap(); let logs = logs::decode_logs(&mut cursor).unwrap(); - TemplateReceipt { + DeployReceipt { version, success: true, error: None, @@ -76,13 +76,13 @@ pub fn decode_template_receipt(bytes: &[u8]) -> TemplateReceipt { } } -fn encode_version(receipt: &TemplateReceipt, w: &mut Vec) { +fn encode_version(receipt: &DeployReceipt, w: &mut Vec) { let v = receipt.version; version::encode_version(v, w); } -fn encode_template_addr(receipt: &TemplateReceipt, w: &mut Vec) { +fn encode_template_addr(receipt: &DeployReceipt, w: &mut Vec) { debug_assert!(receipt.success); let addr = receipt.template_addr(); @@ -94,7 +94,7 @@ fn encode_template_addr(receipt: &TemplateReceipt, w: &mut Vec) { mod tests { use super::*; - use svm_types::{Address, Gas, TemplateReceipt}; + use svm_types::{Address, DeployReceipt, Gas}; use crate::receipt::decode_receipt; @@ -102,7 +102,7 @@ mod tests { fn encode_decode_deploy_template_receipt() { let addr = Address::repeat(0xAB); - let receipt = TemplateReceipt { + let receipt = DeployReceipt { version: 0, success: true, error: None, @@ -114,6 +114,6 @@ mod tests { let bytes = encode_template_receipt(&receipt); let decoded = decode_receipt(&bytes); - assert_eq!(decoded.into_deploy_template(), receipt); + assert_eq!(decoded.into_deploy(), receipt); } } diff --git a/crates/codec/src/receipt/mod.rs b/crates/codec/src/receipt/mod.rs index ab96c3ed4..71a2001b7 100644 --- a/crates/codec/src/receipt/mod.rs +++ b/crates/codec/src/receipt/mod.rs @@ -29,15 +29,15 @@ pub fn decode_receipt(bytes: &[u8]) -> Receipt { match ty { types::DEPLOY_TEMPLATE => { let receipt = decode_template_receipt(bytes); - Receipt::DeployTemplate(receipt) + Receipt::Deploy(receipt) } types::SPAWN_APP => { let receipt = decode_app_receipt(bytes); - Receipt::SpawnApp(receipt) + Receipt::Spawn(receipt) } types::EXEC_APP => { let receipt = decode_exec_receipt(bytes); - Receipt::ExecApp(receipt) + Receipt::Call(receipt) } _ => unreachable!(), } diff --git a/crates/runtime-ffi/tests/api_tests.rs b/crates/runtime-ffi/tests/api_tests.rs index 6ffab6c7a..0a5c26614 100644 --- a/crates/runtime-ffi/tests/api_tests.rs +++ b/crates/runtime-ffi/tests/api_tests.rs @@ -163,8 +163,7 @@ fn svm_runtime_failure() { assert!(res.is_ok()); // extract the `Template Address` out of the `Receipt` - let receipt = - receipt::decode_receipt(template_receipt.clone().into()).into_deploy_template(); + let receipt = receipt::decode_receipt(template_receipt.clone().into()).into_deploy(); let template_addr: &Address = receipt.template_addr().inner(); let template_addr: svm_byte_array = (TEMPLATE_ADDR, template_addr).into(); @@ -304,8 +303,7 @@ fn svm_runtime_success() { assert!(res.is_ok()); // extract the `template-address` out of the receipt - let receipt = - receipt::decode_receipt(template_receipt.clone().into()).into_deploy_template(); + let receipt = receipt::decode_receipt(template_receipt.clone().into()).into_deploy(); let template_addr: &Address = receipt.template_addr().inner(); let template_addr: svm_byte_array = (TEMPLATE_ADDR, template_addr).into(); diff --git a/crates/runtime/src/runtime/default.rs b/crates/runtime/src/runtime/default.rs index 652af97b8..91823c80c 100644 --- a/crates/runtime/src/runtime/default.rs +++ b/crates/runtime/src/runtime/default.rs @@ -5,7 +5,7 @@ use svm_storage::app::AppStorage; use svm_types::GasMode; use svm_types::SectionKind; use svm_types::{AccountAddr, DeployerAddr, SpawnerAddr, State, Template}; -use svm_types::{CallReceipt, ReceiptLog, SpawnReceipt, TemplateReceipt}; +use svm_types::{CallReceipt, DeployReceipt, ReceiptLog, SpawnReceipt}; use svm_types::{Gas, OOGError}; use svm_types::{RuntimeError, Transaction}; use wasmer::{Instance, Module, WasmPtr, WasmTypeList}; @@ -583,7 +583,7 @@ where bytes: &[u8], _deployer: &DeployerAddr, gas_limit: Gas, - ) -> TemplateReceipt { + ) -> DeployReceipt { info!("Deploying a template."); let template = self.env.parse_deploy_template(bytes, None).unwrap(); @@ -595,9 +595,9 @@ where let addr = self.env.compute_template_addr(&template); self.env.store_template(&template, &addr); - TemplateReceipt::new(addr, gas_used) + DeployReceipt::new(addr, gas_used) } else { - TemplateReceipt::new_oog() + DeployReceipt::new_oog() } } diff --git a/crates/runtime/src/runtime/mod.rs b/crates/runtime/src/runtime/mod.rs index d85b25eeb..4da998af7 100644 --- a/crates/runtime/src/runtime/mod.rs +++ b/crates/runtime/src/runtime/mod.rs @@ -24,8 +24,8 @@ pub use default::DefaultRuntime; pub use ptr::RuntimePtr; use svm_types::{ - CallReceipt, DeployerAddr, Gas, RuntimeError, SpawnReceipt, SpawnerAddr, State, - TemplateReceipt, Transaction, + CallReceipt, DeployReceipt, DeployerAddr, Gas, RuntimeError, SpawnReceipt, SpawnerAddr, State, + Transaction, }; use crate::error::ValidateError; @@ -51,7 +51,7 @@ pub trait Runtime { bytes: &[u8], deployer: &DeployerAddr, gas_limit: Gas, - ) -> TemplateReceipt; + ) -> DeployReceipt; /// Spawns a new app out of an existing app-template. fn spawn_app(&mut self, bytes: &[u8], spawner: &SpawnerAddr, gas_limit: Gas) -> SpawnReceipt; diff --git a/crates/runtime/tests/runtime_tests.rs b/crates/runtime/tests/runtime_tests.rs index 82808420f..a02d7e7e6 100644 --- a/crates/runtime/tests/runtime_tests.rs +++ b/crates/runtime/tests/runtime_tests.rs @@ -12,7 +12,7 @@ use svm_layout::FixedLayout; use svm_runtime::{testing, Runtime, ValidateError}; use svm_types::{Address, Gas, RuntimeError}; -use svm_types::{SpawnReceipt, TemplateReceipt}; +use svm_types::{DeployReceipt, SpawnReceipt}; fn memory_runtime() -> impl Runtime { let state_kv = testing::memory_state_kv_init(); @@ -97,7 +97,7 @@ fn memory_runtime_deploy_template_reaches_oog() { include_str!("wasm/runtime_app_ctor.wast").into(), ); - let expected = TemplateReceipt::new_oog(); + let expected = DeployReceipt::new_oog(); let actual = runtime.deploy_template(&bytes, &deployer, maybe_gas); assert_eq!(expected, actual); } diff --git a/crates/types/src/lib.rs b/crates/types/src/lib.rs index b64308d63..b5602c198 100644 --- a/crates/types/src/lib.rs +++ b/crates/types/src/lib.rs @@ -34,7 +34,7 @@ pub use gas::{Gas, GasMode, OOGError}; mod receipt; pub use receipt::{ - into_spawn_receipt, CallReceipt, Receipt, ReceiptLog, ReceiptRef, SpawnReceipt, TemplateReceipt, + into_spawn_receipt, CallReceipt, DeployReceipt, Receipt, ReceiptLog, ReceiptRef, SpawnReceipt, }; /// Address-related types diff --git a/crates/types/src/receipt/deploy_template.rs b/crates/types/src/receipt/deploy_template.rs index 95110a82e..31ccc846b 100644 --- a/crates/types/src/receipt/deploy_template.rs +++ b/crates/types/src/receipt/deploy_template.rs @@ -7,7 +7,7 @@ use crate::{Gas, TemplateAddr}; /// [`TemplateReceipt`] should *not* be wrapped in a [`Result`] for failure /// detection; error detection is built-in the type itself. #[derive(Debug, PartialEq, Clone)] -pub struct TemplateReceipt { +pub struct DeployReceipt { /// Transaction format version pub version: u16, @@ -27,7 +27,7 @@ pub struct TemplateReceipt { pub logs: Vec, } -impl TemplateReceipt { +impl DeployReceipt { /// Creates a [`TemplateReceipt`] which indicates a successful deployment of /// the template located at `addr` which cost `gas_used`. pub fn new(addr: TemplateAddr, gas_used: Gas) -> Self { diff --git a/crates/types/src/receipt/mod.rs b/crates/types/src/receipt/mod.rs index ee5f8d8d3..0261edc5c 100644 --- a/crates/types/src/receipt/mod.rs +++ b/crates/types/src/receipt/mod.rs @@ -3,7 +3,7 @@ mod execute; mod log; mod spawn; -pub use deploy_template::TemplateReceipt; +pub use deploy_template::DeployReceipt; pub use execute::CallReceipt; pub use log::ReceiptLog; pub use spawn::{into_spawn_receipt, SpawnReceipt}; @@ -13,98 +13,98 @@ use crate::RuntimeError; /// Borrowed Receipt pub enum ReceiptRef<'a> { - /// Borrows a `TemplateReceipt`. - DeployTemplate(&'a TemplateReceipt), + /// Borrows a `DeployReceipt`. + Deploy(&'a DeployReceipt), - /// Borrows a `SpawnAppReceipt`. - SpawnApp(&'a SpawnReceipt), + /// Borrows a `SpawnReceipt`. + Spawn(&'a SpawnReceipt), - /// Borrows a `ExecReceipt`. - ExecApp(&'a CallReceipt), + /// Borrows a `CallReceipt`. + Call(&'a CallReceipt), } impl<'a> ReceiptRef<'a> { /// Returns whether the transaction succeeded. pub fn is_success(&self) -> bool { match self { - Self::DeployTemplate(r) => r.success, - Self::SpawnApp(r) => r.success, - Self::ExecApp(r) => r.success, + Self::Deploy(r) => r.success, + Self::Spawn(r) => r.success, + Self::Call(r) => r.success, } } /// Returns the executed transaction results. pub fn returndata(&self) -> &Vec { match self { - Self::DeployTemplate(..) => unreachable!(), - Self::SpawnApp(r) => r.returndata(), - Self::ExecApp(r) => r.returndata(), + Self::Deploy(..) => unreachable!(), + Self::Spawn(r) => r.returndata(), + Self::Call(r) => r.returndata(), } } /// Returns the gas used for the transaction. - pub fn get_gas_used(&self) -> Gas { + pub fn gas_used(&self) -> Gas { match self { - Self::DeployTemplate(r) => r.gas_used, - Self::SpawnApp(r) => r.gas_used, - Self::ExecApp(r) => r.gas_used, + Self::Deploy(r) => r.gas_used, + Self::Spawn(r) => r.gas_used, + Self::Call(r) => r.gas_used, } } /// Returns a `ReceiptError` pub fn error(&self) -> &RuntimeError { match self { - Self::DeployTemplate(r) => r.error.as_ref().unwrap(), - Self::SpawnApp(r) => r.error.as_ref().unwrap(), - Self::ExecApp(r) => r.error.as_ref().unwrap(), + Self::Deploy(r) => r.error.as_ref().unwrap(), + Self::Spawn(r) => r.error.as_ref().unwrap(), + Self::Call(r) => r.error.as_ref().unwrap(), } } } -/// Holds some Receipt-type +/// Holds a Receipt of kind `Deploy/Spawn/Call` #[derive(Debug, PartialEq)] pub enum Receipt { - /// Deploy-Template - DeployTemplate(TemplateReceipt), + /// `Deploy Template` + Deploy(DeployReceipt), - /// Spawn-App - SpawnApp(SpawnReceipt), + /// `Spawn Account` + Spawn(SpawnReceipt), - /// Exec-App - ExecApp(CallReceipt), + /// `Call Account` + Call(CallReceipt), } impl Receipt { - /// Returns whether the transaction succedded. + /// Returns whether the transaction succeeded. /// A transaction counts as a `success` when it didn't panic. pub fn success(&self) -> bool { match self { - Receipt::DeployTemplate(receipt) => receipt.success, - Receipt::SpawnApp(receipt) => receipt.success, - Receipt::ExecApp(receipt) => receipt.success, + Receipt::Deploy(receipt) => receipt.success, + Receipt::Spawn(receipt) => receipt.success, + Receipt::Call(receipt) => receipt.success, } } - /// Returns the inner `deploy-template` receipt - pub fn into_deploy_template(self) -> TemplateReceipt { + /// Returns the inner [`DeployReceipt`] + pub fn into_deploy(self) -> DeployReceipt { match self { - Receipt::DeployTemplate(r) => r, + Receipt::Deploy(r) => r, _ => unreachable!(), } } - /// Returns the inner `spawn-app` receipt + /// Returns the inner [`SpawnReceipt`] pub fn into_spawn_app(self) -> SpawnReceipt { match self { - Receipt::SpawnApp(r) => r, + Receipt::Spawn(r) => r, _ => unreachable!(), } } - /// Returns the inner `exec-app` receipt + /// Returns the inner [`CallReceipt`] pub fn into_exec_app(self) -> CallReceipt { match self { - Receipt::ExecApp(r) => r, + Receipt::Call(r) => r, _ => unreachable!(), } } @@ -112,18 +112,18 @@ impl Receipt { /// Returns the logs generated during the transaction execution pub fn logs(&self) -> &[ReceiptLog] { match self { - Receipt::DeployTemplate(receipt) => receipt.logs(), - Receipt::SpawnApp(receipt) => receipt.logs(), - Receipt::ExecApp(receipt) => receipt.logs(), + Receipt::Deploy(receipt) => receipt.logs(), + Receipt::Spawn(receipt) => receipt.logs(), + Receipt::Call(receipt) => receipt.logs(), } } /// Returns the error within the inner receipt (for failing receipts) pub fn error(&self) -> &RuntimeError { match self { - Receipt::DeployTemplate(receipt) => receipt.error(), - Receipt::SpawnApp(receipt) => receipt.error(), - Receipt::ExecApp(receipt) => receipt.error(), + Receipt::Deploy(receipt) => receipt.error(), + Receipt::Spawn(receipt) => receipt.error(), + Receipt::Call(receipt) => receipt.error(), } } }