uint64_t InstantDEX_name(char *key,int32_t *keysizep,char *exchange,char *name,char *base,uint64_t *baseidp,char *rel,uint64_t *relidp) { uint64_t baseid,relid,assetbits = 0; char *s,*str; baseid = *baseidp, relid = *relidp; //printf(">>>>>> name.(%s) (%s/%s) %llu/%llu\n",name,base,rel,(long long)baseid,(long long)relid); if ( strcmp(base,"5527630") == 0 || baseid == 5527630 ) strcpy(base,"NXT"); if ( strcmp(rel,"5527630") == 0 || relid == 5527630 ) strcpy(rel,"NXT"); if ( relid == 0 && rel[0] != 0 ) { if ( is_decimalstr(rel) != 0 ) relid = calc_nxt64bits(rel); else relid = is_MGWcoin(rel); } else if ( (str= is_MGWasset(0,relid)) != 0 ) strcpy(rel,str); if ( baseid == 0 && base[0] != 0 ) { if ( is_decimalstr(base) != 0 ) baseid = calc_nxt64bits(base); else baseid = is_MGWcoin(base); } else if ( (str= is_MGWasset(0,baseid)) != 0 ) strcpy(base,str); if ( strcmp("InstantDEX",exchange) == 0 || strcmp("nxtae",exchange) == 0 || strcmp("unconf",exchange) == 0 || (baseid != 0 && relid != 0) ) { if ( strcmp(rel,"NXT") == 0 ) s = "+", relid = stringbits("NXT"), strcpy(rel,"NXT"); else if ( strcmp(base,"NXT") == 0 ) s = "-", baseid = stringbits("NXT"), strcpy(base,"NXT"); else s = ""; if ( base[0] == 0 ) { get_assetname(base,baseid); //printf("mapped %llu -> (%s)\n",(long long)baseid,base); } if ( rel[0] == 0 ) { get_assetname(rel,relid); //printf("mapped %llu -> (%s)\n",(long long)relid,rel); } if ( name[0] == 0 ) { if ( relid == NXT_ASSETID ) sprintf(name,"%llu",(long long)baseid); else if ( baseid == NXT_ASSETID ) sprintf(name,"-%llu",(long long)relid); else sprintf(name,"%llu/%llu",(long long)baseid,(long long)relid); } } else { if ( base[0] != 0 && rel[0] != 0 && baseid == 0 && relid == 0 ) { baseid = peggy_basebits(base), relid = peggy_basebits(rel); if ( name[0] == 0 && baseid != 0 && relid != 0 ) { strcpy(name,base); // need to be smarter strcat(name,"/"); strcat(name,rel); } } if ( name[0] == 0 || baseid == 0 || relid == 0 || base[0] == 0 || rel[0] == 0 ) { if ( baseid == 0 && base[0] != 0 ) baseid = stringbits(base); else if ( baseid != 0 && base[0] == 0 ) sprintf(base,"%llu",(long long)baseid); if ( relid == 0 && rel[0] != 0 ) { relid = stringbits(rel); printf("set relid.%llu <- (%s)\n",(long long)relid,rel); } else if ( relid != 0 && rel[0] == 0 ) sprintf(rel,"%llu",(long long)relid); if ( name[0] == 0 ) strcpy(name,base), strcat(name,"/"), strcat(name,rel); } } *baseidp = baseid, *relidp = relid; *keysizep = prices777_key(key,exchange,name,base,baseid,rel,relid); //printf("<<<<<<< name.(%s) (%s/%s) %llu/%llu\n",name,base,rel,(long long)baseid,(long long)relid); return(assetbits); }
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); }