Skip to content

Commit c3c3f7e

Browse files
authored
Merge branch 'master' into copilot/fix-54
2 parents dcaad68 + 2cb3903 commit c3c3f7e

File tree

5 files changed

+26
-9
lines changed

5 files changed

+26
-9
lines changed

package-lock.json

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"homepage": "https://github.com/openSVM/svmp2p#readme",
4040
"dependencies": {
4141
"@coral-xyz/anchor": "0.31.0",
42+
"@coral-xyz/anchor-cli": "^0.31.2",
4243
"@project-serum/anchor": "^0.26.0",
4344
"@solana/wallet-adapter-base": "0.9.24",
4445
"@solana/wallet-adapter-react": "0.15.36",

programs/p2p-exchange/src/instructions/disputes.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,6 @@ pub fn cast_vote(ctx: Context<CastVote>, vote_for_buyer: bool) -> Result<()> {
275275
if juror_index >= 3 {
276276
return Err(error!(ErrorCode::NotAJuror));
277277
}
278-
279278
// Double-check that this specific juror hasn't been counted already
280279
// This is extra safety on top of PDA-based duplicate prevention
281280
let mut vote_count = 0;
@@ -290,8 +289,9 @@ pub fn cast_vote(ctx: Context<CastVote>, vote_for_buyer: bool) -> Result<()> {
290289

291290
// Validate that the juror has not already voted
292291
// Check by using Vote PDA - if the account exists, they've already voted
293-
// This is handled by the PDA constraint in the CastVote accounts struct
294-
292+
// This is handled by the PDA constraint in the CastVote accounts struct=======
293+
// Note: PDA-based duplicate prevention ensures jurors can't vote twice
294+
// The vote account PDA will fail to initialize if the juror already voted
295295
// Initialize vote data (PDA prevents duplicate votes)
296296
vote.dispute = dispute.key();
297297
vote.juror = juror.key();

src/components/OfferCreation.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { useState, useContext } from 'react';
22
import { useConnection } from '@solana/wallet-adapter-react';
3-
import { SystemProgram, Keypair, LAMPORTS_PER_SOL } from '@solana/web3.js';
3+
import { SystemProgram, Keypair, LAMPORTS_PER_SOL, PublicKey } from '@solana/web3.js';
44
// Import BN from @coral-xyz/anchor as a fallback for @project-serum/anchor
55
import { BN } from '@coral-xyz/anchor';
66
import { AppContext } from '../contexts/AppContext';
@@ -98,8 +98,14 @@ const OfferCreation = ({ onStartGuidedWorkflow }) => {
9898
// Generate a new account for the offer
9999
const offer = Keypair.generate();
100100

101-
// Generate a new account for the escrow
102-
const escrow = Keypair.generate();
101+
// Calculate PDA for escrow account
102+
const [escrowAccount] = PublicKey.findProgramAddressSync(
103+
[
104+
Buffer.from("escrow"),
105+
offer.publicKey.toBuffer()
106+
],
107+
program.programId
108+
);
103109

104110
// Current timestamp
105111
const now = new BN(Math.floor(Date.now() / 1000));
@@ -118,10 +124,10 @@ const OfferCreation = ({ onStartGuidedWorkflow }) => {
118124
.accounts({
119125
offer: offer.publicKey,
120126
seller: wallet.publicKey,
121-
escrowAccount: escrow.publicKey,
127+
escrowAccount: escrowAccount,
122128
systemProgram: SystemProgram.programId,
123129
})
124-
.signers([offer, escrow])
130+
.signers([offer])
125131
.rpc();
126132

127133
setTxHash(createTx);

src/idl/p2p_exchange.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
{
1919
"name": "escrowAccount",
2020
"isMut": true,
21-
"isSigner": true
21+
"isSigner": false
2222
},
2323
{
2424
"name": "systemProgram",

0 commit comments

Comments
 (0)