Skip to content

Commit

Permalink
feat: add msg client
Browse files Browse the repository at this point in the history
  • Loading branch information
cgilbe27 committed Jun 27, 2024
1 parent 8a4de2a commit 32374dd
Show file tree
Hide file tree
Showing 19 changed files with 431 additions and 601 deletions.
111 changes: 36 additions & 75 deletions src/sdk/msg/devgas.ts
Original file line number Diff line number Diff line change
@@ -1,88 +1,49 @@
import { EncodeObject, GeneratedType } from "@cosmjs/proto-signing"
import { createProtobufRpcClient, QueryClient } from "@cosmjs/stargate"
import {
MsgCancelFeeShare,

Check failure on line 3 in src/sdk/msg/devgas.ts

View workflow job for this annotation

GitHub Actions / checkout_cache_install_build_test

Module '"src/protojs/index.nibiru.devgas.v1"' has no exported member 'MsgCancelFeeShare'.
MsgCancelFeeShareResponse,

Check failure on line 4 in src/sdk/msg/devgas.ts

View workflow job for this annotation

GitHub Actions / checkout_cache_install_build_test

Module '"src/protojs/index.nibiru.devgas.v1"' has no exported member 'MsgCancelFeeShareResponse'.
MsgClientImpl,

Check failure on line 5 in src/sdk/msg/devgas.ts

View workflow job for this annotation

GitHub Actions / checkout_cache_install_build_test

Module '"src/protojs/index.nibiru.devgas.v1"' has no exported member 'MsgClientImpl'.
MsgRegisterFeeShare,

Check failure on line 6 in src/sdk/msg/devgas.ts

View workflow job for this annotation

GitHub Actions / checkout_cache_install_build_test

Module '"src/protojs/index.nibiru.devgas.v1"' has no exported member 'MsgRegisterFeeShare'.
MsgRegisterFeeShareResponse,

Check failure on line 7 in src/sdk/msg/devgas.ts

View workflow job for this annotation

GitHub Actions / checkout_cache_install_build_test

Module '"src/protojs/index.nibiru.devgas.v1"' has no exported member 'MsgRegisterFeeShareResponse'.
MsgUpdateFeeShare,

Check failure on line 8 in src/sdk/msg/devgas.ts

View workflow job for this annotation

GitHub Actions / checkout_cache_install_build_test

Module '"src/protojs/index.nibiru.devgas.v1"' has no exported member 'MsgUpdateFeeShare'.
MsgUpdateFeeShareResponse,

Check failure on line 9 in src/sdk/msg/devgas.ts

View workflow job for this annotation

GitHub Actions / checkout_cache_install_build_test

Module '"src/protojs/index.nibiru.devgas.v1"' has no exported member 'MsgUpdateFeeShareResponse'.
MsgUpdateParams,

Check failure on line 10 in src/sdk/msg/devgas.ts

View workflow job for this annotation

GitHub Actions / checkout_cache_install_build_test

Module '"src/protojs/index.nibiru.devgas.v1"' has no exported member 'MsgUpdateParams'.
} from "../../protojs/nibiru/devgas/v1/tx"
import { TxMessage } from ".."

const protobufPackage = "nibiru.devgas.v1"

export const DEVGAS_MSG_TYPE_URLS = {
MsgCancelFeeShare: `/${protobufPackage}.MsgCancelFeeShare`,
MsgRegisterFeeShare: `/${protobufPackage}.MsgRegisterFeeShare`,
MsgUpdateFeeShare: `/${protobufPackage}.MsgUpdateFeeShare`,
MsgUpdateParams: `/${protobufPackage}.MsgUpdateParams`,
}

export const devgasTypes: ReadonlyArray<[string, GeneratedType]> = [
[DEVGAS_MSG_TYPE_URLS.MsgCancelFeeShare, MsgCancelFeeShare],
[DEVGAS_MSG_TYPE_URLS.MsgRegisterFeeShare, MsgRegisterFeeShare],
[DEVGAS_MSG_TYPE_URLS.MsgUpdateFeeShare, MsgUpdateFeeShare],
[DEVGAS_MSG_TYPE_URLS.MsgUpdateParams, MsgUpdateParams],
]

export interface MsgCancelFeeShareEncodeObject extends EncodeObject {
readonly typeUrl: string
readonly value: Partial<MsgCancelFeeShare>
}

export const isMsgCancelFeeShareEncodeObject = (encodeObject: EncodeObject) =>
encodeObject.typeUrl === DEVGAS_MSG_TYPE_URLS.MsgCancelFeeShare

export interface MsgRegisterFeeShareEncodeObject extends EncodeObject {
readonly typeUrl: string
readonly value: Partial<MsgRegisterFeeShare>
}

export const isMsgRegisterFeeShareEncodeObject = (encodeObject: EncodeObject) =>
encodeObject.typeUrl === DEVGAS_MSG_TYPE_URLS.MsgRegisterFeeShare

export interface MsgUpdateFeeShareEncodeObject extends EncodeObject {
readonly typeUrl: string
readonly value: Partial<MsgUpdateFeeShare>
MsgUpdateParamsResponse,

Check failure on line 11 in src/sdk/msg/devgas.ts

View workflow job for this annotation

GitHub Actions / checkout_cache_install_build_test

Module '"src/protojs/index.nibiru.devgas.v1"' has no exported member 'MsgUpdateParamsResponse'.
} from "src/protojs/index.nibiru.devgas.v1"

export interface DevgasMsgExtension {
readonly devgasMsg: Readonly<{
registerFeeShare: (
body: MsgRegisterFeeShare
) => Promise<MsgRegisterFeeShareResponse>
updateFeeShare: (
body: MsgUpdateFeeShare
) => Promise<MsgUpdateFeeShareResponse>
cancelFeeShare: (
body: MsgCancelFeeShare
) => Promise<MsgCancelFeeShareResponse>
updateParams: (body: MsgUpdateParams) => Promise<MsgUpdateParamsResponse>
}>
}

export const isMsgUpdateFeeShareEncodeObject = (encodeObject: EncodeObject) =>
encodeObject.typeUrl === DEVGAS_MSG_TYPE_URLS.MsgUpdateFeeShare
export const setupDevgasMsgExtension = (
base: QueryClient
): DevgasMsgExtension => {
const queryService = new MsgClientImpl(createProtobufRpcClient(base))

export interface MsgUpdateParamsEncodeObject extends EncodeObject {
readonly typeUrl: string
readonly value: Partial<MsgUpdateParams>
}
return {
devgasMsg: {
registerFeeShare: async (body: MsgRegisterFeeShare) =>
queryService.RegisterFeeShare(MsgRegisterFeeShare.fromPartial(body)),

export const isMsgUpdateParamsEncodeObject = (encodeObject: EncodeObject) =>
encodeObject.typeUrl === DEVGAS_MSG_TYPE_URLS.MsgUpdateParams
updateFeeShare: async (body: MsgUpdateFeeShare) =>
queryService.UpdateFeeShare(MsgUpdateFeeShare.fromPartial(body)),

// ----------------------------------------------------------------------------

export class DevgasMsgFactory {
static cancelFeeShare(msg: MsgCancelFeeShare): TxMessage {
return {
typeUrl: `/${protobufPackage}.MsgCancelFeeShare`,
value: MsgCancelFeeShare.fromPartial(msg),
}
}

static registerFeeShare(msg: MsgRegisterFeeShare): TxMessage {
return {
typeUrl: `/${protobufPackage}.MsgRegisterFeeShare`,
value: MsgRegisterFeeShare.fromPartial(msg),
}
}

static MsgUpdateFeeShare(msg: MsgUpdateFeeShare): TxMessage {
return {
typeUrl: `/${protobufPackage}.MsgUpdateFeeShare`,
value: MsgUpdateFeeShare.fromPartial(msg),
}
}
cancelFeeShare: async (body: MsgCancelFeeShare) =>
queryService.CancelFeeShare(MsgCancelFeeShare.fromPartial(body)),

static updateParams(msg: MsgUpdateParams): TxMessage {
return {
typeUrl: `/${protobufPackage}.MsgUpdateParams`,
value: MsgUpdateParams.fromPartial(msg),
}
updateParams: async (body: MsgUpdateParams) =>
queryService.UpdateParams(MsgUpdateParams.fromPartial(body)),
},
}
}
29 changes: 0 additions & 29 deletions src/sdk/msg/encode-types.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/sdk/msg/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
*/

export * from "./devgas"
export * from "./encode-types"
export * from "./inflation"
export * from "./oracle"
export * from "./sudo"
Expand Down
76 changes: 30 additions & 46 deletions src/sdk/msg/inflation.ts
Original file line number Diff line number Diff line change
@@ -1,53 +1,37 @@
import { EncodeObject, GeneratedType } from "@cosmjs/proto-signing"
import { createProtobufRpcClient, QueryClient } from "@cosmjs/stargate"
import {
MsgClientImpl,

Check failure on line 3 in src/sdk/msg/inflation.ts

View workflow job for this annotation

GitHub Actions / checkout_cache_install_build_test

Module '"src/protojs/index.nibiru.inflation.v1"' has no exported member 'MsgClientImpl'.
MsgEditInflationParams,
MsgEditInflationParamsResponse,
MsgToggleInflation,
} from "../../protojs/nibiru/inflation/v1/tx"
import { TxMessage } from ".."

const protobufPackage = "nibiru.inflation.v1"

export const INFLATION_MSG_TYPE_URLS = {
MsgEditInflationParams: `/${protobufPackage}.MsgEditInflationParams`,
MsgToggleInflation: `/${protobufPackage}.MsgToggleInflation`,
}

export const inflationTypes: ReadonlyArray<[string, GeneratedType]> = [
[INFLATION_MSG_TYPE_URLS.MsgEditInflationParams, MsgEditInflationParams],
[INFLATION_MSG_TYPE_URLS.MsgToggleInflation, MsgToggleInflation],
]

export interface MsgEditInflationParamsEncodeObject extends EncodeObject {
readonly typeUrl: string
readonly value: Partial<MsgEditInflationParams>
}

export const isMsgEditInflationParamsEncodeObject = (
encodeObject: EncodeObject
) => encodeObject.typeUrl === INFLATION_MSG_TYPE_URLS.MsgEditInflationParams

export interface MsgToggleInflationEncodeObject extends EncodeObject {
readonly typeUrl: string
readonly value: Partial<MsgToggleInflation>
MsgToggleInflationResponse,
} from "src/protojs/index.nibiru.inflation.v1"

export interface InflationMsgExtension {
readonly inflationMsg: Readonly<{
toggleInflation: (
body: MsgToggleInflation
) => Promise<MsgToggleInflationResponse>
editInflationParams: (
body: MsgEditInflationParams
) => Promise<MsgEditInflationParamsResponse>
}>
}

export const isMsgToggleInflationEncodeObject = (encodeObject: EncodeObject) =>
encodeObject.typeUrl === INFLATION_MSG_TYPE_URLS.MsgToggleInflation

// ----------------------------------------------------------------------------

export class InflationMsgFactory {
static editInflationParams(msg: MsgEditInflationParams): TxMessage {
return {
typeUrl: `/${protobufPackage}.MsgEditInflationParams`,
value: MsgEditInflationParams.fromPartial(msg),
}
}

static toggleInflation(msg: MsgToggleInflation): TxMessage {
return {
typeUrl: `/${protobufPackage}.MsgToggleInflation`,
value: MsgToggleInflation.fromPartial(msg),
}
export const setupInflationMsgExtension = (
base: QueryClient
): InflationMsgExtension => {
const queryService = new MsgClientImpl(createProtobufRpcClient(base))

return {
inflationMsg: {
toggleInflation: async (body: MsgToggleInflation) =>
queryService.ToggleInflation(MsgToggleInflation.fromPartial(body)),

editInflationParams: async (body: MsgEditInflationParams) =>
queryService.EditInflationParams(
MsgEditInflationParams.fromPartial(body)
),
},
}
}
Loading

0 comments on commit 32374dd

Please sign in to comment.