This repository contains a Move-based smart contract for a decentralized car pooling service. The car pooling system allows users to register as passengers or drivers, create trips, join trips, and handle payments securely on the blockchain. The contract is designed to ensure trust and automation between the parties involved in car pooling, with features such as trip management, fare collection, and withdrawals for both passengers and the car pooling service management.
- Passenger Registration: Users can register as passengers and deposit funds into their accounts.
- Trip Creation: Drivers can create new trips, specifying the destination and fare.
- Trip Joining: Passengers can join available trips and pay the fare.
- Service Fees: The car pooling service can charge a fee for managing trips.
- Secure Payments: Funds are held in a pool until the trip is completed, after which they are transferred to the driver.
- Balance Management: Passengers and service management can deposit or withdraw funds as needed.
This struct represents the car pooling service and manages the following:
- A list of all active trips.
- The service's wallet containing collected fees.
- The service fee rate.
- The management's address.
Represents an individual car pooling trip:
- Tracks passengers and driver.
- Stores destination and fare.
- Holds the pool of funds collected for the trip.
- Indicates whether the trip has been completed.
Represents a passenger in the system:
- Tracks the passenger's address and their balance of deposited funds.
ENotOwner
: Unauthorized access by someone other than the service management.ENotPassenger
: Action attempted by someone who is not a registered passenger.EInsufficientBalance
: When a passenger or service wallet does not have enough balance.ETripCompleted
: Attempt to interact with a trip that has already been completed.
init(ctx: &mut TxContext)
: Initializes the car pooling service. It creates aServiceCap
object that manages trips and collects service fees.
set_service_fee(service: &mut ServiceCap, fee: u64, ctx: &mut TxContext)
: Allows the service management to set or change the service fee.withdraw_wallet(service: &mut ServiceCap, amount: u64, ctx: &mut TxContext)
: Withdraws funds from the service wallet by the management.
add_passenger(passenger: address, ctx: &mut TxContext)
: Registers a new passenger with an initial balance of zero.deposit(passenger: &mut Passenger, amount: Coin<SUI>)
: Deposits funds into the passenger's balance.withdraw(passenger: &mut Passenger, amount: u64, ctx: &mut TxContext)
: Allows a passenger to withdraw funds from their balance.
create_trip(service: &mut ServiceCap, driver: address, destination: String, fare: u64, ctx: &mut TxContext)
: Creates a new trip managed by the service with a driver, destination, and fare.join_trip(trip: &mut Trip, passenger: &mut Passenger, ctx: &mut TxContext)
: Allows a passenger to join a trip if they have sufficient balance to cover the fare.complete_trip(trip: &mut Trip, ctx: &mut TxContext)
: Completes the trip and transfers the funds in the trip pool to the driver.
view_trips(service: &ServiceCap)
: Returns a list of all active trips.
The contract uses assertions to ensure safe execution. If any condition fails (e.g., insufficient balance, unauthorized access), the corresponding error code will be thrown, ensuring no unintended operations can occur.
- Install the necessary tools for working with Move smart contracts.
- Build the contract and deploy it to a SUI-based blockchain environment.
- Interact with the smart contract by invoking the relevant functions for passenger registration, trip creation, and joining trips.
- Reputation System: Introduce a reputation system for drivers and passengers based on completed trips.
- Dynamic Pricing: Implement dynamic fare adjustments based on demand and distance.
- Cancellation Policy: Add support for trip cancellation and refunds for passengers.
This project is open-source and available under the MIT License.
Feel free to explore the codebase and customize it for your specific needs!