Skip to content

Commit

Permalink
feat: introduce stacks-network, hiro-system-kit
Browse files Browse the repository at this point in the history
  • Loading branch information
Ludo Galabru committed Oct 11, 2022
1 parent bdf50c9 commit ace6411
Show file tree
Hide file tree
Showing 37 changed files with 1,224 additions and 1,071 deletions.
58 changes: 50 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ members = [
"components/clarity-lsp",
"components/stacks-rpc-client",
"components/stacks-devnet-js",
"components/stacks-network",
"components/chainhook-types-rs",
"components/chainhook-event-observer",
"components/chainhook-db"
"components/chainhook-db",
"components/hiro-system-kit",
]
default-members = ["components/clarinet-cli", "components/chainhook-event-observer"]
1 change: 1 addition & 0 deletions components/chainhook-db/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ redis = "0.21.5"
serde-redis = "0.12.0"
chainhook_event_observer = { package = "chainhook-event-observer", default-features = false, path = "../chainhook-event-observer" }
chainhook_types = { package = "chainhook-types", path = "../chainhook-types-rs" }
hiro_system_kit = { package = "hiro-system-kit", path = "../hiro-system-kit" }
clap = { version = "3.2.8", features = ["derive"], optional = true }
clap_generate = { version = "3.0.3", optional = true }
toml = { version = "0.5.6", features = ["preserve_order"], optional = true }
Expand Down
6 changes: 3 additions & 3 deletions components/chainhook-db/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ use chainhook_event_observer::{
start_event_observer, EventObserverConfig, ObserverCommand, ObserverEvent,
DEFAULT_CONTROL_PORT, DEFAULT_INGESTION_PORT,
},
utils::nestable_block_on,
};
use chainhook_types::{BlockIdentifier, StacksBlockData, StacksTransactionData};
use clap::Parser;
use ctrlc;
use hiro_system_kit;
use std::collections::HashSet;
use std::{collections::HashMap, process, sync::mpsc::channel, thread};

Expand Down Expand Up @@ -113,7 +113,7 @@ pub fn main() {
observer_command_rx,
Some(observer_event_tx),
);
let _ = nestable_block_on(future);
let _ = hiro_system_kit::nestable_block_on(future);
});

loop {
Expand Down Expand Up @@ -182,7 +182,7 @@ pub fn main() {
let proofs = HashMap::new();
if let Some(result) = handle_stacks_hook_action(trigger, &proofs) {
if let StacksChainhookOccurrence::Http(request) = result {
nestable_block_on(request.send()).unwrap();
hiro_system_kit::nestable_block_on(request.send()).unwrap();
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions components/chainhook-event-observer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ serde_derive = "1"
stacks_rpc_client = { package = "stacks-rpc-client", path = "../../components/stacks-rpc-client" }
clarinet_utils = { package = "clarinet-utils", path = "../../components/clarinet-utils" }
clarity_repl = { package = "clarity-repl", path = "../../components/clarity-repl" }
hiro_system_kit = { package = "hiro-system-kit", path = "../../components/hiro-system-kit" }

chainhook_types = { package = "chainhook-types", path = "../chainhook-types-rs" }
rocket = { version = "=0.5.0-rc.2", features = ["json"] }
bitcoincore-rpc = "0.14.0"
Expand Down
6 changes: 3 additions & 3 deletions components/chainhook-event-observer/src/observer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ use crate::chainhooks::{
BitcoinChainhookOccurrencePayload, StacksChainhookOccurrence, StacksChainhookOccurrencePayload,
};
use crate::indexer::{self, Indexer, IndexerConfig};
use crate::utils;
use bitcoincore_rpc::bitcoin::{BlockHash, Txid};
use bitcoincore_rpc::{Auth, Client, RpcApi};
use chainhook_types::{
BitcoinChainEvent, StacksChainEvent, StacksNetwork, StacksTransactionData,
TransactionIdentifier,
};
use clarity_repl::clarity::util::hash::bytes_to_hex;
use hiro_system_kit;
use reqwest::Client as HttpClient;
use rocket::config::{Config, LogLevel};
use rocket::http::Status;
Expand Down Expand Up @@ -300,7 +300,7 @@ pub async fn start_event_observer(
.mount("/", routes)
.launch();

let _ = utils::nestable_block_on(future);
let _ = hiro_system_kit::nestable_block_on(future);
});

let control_config = Config {
Expand Down Expand Up @@ -331,7 +331,7 @@ pub async fn start_event_observer(
.mount("/", routes)
.launch();

let _ = utils::nestable_block_on(future);
let _ = hiro_system_kit::nestable_block_on(future);
});

// This loop is used for handling background jobs, emitted by HTTP calls.
Expand Down
10 changes: 5 additions & 5 deletions components/chainhook-event-observer/src/observer/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ use crate::observer::{
self, start_observer_commands_handler, ApiKey, ChainhookStore, EventHandler,
EventObserverConfig, ObserverCommand,
};
use crate::utils;
use chainhook_types::{
BitcoinChainEvent, BitcoinChainUpdatedWithBlocksData, BitcoinNetwork, StacksBlockData,
StacksBlockUpdate, StacksChainEvent, StacksChainUpdatedWithBlocksData, StacksNetwork,
};
use clarity_repl::clarity::vm::types::QualifiedContractIdentifier;
use hiro_system_kit;
use std::collections::{HashMap, HashSet};
use std::sync::mpsc::{channel, Receiver, Sender};
use std::sync::{Arc, RwLock};
Expand Down Expand Up @@ -153,7 +153,7 @@ fn test_stacks_chainhook_register_deregister() {

let handle = std::thread::spawn(move || {
let (config, chainhook_store) = generate_test_config();
let _ = crate::utils::nestable_block_on(start_observer_commands_handler(
let _ = hiro_system_kit::nestable_block_on(start_observer_commands_handler(
config,
Arc::new(RwLock::new(chainhook_store)),
observer_commands_rx,
Expand Down Expand Up @@ -329,7 +329,7 @@ fn test_stacks_chainhook_auto_deregister() {

let handle = std::thread::spawn(move || {
let (config, chainhook_store) = generate_test_config();
let _ = crate::utils::nestable_block_on(start_observer_commands_handler(
let _ = hiro_system_kit::nestable_block_on(start_observer_commands_handler(
config,
Arc::new(RwLock::new(chainhook_store)),
observer_commands_rx,
Expand Down Expand Up @@ -485,7 +485,7 @@ fn test_bitcoin_chainhook_register_deregister() {

let handle = std::thread::spawn(move || {
let (config, chainhook_store) = generate_test_config();
let _ = crate::utils::nestable_block_on(start_observer_commands_handler(
let _ = hiro_system_kit::nestable_block_on(start_observer_commands_handler(
config,
Arc::new(RwLock::new(chainhook_store)),
observer_commands_rx,
Expand Down Expand Up @@ -681,7 +681,7 @@ fn test_bitcoin_chainhook_auto_deregister() {

let handle = std::thread::spawn(move || {
let (config, chainhook_store) = generate_test_config();
let _ = crate::utils::nestable_block_on(start_observer_commands_handler(
let _ = hiro_system_kit::nestable_block_on(start_observer_commands_handler(
config,
Arc::new(RwLock::new(chainhook_store)),
observer_commands_rx,
Expand Down
14 changes: 0 additions & 14 deletions components/chainhook-event-observer/src/utils/mod.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,6 @@
use chainhook_types::{
BitcoinBlockData, BlockIdentifier, StacksBlockData, StacksMicroblockData, StacksTransactionData,
};
use std::future::Future;
use tokio;

pub fn nestable_block_on<F: Future>(future: F) -> F::Output {
let (handle, _rt) = match tokio::runtime::Handle::try_current() {
Ok(h) => (h, None),
Err(_) => {
let rt = tokio::runtime::Runtime::new().unwrap();
(rt.handle().clone(), Some(rt))
}
};
let response = handle.block_on(async { future.await });
response
}

pub trait AbstractStacksBlock {
fn get_identifier(&self) -> &BlockIdentifier;
Expand Down
20 changes: 7 additions & 13 deletions components/clarinet-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -117,40 +117,34 @@ percent-encoding = "2.1.0"
pin-project = "1.0.5"
indexmap = { version = "1.6.1", features = ["serde"] }
shell-escape = "0.1.5"
tiny-hderive = "0.3.0"
reqwest = { version = "0.11", default-features = false, features = [
"blocking",
"json",
"rustls-tls",
] }
bollard = "0.11.0"
crossterm = "0.22.1"
chrono = "0.4.20"
base58 = "0.2.0"
tracing = "0.1"
tracing-subscriber = "0.3.3"
tracing-appender = "0.2.0"
ctrlc = "3.1.9"
strum = { version = "0.23.0", features = ["derive"] }
bitcoin = "0.28.1"
bitcoincore-rpc = "0.14.0"
bitcoincore-rpc-json = "0.14.0"
segment = { version = "0.1.2", optional = true }
mac_address = { version = "1.1.2", optional = true }
tower-lsp = { version = "0.14.0", optional = true }
hex = "0.4.3"
serde_yaml = "0.8.23"
chainhook_event_observer = { package = "chainhook-event-observer", default-features = false, path = "../chainhook-event-observer" }
chainhook_types = { package = "chainhook-types", path = "../chainhook-types-rs" }
stacks_rpc_client = { package = "stacks-rpc-client", path = "../stacks-rpc-client" }
clarinet_files = { package = "clarinet-files", path = "../clarinet-files", features = ["cli"] }
clarity_lsp = { package = "clarity-lsp", path = "../clarity-lsp", features = ["cli"] }
clarinet_deployments = { package = "clarinet-deployments", path = "../clarinet-deployments", features = ["cli"] }
clarinet_utils = { package = "clarinet-utils", path = "../clarinet-utils" }
clarinet_files = { package = "clarinet-files", path = "../clarinet-files", features = ["cli"] }
clarity_lsp = { package = "clarity-lsp", path = "../clarity-lsp", features = ["cli"] }
clarinet_deployments = { package = "clarinet-deployments", path = "../clarinet-deployments", features = ["cli"] }
hiro_system_kit = { package = "hiro-system-kit", path = "../hiro-system-kit" }
clarinet_utils = { package = "clarinet-utils", path = "../clarinet-utils" }
stacks_network = { package = "stacks-network", path = "../stacks-network" }
num_cpus = "1.13.1"
mio = "=0.8.2"
similar = "2.1.0"
crossbeam-channel = "0.5.6"
chrono = "0.4.20"

[dependencies.tui]
version = "0.18.0"
Expand Down
4 changes: 1 addition & 3 deletions components/clarinet-cli/src/bin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@ mod chainhooks;
mod deployments;
mod frontend;
mod generate;
mod integrate;
pub mod integrate;
mod lsp;
mod runner;
mod types;
mod utils;

use frontend::cli;

Expand Down
Loading

0 comments on commit ace6411

Please sign in to comment.