Skip to content

Commit

Permalink
fixes for _handle
Browse files Browse the repository at this point in the history
  • Loading branch information
ametel01 committed Sep 2, 2024
1 parent c82ef84 commit 5c6569d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
7 changes: 4 additions & 3 deletions cairo/src/contracts/token/components/token_router.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down Expand Up @@ -162,7 +162,8 @@ pub mod TokenRouterComponent {
}

fn _handle(ref self: ComponentState<TContractState>, 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();

Expand All @@ -173,7 +174,7 @@ pub mod TokenRouterComponent {

fn _transfer_to(
ref self: ComponentState<TContractState>,
recipient: u256,
recipient: ContractAddress,
amount_or_id: u256,
metadata: Bytes
) {}
Expand Down
15 changes: 11 additions & 4 deletions cairo/src/contracts/token/hyp_erc721.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,7 @@ pub mod HypErc721 {
hook_metadata: Option<Bytes>,
hook: Option<ContractAddress>
) -> u256 {
<<<<<<< HEAD
self._transfer_remote(destination, recipient, amount_or_id, value, hook_metadata, hook)
=======
0
>>>>>>> 60f035683c58f5dd1ce629afbed7d457a4f05bc4
}
}

Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit 5c6569d

Please sign in to comment.