Exemplo n.º 1
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);
}
Exemplo n.º 2
0
char *orderbook_func(char *sender,int32_t valid,cJSON **objs,int32_t numobjs,char *origargstr)
{
    int32_t i,polarity,allflag;
    uint64_t obookid;
    cJSON *json,*bids,*asks,*item;
    struct orderbook *op;
    char obook[512],buf[512],assetA[64],assetB[64],*retstr = 0;
    obookid = get_API_nxt64bits(objs[1]);
    expand_nxt64bits(obook,obookid);
    polarity = get_API_int(objs[2],1);
    if ( polarity == 0 )
        polarity = 1;
    allflag = get_API_int(objs[3],0);
    if ( obookid != 0 && (op= create_orderbook(obookid,polarity,0,0)) != 0 )
    {
        if ( op->numbids == 0 && op->numasks == 0 )
            retstr = clonestr("{\"error\":\"no bids or asks\"}");
        else
        {
            json = cJSON_CreateObject();
            bids = cJSON_CreateArray();
            for (i=0; i<op->numbids; i++)
            {
                item = create_order_json(&op->bids[i],1,allflag);
                cJSON_AddItemToArray(bids,item);
            }
            asks = cJSON_CreateArray();
            for (i=0; i<op->numasks; i++)
            {
                item = create_order_json(&op->asks[i],1,allflag);
                cJSON_AddItemToArray(asks,item);
            }
            expand_nxt64bits(assetA,op->assetA);
            expand_nxt64bits(assetB,op->assetB);
            cJSON_AddItemToObject(json,"orderbook",cJSON_CreateString(obook));
            cJSON_AddItemToObject(json,"assetA",cJSON_CreateString(assetA));
            cJSON_AddItemToObject(json,"assetB",cJSON_CreateString(assetB));
            cJSON_AddItemToObject(json,"polarity",cJSON_CreateNumber(polarity));
            cJSON_AddItemToObject(json,"bids",bids);
            cJSON_AddItemToObject(json,"asks",asks);
            retstr = cJSON_Print(json);
        }
        free_orderbook(op);
    } else
    {
        sprintf(buf,"{\"error\":\"no such orderbook.(%llu)\"}",(long long)obookid);
        retstr = clonestr(buf);
    }
    return(retstr);
}
Exemplo n.º 3
0
void transfer_asset_balance(struct NXThandler_info *mp,struct NXT_assettxid *tp,uint64_t assetbits,char *sender,char *receiver,int64_t quantity)
{
    int32_t createdflag,srcind,destind;
    struct NXT_acct *src,*dest;
    struct NXT_asset *ap;
    char assetid[MAX_NXTADDR_LEN];
    if ( sender == 0 || sender[0] == 0 || receiver == 0 || receiver[0] == 0 )
    {
        printf("illegal transfer asset (%s -> %s)\n",sender,receiver);
        return;
    }
    expand_nxt64bits(assetid,assetbits);
    //printf("transfer_asset_balance\n");
    ap = MTadd_hashtable(&createdflag,mp->NXTassets_tablep,assetid);
    if ( createdflag != 0 )
        printf("transfer_asset_balance: unexpected hashtable creation??\n");
    src = get_NXTacct(&createdflag,mp,sender);
    srcind = get_asset_in_acct(src,ap,1);
    dest = get_NXTacct(&createdflag,mp,receiver);
    destind = get_asset_in_acct(dest,ap,1);
    if ( srcind >= 0 && destind >= 0 )
    {
        src->quantities[srcind] -= quantity;
        addto_account_txlist(src,srcind,tp);
        dest->quantities[destind] += quantity;
        addto_account_txlist(dest,destind,tp);
    } else printf("error finding inds for assetid.%s %s.%d %s.%d\n",assetid,sender,srcind,receiver,destind);
}
Exemplo n.º 4
0
char *placequote_func(int32_t dir,char *sender,int32_t valid,cJSON **objs,int32_t numobjs,char *origargstr)
{
    int32_t polarity;
    uint64_t obookid,nxt64bits,assetA,assetB,txid;
    double price,volume;
    struct orderbook_tx tx;
    char buf[1024],txidstr[512],*retstr = 0;
    nxt64bits = calc_nxt64bits(sender);
    obookid = get_API_nxt64bits(objs[1]);
    polarity = get_API_int(objs[2],1);
    if ( polarity == 0 )
        polarity = 1;
    volume = get_API_float(objs[3]);
    price = get_API_float(objs[4]);
    assetA = get_API_nxt64bits(objs[5]);
    assetB = get_API_nxt64bits(objs[6]);
    printf("PLACE QUOTE polarity.%d dir.%d\n",polarity,dir);
    if ( sender[0] != 0 && find_raw_orders(obookid) != 0 && valid != 0 )
    {
        if ( price != 0. && volume != 0. && dir != 0 )
        {
            if ( dir*polarity > 0 )
                bid_orderbook_tx(&tx,0,nxt64bits,obookid,price,volume);
            else ask_orderbook_tx(&tx,0,nxt64bits,obookid,price,volume);
            txid = pNXT_submit_tx(Global_pNXT->core,Global_pNXT->wallet,(unsigned char *)&tx,sizeof(tx));
            if ( txid != 0 )
            {
                expand_nxt64bits(txidstr,txid);
                sprintf(buf,"{\"txid\":\"%s\"}",txidstr);
                retstr = clonestr(buf);
            }
        }
        if ( retstr == 0 )
        {
            sprintf(buf,"{\"error submitting\":\"place%s error obookid.%llx polarity.%d volume %f price %f\"}",dir>0?"bid":"ask",(long long)obookid,polarity,volume,price);
            retstr = clonestr(buf);
        }
    }
    else if ( assetA != 0 && assetB != 0 && assetA != assetB )
    {
        if ( (obookid= create_raw_orders(assetA,assetB)) != 0 )
        {
            sprintf(buf,"{\"obookid\":\"%llu\"}",(long long)obookid);
            retstr = clonestr(buf);
        }
        else
        {
            sprintf(buf,"{\"error\":\"couldnt create orderbook for assets %llu and %llu\"}",(long long)assetA,(long long)assetB);
            retstr = clonestr(buf);
        }
    }
    else
    {
        sprintf(buf,"{\"error\":\"place%s error obookid.%llx polarity.%d volume %f price %f\"}",polarity>0?"bid":"ask",(long long)obookid,polarity,volume,price);
        retstr = clonestr(buf);
    }
    return(retstr);
}
Exemplo n.º 5
0
char *_sign_and_sendmoney(char *cointxid,struct ramchain_info *ram,struct cointx_info *cointx,char *othersignedtx,uint64_t *redeems,uint64_t *amounts,int32_t numredeems)
{
    uint64_t get_sender(uint64_t *amountp,char *txidstr);
    void *extract_jsonkey(cJSON *item,void *arg,void *arg2);
    void set_MGW_moneysentfname(char *fname,char *NXTaddr);
    int32_t jsonstrcmp(void *ref,void *item);
    char txidstr[64],NXTaddr[64],jsonstr[4096],*retstr = 0;
    int32_t i;
    uint64_t amount,senderbits,redeemtxid;
    fprintf(stderr,"achieved consensus and sign! (%s)\n",othersignedtx);
    if ( (retstr= _submit_withdraw(ram,cointx,othersignedtx)) != 0 )
    {
        if ( is_hexstr(retstr) != 0 )
        {
            strcpy(cointxid,retstr);
            //*AMtxidp = _broadcast_moneysentAM(ram,height);
            for (i=0; i<numredeems; i++)
            {
                if ( (redeemtxid = redeems[i]) != 0 && amounts[i] != 0 )
                {
                    printf("signed and sent.%d: %llu %.8f\n",i,(long long)redeemtxid,dstr(amounts[i]));
                    _ram_update_redeembits(ram,redeemtxid,0,cointxid,0);
                    expand_nxt64bits(txidstr,redeemtxid);
                    senderbits = get_sender(&amount,txidstr);
                    expand_nxt64bits(NXTaddr,senderbits);
                    sprintf(jsonstr,"{\"NXT\":\"%s\",\"redeemtxid\":\"%llu\",\"amount\":\"%.8f\",\"coin\":\"%s\",\"cointxid\":\"%s\",\"vout\":\"%d\"}",NXTaddr,(long long)redeemtxid,dstr(amounts[i]),ram->name,txidstr,i);
                    update_MGW_jsonfile(set_MGW_moneysentfname,extract_jsonkey,jsonstrcmp,0,jsonstr,"redeemtxid",0);
                    update_MGW_jsonfile(set_MGW_moneysentfname,extract_jsonkey,jsonstrcmp,NXTaddr,jsonstr,"redeemtxid",0);
                }
            }
            //backupwallet(cp,ram->coinid);
        }
        else
        {
            for (i=0; i<numredeems; i++)
                printf("(%llu %.8f) ",(long long)redeems[i],dstr(amounts[i]));
            printf("_sign_and_sendmoney: unexpected return.(%s)\n",retstr);
            exit(1);
        }
        return(retstr);
    }
    else printf("sign_and_sendmoney: error sending rawtransaction %s\n",othersignedtx);
    return(0);
}
Exemplo n.º 6
0
int32_t cmp_nxt64bits(const char *str,uint64_t nxt64bits)
{
    char expanded[64];
    if ( str == 0 )//|| str[0] == 0 || nxt64bits == 0 )
        return(-1);
    if ( nxt64bits == 0 && str[0] == 0 )
        return(0);
    expand_nxt64bits(expanded,nxt64bits);
    return(strcmp(str,expanded));
}
Exemplo n.º 7
0
void process_pNXT_AM(struct pNXT_info *dp,struct NXT_protocol_parms *parms)
{
    cJSON *argjson;
    struct json_AM *ap;
    char NXTaddr[64],*sender,*receiver;
    sender = parms->sender; receiver = parms->receiver; ap = parms->AMptr;
    expand_nxt64bits(NXTaddr,ap->H.nxt64bits);
    if ( strcmp(NXTaddr,sender) != 0 )
    {
        printf("unexpected NXTaddr %s != sender.%s when receiver.%s\n",NXTaddr,sender,receiver);
        return;
    }
    if ( (argjson = parse_json_AM(ap)) != 0 )
    {
        printf("process_pNXT_AM got jsontxt.(%s)\n",ap->jsonstr);
        free_json(argjson);
    }
}
Exemplo n.º 8
0
char *call_SuperNET_JSON(char *JSONstr)
{
    cJSON *json,*array;
    int32_t valid;
    char NXTaddr[64],_tokbuf[2*MAX_JSON_FIELD],encoded[NXT_TOKEN_LEN+1],*cmdstr,*retstr = 0;
    struct coin_info *cp = get_coin_info("BTCD");
    if ( Finished_init == 0 )
    {
        printf("Finished_init still 0\n");
        return(clonestr("{\"result\":null}"));
    }
//printf("got call_SuperNET_JSON.(%s)\n",JSONstr);
    if ( cp != 0 && (json= cJSON_Parse(JSONstr)) != 0 )
    {
        expand_nxt64bits(NXTaddr,cp->srvpubnxtbits);
        cJSON_AddItemToObject(json,"NXT",cJSON_CreateString(NXTaddr));
        cJSON_AddItemToObject(json,"pubkey",cJSON_CreateString(Global_mp->pubkeystr));
        cmdstr = cJSON_Print(json);
        if ( cmdstr != 0 )
        {
            stripwhite_ns(cmdstr,strlen(cmdstr));
            issue_generateToken(0,encoded,cmdstr,cp->srvNXTACCTSECRET);
            encoded[NXT_TOKEN_LEN] = 0;
            sprintf(_tokbuf,"[%s,{\"token\":\"%s\"}]",cmdstr,encoded);
            free(cmdstr);
            //printf("made tokbuf.(%s)\n",_tokbuf);
            array = cJSON_Parse(_tokbuf);
            if ( array != 0 )
            {
                cmdstr = verify_tokenized_json(0,NXTaddr,&valid,array);
                //printf("cmdstr.%s valid.%d\n",cmdstr,valid);
                retstr = SuperNET_json_commands(Global_mp,0,array,NXTaddr,valid,_tokbuf);
                //printf("json command return.(%s)\n",retstr);
                if ( cmdstr != 0 )
                    free(cmdstr);
                free_json(array);
            } else printf("couldnt parse tokbuf.(%s)\n",_tokbuf);
        }
        free_json(json);
    } else printf("couldnt parse (%s)\n",JSONstr);
    if ( retstr == 0 )
        retstr = clonestr("{\"result\":null}");
    return(retstr);
}
int32_t get_assetname(char *name,uint64_t assetid)
{
    char assetidstr[64],*jsonstr; cJSON *json;
    name[0] = 0;
    if ( is_native_crypto(name,assetid) != 0 )
        return((int32_t)strlen(name));
    expand_nxt64bits(assetidstr,assetid);
    name[0] = 0;
    if ( (jsonstr= _issue_getAsset(assetidstr)) != 0 )
    {
        if ( (json= cJSON_Parse(jsonstr)) != 0 )
        {
            extract_cJSON_str(name,15,json,"name");
            free_json(json);
        }
        free(jsonstr);
    }
    return((int32_t)strlen(assetidstr));
}
cJSON *InstantDEX_lottostats()
{
    char cmdstr[1024],NXTaddr[64],buf[1024],*jsonstr; struct destbuf receiverstr;
    cJSON *json,*array,*txobj; int32_t i,n,totaltickets = 0; uint64_t amount,senderbits; uint32_t timestamp = 0;
    if ( timestamp == 0 )
        timestamp = 38785003;
    sprintf(cmdstr,"requestType=getAccountTransactions&account=%s&timestamp=%u&type=0&subtype=0",INSTANTDEX_ACCT,timestamp);
    //printf("cmd.(%s)\n",cmdstr);
    if ( (jsonstr= issue_NXTPOST(cmdstr)) != 0 )
    {
        // printf("jsonstr.(%s)\n",jsonstr);
        // mm string.({"requestProcessingTime":33,"transactions":[{"fullHash":"2a2aab3b84dadf092cf4cedcd58a8b5a436968e836338e361c45651bce0ef97e","confirmations":203,"signatureHash":"52a4a43d9055fe4861b3d13fbd03a42fecb8c9ad4ac06a54da7806a8acd9c5d1","transaction":"711527527619439146","amountNQT":"1100000000","transactionIndex":2,"ecBlockHeight":360943,"block":"6797727125503999830","recipientRS":"NXT-74VC-NKPE-RYCA-5LMPT","type":0,"feeNQT":"100000000","recipient":"4383817337783094122","version":1,"sender":"423766016895692955","timestamp":38929220,"ecBlockId":"10121077683890606382","height":360949,"subtype":0,"senderPublicKey":"4e5bbad625df3d536fa90b1e6a28c3f5a56e1fcbe34132391c8d3fd7f671cb19","deadline":1440,"blockTimestamp":38929430,"senderRS":"NXT-8E6V-YBWH-5VMR-26ESD","signature":"4318f36d9cf68ef0a8f58303beb0ed836b670914065a868053da5fe8b096bc0c268e682c0274e1614fc26f81be4564ca517d922deccf169eafa249a88de58036"}]})
        if ( (json= cJSON_Parse(jsonstr)) != 0 )
        {
            if ( (array= cJSON_GetObjectItem(json,"transactions")) != 0 && is_cJSON_Array(array) != 0 && (n= cJSON_GetArraySize(array)) > 0 )
            {
                for (i=0; i<n; i++)
                {
                    txobj = cJSON_GetArrayItem(array,i);
                    copy_cJSON(&receiverstr,cJSON_GetObjectItem(txobj,"recipient"));
                    if ( strcmp(receiverstr.buf,INSTANTDEX_ACCT) == 0 )
                    {
                        if ( (senderbits = get_API_nxt64bits(cJSON_GetObjectItem(txobj,"sender"))) != 0 )
                        {
                            expand_nxt64bits(NXTaddr,senderbits);
                            amount = get_API_nxt64bits(cJSON_GetObjectItem(txobj,"amountNQT"));
                            if ( amount == INSTANTDEX_FEE )
                                totaltickets++;
                            else if ( amount >= 2*INSTANTDEX_FEE )
                                totaltickets += 2;
                        }
                    }
                }
            }
            free_json(json);
        }
        free(jsonstr);
    }
    sprintf(buf,"{\"result\":\"lottostats\",\"totaltickets\":\"%d\"}",totaltickets);
    return(cJSON_Parse(buf));
}
Exemplo n.º 11
0
char *nxt64str2(uint64_t nxt64bits)
{
    static char NXTaddr[64];
    expand_nxt64bits(NXTaddr,nxt64bits);
    return(NXTaddr);
}
Exemplo n.º 12
0
uint64_t _find_pending_transfers(uint64_t *pendingredeemsp,struct mgw777 *mgw)
{
    int32_t j,disable_newsends,specialsender,specialreceiver,numpending = 0;
    char sender[64],receiver[64],txidstr[512],withdrawaddr[512],*destaddr;
    struct NXT_assettxid *tp;
    struct NXT_asset *ap;
    struct cointx_info *cointx;
    uint64_t orphans = 0;
    *pendingredeemsp = 0;
    disable_newsends = ((mgw->numpendingsends > 0) || (mgw->S.gatewayid < 0));
    if ( (ap= mgw->ap) == 0 )
    {
        printf("no NXT_asset for %s\n",mgw->coinstr);
        return(0);
    }
    for (j=0; j<ap->num; j++)
    {
        tp = ap->txids[j];
        //if ( strcmp(mgw->coinstr,"BITS") == 0 )
        //printf("%d of %d: check %s.%llu completed.%d\n",j,ap->num,mgw->coinstr,(long long)tp->redeemtxid,tp->completed);
        if ( tp->completed == 0 )
        {
            expand_nxt64bits(sender,tp->senderbits);
            specialsender = _in_specialNXTaddrs(mgw,sender);
            expand_nxt64bits(receiver,tp->receiverbits);
            specialreceiver = _in_specialNXTaddrs(mgw,receiver);
            if ( (specialsender ^ specialreceiver) == 0 || tp->cointxid != 0 )
            {
                printf("autocomplete: %llu cointxid.%p\n",(long long)tp->redeemtxid,tp->cointxid);
                _complete_assettxid(tp);
            }
            else
            {
                if ( _is_limbo_redeem(mgw,tp->redeemtxid) != 0 )
                {
                    printf("autocomplete: limbo %llu cointxid.%p\n",(long long)tp->redeemtxid,tp->cointxid);
                    _complete_assettxid(tp);
                }
                //printf("receiver.%llu vs MGW.%llu\n",(long long)tp->receiverbits,(long long)mgw->MGWbits);
                if ( tp->receiverbits == mgw->MGWbits ) // redeem start
                {
                    destaddr = "coinaddr";
                    if ( _valid_txamount(mgw,tp->U.assetoshis,0) > 0 && (tp->convwithdrawaddr != 0 || (destaddr= _parse_withdraw_instructions(withdrawaddr,sender,mgw,tp,ap)) != 0) )
                    {
                        if ( tp->convwithdrawaddr == 0 )
                            tp->convwithdrawaddr = clonestr(destaddr);
                        if ( tp->redeemstarted == 0 )
                        {
                            printf("find_pending_transfers: redeem.%llu started %s %.8f for NXT.%s to %s\n",(long long)tp->redeemtxid,mgw->coinstr,dstr(tp->U.assetoshis),sender,destaddr!=0?destaddr:"no withdraw address");
                            tp->redeemstarted = (uint32_t)time(NULL);
                        }
                        else
                        {
                            int32_t i,numpayloads;
                            struct ramchain_hashptr *addrptr;
                            struct rampayload *payloads;
                            if ( (payloads= ram_addrpayloads(&addrptr,&numpayloads,mgw,destaddr)) != 0 && addrptr != 0 && numpayloads > 0 )
                            {
                                for (i=0; i<numpayloads; i++)
                                    if ( (dstr(tp->U.assetoshis) - dstr(payloads[i].value)) == .0101 ) // historical BTCD parameter
                                    {
                                        printf("(autocomplete.%llu payload.i%d >>>>>>>> %.8f <<<<<<<<<) ",(long long)tp->redeemtxid,i,dstr(payloads[i].value));
                                        _complete_assettxid(tp);
                                    }
                            }
                        }
                        if ( tp->completed == 0 && tp->convwithdrawaddr != 0 )
                        {
                            (*pendingredeemsp) += tp->U.assetoshis;
                            printf("%s NXT.%llu withdraw.(%llu %.8f).rt%d_%d_%d_%d.g%d -> %s elapsed %.1f minutes | pending.%d\n",mgw->coinstr,(long long)tp->senderbits,(long long)tp->redeemtxid,dstr(tp->U.assetoshis),mgw->S.enable_withdraws,mgw->S.is_realtime,(tp->height + mgw->withdrawconfirms) <= mgw->S.NXT_RTblocknum,mgw->S.MGWbalance >= 0,(int32_t)(tp->senderbits % NUM_GATEWAYS),tp->convwithdrawaddr,(double)(time(NULL) - tp->redeemstarted)/60,mgw->numpendingsends);
                            numpending++;
                            if ( disable_newsends == 0 )
                            {
                                if ( (cointx= _calc_cointx_withdraw(mgw,tp->convwithdrawaddr,tp->U.assetoshis,tp->redeemtxid)) != 0 )
                                {
                                    if ( ram_MGW_ready(mgw,0,tp->height,0,tp->U.assetoshis) > 0 )
                                    {
                                        ram_send_cointx(mgw,cointx);
                                        mgw->numpendingsends++;
                                        //ram_add_pendingsend(0,ram,tp,cointx);
                                        // disable_newsends = 1;
                                    } else printf("not ready to withdraw yet\n");
                                }
                                else if ( mgw->S.enable_withdraws != 0 && mgw->S.is_realtime != 0 && mgw->S.NXT_is_realtime != 0 )
                                {
                                    //tp->completed = 1; // ignore malformed requests for now
                                }
                            }
                            if ( mgw->S.gatewayid >= 0 && ram_check_consensus(txidstr,mgw,tp) != 0 )
                                printf("completed redeem.%llu with cointxid.%s\n",(long long)tp->redeemtxid,txidstr);
                            //printf("(%llu %.8f).%d ",(long long)tp->redeemtxid,dstr(tp->U.assetoshis),(int32_t)(time(NULL) - tp->redeemstarted));
                        } else printf("%llu %.8f: completed.%d withdraw.%p destaddr.%p\n",(long long)tp->redeemtxid,dstr(tp->U.assetoshis),tp->completed,tp->convwithdrawaddr,destaddr);
                    }
                    else if ( tp->completed == 0 && _valid_txamount(mgw,tp->U.assetoshis,0) > 0 )
                        printf("incomplete but skipped.%llu: %.8f destaddr.%s\n",(long long)tp->redeemtxid,dstr(tp->U.assetoshis),destaddr);
                    else printf("%s.%llu %.8f is too small, thank you for your donation to MGW\n",mgw->coinstr,(long long)tp->redeemtxid,dstr(tp->U.assetoshis)), tp->completed = 1;
                }
                else if ( tp->completed == 0 && specialsender != 0 ) // deposit complete w/o cointxid (shouldnt happen normally)
                {
                    orphans += tp->U.assetoshis;
                    _complete_assettxid(tp);
                    printf("find_pending_transfers: internal transfer.%llu limbo.%d complete %s %.8f to NXT.%s\n",(long long)tp->redeemtxid,_is_limbo_redeem(mgw,tp->redeemtxid),mgw->coinstr,dstr(tp->U.assetoshis),receiver);
                } else tp->completed = 1; // this is some independent tx
            }
        }
    }
    if ( numpending == 0 && mgw->numpendingsends != 0 )
    {
        printf("All pending withdraws done!\n");
        mgw->numpendingsends = 0;
    }
    return(orphans);
}
Exemplo n.º 13
0
char *pNXT_jsonhandler(cJSON **argjsonp,char *argstr,char *verifiedsender)
{
    struct NXThandler_info *mp = Global_mp;
    long len;
    struct coin_info *cp;
    int32_t valid,firsttime = 1;
    cJSON *secretobj = 0,*json;
    char NXTACCTSECRET[1024],sender[64],*origparmstxt,*parmstxt=0,encoded[NXT_TOKEN_LEN+1],*retstr = 0;
again:
    sender[0] = 0;
    if ( verifiedsender != 0 && verifiedsender[0] != 0 )
        safecopy(sender,verifiedsender,sizeof(sender));
    valid = -1;
    //printf("pNXT_jsonhandler argjson.%p\n",*argjsonp);
    if ( *argjsonp != 0 )
    {
        secretobj = cJSON_GetObjectItem(*argjsonp,"secret");
        copy_cJSON(NXTACCTSECRET,secretobj);
        if ( NXTACCTSECRET[0] == 0 && (cp= get_coin_info("BTCD")) != 0 )
        {
            safecopy(NXTACCTSECRET,cp->NXTACCTSECRET,sizeof(NXTACCTSECRET));
            cJSON_ReplaceItemInObject(*argjsonp,"secret",cJSON_CreateString(NXTACCTSECRET));
            //printf("got cp.%p for BTCD (%s) (%s)\n",cp,cp->NXTACCTSECRET,cJSON_Print(*argjsonp));
        }
        parmstxt = cJSON_Print(*argjsonp);
        len = strlen(parmstxt);
        stripwhite_ns(parmstxt,len);
        //printf("parmstxt.(%s)\n",parmstxt);
    }
    if ( *argjsonp == 0 )
    {
        json = cJSON_CreateObject();
        cJSON_AddItemToObject(json,"error",cJSON_CreateString("cant parse"));
        cJSON_AddItemToObject(json,"argstr",cJSON_CreateString(argstr));
        retstr = cJSON_Print(json);
        free_json(json);
        return(retstr);
    }
    else
    {
        origparmstxt = parmstxt;
        parmstxt = verify_tokenized_json(sender,&valid,argjsonp,parmstxt);
    }
    retstr = pNXT_json_commands(mp,Global_pNXT,*argjsonp,sender,valid,argstr);
    //printf("back from pNXT_json_commands\n");
    if ( firsttime != 0 && retstr == 0 && *argjsonp != 0 && parmstxt == 0 )
    {
        cJSON *reqobj;
        uint64_t nxt64bits;
        char _tokbuf[4096],NXTaddr[64],buf[1024];//,*str;
        firsttime = 0;
        reqobj = cJSON_GetObjectItem(*argjsonp,"requestType");
        copy_cJSON(buf,reqobj);
        if ( cJSON_GetObjectItem(*argjsonp,"requestType") != 0 )
            cJSON_ReplaceItemInObject(*argjsonp,"time",cJSON_CreateNumber(time(NULL)));
        else cJSON_AddItemToObject(*argjsonp,"time",cJSON_CreateNumber(time(NULL)));
        nxt64bits = issue_getAccountId(0,NXTACCTSECRET);
        expand_nxt64bits(NXTaddr,nxt64bits);
        cJSON_ReplaceItemInObject(*argjsonp,"NXT",cJSON_CreateString(NXTaddr));
        printf("replace NXT.(%s)\n",NXTaddr);
//#ifndef __linux__
        if ( strcmp(buf,"teleport") != 0 && strcmp(buf,"tradebot") != 0 && strcmp(buf,"makeoffer") != 0 && strcmp(buf,"select") != 0 && strcmp(buf,"checkmessages") != 0 && Global_pNXT->privacyServer != 0 )
        {
            parmstxt = remove_secret(argjsonp,parmstxt);
            issue_generateToken(mp->curl_handle2,encoded,parmstxt,NXTACCTSECRET);
            encoded[NXT_TOKEN_LEN] = 0;
            sprintf(_tokbuf,"[%s,{\"token\":\"%s\"}]",parmstxt,encoded);
            retstr = sendmessage(NXTaddr,NXTACCTSECRET,_tokbuf,(int32_t)strlen(_tokbuf)+1,Global_pNXT->privacyServer_NXTaddr,_tokbuf);
        }
        else
//#endif
        {
            issue_generateToken(mp->curl_handle2,encoded,origparmstxt,NXTACCTSECRET);
            encoded[NXT_TOKEN_LEN] = 0;
            sprintf(_tokbuf,"[%s,{\"token\":\"%s\"}]",origparmstxt,encoded);
            if ( *argjsonp != 0 )
                free_json(*argjsonp);
            *argjsonp = cJSON_Parse(_tokbuf);
            if ( origparmstxt != 0 )
                free(origparmstxt), origparmstxt = 0;
            goto again;
        }
    }
    //printf("free parmstxt.%p, argjson.%p\n",parmstxt,*argjsonp);
    if ( parmstxt != 0 )
        free(parmstxt);
    return(retstr);
}