Skip to main content

rgb_lib/database/
enums.rs

1use super::*;
2
3/// The schema of an asset.
4#[derive(
5    Debug, Clone, Copy, PartialEq, Eq, Hash, Deserialize, Serialize, EnumIter, DeriveActiveEnum,
6)]
7#[sea_orm(rs_type = "u8", db_type = "TinyUnsigned")]
8pub enum AssetSchema {
9    /// NIA schema
10    #[sea_orm(num_value = 1)]
11    Nia = 1,
12    /// UDA schema
13    #[sea_orm(num_value = 2)]
14    Uda = 2,
15    /// CFA schema
16    #[sea_orm(num_value = 3)]
17    Cfa = 3,
18    /// IFA schema
19    #[sea_orm(num_value = 4)]
20    Ifa = 4,
21}
22
23impl fmt::Display for AssetSchema {
24    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
25        write!(f, "{self:?}")
26    }
27}
28
29impl TryFrom<String> for AssetSchema {
30    type Error = Error;
31
32    fn try_from(schema_id: String) -> Result<Self, Self::Error> {
33        Ok(match &schema_id[..] {
34            SCHEMA_ID_NIA => AssetSchema::Nia,
35            SCHEMA_ID_UDA => AssetSchema::Uda,
36            SCHEMA_ID_CFA => AssetSchema::Cfa,
37            SCHEMA_ID_IFA => AssetSchema::Ifa,
38            _ => return Err(Error::UnknownRgbSchema { schema_id }),
39        })
40    }
41}
42
43impl TryFrom<SchemaId> for AssetSchema {
44    type Error = Error;
45
46    fn try_from(schema_id: SchemaId) -> Result<Self, Self::Error> {
47        schema_id.to_string().try_into()
48    }
49}
50
51impl AssetSchema {
52    pub(crate) const VALUES: [Self; NUM_KNOWN_SCHEMAS] =
53        [Self::Nia, Self::Uda, Self::Cfa, Self::Ifa];
54
55    fn from_schema_id_str(schema_id: String) -> Result<Self, Error> {
56        Ok(match &schema_id[..] {
57            SCHEMA_ID_NIA => AssetSchema::Nia,
58            SCHEMA_ID_UDA => AssetSchema::Uda,
59            SCHEMA_ID_CFA => AssetSchema::Cfa,
60            SCHEMA_ID_IFA => AssetSchema::Ifa,
61            _ => return Err(Error::UnknownRgbSchema { schema_id }),
62        })
63    }
64
65    /// Get [`AssetSchema`] from [`SchemaId`].
66    pub fn from_schema_id(schema_id: SchemaId) -> Result<Self, Error> {
67        Self::from_schema_id_str(schema_id.to_string())
68    }
69
70    pub(crate) fn get_from_contract_id(
71        contract_id: ContractId,
72        runtime: &RgbRuntime,
73    ) -> Result<Self, Error> {
74        let schema_id = runtime.genesis(contract_id)?.schema_id;
75        Self::from_schema_id(schema_id)
76    }
77
78    fn schema(&self) -> Schema {
79        match self {
80            Self::Nia => NonInflatableAsset::schema(),
81            Self::Uda => UniqueDigitalAsset::schema(),
82            Self::Cfa => CollectibleFungibleAsset::schema(),
83            Self::Ifa => InflatableFungibleAsset::schema(),
84        }
85    }
86
87    fn scripts(&self) -> Scripts {
88        match self {
89            Self::Nia => NonInflatableAsset::scripts(),
90            Self::Uda => UniqueDigitalAsset::scripts(),
91            Self::Cfa => CollectibleFungibleAsset::scripts(),
92            Self::Ifa => InflatableFungibleAsset::scripts(),
93        }
94    }
95
96    pub(crate) fn types(&self) -> TypeSystem {
97        match self {
98            Self::Nia => NonInflatableAsset::types(),
99            Self::Uda => UniqueDigitalAsset::types(),
100            Self::Cfa => CollectibleFungibleAsset::types(),
101            Self::Ifa => InflatableFungibleAsset::types(),
102        }
103    }
104
105    pub(crate) fn import_kit(&self, runtime: &mut RgbRuntime) -> Result<(), Error> {
106        let schema = self.schema();
107        let lib = self.scripts();
108        let types = self.types();
109        let mut kit = Kit::default();
110        kit.schemata.push(schema).unwrap();
111        kit.scripts.extend(lib.into_values()).unwrap();
112        kit.types = types;
113        let valid_kit = kit.validate().map_err(|_| InternalError::Unexpected)?;
114        runtime.import_kit(valid_kit)?;
115        Ok(())
116    }
117}
118
119impl From<AssetSchema> for SchemaId {
120    fn from(asset_schema: AssetSchema) -> Self {
121        match asset_schema {
122            AssetSchema::Cfa => SchemaId::from_str(SCHEMA_ID_CFA).unwrap(),
123            AssetSchema::Ifa => SchemaId::from_str(SCHEMA_ID_IFA).unwrap(),
124            AssetSchema::Nia => SchemaId::from_str(SCHEMA_ID_NIA).unwrap(),
125            AssetSchema::Uda => SchemaId::from_str(SCHEMA_ID_UDA).unwrap(),
126        }
127    }
128}
129
130#[derive(Debug, Copy, Clone, PartialEq, Eq, EnumIter, DeriveActiveEnum)]
131#[sea_orm(rs_type = "u8", db_type = "TinyUnsigned")]
132pub enum ColoringType {
133    #[sea_orm(num_value = 1)]
134    Receive = 1,
135    #[sea_orm(num_value = 2)]
136    Issue = 2,
137    #[sea_orm(num_value = 3)]
138    Input = 3,
139    #[sea_orm(num_value = 4)]
140    Change = 4,
141}
142
143impl IntoActiveValue<ColoringType> for ColoringType {
144    fn into_active_value(self) -> ActiveValue<ColoringType> {
145        ActiveValue::Set(self)
146    }
147}
148
149/// The type of an RGB recipient.
150#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
151pub enum RecipientTypeFull {
152    /// Receive via blinded UTXO
153    Blind { unblinded_utxo: Outpoint },
154    /// Receive via witness TX
155    Witness { vout: Option<u32> },
156}
157
158impl From<RecipientTypeFull> for Value {
159    fn from(value: RecipientTypeFull) -> Self {
160        Value::Json(Some(Box::new(serde_json::to_value(value).unwrap())))
161    }
162}
163
164impl TryFrom<Value> for RecipientTypeFull {
165    type Error = sea_orm::DbErr;
166
167    fn try_from(v: Value) -> Result<Self, Self::Error> {
168        match v {
169            Value::Json(Some(json)) => {
170                serde_json::from_value(*json).map_err(|e| sea_orm::DbErr::Custom(e.to_string()))
171            }
172            _ => Err(sea_orm::DbErr::Type("Expected JSON value".into())),
173        }
174    }
175}
176
177impl rgb_lib_migration::ValueType for RecipientTypeFull {
178    fn type_name() -> String {
179        "json".to_string()
180    }
181
182    fn column_type() -> ColumnType {
183        ColumnType::Json
184    }
185
186    fn array_type() -> ArrayType {
187        ArrayType::Json
188    }
189
190    fn try_from(v: Value) -> Result<Self, ValueTypeErr> {
191        match v {
192            Value::Json(Some(json)) => serde_json::from_value(*json).map_err(|_| ValueTypeErr),
193            _ => Err(ValueTypeErr),
194        }
195    }
196}
197
198impl TryGetable for RecipientTypeFull {
199    fn try_get_by<I: sea_orm::ColIdx>(res: &QueryResult, index: I) -> Result<Self, TryGetError> {
200        let json_value_opt: Option<JsonValue> = res.try_get_by(index)?;
201        match json_value_opt {
202            Some(json_value) => serde_json::from_value(json_value)
203                .map_err(|e| TryGetError::DbErr(DbErr::Type(e.to_string()))),
204            None => Err(TryGetError::Null(
205                "Null value for RecipientTypeFull".to_string(),
206            )),
207        }
208    }
209}
210
211impl Nullable for RecipientTypeFull {
212    fn null() -> Value {
213        Value::Json(None)
214    }
215}
216
217/// The type of an RGB transport.
218#[derive(Debug, Copy, Clone, PartialEq, Eq, EnumIter, DeriveActiveEnum, Deserialize, Serialize)]
219#[sea_orm(rs_type = "u8", db_type = "TinyUnsigned")]
220pub enum TransportType {
221    /// HTTP(s) JSON-RPC ([specification](https://github.com/RGB-Tools/rgb-http-json-rpc))
222    #[sea_orm(num_value = 1)]
223    JsonRpc = 1,
224}
225
226/// The status of a [`crate::wallet::Transfer`].
227#[derive(
228    Debug,
229    Copy,
230    Clone,
231    PartialEq,
232    Eq,
233    PartialOrd,
234    Ord,
235    EnumIter,
236    DeriveActiveEnum,
237    Deserialize,
238    Serialize,
239)]
240#[sea_orm(rs_type = "u8", db_type = "TinyUnsigned")]
241pub enum TransferStatus {
242    /// Transfer has been initiated (PSBT prepared) but not yet finalized
243    #[sea_orm(num_value = 5)]
244    Initiated = 5,
245    /// Waiting for the counterparty to take action
246    #[sea_orm(num_value = 1)]
247    WaitingCounterparty = 1,
248    /// Waiting for safe height to be reached
249    #[sea_orm(num_value = 6)]
250    WaitingSafeHeight = 6,
251    /// Waiting for the transfer transaction to be broadcasted
252    #[sea_orm(num_value = 7)]
253    WaitingBroadcast = 7,
254    /// Waiting for the transfer transaction to reach the required number of confirmations
255    #[sea_orm(num_value = 2)]
256    WaitingConfirmations = 2,
257    /// Settled transfer, this status is final
258    #[sea_orm(num_value = 3)]
259    Settled = 3,
260    /// Failed transfer, this status is final
261    #[sea_orm(num_value = 4)]
262    Failed = 4,
263}
264
265impl TransferStatus {
266    pub(crate) fn failed(&self) -> bool {
267        self == &TransferStatus::Failed
268    }
269
270    pub(crate) fn initiated(&self) -> bool {
271        self == &TransferStatus::Initiated
272    }
273
274    pub(crate) fn pending(&self) -> bool {
275        [
276            TransferStatus::Initiated,
277            TransferStatus::WaitingCounterparty,
278            TransferStatus::WaitingSafeHeight,
279            TransferStatus::WaitingConfirmations,
280            TransferStatus::WaitingBroadcast,
281        ]
282        .contains(self)
283    }
284
285    #[cfg(any(feature = "electrum", feature = "esplora"))]
286    pub(crate) fn waiting(&self) -> bool {
287        [
288            TransferStatus::WaitingCounterparty,
289            TransferStatus::WaitingSafeHeight,
290            TransferStatus::WaitingConfirmations,
291            TransferStatus::WaitingBroadcast,
292        ]
293        .contains(self)
294    }
295
296    pub(crate) fn settled(&self) -> bool {
297        self == &TransferStatus::Settled
298    }
299
300    pub(crate) fn waiting_confirmations(&self) -> bool {
301        self == &TransferStatus::WaitingConfirmations
302    }
303
304    pub(crate) fn waiting_counterparty(&self) -> bool {
305        self == &TransferStatus::WaitingCounterparty
306    }
307
308    #[cfg(any(feature = "electrum", feature = "esplora"))]
309    pub(crate) fn is_fallible(&self) -> bool {
310        [
311            TransferStatus::Initiated,
312            TransferStatus::WaitingCounterparty,
313            TransferStatus::WaitingSafeHeight,
314            TransferStatus::WaitingBroadcast,
315        ]
316        .contains(self)
317    }
318}
319
320/// The type of a pending vanilla wallet transaction.
321#[derive(Debug, Copy, Clone, PartialEq, Eq, EnumIter, DeriveActiveEnum, Deserialize, Serialize)]
322#[sea_orm(rs_type = "u8", db_type = "TinyUnsigned")]
323pub enum WalletTransactionType {
324    /// Transaction used to create UTXOs
325    #[sea_orm(num_value = 1)]
326    CreateUtxos = 1,
327    /// Transaction used to drain the RGB wallet
328    #[sea_orm(num_value = 2)]
329    Drain = 2,
330    /// Transaction used to perform a BTC send
331    #[sea_orm(num_value = 3)]
332    SendBtc = 3,
333}
334
335/// An RGB assignment.
336#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Deserialize, Serialize)]
337pub enum Assignment {
338    /// Fungible value in RGB units (not considering precision)
339    Fungible(u64),
340    /// Non-fungible value
341    NonFungible,
342    /// Inflation right
343    InflationRight(u64),
344    /// Any assignment
345    Any,
346}
347
348impl Assignment {
349    pub(crate) fn from_opout_and_state(opout: Opout, state: &AllocatedState) -> Self {
350        match state {
351            AllocatedState::Amount(amt) if opout.ty == OS_ASSET => Self::Fungible(amt.as_u64()),
352            AllocatedState::Amount(amt) if opout.ty == OS_INFLATION => {
353                Self::InflationRight(amt.as_u64())
354            }
355            AllocatedState::Data(_) => Self::NonFungible,
356            _ => unreachable!(),
357        }
358    }
359
360    #[cfg(any(feature = "electrum", feature = "esplora"))]
361    pub(crate) fn add_to_assignments(&self, assignments: &mut AssignmentsCollection) {
362        match self {
363            Self::Fungible(amt) => {
364                assignments.fungible = assignments
365                    .fungible
366                    .checked_add(*amt)
367                    .expect("total fungible amount cannot exceed u64::MAX")
368            }
369            Self::NonFungible => assignments.non_fungible = true,
370            Self::InflationRight(amt) => {
371                assignments.inflation = assignments
372                    .inflation
373                    .checked_add(*amt)
374                    .expect("total inflation amount cannot exceed u64::MAX")
375            }
376            _ => unreachable!("when using this method we should know the assignment type"),
377        }
378    }
379
380    pub(crate) fn main_amount(&self) -> u64 {
381        if let Self::Fungible(amt) = self {
382            *amt
383        } else if let Self::NonFungible = self {
384            1
385        } else {
386            0
387        }
388    }
389
390    #[cfg(any(feature = "electrum", feature = "esplora"))]
391    pub(crate) fn inflation_amount(&self) -> u64 {
392        if let Self::InflationRight(amt) = self {
393            *amt
394        } else {
395            0
396        }
397    }
398}
399
400impl From<Assignment> for Value {
401    fn from(value: Assignment) -> Self {
402        Value::Json(Some(Box::new(serde_json::to_value(value).unwrap())))
403    }
404}
405
406impl TryFrom<Value> for Assignment {
407    type Error = sea_orm::DbErr;
408
409    fn try_from(v: Value) -> Result<Self, Self::Error> {
410        match v {
411            Value::Json(Some(json)) => {
412                serde_json::from_value(*json).map_err(|e| sea_orm::DbErr::Custom(e.to_string()))
413            }
414            _ => Err(sea_orm::DbErr::Type("Expected JSON value".into())),
415        }
416    }
417}
418
419impl rgb_lib_migration::ValueType for Assignment {
420    fn type_name() -> String {
421        "json".to_string()
422    }
423
424    fn column_type() -> ColumnType {
425        ColumnType::Json
426    }
427
428    fn array_type() -> ArrayType {
429        ArrayType::Json
430    }
431
432    fn try_from(v: Value) -> Result<Self, ValueTypeErr> {
433        match v {
434            Value::Json(Some(json)) => serde_json::from_value(*json).map_err(|_| ValueTypeErr),
435            _ => Err(ValueTypeErr),
436        }
437    }
438}
439
440impl TryGetable for Assignment {
441    fn try_get_by<I: sea_orm::ColIdx>(res: &QueryResult, index: I) -> Result<Self, TryGetError> {
442        let json_value_opt: Option<JsonValue> = res.try_get_by(index)?;
443        match json_value_opt {
444            Some(json_value) => serde_json::from_value(json_value)
445                .map_err(|e| TryGetError::DbErr(DbErr::Type(e.to_string()))),
446            None => Err(TryGetError::Null("Null value for Assignment".to_string())),
447        }
448    }
449}
450
451impl Nullable for Assignment {
452    fn null() -> Value {
453        Value::Json(None)
454    }
455}
456
457#[cfg(test)]
458mod tests {
459    use super::*;
460
461    #[test]
462    fn test_schema_id() {
463        // roundtrip
464        for asset_schema in AssetSchema::VALUES {
465            let schema_id = asset_schema.into();
466            let asset_schema_from_schema_id = AssetSchema::from_schema_id(schema_id).unwrap();
467            assert_eq!(asset_schema, asset_schema_from_schema_id);
468        }
469
470        // unknown
471        let err = AssetSchema::try_from(s!("unknown")).unwrap_err();
472        assert_matches!(err, Error::UnknownRgbSchema { schema_id: _ });
473        let err = AssetSchema::from_schema_id(SchemaId::strict_dumb()).unwrap_err();
474        assert_matches!(err, Error::UnknownRgbSchema { schema_id: _ });
475
476        // display
477        assert_eq!(AssetSchema::Nia.to_string(), "Nia");
478        assert_eq!(AssetSchema::Uda.to_string(), "Uda");
479        assert_eq!(AssetSchema::Cfa.to_string(), "Cfa");
480        assert_eq!(AssetSchema::Ifa.to_string(), "Ifa");
481    }
482
483    #[test]
484    fn test_coloring_type_into_active_value() {
485        let variants = [
486            ColoringType::Receive,
487            ColoringType::Issue,
488            ColoringType::Input,
489            ColoringType::Change,
490        ];
491        for variant in variants {
492            let active_value = IntoActiveValue::into_active_value(variant);
493            assert_eq!(active_value, ActiveValue::Set(variant));
494        }
495    }
496
497    #[test]
498    fn test_recipient_type_full() {
499        // roundtrip
500        let blind = RecipientTypeFull::Blind {
501            unblinded_utxo: Outpoint {
502                txid: s!("0000000000000000000000000000000000000000000000000000000000000001"),
503                vout: 0,
504            },
505        };
506        let witness = RecipientTypeFull::Witness { vout: Some(1) };
507        let witness_none = RecipientTypeFull::Witness { vout: None };
508        for recipient in [blind, witness, witness_none] {
509            let value: Value = recipient.clone().into();
510            let recovered = RecipientTypeFull::try_from(value).unwrap();
511            assert_eq!(recipient, recovered);
512        }
513
514        // try from value: not JSON
515        let value = Value::Int(Some(42));
516        let err = RecipientTypeFull::try_from(value).unwrap_err();
517        assert!(matches!(err, sea_orm::DbErr::Type(_)));
518
519        // try from value: invalid JSON
520        let bad_json = serde_json::json!({"bad": "data"});
521        let value = Value::Json(Some(Box::new(bad_json)));
522        let err = RecipientTypeFull::try_from(value).unwrap_err();
523        assert!(matches!(err, sea_orm::DbErr::Custom(_)));
524
525        // value type
526        assert_eq!(
527            <RecipientTypeFull as rgb_lib_migration::ValueType>::type_name(),
528            "json"
529        );
530        assert_eq!(
531            <RecipientTypeFull as rgb_lib_migration::ValueType>::column_type(),
532            ColumnType::Json
533        );
534        assert_eq!(
535            <RecipientTypeFull as rgb_lib_migration::ValueType>::array_type(),
536            ArrayType::Json
537        );
538
539        // value type try from
540        let blind = RecipientTypeFull::Blind {
541            unblinded_utxo: Outpoint {
542                txid: s!("0000000000000000000000000000000000000000000000000000000000000001"),
543                vout: 0,
544            },
545        };
546        let json_val = serde_json::to_value(&blind).unwrap();
547        let value = Value::Json(Some(Box::new(json_val)));
548        let recovered =
549            <RecipientTypeFull as rgb_lib_migration::ValueType>::try_from(value).unwrap();
550        assert_eq!(blind, recovered);
551
552        // value type try from: not JSON
553        let value = Value::Int(Some(42));
554        let err = <RecipientTypeFull as rgb_lib_migration::ValueType>::try_from(value);
555        assert!(err.is_err());
556
557        // value type try from: invalid JSON
558        let bad_json = serde_json::json!({"bad": "data"});
559        let value = Value::Json(Some(Box::new(bad_json)));
560        let err = <RecipientTypeFull as rgb_lib_migration::ValueType>::try_from(value);
561        assert!(err.is_err());
562
563        // nullable
564        let null_val = <RecipientTypeFull as Nullable>::null();
565        assert_eq!(null_val, Value::Json(None));
566    }
567
568    #[test]
569    fn test_assignment() {
570        // roundtrip
571        let assignments = [
572            Assignment::Fungible(100),
573            Assignment::NonFungible,
574            Assignment::InflationRight(500),
575            Assignment::Any,
576        ];
577        for assignment in assignments {
578            // test From<Assignment> for Value (already covered, but needed for roundtrip)
579            let value: Value = assignment.clone().into();
580            // test TryFrom<Value> for Assignment
581            let recovered = Assignment::try_from(value).unwrap();
582            assert_eq!(assignment, recovered);
583        }
584
585        // try from value: not JSON
586        let value = Value::Int(Some(42));
587        let err = Assignment::try_from(value).unwrap_err();
588        assert!(matches!(err, sea_orm::DbErr::Type(_)));
589
590        // try from value: invalid JSON
591        let bad_json = serde_json::json!({"InvalidVariant": 123});
592        let value = Value::Json(Some(Box::new(bad_json)));
593        let err = Assignment::try_from(value).unwrap_err();
594        assert!(matches!(err, sea_orm::DbErr::Custom(_)));
595
596        // value type
597        assert_eq!(
598            <Assignment as rgb_lib_migration::ValueType>::type_name(),
599            "json"
600        );
601        assert_eq!(
602            <Assignment as rgb_lib_migration::ValueType>::column_type(),
603            ColumnType::Json
604        );
605        assert_eq!(
606            <Assignment as rgb_lib_migration::ValueType>::array_type(),
607            ArrayType::Json
608        );
609
610        // value type try from
611        let assignment = Assignment::Fungible(42);
612        let json_val = serde_json::to_value(&assignment).unwrap();
613        let value = Value::Json(Some(Box::new(json_val)));
614        let recovered = <Assignment as rgb_lib_migration::ValueType>::try_from(value).unwrap();
615        assert_eq!(assignment, recovered);
616
617        // value type try from: not JSON
618        let value = Value::Int(Some(42));
619        let err = <Assignment as rgb_lib_migration::ValueType>::try_from(value);
620        assert!(err.is_err());
621
622        // value type try from: invalid JSON
623        let bad_json = serde_json::json!({"InvalidVariant": 123});
624        let value = Value::Json(Some(Box::new(bad_json)));
625        let err = <Assignment as rgb_lib_migration::ValueType>::try_from(value);
626        assert!(err.is_err());
627
628        // nullable
629        let null_val = <Assignment as Nullable>::null();
630        assert_eq!(null_val, Value::Json(None));
631
632        // main amount
633        assert_eq!(Assignment::Fungible(100).main_amount(), 100);
634        assert_eq!(Assignment::Fungible(0).main_amount(), 0);
635        assert_eq!(Assignment::NonFungible.main_amount(), 1);
636        assert_eq!(Assignment::InflationRight(500).main_amount(), 0);
637        assert_eq!(Assignment::Any.main_amount(), 0);
638    }
639
640    #[test]
641    fn test_transfer_status_methods() {
642        assert!(TransferStatus::Failed.failed());
643        assert!(!TransferStatus::Settled.failed());
644        assert!(!TransferStatus::WaitingCounterparty.failed());
645        assert!(!TransferStatus::WaitingConfirmations.failed());
646        assert!(!TransferStatus::Initiated.failed());
647        assert!(!TransferStatus::WaitingBroadcast.failed());
648        assert!(!TransferStatus::WaitingSafeHeight.failed());
649
650        assert!(TransferStatus::Initiated.initiated());
651        assert!(!TransferStatus::WaitingCounterparty.initiated());
652        assert!(!TransferStatus::WaitingConfirmations.initiated());
653        assert!(!TransferStatus::WaitingSafeHeight.initiated());
654        assert!(!TransferStatus::Settled.initiated());
655        assert!(!TransferStatus::Failed.initiated());
656        assert!(!TransferStatus::WaitingBroadcast.initiated());
657
658        assert!(TransferStatus::Initiated.pending());
659        assert!(TransferStatus::WaitingCounterparty.pending());
660        assert!(TransferStatus::WaitingConfirmations.pending());
661        assert!(TransferStatus::WaitingSafeHeight.pending());
662        assert!(TransferStatus::WaitingBroadcast.pending());
663        assert!(!TransferStatus::Settled.pending());
664        assert!(!TransferStatus::Failed.pending());
665
666        assert!(TransferStatus::Settled.settled());
667        assert!(!TransferStatus::Failed.settled());
668        assert!(!TransferStatus::WaitingCounterparty.settled());
669        assert!(!TransferStatus::WaitingConfirmations.settled());
670        assert!(!TransferStatus::WaitingSafeHeight.settled());
671        assert!(!TransferStatus::Initiated.settled());
672        assert!(!TransferStatus::WaitingBroadcast.settled());
673
674        assert!(TransferStatus::WaitingConfirmations.waiting_confirmations());
675        assert!(!TransferStatus::WaitingCounterparty.waiting_confirmations());
676        assert!(!TransferStatus::WaitingSafeHeight.waiting_confirmations());
677        assert!(!TransferStatus::WaitingBroadcast.waiting_confirmations());
678        assert!(!TransferStatus::Initiated.waiting_confirmations());
679        assert!(!TransferStatus::Settled.waiting_confirmations());
680        assert!(!TransferStatus::Failed.waiting_confirmations());
681
682        assert!(TransferStatus::WaitingCounterparty.waiting_counterparty());
683        assert!(!TransferStatus::WaitingConfirmations.waiting_counterparty());
684        assert!(!TransferStatus::WaitingSafeHeight.waiting_counterparty());
685        assert!(!TransferStatus::Initiated.waiting_counterparty());
686        assert!(!TransferStatus::Settled.waiting_counterparty());
687        assert!(!TransferStatus::Failed.waiting_counterparty());
688        assert!(!TransferStatus::WaitingBroadcast.waiting_counterparty());
689
690        #[cfg(any(feature = "electrum", feature = "esplora"))]
691        {
692            assert!(TransferStatus::WaitingCounterparty.waiting());
693            assert!(TransferStatus::WaitingConfirmations.waiting());
694            assert!(TransferStatus::WaitingBroadcast.waiting());
695            assert!(TransferStatus::WaitingSafeHeight.waiting());
696            assert!(!TransferStatus::Initiated.waiting());
697            assert!(!TransferStatus::Settled.waiting());
698            assert!(!TransferStatus::Failed.waiting());
699        }
700    }
701}