add contracts
This commit is contained in:
parent
412b0608c5
commit
285cca664a
15
contracts/FavoriteNumber.sol
Normal file
15
contracts/FavoriteNumber.sol
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
pragma solidity >=0.4.22 <0.9.0;
|
||||||
|
|
||||||
|
contract FavoriteNumber {
|
||||||
|
|
||||||
|
uint favoriteNumber;
|
||||||
|
|
||||||
|
function setFavoriteNumber(uint _favoriteNumber) public {
|
||||||
|
favoriteNumber = _favoriteNumber;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getFavoriteNumber() public view returns (uint) {
|
||||||
|
return favoriteNumber;
|
||||||
|
}
|
||||||
|
}
|
40
contracts/MusiciansManager.sol
Normal file
40
contracts/MusiciansManager.sol
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
pragma solidity >=0.4.22 <0.9.0;
|
||||||
|
|
||||||
|
import "./Owner.sol";
|
||||||
|
|
||||||
|
contract MusiciansManager is Owner{
|
||||||
|
|
||||||
|
event musicianCreated(string _artistName);
|
||||||
|
event trackAdded(string _artistName, string _title);
|
||||||
|
event getTheTracks(Track[] _tracks);
|
||||||
|
|
||||||
|
struct Track {
|
||||||
|
string title;
|
||||||
|
uint duration;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Musician {
|
||||||
|
string name;
|
||||||
|
Track[] tracks;
|
||||||
|
}
|
||||||
|
|
||||||
|
mapping (address => Musician) musicians;
|
||||||
|
|
||||||
|
function addMusician(address _address, string memory _name) public isOwner() {
|
||||||
|
require(bytes(musicians[_address].name).length == 0, "Musician already exists");
|
||||||
|
musicians[_address].name = _name;
|
||||||
|
emit musicianCreated(_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
function addTrack(address _address, string memory _title, uint _duration) external isOwner() {
|
||||||
|
require(bytes(musicians[_address].name).length > 0, "Musician does not exist");
|
||||||
|
Track memory thisTrack = Track(_title, _duration);
|
||||||
|
musicians[_address].tracks.push(thisTrack);
|
||||||
|
emit trackAdded(musicians[_address].name, _title);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getTracks(address _address) external {
|
||||||
|
emit getTheTracks(musicians[_address].tracks);
|
||||||
|
}
|
||||||
|
}
|
18
contracts/Owner.sol
Normal file
18
contracts/Owner.sol
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
pragma solidity >=0.4.22 <0.9.0;
|
||||||
|
|
||||||
|
contract Owner{
|
||||||
|
|
||||||
|
address owner;
|
||||||
|
|
||||||
|
constructor(){
|
||||||
|
owner = msg.sender;
|
||||||
|
}
|
||||||
|
|
||||||
|
modifier isOwner(){
|
||||||
|
require(msg.sender == owner, "sender is not the owner");
|
||||||
|
_;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
56
contracts/Wallet.sol
Normal file
56
contracts/Wallet.sol
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
pragma solidity >=0.4.22 <0.9.0;
|
||||||
|
|
||||||
|
|
||||||
|
import "./Owner.sol";
|
||||||
|
|
||||||
|
contract Wallet is Owner{
|
||||||
|
|
||||||
|
event received(uint _newAmount);
|
||||||
|
|
||||||
|
event sended(uint _amount);
|
||||||
|
|
||||||
|
struct Payment{
|
||||||
|
uint amount;
|
||||||
|
uint timeStamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Balance{
|
||||||
|
uint totalBalance;
|
||||||
|
uint numPayment;
|
||||||
|
mapping(uint => Payment) payments;
|
||||||
|
}
|
||||||
|
|
||||||
|
mapping(address => Balance) wallet;
|
||||||
|
|
||||||
|
function getBalances() public isOwner() view returns(uint){
|
||||||
|
return address(this).balance;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getBalance() public view returns(uint){
|
||||||
|
return wallet[msg.sender].totalBalance;
|
||||||
|
}
|
||||||
|
|
||||||
|
function withdrawAllMoney(address payable _to) public{
|
||||||
|
uint amount = wallet[msg.sender].totalBalance;
|
||||||
|
wallet[msg.sender].totalBalance = 0;
|
||||||
|
_to.transfer(amount);
|
||||||
|
}
|
||||||
|
|
||||||
|
function withdrawMoney(address payable _to, uint val) public{
|
||||||
|
uint thisBalance = wallet[msg.sender].totalBalance;
|
||||||
|
require(thisBalance >= val,"not enough balance");
|
||||||
|
//envoyer a l'addr _to
|
||||||
|
wallet[msg.sender].totalBalance -= val;
|
||||||
|
_to.transfer(val);
|
||||||
|
emit sended(val);
|
||||||
|
}
|
||||||
|
|
||||||
|
receive() payable external{
|
||||||
|
Payment memory thisPayment = Payment(msg.value, block.timestamp);
|
||||||
|
wallet[msg.sender].totalBalance += msg.value;
|
||||||
|
wallet[msg.sender].payments[wallet[msg.sender].numPayment] = thisPayment;
|
||||||
|
wallet[msg.sender].numPayment++;
|
||||||
|
emit received(wallet[msg.sender].totalBalance);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user