File tree Expand file tree Collapse file tree 5 files changed +19
-1
lines changed
migrations/2023-08-09-202146_add_opreturn_table Expand file tree Collapse file tree 5 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -6,5 +6,6 @@ CREATE TABLE blocks (
6
6
nonce BIGINT NOT NULL ,
7
7
tx_count INTEGER NOT NULL ,
8
8
size INTEGER NOT NULL ,
9
- weight BIGINT NOT NULL
9
+ weight BIGINT NOT NULL ,
10
+ turnover BIGINT NOT NULL
10
11
);
Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ pub struct Block {
21
21
pub tx_count : i32 ,
22
22
pub size : i32 ,
23
23
pub weight : i64 ,
24
+ pub turnover : i64 ,
24
25
}
25
26
26
27
const MIGRATIONS : diesel_migrations:: EmbeddedMigrations = diesel_migrations:: embed_migrations!( ) ;
Original file line number Diff line number Diff line change @@ -10,5 +10,6 @@ diesel::table! {
10
10
tx_count -> Integer ,
11
11
size -> Integer ,
12
12
weight -> BigInt ,
13
+ turnover -> BigInt ,
13
14
}
14
15
}
Original file line number Diff line number Diff line change @@ -59,6 +59,12 @@ impl BlockchainParser {
59
59
Self :: on_header ( & header, self . cur_height ) ;
60
60
let block = self . chain_storage . get_block ( self . cur_height ) . unwrap ( ) ;
61
61
62
+ let turnover: u64 = block
63
+ . txdata
64
+ . iter ( )
65
+ . flat_map ( |tx| tx. output . iter ( ) . map ( |output| output. value ) )
66
+ . sum ( ) ;
67
+
62
68
tracing:: trace!( target: "parser" , "on_block(height={}) called" , self . cur_height) ;
63
69
blocks. push ( crate :: db:: Block {
64
70
height : self . cur_height . try_into ( ) ?,
@@ -69,6 +75,7 @@ impl BlockchainParser {
69
75
tx_count : block. txdata . len ( ) . try_into ( ) ?,
70
76
size : block. size ( ) . try_into ( ) ?,
71
77
weight : block. weight ( ) . to_wu ( ) . try_into ( ) ?,
78
+ turnover : turnover. try_into ( ) ?,
72
79
} ) ;
73
80
if blocks. len ( ) == block_buffer_size {
74
81
self . db . insert_blocks ( blocks) ?;
Original file line number Diff line number Diff line change @@ -121,4 +121,12 @@ fn test_blocks_db() {
121
121
let mut parser = parser ( ) ;
122
122
parser. start ( ) . unwrap ( ) ;
123
123
assert_eq ! ( parser. db( ) . blocks_count( ) . unwrap( ) , 171 ) ;
124
+ assert_eq ! (
125
+ u64 :: try_from( parser. db( ) . block( 100 ) . unwrap( ) . turnover) . unwrap( ) ,
126
+ 50 * bitcoin:: Amount :: ONE_BTC . to_sat( )
127
+ ) ;
128
+ assert_eq ! (
129
+ u64 :: try_from( parser. db( ) . block( 170 ) . unwrap( ) . turnover) . unwrap( ) ,
130
+ 100 * bitcoin:: Amount :: ONE_BTC . to_sat( )
131
+ ) ;
124
132
}
You can’t perform that action at this time.
0 commit comments