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