Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Get bank pv #89

Merged
merged 5 commits into from
Mar 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}`
);
}
}