Skip to content

Commit

Permalink
packed option
Browse files Browse the repository at this point in the history
  • Loading branch information
pyramation committed May 16, 2022
1 parent b5590b3 commit 7446f19
Show file tree
Hide file tree
Showing 8 changed files with 687 additions and 28 deletions.
438 changes: 438 additions & 0 deletions packages/cosmwasm-typescript-gen/__fixtures__/cosmwasm/api.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
/**
* This file was automatically generated by cosmwasm-typescript-gen.
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
* and run the cosmwasm-typescript-gen generate command to regenerate this file.
*/

import { CosmWasmClient, ExecuteResult, SigningCosmWasmClient } from "@cosmjs/cosmwasm-stargate";
import { Coin, StdFee } from "@cosmjs/amino";
export interface InstantiateMsg {
admin?: string | null;
members: Member[];
}
export interface Member {
addr: string;
weight: number;
}
export type QueryResponse = {
admin: AdminResponse;
} | {
total_weight: TotalWeightResponse;
} | {
list_members: MemberListResponse;
} | {
member: MemberResponse;
} | {
hooks: HooksResponse;
};
export interface AdminResponse {
admin?: string | null;
}
export interface TotalWeightResponse {
weight: number;
}
export interface MemberListResponse {
members: Member[];
}
export interface MemberResponse {
weight?: number | null;
}
export interface HooksResponse {
hooks: string[];
}
export interface CW4GroupReadOnlyInterface {
contractAddress: string;
admin: () => Promise<AdminResponse>;
totalWeight: () => Promise<TotalWeightResponse>;
listMembers: ({
limit,
startAfter
}: {
limit?: number;
startAfter?: string;
}) => Promise<ListMembersResponse>;
member: ({
addr,
atHeight
}: {
addr: string;
atHeight?: number;
}) => Promise<MemberResponse>;
hooks: () => Promise<HooksResponse>;
}
export class CW4GroupQueryClient implements CW4GroupReadOnlyInterface {
client: CosmWasmClient;
contractAddress: string;

constructor(client: CosmWasmClient, contractAddress: string) {
this.client = client;
this.contractAddress = contractAddress;
this.admin = this.admin.bind(this);
this.totalWeight = this.totalWeight.bind(this);
this.listMembers = this.listMembers.bind(this);
this.member = this.member.bind(this);
this.hooks = this.hooks.bind(this);
}

admin = async (): Promise<AdminResponse> => {
return this.client.queryContractSmart(this.contractAddress, {
admin: {}
});
};
totalWeight = async (): Promise<TotalWeightResponse> => {
return this.client.queryContractSmart(this.contractAddress, {
total_weight: {}
});
};
listMembers = async ({
limit,
startAfter
}: {
limit?: number;
startAfter?: string;
}): Promise<ListMembersResponse> => {
return this.client.queryContractSmart(this.contractAddress, {
list_members: {
limit,
start_after: startAfter
}
});
};
member = async ({
addr,
atHeight
}: {
addr: string;
atHeight?: number;
}): Promise<MemberResponse> => {
return this.client.queryContractSmart(this.contractAddress, {
member: {
addr,
at_height: atHeight
}
});
};
hooks = async (): Promise<HooksResponse> => {
return this.client.queryContractSmart(this.contractAddress, {
hooks: {}
});
};
}
export interface CW4GroupInterface extends CW4GroupReadOnlyInterface {
contractAddress: string;
sender: string;
updateAdmin: ({
admin
}: {
admin?: string;
}, fee?: number | StdFee | "auto", memo?: string, funds?: readonly Coin[]) => Promise<ExecuteResult>;
updateMembers: ({
add,
remove
}: {
add: Member[];
remove: string[];
}, fee?: number | StdFee | "auto", memo?: string, funds?: readonly Coin[]) => Promise<ExecuteResult>;
addHook: ({
addr
}: {
addr: string;
}, fee?: number | StdFee | "auto", memo?: string, funds?: readonly Coin[]) => Promise<ExecuteResult>;
removeHook: ({
addr
}: {
addr: string;
}, fee?: number | StdFee | "auto", memo?: string, funds?: readonly Coin[]) => Promise<ExecuteResult>;
}
export class CW4GroupClient extends CW4GroupQueryClient implements CW4GroupInterface {
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.updateAdmin = this.updateAdmin.bind(this);
this.updateMembers = this.updateMembers.bind(this);
this.addHook = this.addHook.bind(this);
this.removeHook = this.removeHook.bind(this);
}

updateAdmin = async ({
admin
}: {
admin?: string;
}, fee: number | StdFee | "auto" = "auto", memo?: string, funds?: readonly Coin[]): Promise<ExecuteResult> => {
return await this.client.execute(this.sender, this.contractAddress, {
update_admin: {
admin
}
}, fee, memo, funds);
};
updateMembers = async ({
add,
remove
}: {
add: Member[];
remove: string[];
}, fee: number | StdFee | "auto" = "auto", memo?: string, funds?: readonly Coin[]): Promise<ExecuteResult> => {
return await this.client.execute(this.sender, this.contractAddress, {
update_members: {
add,
remove
}
}, fee, memo, funds);
};
addHook = async ({
addr
}: {
addr: string;
}, fee: number | StdFee | "auto" = "auto", memo?: string, funds?: readonly Coin[]): Promise<ExecuteResult> => {
return await this.client.execute(this.sender, this.contractAddress, {
add_hook: {
addr
}
}, fee, memo, funds);
};
removeHook = async ({
addr
}: {
addr: string;
}, fee: number | StdFee | "auto" = "auto", memo?: string, funds?: readonly Coin[]): Promise<ExecuteResult> => {
return await this.client.execute(this.sender, this.contractAddress, {
remove_hook: {
addr
}
}, fee, memo, funds);
};
}
23 changes: 15 additions & 8 deletions packages/cosmwasm-typescript-gen/__tests__/wasm.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import cosmos_msg from '../__fixtures__/vectis/cosmos_msg_for__empty.json';
import execute_msg from '../__fixtures__/vectis/execute_msg_for__empty.json';
import { readSchemas } from '../src/utils';
import cosmscript from '../src/index';
import { sync as glob } from 'glob';
import { readFileSync } from 'fs';

it('works', async () => {
const files = glob(__dirname + '/../__fixtures__/vectis/**/*.json');
const schemas = files.map(file => JSON.parse(readFileSync(file, 'utf-8')));
await cosmscript('MyContract', schemas, __dirname + '/../__output__/vectis');
it('vectis', async () => {
const out = __dirname + '/../__output__/vectis';
const schemaDir = __dirname + '/../__fixtures__/vectis/';

const schemas = readSchemas({ schemaDir, argv: {} });
await cosmscript('MyContract', schemas, out);
})

it('cosmwasm', async () => {
const out = __dirname + '/../__output__/cosmwasm';
const schemaDir = __dirname + '/../__fixtures__/cosmwasm/';

const schemas = readSchemas({ schemaDir, argv: { packed: true } });
await cosmscript('CW4Group', schemas, out);
})
7 changes: 2 additions & 5 deletions packages/cosmwasm-typescript-gen/src/commands/from-partial.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { prompt } from '../prompt';
import fromPartial from '../from-partial';
import { sync as glob } from 'glob';
import { readFileSync } from 'fs';
import { readSchemas } from '../utils';

export default async (argv) => {

Expand Down Expand Up @@ -29,8 +28,6 @@ export default async (argv) => {
];

const { schema, out, name } = await prompt(questions, argv);

const files = glob(schema + '/**/*.json');
const schemas = files.map(file => JSON.parse(readFileSync(file, 'utf-8')));
const schemas = readSchemas({ schemaDir: schema, argv });
await fromPartial(name, schemas, out);
};
7 changes: 2 additions & 5 deletions packages/cosmwasm-typescript-gen/src/commands/generate.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { prompt } from '../prompt';
import cosmscript from '../index';
import { sync as glob } from 'glob';
import { readFileSync } from 'fs';
import { readSchemas } from '../utils';

export default async (argv) => {

Expand Down Expand Up @@ -29,8 +28,6 @@ export default async (argv) => {
];

const { schema, out, name } = await prompt(questions, argv);

const files = glob(schema + '/**/*.json');
const schemas = files.map(file => JSON.parse(readFileSync(file, 'utf-8')));
const schemas = readSchemas({ schemaDir: schema, argv });
await cosmscript(name, schemas, out);
};
7 changes: 2 additions & 5 deletions packages/cosmwasm-typescript-gen/src/commands/react-query.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { prompt } from '../prompt';
import reactQuery from '../react-query';
import { sync as glob } from 'glob';
import { readFileSync } from 'fs';
import { readSchemas } from '../utils';

export default async (argv) => {

Expand Down Expand Up @@ -29,8 +28,6 @@ export default async (argv) => {
];

const { schema, out, name } = await prompt(questions, argv);

const files = glob(schema + '/**/*.json');
const schemas = files.map(file => JSON.parse(readFileSync(file, 'utf-8')));
const schemas = readSchemas({ schemaDir: schema, argv });
await reactQuery(name, schemas, out);
};
7 changes: 2 additions & 5 deletions packages/cosmwasm-typescript-gen/src/commands/recoil.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { prompt } from '../prompt';
import recoil from '../recoil';
import { sync as glob } from 'glob';
import { readFileSync } from 'fs';
import { readSchemas } from '../utils';

export default async (argv) => {

Expand Down Expand Up @@ -29,8 +28,6 @@ export default async (argv) => {
];

const { schema, out, name } = await prompt(questions, argv);

const files = glob(schema + '/**/*.json');
const schemas = files.map(file => JSON.parse(readFileSync(file, 'utf-8')));
const schemas = readSchemas({ schemaDir: schema, argv });
await recoil(name, schemas, out);
};
16 changes: 16 additions & 0 deletions packages/cosmwasm-typescript-gen/src/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { sync as glob } from 'glob';
import { readFileSync } from 'fs';

export const readSchemas = ({
schemaDir, argv
}) => {
const files = glob(schemaDir + '/**/*.json');
const schemas = files.map(file => JSON.parse(readFileSync(file, 'utf-8')));
if (argv.packed) {
if (schemas.length !== 1) {
throw new Error('packed option only supports one file');
}
return Object.values(schemas[0]);
}
return schemas;
};

0 comments on commit 7446f19

Please sign in to comment.