From 951971cc319549fe4937a2e40412181edd6bbe19 Mon Sep 17 00:00:00 2001 From: Alexandr Date: Tue, 5 Nov 2024 21:09:05 +0300 Subject: [PATCH 1/2] add get alias details method --- server/src/server.ts | 19 +++++++++++++++++++ server/src/types.ts | 6 ++++++ 2 files changed, 25 insertions(+) diff --git a/server/src/server.ts b/server/src/server.ts index c8d0382..3815885 100644 --- a/server/src/server.ts +++ b/server/src/server.ts @@ -7,6 +7,7 @@ import { ValidationParams, BalanceInfo, TxInfo, + AliasDetails, } from "./types"; import { ZANO_ASSET_ID, ZanoError } from "./utils"; @@ -292,6 +293,24 @@ class ServerWallet { return txs.data.result as TxInfo; } + async getAliasDetails(alias: string) { + try { + const response = await this.fetchDaemon("get_alias_details", { + alias, + }); + if (response.data.result) { + return response.data.result as AliasDetails; + } else { + throw new ZanoError( + `Error fetching alias ${alias}`, + "ALIAS_FETCH_ERROR" + ); + } + } catch { + throw new ZanoError("Failed to fetch alias", "ALIAS_FETCH_ERROR"); + } +} + } export default ServerWallet; diff --git a/server/src/types.ts b/server/src/types.ts index 5c27e5a..287e9a6 100644 --- a/server/src/types.ts +++ b/server/src/types.ts @@ -100,4 +100,10 @@ export interface TxInfo { }; total_transfers: number; transfers: Transfer[]; +} + +export interface AliasDetails { + address: string; + comment: string; + tracking_key: string; } \ No newline at end of file From 3e16251ddfac3d42f23a4cc4756721fe77a1bc10 Mon Sep 17 00:00:00 2001 From: Alexandr Date: Tue, 5 Nov 2024 23:06:12 +0300 Subject: [PATCH 2/2] add readme --- README.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/README.md b/README.md index d48e2ac..c5d41dc 100644 --- a/README.md +++ b/README.md @@ -204,6 +204,7 @@ export interface Wallet { - `sendTransfer(assetId: string, address: string, amount: string)`: Sends a transfer to an address. - `getBalances()`: Retrieves the balances. - `validateWallet(rpcUrl: string, authData: AuthData)`: Validates the wallet. +- `getAliasDetails(alias:string)` : Retrieves information about a specific address alias. #### 1. **Updating Wallet RPC URL** @@ -370,6 +371,28 @@ import { AuthData } from "./types"; })(); ``` +#### 9. **Get Alias details** + +```javascript +import { ServerWallet } from "zano_web3/server"; + +const alias = "alias"; + +(async (alias) => { + const zanoServerAPI = new ServerWallet({ + walletUrl: "http://127.0.0.1:11211/json_rpc", + daemonUrl: "http://127.0.0.1:11211/json_rpc" + }); + + try { + const aliasDetails = await zanoServerAPI.getAliasDetails(alias); + console.log(aliasDetails); + } catch (error) { + console.error(error.message); + } +})(alias); +``` + ## Requirements - Correct RPC URLs for the wallet and daemon. \ No newline at end of file