From fc79d2772d90ca2ae8716163c83a4f747c1a1552 Mon Sep 17 00:00:00 2001 From: Cho Young-Hwi Date: Fri, 13 Mar 2026 21:55:14 +0000 Subject: [PATCH] [#5] Implement donate() Transfer $PLOT from donor to storyline writer via transferFrom, emit Donation event. Validates non-zero amount and storyline existence. Fixes #5 Co-Authored-By: Claude Opus 4.6 (1M context) --- src/StoryFactory.sol | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/StoryFactory.sol b/src/StoryFactory.sol index 9b24323..e438828 100644 --- a/src/StoryFactory.sol +++ b/src/StoryFactory.sol @@ -165,6 +165,23 @@ contract StoryFactory { emit PlotChained(storylineId, plotIndex, msg.sender, contentCID, contentHash); } + // ----------------------------------------------------------------------- + // donate + // ----------------------------------------------------------------------- + + /// @notice Donate $PLOT directly to a storyline's writer + /// @param storylineId The storyline whose writer receives the donation + /// @param amount Amount of $PLOT to donate (in wei) + function donate(uint256 storylineId, uint256 amount) external { + require(amount > 0, "Zero amount"); + Storyline storage s = storylines[storylineId]; + require(s.writer != address(0), "Storyline does not exist"); + + require(PLOT_TOKEN.transferFrom(msg.sender, s.writer, amount), "Transfer failed"); + + emit Donation(storylineId, msg.sender, amount); + } + // ----------------------------------------------------------------------- // Internal helpers // -----------------------------------------------------------------------