diff --git a/.gitignore b/.gitignore index 0c57fcf..f8a5ea8 100644 --- a/.gitignore +++ b/.gitignore @@ -11,10 +11,11 @@ # next.js /.next/ /out/ - +.env # production /build +.yarn # misc .DS_Store *.pem @@ -37,4 +38,4 @@ yarn-error.log* *.tsbuildinfo # logs -*.log \ No newline at end of file +*.log diff --git a/package.json b/package.json index 8d00a83..17ca118 100644 --- a/package.json +++ b/package.json @@ -3,24 +3,33 @@ "version": "0.2.0", "author": "Solana Maintainers ", "license": "MIT", - "private": false, "scripts": { "dev": "next dev", "build": "next build", "start": "next start", "lint": "next lint" }, + "resolutions": { + "blake3-wasm": "^3.0.0", + "@c4312/blake3-internal": "^3.0.0" + }, "dependencies": { "@heroicons/react": "^1.0.5", "@noble/ed25519": "^1.7.1", + "@project-serum/anchor": "^0.26.0", "@solana/wallet-adapter-base": "^0.9.22", "@solana/wallet-adapter-react": "^0.15.32", "@solana/wallet-adapter-react-ui": "^0.9.31", "@solana/wallet-adapter-wallets": "^0.19.16", "@solana/web3.js": "^1.73.0", "@tailwindcss/typography": "^0.5.9", + "axios": "^1.7.2", + "blake3-wasm": "^3.0.0", + "borsh": "^2.0.0", + "bs58": "^5.0.0", "daisyui": "^1.24.3", "date-fns": "^2.29.3", + "hash-wasm": "^4.11.0", "immer": "^9.0.12", "next": "^13.1.5", "next-compose-plugins": "^2.2.1", diff --git a/src/components/SendTransaction.tsx b/src/components/SendTransaction.tsx index 5e6aa10..3639356 100644 --- a/src/components/SendTransaction.tsx +++ b/src/components/SendTransaction.tsx @@ -1,13 +1,18 @@ import { useConnection, useWallet } from '@solana/wallet-adapter-react'; -import { Keypair, SystemProgram, Transaction, TransactionMessage, TransactionSignature, VersionedTransaction } from '@solana/web3.js'; +import { AccountInfo, Keypair, PublicKey, SystemProgram, SYSVAR_CLOCK_PUBKEY, Transaction, TransactionMessage, TransactionSignature, VersionedTransaction } from '@solana/web3.js'; +import axios, { AxiosResponse } from 'axios'; +import { SPVProxyResponse } from 'pages/api/proxy'; import { FC, useCallback } from 'react'; +import { monitorAndVerifyUpdates } from 'spv/client'; +import { COPY_PROGRAM_ID, getCopyProgram } from 'spv/program'; import { notify } from "../utils/notifications"; export const SendTransaction: FC = () => { const { connection } = useConnection(); - const { publicKey, sendTransaction } = useWallet(); + const { publicKey, sendTransaction,signTransaction } = useWallet(); const onClick = useCallback(async () => { + if (!publicKey) { notify({ type: 'error', message: `Wallet not connected!` }); console.log('error', `Send Transaction: Wallet not connected!`); @@ -16,37 +21,68 @@ export const SendTransaction: FC = () => { let signature: TransactionSignature = ''; try { + const copyProgram = getCopyProgram("http://" + (process.env.NEXT_PUBLIC_HOST || "127.0.0.1") + ":8899",Keypair.generate().secretKey,COPY_PROGRAM_ID); + // ; +let toAccount = new PublicKey("gvtVGeQAm5e1fprqZt3xmzTuTWKdTbbytr269wv4yS6"); + +let [account_for_proof,bump] = PublicKey.findProgramAddressSync([Buffer.from("copy_hash")],copyProgram.programId) +console.log("account_for_proof: ",account_for_proof); + let spv_ix = await copyProgram.methods.copyHash(bump).accounts({ + copyAccount: account_for_proof, + sourceAccount: account_for_proof, + clock: SYSVAR_CLOCK_PUBKEY, + systemProgram: SystemProgram.programId, + creator: publicKey + }).instruction(); + // console.log("txn_hash:",txn) // Create instructions to send, in this case a simple transfer const instructions = [ SystemProgram.transfer({ fromPubkey: publicKey, - toPubkey: Keypair.generate().publicKey, - lamports: 1_000_000, + toPubkey: toAccount, + lamports: 1_000, }), + spv_ix ]; // Get the lates block hash to use on our transaction and confirmation - let latestBlockhash = await connection.getLatestBlockhash() - + // let latestBlockhash = await connection.getLatestBlockhash() + let txn = new Transaction().add(instructions[0]).add(instructions[1]); // Create a new TransactionMessage with version and compile it to legacy - const messageLegacy = new TransactionMessage({ - payerKey: publicKey, - recentBlockhash: latestBlockhash.blockhash, - instructions, - }).compileToLegacyMessage(); + // const messageLegacy = new TransactionMessage({ + // payerKey: publicKey, + // recentBlockhash: latestBlockhash.blockhash, + // instructions, + // }).compileToLegacyMessage(); // Create a new VersionedTransacction which supports legacy and v0 - const transation = new VersionedTransaction(messageLegacy) + // const transation = new VersionedTransaction(messageLegacy) + let blockhash = (await connection.getLatestBlockhash('finalized')).blockhash; + txn.recentBlockhash = blockhash; + txn.feePayer = publicKey; + txn = await signTransaction(txn); // Send transaction and await for signature - signature = await sendTransaction(transation, connection); + // signature = await connection.sendRawTransaction(txn.serialize(),{ + // skipPreflight: true, + // + // }); + let account_state = await copyProgram.provider.connection.getAccountInfo(account_for_proof,"processed"); + let spv_proxy_response: AxiosResponse = await axios.post("/api/proxy",{ + txn: txn.serialize().toString("base64") + }) + console.log("done",spv_proxy_response.data.update) // Send transaction and await for signature - await connection.confirmTransaction({ signature, ...latestBlockhash }, 'confirmed'); + // await connection.confirmTransaction({ signature, ...latestBlockhash }, 'processed'); + // console.log("not") - console.log(signature); - notify({ type: 'success', message: 'Transaction successful!', txid: signature }); + // let spv_res = true + let spv_res = await monitorAndVerifyUpdates(account_for_proof,account_state as AccountInfo,copyProgram,bump,"145.40.125.153",spv_proxy_response.data.update); + console.log(spv_res); + spv_res && notify({ type: 'success', message: 'SPV & Txn successful!', txid: spv_proxy_response.data.signature}); + !spv_res && notify({ type: 'error', message: 'Transaction successful but spv fails', txid: spv_proxy_response.data.signature }); } catch (error: any) { notify({ type: 'error', message: `Transaction failed!`, description: error?.message, txid: signature }); console.log('error', `Transaction failed! ${error?.message}`, signature); @@ -57,7 +93,7 @@ export const SendTransaction: FC = () => { return (
-