Browse Source

force keysend if amount in payload from tribe admin to member

push-params
Evan Feenstra 4 years ago
parent
commit
e9effab778
  1. 1
      api/network/receive.ts
  2. 12
      api/network/send.ts
  3. 1
      dist/api/network/receive.js
  4. 2
      dist/api/network/receive.js.map
  5. 10
      dist/api/network/send.js
  6. 2
      dist/api/network/send.js.map

1
api/network/receive.ts

@ -228,6 +228,7 @@ export async function parseKeysendInvoice(i){
const buf = recs && recs[SPHINX_CUSTOM_RECORD_KEY]
const data = buf && buf.toString()
const value = i && i.value && parseInt(i.value)
console.log("==> RECEIVED BALUE",value)
if(!data) return
let payload

12
api/network/send.ts

@ -11,6 +11,8 @@ const constants = require(path.join(__dirname,'../../config/constants.json'))
type NetworkType = undefined | 'mqtt' | 'lightning'
const MIN_SATS = 3;
export async function sendMessage(params) {
const { type, chat, message, sender, amount, success, failure, skipPubKey } = params
let msg = newmsg(type, chat, sender, message)
@ -71,15 +73,20 @@ export async function sendMessage(params) {
}
console.log('-> sending to ', contact.id, destkey)
let mqttTopic = networkType==='mqtt' ? `${destkey}/${chatUUID}` : ''
// sending a payment to one subscriber (like buying a pic)
if(isTribeOwner && contactIds.length===1 && amount && amount>MIN_SATS) {
mqttTopic = '' // FORCE KEYSEND!!!
}
const m = await personalizeMessage(msg, contact, isTribeOwner)
const opts = {
dest: destkey,
data: m,
amt: Math.max((amount||0), 3)
amt: Math.max((amount||0), MIN_SATS)
}
try {
const mqttTopic = networkType==='mqtt' ? `${destkey}/${chatUUID}` : ''
const r = await signAndSend(opts, mqttTopic)
yes = r
} catch (e) {
@ -107,6 +114,7 @@ export function signAndSend(opts, mqttTopic?:string, replayingHistory?:boolean){
let data = JSON.stringify(opts.data||{})
opts.amt = opts.amt || 0
console.log("==> AMOuNTS TO SEND!",opts.amt)
console.log("==> NETWOrK TYPE:", mqttTopic?'mqtt':'lightning')
const sig = await signer.signAscii(data)
data = data + sig

1
dist/api/network/receive.js

@ -258,6 +258,7 @@ function parseKeysendInvoice(i) {
const buf = recs && recs[lightning_2.SPHINX_CUSTOM_RECORD_KEY];
const data = buf && buf.toString();
const value = i && i.value && parseInt(i.value);
console.log("==> RECEIVED BALUE", value);
if (!data)
return;
let payload;

2
dist/api/network/receive.js.map

File diff suppressed because one or more lines are too long

10
dist/api/network/send.js

@ -18,6 +18,7 @@ const tribes = require("../utils/tribes");
const confirmations_1 = require("../controllers/confirmations");
const receive_1 = require("./receive");
const constants = require(path.join(__dirname, '../../config/constants.json'));
const MIN_SATS = 3;
function sendMessage(params) {
return __awaiter(this, void 0, void 0, function* () {
const { type, chat, message, sender, amount, success, failure, skipPubKey } = params;
@ -75,14 +76,18 @@ function sendMessage(params) {
return; // skip (for tribe owner broadcasting, not back to the sender)
}
console.log('-> sending to ', contact.id, destkey);
let mqttTopic = networkType === 'mqtt' ? `${destkey}/${chatUUID}` : '';
// sending a payment to one subscriber (like buying a pic)
if (isTribeOwner && contactIds.length === 1 && amount && amount > MIN_SATS) {
mqttTopic = ''; // FORCE KEYSEND!!!
}
const m = yield msg_1.personalizeMessage(msg, contact, isTribeOwner);
const opts = {
dest: destkey,
data: m,
amt: Math.max((amount || 0), 3)
amt: Math.max((amount || 0), MIN_SATS)
};
try {
const mqttTopic = networkType === 'mqtt' ? `${destkey}/${chatUUID}` : '';
const r = yield signAndSend(opts, mqttTopic);
yes = r;
}
@ -116,6 +121,7 @@ function signAndSend(opts, mqttTopic, replayingHistory) {
let data = JSON.stringify(opts.data || {});
opts.amt = opts.amt || 0;
console.log("==> AMOuNTS TO SEND!", opts.amt);
console.log("==> NETWOrK TYPE:", mqttTopic ? 'mqtt' : 'lightning');
const sig = yield signer.signAscii(data);
data = data + sig;
// console.log("ACTUALLY SEND", mqttTopic)

2
dist/api/network/send.js.map

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save