Skip to content

Commit

Permalink
refactor: move webhooks module to the sbtc crate (#1163)
Browse files Browse the repository at this point in the history
* move webhooks to sbtc crate

* fix typo

Co-authored-by: Daniel Jordon <[email protected]>

* move webhooks errors to sbtc-wide error enum

---------

Co-authored-by: Daniel Jordon <[email protected]>
  • Loading branch information
MCJOHN974 and djordon authored Dec 19, 2024
1 parent edabe4b commit 891677e
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 4 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions sbtc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ edition = "2021"
default = []
integration-tests = ["testing"]
testing = ["dep:bitcoincore-rpc", "dep:bitcoincore-rpc-json"]
webhooks = ["dep:stackslib", "dep:hex"]

[dependencies]
bitcoin = { workspace = true, features = ["rand-std"] }
bitcoincore-rpc = { workspace = true, optional = true }
bitcoincore-rpc-json = { workspace = true, optional = true }
stackslib = { workspace = true, optional = true }
hex = { workspace = true, optional = true }
clarity.workspace = true
rand.workspace = true
serde.workspace = true
Expand Down
10 changes: 10 additions & 0 deletions sbtc/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,14 @@ pub enum Error {
/// This is the transaction ID of from the request
from_request: Txid,
},

/// This is thrown when failing to parse a hex string into bytes.
#[cfg(feature = "webhooks")]
#[error("could not decode the hex string into bytes: {0}")]
DecodeHexBytes(#[source] hex::FromHexError),
/// An error when attempting to generically decode bytes using the
/// trait implementation.
#[cfg(feature = "webhooks")]
#[error("got an error when attempting to call StacksMessageCodec::consensus_deserialize {0}")]
StacksCodec(#[source] blockstack_lib::codec::Error),
}
3 changes: 3 additions & 0 deletions sbtc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ pub mod deposits;
pub mod error;
pub mod events;

#[cfg(feature = "webhooks")]
pub mod webhooks;

#[cfg(any(test, feature = "testing"))]
pub mod testing;

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion signer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ p256k1.workspace = true
prost.workspace = true
rand.workspace = true
reqwest.workspace = true
sbtc = { path = "../sbtc", default-features = false }
sbtc = { path = "../sbtc", features = ["webhooks"] }
serde.workspace = true
serde_bytes.workspace = true
serde_json.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion signer/src/api/new_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ use crate::emily_client::EmilyInteract;
use crate::error::Error;
use crate::metrics::Metrics;
use crate::metrics::STACKS_BLOCKCHAIN;
use crate::stacks::webhooks::NewBlockEvent;
use crate::storage::model::CompletedDepositEvent;
use crate::storage::model::KeyRotationEvent;
use crate::storage::model::RotateKeysTransaction;
Expand All @@ -36,6 +35,7 @@ use crate::storage::model::WithdrawalCreateEvent;
use crate::storage::model::WithdrawalRejectEvent;
use crate::storage::DbRead;
use crate::storage::DbWrite;
use sbtc::webhooks::NewBlockEvent;

use super::ApiState;
use super::SBTC_REGISTRY_CONTRACT_NAME;
Expand Down
1 change: 0 additions & 1 deletion signer/src/stacks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@ pub mod contracts;
/// Contains structs for signing stacks transactions using the signers'
/// multi-sig wallet.
pub mod wallet;
pub mod webhooks;
2 changes: 1 addition & 1 deletion signer/tests/integration/stacks_events_observer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ use rand::rngs::OsRng;
use sbtc::events::RegistryEvent;
use sbtc::events::TxInfo;
use sbtc::testing::deposits::TxSetup;
use sbtc::webhooks::NewBlockEvent;
use signer::api::new_block_handler;
use signer::api::ApiState;
use signer::bitcoin::MockBitcoinInteract;
use signer::context::Context;
use signer::emily_client::EmilyClient;
use signer::stacks::api::MockStacksInteract;
use signer::stacks::webhooks::NewBlockEvent;
use signer::storage::in_memory::Store;
use signer::storage::model::DepositRequest;
use signer::storage::DbWrite as _;
Expand Down

0 comments on commit 891677e

Please sign in to comment.