@@ -4,8 +4,8 @@ use alloy::sol_types::SolValue;
44#[ cfg( not( feature = "library" ) ) ]
55use cosmwasm_std:: entry_point;
66use cosmwasm_std:: {
7- to_json_binary, wasm_execute, Addr , Binary , Deps , DepsMut , Env , Event , MessageInfo , Response ,
8- StdResult ,
7+ to_json_binary, wasm_execute, Addr , Attribute , Binary , Deps , DepsMut , Env , Event , MessageInfo ,
8+ Response , StdResult ,
99} ;
1010use cw_storage_plus:: Item ;
1111use ibc_union_msg:: {
@@ -26,8 +26,9 @@ use ibc_union_msg::{
2626} ;
2727use ibc_union_spec:: {
2828 path:: {
29- BatchPacketsPath , BatchReceiptsPath , ChannelPath , ClientStatePath , ConnectionPath ,
30- ConsensusStatePath , COMMITMENT_MAGIC , COMMITMENT_MAGIC_ACK , COSMWASM_COMMITMENT_PREFIX ,
29+ commit_packets, BatchPacketsPath , BatchReceiptsPath , ChannelPath , ClientStatePath ,
30+ ConnectionPath , ConsensusStatePath , COMMITMENT_MAGIC , COMMITMENT_MAGIC_ACK ,
31+ COSMWASM_COMMITMENT_PREFIX ,
3132 } ,
3233 types:: { Channel , ChannelState , Connection , ConnectionState , Packet } ,
3334} ;
@@ -79,14 +80,20 @@ pub mod events {
7980 pub const TIMEOUT : & str = "packet_timeout" ;
8081 pub const BATCH_SEND : & str = "batch_send" ;
8182 pub const BATCH_ACKS : & str = "batch_acks" ;
83+ pub const WRITE_ACK : & str = "write_ack" ;
8284 }
8385 pub mod attribute {
8486 pub const CLIENT_ID : & str = "client_id" ;
8587 pub const CONNECTION_ID : & str = "connection_id" ;
8688 pub const CHANNEL_ID : & str = "channel_id" ;
8789 pub const COUNTERPARTY_CHANNEL_ID : & str = "counterparty_channel_id" ;
8890 pub const COUNTERPARTY_HEIGHT : & str = "counterparty_height" ;
89- pub const PACKET : & str = "packet" ;
91+ pub const PACKET_HASH : & str = "packet_hash" ;
92+ pub const PACKET_SOURCE_CHANNEL_ID : & str = "packet_source_channel_id" ;
93+ pub const PACKET_DESTINATION_CHANNEL_ID : & str = "packet_destination_channel_id" ;
94+ pub const PACKET_DATA : & str = "packet_data" ;
95+ pub const PACKET_TIMEOUT_HEIGHT : & str = "packet_timeout_height" ;
96+ pub const PACKET_TIMEOUT_TIMESTAMP : & str = "packet_timeout_timestamp" ;
9097 pub const PACKETS : & str = "packets" ;
9198 pub const ACKS : & str = "acks" ;
9299 pub const MAKER : & str = "maker" ;
@@ -103,6 +110,39 @@ pub mod events {
103110 }
104111}
105112
113+ #[ must_use]
114+ fn packet_to_attrs ( packet : & Packet ) -> [ Attribute ; 5 ] {
115+ [
116+ (
117+ events:: attribute:: PACKET_SOURCE_CHANNEL_ID ,
118+ packet. source_channel_id . to_string ( ) ,
119+ ) ,
120+ (
121+ events:: attribute:: PACKET_DESTINATION_CHANNEL_ID ,
122+ packet. destination_channel_id . to_string ( ) ,
123+ ) ,
124+ ( events:: attribute:: PACKET_DATA , packet. data . to_string ( ) ) ,
125+ (
126+ events:: attribute:: PACKET_TIMEOUT_HEIGHT ,
127+ packet. timeout_height . to_string ( ) ,
128+ ) ,
129+ (
130+ events:: attribute:: PACKET_TIMEOUT_TIMESTAMP ,
131+ packet. timeout_timestamp . to_string ( ) ,
132+ ) ,
133+ ]
134+ . map ( Into :: into)
135+ }
136+
137+ #[ must_use]
138+ fn packet_to_attr_hash ( packet : & Packet ) -> Attribute {
139+ (
140+ events:: attribute:: PACKET_HASH ,
141+ commit_packets ( & [ packet. clone ( ) ] ) . to_string ( ) ,
142+ )
143+ . into ( )
144+ }
145+
106146#[ cfg_attr( not( feature = "library" ) , entry_point) ]
107147pub fn execute (
108148 mut deps : DepsMut ,
@@ -584,13 +624,11 @@ fn timeout_packet(
584624
585625 let port_id = CHANNEL_OWNER . load ( deps. storage , source_channel) ?;
586626 Ok ( Response :: new ( )
587- . add_event ( Event :: new ( events:: packet:: TIMEOUT ) . add_attributes ( [
588- (
589- events:: attribute:: PACKET ,
590- serde_json:: to_string ( & packet) . expect ( "packet serialization is infallible; qed;" ) ,
591- ) ,
592- ( events:: attribute:: MAKER , relayer. to_string ( ) ) ,
593- ] ) )
627+ . add_event (
628+ Event :: new ( events:: packet:: TIMEOUT )
629+ . add_attributes ( [ packet_to_attr_hash ( & packet) ] )
630+ . add_attributes ( [ ( events:: attribute:: MAKER , relayer. to_string ( ) ) ] ) ,
631+ )
594632 . add_message ( wasm_execute (
595633 port_id,
596634 & ModuleMsg :: IbcUnionMsg ( IbcUnionMsg :: OnTimeoutPacket {
@@ -637,14 +675,14 @@ fn acknowledge_packet(
637675 let mut messages = Vec :: with_capacity ( packets. len ( ) ) ;
638676 for ( packet, ack) in packets. into_iter ( ) . zip ( acknowledgements) {
639677 mark_packet_as_acknowledged ( deps. branch ( ) , & packet) ?;
640- events. push ( Event :: new ( events :: packet :: ACK ) . add_attributes ( [
641- (
642- events :: attribute :: PACKET ,
643- serde_json :: to_string ( & packet ) . expect ( "packet serialization is infallible; qed;" ) ,
644- ) ,
645- ( events:: attribute:: ACKNOWLEDGEMENT , hex :: encode ( & ack ) ) ,
646- ( events :: attribute :: MAKER , relayer . clone ( ) . to_string ( ) ) ,
647- ] ) ) ;
678+ events. push (
679+ Event :: new ( events :: packet :: ACK )
680+ . add_attributes ( [ packet_to_attr_hash ( & packet ) ] )
681+ . add_attributes ( [
682+ ( events :: attribute :: ACKNOWLEDGEMENT , hex :: encode ( & ack ) ) ,
683+ ( events:: attribute:: MAKER , relayer . clone ( ) . to_string ( ) ) ,
684+ ] ) ,
685+ ) ;
648686 messages. push ( wasm_execute (
649687 port_id. clone ( ) ,
650688 & ModuleMsg :: IbcUnionMsg ( IbcUnionMsg :: OnAcknowledgementPacket {
@@ -1464,15 +1502,12 @@ fn process_receive(
14641502 if !set_packet_receive ( deps. branch ( ) , commitment_key) {
14651503 if intent {
14661504 events. push (
1467- Event :: new ( events:: packet:: INTENT_RECV ) . add_attributes ( [
1468- (
1469- events:: attribute:: PACKET ,
1470- serde_json:: to_string ( & packet)
1471- . expect ( "packet serialization is infallible; qed;" ) ,
1472- ) ,
1473- ( events:: attribute:: MAKER , relayer. clone ( ) ) ,
1474- ( events:: attribute:: MAKER_MSG , hex:: encode ( & relayer_msg) ) ,
1475- ] ) ,
1505+ Event :: new ( events:: packet:: INTENT_RECV )
1506+ . add_attributes ( [ packet_to_attr_hash ( & packet) ] )
1507+ . add_attributes ( [
1508+ ( events:: attribute:: MAKER , relayer. clone ( ) ) ,
1509+ ( events:: attribute:: MAKER_MSG , hex:: encode ( & relayer_msg) ) ,
1510+ ] ) ,
14761511 ) ;
14771512
14781513 messages. push ( wasm_execute (
@@ -1486,15 +1521,12 @@ fn process_receive(
14861521 ) ?) ;
14871522 } else {
14881523 events. push (
1489- Event :: new ( events:: packet:: RECV ) . add_attributes ( [
1490- (
1491- events:: attribute:: PACKET ,
1492- serde_json:: to_string ( & packet)
1493- . expect ( "packet serialization is infallible; qed;" ) ,
1494- ) ,
1495- ( events:: attribute:: MAKER , relayer. clone ( ) ) ,
1496- ( events:: attribute:: MAKER_MSG , hex:: encode ( & relayer_msg) ) ,
1497- ] ) ,
1524+ Event :: new ( events:: packet:: RECV )
1525+ . add_attributes ( [ packet_to_attr_hash ( & packet) ] )
1526+ . add_attributes ( [
1527+ ( events:: attribute:: MAKER , relayer. clone ( ) ) ,
1528+ ( events:: attribute:: MAKER_MSG , hex:: encode ( & relayer_msg) ) ,
1529+ ] ) ,
14981530 ) ;
14991531
15001532 messages. push ( wasm_execute (
@@ -1546,24 +1578,22 @@ fn write_acknowledgement(
15461578 None => return Err ( ContractError :: PacketNotReceived ) ,
15471579 }
15481580
1581+ let acknowledgement_serialized = hex:: encode ( & acknowledgement) ;
1582+
15491583 store_commit (
15501584 deps. branch ( ) ,
15511585 & commitment_key,
1552- & commit_ack ( & acknowledgement. clone ( ) . into ( ) ) ,
1586+ & commit_ack ( & acknowledgement. into ( ) ) ,
15531587 ) ;
15541588
1555- Ok (
1556- Response :: new ( ) . add_event ( Event :: new ( "write_ack" ) . add_attributes ( [
1557- (
1558- events:: attribute:: PACKET ,
1559- serde_json:: to_string ( & packet) . expect ( "packet serialization is infallible; qed;" ) ,
1560- ) ,
1561- (
1589+ Ok ( Response :: new ( ) . add_event (
1590+ Event :: new ( events:: packet:: WRITE_ACK )
1591+ . add_attributes ( [ packet_to_attr_hash ( & packet) ] )
1592+ . add_attributes ( [ (
15621593 events:: attribute:: ACKNOWLEDGEMENT ,
1563- hex:: encode ( acknowledgement) ,
1564- ) ,
1565- ] ) ) ,
1566- )
1594+ acknowledgement_serialized,
1595+ ) ] ) ,
1596+ ) )
15671597}
15681598
15691599fn send_packet (
@@ -1599,6 +1629,9 @@ fn send_packet(
15991629 let serialized_packet =
16001630 serde_json:: to_string ( & packet) . expect ( "packet serialization is infallible; qed;" ) ;
16011631
1632+ let packet_attrs = packet_to_attrs ( & packet) ;
1633+ let packet_attr_hash = packet_to_attr_hash ( & packet) ;
1634+
16021635 let commitment_key = BatchPacketsPath :: from_packets ( & [ packet] ) . key ( ) ;
16031636
16041637 if read_commit ( deps. as_ref ( ) , & commitment_key) . is_some ( ) {
@@ -1610,7 +1643,8 @@ fn send_packet(
16101643 Ok ( Response :: new ( )
16111644 . add_event (
16121645 Event :: new ( events:: packet:: SEND )
1613- . add_attribute ( events:: attribute:: PACKET , & serialized_packet) ,
1646+ . add_attributes ( [ packet_attr_hash] )
1647+ . add_attributes ( packet_attrs) ,
16141648 )
16151649 . set_data ( serialized_packet. as_bytes ( ) ) )
16161650}
0 commit comments