From 0010027e17b133266e86963ee003aa42c8883c84 Mon Sep 17 00:00:00 2001 From: chriseth Date: Thu, 30 Dec 2021 12:31:20 +0100 Subject: [PATCH] Fix mapping example. --- docs/types/mapping-types.rst | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/docs/types/mapping-types.rst b/docs/types/mapping-types.rst index c026d73f2..18f3bf827 100644 --- a/docs/types/mapping-types.rst +++ b/docs/types/mapping-types.rst @@ -84,23 +84,24 @@ The example below uses ``_allowances`` to record the amount someone else is allo } function transferFrom(address sender, address recipient, uint256 amount) public returns (bool) { + require(_allowances[sender][msg.sender] >= amount, "ERC20: Allowance not high enough."); + _allowances[sender][msg.sender] -= amount; _transfer(sender, recipient, amount); - approve(sender, msg.sender, amount); return true; } - function approve(address owner, address spender, uint256 amount) public returns (bool) { - require(owner != address(0), "ERC20: approve from the zero address"); + function approve(address spender, uint256 amount) public returns (bool) { require(spender != address(0), "ERC20: approve to the zero address"); - _allowances[owner][spender] = amount; - emit Approval(owner, spender, amount); + _allowances[msg.sender][spender] = amount; + emit Approval(msg.sender, spender, amount); return true; } function _transfer(address sender, address recipient, uint256 amount) internal { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); + require(_balances[sender] >= amount, "ERC20: Not enough funds."); _balances[sender] -= amount; _balances[recipient] += amount;