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

2023-03-03 14:49:13 浏览数 (1)

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

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

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);
}

0 人点赞