Skip to content

Commit

Permalink
fix: check print predicate for contained value
Browse files Browse the repository at this point in the history
  • Loading branch information
Ludo Galabru committed Nov 2, 2022
1 parent 7d9cb8d commit 0f5956d
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion components/chainhook-event-observer/src/chainhooks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,11 @@ pub fn evaluate_stacks_transaction_predicate_on_transaction<'a>(
match event {
StacksTransactionEvent::SmartContractEvent(actual) => {
if actual.contract_identifier == expected_event.contract_identifier {
return true;
let value =
format!("{}", expect_decoded_clarity_value(&actual.hex_value));
if value.contains(&expected_event.contains) {
return true;
}
}
}
_ => {}
Expand Down Expand Up @@ -673,6 +677,16 @@ pub fn serialized_event_with_decoded_clarity_value(
}
}

pub fn expect_decoded_clarity_value(hex_value: &str) -> ClarityValue {
let hex_value = hex_value
.strip_prefix("0x")
.expect("unable to decode clarity value emitted by stacks-node");
let value_bytes =
hex_bytes(&hex_value).expect("unable to decode clarity value emitted by stacks-node");
ClarityValue::consensus_deserialize(&mut Cursor::new(&value_bytes))
.expect("unable to decode clarity value emitted by stacks-node")
}

pub fn serialized_decoded_clarity_value(hex_value: &str) -> serde_json::Value {
let hex_value = match hex_value.strip_prefix("0x") {
Some(hex_value) => hex_value,
Expand Down

0 comments on commit 0f5956d

Please sign in to comment.