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

Expand Deploy Acceptor #2081

Merged
merged 11 commits into from
Sep 22, 2021
142 changes: 142 additions & 0 deletions execution_engine/src/core/engine_state/executable_deploy_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,50 @@ const STORED_VERSIONED_CONTRACT_BY_HASH_TAG: u8 = 3;
const STORED_VERSIONED_CONTRACT_BY_NAME_TAG: u8 = 4;
const TRANSFER_TAG: u8 = 5;

/// Possible ways to identify the `ExecutableDeployItem`.
#[derive(
Clone, DataSize, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize, JsonSchema,
)]
pub enum ExecutableDeployItemIdentifier {
Module,
Contract(ContractIdentifier),
Package(ContractPackageIdentifier),
Transfer,
}

/// Possible ways to identify the contract object within an `ExecutableDeployItem`.
#[derive(
Clone, DataSize, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize, JsonSchema,
)]
pub enum ContractIdentifier {
Name(String),
Hash(ContractHash),
}

/// Possible ways to identify the contract package object within an `ExecutableDeployItem`.
#[derive(
Clone, DataSize, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize, JsonSchema,
)]
pub enum ContractPackageIdentifier {
Name {
name: String,
version: Option<ContractVersion>,
},
Hash {
contract_package_hash: ContractPackageHash,
version: Option<ContractVersion>,
},
}

impl ContractPackageIdentifier {
pub fn version(&self) -> Option<ContractVersion> {
match self {
ContractPackageIdentifier::Name { version, .. } => *version,
ContractPackageIdentifier::Hash { version, .. } => *version,
}
}
}

#[derive(
Clone, DataSize, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize, JsonSchema,
)]
Expand Down Expand Up @@ -102,6 +146,69 @@ impl ExecutableDeployItem {
}
}

pub fn identifier(&self) -> ExecutableDeployItemIdentifier {
match self {
ExecutableDeployItem::ModuleBytes { .. } => ExecutableDeployItemIdentifier::Module,
ExecutableDeployItem::StoredContractByHash { hash, .. } => {
ExecutableDeployItemIdentifier::Contract(ContractIdentifier::Hash(*hash))
}
ExecutableDeployItem::StoredContractByName { name, .. } => {
ExecutableDeployItemIdentifier::Contract(ContractIdentifier::Name(name.to_string()))
}
ExecutableDeployItem::StoredVersionedContractByHash { hash, version, .. } => {
ExecutableDeployItemIdentifier::Package(ContractPackageIdentifier::Hash {
contract_package_hash: *hash,
version: *version,
})
}
ExecutableDeployItem::StoredVersionedContractByName { name, version, .. } => {
ExecutableDeployItemIdentifier::Package(ContractPackageIdentifier::Name {
name: name.to_string(),
version: *version,
})
}
ExecutableDeployItem::Transfer { .. } => ExecutableDeployItemIdentifier::Transfer,
}
}

pub fn contract_identifier(&self) -> Option<ContractIdentifier> {
match self {
ExecutableDeployItem::ModuleBytes { .. }
| ExecutableDeployItem::StoredVersionedContractByHash { .. }
| ExecutableDeployItem::StoredVersionedContractByName { .. }
| ExecutableDeployItem::Transfer { .. } => None,

ExecutableDeployItem::StoredContractByName { name, .. } => {
Some(ContractIdentifier::Name(name.to_string()))
}
ExecutableDeployItem::StoredContractByHash { hash, .. } => {
Some(ContractIdentifier::Hash(*hash))
}
}
}

pub fn contract_package_identifier(&self) -> Option<ContractPackageIdentifier> {
match self {
ExecutableDeployItem::ModuleBytes { .. }
| ExecutableDeployItem::StoredContractByHash { .. }
| ExecutableDeployItem::StoredContractByName { .. }
| ExecutableDeployItem::Transfer { .. } => None,

ExecutableDeployItem::StoredVersionedContractByName { name, version, .. } => {
Some(ContractPackageIdentifier::Name {
name: name.clone(),
version: *version,
})
}
ExecutableDeployItem::StoredVersionedContractByHash { hash, version, .. } => {
Some(ContractPackageIdentifier::Hash {
contract_package_hash: *hash,
version: *version,
})
}
}
}

pub fn args(&self) -> &RuntimeArgs {
match self {
ExecutableDeployItem::ModuleBytes { args, .. }
Expand All @@ -117,6 +224,41 @@ impl ExecutableDeployItem {
matches!(self, ExecutableDeployItem::Transfer { .. })
}

pub fn is_by_name(&self) -> bool {
matches!(
self,
ExecutableDeployItem::StoredVersionedContractByName { .. }
) || matches!(self, ExecutableDeployItem::StoredContractByName { .. })
}

pub fn by_name(&self) -> Option<String> {
match self {
ExecutableDeployItem::StoredContractByName { name, .. }
| ExecutableDeployItem::StoredVersionedContractByName { name, .. } => {
Some(name.clone())
}
ExecutableDeployItem::ModuleBytes { .. }
| ExecutableDeployItem::StoredContractByHash { .. }
| ExecutableDeployItem::StoredVersionedContractByHash { .. }
| ExecutableDeployItem::Transfer { .. } => None,
}
}

pub fn is_stored_contract(&self) -> bool {
matches!(self, ExecutableDeployItem::StoredContractByHash { .. })
|| matches!(self, ExecutableDeployItem::StoredContractByName { .. })
}

pub fn is_stored_contract_package(&self) -> bool {
matches!(
self,
ExecutableDeployItem::StoredVersionedContractByHash { .. }
) || matches!(
self,
ExecutableDeployItem::StoredVersionedContractByName { .. }
)
}

#[allow(clippy::too_many_arguments)]
pub fn get_deploy_metadata<R>(
&self,
Expand Down
2 changes: 1 addition & 1 deletion execution_engine/src/core/engine_state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub use self::{
engine_config::{EngineConfig, DEFAULT_MAX_QUERY_DEPTH},
era_validators::{GetEraValidatorsError, GetEraValidatorsRequest},
error::Error,
executable_deploy_item::ExecutableDeployItem,
executable_deploy_item::{ExecutableDeployItem, ExecutableDeployItemIdentifier},
execute_request::ExecuteRequest,
execution::Error as ExecError,
execution_result::{ExecutionResult, ExecutionResults, ForcedTransferResult},
Expand Down
Loading