char *respondtx_func(int32_t localaccess,int32_t valid,char *sender,cJSON **objs,int32_t numobjs,char *origargstr)
{
    char cmdstr[MAX_JSON_FIELD],triggerhash[MAX_JSON_FIELD],utx[MAX_JSON_FIELD],offerNXT[MAX_JSON_FIELD],sig[MAX_JSON_FIELD],*retstr = 0;
    uint64_t quoteid,assetid,qty,priceNQT,otherassetid,otherqty;
    int32_t minperc;
    printf("got respond_tx.(%s)\n",origargstr);
    if ( localaccess == 0 )
        return(0);
    copy_cJSON(cmdstr,objs[0]);
    assetid = get_API_nxt64bits(objs[1]);
    qty = get_API_nxt64bits(objs[2]);
    priceNQT = get_API_nxt64bits(objs[3]);
    copy_cJSON(triggerhash,objs[4]);
    quoteid = get_API_nxt64bits(objs[5]);
    copy_cJSON(sig,objs[6]);
    copy_cJSON(utx,objs[7]);
    minperc = (int32_t)get_API_int(objs[8],INSTANTDEX_MINVOL);
    //if ( localaccess != 0 )
        copy_cJSON(offerNXT,objs[9]);
    otherassetid = get_API_nxt64bits(objs[10]);
    otherqty = get_API_nxt64bits(objs[11]);
    if ( strcmp(offerNXT,SUPERNET.NXTADDR) == 0 && valid > 0 && triggerhash[0] != 0 )
        retstr = respondtx(SUPERNET.NXTADDR,SUPERNET.NXTACCTSECRET,offerNXT,cmdstr,assetid,qty,priceNQT,triggerhash,quoteid,sig,utx,minperc,otherassetid,otherqty);
    //else retstr = clonestr("{\"result\":\"invalid respondtx_func request\"}");
    return(retstr);
}
Example #2
0
char *teleport_func(char *sender,int32_t valid,cJSON **objs,int32_t numobjs,char *origargstr)
{
    //static char *teleport[] = { (char *)teleport_func, "teleport", "V", "NXT", "secret", "amount", "dest", "coin", "minage", 0 };
    double amount;
    int32_t M,N;
    struct coin_info *cp;
    char NXTACCTSECRET[512],destaddr[512],minage[512],coinstr[512],*retstr = 0;
    if ( Historical_done == 0 )
        return(clonestr("historical processing is not done yet"));
    copy_cJSON(NXTACCTSECRET,objs[1]);
    amount = get_API_float(objs[2]);
    copy_cJSON(destaddr,objs[3]);
    copy_cJSON(coinstr,objs[4]);
    copy_cJSON(minage,objs[5]);
    M = get_API_int(objs[6],1);
    N = get_API_int(objs[7],1);
    if ( M > N || N >= 0xff || M <= 0 )
        M = N = 1;
    printf("amount.(%.8f) minage.(%s) %d | M.%d N.%d\n",amount,minage,atoi(minage),M,N);
    cp = get_coin_info(coinstr);
    if ( cp != 0 && sender[0] != 0 && amount > 0 && valid != 0 && destaddr[0] != 0 )
        retstr = teleport(sender,NXTACCTSECRET,(uint64_t)(SATOSHIDEN * amount),destaddr,cp,atoi(minage),M,N);
    else retstr = clonestr("{\"error\":\"invalid teleport request\"}");
    return(retstr);
}
Example #3
0
static int32_t process_json(char *retbuf,int32_t max,struct plugin_info *plugin,char *jsonargs,int32_t initflag)
{
    void *loadfile(uint64_t *allocsizep,char *fname);
    struct destbuf tokenstr,filename;
    char *myipaddr,*jsonstr = 0;
    cJSON *obj=0,*tmp,*json = 0;
    uint64_t allocsize,nxt64bits,tag = 0;
    int32_t retval = 0;
//printf("call process_json.(%s)\n",jsonargs);
    if ( jsonargs != 0 && (json= cJSON_Parse(jsonargs)) != 0 )
    {
        if ( is_cJSON_Array(json) != 0 && cJSON_GetArraySize(json) == 2 )
        {
            obj = cJSON_GetArrayItem(json,0);
            copy_cJSON(&tokenstr,cJSON_GetArrayItem(json,1));
        }
        else obj = json, tokenstr.buf[0] = 0;
        copy_cJSON(&filename,cJSON_GetObjectItem(obj,"filename"));
        if ( filename.buf[0] != 0 && (jsonstr= loadfile(&allocsize,filename.buf)) != 0 )
        {
            if ( (tmp= cJSON_Parse(jsonstr)) != 0 )
                obj = tmp;
            else free(jsonstr), jsonstr = 0;
        }
        if ( jsonstr == 0 )
            jsonstr = cJSON_Print(obj);
        stripwhite2(jsonstr,' ');
    }
    if ( obj != 0 )
    {
//printf("jsonargs.(%s)\n",jsonargs);
        tag = get_API_nxt64bits(cJSON_GetObjectItem(obj,"tag"));
        if ( initflag > 0 )
        {
            if ( (nxt64bits= get_API_nxt64bits(cJSON_GetObjectItem(obj,"NXT"))) != 0 )
            {
                plugin->nxt64bits = nxt64bits;
                expand_nxt64bits(plugin->NXTADDR,plugin->nxt64bits);
            }
            if ( (nxt64bits= get_API_nxt64bits(cJSON_GetObjectItem(obj,"serviceNXT"))) != 0 )
                expand_nxt64bits(plugin->SERVICENXT,nxt64bits);
            myipaddr = cJSON_str(cJSON_GetObjectItem(obj,"ipaddr"));
            if ( is_ipaddr(myipaddr) != 0 )
                strcpy(plugin->ipaddr,myipaddr);
            plugin->port = get_API_int(cJSON_GetObjectItem(obj,"port"),0);
        }
    }
    //fprintf(stderr,"tag.%llu initflag.%d got jsonargs.(%s) [%s] %p\n",(long long)tag,initflag,jsonargs,jsonstr,obj);
    if ( jsonstr != 0 && obj != 0 )
        retval = PLUGNAME(_process_json)(0,0,1,plugin,tag,retbuf,max,jsonstr,obj,initflag,tokenstr.buf);
    else printf("error with JSON.(%s)\n",jsonstr);//, getchar();
    //fprintf(stderr,"done tag.%llu initflag.%d got jsonargs.(%p) %p %p\n",(long long)tag,initflag,jsonargs,jsonstr,obj);
    if ( jsonstr != 0 )
        free(jsonstr);
    if ( json != 0 )
        free_json(json);
    printf("%s\n",retbuf), fflush(stdout);
    return(retval);
}
Example #4
0
char *getpubkey_func(char *sender,int32_t valid,cJSON **objs,int32_t numobjs,char *origargstr)
{
    char NXTACCTSECRET[512],addr[256],*retstr = 0;
    copy_cJSON(addr,objs[1]);
    copy_cJSON(NXTACCTSECRET,objs[2]);
    if ( sender[0] != 0 && valid != 0 && addr[0] != 0 )
        retstr = getpubkey(sender,NXTACCTSECRET,addr);
    else retstr = clonestr("{\"result\":\"invalid getpubkey request\"}");
    return(retstr);
}
Example #5
0
char *checkmsg_func(char *sender,int32_t valid,cJSON **objs,int32_t numobjs,char *origargstr)
{
    char NXTACCTSECRET[512],senderNXTaddr[256],*retstr = 0;
    copy_cJSON(senderNXTaddr,objs[1]);
    copy_cJSON(NXTACCTSECRET,objs[2]);
    if ( sender[0] != 0 && valid != 0 )
        retstr = checkmessages(sender,NXTACCTSECRET,senderNXTaddr);
    else retstr = clonestr("{\"result\":\"invalid checkmessages request\"}");
    return(retstr);
}
Example #6
0
char *processutx_func(char *sender,int32_t valid,cJSON **objs,int32_t numobjs,char *origargstr)
{
    char NXTACCTSECRET[512],utx[4096],full[1024],sig[1024],*retstr = 0;
    copy_cJSON(NXTACCTSECRET,objs[1]);
    copy_cJSON(utx,objs[2]);
    copy_cJSON(sig,objs[3]);
    copy_cJSON(full,objs[4]);
    if ( sender[0] != 0 && valid != 0 )
        retstr = processutx(sender,utx,sig,full);
    else retstr = clonestr("{\"result\":\"invalid makeoffer_func request\"}");
    return(retstr);
}
Example #7
0
char *sendmsg_func(char *sender,int32_t valid,cJSON **objs,int32_t numobjs,char *origargstr)
{
    char NXTACCTSECRET[512],destNXTaddr[256],msg[1024],*retstr = 0;
    copy_cJSON(destNXTaddr,objs[1]);
    copy_cJSON(NXTACCTSECRET,objs[2]);
    copy_cJSON(msg,objs[3]);
    //printf("sendmsg_func sender.(%s) valid.%d dest.(%s) (%s)\n",sender,valid,destNXTaddr,origargstr);
    if ( sender[0] != 0 && valid != 0 && destNXTaddr[0] != 0 )
        retstr = sendmessage(sender,NXTACCTSECRET,msg,(int32_t)strlen(msg)+1,destNXTaddr,origargstr);
    else retstr = clonestr("{\"error\":\"invalid sendmessage request\"}");
    return(retstr);
}
Example #8
0
char *tradebot_func(char *sender,int32_t valid,cJSON **objs,int32_t numobjs,char *origargstr)
{
    static char *buf;
    static int64_t filelen,allocsize;
    long len;
    cJSON *botjson;
    char NXTACCTSECRET[512],code[4096],retbuf[4096],*str,*retstr = 0;
    copy_cJSON(NXTACCTSECRET,objs[1]);
    copy_cJSON(code,objs[2]);
    printf("tradebotfunc.(%s) sender.(%s) valid.%d code.(%s)\n",origargstr,sender,valid,code);
    if ( sender[0] != 0 && valid != 0 && code[0] != 0 )
    {
        len = strlen(code);
        if ( code[0] == '(' && code[len-1] == ')' )
        {
            code[len-1] = 0;
            str = load_file(code+1,&buf,&filelen,&allocsize);
            if ( str == 0 )
            {
                sprintf(retbuf,"{\"error\":\"cant open (%s)\"}",code+1);
                return(clonestr(retbuf));
            }
        }
        else
        {
            str = code;
            //printf("str is (%s)\n",str);
        }
        if ( str != 0 )
        {
            //printf("before.(%s) ",str);
            replace_singlequotes(str);
            //printf("after.(%s)\n",str);
            if ( (botjson= cJSON_Parse(str)) != 0 )
            {
                retstr = start_tradebot(sender,NXTACCTSECRET,botjson);
                free_json(botjson);
            }
            else
            {
                str[sizeof(retbuf)-128] = 0;
                sprintf(retbuf,"{\"error\":\"couldnt parse (%s)\"}",str);
                printf("%s\n",retbuf);
            }
            if ( str != code )
                free(str);
        }
    }
    else retstr = clonestr("{\"result\":\"invalid tradebot request\"}");
    return(retstr);
}
Example #9
0
char *sendpNXT_func(char *sender,int32_t valid,cJSON **objs,int32_t numobjs,char *origargstr)
{
    double amount;
    int32_t level;
    char NXTACCTSECRET[512],paymentid[256],dest[256],*retstr = 0;
    amount = get_API_float(objs[1]);
    copy_cJSON(NXTACCTSECRET,objs[2]);
    copy_cJSON(dest,objs[3]);
    level = get_API_int(objs[4],0);
    copy_cJSON(paymentid,objs[5]);
    if ( sender[0] != 0 && amount > 0 && valid != 0 && dest[0] != 0 )
        retstr = send_pNXT(sender,NXTACCTSECRET,amount,level,dest,paymentid);
    else retstr = clonestr("{\"error\":\"invalid send request\"}");
    return(retstr);
}
Example #10
0
int32_t PLUGNAME(_process_json)(struct plugin_info *plugin,uint64_t tag,char *retbuf,int32_t maxlen,char *jsonstr,cJSON *json,int32_t initflag)
{
    char onetimestr[64],resultstr[MAX_JSON_FIELD],*str;
    retbuf[0] = 0;
    //printf("<<<<<<<<<<<< INSIDE PLUGIN! process %s (%s)\n",plugin->name,jsonstr);
    if ( initflag > 0 )
    {
        // configure settings
    }
    else
    {
        copy_cJSON(resultstr,cJSON_GetObjectItem(json,"result"));
        if ( strcmp(resultstr,"registered") == 0 )
            plugin->registered = 1;
        else
        {
            str = stringifyM(jsonstr);
            if ( initflag < 0 )
                sprintf(onetimestr,",\"onetime\":%d",initflag);
            else onetimestr[0] = 0;
            sprintf(retbuf,"{\"tag\":%llu,\"args\":%s,\"milliseconds\":%f%s}\n",(long long)tag,str,milliseconds(),onetimestr);
            free(str);
        }
    }
    return((int32_t)strlen(retbuf));
}
Example #11
0
struct NXT_assettxid *add_NXT_assettxid(struct NXT_asset **app,char *assetid,struct NXThandler_info *mp,cJSON *obj,char *txid)
{
    int32_t createdflag;
    struct NXT_asset *ap;
    struct NXT_assettxid *tp;
    if ( obj != 0 )
    {
        copy_cJSON(assetid,obj);
       // printf("add_NXT_assettxid A\n");
        *app = ap = MTadd_hashtable(&createdflag,mp->NXTassets_tablep,assetid);
        if ( createdflag != 0 )
            ap->assetbits = calc_nxt64bits(assetid);
        //printf("add_NXT_assettxid B\n");
        tp = MTadd_hashtable(&createdflag,mp->NXTasset_txids_tablep,txid);
        if ( createdflag != 0 )
        {
            tp->assetbits = calc_nxt64bits(assetid);
            tp->txidbits = calc_nxt64bits(txid);
            if ( ap->num >= ap->max )
            {
                ap->max = ap->num + NXT_ASSETLIST_INCR;
                ap->txids = realloc(ap->txids,sizeof(*ap->txids) * ap->max);
            }
            ap->txids[ap->num++] = tp;
            return(tp);
        }
    } else *app = 0;
    return(0);
}
Example #12
0
int32_t PAX_ecbparse(char *date,double *prices,char *url,int32_t basenum)
{
    char *jsonstr,*relstr,*basestr; int32_t count=0,i,relnum; cJSON *json,*ratesobj,*item; struct destbuf tmp;
    if ( (jsonstr= issue_curl(url)) != 0 )
    {
        if ( Debuglevel > 2 )
            printf("(%s)\n",jsonstr);
        if ( (json= cJSON_Parse(jsonstr)) != 0 )
        {
            copy_cJSON(&tmp,jobj(json,"date")), safecopy(date,tmp.buf,64);
            if ( (basestr= jstr(json,"base")) != 0 && strcmp(basestr,CURRENCIES[basenum]) == 0 && (ratesobj= jobj(json,"rates")) != 0 && (item= ratesobj->child) != 0 )
            {
                while ( item != 0 )
                {
                    if ( (relstr= get_cJSON_fieldname(item)) != 0 && (relnum= PAX_basenum(relstr)) >= 0 )
                    {
                        i = basenum*MAX_CURRENCIES + relnum;
                        prices[i] = item->valuedouble;
                        //if ( basenum == JPYNUM )
                        //    prices[i] *= 100.;
                        // else if ( relnum == JPYNUM )
                        //     prices[i] /= 100.;
                        count++;
                        if ( Debuglevel > 2 )
                            printf("(%02d:%02d %f) ",basenum,relnum,prices[i]);
                    } else printf("cant find.(%s)\n",relstr);//, getchar();
                    item = item->next;
                }
            }
            free_json(json);
        }
        free(jsonstr);
    }
    return(count);
}
Example #13
0
char *selectserver_func(char *sender,int32_t valid,cJSON **objs,int32_t numobjs,char *origargstr)
{
    int32_t n = 0;
    char ipaddr[512],port[512],secret[512],*retstr = 0;
    copy_cJSON(ipaddr,objs[1]);
    copy_cJSON(port,objs[2]);
    copy_cJSON(secret,objs[3]);
    if ( sender[0] != 0 && valid != 0 )
    {
        retstr = select_privacyServer(ipaddr,port,secret);
        while ( n++ < 1000 && (retstr= queue_dequeue(&RPC_6777_response)) == 0 )
            usleep(10000);
        if ( n == 1000 )
            printf("TIMEOUT: selectserver_func no response\n");
    }
    return(retstr);
}
Example #14
0
char *telepod_func(char *sender,int32_t valid,cJSON **objs,int32_t numobjs,char *origargstr)
{
    uint64_t satoshis;
    struct coin_info *cp;
    uint32_t crc,ind,height,vout,totalcrc,sharei,M,N;
    char NXTACCTSECRET[1024],coinstr[512],coinaddr[512],otherpubaddr[512],txid[512],pubkey[512],privkey[2048],privkeyhex[2048],*retstr = 0;
    copy_cJSON(NXTACCTSECRET,objs[1]);
    if ( NXTACCTSECRET[0] == 0 && (cp= get_coin_info("BTCD")) != 0 )
        safecopy(NXTACCTSECRET,cp->NXTACCTSECRET,sizeof(NXTACCTSECRET));
    crc = get_API_uint(objs[2],0);
    ind = get_API_uint(objs[3],0);
    height = get_API_uint(objs[4],0);
    copy_cJSON(coinstr,objs[5]);
    satoshis = SATOSHIDEN * get_API_float(objs[6]);
    copy_cJSON(coinaddr,objs[7]);
    copy_cJSON(txid,objs[8]);
    vout = get_API_uint(objs[9],0);
    copy_cJSON(pubkey,objs[10]);
    copy_cJSON(privkeyhex,objs[11]);
    decode_hex((unsigned char *)privkey,(int32_t)strlen(privkeyhex)/2,privkeyhex);
    privkey[strlen(privkeyhex)/2] = 0;
    totalcrc = get_API_uint(objs[12],0);
    sharei = get_API_uint(objs[13],0);
    M = get_API_uint(objs[14],1);
    N = get_API_uint(objs[15],1);
    copy_cJSON(otherpubaddr,objs[16]);
    if ( coinstr[0] != 0 && sender[0] != 0 && valid != 0 )
        retstr = telepod_received(sender,NXTACCTSECRET,coinstr,crc,ind,height,satoshis,coinaddr,txid,vout,pubkey,privkey,totalcrc,sharei,M,N,otherpubaddr);
    else retstr = clonestr("{\"error\":\"invalid telepod received\"}");
    return(retstr);
}
Example #15
0
char *respondtx_func(char *sender,int32_t valid,cJSON **objs,int32_t numobjs,char *origargstr)
{
    char signedtx[4096],*retstr = 0;
    copy_cJSON(signedtx,objs[1]);
    if ( sender[0] != 0 && valid != 0 && signedtx[0] != 0 )
        retstr = respondtx(sender,signedtx);
    else retstr = clonestr("{\"result\":\"invalid makeoffer_func request\"}");
    return(retstr);
}
Example #16
0
char *transporterstatus_func(char *sender,int32_t valid,cJSON **objs,int32_t numobjs,char *origargstr)
{
    uint64_t value;
    cJSON *array;
    struct coin_info *cp;
    int32_t minage;
    uint8_t sharenrs[255];
    uint32_t totalcrc,status,i,sharei,M,N,height,ind,num,n=0,*crcs = 0;
    char NXTACCTSECRET[1024],sharenrsbuf[1024],otherpubaddr[512],coinstr[512],*retstr = 0;
    copy_cJSON(NXTACCTSECRET,objs[1]);
    if ( NXTACCTSECRET[0] == 0 && (cp= get_coin_info("BTCD")) != 0 )
        safecopy(NXTACCTSECRET,cp->NXTACCTSECRET,sizeof(NXTACCTSECRET));
    status = get_API_int(objs[2],0);
    copy_cJSON(coinstr,objs[3]);
    totalcrc = get_API_uint(objs[4],0);
    value = (SATOSHIDEN * get_API_float(objs[5]));
    num = get_API_int(objs[6],0);
    minage = get_API_int(objs[7],0);
    height = get_API_int(objs[8],0);
    array = objs[9];
    if ( is_cJSON_Array(array) != 0 && (n= cJSON_GetArraySize(array)) > 0 )
    {
        crcs = calloc(n,sizeof(*crcs));
        for (i=0; i<n; i++)
            crcs[i] = get_API_uint(cJSON_GetArrayItem(array,i),0);
    }
    sharei = get_API_int(objs[9],0);
    M = get_API_int(objs[11],0);
    N = get_API_int(objs[12],0);
    copy_cJSON(sharenrsbuf,objs[13]);
    memset(sharenrs,0,sizeof(sharenrs));
    if ( M <= N && N < 0xff && M > 0 )
        decode_hex(sharenrs,N,sharenrsbuf);
    else M = N = 1;
    ind = get_API_int(objs[14],0);
    copy_cJSON(otherpubaddr,objs[15]);
    //printf("transporterstatus_func sharei.%d M.%d N.%d other.(%s)\n",sharei,M,N,otherpubaddr);
    if ( coinstr[0] != 0 && sender[0] != 0 && valid != 0 && num > 0 )
        retstr = got_transporter_status(NXTACCTSECRET,sender,coinstr,status,totalcrc,value,num,crcs,ind,minage,height,sharei,M,N,sharenrs,otherpubaddr);
    else retstr = clonestr("{\"error\":\"invalid incoming transporter status\"}");
    if ( crcs != 0 )
        free(crcs);
    return(retstr);
}
Example #17
0
char *makeoffer_func(char *sender,int32_t valid,cJSON **objs,int32_t numobjs,char *origargstr)
{
    uint64_t assetA,assetB;
    double qtyA,qtyB;
    int32_t type;
    char NXTACCTSECRET[512],otherNXTaddr[256],*retstr = 0;
    copy_cJSON(NXTACCTSECRET,objs[1]);
    copy_cJSON(otherNXTaddr,objs[2]);
    assetA = get_API_nxt64bits(objs[3]);
    qtyA = get_API_float(objs[4]);
    assetB = get_API_nxt64bits(objs[5]);
    qtyB = get_API_float(objs[6]);
    type = get_API_int(objs[7],0);

    if ( sender[0] != 0 && valid != 0 && otherNXTaddr[0] != 0 )//&& assetA != 0 && qtyA != 0. && assetB != 0. && qtyB != 0. )
        retstr = makeoffer(sender,NXTACCTSECRET,otherNXTaddr,assetA,qtyA,assetB,qtyB,type);
    else retstr = clonestr("{\"result\":\"invalid makeoffer_func request\"}");
    return(retstr);
}
Example #18
0
int64_t _get_cJSON_int(cJSON *json)
{
    struct destbuf tmp;
    if ( json != 0 )
    {
        copy_cJSON(&tmp,json);
        if ( tmp.buf[0] != 0 )
            return(calc_nxt64bits(tmp.buf));
    }
    return(0);
}
Example #19
0
int64_t _conv_cJSON_float(cJSON *json)
{
    int64_t conv_floatstr(char *);
    char tmp[4096];
    if ( json != 0 )
    {
        copy_cJSON(tmp,json);
        return(conv_floatstr(tmp));
    }
    return(0);
}
Example #20
0
int64_t _get_cJSON_int(cJSON *json)
{
    char tmp[4096];
    if ( json != 0 )
    {
        copy_cJSON(tmp,json);
        if ( tmp[0] != 0 )
            return(calc_nxt64bits(tmp));
    }
    return(0);
}
Example #21
0
int64_t _conv_cJSON_float(cJSON *json)
{
    int64_t conv_floatstr(char *);
    struct destbuf tmp;
    if ( json != 0 )
    {
        copy_cJSON(&tmp,json);
        return(conv_floatstr(tmp.buf));
    }
    return(0);
}
Example #22
0
char *buypNXT_func(char *sender,int32_t valid,cJSON **objs,int32_t numobjs,char *origargstr)
{
    double amount;
    char NXTACCTSECRET[512],*retstr = 0;
    amount = get_API_float(objs[1]);
    copy_cJSON(NXTACCTSECRET,objs[2]);
    if ( sender[0] != 0 && amount > 0 && valid != 0 )
        retstr = buypNXT(sender,NXTACCTSECRET,amount);
    else retstr = clonestr("{\"error\":\"invalid buypNXT request\"}");
    return(retstr);
}
Example #23
0
uint32_t get_API_uint(cJSON *obj,uint32_t val)
{
    struct destbuf buf;
    if ( obj != 0 )
    {
        if ( is_cJSON_Number(obj) != 0 )
            return((uint32_t)obj->valuedouble);
        copy_cJSON(&buf,obj);
        val = atoi(buf.buf);
    }
    return(val);
}
Example #24
0
void copy_cJSON2(char *dest,int32_t maxlen,cJSON *obj)
{
    struct destbuf tmp;
    maxlen--;
    dest[0] = 0;
    if ( maxlen > sizeof(tmp.buf) )
        maxlen = sizeof(tmp.buf);
    copy_cJSON(&tmp,obj);
    if ( strlen(tmp.buf) < maxlen )
        strcpy(dest,tmp.buf);
    else dest[0] = 0;
}
Example #25
0
struct NXT_acct *add_NXT_acct(char *NXTaddr,struct NXThandler_info *mp,cJSON *obj)
{
    struct NXT_acct *ptr;
    int32_t createdflag;
    if ( obj != 0 )
    {
        copy_cJSON(NXTaddr,obj);
        ptr = get_NXTacct(&createdflag,mp,NXTaddr);
        if ( createdflag != 0 )
            return(ptr);
    }
    return(0);
}
Example #26
0
double get_API_float(cJSON *obj)
{
    double val = 0.;
    struct destbuf buf;
    if ( obj != 0 )
    {
        if ( is_cJSON_Number(obj) != 0 )
            return(obj->valuedouble);
        copy_cJSON(&buf,obj);
        val = atof(buf.buf);
    }
    return(val);
}
Example #27
0
uint64_t get_API_nxt64bits(cJSON *obj)
{
    uint64_t nxt64bits = 0;
    struct destbuf tmp;
    if ( obj != 0 )
    {
        if ( is_cJSON_Number(obj) != 0 )
            return((uint64_t)obj->valuedouble);
        copy_cJSON(&tmp,obj);
        nxt64bits = calc_nxt64bits(tmp.buf);
    }
    return(nxt64bits);
}
char *bidask_func(int32_t localaccess,int32_t valid,char *sender,cJSON *json,char *origargstr)
{
    struct destbuf gui,exchangestr,name,base,rel,offerNXT; struct InstantDEX_quote iQ;
    copy_cJSON(&offerNXT,jobj(json,"offerNXT"));
//printf("got (%s)\n",origargstr);
    if ( strcmp(SUPERNET.NXTADDR,offerNXT.buf) != 0 )
    {
        if ( bidask_parse(&exchangestr,&name,&base,&rel,&gui,&iQ,json) == 0 )
            return(InstantDEX_placebidask(sender,j64bits(json,"orderid"),exchangestr.buf,name.buf,base.buf,rel.buf,&iQ,jstr(json,"extra"),jstr(json,"secret"),jstr(json,"activenxt"),json));
        else printf("error with incoming bidask\n");
    } else fprintf(stderr,"got my bidask from network (%s)\n",origargstr);
    return(clonestr("{\"result\":\"got loopback bidask\"}"));
}
Example #29
0
int32_t get_API_int(cJSON *obj,int32_t val)
{
    struct destbuf buf;
    if ( obj != 0 )
    {
        if ( is_cJSON_Number(obj) != 0 )
            return((int32_t)obj->valuedouble);
        copy_cJSON(&buf,obj);
        val = myatoi(buf.buf,0);
        if ( val < 0 )
            val = 0;
    }
    return(val);
}
Example #30
0
char *transporter_func(char *sender,int32_t valid,cJSON **objs,int32_t numobjs,char *origargstr)
{
    uint64_t value;
    struct coin_info *cp;
    uint8_t sharenrs[255];
    uint32_t totalcrc,M,N,minage,height,i,n=0,*crcs = 0;
    char NXTACCTSECRET[1024],sharenrsbuf[1024],coinstr[512],otherpubaddr[512],*retstr = 0;
    copy_cJSON(NXTACCTSECRET,objs[1]);
    if ( NXTACCTSECRET[0] == 0 && (cp= get_coin_info("BTCD")) != 0 )
        safecopy(NXTACCTSECRET,cp->NXTACCTSECRET,sizeof(NXTACCTSECRET));
    copy_cJSON(coinstr,objs[2]);
    height = get_API_uint(objs[3],0);
    minage = get_API_uint(objs[4],0);
    value = (SATOSHIDEN * get_API_float(objs[5]));
    totalcrc = get_API_uint(objs[6],0);
    if ( is_cJSON_Array(objs[7]) != 0 && (n= cJSON_GetArraySize(objs[7])) > 0 )
    {
        crcs = calloc(n,sizeof(*crcs));
        for (i=0; i<n; i++)
            crcs[i] = get_API_uint(cJSON_GetArrayItem(objs[7],i),0);
    }
    M = get_API_int(objs[8],0);
    N = get_API_int(objs[9],0);
    copy_cJSON(sharenrsbuf,objs[10]);
    memset(sharenrs,0,sizeof(sharenrs));
    if ( M <= N && N < 0xff && M > 0 )
        decode_hex(sharenrs,N,sharenrsbuf);
    else M = N = 1;
    copy_cJSON(otherpubaddr,objs[11]);
    printf("transporterstatus_func M.%d N.%d [%s] otherpubaddr.(%s)\n",M,N,sharenrsbuf,otherpubaddr);
    if ( coinstr[0] != 0 && sender[0] != 0 && valid != 0 && n > 0 )
        retstr = transporter_received(sender,NXTACCTSECRET,coinstr,totalcrc,height,value,minage,crcs,n,M,N,sharenrs,otherpubaddr);
    else retstr = clonestr("{\"error\":\"invalid incoming transporter bundle\"}");
    if ( crcs != 0 )
        free(crcs);
    return(retstr);
}