Skip to content

Commit

Permalink
Merge pull request #447 from Chia-Network/new-protocol-messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Rigidity authored May 11, 2024
2 parents 3c8cec4 + f800bb4 commit 95b34fa
Show file tree
Hide file tree
Showing 6 changed files with 541 additions and 19 deletions.
16 changes: 16 additions & 0 deletions crates/chia-protocol/src/chia_protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,22 @@ pub enum ProtocolMessageTypes {
RespondBlockHeaders = 88,
RequestFeeEstimates = 89,
RespondFeeEstimates = 90,

// Unfinished block protocol
NewUnfinishedBlock2 = 92,
RequestUnfinishedBlock2 = 93,

// New wallet sync protocol
RequestRemovePuzzleSubscriptions = 94,
RespondRemovePuzzleSubscriptions = 95,
RequestRemoveCoinSubscriptions = 96,
RespondRemoveCoinSubscriptions = 97,
RequestPuzzleState = 98,
RespondPuzzleState = 99,
RejectPuzzleState = 100,
RequestCoinState = 101,
RespondCoinState = 102,
RejectCoinState = 103,
}

#[cfg(feature = "py-bindings")]
Expand Down
12 changes: 12 additions & 0 deletions crates/chia-protocol/src/full_node_protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,15 @@ pub struct RequestPeers {}
pub struct RespondPeers {
peer_list: Vec<TimestampedPeerInfo>,
}

#[streamable(message)]
pub struct NewUnfinishedBlock2 {
unfinished_reward_hash: Bytes32,
foliage_hash: Option<Bytes32>,
}

#[streamable(message)]
pub struct RequestUnfinishedBlock2 {
unfinished_reward_hash: Bytes32,
foliage_hash: Option<Bytes32>,
}
91 changes: 90 additions & 1 deletion crates/chia-protocol/src/wallet_protocol.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use chia_streamable_macro::streamable;
use chia_streamable_macro::{streamable, Streamable};

use crate::Coin;
use crate::CoinState;
Expand Down Expand Up @@ -214,3 +214,92 @@ pub struct RequestFeeEstimates {
pub struct RespondFeeEstimates {
estimates: FeeEstimateGroup,
}

#[streamable(message)]
pub struct RequestRemovePuzzleSubscriptions {
puzzle_hashes: Option<Vec<Bytes32>>,
}

#[streamable(message)]
pub struct RespondRemovePuzzleSubscriptions {
puzzle_hashes: Vec<Bytes32>,
}

#[streamable(message)]
pub struct RequestRemoveCoinSubscriptions {
coin_ids: Option<Vec<Bytes32>>,
}

#[streamable(message)]
pub struct RespondRemoveCoinSubscriptions {
coin_ids: Vec<Bytes32>,
}

#[streamable]
pub struct CoinStateFilters {
include_spent: bool,
include_unspent: bool,
include_hinted: bool,
min_amount: u64,
}

#[streamable(message)]
pub struct RequestPuzzleState {
puzzle_hashes: Vec<Bytes32>,
previous_height: Option<u32>,
header_hash: Bytes32,
filters: CoinStateFilters,
subscribe_when_finished: bool,
}

#[streamable(message)]
pub struct RespondPuzzleState {
puzzle_hashes: Vec<Bytes32>,
height: u32,
header_hash: Bytes32,
is_finished: bool,
coin_states: Vec<CoinState>,
}

#[streamable(message)]
pub struct RejectPuzzleState {
reason: RejectStateReason,
}

#[streamable(message)]
pub struct RequestCoinState {
coin_ids: Vec<Bytes32>,
previous_height: Option<u32>,
header_hash: Bytes32,
subscribe: bool,
}

#[streamable(message)]
pub struct RespondCoinState {
coin_ids: Vec<Bytes32>,
coin_states: Vec<CoinState>,
}

#[streamable(message)]
pub struct RejectCoinState {
reason: RejectStateReason,
}

#[cfg(feature = "py-bindings")]
use chia_py_streamable_macro::{PyJsonDict, PyStreamable};

#[repr(u8)]
#[cfg_attr(feature = "py-bindings", derive(PyJsonDict, PyStreamable))]
#[derive(Streamable, Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
pub enum RejectStateReason {
Reorg = 0,
ExceededSubscriptionLimit = 1,
}

#[cfg(feature = "py-bindings")]
impl chia_traits::ChiaToPython for RejectStateReason {
fn to_python<'a>(&self, py: pyo3::Python<'a>) -> pyo3::PyResult<&'a pyo3::PyAny> {
Ok(pyo3::IntoPy::into_py(*self, py).into_ref(py))
}
}
2 changes: 1 addition & 1 deletion wheel/generate_type_stubs.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
input_dir = crates_dir / "chia-protocol" / "src"

# enums are exposed to python as int
enums = set(["NodeType", "ProtocolMessageTypes"])
enums = set(["NodeType", "ProtocolMessageTypes", "RejectStateReason"])


def transform_type(m: str) -> str:
Expand Down
Loading

0 comments on commit 95b34fa

Please sign in to comment.