Skip to content

Commit

Permalink
vm: improve WitnessPos Display implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky committed Oct 12, 2024
1 parent 0f4db24 commit 4d4078a
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/vm/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@
use std::borrow::Borrow;
use std::cell::RefCell;
use std::cmp::Ordering;
use std::fmt::Debug;
use std::fmt::{self, Debug, Display, Formatter};
use std::num::NonZeroU32;
use std::rc::Rc;

use amplify::confinement;
use amplify::num::u24;
use bp::seals::txout::{CloseMethod, ExplicitSeal, VerifyError, Witness};
use bp::{dbc, Tx, Txid};
use chrono::{MappedLocalTime, TimeZone, Utc};
use commit_verify::mpc;
use single_use_seals::SealWitness;
use strict_encoding::{StrictDecode, StrictDumb, StrictEncode};
Expand Down Expand Up @@ -290,15 +291,14 @@ impl<'op> Operation for OrdOpRef<'op> {
}
}

#[derive(Getters, Copy, Clone, PartialEq, Eq, Hash, Debug, Display)]
#[derive(Getters, Copy, Clone, PartialEq, Eq, Hash, Debug)]
#[derive(StrictType, StrictEncode, StrictDecode)]
#[strict_type(lib = LIB_NAME_RGB_LOGIC)]
#[cfg_attr(
feature = "serde",
derive(Serialize, Deserialize),
serde(crate = "serde_crate", rename_all = "camelCase")
)]
#[display("{height}@{timestamp}")]
pub struct WitnessPos {
#[getter(as_copy)]
layer1: Layer1,
Expand Down Expand Up @@ -389,6 +389,16 @@ impl Ord for WitnessPos {
}

Check warning on line 389 in src/vm/contract.rs

View check run for this annotation

Codecov / codecov/patch

src/vm/contract.rs#L389

Added line #L389 was not covered by tests
}

impl Display for WitnessPos {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(f, "{}:{}, ", self.layer1, self.height)?;
match Utc.timestamp_opt(self.timestamp, 0) {
MappedLocalTime::Single(time) => write!(f, "{}", time.format("%Y-%m-%d %H:%M:%S")),
_ => f.write_str("invalid timestamp"),

Check warning on line 397 in src/vm/contract.rs

View check run for this annotation

Codecov / codecov/patch

src/vm/contract.rs#L393-L397

Added lines #L393 - L397 were not covered by tests
}
}
}

/// RGB consensus information about the status of a witness transaction. This
/// information is used in ordering state transition and state extension
/// processing in the AluVM during the validation, as well as consensus ordering
Expand Down

0 comments on commit 4d4078a

Please sign in to comment.