-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathTransactions.sol
More file actions
46 lines (34 loc) · 1.44 KB
/
Copy pathTransactions.sol
File metadata and controls
46 lines (34 loc) · 1.44 KB
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
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;
// import "hardhat/console.sol";
contract Transactions {
uint256 transactionCount;
event Transfer(address from, address receiver, uint amount, string message, uint256 timestamp, string keyword);
struct TransferStruct {
address sender;
address receiver;
uint amount;
string message;
uint256 timestamp;
string keyword;
}
TransferStruct[] transactions;
/// @notice Adds a transaction to the blockchain.
/// @param receiver The address receiving funds.
/// @param amount The amount being sent.
/// @param message A message associated with the transaction.
/// @param keyword A keyword for categorizing the transaction.
function addToBlockchain(address payable receiver, uint amount, string memory message, string memory keyword) public {
require(receiver != address(0), "Invalid receiver address");
require(amount > 0, "Amount must be greater than 0");
transactionCount += 1;
transactions.push(TransferStruct(msg.sender, receiver, amount, message, block.timestamp, keyword));
emit Transfer(msg.sender, receiver, amount, message, block.timestamp, keyword);
}
function getAllTransactions() public view returns (TransferStruct[] memory) {
return transactions;
}
function getTransactionCount() public view returns (uint256) {
return transactionCount;
}
}