Skip to content

Commit

Permalink
Add a function getSystemInfo()
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelKim20 committed Sep 20, 2024
1 parent c265e63 commit 5c49d27
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 15 deletions.
5 changes: 3 additions & 2 deletions packages/client-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
"11-check:web3": "npx ts-node scripts/00-check/checkWeb3.ts",
"12-check:relay": "npx ts-node scripts/00-check/checkRelay.ts",
"13-check:link": "npx ts-node scripts/00-check/checkLink.ts",
"21-summary:account:account": "npx ts-node scripts/02-summary/account.ts",
"22-summary:account:shop": "npx ts-node scripts/02-summary/shop.ts",
"21-summary:account": "npx ts-node scripts/02-summary/account.ts",
"22-summary:shop": "npx ts-node scripts/02-summary/shop.ts",
"23-summary:system": "npx ts-node scripts/02-summary/system.ts",
"25-ledger:balance:token": "npx ts-node scripts/01-ledger/token.ts",
"26-ledger:balance:point": "npx ts-node scripts/01-ledger/point.ts",
"27-ledger:balance:unpayable": "npx ts-node scripts/01-ledger/unpayable.ts",
Expand Down
29 changes: 29 additions & 0 deletions packages/client-test/scripts/02-summary/system.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Helper } from "../utils";
import { BOACoin } from "../../src/Amount";
import { Client, Context, ContextBuilder } from "acc-sdk-client-v2";

async function main() {
const userInfo = Helper.loadUserInfo();
const contextParams = ContextBuilder.buildContextParams(Helper.NETWORK, userInfo.wallet.privateKey);
if (Helper.RELAY_ENDPOINT !== "") contextParams.relayEndpoint = Helper.RELAY_ENDPOINT;
if (Helper.WEB3_ENDPOINT !== "") contextParams.web3Provider = Helper.WEB3_ENDPOINT;
const context: Context = new Context(contextParams);
const client = new Client(context);

const info = await client.ledger.getSystemInfo();
console.log(`- tokenInfo`);
console.log(` - symbol: ${info.token.symbol}`);
console.log(`- pointInfo`);
console.log(` - precision: ${info.point.precision}`);
console.log(` - equivalent currency: ${info.point.equivalentCurrency}`);
console.log(`- language: ${info.language}`);
console.log(`- support`);
console.log(` - chain bridge: ${info.support.chainBridge}`);
console.log(` - loyalty bridge: ${info.support.loyaltyBridge}`);
console.log(` - exchange: ${info.support.exchange}`);
}

main().catch((error) => {
console.error(error);
process.exitCode = 1;
});
2 changes: 1 addition & 1 deletion packages/client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "acc-sdk-client-v2",
"version": "2.9.0",
"version": "2.10.0",
"author": "BOSagora Foundation",
"license": "AGPL-3.0-or-later",
"main": "dist/index.js",
Expand Down
5 changes: 4 additions & 1 deletion packages/client/src/interface/ILedger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
WithdrawViaBridgeStepValue,
LedgerAction,
IAccountSummary,
RegisterAssistantStepValue
RegisterAssistantStepValue, ISystemInfo
} from "../interfaces";
import { BigNumber } from "@ethersproject/bignumber";
import { BytesLike } from "@ethersproject/bytes";
Expand Down Expand Up @@ -120,4 +120,7 @@ export interface ILedgerMethods extends IClientCore {
registerAssistant: (assistant: string) => AsyncGenerator<RegisterAssistantStepValue>;
unregisterAssistant: () => AsyncGenerator<RegisterAssistantStepValue>;
getAssistant: () => Promise<string>;

// System
getSystemInfo:() => Promise<ISystemInfo>;
}
16 changes: 16 additions & 0 deletions packages/client/src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -687,3 +687,19 @@ export interface IShopSummary {
sideChain: IBalance;
protocolFees: IProtocolFees;
}

export interface ISystemInfo {
token: {
symbol: string;
},
point: {
precision: number,
equivalentCurrency: string;
},
language: string,
support: {
chainBridge: boolean,
loyaltyBridge: boolean,
exchange: boolean
}
}
12 changes: 11 additions & 1 deletion packages/client/src/internal/client/LedgerMethods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ import {
WaiteBridgeSteps,
LedgerAction,
IAccountSummary,
RegisterAssistantStepValue
RegisterAssistantStepValue,
ISystemInfo
} from "../../interfaces";
import {
AmountMismatchError,
Expand Down Expand Up @@ -1799,4 +1800,13 @@ export class LedgerMethods extends ClientCore implements ILedgerMethods {

return res.data.assistant;
}

public async getSystemInfo(): Promise<ISystemInfo> {
const res = await Network.get(await this.relay.getEndpoint(`/v1/system/info`));
if (res.code !== 0 || res.data === undefined) {
throw new InternalServerError(res?.error?.message ?? "");
}

return res.data;
}
}
11 changes: 1 addition & 10 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8297,7 +8297,7 @@ [email protected]:
resolved "https://registry.yarnpkg.com/workerpool/-/workerpool-6.2.1.tgz#46fc150c17d826b86a008e5a4508656777e9c343"
integrity sha512-ILEIE97kDZvF9Wb9f6h5aXK4swSlKGUcOEGiIYb2OOu/IrDU9iwj0fD//SsA6E5ibwJxpEvhullJY4Sl4GcpAw==

"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0":
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
Expand All @@ -8323,15 +8323,6 @@ wrap-ansi@^6.2.0:
string-width "^4.1.0"
strip-ansi "^6.0.0"

wrap-ansi@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
dependencies:
ansi-styles "^4.0.0"
string-width "^4.1.0"
strip-ansi "^6.0.0"

wrap-ansi@^8.1.0:
version "8.1.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214"
Expand Down

0 comments on commit 5c49d27

Please sign in to comment.