Skip to content

Commit

Permalink
Update EIP-6909: Update reference implementation to specification
Browse files Browse the repository at this point in the history
Merged by EIP-Bot.
  • Loading branch information
jtriley-eth authored Aug 18, 2023
1 parent 7069752 commit 9a8a1f5
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions EIPS/eip-6909.md
Original file line number Diff line number Diff line change
Expand Up @@ -510,46 +510,52 @@ contract ERC6909 {
/// @param receiver The address of the receiver.
/// @param id The id of the token.
/// @param amount The amount of the token.
function transfer(address receiver, uint256 id, uint256 amount) public {
function transfer(address receiver, uint256 id, uint256 amount) public returns (bool) {
if (balanceOf[msg.sender][id] < amount) revert InsufficientBalance(msg.sender, id);
balanceOf[msg.sender][id] -= amount;
balanceOf[receiver][id] += amount;
emit Transfer(msg.sender, receiver, id, amount);
return true;
}
/// @notice Transfers an amount of an id from a sender to a receiver.
/// @param sender The address of the sender.
/// @param receiver The address of the receiver.
/// @param id The id of the token.
/// @param amount The amount of the token.
function transferFrom(address sender, address receiver, uint256 id, uint256 amount) public {
function transferFrom(address sender, address receiver, uint256 id, uint256 amount) public returns (bool) {
if (sender != msg.sender && !isOperator[sender][msg.sender]) {
if (allowance[sender][msg.sender][id] < amount) {
revert InsufficientPermission(msg.sender, id);
uint256 senderAllowance = allowance[sender][msg.sender][id];
if (senderAllowance < amount) revert InsufficientPermission(msg.sender, id);
if (senderAllowance != type(uint256).max) {
allowance[sender][msg.sender][id] = senderAllowance - amount;
}
allowance[sender][msg.sender][id] -= amount;
}
if (balanceOf[sender][id] < amount) revert InsufficientBalance(sender, id);
balanceOf[sender][id] -= amount;
balanceOf[receiver][id] += amount;
emit Transfer(sender, receiver, id, amount);
return true;
}
/// @notice Approves an amount of an id to a spender.
/// @param spender The address of the spender.
/// @param id The id of the token.
/// @param amount The amount of the token.
function approve(address spender, uint256 id, uint256 amount) public {
function approve(address spender, uint256 id, uint256 amount) public returns (bool) {
allowance[msg.sender][spender][id] = amount;
emit Approval(msg.sender, spender, id, amount);
return true;
}
/// @notice Sets or removes a spender as an operator for the caller.
/// @param spender The address of the spender.
/// @param approved The approval status.
function setOperator(address spender, bool approved) public {
function setOperator(address spender, bool approved) public returns (bool) {
isOperator[msg.sender][spender] = approved;
emit OperatorSet(msg.sender, spender, approved);
return true;
}
/// @notice Checks if a contract implements an interface.
Expand Down

0 comments on commit 9a8a1f5

Please sign in to comment.