runtime.rs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /* This file is part of DarkFi (https://dark.fi)
  2. *
  3. * Copyright (C) 2020-2024 Dyne.org foundation
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU Affero General Public License as
  7. * published by the Free Software Foundation, either version 3 of the
  8. * License, or (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU Affero General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Affero General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18. use darkfi::{
  19. blockchain::{Blockchain, BlockchainOverlay},
  20. runtime::vm_runtime::Runtime,
  21. util::time::{TimeKeeper, Timestamp},
  22. };
  23. use darkfi_sdk::{crypto::ContractId, pasta::pallas};
  24. fn init_logger() {
  25. let mut cfg = simplelog::ConfigBuilder::new();
  26. cfg.add_filter_ignore("sled".to_string());
  27. simplelog::TermLogger::init(
  28. simplelog::LevelFilter::Debug,
  29. cfg.build(),
  30. simplelog::TerminalMode::Mixed,
  31. simplelog::ColorChoice::Auto,
  32. )
  33. .unwrap();
  34. }
  35. fn main() {
  36. init_logger();
  37. let sled_db = sled::Config::new().temporary(true).open().unwrap();
  38. let blockchain = Blockchain::new(&sled_db).unwrap();
  39. let overlay = BlockchainOverlay::new(&blockchain).unwrap();
  40. let timekeeper = TimeKeeper::new(Timestamp::current_time(), 10, 90, 0);
  41. let wasm_bytes =
  42. include_bytes!("../target/wasm32-unknown-unknown/release/darkfi_dummy_contract.wasm");
  43. let contract_id = ContractId::from(pallas::Base::from(69));
  44. let mut runtime = Runtime::new(wasm_bytes, overlay, contract_id, timekeeper).unwrap();
  45. match runtime.deploy(&[]) {
  46. Ok(()) => {}
  47. Err(e) => println!("Error running deploy: {:#?}", e),
  48. }
  49. match runtime.exec(&[]) {
  50. Ok(_) => {}
  51. Err(e) => println!("Error running exec: {:#?}", e),
  52. }
  53. }