diff options
| -rw-r--r-- | db/migrations/20210612181508_init_referrals.js | 2 | ||||
| -rw-r--r-- | db/migrations/20210612192804_init_waiting_list.js.js | 4 | ||||
| -rw-r--r-- | db/migrations/20210814193811_fix_db_conflicts.js | 16 | ||||
| -rw-r--r-- | lib/webhooks.js | 2 | ||||
| -rw-r--r-- | routes/bitcoin/receive.js | 1 | ||||
| -rw-r--r-- | routes/lnurl.js | 35 | ||||
| -rw-r--r-- | routes/send.js | 19 |
7 files changed, 71 insertions, 8 deletions
diff --git a/db/migrations/20210612181508_init_referrals.js b/db/migrations/20210612181508_init_referrals.js index f9107e15..ae07799d 100644 --- a/db/migrations/20210612181508_init_referrals.js +++ b/db/migrations/20210612181508_init_referrals.js @@ -14,7 +14,7 @@ exports.up = function(knex) { t.string('expiry').nullable(); t.enum('status', ['available', 'used', 'expired', 'cancelled']).notNull().defaultTo('available'); - t.timestamps(); + t.timestamps(true, true); }) ]) }; diff --git a/db/migrations/20210612192804_init_waiting_list.js.js b/db/migrations/20210612192804_init_waiting_list.js.js index 67762ff1..1e8d2be6 100644 --- a/db/migrations/20210612192804_init_waiting_list.js.js +++ b/db/migrations/20210612192804_init_waiting_list.js.js @@ -14,11 +14,11 @@ exports.up = function(knex) { t.foreign('user_id').references('users.id'); t.text('notes').nullable(); - t.timestamps(); + t.timestamps(true, true); }) ]) } exports.down = function(knex) { return knex.schema.dropTable('waiting_list'); -}
\ No newline at end of file +} diff --git a/db/migrations/20210814193811_fix_db_conflicts.js b/db/migrations/20210814193811_fix_db_conflicts.js new file mode 100644 index 00000000..37ff2bbc --- /dev/null +++ b/db/migrations/20210814193811_fix_db_conflicts.js @@ -0,0 +1,16 @@ + +exports.up = function(knex) { + return Promise.all([ + knex.raw("UPDATE waiting_list set created_at = '2021-01-01', updated_at='2021-01-01' WHERE updated_at IS NULL OR created_at IS NULL"), + knex.raw("ALTER TABLE waiting_list MODIFY created_at datetime NOT NULL DEFAULT CURRENT_TIMESTAMP"), + knex.raw("ALTER TABLE waiting_list MODIFY updated_at datetime NOT NULL DEFAULT CURRENT_TIMESTAMP"), + + knex.raw("UPDATE referrals set created_at = '2021-01-01', updated_at='2021-01-01' WHERE updated_at IS NULL OR created_at IS NULL"), + knex.raw("ALTER TABLE referrals MODIFY created_at datetime NOT NULL DEFAULT CURRENT_TIMESTAMP"), + knex.raw("ALTER TABLE referrals MODIFY updated_at datetime NOT NULL DEFAULT CURRENT_TIMESTAMP") + ]) +}; + +exports.down = function(knex) { + +}; diff --git a/lib/webhooks.js b/lib/webhooks.js index 86e1a07b..c282ceea 100644 --- a/lib/webhooks.js +++ b/lib/webhooks.js @@ -12,7 +12,7 @@ callWebhook = (invoice, payment) => { let { asset } = account; let secret = config.webhooks[webhook]; - l.info("calling webhook", webhook); + l.info("calling webhook", webhook, amount, hash, address, text); return wretch() .headers({ "x-webhook": secret }) .url(webhook) diff --git a/routes/bitcoin/receive.js b/routes/bitcoin/receive.js index d9274935..327d1a0c 100644 --- a/routes/bitcoin/receive.js +++ b/routes/bitcoin/receive.js @@ -54,6 +54,7 @@ zmqRawTx.on("message", async (topic, message, sequence) => { const invoice = await db.Invoice.findOne({ where: { + address, user_id: user.id, network: "bitcoin", }, diff --git a/routes/lnurl.js b/routes/lnurl.js index 67f581d1..feceb913 100644 --- a/routes/lnurl.js +++ b/routes/lnurl.js @@ -115,6 +115,41 @@ app.post( ); app.get( + "/lnurlp/:username", + ah(async (req, res, next) => { + const { username } = req.params; + let user = await db.User.findOne({ + where: { + username + } + }); + + let { amount, minSendable, maxSendable } = req.query; + minSendable = minSendable || 1000; + maxSendable = maxSendable || 1000000000; + if (parseInt(amount)) minSendable = maxSendable = amount * 1000; + + try { + let result = await lnurlServer.generateNewUrl("payRequest", { + minSendable, + maxSendable, + metadata: JSON.stringify([["text/plain", `paying ${user.username}`]]) + }); + + recipients[result.secret] = user; + l.info("recipient", user.username, result.secret); + + result = await axios.get(result.url); + + res.send(result.data); + } catch (e) { + l.error("problem generating payment url", e.message); + res.status(500).send(e.message); + } + }) +); + +app.get( "/pay/:username", ah(async (req, res, next) => { const { username } = req.params; diff --git a/routes/send.js b/routes/send.js index 3f240e85..9b4396ef 100644 --- a/routes/send.js +++ b/routes/send.js @@ -2,7 +2,15 @@ const axios = require("axios"); const uuidv4 = require("uuid/v4"); module.exports = ah(async (req, res, next) => { - let { amount, asset, memo, username } = req.body; + let { + amount, + address, + payreq, + unconfidential, + asset, + memo, + username, + } = req.body; let { user } = req; amount = parseInt(amount); @@ -74,9 +82,12 @@ module.exports = ah(async (req, res, next) => { { transaction } ); - let invoice = await db.Invoice.findOne({ - where: { amount, user_id: recipient.id }, - }); + let text = address || payreq; + params = { + where: { user_id: recipient.id }, + }; + if (text) params.where.text = text; + let invoice = await db.Invoice.findOne(params); let a2; let acc = { |
