mirror of
https://github.com/grassrootseconomics/eth-tracker.git
synced 2025-02-23 00:02:00 +01:00
release: v1.0.0-rc
This commit is contained in:
commit
30729e9318
9
.dockerignore
Normal file
9
.dockerignore
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
/**
|
||||||
|
tracker_db
|
||||||
|
!/cmd
|
||||||
|
!/db
|
||||||
|
!/internal
|
||||||
|
!/pkg
|
||||||
|
!/LICENSE
|
||||||
|
!/config.toml
|
||||||
|
!/go.*
|
6
.env.example
Normal file
6
.env.example
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
TRACKER_CORE__POOL_SIZE=
|
||||||
|
TRACKER_CHAIN__ARCHIVE_NODE=
|
||||||
|
TRACKER_CHAIN__WS_ENDPOINT=
|
||||||
|
TRACKER_CHAIN__RPC_ENDPOINT=
|
||||||
|
TRACKER_CHAIN__CHAINID=
|
||||||
|
TRACKER_CHAIN__START_BLOCK=
|
6
.github/dependabot.yaml
vendored
Normal file
6
.github/dependabot.yaml
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
version: 2
|
||||||
|
updates:
|
||||||
|
- package-ecosystem: "gomod"
|
||||||
|
directory: "/"
|
||||||
|
schedule:
|
||||||
|
interval: "weekly"
|
56
.github/workflows/docker.yaml
vendored
Normal file
56
.github/workflows/docker.yaml
vendored
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
name: release
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- "v*"
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
docker:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Set up QEMU
|
||||||
|
uses: docker/setup-qemu-action@v2
|
||||||
|
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v2
|
||||||
|
|
||||||
|
- name: Check out repo
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: Cache Docker layers
|
||||||
|
uses: actions/cache@v3
|
||||||
|
with:
|
||||||
|
path: /tmp/.buildx-cache
|
||||||
|
key: ${{ runner.os }}-buildx-${{ github.sha }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-buildx-
|
||||||
|
|
||||||
|
- name: Login to GHCR Docker registry
|
||||||
|
uses: docker/login-action@v1
|
||||||
|
with:
|
||||||
|
registry: ghcr.io
|
||||||
|
username: ${{ github.repository_owner }}
|
||||||
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
- name: Set outputs
|
||||||
|
run: |
|
||||||
|
echo "RELEASE_TAG=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV \
|
||||||
|
&& echo "RELEASE_SHORT_COMMIT=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
|
||||||
|
|
||||||
|
- name: Build and push image
|
||||||
|
uses: docker/build-push-action@v2
|
||||||
|
with:
|
||||||
|
context: ./
|
||||||
|
file: ./Dockerfile
|
||||||
|
platforms: linux/amd64
|
||||||
|
push: true
|
||||||
|
build-args: |
|
||||||
|
BUILD=${{ env.RELEASE_SHORT_COMMIT }}
|
||||||
|
cache-from: type=local,src=/tmp/.buildx-cache
|
||||||
|
cache-to: type=local,dest=/tmp/.buildx-cache
|
||||||
|
tags: |
|
||||||
|
ghcr.io/grassrootseconomics/celo-tracker:latest
|
||||||
|
ghcr.io/grassrootseconomics/celo-tracker:${{ env.RELEASE_TAG }}
|
6
.gitignore
vendored
Normal file
6
.gitignore
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
tracker_db
|
||||||
|
.vscode
|
||||||
|
.idx
|
||||||
|
**/*.env
|
||||||
|
celo-tracker
|
||||||
|
celo-tracker-cache-bootstrap
|
28
Dockerfile
Normal file
28
Dockerfile
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
FROM golang:1.23.0-bookworm AS build
|
||||||
|
|
||||||
|
ENV CGO_ENABLED=1
|
||||||
|
|
||||||
|
ARG BUILDPLATFORM
|
||||||
|
ARG TARGETPLATFORM
|
||||||
|
ARG BUILD=dev
|
||||||
|
|
||||||
|
RUN echo "Building on $BUILDPLATFORM, building for $TARGETPLATFORM"
|
||||||
|
WORKDIR /build
|
||||||
|
|
||||||
|
COPY . .
|
||||||
|
RUN go mod download
|
||||||
|
RUN go build -o celo-tracker-cache-bootstrap -ldflags="-X main.build=${BUILD} -s -w" cmd/bootstrap/main.go
|
||||||
|
RUN go build -o celo-tracker -ldflags="-X main.build=${BUILD} -s -w" cmd/service/main.go
|
||||||
|
|
||||||
|
FROM debian:bookworm-slim
|
||||||
|
|
||||||
|
ENV DEBIAN_FRONTEND=noninteractive
|
||||||
|
|
||||||
|
WORKDIR /service
|
||||||
|
|
||||||
|
COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
|
||||||
|
COPY --from=build /build/* .
|
||||||
|
|
||||||
|
EXPOSE 5001
|
||||||
|
|
||||||
|
CMD ["./celo-tracker"]
|
661
LICENSE
Normal file
661
LICENSE
Normal file
@ -0,0 +1,661 @@
|
|||||||
|
GNU AFFERO GENERAL PUBLIC LICENSE
|
||||||
|
Version 3, 19 November 2007
|
||||||
|
|
||||||
|
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||||
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
|
of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
|
Preamble
|
||||||
|
|
||||||
|
The GNU Affero General Public License is a free, copyleft license for
|
||||||
|
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
|
||||||
|
to take away your freedom to share and change the works. By contrast,
|
||||||
|
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
|
||||||
|
software for all its users.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
Developers that use our General Public Licenses protect your rights
|
||||||
|
with two steps: (1) assert copyright on the software, and (2) offer
|
||||||
|
you this License which gives you legal permission to copy, distribute
|
||||||
|
and/or modify the software.
|
||||||
|
|
||||||
|
A secondary benefit of defending all users' freedom is that
|
||||||
|
improvements made in alternate versions of the program, if they
|
||||||
|
receive widespread use, become available for other developers to
|
||||||
|
incorporate. Many developers of free software are heartened and
|
||||||
|
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.
|
||||||
|
|
||||||
|
The GNU Affero General Public License is designed specifically to
|
||||||
|
ensure that, in such cases, the modified source code becomes available
|
||||||
|
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.
|
||||||
|
|
||||||
|
An older license, called the Affero General Public License and
|
||||||
|
published by Affero, was designed to accomplish similar goals. This is
|
||||||
|
a different license, not a version of the Affero GPL, but Affero has
|
||||||
|
released a new version of the Affero GPL which permits relicensing under
|
||||||
|
this license.
|
||||||
|
|
||||||
|
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 Affero 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. 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
|
||||||
|
permission to link or combine any covered work with a work licensed
|
||||||
|
under version 3 of the GNU 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 work with which it is combined will remain governed by version
|
||||||
|
3 of the GNU General Public License.
|
||||||
|
|
||||||
|
14. Revised Versions of this License.
|
||||||
|
|
||||||
|
The Free Software Foundation may publish revised and/or new versions of
|
||||||
|
the GNU Affero 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 Affero 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 Affero 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 Affero 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 Affero 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 Affero General Public License for more details.
|
||||||
|
|
||||||
|
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/>.
|
||||||
|
|
||||||
|
Also add information on how to contact you by electronic and paper mail.
|
||||||
|
|
||||||
|
If your software can interact with users remotely through a computer
|
||||||
|
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
|
||||||
|
interface could display a "Source" link that leads users to an archive
|
||||||
|
of the code. There are many ways you could offer source, and different
|
||||||
|
solutions will be better for different programs; see section 13 for the
|
||||||
|
specific requirements.
|
||||||
|
|
||||||
|
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 AGPL, see
|
||||||
|
<https://www.gnu.org/licenses/>.
|
24
Makefile
Normal file
24
Makefile
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
BIN := celo-tracker
|
||||||
|
BOOTSTRAP_BIN := celo-tracker-cache-bootstrap
|
||||||
|
DB_FILE := tracker_db
|
||||||
|
BUILD_CONF := CGO_ENABLED=1 GOOS=linux GOARCH=amd64
|
||||||
|
BUILD_COMMIT := $(shell git rev-parse --short HEAD 2> /dev/null)
|
||||||
|
DEBUG := DEV=true
|
||||||
|
|
||||||
|
.PHONY: build run run-bootstrap clean clean-debug
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm ${BIN} ${BOOTSTRAP_BIN}
|
||||||
|
|
||||||
|
clean-db:
|
||||||
|
rm ${DB_FILE}
|
||||||
|
|
||||||
|
build:
|
||||||
|
${BUILD_CONF} go build -ldflags="-X main.build=${BUILD_COMMIT} -s -w" -o ${BOOTSTRAP_BIN} cmd/bootstrap/main.go
|
||||||
|
${BUILD_CONF} go build -ldflags="-X main.build=${BUILD_COMMIT} -s -w" -o ${BIN} cmd/service/main.go
|
||||||
|
|
||||||
|
run-bootstrap:
|
||||||
|
${BUILD_CONF} ${DEBUG} go run cmd/bootstrap/main.go
|
||||||
|
|
||||||
|
run:
|
||||||
|
${BUILD_CONF} ${DEBUG} go run cmd/service/main.go
|
95
README.md
Normal file
95
README.md
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
# celo-tracker
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
A fast and lightweight tracker designed to monitor the Celo blockchain for live and historical transaction events, including reverted transactions. It filters these events and publishes them to NATS for further processing.
|
||||||
|
|
||||||
|
It applies deduplication at the NATS level, making it safe to run in a distributed fashion.
|
||||||
|
|
||||||
|
## Getting Started
|
||||||
|
|
||||||
|
A `Makefile` is also provided to build the required binaries to run celo-tracker.
|
||||||
|
|
||||||
|
### Bootstrap Cache
|
||||||
|
|
||||||
|
An optional binary, `celo-tracker-cache-bootstrap`, is included to build the Redis cache with all relevant Grassroots Economics smart contract and user addresses to allow filtering on very busy smart contracts e.g. cUSD.
|
||||||
|
|
||||||
|
The cache will auto-update based on any additions/removals from all indexes.
|
||||||
|
|
||||||
|
### Prerequisites
|
||||||
|
|
||||||
|
* Git
|
||||||
|
* Docker
|
||||||
|
* NATS server
|
||||||
|
* Redis server
|
||||||
|
* Access to a Celo RPC node
|
||||||
|
|
||||||
|
See [docker-compose.yaml](dev/docker-compose.yaml) for an example on how to run and deploy a single instance.
|
||||||
|
|
||||||
|
### 1. Build the Docker image
|
||||||
|
|
||||||
|
We provide pre-built images for `linux/amd64`. See the packages tab on Github.
|
||||||
|
|
||||||
|
If you are on any other platform:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git clone https://github.com/grassrootseconomics/celo-tracker.git
|
||||||
|
cd celo-tracker
|
||||||
|
docker buildx build --build-arg BUILD=$(git rev-parse --short HEAD) --tag celo-tracker:$(git rev-parse --short HEAD) --tag celo-tracker:latest .
|
||||||
|
docker images
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. Run NATS and Redis
|
||||||
|
|
||||||
|
For an example, see `dev/docker-compose.yaml`.
|
||||||
|
### 3. Update config values
|
||||||
|
|
||||||
|
See `.env.example` on how to override default values defined in `config.toml` using env variables. Alternatively, mount your own config.toml either during build time or Docker runtime.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Override only specific config values
|
||||||
|
nano .env.example
|
||||||
|
mv .env.example .env
|
||||||
|
```
|
||||||
|
|
||||||
|
Refer to [`config.toml`](config.toml) to understand different config value settings.
|
||||||
|
|
||||||
|
|
||||||
|
### 4. Run the tracker
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd dev
|
||||||
|
docker compose up
|
||||||
|
```
|
||||||
|
|
||||||
|
## Processing NATS messages
|
||||||
|
|
||||||
|
### JSON structure
|
||||||
|
|
||||||
|
```js
|
||||||
|
{
|
||||||
|
"block": Number,
|
||||||
|
"contractAddress": String,
|
||||||
|
"success": Boolean,
|
||||||
|
"timetamp" Number,
|
||||||
|
"transactionHash": String,
|
||||||
|
"transactionType": String,
|
||||||
|
"payload": Object
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Monitoring with NATS CLI
|
||||||
|
|
||||||
|
Install NATS CLI from [here](https://github.com/nats-io/natscli?tab=readme-ov-file#installation).
|
||||||
|
|
||||||
|
```bash
|
||||||
|
nats subscribe "TRACKER.*"
|
||||||
|
```
|
||||||
|
|
||||||
|
### DB File
|
||||||
|
|
||||||
|
A `tracker_db` file is created on the first run. This keeps track of all blocks missed by the processor to attempt a retry later on. This file should not be deleted if you want to maintain resume support for historical tracking across restarts.
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
[AGPL-3.0](LICENSE).
|
236
cmd/bootstrap/main.go
Normal file
236
cmd/bootstrap/main.go
Normal file
@ -0,0 +1,236 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"flag"
|
||||||
|
"log/slog"
|
||||||
|
"os"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/celo-org/celo-blockchain/common"
|
||||||
|
"github.com/grassrootseconomics/celo-tracker/internal/cache"
|
||||||
|
"github.com/grassrootseconomics/celo-tracker/internal/chain"
|
||||||
|
"github.com/grassrootseconomics/celo-tracker/internal/util"
|
||||||
|
"github.com/grassrootseconomics/celoutils/v3"
|
||||||
|
"github.com/grassrootseconomics/w3-celo"
|
||||||
|
"github.com/grassrootseconomics/w3-celo/module/eth"
|
||||||
|
"github.com/knadh/koanf/v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
const cacheType = "redis"
|
||||||
|
|
||||||
|
var (
|
||||||
|
build = "dev"
|
||||||
|
|
||||||
|
confFlag string
|
||||||
|
|
||||||
|
lo *slog.Logger
|
||||||
|
ko *koanf.Koanf
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
flag.StringVar(&confFlag, "config", "config.toml", "Config file location")
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
|
lo = util.InitLogger()
|
||||||
|
ko = util.InitConfig(lo, confFlag)
|
||||||
|
|
||||||
|
lo.Info("starting GE redis cache bootstrapper", "build", build)
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
var (
|
||||||
|
tokenRegistryGetter = w3.MustNewFunc("tokenRegistry()", "address")
|
||||||
|
quoterGetter = w3.MustNewFunc("quoter()", "address")
|
||||||
|
)
|
||||||
|
|
||||||
|
chain, err := chain.NewRPCFetcher(chain.CeloRPCOpts{
|
||||||
|
RPCEndpoint: ko.MustString("chain.rpc_endpoint"),
|
||||||
|
ChainID: ko.MustInt64("chain.chainid"),
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
lo.Error("could not initialize chain client", "error", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
cache, err := cache.New(cache.CacheOpts{
|
||||||
|
Logg: lo,
|
||||||
|
CacheType: cacheType,
|
||||||
|
RedisDSN: ko.MustString("redis.dsn"),
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
lo.Error("could not initialize cache", "error", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), time.Minute*5)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
for _, registry := range ko.MustStrings("bootstrap.ge_registries") {
|
||||||
|
registryMap, err := chain.Provider().RegistryMap(ctx, celoutils.HexToAddress(registry))
|
||||||
|
if err != nil {
|
||||||
|
lo.Error("could not fetch registry", "error", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
if tokenIndex := registryMap[celoutils.TokenIndex]; tokenIndex != celoutils.ZeroAddress {
|
||||||
|
tokenIndexIter, err := chain.Provider().NewBatchIterator(ctx, tokenIndex)
|
||||||
|
if err != nil {
|
||||||
|
lo.Error("could not create token index iter", "error", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
for {
|
||||||
|
batch, err := tokenIndexIter.Next(ctx)
|
||||||
|
if err != nil {
|
||||||
|
lo.Error("error fetching next token index batch", "error", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
if batch == nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
lo.Debug("index batch", "index", tokenIndex.Hex(), "size", len(batch))
|
||||||
|
for _, address := range batch {
|
||||||
|
if err := cache.Add(ctx, address.Hex()); err != nil {
|
||||||
|
lo.Error("redis error setting key", "error", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if poolIndex := registryMap[celoutils.PoolIndex]; poolIndex != celoutils.ZeroAddress {
|
||||||
|
poolIndexIter, err := chain.Provider().NewBatchIterator(ctx, poolIndex)
|
||||||
|
if err != nil {
|
||||||
|
lo.Error("cache could create pool index iter", "error", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
for {
|
||||||
|
batch, err := poolIndexIter.Next(ctx)
|
||||||
|
if err != nil {
|
||||||
|
lo.Error("error fetching next pool index batch", "error", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
if batch == nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
lo.Debug("index batch", "index", poolIndex.Hex(), "size", len(batch))
|
||||||
|
for _, address := range batch {
|
||||||
|
if err := cache.Add(ctx, address.Hex()); err != nil {
|
||||||
|
lo.Error("redis error setting key", "error", err, "address", address.Hex())
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
var poolTokenIndex, priceQuoter common.Address
|
||||||
|
err := chain.Provider().Client.CallCtx(
|
||||||
|
ctx,
|
||||||
|
eth.CallFunc(address, tokenRegistryGetter).Returns(&poolTokenIndex),
|
||||||
|
eth.CallFunc(address, quoterGetter).Returns(&priceQuoter),
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
lo.Error("error fetching pool token index and/or quoter", "error", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
if priceQuoter != celoutils.ZeroAddress {
|
||||||
|
if err := cache.Add(ctx, priceQuoter.Hex()); err != nil {
|
||||||
|
lo.Error("redis error setting key", "error", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if poolTokenIndex != celoutils.ZeroAddress {
|
||||||
|
if err := cache.Add(ctx, poolTokenIndex.Hex()); err != nil {
|
||||||
|
lo.Error("redis error setting key", "error", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
poolTokenIndexIter, err := chain.Provider().NewBatchIterator(ctx, poolTokenIndex)
|
||||||
|
if err != nil {
|
||||||
|
lo.Error("error creating pool token index iter", "error", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
for {
|
||||||
|
batch, err := poolTokenIndexIter.Next(ctx)
|
||||||
|
if err != nil {
|
||||||
|
lo.Error("error fetching next pool token index batch", "error", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
if batch == nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
lo.Debug("index batch", "index", poolTokenIndex.Hex(), "size", len(batch))
|
||||||
|
for _, address := range batch {
|
||||||
|
if address != celoutils.ZeroAddress {
|
||||||
|
if err := cache.Add(ctx, address.Hex()); err != nil {
|
||||||
|
lo.Error("redis error setting key", "error", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if accountsIndex := registryMap[celoutils.AccountIndex]; accountsIndex != celoutils.ZeroAddress {
|
||||||
|
accountsIndexIter, err := chain.Provider().NewBatchIterator(ctx, accountsIndex)
|
||||||
|
if err != nil {
|
||||||
|
lo.Error("could not create accounts index iter", "error", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
for {
|
||||||
|
batch, err := accountsIndexIter.Next(ctx)
|
||||||
|
if err != nil {
|
||||||
|
lo.Error("error fetching next accounts index batch", "error", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
if batch == nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
lo.Debug("index batch", "index", accountsIndex.Hex(), "size", len(batch))
|
||||||
|
for _, address := range batch {
|
||||||
|
if err := cache.Add(ctx, address.Hex()); err != nil {
|
||||||
|
lo.Error("redis error setting key", "error", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, v := range registryMap {
|
||||||
|
if err := cache.Add(ctx, v.Hex()); err != nil {
|
||||||
|
lo.Error("redis error setting key", "error", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, address := range ko.MustStrings("bootstrap.watchlist") {
|
||||||
|
if err := cache.Add(ctx, address); err != nil {
|
||||||
|
lo.Error("redis error setting key", "error", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, address := range ko.MustStrings("bootstrap.blacklist") {
|
||||||
|
if err := cache.Remove(ctx, address); err != nil {
|
||||||
|
lo.Error("redis error deleting key", "error", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := cache.Remove(ctx, celoutils.ZeroAddress.Hex()); err != nil {
|
||||||
|
lo.Error("redis error deleting key", "error", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
cacheSize, err := cache.Size(ctx)
|
||||||
|
if err != nil {
|
||||||
|
lo.Warn("error fetching cache size")
|
||||||
|
}
|
||||||
|
|
||||||
|
lo.Info("redis cache bootstrap complete", "addresses_cached", cacheSize)
|
||||||
|
}
|
209
cmd/service/main.go
Normal file
209
cmd/service/main.go
Normal file
@ -0,0 +1,209 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"flag"
|
||||||
|
"log/slog"
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"os/signal"
|
||||||
|
"runtime"
|
||||||
|
"sync"
|
||||||
|
"syscall"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/grassrootseconomics/celo-tracker/db"
|
||||||
|
"github.com/grassrootseconomics/celo-tracker/internal/api"
|
||||||
|
"github.com/grassrootseconomics/celo-tracker/internal/backfill"
|
||||||
|
"github.com/grassrootseconomics/celo-tracker/internal/cache"
|
||||||
|
"github.com/grassrootseconomics/celo-tracker/internal/chain"
|
||||||
|
"github.com/grassrootseconomics/celo-tracker/internal/pool"
|
||||||
|
"github.com/grassrootseconomics/celo-tracker/internal/processor"
|
||||||
|
"github.com/grassrootseconomics/celo-tracker/internal/pub"
|
||||||
|
"github.com/grassrootseconomics/celo-tracker/internal/router"
|
||||||
|
"github.com/grassrootseconomics/celo-tracker/internal/stats"
|
||||||
|
"github.com/grassrootseconomics/celo-tracker/internal/syncer"
|
||||||
|
"github.com/grassrootseconomics/celo-tracker/internal/util"
|
||||||
|
"github.com/knadh/koanf/v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
const defaultGracefulShutdownPeriod = time.Second * 30
|
||||||
|
|
||||||
|
var (
|
||||||
|
build = "dev"
|
||||||
|
|
||||||
|
confFlag string
|
||||||
|
|
||||||
|
lo *slog.Logger
|
||||||
|
ko *koanf.Koanf
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
flag.StringVar(&confFlag, "config", "config.toml", "Config file location")
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
|
lo = util.InitLogger()
|
||||||
|
ko = util.InitConfig(lo, confFlag)
|
||||||
|
|
||||||
|
lo.Info("starting celo tracker", "build", build)
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
var wg sync.WaitGroup
|
||||||
|
ctx, stop := notifyShutdown()
|
||||||
|
|
||||||
|
chain, err := chain.NewRPCFetcher(chain.CeloRPCOpts{
|
||||||
|
RPCEndpoint: ko.MustString("chain.rpc_endpoint"),
|
||||||
|
ChainID: ko.MustInt64("chain.chainid"),
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
lo.Error("could not initialize chain client", "error", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
db, err := db.New(db.DBOpts{
|
||||||
|
Logg: lo,
|
||||||
|
DBType: ko.MustString("core.db_type"),
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
lo.Error("could not initialize blocks db", "error", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
cache, err := cache.New(cache.CacheOpts{
|
||||||
|
Logg: lo,
|
||||||
|
CacheType: ko.MustString("core.cache_type"),
|
||||||
|
RedisDSN: ko.MustString("redis.dsn"),
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
lo.Error("could not initialize cache", "error", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
jetStreamPub, err := pub.NewJetStreamPub(pub.JetStreamOpts{
|
||||||
|
Endpoint: ko.MustString("jetstream.endpoint"),
|
||||||
|
PersistDuration: time.Duration(ko.MustInt("jetstream.persist_duration_hrs")) * time.Hour,
|
||||||
|
DedupDuration: time.Duration(ko.MustInt("jetstream.dedup_duration_hrs")) * time.Hour,
|
||||||
|
Logg: lo,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
lo.Error("could not initialize jetstream pub", "error", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
router := router.New(router.RouterOpts{
|
||||||
|
Pub: jetStreamPub,
|
||||||
|
Cache: cache,
|
||||||
|
})
|
||||||
|
|
||||||
|
blockProcessor := processor.NewProcessor(processor.ProcessorOpts{
|
||||||
|
Cache: cache,
|
||||||
|
Chain: chain,
|
||||||
|
DB: db,
|
||||||
|
Router: router,
|
||||||
|
Logg: lo,
|
||||||
|
})
|
||||||
|
|
||||||
|
poolOpts := pool.PoolOpts{
|
||||||
|
Logg: lo,
|
||||||
|
WorkerCount: ko.Int("core.pool_size"),
|
||||||
|
Processor: blockProcessor,
|
||||||
|
}
|
||||||
|
if ko.Int("core.pool_size") <= 0 {
|
||||||
|
poolOpts.WorkerCount = runtime.NumCPU() * 3
|
||||||
|
}
|
||||||
|
workerPool := pool.New(poolOpts)
|
||||||
|
|
||||||
|
stats := stats.New(stats.StatsOpts{
|
||||||
|
Cache: cache,
|
||||||
|
Logg: lo,
|
||||||
|
Pool: workerPool,
|
||||||
|
})
|
||||||
|
|
||||||
|
chainSyncer, err := syncer.New(syncer.SyncerOpts{
|
||||||
|
DB: db,
|
||||||
|
Chain: chain,
|
||||||
|
Logg: lo,
|
||||||
|
Pool: workerPool,
|
||||||
|
Stats: stats,
|
||||||
|
StartBlock: ko.Int64("chain.start_block"),
|
||||||
|
WebSocketEndpoint: ko.MustString("chain.ws_endpoint"),
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
lo.Error("could not initialize chain syncer", "error", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
backfill := backfill.New(backfill.BackfillOpts{
|
||||||
|
DB: db,
|
||||||
|
Logg: lo,
|
||||||
|
Pool: workerPool,
|
||||||
|
})
|
||||||
|
|
||||||
|
apiServer := &http.Server{
|
||||||
|
Addr: ko.MustString("api.address"),
|
||||||
|
Handler: api.New(),
|
||||||
|
}
|
||||||
|
|
||||||
|
wg.Add(1)
|
||||||
|
go func() {
|
||||||
|
defer wg.Done()
|
||||||
|
chainSyncer.Start()
|
||||||
|
}()
|
||||||
|
|
||||||
|
wg.Add(1)
|
||||||
|
go func() {
|
||||||
|
defer wg.Done()
|
||||||
|
if err := backfill.Run(false); err != nil {
|
||||||
|
lo.Error("backfiller initial run error", "error", err)
|
||||||
|
}
|
||||||
|
backfill.Start()
|
||||||
|
}()
|
||||||
|
|
||||||
|
wg.Add(1)
|
||||||
|
go func() {
|
||||||
|
defer wg.Done()
|
||||||
|
lo.Info("metrics and stats server starting", "address", ko.MustString("api.address"))
|
||||||
|
if err := apiServer.ListenAndServe(); err != http.ErrServerClosed {
|
||||||
|
lo.Error("failed to start API server", "error", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
<-ctx.Done()
|
||||||
|
lo.Info("shutdown signal received")
|
||||||
|
shutdownCtx, cancel := context.WithTimeout(context.Background(), defaultGracefulShutdownPeriod)
|
||||||
|
|
||||||
|
wg.Add(1)
|
||||||
|
go func() {
|
||||||
|
defer wg.Done()
|
||||||
|
chainSyncer.Stop()
|
||||||
|
backfill.Stop()
|
||||||
|
workerPool.Stop()
|
||||||
|
jetStreamPub.Close()
|
||||||
|
db.Cleanup()
|
||||||
|
db.Close()
|
||||||
|
apiServer.Shutdown(shutdownCtx)
|
||||||
|
lo.Info("graceful shutdown routine complete")
|
||||||
|
}()
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
wg.Wait()
|
||||||
|
stop()
|
||||||
|
cancel()
|
||||||
|
os.Exit(0)
|
||||||
|
}()
|
||||||
|
|
||||||
|
<-shutdownCtx.Done()
|
||||||
|
if errors.Is(shutdownCtx.Err(), context.DeadlineExceeded) {
|
||||||
|
stop()
|
||||||
|
cancel()
|
||||||
|
lo.Error("graceful shutdown period exceeded, forcefully shutting down")
|
||||||
|
}
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
func notifyShutdown() (context.Context, context.CancelFunc) {
|
||||||
|
return signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM, syscall.SIGINT)
|
||||||
|
}
|
42
config.toml
Normal file
42
config.toml
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
[api]
|
||||||
|
# Exposes /debug and /stats
|
||||||
|
address = ":5001"
|
||||||
|
|
||||||
|
[core]
|
||||||
|
# Use a specific cache implementation
|
||||||
|
cache_type = "redis"
|
||||||
|
# Use a specific db implementation
|
||||||
|
db_type = "bolt"
|
||||||
|
# Tune max go routines that can process blocks
|
||||||
|
# Defaults to (nproc * 3)
|
||||||
|
pool_size = 0
|
||||||
|
# If you are using an archive node, set this to true
|
||||||
|
|
||||||
|
[redis]
|
||||||
|
dsn = "127.0.0.1:6379"
|
||||||
|
|
||||||
|
[chain]
|
||||||
|
ws_endpoint = "wss://ws.celo.grassecon.net"
|
||||||
|
rpc_endpoint = "https://celo.grassecon.net"
|
||||||
|
# Defaults to Celo mainnet
|
||||||
|
# At the moment only support Celo based blockchains
|
||||||
|
chainid = 42220
|
||||||
|
# This will start a backfill if set to any other value
|
||||||
|
# Ideally this should remain 0
|
||||||
|
start_block = 0
|
||||||
|
|
||||||
|
[bootstrap]
|
||||||
|
# This will bootstrap the cache on which addresses to track
|
||||||
|
# Grassroots Economics specific registries that autoload all other smart contracts
|
||||||
|
ge_registries = [
|
||||||
|
"0xd1FB944748aca327a1ba036B082993D9dd9Bfa0C",
|
||||||
|
"0x0cc9f4fff962def35bb34a53691180b13e653030",
|
||||||
|
]
|
||||||
|
watchlist = [""]
|
||||||
|
blacklist = [""]
|
||||||
|
|
||||||
|
[jetstream]
|
||||||
|
enable = true
|
||||||
|
endpoint = "nats://127.0.0.1:4222"
|
||||||
|
persist_duration_hrs = 48
|
||||||
|
dedup_duration_hrs = 6
|
180
db/bolt.go
Normal file
180
db/bolt.go
Normal file
@ -0,0 +1,180 @@
|
|||||||
|
package db
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/binary"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/bits-and-blooms/bitset"
|
||||||
|
bolt "go.etcd.io/bbolt"
|
||||||
|
)
|
||||||
|
|
||||||
|
type boltDB struct {
|
||||||
|
db *bolt.DB
|
||||||
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
dbFolderName = "tracker_db"
|
||||||
|
|
||||||
|
upperBoundKey = "upper"
|
||||||
|
lowerBoundKey = "lower"
|
||||||
|
)
|
||||||
|
|
||||||
|
var sortableOrder = binary.BigEndian
|
||||||
|
|
||||||
|
func NewBoltDB() (DB, error) {
|
||||||
|
db, err := bolt.Open(dbFolderName, 0600, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
db.Update(func(tx *bolt.Tx) error {
|
||||||
|
_, err := tx.CreateBucketIfNotExists([]byte("blocks"))
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("create bucket: %s", err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
return &boltDB{
|
||||||
|
db: db,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *boltDB) Close() error {
|
||||||
|
return d.db.Close()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *boltDB) get(k string) ([]byte, error) {
|
||||||
|
var v []byte
|
||||||
|
err := d.db.View(func(tx *bolt.Tx) error {
|
||||||
|
b := tx.Bucket([]byte("blocks"))
|
||||||
|
v = b.Get([]byte(k))
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return v, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *boltDB) setUint64(k string, v uint64) error {
|
||||||
|
err := d.db.Update(func(tx *bolt.Tx) error {
|
||||||
|
b := tx.Bucket([]byte("blocks"))
|
||||||
|
return b.Put([]byte(k), marshalUint64(v))
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *boltDB) setUint64AsKey(v uint64) error {
|
||||||
|
err := d.db.Update(func(tx *bolt.Tx) error {
|
||||||
|
b := tx.Bucket([]byte("blocks"))
|
||||||
|
return b.Put(marshalUint64(v), nil)
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func unmarshalUint64(b []byte) uint64 {
|
||||||
|
return sortableOrder.Uint64(b)
|
||||||
|
}
|
||||||
|
|
||||||
|
func marshalUint64(v uint64) []byte {
|
||||||
|
b := make([]byte, 8)
|
||||||
|
sortableOrder.PutUint64(b, v)
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *boltDB) SetLowerBound(v uint64) error {
|
||||||
|
return d.setUint64(lowerBoundKey, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *boltDB) GetLowerBound() (uint64, error) {
|
||||||
|
v, err := d.get(lowerBoundKey)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if v == nil {
|
||||||
|
return 0, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return unmarshalUint64(v), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *boltDB) SetUpperBound(v uint64) error {
|
||||||
|
return d.setUint64(upperBoundKey, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *boltDB) GetUpperBound() (uint64, error) {
|
||||||
|
v, err := d.get(upperBoundKey)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
return unmarshalUint64(v), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *boltDB) SetValue(v uint64) error {
|
||||||
|
return d.setUint64AsKey(v)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *boltDB) GetMissingValuesBitSet(lowerBound uint64, upperBound uint64) (*bitset.BitSet, error) {
|
||||||
|
var b bitset.BitSet
|
||||||
|
|
||||||
|
err := d.db.View(func(tx *bolt.Tx) error {
|
||||||
|
var (
|
||||||
|
lowerRaw = marshalUint64(lowerBound)
|
||||||
|
upperRaw = marshalUint64(upperBound)
|
||||||
|
)
|
||||||
|
|
||||||
|
for i := lowerBound; i <= upperBound; i++ {
|
||||||
|
b.Set(uint(i))
|
||||||
|
}
|
||||||
|
|
||||||
|
c := tx.Bucket([]byte("blocks")).Cursor()
|
||||||
|
|
||||||
|
for k, _ := c.Seek(lowerRaw); k != nil && bytes.Compare(k, upperRaw) <= 0; k, _ = c.Next() {
|
||||||
|
b.Clear(uint(unmarshalUint64(k)))
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &b, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *boltDB) Cleanup() error {
|
||||||
|
lowerBound, err := d.GetLowerBound()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
target := marshalUint64(lowerBound - 1)
|
||||||
|
|
||||||
|
err = d.db.View(func(tx *bolt.Tx) error {
|
||||||
|
b := tx.Bucket([]byte("blocks"))
|
||||||
|
c := b.Cursor()
|
||||||
|
|
||||||
|
for k, _ := c.First(); k != nil && bytes.Compare(k, target) <= 0; k, _ = c.Next() {
|
||||||
|
if err := b.Delete(k); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
48
db/db.go
Normal file
48
db/db.go
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
package db
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log/slog"
|
||||||
|
|
||||||
|
"github.com/bits-and-blooms/bitset"
|
||||||
|
)
|
||||||
|
|
||||||
|
type (
|
||||||
|
DB interface {
|
||||||
|
Close() error
|
||||||
|
GetLowerBound() (uint64, error)
|
||||||
|
SetLowerBound(v uint64) error
|
||||||
|
SetUpperBound(uint64) error
|
||||||
|
GetUpperBound() (uint64, error)
|
||||||
|
SetValue(uint64) error
|
||||||
|
GetMissingValuesBitSet(uint64, uint64) (*bitset.BitSet, error)
|
||||||
|
Cleanup() error
|
||||||
|
}
|
||||||
|
|
||||||
|
DBOpts struct {
|
||||||
|
Logg *slog.Logger
|
||||||
|
DBType string
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
func New(o DBOpts) (DB, error) {
|
||||||
|
var (
|
||||||
|
err error
|
||||||
|
db DB
|
||||||
|
)
|
||||||
|
|
||||||
|
switch o.DBType {
|
||||||
|
case "bolt":
|
||||||
|
db, err = NewBoltDB()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
db, err = NewBoltDB()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
o.Logg.Warn("invalid db type, using default type (bolt)")
|
||||||
|
}
|
||||||
|
|
||||||
|
return db, nil
|
||||||
|
}
|
1
db/redis.go
Normal file
1
db/redis.go
Normal file
@ -0,0 +1 @@
|
|||||||
|
package db
|
24
dev/docker-compose.yaml
Normal file
24
dev/docker-compose.yaml
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
services:
|
||||||
|
redis:
|
||||||
|
image: redis:7-alpine
|
||||||
|
restart: unless-stopped
|
||||||
|
command: redis-server --save 60 1 --loglevel warning
|
||||||
|
volumes:
|
||||||
|
- tracker-redis:/data
|
||||||
|
ports:
|
||||||
|
- "127.0.0.1:6379:6379"
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD-SHELL", "redis-cli ping | grep PONG"]
|
||||||
|
interval: 10s
|
||||||
|
timeout: 5s
|
||||||
|
retries: 5
|
||||||
|
nats:
|
||||||
|
image: nats:2
|
||||||
|
restart: unless-stopped
|
||||||
|
command: -js -sd /tmp/nats/data -m 8222
|
||||||
|
ports:
|
||||||
|
- 0.0.0.0:4222:4222
|
||||||
|
- 0.0.0.0:8222:8222
|
||||||
|
volumes:
|
||||||
|
tracker-redis:
|
||||||
|
driver: local
|
83
go.mod
Normal file
83
go.mod
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
module github.com/grassrootseconomics/celo-tracker
|
||||||
|
|
||||||
|
go 1.23.0
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/VictoriaMetrics/metrics v1.35.1
|
||||||
|
github.com/alitto/pond v1.9.1
|
||||||
|
github.com/bits-and-blooms/bitset v1.13.0
|
||||||
|
github.com/celo-org/celo-blockchain v1.8.4
|
||||||
|
github.com/grassrootseconomics/celoutils/v3 v3.3.1
|
||||||
|
github.com/grassrootseconomics/w3-celo v0.19.0
|
||||||
|
github.com/kamikazechaser/common v0.2.0
|
||||||
|
github.com/knadh/koanf/parsers/toml v0.1.0
|
||||||
|
github.com/knadh/koanf/providers/env v0.1.0
|
||||||
|
github.com/knadh/koanf/providers/file v1.1.0
|
||||||
|
github.com/knadh/koanf/v2 v2.1.1
|
||||||
|
github.com/nats-io/nats.go v1.36.0
|
||||||
|
github.com/puzpuzpuz/xsync/v3 v3.4.0
|
||||||
|
github.com/redis/rueidis v1.0.44
|
||||||
|
github.com/stretchr/testify v1.9.0
|
||||||
|
github.com/uptrace/bunrouter v1.0.21
|
||||||
|
go.etcd.io/bbolt v1.3.10
|
||||||
|
)
|
||||||
|
|
||||||
|
require (
|
||||||
|
filippo.io/edwards25519 v1.0.0-alpha.2 // indirect
|
||||||
|
github.com/StackExchange/wmi v1.2.1 // indirect
|
||||||
|
github.com/VictoriaMetrics/fastcache v1.12.2 // indirect
|
||||||
|
github.com/btcsuite/btcd/btcec/v2 v2.2.0 // indirect
|
||||||
|
github.com/celo-org/celo-bls-go v0.3.4 // indirect
|
||||||
|
github.com/celo-org/celo-bls-go-android v0.3.3 // indirect
|
||||||
|
github.com/celo-org/celo-bls-go-ios v0.3.3 // indirect
|
||||||
|
github.com/celo-org/celo-bls-go-linux v0.3.3 // indirect
|
||||||
|
github.com/celo-org/celo-bls-go-macos v0.3.3 // indirect
|
||||||
|
github.com/celo-org/celo-bls-go-other v0.3.3 // indirect
|
||||||
|
github.com/celo-org/celo-bls-go-windows v0.3.3 // indirect
|
||||||
|
github.com/cespare/xxhash/v2 v2.3.0 // indirect
|
||||||
|
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||||
|
github.com/deckarep/golang-set v1.8.0 // indirect
|
||||||
|
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect
|
||||||
|
github.com/fsnotify/fsnotify v1.7.0 // indirect
|
||||||
|
github.com/go-ole/go-ole v1.3.0 // indirect
|
||||||
|
github.com/go-stack/stack v1.8.1 // indirect
|
||||||
|
github.com/go-viper/mapstructure/v2 v2.0.0-alpha.1 // indirect
|
||||||
|
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect
|
||||||
|
github.com/google/go-cmp v0.6.0 // indirect
|
||||||
|
github.com/gorilla/websocket v1.5.0 // indirect
|
||||||
|
github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d // indirect
|
||||||
|
github.com/hdevalence/ed25519consensus v0.0.0-20201207055737-7fde80a9d5ff // indirect
|
||||||
|
github.com/holiman/bloomfilter/v2 v2.0.3 // indirect
|
||||||
|
github.com/holiman/uint256 v1.3.0 // indirect
|
||||||
|
github.com/huin/goupnp v1.3.0 // indirect
|
||||||
|
github.com/jackpal/go-nat-pmp v1.0.2 // indirect
|
||||||
|
github.com/klauspost/compress v1.17.2 // indirect
|
||||||
|
github.com/knadh/koanf/maps v0.1.1 // indirect
|
||||||
|
github.com/lmittmann/tint v1.0.4 // indirect
|
||||||
|
github.com/mattn/go-runewidth v0.0.14 // indirect
|
||||||
|
github.com/mitchellh/copystructure v1.2.0 // indirect
|
||||||
|
github.com/mitchellh/reflectwalk v1.0.2 // indirect
|
||||||
|
github.com/nats-io/nkeys v0.4.7 // indirect
|
||||||
|
github.com/nats-io/nuid v1.0.1 // indirect
|
||||||
|
github.com/olekukonko/tablewriter v0.0.5 // indirect
|
||||||
|
github.com/onsi/gomega v1.31.1 // indirect
|
||||||
|
github.com/pelletier/go-toml v1.9.5 // indirect
|
||||||
|
github.com/pkg/errors v0.9.1 // indirect
|
||||||
|
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||||
|
github.com/prometheus/tsdb v0.7.1 // indirect
|
||||||
|
github.com/rivo/uniseg v0.4.2 // indirect
|
||||||
|
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible // indirect
|
||||||
|
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 // indirect
|
||||||
|
github.com/tklauser/go-sysconf v0.3.12 // indirect
|
||||||
|
github.com/tklauser/numcpus v0.6.1 // indirect
|
||||||
|
github.com/valyala/fastrand v1.1.0 // indirect
|
||||||
|
github.com/valyala/histogram v1.2.0 // indirect
|
||||||
|
golang.org/x/crypto v0.25.0 // indirect
|
||||||
|
golang.org/x/net v0.24.0 // indirect
|
||||||
|
golang.org/x/sync v0.7.0 // indirect
|
||||||
|
golang.org/x/sys v0.22.0 // indirect
|
||||||
|
golang.org/x/text v0.16.0 // indirect
|
||||||
|
golang.org/x/time v0.5.0 // indirect
|
||||||
|
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect
|
||||||
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
|
)
|
291
go.sum
Normal file
291
go.sum
Normal file
@ -0,0 +1,291 @@
|
|||||||
|
filippo.io/edwards25519 v1.0.0-alpha.2 h1:EWbZLqGEPSIj2W69gx04KtNVkyPIfe3uj0DhDQJonbQ=
|
||||||
|
filippo.io/edwards25519 v1.0.0-alpha.2/go.mod h1:X+pm78QAUPtFLi1z9PYIlS/bdDnvbCOGKtZ+ACWEf7o=
|
||||||
|
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
|
||||||
|
github.com/StackExchange/wmi v1.2.1 h1:VIkavFPXSjcnS+O8yTq7NI32k0R5Aj+v39y29VYDOSA=
|
||||||
|
github.com/StackExchange/wmi v1.2.1/go.mod h1:rcmrprowKIVzvc+NUiLncP2uuArMWLCbu9SBzvHz7e8=
|
||||||
|
github.com/VictoriaMetrics/fastcache v1.12.2 h1:N0y9ASrJ0F6h0QaC3o6uJb3NIZ9VKLjCM7NQbSmF7WI=
|
||||||
|
github.com/VictoriaMetrics/fastcache v1.12.2/go.mod h1:AmC+Nzz1+3G2eCPapF6UcsnkThDcMsQicp4xDukwJYI=
|
||||||
|
github.com/VictoriaMetrics/metrics v1.35.1 h1:o84wtBKQbzLdDy14XeskkCZih6anG+veZ1SwJHFGwrU=
|
||||||
|
github.com/VictoriaMetrics/metrics v1.35.1/go.mod h1:r7hveu6xMdUACXvB8TYdAj8WEsKzWB0EkpJN+RDtOf8=
|
||||||
|
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
|
||||||
|
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
|
||||||
|
github.com/alitto/pond v1.9.1 h1:OfCpIrMyrWJpn34f647DcFmUxjK8+7Nu3eoVN/WTP+o=
|
||||||
|
github.com/alitto/pond v1.9.1/go.mod h1:xQn3P/sHTYcU/1BR3i86IGIrilcrGC2LiS+E2+CJWsI=
|
||||||
|
github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156 h1:eMwmnE/GDgah4HI848JfFxHt+iPb26b4zyfspmqY0/8=
|
||||||
|
github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156/go.mod h1:Cb/ax3seSYIx7SuZdm2G2xzfwmv3TPSk2ucNfQESPXM=
|
||||||
|
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
|
||||||
|
github.com/bits-and-blooms/bitset v1.13.0 h1:bAQ9OPNFYbGHV6Nez0tmNI0RiEu7/hxlYJRUA0wFAVE=
|
||||||
|
github.com/bits-and-blooms/bitset v1.13.0/go.mod h1:7hO7Gc7Pp1vODcmWvKMRA9BNmbv6a/7QIWpPxHddWR8=
|
||||||
|
github.com/btcsuite/btcd v0.23.2 h1:/YOgUp25sdCnP5ho6Hl3s0E438zlX+Kak7E6TgBgoT0=
|
||||||
|
github.com/btcsuite/btcd/btcec/v2 v2.2.0 h1:fzn1qaOt32TuLjFlkzYSsBC35Q3KUjT1SwPxiMSCF5k=
|
||||||
|
github.com/btcsuite/btcd/btcec/v2 v2.2.0/go.mod h1:U7MHm051Al6XmscBQ0BoNydpOTsFAn707034b5nY8zU=
|
||||||
|
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 h1:q0rUy8C/TYNBQS1+CGKw68tLOFYSNEs0TFnxxnS9+4U=
|
||||||
|
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1/go.mod h1:7SFka0XMvUgj3hfZtydOrQY2mwhPclbT2snogU7SQQc=
|
||||||
|
github.com/buraksezer/consistent v0.0.0-20191006190839-693edf70fd72 h1:fUmDBbSvv1uOzo/t8WaxZMVb7BxJ8JECo5lGoR9c5bA=
|
||||||
|
github.com/buraksezer/consistent v0.0.0-20191006190839-693edf70fd72/go.mod h1:OEE5igu/CDjGegM1Jn6ZMo7R6LlV/JChAkjfQQIRLpg=
|
||||||
|
github.com/celo-org/celo-blockchain v1.8.4 h1:QJiRRGcZyO+PutT8WkFO1juORANAOGhN8yGNP7HvBqk=
|
||||||
|
github.com/celo-org/celo-blockchain v1.8.4/go.mod h1:0udpV9QnZ2rnVu3vf8G9Wjs5di6Bf9urjwGVgAUEGB8=
|
||||||
|
github.com/celo-org/celo-bls-go v0.3.4 h1:slNePT/gVjgUi7f8M4KTwBz/YYgv3JWU6XqyY0xKN84=
|
||||||
|
github.com/celo-org/celo-bls-go v0.3.4/go.mod h1:qDZHMC3bBqOw5qle28cRtKlEyJhslZtckcc2Tomqdks=
|
||||||
|
github.com/celo-org/celo-bls-go-android v0.3.3 h1:iZ2Gragn3JItkptmppeq1SENmNVc1f1W25UE4u231HY=
|
||||||
|
github.com/celo-org/celo-bls-go-android v0.3.3/go.mod h1:cFgtFRH8+6x5b+EyG5SqniXY3aKd03NBSGDgITscX34=
|
||||||
|
github.com/celo-org/celo-bls-go-ios v0.3.3 h1:/yHaEYft9WfXyPIGuJz7V2/r+tp2IqSpkvKsMsVgbuY=
|
||||||
|
github.com/celo-org/celo-bls-go-ios v0.3.3/go.mod h1:eaSoMpx29YV5oF7jXVChzJpNfxeZHnAa8G4PjL5CyW0=
|
||||||
|
github.com/celo-org/celo-bls-go-linux v0.3.3 h1:ukSQSIRyFCQeC1i7LJJunRKvlLuG1JMwNZ6DQZC51fE=
|
||||||
|
github.com/celo-org/celo-bls-go-linux v0.3.3/go.mod h1:DVpJadg22OrxBtMb0ub6iNVdqDBL/r6EDdWVAA0bHa0=
|
||||||
|
github.com/celo-org/celo-bls-go-macos v0.3.3 h1:H4ZGc+kS3e/w9Q6qru6FtlkYtVDS8eIQgw6UURB/Jlo=
|
||||||
|
github.com/celo-org/celo-bls-go-macos v0.3.3/go.mod h1:mYPuRqGMVxj6yZUeL6Q6ggtP52HPBS1jz+FvBPXQ7QA=
|
||||||
|
github.com/celo-org/celo-bls-go-other v0.3.3 h1:/Q9SLJK22hibPm/WI/OPxbBmgXTgUhjUgobfzz7qj/w=
|
||||||
|
github.com/celo-org/celo-bls-go-other v0.3.3/go.mod h1:tNxZNfekzyT7TdYQbyNPhkfpcYtA3KCU/IKX5FNxM/U=
|
||||||
|
github.com/celo-org/celo-bls-go-windows v0.3.3 h1:0IP+Ad9l+op50TIfkmFr+j7+TIjKksVROe+EoF7Ixa4=
|
||||||
|
github.com/celo-org/celo-bls-go-windows v0.3.3/go.mod h1:82GC5iJA9Qw5gynhYqR8ht3J+l/MO8eSNzgSTMI8UdA=
|
||||||
|
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
|
||||||
|
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||||
|
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
|
||||||
|
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||||
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/deckarep/golang-set v1.8.0 h1:sk9/l/KqpunDwP7pSjUg0keiOOLEnOBHzykLrsPppp4=
|
||||||
|
github.com/deckarep/golang-set v1.8.0/go.mod h1:5nI87KwE7wgsBU1F4GKAw2Qod7p5kyS383rP6+o6qqo=
|
||||||
|
github.com/decred/dcrd/crypto/blake256 v1.0.0 h1:/8DMNYp9SGi5f0w7uCm6d6M4OU2rGFK09Y2A4Xv7EE0=
|
||||||
|
github.com/decred/dcrd/crypto/blake256 v1.0.0/go.mod h1:sQl2p6Y26YV+ZOcSTP6thNdn47hh8kt6rqSlvmrXFAc=
|
||||||
|
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 h1:YLtO71vCjJRCBcrPMtQ9nqBsqpA1m5sE92cU+pd5Mcc=
|
||||||
|
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1/go.mod h1:hyedUtir6IdtD/7lIxGeCxkaw7y45JueMRL4DIyJDKs=
|
||||||
|
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
|
||||||
|
github.com/fjl/memsize v0.0.0-20190710130421-bcb5799ab5e5 h1:FtmdgXiUlNeRsoNMFlKLDt+S+6hbjVMEW6RGQ7aUf7c=
|
||||||
|
github.com/fjl/memsize v0.0.0-20190710130421-bcb5799ab5e5/go.mod h1:VvhXpOYNQvB+uIk2RvXzuaQtkQJzzIx6lSBe1xv7hi0=
|
||||||
|
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
||||||
|
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
|
||||||
|
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
|
||||||
|
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
|
||||||
|
github.com/go-kit/kit v0.8.0 h1:Wz+5lgoB0kkuqLEc6NVmwRknTKP6dTGbSqvhZtBI/j0=
|
||||||
|
github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
|
||||||
|
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
|
||||||
|
github.com/go-logfmt/logfmt v0.5.1 h1:otpy5pqBCBZ1ng9RQ0dPu4PN7ba75Y/aA+UpowDyNVA=
|
||||||
|
github.com/go-logfmt/logfmt v0.5.1/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs=
|
||||||
|
github.com/go-logr/logr v1.3.0 h1:2y3SDp0ZXuc6/cjLSZ+Q3ir+QB9T/iG5yYRXqsagWSY=
|
||||||
|
github.com/go-logr/logr v1.3.0/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
|
||||||
|
github.com/go-ole/go-ole v1.2.5/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
|
||||||
|
github.com/go-ole/go-ole v1.3.0 h1:Dt6ye7+vXGIKZ7Xtk4s6/xVdGDQynvom7xCFEdWr6uE=
|
||||||
|
github.com/go-ole/go-ole v1.3.0/go.mod h1:5LS6F96DhAwUc7C+1HLexzMXY1xGRSryjyPPKW6zv78=
|
||||||
|
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
|
||||||
|
github.com/go-stack/stack v1.8.1 h1:ntEHSVwIt7PNXNpgPmVfMrNhLtgjlmnZha2kOpuRiDw=
|
||||||
|
github.com/go-stack/stack v1.8.1/go.mod h1:dcoOX6HbPZSZptuspn9bctJ+N/CnF5gGygcUP3XYfe4=
|
||||||
|
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI=
|
||||||
|
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls=
|
||||||
|
github.com/go-viper/mapstructure/v2 v2.0.0-alpha.1 h1:TQcrn6Wq+sKGkpyPvppOz99zsMBaUOKXq6HSv655U1c=
|
||||||
|
github.com/go-viper/mapstructure/v2 v2.0.0-alpha.1/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM=
|
||||||
|
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
|
||||||
|
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||||
|
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
|
||||||
|
github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
|
||||||
|
github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
|
||||||
|
github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
|
||||||
|
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
|
||||||
|
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
|
||||||
|
github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||||
|
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb h1:PBC98N2aIaM3XXiurYmW7fx4GZkL8feAMVq7nEjURHk=
|
||||||
|
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||||
|
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||||
|
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||||
|
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||||
|
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||||
|
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||||
|
github.com/google/pprof v0.0.0-20230207041349-798e818bf904 h1:4/hN5RUoecvl+RmJRE2YxKWtnnQls6rQjjW5oV7qg2U=
|
||||||
|
github.com/google/pprof v0.0.0-20230207041349-798e818bf904/go.mod h1:uglQLonpP8qtYCYyzA+8c/9qtqgA3qsXGYqCPKARAFg=
|
||||||
|
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
|
||||||
|
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
|
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
|
||||||
|
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||||
|
github.com/grassrootseconomics/celoutils/v3 v3.3.1 h1:ehf0eG2c8BfR2DojOm/nk8SQ44DyTFxXKISw1dHym/w=
|
||||||
|
github.com/grassrootseconomics/celoutils/v3 v3.3.1/go.mod h1:HTHFNnWmvL6rY096xAraOMV3POYFAquoTABP6ogaF7U=
|
||||||
|
github.com/grassrootseconomics/w3-celo v0.19.0 h1:3O5GK2os3/f9D/5oKsB0YxGyO5S3aqon/kx7ckyjQ4o=
|
||||||
|
github.com/grassrootseconomics/w3-celo v0.19.0/go.mod h1:M3KJaj25DspF9siaqNXyamAuzC5DmWXx74tpyPp+R4Y=
|
||||||
|
github.com/hashicorp/go-bexpr v0.1.10 h1:9kuI5PFotCboP3dkDYFr/wi0gg0QVbSNz5oFRpxn4uE=
|
||||||
|
github.com/hashicorp/go-bexpr v0.1.10/go.mod h1:oxlubA2vC/gFVfX1A6JGp7ls7uCDlfJn732ehYYg+g0=
|
||||||
|
github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d h1:dg1dEPuWpEqDnvIw251EVy4zlP8gWbsGj4BsUKCRpYs=
|
||||||
|
github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4=
|
||||||
|
github.com/hdevalence/ed25519consensus v0.0.0-20201207055737-7fde80a9d5ff h1:LeVKjw8pcDQj7WVVnbFvbD7ovcv+r/l15ka1NH6Lswc=
|
||||||
|
github.com/hdevalence/ed25519consensus v0.0.0-20201207055737-7fde80a9d5ff/go.mod h1:Feit0l8NcNO4g69XNjwvsR0LGcwMMfzI1TF253rOIlQ=
|
||||||
|
github.com/holiman/bloomfilter/v2 v2.0.3 h1:73e0e/V0tCydx14a0SCYS/EWCxgwLZ18CZcZKVu0fao=
|
||||||
|
github.com/holiman/bloomfilter/v2 v2.0.3/go.mod h1:zpoh+gs7qcpqrHr3dB55AMiJwo0iURXE7ZOP9L9hSkA=
|
||||||
|
github.com/holiman/uint256 v1.3.0 h1:4wdcm/tnd0xXdu7iS3ruNvxkWwrb4aeBQv19ayYn8F4=
|
||||||
|
github.com/holiman/uint256 v1.3.0/go.mod h1:EOMSn4q6Nyt9P6efbI3bueV4e1b3dGlUCXeiRV4ng7E=
|
||||||
|
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
|
||||||
|
github.com/huin/goupnp v1.3.0 h1:UvLUlWDNpoUdYzb2TCn+MuTWtcjXKSza2n6CBdQ0xXc=
|
||||||
|
github.com/huin/goupnp v1.3.0/go.mod h1:gnGPsThkYa7bFi/KWmEysQRf48l2dvR5bxr2OFckNX8=
|
||||||
|
github.com/jackpal/go-nat-pmp v1.0.2 h1:KzKSgb7qkJvOUTqYl9/Hg/me3pWgBmERKrTGD7BdWus=
|
||||||
|
github.com/jackpal/go-nat-pmp v1.0.2/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc=
|
||||||
|
github.com/kamikazechaser/common v0.2.0 h1:bqi5UaMTDm/wtZlJEvQDNhsLVJP4Beg+HKWeQ+dhpss=
|
||||||
|
github.com/kamikazechaser/common v0.2.0/go.mod h1:I1LEc8+W+g/KHZWARc1gMhuSa2STbQgfL4Hao6I/ZwY=
|
||||||
|
github.com/klauspost/compress v1.17.2 h1:RlWWUY/Dr4fL8qk9YG7DTZ7PDgME2V4csBXA8L/ixi4=
|
||||||
|
github.com/klauspost/compress v1.17.2/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
|
||||||
|
github.com/knadh/koanf/maps v0.1.1 h1:G5TjmUh2D7G2YWf5SQQqSiHRJEjaicvU0KpypqB3NIs=
|
||||||
|
github.com/knadh/koanf/maps v0.1.1/go.mod h1:npD/QZY3V6ghQDdcQzl1W4ICNVTkohC8E73eI2xW4yI=
|
||||||
|
github.com/knadh/koanf/parsers/toml v0.1.0 h1:S2hLqS4TgWZYj4/7mI5m1CQQcWurxUz6ODgOub/6LCI=
|
||||||
|
github.com/knadh/koanf/parsers/toml v0.1.0/go.mod h1:yUprhq6eo3GbyVXFFMdbfZSo928ksS+uo0FFqNMnO18=
|
||||||
|
github.com/knadh/koanf/providers/env v0.1.0 h1:LqKteXqfOWyx5Ab9VfGHmjY9BvRXi+clwyZozgVRiKg=
|
||||||
|
github.com/knadh/koanf/providers/env v0.1.0/go.mod h1:RE8K9GbACJkeEnkl8L/Qcj8p4ZyPXZIQ191HJi44ZaQ=
|
||||||
|
github.com/knadh/koanf/providers/file v1.1.0 h1:MTjA+gRrVl1zqgetEAIaXHqYje0XSosxSiMD4/7kz0o=
|
||||||
|
github.com/knadh/koanf/providers/file v1.1.0/go.mod h1:/faSBcv2mxPVjFrXck95qeoyoZ5myJ6uxN8OOVNJJCI=
|
||||||
|
github.com/knadh/koanf/v2 v2.1.1 h1:/R8eXqasSTsmDCsAyYj+81Wteg8AqrV9CP6gvsTsOmM=
|
||||||
|
github.com/knadh/koanf/v2 v2.1.1/go.mod h1:4mnTRbZCK+ALuBXHZMjDfG9y714L7TykVnZkXbMU3Es=
|
||||||
|
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
|
||||||
|
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
||||||
|
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
|
||||||
|
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||||
|
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||||
|
github.com/lmittmann/tint v1.0.4 h1:LeYihpJ9hyGvE0w+K2okPTGUdVLfng1+nDNVR4vWISc=
|
||||||
|
github.com/lmittmann/tint v1.0.4/go.mod h1:HIS3gSy7qNwGCj+5oRjAutErFBl4BzdQP6cJZ0NfMwE=
|
||||||
|
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
|
||||||
|
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
|
||||||
|
github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ=
|
||||||
|
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
||||||
|
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
|
||||||
|
github.com/mattn/go-runewidth v0.0.14 h1:+xnbZSEeDbOIg5/mE6JF0w6n9duR1l3/WmbinWVwUuU=
|
||||||
|
github.com/mattn/go-runewidth v0.0.14/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
||||||
|
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
|
||||||
|
github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa15WveJJGw=
|
||||||
|
github.com/mitchellh/copystructure v1.2.0/go.mod h1:qLl+cE2AmVv+CoeAwDPye/v+N2HKCj9FbZEVFJRxO9s=
|
||||||
|
github.com/mitchellh/mapstructure v1.4.1 h1:CpVNEelQCZBooIPDn+AR3NpivK/TIKU8bDxdASFVQag=
|
||||||
|
github.com/mitchellh/mapstructure v1.4.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
|
||||||
|
github.com/mitchellh/pointerstructure v1.2.0 h1:O+i9nHnXS3l/9Wu7r4NrEdwA2VFTicjUEN1uBnDo34A=
|
||||||
|
github.com/mitchellh/pointerstructure v1.2.0/go.mod h1:BRAsLI5zgXmw97Lf6s25bs8ohIXc3tViBH44KcwB2g4=
|
||||||
|
github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zxSIeXaQ=
|
||||||
|
github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
|
||||||
|
github.com/nats-io/nats.go v1.36.0 h1:suEUPuWzTSse/XhESwqLxXGuj8vGRuPRoG7MoRN/qyU=
|
||||||
|
github.com/nats-io/nats.go v1.36.0/go.mod h1:Ubdu4Nh9exXdSz0RVWRFBbRfrbSxOYd26oF0wkWclB8=
|
||||||
|
github.com/nats-io/nkeys v0.4.7 h1:RwNJbbIdYCoClSDNY7QVKZlyb/wfT6ugvFCiKy6vDvI=
|
||||||
|
github.com/nats-io/nkeys v0.4.7/go.mod h1:kqXRgRDPlGy7nGaEDMuYzmiJCIAAWDK0IMBtDmGD0nc=
|
||||||
|
github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw=
|
||||||
|
github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c=
|
||||||
|
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
|
||||||
|
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
|
||||||
|
github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
|
||||||
|
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
|
||||||
|
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
|
||||||
|
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
|
||||||
|
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||||
|
github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk=
|
||||||
|
github.com/onsi/ginkgo v1.14.0 h1:2mOpI4JVVPBN+WQRa0WKH2eXR+Ey+uK4n7Zj0aYpIQA=
|
||||||
|
github.com/onsi/ginkgo v1.14.0/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY=
|
||||||
|
github.com/onsi/ginkgo/v2 v2.15.0 h1:79HwNRBAZHOEwrczrgSOPy+eFTTlIGELKy5as+ClttY=
|
||||||
|
github.com/onsi/ginkgo/v2 v2.15.0/go.mod h1:HlxMHtYF57y6Dpf+mc5529KKmSq9h2FpCF+/ZkwUxKM=
|
||||||
|
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
|
||||||
|
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
|
||||||
|
github.com/onsi/gomega v1.31.1 h1:KYppCUK+bUgAZwHOu7EXVBKyQA6ILvOESHkn/tgoqvo=
|
||||||
|
github.com/onsi/gomega v1.31.1/go.mod h1:y40C95dwAD1Nz36SsEnxvfFe8FFfNxzI5eJ0EYGyAy0=
|
||||||
|
github.com/pelletier/go-toml v1.9.5 h1:4yBQzkHv+7BHq2PQUZF3Mx0IYxG7LsP222s7Agd3ve8=
|
||||||
|
github.com/pelletier/go-toml v1.9.5/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
|
||||||
|
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||||
|
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||||
|
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
|
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
|
||||||
|
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
|
||||||
|
github.com/prometheus/common v0.0.0-20181113130724-41aa239b4cce/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro=
|
||||||
|
github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
|
||||||
|
github.com/prometheus/tsdb v0.7.1 h1:YZcsG11NqnK4czYLrWd9mpEuAJIHVQLwdrleYfszMAA=
|
||||||
|
github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
|
||||||
|
github.com/puzpuzpuz/xsync/v3 v3.4.0 h1:DuVBAdXuGFHv8adVXjWWZ63pJq+NRXOWVXlKDBZ+mJ4=
|
||||||
|
github.com/puzpuzpuz/xsync/v3 v3.4.0/go.mod h1:VjzYrABPabuM4KyBh1Ftq6u8nhwY5tBPKP9jpmh0nnA=
|
||||||
|
github.com/redis/rueidis v1.0.44 h1:QfhfuovwEabcywfEXofRjPZuT29pjtpIWDJlCGHZfg8=
|
||||||
|
github.com/redis/rueidis v1.0.44/go.mod h1:bnbkk4+CkXZgDPEbUtSos/o55i4RhFYYesJ4DS2zmq0=
|
||||||
|
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||||
|
github.com/rivo/uniseg v0.4.2 h1:YwD0ulJSJytLpiaWua0sBDusfsCZohxjxzVTYjwxfV8=
|
||||||
|
github.com/rivo/uniseg v0.4.2/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
|
||||||
|
github.com/rjeczalik/notify v0.9.1 h1:CLCKso/QK1snAlnhNR/CNvNiFU2saUtjV0bx3EwNeCE=
|
||||||
|
github.com/rjeczalik/notify v0.9.1/go.mod h1:rKwnCoCGeuQnwBtTSPL9Dad03Vh2n40ePRrjvIXnJho=
|
||||||
|
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
|
||||||
|
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
|
||||||
|
github.com/rs/cors v1.7.0 h1:+88SsELBHx5r+hZ8TCkggzSstaWNbDvThkVK8H6f9ik=
|
||||||
|
github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU=
|
||||||
|
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible h1:Bn1aCHHRnjv4Bl16T8rcaFjYSrGrIZvpiGO6P3Q4GpU=
|
||||||
|
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
|
||||||
|
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
|
||||||
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
|
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||||
|
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||||
|
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
|
||||||
|
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||||
|
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 h1:epCh84lMvA70Z7CTTCmYQn2CKbY8j86K7/FAIr141uY=
|
||||||
|
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7/go.mod h1:q4W45IWZaF22tdD+VEXcAWRA037jwmWEB5VWYORlTpc=
|
||||||
|
github.com/tklauser/go-sysconf v0.3.12 h1:0QaGUFOdQaIVdPgfITYzaTegZvdCjmYO52cSFAEVmqU=
|
||||||
|
github.com/tklauser/go-sysconf v0.3.12/go.mod h1:Ho14jnntGE1fpdOqQEEaiKRpvIavV0hSfmBq8nJbHYI=
|
||||||
|
github.com/tklauser/numcpus v0.6.1 h1:ng9scYS7az0Bk4OZLvrNXNSAO2Pxr1XXRAPyjhIx+Fk=
|
||||||
|
github.com/tklauser/numcpus v0.6.1/go.mod h1:1XfjsgE2zo8GVw7POkMbHENHzVg3GzmoZ9fESEdAacY=
|
||||||
|
github.com/uptrace/bunrouter v1.0.21 h1:HXarvX+N834sXyHpl+I/TuE11m19kLW/qG5u3YpHUag=
|
||||||
|
github.com/uptrace/bunrouter v1.0.21/go.mod h1:TwT7Bc0ztF2Z2q/ZzMuSVkcb/Ig/d3MQeP2cxn3e1hI=
|
||||||
|
github.com/valyala/fastrand v1.1.0 h1:f+5HkLW4rsgzdNoleUOB69hyT9IlD2ZQh9GyDMfb5G8=
|
||||||
|
github.com/valyala/fastrand v1.1.0/go.mod h1:HWqCzkrkg6QXT8V2EXWvXCoow7vLwOFN002oeRzjapQ=
|
||||||
|
github.com/valyala/histogram v1.2.0 h1:wyYGAZZt3CpwUiIb9AU/Zbllg1llXyrtApRS815OLoQ=
|
||||||
|
github.com/valyala/histogram v1.2.0/go.mod h1:Hb4kBwb4UxsaNbbbh+RRz8ZR6pdodR57tzWUS3BUzXY=
|
||||||
|
go.etcd.io/bbolt v1.3.10 h1:+BqfJTcCzTItrop8mq/lbzL8wSGtj94UO/3U31shqG0=
|
||||||
|
go.etcd.io/bbolt v1.3.10/go.mod h1:bK3UQLPJZly7IlNmV7uVHJDxfe5aK9Ll93e/74Y9oEQ=
|
||||||
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
|
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||||
|
golang.org/x/crypto v0.25.0 h1:ypSNr+bnYL2YhwoMt2zPxHFmbAN1KZs/njMG3hxUp30=
|
||||||
|
golang.org/x/crypto v0.25.0/go.mod h1:T+wALwcMOSE0kXgUAnPAHqTLW+XHgcELELW8VaDgm/M=
|
||||||
|
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||||
|
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||||
|
golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
||||||
|
golang.org/x/net v0.0.0-20200813134508-3edf25e44fcc/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
|
||||||
|
golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w=
|
||||||
|
golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8=
|
||||||
|
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
|
||||||
|
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||||
|
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
|
golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
|
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
|
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20200519105757-fe76b779f299/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20200814200057-3d37ad5750ed/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||||
|
golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI=
|
||||||
|
golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||||
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
|
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||||
|
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
|
golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
|
||||||
|
golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
|
||||||
|
golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk=
|
||||||
|
golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
|
||||||
|
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
|
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg=
|
||||||
|
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=
|
||||||
|
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
|
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
|
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
|
||||||
|
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
|
||||||
|
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
|
||||||
|
google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
|
||||||
|
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
|
||||||
|
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
||||||
|
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
|
||||||
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
||||||
|
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
||||||
|
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
|
||||||
|
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce h1:+JknDZhAj8YMt7GC73Ei8pv4MzjDUNPHgQWJdtMAaDU=
|
||||||
|
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce/go.mod h1:5AcXVHNjg+BDxry382+8OKon8SEWiKktQR07RKPsv1c=
|
||||||
|
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
|
||||||
|
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
|
||||||
|
gopkg.in/urfave/cli.v1 v1.20.0 h1:NdAVW6RYxDif9DhDHaAortIu956m2c0v+09AZBPTbE0=
|
||||||
|
gopkg.in/urfave/cli.v1 v1.20.0/go.mod h1:vuBzUtMdQeixQj8LVd+/98pzhxNGQoyuPBlsXHOQNO0=
|
||||||
|
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
|
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
23
internal/api/api.go
Normal file
23
internal/api/api.go
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
package api
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/VictoriaMetrics/metrics"
|
||||||
|
"github.com/uptrace/bunrouter"
|
||||||
|
)
|
||||||
|
|
||||||
|
func New() *bunrouter.Router {
|
||||||
|
router := bunrouter.New()
|
||||||
|
|
||||||
|
router.GET("/metrics", metricsHandler())
|
||||||
|
|
||||||
|
return router
|
||||||
|
}
|
||||||
|
|
||||||
|
func metricsHandler() bunrouter.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, _ bunrouter.Request) error {
|
||||||
|
metrics.WritePrometheus(w, true)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
122
internal/backfill/backfill.go
Normal file
122
internal/backfill/backfill.go
Normal file
@ -0,0 +1,122 @@
|
|||||||
|
package backfill
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"log/slog"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/grassrootseconomics/celo-tracker/db"
|
||||||
|
"github.com/grassrootseconomics/celo-tracker/internal/pool"
|
||||||
|
)
|
||||||
|
|
||||||
|
type (
|
||||||
|
BackfillOpts struct {
|
||||||
|
DB db.DB
|
||||||
|
Logg *slog.Logger
|
||||||
|
Pool *pool.Pool
|
||||||
|
}
|
||||||
|
|
||||||
|
Backfill struct {
|
||||||
|
db db.DB
|
||||||
|
logg *slog.Logger
|
||||||
|
pool *pool.Pool
|
||||||
|
stopCh chan struct{}
|
||||||
|
ticker *time.Ticker
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
idleCheckInterval = 60 * time.Second
|
||||||
|
busyCheckInterval = 1 * time.Second
|
||||||
|
|
||||||
|
maxPoolSizePush = 100
|
||||||
|
)
|
||||||
|
|
||||||
|
func New(o BackfillOpts) *Backfill {
|
||||||
|
return &Backfill{
|
||||||
|
db: o.DB,
|
||||||
|
logg: o.Logg,
|
||||||
|
pool: o.Pool,
|
||||||
|
stopCh: make(chan struct{}),
|
||||||
|
ticker: time.NewTicker(idleCheckInterval),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *Backfill) Stop() {
|
||||||
|
b.ticker.Stop()
|
||||||
|
b.stopCh <- struct{}{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *Backfill) Start() {
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <-b.stopCh:
|
||||||
|
b.logg.Debug("backfill shutting down")
|
||||||
|
return
|
||||||
|
case <-b.ticker.C:
|
||||||
|
if b.pool.Size() <= 1 {
|
||||||
|
if err := b.Run(true); err != nil {
|
||||||
|
b.logg.Error("backfill run error", "err", err)
|
||||||
|
}
|
||||||
|
b.logg.Debug("backfill successful run", "queue_size", b.pool.Size())
|
||||||
|
} else {
|
||||||
|
b.logg.Debug("skipping backfill tick", "queue_size", b.pool.Size())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *Backfill) Run(skipLatest bool) error {
|
||||||
|
lower, err := b.db.GetLowerBound()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("verifier could not get lower bound from db: err %v", err)
|
||||||
|
}
|
||||||
|
upper, err := b.db.GetUpperBound()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("verifier could not get upper bound from db: err %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if skipLatest {
|
||||||
|
upper--
|
||||||
|
}
|
||||||
|
|
||||||
|
missingBlocks, err := b.db.GetMissingValuesBitSet(lower, upper)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("verifier could not get missing values bitset: err %v", err)
|
||||||
|
}
|
||||||
|
missingBlocksCount := missingBlocks.Count()
|
||||||
|
|
||||||
|
if missingBlocksCount > 0 {
|
||||||
|
b.logg.Info("found missing blocks", "skip_latest", skipLatest, "missing_blocks_count", missingBlocksCount)
|
||||||
|
|
||||||
|
buffer := make([]uint, maxPoolSizePush)
|
||||||
|
j := uint(0)
|
||||||
|
pushedCount := 0
|
||||||
|
j, buffer = missingBlocks.NextSetMany(j, buffer)
|
||||||
|
for ; len(buffer) > 0; j, buffer = missingBlocks.NextSetMany(j, buffer) {
|
||||||
|
for k := range buffer {
|
||||||
|
if pushedCount >= maxPoolSizePush {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
b.pool.Push(uint64(buffer[k]))
|
||||||
|
b.logg.Debug("pushed block from backfill", "block", buffer[k])
|
||||||
|
pushedCount++
|
||||||
|
}
|
||||||
|
j += 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if missingBlocksCount > maxPoolSizePush {
|
||||||
|
b.ticker.Reset(busyCheckInterval)
|
||||||
|
} else {
|
||||||
|
b.ticker.Reset(idleCheckInterval)
|
||||||
|
}
|
||||||
|
|
||||||
|
missingBlocks.ClearAll()
|
||||||
|
missingBlocks = nil
|
||||||
|
b.logg.Info("backfill tick run complete")
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
62
internal/cache/cache.go
vendored
Normal file
62
internal/cache/cache.go
vendored
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
package cache
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"log/slog"
|
||||||
|
)
|
||||||
|
|
||||||
|
type (
|
||||||
|
Cache interface {
|
||||||
|
Add(context.Context, string) error
|
||||||
|
Remove(context.Context, string) error
|
||||||
|
Exists(context.Context, string) (bool, error)
|
||||||
|
Size(context.Context) (int64, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
CacheOpts struct {
|
||||||
|
Logg *slog.Logger
|
||||||
|
RedisDSN string
|
||||||
|
CacheType string
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
func New(o CacheOpts) (Cache, error) {
|
||||||
|
var cache Cache
|
||||||
|
|
||||||
|
switch o.CacheType {
|
||||||
|
case "map":
|
||||||
|
cache = NewMapCache()
|
||||||
|
case "redis":
|
||||||
|
redisCache, err := NewRedisCache(redisOpts{
|
||||||
|
DSN: o.RedisDSN,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
cache = redisCache
|
||||||
|
default:
|
||||||
|
cache = NewMapCache()
|
||||||
|
o.Logg.Warn("invalid cache type, using default type (map)")
|
||||||
|
}
|
||||||
|
|
||||||
|
// geSmartContracts, err := o.Chain.Provider().GetGESmartContracts(
|
||||||
|
// context.Background(),
|
||||||
|
// o.Registries,
|
||||||
|
// )
|
||||||
|
// if err != nil {
|
||||||
|
// return nil, fmt.Errorf("cache could not bootstrap GE smart contracts: err %v", err)
|
||||||
|
// }
|
||||||
|
|
||||||
|
// for k, v := range geSmartContracts {
|
||||||
|
// cache.Add(k, v)
|
||||||
|
// }
|
||||||
|
// for _, address := range o.Watchlist {
|
||||||
|
// cache.Add(address, false)
|
||||||
|
// }
|
||||||
|
// for _, address := range o.Blacklist {
|
||||||
|
// cache.Remove(address)
|
||||||
|
// }
|
||||||
|
// o.Logg.Info("cache bootstrap complete", "cached_addresses", cache.Size())
|
||||||
|
|
||||||
|
return cache, nil
|
||||||
|
}
|
56
internal/cache/redis.go
vendored
Normal file
56
internal/cache/redis.go
vendored
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
package cache
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/redis/rueidis"
|
||||||
|
)
|
||||||
|
|
||||||
|
type (
|
||||||
|
redisOpts struct {
|
||||||
|
DSN string
|
||||||
|
}
|
||||||
|
|
||||||
|
redisCache struct {
|
||||||
|
client rueidis.Client
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
func NewRedisCache(o redisOpts) (Cache, error) {
|
||||||
|
client, err := rueidis.NewClient(rueidis.ClientOption{
|
||||||
|
InitAddress: []string{o.DSN},
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &redisCache{
|
||||||
|
client: client,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *redisCache) Add(ctx context.Context, key string) error {
|
||||||
|
// Without NX it will overwrite any existing KEY
|
||||||
|
cmd := c.client.B().Set().Key(key).Value("true").Build()
|
||||||
|
return c.client.Do(ctx, cmd).Error()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *redisCache) Remove(ctx context.Context, key string) error {
|
||||||
|
cmd := c.client.B().Del().Key(key).Build()
|
||||||
|
return c.client.Do(ctx, cmd).Error()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *redisCache) Exists(ctx context.Context, key string) (bool, error) {
|
||||||
|
cmd := c.client.B().Exists().Key(key).Build()
|
||||||
|
res, err := c.client.Do(ctx, cmd).AsBool()
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *redisCache) Size(ctx context.Context) (int64, error) {
|
||||||
|
cmd := c.client.B().Dbsize().Build()
|
||||||
|
return c.client.Do(ctx, cmd).AsInt64()
|
||||||
|
}
|
36
internal/cache/xmap.go
vendored
Normal file
36
internal/cache/xmap.go
vendored
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
package cache
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/puzpuzpuz/xsync/v3"
|
||||||
|
)
|
||||||
|
|
||||||
|
type mapCache struct {
|
||||||
|
xmap *xsync.Map
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewMapCache() Cache {
|
||||||
|
return &mapCache{
|
||||||
|
xmap: xsync.NewMap(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *mapCache) Add(_ context.Context, key string) error {
|
||||||
|
c.xmap.Store(key, true)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *mapCache) Remove(_ context.Context, key string) error {
|
||||||
|
c.xmap.Delete(key)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *mapCache) Exists(_ context.Context, key string) (bool, error) {
|
||||||
|
_, ok := c.xmap.Load(key)
|
||||||
|
return ok, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *mapCache) Size(_ context.Context) (int64, error) {
|
||||||
|
return int64(c.xmap.Size()), nil
|
||||||
|
}
|
121
internal/chain/celo_rpc.go
Normal file
121
internal/chain/celo_rpc.go
Normal file
@ -0,0 +1,121 @@
|
|||||||
|
package chain
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"math/big"
|
||||||
|
"net/http"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/celo-org/celo-blockchain/common"
|
||||||
|
"github.com/celo-org/celo-blockchain/core/types"
|
||||||
|
"github.com/celo-org/celo-blockchain/rpc"
|
||||||
|
"github.com/grassrootseconomics/celoutils/v3"
|
||||||
|
"github.com/grassrootseconomics/w3-celo"
|
||||||
|
"github.com/grassrootseconomics/w3-celo/module/eth"
|
||||||
|
"github.com/grassrootseconomics/w3-celo/w3types"
|
||||||
|
)
|
||||||
|
|
||||||
|
type (
|
||||||
|
CeloRPCOpts struct {
|
||||||
|
RPCEndpoint string
|
||||||
|
ChainID int64
|
||||||
|
}
|
||||||
|
|
||||||
|
CeloRPC struct {
|
||||||
|
provider *celoutils.Provider
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
func NewRPCFetcher(o CeloRPCOpts) (Chain, error) {
|
||||||
|
customRPCClient, err := lowTimeoutRPCClient(o.RPCEndpoint)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
chainProvider := celoutils.NewProvider(
|
||||||
|
o.RPCEndpoint,
|
||||||
|
o.ChainID,
|
||||||
|
celoutils.WithClient(customRPCClient),
|
||||||
|
)
|
||||||
|
|
||||||
|
return &CeloRPC{
|
||||||
|
provider: chainProvider,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func lowTimeoutRPCClient(rpcEndpoint string) (*w3.Client, error) {
|
||||||
|
httpClient := &http.Client{
|
||||||
|
Timeout: 10 * time.Second,
|
||||||
|
}
|
||||||
|
|
||||||
|
rpcClient, err := rpc.DialHTTPWithClient(
|
||||||
|
rpcEndpoint,
|
||||||
|
httpClient,
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return w3.NewClient(rpcClient), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *CeloRPC) GetBlocks(ctx context.Context, blockNumbers []uint64) ([]types.Block, error) {
|
||||||
|
blocksCount := len(blockNumbers)
|
||||||
|
calls := make([]w3types.RPCCaller, blocksCount)
|
||||||
|
blocks := make([]types.Block, blocksCount)
|
||||||
|
|
||||||
|
for i, v := range blockNumbers {
|
||||||
|
calls[i] = eth.BlockByNumber(new(big.Int).SetUint64(v)).Returns(&blocks[i])
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := c.provider.Client.CallCtx(ctx, calls...); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return blocks, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *CeloRPC) GetBlock(ctx context.Context, blockNumber uint64) (*types.Block, error) {
|
||||||
|
var block types.Block
|
||||||
|
blockCall := eth.BlockByNumber(new(big.Int).SetUint64(blockNumber)).Returns(&block)
|
||||||
|
|
||||||
|
if err := c.provider.Client.CallCtx(ctx, blockCall); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &block, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *CeloRPC) GetLatestBlock(ctx context.Context) (uint64, error) {
|
||||||
|
var latestBlock big.Int
|
||||||
|
latestBlockCall := eth.BlockNumber().Returns(&latestBlock)
|
||||||
|
|
||||||
|
if err := c.provider.Client.CallCtx(ctx, latestBlockCall); err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return latestBlock.Uint64(), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *CeloRPC) GetTransaction(ctx context.Context, txHash common.Hash) (*types.Transaction, error) {
|
||||||
|
var transaction types.Transaction
|
||||||
|
if err := c.provider.Client.CallCtx(ctx, eth.Tx(txHash).Returns(&transaction)); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &transaction, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *CeloRPC) GetReceipts(ctx context.Context, blockNumber *big.Int) (types.Receipts, error) {
|
||||||
|
var receipts types.Receipts
|
||||||
|
|
||||||
|
if err := c.provider.Client.CallCtx(ctx, eth.BlockReceipts(blockNumber).Returns(&receipts)); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return receipts, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *CeloRPC) Provider() *celoutils.Provider {
|
||||||
|
return c.provider
|
||||||
|
}
|
98
internal/chain/celo_rpc_e2e_test.go
Normal file
98
internal/chain/celo_rpc_e2e_test.go
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
package chain
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
testRPCEndpoint = "https://celo.archive.grassecon.net"
|
||||||
|
testChainID = 42220
|
||||||
|
)
|
||||||
|
|
||||||
|
func setupCeloRPC() (Chain, error) {
|
||||||
|
opts := CeloRPCOpts{
|
||||||
|
RPCEndpoint: testRPCEndpoint,
|
||||||
|
ChainID: testChainID,
|
||||||
|
}
|
||||||
|
return NewRPCFetcher(opts)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRPC_GetBlocks(t *testing.T) {
|
||||||
|
rpcFetcher, err := setupCeloRPC()
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
blockNumbers := []uint64{
|
||||||
|
19_600_000,
|
||||||
|
23_000_000,
|
||||||
|
27_000_000,
|
||||||
|
}
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
blocks, err := rpcFetcher.GetBlocks(ctx, blockNumbers)
|
||||||
|
require.NoError(t, err)
|
||||||
|
t.Logf("blocks %+v\n", blocks)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRPC_GetBlock(t *testing.T) {
|
||||||
|
rpcFetcher, err := setupCeloRPC()
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
var blockNumber uint64 = 19_900_000
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
block, err := rpcFetcher.GetBlock(ctx, blockNumber)
|
||||||
|
require.NoError(t, err)
|
||||||
|
t.Logf("block %+v\n", block)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRPC_GetLatestBlock(t *testing.T) {
|
||||||
|
rpcFetcher, err := setupCeloRPC()
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
block, err := rpcFetcher.GetLatestBlock(ctx)
|
||||||
|
require.NoError(t, err)
|
||||||
|
t.Logf("block %+v\n", block)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRPC_GetTransaction(t *testing.T) {
|
||||||
|
rpcFetcher, err := setupCeloRPC()
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
var blockNumber uint64 = 19_900_000
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
block, err := rpcFetcher.GetBlock(ctx, blockNumber)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.NotNil(t, block)
|
||||||
|
|
||||||
|
transaction, err := rpcFetcher.GetTransaction(ctx, block.Transactions()[0].Hash())
|
||||||
|
require.NoError(t, err)
|
||||||
|
t.Logf("transaction %+v\n", transaction)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRPC_GetReceipts(t *testing.T) {
|
||||||
|
rpcFetcher, err := setupCeloRPC()
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
var blockNumber uint64 = 19_900_000
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
block, err := rpcFetcher.GetBlock(ctx, blockNumber)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.NotNil(t, block)
|
||||||
|
|
||||||
|
receipts, err := rpcFetcher.GetReceipts(ctx, block.Number())
|
||||||
|
require.NoError(t, err)
|
||||||
|
t.Logf("receipts %+v\n", receipts)
|
||||||
|
}
|
20
internal/chain/chain.go
Normal file
20
internal/chain/chain.go
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
package chain
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"math/big"
|
||||||
|
|
||||||
|
"github.com/celo-org/celo-blockchain/common"
|
||||||
|
"github.com/celo-org/celo-blockchain/core/types"
|
||||||
|
"github.com/grassrootseconomics/celoutils/v3"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Chain interface {
|
||||||
|
GetBlocks(context.Context, []uint64) ([]types.Block, error)
|
||||||
|
GetBlock(context.Context, uint64) (*types.Block, error)
|
||||||
|
GetLatestBlock(context.Context) (uint64, error)
|
||||||
|
GetTransaction(context.Context, common.Hash) (*types.Transaction, error)
|
||||||
|
GetReceipts(context.Context, *big.Int) (types.Receipts, error)
|
||||||
|
// Expose provider until we eject from celoutils
|
||||||
|
Provider() *celoutils.Provider
|
||||||
|
}
|
3
internal/chain/eth_rpc.go
Normal file
3
internal/chain/eth_rpc.go
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
package chain
|
||||||
|
|
||||||
|
// TBA
|
66
internal/pool/pool.go
Normal file
66
internal/pool/pool.go
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
package pool
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"log/slog"
|
||||||
|
"runtime/debug"
|
||||||
|
|
||||||
|
"github.com/alitto/pond"
|
||||||
|
"github.com/grassrootseconomics/celo-tracker/internal/processor"
|
||||||
|
)
|
||||||
|
|
||||||
|
type (
|
||||||
|
PoolOpts struct {
|
||||||
|
Logg *slog.Logger
|
||||||
|
WorkerCount int
|
||||||
|
Processor *processor.Processor
|
||||||
|
}
|
||||||
|
|
||||||
|
Pool struct {
|
||||||
|
logg *slog.Logger
|
||||||
|
workerPool *pond.WorkerPool
|
||||||
|
processor *processor.Processor
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
const blocksBuffer = 100
|
||||||
|
|
||||||
|
func New(o PoolOpts) *Pool {
|
||||||
|
return &Pool{
|
||||||
|
logg: o.Logg,
|
||||||
|
workerPool: pond.New(
|
||||||
|
o.WorkerCount,
|
||||||
|
blocksBuffer,
|
||||||
|
pond.Strategy(pond.Balanced()),
|
||||||
|
pond.PanicHandler(panicHandler(o.Logg)),
|
||||||
|
),
|
||||||
|
processor: o.Processor,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Pool) Stop() {
|
||||||
|
p.workerPool.StopAndWait()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Pool) Push(block uint64) {
|
||||||
|
p.workerPool.Submit(func() {
|
||||||
|
err := p.processor.ProcessBlock(context.Background(), block)
|
||||||
|
if err != nil {
|
||||||
|
p.logg.Error("block processor error", "block_number", block, "error", err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Pool) Size() uint64 {
|
||||||
|
return p.workerPool.WaitingTasks()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Pool) ActiveWorkers() int {
|
||||||
|
return p.workerPool.RunningWorkers()
|
||||||
|
}
|
||||||
|
|
||||||
|
func panicHandler(logg *slog.Logger) func(interface{}) {
|
||||||
|
return func(panic interface{}) {
|
||||||
|
logg.Error("block processor goroutine exited from a panic", "error", panic, "stack_trace", string(debug.Stack()))
|
||||||
|
}
|
||||||
|
}
|
116
internal/processor/processor.go
Normal file
116
internal/processor/processor.go
Normal file
@ -0,0 +1,116 @@
|
|||||||
|
package processor
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"log/slog"
|
||||||
|
|
||||||
|
"github.com/celo-org/celo-blockchain/common"
|
||||||
|
"github.com/celo-org/celo-blockchain/core/types"
|
||||||
|
"github.com/grassrootseconomics/celo-tracker/db"
|
||||||
|
"github.com/grassrootseconomics/celo-tracker/internal/cache"
|
||||||
|
"github.com/grassrootseconomics/celo-tracker/internal/chain"
|
||||||
|
"github.com/grassrootseconomics/celo-tracker/internal/router"
|
||||||
|
)
|
||||||
|
|
||||||
|
type (
|
||||||
|
ProcessorOpts struct {
|
||||||
|
Cache cache.Cache
|
||||||
|
Chain chain.Chain
|
||||||
|
DB db.DB
|
||||||
|
Router *router.Router
|
||||||
|
Logg *slog.Logger
|
||||||
|
}
|
||||||
|
|
||||||
|
Processor struct {
|
||||||
|
cache cache.Cache
|
||||||
|
chain chain.Chain
|
||||||
|
db db.DB
|
||||||
|
router *router.Router
|
||||||
|
logg *slog.Logger
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
func NewProcessor(o ProcessorOpts) *Processor {
|
||||||
|
return &Processor{
|
||||||
|
cache: o.Cache,
|
||||||
|
chain: o.Chain,
|
||||||
|
db: o.DB,
|
||||||
|
router: o.Router,
|
||||||
|
logg: o.Logg,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Processor) ProcessBlock(ctx context.Context, blockNumber uint64) error {
|
||||||
|
block, err := p.chain.GetBlock(ctx, blockNumber)
|
||||||
|
if err != nil && !errors.Is(err, context.Canceled) {
|
||||||
|
return fmt.Errorf("block %d error: %v", blockNumber, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
receipts, err := p.chain.GetReceipts(ctx, block.Number())
|
||||||
|
if err != nil && !errors.Is(err, context.Canceled) {
|
||||||
|
return fmt.Errorf("receipts fetch error: block %d: %v", blockNumber, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, receipt := range receipts {
|
||||||
|
if receipt.Status > 0 {
|
||||||
|
for _, log := range receipt.Logs {
|
||||||
|
exists, err := p.cache.Exists(ctx, log.Address.Hex())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if exists {
|
||||||
|
if err := p.router.RouteSuccessTx(
|
||||||
|
ctx,
|
||||||
|
router.SuccessTx{
|
||||||
|
Log: log,
|
||||||
|
Timestamp: block.Time(),
|
||||||
|
},
|
||||||
|
); err != nil && !errors.Is(err, context.Canceled) {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
tx, err := p.chain.GetTransaction(ctx, receipt.TxHash)
|
||||||
|
if err != nil && !errors.Is(err, context.Canceled) {
|
||||||
|
return fmt.Errorf("get transaction error: tx %s: %v", receipt.TxHash.Hex(), err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if tx.To() != nil {
|
||||||
|
exists, err := p.cache.Exists(ctx, tx.To().Hex())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if exists {
|
||||||
|
from, err := types.Sender(types.LatestSignerForChainID(tx.ChainId()), tx)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("transaction decode error: tx %s: %v", receipt.TxHash.Hex(), err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := p.router.RouteRevertTx(
|
||||||
|
ctx,
|
||||||
|
router.RevertTx{
|
||||||
|
From: from.Hex(),
|
||||||
|
InputData: common.Bytes2Hex(tx.Data()),
|
||||||
|
Block: blockNumber,
|
||||||
|
ContractAddress: tx.To().Hex(),
|
||||||
|
Timestamp: block.Time(),
|
||||||
|
TxHash: receipt.TxHash.Hex(),
|
||||||
|
},
|
||||||
|
); err != nil && !errors.Is(err, context.Canceled) {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := p.db.SetValue(blockNumber); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
p.logg.Debug("successfully processed block", "block", blockNumber)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
92
internal/pub/jetstream.go
Normal file
92
internal/pub/jetstream.go
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
package pub
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"log/slog"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/grassrootseconomics/celo-tracker/pkg/event"
|
||||||
|
"github.com/nats-io/nats.go"
|
||||||
|
)
|
||||||
|
|
||||||
|
type (
|
||||||
|
JetStreamOpts struct {
|
||||||
|
Logg *slog.Logger
|
||||||
|
Endpoint string
|
||||||
|
DedupDuration time.Duration
|
||||||
|
PersistDuration time.Duration
|
||||||
|
}
|
||||||
|
|
||||||
|
jetStreamPub struct {
|
||||||
|
natsConn *nats.Conn
|
||||||
|
jsCtx nats.JetStreamContext
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
const streamName string = "TRACKER"
|
||||||
|
|
||||||
|
var streamSubjects = []string{
|
||||||
|
"TRACKER.*",
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewJetStreamPub(o JetStreamOpts) (Pub, error) {
|
||||||
|
natsConn, err := nats.Connect(o.Endpoint)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
js, err := natsConn.JetStream()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
o.Logg.Info("successfully connected to NATS server")
|
||||||
|
|
||||||
|
stream, err := js.StreamInfo(streamName)
|
||||||
|
if err != nil && !errors.Is(err, nats.ErrStreamNotFound) {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if stream == nil {
|
||||||
|
_, err := js.AddStream(&nats.StreamConfig{
|
||||||
|
Name: streamName,
|
||||||
|
MaxAge: o.PersistDuration,
|
||||||
|
Storage: nats.FileStorage,
|
||||||
|
Subjects: streamSubjects,
|
||||||
|
Duplicates: o.DedupDuration,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
o.Logg.Info("successfully created NATS JetStream stream", "stream_name", streamName)
|
||||||
|
}
|
||||||
|
|
||||||
|
return &jetStreamPub{
|
||||||
|
natsConn: natsConn,
|
||||||
|
jsCtx: js,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *jetStreamPub) Close() {
|
||||||
|
if p.natsConn != nil {
|
||||||
|
p.natsConn.Close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *jetStreamPub) Send(_ context.Context, payload event.Event) error {
|
||||||
|
data, err := payload.Serialize()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = p.jsCtx.Publish(
|
||||||
|
fmt.Sprintf("%s.%s", streamName, payload.TxType),
|
||||||
|
data,
|
||||||
|
nats.MsgId(fmt.Sprintf("%s:%d", payload.TxHash, payload.Index)),
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
12
internal/pub/pub.go
Normal file
12
internal/pub/pub.go
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
package pub
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/grassrootseconomics/celo-tracker/pkg/event"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Pub interface {
|
||||||
|
Send(context.Context, event.Event) error
|
||||||
|
Close()
|
||||||
|
}
|
73
internal/queue/queue.go
Normal file
73
internal/queue/queue.go
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
package queue
|
||||||
|
|
||||||
|
//
|
||||||
|
// import (
|
||||||
|
// "context"
|
||||||
|
// "log/slog"
|
||||||
|
|
||||||
|
// "github.com/alitto/pond"
|
||||||
|
// "github.com/grassrootseconomics/celo-tracker/internal/processor"
|
||||||
|
// )
|
||||||
|
|
||||||
|
// type (
|
||||||
|
// QueueOpts struct {
|
||||||
|
// QueueSize int
|
||||||
|
// Logg *slog.Logger
|
||||||
|
// Processor *processor.Processor
|
||||||
|
// Pool *pond.WorkerPool
|
||||||
|
// }
|
||||||
|
|
||||||
|
// Queue struct {
|
||||||
|
// logg *slog.Logger
|
||||||
|
// processChan chan uint64
|
||||||
|
// stopSignal chan interface{}
|
||||||
|
// processor *processor.Processor
|
||||||
|
// pool *pond.WorkerPool
|
||||||
|
// }
|
||||||
|
// )
|
||||||
|
|
||||||
|
// func New(o QueueOpts) *Queue {
|
||||||
|
// return &Queue{
|
||||||
|
// logg: o.Logg,
|
||||||
|
// processChan: make(chan uint64, o.QueueSize),
|
||||||
|
// stopSignal: make(chan interface{}),
|
||||||
|
// processor: o.Processor,
|
||||||
|
// pool: o.Pool,
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// func (q *Queue) Stop() {
|
||||||
|
// q.stopSignal <- struct{}{}
|
||||||
|
// }
|
||||||
|
|
||||||
|
// func (q *Queue) Process() {
|
||||||
|
// for {
|
||||||
|
// select {
|
||||||
|
// case <-q.stopSignal:
|
||||||
|
// q.logg.Info("shutdown signal received stopping queue processing")
|
||||||
|
// return
|
||||||
|
// case block, ok := <-q.processChan:
|
||||||
|
// if !ok {
|
||||||
|
// return
|
||||||
|
// }
|
||||||
|
// q.pool.Submit(func() {
|
||||||
|
// err := q.processor.ProcessBlock(context.Background(), block)
|
||||||
|
// if err != nil {
|
||||||
|
// q.logg.Error("block processor error", "block_number", block, "error", err)
|
||||||
|
// }
|
||||||
|
// })
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// func (q *Queue) Push(block uint64) {
|
||||||
|
// q.processChan <- block
|
||||||
|
// }
|
||||||
|
|
||||||
|
// func (q *Queue) Size() int {
|
||||||
|
// return len(q.processChan)
|
||||||
|
// }
|
||||||
|
|
||||||
|
// func (q *Queue) WaitingSize() uint64 {
|
||||||
|
// return q.pool.WaitingTasks()
|
||||||
|
// }
|
94
internal/router/faucet_give.go
Normal file
94
internal/router/faucet_give.go
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
package router
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"math/big"
|
||||||
|
|
||||||
|
"github.com/celo-org/celo-blockchain/common"
|
||||||
|
"github.com/grassrootseconomics/celo-tracker/pkg/event"
|
||||||
|
"github.com/grassrootseconomics/celoutils/v3"
|
||||||
|
"github.com/grassrootseconomics/w3-celo"
|
||||||
|
)
|
||||||
|
|
||||||
|
type faucetGiveHandler struct{}
|
||||||
|
|
||||||
|
const faucetGiveEventName = "FAUCET_GIVE"
|
||||||
|
|
||||||
|
var (
|
||||||
|
_ Handler = (*faucetGiveHandler)(nil)
|
||||||
|
|
||||||
|
faucetGiveEvent = w3.MustNewEvent("Give(address indexed _recipient, address indexed _token, uint256 _amount)")
|
||||||
|
faucetGiveToSig = w3.MustNewFunc("giveTo(address)", "uint256")
|
||||||
|
faucetGimmeSig = w3.MustNewFunc("gimme()", "uint256")
|
||||||
|
)
|
||||||
|
|
||||||
|
func (h *faucetGiveHandler) Name() string {
|
||||||
|
return faucetGiveEventName
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *faucetGiveHandler) SuccessTx(ctx context.Context, tx SuccessTx, pubCB PubCallback) error {
|
||||||
|
var (
|
||||||
|
recipient common.Address
|
||||||
|
token common.Address
|
||||||
|
amount big.Int
|
||||||
|
)
|
||||||
|
|
||||||
|
if err := faucetGiveEvent.DecodeArgs(tx.Log, &recipient, &token, &amount); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
faucetGiveEvent := event.Event{
|
||||||
|
Index: tx.Log.Index,
|
||||||
|
Block: tx.Log.BlockNumber,
|
||||||
|
ContractAddress: tx.Log.Address.Hex(),
|
||||||
|
Success: true,
|
||||||
|
Timestamp: tx.Timestamp,
|
||||||
|
TxHash: tx.Log.TxHash.Hex(),
|
||||||
|
TxType: faucetGiveEventName,
|
||||||
|
Payload: map[string]any{
|
||||||
|
"recipient": recipient.Hex(),
|
||||||
|
"token": token.Hex(),
|
||||||
|
"amount": amount.String(),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
return pubCB(ctx, faucetGiveEvent)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *faucetGiveHandler) RevertTx(ctx context.Context, tx RevertTx, pubCB PubCallback) error {
|
||||||
|
faucetGiveEvent := event.Event{
|
||||||
|
Block: tx.Block,
|
||||||
|
ContractAddress: tx.ContractAddress,
|
||||||
|
Success: false,
|
||||||
|
Timestamp: tx.Timestamp,
|
||||||
|
TxHash: tx.TxHash,
|
||||||
|
TxType: faucetGiveEventName,
|
||||||
|
}
|
||||||
|
|
||||||
|
switch tx.InputData[:8] {
|
||||||
|
case "63e4bff4":
|
||||||
|
var to common.Address
|
||||||
|
|
||||||
|
if err := faucetGiveToSig.DecodeArgs(w3.B(tx.InputData), &to); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
faucetGiveEvent.Payload = map[string]any{
|
||||||
|
"recipient": to.Hex(),
|
||||||
|
"token": celoutils.ZeroAddress,
|
||||||
|
"amount": "0",
|
||||||
|
}
|
||||||
|
|
||||||
|
return pubCB(ctx, faucetGiveEvent)
|
||||||
|
case "de82efb4":
|
||||||
|
faucetGiveEvent.Payload = map[string]any{
|
||||||
|
"recipient": celoutils.ZeroAddress,
|
||||||
|
"token": celoutils.ZeroAddress,
|
||||||
|
"amount": "0",
|
||||||
|
}
|
||||||
|
|
||||||
|
return pubCB(ctx, faucetGiveEvent)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
95
internal/router/index_add.go
Normal file
95
internal/router/index_add.go
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
package router
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/celo-org/celo-blockchain/common"
|
||||||
|
"github.com/grassrootseconomics/celo-tracker/internal/cache"
|
||||||
|
"github.com/grassrootseconomics/celo-tracker/pkg/event"
|
||||||
|
"github.com/grassrootseconomics/w3-celo"
|
||||||
|
)
|
||||||
|
|
||||||
|
type indexAddHandler struct {
|
||||||
|
cache cache.Cache
|
||||||
|
}
|
||||||
|
|
||||||
|
const indexAddEventName = "INDEX_ADD"
|
||||||
|
|
||||||
|
var (
|
||||||
|
_ Handler = (*indexAddHandler)(nil)
|
||||||
|
|
||||||
|
indexAddEvent = w3.MustNewEvent("AddressAdded(address _token)")
|
||||||
|
indexAddSig = w3.MustNewFunc("add(address)", "bool")
|
||||||
|
indexRegisterSig = w3.MustNewFunc("register(address)", "bool")
|
||||||
|
)
|
||||||
|
|
||||||
|
func (h *indexAddHandler) Name() string {
|
||||||
|
return indexAddEventName
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *indexAddHandler) SuccessTx(ctx context.Context, tx SuccessTx, pubCB PubCallback) error {
|
||||||
|
var address common.Address
|
||||||
|
|
||||||
|
if err := indexAddEvent.DecodeArgs(tx.Log, &address); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
indexAddEvent := event.Event{
|
||||||
|
Index: tx.Log.Index,
|
||||||
|
Block: tx.Log.BlockNumber,
|
||||||
|
ContractAddress: tx.Log.Address.Hex(),
|
||||||
|
Success: true,
|
||||||
|
Timestamp: tx.Timestamp,
|
||||||
|
TxHash: tx.Log.TxHash.Hex(),
|
||||||
|
TxType: indexAddEventName,
|
||||||
|
Payload: map[string]any{
|
||||||
|
"address": address.Hex(),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := h.cache.Add(ctx, address.Hex()); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return pubCB(ctx, indexAddEvent)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *indexAddHandler) RevertTx(ctx context.Context, tx RevertTx, pubCB PubCallback) error {
|
||||||
|
indexAddEvent := event.Event{
|
||||||
|
Block: tx.Block,
|
||||||
|
ContractAddress: tx.ContractAddress,
|
||||||
|
Success: false,
|
||||||
|
Timestamp: tx.Timestamp,
|
||||||
|
TxHash: tx.TxHash,
|
||||||
|
TxType: indexAddEventName,
|
||||||
|
}
|
||||||
|
|
||||||
|
switch tx.InputData[:8] {
|
||||||
|
case "0a3b0a4f":
|
||||||
|
var address common.Address
|
||||||
|
|
||||||
|
indexAddEvent.Payload = map[string]any{
|
||||||
|
"address": address.Hex(),
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := indexAddSig.DecodeArgs(w3.B(tx.InputData), &address); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return pubCB(ctx, indexAddEvent)
|
||||||
|
case "4420e486":
|
||||||
|
var address common.Address
|
||||||
|
|
||||||
|
indexAddEvent.Payload = map[string]any{
|
||||||
|
"address": address.Hex(),
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := indexRegisterSig.DecodeArgs(w3.B(tx.InputData), &address); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return pubCB(ctx, indexAddEvent)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
77
internal/router/index_remove.go
Normal file
77
internal/router/index_remove.go
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
package router
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/celo-org/celo-blockchain/common"
|
||||||
|
"github.com/grassrootseconomics/celo-tracker/internal/cache"
|
||||||
|
"github.com/grassrootseconomics/celo-tracker/pkg/event"
|
||||||
|
"github.com/grassrootseconomics/w3-celo"
|
||||||
|
)
|
||||||
|
|
||||||
|
type indexRemoveHandler struct {
|
||||||
|
cache cache.Cache
|
||||||
|
}
|
||||||
|
|
||||||
|
const indexRemoveEventName = "INDEX_REMOVE"
|
||||||
|
|
||||||
|
var (
|
||||||
|
_ Handler = (*indexRemoveHandler)(nil)
|
||||||
|
|
||||||
|
indexRemoveEvent = w3.MustNewEvent("AddressRemoved(address _token)")
|
||||||
|
indexRemoveSig = w3.MustNewFunc("remove(address)", "bool")
|
||||||
|
)
|
||||||
|
|
||||||
|
func (h *indexRemoveHandler) Name() string {
|
||||||
|
return indexRemoveEventName
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *indexRemoveHandler) SuccessTx(ctx context.Context, tx SuccessTx, pubCB PubCallback) error {
|
||||||
|
var address common.Address
|
||||||
|
|
||||||
|
if err := indexRemoveEvent.DecodeArgs(tx.Log, &address); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
indexRemoveEvent := event.Event{
|
||||||
|
Index: tx.Log.Index,
|
||||||
|
Block: tx.Log.BlockNumber,
|
||||||
|
ContractAddress: tx.Log.Address.Hex(),
|
||||||
|
Success: true,
|
||||||
|
Timestamp: tx.Timestamp,
|
||||||
|
TxHash: tx.Log.TxHash.Hex(),
|
||||||
|
TxType: indexRemoveEventName,
|
||||||
|
Payload: map[string]any{
|
||||||
|
"address": address.Hex(),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := h.cache.Remove(ctx, address.Hex()); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return pubCB(ctx, indexRemoveEvent)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *indexRemoveHandler) RevertTx(ctx context.Context, tx RevertTx, pubCB PubCallback) error {
|
||||||
|
var address common.Address
|
||||||
|
|
||||||
|
if err := indexRemoveSig.DecodeArgs(w3.B(tx.InputData), &address); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
indexRemoveEvent := event.Event{
|
||||||
|
Block: tx.Block,
|
||||||
|
ContractAddress: tx.ContractAddress,
|
||||||
|
Success: false,
|
||||||
|
Timestamp: tx.Timestamp,
|
||||||
|
TxHash: tx.TxHash,
|
||||||
|
TxType: indexRemoveEventName,
|
||||||
|
Payload: map[string]any{
|
||||||
|
"address": address.Hex(),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
return pubCB(ctx, indexRemoveEvent)
|
||||||
|
}
|
77
internal/router/ownership.go
Normal file
77
internal/router/ownership.go
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
package router
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/celo-org/celo-blockchain/common"
|
||||||
|
"github.com/grassrootseconomics/celo-tracker/pkg/event"
|
||||||
|
"github.com/grassrootseconomics/w3-celo"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ownershipHandler struct{}
|
||||||
|
|
||||||
|
const (
|
||||||
|
ownershipEventName = "OWNERSHIP_TRANSFERRED"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
_ Handler = (*ownershipHandler)(nil)
|
||||||
|
|
||||||
|
ownershipEvent = w3.MustNewEvent("OwnershipTransferred(address indexed previousOwner, address indexed newOwner)")
|
||||||
|
ownershipToSig = w3.MustNewFunc("transferOwnership(address)", "bool")
|
||||||
|
)
|
||||||
|
|
||||||
|
func (h *ownershipHandler) Name() string {
|
||||||
|
return ownershipEventName
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *ownershipHandler) SuccessTx(ctx context.Context, tx SuccessTx, pubCB PubCallback) error {
|
||||||
|
var (
|
||||||
|
previousOwner common.Address
|
||||||
|
newOwner common.Address
|
||||||
|
)
|
||||||
|
|
||||||
|
if err := ownershipEvent.DecodeArgs(tx.Log, &previousOwner, &newOwner); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
ownershipEvent := event.Event{
|
||||||
|
Index: tx.Log.Index,
|
||||||
|
Block: tx.Log.BlockNumber,
|
||||||
|
ContractAddress: tx.Log.Address.Hex(),
|
||||||
|
Success: true,
|
||||||
|
Timestamp: tx.Timestamp,
|
||||||
|
TxHash: tx.Log.TxHash.Hex(),
|
||||||
|
TxType: ownershipEventName,
|
||||||
|
Payload: map[string]any{
|
||||||
|
"previousOwner": previousOwner.Hex(),
|
||||||
|
"newOwner": newOwner.Hex(),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
return pubCB(ctx, ownershipEvent)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *ownershipHandler) RevertTx(ctx context.Context, tx RevertTx, pubCB PubCallback) error {
|
||||||
|
|
||||||
|
var newOwner common.Address
|
||||||
|
|
||||||
|
if err := ownershipToSig.DecodeArgs(w3.B(tx.InputData), &newOwner); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
ownershipEvent := event.Event{
|
||||||
|
Block: tx.Block,
|
||||||
|
ContractAddress: tx.ContractAddress,
|
||||||
|
Success: false,
|
||||||
|
Timestamp: tx.Timestamp,
|
||||||
|
TxHash: tx.TxHash,
|
||||||
|
TxType: ownershipEventName,
|
||||||
|
Payload: map[string]any{
|
||||||
|
"previousOwner": tx.From,
|
||||||
|
"newOwner": newOwner.Hex(),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
return pubCB(ctx, ownershipEvent)
|
||||||
|
}
|
86
internal/router/pool_deposit.go
Normal file
86
internal/router/pool_deposit.go
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
package router
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"math/big"
|
||||||
|
|
||||||
|
"github.com/celo-org/celo-blockchain/common"
|
||||||
|
"github.com/grassrootseconomics/celo-tracker/pkg/event"
|
||||||
|
"github.com/grassrootseconomics/w3-celo"
|
||||||
|
)
|
||||||
|
|
||||||
|
type poolDepositHandler struct{}
|
||||||
|
|
||||||
|
const poolDepositEventName = "POOL_DEPOSIT"
|
||||||
|
|
||||||
|
var (
|
||||||
|
_ Handler = (*poolDepositHandler)(nil)
|
||||||
|
|
||||||
|
poolDepositEvent = w3.MustNewEvent("Deposit(address indexed initiator, address indexed tokenIn, uint256 amountIn)")
|
||||||
|
poolDepositSig = w3.MustNewFunc("deposit(address, uint256)", "")
|
||||||
|
)
|
||||||
|
|
||||||
|
func (h *poolDepositHandler) Name() string {
|
||||||
|
return poolDepositEventName
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *poolDepositHandler) SuccessTx(ctx context.Context, tx SuccessTx, pubCB PubCallback) error {
|
||||||
|
var (
|
||||||
|
initiator common.Address
|
||||||
|
tokenIn common.Address
|
||||||
|
amountIn big.Int
|
||||||
|
)
|
||||||
|
|
||||||
|
if err := poolDepositEvent.DecodeArgs(
|
||||||
|
tx.Log,
|
||||||
|
&initiator,
|
||||||
|
&tokenIn,
|
||||||
|
&amountIn,
|
||||||
|
); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
poolDepositEvent := event.Event{
|
||||||
|
Index: tx.Log.Index,
|
||||||
|
Block: tx.Log.BlockNumber,
|
||||||
|
ContractAddress: tx.Log.Address.Hex(),
|
||||||
|
Success: true,
|
||||||
|
Timestamp: tx.Timestamp,
|
||||||
|
TxHash: tx.Log.TxHash.Hex(),
|
||||||
|
TxType: poolDepositEventName,
|
||||||
|
Payload: map[string]any{
|
||||||
|
"initiator": initiator.Hex(),
|
||||||
|
"tokenIn": tokenIn.Hex(),
|
||||||
|
"amountIn": amountIn.String(),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
return pubCB(ctx, poolDepositEvent)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *poolDepositHandler) RevertTx(ctx context.Context, tx RevertTx, pubCB PubCallback) error {
|
||||||
|
var (
|
||||||
|
tokenIn common.Address
|
||||||
|
amountIn big.Int
|
||||||
|
)
|
||||||
|
|
||||||
|
if err := poolDepositSig.DecodeArgs(w3.B(tx.InputData), &tokenIn, &amountIn); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
poolDepositEvent := event.Event{
|
||||||
|
Block: tx.Block,
|
||||||
|
ContractAddress: tx.ContractAddress,
|
||||||
|
Success: false,
|
||||||
|
Timestamp: tx.Timestamp,
|
||||||
|
TxHash: tx.TxHash,
|
||||||
|
TxType: poolDepositEventName,
|
||||||
|
Payload: map[string]any{
|
||||||
|
"initiator": tx.From,
|
||||||
|
"tokenIn": tokenIn.Hex(),
|
||||||
|
"amountIn": amountIn.String(),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
return pubCB(ctx, poolDepositEvent)
|
||||||
|
}
|
99
internal/router/pool_swap.go
Normal file
99
internal/router/pool_swap.go
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
package router
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"math/big"
|
||||||
|
|
||||||
|
"github.com/celo-org/celo-blockchain/common"
|
||||||
|
"github.com/grassrootseconomics/celo-tracker/pkg/event"
|
||||||
|
"github.com/grassrootseconomics/w3-celo"
|
||||||
|
)
|
||||||
|
|
||||||
|
type poolSwapHandler struct{}
|
||||||
|
|
||||||
|
const poolSwapEventName = "POOL_SWAP"
|
||||||
|
|
||||||
|
var (
|
||||||
|
_ Handler = (*poolSwapHandler)(nil)
|
||||||
|
|
||||||
|
poolSwapEvent = w3.MustNewEvent("Swap(address indexed initiator, address indexed tokenIn, address tokenOut, uint256 amountIn, uint256 amountOut, uint256 fee)")
|
||||||
|
poolSwapSig = w3.MustNewFunc("withdraw(address, address, uint256)", "")
|
||||||
|
)
|
||||||
|
|
||||||
|
func (h *poolSwapHandler) Name() string {
|
||||||
|
return poolSwapEventName
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *poolSwapHandler) SuccessTx(ctx context.Context, tx SuccessTx, pubCB PubCallback) error {
|
||||||
|
var (
|
||||||
|
initiator common.Address
|
||||||
|
tokenIn common.Address
|
||||||
|
tokenOut common.Address
|
||||||
|
amountIn big.Int
|
||||||
|
amountOut big.Int
|
||||||
|
fee big.Int
|
||||||
|
)
|
||||||
|
|
||||||
|
if err := poolSwapEvent.DecodeArgs(
|
||||||
|
tx.Log,
|
||||||
|
&initiator,
|
||||||
|
&tokenIn,
|
||||||
|
&tokenOut,
|
||||||
|
&amountIn,
|
||||||
|
&amountOut,
|
||||||
|
&fee,
|
||||||
|
); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
poolSwapEvent := event.Event{
|
||||||
|
Index: tx.Log.Index,
|
||||||
|
Block: tx.Log.BlockNumber,
|
||||||
|
ContractAddress: tx.Log.Address.Hex(),
|
||||||
|
Success: true,
|
||||||
|
Timestamp: tx.Timestamp,
|
||||||
|
TxHash: tx.Log.TxHash.Hex(),
|
||||||
|
TxType: poolSwapEventName,
|
||||||
|
Payload: map[string]any{
|
||||||
|
"initiator": initiator.Hex(),
|
||||||
|
"tokenIn": tokenIn.Hex(),
|
||||||
|
"tokenOut": tokenOut.Hex(),
|
||||||
|
"amountIn": amountIn.String(),
|
||||||
|
"amountOut": amountOut.String(),
|
||||||
|
"fee": fee.String(),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
return pubCB(ctx, poolSwapEvent)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *poolSwapHandler) RevertTx(ctx context.Context, tx RevertTx, pubCB PubCallback) error {
|
||||||
|
var (
|
||||||
|
tokenOut common.Address
|
||||||
|
tokenIn common.Address
|
||||||
|
amountIn big.Int
|
||||||
|
)
|
||||||
|
|
||||||
|
if err := poolSwapSig.DecodeArgs(w3.B(tx.InputData), &tokenOut, &tokenIn, &amountIn); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
poolSwapEvent := event.Event{
|
||||||
|
Block: tx.Block,
|
||||||
|
ContractAddress: tx.ContractAddress,
|
||||||
|
Success: false,
|
||||||
|
Timestamp: tx.Timestamp,
|
||||||
|
TxHash: tx.TxHash,
|
||||||
|
TxType: poolSwapEventName,
|
||||||
|
Payload: map[string]any{
|
||||||
|
"initiator": tx.From,
|
||||||
|
"tokenIn": tokenIn.Hex(),
|
||||||
|
"tokenOut": tokenOut.Hex(),
|
||||||
|
"amountIn": amountIn.String(),
|
||||||
|
"amountOut": "0",
|
||||||
|
"fee": "0",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
return pubCB(ctx, poolSwapEvent)
|
||||||
|
}
|
78
internal/router/quoter_price.go
Normal file
78
internal/router/quoter_price.go
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
package router
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"math/big"
|
||||||
|
|
||||||
|
"github.com/celo-org/celo-blockchain/common"
|
||||||
|
"github.com/grassrootseconomics/celo-tracker/pkg/event"
|
||||||
|
"github.com/grassrootseconomics/w3-celo"
|
||||||
|
)
|
||||||
|
|
||||||
|
type quoterPriceHandler struct{}
|
||||||
|
|
||||||
|
const quoterPriceEventName = "QUOTER_PRICE_INDEX_UPDATED"
|
||||||
|
|
||||||
|
var (
|
||||||
|
_ Handler = (*quoterPriceHandler)(nil)
|
||||||
|
|
||||||
|
quoterPriceEvent = w3.MustNewEvent("PriceIndexUpdated(address _tokenAddress, uint256 _exchangeRate)")
|
||||||
|
quoterPriceToSig = w3.MustNewFunc("setPriceIndexValue(address, uint256)", "uint256")
|
||||||
|
)
|
||||||
|
|
||||||
|
func (h *quoterPriceHandler) Name() string {
|
||||||
|
return quoterPriceEventName
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *quoterPriceHandler) SuccessTx(ctx context.Context, tx SuccessTx, pubCB PubCallback) error {
|
||||||
|
var (
|
||||||
|
token common.Address
|
||||||
|
exchangeRate big.Int
|
||||||
|
)
|
||||||
|
|
||||||
|
if err := quoterPriceEvent.DecodeArgs(tx.Log, &token, &exchangeRate); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
quoterPriceEvent := event.Event{
|
||||||
|
Index: tx.Log.Index,
|
||||||
|
Block: tx.Log.BlockNumber,
|
||||||
|
ContractAddress: tx.Log.Address.Hex(),
|
||||||
|
Success: true,
|
||||||
|
Timestamp: tx.Timestamp,
|
||||||
|
TxHash: tx.Log.TxHash.Hex(),
|
||||||
|
TxType: quoterPriceEventName,
|
||||||
|
Payload: map[string]any{
|
||||||
|
"token": token.Hex(),
|
||||||
|
"exchangeRate": exchangeRate.String(),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
return pubCB(ctx, quoterPriceEvent)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *quoterPriceHandler) RevertTx(ctx context.Context, tx RevertTx, pubCB PubCallback) error {
|
||||||
|
var (
|
||||||
|
token common.Address
|
||||||
|
exchangeRate big.Int
|
||||||
|
)
|
||||||
|
|
||||||
|
if err := quoterPriceToSig.DecodeArgs(w3.B(tx.InputData), &token, &exchangeRate); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
quoterPriceEvent := event.Event{
|
||||||
|
Block: tx.Block,
|
||||||
|
ContractAddress: tx.ContractAddress,
|
||||||
|
Success: false,
|
||||||
|
Timestamp: tx.Timestamp,
|
||||||
|
TxHash: tx.TxHash,
|
||||||
|
TxType: quoterPriceEventName,
|
||||||
|
Payload: map[string]any{
|
||||||
|
"token": token.Hex(),
|
||||||
|
"exchangeRate": exchangeRate.String(),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
return pubCB(ctx, quoterPriceEvent)
|
||||||
|
}
|
123
internal/router/router.go
Normal file
123
internal/router/router.go
Normal file
@ -0,0 +1,123 @@
|
|||||||
|
package router
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/celo-org/celo-blockchain/common"
|
||||||
|
"github.com/celo-org/celo-blockchain/core/types"
|
||||||
|
"github.com/grassrootseconomics/celo-tracker/internal/cache"
|
||||||
|
"github.com/grassrootseconomics/celo-tracker/internal/pub"
|
||||||
|
"github.com/grassrootseconomics/celo-tracker/pkg/event"
|
||||||
|
"github.com/grassrootseconomics/w3-celo"
|
||||||
|
)
|
||||||
|
|
||||||
|
type (
|
||||||
|
PubCallback func(context.Context, event.Event) error
|
||||||
|
|
||||||
|
SuccessTx struct {
|
||||||
|
Log *types.Log
|
||||||
|
Timestamp uint64
|
||||||
|
}
|
||||||
|
|
||||||
|
RevertTx struct {
|
||||||
|
From string
|
||||||
|
InputData string
|
||||||
|
Block uint64
|
||||||
|
ContractAddress string
|
||||||
|
Timestamp uint64
|
||||||
|
TxHash string
|
||||||
|
}
|
||||||
|
|
||||||
|
Handler interface {
|
||||||
|
Name() string
|
||||||
|
SuccessTx(context.Context, SuccessTx, PubCallback) error
|
||||||
|
RevertTx(context.Context, RevertTx, PubCallback) error
|
||||||
|
}
|
||||||
|
|
||||||
|
RouterOpts struct {
|
||||||
|
Pub pub.Pub
|
||||||
|
Cache cache.Cache
|
||||||
|
}
|
||||||
|
|
||||||
|
Router struct {
|
||||||
|
pub pub.Pub
|
||||||
|
cache cache.Cache
|
||||||
|
logHandlers map[common.Hash]Handler
|
||||||
|
inputDataHandlers map[string]Handler
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
func New(o RouterOpts) *Router {
|
||||||
|
var (
|
||||||
|
indexAddHandler *indexAddHandler = &indexAddHandler{cache: o.Cache}
|
||||||
|
indexRemoveHandler *indexRemoveHandler = &indexRemoveHandler{cache: o.Cache}
|
||||||
|
tokenTransferHandler *tokenTransferHandler = &tokenTransferHandler{cache: o.Cache}
|
||||||
|
faucetGiveHandler *faucetGiveHandler = &faucetGiveHandler{}
|
||||||
|
ownershipHandler *ownershipHandler = &ownershipHandler{}
|
||||||
|
poolDepositHandler *poolDepositHandler = &poolDepositHandler{}
|
||||||
|
poolSwapHandler *poolSwapHandler = &poolSwapHandler{}
|
||||||
|
quoterPriceHandler *quoterPriceHandler = "erPriceHandler{}
|
||||||
|
sealHandler *sealHandler = &sealHandler{}
|
||||||
|
tokenBurnHandler *tokenBurnHandler = &tokenBurnHandler{}
|
||||||
|
tokenMintHandler *tokenMintHandler = &tokenMintHandler{}
|
||||||
|
)
|
||||||
|
|
||||||
|
logHandlers := map[common.Hash]Handler{
|
||||||
|
w3.H("0x26162814817e23ec5035d6a2edc6c422da2da2119e27cfca6be65cc2dc55ca4c"): faucetGiveHandler,
|
||||||
|
w3.H("0xa226db3f664042183ee0281230bba26cbf7b5057e50aee7f25a175ff45ce4d7f"): indexAddHandler,
|
||||||
|
w3.H("0x24a12366c02e13fe4a9e03d86a8952e85bb74a456c16e4a18b6d8295700b74bb"): indexRemoveHandler,
|
||||||
|
w3.H("0x8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0"): ownershipHandler,
|
||||||
|
w3.H("0x5548c837ab068cf56a2c2479df0882a4922fd203edb7517321831d95078c5f62"): poolDepositHandler,
|
||||||
|
w3.H("0xd6d34547c69c5ee3d2667625c188acf1006abb93e0ee7cf03925c67cf7760413"): poolSwapHandler,
|
||||||
|
w3.H("0xdb9ce1a76955721ca61ac50cd1b87f9ab8620325c8619a62192c2dc7871d56b1"): quoterPriceHandler,
|
||||||
|
w3.H("0x6b7e2e653f93b645d4ed7292d6429f96637084363e477c8aaea1a43ed13c284e"): sealHandler,
|
||||||
|
w3.H("0xcc16f5dbb4873280815c1ee09dbd06736cffcc184412cf7a71a0fdb75d397ca5"): tokenBurnHandler,
|
||||||
|
w3.H("0xab8530f87dc9b59234c4623bf917212bb2536d647574c8e7e5da92c2ede0c9f8"): tokenMintHandler,
|
||||||
|
w3.H("0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"): tokenTransferHandler,
|
||||||
|
}
|
||||||
|
|
||||||
|
inputDataHandlers := map[string]Handler{
|
||||||
|
"63e4bff4": faucetGiveHandler,
|
||||||
|
"de82efb4": faucetGiveHandler,
|
||||||
|
"0a3b0a4f": indexAddHandler,
|
||||||
|
"4420e486": indexAddHandler,
|
||||||
|
"29092d0e": indexRemoveHandler,
|
||||||
|
"f2fde38b": ownershipHandler,
|
||||||
|
"47e7ef24": poolDepositHandler,
|
||||||
|
"d9caed12": poolSwapHandler,
|
||||||
|
"ebc59dff": quoterPriceHandler,
|
||||||
|
"86fe212d": sealHandler,
|
||||||
|
"42966c68": tokenBurnHandler,
|
||||||
|
"449a52f8": tokenMintHandler,
|
||||||
|
"a9059cbb": tokenTransferHandler,
|
||||||
|
"23b872dd": tokenTransferHandler,
|
||||||
|
}
|
||||||
|
|
||||||
|
return &Router{
|
||||||
|
pub: o.Pub,
|
||||||
|
logHandlers: logHandlers,
|
||||||
|
inputDataHandlers: inputDataHandlers,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Router) RouteSuccessTx(ctx context.Context, msg SuccessTx) error {
|
||||||
|
handler, ok := r.logHandlers[msg.Log.Topics[0]]
|
||||||
|
if ok {
|
||||||
|
return handler.SuccessTx(ctx, msg, r.pub.Send)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Router) RouteRevertTx(ctx context.Context, msg RevertTx) error {
|
||||||
|
if len(msg.InputData) < 8 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
handler, ok := r.inputDataHandlers[msg.InputData[:8]]
|
||||||
|
if ok {
|
||||||
|
return handler.RevertTx(ctx, msg, r.pub.Send)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
73
internal/router/seal.go
Normal file
73
internal/router/seal.go
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
package router
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"math/big"
|
||||||
|
|
||||||
|
"github.com/grassrootseconomics/celo-tracker/pkg/event"
|
||||||
|
"github.com/grassrootseconomics/w3-celo"
|
||||||
|
)
|
||||||
|
|
||||||
|
type sealHandler struct{}
|
||||||
|
|
||||||
|
const sealEventName = "SEAL_STATE_CHANGE"
|
||||||
|
|
||||||
|
var (
|
||||||
|
_ Handler = (*sealHandler)(nil)
|
||||||
|
|
||||||
|
sealEvent = w3.MustNewEvent("SealStateChange(bool indexed _final, uint256 _sealState)")
|
||||||
|
sealToSig = w3.MustNewFunc("seal(uint256)", "uint256")
|
||||||
|
)
|
||||||
|
|
||||||
|
func (h *sealHandler) Name() string {
|
||||||
|
return sealEventName
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *sealHandler) SuccessTx(ctx context.Context, tx SuccessTx, pubCB PubCallback) error {
|
||||||
|
var (
|
||||||
|
final bool
|
||||||
|
sealState big.Int
|
||||||
|
)
|
||||||
|
|
||||||
|
if err := sealEvent.DecodeArgs(tx.Log, &final, &sealState); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
sealEvent := event.Event{
|
||||||
|
Index: tx.Log.Index,
|
||||||
|
Block: tx.Log.BlockNumber,
|
||||||
|
ContractAddress: tx.Log.Address.Hex(),
|
||||||
|
Success: true,
|
||||||
|
Timestamp: tx.Timestamp,
|
||||||
|
TxHash: tx.Log.TxHash.Hex(),
|
||||||
|
TxType: sealEventName,
|
||||||
|
Payload: map[string]any{
|
||||||
|
"final": final,
|
||||||
|
"sealState": sealState.String(),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
return pubCB(ctx, sealEvent)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *sealHandler) RevertTx(ctx context.Context, tx RevertTx, pubCB PubCallback) error {
|
||||||
|
var sealState big.Int
|
||||||
|
|
||||||
|
if err := sealToSig.DecodeArgs(w3.B(tx.InputData), &sealState); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
sealEvent := event.Event{
|
||||||
|
Block: tx.Block,
|
||||||
|
ContractAddress: tx.ContractAddress,
|
||||||
|
Success: false,
|
||||||
|
Timestamp: tx.Timestamp,
|
||||||
|
TxHash: tx.TxHash,
|
||||||
|
TxType: sealEventName,
|
||||||
|
Payload: map[string]any{
|
||||||
|
"sealState": sealState.String(),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
return pubCB(ctx, sealEvent)
|
||||||
|
}
|
75
internal/router/token_burn.go
Normal file
75
internal/router/token_burn.go
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
package router
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"math/big"
|
||||||
|
|
||||||
|
"github.com/celo-org/celo-blockchain/common"
|
||||||
|
"github.com/grassrootseconomics/celo-tracker/pkg/event"
|
||||||
|
"github.com/grassrootseconomics/w3-celo"
|
||||||
|
)
|
||||||
|
|
||||||
|
type tokenBurnHandler struct{}
|
||||||
|
|
||||||
|
const burnEventName = "TOKEN_BURN"
|
||||||
|
|
||||||
|
var (
|
||||||
|
_ Handler = (*tokenBurnHandler)(nil)
|
||||||
|
|
||||||
|
tokenBurnEvent = w3.MustNewEvent("Burn(address indexed _tokenBurner, uint256 _value)")
|
||||||
|
tokenBurnToSig = w3.MustNewFunc("Burn(uint256)", "bool")
|
||||||
|
)
|
||||||
|
|
||||||
|
func (h *tokenBurnHandler) Name() string {
|
||||||
|
return burnEventName
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *tokenBurnHandler) SuccessTx(ctx context.Context, tx SuccessTx, pubCB PubCallback) error {
|
||||||
|
var (
|
||||||
|
tokenBurner common.Address
|
||||||
|
value big.Int
|
||||||
|
)
|
||||||
|
|
||||||
|
if err := tokenBurnEvent.DecodeArgs(tx.Log, &tokenBurner, &value); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
tokenBurnEvent := event.Event{
|
||||||
|
Index: tx.Log.Index,
|
||||||
|
Block: tx.Log.BlockNumber,
|
||||||
|
ContractAddress: tx.Log.Address.Hex(),
|
||||||
|
Success: true,
|
||||||
|
Timestamp: tx.Timestamp,
|
||||||
|
TxHash: tx.Log.TxHash.Hex(),
|
||||||
|
TxType: burnEventName,
|
||||||
|
Payload: map[string]any{
|
||||||
|
"tokenBurner": tokenBurner.Hex(),
|
||||||
|
"value": value.String(),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
return pubCB(ctx, tokenBurnEvent)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *tokenBurnHandler) RevertTx(ctx context.Context, tx RevertTx, pubCB PubCallback) error {
|
||||||
|
var value big.Int
|
||||||
|
|
||||||
|
if err := tokenBurnToSig.DecodeArgs(w3.B(tx.InputData), &value); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
tokenBurnEvent := event.Event{
|
||||||
|
Block: tx.Block,
|
||||||
|
ContractAddress: tx.ContractAddress,
|
||||||
|
Success: false,
|
||||||
|
Timestamp: tx.Timestamp,
|
||||||
|
TxHash: tx.TxHash,
|
||||||
|
TxType: burnEventName,
|
||||||
|
Payload: map[string]any{
|
||||||
|
"tokenBurner": tx.From,
|
||||||
|
"value": value.String(),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
return pubCB(ctx, tokenBurnEvent)
|
||||||
|
}
|
82
internal/router/token_mint.go
Normal file
82
internal/router/token_mint.go
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
package router
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"math/big"
|
||||||
|
|
||||||
|
"github.com/celo-org/celo-blockchain/common"
|
||||||
|
"github.com/grassrootseconomics/celo-tracker/pkg/event"
|
||||||
|
"github.com/grassrootseconomics/w3-celo"
|
||||||
|
)
|
||||||
|
|
||||||
|
type tokenMintHandler struct{}
|
||||||
|
|
||||||
|
const mintEventName = "TOKEN_MINT"
|
||||||
|
|
||||||
|
var (
|
||||||
|
_ Handler = (*tokenMintHandler)(nil)
|
||||||
|
|
||||||
|
tokenMintEvent = w3.MustNewEvent("Mint(address indexed _tokenMinter, address indexed _beneficiary, uint256 _value)")
|
||||||
|
tokenMintToSig = w3.MustNewFunc("MintTo(address, uint256)", "bool")
|
||||||
|
)
|
||||||
|
|
||||||
|
func (h *tokenMintHandler) Name() string {
|
||||||
|
return mintEventName
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *tokenMintHandler) SuccessTx(ctx context.Context, tx SuccessTx, pubCB PubCallback) error {
|
||||||
|
var (
|
||||||
|
tokenMinter common.Address
|
||||||
|
to common.Address
|
||||||
|
value big.Int
|
||||||
|
)
|
||||||
|
|
||||||
|
if err := tokenMintEvent.DecodeArgs(tx.Log, &tokenMinter, &to, &value); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
tokenMintEvent := event.Event{
|
||||||
|
Index: tx.Log.Index,
|
||||||
|
Block: tx.Log.BlockNumber,
|
||||||
|
ContractAddress: tx.Log.Address.Hex(),
|
||||||
|
Success: true,
|
||||||
|
Timestamp: tx.Timestamp,
|
||||||
|
TxHash: tx.Log.TxHash.Hex(),
|
||||||
|
TxType: mintEventName,
|
||||||
|
Payload: map[string]any{
|
||||||
|
"tokenMinter": tokenMinter.Hex(),
|
||||||
|
"to": to.Hex(),
|
||||||
|
"value": value.String(),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
return pubCB(ctx, tokenMintEvent)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *tokenMintHandler) RevertTx(ctx context.Context, tx RevertTx, pubCB PubCallback) error {
|
||||||
|
|
||||||
|
var (
|
||||||
|
to common.Address
|
||||||
|
value big.Int
|
||||||
|
)
|
||||||
|
|
||||||
|
if err := tokenMintToSig.DecodeArgs(w3.B(tx.InputData), &to, &value); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
tokenMintEvent := event.Event{
|
||||||
|
Block: tx.Block,
|
||||||
|
ContractAddress: tx.ContractAddress,
|
||||||
|
Success: false,
|
||||||
|
Timestamp: tx.Timestamp,
|
||||||
|
TxHash: tx.TxHash,
|
||||||
|
TxType: mintEventName,
|
||||||
|
Payload: map[string]any{
|
||||||
|
"tokenMinter": tx.From,
|
||||||
|
"to": to.Hex(),
|
||||||
|
"value": value.String(),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
return pubCB(ctx, tokenMintEvent)
|
||||||
|
}
|
161
internal/router/token_transfer.go
Normal file
161
internal/router/token_transfer.go
Normal file
@ -0,0 +1,161 @@
|
|||||||
|
package router
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"math/big"
|
||||||
|
|
||||||
|
"github.com/celo-org/celo-blockchain/common"
|
||||||
|
"github.com/grassrootseconomics/celo-tracker/internal/cache"
|
||||||
|
"github.com/grassrootseconomics/celo-tracker/pkg/event"
|
||||||
|
"github.com/grassrootseconomics/celoutils/v3"
|
||||||
|
"github.com/grassrootseconomics/w3-celo"
|
||||||
|
)
|
||||||
|
|
||||||
|
type tokenTransferHandler struct {
|
||||||
|
cache cache.Cache
|
||||||
|
}
|
||||||
|
|
||||||
|
const transferEventName = "TOKEN_TRANSFER"
|
||||||
|
|
||||||
|
var (
|
||||||
|
_ Handler = (*tokenTransferHandler)(nil)
|
||||||
|
|
||||||
|
tokenTransferEvent = w3.MustNewEvent("Transfer(address indexed _from, address indexed _to, uint256 _value)")
|
||||||
|
tokenTransferSig = w3.MustNewFunc("transfer(address, uint256)", "bool")
|
||||||
|
tokenTransferFromSig = w3.MustNewFunc("transferFrom(address, address, uint256)", "bool")
|
||||||
|
|
||||||
|
stables = map[string]bool{
|
||||||
|
celoutils.CUSDContractMainnet: true,
|
||||||
|
celoutils.CKESContractMainnet: true,
|
||||||
|
celoutils.USDTContractMainnet: true,
|
||||||
|
celoutils.USDCContractMainnet: true,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
func (h *tokenTransferHandler) Name() string {
|
||||||
|
return transferEventName
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *tokenTransferHandler) SuccessTx(ctx context.Context, tx SuccessTx, pubCB PubCallback) error {
|
||||||
|
var (
|
||||||
|
from common.Address
|
||||||
|
to common.Address
|
||||||
|
value big.Int
|
||||||
|
)
|
||||||
|
|
||||||
|
if err := tokenTransferEvent.DecodeArgs(tx.Log, &from, &to, &value); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
proceed, err := h.checkStables(ctx, from.Hex(), to.Hex(), tx.Log.Address.Hex())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if !proceed {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
tokenTransferEvent := event.Event{
|
||||||
|
Index: tx.Log.Index,
|
||||||
|
Block: tx.Log.BlockNumber,
|
||||||
|
ContractAddress: tx.Log.Address.Hex(),
|
||||||
|
Success: true,
|
||||||
|
Timestamp: tx.Timestamp,
|
||||||
|
TxHash: tx.Log.TxHash.Hex(),
|
||||||
|
TxType: transferEventName,
|
||||||
|
Payload: map[string]any{
|
||||||
|
"from": from.Hex(),
|
||||||
|
"to": to.Hex(),
|
||||||
|
"value": value.String(),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
return pubCB(ctx, tokenTransferEvent)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *tokenTransferHandler) RevertTx(ctx context.Context, tx RevertTx, pubCB PubCallback) error {
|
||||||
|
tokenTransferEvent := event.Event{
|
||||||
|
Block: tx.Block,
|
||||||
|
ContractAddress: tx.ContractAddress,
|
||||||
|
Success: false,
|
||||||
|
Timestamp: tx.Timestamp,
|
||||||
|
TxHash: tx.TxHash,
|
||||||
|
TxType: transferEventName,
|
||||||
|
}
|
||||||
|
|
||||||
|
switch tx.InputData[:8] {
|
||||||
|
case "a9059cbb":
|
||||||
|
var (
|
||||||
|
to common.Address
|
||||||
|
value big.Int
|
||||||
|
)
|
||||||
|
|
||||||
|
if err := tokenTransferSig.DecodeArgs(w3.B(tx.InputData), &to, &value); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
proceed, err := h.checkStables(ctx, tx.From, to.Hex(), tx.ContractAddress)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if !proceed {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
tokenTransferEvent.Payload = map[string]any{
|
||||||
|
"from": tx.From,
|
||||||
|
"to": to.Hex(),
|
||||||
|
"value": value.String(),
|
||||||
|
}
|
||||||
|
|
||||||
|
return pubCB(ctx, tokenTransferEvent)
|
||||||
|
case "23b872dd":
|
||||||
|
var (
|
||||||
|
from common.Address
|
||||||
|
to common.Address
|
||||||
|
value big.Int
|
||||||
|
)
|
||||||
|
|
||||||
|
if err := tokenTransferFromSig.DecodeArgs(w3.B(tx.InputData), &from, &to, &value); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
proceed, err := h.checkStables(ctx, from.Hex(), to.Hex(), tx.ContractAddress)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if !proceed {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
tokenTransferEvent.Payload = map[string]any{
|
||||||
|
"from": from.Hex(),
|
||||||
|
"to": to.Hex(),
|
||||||
|
"value": value.String(),
|
||||||
|
}
|
||||||
|
|
||||||
|
return pubCB(ctx, tokenTransferEvent)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *tokenTransferHandler) checkStables(ctx context.Context, from string, to string, contractAddress string) (bool, error) {
|
||||||
|
_, ok := stables[contractAddress]
|
||||||
|
if !ok {
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Pipeline this check on Redis with a new method
|
||||||
|
fromExists, err := h.cache.Exists(ctx, from)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
toExists, err := h.cache.Exists(ctx, to)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return fromExists || toExists, nil
|
||||||
|
}
|
88
internal/stats/stats.go
Normal file
88
internal/stats/stats.go
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
package stats
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"log/slog"
|
||||||
|
"sync/atomic"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/grassrootseconomics/celo-tracker/internal/cache"
|
||||||
|
"github.com/grassrootseconomics/celo-tracker/internal/pool"
|
||||||
|
)
|
||||||
|
|
||||||
|
type (
|
||||||
|
StatsOpts struct {
|
||||||
|
Cache cache.Cache
|
||||||
|
Logg *slog.Logger
|
||||||
|
Pool *pool.Pool
|
||||||
|
}
|
||||||
|
|
||||||
|
Stats struct {
|
||||||
|
cache cache.Cache
|
||||||
|
logg *slog.Logger
|
||||||
|
pool *pool.Pool
|
||||||
|
stopCh chan struct{}
|
||||||
|
latestBlock atomic.Uint64
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
const statsPrinterInterval = 15 * time.Second
|
||||||
|
|
||||||
|
func New(o StatsOpts) *Stats {
|
||||||
|
return &Stats{
|
||||||
|
cache: o.Cache,
|
||||||
|
logg: o.Logg,
|
||||||
|
pool: o.Pool,
|
||||||
|
stopCh: make(chan struct{}),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Stats) SetLatestBlock(v uint64) {
|
||||||
|
s.latestBlock.Store(v)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Stats) GetLatestBlock() uint64 {
|
||||||
|
return s.latestBlock.Load()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Stats) Stop() {
|
||||||
|
s.stopCh <- struct{}{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Stats) APIStatsResponse(ctx context.Context) (map[string]interface{}, error) {
|
||||||
|
cacheSize, err := s.cache.Size(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return map[string]interface{}{
|
||||||
|
"latestBlock": s.GetLatestBlock(),
|
||||||
|
"poolQueueSize": s.pool.Size(),
|
||||||
|
"poolActiveWorkers": s.pool.ActiveWorkers(),
|
||||||
|
"cacheSize": cacheSize,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Stats) StartStatsPrinter() {
|
||||||
|
ticker := time.NewTicker(statsPrinterInterval)
|
||||||
|
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <-s.stopCh:
|
||||||
|
s.logg.Debug("stats shutting down")
|
||||||
|
return
|
||||||
|
case <-ticker.C:
|
||||||
|
cacheSize, err := s.cache.Size(context.Background())
|
||||||
|
if err != nil {
|
||||||
|
s.logg.Error("stats printer could not fetch cache size", "error", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
s.logg.Info("block stats",
|
||||||
|
"latest_block", s.GetLatestBlock(),
|
||||||
|
"pool_queue_size", s.pool.Size(),
|
||||||
|
"pool_active_workers", s.pool.ActiveWorkers(),
|
||||||
|
"cache_size", cacheSize,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
80
internal/syncer/realtime.go
Normal file
80
internal/syncer/realtime.go
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
package syncer
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/celo-org/celo-blockchain"
|
||||||
|
"github.com/celo-org/celo-blockchain/core/types"
|
||||||
|
"github.com/celo-org/celo-blockchain/event"
|
||||||
|
)
|
||||||
|
|
||||||
|
type BlockQueueFn func(uint64) error
|
||||||
|
|
||||||
|
const resubscribeInterval = 2 * time.Second
|
||||||
|
|
||||||
|
func (s *Syncer) Stop() {
|
||||||
|
if s.realtimeSub != nil {
|
||||||
|
s.realtimeSub.Unsubscribe()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Syncer) Start() {
|
||||||
|
s.realtimeSub = event.ResubscribeErr(resubscribeInterval, s.resubscribeFn())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Syncer) receiveRealtimeBlocks(ctx context.Context, fn BlockQueueFn) (celo.Subscription, error) {
|
||||||
|
newHeadersReceiver := make(chan *types.Header, 1)
|
||||||
|
sub, err := s.ethClient.SubscribeNewHead(ctx, newHeadersReceiver)
|
||||||
|
s.logg.Info("realtime syncer connected to ws endpoint")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return event.NewSubscription(func(quit <-chan struct{}) error {
|
||||||
|
eventsCtx, eventsCancel := context.WithCancel(context.Background())
|
||||||
|
defer eventsCancel()
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
select {
|
||||||
|
case <-quit:
|
||||||
|
s.logg.Info("realtime syncer stopping")
|
||||||
|
eventsCancel()
|
||||||
|
case <-eventsCtx.Done():
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case header := <-newHeadersReceiver:
|
||||||
|
if err := fn(header.Number.Uint64()); err != nil {
|
||||||
|
s.logg.Error("realtime block queuer error", "error", err)
|
||||||
|
}
|
||||||
|
case <-eventsCtx.Done():
|
||||||
|
s.logg.Info("realtime syncer shutting down")
|
||||||
|
return nil
|
||||||
|
case err := <-sub.Err():
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Syncer) queueRealtimeBlock(blockNumber uint64) error {
|
||||||
|
s.pool.Push(blockNumber)
|
||||||
|
s.stats.SetLatestBlock(blockNumber)
|
||||||
|
if err := s.db.SetUpperBound(blockNumber); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Syncer) resubscribeFn() event.ResubscribeErrFunc {
|
||||||
|
return func(ctx context.Context, err error) (event.Subscription, error) {
|
||||||
|
if err != nil {
|
||||||
|
s.logg.Error("resubscribing after failed subscription", "error", err)
|
||||||
|
}
|
||||||
|
return s.receiveRealtimeBlocks(ctx, s.queueRealtimeBlock)
|
||||||
|
}
|
||||||
|
}
|
77
internal/syncer/syncer.go
Normal file
77
internal/syncer/syncer.go
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
package syncer
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"log/slog"
|
||||||
|
|
||||||
|
"github.com/celo-org/celo-blockchain"
|
||||||
|
"github.com/celo-org/celo-blockchain/ethclient"
|
||||||
|
"github.com/grassrootseconomics/celo-tracker/db"
|
||||||
|
"github.com/grassrootseconomics/celo-tracker/internal/chain"
|
||||||
|
"github.com/grassrootseconomics/celo-tracker/internal/pool"
|
||||||
|
"github.com/grassrootseconomics/celo-tracker/internal/stats"
|
||||||
|
)
|
||||||
|
|
||||||
|
type (
|
||||||
|
SyncerOpts struct {
|
||||||
|
DB db.DB
|
||||||
|
Chain chain.Chain
|
||||||
|
Logg *slog.Logger
|
||||||
|
Pool *pool.Pool
|
||||||
|
Stats *stats.Stats
|
||||||
|
StartBlock int64
|
||||||
|
WebSocketEndpoint string
|
||||||
|
}
|
||||||
|
|
||||||
|
Syncer struct {
|
||||||
|
db db.DB
|
||||||
|
ethClient *ethclient.Client
|
||||||
|
logg *slog.Logger
|
||||||
|
realtimeSub celo.Subscription
|
||||||
|
pool *pool.Pool
|
||||||
|
stats *stats.Stats
|
||||||
|
stopCh chan struct{}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
func New(o SyncerOpts) (*Syncer, error) {
|
||||||
|
latestBlock, err := o.Chain.GetLatestBlock(context.Background())
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
lowerBound, err := o.DB.GetLowerBound()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if lowerBound == 0 {
|
||||||
|
if o.StartBlock > 0 {
|
||||||
|
if err := o.DB.SetLowerBound(uint64(o.StartBlock)); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if err := o.DB.SetLowerBound(latestBlock); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := o.DB.SetUpperBound(latestBlock); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
o.Stats.SetLatestBlock(latestBlock)
|
||||||
|
|
||||||
|
ethClient, err := ethclient.Dial(o.WebSocketEndpoint)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &Syncer{
|
||||||
|
db: o.DB,
|
||||||
|
ethClient: ethClient,
|
||||||
|
logg: o.Logg,
|
||||||
|
pool: o.Pool,
|
||||||
|
stats: o.Stats,
|
||||||
|
stopCh: make(chan struct{}),
|
||||||
|
}, nil
|
||||||
|
}
|
53
internal/util/init.go
Normal file
53
internal/util/init.go
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
package util
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log/slog"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/kamikazechaser/common/logg"
|
||||||
|
"github.com/knadh/koanf/parsers/toml"
|
||||||
|
"github.com/knadh/koanf/providers/env"
|
||||||
|
"github.com/knadh/koanf/providers/file"
|
||||||
|
"github.com/knadh/koanf/v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
func InitLogger() *slog.Logger {
|
||||||
|
loggOpts := logg.LoggOpts{
|
||||||
|
FormatType: logg.Logfmt,
|
||||||
|
LogLevel: slog.LevelInfo,
|
||||||
|
}
|
||||||
|
|
||||||
|
if os.Getenv("DEBUG") != "" {
|
||||||
|
loggOpts.LogLevel = slog.LevelDebug
|
||||||
|
}
|
||||||
|
|
||||||
|
if os.Getenv("DEV") != "" {
|
||||||
|
loggOpts.LogLevel = slog.LevelDebug
|
||||||
|
loggOpts.FormatType = logg.Human
|
||||||
|
}
|
||||||
|
|
||||||
|
return logg.NewLogg(loggOpts)
|
||||||
|
}
|
||||||
|
|
||||||
|
func InitConfig(lo *slog.Logger, confFilePath string) *koanf.Koanf {
|
||||||
|
var (
|
||||||
|
ko = koanf.New(".")
|
||||||
|
)
|
||||||
|
|
||||||
|
confFile := file.Provider(confFilePath)
|
||||||
|
if err := ko.Load(confFile, toml.Parser()); err != nil {
|
||||||
|
lo.Error("could not parse configuration file", "error", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := ko.Load(env.Provider("TRACKER_", ".", func(s string) string {
|
||||||
|
return strings.ReplaceAll(strings.ToLower(
|
||||||
|
strings.TrimPrefix(s, "TRACKER_")), "__", ".")
|
||||||
|
}), nil); err != nil {
|
||||||
|
lo.Error("could not override config from env vars", "error", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
return ko
|
||||||
|
}
|
37
pkg/event/event.go
Normal file
37
pkg/event/event.go
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
package event
|
||||||
|
|
||||||
|
import "encoding/json"
|
||||||
|
|
||||||
|
type (
|
||||||
|
Event struct {
|
||||||
|
Block uint64 `json:"block"`
|
||||||
|
ContractAddress string `json:"contractAddress"`
|
||||||
|
Success bool `json:"success"`
|
||||||
|
Timestamp uint64 `json:"timestamp"`
|
||||||
|
TxHash string `json:"transactionHash"`
|
||||||
|
TxType string `json:"transactionType"`
|
||||||
|
Payload map[string]any `json:"payload"`
|
||||||
|
Index uint `json:"-"`
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
func (e Event) Serialize() ([]byte, error) {
|
||||||
|
jsonData, err := json.Marshal(e)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return jsonData, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func Deserialize(jsonData []byte) (Event, error) {
|
||||||
|
var (
|
||||||
|
event Event
|
||||||
|
)
|
||||||
|
|
||||||
|
if err := json.Unmarshal(jsonData, &event); err != nil {
|
||||||
|
return event, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return event, nil
|
||||||
|
}
|
44
revive.toml
Normal file
44
revive.toml
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
ignoreGeneratedHeader = true
|
||||||
|
severity = "warning"
|
||||||
|
confidence = 0.8
|
||||||
|
errorCode = 0
|
||||||
|
warningCode = 0
|
||||||
|
|
||||||
|
[rule.blank-imports]
|
||||||
|
[rule.context-as-argument]
|
||||||
|
[rule.context-keys-type]
|
||||||
|
[rule.dot-imports]
|
||||||
|
[rule.error-return]
|
||||||
|
[rule.error-strings]
|
||||||
|
[rule.error-naming]
|
||||||
|
[rule.increment-decrement]
|
||||||
|
[rule.var-naming]
|
||||||
|
[rule.var-declaration]
|
||||||
|
[rule.range]
|
||||||
|
[rule.receiver-naming]
|
||||||
|
[rule.time-naming]
|
||||||
|
[rule.unexported-return]
|
||||||
|
[rule.indent-error-flow]
|
||||||
|
[rule.errorf]
|
||||||
|
[rule.empty-block]
|
||||||
|
[rule.superfluous-else]
|
||||||
|
[rule.unused-parameter]
|
||||||
|
[rule.unreachable-code]
|
||||||
|
[rule.redefines-builtin-id]
|
||||||
|
|
||||||
|
|
||||||
|
[rule.defer]
|
||||||
|
arguments = [["loop", "method-call", "recover", "return", "immediate-recover"]]
|
||||||
|
|
||||||
|
[rule.string-of-int]
|
||||||
|
|
||||||
|
[rule.atomic]
|
||||||
|
[rule.call-to-gc]
|
||||||
|
[rule.constant-logical-expr]
|
||||||
|
[rule.identical-branches]
|
||||||
|
[rule.modifies-parameter]
|
||||||
|
[rule.modifies-value-receiver]
|
||||||
|
[rule.range-val-address]
|
||||||
|
[rule.range-val-in-closure]
|
||||||
|
[rule.unconditional-recursion]
|
||||||
|
[rule.waitgroup-by-value]
|
Loading…
Reference in New Issue
Block a user