Post
Topic
Board Announcements (Altcoins)
Re: [ANN] Token0x - Ethereum 2.0
by
blockstarter784
on 16/07/2018, 19:25:57 UTC
If I understand correctly, once you send the payment you have the option to get a refund. That means you can use services and still ask for refund..or am I missing something?

It is easy to show some examples

Example 1


This is Ethnamed Contract in Standard Ethereum.  Nothing special


pragma solidity ^0.4.21;

contract Ethnamed {
   
   
    struct Name {
        string record;
        address owner;
        uint256 expires;
    }
   
    address issuer = 0xad69f2ffd7d7b3e82605f5fe80acc9152929f283;
   
    function changeIssuer(address _to) public {
       
        require(msg.sender == issuer);
       
        issuer = _to;
       
    }
   
    function withdraw(address _to) public {

        require(msg.sender == issuer);
       
        _to.transfer(address(this).balance);
    }
   
    mapping (string => Name) registry;
   
    function resolve(string _name) public view returns (string) {
        return registry[_name].record;
    }
   
    function version() public pure returns (string) {
        return "v0.001";
    }
   
    function transferOwnership(string _name, address _to) public {
       
        require(registry[_name].owner == msg.sender);
       
        registry[_name].owner = _to;
    }

    function removeExpiredName(string _name) public {
       
        require(registry[_name].expires < now);
       
        delete registry[_name];
   
    }
   
    function stringToUint(string s) pure internal returns (uint result) {
        bytes memory b = bytes(s);
        uint i;
        result = 0;
        for (i = 0; i < b.length; i++) {
            uint c = uint(b);
            if (c >= 48 && c <= 57) {
                result = result * 10 + (c - 48);
            }
        }
    }
   

    function setOrUpdateRecord(
        string length,
        string name,
        string record,
        string blockExpiry,
        address owner,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) public payable {
       
        require(stringToUint(blockExpiry) >= block.number);
       
        uint256 life = msg.value == 0.01  ether ?  48 weeks :
                       msg.value == 0.008 ether ?  24 weeks :
                       msg.value == 0.006 ether ?  12 weeks :
                       msg.value == 0.002 ether ?  4  weeks :
                       0;
                       
        require(life > 0);
       
        require(ecrecover(keccak256("\x19Ethereum Signed Message:\n", length, name, "r=", record, "e=", blockExpiry), v, r, s) == issuer);
        require(registry[name].owner == msg.sender || registry[name].owner == 0x0);
        registry[name].record = record;
        registry[name].owner = owner;
        registry[name].expires = now + life;
   
    }
}

Let's change it for Token0x Blockchian

pragma solidity ^0.4.21;

contract Ethnamed {
   
   
    struct Name {
        string record;
        address owner;
        uint256 expires;
    }
   
    address issuer = 0xad69f2ffd7d7b3e82605f5fe80acc9152929f283;
   
    function changeIssuer(address _to) public {
       
        require(msg.sender == issuer);
       
        issuer = _to;
       
    }
   
    function withdraw(address _to) public {

        require(msg.sender == issuer);
       
        _to.transfer(address(this).balance);
    }
   
    mapping (string => Name) registry;
   
    function resolve(string _name) public view returns (string) {
        return registry[_name].record;
    }
   
    function version() public pure returns (string) {
        return "v0.001";
    }
   
    function transferOwnership(string _name, address _to) public {
       
        require(registry[_name].owner == msg.sender);
       
        registry[_name].owner = _to;
    }

    function removeExpiredName(string _name) public {
       
        require(registry[_name].expires < now);
       
        delete registry[_name];
   
    }
   
    function stringToUint(string s) pure internal returns (uint result) {
        bytes memory b = bytes(s);
        uint i;
        result = 0;
        for (i = 0; i < b.length; i++) {
            uint c = uint(b);
            if (c >= 48 && c <= 57) {
                result = result * 10 + (c - 48);
            }
        }
    }
   
    function refund:setOrUpdateRecord(
        string length,
        string name,
        string record,
        string blockExpiry,
        address owner,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) public {
       
        registry[name].record = "";
        registry[name].owner = 0x;
        registry[name].expires = 0;
   
    }

    function setOrUpdateRecord(
        string length,
        string name,
        string record,
        string blockExpiry,
        address owner,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) public payable {
       
        require(msg.refundPeriod < 2 days);

        require(stringToUint(blockExpiry) >= block.number);
       
        uint256 life = msg.value == 0.01  ether ?  48 weeks :
                       msg.value == 0.008 ether ?  24 weeks :
                       msg.value == 0.006 ether ?  12 weeks :
                       msg.value == 0.002 ether ?  4  weeks :
                       0;
                       
        require(life > 0);
       
        require(ecrecover(keccak256("\x19Ethereum Signed Message:\n", length, name, "r=", record, "e=", blockExpiry), v, r, s) == issuer);
        require(registry[name].owner == msg.sender || registry[name].owner == 0x0);
        registry[name].record = record;
        registry[name].owner = owner;
        registry[name].expires = now + life;
   
    }
}

We allow to set the refundPeriod on 2 days otherwise the transaction is reverted

require(msg.refundPeriod < 2 days);

We added the fund function which will be invoked automatically when the user decides to refund

function refund:setOrUpdateRecord(

The different that in this case, the developer cannot revert the transaction but he can make the refund logic



Example 2

Let's say you participate on ICO on standard Ethereum

function() payable {
        bonus = 0;
        uint256 tokens = exchangeRate(msg.value, bonus);
        Token(tokenAddress).sell(msg.sender, tokens);
    }


Let' see how we can make it in new blockchain


function() payable {
        bonus = 0;

        if(msg.refundPeriod == 0 days) {
            bonus = 100; //award for trust
        }
       
        if(msg.refundPeriod == 1 days) {
            bonus = 50; //award for trust
        }

        if(msg.refundPeriod == 2 days) {
            bonus = 30; //award for trust
        }

        uint256 tokens = exchangeRate(msg.value, bonus);
        Token(tokenAddress).sell(msg.sender, tokens);
    }


Also you can write the refund logic for it

function() refund {
        bonus = 0;

        if(msg.refundPeriod == 0 days) {
            bonus = 100; //award for trust
        }
       
        if(msg.refundPeriod == 1 days) {
            bonus = 50; //award for trust
        }

        if(msg.refundPeriod == 2 days) {
            bonus = 30; //award for trust
        }

        uint256 tokens = exchangeRate(msg.value, bonus);
        //reverted transaction
        Token(msg.sender).sell(tokenAddress, tokens);
    }

I wrote the code only for demo case. I did not check it for possible mistakes