├── .gitignore
├── LICENSE
├── README.md
├── community
├── Makefile
├── community.abi
├── community.cpp
├── community.hpp
├── community.wasm
└── ricardian
│ ├── community.clauses.md
│ └── community.contracts.md
├── tests
├── claim_test.sh
└── eosio.contracts
│ ├── eosio.bios.abi
│ └── eosio.bios.wasm
├── token
├── Makefile
├── ricardian
│ ├── token.clauses.md
│ └── token.contracts.md
├── token.abi
├── token.cpp
├── token.hpp
└── token.wasm
└── utils
└── utils.cpp
/.gitignore:
--------------------------------------------------------------------------------
1 | setup.sh
2 | .vscode
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU AFFERO GENERAL PUBLIC LICENSE
2 | Version 3, 19 November 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 Affero General Public License is a free, copyleft license for
11 | software and other kinds of works, specifically designed to ensure
12 | cooperation with the community in the case of network server software.
13 |
14 | The licenses for most software and other practical works are designed
15 | to take away your freedom to share and change the works. By contrast,
16 | our General Public Licenses are intended to guarantee your freedom to
17 | share and change all versions of a program--to make sure it remains free
18 | software for all its users.
19 |
20 | When we speak of free software, we are referring to freedom, not
21 | price. Our General Public Licenses are designed to make sure that you
22 | have the freedom to distribute copies of free software (and charge for
23 | them if you wish), that you receive source code or can get it if you
24 | want it, that you can change the software or use pieces of it in new
25 | free programs, and that you know you can do these things.
26 |
27 | Developers that use our General Public Licenses protect your rights
28 | with two steps: (1) assert copyright on the software, and (2) offer
29 | you this License which gives you legal permission to copy, distribute
30 | and/or modify the software.
31 |
32 | A secondary benefit of defending all users' freedom is that
33 | improvements made in alternate versions of the program, if they
34 | receive widespread use, become available for other developers to
35 | incorporate. Many developers of free software are heartened and
36 | encouraged by the resulting cooperation. However, in the case of
37 | software used on network servers, this result may fail to come about.
38 | The GNU General Public License permits making a modified version and
39 | letting the public access it on a server without ever releasing its
40 | source code to the public.
41 |
42 | The GNU Affero General Public License is designed specifically to
43 | ensure that, in such cases, the modified source code becomes available
44 | to the community. It requires the operator of a network server to
45 | provide the source code of the modified version running there to the
46 | users of that server. Therefore, public use of a modified version, on
47 | a publicly accessible server, gives the public access to the source
48 | code of the modified version.
49 |
50 | An older license, called the Affero General Public License and
51 | published by Affero, was designed to accomplish similar goals. This is
52 | a different license, not a version of the Affero GPL, but Affero has
53 | released a new version of the Affero GPL which permits relicensing under
54 | this license.
55 |
56 | The precise terms and conditions for copying, distribution and
57 | modification follow.
58 |
59 | TERMS AND CONDITIONS
60 |
61 | 0. Definitions.
62 |
63 | "This License" refers to version 3 of the GNU Affero General Public License.
64 |
65 | "Copyright" also means copyright-like laws that apply to other kinds of
66 | works, such as semiconductor masks.
67 |
68 | "The Program" refers to any copyrightable work licensed under this
69 | License. Each licensee is addressed as "you". "Licensees" and
70 | "recipients" may be individuals or organizations.
71 |
72 | To "modify" a work means to copy from or adapt all or part of the work
73 | in a fashion requiring copyright permission, other than the making of an
74 | exact copy. The resulting work is called a "modified version" of the
75 | earlier work or a work "based on" the earlier work.
76 |
77 | A "covered work" means either the unmodified Program or a work based
78 | on the Program.
79 |
80 | To "propagate" a work means to do anything with it that, without
81 | permission, would make you directly or secondarily liable for
82 | infringement under applicable copyright law, except executing it on a
83 | computer or modifying a private copy. Propagation includes copying,
84 | distribution (with or without modification), making available to the
85 | public, and in some countries other activities as well.
86 |
87 | To "convey" a work means any kind of propagation that enables other
88 | parties to make or receive copies. Mere interaction with a user through
89 | a computer network, with no transfer of a copy, is not conveying.
90 |
91 | An interactive user interface displays "Appropriate Legal Notices"
92 | to the extent that it includes a convenient and prominently visible
93 | feature that (1) displays an appropriate copyright notice, and (2)
94 | tells the user that there is no warranty for the work (except to the
95 | extent that warranties are provided), that licensees may convey the
96 | work under this License, and how to view a copy of this License. If
97 | the interface presents a list of user commands or options, such as a
98 | menu, a prominent item in the list meets this criterion.
99 |
100 | 1. Source Code.
101 |
102 | The "source code" for a work means the preferred form of the work
103 | for making modifications to it. "Object code" means any non-source
104 | form of a work.
105 |
106 | A "Standard Interface" means an interface that either is an official
107 | standard defined by a recognized standards body, or, in the case of
108 | interfaces specified for a particular programming language, one that
109 | is widely used among developers working in that language.
110 |
111 | The "System Libraries" of an executable work include anything, other
112 | than the work as a whole, that (a) is included in the normal form of
113 | packaging a Major Component, but which is not part of that Major
114 | Component, and (b) serves only to enable use of the work with that
115 | Major Component, or to implement a Standard Interface for which an
116 | implementation is available to the public in source code form. A
117 | "Major Component", in this context, means a major essential component
118 | (kernel, window system, and so on) of the specific operating system
119 | (if any) on which the executable work runs, or a compiler used to
120 | produce the work, or an object code interpreter used to run it.
121 |
122 | The "Corresponding Source" for a work in object code form means all
123 | the source code needed to generate, install, and (for an executable
124 | work) run the object code and to modify the work, including scripts to
125 | control those activities. However, it does not include the work's
126 | System Libraries, or general-purpose tools or generally available free
127 | programs which are used unmodified in performing those activities but
128 | which are not part of the work. For example, Corresponding Source
129 | includes interface definition files associated with source files for
130 | the work, and the source code for shared libraries and dynamically
131 | linked subprograms that the work is specifically designed to require,
132 | such as by intimate data communication or control flow between those
133 | subprograms and other parts of the work.
134 |
135 | The Corresponding Source need not include anything that users
136 | can regenerate automatically from other parts of the Corresponding
137 | Source.
138 |
139 | The Corresponding Source for a work in source code form is that
140 | same work.
141 |
142 | 2. Basic Permissions.
143 |
144 | All rights granted under this License are granted for the term of
145 | copyright on the Program, and are irrevocable provided the stated
146 | conditions are met. This License explicitly affirms your unlimited
147 | permission to run the unmodified Program. The output from running a
148 | covered work is covered by this License only if the output, given its
149 | content, constitutes a covered work. This License acknowledges your
150 | rights of fair use or other equivalent, as provided by copyright law.
151 |
152 | You may make, run and propagate covered works that you do not
153 | convey, without conditions so long as your license otherwise remains
154 | in force. You may convey covered works to others for the sole purpose
155 | of having them make modifications exclusively for you, or provide you
156 | with facilities for running those works, provided that you comply with
157 | the terms of this License in conveying all material for which you do
158 | not control copyright. Those thus making or running the covered works
159 | for you must do so exclusively on your behalf, under your direction
160 | and control, on terms that prohibit them from making any copies of
161 | your copyrighted material outside their relationship with you.
162 |
163 | Conveying under any other circumstances is permitted solely under
164 | the conditions stated below. Sublicensing is not allowed; section 10
165 | makes it unnecessary.
166 |
167 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
168 |
169 | No covered work shall be deemed part of an effective technological
170 | measure under any applicable law fulfilling obligations under article
171 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
172 | similar laws prohibiting or restricting circumvention of such
173 | measures.
174 |
175 | When you convey a covered work, you waive any legal power to forbid
176 | circumvention of technological measures to the extent such circumvention
177 | is effected by exercising rights under this License with respect to
178 | the covered work, and you disclaim any intention to limit operation or
179 | modification of the work as a means of enforcing, against the work's
180 | users, your or third parties' legal rights to forbid circumvention of
181 | technological measures.
182 |
183 | 4. Conveying Verbatim Copies.
184 |
185 | You may convey verbatim copies of the Program's source code as you
186 | receive it, in any medium, provided that you conspicuously and
187 | appropriately publish on each copy an appropriate copyright notice;
188 | keep intact all notices stating that this License and any
189 | non-permissive terms added in accord with section 7 apply to the code;
190 | keep intact all notices of the absence of any warranty; and give all
191 | recipients a copy of this License along with the Program.
192 |
193 | You may charge any price or no price for each copy that you convey,
194 | and you may offer support or warranty protection for a fee.
195 |
196 | 5. Conveying Modified Source Versions.
197 |
198 | You may convey a work based on the Program, or the modifications to
199 | produce it from the Program, in the form of source code under the
200 | terms of section 4, provided that you also meet all of these conditions:
201 |
202 | a) The work must carry prominent notices stating that you modified
203 | it, and giving a relevant date.
204 |
205 | b) The work must carry prominent notices stating that it is
206 | released under this License and any conditions added under section
207 | 7. This requirement modifies the requirement in section 4 to
208 | "keep intact all notices".
209 |
210 | c) You must license the entire work, as a whole, under this
211 | License to anyone who comes into possession of a copy. This
212 | License will therefore apply, along with any applicable section 7
213 | additional terms, to the whole of the work, and all its parts,
214 | regardless of how they are packaged. This License gives no
215 | permission to license the work in any other way, but it does not
216 | invalidate such permission if you have separately received it.
217 |
218 | d) If the work has interactive user interfaces, each must display
219 | Appropriate Legal Notices; however, if the Program has interactive
220 | interfaces that do not display Appropriate Legal Notices, your
221 | work need not make them do so.
222 |
223 | A compilation of a covered work with other separate and independent
224 | works, which are not by their nature extensions of the covered work,
225 | and which are not combined with it such as to form a larger program,
226 | in or on a volume of a storage or distribution medium, is called an
227 | "aggregate" if the compilation and its resulting copyright are not
228 | used to limit the access or legal rights of the compilation's users
229 | beyond what the individual works permit. Inclusion of a covered work
230 | in an aggregate does not cause this License to apply to the other
231 | parts of the aggregate.
232 |
233 | 6. Conveying Non-Source Forms.
234 |
235 | You may convey a covered work in object code form under the terms
236 | of sections 4 and 5, provided that you also convey the
237 | machine-readable Corresponding Source under the terms of this License,
238 | in one of these ways:
239 |
240 | a) Convey the object code in, or embodied in, a physical product
241 | (including a physical distribution medium), accompanied by the
242 | Corresponding Source fixed on a durable physical medium
243 | customarily used for software interchange.
244 |
245 | b) Convey the object code in, or embodied in, a physical product
246 | (including a physical distribution medium), accompanied by a
247 | written offer, valid for at least three years and valid for as
248 | long as you offer spare parts or customer support for that product
249 | model, to give anyone who possesses the object code either (1) a
250 | copy of the Corresponding Source for all the software in the
251 | product that is covered by this License, on a durable physical
252 | medium customarily used for software interchange, for a price no
253 | more than your reasonable cost of physically performing this
254 | conveying of source, or (2) access to copy the
255 | Corresponding Source from a network server at no charge.
256 |
257 | c) Convey individual copies of the object code with a copy of the
258 | written offer to provide the Corresponding Source. This
259 | alternative is allowed only occasionally and noncommercially, and
260 | only if you received the object code with such an offer, in accord
261 | with subsection 6b.
262 |
263 | d) Convey the object code by offering access from a designated
264 | place (gratis or for a charge), and offer equivalent access to the
265 | Corresponding Source in the same way through the same place at no
266 | further charge. You need not require recipients to copy the
267 | Corresponding Source along with the object code. If the place to
268 | copy the object code is a network server, the Corresponding Source
269 | may be on a different server (operated by you or a third party)
270 | that supports equivalent copying facilities, provided you maintain
271 | clear directions next to the object code saying where to find the
272 | Corresponding Source. Regardless of what server hosts the
273 | Corresponding Source, you remain obligated to ensure that it is
274 | available for as long as needed to satisfy these requirements.
275 |
276 | e) Convey the object code using peer-to-peer transmission, provided
277 | you inform other peers where the object code and Corresponding
278 | Source of the work are being offered to the general public at no
279 | charge under subsection 6d.
280 |
281 | A separable portion of the object code, whose source code is excluded
282 | from the Corresponding Source as a System Library, need not be
283 | included in conveying the object code work.
284 |
285 | A "User Product" is either (1) a "consumer product", which means any
286 | tangible personal property which is normally used for personal, family,
287 | or household purposes, or (2) anything designed or sold for incorporation
288 | into a dwelling. In determining whether a product is a consumer product,
289 | doubtful cases shall be resolved in favor of coverage. For a particular
290 | product received by a particular user, "normally used" refers to a
291 | typical or common use of that class of product, regardless of the status
292 | of the particular user or of the way in which the particular user
293 | actually uses, or expects or is expected to use, the product. A product
294 | is a consumer product regardless of whether the product has substantial
295 | commercial, industrial or non-consumer uses, unless such uses represent
296 | the only significant mode of use of the product.
297 |
298 | "Installation Information" for a User Product means any methods,
299 | procedures, authorization keys, or other information required to install
300 | and execute modified versions of a covered work in that User Product from
301 | a modified version of its Corresponding Source. The information must
302 | suffice to ensure that the continued functioning of the modified object
303 | code is in no case prevented or interfered with solely because
304 | modification has been made.
305 |
306 | If you convey an object code work under this section in, or with, or
307 | specifically for use in, a User Product, and the conveying occurs as
308 | part of a transaction in which the right of possession and use of the
309 | User Product is transferred to the recipient in perpetuity or for a
310 | fixed term (regardless of how the transaction is characterized), the
311 | Corresponding Source conveyed under this section must be accompanied
312 | by the Installation Information. But this requirement does not apply
313 | if neither you nor any third party retains the ability to install
314 | modified object code on the User Product (for example, the work has
315 | been installed in ROM).
316 |
317 | The requirement to provide Installation Information does not include a
318 | requirement to continue to provide support service, warranty, or updates
319 | for a work that has been modified or installed by the recipient, or for
320 | the User Product in which it has been modified or installed. Access to a
321 | network may be denied when the modification itself materially and
322 | adversely affects the operation of the network or violates the rules and
323 | protocols for communication across the network.
324 |
325 | Corresponding Source conveyed, and Installation Information provided,
326 | in accord with this section must be in a format that is publicly
327 | documented (and with an implementation available to the public in
328 | source code form), and must require no special password or key for
329 | unpacking, reading or copying.
330 |
331 | 7. Additional Terms.
332 |
333 | "Additional permissions" are terms that supplement the terms of this
334 | License by making exceptions from one or more of its conditions.
335 | Additional permissions that are applicable to the entire Program shall
336 | be treated as though they were included in this License, to the extent
337 | that they are valid under applicable law. If additional permissions
338 | apply only to part of the Program, that part may be used separately
339 | under those permissions, but the entire Program remains governed by
340 | this License without regard to the additional permissions.
341 |
342 | When you convey a copy of a covered work, you may at your option
343 | remove any additional permissions from that copy, or from any part of
344 | it. (Additional permissions may be written to require their own
345 | removal in certain cases when you modify the work.) You may place
346 | additional permissions on material, added by you to a covered work,
347 | for which you have or can give appropriate copyright permission.
348 |
349 | Notwithstanding any other provision of this License, for material you
350 | add to a covered work, you may (if authorized by the copyright holders of
351 | that material) supplement the terms of this License with terms:
352 |
353 | a) Disclaiming warranty or limiting liability differently from the
354 | terms of sections 15 and 16 of this License; or
355 |
356 | b) Requiring preservation of specified reasonable legal notices or
357 | author attributions in that material or in the Appropriate Legal
358 | Notices displayed by works containing it; or
359 |
360 | c) Prohibiting misrepresentation of the origin of that material, or
361 | requiring that modified versions of such material be marked in
362 | reasonable ways as different from the original version; or
363 |
364 | d) Limiting the use for publicity purposes of names of licensors or
365 | authors of the material; or
366 |
367 | e) Declining to grant rights under trademark law for use of some
368 | trade names, trademarks, or service marks; or
369 |
370 | f) Requiring indemnification of licensors and authors of that
371 | material by anyone who conveys the material (or modified versions of
372 | it) with contractual assumptions of liability to the recipient, for
373 | any liability that these contractual assumptions directly impose on
374 | those licensors and authors.
375 |
376 | All other non-permissive additional terms are considered "further
377 | restrictions" within the meaning of section 10. If the Program as you
378 | received it, or any part of it, contains a notice stating that it is
379 | governed by this License along with a term that is a further
380 | restriction, you may remove that term. If a license document contains
381 | a further restriction but permits relicensing or conveying under this
382 | License, you may add to a covered work material governed by the terms
383 | of that license document, provided that the further restriction does
384 | not survive such relicensing or conveying.
385 |
386 | If you add terms to a covered work in accord with this section, you
387 | must place, in the relevant source files, a statement of the
388 | additional terms that apply to those files, or a notice indicating
389 | where to find the applicable terms.
390 |
391 | Additional terms, permissive or non-permissive, may be stated in the
392 | form of a separately written license, or stated as exceptions;
393 | the above requirements apply either way.
394 |
395 | 8. Termination.
396 |
397 | You may not propagate or modify a covered work except as expressly
398 | provided under this License. Any attempt otherwise to propagate or
399 | modify it is void, and will automatically terminate your rights under
400 | this License (including any patent licenses granted under the third
401 | paragraph of section 11).
402 |
403 | However, if you cease all violation of this License, then your
404 | license from a particular copyright holder is reinstated (a)
405 | provisionally, unless and until the copyright holder explicitly and
406 | finally terminates your license, and (b) permanently, if the copyright
407 | holder fails to notify you of the violation by some reasonable means
408 | prior to 60 days after the cessation.
409 |
410 | Moreover, your license from a particular copyright holder is
411 | reinstated permanently if the copyright holder notifies you of the
412 | violation by some reasonable means, this is the first time you have
413 | received notice of violation of this License (for any work) from that
414 | copyright holder, and you cure the violation prior to 30 days after
415 | your receipt of the notice.
416 |
417 | Termination of your rights under this section does not terminate the
418 | licenses of parties who have received copies or rights from you under
419 | this License. If your rights have been terminated and not permanently
420 | reinstated, you do not qualify to receive new licenses for the same
421 | material under section 10.
422 |
423 | 9. Acceptance Not Required for Having Copies.
424 |
425 | You are not required to accept this License in order to receive or
426 | run a copy of the Program. Ancillary propagation of a covered work
427 | occurring solely as a consequence of using peer-to-peer transmission
428 | to receive a copy likewise does not require acceptance. However,
429 | nothing other than this License grants you permission to propagate or
430 | modify any covered work. These actions infringe copyright if you do
431 | not accept this License. Therefore, by modifying or propagating a
432 | covered work, you indicate your acceptance of this License to do so.
433 |
434 | 10. Automatic Licensing of Downstream Recipients.
435 |
436 | Each time you convey a covered work, the recipient automatically
437 | receives a license from the original licensors, to run, modify and
438 | propagate that work, subject to this License. You are not responsible
439 | for enforcing compliance by third parties with this License.
440 |
441 | An "entity transaction" is a transaction transferring control of an
442 | organization, or substantially all assets of one, or subdividing an
443 | organization, or merging organizations. If propagation of a covered
444 | work results from an entity transaction, each party to that
445 | transaction who receives a copy of the work also receives whatever
446 | licenses to the work the party's predecessor in interest had or could
447 | give under the previous paragraph, plus a right to possession of the
448 | Corresponding Source of the work from the predecessor in interest, if
449 | the predecessor has it or can get it with reasonable efforts.
450 |
451 | You may not impose any further restrictions on the exercise of the
452 | rights granted or affirmed under this License. For example, you may
453 | not impose a license fee, royalty, or other charge for exercise of
454 | rights granted under this License, and you may not initiate litigation
455 | (including a cross-claim or counterclaim in a lawsuit) alleging that
456 | any patent claim is infringed by making, using, selling, offering for
457 | sale, or importing the Program or any portion of it.
458 |
459 | 11. Patents.
460 |
461 | A "contributor" is a copyright holder who authorizes use under this
462 | License of the Program or a work on which the Program is based. The
463 | work thus licensed is called the contributor's "contributor version".
464 |
465 | A contributor's "essential patent claims" are all patent claims
466 | owned or controlled by the contributor, whether already acquired or
467 | hereafter acquired, that would be infringed by some manner, permitted
468 | by this License, of making, using, or selling its contributor version,
469 | but do not include claims that would be infringed only as a
470 | consequence of further modification of the contributor version. For
471 | purposes of this definition, "control" includes the right to grant
472 | patent sublicenses in a manner consistent with the requirements of
473 | this License.
474 |
475 | Each contributor grants you a non-exclusive, worldwide, royalty-free
476 | patent license under the contributor's essential patent claims, to
477 | make, use, sell, offer for sale, import and otherwise run, modify and
478 | propagate the contents of its contributor version.
479 |
480 | In the following three paragraphs, a "patent license" is any express
481 | agreement or commitment, however denominated, not to enforce a patent
482 | (such as an express permission to practice a patent or covenant not to
483 | sue for patent infringement). To "grant" such a patent license to a
484 | party means to make such an agreement or commitment not to enforce a
485 | patent against the party.
486 |
487 | If you convey a covered work, knowingly relying on a patent license,
488 | and the Corresponding Source of the work is not available for anyone
489 | to copy, free of charge and under the terms of this License, through a
490 | publicly available network server or other readily accessible means,
491 | then you must either (1) cause the Corresponding Source to be so
492 | available, or (2) arrange to deprive yourself of the benefit of the
493 | patent license for this particular work, or (3) arrange, in a manner
494 | consistent with the requirements of this License, to extend the patent
495 | license to downstream recipients. "Knowingly relying" means you have
496 | actual knowledge that, but for the patent license, your conveying the
497 | covered work in a country, or your recipient's use of the covered work
498 | in a country, would infringe one or more identifiable patents in that
499 | country that you have reason to believe are valid.
500 |
501 | If, pursuant to or in connection with a single transaction or
502 | arrangement, you convey, or propagate by procuring conveyance of, a
503 | covered work, and grant a patent license to some of the parties
504 | receiving the covered work authorizing them to use, propagate, modify
505 | or convey a specific copy of the covered work, then the patent license
506 | you grant is automatically extended to all recipients of the covered
507 | work and works based on it.
508 |
509 | A patent license is "discriminatory" if it does not include within
510 | the scope of its coverage, prohibits the exercise of, or is
511 | conditioned on the non-exercise of one or more of the rights that are
512 | specifically granted under this License. You may not convey a covered
513 | work if you are a party to an arrangement with a third party that is
514 | in the business of distributing software, under which you make payment
515 | to the third party based on the extent of your activity of conveying
516 | the work, and under which the third party grants, to any of the
517 | parties who would receive the covered work from you, a discriminatory
518 | patent license (a) in connection with copies of the covered work
519 | conveyed by you (or copies made from those copies), or (b) primarily
520 | for and in connection with specific products or compilations that
521 | contain the covered work, unless you entered into that arrangement,
522 | or that patent license was granted, prior to 28 March 2007.
523 |
524 | Nothing in this License shall be construed as excluding or limiting
525 | any implied license or other defenses to infringement that may
526 | otherwise be available to you under applicable patent law.
527 |
528 | 12. No Surrender of Others' Freedom.
529 |
530 | If conditions are imposed on you (whether by court order, agreement or
531 | otherwise) that contradict the conditions of this License, they do not
532 | excuse you from the conditions of this License. If you cannot convey a
533 | covered work so as to satisfy simultaneously your obligations under this
534 | License and any other pertinent obligations, then as a consequence you may
535 | not convey it at all. For example, if you agree to terms that obligate you
536 | to collect a royalty for further conveying from those to whom you convey
537 | the Program, the only way you could satisfy both those terms and this
538 | License would be to refrain entirely from conveying the Program.
539 |
540 | 13. Remote Network Interaction; Use with the GNU General Public License.
541 |
542 | Notwithstanding any other provision of this License, if you modify the
543 | Program, your modified version must prominently offer all users
544 | interacting with it remotely through a computer network (if your version
545 | supports such interaction) an opportunity to receive the Corresponding
546 | Source of your version by providing access to the Corresponding Source
547 | from a network server at no charge, through some standard or customary
548 | means of facilitating copying of software. This Corresponding Source
549 | shall include the Corresponding Source for any work covered by version 3
550 | of the GNU General Public License that is incorporated pursuant to the
551 | following paragraph.
552 |
553 | Notwithstanding any other provision of this License, you have
554 | permission to link or combine any covered work with a work licensed
555 | under version 3 of the GNU General Public License into a single
556 | combined work, and to convey the resulting work. The terms of this
557 | License will continue to apply to the part which is the covered work,
558 | but the work with which it is combined will remain governed by version
559 | 3 of the GNU General Public License.
560 |
561 | 14. Revised Versions of this License.
562 |
563 | The Free Software Foundation may publish revised and/or new versions of
564 | the GNU Affero General Public License from time to time. Such new versions
565 | will be similar in spirit to the present version, but may differ in detail to
566 | address new problems or concerns.
567 |
568 | Each version is given a distinguishing version number. If the
569 | Program specifies that a certain numbered version of the GNU Affero General
570 | Public License "or any later version" applies to it, you have the
571 | option of following the terms and conditions either of that numbered
572 | version or of any later version published by the Free Software
573 | Foundation. If the Program does not specify a version number of the
574 | GNU Affero General Public License, you may choose any version ever published
575 | by the Free Software Foundation.
576 |
577 | If the Program specifies that a proxy can decide which future
578 | versions of the GNU Affero General Public License can be used, that proxy's
579 | public statement of acceptance of a version permanently authorizes you
580 | to choose that version for the Program.
581 |
582 | Later license versions may give you additional or different
583 | permissions. However, no additional obligations are imposed on any
584 | author or copyright holder as a result of your choosing to follow a
585 | later version.
586 |
587 | 15. Disclaimer of Warranty.
588 |
589 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
590 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
591 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
592 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
593 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
594 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
595 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
596 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
597 |
598 | 16. Limitation of Liability.
599 |
600 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
601 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
602 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
603 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
604 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
605 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
606 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
607 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
608 | SUCH DAMAGES.
609 |
610 | 17. Interpretation of Sections 15 and 16.
611 |
612 | If the disclaimer of warranty and limitation of liability provided
613 | above cannot be given local legal effect according to their terms,
614 | reviewing courts shall apply local law that most closely approximates
615 | an absolute waiver of all civil liability in connection with the
616 | Program, unless a warranty or assumption of liability accompanies a
617 | copy of the Program in return for a fee.
618 |
619 | END OF TERMS AND CONDITIONS
620 |
621 | How to Apply These Terms to Your New Programs
622 |
623 | If you develop a new program, and you want it to be of the greatest
624 | possible use to the public, the best way to achieve this is to make it
625 | free software which everyone can redistribute and change under these terms.
626 |
627 | To do so, attach the following notices to the program. It is safest
628 | to attach them to the start of each source file to most effectively
629 | state the exclusion of warranty; and each file should have at least
630 | the "copyright" line and a pointer to where the full notice is found.
631 |
632 |
633 | Copyright (C)
634 |
635 | This program is free software: you can redistribute it and/or modify
636 | it under the terms of the GNU Affero General Public License as published
637 | by the Free Software Foundation, either version 3 of the License, or
638 | (at your option) any later version.
639 |
640 | This program is distributed in the hope that it will be useful,
641 | but WITHOUT ANY WARRANTY; without even the implied warranty of
642 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
643 | GNU Affero General Public License for more details.
644 |
645 | You should have received a copy of the GNU Affero General Public License
646 | along with this program. If not, see .
647 |
648 | Also add information on how to contact you by electronic and paper mail.
649 |
650 | If your software can interact with users remotely through a computer
651 | network, you should also make sure that it provides a way for users to
652 | get its source. For example, if your program is a web application, its
653 | interface could display a "Source" link that leads users to an archive
654 | of the code. There are many ways you could offer source, and different
655 | solutions will be better for different programs; see section 13 for the
656 | specific requirements.
657 |
658 | You should also get your employer (if you work as a programmer) or school,
659 | if any, to sign a "copyright disclaimer" for the program, if necessary.
660 | For more information on this, and how to apply and follow the GNU AGPL, see
661 | .
662 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # EOS Smart Contracts for Cambiatus
2 |
3 | All of our Cambiatus Smart contracts lives here. You'll find everything you need to run here.
4 |
5 | ## Install
6 |
7 | ```
8 | git clone https://github.com/cambiatus/contracts.git
9 | ```
10 |
11 | Our docker setup include two nodes `keosd` and `nodeosd`. The `keosd` is responsible for running the wallet and as well the `cleos` commmand, since this way `cleos` won't spin up its own version of `keosd` daemon everytime you invoke it. The other `nodeos` node is responsible for running the blockchain and compiling files.
12 |
13 | ## Build
14 |
15 | Building the Community Contract
16 |
17 | ```
18 | cd community
19 | make
20 | ```
21 |
22 | ## Attention
23 |
24 | This repo only works using [eosio.cdt](https://github.com/EOSIO/eosio.cdt/releases/tag/v1.7.0) version `v1.7.0`
25 |
26 | ## Setting up a Local EOS Environment
27 |
28 | To setup a local environment you need to install locally a version of EOSIO;
29 | if installed properly, it will add `nodeos` and `cleos` to your binaries.
30 |
31 | Then you can execute the following commands:
32 |
33 | ```sh
34 | WALLET_PASSWORD="YOUR--EOS--WALLET--PASS"
35 | CONTRACT="cambiatus.cm"
36 | TOKEN_CONTRACT="cambiatus.tk"
37 | BACKEND_ACC="cambiatus"
38 | PUBLIC_KEY="EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV"
39 |
40 | nohup nodeos -e -p eosio \
41 | --data-dir .nodeos/data \
42 | --config-dir .nodeos/config \
43 | --plugin eosio::producer_plugin \
44 | --plugin eosio::producer_api_plugin \
45 | --plugin eosio::chain_api_plugin \
46 | --plugin eosio::history_plugin \
47 | --plugin eosio::history_api_plugin \
48 | --plugin eosio::http_plugin \
49 | --plugin eosio::state_history_plugin \
50 | --access-control-allow-origin='*' \
51 | --contracts-console \
52 | --http-validate-host=false \
53 | --trace-history \
54 | --chain-state-history \
55 | --verbose-http-errors \
56 | --filter-on='*' \
57 | --disable-replay-opts \
58 | --delete-all-blocks &
59 |
60 | curl -X POST http://127.0.0.1:8888/v1/producer/schedule_protocol_feature_activations -d '{"protocol_features_to_activate": ["0ec7e080177b2c02b278d5088611686b49d739925a92d9bfcacd7fc6b74053bd"]}'
61 |
62 | cleos set code eosio ./tests/eosio.contracts/eosio.bios.wasm -p eosio
63 | cleos set abi eosio ./tests/eosio.contracts/eosio.bios.abi -p eosio
64 |
65 | cleos push action eosio activate '["f0af56d2c5a48d60a4a5b5c903edfb7db3a736a94ed589d0b797df33ff9d3e1d"]' -p eosio # GET_SENDER
66 |
67 | cleos create account eosio $CONTRACT $PUBLIC_KEY $PUBLIC_KEY
68 | cleos create account eosio $TOKEN_CONTRACT $PUBLIC_KEY $PUBLIC_KEY
69 |
70 | cleos set account permission $TOKEN_CONTRACT active '{"threshold": 1, "keys": [{"key": "'$PUBLIC_KEY'", "weight": 1}], "accounts": [{"permission": {"actor": "'$CONTRACT'", "permission": "eosio.code"}, "weight": 1}]}' owner
71 |
72 | cleos set account permission $CONTRACT active '{"threshold": 1, "keys": [{"key": "'$PUBLIC_KEY'", "weight": 1}], "accounts": [{"permission": {"actor": "'$TOKEN_CONTRACT'", "permission": "eosio.code"}, "weight": 1}]}' owner
73 |
74 | cleos set account permission $CONTRACT active --add-code
75 | cleos set account permission $TOKEN_CONTRACT active --add-code
76 |
77 | cleos create account eosio $BACKEND_ACC $PUBLIC_KEY $PUBLIC_KEY
78 |
79 | cleos set code $CONTRACT ../community/community.wasm
80 | cleos set abi $CONTRACT ../community/community.abi
81 |
82 | cleos set code $TOKEN_CONTRACT ../token/token.wasm
83 | cleos set abi $TOKEN_CONTRACT ../token/token.abi
84 | ```
85 |
--------------------------------------------------------------------------------
/community/Makefile:
--------------------------------------------------------------------------------
1 | .PHONY: community.wasm
2 |
3 | src = $(wildcard *.cpp)
4 | obj = $(src:.cpp=.wasm)
5 | OPTS = -D'__TOKEN_ACCOUNT__=cambiatus.tk' -D'__BACKEND_ACCOUNT__=cambiatus' -D'__PROOF_EXPIRATION_SECS__=1800'
6 |
7 | contract = cambiatus.cm
8 | contract_authorization = $(contract)@active
9 | # authorization = lucca@active
10 | authorization = cambiatus@active
11 |
12 | url = https://staging.cambiatus.io
13 | # url = https://demo.cambiatus.io
14 | # url = https://app.cambiatus.io
15 |
16 | cleos = cleos -u $(url)
17 | push_adm = $(cleos) push action $(contract) $^ -p $(contract_authorization)
18 | push = $(cleos) push action $(contract) $^ -p $(authorization)
19 |
20 | community.wasm: $(src)
21 | eosio-cpp -w $(OPTS) -o $@ $^ --no-missing-ricardian-clause
22 |
23 | clean:
24 | rm $(obj)
25 |
26 | deploy:
27 | $(cleos) set contract $(contract) ../community
28 |
29 | erase:
30 | # $(push_adm) clean '["role", "", "0,TISA"]'
31 | # $(push_adm) clean '["member", "", "0,CMB"]'
32 | # $(push_adm) clean '["sale", "", "0,XXX"]'
33 |
34 | invite:
35 | # $(push) netlink '["0,MIZU", "lucca", "memberdev123", "natural"]'
36 |
37 |
38 | fill-role:
39 | $(push_adm) upsertrole '{"community_id": "0,GOPLAY", "name": "member", "color": "#ffffff", "permissions": ["invite", "claim", "order", "verify", "sell", "transfer"]}'
40 |
41 | # $(push) upsertrole '{"community_id": "0,MUDA", "name": "validator", "color": "#f26c48", "permissions": ["verify"]}'
42 |
43 | migrate-users:
44 | # $(push_adm) migrateusers '["0,VRD"]'
45 |
46 |
47 | assign-role:
48 | # $(push) assignrole '{"community_id": "0,MIZU", "member": "lucca", "roles": ["member", "validator"]} '
49 |
50 | objective:
51 | # $(push) upsertobjctv '["0,MIZU", 0, "## New community goal", "lucca"]'
52 |
53 | action:
54 | # $(push) upsertaction '["0,MIZU", 0, 94 , "New claimable action", "30 MIZU", "3 MIZU", 0, 0, 0, 3, "claimable", "lucca-karla-henriquebuss", 0, "lucca", 0, 0, ""]'
55 | # $(push) upsertaction '["0,MIZU", 0, 94 , "Automatic action", "30 MIZU", "3 MIZU", 0, 0, 0, 3, "automatic", "lucca-karla-henriquebuss", 0, "lucca", 0, 0, ""]'
56 |
57 | reward:
58 | # $(push) reward '["0,MIZU", 172, "karla", "lucca"]'
59 |
60 | claim:
61 | # $(push) claimaction '["0,MIZU", 171, "lucca", "", "", 0]'
62 |
63 | verify:
64 | # $(push) verifyclaim '["0,MIZU", 336, "lucca", 1]'
--------------------------------------------------------------------------------
/community/community.abi:
--------------------------------------------------------------------------------
1 | {
2 | "____comment": "This file was generated with eosio-abigen. DO NOT EDIT ",
3 | "version": "eosio::abi/1.2",
4 | "types": [],
5 | "structs": [
6 | {
7 | "name": "action",
8 | "base": "",
9 | "fields": [
10 | {
11 | "name": "id",
12 | "type": "uint64"
13 | },
14 | {
15 | "name": "objective_id",
16 | "type": "uint64"
17 | },
18 | {
19 | "name": "description",
20 | "type": "string"
21 | },
22 | {
23 | "name": "reward",
24 | "type": "asset"
25 | },
26 | {
27 | "name": "verifier_reward",
28 | "type": "asset"
29 | },
30 | {
31 | "name": "deadline",
32 | "type": "uint64"
33 | },
34 | {
35 | "name": "usages",
36 | "type": "uint64"
37 | },
38 | {
39 | "name": "usages_left",
40 | "type": "uint64"
41 | },
42 | {
43 | "name": "verifications",
44 | "type": "uint64"
45 | },
46 | {
47 | "name": "verification_type",
48 | "type": "string"
49 | },
50 | {
51 | "name": "is_completed",
52 | "type": "uint8"
53 | },
54 | {
55 | "name": "creator",
56 | "type": "name"
57 | },
58 | {
59 | "name": "has_proof_photo",
60 | "type": "uint8"
61 | },
62 | {
63 | "name": "has_proof_code",
64 | "type": "uint8"
65 | },
66 | {
67 | "name": "photo_proof_instructions",
68 | "type": "string"
69 | }
70 | ]
71 | },
72 | {
73 | "name": "action_validator",
74 | "base": "",
75 | "fields": [
76 | {
77 | "name": "id",
78 | "type": "uint64"
79 | },
80 | {
81 | "name": "action_id",
82 | "type": "uint64"
83 | },
84 | {
85 | "name": "validator",
86 | "type": "name"
87 | }
88 | ]
89 | },
90 | {
91 | "name": "assignroles",
92 | "base": "",
93 | "fields": [
94 | {
95 | "name": "community_id",
96 | "type": "symbol"
97 | },
98 | {
99 | "name": "member",
100 | "type": "name"
101 | },
102 | {
103 | "name": "roles",
104 | "type": "name[]"
105 | }
106 | ]
107 | },
108 | {
109 | "name": "check",
110 | "base": "",
111 | "fields": [
112 | {
113 | "name": "id",
114 | "type": "uint64"
115 | },
116 | {
117 | "name": "claim_id",
118 | "type": "uint64"
119 | },
120 | {
121 | "name": "validator",
122 | "type": "name"
123 | },
124 | {
125 | "name": "is_verified",
126 | "type": "uint8"
127 | }
128 | ]
129 | },
130 | {
131 | "name": "claim",
132 | "base": "",
133 | "fields": [
134 | {
135 | "name": "id",
136 | "type": "uint64"
137 | },
138 | {
139 | "name": "action_id",
140 | "type": "uint64"
141 | },
142 | {
143 | "name": "claimer",
144 | "type": "name"
145 | },
146 | {
147 | "name": "status",
148 | "type": "string"
149 | },
150 | {
151 | "name": "proof_photo",
152 | "type": "string"
153 | },
154 | {
155 | "name": "proof_code",
156 | "type": "string"
157 | }
158 | ]
159 | },
160 | {
161 | "name": "claimaction",
162 | "base": "",
163 | "fields": [
164 | {
165 | "name": "community_id",
166 | "type": "symbol"
167 | },
168 | {
169 | "name": "action_id",
170 | "type": "uint64"
171 | },
172 | {
173 | "name": "maker",
174 | "type": "name"
175 | },
176 | {
177 | "name": "proof_photo",
178 | "type": "string"
179 | },
180 | {
181 | "name": "proof_code",
182 | "type": "string"
183 | },
184 | {
185 | "name": "proof_time",
186 | "type": "uint32"
187 | }
188 | ]
189 | },
190 | {
191 | "name": "clean",
192 | "base": "",
193 | "fields": [
194 | {
195 | "name": "t",
196 | "type": "string"
197 | },
198 | {
199 | "name": "name_scope",
200 | "type": "name"
201 | },
202 | {
203 | "name": "symbol_scope",
204 | "type": "symbol"
205 | }
206 | ]
207 | },
208 | {
209 | "name": "community",
210 | "base": "",
211 | "fields": [
212 | {
213 | "name": "symbol",
214 | "type": "symbol"
215 | },
216 | {
217 | "name": "creator",
218 | "type": "name"
219 | },
220 | {
221 | "name": "logo",
222 | "type": "string"
223 | },
224 | {
225 | "name": "name",
226 | "type": "string"
227 | },
228 | {
229 | "name": "description",
230 | "type": "string"
231 | },
232 | {
233 | "name": "inviter_reward",
234 | "type": "asset"
235 | },
236 | {
237 | "name": "invited_reward",
238 | "type": "asset"
239 | },
240 | {
241 | "name": "has_objectives",
242 | "type": "uint8"
243 | },
244 | {
245 | "name": "has_shop",
246 | "type": "uint8"
247 | },
248 | {
249 | "name": "has_kyc",
250 | "type": "uint8"
251 | }
252 | ]
253 | },
254 | {
255 | "name": "create",
256 | "base": "",
257 | "fields": [
258 | {
259 | "name": "cmm_asset",
260 | "type": "asset"
261 | },
262 | {
263 | "name": "creator",
264 | "type": "name"
265 | },
266 | {
267 | "name": "logo",
268 | "type": "string"
269 | },
270 | {
271 | "name": "name",
272 | "type": "string"
273 | },
274 | {
275 | "name": "description",
276 | "type": "string"
277 | },
278 | {
279 | "name": "inviter_reward",
280 | "type": "asset"
281 | },
282 | {
283 | "name": "invited_reward",
284 | "type": "asset"
285 | },
286 | {
287 | "name": "has_objectives",
288 | "type": "uint8"
289 | },
290 | {
291 | "name": "has_shop",
292 | "type": "uint8"
293 | },
294 | {
295 | "name": "has_kyc",
296 | "type": "uint8"
297 | },
298 | {
299 | "name": "auto_invite",
300 | "type": "uint8"
301 | },
302 | {
303 | "name": "subdomain",
304 | "type": "string"
305 | },
306 | {
307 | "name": "website",
308 | "type": "string"
309 | }
310 | ]
311 | },
312 | {
313 | "name": "deleteact",
314 | "base": "",
315 | "fields": [
316 | {
317 | "name": "id",
318 | "type": "uint64"
319 | }
320 | ]
321 | },
322 | {
323 | "name": "deleteobj",
324 | "base": "",
325 | "fields": [
326 | {
327 | "name": "id",
328 | "type": "uint64"
329 | }
330 | ]
331 | },
332 | {
333 | "name": "indexes",
334 | "base": "",
335 | "fields": [
336 | {
337 | "name": "last_used_sale_id",
338 | "type": "uint64"
339 | },
340 | {
341 | "name": "last_used_objective_id",
342 | "type": "uint64"
343 | },
344 | {
345 | "name": "last_used_action_id",
346 | "type": "uint64"
347 | },
348 | {
349 | "name": "last_used_claim_id",
350 | "type": "uint64"
351 | }
352 | ]
353 | },
354 | {
355 | "name": "member",
356 | "base": "",
357 | "fields": [
358 | {
359 | "name": "name",
360 | "type": "name"
361 | },
362 | {
363 | "name": "inviter",
364 | "type": "name"
365 | },
366 | {
367 | "name": "user_type",
368 | "type": "string"
369 | },
370 | {
371 | "name": "roles",
372 | "type": "name[]"
373 | }
374 | ]
375 | },
376 | {
377 | "name": "netlink",
378 | "base": "",
379 | "fields": [
380 | {
381 | "name": "community_id",
382 | "type": "symbol"
383 | },
384 | {
385 | "name": "inviter",
386 | "type": "name"
387 | },
388 | {
389 | "name": "new_user",
390 | "type": "name"
391 | },
392 | {
393 | "name": "user_type",
394 | "type": "string"
395 | }
396 | ]
397 | },
398 | {
399 | "name": "network",
400 | "base": "",
401 | "fields": [
402 | {
403 | "name": "id",
404 | "type": "uint64"
405 | },
406 | {
407 | "name": "community",
408 | "type": "symbol"
409 | },
410 | {
411 | "name": "invited_user",
412 | "type": "name"
413 | },
414 | {
415 | "name": "invited_by",
416 | "type": "name"
417 | },
418 | {
419 | "name": "user_type",
420 | "type": "string"
421 | }
422 | ]
423 | },
424 | {
425 | "name": "objective",
426 | "base": "",
427 | "fields": [
428 | {
429 | "name": "id",
430 | "type": "uint64"
431 | },
432 | {
433 | "name": "description",
434 | "type": "string"
435 | },
436 | {
437 | "name": "community",
438 | "type": "symbol"
439 | },
440 | {
441 | "name": "creator",
442 | "type": "name"
443 | }
444 | ]
445 | },
446 | {
447 | "name": "reward",
448 | "base": "",
449 | "fields": [
450 | {
451 | "name": "community_id",
452 | "type": "symbol"
453 | },
454 | {
455 | "name": "action_id",
456 | "type": "uint64"
457 | },
458 | {
459 | "name": "receiver",
460 | "type": "name"
461 | },
462 | {
463 | "name": "awarder",
464 | "type": "name"
465 | }
466 | ]
467 | },
468 | {
469 | "name": "role",
470 | "base": "",
471 | "fields": [
472 | {
473 | "name": "name",
474 | "type": "name"
475 | },
476 | {
477 | "name": "permissions",
478 | "type": "string[]"
479 | }
480 | ]
481 | },
482 | {
483 | "name": "setindices",
484 | "base": "",
485 | "fields": [
486 | {
487 | "name": "sale_id",
488 | "type": "uint64"
489 | },
490 | {
491 | "name": "objective_id",
492 | "type": "uint64"
493 | },
494 | {
495 | "name": "action_id",
496 | "type": "uint64"
497 | },
498 | {
499 | "name": "claim_id",
500 | "type": "uint64"
501 | }
502 | ]
503 | },
504 | {
505 | "name": "transfersale",
506 | "base": "",
507 | "fields": [
508 | {
509 | "name": "sale_id",
510 | "type": "uint64"
511 | },
512 | {
513 | "name": "from",
514 | "type": "name"
515 | },
516 | {
517 | "name": "to",
518 | "type": "name"
519 | },
520 | {
521 | "name": "quantity",
522 | "type": "asset"
523 | },
524 | {
525 | "name": "units",
526 | "type": "uint64"
527 | }
528 | ]
529 | },
530 | {
531 | "name": "update",
532 | "base": "",
533 | "fields": [
534 | {
535 | "name": "cmm_asset",
536 | "type": "asset"
537 | },
538 | {
539 | "name": "logo",
540 | "type": "string"
541 | },
542 | {
543 | "name": "name",
544 | "type": "string"
545 | },
546 | {
547 | "name": "description",
548 | "type": "string"
549 | },
550 | {
551 | "name": "inviter_reward",
552 | "type": "asset"
553 | },
554 | {
555 | "name": "invited_reward",
556 | "type": "asset"
557 | },
558 | {
559 | "name": "has_objectives",
560 | "type": "uint8"
561 | },
562 | {
563 | "name": "has_shop",
564 | "type": "uint8"
565 | },
566 | {
567 | "name": "has_kyc",
568 | "type": "uint8"
569 | },
570 | {
571 | "name": "auto_invite",
572 | "type": "uint8"
573 | },
574 | {
575 | "name": "subdomain",
576 | "type": "string"
577 | },
578 | {
579 | "name": "website",
580 | "type": "string"
581 | }
582 | ]
583 | },
584 | {
585 | "name": "upsertaction",
586 | "base": "",
587 | "fields": [
588 | {
589 | "name": "community_id",
590 | "type": "symbol"
591 | },
592 | {
593 | "name": "action_id",
594 | "type": "uint64"
595 | },
596 | {
597 | "name": "objective_id",
598 | "type": "uint64"
599 | },
600 | {
601 | "name": "description",
602 | "type": "string"
603 | },
604 | {
605 | "name": "reward",
606 | "type": "asset"
607 | },
608 | {
609 | "name": "verifier_reward",
610 | "type": "asset"
611 | },
612 | {
613 | "name": "deadline",
614 | "type": "uint64"
615 | },
616 | {
617 | "name": "usages",
618 | "type": "uint64"
619 | },
620 | {
621 | "name": "usages_left",
622 | "type": "uint64"
623 | },
624 | {
625 | "name": "verifications",
626 | "type": "uint64"
627 | },
628 | {
629 | "name": "verification_type",
630 | "type": "string"
631 | },
632 | {
633 | "name": "validators_str",
634 | "type": "string"
635 | },
636 | {
637 | "name": "is_completed",
638 | "type": "uint8"
639 | },
640 | {
641 | "name": "creator",
642 | "type": "name"
643 | },
644 | {
645 | "name": "has_proof_photo",
646 | "type": "uint8"
647 | },
648 | {
649 | "name": "has_proof_code",
650 | "type": "uint8"
651 | },
652 | {
653 | "name": "photo_proof_instructions",
654 | "type": "string"
655 | },
656 | {
657 | "name": "image",
658 | "type": "string"
659 | }
660 | ]
661 | },
662 | {
663 | "name": "upsertobjctv",
664 | "base": "",
665 | "fields": [
666 | {
667 | "name": "community_id",
668 | "type": "symbol"
669 | },
670 | {
671 | "name": "objective_id",
672 | "type": "uint64"
673 | },
674 | {
675 | "name": "description",
676 | "type": "string"
677 | },
678 | {
679 | "name": "editor",
680 | "type": "name"
681 | }
682 | ]
683 | },
684 | {
685 | "name": "upsertrole",
686 | "base": "",
687 | "fields": [
688 | {
689 | "name": "community_id",
690 | "type": "symbol"
691 | },
692 | {
693 | "name": "name",
694 | "type": "name"
695 | },
696 | {
697 | "name": "color",
698 | "type": "string"
699 | },
700 | {
701 | "name": "permissions",
702 | "type": "string[]"
703 | }
704 | ]
705 | },
706 | {
707 | "name": "verifyclaim",
708 | "base": "",
709 | "fields": [
710 | {
711 | "name": "community_id",
712 | "type": "symbol"
713 | },
714 | {
715 | "name": "claim_id",
716 | "type": "uint64"
717 | },
718 | {
719 | "name": "verifier",
720 | "type": "name"
721 | },
722 | {
723 | "name": "vote",
724 | "type": "uint8"
725 | }
726 | ]
727 | }
728 | ],
729 | "actions": [
730 | {
731 | "name": "assignroles",
732 | "type": "assignroles",
733 | "ricardian_contract": ""
734 | },
735 | {
736 | "name": "claimaction",
737 | "type": "claimaction",
738 | "ricardian_contract": ""
739 | },
740 | {
741 | "name": "clean",
742 | "type": "clean",
743 | "ricardian_contract": ""
744 | },
745 | {
746 | "name": "create",
747 | "type": "create",
748 | "ricardian_contract": ""
749 | },
750 | {
751 | "name": "deleteact",
752 | "type": "deleteact",
753 | "ricardian_contract": ""
754 | },
755 | {
756 | "name": "deleteobj",
757 | "type": "deleteobj",
758 | "ricardian_contract": ""
759 | },
760 | {
761 | "name": "netlink",
762 | "type": "netlink",
763 | "ricardian_contract": ""
764 | },
765 | {
766 | "name": "reward",
767 | "type": "reward",
768 | "ricardian_contract": ""
769 | },
770 | {
771 | "name": "setindices",
772 | "type": "setindices",
773 | "ricardian_contract": ""
774 | },
775 | {
776 | "name": "transfersale",
777 | "type": "transfersale",
778 | "ricardian_contract": ""
779 | },
780 | {
781 | "name": "update",
782 | "type": "update",
783 | "ricardian_contract": ""
784 | },
785 | {
786 | "name": "upsertaction",
787 | "type": "upsertaction",
788 | "ricardian_contract": ""
789 | },
790 | {
791 | "name": "upsertobjctv",
792 | "type": "upsertobjctv",
793 | "ricardian_contract": ""
794 | },
795 | {
796 | "name": "upsertrole",
797 | "type": "upsertrole",
798 | "ricardian_contract": ""
799 | },
800 | {
801 | "name": "verifyclaim",
802 | "type": "verifyclaim",
803 | "ricardian_contract": ""
804 | }
805 | ],
806 | "tables": [
807 | {
808 | "name": "action",
809 | "type": "action",
810 | "index_type": "i64",
811 | "key_names": [],
812 | "key_types": []
813 | },
814 | {
815 | "name": "check",
816 | "type": "check",
817 | "index_type": "i64",
818 | "key_names": [],
819 | "key_types": []
820 | },
821 | {
822 | "name": "claim",
823 | "type": "claim",
824 | "index_type": "i64",
825 | "key_names": [],
826 | "key_types": []
827 | },
828 | {
829 | "name": "community",
830 | "type": "community",
831 | "index_type": "i64",
832 | "key_names": [],
833 | "key_types": []
834 | },
835 | {
836 | "name": "indexes",
837 | "type": "indexes",
838 | "index_type": "i64",
839 | "key_names": [],
840 | "key_types": []
841 | },
842 | {
843 | "name": "member",
844 | "type": "member",
845 | "index_type": "i64",
846 | "key_names": [],
847 | "key_types": []
848 | },
849 | {
850 | "name": "network",
851 | "type": "network",
852 | "index_type": "i64",
853 | "key_names": [],
854 | "key_types": []
855 | },
856 | {
857 | "name": "objective",
858 | "type": "objective",
859 | "index_type": "i64",
860 | "key_names": [],
861 | "key_types": []
862 | },
863 | {
864 | "name": "role",
865 | "type": "role",
866 | "index_type": "i64",
867 | "key_names": [],
868 | "key_types": []
869 | },
870 | {
871 | "name": "validator",
872 | "type": "action_validator",
873 | "index_type": "i64",
874 | "key_names": [],
875 | "key_types": []
876 | }
877 | ],
878 | "kv_tables": {},
879 | "ricardian_clauses": [],
880 | "variants": [],
881 | "action_results": []
882 | }
--------------------------------------------------------------------------------
/community/community.cpp:
--------------------------------------------------------------------------------
1 | #include "community.hpp"
2 | #include "../utils/utils.cpp"
3 | #include
4 |
5 | inline void verify_sha256_prefix(const std::string &value, const std::string &compared_hash)
6 | {
7 | auto hash = eosio::sha256(value.c_str(), value.length());
8 | auto arr = hash.extract_as_byte_array();
9 |
10 | const char *hex_characters = "0123456789abcdef";
11 | std::string hash_prefix;
12 | const uint8_t *d = reinterpret_cast(arr.data());
13 |
14 | auto prefix_size = compared_hash.length() / 2;
15 | for (uint32_t i = 0; i < prefix_size; ++i)
16 | {
17 | hash_prefix += hex_characters[d[i] >> 4];
18 | hash_prefix += hex_characters[d[i] & 0x0f];
19 | }
20 |
21 | eosio::check(compared_hash == hash_prefix,
22 | "fail to verify hash: " + compared_hash + " should be " + hash_prefix);
23 | }
24 |
25 | void cambiatus::create(eosio::asset cmm_asset, eosio::name creator, std::string logo,
26 | std::string name, std::string description,
27 | eosio::asset inviter_reward, eosio::asset invited_reward,
28 | std::uint8_t has_objectives, std::uint8_t has_shop, std::uint8_t has_kyc,
29 | std::uint8_t auto_invite, std::string subdomain, std::string website)
30 | {
31 | require_auth(creator);
32 |
33 | const eosio::symbol new_symbol = cmm_asset.symbol;
34 |
35 | // Validates reward for invitater and invited users
36 | eosio::check(invited_reward.is_valid(), "invalid invited_reward");
37 | eosio::check(invited_reward.amount >= 0, "invited_reward must be equal or greater than 0");
38 | eosio::check(new_symbol == invited_reward.symbol, "unmatched symbols for max_supply and invited_reward");
39 | eosio::check(inviter_reward.is_valid(), "invalid inviter_reward");
40 | eosio::check(inviter_reward.amount >= 0, "inviter_reward must be equal or greater than 0");
41 | eosio::check(new_symbol == inviter_reward.symbol, "unmatched symbols for max_supply and inviter_reward");
42 |
43 | // Validates string fields
44 | eosio::check(name.size() <= 256, "name has more than 256 bytes");
45 | eosio::check(logo.size() <= 256, "logo has more than 256 bytes");
46 |
47 | // Check if community was created before
48 | communities community(_self, _self.value);
49 | auto existing_cmm = community.find(new_symbol.raw());
50 | eosio::check(existing_cmm == community.end(), "symbol already exists");
51 |
52 | // creates new community
53 | community.emplace(_self, [&](auto &c)
54 | {
55 | c.symbol = new_symbol;
56 | c.creator = creator;
57 | c.logo = logo;
58 | c.name = name;
59 | c.description = description.substr(0, 255);
60 | c.inviter_reward = inviter_reward;
61 | c.invited_reward = invited_reward;
62 | c.has_objectives = has_objectives;
63 | c.has_shop = has_shop;
64 | c.has_kyc = has_kyc; });
65 |
66 | std::string user_type = "natural";
67 | eosio::action netlink = eosio::action(eosio::permission_level{get_self(), eosio::name{"active"}}, // Permission
68 | get_self(), // Account
69 | eosio::name{"netlink"}, // Action
70 | std::make_tuple(new_symbol, creator, creator, user_type));
71 | netlink.send();
72 |
73 | // Notify creator
74 | require_recipient(creator);
75 |
76 | // Create default member role
77 | std::vector permissions{"invite", "claim", "order", "verify", "sell", "transfer"};
78 | roles role_table(_self, new_symbol.raw());
79 | role_table.emplace(_self, [&](auto &r)
80 | { r.name = eosio::name{"member"}; r.permissions = permissions; });
81 | }
82 |
83 | void cambiatus::update(eosio::asset cmm_asset, std::string logo, std::string name,
84 | std::string description, eosio::asset inviter_reward, eosio::asset invited_reward,
85 | std::uint8_t has_objectives, std::uint8_t has_shop, std::uint8_t has_kyc,
86 | std::uint8_t auto_invite, std::string subdomain, std::string website)
87 | {
88 | communities community(_self, _self.value);
89 | const auto &cmm = community.get(cmm_asset.symbol.raw(), "can't find any community with given asset");
90 |
91 | require_auth(cmm.creator);
92 |
93 | // Validates string fields
94 | eosio::check(logo.size() <= 256, "logo has more than 256 bytes");
95 | eosio::check(name.size() <= 256, "name has more than 256 bytes");
96 |
97 | community.modify(cmm, _self, [&](auto &row)
98 | {
99 | row.logo = logo;
100 | row.name = name;
101 | row.description = description.substr(0, 255);
102 | row.inviter_reward = inviter_reward;
103 | row.invited_reward = invited_reward;
104 | row.has_objectives = has_objectives;
105 | row.has_shop = has_shop;
106 | row.has_kyc = has_kyc; });
107 | }
108 |
109 | void cambiatus::netlink(eosio::symbol community_id, eosio::name inviter, eosio::name new_user, std::string user_type)
110 | {
111 | eosio::check(is_account(new_user), "new user account doesn't exists");
112 |
113 | // This action can be performed by:
114 | // 1. The contract itself
115 | // 2. The inviter, directly
116 | // 3. The backend account, on behalf of the inviter
117 | if (eosio::get_sender() == get_self())
118 | {
119 | require_auth(get_self());
120 | }
121 | else if (has_auth(inviter))
122 | {
123 | require_auth(inviter);
124 | }
125 | else
126 | {
127 | require_auth(backend_account);
128 | }
129 |
130 | // Validate user type
131 | eosio::check(user_type == "natural" || user_type == "juridical", "user type must be 'natural' or 'juridical'");
132 |
133 | // Validates community
134 | communities community(_self, _self.value);
135 | const auto &cmm = community.get(community_id.raw(), "can't find any community with given asset");
136 |
137 | // Skip if already member
138 | if (is_member(community_id, new_user))
139 | {
140 | return;
141 | }
142 |
143 | // Validates if inviter is a member, except if its the creator
144 | if (cmm.creator != inviter)
145 | {
146 | eosio::check(is_member(community_id, inviter), "inviter is not part of the community");
147 | eosio::check(has_permission(community_id, inviter, permission::invite), "this user cannot invite with its current roles");
148 | }
149 |
150 | members member(_self, community_id.raw());
151 | member.emplace(_self, [&](auto &r)
152 | { r.name = new_user; r.inviter = inviter; r.user_type = user_type; r.roles = { eosio::name{"member"} }; });
153 |
154 | // Skip rewards if inviter and invited is the same, may happen during community creation
155 | if (inviter == new_user)
156 | return;
157 |
158 | // Send inviter reward
159 | if (cmm.inviter_reward.amount > 0)
160 | {
161 | std::string memo_inviter = "Thanks for helping " + cmm.name + " grow!";
162 | eosio::action inviter_reward = eosio::action(eosio::permission_level{currency_account, eosio::name{"active"}}, // Permission
163 | currency_account, // Account
164 | eosio::name{"issue"}, // Action
165 | // to, quantity, memo
166 | std::make_tuple(inviter, cmm.inviter_reward, memo_inviter));
167 | inviter_reward.send();
168 | require_recipient(inviter);
169 | }
170 |
171 | // Send invited reward
172 | if (cmm.invited_reward.amount > 0)
173 | {
174 | std::string memo_invited = "Welcome to " + cmm.name + "!";
175 | eosio::action invited_reward = eosio::action(eosio::permission_level{currency_account, eosio::name{"active"}}, // Permission
176 | currency_account, // Account
177 | eosio::name{"issue"}, // Action
178 | // to, quantity, memo
179 | std::make_tuple(new_user, cmm.invited_reward, memo_invited));
180 | invited_reward.send();
181 | require_recipient(new_user);
182 | }
183 | else
184 | {
185 | eosio::action init_account = eosio::action(eosio::permission_level{currency_account, eosio::name{"active"}}, // Permission
186 | currency_account, // Account
187 | eosio::name{"initacc"}, // Action
188 | std::make_tuple(cmm.invited_reward.symbol, new_user, inviter));
189 | init_account.send();
190 | require_recipient(new_user);
191 | }
192 | }
193 |
194 | void cambiatus::upsertobjctv(eosio::symbol community_id, std::uint64_t objective_id, std::string description, eosio::name editor)
195 | {
196 | require_auth(editor);
197 |
198 | eosio::check(community_id.is_valid(), "Invalid symbol name for community");
199 |
200 | // Find community
201 | communities community(_self, _self.value);
202 | const auto &cmm = community.get(community_id.raw(), "Can't find community with given community_id");
203 |
204 | eosio::check(cmm.has_objectives, "This community don't have objectives enabled.");
205 |
206 | // Check if editor belongs to the community
207 | eosio::check(is_member(cmm.symbol, editor), "Editor doesn't belong to the community");
208 |
209 | if (objective_id > 0)
210 | {
211 | // Find objective
212 | objectives objective(_self, community_id.raw());
213 | const auto &found_objective = objective.get(objective_id, "Can't find objective with given ID");
214 |
215 | // Validate Auth can be either the community creator or the objective creator
216 | eosio::check(found_objective.creator == editor || cmm.creator == editor, "You must be either the creator of the objective or the community creator to edit");
217 |
218 | objective.modify(found_objective, _self, [&](auto &row)
219 | { row.description = description.substr(0, 255); });
220 | }
221 | else
222 | {
223 | // Insert new objective
224 | objectives objective(_self, community_id.raw());
225 | objective.emplace(_self, [&](auto &o)
226 | {
227 | o.id = get_available_id("objectives");
228 | o.description = description.substr(0, 255);
229 | o.community = community_id;
230 | o.creator = editor; });
231 | }
232 | }
233 |
234 | void cambiatus::upsertaction(eosio::symbol community_id, std::uint64_t action_id, std::uint64_t objective_id,
235 | std::string description, eosio::asset reward,
236 | eosio::asset verifier_reward, std::uint64_t deadline,
237 | std::uint64_t usages, std::uint64_t usages_left,
238 | std::uint64_t verifications, std::string verification_type,
239 | std::string validators_str, std::uint8_t is_completed,
240 | eosio::name creator,
241 | std::uint8_t has_proof_photo, std::uint8_t has_proof_code,
242 | std::string photo_proof_instructions, std::string image)
243 | {
244 | // Validate creator
245 | eosio::check(is_account(creator), "invalid account for creator");
246 | require_auth(creator);
247 |
248 | // Validates that the objective exists
249 | objectives objective(_self, community_id.raw());
250 | auto itr_obj = objective.find(objective_id);
251 | eosio::check(itr_obj != objective.end(), "Can't find objective with given objective_id");
252 | auto &obj = *itr_obj;
253 |
254 | // Validate community
255 | communities community(_self, _self.value);
256 | auto itr_cmm = community.find(obj.community.raw());
257 | eosio::check(itr_cmm != community.end(), "Can't find community with given objective_id");
258 | auto &cmm = *itr_cmm;
259 |
260 | eosio::check(cmm.has_objectives, "This community don't have objectives enabled.");
261 |
262 | // Creator must belong to the community
263 | eosio::check(is_member(cmm.symbol, creator), "Creator doesn't belong to the community");
264 |
265 | // Validate assets
266 | eosio::check(reward.is_valid(), "invalid reward");
267 | eosio::check(reward.amount >= 0, "reward must be greater than or equal to 0");
268 | eosio::check(reward.symbol == obj.community, "reward must be a community token");
269 |
270 | eosio::check(verifier_reward.is_valid(), "invalid verifier_reward");
271 | eosio::check(verifier_reward.amount >= 0, "verifier reward must be greater than or equal to 0");
272 | eosio::check(verifier_reward.symbol == obj.community, "verifier_reward must be a community token");
273 |
274 | // Validate deadline
275 | if (deadline > 0)
276 | {
277 | eosio::check(now() < deadline, "Deadline must be somewhere in the future");
278 | }
279 |
280 | // Validate usages
281 | if (usages > 0)
282 | {
283 | eosio::check(usages <= 1000, "You can have a maximum of 1000 uses");
284 | }
285 |
286 | // Validate verification type
287 | eosio::check(verification_type == "claimable" || verification_type == "automatic", "verification type must be either 'claimable' or 'automatic'");
288 |
289 | // Validate that if we have verifications, it need to be at least three and it must be odd
290 | if (verifications > 0)
291 | {
292 | eosio::check(verifications >= 3 && ((verifications & 1) != 0), "You need at least three validators and it must be an odd number");
293 | }
294 |
295 | // ========================================= End validation, start upsert
296 |
297 | // Find action
298 | actions action(_self, _self.value);
299 | auto itr_act = action.find(action_id);
300 |
301 | if (action_id == 0)
302 | {
303 | // Get last used action id and update table_index table
304 | action_id = get_available_id("actions");
305 |
306 | action.emplace(_self, [&](auto &a)
307 | {
308 | a.id = action_id;
309 | a.objective_id = objective_id;
310 | a.description = description.substr(0, 255);
311 | a.reward = reward;
312 | a.verifier_reward = verifier_reward;
313 | a.deadline = deadline;
314 | a.usages = usages;
315 | a.usages_left = usages;
316 | a.verifications = verifications;
317 | a.verification_type = verification_type;
318 | a.is_completed = 0;
319 | a.creator = creator;
320 | a.has_proof_photo = has_proof_photo;
321 | a.has_proof_code = has_proof_code;
322 | a.photo_proof_instructions = photo_proof_instructions.substr(0, 255); });
323 | }
324 | else
325 | {
326 | action.modify(itr_act, _self, [&](auto &a)
327 | {
328 | a.description = description.substr(0, 255);
329 | a.reward = reward;
330 | a.verifier_reward = verifier_reward;
331 | a.deadline = deadline;
332 | a.usages = usages;
333 | a.usages_left = usages_left;
334 | a.verifications = verifications;
335 | a.verification_type = verification_type;
336 | a.is_completed = is_completed;
337 | a.has_proof_photo = has_proof_photo;
338 | a.has_proof_code = has_proof_code;
339 | a.photo_proof_instructions = photo_proof_instructions.substr(0, 255); });
340 | }
341 |
342 | if (verification_type == "claimable")
343 | {
344 | // Validate list of validators
345 | std::vector strs = split(validators_str, "-");
346 | eosio::check(strs.size() >= verifications, "You cannot have a bigger number of verifications than accounts in the validator list");
347 |
348 | // Ensure list of validators in unique
349 | sort(strs.begin(), strs.end());
350 | auto strs_it = std::unique(strs.begin(), strs.end());
351 | eosio::check(strs_it == strs.end(), "You cannot add a validator more than once to an action");
352 |
353 | // Make sure we have at least 2 verifiers
354 | eosio::check(strs.size() >= 2, "You need at least two verifiers in a claimable action");
355 |
356 | // Define validators table, scoped by action
357 | validators validator(_self, action_id);
358 |
359 | // Clean up existing validators if action already exists
360 |
361 | // for (validator;itr_vals != validator.end();) {
362 | for (auto itr_vals = validator.begin(); itr_vals != validator.end();)
363 | {
364 | eosio::print_f("Test Table : {%, %}\n", itr_vals->action_id);
365 | itr_vals = validator.erase(itr_vals);
366 | }
367 |
368 | std::vector validator_v = split(validators_str, "-");
369 | for (auto i : validator_v)
370 | {
371 | eosio::name acc = eosio::name{i};
372 | eosio::check((bool)acc, "account from validator list cannot be empty");
373 | eosio::check(is_account(acc), "account from validator list don't exist");
374 |
375 | // Must belong to the community
376 | eosio::check(is_member(cmm.symbol, acc), "one of the validators doesn't belong to the community");
377 |
378 | // Add list of validators
379 | validator.emplace(_self, [&](auto &v)
380 | {
381 | v.id = validator.available_primary_key();
382 | v.action_id = action_id;
383 | v.validator = acc; });
384 | };
385 | }
386 | }
387 |
388 | /// @abi action
389 | /// Verify an automatic action, rewarding tokens
390 | void cambiatus::reward(eosio::symbol community_id, std::uint64_t action_id, eosio::name receiver, eosio::name awarder)
391 | {
392 | // Validates awarder
393 | eosio::check(is_account(awarder), "invalid account for awarder");
394 | eosio::check(is_account(receiver), "invalid account for receiver");
395 | require_auth(awarder);
396 |
397 | // Validates if action exists
398 | actions action_table(_self, _self.value);
399 | const auto &action = action_table.get(action_id, "can't find action with given action_id");
400 |
401 | // Validates action and objective are from the community
402 | objectives objective_table(_self, community_id.raw());
403 | const auto &obj = objective_table.get(action.objective_id, "can't find objective with given action_id");
404 |
405 | communities community(_self, _self.value);
406 | const auto &cmm = community.get(obj.community.raw(), "can't find community with given action_id");
407 |
408 | eosio::check(cmm.has_objectives, "this community don't have objectives enabled.");
409 |
410 | // Validates if receiver and awarder belong to the action community
411 | eosio::check(is_member(cmm.symbol, awarder), "verifier doesn't belong to the community");
412 | eosio::check(is_member(cmm.symbol, receiver), "receiver doesn't belong to the community");
413 |
414 | // Validate if the action type is `automatic`
415 | eosio::check(action.verification_type == "automatic", "can't verify actions that aren't automatic, you'll need to open a claim");
416 |
417 | eosio::check(action.is_completed == false, "this action is already completed");
418 |
419 | // Check if user has permission to reward
420 | eosio::check(has_permission(cmm.symbol, awarder, permission::award), "you cannot award with your current roles");
421 |
422 | if (action.usages > 0)
423 | {
424 | eosio::check(action.usages_left >= 1, "there are no usages left for this action");
425 | }
426 |
427 | // change status of verification
428 | action_table.modify(action, _self, [&](auto &a)
429 | {
430 | a.usages_left = a.usages_left - 1;
431 |
432 | if (a.usages_left - 1 <= 0)
433 | {
434 | a.is_completed = 1;
435 | } });
436 |
437 | // Find Token
438 | // cambiatus_tokens tokens(currency_account, currency_account.value);
439 | cambiatus_tokens tokens(currency_account, cmm.symbol.code().raw());
440 | const auto &token = tokens.get(cmm.symbol.code().raw(), "can't find token configurations on cambiatus token contract");
441 |
442 | if (action.reward.amount > 0)
443 | {
444 | // Reward Action Claimer
445 | std::string memo_action = "thanks for doing an action for your community";
446 | eosio::action reward_action = eosio::action(eosio::permission_level{currency_account, eosio::name{"active"}}, // Permission
447 | currency_account, // Account
448 | eosio::name{"issue"}, // Action
449 | // to, quantity, memo
450 | std::make_tuple(receiver, action.reward, memo_action));
451 | reward_action.send();
452 | }
453 |
454 | // Don't reward awarder for automatic verifications
455 | }
456 |
457 | /// @abi action
458 | /// Start a new claim on an action
459 | void cambiatus::claimaction(eosio::symbol community_id, std::uint64_t action_id, eosio::name maker,
460 | std::string proof_photo, std::string proof_code, uint32_t proof_time)
461 | {
462 | // Validate maker
463 | eosio::check(is_account(maker), "invalid account for maker");
464 | require_auth(maker);
465 |
466 | eosio::check(proof_photo.length() <= 256,
467 | "Invalid length for proof photo url, must be less than 256 characters");
468 |
469 | if (!proof_code.empty())
470 | {
471 | eosio::check(proof_code.length() == 8, "proof code needs to be 8 chars");
472 | eosio::check(now() - proof_time <= proof_expiration_secs, "proof time has expired");
473 | std::string proof = std::to_string(action_id) + std::to_string(maker.value) + std::to_string(proof_time);
474 | verify_sha256_prefix(proof, proof_code);
475 | }
476 |
477 | // Validates if action exists
478 | actions action_table(_self, _self.value);
479 | const auto &objact = action_table.get(action_id, "Can't find action with given action_id");
480 |
481 | // Check if action is completed, have usages left or the deadline has been met
482 | eosio::check(objact.is_completed == false, "This is action is already completed, can't open claim");
483 | if (objact.deadline > 0)
484 | {
485 | eosio::check(objact.deadline > now(), "Deadline exceeded");
486 | }
487 |
488 | if (objact.usages > 0)
489 | {
490 | eosio::check(objact.usages_left >= 1, "There are no usages left for this action");
491 | }
492 |
493 | // Check if the action is claimable
494 | eosio::check(objact.verification_type == "claimable", "You can only open claims in claimable actions");
495 |
496 | // Check action proofs
497 | if (objact.has_proof_photo)
498 | {
499 | eosio::check(!proof_photo.empty(), "action requires proof photo");
500 | }
501 | if (objact.has_proof_code)
502 | {
503 | eosio::check(!proof_code.empty() && proof_time > 0, "action requires proof code");
504 | }
505 |
506 | // Validates maker belongs to the action community
507 | objectives objective(_self, community_id.raw());
508 | const auto &obj = objective.get(objact.objective_id, "Can't find objective with given action_id");
509 |
510 | communities community(_self, _self.value);
511 | const auto &cmm = community.get(community_id.raw(), "Can't find community with given action_id");
512 |
513 | eosio::check(cmm.has_objectives, "This community don't have objectives enabled.");
514 |
515 | eosio::check(is_member(cmm.symbol, maker), "Maker doesn't belong to the community");
516 | eosio::check(has_permission(community_id, maker, permission::claim), "you cannot claim with your current roles");
517 |
518 | // Get last used claim id and update item_index table
519 | uint64_t claim_id;
520 | claim_id = get_available_id("claims");
521 |
522 | // Emplace new claim
523 | // claimsnew claim_table(_self, _self.value);
524 | claims claim_table(_self, _self.value);
525 | claim_table.emplace(_self, [&](auto &c)
526 | {
527 | c.id = claim_id;
528 | c.action_id = action_id;
529 | c.claimer = maker;
530 | c.status = "pending";
531 | c.proof_photo = proof_photo;
532 | c.proof_code = proof_code; });
533 | }
534 |
535 | /// @abi action
536 | /// Send a vote to a given claim
537 | void cambiatus::verifyclaim(eosio::symbol community_id, std::uint64_t claim_id, eosio::name verifier, std::uint8_t vote)
538 | {
539 | // Validates verifier belongs to the action community
540 | claims claim_table(_self, _self.value);
541 | // claimsnew claim_table(_self, _self.value);
542 | auto itr_clm = claim_table.find(claim_id);
543 | eosio::check(itr_clm != claim_table.end(), "Can't find claim with given claim_id");
544 | auto &claim = *itr_clm;
545 |
546 | // Check if claim is already verified
547 | eosio::check(claim.status == "pending", "Can't vote on already verified claim");
548 |
549 | // Validates if action exists
550 | actions action(_self, _self.value);
551 | auto itr_objact = action.find(claim.action_id);
552 | eosio::check(itr_objact != action.end(), "Can't find action with given claim_id");
553 | auto &objact = *itr_objact;
554 |
555 | // Validates that the objective exists
556 | objectives objective(_self, community_id.raw());
557 | auto itr_obj = objective.find(objact.objective_id);
558 | eosio::check(itr_obj != objective.end(), "Can't find objective with given claim_id");
559 | auto &obj = *itr_obj;
560 |
561 | // Validate community
562 | communities community(_self, _self.value);
563 | auto itr_cmm = community.find(obj.community.raw());
564 | eosio::check(itr_cmm != community.end(), "Can't find community with given claim_id");
565 | auto &cmm = *itr_cmm;
566 |
567 | eosio::check(cmm.has_objectives, "This community don't have objectives enabled.");
568 |
569 | // Check if user belongs to the action_validator list
570 | validators validator(_self, objact.id);
571 | std::uint64_t validator_count = 0;
572 | for (auto itr_validators = validator.begin(); itr_validators != validator.end();)
573 | {
574 | if ((*itr_validators).validator == verifier)
575 | {
576 | validator_count++;
577 | }
578 | itr_validators++;
579 | }
580 | eosio::check(validator_count > 0, "Verifier is not in the action validator list");
581 |
582 | eosio::check(has_permission(cmm.symbol, verifier, permission::verify), "you cannot verify with your current roles");
583 |
584 | // Check if action is completed, have usages left or the deadline has been met
585 | eosio::check(objact.is_completed == false, "This is action is already completed, can't verify claim");
586 |
587 | if (objact.deadline > 0)
588 | {
589 | eosio::check(objact.deadline > now(), "Deadline exceeded");
590 | }
591 |
592 | if (objact.usages > 0)
593 | {
594 | eosio::check(objact.usages_left >= 1, "There are no usages left for this action");
595 | }
596 |
597 | // Get check index
598 | checks check(_self, _self.value);
599 | auto check_by_claim = check.get_index();
600 |
601 | // Assert that verifier hasn't voted previously
602 | uint64_t checks_count = 0;
603 | for (auto itr_check_claim = check_by_claim.find(claim_id); itr_check_claim != check_by_claim.end(); itr_check_claim++)
604 | {
605 | auto check_claim = *itr_check_claim;
606 | bool existing_vote = check_claim.validator == verifier && check_claim.claim_id == claim_id;
607 | eosio::check(!existing_vote, "The verifier cannot check the same claim more than once");
608 | }
609 |
610 | // Add new check
611 | check.emplace(_self, [&](auto &c)
612 | {
613 | c.id = check.available_primary_key();
614 | c.claim_id = claim.id;
615 | c.validator = verifier;
616 | c.is_verified = vote; });
617 |
618 | if (objact.verifier_reward.amount > 0)
619 | {
620 | // Send verification reward
621 | std::string memo_verification = "Thanks for verifying an action for your community";
622 | eosio::action verification_reward = eosio::action(eosio::permission_level{currency_account, eosio::name{"active"}}, // Permission
623 | currency_account, // Account
624 | eosio::name{"issue"}, // Action
625 | // to, quantity, memo
626 | std::make_tuple(verifier, objact.verifier_reward, memo_verification));
627 | verification_reward.send();
628 | }
629 |
630 | // In order to know if its approved or rejected, we will have to count all existing checks, to see if we already have all needed
631 | // Just check `objact.verifications <= check counter`
632 |
633 | // Then we will have to count the positive and negative votes...
634 | // If more than half was positive, its approved
635 | // else its rejected
636 |
637 | // If we don't have yet the number of votes necessary, then its pending
638 |
639 | // At every vote we will have to update the claim status
640 | std::uint64_t positive_votes = 0;
641 | std::uint64_t negative_votes = 0;
642 |
643 | auto checks_with_claim = check.get_index();
644 | for (auto itr_vote = checks_with_claim.find(claim_id); itr_vote != checks_with_claim.end(); itr_vote++)
645 | {
646 | if (itr_vote->claim_id != claim_id)
647 | continue;
648 |
649 | if (itr_vote->is_verified == 1)
650 | {
651 | positive_votes++;
652 | eosio::print("\nFound a positive vote from: ", (*itr_vote).validator);
653 | }
654 | else
655 | {
656 | negative_votes++;
657 | eosio::print("\nFound a negative vote from: ", (*itr_vote).validator);
658 | }
659 | }
660 |
661 | eosio::print("\nPositive votes: ", positive_votes);
662 | eosio::print("\nNegative votes: ", negative_votes);
663 |
664 | std::uint64_t majority = (objact.verifications >> 1) + (objact.verifications & 1);
665 |
666 | eosio::print("\nMajority: ", majority);
667 |
668 | std::string status = "pending";
669 | if (positive_votes >= majority || negative_votes >= majority)
670 | {
671 | if (positive_votes > negative_votes)
672 | {
673 | status = "approved";
674 | }
675 | else
676 | {
677 | status = "rejected";
678 | }
679 | }
680 |
681 | eosio::print("\nFinal status of the claim is: ", status);
682 | claim_table.modify(itr_clm, _self, [&](auto &c)
683 | { c.status = status; });
684 |
685 | if (status == "approved" && objact.reward.amount > 0)
686 | {
687 | // Send reward
688 | std::string memo_action = "Thanks for doing an action for your community";
689 | eosio::action reward_action = eosio::action(eosio::permission_level{currency_account, eosio::name{"active"}}, // Permission
690 | currency_account, // Account
691 | eosio::name{"issue"}, // Action
692 | // to, quantity, memo
693 | std::make_tuple(claim.claimer, objact.reward, memo_action));
694 | reward_action.send();
695 | }
696 |
697 | // Check if action can be completed. Current claim must be either "approved" or "rejected"
698 | if (status != "pending" && !objact.is_completed && objact.usages > 0)
699 | {
700 | action.modify(itr_objact, _self, [&](auto &a)
701 | {
702 | a.usages_left = objact.usages_left - 1;
703 | a.is_completed = (objact.usages_left - 1) == 0 ? 1 : 0; });
704 | }
705 | }
706 |
707 | void cambiatus::transfersale(std::uint64_t sale_id, eosio::name from, eosio::name to, eosio::asset quantity, std::uint64_t units)
708 | {
709 | // Validate user
710 | require_auth(from);
711 |
712 | // Validate 'to' account
713 | eosio::check(is_account(to), "The sale creator (to) account doesn't exists");
714 |
715 | // Validate accounts are different
716 | eosio::check(from != to, "Can't sale for yourself");
717 |
718 | // Check if community exists
719 | communities community(_self, _self.value);
720 | const auto &cmm = community.get(quantity.symbol.raw(), "Can't find community with given Symbol");
721 |
722 | eosio::check(cmm.has_shop, "This community don't have shop enabled.");
723 |
724 | eosio::check(has_permission(quantity.symbol, from, permission::order), "you cannot create an order with your current roles");
725 | eosio::check(has_permission(quantity.symbol, to, permission::sell), "you cannot buy from this user, it doesn't have the permission to sell in this community anymore.");
726 |
727 | // Validate 'from' user belongs to sale community
728 | eosio::check(is_member(quantity.symbol, from), "You can't use transfersale to this sale if you aren't part of the community");
729 | }
730 |
731 | void cambiatus::upsertrole(eosio::symbol community_id, eosio::name name, std::string color, std::vector &permissions)
732 | {
733 | eosio::check(community_id.is_valid(), "provided symbol is not valid");
734 |
735 | // Find community
736 | communities community_table(_self, _self.value);
737 | const auto &community = community_table.get(community_id.raw(), "can't find community with given community_id");
738 |
739 | // Make sure we have admin's permission to upsert roles **or** the contract permission
740 | // Roles are automatically created during community creation process
741 | if (eosio::get_sender() == community.creator)
742 | {
743 | require_auth(community.creator);
744 | }
745 | else
746 | {
747 | require_auth(get_self());
748 | }
749 |
750 | // Validate permission list
751 | eosio::check(permissions.size() <= 6, "invalid cambiatus permissions");
752 | for (auto p : permissions)
753 | {
754 | eosio::check(p == "invite" || p == "claim" ||
755 | p == "order" || p == "verify" ||
756 | p == "sell" || p == "award" ||
757 | p == "transfer",
758 | "Invalid permission. Check permission list sent");
759 | }
760 |
761 | // Validate color
762 | eosio::check(color.length() == 7, "invalid color");
763 | eosio::check(color.front() == '#', "invalid color");
764 |
765 | // Upserts
766 | roles role_table(_self, community_id.raw());
767 | auto existing_role = role_table.find(name.value);
768 |
769 | if (existing_role == role_table.end())
770 | {
771 | role_table.emplace(_self, [&](auto &r)
772 | {
773 | r.name = name;
774 | r.permissions = permissions; });
775 | }
776 | else
777 | {
778 | role_table.modify(existing_role, _self, [&](auto &r)
779 | { r.permissions = permissions; });
780 | }
781 | }
782 |
783 | void cambiatus::assignroles(eosio::symbol community_id, eosio::name member, std::vector &new_roles)
784 | {
785 | eosio::check(community_id.is_valid(), "provided symbol is not valid");
786 |
787 | // Find community
788 | communities community_table(_self, _self.value);
789 | const auto &community = community_table.get(community_id.raw(), "can't find community with given community_id");
790 |
791 | // Make sure we have admin's permission to upsert roles
792 | require_auth(community.creator);
793 |
794 | // Check if all roles exist
795 | roles role_table(_self, community_id.raw());
796 | for (auto role : new_roles)
797 | {
798 | role_table.get(role.value, "this role doesn't exist");
799 | }
800 |
801 | eosio::check(is_member(community_id, member), "user don't belong to the community");
802 |
803 | // Update member roles
804 | members member_table(_self, community_id.raw());
805 | auto const &found_member = member_table.get(member.value, "user don't belong to the community");
806 | member_table.modify(found_member, _self, [&](auto &m)
807 | { m.roles = new_roles; });
808 | }
809 |
810 | // set chain indices
811 | void cambiatus::setindices(std::uint64_t sale_id, std::uint64_t objective_id, std::uint64_t action_id, std::uint64_t claim_id)
812 | {
813 | require_auth(_self);
814 | indexes default_indexes;
815 | auto current_indexes = curr_indexes.get_or_create(_self, default_indexes);
816 |
817 | current_indexes.last_used_sale_id = sale_id;
818 | current_indexes.last_used_objective_id = objective_id;
819 | current_indexes.last_used_action_id = action_id;
820 | current_indexes.last_used_claim_id = claim_id;
821 |
822 | curr_indexes.set(current_indexes, _self);
823 | }
824 |
825 | void cambiatus::deleteobj(std::uint64_t id)
826 | {
827 | require_auth(_self);
828 |
829 | objectives objective(_self, _self.value);
830 | auto x = objective.find(id);
831 | eosio::check(x != objective.end(), "Cant find objective with given di");
832 | objective.erase(x);
833 | }
834 |
835 | void cambiatus::deleteact(std::uint64_t id)
836 | {
837 | require_auth(_self);
838 |
839 | actions action(_self, _self.value);
840 | auto found_action = action.find(id);
841 | eosio::check(found_action != action.end(), "Cant find action with given id");
842 | action.erase(found_action);
843 | }
844 |
845 | void cambiatus::clean(std::string t, eosio::name name_scope, eosio::symbol symbol_scope)
846 | {
847 | // Clean up the old claims table after the migration
848 | require_auth(_self);
849 |
850 | eosio::check(t == "claim" ||
851 | t == "community" ||
852 | t == "network" ||
853 | t == "member" ||
854 | t == "objective" ||
855 | t == "action" ||
856 | t == "role",
857 | "invalid value for table name");
858 |
859 | if (t == "claim")
860 | {
861 | claims claim_table(_self, _self.value);
862 | for (auto itr = claim_table.begin(); itr != claim_table.end();)
863 | {
864 | itr = claim_table.erase(itr);
865 | }
866 | }
867 |
868 | if (t == "community")
869 | {
870 | communities communities_table(_self, _self.value);
871 | for (auto itr = communities_table.begin(); itr != communities_table.end();)
872 | {
873 | itr = communities_table.erase(itr);
874 | }
875 | }
876 |
877 | if (t == "network")
878 | {
879 | networks network_table(_self, _self.value);
880 | for (auto itr = network_table.begin(); itr != network_table.end();)
881 | {
882 | itr = network_table.erase(itr);
883 | }
884 | }
885 |
886 | if (t == "member")
887 | {
888 | members member_table(_self, symbol_scope.raw());
889 | for (auto itr = member_table.begin(); itr != member_table.end();)
890 | {
891 | itr = member_table.erase(itr);
892 | }
893 | }
894 |
895 | if (t == "action")
896 | {
897 | actions action_table(_self, _self.value);
898 | for (auto itr = action_table.begin(); itr != action_table.end();)
899 | {
900 | itr = action_table.erase(itr);
901 | }
902 | }
903 |
904 | if (t == "objective")
905 | {
906 | objectives objective_table(_self, symbol_scope.raw());
907 | for (auto itr = objective_table.begin(); itr != objective_table.end();)
908 | {
909 | itr = objective_table.erase(itr);
910 | }
911 | }
912 |
913 | if (t == "role")
914 | {
915 | roles role_table(_self, symbol_scope.raw());
916 | for (auto itr = role_table.begin(); itr != role_table.end();)
917 | {
918 | itr = role_table.erase(itr);
919 | }
920 | }
921 | }
922 |
923 | // Get available key
924 | uint64_t cambiatus::get_available_id(std::string table)
925 | {
926 | eosio::check(table == "actions" || table == "objectives" || table == "sales" || table == "claims", "Table index not available");
927 |
928 | // Init indexes table
929 | indexes default_indexes;
930 | auto current_indexes = curr_indexes.get_or_create(_self, default_indexes);
931 |
932 | uint64_t id = 1;
933 |
934 | if (table == "actions")
935 | {
936 | id = current_indexes.last_used_action_id + 1;
937 | current_indexes.last_used_action_id = id;
938 | curr_indexes.set(current_indexes, _self);
939 | }
940 | else if (table == "objectives")
941 | {
942 | id = current_indexes.last_used_objective_id + 1;
943 | current_indexes.last_used_objective_id = id;
944 | curr_indexes.set(current_indexes, _self);
945 | }
946 | else if (table == "sales")
947 | {
948 | id = current_indexes.last_used_sale_id + 1;
949 | current_indexes.last_used_sale_id = id;
950 | curr_indexes.set(current_indexes, _self);
951 | }
952 | else if (table == "claims")
953 | {
954 | id = current_indexes.last_used_claim_id + 1;
955 | current_indexes.last_used_claim_id = id;
956 | curr_indexes.set(current_indexes, _self);
957 | }
958 |
959 | return id;
960 | }
961 |
962 | bool cambiatus::is_member(eosio::symbol community_id, eosio::name user)
963 | {
964 | members member_table(_self, community_id.raw());
965 | auto itr = member_table.find(user.value);
966 | return itr != member_table.end();
967 | }
968 |
969 | bool cambiatus::has_permission(eosio::symbol community_id, eosio::name user, permission e_permission)
970 | {
971 | std::string permission = cambiatus::permission_to_string(e_permission);
972 |
973 | members member_table(_self, community_id.raw());
974 | const auto &member = member_table.get(user.value, "user is not part of the communtiy");
975 |
976 | roles role_table(_self, community_id.raw());
977 | for (auto &&member_role : member.roles)
978 | {
979 | const auto &role = role_table.get(member_role.value, "user has a role that doesn't exist!");
980 |
981 | bool any = std::any_of(role.permissions.begin(), role.permissions.end(), [&](const std::string &elem)
982 | { return elem == permission; });
983 | if (any)
984 | {
985 | return true;
986 | }
987 | }
988 |
989 | return false;
990 | }
991 |
992 | std::string cambiatus::permission_to_string(permission e_permission)
993 | {
994 | switch (e_permission)
995 | {
996 | case permission::invite:
997 | return "invite";
998 | case permission::claim:
999 | return "claim";
1000 | case permission::order:
1001 | return "order";
1002 | case permission::verify:
1003 | return "verify";
1004 | case permission::sell:
1005 | return "sell";
1006 | case permission::award:
1007 | return "award";
1008 | case permission::transfer:
1009 | return "transfer";
1010 | }
1011 | }
1012 |
1013 | EOSIO_DISPATCH(cambiatus,
1014 | (create)(update)(netlink) // Basic community
1015 | (upsertrole)(assignroles) // Roles & Permission
1016 | (upsertobjctv)(upsertaction) // Objectives and Actions
1017 | (reward)(claimaction)(verifyclaim) // Verifications and Claims
1018 | (transfersale) // Shop
1019 | (setindices)(deleteobj)(deleteact)(clean)); // Admin actions
1020 |
--------------------------------------------------------------------------------
/community/community.hpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | #define TOSTR_(T) #T
6 | #define TOSTR(T) TOSTR_(T)
7 |
8 | enum permission
9 | {
10 | invite,
11 | claim,
12 | order,
13 | verify,
14 | sell,
15 | award,
16 | transfer
17 | };
18 |
19 | class [[eosio::contract("community")]] cambiatus : public eosio::contract
20 | {
21 | public:
22 | using contract::contract;
23 |
24 | TABLE community
25 | {
26 | eosio::symbol symbol;
27 |
28 | eosio::name creator;
29 | std::string logo;
30 | std::string name;
31 | std::string description;
32 |
33 | eosio::asset inviter_reward;
34 | eosio::asset invited_reward;
35 |
36 | std::uint8_t has_objectives;
37 | std::uint8_t has_shop;
38 | std::uint8_t has_kyc;
39 |
40 | uint64_t primary_key() const { return symbol.raw(); };
41 |
42 | EOSLIB_SERIALIZE(community,
43 | (symbol)(creator)(logo)(name)(description)(inviter_reward)(invited_reward)(has_objectives)(has_shop)(has_kyc));
44 | };
45 |
46 | TABLE network
47 | {
48 | std::uint64_t id;
49 |
50 | eosio::symbol community;
51 | eosio::name invited_user;
52 | eosio::name invited_by;
53 | std::string user_type;
54 |
55 | // keys and indexes
56 | std::uint64_t primary_key() const { return id; }
57 | std::uint64_t users_by_cmm() const { return community.raw(); }
58 |
59 | EOSLIB_SERIALIZE(network,
60 | (id)(community)(invited_user)(invited_by)(user_type));
61 | };
62 |
63 | TABLE member
64 | {
65 | eosio::name name;
66 | eosio::name inviter;
67 | std::string user_type;
68 | std::vector roles;
69 |
70 | std::uint64_t primary_key() const { return name.value; }
71 |
72 | EOSLIB_SERIALIZE(member,
73 | (name)(inviter)(user_type)(roles));
74 | };
75 |
76 | /**
77 | * Roles is a way to identify people's relation with their community.
78 | * It can be used to allow people to be recognized by their role in the whole of the community, to give them awards or to help them to identify themselves.
79 | * They can be customized with a color and can have a name
80 | *
81 | * Roles can also be atttached with permissions that gives them abilities within the community such as the ability to invite new people in, to sell goods and services and more
82 | *
83 | * The initial abilities that we offer are:
84 | * invite: invite new users `netlink`
85 | * claim: allow claiming actions `claimaction`
86 | * order: create new orders `transfersale`
87 | * verify: verify autenticity on claims `verifyclaim`
88 | * sell: sell items on the shop `createsale` `updatesale` .
89 | * award: awards an action `verifyaction` (`award`)
90 | *
91 | * All of those roles are used from within the contract to mediate the usage of some actions.
92 | *
93 | *
94 | * Roles are scoped by community.
95 | */
96 | TABLE role
97 | {
98 | eosio::name name;
99 | std::vector permissions;
100 |
101 | std::uint64_t primary_key() const { return name.value; }
102 |
103 | EOSLIB_SERIALIZE(role, (name)(permissions));
104 | };
105 |
106 | TABLE objective
107 | {
108 | std::uint64_t id;
109 | std::string description;
110 | eosio::symbol community;
111 | eosio::name creator;
112 |
113 | // keys and indexes
114 | std::uint64_t primary_key() const { return id; }
115 | std::uint64_t by_cmm() const { return community.raw(); }
116 |
117 | EOSLIB_SERIALIZE(objective,
118 | (id)(description)(community)(creator));
119 | };
120 |
121 | TABLE action
122 | {
123 | std::uint64_t id;
124 | std::uint64_t objective_id;
125 | std::string description;
126 | eosio::asset reward;
127 | eosio::asset verifier_reward;
128 | std::uint64_t deadline; // Max date where it can be claimed
129 | std::uint64_t usages; // Max usages
130 | std::uint64_t usages_left;
131 | std::uint64_t verifications; // # verifications needed
132 | std::string verification_type; // Can be 'automatic' and 'claimable'
133 | std::uint8_t is_completed;
134 | eosio::name creator;
135 | std::uint8_t has_proof_photo;
136 | std::uint8_t has_proof_code;
137 | std::string photo_proof_instructions;
138 |
139 | // std::vector roles; // Validators of the action
140 |
141 | std::uint64_t primary_key() const { return id; }
142 | std::uint64_t by_objective() const { return objective_id; }
143 |
144 | EOSLIB_SERIALIZE(action,
145 | (id)(objective_id)(description)(reward)(verifier_reward)(deadline)(usages)(usages_left)(verifications)(verification_type)(is_completed)(creator)(has_proof_photo)(has_proof_code)(photo_proof_instructions));
146 | };
147 |
148 | TABLE action_validator
149 | {
150 | std::uint64_t id;
151 | std::uint64_t action_id;
152 | eosio::name validator;
153 |
154 | std::uint64_t primary_key() const { return id; }
155 | std::uint64_t by_action() const { return action_id; }
156 |
157 | EOSLIB_SERIALIZE(action_validator,
158 | (id)(action_id)(validator));
159 | };
160 |
161 | TABLE claim
162 | {
163 | std::uint64_t id;
164 | std::uint64_t action_id;
165 | eosio::name claimer;
166 | std::string status; // Can be: `approved` `rejected` `pending`
167 | std::string proof_photo;
168 | std::string proof_code;
169 |
170 | std::uint64_t primary_key() const { return id; }
171 | std::uint64_t by_action() const { return action_id; }
172 |
173 | EOSLIB_SERIALIZE(claim,
174 | (id)(action_id)(claimer)(status)(proof_photo)(proof_code));
175 | };
176 |
177 | TABLE check
178 | {
179 | std::uint64_t id;
180 | std::uint64_t claim_id;
181 | eosio::name validator;
182 | std::uint8_t is_verified; // Answer the verificator gave
183 |
184 | std::uint64_t primary_key() const { return id; }
185 | std::uint64_t by_claim() const { return claim_id; }
186 |
187 | EOSLIB_SERIALIZE(check,
188 | (id)(claim_id)(validator)(is_verified));
189 | };
190 |
191 | TABLE indexes
192 | {
193 | std::uint64_t last_used_sale_id;
194 | std::uint64_t last_used_objective_id;
195 | std::uint64_t last_used_action_id;
196 | std::uint64_t last_used_claim_id;
197 | };
198 |
199 | /// @abi action
200 | /// Creates a cambiatus community
201 | ACTION create(eosio::asset cmm_asset, eosio::name creator, std::string logo, std::string name,
202 | std::string description, eosio::asset inviter_reward, eosio::asset invited_reward,
203 | std::uint8_t has_objectives, std::uint8_t has_shop, std::uint8_t has_kyc,
204 | std::uint8_t auto_invite, std::string subdomain, std::string website);
205 |
206 | /// @abi action
207 | /// Updates community attributes
208 | ACTION update(eosio::asset cmm_asset, std::string logo, std::string name,
209 | std::string description, eosio::asset inviter_reward, eosio::asset invited_reward,
210 | std::uint8_t has_objectives, std::uint8_t has_shop, std::uint8_t has_kyc,
211 | std::uint8_t auto_invite, std::string subdomain, std::string website);
212 |
213 | /// @abi action
214 | /// Adds a user to a community
215 | ACTION netlink(eosio::symbol community_id, eosio::name inviter, eosio::name new_user, std::string user_type);
216 |
217 | /// @abi action
218 | /// Create/Edit a given objective
219 | ACTION upsertobjctv(eosio::symbol community_id, std::uint64_t objective_id, std::string description, eosio::name editor);
220 |
221 | /// @abi action
222 | /// Update action
223 | ACTION upsertaction(eosio::symbol community_id, std::uint64_t action_id, std::uint64_t objective_id,
224 | std::string description, eosio::asset reward,
225 | eosio::asset verifier_reward, std::uint64_t deadline,
226 | std::uint64_t usages, std::uint64_t usages_left,
227 | std::uint64_t verifications, std::string verification_type,
228 | std::string validators_str, std::uint8_t is_completed,
229 | eosio::name creator,
230 | std::uint8_t has_proof_photo, std::uint8_t has_proof_code,
231 | std::string photo_proof_instructions, std::string image);
232 |
233 | /// @abi action
234 | /// Start a new claim on an action
235 | ACTION claimaction(eosio::symbol community_id, std::uint64_t action_id, eosio::name maker,
236 | std::string proof_photo, std::string proof_code, uint32_t proof_time);
237 |
238 | /// @abi action
239 | /// Send a vote verification for a given claim. It has to be `claimable` verification_type
240 | ACTION verifyclaim(eosio::symbol community_id, std::uint64_t claim_id, eosio::name verifier, std::uint8_t vote);
241 |
242 | /// @abi action
243 | /// Verify that a given action was completed. It has to have the `automatic` verification_type
244 | ACTION reward(eosio::symbol community_id, std::uint64_t action_id, eosio::name receiver, eosio::name awarder);
245 |
246 | /// @abi action
247 | /// Offchain event hook for when a transfer occours in our shop
248 | ACTION transfersale(std::uint64_t sale_id, eosio::name from, eosio::name to, eosio::asset quantity, std::uint64_t units);
249 |
250 | /// @abi action
251 | /// Upserts roles in a community
252 | ACTION upsertrole(eosio::symbol community_id, eosio::name name, std::string color, std::vector & permissions);
253 |
254 | /// @abi action
255 | /// Sets a number of roles for an user
256 | ACTION assignroles(eosio::symbol community_id, eosio::name member, std::vector & roles);
257 |
258 | /// @abi action
259 | /// Set the indices for a chain
260 | ACTION setindices(std::uint64_t sale_id, std::uint64_t objective_id, std::uint64_t action_id, std::uint64_t claim_id);
261 |
262 | /// @abi action
263 | /// Deletes an objective
264 | ACTION deleteobj(std::uint64_t id);
265 |
266 | /// @abi action
267 | /// Deletes an action
268 | ACTION deleteact(std::uint64_t id);
269 |
270 | ACTION clean(std::string t, eosio::name name_scope, eosio::symbol symbol_scope);
271 |
272 | // Get available key
273 | uint64_t get_available_id(std::string table);
274 |
275 | // Convinience methods
276 | bool is_member(eosio::symbol community_id, eosio::name user);
277 | bool has_permission(eosio::symbol community_id, eosio::name user, permission e_permission);
278 | std::string permission_to_string(permission e_permission);
279 |
280 | typedef eosio::multi_index communities;
281 | typedef eosio::multi_index members;
282 |
283 | typedef eosio::multi_index > >
287 | networks;
288 |
289 | typedef eosio::multi_index > >
293 | objectives;
294 |
295 | typedef eosio::multi_index > >
299 | actions;
300 |
301 | typedef eosio::multi_index > >
305 | validators;
306 |
307 | typedef eosio::multi_index > >
310 | claims;
311 |
312 | typedef eosio::multi_index > >
316 | checks;
317 |
318 | typedef eosio::multi_index roles;
319 |
320 | typedef eosio::singleton item_indexes;
321 |
322 | item_indexes curr_indexes;
323 |
324 | // Initialize our singleton table for indices
325 | cambiatus(eosio::name receiver, eosio::name code, eosio::datastream ds) : contract(receiver, code, ds), curr_indexes(_self, _self.value) {}
326 | };
327 |
328 | const auto currency_account = eosio::name{TOSTR(__TOKEN_ACCOUNT__)};
329 | const auto backend_account = eosio::name{TOSTR(__BACKEND_ACCOUNT__)};
330 | const uint32_t proof_expiration_secs = __PROOF_EXPIRATION_SECS__;
331 |
332 | // Add global reference for a table from the token contract
333 | struct currency_stats
334 | {
335 | eosio::asset supply;
336 | eosio::asset max_supply;
337 | eosio::asset min_balance;
338 | eosio::name issuer;
339 | std::string type;
340 |
341 | uint64_t primary_key() const { return supply.symbol.code().raw(); }
342 | };
343 | typedef eosio::multi_index cambiatus_tokens;
344 |
--------------------------------------------------------------------------------
/community/community.wasm:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cambiatus/contracts/32190b274bd996df3c1f03c834230aae43309086/community/community.wasm
--------------------------------------------------------------------------------
/community/ricardian/community.clauses.md:
--------------------------------------------------------------------------------
1 | Data Storage
2 | ---
3 | spec-version: 0.0.1
4 | title: General Data Storage
5 | summary: This smart contract will store data added by the user. The user consents to the storage of this data by signing the transaction.
6 | icon:
7 |
8 |
9 | Data Usage
10 | ---
11 | spec-version: 0.0.1
12 | title: General Data Use
13 | summary: This smart contract will store user data. The smart contract will not use the stored data for any purpose outside store and delete.
14 | icon:
15 |
16 | Data Ownership
17 | ---
18 | spec-version: 0.0.1
19 | title: Data Ownership
20 | summary: The user of this smart contract verifies that the data is owned by the smart contract, and that the smart contract can use the data in accordance to the terms defined in the Ricardian Contract.
21 | icon:
22 |
23 | Data Distribution
24 | ---
25 | spec-version: 0.0.1
26 | title: Data Ownership
27 | summary: The smart contract promises to not actively share or distribute the address data. The user of the smart contract understands that data stored in a multi index table is not private data and can be accessed by any user of the blockchain.
28 | icon:
29 |
30 |
31 | Data Future
32 | ---
33 | spec-version: 0.0.1
34 | title: Data Ownership
35 | summary: The smart contract promises to only use the data in accordance of the terms defined in the Ricardian Contract, now and at all future dates.
36 | icon:
37 |
--------------------------------------------------------------------------------
/community/ricardian/community.contracts.md:
--------------------------------------------------------------------------------
1 | create
2 | ---
3 | spec-version: 0.0.1
4 | title: Create new community
5 | summary: Creates a new community on Cambiatus. It requires you to send: `cmm_asset`, `creator`, `logo`, `name`, `description`, `inviter_reward` and `invited_reward`. A Cambiatus community is closelly tied to a Cambiatus Token. A community allows a group of people with common goals and objectives to connect and allow the creation of incentives to reach those objectives. It also help to buy and sell products
6 | icon:
7 |
8 | update
9 | ---
10 | spec-version: 0.0.1
11 | title: Update some information about a community
12 | summary: Update information on a existing community on Cambiatus. It requires you to send: `cmm_asset`, `logo`, `name`, `description`, `inviter_reward` and `invited_reward`. All information will be saved, with the exception of the asset that cannot be changed
13 | icon:
14 |
15 | netlink
16 | ---
17 | spec-version: 0.0.1
18 | title: Invites a new account to a given community
19 | summary: Add a user to the Cambiatus community network. It requires you to send: `cmm_asset`, `inviter` and `new_user`. We'll save who invited the new account and on which community
20 | icon:
21 |
22 | newobjective
23 | ---
24 | spec-version: 0.0.1
25 | title:
26 | summary:
27 | icon:
28 |
29 | newaction
30 | ---
31 | spec-version: 0.0.1
32 | title:
33 | summary:
34 | icon:
35 |
36 | claimaction
37 | ---
38 | spec-version: 0.0.1
39 | title:
40 | summary:
41 | icon:
42 |
43 | verifyclaim
44 | ---
45 | spec-version: 0.0.1
46 | title:
47 | summary:
48 | icon:
49 |
50 | verifyaction
51 | ---
52 | spec-version: 0.0.1
53 | title:
54 | summary:
55 | icon:
56 |
57 | createsale
58 | ---
59 | spec-version: 0.0.1
60 | title: Create a sale on a given community
61 | summary: Enable a single user to create a new sale (either buy or sell) on a given community. It requires you to send: `from`, `title`, `description`, `quantity`, `image`, `is_buy` and `units`. All information sent is going to be saved. Note that `quantity` is related to price and `units` to number of items available.
62 | icon:
63 |
64 | updatesale
65 | ---
66 | spec-version: 0.0.1
67 | title: Update a sale
68 | summary: Enable the sale creator to update some details of a single sale. It requires you to send: `sale_id`, `title`, `description`, `quantity`, `image` and `units`. Except by `sale_id`, all information sent is going to be updated. Note that `quantity` is related to price and `units` to number of items available.
69 | icon:
70 |
71 | deletesale
72 | ---
73 | spec-version: 0.0.1
74 | title: Delete a sale
75 | summary: Enable the sale creator to remove a single sale. It requires you to send: `sale_id`. No information is going to be saved.
76 | icon:
77 |
78 | removels
79 | ---
80 | spec-version: 0.0.1
81 | title: Delete a last sale
82 | summary: Remove temporary information created during a sale creation. It requires you to send: `ls_id`. No information is going to be saved.
83 | icon:
84 |
85 | reactsale
86 | ---
87 | spec-version: 0.0.1
88 | title: React to a sale
89 | summary: Enable any user in the same community (except by creator) to react to a sale. It requires you to send: `sale_id`, `from` and `type`. No information is going to be saved.
90 | icon:
91 |
92 | transfersale
93 | ---
94 | spec-version: 0.0.1
95 | title: Process a sale transfer
96 | summary: Enable different users to exchange value for a given sale. It requires you to send: `sale_id`, `from`, `to`, `quantity` and `units`. No information is going to be saved, only used to update previous sale information. Note that `from` is the one interested in the sale, `to` the sale creator, `quantity` is related to price and `units` to number of items available.
97 | icon:
98 |
99 | updobjective
100 | ---
101 | spec-version: 0.0.1
102 | title: updobjective placeholder
103 | summary: placeholder
104 | icon:
105 |
106 | upsertaction
107 | ---
108 | spec-version: 0.0.1
109 | title: upsertaction placeholder
110 | summary: placeholder
111 | icon:
112 |
113 | setindices
114 | ---
115 | spec-version: 0.0.1
116 | title: setindices placeholder
117 | summary: placeholder
118 | icon:
119 |
120 | deleteobj
121 | ---
122 | spec-version: 0.0.1
123 | title: deleteobj placeholder
124 | summary: placeholder
125 | icon:
126 |
127 | deleteact
128 | ---
129 | spec-version: 0.0.1
130 | title: deleteact placeholder
131 | summary: placeholder
132 | icon:
133 |
134 | migrate
135 | ---
136 | spec-version: 0.0.1
137 | title: migrate placeholder
138 | summary: placeholder
139 | icon:
140 |
141 | clean
142 | ---
143 | spec-version: 0.0.1
144 | title: clean placeholder
145 | summary: placeholder
146 | icon:
147 |
148 | migrateafter
149 | ---
150 | spec-version: 0.0.1
151 | title: migrateafter placeholder
152 | summary: placeholder
153 | icon:
--------------------------------------------------------------------------------
/tests/claim_test.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | # Make sure we don't use any unset variables
4 | set -eux
5 |
6 | # cleos='cleos -u https://staging.cambiatus.io'
7 | cleos='cleos' # running local
8 | CMM_CONTRACT='cambiatus.cm'
9 | TK_CONTRACT='cambiatus.tk'
10 | BACKEND_ACC='cambiatus'
11 | OBJECTIVE_ID=64 # todo: change as needed for your environment
12 |
13 | LUCCA_KEY='EOS6UzXrw93HKhugfRewVNpU5aM9hSUSmcwWtWgecDgYi6nwEHMuu'
14 | TEST_KEY='EOS8LtuSpUvAPWEJkzea1tAzzeWsWSrTpEsCmwacFbFxXz4Xjn5R4'
15 |
16 | function create_eos_account () {
17 | $cleos system newaccount --stake-net "10.0000 EOS" --stake-cpu "10.0000 EOS" --buy-ram "10.0000 EOS" eosio $1 $2
18 | }
19 |
20 | function create_test_users() {
21 | echo "======== Creating Test Accounts"
22 | create_eos_account 'claimcreator' $TEST_KEY $TEST_KEY
23 | create_eos_account 'claimclaimer' $TEST_KEY $TEST_KEY
24 | create_eos_account 'claimverif1' $TEST_KEY $TEST_KEY
25 | create_eos_account 'claimverif2' $TEST_KEY $TEST_KEY
26 | create_eos_account 'claimverif3' $TEST_KEY $TEST_KEY
27 | create_eos_account 'claimverif4' $TEST_KEY $TEST_KEY
28 | create_eos_account 'claimverif5' $TEST_KEY $TEST_KEY
29 | }
30 |
31 | function create_test_community() {
32 | echo "======== Creating Test Community / Actions"
33 | $cleos push action $CMM_CONTRACT create '["0 CLM", "claimcreator", "", "Claimers", "", "1 CLM", "10 CLM", 1, 0, 0]' -p claimcreator
34 | $cleos push action $TK_CONTRACT create '["claimcreator", "21000000 CLM", "-1000 CLM", "mcc"]' -p claimcreator
35 |
36 | $cleos push action $CMM_CONTRACT netlink '["0 CLM", "claimcreator", "claimclaimer", "natural"]' -p claimcreator@active
37 | $cleos push action $CMM_CONTRACT netlink '["0 CLM", "claimcreator", "claimverif1", "natural"]' -p claimcreator@active
38 | $cleos push action $CMM_CONTRACT netlink '["0 CLM", "claimcreator", "claimverif2", "natural"]' -p claimcreator
39 | $cleos push action $CMM_CONTRACT netlink '["0 CLM", "claimcreator", "claimverif3", "natural"]' -p claimcreator
40 | $cleos push action $CMM_CONTRACT netlink '["0 CLM", "claimcreator", "claimverif4", "natural"]' -p claimcreator
41 | $cleos push action $CMM_CONTRACT netlink '["0 CLM", "claimcreator", "claimverif5", "natural"]' -p claimcreator
42 |
43 | # as 18 may 2020, this insert yielded an ID of 64
44 | $cleos push action $CMM_CONTRACT newobjective '["0 CLM", "Test claims", "claimcreator"]' -p claimcreator
45 |
46 | $cleos get table $CMM_CONTRACT $CMM_CONTRACT objective
47 | echo "please save the objective id from above"
48 | }
49 |
50 | function create_actions() {
51 | $cleos push action $CMM_CONTRACT upsertaction '[0, '$OBJECTIVE_ID', "Claim with 3 verifications", "1 CLM", "0 CLM", 0, 0, 0, 3, "claimable", "claimverif1-claimverif2-claimverif3-claimverif4", 0, "claimcreator", 1, 1, "please add pics"]' -p claimcreator
52 | $cleos push action $CMM_CONTRACT upsertaction '[0, '$OBJECTIVE_ID', "Claim with 4 verifications", "1 CLM", "0 CLM", 0, 0, 0, 5, "claimable", "claimverif1-claimverif2-claimverif3-claimverif4-claimverif5", 0, "claimcreator", 0, 0, ""]' -p claimcreator
53 |
54 | $cleos get table $CMM_CONTRACT $CMM_CONTRACT action
55 | }
56 |
57 | function claim_actions() {
58 | echo "======== Claiming actions"
59 | FIRST_ID=137
60 | SECOND_ID=138
61 | # We will do this as 3 batches, all with the same scenarios but the actions will have different rules
62 |
63 | ######### First Action, requires 3 approvals
64 | # First claim will be accepted by all
65 | FIRST_CLAIM=159
66 | # $cleos push action $CMM_CONTRACT claimaction '['$FIRST_ID', claimclaimer]' -p claimclaimer
67 |
68 | # $cleos push action $CMM_CONTRACT verifyclaim '['$FIRST_CLAIM', claimverif1, 1]' -p claimverif1
69 | # $cleos push action $CMM_CONTRACT verifyclaim '['$FIRST_CLAIM', claimverif2, 1]' -p claimverif2
70 | # $cleos push action $CMM_CONTRACT verifyclaim '['$FIRST_CLAIM', claimverif3, 1]' -p claimverif3
71 |
72 | # Second claim will be rejected by all
73 | SECOND_CLAIM=160
74 | # $cleos push action $CMM_CONTRACT claimaction '['$FIRST_ID', claimclaimer]' -p claimclaimer
75 |
76 | # $cleos push action $CMM_CONTRACT verifyclaim '['$SECOND_CLAIM', claimverif1, 0]' -p claimverif1
77 | # $cleos push action $CMM_CONTRACT verifyclaim '['$SECOND_CLAIM', claimverif2, 0]' -p claimverif2
78 | # $cleos push action $CMM_CONTRACT verifyclaim '['$SECOND_CLAIM', claimverif3, 0]' -p claimverif3
79 |
80 |
81 | # Thrid will be accepted by the majority
82 | THIRD_CLAIM=161
83 | # $cleos push action $CMM_CONTRACT claimaction '['$FIRST_ID', claimclaimer]' -p claimclaimer
84 |
85 | # $cleos push action $CMM_CONTRACT verifyclaim '['$THIRD_CLAIM', claimverif1, 1]' -p claimverif1
86 | # $cleos push action $CMM_CONTRACT verifyclaim '['$THIRD_CLAIM', claimverif2, 1]' -p claimverif2
87 | # $cleos push action $CMM_CONTRACT verifyclaim '['$THIRD_CLAIM', claimverif3, 0]' -p claimverif3
88 |
89 | # should fail, claim not pending
90 | # $cleos push action $CMM_CONTRACT verifyclaim '['$THIRD_CLAIM', claimverif3, 1]' -p claimverif4
91 |
92 | # Forth will be rejected by the majority
93 | FORTH_CLAIM=162
94 | # $cleos push action $CMM_CONTRACT claimaction '['$FIRST_ID', claimclaimer]' -p claimclaimer
95 |
96 | # $cleos push action $CMM_CONTRACT verifyclaim '['$FORTH_CLAIM', claimverif1, 1]' -p claimverif1
97 | # $cleos push action $CMM_CONTRACT verifyclaim '['$FORTH_CLAIM', claimverif2, 0]' -p claimverif2
98 | # $cleos push action $CMM_CONTRACT verifyclaim '['$FORTH_CLAIM', claimverif3, 0]' -p claimverif3
99 |
100 | # should fail, claim not pending anymore
101 | # $cleos push action $CMM_CONTRACT verifyclaim '['$FORTH_CLAIM', claimverif2, 0]' -p claimverif2
102 |
103 | ######### Second Action, requires 5 approvals
104 | # First claim will be accepted by all
105 | FIFTH_CLAIM=163
106 | # $cleos push action $CMM_CONTRACT claimaction '['$SECOND_ID', claimclaimer]' -p claimclaimer
107 |
108 | # $cleos push action $CMM_CONTRACT verifyclaim '['$FIFTH_CLAIM', claimverif1, 1]' -p claimverif1
109 | # $cleos push action $CMM_CONTRACT verifyclaim '['$FIFTH_CLAIM', claimverif2, 1]' -p claimverif2
110 | # $cleos push action $CMM_CONTRACT verifyclaim '['$FIFTH_CLAIM', claimverif3, 1]' -p claimverif3
111 | # $cleos push action $CMM_CONTRACT verifyclaim '['$FIFTH_CLAIM', claimverif4, 1]' -p claimverif4
112 | # $cleos push action $CMM_CONTRACT verifyclaim '['$FIFTH_CLAIM', claimverif5, 1]' -p claimverif5
113 |
114 | # Second claim will be rejeceted by all
115 | SIXTH_CLAIM=164
116 | # $cleos push action $CMM_CONTRACT claimaction '['$SECOND_ID', claimclaimer]' -p claimclaimer
117 |
118 | # $cleos push action $CMM_CONTRACT verifyclaim '['$SIXTH_CLAIM', claimverif1, 0]' -p claimverif1
119 | # $cleos push action $CMM_CONTRACT verifyclaim '['$SIXTH_CLAIM', claimverif2, 0]' -p claimverif2
120 | # $cleos push action $CMM_CONTRACT verifyclaim '['$SIXTH_CLAIM', claimverif3, 0]' -p claimverif3
121 | # $cleos push action $CMM_CONTRACT verifyclaim '['$SIXTH_CLAIM', claimverif4, 0]' -p claimverif4
122 | # $cleos push action $CMM_CONTRACT verifyclaim '['$SIXTH_CLAIM', claimverif5, 0]' -p claimverif5
123 |
124 |
125 | # Thrid will be accepted by the majority
126 | # SEVENTH_CLAIM=165
127 | # $cleos push action $CMM_CONTRACT claimaction '['$SECOND_ID', claimclaimer]' -p claimclaimer
128 |
129 | # $cleos push action $CMM_CONTRACT verifyclaim '['$SEVENTH_CLAIM', claimverif1, 0]' -p claimverif1
130 | # $cleos push action $CMM_CONTRACT verifyclaim '['$SEVENTH_CLAIM', claimverif2, 0]' -p claimverif2
131 | # $cleos push action $CMM_CONTRACT verifyclaim '['$SEVENTH_CLAIM', claimverif3, 1]' -p claimverif3
132 | # $cleos push action $CMM_CONTRACT verifyclaim '['$SEVENTH_CLAIM', claimverif4, 1]' -p claimverif4
133 | # $cleos push action $CMM_CONTRACT verifyclaim '['$SEVENTH_CLAIM', claimverif5, 1]' -p claimverif5
134 |
135 |
136 | # Forth will be rejeceted by the majority
137 | EIGHTH_CLAIM=166
138 | $cleos push action $CMM_CONTRACT claimaction '['$SECOND_ID', claimclaimer]' -p claimclaimer
139 |
140 | $cleos push action $CMM_CONTRACT verifyclaim '['$EIGHTH_CLAIM', claimverif1, 0]' -p claimverif1
141 | $cleos push action $CMM_CONTRACT verifyclaim '['$EIGHTH_CLAIM', claimverif2, 0]' -p claimverif2
142 | $cleos push action $CMM_CONTRACT verifyclaim '['$EIGHTH_CLAIM', claimverif3, 0]' -p claimverif3
143 | $cleos push action $CMM_CONTRACT verifyclaim '['$EIGHTH_CLAIM', claimverif4, 1]' -p claimverif4
144 | $cleos push action $CMM_CONTRACT verifyclaim '['$EIGHTH_CLAIM', claimverif5, 1]' -p claimverif5
145 |
146 |
147 | }
148 |
149 | function vote_claim() {
150 | echo "======== Verify claims"
151 | $cleos push action $CMM_CONTRACT verifyclaim '[, "claimverif1", true]' -p claimverif1
152 | }
153 |
154 | # create_test_users
155 | # create_test_community
156 | create_actions
157 | # claim_actions
158 |
--------------------------------------------------------------------------------
/tests/eosio.contracts/eosio.bios.abi:
--------------------------------------------------------------------------------
1 | {
2 | "____comment": "This file was generated with eosio-abigen. DO NOT EDIT ",
3 | "version": "eosio::abi/1.1",
4 | "types": [],
5 | "structs": [
6 | {
7 | "name": "abi_hash",
8 | "base": "",
9 | "fields": [
10 | {
11 | "name": "owner",
12 | "type": "name"
13 | },
14 | {
15 | "name": "hash",
16 | "type": "checksum256"
17 | }
18 | ]
19 | },
20 | {
21 | "name": "activate",
22 | "base": "",
23 | "fields": [
24 | {
25 | "name": "feature_digest",
26 | "type": "checksum256"
27 | }
28 | ]
29 | },
30 | {
31 | "name": "authority",
32 | "base": "",
33 | "fields": [
34 | {
35 | "name": "threshold",
36 | "type": "uint32"
37 | },
38 | {
39 | "name": "keys",
40 | "type": "key_weight[]"
41 | },
42 | {
43 | "name": "accounts",
44 | "type": "permission_level_weight[]"
45 | },
46 | {
47 | "name": "waits",
48 | "type": "wait_weight[]"
49 | }
50 | ]
51 | },
52 | {
53 | "name": "blockchain_parameters",
54 | "base": "",
55 | "fields": [
56 | {
57 | "name": "max_block_net_usage",
58 | "type": "uint64"
59 | },
60 | {
61 | "name": "target_block_net_usage_pct",
62 | "type": "uint32"
63 | },
64 | {
65 | "name": "max_transaction_net_usage",
66 | "type": "uint32"
67 | },
68 | {
69 | "name": "base_per_transaction_net_usage",
70 | "type": "uint32"
71 | },
72 | {
73 | "name": "net_usage_leeway",
74 | "type": "uint32"
75 | },
76 | {
77 | "name": "context_free_discount_net_usage_num",
78 | "type": "uint32"
79 | },
80 | {
81 | "name": "context_free_discount_net_usage_den",
82 | "type": "uint32"
83 | },
84 | {
85 | "name": "max_block_cpu_usage",
86 | "type": "uint32"
87 | },
88 | {
89 | "name": "target_block_cpu_usage_pct",
90 | "type": "uint32"
91 | },
92 | {
93 | "name": "max_transaction_cpu_usage",
94 | "type": "uint32"
95 | },
96 | {
97 | "name": "min_transaction_cpu_usage",
98 | "type": "uint32"
99 | },
100 | {
101 | "name": "max_transaction_lifetime",
102 | "type": "uint32"
103 | },
104 | {
105 | "name": "deferred_trx_expiration_window",
106 | "type": "uint32"
107 | },
108 | {
109 | "name": "max_transaction_delay",
110 | "type": "uint32"
111 | },
112 | {
113 | "name": "max_inline_action_size",
114 | "type": "uint32"
115 | },
116 | {
117 | "name": "max_inline_action_depth",
118 | "type": "uint16"
119 | },
120 | {
121 | "name": "max_authority_depth",
122 | "type": "uint16"
123 | }
124 | ]
125 | },
126 | {
127 | "name": "canceldelay",
128 | "base": "",
129 | "fields": [
130 | {
131 | "name": "canceling_auth",
132 | "type": "permission_level"
133 | },
134 | {
135 | "name": "trx_id",
136 | "type": "checksum256"
137 | }
138 | ]
139 | },
140 | {
141 | "name": "deleteauth",
142 | "base": "",
143 | "fields": [
144 | {
145 | "name": "account",
146 | "type": "name"
147 | },
148 | {
149 | "name": "permission",
150 | "type": "name"
151 | }
152 | ]
153 | },
154 | {
155 | "name": "key_weight",
156 | "base": "",
157 | "fields": [
158 | {
159 | "name": "key",
160 | "type": "public_key"
161 | },
162 | {
163 | "name": "weight",
164 | "type": "uint16"
165 | }
166 | ]
167 | },
168 | {
169 | "name": "linkauth",
170 | "base": "",
171 | "fields": [
172 | {
173 | "name": "account",
174 | "type": "name"
175 | },
176 | {
177 | "name": "code",
178 | "type": "name"
179 | },
180 | {
181 | "name": "type",
182 | "type": "name"
183 | },
184 | {
185 | "name": "requirement",
186 | "type": "name"
187 | }
188 | ]
189 | },
190 | {
191 | "name": "newaccount",
192 | "base": "",
193 | "fields": [
194 | {
195 | "name": "creator",
196 | "type": "name"
197 | },
198 | {
199 | "name": "name",
200 | "type": "name"
201 | },
202 | {
203 | "name": "owner",
204 | "type": "authority"
205 | },
206 | {
207 | "name": "active",
208 | "type": "authority"
209 | }
210 | ]
211 | },
212 | {
213 | "name": "onerror",
214 | "base": "",
215 | "fields": [
216 | {
217 | "name": "sender_id",
218 | "type": "uint128"
219 | },
220 | {
221 | "name": "sent_trx",
222 | "type": "bytes"
223 | }
224 | ]
225 | },
226 | {
227 | "name": "permission_level",
228 | "base": "",
229 | "fields": [
230 | {
231 | "name": "actor",
232 | "type": "name"
233 | },
234 | {
235 | "name": "permission",
236 | "type": "name"
237 | }
238 | ]
239 | },
240 | {
241 | "name": "permission_level_weight",
242 | "base": "",
243 | "fields": [
244 | {
245 | "name": "permission",
246 | "type": "permission_level"
247 | },
248 | {
249 | "name": "weight",
250 | "type": "uint16"
251 | }
252 | ]
253 | },
254 | {
255 | "name": "producer_key",
256 | "base": "",
257 | "fields": [
258 | {
259 | "name": "producer_name",
260 | "type": "name"
261 | },
262 | {
263 | "name": "block_signing_key",
264 | "type": "public_key"
265 | }
266 | ]
267 | },
268 | {
269 | "name": "reqactivated",
270 | "base": "",
271 | "fields": [
272 | {
273 | "name": "feature_digest",
274 | "type": "checksum256"
275 | }
276 | ]
277 | },
278 | {
279 | "name": "reqauth",
280 | "base": "",
281 | "fields": [
282 | {
283 | "name": "from",
284 | "type": "name"
285 | }
286 | ]
287 | },
288 | {
289 | "name": "setabi",
290 | "base": "",
291 | "fields": [
292 | {
293 | "name": "account",
294 | "type": "name"
295 | },
296 | {
297 | "name": "abi",
298 | "type": "bytes"
299 | }
300 | ]
301 | },
302 | {
303 | "name": "setalimits",
304 | "base": "",
305 | "fields": [
306 | {
307 | "name": "account",
308 | "type": "name"
309 | },
310 | {
311 | "name": "ram_bytes",
312 | "type": "int64"
313 | },
314 | {
315 | "name": "net_weight",
316 | "type": "int64"
317 | },
318 | {
319 | "name": "cpu_weight",
320 | "type": "int64"
321 | }
322 | ]
323 | },
324 | {
325 | "name": "setcode",
326 | "base": "",
327 | "fields": [
328 | {
329 | "name": "account",
330 | "type": "name"
331 | },
332 | {
333 | "name": "vmtype",
334 | "type": "uint8"
335 | },
336 | {
337 | "name": "vmversion",
338 | "type": "uint8"
339 | },
340 | {
341 | "name": "code",
342 | "type": "bytes"
343 | }
344 | ]
345 | },
346 | {
347 | "name": "setparams",
348 | "base": "",
349 | "fields": [
350 | {
351 | "name": "params",
352 | "type": "blockchain_parameters"
353 | }
354 | ]
355 | },
356 | {
357 | "name": "setpriv",
358 | "base": "",
359 | "fields": [
360 | {
361 | "name": "account",
362 | "type": "name"
363 | },
364 | {
365 | "name": "is_priv",
366 | "type": "uint8"
367 | }
368 | ]
369 | },
370 | {
371 | "name": "setprods",
372 | "base": "",
373 | "fields": [
374 | {
375 | "name": "schedule",
376 | "type": "producer_key[]"
377 | }
378 | ]
379 | },
380 | {
381 | "name": "unlinkauth",
382 | "base": "",
383 | "fields": [
384 | {
385 | "name": "account",
386 | "type": "name"
387 | },
388 | {
389 | "name": "code",
390 | "type": "name"
391 | },
392 | {
393 | "name": "type",
394 | "type": "name"
395 | }
396 | ]
397 | },
398 | {
399 | "name": "updateauth",
400 | "base": "",
401 | "fields": [
402 | {
403 | "name": "account",
404 | "type": "name"
405 | },
406 | {
407 | "name": "permission",
408 | "type": "name"
409 | },
410 | {
411 | "name": "parent",
412 | "type": "name"
413 | },
414 | {
415 | "name": "auth",
416 | "type": "authority"
417 | }
418 | ]
419 | },
420 | {
421 | "name": "wait_weight",
422 | "base": "",
423 | "fields": [
424 | {
425 | "name": "wait_sec",
426 | "type": "uint32"
427 | },
428 | {
429 | "name": "weight",
430 | "type": "uint16"
431 | }
432 | ]
433 | }
434 | ],
435 | "actions": [
436 | {
437 | "name": "activate",
438 | "type": "activate",
439 | "ricardian_contract": "---\nspec_version: \"0.2.0\"\ntitle: Activate Protocol Feature\nsummary: 'Activate protocol feature {{nowrap feature_digest}}'\nicon: http://127.0.0.1/ricardian_assets/eosio.contracts/icons/admin.png#9bf1cec664863bd6aaac0f814b235f8799fb02c850e9aa5da34e8a004bd6518e\n---\n\n{{$action.account}} activates the protocol feature with a digest of {{feature_digest}}."
440 | },
441 | {
442 | "name": "canceldelay",
443 | "type": "canceldelay",
444 | "ricardian_contract": "---\nspec_version: \"0.2.0\"\ntitle: Cancel Delayed Transaction\nsummary: '{{nowrap canceling_auth.actor}} cancels a delayed transaction'\nicon: http://127.0.0.1/ricardian_assets/eosio.contracts/icons/account.png#3d55a2fc3a5c20b456f5657faf666bc25ffd06f4836c5e8256f741149b0b294f\n---\n\n{{canceling_auth.actor}} cancels the delayed transaction with id {{trx_id}}."
445 | },
446 | {
447 | "name": "deleteauth",
448 | "type": "deleteauth",
449 | "ricardian_contract": "---\nspec_version: \"0.2.0\"\ntitle: Delete Account Permission\nsummary: 'Delete the {{nowrap permission}} permission of {{nowrap account}}'\nicon: http://127.0.0.1/ricardian_assets/eosio.contracts/icons/account.png#3d55a2fc3a5c20b456f5657faf666bc25ffd06f4836c5e8256f741149b0b294f\n---\n\nDelete the {{permission}} permission of {{account}}."
450 | },
451 | {
452 | "name": "linkauth",
453 | "type": "linkauth",
454 | "ricardian_contract": "---\nspec_version: \"0.2.0\"\ntitle: Link Action to Permission\nsummary: '{{nowrap account}} sets the minimum required permission for the {{#if type}}{{nowrap type}} action of the{{/if}} {{nowrap code}} contract to {{nowrap requirement}}'\nicon: http://127.0.0.1/ricardian_assets/eosio.contracts/icons/account.png#3d55a2fc3a5c20b456f5657faf666bc25ffd06f4836c5e8256f741149b0b294f\n---\n\n{{account}} sets the minimum required permission for the {{#if type}}{{type}} action of the{{/if}} {{code}} contract to {{requirement}}.\n\n{{#if type}}{{else}}Any links explicitly associated to specific actions of {{code}} will take precedence.{{/if}}"
455 | },
456 | {
457 | "name": "newaccount",
458 | "type": "newaccount",
459 | "ricardian_contract": "---\nspec_version: \"0.2.0\"\ntitle: Create New Account\nsummary: '{{nowrap creator}} creates a new account with the name {{nowrap name}}'\nicon: http://127.0.0.1/ricardian_assets/eosio.contracts/icons/account.png#3d55a2fc3a5c20b456f5657faf666bc25ffd06f4836c5e8256f741149b0b294f\n---\n\n{{creator}} creates a new account with the name {{name}} and the following permissions:\n\nowner permission with authority:\n{{to_json owner}}\n\nactive permission with authority:\n{{to_json active}}"
460 | },
461 | {
462 | "name": "onerror",
463 | "type": "onerror",
464 | "ricardian_contract": ""
465 | },
466 | {
467 | "name": "reqactivated",
468 | "type": "reqactivated",
469 | "ricardian_contract": "---\nspec_version: \"0.2.0\"\ntitle: Assert Protocol Feature Activation\nsummary: 'Assert that protocol feature {{nowrap feature_digest}} has been activated'\nicon: http://127.0.0.1/ricardian_assets/eosio.contracts/icons/admin.png#9bf1cec664863bd6aaac0f814b235f8799fb02c850e9aa5da34e8a004bd6518e\n---\n\nAssert that the protocol feature with a digest of {{feature_digest}} has been activated."
470 | },
471 | {
472 | "name": "reqauth",
473 | "type": "reqauth",
474 | "ricardian_contract": "---\nspec_version: \"0.2.0\"\ntitle: Assert Authorization\nsummary: 'Assert that authorization by {{nowrap from}} is provided'\nicon: http://127.0.0.1/ricardian_assets/eosio.contracts/icons/account.png#3d55a2fc3a5c20b456f5657faf666bc25ffd06f4836c5e8256f741149b0b294f\n---\n\nAssert that authorization by {{from}} is provided."
475 | },
476 | {
477 | "name": "setabi",
478 | "type": "setabi",
479 | "ricardian_contract": "---\nspec_version: \"0.2.0\"\ntitle: Deploy Contract ABI\nsummary: 'Deploy contract ABI on account {{nowrap account}}'\nicon: http://127.0.0.1/ricardian_assets/eosio.contracts/icons/account.png#3d55a2fc3a5c20b456f5657faf666bc25ffd06f4836c5e8256f741149b0b294f\n---\n\nDeploy the ABI file associated with the contract on account {{account}}."
480 | },
481 | {
482 | "name": "setalimits",
483 | "type": "setalimits",
484 | "ricardian_contract": "---\nspec_version: \"0.2.0\"\ntitle: Adjust Resource Limits of Account\nsummary: 'Adjust resource limits of account {{nowrap account}}'\nicon: http://127.0.0.1/ricardian_assets/eosio.contracts/icons/admin.png#9bf1cec664863bd6aaac0f814b235f8799fb02c850e9aa5da34e8a004bd6518e\n---\n\n{{$action.account}} updates {{account}}’s resource limits to have a RAM quota of {{ram_bytes}} bytes, a NET bandwidth quota of {{net_weight}} and a CPU bandwidth quota of {{cpu_weight}}."
485 | },
486 | {
487 | "name": "setcode",
488 | "type": "setcode",
489 | "ricardian_contract": "---\nspec_version: \"0.2.0\"\ntitle: Deploy Contract Code\nsummary: 'Deploy contract code on account {{nowrap account}}'\nicon: http://127.0.0.1/ricardian_assets/eosio.contracts/icons/account.png#3d55a2fc3a5c20b456f5657faf666bc25ffd06f4836c5e8256f741149b0b294f\n---\n\nDeploy compiled contract code to the account {{account}}."
490 | },
491 | {
492 | "name": "setparams",
493 | "type": "setparams",
494 | "ricardian_contract": "---\nspec_version: \"0.2.0\"\ntitle: Set System Parameters\nsummary: 'Set system parameters'\nicon: http://127.0.0.1/ricardian_assets/eosio.contracts/icons/admin.png#9bf1cec664863bd6aaac0f814b235f8799fb02c850e9aa5da34e8a004bd6518e\n---\n\n{{$action.account}} sets system parameters to:\n{{to_json params}}"
495 | },
496 | {
497 | "name": "setpriv",
498 | "type": "setpriv",
499 | "ricardian_contract": "---\nspec_version: \"0.2.0\"\ntitle: Make an Account Privileged or Unprivileged\nsummary: '{{#if is_priv}}Make {{nowrap account}} privileged{{else}}Remove privileged status of {{nowrap account}}{{/if}}'\nicon: http://127.0.0.1/ricardian_assets/eosio.contracts/icons/admin.png#9bf1cec664863bd6aaac0f814b235f8799fb02c850e9aa5da34e8a004bd6518e\n---\n\n{{#if is_priv}}\n{{$action.account}} makes {{account}} privileged.\n{{else}}\n{{$action.account}} removes privileged status of {{account}}.\n{{/if}}"
500 | },
501 | {
502 | "name": "setprods",
503 | "type": "setprods",
504 | "ricardian_contract": "---\nspec_version: \"0.2.0\"\ntitle: Set Block Producers\nsummary: 'Set block producer schedule'\nicon: http://127.0.0.1/ricardian_assets/eosio.contracts/icons/admin.png#9bf1cec664863bd6aaac0f814b235f8799fb02c850e9aa5da34e8a004bd6518e\n---\n\n{{$action.account}} proposes a block producer schedule of:\n{{#each schedule}}\n 1. {{this.producer_name}} with a block signing key of {{this.block_signing_key}}\n{{/each}}"
505 | },
506 | {
507 | "name": "unlinkauth",
508 | "type": "unlinkauth",
509 | "ricardian_contract": "---\nspec_version: \"0.2.0\"\ntitle: Unlink Action from Permission\nsummary: '{{nowrap account}} unsets the minimum required permission for the {{#if type}}{{nowrap type}} action of the{{/if}} {{nowrap code}} contract'\nicon: http://127.0.0.1/ricardian_assets/eosio.contracts/icons/account.png#3d55a2fc3a5c20b456f5657faf666bc25ffd06f4836c5e8256f741149b0b294f\n---\n\n{{account}} removes the association between the {{#if type}}{{type}} action of the{{/if}} {{code}} contract and its minimum required permission.\n\n{{#if type}}{{else}}This will not remove any links explicitly associated to specific actions of {{code}}.{{/if}}"
510 | },
511 | {
512 | "name": "updateauth",
513 | "type": "updateauth",
514 | "ricardian_contract": "---\nspec_version: \"0.2.0\"\ntitle: Modify Account Permission\nsummary: 'Add or update the {{nowrap permission}} permission of {{nowrap account}}'\nicon: http://127.0.0.1/ricardian_assets/eosio.contracts/icons/account.png#3d55a2fc3a5c20b456f5657faf666bc25ffd06f4836c5e8256f741149b0b294f\n---\n\nModify, and create if necessary, the {{permission}} permission of {{account}} to have a parent permission of {{parent}} and the following authority:\n{{to_json auth}}"
515 | }
516 | ],
517 | "tables": [
518 | {
519 | "name": "abihash",
520 | "type": "abi_hash",
521 | "index_type": "i64",
522 | "key_names": [],
523 | "key_types": []
524 | }
525 | ],
526 | "ricardian_clauses": [],
527 | "variants": []
528 | }
--------------------------------------------------------------------------------
/tests/eosio.contracts/eosio.bios.wasm:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cambiatus/contracts/32190b274bd996df3c1f03c834230aae43309086/tests/eosio.contracts/eosio.bios.wasm
--------------------------------------------------------------------------------
/token/Makefile:
--------------------------------------------------------------------------------
1 | .PHONY: token.wasm
2 |
3 | src = $(wildcard *.cpp)
4 | obj = $(src:.cpp=.wasm)
5 | OPTS = -D'__COMMUNITY_ACCOUNT__=cambiatus.cm'
6 |
7 | contract = cambiatus.tk
8 | authorization = lucca@active
9 | contract_authorization = $(contract)@active
10 |
11 | url = https://staging.cambiatus.io
12 | # url = https://demo.cambiatus.io
13 | # url = https://app.cambiatus.io
14 |
15 | cleos = cleos -u $(url)
16 | push = $(cleos) push action $(contract) $^ -p $(authorization)
17 | push_adm = $(cleos) push action $(contract) $^ -p $(contract_authorization)
18 |
19 | token.wasm: $(src)
20 | eosio-cpp $(OPTS) -o $@ $^ -abigen -R ./ricardian
21 |
22 | clean:
23 | rm $(obj)
24 |
25 | deploy:
26 | $(cleos) set contract $(contract) ../token
27 |
28 | issue:
29 | # $(push_adm) issue '["karla", "1000 MIZU", ""]'
30 |
--------------------------------------------------------------------------------
/token/ricardian/token.clauses.md:
--------------------------------------------------------------------------------
1 | Data Storage
2 | ---
3 | spec-version: 0.0.1
4 | title: General Data Storage
5 | summary: This smart contract will store data added by the user. The user consents to the storage of this data by signing the transaction.
6 | icon:
--------------------------------------------------------------------------------
/token/ricardian/token.contracts.md:
--------------------------------------------------------------------------------
1 | create
2 | ---
3 | spec-version: 0.0.1
4 | title: create placeholder
5 | summary: placeholder
6 | icon:
7 |
8 | update
9 | ---
10 | spec-version: 0.0.1
11 | title: update placeholder
12 | summary: placeholder
13 | icon:
14 |
15 | transfer
16 | ---
17 | spec-version: 0.0.1
18 | title: transfer placeholder
19 | summary: placeholder
20 | icon:
21 |
22 | issue
23 | ---
24 | spec-version: 0.0.1
25 | title: issue placeholder
26 | summary: placeholder
27 | icon:
28 |
29 | retire
30 | ---
31 | spec-version: 0.0.1
32 | title: retire placeholder
33 | summary: placeholder
34 | icon:
35 |
36 | setexpiry
37 | ---
38 | spec-version: 0.0.1
39 | title: setexpiry placeholder
40 | summary: placeholder
41 | icon:
42 |
43 | initacc
44 | ---
45 | spec-version: 0.0.1
46 | title: initacc placeholder
47 | summary: placeholder
48 | icon:
--------------------------------------------------------------------------------
/token/token.abi:
--------------------------------------------------------------------------------
1 | {
2 | "____comment": "This file was generated with eosio-abigen. DO NOT EDIT ",
3 | "version": "eosio::abi/1.2",
4 | "types": [],
5 | "structs": [
6 | {
7 | "name": "account",
8 | "base": "",
9 | "fields": [
10 | {
11 | "name": "balance",
12 | "type": "asset"
13 | },
14 | {
15 | "name": "last_activity",
16 | "type": "uint32"
17 | }
18 | ]
19 | },
20 | {
21 | "name": "create",
22 | "base": "",
23 | "fields": [
24 | {
25 | "name": "issuer",
26 | "type": "name"
27 | },
28 | {
29 | "name": "max_supply",
30 | "type": "asset"
31 | },
32 | {
33 | "name": "min_balance",
34 | "type": "asset"
35 | },
36 | {
37 | "name": "type",
38 | "type": "string"
39 | }
40 | ]
41 | },
42 | {
43 | "name": "currency_stats",
44 | "base": "",
45 | "fields": [
46 | {
47 | "name": "supply",
48 | "type": "asset"
49 | },
50 | {
51 | "name": "max_supply",
52 | "type": "asset"
53 | },
54 | {
55 | "name": "min_balance",
56 | "type": "asset"
57 | },
58 | {
59 | "name": "issuer",
60 | "type": "name"
61 | },
62 | {
63 | "name": "type",
64 | "type": "string"
65 | }
66 | ]
67 | },
68 | {
69 | "name": "expiry_options",
70 | "base": "",
71 | "fields": [
72 | {
73 | "name": "currency",
74 | "type": "symbol"
75 | },
76 | {
77 | "name": "natural_expiration_period",
78 | "type": "uint32"
79 | },
80 | {
81 | "name": "juridical_expiration_period",
82 | "type": "uint32"
83 | },
84 | {
85 | "name": "renovation_amount",
86 | "type": "asset"
87 | }
88 | ]
89 | },
90 | {
91 | "name": "initacc",
92 | "base": "",
93 | "fields": [
94 | {
95 | "name": "currency",
96 | "type": "symbol"
97 | },
98 | {
99 | "name": "account",
100 | "type": "name"
101 | },
102 | {
103 | "name": "inviter",
104 | "type": "name"
105 | }
106 | ]
107 | },
108 | {
109 | "name": "issue",
110 | "base": "",
111 | "fields": [
112 | {
113 | "name": "to",
114 | "type": "name"
115 | },
116 | {
117 | "name": "quantity",
118 | "type": "asset"
119 | },
120 | {
121 | "name": "memo",
122 | "type": "string"
123 | }
124 | ]
125 | },
126 | {
127 | "name": "retire",
128 | "base": "",
129 | "fields": [
130 | {
131 | "name": "currency",
132 | "type": "symbol"
133 | },
134 | {
135 | "name": "user_type",
136 | "type": "string"
137 | },
138 | {
139 | "name": "memo",
140 | "type": "string"
141 | }
142 | ]
143 | },
144 | {
145 | "name": "setexpiry",
146 | "base": "",
147 | "fields": [
148 | {
149 | "name": "currency",
150 | "type": "symbol"
151 | },
152 | {
153 | "name": "natural_expiration_period",
154 | "type": "uint32"
155 | },
156 | {
157 | "name": "juridical_expiration_period",
158 | "type": "uint32"
159 | },
160 | {
161 | "name": "renovation_amount",
162 | "type": "asset"
163 | }
164 | ]
165 | },
166 | {
167 | "name": "transfer",
168 | "base": "",
169 | "fields": [
170 | {
171 | "name": "from",
172 | "type": "name"
173 | },
174 | {
175 | "name": "to",
176 | "type": "name"
177 | },
178 | {
179 | "name": "quantity",
180 | "type": "asset"
181 | },
182 | {
183 | "name": "memo",
184 | "type": "string"
185 | }
186 | ]
187 | },
188 | {
189 | "name": "update",
190 | "base": "",
191 | "fields": [
192 | {
193 | "name": "max_supply",
194 | "type": "asset"
195 | },
196 | {
197 | "name": "min_balance",
198 | "type": "asset"
199 | }
200 | ]
201 | }
202 | ],
203 | "actions": [
204 | {
205 | "name": "create",
206 | "type": "create",
207 | "ricardian_contract": ""
208 | },
209 | {
210 | "name": "initacc",
211 | "type": "initacc",
212 | "ricardian_contract": ""
213 | },
214 | {
215 | "name": "issue",
216 | "type": "issue",
217 | "ricardian_contract": ""
218 | },
219 | {
220 | "name": "retire",
221 | "type": "retire",
222 | "ricardian_contract": ""
223 | },
224 | {
225 | "name": "setexpiry",
226 | "type": "setexpiry",
227 | "ricardian_contract": ""
228 | },
229 | {
230 | "name": "transfer",
231 | "type": "transfer",
232 | "ricardian_contract": ""
233 | },
234 | {
235 | "name": "update",
236 | "type": "update",
237 | "ricardian_contract": ""
238 | }
239 | ],
240 | "tables": [
241 | {
242 | "name": "accounts",
243 | "type": "account",
244 | "index_type": "i64",
245 | "key_names": [],
246 | "key_types": []
247 | },
248 | {
249 | "name": "expiryopts",
250 | "type": "expiry_options",
251 | "index_type": "i64",
252 | "key_names": [],
253 | "key_types": []
254 | },
255 | {
256 | "name": "stat",
257 | "type": "currency_stats",
258 | "index_type": "i64",
259 | "key_names": [],
260 | "key_types": []
261 | }
262 | ],
263 | "kv_tables": {},
264 | "ricardian_clauses": [],
265 | "variants": [],
266 | "action_results": []
267 | }
--------------------------------------------------------------------------------
/token/token.cpp:
--------------------------------------------------------------------------------
1 | #include "token.hpp"
2 | #include "../utils/utils.cpp"
3 |
4 | /**
5 | Creates a Cambiatus token.
6 | @author Julien Lucca
7 | @version 1.0
8 |
9 | Every token is related to a community. The community must exist in order for a token to be created.
10 | We use eosio::symbol type and check for the given params with the following rules:
11 |
12 | 1) Currently supports two Token Types: `mcc` for multual credit clearing and `expiry` for expiration tokens
13 | 2) Only the community issuer can create new Tokens
14 | 3) Symbol must be unique and the same for both the community and the token
15 | */
16 | void token::create(eosio::name issuer, eosio::asset max_supply,
17 | eosio::asset min_balance, std::string type)
18 | {
19 | auto sym = max_supply.symbol;
20 | eosio::check(max_supply.symbol == min_balance.symbol, "All assets must share the same symbol");
21 | eosio::check(type == "mcc" || type == "expiry", "type must be 'mcc' or 'expiry'");
22 |
23 | // Find existing community
24 | bespiral_communities communities(community_account, community_account.value);
25 | const auto &cmm = communities.get(sym.raw(), "can't find community. Cambiatus Tokens require a community.");
26 |
27 | eosio::check(sym.is_valid(), "invalid symbol");
28 | eosio::check(max_supply.is_valid(), "invalid max_supply");
29 | eosio::check(max_supply.amount > 0, "max max_supply must be positive");
30 |
31 | // Community creator must be the one creating the token
32 | require_auth(cmm.creator);
33 |
34 | // MCC only validations
35 | if (type == "mcc")
36 | {
37 | eosio::check(min_balance.is_valid(), "invalid min_balance");
38 | eosio::check(min_balance.amount <= 0, "min_balance must be equal or less than 0");
39 | eosio::check(max_supply.symbol == min_balance.symbol, "unmatched symbols for max_supply and min_balance. They must be the same");
40 | }
41 |
42 | stats statstable(_self, sym.code().raw());
43 | auto existing = statstable.find(sym.code().raw());
44 | eosio::check(existing == statstable.end(), "token with this symbol already exists");
45 |
46 | statstable.emplace(_self, [&](auto &s)
47 | {
48 | s.supply.symbol = max_supply.symbol;
49 | s.max_supply = max_supply;
50 | s.min_balance = min_balance;
51 | s.issuer = issuer;
52 | s.type = type;
53 | });
54 |
55 | // Notify creator
56 | require_recipient(cmm.creator);
57 |
58 | // Netlink issuer
59 | if (issuer != cmm.creator)
60 | {
61 | require_recipient(issuer);
62 | eosio::action netlink_issuer = eosio::action(eosio::permission_level{cmm.creator, eosio::name{"active"}}, // Permission
63 | community_account, // Account
64 | eosio::name{"netlink"}, // Action
65 | // cmm_asset, new_user, inviter
66 | std::make_tuple(max_supply, issuer, cmm.creator));
67 | netlink_issuer.send();
68 | }
69 |
70 | // Create new balance for the creator
71 | accounts accounts(_self, issuer.value);
72 | accounts.emplace(_self, [&](auto &a)
73 | {
74 | a.balance = eosio::asset(0, max_supply.symbol);
75 | a.last_activity = now();
76 | });
77 | }
78 |
79 | /**
80 | Update token configurations
81 | @author Julien Lucca
82 | @version 1.0
83 | */
84 | void token::update(eosio::asset max_supply, eosio::asset min_balance)
85 | {
86 | eosio::check(max_supply.symbol == min_balance.symbol, "All assets must share the same symbol");
87 |
88 | eosio::check(min_balance.is_valid(), "invalid min_balance");
89 | eosio::check(max_supply.is_valid(), "invalid max_supply");
90 | eosio::check(max_supply.amount > 0, "max max_supply must be positive");
91 |
92 | // Find existing community
93 | bespiral_communities communities(community_account, community_account.value);
94 | const auto &cmm = communities.get(max_supply.symbol.raw(), "can't find community. Cambiatus Tokens require a community.");
95 |
96 | // Find token stats
97 | stats statstable(_self, max_supply.symbol.code().raw());
98 | const auto &st = statstable.get(min_balance.symbol.code().raw(), "token with given symbol does not exist, create token before issue");
99 |
100 | require_auth(st.issuer);
101 |
102 | statstable.modify(st, _self, [&](auto &s)
103 | {
104 | s.max_supply = max_supply;
105 | s.min_balance = min_balance;
106 | });
107 | }
108 |
109 | /**
110 | Issue / Mint tokens.
111 | @author Julien Lucca
112 | @version 1.0
113 |
114 | Allows the community to issue new tokens. It can be done by only by the issuer, and it is limited by the maximum supply available.
115 |
116 | You can choose to send the newly minted tokens to a specific account.
117 | */
118 | void token::issue(eosio::name to, eosio::asset quantity, std::string memo)
119 | {
120 | eosio::symbol sym = quantity.symbol;
121 | eosio::check(sym.is_valid(), "invalid symbol name");
122 | eosio::check(memo.size() <= 256, "memo has more than 256 bytes");
123 |
124 | stats statstable(_self, sym.code().raw());
125 | const auto &st = statstable.get(sym.code().raw(), "token with given symbol does not exist, create token before issue");
126 |
127 | // Require auth from the bespiral community contract
128 | require_auth(_self);
129 |
130 | eosio::check(quantity.is_valid(), "invalid quantity");
131 | eosio::check(quantity.amount > 0, "must issue positive quantity");
132 | eosio::check(quantity.symbol == st.supply.symbol, "symbol mismatch");
133 | eosio::check(quantity.amount <= st.max_supply.amount - st.supply.amount, "quantity exceeds available supply");
134 |
135 | statstable.modify(st, _self, [&](auto &s)
136 | { s.supply += quantity; });
137 |
138 | add_balance(st.issuer, quantity, st);
139 |
140 | if (to != st.issuer)
141 | {
142 | require_recipient(st.issuer);
143 |
144 | SEND_INLINE_ACTION(*this,
145 | transfer,
146 | {_self, eosio::name{"active"}},
147 | {st.issuer, to, quantity, memo});
148 | }
149 | }
150 |
151 | void token::transfer(eosio::name from, eosio::name to, eosio::asset quantity, std::string memo)
152 | {
153 | eosio::check(from != to, "cannot transfer to self");
154 |
155 | // Require auth from self or from contract
156 | if (has_auth(from))
157 | {
158 | require_auth(from);
159 | }
160 | else
161 | {
162 | require_auth(_self);
163 | }
164 |
165 | eosio::check(is_account(to), "destination account doesn't exists");
166 |
167 | // Find symbol stats
168 | auto sym = quantity.symbol;
169 | stats statstable(_self, sym.code().raw());
170 | const auto &st = statstable.get(sym.code().raw(), "token with given symbol doesn't exists");
171 |
172 | // Validate quantity and memo
173 | eosio::check(quantity.is_valid(), "invalid quantity");
174 | eosio::check(quantity.amount > 0, "quantity must be positive");
175 | eosio::check(quantity.symbol == st.max_supply.symbol, "symbol precision mismatch");
176 | eosio::check(memo.size() <= 256, "memo has more than 256 bytes");
177 |
178 | // Check if from belongs to the community
179 | eosio::check(is_member(quantity.symbol, from), "from account doesn't belong to the community");
180 |
181 | // Check if to belongs to the community
182 | eosio::check(is_member(quantity.symbol, to), "to account doesn't belong to the community");
183 |
184 | // Transfer values
185 | sub_balance(from, quantity, st);
186 | add_balance(to, quantity, st);
187 | }
188 |
189 | /**
190 | Retire all tokens of a given currency
191 | @author Julien Lucca
192 | @version 1.0
193 |
194 | It can only be called and signed from the contract itself and it is used by the expiry feature.
195 | It removes all tokens out of the circulation
196 | */
197 | // void token::retire(eosio::name from, eosio::asset quantity, std::string memo)
198 | void token::retire(eosio::symbol currency, std::string user_type, std::string memo)
199 | {
200 | require_auth(get_self());
201 |
202 | eosio::check(user_type == "natural" || user_type == "juridical", "User type must be 'natural' or 'juridical'");
203 |
204 | auto sym = currency;
205 | eosio::check(sym.is_valid(), "invalid symbol name");
206 | eosio::check(memo.size() <= 256, "memo has more than 256 bytes");
207 |
208 | token::stats statstable(_self, sym.code().raw());
209 | auto existing = statstable.find(sym.code().raw());
210 | eosio::check(existing != statstable.end(), "token with symbol does not exist");
211 | const auto &st = *existing;
212 |
213 | eosio::check(st.type == "expiry", "Cambiatus only retire tokens of the 'expiry' type");
214 |
215 | members member_table(community_account, currency.raw());
216 | for (auto itr = member_table.begin(); itr != member_table.end(); itr++)
217 | {
218 | // Make sure to retire only of a single type
219 | if (itr->user_type == user_type)
220 | {
221 | token::accounts accounts(_self, itr->name.value);
222 | auto from_account = accounts.find(sym.code().raw());
223 |
224 | if (from_account != accounts.end())
225 | {
226 | // Decrease available supply
227 | statstable.modify(st, _self, [&](auto &s)
228 | { s.supply -= from_account->balance; });
229 |
230 | accounts.modify(from_account, _self, [&](auto &a)
231 | {
232 | a.balance = eosio::asset(0, currency);
233 | a.last_activity = now();
234 | });
235 | }
236 | }
237 | }
238 | }
239 |
240 | void token::initacc(eosio::symbol currency, eosio::name account, eosio::name inviter)
241 | {
242 | // Make sure token exists on the stats table
243 | stats statstable(_self, currency.code().raw());
244 | const auto &st = statstable.get(currency.code().raw(), "token with given symbol does not exist, create token before initacc");
245 |
246 | // Make sure account belongs to the given community
247 | // Check if from belongs to the community
248 | eosio::check(is_member(currency, account), "account doesn't belong to the community");
249 |
250 | // Create account table entry
251 | accounts accounts(_self, account.value);
252 | auto found_account = accounts.find(currency.code().raw());
253 |
254 | if (found_account == accounts.end())
255 | {
256 | accounts.emplace(_self, [&](auto &a)
257 | {
258 | a.balance = eosio::asset(0, st.supply.symbol);
259 | a.last_activity = now();
260 | });
261 | }
262 | }
263 |
264 | /**
265 | * Upsert Expiration options for a given currency.
266 | * @author Julien Lucca
267 | * @version 1.0
268 | *
269 | * Upsert expiration details on `expiryopts` table. Also fill amounts for every account on the member list and schedules its retirement
270 | *
271 | * 1) Upserts given expiration options (`expiration_period` in seconds and `renovation_amount` in eosio::asset) for the given `currency`
272 | * 2) Iterates over the members table. For every account on the community.
273 | * 2.1) Issue for the account the given `renovation_amount`
274 | * 3) Schedules a `retire` action for the given `currency` after the given `expiration_period`
275 | */
276 | void token::setexpiry(eosio::symbol currency, std::uint32_t natural_expiration_period, std::uint32_t juridical_expiration_period, eosio::asset renovation_amount)
277 | {
278 | // Validate data
279 | eosio::check(currency.is_valid(), "invalid symbol name");
280 |
281 | // Validate community
282 | token::stats statstable(_self, currency.code().raw());
283 | auto existing = statstable.find(currency.code().raw());
284 | eosio::check(existing != statstable.end(), "token with symbol does not exist");
285 | const auto &st = *existing;
286 |
287 | eosio::check(st.type != "mcc", "you can only configure tokens of the 'expiry' type");
288 | eosio::check(currency == renovation_amount.symbol, "symbol precision mismatch");
289 | eosio::check(currency == st.supply.symbol, "symbol precision mismatch");
290 |
291 | // Only the token issuer can configure that
292 | require_auth(st.issuer);
293 |
294 | // Save data
295 | token::expiry_opts opts(_self, _self.value);
296 | auto old_opts = opts.find(currency.code().raw());
297 |
298 | if (old_opts == opts.end())
299 | {
300 | opts.emplace(_self, [&](auto &a)
301 | {
302 | a.currency = currency;
303 | a.natural_expiration_period = natural_expiration_period;
304 | a.juridical_expiration_period = juridical_expiration_period;
305 | a.renovation_amount = renovation_amount;
306 | });
307 | }
308 | else
309 | {
310 | opts.modify(old_opts, _self, [&](auto &a)
311 | {
312 | a.currency = currency;
313 | a.natural_expiration_period = natural_expiration_period;
314 | a.juridical_expiration_period = juridical_expiration_period;
315 | a.renovation_amount = renovation_amount;
316 | });
317 | }
318 |
319 | // Setup expiration
320 | members members_table(community_account, currency.raw());
321 | for (auto itr = members_table.begin(); itr != members_table.end(); itr++)
322 | {
323 | // Only natural users receive the
324 | if (itr->user_type == "natural")
325 | {
326 |
327 | std::string issue_memo = "Token Renewal, you received " +
328 | renovation_amount.to_string() +
329 | " tokens, valid for " +
330 | std::to_string(natural_expiration_period) +
331 | " seconds.";
332 | eosio::action issue = eosio::action(eosio::permission_level{get_self(), eosio::name{"active"}}, // Permission
333 | get_self(), // Account
334 | eosio::name{"issue"}, // Action
335 | std::make_tuple(itr->name, renovation_amount, issue_memo));
336 | issue.send();
337 | }
338 | }
339 |
340 | auto natural_schedule_id = gen_uuid(currency.raw(), eosio::name{"natural"}.value);
341 | std::string natural_retire_memo = "Your tokens expired! Its been " + std::to_string(natural_expiration_period) + " seconds since the emission!";
342 | std::string natural_str = "natural";
343 |
344 | eosio::transaction retire_natural{};
345 | retire_natural.actions.emplace_back(eosio::permission_level{get_self(), eosio::name{"active"}}, // Permission
346 | get_self(), // Account
347 | eosio::name{"retire"}, // Action
348 | std::make_tuple(currency, natural_str, natural_retire_memo));
349 | retire_natural.delay_sec = natural_expiration_period;
350 | retire_natural.send(natural_schedule_id, get_self(), true);
351 |
352 | // Schedule retirement for juridical
353 | auto juridical_schedule_id = gen_uuid(currency.raw(), eosio::name{"juridical"}.value);
354 | std::string juridical_retire_memo = "Your tokens expired! Its been " + std::to_string(juridical_expiration_period) + " seconds since the emission!";
355 | std::string juridical_str = "juridical";
356 |
357 | eosio::transaction retire_juridical{};
358 | retire_juridical.actions.emplace_back(eosio::permission_level{get_self(), eosio::name{"active"}}, // Permission
359 | get_self(), // Account
360 | eosio::name{"retire"}, // Action
361 | std::make_tuple(currency, juridical_str, juridical_retire_memo));
362 | retire_juridical.delay_sec = juridical_expiration_period;
363 | retire_juridical.send(juridical_schedule_id, get_self(), true);
364 | }
365 |
366 | bool token::is_member(eosio::symbol community_id, eosio::name user)
367 | {
368 | members member_table(community_account, community_id.raw());
369 | auto itr = member_table.find(user.value);
370 |
371 | return itr != member_table.end();
372 | }
373 |
374 | void token::sub_balance(eosio::name owner, eosio::asset value, const token::currency_stats &st)
375 | {
376 | eosio::check(value.is_valid(), "Invalid value");
377 | eosio::check(value.amount > 0, "Can only transfer positive values");
378 |
379 | // Check for existing balance
380 | token::accounts accounts(_self, owner.value);
381 | auto from = accounts.find(value.symbol.code().raw());
382 |
383 | // Add balance table entry
384 | if (from == accounts.end())
385 | {
386 | eosio::check((value.amount * -1) >= st.min_balance.amount, "overdrawn community limit");
387 |
388 | accounts.emplace(_self, [&](auto &a)
389 | {
390 | a.balance = value;
391 | a.balance.amount *= -1;
392 | a.last_activity = now();
393 | });
394 | }
395 | else
396 | {
397 | auto new_balance = from->balance.amount - value.amount;
398 | eosio::check(new_balance >= st.min_balance.amount, "overdrawn community limit");
399 | accounts.modify(from, _self, [&](auto &a)
400 | {
401 | a.balance.amount -= value.amount;
402 | a.last_activity = now();
403 | });
404 | }
405 | return;
406 | }
407 |
408 | void token::add_balance(eosio::name recipient, eosio::asset value, const token::currency_stats &st)
409 | {
410 | eosio::check(value.is_valid(), "Invalid value");
411 | eosio::check(value.amount > 0, "Can only transfer positive values");
412 |
413 | accounts accounts(_self, recipient.value);
414 | auto to = accounts.find(value.symbol.code().raw());
415 |
416 | if (to == accounts.end())
417 | {
418 | accounts.emplace(_self, [&](auto &a)
419 | {
420 | a.balance = value;
421 | a.last_activity = now();
422 | });
423 | }
424 | else
425 | {
426 | accounts.modify(to, _self, [&](auto &a)
427 | {
428 | a.balance += value;
429 | a.last_activity = now();
430 | });
431 | }
432 | }
433 |
434 | EOSIO_DISPATCH(token,
435 | (create)(update)(issue)(transfer)(retire)(setexpiry)(initacc));
436 |
--------------------------------------------------------------------------------
/token/token.hpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | #define TOSTR_(T) #T
6 | #define TOSTR(T) TOSTR_(T)
7 |
8 | class [[eosio::contract("token")]] token : public eosio::contract
9 | {
10 | public:
11 | using contract::contract;
12 |
13 | TABLE account
14 | {
15 | eosio::asset balance;
16 | uint32_t last_activity;
17 |
18 | uint64_t primary_key() const { return balance.symbol.code().raw(); }
19 |
20 | EOSLIB_SERIALIZE(account, (balance)(last_activity));
21 | };
22 |
23 | TABLE currency_stats
24 | {
25 | eosio::asset supply;
26 | eosio::asset max_supply;
27 | eosio::asset min_balance;
28 | eosio::name issuer;
29 | std::string type;
30 |
31 | uint64_t primary_key() const { return supply.symbol.code().raw(); }
32 |
33 | EOSLIB_SERIALIZE(currency_stats, (supply)(max_supply)(min_balance)(issuer)(type));
34 | };
35 |
36 | TABLE expiry_options
37 | {
38 | eosio::symbol currency;
39 | std::uint32_t natural_expiration_period;
40 | std::uint32_t juridical_expiration_period;
41 | eosio::asset renovation_amount;
42 |
43 | uint64_t primary_key() const { return currency.code().raw(); }
44 |
45 | EOSLIB_SERIALIZE(expiry_options, (currency)(natural_expiration_period)(juridical_expiration_period)(renovation_amount));
46 | };
47 |
48 | /// @abi action
49 | /// Create a new BeSpiral Token
50 | ACTION create(eosio::name issuer, eosio::asset max_supply, eosio::asset min_balance, std::string type);
51 |
52 | /// @abi action
53 | /// Update a BeSpiral Token properties
54 | ACTION update(eosio::asset max_supply, eosio::asset min_balance);
55 |
56 | /// @abi action
57 | /// Transfer BeSpiral compatible tokens between users.
58 | ACTION transfer(eosio::name from, eosio::name to, eosio::asset quantity, std::string memo);
59 |
60 | /// @abi action
61 | /// Issue / Mint new BeSpiral compatible tokens
62 | ACTION issue(eosio::name to, eosio::asset quantity, std::string memo);
63 |
64 | /// @abi action
65 | /// Retire tokens from a given account
66 | ACTION retire(eosio::symbol currency, std::string user_type, std::string memo);
67 |
68 | /// @abi action
69 | /// Set expiry options to a given token
70 | ACTION setexpiry(eosio::symbol currency, std::uint32_t natural_expiration_period, std::uint32_t juridical_expiration_period, eosio::asset renovation_amount);
71 |
72 | /// @abi action
73 | /// Init empty balance for a given account
74 | ACTION initacc(eosio::symbol currency, eosio::name account, eosio::name inviter);
75 |
76 | typedef eosio::multi_index accounts;
77 | typedef eosio::multi_index stats;
78 | typedef eosio::multi_index expiry_opts;
79 |
80 | bool is_member(eosio::symbol community_id, eosio::name user);
81 |
82 | void sub_balance(eosio::name owner, eosio::asset value, const token::currency_stats &st);
83 | void add_balance(eosio::name owner, eosio::asset value, const token::currency_stats &st);
84 | void renovate_expiration(eosio::name account, const token::currency_stats &st);
85 | };
86 |
87 | const auto community_account = eosio::name{TOSTR(__COMMUNITY_ACCOUNT__)};
88 |
89 | struct community
90 | {
91 | eosio::symbol symbol;
92 |
93 | eosio::name creator;
94 | std::string logo;
95 | std::string title;
96 | std::string description;
97 |
98 | eosio::asset inviter_reward;
99 | eosio::asset invited_reward;
100 |
101 | std::uint8_t has_objectives;
102 | std::uint8_t has_shop;
103 |
104 | std::uint64_t primary_key() const { return symbol.raw(); }
105 | };
106 | typedef eosio::multi_index bespiral_communities;
107 |
108 | struct network
109 | {
110 | std::uint64_t id;
111 |
112 | eosio::symbol community;
113 | eosio::name invited_user;
114 | eosio::name invited_by;
115 | std::string user_type;
116 |
117 | std::uint64_t primary_key() const { return id; }
118 | std::uint64_t users_by_cmm() const { return community.raw(); }
119 | };
120 |
121 | struct member
122 | {
123 | eosio::name name;
124 | eosio::name inviter;
125 | std::string user_type;
126 | std::vector roles;
127 |
128 | std::uint64_t primary_key() const { return name.value; }
129 | };
130 |
131 | typedef eosio::multi_index > >
135 | bespiral_networks;
136 |
137 | typedef eosio::multi_index members;
138 |
--------------------------------------------------------------------------------
/token/token.wasm:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cambiatus/contracts/32190b274bd996df3c1f03c834230aae43309086/token/token.wasm
--------------------------------------------------------------------------------
/utils/utils.cpp:
--------------------------------------------------------------------------------
1 | uint128_t combine_ids(uint64_t const &x, uint64_t const &y)
2 | {
3 | uint128_t times = 1;
4 | while (times <= y)
5 | times *= 10;
6 |
7 | return (x * times) + y;
8 | }
9 |
10 | uint64_t gen_uuid(const uint64_t &x, const uint64_t &y)
11 | {
12 | uint128_t res = combine_ids(x, y);
13 | return std::hash{}(res);
14 | }
15 |
16 | uint64_t hash_to_uint64(eosio::checksum256 hash)
17 | {
18 | auto hashBytes = hash.extract_as_byte_array().data();
19 | uint128_t num = combine_ids(
20 | combine_ids(hashBytes[0], hashBytes[1]),
21 | combine_ids(hashBytes[2], hashBytes[3]));
22 |
23 | return std::hash{}(num);
24 | }
25 |
26 | std::string uint64_to_str(const uint64_t &value)
27 | {
28 | const char *digits = "0123456789";
29 |
30 | std::string result;
31 | result.reserve(20);
32 | uint64_t helper = value;
33 |
34 | do
35 | {
36 | result += digits[helper % 10];
37 | helper /= 10;
38 | } while (helper);
39 |
40 | std::reverse(result.begin(), result.end());
41 |
42 | return result;
43 | }
44 |
45 | std::vector split(std::string str, std::string delim)
46 | {
47 | std::vector result;
48 | while (str.size())
49 | {
50 | int index = str.find(delim);
51 | if (index != std::string::npos)
52 | {
53 | result.push_back(str.substr(0, index));
54 | str = str.substr(index + delim.size());
55 | if (str.size() == 0)
56 | result.push_back(str);
57 | }
58 | else
59 | {
60 | result.push_back(str);
61 | str = "";
62 | }
63 | }
64 | return result;
65 | }
66 |
67 | uint32_t now()
68 | {
69 | return eosio::current_time_point().sec_since_epoch();
70 | }
71 |
--------------------------------------------------------------------------------