From d7f69449af0c5fb6552e5a9e69798b2940670020 Mon Sep 17 00:00:00 2001 From: Omar Abdulla Date: Wed, 17 Sep 2025 21:06:29 +0300 Subject: [PATCH] Add all of the platforms that we support --- crates/common/src/types/identifiers.rs | 4 +- crates/core/src/lib.rs | 263 ++++++++++++++++++++++++- 2 files changed, 264 insertions(+), 3 deletions(-) diff --git a/crates/common/src/types/identifiers.rs b/crates/common/src/types/identifiers.rs index a43e3e0..bc901e7 100644 --- a/crates/common/src/types/identifiers.rs +++ b/crates/common/src/types/identifiers.rs @@ -28,11 +28,11 @@ pub enum PlatformIdentifier { /// The kitchensink node with the PolkaVM backend with the resolc compiler. KitchensinkPolkavmResolc, /// The kitchensink node with the REVM backend with the solc compiler. - KitchensinkREVMSolc, + KitchensinkRevmSolc, /// The revive dev node with the PolkaVM backend with the resolc compiler. ReviveDevNodePolkavmResolc, /// The revive dev node with the REVM backend with the solc compiler. - ReviveDevNodeREVMSolc, + ReviveDevNodeRevmSolc, } /// An enum of the platform identifiers of all of the platforms supported by this framework. diff --git a/crates/core/src/lib.rs b/crates/core/src/lib.rs index 915a461..8bdb91b 100644 --- a/crates/core/src/lib.rs +++ b/crates/core/src/lib.rs @@ -12,7 +12,8 @@ use alloy::genesis::Genesis; use anyhow::Context as _; use revive_dt_common::types::*; use revive_dt_compiler::{ - DynSolidityCompiler, SolidityCompiler, revive_resolc, + DynSolidityCompiler, SolidityCompiler, + revive_resolc::{self, Resolc}, solc::{self, Solc}, }; use revive_dt_config::*; @@ -174,6 +175,266 @@ impl DynPlatform for GethEvmPlatform { } } +pub struct KitchensinkPolkavmResolc; + +impl DynPlatform for KitchensinkPolkavmResolc { + fn platform_identifier(&self) -> PlatformIdentifier { + PlatformIdentifier::KitchensinkPolkavmResolc + } + + fn node_identifier(&self) -> NodeIdentifier { + NodeIdentifier::Kitchensink + } + + fn vm_identifier(&self) -> VmIdentifier { + VmIdentifier::Polkavm + } + + fn compiler_identifier(&self) -> CompilerIdentifier { + CompilerIdentifier::Resolc + } + + fn new_node( + &self, + context: impl AsRef + + AsRef + + AsRef + + AsRef + + AsRef + + AsRef + + AsRef + + AsRef + + Send + + Sync + + Clone + + 'static, + ) -> anyhow::Result>>> { + let genesis_configuration = AsRef::::as_ref(&context); + let kitchensink_path = AsRef::::as_ref(&context) + .path + .clone(); + let genesis = genesis_configuration.genesis()?.clone(); + Ok(thread::spawn(move || { + let node = SubstrateNode::new( + kitchensink_path, + SubstrateNode::KITCHENSINK_EXPORT_CHAINSPEC_COMMAND, + context, + ); + let node = spawn_node(node, genesis)?; + Ok(Box::new(node) as Box<_>) + })) + } + + fn new_compiler<'a>( + &self, + context: impl AsRef + + AsRef + + AsRef + + 'a, + version: impl Into> + 'a, + ) -> Pin>> + 'a>> { + Box::pin(async move { + let compiler = Resolc::new(context, version).await; + compiler.map(|compiler| Box::new(compiler) as Box) + }) + } +} + +pub struct KitchensinkRevmSolc; + +impl DynPlatform for KitchensinkRevmSolc { + fn platform_identifier(&self) -> PlatformIdentifier { + PlatformIdentifier::KitchensinkRevmSolc + } + + fn node_identifier(&self) -> NodeIdentifier { + NodeIdentifier::Kitchensink + } + + fn vm_identifier(&self) -> VmIdentifier { + VmIdentifier::Evm + } + + fn compiler_identifier(&self) -> CompilerIdentifier { + CompilerIdentifier::Solc + } + + fn new_node( + &self, + context: impl AsRef + + AsRef + + AsRef + + AsRef + + AsRef + + AsRef + + AsRef + + AsRef + + Send + + Sync + + Clone + + 'static, + ) -> anyhow::Result>>> { + let genesis_configuration = AsRef::::as_ref(&context); + let kitchensink_path = AsRef::::as_ref(&context) + .path + .clone(); + let genesis = genesis_configuration.genesis()?.clone(); + Ok(thread::spawn(move || { + let node = SubstrateNode::new( + kitchensink_path, + SubstrateNode::KITCHENSINK_EXPORT_CHAINSPEC_COMMAND, + context, + ); + let node = spawn_node(node, genesis)?; + Ok(Box::new(node) as Box<_>) + })) + } + + fn new_compiler<'a>( + &self, + context: impl AsRef + + AsRef + + AsRef + + 'a, + version: impl Into> + 'a, + ) -> Pin>> + 'a>> { + Box::pin(async move { + let compiler = Solc::new(context, version).await; + compiler.map(|compiler| Box::new(compiler) as Box) + }) + } +} + +pub struct ReviveDevNodePolkavmResolc; + +impl DynPlatform for ReviveDevNodePolkavmResolc { + fn platform_identifier(&self) -> PlatformIdentifier { + PlatformIdentifier::ReviveDevNodePolkavmResolc + } + + fn node_identifier(&self) -> NodeIdentifier { + NodeIdentifier::ReviveDevNode + } + + fn vm_identifier(&self) -> VmIdentifier { + VmIdentifier::Polkavm + } + + fn compiler_identifier(&self) -> CompilerIdentifier { + CompilerIdentifier::Resolc + } + + fn new_node( + &self, + context: impl AsRef + + AsRef + + AsRef + + AsRef + + AsRef + + AsRef + + AsRef + + AsRef + + Send + + Sync + + Clone + + 'static, + ) -> anyhow::Result>>> { + let genesis_configuration = AsRef::::as_ref(&context); + let revive_dev_node_path = AsRef::::as_ref(&context) + .path + .clone(); + let genesis = genesis_configuration.genesis()?.clone(); + Ok(thread::spawn(move || { + let node = SubstrateNode::new( + revive_dev_node_path, + SubstrateNode::REVIVE_DEV_NODE_EXPORT_CHAINSPEC_COMMAND, + context, + ); + let node = spawn_node(node, genesis)?; + Ok(Box::new(node) as Box<_>) + })) + } + + fn new_compiler<'a>( + &self, + context: impl AsRef + + AsRef + + AsRef + + 'a, + version: impl Into> + 'a, + ) -> Pin>> + 'a>> { + Box::pin(async move { + let compiler = Resolc::new(context, version).await; + compiler.map(|compiler| Box::new(compiler) as Box) + }) + } +} + +pub struct ReviveDevNodeRevmSolc; + +impl DynPlatform for ReviveDevNodeRevmSolc { + fn platform_identifier(&self) -> PlatformIdentifier { + PlatformIdentifier::ReviveDevNodeRevmSolc + } + + fn node_identifier(&self) -> NodeIdentifier { + NodeIdentifier::ReviveDevNode + } + + fn vm_identifier(&self) -> VmIdentifier { + VmIdentifier::Evm + } + + fn compiler_identifier(&self) -> CompilerIdentifier { + CompilerIdentifier::Solc + } + + fn new_node( + &self, + context: impl AsRef + + AsRef + + AsRef + + AsRef + + AsRef + + AsRef + + AsRef + + AsRef + + Send + + Sync + + Clone + + 'static, + ) -> anyhow::Result>>> { + let genesis_configuration = AsRef::::as_ref(&context); + let revive_dev_node_path = AsRef::::as_ref(&context) + .path + .clone(); + let genesis = genesis_configuration.genesis()?.clone(); + Ok(thread::spawn(move || { + let node = SubstrateNode::new( + revive_dev_node_path, + SubstrateNode::REVIVE_DEV_NODE_EXPORT_CHAINSPEC_COMMAND, + context, + ); + let node = spawn_node(node, genesis)?; + Ok(Box::new(node) as Box<_>) + })) + } + + fn new_compiler<'a>( + &self, + context: impl AsRef + + AsRef + + AsRef + + 'a, + version: impl Into> + 'a, + ) -> Pin>> + 'a>> { + Box::pin(async move { + let compiler = Solc::new(context, version).await; + compiler.map(|compiler| Box::new(compiler) as Box) + }) + } +} + fn spawn_node( mut node: T, genesis: Genesis,