Skip to content

Commit

Permalink
account id retrieval on account client
Browse files Browse the repository at this point in the history
  • Loading branch information
adairrr committed Oct 11, 2024
1 parent e46ec91 commit 793210e
Show file tree
Hide file tree
Showing 16 changed files with 122 additions and 62 deletions.
2 changes: 1 addition & 1 deletion examples/wagemos-cosmoskit-nextjs/abstract.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default defineConfig({
plugins: [
react(),
registry({
contracts: [{ namespace: 'abstract', name: 'betting', version: '0.0.2' }],
contracts: [{ namespace: 'wagemos', name: 'betting', version: '0.0.2' }],
}),
],
})
Original file line number Diff line number Diff line change
@@ -1,67 +1,86 @@
/**
* This file was automatically generated by @abstract-money/ts-codegen@0.35.8.
* This file was automatically generated by @abstract-money/ts-codegen@0.37.0-beta-3.
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
* and run the @abstract-money/ts-codegen generate command to regenerate this file.
*/

import { CamelCasedProperties } from "type-fest";
import { SigningCosmWasmClient, ExecuteResult } from "@abstract-money/cli/cosmjs";
import { AccountPublicClient, AccountWalletClient, AppExecuteMsg, AppExecuteMsgFactory, AdapterExecuteMsg, AdapterExecuteMsgFactory } from "@abstract-money/core";
import { StdFee, Coin } from "@abstract-money/cli/cosmjs";
import { Decimal, InstantiateMsg, ExecuteMsg, AssetEntry, AccountTrace, ChainName, Uint128, AccountOdds, AccountId, Bet, AnsAsset, QueryMsg, MigrateMsg, Addr, BetsResponse, ConfigResponse, ListOddsResponse, RoundStatus, RoundsResponse, RoundResponse, OddsResponse } from "./Betting.types";
import { BettingQueryMsgBuilder, BettingExecuteMsgBuilder } from "./Betting.message-builder";
import { AccountWalletClient, AccountPublicClient, AppExecuteMsg, AppExecuteMsgFactory } from "@abstract-money/core";

export interface IBettingAppQueryClient {
moduleId: string;
accountPublicClient: AccountPublicClient;
_moduleAddress: string | undefined;
round: () => Promise<RoundResponse>;
round: (params: CamelCasedProperties<Extract<QueryMsg, {
round: unknown;
}>["round"]>) => Promise<RoundResponse>;
listRounds: (params: CamelCasedProperties<Extract<QueryMsg, {
list_rounds: unknown;
}>["list_rounds"]>) => Promise<RoundsResponse>;
odds: (params: CamelCasedProperties<Extract<QueryMsg, {
odds: unknown;
}>["odds"]>) => Promise<OddsResponse>;
listOdds: () => Promise<ListOddsResponse>;
listOdds: (params: CamelCasedProperties<Extract<QueryMsg, {
list_odds: unknown;
}>["list_odds"]>) => Promise<ListOddsResponse>;
config: () => Promise<ConfigResponse>;
bets: () => Promise<BetsResponse>;
bets: (params: CamelCasedProperties<Extract<QueryMsg, {
bets: unknown;
}>["bets"]>) => Promise<BetsResponse>;
getAddress: () => Promise<string>;
}

export class BettingAppQueryClient implements IBettingAppQueryClient {
accountPublicClient: AccountPublicClient;
moduleId: string;
_moduleAddress: string | undefined;

constructor({
accountPublicClient,
moduleId
}: {
accountPublicClient,
moduleId
}: {
accountPublicClient: AccountPublicClient;
moduleId: string;
}) {
this.accountPublicClient = accountPublicClient;
this.moduleId = moduleId;
this.round = this.round.bind(this);
this.listRounds = this.listRounds.bind(this);
this.odds = this.odds.bind(this);
this.listOdds = this.listOdds.bind(this);
this.config = this.config.bind(this);
this.bets = this.bets.bind(this);
}

round = async (): Promise<RoundResponse> => {
return this._query(BettingQueryMsgBuilder.round());
round = async (params: CamelCasedProperties<Extract<QueryMsg, {
round: unknown;
}>["round"]>): Promise<RoundResponse> => {
return this._query(BettingQueryMsgBuilder.round(params));
};
listRounds = async (params: CamelCasedProperties<Extract<QueryMsg, {
list_rounds: unknown;
}>["list_rounds"]>): Promise<RoundsResponse> => {
return this._query(BettingQueryMsgBuilder.listRounds(params));
};
odds = async (params: CamelCasedProperties<Extract<QueryMsg, {
odds: unknown;
}>["odds"]>): Promise<OddsResponse> => {
return this._query(BettingQueryMsgBuilder.odds(params));
};
listOdds = async (): Promise<ListOddsResponse> => {
return this._query(BettingQueryMsgBuilder.listOdds());
listOdds = async (params: CamelCasedProperties<Extract<QueryMsg, {
list_odds: unknown;
}>["list_odds"]>): Promise<ListOddsResponse> => {
return this._query(BettingQueryMsgBuilder.listOdds(params));
};
config = async (): Promise<ConfigResponse> => {
return this._query(BettingQueryMsgBuilder.config());
};
bets = async (): Promise<BetsResponse> => {
return this._query(BettingQueryMsgBuilder.bets());
bets = async (params: CamelCasedProperties<Extract<QueryMsg, {
bets: unknown;
}>["bets"]>): Promise<BetsResponse> => {
return this._query(BettingQueryMsgBuilder.bets(params));
};
getAddress = async (): Promise<string> => {
if (!this._moduleAddress) {
Expand All @@ -86,33 +105,38 @@ export class BettingAppQueryClient implements IBettingAppQueryClient {
});
};
}

export interface IBettingAppClient extends IBettingAppQueryClient {
accountWalletClient: AccountWalletClient;
register: (fee_?: number | StdFee | "auto", memo_?: string, funds_?: Coin[]) => Promise<ExecuteResult>;
createRound: (params: CamelCasedProperties<Extract<ExecuteMsg, {
create_round: unknown;
}>["create_round"]>, fee_?: number | StdFee | "auto", memo_?: string, funds_?: Coin[]) => Promise<ExecuteResult>;
register: (params: CamelCasedProperties<Extract<ExecuteMsg, {
register: unknown;
}>["register"]>, fee_?: number | StdFee | "auto", memo_?: string, funds_?: Coin[]) => Promise<ExecuteResult>;
updateAccounts: (params: CamelCasedProperties<Extract<ExecuteMsg, {
update_accounts: unknown;
}>["update_accounts"]>, fee_?: number | StdFee | "auto", memo_?: string, funds_?: Coin[]) => Promise<ExecuteResult>;
placeBet: (params: CamelCasedProperties<Extract<ExecuteMsg, {
place_bet: unknown;
}>["place_bet"]>, fee_?: number | StdFee | "auto", memo_?: string, funds_?: Coin[]) => Promise<ExecuteResult>;
distributeWinnings: (fee_?: number | StdFee | "auto", memo_?: string, funds_?: Coin[]) => Promise<ExecuteResult>;
distributeWinnings: (params: CamelCasedProperties<Extract<ExecuteMsg, {
distribute_winnings: unknown;
}>["distribute_winnings"]>, fee_?: number | StdFee | "auto", memo_?: string, funds_?: Coin[]) => Promise<ExecuteResult>;
closeRound: (params: CamelCasedProperties<Extract<ExecuteMsg, {
close_round: unknown;
}>["close_round"]>, fee_?: number | StdFee | "auto", memo_?: string, funds_?: Coin[]) => Promise<ExecuteResult>;
updateConfig: (params: CamelCasedProperties<Extract<ExecuteMsg, {
update_config: unknown;
}>["update_config"]>, fee_?: number | StdFee | "auto", memo_?: string, funds_?: Coin[]) => Promise<ExecuteResult>;
}

export class BettingAppClient extends BettingAppQueryClient implements IBettingAppClient {
accountWalletClient: AccountWalletClient;

constructor({
accountPublicClient,
accountWalletClient,
moduleId
}: {
accountPublicClient,
accountWalletClient,
moduleId
}: {
accountPublicClient: AccountPublicClient;
accountWalletClient: AccountWalletClient;
moduleId: string;
Expand All @@ -122,6 +146,7 @@ export class BettingAppClient extends BettingAppQueryClient implements IBettingA
moduleId
});
this.accountWalletClient = accountWalletClient;
this.createRound = this.createRound.bind(this);
this.register = this.register.bind(this);
this.updateAccounts = this.updateAccounts.bind(this);
this.placeBet = this.placeBet.bind(this);
Expand All @@ -130,8 +155,15 @@ export class BettingAppClient extends BettingAppQueryClient implements IBettingA
this.updateConfig = this.updateConfig.bind(this);
}

register = async (fee_: number | StdFee | "auto" = "auto", memo_?: string, funds_?: Coin[]): Promise<ExecuteResult> => {
return this._execute(BettingExecuteMsgBuilder.register(), fee_, memo_, funds_);
createRound = async (params: CamelCasedProperties<Extract<ExecuteMsg, {
create_round: unknown;
}>["create_round"]>, fee_: number | StdFee | "auto" = "auto", memo_?: string, funds_?: Coin[]): Promise<ExecuteResult> => {
return this._execute(BettingExecuteMsgBuilder.createRound(params), fee_, memo_, funds_);
};
register = async (params: CamelCasedProperties<Extract<ExecuteMsg, {
register: unknown;
}>["register"]>, fee_: number | StdFee | "auto" = "auto", memo_?: string, funds_?: Coin[]): Promise<ExecuteResult> => {
return this._execute(BettingExecuteMsgBuilder.register(params), fee_, memo_, funds_);
};
updateAccounts = async (params: CamelCasedProperties<Extract<ExecuteMsg, {
update_accounts: unknown;
Expand All @@ -143,8 +175,10 @@ export class BettingAppClient extends BettingAppQueryClient implements IBettingA
}>["place_bet"]>, fee_: number | StdFee | "auto" = "auto", memo_?: string, funds_?: Coin[]): Promise<ExecuteResult> => {
return this._execute(BettingExecuteMsgBuilder.placeBet(params), fee_, memo_, funds_);
};
distributeWinnings = async (fee_: number | StdFee | "auto" = "auto", memo_?: string, funds_?: Coin[]): Promise<ExecuteResult> => {
return this._execute(BettingExecuteMsgBuilder.distributeWinnings(), fee_, memo_, funds_);
distributeWinnings = async (params: CamelCasedProperties<Extract<ExecuteMsg, {
distribute_winnings: unknown;
}>["distribute_winnings"]>, fee_: number | StdFee | "auto" = "auto", memo_?: string, funds_?: Coin[]): Promise<ExecuteResult> => {
return this._execute(BettingExecuteMsgBuilder.distributeWinnings(params), fee_, memo_, funds_);
};
closeRound = async (params: CamelCasedProperties<Extract<ExecuteMsg, {
close_round: unknown;
Expand All @@ -162,4 +196,4 @@ export class BettingAppClient extends BettingAppQueryClient implements IBettingA
const moduleMsg: AppExecuteMsg<ExecuteMsg> = AppExecuteMsgFactory.executeApp(msg);
return await signingCwClient.execute(sender, await this.getAddress(), moduleMsg, fee_, memo_, funds_);
};
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @ts-nocheck
/**
* This file was automatically generated by @abstract-money/ts-codegen@0.35.8.
* This file was automatically generated by @abstract-money/ts-codegen@0.37.0-beta-3.
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
* and run the @abstract-money/ts-codegen generate command to regenerate this file.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* This file was automatically generated by @abstract-money/ts-codegen@0.35.8.
* This file was automatically generated by @abstract-money/ts-codegen@0.37.0-beta-3.
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
* and run the @abstract-money/ts-codegen generate command to regenerate this file.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* This file was automatically generated by @abstract-money/ts-codegen@0.35.8.
* This file was automatically generated by @abstract-money/ts-codegen@0.37.0-beta-3.
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
* and run the @abstract-money/ts-codegen generate command to regenerate this file.
*/
Expand Down
2 changes: 1 addition & 1 deletion examples/wagemos-cosmoskit-nextjs/src/_generated/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ import {
// React
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

export const BETTING_MODULE_ID = 'abstract:betting'
export const BETTING_MODULE_ID = 'wagemos:betting'

export const betting = {
queries: {
Expand Down
6 changes: 2 additions & 4 deletions examples/wagemos-cosmoskit-nextjs/src/app/remote/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
useSimulateExecuteRemoteManager,
} from '@abstract-money/react'
import { useChain } from '@cosmos-kit/react'
import { ReactQueryDevtools } from '@tanstack/react-query-devtools'
import { useCallback, useMemo, useState } from 'react'
import { Button } from '../../components/ui/button'
import {
Expand Down Expand Up @@ -79,7 +78,6 @@ export default function RemotePage() {
funds: [],
args: {
hostChainName: chainInput,
base_asset: 'juno>juno',
installModules: [],
},
})
Expand All @@ -95,7 +93,7 @@ export default function RemotePage() {
fee: 'auto',
args: {
hostChainName: chainInput,
managerMsg: {
accountMsg: {
update_info: {
name: 'test',
},
Expand All @@ -116,7 +114,7 @@ export default function RemotePage() {
console.log('simulating remote account')
simulateRemote({
hostChainName: chainInput,
managerMsg: {
accountMsg: {
update_info: {
name: 'test',
},
Expand Down
2 changes: 1 addition & 1 deletion examples/wagemos-graz-nextjs/abstract.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default defineConfig({
plugins: [
react(),
registry({
contracts: [{ name: 'betting', namespace: 'abstract', version: '0.0.2' }],
contracts: [{ namespace: 'wagemos', name: 'betting', version: '0.0.2' }],
}),
],
})
Original file line number Diff line number Diff line change
Expand Up @@ -294,4 +294,4 @@ export function useBettingCreateRoundMutation(options?: Omit<UseMutationOptions<
funds
} = {}
}) => client.createRound(msg, fee, memo, funds), options);
}
}
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"type": "module",
"dependencies": {
"@abstract-money/bundle-require": "workspace:*",
"@abstract-money/ts-codegen": "0.37.0-beta-2",
"@abstract-money/ts-codegen": "0.37.0-beta-3",
"@cosmjs/cosmwasm-stargate": "^0.32.3",
"@cosmjs/stargate": "^0.32.3",
"abort-controller": "^3.0.0",
Expand Down
22 changes: 22 additions & 0 deletions packages/core/src/actions/account/public/get-account-id.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { AccountId, chainIdToName } from '@abstract-money/core'
import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate'
import { RegistryTypes } from '../../../codegen/abstract'

export type GetAccountIdParameters = {
accountId: RegistryTypes.AccountId
cosmWasmClient: CosmWasmClient
}

/**
* Get the account id with the chain name set.
* @param accountId
* @param cosmWasmClient
*/
export async function getAccountId({
accountId,
cosmWasmClient,
}: GetAccountIdParameters): Promise<AccountId> {
const chainId = await cosmWasmClient.getChainId()
const chainName = chainIdToName(chainId)
return { ...accountId, chainName } satisfies AccountId
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { RegistryTypes } from '../../../codegen/abstract'

export type GetRegistryAccountIdParameters = {
accountId: RegistryTypes.AccountId
}

export function getRegistryAccountId({
accountId,
}: GetRegistryAccountIdParameters) {
return accountId
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export type SimulateExecuteRemoteAccountParameters = {
* @param cosmWasmClient
* @param apiUrl
* @param hostChainName
* @param managerMsg
* @param accountMsg
* @experimental
*/
export async function simulateExecuteRemoteAccount({
Expand Down
15 changes: 2 additions & 13 deletions packages/core/src/actions/account/wallet/execute-ibc-action.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,8 @@
import semver from 'semver/preload'
import {
AccountClient,
AccountMsgComposer,
AccountTypes,
IbcClientTypes,
} from '../../../codegen/abstract'
import { ModuleType } from '../../../codegen/gql/graphql'
import { IbcClientTypes } from '../../../codegen/abstract'
import { WithCosmWasmSignOptions } from '../../../types/parameters'
import { MaybeArray } from '../../../types/utils'
import { abstractModuleId } from '../../../utils/modules/abstract-module-id'
import { encodeModuleMsg } from '../../../utils/modules/encode-module-msg'
import { CommonModuleNames } from '../../public/types'
import { getModuleAddress } from '../public/get-module-address'
import { getModuleVersion } from '../public/get-module-version'
import { executeOnModule } from './execute-on-module'
import { getAccountClientFromApi } from './get-account-client-from-api'
import { BaseAccountWalletParameters } from './types'

Expand All @@ -32,7 +21,7 @@ export type ExecuteIbcActionParameters = Omit<
* @param signingCosmWasmClient
* @param apiUrl
* @param sender
* @param managerMsg
* @param msg
* @param fee
* @param memo
*/
Expand Down
Loading

0 comments on commit 793210e

Please sign in to comment.