Question: Please DO NOT provide AI generated contents!! I AM LOOKING FOR A HUMAN EXPERT SOLUTIONS. have written this smartcontract for a decentralized rideshare appli cation.
Please DO NOT provide AI generated contents!! I
AM LOOKING FOR A HUMAN EXPERT SOLUTIONS.
have written this smartcontract for a decentralized rideshare appli cation.
This app will serve as a catuall ridesharing app for pople to make extra cash while they are heading to thier preffered destination such as soemone who uses hisger car can pickdrop someone on thier way tofrom work or any place they wish to go
This application is a ridesharing just like uber, but it will be similar to some social media platforms such as Facebook. This featres makes it smillart to facebook;
the users both driver and rider will register, sign in and send and aceepts friend requests from other.
Driver can post the ride to general public or just friends that tells heshe is going from point A to B
Rider can also post a ride request both to general public or just friends that looking for ride from point A to B
both parties will have the access to messaging section each other in private.
So please write a script to deploy and test it in Remix etherum and a full backend SPDXLicenseIdentifier: MIT
pragma solidity ;
contract RideSharing
Define a struct for User
struct User
string name;
bool isDriver;
uint rating;
uint rideCount;
Define a struct for Ride
struct Ride
address rider;
address driver;
uint fare;
bool isCompleted;
Mappings to store users and rides
mappingaddress User public users;
mappinguint Ride public rides;
Event declarations
event UserRegisteredaddress user, string name, bool isDriver;
event RideRequestedaddress rider, uint rideId;
event RideOfferedaddress driver, uint rideId;
event RideCompleteduint rideId, address rider, address driver;
event PaymentProcesseduint rideId, address rider, address driver, uint fare;
event RatingSubmittedaddress user, uint rating;
Counters for rides
uint public rideCounter ;
Function to register a new user
function registerUserstring memory name, bool isDriver public
requirebytesnamelength "Name is required";
requireusersmsgsenderrideCount "User already registered";
usersmsgsender User
name: name,
isDriver: isDriver,
rating:
rideCount:
;
emit UserRegisteredmsgsendername, isDriver;
Function to confirm a ride
function confirmRideuint rideId public
requireridesrideIdrider msgsender ridesrideIddriver msgsender "Only participants can confirm";
requireridesrideIddriver address "Ride not yet offered";
ridesrideIdisCompleted true;
emit RideCompletedrideId, ridesrideIdrider, ridesrideIddriver;
Function to process payment for a ride
function processPaymentuint rideId public payable
requireridesrideIdrider msgsender "Only rider can make payment";
requireridesrideIdisCompleted true, "Ride not completed";
address payable driver payableridesrideIddriver;
driver.transfermsgvalue;
emit PaymentProcessedrideId, msgsender driver, msgvalue;
Function to submit a rating for a user
function submitRatingaddress user, uint rating public
requirerating && rating "Rating should be between and ;
requireusersuserrideCount "User must have completed at least one ride";
usersuserrating usersuserrating usersuserrideCount ratingusersuserrideCount ;
usersuserrideCount;
emit RatingSubmitteduser, rating;
code.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
