├── .gitignore
├── Dockerfile
├── LICENSE
├── config
└── system_preferences.json
├── docker-compose.yaml
├── documentation
├── architecture.md
├── blockchain-digest.md
└── open-api
│ └── qbc.yaml
├── lib
├── __init__.py
├── chain.py
├── encode.py
├── hash.py
├── network.py
├── proof.py
├── qbc_utils.py
├── quant.py
└── transactions.py
├── misc
└── logo.png
├── modules
├── __init__.py
├── chain
│ ├── __init__.py
│ └── controllers.py
├── mining
│ ├── __init__.py
│ └── controllers.py
├── network
│ ├── __init__.py
│ └── controllers.py
└── transactions
│ ├── __init__.py
│ └── controllers.py
├── readme.md
├── requirements.txt
├── run.py
├── storage
├── .gitkeep
├── nodes.json
└── transactions.json
└── test
├── __init__.py
└── test_storage
├── node1
└── nodes.json
├── node2
└── nodes.json
└── node3
└── nodes.json
/.gitignore:
--------------------------------------------------------------------------------
1 | bcenv/
2 | */**/*.pyc
3 | .vscode/
4 | */**/*.bc
--------------------------------------------------------------------------------
/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM python:2
2 |
3 | WORKDIR /usr/src/app
4 |
5 | COPY requirements.txt ./
6 | RUN pip install --no-cache-dir -r requirements.txt
7 |
8 | COPY . .
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/config/system_preferences.json:
--------------------------------------------------------------------------------
1 | {
2 | "genesis_nodes": ["http://localhost:5000"]
3 | }
--------------------------------------------------------------------------------
/docker-compose.yaml:
--------------------------------------------------------------------------------
1 | version: '2.1'
2 | services:
3 | node1:
4 | build: .
5 | ports:
6 | - "5000:5000"
7 | command: [ "python", "./run.py" ]
8 | volumes:
9 | - .:/usr/src/app
10 | - ./test/test_storage/node1:/usr/src/app/storage
11 | - ./test/test_storage/logs1:/tmp/logs
12 | networks:
13 | app_net:
14 | ipv4_address: 172.16.238.10
15 | healthcheck:
16 | test: ["CMD", "curl", "-f", "http://172.16.238.10:5000/stats"]
17 | interval: 30s
18 | timeout: 10s
19 | retries: 5
20 | node2:
21 | build: .
22 | ports:
23 | - "3000:3000"
24 | command: [ "python", "./run.py", "3000" ]
25 | volumes:
26 | - .:/usr/src/app
27 | - ./test/test_storage/node2:/usr/src/app/storage
28 | - ./test/test_storage/logs2:/tmp/logs
29 | depends_on:
30 | node1:
31 | condition: service_healthy
32 | networks:
33 | app_net:
34 | ipv4_address: 172.16.238.11
35 | node3:
36 | build: .
37 | ports:
38 | - "4000:4000"
39 | command: [ "python", "./run.py", "4000" ]
40 | volumes:
41 | - .:/usr/src/app
42 | - ./test/test_storage/node3:/usr/src/app/storage
43 | - ./test/test_storage/logs3:/tmp/logs
44 | depends_on:
45 | node1:
46 | condition: service_healthy
47 | networks:
48 | app_net:
49 | ipv4_address: 172.16.238.12
50 |
51 | networks:
52 | app_net:
53 | driver: bridge
54 | ipam:
55 | driver: default
56 | config:
57 | - subnet: 172.16.238.0/24
--------------------------------------------------------------------------------
/documentation/architecture.md:
--------------------------------------------------------------------------------
1 | # Architecture diagrams WIP
--------------------------------------------------------------------------------
/documentation/blockchain-digest.md:
--------------------------------------------------------------------------------
1 | # Blockchain digest - Last updated Feb 2018
2 |
3 | Altho I am building this list to promote thinking about general purpose block chain development, you can not avoid taking a look of only established use of blockchain - database behind crypto currencies and tokens. So, this digest will always contain overview of cryptocurrencies and related events and tech - it is important to got through these for understanding and learning purposes.
4 |
5 | ## Basics
6 |
7 | * [Goldman Sachs blockchain basics](http://www.goldmansachs.com/our-thinking/pages/blockchain/)
8 | * [Original paper by Satoshi Nakamoto (true identity still unknown):](https://bitcoin.org/bitcoin.pdf)
9 | * [Chris Dixon’s (VC) great overview, Ethereum and ERC20’s origin](https://medium.com/@cdixon/crypto-tokens-a-breakthrough-in-open-network-design-e600975be2ef)
10 | * [2014 blog by Naval Ravinkant, which predicted ICOs and related stuff:](https://startupboy.com/2014/03/09/the-bitcoin-model-for-crowdfunding/)
11 | * [Follow-up to the above, which is probably the best summary of what are the potentials, with a bunch of high-quality links:](https://medium.com/@balajis/thoughts-on-tokens-436109aabcbe)
12 | * [Place which lists upcoming ICOs:](https://www.icoalert.com/)
13 | * [Bitcoin for laypeople](https://gist.github.com/mafintosh/bd9e6d350ebf02441c9707c5f799d05b#file-bitcoin-for-laypeople-md)
14 |
15 | ## Details
16 |
17 | * [Byzantine what? Here is little more detail on how to fight challenges and embrace adventages decentralization brings:](https://medium.com/@chrshmmmr/consensus-in-blockchain-systems-in-short-691fc7d1fefe)
18 | * [Consensus in blockchain system in short](https://medium.com/@chrshmmmr/consensus-in-blockchain-systems-in-short-691fc7d1fefe)
19 | * [Other one:](https://www.coindesk.com/short-guide-blockchain-consensus-protocols/)
20 | * [Ofc, for academically inclined:](https://scholar.google.com/scholar?q=practical+byzantine+fault+tolerance+algorithm&hl=en&as_sdt=0&as_vis=1&oi=scholart&sa=X&ved=0ahUKEwjS94qlxsPVAhWEshQKHWX6C0UQgQMIJDAA)
21 | * [Especially:](http://pmg.csail.mit.edu/papers/osdi99.pdf)
22 | * [Quest for scalable](http://vukolic.com/iNetSec_2015.pdf) not that good but interesting
23 |
24 | ### More on:
25 | * [Zero knowledge proof](https://en.wikipedia.org/wiki/Zero-knowledge_proof)
26 | * [Proof of work](https://en.bitcoin.it/wiki/Proof_of_work)
27 | * [Smart contracts](https://blockgeeks.com/guides/smart-contracts/)
28 |
29 | ## The systems - How do we want to use blockchain.
30 |
31 | ### Government and insurance
32 |
33 | * [Insurance - reinsurance 1](https://www.allianz.com/en/press/news/commitment/sponsorship/161018-insurers-and-reinsurers-launch-blockchain-initiative-b3i/)
34 | * [Insurance - reinsurance 2](https://www.allianz.com/en/press/news/commitment/sponsorship/170206_Blockchain-gains--international-scope/)
35 | * [Insurance - reinsurance 3](http://www.agcs.allianz.com/about-us/news/blockchain-technology-successfully-piloted-by-allianz-risk-transfer-and-nephila-for-catastrophe-swap-/)
36 | * [China Taxes taxes taxes](https://www.zerohedge.com/news/2017-08-06/will-china-use-blockchain-collect-taxes)
37 | * [Dubai blockchain government 1](https://www.forbes.com/sites/suparnadutt/2017/12/18/dubai-sets-sights-on-becoming-the-worlds-first-blockchain-powered-government/#46f77dcc454b)
38 | * [Dubai blockchain government 2](https://www.coindesk.com/dubai-land-department-launches-blockchain-real-estate-initiative/)
39 |
40 |
41 | ### Food
42 |
43 | * [The Conversation - How blockchain could revolutionarize food industry](http://theconversation.com/how-blockchain-technology-could-transform-the-food-industry-89348)
44 |
45 | * [Forbes - The blockchain of food](https://www.forbes.com/forbes/welcome/?toURL=https://www.forbes.com/sites/themixingbowl/2017/10/23/the-blockchain-of-food/)
46 |
47 | * [IBM - Blockchain in food safety](https://www.ibm.com/blogs/blockchain/category/blockchain-in-food-safety/)
48 |
49 | * [Bloomberg - blockchain seen revolutionarizing food chain cutting cost](https://www.bloomberg.com/news/articles/2017-12-07/blockchain-seen-revolutionizing-food-chain-cutting-costs)
50 |
51 |
52 | ### Misc applications, solutions etc
53 |
54 | #### Decentralized apps - not only blockchain (noblockchain?)
55 |
56 | * [IPFS (inter planetary fs)](https://ipfs.io/)
57 | * [Email](http://labs.devana.rs/project/lemon-email/)
58 | * [Decentralized org structures](https://aragon.one/)
59 | * [Decentralized forecasting](http://www.augur.net/)
60 | * [Data science network](https://numer.ai/)
61 | * [Social engagement whatever](https://akasha.world/)
62 | * [Media](https://steem.io/#intro-ex)
63 | * [Professional network](https://indorse.io/)
64 | * [Golem](https://golem.network/)
65 |
66 | #### Green
67 |
68 | * [http://www.genercoin.org/](http://www.genercoin.org/)
69 | * [http://renucoin.com/](http://renucoin.com/)
70 | * [https://kwhcoin.com/](https://kwhcoin.com/)
71 |
72 | ### Other
73 |
74 | * [Basic attention token](https://basicattentiontoken.org/)
75 |
76 | ### Enterprise
77 |
78 | * [https://www.hyperledger.org/](https://www.hyperledger.org/)
79 | * [https://www.ibm.com/blockchain/](https://www.ibm.com/blockchain/)
80 | * [https://www.blockchain.com/enterprise/index.html](https://www.blockchain.com/enterprise/index.html)
81 |
82 | ### Moneyz
83 | * [ZCash](https://z.cash/)
84 | * [Litecoin](https://litecoin.org/)
85 | * [Monero](https://getmonero.org/)
86 | * [Forbes on bitcoin, ripple, litecoin in Jan 2018](https://www.forbes.com/forbes/welcome/?toURL=https://www.forbes.com/sites/panosmourdoukoutas/2018/01/31/bitcoin-ripple-and-litecoin-sell-off-whats-different-this-time-around)
87 |
88 |
89 |
90 |
91 | ## The big heists
92 | #### YEAH, heists
93 | * [DAO 1](https://www.cryptocompare.com/coins/guides/the-dao-the-hack-the-soft-fork-and-the-hard-fork/)
94 | * [DAO 2](https://www.coindesk.com/understanding-dao-hack-journalists/)
95 | * [31M of Ether](https://medium.freecodecamp.org/a-hacker-stole-31m-of-ether-how-it-happened-and-what-it-means-for-ethereum-9e5dc29e33ce)
96 | * [Coincheck](http://money.cnn.com/2018/01/29/technology/coincheck-cryptocurrency-exchange-hack-japan/index.html)
97 | * [Ethereum parity hard fork](http://fortune.com/2017/11/08/ethereum-parity-hack-hard-fork/)
98 | * [The ether thief](https://www.bloomberg.com/features/2017-the-ether-thief/)
99 |
100 |
101 | ## Further reads
102 |
103 | * [Crypto currently](https://medium.com/crypto-currently)
104 | * [Ethereum tokens](https://www.ethereum.org/token)
105 | * [Ethereum natural spec format](https://github.com/ethereum/wiki/wiki/Ethereum-Natural-Specification-Format)
106 | * [Ethereum DAO](https://www.ethereum.org/dao)
107 | * [Indorse - decentralized professional network]( https://blog.indorse.io/why-we-are-building-a-decentralized-professional-network-indorse-8905d831f55a)
108 | * [quntifying decentralization](https://news.earn.com/quantifying-decentralization-e39db233c28e)
109 | * [Blockchain based digital advertizing - BAT token ( look at BRAVE browser as well](https://basicattentiontoken.org/BasicAttentionTokenWhitePaper-4.pdf)
110 |
111 |
--------------------------------------------------------------------------------
/documentation/open-api/qbc.yaml:
--------------------------------------------------------------------------------
1 | swagger: "2.0"
2 | info:
3 | description: "Api definitions for Quantum blockchain"
4 | version: "1.0.0"
5 | title: "QBC Swagger"
6 | termsOfService: "https://www.gnu.org/licenses/gpl-3.0.en.html"
7 | contact:
8 | email: "rastko.vukasinovic@gmail.com"
9 | license:
10 | name: "GPL 3.0"
11 | url: "https://www.gnu.org/licenses/gpl-3.0.en.html"
12 | host: "localhost:5000"
13 | basePath: "/v1"
14 | tags:
15 | - name: "quantum blockchain"
16 | description: "general purpose blockchain"
17 | externalDocs:
18 | description: "Find out more"
19 | url: "https://github.com/metaphorical/quantum-blockchain"
20 | schemes:
21 | - "https"
22 | - "http"
23 | paths:
24 | /inject:
25 | post:
26 | tags:
27 | - "inject"
28 | summary: "Add transaction to transaction pool"
29 | description: ""
30 | consumes:
31 | - "application/json"
32 | produces:
33 | - "application/json"
34 | parameters:
35 | - in: "body"
36 | name: "body"
37 | description: ""
38 | required: true
39 | schema:
40 | $ref: "#/definitions/Inject"
41 | responses:
42 | 200:
43 | description: "Successfully added to transaction pool"
44 | 405:
45 | description: "Invalid input"
46 |
47 | # securityDefinitions:
48 | # petstore_auth:
49 | # type: "oauth2"
50 | # authorizationUrl: ".../oauth/dialog"
51 | # flow: "implicit"
52 | # scopes:
53 | # write:pets: "modify pets in your account"
54 | # read:pets: "read your pets"
55 | # api_key:
56 | # type: "apiKey"
57 | # name: "api_key"
58 | # in: "header"
59 | definitions:
60 | Inject:
61 | type: "object"
62 | properties:
63 | id:
64 | type: "integer"
65 | format: "int64"
66 | externalDocs:
67 | description: "Find out more about Swagger"
68 | url: "http://swagger.io"
--------------------------------------------------------------------------------
/lib/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/metaphorical/quantum-blockchain/7b0c605fabd01c6cfad727317df5bc067125b1d2/lib/__init__.py
--------------------------------------------------------------------------------
/lib/chain.py:
--------------------------------------------------------------------------------
1 | import datetime as date
2 | import json, pickle, os
3 | import hashlib as hasher
4 |
5 | from lib.quant import Quant
6 | from lib.network import Network
7 |
8 | # TODO: All the saves and loads should be improved by adding in memory storage for performance and encryption for security
9 | QBCN = Network()
10 |
11 | class Chain:
12 | """
13 | QBC structure implementation
14 | """
15 | def __init__(self):
16 | # If there is locally storred chain it should be read and used on init
17 | # (instead of basic initiation of genesis block)
18 | if(os.path.exists(os.path.join(os.getcwd(),'storage', 'q.bc'))):
19 | self.qbc = Chain.__read_chain_from_disc()
20 | else:
21 | self.qbc = [Chain.__bang()]
22 | self.save()
23 | self.current_quant = self.qbc[0]
24 |
25 | @classmethod
26 | def __bang(self):
27 | """Bang starts new blockchain creating what is known as 'genesis block'"""
28 | return Quant(0, date.datetime.now(), "Small Bang", "0", "1")
29 | @classmethod
30 | def __create_next_quant(self, last_quant, data):
31 | """
32 | Creates next block in Quantum Blockchain, known as Quant
33 | """
34 | this_index = last_quant.index + 1
35 | this_timestamp = date.datetime.now()
36 | this_data = data
37 | last_hash = last_quant.hash
38 | last_proof = last_quant.proof
39 | return Quant(this_index, this_timestamp, this_data, last_hash, last_proof)
40 | @classmethod
41 | def __read_chain_from_disc(self):
42 | with open(os.path.join(os.getcwd(),'storage', 'q.bc'), 'rb') as qbc_file:
43 | return pickle.load(qbc_file)
44 |
45 | def get_chain_stats(self):
46 | sha = hasher.sha256()
47 | sha.update(self.get_chain("json"))
48 | return json.dumps({
49 | "length": len(self.get_chain()),
50 | "hash": sha.hexdigest()
51 | })
52 |
53 | def create_quant(self, data):
54 | """
55 | Public method to add new quatn to QBC
56 | """
57 | new_quant = Chain.__create_next_quant(self.current_quant, data)
58 | self.qbc.append(new_quant)
59 | self.current_quant = self.qbc[len(self.qbc) - 1]
60 | Chain.save(self)
61 | return new_quant
62 |
63 | def add_quant(self, quant):
64 | """
65 | Add Quant to QBC
66 | """
67 | self.qbc.append(quant)
68 | self.current_quant = self.qbc[len(self.qbc) - 1]
69 | Chain.save(self)
70 |
71 | def get_current_quant(self):
72 | return self.current_quant
73 |
74 | def get_chain(self, format="default"):
75 | return {
76 | "json": json.dumps([{
77 | "index": str(quant.index),
78 | "timestamp": str(quant.timestamp),
79 | "data": str(quant.data),
80 | "hash": quant.hash,
81 | "proof": str(quant.proof)
82 | } for quant in self.qbc]),
83 | "serialized": pickle.dumps(self.qbc)
84 | }.get(format, self.qbc)
85 |
86 | def save(self):
87 | """
88 | Storing QBC on disc serialized using pickle
89 | TODO: introduce encryption
90 | """
91 | with open(os.path.join(os.getcwd(),'storage', 'q.bc'), 'wb') as fp:
92 | pickle.dump(self.qbc, fp)
93 | def load(self):
94 | self.qbc = self.__read_chain_from_disc()
95 |
96 | def get_remote_node_chain(self, host):
97 | """
98 | Downloads chain in bickle format and sets it into qbc
99 |
100 | TODO: In order to develop and test I need to first finish dockerizing
101 | and preset for 2 or 3 node testing setup to emulate different lengths
102 | and chain diverging events.
103 | """
104 | remote_chain = QBCN.read_chain(host)
105 | self.qbc = pickle.loads(remote_chain)
106 | self.save()
--------------------------------------------------------------------------------
/lib/encode.py:
--------------------------------------------------------------------------------
1 | import gnupg
2 |
3 | gpg = gnupg.GPG()
--------------------------------------------------------------------------------
/lib/hash.py:
--------------------------------------------------------------------------------
1 | import hashlib as hasher
2 |
3 | def hash_block(quant):
4 | """
5 | Method to generate fingerprint for the next block.
6 | It is ideal for fingerprint to be the hash of some combination of all the blocks comonents
7 | """
8 | sha = hasher.sha256()
9 | sha.update(str(quant.index) +
10 | str(quant.timestamp) +
11 | str(quant.data) +
12 | str(quant.previous_hash))
13 | return sha.hexdigest()
--------------------------------------------------------------------------------
/lib/network.py:
--------------------------------------------------------------------------------
1 | import os, json, requests, pickle
2 |
3 | from lib.qbc_utils import QbcUtils
4 |
5 | QBCU = QbcUtils()
6 |
7 | # TODO: implement timeout for request and fallback... Probably hardcoded genesis node should be fallback and some (maybe serverless?) discovery mechanism should be created
8 | # TODO: All the saves and loads should be improved by adding in memory storage for performance and encryption for security
9 |
10 | class Network:
11 | def load_nodes(self):
12 | with open(os.path.join(os.getcwd(),'storage', 'nodes.json'), 'rb') as node_file:
13 | nodes_json = json.load(node_file)
14 | print("NODES {}".format(nodes_json))
15 | return nodes_json
16 |
17 | def save_nodes(self, nodes):
18 | # import pdb; pdb.set_trace()
19 | with open(os.path.join(os.getcwd(),'storage', 'nodes.json'), 'wb') as fp:
20 | json.dump(nodes, fp)
21 |
22 | def get_this_node(self):
23 | node_ip = QBCU.get_current_ip()
24 | return QBCU.get_hostname(node_ip, QBCU.get_port())
25 |
26 | def register_and_discover(self, node_addr, this_node):
27 | discover_payload = {'host': this_node}
28 | try:
29 | register_request = requests.post("{}/discover".format(node_addr), json=discover_payload)
30 | except ValueError:
31 | print("register and discover ERROR - {}".format(ValueError))
32 | register_request = False
33 | print("register and discover - {}".format(register_request.text))
34 | return register_request
35 |
36 | def read_chain(self, node_addr):
37 | """
38 | TODO: this might probably grow to be first secure transfer point, so when working on
39 | node to node auth, include it here
40 | """
41 | chain_request = requests.get("{}/chain".format(node_addr))
42 | return chain_request.text
43 |
44 | def broadcast_quant(self, nodes, quant):
45 | """
46 | Broadcast any quant to all nodes in provided list
47 | TODO: secure this process
48 | """
49 | this_node = QBCU.parse_localhost(self.get_this_node())
50 | for qbc_node in nodes:
51 | node_addr = QBCU.parse_localhost(qbc_node)
52 | if node_addr != this_node:
53 | print node_addr
54 | quant_payload = {'quant': pickle.dumps(quant)}
55 | request = requests.post("{}/add-block".format(node_addr), json=quant_payload)
56 | print("Broadcasted new block to {} - {}".format(node_addr, request.text))
57 |
58 | def discover_network(self, live_nodes=[]):
59 | """
60 | Network discovery is done in two stages:
61 | 1 - ping genesys node (aka tracker) to register and get it's full list of nodes
62 | 2 - register on all of the nodes
63 | TODO: implement cross check and re register of nodes.
64 | """
65 | registered_nodes = self.load_nodes()
66 | new_nodes = []
67 | max_length = 0
68 | max_length_node = ""
69 | if not QBCU.is_genesis_node():
70 | this_node = self.get_this_node()
71 | print("THIS NODE {}".format(this_node))
72 | for qbc_node in registered_nodes:
73 | # When node boots up again it will have self on the node list
74 | # We need to make sure that it does not try to call self in discovery process
75 | if qbc_node != self.get_this_node():
76 | node_addr = QBCU.parse_localhost(qbc_node)
77 | # Reading chain stats and checking chain length, if chain length is higher we set it in max_length var
78 | discover_node = self.register_and_discover(node_addr, this_node)
79 |
80 | # Before implementing retries, we assume that there is no node
81 | if discover_node:
82 | node_chain_length = json.loads(discover_node.text)["stats"]["length"]
83 | else:
84 | node_chain_length = 0
85 |
86 | if(node_chain_length > max_length):
87 | max_length = node_chain_length
88 | max_length_node = node_addr
89 | # Getting live nodes and figuring out new ones (no nodes if node not live)
90 | if discover_node:
91 | hosts_from_node = json.loads(discover_node.text)["live_nodes"]
92 | else:
93 | hosts_from_node = []
94 |
95 | new_nodes += [x for x in hosts_from_node if (x != this_node and x not in registered_nodes)]
96 |
97 | print("new nodes - {}".format(json.dumps(new_nodes)))
98 |
99 | registered_nodes = registered_nodes + new_nodes
100 | self.save_nodes(registered_nodes)
101 | if(len(new_nodes) > 0):
102 | print("registered nodes - {}".format(json.dumps(registered_nodes)))
103 | for new_node in new_nodes:
104 | new_node_addr = QBCU.parse_localhost(new_node)
105 | self.register_and_discover(new_node_addr, this_node)
106 | else:
107 | print("I guess this is second node on the network...")
108 | return {
109 | "registered_nodes": registered_nodes,
110 | "longest_chain_length": max_length,
111 | "longest_chain_node": max_length_node
112 | }
--------------------------------------------------------------------------------
/lib/proof.py:
--------------------------------------------------------------------------------
1 | def proof_of_work(last_proof):
2 | """
3 | Simple proof of work implementation:
4 | last proof of work gets incremented until next number divisable by last proof and 19 appears
5 | """
6 | theproof = int(last_proof) + 1
7 | print theproof
8 | while not (theproof % 19 == 0 and theproof % int(last_proof) == 0):
9 | theproof += 1
10 | return theproof
11 |
12 | def validate_pow(last_proof, theproof):
13 | """
14 | Confirm that provided proof is actually the next block
15 | """
16 | return (theproof % 19 == 0 and theproof % int(last_proof) == 0)
17 |
18 | def delegated_block_creation(last_proof):
19 | """
20 | This is no proof system since it just returns order number of block.
21 | Private chain implementation is considered to be in place.
22 | """
23 | return last_proof + 1
24 |
25 | def proof(last_param):
26 | """
27 | Applies selected proof algorythm
28 | Currently just uses Proof of work.
29 | TODO: Implement
30 | * DBC - delegated block creation
31 | * POS - proof of stake
32 | * DPOS - delegated proof of stake
33 | * POA - proof of authority
34 | TODO: Implement configurable proof model.
35 | """
36 | return proof_of_work(last_param)
37 |
38 | def validate(last_proof, theproof):
39 | """
40 | Implement validation switching based on which consensus system is used
41 | """
42 | return validate_pow(last_proof, theproof)
--------------------------------------------------------------------------------
/lib/qbc_utils.py:
--------------------------------------------------------------------------------
1 | import json, socket, sys
2 |
3 | system_config = json.load(open('./config/system_preferences.json'))
4 | class QbcUtils:
5 | def get_current_ip(self):
6 | return socket.gethostbyname(socket.gethostname())
7 |
8 | def get_port(self):
9 | return int(sys.argv[1]) if (len(sys.argv) >= 2) else 5000
10 |
11 | def parse_localhost(self, new_node):
12 | """
13 | for testing purposes, for node to communicate inside same machine,
14 | we need to parse all the IP addresses and replace current machine ones with localhost
15 | """
16 | current_node_ip = self.get_current_ip()
17 | if current_node_ip not in new_node:
18 | node_addr = new_node
19 | else:
20 | node_addr = new_node.replace(current_node_ip, "localhost")
21 | return node_addr
22 |
23 | def get_hostname(self, ip, port):
24 | # TODO: handle different protocols
25 | return "http://{}:{}".format(ip, port)
26 |
27 | def is_genesis_node(self):
28 | """
29 | Shows if current node belongs to list of initial nodes
30 | (it usually mean that those will stay longest time - i.e. forever)
31 | """
32 | genesis_nodes = system_config["genesis_nodes"]
33 | this_node = self.get_hostname(self.get_current_ip(), self.get_port())
34 | return this_node in genesis_nodes or self.parse_localhost(this_node) in genesis_nodes
--------------------------------------------------------------------------------
/lib/quant.py:
--------------------------------------------------------------------------------
1 | from lib.hash import hash_block
2 | from lib.proof import proof
3 |
4 | class Quant:
5 | """
6 | Smallest piece of QBC is quant of data - a block in the blockchain
7 | """
8 | def __init__(self, index, timestamp, data, previous_hash, previous_proof):
9 | self.index = index
10 | self.timestamp = timestamp
11 | self.data = data
12 | self.previous_hash = previous_hash
13 | self.proof = proof(previous_proof)
14 | self.hash = hash_block(self)
15 |
16 |
--------------------------------------------------------------------------------
/lib/transactions.py:
--------------------------------------------------------------------------------
1 | import os, requests, json
2 |
3 | from lib.qbc_utils import QbcUtils
4 |
5 | QBCU = QbcUtils()
6 |
7 | # TODO: All the saves and loads should be improved by adding in memory storage for performance and encryption for security
8 |
9 | class Transactions:
10 | def broadcast_transaction(self, nodes, transaction, port):
11 | node_ip = QBCU.get_current_ip()
12 | port = QBCU.get_port()
13 | this_node = QBCU.parse_localhost(QBCU.get_hostname(node_ip, port))
14 | for node in nodes:
15 | node = QBCU.parse_localhost(node)
16 | if node != this_node:
17 | r = requests.put("{}/inject".format(node), json={"data":transaction})
18 | print(r.text)
19 |
20 | def load_transactions(self):
21 | with open(os.path.join(os.getcwd(),'storage', 'transactions.json'), 'rb') as transactions_file:
22 | return json.load(transactions_file)
23 |
24 | def save_transactions(self, transactions):
25 | with open(os.path.join(os.getcwd(),'storage', 'transactions.json'), 'wb') as fp:
26 | json.dump(transactions, fp)
--------------------------------------------------------------------------------
/misc/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/metaphorical/quantum-blockchain/7b0c605fabd01c6cfad727317df5bc067125b1d2/misc/logo.png
--------------------------------------------------------------------------------
/modules/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/metaphorical/quantum-blockchain/7b0c605fabd01c6cfad727317df5bc067125b1d2/modules/__init__.py
--------------------------------------------------------------------------------
/modules/chain/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/metaphorical/quantum-blockchain/7b0c605fabd01c6cfad727317df5bc067125b1d2/modules/chain/__init__.py
--------------------------------------------------------------------------------
/modules/chain/controllers.py:
--------------------------------------------------------------------------------
1 | import pickle
2 |
3 | from flask import Blueprint, request
4 |
5 | from lib.chain import Chain
6 | from lib.proof import validate
7 |
8 | chain_blueprint = Blueprint('chain', __name__)
9 |
10 | @chain_blueprint.route('/add-block', methods=['POST'])
11 | # Route to simply submit new, just mined block to this node
12 | def add_block():
13 | QBC = Chain()
14 | if request.method == 'POST':
15 | new_quant_pickle = request.get_json()['quant']
16 | new_quant = pickle.loads(new_quant_pickle)
17 | # Step towards BFT system, checking every quant validity
18 | if(validate(QBC.get_current_quant().proof, new_quant.proof)):
19 | QBC.add_quant(new_quant)
20 | # TODO: better detection if it succided
21 | return "Success"
22 | else:
23 | return "Invalid new block received"
24 |
25 | @chain_blueprint.route('/json-chain', methods=['GET'])
26 | # Route to get chain in JSON format
27 | def serve_json_qbc():
28 | QBC = Chain()
29 | if request.method == 'GET':
30 | return QBC.get_chain("json")
31 |
32 | @chain_blueprint.route('/chain', methods=['GET'])
33 | # Route to get chain in Pickel format
34 | def serve_qbc():
35 | QBC = Chain()
36 | if request.method == 'GET':
37 | return QBC.get_chain("serialized")
38 |
39 | @chain_blueprint.route('/stats', methods=['GET'])
40 | # Route to get Node stats
41 | def chain_stats():
42 | QBC = Chain()
43 | return QBC.get_chain_stats()
--------------------------------------------------------------------------------
/modules/mining/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/metaphorical/quantum-blockchain/7b0c605fabd01c6cfad727317df5bc067125b1d2/modules/mining/__init__.py
--------------------------------------------------------------------------------
/modules/mining/controllers.py:
--------------------------------------------------------------------------------
1 | from flask import Blueprint, request
2 |
3 | from lib.chain import Chain
4 | from lib.network import Network
5 | from lib.transactions import Transactions
6 |
7 | mining_blueprint = Blueprint('mining', __name__)
8 | QBC = Chain()
9 | QBCN = Network()
10 | QBCT = Transactions()
11 |
12 | @mining_blueprint.route('/leap', methods=['GET'])
13 | # Route to trigger ad-hoc mining
14 | # TODO: make mining configurable and automathic so POS and DPOS can be implemented
15 | def generate_block():
16 | live_nodes = QBCN.load_nodes()
17 | if request.method == 'GET':
18 | # Below is super simple, the idea is to have decision model on number of transactions and
19 | # also which transactions go in
20 | print "Starting leap"
21 | new_quant_data = QBCT.load_transactions()
22 | new_quant = QBC.create_quant(new_quant_data)
23 | print new_quant
24 | QBCN.broadcast_quant(live_nodes, new_quant)
25 | QBCT.save_transactions([])
26 | print "Quantum leap"
27 | return "block creation successful\n"
--------------------------------------------------------------------------------
/modules/network/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/metaphorical/quantum-blockchain/7b0c605fabd01c6cfad727317df5bc067125b1d2/modules/network/__init__.py
--------------------------------------------------------------------------------
/modules/network/controllers.py:
--------------------------------------------------------------------------------
1 | import json
2 |
3 | from flask import Blueprint, request
4 |
5 | from lib.network import Network
6 | from lib.chain import Chain
7 |
8 | network_blueprint = Blueprint('network', __name__)
9 | QBC = Chain()
10 | QBCN = Network()
11 |
12 | @network_blueprint.route('/discover', methods=['POST', 'GET'])
13 | # Register new node if not already registered
14 | def register_node():
15 | live_nodes = QBCN.load_nodes()
16 | if request.method == 'GET':
17 | return json.dumps(live_nodes)
18 | if request.method == 'POST':
19 | # import pdb; pdb.set_trace()
20 | new_host = request.get_json()['host']
21 | if not (new_host in live_nodes):
22 | live_nodes.append(new_host)
23 | QBCN.save_nodes(live_nodes)
24 | return json.dumps({
25 | "live_nodes": live_nodes,
26 | "stats": json.loads(QBC.get_chain_stats())
27 | })
--------------------------------------------------------------------------------
/modules/transactions/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/metaphorical/quantum-blockchain/7b0c605fabd01c6cfad727317df5bc067125b1d2/modules/transactions/__init__.py
--------------------------------------------------------------------------------
/modules/transactions/controllers.py:
--------------------------------------------------------------------------------
1 | from flask import Blueprint, request
2 |
3 | from lib.transactions import Transactions
4 | from lib.qbc_utils import QbcUtils
5 | from lib.network import Network
6 |
7 | transactions_blueprint = Blueprint('transactions', __name__)
8 | QBCN = Network()
9 | QBCT = Transactions()
10 | QBCU = QbcUtils()
11 |
12 | @transactions_blueprint.route('/inject', methods=['POST', 'PUT'])
13 | # Route to inject transaction (put in waiting queue)
14 | def add_transaction():
15 | waiting_transactions = QBCT.load_transactions()
16 | live_nodes = QBCN.load_nodes()
17 | port = QBCU.get_port()
18 | # add transaction to waiting list
19 | if request.method == 'POST':
20 | waiting_transactions.append(request.get_json()['data'])
21 | QBCT.save_transactions(waiting_transactions)
22 | print "New transaction added"
23 | print "{}".format(request.get_json()['data'])
24 | QBCT.broadcast_transaction(live_nodes, request.get_json()['data'], port)
25 | return "Transaction submission successful\n"
26 | # receive transaction from known node on the network
27 | if request.method == 'PUT':
28 | waiting_transactions.append(request.get_json()['data'])
29 | QBCT.save_transactions(waiting_transactions)
30 | print "ip of node sending transaction - {}".format(request.remote_addr)
31 | print "New transaction added by the network"
32 | print "{}".format(request.get_json())
33 | return "Transaction submission successful\n"
--------------------------------------------------------------------------------
/readme.md:
--------------------------------------------------------------------------------
1 |
2 |  [](https://snyk.io/test/github/metaphorical/quantum-blockchain)
3 |
4 | # Quantum Blockchain (QBC)
5 | #### Basic general purpose blockchain in Python
6 |
7 |
8 | This project grew out of my experiment of building something to get the full scope of what is needed to build general purpose blockchain. Current idea is to try and evolve it to project that can create BC solution which can seriously contribute to any microservice echosystem in need of safe, secure and distributed data storage.
9 |
10 | ## Idea (look into Medium article for more in depth explanation)
11 |
12 | Build general purpose blockchain system that can maintain and fork multiple blockchains for different purposes and accept different data for different blockchains. Build it as general purose solution that can be used as a service in multiservice system to provide blockchain functionality.
13 |
14 | ## Documentation
15 |
16 | * [Medium article (Whitepaper?)](https://hackernoon.com/building-general-purpose-blockchain-71ffb8511ce)
17 | * [Blockchain Digest](documentation/blockchain-digest.md)
18 | * [Architecture](documentation/architecture.md)
19 |
20 | ## How start contributing and future plans for a project
21 |
22 | You can fork this repo and work on it. When you create pull requests, I will make sure to review it and merge it as soon as possible.
23 |
24 | **If this ever picks up as proper project, I want to give control over it ot group of people so it makes senese to contribute and work on it.**
25 |
26 | More detailed documentation about contributing and rules will come later, but you can review whitepaper, outline of planed features etc, and you can also review trello board:
27 |
28 | [QBC trello](https://trello.com/b/IKDDvvC1/quantum-blockchain)
29 |
30 | If you want to contribute, by either idea or doing some work in code (there is a need for lots of that), please ping me at rastko.vukasinovic@gmail.com so we can discuss and I can add you to board so we ca collect all the ideas and proposals and track any work.
31 |
32 | Thank you!
33 |
34 | Read following part of docs for a way to run QBC and quickly start working on it.
35 |
36 | ## QBC Node server
37 |
38 | > **NOTE:** At this moment, for dev purposes, flask server will be running in debug mode.
39 |
40 | ### Running for local development
41 | Install dependencies from requirements.txt
42 |
43 | Start server by running
44 |
45 | ```
46 | python run.py
47 | ```
48 | This runs server at port **5000**
49 |
50 | If you want to run multiple instances you can add the port as the argument:
51 |
52 | ```
53 | python run.py 3000
54 | ```
55 |
56 | This wouldn't fully work since all the instances look at same place on the disc and persist node network data and chain in the same file... this is not for tastinh networks of nodes - just for running it in different port if you want to do it without virtualization.
57 |
58 | ### Running it using Docker - basic
59 | ```
60 | docker build -t qbc .
61 | docker run -it -p 5000:5000 qbc
62 | ```
63 |
64 | ### Node network testing setup
65 |
66 | In order to be able to test multi node network situation there is docker-compose setup provided for this case. To start it simply do:
67 | ```
68 | docker-compose build
69 | docker-compose up
70 | ```
71 | Setup is doing the following:
72 | * All three nodes will react toyour code changes
73 | * Internal app data is stored in **./test/test_storage/node\***
74 | * Logs are stored in **./test/test_storage/logs\***
75 |
76 | **NOTE:** please make sure to cleanup directories for storage persistance by just leaving main node in node list and removing everything else when you are running new clean test.
77 |
78 | ### List of basic features
79 |
80 | * Accept transactions
81 | * broadcast transactions to known nodes
82 | * Create a block
83 | * Get full chain for comparison
84 | * Basic node registration on the network
85 | * Basic node discovery and distributed registration
86 | * Get chain stats
87 | * Persist blockchain on disc
88 | * Basic bootstrap of the node - when node boots up it reads from the disc and fetches chain stats from known nodes, getting longest chain, or keeping current if longest or same length
89 | * Broadcast new block to all nodes
90 | * [TODO] Check new block on all nodes (chain length check + all other checks)
91 | * [TODO] Make chain stats for comparison (configurable/parametrized) (POW)
92 | * [TODO] Network auth system
93 |
94 |
95 | ### List of additional features:
96 | * [TODO] Multiple proof (consensus) systems
97 | * [TODO] Fork new blockchain
98 | * [TODO] Maintain multiple blockchains on network
99 | * [TODO] Strong validation system
100 | * [TODO] Zero knowledge proof access to data
101 | * [TODO] Other auth / data lock methods
102 | * [TODO] Denormalization to SQL DB / JSON
103 |
104 | ### Support features
105 | * [TODO] Admin UI
106 | * [TODO] Analytics dashboard
107 |
108 |
109 | ## Basic elements
110 |
111 | * **Quantum blockchain (QBC)** - this blockcahain
112 | * **Quant** - block in QBC
113 | * **Bang** - creation of new blockchain - genesis block.
114 | * **Transaction** - new data to be added to block
115 | * **Leap** - creating new Quant containing transactions from the pool
116 |
117 | ### Routes available
118 |
119 | * **/inject**
120 | * [POST] add transaction to transaction pool (transactions waiting ti be added to db)
121 | * **/leap**
122 | * [GET] add the data to blockchain - mine a block putting all the transactions in transaction pool in.
123 | * **/json-chain**
124 | * [GET] get whole chain in the node in JSON format
125 | * **/chain**
126 | * [GET] get whole chain in the node serialized in pickle
127 | * **/discover**
128 | * [POST] register one node on the system by sending it node host addres like host=address
129 | * [GET] get currently up to date list of live nodes known to this node
130 | * **/stats**
131 | * [GET] Get chain stats
132 |
133 | ### To test server while running
134 |
135 | Using [httpie](https://httpie.org/) :
136 |
137 | Add transaction to node (put on waiting list aka transaction pool):
138 |
139 | ```
140 | http -v POST localhost:5000/inject data="{\"test\":\"test2\"}"
141 | ```
142 |
143 | Add block of data to blockchain:
144 | ```
145 | http -v GET localhost:5000/leap
146 | ```
147 |
148 | Get blockchain in JSON format:
149 | ```
150 | http -v GET localhost:5000/json-chain
151 | ```
152 |
153 | ## Used third party dependencies
154 |
155 | * [Flask](http://flask.pocoo.org/docs/0.12/quickstart/)
156 | * [Requests](http://docs.python-requests.org/en/latest/user/quickstart/)
157 |
158 |
--------------------------------------------------------------------------------
/requirements.txt:
--------------------------------------------------------------------------------
1 | astroid==1.6.2
2 | backports.functools-lru-cache==1.5
3 | certifi==2018.1.18
4 | chardet==3.0.4
5 | click==6.7
6 | configparser==3.5.0
7 | enum34==1.1.6
8 | Flask==1.0.2
9 | Flask-SocketIO==2.9.3
10 | futures==3.2.0
11 | gnupg==2.3.1
12 | idna==2.6
13 | isort==4.3.4
14 | itsdangerous==0.24
15 | Jinja2==2.10
16 | lazy-object-proxy==1.3.1
17 | MarkupSafe==1.0
18 | mccabe==0.6.1
19 | psutil==5.4.6
20 | pylint==1.8.3
21 | python-engineio==2.0.2
22 | python-socketio==1.8.4
23 | requests==2.18.4
24 | singledispatch==3.4.0.3
25 | six==1.11.0
26 | urllib3==1.22
27 | Werkzeug==3.0.6
28 | wrapt==1.10.11
29 |
--------------------------------------------------------------------------------
/run.py:
--------------------------------------------------------------------------------
1 | import json
2 |
3 | from flask import Flask
4 |
5 | from lib.chain import Chain
6 | from lib.network import Network
7 | from lib.qbc_utils import QbcUtils
8 |
9 | from modules.transactions.controllers import transactions_blueprint
10 | from modules.mining.controllers import mining_blueprint
11 | from modules.network.controllers import network_blueprint
12 | from modules.chain.controllers import chain_blueprint
13 |
14 | node = Flask(__name__)
15 |
16 | QBC = Chain()
17 | QBCN = Network()
18 | QBCU = QbcUtils()
19 | port = QBCU.get_port()
20 |
21 | # Registering all the modules
22 | node.register_blueprint(transactions_blueprint)
23 |
24 | node.register_blueprint(mining_blueprint)
25 |
26 | node.register_blueprint(network_blueprint)
27 |
28 | node.register_blueprint(chain_blueprint)
29 |
30 |
31 | # Discover full network and register on each of the nodes
32 | network = QBCN.discover_network()
33 | live_nodes=network["registered_nodes"]
34 |
35 | if not QBCU.is_genesis_node():
36 | QBCN.save_nodes(live_nodes)
37 |
38 | # If this is not first (genesis) node (meaning that at start there is noone else to look at on start),
39 | # take look at network stats to see if there is longer chain. If there is one - get it.
40 | if json.loads(QBC.get_chain_stats())["length"] < network["longest_chain_length"]:
41 | QBC.get_remote_node_chain(network["longest_chain_node"])
42 |
43 |
44 | node.run(host='0.0.0.0', port=port, debug=True)
--------------------------------------------------------------------------------
/storage/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/metaphorical/quantum-blockchain/7b0c605fabd01c6cfad727317df5bc067125b1d2/storage/.gitkeep
--------------------------------------------------------------------------------
/storage/nodes.json:
--------------------------------------------------------------------------------
1 | [
2 | "http://172.16.238.10:5000"
3 | ]
--------------------------------------------------------------------------------
/storage/transactions.json:
--------------------------------------------------------------------------------
1 | []
--------------------------------------------------------------------------------
/test/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/metaphorical/quantum-blockchain/7b0c605fabd01c6cfad727317df5bc067125b1d2/test/__init__.py
--------------------------------------------------------------------------------
/test/test_storage/node1/nodes.json:
--------------------------------------------------------------------------------
1 | ["http://172.16.238.10:5000"]
--------------------------------------------------------------------------------
/test/test_storage/node2/nodes.json:
--------------------------------------------------------------------------------
1 | ["http://172.16.238.10:5000"]
--------------------------------------------------------------------------------
/test/test_storage/node3/nodes.json:
--------------------------------------------------------------------------------
1 | ["http://172.16.238.10:5000"]
--------------------------------------------------------------------------------