Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update chia-blockchain to 2.1.0, fix tests, and other updates #125

Merged
merged 49 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
0ea0fde
Merge pull request #106 from Chia-Network/develop
MichaelTaylor3D Oct 3, 2023
2f98220
chore: Updating changelog for 1.0.28
ChiaAutomation Oct 3, 2023
f9591a9
Merge pull request #109 from Chia-Network/develop
TheLastCicada Oct 5, 2023
1a7b8e7
chore: Updating changelog for 1.0.29
ChiaAutomation Oct 5, 2023
b9ca2b7
Merge pull request #116 from Chia-Network/develop
MichaelTaylor3D Oct 11, 2023
3199624
chore: Updating changelog for 1.0.30
ChiaAutomation Oct 11, 2023
712e47e
Merge pull request #119 from Chia-Network/develop
MichaelTaylor3D Oct 11, 2023
9f0e03c
chore: Updating changelog for 1.0.31
ChiaAutomation Oct 11, 2023
e7a016b
Merge pull request #121 from Chia-Network/develop
MichaelTaylor3D Oct 11, 2023
4bfe0f4
chore: Updating changelog for 1.0.32
ChiaAutomation Oct 11, 2023
1a2260d
Merge pull request #123 from Chia-Network/develop
MichaelTaylor3D Oct 12, 2023
0f3e4db
chore: Updating changelog for 1.0.33
ChiaAutomation Oct 12, 2023
3a1c49d
Update chia-blockchain to 2.1.0 and major updates to precommit and my…
emlowe Oct 17, 2023
cafa10f
Poetry updates
emlowe Oct 17, 2023
241a2a2
ci: add badge
TheLastCicada Oct 17, 2023
7b2f156
ci: add python tests
TheLastCicada Oct 17, 2023
60a0702
ci: make venv adjustments
TheLastCicada Oct 17, 2023
7fed2c6
ci: adjust testing venvs
TheLastCicada Oct 17, 2023
193eb09
ci: adjust venvs for testing
TheLastCicada Oct 17, 2023
05c0c15
ci: tests in ci venvs
TheLastCicada Oct 17, 2023
1269d7e
Update pytest.ini to ignore sqlalchemy error
emlowe Oct 18, 2023
e662cf6
Merge remote-tracking branch 'origin/develop' into EL.update-chia
emlowe Oct 23, 2023
98a559e
Update tests to not run TestActivities as a workaround
emlowe Oct 23, 2023
d0fbdc2
set MODE to dev for test run
emlowe Oct 23, 2023
2ff0f9c
setup env for tests
emlowe Oct 23, 2023
8162baf
setup env for tests
emlowe Oct 23, 2023
dc6ace4
Update tests.yaml
emlowe Oct 23, 2023
c1f0fcd
Update tests.yaml
emlowe Oct 23, 2023
25a7827
Update tests.yaml
emlowe Oct 23, 2023
9378bab
Update tests.yaml
emlowe Oct 23, 2023
939a4bc
Update tests.yaml
emlowe Oct 23, 2023
aaef395
Update tests.yaml
emlowe Oct 23, 2023
94e25cc
Update tests.yaml
emlowe Oct 23, 2023
b08956e
Update tests.yaml
emlowe Oct 23, 2023
2c15575
Update tests.yaml
emlowe Oct 23, 2023
9f0417d
Some general cleanup
emlowe Oct 23, 2023
961c729
mock code that required a running node
emlowe Oct 23, 2023
94419db
run all tests
emlowe Oct 23, 2023
d83b0ec
override anyio to earlier version for tests
emlowe Oct 23, 2023
1220308
workaround incompatability with anyio 4 and some test packages
emlowe Oct 23, 2023
608a80f
Add nft_wallet stuff to pyinstaller.spec
emlowe Oct 24, 2023
966ab8e
Add chia hidden imports to pyinstaller
emlowe Oct 24, 2023
c2d483b
Add bunch of logging to get_activity
emlowe Oct 30, 2023
ba72fc3
Some more logging
emlowe Oct 30, 2023
3a09166
print to stdout for now
emlowe Oct 30, 2023
862237a
pretty print the dicts
emlowe Oct 30, 2023
5dcf4be
Merge remote-tracking branch 'origin/develop' into EL.update-chia
emlowe Oct 31, 2023
4510b1d
Fix problem with wrong variable name
emlowe Nov 2, 2023
69e0e58
Remove very verbose logging
emlowe Nov 2, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[flake8]
max-line-length = 120
exclude = ./typings/**/*
ignore = E203,W503
per-file-ignores =
# line too long
tests/test_activities_api.py: E501
tests/test_crud_chia.py: E501
# imported but unused
app/api/v1/__init__.py: F401
21 changes: 7 additions & 14 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,20 @@ repos:
repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
- hooks:
- args:
- --in-place
- --remove-all-unused-imports
- --expand-star-imports
- --remove-duplicate-keys
- --remove-unused-variables
exclude: .*/__init__.py
id: autoflake
repo: https://github.com/myint/autoflake
rev: v1.4
- id: flake8
repo: https://github.com/pycqa/flake8
rev: 6.1.0
- hooks:
- args:
- --profile
- black
id: isort
repo: https://github.com/pre-commit/mirrors-isort
rev: v5.10.1
repo: https://github.com/pycqa/isort
rev: 5.12.0
- hooks:
- id: black
repo: https://github.com/psf/black
rev: 22.3.0
rev: 23.7.0
- hooks:
- entry: mypy
id: mypy
Expand All @@ -35,7 +28,7 @@ repos:
- python
- pyi
repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.961
rev: v1.4.1
- hooks:
- id: commitizen
stages:
Expand Down
29 changes: 29 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,32 @@
## 1.0.33 (2023-10-12)

### Fix

- add missing max coin amount in select coin call

## 1.0.32 (2023-10-11)

## 1.0.31 (2023-10-11)

## 1.0.30 (2023-10-11)

### Fix

- derivation roots

## 1.0.29 (2023-10-05)

### Fix

- update the default cadt api host

## 1.0.28 (2023-10-03)

### Fix

- rework wallet indexes
- update default CADT API in config

## 1.0.27 (2023-09-29)

### Fix
Expand Down
6 changes: 3 additions & 3 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and limitations under the License.



Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
Expand Down
3 changes: 0 additions & 3 deletions app/api/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ async def _get_rpc_client(
rpc_port: int,
root_path: Path = DEFAULT_ROOT_PATH,
) -> Iterator[RpcClient]:

rpc_client_cls = {
NodeType.FULL_NODE: FullNodeRpcClient,
NodeType.WALLET: WalletRpcClient,
Expand All @@ -63,7 +62,6 @@ async def _get_rpc_client(


async def get_wallet_rpc_client() -> Iterator[WalletRpcClient]:

async for _ in _get_rpc_client(
node_type=NodeType.WALLET,
self_hostname=settings.CHIA_HOSTNAME,
Expand All @@ -74,7 +72,6 @@ async def get_wallet_rpc_client() -> Iterator[WalletRpcClient]:


async def get_full_node_rpc_client() -> Iterator[FullNodeRpcClient]:

async for _ in _get_rpc_client(
node_type=NodeType.FULL_NODE,
self_hostname=settings.CHIA_HOSTNAME,
Expand Down
7 changes: 3 additions & 4 deletions app/api/v1/activities.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from sqlalchemy import desc, asc
from typing import Dict, List, Optional

from fastapi import APIRouter, Depends
Expand All @@ -25,7 +24,7 @@ async def get_activity(
mode: Optional[GatewayMode] = None,
page: int = 1,
limit: int = 10,
sort: str = 'desc',
sort: str = "desc",
db: Session = Depends(deps.get_db_session),
):
"""Get activity.
Expand Down Expand Up @@ -54,7 +53,7 @@ async def get_activity(
pass
case _:
raise ErrorCode().bad_request_error(message="search_by is invalid")

if minHeight is not None:
activity_filters["and"].append(models.Activity.height >= minHeight)

Expand All @@ -77,7 +76,7 @@ async def get_activity(
total: int

order_by_clause = []
if sort.lower() == 'desc':
if sort.lower() == "desc":
order_by_clause.append(models.Activity.height.desc())
order_by_clause.append(models.Activity.coin_id.desc())
else:
Expand Down
11 changes: 4 additions & 7 deletions app/api/v1/cron.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ async def _scan_token_activity(
climate_warehouse: crud.ClimateWareHouseCrud,
blockchain: crud.BlockChainCrud,
) -> bool:

state = db_crud.select_block_state_first()
if state.peak_height is None:
logger.warning("Full node state has not been retrieved.")
Expand Down Expand Up @@ -100,9 +99,7 @@ async def _scan_token_activity(

db_crud.batch_insert_ignore_activity(activities)

db_crud.update_block_state(
current_height=target_start_height
)
db_crud.update_block_state(current_height=target_start_height)
return True


Expand All @@ -118,9 +115,10 @@ async def scan_token_activity() -> None:
as_async_contextmanager(deps.get_db_session) as db,
as_async_contextmanager(deps.get_full_node_rpc_client) as full_node_client,
):

db_crud = crud.DBCrud(db=db)
climate_warehouse = crud.ClimateWareHouseCrud(url=settings.CADT_API_SERVER_HOST, api_key=settings.CADT_API_KEY)
climate_warehouse = crud.ClimateWareHouseCrud(
url=settings.CADT_API_SERVER_HOST, api_key=settings.CADT_API_KEY
)
blockchain = crud.BlockChainCrud(full_node_client=full_node_client)

try:
Expand Down Expand Up @@ -167,7 +165,6 @@ async def scan_blockchain_state() -> None:
as_async_contextmanager(deps.get_db_session) as db,
as_async_contextmanager(deps.get_full_node_rpc_client) as full_node_client,
):

db_crud = crud.DBCrud(db=db)

try:
Expand Down
7 changes: 3 additions & 4 deletions app/api/v1/keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from chia.types.blockchain_format.sized_bytes import bytes32
from chia.util.bech32m import decode_puzzle_hash, encode_puzzle_hash
from chia.util.byte_types import hexstr_to_bytes
from chia.util.ints import uint32
from chia.wallet.derive_keys import (
master_sk_to_wallet_sk,
master_sk_to_wallet_sk_unhardened,
Expand All @@ -31,7 +32,6 @@ async def get_key(
prefix: str = "bls1238",
wallet_rpc_client: WalletRpcClient = Depends(deps.get_wallet_rpc_client),
):

fingerprint: int = await wallet_rpc_client.get_logged_in_fingerprint()

result: Dict = await wallet_rpc_client.get_private_key(fingerprint)
Expand All @@ -40,10 +40,10 @@ async def get_key(

wallet_secret_key: PrivateKey
if hardened:
wallet_secret_key = master_sk_to_wallet_sk(secret_key, derivation_index)
wallet_secret_key = master_sk_to_wallet_sk(secret_key, uint32(derivation_index))
else:
wallet_secret_key = master_sk_to_wallet_sk_unhardened(
secret_key, derivation_index
secret_key, uint32(derivation_index)
)

wallet_public_key: G1Element = wallet_secret_key.get_g1()
Expand All @@ -63,7 +63,6 @@ async def get_key(
async def parse_key(
address: str,
):

try:
puzzle_hash: bytes = decode_puzzle_hash(address)
except ValueError:
Expand Down
39 changes: 23 additions & 16 deletions app/api/v1/tokens.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import json;

import json
from typing import Any, Dict, Tuple

from blspy import G1Element, G2Element
from chia.rpc.wallet_rpc_client import WalletRpcClient
from chia.types.blockchain_format.sized_bytes import bytes32
from chia.types.coin_spend import CoinSpend
from chia.types.spend_bundle import SpendBundle
from chia.util.byte_types import hexstr_to_bytes
Expand All @@ -15,8 +15,8 @@
from app.core import utils
from app.core.climate_wallet.wallet import ClimateWallet
from app.core.types import ClimateTokenIndex, GatewayMode
from app.utils import disallow
from app.logger import logger
from app.utils import disallow

router = APIRouter()

Expand All @@ -39,8 +39,8 @@ async def create_tokenization_tx(
wallet_client=wallet_rpc_client
)

token: schemas.Token = request.token
payment: schemas.Payment = request.payment
token = request.token
payment = request.payment

token_index = ClimateTokenIndex(
org_uid=token.org_uid,
Expand Down Expand Up @@ -68,6 +68,9 @@ async def create_tokenization_tx(
}

for mode in GatewayMode:
if wallet.mode_to_public_key is None:
raise ValueError("Wallet mode to public key is None!")

public_key: G1Element = wallet.mode_to_public_key[mode]

mod_hash: bytes
Expand Down Expand Up @@ -163,19 +166,19 @@ async def create_detokenization_file(
This endpoint is to be called by the client.
"""

token: schemas.TokenOnChain = request.token
payment: schemas.Payment = request.payment
token = request.token
payment = request.payment

token_index = ClimateTokenIndex(
org_uid=token.org_uid,
warehouse_project_id=token.warehouse_project_id,
vintage_year=token.vintage_year,
sequence_num=token.sequence_num,
)
tail_metadata: schemas.TailMetadataBase = token.detokenization
tail_metadata = token.detokenization

mode_to_public_key: Dict[GatewayMode, G1Element] = {
GatewayMode.DETOKENIZATION: tail_metadata.public_key,
GatewayMode.DETOKENIZATION: G1Element.from_bytes(tail_metadata.public_key),
}
mode_to_message_and_signature: Dict[GatewayMode, Tuple[bytes, G2Element]] = {
GatewayMode.DETOKENIZATION: (
Expand All @@ -187,7 +190,7 @@ async def create_detokenization_file(

wallet = ClimateWallet(
token_index=token_index,
root_public_key=token.public_key,
root_public_key=G1Element.from_bytes(token.public_key),
mode_to_public_key=mode_to_public_key,
mode_to_message_and_signature=mode_to_message_and_signature,
wallet_client=wallet_rpc_client,
Expand All @@ -198,9 +201,11 @@ async def create_detokenization_file(
raise ValueError(f"Asset id {asset_id} inconsistent with request body!")

cat_wallet_info = await utils.get_cat_wallet_info_by_asset_id(
asset_id=hexstr_to_bytes(asset_id),
asset_id=bytes32.from_hexstr(asset_id),
wallet_client=wallet_rpc_client,
)
if cat_wallet_info is None:
raise ValueError(f"Asset id {asset_id} not found in wallet!")

result: Dict = await wallet.create_detokenization_request(
amount=payment.amount,
Expand Down Expand Up @@ -270,7 +275,7 @@ async def create_permissionless_retirement_tx(
This endpoint is to be called by the client.
"""

token: schemas.TokenOnChain = request.token
token = request.token
payment: schemas.RetirementPaymentWithPayer = request.payment

token_index = ClimateTokenIndex(
Expand All @@ -279,7 +284,7 @@ async def create_permissionless_retirement_tx(
vintage_year=token.vintage_year,
sequence_num=token.sequence_num,
)
tail_metadata: schemas.TailMetadataBase = token.permissionless_retirement
tail_metadata = token.permissionless_retirement

mode_to_message_and_signature: Dict[GatewayMode, Tuple[bytes, G2Element]] = {
GatewayMode.PERMISSIONLESS_RETIREMENT: (
Expand All @@ -291,7 +296,7 @@ async def create_permissionless_retirement_tx(

wallet = ClimateWallet(
token_index=token_index,
root_public_key=token.public_key,
root_public_key=G1Element.from_bytes(token.public_key),
mode_to_message_and_signature=mode_to_message_and_signature,
wallet_client=wallet_rpc_client,
constants=constants,
Expand All @@ -301,15 +306,17 @@ async def create_permissionless_retirement_tx(
raise ValueError(f"Asset id {asset_id} inconsistent with request body!")

cat_wallet_info = await utils.get_cat_wallet_info_by_asset_id(
asset_id=hexstr_to_bytes(asset_id),
asset_id=bytes32.from_hexstr(asset_id),
wallet_client=wallet_rpc_client,
)
if cat_wallet_info is None:
raise ValueError(f"Asset id {asset_id} not found in wallet!")

# Create a dictionary with the variables you want to log
log_data = {
"amount": payment.amount,
"fee": payment.fee,
"wallet_id": cat_wallet_info.id
"wallet_id": cat_wallet_info.id,
}

# Convert the dictionary to a JSON-formatted string
Expand Down
Loading
Loading