Skip to main content

Shared code for CCDExplorer.io and its Notification Bot.

Project description

CCD Explorer Fundamentals

This repository hosts the shared code used by many of the other repositories in the CCD Explorer Universe. The only way I knew how to make this work (locally and in Docker containers), is by publishing this repo as a Python package.

Most important modules in the repo are:

  • GRPCClient: this is the partial Python SDK that contains all relevant GRPC types and methods to request information from the GRPC endpoint from a node.
  • MongoDB: this module contains the connection to the MongoDB instance (or replicaset). See the Mongo Type Docs for more information.
  • Tooter: this module is a light wrapper around Apprise, used to send notifications.
  • CIS: this module contains logic to decode CIS-2 events according to the CIS-2 Specifications. This module is used in token accounting. See the CIS Type Docs for more information.

Modules

GRPCClient

This module is implemented as a partial Python SDK for the GRPC endpoint for a node. As such, it needs to be updated regularly whenever new types and methods are added to the GRPC Protocol Documentation. It relies heavily on BetterProto, however only version 2.0.0b6 seems to work. Hence, run

pip install "betterproto[compiler]"==2.0.0b6

to install this version.

BetterProto takes the .proto files from the Concordium GRPC Api Repo and converts this into the neccesary classes. When an update is performed on the Concordium GRPC Api Repo, copy the new files to the same location and run the following command:

python -m grpc_tools.protoc -I. --python_out=. --pyi_out=. --grpc_python_out=. --python_betterproto_out=. service.proto

This will generate the new _pb2.py(i) files.

CCD_Types

When I started with this project, I didn't know the first thing about Protobuf. To be honest, I still don't, but I have found a way to manage this by creating my own classes, mirroring the classes as generated by the types.proto file . These classes are stored in a submodule called CCD_Types. This contains 165 classes and 55 type aliases. See the GRPC Type Docs for more information.

Queries

The services in the service.proto file are mirrored in the queries submodule, where all relevant GRPC calls are built. These are the methods that other services call to retrieve specific information from the node.

For every call to the node, it calls grpc.channel_ready_future to check if the service is ready (the node is able to respond to queries). Is this somehow fails, the module tries to connect to a different node (as supplied in the ENV variables).

Getting Started

Almost none of the modules in this repo as useful as a standalone package, with the exception of the GRPC SDK.

ENV variables

NOTIFIER_API_TOKEN (API token for notifier bot)
API_TOKEN (API token for actual bot)
FASTMAIL_TOKEN (I use Fastmail to send email, leave blank, won't send email)
MONGO_URI (MongoDB URI)
ADMIN_CHAT_ID (Telegram admin chat ID)
MAILTO_LINK (I use Fastmail to send email, leave blank, won't send email)
MAILTO_USER (I use Fastmail to send email, leave blank, won't send email)
GRPC_MAINNET (A list of dicts with GPRC hosts) (Example: [{"host": "localhost", "port": 20000}, {"host": "my.validator.com", "port": 20000}])
GRPC_TESTNET (Same as GPRC_MAINNET)

Tests

The CIS module and GRPC module have associated tests.

Authors

  • explorer.ccd - Everything

License

This project is licensed under the Apache 2.0 License - see the LICENSE.md file for details.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ccdexplorer_fundamentals-0.2.52.tar.gz (179.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ccdexplorer_fundamentals-0.2.52-py3-none-any.whl (217.8 kB view details)

Uploaded Python 3

File details

Details for the file ccdexplorer_fundamentals-0.2.52.tar.gz.

File metadata

File hashes

Hashes for ccdexplorer_fundamentals-0.2.52.tar.gz
Algorithm Hash digest
SHA256 b00e2aaf8aff06b3b35f84013cceb85eff4fd2436131468d555c6dc734fd252a
MD5 d9ddc87c0e211008f83d0bbc8a9ea79d
BLAKE2b-256 39ef205e2d3acb5ee62c2152bae87ba15e4f6dd5ca2227f9263c793b273005f4

See more details on using hashes here.

Provenance

The following attestation bundles were made for ccdexplorer_fundamentals-0.2.52.tar.gz:

Publisher: python-publish.yml on ccdexplorer/ccdexplorer-fundamentals

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ccdexplorer_fundamentals-0.2.52-py3-none-any.whl.

File metadata

File hashes

Hashes for ccdexplorer_fundamentals-0.2.52-py3-none-any.whl
Algorithm Hash digest
SHA256 3654adb194bbb9d1c981bfb86a7724e5c8a9bf3092f6951e772271cece4faa4b
MD5 bd2b4cb659de4a4457569470fa9712f3
BLAKE2b-256 11ea6466dfe405580ecf05d1f03c1d1071e266ba448e2c8c20d4aefd1a5df9fc

See more details on using hashes here.

Provenance

The following attestation bundles were made for ccdexplorer_fundamentals-0.2.52-py3-none-any.whl:

Publisher: python-publish.yml on ccdexplorer/ccdexplorer-fundamentals

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page