Skip to content

Commit

Permalink
formatting and linting changes
Browse files Browse the repository at this point in the history
  • Loading branch information
KohliSuraj committed Jun 25, 2024
1 parent 5af0cd5 commit 83828c7
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 48 deletions.
3 changes: 1 addition & 2 deletions packages/nextjs/app/dashboard/attestations/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const Attestations = () => {
enabled: true,
});

/* struct Attested {
/* struct Attested {
#[key]
recipient: ContractAddress,
#[key]
Expand Down Expand Up @@ -125,7 +125,6 @@ const Attestations = () => {
</tr>
</thead>
<tbody>

{schemas.map((schema, index) => (
<tr key={index} className="border-b">
<td className="px-4 py-2">
Expand Down
8 changes: 4 additions & 4 deletions packages/nextjs/components/forms/CreateAttestationForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { useScaffoldWriteContract } from "~~/hooks/scaffold-stark/useScaffoldWri

const CreateAttestationForm = () => {
const [schema, setSchema] = useState<number>(0);
const[recipient, setRecipient] = useState<string>("");
const[data, setData] = useState<string>("");
const [recipient, setRecipient] = useState<string>("");
const [data, setData] = useState<string>("");

const [revocable, setRevocable] = useState<boolean>(false);
const router = useRouter();
Expand All @@ -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) => {
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion packages/nextjs/contracts/deployedContracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -393,4 +393,4 @@ const deployedContracts = {
},
} as const;

export default deployedContracts;
export default deployedContracts;
26 changes: 18 additions & 8 deletions packages/snfoundry/contracts/src/AttestationRegistry.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@ use super::SchemaRegistry::{ISchemaRegistry, ISchemaRegistryDispatcher};

#[starknet::interface]
pub trait IAttestationRegistry<TContractState> {
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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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<ContractState> {
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);
Expand Down Expand Up @@ -144,8 +155,7 @@ mod AttestationRegistry {

uid
}

// fn revoke(ref self: ContractState, request: RevocationRequest) {}
// fn revoke(ref self: ContractState, request: RevocationRequest) {}
}
}

58 changes: 30 additions & 28 deletions packages/snfoundry/contracts/src/SAS.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand All @@ -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);
Expand Down
1 change: 1 addition & 0 deletions packages/snfoundry/contracts/src/test/Test_sas.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,4 @@ fn test_attestation_validity() {
}
// Additional tests can be added for multi-attestation, delegation, and other complex scenarios


11 changes: 6 additions & 5 deletions packages/snfoundry/scripts-ts/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ const deployScript = async (): Promise<void> => {
// );

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(
Expand Down

0 comments on commit 83828c7

Please sign in to comment.