mirror of
https://github.com/RoboSats/taptrade-core.git
synced 2025-07-19 09:13:39 +00:00
fix bond signing
This commit is contained in:
69
taptrade-cli-demo/trader/Cargo.lock
generated
69
taptrade-cli-demo/trader/Cargo.lock
generated
@ -17,6 +17,15 @@ version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
|
||||
|
||||
[[package]]
|
||||
name = "aho-corasick"
|
||||
version = "1.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anstream"
|
||||
version = "0.6.14"
|
||||
@ -397,6 +406,29 @@ dependencies = [
|
||||
"cfg-if",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "env_filter"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a009aa4810eb158359dda09d0c87378e4bbb89b5a801f016885a4707ba24f7ea"
|
||||
dependencies = [
|
||||
"log",
|
||||
"regex",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "env_logger"
|
||||
version = "0.11.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "38b35839ba51819680ba087cd351788c9a3c476841207e0b8cee0b04722343b9"
|
||||
dependencies = [
|
||||
"anstream",
|
||||
"anstyle",
|
||||
"env_filter",
|
||||
"humantime",
|
||||
"log",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "equivalent"
|
||||
version = "1.0.1"
|
||||
@ -628,6 +660,12 @@ version = "1.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904"
|
||||
|
||||
[[package]]
|
||||
name = "humantime"
|
||||
version = "2.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"
|
||||
|
||||
[[package]]
|
||||
name = "hyper"
|
||||
version = "1.3.1"
|
||||
@ -1029,6 +1067,35 @@ dependencies = [
|
||||
"bitflags 1.3.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "1.10.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b91213439dad192326a0d7c6ee3955910425f441d7038e0d6933b0aec5c4517f"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
"regex-automata",
|
||||
"regex-syntax",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-automata"
|
||||
version = "0.4.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
"regex-syntax",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-syntax"
|
||||
version = "0.8.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b"
|
||||
|
||||
[[package]]
|
||||
name = "reqwest"
|
||||
version = "0.12.4"
|
||||
@ -1508,6 +1575,8 @@ dependencies = [
|
||||
"bdk",
|
||||
"clap",
|
||||
"dotenv",
|
||||
"env_logger",
|
||||
"log",
|
||||
"reqwest",
|
||||
"serde",
|
||||
"sha2",
|
||||
|
@ -9,6 +9,8 @@ base91 = "0.1.0"
|
||||
bdk = "0.29.0"
|
||||
clap = { version = "4.5.4", features = ["derive", "cargo"] }
|
||||
dotenv = "0.15.0"
|
||||
env_logger = "0.11.3"
|
||||
log = "0.4.21"
|
||||
reqwest = { version = "0.12.4", features = ["blocking", "json"] }
|
||||
serde = "1.0.203"
|
||||
sha2 = "0.10.8"
|
||||
|
@ -3,7 +3,8 @@ use anyhow::{anyhow, Result};
|
||||
use sha2::{Sha256, Digest};
|
||||
use std::env;
|
||||
|
||||
use crate::wallet::{generate_descriptor_wallet, WalletDescriptors};
|
||||
use crate::wallet::{get_wallet_xprv, WalletDescriptors};
|
||||
use bdk::bitcoin::bip32::ExtendedPrivKey;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Coordinator;
|
||||
@ -22,7 +23,7 @@ pub struct TraderSettings {
|
||||
pub trade_type: OfferType,
|
||||
pub payout_address: String,
|
||||
pub bond_ratio: u8,
|
||||
pub funded_wallet_descriptor: WalletDescriptors,
|
||||
pub wallet_xprv: ExtendedPrivKey,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
@ -85,7 +86,7 @@ impl CliSettings {
|
||||
let trade_type: OfferType = Self::get_trade_type(None);
|
||||
let payout_address = Self::get_user_input("Enter a payout address for refunded bonds or your trade payout: "); // bdk can be used for validation
|
||||
let bond_ratio: u8 = Self::get_user_input("Enter bond ration in [2, 50]%: ").parse()?;
|
||||
let funded_wallet_descriptor = Self::get_wallet_descriptors(Some(Self::get_user_input("Enter funded testnet wallet xprv or leave empty to generate: ")))?;
|
||||
let wallet_xprv = Self::check_xprv_input(Some(Self::get_user_input("Enter funded testnet wallet xprv or leave empty to generate: ")))?;
|
||||
Ok(TraderSettings {
|
||||
electrum_endpoint,
|
||||
coordinator_endpoint,
|
||||
@ -93,17 +94,17 @@ impl CliSettings {
|
||||
trade_type,
|
||||
payout_address,
|
||||
bond_ratio,
|
||||
funded_wallet_descriptor
|
||||
wallet_xprv
|
||||
})
|
||||
}
|
||||
|
||||
fn get_wallet_descriptors(cli_input: Option<String>) -> Result<WalletDescriptors> {
|
||||
fn check_xprv_input(cli_input: Option<String>) -> Result<ExtendedPrivKey> {
|
||||
if let Some(user_input) = cli_input {
|
||||
if !(user_input.is_empty()) {
|
||||
return generate_descriptor_wallet(Some(user_input));
|
||||
return get_wallet_xprv(Some(user_input));
|
||||
}
|
||||
};
|
||||
generate_descriptor_wallet(None)
|
||||
get_wallet_xprv(None)
|
||||
}
|
||||
|
||||
fn load_from_env() -> Result<TraderSettings> {
|
||||
@ -115,7 +116,7 @@ impl CliSettings {
|
||||
trade_type: Self::get_trade_type(Some(env::var("TRADE_TYPE")?)),
|
||||
payout_address: env::var("PAYOUT_ADDRESS")?,
|
||||
bond_ratio: env::var("BOND_RATIO")?.parse()?,
|
||||
funded_wallet_descriptor: Self::get_wallet_descriptors(Some(env::var("XPRV")?))?,
|
||||
wallet_xprv: Self::check_xprv_input(Some(env::var("XPRV")?))?,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,8 @@ fn start_trade_pipeline(cli_input: &CliSettings) -> Result<()> {
|
||||
}
|
||||
|
||||
fn main() -> Result<()> {
|
||||
// env_logger::builder().filter_level(log::LevelFilter::Debug).init(); // enable to show extended BDK debug messages
|
||||
|
||||
let mode = CliSettings::parse_cli_args()?;
|
||||
dbg!("CLI input :", &mode);
|
||||
start_trade_pipeline(&mode)?;
|
||||
|
@ -9,12 +9,15 @@ use crate::wallet::{load_wallet, bond::Bond};
|
||||
|
||||
|
||||
pub fn run_maker(maker_config: &TraderSettings) -> Result<()> {
|
||||
let offer_conditions = OfferCreationResponse::fetch(maker_config)?;
|
||||
// let offer_conditions = OfferCreationResponse::fetch(maker_config)?;
|
||||
let offer_conditions = OfferCreationResponse {
|
||||
locking_amount: 90000,
|
||||
bond_address: "tb1pfdvgfzwp8vhmelpv8w9kezz7nsmxw68jz6yehgze6mzx0t6r9t2qv9ynmm".to_string(),
|
||||
};
|
||||
|
||||
// let offer_conditions = OfferCreationResponse {
|
||||
// };
|
||||
let wallet = load_wallet(maker_config)?;
|
||||
|
||||
let bond = Bond::assemble(&wallet, &offer_conditions, maker_config)?;
|
||||
dbg!(bond);
|
||||
dbg!(bond.serialize_hex());
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
@ -11,13 +11,12 @@ use crate::cli::TraderSettings;
|
||||
|
||||
// https://github.com/bitcoindevkit/book-of-bdk
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct WalletDescriptors {
|
||||
pub descriptor: Descriptor<DescriptorPublicKey>,
|
||||
pub change_descriptor: Option<Descriptor<DescriptorPublicKey>>
|
||||
pub descriptor: Bip86<ExtendedPrivKey>,
|
||||
pub change_descriptor: Option<Bip86<ExtendedPrivKey>>
|
||||
}
|
||||
|
||||
pub fn generate_descriptor_wallet(xprv_input: Option<String>) -> Result<WalletDescriptors> {
|
||||
pub fn get_wallet_xprv(xprv_input: Option<String>) -> Result<ExtendedPrivKey> {
|
||||
let xprv: ExtendedPrivKey;
|
||||
let network: Network = Network::Testnet;
|
||||
|
||||
@ -30,13 +29,7 @@ pub fn generate_descriptor_wallet(xprv_input: Option<String>) -> Result<WalletDe
|
||||
dbg!("Generated xprv: ", xprv.to_string());
|
||||
}
|
||||
|
||||
let (descriptor, key_map, _) = Bip86(xprv, KeychainKind::External).build(network).unwrap();
|
||||
let (change_descriptor, change_key_map, _) = Bip86(xprv, KeychainKind::Internal).build(network)?;
|
||||
let descriptors = WalletDescriptors {
|
||||
descriptor,
|
||||
change_descriptor: Some(change_descriptor)
|
||||
};
|
||||
Ok(descriptors)
|
||||
Ok(xprv)
|
||||
}
|
||||
|
||||
pub fn load_wallet(trader_config: &TraderSettings) -> Result<Wallet<MemoryDatabase>> {
|
||||
@ -44,8 +37,8 @@ pub fn load_wallet(trader_config: &TraderSettings) -> Result<Wallet<MemoryDataba
|
||||
let blockchain = ElectrumBlockchain::from(client);
|
||||
|
||||
let wallet = Wallet::new(
|
||||
trader_config.funded_wallet_descriptor.descriptor.clone(),
|
||||
trader_config.funded_wallet_descriptor.change_descriptor.clone(),
|
||||
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
|
||||
)?;
|
||||
|
Reference in New Issue
Block a user