import { encodeOperationId } from "@ledgerhq/coin-framework/operation";
import BigNumber from "bignumber.js";
import { fromBigNumberToBigInt } from "@ledgerhq/coin-framework/utils";
export function adaptCoreOperationToLiveOperation(accountId, op) {
    return {
        id: encodeOperationId(accountId, op.tx.hash, op.type),
        hash: op.tx.hash,
        accountId,
        type: op.type,
        value: new BigNumber(op.value.toString()),
        fee: new BigNumber(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: {},
    };
}
export function transactionToIntent(account, transaction) {
    return {
        type: "Payment",
        sender: account.freshAddress,
        recipient: transaction.recipient,
        amount: fromBigNumberToBigInt(transaction.amount, BigInt(0)),
        asset: null,
    };
}
export const buildOptimisticOperation = (account, transaction, sequenceNumber) => {
    return {
        id: encodeOperationId(account.id, "", "OUT"),
        hash: "",
        type: "OUT",
        value: transaction.amount,
        fee: transaction["fees"] ?? BigNumber(0),
        blockHash: null,
        blockHeight: null,
        senders: [account.freshAddress.toString()],
        recipients: [transaction.recipient],
        transactionSequenceNumber: sequenceNumber ?? 0,
        accountId: account.id,
        date: new Date(),
        extra: {},
    };
};
//# sourceMappingURL=utils.js.map