mirror of
https://github.com/GOSTSec/gostexplr
synced 2025-01-14 16:58:02 +00:00
add sync offset
This commit is contained in:
parent
34ecc7c156
commit
fbfd47f893
@ -4,6 +4,7 @@ const moment = require('moment');
|
|||||||
|
|
||||||
var models = require('../models');
|
var models = require('../models');
|
||||||
var rpcConfig = require('../config/config')['rpc'];
|
var rpcConfig = require('../config/config')['rpc'];
|
||||||
|
var HeightOffset = require('../config/config')['syncHeightOffset'] || 0;
|
||||||
|
|
||||||
const {username, password, hostname, port} = rpcConfig;
|
const {username, password, hostname, port} = rpcConfig;
|
||||||
|
|
||||||
@ -67,10 +68,6 @@ async function saveTransaction(txid, blockHeight) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// const transaction = await models.Transaction.create({
|
|
||||||
// txid: tx.txid,
|
|
||||||
// BlockHeight: blockHeight,
|
|
||||||
// });
|
|
||||||
sync_sql += `
|
sync_sql += `
|
||||||
INSERT INTO Transactions (
|
INSERT INTO Transactions (
|
||||||
txid,
|
txid,
|
||||||
@ -87,10 +84,6 @@ async function saveTransaction(txid, blockHeight) {
|
|||||||
for (var i = 0; i < tx.vout.length; i++) {
|
for (var i = 0; i < tx.vout.length; i++) {
|
||||||
const vout = tx.vout[i];
|
const vout = tx.vout[i];
|
||||||
|
|
||||||
// const m_vout = await models.Vout.create({
|
|
||||||
// n: vout.n,
|
|
||||||
// value: vout.value,
|
|
||||||
// });
|
|
||||||
sync_sql += `
|
sync_sql += `
|
||||||
INSERT INTO Vouts (n, value)
|
INSERT INTO Vouts (n, value)
|
||||||
VALUES ("${vout.n}", "${vout.value}");
|
VALUES ("${vout.n}", "${vout.value}");
|
||||||
@ -100,16 +93,7 @@ async function saveTransaction(txid, blockHeight) {
|
|||||||
// Loop over addresses in vout
|
// Loop over addresses in vout
|
||||||
for (var y = 0; y < vout.scriptPubKey.addresses.length; y++) {
|
for (var y = 0; y < vout.scriptPubKey.addresses.length; y++) {
|
||||||
const address = vout.scriptPubKey.addresses[y];
|
const address = vout.scriptPubKey.addresses[y];
|
||||||
// let m_address = await models.Address.findOne({
|
|
||||||
// where: {
|
|
||||||
// address,
|
|
||||||
// },
|
|
||||||
// });
|
|
||||||
// if (m_address === null) {
|
|
||||||
// m_address = await models.Address.create({
|
|
||||||
// address,
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
sync_sql += `
|
sync_sql += `
|
||||||
INSERT IGNORE INTO Addresses (address) VALUES ("${address}");
|
INSERT IGNORE INTO Addresses (address) VALUES ("${address}");
|
||||||
SET @addrid = (
|
SET @addrid = (
|
||||||
@ -124,13 +108,13 @@ async function saveTransaction(txid, blockHeight) {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
`;
|
`;
|
||||||
// await m_vout.addAddresses(m_address);
|
|
||||||
sync_sql += `
|
sync_sql += `
|
||||||
INSERT INTO AddressVouts (AddressId, VoutId)
|
INSERT INTO AddressVouts (AddressId, VoutId)
|
||||||
VALUES (@addrid, @voutid);
|
VALUES (@addrid, @voutid);
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
// await transaction.addVouts(m_vout, {through: {direction: 1}});
|
|
||||||
sync_sql += `
|
sync_sql += `
|
||||||
INSERT INTO TransactionVouts (TransactionId, VoutId, direction)
|
INSERT INTO TransactionVouts (TransactionId, VoutId, direction)
|
||||||
VALUES (@txid, @voutid, 1);
|
VALUES (@txid, @voutid, 1);
|
||||||
@ -141,22 +125,7 @@ async function saveTransaction(txid, blockHeight) {
|
|||||||
for (var i = 0; i < tx.vin.length; i++) {
|
for (var i = 0; i < tx.vin.length; i++) {
|
||||||
const vin = tx.vin[i];
|
const vin = tx.vin[i];
|
||||||
if (vin.txid) {
|
if (vin.txid) {
|
||||||
// const vout = await models.Vout.findAll({
|
|
||||||
// include: {
|
|
||||||
// model: models.Transaction,
|
|
||||||
// where: {
|
|
||||||
// txid: vin.txid,
|
|
||||||
// },
|
|
||||||
// },
|
|
||||||
// where: {
|
|
||||||
// n: vin.vout,
|
|
||||||
// },
|
|
||||||
// });
|
|
||||||
// if (vout) {
|
|
||||||
// await transaction.addVouts(vout[0], { through: { direction: 0, }, });
|
|
||||||
// } else {
|
|
||||||
// throw('Couldnt find vout for VIN');
|
|
||||||
// }
|
|
||||||
sync_sql += `
|
sync_sql += `
|
||||||
SET @vin = (
|
SET @vin = (
|
||||||
SELECT Vouts.id
|
SELECT Vouts.id
|
||||||
@ -204,7 +173,6 @@ async function syncNextBlock(syncedHeight) {
|
|||||||
|
|
||||||
block.time = moment(block.time*1000).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);
|
|
||||||
sync_sql = `
|
sync_sql = `
|
||||||
SET autocommit = 0;
|
SET autocommit = 0;
|
||||||
START TRANSACTION;
|
START TRANSACTION;
|
||||||
@ -243,13 +211,7 @@ async function syncNextBlock(syncedHeight) {
|
|||||||
|
|
||||||
|
|
||||||
if (block.height > 1) {
|
if (block.height > 1) {
|
||||||
// await models.Block.update({
|
|
||||||
// nextblockhash: block.hash
|
|
||||||
// },{
|
|
||||||
// where: {
|
|
||||||
// hash: block.previousblockhash
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
sync_sql += `
|
sync_sql += `
|
||||||
UPDATE Block
|
UPDATE Block
|
||||||
SET nextblockhash="${block.hash}"
|
SET nextblockhash="${block.hash}"
|
||||||
@ -268,7 +230,7 @@ async function getCurrentHeight() {
|
|||||||
params: [],
|
params: [],
|
||||||
id: 1
|
id: 1
|
||||||
}));
|
}));
|
||||||
return JSON.parse(result)['result'];
|
return JSON.parse(result)['result'] - HeightOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getSyncedHeight() {
|
async function getSyncedHeight() {
|
||||||
@ -297,9 +259,7 @@ async function acquireLock() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function syncBlockchain() {
|
async function syncBlockchain() {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
await acquireLock();
|
await acquireLock();
|
||||||
|
|
||||||
let syncedHeight = await getSyncedHeight();
|
let syncedHeight = await getSyncedHeight();
|
||||||
|
@ -39,6 +39,7 @@
|
|||||||
"hostname": "127.0.0.1",
|
"hostname": "127.0.0.1",
|
||||||
"port": 9376
|
"port": 9376
|
||||||
},
|
},
|
||||||
|
"syncHeightOffset": 0,
|
||||||
"env": "production",
|
"env": "production",
|
||||||
"port": 3000
|
"port": 3000
|
||||||
}
|
}
|
||||||
|
@ -7,8 +7,7 @@
|
|||||||
"start": "node ./bin/www",
|
"start": "node ./bin/www",
|
||||||
"initdb": "node ./bin/initdb.js",
|
"initdb": "node ./bin/initdb.js",
|
||||||
"createUserAndDb": "node ./bin/createUserAndDb.js",
|
"createUserAndDb": "node ./bin/createUserAndDb.js",
|
||||||
"syncBlockchain": "node ./bin/syncBlockchain.js",
|
"sync": "node ./bin/syncBlockchain.js"
|
||||||
"addN": "node ./bin/addNToVouts.js"
|
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
Loading…
Reference in New Issue
Block a user