solidity中将地址转化为字节码,进行判断地址的所属权
•技术分享
1432
0
例如可以进行参加领取礼物活动时只让用户领取,而恶意合约无法领取
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.4.0 <0.9.0;
contract addressCode{
function getCode(address add) public view returns(bytes memory) {
return address(add).code;
}
function gift() public view returns(uint256){
bytes memory senderCode = getCode(msg.sender);
require(uint8(senderCode.length) == 0 ,unicode"合约不能调用,只能用户调用");
return senderCode.length;
}
function giftContruct(address add_) public view returns(uint256){
bytes memory senderCode = getCode(add_);
// require(uint8(senderCode.length) == 0 ,unicode"合约不能调用,只能用户调用");
return senderCode.length;
}
}
版权属于:戏人看戏博客网
本文链接:https://day.nb.sb/archives/1342.html
若无注明均为戏人看戏原创,转载请注明出处,感谢您的支持!