aboutsummaryrefslogtreecommitdiffstats
path: root/routes/bitcoin/util/addPayment.js
blob: 077fc2ae38ed675464db9a98ecab6f6f16291e79 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
module.exports = async (account, user, address, amount, memo, hash, fee) => {
    const params = {
        amount: -amount,
        memo,
        fee,
        hash,
        address,
        account_id: account.id,
        user_id: user.id,
        rate: app.get("rates")[user.currency],
        currency: user.currency,
        confirmed: true,
        received: false,
        network: "bitcoin",
    };

    let payment = await db.Payment.create(params);

    payment = payment.get({ plain: true });
    payment.account = account.get({ plain: true });

    emit(user.username, "payment", payment);

    payments.push(params.hash);
    return payment;
}