struct User {
address id;
string name;
}
//Method 1 (argument order matters)
User("0xAio90....", "Mike");
//Method 2 (argument order does not matter)
User({name: "Mike", id: "0xAio90...."});
struct Car {
address owner;
string brand;
uint cc;
}
myCar = Car({string: "Toyota", address: "0xAio90....", cc: 2000});
struct User {
uint id;
string name;
}
uint[] userIds;
mapping(uint => User) users;
pragma solidity ^0.8.11;
contract complexVariable {
struct Payment {
uint amount;
uint timestamp;
} // uppercase -> type; lowercase -> variable
struct Balance {
uint totalBalance;
uint numPayments;
mapping(uint => Payment) payments;
}
mapping(address => Balance) public balanceReveived;
function getBalance() public view returns(uint){
return address(this).balance;
}
function sendMoney() public payable {
balanceReveived[msg.sender].totalBalance += msg.value;
Payment memory payment = Payment(msg.value, block.timestamp);
balanceReceived[msg.sender].payments[balanceReceived[msg.sender].numPayments] = payment;
balanceReceived[msg.sender].numPayments++;
}
function withdrawMoney(address payable _to, uint _amount) public {
require(balanceReceived[msg.sender].totalBalance <= _amount, "not enough funds");
balanceReceived[msg.sender].totalBalance -= _amount;
_to.transfer(_amount);
}
function withdrawAllMoney(address payable _to) public {
uint balanceToSend = balanceReceived[msg.sender].totalBalance;
balanceReveived[msg.sender].totalBalance = 0;
_to.transfer(balanceToSend);
}
}