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
16 changes: 16 additions & 0 deletions smart-contract/contracts/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,20 @@ pub enum Error {
InvalidThreshold = 66,
TooManySigners = 67,
DuplicateSigner = 68,

// --- Sustainability (70-80) ---
/// No sustainability record exists for this product.
SustainabilityNotFound = 70,
/// Carbon footprint value is negative.
InvalidCarbonData = 71,
/// Water usage value is negative.
InvalidWaterData = 72,
/// Renewable energy percentage is out of range (must be 0–100).
InvalidRenewableEnergyData = 73,
/// Waste-recycled percentage is out of range (must be 0–100).
InvalidWasteData = 74,
/// Record has already been verified and cannot be updated.
SustainabilityAlreadyVerified = 75,
/// Operation requires a verified sustainability record.
SustainabilityClaimUnverified = 76,
}
4 changes: 4 additions & 0 deletions smart-contract/contracts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ mod stats;
mod tracking;
#[cfg(not(target_arch = "wasm32"))]
mod upgrade;
#[cfg(not(target_arch = "wasm32"))]
mod sustainability;

#[cfg(test)]
mod load_tests;
Expand Down Expand Up @@ -76,3 +78,5 @@ pub use stats::*;
pub use tracking::*;
#[cfg(not(target_arch = "wasm32"))]
pub use upgrade::*;
#[cfg(not(target_arch = "wasm32"))]
pub use sustainability::*;
16 changes: 15 additions & 1 deletion smart-contract/contracts/src/storage.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use soroban_sdk::{Address, Env, String, Symbol, Vec};

use crate::storage_contract::StorageContract;
use crate::types::{Product, TrackingEvent};
use crate::types::{Product, SustainabilityRecord, TrackingEvent};

pub fn get_auth_contract(env: &Env) -> Option<Address> {
StorageContract::get_auth_contract(env)
Expand Down Expand Up @@ -178,3 +178,17 @@ pub fn remove_from_search_index(env: &Env, keyword: String, product_id: &String)
put_search_index(env, &keyword, &ids);
}
}

// ─── Sustainability ──────────────────────────────────────────────────────────

pub fn put_sustainability(env: &Env, product_id: &String, record: &SustainabilityRecord) {
StorageContract::put_sustainability(env, product_id, record)
}

pub fn get_sustainability(env: &Env, product_id: &String) -> Option<SustainabilityRecord> {
StorageContract::get_sustainability(env, product_id)
}

pub fn has_sustainability(env: &Env, product_id: &String) -> bool {
StorageContract::has_sustainability(env, product_id)
}
26 changes: 25 additions & 1 deletion smart-contract/contracts/src/storage_contract.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use soroban_sdk::{Address, Env, String, Symbol, Vec};

use crate::types::{DataKey, Product, TrackingEvent};
use crate::types::{DataKey, Product, SustainabilityRecord, TrackingEvent};

pub struct StorageContract;

Expand Down Expand Up @@ -279,6 +279,30 @@ impl StorageContract {
.instance()
.set(&Self::active_products_key(), &count);
}

// ─── Sustainability ──────────────────────────────────────────────────────

pub fn sustainability_key(product_id: &String) -> DataKey {
DataKey::Sustainability(product_id.clone())
}

pub fn put_sustainability(env: &Env, product_id: &String, record: &SustainabilityRecord) {
env.storage()
.instance()
.set(&Self::sustainability_key(product_id), record);
}

pub fn get_sustainability(env: &Env, product_id: &String) -> Option<SustainabilityRecord> {
env.storage()
.instance()
.get(&Self::sustainability_key(product_id))
}

pub fn has_sustainability(env: &Env, product_id: &String) -> bool {
env.storage()
.instance()
.has(&Self::sustainability_key(product_id))
}
}

#[cfg(test)]
Expand Down
Loading
Loading