Browse Source

Merge pull request #13 from jl777/dev

dev update
win-cross^2
ca333 8 years ago
committed by GitHub
parent
commit
8d6ce5303e
  1. 2
      .gitignore
  2. 2
      iguana/dPoW.h
  3. 17
      iguana/dpow/dpow_network.c
  4. 34
      iguana/dpow/dpow_prices.c
  5. 2
      iguana/exchanges/LP_bitcoin.c
  6. 30
      iguana/exchanges/LP_commands.c
  7. 11
      iguana/exchanges/LP_include.h
  8. 5
      iguana/exchanges/LP_nativeDEX.c
  9. 24
      iguana/exchanges/LP_ordermatch.c
  10. 4
      iguana/exchanges/LP_rpc.c
  11. 429
      iguana/exchanges/LP_scan.c
  12. 44
      iguana/exchanges/LP_utxos.c
  13. 11
      iguana/exchanges/balance_loop
  14. 2
      iguana/exchanges/coins
  15. 2
      iguana/exchanges/dividends
  16. 2
      iguana/exchanges/install
  17. 6
      iguana/exchanges/mm.c
  18. 5
      iguana/exchanges/secretaddresses
  19. 2
      iguana/exchanges/snapshot
  20. 4
      iguana/exchanges/snapshot_balance
  21. 11
      iguana/exchanges/snapshot_loop
  22. 3
      iguana/exchanges/userpass
  23. 3
      iguana/iguana_exchanges.c
  24. 4
      iguana/iguana_msg.c
  25. 4
      iguana/iguana_notary.c
  26. 1
      iguana/iguana_peers.c
  27. 32
      iguana/iguana_ramchain.c
  28. 1
      iguana/iguana_rpc.c
  29. 2
      iguana/tests/rawtx2

2
.gitignore

@ -484,3 +484,5 @@ iguana/client
iguana/marketmaker.dSYM/Contents/Resources/DWARF/marketmaker
iguana/confs/97f18454bb61e9eb7a827cfbefe42fbf7ae2832dc74c4812bdaef8bcf5c10474
iguana/DB/PRICES/.tmpmarker

2
iguana/dPoW.h

@ -137,7 +137,7 @@ struct dpow_info
int32_t lastheight,maxblocks,SRCHEIGHT,SHORTFLAG,ratifying;
struct pax_transaction *PAX;
portable_mutex_t paxmutex,dexmutex;
uint32_t ipbits[64],numipbits;
uint32_t ipbits[128],numipbits;
struct dpow_block **blocks;
};
uint64_t dpow_notarybestk(uint64_t refmask,struct dpow_block *bp,int8_t *lastkp);

17
iguana/dpow/dpow_network.c

@ -561,7 +561,7 @@ void dex_channelsend(struct supernet_info *myinfo,bits256 srchash,bits256 destha
void dpow_randipbits(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *retjson)
{
int32_t m; uint32_t ipbits; char *coinstr;
int32_t m; uint32_t ipbits; char *coinstr; cJSON *infojson;
if ( is_cJSON_Array(retjson) == 0 )
{
if ( (m= myinfo->numdpowipbits) > 0 )
@ -572,6 +572,11 @@ void dpow_randipbits(struct supernet_info *myinfo,struct iguana_info *coin,cJSON
}
if ( (coinstr= jstr(retjson,"coin")) == 0 )
jaddstr(retjson,"coin",coin->symbol);
if ( (infojson= dpow_getinfo(myinfo,coin)) != 0 )
{
jaddnum(retjson,"notaryheight",juint(infojson,"blocks"));
free_json(infojson);
}
}
}
@ -1318,7 +1323,7 @@ struct dpow_nanomsghdr
{
bits256 srchash,desthash;
struct dpow_nanoutxo ratify,notarize;
uint32_t channel,height,size,datalen,crc32,myipbits,numipbits,ipbits[64];
uint32_t channel,height,size,datalen,crc32,myipbits,numipbits,ipbits[128];
char symbol[16];
uint8_t senderind,version0,version1,packet[];
} PACKED;
@ -2026,10 +2031,10 @@ void dpow_send(struct supernet_info *myinfo,struct dpow_info *dp,struct dpow_blo
printf("%d NANOSEND.%d ht.%d channel.%08x (%d) pax.%08x datalen.%d (%d %llx) (%d %llx) recv.%llx\n",i,sentbytes,np->height,np->channel,size,np->notarize.paxwdcrc,datalen,(int8_t)np->notarize.bestk,(long long)np->notarize.bestmask,bp->notaries[bp->myind].bestk,(long long)bp->notaries[bp->myind].bestmask,(long long)bp->recvmask);
}
void dpow_ipbitsadd(struct supernet_info *myinfo,struct dpow_info *dp,uint32_t *ipbits,int32_t numipbits,int32_t fromid,uint32_t senderipbits)
void dpow_ipbitsadd(struct supernet_info *myinfo,struct dpow_info *dp,uint32_t *ipbits,int32_t numipbits,int32_t maxipbits,int32_t fromid,uint32_t senderipbits)
{
int32_t i,j,matched,missing,n; char ipaddr[64];
if ( numipbits >= 64 )
if ( numipbits >= maxipbits )
{
static int32_t counter;
if ( counter++ < 100 )
@ -2088,7 +2093,7 @@ int32_t dpow_nanomsg_update(struct supernet_info *myinfo)
if ( (flags & 1) == 0 && (size= signed_nn_recv(&freeptr,myinfo,myinfo->notaries,myinfo->numnotaries,myinfo->dpowsock,&np)) > 0 )
{
num++;
if ( size > 0 )
if ( size >= sizeof(*np) )
{
//fprintf(stderr,"%d ",size);
if ( np->version0 == (DPOW_VERSION & 0xff) && np->version1 == ((DPOW_VERSION >> 8) & 0xff) )
@ -2112,7 +2117,7 @@ int32_t dpow_nanomsg_update(struct supernet_info *myinfo)
printf("received nnpacket for (%s)\n",np->symbol);
else
{
dpow_ipbitsadd(myinfo,dp,np->ipbits,np->numipbits,np->senderind,np->myipbits);
dpow_ipbitsadd(myinfo,dp,np->ipbits,np->numipbits,sizeof(np->ipbits)/sizeof(*np->ipbits),np->senderind,np->myipbits);
if ( (bp= dpow_heightfind(myinfo,dp,np->height)) != 0 && bp->state != 0xffffffff && bp->myind >= 0 )
{
//char str[65]; printf("%s RECV ht.%d ch.%08x (%d) crc32.%08x:%08x datalen.%d:%d firstz.%d i.%d senderind.%d myind.%d\n",bits256_str(str,np->srchash),np->height,np->channel,size,np->crc32,crc32,np->datalen,(int32_t)(size - sizeof(*np)),firstz,i,np->senderind,bp->myind);

34
iguana/dpow/dpow_prices.c

@ -1438,7 +1438,7 @@ void PAX_update(struct PAX_data *dp,double *btcusdp,double *kmdbtcp)
*kmdbtcp = 0;
bitcoinave = 0;//url_json("https://api.bitcoinaverage.com/ticker/USD/");
//bitcoincharts = url_json("http://api.bitcoincharts.com/v1/weighted_prices.json");
blockchaininfo = 0;//url_json("https://blockchain.info/ticker");
blockchaininfo = url_json("https://blockchain.info/ticker");
coindesk = 0;//url_json("http://api.coindesk.com/v1/bpi/historical/close.json");
sprintf(url,"https://poloniex.com/public?command=returnChartData&currencyPair=BTC_KMD&start=%ld&end=9999999999&period=86400",(long)(time(NULL)-3600*24));
sprintf(url2,"https://poloniex.com/public?command=returnChartData&currencyPair=BTC_BTCD&start=%ld&end=9999999999&period=86400",(long)(time(NULL)-3600*24));
@ -1541,7 +1541,7 @@ void PAX_update(struct PAX_data *dp,double *btcusdp,double *kmdbtcp)
if ( (item= jobj(blockchaininfo,"USD")) != 0 && item != 0 && (price= jdouble(item,"15m")) > SMALLVAL )
{
dpow_price("blockchain.info","BTCUSD",price,price);
//printf("blockchaininfo %f %f\n",btcusd,price);
printf("blockchaininfo %f %f\n",btcusd,price);
dxblend(&btcusd,price,0.5);
}
free_json(blockchaininfo);
@ -1832,13 +1832,16 @@ void PAX_genecbsplines(struct PAX_data *dp)
portable_mutex_unlock(&mutex);
}
#define BTCFACTOR_TIMESTAMP 1503746319
#define BTCFACTOR_HEIGHT 466266
int32_t PAX_idle(struct supernet_info *myinfo)//struct PAX_data *argdp,int32_t idlegap)
{
static double lastupdate,lastdayupdate; static int32_t didinit; static char *userhome; int32_t idlegap = 10;
static double lastupdate,lastdayupdate; static uint32_t didinit; static char *userhome; int32_t idlegap = 10;
FILE *fp; long filesize; char fname[512]; double splineval; uint32_t pvals[128],timestamp; int32_t i,datenum,seconds,c; struct tai t; struct PAX_data *dp; uint8_t data[512];
if ( Currencymasks[0] == 0 )
return(0);
if ( didinit == 0 )
if ( time(NULL) > didinit+12*3600 )
{
if ( (userhome= OS_filestr(&filesize,"userhome.txt")) == 0 )
userhome = "root";
@ -1849,15 +1852,15 @@ int32_t PAX_idle(struct supernet_info *myinfo)//struct PAX_data *argdp,int32_t i
userhome[strlen(userhome)-1] = 0;
}
}
myinfo->PAXDATA = calloc(1,sizeof(*dp));
didinit = 1;
if ( myinfo->PAXDATA == 0 )
myinfo->PAXDATA = calloc(1,sizeof(*dp));
dp = myinfo->PAXDATA;
PAX_genecbsplines(dp);
printf("generated splines\n");
datenum = OS_conv_unixtime(&t,&seconds,(uint32_t)time(NULL));
didinit = (uint32_t)time(NULL);
datenum = OS_conv_unixtime(&t,&seconds,didinit);
expand_datenum(dp->edate,datenum);
}
dp = myinfo->PAXDATA;
/*if ( 0 && time(NULL) > dp->lastupdate+10 )
{
@ -1904,8 +1907,9 @@ int32_t PAX_idle(struct supernet_info *myinfo)//struct PAX_data *argdp,int32_t i
PAX_emitprices(pvals,dp);
}
timestamp = (uint32_t)time(NULL);
int32_t dispflag = ((rand() % 64) == 0);
if ( dp->kmdbtc == 0 || dispflag != 0 )
int32_t dispflag = ((rand() % 6) == 0);
//printf("PAX_IDLE.%d %.8f %.8f\n",dispflag,dp->kmdbtc,dp->btcusd);
if ( dp->kmdbtc == 0 || dp->btcusd == 0 || dispflag != 0 )
{
PAX_update(dp,&dp->btcusd,&dp->kmdbtc);
for (i=0; i<MAX_CURRENCIES; i++)
@ -1920,10 +1924,12 @@ int32_t PAX_idle(struct supernet_info *myinfo)//struct PAX_data *argdp,int32_t i
pvals[1] = timestamp;
pvals[2] = MAX_CURRENCIES + 3;
pvals[3] = PAX_val32(dp->kmdbtc * 1000);
pvals[4] = PAX_val32(dp->btcusd * .001);
double btcfactor;
//if ( time(NULL) > BTCFACTOR_TIMESTAMP )
btcfactor = .00001;
//else btcfactor = .001;
pvals[4] = PAX_val32(dp->btcusd * btcfactor);
pvals[5] = PAX_val32(dp->CNYUSD);
if ( dispflag != 0 )
printf("KMD %.8f BTC %f CNY %f (%f)\n",dp->kmdbtc,dp->btcusd,dp->CNYUSD,1./dp->CNYUSD);
sprintf(fname,"/%s/.komodo/komodofeed",userhome);
if ( (fp= fopen(fname,"wb")) != 0 )
{
@ -1939,7 +1945,7 @@ int32_t PAX_idle(struct supernet_info *myinfo)//struct PAX_data *argdp,int32_t i
{
for (i=0; i<6; i++)
printf("%u ",pvals[i]);
printf("pvals -> %s\n",fname);
printf("KMD %.8f BTC %f CNY %f (%f) btcusd pval.%u\n",dp->kmdbtc,dp->btcusd,dp->CNYUSD,1./dp->CNYUSD,pvals[4]);
}
}
}

2
iguana/exchanges/LP_bitcoin.c

@ -2025,7 +2025,7 @@ int32_t bitcoin_p2shscript(uint8_t *script,int32_t n,const uint8_t *p2shscript,c
char *bitcoind_passthru(char *coinstr,char *serverport,char *userpass,char *method,char *params)
{
return(bitcoind_RPC(0,coinstr,serverport,userpass,method,params,2));
return(bitcoind_RPC(0,coinstr,serverport,userpass,method,params,4));
}
char *bitcoind_passthrut(char *coinstr,char *serverport,char *userpass,char *method,char *params,int32_t timeout)

30
iguana/exchanges/LP_commands.c

@ -120,7 +120,10 @@ getprices(base, rel)\n\
sendmessage(base=coin, rel="", pubkey=zero, <argjson method2>)\n\
getmessages(firsti=0, num=100)\n\
clearmessages(firsti=0, num=100)\n\
trust(pubkey, trust)\n\
secretaddresses(passphrase, num=10, pubtype=60, taddr=0)\n\
snapshot(coin, height)\n\
snapshot_balance(coin, height, addresses[])\n\
dividends(coin, height, <args>)\n\
\"}"));
base = jstr(argjson,"base");
@ -163,6 +166,13 @@ trust(pubkey, trust)\n\
{
return(LP_portfolio());
}
else if ( strcmp(method,"secretaddresses") == 0 )
{
uint8_t taddr,pubtype;
pubtype = (jobj(argjson,"pubtype") == 0) ? 60 : juint(argjson,"pubtype");
taddr = (jobj(argjson,"taddr") == 0) ? 0 : juint(argjson,"taddr");
return(LP_secretaddresses(ctx,jstr(argjson,"passphrase"),juint(argjson,"num"),taddr,pubtype));
}
if ( base != 0 && rel != 0 )
{
double price,bid,ask;
@ -246,6 +256,24 @@ trust(pubkey, trust)\n\
ptr->inactive = (uint32_t)time(NULL);
return(jprint(LP_coinsjson(0),1));
}
else if ( strcmp(method,"snapshot") == 0 )
{
if ( (ptr= LP_coinsearch(coin)) != 0 )
return(jprint(LP_snapshot(ptr,juint(argjson,"height")),1));
else return(clonestr("{\"error\":\"cant find coind\"}"));
}
else if ( strcmp(method,"dividends") == 0 )
{
if ( (ptr= LP_coinsearch(coin)) != 0 )
return(LP_dividends(ptr,juint(argjson,"height"),argjson));
else return(clonestr("{\"error\":\"cant find coind\"}"));
}
else if ( strcmp(method,"snapshot_balance") == 0 )
{
if ( (ptr= LP_coinsearch(coin)) != 0 )
return(LP_snapshot_balance(ptr,juint(argjson,"height"),argjson));
else return(clonestr("{\"error\":\"cant find coind\"}"));
}
if ( LP_isdisabled(coin,0) != 0 )
return(clonestr("{\"error\":\"coin is disabled\"}"));
if ( strcmp(method,"inventory") == 0 )

11
iguana/exchanges/LP_include.h

@ -166,7 +166,7 @@ struct basilisk_swapinfo
uint8_t userdata_bobrefund[256],userdata_bobrefundlen;
};
struct LP_outpoint { bits256 spendtxid; uint64_t value,interest; int32_t spendvini,spendheight; };
struct LP_outpoint { bits256 spendtxid; uint64_t value,interest; int32_t spendvini,spendheight; char coinaddr[40]; };
struct LP_transaction
{
@ -175,10 +175,17 @@ struct LP_transaction
struct LP_outpoint outpoints[];
};
struct LP_address
{
UT_hash_handle hh;
int64_t balance;
char coinaddr[40];
};
struct iguana_info
{
UT_hash_handle hh;
portable_mutex_t txmutex; struct LP_transaction *transactions;
portable_mutex_t txmutex; struct LP_transaction *transactions; struct LP_address *addresses;
uint64_t txfee;
int32_t longestchain,firstrefht,firstscanht,lastscanht,bussock; uint16_t busport;
uint32_t counter,inactive,lastmempool,lastgetinfo;

5
iguana/exchanges/LP_nativeDEX.c

@ -13,6 +13,7 @@
* Removal or modification of this copyright notice is prohibited. *
* *
******************************************************************************/
//alice only coins GAME UNO BTM ANC: GAME BTCD PPC RDD XZC POT EAC FTC BASH SPR WDC UNO XPM XCN BELA CHC DIME MEC NAUT MED AUR MAX DGC RIC EB3 DOT BTM GEO ANC CANN ICASH WBB SRC PTC ADZ TIPS EQT START EFL FST FJC NYC GCN
//
// LP_nativeDEX.c
@ -392,9 +393,9 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int
}
}
//printf("numutxos vs mine.%d\n",LP_mypeer != 0 ? LP_mypeer->numutxos : -1);
if ( LP_mypeer != 0 && LP_mypeer->numutxos < mostutxos && mostpeer != 0 && time(NULL) > lastresync+180 )
if ( LP_mypeer != 0 && mostpeer != 0 && ((LP_mypeer->numutxos < mostutxos && time(NULL) > lastresync+10) || time(NULL) > lastresync+60) )
{
printf("myutxos.%d most.%d %s\n",LP_mypeer->numutxos,mostutxos,mostpeer->ipaddr);
//printf("myutxos.%d most.%d %s\n",LP_mypeer->numutxos,mostutxos,mostpeer->ipaddr);
LP_peer_utxosquery(LP_mypeer,myport,pubsock,mostpeer,now,60,(mostutxos-LP_mypeer->numutxos) * 2);
lastresync = (uint32_t)time(NULL);
//LP_peer_pricesquery(mostpeer->ipaddr,mostpeer->port);

24
iguana/exchanges/LP_ordermatch.c

@ -606,7 +606,7 @@ struct LP_utxoinfo *LP_bestutxo(double *ordermatchpricep,int64_t *bestsatoshisp,
vout = jint(item,"vout");
vol = jdouble(item,"volume");
metric = price / bestprice;
if ( (butxo= LP_utxofind(1,txid,vout)) != 0 && (long long)(vol*SATOSHIDEN) == butxo->S.satoshis && LP_isavailable(butxo) > 0 && LP_ismine(butxo) == 0 )//&& butxo->T.bestflag == 0 )
if ( (butxo= LP_utxofind(1,txid,vout)) != 0 && (long long)(vol*SATOSHIDEN) == butxo->S.satoshis && LP_isavailable(butxo) > 0 && LP_ismine(butxo) == 0 && butxo->T.bestflag == 0 )
{
if ( LP_iseligible(&val,&val2,butxo->iambob,butxo->coin,butxo->payment.txid,butxo->payment.vout,butxo->S.satoshis,butxo->deposit.txid,butxo->deposit.vout) > 0 )
{
@ -662,6 +662,27 @@ struct LP_utxoinfo *LP_bestutxo(double *ordermatchpricep,int64_t *bestsatoshisp,
break;
}
}
if ( bestutxo == 0 )
{
int32_t numrestraints;
for (i=numrestraints=0; i<numasks; i++)
{
item = jitem(asks,i);
pubkey = jbits256(item,"pubkey");
if ( bits256_cmp(pubkey,LP_mypub25519) != 0 && (pubp= LP_pubkeyadd(pubkey)) != 0 )
{
txid = jbits256(item,"txid");
vout = jint(item,"vout");
if ( (butxo= LP_utxofind(1,txid,vout)) != 0 )
{
numrestraints++;
butxo->T.bestflag = 0;
pubp->numerrors = 0;
}
}
}
printf("no bob utxo found -> cleared %d restraints\n",numrestraints);
}
}
free_json(orderbook);
}
@ -669,6 +690,7 @@ struct LP_utxoinfo *LP_bestutxo(double *ordermatchpricep,int64_t *bestsatoshisp,
}
if ( bestutxo == 0 || *ordermatchpricep == 0. || *bestdestsatoshisp == 0 )
return(0);
bestutxo->T.bestflag = 1;
int32_t changed;
LP_mypriceset(&changed,autxo->coin,base,1. / *ordermatchpricep);
return(bestutxo);

4
iguana/exchanges/LP_rpc.c

@ -118,7 +118,7 @@ cJSON *bitcoin_json(struct iguana_info *coin,char *method,char *params)
retjson = cJSON_Parse(retstr);
free(retstr);
}
//usleep(1000);
//usleep(100);
//printf("dpow_gettxout.(%s)\n",retstr);
} else retjson = cJSON_Parse("{\"result\":\"disabled\"}");
} else printf("bitcoin_json cant talk to NULL coin\n");
@ -397,7 +397,7 @@ cJSON *LP_blockjson(int32_t *heightp,char *symbol,char *blockhashstr,int32_t hei
*heightp = juint(json,"height");
if ( height >= 0 && *heightp != height )
{
printf("unexpected height %d vs %d\n",*heightp,height);
printf("unexpected height %d vs %d for %s (%s)\n",*heightp,height,blockhashstr,jprint(json,0));
*heightp = -1;
free_json(json);
json = 0;

429
iguana/exchanges/LP_scan.c

@ -18,6 +18,31 @@
// marketmaker
//
struct LP_address *_LP_addressfind(struct iguana_info *coin,char *coinaddr)
{
struct LP_address *ap;
HASH_FIND(hh,coin->addresses,coinaddr,strlen(coinaddr),ap);
return(ap);
}
struct LP_address *_LP_addressadd(struct iguana_info *coin,char *coinaddr)
{
struct LP_address *ap;
ap = calloc(1,sizeof(*ap));
safecopy(ap->coinaddr,coinaddr,sizeof(ap->coinaddr));
HASH_ADD_KEYPTR(hh,coin->addresses,ap->coinaddr,strlen(ap->coinaddr),ap);
return(ap);
}
struct LP_address *_LP_address(struct iguana_info *coin,char *coinaddr)
{
struct LP_address *ap;
if ( (ap= _LP_addressfind(coin,coinaddr)) == 0 )
ap = _LP_addressadd(coin,coinaddr);
return(ap);
}
struct LP_transaction *LP_transactionfind(struct iguana_info *coin,bits256 txid)
{
struct LP_transaction *tx;
@ -121,21 +146,22 @@ uint64_t LP_txinterestvalue(uint64_t *interestp,char *destaddr,struct iguana_inf
} else printf("LP_txinterestvalue no addresses found?\n");
//char str[65]; printf("%s %.8f <- %s.(%s) txobj.(%s)\n",destaddr,dstr(value),coin->symbol,bits256_str(str,txid),jprint(txobj,0));
free_json(txobj);
} else { char str[65]; printf("null gettxout return %s/v%d\n",bits256_str(str,txid),vout); }
} //else { char str[65]; printf("null gettxout return %s/v%d\n",bits256_str(str,txid),vout); }
return(value);
}
int32_t LP_transactioninit(struct iguana_info *coin,bits256 txid)
int32_t LP_transactioninit(struct iguana_info *coin,bits256 txid,int32_t iter)
{
struct LP_transaction *tx; int32_t i,height,numvouts,numvins,spentvout; uint32_t timestamp,blocktime; cJSON *txobj,*vins,*vouts,*vout,*vin; bits256 spenttxid; char str[65];
struct LP_transaction *tx; char *address; int32_t i,n,height,numvouts,numvins,spentvout; uint32_t timestamp,blocktime; cJSON *txobj,*vins,*vouts,*vout,*vin,*sobj,*addresses; bits256 spenttxid; char str[65];
if ( (txobj= LP_gettx(coin->symbol,txid)) != 0 )
{
//printf("TX.(%s)\n",jprint(txobj,0));
height = LP_txheight(&timestamp,&blocktime,coin,txid);
if ( timestamp == 0 && height > 0 )
timestamp = blocktime;
vins = jarray(&numvins,txobj,"vin");
vouts = jarray(&numvouts,txobj,"vout");
if ( vouts != 0 && (tx= LP_transactionadd(coin,txid,height,numvouts,numvins,timestamp)) != 0 )
if ( iter == 0 && vouts != 0 && (tx= LP_transactionadd(coin,txid,height,numvouts,numvins,timestamp)) != 0 )
{
for (i=0; i<numvouts; i++)
{
@ -143,15 +169,32 @@ int32_t LP_transactioninit(struct iguana_info *coin,bits256 txid)
if ( (tx->outpoints[i].value= SATOSHIDEN * jdouble(vout,"value")) == 0 )
tx->outpoints[i].value = SATOSHIDEN * jdouble(vout,"amount");
tx->outpoints[i].interest = SATOSHIDEN * jdouble(vout,"interest");
if ( (sobj= jobj(vout,"scriptPubKey")) != 0 )
{
if ( (addresses= jarray(&n,sobj,"addresses")) != 0 && n > 0 )
{
if ( n > 1 )
printf("LP_transactioninit: txid.(%s) multiple addresses.[%s]\n",bits256_str(str,txid),jprint(addresses,0));
if ( (address= jstri(addresses,0)) != 0 && strlen(address) < sizeof(tx->outpoints[i].coinaddr) )
{
strcpy(tx->outpoints[i].coinaddr,address);
} else if ( tx->outpoints[i].value != 0 )
printf("LP_transactioninit: unexpected address.(%s)\n",jprint(addresses,0));
}
//else if ( tx->outpoints[i].value != 0 )
// printf("LP_transactioninit: pax tx ht.%d i.%d (%s) n.%d\n",height,i,jprint(vout,0),n);
}
}
}
if ( vins != 0 )
if ( iter == 1 && vins != 0 )
{
for (i=0; i<numvins; i++)
{
vin = jitem(vins,i);
spenttxid = jbits256(vin,"txid");
spentvout = jint(vin,"vout");
if ( i == 0 && bits256_nonz(spenttxid) == 0 )
continue;
if ( (tx= LP_transactionfind(coin,spenttxid)) != 0 )
{
if ( spentvout < tx->numvouts )
@ -160,23 +203,26 @@ int32_t LP_transactioninit(struct iguana_info *coin,bits256 txid)
tx->outpoints[spentvout].spendvini = i;
tx->outpoints[spentvout].spendheight = height;
//printf("spend %s %s/v%d at ht.%d\n",coin->symbol,bits256_str(str,tx->txid),spentvout,height);
} else printf("LP_transactioninint: %s spentvout.%d < numvouts.%d\n",bits256_str(str,spenttxid),spentvout,tx->numvouts);
}
} else printf("LP_transactioninit: %s spentvout.%d < numvouts.%d\n",bits256_str(str,spenttxid),spentvout,tx->numvouts);
} //else printf("LP_transactioninit: couldnt find (%s) ht.%d %s\n",bits256_str(str,spenttxid),height,jprint(vin,0));
if ( bits256_cmp(spenttxid,txid) == 0 )
printf("spending same tx's %p vout ht.%d %s.[%d] s%d\n",tx,height,bits256_str(str,txid),tx!=0?tx->numvouts:0,spentvout);
}
}
free_json(txobj);
return(0);
} else printf("LP_transactioninit error for %s %s\n",coin->symbol,bits256_str(str,txid));
} //else printf("LP_transactioninit error for %s %s\n",coin->symbol,bits256_str(str,txid));
return(-1);
}
int32_t LP_blockinit(struct iguana_info *coin,int32_t height)
{
int32_t i,numtx,checkht=-1; cJSON *blockobj,*txs; bits256 txid; struct LP_transaction *tx;
if ( (blockobj= LP_blockjson(&checkht,coin->symbol,0,height)) != 0 )
int32_t i,j,iter,numtx,checkht=-1; cJSON *blockobj,*txs; bits256 txid; struct LP_transaction *tx;
if ( (blockobj= LP_blockjson(&checkht,coin->symbol,0,height)) != 0 && checkht == height )
{
if ( (txs= jarray(&numtx,blockobj,"tx")) != 0 )
{
for (iter=0; iter<2; iter++)
for (i=0; i<numtx; i++)
{
txid = jbits256i(txs,i);
@ -189,7 +235,25 @@ int32_t LP_blockinit(struct iguana_info *coin,int32_t height)
printf("LP_blockinit: tx->height %d != %d\n",tx->height,height);
tx->height = height;
}
} else LP_transactioninit(coin,txid);
if ( iter == 1 )
for (j=0; j<10; j++)
{
if (LP_transactioninit(coin,txid,iter) == 0 )
break;
printf("transaction ht.%d init error.%d, pause\n",height,j);
sleep(1);
}
}
else
{
for (j=0; j<10; j++)
{
if (LP_transactioninit(coin,txid,iter) == 0 )
break;
printf("transaction ht.%d init error.%d, pause\n",height,j);
sleep(1);
}
}
}
}
free_json(blockobj);
@ -199,6 +263,339 @@ int32_t LP_blockinit(struct iguana_info *coin,int32_t height)
else return(-1);
}
int32_t LP_scanblockchain(struct iguana_info *coin,int32_t startheight,int32_t endheight)
{
int32_t ht,n = 0;
for (ht=startheight; ht<=endheight; ht++)
{
if ( LP_blockinit(coin,ht) < 0 )
{
printf("error loading block.%d of (%d, %d)\n",ht,startheight,endheight);
return(ht-1);
}
n++;
if ( (n % 1000) == 0 )
fprintf(stderr,"%.1f%% ",100. * (double)n/(endheight-startheight+1));
}
return(endheight);
}
char *banned_txids[] =
{
"78cb4e21245c26b015b888b14c4f5096e18137d2741a6de9734d62b07014dfca", //233559
"00697be658e05561febdee1aafe368b821ca33fbb89b7027365e3d77b5dfede5", //234172
"e909465788b32047c472d73e882d79a92b0d550f90be008f76e1edaee6d742ea", //234187
"f56c6873748a327d0b92b8108f8ec8505a2843a541b1926022883678fb24f9dc", //234188
"abf08be07d8f5b3a433ddcca7ef539e79a3571632efd6d0294ec0492442a0204", //234213
"3b854b996cc982fba8c06e76cf507ae7eed52ab92663f4c0d7d10b3ed879c3b0", //234367
"fa9e474c2cda3cb4127881a40eb3f682feaba3f3328307d518589024a6032cc4", //234635
"ca746fa13e0113c4c0969937ea2c66de036d20274efad4ce114f6b699f1bc0f3", //234662
"43ce88438de4973f21b1388ffe66e68fda592da38c6ef939be10bb1b86387041", //234697
"0aeb748de82f209cd5ff7d3a06f65543904c4c17387c9d87c65fd44b14ad8f8c", //234899
"bbd3a3d9b14730991e1066bd7c626ca270acac4127131afe25f877a5a886eb25", //235252
"fa9943525f2e6c32cbc243294b08187e314d83a2870830180380c3c12a9fd33c", //235253
"a01671c8775328a41304e31a6693bbd35e9acbab28ab117f729eaba9cb769461", //235265
"2ef49d2d27946ad7c5d5e4ab5c089696762ff04e855f8ab48e83bdf0cc68726d", //235295
"c85dcffb16d5a45bd239021ad33443414d60224760f11d535ae2063e5709efee", //235296
// all vouts banned
"c4ea1462c207547cd6fb6a4155ca6d042b22170d29801a465db5c09fec55b19d", //246748
"305dc96d8bc23a69d3db955e03a6a87c1832673470c32fe25473a46cc473c7d1", //247204
};
int32_t komodo_bannedset(int32_t *indallvoutsp,bits256 *array,int32_t max)
{
int32_t i;
if ( sizeof(banned_txids)/sizeof(*banned_txids) > max )
{
fprintf(stderr,"komodo_bannedset: buffer too small %ld vs %d\n",sizeof(banned_txids)/sizeof(*banned_txids),max);
exit(-1);
}
for (i=0; i<sizeof(banned_txids)/sizeof(*banned_txids); i++)
decode_hex(array[i].bytes,sizeof(array[i]),banned_txids[i]);
*indallvoutsp = i-2;
return(i);
}
int sort_balance(void *a,void *b)
{
int64_t aval,bval;
/* compare a to b (cast a and b appropriately)
* return (int) -1 if (a < b)
* return (int) 0 if (a == b)
* return (int) 1 if (a > b)
*/
aval = ((struct LP_address *)a)->balance;
bval = ((struct LP_address *)b)->balance;
//printf("%.8f vs %.8f -> %d\n",dstr(aval),dstr(bval),(int32_t)(bval - aval));
return((aval == bval) ? 0 : ((aval < bval) ? 1 : -1));
}
// a primitive restore can be done by loading the previous snapshot and creating a virtual tx for all the balance at height-1. this wont allow anything but new snapshots, but for many use cases that is all that is needed
cJSON *LP_snapshot(struct iguana_info *coin,int32_t height)
{
static bits256 bannedarray[64]; static int32_t numbanned,indallvouts,maxsnapht; static char lastcoin[16];
struct LP_transaction *tx,*tmp; struct LP_address *ap,*atmp; int32_t isKMD,i,j,n,skipflag=0,startht,endht,ht; uint64_t banned_balance=0,balance=0,noaddr_balance=0; cJSON *retjson,*array,*item;
if ( bannedarray[0].txid == 0 )
numbanned = komodo_bannedset(&indallvouts,bannedarray,(int32_t)(sizeof(bannedarray)/sizeof(*bannedarray)));
startht = 1;
endht = height-1;
if ( strcmp(coin->symbol,lastcoin) == 0 )
{
if ( maxsnapht > height )
skipflag = 1;
else startht = maxsnapht+1;
}
else
{
maxsnapht = 0;
strcpy(lastcoin,coin->symbol);
}
retjson = cJSON_CreateObject();
if ( skipflag == 0 && startht < endht )
{
if ( (ht= LP_scanblockchain(coin,startht,endht)) < endht )
{
if ( ht > maxsnapht )
{
maxsnapht = ht;
printf("maxsnapht.%d for %s\n",maxsnapht,coin->symbol);
}
sleep(10);
if ( (ht= LP_scanblockchain(coin,maxsnapht+1,endht)) < endht )
{
if ( ht > maxsnapht )
{
maxsnapht = ht;
printf("maxsnapht.%d for %s\n",maxsnapht,coin->symbol);
}
jaddstr(retjson,"error","blockchain scan error");
return(retjson);
}
}
if ( ht > maxsnapht )
{
maxsnapht = ht;
printf("maxsnapht.%d for %s\n",maxsnapht,coin->symbol);
}
}
portable_mutex_lock(&coin->txmutex);
HASH_ITER(hh,coin->addresses,ap,atmp)
{
ap->balance = 0;
}
isKMD = (strcmp(coin->symbol,"KMD") == 0) ? 1 : 0;
HASH_ITER(hh,coin->transactions,tx,tmp)
{
if ( tx->height < height )
{
if ( isKMD != 0 )
{
for (j=0; j<numbanned; j++)
if ( bits256_cmp(bannedarray[j],tx->txid) == 0 )
break;
if ( j < numbanned )
{
for (i=0; i<tx->numvouts; i++)
banned_balance += tx->outpoints[i].value;
//char str[256]; printf("skip banned %s bannedtotal: %.8f\n",bits256_str(str,tx->txid),dstr(banned_balance));
continue;
}
}
for (i=0; i<tx->numvouts; i++)
{
if ( (ht=tx->outpoints[i].spendheight) > 0 && ht < height )
continue;
if ( tx->outpoints[i].coinaddr[0] != 0 && (ap= _LP_address(coin,tx->outpoints[i].coinaddr)) != 0 )
{
balance += tx->outpoints[i].value;
ap->balance += tx->outpoints[i].value;
//printf("(%s/%s) %.8f %.8f\n",tx->outpoints[i].coinaddr,ap->coinaddr,dstr(tx->outpoints[i].value),dstr(ap->balance));
} else noaddr_balance += tx->outpoints[i].value;
}
}
}
HASH_SORT(coin->addresses,sort_balance);
portable_mutex_unlock(&coin->txmutex);
printf("%s balance %.8f at height.%d\n",coin->symbol,dstr(balance),height);
array = cJSON_CreateArray();
n = 0;
HASH_ITER(hh,coin->addresses,ap,atmp)
{
if ( ap->balance != 0 )
{
item = cJSON_CreateObject();
jaddnum(item,ap->coinaddr,dstr(ap->balance));
jaddi(array,item);
n++;
}
}
jadd(retjson,"balances",array);
jaddstr(retjson,"coin",coin->symbol);
jaddnum(retjson,"height",height);
jaddnum(retjson,"numaddresses",n);
jaddnum(retjson,"total",dstr(balance));
jaddnum(retjson,"noaddr_total",dstr(noaddr_balance));
return(retjson);
}
char *LP_snapshot_balance(struct iguana_info *coin,int32_t height,cJSON *argjson)
{
cJSON *snapjson,*retjson,*balances,*array,*addrs,*child,*item,*item2; char *coinaddr,*refaddr; int32_t i,n,j,m; uint64_t total=0,value,balance = 0;
retjson = cJSON_CreateObject();
array = cJSON_CreateArray();
if ( (snapjson= LP_snapshot(coin,height)) != 0 )
{
total = jdouble(snapjson,"total") * SATOSHIDEN;
if ( (addrs= jarray(&m,argjson,"addresses")) != 0 )
{
if ( (balances= jarray(&n,snapjson,"balances")) != 0 )
{
for (i=0; i<n; i++)
{
item = jitem(balances,i);
if ( (child= item->child) != 0 )
{
value = (uint64_t)(child->valuedouble * SATOSHIDEN);
if ( (refaddr= get_cJSON_fieldname(child)) != 0 )
{
//printf("check %s %.8f against %d\n",refaddr,dstr(value),m);
for (j=0; j<m; j++)
{
if ( (coinaddr= jstri(addrs,j)) != 0 )
{
if ( strcmp(coinaddr,refaddr) == 0 )
{
item2 = cJSON_CreateObject();
jaddnum(item2,coinaddr,dstr(value));
jaddi(array,item2);
balance += value;
break;
}
}
}
}
}
}
}
}
free_json(snapjson);
}
jadd(retjson,"balances",array);
jaddstr(retjson,"coin",coin->symbol);
jaddnum(retjson,"height",height);
jaddnum(retjson,"balance",dstr(balance));
jaddnum(retjson,"total",dstr(total));
return(jprint(retjson,1));
}
char *LP_dividends(struct iguana_info *coin,int32_t height,cJSON *argjson)
{
cJSON *array,*retjson,*item,*child,*exclude=0; int32_t i,j,emitted=0,dusted=0,n,execflag=0,flag,iter,numexcluded=0; char buf[1024],*field,*prefix="",*suffix=""; uint64_t dustsum=0,excluded=0,total=0,dividend=0,value,val,emit=0,dust=0; double ratio = 1.;
if ( (retjson= LP_snapshot(coin,height)) != 0 )
{
//printf("SNAPSHOT.(%s)\n",retstr);
if ( (array= jarray(&n,retjson,"balances")) != 0 )
{
if ( (n= cJSON_GetArraySize(array)) != 0 )
{
if ( argjson != 0 )
{
exclude = jarray(&numexcluded,argjson,"exclude");
dust = (uint64_t)(jdouble(argjson,"dust") * SATOSHIDEN);
dividend = (uint64_t)(jdouble(argjson,"dividend") * SATOSHIDEN);
if ( jstr(argjson,"prefix") != 0 )
prefix = jstr(argjson,"prefix");
if ( jstr(argjson,"suffix") != 0 )
suffix = jstr(argjson,"suffix");
execflag = jint(argjson,"system");
}
for (iter=0; iter<2; iter++)
{
for (i=0; i<n; i++)
{
flag = 0;
item = jitem(array,i);
if ( (child= item->child) != 0 )
{
value = (uint64_t)(child->valuedouble * SATOSHIDEN);
if ( (field= get_cJSON_fieldname(child)) != 0 )
{
for (j=0; j<numexcluded; j++)
if ( strcmp(field,jstri(exclude,j)) == 0 )
{
flag = 1;
break;
}
}
//printf("(%s %s %.8f) ",jprint(item,0),field,dstr(value));
if ( iter == 0 )
{
if ( flag != 0 )
excluded += value;
else total += value;
}
else
{
if ( flag == 0 )
{
val = ratio * value;
if ( val >= dust )
{
sprintf(buf,"%s %s %.8f %s",prefix,field,dstr(val),suffix);
if ( execflag != 0 )
{
if ( system(buf) != 0 )
printf("error system.(%s)\n",buf);
}
else printf("%s\n",buf);
emit += val;
emitted++;
} else dustsum += val, dusted++;
}
}
}
}
if ( iter == 0 )
{
if ( total > 0 )
{
if ( dividend == 0 )
dividend = total;
ratio = (double)dividend / total;
} else break;
}
}
}
}
free_json(retjson);
retjson = cJSON_CreateObject();
jaddstr(retjson,"coin",coin->symbol);
jaddnum(retjson,"height",height);
jaddnum(retjson,"total",dstr(total));
jaddnum(retjson,"emitted",emitted);
jaddnum(retjson,"excluded",dstr(excluded));
if ( dust != 0 )
{
jaddnum(retjson,"dust",dstr(dust));
jaddnum(retjson,"dusted",dusted);
}
if ( dustsum != 0 )
jaddnum(retjson,"dustsum",dstr(dustsum));
jaddnum(retjson,"dividend",dstr(dividend));
jaddnum(retjson,"dividends",dstr(emit));
jaddnum(retjson,"ratio",ratio);
if ( execflag != 0 )
jaddnum(retjson,"system",execflag);
/*if ( prefix[0] != 0 )
jaddstr(retjson,"prefix",prefix);
if ( suffix[0] != 0 )
jaddstr(retjson,"suffix",suffix);*/
return(jprint(retjson,1));
}
return(clonestr("{\"error\":\"symbol not found\"}"));
}
int64_t basilisk_txvalue(char *symbol,bits256 txid,int32_t vout)
{
char destaddr[64]; uint64_t value,interest = 0; struct iguana_info *coin;
@ -235,7 +632,10 @@ uint64_t LP_txvalue(char *coinaddr,char *symbol,bits256 txid,int32_t vout)
} else printf("vout.%d >= tx->numvouts.%d\n",vout,tx->numvouts);
}
if ( tx == 0 )
LP_transactioninit(coin,txid);
{
LP_transactioninit(coin,txid,0);
LP_transactioninit(coin,txid,1);
}
if ( coinaddr == 0 )
coinaddr = _coinaddr;
value = LP_txinterestvalue(&interest,coinaddr,coin,txid,vout);
@ -275,7 +675,10 @@ int32_t LP_mempoolscan(char *symbol,bits256 searchtxid)
{
txid = jbits256i(array,i);
if ( (tx= LP_transactionfind(coin,txid)) == 0 )
LP_transactioninit(coin,txid);
{
LP_transactioninit(coin,txid,0);
LP_transactioninit(coin,txid,1);
}
if ( bits256_cmp(txid,searchtxid) == 0 )
{
char str[65]; printf("found %s tx.(%s) in mempool slot.%d\n",symbol,bits256_str(str,txid),i);

44
iguana/exchanges/LP_utxos.c

@ -550,7 +550,7 @@ struct LP_utxoinfo *LP_utxoadd(int32_t iambob,int32_t mypubsock,char *symbol,bit
}
if ( numconfirms <= 0 )
{
printf("LP_utxoadd reject numconfirms.%d\n",numconfirms);
//printf("LP_utxoadd reject numconfirms.%d\n",numconfirms);
return(0);
}
numconfirms = -1;
@ -907,6 +907,48 @@ uint64_t LP_privkey_init(int32_t mypubsock,struct iguana_info *coin,bits256 mypr
return(total);
}
char *LP_secretaddresses(void *ctx,char *passphrase,int32_t n,uint8_t taddr,uint8_t pubtype)
{
int32_t i; uint8_t tmptype,pubkey33[33],rmd160[20]; char output[777*45],str[65],str2[65],buf[8192],wifstr[128],coinaddr[64]; bits256 checkprivkey,privkey,pubkey; cJSON *retjson;
retjson = cJSON_CreateObject();
if ( passphrase == 0 || passphrase[0] == 0 )
passphrase = "password";
if ( n <= 0 )
n = 16;
else if ( n > 777 )
n = 777;
conv_NXTpassword(privkey.bytes,pubkey.bytes,(uint8_t *)passphrase,(int32_t)strlen(passphrase));
bitcoin_priv2pub(ctx,pubkey33,coinaddr,privkey,taddr,pubtype);
printf("generator (%s) secrets.[%d] <%s> t.%u p.%u\n",coinaddr,n,passphrase,taddr,pubtype);
sprintf(output,"\"addresses\":[");
for (i=0; i<n; i++)
{
sprintf(buf,"secretaddress %s %03d",passphrase,i);
conv_NXTpassword(privkey.bytes,pubkey.bytes,(uint8_t *)buf,(int32_t)strlen(buf));
bitcoin_priv2pub(ctx,pubkey33,coinaddr,privkey,taddr,pubtype);
bitcoin_priv2wif(0,wifstr,privkey,188);
bitcoin_wif2priv(0,&tmptype,&checkprivkey,wifstr);
bitcoin_addr2rmd160(taddr,&tmptype,rmd160,coinaddr);
if ( bits256_cmp(checkprivkey,privkey) != 0 )
{
printf("WIF.(%s) error -> %s vs %s?\n",wifstr,bits256_str(str,privkey),bits256_str(str2,checkprivkey));
free_json(retjson);
return(clonestr("{\"error\":\"couldnt validate wifstr\"}"));
}
else if ( tmptype != pubtype )
{
printf("checktype.%d != pubtype.%d\n",tmptype,pubtype);
free_json(retjson);
return(clonestr("{\"error\":\"couldnt validate pubtype\"}"));
}
jaddstr(retjson,coinaddr,wifstr);
sprintf(output+strlen(output),"\\\"%s\\\"%c ",coinaddr,i<n-1?',':' ');
printf("./komodo-cli jumblr_secret %s\n",coinaddr);
}
printf("%s]\n",output);
return(jprint(retjson,1));
}
bits256 LP_privkeycalc(void *ctx,uint8_t *pubkey33,bits256 *pubkeyp,struct iguana_info *coin,char *passphrase,char *wifstr)
{
static uint32_t counter;

11
iguana/exchanges/balance_loop

@ -0,0 +1,11 @@
source userpass
ht=$1
while true
do
#curl --url "http://127.0.0.1:7779" --data "{\"userpass\":\"$userpass\",\"method\":\"snapshot\",\"coin\":\"KMD\",\"height\":$ht}"
ht=`curl --url "http://127.0.0.1:7779" --data "{\"userpass\":\"$userpass\",\"method\":\"snapshot\",\"coin\":\"KMD\"}" | jq .blocks`
echo next height $ht
sleep 600
done

2
iguana/exchanges/coins

File diff suppressed because one or more lines are too long

2
iguana/exchanges/dividends

@ -0,0 +1,2 @@
source userpass
curl --url "http://127.0.0.1:7779" --data "{\"userpass\":\"$userpass\",\"method\":\"dividends\",\"coin\":\"KMD\",\"height\":$1,\"prefix\":\"fiat/jumblr sendtoaddress\",\"suffix\":\"\",\"dividend\":50000,\"dust\":1}"

2
iguana/exchanges/install

@ -1,4 +1,4 @@
cp goals goal portfolio autoprice deletemessages getmessages debug register registerall trade ordermatch bestfit orderbook autotrade client run_osx client_osx run coins disable enable myprice myprices getcoins getpeers getpeersIP getprices getutxos help inv setprice status utxos ../dexscripts
cp snapshot_balance snapshot_loop secretaddresses dividends snapshot goals goal portfolio autoprice deletemessages getmessages debug register registerall trade ordermatch bestfit orderbook autotrade client run_osx client_osx run coins disable enable myprice myprices getcoins getpeers getpeersIP getprices getutxos help inv setprice status utxos ../dexscripts
cd ../dexscripts
#cp ../exchanges/passphrase ../exchanges/userpass .
echo you will need to have a passphrase file with your passphrase and userpass file with userpass value in dexscripts dir

6
iguana/exchanges/mm.c

@ -786,12 +786,14 @@ void marketmaker(double minask,double maxbid,char *baseaddr,char *reladdr,double
void LP_main(void *ptr)
{
char *passphrase; double profitmargin; cJSON *argjson = ptr;
char *passphrase; double profitmargin; uint16_t port; cJSON *argjson = ptr;
if ( (passphrase= jstr(argjson,"passphrase")) != 0 )
{
profitmargin = jdouble(argjson,"profitmargin");
LP_profitratio += profitmargin;
LPinit(7779,7780,7781,7782,passphrase,jint(argjson,"client"),jstr(argjson,"userhome"),argjson);
if ( (port= juint(argjson,"rpcport")) < 1000 )
port = 7779;
LPinit(port,7780,7781,7782,passphrase,jint(argjson,"client"),jstr(argjson,"userhome"),argjson);
}
}

5
iguana/exchanges/secretaddresses

@ -0,0 +1,5 @@
source userpass
echo "usage: ./secretaddresses 'passphrase'"
curl --url "http://127.0.0.1:7779" --data "{\"userpass\":\"$userpass\",\"method\":\"secretaddresses\",\"num\":16,\"passphrase\":\"$1\"}"

2
iguana/exchanges/snapshot

@ -0,0 +1,2 @@
source userpass
curl --url "http://127.0.0.1:7779" --data "{\"userpass\":\"$userpass\",\"method\":\"snapshot\",\"coin\":\"KMD\",\"height\":$1}"

4
iguana/exchanges/snapshot_balance

@ -0,0 +1,4 @@
source userpass
ht=$1
curl --url "http://127.0.0.1:7779" --data "{\"userpass\":\"$userpass\",\"method\":\"snapshot_balance\",\"coin\":\"KMD\",\"height\":$ht,\"addresses\":[\"RSAzPFzgTZHNcxLNLdGyVPbjbMA8PRY7Ss\", \"RBgD5eMGwZppid4x7PTEC2Wg1AzvxbsQqB\"]}"

11
iguana/exchanges/snapshot_loop

@ -0,0 +1,11 @@
source userpass
ht=$1
while true
do
curl --url "http://127.0.0.1:7779" --data "{\"userpass\":\"$userpass\",\"method\":\"snapshot\",\"coin\":\"KMD\",\"height\":$ht}"
#ht=`komodo-cli getinfo | jq .blocks`
ht=$(( $ht + 1000 ))
echo next height $ht
sleep 1
done

3
iguana/exchanges/userpass

@ -1 +1,2 @@
export userpass="<put the userpass value from the first API call here>"
#export userpass="<put the userpass value from the first API call here>"
export userpass="c3d8c2a364b7d18c1f9d7321d017b92e9f9c791e4f5c741214fefdea8a071256"

3
iguana/iguana_exchanges.c

@ -784,7 +784,8 @@ void exchanges777_loop(void *ptr)
printf("exchanges loop.(%s)\n",exchange->name);
while ( 1 )
{
PAX_idle(myinfo);
if ( strcmp("bitcoin",exchange->name) == 0 )
PAX_idle(myinfo);
flag = retval = 0;
retstr = 0;
if ( (req= queue_dequeue(&exchange->requestQ)) != 0 )

4
iguana/iguana_msg.c

@ -640,7 +640,7 @@ int32_t iguana_rwtx(struct supernet_info *myinfo,uint8_t zcash,int32_t rwflag,st
len += iguana_rwnum(rwflag,&serialized[len],sizeof(msg->timestamp),&msg->timestamp);
}
len += iguana_rwvarint32(rwflag,&serialized[len],&msg->tx_in);
if ( rwflag == 0 )
if ( rwflag == 0 && msg->tx_in > 0 )
msg->vins = iguana_memalloc(mem,msg->tx_in * sizeof(*msg->vins),1);
if ( maxsize-len <= 0 )
return(-1);
@ -671,7 +671,7 @@ int32_t iguana_rwtx(struct supernet_info *myinfo,uint8_t zcash,int32_t rwflag,st
return(-1);
}
//printf("numvouts.%d ",msg->tx_out);
if ( rwflag == 0 )
if ( rwflag == 0 && msg->tx_out > 0 )
msg->vouts = iguana_memalloc(mem,msg->tx_out * sizeof(*msg->vouts),1);
for (i=0; i<msg->tx_out; i++)
{

4
iguana/iguana_notary.c

@ -71,9 +71,7 @@ void dpow_srcupdate(struct supernet_info *myinfo,struct dpow_info *dp,int32_t he
else
{
freq = 1;
//minsigs = 7;//(komodo_notaries(dp->symbol,pubkeys,height) >> 1) + 1;
//if ( minsigs < DPOW_MINSIGS )
minsigs = DPOW_MINSIGS;
minsigs = 11;
}
printf("%s/%s src ht.%d dest.%u nonz.%d %s minsigs.%d\n",dp->symbol,dp->dest,checkpoint.blockhash.height,dp->destupdated,bits256_nonz(checkpoint.blockhash.hash),bits256_str(str,dp->last.blockhash.hash),minsigs);
dpow_fifoupdate(myinfo,dp->srcfifo,dp->last);

1
iguana/iguana_peers.c

@ -488,6 +488,7 @@ int32_t iguana_socket(int32_t bindflag,char *hostname,uint16_t port)
{
sleep(1);
printf("ERROR BINDING PORT.%d. this is normal tcp timeout, unless another process is using port\n",port);
fflush(stdout);
sleep(3);
printf("%s(%s) port.%d try again: %s sock.%d. errno.%d\n",bindflag!=0?"bind":"connect",hostname,port,strerror(errno),sock,errno);
if ( bindflag == 1 )

32
iguana/iguana_ramchain.c

@ -184,7 +184,7 @@ uint32_t iguana_ramchain_addtxid(struct iguana_info *coin,RAMCHAIN_FUNC,bits256
{
if ( t->txidind != txidind || memcmp(t->txid.bytes,txid.bytes,sizeof(bits256)) != 0 || t->numvouts != numvouts || t->numvins != numvins || t->firstvout != ramchain->H.unspentind || t->firstvin != ramchain->H.spendind || t->locktime != locktime || t->version != version || t->timestamp != timestamp )
{
printf("iguana_ramchain_addtxid.RO: addtxid mismatch (%u %d %d %u %u) vs. (%d %d %d %d %d)\n",(uint32_t)t->txidind,t->numvouts,t->numvins,(uint32_t)t->firstvout,(uint32_t)t->firstvin,txidind,numvouts,numvins,ramchain->H.unspentind,ramchain->H.spendind);
printf("iguana_ramchain_addtxid.RO: addtxid mismatch b.%d (%u %d %d %u %u) vs. (%d %d %d %d %d)\n",bundlei,(uint32_t)t->txidind,t->numvouts,t->numvins,(uint32_t)t->firstvout,(uint32_t)t->firstvin,txidind,numvouts,numvins,ramchain->H.unspentind,ramchain->H.spendind);
//getchar();
return(0);
}
@ -1126,7 +1126,7 @@ int32_t iguana_ramchain_verify(struct iguana_info *coin,struct iguana_ramchain *
return(-3);
}
}
for (k=0; k<t->numvouts; k++,ramchain->H.unspentind++)
for (k=0; k<t->numvouts; k++)
{
u = &Ux[ramchain->H.unspentind];
if ( u->txidind != ramchain->H.txidind )
@ -1148,17 +1148,19 @@ int32_t iguana_ramchain_verify(struct iguana_info *coin,struct iguana_ramchain *
printf("%p itemind.%d pkind.%d %d unspentind?\n",p,ptr->hh.itemind,pkind,ramchain->H.unspentind);
return(-9);
}
ramchain->H.unspentind++;
}
}
else
{
for (k=0; k<t->numvouts; k++,ramchain->H.unspentind++)
for (k=0; k<t->numvouts; k++)
{
if ( U[ramchain->H.unspentind].txidind != ramchain->H.txidind )
{
printf(" k.%d U.%d u->txidind.%x != txidind.%d\n",k,ramchain->H.unspentind,U[ramchain->H.unspentind].txidind,ramchain->H.txidind);
return(-6);
}
ramchain->H.unspentind++;
}
}
ramchain->H.spendind += t->numvins;
@ -1167,7 +1169,7 @@ int32_t iguana_ramchain_verify(struct iguana_info *coin,struct iguana_ramchain *
for (ramchain->H.txidind=rdata->firsti; ramchain->H.txidind<rdata->numtxids; ramchain->H.txidind++)
{
t = &T[ramchain->H.txidind];
for (k=0; k<t->numvins; k++,ramchain->H.spendind++)
for (k=0; k<t->numvins; k++)
{
if ( ramchain->expanded != 0 )
{
@ -1190,6 +1192,7 @@ int32_t iguana_ramchain_verify(struct iguana_info *coin,struct iguana_ramchain *
}
}
}
ramchain->H.spendind++;
}
}
if ( ramchain->expanded != 0 && ramchain->A != ramchain->creditsA )
@ -1655,6 +1658,8 @@ int32_t iguana_ramchain_iterate(struct supernet_info *myinfo,struct iguana_info
printf("iguana_ramchain_iterate cant iterate without data\n");
return(-1);
}
if ( rdata->firsti != 1 )
printf("unexpected firsti.%d %s.%d\n",rdata->firsti,coin->symbol,bundlei);
if ( dest != 0 )
{
// required to do one block at a time, all vins/vouts the same height are assumed to happen simultaneously with vouts before vins
@ -1899,14 +1904,15 @@ long iguana_ramchain_data(struct supernet_info *myinfo,struct iguana_info *coin,
}
if ( block != 0 )
block->fpipbits = 1;
for (i=0; i<txn_count; i++,ramchain->H.txidind++)
for (i=0; i<txn_count; i++)
{
tx = &txarray[i];
iguana_ramchain_addtxid(coin,RAMCHAIN_ARG,tx->txid,tx->tx_out,tx->tx_in,tx->lock_time,tx->version,tx->timestamp,bundlei);
if ( tx->tx_out == 0 && tx->tx_in == 0 )
if ( tx->tx_out == 0 )
{
printf("strange tx without any inputs or outputs? ht.%d\n",bp->bundleheight);
break;
if ( coin->chain->zcash == 0 )
printf("strange tx without any inputs or outputs? ht.%d\n",bp->bundleheight);
continue;
}
for (j=0; j<tx->tx_out; j++)
{
@ -1915,16 +1921,18 @@ long iguana_ramchain_data(struct supernet_info *myinfo,struct iguana_info *coin,
iguana_ramchain_addunspent20(coin,addr,RAMCHAIN_ARG,tx->vouts[j].value,tx->vouts[j].pk_script,tx->vouts[j].pk_scriptlen,tx->txid,j,-1,bp,rmd160);
}
ramchain->H.spendind += tx->tx_in;
ramchain->H.txidind++;
}
//printf("scriptoffset.%d after %d txids\n",ramchain->H.scriptoffset,txn_count);
ramchain->H.txidind = ramchain->H.spendind = rdata->firsti;
for (i=0; i<txn_count; i++,ramchain->H.txidind++)
for (i=0; i<txn_count; i++)
{
tx = &txarray[i];
for (j=0; j<tx->tx_in; j++)
{
iguana_ramchain_addspend256(coin,addr,RAMCHAIN_ARG,tx->vins[j].prev_hash,tx->vins[j].prev_vout,tx->vins[j].vinscript,tx->vins[j].scriptlen,tx->vins[j].sequence,bp);//,bp->hdrsi,bundlei);
}
ramchain->H.txidind++;
}
rdata->prevhash2 = origtxdata->zblock.RO.prev_block;
rdata->scriptspace = scriptspace = ramchain->H.scriptoffset;
@ -2487,13 +2495,17 @@ int32_t iguana_mapchaininit(char *fname,struct iguana_info *coin,struct iguana_r
int32_t iguana_bundlesaveHT(struct supernet_info *myinfo,struct iguana_info *coin,struct OS_memspace *mem,struct OS_memspace *memB,struct iguana_bundle *bp,uint32_t starttime) // helper thread
{
static int depth;
RAMCHAIN_DESTDECLARE; RAMCHAIN_DECLARE; RAMCHAIN_ZEROES;
RAMCHAIN_DESTDECLARE; RAMCHAIN_DECLARE; RAMCHAIN_ZEROES; static struct iguana_blockRO *_destB;
void **ptrs; long *filesizes; uint32_t *ipbits; char fname[1024];
struct iguana_ramchain *R,*mapchain,*dest,newchain; uint32_t fpipbits; bits256 prevhash2;
int32_t i,starti,endi,bp_n,numtxids,valid,sigspace,pubkeyspace,numunspents,numspends,numpkinds,numexternaltxids,scriptspace; struct iguana_block *block; long fpos;
struct OS_memspace HASHMEM; int32_t err,j,num,bundlei,firsti= 1,retval = -1;
memset(&HASHMEM,0,sizeof(HASHMEM));
starti = 0, endi = bp->n - 1;
if ( _destB == 0 )
_destB = malloc(sizeof(*_destB) * 2000);
destB = _destB;
memset(destB,0,sizeof(*destB) * bp->n);
//B = 0, Ux = 0, Sx = 0, P = 0, A = 0, X = 0, Kspace = TXbits = PKbits = 0, U = 0, S = 0, T = 0;
R = mycalloc('s',bp->n,sizeof(*R));
ptrs = mycalloc('w',bp->n,sizeof(*ptrs));

1
iguana/iguana_rpc.c

@ -1170,6 +1170,7 @@ void iguana_rpcloop(void *args)
sleep(3);
}
printf(">>>>>>>>>> iguana_rpcloop 127.0.0.1:%d bind sock.%d iguana API enabled <<<<<<<<<\n",port,bindsock);
fflush(stdout);
space = calloc(1,size);
while ( bindsock >= 0 )
{

2
iguana/tests/rawtx2

@ -1,2 +1,2 @@
#!/bin/bash
curl --url "http://127.0.0.1:7778" --data "{\"coin\":\"BTCD\",\"agent\":\"basilisk\",\"method\":\"rawtx\",\"vals\":{\"changeaddr\":\"RRyBxbrAPRUBCUpiJgJZYrkxqrh8x5ta9Z\",\"addresses\":[\"RFMEYcxuBL8S7UPdUbzXunPtS4p82HRcKs\", \"RRyBxbrAPRUBCUpiJgJZYrkxqrh8x5ta9Z\", \"RDBjpRUqV1AXzVJCBbbXNskgxGRj711qSc\", \"RL4aMgTBzkM1kX7d8QtE2oYXuAj2ZKabmW\", \"RDE9LBKqMaKgQgnsZM3hFCNeWfoXkHWMLs\", \"RDBjpRUqV1AXzVJCBbbXNskgxGRj711qSc\"],\"timeout\":15000,\"satoshis\":\"128700\",\"spendscript\":\"76a9142b4cf64627268ac24effd9aad5895e8ca862114288ac\",\"txfee\":\"10000\",\"burn\":0.00000000}}"
curl --url "http://127.0.0.1:7778" --data "{\"coin\":\"KMD\",\"agent\":\"basilisk\",\"method\":\"rawtx\",\"vals\":{\"changeaddr\":\"RRyBxbrAPRUBCUpiJgJZYrkxqrh8x5ta9Z\",\"addresses\":[\"RFMEYcxuBL8S7UPdUbzXunPtS4p82HRcKs\", \"RRyBxbrAPRUBCUpiJgJZYrkxqrh8x5ta9Z\", \"RDBjpRUqV1AXzVJCBbbXNskgxGRj711qSc\", \"RL4aMgTBzkM1kX7d8QtE2oYXuAj2ZKabmW\", \"RDE9LBKqMaKgQgnsZM3hFCNeWfoXkHWMLs\", \"RDBjpRUqV1AXzVJCBbbXNskgxGRj711qSc\"],\"timeout\":15000,\"satoshis\":\"128700\",\"spendscript\":\"76a9142b4cf64627268ac24effd9aad5895e8ca862114288ac\",\"txfee\":\"10000\",\"burn\":0.00000000}}"

Loading…
Cancel
Save