mirror of
https://github.com/RoboSats/taptrade-core.git
synced 2025-07-19 09:13:39 +00:00
improve rpc wallet connection (user/pass), remove cookie, derive wallet name from descriptor
This commit is contained in:
@ -1 +0,0 @@
|
||||
__cookie__:7b9dd407a2bf94a226776d1d35d5aeb64148b9425ddd6cf286381d6ab1d5f585
|
@ -1,6 +1,6 @@
|
||||
BITCOIN_RPC_ADDRESS_PORT="127.0.0.1:8332"
|
||||
BITCOIN_RPC_COOKIE_FILE_PATH="./.cookie" # path to the cookie file for the bitcoind RPC
|
||||
BITCOIN_RPC_WALLET_NAME="coordinator_wallet" # not used yet
|
||||
BITCOIN_RPC_USER="coordinator"
|
||||
BITCOIN_RPC_PASSWORD="test1234"
|
||||
DATABASE_PATH="./dbs/trades.db" # path to the coordinator sqlite database storing the trades
|
||||
BDK_DB_PATH="./dbs/bdk-wallet" # Path to the BDK Sled database (no .db postfix)
|
||||
WALLET_XPRV="tprv8ZgxMBicQKsPdHuCSjhQuSZP1h6ZTeiRqREYS5guGPdtL7D1uNLpnJmb2oJep99Esq1NbNZKVJBNnD2ZhuXSK7G5eFmmcx73gsoa65e2U32"
|
||||
|
@ -28,7 +28,7 @@ fn run_mempool(mempool: Arc<Mempool>) {
|
||||
loop {
|
||||
// sleep for a while
|
||||
std::thread::sleep(std::time::Duration::from_secs(15));
|
||||
debug!("Fetching mempool");
|
||||
trace!("Fetching mempool");
|
||||
let mempool_txs = match mempool.json_rpc_client.deref().get_raw_mempool() {
|
||||
std::result::Result::Ok(mempool_txs) => mempool_txs,
|
||||
Err(e) => {
|
||||
|
@ -10,7 +10,7 @@ use coordinator::monitoring::monitor_bonds;
|
||||
use coordinator::monitoring::*;
|
||||
use database::CoordinatorDB;
|
||||
use dotenv::dotenv;
|
||||
use log::{debug, error, info, warn};
|
||||
use log::{debug, error, info, trace, warn};
|
||||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
use std::{env, sync::Arc};
|
||||
use tokio::sync::Mutex;
|
||||
|
@ -4,13 +4,16 @@ mod utils;
|
||||
use super::*;
|
||||
use anyhow::Context;
|
||||
use bdk::{
|
||||
bitcoin::{self, bip32::ExtendedPrivKey, consensus::encode::deserialize, Transaction},
|
||||
bitcoin::{
|
||||
self, bip32::ExtendedPrivKey, consensus::encode::deserialize, key::secp256k1,
|
||||
Network::Regtest, Transaction,
|
||||
},
|
||||
bitcoincore_rpc::{Client, RawTx, RpcApi},
|
||||
blockchain::{rpc::Auth, Blockchain, ConfigurableBlockchain, RpcBlockchain, RpcConfig},
|
||||
sled::{self, Tree},
|
||||
template::Bip86,
|
||||
wallet::verify::*,
|
||||
KeychainKind, Wallet,
|
||||
KeychainKind, SyncOptions, Wallet,
|
||||
};
|
||||
use coordinator::mempool_monitoring::MempoolHandler;
|
||||
use std::{collections::HashMap, str::FromStr};
|
||||
@ -37,13 +40,21 @@ pub async fn init_coordinator_wallet() -> Result<CoordinatorWallet<sled::Tree>>
|
||||
let wallet_xprv = ExtendedPrivKey::from_str(
|
||||
&env::var("WALLET_XPRV").context("loading WALLET_XPRV from .env failed")?,
|
||||
)?;
|
||||
let secp_context = secp256k1::Secp256k1::new();
|
||||
let rpc_config = RpcConfig {
|
||||
url: env::var("BITCOIN_RPC_ADDRESS_PORT")?.to_string(),
|
||||
auth: Auth::Cookie {
|
||||
file: env::var("BITCOIN_RPC_COOKIE_FILE_PATH")?.into(),
|
||||
auth: Auth::UserPass {
|
||||
username: env::var("BITCOIN_RPC_USER")?,
|
||||
password: env::var("BITCOIN_RPC_PASSWORD")?,
|
||||
},
|
||||
network: bdk::bitcoin::Network::Regtest,
|
||||
wallet_name: env::var("BITCOIN_RPC_WALLET_NAME")?,
|
||||
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)),
|
||||
Regtest,
|
||||
&secp_context,
|
||||
)?,
|
||||
sync_params: None,
|
||||
};
|
||||
let json_rpc_client = Arc::new(Client::new(
|
||||
@ -63,9 +74,9 @@ pub async fn init_coordinator_wallet() -> Result<CoordinatorWallet<sled::Tree>>
|
||||
let json_rpc_client_clone = Arc::clone(&json_rpc_client);
|
||||
let mempool = MempoolHandler::new(json_rpc_client_clone).await;
|
||||
|
||||
// wallet
|
||||
// .sync(&backend, SyncOptions::default())
|
||||
// .context("Connection to blockchain server failed.")?; // we could also use Esplora to make this async
|
||||
wallet
|
||||
.sync(&backend, SyncOptions::default())
|
||||
.context("Connection to blockchain server failed.")?; // we could also use Esplora to make this async
|
||||
dbg!(wallet.get_balance()?);
|
||||
Ok(CoordinatorWallet {
|
||||
wallet: Arc::new(Mutex::new(wallet)),
|
||||
|
@ -81,6 +81,7 @@ impl OfferPsbtRequest {
|
||||
.send()?
|
||||
.json::<OfferTakenResponse>()?;
|
||||
|
||||
debug!("Trader received escrow psbt");
|
||||
let psbt_bytes = hex::decode(res.trade_psbt_hex_to_sign)?;
|
||||
let psbt = PartiallySignedTransaction::deserialize(&psbt_bytes)?;
|
||||
Ok(psbt)
|
||||
|
@ -2,6 +2,7 @@ pub mod bond;
|
||||
pub mod musig2;
|
||||
pub mod wallet_utils;
|
||||
|
||||
use super::*;
|
||||
use crate::{cli::TraderSettings, communication::api::BondRequirementResponse};
|
||||
use anyhow::{anyhow, Result};
|
||||
use bdk::{
|
||||
@ -73,7 +74,7 @@ impl TradingWallet {
|
||||
// taker input should be the same as in the previous bond transaction.
|
||||
// input amount should be the bond amount when buying,
|
||||
pub fn validate_taker_psbt(&self, psbt: &PartiallySignedTransaction) -> Result<&Self> {
|
||||
dbg!("IMPLEMENT TAKER PSBT VALIDATION!");
|
||||
error!("IMPLEMENT TAKER PSBT VALIDATION!");
|
||||
// tbd once the trade psbt is implemented on coordinator side
|
||||
Ok(self)
|
||||
}
|
||||
@ -86,9 +87,11 @@ impl TradingWallet {
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
// validate input amount, escrow output
|
||||
pub fn validate_maker_psbt(&self, psbt: &PartiallySignedTransaction) -> Result<&Self> {
|
||||
dbg!("IMPLEMENT MAKER PSBT VALIDATION!");
|
||||
error!("IMPLEMENT MAKER PSBT VALIDATION!");
|
||||
// tbd once the trade psbt is implemented on coordinator side
|
||||
|
||||
Ok(self)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user