├── LICENSE ├── README-cn.md ├── README.md ├── privacy-contract └── bidding │ ├── README-cn.md │ ├── README.md │ ├── alice-data-node │ ├── alice-data-node.iml │ ├── dependency-reduced-pom.xml │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ ├── client │ │ └── Client1.java │ │ ├── net │ │ └── platon │ │ │ └── vm │ │ │ └── mpc │ │ │ └── MPCBidEvaluation.java │ │ └── network │ │ └── platon │ │ └── bidevaluation │ │ └── BidEvaluation.java │ ├── bob-data-node │ ├── bob-data-node.iml │ ├── dependency-reduced-pom.xml │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ ├── client │ │ └── Client1.java │ │ ├── net │ │ └── platon │ │ │ └── vm │ │ │ └── mpc │ │ │ └── MPCBidEvaluation.java │ │ └── network │ │ └── platon │ │ └── bidevaluation │ │ └── BidEvaluation.java │ ├── cfg.client1.linux.config │ ├── cfg.client2.linux.config │ ├── contract │ ├── BidEvaluation.cpp │ └── BidEvaluation.proto │ └── dapp │ ├── dapp.iml │ ├── dependency-reduced-pom.xml │ ├── pom.xml │ └── src │ └── main │ └── java │ ├── client │ ├── Client.java │ └── ParameterParser.java │ └── platon │ └── mpc │ └── proxy │ └── ProxyTool.java └── pwasm-contract └── bidding ├── README-cn.md ├── README.md ├── contract └── bidding.cpp └── dapp ├── .classpath ├── .gradle └── 2.13-rc-1 │ └── taskArtifacts │ ├── cache.properties │ ├── cache.properties.lock │ ├── fileHashes.bin │ ├── fileSnapshots.bin │ └── taskArtifacts.bin ├── .project ├── .settings ├── com.zeroc.IceBuilderPlugin.prefs ├── gradle │ ├── org.springsource.ide.eclipse.gradle.core.prefs │ └── org.springsource.ide.eclipse.gradle.refresh.prefs └── org.eclipse.jdt.core.prefs ├── bin ├── net │ └── platon │ │ └── bid │ │ ├── BidMain.class │ │ ├── Bidding$1.class │ │ ├── Bidding$2.class │ │ ├── Bidding$BiddingEventResponse.class │ │ └── Bidding.class └── org │ └── gradle │ └── resource.xml ├── build.gradle └── src └── main ├── java └── net │ └── platon │ └── bid │ ├── BidMain.java │ └── Bidding.java └── resources └── org └── gradle └── resource.xml /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README-cn.md: -------------------------------------------------------------------------------- 1 | # Contract Example - PlatON合约范例 2 | 3 | Copyright 2018 `PlatON`. 4 | 5 | 6 | 7 | ## 概述 8 | 9 | 本文档提供基于`PlatON`平台开发的Dapp范例,并提供完整的工程实现和文档。 10 | 11 | ## privacy-contract 12 | 13 | `privacy-contract`目录主要包含隐私合约范例工程,请参考:[隐私竞价范例](https://github.com/PlatONnetwork/Contract-Example/tree/master/privacy-contract/bidding),获取更多内容。 14 | 15 | ## pwasm-contract 16 | 17 | `pwasm-contract`目录主要包含`wasm`合约范例工程,请参考:[pwasm竞价范例](https://github.com/PlatONnetwork/Contract-Example/tree/master/pwasm-contract/bidding),获取更多详细内容。 18 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Contract Example - PlatON contract examples 2 | 3 | Copyright 2018 `PlatON`. 4 | 5 | 6 | 7 | ## Overview 8 | 9 | This document provides several Dapp examples based on the `PlatON` platform and provides complete engineering implementation and documentation. 10 | 11 | ## privacy-contract 12 | 13 | The `privacy-contract` directory mainly contains standard privacy contract sample projects, for more detail, please refer to: [privacy bidding example](https://github.com/PlatONnetwork/Contract-Example/tree/master/privacy-contract/bidding). 14 | 15 | ## pwasm-contract 16 | 17 | The `pwasm-contract` directory mainly contains the `wasm` contract example project, for more detail, please refer to: [pwasm bidding example](https://github.com/PlatONnetwork/Contract-Example/tree/master/pwasm-contract/bidding). 18 | -------------------------------------------------------------------------------- /privacy-contract/bidding/README-cn.md: -------------------------------------------------------------------------------- 1 | [TOC] 2 | # Bidding privacy contract development on Linux 3 | 4 | 本范例使用隐私合约实现了隐私竞标,包含了隐私合约实现、数据节点实现和Dapp。竞标方法为: 二次加权平均评标。 5 | 6 | > ***本范例要求运行在Ubuntu16.04。*** 7 | 8 | ## 二次加权平均评标 9 | 10 | 假设有三家投标方A/B/C,分别报价a/b/c,开标方P标底价为p,通过Dapp进行评标,评标方法如下: 11 | 报价平均值 y = ( a + b + c ) / 3 12 | 评标基准值 z = ( y + p)/ 2 13 | 取投标报价中低于(含等于)z值,且最接近者为中标人。 14 | 15 | ## 环境要求 16 | 17 | ### 硬件要求 18 | 19 | - CPU架构 20 | 21 | 目前官方只支持`Intel`2代及以上`CPU`架构,搭建环境前需要检测机器是否满足最低要求。 22 | 23 | ```bash 24 | $ cat /proc/cpuinfo 25 | ``` 26 | 27 | 例如输出如下信息: 28 | 29 | ```bash 30 | model name : Intel(R) Xeon(R) CPU E5-2620 v2 @ 2.10GHz 31 | ``` 32 | 33 | 其中`E5-2620 v2`表示`CPU`为Intel第三代架构,符合要求。 34 | 35 | > **CPU架构必须满足Intel v2或以上,否则将无法正常运行** 36 | 37 | ### 软件要求 38 | 39 | - Ubuntu16.04 40 | 41 | 指定操作系统为Ubuntu16.04。 42 | 43 | - JDK1.8+ 44 | 45 | 请参考:[oracle官方网站](https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html),安装并配置好环境变量`CLASSPATH`, `PATH`, `JAVA_HOME`。 46 | 47 | - Maven3.3.9+ 48 | 49 | 请参考:[maven官方网站](http://maven.apache.org/download.cgi)完成安装。 50 | 51 | ## 搭建隐私计算网络 52 | 搭建具有两个计算节点的隐私计算网络,其中计算节点均为`PlatON`节点客户端。 53 | 54 | ### 安装PlatON节点客户端 55 | 56 | 安装带MPC功能的`platon`节点客户端: 57 | 58 | ```bash 59 | # add PPA 60 | $ sudo add-apt-repository ppa:platonnetwork/platon 61 | $ sudo apt-get update 62 | 63 | # install platon with mpc 64 | $ sudo apt-get -f install platon-all 65 | ``` 66 | ### 搭建私有网络 67 | 68 | 参考[PlatON集群环境](zh-cn/basics/[Chinese-Simplified]-%e7%a7%81%e6%9c%89%e7%bd%91%e7%bb%9c#PlatON+%e9%9b%86%e7%be%a4%e7%8e%af%e5%a2%83)搭建私有网络,将计算节点连接私有网络。 69 | 70 | ### 创建数据节点钱包 71 | 72 | 隐私计算包含两个计算参与方,每个参与方分别创建钱包文件: 73 | 74 | ```bash 75 | $ mkdir -p data 76 | $ ./platon --datadir ./data account new 77 | Your new account is locked with a password. Please give a password. Do not forget this password. 78 | Passphrase: 79 | Repeat passphrase: 80 | Address: {0x9a568e649c3a9d43b7f565ff2c835a24934ba447}Copy to clipboardErrorCopied 81 | $ ./platon --datadir ./data account new 82 | Your new account is locked with a password. Please give a password. Do not forget this password. 83 | Passphrase: 84 | Repeat passphrase: 85 | Address: {0xce3a4aa58432065c4c5fae85106aee4aef77a115}Copy to clipboardErrorCopied 86 | ``` 87 | 88 | 以上命令执行2次创建钱包操作,例如本次获得了两个钱包地址如下: 89 | 90 | > `0x9a568e649c3a9d43b7f565ff2c835a24934ba447` 91 | 92 | > `0xce3a4aa58432065c4c5fae85106aee4aef77a115` 93 | 94 | ### 启用MPC功能 95 | 96 | 参考[启用MPC计算功能](zh-cn/basics/[Chinese-Simplified]-%e7%a7%81%e6%9c%89%e7%bd%91%e7%bb%9c#%e4%b8%ba%e8%8a%82%e7%82%b9%e5%90%af%e7%94%a8MPC%e5%8a%9f%e8%83%bd),并且在重启`platon`时候,将`-mpc.actor` 对应配置为上一步生成的数据节点钱包地址:`0x9a568e649c3a9d43b7f565ff2c835a24934ba447`,`0xce3a4aa58432065c4c5fae85106aee4aef77a115`。 97 | 98 | ## 体验隐私bidding 99 | 100 | ### 下载源码 101 | 克隆仓库; 102 | ```bash 103 | $ git clone https://github.com/PlatONnetwork/Contract-Example.git 104 | ``` 105 | ### 安装隐私合约开发工具 106 | #### 下载工具安装包 107 | 下载隐私合约开发工具[安装包](https://download.platon.network/0.5/platon-ubuntu-amd64-mpc-toolkit.tar.gz): 108 | ```bash 109 | $ wget https://download.platon.network/0.5/platon-ubuntu-amd64-mpc-toolkit.tar.gz 110 | $ tar -xvzf platon-ubuntu-amd64-mpc-toolkit.tar.gz 111 | ``` 112 | 执行完以上命令,隐私合约开发工具安装到`platon-mpc-toolkit`工作目录,目录结构如下: 113 | 114 | ```bash 115 | platon-mpc-toolkit 116 | ├── compiler 117 | ├── config.json.template 118 | ├── create_testnet_wallet.sh 119 | ├── ctool 120 | ├── ctool.config.json.template 121 | ├── install-deps.sh 122 | ├── mpc 123 | │ .... 124 | ├── pwasm 125 | │ .... 126 | ├── readme.txt 127 | ├── sample 128 | │ ├── SimpleAddProto.cpp 129 | │ ├── SimpleAddProto.proto 130 | │ └── YaoMillionairesProblem.cpp 131 | ├── web3j -> mpc/bin/web3j/bin/web3j 132 | ``` 133 | 说明: 134 | - **compiler** 135 | 隐私合约编译脚本 136 | - **ctool** 137 | 隐私合约发布工具 138 | - **install-deps.sh** 139 | 第三方依赖安装脚本 140 | - **create_testnet_wallet.sh** 141 | 创建钱包工具脚本 142 | - **mpc** 143 | mpc相关工具集 144 | - **pwas** 145 | pWASM相关工具集 146 | - **sample** 147 | 隐私合约实例 148 | - **config.json.template** 149 | 隐私合约编译配置模板 150 | - **ctool.config.json.template** 151 | 隐私合约发布工具配置文件模板 152 | 153 | 切换到`platon-mpc-toolkit`目录,安装第三方集依赖: 154 | ```bash 155 | $ bash install-deps.sh 156 | ``` 157 | 158 | #### compiler使用方法 159 | **用法:** 160 | ```bash 161 | $ bash ./compiler -c {your config file} -i {your privacy contract} -o {output directory} 162 | ``` 163 | **参数说明:** 164 | * -c:隐私合约文件 165 | * -o:输出目录 166 | * -i:编译配置文件 167 | * -p:`protobuf`定义文件 168 | 169 | ### 编译隐私合约 170 | 171 | 将克隆仓库的bidding隐私合约(`Contract-Example/privacy-contract/bidding/contract/BidEvaluation.cpp`)拷贝到`platon-mpc-toolkit/`,编译隐私合约: 172 | ```bash 173 | $ cd platon-mpc-toolkit 174 | $ bash compiler -c config.json.template -i BidEvaluation.cpp -o ./user 175 | ``` 176 | 执行输出: 177 | ```bash 178 | user/ 179 | ├── MPCBidEvaluation.java # MPC data node core class 180 | ├── MPCBidEvaluation-README.TXT 181 | ├── ProxyBidEvaluation.java # dapp proxy core class 182 | ├── ProxyBidEvaluation-README.TXT 183 | ├── BidEvaluation.cpp.abi.json # abi file of pwam 184 | └── BidEvaluation.wasm # compiled binary of pwasm 185 | ``` 186 | 187 | - **MPCBidEvaluation.java:** 188 | 189 | 数据节点核心类,与`Contract-Example/privacy-contract/bidding/bob-data-node/src/main/java/net/platon/vm/mpc/MPCBidEvaluation.java`相同,用于数据节点注册到计算节点参与隐私计算。 190 | 191 | - **ProxyBidEvaluation.java:** 192 | 193 | Dapp代理客户端类,与`Contract-Example/privacy-contract/bidding/dapp/src/main/java/platon/mpc/proxy/`ProxyBidEvaluation.java`相同, 用于发起隐私计算。 194 | 195 | - **BidEvaluation.wasm:** 196 | 197 | bidding隐私合约二进制,用于隐私合约发布。 198 | 199 | - **BidEvaluation.cpp.abi.json** 200 | 201 | bidding隐私合约abi,用于隐私合约发布。 202 | 203 | ### 发布隐私合约 204 | 205 | 切换工作目录到隐私合约开发工具包安装目录`platon-mpc-toolkit/`。执行以下步骤: 206 | 207 | 1. 编写配置文件 208 | 编写配置文件ctool.config.json如下: 209 | ```bash 210 | { 211 | "url":"http://127.0.0.1:6789", 212 | "gas":"0x99999788888", 213 | "gasPrice":"0x333330", 214 | "from":"0x9a568e649c3a9d43b7f565ff2c835a24934ba447" 215 | } 216 | ``` 217 | 2. 临时解锁账户 218 | ```bash 219 | $ platon attach http://localhost:6789 220 | #enter rpc console 221 | > personal.unlockAccount(eth.accounts[0]) 222 | ``` 223 | 3. 发布合约 224 | ``` 225 | ./ctool deploy --abi ./user/BidEvaluation.cpp.abi.json --code ./user/BidEvaluation.wasm --config ./config.json 226 | ``` 227 | 部署成功后,比如本次输出合约发布地址: 228 | > 0x43355c787c50b647c425f594b441d4bd75198888 229 | 230 | ### 编译mvn工程 231 | 232 | 切换工作目录到:`Contract-Example/privacy-contract/bidding`,分别编译数据节点程序和`Dapp`服务,命令如下: 233 | 234 | ```bash 235 | cd bob-data-node 236 | mvn package 237 | 238 | cd ../alice-data-node 239 | mvn package 240 | 241 | cd ../dapp 242 | mvn package 243 | ``` 244 | 245 | 执行命令,分别生成: 246 | 247 | ```bash 248 | bob-data-node/target/bob-data-node-1.0.jar 249 | alice-data-node/target/alice-data-node-1.0.jar 250 | dapp/target/dapp-1.0.jar 251 | ``` 252 | 253 | ### 启动Bob数据节点 254 | 255 | 切换到工作目录:`Contract-Example/privacy-contract/bidding`,修改配置文件如下: 256 | 257 | ```bash 258 | # 259 | # The client reads this property to create the reference to the 260 | # "TaskCallback" object in the server. 261 | # 262 | TaskCallback.Proxy=tasksession:default -h localhost -p 10002 263 | ``` 264 | 265 | 拷贝`0x9a568e649c3a9d43b7f565ff2c835a24934ba447`地址对应钱包文件,比如命名为:`9a568e649c3a9d43b7f565ff2c835a24934ba447`。 266 | 267 | 执行以下命令启动服务: 268 | 269 | ``` 270 | java -jar bob-data-node/target/bob-data-node-1.0.jar -iceCfgFile=./执行以下命令启动服务: -walletPath=60ceca9c1290ee56b98d4e160ef0453f7c40d219 -walletPass=11111111 271 | ``` 272 | 273 | ### 启动Alice数据节点 274 | 275 | 切换到工作目录:`Contract-Example/privacy-contract/bidding`,修改配置文件如下: 276 | 277 | ```bash 278 | # 279 | # The client reads this property to create the reference to the 280 | # "TaskCallback" object in the server. 281 | # 282 | TaskCallback.Proxy=tasksession:default -h localhost -p 10001 283 | ``` 284 | 285 | 拷贝`0xce3a4aa58432065c4c5fae85106aee4aef77a115`地址对应钱包文件,比如命名为:`ce3a4aa58432065c4c5fae85106aee4aef77a115`。 286 | 287 | 执行以下命令启动服务: 288 | 289 | ``` 290 | java -jar alice-data-node/target/alice-data-node-1.0.jar -iceCfgFile=./执行以下命令启动服务: -walletPath=ce3a4aa58432065c4c5fae85106aee4aef77a115 -walletPass=11111111 291 | ``` 292 | 293 | ### 发起bidding计算 294 | 295 | 切换到工作目录:`Contract-Example/privacy-contract/bidding`,执行以下命令: 296 | 297 | ```bash 298 | java -jar dapp/target/dapp-1.0.jar --walletPath=ce3a4aa58432065c4c5fae85106aee4aef77a115 --walletPass=111111 --url="http://localhost:6789" --contractAddress="0x43355c787c50b647c425f594b441d4bd75198888" --api="startCalc(BidEvaluationResult)" 299 | ``` 300 | 301 | 执行成功得到一个交易,例如: 302 | 303 | ```bash 304 | 0x45655c787c50b647c425f594b441d4bd75198888 305 | ``` 306 | 307 | 由于隐私计算开始执行需要一定的时间,需要等待大约20s左右,然后查询结果: 308 | 309 | ```bash 310 | java -jar dapp/target/dapp-1.0.jar --walletPath=ce3a4aa58432065c4c5fae85106aee4aef77a115 --walletPass=111111 --url="http://localhost:6789" --contractAddress="0x43355c787c50b647c425f594b441d4bd75198888" --api="getResultByTransactionID(45655c787c50b647c425f594b441d4bd75198888)" --returnType=int --method=BidEvaluationResult 311 | ``` 312 | 313 | 例如最后我们得到结果: 314 | 315 | ```bash 316 | 2 317 | ``` 318 | 319 | 在竞标的过程中,所有竞标人的竞标值都是安全的、不会泄露给任何其他参与方,这些特性有MPC协议保证。这里我们来到了隐私竞标的结尾,祝愉快 :) -------------------------------------------------------------------------------- /privacy-contract/bidding/README.md: -------------------------------------------------------------------------------- 1 | # Bidding privacy contract development on Linux 2 | 3 | 4 | This example uses privacy contract to implement privacy bidding, including privacy contract implementation, data node implementation, and `Dapp` sample. The bidding method is: secondary weighted average bid evaluation. 5 | 6 | > ***This example requires running on Ubuntu 16.04.*** 7 | 8 | ## Second weighted average bid evaluation 9 | 10 | Suppose there are three bidders A/B/C, which are quoted a/b/c respectively, and the bidder's P bid base price is p, and the bid evaluation is carried out by `Dapp`. The bid evaluation method is as follows: 11 | Average price of y = ( a + b + c ) / 3 12 | Bid evaluation value z = ( y + p) / 2 13 | The bid price is lower than (including equal to) z value, and the closest one is the winning bidder. 14 | 15 | ## Environmental requirements 16 | 17 | ### Hardware requirements 18 | 19 | - CPU architecture 20 | 21 | At present, the official only supports the `Intel`2 generation and above `CPU` architecture. Before setting up the environment, it is necessary to check whether the machine meets the minimum requirements. 22 | 23 | ```bash 24 | $ cat /proc/cpuinfo 25 | ``` 26 | 27 | For example, the following output : 28 | 29 | ```bash 30 | Model name : Intel(R) Xeon(R) CPU E5-2620 v2 @ 2.10GHz 31 | ``` 32 | 33 | Among them, `E5-2620 v2` indicates that the `CPU` is Intel's third-generation architecture, which meets the requirements. 34 | 35 | > **CPU architecture must meet Intel v2 or above, otherwise it will not work properly** 36 | 37 | ### Software requirements 38 | 39 | - Ubuntu16.04 40 | 41 | The specified operating system is Ubuntu 16.04. 42 | 43 | - JDK1.8+ 44 | 45 | Please refer to: [oracle official website](https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html), install and configure the environment variables `CLASSPATH`, `PATH`, `JAVA_HOME`. 46 | 47 | - Maven3.3.9+ 48 | 49 | Please refer to: [maven official website](http://maven.apache.org/download.cgi) to complete the installation. 50 | 51 | ## Building a privacy computing network 52 | A privacy computing network with two computing nodes is built, where the computing nodes are all `PlatON` node clients. 53 | 54 | ### Installing the PlatON node client 55 | 56 | Install the `platon` node client with MPC functionality: 57 | 58 | ```bash 59 | # add PPA 60 | $ sudo add-apt-repository ppa:platonnetwork/platon 61 | $ sudo apt-get update 62 | 63 | # install platon with mpc 64 | $ sudo apt-get -f install platon-all 65 | ``` 66 | After the installation, the executable files such as `platon`, `ethkey` will be installed to `/usr/bin`. 67 | 68 | ### Building a private network 69 | 70 | Refer to [PlatON Cluster Environment](zh-cn/basics/[Chinese-Simplified]-%e7%a7%81%e6%9c%89%e7%bd%91%e7%bb%9c#PlatON+%e9%9b%86%e7%be%a4%e7%8e%af%e5%a2%83) to build a private network and connect compute nodes to the private network. 71 | 72 | ### Creating two wallets for data nodes 73 | 74 | The privacy calculation consists of two computing participants, each of them creates a wallet file as follows: 75 | 76 | ```bash 77 | $ mkdir -p data 78 | $ ./platon --datadir ./data account new 79 | Your new account is locked with a password. Please give a password. Do not forget this password. 80 | Passphrase: 81 | Repeat passphrase: 82 | Address: {0x9a568e649c3a9d43b7f565ff2c835a24934ba447}Copy to clipboardErrorCopied 83 | $ ./platon --datadir ./data account new 84 | Your new account is locked with a password. Please give a password. Do not forget this password. 85 | Passphrase: 86 | Repeat passphrase: 87 | Address: {0xce3a4aa58432065c4c5fae85106aee4aef77a115}Copy to clipboardErrorCopied 88 | ``` 89 | 90 | The above commands perform two operations to create wallets, and we got two wallet addresses as follows: 91 | 92 | > `0x9a568e649c3a9d43b7f565ff2c835a24934ba447` 93 | 94 | > `0xce3a4aa58432065c4c5fae85106aee4aef77a115` 95 | 96 | ### Turning on MPC function 97 | 98 | Refer to [Enable MPC Calculation Function](zh-cn/basics/[Chinese-Simplified]-%e7%a7%81%e6%9c%89%e7%bd%91%e7%bb%9c#%e4%b8% Ba%e8%8a%82%e7%82%b9%e5%90%af%e7%94%a8MPC%e5%8a%9f%e8%83%bd), when restarting `platon`, will be `-mpc The .actor` corresponding configuration is the data node wallet address generated in the previous step: `0x9a568e649c3a9d43b7f565ff2c835a24934ba447`, `0xce3a4aa58432065c4c5fae85106aee4aef77a115`. 99 | 100 | ## Trying privacy bidding 101 | 102 | ### Downloading source 103 | Clone [PlatON Contract Examples](https://github.com/PlatONnetwork/Contract-Example.git) `github` repository: 104 | ```bash 105 | $ git clone https://github.com/PlatONnetwork/Contract-Example.git 106 | ``` 107 | ### Installing privacy contract development tools 108 | #### Downloading package 109 | Download the privacy contract development tool [installation package](https://download.platon.network/0.5/platon-ubuntu-amd64-mpc-toolkit.tar.gz): 110 | ```bash 111 | $ wget https://download.platon.network/0.5/platon-ubuntu-amd64-mpc-toolkit.tar.gz 112 | $ tar -xvzf platon-ubuntu-amd64-mpc-toolkit.tar.gz 113 | ``` 114 | After executing the above command, the privacy contract development tool is installed into the `platon-mpc-toolkit` working directory. The directory structure is as follows: 115 | 116 | ```bash 117 | platon-mpc-toolkit 118 | ├── compiler 119 | ├── config.json.template 120 | ├── create_testnet_wallet.sh 121 | ├── ctool 122 | ├── ctool.config.json.template 123 | ├── install-deps.sh 124 | ├── mpc 125 | │ .... 126 | ├── pwasm 127 | │ .... 128 | ├── readme.txt 129 | ├── sample 130 | │ ├── SimpleAddProto.cpp 131 | │ ├── SimpleAddProto.proto 132 | │ └── YaoMillionairesProblem.cpp 133 | ├── web3j -> mpc/bin/web3j/bin/web3j 134 | ``` 135 | Description: 136 | - **compiler** 137 | Privacy contract compilation script 138 | - **ctool** 139 | Privacy contract deploy tool 140 | - **install-deps.sh** 141 | Third-party dependent installation script 142 | - **create_testnet_wallet.sh** 143 | A tool script to create a wallet 144 | - **mpc** 145 | `MPC` related toolset 146 | - **pwas** 147 | `pWASM` related toolset 148 | - **sample** 149 | Privacy contract samples 150 | - **config.json.template** 151 | Configuration template of `compiler` 152 | - **ctool.config.json.template** 153 | Configuration template of `ctool` 154 | 155 | Switch to the `platon-mpc-toolkit` directory and install the third-party set dependencies: 156 | ```bash 157 | $ bash install-deps.sh 158 | ``` 159 | 160 | #### compiler usage 161 | **usage:** 162 | ```bash 163 | $ bash ./compiler -c {your config file} -i {your privacy contract} -o {output directory} 164 | ``` 165 | **Parameter Description:** 166 | * -c: privacy contract file 167 | * -o: output directory 168 | * -i: compile the configuration file 169 | * -p:`protobuf` definition file 170 | 171 | ### Compiling the privacy contract 172 | 173 | Copy the bidding privacy contract (`Contract-Example/privacy-contract/bidding/contract/BidEvaluation.cpp`) of the clone repository to `platon-mpc-toolkit/` to compile the privacy contract: 174 | ```bash 175 | $ cd platon-mpc-toolkit 176 | $ bash compiler -c config.json.template -i BidEvaluation.cpp -o ./user 177 | ``` 178 | After execution, it will generate compiled contracts and Java core classes in the `user/`, which is as follows: 179 | ```bash 180 | user/ 181 | ├── MPCBidEvaluation.java # MPC data node core class 182 | ├── MPCBidEvaluation-README.TXT 183 | ├── ProxyBidEvaluation.java # dapp proxy core class 184 | ├── ProxyBidEvaluation-README.TXT 185 | ├── BidEvaluation.cpp.abi.json # abi file of pwam 186 | └── BidEvaluation.wasm # compiled binary of pwasm 187 | ``` 188 | 189 | - **MPCBidEvaluation.java** 190 | 191 | The data node core class `MPCBidEvaluation.java` is the same as `Contract-Example/privacy-contract/bidding/bob-data-node/src/main/java/net/platon/vm/mpc/MPCBidEvaluation.java`, which is for registration and participating to MPC calculation. 192 | 193 | - **ProxyBidEvaluation.java** 194 | 195 | The `Dapp` proxy client class `ProxyBidEvaluation.java` is the same as `Contract-Example/privacy-contract/bidding/dapp/src/main/java/platon/mpc/proxy/ProxyBidEvaluation.java`, whchi is used to initiate privacy calculations. 196 | 197 | - **BidEvaluation.wasm** 198 | 199 | Bidding private contract binary for privacy contract. 200 | 201 | - **BidEvaluation.cpp.abi.json** 202 | 203 | The bidding privacy contract `abi`, which is the description of the `pWASM` is used for the release of privacy contracts. 204 | 205 | ### Publishing a privacy contract 206 | 207 | Switch the working directory to the privacy contract development kit installation directory `platon-mpc-toolkit/`. Perform the following steps: 208 | 209 | 1. Write a configuration file 210 | Create configuration file `ctool.config.json` as follows: 211 | ```bash 212 | { 213 | "url": "http://127.0.0.1:6789", 214 | "gas": "0x99999788888", 215 | "gasPrice": "0x333330", 216 | "from":"0x9a568e649c3a9d43b7f565ff2c835a24934ba447" 217 | } 218 | ``` 219 | 2. Temporarily unlock the account 220 | ```bash 221 | $ platon attach http://localhost:6789 222 | #enter rpc console 223 | > personal.unlockAccount('0x9a568e649c3a9d43b7f565ff2c835a24934ba447') 224 | ``` 225 | 3. Release contract 226 | ``` 227 | ./ctool deploy --abi ./user/BidEvaluation.cpp.abi.json --code ./user/BidEvaluation.wasm --config ./config.json 228 | ``` 229 | 230 | After the deployment, for our example the deployed contract address is: 231 | 232 | > 0x43355c787c50b647c425f594b441d4bd75198888 233 | 234 | ### Compiling mvn project 235 | 236 | Switch the working directory to `Contract-Example/privacy-contract/bidding`, compile the data node program and the `Dapp` service respectively. The commands are as follows: 237 | 238 | ```bash 239 | $ cd bob-data-node 240 | $ mvn package 241 | 242 | $ cd ../alice-data-node 243 | $ mvn package 244 | 245 | $ cd ../dapp 246 | $ mvn package 247 | ``` 248 | 249 | After Executing the command, it will generates the following `Java jar`: 250 | 251 | ```bash 252 | bob-data-node/target/bob-data-node-1.0.jar 253 | alice-data-node/target/alice-data-node-1.0.jar 254 | dapp/target/dapp-1.0.jar 255 | ``` 256 | 257 | ### Running Bob data node 258 | 259 | Switch the working directory to `Contract-Example/privacy-contract/bidding`, modify the configuration file as follows: 260 | 261 | ```bash 262 | # 263 | # The client reads this property to create the reference to the 264 | # "TaskCallback" object in the server. 265 | # 10002 is the listenning port of the node 266 | TaskCallback.Proxy=tasksession:default -h localhost -p 10002 267 | ``` 268 | 269 | Copy the wallet file of address `0x9a568e649c3a9d43b7f565ff2c835a24934ba447` , for example we named the file `9a568e649c3a9d43b7f565ff2c835a24934ba447`. 270 | 271 | Execute the following command to start the `Bob data node` service: 272 | 273 | ``` 274 | java -jar bob-data-node/target/bob-data-node-1.0.jar -iceCfgFile=./Execute the following command to start the service: -walletPath=60ceca9c1290ee56b98d4e160ef0453f7c40d219 -walletPass=11111111 275 | ``` 276 | 277 | ### Running Alice data node 278 | 279 | Switch to the working directory: `Contract-Example/privacy-contract/bidding`, modify the configuration file as follows: 280 | 281 | ```bash 282 | # 283 | # The client reads this property to create the reference to the 284 | # "TaskCallback" object in the server. 285 | # 286 | TaskCallback.Proxy=tasksession:default -h localhost -p 10001 287 | ``` 288 | 289 | Copy the wallet file of address `0xce3a4aa58432065c4c5fae85106aee4aef77a115`, for example we named the file `ce3a4aa58432065c4c5fae85106aee4aef77a115`. 290 | 291 | Execute the following command to start the `Alice data node` service: 292 | 293 | ``` 294 | java -jar alice-data-node/target/alice-data-node-1.0.jar -iceCfgFile=./Execute the service by executing the following command: -walletPath=ce3a4aa58432065c4c5fae85106aee4aef77a115 -walletPass=11111111 295 | ``` 296 | 297 | ### Initiating bidding calculation 298 | 299 | Switch to the working directory `Contract-Example/privacy-contract/bidding` and execute the following command: 300 | 301 | ```bash 302 | java -jar dapp/target/dapp-1.0.jar --walletPath=ce3a4aa58432065c4c5fae85106aee4aef77a115 --walletPass=11111111 --url = "http:// localhost:6789" --contractAddress="0x43355c787c50b647c425f594b441d4bd75198888" --api="startCalc(BidEvaluationResult)" 303 | ``` 304 | 305 | Successfully get a transaction, for example: 306 | 307 | ```bash 308 | 0x45655c787c50b647c425f594b441d4bd75198888 309 | ``` 310 | 311 | Since the privacy calculation take a certain amount of time to get start, it takes about 20s to wait, and then we try to get the result as follows: 312 | 313 | ```bash 314 | java -jar dapp /target/dapp-1.0.jar --walletPath=ce3a4aa58432065c4c5fae85106aee4aef77a115 --walletPass=11111111 --url="http://localhost:6789" --contractAddress="0x43355c787c50b647c425f594b441d4bd75198888" --api = "getResultByTransactionID (45655c787c50b647c425f594b441d4bd75198888 )" --returnType=int --method=BidEvaluationResult 315 | ``` 316 | 317 | Finally we get bidding result, for example: 318 | ```bash 319 | 2 320 | ``` 321 | 322 | During the bidding, the bidders' input are secure and will not reveal to any peers by the power of MPC protocol. Here comes the end of privacy bidding. Enjoy :) 323 | -------------------------------------------------------------------------------- /privacy-contract/bidding/alice-data-node/alice-data-node.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /privacy-contract/bidding/alice-data-node/dependency-reduced-pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | net.platon.mpc 5 | alice-data-node 6 | 1.0-SNAPSHOT 7 | 8 | 9 | 10 | kr.motd.maven 11 | os-maven-plugin 12 | 1.4.1.Final 13 | 14 | 15 | 16 | 17 | maven-compiler-plugin 18 | 3.6.0 19 | 20 | 1.8 21 | 1.8 22 | utf8 23 | 24 | 25 | 26 | org.xolstice.maven.plugins 27 | protobuf-maven-plugin 28 | 0.5.0 29 | 30 | 31 | 32 | compile 33 | compile-custom 34 | 35 | 36 | 37 | 38 | com.google.protobuf:protoc:3.0.0:exe:${os.detected.classifier} 39 | grpc-java 40 | io.grpc:protoc-gen-grpc-java:1.0.0:exe:${os.detected.classifier} 41 | 42 | 43 | 44 | maven-shade-plugin 45 | 3.2.1 46 | 47 | 48 | package 49 | 50 | shade 51 | 52 | 53 | 54 | 55 | *:* 56 | 57 | META-INF/*.SF 58 | META-INF/*.DSA 59 | META-INF/*.RSA 60 | 61 | 62 | 63 | 64 | 65 | client.Client1 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | UTF-8 76 | 77 | 78 | -------------------------------------------------------------------------------- /privacy-contract/bidding/alice-data-node/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | net.platon.mpc 8 | alice-data-node 9 | jar 10 | 1.0 11 | 12 | 13 | 14 | UTF-8 15 | 16 | 17 | 18 | 19 | juzixmaven 20 | juzix maven 21 | https://sdk.platon.network/nexus/content/groups/public/ 22 | 23 | 24 | 25 | 26 | 27 | net.platon.mpc 28 | mpc-data-sdk 29 | 1.0 30 | 31 | 32 | 33 | 34 | 35 | 36 | kr.motd.maven 37 | os-maven-plugin 38 | 1.4.1.Final 39 | 40 | 41 | 42 | 43 | 44 | org.apache.maven.plugins 45 | maven-compiler-plugin 46 | 3.6.0 47 | 48 | 1.8 49 | 1.8 50 | utf8 51 | 52 | 53 | 54 | 55 | org.xolstice.maven.plugins 56 | protobuf-maven-plugin 57 | 0.5.0 58 | 59 | com.google.protobuf:protoc:3.0.0:exe:${os.detected.classifier} 60 | grpc-java 61 | io.grpc:protoc-gen-grpc-java:1.0.0:exe:${os.detected.classifier} 62 | 63 | 64 | 65 | 66 | compile 67 | compile-custom 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | org.apache.maven.plugins 76 | maven-shade-plugin 77 | 3.2.1 78 | 79 | 80 | package 81 | 82 | shade 83 | 84 | 85 | 86 | 87 | *:* 88 | 89 | META-INF/*.SF 90 | META-INF/*.DSA 91 | META-INF/*.RSA 92 | 93 | 94 | 95 | 96 | 97 | client.Client1 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | -------------------------------------------------------------------------------- /privacy-contract/bidding/alice-data-node/src/main/java/client/Client1.java: -------------------------------------------------------------------------------- 1 | package client; 2 | 3 | import net.platon.vm.sdk.client.ConfigInfo; 4 | import net.platon.vm.sdk.client.AppClient; 5 | 6 | public class Client1 { 7 | 8 | public static void main(String[] args) { 9 | (new AppClient(new ConfigInfo(args))).start(args); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /privacy-contract/bidding/alice-data-node/src/main/java/net/platon/vm/mpc/MPCBidEvaluation.java: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * may be some declaration here. 4 | */ 5 | package net.platon.vm.mpc; 6 | 7 | import net.platon.vm.sdk.client.*; 8 | import net.platon.vm.sdk.utils.JDBCUtil; 9 | 10 | import java.util.HashMap; 11 | import java.util.List; 12 | import java.util.Map; 13 | 14 | 15 | /** 16 | * Attention! This file was auto-generated, you just need to implement the "TODO SECTIONS". 17 | * The class name "MPCBidEvaluation" is just to named this file, you can rename "MPCBidEvaluation" what you like. 18 | * More details ref "MPCBidEvaluation-README.TXT". 19 | *

20 | * DIGEST: 21 | *

22 | * IR NAME: MPCBidEvaluation 23 | * IR HASH: 6d894588b21dd56da2a3b971a61b6201 24 | *

25 | * IR FUNC HASH(MD5) IR FUNC NAME IR FUNC PROT 26 | * 1d11e5749603f6fb0e21e611c9bec02f BidEvaluationResult BidEvaluationResult(Bidder,int) 27 | */ 28 | 29 | interface mpc_ii_6d894588b21dd56da2a3b971a61b6201 extends IIInterface { 30 | } 31 | 32 | public class MPCBidEvaluation implements mpc_ii_6d894588b21dd56da2a3b971a61b6201 { 33 | private HashMap funcInterfaces = new HashMap() {{ 34 | put("mpc_f_1d11e5749603f6fb0e21e611c9bec02f_01", new MPCBidEvaluation_BidEvaluationResult_Bidder_int_01()); 35 | put("mpc_f_1d11e5749603f6fb0e21e611c9bec02f_02", new MPCBidEvaluation_BidEvaluationResult_Bidder_int_02()); 36 | }}; 37 | 38 | public MpcCallbackInterface getInstance(String instance_hash) { 39 | if (funcInterfaces.containsKey(instance_hash)) { 40 | return funcInterfaces.get(instance_hash); 41 | } 42 | return null; 43 | } 44 | 45 | public HashMap getInstances() { 46 | return funcInterfaces; 47 | } 48 | 49 | abstract class MpcCallbackBase_6d894588b21dd56da2a3b971a61b6201 implements MpcCallbackInterface { 50 | public abstract byte[] inputImpl(final InputRequestPara para); 51 | 52 | public byte[] input(final InputRequestPara para) { 53 | // TODO: do what you want to do, before call inputImpl 54 | return inputImpl(para); 55 | } 56 | 57 | public void error(final InputRequestPara para, ErrorCode error) { 58 | // TODO: do what you want to do 59 | } 60 | 61 | public void result(final InputRequestPara para, final byte[] data) { 62 | // TODO: do what you want to do 63 | } 64 | } 65 | 66 | abstract class mpc_i_6d894588b21dd56da2a3b971a61b6201 extends MpcCallbackBase_6d894588b21dd56da2a3b971a61b6201 { 67 | } 68 | 69 | abstract class mpc_f_1d11e5749603f6fb0e21e611c9bec02f_01 extends mpc_i_6d894588b21dd56da2a3b971a61b6201 { 70 | public byte[] input_x_default() { 71 | return Data.Int32(0); 72 | } 73 | } 74 | 75 | abstract class mpc_f_1d11e5749603f6fb0e21e611c9bec02f_02 extends mpc_i_6d894588b21dd56da2a3b971a61b6201 { 76 | public byte[] input_x_default() { 77 | return network.platon.bidevaluation.BidEvaluation.Bidder.newBuilder().build().toByteArray(); 78 | } 79 | } 80 | 81 | 82 | /** 83 | * BidEvaluationResult(Bidder,int) 84 | */ 85 | final class MPCBidEvaluation_BidEvaluationResult_Bidder_int_01 extends mpc_f_1d11e5749603f6fb0e21e611c9bec02f_01 { 86 | public byte[] inputImpl(final InputRequestPara para) { 87 | network.platon.bidevaluation.BidEvaluation.Bidder.Builder builder = network.platon.bidevaluation.BidEvaluation.Bidder.newBuilder(); 88 | // TODO: assemble data 89 | 90 | builder.setA(10); 91 | builder.setB(50); 92 | builder.setC(20); 93 | return builder.build().toByteArray(); 94 | } 95 | } 96 | 97 | /** 98 | * BidEvaluationResult(Bidder,int) 99 | */ 100 | final class MPCBidEvaluation_BidEvaluationResult_Bidder_int_02 extends mpc_f_1d11e5749603f6fb0e21e611c9bec02f_02 { 101 | public byte[] inputImpl(final InputRequestPara para) { 102 | int ret_value = 0; 103 | // TODO: assemble data 104 | 105 | return Data.Int32(ret_value); 106 | } 107 | } 108 | 109 | } 110 | -------------------------------------------------------------------------------- /privacy-contract/bidding/alice-data-node/src/main/java/network/platon/bidevaluation/BidEvaluation.java: -------------------------------------------------------------------------------- 1 | // Generated by the protocol buffer compiler. DO NOT EDIT! 2 | // source: BidEvaluation.proto 3 | 4 | package network.platon.bidevaluation; 5 | 6 | public final class BidEvaluation { 7 | private BidEvaluation() {} 8 | public static void registerAllExtensions( 9 | com.google.protobuf.ExtensionRegistryLite registry) { 10 | } 11 | public interface BidderOrBuilder extends 12 | // @@protoc_insertion_point(interface_extends:BidEvaluation.Bidder) 13 | com.google.protobuf.MessageLiteOrBuilder { 14 | 15 | /** 16 | * int32 a = 1; 17 | */ 18 | int getA(); 19 | 20 | /** 21 | * int32 b = 2; 22 | */ 23 | int getB(); 24 | 25 | /** 26 | * int32 c = 3; 27 | */ 28 | int getC(); 29 | } 30 | /** 31 | * Protobuf type {@code BidEvaluation.Bidder} 32 | */ 33 | public static final class Bidder extends 34 | com.google.protobuf.GeneratedMessageLite< 35 | Bidder, Bidder.Builder> implements 36 | // @@protoc_insertion_point(message_implements:BidEvaluation.Bidder) 37 | BidderOrBuilder { 38 | private Bidder() { 39 | } 40 | public static final int A_FIELD_NUMBER = 1; 41 | private int a_; 42 | /** 43 | * int32 a = 1; 44 | */ 45 | public int getA() { 46 | return a_; 47 | } 48 | /** 49 | * int32 a = 1; 50 | */ 51 | private void setA(int value) { 52 | 53 | a_ = value; 54 | } 55 | /** 56 | * int32 a = 1; 57 | */ 58 | private void clearA() { 59 | 60 | a_ = 0; 61 | } 62 | 63 | public static final int B_FIELD_NUMBER = 2; 64 | private int b_; 65 | /** 66 | * int32 b = 2; 67 | */ 68 | public int getB() { 69 | return b_; 70 | } 71 | /** 72 | * int32 b = 2; 73 | */ 74 | private void setB(int value) { 75 | 76 | b_ = value; 77 | } 78 | /** 79 | * int32 b = 2; 80 | */ 81 | private void clearB() { 82 | 83 | b_ = 0; 84 | } 85 | 86 | public static final int C_FIELD_NUMBER = 3; 87 | private int c_; 88 | /** 89 | * int32 c = 3; 90 | */ 91 | public int getC() { 92 | return c_; 93 | } 94 | /** 95 | * int32 c = 3; 96 | */ 97 | private void setC(int value) { 98 | 99 | c_ = value; 100 | } 101 | /** 102 | * int32 c = 3; 103 | */ 104 | private void clearC() { 105 | 106 | c_ = 0; 107 | } 108 | 109 | public void writeTo(com.google.protobuf.CodedOutputStream output) 110 | throws java.io.IOException { 111 | if (a_ != 0) { 112 | output.writeInt32(1, a_); 113 | } 114 | if (b_ != 0) { 115 | output.writeInt32(2, b_); 116 | } 117 | if (c_ != 0) { 118 | output.writeInt32(3, c_); 119 | } 120 | unknownFields.writeTo(output); 121 | } 122 | 123 | public int getSerializedSize() { 124 | int size = memoizedSerializedSize; 125 | if (size != -1) return size; 126 | 127 | size = 0; 128 | if (a_ != 0) { 129 | size += com.google.protobuf.CodedOutputStream 130 | .computeInt32Size(1, a_); 131 | } 132 | if (b_ != 0) { 133 | size += com.google.protobuf.CodedOutputStream 134 | .computeInt32Size(2, b_); 135 | } 136 | if (c_ != 0) { 137 | size += com.google.protobuf.CodedOutputStream 138 | .computeInt32Size(3, c_); 139 | } 140 | size += unknownFields.getSerializedSize(); 141 | memoizedSerializedSize = size; 142 | return size; 143 | } 144 | 145 | public static network.platon.bidevaluation.BidEvaluation.Bidder parseFrom( 146 | java.nio.ByteBuffer data) 147 | throws com.google.protobuf.InvalidProtocolBufferException { 148 | return com.google.protobuf.GeneratedMessageLite.parseFrom( 149 | DEFAULT_INSTANCE, data); 150 | } 151 | public static network.platon.bidevaluation.BidEvaluation.Bidder parseFrom( 152 | java.nio.ByteBuffer data, 153 | com.google.protobuf.ExtensionRegistryLite extensionRegistry) 154 | throws com.google.protobuf.InvalidProtocolBufferException { 155 | return com.google.protobuf.GeneratedMessageLite.parseFrom( 156 | DEFAULT_INSTANCE, data, extensionRegistry); 157 | } 158 | public static network.platon.bidevaluation.BidEvaluation.Bidder parseFrom( 159 | com.google.protobuf.ByteString data) 160 | throws com.google.protobuf.InvalidProtocolBufferException { 161 | return com.google.protobuf.GeneratedMessageLite.parseFrom( 162 | DEFAULT_INSTANCE, data); 163 | } 164 | public static network.platon.bidevaluation.BidEvaluation.Bidder parseFrom( 165 | com.google.protobuf.ByteString data, 166 | com.google.protobuf.ExtensionRegistryLite extensionRegistry) 167 | throws com.google.protobuf.InvalidProtocolBufferException { 168 | return com.google.protobuf.GeneratedMessageLite.parseFrom( 169 | DEFAULT_INSTANCE, data, extensionRegistry); 170 | } 171 | public static network.platon.bidevaluation.BidEvaluation.Bidder parseFrom(byte[] data) 172 | throws com.google.protobuf.InvalidProtocolBufferException { 173 | return com.google.protobuf.GeneratedMessageLite.parseFrom( 174 | DEFAULT_INSTANCE, data); 175 | } 176 | public static network.platon.bidevaluation.BidEvaluation.Bidder parseFrom( 177 | byte[] data, 178 | com.google.protobuf.ExtensionRegistryLite extensionRegistry) 179 | throws com.google.protobuf.InvalidProtocolBufferException { 180 | return com.google.protobuf.GeneratedMessageLite.parseFrom( 181 | DEFAULT_INSTANCE, data, extensionRegistry); 182 | } 183 | public static network.platon.bidevaluation.BidEvaluation.Bidder parseFrom(java.io.InputStream input) 184 | throws java.io.IOException { 185 | return com.google.protobuf.GeneratedMessageLite.parseFrom( 186 | DEFAULT_INSTANCE, input); 187 | } 188 | public static network.platon.bidevaluation.BidEvaluation.Bidder parseFrom( 189 | java.io.InputStream input, 190 | com.google.protobuf.ExtensionRegistryLite extensionRegistry) 191 | throws java.io.IOException { 192 | return com.google.protobuf.GeneratedMessageLite.parseFrom( 193 | DEFAULT_INSTANCE, input, extensionRegistry); 194 | } 195 | public static network.platon.bidevaluation.BidEvaluation.Bidder parseDelimitedFrom(java.io.InputStream input) 196 | throws java.io.IOException { 197 | return parseDelimitedFrom(DEFAULT_INSTANCE, input); 198 | } 199 | public static network.platon.bidevaluation.BidEvaluation.Bidder parseDelimitedFrom( 200 | java.io.InputStream input, 201 | com.google.protobuf.ExtensionRegistryLite extensionRegistry) 202 | throws java.io.IOException { 203 | return parseDelimitedFrom(DEFAULT_INSTANCE, input, extensionRegistry); 204 | } 205 | public static network.platon.bidevaluation.BidEvaluation.Bidder parseFrom( 206 | com.google.protobuf.CodedInputStream input) 207 | throws java.io.IOException { 208 | return com.google.protobuf.GeneratedMessageLite.parseFrom( 209 | DEFAULT_INSTANCE, input); 210 | } 211 | public static network.platon.bidevaluation.BidEvaluation.Bidder parseFrom( 212 | com.google.protobuf.CodedInputStream input, 213 | com.google.protobuf.ExtensionRegistryLite extensionRegistry) 214 | throws java.io.IOException { 215 | return com.google.protobuf.GeneratedMessageLite.parseFrom( 216 | DEFAULT_INSTANCE, input, extensionRegistry); 217 | } 218 | 219 | public static Builder newBuilder() { 220 | return (Builder) DEFAULT_INSTANCE.createBuilder(); 221 | } 222 | public static Builder newBuilder(network.platon.bidevaluation.BidEvaluation.Bidder prototype) { 223 | return (Builder) DEFAULT_INSTANCE.createBuilder(prototype); 224 | } 225 | 226 | /** 227 | * Protobuf type {@code BidEvaluation.Bidder} 228 | */ 229 | public static final class Builder extends 230 | com.google.protobuf.GeneratedMessageLite.Builder< 231 | network.platon.bidevaluation.BidEvaluation.Bidder, Builder> implements 232 | // @@protoc_insertion_point(builder_implements:BidEvaluation.Bidder) 233 | network.platon.bidevaluation.BidEvaluation.BidderOrBuilder { 234 | // Construct using network.platon.bidevaluation.BidEvaluation.Bidder.newBuilder() 235 | private Builder() { 236 | super(DEFAULT_INSTANCE); 237 | } 238 | 239 | 240 | /** 241 | * int32 a = 1; 242 | */ 243 | public int getA() { 244 | return instance.getA(); 245 | } 246 | /** 247 | * int32 a = 1; 248 | */ 249 | public Builder setA(int value) { 250 | copyOnWrite(); 251 | instance.setA(value); 252 | return this; 253 | } 254 | /** 255 | * int32 a = 1; 256 | */ 257 | public Builder clearA() { 258 | copyOnWrite(); 259 | instance.clearA(); 260 | return this; 261 | } 262 | 263 | /** 264 | * int32 b = 2; 265 | */ 266 | public int getB() { 267 | return instance.getB(); 268 | } 269 | /** 270 | * int32 b = 2; 271 | */ 272 | public Builder setB(int value) { 273 | copyOnWrite(); 274 | instance.setB(value); 275 | return this; 276 | } 277 | /** 278 | * int32 b = 2; 279 | */ 280 | public Builder clearB() { 281 | copyOnWrite(); 282 | instance.clearB(); 283 | return this; 284 | } 285 | 286 | /** 287 | * int32 c = 3; 288 | */ 289 | public int getC() { 290 | return instance.getC(); 291 | } 292 | /** 293 | * int32 c = 3; 294 | */ 295 | public Builder setC(int value) { 296 | copyOnWrite(); 297 | instance.setC(value); 298 | return this; 299 | } 300 | /** 301 | * int32 c = 3; 302 | */ 303 | public Builder clearC() { 304 | copyOnWrite(); 305 | instance.clearC(); 306 | return this; 307 | } 308 | 309 | // @@protoc_insertion_point(builder_scope:BidEvaluation.Bidder) 310 | } 311 | @java.lang.SuppressWarnings({"unchecked", "fallthrough"}) 312 | protected final java.lang.Object dynamicMethod( 313 | com.google.protobuf.GeneratedMessageLite.MethodToInvoke method, 314 | java.lang.Object arg0, java.lang.Object arg1) { 315 | switch (method) { 316 | case NEW_MUTABLE_INSTANCE: { 317 | return new network.platon.bidevaluation.BidEvaluation.Bidder(); 318 | } 319 | case IS_INITIALIZED: { 320 | return DEFAULT_INSTANCE; 321 | } 322 | case MAKE_IMMUTABLE: { 323 | return null; 324 | } 325 | case NEW_BUILDER: { 326 | return new Builder(); 327 | } 328 | case VISIT: { 329 | Visitor visitor = (Visitor) arg0; 330 | network.platon.bidevaluation.BidEvaluation.Bidder other = (network.platon.bidevaluation.BidEvaluation.Bidder) arg1; 331 | a_ = visitor.visitInt(a_ != 0, a_, 332 | other.a_ != 0, other.a_); 333 | b_ = visitor.visitInt(b_ != 0, b_, 334 | other.b_ != 0, other.b_); 335 | c_ = visitor.visitInt(c_ != 0, c_, 336 | other.c_ != 0, other.c_); 337 | if (visitor == com.google.protobuf.GeneratedMessageLite.MergeFromVisitor 338 | .INSTANCE) { 339 | } 340 | return this; 341 | } 342 | case MERGE_FROM_STREAM: { 343 | com.google.protobuf.CodedInputStream input = 344 | (com.google.protobuf.CodedInputStream) arg0; 345 | com.google.protobuf.ExtensionRegistryLite extensionRegistry = 346 | (com.google.protobuf.ExtensionRegistryLite) arg1; 347 | if (extensionRegistry == null) { 348 | throw new java.lang.NullPointerException(); 349 | } 350 | try { 351 | boolean done = false; 352 | while (!done) { 353 | int tag = input.readTag(); 354 | switch (tag) { 355 | case 0: 356 | done = true; 357 | break; 358 | default: { 359 | if (!parseUnknownField(tag, input)) { 360 | done = true; 361 | } 362 | break; 363 | } 364 | case 8: { 365 | 366 | a_ = input.readInt32(); 367 | break; 368 | } 369 | case 16: { 370 | 371 | b_ = input.readInt32(); 372 | break; 373 | } 374 | case 24: { 375 | 376 | c_ = input.readInt32(); 377 | break; 378 | } 379 | } 380 | } 381 | } catch (com.google.protobuf.InvalidProtocolBufferException e) { 382 | throw new RuntimeException(e.setUnfinishedMessage(this)); 383 | } catch (java.io.IOException e) { 384 | throw new RuntimeException( 385 | new com.google.protobuf.InvalidProtocolBufferException( 386 | e.getMessage()).setUnfinishedMessage(this)); 387 | } finally { 388 | } 389 | } 390 | // fall through 391 | case GET_DEFAULT_INSTANCE: { 392 | return DEFAULT_INSTANCE; 393 | } 394 | case GET_PARSER: { 395 | if (PARSER == null) { synchronized (network.platon.bidevaluation.BidEvaluation.Bidder.class) { 396 | if (PARSER == null) { 397 | PARSER = new DefaultInstanceBasedParser(DEFAULT_INSTANCE); 398 | } 399 | } 400 | } 401 | return PARSER; 402 | } 403 | case GET_MEMOIZED_IS_INITIALIZED: { 404 | return (byte) 1; 405 | } 406 | case SET_MEMOIZED_IS_INITIALIZED: { 407 | return null; 408 | } 409 | } 410 | throw new UnsupportedOperationException(); 411 | } 412 | 413 | 414 | // @@protoc_insertion_point(class_scope:BidEvaluation.Bidder) 415 | private static final network.platon.bidevaluation.BidEvaluation.Bidder DEFAULT_INSTANCE; 416 | static { 417 | DEFAULT_INSTANCE = new Bidder(); 418 | DEFAULT_INSTANCE.makeImmutable(); 419 | } 420 | 421 | public static network.platon.bidevaluation.BidEvaluation.Bidder getDefaultInstance() { 422 | return DEFAULT_INSTANCE; 423 | } 424 | 425 | private static volatile com.google.protobuf.Parser PARSER; 426 | 427 | public static com.google.protobuf.Parser parser() { 428 | return DEFAULT_INSTANCE.getParserForType(); 429 | } 430 | } 431 | 432 | 433 | static { 434 | } 435 | 436 | // @@protoc_insertion_point(outer_class_scope) 437 | } 438 | -------------------------------------------------------------------------------- /privacy-contract/bidding/bob-data-node/bob-data-node.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /privacy-contract/bidding/bob-data-node/dependency-reduced-pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | net.platon.mpc 5 | bob-data-node 6 | 1.0-SNAPSHOT 7 | 8 | 9 | 10 | kr.motd.maven 11 | os-maven-plugin 12 | 1.4.1.Final 13 | 14 | 15 | 16 | 17 | maven-compiler-plugin 18 | 3.6.0 19 | 20 | 1.8 21 | 1.8 22 | utf8 23 | 24 | 25 | 26 | org.xolstice.maven.plugins 27 | protobuf-maven-plugin 28 | 0.5.0 29 | 30 | 31 | 32 | compile 33 | compile-custom 34 | 35 | 36 | 37 | 38 | com.google.protobuf:protoc:3.0.0:exe:${os.detected.classifier} 39 | grpc-java 40 | io.grpc:protoc-gen-grpc-java:1.0.0:exe:${os.detected.classifier} 41 | 42 | 43 | 44 | maven-shade-plugin 45 | 3.2.1 46 | 47 | 48 | package 49 | 50 | shade 51 | 52 | 53 | 54 | 55 | *:* 56 | 57 | META-INF/*.SF 58 | META-INF/*.DSA 59 | META-INF/*.RSA 60 | 61 | 62 | 63 | 64 | 65 | client.Client1 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | UTF-8 76 | 77 | 78 | -------------------------------------------------------------------------------- /privacy-contract/bidding/bob-data-node/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | net.platon.mpc 8 | bob-data-node 9 | jar 10 | 1.0 11 | 12 | 13 | 14 | UTF-8 15 | 16 | 17 | 18 | 19 | 20 | juzixmaven 21 | juzix maven 22 | https://sdk.platon.network/nexus/content/groups/public/ 23 | 24 | 25 | 26 | 27 | 28 | net.platon.mpc 29 | mpc-data-sdk 30 | 1.0 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | kr.motd.maven 39 | os-maven-plugin 40 | 1.4.1.Final 41 | 42 | 43 | 44 | 45 | 46 | org.apache.maven.plugins 47 | maven-compiler-plugin 48 | 3.6.0 49 | 50 | 1.8 51 | 1.8 52 | utf8 53 | 54 | 55 | 56 | 57 | org.xolstice.maven.plugins 58 | protobuf-maven-plugin 59 | 0.5.0 60 | 61 | com.google.protobuf:protoc:3.0.0:exe:${os.detected.classifier} 62 | grpc-java 63 | io.grpc:protoc-gen-grpc-java:1.0.0:exe:${os.detected.classifier} 64 | 65 | 66 | 67 | 68 | compile 69 | compile-custom 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | org.apache.maven.plugins 78 | maven-shade-plugin 79 | 3.2.1 80 | 81 | 82 | package 83 | 84 | shade 85 | 86 | 87 | 88 | 89 | *:* 90 | 91 | META-INF/*.SF 92 | META-INF/*.DSA 93 | META-INF/*.RSA 94 | 95 | 96 | 97 | 98 | 99 | client.Client1 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | -------------------------------------------------------------------------------- /privacy-contract/bidding/bob-data-node/src/main/java/client/Client1.java: -------------------------------------------------------------------------------- 1 | package client; 2 | 3 | import net.platon.vm.sdk.client.ConfigInfo; 4 | import net.platon.vm.sdk.client.AppClient; 5 | 6 | public class Client1 { 7 | 8 | public static void main(String[] args) { 9 | (new AppClient(new ConfigInfo(args))).start(args); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /privacy-contract/bidding/bob-data-node/src/main/java/net/platon/vm/mpc/MPCBidEvaluation.java: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * may be some declaration here. 4 | */ 5 | package net.platon.vm.mpc; 6 | 7 | import net.platon.vm.sdk.client.*; 8 | import net.platon.vm.sdk.utils.JDBCUtil; 9 | 10 | import java.util.HashMap; 11 | import java.util.List; 12 | import java.util.Map; 13 | 14 | 15 | /** 16 | * Attention! This file was auto-generated, you just need to implement the "TODO SECTIONS". 17 | * The class name "MPCBidEvaluation" is just to named this file, you can rename "MPCBidEvaluation" what you like. 18 | * More details ref "MPCBidEvaluation-README.TXT". 19 | *

20 | * DIGEST: 21 | *

22 | * IR NAME: MPCBidEvaluation 23 | * IR HASH: 6d894588b21dd56da2a3b971a61b6201 24 | *

25 | * IR FUNC HASH(MD5) IR FUNC NAME IR FUNC PROT 26 | * 1d11e5749603f6fb0e21e611c9bec02f BidEvaluationResult BidEvaluationResult(Bidder,int) 27 | */ 28 | 29 | interface mpc_ii_6d894588b21dd56da2a3b971a61b6201 extends IIInterface { 30 | } 31 | 32 | public class MPCBidEvaluation implements mpc_ii_6d894588b21dd56da2a3b971a61b6201 { 33 | private HashMap funcInterfaces = new HashMap() {{ 34 | put("mpc_f_1d11e5749603f6fb0e21e611c9bec02f_01", new MPCBidEvaluation_BidEvaluationResult_Bidder_int_01()); 35 | put("mpc_f_1d11e5749603f6fb0e21e611c9bec02f_02", new MPCBidEvaluation_BidEvaluationResult_Bidder_int_02()); 36 | }}; 37 | 38 | public MpcCallbackInterface getInstance(String instance_hash) { 39 | if (funcInterfaces.containsKey(instance_hash)) { 40 | return funcInterfaces.get(instance_hash); 41 | } 42 | return null; 43 | } 44 | 45 | public HashMap getInstances() { 46 | return funcInterfaces; 47 | } 48 | 49 | abstract class MpcCallbackBase_6d894588b21dd56da2a3b971a61b6201 implements MpcCallbackInterface { 50 | public abstract byte[] inputImpl(final InputRequestPara para); 51 | 52 | public byte[] input(final InputRequestPara para) { 53 | // TODO: do what you want to do, before call inputImpl 54 | return inputImpl(para); 55 | } 56 | 57 | public void error(final InputRequestPara para, ErrorCode error) { 58 | // TODO: do what you want to do 59 | } 60 | 61 | public void result(final InputRequestPara para, final byte[] data) { 62 | // TODO: do what you want to do 63 | } 64 | } 65 | 66 | abstract class mpc_i_6d894588b21dd56da2a3b971a61b6201 extends MpcCallbackBase_6d894588b21dd56da2a3b971a61b6201 { 67 | } 68 | 69 | abstract class mpc_f_1d11e5749603f6fb0e21e611c9bec02f_01 extends mpc_i_6d894588b21dd56da2a3b971a61b6201 { 70 | public byte[] input_x_default() { 71 | return Data.Int32(0); 72 | } 73 | } 74 | 75 | abstract class mpc_f_1d11e5749603f6fb0e21e611c9bec02f_02 extends mpc_i_6d894588b21dd56da2a3b971a61b6201 { 76 | public byte[] input_x_default() { 77 | return network.platon.bidevaluation.BidEvaluation.Bidder.newBuilder().build().toByteArray(); 78 | } 79 | } 80 | 81 | 82 | /** 83 | * BidEvaluationResult(Bidder,int) 84 | */ 85 | final class MPCBidEvaluation_BidEvaluationResult_Bidder_int_01 extends mpc_f_1d11e5749603f6fb0e21e611c9bec02f_01 { 86 | public byte[] inputImpl(final InputRequestPara para) { 87 | network.platon.bidevaluation.BidEvaluation.Bidder.Builder builder = network.platon.bidevaluation.BidEvaluation.Bidder.newBuilder(); 88 | // TODO: assemble data 89 | 90 | return builder.build().toByteArray(); 91 | } 92 | } 93 | 94 | /** 95 | * BidEvaluationResult(Bidder,int) 96 | */ 97 | final class MPCBidEvaluation_BidEvaluationResult_Bidder_int_02 extends mpc_f_1d11e5749603f6fb0e21e611c9bec02f_02 { 98 | public byte[] inputImpl(final InputRequestPara para) { 99 | int ret_value = 0; 100 | // TODO: assemble data 101 | 102 | ret_value = 50; 103 | 104 | return Data.Int32(ret_value); 105 | } 106 | } 107 | 108 | } 109 | -------------------------------------------------------------------------------- /privacy-contract/bidding/bob-data-node/src/main/java/network/platon/bidevaluation/BidEvaluation.java: -------------------------------------------------------------------------------- 1 | // Generated by the protocol buffer compiler. DO NOT EDIT! 2 | // source: BidEvaluation.proto 3 | 4 | package network.platon.bidevaluation; 5 | 6 | public final class BidEvaluation { 7 | private BidEvaluation() {} 8 | public static void registerAllExtensions( 9 | com.google.protobuf.ExtensionRegistryLite registry) { 10 | } 11 | public interface BidderOrBuilder extends 12 | // @@protoc_insertion_point(interface_extends:BidEvaluation.Bidder) 13 | com.google.protobuf.MessageLiteOrBuilder { 14 | 15 | /** 16 | * int32 a = 1; 17 | */ 18 | int getA(); 19 | 20 | /** 21 | * int32 b = 2; 22 | */ 23 | int getB(); 24 | 25 | /** 26 | * int32 c = 3; 27 | */ 28 | int getC(); 29 | } 30 | /** 31 | * Protobuf type {@code BidEvaluation.Bidder} 32 | */ 33 | public static final class Bidder extends 34 | com.google.protobuf.GeneratedMessageLite< 35 | Bidder, Bidder.Builder> implements 36 | // @@protoc_insertion_point(message_implements:BidEvaluation.Bidder) 37 | BidderOrBuilder { 38 | private Bidder() { 39 | } 40 | public static final int A_FIELD_NUMBER = 1; 41 | private int a_; 42 | /** 43 | * int32 a = 1; 44 | */ 45 | public int getA() { 46 | return a_; 47 | } 48 | /** 49 | * int32 a = 1; 50 | */ 51 | private void setA(int value) { 52 | 53 | a_ = value; 54 | } 55 | /** 56 | * int32 a = 1; 57 | */ 58 | private void clearA() { 59 | 60 | a_ = 0; 61 | } 62 | 63 | public static final int B_FIELD_NUMBER = 2; 64 | private int b_; 65 | /** 66 | * int32 b = 2; 67 | */ 68 | public int getB() { 69 | return b_; 70 | } 71 | /** 72 | * int32 b = 2; 73 | */ 74 | private void setB(int value) { 75 | 76 | b_ = value; 77 | } 78 | /** 79 | * int32 b = 2; 80 | */ 81 | private void clearB() { 82 | 83 | b_ = 0; 84 | } 85 | 86 | public static final int C_FIELD_NUMBER = 3; 87 | private int c_; 88 | /** 89 | * int32 c = 3; 90 | */ 91 | public int getC() { 92 | return c_; 93 | } 94 | /** 95 | * int32 c = 3; 96 | */ 97 | private void setC(int value) { 98 | 99 | c_ = value; 100 | } 101 | /** 102 | * int32 c = 3; 103 | */ 104 | private void clearC() { 105 | 106 | c_ = 0; 107 | } 108 | 109 | public void writeTo(com.google.protobuf.CodedOutputStream output) 110 | throws java.io.IOException { 111 | if (a_ != 0) { 112 | output.writeInt32(1, a_); 113 | } 114 | if (b_ != 0) { 115 | output.writeInt32(2, b_); 116 | } 117 | if (c_ != 0) { 118 | output.writeInt32(3, c_); 119 | } 120 | unknownFields.writeTo(output); 121 | } 122 | 123 | public int getSerializedSize() { 124 | int size = memoizedSerializedSize; 125 | if (size != -1) return size; 126 | 127 | size = 0; 128 | if (a_ != 0) { 129 | size += com.google.protobuf.CodedOutputStream 130 | .computeInt32Size(1, a_); 131 | } 132 | if (b_ != 0) { 133 | size += com.google.protobuf.CodedOutputStream 134 | .computeInt32Size(2, b_); 135 | } 136 | if (c_ != 0) { 137 | size += com.google.protobuf.CodedOutputStream 138 | .computeInt32Size(3, c_); 139 | } 140 | size += unknownFields.getSerializedSize(); 141 | memoizedSerializedSize = size; 142 | return size; 143 | } 144 | 145 | public static network.platon.bidevaluation.BidEvaluation.Bidder parseFrom( 146 | java.nio.ByteBuffer data) 147 | throws com.google.protobuf.InvalidProtocolBufferException { 148 | return com.google.protobuf.GeneratedMessageLite.parseFrom( 149 | DEFAULT_INSTANCE, data); 150 | } 151 | public static network.platon.bidevaluation.BidEvaluation.Bidder parseFrom( 152 | java.nio.ByteBuffer data, 153 | com.google.protobuf.ExtensionRegistryLite extensionRegistry) 154 | throws com.google.protobuf.InvalidProtocolBufferException { 155 | return com.google.protobuf.GeneratedMessageLite.parseFrom( 156 | DEFAULT_INSTANCE, data, extensionRegistry); 157 | } 158 | public static network.platon.bidevaluation.BidEvaluation.Bidder parseFrom( 159 | com.google.protobuf.ByteString data) 160 | throws com.google.protobuf.InvalidProtocolBufferException { 161 | return com.google.protobuf.GeneratedMessageLite.parseFrom( 162 | DEFAULT_INSTANCE, data); 163 | } 164 | public static network.platon.bidevaluation.BidEvaluation.Bidder parseFrom( 165 | com.google.protobuf.ByteString data, 166 | com.google.protobuf.ExtensionRegistryLite extensionRegistry) 167 | throws com.google.protobuf.InvalidProtocolBufferException { 168 | return com.google.protobuf.GeneratedMessageLite.parseFrom( 169 | DEFAULT_INSTANCE, data, extensionRegistry); 170 | } 171 | public static network.platon.bidevaluation.BidEvaluation.Bidder parseFrom(byte[] data) 172 | throws com.google.protobuf.InvalidProtocolBufferException { 173 | return com.google.protobuf.GeneratedMessageLite.parseFrom( 174 | DEFAULT_INSTANCE, data); 175 | } 176 | public static network.platon.bidevaluation.BidEvaluation.Bidder parseFrom( 177 | byte[] data, 178 | com.google.protobuf.ExtensionRegistryLite extensionRegistry) 179 | throws com.google.protobuf.InvalidProtocolBufferException { 180 | return com.google.protobuf.GeneratedMessageLite.parseFrom( 181 | DEFAULT_INSTANCE, data, extensionRegistry); 182 | } 183 | public static network.platon.bidevaluation.BidEvaluation.Bidder parseFrom(java.io.InputStream input) 184 | throws java.io.IOException { 185 | return com.google.protobuf.GeneratedMessageLite.parseFrom( 186 | DEFAULT_INSTANCE, input); 187 | } 188 | public static network.platon.bidevaluation.BidEvaluation.Bidder parseFrom( 189 | java.io.InputStream input, 190 | com.google.protobuf.ExtensionRegistryLite extensionRegistry) 191 | throws java.io.IOException { 192 | return com.google.protobuf.GeneratedMessageLite.parseFrom( 193 | DEFAULT_INSTANCE, input, extensionRegistry); 194 | } 195 | public static network.platon.bidevaluation.BidEvaluation.Bidder parseDelimitedFrom(java.io.InputStream input) 196 | throws java.io.IOException { 197 | return parseDelimitedFrom(DEFAULT_INSTANCE, input); 198 | } 199 | public static network.platon.bidevaluation.BidEvaluation.Bidder parseDelimitedFrom( 200 | java.io.InputStream input, 201 | com.google.protobuf.ExtensionRegistryLite extensionRegistry) 202 | throws java.io.IOException { 203 | return parseDelimitedFrom(DEFAULT_INSTANCE, input, extensionRegistry); 204 | } 205 | public static network.platon.bidevaluation.BidEvaluation.Bidder parseFrom( 206 | com.google.protobuf.CodedInputStream input) 207 | throws java.io.IOException { 208 | return com.google.protobuf.GeneratedMessageLite.parseFrom( 209 | DEFAULT_INSTANCE, input); 210 | } 211 | public static network.platon.bidevaluation.BidEvaluation.Bidder parseFrom( 212 | com.google.protobuf.CodedInputStream input, 213 | com.google.protobuf.ExtensionRegistryLite extensionRegistry) 214 | throws java.io.IOException { 215 | return com.google.protobuf.GeneratedMessageLite.parseFrom( 216 | DEFAULT_INSTANCE, input, extensionRegistry); 217 | } 218 | 219 | public static Builder newBuilder() { 220 | return (Builder) DEFAULT_INSTANCE.createBuilder(); 221 | } 222 | public static Builder newBuilder(network.platon.bidevaluation.BidEvaluation.Bidder prototype) { 223 | return (Builder) DEFAULT_INSTANCE.createBuilder(prototype); 224 | } 225 | 226 | /** 227 | * Protobuf type {@code BidEvaluation.Bidder} 228 | */ 229 | public static final class Builder extends 230 | com.google.protobuf.GeneratedMessageLite.Builder< 231 | network.platon.bidevaluation.BidEvaluation.Bidder, Builder> implements 232 | // @@protoc_insertion_point(builder_implements:BidEvaluation.Bidder) 233 | network.platon.bidevaluation.BidEvaluation.BidderOrBuilder { 234 | // Construct using network.platon.bidevaluation.BidEvaluation.Bidder.newBuilder() 235 | private Builder() { 236 | super(DEFAULT_INSTANCE); 237 | } 238 | 239 | 240 | /** 241 | * int32 a = 1; 242 | */ 243 | public int getA() { 244 | return instance.getA(); 245 | } 246 | /** 247 | * int32 a = 1; 248 | */ 249 | public Builder setA(int value) { 250 | copyOnWrite(); 251 | instance.setA(value); 252 | return this; 253 | } 254 | /** 255 | * int32 a = 1; 256 | */ 257 | public Builder clearA() { 258 | copyOnWrite(); 259 | instance.clearA(); 260 | return this; 261 | } 262 | 263 | /** 264 | * int32 b = 2; 265 | */ 266 | public int getB() { 267 | return instance.getB(); 268 | } 269 | /** 270 | * int32 b = 2; 271 | */ 272 | public Builder setB(int value) { 273 | copyOnWrite(); 274 | instance.setB(value); 275 | return this; 276 | } 277 | /** 278 | * int32 b = 2; 279 | */ 280 | public Builder clearB() { 281 | copyOnWrite(); 282 | instance.clearB(); 283 | return this; 284 | } 285 | 286 | /** 287 | * int32 c = 3; 288 | */ 289 | public int getC() { 290 | return instance.getC(); 291 | } 292 | /** 293 | * int32 c = 3; 294 | */ 295 | public Builder setC(int value) { 296 | copyOnWrite(); 297 | instance.setC(value); 298 | return this; 299 | } 300 | /** 301 | * int32 c = 3; 302 | */ 303 | public Builder clearC() { 304 | copyOnWrite(); 305 | instance.clearC(); 306 | return this; 307 | } 308 | 309 | // @@protoc_insertion_point(builder_scope:BidEvaluation.Bidder) 310 | } 311 | @java.lang.SuppressWarnings({"unchecked", "fallthrough"}) 312 | protected final java.lang.Object dynamicMethod( 313 | com.google.protobuf.GeneratedMessageLite.MethodToInvoke method, 314 | java.lang.Object arg0, java.lang.Object arg1) { 315 | switch (method) { 316 | case NEW_MUTABLE_INSTANCE: { 317 | return new network.platon.bidevaluation.BidEvaluation.Bidder(); 318 | } 319 | case IS_INITIALIZED: { 320 | return DEFAULT_INSTANCE; 321 | } 322 | case MAKE_IMMUTABLE: { 323 | return null; 324 | } 325 | case NEW_BUILDER: { 326 | return new Builder(); 327 | } 328 | case VISIT: { 329 | Visitor visitor = (Visitor) arg0; 330 | network.platon.bidevaluation.BidEvaluation.Bidder other = (network.platon.bidevaluation.BidEvaluation.Bidder) arg1; 331 | a_ = visitor.visitInt(a_ != 0, a_, 332 | other.a_ != 0, other.a_); 333 | b_ = visitor.visitInt(b_ != 0, b_, 334 | other.b_ != 0, other.b_); 335 | c_ = visitor.visitInt(c_ != 0, c_, 336 | other.c_ != 0, other.c_); 337 | if (visitor == com.google.protobuf.GeneratedMessageLite.MergeFromVisitor 338 | .INSTANCE) { 339 | } 340 | return this; 341 | } 342 | case MERGE_FROM_STREAM: { 343 | com.google.protobuf.CodedInputStream input = 344 | (com.google.protobuf.CodedInputStream) arg0; 345 | com.google.protobuf.ExtensionRegistryLite extensionRegistry = 346 | (com.google.protobuf.ExtensionRegistryLite) arg1; 347 | if (extensionRegistry == null) { 348 | throw new java.lang.NullPointerException(); 349 | } 350 | try { 351 | boolean done = false; 352 | while (!done) { 353 | int tag = input.readTag(); 354 | switch (tag) { 355 | case 0: 356 | done = true; 357 | break; 358 | default: { 359 | if (!parseUnknownField(tag, input)) { 360 | done = true; 361 | } 362 | break; 363 | } 364 | case 8: { 365 | 366 | a_ = input.readInt32(); 367 | break; 368 | } 369 | case 16: { 370 | 371 | b_ = input.readInt32(); 372 | break; 373 | } 374 | case 24: { 375 | 376 | c_ = input.readInt32(); 377 | break; 378 | } 379 | } 380 | } 381 | } catch (com.google.protobuf.InvalidProtocolBufferException e) { 382 | throw new RuntimeException(e.setUnfinishedMessage(this)); 383 | } catch (java.io.IOException e) { 384 | throw new RuntimeException( 385 | new com.google.protobuf.InvalidProtocolBufferException( 386 | e.getMessage()).setUnfinishedMessage(this)); 387 | } finally { 388 | } 389 | } 390 | // fall through 391 | case GET_DEFAULT_INSTANCE: { 392 | return DEFAULT_INSTANCE; 393 | } 394 | case GET_PARSER: { 395 | if (PARSER == null) { synchronized (network.platon.bidevaluation.BidEvaluation.Bidder.class) { 396 | if (PARSER == null) { 397 | PARSER = new DefaultInstanceBasedParser(DEFAULT_INSTANCE); 398 | } 399 | } 400 | } 401 | return PARSER; 402 | } 403 | case GET_MEMOIZED_IS_INITIALIZED: { 404 | return (byte) 1; 405 | } 406 | case SET_MEMOIZED_IS_INITIALIZED: { 407 | return null; 408 | } 409 | } 410 | throw new UnsupportedOperationException(); 411 | } 412 | 413 | 414 | // @@protoc_insertion_point(class_scope:BidEvaluation.Bidder) 415 | private static final network.platon.bidevaluation.BidEvaluation.Bidder DEFAULT_INSTANCE; 416 | static { 417 | DEFAULT_INSTANCE = new Bidder(); 418 | DEFAULT_INSTANCE.makeImmutable(); 419 | } 420 | 421 | public static network.platon.bidevaluation.BidEvaluation.Bidder getDefaultInstance() { 422 | return DEFAULT_INSTANCE; 423 | } 424 | 425 | private static volatile com.google.protobuf.Parser PARSER; 426 | 427 | public static com.google.protobuf.Parser parser() { 428 | return DEFAULT_INSTANCE.getParserForType(); 429 | } 430 | } 431 | 432 | 433 | static { 434 | } 435 | 436 | // @@protoc_insertion_point(outer_class_scope) 437 | } 438 | -------------------------------------------------------------------------------- /privacy-contract/bidding/cfg.client1.linux.config: -------------------------------------------------------------------------------- 1 | # 2 | # The client reads this property to create the reference to the 3 | # "TaskCallback" object in the server. 4 | # 5 | TaskCallback.Proxy=tasksession:default -h localhsot -p 10001 6 | 7 | 8 | -------------------------------------------------------------------------------- /privacy-contract/bidding/cfg.client2.linux.config: -------------------------------------------------------------------------------- 1 | # 2 | # The client reads this property to create the reference to the 3 | # "TaskCallback" object in the server. 4 | # 5 | TaskCallback.Proxy=tasksession:default -h localhost -p 10002 6 | 7 | -------------------------------------------------------------------------------- /privacy-contract/bidding/contract/BidEvaluation.cpp: -------------------------------------------------------------------------------- 1 | #include "integer.h" 2 | 3 | #include "code/BidEvaluation.pb.h" 4 | using namespace BidEvaluation; 5 | 6 | /* 7 | Alice a,b,c 8 | Bob p 9 | 10 | plang64.exe -config config.json -I. -Iinclude -Icode BidEvaluation.cpp -protobuf-cc code/BidEvaluation.pb.cc -o code/BidEvaluation.cpp.ll -mpcc code/BidEvaluation.mpcc.cpp 11 | 12 | mkdir -p code 13 | protoc --cpp_out=./code BidEvaluation.proto 14 | protoc --java_out=./code BidEvaluation.proto 15 | plang -config config.json -I. -Iinclude -Icode BidEvaluation.cpp -protobuf-cc code/BidEvaluation.pb.cc -protobuf-java code/network/platon/bidevaluation/BidEvaluation.java -o code/BidEvaluation.cpp.ll -mpcc code/BidEvaluation.mpcc.cpp 16 | 17 | */ 18 | int BidEvaluationResult(Bidder bidder, int price) { 19 | printf("Bidder: %d, %d, %d\n", bidder.a(), bidder.b(), bidder.c()); 20 | printf(" price: %d\n", price); 21 | 22 | emp::Integer _a(bidder.a(), emp::ALICE); 23 | emp::Integer _b(bidder.b(), emp::ALICE); 24 | emp::Integer _c(bidder.c(), emp::ALICE); 25 | 26 | emp::Integer _p(price, emp::BOB); 27 | 28 | // algorithm 29 | emp::Integer _y = (_a + _b + _c) / 3; 30 | emp::Integer _z = (_y + _p) / 2; 31 | 32 | emp::Integer arr[3] = {_a,_b,_c}; 33 | int idx[3] = {1,2,3}; 34 | if(!(arr[1].geq(arr[0]).reveal())) {emp::Integer t=arr[0];arr[0]=arr[1];arr[1]=t; int i=idx[0];idx[0]=idx[1];idx[1]=i;} 35 | if(!(arr[2].geq(arr[1]).reveal())) {emp::Integer t=arr[1];arr[1]=arr[2];arr[2]=t; int i=idx[1];idx[1]=idx[2];idx[2]=i;} 36 | if(!(arr[1].geq(arr[0]).reveal())) {emp::Integer t=arr[0];arr[0]=arr[1];arr[1]=t; int i=idx[0];idx[0]=idx[1];idx[1]=i;} 37 | 38 | int i; 39 | for (i = 0; i<3; i++){ 40 | if (!(_z.geq(arr[i]).reveal())) break; 41 | } 42 | 43 | printf(" idx: %d %d %d\n", idx[0], idx[1], idx[2]); 44 | printf(" i: %d\n", i); 45 | 46 | if (i == 0) return 0; // all > z; 47 | i--; 48 | if (i > 0 && arr[i].equal(arr[i-1]).reveal()) return 0; // two or more bidders have the same price 49 | return idx[i]; 50 | } 51 | 52 | -------------------------------------------------------------------------------- /privacy-contract/bidding/contract/BidEvaluation.proto: -------------------------------------------------------------------------------- 1 | 2 | syntax = "proto3"; 3 | option optimize_for = LITE_RUNTIME; 4 | 5 | package BidEvaluation; 6 | option java_package = "network.platon.bidevaluation"; 7 | 8 | message Bidder { 9 | int32 a = 1; 10 | int32 b = 2; 11 | int32 c = 3; 12 | } 13 | -------------------------------------------------------------------------------- /privacy-contract/bidding/dapp/dapp.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | -------------------------------------------------------------------------------- /privacy-contract/bidding/dapp/dependency-reduced-pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | net.platon.mpc 5 | mpc-proxy-tool 6 | 1.0-SNAPSHOT 7 | 8 | 9 | 10 | kr.motd.maven 11 | os-maven-plugin 12 | 1.4.1.Final 13 | 14 | 15 | 16 | 17 | maven-compiler-plugin 18 | 3.6.0 19 | 20 | 1.8 21 | 1.8 22 | utf8 23 | 24 | 25 | 26 | org.xolstice.maven.plugins 27 | protobuf-maven-plugin 28 | 0.5.0 29 | 30 | 31 | 32 | compile 33 | compile-custom 34 | 35 | 36 | 37 | 38 | com.google.protobuf:protoc:3.0.0:exe:${os.detected.classifier} 39 | grpc-java 40 | io.grpc:protoc-gen-grpc-java:1.0.0:exe:${os.detected.classifier} 41 | 42 | 43 | 44 | maven-shade-plugin 45 | 3.2.1 46 | 47 | 48 | package 49 | 50 | shade 51 | 52 | 53 | 54 | 55 | *:* 56 | 57 | META-INF/*.SF 58 | META-INF/*.DSA 59 | META-INF/*.RSA 60 | 61 | 62 | 63 | 64 | 65 | client.Client 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | UTF-8 76 | 77 | 78 | -------------------------------------------------------------------------------- /privacy-contract/bidding/dapp/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | net.platon.mpc 8 | dapp 9 | jar 10 | 1.0 11 | 12 | 13 | UTF-8 14 | 15 | 16 | 17 | 18 | juzixmaven 19 | juzix maven 20 | https://sdk.platon.network/nexus/content/groups/public/ 21 | 22 | 23 | 24 | 25 | 26 | net.platon.mpc 27 | mpc-proxy-sdk 28 | 1.0 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | kr.motd.maven 37 | os-maven-plugin 38 | 1.4.1.Final 39 | 40 | 41 | 42 | 43 | org.apache.maven.plugins 44 | maven-compiler-plugin 45 | 3.6.0 46 | 47 | 1.8 48 | 1.8 49 | utf8 50 | 51 | 52 | 53 | 54 | org.xolstice.maven.plugins 55 | protobuf-maven-plugin 56 | 0.5.0 57 | 58 | com.google.protobuf:protoc:3.0.0:exe:${os.detected.classifier} 59 | grpc-java 60 | io.grpc:protoc-gen-grpc-java:1.0.0:exe:${os.detected.classifier} 61 | 62 | 63 | 64 | 65 | compile 66 | compile-custom 67 | 68 | 69 | 70 | 71 | 72 | 73 | org.apache.maven.plugins 74 | maven-shade-plugin 75 | 3.2.1 76 | 77 | 78 | package 79 | 80 | shade 81 | 82 | 83 | 84 | 85 | *:* 86 | 87 | META-INF/*.SF 88 | META-INF/*.DSA 89 | META-INF/*.RSA 90 | 91 | 92 | 93 | 94 | 95 | client.Client 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | -------------------------------------------------------------------------------- /privacy-contract/bidding/dapp/src/main/java/client/Client.java: -------------------------------------------------------------------------------- 1 | package client; 2 | 3 | import net.platon.mpc.proxy.sdk.ProxyClient; 4 | import org.slf4j.Logger; 5 | import org.slf4j.LoggerFactory; 6 | import platon.mpc.proxy.ProxyTool; 7 | 8 | import java.util.ArrayList; 9 | import java.util.regex.Matcher; 10 | import java.util.regex.Pattern; 11 | 12 | /** 13 | * This demo is show how to use command parameters. 14 | */ 15 | public class Client { 16 | private static final Logger logger = LoggerFactory.getLogger(Client.class.getName()); 17 | 18 | private ParameterParser paras; 19 | 20 | private Client(ParameterParser paras) { 21 | this.paras = paras; 22 | } 23 | 24 | public static void main(String[] args) { 25 | // String walletPath = "--walletPath=" + System.getProperty("user.dir") + "/samples/config/60ceca9c1290ee56b98d4e160ef0453f7c40d219"; 26 | // String walletPass = "--walletPass=11111111"; 27 | // String url = "--url=http://192.168.18.31:7789"; 28 | // String api = "--api=getResultByTaskId(d988b4f4a9f269b8a60d828a2eeca0eec2a446b1d2519818042ef712a8dc9a63)"; 29 | // String method = "TestAdd"; 30 | // String returnType = "--returnType=int"; 31 | // String[] aas = {walletPath, walletPass, url, api, method,returnType}; 32 | // 33 | // Client client0 = new Client(new ParameterParser(aas)); 34 | // client0.doNothing(); 35 | 36 | Client client = new Client(new ParameterParser(args)); 37 | client.run(); 38 | } 39 | 40 | private ArrayList getApi(String api) { 41 | ArrayList apiFuncArgs = new ArrayList<>(); 42 | String pattern = "(\\w+)\\((\\w+)\\)"; 43 | Pattern r = Pattern.compile(pattern); 44 | Matcher m = r.matcher(api); 45 | if (m.find()) { 46 | for (int i = 1; i <= m.groupCount(); i++) { 47 | apiFuncArgs.add(m.group(i)); 48 | } 49 | } 50 | return apiFuncArgs; 51 | } 52 | 53 | private void doNothing() { } 54 | 55 | private void run() { 56 | 57 | ArrayList apiFuncArgs = getApi(paras.api); 58 | if (apiFuncArgs.size() < 2) { 59 | logger.warn("apiFuncArgs.size():{}", apiFuncArgs.size()); 60 | return; 61 | } 62 | String funcName = apiFuncArgs.get(0); 63 | String arg1 = apiFuncArgs.get(1); 64 | 65 | /* 66 | * 0. you should provide follow arguments 67 | */ 68 | String walletPath = paras.walletPath; 69 | String walletPass = paras.walletPass; 70 | String url = paras.url; 71 | 72 | if (funcName.equals("getPlainText")) { 73 | logger.info("Cipher Hex String: {}", arg1); 74 | String plainHexString = ProxyClient.getPlainText(arg1, walletPath, walletPass); 75 | logger.info("Plain Hex String: {}", plainHexString); 76 | return; 77 | } 78 | 79 | 80 | /* 81 | * 1. new a proxy client, and set gasPrice/gasLimit/contractAddress 82 | */ 83 | ProxyTool client = new ProxyTool(url, walletPath, walletPass); 84 | { 85 | // or, you can set contract-address only, price and limit will use default 86 | client.setContractAddress(paras.contractAddress); 87 | } 88 | 89 | String transactionHash; 90 | if (funcName.equals("startCalc")) { 91 | /* 92 | * 2. start calc, by pass a method 93 | */ 94 | transactionHash = client.startCalc(arg1, 3); 95 | logger.info("transactionHash:{}", transactionHash); 96 | if (transactionHash == null) { 97 | logger.warn("transaction hash is null"); 98 | } 99 | 100 | client.close(); 101 | return; 102 | } 103 | 104 | if (funcName.equals("getTaskId")) { 105 | String taskId = client.getTaskId(arg1); 106 | logger.info("taskId:{}", taskId); 107 | if (taskId == null) { 108 | logger.warn("task id is null"); 109 | } 110 | client.close(); 111 | return; 112 | } 113 | 114 | String cipher; 115 | switch (funcName) { 116 | case "getResultByTaskId": 117 | cipher = client.getResultByTaskId(arg1); 118 | break; 119 | case "getResultByTransactionHash": 120 | cipher = client.getResultByTransactionHash(arg1); 121 | break; 122 | default: 123 | logger.warn("function [{}] not exist!", funcName); 124 | client.close(); 125 | return; 126 | } 127 | 128 | logger.info("cipher:{}", cipher); 129 | if (cipher == null) { 130 | logger.warn("cipher is null"); 131 | client.close(); 132 | return; 133 | } 134 | 135 | parseResult(client, cipher); 136 | 137 | client.close(); 138 | } 139 | 140 | private void parseResult(ProxyTool client, String cipher) { 141 | String returnType = paras.returnType; 142 | switch (returnType) { 143 | case "boolean": { 144 | boolean ret = client.getBool(cipher); 145 | logger.info("result boolean: {}", ret); 146 | break; 147 | } 148 | case "int32": { 149 | int ret = client.getInt32(cipher); 150 | logger.info("result int: {}", ret); 151 | break; 152 | } 153 | case "int64": { 154 | long ret = client.getInt64(cipher); 155 | logger.info("result long: {}", ret); 156 | break; 157 | } 158 | case "float": { 159 | float ret = client.getFloat(cipher); 160 | logger.info("result float: {}", ret); 161 | break; 162 | } 163 | case "double": { 164 | double ret = client.getDouble(cipher); 165 | logger.info("result double: {}", ret); 166 | break; 167 | } 168 | default: 169 | logger.warn("unknow return type [{}]", paras.returnType); 170 | break; 171 | } 172 | } 173 | 174 | } -------------------------------------------------------------------------------- /privacy-contract/bidding/dapp/src/main/java/client/ParameterParser.java: -------------------------------------------------------------------------------- 1 | package client; 2 | 3 | 4 | import org.apache.commons.cli.*; 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | 8 | public class ParameterParser { 9 | private static final Logger logger = LoggerFactory.getLogger(ParameterParser.class.getName()); 10 | 11 | public boolean sample = false; 12 | 13 | public String walletPath = ""; 14 | public String walletPass = ""; 15 | public String url = ""; 16 | 17 | public String contractAddress = ""; 18 | public int threadNum = 1; 19 | public String api = ""; 20 | public String method = ""; 21 | public String returnType = ""; 22 | 23 | 24 | private void Helper() { 25 | StringBuilder sb = new StringBuilder(); 26 | sb.append("\n===================== Usage ====================="); 27 | sb.append("\n-h --help: Show this help"); 28 | sb.append("\n"); 29 | sb.append("\n-s --sample: Is run mpc sample"); 30 | sb.append("\n"); 31 | sb.append("\n-w --walletPath: Wallet path"); 32 | sb.append("\n-p --walletPass: Wallet password"); 33 | sb.append("\n-c --url: The url connect to PlatON node"); 34 | sb.append("\n"); 35 | sb.append("\n-a --contractAddress: MPC contract address"); 36 | sb.append("\n-n --threadNum: Thread number, default 1, for performance test"); 37 | sb.append("\n-i --api: MPC client api"); 38 | sb.append("\n =startCalc(method)"); 39 | sb.append("\n =getTaskId(transactionHash)"); 40 | sb.append("\n =getResultByTaskId(taskId)"); 41 | sb.append("\n =getResultByTransactionHash(transactionHash)"); 42 | sb.append("\n =getPlainText(cipher)"); 43 | sb.append("\n-m --method: MPC method"); 44 | sb.append("\n-r --returnType: return type"); 45 | 46 | System.out.println(sb.toString()); 47 | } 48 | 49 | public ParameterParser(String[] args) { 50 | CommandLineParser parser = new DefaultParser(); 51 | Options options = new Options(); 52 | options.addOption("h", "help", false, "Show this help"); 53 | options.addOption("s", "sample", false, "Is run sample"); 54 | options.addOption("w", "walletPath", true, "Wallet Path"); 55 | options.addOption("p", "walletPass", true, "Wallet Password"); 56 | options.addOption("c", "url", true, "The url connect to platon node"); 57 | options.addOption("a", "contractAddress", true, "MPC contract address"); 58 | options.addOption("n", "threadNum", true, "Thread number, default 1, for performance test"); 59 | options.addOption("i", "api", true, "MPC Client API"); 60 | options.addOption("m", "method", true, "MPC method"); 61 | options.addOption("r", "returnType", true, "MPC method return type"); 62 | 63 | CommandLine commandLine = null; 64 | try { 65 | commandLine = parser.parse(options, args); 66 | } catch (ParseException e) { 67 | //e.printStackTrace(); 68 | logger.error("Exception: ", e); 69 | System.exit(1); 70 | } 71 | 72 | if (commandLine.hasOption("help")) { 73 | Helper(); 74 | System.exit(0); 75 | } 76 | if (commandLine.hasOption("sample")) { 77 | sample = true; 78 | } 79 | if (commandLine.hasOption("walletPath")) { 80 | walletPath = commandLine.getOptionValue("walletPath"); 81 | } 82 | if (commandLine.hasOption("walletPass")) { 83 | walletPass = commandLine.getOptionValue("walletPass"); 84 | } 85 | if (commandLine.hasOption("url")) { 86 | url = commandLine.getOptionValue("url"); 87 | } 88 | if (commandLine.hasOption("contractAddress")) { 89 | contractAddress = commandLine.getOptionValue("contractAddress"); 90 | } 91 | if (commandLine.hasOption("threadNum")) { 92 | threadNum = Integer.parseInt(commandLine.getOptionValue("threadNum")); 93 | if (threadNum <= 1) threadNum = 1; 94 | } 95 | if (commandLine.hasOption("api")) { 96 | api = commandLine.getOptionValue("api"); 97 | } 98 | if (commandLine.hasOption("method")) { 99 | method = commandLine.getOptionValue("method"); 100 | } 101 | if (commandLine.hasOption("returnType")) { 102 | returnType = commandLine.getOptionValue("returnType"); 103 | } 104 | 105 | logger.info(toString()); 106 | } 107 | 108 | public String toString() { 109 | StringBuilder sb = new StringBuilder(); 110 | sb.append("\n=============== Parameters ==============="); 111 | sb.append("\n sample: ").append(sample); 112 | sb.append("\n"); 113 | sb.append("\n walletPath: ").append(walletPath); 114 | sb.append("\n walletPass: ********"); 115 | sb.append("\n url: ").append(url); 116 | sb.append("\n"); 117 | sb.append("\ncontractAddress: ").append(contractAddress); 118 | sb.append("\n threadNum: ").append(threadNum); 119 | sb.append("\n api: ").append(api); 120 | sb.append("\n method: ").append(method); 121 | sb.append("\n returnType: ").append(returnType); 122 | 123 | return sb.toString(); 124 | } 125 | 126 | 127 | } 128 | -------------------------------------------------------------------------------- /privacy-contract/bidding/dapp/src/main/java/platon/mpc/proxy/ProxyTool.java: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * may be some declaration here. 4 | */ 5 | package platon.mpc.proxy; 6 | 7 | import net.platon.mpc.proxy.sdk.ProxyClient; 8 | import org.web3j.crypto.Credentials; 9 | import org.web3j.protocol.Web3j; 10 | 11 | 12 | /** 13 | * Attention! This file was auto-generated, DO NOT EDIT! 14 | */ 15 | 16 | public class ProxyTool extends ProxyClient { 17 | /** 18 | * Constructor 19 | */ 20 | public ProxyTool(Web3j web3j, Credentials credentials) { 21 | super(web3j, credentials); 22 | } 23 | 24 | public ProxyTool(String url, Credentials credentials) { 25 | super(url, credentials); 26 | } 27 | 28 | public ProxyTool(String url, String walletPath, String walletPass) { 29 | super(url, walletPath, walletPass); 30 | } 31 | 32 | public ProxyTool(Web3j web3j, String walletPath, String walletPass) { 33 | super(web3j, walletPath, walletPass); 34 | } 35 | 36 | /** 37 | * Public method 38 | */ 39 | public String startCalc(String method) { 40 | return startCalc(method, 0); 41 | } 42 | 43 | public String startCalc(String method, int retry) { 44 | return super.startCalc(method, retry); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /pwasm-contract/bidding/README-cn.md: -------------------------------------------------------------------------------- 1 | 2 | # PlatON Dapp Example 3 | 4 | ## 二次加权平均评标 5 | 假设有三家投标方A/B/C,分别报价a/b/c,开标方P标底价为p,通过Dapp进行评标,评标方法如下: 6 | 报价平均值 y = ( a + b + c ) / 3 7 | 评标基准值 z = ( y + p)/ 2 8 | 取投标报价中低于(含等于)z值,且最接近者为中标人。 9 | 10 | ## 依赖说明 11 | wasm编译需要下载: 12 | 13 | [pwasm-windows-x86_64-0.3.0.zip](https://download.platon.network/0.3/pwasm-windows-x86_64-0.3.0.zip):PlatON开发工具包 14 | 15 | [Ptool-1.0-capsule.jar](https://download.platon.network/Ptool-1.0-capsule.jar):生成钱包和发布合约的工具 16 | 17 | [client-sdk-java-0.4.0.zip](https://github.com/PlatONnetwork/client-sdk-java/releases/download/client_sdk_v0.4.0/client-sdk-java-0.4.0.zip):生成合约对应Java Wapper类工具 18 | 19 | ## 搭建合约开发环境 20 | ### 安装第三方工具包 21 | windows系统需安装以下第三方工具包。 22 | - cmake 3.0+ 用于生成构建文件 23 | - mingw 6.0.0+ 用于编译构建文件 24 | 25 | 使用Chocolatey便捷式安装以上工具。打开cmd窗口,执行以下命令: 26 | ``` 27 | @"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin" 28 | ``` 29 | 30 | 安装CMake 31 | ``` 32 | choco install cmake --version=3.13.0 33 | ``` 34 | 35 | 安装mingw 36 | ``` 37 | choco install mingw 38 | ``` 39 | 40 | ### PlatON开发工具包 41 | 依赖文件pwasm-windows-x86_64-0.3.0.zip为PlatON开发工具包,解压后所有文件均位于`pWASM`目录下,该目录文件结构如下: 42 | ```txt 43 | ├── bin 44 | ├── boost 45 | ├── CMakeModules 46 | ├── external 47 | ├── libc 48 | ├── libc++ 49 | ├── platonlib 50 | ├── rapidjson 51 | ├── docs 52 | ├── script 53 | ├── user 54 | ├── CMakeLists.txt 55 | └── README.md 56 | ``` 57 | 部分文件夹功能概述: 58 | * `external` 用于存放编译过程中需要的二进制包,主要包含`abi`与`bin`文件的生成工具链 59 | * `user` 为合约范例,仅供参考。同时也用于存放脚本自动生成合约模板文件 60 | * `platonlib` PlatON 专供的合约与区块链交互的库。具体参考:[Wasm合约内置库](https://pwasmdoc.platon.network/) 61 | 62 | ### 生成本地钱包 63 | 使用下载的工具`Ptool-1.0-capsule.jar`执行以下命令生成本地钱包: 64 | ``` 65 | java -jar Ptool-1.0-capsule.jar --method=genWallet --walletPath=.\ --walletPass=123456 66 | ``` 67 | 命令执行完成,命令行返回钱包地址,同时在bin目录下生成钱包文件,如果是在PlatON TestNet上进行测试,则需要到[PlatON官网](https://developer.platon.network/#/?lang=en)进行申请测试币。 68 | 69 | 后续会使用到生成的钱包地址和文件,假设此处返回: 70 | - 钱包地址:`0x588fa184b404f9c0e54ce8ce81086293fc08f432` 71 | - 钱包文件:`UTC--2019-02-20T11-47-25.598605318Z--588fa184b404f9c0e54ce8ce81086293fc08f432` 72 | 73 | ## bidding合约 74 | ### 创建合约工程 75 | 在`pWASM`中使用以下命令进行项目配置 76 | ``` 77 | .\script\autoproject.bat . bidding 78 | ``` 79 | 此时,pWASM目录下会生成build文件夹,同时在user目录下生成bidding目录,bidding目录会自动生成空代码文件biding.cpp。 80 | 81 | ### 编写合约代码 82 | 修改bidding.cpp文件,将代码替换为`contract\bidding.cpp`。 83 | 84 | ### 合约编译 85 | 在`pWASM\build`中使用以下命令进行编译 86 | ``` 87 | mingw32-make.exe 88 | ``` 89 | 编译成功后,会在`pWASM\biuild`目录下新建子目录`user\bidding`,并在该目录下生成bidding.wasm和bidding.cpp.abi.json文件。 90 | bidding.cpp.abi.json:合约对应的接口描述文件; 91 | bidding.wasm:合约编译后的二进制文件,字节码指令集; 92 | 93 | ### 生成Java wrapper类 94 | 为方便dapp开发,PlatON提供`client-sdk`工具可将bidding.wasm生成java wrapper类。 95 | 解压下载的`client-sdk-java-0.4.0.zip`,进入`client-sdk-java-0.4.0/bin`目录,将合约编译生成的bidding.wasm和bidding.cpp.abi.json文件拷贝到该目录下,使用以下命令生成java wrapper类。 96 | ``` 97 | client-sdk wasm generate --javaTypes .\bidding.wasm .\bidding.cpp.abi.json -p net.platon -o .\ -t WASM 98 | ``` 99 | 100 | 会在net\platon下生成bidding.java 101 | 102 | ### 发布合约 103 | 使用下载的工具`Ptool-1.0-capsule.jar`用以下命令可发布bidding合约到PlatON TestNet: 104 | ``` 105 | java -jar Ptool-1.0-capsule.jar --method=deployContract --url=http://test-va.platon.network:6789 --walletPath=.\UTC--2019-02-20T11-47-25.598605318Z--588fa184b404f9c0e54ce8ce81086293fc08f432 --walletPass=123456 --code=.\bidding.wasm 106 | ``` 107 | 发布成功后,返回合约地址,此处假设返回合约地址为`0x4c1e1f56bb4bab4c22bf0a6955ec37d73dfa8cfb`。 108 | 109 | 注意: 110 | - 如果需要发布到其他PlatON链,需要修改url命令行参数 111 | - 参数walletPath和walletPass需要根据`生成本地钱包`步骤实际生成结果进行替换 112 | 113 | ## bidding Dapp 114 | PlatON中可使用Java编写Dapp。目录`dapp`中可找到bidding Dapp源代码,可直接打开使用或按照以下步骤进行开发。 115 | ### 创建Java工程 116 | 使用Eclipse或其他Java开发工具创建Gradle工程。 117 | 118 | ### 添加依赖包 119 | 在Gradle工程下默认配置文件build.gradle中添加以下依赖: 120 | ``` 121 | repositories { 122 | maven { url "https://sdk.platon.network/nexus/content/groups/public/" } 123 | } 124 | compile "com.platon.client:core:0.3.0" 125 | ``` 126 | 127 | ### 导入合约wrapper类 128 | 将java文件`client-sdk-0.4.0\bin\net\platon\bidding.java`导入到java项目中。 129 | 130 | ### Dapp代码编写 131 | 调用合约代码如下: 132 | ``` 133 | package net.platon.bid; 134 | 135 | import java.io.File; 136 | import java.math.BigInteger; 137 | 138 | import org.bouncycastle.util.encoders.Hex; 139 | import org.web3j.crypto.Credentials; 140 | import org.web3j.crypto.WalletUtils; 141 | import org.web3j.protocol.Web3j; 142 | import org.web3j.protocol.http.HttpService; 143 | import org.web3j.rlp.RlpDecoder; 144 | import org.web3j.rlp.RlpList; 145 | import org.web3j.rlp.RlpString; 146 | import org.web3j.rlp.RlpType; 147 | import org.web3j.tx.gas.DefaultWasmGasProvider; 148 | import org.web3j.utils.Files; 149 | import org.web3j.utils.Numeric; 150 | 151 | public class BidMain { 152 | 153 | public static void main(String[] args) throws Exception { 154 | String walletPath = "./UTC--2019-02-20T11-47-25.598605318Z--588fa184b404f9c0e54ce8ce81086293fc08f432"; 155 | String walletPass = "123456"; 156 | String url = "http://test-va.platon.network:6789"; 157 | String data = "2,4,6,6"; 158 | String code = "./bidding.wasm"; 159 | String contractAddress = "0x4c1e1f56bb4bab4c22bf0a6955ec37d73dfa8cfb"; 160 | String result = cacl(url, walletPath, walletPass,code,contractAddress, data); 161 | System.out.println("get result:" + result); 162 | } 163 | 164 | private static String cacl(String url, String walletPath,String walletPass, String codePath,String contractAddress,String data) throws Exception{ 165 | String[] input = data.split(","); 166 | //申明web3j和credentials 167 | Web3j web3j = Web3j.build(new HttpService(url)); 168 | Credentials credentials = WalletUtils.loadCredentials(walletPass, walletPath); 169 | byte[] dataBytes = Files.readBytes(new File(codePath)); 170 | String binData = Hex.toHexString(dataBytes); 171 | //初始化对象 172 | Bidding contract = new Bidding(binData, contractAddress, web3j, credentials, new DefaultWasmGasProvider()); 173 | String result = contract.calcData(new BigInteger(input[0]), new BigInteger(input[1]), new BigInteger(input[2]), new BigInteger(input[3])); 174 | //对结果进行解码 175 | RlpList rl = RlpDecoder.decode(Numeric.hexStringToByteArray(result)); 176 | RlpType rt = rl.getValues().get(0); 177 | RlpType rt2 = ((RlpList) rt).getValues().get(0); 178 | BigInteger sss = ((RlpString) rt2).asPositiveBigInteger(); 179 | //得到返回值 180 | result = sss.toString(10); 181 | return result; 182 | us} 183 | } 184 | ``` 185 | 注意,代码中: 186 | - 变量contractAddress表示合约地址,注意修改为`发布合约`步骤返回的实际合约地址 187 | - 变量code为wasm文件路径,注意修改为`合约编译`步骤生成的wasm文件路径。 188 | - 如果需要发布到其他PlatON链,需要修改url变量取值 189 | - 变量walletPath和walletPass需要根据`生成本地钱包`步骤实际生成结果进行替换 190 | 191 | ### Dapp编译运行 192 | 直接在IDE中编译运行BidMain类。 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | -------------------------------------------------------------------------------- /pwasm-contract/bidding/README.md: -------------------------------------------------------------------------------- 1 | # PlatON WASM Bidding Example 2 | 3 | ## Second weighted average bid evaluation 4 | Suppose there are three bidders A/B/C, which are quoted a/b/c respectively, and the bidder's P bid base price is p, and the bid evaluation is carried out by Dapp. The bid evaluation method is as follows: 5 | Average price of y = y = ( a + b + c ) / 3 6 | Bid evaluation value z = ( y + p) / 2 7 | The bid price is lower than (including equal to) z value, and the closest one is the winning bidder. 8 | 9 | ## Dependency description 10 | `Wasm` compilation toolset needs to be downloaded: 11 | 12 | [pwasm-windows-x86_64-0.3.0.zip](https://download.platon.network/0.3/pwasm-windows-x86_64-0.3.0.zip): `PlatON` `WASM` Development kit 13 | 14 | [Ptool-1.0-capsule.jar](https://download.platon.network/Ptool-1.0-capsule.jar): Tools for generating wallet and publishing contract 15 | 16 | [client-sdk-java-0.4.0.zip](https://github.com/PlatONnetwork/client-sdk-java/releases/download/client_sdk_v0.4.0/client-sdk-java-0.4.0.zip) : Java development kit for compiled contract 17 | 18 | ## Building contract development environment 19 | ### Installing third-party toolkits 20 | Windows systems need to install the following third-party toolkits. 21 | - **cmake 3.0+** 22 | 23 | Building tool used to control the project compilation. 24 | 25 | - **mingw 6.0.0+** 26 | 27 | Dependency development environment for WASM contract compilation. 28 | 29 | Use the Chocolatey to easily install the above tools. Open the cmd window and execute the following command: 30 | ``` 31 | @"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey .org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin" 32 | ``` 33 | 34 | Install `CMake `: 35 | ``` 36 | choco install cmake --version=3.13.0 37 | ``` 38 | 39 | Install `mingw` : 40 | ``` 41 | choco install mingw 42 | ``` 43 | 44 | ### PlatON Development Kit 45 | The dependent file `pwasm-windows-x86_64-0.3.0.zip` is the `PlatON` wasm contract development kit. After decompressing, all files are located in the `pWASM` directory. The directory file structure is as follows: 46 | ```txt 47 | ├── bin 48 | ├──boost 49 | ├── CMakeModules 50 | ├── external 51 | ├── libc 52 | ├── libc++ 53 | ├── platonlib 54 | ├── rapidjson 55 | ├── docs 56 | ├── script 57 | ├── user 58 | ├── CMakeLists.txt 59 | └── README.md 60 | ``` 61 | Description: 62 | * `external` is used to store the binary packages needed in the compilation process, mainly including the generation toolchain of `abi` and `bin` files. 63 | * `user` is an example of a contract and is for reference only. Also used to store scripts to automatically generate contract template files 64 | * `platonlib` is a library dedicated to interacting with blockchains. Specific reference: [Wasm contract built-in library](https://pwasmdoc.platon.network/) 65 | 66 | ### Generating a local wallet 67 | Use the downloaded tool `Ptool-1.0-capsule.jar` to execute the following command to generate a local wallet: 68 | ``` 69 | java -jar Ptool-1.0-capsule.jar --method=genWallet --walletPath=.\ --walletPass=123456 70 | ``` 71 | After the command is executed, the command line returns the wallet address and generates the wallet file in the bin directory. If it is tested on `PlatON TestNet`, you need to go to [PlatON official website](https://developer.platon.network/#/?lang=en) Apply for a test coin. 72 | 73 | Subsequent use of the generated wallet address and file, assuming this is returned here: 74 | - Wallet address: `0x588fa184b404f9c0e54ce8ce81086293fc08f432` 75 | - Wallet file: `UTC--2019-02-20T11-47-25.598605318Z--588fa184b404f9c0e54ce8ce81086293fc08f432` 76 | 77 | ## bidding contract 78 | ### Creating a contract project 79 | Use the following command in `pWASM` for project configuration 80 | ``` 81 | .\script\autoproject.bat . bidding 82 | ``` 83 | At this point, the build folder will be generated in the pWASM directory, and the bidding directory will be generated in the user directory. The bidding directory will automatically generate the empty code file biding.cpp. 84 | 85 | ### Writing contract code 86 | Modify the bidding.cpp file and replace the code with `contract\bidding.cpp`. 87 | 88 | ### Contract compilation 89 | Compile with the following command in `pWASM\build` 90 | ``` 91 | mingw32-make.exe 92 | ``` 93 | After the compilation is successful, the subdirectory `user\bidding` will be created in the `pWASM\biuild` directory, and the bidding.wasm and bidding.cpp.abi.json files will be generated in the directory. 94 | Bidding.cpp.abi.json: interface description file corresponding to the contract; 95 | Bidding.wasm: the compiled binary file, bytecode instruction set; 96 | 97 | ### Generating Java wrapper class 98 | To facilitate the development of dapp, PlatON provides the `client-sdk` tool to generate the java wrapper class from bidding.wasm. 99 | Unzip the downloaded `client-sdk-java-0.4.0.zip`, enter the `client-sdk-java-0.4.0/bin` directory, and compile the generated bidding.wasm and bidding.cpp.abi.json files. Copy to this directory and use the following command to generate the java wrapper class. 100 | ``` 101 | client-sdk wasm generate --javaTypes .\bidding.wasm .\bidding.cpp.abi.json -p net.platon -o .\ -t WASM 102 | ``` 103 | 104 | Will generate bidding.java under net\platon 105 | 106 | ### Publishing contract 107 | Use the downloaded tool `Ptool-1.0-capsule.jar` to post the bidding contract to Platton TestNet with the following command: 108 | ``` 109 | java -jar Ptool-1.0-capsule.jar --method=deployContract --url=http://test-va.platon.network:6789 --walletPath=.\UTC--2019-02-20T11-47-25.598605318 Z--588fa184b404f9c0e54ce8ce81086293fc08f432 --walletPass=123456 --code=.\bidding.wasm 110 | ``` 111 | After the release is successful, return the contract address, here it is assumed that the return contract address is `0x4c1e1f56bb4bab4c22bf0a6955ec37d73dfa8cfb`. 112 | 113 | note: 114 | - If you need to publish to other Plat chain, you need to modify the url command line parameters. 115 | - The parameters walletPath and walletPass need to be replaced according to the actual generated result of the `Generate local wallet` step. 116 | 117 | ## Bidding Dapp 118 | Dapp can be written in Java in PlatON. The bidding Dapp source code can be found in the directory `dapp`, which can be opened directly or developed according to the following steps. 119 | ### Creating a Java project 120 | Create a Gradle project using Eclipse or other Java development tools. 121 | 122 | ### Adding a dependency package 123 | Add the following dependency to the default configuration file build.gradle under Gradle project: 124 | ``` 125 | repositories { 126 |     Maven { url "https://sdk.platon.network/nexus/content/groups/public/" } 127 | } 128 | compile "com.platon.client:core:0.3.0" 129 | ``` 130 | 131 | ### Importing contract wrapper class 132 | Import the java file `client-sdk-0.4.0\bin\net\platon\bidding.java` into the java project. 133 | 134 | ### Dapp code writing 135 | The contract code is called as follows: 136 | ``` 137 | package net.platon.bid; 138 | 139 | import java.io.File; 140 | import java.math.BigInteger; 141 | 142 | import org.bouncycastle.util.encoders.Hex; 143 | import org.web3j.crypto.Credentials; 144 | import org.web3j.crypto.WalletUtils; 145 | import org.web3j.protocol.Web3j; 146 | import org.web3j.protocol.http.HttpService; 147 | import org.web3j.rlp.RlpDecoder; 148 | import org.web3j.rlp.RlpList; 149 | import org.web3j.rlp.RlpString; 150 | import org.web3j.rlp.RlpType; 151 | import org.web3j.tx.gas.DefaultWasmGasProvider; 152 | import org.web3j.utils.Files; 153 | import org.web3j.utils.Numeric; 154 | 155 | public class BidMain { 156 | 157 | public static void main(String[] args) throws Exception { 158 | String walletPath = "./UTC--2019-02-20T11-47-25.598605318Z--588fa184b404f9c0e54ce8ce81086293fc08f432"; 159 | String walletPass = "123456"; 160 | String url = "http://test-va.platon.network:6789"; 161 | String data = "2,4,6,6"; 162 | String code = "./bidding.wasm"; 163 | String contractAddress = "0x4c1e1f56bb4bab4c22bf0a6955ec37d73dfa8cfb"; 164 | String result = cacl(url, walletPath, walletPass,code,contractAddress, data); 165 | System.out.println("get result:" + result); 166 | } 167 | 168 | private static String cacl(String url, String walletPath,String walletPass, String codePath,String contractAddress,String data) throws Exception{ 169 | String[] input = data.split(","); 170 | //declare web3j credentials 171 | Web3j web3j = Web3j.build(new HttpService(url)); 172 | Credentials credentials = WalletUtils.loadCredentials(walletPass, walletPath); 173 | byte[] dataBytes = Files.readBytes(new File(codePath)); 174 | String binData = Hex.toHexString(dataBytes); 175 | //initiate 176 | Bidding contract = new Bidding(binData, contractAddress, web3j, credentials, new DefaultWasmGasProvider()); 177 | String result = contract.calcData(new BigInteger(input[0]), new BigInteger(input[1]), new BigInteger(input[2]), new BigInteger(input[3])); 178 | //decode 179 | RlpList rl = RlpDecoder.decode(Numeric.hexStringToByteArray(result)); 180 | RlpType rt = rl.getValues().get(0); 181 | RlpType rt2 = ((RlpList) rt).getValues().get(0); 182 | BigInteger sss = ((RlpString) rt2).asPositiveBigInteger(); 183 | //result back 184 | result = sss.toString(10); 185 | return result; 186 | } 187 | } 188 | ``` 189 | 190 | Note that in the code: 191 | - The variable contractAddress represents the contract address, note the actual contract address returned by the `Publish Contract` step. 192 | - The variable code is the wasm file path. Note that the wasm file path generated by the `Contract Compilation` step is modified. 193 | - If you need to publish to other Plat chain, you need to modify the url variable value 194 | - Variable walletPath and walletPass need to be replaced according to the actual generated result of the `Generate local wallet` step 195 | 196 | ### Dapp compile and run 197 | Compile and run the `BidMain` class directly in the IDE. 198 | -------------------------------------------------------------------------------- /pwasm-contract/bidding/contract/bidding.cpp: -------------------------------------------------------------------------------- 1 | //auto create contract 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | PLATON_EVENT(bidding, int32_t); 10 | 11 | namespace bidding { 12 | class BiddingContract : public platon::Contract { 13 | public: 14 | int calc(uint64_t a, uint64_t b, uint64_t c, uint64_t p) { 15 | double y = (a+b+c) / 3.0; 16 | double z = (y+p) / 2.0; 17 | 18 | double arr[3]; 19 | arr[0] = z - a; 20 | arr[1] = z - b; 21 | arr[2] = z - c; 22 | 23 | double min = arr[0]; 24 | int idx = -1; 25 | if (min >= 0.0f) { 26 | idx = 1; 27 | } 28 | for (int i = 1; i < 3; i++) { 29 | if (arr[i] >= 0.0f && (arr[i] < min || min < 0.0f)) { 30 | min = arr[i]; 31 | idx = i+1; 32 | continue; 33 | } 34 | } 35 | platon::println("arr[0]", arr[0], "arr[1]", arr[1], "arr[2]", arr[2], "idx", idx); 36 | if (idx < 0){ 37 | PLATON_EMIT_EVENT(bidding, 0); 38 | return 0; 39 | } 40 | PLATON_EMIT_EVENT(bidding, idx); 41 | return idx; 42 | } 43 | }; 44 | } 45 | 46 | PLATON_ABI(bidding::BiddingContract, calc); 47 | -------------------------------------------------------------------------------- /pwasm-contract/bidding/dapp/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /pwasm-contract/bidding/dapp/.gradle/2.13-rc-1/taskArtifacts/cache.properties: -------------------------------------------------------------------------------- 1 | #Fri Mar 08 19:56:41 CST 2019 2 | -------------------------------------------------------------------------------- /pwasm-contract/bidding/dapp/.gradle/2.13-rc-1/taskArtifacts/cache.properties.lock: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PlatONnetwork/Contract-Example/6a32d241680a9e6a3b8b4e68b5152394dbe2fceb/pwasm-contract/bidding/dapp/.gradle/2.13-rc-1/taskArtifacts/cache.properties.lock -------------------------------------------------------------------------------- /pwasm-contract/bidding/dapp/.gradle/2.13-rc-1/taskArtifacts/fileHashes.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PlatONnetwork/Contract-Example/6a32d241680a9e6a3b8b4e68b5152394dbe2fceb/pwasm-contract/bidding/dapp/.gradle/2.13-rc-1/taskArtifacts/fileHashes.bin -------------------------------------------------------------------------------- /pwasm-contract/bidding/dapp/.gradle/2.13-rc-1/taskArtifacts/fileSnapshots.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PlatONnetwork/Contract-Example/6a32d241680a9e6a3b8b4e68b5152394dbe2fceb/pwasm-contract/bidding/dapp/.gradle/2.13-rc-1/taskArtifacts/fileSnapshots.bin -------------------------------------------------------------------------------- /pwasm-contract/bidding/dapp/.gradle/2.13-rc-1/taskArtifacts/taskArtifacts.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PlatONnetwork/Contract-Example/6a32d241680a9e6a3b8b4e68b5152394dbe2fceb/pwasm-contract/bidding/dapp/.gradle/2.13-rc-1/taskArtifacts/taskArtifacts.bin -------------------------------------------------------------------------------- /pwasm-contract/bidding/dapp/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | BidDapp 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.springsource.ide.eclipse.gradle.core.nature 16 | org.eclipse.jdt.core.javanature 17 | 18 | 19 | -------------------------------------------------------------------------------- /pwasm-contract/bidding/dapp/.settings/com.zeroc.IceBuilderPlugin.prefs: -------------------------------------------------------------------------------- 1 | builderVersion=4.1 2 | eclipse.preferences.version=1 3 | -------------------------------------------------------------------------------- /pwasm-contract/bidding/dapp/.settings/gradle/org.springsource.ide.eclipse.gradle.core.prefs: -------------------------------------------------------------------------------- 1 | #org.springsource.ide.eclipse.gradle.core.preferences.GradleProjectPreferences 2 | #Fri Mar 08 19:57:40 CST 2019 3 | build.family.org.gradle.tooling.model.eclipse.HierarchicalEclipseProject=; 4 | org.springsource.ide.eclipse.gradle.linkedresources= 5 | org.springsource.ide.eclipse.gradle.rootprojectloc= 6 | -------------------------------------------------------------------------------- /pwasm-contract/bidding/dapp/.settings/gradle/org.springsource.ide.eclipse.gradle.refresh.prefs: -------------------------------------------------------------------------------- 1 | #org.springsource.ide.eclipse.gradle.core.actions.GradleRefreshPreferences 2 | #Fri Mar 08 19:56:51 CST 2019 3 | addResourceFilters=true 4 | afterTasks=afterEclipseImport; 5 | beforeTasks=cleanEclipse;eclipse; 6 | enableAfterTasks=true 7 | enableBeforeTasks=true 8 | useHierarchicalNames=false 9 | -------------------------------------------------------------------------------- /pwasm-contract/bidding/dapp/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | # 2 | #Fri Mar 08 20:54:52 CST 2019 3 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 4 | org.eclipse.jdt.core.compiler.compliance=1.8 5 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 6 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 7 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 8 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 9 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 10 | eclipse.preferences.version=1 11 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 12 | org.eclipse.jdt.core.compiler.source=1.8 13 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 14 | -------------------------------------------------------------------------------- /pwasm-contract/bidding/dapp/bin/net/platon/bid/BidMain.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PlatONnetwork/Contract-Example/6a32d241680a9e6a3b8b4e68b5152394dbe2fceb/pwasm-contract/bidding/dapp/bin/net/platon/bid/BidMain.class -------------------------------------------------------------------------------- /pwasm-contract/bidding/dapp/bin/net/platon/bid/Bidding$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PlatONnetwork/Contract-Example/6a32d241680a9e6a3b8b4e68b5152394dbe2fceb/pwasm-contract/bidding/dapp/bin/net/platon/bid/Bidding$1.class -------------------------------------------------------------------------------- /pwasm-contract/bidding/dapp/bin/net/platon/bid/Bidding$2.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PlatONnetwork/Contract-Example/6a32d241680a9e6a3b8b4e68b5152394dbe2fceb/pwasm-contract/bidding/dapp/bin/net/platon/bid/Bidding$2.class -------------------------------------------------------------------------------- /pwasm-contract/bidding/dapp/bin/net/platon/bid/Bidding$BiddingEventResponse.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PlatONnetwork/Contract-Example/6a32d241680a9e6a3b8b4e68b5152394dbe2fceb/pwasm-contract/bidding/dapp/bin/net/platon/bid/Bidding$BiddingEventResponse.class -------------------------------------------------------------------------------- /pwasm-contract/bidding/dapp/bin/net/platon/bid/Bidding.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PlatONnetwork/Contract-Example/6a32d241680a9e6a3b8b4e68b5152394dbe2fceb/pwasm-contract/bidding/dapp/bin/net/platon/bid/Bidding.class -------------------------------------------------------------------------------- /pwasm-contract/bidding/dapp/bin/org/gradle/resource.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /pwasm-contract/bidding/dapp/build.gradle: -------------------------------------------------------------------------------- 1 | group 'net.platon' 2 | version '1.0' 3 | 4 | buildscript { 5 | repositories { 6 | mavenCentral() 7 | maven { 8 | url "https://plugins.gradle.org/m2/" 9 | } 10 | } 11 | dependencies { 12 | classpath "us.kirchmeier:gradle-capsule-plugin:1.0.2" 13 | } 14 | } 15 | 16 | 17 | apply plugin: 'java' 18 | apply plugin: 'eclipse' 19 | apply plugin: 'idea' 20 | apply plugin: 'us.kirchmeier.capsule' 21 | 22 | version = '1.0' 23 | 24 | // JVM 版本号要求 25 | sourceCompatibility = 1.8 26 | targetCompatibility = 1.8 27 | 28 | // java编译的时候缺省状态下会因为中文字符而失败 29 | [compileJava, compileTestJava, javadoc]*.options*.encoding = 'UTF-8' 30 | 31 | repositories { 32 | mavenLocal() 33 | mavenCentral() 34 | maven { 35 | url "https://sdk.platon.network/nexus/content/groups/public/" 36 | } 37 | 38 | } 39 | 40 | //build跳过测试代码 41 | test { 42 | exclude 'net/platon/**' 43 | } 44 | 45 | dependencies { 46 | compile("com.platon.client:core:0.4.0"){ 47 | exclude group:'org.slf4j',module:'slf4j-log4j12' 48 | } 49 | compile("commons-cli:commons-cli:1.4") 50 | compile("org.springframework:spring-core:4.2.0.RELEASE") 51 | } 52 | 53 | task buildMain(type: FatCapsule) { 54 | applicationClass 'net.platon.bid.BidMain' 55 | baseName 'BidMain' 56 | } 57 | -------------------------------------------------------------------------------- /pwasm-contract/bidding/dapp/src/main/java/net/platon/bid/BidMain.java: -------------------------------------------------------------------------------- 1 | package net.platon.bid; 2 | 3 | import java.io.File; 4 | import java.math.BigInteger; 5 | 6 | import org.bouncycastle.util.encoders.Hex; 7 | import org.web3j.crypto.Credentials; 8 | import org.web3j.crypto.WalletUtils; 9 | import org.web3j.protocol.Web3j; 10 | import org.web3j.protocol.http.HttpService; 11 | import org.web3j.rlp.RlpDecoder; 12 | import org.web3j.rlp.RlpList; 13 | import org.web3j.rlp.RlpString; 14 | import org.web3j.rlp.RlpType; 15 | import org.web3j.tx.gas.DefaultWasmGasProvider; 16 | import org.web3j.utils.Files; 17 | import org.web3j.utils.Numeric; 18 | 19 | public class BidMain { 20 | 21 | public static void main(String[] args) throws Exception { 22 | String walletPath = "./UTC--2019-02-20T11-47-25.598605318Z--588fa184b404f9c0e54ce8ce81086293fc08f432"; 23 | String walletPass = "123456"; 24 | String url = "http://127.0.0.1:6789"; 25 | String data = "2,4,6,6"; 26 | String code = "./bidding.wasm"; 27 | String contractAddress = "0x4c1e1f56bb4bab4c22bf0a6955ec37d73dfa8cfb"; 28 | String result = cacl(url, walletPath, walletPass,code,contractAddress, data); 29 | System.out.println("get result:" + result); 30 | } 31 | 32 | private static String cacl(String url, String walletPath,String walletPass, String codePath,String contractAddress,String data) throws Exception{ 33 | String[] input = data.split(","); 34 | //申明web3j和credentials 35 | Web3j web3j = Web3j.build(new HttpService(url)); 36 | Credentials credentials = WalletUtils.loadCredentials(walletPass, walletPath); 37 | byte[] dataBytes = Files.readBytes(new File(codePath)); 38 | String binData = Hex.toHexString(dataBytes); 39 | //初始化对象 40 | Bidding contract = new Bidding(binData, contractAddress, web3j, credentials, new DefaultWasmGasProvider()); 41 | String result = contract.calcData(new BigInteger(input[0]), new BigInteger(input[1]), new BigInteger(input[2]), new BigInteger(input[3])); 42 | //对结果进行解码 43 | RlpList rl = RlpDecoder.decode(Numeric.hexStringToByteArray(result)); 44 | RlpType rt = rl.getValues().get(0); 45 | RlpType rt2 = ((RlpList) rt).getValues().get(0); 46 | BigInteger sss = ((RlpString) rt2).asPositiveBigInteger(); 47 | //得到返回值 48 | result = sss.toString(10); 49 | return result; 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /pwasm-contract/bidding/dapp/src/main/java/net/platon/bid/Bidding.java: -------------------------------------------------------------------------------- 1 | package net.platon.bid; 2 | 3 | import java.io.IOException; 4 | import java.math.BigInteger; 5 | import java.util.ArrayList; 6 | import java.util.Arrays; 7 | import java.util.Collections; 8 | import java.util.List; 9 | import org.web3j.abi.EventEncoder; 10 | import org.web3j.abi.TypeReference; 11 | import org.web3j.abi.datatypes.Event; 12 | import org.web3j.abi.datatypes.Function; 13 | import org.web3j.abi.datatypes.Type; 14 | import org.web3j.abi.datatypes.generated.Int32; 15 | import org.web3j.crypto.Credentials; 16 | import org.web3j.protocol.Web3j; 17 | import org.web3j.protocol.core.DefaultBlockParameter; 18 | import org.web3j.protocol.core.RemoteCall; 19 | import org.web3j.protocol.core.methods.request.EthFilter; 20 | import org.web3j.protocol.core.methods.response.Log; 21 | import org.web3j.protocol.core.methods.response.TransactionReceipt; 22 | import org.web3j.tx.PlatOnContract; 23 | import org.web3j.tx.TransactionManager; 24 | import org.web3j.tx.gas.ContractGasProvider; 25 | import org.web3j.utils.PlatOnUtil; 26 | import org.web3j.utils.TXTypeEnum; 27 | import rx.Observable; 28 | import rx.functions.Func1; 29 | 30 | /** 31 | *

Auto generated code. 32 | *

Do not modify! 33 | *

Please use the web3j command line tools, 34 | * or the org.web3j.codegen.SolidityFunctionWrapperGenerator in the 35 | * codegen module to update. 36 | * 37 | *

Generated with web3j version 0.4.0. 38 | */ 39 | public class Bidding extends PlatOnContract { 40 | private static final String ABI = "[{\"name\":\"calc\",\"inputs\":[{\"name\":\"a\",\"type\":\"uint64\"},{\"name\":\"b\",\"type\":\"uint64\"},{\"name\":\"c\",\"type\":\"uint64\"},{\"name\":\"p\",\"type\":\"uint64\"}],\"outputs\":[{\"name\":\"\",\"type\":\"int32\"}],\"constant\":\"false\",\"type\":\"function\"},{\"name\":\"bidding\",\"inputs\":[{\"type\":\"int32\"}],\"type\":\"event\"}]"; 41 | 42 | public static final String FUNC_CALC = "calc"; 43 | 44 | public static final Event BIDDING_EVENT = new Event("bidding", 45 | Arrays.>asList(new TypeReference() {})); 46 | ; 47 | 48 | @Deprecated 49 | protected Bidding(String contractBinary, String contractAddress, Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) { 50 | super(contractBinary, contractAddress, web3j, credentials, gasPrice, gasLimit); 51 | } 52 | 53 | protected Bidding(String contractBinary, String contractAddress, Web3j web3j, Credentials credentials, ContractGasProvider contractGasProvider) { 54 | super(contractBinary, contractAddress, web3j, credentials, contractGasProvider); 55 | } 56 | 57 | @Deprecated 58 | protected Bidding(String contractBinary, String contractAddress, Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) { 59 | super(contractBinary, contractAddress, web3j, transactionManager, gasPrice, gasLimit); 60 | } 61 | 62 | protected Bidding(String contractBinary, String contractAddress, Web3j web3j, TransactionManager transactionManager, ContractGasProvider contractGasProvider) { 63 | super(contractBinary, contractAddress, web3j, transactionManager, contractGasProvider); 64 | } 65 | 66 | public RemoteCall calc(BigInteger a, BigInteger b, BigInteger c, BigInteger p) { 67 | final Function function = new Function( 68 | FUNC_CALC, 69 | Arrays.asList(new org.web3j.abi.datatypes.generated.Uint64(a), 70 | new org.web3j.abi.datatypes.generated.Uint64(b), 71 | new org.web3j.abi.datatypes.generated.Uint64(c), 72 | new org.web3j.abi.datatypes.generated.Uint64(p)), 73 | Collections.>emptyList()); 74 | return executeRemoteCallTransaction(function); 75 | } 76 | 77 | public static String calcData(BigInteger a, BigInteger b, BigInteger c, BigInteger p) { 78 | final Function function = new Function( 79 | FUNC_CALC, 80 | Arrays.asList(new org.web3j.abi.datatypes.generated.Uint64(a), 81 | new org.web3j.abi.datatypes.generated.Uint64(b), 82 | new org.web3j.abi.datatypes.generated.Uint64(c), 83 | new org.web3j.abi.datatypes.generated.Uint64(p)), 84 | Collections.>emptyList()); 85 | return PlatOnUtil.invokeEncode(function,customTransactionType(function)); 86 | } 87 | 88 | public static BigInteger calcGasLimit(Web3j web3j, String estimateGasFrom, String estimateGasTo, BigInteger a, BigInteger b, BigInteger c, BigInteger p) throws IOException { 89 | String ethEstimateGasData = calcData(a, b, c, p); 90 | return PlatOnUtil.estimateGasLimit(web3j,estimateGasFrom,estimateGasTo,ethEstimateGasData); 91 | } 92 | 93 | public List getBiddingEvents(TransactionReceipt transactionReceipt) { 94 | List valueList = extractEventParametersWithLog(BIDDING_EVENT, transactionReceipt); 95 | ArrayList responses = new ArrayList(valueList.size()); 96 | for (PlatOnContract.EventValuesWithLog eventValues : valueList) { 97 | BiddingEventResponse typedResponse = new BiddingEventResponse(); 98 | typedResponse.log = eventValues.getLog(); 99 | typedResponse.param1 = (BigInteger) eventValues.getNonIndexedValues().get(0).getValue(); 100 | responses.add(typedResponse); 101 | } 102 | return responses; 103 | } 104 | 105 | public Observable biddingEventObservable(EthFilter filter) { 106 | return web3j.ethLogObservable(filter).map(new Func1() { 107 | public BiddingEventResponse call(Log log) { 108 | PlatOnContract.EventValuesWithLog eventValues = extractEventParametersWithLog(BIDDING_EVENT, log); 109 | BiddingEventResponse typedResponse = new BiddingEventResponse(); 110 | typedResponse.log = log; 111 | typedResponse.param1 = (BigInteger) eventValues.getNonIndexedValues().get(0).getValue(); 112 | return typedResponse; 113 | } 114 | }); 115 | } 116 | 117 | public Observable biddingEventObservable(DefaultBlockParameter startBlock, DefaultBlockParameter endBlock) { 118 | EthFilter filter = new EthFilter(startBlock, endBlock, getContractAddress()); 119 | filter.addSingleTopic(EventEncoder.encode(BIDDING_EVENT)); 120 | return biddingEventObservable(filter); 121 | } 122 | 123 | public static RemoteCall deploy(Web3j web3j, Credentials credentials, String contractBinary, ContractGasProvider contractGasProvider) { 124 | return deployRemoteCall(Bidding.class, web3j, credentials, contractGasProvider, contractBinary, ABI, ""); 125 | } 126 | 127 | @Deprecated 128 | public static RemoteCall deploy(Web3j web3j, Credentials credentials, String contractBinary, BigInteger gasPrice, BigInteger gasLimit) { 129 | return deployRemoteCall(Bidding.class, web3j, credentials, gasPrice, gasLimit, contractBinary, ABI, ""); 130 | } 131 | 132 | public static RemoteCall deploy(Web3j web3j, TransactionManager transactionManager, String contractBinary, ContractGasProvider contractGasProvider) { 133 | return deployRemoteCall(Bidding.class, web3j, transactionManager, contractGasProvider, contractBinary, ABI, ""); 134 | } 135 | 136 | @Deprecated 137 | public static RemoteCall deploy(Web3j web3j, TransactionManager transactionManager, String contractBinary, BigInteger gasPrice, BigInteger gasLimit) { 138 | return deployRemoteCall(Bidding.class, web3j, transactionManager, gasPrice, gasLimit, contractBinary, ABI, ""); 139 | } 140 | 141 | @Deprecated 142 | public static Bidding load(String contractBinary, String contractAddress, Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) { 143 | return new Bidding(contractBinary, contractAddress, web3j, credentials, gasPrice, gasLimit); 144 | } 145 | 146 | @Deprecated 147 | public static Bidding load(String contractBinary, String contractAddress, Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) { 148 | return new Bidding(contractBinary, contractAddress, web3j, transactionManager, gasPrice, gasLimit); 149 | } 150 | 151 | public static Bidding load(String contractBinary, String contractAddress, Web3j web3j, Credentials credentials, ContractGasProvider contractGasProvider) { 152 | return new Bidding(contractBinary, contractAddress, web3j, credentials, contractGasProvider); 153 | } 154 | 155 | public static Bidding load(String contractBinary, String contractAddress, Web3j web3j, TransactionManager transactionManager, ContractGasProvider contractGasProvider) { 156 | return new Bidding(contractBinary, contractAddress, web3j, transactionManager, contractGasProvider); 157 | } 158 | 159 | public static String getDeployData(String contractBinary) { 160 | return PlatOnUtil.deployEncode(contractBinary, ABI); 161 | } 162 | 163 | public static BigInteger getDeployGasLimit(Web3j web3j, String estimateGasFrom, String estimateGasTo, String contractBinary) throws IOException { 164 | return PlatOnUtil.estimateGasLimit(web3j, estimateGasFrom, estimateGasTo, getDeployData(contractBinary)); 165 | } 166 | 167 | private static long customTransactionType(Function function) { 168 | return TXTypeEnum.WASM.type; 169 | } 170 | 171 | protected long getTransactionType(Function function) { 172 | return customTransactionType(function); 173 | } 174 | 175 | public static class BiddingEventResponse { 176 | public Log log; 177 | 178 | public BigInteger param1; 179 | } 180 | } 181 | -------------------------------------------------------------------------------- /pwasm-contract/bidding/dapp/src/main/resources/org/gradle/resource.xml: -------------------------------------------------------------------------------- 1 | 2 | --------------------------------------------------------------------------------