-
Notifications
You must be signed in to change notification settings - Fork 553
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(codegen): generated js client (the wrapper)
it wraps generated protobufjs types and rest client, uses cosmjs and exports high level `txClient()` and `queryClient()` funcs for: * creating messages, signing and broadcasting them, * querying. js client created individually for each module. within Vuex, it can be used like in below: ```js import { DirectSecp256k1HdWallet } from "@cosmjs/proto-signing"; import { txClient, queryClient } from "./store/tendermint/mars/mars/module"; async function main() { const wallet = await DirectSecp256k1HdWallet.fromMnemonic("alfa romeo..."); const t = await txClient(wallet); const q = await queryClient(); console.log(await t.signAndBroadcast([ t.msgCreateUser({ name: "mars", creator: wallet.address }) ])); console.log(await q.queryUserAll()); } main() ```
- Loading branch information
Showing
7 changed files
with
99 additions
and
28 deletions.
There are no files selected for viewing
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,38 @@ | ||
import { coins } from "@cosmjs/launchpad"; | ||
import { SigningStargateClient } from "@cosmjs/stargate"; | ||
import { Registry, DirectSecp256k1HdWallet } from "@cosmjs/proto-signing"; | ||
import Types from "{{ .TypesPath }}"; | ||
import { Api } from "{{ .RESTPath }}"; | ||
|
||
const types = [ | ||
{{ range .Module.Msgs }}["/{{ .URI }}", Types.{{ .URI }}], | ||
{{ end }} | ||
]; | ||
|
||
const registry = new Registry(types); | ||
|
||
const txClient = async (wallet, { addr: addr } = { addr: "http://localhost:26657" }) => { | ||
if (!wallet) throw new Error("wallet is required"); | ||
const client = await SigningStargateClient.connectWithWallet(addr, wallet, { registry }); | ||
const { address } = wallet; | ||
const fee = { | ||
amount: coins(0, "token"), | ||
gas: "200000", | ||
}; | ||
|
||
return { | ||
signAndBroadcast: (msgs) => client.signAndBroadcast(address, msgs, fee), | ||
{{ range .Module.Msgs }}{{ camelCase .Name }}: (data) => ({ typeUrl: "/{{ .URI }}", value: data }), | ||
{{ end }} | ||
}; | ||
}; | ||
|
||
const queryClient = async ({ addr: addr } = { addr: "http://localhost:1317" }) => { | ||
return new Api({ baseUrl: addr }).{{ .Module.Name }}; | ||
}; | ||
|
||
export { | ||
txClient, | ||
queryClient, | ||
}; |
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