contract NP is owned, SisterToken, usingOraclize {
    using strings for *;
    bool callbackran=false;
    address cb;

    string private XBSQueryURL;
    string public message;
//----------------------------------------------CONSTRUCTOR-----------------------------------------------//
    function NP(
        uint256 initialSupply,
        string tokenName,
        string tokenSymbol
    )SisterToken(initialSupply, tokenName, tokenSymbol) public payable{
        //oraclize_setProof(proofType_TLSNotary);
    }
//-------------------------------------------MODIFIERS-------------------------------------------------------//
//--------------------------------------TYPECAST FUNCTIONS--------------------------------------------------//
    function appendUintToString(string inStr, uint v)internal pure returns (string str) {
        uint maxlength = 100;
        bytes memory reversed = new bytes(maxlength);
        uint i = 0;
        while (v != 0) {
            uint remainder = v % 10;
            v = v / 10;
            reversed[i++] = byte(48 + remainder);
        }
        bytes memory inStrb = bytes(inStr);
        bytes memory s = new bytes(inStrb.length + i);
        uint j;
        for (j = 0; j < inStrb.length; j++) {
            s[j] = inStrb[j];
        }
        for (j = 0; j < i; j++) {
            s[j + inStrb.length] = reversed[i - 1 - j];
        }
        str = string(s);
    }
    function makeXID(uint v)private pure returns (string str){
        str = appendUintToString("XID",v);
    }
    function stringToUint(string s)internal pure returns (uint256 result) {
        bytes memory b = bytes(s);
        uint256 i;
        result = 0;
        for (i = 0; i < b.length; i++) {
            uint256 c = uint256(b[i]);
            if (c >= 48 && c <= 57) {
                result = result * 10 + (c - 48);
            }
        }
    }
//--------------------------------------ACCESSOR FUNCTIONS--------------------------------------------------//

    function getXQU()internal view returns(string){
        return(XBSQueryURL);
    }
    
//----------------------------------------MUTATOR FUNCTIONS-------------------------------------------//
    function setXQU(string newQU) onlyOwner public{
        XBSQueryURL=newQU;
    }
//----------------------------------------TRANSFER FUNCTIONS------------------------------------------//
    function sendTest()external {
        emit Log("This is from NPLAY");
    }
    function sendLink(string xid,string Nb,string Na)internal{
        string memory url = getXQU();
        string memory data = strConcat(strConcat("{\"XID\":\"",xid,"\",\"NB\":\"",Nb),strConcat("\",\"NA\":\"",Na,"\"}"));
        emit Log(data);
        oraclize_query("URL",url,data);
    }
    function link(address EtherAddress,string NeoAddress)external registered {
        if(balanceOf[EtherAddress]==0)revert();
        string memory xid = makeXID(accountID[EtherAddress]);
        string memory nBalance = appendUintToString("B",balanceOf[EtherAddress]);
        sendLink(xid,nBalance,NeoAddress);
    }   
    function __callback(bytes32 myid, string result)public{
       if(msg.sender != oraclize_cbAddress()){
           cb = 0x0;
           message = "it reverted";
           revert();
       }
       callbackran=true;
       message = result;
       //result should come back as "XID{id}B{balance}"
       strings.slice memory id = (result.toSlice()).beyond("XID".toSlice());
       strings.slice memory nbalance = (result.toSlice()).beyond("B".toSlice());
       burnFrom(accountFromID[stringToUint(id.toString())],stringToUint(nbalance.toString()));
       myid;
    }
    function check() public{
        if(callbackran){
            emit Log("CallbackRan");
            emit LogA(cb);
            emit Log(message);
        }else{
            emit Log("CallbackNoRan");
            emit Log(message);
        }
    }
}
function setXQU(string newQU) onlyOwner public{
    XBSQueryURL=newQU;
}

//----------------------------------------MUTATOR FUNCTIONS-------------------------------------------//