internal.rs 822 B

1234567891011121314151617181920212223
  1. use darkfi::{
  2. consensus::ValidatorState,
  3. node::{state::StateUpdate, MemoryState},
  4. tx::Transaction,
  5. Result,
  6. };
  7. use super::Darkfid;
  8. impl Darkfid {
  9. /// Apply a new `MemoryState` from the current validator state and simulate a state
  10. /// transition with the given `Transaction`. Returns a vec of `StateUpdate` on success.
  11. pub async fn simulate_transaction(&self, tx: &Transaction) -> Result<Vec<StateUpdate>> {
  12. // Grab the current state and apply a new MemoryState
  13. let validator_state = self.validator_state.read().await;
  14. let state = validator_state.state_machine.lock().await;
  15. let mem_state = MemoryState::new(state.clone());
  16. drop(state);
  17. drop(validator_state);
  18. ValidatorState::validate_state_transitions(mem_state, &[tx.clone()])
  19. }
  20. }