mirror of
https://github.com/serai-dex/serai.git
synced 2024-11-17 01:17:36 +00:00
Implement a pretty Debug for various objects
This commit is contained in:
parent
2641b83b3e
commit
22da7aedde
5 changed files with 65 additions and 6 deletions
|
@ -170,12 +170,18 @@ impl Protocol {
|
||||||
|
|
||||||
/// Transparent structure representing a Pedersen commitment's contents.
|
/// Transparent structure representing a Pedersen commitment's contents.
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
#[derive(Clone, PartialEq, Eq, Debug, Zeroize, ZeroizeOnDrop)]
|
#[derive(Clone, PartialEq, Eq, Zeroize, ZeroizeOnDrop)]
|
||||||
pub struct Commitment {
|
pub struct Commitment {
|
||||||
pub mask: Scalar,
|
pub mask: Scalar,
|
||||||
pub amount: u64,
|
pub amount: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl core::fmt::Debug for Commitment {
|
||||||
|
fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> Result<(), core::fmt::Error> {
|
||||||
|
fmt.debug_struct("Commitment").field("amount", &self.amount).finish_non_exhaustive()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Commitment {
|
impl Commitment {
|
||||||
/// A commitment to zero, defined with a mask of 1 (as to not be the identity).
|
/// A commitment to zero, defined with a mask of 1 (as to not be the identity).
|
||||||
pub fn zero() -> Commitment {
|
pub fn zero() -> Commitment {
|
||||||
|
|
|
@ -182,13 +182,26 @@ impl<B: AddressBytes> AddressMeta<B> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A Monero address, composed of metadata and a spend/view key.
|
/// A Monero address, composed of metadata and a spend/view key.
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
|
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||||
pub struct Address<B: AddressBytes> {
|
pub struct Address<B: AddressBytes> {
|
||||||
pub meta: AddressMeta<B>,
|
pub meta: AddressMeta<B>,
|
||||||
pub spend: EdwardsPoint,
|
pub spend: EdwardsPoint,
|
||||||
pub view: EdwardsPoint,
|
pub view: EdwardsPoint,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<B: AddressBytes> core::fmt::Debug for Address<B> {
|
||||||
|
fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> Result<(), core::fmt::Error> {
|
||||||
|
fmt
|
||||||
|
.debug_struct("Address")
|
||||||
|
.field("meta", &self.meta)
|
||||||
|
.field("spend", &hex::encode(self.spend.compress().0))
|
||||||
|
.field("view", &hex::encode(self.view.compress().0))
|
||||||
|
// This is not a real field yet is the most valuable thing to know when debugging
|
||||||
|
.field("(address)", &self.to_string())
|
||||||
|
.finish()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<B: AddressBytes> Zeroize for Address<B> {
|
impl<B: AddressBytes> Zeroize for Address<B> {
|
||||||
fn zeroize(&mut self) {
|
fn zeroize(&mut self) {
|
||||||
self.meta.zeroize();
|
self.meta.zeroize();
|
||||||
|
|
|
@ -20,12 +20,18 @@ use crate::{
|
||||||
};
|
};
|
||||||
|
|
||||||
/// An absolute output ID, defined as its transaction hash and output index.
|
/// An absolute output ID, defined as its transaction hash and output index.
|
||||||
#[derive(Clone, PartialEq, Eq, Debug, Zeroize, ZeroizeOnDrop)]
|
#[derive(Clone, PartialEq, Eq, Zeroize, ZeroizeOnDrop)]
|
||||||
pub struct AbsoluteId {
|
pub struct AbsoluteId {
|
||||||
pub tx: [u8; 32],
|
pub tx: [u8; 32],
|
||||||
pub o: u8,
|
pub o: u8,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl core::fmt::Debug for AbsoluteId {
|
||||||
|
fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> Result<(), core::fmt::Error> {
|
||||||
|
fmt.debug_struct("AbsoluteId").field("tx", &hex::encode(self.tx)).field("o", &self.o).finish()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl AbsoluteId {
|
impl AbsoluteId {
|
||||||
pub fn write<W: Write>(&self, w: &mut W) -> io::Result<()> {
|
pub fn write<W: Write>(&self, w: &mut W) -> io::Result<()> {
|
||||||
w.write_all(&self.tx)?;
|
w.write_all(&self.tx)?;
|
||||||
|
@ -44,7 +50,7 @@ impl AbsoluteId {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The data contained with an output.
|
/// The data contained with an output.
|
||||||
#[derive(Clone, PartialEq, Eq, Debug, Zeroize, ZeroizeOnDrop)]
|
#[derive(Clone, PartialEq, Eq, Zeroize, ZeroizeOnDrop)]
|
||||||
pub struct OutputData {
|
pub struct OutputData {
|
||||||
pub key: EdwardsPoint,
|
pub key: EdwardsPoint,
|
||||||
/// Absolute difference between the spend key and the key in this output
|
/// Absolute difference between the spend key and the key in this output
|
||||||
|
@ -52,6 +58,17 @@ pub struct OutputData {
|
||||||
pub commitment: Commitment,
|
pub commitment: Commitment,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl core::fmt::Debug for OutputData {
|
||||||
|
fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> Result<(), core::fmt::Error> {
|
||||||
|
fmt
|
||||||
|
.debug_struct("OutputData")
|
||||||
|
.field("key", &hex::encode(self.key.compress().0))
|
||||||
|
.field("key_offset", &hex::encode(self.key_offset.to_bytes()))
|
||||||
|
.field("commitment", &self.commitment)
|
||||||
|
.finish()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl OutputData {
|
impl OutputData {
|
||||||
pub fn write<W: Write>(&self, w: &mut W) -> io::Result<()> {
|
pub fn write<W: Write>(&self, w: &mut W) -> io::Result<()> {
|
||||||
w.write_all(&self.key.compress().to_bytes())?;
|
w.write_all(&self.key.compress().to_bytes())?;
|
||||||
|
@ -76,7 +93,7 @@ impl OutputData {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The metadata for an output.
|
/// The metadata for an output.
|
||||||
#[derive(Clone, PartialEq, Eq, Debug, Zeroize, ZeroizeOnDrop)]
|
#[derive(Clone, PartialEq, Eq, Zeroize, ZeroizeOnDrop)]
|
||||||
pub struct Metadata {
|
pub struct Metadata {
|
||||||
/// The subaddress this output was sent to.
|
/// The subaddress this output was sent to.
|
||||||
pub subaddress: Option<SubaddressIndex>,
|
pub subaddress: Option<SubaddressIndex>,
|
||||||
|
@ -89,6 +106,17 @@ pub struct Metadata {
|
||||||
pub arbitrary_data: Vec<Vec<u8>>,
|
pub arbitrary_data: Vec<Vec<u8>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl core::fmt::Debug for Metadata {
|
||||||
|
fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> Result<(), core::fmt::Error> {
|
||||||
|
fmt
|
||||||
|
.debug_struct("Metadata")
|
||||||
|
.field("subaddress", &self.subaddress)
|
||||||
|
.field("payment_id", &hex::encode(self.payment_id))
|
||||||
|
.field("arbitrary_data", &self.arbitrary_data.iter().map(hex::encode).collect::<Vec<_>>())
|
||||||
|
.finish()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Metadata {
|
impl Metadata {
|
||||||
pub fn write<W: Write>(&self, w: &mut W) -> io::Result<()> {
|
pub fn write<W: Write>(&self, w: &mut W) -> io::Result<()> {
|
||||||
if let Some(subaddress) = self.subaddress {
|
if let Some(subaddress) = self.subaddress {
|
||||||
|
|
|
@ -702,6 +702,7 @@ async fn run<C: Coin, D: Db, Co: Coordinator>(mut raw_db: D, coin: C, mut coordi
|
||||||
info!("created batch {} ({} instructions)", batch.id, batch.instructions.len());
|
info!("created batch {} ({} instructions)", batch.id, batch.instructions.len());
|
||||||
|
|
||||||
// Start signing this batch
|
// Start signing this batch
|
||||||
|
// TODO: Don't reload both sets of keys in full just to get the Substrate public key
|
||||||
tributary_mutable
|
tributary_mutable
|
||||||
.substrate_signers
|
.substrate_signers
|
||||||
.get_mut(tributary_mutable.key_gen.keys(&key).0.group_key().to_bytes().as_slice())
|
.get_mut(tributary_mutable.key_gen.keys(&key).0.group_key().to_bytes().as_slice())
|
||||||
|
|
|
@ -69,13 +69,24 @@ impl<C: Coin> Payment<C> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, PartialEq, Eq, Debug)]
|
#[derive(Clone, PartialEq, Eq)]
|
||||||
pub struct Plan<C: Coin> {
|
pub struct Plan<C: Coin> {
|
||||||
pub key: <C::Curve as Ciphersuite>::G,
|
pub key: <C::Curve as Ciphersuite>::G,
|
||||||
pub inputs: Vec<C::Output>,
|
pub inputs: Vec<C::Output>,
|
||||||
pub payments: Vec<Payment<C>>,
|
pub payments: Vec<Payment<C>>,
|
||||||
pub change: Option<<C::Curve as Ciphersuite>::G>,
|
pub change: Option<<C::Curve as Ciphersuite>::G>,
|
||||||
}
|
}
|
||||||
|
impl<C: Coin> core::fmt::Debug for Plan<C> {
|
||||||
|
fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> Result<(), core::fmt::Error> {
|
||||||
|
fmt
|
||||||
|
.debug_struct("Plan")
|
||||||
|
.field("key", &hex::encode(self.key.to_bytes()))
|
||||||
|
.field("inputs", &self.inputs)
|
||||||
|
.field("payments", &self.payments)
|
||||||
|
.field("change", &self.change.map(|change| hex::encode(change.to_bytes())))
|
||||||
|
.finish()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<C: Coin> Plan<C> {
|
impl<C: Coin> Plan<C> {
|
||||||
pub fn transcript(&self) -> RecommendedTranscript {
|
pub fn transcript(&self) -> RecommendedTranscript {
|
||||||
|
|
Loading…
Reference in a new issue