Compare commits
28 Commits
lash/chain
...
master
Author | SHA1 | Date | |
---|---|---|---|
|
6dc4887b2f | ||
|
bd2bf4bb03 | ||
|
adcdcd704e | ||
|
ca059c5b30 | ||
|
30172798c0 | ||
|
df02af8b6d | ||
|
0a44ceb364 | ||
|
f49e4149fd | ||
|
7c0df3b967 | ||
|
acbbebd8da | ||
|
96f58c5f41 | ||
|
0707291f8f | ||
|
ed7f0a3f71 | ||
|
2fc3d4da0c | ||
|
5fc27671da | ||
|
8f86e9c970 | ||
|
abc619d7b2 | ||
|
42aa809500 | ||
|
e31367853c | ||
|
9522729fa0 | ||
|
097a6f4b53 | ||
|
8d0a1f589b | ||
|
24a71b6c7f | ||
|
b893aaa7b1 | ||
|
ab1977b802 | ||
|
3d39fea7f8 | ||
|
b19b948be3 | ||
|
f961345652 |
1
.gitignore
vendored
1
.gitignore
vendored
@ -6,3 +6,4 @@ build/
|
|||||||
*.egg-info
|
*.egg-info
|
||||||
*.sqlite
|
*.sqlite
|
||||||
.coverage
|
.coverage
|
||||||
|
.chaind
|
||||||
|
2
CHANGELOG
Normal file
2
CHANGELOG
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
- 0.3.2
|
||||||
|
* Change license to AGPL3 and copyright waived to public domain
|
141
LICENSE
141
LICENSE
@ -1,5 +1,5 @@
|
|||||||
GNU GENERAL PUBLIC LICENSE
|
GNU AFFERO GENERAL PUBLIC LICENSE
|
||||||
Version 3, 29 June 2007
|
Version 3, 19 November 2007
|
||||||
|
|
||||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||||
Everyone is permitted to copy and distribute verbatim copies
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
@ -7,17 +7,15 @@
|
|||||||
|
|
||||||
Preamble
|
Preamble
|
||||||
|
|
||||||
The GNU General Public License is a free, copyleft license for
|
The GNU Affero General Public License is a free, copyleft license for
|
||||||
software and other kinds of works.
|
software and other kinds of works, specifically designed to ensure
|
||||||
|
cooperation with the community in the case of network server software.
|
||||||
|
|
||||||
The licenses for most software and other practical works are designed
|
The licenses for most software and other practical works are designed
|
||||||
to take away your freedom to share and change the works. By contrast,
|
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
|
our General Public Licenses are intended to guarantee your freedom to
|
||||||
share and change all versions of a program--to make sure it remains free
|
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
|
software for all its users.
|
||||||
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
|
When we speak of free software, we are referring to freedom, not
|
||||||
price. Our General Public Licenses are designed to make sure that you
|
price. Our General Public Licenses are designed to make sure that you
|
||||||
@ -26,44 +24,34 @@ 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
|
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.
|
free programs, and that you know you can do these things.
|
||||||
|
|
||||||
To protect your rights, we need to prevent others from denying you
|
Developers that use our General Public Licenses protect your rights
|
||||||
these rights or asking you to surrender the rights. Therefore, you have
|
with two steps: (1) assert copyright on the software, and (2) offer
|
||||||
certain responsibilities if you distribute copies of the software, or if
|
you this License which gives you legal permission to copy, distribute
|
||||||
you modify it: responsibilities to respect the freedom of others.
|
and/or modify the software.
|
||||||
|
|
||||||
For example, if you distribute copies of such a program, whether
|
A secondary benefit of defending all users' freedom is that
|
||||||
gratis or for a fee, you must pass on to the recipients the same
|
improvements made in alternate versions of the program, if they
|
||||||
freedoms that you received. You must make sure that they, too, receive
|
receive widespread use, become available for other developers to
|
||||||
or can get the source code. And you must show them these terms so they
|
incorporate. Many developers of free software are heartened and
|
||||||
know their rights.
|
encouraged by the resulting cooperation. However, in the case of
|
||||||
|
software used on network servers, this result may fail to come about.
|
||||||
|
The GNU General Public License permits making a modified version and
|
||||||
|
letting the public access it on a server without ever releasing its
|
||||||
|
source code to the public.
|
||||||
|
|
||||||
Developers that use the GNU GPL protect your rights with two steps:
|
The GNU Affero General Public License is designed specifically to
|
||||||
(1) assert copyright on the software, and (2) offer you this License
|
ensure that, in such cases, the modified source code becomes available
|
||||||
giving you legal permission to copy, distribute and/or modify it.
|
to the community. It requires the operator of a network server to
|
||||||
|
provide the source code of the modified version running there to the
|
||||||
|
users of that server. Therefore, public use of a modified version, on
|
||||||
|
a publicly accessible server, gives the public access to the source
|
||||||
|
code of the modified version.
|
||||||
|
|
||||||
For the developers' and authors' protection, the GPL clearly explains
|
An older license, called the Affero General Public License and
|
||||||
that there is no warranty for this free software. For both users' and
|
published by Affero, was designed to accomplish similar goals. This is
|
||||||
authors' sake, the GPL requires that modified versions be marked as
|
a different license, not a version of the Affero GPL, but Affero has
|
||||||
changed, so that their problems will not be attributed erroneously to
|
released a new version of the Affero GPL which permits relicensing under
|
||||||
authors of previous versions.
|
this license.
|
||||||
|
|
||||||
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
|
The precise terms and conditions for copying, distribution and
|
||||||
modification follow.
|
modification follow.
|
||||||
@ -72,7 +60,7 @@ modification follow.
|
|||||||
|
|
||||||
0. Definitions.
|
0. Definitions.
|
||||||
|
|
||||||
"This License" refers to version 3 of the GNU General Public License.
|
"This License" refers to version 3 of the GNU Affero General Public License.
|
||||||
|
|
||||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||||
works, such as semiconductor masks.
|
works, such as semiconductor masks.
|
||||||
@ -549,35 +537,45 @@ 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
|
the Program, the only way you could satisfy both those terms and this
|
||||||
License would be to refrain entirely from conveying the Program.
|
License would be to refrain entirely from conveying the Program.
|
||||||
|
|
||||||
13. Use with the GNU Affero General Public License.
|
13. Remote Network Interaction; Use with the GNU General Public License.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, if you modify the
|
||||||
|
Program, your modified version must prominently offer all users
|
||||||
|
interacting with it remotely through a computer network (if your version
|
||||||
|
supports such interaction) an opportunity to receive the Corresponding
|
||||||
|
Source of your version by providing access to the Corresponding Source
|
||||||
|
from a network server at no charge, through some standard or customary
|
||||||
|
means of facilitating copying of software. This Corresponding Source
|
||||||
|
shall include the Corresponding Source for any work covered by version 3
|
||||||
|
of the GNU General Public License that is incorporated pursuant to the
|
||||||
|
following paragraph.
|
||||||
|
|
||||||
Notwithstanding any other provision of this License, you have
|
Notwithstanding any other provision of this License, you have
|
||||||
permission to link or combine any covered work with a work licensed
|
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
|
under version 3 of the GNU General Public License into a single
|
||||||
combined work, and to convey the resulting work. The terms of this
|
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,
|
License will continue to apply to the part which is the covered work,
|
||||||
but the special requirements of the GNU Affero General Public License,
|
but the work with which it is combined will remain governed by version
|
||||||
section 13, concerning interaction through a network will apply to the
|
3 of the GNU General Public License.
|
||||||
combination as such.
|
|
||||||
|
|
||||||
14. Revised Versions of this License.
|
14. Revised Versions of this License.
|
||||||
|
|
||||||
The Free Software Foundation may publish revised and/or new versions of
|
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
|
the GNU Affero General Public License from time to time. Such new versions
|
||||||
be similar in spirit to the present version, but may differ in detail to
|
will be similar in spirit to the present version, but may differ in detail to
|
||||||
address new problems or concerns.
|
address new problems or concerns.
|
||||||
|
|
||||||
Each version is given a distinguishing version number. If the
|
Each version is given a distinguishing version number. If the
|
||||||
Program specifies that a certain numbered version of the GNU General
|
Program specifies that a certain numbered version of the GNU Affero General
|
||||||
Public License "or any later version" applies to it, you have the
|
Public License "or any later version" applies to it, you have the
|
||||||
option of following the terms and conditions either of that numbered
|
option of following the terms and conditions either of that numbered
|
||||||
version or of any later version published by the Free Software
|
version or of any later version published by the Free Software
|
||||||
Foundation. If the Program does not specify a version number of the
|
Foundation. If the Program does not specify a version number of the
|
||||||
GNU General Public License, you may choose any version ever published
|
GNU Affero General Public License, you may choose any version ever published
|
||||||
by the Free Software Foundation.
|
by the Free Software Foundation.
|
||||||
|
|
||||||
If the Program specifies that a proxy can decide which future
|
If the Program specifies that a proxy can decide which future
|
||||||
versions of the GNU General Public License can be used, that proxy's
|
versions of the GNU Affero General Public License can be used, that proxy's
|
||||||
public statement of acceptance of a version permanently authorizes you
|
public statement of acceptance of a version permanently authorizes you
|
||||||
to choose that version for the Program.
|
to choose that version for the Program.
|
||||||
|
|
||||||
@ -635,40 +633,29 @@ the "copyright" line and a pointer to where the full notice is found.
|
|||||||
Copyright (C) <year> <name of author>
|
Copyright (C) <year> <name of author>
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
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
|
it under the terms of the GNU Affero General Public License as published by
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU Affero General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU Affero General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
Also add information on how to contact you by electronic and paper mail.
|
Also add information on how to contact you by electronic and paper mail.
|
||||||
|
|
||||||
If the program does terminal interaction, make it output a short
|
If your software can interact with users remotely through a computer
|
||||||
notice like this when it starts in an interactive mode:
|
network, you should also make sure that it provides a way for users to
|
||||||
|
get its source. For example, if your program is a web application, its
|
||||||
<program> Copyright (C) <year> <name of author>
|
interface could display a "Source" link that leads users to an archive
|
||||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
of the code. There are many ways you could offer source, and different
|
||||||
This is free software, and you are welcome to redistribute it
|
solutions will be better for different programs; see section 13 for the
|
||||||
under certain conditions; type `show c' for details.
|
specific requirements.
|
||||||
|
|
||||||
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,
|
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.
|
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
|
For more information on this, and how to apply and follow the GNU AGPL, see
|
||||||
<https://www.gnu.org/licenses/>.
|
<https://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
|
|
||||||
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
|
||||||
|
@ -1 +1 @@
|
|||||||
include *requirements.txt LICENSE chaind/eth/data/config/* chaind/eth/data/config/syncer/*
|
include *requirements.txt LICENSE WAIVER WAIVER.asc CHANGELOG chaind/eth/data/config/* chaind/eth/data/config/syncer/*
|
||||||
|
17
WAIVER
Normal file
17
WAIVER
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
# Copyright waiver for the python package "chaind-eth"
|
||||||
|
|
||||||
|
I dedicate any and all copyright interest in this software to the
|
||||||
|
public domain. I make this dedication for the benefit of the public at
|
||||||
|
large and to the detriment of my heirs and successors. I intend this
|
||||||
|
dedication to be an overt act of relinquishment in perpetuity of all
|
||||||
|
present and future rights to this software under copyright law.
|
||||||
|
|
||||||
|
To the best of my knowledge and belief, my contributions are either
|
||||||
|
originally authored by me or are derived from prior works which I have
|
||||||
|
verified are also in the public domain and are not subject to claims
|
||||||
|
of copyright by other parties.
|
||||||
|
|
||||||
|
To the best of my knowledge and belief, no individual, business,
|
||||||
|
organization, government, or other entity has any copyright interest
|
||||||
|
in my contributions, and I affirm that I will not make contributions
|
||||||
|
that are otherwise encumbered.
|
29
WAIVER.asc
Normal file
29
WAIVER.asc
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
-----BEGIN PGP MESSAGE-----
|
||||||
|
|
||||||
|
owGVU2tQVFUc3wUUuAyIsFAzhBzQYSoWGl4aqQyPDHBQEhphHAru3j27e+Tuvct9
|
||||||
|
sK6kmRiPLAKaDVnwQeZA8rLIBBkoYKJhKLNgBK2BIBoGkSkrVJRH5+6CWn3qw87s
|
||||||
|
vef//z3PLXO1lznJ/X+Y6ijuqXtJ3mTPqdamxybt3ZFK5f7ethHEswYTh7Q6ARhJ
|
||||||
|
lAc5oGE5IOggMJgEHcsAA0nlkFoIAigdiRh1MBR0AQSRBNRQjShSgIBkTPinBiRN
|
||||||
|
A+ohGGIEyEFe+oPREA94ViMYSQ4CgZXgCYOoohEF1Kwew4aAJKAnc6BtdAUaYfZV
|
||||||
|
MSrIQA0SAKuxabMtkwJBk5wWWvltuHhZ4JAeMtZZvQnoIOJ46wAvUhTkeZbjJTpJ
|
||||||
|
oLSFCYnHCDGKSsIDLM5CACRlxeEgjZhcEfE6KzL2ZICcAQoiEkzSOfZOGLBd6VCi
|
||||||
|
0oiCiK1ao+Btyh6PQGTUOOhHYdGkMYQgXmFXrPKr2nMY1khD9YpBFRYBNUrpgGIZ
|
||||||
|
7FIlSpKxOQwJEd7lCBYDIgbLwZ2IuD8O4j0T0EOAg5TmMDFuGSvkWD0wcAi/NrJc
|
||||||
|
Dg+MOkTpcC46Mg8S2DvSIDwmrZA0z9pqfBi8rTVb7XiCYQWcrmo/xGlhsxRNIj1P
|
||||||
|
YA+PLGIRrKQQ3ydOQJD/H34ZiV2N8pBaJGklUIk8YnCPSmxWSzLooLU4JdBKjTFS
|
||||||
|
P0rJrI0NP0kV6Ujeek//ez8JbOPfgSqt9EmA1GgQp8ciSQE/GRG+4JJT60X9xwJh
|
||||||
|
HZGSsLIaEY8LYShRr8Ic6hCixC7cQSZ3kvl6+zs4Bc7WGoI3FPVNFO1Z/SrX2Enf
|
||||||
|
ooxwdl9947jDXXZ+Kf5OfkV5bdDHQe09bp/HD9zsEmoOeyqqA7Lzi1/tq0Qu33Rl
|
||||||
|
NDvdstTeyDBv/wyevOVVNKsMvNSg2DY22ZgSM2E8U1vuvfVUofLMVbusgxdaXd+o
|
||||||
|
mnb28Y7Maus5l/tR5ahHKXi5/H76jO/tL9boxczm152PeuV0fD/zZGaip5/M+7n9
|
||||||
|
fy33Za13mGkvhcMp+4wuy1Pxx2cjzAsPPjFHlQ26X+r4aX39z/mbEoMmHVroGr+y
|
||||||
|
3aZtTxMDMz5/mhq/9vRq7Y10/eXC2rzOyMvHqzxqA4/IN9w/N3qjfzHafD6u1zHd
|
||||||
|
F+R+tStOefqDCKdM/4SRN0M615HDB54N8NjYM11Qtlii1x57cWRnVsJZ4mpdU11r
|
||||||
|
2hMTsd3JHrvvUkfq3fSOhrsN7xz2ubhcMpdnb5e2WHA7fGFve/ODZ+a2tJGWwhPj
|
||||||
|
UVtBaP3Cp98eG2ssTrVEzQ9vV3WcCkd31iafUMgz5C5Rw0uT393r8zNMmJIuftg7
|
||||||
|
7tU1tYdtGok26GYaPJu7w14ruBy9nPrC2crTiqFNruu6B833Rso3H3hedXSs4td3
|
||||||
|
Kw7FKN7qTwhdlF2L6rBMnzRnH0p+zy3ix8KnwjZf3zckJLaAuWuKXbH9JfOZQTWy
|
||||||
|
66HvV+9MW6j+o7F0/GZVRtmV+JihQLrlynwNyIyct3Q2vD3KDsZ9mfrb4hZoGQge
|
||||||
|
88uOC1tK+Rs=
|
||||||
|
=Wuh/
|
||||||
|
-----END PGP MESSAGE-----
|
@ -21,7 +21,6 @@ class Normalizer(TxHexNormalizer, NoopNormalizer):
|
|||||||
hexathon.to_int(v)
|
hexathon.to_int(v)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
eth_normalizer = Normalizer()
|
eth_normalizer = Normalizer()
|
||||||
|
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
from chainlib.interface import ChainInterface
|
from chainlib.interface import ChainInterface
|
||||||
from chainlib.eth.block import (
|
from chainlib.eth.block import (
|
||||||
block_by_number,
|
block_by_number,
|
||||||
|
block_latest,
|
||||||
Block,
|
Block,
|
||||||
)
|
)
|
||||||
from chainlib.eth.tx import (
|
from chainlib.eth.tx import (
|
||||||
@ -16,3 +17,4 @@ class EthChainInterface(ChainInterface):
|
|||||||
self._block_from_src = Block.from_src
|
self._block_from_src = Block.from_src
|
||||||
self._tx_receipt = receipt
|
self._tx_receipt = receipt
|
||||||
self._src_normalize = Tx.src_normalize
|
self._src_normalize = Tx.src_normalize
|
||||||
|
self._block_latest = block_latest
|
||||||
|
@ -5,12 +5,5 @@ id =
|
|||||||
data_dir =
|
data_dir =
|
||||||
dispatch_delay = 0.01
|
dispatch_delay = 0.01
|
||||||
|
|
||||||
[database]
|
[tx]
|
||||||
engine =
|
digest_size = 32
|
||||||
name = chaind
|
|
||||||
driver =
|
|
||||||
user =
|
|
||||||
password =
|
|
||||||
host =
|
|
||||||
port =
|
|
||||||
debug = 0
|
|
||||||
|
165
chaind/eth/runnable/queuer.py
Normal file
165
chaind/eth/runnable/queuer.py
Normal file
@ -0,0 +1,165 @@
|
|||||||
|
# standard imports
|
||||||
|
import os
|
||||||
|
import logging
|
||||||
|
import signal
|
||||||
|
|
||||||
|
# external imports
|
||||||
|
import chainlib.eth.cli
|
||||||
|
from chainlib.eth.cli.arg import (
|
||||||
|
Arg,
|
||||||
|
ArgFlag,
|
||||||
|
process_args,
|
||||||
|
)
|
||||||
|
from chainlib.eth.cli.config import (
|
||||||
|
Config,
|
||||||
|
process_config,
|
||||||
|
)
|
||||||
|
from chainqueue.cli.arg import (
|
||||||
|
apply_arg as apply_arg_queue,
|
||||||
|
apply_flag as apply_flag_queue,
|
||||||
|
)
|
||||||
|
from chaind.cli.arg import (
|
||||||
|
apply_arg,
|
||||||
|
apply_flag,
|
||||||
|
)
|
||||||
|
from chaind.session import SessionController
|
||||||
|
from chaind.setup import Environment
|
||||||
|
from chaind.error import (
|
||||||
|
NothingToDoError,
|
||||||
|
ClientGoneError,
|
||||||
|
ClientBlockError,
|
||||||
|
ClientInputError,
|
||||||
|
)
|
||||||
|
from chainqueue import (
|
||||||
|
Store,
|
||||||
|
Status,
|
||||||
|
)
|
||||||
|
from chainqueue.error import DuplicateTxError
|
||||||
|
from chainqueue.store.fs import (
|
||||||
|
IndexStore,
|
||||||
|
CounterStore,
|
||||||
|
)
|
||||||
|
from chainqueue.cache import CacheTokenTx
|
||||||
|
from chainlib.encode import TxHexNormalizer
|
||||||
|
from chainlib.chain import ChainSpec
|
||||||
|
from chaind.adapters.fs import ChaindFsAdapter
|
||||||
|
from chaind.dispatch import DispatchProcessor
|
||||||
|
from chainqueue.data import config_dir as chainqueue_config_dir
|
||||||
|
from chaind.data import config_dir as chaind_config_dir
|
||||||
|
from chainlib.eth.cli.log import process_log
|
||||||
|
from chaind.cli.config import process_config as process_config_local
|
||||||
|
|
||||||
|
# local imports
|
||||||
|
from chaind.eth.cache import EthCacheTx
|
||||||
|
from chaind.eth.settings import ChaindSettings
|
||||||
|
from chaind.eth.dispatch import EthDispatcher
|
||||||
|
from chaind.eth.settings import process_settings
|
||||||
|
from chaind.settings import (
|
||||||
|
process_queue,
|
||||||
|
process_socket,
|
||||||
|
process_dispatch,
|
||||||
|
)
|
||||||
|
|
||||||
|
logging.basicConfig(level=logging.WARNING)
|
||||||
|
logg = logging.getLogger()
|
||||||
|
|
||||||
|
script_dir = os.path.dirname(os.path.realpath(__file__))
|
||||||
|
config_dir = os.path.join(script_dir, '..', 'data', 'config')
|
||||||
|
|
||||||
|
env = Environment(domain='eth', env=os.environ)
|
||||||
|
|
||||||
|
arg_flags = ArgFlag()
|
||||||
|
arg_flags = apply_flag_queue(arg_flags)
|
||||||
|
arg_flags = apply_flag(arg_flags)
|
||||||
|
|
||||||
|
arg = Arg(arg_flags)
|
||||||
|
arg = apply_arg_queue(arg)
|
||||||
|
arg = apply_arg(arg)
|
||||||
|
|
||||||
|
flags = arg_flags.STD_READ | arg_flags.QUEUE | arg_flags.STATE | arg_flags.SESSION
|
||||||
|
|
||||||
|
argparser = chainlib.eth.cli.ArgumentParser()
|
||||||
|
argparser = process_args(argparser, arg, flags)
|
||||||
|
args = argparser.parse_args()
|
||||||
|
|
||||||
|
logg = process_log(args, logg)
|
||||||
|
|
||||||
|
config = Config()
|
||||||
|
config.add_schema_dir(chainqueue_config_dir)
|
||||||
|
config.add_schema_dir(chaind_config_dir)
|
||||||
|
config = process_config(config, arg, args, flags)
|
||||||
|
config = process_config_local(config, arg, args, flags)
|
||||||
|
config.add('eth', 'CHAIND_ENGINE', False)
|
||||||
|
config.add('sync', 'CHAIND_COMPONENT', False)
|
||||||
|
logg.debug('config loaded:\n{}'.format(config))
|
||||||
|
|
||||||
|
settings = ChaindSettings(include_sync=True)
|
||||||
|
settings = process_settings(settings, config)
|
||||||
|
settings = process_queue(settings, config)
|
||||||
|
settings = process_socket(settings, config)
|
||||||
|
settings = process_dispatch(settings, config)
|
||||||
|
logg.debug('settings loaded:\n{}'.format(settings))
|
||||||
|
|
||||||
|
tx_normalizer = TxHexNormalizer().tx_hash
|
||||||
|
token_cache_store = CacheTokenTx(settings.get('CHAIN_SPEC'), normalizer=tx_normalizer)
|
||||||
|
|
||||||
|
dispatcher = EthDispatcher(settings.get('CONN'))
|
||||||
|
processor = DispatchProcessor(settings.get('CHAIN_SPEC'), settings.dir_for('queue'), dispatcher)
|
||||||
|
ctrl = SessionController(settings, processor.process)
|
||||||
|
|
||||||
|
signal.signal(signal.SIGINT, ctrl.shutdown)
|
||||||
|
signal.signal(signal.SIGTERM, ctrl.shutdown)
|
||||||
|
|
||||||
|
logg.info('session id is ' + settings.get('SESSION_ID'))
|
||||||
|
logg.info('session socket path is ' + settings.get('SESSION_SOCKET_PATH'))
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
global dispatcher, settings
|
||||||
|
|
||||||
|
queue_adapter = ChaindFsAdapter(
|
||||||
|
settings.get('CHAIN_SPEC'),
|
||||||
|
settings.dir_for('queue'),
|
||||||
|
EthCacheTx,
|
||||||
|
dispatcher,
|
||||||
|
store_sync=False,
|
||||||
|
)
|
||||||
|
|
||||||
|
while True:
|
||||||
|
v = None
|
||||||
|
client_socket = None
|
||||||
|
try:
|
||||||
|
(client_socket, v) = ctrl.get()
|
||||||
|
except ClientGoneError:
|
||||||
|
break
|
||||||
|
except ClientBlockError:
|
||||||
|
continue
|
||||||
|
except ClientInputError:
|
||||||
|
continue
|
||||||
|
except NothingToDoError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
if v == None:
|
||||||
|
ctrl.process(settings.get('CONN'))
|
||||||
|
#queue_adapter = create_adapter(settings, dispatcher)
|
||||||
|
continue
|
||||||
|
|
||||||
|
result_data = None
|
||||||
|
r = 0 # no error
|
||||||
|
try:
|
||||||
|
result_data = queue_adapter.put(v.hex())
|
||||||
|
except DuplicateTxError as e:
|
||||||
|
logg.error('tx already exists: {}'.format(e))
|
||||||
|
r = 1
|
||||||
|
except ValueError as e:
|
||||||
|
logg.error('adapter rejected input {}: "{}"'.format(v.hex(), e))
|
||||||
|
continue
|
||||||
|
|
||||||
|
if r == 0:
|
||||||
|
queue_adapter.enqueue(result_data)
|
||||||
|
|
||||||
|
ctrl.respond_put(client_socket, r, extra_data=result_data)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
@ -10,13 +10,40 @@ import socket
|
|||||||
|
|
||||||
# external imports
|
# external imports
|
||||||
import chainlib.eth.cli
|
import chainlib.eth.cli
|
||||||
|
from chainlib.eth.cli.arg import (
|
||||||
|
Arg,
|
||||||
|
ArgFlag,
|
||||||
|
process_args,
|
||||||
|
)
|
||||||
|
from chainlib.eth.cli.config import (
|
||||||
|
Config,
|
||||||
|
process_config,
|
||||||
|
)
|
||||||
from chaind.setup import Environment
|
from chaind.setup import Environment
|
||||||
from chainlib.eth.gas import price
|
from chainlib.eth.gas import price
|
||||||
from chainlib.chain import ChainSpec
|
from chainlib.chain import ChainSpec
|
||||||
from hexathon import strip_0x
|
from hexathon import strip_0x
|
||||||
|
from chainqueue.cli.arg import (
|
||||||
|
apply_arg as apply_arg_queue,
|
||||||
|
apply_flag as apply_flag_queue,
|
||||||
|
)
|
||||||
|
from chainqueue.data import config_dir as chainqueue_config_dir
|
||||||
|
from chaind.data import config_dir as chaind_config_dir
|
||||||
|
from chaind.cli.arg import (
|
||||||
|
apply_arg,
|
||||||
|
apply_flag,
|
||||||
|
)
|
||||||
|
from chainlib.eth.cli.log import process_log
|
||||||
|
from chaind.settings import process_queue
|
||||||
|
from chaind.settings import ChaindSettings
|
||||||
|
from chaind.error import TxSourceError
|
||||||
|
from chainlib.error import (
|
||||||
|
InitializationError,
|
||||||
|
SignerMissingException,
|
||||||
|
)
|
||||||
|
from chaind.cli.config import process_config as process_config_local
|
||||||
|
|
||||||
# local imports
|
# local imports
|
||||||
from chaind.error import TxSourceError
|
|
||||||
from chaind.eth.token.process import Processor
|
from chaind.eth.token.process import Processor
|
||||||
from chaind.eth.token.gas import GasTokenResolver
|
from chaind.eth.token.gas import GasTokenResolver
|
||||||
from chaind.eth.cli.csv import CSVProcessor
|
from chaind.eth.cli.csv import CSVProcessor
|
||||||
@ -24,53 +51,73 @@ from chaind.eth.cli.output import (
|
|||||||
Outputter,
|
Outputter,
|
||||||
OpMode,
|
OpMode,
|
||||||
)
|
)
|
||||||
|
from chaind.eth.settings import process_settings
|
||||||
|
|
||||||
logging.basicConfig(level=logging.WARNING)
|
|
||||||
logg = logging.getLogger()
|
logg = logging.getLogger()
|
||||||
|
|
||||||
script_dir = os.path.dirname(os.path.realpath(__file__))
|
|
||||||
config_dir = os.path.join(script_dir, '..', 'data', 'config')
|
def process_settings_local(settings, config):
|
||||||
|
# if settings.get('SIGNER') == None:
|
||||||
|
# raise SignerMissingException('signer missing')
|
||||||
|
return settings
|
||||||
|
|
||||||
|
|
||||||
arg_flags = chainlib.eth.cli.argflag_std_write
|
env = Environment(domain='eth', env=os.environ)
|
||||||
argparser = chainlib.eth.cli.ArgumentParser(arg_flags)
|
|
||||||
argparser.add_argument('--socket', dest='socket', type=str, help='Socket to send transactions to')
|
arg_flags = ArgFlag()
|
||||||
argparser.add_argument('--token-module', dest='token_module', type=str, help='Python module path to resolve tokens from identifiers')
|
arg_flags = apply_flag_queue(arg_flags)
|
||||||
argparser.add_positional('source', required=False, type=str, help='Transaction source file')
|
arg_flags = apply_flag(arg_flags)
|
||||||
|
|
||||||
|
arg = Arg(arg_flags)
|
||||||
|
arg = apply_arg_queue(arg)
|
||||||
|
arg = apply_arg(arg)
|
||||||
|
arg.set_long('s', 'send-rpc')
|
||||||
|
|
||||||
|
flags = arg_flags.STD_WRITE | arg_flags.TOKEN | arg_flags.SOCKET_CLIENT | arg_flags.STATE | arg_flags.WALLET | arg_flags.SESSION
|
||||||
|
|
||||||
|
argparser = chainlib.eth.cli.ArgumentParser()
|
||||||
|
argparser = process_args(argparser, arg, flags)
|
||||||
|
argparser.add_argument('source', help='Transaction source file')
|
||||||
args = argparser.parse_args()
|
args = argparser.parse_args()
|
||||||
|
|
||||||
extra_args = {
|
logg = process_log(args, logg)
|
||||||
'socket': None,
|
|
||||||
'source': None,
|
|
||||||
}
|
|
||||||
env = Environment(domain='eth', env=os.environ)
|
|
||||||
config = chainlib.eth.cli.Config.from_args(args, arg_flags, extra_args=extra_args, base_config_dir=config_dir)
|
|
||||||
config.add(args.token_module, 'TOKEN_MODULE', True)
|
|
||||||
|
|
||||||
wallet = chainlib.eth.cli.Wallet()
|
config = Config()
|
||||||
wallet.from_config(config)
|
config.add_schema_dir(chainqueue_config_dir)
|
||||||
|
config.add_schema_dir(chaind_config_dir)
|
||||||
|
config = process_config(config, arg, args, flags)
|
||||||
|
config = process_config_local(config, arg, args, flags)
|
||||||
|
config.add(args.source, '_SOURCE', False)
|
||||||
|
config.add('queue', 'CHAIND_COMPONENT', False)
|
||||||
|
config.add('eth', 'CHAIND_ENGINE', False)
|
||||||
|
logg.debug('config loaded:\n{}'.format(config))
|
||||||
|
|
||||||
rpc = chainlib.eth.cli.Rpc(wallet=wallet)
|
try:
|
||||||
conn = rpc.connect_by_config(config)
|
settings = ChaindSettings(include_sync=True)
|
||||||
|
settings = process_settings(settings, config)
|
||||||
chain_spec = ChainSpec.from_chain_str(config.get('CHAIN_SPEC'))
|
settings = process_queue(settings, config)
|
||||||
|
settings = process_settings_local(settings, config)
|
||||||
|
except InitializationError as e:
|
||||||
|
sys.stderr.write('Initialization error: ' + str(e) + '\n')
|
||||||
|
sys.exit(1)
|
||||||
|
logg.debug('settings loaded:\n{}'.format(settings))
|
||||||
|
|
||||||
mode = OpMode.STDOUT
|
mode = OpMode.STDOUT
|
||||||
|
|
||||||
re_unix = r'^ipc://(/.+)'
|
re_unix = r'^ipc://(/.+)'
|
||||||
m = re.match(re_unix, config.get('_SOCKET', ''))
|
m = re.match(re_unix, config.get('SESSION_SOCKET_PATH', ''))
|
||||||
if m != None:
|
if m != None:
|
||||||
config.add(m.group(1), '_SOCKET', exists_ok=True)
|
config.add(m.group(1), 'SESSION_SOCKET_PATH', exists_ok=True)
|
||||||
r = 0
|
r = 0
|
||||||
try:
|
try:
|
||||||
stat_info = os.stat(config.get('_SOCKET'))
|
stat_info = os.stat(config.get('SESSION_SOCKET_PATH'))
|
||||||
if not stat.S_ISSOCK(stat_info.st_mode):
|
if not stat.S_ISSOCK(stat_info.st_mode):
|
||||||
r = 1
|
r = 1
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
r = 1
|
r = 1
|
||||||
|
|
||||||
if r > 0:
|
if r > 0:
|
||||||
sys.stderr.write('{} is not a socket\n'.format(config.get('_SOCKET')))
|
sys.stderr.write('{} is not a socket\n'.format(config.get('SESSION_SOCKET_PATH')))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
mode = OpMode.UNIX
|
mode = OpMode.UNIX
|
||||||
@ -82,18 +129,46 @@ if config.get('_SOURCE') == None:
|
|||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
class SocketSender:
|
||||||
|
|
||||||
|
def __init__(self, settings):
|
||||||
|
self.path = settings.get('SESSION_SOCKET_PATH')
|
||||||
|
|
||||||
|
def send(self, tx):
|
||||||
|
s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
||||||
|
err = None
|
||||||
|
try:
|
||||||
|
s.connect(self.path)
|
||||||
|
except FileNotFoundError as e:
|
||||||
|
err = e
|
||||||
|
if err != None:
|
||||||
|
s.close()
|
||||||
|
raise err
|
||||||
|
s.sendall(tx.encode('utf-8'))
|
||||||
|
r = s.recv(68)
|
||||||
|
s.close()
|
||||||
|
return r
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
conn = settings.get('CONN')
|
||||||
token_resolver = None
|
token_resolver = None
|
||||||
if config.get('TOKEN_MODULE') != None:
|
if settings.get('TOKEN_MODULE') != None:
|
||||||
import importlib
|
import importlib
|
||||||
m = importlib.import_module(config.get('TOKEN_MODULE'))
|
m = importlib.import_module(settings.get('TOKEN_MODULE'))
|
||||||
m = m.TokenResolver
|
m = m.TokenResolver
|
||||||
else:
|
else:
|
||||||
from chaind.eth.token.gas import GasTokenResolver
|
from chaind.eth.token.gas import GasTokenResolver
|
||||||
m = GasTokenResolver
|
m = GasTokenResolver
|
||||||
token_resolver = m(chain_spec, rpc.get_sender_address(), rpc.get_signer(), rpc.get_gas_oracle(), rpc.get_nonce_oracle())
|
token_resolver = m(
|
||||||
|
settings.get('CHAIN_SPEC'),
|
||||||
|
settings.get('SENDER_ADDRESS'),
|
||||||
|
settings.get('SIGNER'),
|
||||||
|
settings.get('GAS_ORACLE'),
|
||||||
|
settings.get('NONCE_ORACLE'),
|
||||||
|
)
|
||||||
|
|
||||||
processor = Processor(token_resolver, config.get('_SOURCE'))
|
processor = Processor(token_resolver, config.get('_SOURCE'), use_checksum=not config.get('_UNSAFE'))
|
||||||
processor.add_processor(CSVProcessor())
|
processor.add_processor(CSVProcessor())
|
||||||
|
|
||||||
sends = None
|
sends = None
|
||||||
@ -103,6 +178,11 @@ def main():
|
|||||||
sys.stderr.write('processing error: {}. processors: {}\n'.format(str(e), str(processor)))
|
sys.stderr.write('processing error: {}. processors: {}\n'.format(str(e), str(processor)))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
sender = None
|
||||||
|
if config.true('_SOCKET_SEND'):
|
||||||
|
if settings.get('SESSION_SOCKET_PATH') != None:
|
||||||
|
sender = SocketSender(settings)
|
||||||
|
|
||||||
tx_iter = iter(processor)
|
tx_iter = iter(processor)
|
||||||
out = Outputter(mode)
|
out = Outputter(mode)
|
||||||
while True:
|
while True:
|
||||||
@ -112,6 +192,14 @@ def main():
|
|||||||
except StopIteration:
|
except StopIteration:
|
||||||
break
|
break
|
||||||
tx_hex = tx_bytes.hex()
|
tx_hex = tx_bytes.hex()
|
||||||
|
if sender != None:
|
||||||
|
r = None
|
||||||
|
try:
|
||||||
|
r = sender.send(tx_hex)
|
||||||
|
except FileNotFoundError as e:
|
||||||
|
sys.stderr.write('send to socket {} failed: {}\n'.format(sender.path, e))
|
||||||
|
sys.exit(1)
|
||||||
|
logg.info('sent {} result {}'.format(tx_hex, r))
|
||||||
print(out.do(tx_hex))
|
print(out.do(tx_hex))
|
||||||
|
|
||||||
|
|
||||||
|
@ -6,19 +6,43 @@ import logging
|
|||||||
import chainlib.eth.cli
|
import chainlib.eth.cli
|
||||||
from chaind.setup import Environment
|
from chaind.setup import Environment
|
||||||
from chaind.filter import StateFilter
|
from chaind.filter import StateFilter
|
||||||
from chaind.adapters.fs import ChaindFsAdapter
|
|
||||||
from chainlib.eth.block import block_latest
|
from chainlib.eth.block import block_latest
|
||||||
from chainlib.eth.connection import EthHTTPConnection
|
|
||||||
from chainlib.chain import ChainSpec
|
|
||||||
from hexathon import strip_0x
|
from hexathon import strip_0x
|
||||||
from chainsyncer.store.fs import SyncFsStore
|
from chainsyncer.store.fs import SyncFsStore
|
||||||
from chainsyncer.driver.chain_interface import ChainInterfaceDriver
|
from chainsyncer.driver.chain_interface import ChainInterfaceDriver
|
||||||
|
from chainsyncer.error import SyncDone
|
||||||
|
from chainlib.eth.cli.arg import (
|
||||||
|
Arg,
|
||||||
|
ArgFlag,
|
||||||
|
process_args,
|
||||||
|
)
|
||||||
|
from chainlib.eth.cli.config import (
|
||||||
|
Config,
|
||||||
|
process_config,
|
||||||
|
)
|
||||||
|
from chainsyncer.cli.arg import (
|
||||||
|
apply_arg as apply_arg_sync,
|
||||||
|
apply_flag as apply_flag_sync,
|
||||||
|
)
|
||||||
|
from chainsyncer.data import config_dir as chainsyncer_config_dir
|
||||||
|
from chaind.data import config_dir as chaind_config_dir
|
||||||
|
from chaind.cli.arg import (
|
||||||
|
apply_arg,
|
||||||
|
apply_flag,
|
||||||
|
)
|
||||||
|
from chainlib.eth.cli.log import process_log
|
||||||
|
from chaind.settings import ChaindSettings
|
||||||
|
from chaind.cli.config import process_config as process_config_local
|
||||||
|
from chainsyncer.cli.config import process_config as process_config_syncer
|
||||||
|
|
||||||
# local imports
|
# local imports
|
||||||
from chaind.eth.cache import EthCacheTx
|
from chaind.eth.cache import EthCacheTx
|
||||||
from chaind.eth.chain import EthChainInterface
|
from chaind.eth.settings import (
|
||||||
|
process_settings,
|
||||||
|
process_sync,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
logging.basicConfig(level=logging.WARNING)
|
|
||||||
logg = logging.getLogger()
|
logg = logging.getLogger()
|
||||||
|
|
||||||
script_dir = os.path.dirname(os.path.realpath(__file__))
|
script_dir = os.path.dirname(os.path.realpath(__file__))
|
||||||
@ -26,91 +50,52 @@ config_dir = os.path.join(script_dir, '..', 'data', 'config')
|
|||||||
|
|
||||||
env = Environment(domain='eth', env=os.environ)
|
env = Environment(domain='eth', env=os.environ)
|
||||||
|
|
||||||
arg_flags = chainlib.eth.cli.argflag_std_read
|
arg_flags = ArgFlag()
|
||||||
argparser = chainlib.eth.cli.ArgumentParser(arg_flags)
|
arg_flags = apply_flag_sync(arg_flags)
|
||||||
argparser.add_argument('--data-dir', type=str, help='data directory')
|
arg_flags = apply_flag(arg_flags)
|
||||||
argparser.add_argument('--runtime-dir', type=str, help='runtime directory')
|
|
||||||
argparser.add_argument('--session-id', dest='session_id', type=str, help='session identifier')
|
arg = Arg(arg_flags)
|
||||||
argparser.add_argument('--dispatch-delay', dest='dispatch_delay', type=float, help='socket timeout before processing queue')
|
arg = apply_arg_sync(arg)
|
||||||
argparser.add_argument('--offset', type=int, default=0, help='Start sync on this block')
|
arg = apply_arg(arg)
|
||||||
argparser.add_argument('--until', type=int, default=0, help='Terminate sync on this block')
|
|
||||||
argparser.add_argument('--head', action='store_true', help='Start at current block height (overrides --offset, assumes --keep-alive)')
|
flags = arg_flags.STD_BASE | arg_flags.CHAIN_SPEC | arg_flags.PROVIDER | arg_flags.SEQ | arg_flags.STATE
|
||||||
argparser.add_argument('--keep-alive', action='store_true', dest='keep_alive', help='Continue to sync head after history sync complete')
|
flags = arg_flags.more(flags, arg_flags.SYNC_RANGE_EXT)
|
||||||
|
flags = arg_flags.more(flags, arg_flags.CHAIND_BASE)
|
||||||
|
|
||||||
|
argparser = chainlib.eth.cli.ArgumentParser()
|
||||||
|
argparser = process_args(argparser, arg, flags)
|
||||||
args = argparser.parse_args()
|
args = argparser.parse_args()
|
||||||
extra_args = {
|
|
||||||
'runtime_dir': 'SESSION_RUNTIME_DIR',
|
|
||||||
'data_dir': 'SESSION_DATA_DIR',
|
|
||||||
'session_id': 'SESSION_ID',
|
|
||||||
'dispatch_delay': 'SESSION_DISPATCH_DELAY',
|
|
||||||
}
|
|
||||||
config = chainlib.eth.cli.Config.from_args(args, arg_flags, extra_args=extra_args, base_config_dir=config_dir)
|
|
||||||
|
|
||||||
logg.debug('session id {} {}'.format(type(config.get('SESSION_ID')), config.get('SESSION_ID')))
|
logg = process_log(args, logg)
|
||||||
if config.get('SESSION_ID') == None:
|
|
||||||
config.add(env.session, 'SESSION_ID', exists_ok=True)
|
|
||||||
if config.get('SESSION_RUNTIME_DIR') == None:
|
|
||||||
config.add(env.runtime_dir, 'SESSION_RUNTIME_DIR', exists_ok=True)
|
|
||||||
if config.get('SESSION_DATA_DIR') == None:
|
|
||||||
config.add(env.data_dir, 'SESSION_DATA_DIR', exists_ok=True)
|
|
||||||
if not config.get('SESSION_SOCKET_PATH'):
|
|
||||||
socket_path = os.path.join(config.get('SESSION_RUNTIME_DIR'), config.get('SESSION_ID'), 'chaind.sock')
|
|
||||||
config.add(socket_path, 'SESSION_SOCKET_PATH', True)
|
|
||||||
config.add(args.keep_alive, '_KEEP_ALIVE', True)
|
|
||||||
config.add(args.head, '_HEAD', True)
|
|
||||||
config.add(args.offset, '_SYNC_OFFSET', True)
|
|
||||||
|
|
||||||
|
config = Config()
|
||||||
|
config.add_schema_dir(chainsyncer_config_dir)
|
||||||
|
config.add_schema_dir(chaind_config_dir)
|
||||||
|
config = process_config(config, arg, args, flags)
|
||||||
|
config = process_config_local(config, arg, args, flags)
|
||||||
|
config = process_config_syncer(config, arg, args, flags)
|
||||||
|
config.add('eth', 'CHAIND_ENGINE', False)
|
||||||
|
config.add('sync', 'CHAIND_COMPONENT', False)
|
||||||
logg.debug('config loaded:\n{}'.format(config))
|
logg.debug('config loaded:\n{}'.format(config))
|
||||||
|
|
||||||
chain_spec = ChainSpec.from_chain_str(config.get('CHAIN_SPEC'))
|
settings = ChaindSettings(include_sync=True)
|
||||||
|
settings = process_settings(settings, config)
|
||||||
conn = EthHTTPConnection(url=config.get('RPC_PROVIDER'), chain_spec=chain_spec)
|
settings = process_sync(settings, config)
|
||||||
|
logg.debug('settings loaded:\n{}'.format(settings))
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
o = block_latest()
|
fltr = StateFilter(settings.get('CHAIN_SPEC'), settings.dir_for('queue'), EthCacheTx)
|
||||||
r = conn.do(o)
|
sync_store = SyncFsStore(settings.get('SESSION_DATA_PATH'), session_id=settings.get('SESSION_ID'))
|
||||||
block_offset = int(strip_0x(r), 16) + 1
|
|
||||||
logg.info('network block height is {}'.format(block_offset))
|
|
||||||
|
|
||||||
keep_alive = False
|
|
||||||
session_block_offset = 0
|
|
||||||
block_limit = 0
|
|
||||||
if args.head:
|
|
||||||
session_block_offset = block_offset
|
|
||||||
block_limit = -1
|
|
||||||
keep_alive = True
|
|
||||||
else:
|
|
||||||
session_block_offset = args.offset
|
|
||||||
|
|
||||||
if args.until > 0:
|
|
||||||
if not args.head and args.until <= session_block_offset:
|
|
||||||
raise ValueError('sync termination block number must be later than offset ({} >= {})'.format(session_block_offset, args.until))
|
|
||||||
block_limit = args.until
|
|
||||||
elif config.true('_KEEP_ALIVE'):
|
|
||||||
keep_alive=True
|
|
||||||
block_limit = -1
|
|
||||||
|
|
||||||
if session_block_offset == -1:
|
|
||||||
session_block_offset = block_offset
|
|
||||||
elif not config.true('_KEEP_ALIVE'):
|
|
||||||
if block_limit == 0:
|
|
||||||
block_limit = block_offset
|
|
||||||
|
|
||||||
queue_adapter = ChaindFsAdapter(
|
|
||||||
chain_spec,
|
|
||||||
config.get('SESSION_DATA_DIR'),
|
|
||||||
EthCacheTx,
|
|
||||||
None,
|
|
||||||
)
|
|
||||||
fltr = StateFilter(queue_adapter)
|
|
||||||
sync_store = SyncFsStore(config.get('SESSION_RUNTIME_DIR'), session_id=config.get('SESSION_ID'))
|
|
||||||
sync_store.register(fltr)
|
sync_store.register(fltr)
|
||||||
|
|
||||||
logg.debug('session block ofset {}'.format(session_block_offset))
|
logg.debug('session block offset {}'.format(settings.get('SYNCER_OFFSET')))
|
||||||
|
|
||||||
chain_interface = EthChainInterface()
|
drv = ChainInterfaceDriver(sync_store, settings.get('SYNCER_INTERFACE'), offset=settings.get('SYNCER_OFFSET'), target=settings.get('SYNCER_LIMIT'))
|
||||||
drv = ChainInterfaceDriver(sync_store, chain_interface, offset=session_block_offset, target=block_limit)
|
try:
|
||||||
drv.run(conn)
|
drv.run(settings.get('CONN'))
|
||||||
|
except SyncDone as e:
|
||||||
|
logg.info('sync done: {}'.format(e))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
@ -1,137 +0,0 @@
|
|||||||
# standard imports
|
|
||||||
import os
|
|
||||||
import logging
|
|
||||||
import signal
|
|
||||||
|
|
||||||
# external imports
|
|
||||||
import chainlib.eth.cli
|
|
||||||
from chaind.session import SessionController
|
|
||||||
from chaind.setup import Environment
|
|
||||||
from chaind.error import (
|
|
||||||
NothingToDoError,
|
|
||||||
ClientGoneError,
|
|
||||||
ClientBlockError,
|
|
||||||
ClientInputError,
|
|
||||||
)
|
|
||||||
from chainqueue import (
|
|
||||||
Store,
|
|
||||||
Status,
|
|
||||||
)
|
|
||||||
from chainqueue.error import DuplicateTxError
|
|
||||||
from chainqueue.store.fs import (
|
|
||||||
IndexStore,
|
|
||||||
CounterStore,
|
|
||||||
)
|
|
||||||
from chainqueue.cache import CacheTokenTx
|
|
||||||
from chainlib.encode import TxHexNormalizer
|
|
||||||
from chainlib.chain import ChainSpec
|
|
||||||
from chaind.adapters.fs import ChaindFsAdapter
|
|
||||||
|
|
||||||
# local imports
|
|
||||||
from chaind.eth.dispatch import EthDispatcher
|
|
||||||
from chaind.eth.cache import EthCacheTx
|
|
||||||
|
|
||||||
logging.basicConfig(level=logging.WARNING)
|
|
||||||
logg = logging.getLogger()
|
|
||||||
|
|
||||||
script_dir = os.path.dirname(os.path.realpath(__file__))
|
|
||||||
config_dir = os.path.join(script_dir, '..', 'data', 'config')
|
|
||||||
|
|
||||||
env = Environment(domain='eth', env=os.environ)
|
|
||||||
|
|
||||||
arg_flags = chainlib.eth.cli.argflag_std_read
|
|
||||||
argparser = chainlib.eth.cli.ArgumentParser(arg_flags)
|
|
||||||
argparser.add_argument('--data-dir', type=str, help='data directory')
|
|
||||||
argparser.add_argument('--runtime-dir', type=str, help='runtime directory')
|
|
||||||
argparser.add_argument('--session-id', dest='session_id', type=str, help='session identifier')
|
|
||||||
argparser.add_argument('--dispatch-delay', dest='dispatch_delay', type=float, help='socket timeout before processing queue')
|
|
||||||
args = argparser.parse_args()
|
|
||||||
extra_args = {
|
|
||||||
'runtime_dir': 'SESSION_RUNTIME_DIR',
|
|
||||||
'data_dir': 'SESSION_DATA_DIR',
|
|
||||||
'session_id': 'SESSION_ID',
|
|
||||||
'dispatch_delay': 'SESSION_DISPATCH_DELAY',
|
|
||||||
}
|
|
||||||
config = chainlib.eth.cli.Config.from_args(args, arg_flags, extra_args=extra_args, base_config_dir=config_dir)
|
|
||||||
|
|
||||||
logg.debug('session id {} {}'.format(type(config.get('SESSION_ID')), config.get('SESSION_ID')))
|
|
||||||
if config.get('SESSION_ID') == None:
|
|
||||||
config.add(env.session, 'SESSION_ID', exists_ok=True)
|
|
||||||
if config.get('SESSION_RUNTIME_DIR') == None:
|
|
||||||
config.add(env.runtime_dir, 'SESSION_RUNTIME_DIR', exists_ok=True)
|
|
||||||
if config.get('SESSION_DATA_DIR') == None:
|
|
||||||
config.add(env.data_dir, 'SESSION_DATA_DIR', exists_ok=True)
|
|
||||||
if not config.get('SESSION_SOCKET_PATH'):
|
|
||||||
socket_path = os.path.join(config.get('SESSION_RUNTIME_DIR'), config.get('SESSION_ID'), 'chaind.sock')
|
|
||||||
config.add(socket_path, 'SESSION_SOCKET_PATH', True)
|
|
||||||
|
|
||||||
logg.debug('config loaded:\n{}'.format(config))
|
|
||||||
|
|
||||||
def process_outgoing(chain_spec, adapter, rpc, limit=100):
|
|
||||||
upcoming = adapter.upcoming()
|
|
||||||
logg.info('process {} {} {}'.format(chain_spec, adapter, rpc))
|
|
||||||
logg.info('upcoming {}'.format(upcoming))
|
|
||||||
i = 0
|
|
||||||
for tx_hash in upcoming:
|
|
||||||
if adapter.dispatch(tx_hash):
|
|
||||||
i += 1
|
|
||||||
return i
|
|
||||||
|
|
||||||
chain_spec = ChainSpec.from_chain_str(config.get('CHAIN_SPEC'))
|
|
||||||
|
|
||||||
rpc = chainlib.eth.cli.Rpc()
|
|
||||||
conn = rpc.connect_by_config(config)
|
|
||||||
|
|
||||||
tx_normalizer = TxHexNormalizer().tx_hash
|
|
||||||
token_cache_store = CacheTokenTx(chain_spec, normalizer=tx_normalizer)
|
|
||||||
dispatcher = EthDispatcher(conn)
|
|
||||||
queue_adapter = ChaindFsAdapter(
|
|
||||||
chain_spec,
|
|
||||||
config.get('SESSION_DATA_DIR'),
|
|
||||||
EthCacheTx,
|
|
||||||
dispatcher,
|
|
||||||
)
|
|
||||||
|
|
||||||
ctrl = SessionController(config, queue_adapter, process_outgoing)
|
|
||||||
signal.signal(signal.SIGINT, ctrl.shutdown)
|
|
||||||
signal.signal(signal.SIGTERM, ctrl.shutdown)
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
|
||||||
while True:
|
|
||||||
v = None
|
|
||||||
client_socket = None
|
|
||||||
try:
|
|
||||||
(client_socket, v) = ctrl.get()
|
|
||||||
except ClientGoneError:
|
|
||||||
break
|
|
||||||
except ClientBlockError:
|
|
||||||
continue
|
|
||||||
except ClientInputError:
|
|
||||||
continue
|
|
||||||
except NothingToDoError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
if v == None:
|
|
||||||
ctrl.process(conn)
|
|
||||||
continue
|
|
||||||
|
|
||||||
result_data = None
|
|
||||||
r = 0 # no error
|
|
||||||
try:
|
|
||||||
result_data = queue_adapter.put(v.hex())
|
|
||||||
except DuplicateTxError as e:
|
|
||||||
logg.error('tx already exists: {}'.format(e))
|
|
||||||
r = 1
|
|
||||||
except ValueError as e:
|
|
||||||
logg.error('adapter rejected input {}: "{}"'.format(v.hex(), e))
|
|
||||||
continue
|
|
||||||
|
|
||||||
if r == 0:
|
|
||||||
queue_adapter.enqueue(result_data)
|
|
||||||
|
|
||||||
ctrl.respond_put(client_socket, r, extra_data=result_data)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
main()
|
|
32
chaind/eth/settings.py
Normal file
32
chaind/eth/settings.py
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
# external imports
|
||||||
|
from chainlib.eth.connection import EthHTTPConnection
|
||||||
|
from chainlib.eth.settings import process_settings as base_process_settings
|
||||||
|
from chaind.eth.chain import EthChainInterface
|
||||||
|
from chaind.settings import *
|
||||||
|
from chainsyncer.settings import process_sync_range
|
||||||
|
|
||||||
|
|
||||||
|
def process_common(settings, config):
|
||||||
|
rpc_provider = config.get('RPC_PROVIDER')
|
||||||
|
if rpc_provider == None:
|
||||||
|
rpc_provider = 'http://localhost:8545'
|
||||||
|
conn = EthHTTPConnection(url=rpc_provider, chain_spec=settings.get('CHAIN_SPEC'))
|
||||||
|
settings.set('RPC', conn)
|
||||||
|
return settings
|
||||||
|
|
||||||
|
|
||||||
|
def process_sync(settings, config):
|
||||||
|
settings.set('SYNCER_INTERFACE', EthChainInterface())
|
||||||
|
settings = process_sync_range(settings, config)
|
||||||
|
return settings
|
||||||
|
|
||||||
|
|
||||||
|
def process_settings(settings, config):
|
||||||
|
settings = base_process_settings(settings, config)
|
||||||
|
settings = process_common(settings, config)
|
||||||
|
settings = process_backend(settings, config)
|
||||||
|
settings = process_session(settings, config)
|
||||||
|
settings = process_socket(settings, config)
|
||||||
|
settings = process_token(settings, config)
|
||||||
|
|
||||||
|
return settings
|
@ -9,7 +9,7 @@ logg = logging.getLogger(__name__)
|
|||||||
|
|
||||||
class BaseTokenResolver:
|
class BaseTokenResolver:
|
||||||
|
|
||||||
def __init__(self, chain_spec, sender, signer, gas_oracle, nonce_oracle):
|
def __init__(self, chain_spec, sender, signer, gas_oracle, nonce_oracle, advance_nonce=False):
|
||||||
self.chain_spec = chain_spec
|
self.chain_spec = chain_spec
|
||||||
self.chain_id = chain_spec.chain_id()
|
self.chain_id = chain_spec.chain_id()
|
||||||
self.signer = signer
|
self.signer = signer
|
||||||
@ -19,6 +19,10 @@ class BaseTokenResolver:
|
|||||||
self.factory = None
|
self.factory = None
|
||||||
self.gas_limit_start = None
|
self.gas_limit_start = None
|
||||||
self.gas_price_start = None
|
self.gas_price_start = None
|
||||||
|
if advance_nonce:
|
||||||
|
self.nonce_getter = self.nonce_oracle.next_nonce
|
||||||
|
else:
|
||||||
|
self.nonce_getter = self.nonce_oracle.get_nonce
|
||||||
|
|
||||||
|
|
||||||
def reset(self):
|
def reset(self):
|
||||||
@ -28,7 +32,7 @@ class BaseTokenResolver:
|
|||||||
|
|
||||||
|
|
||||||
def get_values(self, gas_value, value, executable_address=None):
|
def get_values(self, gas_value, value, executable_address=None):
|
||||||
nonce = self.nonce_oracle.next_nonce()
|
nonce = self.nonce_getter()
|
||||||
|
|
||||||
if executable_address == None:
|
if executable_address == None:
|
||||||
return (value, 0, nonce)
|
return (value, 0, nonce)
|
||||||
|
@ -9,7 +9,7 @@ from chaind.eth.token import BaseTokenResolver
|
|||||||
class GasTokenResolver(BaseTokenResolver):
|
class GasTokenResolver(BaseTokenResolver):
|
||||||
|
|
||||||
def __init__(self, chain_spec, sender, signer, gas_oracle, nonce_oracle):
|
def __init__(self, chain_spec, sender, signer, gas_oracle, nonce_oracle):
|
||||||
super(GasTokenResolver, self).__init__(chain_spec, sender, signer, gas_oracle, nonce_oracle)
|
super(GasTokenResolver, self).__init__(chain_spec, sender, signer, gas_oracle, nonce_oracle, advance_nonce=True)
|
||||||
self.factory = Gas(self.chain_spec, signer=self.signer, gas_oracle=self.gas_oracle, nonce_oracle=self.nonce_oracle)
|
self.factory = Gas(self.chain_spec, signer=self.signer, gas_oracle=self.gas_oracle, nonce_oracle=self.nonce_oracle)
|
||||||
|
|
||||||
|
|
||||||
|
@ -3,7 +3,10 @@ import logging
|
|||||||
|
|
||||||
# external imports
|
# external imports
|
||||||
from chaind.error import TxSourceError
|
from chaind.error import TxSourceError
|
||||||
from chainlib.eth.address import is_checksum_address
|
from chainlib.eth.address import (
|
||||||
|
is_checksum_address,
|
||||||
|
to_checksum_address,
|
||||||
|
)
|
||||||
from chainlib.eth.tx import unpack
|
from chainlib.eth.tx import unpack
|
||||||
from chainlib.eth.gas import Gas
|
from chainlib.eth.gas import Gas
|
||||||
from hexathon import (
|
from hexathon import (
|
||||||
@ -17,10 +20,11 @@ logg = logging.getLogger(__name__)
|
|||||||
|
|
||||||
class Processor:
|
class Processor:
|
||||||
|
|
||||||
def __init__(self, resolver, source):
|
def __init__(self, resolver, source, use_checksum=True):
|
||||||
self.resolver = resolver
|
self.resolver = resolver
|
||||||
self.source = source
|
self.source = source
|
||||||
self.processor = []
|
self.processor = []
|
||||||
|
self.safe = use_checksum
|
||||||
self.conn = None
|
self.conn = None
|
||||||
|
|
||||||
|
|
||||||
@ -50,9 +54,14 @@ class Processor:
|
|||||||
txs = []
|
txs = []
|
||||||
for i, r in enumerate(self.content):
|
for i, r in enumerate(self.content):
|
||||||
logg.debug('processing {}'.format(r))
|
logg.debug('processing {}'.format(r))
|
||||||
if not is_checksum_address(r[0]):
|
address = r[0]
|
||||||
raise ValueError('invalid checksum address {} in record {}'.format(r[0], i))
|
if self.safe:
|
||||||
self.content[i][0] = add_0x(r[0])
|
if not is_checksum_address(address):
|
||||||
|
raise ValueError('invalid checksum address {} in record {}'.format(address, i))
|
||||||
|
else:
|
||||||
|
address = to_checksum_address(address)
|
||||||
|
|
||||||
|
self.content[i][0] = add_0x(address)
|
||||||
try:
|
try:
|
||||||
self.content[i][1] = int(r[1])
|
self.content[i][1] = int(r[1])
|
||||||
except ValueError:
|
except ValueError:
|
||||||
|
@ -1 +1 @@
|
|||||||
eth-erc20~=0.3.0
|
eth-erc20~=0.3.2
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
chaind~=0.1.0
|
chaind~=0.3.0
|
||||||
hexathon~=0.1.5
|
hexathon~=0.1.7
|
||||||
chainlib-eth~=0.1.0
|
chainlib-eth~=0.3.0
|
||||||
pyxdg~=0.27
|
pyxdg~=0.27
|
||||||
shep~=0.2.3
|
funga-eth~=0.6.1
|
||||||
funga-eth~=0.6.0
|
|
||||||
|
16
setup.cfg
16
setup.cfg
@ -1,26 +1,25 @@
|
|||||||
[metadata]
|
[metadata]
|
||||||
name = chaind-eth
|
name = chaind-eth
|
||||||
version = 0.1.0
|
version = 0.3.3
|
||||||
description = Queue server for ethereum
|
description = Queue server for ethereum
|
||||||
author = Louis Holbrook
|
author = Louis Holbrook
|
||||||
author_email = dev@holbrook.no
|
author_email = dev@holbrook.no
|
||||||
url = https://gitlab.com/chaintool/chaind-eth
|
url = https://git.defalsify.org/chaind-eth.git
|
||||||
keywords =
|
keywords =
|
||||||
cic
|
dlt
|
||||||
|
blockchain
|
||||||
cryptocurrency
|
cryptocurrency
|
||||||
ethereum
|
ethereum
|
||||||
solidarity
|
|
||||||
mutual_credit
|
|
||||||
classifiers =
|
classifiers =
|
||||||
Programming Language :: Python :: 3
|
Programming Language :: Python :: 3
|
||||||
Operating System :: OS Independent
|
Operating System :: OS Independent
|
||||||
Development Status :: 3 - Alpha
|
Development Status :: 3 - Alpha
|
||||||
Environment :: Console
|
Environment :: Console
|
||||||
Intended Audience :: Developers
|
Intended Audience :: Developers
|
||||||
License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)
|
License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)
|
||||||
Topic :: Internet
|
Topic :: Internet
|
||||||
# Topic :: Blockchain :: EVM
|
# Topic :: Blockchain :: EVM
|
||||||
license = GPL3
|
license = OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)
|
||||||
licence_files =
|
licence_files =
|
||||||
LICENSE
|
LICENSE
|
||||||
|
|
||||||
@ -31,10 +30,11 @@ packages =
|
|||||||
chaind.eth
|
chaind.eth
|
||||||
chaind.eth.runnable
|
chaind.eth.runnable
|
||||||
chaind.eth.cli
|
chaind.eth.cli
|
||||||
|
chaind.eth.token
|
||||||
|
|
||||||
[options.entry_points]
|
[options.entry_points]
|
||||||
console_scripts =
|
console_scripts =
|
||||||
chaind-eth-tasker = chaind.eth.runnable.tasker:main
|
chaind-eth-queuer = chaind.eth.runnable.queuer:main
|
||||||
chaind-eth-syncer = chaind.eth.runnable.syncer:main
|
chaind-eth-syncer = chaind.eth.runnable.syncer:main
|
||||||
chaind-eth-send = chaind.eth.runnable.send:main
|
chaind-eth-send = chaind.eth.runnable.send:main
|
||||||
#chaind-eth-resend = chaind_eth.runnable.resend:main
|
#chaind-eth-resend = chaind_eth.runnable.resend:main
|
||||||
|
2
setup.py
2
setup.py
@ -27,7 +27,7 @@ while True:
|
|||||||
l = f.readline()
|
l = f.readline()
|
||||||
if l == '':
|
if l == '':
|
||||||
break
|
break
|
||||||
test_requirements.append(l.rstrip())
|
erc20_requirements.append(l.rstrip())
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
[Unit]
|
[Unit]
|
||||||
Description=Chainqueue transaction dispatch interface
|
Description=Chainqueue transaction dispatch interface
|
||||||
Requires=chaind-eth-sync@.service
|
#Requires=chaind-eth-sync@.service
|
||||||
After=chaind-eth-sync@.service
|
#After=chaind-eth-sync@.service
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
Environment="SESSION_ID=%i"
|
Environment="SESSION_ID=%i"
|
||||||
|
@ -11,7 +11,7 @@ from chainlib.chain import ChainSpec
|
|||||||
from chainqueue.cache import CacheTokenTx
|
from chainqueue.cache import CacheTokenTx
|
||||||
from chainlib.error import RPCException
|
from chainlib.error import RPCException
|
||||||
from chainlib.status import Status as TxStatus
|
from chainlib.status import Status as TxStatus
|
||||||
from chaind.unittest.common import TestChaindFsBase
|
from chaind.unittest.fs import TestChaindFsBase
|
||||||
from chaind.driver import QueueDriver
|
from chaind.driver import QueueDriver
|
||||||
from chaind.filter import StateFilter
|
from chaind.filter import StateFilter
|
||||||
from chainlib.eth.gas import Gas
|
from chainlib.eth.gas import Gas
|
||||||
|
Loading…
Reference in New Issue
Block a user