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 {
|
function deposit(bytes32 _id) public payable {
|
||||||
// Any call to this function (even deeply nested) can
|
// Events are emitted using `emit`, followed by
|
||||||
// be detected from the JavaScript API by filtering
|
// the name of the event and the arguments
|
||||||
// for `Deposit` to be called.
|
// (if any) in parentheses. Any such invocation
|
||||||
Deposit(msg.sender, _id, msg.value);
|
// (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 {
|
contract Coin {
|
||||||
// The keyword "public" makes those variables
|
// 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;
|
if (balances[msg.sender] < amount) return;
|
||||||
balances[msg.sender] -= amount;
|
balances[msg.sender] -= amount;
|
||||||
balances[receiver] += amount;
|
balances[receiver] += amount;
|
||||||
Sent(msg.sender, receiver, amount);
|
emit Sent(msg.sender, receiver, amount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -157,10 +157,10 @@ single account.
|
|||||||
.. index:: event
|
.. index:: event
|
||||||
|
|
||||||
The line ``event Sent(address from, address to, uint amount);`` declares
|
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
|
``send``. User interfaces (as well as server applications of course) can
|
||||||
listen for those events being fired on the blockchain without much
|
listen for those events being emitted on the blockchain without much
|
||||||
cost. As soon as it is fired, the listener will also receive the
|
cost. As soon as it is emitted, the listener will also receive the
|
||||||
arguments ``from``, ``to`` and ``amount``, which makes it easy to track
|
arguments ``from``, ``to`` and ``amount``, which makes it easy to track
|
||||||
transactions. In order to listen for this event, you would use ::
|
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 {
|
contract SimpleAuction {
|
||||||
// Parameters of the auction. Times are either
|
// Parameters of the auction. Times are either
|
||||||
@ -282,7 +282,7 @@ activate themselves.
|
|||||||
}
|
}
|
||||||
highestBidder = msg.sender;
|
highestBidder = msg.sender;
|
||||||
highestBid = msg.value;
|
highestBid = msg.value;
|
||||||
HighestBidIncreased(msg.sender, msg.value);
|
emit HighestBidIncreased(msg.sender, msg.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Withdraw a bid that was overbid.
|
/// Withdraw a bid that was overbid.
|
||||||
@ -325,7 +325,7 @@ activate themselves.
|
|||||||
|
|
||||||
// 2. Effects
|
// 2. Effects
|
||||||
ended = true;
|
ended = true;
|
||||||
AuctionEnded(highestBidder, highestBid);
|
emit AuctionEnded(highestBidder, highestBid);
|
||||||
|
|
||||||
// 3. Interaction
|
// 3. Interaction
|
||||||
beneficiary.transfer(highestBid);
|
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 {
|
contract BlindAuction {
|
||||||
struct Bid {
|
struct Bid {
|
||||||
@ -509,7 +509,7 @@ high or low invalid bids.
|
|||||||
onlyAfter(revealEnd)
|
onlyAfter(revealEnd)
|
||||||
{
|
{
|
||||||
require(!ended);
|
require(!ended);
|
||||||
AuctionEnded(highestBidder, highestBid);
|
emit AuctionEnded(highestBidder, highestBid);
|
||||||
ended = true;
|
ended = true;
|
||||||
beneficiary.transfer(highestBid);
|
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 {
|
contract Purchase {
|
||||||
uint public value;
|
uint public value;
|
||||||
@ -574,7 +574,7 @@ Safe Remote Purchase
|
|||||||
onlySeller
|
onlySeller
|
||||||
inState(State.Created)
|
inState(State.Created)
|
||||||
{
|
{
|
||||||
Aborted();
|
emit Aborted();
|
||||||
state = State.Inactive;
|
state = State.Inactive;
|
||||||
seller.transfer(this.balance);
|
seller.transfer(this.balance);
|
||||||
}
|
}
|
||||||
@ -589,7 +589,7 @@ Safe Remote Purchase
|
|||||||
condition(msg.value == (2 * value))
|
condition(msg.value == (2 * value))
|
||||||
payable
|
payable
|
||||||
{
|
{
|
||||||
PurchaseConfirmed();
|
emit PurchaseConfirmed();
|
||||||
buyer = msg.sender;
|
buyer = msg.sender;
|
||||||
state = State.Locked;
|
state = State.Locked;
|
||||||
}
|
}
|
||||||
@ -601,7 +601,7 @@ Safe Remote Purchase
|
|||||||
onlyBuyer
|
onlyBuyer
|
||||||
inState(State.Locked)
|
inState(State.Locked)
|
||||||
{
|
{
|
||||||
ItemReceived();
|
emit ItemReceived();
|
||||||
// It is important to change the state first because
|
// It is important to change the state first because
|
||||||
// otherwise, the contracts called using `send` below
|
// otherwise, the contracts called using `send` below
|
||||||
// can call in again here.
|
// 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 {
|
contract SimpleAuction {
|
||||||
event HighestBidIncreased(address bidder, uint amount); // Event
|
event HighestBidIncreased(address bidder, uint amount); // Event
|
||||||
|
|
||||||
function bid() public payable {
|
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::
|
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 {
|
contract Oracle {
|
||||||
struct Request {
|
struct Request {
|
||||||
@ -481,7 +481,7 @@ Another example that uses external function types::
|
|||||||
event NewRequest(uint);
|
event NewRequest(uint);
|
||||||
function query(bytes data, function(bytes memory) external callback) public {
|
function query(bytes data, function(bytes memory) external callback) public {
|
||||||
requests.push(Request(data, callback));
|
requests.push(Request(data, callback));
|
||||||
NewRequest(requests.length - 1);
|
emit NewRequest(requests.length - 1);
|
||||||
}
|
}
|
||||||
function reply(uint requestID, bytes response) public {
|
function reply(uint requestID, bytes response) public {
|
||||||
// Here goes the check that the reply comes from a trusted source
|
// 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]) {
|
if (balance[_from] >= _value && balance[_to] + _value >= balance[_to]) {
|
||||||
balance[_from] -= _value;
|
balance[_from] -= _value;
|
||||||
balance[_to] += _value;
|
balance[_to] += _value;
|
||||||
Transfer(_from, _to, _value);
|
emit Transfer(_from, _to, _value);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
@ -49,7 +49,7 @@ contract StandardToken is Token {
|
|||||||
|
|
||||||
function approve(address _spender, uint256 _value) public returns (bool success) {
|
function approve(address _spender, uint256 _value) public returns (bool success) {
|
||||||
m_allowance[msg.sender][_spender] = _value;
|
m_allowance[msg.sender][_spender] = _value;
|
||||||
Approval(msg.sender, _spender, _value);
|
emit Approval(msg.sender, _spender, _value);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user