mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-23 09:41:36 +00:00
Formatting
This commit is contained in:
parent
700f3e7a1c
commit
ec6172fc5e
@ -81,12 +81,12 @@ contract AcmeBank {
|
||||
|
||||
// Now let's go through the basics of Solidity
|
||||
|
||||
// 1. DATA TYPES AND ASSOCIATED METHOD
|
||||
|
||||
// 1. DATA TYPES AND ASSOCIATED METHODS
|
||||
// uint is the data type typically used for currency (there are no doubles
|
||||
// or floats) and for dates
|
||||
uint x;
|
||||
|
||||
|
||||
// with 'constant', the compiler replaces each occurence with the acutal value
|
||||
// int of 256 bits, cannot be changed after instantiation
|
||||
int constant a = 8;
|
||||
@ -133,6 +133,7 @@ var a = true;
|
||||
uint x = 5;
|
||||
delete(x); // x is now 0
|
||||
|
||||
|
||||
// 2. DATA STRUCTURES
|
||||
// Arrays
|
||||
bytes32[5] nicknames; // static array
|
||||
@ -181,6 +182,7 @@ state = State.Created;
|
||||
// 'memory' does not persist, 'storage' does
|
||||
// Default is 'storage' for local and state variables; 'memory' for function parameters
|
||||
|
||||
|
||||
// 3. Variables of note
|
||||
// ** this **
|
||||
this; // the address of the current contract
|
||||
@ -209,6 +211,7 @@ block.gasLimit();
|
||||
// ** storage - A persistent storage hash (does not need to be declared) **
|
||||
storage['abc'] = 'def'; // maps 256 bit words to 256 bit words
|
||||
|
||||
|
||||
// 4. FUNCTIONS AND MORE
|
||||
// A. Functions
|
||||
// Simple function
|
||||
@ -290,6 +293,7 @@ function changeOwner(newOwner)
|
||||
owner = newOwner;
|
||||
}
|
||||
|
||||
|
||||
// 5. BRANCHING AND LOOPS
|
||||
|
||||
// All basic logic blocks work - including if/else, for, while, break, continue, return
|
||||
@ -298,6 +302,7 @@ function changeOwner(newOwner)
|
||||
// Syntax is the same as javascript, but there is no type conversion from
|
||||
// non-boolean to boolean, so comparison operators must be used to get the boolean value
|
||||
|
||||
|
||||
// 6. OBJECTS/CONTRACTS
|
||||
|
||||
// A. Calling an external contract
|
||||
@ -350,6 +355,7 @@ import "github.com/ethereum/dapp-bin/library/iterable_mapping.sol";
|
||||
// Importing is under active development and will change
|
||||
// Importing cannot currently be done at the command line
|
||||
|
||||
|
||||
// 7. CONTRACT DESIGN PATTERNS
|
||||
|
||||
// A. Obfuscation
|
||||
@ -383,6 +389,8 @@ function remove() {
|
||||
// compilation may better handle this, but for now there are benefits to
|
||||
// planning your data structures)
|
||||
|
||||
|
||||
|
||||
// *** EXAMPLE: Let's do a more complex example ***
|
||||
|
||||
// ** START EXAMPLE **
|
||||
@ -400,7 +408,7 @@ function remove() {
|
||||
// ]
|
||||
// *** END EXAMPLE ***
|
||||
|
||||
// Some final points
|
||||
|
||||
// 7. NATIVE FUNCTIONS
|
||||
|
||||
// Currency units
|
||||
@ -427,6 +435,7 @@ sha3("ab", "cd");
|
||||
ripemd160("abc");
|
||||
sha256("def");
|
||||
|
||||
|
||||
// 8. COMMON MISTAKES/MISCONCEPTIONS
|
||||
// A few common mistakes and misconceptions:
|
||||
|
||||
@ -441,6 +450,7 @@ sha256("def");
|
||||
|
||||
// TODO
|
||||
|
||||
|
||||
// 9. STYLE NOTES
|
||||
// Use 4 spaces for indentation
|
||||
// (Python's PEP8 is used as the baseline style guide, including its general philosophy)
|
||||
|
Loading…
Reference in New Issue
Block a user