From 5c6569ddafcdd99f61053aa9a9e2a7f7028faedf Mon Sep 17 00:00:00 2001 From: Alex Metelli Date: Mon, 2 Sep 2024 14:44:42 +0800 Subject: [PATCH] fixes for _handle --- .../contracts/token/components/token_router.cairo | 7 ++++--- cairo/src/contracts/token/hyp_erc721.cairo | 15 +++++++++++---- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/cairo/src/contracts/token/components/token_router.cairo b/cairo/src/contracts/token/components/token_router.cairo index 8013cf5..4db6d8d 100644 --- a/cairo/src/contracts/token/components/token_router.cairo +++ b/cairo/src/contracts/token/components/token_router.cairo @@ -53,7 +53,7 @@ pub mod TokenRouterComponent { #[derive(Drop, starknet::Event)] pub struct ReceivedTransferRemote { pub origin: u32, - pub recipient: u256, + pub recipient: ContractAddress, pub amount: u256, } @@ -162,7 +162,8 @@ pub mod TokenRouterComponent { } fn _handle(ref self: ComponentState, origin: u32, message: Bytes) { - let recipient = message.recipient(); + let recipient_felt: felt252 = message.recipient().try_into().expect('u256 to felt failed'); + let recipient: ContractAddress = recipient_felt.try_into().unwrap(); let amount = message.amount(); let metadata = message.metadata(); @@ -173,7 +174,7 @@ pub mod TokenRouterComponent { fn _transfer_to( ref self: ComponentState, - recipient: u256, + recipient: ContractAddress, amount_or_id: u256, metadata: Bytes ) {} diff --git a/cairo/src/contracts/token/hyp_erc721.cairo b/cairo/src/contracts/token/hyp_erc721.cairo index bc8f23c..348caa7 100644 --- a/cairo/src/contracts/token/hyp_erc721.cairo +++ b/cairo/src/contracts/token/hyp_erc721.cairo @@ -135,11 +135,7 @@ pub mod HypErc721 { hook_metadata: Option, hook: Option ) -> u256 { -<<<<<<< HEAD self._transfer_remote(destination, recipient, amount_or_id, value, hook_metadata, hook) -======= - 0 ->>>>>>> 60f035683c58f5dd1ce629afbed7d457a4f05bc4 } } @@ -199,6 +195,17 @@ pub mod HypErc721 { message_id } + fn _handle(ref self: ContractState, origin: u32, message: Bytes) { + let recipient_felt: felt252 = message.recipient().try_into().expect('u256 to felt failed'); + let recipient: ContractAddress = recipient_felt.try_into().unwrap(); + let amount = message.amount(); + let metadata = message.metadata(); + + self._transfer_to(recipient, amount, metadata); + + self.token_router.emit(TokenRouterComponent::ReceivedTransferRemote { origin, recipient, amount, }); + } + fn _transfer_from_sender(ref self: ContractState, amount_or_id: u256) -> Bytes { let token_owner = self.erc721.owner_of(amount_or_id); assert!(token_owner == starknet::get_caller_address(), "Caller is not owner");