I'm reading the process being built on
https://developers.cardano.org/docs/integrate-cardano/listening-for-payments-cli/#process-utxo-table
and I'm stuck on the results of this part:
// Calculate total lovelace of the UTXO(s) inside the wallet address
const utxoTableRows = rawUtxoTable.data.trim().split('\n');
let totalLovelaceRecv = 0;
let isPaymentComplete = false;
for (let x = 2; x < utxoTableRows.length; x++) {
const cells = utxoTableRows[x].split(" ").filter(i => i);
totalLovelaceRecv += parseInt(cells[2]);
}
I understand that up to the .split(" ")
part, the table has been split into at least 2 items within the array of utxoTableRows
since the first row the headers that we aren't interested in and the second row is the first utxo
being processed. The .split(" ")
then splits the row where there is a space but I don't know what the filter part does. The query utxo
table looks as follows:
TxHash | TxIx | Amount |
---|---|---|
dfb99f8f103e56a856e04e087255dbaf402f3801acb71a6baf423a1054d3ccd5 | 0 | 1749651926 |
As you can see there are two rows. I'm completely lost at the filter component. I get more lost in the following command parseInt(cells[2])
. I know somehow it takes the amount as a string and converts to integer. The [2] reference throws me off because wouldn't it have to be [3] since the amount is the 3rd item that gets split in that row? The only thing I can think of is that the .filter(i => i)
throws out the TxHash
, then saves the TxIx
(in this case 0) in cell[1]
and the amount (in this case 1749651926) in cell[2]
, both as strings.
Thank you for the help.