Heling cold solitary self-python Day 125 block chain 039 Ethernet Square erc20 token 09

Heling cold solitary self-python Day 125 block chain 039 Ethernet Square erc20 token 09

【main content】

Erc20 today continue to use the standards to copy the code according to another article Bowen network of intelligent tutorials to annotate a contract can be issued tokens. 36 minutes learning common.

(Also finishing taking notes took about 45 minutes)

Details see the end the process of learning the learning process screen video.

 

[Study notes]

First, today refer to someone else's code, and then add a personal note:

Learning blog address is: https://blog.csdn.net/hantangduhey/article/details/80714656

Today read carefully the source code and add personal notes, felt by nearly twenty days of learning (slightly slower) be able to read these solidity code and complete the annotation:

```

pragma solidity ^ 0.4.24;

 

// original author Bowen address: https: //blog.csdn.net/hantangduhey/article/details/80714656, I quote here only for learning.

 

/**

 * @title SafeMath

 * @dev Math operations with safety checks that throw on error

   Prevent integer overflow issue

 */

library SafeMath {

  function mul(uint256 a, uint256 b) internal pure returns (uint256) {

    uint256 c = a * b;

    assert(a == 0 || c / a == b);

    return c;

  }

 

  function div(uint256 a, uint256 b) internal pure returns (uint256) {

    // assert(b > 0); // Solidity automatically throws when dividing by 0

    uint256 c = a / b;

    // assert(a == b * c + a % b); // There is no case in which this doesn't hold

    return c;

  }

 

  function sub(uint256 a, uint256 b) internal pure returns (uint256) {

    assert(b <= a);

    return a - b;

  }

 

  function add(uint256 a, uint256 b) internal pure returns (uint256) {

    uint256 c = a + b;

    assert(c >= a);

    return c;

  }

}

 

contract StandardToken {

    // use SafeMath

    using SafeMath for uint256;

  

    // token name

    string public name;

    // token abbreviation

    string public symbol;

    // token number of decimal places (tokens can be divided into a number of parts)

    uint8 public  decimals;

    // total number of tokens

    uint256 public totalSupply;

  

    // transaction originator (who call this method, who is the initiator of the transaction) to send _value the number of tokens to _to account

    function transfer(address _to, uint256 _value) public returns (bool success);

    // turn out _value number of tokens from _from account to account _to

    function transferFrom(address _from, address _to, uint256 _value) public returns (bool success);

    // transaction originator _value the right to use the number of tokens to _spender, then _spender transferFrom method before calling the authorized originator account of the money transferred to another person

    function approve(address _spender, uint256 _value) public returns (bool success);

    // query _spender There are still right to use the account number _owner tokens

    function allowance(address _owner, address _spender) public constant returns (uint256 remaining);

    // transfer event successful

    event Transfer(address indexed _from, address indexed _to, uint256 _value);

    // delegate the right to use the success of the event

    event Approval(address indexed _owner, address indexed _spender, uint256 _value);

}

// set the token control administrator contract (that is, the right to declare and initiate a management control agreement with the deployment's)

contract Owned {

 

    // modifier (function modifier), all using some changes in the contract's function should be to make this user right checks, indicate that you must be the owner of the power to do something, administrator of similar meaning

    onlyOwner modify () {

        require(msg.sender == owner);

        _; // do something this dash refers to all subsequent commands

    }

 

    // address of the owner of the power that contract deployer address

    address public owner;

 

    // executed when the contract was created, who enforce the contract is the first owner

    // The following body construction contract is executed only once, when the contract execution deployment, subsequent calls to the contract will not execute the construction of the body, to ensure that the owner of the contract under a permanent record (Deployer) Node address

    constructor() public {

        owner = msg.sender;

    }

    // The new owner, initially empty address, similar to null

    // here seems to be setting a new contract administrator! ?

    address newOwner=0x0;

 

    // replace the successful owner event, the contract administrator to set a successful event broadcast

    event OwnerUpdate(address _prevOwner, address _newOwner);

 

    // The current owner of the ownership to the new owner (needs new owner to call acceptOwnership method to take effect)

    // - This contract was able to change the owner of a smart contract! ! - The new owner needs to agree to, will really be replaced.

    function changeOwner(address _newOwner) public onlyOwner {

        require(_newOwner != owner);

        newOwner = _newOwner; // here after also does not really replace a smart contract owner (controller), the next function is called to perform, then real change.

    }

 

    // The new owner accepts ownership, alternation of power came into effect

    // This function method can only be accepted by that node intelligent new contract owner's identity to call --require (msg.sender == newOwner); restrictions were here

    function acceptOwnership() public{

        require(msg.sender == newOwner);

        emit OwnerUpdate(owner, newOwner);

        owner = newOwner; // then replace the owner really smart contract

        newOwner = 0x0;

    }

}

 

// token control contract

contract Controlled is Owned{

 

    // Creation vip, that is, the node address is first set to deploy contracts vip node, setExclude way is to add a new global variable exlude vip address mapping table.

    // This function is performed only once construction is executed that time when you deploy contracts.

    constructor() public {

       setExclude(msg.sender,true);

    }

 

    // controls whether tokens can be traded, true representatives (exclude in the accounts not limited to this specific implementation in the following transferAllowed years)

    bool public transferEnabled = true;

 

    // whether to enable the account lockout feature, true representatives enabled

    bool lockFlag=true;

    // locked set of accounts, address account, bool whether the lock, true: is locked when lockFlag = true when, congratulations, you can not turn account, ha ha

    mapping(address => bool) locked;

    // privileged user, and lockFlag of unrestricted transferEnabled, vip ah, bool is true representatives vip effective

    mapping (address => bool) exclude; // maps global variables, each address bool value back for years, if the address mapping bool is true, then this address is the identity vip

 

    // set transferEnabled value, this function is called to carry out [whether to allow token transaction global switches], only the current node has a contract to call this function, because function modifier added onlyOwner

    function enableTransfer(bool _enable) public onlyOwner returns (bool success){

        transferEnabled=_enable;

        return true;

    }

 

    // set lockFlag value, this function is called to freeze [whether to lock all global switch for all nodes in the blacklist], only the current node has a contract to call this function, because function modifier added onlyOwner

    function disableLock(bool _enable) public onlyOwner returns (bool success){

        lockFlag=_enable;

        return true;

    }

 

    // _addr added to the account locked, pull the blacklist. . . Add special user node address blacklist, only the current node has a contract to call this function, because function modifier added onlyOwner

    function addLock(address _addr) public onlyOwner returns (bool success){

        require (_addr = msg.sender!); // Avoid adding contract owner node address to the blacklist

        locked[_addr]=true;

        return true;

    }

 

    // set vip user, only the current node has a contract to call this function, because function modifier added onlyOwner

    function setExclude(address _addr,bool _enable) public onlyOwner returns (bool success){

        exclude[_addr]=_enable;

        return true;

    }

 

    // unlock _addr user, the user node is removed from the blacklist, only the current node has a contract to call this function, because function modifier added onlyOwner

    function removeLock(address _addr) public onlyOwner returns (bool success){

        locked[_addr]=false;

        return true;

    }

    // control core contracts to achieve --- This function modifier to ensure global control node whether the user is limited to transactions and accounts are frozen

    modifier transferAllowed(address _addr) {

        // The first line, ensures that all user nodes uncontrolled vip

        if (!exclude[_addr]) {

            // If the global settings prohibit transactions, directly replies: current transaction allowed

            require(transferEnabled,"transfer is not enabeled now!");

            // The next line to check whether the freeze global settings user node blacklist

            if(lockFlag){

                // If the global settings are required to freeze the user node blacklist, it starts to freeze

                require(!locked[_addr],"you are locked!");

            }

        }

        _;

    }

 

}

 

// modify for my own tokens, the original author Bowen address: https: //blog.csdn.net/hantangduhey/article/details/80714656, I quote here only for learning.

contract CloudImageToken is StandardToken,Controlled {

 

    // set of accounts

    mapping (address => uint256) public balanceOf;

    mapping (address => mapping (address => uint256)) internal allowed;

    

    // function construction contracts executed only once, when the contract is executed only deploy --------

    constructor() public {

        totalSupply = 100000000; // 1 million this contract is currently a one-time sum of all currency ordained, no subsequent issuance of coinage function.

        name = "CloudImage Token";

        symbol = "CI";

        decimals = 0;

        balanceOf[msg.sender] = totalSupply;

    }

 

    // node to another contract calls sent tokens, plus a transferAllowed function modifier, accept the global control contract

    function transfer(address _to, uint256 _value) public transferAllowed(msg.sender) returns (bool success) {

        require(_to != address(0));

        require(_value <= balanceOf[msg.sender]);

 

        balanceOf[msg.sender] = balanceOf[msg.sender].sub(_value);

        balanceOf[_to] = balanceOf[_to].add(_value);

        emit Transfer(msg.sender, _to, _value);

        return true;

    }

 

    // send any node to another node tokens, which means that it is authorized to perform the mode, that is to say the contract is calling node has been authorized to send tokens node. Added transferAllowed function modifier, accept the global control contract

    function transferFrom(address _from, address _to, uint256 _value) public transferAllowed(_from) returns (bool success) {

        require(_to != address(0));

        require(_value <= balanceOf[_from]);

        require (_value <= allowed [_from] [msg.sender]); // check the increased here so authorizing the authorization token total effect balance node of the current node transmits the token call contract.

 

        balanceOf[_from] = balanceOf[_from].sub(_value);

        balanceOf[_to] = balanceOf[_to].add(_value);

        allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);

        emit Transfer(_from, _to, _value);

        return true;

    }

 

    // function authorized the operation, this function will not add transferAllowed function modifier. Authorized to operate for all users at all times nodes are available.

    function approve(address _spender, uint256 _value) public returns (bool success) {

        allowed[msg.sender][_spender] = _value;

        emit Approval(msg.sender, _spender, _value);

        return true;

    }

 

    // This static function (using the view qualifier can also be used contant), the balance of the total return for token use. Can query and return with any unauthorized party authorized to accept tokens authorized node on a full case

    function allowance(address _owner, address _spender) public view returns (uint256 remaining) {

      return allowed[_owner][_spender];

    }

 

}

 

 

```

 

[Share] Today's self-perception

Do you believe? Learning ability is upscale!

The lowest grade of learning is basically no self-learning ability, this time can only be forced to learn, as the majority of school learning phase.

The ability to learn is a little low-level self-study can be carried out without the need to actively persecuted external force, then the candidate can deal with some things like assessment.

In grade learning ability is completely independent power of their own to complete the prescribed learning content, such as self-examination to obtain qualifications, can easily participate in professional self-examinations.

High-grade learning ability is independent of the field can choose to learn, and independently determine what to choose textbooks and learning, then you can completely power of their own learning content independently of choice, such as those self-taught, what we call the master is an expert in folk category.

The highest level of self-learning ability is under no circumstances can learn the content, independent exploration and learning new knowledge inherited from their predecessors did not entirely new field, and then the process of the emergence of new inventions, which is the top learning ability, is a master reflect the inventor of independent self-learning capability.

So I think as long as the ability to achieve high-grade learning levels, it be regarded as true learning.

Welcome to discuss

I build [is] the community to learn the original intention is to pursue the same desire and my friends autonomous and independent life, especially the youth there are a lot of trial and error can go to the young people to come together in person to the class of poly the times we were together, communicate with each other, adhere to grow every day, welcome to the community [is] to learn QQ group: 646 854 445

Or visit: www.941xue.com

 

 

[Routine of self-description of the stick]

The last routine explanation, why should I insist on self-study.

 

"If I had not seen the sun, I can live with this dark, but the sun has made me desolate, desolate updated."

- Emily Dickinson

If you want to ask me how to look at his earlier life, I think yesterday and today's answers will be completely different.

Yesterday, I live in desolate satisfaction, conscious peace of mind, took the bag body monthly salary, listening to the kind of command, almost invariably lived a life; sometimes mutual harmony to the people around children, sometimes tongue against preoccupied, show the trivial life, Chuiladanchang work; ecstasy, ecstasy, which can be integrated into the wonders of peace movement, the crushing of marching in step, marking time. At the time I think this is leisurely resignation of ordinary life, that is my fate up.

But one day, I saw a different sun and a different life circumstances under the sun - that's not desolate.

Today, I live in desolate pain, conscious desire to change, marching in step overwhelmed, watching the passage of life, who missed all eyes wide open remorse ... ...

Jiangzai I know I can not go back, I only change is the only right direction.

 

First, why old age is still learning

Give up a lot to go to dinner, go HI songs to play, go to the movies, catch drama ...... time, and then engaged in the learning age, should no longer seems to have been carried out, attracted endless people around puzzled and even contempt poor ......

But I do not want to give up the vow of lifelong learning.

because--

I do not agree with the status quo my life today!

Robert Kiyosaki told us, to reflect on their current life is not what you want, is not that the best motivation and answer?

Gone through most of their lives, and then only to find once, the moment the ongoing life is not what you want, it is a kind of experience?

Only the hearts of sincere feelings in order to answer this question, and then let the rich language is not portrayed.

Half of the trek experience, but found that does not go right, how many people have the courage to admit all the past is wrong?

And I'm willing to tell the past me: "! You're wrong."

So has experienced half a lifetime mistake, big pressure and age of the head, there is hope and a half from the end of the ladder frame and down again, then hobbled to climb another ladder in it?

I prefer to believe that there is hope!

This is why I want to continue to adhere to lifelong learning all the reasons to go on.

 

Second, at this age still learning these techniques do make sense

Pure technology this age are in fact no meaning.

But the interest can go beyond sense.

But technology can lead to changes in thinking, this is the meaning.

Invest in their own minds, their ideas of reform, this is the best preserved, more long-term investment, in the past I have never invested before, miss too much, then invest in their own minds from the start.

Robert Kiyosaki tells us that the really rich are rich time; real freedom is freedom to decide what they are willing to do.

Because I'm willing to do something where my interest, so I hope I have the freedom of choice that day, although that day may still be today from so far away, but I want to believe that more than a day to catch a few steps away from the hope that even taking a step forward.

Furthermore, although I might then have been unable to fully complete master these techniques, but the technology itself is the awakening of the heart may be enlightened, inspired, so as long as we understand that, I believe I will leave that to run away from me the more positive the faster the closer to the next point, and will not be abandoned by the unknown future that too far.

So how can I give up chasing the pace quest?

I want to believe: feeling too late, perhaps not too late.

 

 

[Simultaneous voice notes]

https://www.ximalaya.com/keji/19103006/271995817

 

[Learning] screen recording screen

https://www.bilibili.com/video/av97423188/

 

Guess you like

Origin www.cnblogs.com/lhghroom/p/12547933.html