server: mcp + global: refactor

This commit is contained in:
nym21
2025-06-21 12:43:14 +02:00
parent c9e0f9d985
commit c3ae3cb768
92 changed files with 13601 additions and 12554 deletions

View File

@@ -7,7 +7,7 @@ use serde::Serialize;
// use color_eyre::eyre::eyre;
use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
use crate::{CheckedSub, Error};
use crate::{CheckedSub, Error, Printable};
use super::Date;
@@ -93,3 +93,13 @@ impl fmt::Display for DateIndex {
write!(f, "{}", self.0)
}
}
impl Printable for DateIndex {
fn to_string() -> &'static str {
"dateindex"
}
fn to_possible_strings() -> &'static [&'static str] {
&["d", "date", "dateindex"]
}
}

View File

@@ -3,7 +3,7 @@ use std::{fmt::Debug, ops::Add};
use serde::{Deserialize, Serialize};
use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
use crate::CheckedSub;
use crate::{CheckedSub, Printable};
use super::{Date, DateIndex, YearIndex};
@@ -83,3 +83,13 @@ impl From<YearIndex> for DecadeIndex {
}
}
}
impl Printable for DecadeIndex {
fn to_string() -> &'static str {
"decadeindex"
}
fn to_possible_strings() -> &'static [&'static str] {
&["decade", "decadeindex"]
}
}

View File

@@ -6,7 +6,7 @@ use std::{
use serde::{Deserialize, Serialize};
use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
use crate::CheckedSub;
use crate::{CheckedSub, Printable};
use super::Height;
@@ -80,3 +80,13 @@ impl CheckedSub for DifficultyEpoch {
self.0.checked_sub(rhs.0).map(Self)
}
}
impl Printable for DifficultyEpoch {
fn to_string() -> &'static str {
"difficultyepoch"
}
fn to_possible_strings() -> &'static [&'static str] {
&["difficulty", "difficultyepoch"]
}
}

View File

@@ -6,7 +6,7 @@ use std::{
use serde::{Deserialize, Serialize};
use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
use crate::CheckedSub;
use crate::{CheckedSub, Printable};
use super::Height;
@@ -86,3 +86,13 @@ impl Div<usize> for HalvingEpoch {
Self::from(self.0 as usize / rhs)
}
}
impl Printable for HalvingEpoch {
fn to_string() -> &'static str {
"halvingepoch"
}
fn to_possible_strings() -> &'static [&'static str] {
&["halving", "halvingepoch"]
}
}

View File

@@ -9,7 +9,7 @@ use serde::{Deserialize, Serialize};
use zerocopy::{FromBytes, IntoBytes};
use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
use crate::CheckedSub;
use crate::{CheckedSub, Printable};
use super::StoredUsize;
@@ -209,3 +209,13 @@ impl From<Height> for byteview::ByteView {
Self::new(value.as_bytes())
}
}
impl Printable for Height {
fn to_string() -> &'static str {
"height"
}
fn to_possible_strings() -> &'static [&'static str] {
&["h", "height"]
}
}

View File

@@ -4,7 +4,7 @@ use derive_deref::{Deref, DerefMut};
use serde::Serialize;
use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
use crate::CheckedSub;
use crate::{CheckedSub, Printable};
use super::Vin;
@@ -96,3 +96,13 @@ impl From<InputIndex> for usize {
value.0 as usize
}
}
impl Printable for InputIndex {
fn to_string() -> &'static str {
"inputindex"
}
fn to_possible_strings() -> &'static [&'static str] {
&["in", "inputindex"]
}
}

View File

@@ -3,7 +3,7 @@ use std::{fmt::Debug, ops::Add};
use serde::{Deserialize, Serialize};
use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
use crate::CheckedSub;
use crate::{CheckedSub, Printable};
use super::{Date, DateIndex, YearIndex};
@@ -68,3 +68,13 @@ impl CheckedSub for MonthIndex {
self.0.checked_sub(rhs.0).map(Self)
}
}
impl Printable for MonthIndex {
fn to_string() -> &'static str {
"monthindex"
}
fn to_possible_strings() -> &'static [&'static str] {
&["m", "month", "monthindex"]
}
}

View File

@@ -4,7 +4,7 @@ use derive_deref::{Deref, DerefMut};
use serde::Serialize;
use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
use crate::CheckedSub;
use crate::{CheckedSub, Printable};
use super::Vout;
@@ -102,3 +102,13 @@ impl From<OutputIndex> for usize {
value.0 as usize
}
}
impl Printable for OutputIndex {
fn to_string() -> &'static str {
"outputindex"
}
fn to_possible_strings() -> &'static [&'static str] {
&["out", "outputindex"]
}
}

View File

@@ -6,7 +6,7 @@ use serde::Serialize;
use zerocopy::{FromBytes, IntoBytes};
use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
use crate::CheckedSub;
use crate::{CheckedSub, Printable};
#[derive(
Debug,
@@ -137,6 +137,15 @@ impl CheckedSub<EmptyOutputIndex> for EmptyOutputIndex {
self.0.0.checked_sub(rhs.0.0).map(OutputTypeIndex).map(Self)
}
}
impl Printable for EmptyOutputIndex {
fn to_string() -> &'static str {
"emptyoutputindex"
}
fn to_possible_strings() -> &'static [&'static str] {
&["empty", "emptyoutputindex"]
}
}
#[derive(
Debug,
@@ -183,6 +192,16 @@ impl CheckedSub<P2MSIndex> for P2MSIndex {
}
}
impl Printable for P2MSIndex {
fn to_string() -> &'static str {
"p2msindex"
}
fn to_possible_strings() -> &'static [&'static str] {
&["ms", "p2ms", "p2msindex"]
}
}
#[derive(
Debug,
PartialEq,
@@ -228,6 +247,16 @@ impl CheckedSub<P2AIndex> for P2AIndex {
}
}
impl Printable for P2AIndex {
fn to_string() -> &'static str {
"p2aindex"
}
fn to_possible_strings() -> &'static [&'static str] {
&["a", "p2a", "p2aindex"]
}
}
#[derive(
Debug,
PartialEq,
@@ -273,6 +302,16 @@ impl CheckedSub<OpReturnIndex> for OpReturnIndex {
}
}
impl Printable for OpReturnIndex {
fn to_string() -> &'static str {
"opreturnindex"
}
fn to_possible_strings() -> &'static [&'static str] {
&["op", "opreturn", "opreturnindex"]
}
}
#[derive(
Debug,
PartialEq,
@@ -318,6 +357,16 @@ impl CheckedSub<UnknownOutputIndex> for UnknownOutputIndex {
}
}
impl Printable for UnknownOutputIndex {
fn to_string() -> &'static str {
"unknownoutputindex"
}
fn to_possible_strings() -> &'static [&'static str] {
&["unknown", "unknownoutputindex"]
}
}
#[derive(
Debug,
PartialEq,
@@ -363,6 +412,16 @@ impl CheckedSub<P2PK33Index> for P2PK33Index {
}
}
impl Printable for P2PK33Index {
fn to_string() -> &'static str {
"p2pk33index"
}
fn to_possible_strings() -> &'static [&'static str] {
&["pk33", "p2pk33", "p2pk33index"]
}
}
#[derive(
Debug,
PartialEq,
@@ -408,6 +467,15 @@ impl CheckedSub<P2PK65Index> for P2PK65Index {
}
}
impl Printable for P2PK65Index {
fn to_string() -> &'static str {
"p2pk65index"
}
fn to_possible_strings() -> &'static [&'static str] {
&["pk65", "p2pk65", "p2pk65index"]
}
}
#[derive(
Debug,
PartialEq,
@@ -453,6 +521,16 @@ impl CheckedSub<P2PKHIndex> for P2PKHIndex {
}
}
impl Printable for P2PKHIndex {
fn to_string() -> &'static str {
"p2pkhindex"
}
fn to_possible_strings() -> &'static [&'static str] {
&["pkh", "p2pkh", "p2pkhindex"]
}
}
#[derive(
Debug,
PartialEq,
@@ -498,6 +576,16 @@ impl CheckedSub<P2SHIndex> for P2SHIndex {
}
}
impl Printable for P2SHIndex {
fn to_string() -> &'static str {
"p2shindex"
}
fn to_possible_strings() -> &'static [&'static str] {
&["sh", "p2sh", "p2shindex"]
}
}
#[derive(
Debug,
PartialEq,
@@ -543,6 +631,16 @@ impl CheckedSub<P2TRIndex> for P2TRIndex {
}
}
impl Printable for P2TRIndex {
fn to_string() -> &'static str {
"p2trindex"
}
fn to_possible_strings() -> &'static [&'static str] {
&["tr", "p2tr", "p2trindex"]
}
}
#[derive(
Debug,
PartialEq,
@@ -588,6 +686,16 @@ impl CheckedSub<P2WPKHIndex> for P2WPKHIndex {
}
}
impl Printable for P2WPKHIndex {
fn to_string() -> &'static str {
"p2wpkhindex"
}
fn to_possible_strings() -> &'static [&'static str] {
&["wpkh", "p2wpkh", "p2wpkhindex"]
}
}
#[derive(
Debug,
PartialEq,
@@ -632,3 +740,13 @@ impl CheckedSub<P2WSHIndex> for P2WSHIndex {
self.0.0.checked_sub(rhs.0.0).map(OutputTypeIndex).map(Self)
}
}
impl Printable for P2WSHIndex {
fn to_string() -> &'static str {
"p2wshindex"
}
fn to_possible_strings() -> &'static [&'static str] {
&["wsh", "p2wsh", "p2wshindex"]
}
}

View File

@@ -3,7 +3,7 @@ use std::{fmt::Debug, ops::Add};
use serde::{Deserialize, Serialize};
use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
use crate::CheckedSub;
use crate::{CheckedSub, Printable};
use super::MonthIndex;
@@ -62,3 +62,13 @@ impl CheckedSub for QuarterIndex {
self.0.checked_sub(rhs.0).map(Self)
}
}
impl Printable for QuarterIndex {
fn to_string() -> &'static str {
"quarterindex"
}
fn to_possible_strings() -> &'static [&'static str] {
&["q", "quarter", "quarterindex"]
}
}

View File

@@ -8,7 +8,7 @@ use derive_deref::Deref;
use serde::Serialize;
use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
use crate::CheckedSub;
use crate::{CheckedSub, Printable};
use super::{Dollars, StoredF64};
@@ -148,3 +148,13 @@ impl Ord for StoredF32 {
}
}
}
impl Printable for StoredF32 {
fn to_string() -> &'static str {
"f32"
}
fn to_possible_strings() -> &'static [&'static str] {
&["f32"]
}
}

View File

@@ -8,7 +8,7 @@ use derive_deref::Deref;
use serde::Serialize;
use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
use crate::{Bitcoin, CheckedSub, Dollars};
use crate::{Bitcoin, CheckedSub, Dollars, Printable};
#[derive(
Debug, Deref, Default, Clone, Copy, FromBytes, Immutable, IntoBytes, KnownLayout, Serialize,
@@ -120,3 +120,13 @@ impl From<Bitcoin> for StoredF64 {
Self(f64::from(value))
}
}
impl Printable for StoredF64 {
fn to_string() -> &'static str {
"f64"
}
fn to_possible_strings() -> &'static [&'static str] {
&["f64"]
}
}

View File

@@ -4,7 +4,7 @@ use derive_deref::Deref;
use serde::Serialize;
use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
use crate::CheckedSub;
use crate::{CheckedSub, Printable};
use super::{
EmptyOutputIndex, OpReturnIndex, P2AIndex, P2MSIndex, P2PK33Index, P2PK65Index, P2PKHIndex,
@@ -164,3 +164,13 @@ impl From<EmptyOutputIndex> for StoredU32 {
Self::from(usize::from(value))
}
}
impl Printable for StoredU32 {
fn to_string() -> &'static str {
"u32"
}
fn to_possible_strings() -> &'static [&'static str] {
&["u32"]
}
}

View File

@@ -4,7 +4,7 @@ use derive_deref::Deref;
use serde::Serialize;
use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
use crate::CheckedSub;
use crate::{CheckedSub, Printable};
use super::{InputIndex, OutputIndex, TxIndex};
@@ -97,3 +97,13 @@ impl From<OutputIndex> for StoredU64 {
Self(*value)
}
}
impl Printable for StoredU64 {
fn to_string() -> &'static str {
"u64"
}
fn to_possible_strings() -> &'static [&'static str] {
&["u64"]
}
}

View File

@@ -4,7 +4,7 @@ use derive_deref::Deref;
use serde::Serialize;
use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
use crate::CheckedSub;
use crate::{CheckedSub, Printable};
pub type StoredPhantom = StoredU8;
@@ -93,3 +93,13 @@ impl From<StoredU8> for usize {
value.0 as usize
}
}
impl Printable for StoredU8 {
fn to_string() -> &'static str {
"u8"
}
fn to_possible_strings() -> &'static [&'static str] {
&["u8"]
}
}

View File

@@ -4,7 +4,7 @@ use derive_deref::{Deref, DerefMut};
use serde::Serialize;
use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
use crate::CheckedSub;
use crate::{CheckedSub, Printable};
use super::{
DateIndex, EmptyOutputIndex, Height, InputIndex, MonthIndex, OpReturnIndex, OutputIndex,
@@ -193,3 +193,13 @@ impl From<EmptyOutputIndex> for StoredUsize {
Self::from(usize::from(value))
}
}
impl Printable for StoredUsize {
fn to_string() -> &'static str {
"usize"
}
fn to_possible_strings() -> &'static [&'static str] {
&["usize"]
}
}

View File

@@ -6,7 +6,7 @@ use serde::Serialize;
use zerocopy::{FromBytes, IntoBytes};
use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
use crate::CheckedSub;
use crate::{CheckedSub, Printable};
use super::StoredU32;
@@ -111,3 +111,13 @@ impl From<TxIndex> for StoredU32 {
Self::from(value.0)
}
}
impl Printable for TxIndex {
fn to_string() -> &'static str {
"txindex"
}
fn to_possible_strings() -> &'static [&'static str] {
&["tx", "txindex"]
}
}

View File

@@ -3,7 +3,7 @@ use std::{fmt::Debug, ops::Add};
use serde::{Deserialize, Serialize};
use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
use crate::CheckedSub;
use crate::{CheckedSub, Printable};
use super::{Date, DateIndex};
@@ -86,3 +86,13 @@ impl CheckedSub for WeekIndex {
self.0.checked_sub(rhs.0).map(Self)
}
}
impl Printable for WeekIndex {
fn to_string() -> &'static str {
"weekindex"
}
fn to_possible_strings() -> &'static [&'static str] {
&["w", "week", "weekindex"]
}
}

View File

@@ -3,7 +3,7 @@ use std::{fmt::Debug, ops::Add};
use serde::{Deserialize, Serialize};
use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
use crate::CheckedSub;
use crate::{CheckedSub, Printable};
use super::{Date, DateIndex, MonthIndex};
@@ -80,3 +80,13 @@ impl From<MonthIndex> for YearIndex {
Self((usize::from(value) / 12) as u8)
}
}
impl Printable for YearIndex {
fn to_string() -> &'static str {
"yearindex"
}
fn to_possible_strings() -> &'static [&'static str] {
&["y", "year", "yearindex"]
}
}