Skip to content

Commit

Permalink
v1.1.0-alpha.1
Browse files Browse the repository at this point in the history
v1.1.0-alpha.1
  • Loading branch information
zinoadidi authored Apr 9, 2021
2 parents f1d03ad + 9c62066 commit 5a282f2
Show file tree
Hide file tree
Showing 11 changed files with 256 additions and 58 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

## [1.1.0-alpha.1](https://github.com/thenewboston-developers/thenewboston-js/compare/v1.1.0-alpha.0...v1.1.0-alpha.1) (2021-04-09)

### Features

* feat: Get Methods for Single nodes ([#121](https://github.com/thenewboston-developers/thenewboston-js/issues/121)) ([be17ed9](https://github.com/thenewboston-developers/thenewboston-js/commit/be17ed9d1f50d6a439bbfd4efb1506b324b384e0))
* feat: added updateBankTrust, updateValidatorTrust ([#118](https://github.com/thenewboston-developers/thenewboston-js/issues/118)) ([32e1e1c](https://github.com/thenewboston-developers/thenewboston-js/commit/32e1e1c2afd549bfde80ca4fccc29da55ab5ee32))

### Bug Fixes

* Updated CV and Pv response types ([#133](https://github.com/thenewboston-developers/thenewboston-js/issues/133)) ([7191322](https://github.com/thenewboston-developers/thenewboston-js/commit/7191322e956bc4e2ac4bf47c45a4a075917e8c0d))

## [1.1.0-alpha.0](https://github.com/thenewboston-developers/thenewboston-js/compare/v1.0.3...v1.1.0-alpha.0) (2021-04-01)


Expand Down
40 changes: 6 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,50 +1,21 @@
[ ![Issues](https://img.shields.io/github/issues/thenewboston-developers/thenewboston-js?color=0088ff) ](https://github.com/thenewboston-developers/thenewboston-js/issues) [ ![GitHub pull requests](https://img.shields.io/github/issues-pr/thenewboston-developers/thenewboston-js?color=0088ff) ](https://github.com/thenewboston-developers/thenewboston-js/pulls)  [![thenewboston on npm](https://img.shields.io/npm/v/thenewboston?logo=npm&logoColor=fff&label=NPM+package&color=limegreen)](https://www.npmjs.com/package/thenewboston) [ ![Stars](https://img.shields.io/github/stars/thenewboston-developers/thenewboston-js.svg) ](https://github.com/thenewboston-developers/thenewboston-js/stargazers) [ ![All contributors](https://img.shields.io/github/contributors/thenewboston-developers/thenewboston-js.svg) ](https://github.com/thenewboston-developers/thenewboston-js/graphs/contributors)


## Overview

JavaScript library for thenewboston.

## Contributing Guide

Here you can learn about how you can help make thenewboston-js a robust and simple JavaScript library to use!

### Setup

Make sure you clone the official repository. Here is the command to run if you want to clone with git:

```sh
> git clone https://github.com/thenewboston-developers/thenewboston-js.git
```

After that, you should see a new folder named `thenewboston-js` in your current working directory. Navigate into that project and you're ready to go!

### Development

Before you are able to access any of the npm commands, you must first run `npm install` or `npm i` to get all of the modules loaded into your local project.

### Building

If you are ready to test out your changes, run `npm run build`. After that, you should see the CommonJS module located in the `dist` directory. You can create a `dev.js` file with something like the following code if you want to test out your changes:

```js
const tnb = require("./"); // loads the module from the path in the `package.json`

async function main() {
/* Code! */
}

main();
```

### Contributing

Create your fork / branch from the development branch, All pull requests to be made to development branch for review.
Find out how you can contribute [here](https://github.com/thenewboston-developers/thenewboston-js/blob/master/docs/CONTRIBUTING.md).

### Testing

Some day...

## Documentation

Check out the [documentation here](docs/index.md).
Check out the [documentation here](https://github.com/thenewboston-developers/thenewboston-js/blob/master/docs/index.md).

## Community

Expand All @@ -70,6 +41,7 @@ All donations will go to thenewboston to help fund the team to continue to devel
| ![Bitcoin Logo](https://github.com/thenewboston-developers/Website/raw/development/src/assets/images/bitcoin.png) | 3GZYi3w3BXQfyb868K2phHjrS4i8LooaHh |
| ![Ethereum Logo](https://github.com/thenewboston-developers/Website/raw/development/src/assets/images/ethereum.png) | 0x0E38e2a838F0B20872E5Ff55c82c2EE7509e6d4A |


## License

thenewboston is [MIT licensed](http://opensource.org/licenses/MIT).
35 changes: 35 additions & 0 deletions docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
## Contributing Guide

Here you can learn about how you can help make thenewboston-js a robust and simple JavaScript library to use!

### Setup

Make sure you clone the official repository. Here is the command to run if you want to clone with git:

```sh
> git clone https://github.com/thenewboston-developers/thenewboston-js.git
```

After that, you should see a new folder named `thenewboston-js` in your current working directory. Navigate into that project and you're ready to go!

### Development

Before you are able to access any of the npm commands, you must first run `npm install` or `npm i` to get all of the modules loaded into your local project.

### Building

If you are ready to test out your changes, run `npm run build`. After that, you should see the CommonJS module located in the `dist` directory. You can create a `dev.js` file with something like the following code if you want to test out your changes:

```js
const tnb = require("./"); // loads the module from the path in the `package.json`

async function main() {
/* Code! */
}

main();
```

### Contributing

Create your fork / branch from the development branch, All pull requests to be made to development branch for review.
119 changes: 115 additions & 4 deletions docs/bank.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,15 @@ console.log(accounts);

We can also update the trust of a specific account.

This is an API call to update the level of trust of a specific account. We use `Bank.updateAccount` for this.
This is an API call to update the level of trust of a specific account. We use `Bank.updateAccountTrust` for this.

```ts
const account = new Account("0cdd4ba04456ca169baca3d66eace869520c62fe84421329086e03d91a68acdb", "fakeSigningKeyHex");
const res = await bank.updateAccount("0cdd4ba04456ca169baca3d66eace869520c62fe84421329086e03d91a68acdb", 32, account);
const res = await bank.updateAccountTrust(
"0cdd4ba04456ca169baca3d66eace869520c62fe84421329086e03d91a68acdb",
32,
account
);
console.log(res);
// {
// "id": "64426fc5-b3ac-42fb-b75b-d5ccfcdc6872",
Expand Down Expand Up @@ -219,7 +223,7 @@ console.log(transactions);

> Just like with `Bank.getAccounts`, you can also pass in an options object here.
## Getting Banks
## Getting Banks and Updating Trust

This is similar to the [previous section](#getting-transactions), we are just making an API call.

Expand Down Expand Up @@ -261,6 +265,59 @@ console.log(banks);

> As expected, the options object can also be used with this.
#### Getting a single Bank

The `getBank()` method is used to get a specified bank of the bank.

```ts
const bankNodeId = "// node_identifier: '59af0721c572e6032b835722b5fec22110daad069dc135f1e81794747dbe626f',
";

const res = await bank.getBank(bankNodeId);
console.log(res);

// {
// account_number: '9a275161478536d0a5b88ff05d429b9a9e63d0032a46e7a6a8f088da89c69da5',
// ip_address: '13.57.215.62',
// node_identifier: '59af0721c572e6032b835722b5fec22110daad069dc135f1e81794747dbe626f',
// port: 80,
// protocol: 'http',
// version: 'v1.0',
// default_transaction_fee: 1,
// trust: '50.00'
// }
```

#### Updating Bank Trust

We can also update the trust of a specific bank by using the `updateBankTrust` method.

```ts
const networkIdKeyPair = new Account("fakeSigningKeyHex");

const bankToUpdate = "0cdd4ba04456ca169baca3d66eace869520c62fe84421329086e03d91a68acdb";

const res = await bank.updateAccountTrust(bankToUpdate, 50, networkIdKeyPair);

console.log(res);
// {
// account_number: 'd62165ea6102a74fd484176226cd6ed8f7fc779117138e3ee2d9881ff4fc5a04',
// ip_address: '144.126.219.17',
// node_identifier: '38ce9d9a245b2c5c923b1a6e8bbf5324a8cd57d71c977aef6a457740d7fd6451',
// port: 80,
// protocol: 'http',
// version: 'v1.4',
// default_transaction_fee: 1,
// root_account_file: 'http://144.126.219.17:80/media/root_account_file.json',
// root_account_file_hash: 'ab9b95e5bb1dc66dd57ebf2cb8a8dece41748389d68077f74c916659f4bd2f1b',
// seed_block_identifier: '',
// daily_confirmation_rate: 1,
// trust: '50.00'
// }
```

<br>

## Getting and Adding Blocks

Getting a list of blocks is quite similar to all the previous API calls. For this, we use `Bank.getBlocks`.
Expand Down Expand Up @@ -405,7 +462,7 @@ We use `Bank.getConfirmationBlocks` to get the confirmation blocks and `Bank.get

> Both of these methods support the options object
## Getting Validators and Validator Confirmation Services
## Getting Validators and Updating Trust

The `Bank.getValidators` method is used to get all connected validators of the bank.

Expand Down Expand Up @@ -450,6 +507,60 @@ console.log(res);
// }
```

#### Getting a single Validator

The `getValidator()` method is used to get a specified validator of the bank.

```ts
const validatorNodeId = "01181490ac0fa6f73bd980adb81f1a3e72f81eb6b4ccab4dac8b6db7544e5eb1";

const res = await bank.getValidator(validatorNodeId);
console.log(res);

// {
// account_number: 'd2018eb4a13ea1ed307aa8f73207bc1cbad3fac0070899ff5af158982ae7a804',
// ip_address: '18.218.193.164',
// node_identifier: '01181490ac0fa6f73bd980adb81f1a3e72f81eb6b4ccab4dac8b6db7544e5eb1',
// port: 80,
// protocol: 'http',
// version: 'v1.0',
// default_transaction_fee: 1,
// trust: '100.00'
// }
```

#### Updating Validator Trust

We can also update the trust of a specific validator by using the `updateValidatorTrust` method.

```ts
const networkIdKeyPair = new Account("validatorNetworkIdSigningKey");

const validatorToUpdate = "38ce9d9a245b2c5c923b1a6e8bbf5324a8cd57d71c977aef6a457740d7fd6451";

const res = await bank.updateAccountTrust(validatorToUpdate, 12, networkIdKeyPair);

console.log(res);
// {
// account_number: 'd62165ea6102a74fd484176226cd6ed8f7fc779117138e3ee2d9881ff4fc5a04',
// ip_address: '144.126.219.17',
// node_identifier: '38ce9d9a245b2c5c923b1a6e8bbf5324a8cd57d71c977aef6a457740d7fd6451',
// port: 80,
// protocol: 'http',
// version: 'v1.4',
// default_transaction_fee: 1,
// root_account_file: 'http://144.126.219.17:80/media/root_account_file.json',
// root_account_file_hash: 'ab9b95e5bb1dc66dd57ebf2cb8a8dece41748389d68077f74c916659f4bd2f1b',
// seed_block_identifier: '',
// daily_confirmation_rate: 1,
// trust: '12.00'
// }
```

<br>

## Getting Validator Confirmation Services

We use `Bank.getValidatorConfirmationServices` to get all the Validator Confirmation Services of the bank.

```ts
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "thenewboston",
"version": "1.1.0-alpha.0",
"version": "1.1.0-alpha.1",
"description": "JavaScript library for thenewboston.",
"author": {
"name": "thenewboston-developers",
Expand Down
33 changes: 32 additions & 1 deletion src/bank.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class Bank extends ServerNode {
* @param trust the trust of the the server
* @param account the account for the server node in which the account number is the node identifier and the signing key is the node identifier signing key
*/
async updateAccount(accountNumber: string, trust: number, account: Account) {
async updateAccountTrust(accountNumber: string, trust: number, account: Account) {
return await super.patchData(`/accounts/${accountNumber}`, account.createSignedMessage({ trust }));
}

Expand All @@ -38,6 +38,14 @@ export class Bank extends ServerNode {
return await super.getPaginatedData<PaginatedTransactionEntry & PaginatedEntry>("/bank_transactions", options);
}

/**
* Gets the bank with the specified node identifier.
* @param nodeIdentifier Node Identifier of a bank.
*/
async getBank(nodeIdentifier: string) {
return await super.getData<PaginatedBankEntry>(`/banks/${nodeIdentifier}`);
}

/**
* Gets the connected banks for the given bank.
* @param options The optional object for the pagination options.
Expand All @@ -61,6 +69,21 @@ export class Bank extends ServerNode {
);
}

/**
* Updates a given validators's trust.
* @param nodeIdentifier the validator to update's node identifier
* @param trust the new validator's trust
* @param account the current bank's network Id to sign the request
*/
async updateValidatorTrust(nodeIdentifier: string, trust: number, account: Account) {
return await super.patchData(
`/validators/${nodeIdentifier}`,
account.createSignedMessage({
trust,
})
);
}

/**
* Gets the blocks for the given bank.
* @param options The optional object for the pagination options.
Expand Down Expand Up @@ -194,6 +217,14 @@ export class Bank extends ServerNode {
);
}

/**
* Gets the validator with the specified node identifier.
* @param nodeIdentifier Node Identifier of a validator.
*/
async getValidator(nodeIdentifier: string) {
return await super.getData<PaginatedValidatorEntry>(`/validators/${nodeIdentifier}`);
}

/**
* Gets all of the validators for the current bank.
* @param options The optional object for the pagination options.
Expand Down
4 changes: 4 additions & 0 deletions src/models/responses/confirmation-validator/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,9 @@ export interface ConfirmationValidatorConfigResponse {
protocol: Protocol;
version: Version;
default_transaction_fee: number;
root_account_file: Url;
root_account_file_hash: Hex;
seed_block_identifier: Hex;
daily_confirmation_rate: number;
node_type: NodeType;
}
15 changes: 1 addition & 14 deletions src/models/responses/primary-validator/config.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,7 @@
import type { Hex, Origin, Port, Protocol, Url, Trust, Version, NodeType } from "../constants";

export interface PrimaryValidatorConfigResponse {
primary_validator: {
account_number: Hex;
ip_address: Origin;
node_identifier: Hex;
port: Port | null;
protocol: Protocol;
version: Version;
default_transaction_fee: number;
root_account_file: Url;
root_account_file_hash: Hex;
seed_block_identifier: Hex;
daily_confirmation_rate: number | null;
trust: Trust;
};
primary_validator: null;
account_number: Hex;
ip_address: Origin;
node_identifier: Hex;
Expand Down
Loading

0 comments on commit 5a282f2

Please sign in to comment.