Update Contracts docs to make examples compile (#2170)

* 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`
pull/2172/head
Andrew B Coathup 5 years ago committed by GitHub
parent 885378e421
commit 05d1618d01
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      docs/modules/ROOT/pages/access-control.adoc
  2. 12
      docs/modules/ROOT/pages/erc20-supply.adoc
  3. 4
      docs/modules/ROOT/pages/erc777.adoc
  4. 16
      docs/modules/ROOT/pages/gsn-strategies.adoc

@ -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);
}
@ -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);
}
@ -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);

@ -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);
}
}
@ -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);
}
@ -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;
}
@ -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);
}

@ -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";
@ -30,7 +30,7 @@ contract GLDToken is ERC777 {
ERC777("Gold", "GLD", defaultOperators)
public
{
_mint(msg.sender, msg.sender, initialSupply, "", "");
_mint(msg.sender, initialSupply, "", "");
}
}
----

@ -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) {
@ -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");
@ -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);
}
}

Loading…
Cancel
Save