chik_sdk_bindings/
simulator.rs1use std::sync::{Arc, Mutex};
2
3use binky::Result;
4use chik_bls::SecretKey;
5use chik_protocol::{Bytes32, Coin, CoinSpend};
6
7use crate::BlsPairWithCoin;
8
9#[derive(Default, Clone)]
10pub struct Simulator(Arc<Mutex<chik_sdk_test::Simulator>>);
11
12impl Simulator {
13 pub fn new() -> Result<Self> {
14 Ok(Self::default())
15 }
16
17 pub fn new_coin(&self, puzzle_hash: Bytes32, amount: u64) -> Result<Coin> {
18 Ok(self.0.lock().unwrap().new_coin(puzzle_hash, amount))
19 }
20
21 pub fn bls(&self, amount: u64) -> Result<BlsPairWithCoin> {
22 Ok(self.0.lock().unwrap().bls(amount).into())
23 }
24
25 pub fn spend_coins(
26 &self,
27 coin_spends: Vec<CoinSpend>,
28 secret_keys: Vec<SecretKey>,
29 ) -> Result<()> {
30 self.0
31 .lock()
32 .unwrap()
33 .spend_coins(coin_spends, &secret_keys)?;
34 Ok(())
35 }
36
37 pub fn pass_time(&self, time: u64) -> Result<()> {
38 self.0.lock().unwrap().pass_time(time);
39 Ok(())
40 }
41}