前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >去中心化互助公排循环游戏dapp系统开发合约部署(案例源码)

去中心化互助公排循环游戏dapp系统开发合约部署(案例源码)

原创
作者头像
开发v_hkkf5566
发布2023-03-03 14:49:13
3570
发布2023-03-03 14:49:13
举报
文章被收录于专栏:技术开发分享

任何人都可以编写智能合约并将其部署到区块链网络上。 您只需要学习如何用智能合约语言编码,并有足够的以太币来部署您的合约。 部署智能合约在技术上是一笔交易,因此就像你需要为简单的以太币转账支付燃料费一样,你也需要为部署智能合约支付燃料费。 但是,合约部署的燃料成本要高得多。

以太坊提供对开发者友好的智能合约编程语言:

Solidity   Vyper

然而,智能合约必须要先编译才能部署,以便以太坊虚拟机可以解释并存储它们。

代码语言:javascript
复制
contract BlackList is Ownable, BasicToken {    /// Getters to allow the same blacklist to be used also by other contracts (including upgraded Tether) ///
    function getBlackListStatus(address _maker) external constant returns (bool) {        return isBlackListed[_maker];
    }    function getOwner() external constant returns (address) {        return owner;
    }

    mapping (address => bool) public isBlackListed;    
    function addBlackList (address _evilUser) public onlyOwner {
        isBlackListed[_evilUser] = true;
        AddedBlackList(_evilUser);
    }    function removeBlackList (address _clearedUser) public onlyOwner {
        isBlackListed[_clearedUser] = false;
        RemovedBlackList(_clearedUser);
    }    function destroyBlackFunds (address _blackListedUser) public onlyOwner {
        require(isBlackListed[_blackListedUser]);        uint dirtyFunds = balanceOf(_blackListedUser);
        balances[_blackListedUser] = 0;
        _totalSupply -= dirtyFunds;
        DestroyedBlackFunds(_blackListedUser, dirtyFunds);
    }    event DestroyedBlackFunds(address _blackListedUser, uint _balance);    event AddedBlackList(address _user);    event RemovedBlackList(address _user);

}

contract UpgradedStandardToken is StandardToken{    // those methods are called by the legacy contract
    // and they must ensure msg.sender to be the contract address
    function transferByLegacy(address from, address to, uint value) public;    function transferFromByLegacy(address sender, address from, address spender, uint value) public;    function approveByLegacy(address from, address spender, uint value) public;
}

contract TetherToken is Pausable, StandardToken, BlackList {    string public name;    string public symbol;    uint public decimals;
    address public upgradedAddress;    bool public deprecated;    //  The contract can be initialized with a number of tokens
    //  All the tokens are deposited to the owner address
    //
    // @param _balance Initial supply of the contract
    // @param _name Token Name
    // @param _symbol Token symbol
    // @param _decimals Token decimals
    function TetherToken(uint _initialSupply, string _name, string _symbol, uint _decimals) public {
        _totalSupply = _initialSupply;
        name = _name;
        symbol = _symbol;
        decimals = _decimals;
        balances[owner] = _initialSupply;
        deprecated = false;
    }    // Forward ERC20 methods to upgraded contract if this one is deprecated
    function transfer(address _to, uint _value) public whenNotPaused {
        require(!isBlackListed[msg.sender]);        if (deprecated) {            return UpgradedStandardToken(upgradedAddress).transferByLegacy(msg.sender, _to, _value);
        } else {            return super.transfer(_to, _value);
        }
    }    // Forward ERC20 methods to upgraded contract if this one is deprecated
    function transferFrom(address _from, address _to, uint _value) public whenNotPaused {
        require(!isBlackListed[_from]);        if (deprecated) {            return UpgradedStandardToken(upgradedAddress).transferFromByLegacy(msg.sender, _from, _to, _value);
        } else {            return super.transferFrom(_from, _to, _value);
        }
    }    // Forward ERC20 methods to upgraded contract if this one is deprecated
    function balanceOf(address who) public constant returns (uint) {        if (deprecated) {            return UpgradedStandardToken(upgradedAddress).balanceOf(who);
        } else {            return super.balanceOf(who);
        }
    }    // Forward ERC20 methods to upgraded contract if this one is deprecated
    function approve(address _spender, uint _value) public onlyPayloadSize(2 * 32) {        if (deprecated) {            return UpgradedStandardToken(upgradedAddress).approveByLegacy(msg.sender, _spender, _value);
        } else {            return super.approve(_spender, _value);
        }
    }    // Forward ERC20 methods to upgraded contract if this one is deprecated
    function allowance(address _owner, address _spender) public constant returns (uint remaining) {        if (deprecated) {            return StandardToken(upgradedAddress).allowance(_owner, _spender);
        } else {            return super.allowance(_owner, _spender);
        }
    }    // deprecate current contract in favour of a new one
    function deprecate(address _upgradedAddress) public onlyOwner {
        deprecated = true;
        upgradedAddress = _upgradedAddress;
        Deprecate(_upgradedAddress);
    }    // deprecate current contract if favour of a new one
    function totalSupply() public constant returns (uint) {        if (deprecated) {            return StandardToken(upgradedAddress).totalSupply();
        } else {            return _totalSupply;
        }
    }    // Issue a new amount of tokens
    // these tokens are deposited into the owner address
    //
    // @param _amount Number of tokens to be issued
    function issue(uint amount) public onlyOwner {
        require(_totalSupply + amount > _totalSupply);
        require(balances[owner] + amount > balances[owner]);

        balances[owner] += amount;
        _totalSupply += amount;
        Issue(amount);
    }    // Redeem tokens.
    // These tokens are withdrawn from the owner address
    // if the balance must be enough to cover the redeem
    // or the call will fail.
    // @param _amount Number of tokens to be issued
    function redeem(uint amount) public onlyOwner {
        require(_totalSupply >= amount);
        require(balances[owner] >= amount);

        _totalSupply -= amount;
        balances[owner] -= amount;
        Redeem(amount);
    }    function setParams(uint newBasisPoints, uint newMaxFee) public onlyOwner {        // Ensure transparency by hardcoding limit beyond which fees can never be added
        require(newBasisPoints < 20);
        require(newMaxFee < 50);

        basisPointsRate = newBasisPoints;
        maximumFee = newMaxFee.mul(10**decimals);

        Params(basisPointsRate, maximumFee);
    }    // Called when new token are issued
    event Issue(uint amount);    // Called when tokens are redeemed
    event Redeem(uint amount);    // Called when contract is deprecated
    event Deprecate(address newAddress);    // Called if contract ever adds fees
    event Params(uint feeBasisPoints, uint maxFee);
}

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
区块链
云链聚未来,协同无边界。腾讯云区块链作为中国领先的区块链服务平台和技术提供商,致力于构建技术、数据、价值、产业互联互通的区块链基础设施,引领区块链底层技术及行业应用创新,助力传统产业转型升级,推动实体经济与数字经济深度融合。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档