You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/src/user-guide/tutorials/auction.md
+11-9Lines changed: 11 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -80,7 +80,7 @@ contract Auction {
80
80
81
81
Notice that the constructor receives values for `bidding_time` and `beneficiary_addr` and uses them to initialize the contract's `auction_end_time` and `beneficiary` variables.
82
82
83
-
The other thing to notice about the constructor is that there are two additional arguments passed to the constructor: `must self` and `ctx: Context`.
83
+
The other thing to notice about the constructor is that there are two additional arguments passed to the constructor: `mut self` and `ctx: Context`.
84
84
85
85
#### self
86
86
@@ -91,12 +91,11 @@ Here, you are not only using `self` but you are prepending it with `mut`. `mut`
91
91
92
92
#### Context
93
93
94
-
Context is used to track deadlines for requests. It gives the contract the ability to cancel functions that have taken too long to run, and provides a structure for storing values that are scoped to a particular request so that they can be accessed anywhere in the call chain. This will be familiar to Go and Rust developers, as Context is often used in the same way in those languages and is frequently employed when working with external API calls. It is conventional to name the context object `ctx`.
94
+
Context is used to gate access to certain features including emitting logs, creating contracts, reading messages and transferring ETH. It is conventional to name the context object `ctx`. The `Context` object needs to be passed as the *first* parameter to a function unless the function also takes `self`, in which case the `Context` object should be passed as the second parameter. `Context` must be expicitly made mutable if it will invoke functions that changes the blockchain data, whereas an immutable reference to `Context` can be used where read-only access to the blockchain is needed.
95
95
96
-
Read more on [Context in Go](https://www.makeuseof.com/go-contexts/)
97
-
Read more on [Context in Rust](https://docs.rs/ctx/latest/ctx/)
96
+
Read more on [Context in Fe](https://github.com/ethereum/fe/issues/558)
98
97
99
-
In Fe contracts `ctx`will also be used to track transaction and blockchain data including`msg.sender`, `msg.value`, `block.timestamp` etc.
98
+
In Fe contracts `ctx`is where you can find transaction data such as`msg.sender`, `msg.value`, `block.timestamp` etc.
The method first checks that the current block timestamp is not later than the contract's `aution_end_time` variable. If it *is* later, then the contract reverts. This is triggered using the []`revert`](../spec/statements/revert.md) keyword. The `revert` can accept a struct that becomes encoded as [revert data](https://github.com/ethereum/EIPs/issues/838). Here you can just revert without any arguments. Add the following definition somewhere in `Auction.fe` outside the main contract definition:
125
+
The method first checks that the current block timestamp is not later than the contract's `aution_end_time` variable. If it *is* later, then the contract reverts. This is triggered using the [`revert`](../spec/statements/revert.md) keyword. The `revert` can accept a struct that becomes encoded as [revert data](https://github.com/ethereum/EIPs/issues/838). Here you can just revert without any arguments. Add the following definition somewhere in `Auction.fe` outside the main contract definition:
>**Note** that in this case `mut` is used with `ctx` because `send_value` is making changes to the blockchain (it is moving ETH from one address to another).
175
+
176
+
175
177
### End the auction
176
178
177
179
Finally, you need to add a way to end the auction. This will check whether the bidding period is over, and if it is, automatically trigger the payment to the beneficiary and emit the address of the winner in an event.
@@ -217,15 +219,15 @@ To help test the contract without having to decode transaction logs, you can add
217
219
You can add the following functions to the contract:
0 commit comments