@@ -876,6 +876,9 @@ def build(
876
876
change_address : Optional [Address ] = None ,
877
877
merge_change : Optional [bool ] = False ,
878
878
collateral_change_address : Optional [Address ] = None ,
879
+ auto_validity_start_offset : Optional [int ] = None ,
880
+ auto_ttl_offset : Optional [int ] = None ,
881
+ auto_required_signers : Optional [bool ] = None ,
879
882
) -> TransactionBody :
880
883
"""Build a transaction body from all constraints set through the builder.
881
884
@@ -885,11 +888,41 @@ def build(
885
888
merge_change (Optional[bool]): If the change address match one of the transaction output, the change amount
886
889
will be directly added to that transaction output, instead of being added as a separate output.
887
890
collateral_change_address (Optional[Address]): Address to which collateral changes will be returned.
891
+ auto_validity_start_offset (Optional[int]): Automatically set the validity start interval of the transaction
892
+ to the current slot number + the given offset (default -1000).
893
+ A manually set validity start will always take precedence.
894
+ auto_ttl_offset (Optional[int]): Automatically set the validity end interval (ttl) of the transaction
895
+ to the current slot number + the given offset (default 10_000).
896
+ A manually set ttl will always take precedence.
897
+ auto_required_signers (Optional[bool]): Automatically add all pubkeyhashes of transaction inputs
898
+ to required signatories (default only for Smart Contract transactions).
899
+ Manually set required signers will always take precedence.
888
900
889
901
Returns:
890
902
TransactionBody: A transaction body.
891
903
"""
892
904
self ._ensure_no_input_exclusion_conflict ()
905
+
906
+ # only automatically set the validity interval and required signers if scripts are involved
907
+ is_smart = bool (self .scripts )
908
+
909
+ # Automatically set the validity range to a tight value around transaction creation
910
+ if (
911
+ is_smart or auto_validity_start_offset is not None
912
+ ) and self .validity_start is None :
913
+ last_slot = self .context .last_block_slot
914
+ # If None is provided, the default value is -1000
915
+ if auto_validity_start_offset is None :
916
+ auto_validity_start_offset = - 1000
917
+ self .validity_start = max (0 , last_slot + auto_validity_start_offset )
918
+
919
+ if (is_smart or auto_ttl_offset is not None ) and self .ttl is None :
920
+ last_slot = self .context .last_block_slot
921
+ # If None is provided, the default value is 10_000
922
+ if auto_ttl_offset is None :
923
+ auto_ttl_offset = 10_000
924
+ self .ttl = max (0 , last_slot + auto_ttl_offset )
925
+
893
926
selected_utxos = []
894
927
selected_amount = Value ()
895
928
for i in self .inputs :
@@ -1021,6 +1054,14 @@ def build(
1021
1054
1022
1055
self .inputs [:] = selected_utxos [:]
1023
1056
1057
+ # Automatically set the required signers for smart transactions
1058
+ if (
1059
+ is_smart and auto_required_signers is not False
1060
+ ) and self .required_signers is None :
1061
+ # Collect all signatories from explicitly defined
1062
+ # transaction inputs and collateral inputs, and input addresses
1063
+ self .required_signers = list (self ._input_vkey_hashes ())
1064
+
1024
1065
self ._set_redeemer_index ()
1025
1066
1026
1067
self ._set_collateral_return (collateral_change_address or change_address )
@@ -1175,6 +1216,9 @@ def build_and_sign(
1175
1216
change_address : Optional [Address ] = None ,
1176
1217
merge_change : Optional [bool ] = False ,
1177
1218
collateral_change_address : Optional [Address ] = None ,
1219
+ auto_validity_start_offset : Optional [int ] = None ,
1220
+ auto_ttl_offset : Optional [int ] = None ,
1221
+ auto_required_signers : Optional [bool ] = None ,
1178
1222
) -> Transaction :
1179
1223
"""Build a transaction body from all constraints set through the builder and sign the transaction with
1180
1224
provided signing keys.
@@ -1187,6 +1231,15 @@ def build_and_sign(
1187
1231
merge_change (Optional[bool]): If the change address match one of the transaction output, the change amount
1188
1232
will be directly added to that transaction output, instead of being added as a separate output.
1189
1233
collateral_change_address (Optional[Address]): Address to which collateral changes will be returned.
1234
+ auto_validity_start_offset (Optional[int]): Automatically set the validity start interval of the transaction
1235
+ to the current slot number + the given offset (default -1000).
1236
+ A manually set validity start will always take precedence.
1237
+ auto_ttl_offset (Optional[int]): Automatically set the validity end interval (ttl) of the transaction
1238
+ to the current slot number + the given offset (default 10_000).
1239
+ A manually set ttl will always take precedence.
1240
+ auto_required_signers (Optional[bool]): Automatically add all pubkeyhashes of transaction inputs
1241
+ to required signatories (default only for Smart Contract transactions).
1242
+ Manually set required signers will always take precedence.
1190
1243
1191
1244
Returns:
1192
1245
Transaction: A signed transaction.
@@ -1196,6 +1249,9 @@ def build_and_sign(
1196
1249
change_address = change_address ,
1197
1250
merge_change = merge_change ,
1198
1251
collateral_change_address = collateral_change_address ,
1252
+ auto_validity_start_offset = auto_validity_start_offset ,
1253
+ auto_ttl_offset = auto_ttl_offset ,
1254
+ auto_required_signers = auto_required_signers ,
1199
1255
)
1200
1256
witness_set = self .build_witness_set ()
1201
1257
witness_set .vkey_witnesses = []
0 commit comments