Skip to content

Commit

Permalink
Update Contracts docs to make examples compile (#2170)
Browse files Browse the repository at this point in the history
* Update access-control.adoc to make compile

Add call to `ERC20("MyToken", "TKN")` in `MyToken` constructor

* Update access-control.adoc to make compile

Add call to `ERC20("MyToken", "TKN")` in `MyToken` constructor

* Update access-control.adoc MyToken formatting

* Update erc20-supply.adoc to make compile

Add call to `ERC20("MyToken", "TKN")` in `ERC20FixedSupply` constructor

* Update erc20-supply.adoc to make compile

Add constructor to `ERC20WithMinerReward`

* Update erc20-supply.adoc to make compile

In `MinerRewardMinter` use `ERC20MinterPauser`

* Update erc20-supply.adoc to make compile

Add constructor and override to `ERC20WithAutoMinerReward`

* Update erc777.adoc to make compile

* Update gsn-strategies.adoc to make compile

* Update gsn-strategies.adoc to make compile

Fix imports, add overrides, and revert reason to `MyContract`
  • Loading branch information
abcoathup authored Apr 7, 2020
1 parent 885378e commit 05d1618
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 15 deletions.
10 changes: 5 additions & 5 deletions docs/modules/ROOT/pages/access-control.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ contract MyToken is ERC20, AccessControl {
// Create a new role identifier for the minter role
bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
constructor(address minter) public {
constructor(address minter) public ERC20("MyToken", "TKN") {
// Grant the minter role to a specified account
_setupRole(MINTER_ROLE, minter);
}
Expand Down Expand Up @@ -97,7 +97,7 @@ contract MyToken is ERC20, AccessControl {
bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
bytes32 public constant BURNER_ROLE = keccak256("BURNER_ROLE");
constructor(address minter, address burner) public {
constructor(address minter, address burner) public ERC20("MyToken", "TKN") {
_setupRole(MINTER_ROLE, minter);
_setupRole(BURNER_ROLE, burner);
}
Expand All @@ -109,7 +109,7 @@ contract MyToken is ERC20, AccessControl {
function burn(address from, uint256 amount) public {
require(hasRole(BURNER_ROLE, msg.sender), "Caller is not a burner");
_burn(from, amount);
_burn(from, amount);
}
}
----
Expand Down Expand Up @@ -140,7 +140,7 @@ contract MyToken is ERC20, AccessControl {
bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
bytes32 public constant BURNER_ROLE = keccak256("BURNER_ROLE");
constructor() ERC20("MyToken", "TKN") public {
constructor() public ERC20("MyToken", "TKN") {
// Grant the contract deployer the default admin role: it will be able
// to grant and revoke any roles
_setupRole(DEFAULT_ADMIN_ROLE, msg.sender);
Expand All @@ -153,7 +153,7 @@ contract MyToken is ERC20, AccessControl {
function burn(address from, uint256 amount) public {
require(hasRole(BURNER_ROLE, msg.sender), "Caller is not a burner");
_burn(from, amount);
_burn(from, amount);
}
}
----
Expand Down
12 changes: 8 additions & 4 deletions docs/modules/ROOT/pages/erc20-supply.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Starting with Contracts v2 this pattern is not only discouraged, but disallowed.
[source,solidity]
----
contract ERC20FixedSupply is ERC20 {
constructor() public {
constructor() public ERC20("Fixed", "FIX") {
_mint(msg.sender, 1000);
}
}
Expand All @@ -44,6 +44,8 @@ The mechanism we will implement is a token reward for the miners that produce Et
[source,solidity]
----
contract ERC20WithMinerReward is ERC20 {
constructor() public ERC20("Reward", "RWD") {}
function mintMinerReward() public {
_mint(block.coinbase, 1000);
}
Expand All @@ -64,9 +66,9 @@ The accounts with the minter role don't need to be externally owned, though, and
[source,solidity]
----
contract MinerRewardMinter {
ERC20DeployReady _token;
ERC20MinterPauser _token;
constructor(ERC20DeployReady token) public {
constructor(ERC20MinterPauser token) public {
_token = token;
}
Expand All @@ -90,11 +92,13 @@ Adding to our previous supply mechanism, we can use this to mint a miner reward
[source,solidity]
----
contract ERC20WithAutoMinerReward is ERC20 {
constructor() public ERC20("Reward", "RWD") {}
function _mintMinerReward() internal {
_mint(block.coinbase, 1000);
}
function _transfer(address from, address to, uint256 value) internal {
function _transfer(address from, address to, uint256 value) internal override {
_mintMinerReward();
super._transfer(from, to, value);
}
Expand Down
4 changes: 2 additions & 2 deletions docs/modules/ROOT/pages/erc777.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ We will replicate the `GLD` example of the xref:erc20.adoc#constructing-an-erc20

[source,solidity]
----
pragma solidity ^0.5.0;
pragma solidity ^0.6.0;
import "@openzeppelin/contracts/token/ERC777/ERC777.sol";
Expand All @@ -30,7 +30,7 @@ contract GLDToken is ERC777 {
ERC777("Gold", "GLD", defaultOperators)
public
{
_mint(msg.sender, msg.sender, initialSupply, "", "");
_mint(msg.sender, initialSupply, "", "");
}
}
----
Expand Down
16 changes: 12 additions & 4 deletions docs/modules/ROOT/pages/gsn-strategies.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Instead of using `GSNRecipient` directly, your GSN recipient contract will inste

[source,solidity]
----
import "@openzeppelin/contracts/GSN/GSNRecipientSignature";
import "@openzeppelin/contracts/GSN/GSNRecipientSignature.sol";
contract MyContract is GSNRecipientSignature {
constructor(address trustedSigner) public GSNRecipientSignature(trustedSigner) {
Expand Down Expand Up @@ -106,8 +106,8 @@ Your GSN recipient contract needs to inherit from `GSNRecipientERC20Fee` along w

[source,solidity]
----
import "@openzeppelin/contracts/GSN/GSNRecipientERC20Fee";
import "@openzeppelin/contracts/access/AccessControl";
import "@openzeppelin/contracts/GSN/GSNRecipientERC20Fee.sol";
import "@openzeppelin/contracts/access/AccessControl.sol";
contract MyContract is GSNRecipientERC20Fee, AccessControl {
bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
Expand All @@ -116,8 +116,16 @@ contract MyContract is GSNRecipientERC20Fee, AccessControl {
_setupRole(MINTER_ROLE, _msgSender());
}
function _msgSender() internal view override(Context, GSNRecipient) returns (address payable) {
return GSNRecipient._msgSender();
}
function _msgData() internal view override(Context, GSNRecipient) returns (bytes memory) {
return GSNRecipient._msgData();
}
function mint(address account, uint256 amount) public {
require(hasRole(MINTER_ROLE, _msgSender()));
require(hasRole(MINTER_ROLE, _msgSender()), "Caller is not a minter");
_mint(account, amount);
}
}
Expand Down

0 comments on commit 05d1618

Please sign in to comment.