手把手教你智能合约放弃所有权|丢弃权限|丢权限|放弃所有权

准备工作

  1. 准备好【权限控制】相关代码
  2. 有足够的金额来支付gas费用

对智能合约有疑问请参考我的另一篇文章《从零教你学习以太坊ERC20智能合约》

相关操作

请在需要拥有【丢弃权限】功能的合约中添加以下代码,deploy完成后执行renounceOwnership()函数即可完成丢弃权限操作,此时权限地址为0x0000000000000000000000000000000000000000

注:renounceOwnership()操作不可挽回!

contract Ownable is Context {
    address private _owner;

    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    //构造函数
    constructor () internal {
        address msgSender = _msgSender();
        _owner = msgSender;
        emit OwnershipTransferred(address(0), msgSender);
    }

    //权限所有人
    function owner() public view returns (address) {
        return _owner;
    }

    /**
     * 只有管理员可以操作
     */
    modifier onlyOwner() {
        require(_owner == _msgSender(), "Ownable: caller is not the owner");
        _;
    }

     /**
     * 丢弃权限
     */
    function renounceOwnership() public virtual onlyOwner {
        emit OwnershipTransferred(_owner, address(0));
        _owner = address(0);
    }

    /**
     * @dev 将合同的所有权转移到一个新帐户(“newOwner”)。
	 *      只能由当前所有者调用。
     */
    function transferOwnership(address newOwner) public virtual onlyOwner {
        require(newOwner != address(0), "Ownable: new owner is the zero address");
        emit OwnershipTransferred(_owner, newOwner);
        _owner = newOwner;
    }
}
  • 6
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
好的,我会回答你的问题。关于 apriori 算法的原理,它是一种基于频繁项集的挖掘算法,用于发现数据中的频繁项集。频繁项集是指在数据集中经常出现在一起的物品的集合,例如在购物数据中,经常一起购买的商品就是一个频繁项集。 apriori 算法的核心思想是利用频繁项集的性质,从而减少搜索空间。具体来说,apriori 算法采用了一种称为“逐层搜索”的方法,即首先找到所有的单个物品作为频繁项集,然后基于单个物品,逐步扩展物品数量,直到无法扩展为止。在扩展物品的过程中,apriori 算法利用了一个重要的性质:如果一个项集不是频繁的,那么它的所有超集也不是频繁的。这个性质可以帮助我们剪枝,减少搜索空间。 关于 apriori 算法的代码实现,以下是一个简单的 Python 实现,供你参考: ```python def load_dataset(): return [[1,3,4], [2,3,5], [1,2,3,5], [2,5]] def create_c1(dataset): c1 = [] for transaction in dataset: for item in transaction: if not [item] in c1: c1.append([item]) c1.sort() return list(map(frozenset, c1)) def scan_dataset(dataset, candidates, min_support): support_counts = {} for transaction in dataset: for candidate in candidates: if candidate.issubset(transaction): support_counts[candidate] = support_counts.get(candidate, 0) + 1 num_items = float(len(dataset)) frequent_items = [] support_data = {} for candidate in support_counts: support = support_counts[candidate] / num_items if support >= min_support: frequent_items.append(candidate) support_data[candidate] = support return frequent_items, support_data def apriori_gen(frequent_items, k): next_candidates = [] num_items = len(frequent_items) for i in range(num_items): for j in range(i+1, num_items): itemset1 = list(frequent_items[i])[:k-2] itemset2 = list(frequent_items[j])[:k-2] itemset1.sort() itemset2.sort() if itemset1 == itemset2: next_candidates.append(frequent_items[i] | frequent_items[j]) return next_candidates def apriori(dataset, min_support=0.5): C1 = create_c1(dataset) frequent_items, support_data = scan_dataset(dataset, C1, min_support) all_frequent_items = [frequent_items] k = 2 while len(all_frequent_items[k-2]) > 0: next_candidates = apriori_gen(all_frequent_items[k-2], k) next_frequent_items, next_support_data = scan_dataset(dataset, next_candidates, min_support) support_data.update(next_support_data) all_frequent_items.append(next_frequent_items) k += 1 return all_frequent_items, support_data ``` 这段代码实现了 apriori 算法的主要逻辑,包括数据集加载、候选项集生成、频繁项集挖掘等步骤。你可以通过调用 apriori 函数来运行算法,并设置最小支持度等参数。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

zgsdzczh

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值