mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-23 17:41:41 +00:00
Merge pull request #4465 from al-ias/fix/solidity
[solidity] Solidity minor fixes
This commit is contained in:
commit
da4c77d05b
@ -278,7 +278,7 @@ f(22); // call
|
||||
|
||||
// Delete can be called on most types
|
||||
// (does NOT destroy value, but sets value to 0, the initial value)
|
||||
uint x = 5;
|
||||
delete x;
|
||||
|
||||
|
||||
// Destructuring/Tuples
|
||||
@ -388,7 +388,7 @@ block.gasLimit();
|
||||
storage['abc'] = 'def'; // maps 256 bit words to 256 bit words
|
||||
|
||||
|
||||
// 4. FUNCTIONS AND MORE
|
||||
// 5. FUNCTIONS AND MORE
|
||||
// A. Functions
|
||||
// Simple function
|
||||
function increment(uint x) returns (uint) {
|
||||
@ -435,7 +435,7 @@ function increment(uint x) view returns (uint x) {
|
||||
// Functions hoisted - and can assign a function to a variable
|
||||
function a() {
|
||||
var z = b;
|
||||
b();
|
||||
z();
|
||||
}
|
||||
|
||||
function b() {
|
||||
@ -494,9 +494,9 @@ Coin.LogSent().watch({}, '', function(error, result) {
|
||||
// '_' (underscore) often included as last line in body, and indicates
|
||||
// function being called should be placed there
|
||||
modifier onlyAfter(uint _time) { require (now >= _time); _; }
|
||||
modifier onlyOwner { require(msg.sender == owner) _; }
|
||||
modifier onlyOwner { require(msg.sender == owner); _; }
|
||||
// commonly used with state machines
|
||||
modifier onlyIfStateA (State currState) { require(currState == State.A) _; }
|
||||
modifier onlyIfStateA (State currState) { require(currState == State.A); _; }
|
||||
|
||||
// Append right after function declaration
|
||||
function changeOwner(newOwner)
|
||||
@ -646,7 +646,7 @@ reveal(100, "mySecret");
|
||||
// All data to start of time is stored in blockchain, so
|
||||
// anyone can observe all previous data and changes
|
||||
|
||||
// E. Oracles and External Data
|
||||
// D. Oracles and External Data
|
||||
// Oracles are ways to interact with your smart contracts outside the blockchain.
|
||||
// They are used to get data from the real world, send post requests, to the real world
|
||||
// or vise versa.
|
||||
@ -671,12 +671,12 @@ reveal(100, "mySecret");
|
||||
|
||||
// Setting up oracle networks yourself
|
||||
|
||||
// D. Cron Job
|
||||
// E. Cron Job
|
||||
// Contracts must be manually called to handle time-based scheduling; can create external
|
||||
// code to regularly ping, or provide incentives (ether) for others to
|
||||
//
|
||||
|
||||
// E. Observer Pattern
|
||||
// F. Observer Pattern
|
||||
// An Observer Pattern lets you register as a subscriber and
|
||||
// register a function which is called by the oracle (note, the oracle pays
|
||||
// for this action to be run)
|
||||
@ -714,7 +714,7 @@ contract SomeOracle {
|
||||
// Now, your client contract can addSubscriber by importing SomeOracleCallback
|
||||
// and registering with Some Oracle
|
||||
|
||||
// F. State machines
|
||||
// G. State machines
|
||||
// see example below for State enum and inState modifier
|
||||
```
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user