Skip to content

Commit

Permalink
fix: parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelcr committed Oct 23, 2024
1 parent 41c7dec commit c211f08
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 16 deletions.
1 change: 1 addition & 0 deletions components/chainhook-cli/src/scan/stacks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ pub async fn scan_stacks_chainstate_via_rocksdb_using_predicate(
chainhook: predicate_spec,
apply: hits_per_blocks,
rollback: vec![],
// TODO(rafaelcr): Query for non consensus events which fall between block timestamps to fill in here
events: vec![]
};
let res = match handle_stacks_hook_action(
Expand Down
5 changes: 3 additions & 2 deletions components/chainhook-cli/src/service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -548,8 +548,9 @@ impl Service {
}
StacksChainEvent::ChainUpdatedWithMicroblocks(_)
| StacksChainEvent::ChainUpdatedWithMicroblocksReorg(_) => {},
StacksChainEvent::ChainUpdatedWithNonConsensusEvents(_data) => {
StacksChainEvent::ChainUpdatedWithNonConsensusEvents(data) => {
// TODO(rafaelcr): Store signer data.
println!("signer message: {:?}", data);
}
},
Err(e) => {
Expand Down Expand Up @@ -620,7 +621,7 @@ impl Service {
StacksChainEvent::ChainUpdatedWithMicroblocks(_)
| StacksChainEvent::ChainUpdatedWithMicroblocksReorg(_) => {},
StacksChainEvent::ChainUpdatedWithNonConsensusEvents(_) => {
// TODO(rafaelcr): Send via HTTP payload.
// TODO(rafaelcr): Expire signer message predicates when appropriate
},
};
update_status_from_report(
Expand Down
2 changes: 2 additions & 0 deletions components/chainhook-cli/src/storage/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
pub mod signers;

use std::collections::VecDeque;
use std::path::PathBuf;

Expand Down
15 changes: 8 additions & 7 deletions components/chainhook-sdk/src/indexer/stacks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,16 +305,17 @@ pub struct ContractReadonlyCall {

#[cfg(feature = "stacks-signers")]
#[derive(Deserialize, Debug)]
pub struct NewStackerDbChunkIssuer {
pub issuer_id: u32,
pub slots: Vec<u32>,
}
pub struct NewStackerDbChunkIssuerId(pub u32);

#[cfg(feature = "stacks-signers")]
#[derive(Deserialize, Debug)]
pub struct NewStackerDbChunkIssuerSlots(pub Vec<u32>);

#[cfg(feature = "stacks-signers")]
#[derive(Deserialize, Debug)]
pub struct NewStackerDbChunksContractId {
pub name: String,
pub issuer: Vec<NewStackerDbChunkIssuer>,
pub issuer: (NewStackerDbChunkIssuerId, NewStackerDbChunkIssuerSlots),
}

#[cfg(feature = "stacks-signers")]
Expand All @@ -323,7 +324,7 @@ pub struct NewSignerModifiedSlot {
pub sig: String,
pub data: String,
pub slot_id: u64,
pub version: u64,
pub slot_version: u64,
}

#[cfg(feature = "stacks-signers")]
Expand Down Expand Up @@ -816,7 +817,7 @@ pub fn get_signer_pubkey_from_stackerdb_chunk_slot(
};

let mut digest_bytes = slot.slot_id.to_be_bytes().to_vec();
digest_bytes.extend(slot.version.to_be_bytes().to_vec());
digest_bytes.extend(slot.slot_version.to_be_bytes().to_vec());
let data_bytes_hashed = Sha512Trunc256Sum::from_data(&data_bytes).to_bytes();
digest_bytes.extend(data_bytes_hashed);
let digest = Sha512Trunc256Sum::from_data(&digest_bytes).to_bytes();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,21 +127,24 @@ pub fn create_new_stackerdb_chunk(
slot_data: String,
) -> crate::indexer::stacks::NewStackerDbChunks {
use crate::indexer::stacks::{
NewSignerModifiedSlot, NewStackerDbChunkIssuer, NewStackerDbChunksContractId,
NewSignerModifiedSlot, NewStackerDbChunkIssuerId, NewStackerDbChunkIssuerSlots,
NewStackerDbChunksContractId,
};
crate::indexer::stacks::NewStackerDbChunks {
contract_id: NewStackerDbChunksContractId {
name: contract_name,
issuer: vec![NewStackerDbChunkIssuer {
issuer_id: 26,
slots: vec![0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
}],
issuer: (
NewStackerDbChunkIssuerId(26),
NewStackerDbChunkIssuerSlots(vec![
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
]),
),
},
modified_slots: vec![NewSignerModifiedSlot {
sig: slot_sig,
data: slot_data,
slot_id: 1,
version: 141,
slot_version: 141,
}],
}
}
2 changes: 1 addition & 1 deletion components/chainhook-sdk/src/observer/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ pub fn handle_new_stacks_block(
success_response()
}

#[cfg(feature = "stacks-signers")]
#[post("/stackerdb_chunks", format = "application/json", data = "<payload>")]
#[cfg(feature = "stacks-signers")]
pub fn handle_stackerdb_chunks(
indexer_rw_lock: &State<Arc<RwLock<Indexer>>>,
payload: Json<JsonValue>,
Expand Down

0 comments on commit c211f08

Please sign in to comment.