@@ -20,7 +20,7 @@ use serde_json::Value;
2020
2121use super :: DatabaseClient ;
2222
23- const BQ_RECEIPTS_TABLE_ID : & str = "receipts " ;
23+ const BQ_EXE_RESULTS_TABLE_ID : & str = "exe_results " ;
2424const BQ_BLOCKS_TABLE_ID : & str = "blocks" ;
2525const BQ_TRANSACTIONS_TABLE_ID : & str = "transactions" ;
2626
@@ -131,10 +131,10 @@ impl BigQueryDbClient {
131131 ] ,
132132 ) ,
133133 (
134- BQ_RECEIPTS_TABLE_ID ,
134+ BQ_EXE_RESULTS_TABLE_ID ,
135135 vec ! [
136136 TableFieldSchema :: string( "tx_hash" ) ,
137- TableFieldSchema :: json( "receipt " ) ,
137+ TableFieldSchema :: json( "exe_result " ) ,
138138 ] ,
139139 ) ,
140140 (
@@ -208,7 +208,7 @@ impl DatabaseClient for BigQueryDbClient {
208208 } ;
209209
210210 delete_table ( BQ_BLOCKS_TABLE_ID . to_owned ( ) ) . await ?;
211- delete_table ( BQ_RECEIPTS_TABLE_ID . to_owned ( ) ) . await ?;
211+ delete_table ( BQ_EXE_RESULTS_TABLE_ID . to_owned ( ) ) . await ?;
212212 delete_table ( BQ_TRANSACTIONS_TABLE_ID . to_owned ( ) ) . await ?;
213213
214214 Ok ( ( ) )
@@ -303,66 +303,77 @@ impl DatabaseClient for BigQueryDbClient {
303303 ) ;
304304 } ;
305305
306- let receipts = receipts
307- . iter ( )
308- . map ( |r| {
309- let tx_hash = & r. transaction_hash ;
310- let receipt = ReceiptRow {
311- tx_hash : format ! ( "0x{:x}" , tx_hash) ,
312- receipt : serde_json:: to_value ( r) . expect ( "Failed to serialize receipt" ) ,
313- } ;
314-
315- TableDataInsertAllRequestRows {
316- insert_id : Some ( format ! ( "0x{:x}" , tx_hash) ) ,
317- json : serde_json:: to_value ( receipt) . expect ( "Failed to serialize receipt" ) ,
318- }
319- } )
320- . collect :: < Vec < _ > > ( ) ;
306+ if !receipts. is_empty ( ) {
307+ let receipts = receipts
308+ . iter ( )
309+ . map ( |r| {
310+ let tx_hash = & r. transaction_hash ;
311+ let receipt = ExeResultRow {
312+ tx_hash : format ! ( "0x{:x}" , tx_hash) ,
313+ exe_result : serde_json:: to_value ( r) . expect ( "Failed to serialize receipt" ) ,
314+ } ;
315+
316+ TableDataInsertAllRequestRows {
317+ insert_id : Some ( format ! ( "0x{:x}" , tx_hash) ) ,
318+ json : serde_json:: to_value ( receipt) . expect ( "Failed to serialize receipt" ) ,
319+ }
320+ } )
321+ . collect :: < Vec < _ > > ( ) ;
321322
322- self . insert_batch_data ( BQ_RECEIPTS_TABLE_ID , receipts)
323- . await ?;
323+ log:: debug!( "Inserting {} receipts" , receipts. len( ) ) ;
324324
325- let blocks = blocks
326- . iter ( )
327- . map ( |b| {
328- let block_id = b. number . 0 . as_u64 ( ) ;
325+ self . insert_batch_data ( BQ_EXE_RESULTS_TABLE_ID , receipts)
326+ . await ?;
327+ }
329328
330- let block_row = BlockRow {
331- id : block_id,
332- body : serde_json:: to_value ( b) . expect ( "Failed to serialize block" ) ,
333- } ;
329+ if !blocks. is_empty ( ) {
330+ let blocks = blocks
331+ . iter ( )
332+ . map ( |b| {
333+ let block_id = b. number . 0 . as_u64 ( ) ;
334+
335+ let block_row = BlockRow {
336+ id : block_id,
337+ body : serde_json:: to_value ( b) . expect ( "Failed to serialize block" ) ,
338+ } ;
339+
340+ TableDataInsertAllRequestRows {
341+ insert_id : Some ( b. hash . to_hex_str ( ) ) ,
342+ json : serde_json:: to_value ( block_row) . expect ( "Failed to serialize block" ) ,
343+ }
344+ } )
345+ . collect :: < Vec < _ > > ( ) ;
334346
335- TableDataInsertAllRequestRows {
336- insert_id : Some ( b. hash . to_hex_str ( ) ) ,
337- json : serde_json:: to_value ( block_row) . expect ( "Failed to serialize block" ) ,
338- }
339- } )
340- . collect :: < Vec < _ > > ( ) ;
341-
342- self . insert_batch_data ( BQ_BLOCKS_TABLE_ID , blocks) . await ?;
343-
344- // Insert transactions
345- let transactions = transactions
346- . iter ( )
347- . map ( |txn| {
348- let tx_hash = & txn. hash ;
349-
350- let txn = TransactionRow {
351- tx_hash : format ! ( "0x{:x}" , tx_hash) ,
352- transaction : serde_json:: to_value ( txn)
353- . expect ( "Failed to serialize transaction" ) ,
354- block_number : txn. block_number . expect ( "Block number not found" ) . 0 . as_u64 ( ) ,
355- } ;
356-
357- TableDataInsertAllRequestRows {
358- insert_id : Some ( format ! ( "0x{:x}" , tx_hash) ) ,
359- json : serde_json:: to_value ( txn) . expect ( "Failed to serialize transaction" ) ,
360- }
361- } )
362- . collect :: < Vec < _ > > ( ) ;
347+ log:: debug!( "Inserting {} blocks" , blocks. len( ) ) ;
363348
364- self . insert_batch_data ( BQ_TRANSACTIONS_TABLE_ID , transactions)
365- . await ?;
349+ self . insert_batch_data ( BQ_BLOCKS_TABLE_ID , blocks) . await ?;
350+ }
351+
352+ if !transactions. is_empty ( ) {
353+ let transactions = transactions
354+ . iter ( )
355+ . map ( |txn| {
356+ let tx_hash = & txn. hash ;
357+
358+ let txn = TransactionRow {
359+ tx_hash : format ! ( "0x{:x}" , tx_hash) ,
360+ transaction : serde_json:: to_value ( txn)
361+ . expect ( "Failed to serialize transaction" ) ,
362+ block_number : txn. block_number . expect ( "Block number not found" ) . 0 . as_u64 ( ) ,
363+ } ;
364+
365+ TableDataInsertAllRequestRows {
366+ insert_id : Some ( format ! ( "0x{:x}" , tx_hash) ) ,
367+ json : serde_json:: to_value ( txn) . expect ( "Failed to serialize transaction" ) ,
368+ }
369+ } )
370+ . collect :: < Vec < _ > > ( ) ;
371+
372+ log:: debug!( "Inserting {} transactions" , transactions. len( ) ) ;
373+
374+ self . insert_batch_data ( BQ_TRANSACTIONS_TABLE_ID , transactions)
375+ . await ?;
376+ }
366377
367378 Ok ( ( ) )
368379 }
@@ -383,10 +394,10 @@ impl DatabaseClient for BigQueryDbClient {
383394 } ,
384395 ] ) ,
385396 query : format ! (
386- "SELECT receipt FROM `{project_id}.{dataset_id}.{table_id}` WHERE tx_hash = @tx_hash" ,
397+ "SELECT exe_result FROM `{project_id}.{dataset_id}.{table_id}` WHERE tx_hash = @tx_hash" ,
387398 project_id = self . project_id,
388399 dataset_id = self . dataset_id,
389- table_id = BQ_RECEIPTS_TABLE_ID ,
400+ table_id = BQ_EXE_RESULTS_TABLE_ID ,
390401 ) ,
391402 ..Default :: default ( )
392403 } ;
@@ -458,10 +469,10 @@ pub struct BlockRow {
458469}
459470
460471#[ derive( Debug , Serialize , Clone ) ]
461- pub struct ReceiptRow {
472+ pub struct ExeResultRow {
462473 tx_hash : String ,
463474 #[ serde( serialize_with = "serialize_json_as_string" ) ]
464- receipt : Value ,
475+ exe_result : Value ,
465476}
466477
467478#[ derive( Debug , Serialize , Clone ) ]
0 commit comments