Merge pull request #526 from shocknet/tmp

Misc
This commit is contained in:
CapDog 2022-10-12 18:21:16 -04:00 committed by GitHub
commit 1bbba6a65e
5 changed files with 49 additions and 22 deletions

View file

@ -33,6 +33,8 @@ const $$__SHOCKWALLET__MSG__ = '$$__SHOCKWALLET__MSG__'
const $$__SHOCKWALLET__NUMBER__ = '$$__SHOCKWALLET__NUMBER__' const $$__SHOCKWALLET__NUMBER__ = '$$__SHOCKWALLET__NUMBER__'
const $$__SHOCKWALLET__BOOLEAN__ = '$$__SHOCKWALLET__BOOLEAN__' const $$__SHOCKWALLET__BOOLEAN__ = '$$__SHOCKWALLET__BOOLEAN__'
/// <reference path="../../../utils/GunSmith/Smith.ts" />
mySEA.encrypt = (msg, secret) => { mySEA.encrypt = (msg, secret) => {
if (typeof secret !== 'string') { if (typeof secret !== 'string') {
throw new TypeError( throw new TypeError(
@ -280,6 +282,9 @@ const isAuthenticated = () => typeof user.is === 'object' && user.is !== null
const isAuthenticating = () => _isAuthenticating const isAuthenticating = () => _isAuthenticating
const isRegistering = () => _isRegistering const isRegistering = () => _isRegistering
/**
* @returns {Smith.GunSmithNode}
*/
const getGun = () => { const getGun = () => {
throw new Error('NO GUNS') throw new Error('NO GUNS')
} }

View file

@ -306,8 +306,10 @@ const setCurrentStreamInfo = (encryptedCurrentStreamInfo, user) =>
/** /**
* @typedef {object} SpontaneousPaymentOptions * @typedef {object} SpontaneousPaymentOptions
* @prop {Common.Schema.OrderTargetType} type * @prop {Common.Schema.OrderTargetType=} type
* @prop {string=} ackInfo * @prop {string=} ackInfo
* @prop {number=} maxParts
* @prop {number=} timeoutSeconds
*/ */
/** /**
* @typedef {object} OrderRes * @typedef {object} OrderRes
@ -330,7 +332,7 @@ const sendSpontaneousPayment = async (
amount, amount,
memo, memo,
feeLimit, feeLimit,
opts = { type: 'spontaneousPayment' } { ackInfo, maxParts, timeoutSeconds, type = 'spontaneousPayment' }
) => { ) => {
try { try {
const SEA = require('../Mediator').mySEA const SEA = require('../Mediator').mySEA
@ -338,12 +340,12 @@ const sendSpontaneousPayment = async (
const myPub = getUser()._.sea.pub const myPub = getUser()._.sea.pub
if ( if (
to === myPub && to === myPub &&
opts.type === 'torrentSeed' && type === 'torrentSeed' &&
opts.ackInfo && ackInfo &&
!isNaN(parseInt(opts.ackInfo, 10)) !isNaN(parseInt(ackInfo, 10))
) { ) {
//user requested a seed to themselves //user requested a seed to themselves
const numberOfTokens = Number(opts.ackInfo) || 1 const numberOfTokens = Number(ackInfo) || 1
const seedInfo = selfContentToken() const seedInfo = selfContentToken()
if (!seedInfo) { if (!seedInfo) {
throw new Error('torrentSeed service not available') throw new Error('torrentSeed service not available')
@ -375,8 +377,8 @@ const sendSpontaneousPayment = async (
from: getUser()._.sea.pub, from: getUser()._.sea.pub,
memo: memo || 'no memo', memo: memo || 'no memo',
timestamp: Date.now(), timestamp: Date.now(),
targetType: opts.type, targetType: type,
ackInfo: opts.ackInfo ackInfo
} }
logger.info(JSON.stringify(order)) logger.info(JSON.stringify(order))
@ -496,18 +498,20 @@ const sendSpontaneousPayment = async (
const payment = await sendPaymentV2Invoice({ const payment = await sendPaymentV2Invoice({
feeLimit, feeLimit,
payment_request: orderResponse.response payment_request: orderResponse.response,
max_parts: maxParts,
timeoutSeconds
}) })
const myLndPub = LNDHealthManager.lndPub const myLndPub = LNDHealthManager.lndPub
if ( if (
(opts.type !== 'contentReveal' && (type !== 'contentReveal' &&
opts.type !== 'torrentSeed' && type !== 'torrentSeed' &&
opts.type !== 'service' && type !== 'service' &&
opts.type !== 'product') || type !== 'product') ||
!orderResponse.ackNode !orderResponse.ackNode
) { ) {
SchemaManager.AddOrder({ SchemaManager.AddOrder({
type: opts.type, type,
amount: parseInt(payment.value_sat, 10), amount: parseInt(payment.value_sat, 10),
coordinateHash: payment.payment_hash, coordinateHash: payment.payment_hash,
coordinateIndex: parseInt(payment.payment_index, 10), coordinateIndex: parseInt(payment.payment_index, 10),
@ -580,7 +584,7 @@ const sendSpontaneousPayment = async (
throw new Error(`expected orderAck response, got: ${orderAck.type}`) throw new Error(`expected orderAck response, got: ${orderAck.type}`)
} }
SchemaManager.AddOrder({ SchemaManager.AddOrder({
type: opts.type, type,
amount: parseInt(payment.value_sat, 10), amount: parseInt(payment.value_sat, 10),
coordinateHash: payment.payment_hash, coordinateHash: payment.payment_hash,
coordinateIndex: parseInt(payment.payment_index, 10), coordinateIndex: parseInt(payment.payment_index, 10),
@ -606,12 +610,24 @@ const sendSpontaneousPayment = async (
* @param {number} amount * @param {number} amount
* @param {string} memo * @param {string} memo
* @param {number} feeLimit * @param {number} feeLimit
* @param {number=} maxParts
* @param {number=} timeoutSeconds
* @throws {Error} If no response in less than 20 seconds from the recipient, or * @throws {Error} If no response in less than 20 seconds from the recipient, or
* lightning cannot find a route for the payment. * lightning cannot find a route for the payment.
* @returns {Promise<string>} The payment's preimage. * @returns {Promise<string>} The payment's preimage.
*/ */
const sendPayment = async (to, amount, memo, feeLimit) => { const sendPayment = async (
const res = await sendSpontaneousPayment(to, amount, memo, feeLimit) to,
amount,
memo,
feeLimit,
maxParts,
timeoutSeconds
) => {
const res = await sendSpontaneousPayment(to, amount, memo, feeLimit, {
maxParts,
timeoutSeconds
})
if (!res.payment) { if (!res.payment) {
throw new Error('invalid payment params') //only if it's a torrentSeed request to self throw new Error('invalid payment params') //only if it's a torrentSeed request to self
} }

View file

@ -1189,7 +1189,7 @@ module.exports = async (
lightning.listPayments( lightning.listPayments(
{ {
// TODO // TODO
include_incomplete: !!req.include_incomplete include_incomplete: !!req.body.include_incomplete
}, },
(err, { payments = [] } = {}) => { (err, { payments = [] } = {}) => {
if (err) { if (err) {
@ -2630,7 +2630,7 @@ module.exports = async (
} }
}) })
app.get('/api/accessInfo', async (req, res) => { app.get('/api/accessInfo', (req, res) => {
if (req.ip !== '127.0.0.1') { if (req.ip !== '127.0.0.1') {
res.json({ res.json({
field: 'origin', field: 'origin',

View file

@ -280,7 +280,7 @@ const server = program => {
saveUninitialized: true saveUninitialized: true
}) })
) )
app.use(bodyParser.urlencoded({ extended: 'true' })) app.use(bodyParser.urlencoded({ extended: true }))
app.use(bodyParser.json({ limit: '500kb' })) app.use(bodyParser.json({ limit: '500kb' }))
app.use(bodyParser.json({ type: 'application/vnd.api+json' })) app.use(bodyParser.json({ type: 'application/vnd.api+json' }))
app.use(methodOverride()) app.use(methodOverride())
@ -323,7 +323,7 @@ const server = program => {
const serverInstance = await createServer() const serverInstance = await createServer()
const io = require('socket.io')(serverInstance, { require('socket.io')(serverInstance, {
parser: binaryParser, parser: binaryParser,
transports: ['websocket', 'polling'], transports: ['websocket', 'polling'],
cors: { cors: {

View file

@ -288,7 +288,13 @@ const forge = () => {
} }
await new Promise(res => { await new Promise(res => {
currentGun.on('message', msg => { currentGun.on('message', msg => {
if (msg.type === 'init') { if (typeof msg !== 'object') {
throw new Error(`msg.type !== object`)
}
const message = /** @type {{type: string}} */ (msg)
if (message.type === 'init') {
// @ts-ignore // @ts-ignore
res() res()
} }