Skip to content

Commit

Permalink
[framework] Introduce rooch-nursery (rooch-network#1656)
Browse files Browse the repository at this point in the history
  • Loading branch information
jolestar authored May 8, 2024
1 parent 38a1c32 commit 4197fce
Show file tree
Hide file tree
Showing 51 changed files with 675 additions and 602 deletions.
4 changes: 2 additions & 2 deletions crates/rooch-executor/src/actor/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use rooch_types::address::MultiChainAddress;
use rooch_types::bitcoin::BitcoinModule;
use rooch_types::framework::address_mapping::AddressMappingModule;
use rooch_types::framework::auth_validator::{AuthValidatorCaller, TxValidateResult};
use rooch_types::framework::ethereum_light_client::EthereumLightClientModule;
use rooch_types::framework::ethereum::EthereumModule;
use rooch_types::framework::transaction_validator::TransactionValidator;
use rooch_types::framework::{system_post_execute_functions, system_pre_execute_functions};
use rooch_types::multichain_id::RoochMultiChainID;
Expand Down Expand Up @@ -145,7 +145,7 @@ impl ExecutorActor {
}
RoochMultiChainID::Ether => {
let action = VerifiedMoveAction::Function {
call: EthereumLightClientModule::create_submit_new_block_call_bytes(block_body),
call: EthereumModule::create_submit_new_block_call_bytes(block_body),
bypass_visibility: true,
};
Ok(VerifiedMoveOSTransaction::new(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use moveos_types::module_binding::MoveFunctionCaller;
use moveos_types::transaction::MoveAction;
use rooch_key::keystore::account_keystore::AccountKeystore;
use rooch_key::keystore::memory_keystore::InMemKeystore;
use rooch_types::framework::ethereum_light_client::BlockHeader;
use rooch_types::framework::ethereum::BlockHeader;
use rooch_types::transaction::rooch::RoochTransactionData;

#[test]
Expand Down Expand Up @@ -53,7 +53,11 @@ fn test_submit_block() {
let ethereum_block: Block<()> = serde_json::from_value(json).unwrap();

let block_header = BlockHeader::try_from(&ethereum_block).unwrap();
let action = MoveAction::Function(rooch_types::framework::ethereum_light_client::EthereumLightClientModule::create_submit_new_block_call(&block_header));
let action = MoveAction::Function(
rooch_types::framework::ethereum::EthereumModule::create_submit_new_block_call(
&block_header,
),
);
let tx_data = RoochTransactionData::new_for_test(sender, sequence_number, action);
let tx = keystore.sign_transaction(&sender, tx_data, None).unwrap();
binding_test.execute(tx).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion crates/rooch-framework-tests/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ mod bitcoin_test;
mod brc20_test;
mod chain_id_test;
mod empty_tests;
mod ethereum_light_client_test;
mod ethereum_test;
mod native_validator_tests;
mod ord_test;
mod transaction_validator_tests;
29 changes: 29 additions & 0 deletions crates/rooch-genesis-builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,21 @@ use framework_builder::{Stdlib, StdlibBuildConfig};
use move_package::BuildConfig;
use once_cell::sync::Lazy;

pub const ALL_STDLIB_PACKAGE_NAMES: [&str; 5] = [
"MoveStdlib",
"MoveosStdlib",
"RoochFramework",
"BitcoinMove",
"RoochNursery",
];

pub const ALL_STDLIB_PACKAGE_NAMES_STABLE: [&str; 4] = [
"MoveStdlib",
"MoveosStdlib",
"RoochFramework",
"BitcoinMove",
];

static STDLIB_BUILD_CONFIGS: Lazy<Vec<StdlibBuildConfig>> = Lazy::new(|| {
let move_stdlib_path = path_in_crate("../../frameworks/move-stdlib")
.canonicalize()
Expand All @@ -22,6 +37,11 @@ static STDLIB_BUILD_CONFIGS: Lazy<Vec<StdlibBuildConfig>> = Lazy::new(|| {
let bitcoin_move_path = path_in_crate("../../frameworks/bitcoin-move")
.canonicalize()
.expect("canonicalize path failed");

let rooch_nursery_path = path_in_crate("../../frameworks/rooch-nursery")
.canonicalize()
.expect("canonicalize path failed");

let generated_dir = generated_dir();

vec![
Expand Down Expand Up @@ -58,6 +78,15 @@ static STDLIB_BUILD_CONFIGS: Lazy<Vec<StdlibBuildConfig>> = Lazy::new(|| {
document_output_directory: bitcoin_move_path.join("doc"),
build_config: BuildConfig::default(),
},
StdlibBuildConfig {
path: rooch_nursery_path.clone(),
error_prefix: "Error".to_string(),
error_code_map_output_file: generated_dir
.join("rooch_nursery_error_description.errmap"),
document_template: rooch_nursery_path.join("doc_template/README.md"),
document_output_directory: rooch_nursery_path.join("doc"),
build_config: BuildConfig::default(),
},
]
});

Expand Down
11 changes: 10 additions & 1 deletion crates/rooch-genesis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use rooch_framework::natives::gas_parameter::gas_member::{
FromOnChainGasSchedule, InitialGasSchedule, ToOnChainGasSchedule,
};
use rooch_framework::ROOCH_FRAMEWORK_ADDRESS;
use rooch_genesis_builder::{ALL_STDLIB_PACKAGE_NAMES, ALL_STDLIB_PACKAGE_NAMES_STABLE};
use rooch_types::bitcoin::genesis::BitcoinGenesisContext;
use rooch_types::bitcoin::network::Network;
use rooch_types::error::GenesisError;
Expand Down Expand Up @@ -151,8 +152,16 @@ impl RoochGenesis {
BuildOption::Fresh => Self::build_stdlib()?,
BuildOption::Release => Self::load_stdlib()?,
};
//TODO put the stdlib package names to RoochChainID
let stdlib_package_names = if genesis_ctx.chain_id == RoochChainID::LOCAL.chain_id().id()
|| genesis_ctx.chain_id == RoochChainID::DEV.chain_id().id()
{
ALL_STDLIB_PACKAGE_NAMES.to_vec()
} else {
ALL_STDLIB_PACKAGE_NAMES_STABLE.to_vec()
};

let bundles = stdlib.module_bundles()?;
let bundles = stdlib.module_bundles(stdlib_package_names.as_slice())?;

let genesis_tx = RoochTransaction::new_genesis_tx(
ROOCH_FRAMEWORK_ADDRESS.into(),
Expand Down
2 changes: 1 addition & 1 deletion crates/rooch-relayer/src/actor/ethereum_relayer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use async_trait::async_trait;
use ethers::prelude::*;
use rooch_config::EthereumRelayerConfig;
use rooch_types::{
framework::ethereum_light_client::BlockHeader,
framework::ethereum::BlockHeader,
multichain_id::RoochMultiChainID,
transaction::{L1Block, L1BlockWithBody},
};
Expand Down
11 changes: 10 additions & 1 deletion crates/rooch-types/src/addresses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,21 @@ pub const BITCOIN_MOVE_ADDRESS: AccountAddress = {
AccountAddress::new(addr)
};

pub static ROOCH_NAMED_ADDRESS_MAPPING: [(&str, &str); 2] = [
pub const ROOCH_NURSERY_ADDRESS_NAME: &str = "rooch_nursery";
pub const ROOCH_NURSERY_ADDRESS_LITERAL: &str = "0xa";
pub const ROOCH_NURSERY_ADDRESS: AccountAddress = {
let mut addr = [0u8; AccountAddress::LENGTH];
addr[AccountAddress::LENGTH - 1] = 10u8;
AccountAddress::new(addr)
};

pub static ROOCH_NAMED_ADDRESS_MAPPING: [(&str, &str); 3] = [
(
ROOCH_FRAMEWORK_ADDRESS_NAME,
ROOCH_FRAMEWORK_ADDRESS_LITERAL,
),
(BITCOIN_MOVE_ADDRESS_NAME, BITCOIN_MOVE_ADDRESS_LITERAL),
(ROOCH_NURSERY_ADDRESS_NAME, ROOCH_NURSERY_ADDRESS_LITERAL),
];

pub fn rooch_framework_named_addresses() -> BTreeMap<String, AccountAddress> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) RoochNetwork
// SPDX-License-Identifier: Apache-2.0

use super::ethereum_address::ETHAddress;
use crate::addresses::ROOCH_NURSERY_ADDRESS;
use anyhow::Result;
use ethers::types::Block;
use move_core_types::{
Expand All @@ -10,19 +12,14 @@ use move_core_types::{
u256::{U256, U256_NUM_BYTES},
value::MoveValue,
};
use serde::{Deserialize, Serialize};

use moveos_types::{
module_binding::{ModuleBinding, MoveFunctionCaller},
moveos_std::tx_context::TxContext,
transaction::FunctionCall,
};
use serde::{Deserialize, Serialize};

use crate::addresses::ROOCH_FRAMEWORK_ADDRESS;

use super::ethereum_address::ETHAddress;

pub const MODULE_NAME: &IdentStr = ident_str!("ethereum_light_client");
pub const MODULE_NAME: &IdentStr = ident_str!("ethereum");

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BlockHeader {
Expand Down Expand Up @@ -97,11 +94,11 @@ impl<T> TryFrom<&Block<T>> for BlockHeader {
}

/// Rust bindings for RoochFramework ethereum_light_client module
pub struct EthereumLightClientModule<'a> {
pub struct EthereumModule<'a> {
caller: &'a dyn MoveFunctionCaller,
}

impl<'a> EthereumLightClientModule<'a> {
impl<'a> EthereumModule<'a> {
pub const GET_BLOCK_FUNCTION_NAME: &'static IdentStr = ident_str!("get_block");
pub const SUBMIT_NEW_BLOCK_ENTRY_FUNCTION_NAME: &'static IdentStr =
ident_str!("submit_new_block");
Expand Down Expand Up @@ -144,9 +141,9 @@ impl<'a> EthereumLightClientModule<'a> {
}
}

impl<'a> ModuleBinding<'a> for EthereumLightClientModule<'a> {
impl<'a> ModuleBinding<'a> for EthereumModule<'a> {
const MODULE_NAME: &'static IdentStr = MODULE_NAME;
const MODULE_ADDRESS: AccountAddress = ROOCH_FRAMEWORK_ADDRESS;
const MODULE_ADDRESS: AccountAddress = ROOCH_NURSERY_ADDRESS;

fn new(caller: &'a impl MoveFunctionCaller) -> Self
where
Expand Down
2 changes: 1 addition & 1 deletion crates/rooch-types/src/framework/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ pub mod chain_id;
pub mod coin;
pub mod coin_store;
pub mod empty;
pub mod ethereum;
pub mod ethereum_address;
pub mod ethereum_light_client;
pub mod ethereum_validator;
pub mod gas_coin;
pub mod genesis;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl CommandAction<ExecuteTransactionResponseView> for FrameworkUpgrade {

let stdlib = Stdlib::load_from_file(package_path)?;
let bundles_map: HashMap<_, _> = stdlib
.module_bundles()
.all_module_bundles()
.expect("get bundles failed")
.into_iter()
.collect();
Expand Down
2 changes: 2 additions & 0 deletions examples/bitseed_runner/Move.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ version = "0.0.1"
[dependencies]
MoveosStdlib = { local = "../../frameworks/moveos-stdlib" }
BitcoinMove = { local = "../../frameworks/bitcoin-move" }
RoochNursery = { local = "../../frameworks/rooch-nursery" }

[addresses]
rooch_examples = "_"
moveos_std = "0x2"
rooch_framework = "0x3"
bitcoin_move = "0x4"
rooch_nursery = "0xa"

[dev-addresses]
rooch_examples = "0x42"
4 changes: 2 additions & 2 deletions examples/bitseed_runner/sources/bitseed.move
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ module rooch_examples::bitseed_runner {
use moveos_std::string_utils::parse_u64;
use moveos_std::simple_map::{Self, SimpleMap};
use moveos_std::json;
use bitcoin_move::bitseed;
use bitcoin_move::bitseed::{MintOp, DeployOp};
use rooch_nursery::bitseed;
use rooch_nursery::bitseed::{MintOp, DeployOp};
use bitcoin_move::ord::{InscriptionID, Inscription};
use bitcoin_move::ord;
use moveos_std::object;
Expand Down
2 changes: 2 additions & 0 deletions examples/wasm_execution/Move.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ version = "0.0.1"
[dependencies]
MoveosStdlib = { local = "../../frameworks/moveos-stdlib" }
BitcoinMove = { local = "../../frameworks/bitcoin-move" }
RoochNursery = { local = "../../frameworks/rooch-nursery" }

[addresses]
rooch_examples = "_"
moveos_std = "0x2"
rooch_framework = "0x3"
bitcoin_move = "0x4"
rooch_nursery = "0xa"

[dev-addresses]
rooch_examples = "0x42"
Loading

0 comments on commit 4197fce

Please sign in to comment.