mirror of
https://github.com/RoboSats/taptrade-core.git
synced 2025-09-12 20:56:28 +00:00
refactoring
This commit is contained in:
@ -16,8 +16,9 @@ pub struct OrderRequest {
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub struct BondSubmissionRequest {
|
||||
pub serialized_bond_tx_hex: String,
|
||||
pub robohash_base91: String,
|
||||
pub payout_address: String,
|
||||
pub frost_public_nonce_hex: String,
|
||||
pub signed_bond_base91: String,
|
||||
pub payout_address: String, // does this make sense here?
|
||||
pub musig_pub_nonce_base91: String,
|
||||
pub musig_pubkey_base91: String,
|
||||
}
|
||||
|
@ -0,0 +1,43 @@
|
||||
use crate::cli::TraderSettings;
|
||||
use crate::communication::api::OfferCreationResponse;
|
||||
use crate::wallet::{
|
||||
bond::Bond,
|
||||
musig2::{MuSigData, MusigNonce},
|
||||
TradingWallet,
|
||||
};
|
||||
use anyhow::Result;
|
||||
use bdk::database::MemoryDatabase;
|
||||
// use bdk::{
|
||||
// bitcoin::block,
|
||||
// blockchain::{Blockchain, ElectrumBlockchain},
|
||||
// electrum_client::Client,
|
||||
// wallet::AddressIndex::LastUnused,
|
||||
// Wallet,
|
||||
// };
|
||||
|
||||
pub struct ActiveOffer {}
|
||||
|
||||
impl ActiveOffer {
|
||||
pub fn create(
|
||||
trading_wallet: &TradingWallet,
|
||||
maker_config: &TraderSettings,
|
||||
) -> Result<ActiveOffer> {
|
||||
let offer_conditions = OfferCreationResponse::fetch(maker_config)?;
|
||||
let trading_wallet = &trading_wallet.wallet;
|
||||
|
||||
let offer_conditions = OfferCreationResponse {
|
||||
// hardcoded for testing, locking_address is owned by .env xprv
|
||||
locking_amount: 90000,
|
||||
bond_address: "tb1pfdvgfzwp8vhmelpv8w9kezz7nsmxw68jz6yehgze6mzx0t6r9t2qv9ynmm"
|
||||
.to_string(),
|
||||
};
|
||||
|
||||
let bond = Bond::assemble(trading_wallet, &offer_conditions, maker_config)?;
|
||||
|
||||
let payout_pubkey = trading_wallet.get_address(bdk::wallet::AddressIndex::LastUnused)?;
|
||||
|
||||
let musig_data = MuSigData::create(&maker_config.wallet_xprv, trading_wallet.secp_ctx())?;
|
||||
|
||||
Ok(ActiveOffer {})
|
||||
}
|
||||
}
|
@ -1,43 +1,19 @@
|
||||
mod maker_utils;
|
||||
|
||||
use self::maker_utils::ActiveOffer;
|
||||
use crate::cli::TraderSettings;
|
||||
use crate::communication::api::OfferCreationResponse;
|
||||
use crate::wallet::{
|
||||
bond::Bond,
|
||||
load_wallet,
|
||||
musig2::{MuSigData, MusigNonce},
|
||||
};
|
||||
use crate::wallet::TradingWallet;
|
||||
use anyhow::Result;
|
||||
use bdk::{
|
||||
bitcoin::block,
|
||||
blockchain::{Blockchain, ElectrumBlockchain},
|
||||
electrum_client::Client,
|
||||
wallet::AddressIndex::LastUnused,
|
||||
};
|
||||
|
||||
pub fn run_maker(maker_config: &TraderSettings) -> Result<()> {
|
||||
let blockchain = ElectrumBlockchain::from(Client::new(&maker_config.electrum_endpoint)?);
|
||||
|
||||
// let offer_conditions = OfferCreationResponse::fetch(maker_config)?;
|
||||
let offer_conditions = OfferCreationResponse {
|
||||
// hardcoded for testing, locking_address is owned by .env xprv
|
||||
locking_amount: 90000,
|
||||
bond_address: "tb1pfdvgfzwp8vhmelpv8w9kezz7nsmxw68jz6yehgze6mzx0t6r9t2qv9ynmm".to_string(),
|
||||
};
|
||||
|
||||
let wallet = load_wallet(maker_config, &blockchain)?; // initialize the wallet with xprv
|
||||
|
||||
let bond = Bond::assemble(&wallet, &offer_conditions, maker_config)?; // assemble the Bond transaction for offer creation
|
||||
// blockchain.broadcast(&bond.extract_tx())?; // publish bond to be mined for testing
|
||||
let payout_pubkey = wallet.get_address(bdk::wallet::AddressIndex::LastUnused)?;
|
||||
|
||||
let musig = MuSigData::create(&maker_config.wallet_xprv, wallet.secp_ctx())?;
|
||||
let wallet = TradingWallet::load_wallet(maker_config)?; // initialize the wallet with xprv
|
||||
|
||||
let offer = ActiveOffer::create(&wallet, maker_config)?;
|
||||
// dbg!(&bond.extract_tx().txid());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn run_taker(taker_config: &TraderSettings) -> Result<()> {
|
||||
let blockchain = ElectrumBlockchain::from(Client::new(&taker_config.electrum_endpoint)?);
|
||||
|
||||
// panic!("Taker to be implemented!");
|
||||
|
||||
Ok(())
|
||||
|
@ -18,10 +18,10 @@ use bdk::{
|
||||
use std::str::FromStr;
|
||||
use wallet_utils::get_seed;
|
||||
|
||||
// pub struct WalletDescriptors {
|
||||
// pub descriptor: Bip86<ExtendedPrivKey>,
|
||||
// pub change_descriptor: Option<Bip86<ExtendedPrivKey>>,
|
||||
// }
|
||||
pub struct TradingWallet {
|
||||
pub wallet: Wallet<MemoryDatabase>,
|
||||
pub backend: ElectrumBlockchain,
|
||||
}
|
||||
|
||||
pub fn get_wallet_xprv(xprv_input: Option<String>) -> Result<ExtendedPrivKey> {
|
||||
let xprv: ExtendedPrivKey;
|
||||
@ -37,21 +37,21 @@ pub fn get_wallet_xprv(xprv_input: Option<String>) -> Result<ExtendedPrivKey> {
|
||||
Ok(xprv)
|
||||
}
|
||||
|
||||
pub fn load_wallet(
|
||||
trader_config: &TraderSettings,
|
||||
blockchain: &ElectrumBlockchain,
|
||||
) -> Result<Wallet<MemoryDatabase>> {
|
||||
let wallet = Wallet::new(
|
||||
Bip86(trader_config.wallet_xprv.clone(), KeychainKind::External),
|
||||
Some(Bip86(
|
||||
trader_config.wallet_xprv.clone(),
|
||||
KeychainKind::Internal,
|
||||
)),
|
||||
bitcoin::Network::Testnet,
|
||||
MemoryDatabase::default(), // non-permanent storage
|
||||
)?;
|
||||
impl TradingWallet {
|
||||
pub fn load_wallet(trader_config: &TraderSettings) -> Result<TradingWallet> {
|
||||
let backend = ElectrumBlockchain::from(Client::new(&trader_config.electrum_endpoint)?);
|
||||
let wallet = Wallet::new(
|
||||
Bip86(trader_config.wallet_xprv.clone(), KeychainKind::External),
|
||||
Some(Bip86(
|
||||
trader_config.wallet_xprv.clone(),
|
||||
KeychainKind::Internal,
|
||||
)),
|
||||
bitcoin::Network::Testnet,
|
||||
MemoryDatabase::default(), // non-permanent storage
|
||||
)?;
|
||||
|
||||
wallet.sync(blockchain, SyncOptions::default())?;
|
||||
println!("Balance: {} SAT", wallet.get_balance()?);
|
||||
Ok(wallet)
|
||||
wallet.sync(&backend, SyncOptions::default())?;
|
||||
dbg!("Balance: {} SAT", wallet.get_balance()?);
|
||||
Ok(TradingWallet { wallet, backend })
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user