Better logs
This commit is contained in:
parent
8eb7902e58
commit
4df681fae9
1 changed files with 42 additions and 34 deletions
|
|
@ -88,13 +88,17 @@ const listenerForAddr = (addr, SEA) => async (order, orderID) => {
|
|||
try {
|
||||
if (addr !== currentOrderAddr) {
|
||||
logger.info(
|
||||
orderID,
|
||||
`order address: ${addr} invalidated (current address: ${currentOrderAddr})`
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
if (!Schema.isOrder(order)) {
|
||||
logger.info(`Expected an order instead got: ${JSON.stringify(order)}`)
|
||||
logger.info(
|
||||
orderID,
|
||||
`Expected an order instead got: ${JSON.stringify(order)}`
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -129,19 +133,19 @@ const listenerForAddr = (addr, SEA) => async (order, orderID) => {
|
|||
|
||||
if (!isNumber(amount)) {
|
||||
throw new TypeError(
|
||||
`Could not parse decrypted amount as a number, not a number?, decryptedAmount: ${decryptedAmount}`
|
||||
`${orderID} Could not parse decrypted amount as a number, not a number?, decryptedAmount: ${decryptedAmount}`
|
||||
)
|
||||
}
|
||||
|
||||
if (isNaN(amount)) {
|
||||
throw new TypeError(
|
||||
`Could not parse decrypted amount as a number, got NaN, decryptedAmount: ${decryptedAmount}`
|
||||
`${orderID} Could not parse decrypted amount as a number, got NaN, decryptedAmount: ${decryptedAmount}`
|
||||
)
|
||||
}
|
||||
|
||||
if (!isFinite(amount)) {
|
||||
throw new TypeError(
|
||||
`Amount was correctly decrypted, but got a non finite number, decryptedAmount: ${decryptedAmount}`
|
||||
`${orderID} Amount was correctly decrypted, but got a non finite number, decryptedAmount: ${decryptedAmount}`
|
||||
)
|
||||
}
|
||||
const mySecret = require('../../Mediator').getMySecret()
|
||||
|
|
@ -154,22 +158,22 @@ const listenerForAddr = (addr, SEA) => async (order, orderID) => {
|
|||
*/
|
||||
let serviceOrderContentSeedInfo = null //in case the service is of type 'torrentSeed' this is {seedUrl,seedToken}, can be omitted, in that case, it will be taken from env
|
||||
if (order.targetType === 'service') {
|
||||
logger.info('General Service')
|
||||
logger.info(orderID, 'General Service')
|
||||
const { ackInfo: serviceID } = order
|
||||
logger.info('ACK INFO')
|
||||
logger.info(serviceID)
|
||||
logger.info(orderID, 'ACK INFO')
|
||||
logger.info(orderID, serviceID)
|
||||
if (!Common.isPopulatedString(serviceID)) {
|
||||
throw new TypeError(`no serviceID provided to orderAck`)
|
||||
throw new TypeError(`${orderID} no serviceID provided to orderAck`)
|
||||
}
|
||||
const selectedService = await getUser()
|
||||
.get(Key.OFFERED_SERVICES)
|
||||
.get(serviceID)
|
||||
.then()
|
||||
|
||||
logger.info(selectedService)
|
||||
logger.info(orderID, selectedService)
|
||||
if (!Common.isObj(selectedService)) {
|
||||
throw new TypeError(
|
||||
`invalid serviceID provided to orderAck or service is not an object`
|
||||
`${orderID} invalid serviceID provided to orderAck or service is not an object`
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -181,7 +185,7 @@ const listenerForAddr = (addr, SEA) => async (order, orderID) => {
|
|||
} = /** @type {Record<string, any>} */ (selectedService)
|
||||
if (Number(amount) !== Number(servicePrice)) {
|
||||
throw new TypeError(
|
||||
`service price mismatch ${amount} : ${servicePrice}`
|
||||
`${orderID} service price mismatch ${amount} : ${servicePrice}`
|
||||
)
|
||||
}
|
||||
if (serviceType === 'torrentSeed') {
|
||||
|
|
@ -205,13 +209,13 @@ const listenerForAddr = (addr, SEA) => async (order, orderID) => {
|
|||
const invoice = await _addInvoice(invoiceReq)
|
||||
|
||||
logger.info(
|
||||
'onOrders() -> Successfully created the invoice, will now encrypt it'
|
||||
`${orderID} onOrders() -> Successfully created the invoice, will now encrypt it`
|
||||
)
|
||||
|
||||
const encInvoice = await SEA.encrypt(invoice.payment_request, secret)
|
||||
|
||||
logger.info(
|
||||
`onOrders() -> Will now place the encrypted invoice in order to response usergraph: ${addr}`
|
||||
`${orderID} onOrders() -> Will now place the encrypted invoice in order to response usergraph: ${addr}`
|
||||
)
|
||||
|
||||
const ackNode = Utils.gunID()
|
||||
|
|
@ -236,7 +240,7 @@ const listenerForAddr = (addr, SEA) => async (order, orderID) => {
|
|||
) {
|
||||
rej(
|
||||
new Error(
|
||||
`Error saving encrypted invoice to order to response usergraph: ${ack}`
|
||||
`${orderID} Error saving encrypted invoice to order to response usergraph: ${ack}`
|
||||
)
|
||||
)
|
||||
} else {
|
||||
|
|
@ -251,7 +255,7 @@ const listenerForAddr = (addr, SEA) => async (order, orderID) => {
|
|||
* @param {Common.Schema.InvoiceWhenListed & {r_hash:Buffer,payment_addr:Buffer}} paidInvoice
|
||||
*/
|
||||
const invoicePaidCb = async paidInvoice => {
|
||||
logger.info('INVOICE PAID')
|
||||
logger.info(orderID, 'INVOICE PAID')
|
||||
let breakError = null
|
||||
let orderMetadata //eslint-disable-line init-declarations
|
||||
const hashString = paidInvoice.r_hash.toString('hex')
|
||||
|
|
@ -267,7 +271,7 @@ const listenerForAddr = (addr, SEA) => async (order, orderID) => {
|
|||
case 'tip': {
|
||||
const postID = ackInfo
|
||||
if (!Common.isPopulatedString(postID)) {
|
||||
breakError = 'invalid ackInfo provided for postID'
|
||||
breakError = orderID + ' invalid ackInfo provided for postID'
|
||||
break //create the coordinate, but stop because of the invalid id
|
||||
}
|
||||
getUser()
|
||||
|
|
@ -301,7 +305,7 @@ const listenerForAddr = (addr, SEA) => async (order, orderID) => {
|
|||
) {
|
||||
rej(
|
||||
new Error(
|
||||
`Error saving encrypted orderAck to order to response usergraph: ${ack}`
|
||||
`${orderID} Error saving encrypted orderAck to order to response usergraph: ${ack}`
|
||||
)
|
||||
)
|
||||
} else {
|
||||
|
|
@ -317,16 +321,16 @@ const listenerForAddr = (addr, SEA) => async (order, orderID) => {
|
|||
break
|
||||
}
|
||||
case 'contentReveal': {
|
||||
logger.info('cONTENT REVEAL')
|
||||
logger.info(orderID, 'CONTENT REVEAL')
|
||||
//assuming digital product that only requires to be unlocked
|
||||
const postID = ackInfo
|
||||
logger.info('ACK INFO')
|
||||
logger.info(orderID, 'ACK INFO')
|
||||
logger.info(ackInfo)
|
||||
if (!Common.isPopulatedString(postID)) {
|
||||
breakError = 'invalid ackInfo provided for postID'
|
||||
break //create the coordinate, but stop because of the invalid id
|
||||
}
|
||||
logger.info('IS STRING')
|
||||
logger.info(orderID, 'IS STRING')
|
||||
const selectedPost = /** @type {Record<string, any>} */ (await getUser()
|
||||
.get(Key.POSTS_NEW)
|
||||
.get(postID)
|
||||
|
|
@ -337,7 +341,7 @@ const listenerForAddr = (addr, SEA) => async (order, orderID) => {
|
|||
.get(Key.CONTENT_ITEMS)
|
||||
.then())
|
||||
|
||||
logger.info('LOAD ok')
|
||||
logger.info(orderID, 'LOAD ok')
|
||||
logger.info(selectedPost)
|
||||
if (
|
||||
!selectedPost ||
|
||||
|
|
@ -347,12 +351,12 @@ const listenerForAddr = (addr, SEA) => async (order, orderID) => {
|
|||
breakError = 'ackInfo provided does not correspond to a valid post'
|
||||
break //create the coordinate, but stop because of the invalid post
|
||||
}
|
||||
logger.info('IS POST')
|
||||
logger.info(orderID, 'IS POST')
|
||||
/**
|
||||
* @type {Record<string,string>} <contentID,decryptedRef>
|
||||
*/
|
||||
const contentsToSend = {}
|
||||
logger.info('SECRET OK')
|
||||
logger.info(orderID, 'SECRET OK')
|
||||
let privateFound = false
|
||||
await Common.Utils.asyncForEach(
|
||||
Object.entries(selectedPostContent),
|
||||
|
|
@ -383,7 +387,7 @@ const listenerForAddr = (addr, SEA) => async (order, orderID) => {
|
|||
type: 'orderAck',
|
||||
response: encrypted
|
||||
}
|
||||
logger.info('RES READY')
|
||||
logger.info(orderID, 'RES READY')
|
||||
|
||||
await new Promise((res, rej) => {
|
||||
getUser()
|
||||
|
|
@ -405,12 +409,12 @@ const listenerForAddr = (addr, SEA) => async (order, orderID) => {
|
|||
}
|
||||
})
|
||||
})
|
||||
logger.info('RES SENT CONTENT')
|
||||
logger.info(orderID, 'RES SENT CONTENT')
|
||||
orderMetadata = JSON.stringify(ackData)
|
||||
break
|
||||
}
|
||||
case 'torrentSeed': {
|
||||
logger.info('TORRENT')
|
||||
logger.info(orderID, 'TORRENT')
|
||||
const numberOfTokens = Number(ackInfo) || 1
|
||||
const seedInfo = selfContentToken()
|
||||
if (!seedInfo && !serviceOrderContentSeedInfo) {
|
||||
|
|
@ -427,7 +431,7 @@ const listenerForAddr = (addr, SEA) => async (order, orderID) => {
|
|||
numberOfTokens,
|
||||
seedInfoReady
|
||||
)
|
||||
logger.info('RES SEED OK')
|
||||
logger.info(orderID, 'RES SEED OK')
|
||||
const ackData = { seedUrl, tokens, ackInfo }
|
||||
const toSend = JSON.stringify(ackData)
|
||||
const encrypted = await SEA.encrypt(toSend, secret)
|
||||
|
|
@ -435,7 +439,7 @@ const listenerForAddr = (addr, SEA) => async (order, orderID) => {
|
|||
type: 'orderAck',
|
||||
response: encrypted
|
||||
}
|
||||
logger.info('RES SEED SENT')
|
||||
logger.info(orderID, 'RES SEED SENT')
|
||||
await new Promise((res, rej) => {
|
||||
getUser()
|
||||
.get(Key.ORDER_TO_RESPONSE)
|
||||
|
|
@ -456,7 +460,7 @@ const listenerForAddr = (addr, SEA) => async (order, orderID) => {
|
|||
}
|
||||
})
|
||||
})
|
||||
logger.info('RES SENT SEED')
|
||||
logger.info(orderID, 'RES SENT SEED')
|
||||
orderMetadata = JSON.stringify(ackData)
|
||||
break
|
||||
}
|
||||
|
|
@ -486,17 +490,18 @@ const listenerForAddr = (addr, SEA) => async (order, orderID) => {
|
|||
throw new Error(breakError)
|
||||
}
|
||||
}
|
||||
logger.info('Waiting for invoice to be paid for order ' + orderID)
|
||||
logger.info(orderID, 'Waiting for invoice to be paid for order ' + orderID)
|
||||
new Promise(res => SchemaManager.addListenInvoice(invoice.r_hash, res))
|
||||
.then(invoicePaidCb)
|
||||
.catch(err => {
|
||||
logger.error(
|
||||
orderID,
|
||||
`error inside onOrders, orderAddr: ${addr}, orderID: ${orderID}, order: ${JSON.stringify(
|
||||
order
|
||||
)}`
|
||||
)
|
||||
logger.error(err)
|
||||
logger.info(err)
|
||||
logger.error(orderID, err)
|
||||
logger.info(orderID, err)
|
||||
|
||||
/** @type {import('shock-common').Schema.OrderResponse} */
|
||||
const orderResponse = {
|
||||
|
|
@ -515,6 +520,7 @@ const listenerForAddr = (addr, SEA) => async (order, orderID) => {
|
|||
typeof ack.err !== 'object'
|
||||
) {
|
||||
logger.error(
|
||||
orderID,
|
||||
`Error saving encrypted invoice to order to response usergraph: ${ack}`
|
||||
)
|
||||
}
|
||||
|
|
@ -522,12 +528,13 @@ const listenerForAddr = (addr, SEA) => async (order, orderID) => {
|
|||
})
|
||||
} catch (/** @type {any} */ err) {
|
||||
logger.error(
|
||||
orderID,
|
||||
`error inside onOrders, orderAddr: ${addr}, orderID: ${orderID}, order: ${JSON.stringify(
|
||||
order
|
||||
)}`
|
||||
)
|
||||
logger.error(err)
|
||||
logger.info(err)
|
||||
logger.error(orderID, err)
|
||||
logger.info(orderID, err)
|
||||
|
||||
/** @type {import('shock-common').Schema.OrderResponse} */
|
||||
const orderResponse = {
|
||||
|
|
@ -546,6 +553,7 @@ const listenerForAddr = (addr, SEA) => async (order, orderID) => {
|
|||
typeof ack.err !== 'object'
|
||||
) {
|
||||
logger.error(
|
||||
orderID,
|
||||
`Error saving encrypted invoice to order to response usergraph: ${ack}`
|
||||
)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue