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
1 change: 1 addition & 0 deletions contracts/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions contracts/ERRORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,27 @@ code 1 across different contracts.
| 170–179 | Validation |
| 180–199 | Leasing and insurance |

The enum is capped at **50 cases** by the contract spec, so narrow
single-subject variants were folded into generic ones. The following codes are
retired and must not be reused:

| Retired code | Former variant | Now returns |
|---:|---|---|
| 103 | `BranchAlreadyExists` | `AlreadyExists` (101) |
| 104 | `BranchNotFound` | `NotFound` (5) |
| 105 | `SubscriptionAlreadyExists` | `AlreadyExists` (101) |
| 123 | `InvalidTokenDecimals` | `InvalidInput` (4) |
| 142 | `ProposalNotFound` | `NotFound` (5) |
| 170 | `InvalidAssetName` | `InvalidInput` (4) |
| 171 | `InvalidPurchaseValue` | `InvalidInput` (4) |
| 172 | `InvalidMetadataUri` | `InvalidInput` (4) |
| 180 | `LeaseNotFound` | `NotFound` (5) |
| 181 | `LeaseAlreadyExists` | `AlreadyExists` (101) |
| 194 | `PolicyAlreadyExists` | `AlreadyExists` (101) |
| 195 | `ClaimAlreadyExists` | `AlreadyExists` (101) |

Code `101` was renamed from `AssetAlreadyExists` to `AlreadyExists`.

## `contrib` (200–299)

Typed `Error` enum lives in `contrib/src/error.rs` and is wired into the crate.
Expand Down Expand Up @@ -114,6 +135,7 @@ Typed `Error` enum lives in `asset-maintenance/src/error.rs`. Failures use
| Block | Concern |
|---:|---|
| 500–509 | Providers, schedules, warranties, alerts |
| 510–513 | Maintenance records (voiding/amending) and detokenized assets |

## For backend implementers

Expand Down
12 changes: 12 additions & 0 deletions contracts/asset-maintenance/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ pub enum Error {
AssetNotFound = 508,
/// Invalid date / cost / rating arguments.
InvalidArguments = 509,
/// A record that has already been voided cannot be voided again.
RecordAlreadyVoided = 510,
/// No maintenance record with that id exists for the asset.
RecordNotFound = 511,
/// A voided record can no longer be amended.
RecordVoided = 512,
/// The asset has been detokenized/burned and accepts no new maintenance.
AssetDetokenized = 513,
}

pub fn handle_error(env: &Env, error: Error) -> ! {
Expand All @@ -67,6 +75,10 @@ mod tests {
Error::AlertIndexOutOfBounds as u32,
Error::AssetNotFound as u32,
Error::InvalidArguments as u32,
Error::RecordAlreadyVoided as u32,
Error::RecordNotFound as u32,
Error::RecordVoided as u32,
Error::AssetDetokenized as u32,
] {
assert!((500..600).contains(&code));
}
Expand Down
116 changes: 115 additions & 1 deletion contracts/asset-maintenance/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//! `lower_snake_case`. `asset_id` is always a `#[topic]` so consumers can index
//! per asset.

use soroban_sdk::{contractevent, Address, Env};
use soroban_sdk::{contractevent, Address, Env, String};

use crate::{AlertSeverity, AlertType, MaintenanceAlert, MaintenanceRecord, ScheduledMaintenance};

Expand Down Expand Up @@ -141,6 +141,66 @@ pub struct AlertAcknowledged {
pub timestamp: u64,
}

/// The contract was paused; new maintenance records now reject.
#[contractevent]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct ContractPaused {
#[topic]
pub admin: Address,
pub timestamp: u64,
}

/// The contract was unpaused and resumed normal operation.
#[contractevent]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct ContractUnpaused {
#[topic]
pub admin: Address,
pub timestamp: u64,
}

/// A previously recorded maintenance entry was voided.
#[contractevent]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct MaintenanceRecordVoided {
#[topic]
pub asset_id: u64,
pub record_id: u64,
pub voided_by: Address,
pub timestamp: u64,
}

/// A previously recorded maintenance entry was amended.
#[contractevent]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct MaintenanceRecordAmended {
#[topic]
pub asset_id: u64,
pub record_id: u64,
pub amended_by: Address,
pub timestamp: u64,
}

/// An asset was marked detokenized/burned and accepts no new maintenance.
#[contractevent]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct AssetDetokenized {
#[topic]
pub asset_id: u64,
pub admin: Address,
pub timestamp: u64,
}

/// A detokenized asset was reactivated.
#[contractevent]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct AssetReactivated {
#[topic]
pub asset_id: u64,
pub admin: Address,
pub timestamp: u64,
}

// ---------------------------------------------------------------------------
// Emission helpers
// ---------------------------------------------------------------------------
Expand Down Expand Up @@ -263,3 +323,57 @@ pub fn alert_acknowledged(env: &Env, asset_id: u64, alert_index: u32, by: &Addre
}
.publish(env);
}

pub fn contract_paused(env: &Env, admin: &Address) {
ContractPaused {
admin: admin.clone(),
timestamp: env.ledger().timestamp(),
}
.publish(env);
}

pub fn contract_unpaused(env: &Env, admin: &Address) {
ContractUnpaused {
admin: admin.clone(),
timestamp: env.ledger().timestamp(),
}
.publish(env);
}

pub fn maintenance_record_voided(env: &Env, asset_id: u64, record_id: u64, by: &Address) {
MaintenanceRecordVoided {
asset_id,
record_id,
voided_by: by.clone(),
timestamp: env.ledger().timestamp(),
}
.publish(env);
}

pub fn maintenance_record_amended(env: &Env, asset_id: u64, record_id: u64, by: &Address) {
MaintenanceRecordAmended {
asset_id,
record_id,
amended_by: by.clone(),
timestamp: env.ledger().timestamp(),
}
.publish(env);
}

pub fn asset_detokenized(env: &Env, asset_id: u64, admin: &Address) {
AssetDetokenized {
asset_id,
admin: admin.clone(),
timestamp: env.ledger().timestamp(),
}
.publish(env);
}

pub fn asset_reactivated(env: &Env, asset_id: u64, admin: &Address) {
AssetReactivated {
asset_id,
admin: admin.clone(),
timestamp: env.ledger().timestamp(),
}
.publish(env);
}
Loading
Loading