Browse Source

Merge pull request #68 from stakwork/fix-purchase

Fix purchase
push-params v0.10.4
Evan Feenstra 5 years ago
committed by GitHub
parent
commit
db8d657b45
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      api/controllers/subscriptions.ts
  2. 2
      api/network/receive.ts
  3. 13
      api/network/send.ts
  4. 2
      dist/api/controllers/chatTribes.js
  5. 2
      dist/api/controllers/chatTribes.js.map
  6. 2
      dist/api/controllers/subscriptions.js
  7. 2
      dist/api/controllers/subscriptions.js.map
  8. 2
      dist/api/network/receive.js
  9. 2
      dist/api/network/receive.js.map
  10. 9
      dist/api/network/send.js
  11. 2
      dist/api/network/send.js.map

2
api/controllers/subscriptions.ts

@ -322,7 +322,7 @@ export async function createSubscription(req, res) {
};
export async function editSubscription(req, res) {
console.log('======> editSubscription')
console.log('=> editSubscription')
const date = new Date()
date.setMilliseconds(0)
const id = parseInt(req.params.id)

2
api/network/receive.ts

@ -34,7 +34,6 @@ export const typesToReplay=[ // should match typesToForward
msgtypes.message, msgtypes.group_join, msgtypes.group_leave
]
async function onReceive(payload){
// console.log("=> ON RECEIVE",payload)
// if tribe, owner must forward to MQTT
let doAction = true
const toAddIn:{[k:string]:any} = {}
@ -187,7 +186,6 @@ export async function initTribesSubscriptions(){
tribes.connect(async(topic, message)=>{ // onMessage callback
try{
const msg = message.toString()
// console.log("=====> msg received! TOPIC", topic, "MESSAGE", msg)
// check topic is signed by sender?
const payload = await parseAndVerifyPayload(msg)
onReceive(payload)

13
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) {
@ -109,7 +116,7 @@ export function signAndSend(opts, mqttTopic?:string, replayingHistory?:boolean){
const sig = await signer.signAscii(data)
data = data + sig
// console.log("ACTUALLY SEND", mqttTopic)
try {
if(mqttTopic) {

2
dist/api/controllers/chatTribes.js

@ -150,7 +150,7 @@ function receiveMemberRequest(payload) {
}
if (!theSender)
return console.log('no sender'); // fail (no contact key?)
models_1.models.ChatMember.upsert({
yield models_1.models.ChatMember.upsert({
contactId: theSender.id,
chatId: chat.id,
role: constants.chat_roles.reader,

2
dist/api/controllers/chatTribes.js.map

File diff suppressed because one or more lines are too long

2
dist/api/controllers/subscriptions.js

@ -347,7 +347,7 @@ exports.createSubscription = createSubscription;
;
function editSubscription(req, res) {
return __awaiter(this, void 0, void 0, function* () {
console.log('======> editSubscription');
console.log('=> editSubscription');
const date = new Date();
date.setMilliseconds(0);
const id = parseInt(req.params.id);

2
dist/api/controllers/subscriptions.js.map

File diff suppressed because one or more lines are too long

2
dist/api/network/receive.js

@ -43,7 +43,6 @@ exports.typesToReplay = [
];
function onReceive(payload) {
return __awaiter(this, void 0, void 0, function* () {
// console.log("=> ON RECEIVE",payload)
// if tribe, owner must forward to MQTT
let doAction = true;
const toAddIn = {};
@ -209,7 +208,6 @@ function initTribesSubscriptions() {
tribes.connect((topic, message) => __awaiter(this, void 0, void 0, function* () {
try {
const msg = message.toString();
// console.log("=====> msg received! TOPIC", topic, "MESSAGE", msg)
// check topic is signed by sender?
const payload = yield parseAndVerifyPayload(msg);
onReceive(payload);

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

File diff suppressed because one or more lines are too long

9
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;
}

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

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