Skip to content

Instantly share code, notes, and snippets.

@Davidegloh
Last active August 31, 2021 15:32
Show Gist options
  • Save Davidegloh/9c939e69f5548aa0956b47c2ef85b35b to your computer and use it in GitHub Desktop.
Save Davidegloh/9c939e69f5548aa0956b47c2ef85b35b to your computer and use it in GitHub Desktop.
[Visibility -Solidity] #visibility
//Visibility
// it is a way to restrict access to functions and state variables inside our smart contract
//- Public (everyone can accessed the functions and call it but can't edit it)
//- Private (can only be accessed from the contract within and the functions can only be executed from the contract itself)
//- Internal (can only be accessed from within the contract itself and from contracts deriving from it / which inherited from it.
// - External ( can only be executed from other contracts and services like remix for instance)
// Code
pragma solidity 0.7.5;
contract Bank {
mapping (address => uint) balance; //ligne de code à tapper pour le mapping. Mapping def. à partir d'une key on obtient une value. (K -> V)
function addBalance(uint _toAdd) public returns(uint) { //fonction addBalance pour rajouter un uint à une address
balance[msg.sender] += _toAdd; // ou aussi balance [msg.sender] + _toAdd. Ici on rajouter une valeur à l'adresse de l'envoyeur
return balance[msg.sender]; //ici on retourne la balance de l'envoyeur "[msg.sender]"" updaté
}
function getBalance() public view returns(uint) {// fonction pour afficher une balance qui retourne un integer de l'adresse de l'envoyeur.
return balance[msg.sender];
}
function transfer (address recipient, uint amount) public {// fonction permettant de transferer des fonds d'une adresse à l'autre
_transfer(msg.sender, recipient, amount); // déclaration de la fonction _transfer (ci-dessous) avec en argument les inputs : adresse de
// l'envoyeur, sdu receveur et le montant à transferer.
//event Logs and further checks
}
function _transfer(address from, address to, uint amount) private { // fonction qui permet de débiter les fonds de l'envoyeur et de créditer
balance[from] -= amount; //le compte du receveur. Noter que cette fonction est "private"
balance[to] += amount;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment