cuprate/types/src/service.rs
hinto-janai d503548716
Implement types/ (#94)
* workspace: add `bytemuck` to workspace

* add `types/`

* workspace: add `cuprate-types` to members

* copy `consensus/` types to `types/`

* remove `hard_fork/`

* extended_block_header: impl `Pod`, fix layout

* update `Request/Response`

* impl types

* fix `Response/Request`

* impl `borsh`

* workspace: add `strum`

* service: add `strum` traits

* remove `paste`, `serde_json`, `thiserror`

* remove `strum`

* VerifiedBlockInformation: remove `hf_vote`

* Update Cargo.toml

Co-authored-by: Boog900 <boog900@tutanota.com>

---------

Co-authored-by: Boog900 <boog900@tutanota.com>
2024-03-27 00:46:32 +00:00

88 lines
2.7 KiB
Rust

//! Database [`ReadRequest`]s, [`WriteRequest`]s, and [`Response`]s.
//---------------------------------------------------------------------------------------------------- Import
use std::{
collections::{HashMap, HashSet},
ops::Range,
};
use monero_serai::{block::Block, transaction::Transaction};
#[cfg(feature = "borsh")]
use borsh::{BorshDeserialize, BorshSerialize};
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
use crate::types::{ExtendedBlockHeader, OutputOnChain, VerifiedBlockInformation};
//---------------------------------------------------------------------------------------------------- ReadRequest
/// A read request to the database.
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "borsh", derive(BorshSerialize, BorshDeserialize))]
pub enum ReadRequest {
/// TODO
BlockExtendedHeader(u64),
/// TODO
BlockHash(u64),
/// TODO
BlockExtendedHeaderInRange(Range<u64>),
/// TODO
ChainHeight,
/// TODO
GeneratedCoins,
/// TODO
Outputs(HashMap<u64, HashSet<u64>>),
/// TODO
NumberOutputsWithAmount(Vec<u64>),
/// TODO
CheckKIsNotSpent(HashSet<[u8; 32]>),
/// TODO
BlockBatchInRange(Range<u64>),
}
//---------------------------------------------------------------------------------------------------- WriteRequest
/// A write request to the database.
#[derive(Debug, Clone, PartialEq, Eq)]
// #[cfg_attr(feature = "borsh", derive(BorshSerialize, BorshDeserialize))]
pub enum WriteRequest {
/// TODO
WriteBlock(VerifiedBlockInformation),
}
//---------------------------------------------------------------------------------------------------- Response
/// A response from the database.
#[derive(Debug, Clone, PartialEq, Eq)]
// #[cfg_attr(feature = "borsh", derive(BorshSerialize, BorshDeserialize))]
pub enum Response {
//------------------------------------------------------ Reads
/// TODO
BlockExtendedHeader(ExtendedBlockHeader),
/// TODO
BlockHash([u8; 32]),
/// TODO
BlockExtendedHeaderInRange(Vec<ExtendedBlockHeader>),
/// TODO
ChainHeight(u64, [u8; 32]),
/// TODO
GeneratedCoins(u64),
/// TODO
Outputs(HashMap<u64, HashMap<u64, OutputOnChain>>),
/// TODO
NumberOutputsWithAmount(HashMap<u64, usize>),
/// TODO
/// returns true if key images are spent
CheckKIsNotSpent(bool),
/// TODO
BlockBatchInRange(Vec<(Block, Vec<Transaction>)>),
//------------------------------------------------------ Writes
/// TODO
WriteBlockOk,
}
//---------------------------------------------------------------------------------------------------- Tests
#[cfg(test)]
mod test {
// use super::*;
}