Skip to content

Commit

Permalink
chore: bump version (#558)
Browse files Browse the repository at this point in the history
  • Loading branch information
MicaiahReid committed Apr 6, 2024
1 parent 0ca6f4d commit 13b35a1
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion components/chainhook-cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "chainhook"
version = "1.4.2"
version = "1.5.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
12 changes: 12 additions & 0 deletions components/chainhook-cli/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::storage::{
get_last_block_height_inserted, get_last_unconfirmed_block_height_inserted,
get_stacks_block_at_block_height, insert_unconfirmed_entry_in_stacks_blocks,
is_stacks_block_present, open_readonly_stacks_db_conn, open_readwrite_stacks_db_conn,
set_last_confirmed_insert_key,
};

use chainhook_sdk::chainhooks::types::{
Expand Down Expand Up @@ -634,6 +635,17 @@ async fn handle_command(opts: Opts, ctx: Context) -> Result<(), String> {
}
}
if delete_confirmed {
if let Some(last_inserted) =
get_last_block_height_inserted(&stacks_db_rw, &ctx)
{
if last_inserted == block.block_identifier.index {
set_last_confirmed_insert_key(
&block.parent_block_identifier,
&stacks_db_rw,
&ctx,
)?;
}
}
delete_confirmed_entry_from_stacks_blocks(
&block.block_identifier,
&stacks_db_rw,
Expand Down
25 changes: 17 additions & 8 deletions components/chainhook-cli/src/storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,25 +119,34 @@ fn get_last_unconfirmed_insert_key() -> [u8; 3] {
pub fn insert_entry_in_stacks_blocks(
block: &StacksBlockData,
stacks_db_rw: &DB,
_ctx: &Context,
ctx: &Context,
) -> Result<(), String> {
let key = get_block_key(&block.block_identifier);
let block_bytes = json!(block);
stacks_db_rw
.put(&key, &block_bytes.to_string().as_bytes())
.map_err(|e| format!("unable to insert blocks: {}", e))?;
let previous_last_inserted = get_last_block_height_inserted(stacks_db_rw, _ctx).unwrap_or(0);
let previous_last_inserted = get_last_block_height_inserted(stacks_db_rw, ctx).unwrap_or(0);
if block.block_identifier.index > previous_last_inserted {
stacks_db_rw
.put(
get_last_confirmed_insert_key(),
block.block_identifier.index.to_be_bytes(),
)
.map_err(|e| format!("unable to insert metadata: {}", e))?;
set_last_confirmed_insert_key(&block.block_identifier, stacks_db_rw, ctx)?;
}
Ok(())
}

pub fn set_last_confirmed_insert_key(
block_identifier: &BlockIdentifier,
stacks_db_rw: &DB,
_ctx: &Context,
) -> Result<(), String> {
stacks_db_rw
.put(
get_last_confirmed_insert_key(),
block_identifier.index.to_be_bytes(),
)
.map_err(|e| format!("unable to insert metadata: {}", e))?;
Ok(())
}

pub fn insert_unconfirmed_entry_in_stacks_blocks(
block: &StacksBlockData,
stacks_db_rw: &DB,
Expand Down
2 changes: 1 addition & 1 deletion docs/chainhook-openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"openapi": "3.0.0",
"info": {
"title": "chainhook",
"version": "1.4.2"
"version": "1.5.0"
},
"paths": {
"/ping": {
Expand Down

0 comments on commit 13b35a1

Please sign in to comment.