FINTOCH分趣投系統開發技術詳細及案例原始碼

xiaofufu發表於2023-03-10

  //Send _value amount of tokens from address _from to address _to


  //The transferFrom method is used for a withdraw workflow,allowing contracts to send


  //tokens on your behalf,for example to"deposit"to a contract address and/or to charge


  //fees in sub-currencies;the command should fail unless the _from account has


  //deliberately authorized the sender of the message via some mechanism;we propose


  //these standardized APIs for approval:


  function transferFrom(


  address _from,


  address _to,


  uint256 _amount


  )returns(bool success){詳情及案例:MrsFu123


  require(isSealed());


  //implicitly claim bonus for both sender and receiver


  claimBonus(_from);


  claimBonus(_to);


  //according to VEN's total supply,never overflow here


  if(accounts[_from].balance>=_amount


  &&allowed_from>=_amount


  &&_amount>0){


  accounts[_from].balance-=uint112(_amount);


  allowed_from-=_amount;


  accounts[_to].balance=_amount.add(accounts[_to].balance).toUINT112();


  Transfer(_from,_to,_amount);


  return true;


  }else{


  return false;


  }


  }


  //Allow _spender to withdraw from your account,multiple times,up to the _value amount.


  //If this function is called again it overwrites the current allowance with _value.


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


  allowedmsg.sender=_amount;


  Approval(msg.sender,_spender,_amount);


  return true;


  }


  /Approves and then calls the receiving contract/


  function approveAndCall(address _spender,uint256 _value,bytes _extraData)returns(bool success){


  allowedmsg.sender=_value;


  Approval(msg.sender,_spender,_value);


  //call the receiveApproval function on the contract you want to be notified.This crafts the function signature manually so one doesn't have to include a contract in here just for this.


  //receiveApproval(address _from,uint256 _value,address _tokenContract,bytes _extraData)


  //it is assumed that when does this that the callshouldsucceed,otherwise one would use vanilla approve instead.


  //if(!_spender.call(bytes4(bytes32(sha3("receiveApproval(address,uint256,address,bytes)"))),msg.sender,_value,this,_extraData)){revert();}


  ApprovalReceiver(_spender).receiveApproval(msg.sender,_value,this,_extraData);


  return true;


  }


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


  return allowed_owner;


  }


  //Mint tokens and assign to some one


  function mint(address _owner,uint256 _amount,bool _isRaw,uint32 timestamp)onlyOwner{


  if(_isRaw){


  accounts[_owner].rawTokens=_amount.add(accounts[_owner].rawTokens).toUINT112();


  supplies.rawTokens=_amount.add(supplies.rawTokens).toUINT128();


  }else{


  accounts[_owner].balance=_amount.add(accounts[_owner].balance).toUINT112();


  }


  accounts[_owner].lastMintedTimestamp=timestamp;


  supplies.total=_amount.add(supplies.total).toUINT128();


  Transfer(0,_owner,_amount);


  }


  //Offer bonus to raw tokens holder


  function offerBonus(uint256 _bonus)onlyOwner{


  bonusOffered=bonusOffered.add(_bonus);


  supplies.total=_bonus.add(supplies.total).toUINT128();


  Transfer(0,this,_bonus);


  }


  //Set owner to zero address,to disable mint,and enable token transfer


  function seal()onlyOwner{


  setOwner(0);


  }


  }


  contract ApprovalReceiver{


  function receiveApproval(address _from,uint256 _value,address _tokenContract,bytes _extraData);


  }


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/69956839/viewspace-2939097/,如需轉載,請註明出處,否則將追究法律責任。

相關文章