-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #190 from joel-u410/joel/record-block-details
enhancement: store blocks while crawling transactions and chain
- Loading branch information
Showing
19 changed files
with
378 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
use anyhow::Context; | ||
use diesel::upsert::excluded; | ||
use diesel::{ExpressionMethods, PgConnection, RunQueryDsl}; | ||
use orm::blocks::BlockInsertDb; | ||
use orm::schema::blocks; | ||
use shared::block::Block; | ||
use tendermint_rpc::endpoint::block::Response as TendermintBlockResponse; | ||
|
||
pub fn upsert_block( | ||
transaction_conn: &mut PgConnection, | ||
block: Block, | ||
tm_block_response: TendermintBlockResponse, | ||
) -> anyhow::Result<()> { | ||
diesel::insert_into(blocks::table) | ||
.values::<&BlockInsertDb>(&BlockInsertDb::from(( | ||
block, | ||
tm_block_response, | ||
))) | ||
.on_conflict(blocks::height) | ||
.do_update() | ||
.set(( | ||
blocks::hash.eq(excluded(blocks::hash)), | ||
blocks::app_hash.eq(excluded(blocks::app_hash)), | ||
blocks::timestamp.eq(excluded(blocks::timestamp)), | ||
blocks::proposer.eq(excluded(blocks::proposer)), | ||
blocks::epoch.eq(excluded(blocks::epoch)), | ||
)) | ||
.execute(transaction_conn) | ||
.context("Failed to insert block in db")?; | ||
|
||
anyhow::Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
pub mod balance; | ||
pub mod block; | ||
pub mod crawler_state; | ||
pub mod gov; | ||
pub mod pos; | ||
|
Oops, something went wrong.