mirror of
https://github.com/RoboSats/taptrade-core.git
synced 2025-07-21 10:13:23 +00:00
fix taker bond validation endpoint
This commit is contained in:
@ -26,7 +26,7 @@ async fn receive_order(
|
|||||||
Extension(wallet): Extension<Arc<CoordinatorWallet>>,
|
Extension(wallet): Extension<Arc<CoordinatorWallet>>,
|
||||||
Json(order): Json<OrderRequest>,
|
Json(order): Json<OrderRequest>,
|
||||||
) -> Result<Json<BondRequirementResponse>, AppError> {
|
) -> Result<Json<BondRequirementResponse>, AppError> {
|
||||||
dbg!(&order);
|
debug!("{:#?}", &order);
|
||||||
if order.sanity_check().is_err() {
|
if order.sanity_check().is_err() {
|
||||||
return Err(AppError(anyhow!("Invalid order request")));
|
return Err(AppError(anyhow!("Invalid order request")));
|
||||||
}
|
}
|
||||||
@ -64,11 +64,11 @@ async fn submit_maker_bond(
|
|||||||
{
|
{
|
||||||
Ok(()) => (),
|
Ok(()) => (),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
dbg!(e);
|
error!("{}", e);
|
||||||
return Ok(StatusCode::NOT_ACCEPTABLE.into_response());
|
return Ok(StatusCode::NOT_ACCEPTABLE.into_response());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
trace!("\nBond validation successful");
|
debug!("\nBond validation successful");
|
||||||
let offer_id_hex: String = generate_random_order_id(16); // 16 bytes random offer id, maybe a different system makes more sense later on? (uuid or increasing counter...)
|
let offer_id_hex: String = generate_random_order_id(16); // 16 bytes random offer id, maybe a different system makes more sense later on? (uuid or increasing counter...)
|
||||||
// create address for taker bond
|
// create address for taker bond
|
||||||
let new_taker_bond_address = wallet.get_new_address().await.context(format!(
|
let new_taker_bond_address = wallet.get_new_address().await.context(format!(
|
||||||
@ -117,22 +117,26 @@ async fn submit_taker_bond(
|
|||||||
let bond_requirements = database
|
let bond_requirements = database
|
||||||
.fetch_taker_bond_requirements(&payload.offer.offer_id_hex)
|
.fetch_taker_bond_requirements(&payload.offer.offer_id_hex)
|
||||||
.await;
|
.await;
|
||||||
// match bond_requirements {
|
match bond_requirements {
|
||||||
// Ok(bond_requirements) => {
|
Ok(bond_requirements) => {
|
||||||
// if !wallet
|
match wallet
|
||||||
// .validate_bond_tx_hex(&payload.trade_data.signed_bond_hex, &bond_requirements)
|
.validate_bond_tx_hex(&payload.trade_data.signed_bond_hex, &bond_requirements)
|
||||||
// .await?
|
.await
|
||||||
// {
|
{
|
||||||
// dbg!("Taker Bond validation failed");
|
Ok(()) => (),
|
||||||
// return Ok(StatusCode::NOT_ACCEPTABLE.into_response());
|
Err(e) => {
|
||||||
// }
|
warn!("{}", e);
|
||||||
// }
|
return Ok(StatusCode::NOT_ACCEPTABLE.into_response());
|
||||||
// Err(_) => return Ok(StatusCode::NOT_FOUND.into_response()),
|
}
|
||||||
// }
|
}
|
||||||
|
}
|
||||||
|
Err(_) => return Ok(StatusCode::NOT_FOUND.into_response()),
|
||||||
|
}
|
||||||
|
debug!("\nTaker bond validation successful");
|
||||||
|
|
||||||
|
panic!("Trade contract PSBT not implemented!");
|
||||||
let trade_contract_psbt_taker = "".to_string(); // implement psbt
|
let trade_contract_psbt_taker = "".to_string(); // implement psbt
|
||||||
let trade_contract_psbt_maker = "".to_string(); // implement psbt
|
let trade_contract_psbt_maker = "".to_string(); // implement psbt
|
||||||
panic!("Trade contract PSBT not implemented!");
|
|
||||||
|
|
||||||
database
|
database
|
||||||
.add_taker_info_and_move_table(
|
.add_taker_info_and_move_table(
|
||||||
|
@ -281,18 +281,19 @@ impl CoordinatorDB {
|
|||||||
pub async fn fetch_taker_bond_requirements(
|
pub async fn fetch_taker_bond_requirements(
|
||||||
&self,
|
&self,
|
||||||
offer_id_hex: &String,
|
offer_id_hex: &String,
|
||||||
) -> Result<BondRequirementResponse> {
|
) -> Result<BondRequirements> {
|
||||||
let taker_bond_requirements = sqlx::query(
|
let taker_bond_requirements = sqlx::query(
|
||||||
"SELECT taker_bond_address, bond_amount_sat FROM active_maker_offers WHERE offer_id = ?",
|
"SELECT taker_bond_address, bond_amount_sat, amount_sat FROM active_maker_offers WHERE offer_id = ?",
|
||||||
)
|
)
|
||||||
.bind(offer_id_hex)
|
.bind(offer_id_hex)
|
||||||
.fetch_one(&*self.db_pool)
|
.fetch_one(&*self.db_pool)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(BondRequirementResponse {
|
Ok(BondRequirements {
|
||||||
bond_address: taker_bond_requirements.try_get("taker_bond_address")?,
|
bond_address: taker_bond_requirements.try_get("taker_bond_address")?,
|
||||||
locking_amount_sat: taker_bond_requirements.try_get::<i64, _>("bond_amount_sat")?
|
locking_amount_sat: taker_bond_requirements.try_get::<i64, _>("bond_amount_sat")?
|
||||||
as u64,
|
as u64,
|
||||||
|
min_input_sum_sat: taker_bond_requirements.try_get::<i64, _>("amount_sat")? as u64,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user