Skip to content

Commit

Permalink
chore: merge
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelcr committed Oct 24, 2024
1 parent 58e0f2e commit a90e1fa
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
18 changes: 8 additions & 10 deletions components/chainhook-cli/src/storage/signers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,11 @@ pub fn initialize_signers_db(base_dir: &PathBuf, ctx: &Context) -> Result<Connec
message_id INTEGER NOT NULL,
accepted BOOLEAN NOT NULL,
signer_signature_hash TEXT NOT NULL,
accepted_sig TEXT,
signature TEXT NOT NULL,
rejected_reason TEXT,
rejected_reason_code TEXT,
rejected_validation_failed_code TEXT,
rejected_chain_id INTEGER,
rejected_signature TEXT,
UNIQUE(message_id),
FOREIGN KEY (message_id) REFERENCES messages(id) ON DELETE CASCADE
)",
Expand Down Expand Up @@ -201,22 +200,22 @@ pub fn store_signer_db_messages(
let mut stmt = db_tx
.prepare(
"INSERT INTO block_responses
(message_id, accepted, signer_signature_hash, accepted_sig)
(message_id, accepted, signer_signature_hash, signature)
VALUES (?,TRUE,?,?)",
)
.map_err(|e| format!("unable to prepare statement: {e}"))?;
stmt.execute(rusqlite::params![
&message_id,
&response.signer_signature_hash,
&response.sig,
&response.signature,
])
.map_err(|e| format!("unable to write block pushed: {e}"))?;
}
BlockResponseData::Rejected(response) => {
let mut validation_code: Option<&str> = None;
let reason_code = match &response.reason_code {
BlockRejectReasonCode::ValidationFailed(code) => {
validation_code = match code {
BlockRejectReasonCode::ValidationFailed{ validation_failed} => {
validation_code = match validation_failed {
BlockValidationFailedCode::BadBlockHash => {
Some("bad_block_hash")
}
Expand Down Expand Up @@ -259,19 +258,18 @@ pub fn store_signer_db_messages(
};
let mut stmt = db_tx
.prepare("INSERT INTO block_responses
(message_id, accepted, signer_signature_hash, rejected_reason,
rejected_reason_code, rejected_validation_failed_code, rejected_chain_id,
rejected_signature)
(message_id, accepted, signer_signature_hash, signature, rejected_reason,
rejected_reason_code, rejected_validation_failed_code, rejected_chain_id)
VALUES (?,FALSE,?,?,?,?,?,?)")
.map_err(|e| format!("unable to prepare statement: {e}"))?;
stmt.execute(rusqlite::params![
&message_id,
&response.signer_signature_hash,
&response.signature,
&response.reason,
&reason_code,
&validation_code,
&response.chain_id,
&response.signature,
])
.map_err(|e| format!("unable to write block pushed: {e}"))?;
}
Expand Down
12 changes: 8 additions & 4 deletions components/chainhook-sdk/src/indexer/stacks/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,9 +404,12 @@ fn into_chainhook_event_rejects_invalid_missing_event() {
fn parses_block_response_signer_message() {
use chainhook_types::{BlockResponseData, StacksSignerMessage};

use crate::indexer::stacks::{
NewSignerModifiedSlot, NewStackerDbChunkIssuerId, NewStackerDbChunkIssuerSlots,
NewStackerDbChunks, NewStackerDbChunksContractId,
use crate::{
indexer::stacks::{
NewSignerModifiedSlot, NewStackerDbChunkIssuerId, NewStackerDbChunkIssuerSlots,
NewStackerDbChunks, NewStackerDbChunksContractId,
},
utils::Context,
};

use super::standardize_stacks_stackerdb_chunks;
Expand All @@ -426,7 +429,8 @@ fn parses_block_response_signer_message() {
slot_version: 11,
}],
};
let parsed_chunk = standardize_stacks_stackerdb_chunks(&new_chunks).unwrap();
let ctx = &Context::empty();
let parsed_chunk = standardize_stacks_stackerdb_chunks(&new_chunks, ctx).unwrap();

assert_eq!(parsed_chunk.len(), 1);
let message = &parsed_chunk[0];
Expand Down

0 comments on commit a90e1fa

Please sign in to comment.