contract SantimentWhiteList {

    string constant public VERSION = "0.3.1";

    function () { throw; }   //explicitly unpayable

    struct Limit {
        uint24 min;  //finney
        uint24 max;  //finney
    }

    struct LimitWithAddr {
        address addr;
        uint24 min; //finney
        uint24 max; //finney
    }

    mapping(address=>Limit) public allowed;
    uint16  public chunkNr = 0;
    uint    public recordNum = 0;
    uint256 public controlSum = 0;
    bool public isSetupMode = true;
    address public admin;

    function SantimentWhiteList() { admin = msg.sender; }

    ///@dev add next address package to the internal white list.
    ///@dev call is allowed in setup mode only.
    function addPack(address[] addrs, uint24[] mins, uint24[] maxs, uint16 _chunkNr)
    setupOnly
    adminOnly
    external {
        var len = addrs.length;
        require ( chunkNr++ == _chunkNr);
        require ( mins.length == len &&  mins.length == len );
        for(uint16 i=0; i<len; ++i) {
            var addr = addrs[i];
            var max  = maxs[i];
            var min  = mins[i];
            Limit lim = allowed[addr];
            //remove old record if exists
            if (lim.max > 0) {
                controlSum -= uint160(addr) + lim.min + lim.max;
                delete allowed[addr];
            }
            //insert record if max > 0
            if (max > 0) {
                // max > 0 means add a new record into the list.
                allowed[addr] = Limit({min:min, max:max});
                controlSum += uint160(addr) + min + max;
            }
        }//for
        recordNum+=len;
    }

    ///@notice switch off setup mode
    function start()
    adminOnly
    public {
        isSetupMode = false;
    }

    modifier setupOnly {
        if ( !isSetupMode ) throw;
        _;
    }

    modifier adminOnly {
        if (msg.sender != admin) throw;
        _;
    }

}
/// @author written by ethernian for Santiment Sagl
/// @notice report bugs to: bugs@ethernian.com
/// @title Santiment WhiteList contract
function addPack(address[] addrs, uint24[] mins, uint24[] maxs, uint16 _chunkNr)
setupOnly
adminOnly
external {
    var len = addrs.length;
    require ( chunkNr++ == _chunkNr);
    require ( mins.length == len &&  mins.length == len );
    for(uint16 i=0; i<len; ++i) {
        var addr = addrs[i];
        var max  = maxs[i];
        var min  = mins[i];
        Limit lim = allowed[addr];
        //remove old record if exists
        if (lim.max > 0) {
            controlSum -= uint160(addr) + lim.min + lim.max;
            delete allowed[addr];
        }
        //insert record if max > 0
        if (max > 0) {
            // max > 0 means add a new record into the list.
            allowed[addr] = Limit({min:min, max:max});
            controlSum += uint160(addr) + min + max;
        }
    }//for
    recordNum+=len;
}

///@dev add next address package to the internal white list.
///@dev call is allowed in setup mode only.