whisky-csl 1.0.23

Wrapper around the cardano-serialization-lib for easier transaction building, heavily inspired by cardano-cli APIs
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
use serde::{Deserialize, Serialize};
use std::collections::HashMap;

// ============================================================================
// Basic Type Aliases
// ============================================================================

pub type AddressPrototype = String;
pub type URLPrototype = String;
pub type AnchorDataHashPrototype = String;
pub type AssetNamePrototype = String;
pub type AssetNamesPrototype = Vec<String>;
pub type AuxiliaryDataHashPrototype = String;
pub type BigIntPrototype = String;
pub type BigNumPrototype = String;
pub type VkeyPrototype = String;
pub type DNSRecordAorAAAAPrototype = String;
pub type DNSRecordSRVPrototype = String;
pub type BlockHashPrototype = String;
pub type DataHashPrototype = String;
pub type Ed25519KeyHashPrototype = String;
pub type Ed25519KeyHashesPrototype = Vec<String>;
pub type Ed25519SignaturePrototype = String;
pub type GenesisDelegateHashPrototype = String;
pub type GenesisHashPrototype = String;
pub type GenesisHashesPrototype = Vec<String>;
pub type IntPrototype = String;
pub type KESVKeyPrototype = String;
pub type PoolMetadataHashPrototype = String;
pub type PublicKeyPrototype = String;
pub type RewardAddressPrototype = String;
pub type RewardAddressesPrototype = Vec<String>;
pub type ScriptDataHashPrototype = String;
pub type ScriptHashPrototype = String;
pub type ScriptHashesPrototype = Vec<String>;
pub type TransactionHashPrototype = String;
pub type PlutusScriptPrototype = String;
pub type PlutusScriptsPrototype = Vec<String>;
pub type CostModelPrototype = Vec<String>;

// ============================================================================
// IPv4 and IPv6 Types
// ============================================================================

pub type Ipv4Prototype = [u8; 4];
pub type Ipv6Prototype = [u8; 16];

// ============================================================================
// Nonce Hash (32 bytes)
// ============================================================================

pub type NonceHashPrototype = [u8; 32];

// ============================================================================
// Anchor
// ============================================================================

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct AnchorPrototype {
    pub anchor_data_hash: String,
    pub anchor_url: URLPrototype,
}

// ============================================================================
// Assets and MultiAsset
// ============================================================================

pub type AssetsPrototype = HashMap<String, String>;
pub type MultiAssetPrototype = HashMap<String, AssetsPrototype>;
pub type MintPrototype = MultiAssetPrototype;

// ============================================================================
// Native Scripts
// ============================================================================

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(tag = "type")]
pub enum NativeScriptPrototype {
    #[serde(rename = "SCRIPT_PUBKEY")]
    ScriptPubkey { value: ScriptPubkeyPrototype },
    #[serde(rename = "SCRIPT_ALL")]
    ScriptAll { value: ScriptAllPrototype },
    #[serde(rename = "SCRIPT_ANY")]
    ScriptAny { value: ScriptAnyPrototype },
    #[serde(rename = "SCRIPT_N_OF_K")]
    ScriptNOfK { value: ScriptNOfKPrototype },
    #[serde(rename = "TIMELOCK_START")]
    TimelockStart { value: TimelockStartPrototype },
    #[serde(rename = "TIMELOCK_EXPIRY")]
    TimelockExpiry { value: TimelockExpiryPrototype },
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct ScriptPubkeyPrototype {
    pub addr_keyhash: String,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct ScriptAllPrototype {
    pub native_scripts: Vec<NativeScriptPrototype>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct ScriptAnyPrototype {
    pub native_scripts: Vec<NativeScriptPrototype>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct ScriptNOfKPrototype {
    pub n: u32,
    pub native_scripts: Vec<NativeScriptPrototype>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct TimelockStartPrototype {
    pub slot: String,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct TimelockExpiryPrototype {
    pub slot: String,
}

pub type NativeScriptsPrototype = Vec<NativeScriptPrototype>;

// ============================================================================
// Credential Types
// ============================================================================

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(tag = "type")]
pub enum CredTypePrototype {
    #[serde(rename = "SCRIPT")]
    Script { value: String },
    #[serde(rename = "KEY")]
    Key { value: String },
}

pub type CredentialPrototype = CredTypePrototype;
pub type CredentialsPrototype = Vec<CredTypePrototype>;

// ============================================================================
// Relay Types
// ============================================================================

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(tag = "type")]
pub enum RelayPrototype {
    #[serde(rename = "SINGLE_HOST_ADDR")]
    SingleHostAddr { value: SingleHostAddrPrototype },
    #[serde(rename = "SINGLE_HOST_NAME")]
    SingleHostName { value: SingleHostNamePrototype },
    #[serde(rename = "MULTI_HOST_NAME")]
    MultiHostName { value: MultiHostNamePrototype },
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct SingleHostAddrPrototype {
    pub ipv4: Option<Ipv4Prototype>,
    pub ipv6: Option<Ipv6Prototype>,
    pub port: Option<u16>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct SingleHostNamePrototype {
    pub dns_name: DNSRecordAorAAAAPrototype,
    pub port: Option<u16>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct MultiHostNamePrototype {
    pub dns_name: DNSRecordSRVPrototype,
}

pub type RelaysPrototype = Vec<RelayPrototype>;

// ============================================================================
// Unit Interval
// ============================================================================

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct UnitIntervalPrototype {
    pub denominator: String,
    pub numerator: String,
}

// ============================================================================
// Protocol Version
// ============================================================================

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct ProtocolVersionPrototype {
    pub major: u32,
    pub minor: u32,
}

// ============================================================================
// Pool Types
// ============================================================================

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct PoolMetadataPrototype {
    pub pool_metadata_hash: String,
    pub url: URLPrototype,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct PoolParamsPrototype {
    pub cost: String,
    pub margin: UnitIntervalPrototype,
    pub operator: String,
    pub pledge: String,
    pub pool_metadata: Option<PoolMetadataPrototype>,
    pub pool_owners: Vec<String>,
    pub relays: RelaysPrototype,
    pub reward_account: String,
    pub vrf_keyhash: String,
}

// ============================================================================
// MIR Types
// ============================================================================

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(tag = "type")]
pub enum MIRPotPrototype {
    #[serde(rename = "RESERVES")]
    Reserves,
    #[serde(rename = "TREASURY")]
    Treasury,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct StakeToCoinPrototype {
    pub amount: String,
    pub stake_cred: CredTypePrototype,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(tag = "type")]
pub enum MIREnumPrototype {
    #[serde(rename = "TO_OTHER_POT")]
    ToOtherPot { value: String },
    #[serde(rename = "TO_STAKE_CREDENTIALS")]
    ToStakeCredentials { value: Vec<StakeToCoinPrototype> },
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct MoveInstantaneousRewardPrototype {
    pub pot: MIRPotPrototype,
    pub variant: MIREnumPrototype,
}

pub type MIRToStakeCredentialsPrototype = Vec<StakeToCoinPrototype>;

// ============================================================================
// DRep Types
// ============================================================================

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(tag = "type")]
pub enum DRepPrototype {
    #[serde(rename = "ALWAYS_ABSTAIN")]
    AlwaysAbstain,
    #[serde(rename = "ALWAYS_NO_CONFIDENCE")]
    AlwaysNoConfidence,
    #[serde(rename = "KEY_HASH")]
    KeyHash { value: String },
    #[serde(rename = "SCRIPT_HASH")]
    ScriptHash { value: String },
}

// ============================================================================
// Certificates
// ============================================================================

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct StakeRegistrationPrototype {
    pub coin: Option<String>,
    pub stake_credential: CredTypePrototype,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct StakeDeregistrationPrototype {
    pub coin: Option<String>,
    pub stake_credential: CredTypePrototype,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct StakeDelegationPrototype {
    pub pool_keyhash: String,
    pub stake_credential: CredTypePrototype,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct PoolRegistrationPrototype {
    pub pool_params: PoolParamsPrototype,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct PoolRetirementPrototype {
    pub epoch: u32,
    pub pool_keyhash: String,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct GenesisKeyDelegationPrototype {
    pub genesis_delegate_hash: String,
    pub genesishash: String,
    pub vrf_keyhash: String,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct MoveInstantaneousRewardsCertPrototype {
    pub move_instantaneous_reward: MoveInstantaneousRewardPrototype,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct CommitteeHotAuthPrototype {
    pub committee_cold_credential: CredTypePrototype,
    pub committee_hot_credential: CredTypePrototype,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct CommitteeColdResignPrototype {
    pub anchor: Option<AnchorPrototype>,
    pub committee_cold_credential: CredTypePrototype,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct DRepDeregistrationPrototype {
    pub coin: String,
    pub voting_credential: CredTypePrototype,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct DRepRegistrationPrototype {
    pub anchor: Option<AnchorPrototype>,
    pub coin: String,
    pub voting_credential: CredTypePrototype,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct DRepUpdatePrototype {
    pub anchor: Option<AnchorPrototype>,
    pub voting_credential: CredTypePrototype,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct StakeAndVoteDelegationPrototype {
    pub drep: DRepPrototype,
    pub pool_keyhash: String,
    pub stake_credential: CredTypePrototype,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct StakeRegistrationAndDelegationPrototype {
    pub coin: String,
    pub pool_keyhash: String,
    pub stake_credential: CredTypePrototype,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct StakeVoteRegistrationAndDelegationPrototype {
    pub coin: String,
    pub drep: DRepPrototype,
    pub pool_keyhash: String,
    pub stake_credential: CredTypePrototype,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct VoteDelegationPrototype {
    pub drep: DRepPrototype,
    pub stake_credential: CredTypePrototype,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct VoteRegistrationAndDelegationPrototype {
    pub coin: String,
    pub drep: DRepPrototype,
    pub stake_credential: CredTypePrototype,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(tag = "type")]
pub enum CertificatePrototype {
    #[serde(rename = "STAKE_REGISTRATION")]
    StakeRegistration { value: StakeRegistrationPrototype },
    #[serde(rename = "STAKE_DEREGISTRATION")]
    StakeDeregistration { value: StakeDeregistrationPrototype },
    #[serde(rename = "STAKE_DELEGATION")]
    StakeDelegation { value: StakeDelegationPrototype },
    #[serde(rename = "POOL_REGISTRATION")]
    PoolRegistration { value: PoolRegistrationPrototype },
    #[serde(rename = "POOL_RETIREMENT")]
    PoolRetirement { value: PoolRetirementPrototype },
    #[serde(rename = "GENESIS_KEY_DELEGATION")]
    GenesisKeyDelegation {
        value: GenesisKeyDelegationPrototype,
    },
    #[serde(rename = "MOVE_INSTANTANEOUS_REWARDS_CERT")]
    MoveInstantaneousRewardsCert {
        value: MoveInstantaneousRewardsCertPrototype,
    },
    #[serde(rename = "COMMITTEE_HOT_AUTH")]
    CommitteeHotAuth { value: CommitteeHotAuthPrototype },
    #[serde(rename = "COMMITTEE_COLD_RESIGN")]
    CommitteeColdResign { value: CommitteeColdResignPrototype },
    #[serde(rename = "DREP_DEREGISTRATION")]
    DRepDeregistration { value: DRepDeregistrationPrototype },
    #[serde(rename = "DREP_REGISTRATION")]
    DRepRegistration { value: DRepRegistrationPrototype },
    #[serde(rename = "DREP_UPDATE")]
    DRepUpdate { value: DRepUpdatePrototype },
    #[serde(rename = "STAKE_AND_VOTE_DELEGATION")]
    StakeAndVoteDelegation {
        value: StakeAndVoteDelegationPrototype,
    },
    #[serde(rename = "STAKE_REGISTRATION_AND_DELEGATION")]
    StakeRegistrationAndDelegation {
        value: StakeRegistrationAndDelegationPrototype,
    },
    #[serde(rename = "STAKE_VOTE_REGISTRATION_AND_DELEGATION")]
    StakeVoteRegistrationAndDelegation {
        value: StakeVoteRegistrationAndDelegationPrototype,
    },
    #[serde(rename = "VOTE_DELEGATION")]
    VoteDelegation { value: VoteDelegationPrototype },
    #[serde(rename = "VOTE_REGISTRATION_AND_DELEGATION")]
    VoteRegistrationAndDelegation {
        value: VoteRegistrationAndDelegationPrototype,
    },
}

pub type CertificatesPrototype = Vec<CertificatePrototype>;

// ============================================================================
// Plutus Data Types
// ============================================================================

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(tag = "type")]
pub enum PlutusDataVariant {
    #[serde(rename = "CBOR")]
    Cbor { hex: String },
    #[serde(rename = "MANUAL")]
    Manual { data: PlutusData },
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(tag = "type")]
pub enum PlutusData {
    #[serde(rename = "INTEGER")]
    Integer { value: i128 },
    #[serde(rename = "BYTES")]
    Bytes { value: String },
    #[serde(rename = "LIST")]
    List { value: Vec<PlutusData> },
    #[serde(rename = "MAP")]
    Map {
        value: Vec<(PlutusData, PlutusData)>,
    },
    #[serde(rename = "CONSTR")]
    Constr {
        alternative: u64,
        fields: Vec<PlutusData>,
    },
}

// ============================================================================
// Data Option (for output datum)
// ============================================================================

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(tag = "type")]
pub enum DataOptionPrototype {
    #[serde(rename = "DATA_HASH")]
    DataHash { value: String },
    #[serde(rename = "DATA")]
    Data { value: PlutusDataVariant },
}

// ============================================================================
// Script Reference
// ============================================================================

/// ScriptRef is stored as a CBOR hex string
pub type ScriptRefPrototype = String;

// ============================================================================
// Network ID
// ============================================================================

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(tag = "type")]
pub enum NetworkIdPrototype {
    #[serde(rename = "TESTNET")]
    Testnet,
    #[serde(rename = "MAINNET")]
    Mainnet,
}

// ============================================================================
// Value and Transaction Output
// ============================================================================

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct ValuePrototype {
    pub coin: String,
    pub multiasset: Option<MultiAssetPrototype>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct TransactionOutputPrototype {
    pub address: String,
    pub amount: ValuePrototype,
    pub plutus_data: Option<DataOptionPrototype>,
    pub script_ref: Option<ScriptRefPrototype>,
}

pub type TransactionOutputsPrototype = Vec<TransactionOutputPrototype>;

// ============================================================================
// Transaction Input
// ============================================================================

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct TransactionInputPrototype {
    pub index: u32,
    pub transaction_id: String,
}

pub type TransactionInputsPrototype = Vec<TransactionInputPrototype>;

// ============================================================================
// Transaction Unspent Output (UTxO)
// ============================================================================

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct TransactionUnspentOutputPrototype {
    pub input: TransactionInputPrototype,
    pub output: TransactionOutputPrototype,
}

pub type TransactionUnspentOutputsPrototype = Vec<TransactionUnspentOutputPrototype>;

// ============================================================================
// Withdrawals
// ============================================================================

pub type WithdrawalsPrototype = HashMap<String, String>;

// ============================================================================
// Voting Types
// ============================================================================

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(tag = "type")]
pub enum VoterPrototype {
    #[serde(rename = "CONSTITUTIONAL_COMMITTEE_HOT_CRED")]
    ConstitutionalCommitteeHotCred { value: CredTypePrototype },
    #[serde(rename = "DREP")]
    DRep { value: CredTypePrototype },
    #[serde(rename = "STAKING_POOL")]
    StakingPool { value: String },
}

pub type VotersPrototype = Vec<VoterPrototype>;

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(tag = "type")]
pub enum VoteKindPrototype {
    #[serde(rename = "NO")]
    No,
    #[serde(rename = "YES")]
    Yes,
    #[serde(rename = "ABSTAIN")]
    Abstain,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct GovernanceActionIdPrototype {
    pub index: u32,
    pub transaction_id: String,
}

pub type GovernanceActionIdsPrototype = Vec<GovernanceActionIdPrototype>;

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct VotingProcedurePrototype {
    pub anchor: Option<AnchorPrototype>,
    pub vote: VoteKindPrototype,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct VotePrototype {
    pub action_id: GovernanceActionIdPrototype,
    pub voting_procedure: VotingProcedurePrototype,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct VoterVotesPrototype {
    pub voter: VoterPrototype,
    pub votes: Vec<VotePrototype>,
}

pub type VotingProceduresPrototype = Vec<VoterVotesPrototype>;

// ============================================================================
// Governance Actions
// ============================================================================

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct ParameterChangeActionPrototype {
    pub gov_action_id: Option<GovernanceActionIdPrototype>,
    pub policy_hash: Option<String>,
    pub protocol_param_updates: ProtocolParamUpdatePrototype,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct HardForkInitiationActionPrototype {
    pub gov_action_id: Option<GovernanceActionIdPrototype>,
    pub protocol_version: ProtocolVersionPrototype,
}

pub type TreasuryWithdrawalsPrototype = HashMap<String, String>;

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct TreasuryWithdrawalsActionPrototype {
    pub policy_hash: Option<String>,
    pub withdrawals: TreasuryWithdrawalsPrototype,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct NoConfidenceActionPrototype {
    pub gov_action_id: Option<GovernanceActionIdPrototype>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct CommitteeMemberPrototype {
    pub stake_credential: CredTypePrototype,
    pub term_limit: u32,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct CommitteePrototype {
    pub members: Vec<CommitteeMemberPrototype>,
    pub quorum_threshold: UnitIntervalPrototype,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct UpdateCommitteeActionPrototype {
    pub committee: CommitteePrototype,
    pub gov_action_id: Option<GovernanceActionIdPrototype>,
    pub members_to_remove: Vec<CredTypePrototype>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct ConstitutionPrototype {
    pub anchor: AnchorPrototype,
    pub script_hash: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct NewConstitutionActionPrototype {
    pub constitution: ConstitutionPrototype,
    pub gov_action_id: Option<GovernanceActionIdPrototype>,
}

pub type InfoActionPrototype = ();

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(tag = "type")]
pub enum GovernanceActionPrototype {
    #[serde(rename = "PARAMETER_CHANGE_ACTION")]
    ParameterChangeAction {
        value: ParameterChangeActionPrototype,
    },
    #[serde(rename = "HARD_FORK_INITIATION_ACTION")]
    HardForkInitiationAction {
        value: HardForkInitiationActionPrototype,
    },
    #[serde(rename = "TREASURY_WITHDRAWALS_ACTION")]
    TreasuryWithdrawalsAction {
        value: TreasuryWithdrawalsActionPrototype,
    },
    #[serde(rename = "NO_CONFIDENCE_ACTION")]
    NoConfidenceAction { value: NoConfidenceActionPrototype },
    #[serde(rename = "UPDATE_COMMITTEE_ACTION")]
    UpdateCommitteeAction {
        value: UpdateCommitteeActionPrototype,
    },
    #[serde(rename = "NEW_CONSTITUTION_ACTION")]
    NewConstitutionAction {
        value: NewConstitutionActionPrototype,
    },
    #[serde(rename = "INFO_ACTION")]
    InfoAction,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct VotingProposalPrototype {
    pub anchor: AnchorPrototype,
    pub deposit: String,
    pub governance_action: GovernanceActionPrototype,
    pub reward_account: String,
}

pub type VotingProposalsPrototype = Vec<VotingProposalPrototype>;

// ============================================================================
// Protocol Parameter Update
// ============================================================================

pub type CostmdlsPrototype = HashMap<String, CostModelPrototype>;

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct DRepVotingThresholdsPrototype {
    pub committee_no_confidence: UnitIntervalPrototype,
    pub committee_normal: UnitIntervalPrototype,
    pub hard_fork_initiation: UnitIntervalPrototype,
    pub motion_no_confidence: UnitIntervalPrototype,
    pub pp_economic_group: UnitIntervalPrototype,
    pub pp_governance_group: UnitIntervalPrototype,
    pub pp_network_group: UnitIntervalPrototype,
    pub pp_technical_group: UnitIntervalPrototype,
    pub treasury_withdrawal: UnitIntervalPrototype,
    pub update_constitution: UnitIntervalPrototype,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct PoolVotingThresholdsPrototype {
    pub committee_no_confidence: UnitIntervalPrototype,
    pub committee_normal: UnitIntervalPrototype,
    pub hard_fork_initiation: UnitIntervalPrototype,
    pub motion_no_confidence: UnitIntervalPrototype,
    pub security_relevant_threshold: UnitIntervalPrototype,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct ExUnitPricesPrototype {
    pub mem_price: UnitIntervalPrototype,
    pub step_price: UnitIntervalPrototype,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct NoncePrototype {
    pub hash: Option<NonceHashPrototype>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct ExUnitsPrototype {
    pub mem: String,
    pub steps: String,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct ProtocolParamUpdatePrototype {
    pub ada_per_utxo_byte: Option<String>,
    pub collateral_percentage: Option<u32>,
    pub committee_term_limit: Option<u32>,
    pub cost_models: Option<CostmdlsPrototype>,
    pub d: Option<UnitIntervalPrototype>,
    pub drep_deposit: Option<String>,
    pub drep_inactivity_period: Option<u32>,
    pub drep_voting_thresholds: Option<DRepVotingThresholdsPrototype>,
    pub execution_costs: Option<ExUnitPricesPrototype>,
    pub expansion_rate: Option<UnitIntervalPrototype>,
    pub extra_entropy: Option<NoncePrototype>,
    pub governance_action_deposit: Option<String>,
    pub governance_action_validity_period: Option<u32>,
    pub key_deposit: Option<String>,
    pub max_block_body_size: Option<u32>,
    pub max_block_ex_units: Option<ExUnitsPrototype>,
    pub max_block_header_size: Option<u32>,
    pub max_collateral_inputs: Option<u32>,
    pub max_epoch: Option<u32>,
    pub max_tx_ex_units: Option<ExUnitsPrototype>,
    pub max_tx_size: Option<u32>,
    pub max_value_size: Option<u32>,
    pub min_committee_size: Option<u32>,
    pub min_pool_cost: Option<String>,
    pub minfee_a: Option<String>,
    pub minfee_b: Option<String>,
    pub n_opt: Option<u32>,
    pub pool_deposit: Option<String>,
    pub pool_pledge_influence: Option<UnitIntervalPrototype>,
    pub pool_voting_thresholds: Option<PoolVotingThresholdsPrototype>,
    pub protocol_version: Option<ProtocolVersionPrototype>,
    pub ref_script_coins_per_byte: Option<UnitIntervalPrototype>,
    pub treasury_growth_rate: Option<UnitIntervalPrototype>,
}

pub type ProposedProtocolParameterUpdatesPrototype = HashMap<String, ProtocolParamUpdatePrototype>;

// ============================================================================
// Update
// ============================================================================

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct UpdatePrototype {
    pub epoch: u32,
    pub proposed_protocol_parameter_updates: ProposedProtocolParameterUpdatesPrototype,
}

// ============================================================================
// Redeemer
// ============================================================================

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(tag = "type")]
pub enum RedeemerTagPrototype {
    #[serde(rename = "SPEND")]
    Spend,
    #[serde(rename = "MINT")]
    Mint,
    #[serde(rename = "CERT")]
    Cert,
    #[serde(rename = "REWARD")]
    Reward,
    #[serde(rename = "VOTE")]
    Vote,
    #[serde(rename = "VOTING_PROPOSAL")]
    VotingProposal,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct RedeemerPrototype {
    pub data: PlutusDataVariant,
    pub ex_units: ExUnitsPrototype,
    pub index: String,
    pub tag: RedeemerTagPrototype,
}

pub type RedeemersPrototype = Vec<RedeemerPrototype>;

// ============================================================================
// Language
// ============================================================================

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(tag = "type")]
pub enum LanguageKindPrototype {
    #[serde(rename = "PLUTUS_V1")]
    PlutusV1,
    #[serde(rename = "PLUTUS_V2")]
    PlutusV2,
    #[serde(rename = "PLUTUS_V3")]
    PlutusV3,
}

pub type LanguagePrototype = LanguageKindPrototype;
pub type LanguagesPrototype = Vec<LanguagePrototype>;

// ============================================================================
// Witness Types
// ============================================================================

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct VkeywitnessPrototype {
    pub signature: String,
    pub vkey: VkeyPrototype,
}

pub type VkeywitnessesPrototype = Vec<VkeywitnessPrototype>;

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct BootstrapWitnessPrototype {
    pub attributes: Vec<u8>,
    pub chain_code: Vec<u8>,
    pub signature: String,
    pub vkey: VkeyPrototype,
}

pub type BootstrapWitnessesPrototype = Vec<BootstrapWitnessPrototype>;

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct PlutusListPrototype {
    pub definite_encoding: Option<bool>,
    pub elems: Vec<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct TransactionWitnessSetPrototype {
    pub bootstraps: Option<Vec<BootstrapWitnessPrototype>>,
    pub native_scripts: Option<Vec<NativeScriptPrototype>>,
    pub plutus_data: Option<PlutusListPrototype>,
    pub plutus_scripts: Option<Vec<String>>,
    pub redeemers: Option<Vec<RedeemerPrototype>>,
    pub vkeys: Option<Vec<VkeywitnessPrototype>>,
}

// ============================================================================
// Metadata Types
// ============================================================================

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(tag = "type")]
pub enum MetadatumPrototype {
    #[serde(rename = "INT")]
    Int { value: i128 },
    #[serde(rename = "BYTES")]
    Bytes { value: Vec<u8> },
    #[serde(rename = "STRING")]
    String { value: String },
    #[serde(rename = "LIST")]
    List { value: Vec<MetadatumPrototype> },
    #[serde(rename = "MAP")]
    Map {
        value: Vec<(MetadatumPrototype, MetadatumPrototype)>,
    },
}

pub type TxMetadataPrototype = HashMap<String, MetadatumPrototype>;

// ============================================================================
// Auxiliary Data
// ============================================================================

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct AuxiliaryDataPrototype {
    pub metadata: Option<TxMetadataPrototype>,
    pub native_scripts: Option<Vec<NativeScriptPrototype>>,
    pub plutus_scripts: Option<Vec<String>>,
    pub prefer_alonzo_format: bool,
}

pub type AuxiliaryDataSetPrototype = HashMap<String, AuxiliaryDataPrototype>;

// ============================================================================
// Transaction Body
// ============================================================================

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct TransactionBodyPrototype {
    pub auxiliary_data_hash: Option<String>,
    pub certs: Option<Vec<CertificatePrototype>>,
    pub collateral: Option<Vec<TransactionInputPrototype>>,
    pub collateral_return: Option<TransactionOutputPrototype>,
    pub current_treasury_value: Option<String>,
    pub donation: Option<String>,
    pub fee: String,
    pub inputs: Vec<TransactionInputPrototype>,
    pub mint: Option<MintPrototype>,
    pub network_id: Option<NetworkIdPrototype>,
    pub outputs: TransactionOutputsPrototype,
    pub reference_inputs: Option<Vec<TransactionInputPrototype>>,
    pub required_signers: Option<Vec<String>>,
    pub script_data_hash: Option<String>,
    pub total_collateral: Option<String>,
    pub ttl: Option<String>,
    pub update: Option<UpdatePrototype>,
    pub validity_start_interval: Option<String>,
    pub voting_procedures: Option<Vec<VoterVotesPrototype>>,
    pub voting_proposals: Option<Vec<VotingProposalPrototype>>,
    pub withdrawals: Option<WithdrawalsPrototype>,
}

pub type TransactionBodiesPrototype = Vec<TransactionBodyPrototype>;

// ============================================================================
// Transaction (Main Type)
// ============================================================================

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct TransactionPrototype {
    pub auxiliary_data: Option<AuxiliaryDataPrototype>,
    pub body: TransactionBodyPrototype,
    pub is_valid: bool,
    pub witness_set: TransactionWitnessSetPrototype,
}

// ============================================================================
// Helper Implementation for Parsing
// ============================================================================

impl TransactionPrototype {
    /// Parse a Transaction from a JSON string
    pub fn from_json(json_str: &str) -> Result<Self, serde_json::Error> {
        serde_json::from_str(json_str)
    }

    /// Serialize the Transaction to a JSON string
    pub fn to_json(&self) -> Result<String, serde_json::Error> {
        serde_json::to_string(self)
    }

    /// Serialize the Transaction to a pretty-printed JSON string
    pub fn to_json_pretty(&self) -> Result<String, serde_json::Error> {
        serde_json::to_string_pretty(self)
    }
}