mirror of
https://github.com/RoboSats/taptrade-core.git
synced 2025-07-21 10:13:23 +00:00
finish submit_maker_bond endpoint coordinator
This commit is contained in:
@ -4,6 +4,7 @@ mod utils;
|
|||||||
use self::api::*;
|
use self::api::*;
|
||||||
use self::utils::*;
|
use self::utils::*;
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use crate::wallet::*;
|
||||||
use axum::{
|
use axum::{
|
||||||
http::StatusCode,
|
http::StatusCode,
|
||||||
response::{IntoResponse, Response},
|
response::{IntoResponse, Response},
|
||||||
@ -14,7 +15,6 @@ use rand::Rng;
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
use tokio::net::TcpListener;
|
use tokio::net::TcpListener;
|
||||||
// use crate::coordinator::verify_psbt;
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Axum handler functions
|
// Axum handler functions
|
||||||
@ -46,17 +46,27 @@ async fn submit_maker_bond(
|
|||||||
Extension(wallet): Extension<CoordinatorWallet>,
|
Extension(wallet): Extension<CoordinatorWallet>,
|
||||||
Json(payload): Json<BondSubmissionRequest>,
|
Json(payload): Json<BondSubmissionRequest>,
|
||||||
) -> Result<Response, AppError> {
|
) -> Result<Response, AppError> {
|
||||||
let bond_requirements = database.fetch_maker_request(&payload.robohash_hex).await?;
|
let bond_requirements = if let Ok(requirements) = database
|
||||||
|
.fetch_bond_requirements(&payload.robohash_hex)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
requirements
|
||||||
|
} else {
|
||||||
|
return Ok(StatusCode::NOT_FOUND.into_response());
|
||||||
|
};
|
||||||
|
|
||||||
// validate bond (check amounts, valid inputs, correct addresses, valid signature, feerate)
|
match wallet
|
||||||
// if !wallet
|
.validate_bond_tx_hex(&payload.signed_bond_hex, bond_requirements)
|
||||||
// .validate_bond_tx_hex(&payload.signed_bond_hex)
|
.await
|
||||||
// .await?
|
{
|
||||||
// {
|
Ok(()) => (),
|
||||||
// return Ok(StatusCode::NOT_ACCEPTABLE.into_response());
|
Err(e) => {
|
||||||
// }
|
dbg!(e);
|
||||||
let offer_id_hex = generate_random_order_id(16); // 16 bytes random offer id, maybe a different system makes more sense later on? (uuid or increasing counter...)
|
return Ok(StatusCode::NOT_ACCEPTABLE.into_response());
|
||||||
// create address for taker bond
|
}
|
||||||
|
}
|
||||||
|
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
|
||||||
let new_taker_bond_address = wallet.get_new_address().await?;
|
let new_taker_bond_address = wallet.get_new_address().await?;
|
||||||
// insert bond into sql database and move offer to different table
|
// insert bond into sql database and move offer to different table
|
||||||
let bond_locked_until_timestamp = database
|
let bond_locked_until_timestamp = database
|
||||||
|
@ -146,17 +146,18 @@ impl CoordinatorDB {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn fetch_maker_request(&self, robohash: &String) -> Result<BondRequirementResponse> {
|
pub async fn fetch_bond_requirements(&self, robohash: &String) -> Result<BondRequirements> {
|
||||||
let maker_request = sqlx::query(
|
let maker_request = sqlx::query(
|
||||||
"SELECT bond_address, bond_amount_sat FROM maker_requests WHERE robohash = ?",
|
"SELECT bond_address, bond_amount_sat, amount_sat FROM maker_requests WHERE robohash = ?",
|
||||||
)
|
)
|
||||||
.bind(hex::decode(robohash)?)
|
.bind(hex::decode(robohash)?)
|
||||||
.fetch_one(&*self.db_pool)
|
.fetch_one(&*self.db_pool)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(BondRequirementResponse {
|
Ok(BondRequirements {
|
||||||
bond_address: maker_request.try_get("bond_address")?,
|
bond_address: maker_request.try_get("bond_address")?,
|
||||||
locking_amount_sat: maker_request.try_get::<i64, _>("bond_amount_sat")? as u64,
|
locking_amount_sat: maker_request.try_get::<i64, _>("bond_amount_sat")? as u64,
|
||||||
|
min_input_sum_sat: maker_request.try_get::<i64, _>("amount_sat")? as u64,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ use dotenv::dotenv;
|
|||||||
use std::time::{SystemTime, UNIX_EPOCH};
|
use std::time::{SystemTime, UNIX_EPOCH};
|
||||||
use std::{env, sync::Arc};
|
use std::{env, sync::Arc};
|
||||||
use tokio::sync::Mutex;
|
use tokio::sync::Mutex;
|
||||||
use wallet::CoordinatorWallet;
|
use wallet::*;
|
||||||
|
|
||||||
// populate .env with values before starting
|
// populate .env with values before starting
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
|
Reference in New Issue
Block a user