@@ -152,36 +152,9 @@ def load_or_create_key_pair(base_dir, base_name):
152
152
nft_output = TransactionOutput (address , Value (min_val , my_nft ))
153
153
builder .add_output (nft_output )
154
154
155
- # Build a finalized transaction body with the change returning to our own address
156
- tx_body = builder .build (change_address = address )
157
-
158
- """Sign transaction and add witnesses"""
159
- # Sign the transaction body hash using the payment signing key
160
- payment_signature = self .payment_skey .sign (tx_body .hash ())
161
-
162
- # Sign the transaction body hash using the extended payment signing key
163
- extended_payment_signature = self .extended_payment_skey .sign (tx_body .hash ())
164
-
165
- # Sign the transaction body hash using the policy signing key because we are minting new tokens
166
- policy_signature = policy_skey .sign (tx_body .hash ())
167
-
168
- # Add verification keys and their signatures to the witness set
169
- vk_witnesses = [
170
- VerificationKeyWitness (self .payment_vkey , payment_signature ),
171
- VerificationKeyWitness (policy_vkey , policy_signature ),
172
- VerificationKeyWitness (
173
- self .extended_payment_vkey , extended_payment_signature
174
- ),
175
- ]
176
-
177
- # Create final signed transaction
178
- signed_tx = Transaction (
179
- tx_body ,
180
- # Beside vk witnesses, We also need to add the policy script to witness set when we are minting new tokens.
181
- TransactionWitnessSet (
182
- vkey_witnesses = vk_witnesses , native_scripts = native_scripts
183
- ),
184
- auxiliary_data = auxiliary_data ,
155
+ # Build and sign transaction
156
+ signed_tx = builder .build_and_sign (
157
+ [self .payment_skey , self .extended_payment_skey , policy_skey ], address
185
158
)
186
159
187
160
print ("############### Transaction created ###############" )
@@ -217,23 +190,8 @@ def load_or_create_key_pair(base_dir, base_name):
217
190
218
191
builder .add_output (nft_to_send )
219
192
220
- tx_body = builder .build (change_address = address )
221
-
222
- """Sign transaction and add witnesses"""
223
- # Sign the transaction body hash using the payment signing key
224
- payment_signature = self .payment_skey .sign (tx_body .hash ())
225
-
226
- # Add verification keys and their signatures to the witness set
227
- vk_witnesses = [
228
- VerificationKeyWitness (self .payment_vkey , payment_signature ),
229
- ]
230
-
231
193
# Create final signed transaction
232
- signed_tx = Transaction (
233
- tx_body ,
234
- # Beside vk witnesses, We also need to add the policy script to witness set when we are minting new tokens.
235
- TransactionWitnessSet (vkey_witnesses = vk_witnesses ),
236
- )
194
+ signed_tx = builder .build_and_sign ([self .payment_skey ], address )
237
195
238
196
print ("############### Transaction created ###############" )
239
197
print (signed_tx )
@@ -277,19 +235,7 @@ def test_plutus(self):
277
235
TransactionOutput (script_address , 50000000 , datum_hash = datum_hash (datum ))
278
236
)
279
237
280
- tx_body = builder .build (change_address = giver_address )
281
- witness_set = builder .build_witness_set ()
282
-
283
- payment_signature = self .payment_skey .sign (tx_body .hash ())
284
-
285
- witness_set .vkey_witnesses = [
286
- VerificationKeyWitness (self .payment_vkey , payment_signature ),
287
- ]
288
-
289
- signed_tx = Transaction (
290
- tx_body ,
291
- witness_set ,
292
- )
238
+ signed_tx = builder .build_and_sign ([self .payment_skey ], giver_address )
293
239
294
240
print ("############### Transaction created ###############" )
295
241
print (signed_tx )
@@ -307,19 +253,7 @@ def test_plutus(self):
307
253
builder .add_input_address (giver_address )
308
254
builder .add_output (TransactionOutput (taker_address , 5000000 ))
309
255
310
- tx_body = builder .build (change_address = giver_address )
311
- witness_set = builder .build_witness_set ()
312
-
313
- payment_signature = self .payment_skey .sign (tx_body .hash ())
314
-
315
- witness_set .vkey_witnesses = [
316
- VerificationKeyWitness (self .payment_vkey , payment_signature ),
317
- ]
318
-
319
- signed_tx = Transaction (
320
- tx_body ,
321
- witness_set ,
322
- )
256
+ signed_tx = builder .build_and_sign ([self .payment_skey ], giver_address )
323
257
324
258
print ("############### Transaction created ###############" )
325
259
print (signed_tx )
@@ -352,19 +286,7 @@ def test_plutus(self):
352
286
353
287
builder .collaterals .append (non_nft_utxo )
354
288
355
- tx_body = builder .build (change_address = taker_address )
356
- witness_set = builder .build_witness_set ()
357
-
358
- collateral_signature = self .extended_payment_skey .sign (tx_body .hash ())
359
-
360
- witness_set .vkey_witnesses = [
361
- VerificationKeyWitness (self .extended_payment_vkey , collateral_signature ),
362
- ]
363
-
364
- signed_tx = Transaction (
365
- tx_body ,
366
- witness_set ,
367
- )
289
+ signed_tx = builder .build_and_sign ([self .extended_payment_skey ], taker_address )
368
290
369
291
print ("############### Transaction created ###############" )
370
292
print (signed_tx )
0 commit comments