Skip to content

Commit 9fff86e

Browse files
authored
Feat/328 model doc comments (#354)
* feat(contract): standardize event name trimming (#326) - Add `name` field to `EventRegistrationArgs` and `EventInfo` structs - Implement `trim_string` helper to strip leading/trailing ASCII whitespace - Apply trimming to event name in `register_event` before persisting - Add `name` field to local `EventInfo` copy in ticket_payment contract - Add `test_register_event_name_trimming` test with intentionally messy names - Update all existing test fixtures to include the new `name` field * chore(server): add .dockerignore to reduce Docker build context Excludes target/, .env files, .git/, editor artifacts, and other non-essential files from the Docker build context. - target/ is the primary source of bloat (can be GBs in Rust projects) - .env files must never be baked into images - .git/ metadata (~30MB) is not needed at build time - Docs, scripts, and OS artifacts excluded for a leaner context * docs(server): add doc comments to model structs (#328) Add /// and //! doc comments to all structs and fields in server/src/models/ to improve database layer understandability. - User: documents role distinction from Organizer - Organizer: documents ownership relationship to Events - Event: documents FK to Organizer and cascade behaviour - TicketTier: documents quantity tracking semantics - Ticket: documents status lifecycle (active/used/cancelled) and QR code generation timing - Transaction: documents status lifecycle (pending/completed/failed) and Stellar hash usage for on-chain payments - mod.rs: adds module-level doc with entity relationship diagram
1 parent 816e60e commit 9fff86e

33 files changed

Lines changed: 650 additions & 0 deletions

contract/contracts/event_registry/src/lib.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,8 +359,12 @@ impl EventRegistry {
359359

360360
let platform_fee_percent = storage::get_platform_fee(&env);
361361

362+
// Sanitize: trim leading/trailing whitespace from the event name
363+
let trimmed_name = trim_string(&env, &args.name);
364+
362365
let event_info = EventInfo {
363366
event_id: args.event_id.clone(),
367+
name: trimmed_name,
364368
organizer_address: args.organizer_address.clone(),
365369
payment_address: args.payment_address.clone(),
366370
platform_fee_percent,
@@ -1863,6 +1867,49 @@ fn is_zero_address(env: &Env, address: &Address) -> bool {
18631867
address.to_string() == zero_account
18641868
}
18651869

1870+
/// Trims leading and trailing ASCII whitespace from a Soroban `String`.
1871+
fn trim_string(env: &Env, s: &String) -> String {
1872+
let len = s.len();
1873+
if len == 0 {
1874+
return s.clone();
1875+
}
1876+
1877+
// Copy string bytes into a stack buffer for manipulation
1878+
let mut buf = [0u8; 256];
1879+
let len_usize = len as usize;
1880+
// If name exceeds buffer, return as-is (shouldn't happen in practice)
1881+
if len_usize > buf.len() {
1882+
return s.clone();
1883+
}
1884+
s.copy_into_slice(&mut buf[..len_usize]);
1885+
1886+
let mut start = 0usize;
1887+
while start < len_usize {
1888+
let b = buf[start];
1889+
if b == b' ' || b == b'\t' || b == b'\n' || b == b'\r' {
1890+
start += 1;
1891+
} else {
1892+
break;
1893+
}
1894+
}
1895+
1896+
let mut end = len_usize;
1897+
while end > start {
1898+
let b = buf[end - 1];
1899+
if b == b' ' || b == b'\t' || b == b'\n' || b == b'\r' {
1900+
end -= 1;
1901+
} else {
1902+
break;
1903+
}
1904+
}
1905+
1906+
if start == 0 && end == len_usize {
1907+
return s.clone();
1908+
}
1909+
1910+
String::from_bytes(env, &buf[start..end])
1911+
}
1912+
18661913
fn validate_metadata_cid(env: &Env, cid: &String) -> Result<(), EventRegistryError> {
18671914
let cid_len = cid.len();
18681915
if !(MIN_METADATA_CID_LEN..=MAX_METADATA_CID_LEN).contains(&cid_len) {

0 commit comments

Comments
 (0)