Skip to content

Commit

Permalink
feat: Get bank pv (#89)
Browse files Browse the repository at this point in the history
* Add getBankPV method in Bank class

* Add getBankPV docs

* Update bank.ts

* Return PV object from Bank.getBankPV method

* Update bank.md
  • Loading branch information
AbhayAysola authored Mar 29, 2021
1 parent 28b3ca9 commit 99b0d17
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
9 changes: 9 additions & 0 deletions docs/bank.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 = await bank.getBankPV();
```
9 changes: 6 additions & 3 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
11 changes: 11 additions & 0 deletions src/bank.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ServerNode } from "./server-node";
import { PrimaryValidator } from "./primary-validator";
import type {
PaginationOptions,
BankConfigResponse,
Expand Down Expand Up @@ -141,4 +142,14 @@ export class Bank extends ServerNode {
async getValidators(options: Partial<PaginationOptions> = {}) {
return await super.getPaginatedData<PaginatedValidatorEntry>("/validators", options);
}

/**
* Gets the PrimaryValidator for the current bank.
*/
async getBankPV() {
const { primary_validator } = await this.getConfig();
return new PrimaryValidator(
`${primary_validator.protocol}://${primary_validator.ip_address}:${primary_validator.port}`
);
}
}

0 comments on commit 99b0d17

Please sign in to comment.