adapter.rs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. use crate::wallet::WalletDB;
  2. use crate::Result;
  3. use log::*;
  4. use std::path::PathBuf;
  5. use std::sync::Arc;
  6. // Dummy adapter for now
  7. pub struct RpcAdapter {}
  8. impl RpcAdapter {
  9. pub fn new() -> Arc<Self> {
  10. Arc::new(Self {})
  11. }
  12. pub async fn key_gen() -> Result<()> {
  13. debug!(target: "adapter", "key_gen() [START]");
  14. let (public, private) = WalletDB::create_key().await;
  15. let path = WalletDB::path("wallet.db").expect("Failed to get path");
  16. WalletDB::save_key(path, public, private).await.expect("Failed to save key");
  17. Ok(())
  18. }
  19. pub async fn new_wallet() -> Result<()> {
  20. debug!(target: "adapter", "new_wallet() [START]");
  21. let path = WalletDB::path("wallet.db").expect("Failed to get path");
  22. WalletDB::new(path).await?;
  23. Ok(())
  24. }
  25. pub async fn new_cashier_wallet() -> Result<()> {
  26. debug!(target: "adapter", "new_cashier_wallet() [START]");
  27. let path = WalletDB::path("cashier.db").expect("Failed to get path");
  28. WalletDB::new(path).await?;
  29. Ok(())
  30. }
  31. pub async fn save_cash_key(pubkey: Vec<u8>) -> Result<()> {
  32. debug!(target: "adapter", "save_cash_key() [START]");
  33. let path = WalletDB::path("cashier.db").expect("Failed to get path");
  34. WalletDB::save(path, pubkey).await?;
  35. Ok(())
  36. }
  37. pub async fn save_key(pubkey: Vec<u8>) -> Result<()> {
  38. debug!(target: "adapter", "save_key() [START]");
  39. let path = WalletDB::path("wallet.db").expect("Failed to get path");
  40. WalletDB::save(path, pubkey).await?;
  41. Ok(())
  42. }
  43. pub async fn get_info() {}
  44. pub async fn say_hello() {}
  45. pub async fn stop() {}
  46. }