1
0
mirror of https://github.com/GOSTSec/gostexplr synced 2025-02-05 19:34:26 +00:00

Sync bug, pretty print while sync

This commit is contained in:
xcps 2019-03-16 23:48:45 +05:00 committed by R4SAS
parent 8418db9df9
commit 9017959e7f

View File

@ -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,7 +297,13 @@ async function syncBlockchain() {
while (syncedHeight < currentHeight) { while (syncedHeight < currentHeight) {
syncedHeight = await syncNextBlock(syncedHeight); syncedHeight = await syncNextBlock(syncedHeight);
console.log('\x1b[36m%s\x1b[0m', 'syncedHeight: ', 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)
}
} }
} catch (e) { } catch (e) {
console.log(e); console.log(e);