-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b5590b3
commit 7446f19
Showing
8 changed files
with
687 additions
and
28 deletions.
There are no files selected for viewing
438 changes: 438 additions & 0 deletions
438
packages/cosmwasm-typescript-gen/__fixtures__/cosmwasm/api.json
Large diffs are not rendered by default.
Oops, something went wrong.
210 changes: 210 additions & 0 deletions
210
packages/cosmwasm-typescript-gen/__output__/cosmwasm/CW4GroupContract.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; |