Skip to content

Commit 228c477

Browse files
Merge pull request #51 from KAMALDEEN333/Enforce-Identity-Verification
Implemented the Identity Verification
2 parents b243cbc + 6feb09b commit 228c477

5 files changed

Lines changed: 170 additions & 45 deletions

File tree

contracts/payment-vault-contract/src/contract.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ use crate::error::VaultError;
22
use crate::events;
33
use crate::storage;
44
use crate::types::{BookingRecord, BookingStatus};
5-
use soroban_sdk::{token, Address, Env};
5+
use soroban_sdk::{token, Address, Env, Symbol};
66

77
pub fn initialize_vault(
88
env: &Env,
99
admin: &Address,
1010
token: &Address,
1111
oracle: &Address,
12+
registry: &Address,
1213
) -> Result<(), VaultError> {
1314
// 1. Check if already initialized
1415
if storage::has_admin(env) {
@@ -19,6 +20,7 @@ pub fn initialize_vault(
1920
storage::set_admin(env, admin);
2021
storage::set_token(env, token);
2122
storage::set_oracle(env, oracle);
23+
storage::set_registry_address(env, registry);
2224

2325
Ok(())
2426
}
@@ -65,6 +67,18 @@ pub fn book_session(
6567
// Require authorization from the user creating the booking
6668
user.require_auth();
6769

70+
// Verify expert is verified via Identity Registry cross-contract call
71+
let registry_address = storage::get_registry_address(env).ok_or(VaultError::NotInitialized)?;
72+
let is_verified: bool = env.invoke_contract(
73+
&registry_address,
74+
&Symbol::new(env, "is_verified"),
75+
soroban_sdk::vec![env, expert.to_val()],
76+
);
77+
78+
if !is_verified {
79+
return Err(VaultError::ExpertNotVerified);
80+
}
81+
6882
// Fetch the expert's rate
6983
let rate_per_second =
7084
storage::get_expert_rate(env, expert).ok_or(VaultError::ExpertRateNotSet)?;

contracts/payment-vault-contract/src/error.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ pub enum VaultError {
1313
ReclaimTooEarly = 7,
1414
ContractPaused = 8,
1515
ExpertRateNotSet = 9,
16+
ExpertNotVerified = 10,
1617
}

contracts/payment-vault-contract/src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@ pub struct PaymentVaultContract;
1616

1717
#[contractimpl]
1818
impl PaymentVaultContract {
19-
/// Initialize the vault with the Admin, the Payment Token, and the Oracle (Backend)
19+
/// Initialize the vault with the Admin, the Payment Token, the Oracle (Backend), and the Identity Registry
2020
pub fn init(
2121
env: Env,
2222
admin: Address,
2323
token: Address,
2424
oracle: Address,
25+
registry: Address,
2526
) -> Result<(), VaultError> {
26-
contract::initialize_vault(&env, &admin, &token, &oracle)
27+
contract::initialize_vault(&env, &admin, &token, &oracle, &registry)
2728
}
2829

2930
/// Pause the contract (Admin-only)

contracts/payment-vault-contract/src/storage.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,20 @@ pub enum DataKey {
77
Admin,
88
Token,
99
Oracle,
10-
Booking(u64), // Booking ID -> BookingRecord
11-
BookingCounter, // Counter for generating unique booking IDs
10+
RegistryAddress,
11+
Booking(u64), // Booking ID -> BookingRecord
12+
BookingCounter, // Counter for generating unique booking IDs
13+
UserBookings(Address), // User Address -> Vec<u64> of booking IDs
14+
ExpertBookings(Address), // Expert Address -> Vec<u64> of booking IDs
15+
IsPaused, // Circuit breaker flag
1216
// ── Indexed User Booking List ──────────────────────────────────────────
1317
// Replaces the old Vec<u64> approach with O(1) per-write composite keys.
1418
UserBooking(Address, u32), // (user, index) -> booking_id
1519
UserBookingCount(Address), // user -> total count (u32)
1620
// ── Indexed Expert Booking List ────────────────────────────────────────
1721
ExpertBooking(Address, u32), // (expert, index) -> booking_id
1822
ExpertBookingCount(Address), // expert -> total count (u32)
19-
IsPaused, // Circuit breaker flag
20-
ExpertRate(Address), // Expert Address -> rate per second (i128)
23+
ExpertRate(Address), // Expert Address -> rate per second (i128)
2124
}
2225

2326
// --- Admin ---
@@ -52,6 +55,15 @@ pub fn get_oracle(env: &Env) -> Address {
5255
env.storage().instance().get(&DataKey::Oracle).unwrap()
5356
}
5457

58+
// --- Registry (Identity) ---
59+
pub fn set_registry_address(env: &Env, registry: &Address) {
60+
env.storage().instance().set(&DataKey::RegistryAddress, registry);
61+
}
62+
63+
pub fn get_registry_address(env: &Env) -> Option<Address> {
64+
env.storage().instance().get(&DataKey::RegistryAddress)
65+
}
66+
5567
// --- Pause (Circuit Breaker) ---
5668
pub fn set_paused(env: &Env, paused: bool) {
5769
env.storage().instance().set(&DataKey::IsPaused, &paused);

0 commit comments

Comments
 (0)