Skip to content

[CONTRACT] Implement the event emission module (Hash-and-Emit core) #23

@dinahmaccodes

Description

@dinahmaccodes

Tier: 🟡 Medium

Description:

Create contracts/shipment/src/events.rs — the heart of the Hash-and-Emit pattern. This module contains helper functions that call env.events().publish() to emit structured events to the Stellar ledger.

Context:
In Navin's architecture, heavy data (GPS, sensor readings, metadata) is NOT stored on-chain. Instead, the contract emits events containing only the shipment_id, status, and a data_hash (SHA-256 of the full payload). The Express backend indexes these events, and the frontend verifies them directly against a Stellar RPC node.

Tasks:

  • emit_shipment_created(env, shipment_id, sender, receiver, data_hash)
  • emit_status_updated(env, shipment_id, old_status, new_status, data_hash)
  • emit_milestone_recorded(env, shipment_id, checkpoint, data_hash, reporter)
  • emit_escrow_deposited(env, shipment_id, from, amount)
  • emit_escrow_released(env, shipment_id, to, amount)
  • emit_dispute_raised(env, shipment_id, raised_by, reason_hash)
  • Use env.events().publish((topic_symbol,), data) with descriptive topic symbols

File locations:

  • New file → contracts/shipment/src/events.rs

Acceptance Criteria:

  • All emit functions compile and use env.events().publish()
  • Topic symbols are descriptive (e.g., Symbol::new(env, "shipment_created"))
  • Doc comments explaining what each event contains and who listens for it

PR Checklist:

  • events.rs created with all emit functions
  • cargo fmt — no formatting issues
  • cargo clippy --all-targets --all-features -- -D warnings — no warnings
  • cargo test — all tests pass
  • cargo build --target wasm32-unknown-unknown --release — WASM builds

Reference: Read CONTRIBUTING.md before starting.

Star the Navin repository — it helps the project grow!


Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions