Skip to content

Commit f73ec27

Browse files
committed
db/block: add mining pool information
1 parent 11a1aa4 commit f73ec27

File tree

7 files changed

+126
-5
lines changed

7 files changed

+126
-5
lines changed

Cargo.lock

Lines changed: 115 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ edition = "2021"
1212
[dependencies]
1313
anyhow = "1.0.72"
1414
bitcoin = "0.30.1"
15+
bitcoin-pool-identification = "0.2.4"
1516
clap = { version = "4.3.21", features = [ "cargo" ] }
1617
diesel = { version = "2.1.0", features = [ "r2d2", "sqlite" ], default-features = false }
1718
diesel_migrations = "2.1.0"

migrations/2023-08-09-202146_add_opreturn_table/up.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ CREATE TABLE blocks (
88
size INTEGER NOT NULL,
99
weight BIGINT NOT NULL,
1010
turnover BIGINT NOT NULL,
11-
miner_reward BIGINT NOT NULL
11+
miner_reward BIGINT NOT NULL,
12+
pool TEXT
1213
);

src/db/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ pub struct Block {
2323
pub weight: i64,
2424
pub turnover: i64,
2525
pub miner_reward: i64,
26+
pub pool: Option<String>,
2627
}
2728

2829
const MIGRATIONS: diesel_migrations::EmbeddedMigrations = diesel_migrations::embed_migrations!();

src/db/schema.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ diesel::table! {
1212
weight -> BigInt,
1313
turnover -> BigInt,
1414
miner_reward -> BigInt,
15+
pool -> Nullable<Text>,
1516
}
1617
}

src/parser/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use std::time::{Duration, Instant};
22

3+
use bitcoin_pool_identification::PoolIdentification;
4+
35
use crate::parser::chain::ChainStorage;
46
use crate::ParserOptions;
57

@@ -69,6 +71,8 @@ impl BlockchainParser {
6971
.coinbase()
7072
.map_or_else(|| 0, |cb| cb.output.iter().map(|output| output.value).sum());
7173

74+
let pool = block.identify_pool().map(|p| p.name);
75+
7276
tracing::trace!(target: "parser", "on_block(height={}) called", self.cur_height);
7377
blocks.push(crate::db::Block {
7478
height: self.cur_height.try_into()?,
@@ -81,6 +85,7 @@ impl BlockchainParser {
8185
weight: block.weight().to_wu().try_into()?,
8286
turnover: turnover.try_into()?,
8387
miner_reward: miner_reward.try_into()?,
88+
pool,
8489
});
8590
if blocks.len() == block_buffer_size {
8691
self.db.insert_blocks(blocks)?;

tests/bitcoin.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,4 +133,5 @@ fn test_blocks_db() {
133133
u64::try_from(parser.db().block(50).unwrap().miner_reward).unwrap(),
134134
50 * bitcoin::Amount::ONE_BTC.to_sat()
135135
);
136+
assert!(parser.db().block(75).unwrap().pool.is_none());
136137
}

0 commit comments

Comments
 (0)