Skip to content

Commit

Permalink
FEAT: created a new file that contains the interface ID and how to ge…
Browse files Browse the repository at this point in the history
…nerate it
  • Loading branch information
VictoriaAde committed Jun 3, 2024
1 parent 5d33832 commit 1f756c3
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 5 deletions.
1 change: 1 addition & 0 deletions onchain/src/social.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ pub mod bech32;
pub mod profile;
pub mod request;
pub mod transfer;
pub mod interfaceID;
8 changes: 3 additions & 5 deletions onchain/src/social/account.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use starknet::{ContractAddress, get_caller_address, get_contract_address, contra
use super::profile::NostrProfile;
use super::request::SocialRequest;
use super::transfer::Transfer;
use super::interfaceID::ISRC5_ID;

#[starknet::interface]
pub trait ISocialAccount<TContractState> {
Expand All @@ -21,6 +22,7 @@ pub mod SocialAccount {
};
use super::super::transfer::Transfer;
use super::{ISocialAccountDispatcher, ISocialAccountDispatcherTrait};
use super::super::interfaceID::ISRC5_ID;

component!(path: SRC5Component, storage: src5, event: SRC5Event);

Expand Down Expand Up @@ -50,10 +52,6 @@ pub mod SocialAccount {
#[key]
public_key: u256
}
// Generate interface using src5.rs
// -> Copy interface into a file and run `src5_rs parse <PATH_TO_CAIRO_FILE>`
// -> Note: You would need to define custom Structs and Enums in the file.
const ISRC5_ID: felt252 = 0x2717e95370c20103b33f13a20ed0f89783312fd08860f522ef8f6177fedc5e0;

#[constructor]
fn constructor(ref self: ContractState, public_key: u256,) {
Expand Down Expand Up @@ -119,9 +117,9 @@ mod tests {
ISocialAccountDispatcher, ISocialAccountDispatcherTrait, ISocialAccountSafeDispatcher,
ISocialAccountSafeDispatcherTrait
};
use super::super::interfaceID::ISRC5_ID;

const public_key: u256 = 45;
const ISRC5_ID: felt252 = 0x2717e95370c20103b33f13a20ed0f89783312fd08860f522ef8f6177fedc5e0;

fn declare_account() -> ContractClass {
declare("SocialAccount").unwrap()
Expand Down
40 changes: 40 additions & 0 deletions onchain/src/social/interfaceID.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Generate interface using src5.rs
// -> Copy interface into a file and run `src5_rs parse <PATH_TO_CAIRO_FILE>`
// -> Note: You would need to define custom Structs and Enums in the file.
pub const ISRC5_ID: felt252 = 0x2717e95370c20103b33f13a20ed0f89783312fd08860f522ef8f6177fedc5e0;


// Below is the interface structure for generating the interface ID
// You can generate the ID using this tool: https://github.com/ericnordelo/src5-rs/tree/main?tab=readme-ov-file
struct Transfer {
amount: u256,
token: felt252,
token_address: starknet::ContractAddress,
joyboy: NostrProfile,
recipient: NostrProfile,
}

struct SocialRequest<T> {
public_key: u256,
created_at: u64,
kind: u16,
tags: felt252,
content: T,
sig: Signature,
}

struct NostrProfile {
public_key: u256,
relays: felt252,
}

struct Signature {
r: u256,
s: u256,
}

trait ISocialAccount {
fn get_public_key() -> u256;
fn handle_transfer(request: SocialRequest<Transfer>);
fn is_supported_interface(interface_id: felt252) -> bool;
}

0 comments on commit 1f756c3

Please sign in to comment.