Browse Source

fix loopbot new api, get chan from bot.meta, gen file with conn string for raspiblitz

dependabot/npm_and_yarn/ini-1.3.7
Evan Feenstra 4 years ago
parent
commit
28b5f8b5b4
  1. 65
      dist/src/builtin/loop.js
  2. 2
      dist/src/builtin/loop.js.map
  3. 1
      dist/src/controllers/payment.js
  4. 2
      dist/src/controllers/payment.js.map
  5. 5
      dist/src/utils/setup.js
  6. 2
      dist/src/utils/setup.js.map
  7. 67
      src/builtin/loop.ts
  8. 1
      src/controllers/payment.ts
  9. 6
      src/utils/setup.ts

65
dist/src/builtin/loop.js

@ -13,9 +13,10 @@ const Sphinx = require("sphinx-bot");
const api_1 = require("../controllers/api"); const api_1 = require("../controllers/api");
const node_fetch_1 = require("node-fetch"); const node_fetch_1 = require("node-fetch");
const path = require("path"); const path = require("path");
const models_1 = require("../models");
const constants_1 = require("../constants");
var validate = require('bitcoin-address-validation'); var validate = require('bitcoin-address-validation');
const msg_types = Sphinx.MSG_TYPE; const msg_types = Sphinx.MSG_TYPE;
// /home/ec2-user/.lnd/data/chain/bitcoin/mainnet/admin.macaroon
let initted = false; let initted = false;
const baseurl = 'https://localhost:8080'; const baseurl = 'https://localhost:8080';
function init() { function init() {
@ -58,19 +59,27 @@ function init() {
try { try {
const j = yield doRequest(baseurl + '/v1/loop/out/quote/' + amt); const j = yield doRequest(baseurl + '/v1/loop/out/quote/' + amt);
console.log("=> LOOP QUOTE RES", j); console.log("=> LOOP QUOTE RES", j);
if (!(j && j.swap_fee && j.prepay_amt)) { if (!(j && j.swap_fee_sat && j.prepay_amt_sat)) {
return; return;
} }
let chan;
const bot = yield getBot(message.channel.id);
if (bot && bot.meta)
chan = bot.meta;
if (!chan) {
const embed = new Sphinx.MessageEmbed()
.setAuthor('LoopBot')
.setDescription('No channel set');
message.channel.send({ embed });
}
const j2 = yield doRequest(baseurl + '/v1/loop/out', { const j2 = yield doRequest(baseurl + '/v1/loop/out', {
method: 'POST', method: 'POST',
body: JSON.stringify({ body: JSON.stringify({
amt: amt, amt: amt,
dest: addy, dest: addy,
outgoing_chan_set: [ outgoing_chan_set: [chan],
'704899103684034561' max_swap_fee: j.swap_fee_sat,
], max_prepay_amt: j.prepay_amt_sat
max_swap_fee: j.swap_fee,
max_prepay_amt: j.prepay_amt
}), }),
}); });
console.log("=> LOOP RESPONSE", j2); console.log("=> LOOP RESPONSE", j2);
@ -81,13 +90,13 @@ function init() {
message.channel.send({ embed }); message.channel.send({ embed });
return; return;
} }
if (!(j2 && j2.server_message)) { // if (!(j2 && j2.server_message)) {
return; // return
} // }
const embed = new Sphinx.MessageEmbed() const embed = new Sphinx.MessageEmbed()
.setAuthor('LoopBot') .setAuthor('LoopBot')
.setTitle('Loop Initialized!') .setTitle('Payment was sent!');
.setDescription('Success!'); // .setDescription('Success!')
message.channel.send({ embed }); message.channel.send({ embed });
return; return;
} }
@ -96,6 +105,20 @@ function init() {
} }
} }
const cmd = arr[1]; const cmd = arr[1];
const isAdmin = message.member.roles.find(role => role.name === 'Admin');
if (isAdmin && cmd.startsWith('setchan=')) {
const bot = yield getBot(message.channel.id);
const arr = cmd.split('=');
if (bot && arr.length > 1) {
const chan = arr[1];
yield bot.update({ meta: chan });
const embed = new Sphinx.MessageEmbed()
.setAuthor('LoopBot')
.setDescription('Channel updated to ' + chan)
.setThumbnail(botSVG);
message.channel.send({ embed });
}
}
switch (cmd) { switch (cmd) {
case 'help': case 'help':
const embed = new Sphinx.MessageEmbed() const embed = new Sphinx.MessageEmbed()
@ -103,7 +126,8 @@ function init() {
.setTitle('LoopBot Commands:') .setTitle('LoopBot Commands:')
.addFields([ .addFields([
{ name: 'Send to your on-chain address', value: '/loopout {ADDRESS} {AMOUNT}' }, { name: 'Send to your on-chain address', value: '/loopout {ADDRESS} {AMOUNT}' },
{ name: 'Help', value: '/loopout help' } { name: 'Set Channel', value: '/loopout setchan=***' },
{ name: 'Help', value: '/loopout help' },
]) ])
.setThumbnail(botSVG); .setThumbnail(botSVG);
message.channel.send({ embed }); message.channel.send({ embed });
@ -118,6 +142,21 @@ function init() {
})); }));
} }
exports.init = init; exports.init = init;
function getBot(tribeUUID) {
return __awaiter(this, void 0, void 0, function* () {
const chat = yield models_1.models.Chat.findOne({ where: {
uuid: tribeUUID
} });
if (!chat)
return;
const chatBot = yield models_1.models.ChatBot.findOne({ where: {
chatId: chat.id,
botPrefix: '/loopout',
botType: constants_1.default.bot_types.builtin
} });
return chatBot;
});
}
const botSVG = `<svg viewBox="64 64 896 896" height="12" width="12" fill="white"> const botSVG = `<svg viewBox="64 64 896 896" height="12" width="12" fill="white">
<path d="M300 328a60 60 0 10120 0 60 60 0 10-120 0zM852 64H172c-17.7 0-32 14.3-32 32v660c0 17.7 14.3 32 32 32h680c17.7 0 32-14.3 32-32V96c0-17.7-14.3-32-32-32zm-32 660H204V128h616v596zM604 328a60 60 0 10120 0 60 60 0 10-120 0zm250.2 556H169.8c-16.5 0-29.8 14.3-29.8 32v36c0 4.4 3.3 8 7.4 8h729.1c4.1 0 7.4-3.6 7.4-8v-36c.1-17.7-13.2-32-29.7-32zM664 508H360c-4.4 0-8 3.6-8 8v60c0 4.4 3.6 8 8 8h304c4.4 0 8-3.6 8-8v-60c0-4.4-3.6-8-8-8z" /> <path d="M300 328a60 60 0 10120 0 60 60 0 10-120 0zM852 64H172c-17.7 0-32 14.3-32 32v660c0 17.7 14.3 32 32 32h680c17.7 0 32-14.3 32-32V96c0-17.7-14.3-32-32-32zm-32 660H204V128h616v596zM604 328a60 60 0 10120 0 60 60 0 10-120 0zm250.2 556H169.8c-16.5 0-29.8 14.3-29.8 32v36c0 4.4 3.3 8 7.4 8h729.1c4.1 0 7.4-3.6 7.4-8v-36c.1-17.7-13.2-32-29.7-32zM664 508H360c-4.4 0-8 3.6-8 8v60c0 4.4 3.6 8 8 8h304c4.4 0 8-3.6 8-8v-60c0-4.4-3.6-8-8-8z" />
</svg>`; </svg>`;

2
dist/src/builtin/loop.js.map

File diff suppressed because one or more lines are too long

1
dist/src/controllers/payment.js

@ -190,6 +190,7 @@ exports.listPayments = (req, res) => __awaiter(void 0, void 0, void 0, function*
const msgs = yield models_1.models.Message.findAll({ const msgs = yield models_1.models.Message.findAll({
where: { where: {
type: { [sequelize_1.Op.or]: [ type: { [sequelize_1.Op.or]: [
constants_1.default.message_types.message,
constants_1.default.message_types.payment, constants_1.default.message_types.payment,
constants_1.default.message_types.direct_payment, constants_1.default.message_types.direct_payment,
constants_1.default.message_types.keysend, constants_1.default.message_types.keysend,

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

File diff suppressed because one or more lines are too long

5
dist/src/utils/setup.js

@ -17,6 +17,7 @@ const publicIp = require("public-ip");
const password_1 = require("../utils/password"); const password_1 = require("../utils/password");
const path = require("path"); const path = require("path");
const gitinfo_1 = require("../utils/gitinfo"); const gitinfo_1 = require("../utils/gitinfo");
const fs = require("fs");
const env = process.env.NODE_ENV || 'development'; const env = process.env.NODE_ENV || 'development';
const config = require(path.join(__dirname, '../../config/app.json'))[env]; const config = require(path.join(__dirname, '../../config/app.json'))[env];
const USER_VERSION = 7; const USER_VERSION = 7;
@ -225,9 +226,13 @@ function printQR() {
const b64 = Buffer.from(`ip::${theIP}::${password_1.default || ''}`).toString('base64'); const b64 = Buffer.from(`ip::${theIP}::${password_1.default || ''}`).toString('base64');
console.log('Scan this QR in Sphinx app:'); console.log('Scan this QR in Sphinx app:');
console.log(b64); console.log(b64);
connectionStringFile(b64);
QRCode.toString(b64, { type: 'terminal' }, function (err, url) { QRCode.toString(b64, { type: 'terminal' }, function (err, url) {
console.log(url); console.log(url);
}); });
}); });
} }
function connectionStringFile(str) {
fs.appendFile('../connection_string.txt', str, function (err) { });
}
//# sourceMappingURL=setup.js.map //# sourceMappingURL=setup.js.map

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

File diff suppressed because one or more lines are too long

67
src/builtin/loop.ts

@ -2,11 +2,11 @@ import * as Sphinx from 'sphinx-bot'
import { finalAction } from '../controllers/api' import { finalAction } from '../controllers/api'
import fetch from 'node-fetch' import fetch from 'node-fetch'
import * as path from 'path' import * as path from 'path'
import { models } from '../models'
import constants from '../constants'
var validate = require('bitcoin-address-validation'); var validate = require('bitcoin-address-validation');
const msg_types = Sphinx.MSG_TYPE const msg_types = Sphinx.MSG_TYPE
// /home/ec2-user/.lnd/data/chain/bitcoin/mainnet/admin.macaroon
let initted = false let initted = false
const baseurl = 'https://localhost:8080' const baseurl = 'https://localhost:8080'
@ -52,19 +52,28 @@ export function init() {
try { try {
const j = await doRequest(baseurl + '/v1/loop/out/quote/' + amt) const j = await doRequest(baseurl + '/v1/loop/out/quote/' + amt)
console.log("=> LOOP QUOTE RES", j) console.log("=> LOOP QUOTE RES", j)
if (!(j && j.swap_fee && j.prepay_amt)) { if (!(j && j.swap_fee_sat && j.prepay_amt_sat)) {
return return
} }
let chan
const bot = await getBot(message.channel.id)
if (bot && bot.meta) chan = bot.meta
if (!chan) {
const embed = new Sphinx.MessageEmbed()
.setAuthor('LoopBot')
.setDescription('No channel set')
message.channel.send({ embed })
}
const j2 = await doRequest(baseurl + '/v1/loop/out', { const j2 = await doRequest(baseurl + '/v1/loop/out', {
method: 'POST', method: 'POST',
body: JSON.stringify({ body: JSON.stringify({
amt: amt, amt: amt,
dest: addy, dest: addy,
outgoing_chan_set: [ outgoing_chan_set: [chan],
'704899103684034561' max_swap_fee: j.swap_fee_sat,
], max_prepay_amt: j.prepay_amt_sat
max_swap_fee: j.swap_fee,
max_prepay_amt: j.prepay_amt
}), }),
}) })
console.log("=> LOOP RESPONSE", j2) console.log("=> LOOP RESPONSE", j2)
@ -75,13 +84,13 @@ export function init() {
message.channel.send({ embed }) message.channel.send({ embed })
return return
} }
if (!(j2 && j2.server_message)) { // if (!(j2 && j2.server_message)) {
return // return
} // }
const embed = new Sphinx.MessageEmbed() const embed = new Sphinx.MessageEmbed()
.setAuthor('LoopBot') .setAuthor('LoopBot')
.setTitle('Loop Initialized!') .setTitle('Payment was sent!')
.setDescription('Success!') // .setDescription('Success!')
message.channel.send({ embed }) message.channel.send({ embed })
return return
} catch (e) { } catch (e) {
@ -90,6 +99,22 @@ export function init() {
} }
const cmd = arr[1] const cmd = arr[1]
const isAdmin = message.member.roles.find(role => role.name === 'Admin')
if(isAdmin && cmd.startsWith('setchan=')) {
const bot = await getBot(message.channel.id)
const arr = cmd.split('=')
if(bot && arr.length>1) {
const chan = arr[1]
await bot.update({meta: chan})
const embed = new Sphinx.MessageEmbed()
.setAuthor('LoopBot')
.setDescription('Channel updated to '+chan)
.setThumbnail(botSVG)
message.channel.send({ embed })
}
}
switch (cmd) { switch (cmd) {
case 'help': case 'help':
const embed = new Sphinx.MessageEmbed() const embed = new Sphinx.MessageEmbed()
@ -97,7 +122,8 @@ export function init() {
.setTitle('LoopBot Commands:') .setTitle('LoopBot Commands:')
.addFields([ .addFields([
{ name: 'Send to your on-chain address', value: '/loopout {ADDRESS} {AMOUNT}' }, { name: 'Send to your on-chain address', value: '/loopout {ADDRESS} {AMOUNT}' },
{ name: 'Help', value: '/loopout help' } { name: 'Set Channel', value: '/loopout setchan=***' },
{ name: 'Help', value: '/loopout help' },
]) ])
.setThumbnail(botSVG) .setThumbnail(botSVG)
message.channel.send({ embed }) message.channel.send({ embed })
@ -112,6 +138,19 @@ export function init() {
}) })
} }
async function getBot(tribeUUID:string){
const chat = await models.Chat.findOne({ where:{
uuid: tribeUUID
}})
if (!chat) return
const chatBot = await models.ChatBot.findOne({where: {
chatId: chat.id,
botPrefix: '/loopout',
botType: constants.bot_types.builtin
}})
return chatBot
}
const botSVG = `<svg viewBox="64 64 896 896" height="12" width="12" fill="white"> const botSVG = `<svg viewBox="64 64 896 896" height="12" width="12" fill="white">
<path d="M300 328a60 60 0 10120 0 60 60 0 10-120 0zM852 64H172c-17.7 0-32 14.3-32 32v660c0 17.7 14.3 32 32 32h680c17.7 0 32-14.3 32-32V96c0-17.7-14.3-32-32-32zm-32 660H204V128h616v596zM604 328a60 60 0 10120 0 60 60 0 10-120 0zm250.2 556H169.8c-16.5 0-29.8 14.3-29.8 32v36c0 4.4 3.3 8 7.4 8h729.1c4.1 0 7.4-3.6 7.4-8v-36c.1-17.7-13.2-32-29.7-32zM664 508H360c-4.4 0-8 3.6-8 8v60c0 4.4 3.6 8 8 8h304c4.4 0 8-3.6 8-8v-60c0-4.4-3.6-8-8-8z" /> <path d="M300 328a60 60 0 10120 0 60 60 0 10-120 0zM852 64H172c-17.7 0-32 14.3-32 32v660c0 17.7 14.3 32 32 32h680c17.7 0 32-14.3 32-32V96c0-17.7-14.3-32-32-32zm-32 660H204V128h616v596zM604 328a60 60 0 10120 0 60 60 0 10-120 0zm250.2 556H169.8c-16.5 0-29.8 14.3-29.8 32v36c0 4.4 3.3 8 7.4 8h729.1c4.1 0 7.4-3.6 7.4-8v-36c.1-17.7-13.2-32-29.7-32zM664 508H360c-4.4 0-8 3.6-8 8v60c0 4.4 3.6 8 8 8h304c4.4 0 8-3.6 8-8v-60c0-4.4-3.6-8-8-8z" />
</svg>` </svg>`

1
src/controllers/payment.ts

@ -203,6 +203,7 @@ export const listPayments = async (req, res) => {
const msgs = await models.Message.findAll({ const msgs = await models.Message.findAll({
where:{ where:{
type: {[Op.or]: [ type: {[Op.or]: [
constants.message_types.message, // for example /loopout message
constants.message_types.payment, constants.message_types.payment,
constants.message_types.direct_payment, constants.message_types.direct_payment,
constants.message_types.keysend, constants.message_types.keysend,

6
src/utils/setup.ts

@ -6,6 +6,7 @@ import * as publicIp from 'public-ip'
import password from '../utils/password' import password from '../utils/password'
import * as path from 'path' import * as path from 'path'
import { checkTag, checkCommitHash } from '../utils/gitinfo' import { checkTag, checkCommitHash } from '../utils/gitinfo'
import * as fs from 'fs';
const env = process.env.NODE_ENV || 'development'; const env = process.env.NODE_ENV || 'development';
const config = require(path.join(__dirname, '../../config/app.json'))[env] const config = require(path.join(__dirname, '../../config/app.json'))[env]
@ -222,7 +223,12 @@ async function printQR() {
const b64 = Buffer.from(`ip::${theIP}::${password || ''}`).toString('base64') const b64 = Buffer.from(`ip::${theIP}::${password || ''}`).toString('base64')
console.log('Scan this QR in Sphinx app:') console.log('Scan this QR in Sphinx app:')
console.log(b64) console.log(b64)
connectionStringFile(b64)
QRCode.toString(b64, { type: 'terminal' }, function (err, url) { QRCode.toString(b64, { type: 'terminal' }, function (err, url) {
console.log(url) console.log(url)
}) })
} }
function connectionStringFile(str:string){
fs.appendFile('../connection_string.txt', str, function (err) {});
}
Loading…
Cancel
Save