Skip to content

Commit

Permalink
feat: As a user, I want the indexed objects to contain some "audit" data
Browse files Browse the repository at this point in the history
fix: All indexed objects should have lowercase IDs
  • Loading branch information
alainncls committed Mar 16, 2024
1 parent 6a8c72b commit 5218fcf
Show file tree
Hide file tree
Showing 22 changed files with 403 additions and 56 deletions.
26 changes: 20 additions & 6 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion sdk/examples/utils/countUniqueSubjects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ async function main() {
const allSubjects: string[][] = [];
const uniqueSubjects: Set<string> = new Set<string>();

for (let i = 0; i <= filesNumber; i++) {
for (let i = 0; i < filesNumber; i++) {
allSubjects.push(await fetchSubjectsFromFile(i));
}

Expand Down
3 changes: 2 additions & 1 deletion sdk/examples/utils/getAllAttestations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import fs from "fs";
import path from "path";

const BATCH_SIZE = 100000;
const BATCH_START = 0;

const fetchAllAttestations = async (batchNumber: number, veraxSdk: VeraxSdk) => {
let skip = 0;
Expand Down Expand Up @@ -36,7 +37,7 @@ async function main() {
`We expect ${batchesNumber} batches of ${BATCH_SIZE} attestations to get all ${attestationsNumber} attestations.`,
);

for (let i = 0; i <= batchesNumber; i++) {
for (let i = BATCH_START; i < batchesNumber; i++) {
console.log(`Attestations batch #${i}`);
const subjectsBatch = await fetchAllAttestations(i, veraxSdk);

Expand Down
6 changes: 3 additions & 3 deletions sdk/src/dataMapper/AttestationDataMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export default class AttestationDataMapper extends BaseDataMapper<
}

private async enrichAttestation(attestation: Attestation) {
const schema = (await this.veraxSdk.schema.getSchema(attestation.schemaId)) as Schema;
const schema = (await this.veraxSdk.schema.getSchema(attestation.schema)) as Schema;
attestation.decodedPayload = decodeWithRetry(schema.schema, attestation.attestationData as `0x${string}`);

attestation.attestedDate = Number(attestation.attestedDate);
Expand All @@ -68,7 +68,7 @@ export default class AttestationDataMapper extends BaseDataMapper<
attestation.version = Number(attestation.version);

// Check if data is stored offchain
if (attestation.schemaId === Constants.OFFCHAIN_DATA_SCHEMA_ID) {
if (attestation.schema === Constants.OFFCHAIN_DATA_SCHEMA_ID) {
attestation.offchainData = {
schemaId: (attestation.decodedPayload as OffchainData[])[0].schemaId,
uri: (attestation.decodedPayload as OffchainData[])[0].uri,
Expand Down Expand Up @@ -175,7 +175,7 @@ export default class AttestationDataMapper extends BaseDataMapper<
return null;
}
const attestationWithDecodeObject: AttestationWithDecodeObject = { ...attestation, decodeObject: {} };
const schema = (await this.veraxSdk.schema.getSchema(attestation.schemaId)) as Schema;
const schema = await this.veraxSdk.schema.getSchema(attestation.schema);
const splitSchema = schema.schema.split(",");
const schemaFields = splitSchema.map<string>((item) => item.trim().split(" ")[1]);
for (let i = 0; i < schemaFields.length; i++) {
Expand Down
3 changes: 1 addition & 2 deletions sdk/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export type AttestationWithDecodeObject = Attestation & {

export type Attestation = OnChainAttestation & {
id: string;
schemaString: string;
decodedData: string[];
decodedPayload: object;
offchainData?: OffchainData;
Expand All @@ -34,7 +33,7 @@ export type OffchainData = { schemaId: string; uri: string; error?: string };

export type OnChainAttestation = {
attestationId: string; // The unique identifier of the attestation.
schemaId: string; // The identifier of the schema this attestation adheres to.
schema: string; // The identifier of the schema this attestation adheres to.
replacedBy: string | null; // Whether the attestation was replaced by a new one.
attester: Address; // The address issuing the attestation to the subject.
portal: Address; // The id of the portal that created the attestation.
Expand Down
2 changes: 2 additions & 0 deletions subgraph/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ DEPLOY_ENDPOINT_ARBITRUM_GOERLI=
DEPLOY_ENDPOINT_ARBITRUM_MAINNET=
IPFS_ENDPOINT=
IPFS_IDENTIFIERS=
SUBGRAPH_NAME_LINEA_GOERLI=
SUBGRAPH_NAME_LINEA_MAINNET=
SUBGRAPH_NAME_ARBITRUM=
SUBGRAPH_NAME_ARBITRUM_GOERLI=
26 changes: 26 additions & 0 deletions subgraph/abis/PortalRegistry.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,19 @@
"name": "PortalRegistered",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "address",
"name": "portalAddress",
"type": "address"
}
],
"name": "PortalRevoked",
"type": "event"
},
{
"inputs": [
{
Expand Down Expand Up @@ -345,6 +358,19 @@
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "id",
"type": "address"
}
],
"name": "revoke",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "router",
Expand Down
2 changes: 1 addition & 1 deletion subgraph/networks.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"startBlock": 1454671
}
},
"linea-mainnet": {
"linea": {
"AttestationRegistry": {
"address": "0x3de3893aa4Cdea029e84e75223a152FD08315138",
"startBlock": 346695
Expand Down
22 changes: 11 additions & 11 deletions subgraph/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"license": "MIT",
"author": "Consensys",
"scripts": {
"build:linea-mainnet": "cp subgraph.linea-mainnet.yaml subgraph.yaml && pnpm run codegen:linea-mainnet && graph build --network linea-mainnet",
"build:linea-mainnet": "cp subgraph.linea-mainnet.yaml subgraph.yaml && pnpm run codegen:linea-mainnet && graph build --network linea",
"build:linea-goerli": "cp subgraph.linea-goerli.yaml subgraph.yaml && pnpm run codegen:linea-goerli && graph build --network linea-goerli",
"build:arbitrum-goerli": "cp subgraph.linea-goerli.yaml subgraph.yaml && pnpm run codegen:arbitrum-goerli && graph build --network arbitrum-goerli",
"build:arbitrum-sepolia": "cp subgraph.arbitrum-sepolia.yaml subgraph.yaml && pnpm run codegen:arbitrum-sepolia && graph build --network arbitrum-sepolia",
Expand All @@ -25,26 +25,26 @@
"codegen:arbitrum-goerli": "cp subgraph.linea-goerli.yaml subgraph.yaml && graph codegen",
"codegen:arbitrum-sepolia": "cp subgraph.arbitrum-sepolia.yaml subgraph.yaml && graph codegen",
"codegen:arbitrum-one": "cp subgraph.linea-mainnet.yaml subgraph.yaml && graph codegen",
"create:linea-mainnet": "source .env && graph create --node $DEPLOY_ENDPOINT_LINEA_MAINNET Consensys/linea-attestation-registry",
"create:linea-goerli": "source .env && graph create --node $DEPLOY_ENDPOINT_LINEA_GOERLI Consensys/linea-attestation-registry",
"create:linea-mainnet": "source .env && graph create --node $DEPLOY_ENDPOINT_LINEA_MAINNET $SUBGRAPH_NAME_LINEA_MAINNET",
"create:linea-goerli": "source .env && graph create --node $DEPLOY_ENDPOINT_LINEA_GOERLI $SUBGRAPH_NAME_LINEA_GOERLI",
"create:arbitrum-goerli": "source .env && graph create --node $DEPLOY_ENDPOINT_ARBITRUM_GOERLI Consensys/verax-arbitrum-goerli",
"create:arbitrum-sepolia": "source .env && graph create --node $DEPLOY_ENDPOINT_ARBITRUM_SEPOLIA $SUBGRAPH_NAME_ARBITRUM_SEPOLIA",
"create:arbitrum-one": "source .env && graph create --node $DEPLOY_ENDPOINT_ARBITRUM_GOERLI Consensys/verax-arbitrum",
"deploy:linea-mainnet": "source .env && cp subgraph.linea-mainnet.yaml subgraph.yaml && pnpm run build:linea-mainnet && graph deploy --network linea-mainnet --node $DEPLOY_ENDPOINT_LINEA_MAINNET --headers \"{\\\"Authorization\\\": \\\"Basic $IPFS_IDENTIFIERS\\\"}\" --ipfs $IPFS_ENDPOINT --version-label v0.0.1 Consensys/linea-attestation-registry",
"deploy:linea-goerli": "source .env && cp subgraph.linea-goerli.yaml subgraph.yaml && pnpm run build:linea-goerli && graph deploy --network linea-goerli --node $DEPLOY_ENDPOINT_LINEA_GOERLI --headers \"{\\\"Authorization\\\": \\\"Basic $IPFS_IDENTIFIERS\\\"}\" --ipfs $IPFS_ENDPOINT --version-label v0.0.5 Consensys/linea-attestation-registry",
"deploy:arbitrum-goerli": "source .env && cp subgraph.arbitrum-goerli.yaml subgraph.yaml && pnpm run build:arbitrum-goerli && graph deploy --network arbitrum-goerli --product hosted-service $SUBGRAPH_NAME_ARBITRUM_GOERLI",
"deploy:linea-mainnet": "source .env && cp subgraph.linea-mainnet.yaml subgraph.yaml && graph deploy --network linea --node $DEPLOY_ENDPOINT_LINEA_MAINNET --headers \"{\\\"Authorization\\\": \\\"Basic $IPFS_IDENTIFIERS\\\"}\" --ipfs $IPFS_ENDPOINT --version-label v0.0.1 $SUBGRAPH_NAME_LINEA_MAINNET",
"deploy:linea-goerli": "source .env && cp subgraph.linea-goerli.yaml subgraph.yaml && graph deploy --network linea-goerli --node $DEPLOY_ENDPOINT_LINEA_GOERLI --version-label v0.0.6 $SUBGRAPH_NAME_LINEA_GOERLI",
"deploy:arbitrum-goerli": "source .env && cp subgraph.arbitrum-goerli.yaml subgraph.yaml && graph deploy --network arbitrum-goerli --product hosted-service $SUBGRAPH_NAME_ARBITRUM_GOERLI",
"deploy:arbitrum-sepolia": "source .env && cp subgraph.arbitrum-sepolia.yaml subgraph.yaml && pnpm run build:arbitrum-sepolia && graph deploy --studio $SUBGRAPH_NAME_ARBITRUM_SEPOLIA",
"deploy:arbitrum-one": "source .env && cp subgraph.arbitrum-one.yaml subgraph.yaml && pnpm run build:arbitrum-one && graph deploy --network arbitrum-one --product hosted-service $SUBGRAPH_NAME_ARBITRUM",
"remove:linea-mainnet": "source .env && graph remove --node $DEPLOY_ENDPOINT_LINEA_MAINNET Consensys/linea-attestation-registry",
"remove:linea-goerli": "source .env && graph remove --node $DEPLOY_ENDPOINT_LINEA_GOERLI Consensys/linea-attestation-registry",
"deploy:arbitrum-one": "source .env && cp subgraph.arbitrum-one.yaml subgraph.yaml && graph deploy --network arbitrum-one --product hosted-service $SUBGRAPH_NAME_ARBITRUM",
"remove:linea-mainnet": "source .env && graph remove --node $DEPLOY_ENDPOINT_LINEA_MAINNET $SUBGRAPH_NAME_LINEA_MAINNET",
"remove:linea-goerli": "source .env && graph remove --node $DEPLOY_ENDPOINT_LINEA_GOERLI $SUBGRAPH_NAME_LINEA_GOERLI",
"test": "pnpm run codegen:linea-goerli && graph test",
"test:coverage": "graph test -c",
"test:docker": "graph test -d"
},
"devDependencies": {
"@graphprotocol/graph-cli": "0.68.5",
"@graphprotocol/graph-ts": "0.31.0",
"assemblyscript": "0.19.10",
"@graphprotocol/graph-ts": "0.33.0",
"assemblyscript": "0.27.25",
"matchstick-as": "0.6.0"
}
}
29 changes: 26 additions & 3 deletions subgraph/schema.graphql
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
type Attestation @entity {
id: ID!
schemaId: Bytes!
schema: Schema!
replacedBy: Bytes!
attester: Bytes!
portal: Bytes!
portal: Portal!
attestedDate: BigInt!
expirationDate: BigInt!
revocationDate: BigInt!
Expand All @@ -12,15 +12,16 @@ type Attestation @entity {
subject: Bytes!
encodedSubject: Bytes!
attestationData: Bytes!
schemaString: String
decodedData: [String!]
auditInformation: AuditInformation!
}

type Module @entity {
id: ID!
moduleAddress: Bytes!
name: String!
description: String!
auditInformation: AuditInformation!
}

type Portal @entity {
Expand All @@ -32,6 +33,7 @@ type Portal @entity {
description: String!
ownerName: String!
attestationCounter: Int
auditInformation: AuditInformation!
}

type Schema @entity {
Expand All @@ -41,6 +43,7 @@ type Schema @entity {
context: String!
schema: String!
attestationCounter: Int
auditInformation: AuditInformation!
}

type Counter @entity {
Expand All @@ -53,10 +56,30 @@ type Counter @entity {

type Issuer @entity {
id: ID!
auditInformation: AuditInformation!
}

type RegistryVersion @entity {
id: ID!
versionNumber: Int
timestamp: BigInt
auditInformation: AuditInformation!
}

type AuditInformation @entity {
id: ID!
creation: Audit!
lastModification: Audit!
modifications: [Audit!]!
}

type Audit @entity {
id: ID!
blockNumber: BigInt!
transactionHash: Bytes!
transactionTimestamp: BigInt!
fromAddress: Bytes!
toAddress: Bytes
valueTransferred: BigInt
gasPrice: BigInt
}
Loading

0 comments on commit 5218fcf

Please sign in to comment.