Merge pull request #461 from shocknet/use-logger
Use logger instead of console.*
This commit is contained in:
commit
8ab46fc699
11 changed files with 54 additions and 52 deletions
|
|
@ -454,7 +454,7 @@ const authenticate = async (alias, pass, __user) => {
|
|||
|
||||
return ack.sea.pub
|
||||
} else {
|
||||
console.log(ack)
|
||||
logger.info(ack)
|
||||
logger.error(
|
||||
`Unknown error, wrong password? Ack looks like: ${JSON.stringify(ack)}`
|
||||
)
|
||||
|
|
|
|||
|
|
@ -311,9 +311,9 @@ const sendSpontaneousPayment = async (
|
|||
throw new Error('torrentSeed service not available')
|
||||
}
|
||||
const { seedUrl } = seedInfo
|
||||
console.log('SEED URL OK')
|
||||
logger.info('SEED URL OK')
|
||||
const tokens = await enrollContentTokens(numberOfTokens, seedInfo)
|
||||
console.log('RES SEED OK')
|
||||
logger.info('RES SEED OK')
|
||||
const ackData = JSON.stringify({ seedUrl, tokens })
|
||||
return {
|
||||
payment: null,
|
||||
|
|
@ -386,8 +386,8 @@ const sendSpontaneousPayment = async (
|
|||
)}`
|
||||
throw new Error(msg)
|
||||
}
|
||||
console.log('ORDER ID')
|
||||
console.log(orderID)
|
||||
logger.info('ORDER ID')
|
||||
logger.info(orderID)
|
||||
/** @type {import('shock-common').Schema.OrderResponse} */
|
||||
const encryptedOrderRes = await Utils.tryAndWait(
|
||||
gun =>
|
||||
|
|
@ -397,7 +397,7 @@ const sendSpontaneousPayment = async (
|
|||
.get(Key.ORDER_TO_RESPONSE)
|
||||
.get(orderID)
|
||||
.on(orderResponse => {
|
||||
console.log(orderResponse)
|
||||
logger.info(orderResponse)
|
||||
if (Schema.isOrderResponse(orderResponse)) {
|
||||
res(orderResponse)
|
||||
}
|
||||
|
|
@ -476,8 +476,8 @@ const sendSpontaneousPayment = async (
|
|||
})
|
||||
return { payment }
|
||||
}
|
||||
console.log('ACK NODE')
|
||||
console.log(orderResponse.ackNode)
|
||||
logger.info('ACK NODE')
|
||||
logger.info(orderResponse.ackNode)
|
||||
/** @type {import('shock-common').Schema.OrderResponse} */
|
||||
const encryptedOrderAckRes = await Utils.tryAndWait(
|
||||
gun =>
|
||||
|
|
@ -487,8 +487,8 @@ const sendSpontaneousPayment = async (
|
|||
.get(Key.ORDER_TO_RESPONSE)
|
||||
.get(orderResponse.ackNode)
|
||||
.on(orderResponse => {
|
||||
console.log(orderResponse)
|
||||
console.log(Schema.isOrderResponse(orderResponse))
|
||||
logger.info(orderResponse)
|
||||
logger.info(Schema.isOrderResponse(orderResponse))
|
||||
|
||||
//@ts-expect-error
|
||||
if (orderResponse && orderResponse.type === 'orderAck') {
|
||||
|
|
@ -546,7 +546,7 @@ const sendSpontaneousPayment = async (
|
|||
})
|
||||
return { payment, orderAck }
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
logger.info(e)
|
||||
logger.error('Error inside sendPayment()')
|
||||
logger.error(e)
|
||||
throw e
|
||||
|
|
|
|||
|
|
@ -156,10 +156,10 @@ 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') {
|
||||
console.log('General Service')
|
||||
logger.info('General Service')
|
||||
const { ackInfo: serviceID } = order
|
||||
console.log('ACK INFO')
|
||||
console.log(serviceID)
|
||||
logger.info('ACK INFO')
|
||||
logger.info(serviceID)
|
||||
if (!Common.isPopulatedString(serviceID)) {
|
||||
throw new TypeError(`no serviceID provided to orderAck`)
|
||||
}
|
||||
|
|
@ -169,7 +169,7 @@ const listenerForAddr = (addr, SEA) => async (order, orderID) => {
|
|||
.get(serviceID)
|
||||
.load(res)
|
||||
})
|
||||
console.log(selectedService)
|
||||
logger.info(selectedService)
|
||||
if (!selectedService) {
|
||||
throw new TypeError(`invalid serviceID provided to orderAck`)
|
||||
}
|
||||
|
|
@ -247,7 +247,7 @@ const listenerForAddr = (addr, SEA) => async (order, orderID) => {
|
|||
* @param {Common.Schema.InvoiceWhenListed & {r_hash:Buffer,payment_addr:Buffer}} paidInvoice
|
||||
*/
|
||||
const invoicePaidCb = async paidInvoice => {
|
||||
console.log('INVOICE PAID')
|
||||
logger.info('INVOICE PAID')
|
||||
let breakError = null
|
||||
let orderMetadata //eslint-disable-line init-declarations
|
||||
const hashString = paidInvoice.r_hash.toString('hex')
|
||||
|
|
@ -309,24 +309,24 @@ const listenerForAddr = (addr, SEA) => async (order, orderID) => {
|
|||
break
|
||||
}
|
||||
case 'contentReveal': {
|
||||
console.log('cONTENT REVEAL')
|
||||
logger.info('cONTENT REVEAL')
|
||||
//assuming digital product that only requires to be unlocked
|
||||
const postID = ackInfo
|
||||
console.log('ACK INFO')
|
||||
console.log(ackInfo)
|
||||
logger.info('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
|
||||
}
|
||||
console.log('IS STRING')
|
||||
logger.info('IS STRING')
|
||||
const selectedPost = await new Promise(res => {
|
||||
getUser()
|
||||
.get(Key.POSTS_NEW)
|
||||
.get(postID)
|
||||
.load(res)
|
||||
})
|
||||
console.log('LOAD ok')
|
||||
console.log(selectedPost)
|
||||
logger.info('LOAD ok')
|
||||
logger.info(selectedPost)
|
||||
if (
|
||||
!selectedPost ||
|
||||
!selectedPost.status ||
|
||||
|
|
@ -335,12 +335,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
|
||||
}
|
||||
console.log('IS POST')
|
||||
logger.info('IS POST')
|
||||
/**
|
||||
* @type {Record<string,string>} <contentID,decryptedRef>
|
||||
*/
|
||||
const contentsToSend = {}
|
||||
console.log('SECRET OK')
|
||||
logger.info('SECRET OK')
|
||||
let privateFound = false
|
||||
await Common.Utils.asyncForEach(
|
||||
Object.entries(selectedPost.contentItems),
|
||||
|
|
@ -371,7 +371,7 @@ const listenerForAddr = (addr, SEA) => async (order, orderID) => {
|
|||
type: 'orderAck',
|
||||
response: encrypted
|
||||
}
|
||||
console.log('RES READY')
|
||||
logger.info('RES READY')
|
||||
|
||||
await new Promise((res, rej) => {
|
||||
getUser()
|
||||
|
|
@ -389,12 +389,12 @@ const listenerForAddr = (addr, SEA) => async (order, orderID) => {
|
|||
}
|
||||
})
|
||||
})
|
||||
console.log('RES SENT CONTENT')
|
||||
logger.info('RES SENT CONTENT')
|
||||
orderMetadata = JSON.stringify(ackData)
|
||||
break
|
||||
}
|
||||
case 'torrentSeed': {
|
||||
console.log('TORRENT')
|
||||
logger.info('TORRENT')
|
||||
const numberOfTokens = Number(ackInfo) || 1
|
||||
const seedInfo = selfContentToken()
|
||||
if (!seedInfo && !serviceOrderContentSeedInfo) {
|
||||
|
|
@ -411,7 +411,7 @@ const listenerForAddr = (addr, SEA) => async (order, orderID) => {
|
|||
numberOfTokens,
|
||||
seedInfoReady
|
||||
)
|
||||
console.log('RES SEED OK')
|
||||
logger.info('RES SEED OK')
|
||||
const ackData = { seedUrl, tokens, ackInfo }
|
||||
const toSend = JSON.stringify(ackData)
|
||||
const encrypted = await SEA.encrypt(toSend, secret)
|
||||
|
|
@ -419,7 +419,7 @@ const listenerForAddr = (addr, SEA) => async (order, orderID) => {
|
|||
type: 'orderAck',
|
||||
response: encrypted
|
||||
}
|
||||
console.log('RES SEED SENT')
|
||||
logger.info('RES SEED SENT')
|
||||
await new Promise((res, rej) => {
|
||||
getUser()
|
||||
.get(Key.ORDER_TO_RESPONSE)
|
||||
|
|
@ -436,7 +436,7 @@ const listenerForAddr = (addr, SEA) => async (order, orderID) => {
|
|||
}
|
||||
})
|
||||
})
|
||||
console.log('RES SENT SEED')
|
||||
logger.info('RES SENT SEED')
|
||||
orderMetadata = JSON.stringify(ackData)
|
||||
break
|
||||
}
|
||||
|
|
@ -466,7 +466,7 @@ const listenerForAddr = (addr, SEA) => async (order, orderID) => {
|
|||
throw new Error(breakError)
|
||||
}
|
||||
}
|
||||
console.log('WAITING INVOICE TO BE PAID')
|
||||
logger.info('WAITING INVOICE TO BE PAID')
|
||||
new Promise(res => SchemaManager.addListenInvoice(invoice.r_hash, res))
|
||||
.then(invoicePaidCb)
|
||||
.catch(err => {
|
||||
|
|
@ -476,7 +476,7 @@ const listenerForAddr = (addr, SEA) => async (order, orderID) => {
|
|||
)}`
|
||||
)
|
||||
logger.error(err)
|
||||
console.log(err)
|
||||
logger.info(err)
|
||||
|
||||
/** @type {import('shock-common').Schema.OrderResponse} */
|
||||
const orderResponse = {
|
||||
|
|
@ -503,7 +503,7 @@ const listenerForAddr = (addr, SEA) => async (order, orderID) => {
|
|||
)}`
|
||||
)
|
||||
logger.error(err)
|
||||
console.log(err)
|
||||
logger.info(err)
|
||||
|
||||
/** @type {import('shock-common').Schema.OrderResponse} */
|
||||
const orderResponse = {
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ const {
|
|||
getMySecret,
|
||||
$$__SHOCKWALLET__ENCRYPTED__
|
||||
} = require('../Mediator')
|
||||
const logger = require('../../../config/log')
|
||||
/**
|
||||
* @typedef {import('../contact-api/SimpleGUN').ValidDataValue} ValidDataValue
|
||||
* @typedef {import('./types').ValidRPCDataValue} ValidRPCDataValue
|
||||
|
|
@ -210,8 +211,8 @@ const put = async (rawPath, value) => {
|
|||
if (typeof ack.err === 'string') {
|
||||
rej(new Error(ack.err))
|
||||
} else {
|
||||
console.log(`NON STANDARD GUN ERROR:`)
|
||||
console.log(ack)
|
||||
logger.info(`NON STANDARD GUN ERROR:`)
|
||||
logger.info(ack)
|
||||
rej(new Error(JSON.stringify(ack.err, null, 4)))
|
||||
}
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -180,7 +180,7 @@ const startSocket = socket => {
|
|||
if (isAuthenticated()) {
|
||||
socket.onAny(() => {
|
||||
GunActions.setLastSeenApp().catch(e =>
|
||||
console.log('error setting last seen app', e)
|
||||
logger.info('error setting last seen app', e)
|
||||
)
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -371,7 +371,7 @@ class SchemaManager {
|
|||
.get(coordinateSHA256)
|
||||
.put(encryptedOrderString, ack => {
|
||||
if (ack.err && typeof ack.err !== 'number') {
|
||||
console.log(ack)
|
||||
logger.info(ack)
|
||||
rej(
|
||||
new Error(
|
||||
`Error saving coordinate order to user-graph: ${ack}`
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
//@ts-nocheck TODO- fix types
|
||||
const { gunUUID } = require("../utils")
|
||||
const logger = require('../config/log')
|
||||
class TipsCB {
|
||||
listeners = {}
|
||||
|
||||
|
|
@ -16,7 +17,7 @@ class TipsCB {
|
|||
return "invalid access id"
|
||||
}
|
||||
const postID = this.postsEnabled[accessId]
|
||||
console.log("subbing new socket for post: "+postID)
|
||||
logger.info("subbing new socket for post: "+postID)
|
||||
|
||||
if(!this.listeners[postID]){
|
||||
this.listeners[postID] = []
|
||||
|
|
|
|||
|
|
@ -2376,11 +2376,11 @@ module.exports = async (
|
|||
? gun.user(publicKey)
|
||||
: gun
|
||||
keys.forEach(key => (node = node.get(key)))
|
||||
console.log(`fetching: ${keys}`)
|
||||
logger.info(`fetching: ${keys}`)
|
||||
return new Promise((res, rej) => {
|
||||
const listener = data => {
|
||||
console.log(`got res for: ${keys}`)
|
||||
console.log(data)
|
||||
logger.info(`got res for: ${keys}`)
|
||||
logger.info(data)
|
||||
if (publicKeyForDecryption) {
|
||||
GunWriteRPC.deepDecryptIfNeeded(
|
||||
data,
|
||||
|
|
|
|||
|
|
@ -413,7 +413,7 @@ const server = program => {
|
|||
address: tunnelHost,
|
||||
port: serverPort
|
||||
}
|
||||
console.log(opts)
|
||||
logger.info(opts)
|
||||
relayClient.default(opts, async (connected, params) => {
|
||||
if (connected) {
|
||||
const noProtocolAddress = params.address.replace(
|
||||
|
|
@ -431,7 +431,7 @@ const server = program => {
|
|||
externalIP: `${params.relayId}@${noProtocolAddress}`
|
||||
})
|
||||
qrcode.generate(dataToQr, { small: true })
|
||||
console.log(`connect to ${params.relayId}@${noProtocolAddress}`)
|
||||
logger.info(`connect to ${params.relayId}@${noProtocolAddress}`)
|
||||
} else {
|
||||
logger.error('!! Relay did not connect to server !!')
|
||||
}
|
||||
|
|
|
|||
|
|
@ -195,11 +195,11 @@ module.exports = (
|
|||
)
|
||||
|
||||
io.of('streams').on('connect', socket => {
|
||||
console.log('a user connected')
|
||||
logger.info('a user connected')
|
||||
socket.on('accessId', accessId => {
|
||||
const err = TipsForwarder.addSocket(accessId, socket)
|
||||
if (err) {
|
||||
console.log('err invalid socket for tips notifications ' + err)
|
||||
logger.info('err invalid socket for tips notifications ' + err)
|
||||
socket.disconnect(true)
|
||||
}
|
||||
})
|
||||
|
|
|
|||
|
|
@ -6,13 +6,13 @@ const { listPeers, connectPeer,getInfo } = require('./v2')
|
|||
const handlerBaseUrl = "https://channels.shock.network:4444"
|
||||
|
||||
module.exports = async () => {
|
||||
console.log("DOING CHANNEL INVITE THING: START")
|
||||
logger.info("DOING CHANNEL INVITE THING: START")
|
||||
/**
|
||||
* @type string | undefined
|
||||
*/
|
||||
const invite = process.env.HOSTING_INVITE
|
||||
if(!invite) {
|
||||
console.log("DOING CHANNEL INVITE THING: NVM NO INVITE")
|
||||
logger.info("DOING CHANNEL INVITE THING: NVM NO INVITE")
|
||||
return
|
||||
}
|
||||
try {
|
||||
|
|
@ -21,7 +21,7 @@ module.exports = async () => {
|
|||
*/
|
||||
const invites = await Storage.getItem('processedInvites') || []
|
||||
if(invites.includes(invite)){
|
||||
console.log("DOING CHANNEL INVITE THING: INVITE PROCESSED ALREADY")
|
||||
logger.info("DOING CHANNEL INVITE THING: INVITE PROCESSED ALREADY")
|
||||
return
|
||||
}
|
||||
const me = await getInfo()
|
||||
|
|
@ -29,7 +29,7 @@ module.exports = async () => {
|
|||
//@ts-expect-error
|
||||
const connectReq = await fetch(`${handlerBaseUrl}/connect`)
|
||||
if(connectReq.status !== 200 ){
|
||||
console.log("DOING CHANNEL INVITE THING: CONNECT FAILED")
|
||||
logger.info("DOING CHANNEL INVITE THING: CONNECT FAILED")
|
||||
return
|
||||
}
|
||||
const connJson = await connectReq.json()
|
||||
|
|
@ -53,15 +53,15 @@ module.exports = async () => {
|
|||
body:JSON.stringify(channelReq)
|
||||
})
|
||||
if(res.status !== 200 ){
|
||||
console.log("DOING CHANNEL INVITE THING: FAILED ")
|
||||
logger.info("DOING CHANNEL INVITE THING: FAILED ")
|
||||
return
|
||||
}
|
||||
invites.push(invite)
|
||||
await Storage.setItem('processedInvites',invites)
|
||||
console.log("DOING CHANNEL INVITE THING: DONE!")
|
||||
logger.info("DOING CHANNEL INVITE THING: DONE!")
|
||||
} catch(e){
|
||||
logger.error("error sending invite to channels handler")
|
||||
console.log("DOING CHANNEL INVITE THING: :(")
|
||||
logger.info("DOING CHANNEL INVITE THING: :(")
|
||||
logger.error(e)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue