From b1a4863140f872bd576501fea6b105089dbeb534 Mon Sep 17 00:00:00 2001 From: f321x Date: Wed, 17 Jul 2024 20:35:41 +0200 Subject: [PATCH] small changes, comments --- .../coordinator/src/communication/mod.rs | 11 ++++++++ .../src/coordinator/mempool_monitoring.rs | 3 +++ .../coordinator/src/wallet/mod.rs | 26 ++++++++++++++----- taptrade-cli-demo/trader/src/wallet/mod.rs | 2 +- 4 files changed, 34 insertions(+), 8 deletions(-) diff --git a/taptrade-cli-demo/coordinator/src/communication/mod.rs b/taptrade-cli-demo/coordinator/src/communication/mod.rs index 653025c..d3a3eb7 100755 --- a/taptrade-cli-demo/coordinator/src/communication/mod.rs +++ b/taptrade-cli-demo/coordinator/src/communication/mod.rs @@ -179,6 +179,11 @@ async fn submit_escrow_psbt( Json(payload): Json, ) -> Result { panic!("implement") + + // check if psbt is correct, valid and signed + // publish psbt if it is correct + // return 200 if everything is correct + // return 400 if something is wrong } /// Will get polled by the traders once they submitted their PSBT part. The coorinator will return status code 200 once he received both PSBTs and they got mined, @@ -192,6 +197,12 @@ async fn poll_escrow_confirmation( Json(payload): Json, ) -> Result { panic!("implement") + // let escrow_tx_txid = database.fetch_escrow_txid(&payload.order_id_hex).await?; + // if wallet.is_tx_confirmed(&escrow_tx_txid).await { + // Ok(StatusCode::OK.into_response()) + // } else { + // Ok(StatusCode::ACCEPTED.into_response()) + // } else if not found in database or not published (invalid request) return 404 } async fn submit_obligation_confirmation( diff --git a/taptrade-cli-demo/coordinator/src/coordinator/mempool_monitoring.rs b/taptrade-cli-demo/coordinator/src/coordinator/mempool_monitoring.rs index 67429dd..01a0a4a 100644 --- a/taptrade-cli-demo/coordinator/src/coordinator/mempool_monitoring.rs +++ b/taptrade-cli-demo/coordinator/src/coordinator/mempool_monitoring.rs @@ -1,3 +1,6 @@ +// Obsolete trough usage of gettxspendingprevout, unfortunately bitcoincore_rpc does not support it yet +// doing upstream PR with gettxspendingprevout would make it possible to get rid of this internal mempool state + use super::*; use anyhow::Ok; use bdk::bitcoin::consensus::encode::deserialize; diff --git a/taptrade-cli-demo/coordinator/src/wallet/mod.rs b/taptrade-cli-demo/coordinator/src/wallet/mod.rs index 85a5c02..35023ac 100644 --- a/taptrade-cli-demo/coordinator/src/wallet/mod.rs +++ b/taptrade-cli-demo/coordinator/src/wallet/mod.rs @@ -287,35 +287,46 @@ impl fmt::Debug for CoordinatorWallet { #[cfg(test)] mod tests { + use std::time::Duration; + use super::*; use bdk::bitcoin::Network; use bdk::database::MemoryDatabase; use bdk::{blockchain::RpcBlockchain, Wallet}; async fn new_test_wallet(wallet_xprv: &str) -> CoordinatorWallet { dotenv().ok(); + let wallet_xprv = ExtendedPrivKey::from_str(wallet_xprv).unwrap(); + let secp_context = secp256k1::Secp256k1::new(); let rpc_config = RpcConfig { url: env::var("BITCOIN_RPC_ADDRESS_PORT").unwrap().to_string(), - auth: Auth::Cookie { - file: env::var("BITCOIN_RPC_COOKIE_FILE_PATH").unwrap().into(), + auth: Auth::UserPass { + username: env::var("BITCOIN_RPC_USER").unwrap(), + password: env::var("BITCOIN_RPC_PASSWORD").unwrap(), }, - network: bdk::bitcoin::Network::Regtest, - wallet_name: env::var("BITCOIN_RPC_WALLET_NAME").unwrap(), + network: Regtest, + // wallet_name: env::var("BITCOIN_RPC_WALLET_NAME")?, + wallet_name: bdk::wallet::wallet_name_from_descriptor( + Bip86(wallet_xprv, KeychainKind::External), + Some(Bip86(wallet_xprv, KeychainKind::Internal)), + Network::Testnet, + &secp_context, + ) + .unwrap(), sync_params: None, }; let json_rpc_client = Arc::new(Client::new(&rpc_config.url, rpc_config.auth.clone().into()).unwrap()); let backend = RpcBlockchain::from_config(&rpc_config).unwrap(); - let wallet_xprv = ExtendedPrivKey::from_str(wallet_xprv).unwrap(); let wallet = Wallet::new( Bip86(wallet_xprv, KeychainKind::External), Some(Bip86(wallet_xprv, KeychainKind::Internal)), - Network::Regtest, + Network::Testnet, MemoryDatabase::new(), ) .unwrap(); wallet.sync(&backend, SyncOptions::default()).unwrap(); - + tokio::time::sleep(Duration::from_secs(16)).await; // fetch the mempool CoordinatorWallet:: { wallet: Arc::new(Mutex::new(wallet)), backend: Arc::new(backend), @@ -324,6 +335,7 @@ mod tests { } } + // the transactions are testnet4 transactions, so run a testnet4 rpc node as backend #[tokio::test] async fn test_transaction_without_signature() { let test_wallet = new_test_wallet("tprv8ZgxMBicQKsPdHuCSjhQuSZP1h6ZTeiRqREYS5guGPdtL7D1uNLpnJmb2oJep99Esq1NbNZKVJBNnD2ZhuXSK7G5eFmmcx73gsoa65e2U32").await; diff --git a/taptrade-cli-demo/trader/src/wallet/mod.rs b/taptrade-cli-demo/trader/src/wallet/mod.rs index a00c0a7..56f8d8c 100644 --- a/taptrade-cli-demo/trader/src/wallet/mod.rs +++ b/taptrade-cli-demo/trader/src/wallet/mod.rs @@ -87,7 +87,7 @@ impl TradingWallet { Ok(self) } - // validate input amount, escrow output + // validate amounts, escrow output pub fn validate_maker_psbt(&self, psbt: &PartiallySignedTransaction) -> Result<&Self> { error!("IMPLEMENT MAKER PSBT VALIDATION!"); // tbd once the trade psbt is implemented on coordinator side