diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 9e6003c..712e181 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -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):**
@@ -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
diff --git a/Makefile b/Makefile
index 55d0c94..b778238 100644
--- a/Makefile
+++ b/Makefile
@@ -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
diff --git a/README.md b/README.md
index 774a887..d431767 100644
--- a/README.md
+++ b/README.md
@@ -243,6 +243,7 @@ SwiftChain-SmartContract/
```bash
make build-escrow
make build-delivery
+ make build-dispute
```
To run tests:
@@ -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:
diff --git a/contracts/delivery_contract/lib.rs b/contracts/delivery_contract/lib.rs
index fc6c6fe..ab78f21 100644
--- a/contracts/delivery_contract/lib.rs
+++ b/contracts/delivery_contract/lib.rs
@@ -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
,
- pub status: DeliveryStatus,
- pub metadata: DeliveryMetadata,
- pub created_at: u64,
- pub delivered_at: Option,
- pub transit_started_at: Option,
-}
-
#[contracttype]
#[derive(Clone)]
pub enum DataKey {
diff --git a/contracts/dispute_resolution_contract/Cargo.toml b/contracts/dispute_resolution_contract/Cargo.toml
index a5fd7c8..5b4db12 100644
--- a/contracts/dispute_resolution_contract/Cargo.toml
+++ b/contracts/dispute_resolution_contract/Cargo.toml
@@ -2,6 +2,13 @@
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 "]
+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"
@@ -9,9 +16,9 @@ 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" }
diff --git a/contracts/dispute_resolution_contract/lib.rs b/contracts/dispute_resolution_contract/lib.rs
index fbbf10d..09c74f1 100644
--- a/contracts/dispute_resolution_contract/lib.rs
+++ b/contracts/dispute_resolution_contract/lib.rs
@@ -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)]
@@ -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 {
@@ -127,7 +127,11 @@ 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);
@@ -135,8 +139,11 @@ impl DisputeResolutionContract {
}
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) {
@@ -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);
@@ -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"),
diff --git a/contracts/shared_types/lib.rs b/contracts/shared_types/lib.rs
index dbbf38e..232fc33 100644
--- a/contracts/shared_types/lib.rs
+++ b/contracts/shared_types/lib.rs
@@ -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,
+ pub status: DeliveryStatus,
+ pub metadata: DeliveryMetadata,
+ pub created_at: u64,
+ pub delivered_at: Option,
+ pub transit_started_at: Option,
+}
+
#[contracttype]
#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord)]
pub enum EscrowState {