@@ -388,13 +388,22 @@ extension Transaction: RLPDecodable {
388
388
public init ( rlpItem: RLPItem ) throws {
389
389
let items = try rlpItem. getListItems ( )
390
390
391
- guard items. count == 3 else {
391
+ let payloadRLPListItemCount = 9
392
+ let payloadRLPListItems : [ RLPItem ]
393
+ let hasSignature : Bool
394
+ switch items. count {
395
+ case 3 :
396
+ hasSignature = true
397
+ payloadRLPListItems = try items [ 0 ] . getListItems ( )
398
+ case payloadRLPListItemCount:
399
+ hasSignature = false
400
+ payloadRLPListItems = items
401
+ default :
392
402
throw RLPDecodingError . invalidType ( rlpItem, type: Self . self)
393
403
}
394
404
395
405
// payload
396
- let payloadRLPListItems = try items [ 0 ] . getListItems ( )
397
- guard payloadRLPListItems. count == 9 else {
406
+ guard payloadRLPListItems. count == payloadRLPListItemCount else {
398
407
throw RLPDecodingError . invalidType ( rlpItem, type: Self . self)
399
408
}
400
409
self . script = try Data ( rlpItem: payloadRLPListItems [ 0 ] )
@@ -410,23 +419,28 @@ extension Transaction: RLPDecodable {
410
419
self . authorizers = try payloadRLPListItems [ 8 ] . getListItems ( )
411
420
. map { Address ( data: try Data ( rlpItem: $0) ) }
412
421
413
- // payloadSignatures & envelopeSignatures
414
- self . payloadSignatures = try items [ 1 ] . getListItems ( )
415
- . map { try Transaction . Signature ( rlpItem: $0) }
416
- self . envelopeSignatures = try items [ 2 ] . getListItems ( )
417
- . map { try Transaction . Signature ( rlpItem: $0) }
418
-
419
- for (index, payloadSignature) in payloadSignatures. enumerated ( ) {
420
- guard payloadSignature. signerIndex < signerList. count else {
421
- throw RLPDecodingError . invalidType ( rlpItem, type: Self . self)
422
+ if hasSignature {
423
+ // payloadSignatures & envelopeSignatures
424
+ self . payloadSignatures = try items [ 1 ] . getListItems ( )
425
+ . map { try Transaction . Signature ( rlpItem: $0) }
426
+ self . envelopeSignatures = try items [ 2 ] . getListItems ( )
427
+ . map { try Transaction . Signature ( rlpItem: $0) }
428
+
429
+ for (index, payloadSignature) in payloadSignatures. enumerated ( ) {
430
+ guard payloadSignature. signerIndex < signerList. count else {
431
+ throw RLPDecodingError . invalidType ( rlpItem, type: Self . self)
432
+ }
433
+ payloadSignatures [ index] . address = signerList [ payloadSignature. signerIndex]
422
434
}
423
- payloadSignatures [ index] . address = signerList [ payloadSignature . signerIndex ]
424
- }
425
- for (index , envelopeSignature ) in envelopeSignatures . enumerated ( ) {
426
- guard envelopeSignature . signerIndex < signerList . count else {
427
- throw RLPDecodingError . invalidType ( rlpItem , type : Self . self )
435
+ for ( index, envelopeSignature ) in envelopeSignatures . enumerated ( ) {
436
+ guard envelopeSignature . signerIndex < signerList . count else {
437
+ throw RLPDecodingError . invalidType ( rlpItem , type : Self . self )
438
+ }
439
+ envelopeSignatures [ index ] . address = signerList [ envelopeSignature . signerIndex ]
428
440
}
429
- envelopeSignatures [ index] . address = signerList [ envelopeSignature. signerIndex]
441
+ } else {
442
+ self . payloadSignatures = [ ]
443
+ self . envelopeSignatures = [ ]
430
444
}
431
445
}
432
446
}
0 commit comments