From a807faf4a4b9c8678490dfca6984d7ddc7079c5e Mon Sep 17 00:00:00 2001 From: Janus Date: Mon, 12 Jul 2021 13:36:22 -0400 Subject: [PATCH] Add method get_deposit_address --- src/bin/cashierd.rs | 4 +++- src/service/bitcoin_bridge.rs | 15 ++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/bin/cashierd.rs b/src/bin/cashierd.rs index 6d9f793d7..181d47e02 100644 --- a/src/bin/cashierd.rs +++ b/src/bin/cashierd.rs @@ -34,7 +34,9 @@ async fn start(executor: Arc>, options: ServiceCli) -> Result<()> { fn main() -> Result<()> { - let btc = BitcoinAddress::new(); + let btc = BitcoinAddress::new().unwrap(); + let deposit = btc.get_deposit_address(); + println!("{:?}", deposit); use simplelog::*; diff --git a/src/service/bitcoin_bridge.rs b/src/service/bitcoin_bridge.rs index 84ee5ea92..5436fabc2 100644 --- a/src/service/bitcoin_bridge.rs +++ b/src/service/bitcoin_bridge.rs @@ -12,7 +12,7 @@ use std::net::SocketAddr; use async_std::sync::Arc; use async_executor::Executor; -// Struct needs to attach to drk key stored in db +// Struct still needs to attach to drk key stored in db pub struct BitcoinAddress { secret_key: SecretKey, bitcoin_private_key: PrivateKey, @@ -22,10 +22,11 @@ pub struct BitcoinAddress { impl BitcoinAddress { pub fn new( - ) -> Result> { + ) -> Result { let context = secp256k1::Secp256k1::new(); + // Probably not good enough for release let rand: String = thread_rng() .sample_iter(&Alphanumeric) .take(32) @@ -48,16 +49,16 @@ impl BitcoinAddress { let pub_address = Address::p2pkh(&bitcoin_public_key, Network::Bitcoin); - Ok(Arc::new(BitcoinAddress { + Ok(BitcoinAddress { secret_key, bitcoin_private_key, bitcoin_public_key, pub_address, - })) + }) + } + pub fn get_deposit_address(&self) -> &Address { + &self.pub_address } - // pub fn get_deposit_address(&self) -> BitcoinAddress::pub_address { - // &Self {pub_address} - // } } pub struct CashierService {