From 83828c7d6842748f59b2ecab797b2a9a7de68dbf Mon Sep 17 00:00:00 2001 From: Suraj Kohli Date: Tue, 25 Jun 2024 14:26:24 +0530 Subject: [PATCH] formatting and linting changes --- .../app/dashboard/attestations/page.tsx | 3 +- .../forms/CreateAttestationForm.tsx | 8 +-- .../nextjs/contracts/deployedContracts.ts | 2 +- .../contracts/src/AttestationRegistry.cairo | 26 ++++++--- packages/snfoundry/contracts/src/SAS.cairo | 58 ++++++++++--------- .../contracts/src/test/Test_sas.cairo | 1 + packages/snfoundry/scripts-ts/deploy.ts | 11 ++-- 7 files changed, 61 insertions(+), 48 deletions(-) diff --git a/packages/nextjs/app/dashboard/attestations/page.tsx b/packages/nextjs/app/dashboard/attestations/page.tsx index 0ba9d7f..18d3477 100644 --- a/packages/nextjs/app/dashboard/attestations/page.tsx +++ b/packages/nextjs/app/dashboard/attestations/page.tsx @@ -24,7 +24,7 @@ const Attestations = () => { enabled: true, }); -/* struct Attested { + /* struct Attested { #[key] recipient: ContractAddress, #[key] @@ -125,7 +125,6 @@ const Attestations = () => { - {schemas.map((schema, index) => ( diff --git a/packages/nextjs/components/forms/CreateAttestationForm.tsx b/packages/nextjs/components/forms/CreateAttestationForm.tsx index ca0d2c7..daeee3e 100644 --- a/packages/nextjs/components/forms/CreateAttestationForm.tsx +++ b/packages/nextjs/components/forms/CreateAttestationForm.tsx @@ -5,8 +5,8 @@ import { useScaffoldWriteContract } from "~~/hooks/scaffold-stark/useScaffoldWri const CreateAttestationForm = () => { const [schema, setSchema] = useState(0); - const[recipient, setRecipient] = useState(""); - const[data, setData] = useState(""); + const [recipient, setRecipient] = useState(""); + const [data, setData] = useState(""); const [revocable, setRevocable] = useState(false); const router = useRouter(); @@ -15,7 +15,7 @@ const CreateAttestationForm = () => { useScaffoldWriteContract({ contractName: "AttestationRegistry", functionName: "attest", - args: [ schema, recipient, data, revocable ], + args: [schema, recipient, data, revocable], }); const handleSubmit = async (formData: FormData) => { @@ -27,7 +27,7 @@ const CreateAttestationForm = () => { setRevocable(revocableFetched === "true"); try { await writeAsync({ - args: [ schema, recipient, data, revocable ], + args: [schema, recipient, data, revocable], }); } catch (err) { console.error("Error submitting transaction:", err); diff --git a/packages/nextjs/contracts/deployedContracts.ts b/packages/nextjs/contracts/deployedContracts.ts index 61c12b1..affdb5c 100644 --- a/packages/nextjs/contracts/deployedContracts.ts +++ b/packages/nextjs/contracts/deployedContracts.ts @@ -393,4 +393,4 @@ const deployedContracts = { }, } as const; -export default deployedContracts; \ No newline at end of file +export default deployedContracts; diff --git a/packages/snfoundry/contracts/src/AttestationRegistry.cairo b/packages/snfoundry/contracts/src/AttestationRegistry.cairo index c57db7a..cccf497 100644 --- a/packages/snfoundry/contracts/src/AttestationRegistry.cairo +++ b/packages/snfoundry/contracts/src/AttestationRegistry.cairo @@ -3,8 +3,14 @@ use super::SchemaRegistry::{ISchemaRegistry, ISchemaRegistryDispatcher}; #[starknet::interface] pub trait IAttestationRegistry { - fn attest(ref self: TContractState, schema_uid: u128, recipient: ContractAddress, data: ByteArray, revocable: bool) -> u128; - // fn revoke(ref self: TContractState, request: RevocationRequest); + fn attest( + ref self: TContractState, + schema_uid: u128, + recipient: ContractAddress, + data: ByteArray, + revocable: bool + ) -> u128; +// fn revoke(ref self: TContractState, request: RevocationRequest); } // Define structs @@ -40,11 +46,10 @@ struct AttestationRequest { // data: RevocationRequestData, // } - #[starknet::contract] mod AttestationRegistry { - use core::traits::Into; use contracts::SchemaRegistry::ISchemaRegistryDispatcherTrait; + use core::traits::Into; use starknet::{get_caller_address, get_block_timestamp}; use super::{ ContractAddress, IAttestationRegistry, AttestationRequest, Attestation, @@ -95,14 +100,20 @@ mod AttestationRegistry { } // Constructor -#[constructor] + #[constructor] fn constructor(ref self: ContractState, schema_registry_address: ContractAddress) { self.schema_registry.write(schema_registry_address); } #[abi(embed_v0)] impl AttestationRegistryImpl of IAttestationRegistry { - fn attest(ref self: ContractState, schema_uid: u128, recipient: ContractAddress, data: ByteArray, revocable: bool) -> u128 { + fn attest( + ref self: ContractState, + schema_uid: u128, + recipient: ContractAddress, + data: ByteArray, + revocable: bool + ) -> u128 { let contract_address = self.schema_registry.read(); // let (fetched_uid, fetched_revocable, fetched_schema) = ISchemaRegistryDispatcher { contract_address } // .get_schema(schema_uid); @@ -144,8 +155,7 @@ mod AttestationRegistry { uid } - - // fn revoke(ref self: ContractState, request: RevocationRequest) {} + // fn revoke(ref self: ContractState, request: RevocationRequest) {} } } diff --git a/packages/snfoundry/contracts/src/SAS.cairo b/packages/snfoundry/contracts/src/SAS.cairo index c67730a..bb49674 100644 --- a/packages/snfoundry/contracts/src/SAS.cairo +++ b/packages/snfoundry/contracts/src/SAS.cairo @@ -10,9 +10,9 @@ use starknet::SyscallResult; // use starknet::Store; use starknet::storage_access::Store; use starknet::storage_access::{StorageAddress, StorageBaseAddress}; +use starknet::syscalls::call_contract_syscall; use starknet::syscalls::storage_read_syscall; use starknet::syscalls::storage_write_syscall; -use starknet::syscalls::call_contract_syscall; use starknet::{get_block_timestamp, get_caller_address}; // Define structs @@ -173,31 +173,35 @@ mod SAS { } fn attest(ref self: ContractState, request: AttestationRequest) -> u128 { - - let attestation = Attestation { - uid: EMPTY_UID, - schema_uid: request.schema_uid, - ref_uid: request.refUID, - time: get_block_timestamp(), - expiration_time: request.expirationTime, - recipient: request.recipient, - attester: get_caller_address(), - data: request.data, - }; - - self.current_uid.write(self.current_uid.read() + 1); - let uid = self.current_uid.read(); - let timestamp = get_block_timestamp(); - - self.db.write(uid, attestation); - self.emit(Event::Attested(Attested { - recipient: request.recipient, - attester: get_caller_address(), - uid, - schema_uid: request.schema_uid, - timestamp - })); - + let attestation = Attestation { + uid: EMPTY_UID, + schema_uid: request.schema_uid, + ref_uid: request.refUID, + time: get_block_timestamp(), + expiration_time: request.expirationTime, + recipient: request.recipient, + attester: get_caller_address(), + data: request.data, + }; + + self.current_uid.write(self.current_uid.read() + 1); + let uid = self.current_uid.read(); + let timestamp = get_block_timestamp(); + + self.db.write(uid, attestation); + self + .emit( + Event::Attested( + Attested { + recipient: request.recipient, + attester: get_caller_address(), + uid, + schema_uid: request.schema_uid, + timestamp + } + ) + ); + uid } @@ -218,12 +222,10 @@ mod SAS { fn get_timestamp(self: @ContractState, data: felt252) -> u64 { self.timestamps.read(data) } - } #[generate_trait] impl InternalFunctions of InternalFunctionsTrait { - fn _timestamp(ref self: ContractState, data: felt252, time: u64) { assert(self.timestamps.read(data) == 0, 'Already timestamped'); self.timestamps.write(data, time); diff --git a/packages/snfoundry/contracts/src/test/Test_sas.cairo b/packages/snfoundry/contracts/src/test/Test_sas.cairo index fb4bbeb..ab54b46 100644 --- a/packages/snfoundry/contracts/src/test/Test_sas.cairo +++ b/packages/snfoundry/contracts/src/test/Test_sas.cairo @@ -138,3 +138,4 @@ fn test_attestation_validity() { } // Additional tests can be added for multi-attestation, delegation, and other complex scenarios + diff --git a/packages/snfoundry/scripts-ts/deploy.ts b/packages/snfoundry/scripts-ts/deploy.ts index 90f308b..93a2e8d 100644 --- a/packages/snfoundry/scripts-ts/deploy.ts +++ b/packages/snfoundry/scripts-ts/deploy.ts @@ -9,11 +9,12 @@ const deployScript = async (): Promise => { // ); await deployContract( - { - schema_registry_address: "0x048ec8a62f68659ed94e57e497e154d96cc4d5356ef35a58c6b3f4e034325a8f", // the deployer address is the owner of the contract, - }, - "AttestationRegistry" -); + { + schema_registry_address: + "0x048ec8a62f68659ed94e57e497e154d96cc4d5356ef35a58c6b3f4e034325a8f", // the deployer address is the owner of the contract, + }, + "AttestationRegistry" + ); }; // await deployContract(