Skip to content

Commit

Permalink
Update typescript client code
Browse files Browse the repository at this point in the history
  • Loading branch information
TropicalDog17 committed Oct 18, 2023
1 parent 16a5863 commit f947164
Show file tree
Hide file tree
Showing 8 changed files with 548 additions and 0 deletions.
117 changes: 117 additions & 0 deletions client-ts/Donex.client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/**
* This file was automatically generated by @cosmwasm/[email protected].
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
* and run the @cosmwasm/ts-codegen generate command to regenerate this file.
*/

import { CosmWasmClient, SigningCosmWasmClient, ExecuteResult } from "@cosmjs/cosmwasm-stargate";
import { Coin, StdFee } from "@cosmjs/amino";
import { InstantiateMsg, ExecuteMsg, Addr, QueryMsg, GetAddressesBySocialResponse, GetSocialsByAddressResponse } from "./Donex.types";
export interface DonexReadOnlyInterface {
contractAddress: string;
getAddressesBySocial: ({
platform,
profileId
}: {
platform: string;
profileId: string;
}) => Promise<GetAddressesBySocialResponse>;
getSocialsByAddress: ({
address
}: {
address: Addr;
}) => Promise<GetSocialsByAddressResponse>;
}
export class DonexQueryClient implements DonexReadOnlyInterface {
client: CosmWasmClient;
contractAddress: string;

constructor(client: CosmWasmClient, contractAddress: string) {
this.client = client;
this.contractAddress = contractAddress;
this.getAddressesBySocial = this.getAddressesBySocial.bind(this);
this.getSocialsByAddress = this.getSocialsByAddress.bind(this);
}

getAddressesBySocial = async ({
platform,
profileId
}: {
platform: string;
profileId: string;
}): Promise<GetAddressesBySocialResponse> => {
return this.client.queryContractSmart(this.contractAddress, {
get_addresses_by_social: {
platform,
profile_id: profileId
}
});
};
getSocialsByAddress = async ({
address
}: {
address: Addr;
}): Promise<GetSocialsByAddressResponse> => {
return this.client.queryContractSmart(this.contractAddress, {
get_socials_by_address: {
address
}
});
};
}
export interface DonexInterface extends DonexReadOnlyInterface {
contractAddress: string;
sender: string;
submitSocial: ({
address,
socialInfo
}: {
address: Addr;
socialInfo: string[][];
}, fee?: number | StdFee | "auto", memo?: string, _funds?: Coin[]) => Promise<ExecuteResult>;
donate: ({
recipient
}: {
recipient: Addr;
}, fee?: number | StdFee | "auto", memo?: string, _funds?: Coin[]) => Promise<ExecuteResult>;
}
export class DonexClient extends DonexQueryClient implements DonexInterface {
client: SigningCosmWasmClient;
sender: string;
contractAddress: string;

constructor(client: SigningCosmWasmClient, sender: string, contractAddress: string) {
super(client, contractAddress);
this.client = client;
this.sender = sender;
this.contractAddress = contractAddress;
this.submitSocial = this.submitSocial.bind(this);
this.donate = this.donate.bind(this);
}

submitSocial = async ({
address,
socialInfo
}: {
address: Addr;
socialInfo: string[][];
}, fee: number | StdFee | "auto" = "auto", memo?: string, _funds?: Coin[]): Promise<ExecuteResult> => {
return await this.client.execute(this.sender, this.contractAddress, {
submit_social: {
address,
social_info: socialInfo
}
}, fee, memo, _funds);
};
donate = async ({
recipient
}: {
recipient: Addr;
}, fee: number | StdFee | "auto" = "auto", memo?: string, _funds?: Coin[]): Promise<ExecuteResult> => {
return await this.client.execute(this.sender, this.contractAddress, {
donate: {
recipient
}
}, fee, memo, _funds);
};
}
36 changes: 36 additions & 0 deletions client-ts/Donex.types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* This file was automatically generated by @cosmwasm/[email protected].
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
* and run the @cosmwasm/ts-codegen generate command to regenerate this file.
*/

export interface InstantiateMsg {
accepted_token: string[];
}
export type ExecuteMsg = {
submit_social: {
address: Addr;
social_info: [string, string];
};
} | {
donate: {
recipient: Addr;
};
};
export type Addr = string;
export type QueryMsg = {
get_addresses_by_social: {
platform: string;
profile_id: string;
};
} | {
get_socials_by_address: {
address: Addr;
};
};
export interface GetAddressesBySocialResponse {
address: Addr[];
}
export interface GetSocialsByAddressResponse {
social_infos: [string, string][];
}
202 changes: 202 additions & 0 deletions src/schema/donex-sm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
{
"contract_name": "donex-sm",
"contract_version": "0.1.0",
"idl_version": "1.0.0",
"instantiate": {
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "InstantiateMsg",
"type": "object",
"required": [
"accepted_token"
],
"properties": {
"accepted_token": {
"type": "array",
"items": {
"type": "string"
}
}
},
"additionalProperties": false
},
"execute": {
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "ExecuteMsg",
"oneOf": [
{
"type": "object",
"required": [
"submit_social"
],
"properties": {
"submit_social": {
"type": "object",
"required": [
"address",
"social_info"
],
"properties": {
"address": {
"$ref": "#/definitions/Addr"
},
"social_info": {
"type": "array",
"items": [
{
"type": "string"
},
{
"type": "string"
}
],
"maxItems": 2,
"minItems": 2
}
},
"additionalProperties": false
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"donate"
],
"properties": {
"donate": {
"type": "object",
"required": [
"recipient"
],
"properties": {
"recipient": {
"$ref": "#/definitions/Addr"
}
},
"additionalProperties": false
}
},
"additionalProperties": false
}
],
"definitions": {
"Addr": {
"description": "A human readable address.\n\nIn Cosmos, this is typically bech32 encoded. But for multi-chain smart contracts no assumptions should be made other than being UTF-8 encoded and of reasonable length.\n\nThis type represents a validated address. It can be created in the following ways 1. Use `Addr::unchecked(input)` 2. Use `let checked: Addr = deps.api.addr_validate(input)?` 3. Use `let checked: Addr = deps.api.addr_humanize(canonical_addr)?` 4. Deserialize from JSON. This must only be done from JSON that was validated before such as a contract's state. `Addr` must not be used in messages sent by the user because this would result in unvalidated instances.\n\nThis type is immutable. If you really need to mutate it (Really? Are you sure?), create a mutable copy using `let mut mutable = Addr::to_string()` and operate on that `String` instance.",
"type": "string"
}
}
},
"query": {
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "QueryMsg",
"oneOf": [
{
"type": "object",
"required": [
"get_addresses_by_social"
],
"properties": {
"get_addresses_by_social": {
"type": "object",
"required": [
"platform",
"profile_id"
],
"properties": {
"platform": {
"type": "string"
},
"profile_id": {
"type": "string"
}
},
"additionalProperties": false
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"get_socials_by_address"
],
"properties": {
"get_socials_by_address": {
"type": "object",
"required": [
"address"
],
"properties": {
"address": {
"$ref": "#/definitions/Addr"
}
},
"additionalProperties": false
}
},
"additionalProperties": false
}
],
"definitions": {
"Addr": {
"description": "A human readable address.\n\nIn Cosmos, this is typically bech32 encoded. But for multi-chain smart contracts no assumptions should be made other than being UTF-8 encoded and of reasonable length.\n\nThis type represents a validated address. It can be created in the following ways 1. Use `Addr::unchecked(input)` 2. Use `let checked: Addr = deps.api.addr_validate(input)?` 3. Use `let checked: Addr = deps.api.addr_humanize(canonical_addr)?` 4. Deserialize from JSON. This must only be done from JSON that was validated before such as a contract's state. `Addr` must not be used in messages sent by the user because this would result in unvalidated instances.\n\nThis type is immutable. If you really need to mutate it (Really? Are you sure?), create a mutable copy using `let mut mutable = Addr::to_string()` and operate on that `String` instance.",
"type": "string"
}
}
},
"migrate": null,
"sudo": null,
"responses": {
"get_addresses_by_social": {
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "GetAddressesBySocialResponse",
"type": "object",
"required": [
"address"
],
"properties": {
"address": {
"type": "array",
"items": {
"$ref": "#/definitions/Addr"
}
}
},
"additionalProperties": false,
"definitions": {
"Addr": {
"description": "A human readable address.\n\nIn Cosmos, this is typically bech32 encoded. But for multi-chain smart contracts no assumptions should be made other than being UTF-8 encoded and of reasonable length.\n\nThis type represents a validated address. It can be created in the following ways 1. Use `Addr::unchecked(input)` 2. Use `let checked: Addr = deps.api.addr_validate(input)?` 3. Use `let checked: Addr = deps.api.addr_humanize(canonical_addr)?` 4. Deserialize from JSON. This must only be done from JSON that was validated before such as a contract's state. `Addr` must not be used in messages sent by the user because this would result in unvalidated instances.\n\nThis type is immutable. If you really need to mutate it (Really? Are you sure?), create a mutable copy using `let mut mutable = Addr::to_string()` and operate on that `String` instance.",
"type": "string"
}
}
},
"get_socials_by_address": {
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "GetSocialsByAddressResponse",
"type": "object",
"required": [
"social_infos"
],
"properties": {
"social_infos": {
"type": "array",
"items": {
"type": "array",
"items": [
{
"type": "string"
},
{
"type": "string"
}
],
"maxItems": 2,
"minItems": 2
}
}
},
"additionalProperties": false
}
}
}
Loading

0 comments on commit f947164

Please sign in to comment.