Skip to content

Commit

Permalink
first release
Browse files Browse the repository at this point in the history
  • Loading branch information
karnthis committed Apr 23, 2024
1 parent af24059 commit ea30990
Show file tree
Hide file tree
Showing 41 changed files with 231 additions and 204 deletions.
12 changes: 6 additions & 6 deletions docs/classes/IbcQueryClient.html

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions docs/classes/IbcSigningClient.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/classes/WebsocketCore.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/functions/makeListener.html

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions docs/interfaces/IExtendedSigningStargateClientOptions.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/interfaces/IExtendedStargateClientOptions.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/interfaces/IIbcDeafenBundle.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/interfaces/IIbcDisengageBundle.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/interfaces/IIbcEngageBundle.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/interfaces/IIbcMakeListenerBundle.html

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions docs/interfaces/IIbcQueryClient.html

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions docs/interfaces/IIbcSigningClient.html

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions docs/interfaces/IIndexedTx.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/interfaces/IListener.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/interfaces/IMsgData.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/interfaces/ISignAndBroadcastOptions.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/interfaces/ITxLibraryChapter.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/interfaces/IWebsocketCore.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/types/DCoin.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/types/DDeliverTxResponse.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/types/DEncodeObject.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/types/DHttpEndpoint.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/types/DStdFee.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/types/DTxMsgData.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/types/TCreateExtension.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/types/TCurrentTxEvent.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/types/TCustomModule.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/types/TCustomModuleMap.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/types/TMergedSigner.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/types/TPossibleTxEvents.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/types/TQueryLibrary.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/types/TTxLibrary.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jackallabs/banshee",
"version": "0.0.0-rc.6",
"version": "0.1.0",
"description": "Modern problems require modern solutions",
"keywords": [],
"exports": {
Expand Down
8 changes: 6 additions & 2 deletions src/classes/ibcQueryClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { connectComet } from '@cosmjs/tendermint-rpc'
import { processExtensions } from '@/utils/extensions'
import { WebsocketCore } from '@/classes'
import {
IExtendedStargateClientOptions, IIbcDeafenBundle,
IExtendedStargateClientOptions,
IIbcDeafenBundle,
IIbcDisengageBundle,
IIbcEngageBundle,
IIbcQueryClient,
Expand All @@ -15,7 +16,10 @@ import type { TPossibleTxEvents, TQueryLibrary } from '@/types'
/**
* @class {IIbcQueryClient} IbcQueryClient
*/
export class IbcQueryClient<TQ extends TQueryLibrary> extends StargateClient implements IIbcQueryClient<TQ> {
export class IbcQueryClient<TQ extends TQueryLibrary>
extends StargateClient
implements IIbcQueryClient<TQ>
{
public readonly queries: TQ
protected readonly wsCore: IWebsocketCore

Expand Down
157 changes: 81 additions & 76 deletions src/classes/ibcSigningClient.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {SigningStargateClient} from '@cosmjs/stargate'
import {CometClient, connectComet} from '@cosmjs/tendermint-rpc'
import {createDefaultRegistry} from '@/utils/registry'
import {processExtensions} from '@/utils/extensions'
import {WebsocketCore} from '@/classes'
import type {OfflineSigner} from '@cosmjs/launchpad'
import type {ISignAndBroadcastOptions} from '@/interfaces/ISignAndBroadcastOptions'
import { SigningStargateClient } from '@cosmjs/stargate'
import { CometClient, connectComet } from '@cosmjs/tendermint-rpc'
import { createDefaultRegistry } from '@/utils/registry'
import { processExtensions } from '@/utils/extensions'
import { WebsocketCore } from '@/classes'
import type { OfflineSigner } from '@cosmjs/launchpad'
import type { ISignAndBroadcastOptions } from '@/interfaces/ISignAndBroadcastOptions'
import type {
DDeliverTxResponse,
DEncodeObject,
Expand All @@ -14,87 +14,92 @@ import type {
TTxLibrary
} from '@/types'
import {
IExtendedSigningStargateClientOptions, IIbcDeafenBundle,
IIbcDisengageBundle,
IIbcEngageBundle,
IIbcSigningClient,
IWebsocketCore
IExtendedSigningStargateClientOptions,
IIbcDeafenBundle,
IIbcDisengageBundle,
IIbcEngageBundle,
IIbcSigningClient,
IWebsocketCore
} from '@/interfaces'

/**
* @class {IIbcSigningClient} IbcSigningClient
*/
export class IbcSigningClient<TQ extends TQueryLibrary, TT extends TTxLibrary>
extends SigningStargateClient
implements IIbcSigningClient<TQ, TT> {
public readonly queries: TQ
public readonly txLibrary: TT
protected readonly address: string
protected readonly wsCore: IWebsocketCore
extends SigningStargateClient
implements IIbcSigningClient<TQ, TT>
{
public readonly queries: TQ
public readonly txLibrary: TT
protected readonly address: string
protected readonly wsCore: IWebsocketCore

protected constructor(
tmClient: CometClient,
signer: OfflineSigner,
address: string,
options: IExtendedSigningStargateClientOptions,
) {
super(tmClient, signer, options)
const {queryExtensions = [], txLibrary = {}} = options
this.address = address
this.queries = processExtensions(tmClient, queryExtensions) as TQ
this.txLibrary = txLibrary as TT
this.wsCore = new WebsocketCore()
}
protected constructor(
tmClient: CometClient,
signer: OfflineSigner,
address: string,
options: IExtendedSigningStargateClientOptions,
) {
super(tmClient, signer, options)
const { queryExtensions = [], txLibrary = {} } = options
this.address = address
this.queries = processExtensions(tmClient, queryExtensions) as TQ
this.txLibrary = txLibrary as TT
this.wsCore = new WebsocketCore()
}

/**
* @function connectWithSigner
* @memberof IbcSigningClient
* @async
* @static
*/
public static async connectWithSigner<TQ extends TQueryLibrary, TT extends TTxLibrary> (
endpoint: string | DHttpEndpoint,
signer: OfflineSigner,
options: IExtendedSigningStargateClientOptions = {},
): Promise<IIbcSigningClient<TQ, TT>> {
try {
const client = await connectComet(endpoint)
const {address} = (await signer.getAccounts())[0]
const {customModules = []} = options
return new IbcSigningClient<TQ, TT>(client, signer, address, {
registry: createDefaultRegistry(customModules),
...options,
})
} catch (err) {
throw err
}
/**
* @function connectWithSigner
* @memberof IbcSigningClient
* @async
* @static
*/
public static async connectWithSigner<
TQ extends TQueryLibrary,
TT extends TTxLibrary,
>(
endpoint: string | DHttpEndpoint,
signer: OfflineSigner,
options: IExtendedSigningStargateClientOptions = {},
): Promise<IIbcSigningClient<TQ, TT>> {
try {
const client = await connectComet(endpoint)
const { address } = (await signer.getAccounts())[0]
const { customModules = [] } = options
return new IbcSigningClient<TQ, TT>(client, signer, address, {
registry: createDefaultRegistry(customModules),
...options,
})
} catch (err) {
throw err
}
}

async monitor<T extends TPossibleTxEvents>(
connections: IIbcEngageBundle<T> | IIbcEngageBundle<T>[],
): Promise<void> {
await this.wsCore.monitor(connections)
}
async monitor<T extends TPossibleTxEvents>(
connections: IIbcEngageBundle<T> | IIbcEngageBundle<T>[],
): Promise<void> {
await this.wsCore.monitor(connections)
}

disengage(connections: IIbcDisengageBundle | IIbcDisengageBundle[]): void {
this.wsCore.disengage(connections)
}
disengage(connections: IIbcDisengageBundle | IIbcDisengageBundle[]): void {
this.wsCore.disengage(connections)
}

deafen(connection: IIbcDeafenBundle): void {
this.wsCore.deafen(connection)
}
deafen(connection: IIbcDeafenBundle): void {
this.wsCore.deafen(connection)
}

async selfSignAndBroadcast(
msgs: DEncodeObject[],
options: ISignAndBroadcastOptions = {},
): Promise<DDeliverTxResponse> {
const {fee, memo, timeoutHeight} = {
fee: {
amount: [],
gas: (msgs.length * 100000).toString(),
},
...options,
}
return this.signAndBroadcast(this.address, msgs, fee, memo, timeoutHeight)
async selfSignAndBroadcast(
msgs: DEncodeObject[],
options: ISignAndBroadcastOptions = {},
): Promise<DDeliverTxResponse> {
const { fee, memo, timeoutHeight } = {
fee: {
amount: [],
gas: (msgs.length * 100000).toString(),
},
...options,
}
return this.signAndBroadcast(this.address, msgs, fee, memo, timeoutHeight)
}
}
26 changes: 20 additions & 6 deletions src/classes/websocketCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ import type { CometClient } from '@cosmjs/tendermint-rpc'
import { connectComet } from '@cosmjs/tendermint-rpc'
import type { Stream } from 'xstream'
import type { TPossibleTxEvents } from '@/types'
import { IIbcDeafenBundle, IIbcDisengageBundle, IIbcEngageBundle, IWebsocketCore } from '@/interfaces'
import {
IIbcDeafenBundle,
IIbcDisengageBundle,
IIbcEngageBundle,
IWebsocketCore,
} from '@/interfaces'

export class WebsocketCore implements IWebsocketCore {
protected readonly wsConnections: Record<string, CometClient>
Expand Down Expand Up @@ -35,25 +40,34 @@ export class WebsocketCore implements IWebsocketCore {
delete this.activeStreams[`${conn.chainId}|${conn.query || 'all'}`]
}
} else {
delete this.activeStreams[`${connections.chainId}|${connections.query || 'all'}`]
delete this.activeStreams[
`${connections.chainId}|${connections.query || 'all'}`
]
}
}

deafen(connection: IIbcDeafenBundle): void {
this.activeStreams[`${connection.chainId}|${connection.query || 'all'}`].removeListener(connection.listener)
this.activeStreams[
`${connection.chainId}|${connection.query || 'all'}`
].removeListener(connection.listener)
}

protected async setupMonitoring<T extends TPossibleTxEvents>(conn: IIbcEngageBundle<T>) {
protected async setupMonitoring<T extends TPossibleTxEvents>(
conn: IIbcEngageBundle<T>,
) {
if (!this.wsConnections[conn.chainId]) {
this.wsConnections[conn.chainId] = await connectComet(conn.endpoint)
}
const client = this.wsConnections[conn.chainId]
const streamId = `${conn.chainId}|${conn.query || 'all'}`
if (!this.activeStreams[streamId]) {
if (conn.query) {
this.activeStreams[streamId] = client.subscribeTx(conn.query) as Stream<TPossibleTxEvents>
this.activeStreams[streamId] = client.subscribeTx(
conn.query,
) as Stream<TPossibleTxEvents>
} else {
this.activeStreams[streamId] = client.subscribeTx() as Stream<TPossibleTxEvents>
this.activeStreams[streamId] =
client.subscribeTx() as Stream<TPossibleTxEvents>
}
}
this.activeStreams[streamId].addListener(conn.listener)
Expand Down
4 changes: 2 additions & 2 deletions src/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ type Modify<T, R extends PartialAny<T>> = Omit<T, keyof R> & R

type ModifyDeep<A, B extends DeepPartialAny<A>> = {
// https://stackoverflow.com/a/74216680/985454
[K in keyof A | keyof B]: /**/ K extends keyof A // For all keys in A and B: ... // ───┐
[K in keyof A | keyof B /**/]: K extends keyof A // For all keys in A and B: ... // ───┐
? /**/ K extends keyof B // ───n ─ y ? key K exists in both A and B ...
? /* */ A[K] extends AnyObject // │ ─┴──┐
? /* */ B[K] extends AnyObject // │ ─── n ─ y ? both A and B are objects ...
Expand All @@ -187,7 +187,7 @@ type ModifyDeep<A, B extends DeepPartialAny<A>> = {

type ModifyDeep1<A, B extends DeepPartialAny<A>> = {
// https://stackoverflow.com/a/74216680/985454
[K in keyof A | keyof B]: /**/ K extends keyof A // For all keys in A and B: ... // ───┐
[K in keyof A | keyof B /**/]: K extends keyof A // For all keys in A and B: ... // ───┐
? /* */ K extends keyof B // ── n ─ y ? key K exists in both A and B ...
? /* */ A[K] extends AnyObject // │ ─┴──┐
? /* */ B[K] extends AnyObject // │ ─── n ─ y ? both A and B are objects ...
Expand Down
12 changes: 7 additions & 5 deletions src/interfaces/classes/IIbcQueryClient.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import type {IWebsocketCore} from '@/interfaces'
import type {StargateClient} from '@cosmjs/stargate'
import type {TQueryLibrary} from "@/types";
import type { IWebsocketCore } from '@/interfaces'
import type { StargateClient } from '@cosmjs/stargate'
import type { TQueryLibrary } from '@/types'

/**
* @interface IIbcQueryClient
* @extends StargateClient - [More here](https://cosmos.github.io/cosmjs/latest/stargate/classes/StargateClient.html)
*/
export interface IIbcQueryClient<TQ extends TQueryLibrary> extends StargateClient, IWebsocketCore {
readonly queries: TQ
export interface IIbcQueryClient<TQ extends TQueryLibrary>
extends StargateClient,
IWebsocketCore {
readonly queries: TQ
}
34 changes: 18 additions & 16 deletions src/interfaces/classes/IIbcSigningClient.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type {SigningStargateClient} from '@cosmjs/stargate'
import type { SigningStargateClient } from '@cosmjs/stargate'
import type { DDeliverTxResponse, DEncodeObject, TQueryLibrary, TTxLibrary } from '@/types'
import type {ISignAndBroadcastOptions, IWebsocketCore} from '@/interfaces'
import type { ISignAndBroadcastOptions, IWebsocketCore } from '@/interfaces'

/**
* @interface IIbcSigningClient
Expand All @@ -9,20 +9,22 @@ import type {ISignAndBroadcastOptions, IWebsocketCore} from '@/interfaces'
* @property {TTxLibrary} txLibrary
* @property {selfSignAndBroadcast} selfSignAndBroadcast
*/
export interface IIbcSigningClient<TQ extends TQueryLibrary, TT extends TTxLibrary>
extends SigningStargateClient,
export interface IIbcSigningClient<
TQ extends TQueryLibrary,
TT extends TTxLibrary,
> extends SigningStargateClient,
IWebsocketCore {
readonly queries: TQ
readonly txLibrary: TT
readonly queries: TQ
readonly txLibrary: TT

/**
* @function selfSignAndBroadcast
* @param {DEncodeObject[]} msgs
* @param {ISignAndBroadcastOptions} [options]
* @returns Promise<DDeliverTxResponse>
*/
selfSignAndBroadcast(
msgs: DEncodeObject[],
options?: ISignAndBroadcastOptions,
): Promise<DDeliverTxResponse>
/**
* @function selfSignAndBroadcast
* @param {DEncodeObject[]} msgs
* @param {ISignAndBroadcastOptions} [options]
* @returns Promise<DDeliverTxResponse>
*/
selfSignAndBroadcast(
msgs: DEncodeObject[],
options?: ISignAndBroadcastOptions,
): Promise<DDeliverTxResponse>
}
Loading

0 comments on commit ea30990

Please sign in to comment.