Skip to content

Commit 56e76dc

Browse files
authored
Merge pull request Emeka000#1070 from ussyalfaks/fix/lifebank-soroban-cleanup
fix(lifebank-soroban): resolve issues
2 parents 65f5d55 + bd4bc00 commit 56e76dc

13 files changed

Lines changed: 446 additions & 341 deletions

File tree

lifebank-soroban/contracts/analytics/src/lib.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ mod test;
99
pub use error::AnalyticsError;
1010
pub use types::{AnalyticsConfig, DataKey, MetricsSnapshot, PeriodType, ReportingPeriod};
1111

12-
use soroban_sdk::{contract, contractimpl, symbol_short, Address, Env};
12+
use soroban_sdk::{contract, contractevent, contractimpl, Address, Env};
13+
14+
#[contractevent(topics = ["anlytcs", "init"], data_format = "single-value")]
15+
pub struct AnalyticsInitialized {
16+
pub admin: Address,
17+
}
1318

1419
// ── Constants ─────────────────────────────────────────────────────────────────
1520

@@ -142,14 +147,7 @@ impl AnalyticsContract {
142147
.set(&DataKey::TotalPaymentsReleased, &0u64);
143148
env.storage().persistent().set(&DataKey::TotalVolume, &0i128);
144149

145-
env.events().publish(
146-
(
147-
symbol_short!("anlytcs"),
148-
symbol_short!("init"),
149-
symbol_short!("v1"),
150-
),
151-
admin,
152-
);
150+
AnalyticsInitialized { admin }.publish(&env);
153151

154152
Ok(())
155153
}

lifebank-soroban/contracts/coordinator/src/lib.rs

Lines changed: 60 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ mod test;
1818
pub use error::CoordinatorError;
1919
pub use types::{DataKey, ExcursionSummary, WorkflowRecord, WorkflowStatus};
2020

21-
use soroban_sdk::{contract, contractimpl, contracttype, symbol_short, Address, Env, String, Vec};
21+
use soroban_sdk::{contract, contractevent, contractimpl, contracttype, Address, Env, String, Vec};
2222

2323
/// Default workflow expiry window: 6 hours expressed in seconds.
2424
/// After `allocate_units` is called, if `confirm_delivery` is never invoked
@@ -122,6 +122,7 @@ mod request_client {
122122
use soroban_sdk::{contractclient, Address, Env};
123123

124124
#[contractclient(name = "RequestContractClient")]
125+
#[allow(dead_code)]
125126
pub trait RequestContractInterface {
126127
fn get_request(env: Env, request_id: u64) -> BloodRequest;
127128
}
@@ -132,6 +133,7 @@ mod inventory_client {
132133
use soroban_sdk::{contractclient, Address, Env, String};
133134

134135
#[contractclient(name = "InventoryContractClient")]
136+
#[allow(dead_code)]
135137
pub trait InventoryContractInterface {
136138
fn get_blood_unit(env: Env, blood_unit_id: u64) -> BloodUnit;
137139
fn update_status(
@@ -168,6 +170,7 @@ mod payment_client {
168170
}
169171

170172
#[contractclient(name = "PaymentContractClient")]
173+
#[allow(dead_code)]
171174
pub trait PaymentContractInterface {
172175
fn get_payment(env: Env, payment_id: u64) -> Payment;
173176
fn update_status(env: Env, payment_id: u64, status: PaymentStatus);
@@ -179,6 +182,54 @@ use inventory_client::InventoryContractClient;
179182
use payment_client::PaymentContractClient;
180183
use request_client::RequestContractClient;
181184

185+
// ── Contract events ───────────────────────────────────────────────────────────
186+
187+
#[contractevent(topics = ["coord", "init"], data_format = "single-value")]
188+
pub struct CoordInitialized {
189+
pub admin: Address,
190+
}
191+
192+
#[contractevent(topics = ["coord", "emrghlt"], data_format = "single-value")]
193+
pub struct CoordEmergencyHalt {
194+
pub admin: Address,
195+
}
196+
197+
#[contractevent(topics = ["coord", "alloc"], data_format = "vec")]
198+
pub struct CoordAllocated {
199+
pub request_id: u64,
200+
pub unit_ids: Vec<u64>,
201+
pub unit_count: u32,
202+
}
203+
204+
#[contractevent(topics = ["coord", "dlvrd"], data_format = "vec")]
205+
pub struct CoordDelivered {
206+
pub request_id: u64,
207+
pub location: String,
208+
}
209+
210+
#[contractevent(topics = ["coord", "settld"], data_format = "vec")]
211+
pub struct CoordSettled {
212+
pub request_id: u64,
213+
pub payment_id: u64,
214+
}
215+
216+
#[contractevent(topics = ["coord", "rollbk"], data_format = "single-value")]
217+
pub struct CoordRolledBack {
218+
pub request_id: u64,
219+
}
220+
221+
#[contractevent(topics = ["coord", "expired"], data_format = "single-value")]
222+
pub struct CoordExpired {
223+
pub request_id: u64,
224+
}
225+
226+
#[contractevent(topics = ["coord", "tmp_brch"], data_format = "vec")]
227+
pub struct CoordTemperatureBreach {
228+
pub payment_id: u64,
229+
pub unit_id: u64,
230+
pub timestamp: u64,
231+
}
232+
182233
// ── Storage helpers ────────────────────────────────────────────────────────────
183234

184235
fn get_admin(env: &Env) -> Result<Address, CoordinatorError> {
@@ -250,14 +301,7 @@ impl CoordinatorContract {
250301
env.storage()
251302
.instance()
252303
.set(&DataKey::PaymentContract, &payment_contract);
253-
env.events().publish(
254-
(
255-
symbol_short!("coord"),
256-
symbol_short!("init"),
257-
symbol_short!("v1"),
258-
),
259-
admin,
260-
);
304+
CoordInitialized { admin }.publish(&env);
261305
Ok(())
262306
}
263307

@@ -341,14 +385,7 @@ impl CoordinatorContract {
341385
return Err(CoordinatorError::Unauthorized);
342386
}
343387
env.storage().instance().set(&DataKey::EmergencyHalt, &true);
344-
env.events().publish(
345-
(
346-
symbol_short!("coord"),
347-
symbol_short!("emrghlt"),
348-
symbol_short!("v1"),
349-
),
350-
admin,
351-
);
388+
CoordEmergencyHalt { admin }.publish(&env);
352389
Ok(())
353390
}
354391

@@ -440,14 +477,7 @@ impl CoordinatorContract {
440477
.map_err(|_| CoordinatorError::InventoryUpdateFailed)?;
441478
}
442479

443-
env.events().publish(
444-
(
445-
symbol_short!("coord"),
446-
symbol_short!("alloc"),
447-
symbol_short!("v1"),
448-
),
449-
(request_id, unit_ids.clone(), unit_ids.len()),
450-
);
480+
CoordAllocated { request_id, unit_ids: unit_ids.clone(), unit_count: unit_ids.len() }.publish(&env);
451481

452482
save_workflow(
453483
&env,
@@ -514,14 +544,7 @@ impl CoordinatorContract {
514544
wf.delivery_location = Some(location.clone());
515545
save_workflow(&env, &wf);
516546

517-
env.events().publish(
518-
(
519-
symbol_short!("coord"),
520-
symbol_short!("dlvrd"),
521-
symbol_short!("v1"),
522-
),
523-
(request_id, location),
524-
);
547+
CoordDelivered { request_id, location }.publish(&env);
525548

526549
Ok(())
527550
}
@@ -567,14 +590,7 @@ impl CoordinatorContract {
567590
wf.status = WorkflowStatus::Settled;
568591
save_workflow(&env, &wf);
569592

570-
env.events().publish(
571-
(
572-
symbol_short!("coord"),
573-
symbol_short!("settld"),
574-
symbol_short!("v1"),
575-
),
576-
(request_id, wf.payment_id),
577-
);
593+
CoordSettled { request_id, payment_id: wf.payment_id }.publish(&env);
578594

579595
Ok(())
580596
}
@@ -628,14 +644,7 @@ impl CoordinatorContract {
628644
wf.status = WorkflowStatus::RolledBack;
629645
save_workflow(&env, &wf);
630646

631-
env.events().publish(
632-
(
633-
symbol_short!("coord"),
634-
symbol_short!("rollbk"),
635-
symbol_short!("v1"),
636-
),
637-
request_id,
638-
);
647+
CoordRolledBack { request_id }.publish(&env);
639648

640649
Ok(())
641650
}
@@ -709,14 +718,7 @@ impl CoordinatorContract {
709718
expired_wf.status = WorkflowStatus::RolledBack;
710719
save_workflow(&env, &expired_wf);
711720

712-
env.events().publish(
713-
(
714-
symbol_short!("coord"),
715-
symbol_short!("expired"),
716-
symbol_short!("v1"),
717-
),
718-
request_id,
719-
);
721+
CoordExpired { request_id }.publish(&env);
720722

721723
Ok(())
722724
}
@@ -771,10 +773,7 @@ impl CoordinatorContract {
771773
.map_err(|_| CoordinatorError::PaymentFlagFailed)?;
772774

773775
let now = env.ledger().timestamp();
774-
env.events().publish(
775-
(symbol_short!("coord"), symbol_short!("tmp_brch")),
776-
(payment_id, excursion_summary.unit_id, now),
777-
);
776+
CoordTemperatureBreach { payment_id, unit_id: excursion_summary.unit_id, timestamp: now }.publish(&env);
778777

779778
Ok(())
780779
}

lifebank-soroban/contracts/delivery/src/lib.rs

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,22 @@
11
#![no_std]
22

33
use soroban_sdk::{
4-
contract, contracterror, contractimpl, contracttype, symbol_short, Address, Bytes, Env,
4+
contract, contracterror, contractevent, contractimpl, contracttype, Address, Bytes, Env,
55
};
66

7+
#[contractevent(topics = ["delivery", "init"], data_format = "vec")]
8+
pub struct DeliveryInitialized {
9+
pub admin: Address,
10+
pub request_contract: Address,
11+
}
12+
13+
#[contractevent(topics = ["comply"], data_format = "vec")]
14+
pub struct ComplianceAttested {
15+
pub delivery_id: u64,
16+
pub compliance_hash: Bytes,
17+
pub is_compliant: bool,
18+
}
19+
720
const DEFAULT_MIN_TEMPERATURE_C: i32 = 2;
821
const DEFAULT_MAX_TEMPERATURE_C: i32 = 6;
922

@@ -78,10 +91,11 @@ impl DeliveryContract {
7891
.instance()
7992
.set(&DataKey::ProofRequirements, &proof_requirements);
8093

81-
env.events().publish(
82-
(symbol_short!("init"), symbol_short!("v1")),
83-
(admin, request_contract),
84-
);
94+
DeliveryInitialized {
95+
admin,
96+
request_contract,
97+
}
98+
.publish(&env);
8599

86100
Ok(())
87101
}
@@ -144,10 +158,12 @@ impl DeliveryContract {
144158
&(compliance_hash.clone(), is_compliant),
145159
);
146160

147-
env.events().publish(
148-
(symbol_short!("comply"), symbol_short!("v1")),
149-
(delivery_id, compliance_hash, is_compliant),
150-
);
161+
ComplianceAttested {
162+
delivery_id,
163+
compliance_hash,
164+
is_compliant,
165+
}
166+
.publish(&env);
151167

152168
Ok(())
153169
}

0 commit comments

Comments
 (0)