From 5c49d27df01e3db9057cb7229185798f00e65c29 Mon Sep 17 00:00:00 2001 From: Michael Kim Date: Sat, 21 Sep 2024 06:18:49 +0900 Subject: [PATCH] Add a function getSystemInfo() --- packages/client-test/package.json | 5 ++-- .../client-test/scripts/02-summary/system.ts | 29 +++++++++++++++++++ packages/client/package.json | 2 +- packages/client/src/interface/ILedger.ts | 5 +++- packages/client/src/interfaces.ts | 16 ++++++++++ .../src/internal/client/LedgerMethods.ts | 12 +++++++- yarn.lock | 11 +------ 7 files changed, 65 insertions(+), 15 deletions(-) create mode 100644 packages/client-test/scripts/02-summary/system.ts diff --git a/packages/client-test/package.json b/packages/client-test/package.json index eec5e17..3aca25d 100644 --- a/packages/client-test/package.json +++ b/packages/client-test/package.json @@ -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", diff --git a/packages/client-test/scripts/02-summary/system.ts b/packages/client-test/scripts/02-summary/system.ts new file mode 100644 index 0000000..cec4d47 --- /dev/null +++ b/packages/client-test/scripts/02-summary/system.ts @@ -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; +}); diff --git a/packages/client/package.json b/packages/client/package.json index ff7c334..21d7a86 100644 --- a/packages/client/package.json +++ b/packages/client/package.json @@ -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", diff --git a/packages/client/src/interface/ILedger.ts b/packages/client/src/interface/ILedger.ts index f211d98..c771bcc 100644 --- a/packages/client/src/interface/ILedger.ts +++ b/packages/client/src/interface/ILedger.ts @@ -18,7 +18,7 @@ import { WithdrawViaBridgeStepValue, LedgerAction, IAccountSummary, - RegisterAssistantStepValue + RegisterAssistantStepValue, ISystemInfo } from "../interfaces"; import { BigNumber } from "@ethersproject/bignumber"; import { BytesLike } from "@ethersproject/bytes"; @@ -120,4 +120,7 @@ export interface ILedgerMethods extends IClientCore { registerAssistant: (assistant: string) => AsyncGenerator; unregisterAssistant: () => AsyncGenerator; getAssistant: () => Promise; + + // System + getSystemInfo:() => Promise; } diff --git a/packages/client/src/interfaces.ts b/packages/client/src/interfaces.ts index 8256a41..033bae3 100644 --- a/packages/client/src/interfaces.ts +++ b/packages/client/src/interfaces.ts @@ -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 + } +} \ No newline at end of file diff --git a/packages/client/src/internal/client/LedgerMethods.ts b/packages/client/src/internal/client/LedgerMethods.ts index 0598a3b..c1713bd 100644 --- a/packages/client/src/internal/client/LedgerMethods.ts +++ b/packages/client/src/internal/client/LedgerMethods.ts @@ -45,7 +45,8 @@ import { WaiteBridgeSteps, LedgerAction, IAccountSummary, - RegisterAssistantStepValue + RegisterAssistantStepValue, + ISystemInfo } from "../../interfaces"; import { AmountMismatchError, @@ -1799,4 +1800,13 @@ export class LedgerMethods extends ClientCore implements ILedgerMethods { return res.data.assistant; } + + public async getSystemInfo(): Promise { + 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; + } } diff --git a/yarn.lock b/yarn.lock index 8ba11fd..e54a413 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8297,7 +8297,7 @@ workerpool@6.2.1: 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== @@ -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"