Browse Source

Rename BtcKeys -> Account

Janus 4 năm trước cách đây
mục cha
commit
363fa1b49c
2 tập tin đã thay đổi với 16 bổ sung12 xóa
  1. 15 11
      src/service/btc.rs
  2. 1 1
      src/service/mod.rs

+ 15 - 11
src/service/btc.rs

@@ -99,7 +99,7 @@ impl Default for Keypair {
     }
     }
 }
 }
 #[derive(Clone)]
 #[derive(Clone)]
-pub struct BtcKeys {
+pub struct Account {
     keypair: Arc<Keypair>,
     keypair: Arc<Keypair>,
     btc_privkey: BtcPrivKey,
     btc_privkey: BtcPrivKey,
     pub btc_pubkey: BtcPubKey,
     pub btc_pubkey: BtcPubKey,
@@ -108,13 +108,13 @@ pub struct BtcKeys {
     pub network: Network,
     pub network: Network,
 }
 }
 
 
-impl BtcKeys {
+impl Account {
     pub fn new(keypair: &Keypair, network: Network) -> Self {
     pub fn new(keypair: &Keypair, network: Network) -> Self {
         let (secret_key, _public_key) = keypair.as_tuple();
         let (secret_key, _public_key) = keypair.as_tuple();
 
 
         let btc_privkey = BtcPrivKey::new(secret_key, network);
         let btc_privkey = BtcPrivKey::new(secret_key, network);
         let btc_pubkey = btc_privkey.public_key(&keypair.context);
         let btc_pubkey = btc_privkey.public_key(&keypair.context);
-        let address = BtcKeys::derive_btc_address(btc_pubkey, network);
+        let address = Account::derive_btc_address(btc_pubkey, network);
         let script_pubkey = address.script_pubkey();
         let script_pubkey = address.script_pubkey();
 
 
         Self {
         Self {
@@ -158,7 +158,7 @@ impl BtcKeys {
 }
 }
 
 
 pub struct BtcClient {
 pub struct BtcClient {
-    main_account: BtcKeys,
+    main_account: Account,
     notify_channel: (
     notify_channel: (
         async_channel::Sender<TokenNotification>,
         async_channel::Sender<TokenNotification>,
         async_channel::Receiver<TokenNotification>,
         async_channel::Receiver<TokenNotification>,
@@ -178,7 +178,7 @@ impl BtcClient {
             _ => return Err(Error::NotSupportedNetwork),
             _ => return Err(Error::NotSupportedNetwork),
         };
         };
 
 
-        let main_account = BtcKeys::new(&main_keypair, network);
+        let main_account = Account::new(&main_keypair, network);
 
 
         let electrum_client = ElectrumClient::new(&url)
         let electrum_client = ElectrumClient::new(&url)
             .map_err(|err| crate::Error::from(super::BtcFailed::from(err)))?;
             .map_err(|err| crate::Error::from(super::BtcFailed::from(err)))?;
@@ -193,7 +193,7 @@ impl BtcClient {
 
 
     async fn handle_subscribe_request(
     async fn handle_subscribe_request(
         self: Arc<Self>,
         self: Arc<Self>,
-        btc_keys: BtcKeys,
+        btc_keys: Account,
         drk_pub_key: jubjub::SubgroupPoint,
         drk_pub_key: jubjub::SubgroupPoint,
     ) -> BtcResult<()> {
     ) -> BtcResult<()> {
         debug!(
         debug!(
@@ -213,7 +213,6 @@ impl BtcClient {
 
 
         let status = client.script_subscribe(&script)?;
         let status = client.script_subscribe(&script)?;
 
 
-
         loop {
         loop {
             let current_status = client.script_pop(&script)?;
             let current_status = client.script_pop(&script)?;
             debug!(target: "BTC CLIENT", "script status: {:?}", status);
             debug!(target: "BTC CLIENT", "script status: {:?}", status);
@@ -233,6 +232,7 @@ impl BtcClient {
                 Some(_) => {
                 Some(_) => {
                     // Script has a notification update
                     // Script has a notification update
                     debug!(target: "BTC CLIENT", "ScripPubKey notify update");
                     debug!(target: "BTC CLIENT", "ScripPubKey notify update");
+                    let _ = client.script_unsubscribe(&script)?;
                     break;
                     break;
                 }
                 }
                 None => {
                 None => {
@@ -276,7 +276,7 @@ impl BtcClient {
         Ok(())
         Ok(())
     }
     }
 
 
-    fn send_btc_to_main_wallet(self: Arc<Self>, amount: u64, btc_keys: BtcKeys) -> BtcResult<()> {
+    fn send_btc_to_main_wallet(self: Arc<Self>, amount: u64, btc_keys: Account) -> BtcResult<()> {
         debug!(target: "BTC BRIDGE", "Sending {} BTC to main wallet", amount);
         debug!(target: "BTC BRIDGE", "Sending {} BTC to main wallet", amount);
         let client = &self.client;
         let client = &self.client;
         let keys_clone = btc_keys.clone();
         let keys_clone = btc_keys.clone();
@@ -315,6 +315,10 @@ impl BtcClient {
             lock_time: 0,
             lock_time: 0,
             version: 2,
             version: 2,
         };
         };
+        let txid = transaction.txid();
+        debug!(target: "BTC BRIDGE", "unSigned tx: {:?}",
+               &txid.to_hex());
+
 
 
         let signed_tx = sign_transaction(
         let signed_tx = sign_transaction(
             transaction,
             transaction,
@@ -346,7 +350,7 @@ impl NetworkClient for BtcClient {
     ) -> Result<TokenSubscribtion> {
     ) -> Result<TokenSubscribtion> {
         // Generate bitcoin keys
         // Generate bitcoin keys
         let keypair = Keypair::new();
         let keypair = Keypair::new();
-        let btc_keys = BtcKeys::new(&keypair, self.network);
+        let btc_keys = Account::new(&keypair, self.network);
         let secret_key = serialize(&keypair);
         let secret_key = serialize(&keypair);
         let public_key = btc_keys.address.to_string();
         let public_key = btc_keys.address.to_string();
 
 
@@ -375,7 +379,7 @@ impl NetworkClient for BtcClient {
         _mint: Option<String>,
         _mint: Option<String>,
     ) -> Result<String> {
     ) -> Result<String> {
         let keypair: Keypair = deserialize(&private_key)?;
         let keypair: Keypair = deserialize(&private_key)?;
-        let btc_keys = BtcKeys::new(&keypair, self.network);
+        let btc_keys = Account::new(&keypair, self.network);
         let public_key = keypair.pubkey().to_string();
         let public_key = keypair.pubkey().to_string();
 
 
         smol::spawn(async move {
         smol::spawn(async move {
@@ -395,7 +399,7 @@ impl NetworkClient for BtcClient {
         // address is not a btc address, so derive the btc address
         // address is not a btc address, so derive the btc address
         let client = &self.client;
         let client = &self.client;
         let public_key = deserialize(&address)?;
         let public_key = deserialize(&address)?;
-        let script_pubkey = BtcKeys::derive_btc_script_pubkey(public_key, self.network);
+        let script_pubkey = Account::derive_btc_script_pubkey(public_key, self.network);
 
 
         let main_script_pubkey = &self.main_account.script_pubkey;
         let main_script_pubkey = &self.main_account.script_pubkey;
 
 

+ 1 - 1
src/service/mod.rs

@@ -6,7 +6,7 @@ pub mod reqrep;
 #[cfg(feature = "btc")]
 #[cfg(feature = "btc")]
 pub mod btc;
 pub mod btc;
 #[cfg(feature = "btc")]
 #[cfg(feature = "btc")]
-pub use btc::{Keypair, BtcKeys, BtcFailed, BtcResult, PubAddress};
+pub use btc::{Keypair, Account, BtcFailed, BtcResult, PubAddress};
 
 
 #[cfg(feature = "sol")]
 #[cfg(feature = "sol")]
 pub mod sol;
 pub mod sol;