diff options
author | Nemil Dalal <nemild@gmail.com> | 2015-11-30 17:23:41 -0500 |
---|---|---|
committer | Nemil Dalal <nemild@gmail.com> | 2015-11-30 17:23:41 -0500 |
commit | 541c278de4b253090b27a1ef126f5ed27e050f7c (patch) | |
tree | d1aa3b1e209827cb653f3585c0103ef428cd077b /solidity.html.markdown | |
parent | add8f68f1acdceca1b9e09d6458627c515e73047 (diff) |
Minor updates
Diffstat (limited to 'solidity.html.markdown')
-rw-r--r-- | solidity.html.markdown | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/solidity.html.markdown b/solidity.html.markdown index 77648e51..298b01f3 100644 --- a/solidity.html.markdown +++ b/solidity.html.markdown @@ -30,10 +30,13 @@ contract AcmeBank { // these are persistent throughout the life of the contract // a dictionary that maps addresses to balances - mapping (address => uint) balances; + // the private means that other contracts can't see balances + // but the data is still available to all other parties on the + // blockchain + mapping (address => uint) private balances; // the 'public' makes 'owner' externally readable by users or contracts - // (but not writeable) - + // (but not writeable) address public owner; // Constructor, can receive one or many variables here @@ -125,9 +128,10 @@ var a = true; // by default, all values are set to 0 on instantiation -// Delete can be called on most types, and will set the values to 0 by assignment +// Delete can be called on most types +// (it does NOT destroy the value, but rather sets the value to 0 by assignment) uint x = 5; -delete(x); // x is now 0 +delete x; // x is now 0 // 2. DATA STRUCTURES @@ -151,8 +155,8 @@ function balances(address _account) returns (uint balance) { } // To delete -delete(balances["John"]); -delete(balances); // deletes all elements +delete balances["John"]; +delete balances; // deletes all elements // Unlike languages like Javascript, you cannot iterate through all elements in // a map, without knowing the source keys @@ -166,7 +170,7 @@ Bank b = Bank({ owner: msg.sender, balance: 5 }); -delete(b); // set all values to 0, except any mappings +delete b; // set all variables in struct to 0, except any mappings // Enums enum State { Created, Locked, Inactive }; @@ -226,6 +230,7 @@ function increment(uint x, uint y) returns (uint x, uint y) { uint (a,b) = increment(1,1); // The 'constant' indicates and ensures that a function does not/cannot change the persistent variables +// Constant function execute locally, not on the blockchain uint y; function increment(uint x) constant returns (uint x) { @@ -469,6 +474,7 @@ sha256("def"); ## Sample contracts - [Solidity Baby Step Contracts](https://github.com/fivedogit/solidity-baby-steps/tree/master/contracts) - [Consensys Contracts](https://github.com/ConsenSys/dapp-store-contracts) +- [State of Dapps](http://dapps.ethercasts.com/) ## Information purposefully excluded - Libraries |