mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Documentation about emitting events.
This commit is contained in:
parent
04c922e5ed
commit
f58024b974
@ -724,10 +724,12 @@ All non-indexed arguments will be stored in the data part of the log.
|
||||
);
|
||||
|
||||
function deposit(bytes32 _id) public payable {
|
||||
// Any call to this function (even deeply nested) can
|
||||
// be detected from the JavaScript API by filtering
|
||||
// for `Deposit` to be called.
|
||||
Deposit(msg.sender, _id, msg.value);
|
||||
// Events are emitted using `emit`, followed by
|
||||
// the name of the event and the arguments
|
||||
// (if any) in parentheses. Any such invocation
|
||||
// (even deeply nested) can be detected from
|
||||
// the JavaScript API by filtering for `Deposit`.
|
||||
emit Deposit(msg.sender, _id, msg.value);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -80,7 +80,7 @@ registering with username and password - all you need is an Ethereum keypair.
|
||||
|
||||
::
|
||||
|
||||
pragma solidity ^0.4.0;
|
||||
pragma solidity ^0.4.20; // should actually be 0.4.21
|
||||
|
||||
contract Coin {
|
||||
// The keyword "public" makes those variables
|
||||
@ -107,7 +107,7 @@ registering with username and password - all you need is an Ethereum keypair.
|
||||
if (balances[msg.sender] < amount) return;
|
||||
balances[msg.sender] -= amount;
|
||||
balances[receiver] += amount;
|
||||
Sent(msg.sender, receiver, amount);
|
||||
emit Sent(msg.sender, receiver, amount);
|
||||
}
|
||||
}
|
||||
|
||||
@ -157,10 +157,10 @@ single account.
|
||||
.. index:: event
|
||||
|
||||
The line ``event Sent(address from, address to, uint amount);`` declares
|
||||
a so-called "event" which is fired in the last line of the function
|
||||
a so-called "event" which is emitted in the last line of the function
|
||||
``send``. User interfaces (as well as server applications of course) can
|
||||
listen for those events being fired on the blockchain without much
|
||||
cost. As soon as it is fired, the listener will also receive the
|
||||
listen for those events being emitted on the blockchain without much
|
||||
cost. As soon as it is emitted, the listener will also receive the
|
||||
arguments ``from``, ``to`` and ``amount``, which makes it easy to track
|
||||
transactions. In order to listen for this event, you would use ::
|
||||
|
||||
|
@ -214,7 +214,7 @@ activate themselves.
|
||||
|
||||
::
|
||||
|
||||
pragma solidity ^0.4.11;
|
||||
pragma solidity ^0.4.20; // should actually be 0.4.21
|
||||
|
||||
contract SimpleAuction {
|
||||
// Parameters of the auction. Times are either
|
||||
@ -282,7 +282,7 @@ activate themselves.
|
||||
}
|
||||
highestBidder = msg.sender;
|
||||
highestBid = msg.value;
|
||||
HighestBidIncreased(msg.sender, msg.value);
|
||||
emit HighestBidIncreased(msg.sender, msg.value);
|
||||
}
|
||||
|
||||
/// Withdraw a bid that was overbid.
|
||||
@ -325,7 +325,7 @@ activate themselves.
|
||||
|
||||
// 2. Effects
|
||||
ended = true;
|
||||
AuctionEnded(highestBidder, highestBid);
|
||||
emit AuctionEnded(highestBidder, highestBid);
|
||||
|
||||
// 3. Interaction
|
||||
beneficiary.transfer(highestBid);
|
||||
@ -371,7 +371,7 @@ high or low invalid bids.
|
||||
|
||||
::
|
||||
|
||||
pragma solidity ^0.4.11;
|
||||
pragma solidity ^0.4.20; // should actually be 0.4.21
|
||||
|
||||
contract BlindAuction {
|
||||
struct Bid {
|
||||
@ -509,7 +509,7 @@ high or low invalid bids.
|
||||
onlyAfter(revealEnd)
|
||||
{
|
||||
require(!ended);
|
||||
AuctionEnded(highestBidder, highestBid);
|
||||
emit AuctionEnded(highestBidder, highestBid);
|
||||
ended = true;
|
||||
beneficiary.transfer(highestBid);
|
||||
}
|
||||
@ -524,7 +524,7 @@ Safe Remote Purchase
|
||||
|
||||
::
|
||||
|
||||
pragma solidity ^0.4.11;
|
||||
pragma solidity ^0.4.20; // should actually be 0.4.21
|
||||
|
||||
contract Purchase {
|
||||
uint public value;
|
||||
@ -574,7 +574,7 @@ Safe Remote Purchase
|
||||
onlySeller
|
||||
inState(State.Created)
|
||||
{
|
||||
Aborted();
|
||||
emit Aborted();
|
||||
state = State.Inactive;
|
||||
seller.transfer(this.balance);
|
||||
}
|
||||
@ -589,7 +589,7 @@ Safe Remote Purchase
|
||||
condition(msg.value == (2 * value))
|
||||
payable
|
||||
{
|
||||
PurchaseConfirmed();
|
||||
emit PurchaseConfirmed();
|
||||
buyer = msg.sender;
|
||||
state = State.Locked;
|
||||
}
|
||||
@ -601,7 +601,7 @@ Safe Remote Purchase
|
||||
onlyBuyer
|
||||
inState(State.Locked)
|
||||
{
|
||||
ItemReceived();
|
||||
emit ItemReceived();
|
||||
// It is important to change the state first because
|
||||
// otherwise, the contracts called using `send` below
|
||||
// can call in again here.
|
||||
|
@ -86,14 +86,14 @@ Events are convenience interfaces with the EVM logging facilities.
|
||||
|
||||
::
|
||||
|
||||
pragma solidity ^0.4.0;
|
||||
pragma solidity ^0.4.20; // should actually be 0.4.21
|
||||
|
||||
contract SimpleAuction {
|
||||
event HighestBidIncreased(address bidder, uint amount); // Event
|
||||
|
||||
function bid() public payable {
|
||||
// ...
|
||||
HighestBidIncreased(msg.sender, msg.value); // Triggering event
|
||||
emit HighestBidIncreased(msg.sender, msg.value); // Triggering event
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -470,7 +470,7 @@ Example that shows how to use internal function types::
|
||||
|
||||
Another example that uses external function types::
|
||||
|
||||
pragma solidity ^0.4.11;
|
||||
pragma solidity ^0.4.20; // should actually be 0.4.21
|
||||
|
||||
contract Oracle {
|
||||
struct Request {
|
||||
@ -481,7 +481,7 @@ Another example that uses external function types::
|
||||
event NewRequest(uint);
|
||||
function query(bytes data, function(bytes memory) external callback) public {
|
||||
requests.push(Request(data, callback));
|
||||
NewRequest(requests.length - 1);
|
||||
emit NewRequest(requests.length - 1);
|
||||
}
|
||||
function reply(uint requestID, bytes response) public {
|
||||
// Here goes the check that the reply comes from a trusted source
|
||||
|
@ -40,7 +40,7 @@ contract StandardToken is Token {
|
||||
if (balance[_from] >= _value && balance[_to] + _value >= balance[_to]) {
|
||||
balance[_from] -= _value;
|
||||
balance[_to] += _value;
|
||||
Transfer(_from, _to, _value);
|
||||
emit Transfer(_from, _to, _value);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
@ -49,7 +49,7 @@ contract StandardToken is Token {
|
||||
|
||||
function approve(address _spender, uint256 _value) public returns (bool success) {
|
||||
m_allowance[msg.sender][_spender] = _value;
|
||||
Approval(msg.sender, _spender, _value);
|
||||
emit Approval(msg.sender, _spender, _value);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user