cardano_sdk/cardano/transaction/
state.rs

1//  This Source Code Form is subject to the terms of the Mozilla Public
2//  License, v. 2.0. If a copy of the MPL was not distributed with this
3//  file, You can obtain one at http://mozilla.org/MPL/2.0/.
4
5//! Type-level utilities for guiding the construction of [`Transaction`](super::Transaction).
6
7/// Restricts the inhabitants that a generic parameter can take. This is used in the context of
8/// [`Transaction`](super::Transaction) to allow some methods to be always accessible, or
9/// restricted to a particular state.
10///
11/// For example, the [`Transaction::sign`](super::Transaction::sign) method is only available in the state
12/// [`ReadyForSigning`]. This ensures that the body is not inadvertently modified once constructed,
13/// as it would invalidate all existing signatures.
14pub trait IsTransactionBodyState: crate::non_extensible::NonExtensible {
15    type ChangeStrategy;
16}
17
18/// Indicates that a [`Transaction`](super::Transaction) is in an unknown state; only some methods
19/// will be available.
20///
21/// Note that there's no ways to construct this struct; its only role is to live at the type-level.
22#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
23pub struct Unknown;
24impl crate::non_extensible::NonExtensible for Unknown {}
25impl IsTransactionBodyState for Unknown {
26    type ChangeStrategy = ();
27}
28
29/// Indicates that a [`Transaction`](super::Transaction) is under construction, and its body may
30/// still be modified.
31///
32/// Note that there's no ways to construct this struct; its only role is to live at the type-level.
33#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
34pub struct InConstruction;
35impl crate::non_extensible::NonExtensible for InConstruction {}
36impl IsTransactionBodyState for InConstruction {
37    type ChangeStrategy = crate::cardano::output::change_strategy::ChangeStrategy;
38}
39
40/// Indicates that a [`Transaction`](super::Transaction)'s body is now complete, and the
41/// transaction is either awaiting signatures, or fully signed. In particular, methods such as
42/// [`Transaction::sign`](super::Transaction::sign) and [`Transaction::id`](super::Transaction::id)
43/// becomes available.
44///
45/// Note that there's no ways to construct this struct; its only role is to live at the type-level.
46#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
47pub struct ReadyForSigning;
48impl crate::non_extensible::NonExtensible for ReadyForSigning {}
49impl IsTransactionBodyState for ReadyForSigning {
50    type ChangeStrategy = ();
51}