diff --git a/example/dummy-contract/.gitignore b/example/dummy-contract/.gitignore deleted file mode 100644 index 2c96eb1b6..000000000 --- a/example/dummy-contract/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -target/ -Cargo.lock diff --git a/example/dummy-contract/Cargo.toml b/example/dummy-contract/Cargo.toml deleted file mode 100644 index 9b60c9e6a..000000000 --- a/example/dummy-contract/Cargo.toml +++ /dev/null @@ -1,36 +0,0 @@ -[package] -name = "darkfi_dummy_contract" -version = "0.4.1" -authors = ["Dyne.org foundation "] -license = "AGPL-3.0-only" -edition = "2021" - -[workspace] - -[lib] -crate-type = ["cdylib", "rlib"] - -[dependencies] -darkfi-sdk = {path = "../../src/sdk"} - -# We need to disable random using "custom" which makes the crate a noop -# so the wasm32-unknown-unknown target is enabled. -[target.'cfg(target_arch = "wasm32")'.dependencies] -getrandom = { version = "0.2.8", features = ["custom"] } - -[dev-dependencies] -sled = "0.34.7" -darkfi = {path = "../../", features = ["wasm-runtime"]} -simplelog = "0.12.2" - -[[example]] -name = "runtime" -path = "src/runtime.rs" - -[features] -default = [] -no-entrypoint = [] - -[patch.crates-io] -halo2_proofs = {git="https://github.com/parazyd/halo2", branch="v4"} -halo2_gadgets = {git="https://github.com/parazyd/halo2", branch="v4"} diff --git a/example/dummy-contract/README.md b/example/dummy-contract/README.md deleted file mode 100644 index f1b8cdd96..000000000 --- a/example/dummy-contract/README.md +++ /dev/null @@ -1,11 +0,0 @@ -# Build WASM - -``` -$ cargo +nightly build --target=wasm32-unknown-unknown --release --package darkfi_dummy_contract -``` - -# Run runtime.rs - -``` -$ cargo +nightly run --target=x86_64-unknown-linux-gnu --release --example runtime -``` diff --git a/example/dummy-contract/src/entrypoint.rs b/example/dummy-contract/src/entrypoint.rs deleted file mode 100644 index 69b7533ae..000000000 --- a/example/dummy-contract/src/entrypoint.rs +++ /dev/null @@ -1,53 +0,0 @@ -/* This file is part of DarkFi (https://dark.fi) - * - * Copyright (C) 2020-2024 Dyne.org foundation - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -use darkfi_sdk::{ - crypto::ContractId, - db::{db_init, db_lookup}, - error::ContractResult, -}; - -darkfi_sdk::define_contract!( - init: init_contract, - exec: process_instruction, - apply: process_update, - metadata: get_metadata -); - -fn init_contract(cid: ContractId, _ix: &[u8]) -> ContractResult { - let db = match db_lookup(cid, "dummy_db") { - Ok(v) => v, - Err(_) => db_init(cid, "dummy_db")?, - }; - - Ok(()) -} - -fn get_metadata(_cid: ContractId, _ix: &[u8]) -> ContractResult { - Ok(()) -} - -fn process_instruction(cid: ContractId, _ix: &[u8]) -> ContractResult { - let db = db_lookup(cid, "dummy_db")?; - - Ok(()) -} - -fn process_update(_cid: ContractId, _ix: &[u8]) -> ContractResult { - Ok(()) -} diff --git a/example/dummy-contract/src/lib.rs b/example/dummy-contract/src/lib.rs deleted file mode 100644 index 31c82387b..000000000 --- a/example/dummy-contract/src/lib.rs +++ /dev/null @@ -1,21 +0,0 @@ -/* This file is part of DarkFi (https://dark.fi) - * - * Copyright (C) 2020-2024 Dyne.org foundation - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#[cfg(not(feature = "no-entrypoint"))] -/// WASM entrypoint functions -pub mod entrypoint; diff --git a/example/dummy-contract/src/runtime.rs b/example/dummy-contract/src/runtime.rs deleted file mode 100644 index d7c60c7e7..000000000 --- a/example/dummy-contract/src/runtime.rs +++ /dev/null @@ -1,63 +0,0 @@ -/* This file is part of DarkFi (https://dark.fi) - * - * Copyright (C) 2020-2024 Dyne.org foundation - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -use darkfi::{ - blockchain::{Blockchain, BlockchainOverlay}, - runtime::vm_runtime::Runtime, - util::time::{TimeKeeper, Timestamp}, -}; -use darkfi_sdk::{crypto::ContractId, pasta::pallas}; - -fn init_logger() { - let mut cfg = simplelog::ConfigBuilder::new(); - cfg.add_filter_ignore("sled".to_string()); - - simplelog::TermLogger::init( - simplelog::LevelFilter::Debug, - cfg.build(), - simplelog::TerminalMode::Mixed, - simplelog::ColorChoice::Auto, - ) - .unwrap(); -} - -fn main() { - init_logger(); - - let sled_db = sled::Config::new().temporary(true).open().unwrap(); - let blockchain = Blockchain::new(&sled_db).unwrap(); - let overlay = BlockchainOverlay::new(&blockchain).unwrap(); - - let timekeeper = TimeKeeper::new(Timestamp::current_time(), 10, 90, 0); - - let wasm_bytes = - include_bytes!("../target/wasm32-unknown-unknown/release/darkfi_dummy_contract.wasm"); - - let contract_id = ContractId::from(pallas::Base::from(69)); - - let mut runtime = Runtime::new(wasm_bytes, overlay, contract_id, timekeeper).unwrap(); - match runtime.deploy(&[]) { - Ok(()) => {} - Err(e) => println!("Error running deploy: {:#?}", e), - } - - match runtime.exec(&[]) { - Ok(_) => {} - Err(e) => println!("Error running exec: {:#?}", e), - } -} diff --git a/example/net.rs b/example/net.rs deleted file mode 100644 index 3707bf940..000000000 --- a/example/net.rs +++ /dev/null @@ -1,116 +0,0 @@ -/* This file is part of DarkFi (https://dark.fi) - * - * Copyright (C) 2020-2024 Dyne.org foundation - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -use std::sync::Arc; - -use clap::Parser; -use simplelog::*; -use smol::Executor; - -use darkfi::{ - net, - util::cli::{get_log_config, get_log_level}, - Result, -}; - -async fn start(executor: Arc>, options: ProgramOptions) -> Result<()> { - let p2p = net::P2p::new(options.network_settings, executor.clone()).await; - - p2p.clone().start().await?; - - Ok(()) -} - -struct ProgramOptions { - network_settings: net::Settings, -} - -#[derive(Parser)] -#[clap(name = "dnode")] -pub struct DarkCli { - /// accept address - #[clap(short, long)] - pub accept: Option, - /// seed nodes - #[clap(long, short)] - pub seeds: Option>, - /// manual connections - #[clap(short, short)] - pub connect: Option>, - /// connections slots - #[clap(long)] - pub connect_slots: Option, - /// RPC port - #[clap(long)] - pub rpc_port: Option, -} - -impl ProgramOptions { - fn load() -> Result { - let programcli = DarkCli::parse(); - - let accept_addr = if let Some(accept_addr) = programcli.accept { - vec![accept_addr.parse()?] - } else { - vec![] - }; - - let mut seed_addrs: Vec = vec![]; - if let Some(seeds) = programcli.seeds { - for seed in seeds { - seed_addrs.push(seed.parse()?); - } - } - - let mut manual_connects: Vec = vec![]; - if let Some(connections) = programcli.connect { - for connect in connections { - manual_connects.push(connect.parse()?); - } - } - - let connection_slots = if let Some(connection_slots) = programcli.connect_slots { - connection_slots - } else { - 0 - }; - - Ok(ProgramOptions { - network_settings: net::Settings { - inbound_addrs: accept_addr.clone(), - outbound_connections: connection_slots, - external_addrs: accept_addr, - peers: manual_connects, - seeds: seed_addrs, - ..Default::default() - }, - }) - } -} - -fn main() -> Result<()> { - let options = ProgramOptions::load()?; - - let lvl = get_log_level(1); - let conf = get_log_config(1); - - TermLogger::init(lvl, conf, TerminalMode::Mixed, ColorChoice::Auto)?; - - let ex = Arc::new(Executor::new()); - smol::block_on(ex.run(start(ex.clone(), options))) -}