radix_transactions/model/v2/
signed_partial_transaction_v2.rs

1use super::*;
2use crate::internal_prelude::*;
3
4//=================================================================================
5// NOTE:
6// See versioned.rs for tests and a demonstration for the calculation of hashes etc
7//=================================================================================
8
9/// An analogue of a [`SignedTransactionIntentV2`], except with a [`SubintentV2`] at the root.
10///
11/// This is intended to represent a fully signed, incomplete sub-tree of the transaction,
12/// and be a canonical model for building, storing and transferring this signed subtree.
13///
14/// It contains an unsigned [`PartialTransactionV2`], and signatures for the root subintent,
15/// and each non-root subintent.
16///
17/// It can be prepared and validated using [`self.prepare_and_validate(validator)`][Self::prepare_and_validate],
18/// just like a [`NotarizedTransactionV2`]. Its validated form is a [`ValidatedSignedPartialTransactionV2`].
19///
20/// It can be built with a [`PartialTransactionV2Builder`].
21#[derive(Debug, Clone, Eq, PartialEq, ManifestSbor, ScryptoDescribe)]
22pub struct SignedPartialTransactionV2 {
23    pub partial_transaction: PartialTransactionV2,
24    pub root_subintent_signatures: IntentSignaturesV2,
25    pub non_root_subintent_signatures: NonRootSubintentSignaturesV2,
26}
27
28impl SignedPartialTransactionV2 {
29    pub fn prepare_and_validate(
30        &self,
31        validator: &TransactionValidator,
32    ) -> Result<ValidatedSignedPartialTransactionV2, TransactionValidationError> {
33        self.prepare(validator.preparation_settings())?
34            .validate(validator)
35    }
36}
37
38define_transaction_payload!(
39    SignedPartialTransactionV2,
40    RawSignedPartialTransaction,
41    PreparedSignedPartialTransactionV2 {
42        partial_transaction: PreparedPartialTransactionV2,
43        root_subintent_signatures: PreparedIntentSignaturesV2,
44        non_root_subintent_signatures: PreparedNonRootSubintentSignaturesV2,
45    },
46    TransactionDiscriminator::V2SignedPartialTransaction,
47);
48
49impl HasSubintentHash for PreparedSignedPartialTransactionV2 {
50    fn subintent_hash(&self) -> SubintentHash {
51        self.partial_transaction.subintent_hash()
52    }
53}
54
55impl PreparedSignedPartialTransactionV2 {
56    pub fn non_root_subintent_hashes(&self) -> impl Iterator<Item = SubintentHash> + '_ {
57        self.partial_transaction.non_root_subintent_hashes()
58    }
59
60    pub fn validate(
61        self,
62        validator: &TransactionValidator,
63    ) -> Result<ValidatedSignedPartialTransactionV2, TransactionValidationError> {
64        validator.validate_signed_partial_transaction_v2(self)
65    }
66}