Skip to content

Commit

Permalink
feat: add fswap and fbridge module apis of Finschia v4 (#111)
Browse files Browse the repository at this point in the history
* add fswap module

* feat: support fbridge module

Signed-off-by: zemyblue <zemyblue@gmail.com>

* chore: add fbridge unittest

Signed-off-by: zemyblue <zemyblue@gmail.com>

* feat: bump up finschia-proto v4.0.0-rc1

Signed-off-by: zemyblue <zemyblue@gmail.com>

* chore: update changelog

Signed-off-by: zemyblue <zemyblue@gmail.com>

* feat: add amino sing test of fswap and fbridge.
and apply the finschia v4.0.0-rc2's changes

Signed-off-by: zemyblue <zemyblue@gmail.com>

* feat: add swapAndBridge function in SigningFinschiaClient

Signed-off-by: zemyblue <zemyblue@gmail.com>

* fix: unit test errors

Signed-off-by: zemyblue <zemyblue@gmail.com>

* chore: modify swap_rate from "148079656000000000000" to "148079656000000"

Signed-off-by: zemyblue <zemyblue@gmail.com>

---------

Signed-off-by: zemyblue <zemyblue@gmail.com>
  • Loading branch information
zemyblue committed May 13, 2024
1 parent 3bcbb93 commit 000f556
Show file tree
Hide file tree
Showing 58 changed files with 3,353 additions and 1,042 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]

### Added
- [\#111](https://github.com/Finschia/finschia-js/pull/111) add `fswap` and `fbridge` module apis of Finschia v4

### Changed

Expand Down
2 changes: 1 addition & 1 deletion packages/finschia/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"@cosmjs/stargate": "^0.31.0",
"@cosmjs/tendermint-rpc": "^0.31.0",
"@cosmjs/utils": "^0.31.0",
"@finschia/finschia-proto": "^2.0.0",
"@finschia/finschia-proto": "4.0.0-rc2",
"cosmjs-types": "^0.8.0",
"long": "^4.0.0",
"pako": "^2.0.2",
Expand Down
22 changes: 22 additions & 0 deletions packages/finschia/src/finschiaclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,17 @@ import { Channel } from "cosmjs-types/ibc/core/channel/v1/channel";
import {
CollectionExtension,
EvidenceExtension,
FbridgeExtension,
FeeGrantExtension,
FoundationExtension,
FswapExtension,
NodeExtension,
setupCollectionExtension,
setupEvidenceExtension,
setupFbridgeExtension,
setupFeeGrantExtension,
setupFoundationExtension,
setupFswapExtension,
setupNodeExtension,
setupTokenExtension,
setupTx2Extension,
Expand Down Expand Up @@ -102,6 +106,8 @@ export type QueryClientWithExtensions = QueryClient &
WasmplusExtension &
NodeExtension;

export type QueryClientForV4WithExtensions = QueryClient & FswapExtension & FbridgeExtension;

function createQueryClientWithExtensions(tmClient: TendermintClient): QueryClientWithExtensions {
return QueryClient.withExtensions(
tmClient,
Expand All @@ -126,15 +132,21 @@ function createQueryClientWithExtensions(tmClient: TendermintClient): QueryClien
);
}

function createQueryClientForV4WithExtension(tmClient: TendermintClient): QueryClientForV4WithExtensions {
return QueryClient.withExtensions(tmClient, setupFswapExtension, setupFbridgeExtension);
}

/** Use for testing only */
export interface PrivateFinschiaClient {
readonly tmClient: TendermintClient | undefined;
readonly queryClient: QueryClientWithExtensions | undefined;
readonly queryClientForV4: QueryClientForV4WithExtensions | undefined;
}

export class FinschiaClient {
private readonly tmClient: TendermintClient | undefined;
private readonly queryClient: QueryClientWithExtensions | undefined;
private readonly queryClientForV4: QueryClientForV4WithExtensions | undefined;
private readonly codesCache = new Map<number, CodeDetails>();
private chainId: string | undefined;
private readonly accountParser: AccountParser;
Expand All @@ -151,6 +163,7 @@ export class FinschiaClient {
if (tmClient) {
this.tmClient = tmClient;
this.queryClient = createQueryClientWithExtensions(tmClient);
this.queryClientForV4 = createQueryClientForV4WithExtension(tmClient);
}
const { accountParser = accountFromAny } = options;
this.accountParser = accountParser;
Expand Down Expand Up @@ -180,6 +193,15 @@ export class FinschiaClient {
return this.queryClient;
}

protected forceGetQueryClientForV4(): QueryClientForV4WithExtensions {
if (!this.queryClientForV4) {
throw new Error(
"Query client for v4 not avaliable. You cannot use online functionality in offline mode.",
);
}
return this.queryClientForV4;
}

public async getChainId(): Promise<string> {
if (!this.chainId) {
const response = await this.forceGetTmClient().status();
Expand Down
2 changes: 1 addition & 1 deletion packages/finschia/src/modules/collection/queries.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { createProtobufRpcClient, QueryClient } from "@cosmjs/stargate";
import { assert } from "@cosmjs/utils";
import { Any } from "cosmjs-types/google/protobuf/any";
import { Coin, Contract, Grant, NFT, TokenType } from "@finschia/finschia-proto/lbm/collection/v1/collection";
import { QueryClientImpl } from "@finschia/finschia-proto/lbm/collection/v1/query";
import { Any } from "cosmjs-types/google/protobuf/any";

export interface CollectionExtension {
readonly collection: {
Expand Down
Loading

0 comments on commit 000f556

Please sign in to comment.