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 serde::{Deserialize, Serialize};
use serde_with::{serde_as, DeserializeAs, SerializeAs};
use std::cmp::Ordering;
use std::str::FromStr;
use sqlx::{Row, SqlitePool};
use std::cmp::Ordering;
use std::collections::{HashMap, HashSet};
use std::str::FromStr;
use std::sync::LazyLock;
/// `serde_with` adapter that (de)serializes a malachite [`Integer`] as a decimal
@ -584,7 +584,10 @@ fn build_partial_offering_initiator_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();
bytecode.extend_from_slice(&bigint_to_push_opcode(permanentLiquidityShare));
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;
// preinit_parameters.offeredTokenTotalSupply < Integer::from(0)
let offered_token_is_in_supply =
vm_number_to_bigint(&data[170..178]) < 0;
let offered_token_is_in_supply = vm_number_to_bigint(&data[170..178]) < 0;
let offeringBcmrStorageOut = tx.output.get(8);
if offeringBcmrStorageOut.is_none() {
@ -1305,9 +1307,7 @@ fn parse_ido_preinit_tx_params(
discountAnnualRateNumerator: vm_number_to_bigint(&data[106..110]),
priceNumerator: vm_number_to_bigint(&data[110..126]),
minOffer: vm_number_to_bigint(&data[126..130]),
xTokenCategory: if vm_number_to_bigint(&data[130..162])
== 0
{
xTokenCategory: if vm_number_to_bigint(&data[130..162]) == 0 {
None
} else {
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 {
// output#0 should contain a token with offering_token_id
let first_output = tx
.output.first()
.output
.first()
.ok_or_else(|| anyhow::anyhow!("Should have first output!"))?;
if first_output.token.is_none()
|| 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
let owner_nfthash;
let first_input = tx
.input.first()
.input
.first()
.ok_or_else(|| anyhow::anyhow!("Should have first input!"))?;
let instructions: Vec<_> = first_input.script_sig.instructions().collect();
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
let first_output = tx
.output.first()
.output
.first()
.ok_or_else(|| anyhow::anyhow!("Should have first output!"))?;
if first_output.token.is_none()
|| first_output.token.as_ref().unwrap().id.to_blob()
@ -2428,7 +2431,8 @@ fn ido_add_tx(context: &IdoContext, tx: &Transaction) -> Result<IdoAddResult> {
}
"POSTLAUNCH" => {
let pp_output = tx
.output.first()
.output
.first()
.ok_or_else(|| anyhow::anyhow!("Should have first output!"))?;
let collector_p2nfth = tx
.output
@ -2478,12 +2482,10 @@ fn ido_add_tx(context: &IdoContext, tx: &Transaction) -> Result<IdoAddResult> {
next_output_index: -1,
})
}
_ => {
Err(anyhow::anyhow!(
_ => Err(anyhow::anyhow!(
"An ido with an unknown status: {}",
context.status
))
}
)),
}
}
@ -2716,7 +2718,8 @@ async fn on_add_ido_tx(
items_tx_map.insert(item.txid.clone(), tx_deser);
}
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"))?
.txid
!= ido.preinit_txid
@ -2818,8 +2821,7 @@ async fn on_add_ido_tx(
fn is_ido_sig_in_tx_inputs(tx: &Transaction) -> bool {
for input_index in [0, 1] {
let input = tx.input.get(input_index);
if input.is_some()
&& has_script_ido_signature(&input.unwrap().script_sig) {
if input.is_some() && has_script_ido_signature(&input.unwrap().script_sig) {
return true;
}
}