adapter.rs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. use crate::wallet::WalletDb;
  2. use crate::Result;
  3. use async_std::sync::Arc;
  4. use log::*;
  5. //use std::sync::Arc;
  6. pub type AdapterPtr = Arc<RpcAdapter>;
  7. // Dummy adapter for now
  8. pub struct RpcAdapter {
  9. pub wallet: Arc<WalletDb>,
  10. }
  11. impl RpcAdapter {
  12. pub fn new(wallet: Arc<WalletDb>) -> Result<Self> {
  13. debug!(target: "ADAPTER", "new() [CREATING NEW WALLET]");
  14. Ok(Self { wallet })
  15. }
  16. pub fn init_db(&self) -> Result<()> {
  17. debug!(target: "adapter", "init_db() [START]");
  18. self.wallet.init_db()?;
  19. Ok(())
  20. }
  21. pub fn init_cashier_db(&self) -> Result<()> {
  22. debug!(target: "adapter", "init_cashier_db() [START]");
  23. self.wallet.init_cashier_db()?;
  24. Ok(())
  25. }
  26. pub fn key_gen(&self) -> Result<()> {
  27. debug!(target: "adapter", "key_gen() [START]");
  28. let (public, private) = self.wallet.key_gen();
  29. debug!(target: "adapter", "Created keypair...");
  30. debug!(target: "adapter", "Attempting to write to database...");
  31. self.wallet.put_keypair(public, private)?;
  32. Ok(())
  33. }
  34. pub fn cash_key_gen(&self) -> Result<()> {
  35. debug!(target: "adapter", "key_gen() [START]");
  36. let (public, private) = self.wallet.cash_key_gen();
  37. self.wallet.put_keypair(public, private)?;
  38. Ok(())
  39. }
  40. pub fn get_key(&self) -> Result<()> {
  41. debug!(target: "adapter", "get_key() [START]");
  42. let key_public = self.wallet.get_public()?;
  43. println!("{:?}", key_public);
  44. Ok(())
  45. }
  46. pub fn get_cash_key(&self) -> Result<()> {
  47. debug!(target: "adapter", "get_cash_key() [START]");
  48. let cashier_public = self.wallet.get_cashier_public()?;
  49. println!("{:?}", cashier_public);
  50. Ok(())
  51. }
  52. pub fn test_wallet(&self) -> Result<()> {
  53. self.wallet.test_wallet()?;
  54. debug!(target: "adapter", "test wallet: START");
  55. Ok(())
  56. }
  57. pub fn deposit(&self) -> Result<()> {
  58. debug!(target: "deposit", "deposit: START");
  59. let (public, private) = self.wallet.key_gen();
  60. self.wallet.put_keypair(public, private)?;
  61. Ok(())
  62. }
  63. //pub async fn walletdb(&self) -> WalletPtr {
  64. // self.wallet.clone();
  65. //}
  66. //pub async fn create_
  67. //pub async fn save_key(&self, pubkey: Vec<u8>) -> Result<()> {
  68. // debug!(target: "adapter", "save_key() [START]");
  69. // //let path = WalletDb::path("wallet.db")?;
  70. // //WalletDb::save(path, pubkey).await?;
  71. // Ok(())
  72. //}
  73. //pub async fn save_cash_key(&self, pubkey: Vec<u8>) -> Result<()> {
  74. // debug!(target: "adapter", "save_cash_key() [START]");
  75. // //let path = WalletDb::path("cashier.db")?;
  76. // //WalletDb::save(path, pubkey).await?;
  77. // Ok(())
  78. //}
  79. pub fn get_info(&self) {}
  80. pub fn say_hello(&self) {}
  81. pub fn stop(&self) {}
  82. }