From a1b58d599ec2ed1f5c19f4d5edd31edcfd6ee7c6 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 31 Oct 2024 00:13:08 +0530 Subject: [PATCH 1/8] add Contract Bytecode, update Contract ABI --- server/src/contracts/escrowContractABI.json | 208 +++++++++--------- .../src/contracts/escrowContractBYTECODE.json | 3 + 2 files changed, 108 insertions(+), 103 deletions(-) create mode 100644 server/src/contracts/escrowContractBYTECODE.json diff --git a/server/src/contracts/escrowContractABI.json b/server/src/contracts/escrowContractABI.json index 7893d7a..bfa2a3f 100644 --- a/server/src/contracts/escrowContractABI.json +++ b/server/src/contracts/escrowContractABI.json @@ -1,103 +1,105 @@ -[ - { - "inputs": [ - { - "internalType": "address", - "name": "_thirdParty", - "type": "address" - }, - { - "internalType": "uint256", - "name": "_deadlineInSecs", - "type": "uint256" - } - ], - "stateMutability": "payable", - "type": "constructor" - }, - { - "inputs": [], - "name": "amt", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "deadline", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "employer", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "isFundPresent", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "refundFunds", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address payable", - "name": "_payee", - "type": "address" - } - ], - "name": "releaseFunds", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [], - "name": "thirdParty", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - } -] \ No newline at end of file +{ + "abi":[ + { + "inputs": [ + { + "internalType": "address", + "name": "_thirdParty", + "type": "address" + }, + { + "internalType": "uint256", + "name": "_deadlineInSecs", + "type": "uint256" + } + ], + "stateMutability": "payable", + "type": "constructor" + }, + { + "inputs": [], + "name": "amt", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "deadline", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "employer", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "isFundPresent", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "refundFunds", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address payable", + "name": "_payee", + "type": "address" + } + ], + "name": "releaseFunds", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "thirdParty", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + } + ] +} \ No newline at end of file diff --git a/server/src/contracts/escrowContractBYTECODE.json b/server/src/contracts/escrowContractBYTECODE.json new file mode 100644 index 0000000..62452df --- /dev/null +++ b/server/src/contracts/escrowContractBYTECODE.json @@ -0,0 +1,3 @@ +{ + "bytecode" : "6080604052604051610b34380380610b34833981810160405281019061002591906101b1565b5f3411610067576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161005e90610249565b60405180910390fd5b335f806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508160015f6101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555080426100f29190610294565b60028190555034600481905550600160035f6101000a81548160ff02191690831515021790555050506102c7565b5f80fd5b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f61014d82610124565b9050919050565b61015d81610143565b8114610167575f80fd5b50565b5f8151905061017881610154565b92915050565b5f819050919050565b6101908161017e565b811461019a575f80fd5b50565b5f815190506101ab81610187565b92915050565b5f80604083850312156101c7576101c6610120565b5b5f6101d48582860161016a565b92505060206101e58582860161019d565b9150509250929050565b5f82825260208201905092915050565b7f416d6f756e74206d7573742062652067726561746572207468616e207a65726f5f82015250565b5f6102336020836101ef565b915061023e826101ff565b602082019050919050565b5f6020820190508181035f83015261026081610227565b9050919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b5f61029e8261017e565b91506102a98361017e565b92508282019050808211156102c1576102c0610267565b5b92915050565b610860806102d45f395ff3fe608060405234801561000f575f80fd5b506004361061007b575f3560e01c806330b5d4151161005957806330b5d415146100d757806349569b82146100f5578063ae200e79146100ff578063e02ea4841461011d5761007b565b806316eab96b1461007f578063192e7a7b1461009d57806329dcb0cf146100b9575b5f80fd5b61008761013b565b60405161009491906104de565b60405180910390f35b6100b760048036038101906100b29190610555565b610141565b005b6100c16102c5565b6040516100ce91906104de565b60405180910390f35b6100df6102cb565b6040516100ec919061059a565b60405180910390f35b6100fd6102dd565b005b61010761047e565b60405161011491906105d3565b60405180910390f35b6101256104a1565b60405161013291906105d3565b60405180910390f35b60045481565b60015f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146101d0576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016101c79061066c565b60405180910390fd5b60035f9054906101000a900460ff1661021e576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610215906106d4565b60405180910390fd5b600254421115610263576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161025a9061073c565b60405180910390fd5b5f60035f6101000a81548160ff0219169083151502179055508073ffffffffffffffffffffffffffffffffffffffff166108fc60045490811502906040515f60405180830381858888f193505050501580156102c1573d5f803e3d5ffd5b5050565b60025481565b60035f9054906101000a900460ff1681565b60015f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161461036c576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016103639061066c565b60405180910390fd5b60035f9054906101000a900460ff166103ba576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016103b1906107a4565b60405180910390fd5b60025442116103fe576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016103f59061080c565b60405180910390fd5b5f60035f6101000a81548160ff0219169083151502179055505f8054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166108fc60045490811502906040515f60405180830381858888f1935050505015801561047b573d5f803e3d5ffd5b50565b5f8054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60015f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b5f819050919050565b6104d8816104c6565b82525050565b5f6020820190506104f15f8301846104cf565b92915050565b5f80fd5b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f610524826104fb565b9050919050565b6105348161051a565b811461053e575f80fd5b50565b5f8135905061054f8161052b565b92915050565b5f6020828403121561056a576105696104f7565b5b5f61057784828501610541565b91505092915050565b5f8115159050919050565b61059481610580565b82525050565b5f6020820190506105ad5f83018461058b565b92915050565b5f6105bd826104fb565b9050919050565b6105cd816105b3565b82525050565b5f6020820190506105e65f8301846105c4565b92915050565b5f82825260208201905092915050565b7f4f6e6c792074686972642070617274792063616e2063616c6c207468697320665f8201527f756e6374696f6e00000000000000000000000000000000000000000000000000602082015250565b5f6106566027836105ec565b9150610661826105fc565b604082019050919050565b5f6020820190508181035f8301526106838161064a565b9050919050565b7f4e6f2066756e647320746f2072656c65617365000000000000000000000000005f82015250565b5f6106be6013836105ec565b91506106c98261068a565b602082019050919050565b5f6020820190508181035f8301526106eb816106b2565b9050919050565b7f446561646c696e652068617320706173736564000000000000000000000000005f82015250565b5f6107266013836105ec565b9150610731826106f2565b602082019050919050565b5f6020820190508181035f8301526107538161071a565b9050919050565b7f4e6f2066756e647320746f20726566756e6400000000000000000000000000005f82015250565b5f61078e6012836105ec565b91506107998261075a565b602082019050919050565b5f6020820190508181035f8301526107bb81610782565b9050919050565b7f446561646c696e6520686173206e6f74207061737365642079657400000000005f82015250565b5f6107f6601b836105ec565b9150610801826107c2565b602082019050919050565b5f6020820190508181035f830152610823816107ea565b905091905056fea26469706673582212202f46725f20a71046342028eaa58908a067ed7988abe3ee3dd800f30aa06b9fbd64736f6c634300081a0033" +} \ No newline at end of file From a94d75fd46d90aca2550259b9b8cd7aef652535e Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 31 Oct 2024 00:14:29 +0530 Subject: [PATCH 2/8] fix problem with session storage --- server/src/controllers/authController.js | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/server/src/controllers/authController.js b/server/src/controllers/authController.js index 06c5dce..58245d7 100644 --- a/server/src/controllers/authController.js +++ b/server/src/controllers/authController.js @@ -44,10 +44,7 @@ export const callback = async (req, res) => { } else { // If user doesn't exist, store GitHub user data in session and redirect to enter-wallet req.session.githubUser = { - githubId: userData.id, - username: userData.login, - email: userData.email || `${userData.login}@users.noreply.github.com`, - avatarUrl: userData.avatar_url, + githubId: userData.login // login is github username }; req.session.accessToken = accessToken; // Store access token for later use return res.redirect('/auth/enter-wallet'); @@ -96,9 +93,6 @@ export const addWallet = async (req, res) => { // Create a new user in the database const user = new User({ githubId: githubUser.githubId, - username: githubUser.username, - email: githubUser.email, - avatarUrl: githubUser.avatarUrl, walletAddress: walletAddress, }); From c10275d6963a867ff0010cb6c456e90ec8ea8f45 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 31 Oct 2024 00:15:57 +0530 Subject: [PATCH 3/8] add auth middleware --- server/src/controllers/projectController.js | 16 ++++++++------ server/src/middlewares/authMiddleware.js | 23 ++++++++++++++++++++- 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/server/src/controllers/projectController.js b/server/src/controllers/projectController.js index 7b660c0..f6d1003 100644 --- a/server/src/controllers/projectController.js +++ b/server/src/controllers/projectController.js @@ -30,7 +30,8 @@ export const getProjectById = async (req, res) => { // Create new project export const createNewProject = async (req, res) => { const { issueId, name, description, deadline, applicationDate, amount } = req.body; - const owner = req.user._id; // Assuming req.user is the logged-in user [check] + // const owner = req.session.userId; // Assuming req.session.userId is the logged-in user [check] + const owner = req.user; try { const newProject = new Project({ @@ -49,6 +50,7 @@ export const createNewProject = async (req, res) => { await newProject.save(); res.status(201).json({ message: 'Project created successfully.', project: newProject }); } catch (error) { + console.log(error); res.status(500).json({ message: 'Error creating project.' }); } }; @@ -56,12 +58,14 @@ export const createNewProject = async (req, res) => { // Apply to a project (add freelancer) export const apply = async (req, res) => { const { projectid } = req.params; - const { freelancerId } = req.user._id; + const freelancerId = req.user._id; try { const project = await Project.findById(projectid); if (!project) return res.status(404).json({ message: 'Project not found.' }); + console.log(`freelancer = ${freelancerId}`) + const freelancer = await User.findById(freelancerId); if (!freelancer) return res.status(404).json({ message: 'Freelancer not found.' }); @@ -117,7 +121,7 @@ export const removeApplication = async (req, res) => { export const submitPR = async (req, res) => { const { projectid } = req.params; const { prURL } = req.body; - const freelancerId = req.user._id; // Assuming the freelancer is the logged-in user + const freelancerId = req.user._id; try { const project = await Project.findById(projectid); @@ -140,7 +144,7 @@ export const submitPR = async (req, res) => { export const startProject = async (req, res) => { const { projectid } = req.params; - const ownerId = req.user._id; // Assuming req.user is the logged-in user (project owner) + const ownerId = req.user._id; // check try { const project = await Project.findById(projectid); @@ -160,7 +164,7 @@ export const startProject = async (req, res) => { // Update project status to "started" project.status = 'unresolved'; - const smartContractAddress = deploySmartContract(projectid); // id of smart contract + const smartContractAddress = deploySmartContract(projectid); // id of smart contract project.smartContractAddress = smartContractAddress; await project.save(); @@ -195,7 +199,7 @@ const triggerSmartContractHelper = async (projectid) => { } const freelancer = null; - // Check for the accepted PR + // Check for the accepted PR for (const pr in project.prURLs) { if (await isPRaccepted(pr)) { freelancer = findSubmitter(pr); diff --git a/server/src/middlewares/authMiddleware.js b/server/src/middlewares/authMiddleware.js index c4e35d3..6cb83cb 100644 --- a/server/src/middlewares/authMiddleware.js +++ b/server/src/middlewares/authMiddleware.js @@ -1 +1,22 @@ -// User authentication (cookie-parsing) middleware \ No newline at end of file +// User authentication (cookie-parsing) middleware +import User from '../models/userModel.js'; + +export const getLoggedInUser = async (req, res, next) => { + try { + req.session.userId = "Aradhya2708"; + if (!req.session || !req.session.userId) { + return res.status(401).json({ message: 'Unauthorized. No user session found.' }); + } + + const user = await User.findOne({ githubId: req.session.userId }); + if (!user) { + return res.status(404).json({ message: 'User not found.' }); + } + + req.user = user; // Attach the user object to the request + console.log("req.user._id = ", req.user._id); + next(); // Pass control to the next middleware or route handler + } catch (error) { + res.status(500).json({ message: 'Error retrieving user information.' }); + } +}; From 68c601b8aded482daff40f9f2217bb9a72e9903b Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 31 Oct 2024 00:16:28 +0530 Subject: [PATCH 4/8] update project model --- server/src/models/projectModel.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/models/projectModel.js b/server/src/models/projectModel.js index 148663c..da1b803 100644 --- a/server/src/models/projectModel.js +++ b/server/src/models/projectModel.js @@ -15,7 +15,7 @@ const projectSchema = new mongoose.Schema({ required: true }, deadline: { // problem - type: Date, + type: Number, required: true }, applicationDate: { From 39dde7447bd3b745da1b54d220b4bacc567a1c1d Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 31 Oct 2024 00:17:43 +0530 Subject: [PATCH 5/8] minor fix in routes, updated JSON handling --- server/src/app.js | 5 +++-- server/src/routes/authRoutes.js | 11 +++------- server/src/routes/projectRoutes.js | 32 ++++++++++++++++++++---------- 3 files changed, 27 insertions(+), 21 deletions(-) diff --git a/server/src/app.js b/server/src/app.js index 9858399..fa4adf0 100644 --- a/server/src/app.js +++ b/server/src/app.js @@ -8,7 +8,6 @@ import "dotenv/config" // import routes import authRoutes from './routes/authRoutes.js' import projectRoutes from './routes/projectRoutes.js' -import contributionRoutes from './routes/contributionRoutes.js' const app = express() @@ -30,10 +29,12 @@ app.use( app.use(bodyParser()) app.use(cookieParser()) +app.use(express.json({ limit: '16kb' })); +app.use(express.urlencoded({ extended: true })); +app.use(express.static('public')); // define (mount) routes app.use('/auth', authRoutes); app.use('/project', projectRoutes); -app.use('/contribution', contributionRoutes); export { app } \ No newline at end of file diff --git a/server/src/routes/authRoutes.js b/server/src/routes/authRoutes.js index 513acf5..df84566 100644 --- a/server/src/routes/authRoutes.js +++ b/server/src/routes/authRoutes.js @@ -22,22 +22,17 @@ router.get('/safe', async (req, res) => { } // Find the user by ID - const user = await User.findById(req.session.userId); + const user = await User.findById(req.session.userId); // cookies if (!user) { return res.status(404).send('User not found.'); } // Render a message with the user's username - res.send(`Hey, you are ${user.username}!`); // Display a simple message + res.send(`Hey, you are ${user.githubId}! and your cookie is ${req.session.accessToken}`); // Display a simple message }); // route to add wallet address router.post('/add-wallet', addWallet); -export default router; - -/** - * axios.get('/backend/auth/logout') - * - */ \ No newline at end of file +export default router; \ No newline at end of file diff --git a/server/src/routes/projectRoutes.js b/server/src/routes/projectRoutes.js index 10c405f..949e90d 100644 --- a/server/src/routes/projectRoutes.js +++ b/server/src/routes/projectRoutes.js @@ -1,20 +1,30 @@ +// routes/projectRoutes.js import express from 'express'; -import { getAllProjects, getProjectById, createNewProject, apply, removeApplication, submitPR, getStatus, startProject } from '../controllers/projectController.js'; +import { + getAllProjects, + getProjectById, + createNewProject, + apply, + removeApplication, + submitPR, + getStatus, + startProject, +} from '../controllers/projectController.js'; +import { getLoggedInUser } from '../middlewares/authMiddleware.js'; const router = express.Router(); -// use() auth middleware - +// Apply the `getLoggedInUser` middleware where logged-in user access is needed router.get(`/`, getAllProjects); -router.get(`/:projectid`, getProjectById); -router.post(`/`, createNewProject); +router.get(`/:projectid`, getLoggedInUser, getProjectById); +router.post(`/`, getLoggedInUser, createNewProject); -// utility routes (delete etc) -router.get(`/:projectid/apply`, apply); -router.get(`/:projectid/remove/:freelancerid`, removeApplication); -router.post(`/:projectid/submitPR`, submitPR); -router.get(`/:projectid/status`, getStatus); // route for webhook stuff +// Utility routes with logged-in user check +router.get(`/:projectid/apply`, getLoggedInUser, apply); +router.get(`/:projectid/remove/:freelancerid`, getLoggedInUser, removeApplication); +router.post(`/:projectid/submitPR`, getLoggedInUser, submitPR); +router.get(`/:projectid/status`, getStatus); -router.get(`/:projectid/start`, startProject) // only owner. deploy sc +router.get(`/:projectid/start`, getLoggedInUser, startProject); export default router; From cca2574998bf1a8be55d79f0a96ac90f929cd3b8 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 31 Oct 2024 00:20:17 +0530 Subject: [PATCH 6/8] update web3 functions, environment variables --- server/.env.sample | 5 ++++- server/src/utils/web3Utils.js | 40 ++++++++++++++++++++++++++++------- 2 files changed, 36 insertions(+), 9 deletions(-) diff --git a/server/.env.sample b/server/.env.sample index ffb6f7e..ee40336 100644 --- a/server/.env.sample +++ b/server/.env.sample @@ -5,4 +5,7 @@ MONGODB_URI GITHUB_OAUTH_CLIENT_ID GITHUB_OAUTH_CLIENT_SECRET WALLET_PRIVATE_KEY -INFURA_URL \ No newline at end of file +INFURA_URL +APP_WALLET +INFURA_PROJECT_ID +INFURA_SECRET_KEY \ No newline at end of file diff --git a/server/src/utils/web3Utils.js b/server/src/utils/web3Utils.js index 24d7be3..67e6460 100644 --- a/server/src/utils/web3Utils.js +++ b/server/src/utils/web3Utils.js @@ -1,10 +1,22 @@ import Web3 from 'web3'; -import { CONTRACT_BYTECODE, CONTRACT_ABI } from '../contracts/escrowContractABI.json'; // Ensure ABI is imported for contract interaction +import CONTRACT_ABI_JSON from '../contracts/escrowContractABI.json' with { type: "json" }; // Ensure ABI is imported for contract interaction +import CONTRACT_BYTECODE_JSON from '../contracts/escrowContractBYTECODE.json' with { type: "json" }; import Project from '../models/projectModel.js'; import User from '../models/userModel.js'; import "dotenv/config" -const web3 = new Web3(new Web3.providers.HttpProvider(process.env.INFURA_URL)); +const CONTRACT_ABI = CONTRACT_ABI_JSON.abi +const CONTRACT_BYTECODE = CONTRACT_BYTECODE_JSON.bytecode + +const web3 = new Web3(new Web3.providers.HttpProvider(`https://sepolia.infura.io/v3/${process.env.INFURA_PROJECT_ID}`, { + headers: [ + { + name: 'Authorization', + value: `Basic ${Buffer.from(`${process.env.INFURA_PROJECT_ID}:${process.env.INFURA_SECRET_KEY}`).toString('base64')}` + } + ] +}));// metamask here? +//`https://ethereum.stackexchange.com/questions/67145/how-to-connect-web3-with-metamask` // Function to deploy the Escrow contract export const deploySmartContract = async (projectid) => { @@ -22,6 +34,7 @@ export const deploySmartContract = async (projectid) => { const deployerAccount = accounts[0]; // Assume the first account is the deployer // Create the contract instance + console.log("Contract Abi = ", CONTRACT_ABI); const contract = new web3.eth.Contract(CONTRACT_ABI); // ABI is needed for contract interactions // Deploy the contract with specified parameters @@ -33,6 +46,8 @@ export const deploySmartContract = async (projectid) => { // Estimate gas for the transaction const gasEstimate = await deployTx.estimateGas({ from: deployerAccount, value: amount }); + console.log("deployer Acc = ", deployerAccount) + // Send the transaction const deployedContract = await deployTx.send({ from: deployerAccount, @@ -71,14 +86,23 @@ export const triggerSmartContract = async (projectId, freelancerGithubName) => { // Step 3: Create a contract instance and call releaseFunds const contract = new web3.eth.Contract(CONTRACT_BYTECODE, contractAddress); - // Assume that the account performing the transaction is unlocked or is using MetaMask or similar for transaction signing - const accounts = await web3.eth.getAccounts(); // Replace with appropriate signing account or method - const fromAccount = accounts[0]; // Assuming the first account is used + // Encode the transaction data to call releaseFunds with the specified wallet address + const txData = contract.methods.releaseFunds(walletAddress).encodeABI(); + + // Step 4: Define the transaction parameters + const txParams = { + to: contractAddress, + data: txData, + gas: await contract.methods.releaseFunds(walletAddress).estimateGas(), // Estimate gas required + chainId: await web3.eth.getChainId(), + }; - // Call releaseFunds on the contract, passing the wallet address as the payee - const tx = await contract.methods.releaseFunds(walletAddress).send({ from: fromAccount }); + // Step 5: Sign the transaction with the private key from .env + const signedTx = await web3.eth.accounts.signTransaction(txParams, `0x${process.env.WALLET_PRIVATE_KEY}`); - console.log(`Funds released to ${walletAddress} for project ID ${projectId}. Transaction hash: ${tx.transactionHash}`); + // Step 6: Send the signed transaction to the network + const receipt = await web3.eth.sendSignedTransaction(signedTx.rawTransaction); + console.log(`Funds released to ${walletAddress} for project ID ${projectId}. Transaction hash: ${receipt.transactionHash}`); } catch (error) { console.error(`Error triggering smart contract for project ID ${projectId}:`, error); } From 6f3adceef9c751842a5caf31706d34c301eb16ca Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 31 Oct 2024 00:20:57 +0530 Subject: [PATCH 7/8] minor fix --- server/src/controllers/userController.js | 1 - server/src/routes/contributionRoutes.js | 23 ----------------------- server/src/utils/web3Utils.js | 3 --- 3 files changed, 27 deletions(-) delete mode 100644 server/src/controllers/userController.js delete mode 100644 server/src/routes/contributionRoutes.js diff --git a/server/src/controllers/userController.js b/server/src/controllers/userController.js deleted file mode 100644 index 366c895..0000000 --- a/server/src/controllers/userController.js +++ /dev/null @@ -1 +0,0 @@ -// Handles user-related actions (registration, login). \ No newline at end of file diff --git a/server/src/routes/contributionRoutes.js b/server/src/routes/contributionRoutes.js deleted file mode 100644 index c7abb10..0000000 --- a/server/src/routes/contributionRoutes.js +++ /dev/null @@ -1,23 +0,0 @@ -import express from 'express'; -import { - approveContribution, - submitPullRequest, - checkContributionStatus, - getContributionsForProject, -} from '../controllers/contributionController.js'; - -const router = express.Router(); - -// Route to get contributions for a specific project -router.get('/project/:projectId', getContributionsForProject); - -// Route to approve a contribution -router.post('/:projectId/:contributionId/approve', approveContribution); - -// Route to submit a PR for a contribution -router.post('/:contributionId/submit-pr', submitPullRequest); - -// Route to check the contribution status (e.g., PR merged or not) -router.get('/:contributionId/check-status', checkContributionStatus); - -export default router; diff --git a/server/src/utils/web3Utils.js b/server/src/utils/web3Utils.js index 67e6460..6416550 100644 --- a/server/src/utils/web3Utils.js +++ b/server/src/utils/web3Utils.js @@ -34,7 +34,6 @@ export const deploySmartContract = async (projectid) => { const deployerAccount = accounts[0]; // Assume the first account is the deployer // Create the contract instance - console.log("Contract Abi = ", CONTRACT_ABI); const contract = new web3.eth.Contract(CONTRACT_ABI); // ABI is needed for contract interactions // Deploy the contract with specified parameters @@ -46,8 +45,6 @@ export const deploySmartContract = async (projectid) => { // Estimate gas for the transaction const gasEstimate = await deployTx.estimateGas({ from: deployerAccount, value: amount }); - console.log("deployer Acc = ", deployerAccount) - // Send the transaction const deployedContract = await deployTx.send({ from: deployerAccount, From aaa2c74dede306f9528389321c5961295f3dcef3 Mon Sep 17 00:00:00 2001 From: Aradhya2708 Date: Wed, 6 Nov 2024 00:57:11 +0530 Subject: [PATCH 8/8] resolve conflicts --- server/src/controllers/projectController.js | 7 ------- 1 file changed, 7 deletions(-) diff --git a/server/src/controllers/projectController.js b/server/src/controllers/projectController.js index a8dfeb3..fc34b9d 100644 --- a/server/src/controllers/projectController.js +++ b/server/src/controllers/projectController.js @@ -29,9 +29,6 @@ export const getProjectById = async (req, res) => { // Create new project export const createNewProject = async (req, res) => { - const { issueId, name, description, deadline, applicationDate, amount } = req.body; - // const owner = req.session.userId; // Assuming req.session.userId is the logged-in user [check] - const owner = req.user; const { issueId, name, description, deadline, applicationDate, amountInWei } = req.body; // const owner = req.session.userId; // Assuming req.session.userId is the logged-in user [check] const owner = req.user; @@ -63,7 +60,6 @@ export const createNewProject = async (req, res) => { export const apply = async (req, res) => { const { projectid } = req.params; const freelancerId = req.user._id; - const freelancerId = req.user._id; try { const project = await Project.findById(projectid); @@ -129,7 +125,6 @@ export const submitPR = async (req, res) => { const { projectid } = req.params; const { prURL } = req.body; const freelancerId = req.user._id; - const freelancerId = req.user._id; try { const project = await Project.findById(projectid); @@ -153,7 +148,6 @@ export const submitPR = async (req, res) => { export const startProject = async (req, res) => { const { projectid } = req.params; const ownerId = req.user._id; // check - const ownerId = req.user._id; // check try { const project = await Project.findById(projectid); @@ -173,7 +167,6 @@ export const startProject = async (req, res) => { // Update project status to "started" project.status = 'unresolved'; - const smartContractAddress = deploySmartContract(projectid); // id of smart contract const smartContractAddress = deploySmartContract(projectid); // id of smart contract project.smartContractAddress = smartContractAddress; await project.save();