diff --git a/.github/scripts/codegen-check.sh b/.github/scripts/codegen-check.sh index 6bf43e0..d69152e 100644 --- a/.github/scripts/codegen-check.sh +++ b/.github/scripts/codegen-check.sh @@ -2,12 +2,12 @@ # # CI artifact — not part of the SDK. # -# Renders the .trix/client-lib codegen plugin against the shared transfer +# Renders tx3c's built-in `python-client` template against the shared transfer # fixture and verifies the result the way a consumer would: the rendered module # is imported in a fresh venv with the dependencies its generated # requirements.txt pins installed — no editable install of the SDK source tree. # -# Requires `tx3c` and `python` on PATH. +# Requires `tx3c` (0.24.0 or later, which ships the built-in templates) and `python` on PATH. # Last verified against fleet v0.12.0 (unified Tx3ClientBuilder). set -euo pipefail @@ -17,7 +17,7 @@ trap 'rm -rf "$gen"' EXIT tx3c codegen \ --tii "$repo_root/sdk/tests/fixtures/transfer.tii" \ - --template "$repo_root/.trix/client-lib" \ + --template python-client \ --output "$gen" for f in __init__.py requirements.txt; do diff --git a/.trix/client-lib/README.md.hbs b/.trix/client-lib/README.md.hbs deleted file mode 100644 index 2082b95..0000000 --- a/.trix/client-lib/README.md.hbs +++ /dev/null @@ -1,27 +0,0 @@ -# {{tii.protocol.name}} — Python client - -Generated by `trix codegen` from the `{{tii.protocol.name}}@{{tii.protocol.version}}` protocol interface. Do not edit by hand — re-run `trix codegen` to refresh. - -## Install the runtime SDK - -The generated client delegates transport, signing, and lifecycle to `tx3-sdk`: - -```sh -pip install tx3-sdk -``` - -If you also need a local dev runtime, `trix devnet` exposes a TRP endpoint at `http://localhost:8164`. - -## Use the client - -```python -from tx3_sdk import ClientOptions, Party -from {{tii.protocol.name}} import Client, Profile - -client = Client( - ClientOptions(endpoint="http://localhost:8164"), - Profile.LOCAL, -) -``` - -Each `tx` declared by the protocol becomes a typed method on `client`, returning the `resolve → sign → submit → wait` lifecycle. See the [Tx3 consuming guide](https://docs.txpipe.io/tx3/consuming/quick-start) for the full walkthrough. diff --git a/.trix/client-lib/__init__.py.hbs b/.trix/client-lib/__init__.py.hbs deleted file mode 100644 index f25934c..0000000 --- a/.trix/client-lib/__init__.py.hbs +++ /dev/null @@ -1,132 +0,0 @@ -# This file is auto-generated by trix codegen. -# Target TII version: {{tii.tii.version}} - -from __future__ import annotations - -import json -from dataclasses import dataclass -from enum import Enum -from typing import Any - -from tx3_sdk import ( - Party, - Profile as SdkProfile, - Tx3Client, - Tx3ClientBuilder, -) -from tx3_sdk.core.bytes import TirEnvelope -from tx3_sdk.facade.builder import TxBuilder -from tx3_sdk.trp.client import ClientOptions - -PROTOCOL_NAME = "{{tii.protocol.name}}" -PROTOCOL_VERSION = "{{tii.protocol.version}}" -TARGET_TII_VERSION = "{{tii.tii.version}}" - -{{#if tii.environment}} -# JSON Schema of the protocol environment, embedded verbatim from the TII. -ENVIRONMENT_SCHEMA: dict[str, Any] = json.loads( - """{{{json tii.environment}}}""" -) - -{{/if}} -{{#if tii.components.schemas}} -# Named types for the protocol's custom (record / variant) types. -{{{componentTypes tii.components.schemas "python"}}} - -{{/if}} -{{#each tii.transactions}} -{{constantCase @key}}_TIR = TirEnvelope( - content="{{tir.content}}", - encoding="{{tir.encoding}}", - version="{{tir.version}}", -) - -@dataclass -class {{pascalCase @key}}Params: - """Arguments for the {{@key}} transaction.""" - -{{#each params.properties}} - {{snakeCase @key}}: {{schemaTypeFor this "python"}} -{{/each}} - - -{{/each}} -{{#if tii.profiles}} -{{#each tii.profiles}} -_{{constantCase @key}}_PROFILE = SdkProfile( - environment=json.loads("""{{{json this.environment}}}"""), - parties=json.loads("""{{{json this.parties}}}"""), -) -{{/each}} - - -class Profile(str, Enum): - """Profiles declared by the protocol. Required argument to `Client`.""" - -{{#each tii.profiles}} - {{constantCase @key}} = "{{@key}}" -{{/each}} - - -{{/if}} -class Client: - """Typed protocol client exposing the full transaction lifecycle. - - Wraps the runtime SDK's `Tx3Client` — all lifecycle state, party storage, - resolve/sign/submit/wait, and error handling live in the SDK. This wrapper - only adds the typed shape of per-transaction methods, per-party setters, - and the embedded protocol fragments. - """ - - def __init__( - self, - options: ClientOptions, -{{#if tii.profiles}} - profile: Profile, -{{/if}} - ) -> None: - transactions: dict[str, TirEnvelope] = { -{{#each tii.transactions}} - "{{@key}}": {{constantCase @key}}_TIR, -{{/each}} - } -{{#if tii.profiles}} - profiles: dict[str, SdkProfile] = { -{{#each tii.profiles}} - "{{@key}}": _{{constantCase @key}}_PROFILE, -{{/each}} - } -{{else}} - profiles: dict[str, SdkProfile] = {} -{{/if}} - - builder = Tx3ClientBuilder.from_parts(transactions, profiles, []) - builder = builder.trp(options) -{{#if tii.profiles}} - builder = builder.with_profile(profile.value) -{{/if}} - self._inner: Tx3Client = builder.build() - -{{#each tii.parties}} - def with_{{snakeCase @key}}(self, party: Party) -> "Client": - """Binds the `{{@key}}` party. Overrides any address declared for that - party by the selected profile. - """ - self._inner = self._inner.with_party_unchecked("{{@key}}", party) - return self - -{{/each}} -{{#each tii.transactions}} - def {{snakeCase @key}}(self, args: {{pascalCase @key}}Params) -> TxBuilder: - """Builds the `{{@key}}` transaction. Drive the returned builder with - `.resolve()` and the rest of the lifecycle chain. - """ - return self._inner.tx("{{@key}}").args( - { -{{#each params.properties}} - "{{@key}}": args.{{snakeCase @key}}, -{{/each}} - } - ) - -{{/each}} diff --git a/.trix/client-lib/requirements.txt.hbs b/.trix/client-lib/requirements.txt.hbs deleted file mode 100644 index e42e07b..0000000 --- a/.trix/client-lib/requirements.txt.hbs +++ /dev/null @@ -1,9 +0,0 @@ -anyio==4.9.0 -certifi==2025.4.26 -h11==0.16.0 -httpcore==1.0.9 -httpx==0.28.1 -idna==3.10 -sniffio==1.3.1 - -tx3-sdk>=0.15.0,<0.16.0