/****************************************************************************** * Copyright © 2014-2017 The SuperNET Developers. * * * * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * * the top-level directory of this distribution for the individual copyright * * holder information and the developer policies on copyright and licensing. * * * * Unless otherwise agreed in a custom licensing agreement, no part of the * * SuperNET software, including this file may be copied, modified, propagated * * or distributed except according to the terms contained in the LICENSE file * * * * Removal or modification of this copyright notice is prohibited. * * * ******************************************************************************/ // // LP_coins.c // marketmaker // char *portstrs[][2] = { { "BTC", "8332" }, { "KMD", "7771" } }; uint16_t LP_rpcport(char *symbol) { int32_t i; for (i=0; isymbol); if ( coin->inactive != 0 ) jaddstr(item,"status","inactive"); else jaddstr(item,"status","active"); if ( coin->isPoS != 0 ) jaddstr(item,"type","PoS"); jaddstr(item,"smartaddress",coin->smartaddr); jaddstr(item,"rpc",coin->serverport); jaddnum(item,"pubtype",coin->pubtype); jaddnum(item,"p2shtype",coin->p2shtype); jaddnum(item,"wiftype",coin->wiftype); jaddnum(item,"estimatedrate",coin->estimatedrate); jaddnum(item,"txfee",coin->txfee); return(item); } cJSON *LP_coinsjson() { struct iguana_info *coin,*tmp; cJSON *array = cJSON_CreateArray(); HASH_ITER(hh,LP_coins,coin,tmp) { jaddi(array,LP_coinjson(coin)); } return(array); } struct iguana_info *LP_coinsearch(char *symbol) { struct iguana_info *coin; portable_mutex_lock(&LP_coinmutex); HASH_FIND(hh,LP_coins,symbol,strlen(symbol),coin); portable_mutex_unlock(&LP_coinmutex); return(coin); } struct iguana_info *LP_coinadd(struct iguana_info *cdata) { struct iguana_info *coin = calloc(1,sizeof(*coin)); //printf("%s: (%s) (%s)\n",symbol,cdata.serverport,cdata.userpass); *coin = *cdata; portable_mutex_init(&coin->txmutex); portable_mutex_lock(&LP_coinmutex); HASH_ADD_KEYPTR(hh,LP_coins,coin->symbol,strlen(coin->symbol),coin); portable_mutex_unlock(&LP_coinmutex); return(coin); } int32_t LP_coininit(struct iguana_info *coin,char *symbol,char *name,char *assetname,int32_t isPoS,uint16_t port,uint8_t pubtype,uint8_t p2shtype,uint8_t wiftype,uint64_t txfee,double estimatedrate,int32_t longestchain,uint8_t taddr) { char *name2; memset(coin,0,sizeof(*coin)); safecopy(coin->symbol,symbol,sizeof(coin->symbol)); sprintf(coin->serverport,"127.0.0.1:%u",port); coin->isPoS = isPoS; coin->taddr = taddr; coin->longestchain = longestchain; coin->txfee = txfee; coin->estimatedrate = estimatedrate; coin->pubtype = pubtype; coin->p2shtype = p2shtype; coin->wiftype = wiftype; coin->inactive = (uint32_t)time(NULL); if ( strcmp(symbol,"KMD") == 0 || (assetname != 0 && assetname[0] != 0) ) name2 = 0; else name2 = name; return(LP_userpass(coin->userpass,symbol,assetname,name,name2)); } int32_t LP_isdisabled(char *base,char *rel) { struct iguana_info *coin; if ( base != 0 && (coin= LP_coinsearch(base)) != 0 && coin->inactive != 0 ) return(1); else if ( rel != 0 && (coin= LP_coinsearch(rel)) != 0 && coin->inactive != 0 ) return(1); else return(0); } struct iguana_info *LP_coinfind(char *symbol) { struct iguana_info *coin,cdata; int32_t isPoS,longestchain = 1; uint16_t port; uint64_t txfee; double estimatedrate; uint8_t pubtype,p2shtype,wiftype; char *name,*assetname; if ( (coin= LP_coinsearch(symbol)) != 0 ) return(coin); if ( (port= LP_rpcport(symbol)) == 0 ) return(0); isPoS = 0; txfee = 10000; estimatedrate = 20; pubtype = 60; p2shtype = 85; wiftype = 188; assetname = ""; if ( strcmp(symbol,"BTC") == 0 ) { txfee = 50000; estimatedrate = 300; pubtype = 0; p2shtype = 5; wiftype = 128; name = "bitcoin"; } else if ( strcmp(symbol,"KMD") == 0 ) name = "komodo"; else return(0); if ( LP_coininit(&cdata,symbol,name,assetname,isPoS,port,pubtype,p2shtype,wiftype,txfee,estimatedrate,longestchain,0) > 0 ) { if ( (coin= LP_coinadd(&cdata)) != 0 ) { if ( strcmp(symbol,"KMD") == 0 ) coin->inactive = 0; else if ( strcmp(symbol,"BTC") == 0 ) { coin->inactive = !IAMLP * (uint32_t)time(NULL); printf("BTC inactive.%u\n",coin->inactive); } } } return(coin); } // "coins":[{"coin":"", "rpcport":pppp}, {"coin":"LTC", "name":"litecoin", "rpcport":9332, "pubtype":48, "p2shtype":5, "wiftype":176, "txfee":100000 }] // {"coin":"HUSH", "name":"hush", "rpcport":8822, "taddr":28, "pubtype":184, "p2shtype":189, "wiftype":128, "txfee":10000 } struct iguana_info *LP_coincreate(cJSON *item) { struct iguana_info cdata,*coin=0; int32_t isPoS,longestchain = 1; uint16_t port; uint64_t txfee; double estimatedrate; uint8_t pubtype,p2shtype,wiftype; char *name=0,*symbol,*assetname=0; if ( (symbol= jstr(item,"coin")) != 0 && symbol[0] != 0 && strlen(symbol) < 16 && LP_coinfind(symbol) == 0 && (port= juint(item,"rpcport")) != 0 ) { isPoS = jint(item,"isPoS"); if ( (txfee= j64bits(item,"txfee")) == 0 ) txfee = 10000; if ( (estimatedrate= jdouble(item,"estimatedrate")) == 0. ) estimatedrate = 20; if ( (pubtype= juint(item,"pubtype")) == 0 ) pubtype = 60; if ( (p2shtype= juint(item,"p2shtype")) == 0 ) p2shtype = 85; if ( (wiftype= juint(item,"wiftype")) == 0 ) wiftype = 188; if ( (assetname= jstr(item,"asset")) != 0 ) name = assetname; else if ( (name= jstr(item,"name")) == 0 ) name = symbol; if ( LP_coininit(&cdata,symbol,name,assetname==0?"":assetname,isPoS,port,pubtype,p2shtype,wiftype,txfee,estimatedrate,longestchain,jint(item,"taddr")) < 0 ) { coin = LP_coinadd(&cdata); coin->inactive = (uint32_t)time(NULL); } else coin = LP_coinadd(&cdata); } if ( coin != 0 && item != 0 ) { if ( strcmp("KMD",coin->symbol) != 0 ) { if ( jobj(item,"active") != 0 ) coin->inactive = !jint(item,"active"); else { if ( IAMLP == 0 || assetname != name ) coin->inactive = (uint32_t)time(NULL); else coin->inactive = 0; } } else coin->inactive = 0; } if ( coin != 0 && coin->inactive != 0 ) printf("LPnode.%d %s inactive.%u %p vs %p\n",IAMLP,coin->symbol,coin->inactive,assetname,name); return(0); }