aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDerrick Schwabe <[email protected]>2022-04-04 15:37:43 -0600
committerDerrick Schwabe <[email protected]>2022-04-04 15:37:43 -0600
commit858a2a10b6790c20d65824c672dcae9bf00e3b7e (patch)
tree45f27995beaecf9b6dd578b7a4d7c5892d23f285
parent2fd68236f649b1c27703c15e494b242b79f9527f (diff)
parentd72de475b6621fb6ef31c03c2cf4d3ca1e82f5f2 (diff)
downloadcoinos-server-858a2a10b6790c20d65824c672dcae9bf00e3b7e.tar.gz
coinos-server-858a2a10b6790c20d65824c672dcae9bf00e3b7e.zip
Merge branch 'master' into stageUpdate2
-rw-r--r--lib/send.js3
-rw-r--r--lib/sync.js97
-rw-r--r--package.json2
-rw-r--r--pnpm-lock.yaml112
-rw-r--r--routes/send.js1
-rw-r--r--routes/users.js4
6 files changed, 99 insertions, 120 deletions
diff --git a/lib/send.js b/lib/send.js
index 4d3201fa..1f7e6369 100644
--- a/lib/send.js
+++ b/lib/send.js
@@ -24,6 +24,7 @@ send = async (amount, memo, hash, user) => {
let error, fee, total, preimage, payment;
await db.transaction(async transaction => {
+ l.info("starting lightning send transaction");
let account;
if (user.account.asset === config.liquid.btcasset)
account = await db.Account.findOne({
@@ -94,6 +95,8 @@ send = async (amount, memo, hash, user) => {
});
await db.transaction(async transaction => {
+ l.info("starting lightning fee transaction");
+
let account;
if (user.account.asset === config.liquid.btcasset)
account = await db.Account.findOne({
diff --git a/lib/sync.js b/lib/sync.js
index d7bdb4c5..d6adba2e 100644
--- a/lib/sync.js
+++ b/lib/sync.js
@@ -11,13 +11,13 @@ const init = async () => {
}
try {
- const twoDays = new Date(new Date().setDate(new Date().getDate() - 2));
+ const thirtyDays = new Date(new Date().setDate(new Date().getDate() - 30));
(
await db.Invoice.findAll({
where: {
createdAt: {
- [Op.gt]: twoDays
+ [Op.gt]: thirtyDays
}
},
include: {
@@ -33,22 +33,6 @@ const init = async () => {
console.log(e);
}
- try {
- const accounts = await db.Account.findAll({
- where: { pubkey: { [Op.ne]: null } },
- include: {
- model: db.User,
- as: "user"
- }
- });
-
- accounts.map(({ address, user: { username } }) => {
- addresses[address] = username;
- });
- } catch (e) {
- console.log(e);
- }
-
payments = (
await db.Payment.findAll({
attributes: ["hash"]
@@ -166,19 +150,20 @@ const sync = async () => {
let hashes = unconfirmed.map(p => p.hash);
const transactions = [
- ...(await bc.listTransactions("*", 50)),
- ...(await lq.listTransactions("*", 50))
+ ...(await bc.listTransactions("*", 500)),
+ ...(await lq.listTransactions("*", 500))
].filter(tx => ["send", "receive"].includes(tx.category));
missed = transactions.filter(
tx =>
tx.category === "receive" &&
- tx.confirmations > 0 &&
+ tx.confirmations > 2 &&
hashes.includes(tx.txid)
);
for (let i = 0; i < missed.length; i++) {
let p = unconfirmed.find(p => p.hash === missed[i].txid);
+ /*
p.confirmed = 1;
await db.transaction(async transaction => {
@@ -190,8 +175,9 @@ const sync = async () => {
emit(p.user.username, "account", p.account);
emit(p.user.username, "payment", p);
+ */
- l.info("confirmed tx", p.user_id, p.hash, p.address);
+ l.info("unconfirmed tx", p.user_id, p.hash, p.address);
}
unaccounted = [];
@@ -213,7 +199,9 @@ const sync = async () => {
let receipts = unaccounted
.filter(
- tx => tx.category === "receive" && tx.asset === config.liquid.btcasset
+ tx =>
+ tx.category === "receive" &&
+ (!tx.asset || tx.asset === config.liquid.btcasset)
)
.map(tx => tx.address);
@@ -251,45 +239,54 @@ const sync = async () => {
user_id
} = invoices[i];
- let { amount, txid: hash } = unaccounted.find(
+ l.info("unaccounted", address);
+
+ let pending = unaccounted.filter(
tx => tx.address === address || tx.address === unconfidential
);
- amount = toSats(amount);
+ for (let i = 0; i < pending.length; i++) {
+ let { amount, txid: hash } = pending[i];
- await db.transaction(async transaction => {
- payments.push(hash);
- let p = await db.Payment.create(
- {
- account_id,
- address: address || unconfidential,
- amount,
- confirmed: false,
- currency,
- hash,
- invoice_id,
- network,
- rate,
- received: true,
- tip,
- user_id
- },
- { transaction }
- );
+ amount = toSats(amount);
+
+ await db.transaction(async transaction => {
+ payments.push(hash);
+ let p = await db.Payment.create(
+ {
+ account_id,
+ address: address || unconfidential,
+ amount,
+ confirmed: false,
+ currency,
+ hash,
+ invoice_id,
+ network,
+ rate,
+ received: true,
+ tip,
+ user_id
+ },
+ { transaction }
+ );
- await account.increment({ pending: amount }, { transaction });
+ await account.increment({ pending: amount }, { transaction });
- emit(user.username, "account", account);
- emit(user.username, "payment", p);
- });
+ l.info("found pending balance", user.username, amount);
+
+ emit(user.username, "account", account);
+ emit(user.username, "payment", p);
+ });
+ }
}
} catch (e) {
l.error("sync check failed", e.message, e.stack);
}
+
+ setTimeout(sync, 300000);
};
-//setTimeout(sync, 5000);
-//setInterval(sync, 300000);
+setTimeout(sync, 5000);
app.get(
"/conversions",
diff --git a/package.json b/package.json
index 6aca424b..40f96ae3 100644
--- a/package.json
+++ b/package.json
@@ -51,7 +51,7 @@
"passport-local": "1.0.0",
"pino": "^6.13.2",
"pino-pretty": "^7.0.0",
- "pm2": "^5.1.0",
+ "pm2": "^5.2.0",
"query-string": "^6.13.1",
"sequelize": "^5.21.3",
"sqlite3": "^5.0.2",
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 8604f946..2f5e0809 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -43,7 +43,7 @@ specifiers:
passport-local: 1.0.0
pino: ^6.13.2
pino-pretty: ^7.0.0
- pm2: ^5.1.0
+ pm2: ^5.2.0
prettier: ^1.18.2
query-string: ^6.13.1
sequelize: ^5.21.3
@@ -98,7 +98,7 @@ dependencies:
passport-local: 1.0.0
pino: 6.13.3
pino-pretty: 7.0.1
- pm2: 5.1.2
+ pm2: 5.2.0
query-string: 6.14.1
sequelize: 5.22.4
sqlite3: 5.0.2
@@ -174,17 +174,6 @@ packages:
yargs: 16.2.0
dev: false
- /@jest/types/27.2.5:
- resolution: {integrity: sha512-nmuM4VuDtCZcY+eTpw+0nvstwReMsjPoj7ZR80/BbixulhLaiX+fbv8oeLW8WZlJMcsGQsTmMKT/iTZu1Uy/lQ==}
- engines: {node: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0}
- dependencies:
- '@types/istanbul-lib-coverage': 2.0.3
- '@types/istanbul-reports': 3.0.1
- '@types/node': 16.10.3
- '@types/yargs': 16.0.4
- chalk: 4.1.2
- dev: false
-
/@mapbox/node-pre-gyp/1.0.5:
resolution: {integrity: sha512-4srsKPXWlIxp5Vbqz5uLfBN+du2fJChBoYn/f2h991WLdk7jUvcSk/McVLSv/X+xQIPI8eGD5GjrnygdyHnhPA==}
hasBin: true
@@ -432,27 +421,11 @@ packages:
resolution: {integrity: sha512-1rkryxURpr6aWP7R786/UQOkJ3PcpQiWkAXBmdWc7ryFWqN6a4xfK7BtjXvFBKO9LjQ+MWQSWxYeZX1OApnArA==}
dev: false
- /@types/istanbul-lib-coverage/2.0.3:
- resolution: {integrity: sha512-sz7iLqvVUg1gIedBOvlkxPlc8/uVzyS5OwGz1cKjXzkl3FpL3al0crU8YGU1WoHkxn0Wxbw5tyi6hvzJKNzFsw==}
- dev: false
-
- /@types/istanbul-lib-report/3.0.0:
- resolution: {integrity: sha512-plGgXAPfVKFoYfa9NpYDAkseG+g6Jr294RqeqcqDixSbU34MZVJRi/P+7Y8GDpzkEwLaGZZOpKIEmeVZNtKsrg==}
+ /@types/jest/27.4.1:
+ resolution: {integrity: sha512-23iPJADSmicDVrWk+HT58LMJtzLAnB2AgIzplQuq/bSrGaxCrlvRFjGbXmamnnk/mAmCdLStiGqggu28ocUyiw==}
dependencies:
- '@types/istanbul-lib-coverage': 2.0.3
- dev: false
-
- /@types/istanbul-reports/3.0.1:
- resolution: {integrity: sha512-c3mAZEuK0lvBp8tmuL74XRKn1+y2dcwOUpH7x4WrF6gk1GIgiluDRgMYQtw2OFcBvAJWlt6ASU3tSqxp0Uu0Aw==}
- dependencies:
- '@types/istanbul-lib-report': 3.0.0
- dev: false
-
- /@types/jest/27.0.2:
- resolution: {integrity: sha512-4dRxkS/AFX0c5XW6IPMNOydLn2tEhNhJV7DnYK+0bjoJZ+QTmfucBlihX7aoEsh/ocYtkLC73UbnBXBXIxsULA==}
- dependencies:
- jest-diff: 27.2.5
- pretty-format: 27.2.5
+ jest-matcher-utils: 27.5.1
+ pretty-format: 27.5.1
dev: false
/@types/long/4.0.1:
@@ -521,16 +494,6 @@ packages:
'@types/node': 16.10.3
dev: false
- /@types/yargs-parser/20.2.1:
- resolution: {integrity: sha512-7tFImggNeNBVMsn0vLrpn1H1uPrUBdnARPTpZoitY37ZrdJREzf7I16tMrlK3hen349gr1NYh8CmZQa7CTG6Aw==}
- dev: false
-
- /@types/yargs/16.0.4:
- resolution: {integrity: sha512-T8Yc9wt/5LbJyCaLiHPReJa0kApcIgJ7Bn735GjItUfh08Z1pJvu8QZqb9s+mMvKV6WUQRV7K2R46YbjMXTTJw==}
- dependencies:
- '@types/yargs-parser': 20.2.1
- dev: false
-
/@vulpemventures/secp256k1-zkp/2.0.0:
resolution: {integrity: sha512-LhWeEp9pDWYpuE5Lvvb8QRuxG/9cd+NTxNaAzrg+JT0sO11D7hyxyvSgnHkuTVT7FDdmmQQGZ6lkutfynE45rQ==}
engines: {node: '>=12.0.0'}
@@ -941,8 +904,8 @@ packages:
wif: 2.0.6
dev: false
- /blech32/1.0.1:
- resolution: {integrity: sha512-1/vr1wwB8jvfVCkLQMVXLaIyx7Lgxh/6IqVuQlSsCNzWNzU+64oXzOQ/9BRnN4GANjx9i0O3OSQonDlL4FraSA==}
+ /blech32/1.1.0:
+ resolution: {integrity: sha512-TGl9OgRq7woBzhQX1S5Im7opgyb2lpnEgqoApHpEZ8hgo8NSQkwJrf1Qxbg6frobTdBWxo2c+sFLjZFWGMLZHA==}
engines: {node: '>=10'}
dependencies:
long: 4.0.0
@@ -1447,10 +1410,8 @@ packages:
sha.js: 2.4.11
dev: false
- /cron/1.8.2:
- resolution: {integrity: sha512-Gk2c4y6xKEO8FSAUTklqtfSr7oTq0CiPQeLBG5Fl0qoXpZyMcj1SG59YL+hqq04bu6/IuEA7lMkYDAplQNKkyg==}
- dependencies:
- moment-timezone: 0.5.33
+ /croner/4.1.97:
+ resolution: {integrity: sha512-/f6gpQuxDaqXu+1kwQYSckUglPaOrHdbIlBAu0YuW8/Cdb45XwXYNUBXg3r/9Mo6n540Kn/smKcZWko5x99KrQ==}
dev: false
/crypto-random-string/2.0.0:
@@ -1606,8 +1567,8 @@ packages:
streamsearch: 0.1.2
dev: false
- /diff-sequences/27.0.6:
- resolution: {integrity: sha512-ag6wfpBFyNXZ0p8pcuIDS//D8H062ZQJ3fzYxjpmeKjnz8W4pekL3AI8VohmyZmsWW2PWaHgjsmqR6L13101VQ==}
+ /diff-sequences/27.5.1:
+ resolution: {integrity: sha512-k1gCAXAsNgLwEL+Y8Wvl+M6oEFj5bgazfZULpS5CneoPPXRaCCW7dm+q21Ky2VEE5X+VeRDBVg1Pcvvsr4TtNQ==}
engines: {node: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0}
dev: false
@@ -2583,21 +2544,31 @@ packages:
resolution: {integrity: sha1-R+Y/evVa+m+S4VAOaQ64uFKcCZo=}
dev: false
- /jest-diff/27.2.5:
- resolution: {integrity: sha512-7gfwwyYkeslOOVQY4tVq5TaQa92mWfC9COsVYMNVYyJTOYAqbIkoD3twi5A+h+tAPtAelRxkqY6/xu+jwTr0dA==}
+ /jest-diff/27.5.1:
+ resolution: {integrity: sha512-m0NvkX55LDt9T4mctTEgnZk3fmEg3NRYutvMPWM/0iPnkFj2wIeF45O1718cMSOFO1vINkqmxqD8vE37uTEbqw==}
engines: {node: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0}
dependencies:
chalk: 4.1.2
- diff-sequences: 27.0.6
- jest-get-type: 27.0.6
- pretty-format: 27.2.5
+ diff-sequences: 27.5.1
+ jest-get-type: 27.5.1
+ pretty-format: 27.5.1
dev: false
- /jest-get-type/27.0.6:
- resolution: {integrity: sha512-XTkK5exIeUbbveehcSR8w0bhH+c0yloW/Wpl+9vZrjzztCPWrxhHwkIFpZzCt71oRBsgxmuUfxEqOYoZI2macg==}
+ /jest-get-type/27.5.1:
+ resolution: {integrity: sha512-2KY95ksYSaK7DMBWQn6dQz3kqAf3BB64y2udeG+hv4KfSOb9qwcYQstTJc1KCbsix+wLZWZYN8t7nwX3GOBLRw==}
engines: {node: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0}
dev: false
+ /jest-matcher-utils/27.5.1:
+ resolution: {integrity: sha512-z2uTx/T6LBaCoNWNFWwChLBKYxTMcGBRjAt+2SbP929/Fflb9aa5LGma654Rz8z9HLxsrUaYzxE9T/EFIL/PAw==}
+ engines: {node: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0}
+ dependencies:
+ chalk: 4.1.2
+ jest-diff: 27.5.1
+ jest-get-type: 27.5.1
+ pretty-format: 27.5.1
+ dev: false
+
/joycon/3.0.1:
resolution: {integrity: sha512-SJcJNBg32dGgxhPtM0wQqxqV0ax9k/9TaUskGDSJkSFSQOEWWvQ3zzWdGQRIUry2j1zA5+ReH13t0Mf3StuVZA==}
engines: {node: '>=10'}
@@ -3551,6 +3522,14 @@ packages:
dependencies:
safe-buffer: 5.2.1
dev: false
+ optional: true
+
+ /pidusage/3.0.0:
+ resolution: {integrity: sha512-8VJLToXhj+RYZGNVw8oxc7dS54iCQXUJ+MDFHezQ/fwF5B8W4OWodAMboc1wb08S/4LiHwAmkT4ohf/d3YPPsw==}
+ engines: {node: '>=10'}
+ dependencies:
+ safe-buffer: 5.2.1
+ dev: false
/pino-abstract-transport/0.3.0:
resolution: {integrity: sha512-jsd59/ruahIoIU4xAdFtvk3lS9rwsDNJ7Vi0K34ATh1PEOD796SPqvydMaRk296CeTROyBG0SNCwsshN6QhxVg==}
@@ -3660,8 +3639,8 @@ packages:
dev: false
optional: true
- /pm2/5.1.2:
- resolution: {integrity: sha512-2nJQeCWjkN0WnTkWctaoZpqrJTiUN/Icw76IMVHHzPhr/p7yQYlEQgHzlL5IFWxO2N1HdBNXNdZft2p4HUmUcA==}
+ /pm2/5.2.0:
+ resolution: {integrity: sha512-PO5hMVhQ85cTszFM++6v07Me9hPJMkFbHjkFigtMMk+La8ty2wCi2dlBTeZYJDhPUSjK8Ccltpq2buNRcyMOTw==}
engines: {node: '>=10.0.0'}
hasBin: true
dependencies:
@@ -3675,7 +3654,7 @@ packages:
chokidar: 3.5.2
cli-tableau: 2.0.1
commander: 2.15.1
- cron: 1.8.2
+ croner: 4.1.97
dayjs: 1.8.36
debug: 4.3.2
enquirer: 2.3.6
@@ -3683,7 +3662,7 @@ packages:
fclone: 1.0.11
mkdirp: 1.0.4
needle: 2.4.0
- pidusage: 2.0.21
+ pidusage: 3.0.0
pm2-axon: 4.0.1
pm2-axon-rpc: 0.7.1
pm2-deploy: 1.0.2
@@ -3718,11 +3697,10 @@ packages:
hasBin: true
dev: true
- /pretty-format/27.2.5:
- resolution: {integrity: sha512-+nYn2z9GgicO9JiqmY25Xtq8SYfZ/5VCpEU3pppHHNAhd1y+ZXxmNPd1evmNcAd6Hz4iBV2kf0UpGth5A/VJ7g==}
+ /pretty-format/27.5.1:
+ resolution: {integrity: sha512-Qb1gy5OrP5+zDf2Bvnzdl3jsTf1qXVMazbvCoKhtKqVs4/YK4ozX4gKQJJVyNe+cajNPn0KoC0MC3FUmaHWEmQ==}
engines: {node: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0}
dependencies:
- '@jest/types': 27.2.5
ansi-regex: 5.0.1
ansi-styles: 5.2.0
react-is: 17.0.2
@@ -5025,7 +5003,7 @@ packages:
version: 5.2.0
engines: {node: '>=8.0.0'}
dependencies:
- '@types/jest': 27.0.2
+ '@types/jest': 27.4.1
'@vulpemventures/secp256k1-zkp': 2.0.0
axios: 0.21.4
bech32: 1.1.4
@@ -5033,7 +5011,7 @@ packages:
bip32: 2.0.6
bip66: 1.1.5
bitcoin-ops: 1.4.1
- blech32: 1.0.1
+ blech32: 1.1.0
bs58check: 2.1.2
create-hash: 1.2.0
create-hmac: 1.1.7
diff --git a/routes/send.js b/routes/send.js
index e44d3224..5f1151c5 100644
--- a/routes/send.js
+++ b/routes/send.js
@@ -208,6 +208,7 @@ module.exports = ah(async (req, res, next) => {
res.send(payment);
});
} catch (e) {
+ console.log(e);
l.error("problem sending internal payment", user.username, e.message);
return res.status(500).send(e.message);
}
diff --git a/routes/users.js b/routes/users.js
index 403c4646..549de828 100644
--- a/routes/users.js
+++ b/routes/users.js
@@ -358,7 +358,7 @@ app.post(
user = pick(user, ...whitelist);
res.send({ user, token });
} catch (e) {
- l.error("login error", e.message);
+ l.error("login error", e.message, req.connection.remoteAddress);
res.status(401).end();
}
})
@@ -420,7 +420,7 @@ app.post(
user = pick(user, ...whitelist);
res.send({ user, token });
} catch (e) {
- l.error("login error", e.message);
+ l.error("login error", e.message, req.connection.remoteAddress);
res.status(401).end();
}
})