@@ -284,7 +284,8 @@ def __post_init__(self):
284
284
def from_primitive (cls : Type [_Script ], values : List [Primitive ]) -> _Script :
285
285
if values [0 ] == 0 :
286
286
return cls (NativeScript .from_primitive (values [1 ]))
287
- elif values [0 ] == 1 :
287
+ assert isinstance (values [1 ], bytes )
288
+ if values [0 ] == 1 :
288
289
return cls (PlutusV1Script (values [1 ]))
289
290
else :
290
291
return cls (PlutusV2Script (values [1 ]))
@@ -315,8 +316,10 @@ def from_primitive(
315
316
cls : Type [_DatumOption ], values : List [Primitive ]
316
317
) -> _DatumOption :
317
318
if values [0 ] == 0 :
319
+ assert isinstance (values [1 ], bytes )
318
320
return _DatumOption (DatumHash (values [1 ]))
319
321
else :
322
+ assert isinstance (values [1 ], CBORTag )
320
323
v = cbor2 .loads (values [1 ].value )
321
324
if isinstance (v , CBORTag ):
322
325
return _DatumOption (RawPlutusData .from_primitive (v ))
@@ -334,6 +337,7 @@ def to_primitive(self) -> Primitive:
334
337
335
338
@classmethod
336
339
def from_primitive (cls : Type [_ScriptRef ], value : Primitive ) -> _ScriptRef :
340
+ assert isinstance (value , CBORTag )
337
341
return cls (_Script .from_primitive (cbor2 .loads (value .value )))
338
342
339
343
@@ -343,9 +347,13 @@ class _TransactionOutputPostAlonzo(MapCBORSerializable):
343
347
344
348
amount : Union [int , Value ] = field (metadata = {"key" : 1 })
345
349
346
- datum : _DatumOption = field (default = None , metadata = {"key" : 2 , "optional" : True })
350
+ datum : Optional [_DatumOption ] = field (
351
+ default = None , metadata = {"key" : 2 , "optional" : True }
352
+ )
347
353
348
- script_ref : _ScriptRef = field (default = None , metadata = {"key" : 3 , "optional" : True })
354
+ script_ref : Optional [_ScriptRef ] = field (
355
+ default = None , metadata = {"key" : 3 , "optional" : True }
356
+ )
349
357
350
358
@property
351
359
def script (self ) -> Optional [Union [NativeScript , PlutusV1Script , PlutusV2Script ]]:
@@ -361,15 +369,15 @@ class _TransactionOutputLegacy(ArrayCBORSerializable):
361
369
362
370
amount : Union [int , Value ]
363
371
364
- datum_hash : DatumHash = field (default = None , metadata = {"optional" : True })
372
+ datum_hash : Optional [ DatumHash ] = field (default = None , metadata = {"optional" : True })
365
373
366
374
367
375
@dataclass (repr = False )
368
376
class TransactionOutput (CBORSerializable ):
369
377
370
378
address : Address
371
379
372
- amount : Union [int , Value ]
380
+ amount : Union [Value ]
373
381
374
382
datum_hash : Optional [DatumHash ] = None
375
383
@@ -496,30 +504,36 @@ class TransactionBody(MapCBORSerializable):
496
504
497
505
fee : int = field (default = 0 , metadata = {"key" : 2 })
498
506
499
- ttl : int = field (default = None , metadata = {"key" : 3 , "optional" : True })
507
+ ttl : Optional [ int ] = field (default = None , metadata = {"key" : 3 , "optional" : True })
500
508
501
- certificates : List [Certificate ] = field (
509
+ certificates : Optional [ List [Certificate ] ] = field (
502
510
default = None , metadata = {"key" : 4 , "optional" : True }
503
511
)
504
512
505
- withdraws : Withdrawals = field (default = None , metadata = {"key" : 5 , "optional" : True })
513
+ withdraws : Optional [Withdrawals ] = field (
514
+ default = None , metadata = {"key" : 5 , "optional" : True }
515
+ )
506
516
507
517
# TODO: Add proposal update support
508
518
update : Any = field (default = None , metadata = {"key" : 6 , "optional" : True })
509
519
510
- auxiliary_data_hash : AuxiliaryDataHash = field (
520
+ auxiliary_data_hash : Optional [ AuxiliaryDataHash ] = field (
511
521
default = None , metadata = {"key" : 7 , "optional" : True }
512
522
)
513
523
514
- validity_start : int = field (default = None , metadata = {"key" : 8 , "optional" : True })
524
+ validity_start : Optional [int ] = field (
525
+ default = None , metadata = {"key" : 8 , "optional" : True }
526
+ )
515
527
516
- mint : MultiAsset = field (default = None , metadata = {"key" : 9 , "optional" : True })
528
+ mint : Optional [MultiAsset ] = field (
529
+ default = None , metadata = {"key" : 9 , "optional" : True }
530
+ )
517
531
518
- script_data_hash : ScriptDataHash = field (
532
+ script_data_hash : Optional [ ScriptDataHash ] = field (
519
533
default = None , metadata = {"key" : 11 , "optional" : True }
520
534
)
521
535
522
- collateral : List [TransactionInput ] = field (
536
+ collateral : Optional [ List [TransactionInput ] ] = field (
523
537
default = None ,
524
538
metadata = {
525
539
"key" : 13 ,
@@ -528,7 +542,7 @@ class TransactionBody(MapCBORSerializable):
528
542
},
529
543
)
530
544
531
- required_signers : List [VerificationKeyHash ] = field (
545
+ required_signers : Optional [ List [VerificationKeyHash ] ] = field (
532
546
default = None ,
533
547
metadata = {
534
548
"key" : 14 ,
@@ -537,15 +551,19 @@ class TransactionBody(MapCBORSerializable):
537
551
},
538
552
)
539
553
540
- network_id : Network = field (default = None , metadata = {"key" : 15 , "optional" : True })
554
+ network_id : Optional [Network ] = field (
555
+ default = None , metadata = {"key" : 15 , "optional" : True }
556
+ )
541
557
542
- collateral_return : TransactionOutput = field (
558
+ collateral_return : Optional [ TransactionOutput ] = field (
543
559
default = None , metadata = {"key" : 16 , "optional" : True }
544
560
)
545
561
546
- total_collateral : int = field (default = None , metadata = {"key" : 17 , "optional" : True })
562
+ total_collateral : Optional [int ] = field (
563
+ default = None , metadata = {"key" : 17 , "optional" : True }
564
+ )
547
565
548
- reference_inputs : List [TransactionInput ] = field (
566
+ reference_inputs : Optional [ List [TransactionInput ] ] = field (
549
567
default = None ,
550
568
metadata = {
551
569
"key" : 18 ,
@@ -555,9 +573,9 @@ class TransactionBody(MapCBORSerializable):
555
573
)
556
574
557
575
def hash (self ) -> bytes :
558
- return blake2b (
559
- self . to_cbor ( encoding = "bytes" ), TRANSACTION_HASH_SIZE , encoder = RawEncoder
560
- )
576
+ h = self . to_cbor ( encoding = "bytes" )
577
+ assert isinstance ( h , bytes )
578
+ return blake2b ( h , TRANSACTION_HASH_SIZE , encoder = RawEncoder )
561
579
562
580
@property
563
581
def id (self ) -> TransactionId :
@@ -572,7 +590,7 @@ class Transaction(ArrayCBORSerializable):
572
590
573
591
valid : bool = True
574
592
575
- auxiliary_data : Union [AuxiliaryData , type ( None ) ] = None
593
+ auxiliary_data : Optional [AuxiliaryData ] = None
576
594
577
595
@property
578
596
def id (self ) -> TransactionId :
0 commit comments