Skip to content

Commit fe110ac

Browse files
jmcook1186cburgdorf
authored andcommitted
apply changes from review
Signed-off-by: jmc <33655003+jmcook1186@users.noreply.github.com>
1 parent 42b5ad2 commit fe110ac

2 files changed

Lines changed: 14 additions & 12 deletions

File tree

docs/src/user-guide/example_contracts/auction_contract.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,15 @@ contract Auction {
8383
ctx.send_value(to: self.beneficiary, wei: self.highest_bid)
8484
}
8585
86-
pub fn check_highest_bidder(mut self, ctx: Context) -> address {
86+
pub fn check_highest_bidder(mut self) -> address {
8787
return self.highest_bidder;
8888
}
8989
90-
pub fn check_highest_bid(mut self, ctx: Context) -> u256 {
90+
pub fn check_highest_bid(mut self) -> u256 {
9191
return self.highest_bid;
9292
}
9393
94-
pub fn check_ended(mut self, ctx: Context) -> bool {
94+
pub fn check_ended(mut self) -> bool {
9595
return self.ended;
9696
}
9797
}

docs/src/user-guide/tutorials/auction.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ contract Auction {
8080

8181
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.
8282

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`.
8484

8585
#### self
8686

@@ -91,12 +91,11 @@ Here, you are not only using `self` but you are prepending it with `mut`. `mut`
9191

9292
#### Context
9393

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.
9595

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)
9897

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.
10099

101100

102101
### Bidding
@@ -123,7 +122,7 @@ pub fn bid(mut self, mut ctx: Context) {
123122
}
124123
```
125124

126-
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:
127126

128127
```rust
129128
struct AuctionAlreadyEnded {
@@ -172,6 +171,9 @@ pub fn withdraw(mut self, mut ctx: Context) -> bool {
172171
}
173172
```
174173

174+
>**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+
175177
### End the auction
176178

177179
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
217219
You can add the following functions to the contract:
218220

219221
```rust
220-
pub fn check_highest_bidder(mut self, ctx: Context) -> address {
222+
pub fn check_highest_bidder(mut self) -> address {
221223
return self.highest_bidder;
222224
}
223225

224-
pub fn check_highest_bid(mut self, ctx: Context) -> u256 {
226+
pub fn check_highest_bid(mut self) -> u256 {
225227
return self.highest_bid;
226228
}
227229

228-
pub fn check_ended(mut self, ctx: Context) -> bool {
230+
pub fn check_ended(mut self) -> bool {
229231
return self.ended;
230232
}
231233
```

0 commit comments

Comments
 (0)