Skip to content

Commit

Permalink
changes in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
KohliSuraj committed Jun 20, 2024
1 parent 16c74b7 commit b3b72ab
Show file tree
Hide file tree
Showing 3 changed files with 319 additions and 1 deletion.
259 changes: 258 additions & 1 deletion packages/nextjs/contracts/deployedContracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,263 @@
* You should not edit it manually or your changes might be overwritten.
*/

const deployedContracts = {} as const;
const deployedContracts = {
devnet: {
YourContract: {
address:
"0x044565ce852d3eb78527b6746a07a77abef4fc6a31de461f864f652f950242a0",
abi: [
{
type: "impl",
name: "YourContractImpl",
interface_name: "contracts::YourContract::IYourContract",
},
{
type: "struct",
name: "core::byte_array::ByteArray",
members: [
{
name: "data",
type: "core::array::Array::<core::bytes_31::bytes31>",
},
{
name: "pending_word",
type: "core::felt252",
},
{
name: "pending_word_len",
type: "core::integer::u32",
},
],
},
{
type: "struct",
name: "core::integer::u256",
members: [
{
name: "low",
type: "core::integer::u128",
},
{
name: "high",
type: "core::integer::u128",
},
],
},
{
type: "enum",
name: "core::bool",
variants: [
{
name: "False",
type: "()",
},
{
name: "True",
type: "()",
},
],
},
{
type: "interface",
name: "contracts::YourContract::IYourContract",
items: [
{
type: "function",
name: "gretting",
inputs: [],
outputs: [
{
type: "core::byte_array::ByteArray",
},
],
state_mutability: "view",
},
{
type: "function",
name: "set_gretting",
inputs: [
{
name: "new_greeting",
type: "core::byte_array::ByteArray",
},
{
name: "amount_eth",
type: "core::integer::u256",
},
],
outputs: [],
state_mutability: "external",
},
{
type: "function",
name: "withdraw",
inputs: [],
outputs: [],
state_mutability: "external",
},
{
type: "function",
name: "premium",
inputs: [],
outputs: [
{
type: "core::bool",
},
],
state_mutability: "view",
},
],
},
{
type: "impl",
name: "OwnableImpl",
interface_name: "openzeppelin::access::ownable::interface::IOwnable",
},
{
type: "interface",
name: "openzeppelin::access::ownable::interface::IOwnable",
items: [
{
type: "function",
name: "owner",
inputs: [],
outputs: [
{
type: "core::starknet::contract_address::ContractAddress",
},
],
state_mutability: "view",
},
{
type: "function",
name: "transfer_ownership",
inputs: [
{
name: "new_owner",
type: "core::starknet::contract_address::ContractAddress",
},
],
outputs: [],
state_mutability: "external",
},
{
type: "function",
name: "renounce_ownership",
inputs: [],
outputs: [],
state_mutability: "external",
},
],
},
{
type: "constructor",
name: "constructor",
inputs: [
{
name: "owner",
type: "core::starknet::contract_address::ContractAddress",
},
],
},
{
type: "event",
name: "openzeppelin::access::ownable::ownable::OwnableComponent::OwnershipTransferred",
kind: "struct",
members: [
{
name: "previous_owner",
type: "core::starknet::contract_address::ContractAddress",
kind: "key",
},
{
name: "new_owner",
type: "core::starknet::contract_address::ContractAddress",
kind: "key",
},
],
},
{
type: "event",
name: "openzeppelin::access::ownable::ownable::OwnableComponent::OwnershipTransferStarted",
kind: "struct",
members: [
{
name: "previous_owner",
type: "core::starknet::contract_address::ContractAddress",
kind: "key",
},
{
name: "new_owner",
type: "core::starknet::contract_address::ContractAddress",
kind: "key",
},
],
},
{
type: "event",
name: "openzeppelin::access::ownable::ownable::OwnableComponent::Event",
kind: "enum",
variants: [
{
name: "OwnershipTransferred",
type: "openzeppelin::access::ownable::ownable::OwnableComponent::OwnershipTransferred",
kind: "nested",
},
{
name: "OwnershipTransferStarted",
type: "openzeppelin::access::ownable::ownable::OwnableComponent::OwnershipTransferStarted",
kind: "nested",
},
],
},
{
type: "event",
name: "contracts::YourContract::YourContract::GreetingChanged",
kind: "struct",
members: [
{
name: "greeting_setter",
type: "core::starknet::contract_address::ContractAddress",
kind: "key",
},
{
name: "new_greeting",
type: "core::byte_array::ByteArray",
kind: "key",
},
{
name: "premium",
type: "core::bool",
kind: "data",
},
{
name: "value",
type: "core::integer::u256",
kind: "data",
},
],
},
{
type: "event",
name: "contracts::YourContract::YourContract::Event",
kind: "enum",
variants: [
{
name: "OwnableEvent",
type: "openzeppelin::access::ownable::ownable::OwnableComponent::Event",
kind: "flat",
},
{
name: "GreetingChanged",
type: "contracts::YourContract::YourContract::GreetingChanged",
kind: "nested",
},
],
},
],
},
},
} as const;

export default deployedContracts;
60 changes: 60 additions & 0 deletions packages/snfoundry/contracts/src/SchemaRegistry.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#[starknet::interface]
pub trait ISchemaRegistry<TContractState> {
/// @notice Submits and reserves a new schema
/// @param schema The schema data schema.
/// @param revocable Whether the schema allows revocations explicitly.
/// @return The UID of the new schema.
fn register(ref self: TContractState, schema: ByteArray, revocable: bool) -> felt252;
/// @notice Returns an existing schema by UID
/// @param uid The UID of the schema to retrieve.
/// @return The schema data members.
fn get_schema(self: @TContractState, uid: felt252) -> (felt252, bool, ByteArray);
fn get_uid(self: @TContractState, uid: felt252, revocable: bool, schema: ByteArray) -> felt252;
}

#[starknet::contract]
mod SchemaRegistry {
use core::poseidon::PoseidonTrait;
use core::hash::{HashStateTrait, HashStateExTrait};

use super::ISchemaRegistry;

/// @notice A struct representing a record for a submitted schema.
#[derive(Drop, Serde, Hash)]
pub struct SchemaRecord {
uid: felt252, // The unique identifier of the schema.
revocable: bool, // Whether the schema allows revocations explicitly.
schema: ByteArray // Custom specification of the schema
}

#[storage]
struct Storage {
// The global mapping between schema records and their IDs.
registry: LegacyMap<felt252, SchemaRecord>,
}

#[abi(embed_v0)]
impl SchemaRegistryImpl of ISchemaRegistry<ContractState> {
fn get_schema(self: @ContractState, uid: felt252) -> (felt252, bool, ByteArray) {
let data = self.registry.read(uid);
(data.uid, data.revocable, data.schema)
}

fn register(ref self: ContractState, schema: ByteArray, revocable: bool) -> felt252 {
// let uid = self.registry.len();
// self.registry.write(uid, SchemaRecord { uid, revocable, schema });
self.registry.read(1).uid
}


// internal helper functions
fn get_uid(
self: @ContractState, uid: felt252, revocable: bool, schema: ByteArray
) -> felt252 {
let struct_to_hash = SchemaRecord { uid, revocable, schema };
let hash = PoseidonTrait::new().update_with(struct_to_hash).finalize();
hash
}
}
}

1 change: 1 addition & 0 deletions packages/snfoundry/contracts/src/lib.cairo
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
mod YourContract;
mod SchemaRegistry;
#[cfg(test)]
mod test {
mod TestContract;
Expand Down

0 comments on commit b3b72ab

Please sign in to comment.