fabric-chaincode-python 2.5.2__py3-none-any.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.
Files changed (40) hide show
  1. fabric_chaincode_python-2.5.2.dist-info/METADATA +101 -0
  2. fabric_chaincode_python-2.5.2.dist-info/RECORD +40 -0
  3. fabric_chaincode_python-2.5.2.dist-info/WHEEL +5 -0
  4. fabric_chaincode_python-2.5.2.dist-info/licenses/LICENSE +201 -0
  5. fabric_chaincode_python-2.5.2.dist-info/licenses/NOTICE +18 -0
  6. fabric_chaincode_python-2.5.2.dist-info/top_level.txt +1 -0
  7. src/__init__.py +5 -0
  8. src/fabric_contract_api/__init__.py +51 -0
  9. src/fabric_contract_api/contractapi/__init__.py +29 -0
  10. src/fabric_contract_api/contractapi/contract.py +141 -0
  11. src/fabric_contract_api/contractapi/contract_chaincode.py +552 -0
  12. src/fabric_contract_api/contractapi/system_contract.py +45 -0
  13. src/fabric_contract_api/contractapi/transaction_context.py +160 -0
  14. src/fabric_contract_api/contractapi/utils/__init__.py +4 -0
  15. src/fabric_contract_api/contractapi/utils/undefined_interface.py +33 -0
  16. src/fabric_contract_api/internal/__init__.py +16 -0
  17. src/fabric_contract_api/internal/contract_function.py +453 -0
  18. src/fabric_contract_api/internal/transaction_handler.py +131 -0
  19. src/fabric_contract_api/internal/types.py +180 -0
  20. src/fabric_contract_api/internal/types_handler.py +224 -0
  21. src/fabric_contract_api/internal/utils.py +59 -0
  22. src/fabric_contract_api/metadata/__init__.py +32 -0
  23. src/fabric_contract_api/metadata/metadata.py +456 -0
  24. src/fabric_contract_api/metadata/schema.py +238 -0
  25. src/fabric_contract_api/serializer/__init__.py +5 -0
  26. src/fabric_contract_api/serializer/json_transaction_serializer.py +363 -0
  27. src/fabric_contract_api/serializer/transaction_serializer.py +45 -0
  28. src/fabric_shim/__init__.py +2 -0
  29. src/fabric_shim/chaincode.py +8 -0
  30. src/fabric_shim/handler.py +336 -0
  31. src/fabric_shim/interfaces.py +134 -0
  32. src/fabric_shim/iterators.py +107 -0
  33. src/fabric_shim/logger.py +1 -0
  34. src/fabric_shim/logging.py +63 -0
  35. src/fabric_shim/msg_queue_handler.py +91 -0
  36. src/fabric_shim/response.py +49 -0
  37. src/fabric_shim/server.py +155 -0
  38. src/fabric_shim/stub.py +342 -0
  39. src/fabric_shim/utils.py +41 -0
  40. src/version.py +3 -0
@@ -0,0 +1,101 @@
1
+ Metadata-Version: 2.4
2
+ Name: fabric-chaincode-python
3
+ Version: 2.5.2
4
+ Summary: Hyperledger Fabric chaincode shim and contract API for Python (experimental)
5
+ Home-page: https://github.com/kmilodenisglez/fabric-chaincode-python/
6
+ Download-URL: https://github.com/kmilodenisglez/fabric-chaincode-python/
7
+ Author: Hyperledger Community
8
+ License: Apache License v2.0
9
+ Keywords: Hyperledger,Fabric,Chaincode,Python
10
+ Platform: any
11
+ Requires-Python: >=3.10
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+ License-File: NOTICE
15
+ Requires-Dist: grpcio<2.0.0,>=1.83.1
16
+ Requires-Dist: grpclib>=0.4.3
17
+ Requires-Dist: protobuf<8.0.0,>=5.27.0
18
+ Requires-Dist: hyperledger-fabric-protos<0.4.0,>=0.3.7.dev1
19
+ Requires-Dist: jsonschema>=4.0.0
20
+ Dynamic: author
21
+ Dynamic: download-url
22
+ Dynamic: home-page
23
+ Dynamic: license-file
24
+ Dynamic: platform
25
+
26
+ # Hyperledger Fabric Chaincode Python
27
+
28
+ ![GitHub License](https://img.shields.io/github/license/hyperledger/fabric-chaincode-python)
29
+ [![OpenSSF Best Practices](https://bestpractices.coreinfrastructure.org/projects/14928/badge)](https://bestpractices.coreinfrastructure.org/projects/14928)
30
+ [![OpenSSF Scorecard](https://api.scorecard.dev/projects/github.com/hyperledger/fabric-chaincode-python/badge)](https://scorecard.dev/viewer/?uri=github.com/hyperledger/fabric-chaincode-python)
31
+
32
+ [![Python Version](https://img.shields.io/pypi/pyversions/fabric-chaincode-python.svg)](https://pypi.org/project/fabric-chaincode-python/)
33
+ [![GitHub Actions](https://github.com/hyperledger/fabric-chaincode-python/workflows/CI/badge.svg)](https://github.com/hyperledger/fabric-chaincode-python/actions?query=workflow%3ACI)
34
+ [![GitHub Release](https://img.shields.io/github/v/release/hyperledger/fabric-chaincode-python.svg)](https://github.com/hyperledger/fabric-chaincode-python/releases)
35
+
36
+ This is a Python based implementation of Hyperledger Fabric chaincode shim and contract
37
+ API, which enables development of smart contracts using the Python language. Chaincodes
38
+ (smart contracts) written in Python run inside Hyperledger Fabric peers.
39
+
40
+ ## Documentation
41
+
42
+ - [API documentation](https://hyperledger.github.io/fabric-chaincode-python/)
43
+ - [Full Hyperledger Fabric documentation](https://hyperledger-fabric.readthedocs.io/)
44
+ - [Samples repository](https://github.com/hyperledger/fabric-samples)
45
+
46
+ ## Project structure
47
+
48
+ ```
49
+ src/
50
+ ├── fabric_contract_api/ Python Contract API
51
+ └── fabric_shim/ Python chaincode shim (Fabric 2.x)
52
+ ```
53
+
54
+ - **fabric_contract_api** - Contains the Python contract API used to write smart contracts with the high-level contract programming model.
55
+ - **fabric_shim** - Contains the Python classes that implement the chaincode shim API and the way to communicate with Fabric peers.
56
+
57
+ ## Building and testing
58
+
59
+ Make sure you have the following prereqs installed:
60
+
61
+ - [Python](https://www.python.org/) 3.11 or later
62
+ - [pip](https://pip.pypa.io/en/stable/)
63
+
64
+ Create a virtual environment and install the development dependencies:
65
+
66
+ ```
67
+ python3 -m venv .venv
68
+ source .venv/bin/activate
69
+ pip install -e . -r requirements-dev.txt
70
+ ```
71
+
72
+ Run the unit tests:
73
+
74
+ ```
75
+ pytest tests/
76
+ ```
77
+
78
+ ## Contributing
79
+
80
+ We welcome contributions to the Hyperledger Fabric project in many forms. If you are
81
+ interested in contributing updates to this project, please start with the
82
+ [contributing guide](CONTRIBUTING.md).
83
+
84
+ There is also a [release guide](RELEASING.md) describing the process for publishing new
85
+ versions.
86
+
87
+ ## Community
88
+
89
+ - [Hyperledger Community](https://www.hyperledger.org/community)
90
+ - [Hyperledger mailing lists and archives](http://lists.hyperledger.org/)
91
+ - [Hyperledger Chat](http://chat.hyperledger.org/channel/fabric)
92
+ - [Hyperledger Fabric Wiki](https://wiki.hyperledger.org/display/Fabric)
93
+ - [Hyperledger Code of Conduct](CODE_OF_CONDUCT.md)
94
+
95
+ ## License <a name="license"></a>
96
+
97
+ Hyperledger Project source code files are made available under the Apache License,
98
+ Version 2.0 (Apache-2.0), located in the [LICENSE](LICENSE) file. Hyperledger Project
99
+ documentation files are made available under the Creative Commons Attribution 4.0
100
+ International License (CC-BY-4.0), available at
101
+ http://creativecommons.org/licenses/by/4.0/.
@@ -0,0 +1,40 @@
1
+ fabric_chaincode_python-2.5.2.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
2
+ fabric_chaincode_python-2.5.2.dist-info/licenses/NOTICE,sha256=UFpjAW402B5KR7CekkKG5kO1lk18Rpe7j1yUuf6aQ5I,802
3
+ src/__init__.py,sha256=Kv2_IpzZI0qfnp4UUo6luBDpjqMEyGnubeANvvCrw34,80
4
+ src/version.py,sha256=VflimvOZJOtOSVy8q3PhPH7b4fPixTKblABNuzKDWYw,57
5
+ src/fabric_contract_api/__init__.py,sha256=H3TbY8h7CuX5H3hh5c9vR5eBgYroJSkONh5fudPZdec,1683
6
+ src/fabric_contract_api/contractapi/__init__.py,sha256=SePH6lw7y6V1GqOEdqn6OUGP0ha7xGfiAUd2tJbyq8k,1037
7
+ src/fabric_contract_api/contractapi/contract.py,sha256=icXjFRcD8-eN12GgLRwZUQ-Oj12pj5sZXbqwoR4UxGo,4689
8
+ src/fabric_contract_api/contractapi/contract_chaincode.py,sha256=TJ0KdeQN7DlUGOKyP60Q5KiUB0bfe_enL68do7wns8o,21079
9
+ src/fabric_contract_api/contractapi/system_contract.py,sha256=0KqwejjrN6yfDH5dAC8g4H9rFccyFeiXaqLyZ8OmL90,1358
10
+ src/fabric_contract_api/contractapi/transaction_context.py,sha256=MsgNoOkRuqlEyz0NvSBaB4ooYuPeKKEjt0tdZ-9zAgk,5314
11
+ src/fabric_contract_api/contractapi/utils/__init__.py,sha256=D2oclgtHy4iS6sS0ZZWK0ZIIuktOSESaX0i6m21aTDM,171
12
+ src/fabric_contract_api/contractapi/utils/undefined_interface.py,sha256=Fzp5TgDKOCMgSuHjpn_eQnfwwbxWo64LGHIAB4AfRnw,1030
13
+ src/fabric_contract_api/internal/__init__.py,sha256=gFdvT7EUdXJJxW5F7XAD5xAoPyzTge0Om8x4E8qJ8DU,874
14
+ src/fabric_contract_api/internal/contract_function.py,sha256=cCre6XAQQeCpuDcF7AWfQIeheFmJiJpPcSp4s9Xtb5g,17161
15
+ src/fabric_contract_api/internal/transaction_handler.py,sha256=6Uh4MSxe399s1ZlA0nzCM8qRPoUPQqapMZ7OVZ76cqQ,4758
16
+ src/fabric_contract_api/internal/types.py,sha256=vredtncoulWBPWKK1MAN5j2NVludChQAPgZjYx4DQtQ,5272
17
+ src/fabric_contract_api/internal/types_handler.py,sha256=7HTgWHp1ycESJjDiQ0XKQujWBmZz7iC1voE96LpKw44,7726
18
+ src/fabric_contract_api/internal/utils.py,sha256=HCPcVb4mti4plOBkJKQvyjWdhdjVd-UKrjTnfHxtGpo,1690
19
+ src/fabric_contract_api/metadata/__init__.py,sha256=K7Lc8q92CaSL8OLEMqlQKMT_DoMEfkvgJRnrr8vBoWs,1086
20
+ src/fabric_contract_api/metadata/metadata.py,sha256=w6NoM_l5Mtu3LBw-ls1GeFQAU8PFMsjEQxmTixnsTeQ,15339
21
+ src/fabric_contract_api/metadata/schema.py,sha256=ulinuYNX8tGxtmozi2_73LYRRmnTShQ6toHOun2wJMo,8426
22
+ src/fabric_contract_api/serializer/__init__.py,sha256=LwRs7Ypdi3oa9ASFpiNP2HGONN2zIIIJlxWgft50vis,231
23
+ src/fabric_contract_api/serializer/json_transaction_serializer.py,sha256=ntountwf_IPnDOT_wLW80gDiHsDFEw1sEEjWNsAyTAo,14293
24
+ src/fabric_contract_api/serializer/transaction_serializer.py,sha256=tBsLrftnW_ViWtTvwfBQR5__Ep9uopNLvt00oLIMpiI,1586
25
+ src/fabric_shim/__init__.py,sha256=tnNC6uHPZZRziNtt4D4MAqnkqtJUUsdl31ezw33gCyU,118
26
+ src/fabric_shim/chaincode.py,sha256=cG9-cWEJz_xQhz9GnbidCIrJO8eOPECxxtHmxHVsexA,223
27
+ src/fabric_shim/handler.py,sha256=vIEvVl5meJOKIWUvGwCgFwOMXZiwwLXymZOx8_w_Rfo,14320
28
+ src/fabric_shim/interfaces.py,sha256=O6BNRzcnyuSbAT-viDW69uM3krg5uZn_XcWOs813Z0k,4821
29
+ src/fabric_shim/iterators.py,sha256=qjEOcAhT44rE_g10mPYZR32KG7riRf3CvIvOfqYcXNY,3596
30
+ src/fabric_shim/logger.py,sha256=bG7Ffen4LvQtgnYPFEpFccsWs81t4zqqeqn9ZeirH6E,38
31
+ src/fabric_shim/logging.py,sha256=UCRQsikez_badFYMYy3zugs3elGUTOYw5fLhLt-HzB4,1858
32
+ src/fabric_shim/msg_queue_handler.py,sha256=4JqSqMSbX010Ls_6dHtbmGR3LwPdkq1z55CW5kJoaW4,3111
33
+ src/fabric_shim/response.py,sha256=4P0013ULz7SMqTXBWKHTqQR62WRXBex9wgpU_Oqn1ZU,1826
34
+ src/fabric_shim/server.py,sha256=A6tdyqyNi46Aqd-C1n4kxy16Zfqbfh-beBqOuztgwqo,5429
35
+ src/fabric_shim/stub.py,sha256=2ITTZyoMLUfB2f7Wjb4wCt1PIBJ-GlnkGjgRLh9wQmE,15389
36
+ src/fabric_shim/utils.py,sha256=bmySQ0bEh3xKqAZydwBS1VtAcUmOhT98pxr9xWO2xxQ,1223
37
+ fabric_chaincode_python-2.5.2.dist-info/METADATA,sha256=fxttBSxUbJPty0NtZ-k9tpnSPcApxKRyhokpYnGrH3k,4144
38
+ fabric_chaincode_python-2.5.2.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
39
+ fabric_chaincode_python-2.5.2.dist-info/top_level.txt,sha256=74rtVfumQlgAPzR5_2CgYN24MB0XARCg0t-gzk6gTrM,4
40
+ fabric_chaincode_python-2.5.2.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.0.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,18 @@
1
+ Fabric Chaincode for Python
2
+ Copyright 2023-2026 The Hyperledger Fabric Contributors
3
+
4
+ This product includes software developed at
5
+ Hyperledger (https://www.hyperledger.org/) and the
6
+ Linux Foundation Decentralized Trust (https://www.lfdecentralizedtrust.org/).
7
+
8
+ This product is licensed under the Apache License, Version 2.0 (the "License");
9
+ you may not use this product except in compliance with the License.
10
+ You may obtain a copy of the License at
11
+
12
+ http://www.apache.org/licenses/LICENSE-2.0
13
+
14
+ Unless required by applicable law or agreed to in writing, software
15
+ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16
+ WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
17
+ License for the specific language governing permissions and limitations under
18
+ the License.
src/__init__.py ADDED
@@ -0,0 +1,5 @@
1
+ #
2
+ # SPDX-License-Identifier: Apache-2.0
3
+ #
4
+
5
+ from .version import VERSION # noqa
@@ -0,0 +1,51 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ """Hyperledger Fabric Contract API for Python.
3
+
4
+ This package provides a high-level, contract-oriented programming model on
5
+ top of the low-level :mod:`fabric_shim` chaincode shim. It is the Python
6
+ equivalent of Hyperledger's ``fabric-contract-api-go``.
7
+
8
+ Public surface (mirrors the Go layout)::
9
+
10
+ fabric_contract_api.contractapi # Contract, ContractChaincode, ...
11
+ fabric_contract_api.serializer # TransactionSerializer, JSONSerializer
12
+ fabric_contract_api.metadata # Metadata types & schema helpers
13
+ fabric_contract_api.internal # Introspection & type validation helpers
14
+
15
+ The most useful imports for application developers are::
16
+
17
+ from fabric_contract_api.contractapi import Contract, ContractChaincode
18
+ from fabric_contract_api.contractapi import TransactionContext, TransactionContextInterface
19
+ """
20
+
21
+ from .contractapi import ( # noqa: F401 (re-exported for convenience)
22
+ Contract,
23
+ ContractChaincode,
24
+ ContractInterface,
25
+ EvaluationContractInterface,
26
+ IgnoreContractInterface,
27
+ SystemContract,
28
+ SystemContractName,
29
+ TransactionContext,
30
+ TransactionContextInterface,
31
+ SettableTransactionContextInterface,
32
+ )
33
+ from .serializer import ( # noqa: F401
34
+ TransactionSerializer,
35
+ JSONSerializer,
36
+ )
37
+
38
+ __all__ = [
39
+ "Contract",
40
+ "ContractChaincode",
41
+ "ContractInterface",
42
+ "EvaluationContractInterface",
43
+ "IgnoreContractInterface",
44
+ "SystemContract",
45
+ "SystemContractName",
46
+ "TransactionContext",
47
+ "TransactionContextInterface",
48
+ "SettableTransactionContextInterface",
49
+ "TransactionSerializer",
50
+ "JSONSerializer",
51
+ ]
@@ -0,0 +1,29 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ """Contract API package for :mod:`fabric_contract_api`.
3
+
4
+ Mirrors Go's ``contractapi`` package. Provides the high-level building
5
+ blocks for declaring and running contracts:
6
+
7
+ * :class:`Contract` — base class for application contracts.
8
+ * :class:`ContractChaincode` — chaincode adapter that dispatches to
9
+ registered contracts.
10
+ * :class:`TransactionContext` and :class:`TransactionContextInterface` —
11
+ per-transaction context passed to contract functions.
12
+ * :class:`SystemContract` — built-in contract that exposes chaincode
13
+ metadata.
14
+ """
15
+
16
+ from .contract import ( # noqa: F401
17
+ Contract,
18
+ ContractInterface,
19
+ EvaluationContractInterface,
20
+ IgnoreContractInterface,
21
+ )
22
+ from .contract_chaincode import ContractChaincode # noqa: F401
23
+ from .system_contract import SystemContract, SystemContractName # noqa: F401
24
+ from .transaction_context import ( # noqa: F401
25
+ ClientIdentity,
26
+ SettableTransactionContextInterface,
27
+ TransactionContext,
28
+ TransactionContextInterface,
29
+ )
@@ -0,0 +1,141 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ """Contract base classes and interfaces.
3
+
4
+ This is the Python equivalent of Go's ``contractapi/contract.go``. It
5
+ defines:
6
+
7
+ * :class:`ContractInterface` — the :class:`abc.ABC` every contract must
8
+ implement.
9
+ * :class:`IgnoreContractInterface` — optional interface for contracts that
10
+ want to mark certain public methods as not callable from the outside.
11
+ * :class:`EvaluationContractInterface` — optional interface that lets a
12
+ contract declare which transactions are "evaluate" (i.e. read-only queries).
13
+ * :class:`Contract` — a concrete base class with sensible defaults that
14
+ application contracts can subclass (or embed) to quickly satisfy the
15
+ interfaces.
16
+ """
17
+
18
+ from __future__ import annotations
19
+
20
+ import abc
21
+ from typing import Any, List, Optional
22
+
23
+ from ..metadata import InfoMetadata
24
+ from .transaction_context import (
25
+ SettableTransactionContextInterface,
26
+ TransactionContext,
27
+ )
28
+
29
+
30
+ class ContractInterface(abc.ABC):
31
+ """Interface that every contract must implement."""
32
+
33
+ @abc.abstractmethod
34
+ def get_info(self) -> InfoMetadata:
35
+ """Return the info block used in the metadata."""
36
+
37
+ @abc.abstractmethod
38
+ def get_unknown_transaction(self) -> Optional[Any]:
39
+ """Return the unknown-transaction callable, or ``None``."""
40
+
41
+ @abc.abstractmethod
42
+ def get_before_transaction(self) -> Optional[Any]:
43
+ """Return the before-transaction callable, or ``None``."""
44
+
45
+ @abc.abstractmethod
46
+ def get_after_transaction(self) -> Optional[Any]:
47
+ """Return the after-transaction callable, or ``None``."""
48
+
49
+ @abc.abstractmethod
50
+ def get_name(self) -> str:
51
+ """Return the name of the contract."""
52
+
53
+ @abc.abstractmethod
54
+ def get_transaction_context_handler(self) -> SettableTransactionContextInterface:
55
+ """Return the transaction-context class to use."""
56
+
57
+
58
+ class IgnoreContractInterface(abc.ABC):
59
+ """Optional interface for marking methods as not-callable."""
60
+
61
+ @abc.abstractmethod
62
+ def get_ignored_functions(self) -> List[str]:
63
+ """Return the list of method names that should be excluded."""
64
+
65
+
66
+ class EvaluationContractInterface(abc.ABC):
67
+ """Optional interface for marking methods as evaluate (read-only)."""
68
+
69
+ @abc.abstractmethod
70
+ def get_evaluate_transactions(self) -> List[str]:
71
+ """Return the list of method names tagged as evaluate."""
72
+
73
+
74
+ class Contract(ContractInterface):
75
+ """Default contract base class.
76
+
77
+ Subclass this to define your own contract. You only need to override
78
+ the methods that are interesting to you::
79
+
80
+ class MyContract(Contract):
81
+ Name = "MyContract"
82
+
83
+ def my_transaction(self, ctx, key: str) -> str:
84
+ ...
85
+
86
+ The following attributes are set as plain instance/class attributes so
87
+ they can be easily overridden:
88
+
89
+ * :attr:`Name` — the contract name.
90
+ * :attr:`Info` — a :class:`metadata.InfoMetadata` describing the contract.
91
+ * :attr:`UnknownTransaction` — callable for unknown-transaction handling.
92
+ * :attr:`BeforeTransaction` — callable invoked before each transaction.
93
+ * :attr:`AfterTransaction` — callable invoked after each transaction.
94
+ * :attr:`TransactionContextHandler` — the transaction-context class.
95
+ """
96
+
97
+ Name: str = ""
98
+ Info: Optional[InfoMetadata] = None
99
+ UnknownTransaction: Optional[Any] = None
100
+ BeforeTransaction: Optional[Any] = None
101
+ AfterTransaction: Optional[Any] = None
102
+ TransactionContextHandler: Optional[type] = None
103
+
104
+ def __init__(self) -> None:
105
+ # Each Contract instance gets its own InfoMetadata so subclasses don't
106
+ # accidentally share state via the class-level attribute.
107
+ if self.Info is None:
108
+ self.Info = InfoMetadata()
109
+
110
+ def get_info(self) -> InfoMetadata:
111
+ if self.Info is None:
112
+ self.Info = InfoMetadata()
113
+ return self.Info
114
+
115
+ def get_unknown_transaction(self) -> Optional[Any]:
116
+ return self.UnknownTransaction
117
+
118
+ def get_before_transaction(self) -> Optional[Any]:
119
+ return self.BeforeTransaction
120
+
121
+ def get_after_transaction(self) -> Optional[Any]:
122
+ return self.AfterTransaction
123
+
124
+ def get_name(self) -> str:
125
+ return self.Name
126
+
127
+ def get_transaction_context_handler(self) -> SettableTransactionContextInterface:
128
+ if self.TransactionContextHandler is None:
129
+ return TransactionContext()
130
+ handler = self.TransactionContextHandler
131
+ if isinstance(handler, type):
132
+ return handler()
133
+ return handler
134
+
135
+
136
+ __all__ = [
137
+ "Contract",
138
+ "ContractInterface",
139
+ "EvaluationContractInterface",
140
+ "IgnoreContractInterface",
141
+ ]