-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: 83 add cosmos service: add query and tx clients #96
Merged
Merged
Changes from 24 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
f2a17a7
Import generated Duality core code (and ignore linting errors)
dib542 68d7790
Add a generated code update script
dib542 6252360
Add used dependencies in generated code
dib542 18efcf0
Downgrade stargate to avoid inconsistent sub-dependencies:
dib542 fb1cc85
Add @cosmjs node environment dependencies
dib542 8802a73
Ignore generated TypeScript issues: but it doesn't ignore all of them
dib542 4f67236
Fix Startport's terrible code with no way to automatically fix
dib542 88bc2e5
Add potential generated script fix
dib542 97690e8
Add autogenerated changes about tick query URL path
dib542 9f10a82
Fix Webpack sourcemap warnings: by disabling sourcemaps
dib542 6523acc
Fix: align client.signAndBroadcast type options
dib542 5d0dba6
Change default fee to 'auto'
dib542 9c32edf
Create custom API file from generated file
dib542 8e0203e
Move generated files and allow Prettier to format them
dib542 b218af0
Remove previous rules for not formatting generated code
dib542 6a65370
Allow update script to be run as an package script
dib542 145297d
Copy over only generated types and REST file: index.ts is now custom
dib542 3dd8509
Attempt to add all generated Msgs to txClient dynamically
dib542 1343390
Revert "Attempt to add all generated Msgs to txClient dynamically"
dib542 b312a4d
Add environment variables for local chain connecting
dib542 6daa277
Make indexer environment URLs consistent with prototype listener URLs
dib542 e438a70
Make Cosmos Query and Tx env variables consistent with Event variables
dib542 93375f7
Update to my suggested environment variable names
dib542 66cc6a2
Add comments about updating Msg methods
dib542 d1729a5
Allow more API config properties to be passed through new queryClient
dib542 7f08a17
Simplify ApiConfig passing with default and spreading arbitrary params
dib542 73c5ded
Merge branch 'main' into 83-add-query-and-tx-clients
dib542 0f54a0f
Align environment variables to main branch
dib542 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Large diffs are not rendered by default.
Oops, something went wrong.
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,20 @@ | ||
#!/bin/sh | ||
|
||
# use provided source path or a default | ||
DUALITY_CORE_DIRECTORY="${1:-"../duality"}" | ||
|
||
# copy type files | ||
cp -r "$DUALITY_CORE_DIRECTORY/vue/src/store/generated/duality/duality.duality/module/types" \ | ||
"src/lib/web3/generated/duality/duality.duality/module" | ||
|
||
# copy REST API file | ||
cp -r "$DUALITY_CORE_DIRECTORY/vue/src/store/generated/duality/duality.duality/module/rest.ts" \ | ||
"src/lib/web3/generated/duality/duality.duality/module/rest.ts" | ||
|
||
# copy version info | ||
cp -r "$DUALITY_CORE_DIRECTORY/vue/src/store/generated/duality/duality.duality/package.json" \ | ||
"src/lib/web3/generated/duality/duality.duality/package.json" | ||
|
||
# copy readme info | ||
cp -r "$DUALITY_CORE_DIRECTORY/vue/src/store/generated/readme.md" \ | ||
"src/lib/web3/generated/readme.md" |
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,72 @@ | ||
// This file is modified from an original generated/duality/duality.duality/module/index.ts file | ||
// | ||
// This file will not auto generate changes: | ||
// if new Msgs are created they should be added to the txClient below | ||
|
||
import { StdFee } from '@cosmjs/launchpad'; | ||
import { defaultRegistryTypes, SigningStargateClient } from '@cosmjs/stargate'; | ||
import { Registry, OfflineSigner, EncodeObject } from '@cosmjs/proto-signing'; | ||
import { Api } from './generated/duality/duality.duality/module/rest'; | ||
import { | ||
MsgWithdrawShares, | ||
MsgDepositShares, | ||
} from './generated/duality/duality.duality/module/types/duality/tx'; | ||
|
||
const { REACT_APP__RPC_API = '', REACT_APP__REST_API = '' } = process.env; | ||
|
||
export const MissingWalletError = new Error('wallet is required'); | ||
|
||
export const registry = new Registry(defaultRegistryTypes); | ||
|
||
// -----> register our Msgs here | ||
registry.register('/duality.duality.MsgDepositShares', MsgDepositShares); | ||
registry.register('/duality.duality.MsgWithdrawShares', MsgWithdrawShares); | ||
|
||
interface TxClientOptions { | ||
addr?: string; | ||
} | ||
|
||
interface SignAndBroadcastOptions { | ||
fee?: StdFee | 'auto' | number; | ||
memo?: string; | ||
} | ||
|
||
const txClient = async ( | ||
wallet: OfflineSigner, | ||
{ addr = REACT_APP__RPC_API }: TxClientOptions = {} | ||
) => { | ||
if (!wallet) throw MissingWalletError; | ||
const client = addr | ||
? await SigningStargateClient.connectWithSigner(addr, wallet, { registry }) | ||
: await SigningStargateClient.offline(wallet, { registry }); | ||
const { address } = (await wallet.getAccounts())[0]; | ||
|
||
return { | ||
signAndBroadcast: ( | ||
msgs: EncodeObject[], | ||
{ fee = 'auto', memo }: SignAndBroadcastOptions = {} | ||
) => client.signAndBroadcast(address, msgs, fee, memo), | ||
|
||
// -----> register our Msg client methods here | ||
msgWithdrawShares: (data: MsgWithdrawShares): EncodeObject => ({ | ||
typeUrl: '/duality.duality.MsgWithdrawShares', | ||
value: MsgWithdrawShares.fromPartial(data), | ||
}), | ||
msgDepositShares: (data: MsgDepositShares): EncodeObject => ({ | ||
typeUrl: '/duality.duality.MsgDepositShares', | ||
value: MsgDepositShares.fromPartial(data), | ||
}), | ||
}; | ||
}; | ||
|
||
interface QueryClientOptions { | ||
addr?: string; | ||
} | ||
|
||
const queryClient = async ({ | ||
addr = REACT_APP__REST_API, | ||
}: QueryClientOptions = {}) => { | ||
return new Api({ baseUrl: addr }); | ||
}; | ||
|
||
export { txClient, queryClient }; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feels a bit too complicated
If we don't add any more attributes something like would be a lot simpler
If we do, I think somewhat spreading the defaults would make a more readable (maybe a tiny bit)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resolved by pulling in the already generated
ApiConfig
type with the baseUrl already predefined in d1729a5