From 0f429884082fba8fa56540a8d4d1944df2dfed3d Mon Sep 17 00:00:00 2001 From: dev4 Date: Sat, 20 Sep 2025 22:15:02 +0000 Subject: [PATCH] =?UTF-8?q?docs:=20Documentation=20API=20Funds=20compl?= =?UTF-8?q?=C3=A8te?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Ajout de docs/API_FUNDS.md avec documentation complète - Problèmes résolus documentés (TypeScript, Docker, API 404) - Tests unitaires et d'intégration documentés - Configuration Docker socket et CLI documentée --- CHANGELOG.md | 12 +++++ docs/API_FUNDS.md | 118 +++++++++++++++++++++++++++++++++++++++------- 2 files changed, 114 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b1930e1..e5de7ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -61,6 +61,18 @@ - Récupération des rattachements via `sub` puis sélection d’un rattachement d’étude (office) si présent. - Objectif: permettre le login même si le JWT IdNot ne fournit pas `profile_idn`. +## v1.1.2 + +### 📚 Documentation +- **API Funds** : Ajout de `docs/API_FUNDS.md` avec documentation complète +- **Problèmes résolus** : Documentation des corrections TypeScript, Docker daemon access, API endpoint 404 +- **Tests** : Documentation des tests unitaires et d'intégration +- **Configuration** : Documentation de la configuration Docker socket et CLI + +### 🔧 Améliorations +- **Documentation** : Documentation complète de l'API funds et de son intégration +- **Configuration** : Documentation de la configuration requise pour Docker CLI + ## v1.1.1 ### 🚀 Nouvelles fonctionnalités diff --git a/docs/API_FUNDS.md b/docs/API_FUNDS.md index 2b94897..48b1753 100644 --- a/docs/API_FUNDS.md +++ b/docs/API_FUNDS.md @@ -1,25 +1,111 @@ -# API Funds - LeCoffre Back Mini +# API Funds - lecoffre-back-mini ## Endpoints disponibles -- `POST /api/v1/funds/transfer` : Transfert automatique de fonds -- `GET /api/v1/funds/check` : Vérification des fonds + +### POST /api/v1/funds/transfer +Transfère automatiquement des fonds du wallet mining vers le relay. + +**Paramètres :** +- `amount` (optionnel) : Montant à transférer en BTC (défaut: 0.01) +- `source` (optionnel) : Wallet source (défaut: 'mining_mnemonic') +- `target` (optionnel) : Wallet cible (défaut: 'default') + +**Réponse :** +```json +{ + "success": true, + "message": "Transfert de 0.01 BTC réussi", + "transactionId": "txid...", + "address": "address...", + "sourceBalance": 49.99998340, + "targetBalance": 0.02 +} +``` + +### GET /api/v1/funds/check +Vérifie les fonds du relay et du wallet mining. + +**Réponse :** +```json +{ + "success": true, + "relay": { + "outputsCount": 2, + "balance": 0.02 + }, + "mining": { + "balance": 49.99998340 + }, + "needsTransfer": false +} +``` ## Configuration requise -- Docker socket monté : `/var/run/docker.sock:/var/run/docker.sock` -- Accès au container `bitcoin-signet` -- Wallets Bitcoin : `mining_mnemonic` et `default` -## Transfert automatique -```bash -curl -X POST https://dev4.4nkweb.com/api/v1/funds/transfer \ - -H "Content-Type: application/json" \ - -d '{"amount": 0.01, "source": "mining_mnemonic", "target": "default"}' +### Docker Socket +Le service nécessite l'accès au Docker socket pour exécuter `bitcoin-cli` : +```yaml +volumes: + - /var/run/docker.sock:/var/run/docker.sock ``` -## Vérification des fonds -```bash -curl https://dev4.4nkweb.com/api/v1/funds/check +### Docker CLI +Le container inclut `docker-cli` pour interagir avec Bitcoin Core : +```dockerfile +RUN apk add --no-cache docker-cli ``` -## Date -2025-09-20 +## Intégration frontend + +### Détection automatique des fonds insuffisants +Le frontend (`ihm_client`) détecte automatiquement les fonds insuffisants et déclenche un transfert : + +```typescript +// Dans service.ts +if (insufficientFunds) { + await this.triggerAutomaticFundsTransfer(); +} +``` + +### API URL +L'API est accessible via Nginx sur : +- `https://dev4.4nkweb.com/api/v1/funds/transfer` +- `https://dev4.4nkweb.com/api/v1/funds/check` + +## Tests + +### Tests unitaires +```bash +npm run test:funds +``` + +### Tests d'intégration +```bash +npm run test:integration +``` + +## Problèmes résolus + +### 1. TypeScript compilation errors +**Problème :** Erreurs de compilation TypeScript dans `funds.routes.ts`. + +**Solution :** +- Ajout de `Promise` aux signatures de fonctions +- Correction du type `error` avec `instanceof Error` +- Ajout de `return;` après les réponses + +### 2. Docker daemon access +**Problème :** `Cannot connect to the Docker daemon`. + +**Solution :** Ajout du volume Docker socket dans `docker-compose.yml`. + +### 3. API endpoint 404 +**Problème :** L'endpoint `/api/v1/funds/transfer` retournait 404. + +**Solution :** +- Rebuild de l'image Docker +- Correction de l'URL dans le frontend +- Configuration Nginx pour `/api/v1/funds/` + +## Date de mise à jour +2025-01-20 - API funds implémentée et testée \ No newline at end of file