Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🎉 Remarkable validator #18

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions validate/graph.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// const GRAPHQL_URL = 'https://app.gc.subsquid.io/beta/rubick/009-rc0/graphql'
const RMRK_GRAPHQL_URL = 'https://gql-rmrk2-prod.graphcdn.app'

import {
getClient,
graphFetch
} from 'https://esm.sh/@kodadot1/[email protected]'
import { query } from 'https://esm.sh/[email protected]'

const client = getClient('rmrk2')

export async function getKodaCollection(id: string): Promise<any> {
const collection = client.collectionById(id, ['id', 'symbol', 'blockNumber', 'max', 'issuer', 'metadata', 'name', 'supply' ] as any)
const result = await client.fetch<{ data: any }>(collection)
return result.data.collection
}

export async function getSingularCollection(id: string): Promise<any> {
const q = query({
operation: {
alias: 'collection',
name: 'collections_by_pk',
},
fields: [
'id',
'symbol',
'blockNumber: block',
'max',
'issuer',
'metadata',
'name: metadata_name',
{ 'count: nfts_aggregate': [
{ 'aggregate': [
'value :count'
] }
] }
],
variables: {
id: {
type: 'String',
name: 'id',
required: true,
value: id,
}
},
})

const result = await graphFetch<{ data: any }>(RMRK_GRAPHQL_URL, q)
const { data: { collection } } = result
const x = { ...collection, blockNumber: String(collection.blockNumber), supply: collection.count.aggregate.value }
delete x['count']
return x
}

5 changes: 5 additions & 0 deletions validate/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { parse } from "https://deno.land/[email protected]/flags/mod.ts"

const flags = parse(Deno.args, {
string: ["entity", "id"],
});
13 changes: 13 additions & 0 deletions validate/tests/collection.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { assertEquals } from "https://deno.land/[email protected]/testing/asserts.ts";
import { getKodaCollection, getSingularCollection } from "../graph.ts";

Deno.test("Collection should be equal", async () => {
const id = '5412791fffe83a9b05-AW7TG'
const koda = await getKodaCollection(id)
const singular = await getSingularCollection(id)

console.log(koda)
console.log(singular)

assertEquals(koda, singular)
});