ncantu 3c212e56e9 api-anchorage: combine multiple UTXOs, api-relay: storage interface refactor
**Motivations:**
- Résoudre erreur "No UTXO large enough" en combinant plusieurs petits UTXOs
- Refactorer api-relay avec interface StorageServiceInterface pour meilleure abstraction
- Ajouter script restart-bitcoind.sh

**Root causes:**
- api-anchorage: logique cherchait uniquement un UTXO assez grand, ne combinait pas plusieurs petits UTXOs
- api-relay: code dupliqué entre StorageService et DatabaseStorageService

**Correctifs:**
- api-anchorage: combinaison automatique de plusieurs petits UTXOs si aucun assez grand, ajustement frais pour inputs multiples, limite 20 UTXOs, gestion cohérente verrouillage/déverrouillage

**Evolutions:**
- api-relay: StorageServiceInterface (abstraction commune), refactoring routes (keys, messages, signatures, metrics, bloom) pour utiliser interface, eslint config, package updates
- fixKnowledge: api-anchorage-combine-utxos.md (documentation correction)
- restart-bitcoind.sh: script redémarrage bitcoind

**Pages affectées:**
- api-anchorage: bitcoin-rpc.js
- api-relay: eslint.config.mjs, package.json, index.ts, middleware/auth.ts, routes (bloom, keys, messages, metrics, signatures), services (apiKeyService, database, relay, storageAdapter, storageInterface)
- fixKnowledge: api-anchorage-combine-utxos.md
- restart-bitcoind.sh
2026-01-28 07:50:56 +01:00

90 lines
2.0 KiB
TypeScript

import type {
StoredMessage,
StoredSignature,
StoredKey,
} from '../types/message.js';
import type { DatabaseStorageService } from './database.js';
import type { StorageServiceInterface } from './storageInterface.js';
/**
* Adapter to make DatabaseStorageService compatible with StorageServiceInterface.
* This allows existing code to work with the new database implementation.
*/
export class StorageAdapter implements StorageServiceInterface {
constructor(private db: DatabaseStorageService) {}
hasSeenHash(hash: string): boolean {
return this.db.hasSeenHash(hash);
}
markHashSeen(hash: string): void {
this.db.markHashSeen(hash);
}
storeMessage(msg: StoredMessage): void {
this.db.storeMessage(msg);
}
getMessage(hash: string): StoredMessage | undefined {
return this.db.getMessage(hash);
}
getMessages(
start: number,
end: number,
serviceUuid?: string,
): StoredMessage[] {
return this.db.getMessages(start, end, serviceUuid);
}
storeSignature(sig: StoredSignature): void {
this.db.storeSignature(sig);
}
getSignatures(hash: string): StoredSignature[] {
return this.db.getSignatures(hash);
}
storeKey(key: StoredKey): void {
this.db.storeKey(key);
}
getKeys(hash: string): StoredKey[] {
return this.db.getKeys(hash);
}
getKeysInWindow(start: number, end: number): StoredKey[] {
return this.db.getKeysInWindow(start, end);
}
getSeenHashCount(): number {
return this.db.getSeenHashCount();
}
getSeenHashes(): string[] {
return this.db.getSeenHashes();
}
getSignatureCount(): number {
return this.db.getSignatureCount();
}
getKeyCount(): number {
return this.db.getKeyCount();
}
/**
* No-op for compatibility (database handles persistence automatically).
*/
async saveToDisk(): Promise<void> {
// Database is already persistent, no need to save
}
/**
* No-op for compatibility.
*/
async initialize(): Promise<void> {
// Already initialized in database service
}
}