├── .gitignore
├── README.md
├── license.txt
├── pom.xml
└── src
└── main
├── java
└── org
│ └── xialing
│ ├── FabricServerApplication.java
│ ├── common
│ ├── constants
│ │ └── Constant.java
│ ├── dto
│ │ ├── R.java
│ │ ├── base
│ │ │ ├── AbsRequestBean.java
│ │ │ ├── AbsResponseBean.java
│ │ │ ├── RequestBean.java
│ │ │ └── ResponseBean.java
│ │ ├── block
│ │ │ ├── BlockChainChannelDTO.java
│ │ │ ├── BlockChainContractDTO.java
│ │ │ ├── BlockChainContractFunDTO.java
│ │ │ ├── BlockChainContractFunEventDTO.java
│ │ │ ├── BlockChainNetDTO.java
│ │ │ ├── BlockChainOrdererDTO.java
│ │ │ ├── BlockChainOrgCaDTO.java
│ │ │ ├── BlockChainOrgDTO.java
│ │ │ ├── BlockChainOrgNodeDTO.java
│ │ │ ├── BlockChainOrgUserDTO.java
│ │ │ ├── ContractChannelDTO.java
│ │ │ └── NodeChannelDTO.java
│ │ └── route
│ │ │ ├── BaasRouteDTO.java
│ │ │ ├── base
│ │ │ ├── Block.java
│ │ │ ├── Transaction.java
│ │ │ └── request
│ │ │ │ └── BaseRequest.java
│ │ │ ├── blockinfo
│ │ │ ├── BlockInfoRequest.java
│ │ │ ├── BlockList.java
│ │ │ ├── BlockSummary.java
│ │ │ └── LatesdTransactionList.java
│ │ │ ├── event
│ │ │ ├── BlockEventMsgDTO.java
│ │ │ ├── ContractEvent.java
│ │ │ └── ContractEventListenerRequest.java
│ │ │ ├── invoke
│ │ │ ├── InvokeAsyncQueryRequest.java
│ │ │ ├── InvokeAsyncQueryResult.java
│ │ │ ├── InvokeRequest.java
│ │ │ └── InvokeResult.java
│ │ │ └── query
│ │ │ ├── QueryRequest.java
│ │ │ └── QueryResult.java
│ ├── enums
│ │ ├── AsyncInvokeTypeEnum.java
│ │ └── ResponseCodeEnum.java
│ └── exception
│ │ └── ServiceException.java
│ └── fabric
│ ├── config
│ └── FabricConfig.java
│ ├── context
│ └── ChannelContext.java
│ ├── controller
│ ├── FabricController.java
│ ├── FabricEventController.java
│ └── FabricInfoController.java
│ ├── listener
│ └── FabricEventListener.java
│ ├── model
│ ├── ChannelBean.java
│ ├── EventPayLoad.java
│ ├── FabricEnrollment.java
│ └── FabricUser.java
│ ├── remote
│ └── RemoteBlockEventService.java
│ ├── service
│ ├── CommonService.java
│ ├── FabricEventService.java
│ ├── FabricInfoService.java
│ └── FabricService.java
│ ├── template
│ └── FabricTemplate.java
│ └── utils
│ ├── CryptoUtils.java
│ ├── FabricUtils.java
│ └── ThreadPoolManager.java
└── resources
├── application.yml
├── bootstrap.yml
├── ca
├── cacert
├── client.pem
└── out_sk
└── logback-spring.xml
/.gitignore:
--------------------------------------------------------------------------------
1 | # Created by .ignore support plugin (hsz.mobi)
2 | *.iml
3 | .idea/
4 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # fabric-java-block
2 |
3 | [](https://996.icu)
4 | [](https://github.com/996icu/996.ICU/blob/master/LICENSE)
5 |
6 | 集成springboot和fabric sdk 提供rest api的接口
7 |
8 | 用swagger 生成api文档
9 |
10 | 基于Hyperledger Fabric v1.4.0版本...
11 |
12 | 1.调用合约
13 |
14 | 2.事件监听
15 |
16 | 3.区块链概况查询
17 |
18 |
19 | 联系 email top3372@163.com
--------------------------------------------------------------------------------
/license.txt:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright © 2007 Free Software Foundation, Inc.
5 |
6 | Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 | The GNU General Public License is a free, copyleft license for software and other kinds of works.
10 |
11 | The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too.
12 |
13 | When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things.
14 |
15 | To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others.
16 |
17 | For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights.
18 |
19 | Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it.
20 |
21 | For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions.
22 |
23 | Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users.
24 |
25 | Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free.
26 |
27 | The precise terms and conditions for copying, distribution and modification follow.
28 |
29 | TERMS AND CONDITIONS
30 | 0. Definitions.
31 | “This License” refers to version 3 of the GNU General Public License.
32 |
33 | “Copyright” also means copyright-like laws that apply to other kinds of works, such as semiconductor masks.
34 |
35 | “The Program” refers to any copyrightable work licensed under this License. Each licensee is addressed as “you”. “Licensees” and “recipients” may be individuals or organizations.
36 |
37 | To “modify” a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a “modified version” of the earlier work or a work “based on” the earlier work.
38 |
39 | A “covered work” means either the unmodified Program or a work based on the Program.
40 |
41 | To “propagate” a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well.
42 |
43 | To “convey” a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying.
44 |
45 | An interactive user interface displays “Appropriate Legal Notices” to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion.
46 |
47 | 1. Source Code.
48 | The “source code” for a work means the preferred form of the work for making modifications to it. “Object code” means any non-source form of a work.
49 |
50 | A “Standard Interface” means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language.
51 |
52 | The “System Libraries” of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A “Major Component”, in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it.
53 |
54 | The “Corresponding Source” for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work.
55 |
56 | The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source.
57 |
58 | The Corresponding Source for a work in source code form is that same work.
59 |
60 | 2. Basic Permissions.
61 | All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law.
62 |
63 | You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you.
64 |
65 | Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary.
66 |
67 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
68 | No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures.
69 |
70 | When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures.
71 |
72 | 4. Conveying Verbatim Copies.
73 | You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program.
74 |
75 | You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee.
76 |
77 | 5. Conveying Modified Source Versions.
78 | You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions:
79 |
80 | a) The work must carry prominent notices stating that you modified it, and giving a relevant date.
81 | b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to “keep intact all notices”.
82 | c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it.
83 | d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so.
84 | A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an “aggregate” if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate.
85 |
86 | 6. Conveying Non-Source Forms.
87 | You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways:
88 |
89 | a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange.
90 | b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge.
91 | c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b.
92 | d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements.
93 | e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d.
94 | A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work.
95 |
96 | A “User Product” is either (1) a “consumer product”, which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, “normally used” refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product.
97 |
98 | “Installation Information” for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made.
99 |
100 | If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM).
101 |
102 | The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network.
103 |
104 | Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying.
105 |
106 | 7. Additional Terms.
107 | “Additional permissions” are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions.
108 |
109 | When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission.
110 |
111 | Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms:
112 |
113 | a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or
114 | b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or
115 | c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or
116 | d) Limiting the use for publicity purposes of names of licensors or authors of the material; or
117 | e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or
118 | f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors.
119 | All other non-permissive additional terms are considered “further restrictions” within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying.
120 |
121 | If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms.
122 |
123 | Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way.
124 |
125 | 8. Termination.
126 | You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11).
127 |
128 | However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation.
129 |
130 | Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice.
131 |
132 | Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10.
133 |
134 | 9. Acceptance Not Required for Having Copies.
135 | You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so.
136 |
137 | 10. Automatic Licensing of Downstream Recipients.
138 | Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License.
139 |
140 | An “entity transaction” is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts.
141 |
142 | You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it.
143 |
144 | 11. Patents.
145 | A “contributor” is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's “contributor version”.
146 |
147 | A contributor's “essential patent claims” are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, “control” includes the right to grant patent sublicenses in a manner consistent with the requirements of this License.
148 |
149 | Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version.
150 |
151 | In the following three paragraphs, a “patent license” is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To “grant” such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party.
152 |
153 | If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. “Knowingly relying” means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid.
154 |
155 | If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it.
156 |
157 | A patent license is “discriminatory” if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007.
158 |
159 | Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law.
160 |
161 | 12. No Surrender of Others' Freedom.
162 | If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program.
163 |
164 | 13. Use with the GNU Affero General Public License.
165 | Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such.
166 |
167 | 14. Revised Versions of this License.
168 | The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.
169 |
170 | Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License “or any later version” applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation.
171 |
172 | If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program.
173 |
174 | Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version.
175 |
176 | 15. Disclaimer of Warranty.
177 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
178 |
179 | 16. Limitation of Liability.
180 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
181 |
182 | 17. Interpretation of Sections 15 and 16.
183 | If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee.
184 |
185 | END OF TERMS AND CONDITIONS
186 |
187 | How to Apply These Terms to Your New Programs
188 | If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms.
189 |
190 | To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the “copyright” line and a pointer to where the full notice is found.
191 |
192 |
193 | Copyright (C)
194 |
195 | This program is free software: you can redistribute it and/or modify
196 | it under the terms of the GNU General Public License as published by
197 | the Free Software Foundation, either version 3 of the License, or
198 | (at your option) any later version.
199 |
200 | This program is distributed in the hope that it will be useful,
201 | but WITHOUT ANY WARRANTY; without even the implied warranty of
202 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
203 | GNU General Public License for more details.
204 |
205 | You should have received a copy of the GNU General Public License
206 | along with this program. If not, see .
207 | Also add information on how to contact you by electronic and paper mail.
208 |
209 | If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode:
210 |
211 | Copyright (C)
212 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
213 | This is free software, and you are welcome to redistribute it
214 | under certain conditions; type `show c' for details.
215 | The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an “about box”.
216 |
217 | You should also get your employer (if you work as a programmer) or school, if any, to sign a “copyright disclaimer” for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see .
218 |
219 | The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read .
220 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | org.springframework.boot
8 | spring-boot-starter-parent
9 | 2.2.5.RELEASE
10 |
11 |
12 | xialing-block-route-fabric
13 | 1.0-SNAPSHOT
14 | Fabric SDK服务
15 | jar
16 |
17 |
18 | 1.23.0
19 | 3.10.0
20 | 1.63
21 | 4.5.10
22 | true
23 | UTF-8
24 | UTF-8
25 | 8.0.18
26 |
27 |
28 |
29 |
30 |
31 |
32 | com.googlecode.json-simple
33 | json-simple
34 | 1.1.1
35 |
36 |
37 |
38 |
39 |
40 | org.hyperledger.fabric-sdk-java
41 | fabric-sdk-java
42 | 1.4.8
43 |
44 |
45 |
46 |
47 |
48 | org.json
49 | json
50 | 20190722
51 |
52 |
53 |
54 |
55 | org.testng
56 | testng
57 | 6.14.3
58 | test
59 |
60 |
61 |
62 | io.grpc
63 | grpc-netty
64 | ${grpc.version}
65 |
66 |
67 | io.grpc
68 | grpc-protobuf
69 | ${grpc.version}
70 |
71 |
72 | io.grpc
73 | grpc-stub
74 | ${grpc.version}
75 |
76 |
77 | io.netty
78 | netty-tcnative-boringssl-static
79 | 2.0.26.Final
80 |
81 |
82 | io.netty
83 | netty-codec-http2
84 | 4.1.41.Final
85 |
86 |
87 |
88 | com.google.protobuf
89 | protobuf-java
90 | ${protobuf.version}
91 |
92 |
93 | com.google.protobuf
94 | protobuf-java-util
95 | ${protobuf.version}
96 |
97 |
98 |
99 | org.bouncycastle
100 | bcpkix-jdk15on
101 | ${bouncycastle.version}
102 |
103 |
104 |
105 | commons-logging
106 | commons-logging
107 | 1.2
108 |
109 |
110 | commons-cli
111 | commons-cli
112 | 1.4
113 |
114 |
115 | org.apache.commons
116 | commons-compress
117 | [1.19,)
118 |
119 |
120 | commons-io
121 | commons-io
122 | 2.6
123 |
124 |
125 |
126 | org.springframework.boot
127 | spring-boot-starter
128 |
129 |
130 |
131 |
132 | org.apache.httpcomponents
133 | httpclient
134 | ${httpclient.version}
135 |
136 |
137 |
138 |
139 |
140 | org.apache.httpcomponents
141 | httpmime
142 | ${httpclient.version}
143 | test
144 |
145 |
146 |
147 |
148 |
149 | org.glassfish
150 | javax.json
151 | 1.1.4
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 | com.alibaba
169 | fastjson
170 | 1.2.54
171 |
172 |
173 |
174 |
175 | org.yaml
176 | snakeyaml
177 | 1.25
178 |
179 |
180 |
181 | javax.servlet
182 | jstl
183 | 1.2
184 |
185 |
186 |
187 | org.springframework.boot
188 | spring-boot-starter-actuator
189 |
190 |
191 | org.springframework.boot
192 | spring-boot-starter-web
193 |
194 |
195 | org.springframework.boot
196 | spring-boot-starter-test
197 | test
198 |
199 |
200 | org.springframework.boot
201 | spring-boot-devtools
202 | runtime
203 |
204 |
205 |
206 |
207 |
208 | org.eclipse.jdt.core.compiler
209 | ecj
210 | 4.6.1
211 | provided
212 |
213 |
214 |
215 | io.springfox
216 | springfox-swagger2
217 | 2.9.2
218 |
219 |
220 |
221 | io.springfox
222 | springfox-swagger-ui
223 | 2.9.2
224 |
225 |
226 |
227 | org.springframework.boot
228 | spring-boot-starter-aop
229 |
230 |
231 |
232 | org.projectlombok
233 | lombok
234 |
235 |
236 |
237 | cn.hutool
238 | hutool-all
239 | 5.1.4
240 |
241 |
242 |
243 |
244 | block-route-fabric
245 |
246 |
247 | org.springframework.boot
248 | spring-boot-maven-plugin
249 |
250 | org.xialing.FabricServerApplication
251 |
252 |
253 |
254 |
255 |
--------------------------------------------------------------------------------
/src/main/java/org/xialing/FabricServerApplication.java:
--------------------------------------------------------------------------------
1 | package org.xialing;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | /**
7 | * @author leon
8 | * @version 1.0
9 | * @date 2020/2/27 13:51
10 | */
11 | @SpringBootApplication
12 | public class FabricServerApplication {
13 | public static void main(String[] args) {
14 | SpringApplication.run(FabricServerApplication.class, args);
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src/main/java/org/xialing/common/constants/Constant.java:
--------------------------------------------------------------------------------
1 | package org.xialing.common.constants;
2 |
3 | /**
4 | * @author leon
5 | * @version 1.0
6 | * @date 2020/4/28 11:14
7 | */
8 | public class Constant {
9 |
10 | public static final String SUCCESS = "000000";
11 |
12 | public static final String VERIFY_ERROR = "403";
13 |
14 | public static final String FAILURE = "999999";
15 |
16 | public static final String Secure_FAIL = "999999";
17 |
18 | public static final String PARAM_VRFY_FAIL = "000012";
19 |
20 | public static final String NO_AUTH_CODE = "000017";
21 |
22 | public static final String SEPARATE = "|&&|";
23 | }
24 |
--------------------------------------------------------------------------------
/src/main/java/org/xialing/common/dto/R.java:
--------------------------------------------------------------------------------
1 | package org.xialing.common.dto;
2 |
3 | import org.xialing.common.constants.Constant;
4 | import lombok.Data;
5 | import org.xialing.common.dto.base.ResponseBean;
6 |
7 | import java.io.Serializable;
8 |
9 | /**
10 | * 响应对象
11 | *
12 | * @author jack
13 | */
14 | @Data
15 | public class R implements Serializable {
16 |
17 | private static final long serialVersionUID = -3355484205126156607L;
18 |
19 | private boolean result;
20 |
21 | private T data;
22 |
23 | private String code;
24 |
25 | private String msg;
26 |
27 | public R() {
28 |
29 | }
30 |
31 | public R(ResponseBean responseBean) {
32 | this.result = true;
33 | this.code = responseBean.getErrorCode();
34 | this.msg = responseBean.getErrorMessage();
35 | }
36 |
37 | public R(String code, String msg) {
38 | this.result = true;
39 | this.code = code;
40 | this.msg = msg;
41 | }
42 |
43 | public R(T data, String code, String msg) {
44 | this.result = true;
45 | this.data = data;
46 | this.code = code;
47 | this.msg = msg;
48 | }
49 |
50 | public R(boolean result, T data, String code, String msg) {
51 | this.result = result;
52 | this.data = data;
53 | this.code = code;
54 | this.msg = msg;
55 | }
56 |
57 | public R(boolean result, T data) {
58 | this.result = result;
59 | this.data = data;
60 | }
61 |
62 | public R(String msg) {
63 | this.result = true;
64 | this.msg = msg;
65 | }
66 |
67 |
68 | public String getMsg() {
69 | return msg;
70 | }
71 |
72 | public void setMsg(String msg) {
73 | this.msg = msg;
74 | }
75 |
76 | public boolean getResult() {
77 | return result;
78 | }
79 |
80 | public void setResult(boolean result) {
81 | this.result = result;
82 | }
83 |
84 | public T getData() {
85 | return data;
86 | }
87 |
88 | public void setData(T data) {
89 | this.data = data;
90 | }
91 |
92 | public String getCode() {
93 | return code;
94 | }
95 |
96 | public void setCode(String code) {
97 | this.code = code;
98 | }
99 |
100 | public static R error(String code, String msg) {
101 | return new R<>(code, msg);
102 | }
103 |
104 | public static R error(T data, String code, String msg) {
105 | return new R<>(false, data, code, msg);
106 | }
107 | public static R error(String s) {
108 | return new R<>(Constant.FAILURE, s);
109 | }
110 |
111 |
112 |
113 | public static R success(T data, String msg) {
114 | return new R<>(data, Constant.SUCCESS, msg);
115 | }
116 | public static R success(T data) {
117 | return new R<>(data, Constant.SUCCESS, "success");
118 | }
119 |
120 | public static R successSimple(ResponseBean responseBean) {
121 | return new R(responseBean);
122 | }
123 |
124 | public static R error() {
125 | return new R<>(Constant.FAILURE, "未知异常,请联系管理员");
126 | }
127 |
128 | public static R success() {
129 | return new R<>(null, Constant.SUCCESS, "success");
130 | }
131 | }
--------------------------------------------------------------------------------
/src/main/java/org/xialing/common/dto/base/AbsRequestBean.java:
--------------------------------------------------------------------------------
1 | package org.xialing.common.dto.base;
2 |
3 | import java.io.Serializable;
4 | import java.util.Date;
5 |
6 | public abstract class AbsRequestBean implements Serializable {
7 | /**
8 | *
9 | */
10 | private static final long serialVersionUID = -2658930134054157312L;
11 | private String reqId = "";
12 | private String version = "1";
13 | private String saleMerchId;
14 | private Date dateTime = new Date();
15 | private String reserve;
16 |
17 | public AbsRequestBean() {
18 | super();
19 | }
20 |
21 | public AbsRequestBean(String reqId, String version, String saleMerchId, Date dateTime, String reserve) {
22 | super();
23 | this.reqId = reqId;
24 | this.version = version;
25 | this.saleMerchId = saleMerchId;
26 | this.dateTime = dateTime;
27 | this.reserve = reserve;
28 | }
29 |
30 | public String getReqId() {
31 | return reqId;
32 | }
33 |
34 | public void setReqId(String reqId) {
35 | this.reqId = reqId;
36 | }
37 |
38 | public String getVersion() {
39 | return version;
40 | }
41 |
42 | public void setVersion(String version) {
43 | this.version = version;
44 | }
45 |
46 | public String getSaleMerchId() {
47 | return saleMerchId;
48 | }
49 |
50 | public void setSaleMerchId(String saleMerchId) {
51 | this.saleMerchId = saleMerchId;
52 | }
53 |
54 | public Date getDateTime() {
55 | return dateTime;
56 | }
57 |
58 | public void setDateTime(Date dateTime) {
59 | this.dateTime = dateTime;
60 | }
61 |
62 | public String getReserve() {
63 | return reserve;
64 | }
65 |
66 | public void setReserve(String reserve) {
67 | this.reserve = reserve;
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/src/main/java/org/xialing/common/dto/base/AbsResponseBean.java:
--------------------------------------------------------------------------------
1 | package org.xialing.common.dto.base;
2 |
3 | import java.io.Serializable;
4 | import java.util.Date;
5 |
6 | public abstract class AbsResponseBean implements Serializable {
7 |
8 | /**
9 | *
10 | */
11 | private static final long serialVersionUID = -6632899838939719803L;
12 |
13 | private String reqId = "";
14 | private String version = "1";
15 | private String status;
16 | private String errorCode;
17 | private String errorMessage;
18 | private Date dateTime = new Date();
19 | private String reserve;
20 |
21 | public AbsResponseBean() {
22 | super();
23 | }
24 |
25 | public AbsResponseBean(String reqId, String version, String status, String errorCode, String errorMessage,
26 | Date dateTime, String reserve) {
27 | super();
28 | this.reqId = reqId;
29 | this.version = version;
30 | this.status = status;
31 | this.errorCode = errorCode;
32 | this.errorMessage = errorMessage;
33 | this.dateTime = dateTime;
34 | this.reserve = reserve;
35 | }
36 |
37 | public String getReqId() {
38 | return reqId;
39 | }
40 |
41 | public void setReqId(String reqId) {
42 | this.reqId = reqId;
43 | }
44 |
45 | public String getVersion() {
46 | return version;
47 | }
48 |
49 | public void setVersion(String version) {
50 | this.version = version;
51 | }
52 |
53 | public String getStatus() {
54 | return status;
55 | }
56 |
57 | public void setStatus(String status) {
58 | this.status = status;
59 | }
60 |
61 | public String getErrorCode() {
62 | return errorCode;
63 | }
64 |
65 | public void setErrorCode(String errorCode) {
66 | this.errorCode = errorCode;
67 | }
68 |
69 | public String getErrorMessage() {
70 | return errorMessage;
71 | }
72 |
73 | public void setErrorMessage(String errorMessage) {
74 | this.errorMessage = errorMessage;
75 | }
76 |
77 | public Date getDateTime() {
78 | return dateTime;
79 | }
80 |
81 | public void setDateTime(Date dateTime) {
82 | this.dateTime = dateTime;
83 | }
84 |
85 | public String getReserve() {
86 | return reserve;
87 | }
88 |
89 | public void setReserve(String reserve) {
90 | this.reserve = reserve;
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/src/main/java/org/xialing/common/dto/base/RequestBean.java:
--------------------------------------------------------------------------------
1 | package org.xialing.common.dto.base;
2 |
3 | import java.io.Serializable;
4 |
5 | public class RequestBean extends AbsRequestBean implements Serializable {
6 |
7 | /**
8 | *
9 | */
10 | private static final long serialVersionUID = 8719244596842350606L;
11 | private T data;
12 |
13 | public RequestBean() {
14 | super();
15 | }
16 |
17 | public RequestBean(T data) {
18 | super();
19 | this.data = data;
20 | }
21 |
22 | public T getData() {
23 | return data;
24 | }
25 |
26 | public void setData(T data) {
27 | this.data = data;
28 | }
29 |
30 | }
--------------------------------------------------------------------------------
/src/main/java/org/xialing/common/dto/base/ResponseBean.java:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | */
4 | package org.xialing.common.dto.base;
5 |
6 | /**
7 | * @author xiaonian.yang
8 | *
9 | */
10 | public class ResponseBean extends AbsResponseBean implements java.io.Serializable {
11 |
12 | /**
13 | *
14 | */
15 | private static final long serialVersionUID = 1L;
16 |
17 | private boolean result;
18 |
19 | private T data;
20 |
21 |
22 | public ResponseBean() {
23 |
24 | }
25 |
26 | public ResponseBean(String code, String msg) {
27 | this.result = false;
28 | super.setErrorCode(code);
29 | super.setErrorMessage(msg);
30 | }
31 |
32 | public ResponseBean(T data, String code, String msg) {
33 | this.result = true;
34 | this.data = data;
35 | super.setErrorCode(code);
36 | super.setErrorMessage(msg);
37 | }
38 |
39 | public ResponseBean(boolean result, T data, String code, String msg) {
40 | this.result = result;
41 | this.data = data;
42 | super.setErrorCode(code);
43 | super.setErrorMessage(msg);
44 | }
45 |
46 | public ResponseBean(boolean result, T data) {
47 | this.result = result;
48 | this.data = data;
49 | }
50 |
51 | public boolean getResult() {
52 | return result;
53 | }
54 |
55 | public void setResult(boolean result) {
56 | this.result = result;
57 | }
58 |
59 | public T getData() {
60 | return data;
61 | }
62 |
63 | public void setData(T data) {
64 | this.data = data;
65 | }
66 |
67 | public static ResponseBean error(String code, String msg) {
68 | return new ResponseBean(code, msg);
69 | }
70 |
71 | public static ResponseBean error(T data, String code, String msg) {
72 | return new ResponseBean(false, data, code, msg);
73 | }
74 |
75 | public static ResponseBean success(T data, String code, String msg) {
76 | return new ResponseBean(true, data, code, msg);
77 | }
78 |
79 | public static ResponseBean success(String code, String msg) {
80 | return new ResponseBean(true, null, code, msg);
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/src/main/java/org/xialing/common/dto/block/BlockChainChannelDTO.java:
--------------------------------------------------------------------------------
1 | package org.xialing.common.dto.block;
2 |
3 | import lombok.Data;
4 |
5 | import java.util.Date;
6 |
7 |
8 | @Data
9 | public class BlockChainChannelDTO {
10 |
11 | private Long id;
12 |
13 |
14 | private String channelCode;
15 |
16 |
17 | private String channelName;
18 |
19 |
20 | private String channelKey;
21 |
22 |
23 | private String blockChainNetCode;
24 |
25 |
26 | private String channelType;
27 |
28 |
29 | private String state;
30 |
31 |
32 | private String description;
33 |
34 |
35 | private String remark;
36 |
37 |
38 | private String createBy;
39 |
40 |
41 | private Date createTime;
42 |
43 |
44 | private String updateBy;
45 |
46 |
47 | private Date updateTime;
48 |
49 | }
--------------------------------------------------------------------------------
/src/main/java/org/xialing/common/dto/block/BlockChainContractDTO.java:
--------------------------------------------------------------------------------
1 | package org.xialing.common.dto.block;
2 |
3 | import lombok.Data;
4 |
5 | import java.util.Date;
6 |
7 | @Data
8 | public class BlockChainContractDTO {
9 |
10 | private Long id;
11 |
12 | private String contractCode;
13 |
14 | private String contractName;
15 |
16 | private String contractKey;
17 |
18 | private String businessType;
19 |
20 | private String contractType;
21 |
22 | private String version;
23 |
24 | private String state;
25 |
26 | private String description;
27 |
28 | private String remark;
29 |
30 | private String createBy;
31 |
32 | private Date createTime;
33 |
34 | private String updateBy;
35 |
36 | private Date updateTime;
37 |
38 | }
--------------------------------------------------------------------------------
/src/main/java/org/xialing/common/dto/block/BlockChainContractFunDTO.java:
--------------------------------------------------------------------------------
1 | package org.xialing.common.dto.block;
2 |
3 | import lombok.Data;
4 |
5 | import java.util.Date;
6 | import java.util.List;
7 |
8 |
9 | @Data
10 | public class BlockChainContractFunDTO {
11 |
12 | private Long id;
13 |
14 |
15 | private String funCode;
16 |
17 |
18 | private String funName;
19 |
20 |
21 | private String funKey;
22 |
23 |
24 | private String funType;
25 |
26 | private String asyncFlag;
27 |
28 | private String businessCode;
29 |
30 |
31 | private String contractCode;
32 |
33 |
34 | private String state;
35 |
36 |
37 | private String description;
38 |
39 |
40 | private String remark;
41 |
42 |
43 | private String createBy;
44 |
45 |
46 | private Date createTime;
47 |
48 |
49 | private String updateBy;
50 |
51 |
52 | private Date updateTime;
53 |
54 | private String baasRouteCode;
55 |
56 | private List eventDTOList;
57 |
58 | }
--------------------------------------------------------------------------------
/src/main/java/org/xialing/common/dto/block/BlockChainContractFunEventDTO.java:
--------------------------------------------------------------------------------
1 | package org.xialing.common.dto.block;
2 |
3 | import lombok.Data;
4 |
5 | import java.util.Date;
6 |
7 |
8 | @Data
9 | public class BlockChainContractFunEventDTO {
10 |
11 | private Long id;
12 |
13 | private String eventCode;
14 |
15 | private String eventName;
16 |
17 | private String eventKey;
18 |
19 | private String eventType;
20 |
21 | private String funCode;
22 |
23 | private String contractCode;
24 |
25 | private String state;
26 |
27 | private String description;
28 |
29 | private String remark;
30 |
31 | private String createBy;
32 |
33 |
34 | private Date createTime;
35 |
36 | private String updateBy;
37 |
38 | private Date updateTime;
39 |
40 | private static final long serialVersionUID = 1L;
41 | }
--------------------------------------------------------------------------------
/src/main/java/org/xialing/common/dto/block/BlockChainNetDTO.java:
--------------------------------------------------------------------------------
1 | package org.xialing.common.dto.block;
2 |
3 | import lombok.Data;
4 |
5 | import java.util.Date;
6 |
7 |
8 | @Data
9 | public class BlockChainNetDTO {
10 |
11 | private Long id;
12 |
13 |
14 | private String blockChainNetCode;
15 |
16 |
17 | private String blockChainNetName;
18 |
19 |
20 | private String blockChainNetKey;
21 |
22 |
23 | private String blockChainNetType;
24 |
25 |
26 | private String consensusType;
27 |
28 |
29 | private String state;
30 |
31 |
32 | private String description;
33 |
34 |
35 | private String remark;
36 |
37 |
38 | private String createBy;
39 |
40 |
41 | private Date createTime;
42 |
43 |
44 | private String updateBy;
45 |
46 |
47 | private Date updateTime;
48 |
49 |
50 | }
--------------------------------------------------------------------------------
/src/main/java/org/xialing/common/dto/block/BlockChainOrdererDTO.java:
--------------------------------------------------------------------------------
1 | package org.xialing.common.dto.block;
2 |
3 | import lombok.Data;
4 |
5 | import java.util.Date;
6 |
7 |
8 | @Data
9 | public class BlockChainOrdererDTO {
10 |
11 | private Long id;
12 |
13 |
14 | private String ordererCode;
15 |
16 |
17 | private String ordererName;
18 |
19 |
20 | private String ordererKey;
21 |
22 |
23 | private String ordererUrl;
24 |
25 |
26 | private String blockChainNetCode;
27 |
28 |
29 | private String state;
30 |
31 |
32 | private String description;
33 |
34 |
35 | private String remark;
36 |
37 |
38 | private String createBy;
39 |
40 |
41 | private Date createTime;
42 |
43 |
44 | private String updateBy;
45 |
46 |
47 | private Date updateTime;
48 |
49 |
50 | private String ordererCert;
51 |
52 |
53 | }
--------------------------------------------------------------------------------
/src/main/java/org/xialing/common/dto/block/BlockChainOrgCaDTO.java:
--------------------------------------------------------------------------------
1 | package org.xialing.common.dto.block;
2 |
3 | import lombok.Data;
4 |
5 | import java.util.Date;
6 |
7 | @Data
8 | public class BlockChainOrgCaDTO {
9 |
10 | private Long id;
11 |
12 | private String caCode;
13 |
14 | private String caName;
15 |
16 | private String caKey;
17 |
18 | private String caUrl;
19 |
20 | private String adminUserName;
21 |
22 | private String adminUserPwd;
23 |
24 | private String orgCode;
25 |
26 | private String state;
27 |
28 | private String description;
29 |
30 | private String remark;
31 |
32 | private String createBy;
33 |
34 | private Date createTime;
35 |
36 | private String updateBy;
37 |
38 | private Date updateTime;
39 |
40 | private String caCert;
41 |
42 | }
--------------------------------------------------------------------------------
/src/main/java/org/xialing/common/dto/block/BlockChainOrgDTO.java:
--------------------------------------------------------------------------------
1 | package org.xialing.common.dto.block;
2 |
3 | import lombok.Data;
4 |
5 | import java.util.Date;
6 | import java.util.List;
7 |
8 |
9 | @Data
10 | public class BlockChainOrgDTO {
11 |
12 | private Long id;
13 |
14 | private String orgCode;
15 |
16 | private String orgName;
17 |
18 | private String orgKey;
19 |
20 | private String orgPrivateKey;
21 |
22 | private String orgSignedCert;
23 |
24 | private String mspId;
25 |
26 | private String type;
27 |
28 | private String blockChainNetCode;
29 |
30 | private String state;
31 |
32 | private String description;
33 |
34 | private String remark;
35 |
36 | private String createBy;
37 |
38 | private Date createTime;
39 |
40 | private String updateBy;
41 |
42 | private Date updateTime;
43 |
44 | private BlockChainOrgCaDTO blockChainOrgCa;
45 |
46 | private BlockChainOrgUserDTO blockChainOrgUser;
47 |
48 | private List nodeList;
49 |
50 | }
--------------------------------------------------------------------------------
/src/main/java/org/xialing/common/dto/block/BlockChainOrgNodeDTO.java:
--------------------------------------------------------------------------------
1 | package org.xialing.common.dto.block;
2 |
3 | import lombok.Data;
4 |
5 | import java.util.Date;
6 |
7 | @Data
8 | public class BlockChainOrgNodeDTO {
9 |
10 | private Long id;
11 |
12 | private String nodeCode;
13 |
14 | private String nodeName;
15 |
16 | private String nodeKey;
17 |
18 | private String nodeUrl;
19 |
20 | private String nodeType;
21 |
22 | private String orgCode;
23 |
24 | private String state;
25 |
26 | private String description;
27 |
28 | private String remark;
29 |
30 | private String createBy;
31 |
32 | private Date createTime;
33 |
34 | private String updateBy;
35 |
36 | private Date updateTime;
37 |
38 | private String nodeCert;
39 |
40 | private static final long serialVersionUID = 1L;
41 | }
--------------------------------------------------------------------------------
/src/main/java/org/xialing/common/dto/block/BlockChainOrgUserDTO.java:
--------------------------------------------------------------------------------
1 | package org.xialing.common.dto.block;
2 |
3 | import lombok.Data;
4 |
5 | import java.util.Date;
6 |
7 | @Data
8 | public class BlockChainOrgUserDTO {
9 |
10 | private Long id;
11 |
12 |
13 | private String orgUserCode;
14 |
15 |
16 | private String orgUserName;
17 |
18 | private String orgCode;
19 |
20 | private String state;
21 |
22 |
23 | private String description;
24 |
25 |
26 | private String remark;
27 |
28 |
29 | private String createBy;
30 |
31 |
32 | private Date createTime;
33 |
34 |
35 | private String updateBy;
36 |
37 |
38 | private Date updateTime;
39 |
40 |
41 | private String orgUserKey;
42 |
43 | private String orgUserCert;
44 |
45 | }
--------------------------------------------------------------------------------
/src/main/java/org/xialing/common/dto/block/ContractChannelDTO.java:
--------------------------------------------------------------------------------
1 | package org.xialing.common.dto.block;
2 |
3 | import lombok.Data;
4 |
5 | /**
6 | * @author zhangys
7 | * @date 2020/3/18 16:10
8 | */
9 | @Data
10 | public class ContractChannelDTO {
11 |
12 | private String contractCode;
13 |
14 | private String contractName;
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/src/main/java/org/xialing/common/dto/block/NodeChannelDTO.java:
--------------------------------------------------------------------------------
1 | package org.xialing.common.dto.block;
2 |
3 | import lombok.Data;
4 |
5 | import java.util.Date;
6 | import java.util.List;
7 |
8 | @Data
9 | public class NodeChannelDTO {
10 |
11 | private Long id;
12 |
13 | private String nodeCode;
14 |
15 | private String channelCode;
16 |
17 | private String orgCode;
18 |
19 | private String blockChainNetCode;
20 |
21 | private String state;
22 |
23 | private String createBy;
24 |
25 | private Date createTime;
26 |
27 | private String updateBy;
28 |
29 | private Date updateTime;
30 |
31 | private List channelCodes;
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/src/main/java/org/xialing/common/dto/route/BaasRouteDTO.java:
--------------------------------------------------------------------------------
1 | package org.xialing.common.dto.route;
2 |
3 | import lombok.Data;
4 |
5 | import java.io.Serializable;
6 | import java.util.Date;
7 |
8 |
9 | @Data
10 | public class BaasRouteDTO implements Serializable {
11 |
12 | private Long id;
13 |
14 |
15 | private String baasRouteCode;
16 |
17 |
18 | private String baasRouteName;
19 |
20 |
21 | private String baasRouteDesc;
22 |
23 |
24 | private String status;
25 |
26 |
27 | private Long seqNum;
28 |
29 |
30 | private Date createTime;
31 |
32 |
33 | private Date updateTime;
34 |
35 |
36 | private String secretId;
37 |
38 |
39 | private String secretKey;
40 |
41 |
42 | private String endPoint;
43 |
44 |
45 | private String region;
46 |
47 | private String className;
48 |
49 | private static final long serialVersionUID = 1L;
50 | }
--------------------------------------------------------------------------------
/src/main/java/org/xialing/common/dto/route/base/Block.java:
--------------------------------------------------------------------------------
1 | package org.xialing.common.dto.route.base;
2 |
3 | import lombok.Data;
4 |
5 | /**
6 | * @author leon
7 | * @version 1.0
8 | * @date 2019/11/11 11:42
9 | */
10 | @Data
11 | public class Block {
12 | private Long blockNum;
13 | private String dataHash;
14 | private Long blockId;
15 | private String preHash;
16 | private Long txCount;
17 | }
18 |
--------------------------------------------------------------------------------
/src/main/java/org/xialing/common/dto/route/base/Transaction.java:
--------------------------------------------------------------------------------
1 | package org.xialing.common.dto.route.base;
2 |
3 | import lombok.Data;
4 |
5 | /**
6 | * @author leon
7 | * @version 1.0
8 | * @date 2019/11/11 14:09
9 | */
10 | @Data
11 | public class Transaction {
12 | private String transactionId; //交易ID
13 | private String transactionHash; //交易hash
14 | private String createOrgName; //创建交易的组织名
15 | private Long blockId; //交易所在区块号
16 | private String transactionType; //交易类型(普通交易和配置交易)
17 | private String createTime; //交易创建时间
18 | private Long blockHeight; //交易所在区块高度
19 | private String transactionStatus; //交易状态
20 | }
21 |
--------------------------------------------------------------------------------
/src/main/java/org/xialing/common/dto/route/base/request/BaseRequest.java:
--------------------------------------------------------------------------------
1 | package org.xialing.common.dto.route.base.request;
2 |
3 | import org.xialing.common.dto.route.BaasRouteDTO;
4 | import org.xialing.common.dto.block.*;
5 | import lombok.Data;
6 |
7 | import java.util.List;
8 |
9 | /**
10 | * @author leon
11 | * @version 1.0
12 | * @date 2020/3/1 15:59
13 | */
14 | @Data
15 | public class BaseRequest {
16 |
17 | private BaasRouteDTO baasRouteDTO; // BaaS连接相关信息(对应ROUTE_BAAS_ROUTE表)
18 |
19 | private BlockChainNetDTO blockChainNetDTO;
20 |
21 | private BlockChainChannelDTO blockChainChannelDTO;
22 |
23 | private List blockChainOrdererDTOs;
24 |
25 | private BlockChainContractDTO blockChainContractDTO;
26 |
27 | private BlockChainContractFunDTO blockChainContractFunDTO;
28 |
29 | private BlockChainOrgDTO currentBlockChainOrgDTO;
30 |
31 | private BlockChainOrgCaDTO currentBlockChainOrgCaDTO;
32 |
33 | private BlockChainOrgUserDTO currentBlockChainOrgUserDTO;
34 |
35 | private List strategyOrgList;
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/org/xialing/common/dto/route/blockinfo/BlockInfoRequest.java:
--------------------------------------------------------------------------------
1 | package org.xialing.common.dto.route.blockinfo;
2 |
3 | import org.xialing.common.dto.route.base.request.BaseRequest;
4 | import lombok.Data;
5 | import lombok.EqualsAndHashCode;
6 |
7 | /**
8 | * @author leon
9 | * @version 1.0
10 | * @date 2019/11/11 11:25
11 | */
12 | @EqualsAndHashCode(callSuper = true)
13 | @Data
14 | public class BlockInfoRequest extends BaseRequest {
15 |
16 | private String baasRouteCode;
17 |
18 | private Long offset;
19 |
20 | private Long limit;
21 |
22 | private Long latestBlockNumber = 5L;
23 | }
24 |
--------------------------------------------------------------------------------
/src/main/java/org/xialing/common/dto/route/blockinfo/BlockList.java:
--------------------------------------------------------------------------------
1 | package org.xialing.common.dto.route.blockinfo;
2 |
3 | import org.xialing.common.dto.route.base.Block;
4 | import lombok.Data;
5 |
6 | import java.util.List;
7 |
8 | /**
9 | * @author leon
10 | * @version 1.0
11 | * @date 2019/11/11 11:35
12 | */
13 | @Data
14 | public class BlockList {
15 | private Long totalCount;
16 |
17 | private List blockList;
18 |
19 | private String requestId;
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/src/main/java/org/xialing/common/dto/route/blockinfo/BlockSummary.java:
--------------------------------------------------------------------------------
1 | package org.xialing.common.dto.route.blockinfo;
2 |
3 | import lombok.Data;
4 |
5 | /**
6 | * @author leon
7 | * @version 1.0
8 | * @date 2019/11/11 11:35
9 | */
10 | @Data
11 | public class BlockSummary {
12 | private Long totalChannelCount; //网络通道总数量
13 | private Long myChannelCount; //当前组织创建的通道数量
14 | private Long joinChannelCount; //当前组织加入的通道数量
15 | private Long totalPeerCount; //网络节点总数量
16 | private Long myPeerCount; //当前组织创建的节点数量
17 | private Long orderCount; //其他组织创建的节点数量
18 | private Long totalGroupCount; // 网络组织总数量
19 | private Long myGroupCount; //当前组织创建的组织数量
20 | private Long totalChaincodeCount; // 网络智能合约总数量
21 | private Long recentChaincodeCount; //最近7天发起的智能合约数量
22 | private Long myChaincodeCount; //当前组织发起的智能合约数量
23 | private Long totalCertCount; //当前组织的证书总数量
24 | private Long tlsCertCount; //颁发给当前组织的证书数量
25 | private Long peerCertCount; //网络背书节点证书数量
26 | private Long clientCertCount; // 当前组织业务证书数量
27 | private String requestId; //唯一请求 ID,每次请求都会返回。定位问题时需要提供该次请求的 RequestId。
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/src/main/java/org/xialing/common/dto/route/blockinfo/LatesdTransactionList.java:
--------------------------------------------------------------------------------
1 | package org.xialing.common.dto.route.blockinfo;
2 |
3 | import org.xialing.common.dto.route.base.Transaction;
4 | import lombok.Data;
5 |
6 | import java.util.List;
7 |
8 | /**
9 | * @author leon
10 | * @version 1.0
11 | * @date 2019/11/11 11:34
12 | */
13 | @Data
14 | public class LatesdTransactionList {
15 |
16 | private Long totalCount;
17 | private List transactionList;
18 |
19 | private String requestId;
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/src/main/java/org/xialing/common/dto/route/event/BlockEventMsgDTO.java:
--------------------------------------------------------------------------------
1 | package org.xialing.common.dto.route.event;
2 |
3 | import lombok.Data;
4 |
5 | import java.io.Serializable;
6 | import java.util.Date;
7 |
8 | /**
9 | * Table: ROUTE_BLOCK_EVENT_MSG
10 | */
11 | @Data
12 | public class BlockEventMsgDTO implements Serializable {
13 |
14 | private Long id;
15 |
16 |
17 | private String eventMsgCode;
18 |
19 |
20 | private String eventCode;
21 |
22 |
23 | private String eventType;
24 |
25 |
26 | private String eventPayLoad;
27 |
28 | private String status;
29 |
30 |
31 | private String txId;
32 |
33 |
34 | private Long blockNo;
35 |
36 |
37 | private String funCode;
38 |
39 |
40 | private String contractCode;
41 |
42 |
43 | private String channelCode;
44 |
45 |
46 | private String blockChainNetCode;
47 |
48 |
49 | private String leagueCode;
50 |
51 |
52 | private Date createTime;
53 |
54 | private static final long serialVersionUID = 1L;
55 | }
--------------------------------------------------------------------------------
/src/main/java/org/xialing/common/dto/route/event/ContractEvent.java:
--------------------------------------------------------------------------------
1 | package org.xialing.common.dto.route.event;
2 |
3 | import lombok.Data;
4 |
5 |
6 | /**
7 | * @author leon
8 | * @version 1.0
9 | * @date 2020/3/5 10:22
10 | */
11 | @Data
12 | public class ContractEvent {
13 |
14 | private String chainNetCode;
15 |
16 | private String chainNetKey;
17 |
18 | private String channelCode;
19 |
20 | private String channelKey;
21 |
22 | private String contractCode;
23 |
24 | private String contractKey;
25 |
26 | private String funCode;
27 |
28 | private String funKey;
29 |
30 | private String eventCode;
31 |
32 | private String eventKey;
33 |
34 | private String evenType;
35 |
36 | private String leagueCode;
37 |
38 | private String eventPayLoad;
39 |
40 | private String txId;
41 |
42 | private Long blockNo;
43 |
44 |
45 |
46 |
47 |
48 | }
49 |
--------------------------------------------------------------------------------
/src/main/java/org/xialing/common/dto/route/event/ContractEventListenerRequest.java:
--------------------------------------------------------------------------------
1 | package org.xialing.common.dto.route.event;
2 |
3 | import org.xialing.common.dto.route.base.request.BaseRequest;
4 | import org.xialing.common.dto.block.BlockChainContractFunDTO;
5 | import lombok.Data;
6 | import lombok.EqualsAndHashCode;
7 |
8 | import java.util.List;
9 |
10 | /**
11 | * @author leon
12 | * @version 1.0
13 | * @date 2020/3/6 13:42
14 | */
15 | @EqualsAndHashCode(callSuper = true)
16 | @Data
17 | public class ContractEventListenerRequest extends BaseRequest {
18 |
19 |
20 | private String leagueCode;
21 |
22 | private List funList;
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/src/main/java/org/xialing/common/dto/route/invoke/InvokeAsyncQueryRequest.java:
--------------------------------------------------------------------------------
1 | package org.xialing.common.dto.route.invoke;
2 |
3 | import org.xialing.common.dto.route.base.request.BaseRequest;
4 | import lombok.Data;
5 | import lombok.EqualsAndHashCode;
6 |
7 | /**
8 | * @author leon
9 | * @version 1.0
10 | * @date 2019/10/4 23:17
11 | */
12 | @EqualsAndHashCode(callSuper = true)
13 | @Data
14 | public class InvokeAsyncQueryRequest extends BaseRequest {
15 |
16 | private String txId; // BaaS渠道返回单号(Tx_Id)
17 | private String orderNo; // 链订单流水号
18 | private String baasRouteCode; // 区块链渠道号(TBAAS)
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/src/main/java/org/xialing/common/dto/route/invoke/InvokeAsyncQueryResult.java:
--------------------------------------------------------------------------------
1 | package org.xialing.common.dto.route.invoke;
2 |
3 | import lombok.Data;
4 |
5 | /**
6 | * @author leon
7 | * @version 1.0
8 | * @date 2019/10/2 23:02
9 | */
10 | @Data
11 | public class InvokeAsyncQueryResult {
12 |
13 | // private String requestSerialNo;
14 | private String txValidationCode; // 获取交易执行状态码
15 | private String txValidationMsg; // 获取交易执行消息
16 | private Long blockId; // 获取交易所在区块ID
17 | private String requestId; // 获取唯一请求 ID,每次请求都会返回。定位问题时需要提供该次请求的 RequestId。
18 | private String orderNo; // 链订单流水号
19 | private String returnNo; // BaaS渠道返回单号(Tx_Id)
20 | private String status; // 状态:000000.请求处理成功; 000002.请求受理失败;
21 | private String errorMsg; // 获取交易执行消息
22 | private String requestContext; // 链查询请求原文
23 | private String responseContext; // 链查询响应原文
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/src/main/java/org/xialing/common/dto/route/invoke/InvokeRequest.java:
--------------------------------------------------------------------------------
1 | package org.xialing.common.dto.route.invoke;
2 |
3 | import org.xialing.common.dto.route.base.request.BaseRequest;
4 | import lombok.Data;
5 | import lombok.EqualsAndHashCode;
6 |
7 | /**
8 | * @author leon
9 | * @version 1.0
10 | * @date 2019/10/2 22:57
11 | */
12 | @EqualsAndHashCode(callSuper = true)
13 | @Data
14 | public class InvokeRequest extends BaseRequest {
15 |
16 |
17 | private String requestSerialNo; // 请求流水号
18 | private String baasRouteCode; // 区块链渠道号(TBAAS)
19 | private String orderNo; // 链订单流水号
20 | private String[] args; // 合约参数
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/src/main/java/org/xialing/common/dto/route/invoke/InvokeResult.java:
--------------------------------------------------------------------------------
1 | package org.xialing.common.dto.route.invoke;
2 |
3 | import lombok.Data;
4 |
5 | /**
6 | * @author leon
7 | * @version 1.0
8 | * @date 2019/10/2 22:57
9 | */
10 | @Data
11 | public class InvokeResult {
12 |
13 | // private String requestSerialNo;
14 |
15 | /**
16 | * 链订单流水号
17 | */
18 | private String orderNo;
19 |
20 | /**
21 | * 上链操作请求原文
22 | */
23 | private String requestContext;
24 |
25 | /**
26 | * 上链操作响应原文
27 | */
28 | private String responseContext;
29 |
30 | /**
31 | * 获取唯一请求 ID,每次请求都会返回。定位问题时需要提供该次请求的 RequestId。
32 | */
33 | private String requestId;
34 |
35 | /**
36 | * 获取交易ID 同 txId
37 | */
38 | private String returnNo;
39 |
40 | /**
41 | * 获取交易ID 同 returnNo
42 | */
43 | private String txId;
44 |
45 | /**
46 | * 请求状态:000001.请求已受理;000002.请求受理失败
47 | */
48 | private String status;
49 |
50 | /**
51 | * 上链错误信息
52 | */
53 | private String errorMsg;
54 |
55 | private Long blockNo;
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/src/main/java/org/xialing/common/dto/route/query/QueryRequest.java:
--------------------------------------------------------------------------------
1 | package org.xialing.common.dto.route.query;
2 |
3 | import org.xialing.common.dto.route.base.request.BaseRequest;
4 | import lombok.Data;
5 | import lombok.EqualsAndHashCode;
6 |
7 | /**
8 | * @author leon
9 | * @version 1.0
10 | * @date 2019/10/2 22:57
11 | */
12 | @EqualsAndHashCode(callSuper = true)
13 | @Data
14 | public class QueryRequest extends BaseRequest {
15 |
16 | private String requestSerialNo; // 请求流水号
17 | private String baasRouteCode; // 区块链渠道号(TBAAS)
18 | private String orderNo; // 链订单流水号
19 | private String[] args; // 合约参数
20 |
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/src/main/java/org/xialing/common/dto/route/query/QueryResult.java:
--------------------------------------------------------------------------------
1 | package org.xialing.common.dto.route.query;
2 |
3 | import lombok.Data;
4 |
5 | /**
6 | * @author leon
7 | * @version 1.0
8 | * @date 2019/10/2 22:58
9 | */
10 | @Data
11 | public class QueryResult {
12 |
13 | private String requestSerialNo;
14 | private String orderNo;
15 | private String[] data;
16 | private String requestId;
17 | private String status;
18 | private String errorMsg;
19 | private String requestContext;
20 |
21 | private String responseContext;
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/src/main/java/org/xialing/common/enums/AsyncInvokeTypeEnum.java:
--------------------------------------------------------------------------------
1 | package org.xialing.common.enums;
2 |
3 | /**
4 | * @author leon
5 | * @version 1.0
6 | * @date 2019/9/29 11:02
7 | */
8 | public enum AsyncInvokeTypeEnum {
9 |
10 | SYNC("0", "sync"),
11 |
12 | ASYNC("1","async"),
13 |
14 | ;
15 |
16 | private final String code;
17 | private final String description;
18 |
19 | /**
20 | * 私有构造函数
21 | *
22 | * @param code
23 | * @param description
24 | */
25 | AsyncInvokeTypeEnum(String code, String description) {
26 | this.code = code;
27 | this.description = description;
28 | }
29 |
30 | /**
31 | * @return Returns the code.
32 | */
33 | public String getCode() {
34 | return code;
35 | }
36 |
37 | /**
38 | * @return Returns the description.
39 | */
40 | public String getDescription() {
41 | return description;
42 | }
43 |
44 | /**
45 | * 通过枚举code
获得枚举
46 | *
47 | * @param code
48 | * @return
49 | */
50 | public static AsyncInvokeTypeEnum getByCode(String code) {
51 | for (AsyncInvokeTypeEnum status : values()) {
52 | if (status.getCode().equals(code)) {
53 | return status;
54 | }
55 | }
56 | return null;
57 | }
58 |
59 | }
60 |
--------------------------------------------------------------------------------
/src/main/java/org/xialing/common/enums/ResponseCodeEnum.java:
--------------------------------------------------------------------------------
1 | package org.xialing.common.enums;
2 |
3 |
4 | public enum ResponseCodeEnum {
5 | SUCCESS("000000", "请求处理成功"),
6 |
7 | PROCESSING("0000001", "请求已受理"),
8 |
9 | PROCESS_ERROR("000002", "请求受理失败"),
10 |
11 | PROCESS_CANCEL("000003", "请求受理撤销"),
12 |
13 | PROCESS_SUCCESS("000004", "请求受理成功"),
14 |
15 | MSG_PARSING_FAILURE("000005", "报文解析失败"),
16 |
17 | COMPRESS_FAILURE("000006", "报文压缩处理失败"),
18 |
19 | UNCOMPRESS_FAILURE("000007", "报文解压缩处理失败"),
20 |
21 | INVALID_PARAM("000008", "无效的请求参数"),
22 |
23 | VALID_TARGETSYSCODE_FAILURE("000009", "目标系统校验失败"),
24 |
25 | VALID_DATAMSGSIZE_FAILURE("000010", "请求报文内容长度校验失败"),
26 |
27 | UNDEFINED_SERVICE("000011", "请求服务代码未定义"),
28 |
29 | PARAM_VRFY_FAIL("000012", "参数校验未通过"),
30 |
31 | ENCRYP_MACHINE_HANDLE_FAILURE("000013", "加密机处理失败"),
32 |
33 | BUSI_ERROR("000014", "内部服务异常"),
34 |
35 | API_VERSION_ERROR("000015", "调用接口服务版本错误"),
36 |
37 | /**
38 | * token 过期
39 | **/
40 | TOKEN_TIMEOUT_CODE("000016", "token 过期"),
41 | /**
42 | * 禁止访问
43 | **/
44 | NO_AUTH_CODE("000017", "禁止访问"),
45 |
46 | VERIFY_SUCCESS("000018", "校验成功"),
47 |
48 | VERIFY_ERROR("000019", "校验失败"),
49 |
50 | REQUEST_DUPLICATE("000020","请求过于频繁"),
51 |
52 | DB_ERROR("999990", "数据库执行失败"),
53 |
54 | DB_BUSY("999991", "数据库执行忙"),
55 |
56 | REMOTE_CALL_FAILURE("999992", "远程调用失败"),
57 |
58 | UNDEFINED_ERROR("999993", "服务处理失败"),
59 |
60 | FAILURE("999999", "未知失败"),
61 |
62 | LOGIN_FAILURE("10001", "登录失败"),
63 |
64 | LOGOUT_FAILURE("10002", "注销失败"),
65 |
66 | WRONG_VERSION("10003", "请求版本非法"),
67 |
68 | VALIDATE_SIGN_EXCEPTION("10004", "数据验签异常"),
69 |
70 | VALIDATE_SIGN_FAIL("10005", "数据验签失败"),
71 |
72 | PARAM_CHECH_ERROR("10006","参数校验错误"),
73 |
74 | ORDER_STATUS_ERROR("10007","订单状态错误"),
75 |
76 | TRANSACTION_DUPLICATE("10008","请求重复"),
77 |
78 | CHANNEL_INVOKE_ERROR("10009","Baas渠道上链失败"),
79 |
80 | CHAIN_ORDER_NOT_FOUND("10010","链单未找到"),
81 |
82 | TRADE_ORDER_NOT_FOUND("10011","网关订单未找到"),
83 |
84 | ORG_IS_NOT_MATCH("10012","组织机构和合约背书组织不匹配"),
85 |
86 | CHANNEL_INVOKE_QUERY_ERROR("10013","Baas渠道上链结果查询失败"),
87 |
88 | CHANNEL_QUERY_ERROR("10014","Baas渠道上链结果查询失败"),
89 |
90 | REGISTER_EVENT_LISTENER_ERROR("10015","注册事件监听失败"),
91 |
92 | UNREGISTER_EVENT_LISTENER_ERROR("10015","取消事件监听失败"),
93 | ;
94 | private String code;
95 | private String desc;
96 |
97 | ResponseCodeEnum(String code, String desc) {
98 |
99 | this.code = code;
100 | this.desc = desc;
101 | }
102 |
103 | public String getCode() {
104 | return code;
105 | }
106 |
107 | public String getDesc() {
108 | return desc;
109 | }
110 |
111 | public static com.uzigood.core.enums.ResponseCodeEnum getResponseCodeEnum(String value) {
112 | if (value != null) {
113 | for (com.uzigood.core.enums.ResponseCodeEnum nameEnum : values()) {
114 | if (nameEnum.getCode().equals(value)) {
115 | return nameEnum;
116 | }
117 | }
118 | }
119 | return null;
120 | }
121 |
122 | public static boolean isResponseCodeEnum(String value) {
123 | if (value != null) {
124 | for (com.uzigood.core.enums.ResponseCodeEnum nameEnum : values()) {
125 | if (nameEnum.getCode().equals(value)) {
126 | return true;
127 | }
128 | }
129 | }
130 | return false;
131 | }
132 |
133 |
134 | }
135 |
--------------------------------------------------------------------------------
/src/main/java/org/xialing/common/exception/ServiceException.java:
--------------------------------------------------------------------------------
1 | package org.xialing.common.exception;
2 |
3 | import org.xialing.common.enums.ResponseCodeEnum;
4 |
5 | /**
6 | * @author leon
7 | * @version 1.0
8 | * @date 2020/4/28 11:40
9 | */
10 | public class ServiceException extends RuntimeException {
11 | private String code;
12 |
13 | private String desc;
14 |
15 | public ServiceException(String desc) {
16 | this.code = code;
17 | this.desc = desc;
18 | }
19 |
20 | public ServiceException(String code, String desc) {
21 |
22 | this.code = code;
23 | this.desc = desc;
24 | }
25 |
26 | public ServiceException(ResponseCodeEnum respCodeEnum, String desc) {
27 |
28 | this.code = respCodeEnum.getCode();
29 | this.desc = desc;
30 | }
31 |
32 | public ServiceException(ResponseCodeEnum respCodeEnum) {
33 |
34 | this.code = respCodeEnum.getCode();
35 | this.desc = respCodeEnum.getDesc();
36 | }
37 |
38 | public ServiceException(ResponseCodeEnum respCodeEnum, Throwable cause) {
39 |
40 | this.code = respCodeEnum.getCode();
41 | this.desc = respCodeEnum.getDesc();
42 | }
43 |
44 | public ServiceException(ResponseCodeEnum respCodeEnum, String msg, Throwable cause) {
45 |
46 |
47 | this.code = respCodeEnum.getCode();
48 | this.desc = respCodeEnum.getDesc();
49 | }
50 |
51 | @Override
52 | public Throwable fillInStackTrace() {
53 | return this;
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/src/main/java/org/xialing/fabric/config/FabricConfig.java:
--------------------------------------------------------------------------------
1 | package org.xialing.fabric.config;
2 |
3 |
4 |
5 | import java.nio.charset.StandardCharsets;
6 | import java.util.Properties;
7 | import java.util.concurrent.TimeUnit;
8 |
9 | public class FabricConfig {
10 |
11 |
12 | private static void checkInit(String hostname, String certPath) {
13 | if (hostname == null || certPath == null) {
14 | throw new RuntimeException("Please set host name AND cert path");
15 | }
16 | }
17 |
18 | public static Properties getOrderProperties(String hostname, String certPath,String domain) {
19 | checkInit(hostname,certPath);
20 |
21 | Properties ordererProperties = new Properties();
22 |
23 | ordererProperties.put("grpc.NettyChannelBuilderOption.keepAliveTime", new Object[]{5L, TimeUnit.MINUTES});
24 | ordererProperties.put("grpc.NettyChannelBuilderOption.keepAliveTimeout", new Object[]{8L, TimeUnit.SECONDS});
25 | ordererProperties.put("grpc.NettyChannelBuilderOption.keepAliveWithoutCalls", new Object[]{true});
26 |
27 | ordererProperties.put("pemBytes", certPath.getBytes(StandardCharsets.UTF_8));
28 | // ordererProperties.setProperty("pemFile", FileUtils.getResourceFilePath(CERT_PATH));
29 | ordererProperties.setProperty("hostnameOverride", hostname);
30 | ordererProperties.setProperty("sslProvider", "openSSL");
31 | ordererProperties.setProperty("negotiationType", "TLS");
32 |
33 | //配置连接属性
34 | ordererProperties.setProperty("grpc.NettyChannelBuilderOption.userAgent", "/" + domain);
35 |
36 | return ordererProperties;
37 | }
38 |
39 | public static Properties getPeerProperties(String hostname, String certPath,String domain) {
40 | checkInit(hostname,certPath);
41 |
42 | Properties peerProperties = new Properties();
43 | peerProperties.put("pemBytes", certPath.getBytes(StandardCharsets.UTF_8));
44 | // peerProperties.setProperty("pemFile", FileUtils.getResourceFilePath(CERT_PATH));
45 | peerProperties.setProperty("hostnameOverride", hostname);
46 | peerProperties.setProperty("sslProvider", "openSSL");
47 | peerProperties.setProperty("negotiationType", "TLS");
48 |
49 | //配置连接属性
50 | peerProperties.setProperty("grpc.NettyChannelBuilderOption.userAgent", "/" + domain);
51 |
52 | return peerProperties;
53 | }
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/src/main/java/org/xialing/fabric/context/ChannelContext.java:
--------------------------------------------------------------------------------
1 | package org.xialing.fabric.context;
2 |
3 | import org.xialing.fabric.model.ChannelBean;
4 | import org.hyperledger.fabric.sdk.Channel;
5 |
6 | import java.util.HashMap;
7 | import java.util.Map;
8 |
9 | /**
10 | * @author leon
11 | * @version 1.0
12 | * @date 2020/3/6 13:56
13 | */
14 | public class ChannelContext {
15 |
16 | private static Map channelBeanContext = new HashMap<>();
17 |
18 | private static Map chainCodeEventHandlerContext = new HashMap<>();
19 |
20 | public static void addChannelContext(String channelName, ChannelBean channelbean){
21 | channelBeanContext.put(channelName,channelbean);
22 | }
23 |
24 | public static ChannelBean getChannelContext(String channelName){
25 | return channelBeanContext.get(channelName);
26 | }
27 |
28 | public static void removeChannelContext(String channelName){
29 | channelBeanContext.remove(channelName);
30 | }
31 |
32 | public static void clearChannelContext(){
33 | channelBeanContext.clear();}
34 |
35 | public static int sizeForChannelContext(){return channelBeanContext.size();}
36 |
37 |
38 | public static void addChainCodeEventHandlerContext(String channelEventName, String handler){
39 | chainCodeEventHandlerContext.put(channelEventName,handler);
40 | }
41 |
42 | public static String getChainCodeEventHandlerContext(String channelEventName){
43 | return chainCodeEventHandlerContext.get(channelEventName);
44 | }
45 |
46 | public static void removeChainCodeEventHandlerContext(String channelEventName){
47 | chainCodeEventHandlerContext.remove(channelEventName);
48 | }
49 |
50 | public static void clearChainCodeEventHandlerContext(){
51 | chainCodeEventHandlerContext.clear();}
52 |
53 | public static int sizeForChainCodeEventHandlerContext(){return chainCodeEventHandlerContext.size();}
54 |
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/src/main/java/org/xialing/fabric/controller/FabricController.java:
--------------------------------------------------------------------------------
1 | package org.xialing.fabric.controller;
2 |
3 | import org.xialing.common.dto.R;
4 |
5 | import org.xialing.common.dto.route.invoke.InvokeAsyncQueryRequest;
6 | import org.xialing.common.dto.route.invoke.InvokeAsyncQueryResult;
7 | import org.xialing.common.dto.route.invoke.InvokeRequest;
8 | import org.xialing.common.dto.route.invoke.InvokeResult;
9 | import org.xialing.common.dto.route.query.QueryRequest;
10 | import org.xialing.common.dto.route.query.QueryResult;
11 | import org.xialing.common.enums.ResponseCodeEnum;
12 | import org.xialing.fabric.service.FabricService;
13 | import lombok.extern.slf4j.Slf4j;
14 | import org.springframework.web.bind.annotation.PostMapping;
15 | import org.springframework.web.bind.annotation.RequestBody;
16 | import org.springframework.web.bind.annotation.RequestMapping;
17 | import org.springframework.web.bind.annotation.RestController;
18 |
19 | import javax.annotation.Resource;
20 |
21 | /**
22 | * @author leon
23 | * @version 1.0
24 | * @date 2019/10/8 23:07
25 | */
26 | @RestController
27 | @Slf4j
28 | @RequestMapping("fabric")
29 | public class FabricController{
30 |
31 | @Resource
32 | private FabricService fabricService;
33 |
34 | @PostMapping("route/invoke")
35 | public R invoke(@RequestBody InvokeRequest invokeRequest){
36 | try {
37 | return R.success(fabricService.invoke(invokeRequest));
38 | } catch (Exception e) {
39 | log.error(e.getMessage());
40 | return R.error(ResponseCodeEnum.BUSI_ERROR.getCode(),e.getMessage());
41 | }
42 | }
43 |
44 | @PostMapping("route/invoke/asyncQ")
45 | public R invokeAsyncQuery(@RequestBody InvokeAsyncQueryRequest invokeAsyncQueryRequest){
46 | try {
47 | return R.success(fabricService.asyncQueryResult(invokeAsyncQueryRequest));
48 | } catch (Exception e) {
49 | log.error(e.getMessage());
50 | return R.error(ResponseCodeEnum.BUSI_ERROR.getCode(),e.getMessage());
51 | }
52 | }
53 |
54 | @PostMapping("route/query")
55 | public R query(@RequestBody QueryRequest queryRequest){
56 | try {
57 | return R.success(fabricService.query(queryRequest));
58 | } catch (Exception e) {
59 | log.error(e.getMessage());
60 | return R.error(ResponseCodeEnum.BUSI_ERROR.getCode(),e.getMessage());
61 | }
62 | }
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/src/main/java/org/xialing/fabric/controller/FabricEventController.java:
--------------------------------------------------------------------------------
1 | package org.xialing.fabric.controller;
2 |
3 | import org.xialing.common.dto.R;
4 | import org.xialing.common.dto.route.event.ContractEventListenerRequest;
5 | import org.xialing.common.enums.ResponseCodeEnum;
6 | import org.xialing.fabric.service.FabricEventService;
7 | import lombok.extern.slf4j.Slf4j;
8 | import org.springframework.web.bind.annotation.*;
9 |
10 | import javax.annotation.Resource;
11 |
12 | /**
13 | * @author leon
14 | * @version 1.0
15 | * @date 2020/3/5 16:33
16 | */
17 | @RestController
18 | @Slf4j
19 | @RequestMapping("fabric-event")
20 | public class FabricEventController {
21 |
22 | @Resource
23 | private FabricEventService fabricEventService;
24 |
25 | @GetMapping("register-contract-listener")
26 | public R registerContractListener(@RequestBody ContractEventListenerRequest contractEventListenerRequest){
27 | try {
28 | fabricEventService.registerContractListener(contractEventListenerRequest);
29 | return R.success();
30 | }catch (Exception e){
31 | log.error(e.getMessage());
32 | return R.error(ResponseCodeEnum.BUSI_ERROR.getCode(),e.getMessage());
33 | }
34 | }
35 |
36 | @GetMapping("unRegister-contract-listener")
37 | public R unRegisterContractListener(@RequestBody ContractEventListenerRequest contractEventListenerRequest){
38 | try {
39 | fabricEventService.unRegisterContractListener(contractEventListenerRequest);
40 | return R.success();
41 | }catch (Exception e){
42 | log.error(e.getMessage());
43 | return R.error(ResponseCodeEnum.BUSI_ERROR.getCode(),e.getMessage());
44 | }
45 | }
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/src/main/java/org/xialing/fabric/controller/FabricInfoController.java:
--------------------------------------------------------------------------------
1 | package org.xialing.fabric.controller;
2 |
3 | import lombok.extern.slf4j.Slf4j;
4 | import org.springframework.web.bind.annotation.RequestMapping;
5 | import org.springframework.web.bind.annotation.RestController;
6 |
7 | /**
8 | * @author leon
9 | * @version 1.0
10 | * @date 2020/3/2 17:27
11 | */
12 | @RestController
13 | @Slf4j
14 | @RequestMapping("fabric-info")
15 | public class FabricInfoController {
16 | }
17 |
--------------------------------------------------------------------------------
/src/main/java/org/xialing/fabric/listener/FabricEventListener.java:
--------------------------------------------------------------------------------
1 | package org.xialing.fabric.listener;
2 |
3 |
4 | import cn.hutool.json.JSONUtil;
5 | import org.xialing.common.dto.route.event.ContractEvent;
6 | import org.xialing.fabric.model.EventPayLoad;
7 | import lombok.extern.slf4j.Slf4j;
8 | import org.hyperledger.fabric.sdk.*;
9 | import org.hyperledger.fabric.sdk.exception.InvalidArgumentException;
10 | import org.xialing.fabric.remote.RemoteBlockEventService;
11 | import org.xialing.fabric.utils.ThreadPoolManager;
12 |
13 | import java.util.regex.*;
14 |
15 | /**
16 | * @author leon
17 | * @version 1.0
18 | * @date 2020/3/5 10:15
19 | */
20 | @Slf4j
21 | public class FabricEventListener {
22 |
23 | public static String setChainCodeEventListener(Channel channel,
24 | ContractEvent contractEvent,
25 | RemoteBlockEventService remoteBlockEventService)
26 | throws InvalidArgumentException {
27 |
28 | ChaincodeEventListener chaincodeEventListener = (handle, blockEvent, chaincodeEvent) -> {
29 |
30 |
31 | log.info("RECEIVED CHAINCODE EVENT with handle: " +
32 | handle +
33 | ", chaincodeId: " + chaincodeEvent.getChaincodeId() +
34 | ", chaincode event name: " + chaincodeEvent.getEventName() +
35 | ", transactionId: " + chaincodeEvent.getTxId() +
36 | ", event Payload: " + new String(chaincodeEvent.getPayload()));
37 | //解析PayLoad 对比 是否 同一联盟信息
38 | EventPayLoad eventPayLoad = JSONUtil.toBean(new String(chaincodeEvent.getPayload()),EventPayLoad.class);
39 | if(contractEvent.getLeagueCode().equals(eventPayLoad.getLeagueCode())) {
40 | contractEvent.setEventPayLoad(new String(chaincodeEvent.getPayload()));
41 | contractEvent.setBlockNo(blockEvent.getBlockNumber());
42 | contractEvent.setTxId(chaincodeEvent.getTxId());
43 | //调用接口返回事件信息
44 | ThreadPoolManager.newInstance().addExecuteTask(() -> remoteBlockEventService.recordBlockEvent(contractEvent));
45 | }
46 |
47 | };
48 | // chaincode events.
49 | String chaincodeEventHandler = channel.registerChaincodeEventListener(Pattern.compile(".*"),
50 | Pattern.compile(Pattern.quote(contractEvent.getEventKey())), chaincodeEventListener);
51 | return chaincodeEventHandler;
52 | }
53 |
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/src/main/java/org/xialing/fabric/model/ChannelBean.java:
--------------------------------------------------------------------------------
1 | package org.xialing.fabric.model;
2 |
3 | import lombok.Builder;
4 | import lombok.Data;
5 | import lombok.Synchronized;
6 | import org.hyperledger.fabric.sdk.Channel;
7 |
8 | /**
9 | * @author leon
10 | * @version 1.0
11 | * @date 2020/3/8 23:29
12 | */
13 | @Data
14 | public class ChannelBean {
15 |
16 | private Channel channel;
17 |
18 | private int contractEventCount = 0;
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/src/main/java/org/xialing/fabric/model/EventPayLoad.java:
--------------------------------------------------------------------------------
1 | package org.xialing.fabric.model;
2 |
3 | import lombok.Data;
4 |
5 | /**
6 | * @author leon
7 | * @version 1.0
8 | * @date 2020/3/9 16:59
9 | */
10 | @Data
11 | public class EventPayLoad {
12 |
13 | private String leagueCode;
14 | }
15 |
--------------------------------------------------------------------------------
/src/main/java/org/xialing/fabric/model/FabricEnrollment.java:
--------------------------------------------------------------------------------
1 | package org.xialing.fabric.model;
2 |
3 |
4 | import org.xialing.fabric.utils.CryptoUtils;
5 | import org.hyperledger.fabric.sdk.Enrollment;
6 |
7 | import java.io.IOException;
8 | import java.nio.charset.StandardCharsets;
9 | import java.security.NoSuchAlgorithmException;
10 | import java.security.NoSuchProviderException;
11 | import java.security.PrivateKey;
12 | import java.security.spec.InvalidKeySpecException;
13 |
14 | public class FabricEnrollment implements Enrollment {
15 |
16 | private String keyFilePath;
17 | private String certFilePath;
18 |
19 | private PrivateKey privateKey;
20 | private String cert;
21 |
22 | public FabricEnrollment(String keyFilePath, String certFilePath) {
23 | this.keyFilePath = keyFilePath;
24 | this.certFilePath = certFilePath;
25 | }
26 | @Override
27 | public PrivateKey getKey() {
28 | try {
29 | if (privateKey == null) {
30 | // privateKey = CryptoUtils.getPrivateKeyFromBytes(FileUtils.getFileBytes(FileUtils.getResourceFilePath(keyFilePath)));
31 | privateKey = CryptoUtils.getPrivateKeyFromBytes(keyFilePath.getBytes(StandardCharsets.UTF_8));
32 | }
33 | return privateKey;
34 | } catch (IOException e) {
35 | e.printStackTrace();
36 | } catch (NoSuchProviderException e) {
37 | e.printStackTrace();
38 | } catch (NoSuchAlgorithmException e) {
39 | e.printStackTrace();
40 | } catch (InvalidKeySpecException e) {
41 | e.printStackTrace();
42 | }
43 | return null;
44 | }
45 | @Override
46 | public String getCert() {
47 | if (cert == null) {
48 | cert = certFilePath;
49 | }
50 | return cert;
51 | }
52 |
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/src/main/java/org/xialing/fabric/model/FabricUser.java:
--------------------------------------------------------------------------------
1 | package org.xialing.fabric.model;
2 |
3 | import org.hyperledger.fabric.sdk.Enrollment;
4 | import org.hyperledger.fabric.sdk.User;
5 |
6 | import java.util.Set;
7 |
8 | public class FabricUser implements User {
9 |
10 | private String name;
11 | private Set roles;
12 | private String account;
13 | private String affiliation;
14 | private Enrollment enrollment;
15 | private String mspId;
16 |
17 | public FabricUser(String name, Enrollment enrollment, String mspId) {
18 | this.name = name;
19 | this.enrollment = enrollment;
20 | this.mspId = mspId;
21 | }
22 |
23 | public void setRoles(Set roles) {
24 | this.roles = roles;
25 | }
26 |
27 | public void setAccount(String account) {
28 | this.account = account;
29 | }
30 |
31 | public void setAffiliation(String affiliation) {
32 | this.affiliation = affiliation;
33 | }
34 |
35 | @Override
36 | public String getName() {
37 | return name;
38 | }
39 | @Override
40 | public Set getRoles() {
41 | return roles;
42 | }
43 | @Override
44 | public String getAccount() {
45 | return account;
46 | }
47 | @Override
48 | public String getAffiliation() {
49 | return affiliation;
50 | }
51 | @Override
52 | public Enrollment getEnrollment() {
53 | return enrollment;
54 | }
55 | @Override
56 | public String getMspId() {
57 | return mspId;
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/src/main/java/org/xialing/fabric/remote/RemoteBlockEventService.java:
--------------------------------------------------------------------------------
1 | package org.xialing.fabric.remote;
2 |
3 | import org.springframework.stereotype.Service;
4 | import org.xialing.common.dto.route.event.ContractEvent;
5 |
6 | /**
7 | * @author leon
8 | * @version 1.0
9 | * @date 2020/4/28 11:25
10 | */
11 | @Service
12 | public class RemoteBlockEventService {
13 | public void recordBlockEvent(ContractEvent contractEvent) {
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/src/main/java/org/xialing/fabric/service/CommonService.java:
--------------------------------------------------------------------------------
1 | package org.xialing.fabric.service;
2 |
3 |
4 | import org.xialing.common.dto.route.base.request.BaseRequest;
5 | import org.xialing.common.enums.ResponseCodeEnum;
6 | import org.xialing.common.exception.ServiceException;
7 | import org.xialing.fabric.utils.FabricUtils;
8 | import org.hyperledger.fabric.sdk.Channel;
9 | import org.hyperledger.fabric.sdk.HFClient;
10 |
11 | /**
12 | * @author leon
13 | * @version 1.0
14 | * @date 2020/3/6 14:42
15 | */
16 | public class CommonService {
17 |
18 |
19 | public Channel initChannel(HFClient client, BaseRequest baseRequest){
20 | Channel currentChannel;
21 | try {
22 | currentChannel = FabricUtils.initChannel(client,baseRequest.getCurrentBlockChainOrgUserDTO(),baseRequest.getCurrentBlockChainOrgDTO(),
23 | baseRequest.getBlockChainChannelDTO(),baseRequest.getBaasRouteDTO(),baseRequest.getBlockChainOrdererDTOs());
24 | } catch (Exception e) {
25 | e.printStackTrace();
26 | throw new ServiceException(ResponseCodeEnum.CHANNEL_INVOKE_ERROR,"初始化区块链配置失败");
27 | }
28 | return currentChannel;
29 | }
30 |
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/src/main/java/org/xialing/fabric/service/FabricEventService.java:
--------------------------------------------------------------------------------
1 | package org.xialing.fabric.service;
2 |
3 |
4 | import org.xialing.common.dto.block.BlockChainContractFunDTO;
5 | import org.xialing.common.dto.block.BlockChainContractFunEventDTO;
6 | import org.xialing.common.dto.route.event.ContractEvent;
7 | import org.xialing.common.dto.route.event.ContractEventListenerRequest;
8 | import org.xialing.fabric.context.ChannelContext;
9 | import org.xialing.fabric.listener.FabricEventListener;
10 | import org.xialing.fabric.model.ChannelBean;
11 | import org.hyperledger.fabric.sdk.Channel;
12 | import org.hyperledger.fabric.sdk.HFClient;
13 | import org.hyperledger.fabric.sdk.exception.InvalidArgumentException;
14 | import org.springframework.stereotype.Service;
15 | import org.xialing.fabric.remote.RemoteBlockEventService;
16 |
17 | import javax.annotation.Resource;
18 |
19 | /**
20 | * @author leon
21 | * @version 1.0
22 | * @date 2020/3/6 14:41
23 | */
24 | @Service
25 | public class FabricEventService extends CommonService {
26 |
27 | @Resource
28 | private RemoteBlockEventService remoteBlockEventService;
29 |
30 | public void registerContractListener(ContractEventListenerRequest contractEventListenerRequest) throws InvalidArgumentException {
31 |
32 | String channelName = contractEventListenerRequest.getBlockChainNetDTO().getBlockChainNetCode() +
33 | contractEventListenerRequest.getBlockChainChannelDTO().getChannelCode() +
34 | contractEventListenerRequest.getLeagueCode();
35 |
36 |
37 | ChannelBean channelBean = ChannelContext.getChannelContext(channelName);
38 | if(channelBean == null){
39 | HFClient client = HFClient.createNewInstance();
40 | Channel currentChannel = super.initChannel(client, contractEventListenerRequest);
41 | channelBean = new ChannelBean();
42 | channelBean.setChannel(currentChannel);
43 | ChannelContext.addChannelContext(channelName,channelBean);
44 | }
45 |
46 | for(BlockChainContractFunDTO funDTO : contractEventListenerRequest.getFunList()){
47 | for(BlockChainContractFunEventDTO eventDTO : funDTO.getEventDTOList()){
48 |
49 | ContractEvent contractEvent = new ContractEvent();
50 | contractEvent.setChainNetCode(contractEventListenerRequest.getBlockChainNetDTO().getBlockChainNetCode());
51 | contractEvent.setChainNetKey(contractEventListenerRequest.getBlockChainNetDTO().getBlockChainNetKey());
52 | contractEvent.setChannelCode(contractEventListenerRequest.getBlockChainChannelDTO().getChannelCode());
53 | contractEvent.setChannelKey(contractEventListenerRequest.getBlockChainChannelDTO().getChannelKey());
54 | contractEvent.setContractCode(contractEventListenerRequest.getBlockChainContractDTO().getContractCode());
55 | contractEvent.setContractKey(contractEventListenerRequest.getBlockChainContractDTO().getContractKey());
56 | contractEvent.setFunCode(funDTO.getFunCode());
57 | contractEvent.setFunKey(funDTO.getFunKey());
58 | contractEvent.setEventCode(eventDTO.getEventCode());
59 | contractEvent.setEventKey(eventDTO.getEventKey());
60 | contractEvent.setEvenType(eventDTO.getEventType());
61 | contractEvent.setLeagueCode(contractEventListenerRequest.getLeagueCode());
62 |
63 | String eventListenerHandle = FabricEventListener.setChainCodeEventListener
64 | (channelBean.getChannel(), contractEvent,remoteBlockEventService);
65 |
66 | String channelContractName = contractEventListenerRequest.getBlockChainNetDTO().getBlockChainNetCode() +
67 | contractEventListenerRequest.getBlockChainChannelDTO().getChannelCode() +
68 | contractEventListenerRequest.getLeagueCode() +
69 | contractEventListenerRequest.getBlockChainContractDTO().getContractCode() +
70 | funDTO.getFunCode() +
71 | eventDTO.getEventCode();
72 |
73 | ChannelContext.addChainCodeEventHandlerContext
74 | (channelContractName,eventListenerHandle);
75 |
76 | }
77 | channelBean.setContractEventCount(channelBean.getContractEventCount() + 1);
78 | }
79 |
80 |
81 |
82 | }
83 |
84 | public void unRegisterContractListener(ContractEventListenerRequest contractEventListenerRequest) throws InvalidArgumentException {
85 |
86 | String channelName = contractEventListenerRequest.getBlockChainNetDTO().getBlockChainNetCode() +
87 | contractEventListenerRequest.getBlockChainChannelDTO().getChannelCode() +
88 | contractEventListenerRequest.getLeagueCode();
89 |
90 | ChannelBean channelBean = ChannelContext.getChannelContext(channelName);
91 | if(channelBean == null){
92 | HFClient client = HFClient.createNewInstance();
93 | Channel currentChannel = super.initChannel(client, contractEventListenerRequest);
94 | channelBean = new ChannelBean();
95 | channelBean.setChannel(currentChannel);
96 | ChannelContext.addChannelContext(channelName,channelBean);
97 | }
98 |
99 | for(BlockChainContractFunDTO funDTO : contractEventListenerRequest.getFunList()) {
100 | for (BlockChainContractFunEventDTO eventDTO : funDTO.getEventDTOList()) {
101 |
102 | String channelContractName = contractEventListenerRequest.getBlockChainNetDTO().getBlockChainNetCode() +
103 | contractEventListenerRequest.getBlockChainChannelDTO().getChannelCode() +
104 | contractEventListenerRequest.getLeagueCode() +
105 | contractEventListenerRequest.getBlockChainContractDTO().getContractCode() +
106 | funDTO.getFunCode() +
107 | eventDTO.getEventCode();
108 |
109 | String eventListenerHandle = ChannelContext.getChainCodeEventHandlerContext
110 | (channelContractName);
111 |
112 | channelBean.getChannel().unregisterBlockListener(eventListenerHandle);
113 | ChannelContext.removeChainCodeEventHandlerContext(channelContractName);
114 |
115 | }
116 | channelBean.setContractEventCount(channelBean.getContractEventCount() - 1);
117 | if (channelBean.getContractEventCount() == 0) {
118 | ChannelContext.removeChannelContext(channelName);
119 | }
120 | }
121 | }
122 | }
123 |
--------------------------------------------------------------------------------
/src/main/java/org/xialing/fabric/service/FabricInfoService.java:
--------------------------------------------------------------------------------
1 | package org.xialing.fabric.service;
2 |
3 | import org.springframework.stereotype.Service;
4 |
5 | /**
6 | * @author leon
7 | * @version 1.0
8 | * @date 2020/3/5 14:42
9 | */
10 | @Service
11 | public class FabricInfoService {
12 |
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/src/main/java/org/xialing/fabric/service/FabricService.java:
--------------------------------------------------------------------------------
1 | package org.xialing.fabric.service;
2 |
3 |
4 | import cn.hutool.core.util.IdUtil;
5 | import cn.hutool.json.JSONUtil;
6 | import org.xialing.common.dto.route.invoke.InvokeAsyncQueryRequest;
7 | import org.xialing.common.dto.route.invoke.InvokeAsyncQueryResult;
8 | import org.xialing.common.dto.route.invoke.InvokeRequest;
9 | import org.xialing.common.dto.route.invoke.InvokeResult;
10 | import org.xialing.common.dto.route.query.QueryRequest;
11 | import org.xialing.common.dto.route.query.QueryResult;
12 | import org.xialing.common.enums.AsyncInvokeTypeEnum;
13 | import org.xialing.common.enums.ResponseCodeEnum;
14 | import org.xialing.fabric.template.FabricTemplate;
15 | import org.xialing.fabric.utils.FabricUtils;
16 | import lombok.extern.slf4j.Slf4j;
17 | import org.hyperledger.fabric.sdk.ChaincodeID;
18 | import org.hyperledger.fabric.sdk.Channel;
19 | import org.hyperledger.fabric.sdk.HFClient;
20 | import org.springframework.stereotype.Service;
21 |
22 | import javax.annotation.PostConstruct;
23 | import java.util.List;
24 |
25 | /**
26 | * @author leon
27 | * @version 1.0
28 | * @date 2020/2/27 14:10
29 | */
30 | @Service
31 | @Slf4j
32 | public class FabricService extends CommonService{
33 |
34 |
35 | public InvokeResult invoke(InvokeRequest invokeRequest) {
36 | HFClient client = HFClient.createNewInstance();
37 | InvokeResult invokeResult = null;
38 | try {
39 | Channel currentChannel = super.initChannel(client, invokeRequest);
40 |
41 | FabricTemplate fabricTemplate = new FabricTemplate();
42 | FabricTemplate.setClient(client);
43 |
44 | List peers = FabricUtils.converPeerNodeKey(invokeRequest.getStrategyOrgList());
45 |
46 | ChaincodeID chainCodeId = ChaincodeID.newBuilder()
47 | .setName(invokeRequest.getBlockChainContractDTO().getContractKey())
48 | .setVersion(invokeRequest.getBlockChainContractDTO().getVersion())
49 | .setPath("").build();
50 | invokeResult = fabricTemplate.transaction
51 | (currentChannel, invokeRequest.getBlockChainContractFunDTO().getFunKey(),
52 | invokeRequest.getArgs(),
53 | chainCodeId,
54 | peers, invokeRequest.getBlockChainContractFunDTO().getAsyncFlag());
55 | invokeResult.setOrderNo(invokeRequest.getOrderNo());
56 | invokeResult.setRequestId(IdUtil.fastUUID());
57 | invokeResult.setRequestContext(JSONUtil.toJsonStr(invokeRequest));
58 | invokeResult.setReturnNo(invokeResult.getTxId());
59 | if (AsyncInvokeTypeEnum.ASYNC.getCode().equals(invokeRequest.getBlockChainContractFunDTO().getAsyncFlag())) {
60 | invokeResult.setStatus(ResponseCodeEnum.PROCESSING.getCode());
61 | } else {
62 | invokeResult.setStatus(ResponseCodeEnum.SUCCESS.getCode());
63 | }
64 | invokeResult.setResponseContext(JSONUtil.toJsonStr(invokeResult));
65 | }catch (Exception e){
66 | log.error("Fabric SDK invoke 出错: " + e.getMessage());
67 | e.printStackTrace();
68 | invokeResult = new InvokeResult();
69 | invokeResult.setOrderNo(invokeRequest.getOrderNo());
70 | invokeResult.setRequestId(IdUtil.fastUUID());
71 | invokeResult.setRequestContext(JSONUtil.toJsonStr(invokeRequest));
72 | invokeResult.setStatus(ResponseCodeEnum.PROCESS_ERROR.getCode());
73 | invokeResult.setErrorMsg(e.getMessage());
74 | }
75 | return invokeResult;
76 | }
77 |
78 | public QueryResult query(QueryRequest queryRequest) {
79 | HFClient client = HFClient.createNewInstance();
80 | QueryResult queryResult = null;
81 | try {
82 | Channel currentChannel = super.initChannel(client, queryRequest);
83 |
84 | FabricTemplate fabricTemplate = new FabricTemplate();
85 | FabricTemplate.setClient(client);
86 | List peers = FabricUtils.converPeerNodeKey(queryRequest.getStrategyOrgList());
87 |
88 | ChaincodeID chainCodeId = ChaincodeID.newBuilder()
89 | .setName(queryRequest.getBlockChainContractDTO().getContractKey())
90 | .setVersion(queryRequest.getBlockChainContractDTO().getVersion())
91 | .setPath("").build();
92 | queryResult = fabricTemplate.query(currentChannel, queryRequest.getBlockChainContractFunDTO().getFunKey(),
93 | queryRequest.getArgs(),
94 | chainCodeId, peers);
95 | queryResult.setOrderNo(queryRequest.getOrderNo());
96 | queryResult.setRequestId(IdUtil.fastUUID());
97 | queryResult.setRequestContext(JSONUtil.toJsonStr(queryRequest));
98 |
99 | queryResult.setStatus(ResponseCodeEnum.SUCCESS.getCode());
100 | queryResult.setResponseContext(JSONUtil.toJsonStr(queryResult));
101 |
102 | }catch(Exception e){
103 | log.error("Fabric SDK query 出错: " + e.getMessage());
104 | e.printStackTrace();
105 | queryResult = new QueryResult();
106 | queryResult.setOrderNo(queryRequest.getOrderNo());
107 | queryResult.setRequestId(IdUtil.fastUUID());
108 | queryResult.setRequestContext(JSONUtil.toJsonStr(queryRequest));
109 | queryResult.setStatus(ResponseCodeEnum.PROCESS_ERROR.getCode());
110 | queryResult.setErrorMsg(e.getMessage());
111 | }
112 | return queryResult;
113 | }
114 |
115 | public InvokeAsyncQueryResult asyncQueryResult(InvokeAsyncQueryRequest invokeAsyncQueryRequest) {
116 | HFClient client = HFClient.createNewInstance();
117 | Channel currentChannel = super.initChannel(client, invokeAsyncQueryRequest);
118 |
119 | FabricTemplate fabricTemplate = new FabricTemplate();
120 | FabricTemplate.setClient(client);
121 |
122 | InvokeAsyncQueryResult result = fabricTemplate.asyncQueryResult(currentChannel,invokeAsyncQueryRequest.getTxId());
123 |
124 | result.setOrderNo(invokeAsyncQueryRequest.getOrderNo());
125 | result.setRequestContext(JSONUtil.toJsonStr(invokeAsyncQueryRequest));
126 | result.setReturnNo(invokeAsyncQueryRequest.getTxId());
127 | result.setResponseContext(JSONUtil.toJsonStr(result));
128 | return result;
129 | }
130 |
131 |
132 |
133 |
134 | }
135 |
--------------------------------------------------------------------------------
/src/main/java/org/xialing/fabric/template/FabricTemplate.java:
--------------------------------------------------------------------------------
1 | package org.xialing.fabric.template;
2 |
3 | import com.google.protobuf.ByteString;
4 | import com.google.protobuf.InvalidProtocolBufferException;
5 | import lombok.extern.slf4j.Slf4j;
6 | import org.hyperledger.fabric.sdk.*;
7 | import org.hyperledger.fabric.sdk.exception.InvalidArgumentException;
8 | import org.hyperledger.fabric.sdk.exception.ProposalException;
9 | import org.xialing.common.dto.route.invoke.InvokeAsyncQueryResult;
10 | import org.xialing.common.dto.route.invoke.InvokeResult;
11 | import org.xialing.common.dto.route.query.QueryResult;
12 | import org.xialing.common.enums.AsyncInvokeTypeEnum;
13 | import org.xialing.common.enums.ResponseCodeEnum;
14 | import org.xialing.fabric.utils.ThreadPoolManager;
15 |
16 | import java.util.*;
17 | import java.util.concurrent.CompletableFuture;
18 | import java.util.regex.Pattern;
19 |
20 | /**
21 | * @author leon
22 | * @version 1.0
23 | * @date 2020/2/27 14:42
24 | */
25 | @Slf4j
26 | public class FabricTemplate {
27 |
28 |
29 | private static HFClient client = null;
30 |
31 | public static void setClient(HFClient client) {
32 | FabricTemplate.client = client;
33 | }
34 |
35 | private void checkClient() {
36 | if (client == null) {
37 | throw new RuntimeException("Please set template fabric client");
38 | }
39 | }
40 |
41 | public QueryResult query(Channel chain, String function, String[] args, ChaincodeID chainCodeId, List peerList) {
42 | return query(chain, function, args, chainCodeId, peerList, 1);
43 | }
44 |
45 | public QueryResult query(Channel chain, String function, String[] args, ChaincodeID chainCodeId,
46 | List peerList, int policy) {
47 | checkClient();
48 | String result = null;
49 | int verify = 0;
50 | List endorserList = new ArrayList();
51 |
52 | chain.getPeers().forEach(peer -> {
53 | if (peerList.contains(peer.getName())) {
54 | endorserList.add(peer);
55 | }
56 | });
57 |
58 | try {
59 | QueryByChaincodeRequest queryByChaincodeRequest = client.newQueryProposalRequest();
60 | queryByChaincodeRequest.setArgs(args);
61 | queryByChaincodeRequest.setFcn(function);
62 | queryByChaincodeRequest.setChaincodeID(chainCodeId);
63 |
64 | Collection queryProposals = chain.queryByChaincode(queryByChaincodeRequest, endorserList);
65 | List resultData = new ArrayList<>();
66 | for (ProposalResponse proposalResponse : queryProposals) {
67 | if (!proposalResponse.isVerified() || proposalResponse.getStatus() != ProposalResponse.Status.SUCCESS) {
68 | log.error("Failed query proposal from peer {} status: {} . Messages: {} . Was verified : {}",
69 | proposalResponse.getPeer().getName(), proposalResponse.getStatus(),
70 | proposalResponse.getMessage(), proposalResponse.isVerified());
71 | } else {
72 | verify++;
73 | String payload = proposalResponse.getProposalResponse().getResponse().getPayload().toStringUtf8();
74 | if (result == null) {
75 | result = payload;
76 | }
77 | else if (!result.equals(payload)) {
78 | throw new RuntimeException("检测到节点数据不匹配!请检查智能合约是否同步或是否存在恶意节点!");
79 | }
80 | resultData.add(payload);
81 | }
82 | }
83 |
84 | if (verify < policy) {
85 | throw new RuntimeException("请求不满足背书策略");
86 | }
87 | QueryResult queryResult = new QueryResult();
88 | queryResult.setData((String[]) resultData.toArray());
89 | return queryResult;
90 | } catch (Exception e) {
91 | log.error("", e);
92 | throw new RuntimeException(e);
93 | }
94 | }
95 |
96 | public InvokeResult transaction(Channel chain, String function, String[] args, ChaincodeID chainCodeId,
97 | List peerList, String asyncFlag) {
98 | return transaction(chain, function, args, chainCodeId, peerList,asyncFlag, 1);
99 | }
100 |
101 | public InvokeResult transaction(Channel chain, String function, String[] args, ChaincodeID chainCodeId,
102 | List peerList,String asyncFlag, int policy) {
103 |
104 | try {
105 | checkClient();
106 | List endorserList = new ArrayList();
107 |
108 | chain.getPeers().forEach(peer -> {
109 | if (peerList.contains(peer.getName())) {
110 | endorserList.add(peer);
111 | }
112 | });
113 |
114 |
115 | TransactionProposalRequest transactionProposalRequest = client.newTransactionProposalRequest();
116 | transactionProposalRequest.setArgs(args);
117 | transactionProposalRequest.setFcn(function);
118 | transactionProposalRequest.setChaincodeID(chainCodeId);
119 |
120 | Collection successful = new LinkedList<>();
121 | Collection failed = new LinkedList<>();
122 | Collection queryProposals = chain.sendTransactionProposal(transactionProposalRequest,
123 | endorserList);
124 |
125 | String transactionId = "";
126 | String returnPayLoad = "";
127 | for (ProposalResponse proposalResponse : queryProposals) {
128 | if (!proposalResponse.isVerified() || proposalResponse.getStatus() != ProposalResponse.Status.SUCCESS) {
129 | log.error("Failed query proposal from peer {} status: {} . Messages: {} . Was verified : {}",
130 | proposalResponse.getPeer().getName(), proposalResponse.getStatus(),
131 | proposalResponse.getMessage(), proposalResponse.isVerified());
132 | failed.add(proposalResponse);
133 | } else {
134 | successful.add(proposalResponse);
135 | String payload = proposalResponse.getProposalResponse().getResponse().getPayload().toStringUtf8();
136 | if (returnPayLoad == null) {
137 | log.debug("payload return {}", payload);
138 | returnPayLoad = payload;
139 | log.info("#############################交易ID############################# " + proposalResponse.getTransactionID());
140 | transactionId = proposalResponse.getTransactionID();
141 | } else if (!returnPayLoad.equals(payload)) {
142 | throw new RuntimeException("检测到节点数据不匹配!请检查智能合约是否同步或是否存在恶意节点!");
143 | }
144 | }
145 | }
146 | if (successful.size() < policy) {
147 | throw new RuntimeException("请求不满足背书策略");
148 | }
149 | if(AsyncInvokeTypeEnum.ASYNC.getCode().equals(asyncFlag)){
150 | InvokeResult result = new InvokeResult();
151 | result.setTxId(transactionId);
152 | //异步上链
153 | ThreadPoolManager.newInstance().addExecuteTask(() -> sendTransaction(chain, successful));
154 | return result;
155 | }else {
156 | InvokeResult result = this.sendTransaction(chain, successful);
157 | return result;
158 | }
159 | } catch (Exception e) {
160 | log.error("", e);
161 | throw new RuntimeException(e);
162 | }
163 | }
164 |
165 |
166 | public InvokeResult sendTransaction(Channel chain,Collection successful){
167 | CompletableFuture future = chain.sendTransaction(successful, chain.getOrderers());
168 | try {
169 | BlockEvent.TransactionEvent event = future.get();
170 | log.info("#############################区块号############################# " + event.getBlockEvent().getBlockNumber());
171 | log.info("#############################交易ID############################# " + event.getTransactionID());
172 | log.debug("{}", event.isValid());
173 | InvokeResult result = new InvokeResult();
174 | result.setBlockNo(event.getBlockEvent().getBlockNumber());
175 | result.setTxId(event.getTransactionID());
176 | return result;
177 | } catch (Exception e) {
178 | log.error("", e);
179 | throw new RuntimeException(e);
180 | }
181 | }
182 |
183 |
184 | public InvokeAsyncQueryResult asyncQueryResult(Channel chain, String transactionId){
185 | InvokeAsyncQueryResult result = new InvokeAsyncQueryResult();
186 | try {
187 | TransactionInfo transactionInfo = chain.queryTransactionByID(transactionId);
188 | BlockInfo blockInfo = chain.queryBlockByTransactionID(transactionId);
189 | result.setBlockId(blockInfo.getBlockNumber());
190 | result.setTxValidationCode(String.valueOf(transactionInfo.getValidationCode().getNumber()));
191 | result.setTxValidationMsg(transactionInfo.getValidationCode().getValueDescriptor().getFullName());
192 | if(transactionInfo.getValidationCode().getNumber() == 0) {
193 | result.setStatus(ResponseCodeEnum.SUCCESS.getCode());
194 | }else {
195 | result.setStatus(ResponseCodeEnum.PROCESS_ERROR.getCode());
196 | }
197 | }catch (Exception e) {
198 | log.error("", e);
199 | result.setTxValidationCode(ResponseCodeEnum.PROCESS_ERROR.getCode());
200 | result.setTxValidationMsg(e.getLocalizedMessage());
201 | result.setStatus(ResponseCodeEnum.PROCESS_ERROR.getCode());
202 | }
203 | return result;
204 | }
205 |
206 | public BlockchainInfo getBlockInfo(Channel chain) throws InvalidArgumentException, ProposalException {
207 | client.queryChannels((Peer) chain.getPeers().toArray()[0]);//通道总数
208 | client.queryInstalledChaincodes((Peer) chain.getPeers().toArray()[0]);//安装的合约数
209 | chain.queryInstantiatedChaincodes((Peer) chain.getPeers().toArray()[0]);//当前组织安装合约数
210 | chain.getDiscoveredChaincodeNames();//
211 | chain.getPeersOrganizationMSPIDs();//
212 | chain.getPeers();//peer总数
213 | chain.getOrderers();//排序总数
214 | chain.getOrderersOrganizationMSPIDs();//组织总数
215 | BlockchainInfo blockchainInfo = chain.queryBlockchainInfo();
216 | blockchainInfo.getHeight();//当前通道区块高度
217 | return null;
218 | }
219 |
220 |
221 | }
222 |
--------------------------------------------------------------------------------
/src/main/java/org/xialing/fabric/utils/CryptoUtils.java:
--------------------------------------------------------------------------------
1 | package org.xialing.fabric.utils;
2 |
3 | import org.bouncycastle.asn1.pkcs.PrivateKeyInfo;
4 | import org.bouncycastle.jce.provider.BouncyCastleProvider;
5 | import org.bouncycastle.openssl.PEMParser;
6 | import org.bouncycastle.openssl.jcajce.JcaPEMKeyConverter;
7 |
8 | import java.io.IOException;
9 | import java.io.StringReader;
10 | import java.security.NoSuchAlgorithmException;
11 | import java.security.NoSuchProviderException;
12 | import java.security.PrivateKey;
13 | import java.security.Security;
14 | import java.security.spec.InvalidKeySpecException;
15 |
16 | public class CryptoUtils {
17 |
18 | static {
19 | Security.addProvider(new BouncyCastleProvider());
20 | }
21 |
22 | public static PrivateKey getPrivateKeyFromBytes(byte[] data) throws IOException, NoSuchProviderException, NoSuchAlgorithmException, InvalidKeySpecException {
23 | final PEMParser pemParser = new PEMParser(new StringReader(new String(data)));
24 | PrivateKeyInfo pemPair = (PrivateKeyInfo) pemParser.readObject();
25 | return new JcaPEMKeyConverter().setProvider(BouncyCastleProvider.PROVIDER_NAME).getPrivateKey(pemPair);
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/main/java/org/xialing/fabric/utils/FabricUtils.java:
--------------------------------------------------------------------------------
1 | package org.xialing.fabric.utils;
2 |
3 | import org.xialing.common.dto.block.*;
4 | import org.xialing.common.dto.route.BaasRouteDTO;
5 | import org.xialing.fabric.config.FabricConfig;
6 | import org.xialing.fabric.model.FabricEnrollment;
7 | import org.xialing.fabric.model.FabricUser;
8 | import org.hyperledger.fabric.sdk.Channel;
9 | import org.hyperledger.fabric.sdk.HFClient;
10 | import org.hyperledger.fabric.sdk.Peer;
11 | import org.hyperledger.fabric.sdk.security.CryptoSuite;
12 |
13 | import java.util.ArrayList;
14 | import java.util.EnumSet;
15 | import java.util.List;
16 |
17 | import static org.hyperledger.fabric.sdk.Channel.PeerOptions.createPeerOptions;
18 |
19 | /**
20 | * @author leon
21 | * @version 1.0
22 | * @date 2020/3/3 15:24
23 | */
24 | public class FabricUtils {
25 |
26 | public static Channel initChannel(HFClient client, BlockChainOrgUserDTO userDTO, BlockChainOrgDTO currentOrgDTO,
27 | BlockChainChannelDTO channelDTO, BaasRouteDTO routeDTO, List ordererList) throws Exception {
28 | client.setCryptoSuite(CryptoSuite.Factory.getCryptoSuite());
29 |
30 | // 实例化用户需要先在控制台-证书管理中申请客户端证书,申请的企业名称需要与当前登录账户实名认证的企业名称相同
31 | FabricUser user = new FabricUser(userDTO.getOrgUserName(), new FabricEnrollment(userDTO.getOrgUserKey(), userDTO.getOrgUserCert()),
32 | currentOrgDTO.getMspId());
33 |
34 | client.setUserContext(user);
35 |
36 | Channel chain = client.newChannel(channelDTO.getChannelKey());
37 |
38 | for(BlockChainOrdererDTO ordererDTO: ordererList) {
39 | chain.addOrderer(client.newOrderer(ordererDTO.getOrdererKey(), routeDTO.getEndPoint(),
40 | FabricConfig.getOrderProperties(routeDTO.getSecretId(),routeDTO.getSecretKey(),ordererDTO.getOrdererKey())));
41 | }
42 |
43 | for(BlockChainOrgNodeDTO nodeDTO : currentOrgDTO.getNodeList()){
44 | chain.addPeer(client.newPeer(nodeDTO.getNodeKey(), routeDTO.getEndPoint(), FabricConfig.getPeerProperties(routeDTO.getSecretId(),
45 | routeDTO.getSecretKey(),nodeDTO.getNodeKey())),
46 | createPeerOptions().setPeerRoles(EnumSet.of(Peer.PeerRole.ENDORSING_PEER,
47 | Peer.PeerRole.LEDGER_QUERY, Peer.PeerRole.CHAINCODE_QUERY, Peer.PeerRole.EVENT_SOURCE)));
48 | //registerEventsForFilteredBlocks()
49 | }
50 |
51 |
52 | chain.initialize();
53 |
54 | return chain;
55 | }
56 |
57 |
58 | // public static List convertArgs(String[] args){
59 | // List byteArgs = new ArrayList<>();
60 | // for(String arg : args){
61 | // byteArgs.add(arg.getBytes());
62 | // }
63 | // return byteArgs;
64 | // }
65 |
66 | public static List converPeerNodeKey(List orgList){
67 | List peerKeyList = new ArrayList<>();
68 | for(BlockChainOrgDTO orgDTO : orgList){
69 | for(BlockChainOrgNodeDTO nodeDTO : orgDTO.getNodeList()){
70 | peerKeyList.add(nodeDTO.getNodeKey());
71 | }
72 | }
73 | return peerKeyList;
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/src/main/java/org/xialing/fabric/utils/ThreadPoolManager.java:
--------------------------------------------------------------------------------
1 | package org.xialing.fabric.utils;
2 |
3 | import com.google.common.util.concurrent.ThreadFactoryBuilder;
4 | import lombok.extern.slf4j.Slf4j;
5 |
6 | import java.util.LinkedList;
7 | import java.util.Queue;
8 | import java.util.concurrent.*;
9 |
10 | /**
11 | * 线程池管理(线程统一调度管理)
12 | * @author Leon
13 | */
14 | @Slf4j
15 | public final class ThreadPoolManager {
16 |
17 | private static ThreadPoolManager sThreadPoolManager = new ThreadPoolManager();
18 |
19 | /**
20 | * 线程名称格式
21 | */
22 | private final ThreadFactory namedThreadFactory = new ThreadFactoryBuilder().
23 | setNameFormat("uzigood-threadpool-call-runner-%d").build();
24 |
25 | /**
26 | * 线程池维护线程的最少数量
27 | */
28 | private static final int SIZE_CORE_POOL = 3;
29 |
30 | /**
31 | * 线程池维护线程的最大数量
32 | */
33 | private static final int SIZE_MAX_POOL = 4;
34 |
35 | /**
36 | * 线程池维护线程所允许的空闲时间
37 | */
38 | private static final int TIME_KEEP_ALIVE = 5000;
39 |
40 | /**
41 | * 线程池所使用的缓冲队列大小
42 | */
43 | private static final int SIZE_WORK_QUEUE = 500;
44 |
45 | /**
46 | * 任务调度周期
47 | */
48 | private static final int PERIOD_TASK_QOS = 1000;
49 |
50 | /**
51 | * 线程池单例创建方法
52 | */
53 | public static ThreadPoolManager newInstance() {
54 | return sThreadPoolManager;
55 | }
56 |
57 | /**
58 | * 任务缓冲队列
59 | */
60 |
61 | private final Queue mTaskQueue = new LinkedList();
62 |
63 | /**
64 | * 线程池超出界线时将任务加入缓冲队列
65 | */
66 | private final RejectedExecutionHandler mHandler = new RejectedExecutionHandler() {
67 | @Override
68 | public void rejectedExecution(Runnable task, ThreadPoolExecutor executor) {
69 | mTaskQueue.offer(task);
70 | }
71 | };
72 |
73 | /**
74 | * 将缓冲队列中的任务重新加载到线程池
75 | */
76 | private final Runnable mAccessBufferThread = new Runnable() {
77 | @Override
78 | public void run() {
79 | if (hasMoreAcquire()) {
80 | mThreadPool.execute(mTaskQueue.poll());
81 | }
82 | }
83 | };
84 |
85 | /**
86 | *
87 | * 线程池
88 | */
89 | private final ThreadPoolExecutor mThreadPool = new ThreadPoolExecutor(SIZE_CORE_POOL, SIZE_MAX_POOL,
90 | TIME_KEEP_ALIVE, TimeUnit.SECONDS, new ArrayBlockingQueue(SIZE_WORK_QUEUE),namedThreadFactory, mHandler);
91 |
92 | /**
93 | * 将构造方法访问修饰符设为私有,禁止任意实例化。
94 | */
95 | private ThreadPoolManager() {
96 | }
97 |
98 | public void perpare() {
99 | if (mThreadPool.isShutdown() && !mThreadPool.prestartCoreThread()) {
100 | @SuppressWarnings("unused")
101 | int startThread = mThreadPool.prestartAllCoreThreads();
102 | }
103 | }
104 |
105 | /**
106 | * 消息队列检查方法
107 | */
108 | private boolean hasMoreAcquire() {
109 | return !mTaskQueue.isEmpty();
110 | }
111 |
112 | /**
113 | * 向线程池中添加任务方法
114 | */
115 | public void addExecuteTask(Runnable task) {
116 | if (task != null) {
117 | log.info("mThreadPool线程池" + Thread.currentThread().getName());
118 | mThreadPool.execute(task);
119 | }
120 | }
121 |
122 | /**
123 | * 向线程池中添加任务方法
124 | */
125 | public Future addSubmitTask(Callable task) {
126 | if (task != null) {
127 | log.info("mThreadPool线程池" + Thread.currentThread().getName());
128 | return mThreadPool.submit(task);
129 | }
130 | return null;
131 | }
132 |
133 |
134 |
135 |
136 | protected boolean isTaskEnd() {
137 | return mThreadPool.getActiveCount() == 0;
138 | }
139 |
140 | public void shutdown() {
141 | mTaskQueue.clear();
142 | mThreadPool.shutdown();
143 | }
144 | }
--------------------------------------------------------------------------------
/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 |
2 | logging:
3 | level:
4 | org.xialing: info
5 | org.springframework: info
6 |
7 | spring:
8 | application:
9 | name: block-channel-fabric
10 | profiles:
11 | active: dev
12 |
13 |
--------------------------------------------------------------------------------
/src/main/resources/bootstrap.yml:
--------------------------------------------------------------------------------
1 |
2 | ## org.springframework.boot.autoconfigure.web.ServerProperties
3 | server.port: 8203
4 |
5 | management:
6 | endpoints:
7 | web:
8 | exposure:
9 | include: "*"
10 | spring:
11 | jackson:
12 | date-format: yyyy-MM-dd HH:mm:ss
13 | time-zone: GMT+8
14 | serialization:
15 | write-dates-as-timestamps: false
16 | undertow:
17 | buffer-size: 1024
18 | direct-buffers: true
19 |
20 | # 配置下面两个值将会走到 ControllerAdvice 全局里面去
21 | # org.springframework.boot.autoconfigure.web.WebMvcProperties
22 | # main:
23 | # #允许配置文件中存在相同名字时 覆盖
24 | # allow-bean-definition-overriding: true
25 | mvc.throw-exception-if-no-handler-found: true
26 | # org.springframework.boot.autoconfigure.web.ResourceProperties
27 | resources.add-mappings: false
28 |
--------------------------------------------------------------------------------
/src/main/resources/ca/cacert:
--------------------------------------------------------------------------------
1 | -----BEGIN CERTIFICATE-----
2 | MIIBvDCCAWICCQDP5Bh6UgTMHTAKBggqhkjOPQQDAjBmMQswCQYDVQQGEwJDTjER
3 | MA8GA1UECAwIU2hlblpoZW4xETAPBgNVBAcMCFNoZW5aaGVuMQ4wDAYDVQQKDAVu
4 | Z2lueDEhMB8GA1UEAwwYbmdpbnguYmNrNTI0cXFxN3Q2LnRiYWFzMB4XDTE5MDgz
5 | MDA1MDcyNVoXDTI5MDgyNzA1MDcyNVowZjELMAkGA1UEBhMCQ04xETAPBgNVBAgM
6 | CFNoZW5aaGVuMREwDwYDVQQHDAhTaGVuWmhlbjEOMAwGA1UECgwFbmdpbngxITAf
7 | BgNVBAMMGG5naW54LmJjazUyNHFxcTd0Ni50YmFhczBZMBMGByqGSM49AgEGCCqG
8 | SM49AwEHA0IABN7YCAjCGd6B1VU3D1Dt2r57dO6NMwSHpeS3T2dEfNztIpw+ATdw
9 | 2yLcwpGCqjTtEJrgVja2BWHRXCzzp70XFRYwCgYIKoZIzj0EAwIDSAAwRQIgZu56
10 | jugqIPR67+B+b1k5scWctrhHwilTd66Cp1KChgkCIQCd7lYIvrD/nA5NHKUuB9hP
11 | Jd3R9iLuTQuGTWgGGDiixA==
12 | -----END CERTIFICATE-----
--------------------------------------------------------------------------------
/src/main/resources/ca/client.pem:
--------------------------------------------------------------------------------
1 | -----BEGIN CERTIFICATE-----
2 | MIIC1DCCAnugAwIBAgIBCDAKBggqhkjOPQQDAjBlMQswCQYDVQQGEwJDTjERMA8G
3 | A1UECAwIU2hlblpoZW4xETAPBgNVBAcMCFNoZW5aaGVuMQ8wDQYDVQQKDAZ1emlP
4 | cmcxHzAdBgNVBAMMFmNhLnV6aW9yZy5iY2s1MjRxcXE3dDYwHhcNMjAwMjI2MDgx
5 | NjM1WhcNMjMwMjEwMDgxNjM1WjCBgzELMAkGA1UEBhMCQ04xETAPBgNVBAgTCFNo
6 | ZW5aaGVuMRIwEAYDVQQHEwk0U2hlblpoZW4xDzANBgNVBAoTBnV6aU9yZzEPMA0G
7 | A1UECxMGY2xpZW50MSswKQYDVQQDFCJ1emlnb29kQHV6aW9yZy5iY2s1MjRxcXE3
8 | dDZAY2xpZW50MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEAzxtgJ/wBFPw/SrG
9 | rsnq2IEm04TzO2ng1lHHqGmWar1nZXCsyXbftxMvYy3zIwnvIEuDZ3EcBJORg0Eu
10 | Pcm8bqOB/DCB+TAJBgNVHRMEAjAAMBEGCWCGSAGG+EIBAQQEAwIGQDAdBgNVHQ4E
11 | FgQUuKEiyVFN/8Ya8HNMKTlYr+6r8pAwgZcGA1UdIwSBjzCBjIAUdtwS3qW/4FAo
12 | DDtX8HnJgsgiAFShaaRnMGUxCzAJBgNVBAYTAkNOMREwDwYDVQQIDAhTaGVuWmhl
13 | bjERMA8GA1UEBwwIU2hlblpoZW4xDzANBgNVBAoMBnV6aU9yZzEfMB0GA1UEAwwW
14 | Y2EudXppb3JnLmJjazUyNHFxcTd0NoIJALj1NWhRvT22MAsGA1UdDwQEAwIFoDAT
15 | BgNVHSUEDDAKBggrBgEFBQcDATAKBggqhkjOPQQDAgNHADBEAiAQ22R3NbZydh0c
16 | NrUzS1E0d10LBVtGzf9ZrX7RY/pfYQIgVOxcZuckpl3V8pWZGtd0c7eTNU1JQfQk
17 | jpZQXNKdK7A=
18 | -----END CERTIFICATE-----
19 |
--------------------------------------------------------------------------------
/src/main/resources/ca/out_sk:
--------------------------------------------------------------------------------
1 | -----BEGIN PRIVATE KEY-----
2 | MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgBWbjRVdaaCNsA7Qn
3 | /c6cFlRWH86flgBKCs6whPXy2tChRANCAAQDPG2An/AEU/D9KsauyerYgSbThPM7
4 | aeDWUceoaZZqvWdlcKzJdt+3Ey9jLfMjCe8gS4NncRwEk5GDQS49ybxu
5 | -----END PRIVATE KEY-----
6 |
--------------------------------------------------------------------------------
/src/main/resources/logback-spring.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
8 | xialing
9 |
10 |
12 |
13 |
14 |
15 |
16 |
17 |
19 |
21 |
23 |
24 |
26 |
27 |
28 |
30 |
31 |
32 | debug
33 |
34 |
35 | ${CONSOLE_LOG_PATTERN}
36 |
37 | UTF-8
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
47 |
48 | ${log.path}/block-channel-fabric_debug.log
49 |
50 |
51 | %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} -
52 | %msg%n
53 | UTF-8
54 |
55 |
56 |
58 |
59 | ${log.path}/block-channel-fabric-debug-%d{yyyy-MM-dd}.%i.log
60 |
61 |
63 | 100MB
64 |
65 |
66 | 15
67 |
68 |
69 |
70 | debug
71 | ACCEPT
72 | DENY
73 |
74 |
75 |
76 |
77 |
79 |
80 | ${log.path}/block-channel-fabric_info.log
81 |
82 |
83 | %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} -
84 | %msg%n
85 | UTF-8
86 |
87 |
88 |
90 |
91 | ${log.path}/block-channel-fabric-info-%d{yyyy-MM-dd}.%i.log
92 |
93 |
95 | 100MB
96 |
97 |
98 | 15
99 |
100 |
101 |
102 | info
103 | ACCEPT
104 | DENY
105 |
106 |
107 |
108 |
109 |
111 |
112 | ${log.path}/block-channel-fabric_warn.log
113 |
114 |
115 | %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} -
116 | %msg%n
117 | UTF-8
118 |
119 |
120 |
122 | ${log.path}/block-channel-fabric-warn-%d{yyyy-MM-dd}.%i.log
123 |
124 |
126 | 100MB
127 |
128 |
129 | 15
130 |
131 |
132 |
133 | warn
134 | ACCEPT
135 | DENY
136 |
137 |
138 |
139 |
140 |
142 |
143 | ${log.path}/block-channel-fabric_error.log
144 |
145 |
146 | %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} -
147 | %msg%n
148 | UTF-8
149 |
150 |
151 |
153 | ${log.path}/block-channel-fabric-error-%d{yyyy-MM-dd}.%i.log
154 |
155 |
157 | 100MB
158 |
159 |
160 | 15
161 |
162 |
163 |
164 | ERROR
165 | ACCEPT
166 | DENY
167 |
168 |
169 |
170 |
171 |
177 |
178 |
182 |
183 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 |
196 |
197 |
198 |
199 |
200 |
201 |
202 |
203 |
204 |
205 |
206 |
--------------------------------------------------------------------------------