mirror of
https://github.com/hinto-janai/cuprate.git
synced 2025-01-22 10:34:37 +00:00
add new tables & types
This commit is contained in:
parent
fdd1689665
commit
d648871966
4 changed files with 123 additions and 8 deletions
|
@ -52,7 +52,7 @@
|
||||||
unused_crate_dependencies,
|
unused_crate_dependencies,
|
||||||
unused_doc_comments,
|
unused_doc_comments,
|
||||||
unused_mut,
|
unused_mut,
|
||||||
missing_docs,
|
//missing_docs,
|
||||||
deprecated,
|
deprecated,
|
||||||
unused_comparisons,
|
unused_comparisons,
|
||||||
nonstandard_style
|
nonstandard_style
|
||||||
|
|
|
@ -16,11 +16,7 @@
|
||||||
//! accessing _all_ tables defined here at once.
|
//! accessing _all_ tables defined here at once.
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------- Import
|
//---------------------------------------------------------------------------------------------------- Import
|
||||||
use crate::types::{
|
use crate::types::{Amount, AmountIndex, AmountIndices, BlockBlob, BlockHash, BlockHeight, BlockInfo, KeyImage, Output, PreRctOutputId, PrunableBlob, PrunableHash, PrunedBlob, RctOutput, TxBlob, TxHash, TxId, UnlockTime, RawChainId, AltChainInfo, AltBlockHeight, CompactAltBlockInfo, AltTransactionInfo};
|
||||||
Amount, AmountIndex, AmountIndices, BlockBlob, BlockHash, BlockHeight, BlockInfo, KeyImage,
|
|
||||||
Output, PreRctOutputId, PrunableBlob, PrunableHash, PrunedBlob, RctOutput, TxBlob, TxHash,
|
|
||||||
TxId, UnlockTime,
|
|
||||||
};
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------- Tables
|
//---------------------------------------------------------------------------------------------------- Tables
|
||||||
// Notes:
|
// Notes:
|
||||||
|
@ -129,6 +125,25 @@ cuprate_database::define_tables! {
|
||||||
/// Transactions without unlock times will not exist in this table.
|
/// Transactions without unlock times will not exist in this table.
|
||||||
14 => TxUnlockTime,
|
14 => TxUnlockTime,
|
||||||
TxId => UnlockTime,
|
TxId => UnlockTime,
|
||||||
|
|
||||||
|
15 => AltChainInfos,
|
||||||
|
RawChainId => AltChainInfo,
|
||||||
|
|
||||||
|
16 => AltBlockHeights,
|
||||||
|
BlockHash => AltBlockHeight,
|
||||||
|
|
||||||
|
17 => AltBlocksInfo,
|
||||||
|
AltBlockHeight => CompactAltBlockInfo,
|
||||||
|
|
||||||
|
18 => AltBlockBlobs,
|
||||||
|
AltBlockHeight => BlockBlob,
|
||||||
|
|
||||||
|
19 => AltTransactionBlobs,
|
||||||
|
TxHash => TxBlob,
|
||||||
|
|
||||||
|
20 => AltTransactionInfos,
|
||||||
|
TxHash => AltTransactionInfo,
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------- Tests
|
//---------------------------------------------------------------------------------------------------- Tests
|
||||||
|
|
|
@ -41,13 +41,15 @@
|
||||||
#![forbid(unsafe_code)] // if you remove this line i will steal your monero
|
#![forbid(unsafe_code)] // if you remove this line i will steal your monero
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------- Import
|
//---------------------------------------------------------------------------------------------------- Import
|
||||||
|
use std::num::NonZero;
|
||||||
|
|
||||||
use bytemuck::{Pod, Zeroable};
|
use bytemuck::{Pod, Zeroable};
|
||||||
|
|
||||||
#[cfg(feature = "serde")]
|
#[cfg(feature = "serde")]
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use cuprate_database::{Key, StorableVec};
|
use cuprate_database::{Key, StorableVec};
|
||||||
|
use cuprate_types::{Chain, ChainId};
|
||||||
//---------------------------------------------------------------------------------------------------- Aliases
|
//---------------------------------------------------------------------------------------------------- Aliases
|
||||||
// These type aliases exist as many Monero-related types are the exact same.
|
// These type aliases exist as many Monero-related types are the exact same.
|
||||||
// For clarity, they're given type aliases as to not confuse them.
|
// For clarity, they're given type aliases as to not confuse them.
|
||||||
|
@ -324,6 +326,103 @@ pub struct RctOutput {
|
||||||
}
|
}
|
||||||
// TODO: local_index?
|
// TODO: local_index?
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------- RawChain
|
||||||
|
#[derive(Copy, Clone, Debug, PartialEq, PartialOrd, Eq, Ord, Hash, Pod, Zeroable)]
|
||||||
|
#[repr(transparent)]
|
||||||
|
pub struct RawChain(u64);
|
||||||
|
|
||||||
|
impl From<Chain> for RawChain {
|
||||||
|
fn from(value: Chain) -> Self {
|
||||||
|
match value {
|
||||||
|
Chain::Main => RawChain(0),
|
||||||
|
Chain::Alt(chain_id) => RawChain(chain_id.0.get()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<RawChain> for Chain {
|
||||||
|
fn from(value: RawChain) -> Self {
|
||||||
|
NonZero::new(value.0)
|
||||||
|
.map(|id| Chain::Alt(ChainId(id)))
|
||||||
|
.unwrap_or(Chain::Main)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------- RawChainId
|
||||||
|
#[derive(Copy, Clone, Debug, PartialEq, PartialOrd, Eq, Ord, Hash, Pod, Zeroable)]
|
||||||
|
#[repr(transparent)]
|
||||||
|
pub struct RawChainId(u64);
|
||||||
|
|
||||||
|
impl From<ChainId> for RawChainId {
|
||||||
|
fn from(value: ChainId) -> Self {
|
||||||
|
RawChainId(value.0.get())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<RawChainId> for ChainId {
|
||||||
|
fn from(value: RawChainId) -> Self {
|
||||||
|
ChainId(NonZero::new(value.0).expect("RawChainId mut not have a value of `0`"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Key for RawChainId {}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------- AltChainInfo
|
||||||
|
#[derive(Copy, Clone, Debug, PartialEq, PartialOrd, Eq, Ord, Hash, Pod, Zeroable)]
|
||||||
|
#[repr(C)]
|
||||||
|
pub struct AltChainInfo {
|
||||||
|
parent_chain: RawChain,
|
||||||
|
common_ancestor_height: u64
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------- AltBlockHeight
|
||||||
|
#[derive(Copy, Clone, Debug, PartialEq, PartialOrd, Eq, Ord, Hash, Pod, Zeroable)]
|
||||||
|
#[repr(C)]
|
||||||
|
pub struct AltBlockHeight {
|
||||||
|
chain_id: u64,
|
||||||
|
height: u64,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Key for AltBlockHeight {}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------- CompactAltBlockInfo
|
||||||
|
#[derive(Copy, Clone, Debug, PartialEq, PartialOrd, Eq, Ord, Hash, Pod, Zeroable)]
|
||||||
|
#[repr(C)]
|
||||||
|
pub struct CompactAltBlockInfo {
|
||||||
|
/// The block's hash.
|
||||||
|
///
|
||||||
|
/// [`Block::hash`].
|
||||||
|
pub block_hash: [u8; 32],
|
||||||
|
/// The block's proof-of-work hash.
|
||||||
|
pub pow_hash: [u8; 32],
|
||||||
|
/// The block's height.
|
||||||
|
pub height: u64,
|
||||||
|
/// The adjusted block size, in bytes.
|
||||||
|
pub weight: usize,
|
||||||
|
/// The long term block weight, which is the weight factored in with previous block weights.
|
||||||
|
pub long_term_weight: usize,
|
||||||
|
/// The cumulative difficulty of all blocks up until and including this block.
|
||||||
|
pub cumulative_difficulty_low: u64,
|
||||||
|
pub cumulative_difficulty_high: u64,
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------- AltTransactionInfo
|
||||||
|
#[derive(Copy, Clone, Debug, PartialEq, PartialOrd, Eq, Ord, Hash, Pod, Zeroable)]
|
||||||
|
#[repr(C)]
|
||||||
|
pub struct AltTransactionInfo {
|
||||||
|
/// The transaction's weight.
|
||||||
|
///
|
||||||
|
/// [`Transaction::weight`].
|
||||||
|
pub tx_weight: usize,
|
||||||
|
/// The transaction's total fees.
|
||||||
|
pub fee: u64,
|
||||||
|
/// The transaction's hash.
|
||||||
|
///
|
||||||
|
/// [`Transaction::hash`].
|
||||||
|
pub tx_hash: [u8; 32],
|
||||||
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------- Tests
|
//---------------------------------------------------------------------------------------------------- Tests
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
//! Various shared data types in Cuprate.
|
//! Various shared data types in Cuprate.
|
||||||
|
|
||||||
|
use std::num::NonZero;
|
||||||
//---------------------------------------------------------------------------------------------------- Import
|
//---------------------------------------------------------------------------------------------------- Import
|
||||||
use curve25519_dalek::edwards::EdwardsPoint;
|
use curve25519_dalek::edwards::EdwardsPoint;
|
||||||
use monero_serai::{
|
use monero_serai::{
|
||||||
|
@ -97,7 +98,7 @@ pub struct VerifiedBlockInformation {
|
||||||
///
|
///
|
||||||
/// The inner value is meaningless.
|
/// The inner value is meaningless.
|
||||||
#[derive(Debug, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
|
#[derive(Debug, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
|
||||||
pub struct ChainId(pub u64);
|
pub struct ChainId(pub NonZero<u64>);
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------- Chain
|
//---------------------------------------------------------------------------------------------------- Chain
|
||||||
/// An identifier for a chain.
|
/// An identifier for a chain.
|
||||||
|
|
Loading…
Reference in a new issue