Skip to content

Commit

Permalink
added get attestation function
Browse files Browse the repository at this point in the history
  • Loading branch information
KohliSuraj committed Jun 25, 2024
1 parent 438231e commit b17895e
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@ type DisplayContent =
export const displayTxResult = (
displayContent: DisplayContent | DisplayContent[],
asText: boolean,
functionOutputs: readonly AbiOutput[] = [],
functionOutputs: readonly AbiOutput[] = []
): string | ReactElement | number => {
if (displayContent == null) {
return "";
}
if (functionOutputs != null && functionOutputs.length != 0) {
const type = functionOutputs[0].type;
const parsedParam = parseParamWithType(type, displayContent, true);
console.log(parsedParam);

if (typeof parsedParam === "bigint") {
const asNumber = Number(parsedParam);
Expand Down
112 changes: 110 additions & 2 deletions packages/nextjs/contracts/deployedContracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ const deployedContracts = {
},
],
},
AttestationRegistry: {
AttestationRegistry: {
address:
"0x0415e94910dadd0a9be94dff4e5c762c4ccc034a66ebf424cb011ef885af0f41",
"0x043a0fcd4152f67425ca045f81babfdf9d8a0ed7a3e4dda1f1a5bfc094a8d5da",
abi: [
{
type: "impl",
Expand Down Expand Up @@ -166,10 +166,64 @@ const deployedContracts = {
},
],
},
{
type: "struct",
name: "contracts::AttestationRegistry::Attestation",
members: [
{
name: "uid",
type: "core::integer::u128",
},
{
name: "schema_uid",
type: "core::integer::u128",
},
{
name: "time",
type: "core::integer::u64",
},
{
name: "recipient",
type: "core::starknet::contract_address::ContractAddress",
},
{
name: "attester",
type: "core::starknet::contract_address::ContractAddress",
},
{
name: "data",
type: "core::byte_array::ByteArray",
},
{
name: "revocable",
type: "core::bool",
},
{
name: "revocation_time",
type: "core::integer::u64",
},
],
},
{
type: "interface",
name: "contracts::AttestationRegistry::IAttestationRegistry",
items: [
{
type: "function",
name: "get_attestation",
inputs: [
{
name: "attestation_uid",
type: "core::integer::u128",
},
],
outputs: [
{
type: "contracts::AttestationRegistry::Attestation",
},
],
state_mutability: "view",
},
{
type: "function",
name: "attest",
Expand Down Expand Up @@ -348,10 +402,64 @@ const deployedContracts = {
},
],
},
{
type: "struct",
name: "contracts::AttestationRegistry::Attestation",
members: [
{
name: "uid",
type: "core::integer::u128",
},
{
name: "schema_uid",
type: "core::integer::u128",
},
{
name: "time",
type: "core::integer::u64",
},
{
name: "recipient",
type: "core::starknet::contract_address::ContractAddress",
},
{
name: "attester",
type: "core::starknet::contract_address::ContractAddress",
},
{
name: "data",
type: "core::byte_array::ByteArray",
},
{
name: "revocable",
type: "core::bool",
},
{
name: "revocation_time",
type: "core::integer::u64",
},
],
},
{
type: "interface",
name: "contracts::AttestationRegistry::IAttestationRegistry",
items: [
{
type: "function",
name: "get_attestation",
inputs: [
{
name: "attestation_uid",
type: "core::integer::u128",
},
],
outputs: [
{
type: "contracts::AttestationRegistry::Attestation",
},
],
state_mutability: "view",
},
{
type: "function",
name: "attest",
Expand Down
21 changes: 15 additions & 6 deletions packages/snfoundry/contracts/src/AttestationRegistry.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use super::SchemaRegistry::{ISchemaRegistry, ISchemaRegistryDispatcher};

#[starknet::interface]
pub trait IAttestationRegistry<TContractState> {
// fn get_attestation(self: @TContractState, attestation_uid: u128) -> (u128, u128, u64, ContractAddress, ContractAddress, ByteArray, bool, u64);
fn get_attestation(self: @TContractState, attestation_uid: u128) -> Attestation;
fn attest(
ref self: TContractState,
schema_uid: u128,
Expand Down Expand Up @@ -101,11 +101,20 @@ mod AttestationRegistry {

#[abi(embed_v0)]
impl AttestationRegistryImpl of IAttestationRegistry<ContractState> {
// fn get_attestation(self: @ContractState, attestation_uid: u128) -> (u128, u128, u64, ContractAddress, ContractAddress, ByteArray, bool, u64) {
// let data = self.db.read(attestation_uid);
// (data.uid, data.schema_uid, data.time, data.recipient, data.attester, data.data, data.revocable, data.revocation_time)
// }

fn get_attestation(self: @ContractState, attestation_uid: u128) -> Attestation {
let data = self.db.read(attestation_uid);
Attestation {
uid: data.uid,
schema_uid: data.schema_uid,
time: data.time,
recipient: data.recipient,
attester: data.attester,
data: data.data,
revocable: data.revocable,
revocation_time: data.revocation_time,
}
}

fn attest(
ref self: ContractState,
schema_uid: u128,
Expand Down

0 comments on commit b17895e

Please sign in to comment.