Skip to content

Commit

Permalink
Merge pull request #200 from Chia-Network/quex.wtf_tests
Browse files Browse the repository at this point in the history
[CHIA-1259] Update chia-blockchain to 2.4.3
  • Loading branch information
TheLastCicada authored Oct 18, 2024
2 parents 9774a02 + 8104d7d commit 3487b31
Show file tree
Hide file tree
Showing 15 changed files with 1,215 additions and 967 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
MODE="dev"
CHIA_ROOT="~/.chia/testnet10"
CONFIG_PATH="climate_token/config/config.yaml"
SERVER_PORT=31999
32 changes: 16 additions & 16 deletions .github/workflows/build-installers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ on:
branches:
- stage
tags:
- '**'
- "**"
pull_request:
branches:
- '**'
- "**"
workflow_dispatch: {}

concurrency:
Expand All @@ -32,22 +32,22 @@ jobs:
app-name: climate-tokenization-chia
app-mode: registry
app-description: "Carbon tokenization application on the Chia blockchain"
add-to-apt: 'true'
add-to-apt: "true"
- name: explorer
app-name: climate-explorer-chia
app-mode: explorer
app-description: "Interface for tracking Chia on-chain carbon tokens"
add-to-apt: 'true'
add-to-apt: "true"
- name: client
app-name: climate-token-driver
app-mode: client
app-description: "Embedded climate token driver for carbon tokens on the Chia blockchain"
add-to-apt: 'false'
add-to-apt: "false"
- name: dev
app-name: dev-token-driver-chia
app-mode: dev
app-description: "Token driver in dev mode"
add-to-apt: 'false'
add-to-apt: "false"

os:
- name: Linux
Expand All @@ -57,22 +57,22 @@ jobs:
arm: [Linux, ARM64]
intel: [ubuntu-latest]
artifact-os-name: linux
executable-extension: ''
executable-extension: ""
- name: macOS
matrix: macos
emoji: 🍎
runs-on:
arm: [macOS, ARM64]
intel: [macos-12]
artifact-os-name: macos
executable-extension: ''
executable-extension: ""
- name: Windows
matrix: windows
emoji: 🪟
runs-on:
intel: [windows-latest]
artifact-os-name: windows
executable-extension: '.exe'
executable-extension: ".exe"
arch:
- name: ARM
matrix: arm
Expand All @@ -86,9 +86,9 @@ jobs:
electron-builder-options: --x64
preconfiguration:
- name: default
cadt-api-server-host: 'https://observer.climateactiondata.org/api'
cadt-api-server-host: "https://observer.climateactiondata.org/api"
- name: testneta
cadt-api-server-host: 'https://chia-cadt-demo.chiamanaged.com/observer'
cadt-api-server-host: "https://chia-cadt-demo.chiamanaged.com/observer"
exclude:
- os:
matrix: windows
Expand All @@ -111,18 +111,19 @@ jobs:
- name: Checkout Code
uses: actions/checkout@v3
with:
submodules: 'recursive'
submodules: "recursive"

- name: Setup Python
uses: Chia-Network/actions/setup-python@main
with:
python-version: '3.10'
python-version: "3.10"

- name: Create .env file
run: |
echo "MODE=${{ matrix.config.app-mode }}" > .env
echo 'CHIA_ROOT="~/.chia/mainnet"' >> .env
echo 'CONFIG_PATH="climate_token/config/config.yaml"' >> .env
echo 'SERVER_PORT=31999' >> .env
- name: Apply preconfigurations
if: matrix.preconfiguration.name != 'default'
Expand Down Expand Up @@ -242,9 +243,9 @@ jobs:
- name: Create zip files for release
uses: thedoctor0/[email protected]
with:
type: 'zip'
type: "zip"
filename: ${{ matrix.config.app-name }}_${{ matrix.os.artifact-os-name }}_${{ steps.tag-name.outputs.TAGNAME || github.sha }}_${{ matrix.arch.artifact-name }}.zip
directory: 'artifacts'
directory: "artifacts"
if: startsWith(github.ref, 'refs/tags/') && matrix.preconfiguration.name == 'default'

- name: Release executable
Expand Down Expand Up @@ -275,7 +276,6 @@ jobs:
retention-days: 1
if: startsWith(github.ref, 'refs/tags/') && matrix.os.matrix == 'linux' && matrix.config.add-to-apt == 'true' && matrix.arch.name == 'Intel' && matrix.preconfiguration.name == 'default'


apt-upload:
name: Trigger update in apt repo
runs-on: ubuntu-latest
Expand Down
4 changes: 2 additions & 2 deletions app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Settings(BaseSettings):
MODE: ExecutionMode
CHIA_ROOT: Path = Path("~/.chia/mainnet")
CONFIG_PATH: Path = Path("climate_token/config/config.yaml")
SERVER_PORT: Optional[int]
SERVER_PORT: Optional[int] = 31999

# Visible configs: configurable through config.yaml
LOG_PATH: Path = Path("climate_token/log/debug.log")
Expand Down Expand Up @@ -67,7 +67,7 @@ def get_instance(cls) -> Settings:
cls._instance = get_settings()
return cls._instance

@root_validator
@root_validator(skip_on_failure=True)
def configure_port(cls, values: Dict[str, Any]) -> Dict[str, Any]:
if values["MODE"] == ExecutionMode.REGISTRY:
values["SERVER_PORT"] = values.get("CLIMATE_TOKEN_REGISTRY_PORT", ServerPort.CLIMATE_TOKEN_REGISTRY.value)
Expand Down
14 changes: 7 additions & 7 deletions app/core/chialisp/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

from typing import Optional, Tuple

from chia.types.announcement import Announcement
from chia.types.blockchain_format.coin import Coin
from chia.types.blockchain_format.program import Program
from chia.types.blockchain_format.sized_bytes import bytes32
from chia.types.coin_spend import CoinSpend
from chia.types.coin_spend import CoinSpend, make_spend
from chia.types.condition_opcodes import ConditionOpcode
from chia.wallet.conditions import CreateCoinAnnouncement

from app.core.chialisp.load_clvm import load_clvm_locally
from app.core.chialisp.tail import (
Expand Down Expand Up @@ -35,10 +35,10 @@ def create_gateway_solution(
def create_gateway_announcement(
coin: Coin,
conditions_program: Program,
) -> Announcement:
return Announcement(
origin_info=coin.name(),
message=conditions_program.get_tree_hash(),
) -> CreateCoinAnnouncement:
return CreateCoinAnnouncement(
coin_id=coin.name(),
msg=conditions_program.get_tree_hash(),
)


Expand Down Expand Up @@ -94,7 +94,7 @@ def parse_gateway_spend(
puzzle_hash: bytes32 = delegated_puzzle_mod.get_tree_hash()
raise ValueError(f"Invalid delegated puzzle with hash {puzzle_hash.hex()}")

tail_spend = CoinSpend(
tail_spend = make_spend(
coin=coin,
puzzle_reveal=tail_program,
solution=tail_solution,
Expand Down
25 changes: 12 additions & 13 deletions app/core/climate_wallet/wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
import time
from typing import Any, Dict, Iterator, List, Optional, Tuple, Union

from chia_rs import AugSchemeMPL, G1Element, G2Element, PrivateKey
from chia.consensus.constants import ConsensusConstants
from chia.rpc.full_node_rpc_client import FullNodeRpcClient
from chia.rpc.wallet_rpc_client import WalletRpcClient
from chia.types.blockchain_format.coin import Coin
from chia.types.blockchain_format.program import Program
from chia.types.blockchain_format.sized_bytes import bytes32
from chia.types.coin_record import CoinRecord
from chia.types.coin_spend import CoinSpend
from chia.types.coin_spend import CoinSpend, make_spend
from chia.types.spend_bundle import SpendBundle, estimate_fees
from chia.util.bech32m import bech32_decode, bech32_encode, convertbits
from chia.util.ints import uint32, uint64
Expand All @@ -29,6 +28,7 @@
from chia.wallet.util.compute_memos import compute_memos
from chia.wallet.util.tx_config import DEFAULT_TX_CONFIG
from chia.wallet.util.wallet_types import WalletType
from chia_rs import AugSchemeMPL, G1Element, G2Element, PrivateKey

from app.core.chialisp.gateway import create_gateway_puzzle, parse_gateway_spend
from app.core.chialisp.tail import create_delegated_puzzle, create_tail_program
Expand Down Expand Up @@ -137,7 +137,7 @@ def has_wallet_client(self) -> bool:
@property
def delegated_signatures(self) -> Dict[Tuple[bytes, bytes], G2Element]:
return {
(bytes(self.root_public_key), message): signature
(self.root_public_key, message): signature
for (
mode,
(message, signature),
Expand Down Expand Up @@ -224,12 +224,12 @@ async def _create_transaction(
aggregated_signature=signature,
)

transaction_records = await get_created_signed_transactions(
response = await get_created_signed_transactions(
transaction_request=transaction_request,
wallet_id=wallet_id,
wallet_client=self.wallet_client,
)
(first_transaction_record, *rest_transaction_records) = transaction_records
(first_transaction_record, *rest_transaction_records) = response.transactions
if first_transaction_record.spend_bundle is None:
raise ValueError("No spend bundle created!")
spend_bundle = SpendBundle.aggregate(
Expand Down Expand Up @@ -287,7 +287,6 @@ async def _create_client_transaction(
logger.info(f" - {key}: {value}")

transaction_request: TransactionRequest
transaction_records: List[TransactionRecord]

# this is a hack to get inner puzzle hash for `origin_coin`

Expand All @@ -302,15 +301,15 @@ async def _create_client_transaction(
],
fee=0,
)
transaction_records = await get_created_signed_transactions(
response = await get_created_signed_transactions(
transaction_request=transaction_request,
wallet_id=wallet_id,
wallet_client=self.wallet_client,
)
if len(transaction_records) != 1:
raise ValueError(f"Transaction record has unexpected length {len(transaction_records)}!")
if len(response.transactions) != 1:
raise ValueError(f"Transaction record has unexpected length {len(response.transactions)}!")

transaction_record = transaction_records[0]
transaction_record = response.transactions[0]
if transaction_record.spend_bundle is None:
raise ValueError("No spend bundle created!")
coin_spend: CoinSpend = transaction_record.spend_bundle.coin_spends[0]
Expand Down Expand Up @@ -355,7 +354,7 @@ async def send_tokenization_transaction(

gateway_secret_key: PrivateKey = self.mode_to_secret_key[mode]
gateway_public_key: G1Element = self.mode_to_public_key[mode]
public_key_to_secret_key = {bytes(gateway_public_key): gateway_secret_key}
public_key_to_secret_key = {gateway_public_key: gateway_secret_key}

coins: List[Coin] = await self.wallet_client.select_coins(
amount=amount + fee,
Expand Down Expand Up @@ -466,7 +465,7 @@ async def parse_detokenization_request(
if inner_puzzle != gateway_puzzle:
continue

inner_coin_spend = CoinSpend(
inner_coin_spend = make_spend(
coin=coin,
puzzle_reveal=inner_puzzle,
solution=inner_solution,
Expand Down Expand Up @@ -523,7 +522,7 @@ async def sign_and_send_detokenization_request(
raise ValueError("No public keys provided for the registry!")
gateway_secret_key: PrivateKey = self.mode_to_secret_key[mode]
gateway_public_key: G1Element = self.mode_to_public_key[mode]
public_key_to_secret_key = {bytes(gateway_public_key): gateway_secret_key}
public_key_to_secret_key = {gateway_public_key: gateway_secret_key}

(_, data) = bech32_decode(content, max_length=len(content))
if data is None:
Expand Down
8 changes: 4 additions & 4 deletions app/core/climate_wallet/wallet_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from typing import Any, Dict, List, Optional, Tuple

from chia_rs import AugSchemeMPL, G1Element, G2Element, PrivateKey
from chia.types.blockchain_format.coin import Coin
from chia.types.blockchain_format.program import INFINITE_COST, Program
from chia.types.blockchain_format.sized_bytes import bytes32
Expand All @@ -18,6 +17,7 @@
)
from chia.wallet.lineage_proof import LineageProof
from chia.wallet.payment import Payment
from chia_rs import AugSchemeMPL, G1Element, G2Element, PrivateKey

from app.core.chialisp.gateway import create_gateway_announcement, create_gateway_puzzle, create_gateway_solution
from app.core.chialisp.load_clvm import load_clvm_locally
Expand Down Expand Up @@ -141,8 +141,8 @@ def create_gateway_request_and_spend(
def create_gateway_signature(
coin_spend: CoinSpend,
agg_sig_additional_data: bytes,
public_key_to_secret_key: Optional[Dict[bytes, PrivateKey]] = None,
public_key_message_to_signature: Optional[Dict[Tuple[bytes, bytes], G2Element]] = None,
public_key_to_secret_key: Optional[Dict[G1Element, PrivateKey]] = None,
public_key_message_to_signature: Optional[Dict[Tuple[G1Element, bytes], G2Element]] = None,
allow_missing: bool = False,
) -> G2Element:
if public_key_to_secret_key is None:
Expand Down Expand Up @@ -176,7 +176,7 @@ def create_gateway_signature(
if allow_missing:
continue
else:
raise ValueError(f"Cannot sign for key {public_key.hex()} and message {message.hex()}")
raise ValueError(f"Cannot sign for key {bytes(public_key).hex()} and message {message.hex()}")

signatures.append(signature)

Expand Down
10 changes: 5 additions & 5 deletions app/core/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
import enum
from typing import Any, Dict, List, Optional

from chia.types.announcement import Announcement
from chia.types.blockchain_format.coin import Coin
from chia.types.blockchain_format.program import Program
from chia.types.blockchain_format.sized_bytes import bytes32
from chia.types.condition_opcodes import ConditionOpcode
from chia.wallet.conditions import CreateCoinAnnouncement, CreatePuzzleAnnouncement
from chia.wallet.payment import Payment

CLIMATE_WALLET_INDEX = 2
Expand Down Expand Up @@ -50,8 +50,8 @@ def name(self) -> bytes32:
class TransactionRequest(object):
coins: Optional[List[Coin]] = dataclasses.field(default=None)
payments: List[Payment] = dataclasses.field(default_factory=list)
coin_announcements: List[Announcement] = dataclasses.field(default_factory=list)
puzzle_announcements: List[Announcement] = dataclasses.field(default_factory=list)
coin_announcements: List[CreateCoinAnnouncement] = dataclasses.field(default_factory=list)
puzzle_announcements: List[CreatePuzzleAnnouncement] = dataclasses.field(default_factory=list)
fee: int = dataclasses.field(default=0)

def to_program(self) -> Program:
Expand All @@ -60,10 +60,10 @@ def to_program(self) -> Program:
conditions.append([ConditionOpcode.CREATE_COIN] + payment.as_condition_args())

for announcement in self.coin_announcements:
conditions.append([ConditionOpcode.ASSERT_COIN_ANNOUNCEMENT, announcement.name()])
conditions.append(announcement.to_program())

for announcement in self.puzzle_announcements:
conditions.append([ConditionOpcode.ASSERT_PUZZLE_ANNOUNCEMENT, announcement.name()])
conditions.append(announcement.to_program())

if self.fee:
conditions.append([ConditionOpcode.RESERVE_FEE, self.fee])
Expand Down
9 changes: 4 additions & 5 deletions app/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

from typing import Any, Dict, List, Optional

from chia_rs import G1Element, PrivateKey
from chia.consensus.constants import ConsensusConstants
from chia.consensus.constants import ConsensusConstants, replace_str_to_bytes
from chia.consensus.default_constants import DEFAULT_CONSTANTS
from chia.rpc.wallet_rpc_client import WalletRpcClient
from chia.types.blockchain_format.sized_bytes import bytes32
Expand All @@ -17,6 +16,7 @@
from chia.wallet.util.tx_config import DEFAULT_TX_CONFIG
from chia.wallet.util.wallet_types import WalletType
from chia.wallet.wallet_info import WalletInfo
from chia_rs import G1Element, PrivateKey

from app.core.derive_keys import master_sk_to_root_sk
from app.core.types import TransactionRequest
Expand All @@ -34,7 +34,7 @@ async def get_constants(
filename="config.yaml",
)
constant_overrides = config["network_overrides"]["constants"][network_name]
constants = DEFAULT_CONSTANTS.replace_str_to_bytes(**constant_overrides)
constants = replace_str_to_bytes(DEFAULT_CONSTANTS, **constant_overrides)

return constants

Expand Down Expand Up @@ -115,11 +115,10 @@ async def get_created_signed_transactions(
transaction_records = await wallet_client.create_signed_transactions(
coins=transaction_request.coins,
additions=transaction_request.additions,
coin_announcements=transaction_request.coin_announcements,
puzzle_announcements=transaction_request.puzzle_announcements,
fee=uint64(transaction_request.fee),
wallet_id=wallet_id,
tx_config=DEFAULT_TX_CONFIG,
extra_conditions=(*transaction_request.coin_announcements, *transaction_request.puzzle_announcements),
)

return transaction_records
Loading

0 comments on commit 3487b31

Please sign in to comment.