Building the transaction listeners for the banks

We need to build a transaction listener, to detect incoming transactions to the bank's customers. We need one for Bank A and one for Bank B. 

The transaction listener will carry out the following tasks:

  • Monitor the blockchain for the txCreated event. The txCreated event is triggered by the corprem whenever a new transaction is created using the method createTx.
  • In the case of an event being triggered, the listener checks the transaction payload to see if the receiving bank (trans.Rbank) is the bank hosting the transaction listener. Thus, the transaction listener for Bank A checks for transactions where the receiving bank is banka. Similarly, the transaction listener for Bank B checks if the receiving bank is bankb.
  • If the transaction is intended for the bank, the transaction listener fetches the customer's current balance from the customers table. It fetches the transaction amount and the receiver's account from the transaction payload, and increments the receiving account's balance in the customers table with the transaction amount.
  • Next, it inserts the incoming transaction details into the transactions table. The transtype flag is set to Incoming.
  • Lastly, it calls the iread() method. The iread() method takes the hash of the compliance documents accompanying the transaction as an input parameter. It uses the hash value to fetch the documents from the IPFS node of the receiving bank and saves it to the local storage of the bank infrastructure.
  • A catch block catches any errors while executing the preceding tasks. 

The transaction listener has the following two methods:

  • Transactionlisten(): The listener method checks for any incoming transactions and processes the tasks listed previously.
  • iread(): This uses the IPFS client to fetch the compliance documents from the IPFS network and saves them to the local storage.

Let's start building the transaction listener. The following steps are for the transaction listener for Bank A. Repeat the steps for Bank B.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.14.253.221