|
2 | 2 |
|
3 | 3 | from copy import deepcopy
|
4 | 4 | from dataclasses import dataclass, field, fields
|
5 |
| -from typing import Dict, List, Optional, Set, Tuple, Union |
| 5 | +from typing import Dict, List, Optional, Set, Tuple, Union, Callable |
6 | 6 |
|
7 | 7 | from pycardano.address import Address, AddressType
|
8 | 8 | from pycardano.backend.base import ChainContext
|
@@ -143,16 +143,36 @@ class TransactionBuilder:
|
143 | 143 |
|
144 | 144 | _should_estimate_execution_units: bool = field(init=False, default=None)
|
145 | 145 |
|
146 |
| - def add_input(self, utxo: UTxO) -> TransactionBuilder: |
147 |
| - """Add a specific UTxO to transaction's inputs. |
| 146 | + def apply(self, callback: Callable[[], None]) -> TransactionBuilder: |
| 147 | + """Apply the provided callback function to the transaction. |
148 | 148 |
|
149 | 149 | Args:
|
150 |
| - utxo (UTxO): UTxO to be added. |
| 150 | + callback (Callable[[], None]): A callback function. The callback |
| 151 | + should not return a value, as nothing will be done with it. |
151 | 152 |
|
152 | 153 | Returns:
|
153 | 154 | TransactionBuilder: Current transaction builder.
|
154 | 155 | """
|
155 |
| - self.inputs.append(utxo) |
| 156 | + if callable(callback): |
| 157 | + callback() |
| 158 | + else: |
| 159 | + raise ValueError("Not a callable.") |
| 160 | + return self |
| 161 | + |
| 162 | + def add_input(self, utxo: Union[UTxO, List[UTxO]]) -> TransactionBuilder: |
| 163 | + """Add a specific UTxO or a list of UTxOs to the transaction's inputs. |
| 164 | +
|
| 165 | + Args: |
| 166 | + utxo (Union[UTxO, List[UTxO]]): UTxO or list of UTxOs to be added to the transaction. |
| 167 | +
|
| 168 | + Returns: |
| 169 | + TransactionBuilder: Current transaction builder. |
| 170 | + """ |
| 171 | + if isinstance(utxo, list): |
| 172 | + for o in utxo: |
| 173 | + self.inputs.append(o) |
| 174 | + else: |
| 175 | + self.inputs.append(utxo) |
156 | 176 | return self
|
157 | 177 |
|
158 | 178 | def _consolidate_redeemer(self, redeemer):
|
|
0 commit comments