Skip to content

Commit

Permalink
fix: fixes needed for compatibility with chia-blockchain 2.4.4
Browse files Browse the repository at this point in the history
* Code and tool updates

* More code updates

* Update README.md

Co-authored-by: Matt Hauff <[email protected]>

* Minor fixes

---------

Co-authored-by: Matt Hauff <[email protected]>
  • Loading branch information
emlowe and Quexington authored Oct 28, 2024
1 parent 11434fc commit b3d697d
Show file tree
Hide file tree
Showing 31 changed files with 399 additions and 238 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/auto-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
- name: Setup Python
uses: Chia-Network/actions/setup-python@main
with:
python-version: '3'
python-version: "3"

- name: Install commitizen
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ensure-version-increment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ name: Check Version Increment
on:
pull_request:
branches:
- 'main'
- "main"

concurrency:
# SHA is added to the end if on `main` to let all main workflows run
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release-notes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Create release notes
on:
push:
tags:
- '**'
- "**"

permissions:
contents: write
Expand All @@ -27,7 +27,7 @@ jobs:
- name: Setup Python
uses: Chia-Network/actions/setup-python@main
with:
python-version: '3'
python-version: "3"

- name: Install commitizen
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
- stage
pull_request:
branches:
- '**'
- "**"

jobs:
test:
Expand All @@ -31,7 +31,7 @@ jobs:
- name: Setup Python
uses: Chia-Network/actions/setup-python@main
with:
python-version: '3.10'
python-version: "3.10"

- name: Create virtual environment
uses: Chia-Network/actions/create-venv@main
Expand Down
75 changes: 39 additions & 36 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,37 +1,40 @@
repos:
- hooks:
- id: end-of-file-fixer
- id: trailing-whitespace
repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
- hooks:
- id: flake8
repo: https://github.com/pycqa/flake8
rev: 6.1.0
- hooks:
- args:
- --profile
- black
id: isort
repo: https://github.com/pycqa/isort
rev: 5.12.0
- hooks:
- id: black
repo: https://github.com/psf/black
rev: 23.7.0
- hooks:
- entry: mypy
id: mypy
language: system
name: mypy
types:
- python
- pyi
repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.4.1
- hooks:
- id: commitizen
stages:
- commit-msg
repo: https://github.com/commitizen-tools/commitizen
rev: v2.27.1
- hooks:
- id: end-of-file-fixer
- id: trailing-whitespace
repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
- hooks:
- id: flake8
repo: https://github.com/pycqa/flake8
rev: 6.1.0
- hooks:
- args:
- --profile
- black
id: isort
repo: https://github.com/pycqa/isort
rev: 5.12.0
- hooks:
- id: black
repo: https://github.com/psf/black
rev: 23.7.0
- hooks:
- entry: mypy
id: mypy
language: system
name: mypy
pass_filenames: false
repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.11.1
- hooks:
- id: commitizen
stages:
- commit-msg
repo: https://github.com/commitizen-tools/commitizen
rev: v2.27.1
- hooks:
- id: prettier
types_or: [ini, json, toml, yaml, markdown]
repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.1.0
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@

### Fix

- update climate warehouse and ui parameter names
- update climate warehouse and ui parameter names
- add exit code for incorrect host configuration
- format host conditional
- require localhost unless running in explorer mode
Expand Down
91 changes: 47 additions & 44 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,49 +5,49 @@

This application can run in 4 modes, each providing a separate application with a distinct use case:

* **Chia Climate Tokenization**:
* Mode: Registry
* Use case: A registry would use this to tokenize carbon credits onto the Chia blockchain
* Port: 31312
* Application Name: climate-tokenization-chia
* *Only listens on localhost for connections from the [Climate Tokenization Engine](https://github.com/Chia-Network/Climate-Tokenization-Engine)*
* **Climate Explorer**:
* Mode: Explorer
* Use case: A registry (or interested observer) would use this to track all on-chain activity related to tokenized carbon credits
* Port: 31313
* Application Name: climate-explorer
* **Climate Token Driver**:
* Mode: Client
* Use case: A carbon token holder could use this in conjunction with the [Climate Wallet](https://github.com/Chia-Network/Climate-Wallet) to manage their tokenized carbon credits
* Port: 31314
* Application Name: climate-token-driver
* **Dev Mode (for developers only!)**:
* Mode: Dev
* Use case: Developers are able to test the software without having to communicate with the blockchain
* Port: 31999
* Application Name: Only available from source builds

When compiling from source, the "mode" is controlled by the `.env` file. Each application, or mode, is offered as precompiled binaries, appropriate for most users.
- **Chia Climate Tokenization**:
- Mode: Registry
- Use case: A registry would use this to tokenize carbon credits onto the Chia blockchain
- Port: 31312
- Application Name: climate-tokenization-chia
- Only listens on localhost for connections from the [Climate Tokenization Engine](https://github.com/Chia-Network/Climate-Tokenization-Engine)
- **Climate Explorer**:
- Mode: Explorer
- Use case: A registry (or interested observer) would use this to track all on-chain activity related to tokenized carbon credits
- Port: 31313
- Application Name: climate-explorer
- **Climate Token Driver**:
- Mode: Client
- Use case: A carbon token holder could use this in conjunction with the [Climate Wallet](https://github.com/Chia-Network/Climate-Wallet) to manage their tokenized carbon credits
- Port: 31314
- Application Name: climate-token-driver
- **Dev Mode (for developers only!)**:
- Mode: Dev
- Use case: Developers are able to test the software without having to communicate with the blockchain
- Port: 31999
- Application Name: Only available from source builds

When compiling from source, the "mode" is controlled by the `.env` file. Each application, or mode, is offered as precompiled binaries, appropriate for most users.

## Related Projects

* [Chia Blockchain](https://github.com/Chia-Network/chia-blockchain)
* [Climate Tokenization Engine](https://github.com/Chia-Network/Climate-Tokenization-Engine)
* [Climate Tokenization Engine User Interface](https://github.com/Chia-Network/Climate-Tokenization-Engine-UI)
* [Climate Explorer UI](https://github.com/Chia-Network/climate-explorer-ui)
* [Climate Wallet](https://github.com/Chia-Network/Climate-Wallet)
* [Climate Action Data Trust](https://github.com/Chia-Network/cadt)
* [Climate Action Data Trust UI](https://github.com/Chia-Network/cadt-ui)
- [Chia Blockchain](https://github.com/Chia-Network/chia-blockchain)
- [Climate Tokenization Engine](https://github.com/Chia-Network/Climate-Tokenization-Engine)
- [Climate Tokenization Engine User Interface](https://github.com/Chia-Network/Climate-Tokenization-Engine-UI)
- [Climate Explorer UI](https://github.com/Chia-Network/climate-explorer-ui)
- [Climate Wallet](https://github.com/Chia-Network/Climate-Wallet)
- [Climate Action Data Trust](https://github.com/Chia-Network/cadt)
- [Climate Action Data Trust UI](https://github.com/Chia-Network/cadt-ui)

## Hierarchy

- `app`:
- `api`: API layer implementations
- `core`: service layer implementations
- `crud`: repository layer implementations
- `db`: database utilities
- `models`: database models
- `schemas`: schemas shared by all the layers
- `api`: API layer implementations
- `core`: service layer implementations
- `crud`: repository layer implementations
- `db`: database utilities
- `models`: database models
- `schemas`: schemas shared by all the layers
- `tests`: pytest suites

## Installation and configuration
Expand All @@ -56,7 +56,7 @@ Precompiled executables are available for Mac, Windows, and Linux (both ARM and

### Debian-based Linux Distros

For users of Debian, Ubuntu, Mint, PopOS, and other Debian-based distributions, a .deb file is provided on the [releases](https://github.com/Chia-Network/climate-token-driver/releases) page. This can be installed with
For users of Debian, Ubuntu, Mint, PopOS, and other Debian-based distributions, a .deb file is provided on the [releases](https://github.com/Chia-Network/climate-token-driver/releases) page. This can be installed with

```sh
dpkg -i package-filename.deb
Expand Down Expand Up @@ -97,7 +97,8 @@ sudo apt-get install climate-explorer-chia
sudo systemctl start climate-tokenization-chia@<USERNAME>
sudo systemctl start climate-explorer-chia@<USERNAME>
```
For `<USERNAME>`, enter the user that Chia runs as (the user with the `.chia` directory in their home directory). For example, if the `ubuntu` is where Chia runs, start Chia Climate Tokenization with `systemctl start climate-tokenization-chia@ubuntu`.

For `<USERNAME>`, enter the user that Chia runs as (the user with the `.chia` directory in their home directory). For example, if the `ubuntu` is where Chia runs, start Chia Climate Tokenization with `systemctl start climate-tokenization-chia@ubuntu`.

6. Set the Chia Climate Tokenization and Climate Explorer to run at boot

Expand All @@ -106,7 +107,6 @@ sudo systemctl enable climate-tokenization-chia@<USERNAME>
sudo systemctl enable climate-explorer-chia@<USERNAME>
```


### From Source

- Clone this repo.
Expand Down Expand Up @@ -139,7 +139,8 @@ sudo systemctl enable climate-explorer-chia@<USERNAME>
## Configurations

Note there are two steps the application loads the configurations:
1. The application will first look for any environment variables set on the host machine for `MODE`, `CHIA_ROOT`, and `CONFIG_PATH`. Any variables not set on the host system will be loaded from the `.env` environment file, which is opened via `python-dotenv`, where `${CHIA_ROOT}` and `${CONFIG_PATH}` are pre-loaded. This file is not visible to end users in packaged binaries, and are suitable for binary builders to change the default *flavor* for the binary (though it is overridden by system environment variables).

1. The application will first look for any environment variables set on the host machine for `MODE`, `CHIA_ROOT`, and `CONFIG_PATH`. Any variables not set on the host system will be loaded from the `.env` environment file, which is opened via `python-dotenv`, where `${CHIA_ROOT}` and `${CONFIG_PATH}` are pre-loaded. This file is not visible to end users in packaged binaries, and are suitable for binary builders to change the default _flavor_ for the binary (though it is overridden by system environment variables).

1. Then, a `config.yaml` file located at `${CHIA_ROOT}/${CONFIG_PATH}` is loaded, which adds to the configurations after `.env`.
This part of the configuration is free to change by end binary users.
Expand Down Expand Up @@ -175,7 +176,7 @@ As with `registry` mode, `client` mode is only designed to integrate with other

Only when in `explorer` mode, the following configurations are relevant:

- `CLIMATE_EXPLORER_SERVER_HOST`: Network interface to bind the climate explorer to. Default is `0.0.0.0` as the Climate Explorer is intended to be a publicly available interface. Can be set to `127.0.0.1` to be privately available only on localhost.
- `CLIMATE_EXPLORER_SERVER_HOST`: Network interface to bind the climate explorer to. Default is `0.0.0.0` as the Climate Explorer is intended to be a publicly available interface. Can be set to `127.0.0.1` to be privately available only on localhost.
- `CLIMATE_EXPLORER_PORT`: 31313 by default.
- `DB_PATH`: the database this application writes to, relative to `${CHIA_ROOT}`.
- `BLOCK_START`: the block to start scanning for climate token activities.
Expand Down Expand Up @@ -223,15 +224,18 @@ Only when in `explorer` mode, the following configurations are relevant:
# first ensure the `MODE` is set to the `dev` for all tests to be discoverable, then
python -m pytest ./tests
```

### Commiting

[Signed commits](https://docs.github.com/en/authentication/managing-commit-signature-verification/signing-commits) are required.

​This repo uses a [commit convention](https://www.conventionalcommits.org/en/v1.0.0/). A typical commit message might read:

```
fix: correct home screen layout
```

The first part of this is the commit "type". The most common types are "feat" for new features, and "fix" for bugfixes. Using these commit types helps us correctly manage our version numbers and changelogs. Since our release process calculates new version numbers from our commits it is very important to get this right.
Expand All @@ -250,10 +254,9 @@ The first part of this is the commit "type". The most common types are "feat" fo
After the type and scope there should be a colon.
The "subject" of the commit follows. It should be a short indication of the change. The commit convention prefers that this is written in the present-imperative tense.
#### Branch Layout
All pull requests should be made against the `develop` branch. Commits to the `main` branch will trigger a release, so the `main` branch is always the code in the latest release.
All pull requests should be made against the `develop` branch. Commits to the `main` branch will trigger a release, so the `main` branch is always the code in the latest release.
26 changes: 14 additions & 12 deletions app/api/v1/activities.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@

router = APIRouter()


@router.get("/", response_model=schemas.ActivitiesResponse)
@disallow([ExecutionMode.REGISTRY, ExecutionMode.CLIENT])
@disallow([ExecutionMode.REGISTRY, ExecutionMode.CLIENT]) # type: ignore[misc]
async def get_activity(
search: Optional[str] = None,
search_by: Optional[schemas.ActivitySearchBy] = None,
Expand Down Expand Up @@ -129,12 +130,12 @@ async def get_activity(


@router.get("/activity-record", response_model=schemas.ActivityRecordResponse)
@disallow([ExecutionMode.REGISTRY, ExecutionMode.CLIENT])
@disallow([ExecutionMode.REGISTRY, ExecutionMode.CLIENT]) # type: ignore[misc]
async def get_activity_by_cw_unit_id(
cw_unit_id: str,
coin_id: str,
action_mode: str,
db: Session = Depends(deps.get_db_session),
cw_unit_id: str,
coin_id: str,
action_mode: str,
db: Session = Depends(deps.get_db_session),
) -> schemas.ActivityRecordResponse:
"""Get a single activity based on the unit's unitWarehouseId.
Expand All @@ -143,7 +144,6 @@ async def get_activity_by_cw_unit_id(

db_crud = crud.DBCrud(db=db)


# fetch unit and related data from CADT
cw_filters: Dict[str, str] = {"warehouseUnitId": cw_unit_id}

Expand All @@ -162,13 +162,13 @@ async def get_activity_by_cw_unit_id(
if unit_with_metadata["marketplaceIdentifier"]:
activity_filters["and"].append(models.Activity.asset_id == unit_with_metadata["marketplaceIdentifier"])
else:
logger.warning(f"retrieved unit does not contain marketplace identifier. unable to get activity record")
logger.warning("retrieved unit does not contain marketplace identifier. unable to get activity record")
return schemas.ActivityRecordResponse()

activity_filters["and"].append(models.Activity.mode == action_mode)
activity_filters["and"].append(models.Activity.coin_id == coin_id)

activities: [models.Activity]
activities = [models.Activity]
total: int

# fetch activities with filters, 'total' var ignored
Expand All @@ -182,11 +182,13 @@ async def get_activity_by_cw_unit_id(
return schemas.ActivityRecordResponse()

try:
activity = next((activity for activity in activities if activity.coin_id == coin_id and activity.mode == action_mode), None)
activity = next(
(activity for activity in activities if activity.coin_id == coin_id and activity.mode == action_mode), None
)
if activity is None:
return schemas.ActivityRecordResponse()
except:
logger.warning(f"an exception occurred while processing activity record")
except Exception:
logger.warning("an exception occurred while processing activity record")
return schemas.ActivityRecordResponse()

unit_with_metadata = unit_with_metadata.copy()
Expand Down
2 changes: 1 addition & 1 deletion app/api/v1/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from fastapi import APIRouter

from app.api.v1 import activities, cron, keys, tokens, transactions, organizations
from app.api.v1 import activities, cron, keys, organizations, tokens, transactions

router = APIRouter(
prefix="/v1",
Expand Down
Loading

0 comments on commit b3d697d

Please sign in to comment.