Gav Wood
10 years ago
240 changed files with 16967 additions and 5318 deletions
@ -1,19 +1,673 @@ |
|||
The MIT License (MIT) |
|||
|
|||
Permission is hereby granted, free of charge, to any person obtaining a copy |
|||
of this software and associated documentation files (the "Software"), to deal |
|||
in the Software without restriction, including without limitation the rights |
|||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|||
copies of the Software, and to permit persons to whom the Software is |
|||
furnished to do so, subject to the following conditions: |
|||
|
|||
The above copyright notice and this permission notice shall be included in |
|||
all copies or substantial portions of the Software. |
|||
|
|||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
|||
THE SOFTWARE. |
|||
Version 3, 29 June 2007 |
|||
|
|||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> |
|||
Everyone is permitted to copy and distribute verbatim copies |
|||
of this license document, but changing it is not allowed. |
|||
|
|||
Preamble |
|||
|
|||
The GNU General Public License is a free, copyleft license for |
|||
software and other kinds of works. |
|||
|
|||
The licenses for most software and other practical works are designed |
|||
to take away your freedom to share and change the works. By contrast, |
|||
the GNU General Public License is intended to guarantee your freedom to |
|||
share and change all versions of a program--to make sure it remains free |
|||
software for all its users. We, the Free Software Foundation, use the |
|||
GNU General Public License for most of our software; it applies also to |
|||
any other work released this way by its authors. You can apply it to |
|||
your programs, too. |
|||
|
|||
When we speak of free software, we are referring to freedom, not |
|||
price. Our General Public Licenses are designed to make sure that you |
|||
have the freedom to distribute copies of free software (and charge for |
|||
them if you wish), that you receive source code or can get it if you |
|||
want it, that you can change the software or use pieces of it in new |
|||
free programs, and that you know you can do these things. |
|||
|
|||
To protect your rights, we need to prevent others from denying you |
|||
these rights or asking you to surrender the rights. Therefore, you have |
|||
certain responsibilities if you distribute copies of the software, or if |
|||
you modify it: responsibilities to respect the freedom of others. |
|||
|
|||
For example, if you distribute copies of such a program, whether |
|||
gratis or for a fee, you must pass on to the recipients the same |
|||
freedoms that you received. You must make sure that they, too, receive |
|||
or can get the source code. And you must show them these terms so they |
|||
know their rights. |
|||
|
|||
Developers that use the GNU GPL protect your rights with two steps: |
|||
(1) assert copyright on the software, and (2) offer you this License |
|||
giving you legal permission to copy, distribute and/or modify it. |
|||
|
|||
For the developers' and authors' protection, the GPL clearly explains |
|||
that there is no warranty for this free software. For both users' and |
|||
authors' sake, the GPL requires that modified versions be marked as |
|||
changed, so that their problems will not be attributed erroneously to |
|||
authors of previous versions. |
|||
|
|||
Some devices are designed to deny users access to install or run |
|||
modified versions of the software inside them, although the manufacturer |
|||
can do so. This is fundamentally incompatible with the aim of |
|||
protecting users' freedom to change the software. The systematic |
|||
pattern of such abuse occurs in the area of products for individuals to |
|||
use, which is precisely where it is most unacceptable. Therefore, we |
|||
have designed this version of the GPL to prohibit the practice for those |
|||
products. If such problems arise substantially in other domains, we |
|||
stand ready to extend this provision to those domains in future versions |
|||
of the GPL, as needed to protect the freedom of users. |
|||
|
|||
Finally, every program is threatened constantly by software patents. |
|||
States should not allow patents to restrict development and use of |
|||
software on general-purpose computers, but in those that do, we wish to |
|||
avoid the special danger that patents applied to a free program could |
|||
make it effectively proprietary. To prevent this, the GPL assures that |
|||
patents cannot be used to render the program non-free. |
|||
|
|||
The precise terms and conditions for copying, distribution and |
|||
modification follow. |
|||
|
|||
TERMS AND CONDITIONS |
|||
|
|||
0. Definitions. |
|||
|
|||
"This License" refers to version 3 of the GNU General Public License. |
|||
|
|||
"Copyright" also means copyright-like laws that apply to other kinds of |
|||
works, such as semiconductor masks. |
|||
|
|||
"The Program" refers to any copyrightable work licensed under this |
|||
License. Each licensee is addressed as "you". "Licensees" and |
|||
"recipients" may be individuals or organizations. |
|||
|
|||
To "modify" a work means to copy from or adapt all or part of the work |
|||
in a fashion requiring copyright permission, other than the making of an |
|||
exact copy. The resulting work is called a "modified version" of the |
|||
earlier work or a work "based on" the earlier work. |
|||
|
|||
A "covered work" means either the unmodified Program or a work based |
|||
on the Program. |
|||
|
|||
To "propagate" a work means to do anything with it that, without |
|||
permission, would make you directly or secondarily liable for |
|||
infringement under applicable copyright law, except executing it on a |
|||
computer or modifying a private copy. Propagation includes copying, |
|||
distribution (with or without modification), making available to the |
|||
public, and in some countries other activities as well. |
|||
|
|||
To "convey" a work means any kind of propagation that enables other |
|||
parties to make or receive copies. Mere interaction with a user through |
|||
a computer network, with no transfer of a copy, is not conveying. |
|||
|
|||
An interactive user interface displays "Appropriate Legal Notices" |
|||
to the extent that it includes a convenient and prominently visible |
|||
feature that (1) displays an appropriate copyright notice, and (2) |
|||
tells the user that there is no warranty for the work (except to the |
|||
extent that warranties are provided), that licensees may convey the |
|||
work under this License, and how to view a copy of this License. If |
|||
the interface presents a list of user commands or options, such as a |
|||
menu, a prominent item in the list meets this criterion. |
|||
|
|||
1. Source Code. |
|||
|
|||
The "source code" for a work means the preferred form of the work |
|||
for making modifications to it. "Object code" means any non-source |
|||
form of a work. |
|||
|
|||
A "Standard Interface" means an interface that either is an official |
|||
standard defined by a recognized standards body, or, in the case of |
|||
interfaces specified for a particular programming language, one that |
|||
is widely used among developers working in that language. |
|||
|
|||
The "System Libraries" of an executable work include anything, other |
|||
than the work as a whole, that (a) is included in the normal form of |
|||
packaging a Major Component, but which is not part of that Major |
|||
Component, and (b) serves only to enable use of the work with that |
|||
Major Component, or to implement a Standard Interface for which an |
|||
implementation is available to the public in source code form. A |
|||
"Major Component", in this context, means a major essential component |
|||
(kernel, window system, and so on) of the specific operating system |
|||
(if any) on which the executable work runs, or a compiler used to |
|||
produce the work, or an object code interpreter used to run it. |
|||
|
|||
The "Corresponding Source" for a work in object code form means all |
|||
the source code needed to generate, install, and (for an executable |
|||
work) run the object code and to modify the work, including scripts to |
|||
control those activities. However, it does not include the work's |
|||
System Libraries, or general-purpose tools or generally available free |
|||
programs which are used unmodified in performing those activities but |
|||
which are not part of the work. For example, Corresponding Source |
|||
includes interface definition files associated with source files for |
|||
the work, and the source code for shared libraries and dynamically |
|||
linked subprograms that the work is specifically designed to require, |
|||
such as by intimate data communication or control flow between those |
|||
subprograms and other parts of the work. |
|||
|
|||
The Corresponding Source need not include anything that users |
|||
can regenerate automatically from other parts of the Corresponding |
|||
Source. |
|||
|
|||
The Corresponding Source for a work in source code form is that |
|||
same work. |
|||
|
|||
2. Basic Permissions. |
|||
|
|||
All rights granted under this License are granted for the term of |
|||
copyright on the Program, and are irrevocable provided the stated |
|||
conditions are met. This License explicitly affirms your unlimited |
|||
permission to run the unmodified Program. The output from running a |
|||
covered work is covered by this License only if the output, given its |
|||
content, constitutes a covered work. This License acknowledges your |
|||
rights of fair use or other equivalent, as provided by copyright law. |
|||
|
|||
You may make, run and propagate covered works that you do not |
|||
convey, without conditions so long as your license otherwise remains |
|||
in force. You may convey covered works to others for the sole purpose |
|||
of having them make modifications exclusively for you, or provide you |
|||
with facilities for running those works, provided that you comply with |
|||
the terms of this License in conveying all material for which you do |
|||
not control copyright. Those thus making or running the covered works |
|||
for you must do so exclusively on your behalf, under your direction |
|||
and control, on terms that prohibit them from making any copies of |
|||
your copyrighted material outside their relationship with you. |
|||
|
|||
Conveying under any other circumstances is permitted solely under |
|||
the conditions stated below. Sublicensing is not allowed; section 10 |
|||
makes it unnecessary. |
|||
|
|||
3. Protecting Users' Legal Rights From Anti-Circumvention Law. |
|||
|
|||
No covered work shall be deemed part of an effective technological |
|||
measure under any applicable law fulfilling obligations under article |
|||
11 of the WIPO copyright treaty adopted on 20 December 1996, or |
|||
similar laws prohibiting or restricting circumvention of such |
|||
measures. |
|||
|
|||
When you convey a covered work, you waive any legal power to forbid |
|||
circumvention of technological measures to the extent such circumvention |
|||
is effected by exercising rights under this License with respect to |
|||
the covered work, and you disclaim any intention to limit operation or |
|||
modification of the work as a means of enforcing, against the work's |
|||
users, your or third parties' legal rights to forbid circumvention of |
|||
technological measures. |
|||
|
|||
4. Conveying Verbatim Copies. |
|||
|
|||
You may convey verbatim copies of the Program's source code as you |
|||
receive it, in any medium, provided that you conspicuously and |
|||
appropriately publish on each copy an appropriate copyright notice; |
|||
keep intact all notices stating that this License and any |
|||
non-permissive terms added in accord with section 7 apply to the code; |
|||
keep intact all notices of the absence of any warranty; and give all |
|||
recipients a copy of this License along with the Program. |
|||
|
|||
You may charge any price or no price for each copy that you convey, |
|||
and you may offer support or warranty protection for a fee. |
|||
|
|||
5. Conveying Modified Source Versions. |
|||
|
|||
You may convey a work based on the Program, or the modifications to |
|||
produce it from the Program, in the form of source code under the |
|||
terms of section 4, provided that you also meet all of these conditions: |
|||
|
|||
a) The work must carry prominent notices stating that you modified |
|||
it, and giving a relevant date. |
|||
|
|||
b) The work must carry prominent notices stating that it is |
|||
released under this License and any conditions added under section |
|||
7. This requirement modifies the requirement in section 4 to |
|||
"keep intact all notices". |
|||
|
|||
c) You must license the entire work, as a whole, under this |
|||
License to anyone who comes into possession of a copy. This |
|||
License will therefore apply, along with any applicable section 7 |
|||
additional terms, to the whole of the work, and all its parts, |
|||
regardless of how they are packaged. This License gives no |
|||
permission to license the work in any other way, but it does not |
|||
invalidate such permission if you have separately received it. |
|||
|
|||
d) If the work has interactive user interfaces, each must display |
|||
Appropriate Legal Notices; however, if the Program has interactive |
|||
interfaces that do not display Appropriate Legal Notices, your |
|||
work need not make them do so. |
|||
|
|||
A compilation of a covered work with other separate and independent |
|||
works, which are not by their nature extensions of the covered work, |
|||
and which are not combined with it such as to form a larger program, |
|||
in or on a volume of a storage or distribution medium, is called an |
|||
"aggregate" if the compilation and its resulting copyright are not |
|||
used to limit the access or legal rights of the compilation's users |
|||
beyond what the individual works permit. Inclusion of a covered work |
|||
in an aggregate does not cause this License to apply to the other |
|||
parts of the aggregate. |
|||
|
|||
6. Conveying Non-Source Forms. |
|||
|
|||
You may convey a covered work in object code form under the terms |
|||
of sections 4 and 5, provided that you also convey the |
|||
machine-readable Corresponding Source under the terms of this License, |
|||
in one of these ways: |
|||
|
|||
a) Convey the object code in, or embodied in, a physical product |
|||
(including a physical distribution medium), accompanied by the |
|||
Corresponding Source fixed on a durable physical medium |
|||
customarily used for software interchange. |
|||
|
|||
b) Convey the object code in, or embodied in, a physical product |
|||
(including a physical distribution medium), accompanied by a |
|||
written offer, valid for at least three years and valid for as |
|||
long as you offer spare parts or customer support for that product |
|||
model, to give anyone who possesses the object code either (1) a |
|||
copy of the Corresponding Source for all the software in the |
|||
product that is covered by this License, on a durable physical |
|||
medium customarily used for software interchange, for a price no |
|||
more than your reasonable cost of physically performing this |
|||
conveying of source, or (2) access to copy the |
|||
Corresponding Source from a network server at no charge. |
|||
|
|||
c) Convey individual copies of the object code with a copy of the |
|||
written offer to provide the Corresponding Source. This |
|||
alternative is allowed only occasionally and noncommercially, and |
|||
only if you received the object code with such an offer, in accord |
|||
with subsection 6b. |
|||
|
|||
d) Convey the object code by offering access from a designated |
|||
place (gratis or for a charge), and offer equivalent access to the |
|||
Corresponding Source in the same way through the same place at no |
|||
further charge. You need not require recipients to copy the |
|||
Corresponding Source along with the object code. If the place to |
|||
copy the object code is a network server, the Corresponding Source |
|||
may be on a different server (operated by you or a third party) |
|||
that supports equivalent copying facilities, provided you maintain |
|||
clear directions next to the object code saying where to find the |
|||
Corresponding Source. Regardless of what server hosts the |
|||
Corresponding Source, you remain obligated to ensure that it is |
|||
available for as long as needed to satisfy these requirements. |
|||
|
|||
e) Convey the object code using peer-to-peer transmission, provided |
|||
you inform other peers where the object code and Corresponding |
|||
Source of the work are being offered to the general public at no |
|||
charge under subsection 6d. |
|||
|
|||
A separable portion of the object code, whose source code is excluded |
|||
from the Corresponding Source as a System Library, need not be |
|||
included in conveying the object code work. |
|||
|
|||
A "User Product" is either (1) a "consumer product", which means any |
|||
tangible personal property which is normally used for personal, family, |
|||
or household purposes, or (2) anything designed or sold for incorporation |
|||
into a dwelling. In determining whether a product is a consumer product, |
|||
doubtful cases shall be resolved in favor of coverage. For a particular |
|||
product received by a particular user, "normally used" refers to a |
|||
typical or common use of that class of product, regardless of the status |
|||
of the particular user or of the way in which the particular user |
|||
actually uses, or expects or is expected to use, the product. A product |
|||
is a consumer product regardless of whether the product has substantial |
|||
commercial, industrial or non-consumer uses, unless such uses represent |
|||
the only significant mode of use of the product. |
|||
|
|||
"Installation Information" for a User Product means any methods, |
|||
procedures, authorization keys, or other information required to install |
|||
and execute modified versions of a covered work in that User Product from |
|||
a modified version of its Corresponding Source. The information must |
|||
suffice to ensure that the continued functioning of the modified object |
|||
code is in no case prevented or interfered with solely because |
|||
modification has been made. |
|||
|
|||
If you convey an object code work under this section in, or with, or |
|||
specifically for use in, a User Product, and the conveying occurs as |
|||
part of a transaction in which the right of possession and use of the |
|||
User Product is transferred to the recipient in perpetuity or for a |
|||
fixed term (regardless of how the transaction is characterized), the |
|||
Corresponding Source conveyed under this section must be accompanied |
|||
by the Installation Information. But this requirement does not apply |
|||
if neither you nor any third party retains the ability to install |
|||
modified object code on the User Product (for example, the work has |
|||
been installed in ROM). |
|||
|
|||
The requirement to provide Installation Information does not include a |
|||
requirement to continue to provide support service, warranty, or updates |
|||
for a work that has been modified or installed by the recipient, or for |
|||
the User Product in which it has been modified or installed. Access to a |
|||
network may be denied when the modification itself materially and |
|||
adversely affects the operation of the network or violates the rules and |
|||
protocols for communication across the network. |
|||
|
|||
Corresponding Source conveyed, and Installation Information provided, |
|||
in accord with this section must be in a format that is publicly |
|||
documented (and with an implementation available to the public in |
|||
source code form), and must require no special password or key for |
|||
unpacking, reading or copying. |
|||
|
|||
7. Additional Terms. |
|||
|
|||
"Additional permissions" are terms that supplement the terms of this |
|||
License by making exceptions from one or more of its conditions. |
|||
Additional permissions that are applicable to the entire Program shall |
|||
be treated as though they were included in this License, to the extent |
|||
that they are valid under applicable law. If additional permissions |
|||
apply only to part of the Program, that part may be used separately |
|||
under those permissions, but the entire Program remains governed by |
|||
this License without regard to the additional permissions. |
|||
|
|||
When you convey a copy of a covered work, you may at your option |
|||
remove any additional permissions from that copy, or from any part of |
|||
it. (Additional permissions may be written to require their own |
|||
removal in certain cases when you modify the work.) You may place |
|||
additional permissions on material, added by you to a covered work, |
|||
for which you have or can give appropriate copyright permission. |
|||
|
|||
Notwithstanding any other provision of this License, for material you |
|||
add to a covered work, you may (if authorized by the copyright holders of |
|||
that material) supplement the terms of this License with terms: |
|||
|
|||
a) Disclaiming warranty or limiting liability differently from the |
|||
terms of sections 15 and 16 of this License; or |
|||
|
|||
b) Requiring preservation of specified reasonable legal notices or |
|||
author attributions in that material or in the Appropriate Legal |
|||
Notices displayed by works containing it; or |
|||
|
|||
c) Prohibiting misrepresentation of the origin of that material, or |
|||
requiring that modified versions of such material be marked in |
|||
reasonable ways as different from the original version; or |
|||
|
|||
d) Limiting the use for publicity purposes of names of licensors or |
|||
authors of the material; or |
|||
|
|||
e) Declining to grant rights under trademark law for use of some |
|||
trade names, trademarks, or service marks; or |
|||
|
|||
f) Requiring indemnification of licensors and authors of that |
|||
material by anyone who conveys the material (or modified versions of |
|||
it) with contractual assumptions of liability to the recipient, for |
|||
any liability that these contractual assumptions directly impose on |
|||
those licensors and authors. |
|||
|
|||
All other non-permissive additional terms are considered "further |
|||
restrictions" within the meaning of section 10. If the Program as you |
|||
received it, or any part of it, contains a notice stating that it is |
|||
governed by this License along with a term that is a further |
|||
restriction, you may remove that term. If a license document contains |
|||
a further restriction but permits relicensing or conveying under this |
|||
License, you may add to a covered work material governed by the terms |
|||
of that license document, provided that the further restriction does |
|||
not survive such relicensing or conveying. |
|||
|
|||
If you add terms to a covered work in accord with this section, you |
|||
must place, in the relevant source files, a statement of the |
|||
additional terms that apply to those files, or a notice indicating |
|||
where to find the applicable terms. |
|||
|
|||
Additional terms, permissive or non-permissive, may be stated in the |
|||
form of a separately written license, or stated as exceptions; |
|||
the above requirements apply either way. |
|||
|
|||
8. Termination. |
|||
|
|||
You may not propagate or modify a covered work except as expressly |
|||
provided under this License. Any attempt otherwise to propagate or |
|||
modify it is void, and will automatically terminate your rights under |
|||
this License (including any patent licenses granted under the third |
|||
paragraph of section 11). |
|||
|
|||
However, if you cease all violation of this License, then your |
|||
license from a particular copyright holder is reinstated (a) |
|||
provisionally, unless and until the copyright holder explicitly and |
|||
finally terminates your license, and (b) permanently, if the copyright |
|||
holder fails to notify you of the violation by some reasonable means |
|||
prior to 60 days after the cessation. |
|||
|
|||
Moreover, your license from a particular copyright holder is |
|||
reinstated permanently if the copyright holder notifies you of the |
|||
violation by some reasonable means, this is the first time you have |
|||
received notice of violation of this License (for any work) from that |
|||
copyright holder, and you cure the violation prior to 30 days after |
|||
your receipt of the notice. |
|||
|
|||
Termination of your rights under this section does not terminate the |
|||
licenses of parties who have received copies or rights from you under |
|||
this License. If your rights have been terminated and not permanently |
|||
reinstated, you do not qualify to receive new licenses for the same |
|||
material under section 10. |
|||
|
|||
9. Acceptance Not Required for Having Copies. |
|||
|
|||
You are not required to accept this License in order to receive or |
|||
run a copy of the Program. Ancillary propagation of a covered work |
|||
occurring solely as a consequence of using peer-to-peer transmission |
|||
to receive a copy likewise does not require acceptance. However, |
|||
nothing other than this License grants you permission to propagate or |
|||
modify any covered work. These actions infringe copyright if you do |
|||
not accept this License. Therefore, by modifying or propagating a |
|||
covered work, you indicate your acceptance of this License to do so. |
|||
|
|||
10. Automatic Licensing of Downstream Recipients. |
|||
|
|||
Each time you convey a covered work, the recipient automatically |
|||
receives a license from the original licensors, to run, modify and |
|||
propagate that work, subject to this License. You are not responsible |
|||
for enforcing compliance by third parties with this License. |
|||
|
|||
An "entity transaction" is a transaction transferring control of an |
|||
organization, or substantially all assets of one, or subdividing an |
|||
organization, or merging organizations. If propagation of a covered |
|||
work results from an entity transaction, each party to that |
|||
transaction who receives a copy of the work also receives whatever |
|||
licenses to the work the party's predecessor in interest had or could |
|||
give under the previous paragraph, plus a right to possession of the |
|||
Corresponding Source of the work from the predecessor in interest, if |
|||
the predecessor has it or can get it with reasonable efforts. |
|||
|
|||
You may not impose any further restrictions on the exercise of the |
|||
rights granted or affirmed under this License. For example, you may |
|||
not impose a license fee, royalty, or other charge for exercise of |
|||
rights granted under this License, and you may not initiate litigation |
|||
(including a cross-claim or counterclaim in a lawsuit) alleging that |
|||
any patent claim is infringed by making, using, selling, offering for |
|||
sale, or importing the Program or any portion of it. |
|||
|
|||
11. Patents. |
|||
|
|||
A "contributor" is a copyright holder who authorizes use under this |
|||
License of the Program or a work on which the Program is based. The |
|||
work thus licensed is called the contributor's "contributor version". |
|||
|
|||
A contributor's "essential patent claims" are all patent claims |
|||
owned or controlled by the contributor, whether already acquired or |
|||
hereafter acquired, that would be infringed by some manner, permitted |
|||
by this License, of making, using, or selling its contributor version, |
|||
but do not include claims that would be infringed only as a |
|||
consequence of further modification of the contributor version. For |
|||
purposes of this definition, "control" includes the right to grant |
|||
patent sublicenses in a manner consistent with the requirements of |
|||
this License. |
|||
|
|||
Each contributor grants you a non-exclusive, worldwide, royalty-free |
|||
patent license under the contributor's essential patent claims, to |
|||
make, use, sell, offer for sale, import and otherwise run, modify and |
|||
propagate the contents of its contributor version. |
|||
|
|||
In the following three paragraphs, a "patent license" is any express |
|||
agreement or commitment, however denominated, not to enforce a patent |
|||
(such as an express permission to practice a patent or covenant not to |
|||
sue for patent infringement). To "grant" such a patent license to a |
|||
party means to make such an agreement or commitment not to enforce a |
|||
patent against the party. |
|||
|
|||
If you convey a covered work, knowingly relying on a patent license, |
|||
and the Corresponding Source of the work is not available for anyone |
|||
to copy, free of charge and under the terms of this License, through a |
|||
publicly available network server or other readily accessible means, |
|||
then you must either (1) cause the Corresponding Source to be so |
|||
available, or (2) arrange to deprive yourself of the benefit of the |
|||
patent license for this particular work, or (3) arrange, in a manner |
|||
consistent with the requirements of this License, to extend the patent |
|||
license to downstream recipients. "Knowingly relying" means you have |
|||
actual knowledge that, but for the patent license, your conveying the |
|||
covered work in a country, or your recipient's use of the covered work |
|||
in a country, would infringe one or more identifiable patents in that |
|||
country that you have reason to believe are valid. |
|||
|
|||
If, pursuant to or in connection with a single transaction or |
|||
arrangement, you convey, or propagate by procuring conveyance of, a |
|||
covered work, and grant a patent license to some of the parties |
|||
receiving the covered work authorizing them to use, propagate, modify |
|||
or convey a specific copy of the covered work, then the patent license |
|||
you grant is automatically extended to all recipients of the covered |
|||
work and works based on it. |
|||
|
|||
A patent license is "discriminatory" if it does not include within |
|||
the scope of its coverage, prohibits the exercise of, or is |
|||
conditioned on the non-exercise of one or more of the rights that are |
|||
specifically granted under this License. You may not convey a covered |
|||
work if you are a party to an arrangement with a third party that is |
|||
in the business of distributing software, under which you make payment |
|||
to the third party based on the extent of your activity of conveying |
|||
the work, and under which the third party grants, to any of the |
|||
parties who would receive the covered work from you, a discriminatory |
|||
patent license (a) in connection with copies of the covered work |
|||
conveyed by you (or copies made from those copies), or (b) primarily |
|||
for and in connection with specific products or compilations that |
|||
contain the covered work, unless you entered into that arrangement, |
|||
or that patent license was granted, prior to 28 March 2007. |
|||
|
|||
Nothing in this License shall be construed as excluding or limiting |
|||
any implied license or other defenses to infringement that may |
|||
otherwise be available to you under applicable patent law. |
|||
|
|||
12. No Surrender of Others' Freedom. |
|||
|
|||
If conditions are imposed on you (whether by court order, agreement or |
|||
otherwise) that contradict the conditions of this License, they do not |
|||
excuse you from the conditions of this License. If you cannot convey a |
|||
covered work so as to satisfy simultaneously your obligations under this |
|||
License and any other pertinent obligations, then as a consequence you may |
|||
not convey it at all. For example, if you agree to terms that obligate you |
|||
to collect a royalty for further conveying from those to whom you convey |
|||
the Program, the only way you could satisfy both those terms and this |
|||
License would be to refrain entirely from conveying the Program. |
|||
|
|||
13. Use with the GNU Affero General Public License. |
|||
|
|||
Notwithstanding any other provision of this License, you have |
|||
permission to link or combine any covered work with a work licensed |
|||
under version 3 of the GNU Affero General Public License into a single |
|||
combined work, and to convey the resulting work. The terms of this |
|||
License will continue to apply to the part which is the covered work, |
|||
but the special requirements of the GNU Affero General Public License, |
|||
section 13, concerning interaction through a network will apply to the |
|||
combination as such. |
|||
|
|||
14. Revised Versions of this License. |
|||
|
|||
The Free Software Foundation may publish revised and/or new versions of |
|||
the GNU General Public License from time to time. Such new versions will |
|||
be similar in spirit to the present version, but may differ in detail to |
|||
address new problems or concerns. |
|||
|
|||
Each version is given a distinguishing version number. If the |
|||
Program specifies that a certain numbered version of the GNU General |
|||
Public License "or any later version" applies to it, you have the |
|||
option of following the terms and conditions either of that numbered |
|||
version or of any later version published by the Free Software |
|||
Foundation. If the Program does not specify a version number of the |
|||
GNU General Public License, you may choose any version ever published |
|||
by the Free Software Foundation. |
|||
|
|||
If the Program specifies that a proxy can decide which future |
|||
versions of the GNU General Public License can be used, that proxy's |
|||
public statement of acceptance of a version permanently authorizes you |
|||
to choose that version for the Program. |
|||
|
|||
Later license versions may give you additional or different |
|||
permissions. However, no additional obligations are imposed on any |
|||
author or copyright holder as a result of your choosing to follow a |
|||
later version. |
|||
|
|||
15. Disclaimer of Warranty. |
|||
|
|||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY |
|||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT |
|||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY |
|||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, |
|||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM |
|||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF |
|||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION. |
|||
|
|||
16. Limitation of Liability. |
|||
|
|||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING |
|||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS |
|||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY |
|||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE |
|||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF |
|||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD |
|||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), |
|||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF |
|||
SUCH DAMAGES. |
|||
|
|||
17. Interpretation of Sections 15 and 16. |
|||
|
|||
If the disclaimer of warranty and limitation of liability provided |
|||
above cannot be given local legal effect according to their terms, |
|||
reviewing courts shall apply local law that most closely approximates |
|||
an absolute waiver of all civil liability in connection with the |
|||
Program, unless a warranty or assumption of liability accompanies a |
|||
copy of the Program in return for a fee. |
|||
|
|||
END OF TERMS AND CONDITIONS |
|||
|
|||
How to Apply These Terms to Your New Programs |
|||
|
|||
If you develop a new program, and you want it to be of the greatest |
|||
possible use to the public, the best way to achieve this is to make it |
|||
free software which everyone can redistribute and change under these terms. |
|||
|
|||
To do so, attach the following notices to the program. It is safest |
|||
to attach them to the start of each source file to most effectively |
|||
state the exclusion of warranty; and each file should have at least |
|||
the "copyright" line and a pointer to where the full notice is found. |
|||
|
|||
<one line to give the program's name and a brief idea of what it does.> |
|||
Copyright (C) <year> <name of author> |
|||
|
|||
This program is free software: you can redistribute it and/or modify |
|||
it under the terms of the GNU General Public License as published by |
|||
the Free Software Foundation, either version 3 of the License, or |
|||
(at your option) any later version. |
|||
|
|||
This program is distributed in the hope that it will be useful, |
|||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
GNU General Public License for more details. |
|||
|
|||
You should have received a copy of the GNU General Public License |
|||
along with this program. If not, see <http://www.gnu.org/licenses/>. |
|||
|
|||
Also add information on how to contact you by electronic and paper mail. |
|||
|
|||
If the program does terminal interaction, make it output a short |
|||
notice like this when it starts in an interactive mode: |
|||
|
|||
<program> Copyright (C) <year> <name of author> |
|||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. |
|||
This is free software, and you are welcome to redistribute it |
|||
under certain conditions; type `show c' for details. |
|||
|
|||
The hypothetical commands `show w' and `show c' should show the appropriate |
|||
parts of the General Public License. Of course, your program's commands |
|||
might be different; for a GUI interface, you would use an "about box". |
|||
|
|||
You should also get your employer (if you work as a programmer) or school, |
|||
if any, to sign a "copyright disclaimer" for the program, if necessary. |
|||
For more information on this, and how to apply and follow the GNU GPL, see |
|||
<http://www.gnu.org/licenses/>. |
|||
|
|||
The GNU General Public License does not permit incorporating your program |
|||
into proprietary programs. If your program is a subroutine library, you |
|||
may consider it more useful to permit linking proprietary applications with |
|||
the library. If this is what you want to do, use the GNU Lesser General |
|||
Public License instead of this License. But first, please read |
|||
<http://www.gnu.org/philosophy/why-not-lgpl.html>. |
|||
|
@ -0,0 +1,83 @@ |
|||
/*
|
|||
This file is part of cpp-ethereum. |
|||
|
|||
cpp-ethereum is free software: you can redistribute it and/or modify |
|||
it under the terms of the GNU General Public License as published by |
|||
the Free Software Foundation, either version 3 of the License, or |
|||
(at your option) any later version. |
|||
|
|||
cpp-ethereum is distributed in the hope that it will be useful, |
|||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
GNU General Public License for more details. |
|||
|
|||
You should have received a copy of the GNU General Public License |
|||
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
/** @file DownloadView.cpp
|
|||
* @author Gav Wood <i@gavwood.com> |
|||
* @date 2014 |
|||
*/ |
|||
|
|||
#include "DownloadView.h" |
|||
|
|||
#include <QtWidgets> |
|||
#include <QtCore> |
|||
#include <libethereum/DownloadMan.h> |
|||
#include "Grapher.h" |
|||
|
|||
using namespace std; |
|||
using namespace dev; |
|||
using namespace dev::eth; |
|||
|
|||
DownloadView::DownloadView(QWidget* _p): QWidget(_p) |
|||
{ |
|||
} |
|||
|
|||
void DownloadView::paintEvent(QPaintEvent*) |
|||
{ |
|||
QPainter p(this); |
|||
|
|||
p.fillRect(rect(), Qt::white); |
|||
if (!m_man || m_man->chain().empty() || !m_man->subCount()) |
|||
return; |
|||
|
|||
double ratio = (double)rect().width() / rect().height(); |
|||
if (ratio < 1) |
|||
ratio = 1 / ratio; |
|||
double n = min(rect().width(), rect().height()) / ceil(sqrt(m_man->chain().size() / ratio)); |
|||
|
|||
// QSizeF area(rect().width() / floor(rect().width() / n), rect().height() / floor(rect().height() / n));
|
|||
QSizeF area(n, n); |
|||
QPointF pos(0, 0); |
|||
|
|||
auto const& bg = m_man->blocksGot(); |
|||
|
|||
for (unsigned i = bg.all().first, ei = bg.all().second; i < ei; ++i) |
|||
{ |
|||
int s = -2; |
|||
if (bg.contains(i)) |
|||
s = -1; |
|||
else |
|||
{ |
|||
unsigned h = 0; |
|||
m_man->foreachSub([&](DownloadSub const& sub) |
|||
{ |
|||
if (sub.asked().contains(i)) |
|||
s = h; |
|||
h++; |
|||
}); |
|||
} |
|||
unsigned dh = 360 / m_man->subCount(); |
|||
if (s == -2) |
|||
p.fillRect(QRectF(QPointF(pos) + QPointF(3 * area.width() / 8, 3 * area.height() / 8), area / 4), Qt::black); |
|||
else if (s == -1) |
|||
p.fillRect(QRectF(QPointF(pos) + QPointF(1 * area.width() / 8, 1 * area.height() / 8), area * 3 / 4), Qt::black); |
|||
else |
|||
p.fillRect(QRectF(QPointF(pos) + QPointF(1 * area.width() / 8, 1 * area.height() / 8), area * 3 / 4), QColor::fromHsv(s * dh, 64, 128)); |
|||
|
|||
pos.setX(pos.x() + n); |
|||
if (pos.x() >= rect().width() - n) |
|||
pos = QPoint(0, pos.y() + n); |
|||
} |
|||
} |
@ -0,0 +1,53 @@ |
|||
/*
|
|||
This file is part of cpp-ethereum. |
|||
|
|||
cpp-ethereum is free software: you can redistribute it and/or modify |
|||
it under the terms of the GNU General Public License as published by |
|||
the Free Software Foundation, either version 3 of the License, or |
|||
(at your option) any later version. |
|||
|
|||
cpp-ethereum is distributed in the hope that it will be useful, |
|||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
GNU General Public License for more details. |
|||
|
|||
You should have received a copy of the GNU General Public License |
|||
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
/** @file DownloadView.h
|
|||
* @author Gav Wood <i@gavwood.com> |
|||
* @date 2014 |
|||
*/ |
|||
|
|||
#pragma once |
|||
|
|||
#ifdef Q_MOC_RUN |
|||
#define BOOST_MPL_IF_HPP_INCLUDED |
|||
#endif |
|||
|
|||
#include <list> |
|||
#include <QtWidgets/QWidget> |
|||
#ifndef Q_MOC_RUN |
|||
#include <libethereum/Client.h> |
|||
#endif |
|||
|
|||
namespace dev { namespace eth { |
|||
struct MineInfo; |
|||
class DownloadMan; |
|||
}} |
|||
|
|||
class DownloadView: public QWidget |
|||
{ |
|||
Q_OBJECT |
|||
|
|||
public: |
|||
DownloadView(QWidget* _p = nullptr); |
|||
|
|||
void setDownloadMan(dev::eth::DownloadMan const* _man) { m_man = _man; } |
|||
|
|||
protected: |
|||
virtual void paintEvent(QPaintEvent*); |
|||
|
|||
private: |
|||
dev::eth::DownloadMan const* m_man = nullptr; |
|||
}; |
File diff suppressed because it is too large
@ -0,0 +1,117 @@ |
|||
cmake_policy(SET CMP0015 NEW) |
|||
|
|||
if ("${TARGET_PLATFORM}" STREQUAL "w64") |
|||
cmake_policy(SET CMP0020 NEW) |
|||
endif () |
|||
|
|||
|
|||
set(CMAKE_INCLUDE_CURRENT_DIR ON) |
|||
aux_source_directory(. SRC_LIST) |
|||
|
|||
include_directories(..) |
|||
link_directories(../libethcore) |
|||
link_directories(../libethereum) |
|||
link_directories(../libqethereum) |
|||
|
|||
# Find Qt5 for Apple and update src_list for windows |
|||
if (APPLE) |
|||
# homebrew defaults to qt4 and installs qt5 as 'keg-only' |
|||
# which places it into /usr/local/opt insteadof /usr/local. |
|||
|
|||
set(CMAKE_PREFIX_PATH /usr/local/opt/qt5) |
|||
include_directories(/usr/local/opt/qt5/include /usr/local/include) |
|||
elseif ("${TARGET_PLATFORM}" STREQUAL "w64") |
|||
set(SRC_LIST ${SRC_LIST} ../windows/qt_plugin_import.cpp) |
|||
elseif (UNIX) |
|||
set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} ";$ENV{QTDIR}/lib/cmake") |
|||
endif () |
|||
|
|||
|
|||
find_package(Qt5Widgets REQUIRED) |
|||
find_package(Qt5Gui REQUIRED) |
|||
find_package(Qt5Quick REQUIRED) |
|||
find_package(Qt5Qml REQUIRED) |
|||
find_package(Qt5Network REQUIRED) |
|||
qt5_wrap_ui(ui_Main.h Main.ui) |
|||
qt5_add_resources(RESOURCE_ADDED Resources.qrc) |
|||
|
|||
# Set name of binary and add_executable() |
|||
if (APPLE) |
|||
set(EXECUTEABLE IEthXi) |
|||
set(CMAKE_INSTALL_PREFIX ./) |
|||
set(BIN_INSTALL_DIR ".") |
|||
set(DOC_INSTALL_DIR ".") |
|||
|
|||
set(PROJECT_VERSION "${ETH_VERSION}") |
|||
set(MACOSX_BUNDLE_INFO_STRING "${PROJECT_NAME} ${PROJECT_VERSION}") |
|||
set(MACOSX_BUNDLE_BUNDLE_VERSION "${PROJECT_NAME} ${PROJECT_VERSION}") |
|||
set(MACOSX_BUNDLE_LONG_VERSION_STRING "${PROJECT_NAME} ${PROJECT_VERSION}") |
|||
set(MACOSX_BUNDLE_SHORT_VERSION_STRING "${PROJECT_VERSION}") |
|||
set(MACOSX_BUNDLE_COPYRIGHT "${PROJECT_COPYRIGHT_YEAR} ${PROJECT_VENDOR}") |
|||
set(MACOSX_BUNDLE_GUI_IDENTIFIER "${PROJECT_DOMAIN_SECOND}.${PROJECT_DOMAIN_FIRST}") |
|||
set(MACOSX_BUNDLE_BUNDLE_NAME ${EXECUTEABLE}) |
|||
include(BundleUtilities) |
|||
|
|||
add_executable(${EXECUTEABLE} MACOSX_BUNDLE Main.ui ${RESOURCE_ADDED} ${SRC_LIST}) |
|||
else () |
|||
set(EXECUTEABLE iethxi) |
|||
add_executable(${EXECUTEABLE} Main.ui ${RESOURCE_ADDED} ${SRC_LIST}) |
|||
endif () |
|||
|
|||
qt5_use_modules(${EXECUTEABLE} Core Gui Widgets Network Quick Qml) |
|||
target_link_libraries(${EXECUTEABLE} qethereum ethereum secp256k1 ${CRYPTOPP_LS}) |
|||
|
|||
if (APPLE) |
|||
if (${ADDFRAMEWORKS}) |
|||
set_target_properties(${EXECUTEABLE} PROPERTIES MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/EthereumMacOSXBundleInfo.plist.in") |
|||
endif () |
|||
|
|||
SET_SOURCE_FILES_PROPERTIES(${EXECUTEABLE} PROPERTIES MACOSX_PACKAGE_LOCATION MacOS) |
|||
|
|||
# This is a workaround for when the build-type defaults to Debug, and when a multi-config generator like xcode is used, where the type |
|||
# will not be set but defaults to release. |
|||
set(generator_lowercase "${CMAKE_GENERATOR}") |
|||
string(TOLOWER "${CMAKE_GENERATOR}" generator_lowercase) |
|||
if ("${generator_lowercase}" STREQUAL "xcode") |
|||
# TODO: Not sure how to resolve this. Possibly \${TARGET_BUILD_DIR} |
|||
set(binary_build_dir "${CMAKE_CURRENT_BINARY_DIR}/Debug") |
|||
else () |
|||
set(binary_build_dir "${CMAKE_CURRENT_BINARY_DIR}") |
|||
endif () |
|||
|
|||
set(APPS ${binary_build_dir}/${EXECUTEABLE}.app) |
|||
|
|||
# This tool and the next will automatically looked at the linked libraries in order to determine what dependencies are required. Thus, target_link_libaries only needs to add ethereum and secp256k1 (above) |
|||
install(CODE " |
|||
include(BundleUtilities) |
|||
set(BU_CHMOD_BUNDLE_ITEMS 1) |
|||
fixup_bundle(\"${APPS}\" \"${BUNDLELIBS}\" \"../libqethereum ../libethereum ../secp256k1\") |
|||
" COMPONENT RUNTIME ) |
|||
|
|||
if (${ADDFRAMEWORKS}) |
|||
add_custom_target(addframeworks ALL |
|||
COMMAND /usr/local/opt/qt5/bin/macdeployqt ${binary_build_dir}/${EXECUTEABLE}.app |
|||
WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} |
|||
DEPENDS ${PROJECT_NAME} |
|||
) |
|||
endif () |
|||
|
|||
elseif ("${TARGET_PLATFORM}" STREQUAL "w64") |
|||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-keep-inline-dllexport -static-libgcc -static-libstdc++ -static") |
|||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-s -Wl,-subsystem,windows -mthreads -L/usr/x86_64-w64-mingw32/plugins/platforms") |
|||
target_link_libraries(${EXECUTEABLE} gcc) |
|||
target_link_libraries(${EXECUTEABLE} mingw32 qtmain mswsock iphlpapi qwindows shlwapi Qt5PlatformSupport gdi32 comdlg32 oleaut32 imm32 winmm ole32 uuid ws2_32) |
|||
target_link_libraries(${EXECUTEABLE} boost_system-mt-s) |
|||
target_link_libraries(${EXECUTEABLE} boost_filesystem-mt-s) |
|||
target_link_libraries(${EXECUTEABLE} boost_thread_win32-mt-s) |
|||
target_link_libraries(${EXECUTEABLE} Qt5PlatformSupport) |
|||
set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS) |
|||
elseif (UNIX) |
|||
else () |
|||
target_link_libraries(${EXECUTEABLE} boost_system) |
|||
target_link_libraries(${EXECUTEABLE} boost_filesystem) |
|||
find_package(Threads REQUIRED) |
|||
target_link_libraries(${EXECUTEABLE} ${CMAKE_THREAD_LIBS_INIT}) |
|||
install( TARGETS ${EXECUTEABLE} RUNTIME DESTINATION bin ) |
|||
endif () |
|||
|
@ -0,0 +1,38 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> |
|||
<plist version="1.0"> |
|||
<dict> |
|||
<key>CFBundleDevelopmentRegion</key> |
|||
<string>English</string> |
|||
<key>CFBundleExecutable</key> |
|||
<string>${MACOSX_BUNDLE_EXECUTABLE_NAME}</string> |
|||
<key>CFBundleGetInfoString</key> |
|||
<string>${MACOSX_BUNDLE_INFO_STRING}</string> |
|||
<key>CFBundleIconFile</key> |
|||
<string>${MACOSX_BUNDLE_ICON_FILE}</string> |
|||
<key>CFBundleIdentifier</key> |
|||
<string>${MACOSX_BUNDLE_GUI_IDENTIFIER}</string> |
|||
<key>CFBundleInfoDictionaryVersion</key> |
|||
<string>6.0</string> |
|||
<key>CFBundleLongVersionString</key> |
|||
<string>${MACOSX_BUNDLE_LONG_VERSION_STRING}</string> |
|||
<key>CFBundleName</key> |
|||
<string>${MACOSX_BUNDLE_BUNDLE_NAME}</string> |
|||
<key>CFBundlePackageType</key> |
|||
<string>APPL</string> |
|||
<key>CFBundleShortVersionString</key> |
|||
<string>${MACOSX_BUNDLE_SHORT_VERSION_STRING}</string> |
|||
<key>CFBundleSignature</key> |
|||
<string>????</string> |
|||
<key>CFBundleVersion</key> |
|||
<string>${MACOSX_BUNDLE_BUNDLE_VERSION}</string> |
|||
<key>CSResourcesFileMapped</key> |
|||
<true/> |
|||
<key>LSRequiresCarbon</key> |
|||
<true/> |
|||
<key>NSHumanReadableCopyright</key> |
|||
<string>${MACOSX_BUNDLE_COPYRIGHT}</string> |
|||
<key>NSHighResolutionCapable</key> |
|||
<true/> |
|||
</dict> |
|||
</plist> |
@ -0,0 +1,168 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<ui version="4.0"> |
|||
<class>Main</class> |
|||
<widget class="QMainWindow" name="Main"> |
|||
<property name="geometry"> |
|||
<rect> |
|||
<x>0</x> |
|||
<y>0</y> |
|||
<width>562</width> |
|||
<height>488</height> |
|||
</rect> |
|||
</property> |
|||
<property name="windowTitle"> |
|||
<string>Walleth</string> |
|||
</property> |
|||
<property name="dockNestingEnabled"> |
|||
<bool>true</bool> |
|||
</property> |
|||
<property name="dockOptions"> |
|||
<set>QMainWindow::AllowNestedDocks|QMainWindow::AllowTabbedDocks|QMainWindow::VerticalTabs</set> |
|||
</property> |
|||
<property name="sizeGripEnabled" stdset="0"> |
|||
<bool>true</bool> |
|||
</property> |
|||
<widget class="QWidget" name="centralwidget"> |
|||
<layout class="QVBoxLayout" name="verticalLayout"> |
|||
<property name="leftMargin"> |
|||
<number>0</number> |
|||
</property> |
|||
<property name="topMargin"> |
|||
<number>0</number> |
|||
</property> |
|||
<property name="rightMargin"> |
|||
<number>0</number> |
|||
</property> |
|||
<property name="bottomMargin"> |
|||
<number>0</number> |
|||
</property> |
|||
<item> |
|||
<layout class="QHBoxLayout" name="fullDisplay"> |
|||
<item> |
|||
<widget class="QLabel" name="balance"> |
|||
<property name="text"> |
|||
<string>0 wei</string> |
|||
</property> |
|||
</widget> |
|||
</item> |
|||
<item> |
|||
<widget class="QLabel" name="peerCount"> |
|||
<property name="text"> |
|||
<string>0 peers</string> |
|||
</property> |
|||
</widget> |
|||
</item> |
|||
<item> |
|||
<widget class="QLabel" name="blockCount"> |
|||
<property name="text"> |
|||
<string>1 block</string> |
|||
</property> |
|||
</widget> |
|||
</item> |
|||
</layout> |
|||
</item> |
|||
</layout> |
|||
</widget> |
|||
<widget class="QMenuBar" name="menubar"> |
|||
<property name="geometry"> |
|||
<rect> |
|||
<x>0</x> |
|||
<y>0</y> |
|||
<width>562</width> |
|||
<height>25</height> |
|||
</rect> |
|||
</property> |
|||
<widget class="QMenu" name="menu_File"> |
|||
<property name="title"> |
|||
<string>&File</string> |
|||
</property> |
|||
<addaction name="quit"/> |
|||
</widget> |
|||
<widget class="QMenu" name="menu_Network"> |
|||
<property name="title"> |
|||
<string>&Network</string> |
|||
</property> |
|||
<addaction name="upnp"/> |
|||
<addaction name="net"/> |
|||
<addaction name="connect"/> |
|||
</widget> |
|||
<widget class="QMenu" name="menu_Tools"> |
|||
<property name="title"> |
|||
<string>T&ools</string> |
|||
</property> |
|||
<addaction name="mine"/> |
|||
<addaction name="create"/> |
|||
<addaction name="preview"/> |
|||
</widget> |
|||
<widget class="QMenu" name="menu_Help"> |
|||
<property name="title"> |
|||
<string>&Help</string> |
|||
</property> |
|||
<addaction name="about"/> |
|||
</widget> |
|||
<addaction name="menu_File"/> |
|||
<addaction name="menu_Network"/> |
|||
<addaction name="menu_Tools"/> |
|||
<addaction name="menu_Help"/> |
|||
</widget> |
|||
<widget class="QStatusBar" name="statusbar"/> |
|||
<action name="quit"> |
|||
<property name="text"> |
|||
<string>&Quit</string> |
|||
</property> |
|||
</action> |
|||
<action name="upnp"> |
|||
<property name="checkable"> |
|||
<bool>true</bool> |
|||
</property> |
|||
<property name="checked"> |
|||
<bool>true</bool> |
|||
</property> |
|||
<property name="text"> |
|||
<string>Use &UPnP</string> |
|||
</property> |
|||
</action> |
|||
<action name="connect"> |
|||
<property name="text"> |
|||
<string>&Connect to Peer...</string> |
|||
</property> |
|||
</action> |
|||
<action name="net"> |
|||
<property name="checkable"> |
|||
<bool>true</bool> |
|||
</property> |
|||
<property name="text"> |
|||
<string>Enable &Network</string> |
|||
</property> |
|||
</action> |
|||
<action name="mine"> |
|||
<property name="checkable"> |
|||
<bool>true</bool> |
|||
</property> |
|||
<property name="text"> |
|||
<string>&Mine</string> |
|||
</property> |
|||
</action> |
|||
<action name="create"> |
|||
<property name="text"> |
|||
<string>&New Address</string> |
|||
</property> |
|||
</action> |
|||
<action name="about"> |
|||
<property name="text"> |
|||
<string>&About...</string> |
|||
</property> |
|||
</action> |
|||
<action name="preview"> |
|||
<property name="checkable"> |
|||
<bool>true</bool> |
|||
</property> |
|||
<property name="text"> |
|||
<string>&Preview</string> |
|||
</property> |
|||
</action> |
|||
</widget> |
|||
<layoutdefault spacing="6" margin="11"/> |
|||
<resources/> |
|||
<connections/> |
|||
</ui> |
@ -0,0 +1,59 @@ |
|||
#include <QtNetwork/QNetworkReply> |
|||
#include <QtQuick/QQuickView> |
|||
#include <QtQml/QQmlContext> |
|||
#include <QtQml/QQmlEngine> |
|||
#include <QtQml/QtQml> |
|||
#include <QtWidgets/QMessageBox> |
|||
#include <QtWidgets/QInputDialog> |
|||
#include <QtGui/QClipboard> |
|||
#include <QtCore/QtCore> |
|||
#include <libethcore/FileSystem.h> |
|||
#include <libethcore/Dagger.h> |
|||
#include <libevmface/Instruction.h> |
|||
#include <libethereum/Client.h> |
|||
#include <libethereum/EthereumHost.h> |
|||
#include "BuildInfo.h" |
|||
#include "MainWin.h" |
|||
#include "ui_Main.h" |
|||
using namespace std; |
|||
using namespace eth; |
|||
|
|||
Main::Main(QWidget *parent) : |
|||
QObject(parent) |
|||
{ |
|||
/* qRegisterMetaType<eth::u256>("eth::u256");
|
|||
qRegisterMetaType<eth::KeyPair>("eth::KeyPair"); |
|||
qRegisterMetaType<eth::Secret>("eth::Secret"); |
|||
qRegisterMetaType<eth::Address>("eth::Address"); |
|||
qRegisterMetaType<QmlAccount*>("QmlAccount*"); |
|||
qRegisterMetaType<QmlEthereum*>("QmlEthereum*"); |
|||
|
|||
qmlRegisterType<QmlEthereum>("org.ethereum", 1, 0, "Ethereum"); |
|||
qmlRegisterType<QmlAccount>("org.ethereum", 1, 0, "Account"); |
|||
qmlRegisterSingletonType<QmlU256Helper>("org.ethereum", 1, 0, "Balance", QmlEthereum::constructU256Helper); |
|||
qmlRegisterSingletonType<QmlKeyHelper>("org.ethereum", 1, 0, "Key", QmlEthereum::constructKeyHelper); |
|||
*/ |
|||
/*
|
|||
ui->librariesView->setModel(m_libraryMan); |
|||
ui->graphsView->setModel(m_graphMan); |
|||
*/ |
|||
|
|||
|
|||
|
|||
|
|||
// QQmlContext* context = m_view->rootContext();
|
|||
// context->setContextProperty("u256", new U256Helper(this));
|
|||
} |
|||
|
|||
Main::~Main() |
|||
{ |
|||
} |
|||
|
|||
// extra bits needed to link on VS
|
|||
#ifdef _MSC_VER |
|||
|
|||
// include moc file, ofuscated to hide from automoc
|
|||
#include\ |
|||
"moc_MainWin.cpp" |
|||
|
|||
#endif |
@ -0,0 +1,18 @@ |
|||
#ifndef MAIN_H |
|||
#define MAIN_H |
|||
|
|||
#include <QtQml/QQmlApplicationEngine> |
|||
|
|||
class Main: public QObject |
|||
{ |
|||
Q_OBJECT |
|||
|
|||
public: |
|||
explicit Main(QWidget *parent = 0); |
|||
~Main(); |
|||
|
|||
private: |
|||
QQmlApplicationEngine* m_view; |
|||
}; |
|||
|
|||
#endif // MAIN_H
|
@ -0,0 +1,5 @@ |
|||
<RCC> |
|||
<qresource prefix="/"> |
|||
<file>Simple.qml</file> |
|||
</qresource> |
|||
</RCC> |
@ -0,0 +1,9 @@ |
|||
import QtQuick.Controls 1.1 |
|||
|
|||
ApplicationWindow { |
|||
title: "My App" |
|||
Button { |
|||
text: "Push Me" |
|||
anchors.centerIn: parent |
|||
} |
|||
} |
@ -0,0 +1,9 @@ |
|||
#include <QtQml/QQmlApplicationEngine> |
|||
#include <QtWidgets/QApplication> |
|||
|
|||
int main(int argc, char *argv[]) |
|||
{ |
|||
QApplication a(argc, argv); |
|||
QQmlApplicationEngine app(QUrl("qrc:/Simple.qml")); |
|||
return a.exec(); |
|||
} |
@ -0,0 +1,282 @@ |
|||
/*
|
|||
This file is part of cpp-ethereum. |
|||
|
|||
cpp-ethereum is free software: you can redistribute it and/or modify |
|||
it under the terms of the GNU General Public License as published by |
|||
the Free Software Foundation, either version 3 of the License, or |
|||
(at your option) any later version. |
|||
|
|||
cpp-ethereum is distributed in the hope that it will be useful, |
|||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
GNU General Public License for more details. |
|||
|
|||
You should have received a copy of the GNU General Public License |
|||
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
/** @file Common.cpp
|
|||
* @author Gav Wood <i@gavwood.com> |
|||
* @date 2014 |
|||
*/ |
|||
|
|||
#include "CommonData.h" |
|||
|
|||
#include <random> |
|||
#include "Exceptions.h" |
|||
using namespace std; |
|||
using namespace dev; |
|||
|
|||
std::string dev::escaped(std::string const& _s, bool _all) |
|||
{ |
|||
std::string ret; |
|||
ret.reserve(_s.size()); |
|||
ret.push_back('"'); |
|||
for (auto i: _s) |
|||
if (i == '"' && !_all) |
|||
ret += "\\\""; |
|||
else if (i == '\\' && !_all) |
|||
ret += "\\\\"; |
|||
else if (i < ' ' || _all) |
|||
{ |
|||
ret += "\\x"; |
|||
ret.push_back("0123456789abcdef"[(uint8_t)i / 16]); |
|||
ret.push_back("0123456789abcdef"[(uint8_t)i % 16]); |
|||
} |
|||
else |
|||
ret.push_back(i); |
|||
ret.push_back('"'); |
|||
return ret; |
|||
} |
|||
|
|||
std::string dev::randomWord() |
|||
{ |
|||
static std::mt19937_64 s_eng(0); |
|||
std::string ret(std::uniform_int_distribution<int>(1, 5)(s_eng), ' '); |
|||
char const n[] = "qwertyuiop";//asdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890";
|
|||
std::uniform_int_distribution<int> d(0, sizeof(n) - 2); |
|||
for (char& c: ret) |
|||
c = n[d(s_eng)]; |
|||
return ret; |
|||
} |
|||
|
|||
int dev::fromHex(char _i) |
|||
{ |
|||
if (_i >= '0' && _i <= '9') |
|||
return _i - '0'; |
|||
if (_i >= 'a' && _i <= 'f') |
|||
return _i - 'a' + 10; |
|||
if (_i >= 'A' && _i <= 'F') |
|||
return _i - 'A' + 10; |
|||
throw BadHexCharacter(); |
|||
} |
|||
|
|||
bytes dev::fromHex(std::string const& _s) |
|||
{ |
|||
unsigned s = (_s[0] == '0' && _s[1] == 'x') ? 2 : 0; |
|||
std::vector<uint8_t> ret; |
|||
ret.reserve((_s.size() - s + 1) / 2); |
|||
|
|||
if (_s.size() % 2) |
|||
try |
|||
{ |
|||
ret.push_back(fromHex(_s[s++])); |
|||
} |
|||
catch (...){ ret.push_back(0); } |
|||
for (unsigned i = s; i < _s.size(); i += 2) |
|||
try |
|||
{ |
|||
ret.push_back((byte)(fromHex(_s[i]) * 16 + fromHex(_s[i + 1]))); |
|||
} |
|||
catch (...){ ret.push_back(0); } |
|||
return ret; |
|||
} |
|||
|
|||
bytes dev::asNibbles(std::string const& _s) |
|||
{ |
|||
std::vector<uint8_t> ret; |
|||
ret.reserve(_s.size() * 2); |
|||
for (auto i: _s) |
|||
{ |
|||
ret.push_back(i / 16); |
|||
ret.push_back(i % 16); |
|||
} |
|||
return ret; |
|||
} |
|||
|
|||
#if 0 |
|||
|
|||
/* Following code is copyright 2012-2014 Luke Dashjr
|
|||
* |
|||
* This program is free software; you can redistribute it and/or modify it |
|||
* under the terms of the standard MIT license. See COPYING for more details. |
|||
*/ |
|||
|
|||
#include <cstdbool> |
|||
#include <cstddef> |
|||
#include <cstdint> |
|||
#include <cstring> |
|||
|
|||
static const int8_t b58digits_map[] = { |
|||
-1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1, |
|||
-1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1, |
|||
-1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1, |
|||
-1, 0, 1, 2, 3, 4, 5, 6, 7, 8,-1,-1,-1,-1,-1,-1, |
|||
-1, 9,10,11,12,13,14,15, 16,-1,17,18,19,20,21,-1, |
|||
22,23,24,25,26,27,28,29, 30,31,32,-1,-1,-1,-1,-1, |
|||
-1,33,34,35,36,37,38,39, 40,41,42,43,-1,44,45,46, |
|||
47,48,49,50,51,52,53,54, 55,56,57,-1,-1,-1,-1,-1, |
|||
}; |
|||
|
|||
bool b58tobin(void *bin, size_t *binszp, const char *b58, size_t b58sz) |
|||
{ |
|||
size_t binsz = *binszp; |
|||
const unsigned char *b58u = (void*)b58; |
|||
unsigned char *binu = bin; |
|||
size_t outisz = (binsz + 3) / 4; |
|||
uint32_t outi[outisz]; |
|||
uint64_t t; |
|||
uint32_t c; |
|||
size_t i, j; |
|||
uint8_t bytesleft = binsz % 4; |
|||
uint32_t zeromask = bytesleft ? (0xffffffff << (bytesleft * 8)) : 0; |
|||
unsigned zerocount = 0; |
|||
|
|||
if (!b58sz) |
|||
b58sz = strlen(b58); |
|||
|
|||
memset(outi, 0, outisz * sizeof(*outi)); |
|||
|
|||
// Leading zeros, just count
|
|||
for (i = 0; i < b58sz && !b58digits_map[b58u[i]]; ++i) |
|||
++zerocount; |
|||
|
|||
for ( ; i < b58sz; ++i) |
|||
{ |
|||
if (b58u[i] & 0x80) |
|||
// High-bit set on invalid digit
|
|||
return false; |
|||
if (b58digits_map[b58u[i]] == -1) |
|||
// Invalid base58 digit
|
|||
return false; |
|||
c = (unsigned)b58digits_map[b58u[i]]; |
|||
for (j = outisz; j--; ) |
|||
{ |
|||
t = ((uint64_t)outi[j]) * 58 + c; |
|||
c = (t & 0x3f00000000) >> 32; |
|||
outi[j] = t & 0xffffffff; |
|||
} |
|||
if (c) |
|||
// Output number too big (carry to the next int32)
|
|||
return false; |
|||
if (outi[0] & zeromask) |
|||
// Output number too big (last int32 filled too far)
|
|||
return false; |
|||
} |
|||
|
|||
j = 0; |
|||
switch (bytesleft) { |
|||
case 3: |
|||
*(binu++) = (outi[0] & 0xff0000) >> 16; |
|||
case 2: |
|||
*(binu++) = (outi[0] & 0xff00) >> 8; |
|||
case 1: |
|||
*(binu++) = (outi[0] & 0xff); |
|||
++j; |
|||
default: |
|||
break; |
|||
} |
|||
|
|||
for (; j < outisz; ++j) |
|||
{ |
|||
*(binu++) = (outi[j] >> 0x18) & 0xff; |
|||
*(binu++) = (outi[j] >> 0x10) & 0xff; |
|||
*(binu++) = (outi[j] >> 8) & 0xff; |
|||
*(binu++) = (outi[j] >> 0) & 0xff; |
|||
} |
|||
|
|||
// Count canonical base58 byte count
|
|||
binu = bin; |
|||
for (i = 0; i < binsz; ++i) |
|||
{ |
|||
if (binu[i]) |
|||
break; |
|||
--*binszp; |
|||
} |
|||
*binszp += zerocount; |
|||
|
|||
return true; |
|||
} |
|||
|
|||
static |
|||
bool my_dblsha256(void *hash, const void *data, size_t datasz) |
|||
{ |
|||
uint8_t buf[0x20]; |
|||
return b58_sha256_impl(buf, data, datasz) && b58_sha256_impl(hash, buf, sizeof(buf)); |
|||
} |
|||
|
|||
int b58check(const void *bin, size_t binsz, const char *base58str, size_t b58sz) |
|||
{ |
|||
unsigned char buf[32]; |
|||
const uint8_t *binc = bin; |
|||
unsigned i; |
|||
if (binsz < 4) |
|||
return -4; |
|||
if (!my_dblsha256(buf, bin, binsz - 4)) |
|||
return -2; |
|||
if (memcmp(&binc[binsz - 4], buf, 4)) |
|||
return -1; |
|||
|
|||
// Check number of zeros is correct AFTER verifying checksum (to avoid possibility of accessing base58str beyond the end)
|
|||
for (i = 0; binc[i] == '\0' && base58str[i] == '1'; ++i) |
|||
{} // Just finding the end of zeros, nothing to do in loop
|
|||
if (binc[i] == '\0' || base58str[i] == '1') |
|||
return -3; |
|||
|
|||
return binc[0]; |
|||
} |
|||
|
|||
static const char b58digits_ordered[] = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"; |
|||
|
|||
bool b58enc(char *b58, size_t *b58sz, const void *data, size_t binsz) |
|||
{ |
|||
const uint8_t *bin = data; |
|||
int carry; |
|||
size_t i, j, high, zcount = 0; |
|||
size_t size; |
|||
|
|||
while (zcount < binsz && !bin[zcount]) |
|||
++zcount; |
|||
|
|||
size = (binsz - zcount) * 138 / 100 + 1; |
|||
uint8_t buf[size]; |
|||
memset(buf, 0, size); |
|||
|
|||
for (i = zcount, high = size - 1; i < binsz; ++i, high = j) |
|||
{ |
|||
for (carry = bin[i], j = size - 1; (j > high) || carry; --j) |
|||
{ |
|||
carry += 256 * buf[j]; |
|||
buf[j] = carry % 58; |
|||
carry /= 58; |
|||
} |
|||
} |
|||
|
|||
for (j = 0; j < size && !buf[j]; ++j); |
|||
|
|||
if (*b58sz <= zcount + size - j) |
|||
{ |
|||
*b58sz = zcount + size - j + 1; |
|||
return false; |
|||
} |
|||
|
|||
if (zcount) |
|||
memset(b58, '1', zcount); |
|||
for (i = zcount; j < size; ++i, ++j) |
|||
b58[i] = b58digits_ordered[buf[j]]; |
|||
b58[i] = '\0'; |
|||
*b58sz = i + 1; |
|||
|
|||
return true; |
|||
} |
|||
|
|||
#endif |
@ -0,0 +1,28 @@ |
|||
/*
|
|||
This file is part of cpp-ethereum. |
|||
|
|||
cpp-ethereum is free software: you can redistribute it and/or modify |
|||
it under the terms of the GNU General Public License as published by |
|||
the Free Software Foundation, either version 3 of the License, or |
|||
(at your option) any later version. |
|||
|
|||
cpp-ethereum is distributed in the hope that it will be useful, |
|||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
GNU General Public License for more details. |
|||
|
|||
You should have received a copy of the GNU General Public License |
|||
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
/** @file FixedHash.cpp
|
|||
* @author Gav Wood <i@gavwood.com> |
|||
* @date 2014 |
|||
*/ |
|||
|
|||
#include <ctime> |
|||
#include "FixedHash.h" |
|||
|
|||
using namespace std; |
|||
using namespace dev; |
|||
|
|||
std::mt19937_64 dev::s_fixedHashEngine(time(0)); |
@ -0,0 +1,41 @@ |
|||
/*
|
|||
This file is part of cpp-ethereum. |
|||
|
|||
cpp-ethereum is free software: you can redistribute it and/or modify |
|||
it under the terms of the GNU General Public License as published by |
|||
the Free Software Foundation, either version 3 of the License, or |
|||
(at your option) any later version. |
|||
|
|||
cpp-ethereum is distributed in the hope that it will be useful, |
|||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
GNU General Public License for more details. |
|||
|
|||
You should have received a copy of the GNU General Public License |
|||
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
/** @file Guards.h
|
|||
* @author Gav Wood <i@gavwood.com> |
|||
* @date 2014 |
|||
*/ |
|||
|
|||
#pragma once |
|||
|
|||
#include <mutex> |
|||
#include <boost/thread.hpp> |
|||
|
|||
namespace dev |
|||
{ |
|||
|
|||
using Mutex = std::mutex; |
|||
using RecursiveMutex = std::recursive_mutex; |
|||
using SharedMutex = boost::shared_mutex; |
|||
|
|||
using Guard = std::lock_guard<std::mutex>; |
|||
using RecursiveGuard = std::lock_guard<std::recursive_mutex>; |
|||
using ReadGuard = boost::shared_lock<boost::shared_mutex>; |
|||
using UpgradableGuard = boost::upgrade_lock<boost::shared_mutex>; |
|||
using UpgradeGuard = boost::upgrade_to_unique_lock<boost::shared_mutex>; |
|||
using WriteGuard = boost::unique_lock<boost::shared_mutex>; |
|||
|
|||
} |
@ -0,0 +1,22 @@ |
|||
/*
|
|||
This file is part of cpp-ethereum. |
|||
|
|||
cpp-ethereum is free software: you can redistribute it and/or modify |
|||
it under the terms of the GNU General Public License as published by |
|||
the Free Software Foundation, either version 3 of the License, or |
|||
(at your option) any later version. |
|||
|
|||
cpp-ethereum is distributed in the hope that it will be useful, |
|||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
GNU General Public License for more details. |
|||
|
|||
You should have received a copy of the GNU General Public License |
|||
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
/** @file RangeMask.cpp
|
|||
* @author Gav Wood <i@gavwood.com> |
|||
* @date 2014 |
|||
*/ |
|||
|
|||
#include "RangeMask.h" |
@ -0,0 +1,212 @@ |
|||
/*
|
|||
This file is part of cpp-ethereum. |
|||
|
|||
cpp-ethereum is free software: you can redistribute it and/or modify |
|||
it under the terms of the GNU General Public License as published by |
|||
the Free Software Foundation, either version 3 of the License, or |
|||
(at your option) any later version. |
|||
|
|||
cpp-ethereum is distributed in the hope that it will be useful, |
|||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
GNU General Public License for more details. |
|||
|
|||
You should have received a copy of the GNU General Public License |
|||
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
/** @file EthereumHost.h
|
|||
* @author Gav Wood <i@gavwood.com> |
|||
* @date 2014 |
|||
*/ |
|||
|
|||
#pragma once |
|||
|
|||
#include <map> |
|||
#include <utility> |
|||
#include <vector> |
|||
#include <iostream> |
|||
|
|||
namespace dev |
|||
{ |
|||
|
|||
class RLPStream; |
|||
|
|||
using UnsignedRange = std::pair<unsigned, unsigned>; |
|||
using UnsignedRanges = std::vector<UnsignedRange>; |
|||
|
|||
template <class T> |
|||
class RangeMask |
|||
{ |
|||
template <class U> friend std::ostream& operator<<(std::ostream& _out, RangeMask<U> const& _r); |
|||
|
|||
public: |
|||
using Range = std::pair<T, T>; |
|||
using Ranges = std::vector<Range>; |
|||
|
|||
RangeMask() {} |
|||
RangeMask(T _begin, T _end): m_all(_begin, _end) {} |
|||
RangeMask(Range const& _c): m_all(_c) {} |
|||
|
|||
RangeMask operator+(RangeMask const& _m) const { return RangeMask(*this) += _m; } |
|||
|
|||
RangeMask lowest(T _items) const |
|||
{ |
|||
RangeMask ret(m_all); |
|||
for (auto i = m_ranges.begin(); i != m_ranges.end() && _items; ++i) |
|||
_items -= (ret.m_ranges[i->first] = std::min(i->first + _items, i->second)) - i->first; |
|||
return ret; |
|||
} |
|||
|
|||
RangeMask operator~() const |
|||
{ |
|||
RangeMask ret(m_all); |
|||
T last = m_all.first; |
|||
for (auto i: m_ranges) |
|||
{ |
|||
if (i.first != last) |
|||
ret.m_ranges[last] = i.first; |
|||
last = i.second; |
|||
} |
|||
if (last != m_all.second) |
|||
ret.m_ranges[last] = m_all.second; |
|||
return ret; |
|||
} |
|||
|
|||
RangeMask& operator+=(RangeMask const& _m) |
|||
{ |
|||
for (auto const& i: _m.m_ranges) |
|||
operator+=(i); |
|||
return *this; |
|||
} |
|||
RangeMask& operator+=(UnsignedRange const& _m) |
|||
{ |
|||
for (auto i = _m.first; i < _m.second;) |
|||
{ |
|||
// for each number, we find the element equal or next lower. this, if any, must contain the value.
|
|||
auto uit = m_ranges.upper_bound(i); |
|||
auto it = uit == m_ranges.begin() ? m_ranges.end() : std::prev(uit); |
|||
if (it == m_ranges.end() || it->second < i) |
|||
// lower range is too low to merge.
|
|||
// if the next higher range is too high.
|
|||
if (uit == m_ranges.end() || uit->first > _m.second) |
|||
{ |
|||
// just create a new range
|
|||
m_ranges[i] = _m.second; |
|||
break; |
|||
} |
|||
else |
|||
{ |
|||
if (uit->first == i) |
|||
// move i to end of range
|
|||
i = uit->second; |
|||
else |
|||
{ |
|||
// merge with the next higher range
|
|||
// move i to end of range
|
|||
i = m_ranges[i] = uit->second; |
|||
i = uit->second; |
|||
m_ranges.erase(uit); |
|||
} |
|||
} |
|||
else if (it->second == i) |
|||
{ |
|||
// if the next higher range is too high.
|
|||
if (uit == m_ranges.end() || uit->first > _m.second) |
|||
{ |
|||
// merge with the next lower range
|
|||
m_ranges[it->first] = _m.second; |
|||
break; |
|||
} |
|||
else |
|||
{ |
|||
// merge with both next lower & next higher.
|
|||
i = m_ranges[it->first] = uit->second; |
|||
m_ranges.erase(uit); |
|||
} |
|||
} |
|||
else |
|||
i = it->second; |
|||
} |
|||
return *this; |
|||
} |
|||
|
|||
RangeMask& operator+=(T _i) |
|||
{ |
|||
return operator+=(Range(_i, _i + 1)); |
|||
} |
|||
|
|||
bool contains(T _i) const |
|||
{ |
|||
auto it = m_ranges.upper_bound(_i); |
|||
if (it == m_ranges.begin()) |
|||
return false; |
|||
return (--it)->second > _i; |
|||
} |
|||
|
|||
bool empty() const |
|||
{ |
|||
return m_ranges.empty(); |
|||
} |
|||
|
|||
bool full() const |
|||
{ |
|||
return m_ranges.size() == 1 && m_ranges.begin()->first == m_all.first && m_ranges.begin()->second == m_all.second; |
|||
} |
|||
|
|||
void clear() |
|||
{ |
|||
m_ranges.clear(); |
|||
} |
|||
|
|||
std::pair<T, T> const& all() const { return m_all; } |
|||
|
|||
class const_iterator |
|||
{ |
|||
friend class RangeMask; |
|||
|
|||
public: |
|||
const_iterator() {} |
|||
|
|||
T operator*() const { return m_value; } |
|||
const_iterator& operator++() { if (m_owner) m_value = m_owner->next(m_value); return *this; } |
|||
const_iterator operator++(int) { auto ret = *this; if (m_owner) m_value = m_owner->next(m_value); return ret; } |
|||
|
|||
bool operator==(const_iterator const& _i) const { return m_owner == _i.m_owner && m_value == _i.m_value; } |
|||
bool operator!=(const_iterator const& _i) const { return !operator==(_i); } |
|||
bool operator<(const_iterator const& _i) const { return m_value < _i.m_value; } |
|||
|
|||
private: |
|||
const_iterator(RangeMask const& _m, bool _end): m_owner(&_m), m_value(_m.m_ranges.empty() || _end ? _m.m_all.second : _m.m_ranges.begin()->first) {} |
|||
|
|||
RangeMask const* m_owner = nullptr; |
|||
T m_value = 0; |
|||
}; |
|||
|
|||
const_iterator begin() const { return const_iterator(*this, false); } |
|||
const_iterator end() const { return const_iterator(*this, true); } |
|||
T next(T _t) const |
|||
{ |
|||
_t++; |
|||
// find next item in range at least _t
|
|||
auto uit = m_ranges.upper_bound(_t); // > _t
|
|||
auto it = uit == m_ranges.begin() ? m_ranges.end() : std::prev(uit); |
|||
if (it != m_ranges.end() && it->first <= _t && it->second > _t) |
|||
return _t; |
|||
return uit == m_ranges.end() ? m_all.second : uit->first; |
|||
} |
|||
|
|||
private: |
|||
UnsignedRange m_all; |
|||
std::map<T, T> m_ranges; |
|||
}; |
|||
|
|||
template <class T> inline std::ostream& operator<<(std::ostream& _out, RangeMask<T> const& _r) |
|||
{ |
|||
_out << _r.m_all.first << "{ "; |
|||
for (auto const& i: _r.m_ranges) |
|||
_out << "[" << i.first << ", " << i.second << ") "; |
|||
_out << "}" << _r.m_all.second; |
|||
return _out; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,63 @@ |
|||
/*
|
|||
This file is part of cpp-ethereum. |
|||
|
|||
cpp-ethereum is free software: you can redistribute it and/or modify |
|||
it under the terms of the GNU General Public License as published by |
|||
the Free Software Foundation, either version 3 of the License, or |
|||
(at your option) any later version. |
|||
|
|||
cpp-ethereum is distributed in the hope that it will be useful, |
|||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
GNU General Public License for more details. |
|||
|
|||
You should have received a copy of the GNU General Public License |
|||
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
/** @file Worker.cpp
|
|||
* @author Gav Wood <i@gavwood.com> |
|||
* @date 2014 |
|||
*/ |
|||
|
|||
#include "Worker.h" |
|||
|
|||
#include <chrono> |
|||
#include <thread> |
|||
#include "Log.h" |
|||
using namespace std; |
|||
using namespace dev; |
|||
|
|||
void Worker::startWorking() |
|||
{ |
|||
cdebug << "startWorking for thread" << m_name; |
|||
Guard l(x_work); |
|||
if (m_work) |
|||
return; |
|||
cdebug << "Spawning" << m_name; |
|||
m_stop = false; |
|||
m_work.reset(new thread([&]() |
|||
{ |
|||
setThreadName(m_name.c_str()); |
|||
while (!m_stop) |
|||
{ |
|||
this_thread::sleep_for(chrono::milliseconds(30)); |
|||
doWork(); |
|||
} |
|||
cdebug << "Finishing up worker thread"; |
|||
doneWorking(); |
|||
})); |
|||
} |
|||
|
|||
void Worker::stopWorking() |
|||
{ |
|||
cdebug << "stopWorking for thread" << m_name; |
|||
Guard l(x_work); |
|||
if (!m_work) |
|||
return; |
|||
cdebug << "Stopping" << m_name; |
|||
m_stop = true; |
|||
m_work->join(); |
|||
m_work.reset(); |
|||
cdebug << "Stopped" << m_name; |
|||
} |
|||
|
@ -0,0 +1,59 @@ |
|||
/*
|
|||
This file is part of cpp-ethereum. |
|||
|
|||
cpp-ethereum is free software: you can redistribute it and/or modify |
|||
it under the terms of the GNU General Public License as published by |
|||
the Free Software Foundation, either version 3 of the License, or |
|||
(at your option) any later version. |
|||
|
|||
cpp-ethereum is distributed in the hope that it will be useful, |
|||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
GNU General Public License for more details. |
|||
|
|||
You should have received a copy of the GNU General Public License |
|||
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
/** @file Worker.h
|
|||
* @author Gav Wood <i@gavwood.com> |
|||
* @date 2014 |
|||
*/ |
|||
|
|||
#pragma once |
|||
|
|||
#include <string> |
|||
#include <thread> |
|||
#include "Guards.h" |
|||
|
|||
namespace dev |
|||
{ |
|||
|
|||
class Worker |
|||
{ |
|||
protected: |
|||
Worker(std::string const& _name = "anon"): m_name(_name) {} |
|||
|
|||
/// Move-constructor.
|
|||
Worker(Worker&& _m) { std::swap(m_name, _m.m_name); } |
|||
|
|||
/// Move-assignment.
|
|||
Worker& operator=(Worker&& _m) { std::swap(m_name, _m.m_name); return *this; } |
|||
|
|||
virtual ~Worker() { stopWorking(); } |
|||
|
|||
void setName(std::string _n) { if (!isWorking()) m_name = _n; } |
|||
|
|||
void startWorking(); |
|||
void stopWorking(); |
|||
bool isWorking() const { Guard l(x_work); return !!m_work; } |
|||
virtual void doWork() = 0; |
|||
virtual void doneWorking() {} |
|||
|
|||
private: |
|||
mutable Mutex x_work; ///< Lock for the network existance.
|
|||
std::unique_ptr<std::thread> m_work; ///< The network thread.
|
|||
bool m_stop = false; |
|||
std::string m_name; |
|||
}; |
|||
|
|||
} |
@ -0,0 +1,10 @@ |
|||
#ifdef _MSC_VER |
|||
#include "All.h" |
|||
#include "Common.cpp" |
|||
#include "CommonData.cpp" |
|||
#include "CommonIO.cpp" |
|||
#include "FixedHash.cpp" |
|||
#include "Guards.cpp" |
|||
#include "Log.cpp" |
|||
#include "RLP.cpp" |
|||
#endif |
@ -0,0 +1,9 @@ |
|||
#pragma once |
|||
|
|||
#include "Common.h" |
|||
#include "FileSystem.h" |
|||
#include "MemoryDB.h" |
|||
#include "OverlayDB.h" |
|||
#include "SHA3.h" |
|||
#include "TrieCommon.h" |
|||
#include "TrieDB.h" |
@ -0,0 +1,56 @@ |
|||
cmake_policy(SET CMP0015 NEW) |
|||
|
|||
aux_source_directory(. SRC_LIST) |
|||
|
|||
set(EXECUTABLE devcrypto) |
|||
|
|||
# set(CMAKE_INSTALL_PREFIX ../lib) |
|||
if(ETH_STATIC) |
|||
add_library(${EXECUTABLE} STATIC ${SRC_LIST}) |
|||
else() |
|||
add_library(${EXECUTABLE} SHARED ${SRC_LIST}) |
|||
endif() |
|||
|
|||
file(GLOB HEADERS "*.h") |
|||
|
|||
include_directories(..) |
|||
|
|||
target_link_libraries(${EXECUTABLE} devcore) |
|||
target_link_libraries(${EXECUTABLE} secp256k1) |
|||
target_link_libraries(${EXECUTABLE} gmp) |
|||
target_link_libraries(${EXECUTABLE} ${LEVELDB_LS}) |
|||
target_link_libraries(${EXECUTABLE} ${CRYPTOPP_LS}) |
|||
|
|||
if("${TARGET_PLATFORM}" STREQUAL "w64") |
|||
target_link_libraries(${EXECUTABLE} boost_system-mt-s) |
|||
target_link_libraries(${EXECUTABLE} boost_filesystem-mt-s) |
|||
target_link_libraries(${EXECUTABLE} boost_thread_win32-mt-s) |
|||
target_link_libraries(${EXECUTABLE} iphlpapi) |
|||
target_link_libraries(${EXECUTABLE} ws2_32) |
|||
target_link_libraries(${EXECUTABLE} mswsock) |
|||
target_link_libraries(${EXECUTABLE} shlwapi) |
|||
elseif (APPLE) |
|||
# Latest mavericks boost libraries only come with -mt |
|||
target_link_libraries(${EXECUTABLE} boost_system-mt) |
|||
target_link_libraries(${EXECUTABLE} boost_filesystem-mt) |
|||
target_link_libraries(${EXECUTABLE} boost_thread-mt) |
|||
find_package(Threads REQUIRED) |
|||
target_link_libraries(${EXECUTABLE} ${CMAKE_THREAD_LIBS_INIT}) |
|||
elseif (UNIX) |
|||
find_package(Boost 1.53 REQUIRED COMPONENTS filesystem) |
|||
target_link_libraries(${EXECUTABLE} ${Boost_SYSTEM_LIBRARY}) |
|||
target_link_libraries(${EXECUTABLE} ${Boost_FILESYSTEM_LIBRARY}) |
|||
target_link_libraries(${EXECUTABLE} ${Boost_THREAD_LIBRARY}) |
|||
target_link_libraries(${EXECUTABLE} ${Boost_DATE_TIME_LIBRARY}) |
|||
target_link_libraries(${EXECUTABLE} ${CMAKE_THREAD_LIBS_INIT}) |
|||
else () |
|||
target_link_libraries(${EXECUTABLE} boost_system) |
|||
target_link_libraries(${EXECUTABLE} boost_filesystem) |
|||
target_link_libraries(${EXECUTABLE} boost_thread) |
|||
find_package(Threads REQUIRED) |
|||
target_link_libraries(${EXECUTABLE} ${CMAKE_THREAD_LIBS_INIT}) |
|||
endif () |
|||
|
|||
install( TARGETS ${EXECUTABLE} ARCHIVE DESTINATION lib LIBRARY DESTINATION lib ) |
|||
install( FILES ${HEADERS} DESTINATION include/${EXECUTABLE} ) |
|||
|
@ -0,0 +1,104 @@ |
|||
/*
|
|||
This file is part of cpp-ethereum. |
|||
|
|||
cpp-ethereum is free software: you can redistribute it and/or modify |
|||
it under the terms of the GNU General Public License as published by |
|||
the Free Software Foundation, either version 3 of the License, or |
|||
(at your option) any later version. |
|||
|
|||
cpp-ethereum is distributed in the hope that it will be useful, |
|||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
GNU General Public License for more details. |
|||
|
|||
You should have received a copy of the GNU General Public License |
|||
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
/** @file CommonEth.cpp
|
|||
* @author Gav Wood <i@gavwood.com> |
|||
* @date 2014 |
|||
*/ |
|||
|
|||
#include "Common.h" |
|||
#include <random> |
|||
#include <secp256k1/secp256k1.h> |
|||
#include "SHA3.h" |
|||
using namespace std; |
|||
using namespace dev; |
|||
using namespace dev::eth; |
|||
|
|||
//#define ETH_ADDRESS_DEBUG 1
|
|||
|
|||
Address dev::toAddress(Secret _private) |
|||
{ |
|||
secp256k1_start(); |
|||
|
|||
byte pubkey[65]; |
|||
int pubkeylen = 65; |
|||
int ok = secp256k1_ecdsa_seckey_verify(_private.data()); |
|||
if (!ok) |
|||
return Address(); |
|||
ok = secp256k1_ecdsa_pubkey_create(pubkey, &pubkeylen, _private.data(), 0); |
|||
assert(pubkeylen == 65); |
|||
if (!ok) |
|||
return Address(); |
|||
ok = secp256k1_ecdsa_pubkey_verify(pubkey, 65); |
|||
if (!ok) |
|||
return Address(); |
|||
auto ret = right160(dev::eth::sha3(bytesConstRef(&(pubkey[1]), 64))); |
|||
#if ETH_ADDRESS_DEBUG |
|||
cout << "---- ADDRESS -------------------------------" << endl; |
|||
cout << "SEC: " << _private << endl; |
|||
cout << "PUB: " << toHex(bytesConstRef(&(pubkey[1]), 64)) << endl; |
|||
cout << "ADR: " << ret << endl; |
|||
#endif |
|||
return ret; |
|||
} |
|||
|
|||
KeyPair KeyPair::create() |
|||
{ |
|||
secp256k1_start(); |
|||
static std::mt19937_64 s_eng(time(0)); |
|||
std::uniform_int_distribution<uint16_t> d(0, 255); |
|||
|
|||
for (int i = 0; i < 100; ++i) |
|||
{ |
|||
h256 sec; |
|||
for (unsigned i = 0; i < 32; ++i) |
|||
sec[i] = (byte)d(s_eng); |
|||
|
|||
KeyPair ret(sec); |
|||
if (ret.address()) |
|||
return ret; |
|||
} |
|||
return KeyPair(); |
|||
} |
|||
|
|||
KeyPair::KeyPair(h256 _sec): |
|||
m_secret(_sec) |
|||
{ |
|||
int ok = secp256k1_ecdsa_seckey_verify(m_secret.data()); |
|||
if (!ok) |
|||
return; |
|||
|
|||
byte pubkey[65]; |
|||
int pubkeylen = 65; |
|||
ok = secp256k1_ecdsa_pubkey_create(pubkey, &pubkeylen, m_secret.data(), 0); |
|||
if (!ok || pubkeylen != 65) |
|||
return; |
|||
|
|||
ok = secp256k1_ecdsa_pubkey_verify(pubkey, 65); |
|||
if (!ok) |
|||
return; |
|||
|
|||
m_secret = m_secret; |
|||
memcpy(m_public.data(), &(pubkey[1]), 64); |
|||
m_address = right160(dev::eth::sha3(bytesConstRef(&(pubkey[1]), 64))); |
|||
|
|||
#if ETH_ADDRESS_DEBUG |
|||
cout << "---- ADDRESS -------------------------------" << endl; |
|||
cout << "SEC: " << m_secret << endl; |
|||
cout << "PUB: " << m_public << endl; |
|||
cout << "ADR: " << m_address << endl; |
|||
#endif |
|||
} |
@ -0,0 +1,86 @@ |
|||
/*
|
|||
This file is part of cpp-ethereum. |
|||
|
|||
cpp-ethereum is free software: you can redistribute it and/or modify |
|||
it under the terms of the GNU General Public License as published by |
|||
the Free Software Foundation, either version 3 of the License, or |
|||
(at your option) any later version. |
|||
|
|||
cpp-ethereum is distributed in the hope that it will be useful, |
|||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
GNU General Public License for more details. |
|||
|
|||
You should have received a copy of the GNU General Public License |
|||
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
/** @file CommonEth.h
|
|||
* @author Gav Wood <i@gavwood.com> |
|||
* @date 2014 |
|||
* |
|||
* Ethereum-specific data structures & algorithms. |
|||
*/ |
|||
|
|||
#pragma once |
|||
|
|||
#include <libdevcore/Common.h> |
|||
#include <libdevcore/FixedHash.h> |
|||
|
|||
namespace dev |
|||
{ |
|||
|
|||
/// A secret key: 32 bytes.
|
|||
/// @NOTE This is not endian-specific; it's just a bunch of bytes.
|
|||
using Secret = h256; |
|||
|
|||
/// A public key: 64 bytes.
|
|||
/// @NOTE This is not endian-specific; it's just a bunch of bytes.
|
|||
using Public = h512; |
|||
|
|||
/// An Ethereum address: 20 bytes.
|
|||
/// @NOTE This is not endian-specific; it's just a bunch of bytes.
|
|||
using Address = h160; |
|||
|
|||
/// A vector of Ethereum addresses.
|
|||
using Addresses = h160s; |
|||
|
|||
/// Convert a private key into the public key equivalent.
|
|||
/// @returns 0 if it's not a valid private key.
|
|||
Address toAddress(h256 _private); |
|||
|
|||
/// Simple class that represents a "key pair".
|
|||
/// All of the data of the class can be regenerated from the secret key (m_secret) alone.
|
|||
/// Actually stores a tuplet of secret, public and address (the right 160-bits of the public).
|
|||
class KeyPair |
|||
{ |
|||
public: |
|||
/// Null constructor.
|
|||
KeyPair() {} |
|||
|
|||
/// Normal constructor - populates object from the given secret key.
|
|||
KeyPair(Secret _k); |
|||
|
|||
/// Create a new, randomly generated object.
|
|||
static KeyPair create(); |
|||
|
|||
/// Retrieve the secret key.
|
|||
Secret const& secret() const { return m_secret; } |
|||
/// Retrieve the secret key.
|
|||
Secret const& sec() const { return m_secret; } |
|||
|
|||
/// Retrieve the public key.
|
|||
Public const& pub() const { return m_public; } |
|||
|
|||
/// Retrieve the associated address of the public key.
|
|||
Address const& address() const { return m_address; } |
|||
|
|||
bool operator==(KeyPair const& _c) const { return m_secret == _c.m_secret; } |
|||
bool operator!=(KeyPair const& _c) const { return m_secret != _c.m_secret; } |
|||
|
|||
private: |
|||
Secret m_secret; |
|||
Public m_public; |
|||
Address m_address; |
|||
}; |
|||
|
|||
} |
@ -0,0 +1,36 @@ |
|||
/*
|
|||
This file is part of cpp-ethereum. |
|||
|
|||
cpp-ethereum is free software: you can redistribute it and/or modify |
|||
it under the terms of the GNU General Public License as published by |
|||
the Free Software Foundation, either version 3 of the License, or |
|||
(at your option) any later version. |
|||
|
|||
cpp-ethereum is distributed in the hope that it will be useful, |
|||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
GNU General Public License for more details. |
|||
|
|||
You should have received a copy of the GNU General Public License |
|||
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
/** @file CryptoHeaders.h
|
|||
* @author Tim Hughes <tim@twistedfury.com> |
|||
* @date 2014 |
|||
*/ |
|||
#pragma once |
|||
|
|||
// need to leave this one disabled
|
|||
#pragma GCC diagnostic ignored "-Wunused-function" |
|||
|
|||
#pragma warning(push) |
|||
#pragma warning(disable:4100 4244) |
|||
#pragma GCC diagnostic push |
|||
#pragma GCC diagnostic ignored "-Wconversion" |
|||
#pragma GCC diagnostic ignored "-Wunused-parameter" |
|||
#include <sha.h> |
|||
#include <sha3.h> |
|||
#include <ripemd.h> |
|||
#include <secp256k1/secp256k1.h> |
|||
#pragma warning(pop) |
|||
#pragma GCC diagnostic pop |
@ -1,40 +1,46 @@ |
|||
#pragma once |
|||
|
|||
#include <libethential/Exceptions.h> |
|||
#include <libdevcore/Exceptions.h> |
|||
|
|||
namespace dev |
|||
{ |
|||
namespace eth |
|||
{ |
|||
|
|||
class NotEnoughCash: public Exception {}; |
|||
class DatabaseAlreadyOpen: public dev::Exception {}; |
|||
|
|||
class NotEnoughCash: public dev::Exception {}; |
|||
|
|||
class GasPriceTooLow: public Exception {}; |
|||
class BlockGasLimitReached: public Exception {}; |
|||
class NoSuchContract: public Exception {}; |
|||
class ContractAddressCollision: public Exception {}; |
|||
class FeeTooSmall: public Exception {}; |
|||
class TooMuchGasUsed: public Exception {}; |
|||
class ExtraDataTooBig: public Exception {}; |
|||
class InvalidSignature: public Exception {}; |
|||
class InvalidTransactionFormat: public Exception { public: InvalidTransactionFormat(int _f, bytesConstRef _d): m_f(_f), m_d(_d.toBytes()) {} int m_f; bytes m_d; virtual std::string description() const { return "Invalid transaction format: Bad field " + toString(m_f) + " (" + toHex(m_d) + ")"; } }; |
|||
class InvalidBlockFormat: public Exception { public: InvalidBlockFormat(int _f, bytesConstRef _d): m_f(_f), m_d(_d.toBytes()) {} int m_f; bytes m_d; virtual std::string description() const { return "Invalid block format: Bad field " + toString(m_f) + " (" + toHex(m_d) + ")"; } }; |
|||
class InvalidBlockHeaderFormat: public Exception { public: InvalidBlockHeaderFormat(int _f, bytesConstRef _d): m_f(_f), m_d(_d.toBytes()) {} int m_f; bytes m_d; virtual std::string description() const { return "Invalid block header format: Bad field " + toString(m_f) + " (" + toHex(m_d) + ")"; } }; |
|||
class InvalidUnclesHash: public Exception {}; |
|||
class InvalidUncle: public Exception {}; |
|||
class UncleNotAnUncle: public Exception {}; |
|||
class DuplicateUncleNonce: public Exception {}; |
|||
class InvalidStateRoot: public Exception {}; |
|||
class InvalidTransactionsHash: public Exception { public: InvalidTransactionsHash(h256 _head, h256 _real): m_head(_head), m_real(_real) {} h256 m_head; h256 m_real; virtual std::string description() const { return "Invalid transactions hash: header says: " + toHex(m_head.ref()) + " block is:" + toHex(m_real.ref()); } }; |
|||
class InvalidTransaction: public Exception {}; |
|||
class InvalidDifficulty: public Exception {}; |
|||
class InvalidGasLimit: public Exception {}; |
|||
class InvalidMinGasPrice: public Exception { public: InvalidMinGasPrice(u256 _provided = 0, u256 _limit = 0): provided(_provided), limit(_limit) {} u256 provided; u256 limit; virtual std::string description() const { return "Invalid minimum gas price (provided: " + toString(provided) + " limit:" + toString(limit) + ")"; } }; |
|||
class InvalidTransactionGasUsed: public Exception {}; |
|||
class InvalidTransactionStateRoot: public Exception {}; |
|||
class InvalidTimestamp: public Exception {}; |
|||
class InvalidNonce: public Exception { public: InvalidNonce(u256 _required = 0, u256 _candidate = 0): required(_required), candidate(_candidate) {} u256 required; u256 candidate; virtual std::string description() const { return "Invalid nonce (r: " + toString(required) + " c:" + toString(candidate) + ")"; } }; |
|||
class InvalidBlockNonce: public Exception { public: InvalidBlockNonce(h256 _h = h256(), h256 _n = h256(), u256 _d = 0): h(_h), n(_n), d(_d) {} h256 h; h256 n; u256 d; virtual std::string description() const { return "Invalid nonce (h: " + toString(h) + " n:" + toString(n) + " d:" + toString(d) + ")"; } }; |
|||
class InvalidParentHash: public Exception {}; |
|||
class InvalidNumber: public Exception {}; |
|||
class InvalidContractAddress: public Exception {}; |
|||
class GasPriceTooLow: public dev::Exception {}; |
|||
class BlockGasLimitReached: public dev::Exception {}; |
|||
class NoSuchContract: public dev::Exception {}; |
|||
class ContractAddressCollision: public dev::Exception {}; |
|||
class FeeTooSmall: public dev::Exception {}; |
|||
class TooMuchGasUsed: public dev::Exception {}; |
|||
class ExtraDataTooBig: public dev::Exception {}; |
|||
class InvalidSignature: public dev::Exception {}; |
|||
class InvalidTransactionFormat: public dev::Exception { public: InvalidTransactionFormat(int _f, bytesConstRef _d): m_f(_f), m_d(_d.toBytes()) {} int m_f; bytes m_d; virtual std::string description() const { return "Invalid transaction format: Bad field " + toString(m_f) + " (" + toHex(m_d) + ")"; } }; |
|||
class InvalidBlockFormat: public dev::Exception { public: InvalidBlockFormat(int _f, bytesConstRef _d): m_f(_f), m_d(_d.toBytes()) {} int m_f; bytes m_d; virtual std::string description() const { return "Invalid block format: Bad field " + toString(m_f) + " (" + toHex(m_d) + ")"; } }; |
|||
class InvalidBlockHeaderFormat: public dev::Exception { public: InvalidBlockHeaderFormat(int _f, bytesConstRef _d): m_f(_f), m_d(_d.toBytes()) {} int m_f; bytes m_d; virtual std::string description() const { return "Invalid block header format: Bad field " + toString(m_f) + " (" + toHex(m_d) + ")"; } }; |
|||
class InvalidUnclesHash: public dev::Exception {}; |
|||
class InvalidUncle: public dev::Exception {}; |
|||
class UncleTooOld: public dev::Exception {}; |
|||
class UncleInChain: public dev::Exception {}; |
|||
class DuplicateUncleNonce: public dev::Exception {}; |
|||
class InvalidStateRoot: public dev::Exception {}; |
|||
class InvalidTransactionsHash: public dev::Exception { public: InvalidTransactionsHash(h256 _head, h256 _real): m_head(_head), m_real(_real) {} h256 m_head; h256 m_real; virtual std::string description() const { return "Invalid transactions hash: header says: " + toHex(m_head.ref()) + " block is:" + toHex(m_real.ref()); } }; |
|||
class InvalidTransaction: public dev::Exception {}; |
|||
class InvalidDifficulty: public dev::Exception {}; |
|||
class InvalidGasLimit: public dev::Exception { public: InvalidGasLimit(u256 _provided = 0, u256 _valid = 0): provided(_provided), valid(_valid) {} u256 provided; u256 valid; virtual std::string description() const { return "Invalid gas limit (provided: " + toString(provided) + " valid:" + toString(valid) + ")"; } }; |
|||
class InvalidMinGasPrice: public dev::Exception { public: InvalidMinGasPrice(u256 _provided = 0, u256 _limit = 0): provided(_provided), limit(_limit) {} u256 provided; u256 limit; virtual std::string description() const { return "Invalid minimum gas price (provided: " + toString(provided) + " limit:" + toString(limit) + ")"; } }; |
|||
class InvalidTransactionGasUsed: public dev::Exception {}; |
|||
class InvalidTransactionStateRoot: public dev::Exception {}; |
|||
class InvalidTimestamp: public dev::Exception {}; |
|||
class InvalidNonce: public dev::Exception { public: InvalidNonce(u256 _required = 0, u256 _candidate = 0): required(_required), candidate(_candidate) {} u256 required; u256 candidate; virtual std::string description() const { return "Invalid nonce (r: " + toString(required) + " c:" + toString(candidate) + ")"; } }; |
|||
class InvalidBlockNonce: public dev::Exception { public: InvalidBlockNonce(h256 _h = h256(), h256 _n = h256(), u256 _d = 0): h(_h), n(_n), d(_d) {} h256 h; h256 n; u256 d; virtual std::string description() const { return "Invalid nonce (h: " + toString(h) + " n:" + toString(n) + " d:" + toString(d) + ")"; } }; |
|||
class InvalidParentHash: public dev::Exception {}; |
|||
class InvalidNumber: public dev::Exception {}; |
|||
class InvalidContractAddress: public dev::Exception {}; |
|||
|
|||
} |
|||
} |
|||
|
@ -0,0 +1,6 @@ |
|||
#ifdef _MSC_VER |
|||
#include "All.h" |
|||
#include "BlockInfo.cpp" |
|||
#include "CommonEth.cpp" |
|||
#include "Dagger.cpp" |
|||
#endif |
@ -1,104 +0,0 @@ |
|||
/*
|
|||
This file is part of cpp-ethereum. |
|||
|
|||
cpp-ethereum is free software: you can redistribute it and/or modify |
|||
it under the terms of the GNU General Public License as published by |
|||
the Free Software Foundation, either version 3 of the License, or |
|||
(at your option) any later version. |
|||
|
|||
cpp-ethereum is distributed in the hope that it will be useful, |
|||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
GNU General Public License for more details. |
|||
|
|||
You should have received a copy of the GNU General Public License |
|||
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
/** @file Common.cpp
|
|||
* @author Gav Wood <i@gavwood.com> |
|||
* @date 2014 |
|||
*/ |
|||
|
|||
#include "CommonData.h" |
|||
|
|||
#include <random> |
|||
#include "Exceptions.h" |
|||
using namespace std; |
|||
using namespace eth; |
|||
|
|||
std::string eth::escaped(std::string const& _s, bool _all) |
|||
{ |
|||
std::string ret; |
|||
ret.reserve(_s.size()); |
|||
ret.push_back('"'); |
|||
for (auto i: _s) |
|||
if (i == '"' && !_all) |
|||
ret += "\\\""; |
|||
else if (i == '\\' && !_all) |
|||
ret += "\\\\"; |
|||
else if (i < ' ' || _all) |
|||
{ |
|||
ret += "\\x"; |
|||
ret.push_back("0123456789abcdef"[(uint8_t)i / 16]); |
|||
ret.push_back("0123456789abcdef"[(uint8_t)i % 16]); |
|||
} |
|||
else |
|||
ret.push_back(i); |
|||
ret.push_back('"'); |
|||
return ret; |
|||
} |
|||
|
|||
std::string eth::randomWord() |
|||
{ |
|||
static std::mt19937_64 s_eng(0); |
|||
std::string ret(std::uniform_int_distribution<int>(1, 5)(s_eng), ' '); |
|||
char const n[] = "qwertyuiop";//asdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890";
|
|||
std::uniform_int_distribution<int> d(0, sizeof(n) - 2); |
|||
for (char& c: ret) |
|||
c = n[d(s_eng)]; |
|||
return ret; |
|||
} |
|||
|
|||
int eth::fromHex(char _i) |
|||
{ |
|||
if (_i >= '0' && _i <= '9') |
|||
return _i - '0'; |
|||
if (_i >= 'a' && _i <= 'f') |
|||
return _i - 'a' + 10; |
|||
if (_i >= 'A' && _i <= 'F') |
|||
return _i - 'A' + 10; |
|||
throw BadHexCharacter(); |
|||
} |
|||
|
|||
bytes eth::fromHex(std::string const& _s) |
|||
{ |
|||
uint s = (_s[0] == '0' && _s[1] == 'x') ? 2 : 0; |
|||
std::vector<uint8_t> ret; |
|||
ret.reserve((_s.size() - s + 1) / 2); |
|||
|
|||
if (_s.size() % 2) |
|||
try |
|||
{ |
|||
ret.push_back(fromHex(_s[s++])); |
|||
} |
|||
catch (...){ ret.push_back(0); } |
|||
for (uint i = s; i < _s.size(); i += 2) |
|||
try |
|||
{ |
|||
ret.push_back((byte)(fromHex(_s[i]) * 16 + fromHex(_s[i + 1]))); |
|||
} |
|||
catch (...){ ret.push_back(0); } |
|||
return ret; |
|||
} |
|||
|
|||
bytes eth::asNibbles(std::string const& _s) |
|||
{ |
|||
std::vector<uint8_t> ret; |
|||
ret.reserve(_s.size() * 2); |
|||
for (auto i: _s) |
|||
{ |
|||
ret.push_back(i / 16); |
|||
ret.push_back(i % 16); |
|||
} |
|||
return ret; |
|||
} |
@ -0,0 +1,84 @@ |
|||
/*
|
|||
This file is part of cpp-ethereum. |
|||
|
|||
cpp-ethereum is free software: you can redistribute it and/or modify |
|||
it under the terms of the GNU General Public License as published by |
|||
the Free Software Foundation, either version 3 of the License, or |
|||
(at your option) any later version. |
|||
|
|||
cpp-ethereum is distributed in the hope that it will be useful, |
|||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
GNU General Public License for more details. |
|||
|
|||
You should have received a copy of the GNU General Public License |
|||
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
/** @file AccountDiff.cpp
|
|||
* @author Gav Wood <i@gavwood.com> |
|||
* @date 2014 |
|||
*/ |
|||
|
|||
#include "AccountDiff.h" |
|||
|
|||
#include <libdevcore/CommonIO.h> |
|||
using namespace std; |
|||
using namespace dev; |
|||
using namespace dev::eth; |
|||
|
|||
AccountChange AccountDiff::changeType() const |
|||
{ |
|||
bool bn = (balance || nonce); |
|||
bool sc = (!storage.empty() || code); |
|||
return exist ? exist.from() ? AccountChange::Deletion : AccountChange::Creation : (bn && sc) ? AccountChange::All : bn ? AccountChange::Intrinsic: sc ? AccountChange::CodeStorage : AccountChange::None; |
|||
} |
|||
|
|||
char const* AccountDiff::lead() const |
|||
{ |
|||
bool bn = (balance || nonce); |
|||
bool sc = (!storage.empty() || code); |
|||
return exist ? exist.from() ? "XXX" : "+++" : (bn && sc) ? "***" : bn ? " * " : sc ? "* *" : " "; |
|||
} |
|||
|
|||
namespace dev { |
|||
|
|||
std::ostream& operator<<(std::ostream& _out, dev::eth::AccountDiff const& _s) |
|||
{ |
|||
if (!_s.exist.to()) |
|||
return _out; |
|||
|
|||
if (_s.nonce) |
|||
{ |
|||
_out << std::dec << "#" << _s.nonce.to() << " "; |
|||
if (_s.nonce.from()) |
|||
_out << "(" << std::showpos << (((bigint)_s.nonce.to()) - ((bigint)_s.nonce.from())) << std::noshowpos << ") "; |
|||
} |
|||
if (_s.balance) |
|||
{ |
|||
_out << std::dec << _s.balance.to() << " "; |
|||
if (_s.balance.from()) |
|||
_out << "(" << std::showpos << (((bigint)_s.balance.to()) - ((bigint)_s.balance.from())) << std::noshowpos << ") "; |
|||
} |
|||
if (_s.code) |
|||
_out << "$" << std::hex << nouppercase << _s.code.to() << " (" << _s.code.from() << ") "; |
|||
for (pair<u256, Diff<u256>> const& i: _s.storage) |
|||
if (!i.second.from()) |
|||
_out << endl << " + " << (h256)i.first << ": " << std::hex << nouppercase << i.second.to(); |
|||
else if (!i.second.to()) |
|||
_out << endl << "XXX " << (h256)i.first << " (" << std::hex << nouppercase << i.second.from() << ")"; |
|||
else |
|||
_out << endl << " * " << (h256)i.first << ": " << std::hex << nouppercase << i.second.to() << " (" << i.second.from() << ")"; |
|||
return _out; |
|||
} |
|||
|
|||
std::ostream& operator<<(std::ostream& _out, dev::eth::StateDiff const& _s) |
|||
{ |
|||
_out << _s.accounts.size() << " accounts changed:" << endl; |
|||
dev::eth::AccountDiff d; |
|||
_out << d; |
|||
for (auto const& i: _s.accounts) |
|||
_out << i.second.lead() << " " << i.first << ": " << i.second << endl; |
|||
return _out; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,76 @@ |
|||
/*
|
|||
This file is part of cpp-ethereum. |
|||
|
|||
cpp-ethereum is free software: you can redistribute it and/or modify |
|||
it under the terms of the GNU General Public License as published by |
|||
the Free Software Foundation, either version 3 of the License, or |
|||
(at your option) any later version. |
|||
|
|||
cpp-ethereum is distributed in the hope that it will be useful, |
|||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
GNU General Public License for more details. |
|||
|
|||
You should have received a copy of the GNU General Public License |
|||
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
/** @file AccountDiff.h
|
|||
* @author Gav Wood <i@gavwood.com> |
|||
* @date 2014 |
|||
*/ |
|||
|
|||
#pragma once |
|||
|
|||
#include <libdevcore/Common.h> |
|||
#include <libethcore/CommonEth.h> |
|||
|
|||
namespace dev |
|||
{ |
|||
namespace eth |
|||
{ |
|||
|
|||
enum class ExistDiff { Same, New, Dead }; |
|||
template <class T> |
|||
class Diff |
|||
{ |
|||
public: |
|||
Diff() {} |
|||
Diff(T _from, T _to): m_from(_from), m_to(_to) {} |
|||
|
|||
T const& from() const { return m_from; } |
|||
T const& to() const { return m_to; } |
|||
|
|||
explicit operator bool() const { return m_from != m_to; } |
|||
|
|||
private: |
|||
T m_from; |
|||
T m_to; |
|||
}; |
|||
|
|||
enum class AccountChange { None, Creation, Deletion, Intrinsic, CodeStorage, All }; |
|||
|
|||
struct AccountDiff |
|||
{ |
|||
inline bool changed() const { return storage.size() || code || nonce || balance || exist; } |
|||
char const* lead() const; |
|||
AccountChange changeType() const; |
|||
|
|||
Diff<bool> exist; |
|||
Diff<u256> balance; |
|||
Diff<u256> nonce; |
|||
std::map<u256, Diff<u256>> storage; |
|||
Diff<bytes> code; |
|||
}; |
|||
|
|||
struct StateDiff |
|||
{ |
|||
std::map<Address, AccountDiff> accounts; |
|||
}; |
|||
|
|||
} |
|||
|
|||
std::ostream& operator<<(std::ostream& _out, dev::eth::StateDiff const& _s); |
|||
std::ostream& operator<<(std::ostream& _out, dev::eth::AccountDiff const& _s); |
|||
|
|||
} |
|||
|
@ -0,0 +1,41 @@ |
|||
/*
|
|||
This file is part of cpp-ethereum. |
|||
|
|||
cpp-ethereum is free software: you can redistribute it and/or modify |
|||
it under the terms of the GNU General Public License as published by |
|||
the Free Software Foundation, either version 3 of the License, or |
|||
(at your option) any later version. |
|||
|
|||
cpp-ethereum is distributed in the hope that it will be useful, |
|||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
GNU General Public License for more details. |
|||
|
|||
You should have received a copy of the GNU General Public License |
|||
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
/** @file BlockDetails.cpp
|
|||
* @author Gav Wood <i@gavwood.com> |
|||
* @date 2014 |
|||
*/ |
|||
|
|||
#include "BlockDetails.h" |
|||
|
|||
#include <libdevcore/Common.h> |
|||
using namespace std; |
|||
using namespace dev; |
|||
using namespace dev::eth; |
|||
|
|||
BlockDetails::BlockDetails(RLP const& _r) |
|||
{ |
|||
number = _r[0].toInt<unsigned>(); |
|||
totalDifficulty = _r[1].toInt<u256>(); |
|||
parent = _r[2].toHash<h256>(); |
|||
children = _r[3].toVector<h256>(); |
|||
bloom = _r[4].toHash<h256>(); |
|||
} |
|||
|
|||
bytes BlockDetails::rlp() const |
|||
{ |
|||
return rlpList(number, totalDifficulty, parent, children, bloom); |
|||
} |
@ -0,0 +1,84 @@ |
|||
/*
|
|||
This file is part of cpp-ethereum. |
|||
|
|||
cpp-ethereum is free software: you can redistribute it and/or modify |
|||
it under the terms of the GNU General Public License as published by |
|||
the Free Software Foundation, either version 3 of the License, or |
|||
(at your option) any later version. |
|||
|
|||
cpp-ethereum is distributed in the hope that it will be useful, |
|||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
GNU General Public License for more details. |
|||
|
|||
You should have received a copy of the GNU General Public License |
|||
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
/** @file BlockDetails.h
|
|||
* @author Gav Wood <i@gavwood.com> |
|||
* @date 2014 |
|||
*/ |
|||
|
|||
#pragma once |
|||
|
|||
#pragma warning(push) |
|||
#pragma warning(disable: 4100 4267) |
|||
#include <leveldb/db.h> |
|||
#pragma warning(pop) |
|||
|
|||
#include <libdevcore/Log.h> |
|||
#include <libdevcore/RLP.h> |
|||
#include "Manifest.h" |
|||
namespace ldb = leveldb; |
|||
|
|||
namespace dev |
|||
{ |
|||
namespace eth |
|||
{ |
|||
|
|||
struct BlockDetails |
|||
{ |
|||
BlockDetails(): number(0), totalDifficulty(0) {} |
|||
BlockDetails(unsigned _n, u256 _tD, h256 _p, h256s _c, h256 _bloom): number(_n), totalDifficulty(_tD), parent(_p), children(_c), bloom(_bloom) {} |
|||
BlockDetails(RLP const& _r); |
|||
bytes rlp() const; |
|||
|
|||
bool isNull() const { return !totalDifficulty; } |
|||
explicit operator bool() const { return !isNull(); } |
|||
|
|||
unsigned number; // TODO: remove?
|
|||
u256 totalDifficulty; |
|||
h256 parent; |
|||
h256s children; |
|||
h256 bloom; |
|||
}; |
|||
|
|||
struct BlockBlooms |
|||
{ |
|||
BlockBlooms() {} |
|||
BlockBlooms(RLP const& _r) { blooms = _r.toVector<h256>(); } |
|||
bytes rlp() const { RLPStream s; s << blooms; return s.out(); } |
|||
|
|||
h256s blooms; |
|||
}; |
|||
|
|||
struct BlockTraces |
|||
{ |
|||
BlockTraces() {} |
|||
BlockTraces(RLP const& _r) { for (auto const& i: _r) traces.emplace_back(i.data()); } |
|||
bytes rlp() const { RLPStream s(traces.size()); for (auto const& i: traces) i.streamOut(s); return s.out(); } |
|||
|
|||
Manifests traces; |
|||
}; |
|||
|
|||
|
|||
typedef std::map<h256, BlockDetails> BlockDetailsHash; |
|||
typedef std::map<h256, BlockBlooms> BlockBloomsHash; |
|||
typedef std::map<h256, BlockTraces> BlockTracesHash; |
|||
|
|||
static const BlockDetails NullBlockDetails; |
|||
static const BlockBlooms NullBlockBlooms; |
|||
static const BlockTraces NullBlockTraces; |
|||
|
|||
} |
|||
} |
@ -0,0 +1,142 @@ |
|||
/*
|
|||
This file is part of cpp-ethereum. |
|||
|
|||
cpp-ethereum is free software: you can redistribute it and/or modify |
|||
it under the terms of the GNU General Public License as published by |
|||
the Free Software Foundation, either version 3 of the License, or |
|||
(at your option) any later version. |
|||
|
|||
cpp-ethereum is distributed in the hope that it will be useful, |
|||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
GNU General Public License for more details. |
|||
|
|||
You should have received a copy of the GNU General Public License |
|||
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
/** @file BlockQueue.cpp
|
|||
* @author Gav Wood <i@gavwood.com> |
|||
* @date 2014 |
|||
*/ |
|||
|
|||
#include "BlockQueue.h" |
|||
|
|||
#include <libdevcore/Log.h> |
|||
#include <libethcore/Exceptions.h> |
|||
#include <libethcore/BlockInfo.h> |
|||
#include "BlockChain.h" |
|||
using namespace std; |
|||
using namespace dev; |
|||
using namespace dev::eth; |
|||
|
|||
bool BlockQueue::import(bytesConstRef _block, BlockChain const& _bc) |
|||
{ |
|||
// Check if we already know this block.
|
|||
h256 h = BlockInfo::headerHash(_block); |
|||
|
|||
cblockq << "Queuing block" << h.abridged() << "for import..."; |
|||
|
|||
UpgradableGuard l(m_lock); |
|||
|
|||
if (m_readySet.count(h) || m_drainingSet.count(h) || m_unknownSet.count(h)) |
|||
{ |
|||
// Already know about this one.
|
|||
cblockq << "Already known."; |
|||
return false; |
|||
} |
|||
|
|||
// VERIFY: populates from the block and checks the block is internally coherent.
|
|||
BlockInfo bi; |
|||
|
|||
#if ETH_CATCH |
|||
try |
|||
#endif |
|||
{ |
|||
bi.populate(_block); |
|||
bi.verifyInternals(_block); |
|||
} |
|||
#if ETH_CATCH |
|||
catch (Exception const& _e) |
|||
{ |
|||
cwarn << "Ignoring malformed block: " << _e.description(); |
|||
return false; |
|||
} |
|||
#endif |
|||
|
|||
// Check block doesn't already exist first!
|
|||
if (_bc.details(h)) |
|||
{ |
|||
cblockq << "Already known in chain."; |
|||
return false; |
|||
} |
|||
|
|||
UpgradeGuard ul(l); |
|||
|
|||
// Check it's not in the future
|
|||
if (bi.timestamp > (u256)time(0)) |
|||
{ |
|||
m_future.insert(make_pair((unsigned)bi.timestamp, _block.toBytes())); |
|||
cblockq << "OK - queued for future."; |
|||
} |
|||
else |
|||
{ |
|||
// We now know it.
|
|||
if (!m_readySet.count(bi.parentHash) && !m_drainingSet.count(bi.parentHash) && !_bc.isKnown(bi.parentHash)) |
|||
{ |
|||
// We don't know the parent (yet) - queue it up for later. It'll get resent to us if we find out about its ancestry later on.
|
|||
cblockq << "OK - queued as unknown parent:" << bi.parentHash.abridged(); |
|||
m_unknown.insert(make_pair(bi.parentHash, make_pair(h, _block.toBytes()))); |
|||
m_unknownSet.insert(h); |
|||
} |
|||
else |
|||
{ |
|||
// If valid, append to blocks.
|
|||
cblockq << "OK - ready for chain insertion."; |
|||
m_ready.push_back(_block.toBytes()); |
|||
m_readySet.insert(h); |
|||
|
|||
noteReadyWithoutWriteGuard(h); |
|||
} |
|||
} |
|||
|
|||
return true; |
|||
} |
|||
|
|||
void BlockQueue::tick(BlockChain const& _bc) |
|||
{ |
|||
unsigned t = time(0); |
|||
for (auto i = m_future.begin(); i != m_future.end() && i->first < time(0); ++i) |
|||
import(&(i->second), _bc); |
|||
|
|||
WriteGuard l(m_lock); |
|||
m_future.erase(m_future.begin(), m_future.upper_bound(t)); |
|||
} |
|||
|
|||
void BlockQueue::drain(std::vector<bytes>& o_out) |
|||
{ |
|||
WriteGuard l(m_lock); |
|||
if (m_drainingSet.empty()) |
|||
{ |
|||
swap(o_out, m_ready); |
|||
swap(m_drainingSet, m_readySet); |
|||
} |
|||
} |
|||
|
|||
void BlockQueue::noteReadyWithoutWriteGuard(h256 _good) |
|||
{ |
|||
list<h256> goodQueue(1, _good); |
|||
while (goodQueue.size()) |
|||
{ |
|||
auto r = m_unknown.equal_range(goodQueue.front()); |
|||
goodQueue.pop_front(); |
|||
for (auto it = r.first; it != r.second; ++it) |
|||
{ |
|||
m_ready.push_back(it->second.second); |
|||
auto newReady = it->second.first; |
|||
m_unknownSet.erase(newReady); |
|||
m_readySet.insert(newReady); |
|||
goodQueue.push_back(newReady); |
|||
} |
|||
m_unknown.erase(r.first, r.second); |
|||
} |
|||
} |
@ -0,0 +1,84 @@ |
|||
/*
|
|||
This file is part of cpp-ethereum. |
|||
|
|||
cpp-ethereum is free software: you can redistribute it and/or modify |
|||
it under the terms of the GNU General Public License as published by |
|||
the Free Software Foundation, either version 3 of the License, or |
|||
(at your option) any later version. |
|||
|
|||
cpp-ethereum is distributed in the hope that it will be useful, |
|||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
GNU General Public License for more details. |
|||
|
|||
You should have received a copy of the GNU General Public License |
|||
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
/** @file BlockQueue.h
|
|||
* @author Gav Wood <i@gavwood.com> |
|||
* @date 2014 |
|||
*/ |
|||
|
|||
#pragma once |
|||
|
|||
#include <boost/thread.hpp> |
|||
#include <libdevcore/Common.h> |
|||
#include <libdevcore/Log.h> |
|||
#include <libethcore/CommonEth.h> |
|||
#include <libdevcore/Guards.h> |
|||
|
|||
namespace dev |
|||
{ |
|||
namespace eth |
|||
{ |
|||
|
|||
class BlockChain; |
|||
|
|||
struct BlockQueueChannel: public LogChannel { static const char* name() { return "[]Q"; } static const int verbosity = 4; }; |
|||
#define cblockq dev::LogOutputStream<dev::eth::BlockQueueChannel, true>() |
|||
|
|||
/**
|
|||
* @brief A queue of blocks. Sits between network or other I/O and the BlockChain. |
|||
* Sorts them ready for blockchain insertion (with the BlockChain::sync() method). |
|||
* @threadsafe |
|||
*/ |
|||
class BlockQueue |
|||
{ |
|||
public: |
|||
/// Import a block into the queue.
|
|||
bool import(bytesConstRef _tx, BlockChain const& _bc); |
|||
|
|||
/// Notes that time has moved on and some blocks that used to be "in the future" may no be valid.
|
|||
void tick(BlockChain const& _bc); |
|||
|
|||
/// Grabs the blocks that are ready, giving them in the correct order for insertion into the chain.
|
|||
/// Don't forget to call doneDrain() once you're done importing.
|
|||
void drain(std::vector<bytes>& o_out); |
|||
|
|||
/// Must be called after a drain() call. Notes that the drained blocks have been imported into the blockchain, so we can forget about them.
|
|||
void doneDrain() { WriteGuard l(m_lock); m_drainingSet.clear(); } |
|||
|
|||
/// Notify the queue that the chain has changed and a new block has attained 'ready' status (i.e. is in the chain).
|
|||
void noteReady(h256 _b) { WriteGuard l(m_lock); noteReadyWithoutWriteGuard(_b); } |
|||
|
|||
/// Get information on the items queued.
|
|||
std::pair<unsigned, unsigned> items() const { ReadGuard l(m_lock); return std::make_pair(m_ready.size(), m_unknown.size()); } |
|||
|
|||
/// Clear everything.
|
|||
void clear() { WriteGuard l(m_lock); m_readySet.clear(); m_drainingSet.clear(); m_ready.clear(); m_unknownSet.clear(); m_unknown.clear(); m_future.clear(); } |
|||
|
|||
private: |
|||
void noteReadyWithoutWriteGuard(h256 _b); |
|||
void notePresentWithoutWriteGuard(bytesConstRef _block); |
|||
|
|||
mutable boost::shared_mutex m_lock; ///< General lock.
|
|||
std::set<h256> m_readySet; ///< All blocks ready for chain-import.
|
|||
std::set<h256> m_drainingSet; ///< All blocks being imported.
|
|||
std::vector<bytes> m_ready; ///< List of blocks, in correct order, ready for chain-import.
|
|||
std::set<h256> m_unknownSet; ///< Set of all blocks whose parents are not ready/in-chain.
|
|||
std::multimap<h256, std::pair<h256, bytes>> m_unknown; ///< For transactions that have an unknown parent; we map their parent hash to the block stuff, and insert once the block appears.
|
|||
std::multimap<unsigned, bytes> m_future; ///< Set of blocks that are not yet valid.
|
|||
}; |
|||
|
|||
} |
|||
} |
@ -0,0 +1,28 @@ |
|||
/*
|
|||
This file is part of cpp-ethereum. |
|||
|
|||
cpp-ethereum is free software: you can redistribute it and/or modify |
|||
it under the terms of the GNU General Public License as published by |
|||
the Free Software Foundation, either version 3 of the License, or |
|||
(at your option) any later version. |
|||
|
|||
cpp-ethereum is distributed in the hope that it will be useful, |
|||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
GNU General Public License for more details. |
|||
|
|||
You should have received a copy of the GNU General Public License |
|||
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
/** @file PeerNetwork.cpp
|
|||
* @author Gav Wood <i@gavwood.com> |
|||
* @date 2014 |
|||
*/ |
|||
|
|||
#include "CommonNet.h" |
|||
using namespace std; |
|||
using namespace dev; |
|||
using namespace dev::eth; |
|||
|
|||
#pragma GCC diagnostic ignored "-Wunused-variable" |
|||
namespace { char dummy; }; |
@ -0,0 +1,74 @@ |
|||
/*
|
|||
This file is part of cpp-ethereum. |
|||
|
|||
cpp-ethereum is free software: you can redistribute it and/or modify |
|||
it under the terms of the GNU General Public License as published by |
|||
the Free Software Foundation, either version 3 of the License, or |
|||
(at your option) any later version. |
|||
|
|||
cpp-ethereum is distributed in the hope that it will be useful, |
|||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
GNU General Public License for more details. |
|||
|
|||
You should have received a copy of the GNU General Public License |
|||
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
/** @file PeerNetwork.h
|
|||
* @author Gav Wood <i@gavwood.com> |
|||
* @date 2014 |
|||
* |
|||
* Miscellanea required for the PeerServer/Session classes. |
|||
*/ |
|||
|
|||
#pragma once |
|||
|
|||
#include <string> |
|||
#include <chrono> |
|||
#include <libdevcore/Common.h> |
|||
#include <libdevcore/Log.h> |
|||
|
|||
namespace dev |
|||
{ |
|||
namespace eth |
|||
{ |
|||
|
|||
#if ETH_DEBUG |
|||
static const unsigned c_maxHashes = 64; ///< Maximum number of hashes BlockHashes will ever send.
|
|||
static const unsigned c_maxHashesAsk = 64; ///< Maximum number of hashes GetBlockHashes will ever ask for.
|
|||
static const unsigned c_maxBlocks = 32; ///< Maximum number of blocks Blocks will ever send.
|
|||
static const unsigned c_maxBlocksAsk = 32; ///< Maximum number of blocks we ask to receive in Blocks (when using GetChain).
|
|||
#else |
|||
static const unsigned c_maxHashes = 256; ///< Maximum number of hashes BlockHashes will ever send.
|
|||
static const unsigned c_maxHashesAsk = 256; ///< Maximum number of hashes GetBlockHashes will ever ask for.
|
|||
static const unsigned c_maxBlocks = 128; ///< Maximum number of blocks Blocks will ever send.
|
|||
static const unsigned c_maxBlocksAsk = 128; ///< Maximum number of blocks we ask to receive in Blocks (when using GetChain).
|
|||
#endif |
|||
class OverlayDB; |
|||
class BlockChain; |
|||
class TransactionQueue; |
|||
class EthereumHost; |
|||
class EthereumPeer; |
|||
|
|||
enum EthereumPacket |
|||
{ |
|||
StatusPacket = 0x10, |
|||
GetTransactionsPacket, |
|||
TransactionsPacket, |
|||
GetBlockHashesPacket, |
|||
BlockHashesPacket, |
|||
GetBlocksPacket, |
|||
BlocksPacket, |
|||
}; |
|||
|
|||
enum class Grabbing |
|||
{ |
|||
State, |
|||
Hashes, |
|||
Chain, |
|||
ChainHelper, |
|||
Nothing |
|||
}; |
|||
|
|||
} |
|||
} |
@ -0,0 +1,75 @@ |
|||
/*
|
|||
This file is part of cpp-ethereum. |
|||
|
|||
cpp-ethereum is free software: you can redistribute it and/or modify |
|||
it under the terms of the GNU General Public License as published by |
|||
the Free Software Foundation, either version 3 of the License, or |
|||
(at your option) any later version. |
|||
|
|||
cpp-ethereum is distributed in the hope that it will be useful, |
|||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
GNU General Public License for more details. |
|||
|
|||
You should have received a copy of the GNU General Public License |
|||
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
/** @file DownloadMan.cpp
|
|||
* @author Gav Wood <i@gavwood.com> |
|||
* @date 2014 |
|||
*/ |
|||
|
|||
#include "DownloadMan.h" |
|||
using namespace std; |
|||
using namespace dev; |
|||
using namespace dev::eth; |
|||
|
|||
DownloadSub::DownloadSub(DownloadMan& _man): m_man(&_man) |
|||
{ |
|||
WriteGuard l(m_man->x_subs); |
|||
m_man->m_subs.insert(this); |
|||
} |
|||
|
|||
DownloadSub::~DownloadSub() |
|||
{ |
|||
if (m_man) |
|||
{ |
|||
WriteGuard l(m_man->x_subs); |
|||
m_man->m_subs.erase(this); |
|||
} |
|||
} |
|||
|
|||
h256Set DownloadSub::nextFetch(unsigned _n) |
|||
{ |
|||
Guard l(m_fetch); |
|||
|
|||
if (m_remaining.size()) |
|||
return m_remaining; |
|||
|
|||
m_asked.clear(); |
|||
m_indices.clear(); |
|||
m_remaining.clear(); |
|||
|
|||
if (!m_man) |
|||
return h256Set(); |
|||
|
|||
m_asked = (~(m_man->taken() + m_attempted)).lowest(_n); |
|||
if (m_asked.empty()) |
|||
m_asked = (~(m_man->taken(true) + m_attempted)).lowest(_n); |
|||
m_attempted += m_asked; |
|||
for (auto i: m_asked) |
|||
{ |
|||
auto x = m_man->m_chain[i]; |
|||
m_remaining.insert(x); |
|||
m_indices[x] = i; |
|||
} |
|||
return m_remaining; |
|||
} |
|||
|
|||
void DownloadSub::noteBlock(h256 _hash) |
|||
{ |
|||
Guard l(m_fetch); |
|||
if (m_man && m_indices.count(_hash)) |
|||
m_man->m_blocksGot += m_indices[_hash]; |
|||
m_remaining.erase(_hash); |
|||
} |
@ -0,0 +1,136 @@ |
|||
/*
|
|||
This file is part of cpp-ethereum. |
|||
|
|||
cpp-ethereum is free software: you can redistribute it and/or modify |
|||
it under the terms of the GNU General Public License as published by |
|||
the Free Software Foundation, either version 3 of the License, or |
|||
(at your option) any later version. |
|||
|
|||
cpp-ethereum is distributed in the hope that it will be useful, |
|||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
GNU General Public License for more details. |
|||
|
|||
You should have received a copy of the GNU General Public License |
|||
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
/** @file DownloadMan.h
|
|||
* @author Gav Wood <i@gavwood.com> |
|||
* @date 2014 |
|||
*/ |
|||
|
|||
#pragma once |
|||
|
|||
#include <map> |
|||
#include <vector> |
|||
#include <set> |
|||
#include <libdevcore/Guards.h> |
|||
#include <libdevcore/Worker.h> |
|||
#include <libdevcore/RangeMask.h> |
|||
#include <libdevcore/FixedHash.h> |
|||
|
|||
namespace dev |
|||
{ |
|||
|
|||
namespace eth |
|||
{ |
|||
|
|||
class DownloadMan; |
|||
|
|||
class DownloadSub |
|||
{ |
|||
friend class DownloadMan; |
|||
|
|||
public: |
|||
DownloadSub(DownloadMan& _man); |
|||
~DownloadSub(); |
|||
|
|||
/// Finished last fetch - grab the next bunch of block hashes to download.
|
|||
h256Set nextFetch(unsigned _n); |
|||
|
|||
/// Note that we've received a particular block.
|
|||
void noteBlock(h256 _hash); |
|||
|
|||
/// Nothing doing here.
|
|||
void doneFetch() { resetFetch(); } |
|||
|
|||
RangeMask<unsigned> const& asked() const { return m_asked; } |
|||
RangeMask<unsigned> const& attemped() const { return m_attempted; } |
|||
|
|||
private: |
|||
void resetFetch() // Called by DownloadMan when we need to reset the download.
|
|||
{ |
|||
Guard l(m_fetch); |
|||
m_remaining.clear(); |
|||
m_indices.clear(); |
|||
m_asked.clear(); |
|||
m_attempted.clear(); |
|||
} |
|||
|
|||
DownloadMan* m_man = nullptr; |
|||
|
|||
Mutex m_fetch; |
|||
h256Set m_remaining; |
|||
std::map<h256, unsigned> m_indices; |
|||
RangeMask<unsigned> m_asked; |
|||
RangeMask<unsigned> m_attempted; |
|||
}; |
|||
|
|||
class DownloadMan |
|||
{ |
|||
friend class DownloadSub; |
|||
|
|||
public: |
|||
~DownloadMan() |
|||
{ |
|||
for (auto i: m_subs) |
|||
i->m_man = nullptr; |
|||
} |
|||
|
|||
void resetToChain(h256s const& _chain) |
|||
{ |
|||
{ |
|||
ReadGuard l(x_subs); |
|||
for (auto i: m_subs) |
|||
i->resetFetch(); |
|||
} |
|||
m_chain.clear(); |
|||
m_chain.reserve(_chain.size()); |
|||
for (auto i = _chain.rbegin(); i != _chain.rend(); ++i) |
|||
m_chain.push_back(*i); |
|||
m_blocksGot = RangeMask<unsigned>(0, m_chain.size()); |
|||
} |
|||
|
|||
RangeMask<unsigned> taken(bool _desperate = false) const |
|||
{ |
|||
auto ret = m_blocksGot; |
|||
if (!_desperate) |
|||
{ |
|||
ReadGuard l(x_subs); |
|||
for (auto i: m_subs) |
|||
ret += i->m_asked; |
|||
} |
|||
return ret; |
|||
} |
|||
|
|||
bool isComplete() const |
|||
{ |
|||
return m_blocksGot.full(); |
|||
} |
|||
|
|||
h256s chain() const { return m_chain; } |
|||
void foreachSub(std::function<void(DownloadSub const&)> const& _f) const { ReadGuard l(x_subs); for(auto i: m_subs) _f(*i); } |
|||
unsigned subCount() const { ReadGuard l(x_subs); return m_subs.size(); } |
|||
RangeMask<unsigned> blocksGot() const { return m_blocksGot; } |
|||
|
|||
private: |
|||
h256s m_chain; |
|||
RangeMask<unsigned> m_blocksGot; |
|||
|
|||
mutable SharedMutex x_subs; |
|||
std::set<DownloadSub*> m_subs; |
|||
}; |
|||
|
|||
} |
|||
|
|||
} |
@ -0,0 +1,281 @@ |
|||
/*
|
|||
This file is part of cpp-ethereum. |
|||
|
|||
cpp-ethereum is free software: you can redistribute it and/or modify |
|||
it under the terms of the GNU General Public License as published by |
|||
the Free Software Foundation, either version 3 of the License, or |
|||
(at your option) any later version. |
|||
|
|||
cpp-ethereum is distributed in the hope that it will be useful, |
|||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
GNU General Public License for more details. |
|||
|
|||
You should have received a copy of the GNU General Public License |
|||
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
/** @file EthereumHost.cpp
|
|||
* @author Gav Wood <i@gavwood.com> |
|||
* @date 2014 |
|||
*/ |
|||
|
|||
#include "EthereumHost.h" |
|||
|
|||
#include <set> |
|||
#include <chrono> |
|||
#include <thread> |
|||
#include <libdevcore/Common.h> |
|||
#include <libp2p/Host.h> |
|||
#include <libp2p/Session.h> |
|||
#include <libethcore/Exceptions.h> |
|||
#include "BlockChain.h" |
|||
#include "TransactionQueue.h" |
|||
#include "BlockQueue.h" |
|||
#include "EthereumPeer.h" |
|||
#include "DownloadMan.h" |
|||
using namespace std; |
|||
using namespace dev; |
|||
using namespace dev::eth; |
|||
using namespace p2p; |
|||
|
|||
EthereumHost::EthereumHost(BlockChain const& _ch, TransactionQueue& _tq, BlockQueue& _bq, u256 _networkId): |
|||
HostCapability<EthereumPeer>(), |
|||
Worker ("ethsync"), |
|||
m_chain (_ch), |
|||
m_tq (_tq), |
|||
m_bq (_bq), |
|||
m_networkId (_networkId) |
|||
{ |
|||
m_latestBlockSent = _ch.currentHash(); |
|||
} |
|||
|
|||
EthereumHost::~EthereumHost() |
|||
{ |
|||
for (auto const& i: peers()) |
|||
i->cap<EthereumPeer>()->giveUpOnFetch(); |
|||
} |
|||
|
|||
bool EthereumHost::ensureInitialised(TransactionQueue& _tq) |
|||
{ |
|||
if (!m_latestBlockSent) |
|||
{ |
|||
// First time - just initialise.
|
|||
m_latestBlockSent = m_chain.currentHash(); |
|||
clog(NetNote) << "Initialising: latest=" << m_latestBlockSent.abridged(); |
|||
|
|||
for (auto const& i: _tq.transactions()) |
|||
m_transactionsSent.insert(i.first); |
|||
return true; |
|||
} |
|||
return false; |
|||
} |
|||
|
|||
void EthereumHost::noteHavePeerState(EthereumPeer* _who) |
|||
{ |
|||
clog(NetAllDetail) << "Have peer state."; |
|||
|
|||
// if already downloading hash-chain, ignore.
|
|||
if (m_grabbing != Grabbing::Nothing) |
|||
{ |
|||
clog(NetAllDetail) << "Already downloading chain. Just set to help out."; |
|||
_who->ensureGettingChain(); |
|||
return; |
|||
} |
|||
|
|||
// otherwise check to see if we should be downloading...
|
|||
_who->tryGrabbingHashChain(); |
|||
} |
|||
|
|||
void EthereumHost::updateGrabbing(Grabbing _g) |
|||
{ |
|||
m_grabbing = _g; |
|||
if (_g == Grabbing::Nothing) |
|||
readyForSync(); |
|||
else if (_g == Grabbing::Chain) |
|||
for (auto j: peers()) |
|||
j->cap<EthereumPeer>()->ensureGettingChain(); |
|||
} |
|||
|
|||
void EthereumHost::noteHaveChain(EthereumPeer* _from) |
|||
{ |
|||
auto td = _from->m_totalDifficulty; |
|||
|
|||
if (_from->m_neededBlocks.empty()) |
|||
{ |
|||
_from->m_grabbing = Grabbing::Nothing; |
|||
updateGrabbing(Grabbing::Nothing); |
|||
return; |
|||
} |
|||
|
|||
clog(NetNote) << "Hash-chain COMPLETE:" << _from->m_totalDifficulty << "vs" << m_chain.details().totalDifficulty << ";" << _from->m_neededBlocks.size() << " blocks, ends" << _from->m_neededBlocks.back().abridged(); |
|||
|
|||
if (td < m_chain.details().totalDifficulty || (td == m_chain.details().totalDifficulty && m_chain.currentHash() == _from->m_latestHash)) |
|||
{ |
|||
clog(NetNote) << "Difficulty of hashchain not HIGHER. Ignoring."; |
|||
_from->m_grabbing = Grabbing::Nothing; |
|||
updateGrabbing(Grabbing::Nothing); |
|||
return; |
|||
} |
|||
|
|||
clog(NetNote) << "Difficulty of hashchain HIGHER. Replacing fetch queue [latest now" << _from->m_latestHash.abridged() << ", was" << m_latestBlockSent.abridged() << "]"; |
|||
|
|||
// Looks like it's the best yet for total difficulty. Set to download.
|
|||
m_man.resetToChain(_from->m_neededBlocks); |
|||
m_latestBlockSent = _from->m_latestHash; |
|||
|
|||
_from->m_grabbing = Grabbing::Chain; |
|||
updateGrabbing(Grabbing::Chain); |
|||
} |
|||
|
|||
void EthereumHost::readyForSync() |
|||
{ |
|||
// start grabbing next hash chain if there is one.
|
|||
for (auto j: peers()) |
|||
{ |
|||
j->cap<EthereumPeer>()->tryGrabbingHashChain(); |
|||
if (j->cap<EthereumPeer>()->m_grabbing == Grabbing::Hashes) |
|||
{ |
|||
m_grabbing = Grabbing::Hashes; |
|||
return; |
|||
} |
|||
} |
|||
clog(NetNote) << "No more peers to sync with."; |
|||
} |
|||
|
|||
void EthereumHost::noteDoneBlocks(EthereumPeer* _who) |
|||
{ |
|||
if (m_man.isComplete()) |
|||
{ |
|||
// Done our chain-get.
|
|||
clog(NetNote) << "Chain download complete."; |
|||
updateGrabbing(Grabbing::Nothing); |
|||
} |
|||
if (_who->m_grabbing == Grabbing::Chain) |
|||
{ |
|||
// Done our chain-get.
|
|||
clog(NetNote) << "Chain download failed. Peer with blocks didn't have them all. This peer is bad and should be punished."; |
|||
// TODO: note that peer is BADBADBAD!
|
|||
updateGrabbing(Grabbing::Nothing); |
|||
} |
|||
} |
|||
|
|||
bool EthereumHost::noteBlock(h256 _hash, bytesConstRef _data) |
|||
{ |
|||
if (!m_chain.details(_hash)) |
|||
{ |
|||
lock_guard<recursive_mutex> l(m_incomingLock); |
|||
m_incomingBlocks.push_back(_data.toBytes()); |
|||
return true; |
|||
} |
|||
return false; |
|||
} |
|||
|
|||
void EthereumHost::doWork() |
|||
{ |
|||
bool netChange = ensureInitialised(m_tq); |
|||
auto h = m_chain.currentHash(); |
|||
maintainTransactions(m_tq, h); |
|||
maintainBlocks(m_bq, h); |
|||
// return netChange;
|
|||
// TODO: Figure out what to do with netChange.
|
|||
(void)netChange; |
|||
} |
|||
|
|||
void EthereumHost::maintainTransactions(TransactionQueue& _tq, h256 _currentHash) |
|||
{ |
|||
bool resendAll = (_currentHash != m_latestBlockSent); |
|||
{ |
|||
lock_guard<recursive_mutex> l(m_incomingLock); |
|||
for (auto it = m_incomingTransactions.begin(); it != m_incomingTransactions.end(); ++it) |
|||
if (_tq.import(&*it)) |
|||
{}//ret = true; // just putting a transaction in the queue isn't enough to change the state - it might have an invalid nonce...
|
|||
else |
|||
m_transactionsSent.insert(sha3(*it)); // if we already had the transaction, then don't bother sending it on.
|
|||
m_incomingTransactions.clear(); |
|||
} |
|||
|
|||
// Send any new transactions.
|
|||
for (auto const& p: peers()) |
|||
{ |
|||
auto ep = p->cap<EthereumPeer>(); |
|||
if (ep) |
|||
{ |
|||
bytes b; |
|||
unsigned n = 0; |
|||
for (auto const& i: _tq.transactions()) |
|||
if ((!m_transactionsSent.count(i.first) && !ep->m_knownTransactions.count(i.first)) || ep->m_requireTransactions || resendAll) |
|||
{ |
|||
b += i.second; |
|||
++n; |
|||
m_transactionsSent.insert(i.first); |
|||
} |
|||
ep->clearKnownTransactions(); |
|||
|
|||
if (n) |
|||
{ |
|||
RLPStream ts; |
|||
EthereumPeer::prep(ts); |
|||
ts.appendList(n + 1) << TransactionsPacket; |
|||
ts.appendRaw(b, n).swapOut(b); |
|||
seal(b); |
|||
ep->send(&b); |
|||
} |
|||
ep->m_requireTransactions = false; |
|||
} |
|||
} |
|||
} |
|||
|
|||
void EthereumHost::reset() |
|||
{ |
|||
m_grabbing = Grabbing::Nothing; |
|||
|
|||
m_man.resetToChain(h256s()); |
|||
|
|||
m_incomingTransactions.clear(); |
|||
m_incomingBlocks.clear(); |
|||
|
|||
m_latestBlockSent = h256(); |
|||
m_transactionsSent.clear(); |
|||
} |
|||
|
|||
void EthereumHost::maintainBlocks(BlockQueue& _bq, h256 _currentHash) |
|||
{ |
|||
// Import new blocks
|
|||
{ |
|||
lock_guard<recursive_mutex> l(m_incomingLock); |
|||
for (auto it = m_incomingBlocks.rbegin(); it != m_incomingBlocks.rend(); ++it) |
|||
if (_bq.import(&*it, m_chain)) |
|||
{} |
|||
else{} // TODO: don't forward it.
|
|||
m_incomingBlocks.clear(); |
|||
} |
|||
|
|||
// If we've finished our initial sync send any new blocks.
|
|||
if (m_grabbing == Grabbing::Nothing && m_chain.details(m_latestBlockSent) && m_chain.details(m_latestBlockSent).totalDifficulty < m_chain.details(_currentHash).totalDifficulty) |
|||
{ |
|||
RLPStream ts; |
|||
EthereumPeer::prep(ts); |
|||
bytes bs; |
|||
unsigned c = 0; |
|||
for (auto h: m_chain.treeRoute(m_latestBlockSent, _currentHash, nullptr, false, true)) |
|||
{ |
|||
bs += m_chain.block(h); |
|||
++c; |
|||
} |
|||
clog(NetMessageSummary) << "Sending" << c << "new blocks (current is" << _currentHash << ", was" << m_latestBlockSent << ")"; |
|||
ts.appendList(1 + c).append(BlocksPacket).appendRaw(bs, c); |
|||
bytes b; |
|||
ts.swapOut(b); |
|||
seal(b); |
|||
|
|||
for (auto j: peers()) |
|||
{ |
|||
auto p = j->cap<EthereumPeer>(); |
|||
Guard l(p->x_knownBlocks); |
|||
if (!p->m_knownBlocks.count(_currentHash)) |
|||
p->send(&b); |
|||
p->m_knownBlocks.clear(); |
|||
} |
|||
m_latestBlockSent = _currentHash; |
|||
} |
|||
} |
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue