Exemple #1
0
char *balance(char *retbuf,long maxlen,struct txnet777 *TXNET,cJSON *json,char *jsonstr,char *tokenstr,char *forwarder,char *sender,int32_t valid)
{
    char numstr[64],*arraystr; struct txnet777_tx args; cJSON *argjson;
    memset(&args,0,sizeof(args));
    argjson = cJSON_CreateArray();
    memcpy(&args.H.sig.txid,&argjson,sizeof(argjson));
    args.in.senderbits = conv_acctstr(sender);
    kv777_iterate(RPS.TXNET.transactions,&args,0,RPS_balanceiterator);
    arraystr = jprint(argjson,1);
    sprintf(retbuf,"{\"result\":\"success\",\"account\":\"%s\",\"balance\":\"%s\",\"transactions\":%s}",sender,numstr,arraystr);
    return(0);
}
Exemple #2
0
char *bet(char *retbuf,long maxlen,struct txnet777 *TXNET,cJSON *json,char *jsonstr,char *tokenstr,char *forwarder,char *sender,int32_t valid)
{
    struct txnet777_tx tx; int64_t balance,senderbits,betamount,destbits;
    if ( (betamount= jdouble(json,"bet") * SATOSHIDEN) > 0 && (destbits= calc_rpsbits(jstr(json,"move"))) != 0 )
    {
        memset(&tx,0,sizeof(tx));
        tx.in.senderbits = senderbits = conv_acctstr(sender);
        kv777_iterate(RPS.TXNET.transactions,&tx,0,balanceiterator);
        if ( (balance= tx.out[0].destamount) >= betamount )
        {
            memset(&tx,0,sizeof(tx));
            tx.out[0].destamount = betamount, tx.out[0].destbits = destbits;
            txnet777_signtx(&RPS.TXNET,0,&tx,sizeof(tx),RPS.name,senderbits,(uint32_t)time(NULL));
            txnet777_broadcast(&RPS.TXNET,&tx);
        }
    } else sprintf(retbuf,"{\"error\":\"illegal bet\",\"betamount\":\"%llu\"}",(long long)betamount);
    return(0);
}
struct coin777 *coin777_create(char *coinstr,cJSON *argjson)
{
    char *serverport,*path=0,*conf=0; struct destbuf tmp;
    struct coin777 *coin = calloc(1,sizeof(*coin));
    safecopy(coin->name,coinstr,sizeof(coin->name));
    if ( argjson == 0 )
    {
        coin->minconfirms = (strcmp("BTC",coinstr) == 0) ? 3 : 10;
        coin->estblocktime = (strcmp("BTC",coinstr) == 0) ? 600 : 120;
    }
    else
    {
        coin->minoutput = get_API_nxt64bits(cJSON_GetObjectItem(argjson,"minoutput"));
        coin->minconfirms = get_API_int(cJSON_GetObjectItem(argjson,"minconfirms"),(strcmp("BTC",coinstr) == 0) ? 3 : 10);
        coin->estblocktime = get_API_int(cJSON_GetObjectItem(argjson,"estblocktime"),(strcmp("BTC",coinstr) == 0) ? 600 : 120);
        coin->jsonstr = cJSON_Print(argjson);
        coin->argjson = cJSON_Duplicate(argjson,1);
        if ( (serverport= cJSON_str(cJSON_GetObjectItem(argjson,"rpc"))) != 0 )
            safecopy(coin->serverport,serverport,sizeof(coin->serverport));
        path = cJSON_str(cJSON_GetObjectItem(argjson,"path"));
        conf = cJSON_str(cJSON_GetObjectItem(argjson,"conf"));

        copy_cJSON(&tmp,cJSON_GetObjectItem(argjson,"assetid")), safecopy(coin->mgw.assetidstr,tmp.buf,sizeof(coin->mgw.assetidstr));
        coin->mgw.assetidbits = calc_nxt64bits(coin->mgw.assetidstr);
        copy_cJSON(&tmp,cJSON_GetObjectItem(argjson,"issuer")), safecopy(coin->mgw.issuer,tmp.buf,sizeof(coin->mgw.issuer));;
        coin->mgw.issuerbits = conv_acctstr(coin->mgw.issuer);
        printf(">>>>>>>>>>>> a issuer.%s %llu assetid.%llu minoutput.%llu\n",coin->mgw.issuer,(long long)coin->mgw.issuerbits,(long long)coin->mgw.assetidbits,(long long)coin->minoutput);
        //uint32_t set_assetname(uint64_t *multp,char *name,uint64_t assetbits);
        _set_assetname(&coin->mgw.ap_mult,coin->mgw.assetname,0,coin->mgw.assetidbits);
        printf("assetname.(%s) mult.%llu\n",coin->mgw.assetname,coin->mgw.ap_mult);
        strcpy(coin->mgw.coinstr,coinstr);
        if ( (coin->mgw.special= cJSON_GetObjectItem(argjson,"special")) == 0 )
            coin->mgw.special = cJSON_GetObjectItem(COINS.argjson,"special");
        if ( coin->mgw.special != 0 )
            coin->mgw.special = NXT_convjson(coin->mgw.special);
        printf("CONVERTED.(%s)\n",cJSON_Print(coin->mgw.special));
        coin->mgw.limbo = cJSON_GetObjectItem(argjson,"limbo");
        coin->mgw.dust = get_API_nxt64bits(cJSON_GetObjectItem(argjson,"dust"));
        coin->mgw.txfee = get_API_nxt64bits(cJSON_GetObjectItem(argjson,"txfee_satoshis"));
        if ( coin->mgw.txfee == 0 )
            coin->mgw.txfee = (uint64_t)(SATOSHIDEN * get_API_float(cJSON_GetObjectItem(argjson,"txfee")));
        if ( coin->mgw.txfee == 0 )
            coin->mgw.txfee = 10000;
        coin->mgw.NXTfee_equiv = get_API_nxt64bits(cJSON_GetObjectItem(argjson,"NXTfee_equiv_satoshis"));
        if ( coin->mgw.NXTfee_equiv == 0 )
            coin->mgw.NXTfee_equiv = (uint64_t)(SATOSHIDEN * get_API_float(cJSON_GetObjectItem(argjson,"NXTfee_equiv")));
        copy_cJSON(&tmp,cJSON_GetObjectItem(argjson,"opreturnmarker")), safecopy(coin->mgw.opreturnmarker,tmp.buf,sizeof(coin->mgw.opreturnmarker));
        printf("OPRETURN.(%s)\n",coin->mgw.opreturnmarker);
        copy_cJSON(&tmp,cJSON_GetObjectItem(argjson,"marker2")), safecopy(coin->mgw.marker2,tmp.buf,sizeof(coin->mgw.marker2));
        coin->mgw.redeemheight = get_API_int(cJSON_GetObjectItem(argjson,"redeemheight"),430000);
        coin->mgw.use_addmultisig = get_API_int(cJSON_GetObjectItem(argjson,"useaddmultisig"),(strcmp("BTC",coinstr) != 0));
        coin->mgw.do_opreturn = get_API_int(cJSON_GetObjectItem(argjson,"do_opreturn"),(strcmp("BTC",coinstr) == 0));
        coin->mgw.oldtx_format = get_API_int(cJSON_GetObjectItem(argjson,"oldtx_format"),(strcmp("BTC",coinstr) == 0));
        coin->mgw.firstunspentind = get_API_int(cJSON_GetObjectItem(argjson,"firstunspent"),(strcmp("BTCD",coinstr) == 0) ? 2500000 : 0);
        if ( (coin->mgw.NXTconvrate = get_API_float(cJSON_GetObjectItem(argjson,"NXTconvrate"))) == 0 )
        {
            if ( coin->mgw.NXTfee_equiv != 0 && coin->mgw.txfee != 0 )
                coin->mgw.NXTconvrate = ((double)coin->mgw.NXTfee_equiv / coin->mgw.txfee);
        }
        copy_cJSON(&tmp,cJSON_GetObjectItem(argjson,"marker")), safecopy(coin->mgw.marker,tmp.buf,sizeof(coin->mgw.marker));
        printf("OPRETURN.(%s)\n",coin->mgw.opreturnmarker);
    }
    printf("coin777_create %s: (%s) %llu mult.%llu NXTconvrate %.8f minconfirms.%d issuer.(%s) %llu opreturn.%d oldformat.%d\n",coin->mgw.coinstr,coin->mgw.assetidstr,(long long)coin->mgw.assetidbits,(long long)coin->mgw.ap_mult,coin->mgw.NXTconvrate,coin->minconfirms,coin->mgw.issuer,(long long)coin->mgw.issuerbits,coin->mgw.do_opreturn,coin->mgw.oldtx_format);
    extract_userpass(coin->serverport,coin->userpass,coinstr,SUPERNET.userhome,path,conf);
    printf("COIN.%s serverport.(%s) userpass.(%s)\n",coin->name,coin->serverport,coin->userpass);
    COINS.LIST = realloc(COINS.LIST,(COINS.num+1) * sizeof(*coin));
    COINS.LIST[COINS.num] = coin, COINS.num++;
    //ensure_packedptrs(coin);
    return(coin);
}
Exemple #4
0
struct coin777 *coin777_create(char *coinstr,cJSON *argjson)
{
    char *serverport,*path=0,*conf=0; struct destbuf tmp;
    struct coin777 *coin = calloc(1,sizeof(*coin));
    if ( coinstr == 0 || coinstr[0] == 0 )
    {
        printf("null coinstr?\n");
        //getchar();
        return(0);
    }
    safecopy(coin->name,coinstr,sizeof(coin->name));
    coin->jvin = -1;
    if ( argjson == 0 || strcmp(coinstr,"NXT") == 0 )
    {
        coin->usep2sh = 1;
        coin->minconfirms = (strcmp("BTC",coinstr) == 0) ? 3 : 10;
        coin->estblocktime = (strcmp("BTC",coinstr) == 0) ? 600 : 120;
        coin->mgw.use_addmultisig = (strcmp("BTC",coinstr) != 0);
    }
    else
    {
        coin->minoutput = get_API_nxt64bits(cJSON_GetObjectItem(argjson,"minoutput"));
        coin->minconfirms = get_API_int(cJSON_GetObjectItem(argjson,"minconfirms"),(strcmp("BTC",coinstr) == 0) ? 3 : 10);
        coin->estblocktime = get_API_int(cJSON_GetObjectItem(argjson,"estblocktime"),(strcmp("BTC",coinstr) == 0) ? 600 : 120);
        coin->jsonstr = cJSON_Print(argjson);
        coin->argjson = cJSON_Duplicate(argjson,1);
        if ( (serverport= cJSON_str(cJSON_GetObjectItem(argjson,"rpc"))) != 0 )
            safecopy(coin->serverport,serverport,sizeof(coin->serverport));
        path = cJSON_str(cJSON_GetObjectItem(argjson,"path"));
        conf = cJSON_str(cJSON_GetObjectItem(argjson,"conf"));

        copy_cJSON(&tmp,cJSON_GetObjectItem(argjson,"assetid")), safecopy(coin->mgw.assetidstr,tmp.buf,sizeof(coin->mgw.assetidstr));
        if ( (coin->mgw.assetidbits= calc_nxt64bits(coin->mgw.assetidstr)) == 0 )
            coin->mgw.assetidbits = is_MGWcoin(coinstr);
        copy_cJSON(&tmp,cJSON_GetObjectItem(argjson,"issuer")), safecopy(coin->mgw.issuer,tmp.buf,sizeof(coin->mgw.issuer));;
        coin->mgw.issuerbits = conv_acctstr(coin->mgw.issuer);
        printf(">>>>>>>>>>>> a issuer.%s %llu assetid.%llu minoutput.%llu\n",coin->mgw.issuer,(long long)coin->mgw.issuerbits,(long long)coin->mgw.assetidbits,(long long)coin->minoutput);
        //uint32_t set_assetname(uint64_t *multp,char *name,uint64_t assetbits);
        if ( coin->mgw.assetidbits != 0 )
            _set_assetname(&coin->mgw.ap_mult,coin->mgw.assetname,0,coin->mgw.assetidbits);
        printf("assetname.(%s) mult.%llu\n",coin->mgw.assetname,coin->mgw.ap_mult);
        strcpy(coin->mgw.coinstr,coinstr);
        if ( (coin->mgw.special= cJSON_GetObjectItem(argjson,"special")) == 0 )
            coin->mgw.special = cJSON_GetObjectItem(COINS.argjson,"special");
        if ( coin->mgw.special != 0 )
        {
            coin->mgw.special = NXT_convjson(coin->mgw.special);
            printf("CONVERTED.(%s)\n",cJSON_Print(coin->mgw.special));
        }
        coin->mgw.limbo = cJSON_GetObjectItem(argjson,"limbo");
        coin->mgw.dust = get_API_nxt64bits(cJSON_GetObjectItem(argjson,"dust"));
        coin->mgw.txfee = get_API_nxt64bits(cJSON_GetObjectItem(argjson,"txfee_satoshis"));
        if ( coin->mgw.txfee == 0 )
            coin->mgw.txfee = (uint64_t)(SATOSHIDEN * get_API_float(cJSON_GetObjectItem(argjson,"txfee")));
        coin->mgw.NXTfee_equiv = get_API_nxt64bits(cJSON_GetObjectItem(argjson,"NXTfee_equiv_satoshis"));
        if ( coin->mgw.NXTfee_equiv == 0 )
            coin->mgw.NXTfee_equiv = (uint64_t)(SATOSHIDEN * get_API_float(cJSON_GetObjectItem(argjson,"NXTfee_equiv")));
        copy_cJSON(&tmp,cJSON_GetObjectItem(argjson,"opreturnmarker")), safecopy(coin->mgw.opreturnmarker,tmp.buf,sizeof(coin->mgw.opreturnmarker));
        printf("OPRETURN.(%s)\n",coin->mgw.opreturnmarker);
        copy_cJSON(&tmp,cJSON_GetObjectItem(argjson,"marker2")), safecopy(coin->mgw.marker2,tmp.buf,sizeof(coin->mgw.marker2));
        coin->mgw.redeemheight = get_API_int(cJSON_GetObjectItem(argjson,"redeemheight"),430000);
        coin->mgw.use_addmultisig = get_API_int(cJSON_GetObjectItem(argjson,"useaddmultisig"),(strcmp("BTC",coinstr) != 0));
        coin->mgw.do_opreturn = get_API_int(cJSON_GetObjectItem(argjson,"do_opreturn"),(strcmp("BTC",coinstr) == 0));
        coin->mgw.oldtx_format = get_API_int(cJSON_GetObjectItem(argjson,"oldtx_format"),(strcmp("BTC",coinstr) == 0));
        coin->mgw.firstunspentind = get_API_int(cJSON_GetObjectItem(argjson,"firstunspent"),(strcmp("BTCD",coinstr) == 0) ? 2500000 : 0);
        if ( (coin->mgw.NXTconvrate = get_API_float(cJSON_GetObjectItem(argjson,"NXTconvrate"))) == 0 )
        {
            if ( coin->mgw.NXTfee_equiv != 0 && coin->mgw.txfee != 0 )
                coin->mgw.NXTconvrate = ((double)coin->mgw.NXTfee_equiv / coin->mgw.txfee);
        }
        copy_cJSON(&tmp,cJSON_GetObjectItem(argjson,"marker")), safecopy(coin->mgw.marker,tmp.buf,sizeof(coin->mgw.marker));
        printf("OPRETURN.(%s)\n",coin->mgw.opreturnmarker);
        coin->addrtype = get_API_int(jobj(argjson,"addrtype"),0);
        coin->p2shtype = get_API_int(jobj(argjson,"p2shtype"),0);
        coin->usep2sh = get_API_int(jobj(argjson,"usep2sh"),1);
    }
    if ( coin->mgw.txfee == 0 )
        coin->mgw.txfee = 10000;
    if ( strcmp(coin->name,"BTC") == 0 )
    {
        coin->addrtype = 0, coin->p2shtype = 5;
        if ( coin->donationaddress[0] == 0 )
        {
            strcpy(coin->donationaddress,"177MRHRjAxCZc7Sr5NViqHRivDu1sNwkHZ");
            sprintf(coin->donationscript,"76a91443044b8d5dc8f3758dbc83374c596e96d25ead4f88ac");
        }
    }
    else if ( strcmp(coin->name,"LTC") == 0 )
        coin->addrtype = 48, coin->p2shtype = 5, coin->minconfirms = 1, coin->mgw.txfee = 100000, coin->usep2sh = 0;
    else if ( strcmp(coin->name,"BTCD") == 0 )
        coin->addrtype = 60, coin->p2shtype = 85, coin->mgw.txfee = 1000000;//, strcpy(coin->donationaddress,"RDRWMSrDdoUcfZRBWUz7KZQSxPS9bZRerM");
    else if ( strcmp(coin->name,"DOGE") == 0 )
        coin->addrtype = 30, coin->p2shtype = 35;
    else if ( strcmp(coin->name,"VRC") == 0 )
        coin->addrtype = 70, coin->p2shtype = 85;
    else if ( strcmp(coin->name,"OPAL") == 0 )
        coin->addrtype = 115, coin->p2shtype = 28;
    else if ( strcmp(coin->name,"BITS") == 0 )
        coin->addrtype = 25, coin->p2shtype = 8;
    printf("coin777_create %s: (%s) %llu mult.%llu NXTconvrate %.8f minconfirms.%d issuer.(%s) %llu opreturn.%d oldformat.%d\n",coin->mgw.coinstr,coin->mgw.assetidstr,(long long)coin->mgw.assetidbits,(long long)coin->mgw.ap_mult,coin->mgw.NXTconvrate,coin->minconfirms,coin->mgw.issuer,(long long)coin->mgw.issuerbits,coin->mgw.do_opreturn,coin->mgw.oldtx_format);
    if ( strcmp(coin->name,"NXT") != 0 )
    {
        extract_userpass(coin->serverport,coin->userpass,coinstr,SUPERNET.userhome,path,conf);
        set_atomickeys(coin);
        printf("COIN.%s serverport.(%s) userpass.(%s) %s/%s %s/%s\n",coin->name,coin->serverport,coin->userpass,coin->atomicrecv,coin->atomicrecvpubkey,coin->atomicsend,coin->atomicsendpubkey);
    }
    COINS.LIST = realloc(COINS.LIST,(COINS.num+1) * sizeof(*coin));
    COINS.LIST[COINS.num] = coin, COINS.num++;
    //ensure_packedptrs(coin);
    return(coin);
}