11use std:: collections:: BTreeMap ;
2- use std:: fmt;
3- use std:: str:: FromStr ;
42
53use borsh:: schema:: { Declaration , Definition , Fields } ;
64use borsh:: { BorshDeserialize , BorshSchema , BorshSerialize } ;
7- use data_encoding:: HEXUPPER ;
85use ibc:: apps:: nft_transfer:: types:: PORT_ID_STR as NFT_PORT_ID_STR ;
96use ibc:: apps:: nft_transfer:: types:: msgs:: transfer:: MsgTransfer as IbcMsgNftTransfer ;
107use ibc:: apps:: nft_transfer:: types:: packet:: PacketData as NftPacketData ;
@@ -18,13 +15,9 @@ use ibc::core::channel::types::packet::Packet;
1815use ibc:: core:: handler:: types:: msgs:: MsgEnvelope ;
1916use ibc:: core:: host:: types:: identifiers:: PortId ;
2017use ibc:: primitives:: proto:: Protobuf ;
21- use masp_primitives:: transaction:: Transaction as MaspTransaction ;
22- use namada_core:: address:: Address ;
23- use namada_core:: borsh:: BorshSerializeExt ;
24- use namada_core:: key:: common:: PublicKey ;
25- use namada_core:: string_encoding:: StringEncoded ;
2618use serde:: { Deserialize , Serialize } ;
27-
19+ use namada_core:: string_encoding:: StringEncoded ;
20+ use namada_systems:: ibc:: IbcShieldingData ;
2821use crate :: trace;
2922
3023trait Sealed { }
@@ -238,50 +231,11 @@ impl<Transfer: BorshSchema> BorshSchema for MsgNftTransfer<Transfer> {
238231 }
239232}
240233
241- /// Shielding data in IBC packet memo
242- #[ derive( Debug , Clone , BorshDeserialize , BorshSerialize ) ]
243- pub struct IbcShieldingData {
244- /// The MASP transaction that does the shielding
245- pub masp_tx : MaspTransaction ,
246- /// The account that will pay the shielding fee
247- pub shielding_fee_payer : PublicKey ,
248- /// The token that the shielding fee will be paid in
249- pub shielding_fee_token : Address ,
250- }
251-
252- impl From < & IbcShieldingData > for String {
253- fn from ( data : & IbcShieldingData ) -> Self {
254- HEXUPPER . encode ( & data. serialize_to_vec ( ) )
255- }
256- }
257-
258- impl From < IbcShieldingData > for String {
259- fn from ( data : IbcShieldingData ) -> Self {
260- ( & data) . into ( )
261- }
262- }
263-
264- impl fmt:: Display for IbcShieldingData {
265- fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
266- write ! ( f, "{}" , String :: from( self ) )
267- }
268- }
269-
270- impl FromStr for IbcShieldingData {
271- type Err = String ;
272-
273- fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
274- let bytes = HEXUPPER
275- . decode ( s. as_bytes ( ) )
276- . map_err ( |err| err. to_string ( ) ) ?;
277- IbcShieldingData :: try_from_slice ( & bytes) . map_err ( |err| err. to_string ( ) )
278- }
279- }
280234
281235/// Extract MASP transaction from IBC envelope
282236pub fn extract_masp_tx_from_envelope (
283237 envelope : & MsgEnvelope ,
284- ) -> Option < MaspTransaction > {
238+ ) -> Option < IbcShieldingData > {
285239 match envelope {
286240 MsgEnvelope :: Packet ( PacketMsg :: Recv ( msg) ) => {
287241 extract_masp_tx_from_packet ( & msg. packet )
@@ -308,9 +262,11 @@ pub fn decode_ibc_shielding_data(
308262}
309263
310264/// Extract MASP transaction from IBC packet memo
311- pub fn extract_masp_tx_from_packet ( packet : & Packet ) -> Option < MaspTransaction > {
265+ pub fn extract_masp_tx_from_packet (
266+ packet : & Packet ,
267+ ) -> Option < IbcShieldingData > {
312268 let memo = extract_memo_from_packet ( packet, & packet. port_id_on_b ) ?;
313- decode_ibc_shielding_data ( memo) . map ( |data| data . masp_tx )
269+ decode_ibc_shielding_data ( memo)
314270}
315271
316272fn extract_memo_from_packet (
@@ -373,17 +329,3 @@ pub fn extract_traces_from_recv_msg(
373329 _ => Ok ( vec ! [ ] ) ,
374330 }
375331}
376-
377- /// Get IBC memo string from MASP transaction for receiving
378- pub fn convert_masp_tx_to_ibc_memo (
379- transaction : & MaspTransaction ,
380- shielding_fee_payer : PublicKey ,
381- shielding_fee_token : Address ,
382- ) -> String {
383- IbcShieldingData {
384- masp_tx : transaction. clone ( ) ,
385- shielding_fee_payer,
386- shielding_fee_token,
387- }
388- . into ( )
389- }
0 commit comments