-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: request command use fallback neighbours request (#20)
* refactor: added request from neighbours in request command * wip: added request-response test * fix: resolved test * refactor: upd tests * trying to fix compiler bug * fix visibility in tests * refactor: renamed OperatorLever * refactor: moved handling of request-response message to separate function
- Loading branch information
1 parent
3af2daf
commit d49ae98
Showing
5 changed files
with
269 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,20 @@ | ||
use bitcoin::hashes::sha256; | ||
use libp2p::PeerId; | ||
use prost::Message; | ||
use strata_p2p_wire::p2p::v1::{GossipsubMsg, GossipsubMsgKind}; | ||
use strata_p2p_wire::p2p::v1::GossipsubMsg; | ||
|
||
/// Events emitted from P2P to handle from operator side. | ||
/// | ||
/// `DepositSetupPayload` is generic as some implementation details for different BitVM2 | ||
/// applications may vary. The only requirement for them to be decodable from bytes as protobuf | ||
/// message. | ||
#[derive(Clone, Debug)] | ||
pub struct Event<DepositSetupPayload: Message + Clone> { | ||
pub peer_id: PeerId, | ||
pub kind: EventKind<DepositSetupPayload>, | ||
} | ||
|
||
impl<DSP: Message + Clone> Event<DSP> { | ||
pub fn new(peer_id: PeerId, kind: EventKind<DSP>) -> Self { | ||
Self { peer_id, kind } | ||
} | ||
|
||
pub fn scope(&self) -> Option<sha256::Hash> { | ||
// TODD(Velnbur): when other tpes of event are added, remove this one: | ||
#[allow(irrefutable_let_patterns)] | ||
let EventKind::GossipsubMsg(GossipsubMsg { kind, .. }) = &self.kind | ||
else { | ||
return None; | ||
}; | ||
|
||
match kind { | ||
GossipsubMsgKind::Deposit { scope, .. } => Some(*scope), | ||
_ => None, | ||
} | ||
} | ||
} | ||
|
||
#[derive(Debug, Clone)] | ||
pub enum EventKind<DepositSetupPayload: Message + Clone> { | ||
GossipsubMsg(GossipsubMsg<DepositSetupPayload>), | ||
pub enum Event<DepositSetupPayload: Message + Clone> { | ||
ReceivedMessage(GossipsubMsg<DepositSetupPayload>), | ||
} | ||
|
||
impl<DepositSetupPayload: Message + Clone> From<GossipsubMsg<DepositSetupPayload>> | ||
for EventKind<DepositSetupPayload> | ||
for Event<DepositSetupPayload> | ||
{ | ||
fn from(v: GossipsubMsg<DepositSetupPayload>) -> Self { | ||
Self::GossipsubMsg(v) | ||
Self::ReceivedMessage(v) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.