diff --git a/backend/contracts/MessageBox.sol b/backend/contracts/MessageBox.sol index 366c734..1229c5d 100644 --- a/backend/contracts/MessageBox.sol +++ b/backend/contracts/MessageBox.sol @@ -2,11 +2,18 @@ pragma solidity ^0.8.0; contract MessageBox { - string public message; + string private _message; address public author; function setMessage(string calldata in_message) external { - message = in_message; + _message = in_message; author = msg.sender; } + + function message() external view returns (string memory) { + if (msg.sender!=author) { + revert("not allowed"); + } + return _message; + } } diff --git a/backend/test/MessageBox.ts b/backend/test/MessageBox.ts index f45e838..c1788cd 100644 --- a/backend/test/MessageBox.ts +++ b/backend/test/MessageBox.ts @@ -9,7 +9,7 @@ describe("MessageBox", function () { return { messageBox }; } - it("Should send message", async function () { + it("Should set message", async function () { const {messageBox} = await deployMessageBox(); await messageBox.setMessage("hello world"); diff --git a/frontend/src/views/HomeView.vue b/frontend/src/views/HomeView.vue index bae0685..d08fe9b 100644 --- a/frontend/src/views/HomeView.vue +++ b/frontend/src/views/HomeView.vue @@ -32,8 +32,8 @@ function handleError(error: Error, errorMessage: string) { } async function fetchMessage(): Promise { - const message = await uwMessageBox.value!.message(); - const author = await uwMessageBox.value!.author(); + const message = await messageBox.value!.message(); + const author = await messageBox.value!.author(); return { message, author }; }