@@ -241,7 +241,6 @@ pragma solidity ^0.8.0;
241
241
import "./IERC1155.sol";
242
242
import "./IERC1155Receiver.sol";
243
243
import "./IERC1155MetadataURI.sol";
244
- import "https://github.com/AmazingAng/WTF-Solidity/blob/main/34_ERC721/Address.sol";
245
244
import "https://github.com/AmazingAng/WTF-Solidity/blob/main/34_ERC721/String.sol";
246
245
import "https://github.com/AmazingAng/WTF-Solidity/blob/main/34_ERC721/IERC165.sol";
247
246
@@ -250,8 +249,8 @@ import "https://github.com/AmazingAng/WTF-Solidity/blob/main/34_ERC721/IERC165.s
250
249
* 见 https://eips.ethereum.org/EIPS/eip-1155
251
250
*/
252
251
contract ERC1155 is IERC165, IERC1155, IERC1155MetadataURI {
253
- using Address for address; // 使用Address库,用isContract来判断地址是否为合约
254
- using Strings for uint256; // 使用Strings库
252
+
253
+ using Strings for uint256; // 使用String库
255
254
// Token名称
256
255
string public name;
257
256
// Token代号
@@ -493,6 +492,9 @@ contract ERC1155 is IERC165, IERC1155, IERC1155MetadataURI {
493
492
emit TransferBatch(operator, from, address(0), ids, amounts);
494
493
}
495
494
495
+ // 错误 无效的接收者
496
+ error ERC1155InvalidReceiver(address receiver);
497
+
496
498
// @dev ERC1155的安全转账检查
497
499
function _doSafeTransferAcceptanceCheck(
498
500
address operator,
@@ -502,15 +504,20 @@ contract ERC1155 is IERC165, IERC1155, IERC1155MetadataURI {
502
504
uint256 amount,
503
505
bytes memory data
504
506
) private {
505
- if (to.isContract() ) {
507
+ if (to.code.length > 0 ) {
506
508
try IERC1155Receiver(to).onERC1155Received(operator, from, id, amount, data) returns (bytes4 response) {
507
509
if (response != IERC1155Receiver.onERC1155Received.selector) {
508
- revert("ERC1155: ERC1155Receiver rejected tokens");
510
+ revert ERC1155InvalidReceiver(to);
511
+ }
512
+ } catch (bytes memory reason) {
513
+ if (reason.length == 0) {
514
+ revert ERC1155InvalidReceiver(to);
515
+ } else {
516
+ /// @solidity memory-safe-assembly
517
+ assembly {
518
+ revert(add(32, reason), mload(reason))
519
+ }
509
520
}
510
- } catch Error(string memory reason) {
511
- revert(reason);
512
- } catch {
513
- revert("ERC1155: transfer to non-ERC1155Receiver implementer");
514
521
}
515
522
}
516
523
}
@@ -524,17 +531,22 @@ contract ERC1155 is IERC165, IERC1155, IERC1155MetadataURI {
524
531
uint256[] memory amounts,
525
532
bytes memory data
526
533
) private {
527
- if (to.isContract() ) {
534
+ if (to.code.length > 0 ) {
528
535
try IERC1155Receiver(to).onERC1155BatchReceived(operator, from, ids, amounts, data) returns (
529
536
bytes4 response
530
537
) {
531
538
if (response != IERC1155Receiver.onERC1155BatchReceived.selector) {
532
- revert("ERC1155: ERC1155Receiver rejected tokens");
539
+ revert ERC1155InvalidReceiver(to);
540
+ }
541
+ } catch (bytes memory reason) {
542
+ if (reason.length == 0) {
543
+ revert ERC1155InvalidReceiver(to);
544
+ } else {
545
+ /// @solidity memory-safe-assembly
546
+ assembly {
547
+ revert(add(32, reason), mload(reason))
548
+ }
533
549
}
534
- } catch Error(string memory reason) {
535
- revert(reason);
536
- } catch {
537
- revert("ERC1155: transfer to non-ERC1155Receiver implementer");
538
550
}
539
551
}
540
552
}
0 commit comments