Browse Source

Sync bug, pretty print while sync

master
xcps 6 years ago committed by R4SAS
parent
commit
9017959e7f
  1. 14
      bin/syncBlockchain.js

14
bin/syncBlockchain.js

@ -7,7 +7,8 @@ var rpcConfig = require('../config/config')['rpc'];
const {username, password, hostname, port} = rpcConfig; const {username, password, hostname, port} = rpcConfig;
let sync_sql = ''; let sync_sql = '',
coolstrs = [];
function MakeRPCRequest(postData) { function MakeRPCRequest(postData) {
return new Promise(function(resolve, reject) { return new Promise(function(resolve, reject) {
@ -188,7 +189,7 @@ async function syncNextBlock(syncedHeight) {
})); }));
const block = JSON.parse(res_block)['result']; const block = JSON.parse(res_block)['result'];
block.time = moment(1491163173000).format('YYYY-MM-DD HH:MM:SS'); block.time = moment(block.time*1000).format('YYYY-MM-DD HH:mm:ss');
// await models.Block.create(block); // await models.Block.create(block);
sync_sql = ` sync_sql = `
@ -221,8 +222,10 @@ async function syncNextBlock(syncedHeight) {
"${block.nextblockhash}" "${block.nextblockhash}"
); );
` `
coolstrs = []
for (var i = 0; i < block.tx.length; i++) { for (var i = 0; i < block.tx.length; i++) {
await saveTransaction(block.tx[i], block.height); await saveTransaction(block.tx[i], block.height);
coolstrs.push(`${block.tx[i]} - ${block.time}`);
} }
@ -242,6 +245,7 @@ async function syncNextBlock(syncedHeight) {
} }
sync_sql += 'COMMIT;' sync_sql += 'COMMIT;'
await models.sequelize.query(sync_sql); await models.sequelize.query(sync_sql);
return height; return height;
} }
@ -293,8 +297,14 @@ async function syncBlockchain() {
while (syncedHeight < currentHeight) { while (syncedHeight < currentHeight) {
syncedHeight = await syncNextBlock(syncedHeight); syncedHeight = await syncNextBlock(syncedHeight);
if (coolstrs) {
for(str of coolstrs) {
console.log('\x1b[36m%s\x1b[0m', 'syncedHeight: ', syncedHeight, str)
}
} else {
console.log('\x1b[36m%s\x1b[0m', 'syncedHeight: ', syncedHeight) console.log('\x1b[36m%s\x1b[0m', 'syncedHeight: ', syncedHeight)
} }
}
} catch (e) { } catch (e) {
console.log(e); console.log(e);
} finally { } finally {

Loading…
Cancel
Save