|
@@ -137,8 +137,9 @@ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI {
|
|
|
|
|
|
_beforeTokenTransfer(operator, from, to, _asSingletonArray(id), _asSingletonArray(amount), data);
|
|
|
|
|
|
- _balances[id][from] = _balances[id][from] - amount;
|
|
|
- _balances[id][to] = _balances[id][to] + amount;
|
|
|
+ require(_balances[id][from] >= amount, "ERC1155: insufficient balance for transfer");
|
|
|
+ _balances[id][from] -= amount;
|
|
|
+ _balances[id][to] += amount;
|
|
|
|
|
|
emit TransferSingle(operator, from, to, id, amount);
|
|
|
|
|
@@ -174,8 +175,9 @@ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI {
|
|
|
uint256 id = ids[i];
|
|
|
uint256 amount = amounts[i];
|
|
|
|
|
|
- _balances[id][from] = _balances[id][from] - amount;
|
|
|
- _balances[id][to] = _balances[id][to] + amount;
|
|
|
+ require(_balances[id][from] >= amount, "ERC1155: insufficient balance for transfer");
|
|
|
+ _balances[id][from] -= amount;
|
|
|
+ _balances[id][to] += amount;
|
|
|
}
|
|
|
|
|
|
emit TransferBatch(operator, from, to, ids, amounts);
|
|
@@ -224,7 +226,7 @@ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI {
|
|
|
|
|
|
_beforeTokenTransfer(operator, address(0), account, _asSingletonArray(id), _asSingletonArray(amount), data);
|
|
|
|
|
|
- _balances[id][account] = _balances[id][account] + amount;
|
|
|
+ _balances[id][account] += amount;
|
|
|
emit TransferSingle(operator, address(0), account, id, amount);
|
|
|
|
|
|
_doSafeTransferAcceptanceCheck(operator, address(0), account, id, amount, data);
|
|
@@ -248,7 +250,7 @@ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI {
|
|
|
_beforeTokenTransfer(operator, address(0), to, ids, amounts, data);
|
|
|
|
|
|
for (uint i = 0; i < ids.length; i++) {
|
|
|
- _balances[ids[i]][to] = amounts[i] + _balances[ids[i]][to];
|
|
|
+ _balances[ids[i]][to] += amounts[i];
|
|
|
}
|
|
|
|
|
|
emit TransferBatch(operator, address(0), to, ids, amounts);
|
|
@@ -271,7 +273,8 @@ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI {
|
|
|
|
|
|
_beforeTokenTransfer(operator, account, address(0), _asSingletonArray(id), _asSingletonArray(amount), "");
|
|
|
|
|
|
- _balances[id][account] = _balances[id][account] - amount;
|
|
|
+ require(_balances[id][account] >= amount, "ERC1155: burn amount exceeds balance");
|
|
|
+ _balances[id][account] -= amount;
|
|
|
|
|
|
emit TransferSingle(operator, account, address(0), id, amount);
|
|
|
}
|
|
@@ -292,7 +295,11 @@ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI {
|
|
|
_beforeTokenTransfer(operator, account, address(0), ids, amounts, "");
|
|
|
|
|
|
for (uint i = 0; i < ids.length; i++) {
|
|
|
- _balances[ids[i]][account] = _balances[ids[i]][account] - amounts[i];
|
|
|
+ uint256 id = ids[i];
|
|
|
+ uint256 amount = amounts[i];
|
|
|
+
|
|
|
+ require(_balances[id][account] >= amount, "ERC1155: burn amount exceeds balance");
|
|
|
+ _balances[id][account] -= amount;
|
|
|
}
|
|
|
|
|
|
emit TransferBatch(operator, account, address(0), ids, amounts);
|