"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.buildOptimisticOperation = exports.transactionToIntent = exports.adaptCoreOperationToLiveOperation = void 0;
const operation_1 = require("@ledgerhq/coin-framework/operation");
const bignumber_js_1 = __importDefault(require("bignumber.js"));
const utils_1 = require("@ledgerhq/coin-framework/utils");
function adaptCoreOperationToLiveOperation(accountId, op) {
    return {
        id: (0, operation_1.encodeOperationId)(accountId, op.tx.hash, op.type),
        hash: op.tx.hash,
        accountId,
        type: op.type,
        value: new bignumber_js_1.default(op.value.toString()),
        fee: new bignumber_js_1.default(op.tx.fees.toString()),
        blockHash: op.tx.block.hash,
        blockHeight: op.tx.block.height,
        senders: op.senders,
        recipients: op.recipients,
        date: op.tx.date,
        transactionSequenceNumber: op.details?.sequence,
        extra: {},
    };
}
exports.adaptCoreOperationToLiveOperation = adaptCoreOperationToLiveOperation;
function transactionToIntent(account, transaction) {
    return {
        type: "Payment",
        sender: account.freshAddress,
        recipient: transaction.recipient,
        amount: (0, utils_1.fromBigNumberToBigInt)(transaction.amount, BigInt(0)),
        asset: null,
    };
}
exports.transactionToIntent = transactionToIntent;
const buildOptimisticOperation = (account, transaction, sequenceNumber) => {
    return {
        id: (0, operation_1.encodeOperationId)(account.id, "", "OUT"),
        hash: "",
        type: "OUT",
        value: transaction.amount,
        fee: transaction["fees"] ?? (0, bignumber_js_1.default)(0),
        blockHash: null,
        blockHeight: null,
        senders: [account.freshAddress.toString()],
        recipients: [transaction.recipient],
        transactionSequenceNumber: sequenceNumber ?? 0,
        accountId: account.id,
        date: new Date(),
        extra: {},
    };
};
exports.buildOptimisticOperation = buildOptimisticOperation;
//# sourceMappingURL=utils.js.map