Skip to content

Commit

Permalink
some progress
Browse files Browse the repository at this point in the history
  • Loading branch information
zeitgeistxx committed Jun 29, 2024
1 parent acbdadb commit 470be7a
Show file tree
Hide file tree
Showing 10 changed files with 125 additions and 68 deletions.
Binary file modified backend/bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion backend/src/libs/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ const minioClient = new Client({
secretKey: process.env.MINIO_SECRETKEY!,
})

const bucketName = process.env.MINIO_BUCKET!;
const bucketName = process.env.MINIO_BUCKET_NAME!;

export { minioClient, bucketName };
4 changes: 1 addition & 3 deletions backend/src/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@ import { Elysia } from "elysia";
import authRoutes from "@/routes/auth";
import machineRoutes from "@/routes/machine";
import storeRoutes from "@/routes/store";
import paymentRoutes from "@/routes/payment";

const routes = new Elysia();

routes
.get("/", () => "Hello from Elysia!")
.group("/auth", (routes) => routes.use(authRoutes))
.group("/machine", (routes) => routes.use(machineRoutes))
.group("/store", (routes) => routes.use(storeRoutes))
.group("/payment", (routes) => routes.use(paymentRoutes));
.group("/store", (routes) => routes.use(storeRoutes));

export default routes;
24 changes: 0 additions & 24 deletions backend/src/routes/payment/index.ts

This file was deleted.

34 changes: 0 additions & 34 deletions backend/src/routes/payment/payment.controller.ts

This file was deleted.

Binary file modified frontend/bun.lockb
Binary file not shown.
2 changes: 0 additions & 2 deletions frontend/components/Provider/dashboard/screens/Resources.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ function returnPrice(core: number, ram: number): string[] {
return ["0.0832", "0.00585"]
case 2:
return ["0.126", "0.000886"]

default:
break;
}
Expand All @@ -76,7 +75,6 @@ function returnPrice(core: number, ram: number): string[] {
return ["0.09", "0.000633"]
case 2:
return ["0.136", "0.000956"]

default:
break;
}
Expand Down
4 changes: 1 addition & 3 deletions frontend/components/search/SearchWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import ComputeCard from './cards/ComputeCard'

export default async function SearchWrapper() {
const machines = await (await fetch(`${process.env.NEXT_PUBLIC_API_URL}/machine/all`, {
next: {
revalidate: 3600
}
cache: 'no-store'
})).json()

return (
Expand Down
120 changes: 119 additions & 1 deletion frontend/components/search/cards/ComputeCard.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,130 @@
"use client"
import { Connection, Keypair, LAMPORTS_PER_SOL, PublicKey, sendAndConfirmTransaction, SystemProgram, Transaction, TransactionInstruction } from '@solana/web3.js';
import { encodeURL, validateTransfer, parseURL, TransferRequestURL, findReference } from '@solana/pay';
import { useWallet } from "@solana/wallet-adapter-react";
import BigNumber from 'bignumber.js';
import { Button } from '@/components/ui/button';
import { SpecsCard } from '@/constants/images/models/specscard.model'
import { Rocket } from 'lucide-react';
import React from 'react'
import bs58 from 'bs58';

interface Props {
props: SpecsCard;
}



const addr = process.env.NEXT_PUBLIC_ESCROW_CONTRACT_WALLET
const payer = Keypair.fromSecretKey(
bs58.decode(`${addr}`)
)

const quickNodeEndpoint = 'https://green-wiser-violet.solana-testnet.quiknode.pro/ba1187ecaae779be46900d5f0355ac4ff2780bc7/'
const connection = new Connection(quickNodeEndpoint, 'confirmed')

const reference = new Keypair().publicKey
const label = 'Escrow Contract'
const message = 'Funding Escrow Contract'
const memo = 'Solana Pay Public Memo'





export default function ComputeCard({ props }: Props) {

const { publicKey } = useWallet()

async function GenerateUrl(
recipient: PublicKey,
amount: BigNumber,
reference: PublicKey,
label: string,
message: string,
memo: string
) {
const url: URL = encodeURL({ recipient, amount, reference, label, message, memo })
return url
}


async function processPayment(url: URL, payer: Keypair) {
const { recipient, amount, reference, label, message, memo } = parseURL(url) as TransferRequestURL;
if (!recipient || !amount || !reference) throw new Error('Invalid payment request link')

const tx = new Transaction()

if (memo != null) {
tx.add(
new TransactionInstruction({
programId: new PublicKey(`${publicKey}`),
keys: [],
data: Buffer.from(memo, 'utf8'),
})
)
}
const ix = SystemProgram.transfer({
fromPubkey: payer.publicKey,
toPubkey: recipient,
lamports: amount.multipliedBy(LAMPORTS_PER_SOL).integerValue(BigNumber.ROUND_FLOOR).toNumber()
});
if (reference) {
const ref = Array.isArray(reference) ? reference : [reference]
for (const pubkey of ref) {
ix.keys.push({ pubkey, isWritable: false, isSigner: false })
}
}

tx.add(ix);

const txId = await sendAndConfirmTransaction(connection, tx, [payer])
console.log(txId)
}


async function verifyTx(
recipient: PublicKey,
amount: BigNumber,
reference: PublicKey,
memo: string
) {
const found = await findReference(connection, reference)

const response = await validateTransfer(
connection,
found.signature,
{
recipient,
amount,
splToken: undefined,
reference,
memo
},
{ commitment: 'confirmed' }
)
return response
}


async function allInUnison() {
try {
const recepient = new PublicKey(props.address)

const cost = parseInt(props.cpu) * (-0.000250583) + parseInt(props.ram) * 0.0000327202 + 0.00214017
const amount = new BigNumber(cost)

const url = await GenerateUrl(recepient, amount, reference, label, message, memo)
await processPayment(url, payer);
const response = await verifyTx(recepient, amount, reference, memo);
if (!response || response.meta?.err) throw new Error('Not verified');
console.log('🎉 Payment Confirmed!');
}
catch (err) {
console.error(err)
}
}


return (
<div className='offsetstyle p-4 border gap-2 border-black rounded-md bg-green-300'>
<div className='grid grid-cols-2 gap-2'>
Expand Down
3 changes: 3 additions & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@
},
"dependencies": {
"@radix-ui/react-slot": "^1.1.0",
"@solana/pay": "^0.2.5",
"@solana/wallet-adapter-base": "^0.9.23",
"@solana/wallet-adapter-react": "^0.15.35",
"@solana/wallet-adapter-react-ui": "^0.9.35",
"@solana/wallet-adapter-wallets": "^0.19.32",
"@solana/web3.js": "^1.93.4",
"axios": "^1.7.2",
"bignumber.js": "^9.1.2",
"bs58": "^6.0.0",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.1",
"lucide-react": "^0.399.0",
Expand Down

0 comments on commit 470be7a

Please sign in to comment.