diff --git a/package.json b/package.json index 3a0b072..30bb103 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jechain", - "version": "0.25.1", + "version": "0.25.2", "description": "Node for JeChain - an experimental smart contract blockchain network", "main": "./index.js", "scripts": { diff --git a/src/core/runtime.js b/src/core/runtime.js index 95bb09c..3ad030e 100644 --- a/src/core/runtime.js +++ b/src/core/runtime.js @@ -291,7 +291,7 @@ async function jelscript(input, originalState = {}, gas, stateDB, block, txInfo, break; case "log": // Log out data - if (enableLogging) console.log(`LOG [${(new Date()).toISOString()}]`, contractInfo.address + ":", c); + if (enableLogging) console.log(`\x1b[32mLOG\x1b[0m [${(new Date()).toISOString()}]`, contractInfo.address + ":", c); break; diff --git a/src/core/txPool.js b/src/core/txPool.js index 19f5ca1..3d2966c 100644 --- a/src/core/txPool.js +++ b/src/core/txPool.js @@ -19,7 +19,7 @@ async function addTransaction(transaction, chainInfo, stateDB) { await Transaction.isValid(transaction, stateDB)) || BigInt(transaction.additionalData.contractGas || 0) > BigInt(BLOCK_GAS_LIMIT) ) { - console.log(`LOG [${(new Date()).toISOString()}] Failed to add one transaction to pool.`); + console.log(`\x1b[31mERROR\x1b[0m [${(new Date()).toISOString()}] Failed to add one transaction to pool.`); return; } @@ -30,7 +30,7 @@ async function addTransaction(transaction, chainInfo, stateDB) { const txSenderAddress = SHA256(txSenderPubkey); if (!(await stateDB.keys().all()).includes(txSenderAddress)) { - console.log(`LOG [${(new Date()).toISOString()}] Failed to add one transaction to pool.`); + console.log(`\x1b[31mERROR\x1b[0m [${(new Date()).toISOString()}] Failed to add one transaction to pool.`); return; } @@ -47,13 +47,13 @@ async function addTransaction(transaction, chainInfo, stateDB) { } if (maxNonce + 1 !== transaction.nonce) { - console.log(`LOG [${(new Date()).toISOString()}] Failed to add one transaction to pool.`); + console.log(`\x1b[31mERROR\x1b[0m [${(new Date()).toISOString()}] Failed to add one transaction to pool.`); return; } txPool.push(transaction); - console.log(`LOG [${(new Date()).toISOString()}] Added one transaction to pool.`); + console.log(`\x1b[32mLOG\x1b[0m [${(new Date()).toISOString()}] Added one transaction to pool.`); } async function clearDepreciatedTxns(chainInfo, stateDB) { diff --git a/src/node/server.js b/src/node/server.js index 1cddef1..14a7699 100644 --- a/src/node/server.js +++ b/src/node/server.js @@ -58,13 +58,13 @@ async function startServer(options) { const keyPair = ec.keyFromPrivate(privateKey, "hex"); const publicKey = keyPair.getPublic("hex"); - process.on("uncaughtException", err => console.log(`LOG [${(new Date()).toISOString()}]`, err)); + process.on("uncaughtException", err => console.log(`\x1b[31mERROR\x1b[0m [${(new Date()).toISOString()}] Uncaught Exception`, err)); await codeDB.put(EMPTY_HASH, ""); const server = new WS.Server({ port: PORT }); - console.log(`LOG [${(new Date()).toISOString()}] Listening on PORT`, PORT.toString()); + console.log(`\x1b[32mLOG\x1b[0m [${(new Date()).toISOString()}] P2P server listening on PORT`, PORT.toString()); server.on("connection", async (socket, req) => { // Message handler @@ -103,7 +103,7 @@ async function startServer(options) { chainInfo.checkedBlock[newBlock.hash] = true; if (await verifyBlock(newBlock, chainInfo, stateDB, codeDB, ENABLE_LOGGING)) { - console.log(`LOG [${(new Date()).toISOString()}] New block received.`); + console.log(`\x1b[32mLOG\x1b[0m [${(new Date()).toISOString()}] New block received.`); // If mining is enabled, we will set mined to true, informing that another node has mined before us. if (ENABLE_MINING) { @@ -124,7 +124,7 @@ async function startServer(options) { // Update the new transaction pool (remove all the transactions that are no longer valid). chainInfo.transactionPool = await clearDepreciatedTxns(chainInfo, stateDB); - console.log(`LOG [${(new Date()).toISOString()}] Block #${newBlock.blockNumber} synced, state transited.`); + console.log(`\x1b[32mLOG\x1b[0m [${(new Date()).toISOString()}] Block #${newBlock.blockNumber} synced, state transited.`); sendMessage(message, opened); // Broadcast block to other nodes @@ -179,7 +179,7 @@ async function startServer(options) { if (maxNonce + 1 !== transaction.nonce) return; - console.log(`LOG [${(new Date()).toISOString()}] New transaction received, broadcasted and added to pool.`); + console.log(`\x1b[32mLOG\x1b[0m [${(new Date()).toISOString()}] New transaction received, broadcasted and added to pool.`); chainInfo.transactionPool.push(transaction); @@ -201,7 +201,7 @@ async function startServer(options) { socket.send(produceMessage(TYPE.SEND_BLOCK, block)); // Send block - console.log(`LOG [${(new Date()).toISOString()}] Sent block at position ${blockNumber} to ${requestAddress}.`); + console.log(`\x1b[32mLOG\x1b[0m [${(new Date()).toISOString()}] Sent block at position ${blockNumber} to ${requestAddress}.`); } } @@ -239,7 +239,7 @@ async function startServer(options) { await updateDifficulty(block, chainInfo, blockDB); // Update difficulty. - console.log(`LOG [${(new Date()).toISOString()}] Synced block at position ${block.blockNumber}.`); + console.log(`\x1b[32mLOG\x1b[0m [${(new Date()).toISOString()}] Synced block at position ${block.blockNumber}.`); // Continue requesting the next block for (const node of opened) { @@ -345,14 +345,14 @@ function connect(MY_ADDRESS, address) { connectedNodes++; - console.log(`LOG [${(new Date()).toISOString()}] Connected to ${address}.`); + console.log(`\x1b[32mLOG\x1b[0m [${(new Date()).toISOString()}] Connected to ${address}.`); // Listen for disconnection, will remove them from "opened" and "connected". socket.on("close", () => { opened.splice(connected.indexOf(address), 1); connected.splice(connected.indexOf(address), 1); - console.log(`LOG [${(new Date()).toISOString()}] Disconnected from ${address}.`); + console.log(`\x1b[32mLOG\x1b[0m [${(new Date()).toISOString()}] Disconnected from ${address}.`); }); } }); @@ -365,7 +365,7 @@ function connect(MY_ADDRESS, address) { async function sendTransaction(transaction) { sendMessage(produceMessage(TYPE.CREATE_TRANSACTION, transaction), opened); - console.log(`LOG [${(new Date()).toISOString()}] Sent one transaction.`); + console.log(`\x1b[32mLOG\x1b[0m [${(new Date()).toISOString()}] Sent one transaction.`); await addTransaction(transaction, chainInfo, stateDB); } @@ -537,7 +537,7 @@ async function mine(publicKey, ENABLE_LOGGING) { sendMessage(produceMessage(TYPE.NEW_BLOCK, Block.serialize(chainInfo.latestBlock)), opened); // Broadcast the new block - console.log(`LOG [${(new Date()).toISOString()}] Block #${chainInfo.latestBlock.blockNumber} mined and synced, state transited.`); + console.log(`\x1b[32mLOG\x1b[0m [${(new Date()).toISOString()}] Block #${chainInfo.latestBlock.blockNumber} mined and synced, state transited.`); } else { mined = false; } @@ -547,7 +547,7 @@ async function mine(publicKey, ENABLE_LOGGING) { worker = fork(`${__dirname}/../miner/worker.js`); }) - .catch(err => console.log(err)); + .catch(err => console.log(`\x1b[31mERROR\x1b[0m [${(new Date()).toISOString()}] Error at mining child process`, err)); } // Function to mine continuously diff --git a/src/rpc/rpc.js b/src/rpc/rpc.js index 45e3876..f32374d 100644 --- a/src/rpc/rpc.js +++ b/src/rpc/rpc.js @@ -9,7 +9,7 @@ const fastify = require("fastify")(); function rpc(PORT, client, transactionHandler, keyPair, stateDB, blockDB, bhashDB, codeDB) { - process.on("uncaughtException", err => console.log(`LOG [${(new Date()).toISOString()}]`, err)); + process.on("uncaughtException", err => console.log(`\x1b[31mERROR\x1b[0m [${(new Date()).toISOString()}] Uncaught Exception`, err)); fastify.get("/:option", async (req, reply) => { @@ -327,11 +327,11 @@ function rpc(PORT, client, transactionHandler, keyPair, stateDB, blockDB, bhashD fastify.listen(PORT, (err, address) => { if (err) { - console.log(`LOG [${(new Date()).toISOString()}] Error at RPC server: Fastify: `, err); + console.log(`\x1b[31mERROR\x1b[0m [${(new Date()).toISOString()}] Error at RPC server: Fastify: `, err); process.exit(1); } - console.log(`LOG [${(new Date()).toISOString()}] RPC server running on PORT ${PORT}`); + console.log(`\x1b[32mLOG\x1b[0m [${(new Date()).toISOString()}] RPC server listening on PORT ${PORT}`); }); }