Skip to content

Commit

Permalink
feat: Tx fees (#92)
Browse files Browse the repository at this point in the history
* Add getTxFee in Bank and PrimaryValidator class

* Add docs for getTxFee method
  • Loading branch information
AbhayAysola authored Mar 29, 2021
1 parent 99b0d17 commit 8650634
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 0 deletions.
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;
}
}

0 comments on commit 8650634

Please sign in to comment.