adapter.rs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. use crate::wallet::WalletDB;
  2. use crate::Result;
  3. use log::*;
  4. use std::sync::Arc;
  5. // there should
  6. // Dummy adapter for now
  7. pub struct RpcAdapter {
  8. wallet: Arc<WalletDB>,
  9. }
  10. impl RpcAdapter {
  11. pub fn new(dbname: &str) -> Result<Arc<Self>> {
  12. let wallet = WalletDB::new(dbname)?;
  13. Ok(Arc::new(Self { wallet }))
  14. }
  15. //pub async fn get_path(&self) -> Result<PathBuf> {
  16. //}
  17. pub async fn key_gen(&self) -> Result<()> {
  18. debug!(target: "adapter", "key_gen() [START]");
  19. let (public, private) = self.wallet.key_gen().await;
  20. self.wallet.put_key(public, private).await?;
  21. Ok(())
  22. }
  23. pub async fn cash_key_gen(&self) -> Result<()> {
  24. debug!(target: "adapter", "key_gen() [START]");
  25. //let (public, private) = WalletDB::create_key().await;
  26. //let path = WalletDB::path("cashier.db")?;
  27. //WalletDB::save_key(path, public, private)
  28. // .await
  29. // .expect("Failed to save key");
  30. Ok(())
  31. }
  32. pub async fn get_key(&self) -> Result<()> {
  33. debug!(target: "adapter", "get_key() [START]");
  34. //let path = WalletDB::path("wallet.db")?;
  35. //WalletDB::get_public(path).await?;
  36. Ok(())
  37. }
  38. pub async fn get_cash_key(&self) -> Result<()> {
  39. debug!(target: "adapter", "get_cash_key() [START]");
  40. //let path = WalletDB::path("cashier.db")?;
  41. //let key = WalletDB::get_public(path).await?;
  42. //println!("{:?}", key);
  43. Ok(())
  44. }
  45. pub async fn save_key(&self, pubkey: Vec<u8>) -> Result<()> {
  46. debug!(target: "adapter", "save_key() [START]");
  47. //let path = WalletDB::path("wallet.db")?;
  48. //WalletDB::save(path, pubkey).await?;
  49. Ok(())
  50. }
  51. pub async fn save_cash_key(&self, pubkey: Vec<u8>) -> Result<()> {
  52. debug!(target: "adapter", "save_cash_key() [START]");
  53. //let path = WalletDB::path("cashier.db")?;
  54. //WalletDB::save(path, pubkey).await?;
  55. Ok(())
  56. }
  57. pub async fn get_info(&self) {}
  58. pub async fn say_hello(&self) {}
  59. pub async fn stop(&self) {}
  60. }