Browse Source

sync chat meta (itemID, timetamp, sats_per_minute), tip amount

dependabot/npm_and_yarn/ini-1.3.7
Evan Feenstra 4 years ago
parent
commit
c52b9349cc
  1. 10
      dist/src/controllers/contacts.js
  2. 2
      dist/src/controllers/contacts.js.map
  3. 103
      dist/src/controllers/feed.js
  4. 1
      dist/src/controllers/feed.js.map
  5. 2
      dist/src/controllers/index.js
  6. 2
      dist/src/controllers/index.js.map
  7. 51
      dist/src/controllers/payment.js
  8. 2
      dist/src/controllers/payment.js.map
  9. 4
      dist/src/models/ts/chat.js
  10. 2
      dist/src/models/ts/chat.js.map
  11. 4
      dist/src/models/ts/contact.js
  12. 2
      dist/src/models/ts/contact.js.map
  13. 2
      dist/src/utils/setup.js
  14. 2
      dist/src/utils/setup.js.map
  15. 10
      src/controllers/contacts.ts
  16. 115
      src/controllers/feed.ts
  17. 3
      src/controllers/index.ts
  18. 56
      src/controllers/payment.ts
  19. 3
      src/models/ts/chat.ts
  20. 3
      src/models/ts/contact.ts
  21. 4
      src/utils/setup.ts

10
dist/src/controllers/contacts.js

@ -80,7 +80,7 @@ exports.updateContact = (req, res) => __awaiter(void 0, void 0, void 0, function
if (!contact) {
return res_1.failure(res, 'no contact found');
}
// update self
// update contact
const owner = yield contact.update(jsonUtils.jsonToContact(attrs));
res_1.success(res, jsonUtils.contactToJson(owner));
if (!contact.isOwner)
@ -88,6 +88,12 @@ exports.updateContact = (req, res) => __awaiter(void 0, void 0, void 0, function
if (!(attrs['contact_key'] || attrs['alias'] || attrs['photo_url'])) {
return; // skip if not at least one of these
}
const contactKeyChanged = contact.contactKey !== attrs['contact_key'];
const aliasChanged = contact.alias !== attrs['alias'];
const photoChanged = contact.photoUrl !== attrs['photo_url'];
if (!(contactKeyChanged || aliasChanged || photoChanged)) {
return;
}
// send updated owner info to others!
const contactIds = yield models_1.models.Contact.findAll({ where: { deleted: false } })
.filter(c => c.id !== 1 && c.publicKey).map(c => c.id);
@ -242,7 +248,7 @@ exports.receiveConfirmContactKey = (payload) => __awaiter(void 0, void 0, void 0
}
});
const extractAttrs = body => {
let fields_to_update = ["public_key", "node_alias", "alias", "photo_url", "device_id", "status", "contact_key", "from_group", "private_photo", "notification_sound"];
let fields_to_update = ["public_key", "node_alias", "alias", "photo_url", "device_id", "status", "contact_key", "from_group", "private_photo", "notification_sound", "tip_amount"];
let attrs = {};
Object.keys(body).forEach(key => {
if (fields_to_update.includes(key)) {

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

File diff suppressed because one or more lines are too long

103
dist/src/controllers/feed.js

@ -0,0 +1,103 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const models_1 = require("../models");
const helpers = require("../helpers");
const res_1 = require("../utils/res");
const constants_1 = require("../constants");
exports.streamFeed = (req, res) => __awaiter(void 0, void 0, void 0, function* () {
const { destinations, amount, chat_id, text } = req.body;
if (!(destinations && destinations.length)) {
return res_1.failure(res, 'no destinations');
}
let meta;
try {
meta = JSON.parse(text);
}
catch (e) { }
if (!meta) {
return res_1.failure(res, 'no meta');
}
if (meta && meta.itemID) {
const cm = {
itemID: meta.itemID,
timestamp: meta.timestamp || 0,
sats_per_minute: amount || 0,
};
const chat = yield models_1.models.Chat.findOne({ where: { id: chat_id } });
if (!chat) {
return res_1.failure(res, 'no chat');
}
yield chat.update({ meta: JSON.stringify(cm) });
}
const owner = yield models_1.models.Contact.findOne({ where: { isOwner: true } });
if (amount && typeof amount === 'number') {
yield asyncForEach(destinations, (d) => __awaiter(void 0, void 0, void 0, function* () {
if (d.type === 'node') {
if (!d.address)
return;
if (d.address.length !== 66)
return;
if (d.address === owner.publicKey)
return; // dont send to self
const amt = Math.max(Math.round((d.split / 100) * amount), 1);
yield anonymousKeysend(owner, d.address, amt, text, function () { }, function () { });
}
}));
}
res_1.success(res, {});
});
function anonymousKeysend(owner, destination_key, amount, text, onSuccess, onFailure) {
return __awaiter(this, void 0, void 0, function* () {
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
});
onSuccess({ destination_key, amount });
},
failure: (error) => {
onFailure(error);
}
});
});
}
exports.anonymousKeysend = anonymousKeysend;
function asyncForEach(array, callback) {
return __awaiter(this, void 0, void 0, function* () {
for (let index = 0; index < array.length; index++) {
yield callback(array[index], index, array);
}
});
}
//# sourceMappingURL=feed.js.map

1
dist/src/controllers/feed.js.map

@ -0,0 +1 @@
{"version":3,"file":"feed.js","sourceRoot":"","sources":["../../../src/controllers/feed.ts"],"names":[],"mappings":";;;;;;;;;;;AACA,sCAAgC;AAChC,sCAAqC;AACrC,sCAA+C;AAC/C,4CAAoC;AAevB,QAAA,UAAU,GAAG,CAAO,GAAG,EAAC,GAAG,EAAE,EAAE;IAC1C,MAAM,EACJ,YAAY,EACZ,MAAM,EACN,OAAO,EACP,IAAI,EACL,GAKG,GAAG,CAAC,IAAI,CAAA;IAEZ,IAAG,CAAC,CAAC,YAAY,IAAI,YAAY,CAAC,MAAM,CAAC,EAAE;QACzC,OAAO,aAAO,CAAC,GAAG,EAAE,iBAAiB,CAAC,CAAA;KACvC;IACD,IAAI,IAAI,CAAC;IACT,IAAI;QACF,IAAI,GAAG,IAAI,CAAC,KAAK,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EAAE,IAAI;oBACf,SAAS,EAAE,IAAI;iBAChB,CAAC,CAAA;gBACF,SAAS,CAAC,EAAC,eAAe,EAAE,MAAM,EAAC,CAAC,CAAA;YACtC,CAAC;YACD,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE;gBACjB,SAAS,CAAC,KAAK,CAAC,CAAA;YAClB,CAAC;SACF,CAAC,CAAA;IACJ,CAAC;CAAA;AAlCD,4CAkCC;AAED,SAAe,YAAY,CAAC,KAAK,EAAE,QAAQ;;QACzC,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE;YACjD,MAAM,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;SAC5C;IACH,CAAC;CAAA"}

2
dist/src/controllers/index.js

@ -28,6 +28,7 @@ const gitinfo_1 = require("../utils/gitinfo");
const timers = require("../utils/timers");
const builtInBots = require("../builtin");
const constants_1 = require("../constants");
const feed = require("./feed");
function set(app) {
return __awaiter(this, void 0, void 0, function* () {
builtInBots.init();
@ -78,6 +79,7 @@ function set(app) {
app.post('/attachment', media.sendAttachmentMessage);
app.post('/purchase', media.purchase);
app.get('/signer/:challenge', media.signer);
app.post('/stream', feed.streamFeed);
app.post('/invoices', invoices.createInvoice);
app.get('/invoices', invoices.listInvoices);
app.put('/invoices', invoices.payInvoice);

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

File diff suppressed because one or more lines are too long

51
dist/src/controllers/payment.js

@ -20,14 +20,21 @@ const network = require("../network");
const short = require("short-uuid");
const constants_1 = require("../constants");
const sequelize_1 = require("sequelize");
const feed_1 = require("./feed");
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) {
anonymousKeysend(res, destination_key, amount || '', text || '');
feed_1.anonymousKeysend(owner, destination_key, amount || '', text || '', function (body) {
res_1.success(res, body);
}, function (error) {
res.status(200);
res.json({ success: false, error });
res.end();
});
return;
}
const owner = yield models_1.models.Contact.findOne({ where: { isOwner: true } });
const chat = yield helpers.findOrCreateChat({
chat_id,
owner_id: owner.id,
@ -104,46 +111,6 @@ 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

4
dist/src/models/ts/chat.js

@ -124,6 +124,10 @@ __decorate([
sequelize_typescript_1.Column,
__metadata("design:type", String)
], Chat.prototype, "feedUrl", void 0);
__decorate([
sequelize_typescript_1.Column,
__metadata("design:type", String)
], Chat.prototype, "meta", void 0);
Chat = __decorate([
sequelize_typescript_1.Table({ tableName: 'sphinx_chats', underscored: true })
], Chat);

2
dist/src/models/ts/chat.js.map

@ -1 +1 @@
{"version":3,"file":"chat.js","sourceRoot":"","sources":["../../../../src/models/ts/chat.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,+DAAsE;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,IAAI,EAAE,+BAAQ,CAAC,OAAO;QACtB,YAAY,EAAE,KAAK;KAEpB,CAAC;;sCACe;AAGjB;IADC,6BAAM;;qCACS;AAGhB;IADC,6BAAM;;yCACY;AAOnB;IALC,6BAAM,CAAC;QACN,IAAI,EAAE,+BAAQ,CAAC,OAAO;QACtB,YAAY,EAAE,KAAK;QACnB,SAAS,EAAE,KAAK;KACjB,CAAC;;kCACW;AAGb;IADC,6BAAM;;oCACO;AAGd;IADC,6BAAM;;qCACQ;AAGf;IADC,6BAAM;;kCACK;AA5FO,IAAI;IADxB,4BAAK,CAAC,EAAC,SAAS,EAAE,cAAc,EAAE,WAAW,EAAE,IAAI,EAAC,CAAC;GACjC,IAAI,CA8FxB;kBA9FoB,IAAI"}

4
dist/src/models/ts/contact.js

@ -93,6 +93,10 @@ __decorate([
sequelize_typescript_1.Column,
__metadata("design:type", Date)
], Contact.prototype, "lastActive", void 0);
__decorate([
sequelize_typescript_1.Column(sequelize_typescript_1.DataType.BIGINT),
__metadata("design:type", Number)
], Contact.prototype, "tipAmount", void 0);
Contact = __decorate([
sequelize_typescript_1.Table({ tableName: 'sphinx_contacts', underscored: true })
], Contact);

2
dist/src/models/ts/contact.js.map

@ -1 +1 @@
{"version":3,"file":"contact.js","sourceRoot":"","sources":["../../../../src/models/ts/contact.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,+DAAsE;AAGtE,IAAqB,OAAO,GAA5B,MAAqB,OAAQ,SAAQ,4BAAc;CAiElD,CAAA;AAzDC;IANC,6BAAM,CAAC;QACN,IAAI,EAAE,+BAAQ,CAAC,MAAM;QACrB,UAAU,EAAE,IAAI;QAChB,MAAM,EAAE,IAAI;QACZ,aAAa,EAAE,IAAI;KACpB,CAAC;;mCACQ;AAGV;IADC,6BAAM;;0CACU;AAGjB;IADC,6BAAM;;0CACU;AAGjB;IADC,6BAAM;;sCACM;AAGb;IADC,6BAAM;;yCACS;AAGhB;IADC,6BAAM;;6CACc;AAGrB;IADC,6BAAM;;wCACS;AAOhB;IALC,6BAAM,CAAC;QACN,IAAI,EAAE,+BAAQ,CAAC,OAAO;QACtB,YAAY,EAAE,KAAK;QACnB,SAAS,EAAE,KAAK;KACjB,CAAC;;wCACc;AAGhB;IADC,6BAAM;;0CACU;AAGjB;IADC,6BAAM,CAAC,+BAAQ,CAAC,MAAM,CAAC;;yCACR;AAGhB;IADC,6BAAM,CAAC,+BAAQ,CAAC,MAAM,CAAC;;uCACV;AAGd;IADC,6BAAM,CAAC,+BAAQ,CAAC,IAAI,CAAC;;2CACJ;AAGlB;IADC,6BAAM;;yCACS;AAGhB;IADC,6BAAM;8BACI,IAAI;0CAAA;AAGf;IADC,6BAAM;8BACI,IAAI;0CAAA;AAGf;IADC,6BAAM;;0CACW;AAGlB;IADC,6BAAM;;kDACkB;AAGzB;IADC,6BAAM;8BACK,IAAI;2CAAA;AA/DG,OAAO;IAD3B,4BAAK,CAAC,EAAC,SAAS,EAAE,iBAAiB,EAAE,WAAW,EAAE,IAAI,EAAC,CAAC;GACpC,OAAO,CAiE3B;kBAjEoB,OAAO"}
{"version":3,"file":"contact.js","sourceRoot":"","sources":["../../../../src/models/ts/contact.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,+DAAsE;AAGtE,IAAqB,OAAO,GAA5B,MAAqB,OAAQ,SAAQ,4BAAc;CAoElD,CAAA;AA5DC;IANC,6BAAM,CAAC;QACN,IAAI,EAAE,+BAAQ,CAAC,MAAM;QACrB,UAAU,EAAE,IAAI;QAChB,MAAM,EAAE,IAAI;QACZ,aAAa,EAAE,IAAI;KACpB,CAAC;;mCACQ;AAGV;IADC,6BAAM;;0CACU;AAGjB;IADC,6BAAM;;0CACU;AAGjB;IADC,6BAAM;;sCACM;AAGb;IADC,6BAAM;;yCACS;AAGhB;IADC,6BAAM;;6CACc;AAGrB;IADC,6BAAM;;wCACS;AAOhB;IALC,6BAAM,CAAC;QACN,IAAI,EAAE,+BAAQ,CAAC,OAAO;QACtB,YAAY,EAAE,KAAK;QACnB,SAAS,EAAE,KAAK;KACjB,CAAC;;wCACc;AAGhB;IADC,6BAAM;;0CACU;AAGjB;IADC,6BAAM,CAAC,+BAAQ,CAAC,MAAM,CAAC;;yCACR;AAGhB;IADC,6BAAM,CAAC,+BAAQ,CAAC,MAAM,CAAC;;uCACV;AAGd;IADC,6BAAM,CAAC,+BAAQ,CAAC,IAAI,CAAC;;2CACJ;AAGlB;IADC,6BAAM;;yCACS;AAGhB;IADC,6BAAM;8BACI,IAAI;0CAAA;AAGf;IADC,6BAAM;8BACI,IAAI;0CAAA;AAGf;IADC,6BAAM;;0CACW;AAGlB;IADC,6BAAM;;kDACkB;AAGzB;IADC,6BAAM;8BACK,IAAI;2CAAA;AAGhB;IADC,6BAAM,CAAC,+BAAQ,CAAC,MAAM,CAAC;;0CACP;AAlEE,OAAO;IAD3B,4BAAK,CAAC,EAAC,SAAS,EAAE,iBAAiB,EAAE,WAAW,EAAE,IAAI,EAAC,CAAC;GACpC,OAAO,CAoE3B;kBApEoB,OAAO"}

2
dist/src/utils/setup.js

@ -48,6 +48,8 @@ function setVersion() {
}
function migrate() {
return __awaiter(this, void 0, void 0, function* () {
addTableColumn('sphinx_chats', 'meta');
addTableColumn('sphinx_contacts', 'tip_amount', 'BIGINT');
addTableColumn('sphinx_contacts', 'last_active', 'DATETIME');
try {
yield models_1.sequelize.query(`

2
dist/src/utils/setup.js.map

File diff suppressed because one or more lines are too long

10
src/controllers/contacts.ts

@ -83,7 +83,7 @@ export const updateContact = async (req, res) => {
return failure(res, 'no contact found')
}
// update self
// update contact
const owner = await contact.update(jsonUtils.jsonToContact(attrs))
success(res, jsonUtils.contactToJson(owner))
@ -91,6 +91,12 @@ export const updateContact = async (req, res) => {
if (!(attrs['contact_key'] || attrs['alias'] || attrs['photo_url'])) {
return // skip if not at least one of these
}
const contactKeyChanged = contact.contactKey!==attrs['contact_key']
const aliasChanged = contact.alias!==attrs['alias']
const photoChanged = contact.photoUrl!==attrs['photo_url']
if(!(contactKeyChanged || aliasChanged || photoChanged)) {
return
}
// send updated owner info to others!
const contactIds = await models.Contact.findAll({where:{deleted:false}})
@ -267,7 +273,7 @@ export const receiveConfirmContactKey = async (payload) => {
}
const extractAttrs = body => {
let fields_to_update = ["public_key", "node_alias", "alias", "photo_url", "device_id", "status", "contact_key", "from_group", "private_photo", "notification_sound"]
let fields_to_update = ["public_key", "node_alias", "alias", "photo_url", "device_id", "status", "contact_key", "from_group", "private_photo", "notification_sound", "tip_amount"]
let attrs = {}
Object.keys(body).forEach(key => {
if (fields_to_update.includes(key)) {

115
src/controllers/feed.ts

@ -0,0 +1,115 @@
import {models} from '../models'
import * as helpers from '../helpers'
import { failure, success } from '../utils/res'
import constants from '../constants'
export interface ChatMeta {
itemID: number,
timestamp: number,
sats_per_minute: number,
}
type DestinationType = 'wallet' | 'node'
export interface Destination {
address: string
split: number
type: DestinationType
}
export const streamFeed = async (req,res) => {
const {
destinations,
amount,
chat_id,
text
}:{
destinations:Destination[],
amount:number,
chat_id:number,
text:string
} = req.body
if(!(destinations && destinations.length)) {
return failure(res, 'no destinations')
}
let meta;
try {
meta = JSON.parse(text)
} catch(e) {}
if(!meta) {
return failure(res, 'no meta')
}
if(meta && meta.itemID) {
const cm:ChatMeta = {
itemID: meta.itemID,
timestamp: meta.timestamp||0,
sats_per_minute: amount||0,
}
const chat = await models.Chat.findOne({ where: { id: chat_id } })
if(!chat) {
return failure(res, 'no chat')
}
await chat.update({meta: JSON.stringify(cm)})
}
const owner = await models.Contact.findOne({ where: { isOwner: true }})
if(amount && typeof amount==='number') {
await asyncForEach(destinations, async (d:Destination)=>{
if (d.type === 'node') {
if (!d.address) return
if (d.address.length !== 66) return
if (d.address===owner.publicKey) return // dont send to self
const amt = Math.max(Math.round((d.split / 100) * amount), 1)
await anonymousKeysend(owner, d.address, amt, text, function(){}, function(){})
}
})
}
success(res, {})
}
export async function anonymousKeysend(owner, destination_key:string, amount:number, text:string, onSuccess:Function, onFailure:Function){
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
})
onSuccess({destination_key, amount})
},
failure: (error) => {
onFailure(error)
}
})
}
async function asyncForEach(array, callback) {
for (let index = 0; index < array.length; index++) {
await callback(array[index], index, array);
}
}

3
src/controllers/index.ts

@ -17,6 +17,7 @@ import {checkTag} from '../utils/gitinfo'
import * as timers from '../utils/timers'
import * as builtInBots from '../builtin'
import constants from '../constants'
import * as feed from './feed'
export async function set(app) {
@ -77,6 +78,8 @@ export async function set(app) {
app.post('/purchase', media.purchase)
app.get('/signer/:challenge', media.signer)
app.post('/stream', feed.streamFeed)
app.post('/invoices', invoices.createInvoice)
app.get('/invoices', invoices.listInvoices)
app.put('/invoices', invoices.payInvoice)

56
src/controllers/payment.ts

@ -9,6 +9,7 @@ import * as network from '../network'
import * as short from 'short-uuid'
import constants from '../constants'
import { Op } from 'sequelize'
import {anonymousKeysend} from './feed'
export const sendPayment = async (req, res) => {
const {
@ -28,13 +29,22 @@ 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) {
anonymousKeysend(res, destination_key, amount||'', text||'')
anonymousKeysend(owner, destination_key, amount||'', text||'',
function(body) {
success(res, body)
},
function(error) {
res.status(200);
res.json({ success: false, error });
res.end();
}
)
return
}
const owner = await models.Contact.findOne({ where: { isOwner: true }})
const chat = await helpers.findOrCreateChat({
chat_id,
owner_id: owner.id,
@ -112,46 +122,6 @@ 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 })

3
src/models/ts/chat.ts

@ -92,4 +92,7 @@ export default class Chat extends Model<Chat> {
@Column
feedUrl: string
@Column
meta: string
}

3
src/models/ts/contact.ts

@ -66,4 +66,7 @@ export default class Contact extends Model<Contact> {
@Column
lastActive: Date
@Column(DataType.BIGINT)
tipAmount: number
}

4
src/utils/setup.ts

@ -37,6 +37,10 @@ async function setVersion() {
async function migrate() {
addTableColumn('sphinx_chats', 'meta')
addTableColumn('sphinx_contacts', 'tip_amount', 'BIGINT')
addTableColumn('sphinx_contacts', 'last_active', 'DATETIME')
try {

Loading…
Cancel
Save