Skip to content

Commit

Permalink
Merge branch 'og-nft-backend' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
EjembiEmmanuel committed Sep 18, 2024
2 parents 3bd887a + 73ed2a7 commit ad1a2c3
Show file tree
Hide file tree
Showing 5 changed files with 275 additions and 32 deletions.
6 changes: 6 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
NEXT_PUBLIC_RPC_URL=
RPC_URL=

# Referral and Signing storage DB, not required unless u r testing this feature
DATABASE_URL=

# OG NFT Signer. Not required unless u r testing this feature
# Note: Below sample addresses are for Sepolia testnet
ACCOUNT_PK=0x0574ba4998dd9aedf1c4d6e56b747b29256a795bc3846437d121cd64b972bdd8
NEXT_PUBLIC_OG_NFT_CONTRACT=0x3cb654f2f557a7f71a0c16d97c05a2dec62a0b744979d11afc95b804e1d7307
74 changes: 42 additions & 32 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -1,32 +1,42 @@
datasource db {
url = env("DATABASE_URL")
provider = "postgresql"
}

generator client {
provider = "prisma-client-js"
}

model User {
id Int @id @default(autoincrement())
address String @unique
isTncSigned Boolean? @default(false)
message String?
tncDocVersion String? @default("1.0")
referralCode String @unique
referrals Referral[]
referralCount Int? @default(0)
createdAt DateTime @default(now())
}

model Referral {
referralId Int @id @default(autoincrement())
refreeAddress String @unique
createdAt DateTime @default(now())
User User @relation(fields: [userId], references: [id])
userId Int
@@unique([userId, refreeAddress], name: "unique_referral")
}
datasource db {
url = env("DATABASE_URL")
provider = "postgresql"
}

generator client {
provider = "prisma-client-js"
}

model User {
id Int @id @default(autoincrement())
address String @unique
isTncSigned Boolean? @default(false)
message String?
tncDocVersion String? @default("1.0")
referralCode String @unique
referrals Referral[]
referralCount Int? @default(0)
createdAt DateTime @default(now())
og_nft_users og_nft_users?
}

model Referral {
referralId Int @id @default(autoincrement())
refreeAddress String @unique
createdAt DateTime @default(now())
User User @relation(fields: [userId], references: [id])
userId Int
@@unique([userId, refreeAddress], name: "unique_referral")
}

model og_nft_users {
id Int @id @default(autoincrement())
userId Int @unique
User User @relation(fields: [userId], references: [id])
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
37 changes: 37 additions & 0 deletions public/og_nft_eligible_users.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[
"0x5b55db55f5884856860e63f3595b2ec6b2c9555f3f507b4ca728d8e427b7864",
"0x5095078578a59f8a9c17df97188db1b59574c6d4836dd3e705fe8537624228a",
"0x18489438975ee3c6bc18add415d7889a9630547398f26bb5dee27481216a67d",
"0x43fbdfdd75f2726f999ad87833ca6372261b200e956cd8df7986e4fc518d0eb",
"0x4d1740c01d87e64d7b5149616724bfe24537e200b3f13f6b8b8e760d0ec742",
"0x29dbf109d0f4c8fa807c14e867df953ab3bc9b39d9f66e9a13f1922d10243bb",
"0x708a705b8ee042cde294269c20f65790a9bb535e6e76b9df600821e322e03cf",
"0x36aa3388e7da64d6adf08653abc5699f681ffedacd7938d2e115f73919be294",
"0x47ab88662a0173b6014bfc41f7479cf8f973a7212fe5bc9abf8f40138c0c979",
"0x46d703df4dd4e1b8196b294ec295c8c66097836cd4085372299ac53dff5d478",
"0x11dfbced0c610ae46447105b97477b93e9bbc2f346980c7de51d3622f310201",
"0x3950ce99fa8c34188f591d55ccbeafb109c6215cb33f37f5b22d14d1462ae9c",
"0x55741fd3ec832f7b9500e24a885b8729f213357be4a8e209c4bca1f3b909ae",
"0x578ecc0659983818087560740a0842e846a516962231cbef4658735adb9063c",
"0x5caa422de56ffa4d6bbcf8cea2d8c7a3d0c490edf2155d3b29a68d9ddc55479",
"0x7a900c5b496d15bbb1c3c69d090e890a4b19dbceabee72232d4f2bec67ff4c",
"0x7f5d5b58f2a1c504f6a8d0e47269c903485582308b6f3415c27a561e0d1a6fa",
"0x17603b7963b1e2357a57e3c16f83abacef6bd8cf59e5394c34ae72ce566da2",
"0x4bbdde9359d8bc7e513f510f9080306dbf267acb41228a4706d1b55f2fd065d",
"0x4015548595f22ccf56f6f42ada31a5d8eb7cb307c4e9e550b578d44fa25bcc",
"0x50393e851e40de930abcd9569d9df55883b9f2836d4bae724f126d2258cd292",
"0x2915ca6c218df8b394237b278cc920668fd504268494e1ebcf108a660cd7136",
"0x552760d9b7d629e2daf636129fb519ac17a739e1a1fa05ee928ccb1f62c26cf",
"0x14f59c23735b4aaaf6b6c0df567cacff9adc27f50dcb8b5270cf1237605c263",
"0x6733e297fe300f78f48c7106ad550626377aa732cef360867218c08a536ea5e",
"0x1ca34f742a91a588a3e770c8c8c8618a0713d7f64fda7935d42dcfcf4adffa0",
"0x6a98eef8b1ce965ec9f6daf4c896f5c21217f2365652c30d462b13a1858ed7c",
"0x5105649f42252f79109356e1c8765b7dcdb9bf4a6a68534e7fc962421c7efd2",
"0x36177b6741a43c219602ce857c18e445920d5a6ea5f4ee3a0240e8ae319bbf5",
"0x679316db27cdb5d579d0508859ce450db3c2a2483e3628f7c1fc80b52e87634",
"0x7463d3ebcd4c6de2035cca849814bbba4dd7820dac25e074e78087903d1b585",
"0x7342070d73d4ceef7e7c84420acb3026720e88fef10302fc11fd25a7ee0b715",
"0x2b27457428b94b38ccad5339ebc17a211b7c482c008ac8ad22e01b30e923628",
"0x67b72d3df972e5816b07ad4794af8e85c968409554281880149e96f09df1d56",
"0x54d159fa98b0f67b3d3b287aae0340bf595d8f2a96ed99532785aeef08c1ede"
]
118 changes: 118 additions & 0 deletions src/abi/nft.abi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
[
{
"name": "name",
"type": "function",
"inputs": [],
"outputs": [
{
"type": "core::byte_array::ByteArray"
}
],
"state_mutability": "view"
},
{
"name": "symbol",
"type": "function",
"inputs": [],
"outputs": [
{
"type": "core::byte_array::ByteArray"
}
],
"state_mutability": "view"
},
{
"name": "mint",
"type": "function",
"inputs": [
{
"name": "nftId",
"type": "core::integer::u8"
},
{
"name": "rewardEarned",
"type": "core::integer::u128"
},
{
"name": "hash",
"type": "core::felt252"
},
{
"name": "signature",
"type": "core::array::Array::<core::felt252>"
}
],
"outputs": [],
"state_mutability": "external"
},
{
"name": "upgrade",
"type": "function",
"inputs": [
{
"name": "newClassHash",
"type": "core::starknet::class_hash::ClassHash"
}
],
"outputs": [],
"state_mutability": "external"
},
{
"name": "set_settings",
"type": "function",
"inputs": [
{
"name": "settings",
"type": "defispring::nft::Settings"
}
],
"outputs": [],
"state_mutability": "external"
},
{
"name": "get_settings",
"type": "function",
"inputs": [],
"outputs": [
{
"type": "defispring::nft::Settings"
}
],
"state_mutability": "view"
},
{
"name": "set_pubkey",
"type": "function",
"inputs": [
{
"name": "pubkey",
"type": "core::felt252"
}
],
"outputs": [],
"state_mutability": "external"
},
{
"name": "get_pubkey",
"type": "function",
"inputs": [],
"outputs": [
{
"type": "core::felt252"
}
],
"state_mutability": "view"
},
{
"name": "set_token_uri",
"type": "function",
"inputs": [
{
"name": "uri",
"type": "core::byte_array::ByteArray"
}
],
"outputs": [],
"state_mutability": "external"
}
]
72 changes: 72 additions & 0 deletions src/app/api/users/ognft/[address]/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { NextResponse } from 'next/server';
import { ec, hash } from 'starknet';
import { standariseAddress } from '@/utils';
import OGNFTUsersJson from '@public/og_nft_eligible_users.json';

export const revalidate = 3600;

export async function GET(req: Request, context: any) {
try {
const { params } = context;
const addr = params.address;

// standardised address
let pAddr = addr;
try {
pAddr = standariseAddress(addr);
} catch (e) {
throw new Error('Invalid address');
}

const queryAddr = pAddr;

if (!process.env.ACCOUNT_PK) {
throw new Error('Invalid signer');
}

const isOgNFTUser = OGNFTUsersJson.includes(queryAddr);

// total ogNFTUsers
const totalOgNFTUsers = OGNFTUsersJson.length;

console.log('isOgUser', isOgNFTUser);
if (!isOgNFTUser) {
return NextResponse.json(
{
address: '',
hash: '',
isOgNFTUser: false,
sig: [],
totalOgNFTUsers,
},
{
status: 200,
},
);
}

const hash1 = hash.computePedersenHash(pAddr, 0);

const sig = ec.starkCurve.sign(hash1, process.env.ACCOUNT_PK);

return NextResponse.json({
address: pAddr,
isOgNFTUser,
hash: hash1,
sig: [sig.r.toString(), sig.s.toString()],
totalOgNFTUsers,
});
} catch (err) {
console.error('Error /api/users/:address', err);
return NextResponse.json(
{
address: '',
hash: '',
sig: [],
},
{
status: 500,
},
);
}
}

0 comments on commit ad1a2c3

Please sign in to comment.