identity_iota_core/iota_interaction_rust/
transaction_builder.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright 2020-2024 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

use std::ops::Deref;
use std::ops::DerefMut;

use crate::rebased::Error;
use identity_iota_interaction::types::programmable_transaction_builder::ProgrammableTransactionBuilder;
use identity_iota_interaction::ProgrammableTransactionBcs;
use identity_iota_interaction::TransactionBuilderT;

#[derive(Default)]
pub(crate) struct TransactionBuilderRustSdk {
  pub(crate) builder: ProgrammableTransactionBuilder,
}

impl TransactionBuilderRustSdk {
  pub(crate) fn new(builder: ProgrammableTransactionBuilder) -> Self {
    TransactionBuilderRustSdk { builder }
  }
}

impl TransactionBuilderT for TransactionBuilderRustSdk {
  type Error = Error;
  type NativeTxBuilder = ProgrammableTransactionBuilder;

  fn finish(self) -> Result<ProgrammableTransactionBcs, Error> {
    let tx = self.builder.finish();
    Ok(bcs::to_bytes(&tx)?)
  }

  fn as_native_tx_builder(&mut self) -> &mut Self::NativeTxBuilder {
    &mut self.builder
  }

  fn into_native_tx_builder(self) -> Self::NativeTxBuilder {
    self.builder
  }
}

impl Deref for TransactionBuilderRustSdk {
  type Target = ProgrammableTransactionBuilder;

  fn deref(&self) -> &Self::Target {
    &self.builder
  }
}

impl DerefMut for TransactionBuilderRustSdk {
  fn deref_mut(&mut self) -> &mut Self::Target {
    &mut self.builder
  }
}