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: Tx fees #92

Merged
merged 2 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
10 changes: 10 additions & 0 deletions docs/bank.md
Original file line number Diff line number Diff line change
Expand Up @@ -516,3 +516,13 @@ Simply use the `Bank.getBankPV` method which returns the formatted url of the Pr
const bank = new tnb.Bank("http://143.110.137.54");
const pv = await bank.getBankPV();
```

## Getting the Bank's Transaction Fee

Use the `Bank.getTxFee` method to get the transaction fee

```ts
const bank = new tnb.Bank("http://143.110.137.54");
console.log(await bank.getTxFee());
// 1
```
4 changes: 4 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ There are two ways to use the library.

- [Getting the Bank's Primary Validator](bank.md#getting-the-bank's-primary-validator)

- [Getting the Bank's Transaction Fee](bank.md#getting-the-bank's-transaction-fee)

- [Validator](validator.md#validator)

- [Creating Validators](validator.md#creating-banks)
Expand All @@ -63,4 +65,6 @@ There are two ways to use the library.

- [Adding Bank Blocks](validator.md#adding-bank-blocks)

- [Getting the Primary Validator's Transaction Fee](primary-validator.md#getting-the-primary-validator's-transaction-fee)

- [Confirmation Validator](validator.md#confirmation-validator)
10 changes: 10 additions & 0 deletions docs/primary-validator.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,13 @@ const res = await primaryValidator.addBankBlocks("fakeBalanceLock", transactions
```

As you can see, this method takes 3 parameters, the balanceLock of the account you are sending from, the list of transactions, and an account object with the correct accountNumber and signingKey.

## Getting the Primary Validator's Transaction Fee

Simply use the `PrimaryValidator.getTxFee` method to get the transaction fee

```ts
const primaryValidator = new tnb.PrimaryValidator("http://157.230.75.212");
console.log(await primaryValidator.getTxFee());
// 1
```
7 changes: 7 additions & 0 deletions src/bank.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,11 @@ export class Bank extends ServerNode {
`${primary_validator.protocol}://${primary_validator.ip_address}:${primary_validator.port}`
);
}

/**
* Get transaction fee of the current Primary Validator
*/
async getTxFee() {
return (await this.getConfig()).default_transaction_fee;
}
}
7 changes: 7 additions & 0 deletions src/primary-validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,11 @@ export class PrimaryValidator extends Validator {
async addBankBlocks(balanceLock: string, transactions: Transaction[], account: Account) {
return await this.postData("/bank_blocks", account.createBlockMessage(balanceLock, transactions));
}

/**
* Get transaction fee of the current Primary Validator
*/
async getTxFee() {
return (await this.getConfig()).default_transaction_fee;
}
}