@ledgerhq/coin-canton
Version:
67 lines • 2.74 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.listOperations = listOperations;
const config_1 = __importDefault(require("../../config"));
const gateway_1 = require("../../network/gateway");
const gateway_2 = require("../../network/gateway");
function convertAssetViewToAssetInfo(nativeInstrumentId, asset) {
if (!asset || asset.type === "native") {
return { type: nativeInstrumentId };
}
if (asset.type === "token") {
return {
type: asset.type,
...(asset.instrumentId ? { assetReference: asset.instrumentId } : {}),
...(asset.instrumentAdmin ? { assetOwner: asset.instrumentAdmin } : {}),
};
}
return { type: asset.type };
}
/**
* Returns list of operations associated to an account.
* @param partyId Account partyId
* @param minHeight Minimum block height
* @param cursor Pagination cursor
* @param limit Max number of operations
* @returns Operations found and the next cursor for pagination.
*/
async function listOperations(currency, partyId, minHeight, cursor, limit, _order) {
if (!(0, gateway_1.isGatewayEnabled)(currency))
throw new Error("Not implemented");
const { nativeInstrumentId } = config_1.default.getCoinConfig(currency.id);
const { operations, next } = await (0, gateway_2.getOperations)(currency, partyId, {
cursor: cursor !== undefined ? parseInt(cursor) : undefined,
minOffset: minHeight,
limit: limit,
});
const ops = [];
for (const tx of operations) {
if (tx.type === "Send" && tx.senders && tx.recipients && tx.transfers?.length) {
const asset = convertAssetViewToAssetInfo(nativeInstrumentId, tx.asset);
ops.push({
id: tx.uid,
type: tx.senders.includes(partyId) ? "OUT" : "IN",
value: BigInt(tx.transfers[0].value),
senders: tx.senders,
recipients: tx.recipients,
asset,
tx: {
hash: tx.transaction_hash,
fees: BigInt(tx.fee.value),
date: new Date(tx.transaction_timestamp),
block: {
height: tx.block.height,
hash: tx.block.hash ?? "",
time: new Date(tx.block.time),
},
failed: false,
},
});
}
}
return { items: ops, next: next !== undefined ? next + "" : undefined };
}
//# sourceMappingURL=listOperations.js.map