|
1 | 1 | use std::time::{Duration, Instant};
|
2 | 2 |
|
3 |
| -use diesel::connection::TransactionManager; |
4 |
| -use diesel::RunQueryDsl; |
5 |
| - |
6 | 3 | use crate::parser::chain::ChainStorage;
|
7 | 4 | use crate::ParserOptions;
|
8 | 5 |
|
@@ -56,24 +53,13 @@ impl BlockchainParser {
|
56 | 53 | tracing::debug!(target: "parser", "Starting worker ...");
|
57 | 54 |
|
58 | 55 | self.on_start(self.cur_height);
|
59 |
| - let mut conn = self.db.pool.get()?; |
60 |
| - diesel::r2d2::PoolTransactionManager::begin_transaction(&mut conn)?; |
61 | 56 | while let Some(header) = self.chain_storage.get_header(self.cur_height) {
|
62 | 57 | Self::on_header(&header, self.cur_height);
|
63 | 58 | let block = self.chain_storage.get_block(self.cur_height).unwrap();
|
64 |
| - self.on_block(&block, self.cur_height, &mut conn)?; |
| 59 | + self.on_block(&block, self.cur_height)?; |
65 | 60 | self.print_progress(self.cur_height);
|
66 | 61 | self.cur_height += 1;
|
67 |
| - |
68 |
| - if self.cur_height % 1000 == 0 { |
69 |
| - diesel::r2d2::PoolTransactionManager::commit_transaction(&mut conn)?; |
70 |
| - drop(conn); |
71 |
| - conn = self.db.pool.get()?; |
72 |
| - diesel::r2d2::PoolTransactionManager::begin_transaction(&mut conn)?; |
73 |
| - } |
74 | 62 | }
|
75 |
| - diesel::r2d2::PoolTransactionManager::commit_transaction(&mut conn)?; |
76 |
| - drop(conn); |
77 | 63 | self.on_complete(self.cur_height.saturating_sub(1));
|
78 | 64 | Ok(())
|
79 | 65 | }
|
@@ -101,23 +87,18 @@ impl BlockchainParser {
|
101 | 87 | &mut self,
|
102 | 88 | block: &bitcoin::Block,
|
103 | 89 | height: u64,
|
104 |
| - conn: &mut diesel::r2d2::PooledConnection< |
105 |
| - diesel::r2d2::ConnectionManager<diesel::sqlite::SqliteConnection>, |
106 |
| - >, |
107 | 90 | ) -> anyhow::Result<()> {
|
108 | 91 | tracing::trace!(target: "parser", "on_block(height={}) called", height);
|
109 |
| - diesel::insert_into(crate::db::schema::blocks::table) |
110 |
| - .values(crate::db::Block { |
111 |
| - height: self.cur_height.try_into()?, |
112 |
| - version: block.header.version.to_consensus(), |
113 |
| - time: block.header.time.try_into()?, |
114 |
| - encoded_target: block.header.bits.to_consensus().try_into()?, |
115 |
| - nonce: block.header.nonce.try_into()?, |
116 |
| - tx_count: block.txdata.len().try_into()?, |
117 |
| - size: block.size().try_into()?, |
118 |
| - weight: block.weight().to_wu().try_into()?, |
119 |
| - }) |
120 |
| - .execute(conn)?; |
| 92 | + self.db.insert_block(crate::db::Block { |
| 93 | + height: self.cur_height.try_into()?, |
| 94 | + version: block.header.version.to_consensus(), |
| 95 | + time: block.header.time.try_into()?, |
| 96 | + encoded_target: block.header.bits.to_consensus().try_into()?, |
| 97 | + nonce: block.header.nonce.try_into()?, |
| 98 | + tx_count: block.txdata.len().try_into()?, |
| 99 | + size: block.size().try_into()?, |
| 100 | + weight: block.weight().to_wu().try_into()?, |
| 101 | + })?; |
121 | 102 | Ok(())
|
122 | 103 | }
|
123 | 104 |
|
|
0 commit comments