biglup-cometa 1.2.1.post1__py3-none-linux_armv7l.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- biglup_cometa-1.2.1.post1.dist-info/METADATA +1197 -0
- biglup_cometa-1.2.1.post1.dist-info/RECORD +251 -0
- biglup_cometa-1.2.1.post1.dist-info/WHEEL +5 -0
- biglup_cometa-1.2.1.post1.dist-info/licenses/LICENSE +201 -0
- biglup_cometa-1.2.1.post1.dist-info/top_level.txt +1 -0
- cometa/__init__.py +554 -0
- cometa/_aiken_ffi.py +92 -0
- cometa/_cdef/aiken-c.cdef +32 -0
- cometa/_cdef/cardano-c.cdef +2947 -0
- cometa/_ffi.py +93 -0
- cometa/_native/linux-armv7/libaiken_c.so +0 -0
- cometa/_native/linux-armv7/libcardano-c.so +0 -0
- cometa/address/__init__.py +39 -0
- cometa/address/address.py +323 -0
- cometa/address/address_type.py +59 -0
- cometa/address/base_address.py +238 -0
- cometa/address/byron_address.py +263 -0
- cometa/address/byron_address_attributes.py +49 -0
- cometa/address/byron_address_type.py +34 -0
- cometa/address/enterprise_address.py +224 -0
- cometa/address/pointer_address.py +244 -0
- cometa/address/reward_address.py +222 -0
- cometa/address/stake_pointer.py +49 -0
- cometa/aiken/__init__.py +27 -0
- cometa/aiken/aiken_tx_evaluator.py +298 -0
- cometa/aiken/script_util.py +100 -0
- cometa/assets/__init__.py +35 -0
- cometa/assets/asset_id.py +245 -0
- cometa/assets/asset_id_list.py +193 -0
- cometa/assets/asset_id_map.py +270 -0
- cometa/assets/asset_name.py +241 -0
- cometa/assets/asset_name_list.py +203 -0
- cometa/assets/asset_name_map.py +330 -0
- cometa/assets/multi_asset.py +361 -0
- cometa/assets/policy_id_list.py +195 -0
- cometa/auxiliary_data/__init__.py +39 -0
- cometa/auxiliary_data/auxiliary_data.py +186 -0
- cometa/auxiliary_data/metadatum.py +516 -0
- cometa/auxiliary_data/metadatum_kind.py +41 -0
- cometa/auxiliary_data/metadatum_label_list.py +195 -0
- cometa/auxiliary_data/metadatum_list.py +286 -0
- cometa/auxiliary_data/metadatum_map.py +305 -0
- cometa/auxiliary_data/plutus_v1_script_list.py +289 -0
- cometa/auxiliary_data/plutus_v2_script_list.py +296 -0
- cometa/auxiliary_data/plutus_v3_script_list.py +265 -0
- cometa/auxiliary_data/transaction_metadata.py +286 -0
- cometa/bip39/__init__.py +25 -0
- cometa/bip39/bip39.py +116 -0
- cometa/buffer.py +536 -0
- cometa/cardano.py +83 -0
- cometa/cbor/__init__.py +31 -0
- cometa/cbor/cbor_major_type.py +96 -0
- cometa/cbor/cbor_reader.py +303 -0
- cometa/cbor/cbor_reader_state.py +155 -0
- cometa/cbor/cbor_simple_value.py +73 -0
- cometa/cbor/cbor_tag.py +113 -0
- cometa/cbor/cbor_writer.py +273 -0
- cometa/certificates/__init__.py +71 -0
- cometa/certificates/auth_committee_hot_cert.py +204 -0
- cometa/certificates/certificate.py +714 -0
- cometa/certificates/certificate_set.py +230 -0
- cometa/certificates/certificate_type.py +103 -0
- cometa/certificates/genesis_key_delegation_cert.py +225 -0
- cometa/certificates/mir_cert.py +210 -0
- cometa/certificates/mir_cert_pot_type.py +31 -0
- cometa/certificates/mir_cert_type.py +32 -0
- cometa/certificates/mir_to_pot_cert.py +186 -0
- cometa/certificates/mir_to_stake_creds_cert.py +261 -0
- cometa/certificates/pool_registration_cert.py +156 -0
- cometa/certificates/pool_retirement_cert.py +182 -0
- cometa/certificates/register_drep_cert.py +226 -0
- cometa/certificates/registration_cert.py +186 -0
- cometa/certificates/resign_committee_cold_cert.py +201 -0
- cometa/certificates/stake_delegation_cert.py +186 -0
- cometa/certificates/stake_deregistration_cert.py +156 -0
- cometa/certificates/stake_registration_cert.py +156 -0
- cometa/certificates/stake_registration_delegation_cert.py +227 -0
- cometa/certificates/stake_vote_delegation_cert.py +228 -0
- cometa/certificates/stake_vote_registration_delegation_cert.py +274 -0
- cometa/certificates/unregister_drep_cert.py +184 -0
- cometa/certificates/unregistration_cert.py +186 -0
- cometa/certificates/update_drep_cert.py +193 -0
- cometa/certificates/vote_delegation_cert.py +187 -0
- cometa/certificates/vote_registration_delegation_cert.py +227 -0
- cometa/common/__init__.py +55 -0
- cometa/common/anchor.py +282 -0
- cometa/common/bigint.py +574 -0
- cometa/common/byte_order.py +38 -0
- cometa/common/credential.py +337 -0
- cometa/common/credential_type.py +32 -0
- cometa/common/datum.py +295 -0
- cometa/common/datum_type.py +44 -0
- cometa/common/drep.py +274 -0
- cometa/common/drep_type.py +53 -0
- cometa/common/ex_units.py +177 -0
- cometa/common/governance_action_id.py +300 -0
- cometa/common/governance_key_type.py +35 -0
- cometa/common/network_id.py +31 -0
- cometa/common/network_magic.py +99 -0
- cometa/common/protocol_version.py +183 -0
- cometa/common/reward_address_list.py +194 -0
- cometa/common/slot_config.py +92 -0
- cometa/common/unit_interval.py +222 -0
- cometa/common/utxo.py +206 -0
- cometa/common/utxo_list.py +335 -0
- cometa/common/withdrawal_map.py +338 -0
- cometa/cryptography/__init__.py +43 -0
- cometa/cryptography/bip32_private_key.py +283 -0
- cometa/cryptography/bip32_public_key.py +210 -0
- cometa/cryptography/blake2b_hash.py +283 -0
- cometa/cryptography/blake2b_hash_set.py +213 -0
- cometa/cryptography/blake2b_hash_size.py +44 -0
- cometa/cryptography/crc32.py +42 -0
- cometa/cryptography/ed25519_private_key.py +252 -0
- cometa/cryptography/ed25519_public_key.py +189 -0
- cometa/cryptography/ed25519_signature.py +150 -0
- cometa/cryptography/emip3.py +134 -0
- cometa/cryptography/pbkdf2.py +69 -0
- cometa/encoding/__init__.py +20 -0
- cometa/encoding/base58.py +112 -0
- cometa/encoding/bech32.py +131 -0
- cometa/errors.py +81 -0
- cometa/json/__init__.py +23 -0
- cometa/json/json_context.py +40 -0
- cometa/json/json_format.py +36 -0
- cometa/json/json_object.py +363 -0
- cometa/json/json_object_type.py +54 -0
- cometa/json/json_writer.py +325 -0
- cometa/key_handler/__init__.py +43 -0
- cometa/key_handler/secure_key_handler.py +278 -0
- cometa/key_handler/software_bip32_secure_key_handler.py +360 -0
- cometa/key_handler/software_ed25519_secure_key_handler.py +300 -0
- cometa/message_signing/__init__.py +19 -0
- cometa/message_signing/cip8.py +185 -0
- cometa/plutus_data/__init__.py +30 -0
- cometa/plutus_data/constr_plutus_data.py +226 -0
- cometa/plutus_data/plutus_data.py +492 -0
- cometa/plutus_data/plutus_data_kind.py +40 -0
- cometa/plutus_data/plutus_list.py +402 -0
- cometa/plutus_data/plutus_map.py +367 -0
- cometa/pool_params/__init__.py +43 -0
- cometa/pool_params/ipv4.py +242 -0
- cometa/pool_params/ipv6.py +190 -0
- cometa/pool_params/multi_host_name_relay.py +145 -0
- cometa/pool_params/pool_metadata.py +195 -0
- cometa/pool_params/pool_owners.py +196 -0
- cometa/pool_params/pool_params.py +331 -0
- cometa/pool_params/relay.py +269 -0
- cometa/pool_params/relay_type.py +54 -0
- cometa/pool_params/relays.py +194 -0
- cometa/pool_params/single_host_addr_relay.py +210 -0
- cometa/pool_params/single_host_name_relay.py +177 -0
- cometa/proposal_procedures/__init__.py +48 -0
- cometa/proposal_procedures/committee.py +262 -0
- cometa/proposal_procedures/committee_members_map.py +290 -0
- cometa/proposal_procedures/constitution.py +196 -0
- cometa/proposal_procedures/credential_set.py +231 -0
- cometa/proposal_procedures/governance_action_type.py +66 -0
- cometa/proposal_procedures/hard_fork_initiation_action.py +212 -0
- cometa/proposal_procedures/info_action.py +124 -0
- cometa/proposal_procedures/new_constitution_action.py +207 -0
- cometa/proposal_procedures/no_confidence_action.py +172 -0
- cometa/proposal_procedures/parameter_change_action.py +246 -0
- cometa/proposal_procedures/proposal_procedure.py +613 -0
- cometa/proposal_procedures/proposal_procedure_set.py +218 -0
- cometa/proposal_procedures/treasury_withdrawals_action.py +204 -0
- cometa/proposal_procedures/update_committee_action.py +287 -0
- cometa/protocol_params/__init__.py +37 -0
- cometa/protocol_params/cost_model.py +239 -0
- cometa/protocol_params/costmdls.py +225 -0
- cometa/protocol_params/drep_voting_thresholds.py +321 -0
- cometa/protocol_params/ex_unit_prices.py +182 -0
- cometa/protocol_params/pool_voting_thresholds.py +226 -0
- cometa/protocol_params/proposed_param_updates.py +255 -0
- cometa/protocol_params/protocol_param_update.py +746 -0
- cometa/protocol_params/protocol_parameters.py +503 -0
- cometa/protocol_params/update.py +186 -0
- cometa/providers/__init__.py +30 -0
- cometa/providers/blockfrost_provider.py +810 -0
- cometa/providers/c_provider_wrapper.py +399 -0
- cometa/providers/provider.py +210 -0
- cometa/providers/provider_tx_evaluator.py +83 -0
- cometa/providers/python_provider_adapter.py +468 -0
- cometa/scripts/__init__.py +62 -0
- cometa/scripts/native_scripts/__init__.py +51 -0
- cometa/scripts/native_scripts/native_script.py +412 -0
- cometa/scripts/native_scripts/native_script_list.py +270 -0
- cometa/scripts/native_scripts/native_script_type.py +75 -0
- cometa/scripts/native_scripts/script_all.py +196 -0
- cometa/scripts/native_scripts/script_any.py +196 -0
- cometa/scripts/native_scripts/script_invalid_after.py +187 -0
- cometa/scripts/native_scripts/script_invalid_before.py +218 -0
- cometa/scripts/native_scripts/script_n_of_k.py +223 -0
- cometa/scripts/native_scripts/script_pubkey.py +171 -0
- cometa/scripts/plutus_scripts/__init__.py +27 -0
- cometa/scripts/plutus_scripts/plutus_language_version.py +36 -0
- cometa/scripts/plutus_scripts/plutus_v1_script.py +187 -0
- cometa/scripts/plutus_scripts/plutus_v2_script.py +192 -0
- cometa/scripts/plutus_scripts/plutus_v3_script.py +225 -0
- cometa/scripts/script.py +366 -0
- cometa/scripts/script_language.py +67 -0
- cometa/time.py +82 -0
- cometa/transaction/__init__.py +21 -0
- cometa/transaction/transaction.py +425 -0
- cometa/transaction_body/__init__.py +31 -0
- cometa/transaction_body/transaction_body.py +858 -0
- cometa/transaction_body/transaction_input.py +258 -0
- cometa/transaction_body/transaction_input_set.py +233 -0
- cometa/transaction_body/transaction_output.py +272 -0
- cometa/transaction_body/transaction_output_list.py +240 -0
- cometa/transaction_body/value.py +562 -0
- cometa/transaction_builder/__init__.py +96 -0
- cometa/transaction_builder/balancing/__init__.py +27 -0
- cometa/transaction_builder/balancing/implicit_coin.py +112 -0
- cometa/transaction_builder/balancing/input_to_redeemer_map.py +278 -0
- cometa/transaction_builder/balancing/transaction_balancing.py +190 -0
- cometa/transaction_builder/coin_selection/__init__.py +32 -0
- cometa/transaction_builder/coin_selection/c_coin_selector_wrapper.py +170 -0
- cometa/transaction_builder/coin_selection/coin_selector.py +90 -0
- cometa/transaction_builder/coin_selection/large_first_coin_selector.py +77 -0
- cometa/transaction_builder/coin_selection/python_coin_selector_adapter.py +201 -0
- cometa/transaction_builder/evaluation/__init__.py +29 -0
- cometa/transaction_builder/evaluation/c_tx_evaluator_wrapper.py +200 -0
- cometa/transaction_builder/evaluation/python_tx_evaluator_adapter.py +167 -0
- cometa/transaction_builder/evaluation/tx_evaluator.py +85 -0
- cometa/transaction_builder/fee.py +364 -0
- cometa/transaction_builder/script_data_hash.py +80 -0
- cometa/transaction_builder/tx_builder.py +2123 -0
- cometa/voting_procedures/__init__.py +35 -0
- cometa/voting_procedures/governance_action_id_list.py +200 -0
- cometa/voting_procedures/vote.py +55 -0
- cometa/voting_procedures/voter.py +181 -0
- cometa/voting_procedures/voter_list.py +194 -0
- cometa/voting_procedures/voter_type.py +63 -0
- cometa/voting_procedures/voting_procedure.py +173 -0
- cometa/voting_procedures/voting_procedure_list.py +194 -0
- cometa/voting_procedures/voting_procedures.py +291 -0
- cometa/witness_set/__init__.py +45 -0
- cometa/witness_set/bootstrap_witness.py +345 -0
- cometa/witness_set/bootstrap_witness_set.py +243 -0
- cometa/witness_set/native_script_set.py +295 -0
- cometa/witness_set/plutus_data_set.py +254 -0
- cometa/witness_set/plutus_v1_script_set.py +231 -0
- cometa/witness_set/plutus_v2_script_set.py +240 -0
- cometa/witness_set/plutus_v3_script_set.py +231 -0
- cometa/witness_set/redeemer.py +260 -0
- cometa/witness_set/redeemer_list.py +285 -0
- cometa/witness_set/redeemer_tag.py +83 -0
- cometa/witness_set/vkey_witness.py +267 -0
- cometa/witness_set/vkey_witness_set.py +239 -0
- cometa/witness_set/witness_set.py +408 -0
|
@@ -0,0 +1,1197 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: biglup-cometa
|
|
3
|
+
Version: 1.2.1.post1
|
|
4
|
+
Summary: Python bindings for libcardano-c (Cometa project)
|
|
5
|
+
Author-email: Angel Castillo <angel.castillob@prototnmail.io>
|
|
6
|
+
License: Apache License
|
|
7
|
+
Version 2.0, January 2004
|
|
8
|
+
http://www.apache.org/licenses/
|
|
9
|
+
|
|
10
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
11
|
+
|
|
12
|
+
1. Definitions.
|
|
13
|
+
|
|
14
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
15
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
16
|
+
|
|
17
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
18
|
+
the copyright owner that is granting the License.
|
|
19
|
+
|
|
20
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
21
|
+
other entities that control, are controlled by, or are under common
|
|
22
|
+
control with that entity. For the purposes of this definition,
|
|
23
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
24
|
+
direction or management of such entity, whether by contract or
|
|
25
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
26
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
27
|
+
|
|
28
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
29
|
+
exercising permissions granted by this License.
|
|
30
|
+
|
|
31
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
32
|
+
including but not limited to software source code, documentation
|
|
33
|
+
source, and configuration files.
|
|
34
|
+
|
|
35
|
+
"Object" form shall mean any form resulting from mechanical
|
|
36
|
+
transformation or translation of a Source form, including but
|
|
37
|
+
not limited to compiled object code, generated documentation,
|
|
38
|
+
and conversions to other media types.
|
|
39
|
+
|
|
40
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
41
|
+
Object form, made available under the License, as indicated by a
|
|
42
|
+
copyright notice that is included in or attached to the work
|
|
43
|
+
(an example is provided in the Appendix below).
|
|
44
|
+
|
|
45
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
46
|
+
form, that is based on (or derived from) the Work and for which the
|
|
47
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
48
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
49
|
+
of this License, Derivative Works shall not include works that remain
|
|
50
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
51
|
+
the Work and Derivative Works thereof.
|
|
52
|
+
|
|
53
|
+
"Contribution" shall mean any work of authorship, including
|
|
54
|
+
the original version of the Work and any modifications or additions
|
|
55
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
56
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
57
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
58
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
59
|
+
means any form of electronic, verbal, or written communication sent
|
|
60
|
+
to the Licensor or its representatives, including but not limited to
|
|
61
|
+
communication on electronic mailing lists, source code control systems,
|
|
62
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
63
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
64
|
+
excluding communication that is conspicuously marked or otherwise
|
|
65
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
66
|
+
|
|
67
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
68
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
69
|
+
subsequently incorporated within the Work.
|
|
70
|
+
|
|
71
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
72
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
73
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
74
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
75
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
76
|
+
Work and such Derivative Works in Source or Object form.
|
|
77
|
+
|
|
78
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
79
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
80
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
81
|
+
(except as stated in this section) patent license to make, have made,
|
|
82
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
83
|
+
where such license applies only to those patent claims licensable
|
|
84
|
+
by such Contributor that are necessarily infringed by their
|
|
85
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
86
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
87
|
+
institute patent litigation against any entity (including a
|
|
88
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
89
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
90
|
+
or contributory patent infringement, then any patent licenses
|
|
91
|
+
granted to You under this License for that Work shall terminate
|
|
92
|
+
as of the date such litigation is filed.
|
|
93
|
+
|
|
94
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
95
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
96
|
+
modifications, and in Source or Object form, provided that You
|
|
97
|
+
meet the following conditions:
|
|
98
|
+
|
|
99
|
+
(a) You must give any other recipients of the Work or
|
|
100
|
+
Derivative Works a copy of this License; and
|
|
101
|
+
|
|
102
|
+
(b) You must cause any modified files to carry prominent notices
|
|
103
|
+
stating that You changed the files; and
|
|
104
|
+
|
|
105
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
106
|
+
that You distribute, all copyright, patent, trademark, and
|
|
107
|
+
attribution notices from the Source form of the Work,
|
|
108
|
+
excluding those notices that do not pertain to any part of
|
|
109
|
+
the Derivative Works; and
|
|
110
|
+
|
|
111
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
112
|
+
distribution, then any Derivative Works that You distribute must
|
|
113
|
+
include a readable copy of the attribution notices contained
|
|
114
|
+
within such NOTICE file, excluding those notices that do not
|
|
115
|
+
pertain to any part of the Derivative Works, in at least one
|
|
116
|
+
of the following places: within a NOTICE text file distributed
|
|
117
|
+
as part of the Derivative Works; within the Source form or
|
|
118
|
+
documentation, if provided along with the Derivative Works; or,
|
|
119
|
+
within a display generated by the Derivative Works, if and
|
|
120
|
+
wherever such third-party notices normally appear. The contents
|
|
121
|
+
of the NOTICE file are for informational purposes only and
|
|
122
|
+
do not modify the License. You may add Your own attribution
|
|
123
|
+
notices within Derivative Works that You distribute, alongside
|
|
124
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
125
|
+
that such additional attribution notices cannot be construed
|
|
126
|
+
as modifying the License.
|
|
127
|
+
|
|
128
|
+
You may add Your own copyright statement to Your modifications and
|
|
129
|
+
may provide additional or different license terms and conditions
|
|
130
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
131
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
132
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
133
|
+
the conditions stated in this License.
|
|
134
|
+
|
|
135
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
136
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
137
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
138
|
+
this License, without any additional terms or conditions.
|
|
139
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
140
|
+
the terms of any separate license agreement you may have executed
|
|
141
|
+
with Licensor regarding such Contributions.
|
|
142
|
+
|
|
143
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
144
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
145
|
+
except as required for reasonable and customary use in describing the
|
|
146
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
147
|
+
|
|
148
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
149
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
150
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
151
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
152
|
+
implied, including, without limitation, any warranties or conditions
|
|
153
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
154
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
155
|
+
appropriateness of using or redistributing the Work and assume any
|
|
156
|
+
risks associated with Your exercise of permissions under this License.
|
|
157
|
+
|
|
158
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
159
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
160
|
+
unless required by applicable law (such as deliberate and grossly
|
|
161
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
162
|
+
liable to You for damages, including any direct, indirect, special,
|
|
163
|
+
incidental, or consequential damages of any character arising as a
|
|
164
|
+
result of this License or out of the use or inability to use the
|
|
165
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
166
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
167
|
+
other commercial damages or losses), even if such Contributor
|
|
168
|
+
has been advised of the possibility of such damages.
|
|
169
|
+
|
|
170
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
171
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
172
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
173
|
+
or other liability obligations and/or rights consistent with this
|
|
174
|
+
License. However, in accepting such obligations, You may act only
|
|
175
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
176
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
177
|
+
defend, and hold each Contributor harmless for any liability
|
|
178
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
179
|
+
of your accepting any such warranty or additional liability.
|
|
180
|
+
|
|
181
|
+
END OF TERMS AND CONDITIONS
|
|
182
|
+
|
|
183
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
184
|
+
|
|
185
|
+
To apply the Apache License to your work, attach the following
|
|
186
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
187
|
+
replaced with your own identifying information. (Don't include
|
|
188
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
189
|
+
comment syntax for the file format. We also recommend that a
|
|
190
|
+
file or class name and description of purpose be included on the
|
|
191
|
+
same "printed page" as the copyright notice for easier
|
|
192
|
+
identification within third-party archives.
|
|
193
|
+
|
|
194
|
+
Copyright [yyyy] [name of copyright owner]
|
|
195
|
+
|
|
196
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
197
|
+
you may not use this file except in compliance with the License.
|
|
198
|
+
You may obtain a copy of the License at
|
|
199
|
+
|
|
200
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
201
|
+
|
|
202
|
+
Unless required by applicable law or agreed to in writing, software
|
|
203
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
204
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
205
|
+
See the License for the specific language governing permissions and
|
|
206
|
+
limitations under the License.
|
|
207
|
+
|
|
208
|
+
Project-URL: Homepage, https://cometa.dev
|
|
209
|
+
Project-URL: Source, https://github.com/Biglup/cometa.py
|
|
210
|
+
Project-URL: Issues, https://github.com/Biglup/cometa.py/issues
|
|
211
|
+
Classifier: Programming Language :: Python :: 3
|
|
212
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
213
|
+
Classifier: Operating System :: OS Independent
|
|
214
|
+
Requires-Python: >=3.9
|
|
215
|
+
Description-Content-Type: text/markdown
|
|
216
|
+
License-File: LICENSE
|
|
217
|
+
Requires-Dist: cffi>=1.16.0
|
|
218
|
+
Dynamic: license-file
|
|
219
|
+
|
|
220
|
+
<div align="center">
|
|
221
|
+
<a href="" target="_blank">
|
|
222
|
+
<img align="center" width="300" src="https://raw.githubusercontent.com/Biglup/cometa.py/main/assets/cometa_py.png">
|
|
223
|
+
</a>
|
|
224
|
+
</div>
|
|
225
|
+
|
|
226
|
+
<br>
|
|
227
|
+
|
|
228
|
+
<div align="center">
|
|
229
|
+
|
|
230
|
+

|
|
231
|
+

|
|
232
|
+
[](https://cometapy.readthedocs.io/en/latest/?badge=latest)
|
|
233
|
+
[](https://x.com/BiglupLabs)
|
|
234
|
+
[](https://pypi.org/project/biglup-cometa/)
|
|
235
|
+
|
|
236
|
+
</div>
|
|
237
|
+
|
|
238
|
+
<hr>
|
|
239
|
+
|
|
240
|
+
- [Official Website](https://cometa.dev/)
|
|
241
|
+
- [Installation](#installation)
|
|
242
|
+
- [Documentation](https://cometapy.readthedocs.io/en/latest/)
|
|
243
|
+
|
|
244
|
+
<hr>
|
|
245
|
+
|
|
246
|
+
Cometa.py is a lightweight, high-performance Python library binding for the [libcardano-c](https://github.com/Biglup/cardano-c) library, designed to simplify blockchain development on Cardano.
|
|
247
|
+
|
|
248
|
+
Cometa.py packages [libcardano-c](https://github.com/Biglup/cardano-c) using CFFI bindings, providing a fully documented, developer-friendly Pythonic API with type hints for excellent IDE support.
|
|
249
|
+
|
|
250
|
+
Example:
|
|
251
|
+
|
|
252
|
+
```python
|
|
253
|
+
from cometa import TxBuilder, SlotConfig
|
|
254
|
+
|
|
255
|
+
builder = TxBuilder(protocol_params, SlotConfig.mainnet())
|
|
256
|
+
|
|
257
|
+
unsigned_tx = (
|
|
258
|
+
builder
|
|
259
|
+
.set_change_address(sender_address)
|
|
260
|
+
.set_utxos(utxos)
|
|
261
|
+
.send_lovelace(recipient_address, 12_000_000)
|
|
262
|
+
.expires_in(3600)
|
|
263
|
+
.build()
|
|
264
|
+
)
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
<hr>
|
|
268
|
+
|
|
269
|
+
## **Conway Era Support**
|
|
270
|
+
|
|
271
|
+
Cometa.py supports all features up to the Conway era, which is the current era of the Cardano blockchain. Conway era brought decentralized governance to Cardano, including:
|
|
272
|
+
|
|
273
|
+
- [Register as DRep (PubKey)](examples/drep_pubkey_example.py)
|
|
274
|
+
- [Register as DRep (Script)](examples/drep_script_example.py)
|
|
275
|
+
- [Submit governance action proposal (Withdrawing from treasury)](examples/propose_treasury_withdrawal_example.py)
|
|
276
|
+
- [Vote for proposal (PubKey DRep)](examples/vote_for_proposal_drep_pubkey_example.py)
|
|
277
|
+
- [Vote for proposal (Script DRep)](examples/vote_for_proposal_drep_script_example.py)
|
|
278
|
+
|
|
279
|
+
These are some of the examples illustrated in the [examples](examples/) directory. However, you should
|
|
280
|
+
be able to build any valid transaction for the current era. See the [Documentation](https://cometapy.readthedocs.io/) for more information.
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
<hr>
|
|
284
|
+
|
|
285
|
+
## **Installation**
|
|
286
|
+
|
|
287
|
+
You can install Cometa.py using pip:
|
|
288
|
+
|
|
289
|
+
```bash
|
|
290
|
+
pip install biglup-cometa
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
Once installed, you can import it into your application:
|
|
294
|
+
|
|
295
|
+
```python
|
|
296
|
+
import cometa
|
|
297
|
+
|
|
298
|
+
version = cometa.get_lib_version()
|
|
299
|
+
print(f"Library version: {version}")
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
<hr>
|
|
303
|
+
|
|
304
|
+
## **Getting Started**
|
|
305
|
+
|
|
306
|
+
The primary component for creating transactions is the `TxBuilder`. It provides a fluent (chainable) API that simplifies the complex process of assembling inputs, outputs, and calculating fees.
|
|
307
|
+
|
|
308
|
+
The `TxBuilder` requires protocol parameters and a `SlotConfig` for slot/time calculations:
|
|
309
|
+
|
|
310
|
+
```python
|
|
311
|
+
from cometa import TxBuilder, SlotConfig, ProtocolParameters
|
|
312
|
+
|
|
313
|
+
# SlotConfig provides network timing configuration
|
|
314
|
+
# Use the appropriate factory method for your network:
|
|
315
|
+
slot_config = SlotConfig.mainnet() # For mainnet
|
|
316
|
+
slot_config = SlotConfig.preprod() # For preprod testnet
|
|
317
|
+
slot_config = SlotConfig.preview() # For preview testnet
|
|
318
|
+
|
|
319
|
+
# Create the builder
|
|
320
|
+
builder = TxBuilder(protocol_params, slot_config)
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
> **Note:** The `TxBuilder` uses `AikenTxEvaluator` by default for local Plutus script evaluation. You can override this with a custom evaluator using `builder.set_evaluator()`.
|
|
324
|
+
|
|
325
|
+
First, establish a connection to the Cardano network using a Provider:
|
|
326
|
+
|
|
327
|
+
```python
|
|
328
|
+
from cometa import BlockfrostProvider, NetworkMagic
|
|
329
|
+
|
|
330
|
+
provider = BlockfrostProvider(
|
|
331
|
+
network=NetworkMagic.PREPROD,
|
|
332
|
+
project_id="YOUR_BLOCKFROST_PROJECT_ID"
|
|
333
|
+
)
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
> **Tip:** You can create your own providers by implementing the `Provider` protocol.
|
|
337
|
+
|
|
338
|
+
Create your addresses and fetch UTxOs:
|
|
339
|
+
|
|
340
|
+
```python
|
|
341
|
+
from cometa import Address
|
|
342
|
+
|
|
343
|
+
sender_address = Address.from_bech32("addr_test1...")
|
|
344
|
+
recipient_address = Address.from_bech32("addr_test1...")
|
|
345
|
+
|
|
346
|
+
# Fetch UTxOs from the provider
|
|
347
|
+
utxos = provider.get_unspent_outputs(sender_address)
|
|
348
|
+
protocol_params = provider.get_parameters()
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
Build your transaction using the fluent API:
|
|
352
|
+
|
|
353
|
+
```python
|
|
354
|
+
from cometa import TxBuilder, SlotConfig
|
|
355
|
+
|
|
356
|
+
builder = TxBuilder(protocol_params, SlotConfig.preprod())
|
|
357
|
+
|
|
358
|
+
unsigned_tx = (
|
|
359
|
+
builder
|
|
360
|
+
.set_change_address(sender_address)
|
|
361
|
+
.set_utxos(utxos)
|
|
362
|
+
.send_lovelace(recipient_address, 2_000_000) # Send 2 ADA
|
|
363
|
+
.expires_in(7200) # Valid for 2 hours
|
|
364
|
+
.build()
|
|
365
|
+
)
|
|
366
|
+
```
|
|
367
|
+
|
|
368
|
+
Sign and submit the transaction:
|
|
369
|
+
|
|
370
|
+
```python
|
|
371
|
+
tx_hash = provider.submit_transaction(signed_tx)
|
|
372
|
+
print(f"Transaction submitted! TxHash: {tx_hash}")
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
<hr>
|
|
376
|
+
|
|
377
|
+
## **Transaction Builder Examples**
|
|
378
|
+
|
|
379
|
+
The `TxBuilder` supports a wide range of transaction types. Here are some common patterns.
|
|
380
|
+
|
|
381
|
+
All examples below assume you have already created the builder:
|
|
382
|
+
|
|
383
|
+
```python
|
|
384
|
+
from cometa import TxBuilder, SlotConfig
|
|
385
|
+
|
|
386
|
+
builder = TxBuilder(protocol_params, SlotConfig.preprod())
|
|
387
|
+
```
|
|
388
|
+
|
|
389
|
+
### Sending Multiple Outputs
|
|
390
|
+
|
|
391
|
+
```python
|
|
392
|
+
tx = (
|
|
393
|
+
builder
|
|
394
|
+
.set_change_address(sender_address)
|
|
395
|
+
.set_utxos(utxos)
|
|
396
|
+
.send_lovelace("addr_test1qz...", 5_000_000) # Send 5 ADA
|
|
397
|
+
.send_lovelace("addr_test1qp...", 10_000_000) # Send 10 ADA
|
|
398
|
+
.send_lovelace("addr_test1qr...", 2_000_000) # Send 2 ADA
|
|
399
|
+
.expires_in(7200) # Expires in 2 hours
|
|
400
|
+
.build()
|
|
401
|
+
)
|
|
402
|
+
```
|
|
403
|
+
|
|
404
|
+
### Minting Tokens with Native Scripts
|
|
405
|
+
|
|
406
|
+
```python
|
|
407
|
+
from cometa import ScriptAll, ScriptPubkey, Value
|
|
408
|
+
|
|
409
|
+
# Create a native script policy
|
|
410
|
+
pub_key_hash = payment_key.to_hash()
|
|
411
|
+
native_script = ScriptAll.new([
|
|
412
|
+
ScriptPubkey.new(pub_key_hash)
|
|
413
|
+
])
|
|
414
|
+
policy_id = native_script.hash
|
|
415
|
+
|
|
416
|
+
# Mint tokens
|
|
417
|
+
tx = (
|
|
418
|
+
builder
|
|
419
|
+
.set_change_address(sender_address)
|
|
420
|
+
.set_utxos(utxos)
|
|
421
|
+
.mint_token(amount=100, policy_id=policy_id, asset_name=b"MyToken")
|
|
422
|
+
.add_script(native_script)
|
|
423
|
+
.send_value(
|
|
424
|
+
address=str(sender_address),
|
|
425
|
+
value=Value.from_dict([2_000_000, {policy_id: {b"MyToken": 100}}])
|
|
426
|
+
)
|
|
427
|
+
.expires_in(3600)
|
|
428
|
+
.build()
|
|
429
|
+
)
|
|
430
|
+
```
|
|
431
|
+
|
|
432
|
+
### Burning Tokens
|
|
433
|
+
|
|
434
|
+
```python
|
|
435
|
+
# Burn tokens (negative amount)
|
|
436
|
+
tx = (
|
|
437
|
+
builder
|
|
438
|
+
.set_change_address(sender_address)
|
|
439
|
+
.set_utxos(utxos)
|
|
440
|
+
.mint_token(amount=-50, policy_id=policy_id, asset_name=b"MyToken")
|
|
441
|
+
.add_script(native_script)
|
|
442
|
+
.expires_in(3600)
|
|
443
|
+
.build()
|
|
444
|
+
)
|
|
445
|
+
```
|
|
446
|
+
|
|
447
|
+
### Attaching Metadata (CIP-25 NFTs)
|
|
448
|
+
|
|
449
|
+
```python
|
|
450
|
+
# CIP-25 NFT metadata
|
|
451
|
+
nft_metadata = {
|
|
452
|
+
policy_id.hex(): {
|
|
453
|
+
"MyNFT": {
|
|
454
|
+
"name": "My Awesome NFT",
|
|
455
|
+
"image": "ipfs://QmXyz...",
|
|
456
|
+
"description": "A unique digital artwork"
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
tx = (
|
|
462
|
+
builder
|
|
463
|
+
.set_change_address(sender_address)
|
|
464
|
+
.set_utxos(utxos)
|
|
465
|
+
.mint_token(amount=1, policy_id=policy_id, asset_name=b"MyNFT")
|
|
466
|
+
.add_script(native_script)
|
|
467
|
+
.set_metadata(metadata=nft_metadata, tag=721) # CIP-25 uses tag 721
|
|
468
|
+
.send_value(
|
|
469
|
+
address=recipient_address,
|
|
470
|
+
value=Value.from_dict([2_000_000, {policy_id: {b"MyNFT": 1}}])
|
|
471
|
+
)
|
|
472
|
+
.expires_in(3600)
|
|
473
|
+
.build()
|
|
474
|
+
)
|
|
475
|
+
```
|
|
476
|
+
|
|
477
|
+
### Staking Operations
|
|
478
|
+
|
|
479
|
+
```python
|
|
480
|
+
from cometa import DRep
|
|
481
|
+
|
|
482
|
+
# Delegate stake to a pool
|
|
483
|
+
tx = (
|
|
484
|
+
builder
|
|
485
|
+
.set_change_address(sender_address)
|
|
486
|
+
.set_utxos(utxos)
|
|
487
|
+
.delegate_stake(
|
|
488
|
+
reward_address=reward_address,
|
|
489
|
+
pool_id="pool1..."
|
|
490
|
+
)
|
|
491
|
+
.build()
|
|
492
|
+
)
|
|
493
|
+
|
|
494
|
+
# Delegate voting power to a DRep (Conway era)
|
|
495
|
+
tx = (
|
|
496
|
+
builder
|
|
497
|
+
.set_change_address(sender_address)
|
|
498
|
+
.set_utxos(utxos)
|
|
499
|
+
.delegate_voting_power(
|
|
500
|
+
reward_address=reward_address,
|
|
501
|
+
drep=DRep.from_key_hash("drep_key_hash_hex...")
|
|
502
|
+
)
|
|
503
|
+
.build()
|
|
504
|
+
)
|
|
505
|
+
```
|
|
506
|
+
|
|
507
|
+
### Treasury Donation
|
|
508
|
+
|
|
509
|
+
```python
|
|
510
|
+
# Donate to the Cardano treasury
|
|
511
|
+
tx = (
|
|
512
|
+
builder
|
|
513
|
+
.set_change_address(sender_address)
|
|
514
|
+
.set_utxos(utxos)
|
|
515
|
+
.donate(1_000_000_000) # Donate 1000 ADA
|
|
516
|
+
.build()
|
|
517
|
+
)
|
|
518
|
+
```
|
|
519
|
+
|
|
520
|
+
<hr>
|
|
521
|
+
|
|
522
|
+
## **Plutus Smart Contracts**
|
|
523
|
+
|
|
524
|
+
Cometa.py supports Plutus V1, V2, and V3 scripts for smart contract interactions. Plutus scripts can be used for spending validation, minting policies, and staking operations.
|
|
525
|
+
|
|
526
|
+
### Loading Plutus Scripts
|
|
527
|
+
|
|
528
|
+
```python
|
|
529
|
+
from cometa import PlutusV3Script, PlutusV2Script, PlutusV1Script, Script
|
|
530
|
+
|
|
531
|
+
# Load a Plutus V3 script from CBOR hex
|
|
532
|
+
plutus_v3 = PlutusV3Script.from_hex("590dff010000323232...")
|
|
533
|
+
script = Script.from_plutus_v3(plutus_v3)
|
|
534
|
+
|
|
535
|
+
# Load Plutus V2 or V1 similarly
|
|
536
|
+
plutus_v2 = PlutusV2Script.from_hex("...")
|
|
537
|
+
script_v2 = Script.from_plutus_v2(plutus_v2)
|
|
538
|
+
|
|
539
|
+
# Get the script hash (used as policy ID for minting)
|
|
540
|
+
script_hash = script.hash
|
|
541
|
+
print(f"Script hash: {script_hash.hex()}")
|
|
542
|
+
```
|
|
543
|
+
|
|
544
|
+
### Creating Script Addresses
|
|
545
|
+
|
|
546
|
+
```python
|
|
547
|
+
from cometa import EnterpriseAddress, Credential, NetworkId
|
|
548
|
+
|
|
549
|
+
# Create a credential from the script hash
|
|
550
|
+
script_credential = Credential.from_script_hash(script_hash)
|
|
551
|
+
|
|
552
|
+
# Create an enterprise address (no staking) for the script
|
|
553
|
+
script_address = EnterpriseAddress.from_credentials(
|
|
554
|
+
NetworkId.TESTNET,
|
|
555
|
+
script_credential
|
|
556
|
+
).to_address()
|
|
557
|
+
|
|
558
|
+
print(f"Script address: {script_address}")
|
|
559
|
+
```
|
|
560
|
+
|
|
561
|
+
### Spending from a Plutus Script
|
|
562
|
+
|
|
563
|
+
```python
|
|
564
|
+
from cometa import ConstrPlutusData
|
|
565
|
+
|
|
566
|
+
# Get UTXOs locked at the script address
|
|
567
|
+
script_utxos = provider.get_unspent_outputs(str(script_address))
|
|
568
|
+
|
|
569
|
+
# Create a redeemer (argument to the script)
|
|
570
|
+
# ConstrPlutusData(0) is a simple constructor - your script defines the format
|
|
571
|
+
redeemer = ConstrPlutusData(0)
|
|
572
|
+
|
|
573
|
+
# Build transaction to spend from the script
|
|
574
|
+
spend_tx = (
|
|
575
|
+
builder
|
|
576
|
+
.set_change_address(sender_address)
|
|
577
|
+
.set_utxos(utxos)
|
|
578
|
+
.add_input(utxo=script_utxos[0], redeemer=redeemer) # Script input with redeemer
|
|
579
|
+
.send_lovelace(address=recipient_address, amount=5_000_000)
|
|
580
|
+
.add_script(script) # Include the script for validation
|
|
581
|
+
.expires_in(3600)
|
|
582
|
+
.build()
|
|
583
|
+
)
|
|
584
|
+
```
|
|
585
|
+
|
|
586
|
+
### Working with Plutus Data
|
|
587
|
+
|
|
588
|
+
```python
|
|
589
|
+
from cometa import ConstrPlutusData, PlutusList, PlutusMap
|
|
590
|
+
# Constructor with fields (most common pattern)
|
|
591
|
+
# Represents: data MyDatum = MyDatum { owner: PubKeyHash, amount: Integer }
|
|
592
|
+
datum = ConstrPlutusData(
|
|
593
|
+
0, # Constructor index
|
|
594
|
+
[
|
|
595
|
+
b"pubkey_hash_here", # owner
|
|
596
|
+
1000000 # amount
|
|
597
|
+
]
|
|
598
|
+
)
|
|
599
|
+
|
|
600
|
+
# List of integers
|
|
601
|
+
int_list = PlutusList.from_list([
|
|
602
|
+
1,
|
|
603
|
+
2,
|
|
604
|
+
3
|
|
605
|
+
])
|
|
606
|
+
|
|
607
|
+
# Map (key-value pairs)
|
|
608
|
+
plutus_map = PlutusMap()
|
|
609
|
+
plutus_map[b"key1"] = 100
|
|
610
|
+
plutus_map[b"key2"] = 200
|
|
611
|
+
```
|
|
612
|
+
|
|
613
|
+
|
|
614
|
+
### Working with Scripts
|
|
615
|
+
|
|
616
|
+
Cometa.py provides some utilities to parameterize scripts and local transaction evaluation using the Aiken UPLC evaluator.
|
|
617
|
+
|
|
618
|
+
#### Applying Parameters to Scripts
|
|
619
|
+
|
|
620
|
+
Many contracts are parameterized, they require configuration data to be applied before deployment. Use `apply_params_to_script` to apply parameters to compiled scripts:
|
|
621
|
+
|
|
622
|
+
```python
|
|
623
|
+
from cometa import apply_params_to_script, PlutusV2Script, Script, PlutusList, PlutusData, ConstrPlutusData
|
|
624
|
+
|
|
625
|
+
# Load your compiled script
|
|
626
|
+
compiled_code = "590221010000323232..."
|
|
627
|
+
|
|
628
|
+
# Build parameters as Plutus Data
|
|
629
|
+
# Example: Gift Card contract requires token_name and utxo_ref
|
|
630
|
+
token_name = "MyToken"
|
|
631
|
+
output_ref = ConstrPlutusData(0, [
|
|
632
|
+
ConstrPlutusData(0, [PlutusData.from_hex(utxo.input.transaction_id.hex())]),
|
|
633
|
+
PlutusData.from_int(utxo.input.index)
|
|
634
|
+
])
|
|
635
|
+
|
|
636
|
+
params = PlutusList.from_list([
|
|
637
|
+
PlutusData.from_string(token_name),
|
|
638
|
+
PlutusData.from_constr(output_ref)
|
|
639
|
+
])
|
|
640
|
+
|
|
641
|
+
# Apply parameters to get the final script
|
|
642
|
+
parameterized_code = apply_params_to_script(params, compiled_code)
|
|
643
|
+
|
|
644
|
+
# Create the script object
|
|
645
|
+
plutus_script = PlutusV2Script.from_hex(parameterized_code)
|
|
646
|
+
script = Script.from_plutus_v2(plutus_script)
|
|
647
|
+
|
|
648
|
+
# Get the policy ID (script hash)
|
|
649
|
+
policy_id = script.hash
|
|
650
|
+
print(f"Policy ID: {policy_id.hex()}")
|
|
651
|
+
```
|
|
652
|
+
|
|
653
|
+
#### Example: Minting with Parameterized Script
|
|
654
|
+
|
|
655
|
+
```python
|
|
656
|
+
from cometa import (
|
|
657
|
+
BlockfrostProvider, NetworkMagic, TxBuilder, SlotConfig,
|
|
658
|
+
PlutusV2Script, Script, Value,
|
|
659
|
+
PlutusList, PlutusData, ConstrPlutusData, apply_params_to_script
|
|
660
|
+
)
|
|
661
|
+
|
|
662
|
+
# Setup provider
|
|
663
|
+
provider = BlockfrostProvider(
|
|
664
|
+
network=NetworkMagic.PREPROD,
|
|
665
|
+
project_id="YOUR_PROJECT_ID"
|
|
666
|
+
)
|
|
667
|
+
|
|
668
|
+
# Get protocol parameters and UTXOs
|
|
669
|
+
protocol_params = provider.get_parameters()
|
|
670
|
+
utxos = provider.get_unspent_outputs(sender_address)
|
|
671
|
+
|
|
672
|
+
# Select a UTXO to use as parameter (ensures script uniqueness)
|
|
673
|
+
param_utxo = utxos[0]
|
|
674
|
+
|
|
675
|
+
# Build script parameters
|
|
676
|
+
token_name = "MyNFT"
|
|
677
|
+
output_ref = ConstrPlutusData(0, [
|
|
678
|
+
ConstrPlutusData(0, [PlutusData.from_hex(param_utxo.input.transaction_id.hex())]),
|
|
679
|
+
PlutusData.from_int(param_utxo.input.index)
|
|
680
|
+
])
|
|
681
|
+
|
|
682
|
+
params = PlutusList.from_list([
|
|
683
|
+
PlutusData.from_string(token_name),
|
|
684
|
+
PlutusData.from_constr(output_ref)
|
|
685
|
+
])
|
|
686
|
+
|
|
687
|
+
# Apply parameters and create script
|
|
688
|
+
compiled_code = "590221010000323232..."
|
|
689
|
+
parameterized = apply_params_to_script(params, compiled_code)
|
|
690
|
+
script = Script.from_plutus_v2(PlutusV2Script.from_hex(parameterized))
|
|
691
|
+
|
|
692
|
+
# Build mint transaction
|
|
693
|
+
# Note: TxBuilder uses AikenTxEvaluator by default for local Plutus evaluation
|
|
694
|
+
policy_id = script.hash
|
|
695
|
+
asset_name = token_name.encode("utf-8")
|
|
696
|
+
mint_redeemer = ConstrPlutusData(0) # Mint action
|
|
697
|
+
|
|
698
|
+
builder = TxBuilder(protocol_params, SlotConfig.preprod())
|
|
699
|
+
|
|
700
|
+
tx = (
|
|
701
|
+
builder
|
|
702
|
+
.set_change_address(sender_address)
|
|
703
|
+
.set_utxos(utxos)
|
|
704
|
+
.add_input(param_utxo) # Must spend the referenced UTXO
|
|
705
|
+
.mint_token(policy_id=policy_id, asset_name=asset_name, amount=1, redeemer=mint_redeemer)
|
|
706
|
+
.add_script(script)
|
|
707
|
+
.send_value(
|
|
708
|
+
address=str(recipient_address),
|
|
709
|
+
value=Value.from_dict([2_000_000, {policy_id: {asset_name: 1}}])
|
|
710
|
+
)
|
|
711
|
+
.expires_in(3600)
|
|
712
|
+
.build()
|
|
713
|
+
)
|
|
714
|
+
|
|
715
|
+
# Sign and submit
|
|
716
|
+
signed_tx = sign_transaction(tx, private_key)
|
|
717
|
+
tx_hash = provider.submit_transaction(signed_tx.serialize_to_cbor())
|
|
718
|
+
print(f"Transaction submitted: {tx_hash}")
|
|
719
|
+
```
|
|
720
|
+
|
|
721
|
+
<hr>
|
|
722
|
+
|
|
723
|
+
## **Conway Governance**
|
|
724
|
+
|
|
725
|
+
Cardano's Conway era introduced decentralized governance. Cometa.py supports all governance features including DRep registration, voting, and proposal submission.
|
|
726
|
+
|
|
727
|
+
### Registering as a DRep
|
|
728
|
+
|
|
729
|
+
Delegated Representatives (DReps) vote on governance proposals on behalf of delegators:
|
|
730
|
+
|
|
731
|
+
```python
|
|
732
|
+
from cometa import DRep, DRepType, Credential, Anchor, Blake2bHash, Ed25519PublicKey
|
|
733
|
+
|
|
734
|
+
# Create DRep credential from your DRep key
|
|
735
|
+
drep_pub_key = Ed25519PublicKey.from_hex("your_drep_public_key_hex")
|
|
736
|
+
drep_credential = Credential.from_key_hash(drep_pub_key.to_hash())
|
|
737
|
+
|
|
738
|
+
# Create the DRep object
|
|
739
|
+
drep = DRep.new(drep_type=DRepType.KEY_HASH, credential=drep_credential)
|
|
740
|
+
print(f"DRep ID: {drep.to_cip129_string()}")
|
|
741
|
+
|
|
742
|
+
# Create an anchor (metadata URL + hash)
|
|
743
|
+
anchor = Anchor.new(
|
|
744
|
+
url="https://example.com/drep-metadata.jsonld",
|
|
745
|
+
hash_value=Blake2bHash.from_hex("metadata_hash_hex...")
|
|
746
|
+
)
|
|
747
|
+
|
|
748
|
+
# Register as a DRep
|
|
749
|
+
register_tx = (
|
|
750
|
+
builder
|
|
751
|
+
.set_change_address(sender_address)
|
|
752
|
+
.set_utxos(utxos)
|
|
753
|
+
.register_drep(drep=drep, anchor=anchor)
|
|
754
|
+
.build()
|
|
755
|
+
)
|
|
756
|
+
```
|
|
757
|
+
|
|
758
|
+
### Delegating Voting Power
|
|
759
|
+
|
|
760
|
+
ADA holders can delegate their voting power to a DRep:
|
|
761
|
+
|
|
762
|
+
```python
|
|
763
|
+
from cometa import DRep
|
|
764
|
+
|
|
765
|
+
# Delegate to a specific DRep
|
|
766
|
+
drep = DRep.from_string("drep1...") # DRep ID in CIP-129 format
|
|
767
|
+
|
|
768
|
+
# First register your stake key (if not already registered)
|
|
769
|
+
register_stake_tx = (
|
|
770
|
+
builder
|
|
771
|
+
.set_change_address(sender_address)
|
|
772
|
+
.set_utxos(utxos)
|
|
773
|
+
.register_reward_address(reward_address=reward_address)
|
|
774
|
+
.build()
|
|
775
|
+
)
|
|
776
|
+
|
|
777
|
+
# Then delegate voting power
|
|
778
|
+
delegate_tx = (
|
|
779
|
+
builder
|
|
780
|
+
.set_change_address(sender_address)
|
|
781
|
+
.set_utxos(utxos)
|
|
782
|
+
.delegate_voting_power(
|
|
783
|
+
drep=drep,
|
|
784
|
+
reward_address=reward_address
|
|
785
|
+
)
|
|
786
|
+
.build()
|
|
787
|
+
)
|
|
788
|
+
|
|
789
|
+
# You can also delegate to special DReps
|
|
790
|
+
from cometa import DRep
|
|
791
|
+
|
|
792
|
+
# Delegate to "Abstain" (participate in quorum but don't vote)
|
|
793
|
+
abstain_drep = DRep.new_abstain()
|
|
794
|
+
|
|
795
|
+
# Delegate to "No Confidence" (vote no on everything)
|
|
796
|
+
no_confidence_drep = DRep.new_no_confidence()
|
|
797
|
+
```
|
|
798
|
+
|
|
799
|
+
### Voting on Proposals
|
|
800
|
+
|
|
801
|
+
DReps can vote on governance proposals:
|
|
802
|
+
|
|
803
|
+
```python
|
|
804
|
+
from cometa import (
|
|
805
|
+
Voter, VoterType, Vote, VotingProcedure,
|
|
806
|
+
GovernanceActionId, Anchor, Blake2bHash
|
|
807
|
+
)
|
|
808
|
+
|
|
809
|
+
# Create the voter (DRep credential)
|
|
810
|
+
voter = Voter.new(VoterType.DREP_KEY_HASH, drep_credential)
|
|
811
|
+
|
|
812
|
+
# Reference the governance action to vote on
|
|
813
|
+
action_id = GovernanceActionId.from_bech32(
|
|
814
|
+
"gov_action1u8gafgcskj6sqvgwqse7adc0h9438m535lg97czcvxntscvw7f5sqgf2n7j"
|
|
815
|
+
)
|
|
816
|
+
|
|
817
|
+
# Create voting procedure with rationale anchor
|
|
818
|
+
rationale_anchor = Anchor.new(
|
|
819
|
+
url="https://example.com/vote-rationale.jsonld",
|
|
820
|
+
hash_value=Blake2bHash.from_hex("rationale_hash...")
|
|
821
|
+
)
|
|
822
|
+
voting_procedure = VotingProcedure.new(Vote.YES, rationale_anchor)
|
|
823
|
+
|
|
824
|
+
# Cast the vote
|
|
825
|
+
vote_tx = (
|
|
826
|
+
builder
|
|
827
|
+
.set_change_address(sender_address)
|
|
828
|
+
.set_utxos(utxos)
|
|
829
|
+
.vote(
|
|
830
|
+
voter=voter,
|
|
831
|
+
action_id=action_id,
|
|
832
|
+
voting_procedure=voting_procedure
|
|
833
|
+
)
|
|
834
|
+
.build()
|
|
835
|
+
)
|
|
836
|
+
```
|
|
837
|
+
|
|
838
|
+
### Proposing Governance Actions
|
|
839
|
+
|
|
840
|
+
Submit proposals for on-chain governance:
|
|
841
|
+
|
|
842
|
+
```python
|
|
843
|
+
from cometa import Anchor, Blake2bHash
|
|
844
|
+
|
|
845
|
+
# All proposals require an anchor with metadata
|
|
846
|
+
proposal_anchor = Anchor.new(
|
|
847
|
+
url="https://example.com/proposal-metadata.jsonld",
|
|
848
|
+
hash_value=Blake2bHash.from_hex("metadata_hash...")
|
|
849
|
+
)
|
|
850
|
+
|
|
851
|
+
# Info action (non-binding poll)
|
|
852
|
+
info_tx = (
|
|
853
|
+
builder
|
|
854
|
+
.set_change_address(sender_address)
|
|
855
|
+
.set_utxos(utxos)
|
|
856
|
+
.propose_info(
|
|
857
|
+
reward_address=reward_address, # Deposit refund address
|
|
858
|
+
anchor=proposal_anchor
|
|
859
|
+
)
|
|
860
|
+
.build()
|
|
861
|
+
)
|
|
862
|
+
```
|
|
863
|
+
|
|
864
|
+
### Deregistering a DRep
|
|
865
|
+
|
|
866
|
+
```python
|
|
867
|
+
# Deregister and reclaim your deposit
|
|
868
|
+
deregister_tx = (
|
|
869
|
+
builder
|
|
870
|
+
.set_change_address(sender_address)
|
|
871
|
+
.set_utxos(utxos)
|
|
872
|
+
.deregister_drep(drep=drep)
|
|
873
|
+
.build()
|
|
874
|
+
)
|
|
875
|
+
```
|
|
876
|
+
|
|
877
|
+
### Withdrawing Staking Rewards
|
|
878
|
+
|
|
879
|
+
```python
|
|
880
|
+
# Get current rewards balance
|
|
881
|
+
rewards_balance = provider.get_rewards_balance(reward_address)
|
|
882
|
+
|
|
883
|
+
# Withdraw all rewards
|
|
884
|
+
withdraw_tx = (
|
|
885
|
+
builder
|
|
886
|
+
.set_change_address(sender_address)
|
|
887
|
+
.set_utxos(utxos)
|
|
888
|
+
.withdraw_rewards(
|
|
889
|
+
amount=rewards_balance,
|
|
890
|
+
reward_address=reward_address
|
|
891
|
+
)
|
|
892
|
+
.build()
|
|
893
|
+
)
|
|
894
|
+
|
|
895
|
+
# Optionally deregister stake key to reclaim deposit
|
|
896
|
+
deregister_stake_tx = (
|
|
897
|
+
builder
|
|
898
|
+
.set_change_address(sender_address)
|
|
899
|
+
.set_utxos(utxos)
|
|
900
|
+
.withdraw_rewards(amount=rewards_balance, reward_address=reward_address)
|
|
901
|
+
.deregister_reward_address(reward_address=reward_address)
|
|
902
|
+
.build()
|
|
903
|
+
)
|
|
904
|
+
```
|
|
905
|
+
|
|
906
|
+
You can see the full capabilities of the transaction builder in the [TxBuilder API documentation](https://cometapy.readthedocs.io/en/latest/api/transaction_builder/tx_builder.html).
|
|
907
|
+
|
|
908
|
+
<hr>
|
|
909
|
+
|
|
910
|
+
## **Working with CBOR**
|
|
911
|
+
|
|
912
|
+
Cardano uses [CBOR (Concise Binary Object Representation)](https://cbor.io/) for serialization. Cometa.py provides `CborReader` and `CborWriter` for encoding and decoding CBOR data.
|
|
913
|
+
|
|
914
|
+
### Writing CBOR Data
|
|
915
|
+
|
|
916
|
+
```python
|
|
917
|
+
from cometa import CborWriter
|
|
918
|
+
|
|
919
|
+
# Create a writer
|
|
920
|
+
writer = CborWriter()
|
|
921
|
+
|
|
922
|
+
# Write primitive values
|
|
923
|
+
writer.write_int(42)
|
|
924
|
+
writer.write_str("Hello, Cardano!")
|
|
925
|
+
writer.write_bytes(b"\x01\x02\x03")
|
|
926
|
+
writer.write_bool(True)
|
|
927
|
+
writer.write_null()
|
|
928
|
+
|
|
929
|
+
# Get the encoded bytes
|
|
930
|
+
cbor_bytes = writer.encode()
|
|
931
|
+
cbor_hex = writer.to_hex()
|
|
932
|
+
```
|
|
933
|
+
|
|
934
|
+
### Reading CBOR Data
|
|
935
|
+
|
|
936
|
+
```python
|
|
937
|
+
from cometa import CborReader, CborReaderState
|
|
938
|
+
|
|
939
|
+
# Create a reader from hex or bytes
|
|
940
|
+
reader = CborReader.from_hex("83010203") # Array [1, 2, 3]
|
|
941
|
+
|
|
942
|
+
# Check what type of data is next
|
|
943
|
+
state = reader.peek_state()
|
|
944
|
+
if state == CborReaderState.START_ARRAY:
|
|
945
|
+
length = reader.read_array_len()
|
|
946
|
+
for _ in range(length):
|
|
947
|
+
value = reader.read_uint()
|
|
948
|
+
print(value)
|
|
949
|
+
reader.read_array_end()
|
|
950
|
+
```
|
|
951
|
+
|
|
952
|
+
<hr>
|
|
953
|
+
|
|
954
|
+
## **Cryptography**
|
|
955
|
+
|
|
956
|
+
Cometa.py provides comprehensive cryptographic primitives for Cardano development, including Ed25519 key pairs, BIP32 hierarchical deterministic keys, and BIP39 mnemonic support.
|
|
957
|
+
|
|
958
|
+
### Working with Mnemonics (BIP39)
|
|
959
|
+
|
|
960
|
+
BIP39 mnemonics are human-readable word sequences that encode cryptographic entropy:
|
|
961
|
+
|
|
962
|
+
```python
|
|
963
|
+
from cometa import mnemonic_to_entropy, entropy_to_mnemonic
|
|
964
|
+
|
|
965
|
+
# Convert a mnemonic phrase to entropy
|
|
966
|
+
mnemonic_words = [
|
|
967
|
+
"abandon", "abandon", "abandon", "abandon",
|
|
968
|
+
"abandon", "abandon", "abandon", "abandon",
|
|
969
|
+
"abandon", "abandon", "abandon", "about"
|
|
970
|
+
]
|
|
971
|
+
entropy = mnemonic_to_entropy(mnemonic_words)
|
|
972
|
+
print(f"Entropy: {entropy.hex()}")
|
|
973
|
+
```
|
|
974
|
+
|
|
975
|
+
### Deriving Keys from Mnemonics (CIP-1852)
|
|
976
|
+
|
|
977
|
+
Cardano uses CIP-1852 for HD wallet key derivation:
|
|
978
|
+
|
|
979
|
+
```python
|
|
980
|
+
from cometa import (
|
|
981
|
+
mnemonic_to_entropy,
|
|
982
|
+
Bip32PrivateKey,
|
|
983
|
+
harden,
|
|
984
|
+
BaseAddress,
|
|
985
|
+
NetworkId,
|
|
986
|
+
Credential
|
|
987
|
+
)
|
|
988
|
+
|
|
989
|
+
# Convert mnemonic to entropy
|
|
990
|
+
mnemonic = "your 24 word mnemonic phrase here...".split()
|
|
991
|
+
entropy = mnemonic_to_entropy(mnemonic)
|
|
992
|
+
|
|
993
|
+
# Create root key from entropy
|
|
994
|
+
root_key = Bip32PrivateKey.from_bip39_entropy(b"optional-passphrase", entropy)
|
|
995
|
+
|
|
996
|
+
# Derive account key using CIP-1852 path: m/1852'/1815'/0'
|
|
997
|
+
# 1852' = Cardano purpose, 1815' = ADA coin type, 0' = account 0
|
|
998
|
+
account_key = root_key.derive([
|
|
999
|
+
harden(1852), # Purpose
|
|
1000
|
+
harden(1815), # Coin type (ADA)
|
|
1001
|
+
harden(0) # Account index
|
|
1002
|
+
])
|
|
1003
|
+
|
|
1004
|
+
# Get account public key (can be shared safely)
|
|
1005
|
+
account_pub_key = account_key.get_public_key()
|
|
1006
|
+
|
|
1007
|
+
# Derive payment key: m/1852'/1815'/0'/0/0
|
|
1008
|
+
payment_key = account_pub_key.derive([0, 0]) # External chain, address 0
|
|
1009
|
+
|
|
1010
|
+
# Derive staking key: m/1852'/1815'/0'/2/0
|
|
1011
|
+
staking_key = account_pub_key.derive([2, 0]) # Staking chain, index 0
|
|
1012
|
+
|
|
1013
|
+
# Create credentials from key hashes
|
|
1014
|
+
payment_credential = Credential.from_key_hash(
|
|
1015
|
+
payment_key.to_ed25519_key().to_hash()
|
|
1016
|
+
)
|
|
1017
|
+
staking_credential = Credential.from_key_hash(
|
|
1018
|
+
staking_key.to_ed25519_key().to_hash()
|
|
1019
|
+
)
|
|
1020
|
+
|
|
1021
|
+
# Create a base address
|
|
1022
|
+
address = BaseAddress.from_credentials(
|
|
1023
|
+
NetworkId.MAINNET,
|
|
1024
|
+
payment_credential,
|
|
1025
|
+
staking_credential
|
|
1026
|
+
)
|
|
1027
|
+
print(f"Address: {address.to_bech32()}")
|
|
1028
|
+
```
|
|
1029
|
+
|
|
1030
|
+
### Signing and Verifying Messages
|
|
1031
|
+
|
|
1032
|
+
Ed25519 signatures are used for transaction signing and message authentication:
|
|
1033
|
+
|
|
1034
|
+
```python
|
|
1035
|
+
from cometa import Ed25519PrivateKey, Ed25519PublicKey
|
|
1036
|
+
|
|
1037
|
+
# Create a private key (in practice, derive from HD wallet)
|
|
1038
|
+
private_key = Ed25519PrivateKey.from_normal_bytes(bytes(32))
|
|
1039
|
+
|
|
1040
|
+
# Get the corresponding public key
|
|
1041
|
+
public_key = private_key.get_public_key()
|
|
1042
|
+
print(f"Public key hash: {public_key.to_hash().to_hex()}")
|
|
1043
|
+
|
|
1044
|
+
# Sign a message
|
|
1045
|
+
message = b"Hello, Cardano!"
|
|
1046
|
+
signature = private_key.sign(message)
|
|
1047
|
+
print(f"Signature: {signature.to_hex()}")
|
|
1048
|
+
|
|
1049
|
+
# Verify the signature
|
|
1050
|
+
is_valid = public_key.verify(signature, message)
|
|
1051
|
+
print(f"Signature valid: {is_valid}")
|
|
1052
|
+
|
|
1053
|
+
# Verification fails with wrong message
|
|
1054
|
+
is_valid = public_key.verify(signature, b"Wrong message")
|
|
1055
|
+
print(f"Wrong message valid: {is_valid}") # False
|
|
1056
|
+
```
|
|
1057
|
+
|
|
1058
|
+
<hr>
|
|
1059
|
+
|
|
1060
|
+
## **Extending the Transaction Builder**
|
|
1061
|
+
|
|
1062
|
+
The `TxBuilder` API allows you to override its core logic for coin selection and transaction evaluation. If these custom implementations are not provided, the builder uses the following defaults:
|
|
1063
|
+
|
|
1064
|
+
- **Coin Selection**: A "Largest First" strategy via `LargeFirstCoinSelector`
|
|
1065
|
+
- **Transaction Evaluation**: Local evaluation via `AikenTxEvaluator` (uses the Aiken UPLC evaluator)
|
|
1066
|
+
|
|
1067
|
+
### Implementing a Custom CoinSelector
|
|
1068
|
+
|
|
1069
|
+
The coin selector is responsible for choosing which UTxOs to spend to cover the value required by the transaction's outputs. You can provide your own strategy by implementing the `CoinSelector` protocol:
|
|
1070
|
+
|
|
1071
|
+
```python
|
|
1072
|
+
from typing import List, Tuple
|
|
1073
|
+
from cometa import Utxo, Value
|
|
1074
|
+
|
|
1075
|
+
class MyCoinSelector:
|
|
1076
|
+
"""Custom coin selection strategy."""
|
|
1077
|
+
|
|
1078
|
+
def get_name(self) -> str:
|
|
1079
|
+
return "MyCustomSelector"
|
|
1080
|
+
|
|
1081
|
+
def select(
|
|
1082
|
+
self,
|
|
1083
|
+
pre_selected_utxo: List[Utxo],
|
|
1084
|
+
available_utxo: List[Utxo],
|
|
1085
|
+
target: Value,
|
|
1086
|
+
) -> Tuple[List[Utxo], List[Utxo]]:
|
|
1087
|
+
# Your custom selection logic here
|
|
1088
|
+
# Return: (selected_utxos, remaining_utxos)
|
|
1089
|
+
...
|
|
1090
|
+
```
|
|
1091
|
+
|
|
1092
|
+
Attach your custom selector to the builder:
|
|
1093
|
+
|
|
1094
|
+
```python
|
|
1095
|
+
my_selector = MyCoinSelector()
|
|
1096
|
+
builder.set_coin_selector(my_selector)
|
|
1097
|
+
```
|
|
1098
|
+
|
|
1099
|
+
### Transaction Evaluators
|
|
1100
|
+
|
|
1101
|
+
The transaction evaluator calculates execution units (ExUnits) for Plutus scripts.
|
|
1102
|
+
|
|
1103
|
+
**Default: Local Evaluation with AikenTxEvaluator**
|
|
1104
|
+
|
|
1105
|
+
By default, `TxBuilder` uses `AikenTxEvaluator` for local Plutus script evaluation. This is configured automatically based on the `SlotConfig` and protocol parameters you provide:
|
|
1106
|
+
|
|
1107
|
+
```python
|
|
1108
|
+
from cometa import TxBuilder, SlotConfig
|
|
1109
|
+
|
|
1110
|
+
# AikenTxEvaluator is used automatically
|
|
1111
|
+
builder = TxBuilder(protocol_params, SlotConfig.preprod())
|
|
1112
|
+
|
|
1113
|
+
# Build transaction with Plutus scripts - evaluation happens locally
|
|
1114
|
+
tx = (
|
|
1115
|
+
builder
|
|
1116
|
+
.set_change_address(sender_address)
|
|
1117
|
+
.set_utxos(utxos)
|
|
1118
|
+
.add_input(script_utxo, redeemer=redeemer)
|
|
1119
|
+
.add_script(script)
|
|
1120
|
+
.build()
|
|
1121
|
+
)
|
|
1122
|
+
```
|
|
1123
|
+
|
|
1124
|
+
**Custom AikenTxEvaluator Configuration**
|
|
1125
|
+
|
|
1126
|
+
If you need to customize the evaluator settings, you can create your own instance:
|
|
1127
|
+
|
|
1128
|
+
```python
|
|
1129
|
+
from cometa import TxBuilder, SlotConfig
|
|
1130
|
+
from cometa.aiken import AikenTxEvaluator
|
|
1131
|
+
|
|
1132
|
+
# Create custom evaluator with specific settings
|
|
1133
|
+
evaluator = AikenTxEvaluator(
|
|
1134
|
+
cost_models=protocol_params.cost_models,
|
|
1135
|
+
slot_config=SlotConfig.preprod(),
|
|
1136
|
+
max_tx_ex_units=protocol_params.max_tx_ex_units,
|
|
1137
|
+
)
|
|
1138
|
+
|
|
1139
|
+
# Override the default evaluator
|
|
1140
|
+
builder = TxBuilder(protocol_params, SlotConfig.preprod())
|
|
1141
|
+
builder.set_evaluator(evaluator)
|
|
1142
|
+
```
|
|
1143
|
+
|
|
1144
|
+
**Custom Evaluator**
|
|
1145
|
+
|
|
1146
|
+
You can also implement your own evaluator by following the `TxEvaluator` protocol:
|
|
1147
|
+
|
|
1148
|
+
```python
|
|
1149
|
+
from typing import List, Optional
|
|
1150
|
+
from cometa import Transaction, Utxo, Redeemer
|
|
1151
|
+
|
|
1152
|
+
class MyTxEvaluator:
|
|
1153
|
+
"""Custom transaction evaluator."""
|
|
1154
|
+
|
|
1155
|
+
def get_name(self) -> str:
|
|
1156
|
+
return "MyCustomEvaluator"
|
|
1157
|
+
|
|
1158
|
+
def evaluate(
|
|
1159
|
+
self,
|
|
1160
|
+
transaction: Transaction,
|
|
1161
|
+
additional_utxos: Optional[List[Utxo]] = None,
|
|
1162
|
+
) -> List[Redeemer]:
|
|
1163
|
+
# Your custom evaluation logic here
|
|
1164
|
+
...
|
|
1165
|
+
```
|
|
1166
|
+
|
|
1167
|
+
Attach your custom evaluator to the builder:
|
|
1168
|
+
|
|
1169
|
+
```python
|
|
1170
|
+
my_evaluator = MyTxEvaluator()
|
|
1171
|
+
builder.set_evaluator(my_evaluator)
|
|
1172
|
+
```
|
|
1173
|
+
|
|
1174
|
+
<hr>
|
|
1175
|
+
|
|
1176
|
+
## **Building and Testing**
|
|
1177
|
+
|
|
1178
|
+
While the underlying [libcardano-c](https://github.com/Biglup/cardano-c) library has its own comprehensive test suite, Cometa.py maintains a separate, dedicated suite of tests. These binding-level tests verify the correctness of the Python-to-C interface and ensure the high-level API functions as expected.
|
|
1179
|
+
|
|
1180
|
+
To build and run the tests, use the following commands:
|
|
1181
|
+
|
|
1182
|
+
```bash
|
|
1183
|
+
pip install -e ".[dev]"
|
|
1184
|
+
pytest
|
|
1185
|
+
```
|
|
1186
|
+
|
|
1187
|
+
To run the linter:
|
|
1188
|
+
|
|
1189
|
+
```bash
|
|
1190
|
+
pylint src/cometa
|
|
1191
|
+
```
|
|
1192
|
+
|
|
1193
|
+
<hr>
|
|
1194
|
+
|
|
1195
|
+
## **License**
|
|
1196
|
+
|
|
1197
|
+
Cometa.py is licensed under the Apache 2.0 License. See the [LICENSE](LICENSE) file for more information.
|