Skip to content

Commit

Permalink
fix: config style
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelcr committed Oct 10, 2024
1 parent 6971a82 commit 93df405
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 28 deletions.
2 changes: 1 addition & 1 deletion components/chainhook-cli/src/scan/bitcoin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ pub async fn execute_predicates_action<'a>(
gather_proofs(&trigger, &mut proofs, config, ctx);
}
let predicate_uuid = &trigger.chainhook.uuid;
match handle_bitcoin_hook_action(trigger, &proofs, &config.predicates_config) {
match handle_bitcoin_hook_action(trigger, &proofs, &config) {
Err(e) => {
warn!(
ctx.expect_logger(),
Expand Down
10 changes: 3 additions & 7 deletions components/chainhook-cli/src/scan/stacks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ pub async fn scan_stacks_chainstate_via_rocksdb_using_predicate(
let res = match handle_stacks_hook_action(
trigger,
&proofs,
&config.get_event_observer_config().predicates_config,
&config.get_event_observer_config(),
ctx,
) {
Err(e) => {
Expand Down Expand Up @@ -534,12 +534,8 @@ pub async fn scan_stacks_chainstate_via_csv_using_predicate(
apply: hits_per_blocks,
rollback: vec![],
};
match handle_stacks_hook_action(
trigger,
&proofs,
&config.get_event_observer_config().predicates_config,
ctx,
) {
match handle_stacks_hook_action(trigger, &proofs, &config.get_event_observer_config(), ctx)
{
Err(e) => {
error!(ctx.expect_logger(), "unable to handle action {}", e);
}
Expand Down
6 changes: 3 additions & 3 deletions components/chainhook-sdk/src/chainhooks/bitcoin/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use super::types::{
append_error_context, validate_txid, ChainhookInstance, ExactMatchingRule, HookAction,
MatchingRule, PoxConfig, TxinPredicate,
};
use crate::{observer::PredicatesConfig, utils::{Context, MAX_BLOCK_HEIGHTS_ENTRIES}};
use crate::{observer::EventObserverConfig, utils::{Context, MAX_BLOCK_HEIGHTS_ENTRIES}};

use bitcoincore_rpc_json::bitcoin::{address::Payload, Address};
use chainhook_types::{
Expand Down Expand Up @@ -760,12 +760,12 @@ pub fn serialize_bitcoin_transactions_to_json(
pub fn handle_bitcoin_hook_action<'a>(
trigger: BitcoinTriggerChainhook<'a>,
proofs: &HashMap<&'a TransactionIdentifier, String>,
config: &PredicatesConfig,
config: &EventObserverConfig,
) -> Result<BitcoinChainhookOccurrence, String> {
match &trigger.chainhook.action {
HookAction::HttpPost(http) => {
let mut client_builder = Client::builder();
if let Some(timeout) = config.payload_http_request_timeout_ms {
if let Some(timeout) = config.predicates_config.payload_http_request_timeout_ms {
client_builder = client_builder.timeout(Duration::from_millis(timeout));
}
let client = client_builder
Expand Down
6 changes: 3 additions & 3 deletions components/chainhook-sdk/src/chainhooks/stacks/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::observer::PredicatesConfig;
use crate::observer::EventObserverConfig;
use crate::utils::{AbstractStacksBlock, Context, MAX_BLOCK_HEIGHTS_ENTRIES};

use super::types::{
Expand Down Expand Up @@ -1327,13 +1327,13 @@ pub fn serialize_stacks_payload_to_json<'a>(
pub fn handle_stacks_hook_action<'a>(
trigger: StacksTriggerChainhook<'a>,
proofs: &HashMap<&'a TransactionIdentifier, String>,
config: &PredicatesConfig,
config: &EventObserverConfig,
ctx: &Context,
) -> Result<StacksChainhookOccurrence, String> {
match &trigger.chainhook.action {
HookAction::HttpPost(http) => {
let mut client_builder = Client::builder();
if let Some(timeout) = config.payload_http_request_timeout_ms {
if let Some(timeout) = config.predicates_config.payload_http_request_timeout_ms {
client_builder = client_builder.timeout(Duration::from_millis(timeout));
}
let client = client_builder
Expand Down
7 changes: 4 additions & 3 deletions components/chainhook-sdk/src/chainhooks/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ use super::{
types::{ExactMatchingRule, FileHook},
};
use crate::{
chainhooks::stacks::serialize_stacks_payload_to_json, observer::PredicatesConfig,
chainhooks::stacks::serialize_stacks_payload_to_json,
observer::EventObserverConfig,
utils::Context,
};
use crate::{
Expand Down Expand Up @@ -739,7 +740,7 @@ fn test_stacks_hook_action_noop() {
tracer: false,
};
let occurrence =
handle_stacks_hook_action(trigger, &proofs, &PredicatesConfig::default(), &ctx).unwrap();
handle_stacks_hook_action(trigger, &proofs, &EventObserverConfig::default(), &ctx).unwrap();
if let StacksChainhookOccurrence::Data(data) = occurrence {
assert_eq!(data.apply.len(), 1);
assert_eq!(
Expand Down Expand Up @@ -817,7 +818,7 @@ fn test_stacks_hook_action_file_append() {
tracer: false,
};
let occurrence =
handle_stacks_hook_action(trigger, &proofs, &PredicatesConfig::default(), &ctx).unwrap();
handle_stacks_hook_action(trigger, &proofs, &EventObserverConfig::default(), &ctx).unwrap();
if let StacksChainhookOccurrence::File(path, bytes) = occurrence {
assert_eq!(path, "./".to_string());
let json: JsonValue = serde_json::from_slice(&bytes).unwrap();
Expand Down
13 changes: 2 additions & 11 deletions components/chainhook-sdk/src/observer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1507,11 +1507,7 @@ pub async fn start_observer_commands_handler(
}
for chainhook_to_trigger in chainhooks_to_trigger.into_iter() {
let predicate_uuid = &chainhook_to_trigger.chainhook.uuid;
match handle_bitcoin_hook_action(
chainhook_to_trigger,
&proofs,
&config.predicates_config,
) {
match handle_bitcoin_hook_action(chainhook_to_trigger, &proofs, &config) {
Err(e) => {
// todo: we may want to set predicates that reach this branch as interrupted,
// but for now we will error to see if this problem occurs.
Expand Down Expand Up @@ -1700,12 +1696,7 @@ pub async fn start_observer_commands_handler(
let proofs = HashMap::new();
for chainhook_to_trigger in chainhooks_to_trigger.into_iter() {
let predicate_uuid = &chainhook_to_trigger.chainhook.uuid;
match handle_stacks_hook_action(
chainhook_to_trigger,
&proofs,
&config.predicates_config,
&ctx,
) {
match handle_stacks_hook_action(chainhook_to_trigger, &proofs, &config, &ctx) {
Err(e) => {
ctx.try_log(|logger| {
// todo: we may want to set predicates that reach this branch as interrupted,
Expand Down

0 comments on commit 93df405

Please sign in to comment.