From 37038a28e0777860096b15fd23e1be1b62e159a0 Mon Sep 17 00:00:00 2001 From: xcps Date: Sun, 4 Mar 2018 03:15:40 +0500 Subject: [PATCH] asdf --- .gitignore | 0 README.md | 0 app.js | 0 bin/createUserAndDb.js | 0 bin/initdb.js | 0 bin/syncBlockchain.js | 57 +++++++++++++++++++++++------------ 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 | Bin public/images/gostcoin-b.png | Bin public/stylesheets/style.css | 0 routes/address.js | 26 +++++++++------- routes/asdf.sql | 13 ++++++++ routes/block.js | 0 routes/index.js | 0 routes/search.js | 0 routes/transaction.js | 0 views/404.pug | 0 views/address.pug | 5 ++- views/block.pug | 0 views/error.pug | 0 views/index.pug | 0 views/layout.pug | 2 +- views/transaction.pug | 0 30 files changed, 68 insertions(+), 35 deletions(-) mode change 100644 => 100755 .gitignore mode change 100644 => 100755 README.md mode change 100644 => 100755 app.js mode change 100644 => 100755 bin/createUserAndDb.js mode change 100644 => 100755 bin/initdb.js mode change 100644 => 100755 bin/syncBlockchain.js mode change 100644 => 100755 config/config.json.example mode change 100644 => 100755 models/address.js mode change 100644 => 100755 models/block.js mode change 100644 => 100755 models/failure.js mode change 100644 => 100755 models/index.js mode change 100644 => 100755 models/transaction.js mode change 100644 => 100755 models/vout.js mode change 100644 => 100755 package.json mode change 100644 => 100755 public/favicon.ico mode change 100644 => 100755 public/images/gostcoin-b.png mode change 100644 => 100755 public/stylesheets/style.css mode change 100644 => 100755 routes/address.js create mode 100755 routes/asdf.sql mode change 100644 => 100755 routes/block.js mode change 100644 => 100755 routes/index.js mode change 100644 => 100755 routes/search.js mode change 100644 => 100755 routes/transaction.js mode change 100644 => 100755 views/404.pug mode change 100644 => 100755 views/address.pug mode change 100644 => 100755 views/block.pug mode change 100644 => 100755 views/error.pug mode change 100644 => 100755 views/index.pug mode change 100644 => 100755 views/layout.pug mode change 100644 => 100755 views/transaction.pug diff --git a/.gitignore b/.gitignore old mode 100644 new mode 100755 diff --git a/README.md b/README.md old mode 100644 new mode 100755 diff --git a/app.js b/app.js old mode 100644 new mode 100755 diff --git a/bin/createUserAndDb.js b/bin/createUserAndDb.js old mode 100644 new mode 100755 diff --git a/bin/initdb.js b/bin/initdb.js old mode 100644 new mode 100755 diff --git a/bin/syncBlockchain.js b/bin/syncBlockchain.js old mode 100644 new mode 100755 index 7cbf704..a2572c3 --- a/bin/syncBlockchain.js +++ b/bin/syncBlockchain.js @@ -41,40 +41,56 @@ async function saveTransaction(txid, blockHeight) { const tx = JSON.parse(res_tx)['result']; if (tx === null) { await models.Failure.create({ - msg: `${txid} fetching failed`, + msg: `Transaction ${txid} fetching failed`, }); return; } - const transaction = await models.Transaction.create({ + // const transaction = await models.Transaction.create({ + // txid: tx.txid, + // BlockHeight: blockHeight, + // }); + const transaction = { txid: tx.txid, BlockHeight: blockHeight, - }); + vouts: [], + }; // Loop over vouts for (var i = 0; i < tx.vout.length; 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, value: vout.value, - }); + addresses: [] + }; // Loop over addresses in vout for (var y = 0; y < vout.scriptPubKey.addresses.length; 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, - }); - } - await m_vout.addAddresses(m_address); + // let m_address = await models.Address.findOne({ + // where: { + // address, + // }, + // }); + // if (m_address === null) { + // m_address = await models.Address.create({ /// TODO create + // 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++) { const vin = tx.vin[i]; @@ -114,9 +130,9 @@ async function syncNextBlock(syncedHeight) { })); const block = JSON.parse(res_block)['result']; 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++) { - await saveTransaction(block.tx[i], block.height); + // await saveTransaction(block.tx[i], block.height); } if (block.height > 1) { await models.Block.update({ @@ -159,12 +175,13 @@ async function syncBlockchain() { try { while (syncedHeight < currentHeight) { syncedHeight = await syncNextBlock(syncedHeight); - console.log('\x1b[36m%s\x1b[0m', 'syncedHeight: ', syncedHeight) + process.stdout.write(`Synced ${syncedHeight} out of ${currentHeight}\r`); } } catch (e) { console.log('=====', e); process.exit(0); } + process.stdout.write('\nDone\n'); process.exit(0); } diff --git a/config/config.json.example b/config/config.json.example old mode 100644 new mode 100755 diff --git a/models/address.js b/models/address.js old mode 100644 new mode 100755 diff --git a/models/block.js b/models/block.js old mode 100644 new mode 100755 diff --git a/models/failure.js b/models/failure.js old mode 100644 new mode 100755 diff --git a/models/index.js b/models/index.js old mode 100644 new mode 100755 diff --git a/models/transaction.js b/models/transaction.js old mode 100644 new mode 100755 diff --git a/models/vout.js b/models/vout.js old mode 100644 new mode 100755 diff --git a/package.json b/package.json old mode 100644 new mode 100755 diff --git a/public/favicon.ico b/public/favicon.ico old mode 100644 new mode 100755 diff --git a/public/images/gostcoin-b.png b/public/images/gostcoin-b.png old mode 100644 new mode 100755 diff --git a/public/stylesheets/style.css b/public/stylesheets/style.css old mode 100644 new mode 100755 diff --git a/routes/address.js b/routes/address.js old mode 100644 new mode 100755 index 7fadf88..56fd70b --- a/routes/address.js +++ b/routes/address.js @@ -6,36 +6,40 @@ var router = express.Router(); router.get('/:address/:offset*?', async function(req, res, next) { const safe_address = encodeURI(req.params.address); + const limit = 30; - const address = await models.Address.findOne({ - where: { - address: safe_address, - }, + const transactions = await models.Transaction.findAll({ include: { model: models.Vout, 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'); return; } - const limit = 30; + const paramPage = parseInt(req.params.offset); const page = isNaN(paramPage) || paramPage < 1 ? 1 : paramPage; 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; - console.log(address.toJSON()); res.render('address', { - address: address.toJSON(), + address: safe_address, + transactions, nextpage, prevpage, }); diff --git a/routes/asdf.sql b/routes/asdf.sql new file mode 100755 index 0000000..fd32114 --- /dev/null +++ b/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 }, \ No newline at end of file diff --git a/routes/block.js b/routes/block.js old mode 100644 new mode 100755 diff --git a/routes/index.js b/routes/index.js old mode 100644 new mode 100755 diff --git a/routes/search.js b/routes/search.js old mode 100644 new mode 100755 diff --git a/routes/transaction.js b/routes/transaction.js old mode 100644 new mode 100755 diff --git a/views/404.pug b/views/404.pug old mode 100644 new mode 100755 diff --git a/views/address.pug b/views/address.pug old mode 100644 new mode 100755 index 68b1fa9..3db1d32 --- a/views/address.pug +++ b/views/address.pug @@ -6,10 +6,9 @@ block content h3 Transactions table - each vout in address.Vouts - each transaction in vout.Transactions + each transaction in transactions tr - if transaction.TransactionVouts.direction == 1 + if transaction['Vouts.TransactionVouts.direction'] == 1 td INCOME else td OUTCOME diff --git a/views/block.pug b/views/block.pug old mode 100644 new mode 100755 diff --git a/views/error.pug b/views/error.pug old mode 100644 new mode 100755 diff --git a/views/index.pug b/views/index.pug old mode 100644 new mode 100755 diff --git a/views/layout.pug b/views/layout.pug old mode 100644 new mode 100755 index e5ef35a..7a4cb3d --- a/views/layout.pug +++ b/views/layout.pug @@ -1,7 +1,7 @@ doctype html html head - title GOSTcoin blockchain explorer + title ANnYcoin blockchain explorer link(rel='stylesheet', href='/stylesheets/style.css') link(rel='shortcut icon', href='/favicon.ico') meta(name="viewport", content="width=device-width") diff --git a/views/transaction.pug b/views/transaction.pug old mode 100644 new mode 100755