aboutsummaryrefslogtreecommitdiffstats
path: root/.env.production
blob: 52119afaef74f08b79eda2bb1600b33d571cb1e7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
PUBLIC_COINOS_URL=http://app:3119
PUBLIC_BTC=6f0279e9ed041c3d710a9f57d0c02928416460c4b722ae3457a11eec381c526d
PUBLIC_SOCKET=wss://coinos.io/ws
PUBLIC_EXPLORER=https://mempool.space
PUBLIC_LIQUID_EXPLORER=https://liquid.network
PUBLIC_DOMAIN=coinos.io
PUBLIC_COINOS_PUBKEY=ba80990666ef0b6f4ba5059347beb13242921e54669e680064ca755256a1e3a6
PUBLIC_COINOS_RELAY=wss://relay.coinos.io
PUBLIC_COINOS_NETWORK=bitcoin
PUBLIC_VAPID_PUBKEY=BFCcO7u4fpgDjWK-Py2qL7rGeueaijf97zxyBKcld25Hya9psuB9pVPeWKpUTdZI0wEWWzTOUK0LVO9uUfbaMhI
e */ .highlight .vm { color: #369 } /* Name.Variable.Magic */ .highlight .il { color: #00D; font-weight: bold } /* Literal.Number.Integer.Long */
const axios = require("axios");

module.exports = async (asset, user, transaction) => {
  const account = await db.Account.findOne({
    where: {
      user_id: user.id,
      asset,
      pubkey: null
    },
    lock: transaction.LOCK.UPDATE,
    transaction
  });

  if (account) return account;

  let params = {
    user_id: user.id,
    asset
  };
  let name = asset.substr(0, 6);
  let domain = "";
  let ticker = asset.substr(0, 3).toUpperCase();
  let precision = 8;

  const assets = app.get("assets");

  if (assets[asset]) {
    ({ domain, ticker, precision, name } = assets[asset]);
  } else {
    const existing = await db.Account.findOne(
      {
        where: {
          asset
        },
        order: [["id", "ASC"]],
        limit: 1,
      lock: transaction.LOCK.UPDATE,
      transaction
      },
    );

    if (existing) {
      ({ domain, ticker, precision, name } = existing);
    }
  }

  params = { ...params, ...{ domain, ticker, precision, name } };
  params.balance = 0;
  params.pending = 0;
  return db.Account.create(params, { transaction });
};