Skip to content

Commit 7969d51

Browse files
authored
Add Web4/DHT domain resolution methods (#15)
- Add resolveWeb4ViaDht() for DHT-based domain resolution - Add getContractFromDht() to retrieve contracts from DHT storage - Improve getContractByHash() with JSDoc and proper return type These methods support Web4/dApp functionality once the ZHTP node implements the corresponding endpoints (blocked by node Issue #113). Endpoints: - GET /api/v1/dht/web4/resolve/{domain} - GET /api/v1/dht/contract/{contractId} - GET /api/v1/blockchain/contract/{hash} Fixes #9
1 parent 5e33c29 commit 7969d51

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

src/core/zhtp-api-methods.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -557,8 +557,12 @@ export abstract class ZhtpApiMethods extends ZhtpApiCore {
557557
return this.request<any>(endpoint);
558558
}
559559

560-
async getContractByHash(hash: string): Promise<any> {
561-
return this.request<any>(`/api/v1/blockchain/contract/${hash}`);
560+
/**
561+
* Lookup contract by blockchain transaction hash
562+
* @param hash - Deployment transaction hash
563+
*/
564+
async getContractByHash(hash: string): Promise<SmartContract> {
565+
return this.request<SmartContract>(`/api/v1/blockchain/contract/${hash}`);
562566
}
563567

564568
async getContractById(contractId: string): Promise<SmartContract> {
@@ -569,6 +573,22 @@ export abstract class ZhtpApiMethods extends ZhtpApiCore {
569573
return this.request<DApp>(`/api/v1/web4/resolve/${encodeURIComponent(domainName)}`);
570574
}
571575

576+
/**
577+
* Resolve Web4 domain via DHT network
578+
* @param domain - Domain name (e.g., "example.zhtp")
579+
*/
580+
async resolveWeb4ViaDht(domain: string): Promise<DApp> {
581+
return this.request<DApp>(`/api/v1/dht/web4/resolve/${encodeURIComponent(domain)}`);
582+
}
583+
584+
/**
585+
* Get contract from DHT distributed storage
586+
* @param contractId - Contract identifier
587+
*/
588+
async getContractFromDht(contractId: string): Promise<SmartContract> {
589+
return this.request<SmartContract>(`/api/v1/dht/contract/${contractId}`);
590+
}
591+
572592
// ==================== Blockchain Operations ====================
573593

574594
async getBlockchainInfo(): Promise<any> {

0 commit comments

Comments
 (0)