Skip to content

Commit

Permalink
feat: Bulk payments (#82)
Browse files Browse the repository at this point in the history
* implement bulk transactions

* added bulkpayments method in AccountPaymentHandler

* updated payment handlet test

* updated payment handlet docs
  • Loading branch information
tomijaga authored Mar 28, 2021
1 parent f3b5427 commit 28b3ca9
Show file tree
Hide file tree
Showing 7 changed files with 10,594 additions and 57 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,5 @@ types

# Development File
dev.js
dev.ts

66 changes: 55 additions & 11 deletions docs/account-payment-handler.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,76 @@ In this section, we will look at the methods of the `AccountPaymentHandler` clas

## Sending Coins

Any Application can send coins by using a bank to process an account's transactions.
Any application or user send coins by using a bank to process an account's transactions.

>**Note**: Before you can send coins you need to call the `init()` method in order to update to retrieve the details and transactions fees for the **Bank** and **Primary Validator**
> **Note**: Before you can send coins you need to call the `init()` method in order to update to retrieve the details and transactions fees for the **Bank** and **Primary Validator**
We send coins using the `sendCoins()` method.
Coins can be sent by using the `sendCoins()` method.

```ts

const sendersAccount = new Account("fakeSigningKey");
const bankUrl = "http://18.218.193.164";

const paymentHandlerOptions={
account: sendersAccount,
bankUrl: bankUrl
}
const paymentHandlerOptions = {
account: sendersAccount,
bankUrl: bankUrl,
};

const paymentHandler = new tnb.AccountPaymentHandler(paymentHandlerOptions);

// This is very important.
// This is very important.
// Method for getting the Bank and Primary validator Transactions fees
await paymentHandler.init();

//This can be a new Account object or just the recipients account number
const recipientAccount = new Account ("fakeSigningKey");
const recipientAccount = new Account("fakeSigningKey");
const amount = 1000;

await sendCoins(recipientAccount, 1000);
```

## Send Bulk Payments

Any application or user can send multiple coins to multiple recipients from a single account.

> **Note**: Before you can send coins you need to call the `init()` method in order to update to retrieve the details and transactions fees for the **Bank** and **Primary Validator**
Bulk payments can be sent by using the `sendBulkPayments()` method.

```ts
const sendersAccount = new Account("fakeSigningKey");
const bankUrl = "http://18.218.193.164";

const paymentHandlerOptions = {
account: sendersAccount,
bankUrl: bankUrl,
};

const paymentHandler = new tnb.AccountPaymentHandler(paymentHandlerOptions);

// This is very important.
// Method for getting the Bank and Primary validator Transactions fees
await paymentHandler.init();

/* Note
The sender cannot be listed as a recipient
A recipient cannot be listed more than once
*/

const txs = [
{
amount: 10,
recipient: "fakeAccountNumber1",
},
{
amount: 100,
recipient: "fakeAccountNumber2",
},
{
amount: 1000,
recipient: "fakeAccountNumber3",
},
];

```
await sendBulkPayments(txs);
```
Loading

0 comments on commit 28b3ca9

Please sign in to comment.