add client

This commit is contained in:
liangping 2024-01-11 13:43:18 +08:00
parent 1354abdb5d
commit 73f36c64b4

View File

@ -20,12 +20,12 @@ export class BaseRestClient<R extends AbstractRegistry> {
this.endpoint = endpoint;
this.registry = registry;
}
async request<T>(request: Request<T>, args: Record<string, any>, query = '') {
async request<T>(request: Request<T>, args: Record<string, any>, query = '', adapter: (source: any) => T = undefined) {
let url = `${request.url.startsWith("http")?'':this.endpoint}${request.url}${query}`;
Object.keys(args).forEach((k) => {
url = url.replace(`{${k}}`, args[k] || '');
});
return fetchData<T>(url, request.adapter);
return fetchData<T>(url, adapter||request.adapter);
}
}
@ -161,7 +161,14 @@ export class CosmosRestClient extends BaseRestClient<RequestRegistry> {
return this.request(this.registry.gov_proposals_deposits, { proposal_id });
}
async getGovProposalTally(proposal_id: string) {
return this.request(this.registry.gov_proposals_tally, { proposal_id });
return this.request(this.registry.gov_proposals_tally, { proposal_id }, undefined, (source: any) => {
return {tally: {
yes: source.yes || source.yes_count,
abstain: source.abstain || source.abstain_count,
no: source.no || source.no_count,
no_with_veto: source.no_with_veto || source.no_with_veto_count,
}};
});
}
async getGovProposalVotes(proposal_id: string, page?: PageRequest) {
if(!page) page = new PageRequest()