|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
// SPDX-License-Identifier: MIT pragma solidity >=0.6.12 <0.9.0; /** * @title HouseTransaction * @dev A contract to simulate a transaction between two buyers. One writes "casa" and the other transfers Ether. */ contract HouseTransaction { address public writer; address public buyer; string public writtenWord; uint public transferAmount; bool public wordWritten; bool public paymentMade; event TransactionCompleted(address writer, address buyer); /** * @dev Initializes the contract, setting the writer and buyer addresses. * @param _writer The address of the person who will write the word "casa". * @param _buyer The address of the person who will transfer Ether. */ constructor(address _writer, address _buyer) { writer = _writer; buyer = _buyer; wordWritten = false; paymentMade = false; } /** * @dev Allows the writer to write the word "casa". * @param _word The word to be written. */ function writeWord(string memory _word) public { require(msg.sender == writer, "Only the designated writer can write the word."); require(keccak256(bytes(_word)) == keccak256(bytes("casa")), "The word must be 'casa'."); writtenWord = _word; wordWritten = true; checkCompletion(); } /** * @dev Allows the buyer to make the payment. */ function makePayment() public payable { require(msg.sender == buyer, "Only the designated buyer can make the payment."); require(msg.value > 0, "Payment must be greater than 0."); transferAmount = msg.value; paymentMade = true; checkCompletion(); } /** * @dev Checks if both conditions are met and emits the completion event. */ function checkCompletion() internal { if (wordWritten && paymentMade) { emit TransactionCompleted(writer, buyer); } } } |

Explicación del Contrato:
- Variables de Estado:
- Constructor:
- Funciones:
- Evento:

