Browse Source

save anon keysend when u send

loopout2
Evan Feenstra 4 years ago
parent
commit
a9d2190acf
  1. 64
      dist/src/controllers/payment.js
  2. 2
      dist/src/controllers/payment.js.map
  3. 65
      src/controllers/payment.ts

64
dist/src/controllers/payment.js

@ -23,29 +23,11 @@ const sequelize_1 = require("sequelize");
exports.sendPayment = (req, res) => __awaiter(void 0, void 0, void 0, function* () {
const { amount, chat_id, contact_id, destination_key, media_type, muid, text, remote_text, dimensions, remote_text_map, contact_ids, reply_uuid, } = req.body;
console.log('[send payment]', req.body);
const owner = yield models_1.models.Contact.findOne({ where: { isOwner: true } });
if (destination_key && !contact_id && !chat_id) {
const msg = {
type: constants_1.default.message_types.keysend,
};
if (text)
msg.message = { content: text };
return helpers.performKeysendMessage({
sender: owner,
destination_key,
amount,
msg,
success: () => {
console.log('payment sent!');
res_1.success(res, { destination_key, amount });
},
failure: (error) => {
res.status(200);
res.json({ success: false, error });
res.end();
}
});
anonymousKeysend(res, destination_key, amount || '', text || '');
return;
}
const owner = yield models_1.models.Contact.findOne({ where: { isOwner: true } });
const chat = yield helpers.findOrCreateChat({
chat_id,
owner_id: owner.id,
@ -122,6 +104,46 @@ exports.sendPayment = (req, res) => __awaiter(void 0, void 0, void 0, function*
})
});
});
function anonymousKeysend(res, destination_key, amount, text) {
return __awaiter(this, void 0, void 0, function* () {
const owner = yield models_1.models.Contact.findOne({ where: { isOwner: true } });
const msg = {
type: constants_1.default.message_types.keysend,
};
if (text)
msg.message = { content: text };
return helpers.performKeysendMessage({
sender: owner,
destination_key,
amount,
msg,
success: () => {
console.log('payment sent!');
var date = new Date();
date.setMilliseconds(0);
models_1.models.Message.create({
chatId: 0,
type: constants_1.default.message_types.keysend,
sender: 1,
amount,
amountMsat: amount * 1000,
paymentHash: '',
date,
messageContent: text || '',
status: constants_1.default.statuses.confirmed,
createdAt: date,
updatedAt: date
});
res_1.success(res, { destination_key, amount });
},
failure: (error) => {
res.status(200);
res.json({ success: false, error });
res.end();
}
});
});
}
exports.receivePayment = (payload) => __awaiter(void 0, void 0, void 0, function* () {
console.log('received payment', { payload });
var date = new Date();

2
dist/src/controllers/payment.js.map

File diff suppressed because one or more lines are too long

65
src/controllers/payment.ts

@ -28,30 +28,13 @@ export const sendPayment = async (req, res) => {
console.log('[send payment]', req.body)
const owner = await models.Contact.findOne({ where: { isOwner: true }})
if (destination_key && !contact_id && !chat_id) {
const msg:{[k:string]:any} = {
type:constants.message_types.keysend,
}
if(text) msg.message = {content:text}
return helpers.performKeysendMessage({
sender:owner,
destination_key,
amount,
msg,
success: () => {
console.log('payment sent!')
success(res, {destination_key, amount})
},
failure: (error) => {
res.status(200);
res.json({ success: false, error });
res.end();
}
})
anonymousKeysend(res, destination_key, amount||'', text||'')
return
}
const owner = await models.Contact.findOne({ where: { isOwner: true }})
const chat = await helpers.findOrCreateChat({
chat_id,
owner_id: owner.id,
@ -129,6 +112,46 @@ export const sendPayment = async (req, res) => {
})
};
async function anonymousKeysend(res, destination_key:string, amount:number, text:string){
const owner = await models.Contact.findOne({ where: { isOwner: true }})
const msg:{[k:string]:any} = {
type:constants.message_types.keysend,
}
if(text) msg.message = {content:text}
return helpers.performKeysendMessage({
sender:owner,
destination_key,
amount,
msg,
success: () => {
console.log('payment sent!')
var date = new Date();
date.setMilliseconds(0)
models.Message.create({
chatId: 0,
type: constants.message_types.keysend,
sender: 1,
amount,
amountMsat: amount*1000,
paymentHash: '',
date,
messageContent: text||'',
status: constants.statuses.confirmed,
createdAt: date,
updatedAt: date
})
success(res, {destination_key, amount})
},
failure: (error) => {
res.status(200);
res.json({ success: false, error });
res.end();
}
})
}
export const receivePayment = async (payload) => {
console.log('received payment', { payload })

Loading…
Cancel
Save