Skip to content

Commit

Permalink
key index + transfer event if recipient alredy link
Browse files Browse the repository at this point in the history
  • Loading branch information
MSghais committed Jun 19, 2024
1 parent 8506728 commit 2ce604f
Showing 1 changed file with 56 additions and 43 deletions.
99 changes: 56 additions & 43 deletions onchain/src/social/deposit.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -40,47 +40,6 @@ pub trait IDepositEscrow<TContractState> {
fn claim(ref self: TContractState, request: SocialRequest<DepositId>);
}

#[derive(Drop, starknet::Event)]
struct ClaimEvent {
#[key]
deposit_id: DepositId,
sender: ContractAddress,
amount: u256,
token_address: ContractAddress,
recipient: NostrPublicKey,
}

#[derive(Drop, starknet::Event)]
struct DepositEvent {
#[key]
deposit_id: DepositId,
sender: ContractAddress,
amount: u256,
token_address: ContractAddress,
recipient: NostrPublicKey,
}

#[derive(Drop, starknet::Event)]
struct CancelEvent {
#[key]
deposit_id: DepositId,
sender: ContractAddress,
amount: u256,
token_address: ContractAddress,
recipient: NostrPublicKey,
}

#[derive(Drop, starknet::Event)]
struct TransferEvent {
#[key]
deposit_id: DepositId,
sender: ContractAddress,
amount: u256,
token_address: ContractAddress,
recipient: NostrPublicKey,
}


#[starknet::contract]
pub mod DepositEscrow {
use core::num::traits::Zero;
Expand All @@ -96,7 +55,6 @@ pub mod DepositEscrow {

use super::{
Deposit, DepositId, DepositResult, IDepositEscrow, NostrPublicKey, DepositIdEncodeImpl,
CancelEvent, DepositEvent, ClaimEvent, TransferEvent
};

impl DepositDefault of Default<Deposit> {
Expand All @@ -119,6 +77,52 @@ pub mod DepositEscrow {
nostr_to_sn: LegacyMap<NostrPublicKey, ContractAddress>
}

#[derive(Drop, starknet::Event)]
struct ClaimEvent {
#[key]
deposit_id: DepositId,
#[key]
sender: ContractAddress,
#[key]
recipient: NostrPublicKey,
amount: u256,
token_address: ContractAddress,
}

#[derive(Drop, starknet::Event)]
struct DepositEvent {
#[key]
deposit_id: DepositId,
#[key]
sender: ContractAddress,
#[key]
recipient: NostrPublicKey,
amount: u256,
token_address: ContractAddress,
}

#[derive(Drop, starknet::Event)]
struct CancelEvent {
#[key]
deposit_id: DepositId,
#[key]
sender: ContractAddress,
#[key]
recipient: NostrPublicKey,
amount: u256,
token_address: ContractAddress,
}

#[derive(Drop, starknet::Event)]
struct TransferEvent {
#[key]
sender: ContractAddress,
#[key]
recipient: NostrPublicKey,
amount: u256,
token_address: ContractAddress,
}

#[event]
#[derive(Drop, starknet::Event)]
enum Event {
Expand Down Expand Up @@ -151,6 +155,15 @@ pub mod DepositEscrow {
if (!recipient.is_zero()) {
let erc20 = IERC20Dispatcher { contract_address: token_address };
erc20.transfer_from(get_caller_address(), recipient, amount);
self
.emit(
TransferEvent {
sender: get_caller_address(),
recipient: recipient,
amount: amount,
token_address: token_address
}
);
return DepositResult::Transfer(recipient);
}

Expand All @@ -175,7 +188,7 @@ pub mod DepositEscrow {
self
.emit(
DepositEvent {
deposit_id: deposit_id + 1,
deposit_id: deposit_id,
sender: get_caller_address(),
recipient: nostr_recipient,
amount: amount,
Expand Down

0 comments on commit 2ce604f

Please sign in to comment.