format ido

This commit is contained in:
Hossein Zoda 2026-06-21 01:43:20 +03:00
parent 0aa4d1c530
commit 5f49ad75c0
4 changed files with 1112 additions and 590 deletions

File diff suppressed because it is too large Load diff

View file

@ -16,9 +16,9 @@ use crate::db::cauldron::config::check_db_version;
use crate::db::cauldron::prepare_tables as cauldron_prepare_tables; use crate::db::cauldron::prepare_tables as cauldron_prepare_tables;
use crate::db::cauldron::tokentoken::create_table as tokentoken_prepare_tables; use crate::db::cauldron::tokentoken::create_table as tokentoken_prepare_tables;
use crate::db::crc20::prepare_tables as crc20_prepare_tables; use crate::db::crc20::prepare_tables as crc20_prepare_tables;
use crate::db::ido::prepare_tables as ido_prepare_tables;
use crate::db::moria::prepare_tables as moria_prepare_tables; use crate::db::moria::prepare_tables as moria_prepare_tables;
use crate::db::oracle::prepare_tables as oracle_prepare_tables; use crate::db::oracle::prepare_tables as oracle_prepare_tables;
use crate::db::ido::prepare_tables as ido_prepare_tables;
/// Create read and write database pools for a given database path /// Create read and write database pools for a given database path
async fn create_db_pool(db_path: &str, read_max_size: u32) -> (bool, SqlitePool, SqlitePool) { async fn create_db_pool(db_path: &str, read_max_size: u32) -> (bool, SqlitePool, SqlitePool) {

View file

@ -41,7 +41,9 @@ pub fn electrum_get_tip(client: &Client) -> Result<(BlockHeader, u64)> {
} }
/// Fetch defi (cauldron + tokentoken) and oracle mempool transactions /// Fetch defi (cauldron + tokentoken) and oracle mempool transactions
pub fn electrum_fetch_mempool(client: &Client) -> Result<(HashSet<Txid>, HashSet<Txid>, HashSet<Txid>)> { pub fn electrum_fetch_mempool(
client: &Client,
) -> Result<(HashSet<Txid>, HashSet<Txid>, HashSet<Txid>)> {
let cauldron_filter = json!({ let cauldron_filter = json!({
"scriptsig": hex::encode(&V2_CONTRACT_TEMPLATE[(V2_CONTRACT_TEMPLATE.len() - 43)..]), // cauldron spends "scriptsig": hex::encode(&V2_CONTRACT_TEMPLATE[(V2_CONTRACT_TEMPLATE.len() - 43)..]), // cauldron spends
"scriptpubkey": hex::encode([0x6a /* op_return */, 0x06 /* push */, b'S', b'U', b'M', b'M', b'O', b'N']), // new pools (potentially) "scriptpubkey": hex::encode([0x6a /* op_return */, 0x06 /* push */, b'S', b'U', b'M', b'M', b'O', b'N']), // new pools (potentially)

View file

@ -54,8 +54,14 @@ pub async fn list_idos(
}) })
.transpose()?; .transpose()?;
let items = let items = crate::db::ido::list_idos(
crate::db::ido::list_idos(&db.ido_r, is_valid, status, offered_token_id_blob, offset, limit) &db.ido_r,
is_valid,
status,
offered_token_id_blob,
offset,
limit,
)
.await .await
.map_err(db_error)?; .map_err(db_error)?;
@ -64,10 +70,7 @@ pub async fn list_idos(
/// Get a single IDO by id token ID. Returns null if not found. /// Get a single IDO by id token ID. Returns null if not found.
#[get("/by-id/<id>")] #[get("/by-id/<id>")]
pub async fn get_ido_by_id( pub async fn get_ido_by_id(id: &str, db: &State<DB>) -> CachedApiResult<Value> {
id: &str,
db: &State<DB>,
) -> CachedApiResult<Value> {
let blob = display_hex_to_blob::<TokenID>(id).map_err(|e| { let blob = display_hex_to_blob::<TokenID>(id).map_err(|e| {
bad_request( bad_request(
ApiErrorCode::InvalidParameters, ApiErrorCode::InvalidParameters,
@ -112,7 +115,11 @@ fn parse_owner_nfthash_filters(
return Ok(Vec::new()); return Ok(Vec::new());
}; };
let parts: Vec<&str> = raw.split(',').map(|s| s.trim()).filter(|s| !s.is_empty()).collect(); let parts: Vec<&str> = raw
.split(',')
.map(|s| s.trim())
.filter(|s| !s.is_empty())
.collect();
if parts.len() > MAX_OWNER_NFTHASH_FILTERS { if parts.len() > MAX_OWNER_NFTHASH_FILTERS {
return Err(bad_request( return Err(bad_request(
ApiErrorCode::InvalidParameters, ApiErrorCode::InvalidParameters,
@ -168,7 +175,15 @@ pub async fn list_ido_entries(
let (internal_id, preinit_txid_hex) = resolve_ido(id, &db.ido_r).await?; let (internal_id, preinit_txid_hex) = resolve_ido(id, &db.ido_r).await?;
let items = crate::db::ido::list_ido_entries(&db.ido_r, internal_id, &preinit_txid_hex, distributed, &owner_nfthashes, offset, limit) let items = crate::db::ido::list_ido_entries(
&db.ido_r,
internal_id,
&preinit_txid_hex,
distributed,
&owner_nfthashes,
offset,
limit,
)
.await .await
.map_err(db_error)?; .map_err(db_error)?;
@ -178,10 +193,7 @@ pub async fn list_ido_entries(
/// Get the raw transaction hex for a txchain item by its txid. /// Get the raw transaction hex for a txchain item by its txid.
/// Returns `{"tx": "<hex>"}` or `{"tx": null}` if not found. /// Returns `{"tx": "<hex>"}` or `{"tx": null}` if not found.
#[get("/txchain/<txid>/tx")] #[get("/txchain/<txid>/tx")]
pub async fn get_txchain_tx( pub async fn get_txchain_tx(txid: &str, db: &State<DB>) -> CachedApiResult<Value> {
txid: &str,
db: &State<DB>,
) -> CachedApiResult<Value> {
let txid_blob = display_hex_to_blob::<Txid>(txid).map_err(|e| { let txid_blob = display_hex_to_blob::<Txid>(txid).map_err(|e| {
bad_request( bad_request(
ApiErrorCode::InvalidParameters, ApiErrorCode::InvalidParameters,
@ -193,10 +205,7 @@ pub async fn get_txchain_tx(
.await .await
.map_err(db_error)?; .map_err(db_error)?;
Ok(cached_ok( Ok(cached_ok(serde_json::json!({ "tx": tx_hex }), CACHE_NONE))
serde_json::json!({ "tx": tx_hex }),
CACHE_NONE,
))
} }
/// [Debug] List the txchain for an IDO, sorted oldest-first (head is last). /// [Debug] List the txchain for an IDO, sorted oldest-first (head is last).
@ -212,11 +221,14 @@ pub async fn list_ido_txchain(
db: &State<DB>, db: &State<DB>,
) -> CachedApiResult<Value> { ) -> CachedApiResult<Value> {
let offset = offset.unwrap_or(0).max(0); let offset = offset.unwrap_or(0).max(0);
let limit = limit.unwrap_or(DEBUG_DEFAULT_LIMIT).clamp(1, DEBUG_MAX_LIMIT); let limit = limit
.unwrap_or(DEBUG_DEFAULT_LIMIT)
.clamp(1, DEBUG_MAX_LIMIT);
let (internal_id, preinit_txid_hex) = resolve_ido(id, &db.ido_r).await?; let (internal_id, preinit_txid_hex) = resolve_ido(id, &db.ido_r).await?;
let items = crate::db::ido::list_ido_txchain(&db.ido_r, internal_id, &preinit_txid_hex, offset, limit) let items =
crate::db::ido::list_ido_txchain(&db.ido_r, internal_id, &preinit_txid_hex, offset, limit)
.await .await
.map_err(db_error)?; .map_err(db_error)?;
@ -239,8 +251,12 @@ async fn resolve_ido(
.map_err(db_error)? .map_err(db_error)?
.ok_or_else(|| not_found(ApiErrorCode::IdoNotFound, "IDO not found"))?; .ok_or_else(|| not_found(ApiErrorCode::IdoNotFound, "IDO not found"))?;
let preinit_txid_hex = blob_to_display_hex::<Txid>(&preinit_blob) let preinit_txid_hex = blob_to_display_hex::<Txid>(&preinit_blob).map_err(|e| {
.map_err(|e| bad_request(ApiErrorCode::InvalidParameters, &format!("Invalid IDO id: {e}")))?; bad_request(
ApiErrorCode::InvalidParameters,
&format!("Invalid IDO id: {e}"),
)
})?;
Ok((internal_id, preinit_txid_hex)) Ok((internal_id, preinit_txid_hex))
} }
@ -255,7 +271,9 @@ pub async fn list_txchain_tracker_map(
db: &State<DB>, db: &State<DB>,
) -> CachedApiResult<Value> { ) -> CachedApiResult<Value> {
let offset = offset.unwrap_or(0).max(0); let offset = offset.unwrap_or(0).max(0);
let limit = limit.unwrap_or(DEBUG_DEFAULT_LIMIT).clamp(1, DEBUG_MAX_LIMIT); let limit = limit
.unwrap_or(DEBUG_DEFAULT_LIMIT)
.clamp(1, DEBUG_MAX_LIMIT);
let items = crate::db::ido::list_txchain_tracker_map(&db.ido_r, offset, limit) let items = crate::db::ido::list_txchain_tracker_map(&db.ido_r, offset, limit)
.await .await