Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ make build
# Build specific contracts
make build-escrow
make build-delivery
make build-dispute
```

**For Windows Users (or users without Make):**
Expand All @@ -61,6 +62,7 @@ cargo build --target wasm32-unknown-unknown --release
# Build specific contracts
cargo build -p escrow_contract --target wasm32-unknown-unknown --release
cargo build -p delivery_contract --target wasm32-unknown-unknown --release
cargo build -p dispute_resolution_contract --target wasm32-unknown-unknown --release
```

## Testing Guidelines
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ build-delivery:
cargo build -p delivery_contract --target wasm32-unknown-unknown --release
@echo "Delivery contract built successfully!"

build-dispute:
cargo build -p dispute_resolution_contract --target wasm32-unknown-unknown --release
@echo "Dispute resolution contract built successfully!"

clean:
cargo clean

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ SwiftChain-SmartContract/
```bash
make build-escrow
make build-delivery
make build-dispute
```

To run tests:
Expand All @@ -263,6 +264,7 @@ SwiftChain-SmartContract/
```bash
cargo build -p escrow_contract --target wasm32-unknown-unknown --release
cargo build -p delivery_contract --target wasm32-unknown-unknown --release
cargo build -p dispute_resolution_contract --target wasm32-unknown-unknown --release
```

To run tests:
Expand Down
16 changes: 1 addition & 15 deletions contracts/delivery_contract/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,13 @@

use shared_types::SwiftChainError;
use shared_types::{delivery_key, DeliveryMetadata, DriverProfile, StorageKey};
pub use shared_types::{DeliveryId, DeliveryStatus};
pub use shared_types::{DeliveryId, DeliveryStatus, DeliveryRecord};
use soroban_sdk::{
contract, contracterror, contractimpl, contracttype, panic_with_error, Address, Env, Symbol,
};

// Local DeliveryMetadata removed in favor of shared_types::DeliveryMetadata

#[contracttype]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct DeliveryRecord {
pub delivery_id: DeliveryId,
pub sender: Address,
pub recipient: Address,
pub driver: Option<Address>,
pub status: DeliveryStatus,
pub metadata: DeliveryMetadata,
pub created_at: u64,
pub delivered_at: Option<u64>,
pub transit_started_at: Option<u64>,
}

#[contracttype]
#[derive(Clone)]
pub enum DataKey {
Expand Down
11 changes: 9 additions & 2 deletions contracts/dispute_resolution_contract/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,23 @@
name = "dispute_resolution_contract"
version = "0.1.0"
edition = "2021"
description = "Soroban dispute resolution smart contract for SwiftChain logistics escrow workflows."
license = "MIT"
repository = "https://github.com/SwiftChainn/SwiftChain-SmartContract"
authors = ["SwiftChain Contributors <dev@swiftchain.org>"]
keywords = ["soroban", "stellar", "escrow", "dispute", "logistics", "blockchain"]
homepage = "https://github.com/SwiftChainn/SwiftChain-SmartContract"
documentation = "https://github.com/SwiftChainn/SwiftChain-SmartContract#readme"

[lib]
path = "lib.rs"
crate-type = ["cdylib", "rlib"]

[dependencies]
soroban-sdk = { workspace = true }
delivery_contract = { path = "../delivery_contract" }
escrow_contract = { path = "../escrow_contract" }
shared_types = { path = "../shared_types" }

[dev-dependencies]
soroban-sdk = { workspace = true, features = ["testutils"] }
delivery_contract = { path = "../delivery_contract" }
escrow_contract = { path = "../escrow_contract" }
46 changes: 29 additions & 17 deletions contracts/dispute_resolution_contract/lib.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#![no_std]

use soroban_sdk::{
contract, contractimpl, contracttype, panic_with_error, Address, BytesN, Env, Symbol,
Vec,
contract, contractimpl, contracttype, panic_with_error, Address, BytesN, Env, IntoVal,
Symbol, Vec,
};
use shared_types::{DeliveryId, SwiftChainError};
use delivery_contract::{DeliveryContractClient, DeliveryStatus};
use shared_types::{DeliveryId, DeliveryStatus, EscrowRecord, EscrowStatus, SwiftChainError};

#[contracttype]
#[derive(Clone, Debug, Eq, PartialEq)]
Expand Down Expand Up @@ -105,10 +104,11 @@ impl DisputeResolutionContract {
caller.require_auth();

let delivery_contract_addr = Self::get_delivery_contract(env.clone());
let delivery_client = DeliveryContractClient::new(&env, &delivery_contract_addr);

// Fetch the delivery record
let delivery = delivery_client.get_delivery(&delivery_id);
let delivery: shared_types::DeliveryRecord = env.invoke_contract(
&delivery_contract_addr,
&Symbol::new(&env, "get_delivery"),
soroban_sdk::vec![&env, delivery_id.into_val(&env)],
);

// Verify the caller is sender or recipient
if caller != delivery.sender && caller != delivery.recipient {
Expand All @@ -127,16 +127,23 @@ impl DisputeResolutionContract {
}
DeliveryStatus::Active | DeliveryStatus::InTransit => {
// Call delivery contract to transition to Disputed and pause escrow
delivery_client.raise_dispute(&caller, &delivery_id);
let _: () = env.invoke_contract(
&delivery_contract_addr,
&Symbol::new(&env, "raise_dispute"),
soroban_sdk::vec![&env, caller.into_val(&env), delivery_id.into_val(&env)],
);
}
_ => {
panic_with_error!(&env, SwiftChainError::InvalidState);
}
}

let escrow_addr = Self::get_escrow_contract(env.clone());
let escrow_client = escrow_contract::EscrowContractClient::new(&env, &escrow_addr);
escrow_client.freeze_funds(&u64::from(delivery_id));
let _: () = env.invoke_contract(
&escrow_addr,
&Symbol::new(&env, "freeze_funds"),
soroban_sdk::vec![&env, u64::from(delivery_id).into_val(&env)],
);

let dispute_key = DataKey::Dispute(delivery_id);
if env.storage().persistent().has(&dispute_key) {
Expand Down Expand Up @@ -180,8 +187,11 @@ impl DisputeResolutionContract {
}

let delivery_contract_addr = Self::get_delivery_contract(env.clone());
let delivery_client = DeliveryContractClient::new(&env, &delivery_contract_addr);
let delivery = delivery_client.get_delivery(&delivery_id);
let delivery: shared_types::DeliveryRecord = env.invoke_contract(
&delivery_contract_addr,
&Symbol::new(&env, "get_delivery"),
soroban_sdk::vec![&env, delivery_id.into_val(&env)],
);

if caller != delivery.sender && caller != delivery.recipient {
panic_with_error!(&env, SwiftChainError::Unauthorized);
Expand Down Expand Up @@ -265,11 +275,13 @@ impl DisputeResolutionContract {
env.storage().persistent().extend_ttl(&dispute_key, 518400, 518400);

let escrow_addr = Self::get_escrow_contract(env.clone());
let escrow_client = escrow_contract::EscrowContractClient::new(&env, &escrow_addr);
let escrow = escrow_client.get_escrow(&u64::from(delivery_id));
let escrow: EscrowRecord = env.invoke_contract(
&escrow_addr,
&Symbol::new(&env, "get_escrow"),
soroban_sdk::vec![&env, u64::from(delivery_id).into_val(&env)],
);

if escrow.status == shared_types::EscrowStatus::Paused {
use soroban_sdk::IntoVal;
if escrow.status == EscrowStatus::Paused {
let _: () = env.invoke_contract(
&escrow_addr,
&Symbol::new(&env, "resolve_dispute_split"),
Expand Down
14 changes: 14 additions & 0 deletions contracts/shared_types/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,20 @@ pub enum DeliveryStatus {
Cancelled,
}

#[contracttype]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct DeliveryRecord {
pub delivery_id: DeliveryId,
pub sender: Address,
pub recipient: Address,
pub driver: Option<Address>,
pub status: DeliveryStatus,
pub metadata: DeliveryMetadata,
pub created_at: u64,
pub delivered_at: Option<u64>,
pub transit_started_at: Option<u64>,
}

#[contracttype]
#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord)]
pub enum EscrowState {
Expand Down