mod.rs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. use crate::{
  2. storage::{sqlite::SQLite, Storage},
  3. AccountId, Amount, Error, Ledger, RevId, Status,
  4. };
  5. use sqlx::sqlite::SqlitePoolOptions;
  6. use std::sync::Arc;
  7. #[allow(unused)]
  8. pub async fn get_file_asset_manager_and_ledger<'a>(name: &str) -> Arc<Ledger<SQLite>> {
  9. let pool = SqlitePoolOptions::new()
  10. .max_connections(1)
  11. .idle_timeout(None)
  12. .max_lifetime(None)
  13. .connect(format!("sqlite:///tmp/{}.db", name).as_str())
  14. .await
  15. .expect("pool");
  16. let db = SQLite::new(pool);
  17. db.setup().await.expect("setup");
  18. Ledger::new(db.into())
  19. }
  20. pub async fn get_asset_manager_and_ledger() -> Arc<Ledger<SQLite>> {
  21. let pool = SqlitePoolOptions::new()
  22. .max_connections(1)
  23. .idle_timeout(None)
  24. .max_lifetime(None)
  25. .connect(":memory:")
  26. .await
  27. .expect("pool");
  28. let db = SQLite::new(pool);
  29. db.setup().await.expect("setup");
  30. Ledger::new(db.into())
  31. }
  32. pub async fn withdrawal(
  33. ledger: &Ledger<SQLite>,
  34. account_id: &AccountId,
  35. status: Status,
  36. amount: Amount,
  37. ) -> Result<RevId, Error> {
  38. Ok(ledger
  39. .withdrawal(account_id, amount, status, "Test".to_owned())
  40. .await?
  41. .revision_id
  42. .clone())
  43. }
  44. pub async fn deposit<S>(ledger: &Ledger<S>, account_id: &AccountId, amount: Amount) -> RevId
  45. where
  46. S: Storage + Send + Sync,
  47. {
  48. ledger
  49. .deposit(
  50. account_id,
  51. amount,
  52. "settled".into(),
  53. vec![],
  54. "Test".to_owned(),
  55. )
  56. .await
  57. .expect("valid tx")
  58. .revision_id
  59. .clone()
  60. }
  61. mod deposit;
  62. mod negative_deposit;
  63. mod tx;
  64. mod withdrawal;