This commit is contained in:
Hossein Zoda 2026-06-22 10:48:08 +00:00
parent c7a9e9bea6
commit e2f72e608e

View file

@ -20,10 +20,10 @@ use malachite::base::num::conversion::traits::PowerOf2Digits;
use malachite::{Integer, Natural}; use malachite::{Integer, Natural};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_with::{serde_as, DeserializeAs, SerializeAs}; use serde_with::{serde_as, DeserializeAs, SerializeAs};
use std::cmp::Ordering;
use std::str::FromStr;
use sqlx::{Row, SqlitePool}; use sqlx::{Row, SqlitePool};
use std::cmp::Ordering;
use std::collections::{HashMap, HashSet}; use std::collections::{HashMap, HashSet};
use std::str::FromStr;
use std::sync::LazyLock; use std::sync::LazyLock;
/// `serde_with` adapter that (de)serializes a malachite [`Integer`] as a decimal /// `serde_with` adapter that (de)serializes a malachite [`Integer`] as a decimal
@ -584,7 +584,10 @@ fn build_partial_offering_initiator_bytecode(
bytecode bytecode
} }
fn build_partial_postlaunch_bytecode(permanentLiquidityShare: &Integer, price: &Integer) -> Vec<u8> { fn build_partial_postlaunch_bytecode(
permanentLiquidityShare: &Integer,
price: &Integer,
) -> Vec<u8> {
let mut bytecode = Vec::new(); let mut bytecode = Vec::new();
bytecode.extend_from_slice(&bigint_to_push_opcode(permanentLiquidityShare)); bytecode.extend_from_slice(&bigint_to_push_opcode(permanentLiquidityShare));
bytecode.extend_from_slice(&bigint_to_push_opcode(price)); bytecode.extend_from_slice(&bigint_to_push_opcode(price));
@ -1243,8 +1246,7 @@ fn parse_ido_preinit_tx_params(
} }
let mut is_valid_ido = true; let mut is_valid_ido = true;
// preinit_parameters.offeredTokenTotalSupply < Integer::from(0) // preinit_parameters.offeredTokenTotalSupply < Integer::from(0)
let offered_token_is_in_supply = let offered_token_is_in_supply = vm_number_to_bigint(&data[170..178]) < 0;
vm_number_to_bigint(&data[170..178]) < 0;
let offeringBcmrStorageOut = tx.output.get(8); let offeringBcmrStorageOut = tx.output.get(8);
if offeringBcmrStorageOut.is_none() { if offeringBcmrStorageOut.is_none() {
@ -1305,9 +1307,7 @@ fn parse_ido_preinit_tx_params(
discountAnnualRateNumerator: vm_number_to_bigint(&data[106..110]), discountAnnualRateNumerator: vm_number_to_bigint(&data[106..110]),
priceNumerator: vm_number_to_bigint(&data[110..126]), priceNumerator: vm_number_to_bigint(&data[110..126]),
minOffer: vm_number_to_bigint(&data[126..130]), minOffer: vm_number_to_bigint(&data[126..130]),
xTokenCategory: if vm_number_to_bigint(&data[130..162]) xTokenCategory: if vm_number_to_bigint(&data[130..162]) == 0 {
== 0
{
None None
} else { } else {
Some(data[130..162].to_vec()) Some(data[130..162].to_vec())
@ -2181,7 +2181,8 @@ fn ido_add_tx(context: &IdoContext, tx: &Transaction) -> Result<IdoAddResult> {
if let IdoState::Active(ref active_state) = context.state { if let IdoState::Active(ref active_state) = context.state {
// output#0 should contain a token with offering_token_id // output#0 should contain a token with offering_token_id
let first_output = tx let first_output = tx
.output.first() .output
.first()
.ok_or_else(|| anyhow::anyhow!("Should have first output!"))?; .ok_or_else(|| anyhow::anyhow!("Should have first output!"))?;
if first_output.token.is_none() if first_output.token.is_none()
|| first_output.token.as_ref().unwrap().id.to_blob() || first_output.token.as_ref().unwrap().id.to_blob()
@ -2221,7 +2222,8 @@ fn ido_add_tx(context: &IdoContext, tx: &Transaction) -> Result<IdoAddResult> {
// pull owner_nfthash from unlocking bytecode of input#0 // pull owner_nfthash from unlocking bytecode of input#0
let owner_nfthash; let owner_nfthash;
let first_input = tx let first_input = tx
.input.first() .input
.first()
.ok_or_else(|| anyhow::anyhow!("Should have first input!"))?; .ok_or_else(|| anyhow::anyhow!("Should have first input!"))?;
let instructions: Vec<_> = first_input.script_sig.instructions().collect(); let instructions: Vec<_> = first_input.script_sig.instructions().collect();
if instructions.is_empty() { if instructions.is_empty() {
@ -2349,7 +2351,8 @@ fn ido_add_tx(context: &IdoContext, tx: &Transaction) -> Result<IdoAddResult> {
} }
// output#0 should contain a token with offering_token_id // output#0 should contain a token with offering_token_id
let first_output = tx let first_output = tx
.output.first() .output
.first()
.ok_or_else(|| anyhow::anyhow!("Should have first output!"))?; .ok_or_else(|| anyhow::anyhow!("Should have first output!"))?;
if first_output.token.is_none() if first_output.token.is_none()
|| first_output.token.as_ref().unwrap().id.to_blob() || first_output.token.as_ref().unwrap().id.to_blob()
@ -2428,7 +2431,8 @@ fn ido_add_tx(context: &IdoContext, tx: &Transaction) -> Result<IdoAddResult> {
} }
"POSTLAUNCH" => { "POSTLAUNCH" => {
let pp_output = tx let pp_output = tx
.output.first() .output
.first()
.ok_or_else(|| anyhow::anyhow!("Should have first output!"))?; .ok_or_else(|| anyhow::anyhow!("Should have first output!"))?;
let collector_p2nfth = tx let collector_p2nfth = tx
.output .output
@ -2478,12 +2482,10 @@ fn ido_add_tx(context: &IdoContext, tx: &Transaction) -> Result<IdoAddResult> {
next_output_index: -1, next_output_index: -1,
}) })
} }
_ => { _ => Err(anyhow::anyhow!(
Err(anyhow::anyhow!(
"An ido with an unknown status: {}", "An ido with an unknown status: {}",
context.status context.status
)) )),
}
} }
} }
@ -2716,7 +2718,8 @@ async fn on_add_ido_tx(
items_tx_map.insert(item.txid.clone(), tx_deser); items_tx_map.insert(item.txid.clone(), tx_deser);
} }
let new_chain = reconstruct_txchain(&items_by_id, Some(prev_txchain_item.id)); let new_chain = reconstruct_txchain(&items_by_id, Some(prev_txchain_item.id));
if new_chain.first() if new_chain
.first()
.ok_or_else(|| anyhow::anyhow!("txchain is empty"))? .ok_or_else(|| anyhow::anyhow!("txchain is empty"))?
.txid .txid
!= ido.preinit_txid != ido.preinit_txid
@ -2818,8 +2821,7 @@ async fn on_add_ido_tx(
fn is_ido_sig_in_tx_inputs(tx: &Transaction) -> bool { fn is_ido_sig_in_tx_inputs(tx: &Transaction) -> bool {
for input_index in [0, 1] { for input_index in [0, 1] {
let input = tx.input.get(input_index); let input = tx.input.get(input_index);
if input.is_some() if input.is_some() && has_script_ido_signature(&input.unwrap().script_sig) {
&& has_script_ido_signature(&input.unwrap().script_sig) {
return true; return true;
} }
} }