From 0b936deca89ab5478eecc180ca768c42bcbf661a Mon Sep 17 00:00:00 2001 From: Sosthene Date: Sat, 24 Jan 2026 18:33:29 +0100 Subject: [PATCH] feat: Replace SpendStatus with SpendInfo --- spdk-core/src/client/spend.rs | 15 ++-------- spdk-core/src/client/structs.rs | 49 ++++++++++++++++++++++++++------ spdk-core/src/scanner/scanner.rs | 5 ++-- 3 files changed, 46 insertions(+), 23 deletions(-) diff --git a/spdk-core/src/client/spend.rs b/spdk-core/src/client/spend.rs index 22cdfbb..6bb2df7 100644 --- a/spdk-core/src/client/spend.rs +++ b/spdk-core/src/client/spend.rs @@ -23,10 +23,7 @@ use anyhow::{Error, Result}; use crate::constants::{DATA_CARRIER_SIZE, NUMS}; -use super::{ - OutputSpendStatus, OwnedOutput, Recipient, RecipientAddress, SilentPaymentUnsignedTransaction, - SpClient, -}; +use super::{OwnedOutput, Recipient, RecipientAddress, SilentPaymentUnsignedTransaction, SpClient}; impl SpClient { // For now it's only suitable for wallet that spends only silent payments outputs that it owns @@ -38,10 +35,7 @@ impl SpClient { network: Network, ) -> Result { // check that all available outputs are unspent - if available_utxos - .iter() - .any(|(_, o)| o.spend_status != OutputSpendStatus::Unspent) - { + if available_utxos.iter().any(|(_, o)| !o.is_unspent()) { return Err(Error::msg("All outputs must be unspent".to_string())); } @@ -173,10 +167,7 @@ impl SpClient { network: Network, ) -> Result { // check that all available outputs are unspent - if available_utxos - .iter() - .any(|(_, o)| o.spend_status != OutputSpendStatus::Unspent) - { + if available_utxos.iter().any(|(_, o)| !o.is_unspent()) { return Err(Error::msg("All outputs must be unspent".to_string())); } diff --git a/spdk-core/src/client/structs.rs b/spdk-core/src/client/structs.rs index d942296..54cec73 100644 --- a/spdk-core/src/client/structs.rs +++ b/spdk-core/src/client/structs.rs @@ -7,19 +7,36 @@ use bitcoin::{ hex::{DisplayHex, FromHex}, key::Secp256k1, secp256k1::{PublicKey, SecretKey}, - Address, Amount, Network, OutPoint, ScriptBuf, Transaction, + Address, Amount, BlockHash, Network, OutPoint, ScriptBuf, Transaction, Txid, }; use serde::{Deserialize, Serialize}; use silentpayments::{receiving::Label, SilentPaymentAddress}; -type SpendingTxId = [u8; 32]; -type MinedInBlock = [u8; 32]; +#[derive(Default, Debug, Serialize, Deserialize, Clone, PartialEq)] +pub struct SpendInfo { + pub spending_txid: Option, + pub mined_in_block: Option, +} -#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)] -pub enum OutputSpendStatus { - Unspent, - Spent(SpendingTxId), - Mined(MinedInBlock), +impl SpendInfo { + pub fn new_empty() -> Self { + Self { + spending_txid: None, + mined_in_block: None, + } + } + + pub fn is_unspent(&self) -> bool { + self.spending_txid.is_none() && self.mined_in_block.is_none() + } + + pub fn is_spent_unconfirmed(&self) -> bool { + self.spending_txid.is_some() && self.mined_in_block.is_none() + } + + pub fn is_mined(&self) -> bool { + self.mined_in_block.is_some() + } } #[derive(Debug, Serialize, Deserialize, Clone, PartialEq)] @@ -29,7 +46,21 @@ pub struct OwnedOutput { pub amount: Amount, pub script: ScriptBuf, pub label: Option