From fc8dbfa4120b84702e398c5912a681faa25231f1 Mon Sep 17 00:00:00 2001 From: supertramp Date: Thu, 4 Dec 2025 14:53:09 +0000 Subject: [PATCH] Fix DAO method paths to match node implementation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixed 7 DAO method issues to match actual node endpoints: 1. getDaoTreasury: /treasury/balance → /treasury/status - Updated response parsing to treasury.total_balance 2. getTreasuryHistory: /treasury/history → /treasury/transactions - Added limit/offset query parameter support - Updated response parsing to transactions array 3. createProposal: /dao/proposals → /dao/proposal/create - Fixed singular 'proposal' path 4. getProposalDetails: /dao/proposals/{id} → /dao/proposal/{id} - Fixed singular 'proposal' path 5. submitVote: Updated request body format - Changed to voter_identity_id, proposal_id, vote_choice - Added support for yes/no/abstain and justification 6. registerDelegate: Fixed request body field names - Changed userDid → user_did - Changed delegateInfo → delegate_info 7. revokeDelegation: Fixed request body field name - Changed userDid → user_did All paths now match node's dao/mod.rs implementation (lines 957-1029) --- dist/core/zhtp-api-methods.d.ts | 9 ++++--- dist/core/zhtp-api-methods.d.ts.map | 2 +- dist/core/zhtp-api-methods.js | 37 +++++++++++++++++++---------- dist/core/zhtp-api-methods.js.map | 2 +- src/core/zhtp-api-methods.ts | 36 ++++++++++++++++++---------- 5 files changed, 57 insertions(+), 29 deletions(-) diff --git a/dist/core/zhtp-api-methods.d.ts b/dist/core/zhtp-api-methods.d.ts index bfdc8a4..9b2ad1d 100644 --- a/dist/core/zhtp-api-methods.d.ts +++ b/dist/core/zhtp-api-methods.d.ts @@ -125,15 +125,18 @@ export declare abstract class ZhtpApiMethods extends ZhtpApiCore { getDaoProposals(): Promise; getDaoStats(): Promise; createProposal(proposal: any): Promise; - submitVote(proposalId: string, vote: boolean, voterDid: string): Promise; + submitVote(voterIdentityId: string, proposalId: string, voteChoice: 'yes' | 'no' | 'abstain', justification?: string): Promise; getDaoTreasury(): Promise; getProposalDetails(proposalId: string): Promise; getDaoData(): Promise>; getDaoDelegates(): Promise; getDelegateProfile(delegateId: string): Promise; - registerDelegate(userDid: string, delegateInfo: Record): Promise; + registerDelegate(userDid: string, delegateInfo: { + name: string; + bio: string; + }): Promise; revokeDelegation(userDid: string): Promise; - getTreasuryHistory(): Promise; + getTreasuryHistory(limit?: number, offset?: number): Promise; createSpendingProposal(proposalData: Record): Promise; getVotingPower(userDid: string): Promise; getUserVotes(userDid: string): Promise { - return this.request('/api/v1/dao/proposals', { + return this.request('/api/v1/dao/proposal/create', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(proposal), @@ -566,24 +566,30 @@ export abstract class ZhtpApiMethods extends ZhtpApiCore { } async submitVote( + voterIdentityId: string, proposalId: string, - vote: boolean, - voterDid: string + voteChoice: 'yes' | 'no' | 'abstain', + justification?: string ): Promise { await this.request('/api/v1/dao/vote/cast', { method: 'POST', headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ proposalId, vote, voterDid }), + body: JSON.stringify({ + voter_identity_id: voterIdentityId, + proposal_id: proposalId, + vote_choice: voteChoice, + justification + }), }); } async getDaoTreasury(): Promise { - const response = await this.request('/api/v1/dao/treasury/balance'); - return response?.balance || 0; + const response = await this.request('/api/v1/dao/treasury/status'); + return response?.treasury?.total_balance || 0; } async getProposalDetails(proposalId: string): Promise { - return this.request(`/api/v1/dao/proposals/${proposalId}`); + return this.request(`/api/v1/dao/proposal/${proposalId}`); } async getDaoData(): Promise> { @@ -598,11 +604,11 @@ export abstract class ZhtpApiMethods extends ZhtpApiCore { return this.request(`/api/v1/dao/delegates/${delegateId}`); } - async registerDelegate(userDid: string, delegateInfo: Record): Promise { + async registerDelegate(userDid: string, delegateInfo: { name: string; bio: string }): Promise { return this.request('/api/v1/dao/delegates/register', { method: 'POST', headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ userDid, delegateInfo }), + body: JSON.stringify({ user_did: userDid, delegate_info: delegateInfo }), }); } @@ -610,12 +616,18 @@ export abstract class ZhtpApiMethods extends ZhtpApiCore { await this.request('/api/v1/dao/delegates/revoke', { method: 'POST', headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ userDid }), + body: JSON.stringify({ user_did: userDid }), }); } - async getTreasuryHistory(): Promise { - return this.request('/api/v1/dao/treasury/history'); + async getTreasuryHistory(limit?: number, offset?: number): Promise { + const params = new URLSearchParams(); + if (limit) params.append('limit', limit.toString()); + if (offset) params.append('offset', offset.toString()); + const queryString = params.toString(); + const url = `/api/v1/dao/treasury/transactions${queryString ? '?' + queryString : ''}`; + const response = await this.request(url); + return response?.transactions || []; } async createSpendingProposal(proposalData: Record): Promise {