Skip to content

Commit 5a282f2

Browse files
authored
v1.1.0-alpha.1
v1.1.0-alpha.1
2 parents f1d03ad + 9c62066 commit 5a282f2

File tree

11 files changed

+256
-58
lines changed

11 files changed

+256
-58
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@
22

33
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.
44

5+
## [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)
6+
7+
### Features
8+
9+
* 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))
10+
* feat: added updateBankTrust, updateValidatorTrust ([#118](https://github.com/thenewboston-developers/thenewboston-js/issues/118)) ([32e1e1c](https://github.com/thenewboston-developers/thenewboston-js/commit/32e1e1c2afd549bfde80ca4fccc29da55ab5ee32))
11+
12+
### Bug Fixes
13+
14+
* 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))
15+
516
## [1.1.0-alpha.0](https://github.com/thenewboston-developers/thenewboston-js/compare/v1.0.3...v1.1.0-alpha.0) (2021-04-01)
617

718

README.md

Lines changed: 6 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,21 @@
1+
[ ![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)
2+
3+
14
## Overview
25

36
JavaScript library for thenewboston.
47

5-
## Contributing Guide
6-
7-
Here you can learn about how you can help make thenewboston-js a robust and simple JavaScript library to use!
8-
9-
### Setup
10-
11-
Make sure you clone the official repository. Here is the command to run if you want to clone with git:
12-
13-
```sh
14-
> git clone https://github.com/thenewboston-developers/thenewboston-js.git
15-
```
16-
17-
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!
18-
19-
### Development
20-
21-
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.
22-
23-
### Building
24-
25-
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:
26-
27-
```js
28-
const tnb = require("./"); // loads the module from the path in the `package.json`
29-
30-
async function main() {
31-
/* Code! */
32-
}
33-
34-
main();
35-
```
36-
378
### Contributing
389

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

4112
### Testing
4213

4314
Some day...
4415

4516
## Documentation
4617

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

4920
## Community
5021

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

44+
7345
## License
7446

7547
thenewboston is [MIT licensed](http://opensource.org/licenses/MIT).

docs/CONTRIBUTING.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
## Contributing Guide
2+
3+
Here you can learn about how you can help make thenewboston-js a robust and simple JavaScript library to use!
4+
5+
### Setup
6+
7+
Make sure you clone the official repository. Here is the command to run if you want to clone with git:
8+
9+
```sh
10+
> git clone https://github.com/thenewboston-developers/thenewboston-js.git
11+
```
12+
13+
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!
14+
15+
### Development
16+
17+
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.
18+
19+
### Building
20+
21+
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:
22+
23+
```js
24+
const tnb = require("./"); // loads the module from the path in the `package.json`
25+
26+
async function main() {
27+
/* Code! */
28+
}
29+
30+
main();
31+
```
32+
33+
### Contributing
34+
35+
Create your fork / branch from the development branch, All pull requests to be made to development branch for review.

docs/bank.md

Lines changed: 115 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,15 @@ console.log(accounts);
108108

109109
We can also update the trust of a specific account.
110110

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

113113
```ts
114114
const account = new Account("0cdd4ba04456ca169baca3d66eace869520c62fe84421329086e03d91a68acdb", "fakeSigningKeyHex");
115-
const res = await bank.updateAccount("0cdd4ba04456ca169baca3d66eace869520c62fe84421329086e03d91a68acdb", 32, account);
115+
const res = await bank.updateAccountTrust(
116+
"0cdd4ba04456ca169baca3d66eace869520c62fe84421329086e03d91a68acdb",
117+
32,
118+
account
119+
);
116120
console.log(res);
117121
// {
118122
// "id": "64426fc5-b3ac-42fb-b75b-d5ccfcdc6872",
@@ -219,7 +223,7 @@ console.log(transactions);
219223

220224
> Just like with `Bank.getAccounts`, you can also pass in an options object here.
221225
222-
## Getting Banks
226+
## Getting Banks and Updating Trust
223227

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

@@ -261,6 +265,59 @@ console.log(banks);
261265

262266
> As expected, the options object can also be used with this.
263267
268+
#### Getting a single Bank
269+
270+
The `getBank()` method is used to get a specified bank of the bank.
271+
272+
```ts
273+
const bankNodeId = "// node_identifier: '59af0721c572e6032b835722b5fec22110daad069dc135f1e81794747dbe626f',
274+
";
275+
276+
const res = await bank.getBank(bankNodeId);
277+
console.log(res);
278+
279+
// {
280+
// account_number: '9a275161478536d0a5b88ff05d429b9a9e63d0032a46e7a6a8f088da89c69da5',
281+
// ip_address: '13.57.215.62',
282+
// node_identifier: '59af0721c572e6032b835722b5fec22110daad069dc135f1e81794747dbe626f',
283+
// port: 80,
284+
// protocol: 'http',
285+
// version: 'v1.0',
286+
// default_transaction_fee: 1,
287+
// trust: '50.00'
288+
// }
289+
```
290+
291+
#### Updating Bank Trust
292+
293+
We can also update the trust of a specific bank by using the `updateBankTrust` method.
294+
295+
```ts
296+
const networkIdKeyPair = new Account("fakeSigningKeyHex");
297+
298+
const bankToUpdate = "0cdd4ba04456ca169baca3d66eace869520c62fe84421329086e03d91a68acdb";
299+
300+
const res = await bank.updateAccountTrust(bankToUpdate, 50, networkIdKeyPair);
301+
302+
console.log(res);
303+
// {
304+
// account_number: 'd62165ea6102a74fd484176226cd6ed8f7fc779117138e3ee2d9881ff4fc5a04',
305+
// ip_address: '144.126.219.17',
306+
// node_identifier: '38ce9d9a245b2c5c923b1a6e8bbf5324a8cd57d71c977aef6a457740d7fd6451',
307+
// port: 80,
308+
// protocol: 'http',
309+
// version: 'v1.4',
310+
// default_transaction_fee: 1,
311+
// root_account_file: 'http://144.126.219.17:80/media/root_account_file.json',
312+
// root_account_file_hash: 'ab9b95e5bb1dc66dd57ebf2cb8a8dece41748389d68077f74c916659f4bd2f1b',
313+
// seed_block_identifier: '',
314+
// daily_confirmation_rate: 1,
315+
// trust: '50.00'
316+
// }
317+
```
318+
319+
<br>
320+
264321
## Getting and Adding Blocks
265322

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

406463
> Both of these methods support the options object
407464
408-
## Getting Validators and Validator Confirmation Services
465+
## Getting Validators and Updating Trust
409466

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

@@ -450,6 +507,60 @@ console.log(res);
450507
// }
451508
```
452509

510+
#### Getting a single Validator
511+
512+
The `getValidator()` method is used to get a specified validator of the bank.
513+
514+
```ts
515+
const validatorNodeId = "01181490ac0fa6f73bd980adb81f1a3e72f81eb6b4ccab4dac8b6db7544e5eb1";
516+
517+
const res = await bank.getValidator(validatorNodeId);
518+
console.log(res);
519+
520+
// {
521+
// account_number: 'd2018eb4a13ea1ed307aa8f73207bc1cbad3fac0070899ff5af158982ae7a804',
522+
// ip_address: '18.218.193.164',
523+
// node_identifier: '01181490ac0fa6f73bd980adb81f1a3e72f81eb6b4ccab4dac8b6db7544e5eb1',
524+
// port: 80,
525+
// protocol: 'http',
526+
// version: 'v1.0',
527+
// default_transaction_fee: 1,
528+
// trust: '100.00'
529+
// }
530+
```
531+
532+
#### Updating Validator Trust
533+
534+
We can also update the trust of a specific validator by using the `updateValidatorTrust` method.
535+
536+
```ts
537+
const networkIdKeyPair = new Account("validatorNetworkIdSigningKey");
538+
539+
const validatorToUpdate = "38ce9d9a245b2c5c923b1a6e8bbf5324a8cd57d71c977aef6a457740d7fd6451";
540+
541+
const res = await bank.updateAccountTrust(validatorToUpdate, 12, networkIdKeyPair);
542+
543+
console.log(res);
544+
// {
545+
// account_number: 'd62165ea6102a74fd484176226cd6ed8f7fc779117138e3ee2d9881ff4fc5a04',
546+
// ip_address: '144.126.219.17',
547+
// node_identifier: '38ce9d9a245b2c5c923b1a6e8bbf5324a8cd57d71c977aef6a457740d7fd6451',
548+
// port: 80,
549+
// protocol: 'http',
550+
// version: 'v1.4',
551+
// default_transaction_fee: 1,
552+
// root_account_file: 'http://144.126.219.17:80/media/root_account_file.json',
553+
// root_account_file_hash: 'ab9b95e5bb1dc66dd57ebf2cb8a8dece41748389d68077f74c916659f4bd2f1b',
554+
// seed_block_identifier: '',
555+
// daily_confirmation_rate: 1,
556+
// trust: '12.00'
557+
// }
558+
```
559+
560+
<br>
561+
562+
## Getting Validator Confirmation Services
563+
453564
We use `Bank.getValidatorConfirmationServices` to get all the Validator Confirmation Services of the bank.
454565

455566
```ts

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "thenewboston",
3-
"version": "1.1.0-alpha.0",
3+
"version": "1.1.0-alpha.1",
44
"description": "JavaScript library for thenewboston.",
55
"author": {
66
"name": "thenewboston-developers",

src/bank.ts

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export class Bank extends ServerNode {
2626
* @param trust the trust of the the server
2727
* @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
2828
*/
29-
async updateAccount(accountNumber: string, trust: number, account: Account) {
29+
async updateAccountTrust(accountNumber: string, trust: number, account: Account) {
3030
return await super.patchData(`/accounts/${accountNumber}`, account.createSignedMessage({ trust }));
3131
}
3232

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

41+
/**
42+
* Gets the bank with the specified node identifier.
43+
* @param nodeIdentifier Node Identifier of a bank.
44+
*/
45+
async getBank(nodeIdentifier: string) {
46+
return await super.getData<PaginatedBankEntry>(`/banks/${nodeIdentifier}`);
47+
}
48+
4149
/**
4250
* Gets the connected banks for the given bank.
4351
* @param options The optional object for the pagination options.
@@ -61,6 +69,21 @@ export class Bank extends ServerNode {
6169
);
6270
}
6371

72+
/**
73+
* Updates a given validators's trust.
74+
* @param nodeIdentifier the validator to update's node identifier
75+
* @param trust the new validator's trust
76+
* @param account the current bank's network Id to sign the request
77+
*/
78+
async updateValidatorTrust(nodeIdentifier: string, trust: number, account: Account) {
79+
return await super.patchData(
80+
`/validators/${nodeIdentifier}`,
81+
account.createSignedMessage({
82+
trust,
83+
})
84+
);
85+
}
86+
6487
/**
6588
* Gets the blocks for the given bank.
6689
* @param options The optional object for the pagination options.
@@ -194,6 +217,14 @@ export class Bank extends ServerNode {
194217
);
195218
}
196219

220+
/**
221+
* Gets the validator with the specified node identifier.
222+
* @param nodeIdentifier Node Identifier of a validator.
223+
*/
224+
async getValidator(nodeIdentifier: string) {
225+
return await super.getData<PaginatedValidatorEntry>(`/validators/${nodeIdentifier}`);
226+
}
227+
197228
/**
198229
* Gets all of the validators for the current bank.
199230
* @param options The optional object for the pagination options.

src/models/responses/confirmation-validator/config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,9 @@ export interface ConfirmationValidatorConfigResponse {
2222
protocol: Protocol;
2323
version: Version;
2424
default_transaction_fee: number;
25+
root_account_file: Url;
26+
root_account_file_hash: Hex;
27+
seed_block_identifier: Hex;
28+
daily_confirmation_rate: number;
2529
node_type: NodeType;
2630
}

src/models/responses/primary-validator/config.ts

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,7 @@
11
import type { Hex, Origin, Port, Protocol, Url, Trust, Version, NodeType } from "../constants";
22

33
export interface PrimaryValidatorConfigResponse {
4-
primary_validator: {
5-
account_number: Hex;
6-
ip_address: Origin;
7-
node_identifier: Hex;
8-
port: Port | null;
9-
protocol: Protocol;
10-
version: Version;
11-
default_transaction_fee: number;
12-
root_account_file: Url;
13-
root_account_file_hash: Hex;
14-
seed_block_identifier: Hex;
15-
daily_confirmation_rate: number | null;
16-
trust: Trust;
17-
};
4+
primary_validator: null;
185
account_number: Hex;
196
ip_address: Origin;
207
node_identifier: Hex;

0 commit comments

Comments
 (0)