Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update ordhook schemas #458

Merged
merged 12 commits into from
Nov 17, 2023
1,702 changes: 692 additions & 1,010 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions components/chainhook-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ redis = "0.21.5"
serde-redis = "0.12.0"
hex = "0.4.3"
rand = "0.8.5"
chainhook-sdk = { version = "0.10.0", default-features = false, features = [
chainhook-sdk = { version = "0.11.0", default-features = false, features = [
"zeromq",
], path = "../chainhook-sdk" }
clarinet-files = "2"
hiro-system-kit = "0.3.1"
# clarinet-files = { path = "../../../clarinet/components/clarinet-files" }
# hiro-system-kit = { path = "../../../clarinet/components/hiro-system-kit" }
Expand Down
3 changes: 3 additions & 0 deletions components/chainhook-cli/src/config/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ pub enum NetworkConfigMode {
Devnet,
Testnet,
Mainnet,
Signet,
}

impl NetworkConfigMode {
Expand All @@ -68,13 +69,15 @@ impl NetworkConfigMode {
BitcoinNetwork::Regtest => NetworkConfigMode::Devnet,
BitcoinNetwork::Testnet => NetworkConfigMode::Testnet,
BitcoinNetwork::Mainnet => NetworkConfigMode::Mainnet,
BitcoinNetwork::Signet => NetworkConfigMode::Signet,
}
}
pub fn as_str(&self) -> &str {
match self {
NetworkConfigMode::Devnet => "devnet",
NetworkConfigMode::Testnet => "testnet",
NetworkConfigMode::Mainnet => "mainnet",
NetworkConfigMode::Signet => "signet",
}
}
}
4 changes: 2 additions & 2 deletions components/chainhook-sdk/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "chainhook-sdk"
version = "0.10.2"
version = "0.11.0"
description = "Stateless Transaction Indexing Engine for Stacks and Bitcoin"
license = "GPL-3.0"
edition = "2021"
Expand All @@ -18,7 +18,7 @@ hiro-system-kit = { version = "0.3.1", optional = true }
# stacks-rpc-client = { version = "1", path = "../../../clarinet/components/stacks-rpc-client" }
# clarinet-utils = { version = "1", path = "../../../clarinet/components/clarinet-utils" }
# hiro-system-kit = { version = "0.1.0", path = "../../../clarinet/components/hiro-system-kit" }
chainhook-types = { version = "1.1.0", path = "../chainhook-types-rs" }
chainhook-types = { version = "1.2.0", path = "../chainhook-types-rs" }
rocket = { version = "=0.5.0-rc.3", features = ["json"] }
bitcoincore-rpc = "0.16.0"
bitcoincore-rpc-json = "0.16.0"
Expand Down
2 changes: 2 additions & 0 deletions components/chainhook-sdk/src/chainhooks/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,7 @@ pub fn get_stacks_canonical_magic_bytes(network: &BitcoinNetwork) -> [u8; 2] {
BitcoinNetwork::Mainnet => *b"X2",
BitcoinNetwork::Testnet => *b"T2",
BitcoinNetwork::Regtest => *b"id",
BitcoinNetwork::Signet => unreachable!()
}
}

Expand Down Expand Up @@ -597,6 +598,7 @@ pub fn get_canonical_pox_config(network: &BitcoinNetwork) -> PoxConfig {
BitcoinNetwork::Mainnet => POX_CONFIG_MAINNET,
BitcoinNetwork::Testnet => POX_CONFIG_TESTNET,
BitcoinNetwork::Regtest => POX_CONFIG_DEVNET,
BitcoinNetwork::Signet => unreachable!(),
}
}

Expand Down
53 changes: 53 additions & 0 deletions components/chainhook-sdk/src/observer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,59 @@ impl EventObserverConfig {
_ => unreachable!(),
}
}

pub fn new_using_overrides(
overrides: Option<&EventObserverConfigOverrides>,
) -> Result<EventObserverConfig, String> {
let bitcoin_network =
if let Some(network) = overrides.and_then(|c| c.bitcoin_network.as_ref()) {
BitcoinNetwork::from_str(network)?
} else {
BitcoinNetwork::Regtest
};

let stacks_network =
if let Some(network) = overrides.and_then(|c| c.stacks_network.as_ref()) {
StacksNetwork::from_str(network)?
} else {
StacksNetwork::Devnet
};

let config = EventObserverConfig {
bitcoin_rpc_proxy_enabled: false,
chainhook_config: None,
ingestion_port: overrides
.and_then(|c| c.ingestion_port)
.unwrap_or(DEFAULT_INGESTION_PORT),
bitcoind_rpc_username: overrides
.and_then(|c| c.bitcoind_rpc_username.clone())
.unwrap_or("devnet".to_string()),
bitcoind_rpc_password: overrides
.and_then(|c| c.bitcoind_rpc_password.clone())
.unwrap_or("devnet".to_string()),
bitcoind_rpc_url: overrides
.and_then(|c| c.bitcoind_rpc_url.clone())
.unwrap_or("http://localhost:18443".to_string()),
bitcoin_block_signaling: overrides
.and_then(|c| c.bitcoind_zmq_url.as_ref())
.map(|url| BitcoinBlockSignaling::ZeroMQ(url.clone()))
.unwrap_or(BitcoinBlockSignaling::Stacks(
StacksNodeConfig::default_localhost(
overrides
.and_then(|c| c.ingestion_port)
.unwrap_or(DEFAULT_INGESTION_PORT),
),
)),
display_logs: overrides.and_then(|c| c.display_logs).unwrap_or(false),
cache_path: overrides
.and_then(|c| c.cache_path.clone())
.unwrap_or("cache".to_string()),
bitcoin_network,
stacks_network,
data_handler_tx: None,
};
Ok(config)
}
}

#[derive(Deserialize, Debug)]
Expand Down
2 changes: 1 addition & 1 deletion components/chainhook-types-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "chainhook-types"
description = "Bitcoin and Stacks data schemas, based on the Rosetta specification"
license = "MIT"
version = "1.1.0"
version = "1.2.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
14 changes: 12 additions & 2 deletions components/chainhook-types-rs/src/rosetta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,13 +324,21 @@ pub enum OrdinalOperation {
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
pub struct OrdinalInscriptionTransferData {
pub inscription_id: String,
pub updated_address: Option<String>,
pub destination: OrdinalInscriptionTransferDestination,
pub satpoint_pre_transfer: String,
pub satpoint_post_transfer: String,
pub post_transfer_output_value: Option<u64>,
pub tx_index: usize,
}

#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
#[serde(tag = "type", content = "value", rename_all = "snake_case")]
pub enum OrdinalInscriptionTransferDestination {
Transferred(String),
SpentInFees,
Burnt(String),
}

#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
pub enum OrdinalInscriptionCurseType {
Tag(u8),
Expand Down Expand Up @@ -877,6 +885,7 @@ impl StacksNetwork {
pub enum BitcoinNetwork {
Regtest,
Testnet,
Signet,
Mainnet,
}

Expand All @@ -886,9 +895,10 @@ impl BitcoinNetwork {
"regtest" => BitcoinNetwork::Regtest,
"testnet" => BitcoinNetwork::Testnet,
"mainnet" => BitcoinNetwork::Mainnet,
"signet" => BitcoinNetwork::Signet,
_ => {
return Err(format!(
"network '{}' unsupported (mainnet, testnet, regtest)",
"network '{}' unsupported (mainnet, testnet, regtest, signet)",
network
))
}
Expand Down