Skip to content

Implement emit_stream_created and the StreamCreatedEvent payload referenced by create_stream #135

Description

@greatest0fallt1me

Description

create_stream calls emit_stream_created(&env, stream_id, &payer, &info.recipient, rate_per_second, initial_balance) at src/lib.rs:136, but that function does not exist anywhere in the crate, and the test test_create_stream_emits_event (src/lib.rs:680) deserialises a StreamCreatedEvent struct (src/lib.rs:708) that is also never defined. docs/events.md already specifies a full event catalogue, yet the contract emits no events at all. This issue implements the stream_created event end-to-end so off-chain indexers can rebuild stream history as docs/events.md promises.

Requirements and context

Functional

  • Define #[contracttype] pub struct StreamCreatedEvent { payer: Address, recipient: Address, rate_per_second: i128, initial_balance: i128 } to match the data payload asserted in test_create_stream_emits_event (src/lib.rs:707712).
  • Implement fn emit_stream_created(env: &Env, stream_id: u32, payer: &Address, recipient: &Address, rate_per_second: i128, initial_balance: i128) that publishes via env.events().publish(...).
  • The inline test expects topics topic[0] == Symbol "stream_created" and topic[1] == stream_id (src/lib.rs:702705). Note this conflicts with docs/events.md, which specifies a two-symbol topic (stream, created) with stream_id in the data payload. Pick one canonical topic shape, make the test and docs/events.md agree, and document the decision in the PR.
  • Ensure exactly one event is emitted per create_stream and none on start/stop (test_no_spurious_stream_created_events, src/lib.rs:717).

Non-functional / repo conventions

  • Keep the event helper free of auth side effects; it must only read the values passed in.
  • Stay within the WASM budget checked by scripts/check-wasm-size.sh; events add to size.
  • Follow the existing accounting fields — initial_balance is the value escrowed at creation, not the running balance.

Acceptance criteria

  • StreamCreatedEvent defined and emit_stream_created implemented; src/lib.rs:136 resolves.
  • test_create_stream_emits_event and test_no_spurious_stream_created_events pass.
  • Topic shape is consistent between the contract, the tests, and docs/events.md.
  • Exactly one event published per create_stream; no spurious events on other entry points.
  • cargo clippy --all-targets --all-features -- -D warnings passes.

Suggested execution

1. Fork the repo and create a branchgit checkout -b feature/stream-created-event.

2. Implement changes — add the StreamCreatedEvent type and emit_stream_created to src/lib.rs (or a new src/events.rs module re-exported from lib.rs); reconcile docs/events.md.

3. Write/extend tests — extend the inline #[cfg(test)] mod test using soroban_sdk::testutils::Events; assert topic and data payload exactly as in src/lib.rs:694713.

4. Test and commit

cargo fmt --all -- --check
cargo clippy --all-targets --all-features -- -D warnings
cargo test --features testutils
./scripts/check-wasm-size.sh

Example commit message

feat(events): emit stream_created event from create_stream

Guidelines

  • Target 95% line coverage (docs/coverage.sh, CONTRIBUTING.md).
  • Add /// doc-comments to the event type/helper and update docs/events.md (topic + payload table) so the doc matches the implementation.
  • Timeframe: 96 hours.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions