From d0b3345bb3de953f1873584394f09ee484f53607 Mon Sep 17 00:00:00 2001 From: Ed Hastings Date: Thu, 3 Oct 2024 16:35:14 -0700 Subject: [PATCH] reclaims name from deprecated enum for use by replacement enum --- storage/src/global_state/state/mod.rs | 7 +++-- storage/src/system/transfer.rs | 38 +++++++++------------------ 2 files changed, 16 insertions(+), 29 deletions(-) diff --git a/storage/src/global_state/state/mod.rs b/storage/src/global_state/state/mod.rs index 3123dc7e2b..0a414a4a71 100644 --- a/storage/src/global_state/state/mod.rs +++ b/storage/src/global_state/state/mod.rs @@ -82,7 +82,7 @@ use crate::{ mint::Mint, protocol_upgrade::{ProtocolUpgradeError, ProtocolUpgrader}, runtime_native::{Id, RuntimeNative}, - transfer::{NewTransferTargetMode, TransferError, TransferRuntimeArgsBuilder}, + transfer::{TransferError, TransferRuntimeArgsBuilder, TransferTargetMode}, }, tracking_copy::{TrackingCopy, TrackingCopyEntityExt, TrackingCopyError, TrackingCopyExt}, }; @@ -2075,11 +2075,10 @@ pub trait StateProvider { ); match transfer_target_mode { - NewTransferTargetMode::ExistingAccount { .. } - | NewTransferTargetMode::PurseExists { .. } => { + TransferTargetMode::ExistingAccount { .. } | TransferTargetMode::PurseExists { .. } => { // Noop } - NewTransferTargetMode::CreateAccount(account_hash) => { + TransferTargetMode::CreateAccount(account_hash) => { let main_purse = match runtime.mint(U512::zero()) { Ok(uref) => uref, Err(mint_error) => { diff --git a/storage/src/system/transfer.rs b/storage/src/system/transfer.rs index b5992a38ae..90f7ff496f 100644 --- a/storage/src/system/transfer.rs +++ b/storage/src/system/transfer.rs @@ -76,22 +76,10 @@ impl From for TransferError { } } -/// A target mode indicates if a native transfer's arguments will resolve to an existing purse, or -/// will have to create a new account first. -#[derive(Copy, Clone, Debug, PartialEq, Eq)] -pub enum TransferTargetMode { - /// Unknown target mode. - Unknown, - /// Native transfer arguments resolved into a transfer to a purse. - PurseExists(URef), - /// Native transfer arguments resolved into a transfer to an account. - CreateAccount(AccountHash), -} - /// A target mode indicates if a native transfer's arguments will resolve to an existing purse, or /// will have to create a new account first. #[derive(Copy, Clone, Debug, PartialEq)] -pub enum NewTransferTargetMode { +pub enum TransferTargetMode { /// Native transfer arguments resolved into a transfer to an existing account. ExistingAccount { /// Existing account hash. @@ -110,19 +98,19 @@ pub enum NewTransferTargetMode { CreateAccount(AccountHash), } -impl NewTransferTargetMode { +impl TransferTargetMode { /// Target account hash, if any. pub fn target_account_hash(&self) -> Option { match self { - NewTransferTargetMode::PurseExists { + TransferTargetMode::PurseExists { target_account_hash, .. } => *target_account_hash, - NewTransferTargetMode::ExistingAccount { + TransferTargetMode::ExistingAccount { target_account_hash, .. } => Some(*target_account_hash), - NewTransferTargetMode::CreateAccount(target_account_hash) => Some(*target_account_hash), + TransferTargetMode::CreateAccount(target_account_hash) => Some(*target_account_hash), } } } @@ -311,12 +299,12 @@ impl TransferRuntimeArgsBuilder { /// If the "target" account hash is not existing, then a special variant is returned that /// indicates that the system has to create new account first. /// - /// Returns [`NewTransferTargetMode`] with a resolved variant. + /// Returns [`TransferTargetMode`] with a resolved variant. pub fn resolve_transfer_target_mode( &mut self, protocol_version: ProtocolVersion, tracking_copy: Rc>>, - ) -> Result + ) -> Result where R: StateReader, { @@ -342,7 +330,7 @@ impl TransferRuntimeArgsBuilder { return Err(TransferError::InvalidPurse); } - return Ok(NewTransferTargetMode::PurseExists { + return Ok(TransferTargetMode::PurseExists { purse_uref, target_account_hash, }); @@ -371,12 +359,12 @@ impl TransferRuntimeArgsBuilder { { Ok((_, entity)) => { let main_purse_addable = entity.main_purse().with_access_rights(AccessRights::ADD); - Ok(NewTransferTargetMode::ExistingAccount { + Ok(TransferTargetMode::ExistingAccount { target_account_hash: account_hash, main_purse: main_purse_addable, }) } - Err(_) => Ok(NewTransferTargetMode::CreateAccount(account_hash)), + Err(_) => Ok(TransferTargetMode::CreateAccount(account_hash)), } } @@ -428,15 +416,15 @@ impl TransferRuntimeArgsBuilder { let (to, target) = match self .resolve_transfer_target_mode(protocol_version, Rc::clone(&tracking_copy))? { - NewTransferTargetMode::ExistingAccount { + TransferTargetMode::ExistingAccount { main_purse: purse_uref, target_account_hash: target_account, } => (Some(target_account), purse_uref), - NewTransferTargetMode::PurseExists { + TransferTargetMode::PurseExists { target_account_hash, purse_uref, } => (target_account_hash, purse_uref), - NewTransferTargetMode::CreateAccount(_) => { + TransferTargetMode::CreateAccount(_) => { // Method "build()" is called after `resolve_transfer_target_mode` is first called // and handled by creating a new account. Calling `resolve_transfer_target_mode` // for the second time should never return `CreateAccount` variant.