File tree Expand file tree Collapse file tree 5 files changed +13
-1
lines changed
migrations/2023-08-09-202146_add_opreturn_table Expand file tree Collapse file tree 5 files changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -7,5 +7,6 @@ CREATE TABLE blocks (
7
7
tx_count INTEGER NOT NULL ,
8
8
size INTEGER NOT NULL ,
9
9
weight BIGINT NOT NULL ,
10
- turnover BIGINT NOT NULL
10
+ turnover BIGINT NOT NULL ,
11
+ miner_reward BIGINT NOT NULL
11
12
);
Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ pub struct Block {
22
22
pub size : i32 ,
23
23
pub weight : i64 ,
24
24
pub turnover : i64 ,
25
+ pub miner_reward : i64 ,
25
26
}
26
27
27
28
const MIGRATIONS : diesel_migrations:: EmbeddedMigrations = diesel_migrations:: embed_migrations!( ) ;
Original file line number Diff line number Diff line change @@ -11,5 +11,6 @@ diesel::table! {
11
11
size -> Integer ,
12
12
weight -> BigInt ,
13
13
turnover -> BigInt ,
14
+ miner_reward -> BigInt ,
14
15
}
15
16
}
Original file line number Diff line number Diff line change @@ -65,6 +65,10 @@ impl BlockchainParser {
65
65
. flat_map ( |tx| tx. output . iter ( ) . map ( |output| output. value ) )
66
66
. sum ( ) ;
67
67
68
+ let miner_reward = block
69
+ . coinbase ( )
70
+ . map_or_else ( || 0 , |cb| cb. output . iter ( ) . map ( |output| output. value ) . sum ( ) ) ;
71
+
68
72
tracing:: trace!( target: "parser" , "on_block(height={}) called" , self . cur_height) ;
69
73
blocks. push ( crate :: db:: Block {
70
74
height : self . cur_height . try_into ( ) ?,
@@ -76,6 +80,7 @@ impl BlockchainParser {
76
80
size : block. size ( ) . try_into ( ) ?,
77
81
weight : block. weight ( ) . to_wu ( ) . try_into ( ) ?,
78
82
turnover : turnover. try_into ( ) ?,
83
+ miner_reward : miner_reward. try_into ( ) ?,
79
84
} ) ;
80
85
if blocks. len ( ) == block_buffer_size {
81
86
self . db . insert_blocks ( blocks) ?;
Original file line number Diff line number Diff line change @@ -129,4 +129,8 @@ fn test_blocks_db() {
129
129
u64 :: try_from( parser. db( ) . block( 170 ) . unwrap( ) . turnover) . unwrap( ) ,
130
130
100 * bitcoin:: Amount :: ONE_BTC . to_sat( )
131
131
) ;
132
+ assert_eq ! (
133
+ u64 :: try_from( parser. db( ) . block( 50 ) . unwrap( ) . miner_reward) . unwrap( ) ,
134
+ 50 * bitcoin:: Amount :: ONE_BTC . to_sat( )
135
+ ) ;
132
136
}
You can’t perform that action at this time.
0 commit comments