From 72d4fdd6096468191e85ef79868f30cba54a3987 Mon Sep 17 00:00:00 2001 From: Abhay <67417765+AbhayAysola@users.noreply.github.com> Date: Mon, 29 Mar 2021 09:02:00 +0530 Subject: [PATCH 1/5] Add getBankPV method in Bank class --- src/bank.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/bank.ts b/src/bank.ts index 2c4568fb..d442c899 100644 --- a/src/bank.ts +++ b/src/bank.ts @@ -141,4 +141,12 @@ export class Bank extends ServerNode { async getValidators(options: Partial = {}) { return await super.getPaginatedData("/validators", options); } + + /** + * Gets the PrimaryValidator for the current bank. + */ + async getBankPV() { + const { primary_validator } = await await this.getConfig(); + return `${primary_validator.protocol}://${primary_validator.ip_address}:${primary_validator.port}`; + } } From cab05820baa0383f7dbd8f1888964d7b44184acb Mon Sep 17 00:00:00 2001 From: Abhay <67417765+AbhayAysola@users.noreply.github.com> Date: Mon, 29 Mar 2021 09:06:04 +0530 Subject: [PATCH 2/5] Add getBankPV docs --- docs/bank.md | 9 +++++++++ docs/index.md | 9 ++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/docs/bank.md b/docs/bank.md index 35be6678..d6f50521 100644 --- a/docs/bank.md +++ b/docs/bank.md @@ -507,3 +507,12 @@ console.log(res); ``` > If you don't understand upgradeRequest and upgradeNotice, check out the [documentation](https://thenewboston.com/guide/resync-process) at thenewboston.com + +## Getting the Bank's Primary Validator + +Simply use the `Bank.getBankPV` method which returns the formatted url of the Primary Validator + +```ts +const bank = new tnb.Bank("http://143.110.137.54"); +const pv = new tnb.PrimaryValidator(await bank.getBankPV()); +``` diff --git a/docs/index.md b/docs/index.md index 571a01a3..055c684e 100644 --- a/docs/index.md +++ b/docs/index.md @@ -5,9 +5,10 @@ Here, you will learn about how to use all of what thenewboston-js has to offer. ## Getting Started There are two ways to use the library. - - Clone the repository / download the files and load them into your project. - - Using NPM ``npm install thenewboston ``, this will install the library to your package.json file - + +- Clone the repository / download the files and load them into your project. +- Using NPM `npm install thenewboston `, this will install the library to your package.json file + > For simplicity, we will not be including `import` or `require` statements in our examples. ## Table of Contents @@ -46,6 +47,8 @@ There are two ways to use the library. - [Sending Upgrade Notice and Upgrade Request](bank.md#sending-upgrade-notice-and-upgrade-request) + - [Getting the Bank's Primary Validator](bank.md#getting-the-bank's-primary-validator) + - [Validator](validator.md#validator) - [Creating Validators](validator.md#creating-banks) From e5bf8440b1bfd2ed6964b33cee4d11f8a8c030ca Mon Sep 17 00:00:00 2001 From: Abhay <67417765+AbhayAysola@users.noreply.github.com> Date: Mon, 29 Mar 2021 11:07:54 +0530 Subject: [PATCH 3/5] Update bank.ts --- src/bank.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bank.ts b/src/bank.ts index d442c899..178d84d4 100644 --- a/src/bank.ts +++ b/src/bank.ts @@ -146,7 +146,7 @@ export class Bank extends ServerNode { * Gets the PrimaryValidator for the current bank. */ async getBankPV() { - const { primary_validator } = await await this.getConfig(); + const { primary_validator } = await this.getConfig(); return `${primary_validator.protocol}://${primary_validator.ip_address}:${primary_validator.port}`; } } From 3d35800a320179ea4b2baf782048bdda55666455 Mon Sep 17 00:00:00 2001 From: Abhay <67417765+AbhayAysola@users.noreply.github.com> Date: Mon, 29 Mar 2021 13:50:32 +0530 Subject: [PATCH 4/5] Return PV object from Bank.getBankPV method --- src/bank.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/bank.ts b/src/bank.ts index 178d84d4..0d3f92d1 100644 --- a/src/bank.ts +++ b/src/bank.ts @@ -1,4 +1,5 @@ import { ServerNode } from "./server-node"; +import { PrimaryValidator } from "./primary-validator"; import type { PaginationOptions, BankConfigResponse, @@ -147,6 +148,8 @@ export class Bank extends ServerNode { */ async getBankPV() { const { primary_validator } = await this.getConfig(); - return `${primary_validator.protocol}://${primary_validator.ip_address}:${primary_validator.port}`; + return new PrimaryValidator( + `${primary_validator.protocol}://${primary_validator.ip_address}:${primary_validator.port}` + ); } } From 30fcbc4bdeacf5a11d03a7fa8b61f9aafb8feb84 Mon Sep 17 00:00:00 2001 From: Abhay <67417765+AbhayAysola@users.noreply.github.com> Date: Mon, 29 Mar 2021 14:19:59 +0530 Subject: [PATCH 5/5] Update bank.md --- docs/bank.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/bank.md b/docs/bank.md index d6f50521..afe51928 100644 --- a/docs/bank.md +++ b/docs/bank.md @@ -514,5 +514,5 @@ Simply use the `Bank.getBankPV` method which returns the formatted url of the Pr ```ts const bank = new tnb.Bank("http://143.110.137.54"); -const pv = new tnb.PrimaryValidator(await bank.getBankPV()); +const pv = await bank.getBankPV(); ```