Skip to content

Commit

Permalink
fix: clean expectations
Browse files Browse the repository at this point in the history
  • Loading branch information
lgalabru committed Apr 3, 2023
1 parent 3ee98a8 commit f9e089f
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 46 deletions.
6 changes: 2 additions & 4 deletions components/chainhook-cli/src/config/mod.rs
Expand Up @@ -2,17 +2,15 @@ pub mod file;
pub mod generator;

pub use chainhook_event_observer::indexer::IndexerConfig;
use chainhook_event_observer::observer::{
EventObserverConfig,
};
use chainhook_event_observer::observer::EventObserverConfig;
use chainhook_types::{BitcoinBlockSignaling, BitcoinNetwork, StacksNetwork};
pub use file::ConfigFile;
use std::collections::HashSet;
use std::fs::File;
use std::io::{BufReader, Read};
use std::path::PathBuf;

use crate::service::{DEFAULT_INGESTION_PORT, DEFAULT_CONTROL_PORT};
use crate::service::{DEFAULT_CONTROL_PORT, DEFAULT_INGESTION_PORT};

const DEFAULT_MAINNET_TSV_ARCHIVE: &str =
"https://archive.hiro.so/mainnet/stacks-blockchain-api/mainnet-stacks-blockchain-api-latest.gz";
Expand Down
5 changes: 3 additions & 2 deletions components/chainhook-cli/src/service/mod.rs
Expand Up @@ -115,11 +115,12 @@ impl Service {

info!(
self.ctx.expect_logger(),
"Listening for new blockchain events on port {}", DEFAULT_INGESTION_PORT
"Listening for new blockchain events on port {}", event_observer_config.ingestion_port
);
info!(
self.ctx.expect_logger(),
"Listening for chainhook predicate registrations on port {}", DEFAULT_CONTROL_PORT
"Listening for chainhook predicate registrations on port {}",
event_observer_config.control_port
);

// let ordinal_index = match initialize_ordinal_index(&event_observer_config, None, &self.ctx)
Expand Down
4 changes: 2 additions & 2 deletions components/chainhook-event-observer/Observer.toml
Expand Up @@ -7,8 +7,8 @@ control_port = 20446
ingestion_port = 20445
bitcoind_rpc_username = "devnet"
bitcoind_rpc_password = "devnet"
bitcoin_node_rpc_host = "localhost"
bitcoin_node_rpc_port = 18443
bitcoind_rpc_host = "localhost"
bitcoind_rpc_port = 18443
stacks_node_rpc_host = "localhost"
stacks_node_rpc_port = 20443
operators = ["74738ff5-5367-5958-9aee-98fffdcd1876"]
13 changes: 7 additions & 6 deletions components/chainhook-event-observer/src/chainhooks/stacks/mod.rs
Expand Up @@ -548,15 +548,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))
try_decode_clarity_value(hex_value)
.expect("unable to decode clarity value emitted by stacks-node")
}

pub fn try_decode_clarity_value(hex_value: &str) -> Option<ClarityValue> {
let hex_value = hex_value.strip_prefix("0x")?;
let value_bytes = hex_bytes(&hex_value).ok()?;
ClarityValue::consensus_deserialize(&mut Cursor::new(&value_bytes)).ok()
}

pub fn serialized_decoded_clarity_value(hex_value: &str, ctx: &Context) -> serde_json::Value {
let hex_value = match hex_value.strip_prefix("0x") {
Some(hex_value) => hex_value,
Expand Down
61 changes: 33 additions & 28 deletions components/chainhook-event-observer/src/indexer/bitcoin/mod.rs
Expand Up @@ -296,34 +296,39 @@ pub fn standardize_bitcoin_block(

let mut inputs = vec![];
let mut sats_in = 0;
for input in tx.vin.drain(..) {
for (index, input) in tx.vin.drain(..).enumerate() {
if input.is_coinbase() {
continue;
}
let value = input
.prevout
.as_ref()
.expect("not provided for coinbase txs")
.value
.to_sat();
sats_in += value;
let prevout = input.prevout.as_ref().ok_or(format!(
"error retrieving prevout for transaction {}, input #{} (block #{})",
tx.txid, index, block.height
))?;

let txid = input.txid.as_ref().ok_or(format!(
"error retrieving txid for transaction {}, input #{} (block #{})",
tx.txid, index, block.height
))?;

let vout = input.vout.ok_or(format!(
"error retrieving vout for transaction {}, input #{} (block #{})",
tx.txid, index, block.height
))?;

let script_sig = input.script_sig.ok_or(format!(
"error retrieving script_sig for transaction {}, input #{} (block #{})",
tx.txid, index, block.height
))?;

sats_in += prevout.value.to_sat();
inputs.push(TxIn {
previous_output: OutPoint {
txid: format!(
"0x{}",
input
.txid
.expect("not provided for coinbase txs")
.to_string()
),
vout: input.vout.expect("not provided for coinbase txs"),
block_height: input.prevout.expect("not provided for coinbase txs").height,
value,
txid: format!("0x{}", txid.to_string()),
vout,
block_height: prevout.height,
value: prevout.value.to_sat(),
},
script_sig: format!(
"0x{}",
hex::encode(&input.script_sig.expect("not provided for coinbase txs").hex)
),
script_sig: format!("0x{}", hex::encode(&script_sig.hex)),
sequence: input.sequence,
witness: input
.txinwitness
Expand Down Expand Up @@ -578,15 +583,15 @@ fn try_parse_stacks_operation(
// }
// }

let pox_cycle_id = pox_config.get_pox_cycle_id(block_height);
let pox_cycle_len = pox_config.get_pox_cycle_len();
let pox_cycle_pos = pox_config.get_pos_in_pox_cycle(block_height);
let pox_cycle_index = pox_config.get_pox_cycle_id(block_height);
let pox_cycle_length = pox_config.get_pox_cycle_len();
let pox_cycle_position = pox_config.get_pos_in_pox_cycle(block_height);

StacksBaseChainOperation::BlockCommitted(StacksBlockCommitmentData {
block_hash: res.stacks_block_hash,
pox_cycle_id,
pox_cycle_len,
pox_cycle_pos,
pox_cycle_index,
pox_cycle_length,
pox_cycle_position,
pox_sats_burnt,
pox_sats_transferred,
// mining_address_pre_commit: None,
Expand Down
10 changes: 9 additions & 1 deletion components/chainhook-event-observer/src/observer/mod.rs
Expand Up @@ -544,7 +544,15 @@ pub async fn start_observer_commands_handler(
}
ObserverCommand::ProcessBitcoinBlock(block_data) => {
let new_block =
standardize_bitcoin_block(block_data, &config.bitcoin_network, &ctx)?;
match standardize_bitcoin_block(block_data, &config.bitcoin_network, &ctx) {
Ok(block) => block,
Err(e) => {
ctx.try_log(|logger| {
slog::error!(logger, "Error standardizing block: {}", e)
});
continue;
}
};
bitcoin_block_store.insert(new_block.block_identifier.clone(), new_block);
}
ObserverCommand::CacheBitcoinBlock(block) => {
Expand Down
6 changes: 3 additions & 3 deletions components/chainhook-types-rs/src/rosetta.rs
Expand Up @@ -321,9 +321,9 @@ pub enum StacksBaseChainOperation {
#[serde(rename_all = "snake_case")]
pub struct StacksBlockCommitmentData {
pub block_hash: String,
pub pox_cycle_id: u64,
pub pox_cycle_len: u64,
pub pox_cycle_pos: u64,
pub pox_cycle_index: u64,
pub pox_cycle_length: u64,
pub pox_cycle_position: u64,
pub pox_sats_burnt: u64,
pub pox_sats_transferred: Vec<PoxReward>,
// pub mining_address_pre_commit: Option<String>,
Expand Down

0 comments on commit f9e089f

Please sign in to comment.