Skip to content

Commit d091a19

Browse files
etet
et
authored and
et
committed
introduced apply & add_input supports list of utxos
1 parent a2c3a8e commit d091a19

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

pycardano/txbuilder.py

+25-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from copy import deepcopy
44
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
66

77
from pycardano.address import Address, AddressType
88
from pycardano.backend.base import ChainContext
@@ -143,16 +143,36 @@ class TransactionBuilder:
143143

144144
_should_estimate_execution_units: bool = field(init=False, default=None)
145145

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.
148148
149149
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.
151152
152153
Returns:
153154
TransactionBuilder: Current transaction builder.
154155
"""
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)
156176
return self
157177

158178
def _consolidate_redeemer(self, redeemer):

0 commit comments

Comments
 (0)