diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..581a776 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,56 @@ +# Contributing to pyfragment + +## Development setup + +```bash +git clone https://github.com/bohd4nx/pyfragment.git +cd pyfragment +pip install -e ".[dev]" +``` + +## Running checks + +```bash +# Lint and format +ruff check . --fix && ruff format . + +# Type check +mypy . --explicit-package-bases + +# Tests +pytest +``` + +All three must pass before opening a PR. + +## Project structure + +``` +pyfragment/ + client.py — FragmentClient (public entry point) + core/ — transport, cookies, constants + domains/ — one package per feature domain + ads/ — recharge_ads, topup_ton + anonymous_numbers/— buy_number, manage_number + giveaways/ — giveaway_stars, giveaway_premium + marketplace/ — search_usernames, search_numbers, search_gifts + purchases/ — purchase_stars, purchase_premium + tonapi/ — wallet info, transaction signing + models/ — result dataclasses and enums + exceptions.py — exception hierarchy +tests/ — unit tests (pytest) +examples/ — runnable usage examples (excluded from CI) +``` + +## Conventions + +- All public async methods live on `FragmentClient` and delegate to a domain service. +- Domain functions receive a `FragmentClient` instance, never raw httpx clients. +- Patch targets in tests use the module where the name is **defined**, e.g. `pyfragment.domains.tonapi.transaction.process_transaction`. +- Versioning follows [CalVer](https://calver.org/): `YYYY.MINOR.MICRO`. Bump in `pyproject.toml`; tag as `vYYYY.MINOR.MICRO`. + +## Pull requests + +- Keep PRs focused — one feature or fix per PR. +- Update `CHANGELOG.md` under `[Unreleased]`. +- Add or update tests for any changed behaviour. diff --git a/README.md b/README.md index 06c13d1..3a7d969 100644 --- a/README.md +++ b/README.md @@ -39,13 +39,13 @@ Requires Python 3.10+. ## Configuration -| Parameter | Type | Default | Description | -| ---------------- | ------------- | -------- | -------------------------------------------------------- | -| `seed` | `str` | — | 24-word TON wallet mnemonic | -| `api_key` | `str` | — | Tonapi key from [tonconsole.com](https://tonconsole.com) | -| `cookies` | `dict \| str` | — | Fragment session cookies | -| `wallet_version` | `str` | `"V5R1"` | `"V4R2"` or `"V5R1"` | -| `timeout` | `float` | `30.0` | HTTP request timeout in seconds | +| Parameter | Type | Default | Description | +| ---------------- | ------------- | -------- | ----------------------------------------------------------- | +| `seed` | `str` | — | 12-, 18-, or 24-word TON wallet mnemonic | +| `api_key` | `str` | — | Tonapi key from [tonconsole.com](https://tonconsole.com) | +| `cookies` | `dict \| str` | — | Fragment session cookies | +| `wallet_version` | `str` | `"V5R1"` | `"V4R2"` or `"V5R1"` (also accepts `WalletVersion` literal) | +| `timeout` | `float` | `30.0` | HTTP request timeout in seconds | --- @@ -128,12 +128,41 @@ Full runnable examples: - https://github.com/bohd4nx/pyfragment/tree/master/examples +--- + +## Error Handling + +All exceptions inherit from `FragmentError`. Catch specific ones or the base class: + +```python +from pyfragment import ( + ConfigurationError, # invalid arguments (amount, months, payment_method, etc.) + UserNotFoundError, # recipient not found on Fragment + WalletError, # insufficient TON/USDT balance + TransactionError, # broadcast failed, duplicate seqno, invalid payload + FragmentAPIError, # Fragment API returned an error response + FragmentPageError, # page fetch or hash extraction failed + AnonymousNumberError, # number not owned, wrong state, login code issues + CookieError, # missing or malformed session cookies + ParseError, # failed to decode Fragment payload + VerificationError, # on-chain verification step failed + OperationError, # generic operation-level failure + UnexpectedError, # unexpected API response structure +) +``` + Payload debug/decode helper (thanks): - https://ton-cell-abi-viewer.vercel.app/ --- +## Changelog + +See [CHANGELOG.md](https://github.com/bohd4nx/pyfragment/blob/master/CHANGELOG.md) for release history. + +--- +