@ledgerhq/coin-canton
Version:
52 lines • 1.89 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.listOperations = listOperations;
const indexer_1 = require("../../network/indexer");
/**
* Returns list of operations associated to an account.
* @param address Account address
* @param pagination Pagination options
* @returns Operations found and the next "id" or "index" to use for pagination (i.e. `start` property).\
* If `0` is returns, no pagination needed.
* This "id" or "index" value, thus it has functional meaning, is different for each blockchain.
*/
async function listOperations(address, page) {
const transactions = await (0, indexer_1.getTransactions)(address, { from: page.minHeight });
return [transactions.map(convertToCoreOperation(address)), ""];
}
const convertToCoreOperation = (address) => (operation) => {
const { meta: { delivered_amount }, tx: { Fee, hash, inLedger, date, Account, Destination }, } = operation;
const type = Account === address ? "OUT" : "IN";
let value = delivered_amount && typeof delivered_amount === "string"
? BigInt(delivered_amount)
: BigInt(0);
const feeValue = BigInt(Fee);
if (type === "OUT") {
if (!Number.isNaN(feeValue)) {
value = value + feeValue;
}
}
return {
/**
* Note: The operation ID must be concatenated with another
* value if the transaction hash is not enough to identify it
*/
id: hash,
asset: { type: "native" },
tx: {
hash,
fees: feeValue,
date: new Date(date),
block: {
height: inLedger,
hash,
time: new Date(date),
},
},
type,
value,
senders: [Account],
recipients: [Destination],
};
};
//# sourceMappingURL=listOperations.js.map