diff --git a/crates/aleph-types/src/message/aggregate.rs b/crates/aleph-types/src/message/aggregate.rs index beb4c2c..832a5f0 100644 --- a/crates/aleph-types/src/message/aggregate.rs +++ b/crates/aleph-types/src/message/aggregate.rs @@ -84,6 +84,7 @@ mod tests { &address!("0xa1B3bb7d2332383D96b7796B908fB7f7F3c2Be10") ); assert_eq!(&message.content.time, &Timestamp::from(1762518461.4893668)); + assert_eq!(message.sent_at(), &message.content.time); // Check aggregate content fields let aggregate_content = match message.content() { diff --git a/crates/aleph-types/src/message/base_message.rs b/crates/aleph-types/src/message/base_message.rs index f5a40db..59eec80 100644 --- a/crates/aleph-types/src/message/base_message.rs +++ b/crates/aleph-types/src/message/base_message.rs @@ -176,6 +176,19 @@ impl Message { pub fn owner(&self) -> &Address { &self.content.address } + + /// Returns the time at which the message was sent. + /// Notes: + /// * This value is signed by the sender and should not be trusted accordingly. + /// * We prefer `content.time` over `time` as `time` is not part of the signed payload. + pub fn sent_at(&self) -> &Timestamp { + &self.content.time + } + + /// Returns the earliest confirmation time of the message. + pub fn confirmed_at(&self) -> Option<&Timestamp> { + self.confirmations.first().and_then(|c| c.time.as_ref()) + } } // Custom deserializer that uses message_type to efficiently deserialize content diff --git a/crates/aleph-types/src/message/forget.rs b/crates/aleph-types/src/message/forget.rs index eaee321..71743aa 100644 --- a/crates/aleph-types/src/message/forget.rs +++ b/crates/aleph-types/src/message/forget.rs @@ -57,6 +57,7 @@ mod tests { &address!("0xB68B9D4f3771c246233823ed1D3Add451055F9Ef") ); assert_eq!(&message.content.time, &Timestamp::from(1762515432.413)); + assert_eq!(message.sent_at(), &message.content.time); // Check aggregate content fields let forget_content = match message.content() { diff --git a/crates/aleph-types/src/message/instance.rs b/crates/aleph-types/src/message/instance.rs index 2467191..b746645 100644 --- a/crates/aleph-types/src/message/instance.rs +++ b/crates/aleph-types/src/message/instance.rs @@ -69,6 +69,7 @@ mod test { &address!("0x238224C744F4b90b4494516e074D2676ECfC6803") ); assert_eq!(&message.content.time, &Timestamp::from(1762349117.833176)); + assert_eq!(message.sent_at(), &message.content.time); // Check instance content fields let instance_content = match message.content() { @@ -162,6 +163,10 @@ mod test { ); assert!(message.confirmed()); + assert_eq!( + message.confirmed_at(), + message.confirmations[0].time.as_ref() + ); assert_eq!( message.confirmations, vec![MessageConfirmation { @@ -169,8 +174,8 @@ mod test { height: 23733404, hash: "0xda1dd1676b5f08cef019172a7b31de303c86aafe8cb209916cf5ffa2bc5871dc" .to_string(), - time: None, - publisher: None, + time: Some(Timestamp::from(1762349117.833245)), + publisher: Some(address!("0x23eC28598DCeB2f7082Cc3a9D670592DfEd6e0dC")), }] ); } diff --git a/crates/aleph-types/src/message/post.rs b/crates/aleph-types/src/message/post.rs index 95c8d6f..0d2afbb 100644 --- a/crates/aleph-types/src/message/post.rs +++ b/crates/aleph-types/src/message/post.rs @@ -86,6 +86,7 @@ mod tests { &address!("0xB68B9D4f3771c246233823ed1D3Add451055F9Ef") ); assert_eq!(&message.content.time, &Timestamp::from(1762515431.653)); + assert_eq!(message.sent_at(), &message.content.time); // Check aggregate content fields let post_content = match message.content() { @@ -147,6 +148,7 @@ mod tests { &address!("0xB68B9D4f3771c246233823ed1D3Add451055F9Ef") ); assert_eq!(&message.content.time, &Timestamp::from(1762515432.375)); + assert_eq!(message.sent_at(), &message.content.time); // Check aggregate content fields let post_content = match message.content() { diff --git a/crates/aleph-types/src/message/program.rs b/crates/aleph-types/src/message/program.rs index 02dedac..ca8375f 100644 --- a/crates/aleph-types/src/message/program.rs +++ b/crates/aleph-types/src/message/program.rs @@ -128,6 +128,7 @@ mod tests { &Address::from("0x9C2FD74F9CA2B7C4941690316B0Ebc35ce55c885".to_string()) ); assert_eq!(&message.content.time, &Timestamp::from(1757026128.773)); + assert_eq!(message.sent_at(), &message.content.time); // Check program content fields let program_content = match message.content() { @@ -214,6 +215,7 @@ mod tests { // No confirmation on this fixture assert!(!message.confirmed()); + assert!(message.confirmed_at().is_none()); assert!(message.confirmations.is_empty()); } diff --git a/crates/aleph-types/src/message/store.rs b/crates/aleph-types/src/message/store.rs index 7299696..4073ac0 100644 --- a/crates/aleph-types/src/message/store.rs +++ b/crates/aleph-types/src/message/store.rs @@ -86,6 +86,7 @@ mod tests { &Address::from("0x238224C744F4b90b4494516e074D2676ECfC6803".to_string()) ); assert_eq!(&message.content.time, &Timestamp::from(1761047957.7483068)); + assert_eq!(message.sent_at(), &message.content.time); // Check STORE-specific fields match message.content() { diff --git a/fixtures/messages/instance/instance-gpu-payg.json b/fixtures/messages/instance/instance-gpu-payg.json index 74a11c6..b8e4861 100644 --- a/fixtures/messages/instance/instance-gpu-payg.json +++ b/fixtures/messages/instance/instance-gpu-payg.json @@ -72,7 +72,9 @@ { "chain": "ETH", "height": 23733404, - "hash": "0xda1dd1676b5f08cef019172a7b31de303c86aafe8cb209916cf5ffa2bc5871dc" + "hash": "0xda1dd1676b5f08cef019172a7b31de303c86aafe8cb209916cf5ffa2bc5871dc", + "time": 1762349117.833245, + "publisher": "0x23eC28598DCeB2f7082Cc3a9D670592DfEd6e0dC" } ] }