xcps 7 years ago
parent
commit
37038a28e0
  1. 0
      .gitignore
  2. 0
      README.md
  3. 0
      app.js
  4. 0
      bin/createUserAndDb.js
  5. 0
      bin/initdb.js
  6. 57
      bin/syncBlockchain.js
  7. 0
      config/config.json.example
  8. 0
      models/address.js
  9. 0
      models/block.js
  10. 0
      models/failure.js
  11. 0
      models/index.js
  12. 0
      models/transaction.js
  13. 0
      models/vout.js
  14. 0
      package.json
  15. 0
      public/favicon.ico
  16. 0
      public/images/gostcoin-b.png
  17. 0
      public/stylesheets/style.css
  18. 26
      routes/address.js
  19. 13
      routes/asdf.sql
  20. 0
      routes/block.js
  21. 0
      routes/index.js
  22. 0
      routes/search.js
  23. 0
      routes/transaction.js
  24. 0
      views/404.pug
  25. 5
      views/address.pug
  26. 0
      views/block.pug
  27. 0
      views/error.pug
  28. 0
      views/index.pug
  29. 2
      views/layout.pug
  30. 0
      views/transaction.pug

0
.gitignore vendored

0
bin/createUserAndDb.js

0
bin/initdb.js

57
bin/syncBlockchain.js

@ -41,40 +41,56 @@ async function saveTransaction(txid, blockHeight) {
const tx = JSON.parse(res_tx)['result']; const tx = JSON.parse(res_tx)['result'];
if (tx === null) { if (tx === null) {
await models.Failure.create({ await models.Failure.create({
msg: `${txid} fetching failed`, msg: `Transaction ${txid} fetching failed`,
}); });
return; return;
} }
const transaction = await models.Transaction.create({ // const transaction = await models.Transaction.create({
// txid: tx.txid,
// BlockHeight: blockHeight,
// });
const transaction = {
txid: tx.txid, txid: tx.txid,
BlockHeight: blockHeight, BlockHeight: blockHeight,
}); vouts: [],
};
// Loop over vouts // Loop over vouts
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({ // const m_vout = await models.Vout.create({
// n: vout.n,
// value: vout.value,
// });
const m_vout = {
n: vout.n, n: vout.n,
value: vout.value, value: vout.value,
}); addresses: []
};
// 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({ // let m_address = await models.Address.findOne({
where: { // where: {
address, // address,
}, // },
}); // });
if (m_address === null) { // if (m_address === null) {
m_address = await models.Address.create({ // m_address = await models.Address.create({ /// TODO create
address, // address,
}); // });
} // }
await m_vout.addAddresses(m_address); // if (m_address === null) {
// m_address = { address, };
// }
// await m_vout.addAddresses(m_address);
m_vout.push(m_address);
} }
await transaction.addVouts(m_vout, {through: {direction: 1}}); // await transaction.addVouts(m_vout, {through: {direction: 1}}); // TODO create
transaction.addVouts(m_vout, {through: {direction: 1}}); // TODO create
} }
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];
@ -114,9 +130,9 @@ async function syncNextBlock(syncedHeight) {
})); }));
const block = JSON.parse(res_block)['result']; const block = JSON.parse(res_block)['result'];
block.time = new Date(block.time * 1000); block.time = new Date(block.time * 1000);
await models.Block.create(block); // await models.Block.create(block);
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);
} }
if (block.height > 1) { if (block.height > 1) {
await models.Block.update({ await models.Block.update({
@ -159,12 +175,13 @@ async function syncBlockchain() {
try { try {
while (syncedHeight < currentHeight) { while (syncedHeight < currentHeight) {
syncedHeight = await syncNextBlock(syncedHeight); syncedHeight = await syncNextBlock(syncedHeight);
console.log('\x1b[36m%s\x1b[0m', 'syncedHeight: ', syncedHeight) process.stdout.write(`Synced ${syncedHeight} out of ${currentHeight}\r`);
} }
} catch (e) { } catch (e) {
console.log('=====', e); console.log('=====', e);
process.exit(0); process.exit(0);
} }
process.stdout.write('\nDone\n');
process.exit(0); process.exit(0);
} }

0
config/config.json.example

0
models/address.js

0
models/block.js

0
models/failure.js

0
models/index.js

0
models/transaction.js

0
models/vout.js

0
package.json

0
public/favicon.ico

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

0
public/images/gostcoin-b.png

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 22 KiB

0
public/stylesheets/style.css

26
routes/address.js

@ -6,36 +6,40 @@ var router = express.Router();
router.get('/:address/:offset*?', async function(req, res, next) { router.get('/:address/:offset*?', async function(req, res, next) {
const safe_address = encodeURI(req.params.address); const safe_address = encodeURI(req.params.address);
const limit = 30;
const address = await models.Address.findOne({ const transactions = await models.Transaction.findAll({
where: {
address: safe_address,
},
include: { include: {
model: models.Vout, model: models.Vout,
include: { include: {
model: models.Transaction, model: models.Address,
where: {
address: safe_address,
},
}, },
}, },
raw: true,
limit: 30,
}); });
if (address === null) { console.log(transactions);
if (transactions === null) {
res.status(404).render('404'); res.status(404).render('404');
return; return;
} }
const limit = 30;
const paramPage = parseInt(req.params.offset); const paramPage = parseInt(req.params.offset);
const page = isNaN(paramPage) || paramPage < 1 ? 1 : paramPage; const page = isNaN(paramPage) || paramPage < 1 ? 1 : paramPage;
const offset = 30 * (page - 1); const offset = 30 * (page - 1);
const nextpage = address.Vouts.length === 30 ? page + 1 : null; const nextpage = transactions.length === 30 ? page + 1 : null;
const prevpage = page > 1 ? page - 1 : null; const prevpage = page > 1 ? page - 1 : null;
console.log(address.toJSON());
res.render('address', { res.render('address', {
address: address.toJSON(), address: safe_address,
transactions,
nextpage, nextpage,
prevpage, prevpage,
}); });

13
routes/asdf.sql

@ -0,0 +1,13 @@
{ id: 35,
txid: '6dbdd552bed6523a48de3d07dfbdb655cf8386582cb4e7b5e0a7090ebf80e9bc',
BlockHeight: 68,
'Vouts.id': null,
'Vouts.n': null,
'Vouts.value': null,
'Vouts.TransactionVouts.direction': null,
'Vouts.TransactionVouts.TransactionId': null,
'Vouts.TransactionVouts.VoutId': null,
'Vouts.Addresses.id': null,
'Vouts.Addresses.address': null,
'Vouts.Addresses.AddressVout.AddressId': null,
'Vouts.Addresses.AddressVout.VoutId': null },

0
routes/block.js

0
routes/index.js

0
routes/search.js

0
routes/transaction.js

0
views/404.pug

5
views/address.pug

@ -6,10 +6,9 @@ block content
h3 Transactions h3 Transactions
table table
each vout in address.Vouts each transaction in transactions
each transaction in vout.Transactions
tr tr
if transaction.TransactionVouts.direction == 1 if transaction['Vouts.TransactionVouts.direction'] == 1
td INCOME td INCOME
else else
td OUTCOME td OUTCOME

0
views/block.pug

0
views/error.pug

0
views/index.pug

2
views/layout.pug

@ -1,7 +1,7 @@
doctype html doctype html
html html
head head
title GOSTcoin blockchain explorer title ANnYcoin blockchain explorer
link(rel='stylesheet', href='/stylesheets/style.css') link(rel='stylesheet', href='/stylesheets/style.css')
link(rel='shortcut icon', href='/favicon.ico') link(rel='shortcut icon', href='/favicon.ico')
meta(name="viewport", content="width=device-width") meta(name="viewport", content="width=device-width")

0
views/transaction.pug

Loading…
Cancel
Save