Merge pull request #234 from shocknet/tip-post-via-http
tip post through http
This commit is contained in:
commit
ca615cd69f
2 changed files with 35 additions and 8 deletions
|
|
@ -906,17 +906,30 @@ const sendHRWithInitialMsg = async (
|
|||
await sendMessage(recipientPublicKey, initialMsg, user, SEA)
|
||||
}
|
||||
|
||||
/**
|
||||
* @typedef {object} SpontPaymentOptions
|
||||
* @prop {Common.Schema.OrderTargetType} type
|
||||
* @prop {string=} postID
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns the preimage corresponding to the payment.
|
||||
* @param {string} to
|
||||
* @param {number} amount
|
||||
* @param {string} memo
|
||||
* @param {number} feeLimit
|
||||
* @param {SpontPaymentOptions} opts
|
||||
* @throws {Error} If no response in less than 20 seconds from the recipient, or
|
||||
* lightning cannot find a route for the payment.
|
||||
* @returns {Promise<PaymentV2>} The payment's preimage.
|
||||
*/
|
||||
const sendSpontaneousPayment = async (to, amount, memo, feeLimit) => {
|
||||
const sendSpontaneousPayment = async (
|
||||
to,
|
||||
amount,
|
||||
memo,
|
||||
feeLimit,
|
||||
opts = { type: 'user' }
|
||||
) => {
|
||||
try {
|
||||
const SEA = require('../Mediator').mySEA
|
||||
const getUser = () => require('../Mediator').getUser()
|
||||
|
|
@ -937,7 +950,11 @@ const sendSpontaneousPayment = async (to, amount, memo, feeLimit) => {
|
|||
from: getUser()._.sea.pub,
|
||||
memo: memo || 'no memo',
|
||||
timestamp: Date.now(),
|
||||
targetType: 'user'
|
||||
targetType: opts.type
|
||||
}
|
||||
|
||||
if (opts.type === 'post') {
|
||||
order.postID = opts.postID
|
||||
}
|
||||
|
||||
logger.info(JSON.stringify(order))
|
||||
|
|
|
|||
|
|
@ -1267,12 +1267,12 @@ module.exports = async (
|
|||
|
||||
app.post('/api/lnd/unifiedTrx', async (req, res) => {
|
||||
try {
|
||||
const { type, amt, to, memo, feeLimit } = req.body
|
||||
const { type, amt, to, memo, feeLimit, postID } = req.body
|
||||
|
||||
if (type !== 'spont') {
|
||||
if (type !== 'spont' && type !== 'post') {
|
||||
return res.status(415).json({
|
||||
field: 'type',
|
||||
errorMessage: `Only 'spont' payments supported via this endpoint for now.`
|
||||
errorMessage: `Only 'spont' and 'post' payments supported via this endpoint for now.`
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -1306,9 +1306,19 @@ module.exports = async (
|
|||
})
|
||||
}
|
||||
|
||||
return res
|
||||
.status(200)
|
||||
.json(await GunActions.sendSpontaneousPayment(to, amt, memo, feeLimit))
|
||||
if (type === 'post' && typeof postID !== 'string') {
|
||||
return res.status(400).json({
|
||||
field: 'postID',
|
||||
errorMessage: `Send postID`
|
||||
})
|
||||
}
|
||||
|
||||
return res.status(200).json(
|
||||
await GunActions.sendSpontaneousPayment(to, amt, memo, feeLimit, {
|
||||
type,
|
||||
postID
|
||||
})
|
||||
)
|
||||
} catch (e) {
|
||||
return res.status(500).json({
|
||||
errorMessage: e.message
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue