Browse Source

Merge remote-tracking branch 'origin/master'

master
jl777 8 years ago
parent
commit
88d02eeb56
  1. 181
      .gitignore
  2. BIN
      OSlibs/win/libcrypto-1_1.dll
  3. BIN
      OSlibs/win/libcurl.dll
  4. BIN
      OSlibs/win/libcurl.exp
  5. BIN
      OSlibs/win/libcurl.lib
  6. BIN
      OSlibs/win/libssl-1_1.dll
  7. 32
      README.md
  8. 807
      basilisk/basilisk.c
  9. 27
      basilisk/basilisk.h
  10. 307
      basilisk/basilisk_DEX.c
  11. 120
      basilisk/basilisk_MSG.c
  12. 430
      basilisk/basilisk_bitcoin.c
  13. 2
      basilisk/basilisk_ping.c
  14. 1513
      basilisk/basilisk_swap.c
  15. 22
      basilisk/basilisk_tradebot.c
  16. 495
      basilisk/jumblr.c
  17. 90
      basilisk/smartaddress.c
  18. 47
      basilisk/tradebots_SVM.h
  19. 72
      basilisk/tradebots_liquidity.c
  20. 108
      basilisk/tradebots_marketmaker.c
  21. 2
      crypto777/OS_portable.c
  22. 7
      crypto777/OS_portable.h
  23. 7
      crypto777/OS_time.c
  24. 3
      crypto777/SaM.c
  25. 31
      crypto777/bitcoind_RPC.c
  26. 4
      crypto777/cJSON.c
  27. 2
      crypto777/curve25519.c
  28. 6
      crypto777/iguana_OS.c
  29. 150
      crypto777/iguana_utils.c
  30. 4
      crypto777/inet.c
  31. 2
      crypto777/ramcoder.c
  32. 23
      datachain/datachain.c
  33. 50
      gecko/gecko.c
  34. 2
      gecko/gecko_headers.c
  35. 2
      gecko/gecko_miner.c
  36. 16
      iguana.vcxproj
  37. 51
      iguana/SuperNET_keys.c
  38. 2
      iguana/cards777.c
  39. 26
      iguana/dPoW.h
  40. 5
      iguana/dpow/dpow_fsm.c
  41. 556
      iguana/dpow/dpow_network.c
  42. 74
      iguana/dpow/dpow_prices.c
  43. 41
      iguana/dpow/dpow_rpc.c
  44. 4
      iguana/dpow/dpow_tx.c
  45. 52
      iguana/dpowassets
  46. 19
      iguana/exchanges/bitcoin.c
  47. 18
      iguana/exchanges/bittrex.c
  48. 3
      iguana/exchanges/fxcm.c
  49. 722
      iguana/exchanges/mm.c
  50. 13
      iguana/iguana777.c
  51. 65
      iguana/iguana777.h
  52. 4
      iguana/iguana_accept.c
  53. 47
      iguana/iguana_bitmap.c
  54. 8
      iguana/iguana_blocks.c
  55. 37
      iguana/iguana_bundles.c
  56. 17
      iguana/iguana_chains.c
  57. 28
      iguana/iguana_exchanges.c
  58. 5
      iguana/iguana_init.c
  59. 7
      iguana/iguana_interpreter.c
  60. 450
      iguana/iguana_json.c
  61. 14
      iguana/iguana_mofn.c
  62. 16
      iguana/iguana_msg.c
  63. 244
      iguana/iguana_notary.c
  64. 261
      iguana/iguana_payments.c
  65. 12
      iguana/iguana_peers.c
  66. 64
      iguana/iguana_ramchain.c
  67. 10
      iguana/iguana_realtime.c
  68. 62
      iguana/iguana_recv.c
  69. 22
      iguana/iguana_rpc.c
  70. 15
      iguana/iguana_scripts.c
  71. 10
      iguana/iguana_secp.c
  72. 198
      iguana/iguana_sign.c
  73. 26
      iguana/iguana_spendvectors.c
  74. 5
      iguana/iguana_tradebots.c
  75. 4
      iguana/iguana_tx.c
  76. 22
      iguana/iguana_txidfind.c
  77. 36
      iguana/iguana_unspents.c
  78. 2
      iguana/iguana_volatiles.c
  79. 14
      iguana/iguana_wallet.c
  80. 778
      iguana/kmd_lookup.h
  81. 1
      iguana/m_mm
  82. 4
      iguana/m_osx
  83. 2
      iguana/m_unix
  84. 522
      iguana/main.c
  85. 3
      iguana/mini-gmp.c
  86. 2
      iguana/pangea_api.c
  87. 2
      iguana/pangea_hand.c
  88. 22
      iguana/pangea_json.c
  89. 563
      iguana/ramchain_api.c
  90. 2
      iguana/secp256k1/src/ecmult_const_impl.h
  91. 2
      iguana/secp256k1/src/modules/rangeproof/rangeproof_impl.h
  92. 2
      iguana/secp256k1/src/modules/recovery/main_impl.h
  93. 2
      iguana/tests/DEXinit
  94. 164
      iguana/tests/KMD.batch10
  95. 161
      iguana/tests/KMD.batch10.importaddress
  96. 129
      iguana/tests/KMD.batch10.listunspent
  97. 64
      iguana/tests/KMD.batch10.txids
  98. 191
      iguana/tests/KMD.batch11
  99. 188
      iguana/tests/KMD.batch11.importaddress
  100. 151
      iguana/tests/KMD.batch11.listunspent

181
.gitignore

@ -38,6 +38,7 @@ deprecated/.DS_Store
.DS_Store
<<<<<<< HEAD
iguana/help/.tmpmarker
iguana/genesis/.tmpmarker
@ -47,3 +48,183 @@ iguana/help.json
iguana/autoAPI.md
iguana/basilisk.o-2ad8cb38
=======
*.pbxproj
iguana/tmp/.tmpmarker
iguana/SVM/rawfeatures/.tmpmarker
iguana/DB/.tmpmarker
iguana/DB/TRANSACTIONS/.tmpmarker
iguana/DB/purgeable/.tmpmarker
iguana/DB/purgeable/BTCD/.tmpmarker
iguana/DB/purgeable/BTC/.tmpmarker
iguana/DB/ECB/.tmpmarker
iguana/genesis/.tmpmarker
iguana/help/.tmpmarker
iguana/SVM/.tmpmarker
iguana/SVM/models/.tmpmarker
SuperNET.xcodeproj/xcuserdata/mac.xcuserdatad/xcschemes/xcschememanagement.plist
SuperNET.xcodeproj/xcuserdata/mac.xcuserdatad/xcschemes/SuperNET.xcscheme
iguana/DB/BTC/.tmpmarker
*.vouts
iguana/DB/BTC/vouts/.tmpmarker
iguana/DB/BTC/accounts/.tmpmarker
iguana/DB/BTC/spends/.tmpmarker
iguana/DB/BTC/validated/.tmpmarker
iguana/DB/KMD/.tmpmarker
iguana/DB/KMD/accounts/.tmpmarker
iguana/DB/KMD/spends/.tmpmarker
iguana/DB/KMD/validated/.tmpmarker
iguana/DB/KMD/vouts/.tmpmarker
iguana/DB/purgeable/KMD/.tmpmarker
iguana/DB/ro/.tmpmarker
iguana/DB/ro/BTC/.tmpmarker
iguana/DB/ro/KMD/.tmpmarker
iguana/confs/682c279f7b01b96aee50f11b327bf6c0a3d3481a23a9a265f0796e9bb3765b24
iguana/confs/682c279f7b01b96aee50f11b327bf6c0a3d3481a23a9a265f0796e9bb3765b24.old
iguana/confs/83cb074c13289a91a0cd50a8e6932b2237d1533ec1cbff56ab3d9b1d37f8df35
iguana/confs/83cb074c13289a91a0cd50a8e6932b2237d1533ec1cbff56ab3d9b1d37f8df35.old
iguana/tmp/BTC/.tmpmarker
iguana/tmp/BTC/0/.tmpmarker
iguana/tmp/BTC/0/0/.tmpmarker
iguana/tmp/BTC/peers.txt
iguana/tmp/BTC/RT/.tmpmarker
iguana/tmp/KMD/.tmpmarker
iguana/tmp/KMD/0/.tmpmarker
iguana/tmp/KMD/0/0/.tmpmarker
iguana/tmp/KMD/peers.txt
iguana/tmp/KMD/RT/.tmpmarker
*.xcworkspacedata
*.xcuserstate
includes/iguana_apideclares copy.h
iguana/iguana_tx.o-4b5de8fe
iguana/confs/c6faccf6b625bbb826f47b77c3274e985db7b0a47d435f32bea2f7f3724cdd17
iguana/confs/c6faccf6b625bbb826f47b77c3274e985db7b0a47d435f32bea2f7f3724cdd17.old
iguana/marketmaker
iguana/secp256k1.o-501dfbfe
iguana/confs/cc577d22ca76351d495f147b470103392b5f2ab0948e45608623a7d9728e2c6f
iguana/confs/cc577d22ca76351d495f147b470103392b5f2ab0948e45608623a7d9728e2c6f.old
iguana/DB/DEX.log
iguana/iguana_notary.o-54f98cc3
iguana/basilisk.o-2ad8cb38
iguana/pangea_hand.o-02d25ec3
iguana/confs/4dfa301d0adf61f0ec08e4d4cb4444f4fc377f45f5d6b1da0814033920d72353
iguana/help.json
iguana/index7778.html
*.json
iguana/DB/KMD/utxo.dat
iguana/unparsed.txt
iguana/unparsed.txt
iguana/unparsed.txt
iguana/DB/SWAPS/.tmpmarker
iguana/DB/SWAPS/list
iguana/DB/SWAPS/15974209-4014252807
iguana/iguana777.o-0cc60f50
iguana/DB/SWAPS/667293271-3414303895
iguana/DB/SWAPS/667293271-3414303895.swap
iguana/DB/SWAPS/548227681-1452262678.swap
iguana/DB/SWAPS/548227681-1452262678
*.bobdeposit
*.bobpayment
*.bobreclaim
*.bobrefund
*.swap
iguana/DB/SWAPS/1268007736-526212866
iguana/DB/SWAPS/3111936786-3185288772
iguana/DB/SWAPS/3368214189-2405641584
iguana/DB/SWAPS/1133671270-1840176506
iguana/DB/SWAPS/467927158-3437055573
iguana/DB/SWAPS/270159951-1269722638
iguana/DB/SWAPS/244991424-1008712592
iguana/confs/1cc0270abba7f4463a3dcb9908b9d875691a6773fe3cc1b4302233ed76665300
iguana/autoAPI.md
iguana/confs/5228bcea7ae2515a29c3844673de6ee2acba53bf45724744a00ff4306f192912
iguana/confs/630929d976025fafde221c7358eb5805f4359bad3c6b8bd50ad3f6e0a9b5ce78
>>>>>>> origin/master

BIN
OSlibs/win/libcrypto-1_1.dll

Binary file not shown.

BIN
OSlibs/win/libcurl.dll

Binary file not shown.

BIN
OSlibs/win/libcurl.exp

Binary file not shown.

BIN
OSlibs/win/libcurl.lib

Binary file not shown.

BIN
OSlibs/win/libssl-1_1.dll

Binary file not shown.

32
README.md

@ -223,3 +223,35 @@ sudo service ntp start
Now things should be ready. To update and run notary node:
pkill iguana; ./m_LP; tests/notaryinit
##Build for OSX distribution##
Get OSX SDK 10.6 from https://github.com/ca333/MacOSX-SDKs/releases/tag/10.6
Unpack & move the .sdk folder to Xcodes SDK folder:
```cd DownloadDirectory```
```mv MacOSX10.6.sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/.```
If you are using Xcode > 7.3 add the new SDK to XCode by changing MinimumSDKVersion in your Info.plist:
```vi /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Info.plist```
Change the value to:
```
<key>MinimumSDKVersion</key>
<string>10.6</string>
```
Build crypto777 library and agents with OSX release makefile:
```./m_onetime m_osx_release```
Execute the OSX deploy script:
```
./osx_deploy.sh
```
The iguana binary and its linked libraries are in ```$HOME/tmp/iguana```.

807
basilisk/basilisk.c

@ -265,6 +265,7 @@ int32_t basilisk_sendcmd(struct supernet_info *myinfo,char *destipaddr,char *typ
}
if ( s == n && valid == 1 && (destipaddr == 0 || strcmp(addr->ipaddr,destipaddr) == 0) )
{
val = 0;
//fprintf(stderr,">>> (%s).%u ",addr->ipaddr,coin->chain->portp2p);
//printf("n.%d/fanout.%d i.%d l.%d [%s].tag%u send %s [%x] datalen.%d addr->supernet.%u basilisk.%u to (%s).%d destip.%s\n",n,fanout,i,l,cmd,*(uint32_t *)data,type,*(int32_t *)&data[datalen-4],datalen,addr->supernet,addr->basilisk,addr->ipaddr,addr->A.port,destipaddr!=0?destipaddr:"broadcast");
if ( encryptflag != 0 && bits256_nonz(addr->pubkey) != 0 )
@ -462,7 +463,7 @@ char *basilisk_standardservice(char *CMD,struct supernet_info *myinfo,void *_add
}
ptr->finished = OS_milliseconds() + 10000;
}
if ( 0 && strcmp("MSG",CMD) == 0 )
if ( (0) && strcmp("MSG",CMD) == 0 )
printf("%s.(%s) -> (%s)\n",CMD,jprint(valsobj,0),retstr!=0?retstr:"");
return(retstr);
}
@ -481,8 +482,10 @@ int32_t basilisk_relayid(struct supernet_info *myinfo,uint32_t ipbits)
#include "basilisk_ether.c"
#include "basilisk_waves.c"
#include "basilisk_lisk.c"
#include "smartaddress.c"
#include "basilisk_MSG.c"
#include "tradebots_marketmaker.c"
#include "tradebots_liquidity.c"
#include "basilisk_tradebot.c"
#include "basilisk_swap.c"
@ -490,6 +493,7 @@ int32_t basilisk_relayid(struct supernet_info *myinfo,uint32_t ipbits)
#include "basilisk_ping.c"
#include "basilisk_vote.c"
#include "basilisk_CMD.c"
#include "jumblr.c"
void basilisk_functions(struct iguana_info *coin,int32_t protocol)
{
@ -793,10 +797,10 @@ int32_t basilisk_p2pQ_process(struct supernet_info *myinfo,int32_t maxiters)
else
{
len += iguana_rwnum(0,ptr->data,sizeof(basilisktag),&basilisktag);
if ( 0 && myinfo->IAMLP == 0 )
if ( (0) && myinfo->IAMLP == 0 )
printf("RELAYID.%d ->received.%d basilisk_p2p.(%s) from %s tag.%u\n",myinfo->NOTARY.RELAYID,ptr->datalen,ptr->type,senderip,basilisktag);
basilisk_msgprocess(myinfo,ptr->addr,ptr->ipbits,ptr->type,basilisktag,&ptr->data[len],ptr->datalen - len);
if ( 0 && myinfo->IAMLP == 0 )
if ( (0) && myinfo->IAMLP == 0 )
printf("processed.%s from %s\n",ptr->type,senderip);
}
free(ptr);
@ -868,7 +872,7 @@ int32_t basilisk_issued_purge(struct supernet_info *myinfo,int32_t timepad)
void basilisks_loop(void *arg)
{
static uint32_t counter;
struct iguana_info *relay; struct supernet_info *myinfo = arg; int32_t iter; double startmilli,endmilli; struct dpow_info *dp;
struct iguana_info *relay; struct supernet_info *myinfo = arg; int32_t iter; double startmilli,endmilli; struct dpow_info *dp;
iter = 0;
relay = iguana_coinfind("RELAY");
printf("start basilisk loop\n");
@ -901,13 +905,14 @@ void basilisks_loop(void *arg)
{
dp = &myinfo->DPOWS[counter % myinfo->numdpows];
iguana_dPoWupdate(myinfo,dp);
if ( (counter % myinfo->numdpows) != 0 )
//if ( (counter % myinfo->numdpows) != 0 )
{
//fprintf(stderr,"F ");
iguana_dPoWupdate(myinfo,&myinfo->DPOWS[0]);
}
endmilli = startmilli + 30;
}
//fprintf(stderr,"F ");
}
else
{
@ -948,6 +953,436 @@ void basilisks_init(struct supernet_info *myinfo)
#include "../includes/iguana_apidefs.h"
#include "../includes/iguana_apideclares.h"
#include "../includes/iguana_apideclares2.h"
TWO_STRINGS(tradebot,gensvm,base,rel)
{
#ifdef _WIN
return(clonestr("{\"error\":\"windows doesnt support SVM\"}"));
#else
int32_t numfeatures = 317*61;
struct tradebot_arbpair *pair;
if ( base[0] != 0 && rel[0] != 0 && (pair= tradebots_arbpair_find(base,rel)) != 0 && pair->fp != 0 )
{
tradebots_calcanswers(pair);
ocas_gen(pair->refc,numfeatures,0,(int32_t)(ftell(pair->fp) / sizeof(pair->rawfeatures)));
return(clonestr("{\"result\":\"success\"}"));
} else return(clonestr("{\"error\":\"cant find arbpair\"}"));
#endif
}
ZERO_ARGS(tradebot,openliquidity)
{
int32_t i; cJSON *array = cJSON_CreateArray();
for (i=0; i<sizeof(myinfo->linfos)/sizeof(*myinfo->linfos); i++)
{
if ( myinfo->linfos[i].base[0] != 0 )
jaddi(array,linfo_json(&myinfo->linfos[i]));
}
return(jprint(array,1));
}
ZERO_ARGS(tradebot,allbalances)
{
int32_t i,n; double value,pending; char *base; cJSON *item,*balances = cJSON_CreateObject();
if ( myinfo->liquidity_currencies == 0 )
myinfo->liquidity_currencies = cJSON_Parse("[\"KMD\", \"BTC\"]");
if ( myinfo->liquidity_currencies != 0 && (n= cJSON_GetArraySize(myinfo->liquidity_currencies)) > 0 )
{
for (i=0; i<n; i++)
{
base = jstri(myinfo->liquidity_currencies,i);
value = tradebot_balance(myinfo,base);
pending = tradebot_pending(myinfo,base);
item = cJSON_CreateObject();
jaddnum(item,"value",value);
jaddnum(item,"pending",pending);
jadd(balances,base,item);
}
}
return(jprint(balances,1));
}
ZERO_ARGS(tradebot,anchor)
{
FILE *fp; char *anchorstr,fname[512]; cJSON *anchor; int32_t retval = -1;
if ( (anchorstr= tradebot_allbalances(myinfo,0,0,0)) != 0 )
{
if ( (anchor= cJSON_Parse(anchorstr)) != 0 )
{
if ( jobj(anchor,"error") == 0 )
{
sprintf(fname,"%s/anchor",GLOBAL_DBDIR), OS_compatible_path(fname);
if ( (fp= fopen(fname,"wb")) != 0 )
{
if ( fwrite(anchorstr,1,strlen(anchorstr)+1,fp) == strlen(anchorstr)+1 )
retval = 0;
fclose(fp);
}
}
}
free(anchorstr);
}
if ( retval == 0 )
return(clonestr("{\"result\":\"success\"}"));
else return(clonestr("{\"error\":\"couldnt make anchor file\"}"));
}
ZERO_ARGS(tradebot,portfolio)
{
char *currentstr,*anchorstr,fname[512]; long fsize; cJSON *current,*anchor=0,*portfolio=0;
if ( (currentstr= tradebot_allbalances(myinfo,0,0,0)) != 0 )
{
if ( (current= cJSON_Parse(currentstr)) != 0 )
{
sprintf(fname,"%s/anchor",GLOBAL_DBDIR), OS_compatible_path(fname);
if ( (anchorstr= OS_filestr(&fsize,fname)) != 0 )
{
anchor = cJSON_Parse(anchorstr);
free(anchorstr);
}
if ( anchor == 0 )
anchor = cJSON_Parse("{}");
portfolio = tradebot_balancesdiff(myinfo,current,anchor);
free_json(current);
}
free(currentstr);
}
if ( portfolio == 0 )
return(clonestr("{\"result\":\"success\"}"));
else return(jprint(portfolio,1));
}
ARRAY_OBJ_INT(tradebot,goals,currencies,vals,targettime)
{
static bits256 zero; char *targetcoin; int32_t i,n;
if ( currencies != 0 && vals != 0 )
{
// init things so automatically updates refli.bid and refli.ask
// volume range with margin
// currency percentage value in BTC? target distribution, max percentage, min percentage`
// min price to sell, max price to buy, max volume
n = cJSON_GetArraySize(currencies);
for (i=0; i<n; i++)
{
targetcoin = jstri(currencies,i);
tradebot_liquidity_command(myinfo,targetcoin,zero,vals);
}
return(clonestr("{\"result\":\"success\"}"));
} else return(clonestr("{\"error\":\"no currencies or vals\"}"));
}
HASH_ARRAY_STRING(basilisk,getmessage,hash,vals,hexstr)
{
uint32_t msgid,width,channel; char *retstr;
if ( bits256_cmp(GENESIS_PUBKEY,jbits256(vals,"srchash")) == 0 )
jaddbits256(vals,"srchash",hash);
if ( bits256_cmp(GENESIS_PUBKEY,jbits256(vals,"desthash")) == 0 )
jaddbits256(vals,"desthash",myinfo->myaddr.persistent);
if ( (msgid= juint(vals,"msgid")) == 0 )
{
msgid = (uint32_t)time(NULL);
jdelete(vals,"msgid");
jaddnum(vals,"msgid",msgid);
}
if ( myinfo->NOTARY.RELAYID >= 0 || myinfo->dexsock >= 0 || myinfo->subsock >= 0 )
{
channel = juint(vals,"channel");
width = juint(vals,"width");
retstr = basilisk_iterate_MSG(myinfo,channel,msgid,jbits256(vals,"srchash"),jbits256(vals,"desthash"),width);
//printf("getmessage.(%s)\n",retstr);
return(retstr);
}
//printf("getmessage not relay.%d dexsock.%d subsock.%d\n",myinfo->NOTARY.RELAYID,myinfo->dexsock,myinfo->subsock);
return(basilisk_standardservice("MSG",myinfo,0,jbits256(vals,"desthash"),vals,hexstr,1));
}
HASH_ARRAY_STRING(basilisk,sendmessage,hash,vals,hexstr)
{
int32_t keylen,datalen,allocsize = 65536; uint8_t key[BASILISK_KEYSIZE],*space,*space2,*data,*ptr = 0; char *retstr=0;
space = calloc(1,allocsize);
space2 = calloc(1,allocsize);
data = get_dataptr(BASILISK_HDROFFSET,&ptr,&datalen,&space[BASILISK_KEYSIZE],allocsize-BASILISK_KEYSIZE,hexstr);
if ( myinfo->subsock >= 0 || myinfo->dexsock >= 0 || (myinfo->IAMNOTARY != 0 && myinfo->NOTARY.RELAYID >= 0) )
{
keylen = basilisk_messagekey(key,juint(vals,"channel"),juint(vals,"msgid"),jbits256(vals,"srchash"),jbits256(vals,"desthash"));
if ( data != 0 )
{
retstr = basilisk_respond_addmessage(myinfo,key,keylen,data,datalen,0,juint(vals,"duration"));
} else printf("no get_dataptr\n");
if ( retstr != 0 )
free(retstr);
} //else printf("not notary.%d relayid.%d\n",myinfo->IAMNOTARY,myinfo->NOTARY.RELAYID);
if ( vals != 0 && juint(vals,"fanout") == 0 )
jaddnum(vals,"fanout",MAX(8,(int32_t)sqrt(myinfo->NOTARY.NUMRELAYS)+2));
if ( BASILISK_KEYSIZE+datalen < allocsize )
{
memcpy(space2,key,BASILISK_KEYSIZE);
if ( data != 0 && datalen != 0 )
memcpy(&space2[BASILISK_KEYSIZE],data,datalen);
dex_reqsend(myinfo,"DEX",space2,datalen+BASILISK_KEYSIZE,1,"");
} else printf("sendmessage space too small error for %d\n",datalen);
free(space);
free(space2);
if ( ptr != 0 )
free(ptr);
return(basilisk_standardservice("OUT",myinfo,0,jbits256(vals,"desthash"),vals,hexstr,0));
}
HASH_ARRAY_STRING(basilisk,value,hash,vals,hexstr)
{
char *retstr=0,*symbol,*coinaddr,*infostr; cJSON *retjson,*sobj,*info,*addrs,*txoutjson,*txjson,*array; uint32_t basilisktag,blocktime; bits256 txid,blockhash; struct basilisk_item *ptr,Lptr; uint64_t value; int32_t timeoutmillis,vout,height,n,m;
if ( vals == 0 )
return(clonestr("{\"error\":\"null valsobj\"}"));
//if ( myinfo->IAMNOTARY != 0 || myinfo->NOTARY.RELAYID >= 0 )
// return(clonestr("{\"error\":\"special relays only do OUT and MSG\"}"));
//if ( coin == 0 )
{
if ( (symbol= jstr(vals,"symbol")) != 0 || (symbol= jstr(vals,"coin")) != 0 )
coin = iguana_coinfind(symbol);
}
if ( jobj(vals,"fanout") == 0 )
jaddnum(vals,"fanout",MAX(5,(int32_t)sqrt(myinfo->NOTARY.NUMRELAYS)+1));
txid = jbits256(vals,"txid");
vout = jint(vals,"vout");
if ( coin != 0 )
{
if ( coin->FULLNODE < 0 )
{
if ( (txoutjson= dpow_gettxout(myinfo,coin,txid,vout)) != 0 )
{
if ( (coinaddr= jstr(txoutjson,"address")) != 0 && (value= SATOSHIDEN*jdouble(txoutjson,"value")) != 0 )
{
retjson = cJSON_CreateObject();
jaddstr(retjson,"result","success");
jaddstr(retjson,"address",coinaddr);
jadd64bits(retjson,"satoshis",value);
jaddnum(retjson,"value",dstr(value));
jaddnum(retjson,"amount",dstr(value));
height = dpow_getchaintip(myinfo,&blockhash,&blocktime,0,0,coin);
jaddnum(retjson,"height",height);
jaddnum(retjson,"numconfirms",jint(txoutjson,"confirmations"));
jaddbits256(retjson,"txid",txid);
jaddnum(retjson,"vout",vout);
jaddstr(retjson,"coin",coin->symbol);
}
else
{
free_json(txoutjson);
return(clonestr("{\"error\":\"return from gettxout missing fields\"}"));
}
free_json(txoutjson);
return(jprint(retjson,1));
} else return(clonestr("{\"error\":\"null return from gettxout\"}"));
}
if ( (basilisktag= juint(vals,"basilisktag")) == 0 )
basilisktag = rand();
if ( (timeoutmillis= juint(vals,"timeout")) <= 0 )
timeoutmillis = BASILISK_TIMEOUT;
if ( coin->FULLNODE > 0 && (ptr= basilisk_bitcoinvalue(&Lptr,myinfo,coin,remoteaddr,basilisktag,timeoutmillis,vals)) != 0 )
{
retstr = ptr->retstr, ptr->retstr = 0;
ptr->finished = OS_milliseconds() + 10000;
return(retstr);
}
}
if ( myinfo->reqsock >= 0 )
{
if ( (retstr= _dex_getrawtransaction(myinfo,symbol,txid)) != 0 )
{
if ( (txoutjson= cJSON_Parse(retstr)) != 0 )
{
//printf("TX.(%s)\n",jprint(txoutjson,0));
retjson = cJSON_CreateObject();
jaddstr(retjson,"result","success");
jaddnum(retjson,"numconfirms",jint(txoutjson,"confirmations"));
if ( (array= jarray(&n,txoutjson,"vout")) != 0 && vout < n && (txjson= jitem(array,vout)) != 0 )
{
//printf("txjson.(%s)\n",jprint(txjson,0));
if ( (value= jdouble(txjson,"value") * SATOSHIDEN) != 0 )
{
if ( (sobj= jobj(txjson,"scriptPubKey")) != 0 && (addrs= jarray(&m,sobj,"addresses")) != 0 && (coinaddr= jstri(addrs,0)) != 0 )
jaddstr(retjson,"address",coinaddr);
jadd64bits(retjson,"satoshis",value);
jaddnum(retjson,"value",dstr(value));
if ( (infostr= _dex_getinfo(myinfo,symbol)) != 0 )
{
if ( (info= cJSON_Parse(infostr)) != 0 )
{
if ( (height= jint(info,"blocks")) > 0 )
{
height -= jint(txoutjson,"confirmations");
jaddnum(retjson,"height",height);
}
free_json(info);
}
free(infostr);
}
jaddbits256(retjson,"txid",txid);
jaddnum(retjson,"vout",vout);
jaddstr(retjson,"coin",symbol);
free(retstr);
free_json(txoutjson);
return(jprint(retjson,1));
}
}
free_json(txoutjson);
return(jprint(retjson,1));
}
return(retstr);
}
}
return(basilisk_standardservice("VAL",myinfo,0,hash,vals,hexstr,1));
}
HASH_ARRAY_STRING(basilisk,rawtx,hash,vals,hexstr)
{
char *retstr=0,*symbol; uint32_t basilisktag; int32_t timeoutmillis,i,retval = -1; uint64_t amount,txfee; cJSON *retarray;
if ( vals == 0 )
return(clonestr("{\"error\":\"null valsobj\"}"));
//if ( coin == 0 )
{
if ( (symbol= jstr(vals,"symbol")) != 0 || (symbol= jstr(vals,"coin")) != 0 )
coin = iguana_coinfind(symbol);
}
if ( jobj(vals,"numrequired") == 0 )
jaddnum(vals,"numrequired",MIN(3,(int32_t)sqrt(myinfo->NOTARY.NUMRELAYS)+1));
if ( jobj(vals,"fanout") == 0 )
jaddnum(vals,"fanout",MAX(3,(int32_t)sqrt(myinfo->NOTARY.NUMRELAYS)+1));
if ( coin != 0 )
{
//if ( juint(vals,"burn") == 0 )
// jaddnum(vals,"burn",0.0001);
if ( (basilisktag= juint(vals,"basilisktag")) == 0 )
basilisktag = rand();
if ( (timeoutmillis= juint(vals,"timeout")) <= 0 )
timeoutmillis = BASILISK_TIMEOUT;
if ( (retstr= basilisk_bitcoinrawtx(myinfo,coin,remoteaddr,basilisktag,timeoutmillis,vals,0)) != 0 )
{
printf("rawtx.(%s)\n",retstr);
if ( (amount= j64bits(vals,"satoshis")) == 0 )
amount = jdouble(vals,"value") * SATOSHIDEN;
if ( (txfee= j64bits(vals,"txfee")) == 0 )
txfee = coin->chain->txfee;
if ( txfee == 0 )
txfee = 10000;
retval = -1;
if ( (retarray= cJSON_Parse(retstr)) != 0 )
{
if ( is_cJSON_Array(retarray) != 0 )
{
for (i=0; i<cJSON_GetArraySize(retarray); i++)
{
if ( basilisk_vins_validate(myinfo,coin,jitem(retarray,i),amount,txfee) == 0 )
{
retval = 0;
break;
}
}
} else retval = basilisk_vins_validate(myinfo,coin,retarray,amount,txfee);
if ( retval < 0 )
{
printf("ERROR.(%s)\n",retstr);
free(retstr);
retstr = clonestr("{\"error\":\"invalid vin in rawtx\"}");
}
}
}
} else retstr = clonestr("{\"error\":\"no coin specified or found\"}");
return(retstr);
}
STRING_ARG(jumblr,setpassphrase,passphrase)
{
cJSON *retjson; char KMDaddr[64],BTCaddr[64],wifstr[64]; bits256 privkey; struct iguana_info *coinbtc;
if ( passphrase == 0 || passphrase[0] == 0 || (coin= iguana_coinfind("KMD")) == 0 || coin->FULLNODE >= 0 )
return(clonestr("{\"error\":\"no passphrase or no native komodod\"}"));
else
{
safecopy(myinfo->jumblr_passphrase,passphrase,sizeof(myinfo->jumblr_passphrase));
retjson = cJSON_CreateObject();
jaddstr(retjson,"result","success");
privkey = jumblr_privkey(myinfo,BTCaddr,KMDaddr,JUMBLR_DEPOSITPREFIX);
smartaddress_add(myinfo,privkey,BTCaddr,KMDaddr);
myinfo->jumblr_depositkey = curve25519(privkey,curve25519_basepoint9());
bitcoin_priv2wif(wifstr,privkey,coin->chain->wiftype);
if ( coin->FULLNODE < 0 )
jumblr_importprivkey(myinfo,coin,wifstr);
jaddstr(retjson,"KMDdeposit",KMDaddr);
jaddstr(retjson,"BTCdeposit",BTCaddr);
if ( (coinbtc= iguana_coinfind("BTC")) != 0 )
{
bitcoin_priv2wif(wifstr,privkey,coinbtc->chain->wiftype);
if ( coinbtc->FULLNODE < 0 )
jumblr_importprivkey(myinfo,coinbtc,wifstr);
jaddnum(retjson,"BTCdeposits",dstr(jumblr_balance(myinfo,coinbtc,BTCaddr)));
}
privkey = jumblr_privkey(myinfo,BTCaddr,KMDaddr,"");
smartaddress_add(myinfo,privkey,BTCaddr,KMDaddr);
myinfo->jumblr_pubkey = curve25519(privkey,curve25519_basepoint9());
jaddstr(retjson,"KMDjumblr",KMDaddr);
jaddstr(retjson,"BTCjumblr",BTCaddr);
if ( coinbtc != 0 )
jaddnum(retjson,"BTCjumbled",dstr(jumblr_balance(myinfo,coinbtc,BTCaddr)));
return(jprint(retjson,1));
}
}
ZERO_ARGS(jumblr,status)
{
cJSON *retjson; char KMDaddr[64],BTCaddr[64]; struct jumblr_item *ptr,*tmp; struct iguana_info *coinbtc; int64_t received,deposited,jumblred,step_t2z,step_z2z,step_z2t,finished,pending,maxval,minval;
if ( strcmp(coin->symbol,"KMD") == 0 && coin->FULLNODE < 0 && myinfo->jumblr_passphrase[0] != 0 )
{
jumblr_opidsupdate(myinfo,coin);
retjson = cJSON_CreateObject();
step_t2z = step_z2z = step_z2t = deposited = finished = pending = 0;
jumblr_privkey(myinfo,BTCaddr,KMDaddr,JUMBLR_DEPOSITPREFIX);
jaddstr(retjson,"KMDdeposit",KMDaddr);
jaddstr(retjson,"BTCdeposit",BTCaddr);
if ( (coinbtc= iguana_coinfind("BTC")) != 0 )
jaddnum(retjson,"BTCdeposits",dstr(jumblr_balance(myinfo,coinbtc,BTCaddr)));
received = jumblr_receivedby(myinfo,coin,KMDaddr);
deposited = jumblr_balance(myinfo,coin,KMDaddr);
jumblr_privkey(myinfo,BTCaddr,KMDaddr,"");
jaddstr(retjson,"KMDjumblr",KMDaddr);
jaddstr(retjson,"BTCjumblr",BTCaddr);
if ( coinbtc != 0 )
jaddnum(retjson,"BTCjumbled",dstr(jumblr_balance(myinfo,coinbtc,BTCaddr)));
finished = jumblr_receivedby(myinfo,coin,KMDaddr);
jumblred = jumblr_balance(myinfo,coin,KMDaddr);
HASH_ITER(hh,myinfo->jumblrs,ptr,tmp)
{
if ( strlen(ptr->src) >= 40 )
{
if ( strlen(ptr->dest) >= 40 )
step_z2z += ptr->amount;
else step_z2t += ptr->amount;
} else step_t2z += ptr->amount;
}
jaddstr(retjson,"result","success");
jaddnum(retjson,"deposits",dstr(deposited));
jaddnum(retjson,"t_to_z",dstr(step_t2z));
jaddnum(retjson,"z_to_z",dstr(step_z2z));
jaddnum(retjson,"z_to_t",dstr(step_z2t));
maxval = MAX(step_t2z,MAX(step_z2z,step_z2t));
minval = MIN(step_t2z,MIN(step_z2z,step_z2t));
if ( maxval > minval )
{
pending = (maxval - minval);
if ( pending < finished*.1 )
pending = 0;
}
jaddnum(retjson,"pending",dstr(pending));
jaddnum(retjson,"jumbled",dstr(jumblred));
jaddnum(retjson,"received",dstr(received));
jaddnum(retjson,"finished",dstr(finished));
return(jprint(retjson,1));
}
else
{
printf("(%s) (%s) %d\n",coin->symbol,myinfo->jumblr_passphrase,coin->FULLNODE);
return(clonestr("{\"error\":\"jumblr status no passphrase or no native komodod\"}"));
}
}
HASH_ARRAY_STRING(basilisk,balances,hash,vals,hexstr)
{
@ -1067,4 +1502,366 @@ INT_ARG(iguana,paxfiats,mask)
komodo_assetcoins(1,mask);
return(clonestr("{\"result\":\"success\"}"));
}
int32_t utxocmp(cJSON *utxo,cJSON *utxo2)
{
bits256 txid,txid2; int32_t vout=-1,vout2=-1;
//printf("cmp (%s) vs (%s)\n",jprint(utxo,0),jprint(utxo2,0));
txid = jbits256(utxo,"txid");
vout = jint(utxo,"vout");
txid2 = jbits256(utxo2,"txid");
vout2 = jint(utxo2,"vout");
if ( bits256_cmp(txid,txid2) == 0 && vout == vout2 )
return(0);
else return(-1);
}
ZERO_ARGS(basilisk,cancelrefresh)
{
myinfo->cancelrefresh = 1;
return(clonestr("{\"result\":\"refresh cancel started\"}"));
}
TWO_STRINGS(basilisk,refresh,symbol,address)
{
cJSON *array=0,*array2=0,*array3,*item,*item2; char *retstr; int32_t i,j,n,m,vout; bits256 txid;
myinfo->cancelrefresh = 0;
if ( symbol != 0 && iguana_isnotarychain(symbol) >= 0 && address != 0 && address[0] != 0 )
{
if ( (retstr= _dex_listunspent(myinfo,symbol,address)) != 0 )
{
array = cJSON_Parse(retstr);
free(retstr);
}
if ( (retstr= _dex_listunspent2(myinfo,symbol,address)) != 0 )
{
if ( array == 0 )
array = cJSON_Parse(retstr);
else array2 = cJSON_Parse(retstr);
free(retstr);
}
if ( array != 0 && array2 != 0 ) // merge
{
m = cJSON_GetArraySize(array2);
array3 = jduplicate(array);
n = cJSON_GetArraySize(array3);
//printf("MERGE %s and %s\n",jprint(array,0),jprint(array2,0));
for (j=0; j<m; j++)
{
if ( myinfo->cancelrefresh != 0 )
break;
item2 = jitem(array2,j);
for (i=0; i<n; i++)
if ( utxocmp(jitem(array,i),item2) == 0 )
break;
if ( i == n )
{
//printf("FOUND NEW %s\n",jprint(item2,0));
jaddi(array3,jduplicate(item2));
}
}
free_json(array);
free_json(array2), array2 = 0;
array = array3, array3 = 0;
}
if ( array != 0 ) // gettxout
{
n = cJSON_GetArraySize(array);
array3 = cJSON_CreateArray();
for (i=0; i<n; i++)
{
if ( myinfo->cancelrefresh != 0 )
break;
item = jitem(array,i);
txid = jbits256(item,"txid");
vout = jint(item,"vout");
if ( (retstr= _dex_gettxout(myinfo,symbol,txid,vout)) != 0 )
{
if ( (item2= cJSON_Parse(retstr)) != 0 )
{
if ( jdouble(item2,"value") > 0 )
{
jaddbits256(item2,"txid",txid);
jaddnum(item2,"vout",vout);
jaddnum(item2,"amount",jdouble(item2,"value"));
//printf("%s\n",jprint(item2,0));
jaddi(array3,item2);
}
else free_json(item2);
}
free(retstr);
}
}
free_json(array);
myinfo->cancelrefresh = 0;
return(jprint(array3,1));
} else return(clonestr("[]"));
}
myinfo->cancelrefresh = 0;
return(clonestr("{\"error\":\"invalid coin or address specified\"}"));
}
STRING_ARRAY_OBJ_STRING(basilisk,utxorawtx,symbol,utxos,vals,ignore)
{
char *destaddr,*changeaddr; uint64_t satoshis,txfee; int32_t completed,sendflag,timelock;
timelock = jint(vals,"timelock");
sendflag = jint(vals,"sendflag");
satoshis = jdouble(vals,"amount") * SATOSHIDEN;
destaddr = jstr(vals,"destaddr");
changeaddr = jstr(vals,"changeaddr");
if ( destaddr != 0 && changeaddr != 0 && symbol != 0 && (coin= iguana_coinfind(symbol)) != 0 )
{
txfee = jdouble(vals,"txfee") * SATOSHIDEN;
return(iguana_utxorawtx(myinfo,coin,timelock,destaddr,changeaddr,satoshis,txfee,&completed,sendflag,utxos));
}
return(clonestr("{\"error\":\"invalid coin or address specified\"}"));
}
//int64_t iguana_verifytimelock(struct supernet_info *myinfo,struct iguana_info *coin,uint32_t timelocked,char *destaddr,bits256 txid,int32_t vout)
THREE_STRINGS_AND_DOUBLE(tradebot,aveprice,comment,base,rel,basevolume)
{
double retvals[4],aveprice; cJSON *retjson = cJSON_CreateObject();
aveprice = instantdex_avehbla(myinfo,retvals,base,rel,basevolume);
jaddstr(retjson,"result","success");
jaddnum(retjson,"aveprice",aveprice);
jaddnum(retjson,"avebid",retvals[0]);
jaddnum(retjson,"bidvol",retvals[1]);
jaddnum(retjson,"aveask",retvals[2]);
jaddnum(retjson,"askvol",retvals[3]);
return(jprint(retjson,1));
}
ZERO_ARGS(InstantDEX,allcoins)
{
struct iguana_info *tmp; cJSON *native,*notarychains,*basilisk,*virtual,*full,*retjson = cJSON_CreateObject();
full = cJSON_CreateArray();
native = cJSON_CreateArray();
basilisk = cJSON_CreateArray();
virtual = cJSON_CreateArray();
notarychains = cJSON_CreateArray();
HASH_ITER(hh,myinfo->allcoins,coin,tmp)
{
if ( coin->FULLNODE < 0 )
jaddistr(native,coin->symbol);
//else if ( coin->virtualchain != 0 )
// jaddistr(virtual,coin->symbol);
else if ( coin->FULLNODE > 0 )//|| coin->VALIDATENODE > 0 )
jaddistr(full,coin->symbol);
//else if ( coin->notarychain >= 0 )
// jaddistr(notarychains,coin->symbol);
else jaddistr(basilisk,coin->symbol);
}
jadd(retjson,"native",native);
jadd(retjson,"basilisk",basilisk);
jadd(retjson,"full",full);
//jadd(retjson,"virtual",virtual);
//jadd(retjson,"notarychains",notarychains);
return(jprint(retjson,1));
}
STRING_ARG(InstantDEX,available,source)
{
uint64_t total = 0; int32_t i,n=0; char coinaddr[64]; cJSON *item,*unspents,*retjson = 0;
if ( source != 0 && source[0] != 0 && (coin= iguana_coinfind(source)) != 0 )
{
if ( myinfo->expiration != 0 )
{
bitcoin_address(coinaddr,coin->chain->pubtype,myinfo->persistent_pubkey33,33);
if ( (unspents= basilisk_unspents(myinfo,coin,coinaddr)) != 0 )
{
//printf("available.(%s)\n",jprint(unspents,0));
if ( (n= cJSON_GetArraySize(unspents)) > 0 )
{
for (i=0; i<n; i++)
{
item = jitem(unspents,i);
//if ( is_cJSON_True(jobj(item,"spendable")) != 0 )
total += jdouble(item,"amount") * SATOSHIDEN;
//printf("(%s) -> %.8f\n",jprint(item,0),dstr(total));
}
}
free_json(unspents);
}
retjson = cJSON_CreateObject();
jaddnum(retjson,"result",dstr(total));
printf(" n.%d total %.8f (%s)\n",n,dstr(total),jprint(retjson,0));
return(jprint(retjson,1));
}
printf("InstantDEX_available: need to unlock wallet\n");
return(clonestr("{\"error\":\"need to unlock wallet\"}"));
}
printf("InstantDEX_available: %s is not active\n",source!=0?source:"");
return(clonestr("{\"error\":\"specified coin is not active\"}"));
}
HASH_ARRAY_STRING(InstantDEX,request,hash,vals,hexstr)
{
uint8_t serialized[512]; bits256 privkey; char buf[512],BTCaddr[64],KMDaddr[64]; struct basilisk_request R; int32_t jumblr,iambob,optionhours; cJSON *reqjson; uint32_t datalen=0,DEX_channel; struct iguana_info *bobcoin,*alicecoin;
myinfo->DEXactive = (uint32_t)time(NULL) + 3*BASILISK_TIMEOUT + 60;
jadd64bits(vals,"minamount",jdouble(vals,"minprice") * jdouble(vals,"amount") * SATOSHIDEN * SATOSHIDEN);
if ( jobj(vals,"desthash") == 0 )
jaddbits256(vals,"desthash",hash);
jadd64bits(vals,"satoshis",jdouble(vals,"amount") * SATOSHIDEN);
jadd64bits(vals,"destsatoshis",jdouble(vals,"destamount") * SATOSHIDEN);
jaddnum(vals,"timestamp",time(NULL));
if ( (jumblr= jint(vals,"usejumblr")) != 0 )
privkey = jumblr_privkey(myinfo,BTCaddr,KMDaddr,jumblr == 1 ? JUMBLR_DEPOSITPREFIX : "");
else privkey = myinfo->persistent_priv;
hash = curve25519(privkey,curve25519_basepoint9());
if ( jobj(vals,"srchash") == 0 )
jaddbits256(vals,"srchash",hash);
printf("service.(%s)\n",jprint(vals,0));
memset(&R,0,sizeof(R));
if ( basilisk_request_create(&R,vals,hash,juint(vals,"timestamp")) == 0 )
{
iambob = bitcoin_coinptrs(hash,&bobcoin,&alicecoin,R.src,R.dest,privkey,GENESIS_PUBKEY);
if ( (optionhours= jint(vals,"optionhours")) != 0 )
{
printf("iambob.%d optionhours.%d R.requestid.%u vs calc %u, q.%u\n",iambob,R.optionhours,R.requestid,basilisk_requestid(&R),R.quoteid);
if ( iambob != 0 && optionhours > 0 )
{
sprintf(buf,"{\"error\":\"illegal call option request hours.%d when iambob.%d\"}",optionhours,iambob);
printf("ERROR.(%s)\n",buf);
return(clonestr(buf));
}
else if ( iambob == 0 && optionhours < 0 )
{
sprintf(buf,"{\"error\":\"illegal put option request hours.%d when iambob.%d\"}",optionhours,iambob);
printf("ERROR.(%s)\n",buf);
return(clonestr(buf));
}
}
//if ( myinfo->IAMNOTARY != 0 || myinfo->NOTARY.RELAYID >= 0 )
// R.relaybits = myinfo->myaddr.myipbits;
if ( (reqjson= basilisk_requestjson(&R)) != 0 )
free_json(reqjson);
datalen = basilisk_rwDEXquote(1,serialized,&R);
//int32_t i; for (i=0; i<sizeof(R); i++)
// printf("%02x",((uint8_t *)&R)[i]);
printf(" R.requestid.%u vs calc %u, q.%u datalen.%d\n",R.requestid,basilisk_requestid(&R),R.quoteid,datalen);
basilisk_rwDEXquote(0,serialized,&R);
} else printf("error creating request\n");
if ( datalen > 0 )
{
uint32_t msgid;//,crc=0,crcs[2],numiters = 0; uint8_t buf[4096];
memset(hash.bytes,0,sizeof(hash));
msgid = (uint32_t)time(NULL);
DEX_channel = 'D' + ((uint32_t)'E' << 8) + ((uint32_t)'X' << 16);
basilisk_channelsend(myinfo,hash,hash,DEX_channel,msgid,serialized,datalen,60);
sleep(3);
/*while ( numiters < 10 && (crc= basilisk_crcsend(myinfo,0,buf,sizeof(buf),hash,myinfo->myaddr.persistent,DEX_channel,msgid,serialized,datalen,crcs)) == 0 )
{
//printf("didnt get back what was sent\n");
sleep(3);
basilisk_channelsend(myinfo,myinfo->myaddr.persistent,hash,DEX_channel,msgid,serialized,datalen,60);
numiters++;
}*/
//if ( crc != 0 )//basilisk_channelsend(myinfo,R.srchash,R.desthash,DEX_channel,(uint32_t)time(NULL),serialized,datalen,30) == 0 )
return(clonestr("{\"result\":\"DEX message sent\"}"));
//else return(clonestr("{\"error\":\"DEX message couldnt be sent\"}"));
}
return(clonestr("{\"error\":\"DEX message not sent\"}"));
}
INT_ARG(InstantDEX,automatched,requestid)
{
// return quoteid
myinfo->DEXactive = (uint32_t)time(NULL) + INSTANTDEX_LOCKTIME;
return(clonestr("{\"result\":\"automatched not yet\"}"));
}
int32_t InstantDEX_incoming_func(struct supernet_info *myinfo,void *ptr,uint8_t *data,int32_t datalen)
{
//int32_t i;
//for (i=0; i<datalen; i++)
// printf("%02x",data[i]);
//printf(" <- incoming\n");
return(0);
}
int32_t InstantDEX_process_channelget(struct supernet_info *myinfo,void *ptr,int32_t (*internal_func)(struct supernet_info *myinfo,void *ptr,uint8_t *data,int32_t datalen),uint32_t channel,uint32_t msgid,uint8_t *data,int32_t datalen,uint32_t expiration,uint32_t duration)
{
return((*internal_func)(myinfo,ptr,data,datalen));
}
INT_ARG(InstantDEX,incoming,requestid)
{
cJSON *retjson,*retarray; bits256 zero; uint32_t DEX_channel,msgid,now; int32_t retval,width,drift=3; uint8_t data[32768];
now = (uint32_t)time(NULL);
memset(&zero,0,sizeof(zero));
width = (now - myinfo->DEXpoll) + 2*drift;
if ( width < (drift+1) )
width = 2*drift+1;
else if ( width > 64 )
width = 64;
myinfo->DEXpoll = now;
retjson = cJSON_CreateObject();
DEX_channel = 'D' + ((uint32_t)'E' << 8) + ((uint32_t)'X' << 16);
msgid = (uint32_t)time(NULL) + drift;
if ( (retarray= basilisk_channelget(myinfo,zero,myinfo->myaddr.persistent,DEX_channel,msgid,width)) != 0 )
{
//printf("GOT.(%s)\n",jprint(retarray,0));
if ( (retval= basilisk_process_retarray(myinfo,0,InstantDEX_process_channelget,data,sizeof(data),DEX_channel,msgid,retarray,InstantDEX_incoming_func)) > 0 )
{
jaddstr(retjson,"result","success");
} else jaddstr(retjson,"error","cant process InstantDEX retarray");
jadd(retjson,"responses",retarray);
}
else
{
jaddstr(retjson,"error","cant do InstantDEX channelget");
printf("error channelget\n");
}
return(jprint(retjson,1));
}
/*TWO_INTS(InstantDEX,swapstatus,requestid,quoteid)
{
cJSON *vals; char *retstr;
myinfo->DEXactive = (uint32_t)time(NULL) + INSTANTDEX_LOCKTIME;
//if ( myinfo->IAMLP != 0 )
// return(basilisk_respond_swapstatus(myinfo,myinfo->myaddr.persistent,requestid,quoteid));
//else
{
vals = cJSON_CreateObject();
jaddnum(vals,"requestid",(uint32_t)requestid);
jaddnum(vals,"quoteid",(uint32_t)quoteid);
jaddbits256(vals,"hash",myinfo->myaddr.persistent);
retstr = basilisk_standardservice("SWP",myinfo,0,myinfo->myaddr.persistent,vals,"",1);
free_json(vals);
return(retstr);
}
}*/
TWO_INTS(InstantDEX,accept,requestid,quoteid)
{
cJSON *vals; char *retstr;
myinfo->DEXactive = (uint32_t)time(NULL) + INSTANTDEX_LOCKTIME;
if ( myinfo->IAMLP != 0 || myinfo->dexsock >= 0 || myinfo->subsock >= 0 )
return(basilisk_respond_accept(myinfo,myinfo->persistent_priv,requestid,quoteid,&myinfo->DEXaccept));
else
{
vals = cJSON_CreateObject();
jaddnum(vals,"quoteid",(uint32_t)quoteid);
jaddnum(vals,"requestid",(uint32_t)requestid);
retstr = basilisk_standardservice("ACC",myinfo,0,myinfo->myaddr.persistent,vals,"",1);
free_json(vals);
return(retstr);
}
}
ZERO_ARGS(InstantDEX,init)
{
basilisk_swaps_init(myinfo);
return(clonestr("{\"result\":\"success\"}"));
}
ZERO_ARGS(InstantDEX,getswaplist)
{
return(basilisk_swaplist(myinfo));
}
#include "../includes/iguana_apiundefs.h"

27
basilisk/basilisk.h

@ -16,7 +16,7 @@
#ifndef H_BASILISK_H
#define H_BASILISK_H
//#define BASILISK_DISABLESENDTX
#define BASILISK_DISABLESENDTX
#define BASILISK_DISABLEWAITTX
#include "../iguana/iguana777.h"
@ -37,13 +37,16 @@
#define INSTANTDEX_INSURANCEDIV 777
#define INSTANTDEX_PUBKEY "03bc2c7ba671bae4a6fc835244c9762b41647b9827d4780a89a949b984a8ddcc06"
#define INSTANTDEX_RMD160 "ca1e04745e8ca0c60d8c5881531d51bec470743f"
#define JUMBLR_RMD160 "5177f8b427e5f47342a4b8ab5dac770815d4389e"
#define TIERNOLAN_RMD160 "daedddd8dbe7a2439841ced40ba9c3d375f98146"
#define INSTANTDEX_BTC "1KRhTPvoxyJmVALwHFXZdeeWFbcJSbkFPu"
#define INSTANTDEX_BTCD "RThtXup6Zo7LZAi8kRWgjAyi1s4u6U9Cpf"
struct basilisk_swap;
struct basilisk_rawtxinfo
{
char destaddr[64];
char destaddr[64],coinstr[16];
bits256 txid,signedtxid,actualtxid;
uint64_t amount,change,inputsum;
int32_t redeemlen,datalen,completed,vintype,vouttype,numconfirms,spendlen,secretstart,suppress_pubkeys;
@ -57,8 +60,9 @@ struct basilisk_rawtx
struct iguana_msgtx msgtx;
struct basilisk_rawtxinfo I;
struct iguana_info *coin;
char vinstr[8192];
cJSON *vins;
uint8_t *txbytes,spendscript[512],redeemscript[1024],extraspace[1024];
uint8_t txbytes[16384],spendscript[512],redeemscript[1024],extraspace[4096];
};
struct basilisk_swapinfo
@ -67,27 +71,16 @@ struct basilisk_swapinfo
char bobstr[64],alicestr[64];
bits256 myhash,otherhash,orderhash;
uint32_t statebits,otherstatebits,started,expiration,finished,dead,reftime,putduration,callduration;
int32_t bobconfirms,aliceconfirms,iambob,reclaimed;
int32_t bobconfirms,aliceconfirms,iambob,reclaimed,bobspent,alicespent,pad;
uint64_t alicesatoshis,bobsatoshis,bobinsurance,aliceinsurance;
bits256 myprivs[2],mypubs[2],otherpubs[2],pubA0,pubA1,pubB0,pubB1,privAm,pubAm,privBn,pubBn;
uint32_t crcs_mypub[2],crcs_mychoosei[2],crcs_myprivs[2],crcs_mypriv[2];
int32_t choosei,otherchoosei,cutverified,otherverifiedcut,numpubs,havestate,otherhavestate;
int32_t choosei,otherchoosei,cutverified,otherverifiedcut,numpubs,havestate,otherhavestate,pad2;
uint8_t secretAm[20],secretBn[20];
uint8_t secretAm256[32],secretBn256[32];
};
struct basilisk_swap
{
struct supernet_info *myinfo; struct iguana_info *bobcoin,*alicecoin;
void (*balancingtrade)(struct supernet_info *myinfo,struct basilisk_swap *swap,int32_t iambob);
struct basilisk_swapinfo I;
struct basilisk_rawtx bobdeposit,bobpayment,alicepayment,myfee,otherfee,aliceclaim,alicespend,bobreclaim,bobspend,bobrefund,alicereclaim;
bits256 privkeys[INSTANTDEX_DECKSIZE];
uint64_t otherdeck[INSTANTDEX_DECKSIZE][2],deck[INSTANTDEX_DECKSIZE][2];
uint8_t verifybuf[65536];
};
struct basilisk_value { bits256 txid; int64_t value; int32_t height; int16_t vout; char coinaddr[64]; };
struct basilisk_item
@ -135,7 +128,7 @@ int32_t basilisk_update(char *symbol,uint32_t reftimestamp);
void basilisk_seqresult(struct supernet_info *myinfo,char *retstr);
struct iguana_info *basilisk_geckochain(struct supernet_info *myinfo,char *symbol,char *chainname,cJSON *valsobj);
void basilisk_alicepayment(struct supernet_info *myinfo,struct basilisk_swap *swap,struct iguana_info *coin,struct basilisk_rawtx *alicepayment,bits256 pubAm,bits256 pubBn);
void basilisk_rawtx_setparms(char *name,struct supernet_info *myinfo,struct basilisk_swap *swap,struct basilisk_rawtx *rawtx,struct iguana_info *coin,int32_t numconfirms,int32_t vintype,uint64_t satoshis,int32_t vouttype,uint8_t *pubkey33);
void basilisk_rawtx_setparms(char *name,uint32_t quoteid,struct basilisk_rawtx *rawtx,struct iguana_info *coin,int32_t numconfirms,int32_t vintype,uint64_t satoshis,int32_t vouttype,uint8_t *pubkey33,int32_t jumblrflag);
void basilisk_setmyid(struct supernet_info *myinfo);
int32_t basilisk_rwDEXquote(int32_t rwflag,uint8_t *serialized,struct basilisk_request *rp);
cJSON *basilisk_requestjson(struct basilisk_request *rp);

307
basilisk/basilisk_DEX.c

@ -229,15 +229,17 @@ int32_t basilisk_request_create(struct basilisk_request *rp,cJSON *valsobj,bits2
return(-1);
}
char *basilisk_start(struct supernet_info *myinfo,struct basilisk_request *_rp,uint32_t statebits,int32_t optionduration)
char *basilisk_start(struct supernet_info *myinfo,bits256 privkey,struct basilisk_request *_rp,uint32_t statebits,int32_t optionduration)
{
cJSON *retjson; struct basilisk_request *rp=0; int32_t i;
cJSON *retjson; bits256 tmpprivkey; struct basilisk_request *rp=0; int32_t i,srcmatch,destmatch;
if ( _rp->requestid == myinfo->lastdexrequestid )
{
//printf("filter duplicate r%u\n",_rp->requestid);
return(clonestr("{\"error\":\"filter duplicate requestid\"}"));
}
if ( (bits256_cmp(_rp->srchash,myinfo->myaddr.persistent) == 0 || bits256_cmp(_rp->desthash,myinfo->myaddr.persistent) == 0) )
srcmatch = smartaddress_pubkey(myinfo,&tmpprivkey,_rp->srchash) >= 0;
destmatch = smartaddress_pubkey(myinfo,&tmpprivkey,_rp->desthash) >= 0;
if ( srcmatch != 0 || destmatch != 0 )
{
for (i=0; i<myinfo->numswaps; i++)
if ( myinfo->swaps[i]->I.req.requestid == _rp->requestid )
@ -251,12 +253,11 @@ char *basilisk_start(struct supernet_info *myinfo,struct basilisk_request *_rp,u
*rp = *_rp;
printf("START thread to complete %u/%u for (%s %.8f) <-> (%s %.8f) q.%u\n",rp->requestid,rp->quoteid,rp->src,dstr(rp->srcamount),rp->dest,dstr(rp->destamount),rp->quoteid);
myinfo->lastdexrequestid = rp->requestid;
if ( basilisk_thread_start(myinfo,rp,statebits,optionduration) != 0 )
if ( basilisk_thread_start(myinfo,privkey,rp,statebits,optionduration,0) != 0 )
{
basilisk_request_enqueue(myinfo,rp);
return(clonestr("{\"result\":\"started atomic swap thread\"}"));
}
else return(clonestr("{\"error\":\"couldnt atomic swap thread\"}"));
} else return(clonestr("{\"error\":\"couldnt atomic swap thread\"}"));
}
else
{
@ -275,8 +276,8 @@ char *basilisk_start(struct supernet_info *myinfo,struct basilisk_request *_rp,u
void basilisk_requests_poll(struct supernet_info *myinfo)
{
static uint32_t lastpoll;
char *retstr; uint8_t data[32768]; cJSON *outerarray,*retjson; uint32_t msgid,channel; int32_t datalen,i,n; struct basilisk_request issueR; double hwm = 0.;
if ( time(NULL) < lastpoll+3 )
char *retstr; uint8_t data[32768]; cJSON *outerarray,*retjson; uint32_t msgid,channel; int32_t datalen,i,n; struct basilisk_request issueR; bits256 privkey; double hwm = 0.;
if ( myinfo->IAMNOTARY != 0 || time(NULL) < lastpoll+20 || (myinfo->IAMLP == 0 && myinfo->DEXactive < time(NULL)) )
return;
lastpoll = (uint32_t)time(NULL);
memset(&issueR,0,sizeof(issueR));
@ -299,42 +300,15 @@ void basilisk_requests_poll(struct supernet_info *myinfo)
channel = 'D' + ((uint32_t)'E' << 8) + ((uint32_t)'X' << 16);
if ( hwm > 0. )
{
//printf("hwm %f\n",hwm);
//for (i=0; i<sizeof(issueR); i++)
// printf("%02x",((uint8_t *)&issueR)[i]);
//printf("\n");
myinfo->DEXaccept = issueR;
/*issueR.quoteid = basilisk_quoteid(&issueR);
datalen = basilisk_rwDEXquote(1,data,&issueR);
msgid = (uint32_t)time(NULL);
keylen = basilisk_messagekey(key,0,msgid,issueR.srchash,issueR.desthash);
if ( (retstr= basilisk_respond_addmessage(myinfo,key,keylen,data,datalen,0,BASILISK_DEXDURATION)) != 0 )
free(retstr);*/
if ( bits256_cmp(myinfo->myaddr.persistent,issueR.srchash) == 0 ) // my request
if ( smartaddress_pubkey(myinfo,&privkey,issueR.srchash) >= 0 )
{
printf("matched dex_smartpubkey\n");
dex_channelsend(myinfo,issueR.srchash,issueR.desthash,channel,0x4000000,(void *)&issueR.requestid,sizeof(issueR.requestid)); // 60
dpow_nanomsg_update(myinfo);
dex_updateclient(myinfo);
if ( (retstr= basilisk_start(myinfo,&issueR,1,issueR.optionhours * 3600)) != 0 )
free(retstr);
/*if ( (retstr= InstantDEX_accept(myinfo,0,0,0,issueR.requestid,issueR.quoteid)) != 0 )
if ( (retstr= basilisk_start(myinfo,privkey,&issueR,1,issueR.optionhours * 3600)) != 0 )
free(retstr);
printf("my req hwm %f -> %u\n",hwm,issueR.requestid);
basilisk_channelsend(myinfo,issueR.srchash,issueR.desthash,channel,0x4000000,(void *)&issueR.requestid,sizeof(issueR.requestid),60);
numiters = crc = 0;
while ( numiters < 10 && (crc= basilisk_crcsend(myinfo,0,buf,sizeof(buf),issueR.srchash,issueR.desthash,channel,0x4000000,(void *)&issueR.requestid,sizeof(issueR.requestid),crcs)) == 0 )
{
printf("didnt get back what was sent\n");
sleep(3);
basilisk_channelsend(myinfo,issueR.srchash,issueR.desthash,channel,0x4000000,(void *)&issueR.requestid,sizeof(issueR.requestid),60);
numiters++;
}
if ( crc != 0 )
{
printf("crc.%08x -> basilisk_starta\n",crc);
if ( (retstr= basilisk_start(myinfo,&issueR,1,issueR.optionhours * 3600)) != 0 )
free(retstr);
} // else printf("couldnt accept offer\n");*/
}
else if ( issueR.requestid != myinfo->lastdexrequestid )//if ( issueR.quoteid == 0 )
{
@ -346,24 +320,8 @@ void basilisk_requests_poll(struct supernet_info *myinfo)
dex_channelsend(myinfo,issueR.desthash,issueR.srchash,channel,msgid,data,datalen); //INSTANTDEX_LOCKTIME*2
dpow_nanomsg_update(myinfo);
dex_updateclient(myinfo);
if ( (retstr= basilisk_start(myinfo,&issueR,0,issueR.optionhours * 3600)) != 0 )
if ( (retstr= basilisk_start(myinfo,myinfo->persistent_priv,&issueR,0,issueR.optionhours * 3600)) != 0 )
free(retstr);
/*crcs[0] = crcs[1] = 0;
numiters = 0;
basilisk_channelsend(myinfo,issueR.desthash,issueR.srchash,channel,msgid,data,datalen,INSTANTDEX_LOCKTIME*2);
while ( numiters < 10 && (crc= basilisk_crcsend(myinfo,0,buf,sizeof(buf),issueR.desthash,issueR.srchash,channel,msgid,data,datalen,crcs)) == 0 )
{
//printf("didnt get back what was sent\n");
sleep(3);
basilisk_channelsend(myinfo,issueR.desthash,issueR.srchash,channel,msgid,data,datalen,INSTANTDEX_LOCKTIME*2);
numiters++;
}
if ( crc != 0 )
{
printf("crc.%08x -> basilisk_start\n",crc);
if ( (retstr= basilisk_start(myinfo,&issueR,0,issueR.optionhours * 3600)) != 0 )
free(retstr);
}*/
} //else printf("basilisk_requests_poll unexpected hwm issueR\n");
}
}
@ -489,7 +447,7 @@ char *basilisk_respond_requests(struct supernet_info *myinfo,bits256 hash,uint32
return(jprint(retjson,1));
}
char *basilisk_respond_accept(struct supernet_info *myinfo,uint32_t requestid,uint32_t quoteid,struct basilisk_request *refrp)
char *basilisk_respond_accept(struct supernet_info *myinfo,bits256 privkey,uint32_t requestid,uint32_t quoteid,struct basilisk_request *refrp)
{
int32_t i,num=0; char *retstr=0; struct basilisk_request *requests,*rp; uint8_t space[4096];
portable_mutex_lock(&myinfo->DEX_reqmutex);
@ -501,7 +459,7 @@ char *basilisk_respond_accept(struct supernet_info *myinfo,uint32_t requestid,ui
if ( rp->requestid == requestid && rp->quoteid == quoteid )
{
printf("start from accept\n");
retstr = basilisk_start(myinfo,rp,1,0);
retstr = basilisk_start(myinfo,privkey,rp,1,0);
break;
}
}
@ -513,51 +471,6 @@ char *basilisk_respond_accept(struct supernet_info *myinfo,uint32_t requestid,ui
retstr = clonestr("{\"error\":\"couldnt find to requestid to choose\"}");
return(retstr);
}
#include "../includes/iguana_apidefs.h"
#include "../includes/iguana_apideclares.h"
THREE_STRINGS_AND_DOUBLE(tradebot,aveprice,comment,base,rel,basevolume)
{
double retvals[4],aveprice; cJSON *retjson = cJSON_CreateObject();
aveprice = instantdex_avehbla(myinfo,retvals,base,rel,basevolume);
jaddstr(retjson,"result","success");
jaddnum(retjson,"aveprice",aveprice);
jaddnum(retjson,"avebid",retvals[0]);
jaddnum(retjson,"bidvol",retvals[1]);
jaddnum(retjson,"aveask",retvals[2]);
jaddnum(retjson,"askvol",retvals[3]);
return(jprint(retjson,1));
}
ZERO_ARGS(InstantDEX,allcoins)
{
struct iguana_info *tmp; cJSON *native,*notarychains,*basilisk,*virtual,*full,*retjson = cJSON_CreateObject();
full = cJSON_CreateArray();
native = cJSON_CreateArray();
basilisk = cJSON_CreateArray();
virtual = cJSON_CreateArray();
notarychains = cJSON_CreateArray();
HASH_ITER(hh,myinfo->allcoins,coin,tmp)
{
if ( coin->FULLNODE < 0 )
jaddistr(native,coin->symbol);
//else if ( coin->virtualchain != 0 )
// jaddistr(virtual,coin->symbol);
else if ( coin->FULLNODE > 0 )//|| coin->VALIDATENODE > 0 )
jaddistr(full,coin->symbol);
//else if ( coin->notarychain >= 0 )
// jaddistr(notarychains,coin->symbol);
else jaddistr(basilisk,coin->symbol);
}
jadd(retjson,"native",native);
jadd(retjson,"basilisk",basilisk);
jadd(retjson,"full",full);
//jadd(retjson,"virtual",virtual);
//jadd(retjson,"notarychains",notarychains);
return(jprint(retjson,1));
}
cJSON *basilisk_unspents(struct supernet_info *myinfo,struct iguana_info *coin,char *coinaddr)
{
cJSON *unspents=0,*array=0; char *retstr;
@ -570,7 +483,7 @@ cJSON *basilisk_unspents(struct supernet_info *myinfo,struct iguana_info *coin,c
}
else if ( coin->FULLNODE == 0 )
{
if ( (retstr= _dex_listunspent(myinfo,coin->symbol,coinaddr)) != 0 )
if ( (retstr= dex_listunspent(myinfo,coin,0,0,coin->symbol,coinaddr)) != 0 )
{
unspents = cJSON_Parse(retstr);
free(retstr);
@ -600,191 +513,3 @@ char *basilisk_sendrawtransaction(struct supernet_info *myinfo,struct iguana_inf
return(retstr);
}
STRING_ARG(InstantDEX,available,source)
{
uint64_t total = 0; int32_t i,n=0; char coinaddr[64]; cJSON *item,*unspents,*retjson = 0;
if ( source != 0 && source[0] != 0 && (coin= iguana_coinfind(source)) != 0 )
{
if ( myinfo->expiration != 0 )
{
bitcoin_address(coinaddr,coin->chain->pubtype,myinfo->persistent_pubkey33,33);
if ( (unspents= basilisk_unspents(myinfo,coin,coinaddr)) != 0 )
{
//printf("available.(%s)\n",jprint(unspents,0));
if ( (n= cJSON_GetArraySize(unspents)) > 0 )
{
for (i=0; i<n; i++)
{
item = jitem(unspents,i);
//if ( is_cJSON_True(jobj(item,"spendable")) != 0 )
total += jdouble(item,"amount") * SATOSHIDEN;
//printf("(%s) -> %.8f\n",jprint(item,0),dstr(total));
}
}
free_json(unspents);
}
retjson = cJSON_CreateObject();
jaddnum(retjson,"result",dstr(total));
printf(" n.%d total %.8f (%s)\n",n,dstr(total),jprint(retjson,0));
return(jprint(retjson,1));
}
printf("InstantDEX_available: need to unlock wallet\n");
return(clonestr("{\"error\":\"need to unlock wallet\"}"));
}
printf("InstantDEX_available: %s is not active\n",source!=0?source:"");
return(clonestr("{\"error\":\"specified coin is not active\"}"));
}
HASH_ARRAY_STRING(InstantDEX,request,hash,vals,hexstr)
{
uint8_t serialized[512]; char buf[512]; struct basilisk_request R; int32_t iambob,optionhours; cJSON *reqjson; uint32_t datalen=0,DEX_channel; struct iguana_info *bobcoin,*alicecoin;
myinfo->DEXactive = (uint32_t)time(NULL) + 3*BASILISK_TIMEOUT + 60;
jadd64bits(vals,"minamount",jdouble(vals,"minprice") * jdouble(vals,"amount") * SATOSHIDEN);
if ( jobj(vals,"srchash") == 0 )
jaddbits256(vals,"srchash",myinfo->myaddr.persistent);
if ( jobj(vals,"desthash") == 0 )
jaddbits256(vals,"desthash",hash);
jadd64bits(vals,"satoshis",jdouble(vals,"amount") * SATOSHIDEN);
jadd64bits(vals,"destsatoshis",jdouble(vals,"destamount") * SATOSHIDEN);
jaddnum(vals,"timestamp",time(NULL));
hash = myinfo->myaddr.persistent;
printf("service.(%s)\n",jprint(vals,0));
memset(&R,0,sizeof(R));
if ( basilisk_request_create(&R,vals,hash,juint(vals,"timestamp")) == 0 )
{
iambob = bitcoin_coinptrs(myinfo,&bobcoin,&alicecoin,R.src,R.dest,myinfo->myaddr.persistent,GENESIS_PUBKEY);
if ( (optionhours= jint(vals,"optionhours")) != 0 )
{
printf("iambob.%d optionhours.%d R.requestid.%u vs calc %u, q.%u\n",iambob,R.optionhours,R.requestid,basilisk_requestid(&R),R.quoteid);
if ( iambob != 0 && optionhours > 0 )
{
sprintf(buf,"{\"error\":\"illegal call option request hours.%d when iambob.%d\"}",optionhours,iambob);
printf("ERROR.(%s)\n",buf);
return(clonestr(buf));
}
else if ( iambob == 0 && optionhours < 0 )
{
sprintf(buf,"{\"error\":\"illegal put option request hours.%d when iambob.%d\"}",optionhours,iambob);
printf("ERROR.(%s)\n",buf);
return(clonestr(buf));
}
}
//if ( myinfo->IAMNOTARY != 0 || myinfo->NOTARY.RELAYID >= 0 )
// R.relaybits = myinfo->myaddr.myipbits;
if ( (reqjson= basilisk_requestjson(&R)) != 0 )
free_json(reqjson);
datalen = basilisk_rwDEXquote(1,serialized,&R);
//int32_t i; for (i=0; i<sizeof(R); i++)
// printf("%02x",((uint8_t *)&R)[i]);
printf(" R.requestid.%u vs calc %u, q.%u datalen.%d\n",R.requestid,basilisk_requestid(&R),R.quoteid,datalen);
basilisk_rwDEXquote(0,serialized,&R);
} else printf("error creating request\n");
if ( datalen > 0 )
{
uint32_t msgid,crc,crcs[2],numiters = 0; uint8_t buf[4096];
memset(hash.bytes,0,sizeof(hash));
msgid = (uint32_t)time(NULL);
DEX_channel = 'D' + ((uint32_t)'E' << 8) + ((uint32_t)'X' << 16);
basilisk_channelsend(myinfo,myinfo->myaddr.persistent,hash,DEX_channel,msgid,serialized,datalen,60);
sleep(3);
while ( numiters < 10 && (crc= basilisk_crcsend(myinfo,0,buf,sizeof(buf),hash,myinfo->myaddr.persistent,DEX_channel,msgid,serialized,datalen,crcs)) == 0 )
{
//printf("didnt get back what was sent\n");
sleep(3);
basilisk_channelsend(myinfo,myinfo->myaddr.persistent,hash,DEX_channel,msgid,serialized,datalen,60);
numiters++;
}
if ( crc != 0 )//basilisk_channelsend(myinfo,R.srchash,R.desthash,DEX_channel,(uint32_t)time(NULL),serialized,datalen,30) == 0 )
return(clonestr("{\"result\":\"DEX message sent\"}"));
else return(clonestr("{\"error\":\"DEX message couldnt be sent\"}"));
}
return(clonestr("{\"error\":\"DEX message not sent\"}"));
}
INT_ARG(InstantDEX,automatched,requestid)
{
// return quoteid
myinfo->DEXactive = (uint32_t)time(NULL) + INSTANTDEX_LOCKTIME;
return(clonestr("{\"result\":\"automatched not yet\"}"));
}
int32_t InstantDEX_incoming_func(struct supernet_info *myinfo,void *ptr,uint8_t *data,int32_t datalen)
{
//int32_t i;
//for (i=0; i<datalen; i++)
// printf("%02x",data[i]);
//printf(" <- incoming\n");
return(0);
}
int32_t InstantDEX_process_channelget(struct supernet_info *myinfo,void *ptr,int32_t (*internal_func)(struct supernet_info *myinfo,void *ptr,uint8_t *data,int32_t datalen),uint32_t channel,uint32_t msgid,uint8_t *data,int32_t datalen,uint32_t expiration,uint32_t duration)
{
return((*internal_func)(myinfo,ptr,data,datalen));
}
INT_ARG(InstantDEX,incoming,requestid)
{
cJSON *retjson,*retarray; bits256 zero; uint32_t DEX_channel,msgid,now; int32_t retval,width,drift=3; uint8_t data[32768];
now = (uint32_t)time(NULL);
memset(&zero,0,sizeof(zero));
width = (now - myinfo->DEXpoll) + 2*drift;
if ( width < (drift+1) )
width = 2*drift+1;
else if ( width > 64 )
width = 64;
myinfo->DEXpoll = now;
retjson = cJSON_CreateObject();
DEX_channel = 'D' + ((uint32_t)'E' << 8) + ((uint32_t)'X' << 16);
msgid = (uint32_t)time(NULL) + drift;
if ( (retarray= basilisk_channelget(myinfo,zero,myinfo->myaddr.persistent,DEX_channel,msgid,width)) != 0 )
{
//printf("GOT.(%s)\n",jprint(retarray,0));
if ( (retval= basilisk_process_retarray(myinfo,0,InstantDEX_process_channelget,data,sizeof(data),DEX_channel,msgid,retarray,InstantDEX_incoming_func)) > 0 )
{
jaddstr(retjson,"result","success");
} else jaddstr(retjson,"error","cant process InstantDEX retarray");
jadd(retjson,"responses",retarray);
}
else
{
jaddstr(retjson,"error","cant do InstantDEX channelget");
printf("error channelget\n");
}
return(jprint(retjson,1));
}
/*TWO_INTS(InstantDEX,swapstatus,requestid,quoteid)
{
cJSON *vals; char *retstr;
myinfo->DEXactive = (uint32_t)time(NULL) + INSTANTDEX_LOCKTIME;
//if ( myinfo->IAMLP != 0 )
// return(basilisk_respond_swapstatus(myinfo,myinfo->myaddr.persistent,requestid,quoteid));
//else
{
vals = cJSON_CreateObject();
jaddnum(vals,"requestid",(uint32_t)requestid);
jaddnum(vals,"quoteid",(uint32_t)quoteid);
jaddbits256(vals,"hash",myinfo->myaddr.persistent);
retstr = basilisk_standardservice("SWP",myinfo,0,myinfo->myaddr.persistent,vals,"",1);
free_json(vals);
return(retstr);
}
}*/
TWO_INTS(InstantDEX,accept,requestid,quoteid)
{
cJSON *vals; char *retstr;
myinfo->DEXactive = (uint32_t)time(NULL) + INSTANTDEX_LOCKTIME;
if ( myinfo->IAMLP != 0 || myinfo->dexsock >= 0 || myinfo->subsock >= 0 )
return(basilisk_respond_accept(myinfo,requestid,quoteid,&myinfo->DEXaccept));
else
{
vals = cJSON_CreateObject();
jaddnum(vals,"quoteid",(uint32_t)quoteid);
jaddnum(vals,"requestid",(uint32_t)requestid);
retstr = basilisk_standardservice("ACC",myinfo,0,myinfo->myaddr.persistent,vals,"",1);
free_json(vals);
return(retstr);
}
}
#include "../includes/iguana_apiundefs.h"

120
basilisk/basilisk_MSG.c

@ -98,12 +98,16 @@ char *basilisk_iterate_MSG(struct supernet_info *myinfo,uint32_t channel,uint32_
// char str[65],str2[65]; printf("MSGiterate (%s) -> (%s)\n",bits256_str(str,srchash),bits256_str(str2,desthash));
array = cJSON_CreateArray();
portable_mutex_lock(&myinfo->messagemutex);
//printf("iterate_MSG allflag.%d width.%d channel.%d msgid.%d src.%llx -> %llx\n",allflag,origwidth,channel,msgid,(long long)srchash.txid,(long long)desthash.txid);
//printf("iterate_MSG width.%d channel.%d msgid.%d src.%llx -> %llx\n",origwidth,channel,msgid,(long long)srchash.txid,(long long)desthash.txid);
for (i=0; i<width; i++)
{
keylen = basilisk_messagekey(key,channel,msgid,srchash,desthash);
if ( (item= _basilisk_respond_getmessage(myinfo,key,keylen)) != 0 )
jaddi(array,item);//, printf("gotmsg0.(%s)\n",jprint(item,0));
{
jaddbits256(item,"src",srchash);
jaddbits256(item,"dest",desthash);
jaddi(array,item);
}
//keylen = basilisk_messagekey(key,channel,msgid,desthash,srchash);
//if ( (item= _basilisk_respond_getmessage(myinfo,key,keylen)) != 0 )
// jaddi(array,item);//, printf("gotmsg0.(%s)\n",jprint(item,0));
@ -113,7 +117,11 @@ char *basilisk_iterate_MSG(struct supernet_info *myinfo,uint32_t channel,uint32_
{
keylen = basilisk_messagekey(key,channel,msgid,zero,desthash);
if ( (item= _basilisk_respond_getmessage(myinfo,key,keylen)) != 0 )
jaddi(array,item);//, printf("gotmsg1.(%s)\n",jprint(item,0));
{
jaddbits256(item,"src",srchash);
jaddbits256(item,"dest",desthash);
jaddi(array,item);
}
//keylen = basilisk_messagekey(key,channel,msgid,desthash,zero);
//if ( (item= _basilisk_respond_getmessage(myinfo,key,keylen)) != 0 )
// jaddi(array,item);//, printf("gotmsg1.(%s)\n",jprint(item,0));
@ -122,7 +130,11 @@ char *basilisk_iterate_MSG(struct supernet_info *myinfo,uint32_t channel,uint32_
{
keylen = basilisk_messagekey(key,channel,msgid,srchash,zero);
if ( (item= _basilisk_respond_getmessage(myinfo,key,keylen)) != 0 )
jaddi(array,item);//, printf("gotmsg2.(%s)\n",jprint(item,0));
{
jaddbits256(item,"src",srchash);
jaddbits256(item,"dest",desthash);
jaddi(array,item);
}
//keylen = basilisk_messagekey(key,channel,msgid,zero,srchash);
//if ( (item= _basilisk_respond_getmessage(myinfo,key,keylen)) != 0 )
// jaddi(array,item);//, printf("gotmsg2.(%s)\n",jprint(item,0));
@ -131,7 +143,11 @@ char *basilisk_iterate_MSG(struct supernet_info *myinfo,uint32_t channel,uint32_
{
keylen = basilisk_messagekey(key,channel,msgid,zero,zero);
if ( (item= _basilisk_respond_getmessage(myinfo,key,keylen)) != 0 )
jaddi(array,item);//, printf("gotmsg3.(%s)\n",jprint(item,0));
{
jaddbits256(item,"src",srchash);
jaddbits256(item,"dest",desthash);
jaddi(array,item);
}
}
}
msgid--;
@ -143,7 +159,11 @@ char *basilisk_iterate_MSG(struct supernet_info *myinfo,uint32_t channel,uint32_
if ( basilisk_msgcmp(msg,origwidth,channel,origmsgid,zero,zero) == 0 )
{
if ( (msgjson= basilisk_msgjson(msg,msg->key,msg->keylen)) != 0 )
{
jaddbits256(msgjson,"src",srchash);
jaddbits256(msgjson,"dest",desthash);
jaddi(array,msgjson);
}
}
}
if ( now > msg->expiration+60 )
@ -217,7 +237,11 @@ char *basilisk_respond_addmessage(struct supernet_info *myinfo,uint8_t *key,int3
HASH_ADD_KEYPTR(hh,myinfo->messagetable,msg->key,msg->keylen,msg);
QUEUEITEMS++;
portable_mutex_unlock(&myinfo->messagemutex);
//printf("add message keylen.%d [%d]\n",msg->keylen,datalen);
{
bits256 srchash,desthash; uint32_t channel,msgid;
basilisk_messagekeyread(key,&channel,&msgid,&srchash,&desthash);
//printf("add message keylen.%d [%d] msgid.%x channel.%x\n",msg->keylen,datalen,msgid,channel);
}
//if ( myinfo->NOTARY.RELAYID >= 0 )
// dpow_handler(myinfo,msg);
if ( sendping != 0 )
@ -259,66 +283,41 @@ char *basilisk_respond_MSG(struct supernet_info *myinfo,char *CMD,void *addr,cha
return(retstr);
}
#include "../includes/iguana_apidefs.h"
#include "../includes/iguana_apideclares.h"
HASH_ARRAY_STRING(basilisk,getmessage,hash,vals,hexstr)
cJSON *dpow_getmessage(struct supernet_info *myinfo,char *jsonstr)
{
uint32_t msgid,width,channel; char *retstr;
if ( bits256_cmp(GENESIS_PUBKEY,jbits256(vals,"srchash")) == 0 )
jaddbits256(vals,"srchash",hash);
if ( bits256_cmp(GENESIS_PUBKEY,jbits256(vals,"desthash")) == 0 )
jaddbits256(vals,"desthash",myinfo->myaddr.persistent);
if ( (msgid= juint(vals,"msgid")) == 0 )
cJSON *valsobj,*retjson = 0; char *retstr;
if ( (valsobj= cJSON_Parse(jsonstr)) != 0 )
{
msgid = (uint32_t)time(NULL);
jdelete(vals,"msgid");
jaddnum(vals,"msgid",msgid);
}
if ( myinfo->NOTARY.RELAYID >= 0 || myinfo->dexsock >= 0 || myinfo->subsock >= 0 )
{
channel = juint(vals,"channel");
width = juint(vals,"width");
retstr = basilisk_iterate_MSG(myinfo,channel,msgid,jbits256(vals,"srchash"),jbits256(vals,"desthash"),width);
//printf("getmessage.(%s)\n",retstr);
return(retstr);
retstr = basilisk_iterate_MSG(myinfo,juint(valsobj,"channel"),juint(valsobj,"msgid"),jbits256(valsobj,"srchash"),jbits256(valsobj,"desthash"),juint(valsobj,"width"));
retjson = cJSON_Parse(retstr);
free(retstr);
}
//printf("getmessage not relay.%d dexsock.%d subsock.%d\n",myinfo->NOTARY.RELAYID,myinfo->dexsock,myinfo->subsock);
return(basilisk_standardservice("MSG",myinfo,0,jbits256(vals,"desthash"),vals,hexstr,1));
return(retjson);
}
HASH_ARRAY_STRING(basilisk,sendmessage,hash,vals,hexstr)
cJSON *dpow_addmessage(struct supernet_info *myinfo,char *jsonstr)
{
int32_t keylen,datalen,allocsize = 65536; uint8_t key[BASILISK_KEYSIZE],*space,*space2,*data,*ptr = 0; char *retstr=0;
space = calloc(1,allocsize);
space2 = calloc(1,allocsize);
data = get_dataptr(BASILISK_HDROFFSET,&ptr,&datalen,&space[BASILISK_KEYSIZE],allocsize-BASILISK_KEYSIZE,hexstr);
if ( myinfo->subsock >= 0 || myinfo->dexsock >= 0 || (myinfo->IAMNOTARY != 0 && myinfo->NOTARY.RELAYID >= 0) )
cJSON *vals,*retjson=0; char *retstr=0,*datastr; int32_t datalen,keylen; uint8_t *data=0,key[BASILISK_KEYSIZE];
if ( (vals= cJSON_Parse(jsonstr)) != 0 )
{
keylen = basilisk_messagekey(key,juint(vals,"channel"),juint(vals,"msgid"),jbits256(vals,"srchash"),jbits256(vals,"desthash"));
if ( data != 0 )
if ( (datastr= jstr(vals,"data")) != 0 )
{
retstr = basilisk_respond_addmessage(myinfo,key,keylen,data,datalen,0,juint(vals,"duration"));
} else printf("no get_dataptr\n");
datalen = (int32_t)strlen(datastr) >> 1;
data = malloc(datalen);
decode_hex(data,datalen,datastr);
if ( (retstr= basilisk_respond_addmessage(myinfo,key,keylen,data,datalen,0,juint(vals,"duration"))) != 0 )
retjson = cJSON_Parse(retstr);
}
if ( retstr != 0 )
free(retstr);
} //else printf("not notary.%d relayid.%d\n",myinfo->IAMNOTARY,myinfo->NOTARY.RELAYID);
if ( vals != 0 && juint(vals,"fanout") == 0 )
jaddnum(vals,"fanout",MAX(8,(int32_t)sqrt(myinfo->NOTARY.NUMRELAYS)+2));
if ( BASILISK_KEYSIZE+datalen < allocsize )
{
memcpy(space2,key,BASILISK_KEYSIZE);
if ( data != 0 && datalen != 0 )
memcpy(&space2[BASILISK_KEYSIZE],data,datalen);
dex_reqsend(myinfo,"DEX",space2,datalen+BASILISK_KEYSIZE,1,"");
} else printf("sendmessage space too small error for %d\n",datalen);
free(space);
free(space2);
if ( ptr != 0 )
free(ptr);
return(basilisk_standardservice("OUT",myinfo,0,jbits256(vals,"desthash"),vals,hexstr,0));
if ( data != 0 )
free(data);
}
if ( retjson == 0 )
retjson = cJSON_Parse("{\"error\":\"couldnt add message\"}");
return(retjson);
}
#include "../includes/iguana_apiundefs.h"
int32_t basilisk_channelsend(struct supernet_info *myinfo,bits256 srchash,bits256 desthash,uint32_t channel,uint32_t msgid,uint8_t *data,int32_t datalen,uint32_t duration)
{
@ -384,9 +383,16 @@ cJSON *basilisk_channelget(struct supernet_info *myinfo,bits256 srchash,bits256
jaddnum(valsobj,"numrequired",1);
jaddbits256(valsobj,"srchash",srchash);
jaddbits256(valsobj,"desthash",desthash);
if ( (retstr= basilisk_getmessage(myinfo,0,0,0,desthash,valsobj,0)) != 0 )
if ( myinfo->IAMNOTARY != 0 )
retstr = basilisk_getmessage(myinfo,0,0,0,desthash,valsobj,0);
else
{
//char str[65],str2[65];
retstr = _dex_getmessage(myinfo,jprint(valsobj,0));
//printf("channel.%u msgid.%u gotmessage.(%d) %s %s %s\n",channel,msgid,(int32_t)strlen(retstr),strlen(retstr) < 100 ? retstr : "(too long)",bits256_str(str,srchash),bits256_str(str2,desthash));
}
if ( retstr != 0 )
{
//printf("channel.%u msgid.%u gotmessage.(%d)\n",channel,msgid,(int32_t)strlen(retstr));
if ( (retarray= cJSON_Parse(retstr)) != 0 )
{
if ( is_cJSON_Array(retarray) == 0 )
@ -538,7 +544,7 @@ uint32_t basilisk_crcrecv(struct supernet_info *myinfo,int32_t width,uint8_t *ve
uint32_t basilisk_crcsend(struct supernet_info *myinfo,int32_t width,uint8_t *verifybuf,int32_t maxlen,bits256 srchash,bits256 desthash,uint32_t channel,uint32_t msgbits,uint8_t *data,int32_t datalen,uint32_t crcs[2])
{
uint32_t crc; int32_t recvlen;
uint32_t crc; int32_t recvlen=0;
if ( crcs != 0 )
{
crc = calc_crc32(0,data,datalen);

430
basilisk/basilisk_bitcoin.c

@ -22,36 +22,6 @@
};*/
#ifdef bitcoincancalculatebalances
int64_t bitcoin_value(struct iguana_info *coin,bits256 txid,int16_t vout,char *coinaddr)
{
char params[512],str[65]; char *curlstr; cJSON *txobj,*vouts,*item,*sobj,*addrs; int32_t j,m,n; int64_t value = 0;
sprintf(params,"[\"%s\", 1]",bits256_str(str,txid));
if ( (curlstr= bitcoind_passthru(coin->symbol,coin->chain->serverport,coin->chain->userpass,"getrawtransaction",params)) != 0 )
{
if ( (txobj= cJSON_Parse(curlstr)) != 0 )
{
if ( (vouts= jarray(&n,txobj,"vout")) != 0 && vout < n )
{
item = jitem(vouts,vout);
if ( (sobj= jobj(item,"scriptPubKey")) != 0 && (addrs= jarray(&m,sobj,"addresses")) != 0 )
{
for (j=0; j<m; j++)
{
if ( strcmp(jstri(addrs,j),coinaddr) == 0 )
{
value = SATOSHIDEN * jdouble(item,"satoshis");
break;
}
}
}
}
free_json(txobj);
}
free(curlstr);
}
return(value);
}
char *bitcoin_balance(struct iguana_info *coin,char *coinaddr,int32_t lastheight,int32_t minconf)
{
int32_t i,n,height,maxconf=1<<30; int64_t balance = 0; char params[512],*curlstr; cJSON *array,*retjson,*curljson;
@ -84,6 +54,36 @@ char *bitcoin_balance(struct iguana_info *coin,char *coinaddr,int32_t lastheight
return(jprint(retjson,1));
}
int64_t bitcoin_value(struct iguana_info *coin,bits256 txid,int16_t vout,char *coinaddr)
{
char params[512],str[65]; char *curlstr; cJSON *txobj,*vouts,*item,*sobj,*addrs; int32_t j,m,n; int64_t value = 0;
sprintf(params,"[\"%s\", 1]",bits256_str(str,txid));
if ( (curlstr= bitcoind_passthru(coin->symbol,coin->chain->serverport,coin->chain->userpass,"getrawtransaction",params)) != 0 )
{
if ( (txobj= cJSON_Parse(curlstr)) != 0 )
{
if ( (vouts= jarray(&n,txobj,"vout")) != 0 && vout < n )
{
item = jitem(vouts,vout);
if ( (sobj= jobj(item,"scriptPubKey")) != 0 && (addrs= jarray(&m,sobj,"addresses")) != 0 )
{
for (j=0; j<m; j++)
{
if ( strcmp(jstri(addrs,j),coinaddr) == 0 )
{
value = SATOSHIDEN * jdouble(item,"satoshis");
break;
}
}
}
}
free_json(txobj);
}
free(curlstr);
}
return(value);
}
char *basilisk_bitcoinblockhashstr(char *coinstr,char *serverport,char *userpass,int32_t height)
{
char numstr[128],*blockhashstr=0; bits256 hash2; struct iguana_info *coin;
@ -473,6 +473,23 @@ void *basilisk_getinfo(struct basilisk_item *Lptr,struct supernet_info *myinfo,s
return(ptr);
}
int64_t iguana_getestimatedfee(struct supernet_info *myinfo,struct iguana_info *coin)
{
char *retstr; cJSON *retjson; double x; int64_t txfeeperbyte = 200;
if ( (retstr= _dex_getinfo(myinfo,coin->symbol)) != 0 )
{
if ( (retjson= cJSON_Parse(retstr)) != 0 )
{
if ( (x= jdouble(retjson,"estimatefee")) > SMALLVAL )
txfeeperbyte = 1 + (x * SATOSHIDEN) / 1024;
printf("SET txfeeperbyte %lld (%s)\n",(long long)txfeeperbyte,retstr);
free(retjson);
}
free(retstr);
}
return(txfeeperbyte);
}
int32_t basilisk_voutvin_validate(struct iguana_info *coin,char *rawtx,uint64_t inputsum,uint64_t amount,uint64_t txfee)
{
//static int counter;
@ -543,13 +560,32 @@ int32_t basilisk_vins_validate(struct supernet_info *myinfo,struct iguana_info *
return(retval);
}
int64_t iguana_esttxfee(struct supernet_info *myinfo,struct iguana_info *coin,char *rawtx,char *signedtx,int32_t numvins)
{
int64_t txfee = 0;
if ( coin->estimatedfee == 0 )
coin->estimatedfee = iguana_getestimatedfee(myinfo,coin);
if ( signedtx != 0 )
{
txfee = coin->estimatedfee * (strlen(signedtx)/2 + numvins);
free(signedtx);
}
else if ( rawtx != 0 )
{
txfee = coin->estimatedfee * (strlen(rawtx)/2 + numvins * 110);
free(rawtx);
}
return(txfee);
}
char *iguana_utxoduplicates(struct supernet_info *myinfo,struct iguana_info *coin,uint8_t *pubkey33,uint64_t satoshis,int32_t duplicates,int32_t *completedp,bits256 *signedtxidp,int32_t sendflag,cJSON *addresses)
{
uint8_t script[35]; int32_t i,spendlen; cJSON *txobj=0,*vins=0; char *rawtx=0,*signedtx,changeaddr[64];
uint8_t script[35]; int64_t txfee; int32_t i,spendlen; cJSON *txobj=0,*vins=0; char *rawtx=0,*signedtx=0,changeaddr[64];
*completedp = 0;
if ( signedtxidp != 0 )
memset(signedtxidp,0,sizeof(*signedtxidp));
bitcoin_address(changeaddr,coin->chain->pubtype,myinfo->persistent_pubkey33,33);
txfee = (coin->txfee + duplicates*coin->txfee*2);
if ( (txobj= bitcoin_txcreate(coin->symbol,coin->chain->isPoS,0,1,0)) != 0 )
{
if ( duplicates <= 0 )
@ -557,19 +593,28 @@ char *iguana_utxoduplicates(struct supernet_info *myinfo,struct iguana_info *coi
spendlen = bitcoin_pubkeyspend(script,0,pubkey33);
for (i=0; i<duplicates; i++)
bitcoin_txoutput(txobj,script,spendlen,satoshis);
rawtx = iguana_calcrawtx(myinfo,coin,&vins,txobj,satoshis * duplicates,changeaddr,coin->txfee + duplicates*coin->txfee/5,addresses,0,0,0,0,"127.0.0.1",0,1);
rawtx = iguana_calcrawtx(myinfo,coin,&vins,txobj,satoshis * duplicates,changeaddr,txfee,addresses,0,0,0,0,"127.0.0.1",0,1);
if ( cJSON_GetArraySize(vins) > duplicates/4 )
{
free(rawtx);
rawtx = 0;
fprintf(stderr,"No point to recycle utxo when trying to create utxo duplicates, numvins.%d vs duplicates.%d\n",cJSON_GetArraySize(vins),duplicates);
free_json(vins);
return(rawtx);
}
//printf("duplicatesTX.(%s)\n",rawtx);
if ( signedtxidp != 0 )
{
if ( (signedtx= iguana_signrawtx(myinfo,coin,0,signedtxidp,completedp,vins,rawtx,0,0)) != 0 )
{
free(rawtx);
if ( *completedp != 0 && sendflag != 0 )
if ( *completedp != 0 )
{
printf("splitfunds signedtx.(%s)\n",signedtx);
iguana_sendrawtransaction(myinfo,coin,signedtx);
if ( sendflag != 0 )
iguana_sendrawtransaction(myinfo,coin,signedtx);
free(rawtx);
rawtx = signedtx, signedtx = 0;
}
rawtx = signedtx;
} else printf("error signing raw utxoduplicates tx\n");
}
}
@ -580,6 +625,127 @@ char *iguana_utxoduplicates(struct supernet_info *myinfo,struct iguana_info *coi
return(rawtx);
}
int64_t iguana_verifytimelock(struct supernet_info *myinfo,struct iguana_info *coin,uint32_t timelocked,char *destaddr,bits256 txid,int32_t vout)
{
uint8_t script[35],script2[35],p2shscript[128],rmd160[20],addrtype; char *retstr,*spendscriptstr; int32_t p2shlen,spendlen; cJSON *sobj,*txout=0; int64_t value = 0;
bitcoin_addr2rmd160(&addrtype,rmd160,destaddr);
if ( addrtype != coin->chain->pubtype )
return(-1);
p2shlen = bitcoin_timelockspend(p2shscript,0,rmd160,timelocked);
calc_rmd160(0,rmd160,p2shscript,p2shlen);
spendlen = bitcoin_p2shspend(script,0,rmd160);
if ( coin->FULLNODE != 0 )
txout = dpow_gettxout(myinfo,coin,txid,vout);
else if ( (retstr= _dex_gettxout(myinfo,coin->symbol,txid,vout)) != 0 )
{
txout = cJSON_Parse(retstr);
free(retstr);
}
if ( txout != 0 )
{
if ( (sobj= jobj(txout,"scriptPubKey")) != 0 && (spendscriptstr= jstr(sobj,"hex")) == 0 )
{
if ( strlen(spendscriptstr) == spendlen*2 )
{
decode_hex(script2,spendlen,spendscriptstr);
if ( memcmp(script,script2,spendlen) != 0 )
return(-2);
value = SATOSHIDEN * jdouble(txout,"value");
} else return(-4);
}
free_json(txout);
return(value);
} return(-2);
}
char *iguana_utxorawtx(struct supernet_info *myinfo,struct iguana_info *coin,int32_t timelock,char *destaddr,char *changeaddr,uint64_t satoshis,uint64_t txfee,int32_t *completedp,int32_t sendflag,cJSON *utxos)
{
uint8_t script[35],p2shscript[128],rmd160[20],addrtype; bits256 txid; int32_t p2shlen,iter,spendlen; cJSON *retjson,*txcopy,*txobj=0,*vins=0; char *rawtx=0,*signedtx=0; uint32_t timelocked = 0;
*completedp = 0;
if ( iguana_addressvalidate(coin,&addrtype,destaddr) < 0 || iguana_addressvalidate(coin,&addrtype,changeaddr) < 0 )
return(clonestr("{\"error\":\"invalid coin address\"}"));
bitcoin_addr2rmd160(&addrtype,rmd160,changeaddr);
if ( addrtype != coin->chain->pubtype )
return(clonestr("{\"error\":\"invalid changeaddr type\"}"));
bitcoin_addr2rmd160(&addrtype,rmd160,destaddr);
if ( addrtype != coin->chain->pubtype )
return(clonestr("{\"error\":\"invalid dest address type\"}"));
if ( txfee == 0 && strcmp(coin->symbol,"BTC") != 0 && (txfee= coin->txfee) == 0 )
txfee = coin->chain->txfee;
retjson = cJSON_CreateObject();
if ( (txobj= bitcoin_txcreate(coin->symbol,coin->chain->isPoS,0,1,0)) != 0 )
{
if ( timelock == 0 )
spendlen = bitcoin_standardspend(script,0,rmd160);
else
{
timelocked = (uint32_t)(time(NULL)+timelock);
if ( (timelocked % 3600) != 0 )
timelocked += (3600 - (timelocked % 3600));
p2shlen = bitcoin_timelockspend(p2shscript,0,rmd160,timelocked);
calc_rmd160(0,rmd160,p2shscript,p2shlen);
spendlen = bitcoin_p2shspend(script,0,rmd160);
printf("timelock.%d spend timelocked %u\n",timelock,timelocked);
}
bitcoin_txoutput(txobj,script,spendlen,satoshis);
for (iter=0; iter<2; iter++)
{
txcopy = jduplicate(txobj);
if ( (rawtx= iguana_calcutxorawtx(myinfo,coin,&vins,txobj,satoshis,changeaddr,txfee,utxos,"",0,0)) != 0 )
{
if ( iter == 1 || txfee != 0 )
jaddstr(retjson,"rawtx",rawtx);
if ( (signedtx= iguana_signrawtx(myinfo,coin,0,&txid,completedp,vins,rawtx,0,0)) != 0 )
{
if ( (iter == 1 || txfee != 0) && *completedp != 0 )
{
jaddbits256(retjson,"txid",txid);
jaddstr(retjson,"signedtx",signedtx);
if ( sendflag != 0 )
{
//printf("send signedtx.(%s)\n",signedtx);
txid = iguana_sendrawtransaction(myinfo,coin,signedtx);
jaddbits256(retjson,"sent",txid);
}
}
} else printf("error signing raw utxorawtx tx\n");
} else printf("null rawtx from calcutxorawtx\n");
if ( txfee != 0 )
{
free_json(txcopy);
break;
}
else // must be BTC and txfee == 0
{
txfee = iguana_esttxfee(myinfo,coin,rawtx,signedtx,cJSON_GetArraySize(vins));
free_json(vins);
rawtx = signedtx = 0;
vins = 0;
*completedp = 0;
txobj = txcopy;
}
}
}
if ( timelock != 0 )
{
jaddnum(retjson,"timelock",timelock);
jaddnum(retjson,"timelocked",timelocked);
}
jaddstr(retjson,"result","success");
if ( *completedp != 0 )
jadd(retjson,"completed",jtrue());
else jadd(retjson,"completed",jfalse());
if ( vins != 0 )
free_json(vins);
if ( txobj != 0 )
free_json(txobj);
if ( rawtx != 0 )
free(rawtx);
if ( signedtx != 0 )
free(signedtx);
return(jprint(retjson,1));
}
char *basilisk_bitcoinrawtx(struct supernet_info *myinfo,struct iguana_info *coin,char *remoteaddr,uint32_t basilisktag,int32_t timeoutmillis,cJSON *valsobj,struct vin_info *V)
{
uint8_t buf[4096]; int32_t oplen,offset,minconf,spendlen; cJSON *vins,*addresses,*txobj = 0; uint32_t locktime; char *opreturn,*spendscriptstr,*changeaddr,*rawtx = 0; int64_t amount,txfee,burnamount;
@ -592,9 +758,14 @@ char *basilisk_bitcoinrawtx(struct supernet_info *myinfo,struct iguana_info *coi
if ( (amount= j64bits(valsobj,"satoshis")) == 0 )
amount = jdouble(valsobj,"value") * SATOSHIDEN;
if ( (txfee= j64bits(valsobj,"txfee")) == 0 )
txfee = coin->chain->txfee;
if ( txfee == 0 )
txfee = 10000;
{
//if ( strcmp(coin->symbol,"BTC") != 0 )
{
txfee = coin->chain->txfee;
if ( txfee < 50000 )
txfee = 50000;
}
}
spendscriptstr = jstr(valsobj,"spendscript");
minconf = juint(valsobj,"minconf");
locktime = jint(valsobj,"locktime");
@ -603,7 +774,7 @@ char *basilisk_bitcoinrawtx(struct supernet_info *myinfo,struct iguana_info *coi
addresses = iguana_getaddressesbyaccount(myinfo,coin,"*");
jadd(valsobj,"addresses",addresses);
}
//printf("use addresses.(%s)\n",jprint(addresses,0));
printf("use addresses.(%s)\n",jprint(addresses,0));
//printf("(%s) vals.(%s) change.(%s) spend.%s\n",coin->symbol,jprint(valsobj,0),changeaddr,spendscriptstr);
if ( changeaddr == 0 || changeaddr[0] == 0 || spendscriptstr == 0 || spendscriptstr[0] == 0 )
return(clonestr("{\"error\":\"invalid changeaddr or spendscript or addresses\"}"));
@ -631,7 +802,15 @@ char *basilisk_bitcoinrawtx(struct supernet_info *myinfo,struct iguana_info *coi
oplen = 0;
} else oplen = datachain_opreturnscript(coin,buf,opreturn,oplen);
}
rawtx = iguana_calcrawtx(myinfo,coin,&vins,txobj,amount,changeaddr,txfee,addresses,minconf,oplen!=0?buf:0,oplen+offset,burnamount,remoteaddr,V,0);
rawtx = iguana_calcrawtx(myinfo,coin,&vins,txobj,amount,changeaddr,txfee,addresses,minconf,oplen!=0?buf:0,oplen+offset,burnamount,remoteaddr,V,1);
if ( txfee == 0 )
{
txfee = iguana_esttxfee(myinfo,coin,rawtx,0,vins != 0 ? cJSON_GetArraySize(vins): 0);
if ( vins != 0 )
free_json(vins), vins = 0;
rawtx = iguana_calcrawtx(myinfo,coin,&vins,txobj,amount,changeaddr,txfee,addresses,minconf,oplen!=0?buf:0,oplen+offset,burnamount,remoteaddr,V,1);
printf("new txfee %.8f (%s)\n",dstr(txfee),rawtx);
}
//printf("generated.(%s) vins.(%s)\n",rawtx!=0?rawtx:"",vins!=0?jprint(vins,0):"");
}
if ( rawtx != 0 )
@ -877,175 +1056,6 @@ cJSON *BTC_makeclaimfunc(struct supernet_info *myinfo,struct exchange_info *exch
}
#endif
#include "../includes/iguana_apidefs.h"
#include "../includes/iguana_apideclares.h"
HASH_ARRAY_STRING(basilisk,value,hash,vals,hexstr)
{
char *retstr=0,*symbol,*coinaddr,*infostr; cJSON *retjson,*sobj,*info,*addrs,*txoutjson,*txjson,*array; uint32_t basilisktag,blocktime; bits256 txid,blockhash; struct basilisk_item *ptr,Lptr; uint64_t value; int32_t timeoutmillis,vout,height,n,m;
if ( vals == 0 )
return(clonestr("{\"error\":\"null valsobj\"}"));
//if ( myinfo->IAMNOTARY != 0 || myinfo->NOTARY.RELAYID >= 0 )
// return(clonestr("{\"error\":\"special relays only do OUT and MSG\"}"));
//if ( coin == 0 )
{
if ( (symbol= jstr(vals,"symbol")) != 0 || (symbol= jstr(vals,"coin")) != 0 )
coin = iguana_coinfind(symbol);
}
if ( jobj(vals,"fanout") == 0 )
jaddnum(vals,"fanout",MAX(5,(int32_t)sqrt(myinfo->NOTARY.NUMRELAYS)+1));
txid = jbits256(vals,"txid");
vout = jint(vals,"vout");
if ( coin != 0 )
{
if ( coin->FULLNODE < 0 )
{
if ( (txoutjson= dpow_gettxout(myinfo,coin,txid,vout)) != 0 )
{
if ( (coinaddr= jstr(txoutjson,"address")) != 0 && (value= SATOSHIDEN*jdouble(txoutjson,"value")) != 0 )
{
retjson = cJSON_CreateObject();
jaddstr(retjson,"result","success");
jaddstr(retjson,"address",coinaddr);
jadd64bits(retjson,"satoshis",value);
jaddnum(retjson,"value",dstr(value));
jaddnum(retjson,"amount",dstr(value));
height = dpow_getchaintip(myinfo,&blockhash,&blocktime,0,0,coin);
jaddnum(retjson,"height",height);
jaddnum(retjson,"numconfirms",jint(txoutjson,"confirmations"));
jaddbits256(retjson,"txid",txid);
jaddnum(retjson,"vout",vout);
jaddstr(retjson,"coin",coin->symbol);
}
else
{
free_json(txoutjson);
return(clonestr("{\"error\":\"return from gettxout missing fields\"}"));
}
free_json(txoutjson);
return(jprint(retjson,1));
} else return(clonestr("{\"error\":\"null return from gettxout\"}"));
}
if ( (basilisktag= juint(vals,"basilisktag")) == 0 )
basilisktag = rand();
if ( (timeoutmillis= juint(vals,"timeout")) <= 0 )
timeoutmillis = BASILISK_TIMEOUT;
if ( coin->FULLNODE > 0 && (ptr= basilisk_bitcoinvalue(&Lptr,myinfo,coin,remoteaddr,basilisktag,timeoutmillis,vals)) != 0 )
{
retstr = ptr->retstr, ptr->retstr = 0;
ptr->finished = OS_milliseconds() + 10000;
return(retstr);
}
}
if ( myinfo->reqsock >= 0 )
{
if ( (retstr= _dex_getrawtransaction(myinfo,symbol,txid)) != 0 )
{
if ( (txoutjson= cJSON_Parse(retstr)) != 0 )
{
//printf("TX.(%s)\n",jprint(txoutjson,0));
retjson = cJSON_CreateObject();
jaddstr(retjson,"result","success");
jaddnum(retjson,"numconfirms",jint(txoutjson,"confirmations"));
if ( (array= jarray(&n,txoutjson,"vout")) != 0 && vout < n && (txjson= jitem(array,vout)) != 0 )
{
//printf("txjson.(%s)\n",jprint(txjson,0));
if ( (value= jdouble(txjson,"value") * SATOSHIDEN) != 0 )
{
if ( (sobj= jobj(txjson,"scriptPubKey")) != 0 && (addrs= jarray(&m,sobj,"addresses")) != 0 && (coinaddr= jstri(addrs,0)) != 0 )
jaddstr(retjson,"address",coinaddr);
jadd64bits(retjson,"satoshis",value);
jaddnum(retjson,"value",dstr(value));
if ( (infostr= _dex_getinfo(myinfo,symbol)) != 0 )
{
if ( (info= cJSON_Parse(infostr)) != 0 )
{
if ( (height= jint(info,"blocks")) > 0 )
{
height -= jint(txoutjson,"confirmations");
jaddnum(retjson,"height",height);
}
free_json(info);
}
free(infostr);
}
jaddbits256(retjson,"txid",txid);
jaddnum(retjson,"vout",vout);
jaddstr(retjson,"coin",symbol);
free(retstr);
free_json(txoutjson);
return(jprint(retjson,1));
}
}
free_json(txoutjson);
return(jprint(retjson,1));
}
return(retstr);
}
}
return(basilisk_standardservice("VAL",myinfo,0,hash,vals,hexstr,1));
}
HASH_ARRAY_STRING(basilisk,rawtx,hash,vals,hexstr)
{
char *retstr=0,*symbol; uint32_t basilisktag; int32_t timeoutmillis,i,retval = -1; uint64_t amount,txfee; cJSON *retarray;
if ( vals == 0 )
return(clonestr("{\"error\":\"null valsobj\"}"));
//if ( coin == 0 )
{
if ( (symbol= jstr(vals,"symbol")) != 0 || (symbol= jstr(vals,"coin")) != 0 )
coin = iguana_coinfind(symbol);
}
if ( jobj(vals,"numrequired") == 0 )
jaddnum(vals,"numrequired",MIN(3,(int32_t)sqrt(myinfo->NOTARY.NUMRELAYS)+1));
if ( jobj(vals,"fanout") == 0 )
jaddnum(vals,"fanout",MAX(3,(int32_t)sqrt(myinfo->NOTARY.NUMRELAYS)+1));
if ( coin != 0 )
{
//if ( juint(vals,"burn") == 0 )
// jaddnum(vals,"burn",0.0001);
if ( (basilisktag= juint(vals,"basilisktag")) == 0 )
basilisktag = rand();
if ( (timeoutmillis= juint(vals,"timeout")) <= 0 )
timeoutmillis = BASILISK_TIMEOUT;
if ( (retstr= basilisk_bitcoinrawtx(myinfo,coin,remoteaddr,basilisktag,timeoutmillis,vals,0)) != 0 )
{
printf("rawtx.(%s)\n",retstr);
if ( (amount= j64bits(vals,"satoshis")) == 0 )
amount = jdouble(vals,"value") * SATOSHIDEN;
if ( (txfee= j64bits(vals,"txfee")) == 0 )
txfee = coin->chain->txfee;
if ( txfee == 0 )
txfee = 10000;
retval = -1;
if ( (retarray= cJSON_Parse(retstr)) != 0 )
{
if ( is_cJSON_Array(retarray) != 0 )
{
for (i=0; i<cJSON_GetArraySize(retarray); i++)
{
if ( basilisk_vins_validate(myinfo,coin,jitem(retarray,i),amount,txfee) == 0 )
{
retval = 0;
break;
}
}
} else retval = basilisk_vins_validate(myinfo,coin,retarray,amount,txfee);
if ( retval < 0 )
{
printf("ERROR.(%s)\n",retstr);
free(retstr);
retstr = clonestr("{\"error\":\"invalid vin in rawtx\"}");
}
}
}
} else retstr = clonestr("{\"error\":\"no coin specified or found\"}");
return(retstr);
}
#include "../includes/iguana_apiundefs.h"
int32_t basilisk_unspentfind(struct supernet_info *myinfo,struct iguana_info *coin,bits256 *txidp,int32_t *voutp,uint8_t *spendscript,struct iguana_outpoint outpt,int64_t value)
{
struct iguana_waccount *wacct,*tmp; struct iguana_waddress *waddr,*tmp2;

2
basilisk/basilisk_ping.c

@ -107,7 +107,7 @@ int32_t basilisk_ping_genvirts(struct supernet_info *myinfo,uint8_t *data,int32_
int32_t basilisk_ping_processMSG(struct supernet_info *myinfo,uint32_t senderipbits,uint8_t *data,int32_t datalen)
{
int32_t i,msglen,len=0; uint8_t num,keylen,*message,*key; uint32_t duration;
int32_t i,msglen=0,len=0; uint8_t num,keylen,*message,*key; uint32_t duration;
if ( (num= data[len++]) > 0 )
{
//printf("processMSG num.%d datalen.%d\n",num,datalen);

1513
basilisk/basilisk_swap.c

File diff suppressed because it is too large

22
basilisk/basilisk_tradebot.c

@ -69,12 +69,12 @@ int32_t basilisk_txitem(struct supernet_info *myinfo,struct basilisk_swap *swap,
decode_hex((void *)&rawtx->I,sizeof(rawtx->I),hexstr);
if ( (hexstr= jstr(obj,"txbytes")) != 0 && strlen(hexstr) == rawtx->I.datalen*2 )
{
if ( rawtx->txbytes == 0 )
/*if ( rawtx->txbytes == 0 )
{
printf("free (%s) txbytes\n",name);
free(rawtx->txbytes);
}
rawtx->txbytes = calloc(1,rawtx->I.datalen);
rawtx->txbytes = calloc(1,rawtx->I.datalen);*/
decode_hex((void *)rawtx->txbytes,rawtx->I.datalen,hexstr);
}
printf("PROCESS.(%s)\n",jprint(obj,0));
@ -92,6 +92,7 @@ cJSON *basilisk_swapobj(struct supernet_info *myinfo,struct basilisk_swap *swap)
jaddnum(obj,"quoteid",swap->I.req.quoteid);
jadd(obj,"req",basilisk_requestjson(&swap->I.req));
jaddstr(obj,"info",hexstr);
//printf("strlen(hexstr) swap->I %d vs %d\n",(int32_t)strlen(hexstr),(int32_t)sizeof(swap->I)*2);
return(obj);
}
@ -104,7 +105,7 @@ int32_t basilisk_swapconv(struct supernet_info *myinfo,struct basilisk_swap *swa
if ( juint(obj,"requestid") == swap->I.req.requestid && juint(obj,"quoteid") == swap->I.req.quoteid )
return(0);
printf("swapconv mismatched req/quote %d %d, %d %d\n",juint(obj,"requestid"),swap->I.req.requestid,juint(obj,"quoteid"),swap->I.req.quoteid);
} else printf("no info field in swap obj\n");
} //else printf("no info field in swap obj.(%s) len.%d vs %d\n",jprint(obj,0),(int32_t)strlen(hexstr),(int32_t)sizeof(swap->I)*2);
return(-1);
}
@ -278,7 +279,7 @@ int32_t basilisk_request_cmpref(struct basilisk_request *ref,struct basilisk_req
double basilisk_request_listprocess(struct supernet_info *myinfo,struct basilisk_request *issueR,struct basilisk_request *list,int32_t n)
{
int32_t i,noquoteflag=0,havequoteflag=0,myrequest=0,maxi=-1; int64_t balance=0,destamount,minamount = 0,maxamount = 0; uint32_t pendingid=0; struct basilisk_swap *active; double metric = 0.;
int32_t i,noquoteflag=0,havequoteflag=0,myrequest=0,maxi=-1; int64_t balance=0,destamount,minamount = 0,maxamount = 0; bits256 privkey; uint32_t pendingid=0; struct basilisk_swap *active; double metric = 0.;
memset(issueR,0,sizeof(*issueR));
minamount = list[0].minamount;
//printf("need to verify null quoteid is list[0] requestid.%u quoteid.%u\n",list[0].requestid,list[0].quoteid);
@ -288,7 +289,7 @@ double basilisk_request_listprocess(struct supernet_info *myinfo,struct basilisk
return(0.);
pendingid = active->I.req.quoteid;
}
if ( bits256_cmp(myinfo->myaddr.persistent,list[0].srchash) == 0 ) // my request
if ( smartaddress_pubkey(myinfo,&privkey,list[0].srchash) >= 0 )
myrequest = 1;
for (i=0; i<n; i++)
{
@ -296,7 +297,7 @@ double basilisk_request_listprocess(struct supernet_info *myinfo,struct basilisk
return(-1);
if ( list[i].quoteid != 0 )
{
if ( bits256_cmp(myinfo->myaddr.persistent,list[i].desthash) == 0 ) // my quoteid
if ( smartaddress_pubkey(myinfo,&privkey,list[i].desthash) >= 0 )
myrequest |= 2;
havequoteflag++;
if ( pendingid == 0 )
@ -330,9 +331,9 @@ double basilisk_request_listprocess(struct supernet_info *myinfo,struct basilisk
aveprice = refprice;
if ( fabs(aveprice) < SMALLVAL )
return(0);
printf("avebid %f bidvol %f, aveask %f askvol %f\n",retvals[0],retvals[1],retvals[2],retvals[3]);
//retvals[0] = avebid, retvals[1] = bidvol, retvals[2] = aveask, retvals[3] = askvol;
destamount = (1.0 - profitmargin) * aveprice * list[0].srcamount;
destamount = (1.0 - profitmargin) * aveprice * list[0].srcamount * SATOSHIDEN;
printf("aveprice %f dest %.8f avebid %f bidvol %f, aveask %f askvol %f\n",aveprice,dstr(destamount),retvals[0],retvals[1],retvals[2],retvals[3]);
if ( (retstr= InstantDEX_available(myinfo,iguana_coinfind(list[0].dest),0,0,list[0].dest)) != 0 )
{
if ( (retjson= cJSON_Parse(retstr)) != 0 )
@ -343,8 +344,8 @@ double basilisk_request_listprocess(struct supernet_info *myinfo,struct basilisk
free(retstr);
}
// BTC balance 0.00500000 destamount 0.00041951 aveprice 0.00421619 minamount 0.00020000
printf("%s balance %.8f destamount %.8f aveprice %.8f minamount %.8f\n",list[0].dest,dstr(balance),dstr(destamount),aveprice,dstr(minamount));
if ( balance > destamount && (int64_t)destamount > 0 && destamount >= maxamount && destamount >= minamount )
printf("%s balance %.8f destamount %.8f aveprice %.8f maxamount %.8f minamount %.8f\n",list[0].dest,dstr(balance),dstr(destamount),aveprice,dstr(maxamount),dstr(minamount));
if ( balance > destamount && (int64_t)destamount > 0 && destamount >= minamount ) // max?
{
metric = 1.;
*issueR = list[0];
@ -374,6 +375,7 @@ double basilisk_process_results(struct supernet_info *myinfo,struct basilisk_req
{
cJSON *array,*item; uint8_t *hexdata,*allocptr,hexspace[32768]; char *hexstr; int32_t i,hexlen,n,m,nonz; struct basilisk_request tmpR,R,refR,list[BASILISK_MAXRELAYS]; double metric=0.;
memset(&refR,0,sizeof(refR));
memset(&R,0,sizeof(R));
//printf("process.(%s)\n",jprint(retjson,0));
if ( (array= jarray(&n,retjson,"messages")) != 0 )
{

495
basilisk/jumblr.c

@ -0,0 +1,495 @@
/******************************************************************************
* 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. *
* *
******************************************************************************/
// included from basilisk.c
// connect DEX to jumblr-core
/*
z_exportkey "zaddr"
z_exportwallet "filename"
z_getoperationstatus (["operationid", ... ])
z_gettotalbalance ( minconf )
z_importkey "zkey" ( rescan )
z_importwallet "filename"
z_listaddresses
z_sendmany "fromaddress" [{"address":... ,"amount":..., "memo":"<hex>"},...] ( minconf ) ( fee )
*/
#define JUMBLR_INCR 99.65
#define JUMBLR_TXFEE 0.01
#define JUMBLR_ADDR "RGhxXpXSSBTBm9EvNsXnTQczthMCxHX91t"
#define JUMBLR_BTCADDR "18RmTJe9qMech8siuhYfMtHo8RtcN1obC6"
#define JUMBLR_FEE 0.001
int32_t jumblr_addresstype(struct supernet_info *myinfo,struct iguana_info *coin,char *addr)
{
if ( addr[0] == 'z' && addr[1] == 'c' && strlen(addr) >= 40 )
return('z');
else if ( strlen(addr) < 40 )
return('t');
else return(-1);
}
struct jumblr_item *jumblr_opidfind(struct supernet_info *myinfo,char *opid)
{
struct jumblr_item *ptr;
HASH_FIND(hh,myinfo->jumblrs,opid,(int32_t)strlen(opid),ptr);
return(ptr);
}
struct jumblr_item *jumblr_opidadd(struct supernet_info *myinfo,struct iguana_info *coin,char *opid)
{
struct jumblr_item *ptr;
if ( (ptr= jumblr_opidfind(myinfo,opid)) == 0 )
{
ptr = calloc(1,sizeof(*ptr));
safecopy(ptr->opid,opid,sizeof(ptr->opid));
HASH_ADD_KEYPTR(hh,myinfo->jumblrs,ptr->opid,(int32_t)strlen(ptr->opid),ptr);
if ( ptr != jumblr_opidfind(myinfo,opid) )
printf("jumblr_opidadd.(%s) ERROR, couldnt find after add\n",opid);
}
return(ptr);
}
char *jumblr_validateaddress(struct supernet_info *myinfo,struct iguana_info *coin,char *addr)
{
char params[1024];
if ( coin->FULLNODE < 0 )
{
sprintf(params,"[\"%s\"]",addr);
return(bitcoind_passthru(coin->symbol,coin->chain->serverport,coin->chain->userpass,"validateaddress",params));
} else return(_dex_validateaddress(myinfo,coin->symbol,addr));
}
int32_t jumblr_ismine(struct supernet_info *myinfo,struct iguana_info *coin,char *addr)
{
char params[1024],*retstr; cJSON *retjson,*obj; int32_t retval = -1;
sprintf(params,"[\"%s\"]",addr);
if ( (retstr= jumblr_validateaddress(myinfo,coin,addr)) != 0 )
{
if ( (retjson= cJSON_Parse(retstr)) != 0 )
{
if ( (obj= jobj(retjson,"ismine")) != 0 && is_cJSON_True(obj) != 0 )
retval = 1;
else retval = 0;
free_json(retjson);
}
free(retstr);
}
return(retval);
}
char *jumblr_zgetnewaddress(struct supernet_info *myinfo,struct iguana_info *coin)
{
return(bitcoind_passthru(coin->symbol,coin->chain->serverport,coin->chain->userpass,"z_getnewaddress",""));
}
char *jumblr_zlistoperationids(struct supernet_info *myinfo,struct iguana_info *coin)
{
return(bitcoind_passthru(coin->symbol,coin->chain->serverport,coin->chain->userpass,"z_listoperationids",""));
}
char *jumblr_zgetoperationresult(struct supernet_info *myinfo,struct iguana_info *coin,char *opid)
{
char params[1024];
sprintf(params,"[[\"%s\"]]",opid);
return(bitcoind_passthru(coin->symbol,coin->chain->serverport,coin->chain->userpass,"z_getoperationresult",params));
}
char *jumblr_zgetoperationstatus(struct supernet_info *myinfo,struct iguana_info *coin,char *opid)
{
char params[1024];
sprintf(params,"[[\"%s\"]]",opid);
return(bitcoind_passthru(coin->symbol,coin->chain->serverport,coin->chain->userpass,"z_getoperationstatus",params));
}
char *jumblr_sendt_to_z(struct supernet_info *myinfo,struct iguana_info *coin,char *taddr,char *zaddr,double amount)
{
char params[1024]; double fee = (amount-3*JUMBLR_TXFEE) * JUMBLR_FEE;
if ( jumblr_addresstype(myinfo,coin,zaddr) != 'z' || jumblr_addresstype(myinfo,coin,taddr) != 't' )
return(clonestr("{\"error\":\"illegal address in t to z\"}"));
sprintf(params,"[\"%s\", [{\"address\":\"%s\",\"amount\":%.8f}, {\"address\":\"%s\",\"amount\":%.8f}], 1, %.8f]",taddr,zaddr,amount-fee-JUMBLR_TXFEE,JUMBLR_ADDR,fee,JUMBLR_TXFEE);
return(bitcoind_passthru(coin->symbol,coin->chain->serverport,coin->chain->userpass,"z_sendmany",params));
}
char *jumblr_sendz_to_z(struct supernet_info *myinfo,struct iguana_info *coin,char *zaddrS,char *zaddrD,double amount)
{
char params[1024]; double fee = (amount-2*JUMBLR_TXFEE) * JUMBLR_FEE;
if ( jumblr_addresstype(myinfo,coin,zaddrS) != 'z' || jumblr_addresstype(myinfo,coin,zaddrD) != 'z' )
return(clonestr("{\"error\":\"illegal address in z to z\"}"));
sprintf(params,"[\"%s\", [{\"address\":\"%s\",\"amount\":%.8f}, {\"address\":\"%s\",\"amount\":%.8f}], 1, %.8f]",zaddrS,zaddrD,amount-fee-JUMBLR_TXFEE,JUMBLR_ADDR,fee,JUMBLR_TXFEE);
return(bitcoind_passthru(coin->symbol,coin->chain->serverport,coin->chain->userpass,"z_sendmany",params));
}
char *jumblr_sendz_to_t(struct supernet_info *myinfo,struct iguana_info *coin,char *zaddr,char *taddr,double amount)
{
char params[1024]; double fee = (amount-JUMBLR_TXFEE) * JUMBLR_FEE;
if ( jumblr_addresstype(myinfo,coin,zaddr) != 'z' || jumblr_addresstype(myinfo,coin,taddr) != 't' )
return(clonestr("{\"error\":\"illegal address in z to t\"}"));
sprintf(params,"[\"%s\", [{\"address\":\"%s\",\"amount\":%.8f}, {\"address\":\"%s\",\"amount\":%.8f}], 1, %.8f]",zaddr,taddr,amount-fee-JUMBLR_TXFEE,JUMBLR_ADDR,fee,JUMBLR_TXFEE);
return(bitcoind_passthru(coin->symbol,coin->chain->serverport,coin->chain->userpass,"z_sendmany",params));
}
char *jumblr_zlistreceivedbyaddress(struct supernet_info *myinfo,struct iguana_info *coin,char *addr)
{
char params[1024];
sprintf(params,"[\"%s\", 1]",addr);
return(bitcoind_passthru(coin->symbol,coin->chain->serverport,coin->chain->userpass,"z_listreceivedbyaddress",params));
}
char *jumblr_getreceivedbyaddress(struct supernet_info *myinfo,struct iguana_info *coin,char *addr)
{
char params[1024];
sprintf(params,"[\"%s\", 1]",addr);
return(bitcoind_passthru(coin->symbol,coin->chain->serverport,coin->chain->userpass,"getreceivedbyaddress",params));
}
char *jumblr_importprivkey(struct supernet_info *myinfo,struct iguana_info *coin,char *wifstr)
{
char params[1024];
sprintf(params,"[\"%s\", \"\", false]",wifstr);
return(bitcoind_passthru(coin->symbol,coin->chain->serverport,coin->chain->userpass,"importprivkey",params));
}
char *jumblr_zgetbalance(struct supernet_info *myinfo,struct iguana_info *coin,char *addr)
{
char params[1024];
sprintf(params,"[\"%s\", 1]",addr);
return(bitcoind_passthru(coin->symbol,coin->chain->serverport,coin->chain->userpass,"z_getbalance",params));
}
char *jumblr_listunspent(struct supernet_info *myinfo,struct iguana_info *coin,char *addr)
{
char params[1024];
sprintf(params,"[1, 99999999, [\"%s\"]]",addr);
return(bitcoind_passthru(coin->symbol,coin->chain->serverport,coin->chain->userpass,"listunspent",params));
}
int64_t jumblr_receivedby(struct supernet_info *myinfo,struct iguana_info *coin,char *addr)
{
char *retstr; int64_t total = 0;
if ( (retstr= jumblr_getreceivedbyaddress(myinfo,coin,addr)) != 0 )
{
total = atof(retstr) * SATOSHIDEN;
free(retstr);
}
return(total);
}
int64_t jumblr_balance(struct supernet_info *myinfo,struct iguana_info *coin,char *addr)
{
char *retstr; double val; cJSON *retjson; int32_t i,n; int64_t balance = 0;
if ( jumblr_addresstype(myinfo,coin,addr) == 't' )
{
if ( coin->FULLNODE < 0 && jumblr_ismine(myinfo,coin,addr) > 0 )
{
if ( (retstr= jumblr_listunspent(myinfo,coin,addr)) != 0 )
{
if ( (retjson= cJSON_Parse(retstr)) != 0 )
{
if ( (n= cJSON_GetArraySize(retjson)) > 0 )
for (i=0; i<n; i++)
balance += SATOSHIDEN * jdouble(jitem(retjson,i),"amount");
free_json(retjson);
}
free(retstr);
}
}
else if ( (retstr= dex_getbalance(myinfo,coin,0,0,coin->symbol,addr)) != 0 )
{
//printf("retstr.(%s)\n",retstr);
if ( (retjson= cJSON_Parse(retstr)) != 0 )
{
balance = jdouble(retjson,"balance") * SATOSHIDEN;
free_json(retjson);
}
free(retstr);
}
}
else if ( (retstr= jumblr_zgetbalance(myinfo,coin,addr)) != 0 )
{
if ( (val= atof(retstr)) > SMALLVAL )
balance = val * SATOSHIDEN;
free(retstr);
}
return(balance);
}
int32_t jumblr_itemset(struct jumblr_item *ptr,cJSON *item,char *status)
{
cJSON *params,*amounts,*dest; char *from,*addr; int32_t i,n; int64_t amount;
/*"params" : {
"fromaddress" : "RDhEGYScNQYetCyG75Kf8Fg61UWPdwc1C5",
"amounts" : [
{
"address" : "zc9s3UdkDFTnnwHrMCr1vYy2WmkjhmTxXNiqC42s7BjeKBVUwk766TTSsrRPKfnX31Bbu8wbrTqnjDqskYGwx48FZMPHvft",
"amount" : 3.00000000
}
],
"minconf" : 1,
"fee" : 0.00010000
}*/
if ( (params= jobj(item,"params")) != 0 )
{
//printf("params.(%s)\n",jprint(params,0));
if ( (from= jstr(params,"fromaddress")) != 0 )
{
safecopy(ptr->src,from,sizeof(ptr->src));
}
if ( (amounts= jarray(&n,params,"amounts")) != 0 )
{
for (i=0; i<n; i++)
{
dest = jitem(amounts,i);
//printf("%s ",jprint(dest,0));
if ( (addr= jstr(dest,"address")) != 0 && (amount= jdouble(dest,"amount")*SATOSHIDEN) > 0 )
{
if ( strcmp(addr,JUMBLR_ADDR) == 0 )
ptr->fee = amount;
else
{
ptr->amount = amount;
safecopy(ptr->dest,addr,sizeof(ptr->dest));
}
}
}
}
ptr->txfee = jdouble(params,"fee") * SATOSHIDEN;
}
return(1);
}
void jumblr_opidupdate(struct supernet_info *myinfo,struct iguana_info *coin,struct jumblr_item *ptr)
{
char *retstr,*status,KMDjumblr[64],KMDdeposit[64],BTCaddr[64]; cJSON *retjson,*item;
if ( ptr->status == 0 )
{
if ( (retstr= jumblr_zgetoperationstatus(myinfo,coin,ptr->opid)) != 0 )
{
if ( (retjson= cJSON_Parse(retstr)) != 0 )
{
if ( cJSON_GetArraySize(retjson) == 1 )
{
item = jitem(retjson,0);
//printf("%s\n",jprint(item,0));
if ( (status= jstr(item,"status")) != 0 )
{
if ( strcmp(status,"success") == 0 )
{
ptr->status = jumblr_itemset(ptr,item,status);
jumblr_privkey(myinfo,BTCaddr,KMDdeposit,JUMBLR_DEPOSITPREFIX);
jumblr_privkey(myinfo,BTCaddr,KMDjumblr,"");
if ( (jumblr_addresstype(myinfo,coin,ptr->src) == 't' && jumblr_addresstype(myinfo,coin,ptr->src) == 'z' && strcmp(ptr->src,KMDdeposit) != 0) || (jumblr_addresstype(myinfo,coin,ptr->src) == 'z' && jumblr_addresstype(myinfo,coin,ptr->src) == 't' && strcmp(ptr->dest,KMDjumblr) != 0) )
{
printf("a non-jumblr t->z pruned\n");
free(jumblr_zgetoperationresult(myinfo,coin,ptr->opid));
ptr->status = -1;
}
}
else if ( strcmp(status,"failed") == 0 )
{
printf("%s failed\n",ptr->opid);
free(jumblr_zgetoperationresult(myinfo,coin,ptr->opid));
ptr->status = -1;
}
}
}
free_json(retjson);
}
free(retstr);
}
}
}
void jumblr_prune(struct supernet_info *myinfo,struct iguana_info *coin,struct jumblr_item *ptr)
{
struct jumblr_item *tmp; char oldsrc[128]; int32_t flag = 1;
printf("PRUNE %s\n",ptr->opid);
strcpy(oldsrc,ptr->src);
free(jumblr_zgetoperationresult(myinfo,coin,ptr->opid));
while ( flag != 0 )
{
flag = 0;
HASH_ITER(hh,myinfo->jumblrs,ptr,tmp)
{
if ( strcmp(oldsrc,ptr->dest) == 0 )
{
printf("prune %s (%s -> %s) matched oldsrc\n",ptr->opid,ptr->src,ptr->dest);
free(jumblr_zgetoperationresult(myinfo,coin,ptr->opid));
strcpy(oldsrc,ptr->src);
flag = 1;
break;
}
}
}
}
void jumblr_opidsupdate(struct supernet_info *myinfo,struct iguana_info *coin)
{
char *retstr; cJSON *array; int32_t i,n; struct jumblr_item *ptr;
if ( (retstr= jumblr_zlistoperationids(myinfo,coin)) != 0 )
{
if ( (array= cJSON_Parse(retstr)) != 0 )
{
if ( (n= cJSON_GetArraySize(array)) > 0 )
{
for (i=0; i<n; i++)
{
if ( (ptr= jumblr_opidadd(myinfo,coin,jstri(array,i))) != 0 )
{
if ( ptr->status == 0 )
jumblr_opidupdate(myinfo,coin,ptr);
//printf("%d: %s -> %s %.8f\n",ptr->status,ptr->src,ptr->dest,dstr(ptr->amount));
if ( jumblr_addresstype(myinfo,coin,ptr->src) == 'z' && jumblr_addresstype(myinfo,coin,ptr->dest) == 't' )
jumblr_prune(myinfo,coin,ptr);
}
}
}
free_json(array);
}
free(retstr);
}
}
bits256 jumblr_privkey(struct supernet_info *myinfo,char *BTCaddr,char *KMDaddr,char *prefix)
{
bits256 privkey,pubkey; uint8_t pubkey33[33]; char passphrase[sizeof(myinfo->jumblr_passphrase) + 64];
sprintf(passphrase,"%s%s",prefix,myinfo->jumblr_passphrase);
conv_NXTpassword(privkey.bytes,pubkey.bytes,(uint8_t *)passphrase,(int32_t)strlen(passphrase));
bitcoin_pubkey33(myinfo->ctx,pubkey33,privkey);
bitcoin_address(BTCaddr,0,pubkey33,33);
bitcoin_address(KMDaddr,60,pubkey33,33);
return(privkey);
}
void jumblr_DEXcheck(struct supernet_info *myinfo,struct iguana_info *coinkmd,char *BTCaddr,char *KMDaddr,bits256 privkey)
{
static double kmdprice,pending; static uint32_t lasttime;
double btcavail=0,minbtc,avebid,aveask,highbid,lowask,CMC_average,USD_average,changes[3]; struct iguana_info *coinbtc; cJSON *vals; bits256 hash; char *retstr;
coinbtc = iguana_coinfind("BTC");
if ( kmdprice == 0. || time(NULL) > lasttime+60 )
{
kmdprice = get_theoretical(&avebid,&aveask,&highbid,&lowask,&CMC_average,changes,"komodo","KMD","BTC",&USD_average);
lasttime = (uint32_t)time(NULL);
printf("KMD %.8f\n",kmdprice);
}
if ( kmdprice > SMALLVAL )
{
minbtc = (kmdprice * 1.1) * (JUMBLR_INCR + 3*(JUMBLR_INCR * JUMBLR_FEE + JUMBLR_TXFEE));
if ( coinbtc != 0 && (btcavail= dstr(jumblr_balance(myinfo,coinbtc,BTCaddr))) > minbtc+pending )
{
printf("BTC deposits %.8f, min %.8f\n",btcavail,minbtc);
vals = cJSON_CreateObject();
jaddstr(vals,"source","BTC");
//hash = curve25519(privkey,curve25519_basepoint9());
jaddstr(vals,"dest","KMD");
jaddnum(vals,"amount",btcavail*.3);
jaddnum(vals,"minprice",kmdprice*.95);
jaddnum(vals,"usejumblr",1);
memset(hash.bytes,0,sizeof(hash));
pending = btcavail;
if ( (retstr= InstantDEX_request(myinfo,coinbtc,0,0,hash,vals,"")) != 0 )
{
printf("request.(%s) -> (%s)\n",jprint(vals,0),retstr);
free(retstr);
}
// curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"InstantDEX\",\"method\":\"request\",\"vals\":{\"source\":\"KMD\",\"amount\":20,\"dest\":\"USD\",\"minprice\":0.08}}"
} //else printf("btcavail %.8f pending %.8f\n",btcavail,pending);
} else printf("null kmdprice %.8f\n",kmdprice);
}
void jumblr_iteration(struct supernet_info *myinfo,struct iguana_info *coin,int32_t selector,int32_t modval)
{
//static uint32_t lasttime;
char BTCaddr[64],KMDaddr[64],*zaddr,*retstr; bits256 privkey; uint64_t amount=0,total=0; double fee; struct jumblr_item *ptr,*tmp; uint8_t r;
fee = JUMBLR_INCR * JUMBLR_FEE;
OS_randombytes(&r,sizeof(r));
//r = 0;
if ( strcmp(coin->symbol,"KMD") == 0 && coin->FULLNODE < 0 )
{
//printf("JUMBLR selector.%d modval.%d r.%d\n",selector,modval,r&7);
switch ( selector )
{
case 0: // public -> z, need to importprivkey
jumblr_privkey(myinfo,BTCaddr,KMDaddr,JUMBLR_DEPOSITPREFIX);
if ( (total= jumblr_balance(myinfo,coin,KMDaddr)) >= (JUMBLR_INCR + 3*(fee+JUMBLR_TXFEE))*SATOSHIDEN )
{
if ( (r & 1) == 0 )
{
if ( (zaddr= jumblr_zgetnewaddress(myinfo,coin)) != 0 )
{
if ( total >= SATOSHIDEN * ((JUMBLR_INCR + 3*fee)*100 + 3*JUMBLR_TXFEE) )
amount = SATOSHIDEN * ((JUMBLR_INCR + 3*fee)*100 + 3*JUMBLR_TXFEE);
else if ( total >= SATOSHIDEN * ((JUMBLR_INCR + 3*fee)*10 + 3*JUMBLR_TXFEE) )
amount = SATOSHIDEN * ((JUMBLR_INCR + 3*fee)*10 + 3*JUMBLR_TXFEE);
else amount = SATOSHIDEN * ((JUMBLR_INCR + 3*fee) + 3*JUMBLR_TXFEE);
if ( (retstr= jumblr_sendt_to_z(myinfo,coin,KMDaddr,zaddr,dstr(amount))) != 0 )
{
printf("sendt_to_z.(%s)\n",retstr);
free(retstr);
}
free(zaddr);
} else printf("no zaddr from jumblr_zgetnewaddress\n");
}
} else printf("%s total %.8f vs %.8f\n",KMDaddr,dstr(total),(JUMBLR_INCR + 3*(fee+JUMBLR_TXFEE)));
break;
case 1: // z -> z
jumblr_opidsupdate(myinfo,coin);
HASH_ITER(hh,myinfo->jumblrs,ptr,tmp)
{
if ( jumblr_addresstype(myinfo,coin,ptr->src) == 't' && jumblr_addresstype(myinfo,coin,ptr->dest) == 'z' )
{
if ( (r & 1) == 0 && ptr->spent == 0 && (total= jumblr_balance(myinfo,coin,ptr->dest)) >= (fee + JUMBLR_FEE)*SATOSHIDEN )
{
if ( (zaddr= jumblr_zgetnewaddress(myinfo,coin)) != 0 )
{
if ( (retstr= jumblr_sendz_to_z(myinfo,coin,ptr->dest,zaddr,dstr(total))) != 0 )
{
printf("sendz_to_z.(%s)\n",retstr);
free(retstr);
}
ptr->spent = (uint32_t)time(NULL);
free(zaddr);
break;
}
}
}
}
break;
case 2: // z -> public
jumblr_opidsupdate(myinfo,coin);
HASH_ITER(hh,myinfo->jumblrs,ptr,tmp)
{
if ( jumblr_addresstype(myinfo,coin,ptr->src) == 'z' && jumblr_addresstype(myinfo,coin,ptr->dest) == 'z' )
{
if ( (r & 1) == 0 && ptr->spent == 0 && (total= jumblr_balance(myinfo,coin,ptr->dest)) >= (fee + JUMBLR_FEE)*SATOSHIDEN )
{
privkey = jumblr_privkey(myinfo,BTCaddr,KMDaddr,"");
if ( (retstr= jumblr_sendz_to_t(myinfo,coin,ptr->dest,KMDaddr,dstr(total))) != 0 )
{
printf("sendz_to_t.(%s)\n",retstr);
free(retstr);
}
ptr->spent = (uint32_t)time(NULL);
break;
}
}
}
break;
}
}
}

90
basilisk/smartaddress.c

@ -0,0 +1,90 @@
/******************************************************************************
* 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. *
* *
******************************************************************************/
// included from basilisk.c
int32_t smartaddress_add(struct supernet_info *myinfo,bits256 privkey,char *BTCaddr,char *KMDaddr)
{
struct smartaddress *ap;
int32_t i;
if ( myinfo->numsmartaddrs < sizeof(myinfo->smartaddrs)/sizeof(*myinfo->smartaddrs) )
{
for (i=0; i<myinfo->numsmartaddrs; i++)
if ( bits256_cmp(myinfo->smartaddrs[i].privkey,privkey) == 0 )
return(-1);
ap = &myinfo->smartaddrs[myinfo->numsmartaddrs++];
ap->privkey = privkey;
bitcoin_pubkey33(myinfo->ctx,ap->pubkey33,privkey);
calc_rmd160_sha256(ap->rmd160,ap->pubkey33,33);
ap->pubkey = curve25519(privkey,curve25519_basepoint9());
char coinaddr[64]; uint8_t addrtype,rmd160[20];
bitcoin_address(coinaddr,0,ap->pubkey33,33);
for (i=0; i<20; i++)
printf("%02x",ap->rmd160[i]);
bitcoin_addr2rmd160(&addrtype,rmd160,coinaddr);
printf(", ");
for (i=0; i<20; i++)
printf("%02x",rmd160[i]);
printf (" <- rmd160 for %d %s vs %s\n",myinfo->numsmartaddrs,coinaddr,BTCaddr);
return(myinfo->numsmartaddrs);
}
printf("too many smartaddresses %d vs %d\n",myinfo->numsmartaddrs,(int32_t)(sizeof(myinfo->smartaddrs)/sizeof(*myinfo->smartaddrs)));
return(-1);
}
int32_t smartaddress(struct supernet_info *myinfo,bits256 *privkeyp,char *coinaddr)
{
int32_t i; uint8_t addrtype,rmd160[20];
memset(privkeyp,0,sizeof(*privkeyp));
bitcoin_addr2rmd160(&addrtype,rmd160,coinaddr);
for (i=0; i<myinfo->numsmartaddrs; i++)
if ( memcmp(myinfo->smartaddrs[i].rmd160,rmd160,20) == 0 )
{
*privkeyp = myinfo->smartaddrs[i].privkey;
printf("MATCHED %s\n",coinaddr);
return(i);
}
for (i=0; i<20; i++)
printf("%02x",rmd160[i]);
printf(" <- rmd160 smartaddress cant find (%s) of %d\n",coinaddr,myinfo->numsmartaddrs);
return(-1);
}
int32_t smartaddress_pubkey(struct supernet_info *myinfo,bits256 *privkeyp,bits256 pubkey)
{
int32_t i;
memset(privkeyp,0,sizeof(*privkeyp));
for (i=0; i<myinfo->numsmartaddrs; i++)
if ( bits256_cmp(myinfo->smartaddrs[i].pubkey,pubkey) == 0 )
{
*privkeyp = myinfo->smartaddrs[i].privkey;
return(i);
}
return(-1);
}
int32_t smartaddress_pubkey33(struct supernet_info *myinfo,bits256 *privkeyp,uint8_t *pubkey33)
{
int32_t i;
memset(privkeyp,0,sizeof(*privkeyp));
for (i=0; i<myinfo->numsmartaddrs; i++)
if ( memcmp(myinfo->smartaddrs[i].pubkey33,pubkey33,33) == 0 )
{
*privkeyp = myinfo->smartaddrs[i].privkey;
return(i);
}
return(0);
}

47
basilisk/tradebots_SVM.h

@ -20,16 +20,14 @@
//#include <dispatch/dispatch.h>
typedef float svmtype;
#ifdef WIN32
// fadedreamz@gmail.com - added for successful compilation, however, for MSVC probably require a particular OpenCL SDK
// to work with it (e,g nvidia or amd SDK)
typedef struct fake_opencl_double {
typedef struct fake_opencl_double { //use a struct for double2 typedefinition on all OS - ca333@protonmail.ch
double x;
double y;
}double2;
#else
typedef double double2 __attribute__((ext_vector_type(2)));
#endif
#define MAX_VECTORS (1440 * 365 * 5)
#define MAIN_MAXCORES 16
#define c_to_refc(c) (c)
@ -192,7 +190,7 @@ void ocas_purge(struct ocas_vars *vars)
fatal("dot_expanded_features not implemented");
return(0);
}
static inline void add_expanded_features(register double *W,register double y,register int c,register int selector,register int numfeatures)
{
fatal("add_expanded_features not implemented");
@ -226,7 +224,7 @@ static inline double calc_ocas_output(register struct ocas_vars *vars,register i
// printf("%f ",sum);
return(sum);
}
static inline void add_ocas_output(register double y,register struct ocas_vars *vars,register int selector,register int c,register int weekind,register int answerind,register double *W,register double *new_a,register int numfeatures)
{
register int coeffi;
@ -321,7 +319,7 @@ static inline double _dbufave(register double *buf,register int len)
sum = 0.;
return(sum);
}
static inline void add_newcut_entry(register struct ocas_vars *vars,register int answerind,register int *new_cut,register int i,register int weekind,register double y)
{
weekind <<= 1;
@ -334,7 +332,7 @@ static inline double validate_ocas_model(register struct ocas_vars *vars,registe
{
register svmtype *features;
register double y,pred,perc,answer=0.,feature;
register int i,j,pos,neg,good,bad,oldcuts,training_errors,weekind,nonz,posA,negA;
register int i,j,pos,neg,good,bad,oldcuts,training_errors,weekind,nonz=0,posA,negA;
for (i=pos=neg=good=bad=oldcuts=training_errors=posA=negA=0; i<numdocs; i++)
{
weekind = (weekinds == 0) ? i : weekinds[i];
@ -403,7 +401,7 @@ static int _increasing_double(const void *a,const void *b)
#undef double_a
#undef double_b
}
static inline void calc_ocas_strategy(register struct ocas_vars *vars,register int answerind,register double C,register int numfeatures,register int len,register int *weekinds,register int *new_cut,register double *W,register double *oldW,register double *output,register double *old_output,register double2 *hpfb)
{
double answermag;
@ -541,9 +539,9 @@ static inline void calc_ocas_strategy(register struct ocas_vars *vars,register i
static inline double ocas_splx_solver(register int *nonzalphap,register int maxlhs,register double *d,register double *activeH,register double *diag_H,register double *f,register double C,register double *alpha,register int n,register int MaxIter,register double TolAbs,register double TolRel,register double QP_TH)
{
register double *col_u,*col_v;
register double QP,QD,lastQD,tmp,diff,distA,distB,etaA,etaB,improv,tmp_num,delta,x_neq0,xval,dval,diagval,tmp_den,tau;
register int u=0,v=0,i,j,iter,nonzalpha,unlikely = 0;
register double *col_u=0,*col_v=0;
register double QP,QD,lastQD,tmp,diff,distA,distB,etaA,etaB,improv,tmp_num,delta,x_neq0,xval,dval,diagval=0.,tmp_den,tau=0.;
register int u=0,v=0,i,j,iter,nonzalpha=0,unlikely = 0;
QP = distA = distB = OCAS_PLUS_INF; lastQD = QD = OCAS_NEG_INF;
x_neq0 = C;
etaA = etaB = 0.;
@ -782,11 +780,11 @@ static void ocas_print(struct ocas_vars *vars,int answerind,int ishwm,double C)
//printf("ocas_print.A%d\n",answerind);
//printf("%s.A%02d %4d %8.2f | QP %9.3f QD %9.3f [%9.4f %7.3f] SV.%d %4d | M%9.6f (%9.6f max %8.1f %9.6f) %s.A%02d %9.6f%%\n",
dispvals[0] = vars->Q_P[answerind]/1000000000.; dispvals[1] = (C * vars->Q_D[answerind])/1000000000.;
dispvals[2] = (vars->Q_P[answerind]-C * vars->Q_D[answerind]) / 1000000000;
dispvals[2] = (vars->Q_P[answerind]-C * vars->Q_D[answerind]) / 1000000000;
dispvals[3] = (vars->Q_P[answerind]-C * vars->Q_D[answerind]) / MAX(1,fabs(vars->Q_P[answerind]));
printf("%3d %d.A%02d +%d -%d",vars->nohwm[answerind],vars->refc,answerind,vars->good[answerind],vars->bad[answerind]);
printf(" %4d %8.2f |QP %9.3f QD %10.2f [%11.2f %9.1f] SV.%3d %3d |M%9.3f errs.%-6d %-8.0f %5.2f%% errs %6.5f A%9.6f W0%9.6f D%11.9f\n",//[%7.4f%%]\n",
vars->numIt[answerind],vars->ocas_time/1000,dispvals[0],dispvals[1],dispvals[2],dispvals[3],
vars->numIt[answerind],vars->ocas_time/1000,dispvals[0],dispvals[1],dispvals[2],dispvals[3],
vars->nNZAlpha[answerind], vars->numlhs[answerind],
// PTRS->lastmetrics[answerind],PTRS->learningrates[answerind][0],PTRS->maxiters[answerind],PTRS->learningrates[answerind][1],
vars->lastmetrics[answerind][0],vars->trn_err[answerind],vars->maxiters[answerind],vars->perc[answerind],
@ -827,8 +825,8 @@ static inline void finish_ocasiter(register int answerind,register struct ocas_v
vars->errperc[answerind] = (100 * (double)vars->trn_err[answerind])/(double)MAX(1,vars->len[answerind]);
vars->Q_P[answerind] = 0.5*vars->sq_norm_W[answerind] + (C * vars->xi[answerind]);
vars->ocas_time = (vars->output_time + vars->w_time + vars->add_time + vars->sort_time + vars->qp_solver_time);
ocas_print(vars,answerind,0,C);
}
ocas_print(vars,answerind,0,C);
}
static inline int ocas_iter(struct ocas_vars *vars,int max_nohwm)
{
@ -840,7 +838,7 @@ static inline int ocas_iter(struct ocas_vars *vars,int max_nohwm)
int inactives[81];
register struct ocas_CLbuffers *ptr;
register double netcuts,startmilli,y,psum,pcount,nosum;
register int i,numfeatures,cutlen,lastanswerind,lwm,numactive,numthreads,answerind,*weekinds;
register int i,numfeatures,cutlen,lastanswerind,lwm=(1<<20),numactive,numthreads,answerind,*weekinds;
numactive = 0;
if ( (numfeatures= vars->numfeatures) > MAX_OCAS_FEATURES )
{
@ -947,8 +945,8 @@ static inline int init_ocas_vars(int numthreads,int selector,long answerindmask,
{
int answerind,lastanswerind,retval = 0;
lastanswerind = TRADEBOTS_NUMANSWERS;
vars->maxlen = maxlen;
vars->numthreads = numthreads;
vars->maxlen = maxlen;
vars->numthreads = numthreads;
vars->selector = selector;
//printf("init_ocas_vars lastanswerind.%d\n",lastanswerind);
for (answerind=0; answerind<lastanswerind; answerind++)
@ -956,8 +954,8 @@ static inline int init_ocas_vars(int numthreads,int selector,long answerindmask,
//printf("A%d.len_%d ",answerind,vars->len[answerind]);
if ( vars->len[answerind] > 0 )//&& (answerindmask == -1L || ((1L<<answerind) & answerindmask) != 0) )
{
vars->refc = c_to_refc(c); vars->c = c; vars->C = C;
vars->numfeatures = numfeatures; vars->maxlhs = maxlhs;
vars->refc = c_to_refc(c); vars->c = c; vars->C = C;
vars->numfeatures = numfeatures; vars->maxlhs = maxlhs;
if ( vars->CLspaces[answerind] == 0 )
vars->CLspaces[answerind] = myaligned_alloc(sizeof(*vars->CLspaces[answerind]));
vars->answerabsaves[answerind] = answerabsave[answerind];
@ -972,7 +970,7 @@ static inline int init_ocas_vars(int numthreads,int selector,long answerindmask,
//printf("mask.%lx init_ocas_vars selector.%d weekinds[0].%p\n",answerindmask,selector,vars->weekinds[0]);
return(retval);
}
void ocas_init(struct ocas_vars *vars,int32_t c,int32_t numfeatures,int32_t starti,int32_t endi)
{
struct ocas_CLbuffers *ptr; struct ocas_lhsbuffers *lhs;
@ -1061,7 +1059,7 @@ void ocas_init(struct ocas_vars *vars,int32_t c,int32_t numfeatures,int32_t star
vars->output_time = vars->sort_time = vars->w_time = vars->qp_solver_time = vars->ocas_time = vars->add_time = 0;
vars->startweekind = starti; vars->endweekind = endi;
}
int32_t ocas_gen(int32_t c,int32_t numfeatures,int32_t starti,int32_t endi)
{
int32_t i; struct ocas_vars *vars = calloc(1,sizeof(*vars));
@ -1072,4 +1070,3 @@ int32_t ocas_gen(int32_t c,int32_t numfeatures,int32_t starti,int32_t endi)
return(0);
}
#endif

72
basilisk/tradebots_liquidity.c

@ -110,7 +110,7 @@ int32_t tradebots_calcrawfeatures(struct tradebot_arbpair *pair)
}
if ( n > sizeof(pair->rawfeatures)/sizeof(*pair->rawfeatures) )
{
printf("n.%d too many for rawfeatures %ld\n",n,sizeof(pair->rawfeatures)/sizeof(*pair->rawfeatures));
printf("n.%d too many for rawfeatures %d\n",n,(int32_t)(sizeof(pair->rawfeatures)/sizeof(*pair->rawfeatures)));
exit(-1);
}
return(n);
@ -160,7 +160,7 @@ struct tradebot_arbpair *tradebots_arbpair_create(char *base,char *rel)
pair->fp = OS_appendfile(fname);
if ( (ftell(pair->fp) % sizeof(pair->rawfeatures)) != 0 )
{
printf("misalinged rawfeatures %ld %ld\n",ftell(pair->fp),(ftell(pair->fp) % sizeof(pair->rawfeatures)));
printf("misalinged rawfeatures %d %d\n",(uint32_t)ftell(pair->fp),(uint32_t)(ftell(pair->fp) % sizeof(pair->rawfeatures)));
}
fseek(pair->fp,(ftell(pair->fp) / sizeof(pair->rawfeatures)) * sizeof(pair->rawfeatures) - sizeof(pair->rawfeatures),SEEK_SET);
if ( fread(pair->rawfeatures,1,sizeof(pair->rawfeatures),pair->fp) == sizeof(pair->rawfeatures) )
@ -309,8 +309,8 @@ int32_t tradebots_calcpreds(float *RTpreds,struct tradebot_arbpair *pair,double
void tradebots_calcanswers(struct tradebot_arbpair *pair)
{
double highbid,lowask,futurebid,futureask,ave,vol,bidaves[TRADEBOTS_NUMDECAYS],askaves[TRADEBOTS_NUMDECAYS],bidslopes[TRADEBOTS_NUMDECAYS],askslopes[TRADEBOTS_NUMDECAYS];
float rawfeatures[sizeof(pair->rawfeatures)/sizeof(*pair->rawfeatures)],futuremin,futuremax,minval,maxval,*hblas = 0;
uint32_t timestamp,firsttime = 0; long fpos,savepos; int32_t flag,i,iter,j,ind,maxi;
float rawfeatures[sizeof(pair->rawfeatures)/sizeof(*pair->rawfeatures)],futuremin=0,futuremax=0,minval=0,maxval=0,*hblas = 0;
uint32_t timestamp,firsttime = 0; long fpos,savepos; int32_t flag,i,iter,j,ind,maxi=0;
OCAS_PLUS_INF = _OCAS_PLUS_INF; OCAS_NEG_INF = -_OCAS_PLUS_INF;
if ( pair->fp != 0 )
{
@ -932,6 +932,8 @@ void _default_liquidity_command(struct supernet_info *myinfo,char *base,bits256
li.ask = jdouble(vals,"ask");
if ( (li.minvol= jdouble(vals,"minvol")) <= 0. )
li.minvol = (strcmp("BTC",base) == 0) ? 0.0001 : 0.001;
if ( strcmp(li.base,"KMD") == 0 && strcmp(li.rel,"BTC") == 0 && li.minvol > 100. )
li.minvol = 100.;
if ( (li.maxvol= jdouble(vals,"maxvol")) < li.minvol )
li.maxvol = li.minvol;
if ( (li.totalvol= jdouble(vals,"total")) < li.maxvol )
@ -982,7 +984,7 @@ void _default_liquidity_command(struct supernet_info *myinfo,char *base,bits256
} else tradebot_monitor(myinfo,0,0,0,li.exchange,li.base,li.rel,0.);
}
myinfo->linfos[i] = li;
printf("Set linfo[%d] %s (%s/%s) profitmargin %.6f bid %.6f ask %.8f maxvol %.f ref %.8f\n",i,li.exchange,li.base,li.rel,li.profit,li.bid,li.ask,li.maxvol,li.refprice);
printf("Set linfo[%d] %s (%s/%s) profitmargin %.6f bid %.8f ask %.8f minvol %.6f maxvol %.6f ref %.8f <- (%s)\n",i,li.exchange,li.base,li.rel,li.profit,li.bid,li.ask,li.minvol,li.maxvol,li.refprice,jprint(vals,0));
return;
}
}
@ -1010,7 +1012,7 @@ double _default_liquidity_active(struct supernet_info *myinfo,double *refpricep,
dir = 1;
else if ( strcmp(rel,refli.base) == 0 && strcmp(base,refli.rel) == 0 )
dir = -1;
else dir = 0;
else continue;
if ( exchange[0] != 0 && refli.exchange[0] != 0 && strcmp(exchange,refli.exchange) != 0 )
{
printf("continue %s %s/%s [%d] dir.%d vs %s %s/%s\n",exchange,base,rel,i,dir,refli.exchange,refli.base,refli.rel);
@ -1056,7 +1058,7 @@ struct liquidity_info *_default_lifind(struct supernet_info *myinfo,int32_t *dir
void _default_swap_balancingtrade(struct supernet_info *myinfo,struct basilisk_swap *swap,int32_t iambob)
{
// update balance, compare to target balance, issue balancing trade via central exchanges, if needed
struct liquidity_info *li; double vol,price,volume,srcamount,destamount,profitmargin,dir=0.,dotrade=1.; char base[64],rel[64]; int32_t idir;
struct liquidity_info *li; double vol,price,volume,srcamount,destamount,profitmargin,dir=0.,dotrade=1.; char base[64],rel[64]; int32_t idir; char *tradestr=0; cJSON *tradejson;
srcamount = swap->I.req.srcamount;
destamount = swap->I.req.destamount;
profitmargin = (double)swap->I.req.profitmargin / 1000000.;
@ -1101,8 +1103,8 @@ void _default_swap_balancingtrade(struct supernet_info *myinfo,struct basilisk_s
{
printf("BOB: price %f * vol %f -> %s newprice %f margin %.2f%%\n",price,volume,dir < 0. ? "buy" : "sell",price + dir * price * profitmargin,100*profitmargin);
if ( dir < 0. )
InstantDEX_buy(myinfo,0,0,0,"poloniex",base,rel,price,volume,dotrade);
else InstantDEX_sell(myinfo,0,0,0,"poloniex",base,rel,price,volume,dotrade);
tradestr = InstantDEX_buy(myinfo,0,0,0,"bittrex",base,rel,price,volume,dotrade);
else tradestr = InstantDEX_sell(myinfo,0,0,0,"bittrex",base,rel,price,volume,dotrade);
}
}
else
@ -1111,14 +1113,26 @@ void _default_swap_balancingtrade(struct supernet_info *myinfo,struct basilisk_s
{
printf("ALICE: price %f * vol %f -> %s newprice %f margin %.2f%%\n",price,volume,dir > 0. ? "buy" : "sell",price - dir * price * profitmargin,100*profitmargin);
if ( dir > 0. )
InstantDEX_buy(myinfo,0,0,0,"poloniex",base,rel,price,volume,dotrade);
else InstantDEX_sell(myinfo,0,0,0,"poloniex",base,rel,price,volume,dotrade);
tradestr = InstantDEX_buy(myinfo,0,0,0,"bittrex",base,rel,price,volume,dotrade);
else tradestr = InstantDEX_sell(myinfo,0,0,0,"bittrex",base,rel,price,volume,dotrade);
}
}
if ( tradestr != 0 )
{
if ( (tradejson= cJSON_Parse(tradestr)) != 0 )
{
if ( jobj(tradejson,"error") == 0 ) // balancing is opposite trade
tradebot_pendingadd(myinfo,tradejson,swap->I.req.dest,destamount,swap->I.req.src,srcamount);
else free_json(tradejson);
}
free(tradestr);
}
}
void tradebot_swap_balancingtrade(struct supernet_info *myinfo,struct basilisk_swap *swap,int32_t iambob)
{
printf("balancing trade\n");
return;
if ( swap->balancingtrade == 0 )
_default_swap_balancingtrade(myinfo,swap,iambob);
else (*swap->balancingtrade)(myinfo,swap,iambob);
@ -1143,7 +1157,7 @@ double tradebot_liquidity_active(struct supernet_info *myinfo,double *refpricep,
void tradebots_processprices(struct supernet_info *myinfo,struct exchange_info *exchange,char *base,char *rel,struct exchange_quote *bidasks,int32_t numbids,int32_t numasks)
{
double price,profitmargin,volume; struct tradebot_arbpair *pair;
double price,profitmargin=0.,volume; struct tradebot_arbpair *pair;
if ( strcmp(rel,"NXT") == 0 && strcmp(base,"BTC") != 0 && (base= NXT_assetnamefind(base)) == 0 )
{
//printf("reject %s %s/%s\n",exchange,base,rel);
@ -1154,7 +1168,7 @@ void tradebots_processprices(struct supernet_info *myinfo,struct exchange_info *
//printf("reject %s %s/%s\n",exchange,base,rel);
return;
}
//printf("%s %s/%s bids.%d asks.%d\n",exchange->name,base,rel,numbids,numasks);
printf("%s %s/%s bids.%d asks.%d\n",exchange->name,base,rel,numbids,numasks);
if ( numbids > 0 && (volume= bidasks[0].volume) > 0. && (profitmargin=
tradebot_liquidity_active(myinfo,&price,exchange->name,base,rel,volume)) > 0. )
{
@ -1193,35 +1207,3 @@ void tradebots_processprices(struct supernet_info *myinfo,struct exchange_info *
}
}
}
#include "../includes/iguana_apidefs.h"
#include "../includes/iguana_apideclares.h"
TWO_STRINGS(tradebot,gensvm,base,rel)
{
#ifdef _WIN
return(clonestr("{\"error\":\"windows doesnt support SVM\"}"));
#else
int32_t numfeatures = 317*61;
struct tradebot_arbpair *pair;
if ( base[0] != 0 && rel[0] != 0 && (pair= tradebots_arbpair_find(base,rel)) != 0 && pair->fp != 0 )
{
tradebots_calcanswers(pair);
ocas_gen(pair->refc,numfeatures,0,(int32_t)(ftell(pair->fp) / sizeof(pair->rawfeatures)));
return(clonestr("{\"result\":\"success\"}"));
} else return(clonestr("{\"error\":\"cant find arbpair\"}"));
#endif
}
ZERO_ARGS(tradebot,openliquidity)
{
int32_t i; cJSON *array = cJSON_CreateArray();
for (i=0; i<sizeof(myinfo->linfos)/sizeof(*myinfo->linfos); i++)
{
if ( myinfo->linfos[i].base[0] != 0 )
jaddi(array,linfo_json(&myinfo->linfos[i]));
}
return(jprint(array,1));
}
#include "../includes/iguana_apiundefs.h"

108
basilisk/tradebots_marketmaker.c

@ -0,0 +1,108 @@
/******************************************************************************
* 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. *
* *
******************************************************************************/
// included from basilisk.c
// "currency":{"value":%.8f, "pending":%.8f}
cJSON *tradebot_balancediff(cJSON *item,cJSON *anchoritem) // only item might be null
{
double current[2],past[2]; int32_t i; cJSON *diffitem = jduplicate(anchoritem);
memset(current,0,sizeof(current));
memset(past,0,sizeof(past));
if ( jobj(diffitem,"value") != 0 )
jdelete(diffitem,"value");
if ( jobj(diffitem,"pending") != 0 )
jdelete(diffitem,"pending");
for (i=0; i<2; i++)
{
if ( current[i] != 0. || past[i] != 0. )
jaddnum(diffitem,i == 0 ? "value" : "pending",current[i] - past[i]);
}
return(diffitem);
}
cJSON *tradebot_balancesdiff(struct supernet_info *myinfo,cJSON *current,cJSON *anchor)
{
cJSON *item,*anchoritem,*diffitem,*array; int32_t i,n; char *field;
if ( anchor == 0 )
return(jduplicate(current));
array = cJSON_CreateObject();
n = cJSON_GetArraySize(current);
for (i=0; i<n; i++)
{
item = jitem(current,i);
field = jfieldname(item);
if ( (anchoritem= jobj(anchor,field)) != 0 )
diffitem = tradebot_balancediff(item,anchoritem);
else diffitem = jduplicate(item);
jadd(array,field,diffitem);
}
n = cJSON_GetArraySize(anchor);
for (i=0; i<n; i++)
{
item = jitem(current,i);
field = jfieldname(item);
if ( jobj(array,field) == 0 )
jadd(array,field,tradebot_balancediff(0,item));
}
return(array);
}
// get balances from all exchanges, wallets, pending
double tradebot_balance(struct supernet_info *myinfo,char *base)
{
cJSON *json; double value = 0.; int32_t i; struct iguana_info *coin = iguana_coinfind(base);
if ( coin != 0 && (json= iguana_getinfo(myinfo,coin)) != 0 )
{
value = jdouble(json,"balance");
free_json(json);
}
for (i=0; i<myinfo->numexchanges; i++)
{
value += 0;//InstantDEX_balance(myinfo,0,0,0,exchange,base);
}
return(value);
}
void tradebot_pendingadd(struct supernet_info *myinfo,cJSON *tradejson,char *base,double basevolume,char *rel,double relvolume)
{
portable_mutex_lock(&myinfo->pending_mutex);
// add to myinfo->trades
portable_mutex_unlock(&myinfo->pending_mutex);
}
void tradebot_pendingremove(struct supernet_info *myinfo,char *base,double basevolume,char *rel,double relvolume)
{
portable_mutex_lock(&myinfo->pending_mutex);
// remove from myinfo->trades
portable_mutex_unlock(&myinfo->pending_mutex);
}
double tradebot_pending(struct supernet_info *myinfo,char *base)
{
double pending = 0.; struct pending_trade *tp,*tmp;
portable_mutex_lock(&myinfo->pending_mutex);
HASH_ITER(hh,myinfo->trades,tp,tmp)
{
if ( strcmp(base,tp->base) == 0 )
pending += tp->dir * tp->basevolume;
else if ( strcmp(base,tp->rel) == 0 )
pending -= tp->dir * tp->relvolume;
}
portable_mutex_unlock(&myinfo->pending_mutex);
return(pending);
}

2
crypto777/OS_portable.c

@ -48,7 +48,7 @@ void OS_portable_randombytes(unsigned char *x,long xlen)
sleep(1);
continue;
}
if ( 0 )
if ( (0) )
{
int32_t j;
for (j=0; j<i; j++)

7
crypto777/OS_portable.h

@ -18,7 +18,7 @@
// iguana_OS has functions that invoke system calls. Whenever possible stdio and similar functions are use and most functions are fully portable and in this file. For things that require OS specific, the call is routed to iguana_OS_portable_* Usually, all but one OS can be handled with the same code, so iguana_OS_portable.c has most of this shared logic and an #ifdef iguana_OS_nonportable.c
#ifdef __APPLE__
#define LIQUIDITY_PROVIDER 1
//#define LIQUIDITY_PROVIDER 1
#endif
#ifdef NATIVE_WINDOWS
@ -365,8 +365,12 @@ void escape_code(char *escaped,char *str);
void SaM_PrepareIndices();
// iguana_serdes.c
#ifndef IGUANA_LOG2PACKETSIZE
#define IGUANA_LOG2PACKETSIZE 22
#endif
#ifndef IGUANA_MAXPACKETSIZE
#define IGUANA_MAXPACKETSIZE (1 << IGUANA_LOG2PACKETSIZE)
#endif
struct iguana_msghdr { uint8_t netmagic[4]; char command[12]; uint8_t serdatalen[4],hash[4]; } PACKED;
int32_t iguana_rwnum(int32_t rwflag,uint8_t *serialized,int32_t len,void *endianedp);
@ -400,6 +404,7 @@ int32_t revsort32(uint32_t *buf,uint32_t num,int32_t size);
bits256 bits256_sha256(bits256 data);
void bits256_rmd160(uint8_t rmd160[20],bits256 data);
void bits256_rmd160_sha256(uint8_t rmd160[20],bits256 data);
double get_theoretical(double *avebidp,double *aveaskp,double *highbidp,double *lowaskp,double *CMC_averagep,double changes[3],char *name,char *base,char *rel,double *USD_averagep);
extern char *Iguana_validcommands[];
extern bits256 GENESIS_PUBKEY,GENESIS_PRIVKEY;

7
crypto777/OS_time.c

@ -552,7 +552,7 @@ uint32_t OS_conv_datenum(int32_t datenum,int32_t hour,int32_t minute,int32_t sec
int32_t OS_conv_unixtime(struct tai *tp,int32_t *secondsp,time_t timestamp) // gmtime -> datenum + number of seconds
{
struct tm tm,*ptr; int32_t datenum; uint32_t checktime; char buf[64]; struct tai t; struct taitime ct;
struct tai t; struct taitime ct;
if ( 1 )
{
*tp = t = utc2tai((uint32_t)timestamp);
@ -560,8 +560,9 @@ int32_t OS_conv_unixtime(struct tai *tp,int32_t *secondsp,time_t timestamp) // g
*secondsp = (ct.hour*3600 + ct.minute*60 + ct.second);
return(calc_datenum(ct.date.year,ct.date.month,ct.date.day));
}
else
/*else
{
struct tm tm,*ptr; int32_t datenum; uint32_t checktime; char buf[64];
if ( (ptr= gmtime(&timestamp)) != 0 )
tm = *ptr;;
strftime(buf,sizeof(buf), "%Y-%m-%dT%H:%M:%SZ",&tm); //printf("%s\n",buf);
@ -572,7 +573,7 @@ int32_t OS_conv_unixtime(struct tai *tp,int32_t *secondsp,time_t timestamp) // g
return(-1);
}
return(datenum);
}
}*/
}
int32_t conv_date(int32_t *secondsp,char *date)

3
crypto777/SaM.c

@ -285,7 +285,7 @@ int32_t SaM_test()
memset(histo,0,sizeof(histo));
for (i=0; i<5; i++)
{
if ( 0 && (i % 100) == 99 )
if ( (0) && (i % 100) == 99 )
{
for (j=0; j<32; j++)
seed.bytes[j] = rand() >> 8;
@ -340,6 +340,7 @@ bits384 SaM_encrypt(uint8_t *dest,uint8_t *src,int32_t len,bits384 password,uint
{
bits384 xorpad; int32_t i; struct SaM_info XORpad;
SaM_Initialize(&XORpad), SaM_Absorb(&XORpad,password.bytes,sizeof(password),(void *)&timestamp,sizeof(timestamp));
memset(xorpad.bytes,0,sizeof(xorpad));
while ( len >= 0 )
{
SaM_emit(&XORpad);

31
crypto777/bitcoind_RPC.c

@ -14,15 +14,11 @@
******************************************************************************/
#include "OS_portable.h"
#define LIQUIDITY_PROVIDER 1
#if LIQUIDITY_PROVIDER
#ifdef _WIN32
#include <curl.h>
#include <easy.h>
#else
#include <curl/curl.h>
#include <curl/easy.h>
#endif
// return data from the server
#define CURL_GLOBAL_ALL (CURL_GLOBAL_SSL|CURL_GLOBAL_WIN32)
@ -109,6 +105,8 @@ char *post_process_bitcoind_RPC(char *debugstr,char *command,char *rpcstr,char *
*
************************************************************************/
static int32_t USE_JAY;
char *Jay_NXTrequest(char *command,char *params)
{
char *retstr = 0;
@ -127,7 +125,7 @@ char *bitcoind_RPC(char **retstrp,char *debugstr,char *url,char *userpass,char *
didinit = 1;
curl_global_init(CURL_GLOBAL_ALL); //init the curl session
}
if ( USE_JAY != 0 && (strncmp(url,"http://127.0.0.1:7876/nxt",strlen("http://127.0.0.1:7876/nxt")) == 0 || strncmp(url,"https://127.0.0.1:7876/nxt",strlen("https://127.0.0.1:7876/nxt")) == 0) )
if ( (0) && (USE_JAY != 0 && (strncmp(url,"http://127.0.0.1:7876/nxt",strlen("http://127.0.0.1:7876/nxt")) == 0 || strncmp(url,"https://127.0.0.1:7876/nxt",strlen("https://127.0.0.1:7876/nxt")) == 0)) )
{
if ( (databuf= Jay_NXTrequest(command,params)) != 0 )
return(databuf);
@ -138,7 +136,7 @@ char *bitcoind_RPC(char **retstrp,char *debugstr,char *url,char *userpass,char *
else specialcase = 0;
if ( url[0] == 0 )
strcpy(url,"http://127.0.0.1:7776");
if ( specialcase != 0 && 0 )
if ( specialcase != 0 && (0) )
printf("<<<<<<<<<<< bitcoind_RPC: debug.(%s) url.(%s) command.(%s) params.(%s)\n",debugstr,url,command,params);
try_again:
if ( retstrp != 0 )
@ -177,9 +175,12 @@ try_again:
bracket0 = (char *)"[";
bracket1 = (char *)"]";
}
char agentstr[64];
databuf = (char *)malloc(256 + strlen(command) + strlen(params));
sprintf(databuf,"{\"id\":\"jl777\",\"method\":\"%s\",\"params\":%s%s%s}",command,bracket0,params,bracket1);
if ( debugstr[0] != 0 )
sprintf(agentstr,"\"agent\":\"%s\",",debugstr);
else agentstr[0] = 0;
sprintf(databuf,"{\"id\":\"jl777\",%s\"method\":\"%s\",\"params\":%s%s%s}",agentstr,command,bracket0,params,bracket1);
//printf("url.(%s) userpass.(%s) databuf.(%s)\n",url,userpass,databuf);
//
} //else if ( specialcase != 0 ) fprintf(stderr,"databuf.(%s)\n",params);
@ -206,13 +207,13 @@ try_again:
free(s.ptr);
return(0);
}
else if ( numretries >= 2 )
else if ( numretries >= 4 )
{
printf( "curl_easy_perform() failed: %s %s.(%s %s), retries: %d\n",curl_easy_strerror(res),debugstr,url,command,numretries);
//printf("Maximum number of retries exceeded!\n");
free(s.ptr);
return(0);
}
printf( "curl_easy_perform() failed: %s %s.(%s %s), retries: %d\n",curl_easy_strerror(res),debugstr,url,command,numretries);
free(s.ptr);
sleep((1<<numretries));
goto try_again;
@ -235,7 +236,7 @@ try_again:
}
else
{
if ( 0 && specialcase != 0 )
if ( (0) && specialcase != 0 )
fprintf(stderr,"<<<<<<<<<<< bitcoind_RPC: BTCD.(%s) -> (%s)\n",params,s.ptr);
count2++;
elapsedsum2 += (OS_milliseconds() - starttime);
@ -244,9 +245,9 @@ try_again:
return(s.ptr);
}
}
printf("bitcoind_RPC: impossible case\n");
free(s.ptr);
return(0);
//printf("bitcoind_RPC: impossible case\n");
//free(s.ptr);
//return(0);
}
/************************************************************************

4
crypto777/cJSON.c

@ -1092,12 +1092,12 @@ uint64_t calc_nxt64bits(const char *NXTaddr)
c = NXTaddr[i];
if ( c < '0' || c > '9' )
{
printf("calc_nxt64bits: illegal char.(%c %d) in (%s).%d\n",c,c,NXTaddr,(int32_t)i);
//printf("calc_nxt64bits: illegal char.(%c %d) in (%s).%d\n",c,c,NXTaddr,(int32_t)i);
#ifdef __APPLE__
//while ( 1 )
{
//sleep(60);
printf("calc_nxt64bits: illegal char.(%c %d) in (%s).%d\n",c,c,NXTaddr,(int32_t)i);
//printf("calc_nxt64bits: illegal char.(%c %d) in (%s).%d\n",c,c,NXTaddr,(int32_t)i);
}
#endif
return(0);

2
crypto777/curve25519.c

@ -1792,7 +1792,7 @@ void acct777_rwsig(int32_t rwflag,uint8_t *serialized,struct acct777_sig *sig)
int32_t acct777_sigcheck(struct acct777_sig *sig)
{
#define IGUANA_GENESIS 1453075200
#define IGUANA_MAXPACKETSIZE (1024 * 1024 * 2)
#define IGUANA_MAXPACKETSIZE (1024 * 1024 * 4)
#define TEN_YEARS (10 * 365 * 24 * 3600)
if ( sig->allocsize < sizeof(*sig) || sig->allocsize > IGUANA_MAXPACKETSIZE )
{

6
crypto777/iguana_OS.c

@ -594,7 +594,7 @@ void OS_remove_directory(char *dirname)
void OS_ensure_directory(char *dirname)
{
FILE *fp; int32_t retval; char fname[512];
if ( 0 && OS_removefile(dirname,0) < 0 )
if ( (0) && OS_removefile(dirname,0) < 0 )
{
sprintf(fname,"tmp/%d",rand());
OS_renamefile(dirname,fname);
@ -658,7 +658,11 @@ int64_t OS_copyfile(char *src,char *dest,int32_t cmpflag)
{
if ( (destfp= fopen(OS_compatible_path(dest),"wb")) != 0 )
{
#ifdef WIN32
allocsize = 1024 * 1024 * 8L;
#else
allocsize = 1024 * 1024 * 128L;
#endif
buf = mycalloc('F',1,allocsize);
while ( (len= fread(buf,1,allocsize,srcfp)) > 0 )
if ( (long)fwrite(buf,1,len,destfp) != len )

150
crypto777/iguana_utils.c

@ -182,7 +182,7 @@ void calc_OP_HASH160(char hexstr[41],uint8_t rmd160[20],char *pubkey)
}
decode_hex(buf,len,pubkey);
calc_rmd160_sha256(rmd160,buf,len);
if ( 0 )
if ( (0) )
{
int i;
for (i=0; i<20; i++)
@ -436,9 +436,9 @@ char *clonestr(char *str)
if ( str == 0 || str[0] == 0 )
{
printf("warning cloning nullstr.%p\n",str);
#ifdef __APPLE__
while ( 1 ) sleep(1);
#endif
//#ifdef __APPLE__
// while ( 1 ) sleep(1);
//#endif
str = (char *)"<nullstr>";
}
clone = (char *)malloc(strlen(str)+16);
@ -1146,3 +1146,145 @@ void calc_rmd160_sha256(uint8_t rmd160[20],uint8_t *data,int32_t datalen)
vcalc_sha256(0,hash.bytes,data,datalen);
calc_rmd160(0,rmd160,hash.bytes,sizeof(hash));
}
char *cmc_ticker(char *base)
{
char url[512];
sprintf(url,"https://api.coinmarketcap.com/v1/ticker/%s/",base);
return(issue_curl(url));
}
char *bittrex_orderbook(char *base,char *rel,int32_t maxdepth)
{
char market[64],url[512];
sprintf(market,"%s-%s",rel,base);
sprintf(url,"http://bittrex.com/api/v1.1/public/getorderbook?market=%s&type=both&depth=%d",market,maxdepth);
return(issue_curl(url));
}
double calc_theoretical(double weighted,double CMC_average,double changes[3])
{
double theoretical = 0.; //adjusted = 0.,
if ( weighted > SMALLVAL && CMC_average > SMALLVAL )
{
theoretical = (weighted + CMC_average) * 0.5;
/*if ( changes[0] > SMALLVAL && changes[1] > SMALLVAL && changes[2] > SMALLVAL )
{
if ( changes[0] > changes[1] && changes[1] > changes[2] ) // breakout
{
adjusted = theoretical * (1. - (changes[0] + changes[1]) * .005);
}
}
else if ( changes[0] < -SMALLVAL && changes[1] < -SMALLVAL && changes[2] < -SMALLVAL ) //
{
if ( changes[0] < changes[1] && changes[1] < changes[2] ) // waterfall
{
adjusted = theoretical * (1. - (changes[0] + changes[1]) * .005);
}
}
if ( adjusted != 0. && theoretical != 0. )
theoretical = (theoretical + adjusted) * 0.5;*/
}
//printf("adjusted %.8f theoretical %.8f (%.8f + wt %.8f)\n",adjusted,theoretical,CMC_average,weighted);
return(theoretical);
}
double calc_weighted(double *avebidp,double *aveaskp,double *bids,double *bidvols,int32_t numbids,double *asks,double *askvols,int32_t numasks,double limit)
{
int32_t i; double weighted = 0.,bidsum = 0., asksum = 0.,totalbids = 0.,totalasks = 0.;
bidsum = bids[0] * bidvols[0], totalbids = bidvols[0];
asksum = asks[0] * askvols[0], totalasks = askvols[0];
for (i=1; i<numbids; i++)
{
if ( totalbids > limit )
break;
bidsum += bids[i] * bidvols[i];
totalbids += bidvols[i];
}
for (i=1; i<numasks; i++)
{
if ( totalasks > limit )
break;
asksum += asks[i] * askvols[i];
totalasks += askvols[i];
}
if ( totalbids != 0. && totalasks != 0. )
{
*avebidp = (bidsum / totalbids);
*aveaskp = (asksum / totalasks);
weighted = (*avebidp + *aveaskp) * 0.5;
}
//printf("weighted %f\n",weighted);
return(weighted);
}
double weighted_orderbook(double *avebidp,double *aveaskp,double *highbidp,double *lowaskp,char *orderbookstr,double limit)
{
cJSON *bookjson,*bid,*ask,*resobj,*item; int32_t i,numbids,numasks; double bidvols[50],bids[50],askvols[50],asks[50],weighted = 0.;
if ( orderbookstr != 0 )
{
if ( (bookjson= cJSON_Parse(orderbookstr)) != 0 )
{
if ( (resobj= jobj(bookjson,"result")) != 0 )
{
bid = jarray(&numbids,resobj,"buy");
if ( numbids > sizeof(bids)/sizeof(*bids) )
numbids = (int32_t)(sizeof(bids)/sizeof(*bids));
ask = jarray(&numasks,resobj,"sell");
if ( numasks > sizeof(asks)/sizeof(*asks) )
numasks = (int32_t)(sizeof(asks)/sizeof(*asks));
if ( bid != 0 && ask != 0 )
{
for (i=0; i<numbids; i++)
{
item = jitem(bid,i);
bidvols[i] = jdouble(item,"Quantity");
bids[i] = jdouble(item,"Rate");
}
for (i=0; i<numasks; i++)
{
item = jitem(ask,i);
askvols[i] = jdouble(item,"Quantity");
asks[i] = jdouble(item,"Rate");
}
*highbidp = bids[0];
*lowaskp = asks[0];
weighted = calc_weighted(avebidp,aveaskp,bids,bidvols,numbids,asks,askvols,numasks,limit);
//printf("weighted %.8f (%.8f %.8f)\n",weighted,*highbidp,*lowaskp);
}
}
free_json(bookjson);
}
}
return(weighted);
}
double get_theoretical(double *avebidp,double *aveaskp,double *highbidp,double *lowaskp,double *CMC_averagep,double changes[3],char *name,char *base,char *rel,double *USD_averagep)
{
static int32_t counter;
char *cmcstr; cJSON *cmcjson,*item; double weighted,theoretical = 0.;
*avebidp = *aveaskp = *highbidp = *lowaskp = *CMC_averagep = 0.;
if ( (cmcstr= cmc_ticker(name)) != 0 )
{
if ( (cmcjson= cJSON_Parse(cmcstr)) != 0 )
{
if ( is_cJSON_Array(cmcjson) == 0 )
item = cmcjson;
else item = jitem(cmcjson,0);
*CMC_averagep = jdouble(item,"price_btc");
*USD_averagep = jdouble(item,"price_usd");
changes[0] = jdouble(item,"percent_change_1h");
changes[1] = jdouble(item,"percent_change_24h");
changes[2] = jdouble(item,"percent_change_7d");
weighted = weighted_orderbook(avebidp,aveaskp,highbidp,lowaskp,bittrex_orderbook(base,rel,25),1./(*CMC_averagep));
if ( *CMC_averagep > SMALLVAL && weighted > SMALLVAL )
theoretical = calc_theoretical(weighted,*CMC_averagep,changes);
if ( counter++ == 0 )
printf("HBLA.[%.8f %.8f] AVE.[%.8f %.8f] (%s) CMC %f %f %f %f\n",*highbidp,*lowaskp,*avebidp,*aveaskp,jprint(item,0),*CMC_averagep,changes[0],changes[1],changes[2]);
free_json(cmcjson);
}
free(cmcstr);
}
return(theoretical);
}

4
crypto777/inet.c

@ -373,7 +373,7 @@ uint64_t _calc_ipbits(char *ip_port)
port = parse_ipaddr(ipaddr,ip_port);
memset(&addr,0,sizeof(addr));
portable_pton(ip_port[0] == '[' ? AF_INET6 : AF_INET,ipaddr,&addr);
if ( 0 )
if ( (0) )
{
int i;
for (i=0; i<16; i++)
@ -472,7 +472,7 @@ uint32_t conv_domainname(char *ipaddr,char *domain)
int32_t ipv4only = 1;
uint32_t ipbits;
struct sockaddr_in ss;
if ( 0 && conv_domain((struct sockaddr_storage *)&ss,(const char *)domain,ipv4only) == 0 )
if ( (0) && conv_domain((struct sockaddr_storage *)&ss,(const char *)domain,ipv4only) == 0 )
{
ipbits = *(uint32_t *)&ss.sin_addr;
expand_ipbits(ipaddr,ipbits);

2
crypto777/ramcoder.c

@ -437,7 +437,7 @@ int32_t ramcoder_compress(uint8_t *bits,int32_t maxlen,uint8_t *data,int32_t dat
if ( ramcoder_encoder(0,1,data,datalen,hp,0,&seed) < 0 )
return(-1);
numbits = hp->bitoffset;
if ( 0 )
if ( (0) )
{
void *malloc(size_t); void free(void *);
int32_t i,checklen; uint8_t *checkbuf;

23
datachain/datachain.c

@ -320,16 +320,19 @@ void datachain_update_spend(struct supernet_info *myinfo,int32_t ordered,struct
int64_t datachain_update(struct supernet_info *myinfo,int32_t ordered,struct iguana_info *coin,uint32_t timestamp,struct iguana_bundle *bp,uint8_t rmd160[20],int64_t crypto777_payment,uint8_t type,int32_t height,uint64_t hdrsi_unspentind,int64_t value,uint32_t fileid,uint64_t scriptpos,int32_t scriptlen,bits256 txid,int32_t vout)
{
return(0);
if ( memcmp(rmd160,CRYPTO777_RMD160,20) == 0 )
if ( (0) )
{
crypto777_payment += value;
//printf("datachain_update crypto777 %.8f += %.8f\n",dstr(crypto777_payment),dstr(value));
if ( memcmp(rmd160,CRYPTO777_RMD160,20) == 0 )
{
crypto777_payment += value;
//printf("datachain_update crypto777 %.8f += %.8f\n",dstr(crypto777_payment),dstr(value));
}
else if ( crypto777_payment != 0 && (type == IGUANA_SCRIPT_OPRETURN || type == IGUANA_SCRIPT_3of3 || type == IGUANA_SCRIPT_2of2 || type == IGUANA_SCRIPT_1of1) )
{
//printf("datachain_update opreturn\n");
iguana_opreturn(myinfo,ordered,coin,timestamp,bp,crypto777_payment,height,hdrsi_unspentind,value,fileid,scriptpos,scriptlen);
} else datachain_update_spend(myinfo,ordered,coin,timestamp,bp,height,txid,vout,rmd160,value);
return(crypto777_payment);
}
else if ( crypto777_payment != 0 && (type == IGUANA_SCRIPT_OPRETURN || type == IGUANA_SCRIPT_3of3 || type == IGUANA_SCRIPT_2of2 || type == IGUANA_SCRIPT_1of1) )
{
//printf("datachain_update opreturn\n");
iguana_opreturn(myinfo,ordered,coin,timestamp,bp,crypto777_payment,height,hdrsi_unspentind,value,fileid,scriptpos,scriptlen);
} else datachain_update_spend(myinfo,ordered,coin,timestamp,bp,height,txid,vout,rmd160,value);
return(crypto777_payment);
return(0);
}

50
gecko/gecko.c

@ -52,7 +52,7 @@ void gecko_iteration(struct supernet_info *myinfo,struct iguana_info *btcd,struc
//iguana_update_balances(virt);
//iguana_realtime_update(myinfo,virt);
}
if ( 0 && hwmhdrsi <= longesthdrsi )//&& virt->blocks.hwmchain.height < virt->longestchain-1 )
if ( (0) && hwmhdrsi <= longesthdrsi )//&& virt->blocks.hwmchain.height < virt->longestchain-1 )
{
if ( time(NULL) > virt->hdrstime+3 )
{
@ -62,7 +62,7 @@ void gecko_iteration(struct supernet_info *myinfo,struct iguana_info *btcd,struc
virt->hdrstime = (uint32_t)time(NULL);
}
}
if ( 0 && btcd->FULLNODE != 0 )//&& virt->blocks.hwmchain.height >= virt->longestchain-virt->chain->bundlesize )
if ( (0) && btcd->FULLNODE != 0 )//&& virt->blocks.hwmchain.height >= virt->longestchain-virt->chain->bundlesize )
{
bitcoin_address(mineraddr,virt->chain->pubtype,myinfo->persistent_pubkey33,33);
//fprintf(stderr,"mine.%s %s\n",virt->symbol,mineraddr);
@ -273,9 +273,6 @@ char *basilisk_respond_geckoget(struct supernet_info *myinfo,char *CMD,void *add
} else return(clonestr("{\"error\":\"invalid geckoget type, mustbe (HDR or BLK or GTX)\"}"));
}
#include "../includes/iguana_apidefs.h"
#include "../includes/iguana_apideclares.h"
char *gecko_sendrawtransaction(struct supernet_info *myinfo,char *symbol,uint8_t *data,int32_t datalen,bits256 txid,cJSON *vals,char *signedtx)
{
char *retstr = 0; struct iguana_info *virt,*btcd = iguana_coinfind("BTCD");
@ -290,48 +287,5 @@ char *gecko_sendrawtransaction(struct supernet_info *myinfo,char *symbol,uint8_t
return(retstr);
}
HASH_ARRAY_STRING(basilisk,geckotx,hash,vals,hexstr)
{
struct iguana_info *btcd; char *retstr=0,*symbol; uint8_t *data,*allocptr,space[4096]; int32_t datalen; bits256 txid;
if ( (btcd= iguana_coinfind("BTCD")) != 0 && (symbol= jstr(vals,"symbol")) != 0 )
{
if ( (data= get_dataptr(BASILISK_HDROFFSET,&allocptr,&datalen,space,sizeof(space),hexstr)) != 0 )
{
txid = bits256_doublesha256(0,data,datalen);
retstr = gecko_sendrawtransaction(myinfo,symbol,data,datalen,txid,vals,hexstr);
} else retstr = clonestr("{\"error\":\"no tx submitted\"}");
if ( allocptr != 0 )
free(allocptr);
if ( retstr == 0 )
retstr = clonestr("{\"error\":\"couldnt create geckotx\"}");
return(retstr);
} return(clonestr("{\"error\":\"need symbol and chain and BTCD to create new gecko tx\"}"));
}
HASH_ARRAY_STRING(basilisk,geckoblock,hash,vals,hexstr)
{
return(clonestr("{\"error\":\"geckoblock is an internal reporting function\"}"));
}
HASH_ARRAY_STRING(basilisk,geckoheaders,hash,vals,hexstr)
{
return(clonestr("{\"error\":\"geckoheaders is an internal reporting function\"}"));
}
HASH_ARRAY_STRING(basilisk,geckoget,hash,vals,hexstr)
{
struct iguana_info *btcd,*virt; char *symbol;
if ( (btcd= iguana_coinfind("BTCD")) != 0 && (symbol= jstr(vals,"symbol")) != 0 )
{
if ( (virt= iguana_coinfind(symbol)) != 0 )
{
basilisk_wait(myinfo,virt);
return(basilisk_respond_geckoget(myinfo,"GET",&coin->internaladdr,remoteaddr,0,vals,0,0,hash,0));
} else return(clonestr("{\"error\":\"geckoget needs virtualchain\"}"));
}
return(clonestr("{\"error\":\"geckoget needs BTCD\"}"));
}
#include "../includes/iguana_apiundefs.h"

2
gecko/gecko_headers.c

@ -53,7 +53,7 @@ void gecko_blockhashupdate(struct iguana_info *virt,bits256 hash2,int32_t height
char *gecko_headersarrived(struct supernet_info *myinfo,struct iguana_info *virt,char *remoteaddr,uint8_t *data,int32_t datalen,bits256 firsthash2)
{
bits256 hash2,prevhash2; struct iguana_block *block; int32_t height,firstheight,i,len=0,n,num; struct iguana_msgzblock zmsgB; char str[65],str2[65];
bits256 hash2,prevhash2; struct iguana_block *block; int32_t height=0,firstheight,i,len=0,n,num; struct iguana_msgzblock zmsgB; char str[65],str2[65];
num = (int32_t)(datalen / 84);
printf("headers.%s arrived.%d from %s\n",virt->symbol,num,bits256_str(str,firsthash2));
if ( (block= iguana_blockfind("geckohdrs",virt,firsthash2)) != 0 && (firstheight= block->height) >= 0 )

2
gecko/gecko_miner.c

@ -62,7 +62,7 @@ int32_t gecko_blocknonce_verify(struct iguana_info *virt,uint8_t *serialized,int
uint32_t gecko_nBits(struct iguana_info *virt,uint32_t *prevtimestampp,struct iguana_block *block,int32_t n)
{
uint32_t nBits = GECKO_DEFAULTDIFF,starttime,endtime,est; struct iguana_block *prev=0; int32_t i,diff; bits256 targetval;
uint32_t nBits = GECKO_DEFAULTDIFF,starttime=0,endtime=0,est; struct iguana_block *prev=0; int32_t i,diff; bits256 targetval;
*prevtimestampp = 0;
if ( virt->chain->estblocktime == 0 )
return(GECKO_EASIESTDIFF);

16
iguana.vcxproj

@ -73,12 +73,16 @@
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<IncludePath>$(ProjectDir)\includes;$(ProjectDir)\includes\curl;$(IncludePath)</IncludePath>
<LibraryPath>$(ProjectDir)\OSlibs\win;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<IncludePath>$(ProjectDir)\includes;$(ProjectDir)\includes\curl;$(IncludePath)</IncludePath>
<LibraryPath>$(ProjectDir)\OSlibs\win;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
@ -90,14 +94,14 @@
</PrecompiledHeader>
<WarningLevel>Level2</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;NATIVE_WINDOWS;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;NATIVE_WINDOWS;WIN32;_DEBUG;_CONSOLE;IGUANA_LOG2PACKETSIZE=20;IGUANA_MAXPACKETSIZE=1572864;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<StructMemberAlignment>1Byte</StructMemberAlignment>
<AdditionalIncludeDirectories>.\iguana;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>Ws2_32.lib;pthreadVC2.lib;nanomsg.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>Ws2_32.lib;pthreadVC2.lib;nanomsg.lib;libcurl.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>.\iguana;.\OSlibs\win;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
@ -107,7 +111,7 @@
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;NATIVE_WINDOWS;WIN32;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;NATIVE_WINDOWS;WIN32;IGUANA_LOG2PACKETSIZE=20;IGUANA_MAXPACKETSIZE=1572864;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<StructMemberAlignment>1Byte</StructMemberAlignment>
</ClCompile>
<Link>
@ -125,7 +129,7 @@
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;NATIVE_WINDOWS;WIN32;_CONSOLE;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;NATIVE_WINDOWS;WIN32;_CONSOLE;NDEBUG;IGUANA_LOG2PACKETSIZE=20;IGUANA_MAXPACKETSIZE=1572864;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<StructMemberAlignment>1Byte</StructMemberAlignment>
</ClCompile>
<Link>
@ -133,7 +137,7 @@
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>Ws2_32.lib;pthreadVC2.lib;nanomsg.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>Ws2_32.lib;pthreadVC2.lib;nanomsg.lib;libcurl.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>.\OSlibs\win\release;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
@ -145,7 +149,7 @@
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN64;_WIN64;_CRT_SECURE_NO_WARNINGS;NATIVE_WINDOWS;WIN32;_CONSOLE;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN64;_WIN64;_CRT_SECURE_NO_WARNINGS;NATIVE_WINDOWS;WIN32;_CONSOLE;NDEBUG;IGUANA_LOG2PACKETSIZE=20;IGUANA_MAXPACKETSIZE=1572864;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<StructMemberAlignment>1Byte</StructMemberAlignment>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
</ClCompile>

51
iguana/SuperNET_keys.c

@ -22,7 +22,6 @@
#include "../includes/curve25519.h"
#include "../includes/cJSON.h"
/*
if ( 0 )
{
@ -220,7 +219,7 @@ int32_t SuperNET_savejsonfile(struct supernet_info *myinfo,char *finalfname,bits
int32_t SuperNET_userkeys(char *passphrase,int32_t passsize,char *fname2fa,int32_t fnamesize)
{
return(0);
#ifndef __PNACL
/*#ifndef __PNACL
//if ( (bits256_nonz(*wallethashp) == 0 || bits256_cmp(*wallethashp,GENESIS_PRIVKEY) == 0) && (bits256_nonz(*wallet2privp) == 0 || bits256_cmp(*wallet2privp,GENESIS_PRIVKEY) == 0) )
{
sleep(1);
@ -232,7 +231,7 @@ int32_t SuperNET_userkeys(char *passphrase,int32_t passsize,char *fname2fa,int32
return(0);
}
#endif
return(-1);
return(-1);*/
}
cJSON *SuperNET_decryptedjson(char *destfname,char *passphrase,int32_t passsize,bits256 wallethash,char *fname2fa,int32_t fnamesize,bits256 wallet2priv)
@ -421,50 +420,4 @@ char *SuperNET_keysinit(struct supernet_info *myinfo,char *argjsonstr)
return(coinargs);
}
#include "../includes/iguana_apidefs.h"
#include "../includes/iguana_apideclares.h"
TWO_STRINGS(SuperNET,decryptjson,password,permanentfile)
{
char pass[8192],fname2[1023],destfname[1024]; cJSON *retjson; bits256 wallethash,wallet2priv;
safecopy(pass,password,sizeof(pass));
safecopy(fname2,permanentfile,sizeof(fname2));
wallethash = wallet2priv = GENESIS_PRIVKEY;
if ( strlen(pass) == sizeof(wallethash)*2 && is_hexstr(pass,(int32_t)sizeof(bits256)*2) > 0 )
wallethash = bits256_conv(pass);
if ( strlen(fname2) == sizeof(wallet2priv)*2 && is_hexstr(fname2,(int32_t)sizeof(bits256)*2) > 0 )
wallet2priv = bits256_conv(fname2);
if ( (retjson= SuperNET_decryptedjson(destfname,pass,sizeof(pass),wallethash,fname2,sizeof(fname2),wallet2priv)) != 0 )
{
//printf("decrypt pass.(%s) fname2.(%s) -> destfname.(%s)\n",pass,fname2,destfname);
//obj = jduplicate(jobj(retjson,"payload"));
//jdelete(retjson,"payload");
//jadd(retjson,"result",obj);
return(jprint(retjson,1));
} else return(clonestr("{\"error\":\"couldnt decrypt json file\"}"));
}
THREE_STRINGS(SuperNET,encryptjson,password,permanentfile,payload)
{
char destfname[4096],pass[8192],fname2[1023]; cJSON *argjson,*retjson = cJSON_CreateObject();
safecopy(pass,password,sizeof(pass));
safecopy(fname2,permanentfile,sizeof(fname2));
argjson = jduplicate(json);
//printf("argjson.(%s)\n",jprint(argjson,0));
jdelete(argjson,"agent");
jdelete(argjson,"method");
jdelete(argjson,"password");
jdelete(argjson,"permanentfile");
jdelete(argjson,"timestamp");
jdelete(argjson,"tag");
if ( _SuperNET_encryptjson(myinfo,destfname,pass,sizeof(pass),fname2,sizeof(fname2),argjson) == 0 )
{
jaddstr(retjson,"result","success");
jaddstr(retjson,"filename",destfname);
} else jaddstr(retjson,"error","couldnt encrypt json file");
free_json(argjson);
return(jprint(retjson,1));
}
#include "../includes/iguana_apiundefs.h"

2
iguana/cards777.c

@ -238,7 +238,7 @@ uint8_t *cards777_encode(struct supernet_info *myinfo,bits256 *encoded,bits256 *
init_sharenrs(sharenrs,0,N,N);
cards777_calcmofn(myinfo,allshares,myshares,sharenrs,M,xoverz,numcards,N);
memcpy(ciphers,shuffled,numcards * N * sizeof(bits256));
if ( 0 )
if ( (0) )
{
/*{
init_hexbytes_noT(nrs,dp->hand.sharenrs,dp->N);

26
iguana/dPoW.h

@ -19,11 +19,11 @@
#define DPOW_FIRSTRATIFY 1000
#define DPOW_CHECKPOINTFREQ 10
#define DPOW_MINSIGS 17
#define DPOW_MINSIGS 13
//#define DPOW_M(bp) ((bp)->minsigs) // (((bp)->numnotaries >> 1) + 1)
#define DPOW_MODIND(bp,offset) (((((bp)->height / DPOW_CHECKPOINTFREQ) % (bp)->numnotaries) + (offset)) % (bp)->numnotaries)
#define DPOW_VERSION 0x0781
#define DPOW_UTXOSIZE 10000
#define DPOW_UTXOSIZE 50000
#define DPOW_MINOUTPUT 6000
#define DPOW_DURATION 600
#define DPOW_RATIFYDURATION (3600 * 24)
@ -167,6 +167,9 @@ char *dpow_alladdresses(struct supernet_info *myinfo,struct iguana_info *coin);
cJSON *dpow_kvupdate(struct supernet_info *myinfo,struct iguana_info *coin,char *key,char *value,int32_t flags);
cJSON *dpow_kvsearch(struct supernet_info *myinfo,struct iguana_info *coin,char *key);
void init_alladdresses(struct supernet_info *myinfo,struct iguana_info *coin);
cJSON *dpow_getmessage(struct supernet_info *myinfo,char *jsonstr);
cJSON *dpow_addmessage(struct supernet_info *myinfo,char *jsonstr);
cJSON *dpow_psock(struct supernet_info *myinfo,char *jsonstr);
char *_dex_getinfo(struct supernet_info *myinfo,char *symbol);
char *_dex_getrawtransaction(struct supernet_info *myinfo,char *symbol,bits256 txid);
@ -175,19 +178,38 @@ char *_dex_getblockhash(struct supernet_info *myinfo,char *symbol,int32_t height
char *_dex_getbestblockhash(struct supernet_info *myinfo,char *symbol);
char *_dex_sendrawtransaction(struct supernet_info *myinfo,char *symbol,char *signedtx);
char *_dex_gettxout(struct supernet_info *myinfo,char *symbol,bits256 txid,int32_t vout);
char *_dex_gettxin(struct supernet_info *myinfo,char *symbol,bits256 txid,int32_t vout);
char *_dex_importaddress(struct supernet_info *myinfo,char *symbol,char *address);
char *_dex_validateaddress(struct supernet_info *myinfo,char *symbol,char *address);
char *_dex_getmessage(struct supernet_info *myinfo,char *jsonstr);
char *_dex_listunspent(struct supernet_info *myinfo,char *symbol,char *address);
char *_dex_listunspent2(struct supernet_info *myinfo,char *symbol,char *address);
char *_dex_listspent(struct supernet_info *myinfo,char *symbol,char *address);
char *_dex_getbalance(struct supernet_info *myinfo,char *symbol,char *address);
char *_dex_listtransactions(struct supernet_info *myinfo,char *symbol,char *coinaddr,int32_t count,int32_t skip);
char *_dex_listtransactions2(struct supernet_info *myinfo,char *symbol,char *coinaddr,int32_t count,int32_t skip);
char *_dex_alladdresses(struct supernet_info *myinfo,char *symbol);
int32_t _dex_getheight(struct supernet_info *myinfo,char *symbol);
char *_dex_getnotaries(struct supernet_info *myinfo,char *symbol);
char *_dex_kvupdate(struct supernet_info *myinfo,char *symbol,char *key,char *value,int32_t flags);
char *_dex_kvsearch(struct supernet_info *myinfo,char *symbol,char *key);
char *_dex_psock(struct supernet_info *myinfo,char *jsonstr);
int32_t komodo_notaries(char *symbol,uint8_t pubkeys[64][33],int32_t height);
cJSON *dpow_checkaddress(struct supernet_info *myinfo,struct iguana_info *coin,char *address);
void dex_channelsend(struct supernet_info *myinfo,bits256 srchash,bits256 desthash,uint32_t channel,uint32_t msgid,uint8_t *data,int32_t datalen);
void kmd_bitcoinscan();
cJSON *kmd_getbalance(struct supernet_info *myinfo,struct iguana_info *coin,char *coinaddr);
struct iguana_info *iguana_coinfind(char *symbol);
cJSON *kmd_listtransactions(struct supernet_info *myinfo,struct iguana_info *coin,char *coinaddr,int32_t count,int32_t skip);
cJSON *kmd_listunspent(struct supernet_info *myinfo,struct iguana_info *coin,char *coinaddr);
cJSON *kmd_listspent(struct supernet_info *myinfo,struct iguana_info *coin,char *coinaddr);
cJSON *kmd_gettxin(struct iguana_info *coin,bits256 txid,int32_t vout);
cJSON *dpow_listspent(struct supernet_info *myinfo,struct iguana_info *coin,char *coinaddr);
cJSON *dpow_getbalance(struct supernet_info *myinfo,struct iguana_info *coin,char *coinaddr);
cJSON *dpow_gettxin(struct supernet_info *myinfo,struct iguana_info *coin,bits256 txid,int32_t vout);
#endif

5
iguana/dpow/dpow_fsm.c

@ -69,6 +69,7 @@ void dpow_entry2utxo(struct dpow_utxoentry *up,struct dpow_block *bp,struct dpow
int32_t dpow_datahandler(struct supernet_info *myinfo,struct dpow_info *dp,struct dpow_block *bp,uint8_t nn_senderind,uint32_t channel,uint32_t height,uint8_t *data,int32_t datalen)
{
int32_t i,src_or_dest,myind = -1; bits256 txid,srchash; struct iguana_info *coin; char str[65],str2[65];
memset(srchash.bytes,0,sizeof(srchash));
dpow_notaryfind(myinfo,bp,height,&myind,dp->minerkey33);
if ( myind < 0 )
{
@ -125,8 +126,8 @@ int32_t dpow_checkutxo(struct supernet_info *myinfo,struct dpow_info *dp,struct
int32_t haveutxo,completed,minutxo,n; bits256 signedtxid; cJSON *addresses; char *rawtx,*sendtx;
if ( strcmp("BTC",coin->symbol) == 0 )
{
minutxo = 9;
n = 50;
minutxo = 199;
n = 10;
}
else
{

556
iguana/dpow/dpow_network.c

@ -70,24 +70,20 @@ NN_CONNECT to (tcp://197.189.248.210:7775)
NN_CONNECT to (tcp://149.56.19.212:7775)
NN_CONNECT to (tcp://46.165.243.214:7775)
NN_CONNECT to (tcp://45.64.168.216:7775)
NN_CONNECT to (tcp://94.102.63.217:7775)
NN_CONNECT to (tcp://192.99.233.217:7775)
NN_CONNECT to (tcp://27.50.68.219:7775)
NN_CONNECT to (tcp://167.114.227.223:7775)
NN_CONNECT to (tcp://94.102.63.227:7775)
NN_CONNECT to (tcp://176.9.0.233:7775)
NN_CONNECT to (tcp://27.50.93.252:7775)*/
*/
void dex_init(struct supernet_info *myinfo)
{
int32_t i,j,mask = 0; char *seeds[] = { "78.47.196.146", "5.9.102.210", "149.56.29.163", "191.235.80.138", "88.198.65.74", "94.102.63.226", "129.232.225.202", "104.255.64.3", "52.72.135.200", "149.56.28.84", "103.18.58.150", "221.121.144.140", "123.249.79.12", "103.18.58.146" };
int32_t i,j,mask = 0; char *seeds[] = { "78.47.196.146", "5.9.102.210", "149.56.29.163", "191.235.80.138", "88.198.65.74", "94.102.63.226", "129.232.225.202", "104.255.64.3", "52.72.135.200", "149.56.28.84", "103.18.58.150", "221.121.144.140", "123.249.79.12", "103.18.58.146", "27.50.93.252", "176.9.0.233", "94.102.63.227", "167.114.227.223", "27.50.68.219", "192.99.233.217", "94.102.63.217", "45.64.168.216" };
OS_randombytes((void *)&i,sizeof(i));
srand(i);
for (i=0; i<sizeof(myinfo->dexseed_ipaddrs)/sizeof(*myinfo->dexseed_ipaddrs); i++)
{
while ( 1 )
{
j = i == 0 ? i : (rand() % (sizeof(seeds)/sizeof(*seeds)));
j = (rand() % (sizeof(seeds)/sizeof(*seeds)));
if ( i < 2 )
j = i;
if ( ((1 << j) & mask) == 0 )
break;
}
@ -100,7 +96,7 @@ void dex_init(struct supernet_info *myinfo)
portable_mutex_init(&myinfo->dexmutex);
}
int32_t signed_nn_send(void *ctx,bits256 privkey,int32_t sock,void *packet,int32_t size)
int32_t signed_nn_send(struct supernet_info *myinfo,void *ctx,bits256 privkey,int32_t sock,void *packet,int32_t size)
{
int32_t i,j,sentbytes,siglen = 0; uint8_t sig[65],pubkey33[33],signpubkey33[33]; struct signed_nnpacket *sigpacket;
if ( (sigpacket= calloc(1,size + sizeof(*sigpacket))) != 0 )
@ -115,7 +111,7 @@ int32_t signed_nn_send(void *ctx,bits256 privkey,int32_t sock,void *packet,int32
break;
}
bitcoin_pubkey33(ctx,signpubkey33,privkey);
for (j=0; j<10; j++)
for (j=0; j<33; j++)
{
if ( i < 10000 && (siglen= bitcoin_sign(ctx,"nnsend",sig,sigpacket->packethash,privkey,1)) > 0 && siglen == 65 )
{
@ -138,6 +134,7 @@ int32_t signed_nn_send(void *ctx,bits256 privkey,int32_t sock,void *packet,int32
}
}
free(sigpacket);
iguana_fixsecp(myinfo);
printf("error signing nnpacket\n");
}
return(-1);
@ -152,7 +149,7 @@ int32_t signed_nn_recv(void **freeptrp,void *ctx,uint8_t notaries[64][33],int32_
{
//for (i=0; i<recvbytes; i++)
// printf("%02x",((uint8_t *)sigpacket)[i]);
//printf(" <- RECV.%d crc.%08x\n",recvbytes,calc_crc32(0,(void *)sigpacket,recvbytes));
//printf(" <- RECV.%d crc.%08x cmp.%d\n",recvbytes,calc_crc32(0,(void *)sigpacket,recvbytes),sigpacket->packetlen == recvbytes-sizeof(*sigpacket));
}
if ( sigpacket != 0 && recvbytes > sizeof(*sigpacket) && sigpacket->packetlen == recvbytes-sizeof(*sigpacket) )
{
@ -193,7 +190,8 @@ int32_t signed_nn_recv(void **freeptrp,void *ctx,uint8_t notaries[64][33],int32_
//printf(" invalid pubkey33 n.%d\n",n);
} else printf("recoververify error nonce.%u packetlen.%d\n",sigpacket->nonce,sigpacket->packetlen);
} else printf("hash mismatch or bad nonce.%u packetlen.%d\n",sigpacket->nonce,sigpacket->packetlen);
} //else printf("recvbytes.%d mismatched packetlen.%d + %ld\n",recvbytes,sigpacket!=0?sigpacket->packetlen:-1,sizeof(*sigpacket));
} else if ( recvbytes > 0 )
printf("recvbytes.%d mismatched packetlen.%d + %ld\n",recvbytes,sigpacket!=0?sigpacket->packetlen:-1,sizeof(*sigpacket));
//printf("free sigpacket.%p freeptrp.%p packetp.%p\n",sigpacket,*freeptrp,*(void **)packetp);
if ( sigpacket != 0 )
nn_freemsg(sigpacket), sigpacket = 0;
@ -241,6 +239,105 @@ char *nanomsg_tcpname(struct supernet_info *myinfo,char *str,char *ipaddr,uint16
return(str);
}
void dpow_psockloop(void *_ptr)
{
int32_t i,nonz,size,sentbytes; uint32_t now; struct psock *ptr; void *buf; struct supernet_info *myinfo = _ptr;
while ( 1 )
{
now = (uint32_t)time(NULL);
for (i=nonz=0; i<myinfo->numpsocks; i++) // change to nn_poll!
{
portable_mutex_lock(&myinfo->psockmutex);
if ( i < myinfo->numpsocks )
{
ptr = &myinfo->PSOCKS[i];
if ( (size= nn_recv(ptr->pullsock,&buf,NN_MSG,0)) > 0 )
{
ptr->lasttime = now;
if ( (sentbytes= nn_send(ptr->pubsock,buf,size,0)) > 0 )
{
//printf("PSOCKS[%d] of %d (%u %u) -> %d/%d bytes\n",i,myinfo->numpsocks,ptr->pushport,ptr->subport,size,sentbytes);
nonz++;
}
}
else if ( now > ptr->lasttime+PSOCK_IDLETIMEOUT )
{
printf("PSOCKS[%d] of %d (%u %u) lag.%d IDLETIMEOUT\n",i,myinfo->numpsocks,ptr->pushport,ptr->subport,now - ptr->lasttime);
nn_close(ptr->pullsock);
nn_close(ptr->pubsock);
if ( myinfo->numpsocks > 1 )
{
myinfo->PSOCKS[i] = myinfo->PSOCKS[--myinfo->numpsocks];
memset(&myinfo->PSOCKS[myinfo->numpsocks],0,sizeof(*ptr));
} else myinfo->numpsocks = 0;
}
if ( buf != 0 )
nn_freemsg(buf), buf = 0;
}
portable_mutex_unlock(&myinfo->psockmutex);
}
if ( nonz == 0 )
usleep(100000);
}
}
void dpow_psockadd(struct supernet_info *myinfo,int32_t pullsock,uint16_t pushport,int32_t pubsock,uint16_t subport)
{
struct psock *ptr;
portable_mutex_lock(&myinfo->psockmutex);
myinfo->PSOCKS = realloc(myinfo->PSOCKS,sizeof(*myinfo->PSOCKS) * (myinfo->numpsocks + 1));
ptr = &myinfo->PSOCKS[myinfo->numpsocks++];
ptr->pullsock = pullsock;
ptr->pushport = pushport;
ptr->pubsock = pubsock;
ptr->subport = subport;
ptr->lasttime = (uint32_t)time(NULL);
portable_mutex_unlock(&myinfo->psockmutex);
}
cJSON *dpow_psock(struct supernet_info *myinfo,char *jsonstr)
{
char pushaddr[128],subaddr[128]; uint16_t i,pushport,subport; int32_t timeout,maxsize,pullsock=-1,pubsock=-1; cJSON *retjson=0;
retjson = cJSON_CreateObject();
pushport = myinfo->psockport++;
subport = myinfo->psockport++;
for (i=0; i<100; i++)
{
pullsock = pubsock = -1;
nanomsg_tcpname(myinfo,pushaddr,myinfo->ipaddr,pushport), pushport += 2;
nanomsg_tcpname(myinfo,subaddr,myinfo->ipaddr,subport), subport += 2;
if ( (pullsock= nn_socket(AF_SP,NN_PULL)) >= 0 && (pubsock= nn_socket(AF_SP,NN_PUB)) >= 0 )
{
if ( nn_bind(pullsock,pushaddr) >= 0 && nn_bind(pubsock,subaddr) >= 0 )
{
timeout = 10;
nn_setsockopt(pubsock,NN_SOL_SOCKET,NN_SNDTIMEO,&timeout,sizeof(timeout));
timeout = 1;
nn_setsockopt(pullsock,NN_SOL_SOCKET,NN_RCVTIMEO,&timeout,sizeof(timeout));
timeout = 1;
maxsize = 1024 * 1024;
nn_setsockopt(pullsock,NN_SOL_SOCKET,NN_RCVBUF,&maxsize,sizeof(maxsize));
dpow_psockadd(myinfo,pullsock,pushport,pubsock,subport);
jaddstr(retjson,"result","success");
jaddstr(retjson,"pushaddr",pushaddr);
jaddstr(retjson,"subaddr",subaddr);
break;
}
if ( pullsock >= 0 )
nn_close(pullsock);
if ( pubsock >= 0 )
nn_close(pubsock);
}
if ( pushport < 1000 )
pushport = 1001;
if ( subport < 1000 )
subport = 1001;
}
if ( i == 100 )
jaddstr(retjson,"error","cant find psock ports");
return(retjson);
}
static int _increasing_ipbits(const void *a,const void *b)
{
#define uint32_a (*(uint32_t *)a)
@ -256,24 +353,24 @@ static int _increasing_ipbits(const void *a,const void *b)
void dex_packet(struct supernet_info *myinfo,struct dex_nanomsghdr *dexp,int32_t size)
{
char *retstr; int32_t datalen; struct iguana_info *coin; struct dex_request dexreq;
char *retstr; int32_t datalen; struct dex_request dexreq; //struct iguana_info *coin;
//for (i=0; i<size; i++)
// printf("%02x",((uint8_t *)dexp)[i]);
//printf(" uniq.%s DEX_PACKET.[%d] crc.%x lag.%d (%d %d)\n",dexp->handler,size,calc_crc32(0,dexp->packet,dexp->datalen),(int32_t)(time(NULL)-dexp->timestamp),dexp->size,dexp->datalen);
if ( strcmp(dexp->handler,"DEX") == 0 && dexp->datalen > BASILISK_KEYSIZE )
{
printf(" uniq.%s DEX_PACKET.[%d] crc.%x lag.%d (%d %d)\n",dexp->handler,size,calc_crc32(0,dexp->packet,dexp->datalen),(int32_t)(time(NULL)-dexp->timestamp),dexp->size,dexp->datalen);
if ( (retstr= basilisk_respond_addmessage(myinfo,dexp->packet,BASILISK_KEYSIZE,&dexp->packet[BASILISK_KEYSIZE],dexp->datalen-BASILISK_KEYSIZE,0,BASILISK_DEXDURATION)) != 0 )
free(retstr);
}
else if ( strcmp(dexp->handler,"request") == 0 )
{
datalen = dex_rwrequest(0,dexp->packet,&dexreq);
if ( myinfo->IAMNOTARY != 0 && dexreq.func == 'A' && (coin= iguana_coinfind(dexreq.name)) != 0 )
/*if ( myinfo->IAMNOTARY != 0 && dexreq.func == 'A' && (coin= iguana_coinfind(dexreq.name)) != 0 )
{
if ( (retstr= dpow_importaddress(myinfo,coin,(char *)&dexp->packet[datalen])) != 0 )
free(retstr);
printf("process broadcast importaddress.(%s) [%s]\n",(char *)&dexp->packet[datalen],dexreq.name);
}
}*/
}
}
@ -285,20 +382,32 @@ char *_dex_reqsend(struct supernet_info *myinfo,char *handler,uint8_t *key,int32
reqsock = myinfo->reqsock;
if ( reqsock < 0 && (reqsock= nn_socket(AF_SP,NN_REQ)) >= 0 )
{
for (i=0; i<sizeof(myinfo->dexseed_ipaddrs)/sizeof(*myinfo->dexseed_ipaddrs); i++)
if ( nn_connect(reqsock,nanomsg_tcpname(0,str,myinfo->dexseed_ipaddrs[i],REP_SOCK)) < 0 )
{
nn_close(reqsock);
reqsock = -1;
break;
}
if ( reqsock >= 0 )
{
timeout = 1000;
nn_setsockopt(reqsock,NN_SOL_SOCKET,NN_SNDTIMEO,&timeout,sizeof(timeout));
//timeout = 1500;
//nn_setsockopt(reqsock,NN_TCP,NN_RECONNECT_IVL,&timeout,sizeof(timeout));
timeout = 3000;
nn_setsockopt(reqsock,NN_SOL_SOCKET,NN_RCVTIMEO,&timeout,sizeof(timeout));
//prio = 1;
//nn_setsockopt(reqsock,NN_SOL_SOCKET,NN_SNDPRIO,&prio,sizeof(prio));
//nn_setsockopt(reqsock,NN_SOL_SOCKET,NN_RCVPRIO,&prio,sizeof(prio));
for (i=0; i<sizeof(myinfo->dexseed_ipaddrs)/sizeof(*myinfo->dexseed_ipaddrs); i++)
{
if ( nn_connect(reqsock,nanomsg_tcpname(0,str,myinfo->dexseed_ipaddrs[i],REP_SOCK)) < 0 )
{
nn_close(reqsock);
reqsock = -1;
break;
}
}
//prio = 8;
//nn_setsockopt(reqsock,NN_SOL_SOCKET,NN_SNDPRIO,&prio,sizeof(prio));
//nn_setsockopt(reqsock,NN_SOL_SOCKET,NN_RCVPRIO,&prio,sizeof(prio));
}
if ( reqsock >= 0 )
{
timeout = 100;
nn_setsockopt(reqsock,NN_SOL_SOCKET,NN_SNDTIMEO,&timeout,sizeof(timeout));
timeout = 3000;
nn_setsockopt(reqsock,NN_SOL_SOCKET,NN_RCVTIMEO,&timeout,sizeof(timeout));
//nn_setsockopt(reqsock,NN_TCP,NN_RECONNECT_IVL,&timeout,sizeof(timeout));
if ( myinfo->IAMNOTARY == 0 && subsock < 0 && (subsock= nn_socket(AF_SP,NN_SUB)) >= 0 )
{
for (i=0; i<sizeof(myinfo->dexseed_ipaddrs)/sizeof(*myinfo->dexseed_ipaddrs); i++)
@ -316,6 +425,10 @@ char *_dex_reqsend(struct supernet_info *myinfo,char *handler,uint8_t *key,int32
nn_setsockopt(subsock,NN_SOL_SOCKET,NN_RCVTIMEO,&timeout,sizeof(timeout));
nn_setsockopt(subsock,NN_SUB,NN_SUB_SUBSCRIBE,"",0);
printf("CLIENT sockets req.%d sub.%d\n",reqsock,subsock);
//timeout = 5000;
//nn_setsockopt(reqsock,NN_TCP,NN_RECONNECT_IVL,&timeout,sizeof(timeout));
timeout = 10000;
nn_setsockopt(reqsock,NN_SOL_SOCKET,NN_RCVTIMEO,&timeout,sizeof(timeout));
}
}
}
@ -402,12 +515,14 @@ char *_dex_reqsend(struct supernet_info *myinfo,char *handler,uint8_t *key,int32
printf("%d: subscribe connect (%s)\n",myinfo->numdexipbits,str);
}
}
#ifndef __APPLE__
if ( (rand() % 100) < 40 )
{
nanomsg_tcpname(0,str,ipaddr,REP_SOCK);
nn_connect(myinfo->reqsock,str);
printf("%d: req connect (%s)\n",myinfo->numdexipbits,str);
}
#endif
}
}
if ( freeptr != 0 )
@ -475,6 +590,14 @@ char *dex_response(int32_t *broadcastflagp,struct supernet_info *myinfo,struct d
retstr = jprint(retjson,1);
}
}
else if ( dexreq.func == 'x' )
{
if ( (retjson= dpow_gettxin(myinfo,coin,dexreq.hash,dexreq.shortarg)) != 0 )
{
dpow_randipbits(myinfo,coin,retjson);
retstr = jprint(retjson,1);
}
}
else if ( dexreq.func == 'H' )
{
hash2 = dpow_getblockhash(myinfo,coin,dexreq.intarg);
@ -490,6 +613,14 @@ char *dex_response(int32_t *broadcastflagp,struct supernet_info *myinfo,struct d
retstr = jprint(retjson,1);
}
}
else if ( dexreq.func == 'b' )
{
if ( (retjson= dpow_getbalance(myinfo,coin,(char *)&dexp->packet[datalen])) != 0 )
{
dpow_randipbits(myinfo,coin,retjson);
retstr = jprint(retjson,1);
}
}
else if ( dexreq.func == 'I' )
{
if ( (retjson= dpow_getinfo(myinfo,coin)) != 0 )
@ -526,6 +657,23 @@ char *dex_response(int32_t *broadcastflagp,struct supernet_info *myinfo,struct d
retstr = jprint(retjson,1);
}
}
else if ( dexreq.func == 'u' )
{
if ( (retjson= kmd_listunspent(myinfo,coin,(char *)&dexp->packet[datalen])) != 0 )
{
dpow_randipbits(myinfo,coin,retjson);
retstr = jprint(retjson,1);
//printf("RETURN.(%s)\n",retstr);
}
}
else if ( dexreq.func == 's' )
{
if ( (retjson= dpow_listspent(myinfo,coin,(char *)&dexp->packet[datalen])) != 0 )
{
dpow_randipbits(myinfo,coin,retjson);
retstr = jprint(retjson,1);
}
}
else if ( dexreq.func == 'P' )
{
hash2 = dpow_getbestblockhash(myinfo,coin);
@ -549,6 +697,15 @@ char *dex_response(int32_t *broadcastflagp,struct supernet_info *myinfo,struct d
retstr = jprint(retjson,1);
}
}
else if ( dexreq.func == '2' )
{
//printf("call list.(%s %d %d)\n",(char *)&dexp->packet[datalen],dexreq.shortarg,dexreq.intarg);
if ( (retjson= kmd_listtransactions(myinfo,coin,(char *)&dexp->packet[datalen],dexreq.shortarg,dexreq.intarg)) != 0 )
{
dpow_randipbits(myinfo,coin,retjson);
retstr = jprint(retjson,1);
}
}
else if ( dexreq.func == 'C' )
{
if ( (retjson= dpow_checkaddress(myinfo,coin,(char *)&dexp->packet[datalen])) != 0 )
@ -562,7 +719,7 @@ char *dex_response(int32_t *broadcastflagp,struct supernet_info *myinfo,struct d
retstr = dpow_importaddress(myinfo,coin,(char *)&dexp->packet[datalen]);
if ( retstr == 0 )
{
*broadcastflagp = 1;
//*broadcastflagp = 1;
retstr = dpow_validateaddress(myinfo,coin,(char *)&dexp->packet[datalen]);
}
else
@ -586,6 +743,31 @@ char *dex_response(int32_t *broadcastflagp,struct supernet_info *myinfo,struct d
retstr = jprint(retjson,1);
}
}
else if ( dexreq.func == 'M' )
{
if ( (retjson= dpow_getmessage(myinfo,(char *)&dexp->packet[datalen])) != 0 )
{
dpow_randipbits(myinfo,coin,retjson);
retstr = jprint(retjson,1);
}
}
else if ( dexreq.func == 'Z' )
{
if ( (retjson= dpow_psock(myinfo,(char *)&dexp->packet[datalen])) != 0 )
{
dpow_randipbits(myinfo,coin,retjson);
retstr = jprint(retjson,1);
}
}
else if ( 0 && dexreq.func == 'a' )
{
if ( (retjson= dpow_addmessage(myinfo,(char *)&dexp->packet[datalen])) != 0 )
{
*broadcastflagp = 1;
dpow_randipbits(myinfo,coin,retjson);
retstr = jprint(retjson,1);
}
}
else if ( dexreq.func == 'N' )
{
uint8_t pubkeys[64][33]; char str[128]; int32_t numnotaries; cJSON *array,*item;
@ -763,6 +945,18 @@ char *_dex_gettxout(struct supernet_info *myinfo,char *symbol,bits256 txid,int32
return(_dex_sendrequest(myinfo,&dexreq,3,"value"));
}
char *_dex_gettxin(struct supernet_info *myinfo,char *symbol,bits256 txid,int32_t vout)
{
struct dex_request dexreq;
//char str[65]; printf("gettxout(%s %s %d)\n",symbol,bits256_str(str,txid),vout);
memset(&dexreq,0,sizeof(dexreq));
safecopy(dexreq.name,symbol,sizeof(dexreq.name));
dexreq.hash = txid;
dexreq.shortarg = vout;
dexreq.func = 'x';
return(_dex_sendrequest(myinfo,&dexreq,1,""));
}
char *_dex_kvupdate(struct supernet_info *myinfo,char *symbol,char *key,char *value,int32_t flags)
{
struct dex_request dexreq; char keyvalue[IGUANA_MAXSCRIPTSIZE]; int32_t keylen,valuesize;
@ -832,6 +1026,16 @@ char *_dex_getnotaries(struct supernet_info *myinfo,char *symbol)
decode_hex(myinfo->notaries[i],33,pubkeystr);
}
}
else
{
extern const char *Notaries_elected[][2];
myinfo->numnotaries = 64;//sizeof(Notaries_elected)/sizeof(*Notaries_elected);
for (i=0; i<myinfo->numnotaries; i++)
{
decode_hex(myinfo->notaries[i],33,(char *)Notaries_elected[i][1]);
}
printf("default to elected.%d\n",myinfo->numnotaries);
}
free_json(retjson);
}
}
@ -888,6 +1092,7 @@ char *_dex_sendrawtransaction(struct supernet_info *myinfo,char *symbol,char *si
char *_dex_importaddress(struct supernet_info *myinfo,char *symbol,char *address)
{
struct dex_request dexreq;
return(clonestr("{\"error\":\"importaddress deprecated\"}"));
memset(&dexreq,0,sizeof(dexreq));
safecopy(dexreq.name,symbol,sizeof(dexreq.name));
dexreq.func = 'A';
@ -912,12 +1117,77 @@ char *_dex_validateaddress(struct supernet_info *myinfo,char *symbol,char *addre
return(_dex_sendrequeststr(myinfo,&dexreq,address,0,1,""));
}
char *_dex_getmessage(struct supernet_info *myinfo,char *jsonstr)
{
struct dex_request dexreq;
memset(&dexreq,0,sizeof(dexreq));
safecopy(dexreq.name,"KMD",sizeof(dexreq.name));
dexreq.func = 'M';
return(_dex_sendrequeststr(myinfo,&dexreq,jsonstr,0,1,""));
}
char *_dex_sendmessage(struct supernet_info *myinfo,char *jsonstr)
{
struct dex_request dexreq;
memset(&dexreq,0,sizeof(dexreq));
safecopy(dexreq.name,"KMD",sizeof(dexreq.name));
dexreq.func = 'a';
return(_dex_sendrequeststr(myinfo,&dexreq,jsonstr,0,1,""));
}
char *_dex_psock(struct supernet_info *myinfo,char *jsonstr)
{
struct dex_request dexreq;
if ( jsonstr == 0 )
jsonstr = "{}";
memset(&dexreq,0,sizeof(dexreq));
safecopy(dexreq.name,"KMD",sizeof(dexreq.name));
dexreq.func = 'Z';
return(_dex_sendrequeststr(myinfo,&dexreq,jsonstr,0,1,""));
}
char *_dex_listunspentarg(struct supernet_info *myinfo,char *symbol,char *address,uint8_t arg)
{
struct dex_request dexreq; char *retstr;
memset(&dexreq,0,sizeof(dexreq));
safecopy(dexreq.name,symbol,sizeof(dexreq.name));
dexreq.func = arg;
if ( (retstr= _dex_sendrequeststr(myinfo,&dexreq,address,0,1,"")) != 0 )
{
//printf("UNSPENTS.(%s)\n",retstr);
}
return(_dex_arrayreturn(retstr));
}
char *_dex_listunspent(struct supernet_info *myinfo,char *symbol,char *address)
{
return(_dex_listunspentarg(myinfo,symbol,address,'u')); // 'U' old variant
}
char *_dex_listunspent2(struct supernet_info *myinfo,char *symbol,char *address)
{
return(_dex_listunspentarg(myinfo,symbol,address,'u'));
}
char *_dex_listspent(struct supernet_info *myinfo,char *symbol,char *address)
{
struct dex_request dexreq; char *retstr;
memset(&dexreq,0,sizeof(dexreq));
safecopy(dexreq.name,symbol,sizeof(dexreq.name));
dexreq.func = 'U';
dexreq.func = 's';
if ( (retstr= _dex_sendrequeststr(myinfo,&dexreq,address,0,1,"")) != 0 )
{
//printf("UNSPENTS.(%s)\n",retstr);
}
return(_dex_arrayreturn(retstr));
}
char *_dex_getbalance(struct supernet_info *myinfo,char *symbol,char *address)
{
struct dex_request dexreq; char *retstr;
memset(&dexreq,0,sizeof(dexreq));
safecopy(dexreq.name,symbol,sizeof(dexreq.name));
dexreq.func = 'b';
if ( (retstr= _dex_sendrequeststr(myinfo,&dexreq,address,0,1,"")) != 0 )
{
//printf("UNSPENTS.(%s)\n",retstr);
@ -932,7 +1202,18 @@ char *_dex_listtransactions(struct supernet_info *myinfo,char *symbol,char *addr
safecopy(dexreq.name,symbol,sizeof(dexreq.name));
dexreq.intarg = skip;
dexreq.shortarg = count;
dexreq.func = 'L';
dexreq.func = '2';//'L';
return(_dex_arrayreturn(_dex_sendrequeststr(myinfo,&dexreq,address,0,1,"")));
}
char *_dex_listtransactions2(struct supernet_info *myinfo,char *symbol,char *address,int32_t count,int32_t skip)
{
struct dex_request dexreq;
memset(&dexreq,0,sizeof(dexreq));
safecopy(dexreq.name,symbol,sizeof(dexreq.name));
dexreq.intarg = skip;
dexreq.shortarg = count;
dexreq.func = '2';
return(_dex_arrayreturn(_dex_sendrequeststr(myinfo,&dexreq,address,0,1,"")));
}
@ -957,7 +1238,7 @@ int32_t dex_crc32find(struct supernet_info *myinfo,uint32_t crc32)
int32_t dex_packetcheck(struct supernet_info *myinfo,struct dex_nanomsghdr *dexp,int32_t size)
{
int32_t firstz=-1; uint32_t crc32;
uint32_t crc32; //int32_t firstz=-1;
if ( dexp->version0 == (DEX_VERSION & 0xff) && dexp->version1 == ((DEX_VERSION >> 8) & 0xff) )
{
if ( dexp->datalen == (size - sizeof(*dexp)) )
@ -965,7 +1246,7 @@ int32_t dex_packetcheck(struct supernet_info *myinfo,struct dex_nanomsghdr *dexp
crc32 = calc_crc32(0,dexp->packet,dexp->datalen);//(void *)((long)dexp + sizeof(dexp->crc32)),(int32_t)(size - sizeof(dexp->crc32)));
if ( dexp->crc32 == crc32 )//&& (firstz= dex_crc32find(myinfo,crc32)) >= 0 )
return(0);
else printf("dexp %08x != %08x || firstz.%d < 0\n",dexp->crc32,crc32,firstz);
//else printf("dexp %08x != %08x || firstz.%d < 0\n",dexp->crc32,crc32,firstz);
} else printf("datalen.%d != (%d - %ld)\n",dexp->datalen,size,sizeof(*dexp));
}
return(-1);
@ -974,6 +1255,7 @@ int32_t dex_packetcheck(struct supernet_info *myinfo,struct dex_nanomsghdr *dexp
int32_t dex_subsock_poll(struct supernet_info *myinfo)
{
int32_t size= -1; struct dex_nanomsghdr *dexp; void *freeptr;
return(0);
//fprintf(stderr,"subsock.%d\n",myinfo->subsock);
if ( myinfo->subsock >= 0 && (size= signed_nn_recv(&freeptr,myinfo->ctx,myinfo->notaries,myinfo->numnotaries,myinfo->subsock,&dexp)) >= 0 )
{
@ -994,7 +1276,7 @@ void dex_updateclient(struct supernet_info *myinfo)
int32_t i;
if ( myinfo->IAMNOTARY == 0 )
{
for (i=0; i<100; i++)
for (i=0; i<1000; i++)
if ( dex_subsock_poll(myinfo) <= 0 )
break;
}
@ -1143,12 +1425,13 @@ void dpow_nanomsginit(struct supernet_info *myinfo,char *ipaddr)
}
else
{
timeout = 500;
timeout = 100;
nn_setsockopt(repsock,NN_SOL_SOCKET,NN_SNDTIMEO,&timeout,sizeof(timeout));
nn_setsockopt(dexsock,NN_SOL_SOCKET,NN_SNDTIMEO,&timeout,sizeof(timeout));
timeout = 10;
nn_setsockopt(pubsock,NN_SOL_SOCKET,NN_SNDTIMEO,&timeout,sizeof(timeout));
timeout = 1;
nn_setsockopt(dexsock,NN_SOL_SOCKET,NN_RCVTIMEO,&timeout,sizeof(timeout));
timeout = 500;
timeout = 1;
nn_setsockopt(repsock,NN_SOL_SOCKET,NN_RCVTIMEO,&timeout,sizeof(timeout));
maxsize = 1024 * 1024;
printf("RCVBUF.%d\n",nn_setsockopt(dexsock,NN_SOL_SOCKET,NN_RCVBUF,&maxsize,sizeof(maxsize)));
@ -1162,7 +1445,7 @@ void dpow_nanomsginit(struct supernet_info *myinfo,char *ipaddr)
}
myinfo->dpowipbits[0] = (uint32_t)calc_ipbits(myinfo->ipaddr);
myinfo->numdpowipbits = 1;
timeout = 10;
timeout = 1;
nn_setsockopt(dpowsock,NN_SOL_SOCKET,NN_RCVTIMEO,&timeout,sizeof(timeout));
maxsize = 1024 * 1024;
printf("RCVBUF.%d\n",nn_setsockopt(dpowsock,NN_SOL_SOCKET,NN_RCVBUF,&maxsize,sizeof(maxsize)));
@ -1710,7 +1993,7 @@ void dpow_send(struct supernet_info *myinfo,struct dpow_info *dp,struct dpow_blo
pfd.events = NN_POLLOUT;
if ( nn_poll(&pfd,1,100) > 0 )
{
sentbytes = signed_nn_send(myinfo->ctx,myinfo->persistent_priv,myinfo->dpowsock,np,size);
sentbytes = signed_nn_send(myinfo,myinfo->ctx,myinfo->persistent_priv,myinfo->dpowsock,np,size);
break;
}
usleep(1000);
@ -1726,7 +2009,9 @@ void dpow_ipbitsadd(struct supernet_info *myinfo,struct dpow_info *dp,uint32_t *
int32_t i,j,matched,missing,n; char ipaddr[64];
if ( numipbits >= 64 )
{
printf("dpow_ipbitsadd reject from.%d numipbits.%d\n",fromid,numipbits);
static int32_t counter;
if ( counter++ < 100 )
printf("dpow_ipbitsadd reject from.%d numipbits.%d\n",fromid,numipbits);
return;
}
n = dp->numipbits;
@ -1765,7 +2050,7 @@ void dpow_ipbitsadd(struct supernet_info *myinfo,struct dpow_info *dp,uint32_t *
int32_t dpow_nanomsg_update(struct supernet_info *myinfo)
{
int32_t i,n=0,num=0,size,broadcastflag,firstz = -1; char *retstr; uint32_t crc32,r,m; struct dpow_nanomsghdr *np=0; struct dpow_info *dp; struct dpow_block *bp; struct dex_nanomsghdr *dexp = 0; void *freeptr;
int32_t i,n,num,num2,flags=0,size,iter,lastval=0,broadcastflag,firstz = -1; char *retstr; uint32_t crc32,r,m; struct dpow_nanomsghdr *np=0; struct dpow_info *dp; struct dpow_block *bp; struct dex_nanomsghdr *dexp = 0; void *freeptr;
if ( time(NULL) < myinfo->nanoinit+5 || (myinfo->dpowsock < 0 && myinfo->dexsock < 0 && myinfo->repsock < 0) )
return(-1);
if ( myinfo->IAMNOTARY != 0 && myinfo->numnotaries <= 0 )
@ -1774,123 +2059,128 @@ int32_t dpow_nanomsg_update(struct supernet_info *myinfo)
printf("INIT with %d notaries\n",myinfo->numnotaries);
}
portable_mutex_lock(&myinfo->dpowmutex);
/*for (i=0; i<100; i++)
num = num2 = n = 0;
for (iter=0; iter<100; iter++)
{
struct nn_pollfd pfd;
pfd.fd = myinfo->dpowsock;
pfd.events = NN_POLLIN;
if ( nn_poll(&pfd,1,100) > 0 )
break;
usleep(1000);
}*/
while ( (size= signed_nn_recv(&freeptr,myinfo->ctx,myinfo->notaries,myinfo->numnotaries,myinfo->dpowsock,&np)) >= 0 && num < 100 )
{
num++;
if ( size > 0 )
freeptr = 0;
if ( (flags & 1) == 0 && (size= signed_nn_recv(&freeptr,myinfo->ctx,myinfo->notaries,myinfo->numnotaries,myinfo->dpowsock,&np)) > 0 )
{
//fprintf(stderr,"%d ",size);
if ( np->version0 == (DPOW_VERSION & 0xff) && np->version1 == ((DPOW_VERSION >> 8) & 0xff) )
num++;
if ( size > 0 )
{
//printf("v.%02x %02x datalen.%d size.%d %d vs %d\n",np->version0,np->version1,np->datalen,size,np->datalen,(int32_t)(size - sizeof(*np)));
if ( np->datalen == (size - sizeof(*np)) )
//fprintf(stderr,"%d ",size);
if ( np->version0 == (DPOW_VERSION & 0xff) && np->version1 == ((DPOW_VERSION >> 8) & 0xff) )
{
crc32 = calc_crc32(0,np->packet,np->datalen);
dp = 0;
for (i=0; i<myinfo->numdpows; i++)
//printf("v.%02x %02x datalen.%d size.%d %d vs %d\n",np->version0,np->version1,np->datalen,size,np->datalen,(int32_t)(size - sizeof(*np)));
if ( np->datalen == (size - sizeof(*np)) )
{
if ( strcmp(np->symbol,myinfo->DPOWS[i].symbol) == 0 )
crc32 = calc_crc32(0,np->packet,np->datalen);
dp = 0;
for (i=0; i<myinfo->numdpows; i++)
{
dp = &myinfo->DPOWS[i];
break;
if ( strcmp(np->symbol,myinfo->DPOWS[i].symbol) == 0 )
{
dp = &myinfo->DPOWS[i];
break;
}
}
}
if ( dp != 0 && crc32 == np->crc32 )
{
if ( i == myinfo->numdpows )
printf("received nnpacket for (%s)\n",np->symbol);
else
if ( dp != 0 && crc32 == np->crc32 )
{
dpow_ipbitsadd(myinfo,dp,np->ipbits,np->numipbits,np->senderind,np->myipbits);
if ( (bp= dpow_heightfind(myinfo,dp,np->height)) != 0 && bp->state != 0xffffffff && bp->myind >= 0 )
if ( i == myinfo->numdpows )
printf("received nnpacket for (%s)\n",np->symbol);
else
{
//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);
if ( np->senderind >= 0 && np->senderind < bp->numnotaries )
dpow_ipbitsadd(myinfo,dp,np->ipbits,np->numipbits,np->senderind,np->myipbits);
if ( (bp= dpow_heightfind(myinfo,dp,np->height)) != 0 && bp->state != 0xffffffff && bp->myind >= 0 )
{
if ( memcmp(bp->notaries[np->senderind].pubkey+1,np->srchash.bytes,32) == 0 && bits256_nonz(np->srchash) != 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);
if ( np->senderind >= 0 && np->senderind < bp->numnotaries )
{
if ( bp->isratify == 0 )
dpow_nanoutxoget(myinfo,dp,bp,&np->notarize,0,np->senderind,np->channel);
else dpow_nanoutxoget(myinfo,dp,bp,&np->ratify,1,np->senderind,np->channel);
dpow_datahandler(myinfo,dp,bp,np->senderind,np->channel,np->height,np->packet,np->datalen);
} else printf("wrong senderind.%d\n",np->senderind);
}
} //else printf("height.%d bp.%p state.%x senderind.%d\n",np->height,bp,bp!=0?bp->state:0,np->senderind);
//dp->crcs[firstz] = crc32;
}
} //else printf("crc error from.%d %x vs %x or no dp.%p [%s]\n",np->senderind,crc32,np->crc32,dp,np->symbol);
} else printf("ignore.%d np->datalen.%d %d (size %d - %ld) [%s]\n",np->senderind,np->datalen,(int32_t)(size-sizeof(*np)),size,sizeof(*np),np->symbol);
} //else printf("wrong version from.%d %02x %02x size.%d [%s]\n",np->senderind,np->version0,np->version1,size,np->symbol);
} //else printf("illegal size.%d\n",size);
if ( memcmp(bp->notaries[np->senderind].pubkey+1,np->srchash.bytes,32) == 0 && bits256_nonz(np->srchash) != 0 )
{
if ( bp->isratify == 0 )
dpow_nanoutxoget(myinfo,dp,bp,&np->notarize,0,np->senderind,np->channel);
else dpow_nanoutxoget(myinfo,dp,bp,&np->ratify,1,np->senderind,np->channel);
dpow_datahandler(myinfo,dp,bp,np->senderind,np->channel,np->height,np->packet,np->datalen);
} else printf("wrong senderind.%d\n",np->senderind);
}
} //else printf("height.%d bp.%p state.%x senderind.%d\n",np->height,bp,bp!=0?bp->state:0,np->senderind);
//dp->crcs[firstz] = crc32;
}
} //else printf("crc error from.%d %x vs %x or no dp.%p [%s]\n",np->senderind,crc32,np->crc32,dp,np->symbol);
} else printf("ignore.%d np->datalen.%d %d (size %d - %ld) [%s]\n",np->senderind,np->datalen,(int32_t)(size-sizeof(*np)),size,sizeof(*np),np->symbol);
} //else printf("wrong version from.%d %02x %02x size.%d [%s]\n",np->senderind,np->version0,np->version1,size,np->symbol);
}
} else flags |= 1;
if ( freeptr != 0 )
nn_freemsg(freeptr), np = 0, freeptr = 0;
} //else printf("no packets\n");
n = 0;
if ( myinfo->dexsock >= 0 ) // from servers
{
if ( (size= signed_nn_recv(&freeptr,myinfo->ctx,myinfo->notaries,myinfo->numnotaries,myinfo->dexsock,&dexp)) > 0 )
if ( myinfo->dexsock >= 0 ) // from servers
{
//fprintf(stderr,"%d ",size);
num++;
if ( dex_packetcheck(myinfo,dexp,size) == 0 )
freeptr = 0;
if ( (flags & 2) == 0 && (size= signed_nn_recv(&freeptr,myinfo->ctx,myinfo->notaries,myinfo->numnotaries,myinfo->dexsock,&dexp)) > 0 )
{
//printf("FROM BUS.%08x -> pub\n",dexp->crc32);
signed_nn_send(myinfo->ctx,myinfo->persistent_priv,myinfo->pubsock,dexp,size);
dex_packet(myinfo,dexp,size);
}
//printf("GOT DEX bus PACKET.%d\n",size);
//fprintf(stderr,"%d ",size);
n++;
if ( dex_packetcheck(myinfo,dexp,size) == 0 )
{
//printf("FROM BUS.%08x -> pub\n",dexp->crc32);
//signed_nn_send(myinfo,myinfo->ctx,myinfo->persistent_priv,myinfo->pubsock,dexp,size);
dex_packet(myinfo,dexp,size);
}
//printf("GOT DEX bus PACKET.%d\n",size);
} else flags |= 2;
if ( freeptr != 0 )
nn_freemsg(freeptr), dexp = 0, freeptr = 0;
}
}
if ( myinfo->repsock >= 0 ) // from clients
{
if ( (size= nn_recv(myinfo->repsock,&dexp,NN_MSG,0)) > 0 )
if ( myinfo->repsock >= 0 ) // from clients
{
num++;
//printf("REP got %d crc.%08x\n",size,calc_crc32(0,(void *)dexp,size));
if ( (retstr= dex_response(&broadcastflag,myinfo,dexp)) != 0 )
dexp = 0;
if ( (flags & 4) == 0 && (size= nn_recv(myinfo->repsock,&dexp,NN_MSG,0)) > 0 )
{
signed_nn_send(myinfo->ctx,myinfo->persistent_priv,myinfo->repsock,retstr,(int32_t)strlen(retstr)+1);
//printf("send back[%ld]\n",strlen(retstr)+1);
free(retstr);
if ( broadcastflag != 0 )
num2++;
//printf("REP got %d crc.%08x\n",size,calc_crc32(0,(void *)dexp,size));
if ( (retstr= dex_response(&broadcastflag,myinfo,dexp)) != 0 )
{
printf("BROADCAST dexp request.[%d]\n",size);
signed_nn_send(myinfo->ctx,myinfo->persistent_priv,myinfo->dexsock,dexp,size);
signed_nn_send(myinfo,myinfo->ctx,myinfo->persistent_priv,myinfo->repsock,retstr,(int32_t)strlen(retstr)+1);
//printf("send back[%ld]\n",strlen(retstr)+1);
free(retstr);
if ( broadcastflag != 0 )
{
printf("BROADCAST dexp request.[%d]\n",size);
signed_nn_send(myinfo,myinfo->ctx,myinfo->persistent_priv,myinfo->dexsock,dexp,size);
//signed_nn_send(myinfo,myinfo->ctx,myinfo->persistent_priv,myinfo->pubsock,dexp,size);
}
}
}
else
{
if ( (m= myinfo->numdpowipbits) > 0 )
{
r = myinfo->dpowipbits[rand() % m];
signed_nn_send(myinfo->ctx,myinfo->persistent_priv,myinfo->repsock,&r,sizeof(r));
//printf("REP.%08x <- rand ip m.%d %x\n",dexp->crc32,m,r);
} else printf("illegal state without dpowipbits?\n");
if ( dex_packetcheck(myinfo,dexp,size) == 0 )
else
{
signed_nn_send(myinfo->ctx,myinfo->persistent_priv,myinfo->dexsock,dexp,size);
signed_nn_send(myinfo->ctx,myinfo->persistent_priv,myinfo->pubsock,dexp,size);
//printf("REP.%08x -> dexbus and pub, t.%d lag.%d\n",dexp->crc32,dexp->timestamp,(int32_t)(time(NULL)-dexp->timestamp));
dex_packet(myinfo,dexp,size);
} else printf("failed dexpacketcheck\n");
}
//printf("GOT DEX rep PACKET.%d\n",size);
//if ( freeptr != 0 )
// nn_freemsg(freeptr), dexp = 0, freeptr = 0;
if ( (m= myinfo->numdpowipbits) > 0 )
{
r = myinfo->dpowipbits[rand() % m];
signed_nn_send(myinfo,myinfo->ctx,myinfo->persistent_priv,myinfo->repsock,&r,sizeof(r));
//printf("REP.%08x <- rand ip m.%d %x\n",dexp->crc32,m,r);
} else printf("illegal state without dpowipbits?\n");
if ( dex_packetcheck(myinfo,dexp,size) == 0 )
{
signed_nn_send(myinfo,myinfo->ctx,myinfo->persistent_priv,myinfo->dexsock,dexp,size);
//signed_nn_send(myinfo,myinfo->ctx,myinfo->persistent_priv,myinfo->pubsock,dexp,size);
//printf("REP.%08x -> dexbus and pub, t.%d lag.%d\n",dexp->crc32,dexp->timestamp,(int32_t)(time(NULL)-dexp->timestamp));
dex_packet(myinfo,dexp,size);
} //else printf("failed dexpacketcheck\n");
}
//printf("GOT DEX rep PACKET.%d\n",size);
//if ( freeptr != 0 )
// nn_freemsg(freeptr), dexp = 0, freeptr = 0;
//if ( num > 1000 )
// break;
} else flags |= 4;
if ( dexp != 0 )
nn_freemsg(dexp), dexp = 0;
}
if ( (num + n + num2) != lastval )
{
//printf("lastval.%d: num.%d n.%d num2.%d rep packets\n",lastval,num,n,num2);
lastval = (num + n + num2);
} else break;
}
portable_mutex_unlock(&myinfo->dpowmutex);
return(num);

74
iguana/dpow/dpow_prices.c

@ -1154,6 +1154,7 @@ cJSON *url_json2(char *url)
double PAX_yahoo(char *metal)
{
// http://finance.yahoo.com/webservice/v1/symbols/allcurrencies/quote?format=json
// http://finance.yahoo.com/webservice/v1/symbols/EUR=USD/quote?format=json
// http://finance.yahoo.com/webservice/v1/symbols/XAU=X/quote?format=json
// http://finance.yahoo.com/webservice/v1/symbols/XAG=X/quote?format=json
// http://finance.yahoo.com/webservice/v1/symbols/XPT=X/quote?format=json
@ -1450,7 +1451,7 @@ void PAX_update(struct PAX_data *dp,double *btcusdp,double *kmdbtcp)
}
if ( 1 )
{
double avebid,aveask,bidvol,askvol; //struct exchange_quote sortbuf[512]; struct supernet_info *myinfo = SuperNET_MYINFO(0); cJSON *argjson = cJSON_Parse("{}");
double USD_average,avebid,aveask,bidvol,askvol,highbid,lowask,CMC_average,changes[3]; //struct exchange_quote sortbuf[512]; struct supernet_info *myinfo = SuperNET_MYINFO(0); cJSON *argjson = cJSON_Parse("{}");
//aveask = instantdex_aveprice(myinfo,sortbuf,(int32_t)(sizeof(sortbuf)/sizeof(*sortbuf)),&askvol,"KMD","BTC",1,argjson);
//avebid = instantdex_aveprice(myinfo,sortbuf,(int32_t)(sizeof(sortbuf)/sizeof(*sortbuf)),&bidvol,"KMD","BTC",-1,argjson);
if ( 0 && avebid > SMALLVAL && aveask > SMALLVAL )
@ -1460,6 +1461,8 @@ void PAX_update(struct PAX_data *dp,double *btcusdp,double *kmdbtcp)
printf("set KMD price %f\n",price);
dp->KMDBTC = price;
}
else if ( (dp->KMDBTC= get_theoretical(&avebid,&aveask,&highbid,&lowask,&CMC_average,changes,"komodo","KMD","BTC",&USD_average)) > SMALLVAL )
*kmdbtcp = dp->KMDBTC;
else
{
for (iter=1; iter<2; iter++)
@ -1635,7 +1638,7 @@ void _crypto_update(double cryptovols[2][9][2],struct PAX_data *dp,int32_t selec
void PAX_RTupdate(double cryptovols[2][9][2],double RTmetals[4],double *RTprices,struct PAX_data *dp)
{
char *cryptostrs[9] = { "btc", "nxt", "unity", "eth", "etc", "kmd", "xmr", "bts", "xcp" };
int32_t iter,i,c,baserel,basenum,relnum; double cnyusd,btcusd,kmdbtc,bid,ask,price,vol,prices[8][2],volumes[8][2];
int32_t iter,i,c,baserel,basenum,relnum; double cnyusd,btcusd,kmdbtc,bid=0.,ask=0.,price,vol,prices[8][2],volumes[8][2];
char base[16],rel[16];
PAX_update(dp,&btcusd,&kmdbtc);
memset(prices,0,sizeof(prices));
@ -1882,41 +1885,44 @@ int32_t PAX_idle(struct supernet_info *myinfo)//struct PAX_data *argdp,int32_t i
PAX_RTupdate(dp->cryptovols,dp->RTmetals,dp->RTprices,dp);
PAX_emitprices(pvals,dp);
}
PAX_update(dp,&dp->btcusd,&dp->kmdbtc);
timestamp = (uint32_t)time(NULL);
int32_t dispflag = ((rand() % 100) == 0);
for (i=0; i<MAX_CURRENCIES; i++)
int32_t dispflag = ((rand() % 64) == 0);
if ( dp->kmdbtc == 0 || dispflag != 0 )
{
splineval = PAX_splineval(&dp->splines[i],timestamp,0);
pvals[6+i] = PAX_val32(splineval);
PAX_update(dp,&dp->btcusd,&dp->kmdbtc);
for (i=0; i<MAX_CURRENCIES; i++)
{
splineval = PAX_splineval(&dp->splines[i],timestamp,0);
pvals[6+i] = PAX_val32(splineval);
if ( dispflag != 0 )
printf("%u ",pvals[6+i]);
}
if ( pvals[6+CNY] != 0 && pvals[6+USD] != 0 )
dp->CNYUSD = ((double)pvals[6 + CNY] / pvals[6 + USD]) * MINDENOMS[USD] / MINDENOMS[CNY];
pvals[1] = timestamp;
pvals[2] = MAX_CURRENCIES + 3;
pvals[3] = PAX_val32(dp->kmdbtc * 1000);
pvals[4] = PAX_val32(dp->btcusd * .001);
pvals[5] = PAX_val32(dp->CNYUSD);
if ( dispflag != 0 )
printf("%u ",pvals[6+i]);
}
if ( pvals[6+CNY] != 0 && pvals[6+USD] != 0 )
dp->CNYUSD = ((double)pvals[6 + CNY] / pvals[6 + USD]) * MINDENOMS[USD] / MINDENOMS[CNY];
pvals[1] = timestamp;
pvals[2] = MAX_CURRENCIES + 3;
pvals[3] = PAX_val32(dp->kmdbtc * 1000);
pvals[4] = PAX_val32(dp->btcusd * .001);
pvals[5] = PAX_val32(dp->CNYUSD);
if ( dispflag != 0 )
printf("KMD %f 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 )
{
for (i=1; i<MAX_CURRENCIES+6; i++)
iguana_rwnum(1,&data[i*sizeof(uint32_t)],sizeof(*pvals),(void *)&pvals[i]);
pvals[0] = calc_crc32(0,(void *)&data[sizeof(uint32_t)],(MAX_CURRENCIES+5)*sizeof(*pvals));
iguana_rwnum(1,data,sizeof(*pvals),(void *)&pvals[0]);
if ( fwrite(data,sizeof(*pvals),MAX_CURRENCIES+6,fp) != MAX_CURRENCIES+6 )
printf("error writing pvals to (%s)\n",fname);
fclose(fp);
}
if ( dispflag != 0 )
{
for (i=0; i<6; i++)
printf("%u ",pvals[i]);
printf("pvals -> %s\n",fname);
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 )
{
for (i=1; i<MAX_CURRENCIES+6; i++)
iguana_rwnum(1,&data[i*sizeof(uint32_t)],sizeof(*pvals),(void *)&pvals[i]);
pvals[0] = calc_crc32(0,(void *)&data[sizeof(uint32_t)],(MAX_CURRENCIES+5)*sizeof(*pvals));
iguana_rwnum(1,data,sizeof(*pvals),(void *)&pvals[0]);
if ( fwrite(data,sizeof(*pvals),MAX_CURRENCIES+6,fp) != MAX_CURRENCIES+6 )
printf("error writing pvals to (%s)\n",fname);
fclose(fp);
}
if ( dispflag != 0 )
{
for (i=0; i<6; i++)
printf("%u ",pvals[i]);
printf("pvals -> %s\n",fname);
}
}
}
return(0);

41
iguana/dpow/dpow_rpc.c

@ -36,6 +36,16 @@ cJSON *dpow_getinfo(struct supernet_info *myinfo,struct iguana_info *coin)
{
json = cJSON_Parse(retstr);
free(retstr);
if ( strcmp(coin->symbol,"BTC") == 0 )
{
sprintf(buf,"[%d]",2);
if ( (retstr= bitcoind_passthru(coin->symbol,coin->chain->serverport,coin->chain->userpass,"estimatefee",buf)) != 0 )
{
if ( atof(retstr) > SMALLVAL )
jaddnum(json,"estimatefee",atof(retstr));
free(retstr);
}
}
}
return(json);
}
@ -324,6 +334,7 @@ cJSON *dpow_gettxout(struct supernet_info *myinfo,struct iguana_info *coin,bits2
json = cJSON_Parse(retstr);
free(retstr);
}
//printf("dpow_gettxout.(%s)\n",retstr);
return(json);
}
@ -405,6 +416,36 @@ cJSON *dpow_listunspent(struct supernet_info *myinfo,struct iguana_info *coin,ch
return(json);
}
cJSON *dpow_listspent(struct supernet_info *myinfo,struct iguana_info *coin,char *coinaddr)
{
if ( myinfo->DEXEXPLORER != 0 )
return(kmd_listspent(myinfo,coin,coinaddr));
else
{
return(0);
}
}
cJSON *dpow_getbalance(struct supernet_info *myinfo,struct iguana_info *coin,char *coinaddr)
{
if ( myinfo->DEXEXPLORER != 0 )
return(kmd_getbalance(myinfo,coin,coinaddr));
else
{
return(0);
}
}
cJSON *dpow_gettxin(struct supernet_info *myinfo,struct iguana_info *coin,bits256 txid,int32_t vout)
{
if ( myinfo->DEXEXPLORER != 0 )
return(kmd_gettxin(coin,txid,vout));
else
{
return(0);
}
}
cJSON *dpow_listtransactions(struct supernet_info *myinfo,struct iguana_info *coin,char *coinaddr,int32_t count,int32_t skip)
{
char buf[128],*retstr; cJSON *json = 0;

4
iguana/dpow/dpow_tx.c

@ -224,7 +224,7 @@ int32_t dpow_voutstandard(struct dpow_block *bp,uint8_t *serialized,int32_t m,in
}
printf("numvouts.%d len.%d RATIFY vouts\n",numvouts,len);
}
if ( (src_or_dest == 0 || strcmp(bp->destcoin->symbol,"BTC") != 0) && (n= dpow_paxpending(extras,&paxwdcrc)) > 0 )
if ( 0 && (src_or_dest == 0 || strcmp(bp->destcoin->symbol,"BTC") != 0) && (n= dpow_paxpending(extras,&paxwdcrc)) > 0 )
{
for (i=0; i<n; i++)
printf("%02x",extras[i]);
@ -429,6 +429,7 @@ void dpow_rawtxsign(struct supernet_info *myinfo,struct dpow_info *dp,struct igu
return;
for (j=0; j<sizeof(srchash); j++)
srchash.bytes[j] = dp->minerkey33[j+1];
memset(srchash.bytes,0,sizeof(srchash));
m = 0;
ep = &bp->notaries[myind];
cp = (src_or_dest != 0) ? &bp->notaries[myind].dest : &bp->notaries[myind].src;
@ -564,6 +565,7 @@ void dpow_sigscheck(struct supernet_info *myinfo,struct dpow_info *dp,struct dpo
bits256 txid,srchash,zero,signedtxid; struct iguana_info *coin; int32_t j,len,numsigs; char *retstr=0,str[65],str2[65]; uint8_t txdata[32768]; uint32_t channel,state;
coin = (src_or_dest != 0) ? bp->destcoin : bp->srccoin;
memset(zero.bytes,0,sizeof(zero));
memset(txid.bytes,0,sizeof(txid));
channel = (src_or_dest != 0) ? DPOW_SIGBTCCHANNEL : DPOW_SIGCHANNEL;
if ( bestk >= 0 && bp->state != 0xffffffff && coin != 0 )
{

52
iguana/dpowassets

@ -1,52 +0,0 @@
#!/bin/bash
set -x
source pubkey.txt
echo $pubkey
curl --url "http://127.0.0.1:7776" --data "{\"timeout\":60000,\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"REVS\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"SUPERNET\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"DEX\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"PANGEA\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"JUMBLR\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"BET\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"CRYPTO\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"HODL\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"SHARK\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"BOTS\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"MGW\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"USD\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"EUR\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"JPY\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"GBP\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"AUD\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"CAD\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"CHF\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"NZD\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"CNY\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"RUB\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"MXN\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"BRL\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"INR\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"HKD\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"TRY\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"ZAR\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"PLN\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"NOK\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"SEK\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"DKK\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"CZK\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"HUF\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"ILS\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"KRW\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"MYR\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"PHP\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"RON\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"SGD\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"THB\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"BGN\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"IDR\",\"pubkey\":\"$pubkey\"}"
curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"HRK\",\"pubkey\":\"$pubkey\"}"

19
iguana/exchanges/bitcoin.c

@ -107,18 +107,30 @@ int32_t base58encode_checkbuf(uint8_t addrtype,uint8_t *data,int32_t data_len)
int32_t bitcoin_wif2priv(uint8_t *addrtypep,bits256 *privkeyp,char *wifstr)
{
int32_t len = -1; bits256 hash; uint8_t buf[64];
int32_t len = -1; bits256 hash; uint8_t buf[256];
memset(buf,0,sizeof(buf));
if ( (len= bitcoin_base58decode(buf,wifstr)) >= 4 )
{
// validate with trailing hash, then remove hash
if ( len < 38 )
len = 38;
hash = bits256_doublesha256(0,buf,len - 4);
*addrtypep = *buf;
memcpy(privkeyp,buf+1,32);
if ( (buf[len - 4]&0xff) == hash.bytes[31] && (buf[len - 3]&0xff) == hash.bytes[30] &&(buf[len - 2]&0xff) == hash.bytes[29] &&(buf[len - 1]&0xff) == hash.bytes[28] )
if ( (buf[len - 4]&0xff) == hash.bytes[31] && (buf[len - 3]&0xff) == hash.bytes[30] &&(buf[len - 2]&0xff) == hash.bytes[29] && (buf[len - 1]&0xff) == hash.bytes[28] )
{
//printf("coinaddr.(%s) valid checksum\n",coinaddr);
//int32_t i; for (i=0; i<len; i++)
// printf("%02x ",buf[i]);
//printf(" buf, hash.%02x %02x %02x %02x ",hash.bytes[28],hash.bytes[29],hash.bytes[30],hash.bytes[31]);
//printf("wifstr.(%s) valid len.%d\n",wifstr,len);
return(32);
}
else
{
int32_t i; for (i=0; i<len; i++)
printf("%02x ",buf[i]);
printf(" buf, hash.%02x %02x %02x %02x\n",hash.bytes[28],hash.bytes[29],hash.bytes[30],hash.bytes[31]);
}
}
return(-1);
}
@ -290,6 +302,7 @@ struct bitcoin_spend *iguana_spendset(struct supernet_info *myinfo,struct iguana
ptr = spend->inputs;
for (i=0; i<maxinputs; i++,ptr++)
{
up = 0;
for (mode=1; mode>=0; mode--)
if ( (up= iguana_bestfit(coin,ups,totalunspents,remains,mode)) != 0 )
break;

18
iguana/exchanges/bittrex.c

@ -194,8 +194,13 @@ uint64_t TRADE(int32_t dotrade,char **retstrp,struct exchange_info *exchange,cha
char *ORDERSTATUS(struct exchange_info *exchange,uint64_t quoteid,cJSON *argjson)
{
char payload[1024],*retstr = 0; cJSON *json;
sprintf(payload,"https://bittrex.com/api/v1.1/account/getorder?apikey=%s&nonce=%llu&uuid=%llu",exchange->apikey,(long long)exchange_nonce(exchange),(long long)quoteid);
char payload[1024],*orderstr=0,orderbuf[512],*retstr = 0; cJSON *json;
if ( argjson != 0 )
orderstr = jstr(argjson,"uuid");//, printf("status.(%s)\n",jprint(argjson,0));
if ( orderstr == 0 )
sprintf(orderbuf,"%llu",(long long)quoteid);
else strcpy(orderbuf,jstr(argjson,"uuid"));
sprintf(payload,"https://bittrex.com/api/v1.1/account/getorder?apikey=%s&nonce=%llu&uuid=%s",exchange->apikey,(long long)exchange_nonce(exchange),orderbuf);
if ( (json= SIGNPOST(&exchange->cHandle,1,&retstr,exchange,payload,payload)) != 0 )
{
free_json(json);
@ -205,8 +210,13 @@ char *ORDERSTATUS(struct exchange_info *exchange,uint64_t quoteid,cJSON *argjson
char *CANCELORDER(struct exchange_info *exchange,uint64_t quoteid,cJSON *argjson)
{
char payload[1024],*retstr = 0; cJSON *json;
sprintf(payload,"https://bittrex.com/api/v1.1/market/cancel?apikey=%s&nonce=%llu&uuid=%llu",exchange->apikey,(long long)exchange_nonce(exchange),(long long)quoteid);
char payload[1024],*orderstr=0,orderbuf[512],*retstr = 0; cJSON *json;
if ( argjson != 0 )
orderstr = jstr(argjson,"uuid");//, printf("cancel.(%s)\n",jprint(argjson,0));
if ( orderstr == 0 )
sprintf(orderbuf,"%llu",(long long)quoteid);
else strcpy(orderbuf,jstr(argjson,"uuid"));
sprintf(payload,"https://bittrex.com/api/v1.1/market/cancel?apikey=%s&nonce=%llu&uuid=%s",exchange->apikey,(long long)exchange_nonce(exchange),orderbuf);
if ( (json= SIGNPOST(&exchange->cHandle,1,&retstr,exchange,payload,payload)) != 0 )
{
free_json(json);

3
iguana/exchanges/fxcm.c

@ -99,7 +99,7 @@ int32_t fxcm_setcontracts()
{
if ( (json= cJSON_Parse(xmlstr)) != 0 )
{
/*<Rate Symbol="USDJPY">
/* <Rate Symbol="USDJPY">
<Bid>123.763</Bid>
<Ask>123.786</Ask>
<High>123.956</High>
@ -153,6 +153,7 @@ int32_t fxcm_ensure()
char *ALLPAIRS(struct exchange_info *exchange,cJSON *argjson)
{
int32_t i,c,n; char base[32],rel[32]; cJSON *json,*item,*array = cJSON_CreateArray();
n = 0;
if ( fxcm_ensure() == 0 )
{
for (i=0; i<num_FXCM; i++)

722
iguana/exchanges/mm.c

@ -0,0 +1,722 @@
/******************************************************************************
* 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. *
* *
******************************************************************************/
//
// main.c
// marketmaker
//
// Copyright © 2017 SuperNET. All rights reserved.
//
#include <stdio.h>
#include <stdint.h>
#include "OS_portable.h"
#define MAX(a,b) ((a) > (b) ? (a) : (b))
struct mmpending_order
{
double price,volume;
int32_t dir;
uint32_t pending,completed,canceled,cancelstarted,reported;
cJSON *errorjson;
char exchange[16],base[16],rel[16],orderid[64];
} *Pending_orders;
int32_t Num_Pending;
#define IGUANA_URL "http://127.0.0.1:7778"
char CURRENCIES[][8] = { "USD", "EUR", "JPY", "GBP", "AUD", "CAD", "CHF", "NZD", // major currencies
"CNY", "RUB", "MXN", "BRL", "INR", "HKD", "TRY", "ZAR", "PLN", "NOK", "SEK", "DKK", "CZK", "HUF", "ILS", "KRW", "MYR", "PHP", "RON", "SGD", "THB", "BGN", "IDR", "HRK", // end of currencies
};
double PAXPRICES[sizeof(CURRENCIES)/sizeof(*CURRENCIES)];
char *DEX_amlp(char *blocktrail)
{
char url[512],postdata[1024];
sprintf(url,"%s/?",IGUANA_URL);
sprintf(postdata,"{\"agent\":\"tradebot\",\"method\":\"amlp\",\"blocktrail\":\"%s\"}",blocktrail);
return(bitcoind_RPC(0,"tradebot",url,0,"amlp",postdata));
}
char *DEX_openorders(char *exchange)
{
char url[512],postdata[1024];
sprintf(url,"%s/?",IGUANA_URL);
sprintf(postdata,"{\"agent\":\"InstantDEX\",\"method\":\"openorders\",\"exchange\":\"%s\"}",exchange);
return(bitcoind_RPC(0,"InstantDEX",url,0,"openorders",postdata));
}
char *DEX_tradehistory(char *exchange)
{
char url[512],postdata[1024];
sprintf(url,"%s/?",IGUANA_URL);
sprintf(postdata,"{\"agent\":\"InstantDEX\",\"method\":\"tradehistory\",\"exchange\":\"%s\"}",exchange);
return(bitcoind_RPC(0,"InstantDEX",url,0,"tradehistory",postdata));
}
char *DEX_orderstatus(char *exchange,char *orderid)
{
char url[512],postdata[1024];
sprintf(url,"%s/?",IGUANA_URL);
sprintf(postdata,"{\"agent\":\"InstantDEX\",\"method\":\"orderstatus\",\"exchange\":\"%s\",\"orderid\":\"%s\"}",exchange,orderid);
return(bitcoind_RPC(0,"InstantDEX",url,0,"orderstatus",postdata));
}
char *DEX_cancelorder(char *exchange,char *orderid)
{
char url[512],postdata[1024];
sprintf(url,"%s/?",IGUANA_URL);
sprintf(postdata,"{\"agent\":\"InstantDEX\",\"method\":\"cancelorder\",\"exchange\":\"%s\",\"orderid\":\"%s\"}",exchange,orderid);
return(bitcoind_RPC(0,"InstantDEX",url,0,"cancelorder",postdata));
}
char *DEX_balance(char *exchange,char *base,char *coinaddr)
{
char url[512],postdata[1024];
sprintf(url,"%s/?",IGUANA_URL);
if ( strcmp(exchange,"DEX") == 0 )
{
sprintf(postdata,"{\"agent\":\"dex\",\"method\":\"getbalance\",\"address\":\"%s\",\"symbol\":\"%s\"}",coinaddr,base);
return(bitcoind_RPC(0,"dex",url,0,"getbalance",postdata));
}
else
{
sprintf(postdata,"{\"agent\":\"InstantDEX\",\"method\":\"balance\",\"exchange\":\"%s\",\"base\":\"%s\"}",exchange,base);
return(bitcoind_RPC(0,"InstantDEX",url,0,"balance",postdata));
}
}
char *DEX_apikeypair(char *exchange,char *apikey,char *apisecret)
{
char url[512],postdata[1024];
sprintf(url,"%s/?",IGUANA_URL);
sprintf(postdata,"{\"agent\":\"InstantDEX\",\"method\":\"apikeypair\",\"exchange\":\"%s\",\"apikey\":\"%s\",\"apisecret\":\"%s\"}",exchange,apikey,apisecret);
return(bitcoind_RPC(0,"InstantDEX",url,0,"apikeypair",postdata));
}
char *DEX_setuserid(char *exchange,char *userid,char *tradepassword)
{
char url[512],postdata[1024];
sprintf(url,"%s/?",IGUANA_URL);
sprintf(postdata,"{\"agent\":\"InstantDEX\",\"method\":\"setuserid\",\"exchange\":\"%s\",\"userid\":\"%s\",\"tradepassword\":\"%s\"}",exchange,userid,tradepassword);
return(bitcoind_RPC(0,"InstantDEX",url,0,"setuserid",postdata));
}
char *DEX_trade(char *exchange,char *base,char *rel,int32_t dir,double price,double volume)
{
char url[512],postdata[1024];
sprintf(url,"%s/?",IGUANA_URL);
sprintf(postdata,"{\"agent\":\"InstantDEX\",\"method\":\"%s\",\"exchange\":\"%s\",\"base\":\"%s\",\"rel\":\"%s\",\"price\":%.8f,\"volume\":%.8f,\"dotrade\":1}",dir>0?"buy":"sell",exchange,base,rel,price,volume);
//printf("DEX_trade.(%s)\n",postdata);
return(bitcoind_RPC(0,"InstantDEX",url,0,dir>0?"buy":"sell",postdata));
}
char *DEX_withdraw(char *exchange,char *base,char *destaddr,double amount)
{
char url[512],postdata[1024];
sprintf(url,"%s/?",IGUANA_URL);
sprintf(postdata,"{\"agent\":\"InstantDEX\",\"method\":\"withdraw\",\"exchange\":\"%s\",\"destaddr\":\"%s\",\"amount\":%.8f}",exchange,destaddr,amount);
return(bitcoind_RPC(0,"InstantDEX",url,0,"withdraw",postdata));
}
char *iguana_walletpassphrase(char *passphrase,int32_t timeout)
{
char url[512],postdata[1024];
sprintf(url,"%s/coin=KMD&agent=bitcoinrpc&method=walletpassphrase?",IGUANA_URL);
sprintf(postdata,"[\"%s\", %d]",passphrase,timeout);
return(bitcoind_RPC(0,"",url,0,"walletpassphrase",postdata));
}
double bittrex_balance(char *base,char *coinaddr)
{
char *retstr; cJSON *retjson; double balance = 0.;
if ( (retstr= DEX_balance("bittrex",base,coinaddr)) != 0 )
{
if ( (retjson= cJSON_Parse(retstr)) != 0 )
{
balance = jdouble(retjson,"balance");
free_json(retjson);
}
free(retstr);
}
return(balance);
}
double dex_balance(char *base,char *coinaddr)
{
char *retstr; cJSON *retjson; double balance = 0.;
if ( (retstr= DEX_balance("DEX",base,coinaddr)) != 0 )
{
if ( (retjson= cJSON_Parse(retstr)) != 0 )
{
balance = jdouble(retjson,"balance");
free_json(retjson);
}
free(retstr);
}
return(balance);
}
int32_t komodo_baseid(char *base)
{
int32_t i;
for (i=0; i<sizeof(CURRENCIES)/sizeof(*CURRENCIES); i++)
if ( strcmp(base,CURRENCIES[i]) == 0 )
return(i);
return(-1);
}
cJSON *yahoo_allcurrencies()
{
char *retstr; cJSON *retjson = 0;
if ( (retstr= issue_curl("http://finance.yahoo.com/webservice/v1/symbols/allcurrencies/quote?format=json")) != 0 )
{
retjson = cJSON_Parse(retstr);
free(retstr);
}
return(retjson);
}
void _marketmaker_fiatupdate(int32_t baseid,double price)
{
PAXPRICES[baseid] = price * PAXPRICES[0];
printf("%.6f %s per USD, %.8f %s per KMD\n",price,CURRENCIES[baseid],PAXPRICES[baseid],CURRENCIES[baseid]);
}
uint32_t marketmaker_fiatupdate(cJSON *fiatjson)
{
int32_t i,n,baseid; cJSON *item,*array; double price; char *name; uint64_t mask = 0;
fiatjson = jobj(fiatjson,"list");
if ( fiatjson != 0 && (array= jarray(&n,fiatjson,"resources")) > 0 )
{
for (i=0; i<n; i++)
{
/*
"resource" : {
"classname" : "Quote",
"fields" : {
"name" : "USD/BRX",
"price" : "3.063200",
"symbol" : "BRX=X",
"ts" : "1487866204",
"type" : "currency",
"utctime" : "2017-02-23T16:10:04+0000",
"volume" : "0"
}
*/
item = jitem(array,i);
if ( (item= jobj(item,"resource")) != 0 )
item = jobj(item,"fields");
if ( item != 0 )
{
price = jdouble(item,"price");
if ( price > SMALLVAL && (name= jstr(item,"name")) != 0 && strncmp(name,"USD/",4) == 0 )
{
if ( (baseid= komodo_baseid(name+4)) >= 0 && baseid < 32 )
{
if ( ((1LL << baseid) & mask) == 0 )
{
_marketmaker_fiatupdate(baseid,price);
mask |= (1LL << baseid);
} else if ( fabs(price*PAXPRICES[0] - PAXPRICES[baseid]) > SMALLVAL )
printf("DUPLICATE PRICE? %s %.8f vs %.8f\n",name+4,price*PAXPRICES[0],PAXPRICES[baseid]);
}
}
}
}
}
printf("pax mask.%x\n",(uint32_t)mask);
return((uint32_t)mask);
}
void marketmaker_cancel(struct mmpending_order *ptr)
{
char *retstr; cJSON *retjson;
if ( ptr->pending != 0 && ptr->cancelstarted == 0 )
{
ptr->cancelstarted = (uint32_t)time(NULL);
if ( (retstr= DEX_cancelorder(ptr->exchange,ptr->orderid)) != 0 )
{
if ( (retjson= cJSON_Parse(retstr)) != 0 )
{
printf("cancel %s (%s/%s) %.8f vol %.8f dir.%d -> (%s)\n",ptr->exchange,ptr->base,ptr->rel,ptr->price,ptr->volume,ptr->dir,jprint(retjson,0));
free_json(retjson);
ptr->pending = 0;
ptr->canceled = (uint32_t)time(NULL);
}
free(retstr);
}
}
}
void marketmaker_queue(char *exchange,char *base,char *rel,int32_t dir,double price,double volume,cJSON *retjson)
{
struct mmpending_order *ptr; char *orderid;
//DEX_trade.({"success":true,"message":"","result":{"uuid":"d5faa9e4-660d-436f-a257-2c6a40442d8c"},"tag":"11271578410079391025"}
if ( is_cJSON_True(jobj(retjson,"success")) != 0 && jobj(retjson,"result") != 0 )
retjson = jobj(retjson,"result");
printf("QUEUE.%s %s/%s dir.%d %.8f %.6f (%s)\n",exchange,base,rel,dir,price,volume,jprint(retjson,0));
Pending_orders = realloc(Pending_orders,(1 + Num_Pending) * sizeof(*Pending_orders));
ptr = &Pending_orders[Num_Pending++];
memset(ptr,0,sizeof(*ptr));
ptr->price = price;
ptr->volume = volume;
ptr->dir = dir;
ptr->pending = (uint32_t)time(NULL);
strcpy(ptr->exchange,exchange);
strcpy(ptr->base,base);
strcpy(ptr->rel,rel);
if ( (orderid= jstr(retjson,"OrderUuid")) != 0 || (orderid= jstr(retjson,"uuid")) != 0 )
strcpy(ptr->orderid,orderid);
else strcpy(ptr->orderid,"0");
}
void marketmaker_pendingupdate(char *exchange,char *base,char *rel)
{
char *retstr; cJSON *retjson,*obj; int32_t i; struct mmpending_order *ptr;
for (i=0; i<Num_Pending; i++)
{
ptr = &Pending_orders[i];
if ( strcmp(exchange,ptr->exchange) != 0 || strcmp(base,ptr->base) != 0 || strcmp(rel,ptr->rel) != 0 )
continue;
if ( ptr->completed == 0 && (retstr= DEX_orderstatus(exchange,ptr->orderid)) != 0 )
{
//printf("%s status.(%s)\n",ptr->orderid,retstr);
if ( (retjson= cJSON_Parse(retstr)) != 0 )
{
obj = jobj(retjson,"result");
if ( is_cJSON_Array(obj) != 0 )
obj = jitem(retjson,0);
if ( jdouble(obj,"QuantityRemaining") == 0. || is_cJSON_True(jobj(obj,"IsOpen")) == 0 )
{
//{"Uuid":null,"OrderUuid":"e7b0789c-0c4e-413b-a768-3d5734d9cbe5","Exchange":"BTC-KMD","OrderType":"LIMIT_SELL","Quantity":877.77700000,"QuantityRemaining":462.50512234,"Limit":0.00011770,"CommissionPaid":0.00012219,"Price":0.04887750,"PricePerUnit":0.00011769,"Opened":"2017-02-20T13:16:22.29","Closed":null,"CancelInitiated":false,"ImmediateOrCancel":false,"IsConditional":false,"Condition":"NONE","ConditionTarget":null} printf("uuid.(%s) finished.(%s)\n",ptr->orderid,jprint(retjson,0));
ptr->completed = (uint32_t)time(NULL);
ptr->pending = 0;
}
free_json(retjson);
}
free(retstr);
}
}
}
void marketmaker_pendinginit(char *exchange,char *base,char *rel)
{
char *retstr,*orderid; cJSON *retjson,*array,*item; int32_t i,j,n,dir; struct mmpending_order *ptr;
if ( (retstr= DEX_openorders(exchange)) != 0 )
{
if ( (retjson= cJSON_Parse(retstr)) != 0 )
{
//printf("%s\n",jprint(retjson,0));
if ( is_cJSON_True(jobj(retjson,"success")) != 0 && (array= jarray(&n,retjson,"result")) != 0 )
{
for (i=0; i<n; i++)
{
item = jitem(array,i);
//printf("(%s)\n",jprint(item,0));
//{"success":true,"message":"","result":[{"Uuid":null,"OrderUuid":"81ad3e37-65d4-4fee-9c29-03b050f5192b","Exchange":"BTC-KMD","OrderType":"LIMIT_BUY","Quantity":885.19934578,"QuantityRemaining":885.19934578,"Limit":0.00011184,"CommissionPaid":0,"Price":0,"PricePerUnit":null,"Opened":"2017-02-19T19:14:02.94","Closed":null,"CancelInitiated":false,"ImmediateOrCancel":false,"IsConditional":false,"Condition":"NONE","ConditionTarget":null}],"tag":"10056789044100011414"}
if ( (orderid= jstr(item,"OrderUuid")) != 0 && is_cJSON_Null(jobj(item,"Closed")) != 0 && is_cJSON_False(jobj(item,"CancelInitiated")) != 0 )
{
for (j=0; j<Num_Pending; j++)
{
ptr = &Pending_orders[j];
if ( strcmp(exchange,ptr->exchange) != 0 || strcmp(base,ptr->base) != 0 || strcmp(rel,ptr->rel) != 0 )
continue;
if ( strcmp(ptr->orderid,orderid) == 0 )
{
ptr->pending = (uint32_t)time(NULL);
ptr->completed = 0;
printf("%s pending\n",orderid);
break;
}
}
if ( j == Num_Pending )
{
if ( jstr(item,"OrderType") != 0 )
{
if ( strcmp(jstr(item,"OrderType"),"LIMIT_BUY") == 0 )
dir = 1;
else if ( strcmp(jstr(item,"OrderType"),"LIMIT_SELL") == 0 )
dir = -1;
else dir = 0;
if ( dir != 0 )
marketmaker_queue(exchange,base,rel,dir,jdouble(item,"Limit"),jdouble(item,"QuantityRemaining"),item);
else printf("no dir (%s) (%s)\n",jprint(item,0),jstr(item,"OrderType"));
}
}
}
}
}
free_json(retjson);
}
free(retstr);
}
}
double marketmaker_filled(char *exchange,char *base,char *rel,double *buyvolp,double *sellvolp,double *pendingbidsp,double *pendingasksp)
{
double pricesum = 0.,volsum = 0.; struct mmpending_order *ptr; int32_t i;
*pendingbidsp = *pendingasksp = 0.;
for (i=0; i<Num_Pending; i++)
{
ptr = &Pending_orders[i];
if ( strcmp(exchange,ptr->exchange) != 0 || strcmp(base,ptr->base) != 0 || strcmp(rel,ptr->rel) != 0 )
continue;
if ( ptr->completed != 0 )
{
if ( ptr->reported == 0 )
{
if ( ptr->dir > 0 )
(*buyvolp) += ptr->volume;
else if ( ptr->dir < 0 )
(*sellvolp) += ptr->volume;
pricesum += ptr->volume * ptr->price;
volsum += ptr->volume;
ptr->reported = (uint32_t)time(NULL);
printf("REPORT dir.%d vol %.8f\n",ptr->dir,ptr->volume);
}
}
else if ( ptr->pending != 0 ) // alternative is error or cancelled
{
if ( ptr->dir > 0 )
(*pendingbidsp) += ptr->volume;
else if ( ptr->dir < 0 )
(*pendingasksp) += ptr->volume;
}
}
if ( volsum != 0. )
pricesum /= volsum;
return(pricesum);
}
int32_t marketmaker_prune(char *exchange,char *base,char *rel,int32_t polarity,double bid,double ask,double separation)
{
int32_t i,n = 0; struct mmpending_order *ptr;
for (i=0; i<Num_Pending; i++)
{
ptr = &Pending_orders[i];
if ( strcmp(exchange,ptr->exchange) != 0 || strcmp(base,ptr->base) != 0 || strcmp(rel,ptr->rel) != 0 )
continue;
if ( ptr->pending != 0 && ptr->cancelstarted == 0 )
{
if ( polarity != 0 )
{
if ( ((ptr->dir*polarity > 0 && ptr->price < bid-separation) || (ptr->dir*polarity < 0 && ptr->price > ask+separation)) )
{
printf("polarity.%d dir.%d price.%f bid.%f ask.%f\n",polarity,ptr->dir,ptr->price,bid,ask);
marketmaker_cancel(ptr), n++;
}
}
/*else
{,*prunebid=0,*pruneask=0; double lowbid=0.,highask=0.
if ( ptr->dir > 0 && (lowbid == 0. || ptr->price < lowbid) )
{
lowbid = ptr->price;
prunebid = ptr;
}
else if ( ptr->dir < 0 && (highask == 0. || ptr->price > highask) )
{
highask = ptr->price;
pruneask = ptr;
}
}*/
}
}
/*if ( polarity == 0 )
{
if ( prunebid != 0 && fabs(prunebid->price - bid) > separation )
marketmaker_cancel(prunebid), n++;
if ( pruneask != 0 && fabs(pruneask->price - ask) > separation )
marketmaker_cancel(pruneask), n++;
}*/
return(n);
}
void marketmaker_volumeset(double *bidincrp,double *askincrp,double incr,double buyvol,double pendingbids,double sellvol,double pendingasks,double maxexposure)
{
*bidincrp = *askincrp = incr;
//if ( pendingbids >= pendingasks+maxexposure )
// *bidincrp = 0.;
//else if ( pendingasks >= pendingbids+maxexposure )
// *askincrp = 0.;
if ( *bidincrp > 0. && pendingbids + *bidincrp > maxexposure )
*bidincrp = (maxexposure - *bidincrp);
if ( *askincrp > 0. && pendingasks + *askincrp > maxexposure )
*askincrp = (maxexposure - *askincrp);
if ( *bidincrp < 0. )
*bidincrp = 0.;
if ( *askincrp < 0. )
*askincrp = 0.;
}
int32_t marketmaker_spread(char *exchange,char *base,char *rel,double bid,double bidvol,double ask,double askvol,double separation)
{
int32_t nearflags[2],i,n = 0; struct mmpending_order *ptr; cJSON *retjson,*vals; char *retstr,postdata[1024],url[128]; double vol,spread_ratio;
memset(nearflags,0,sizeof(nearflags));
if ( strcmp("DEX",exchange) != 0 )
{
for (i=0; i<Num_Pending; i++)
{
ptr = &Pending_orders[i];
if ( strcmp(exchange,ptr->exchange) != 0 || strcmp(base,ptr->base) != 0 || strcmp(rel,ptr->rel) != 0 )
continue;
if ( ptr->pending != 0 && ptr->cancelstarted == 0 )
{
if ( bid > SMALLVAL && bidvol > SMALLVAL && ptr->dir > 0 && fabs(bid - ptr->price) < separation )
nearflags[0]++;
if ( ask > SMALLVAL && askvol > SMALLVAL && ptr->dir < 0 && fabs(ask - ptr->price) < separation )
nearflags[1]++;
}
}
}
//printf("spread.%s (%.8f %.6f) (%.8f %.6f)\n",exchange,bid,bidvol,ask,askvol);
if ( bid > SMALLVAL && bidvol > SMALLVAL && nearflags[0] == 0 )
{
if ( strcmp("DEX",exchange) == 0 && strcmp(base,"KMD") == 0 && strcmp(rel,"BTC") == 0 )
{
if ( ask > SMALLVAL && askvol > SMALLVAL )
{
/*li.profit = jdouble(vals,"profit");
li.refprice = jdouble(vals,"refprice");
li.bid = jdouble(vals,"bid");
li.ask = jdouble(vals,"ask");
if ( (li.minvol= jdouble(vals,"minvol")) <= 0. )
li.minvol = (strcmp("BTC",base) == 0) ? 0.0001 : 0.001;
if ( (li.maxvol= jdouble(vals,"maxvol")) < li.minvol )
li.maxvol = li.minvol;*/
//curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"tradebot\",\"method\":\"liquidity\",\"targetcoin\":\"MVP\",\"vals\":{\"rel\":\"USD\",\"bid\":0.09,\"ask\":0.11,\"maxvol\":100}}"
vals = cJSON_CreateObject();
jaddstr(vals,"rel","BTC");
jaddnum(vals,"bid",bid);
jaddnum(vals,"ask",ask);
vol = bidvol > askvol ? askvol : bidvol;
jaddnum(vals,"maxvol",vol);
jaddnum(vals,"minvol",vol*0.1 > 100 ? 100 : vol * 0.1);
sprintf(url,"%s/?",IGUANA_URL);
sprintf(postdata,"{\"agent\":\"tradebot\",\"method\":\"liquidity\",\"targetcoin\":\"%s\",\"vals\":%s}",base,jprint(vals,1));
printf("(%s)\n",postdata);
if ( (retstr= bitcoind_RPC(0,"tradebot",url,0,"liqudity",postdata)) != 0 )
{
//printf("(%s) -> (%s)\n",postdata,retstr);
free(retstr);
}
spread_ratio = .5 * ((ask - bid) / (bid + ask));
for (i=0; i<sizeof(CURRENCIES)/sizeof(*CURRENCIES); i++)
{
if ( PAXPRICES[i] > SMALLVAL )
{
vals = cJSON_CreateObject();
jaddstr(vals,"rel",CURRENCIES[i]);
jaddnum(vals,"bid",PAXPRICES[i] * (1. - spread_ratio));
jaddnum(vals,"ask",PAXPRICES[i] * (1. + spread_ratio));
jaddnum(vals,"maxvol",vol * PAXPRICES[i]);
jaddnum(vals,"minvol",MAX(1,(int32_t)(vol * 0.01 * PAXPRICES[i])));
sprintf(url,"%s/?",IGUANA_URL);
sprintf(postdata,"{\"agent\":\"tradebot\",\"method\":\"liquidity\",\"targetcoin\":\"%s\",\"vals\":%s}","KMD",jprint(vals,1));
if ( (retstr= bitcoind_RPC(0,"tradebot",url,0,"liqudity",postdata)) != 0 )
{
//printf("(%s) -> (%s)\n",postdata,retstr);
free(retstr);
}
}
break;
}
} else printf("unsupported ask only for DEX %s/%s\n",base,rel);
}
else if ( (retstr= DEX_trade(exchange,base,rel,1,bid,bidvol)) != 0 )
{
//printf("DEX_trade.(%s)\n",retstr);
if ( (retjson= cJSON_Parse(retstr)) != 0 )
{
marketmaker_queue(exchange,base,rel,1,bid,bidvol,retjson);
free_json(retjson);
}
free(retstr);
}
}
if ( ask > SMALLVAL && askvol > SMALLVAL && nearflags[1] == 0 && strcmp("DEX",exchange) != 0 )
{
if ( (retstr= DEX_trade(exchange,base,rel,-1,ask,askvol)) != 0 )
{
//printf("DEX_trade.(%s)\n",retstr);
if ( (retjson= cJSON_Parse(retstr)) != 0 )
{
marketmaker_queue(exchange,base,rel,-1,ask,askvol,retjson);
free_json(retjson);
}
free(retstr);
}
}
return(n);
}
void marketmaker(double minask,double maxbid,char *baseaddr,char *reladdr,double start_BASE,double start_REL,double profitmargin,double maxexposure,double ratioincr,char *exchange,char *name,char *base,char *rel)
{
static uint32_t counter;
cJSON *fiatjson; double bid,ask,start_DEXbase,start_DEXrel,USD_average=0.,DEX_base = 0.,DEX_rel = 0.,balance_base=0.,balance_rel=0.,mmbid,mmask,usdprice=0.,CMC_average=0.,aveprice,incr,pendingbids,pendingasks,buyvol,sellvol,bidincr,askincr,filledprice,avebid=0.,aveask=0.,val,changes[3],highbid=0.,lowask=0.,theoretical = 0.; uint32_t lasttime = 0;
incr = maxexposure * ratioincr;
buyvol = sellvol = 0.;
start_DEXbase = dex_balance(base,baseaddr);
start_DEXrel = dex_balance(rel,reladdr);
while ( 1 )
{
if ( time(NULL) > lasttime+300 )
{
if ( (val= get_theoretical(&avebid,&aveask,&highbid,&lowask,&CMC_average,changes,name,base,rel,&USD_average)) != 0. )
{
if ( theoretical == 0. )
{
theoretical = val;
incr /= theoretical;
maxexposure /= theoretical;
if ( incr > 2 )
{
incr = (int32_t)incr;
incr += 0.777;
}
} else theoretical = (theoretical + val) * 0.5;
if ( (counter++ % 12) == 0 )
{
if ( USD_average > SMALLVAL && CMC_average > SMALLVAL && theoretical > SMALLVAL )
{
usdprice = USD_average * (theoretical / CMC_average);
printf("USD %.4f <- (%.6f * (%.8f / %.8f))\n",usdprice,USD_average,theoretical,CMC_average);
PAXPRICES[0] = usdprice;
if ( (fiatjson= yahoo_allcurrencies()) != 0 )
{
marketmaker_fiatupdate(fiatjson);
free_json(fiatjson);
}
}
}
}
if ( strcmp(exchange,"bittrex") == 0 )
{
balance_base = bittrex_balance(base,"");
balance_rel = bittrex_balance(rel,"");
DEX_base = dex_balance(base,baseaddr);
DEX_rel = dex_balance(rel,reladdr);
} else printf("add support for %s balance\n",exchange);
lasttime = (uint32_t)time(NULL);
}
marketmaker_pendingupdate(exchange,base,rel);
if ( theoretical > SMALLVAL && avebid > SMALLVAL && aveask > SMALLVAL )
{
aveprice = (avebid + aveask) * 0.5;
// if order is filled, theoretical <- filled (theoretical + price)/2
if ( (filledprice= marketmaker_filled(exchange,base,rel,&buyvol,&sellvol,&pendingbids,&pendingasks)) != 0. )
theoretical = (theoretical + filledprice) * 0.5;
buyvol = sellvol = 0;
if ( (balance_base + DEX_base) < (start_BASE + start_DEXbase) )
sellvol += ((start_BASE + start_DEXbase) - (balance_base + DEX_base));
else buyvol += ((balance_base + DEX_base) - (start_BASE + start_DEXbase));
if ( (balance_rel + DEX_rel) < (start_REL + start_DEXrel) )
buyvol += ((start_REL + start_DEXrel) - (balance_rel + DEX_rel)) / theoretical;
else sellvol += ((balance_rel + DEX_rel) - (start_REL + start_DEXrel)) / theoretical;
mmbid = theoretical - theoretical*profitmargin;
mmask = theoretical + theoretical*profitmargin;
// if any existing order exceeds double margin distance, cancel
marketmaker_prune(exchange,base,rel,1,mmbid - theoretical*profitmargin,mmask + theoretical*profitmargin,0.);
// if new prices crosses existing order, cancel old order first
marketmaker_prune(exchange,base,rel,-1,mmbid,mmask,0.);
printf("(%.8f %.8f) ",mmbid,mmask);
if ( (1) )
{
if ( mmbid >= lowask || (maxbid > SMALLVAL && mmbid > maxbid) ) //mmbid < highbid ||
mmbid = 0.;
if ( mmask <= highbid || (minask > SMALLVAL && mmask < minask) ) // mmask > lowask ||
mmask = 0.;
}
marketmaker_volumeset(&bidincr,&askincr,incr,buyvol,pendingbids,sellvol,pendingasks,maxexposure);
printf("AVE.(%.8f %.8f) hbla %.8f %.8f bid %.8f ask %.8f theory %.8f buys.(%.6f %.6f) sells.(%.6f %.6f) incr.(%.6f %.6f) balances.(%.8f + %.8f, %.8f + %.8f) test %f\n",avebid,aveask,highbid,lowask,mmbid,mmask,theoretical,buyvol,pendingbids,sellvol,pendingasks,bidincr,askincr,balance_base,DEX_base,balance_rel,DEX_rel,(aveask - avebid)/aveprice);
if ( (aveask - avebid)/aveprice > 4*profitmargin )
bid = highbid * (1 - 4*profitmargin), ask = lowask * (1 + 4*profitmargin);
else bid = avebid - profitmargin*aveprice, ask = avebid + profitmargin*aveprice;
marketmaker_spread("DEX",base,rel,bid,incr,ask,incr,profitmargin*aveprice*0.5);
if ( (pendingbids + buyvol) > (pendingasks + sellvol) )
{
bidincr *= (double)(pendingasks + sellvol) / ((pendingbids + buyvol) + (pendingasks + sellvol));
if ( bidincr < 0.1*incr )
bidincr = 0.1*incr;
if ( bidincr > 1. )
bidincr = (int32_t)bidincr + 0.777;
}
if ( (pendingbids + buyvol) < (pendingasks + sellvol) )
{
askincr *= (double)(pendingbids + buyvol) / ((pendingbids + buyvol) + (pendingasks + sellvol));
if ( askincr < 0.1*incr )
askincr = 0.1*incr;
if ( askincr > 1. )
askincr = (int32_t)askincr + 0.777;
}
//printf("mmbid %.8f %.6f, mmask %.8f %.6f\n",mmbid,bidincr,mmask,askincr);
//marketmaker_spread(exchange,base,rel,mmbid,bidincr,mmask,askincr,profitmargin*aveprice*0.5);
sleep(6000);
}
}
}
int main(int argc, const char * argv[])
{
char *base,*rel,*name,*exchange,*apikey,*apisecret,*blocktrail;
double profitmargin,maxexposure,incrratio,start_rel,start_base,minask,maxbid;
cJSON *retjson,*addrjson; char *retstr,*baseaddr,*reladdr,*passphrase;
if ( argc > 1 && (retjson= cJSON_Parse(argv[1])) != 0 )
{
minask = jdouble(retjson,"minask");
maxbid = jdouble(retjson,"maxbid");
profitmargin = jdouble(retjson,"profitmargin");
maxexposure = jdouble(retjson,"maxexposure");
incrratio = jdouble(retjson,"lotratio");
start_base = jdouble(retjson,"start_base");
start_rel = jdouble(retjson,"start_rel");
passphrase = jstr(retjson,"passphrase");
apikey = jstr(retjson,"apikey");
apisecret = jstr(retjson,"apisecret");
base = jstr(retjson,"base");
name = jstr(retjson,"name");
rel = jstr(retjson,"rel");
blocktrail = jstr(retjson,"blocktrail");
exchange = jstr(retjson,"exchange");
if ( profitmargin < 0. || maxexposure <= 0. || incrratio <= 0. || apikey == 0 || apisecret == 0 || base == 0 || name == 0 || rel == 0 || exchange == 0 || blocktrail == 0 )
{
printf("illegal parameter (%s)\n",jprint(retjson,0));
exit(-1);
}
if ( (retstr= iguana_walletpassphrase(passphrase,999999)) != 0 )
{
printf("%s\n",DEX_apikeypair(exchange,apikey,apisecret));
printf("%s %s\n",base,DEX_balance(exchange,base,""));
printf("%s %s\n",rel,DEX_balance(exchange,rel,""));
marketmaker_pendinginit(exchange,base,rel);
if ( (addrjson= cJSON_Parse(retstr)) != 0 )
{
baseaddr = jstr(addrjson,base);
reladdr = jstr(addrjson,rel);
if ( baseaddr != 0 && reladdr != 0 )
{
printf("%s\n",DEX_amlp(blocktrail));
printf("%s.%s %s\n",base,baseaddr,DEX_balance("DEX",base,baseaddr));
printf("%s.%s %s\n",rel,reladdr,DEX_balance("DEX",rel,reladdr));
// initialize state using DEX_pendingorders, etc.
marketmaker(minask,maxbid,baseaddr,reladdr,start_base,start_rel,profitmargin,maxexposure,incrratio,exchange,name,base,rel);
}
free_json(addrjson);
} else printf("ERROR parsing.(%s)\n",retstr);
free(retstr);
}
free_json(retjson);
}
return 0;
}

13
iguana/iguana777.c

@ -233,7 +233,7 @@ uint32_t iguana_updatemetrics(struct supernet_info *myinfo,struct iguana_info *c
{
expand_ipbits(ipaddr,(uint32_t)addr->ipbits);
fprintf(fp,"%s\n",ipaddr);
if ( 0 && addr->msgcounts.verack == 0 )
if ( (0) && addr->msgcounts.verack == 0 )
{
printf("iguana_sendblockreq (%s) addrind.%d hasn't verack'ed yet\n",addr->ipaddr,addr->addrind);
iguana_send_version(coin,addr,coin->myservices);
@ -274,7 +274,7 @@ void iguana_emitQ(struct iguana_info *coin,struct iguana_bundle *bp)
void iguana_bundleQ(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_bundle *bp,int32_t timelimit)
{
struct iguana_helper *ptr; struct iguana_bundle *tmp; int32_t i,n = 0;
if ( 0 && bp->queued == 0 && bp->emitfinish <= 1 && iguana_bundleready(myinfo,coin,bp,0) == bp->n )
if ( (0) && bp->queued == 0 && bp->emitfinish <= 1 && iguana_bundleready(myinfo,coin,bp,0) == bp->n )
printf("bundle.[%d] is ready\n",bp->hdrsi);
if ( bp->queued != 0 )
return;
@ -637,7 +637,7 @@ int32_t iguana_coin_mainiter(struct supernet_info *myinfo,struct iguana_info *co
isRT *= (coin->RTheight > 0);
if ( coin->peers != 0 )
*numpeersp += coin->peers->numranked;
if ( 0 && (rand() % 10) == 0 )
if ( (0) && (rand() % 10) == 0 )
printf("%s main.%u vs %u, svs %u %d vs %d\n",coin->symbol,(uint32_t)time(NULL),coin->startutc+10,coin->spendvectorsaved ,coin->blocks.hwmchain.height/coin->chain->bundlesize,(coin->longestchain-coin->minconfirms)/coin->chain->bundlesize);
if ( time(NULL) > coin->startutc+60 )
{
@ -682,7 +682,7 @@ int32_t iguana_coin_mainiter(struct supernet_info *myinfo,struct iguana_info *co
}
if ( (bp= coin->current) != 0 && coin->stucktime != 0 && coin->isRT == 0 && coin->RTheight == 0 && (time(NULL) - coin->stucktime) > coin->MAXSTUCKTIME )
{
if ( 0 )
if ( (0) )
{
printf("%s is stuck too long, restarting due to %d\n",coin->symbol,bp->hdrsi);
if ( coin->started != 0 )
@ -885,10 +885,13 @@ void iguana_coinloop(void *arg)
coins++;
coin = coins[0];
if ( (coin->notarychain= iguana_isnotarychain(coin->symbol)) >= 0 )
{
coin->VALIDATENODE = 0;
coin->DEXEXPLORER = myinfo->DEXEXPLORER;
}
//if ( coin->FULLNODE > 0 )
// coin->notarychain = -1;
printf("begin coinloop[%d] %s notarychain.%d\n",n,coin->symbol,coin->notarychain);
printf("begin coinloop[%d] %s notarychain.%d DEXEXPLORER.%d\n",n,coin->symbol,coin->notarychain,coin->DEXEXPLORER);
memset(zero.bytes,0,sizeof(zero));
while ( 1 )
{

65
iguana/iguana777.h

@ -21,13 +21,17 @@
#define iguana777_net_h
#if defined(_WIN32) || defined(_WIN64)
#ifndef WIN32
#define WIN32
#endif
#endif
#if (defined(_WIN32) || defined(__WIN32__)) && \
!defined(WIN32) && !defined(__SYMBIAN32__)
#ifndef WIN32
#define WIN32
#endif
#endif
#ifdef WIN32
#define __MINGW
@ -59,12 +63,14 @@
#include "../crypto777/nanosrc/nn.h"
#include "../crypto777/nanosrc/bus.h"
#include "../crypto777/nanosrc/pubsub.h"
#include "../crypto777/nanosrc/pipeline.h"
#include "../crypto777/nanosrc/reqrep.h"
#include "../crypto777/nanosrc/tcp.h"
#else
#include "/usr/local/include/nanomsg/nn.h"
#include "/usr/local/include/nanomsg/bus.h"
#include "/usr/local/include/nanomsg/pubsub.h"
#include "/usr/local/include/nanomsg/pipeline.h"
#include "/usr/local/include/nanomsg/reqrep.h"
#include "/usr/local/include/nanomsg/tcp.h"
#endif
@ -88,6 +94,26 @@ struct supernet_address
char NXTADDR[32],BTC[64],BTCD[64];
};
struct smartaddress
{
bits256 privkey,pubkey;
uint8_t pubkey33[33],rmd160[20];
};
struct pending_trade { UT_hash_handle hh; double basevolume,relvolume,dir; char base[32],rel[32]; };
#define PSOCK_IDLETIMEOUT 600
struct psock { uint32_t lasttime; int32_t pullsock,pubsock; uint16_t pushport,subport; };
#define JUMBLR_DEPOSITPREFIX "deposit "
struct jumblr_item
{
UT_hash_handle hh;
int64_t amount,fee,txfee;
uint32_t spent,pad;
char opid[64],src[128],dest[128],status;
};
struct liquidity_info
{
char base[16],rel[16],exchange[16];
@ -100,9 +126,9 @@ struct message_info { int32_t msgcount; bits256 refhash,msghashes[64]; uint32_t
struct supernet_info
{
struct supernet_address myaddr;
bits256 persistent_priv,privkey;
bits256 persistent_priv,privkey,jumblr_pubkey,jumblr_depositkey;
uint8_t persistent_pubkey33[33];
char ipaddr[64],NXTAPIURL[512],secret[4096],password[4096],rpcsymbol[64],handle[1024],permanentfile[1024];
char ipaddr[64],NXTAPIURL[512],secret[4096],password[4096],rpcsymbol[64],handle[1024],permanentfile[1024],jumblr_passphrase[1024];
char *decryptstr;
void (*liquidity_command)(struct supernet_info *myinfo,char *base,bits256 hash,cJSON *vals);
double (*liquidity_active)(struct supernet_info *myinfo,double *refpricep,char *exchange,char *base,char *rel,double volume);
@ -110,6 +136,7 @@ struct supernet_info
uint32_t expiration,dirty,DEXactive,DEXpoll,totalcoins,nanoinit,lastdexrequestid,dexcrcs[1024];
uint16_t argport,rpcport;
struct basilisk_info basilisks;
struct jumblr_item *jumblrs;
struct exchange_info *tradingexchanges[SUPERNET_MAXEXCHANGES]; int32_t numexchanges;
struct iguana_waccount *wallet;
struct iguana_info *allcoins; int32_t allcoins_being_added,allcoins_numvirts;
@ -125,19 +152,45 @@ struct supernet_info
struct delayedPoW_info dPoW;
struct basilisk_spend *spends; int32_t numspends;
char bindaddr[64];
// fadedreamz
char blocktrail_apikey[256];
struct peggy_info *PEGS;
void *PAXDATA;
struct liquidity_info linfos[512];
struct liquidity_info linfos[512]; cJSON *liquidity_currencies; struct pending_trade *trades; portable_mutex_t pending_mutex;
struct komodo_notaries NOTARY;
char seedipaddr[64]; uint32_t dpowipbits[128]; int32_t numdpowipbits; portable_mutex_t notarymutex,dpowmutex;
char dexseed_ipaddrs[4][64]; uint32_t dexipbits[128]; int32_t numdexipbits; portable_mutex_t dexmutex;
char dexseed_ipaddrs[2][64]; uint32_t dexipbits[128]; int32_t numdexipbits; portable_mutex_t dexmutex;
// compatibility
bits256 pangea_category,instantdex_category;
uint8_t logs[256],exps[510];
struct message_info msgids[8192];
double *svmfeatures;
uint8_t notaries[64][33]; int32_t numnotaries;
uint16_t psockport,numpsocks; struct psock *PSOCKS; portable_mutex_t psockmutex;
uint8_t notaries[64][33]; int32_t numnotaries,DEXEXPLORER;
FILE *swapsfp;
struct smartaddress smartaddrs[64]; int32_t numsmartaddrs,cancelrefresh;
};
struct basilisk_swapmessage
{
bits256 srchash,desthash;
uint32_t crc32,msgbits,quoteid,datalen;
uint8_t *data;
};
struct basilisk_swap
{
struct supernet_info *myinfoptr; struct iguana_info *bobcoin,*alicecoin;
void (*balancingtrade)(struct supernet_info *myinfo,struct basilisk_swap *swap,int32_t iambob);
int32_t subsock,pushsock,connected; uint32_t lasttime;
FILE *fp;
bits256 persistent_privkey,persistent_pubkey;
struct basilisk_swapinfo I;
struct basilisk_rawtx bobdeposit,bobpayment,alicepayment,myfee,otherfee,aliceclaim,alicespend,bobreclaim,bobspend,bobrefund,alicereclaim;
bits256 privkeys[INSTANTDEX_DECKSIZE];
struct basilisk_swapmessage *messages; int32_t nummessages;
uint64_t otherdeck[INSTANTDEX_DECKSIZE][2],deck[INSTANTDEX_DECKSIZE][2];
uint8_t persistent_pubkey33[33],pad[15],verifybuf[65536];
};
#include "../includes/iguana_funcs.h"

4
iguana/iguana_accept.c

@ -369,7 +369,7 @@ int32_t iguana_peerhdrrequest(struct supernet_info *myinfo,struct iguana_info *c
} else printf("cant find block at ht.%d\n",height+i);
}
}
if ( 0 && flag != 0 && strcmp("BTCD",coin->symbol) != 0 )
if ( (0) && flag != 0 && strcmp("BTCD",coin->symbol) != 0 )
retval = iguana_queue_send(addr,0,serialized,"headers",len);
//printf("hdrs request retval.%d len.%d\n",retval,len);
} //else printf("couldnt find header\n");
@ -446,4 +446,4 @@ int32_t iguana_peeraddrrequest(struct iguana_info *coin,struct iguana_peer *addr
if ( x == 0 )
return(-1);
return(sendlen);
}
}

47
iguana/iguana_bitmap.c

@ -401,8 +401,8 @@ void disp_yval(register int32_t color,register float yval,register uint32_t *bit
//if ( pixelwt(color) > pixelwt(bitmap[y*rowwidth + x]) )
bitmap[y*rowwidth + x] = pixel_blend(bitmap[y*rowwidth + x],color);
return;
if ( is_primary_color(color) != 0 || (is_primary_color(bitmap[y*rowwidth+x]) == 0 && pixelwt(color) > pixelwt(bitmap[y*rowwidth + x])) )
bitmap[y*rowwidth + x] = color;
//if ( is_primary_color(color) != 0 || (is_primary_color(bitmap[y*rowwidth+x]) == 0 && pixelwt(color) > pixelwt(bitmap[y*rowwidth + x])) )
// bitmap[y*rowwidth + x] = color;
}
void disp_yvalsum(register int32_t color,register float yval,register uint32_t *bitmap,register int32_t x,register int32_t rowwidth,register int32_t height)
@ -509,7 +509,7 @@ void output_line(int32_t calclogflag,double ave,float *buf,int32_t n,int32_t col
double src[1024],dest[1024]; int32_t i;
memset(src,0,sizeof(src));
memset(dest,0,sizeof(dest));
if ( 1 )
if ( (1) )
{
for (i=0; i<1024; i++)
src[1023-i] = dest[1023-i] = buf[i];
@ -1085,7 +1085,7 @@ void iguana_bitmapbundle(struct iguana_info *coin,uint8_t *rect,int32_t rowwidth
struct iguana_bitmap *iguana_bitmapfind(char *name)
{
struct iguana_info *coin; int32_t width,height,n,hdrsi,x,y;
struct iguana_info *coin; int32_t width=1,height=1,n,hdrsi,x,y;
if ( ((coin= iguana_coinfind(name)) != 0 || (coin= iguana_coinfind("BTCD")) != 0) && coin->screen != 0 )
{
strcpy(coin->screen->name,coin->symbol);
@ -1162,42 +1162,3 @@ void iguana_bitmap(char *space,int32_t max,char *name)
}
}
#include "../includes/iguana_apidefs.h"
#include "../includes/iguana_apideclares.h"
STRING_AND_TWOINTS(mouse,change,name,x,y)
{
printf("mouse (%s) x.%d y.%d\n",name,x,y);
return(clonestr("{\"result\":\"changed\"}"));
}
STRING_ARG(mouse,leave,name)
{
printf("mouse (%s) leave\n",name);
return(clonestr("{\"result\":\"left\"}"));
}
STRING_AND_TWOINTS(mouse,click,name,x,y)
{
printf("mouse (%s) x.%d y.%d click\n",name,x,y);
return(clonestr("{\"result\":\"click\"}"));
}
STRING_AND_INT(keyboard,key,name,c)
{
printf(" KEY.(%s) c.%d (%c)\n",name,c,c);
return(clonestr("{\"result\":\"key\"}"));
}
STRING_AND_TWOINTS(mouse,image,name,x,y)
{
printf("mouse CREATE (%s) x.%d y.%d\n",name,x,y);
return(clonestr("{\"result\":\"opened\"}"));
}
STRING_ARG(mouse,close,name)
{
printf("mouse CLOSE (%s)\n",name);
return(clonestr("{\"result\":\"closed\"}"));
}
#include "../includes/iguana_apiundefs.h"

8
iguana/iguana_blocks.c

@ -411,7 +411,7 @@ double PoW_from_compact(uint32_t nBits,uint8_t unitval) // NOT consensus safe, b
nbytes = (nBits >> 24) & 0xFF;
nbits = (8 * (nbytes - 3));
PoW = (nBits & 0xFFFFFF);
if ( 0 && nbytes > unitval )
if ( (0) && nbytes > unitval )
{
printf("illegal nBits.%x unitval.%02x\n",nBits,unitval);
return(0.);
@ -590,7 +590,7 @@ struct iguana_block *_iguana_chainlink(struct supernet_info *myinfo,struct iguan
if ( bits256_nonz(prev->RO.hash2) == 0 || (prev->valid == 0 && iguana_blockvalidate(myinfo,coin,&valid,prev,0) < 0) )
{
char str[65];
if ( 0 && bits256_nonz(prev->RO.hash2) != 0 )
if ( (0) && bits256_nonz(prev->RO.hash2) != 0 )
printf("(%s) notready v.%d m.%d h.%d\n",bits256_str(str,prev->RO.hash2),prev->valid,prev->mainchain,prev->height);
return(0);
} else prev->valid = 1;
@ -645,7 +645,7 @@ struct iguana_block *_iguana_chainlink(struct supernet_info *myinfo,struct iguan
else str2[0] = 0;
if ( coin->blocks.maxblocks > coin->longestchain )
coin->longestchain = coin->blocks.maxblocks;
if ( 0 && (block->height % coin->chain->bundlesize) == 0 )
if ( (0) && (block->height % coin->chain->bundlesize) == 0 )
{
printf("EXTENDMAIN %s %d <- (%s) n.%u max.%u PoW %f numtx.%d valid.%d\n",str,block->height,str2,hwmchain->height+1,coin->blocks.maxblocks,block->PoW,block->RO.txn_count,block->valid);
//iguana_walkchain(coin);
@ -724,7 +724,7 @@ struct iguana_block *_iguana_chainlink(struct supernet_info *myinfo,struct iguan
iguana_RTnewblock(myinfo,coin,block);
block->hdrsi = hdrsi;
block->bundlei = bundlei;
if ( 0 && (bp= coin->bundles[hdrsi]) != 0 )
if ( (0) && (bp= coin->bundles[hdrsi]) != 0 )
{
if ( bp->blocks[bundlei] != block || bits256_cmp(bp->hashes[bundlei],block->RO.hash2) != 0 )
printf("new hwm [%d:%d] mismatched bundle block\n",hdrsi,bundlei);

37
iguana/iguana_bundles.c

@ -21,6 +21,7 @@ static uint16_t iguana_primes[] = { 65353, 65357, 65371, 65381, 65393, 65407, 65
struct iguana_bloominds iguana_calcbloom(bits256 hash2)
{
int32_t i,j,k; struct iguana_bloominds bit;
memset(&bit,0,sizeof(bit));
k = (int32_t)(sizeof(bit)/sizeof(uint16_t)) - 1;
j = 15;
for (i=0; i<sizeof(bit)/sizeof(uint16_t); i++,j--,k--)
@ -158,7 +159,7 @@ int32_t iguana_hash2set(struct iguana_info *coin,char *debugstr,struct iguana_bu
{
// printf("bloomset (%s) -> [%d:%d]\n",bits256_str(str,newhash2),bp->hdrsi,bundlei);
iguana_bloomset(coin,&bp->bloom,0,bit);
if ( 0 )
if ( (0) )
{
int32_t i;
if ( iguana_bloomfind(coin,&bp->bloom,0,bit) < 0 )
@ -245,7 +246,7 @@ int32_t iguana_bundlehash2add(struct iguana_info *coin,struct iguana_block **blo
return(-1);
}
}
if ( 0 && bits256_nonz(bp->hashes[bundlei]) != 0 && bits256_cmp(bp->hashes[bundlei],block->RO.hash2) != 0 )
if ( (0) && bits256_nonz(bp->hashes[bundlei]) != 0 && bits256_cmp(bp->hashes[bundlei],block->RO.hash2) != 0 )
{
//char str[65],str2[65];
//printf("B bp.[%d]->hashes[%d] mismatch %s != %s%s\n",bp->hdrsi,bundlei,bits256_str(str,bp->hashes[bundlei]),bits256_str(str2,block->RO.hash2),block->mainchain?".main":"");
@ -461,7 +462,7 @@ char *iguana_bundleaddrs(struct iguana_info *coin,int32_t hdrsi)
uint8_t *PKbits; struct iguana_pkhash *P; uint32_t pkind,numpkinds; struct iguana_bundle *bp; struct iguana_ramchain *ramchain; struct iguana_ramchaindata *rdata; cJSON *retjson; char rmdstr[41];
if ( (bp= coin->bundles[hdrsi]) != 0 )
{
if ( 0 && coin->RTramchain_busy != 0 )
if ( (0) && coin->RTramchain_busy != 0 )
{
printf("iguana_bundleaddrs: unexpected access when RTramchain_busy\n");
return(0);
@ -520,7 +521,7 @@ void iguana_bundlepurgefiles(struct iguana_info *coin,struct iguana_bundle *bp)
sprintf(fname,"%s/%s/%d/%d",GLOBAL_TMPDIR,coin->symbol,subdir,bp->bundleheight), OS_remove_directory(fname);
//printf("purged hdrsi.[%d] subdir.%d lag.%ld\n",bp->hdrsi,subdir,time(NULL) - bp->emitfinish);
bp->purgetime = (uint32_t)time(NULL);
if ( 0 )
if ( (0) )
{
for (i=subdir*IGUANA_SUBDIRDIVISOR; i<(subdir+1)*IGUANA_SUBDIRDIVISOR; i++)
{
@ -692,14 +693,14 @@ int32_t iguana_bundleissuemissing(struct supernet_info *myinfo,struct iguana_inf
queue_enqueue("missing",&coin->priorityQ,&req->DL);
bp->issued[i] = 1;
n++;
if ( 0 && bp == coin->current )
if ( (0) && bp == coin->current )
printf("%s issuemissing.[%d:%d]\n",bits256_str(str,hash2),bp->hdrsi,i);
} //else printf("[z%d] ",i);
} //else printf("%d ",now - (bp->issued[i]+lag));
}
if ( firsti >= 0 )//&& bp == coin->current )
{
if ( 0 && bp == coin->current )
if ( (0) && bp == coin->current )
printf("%s [%d] first missing.%d of %d\n",bits256_str(str,hash2),bp->hdrsi,firsti,nonz);
iguana_bundleblock(coin,&hash2,bp,firsti);
if ( bits256_nonz(hash2) != 0 )
@ -773,7 +774,7 @@ int32_t iguana_bundleready(struct supernet_info *myinfo,struct iguana_info *coin
int32_t i,ready,valid; char fname[1024]; struct iguana_block *block; int32_t sum[0x100],counts[0x100]; struct iguana_blockRO *B; struct iguana_bundle *nextbp; void *ptr; long filesize; struct iguana_ramchain R; bits256 prevhash2;
memset(sum,0,sizeof(sum));
memset(counts,0,sizeof(counts));
if ( 0 && bp->queued == 0 )
if ( (0) && bp->queued == 0 )
{
for (i=ready=0; i<bp->n; i++)
if ( (block= bp->blocks[i]) == 0 )
@ -825,7 +826,7 @@ int32_t iguana_bundleready(struct supernet_info *myinfo,struct iguana_info *coin
char str[65];
if ( requiredflag != 0 )
printf(">>>>>>> block contents error at ht.%d [%d:%d]\n",bp->bundleheight+i,bp->hdrsi,i);
if ( 0 && bits256_nonz(block->RO.hash2) != 0 )
if ( (0) && bits256_nonz(block->RO.hash2) != 0 )
printf("patch.%d and reissue prev.%s %d\n",bp->bundleheight+i,bits256_str(str,block->RO.prev_block),i);
iguana_blockunmark(coin,block,bp,i,1);
}
@ -845,11 +846,11 @@ int32_t iguana_bundleready(struct supernet_info *myinfo,struct iguana_info *coin
}
fclose(fp);
}
else if ( 0 )
else if ( (0) )
//#endif
{
iguana_blockunmark(coin,block,bp,i,1);
if ( 0 && requiredflag != 0 )
if ( (0) && requiredflag != 0 )
printf("not ready altpath.(%d %d %d %d %d) [%d:%d]\n",block->txvalid == 0,block->fpipbits == 0 ,block->fpos < 0,(bp->bundleheight+i > 0 && bits256_nonz(block->RO.prev_block) == 0),iguana_blockvalidate(myinfo,coin,&valid,block,1) < 0,bp->hdrsi,i);
}
else
@ -877,7 +878,7 @@ int32_t iguana_bundleready(struct supernet_info *myinfo,struct iguana_info *coin
int32_t iguana_bundlehdr(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_bundle *bp,int32_t starti)
{
int32_t i,dist,counter=0; char str[65];
if ( 0 && bp->isRT == 0 && (bp->hdrsi == coin->bundlescount-1 || bp == coin->current) )
if ( (0) && bp->isRT == 0 && (bp->hdrsi == coin->bundlescount-1 || bp == coin->current) )
printf("hdr ITERATE.%d bundle.%d vs %d: h.%d n.%d r.%d s.%d c.%d finished.%d spec.%p[%d]\n",bp->hdrsi,bp->bundleheight,coin->longestchain-coin->chain->bundlesize,bp->numhashes,bp->n,bp->numrecv,bp->numsaved,bp->numcached,bp->emitfinish,bp->speculative,bp->numspec);
dist = 30 + (coin->current != 0 ? bp->hdrsi - coin->current->hdrsi : 0);
if ( bp == coin->current )
@ -976,7 +977,7 @@ int64_t iguana_bundlecalcs(struct supernet_info *myinfo,struct iguana_info *coin
datasize += block->RO.recvlen;
}
}
else if ( 0 && bits256_nonz(block->RO.hash2) != 0 && bits256_nonz(bp->hashes[bundlei]) != 0 )
else if ( (0) && bits256_nonz(block->RO.hash2) != 0 && bits256_nonz(bp->hashes[bundlei]) != 0 )
{
printf("hash mismatch [%d:%d]\n",bp->hdrsi,bundlei);
iguana_blockunmark(coin,block,bp,bundlei,1);
@ -996,7 +997,7 @@ int64_t iguana_bundlecalcs(struct supernet_info *myinfo,struct iguana_info *coin
}
}
bp->numcached = numcached;
if ( 0 && bp->numcached != numsaved )
if ( (0) && bp->numcached != numsaved )
printf("[%d] emit.%u ramchain.%p numcached.%d vs numsaved.%d numhashes.%d\n",bp->hdrsi,bp->emitfinish,bp->ramchain.H.data,bp->numcached,numsaved,numhashes);
bp->datasize = datasize;
bp->numhashes = numhashes;
@ -1126,7 +1127,7 @@ int32_t iguana_bundleiters(struct supernet_info *myinfo,struct iguana_info *coin
iguana_bundlecalcs(myinfo,coin,bp,lag);
if ( coin->blockdepth == 0 && coin->blockdepth == 0 && bp->hdrsi == coin->bundlescount-1 )
iguana_autoextend(myinfo,coin,bp);
if ( 0 && bp->hdrsi == 0 )
if ( (0) && bp->hdrsi == 0 )
printf("ITER utxo.%u now.%u spec.%-4d bundle.%-4d h.%-4d r.%-4d s.%-4d F.%d T.%d issued.%d mb.%d/%d\n",bp->utxofinish,(uint32_t)time(NULL),bp->numspec,bp->bundleheight/coin->chain->bundlesize,bp->numhashes,bp->numrecv,bp->numsaved,bp->emitfinish,timelimit,counter,coin->MAXBUNDLES,coin->bundlescount);
bp->nexttime = (uint32_t)time(NULL) + ((bp->hdrsi > starti) ? 0 : -2);
if ( bp->hdrsi == coin->bundlescount-1 || (bp->numhashes < bp->n && bp->bundleheight < coin->longestchain-coin->chain->bundlesize) )
@ -1144,10 +1145,10 @@ int32_t iguana_bundleiters(struct supernet_info *myinfo,struct iguana_info *coin
{
max = bp->n;
counter = iguana_bundleissuemissing(myinfo,coin,bp,1,3.);
if ( 0 && counter > 0 )
if ( (0) && counter > 0 )
printf("starti.%d range.%d now.%u spec.%-4d bundle.%-4d h.%-4d r.%-4d s.%-4d F.%d T.%d issued.%d mb.%d/%d\n",starti,range,(uint32_t)time(NULL),bp->numspec,bp->bundleheight/coin->chain->bundlesize,bp->numhashes,bp->numrecv,bp->numsaved,bp->emitfinish,timelimit,counter,coin->MAXBUNDLES,coin->bundlescount);
} else bp->nexttime++;
if ( 0 && bp->emitfinish <= 1 )
if ( (0) && bp->emitfinish <= 1 )
iguana_bundleQ(myinfo,coin,bp,1000);
else
{
@ -1417,7 +1418,7 @@ void iguana_bundlestats(struct supernet_info *myinfo,struct iguana_info *coin,ch
//sortbuf[m*2] = bp->metric;
//sortbuf[m*2 + 1] = i;
m++;
if ( 0 && lastpending == 0 )
if ( (0) && lastpending == 0 )
printf("%d ",bp->numsaved);
}
}
@ -1552,7 +1553,7 @@ void iguana_bundlestats(struct supernet_info *myinfo,struct iguana_info *coin,ch
myallocated(0,0);
coin->lastdisp = (uint32_t)time(NULL);
}
if ( 0 && (bp= coin->current) != 0 && coin->RTheight >= bp->bundleheight && coin->RTheight < bp->bundleheight+bp->n )
if ( (0) && (bp= coin->current) != 0 && coin->RTheight >= bp->bundleheight && coin->RTheight < bp->bundleheight+bp->n )
{
for (i=coin->RTheight-bp->bundleheight; i<bp->n; i++)
{

17
iguana/iguana_chains.c

@ -126,12 +126,12 @@ int32_t blockhash_scrypt(uint8_t *blockhashp,uint8_t *serialized,int32_t len)
blockhashfunc iguana_hashalgo(char *hashalgostr)
{
return(blockhash_sha256); // all coins seem to use this for genesis
if ( hashalgostr == 0 || hashalgostr[0] == 0 || strcmp(hashalgostr,"sha256") == 0 )
/*if ( hashalgostr == 0 || hashalgostr[0] == 0 || strcmp(hashalgostr,"sha256") == 0 )
return(blockhash_sha256);
else if ( strcmp(hashalgostr,"scrypt") == 0 )
return(blockhash_scrypt);
else printf("unsupported blockhash algo.(%s)\n",hashalgostr);
return(0);
return(0);*/
}
bits256 iguana_calcblockhash(char *symbol,int32_t (*hashalgo)(uint8_t *blockhashp,uint8_t *serialized,int32_t len),uint8_t *serialized,int32_t len)
@ -189,8 +189,8 @@ bits256 iguana_chaingenesis(struct supernet_info *myinfo,char *symbol,uint8_t zc
char *parse_conf_line(char *line,char *field)
{
line += strlen(field);
for (; *line!='='&&*line!=0; line++)
break;
while ( (*line) != '=' && (*line) != 0 )
line++;
if ( *line == 0 )
return(0);
if ( *line == '=' )
@ -232,7 +232,12 @@ void set_coinconfname(char *fname,char *coinstr,char *userhome,char *coindir,cha
sprintf(confname,"%s.conf",buf);
}
printf("userhome.(%s) coindir.(%s) confname.(%s)\n",userhome,coindir,confname);
sprintf(fname,"%s/%s/%s",userhome,coindir,confname);
#ifdef WIN32
if ( userhome == 0 || userhome[0] == 0 )
sprintf(fname,"%s/%s",coindir,confname);
else
#endif
sprintf(fname,"%s/%s/%s",userhome,coindir,confname);
}
uint16_t extract_userpass(char *serverport,char *userpass,char *coinstr,char *userhome,char *coindir,char *confname)
@ -486,7 +491,7 @@ void iguana_chaininit(struct supernet_info *myinfo,struct iguana_chain *chain,in
if ( strcmp(chain->symbol,"BTC") == 0 )
{
chain->unitval = 0x1d;
chain->txfee = 10000;
chain->txfee = 50000;
chain->havecltv = 1;
}
else chain->txfee = 10000;

28
iguana/iguana_exchanges.c

@ -995,6 +995,7 @@ char *exchanges777_Qrequest(struct exchange_info *exchange,int32_t func,char *ba
safecopy(req->rel,rel,sizeof(req->rel));
req->retstrp = calloc(1,sizeof(void *));
req->orderid = orderid;
req->argjson = jduplicate(argjson);
//printf("Qrequest\n");
return(exchanges777_submit(exchange,req,func,maxseconds));
}
@ -1129,7 +1130,7 @@ struct exchange_info *exchanges777_info(char *exchangestr,int32_t sleepflag,cJSO
sleep(sleepflag);
}
}
if ( 0 && exchange != 0 )
if ( (0) && exchange != 0 )
printf("found exchange.(%s) %p %p %p\n",exchange->name,exchange->issue.supports,exchange->issue.price,exchange->issue.allpairs);
return(exchange);
}
@ -1175,6 +1176,7 @@ cJSON *iguana_pricesarray(struct supernet_info *myinfo,char *exchange,char *base
#include "../includes/iguana_apidefs.h"
#include "../includes/iguana_apideclares.h"
#include "../includes/iguana_apideclares2.h"
THREE_STRINGS_AND_THREE_INTS(InstantDEX,orderbook,exchange,base,rel,depth,allfields,ignore)
{
@ -1244,26 +1246,42 @@ TWO_STRINGS(InstantDEX,balance,exchange,base)
TWO_STRINGS(InstantDEX,orderstatus,exchange,orderid)
{
struct exchange_info *ptr;
struct exchange_info *ptr; cJSON *argjson; char *retstr; uint64_t num = 0;
if ( remoteaddr == 0 )
{
if ( myinfo->expiration == 0 )
return(clonestr("{\"error\":\"need to unlock wallet\"}"));
if ( (ptr= exchanges777_info(exchange,1,json,remoteaddr)) != 0 )
return(exchanges777_Qrequest(ptr,'P',0,0,juint(json,"maxseconds"),calc_nxt64bits(orderid),0,0,json));
{
argjson = cJSON_CreateObject();
jaddstr(argjson,"uuid",orderid);
if ( is_decimalstr(orderid) != 0 )
num = calc_nxt64bits(orderid);
retstr = exchanges777_Qrequest(ptr,'P',0,0,juint(json,"maxseconds"),num,0,0,argjson);
free_json(argjson);
return(retstr);
}
else return(clonestr("{\"error\":\"cant find or create exchange\"}"));
} else return(clonestr("{\"error\":\"no remote for this API\"}"));
}
TWO_STRINGS(InstantDEX,cancelorder,exchange,orderid)
{
struct exchange_info *ptr;
struct exchange_info *ptr; cJSON *argjson; char *retstr; uint64_t num = 0;
if ( remoteaddr == 0 )
{
if ( myinfo->expiration == 0 )
return(clonestr("{\"error\":\"need to unlock wallet\"}"));
if ( (ptr= exchanges777_info(exchange,1,json,remoteaddr)) != 0 )
return(exchanges777_Qrequest(ptr,'C',0,0,juint(json,"maxseconds"),calc_nxt64bits(orderid),0,0,json));
{
argjson = cJSON_CreateObject();
jaddstr(argjson,"uuid",orderid);
if ( is_decimalstr(orderid) != 0 )
num = calc_nxt64bits(orderid);
retstr = exchanges777_Qrequest(ptr,'C',0,0,juint(json,"maxseconds"),num,0,0,argjson);
free_json(argjson);
return(retstr);
}
else return(clonestr("{\"error\":\"cant find or create exchange\"}"));
} else return(clonestr("{\"error\":\"no remote for this API\"}"));
}

5
iguana/iguana_init.c

@ -77,6 +77,7 @@ void iguana_initcoin(struct iguana_info *coin,cJSON *argjson)
{
sprintf(dirname,"%s/%s",GLOBAL_TMPDIR,coin->symbol), OS_portable_path(dirname);
portable_mutex_init(&coin->RTmutex);
portable_mutex_init(&coin->kmdmutex);
portable_mutex_init(&coin->peers_mutex);
portable_mutex_init(&coin->blocks_mutex);
portable_mutex_init(&coin->special_mutex);
@ -268,7 +269,7 @@ int32_t iguana_bundleinitmap(struct supernet_info *myinfo,struct iguana_info *co
void iguana_parseline(struct supernet_info *myinfo,struct iguana_info *coin,int32_t iter,FILE *fp)
{
int32_t j,k,m,c,flag,bundlei,lastheight,missing=0,height = -1; char checkstr[1024],line[1024];
int32_t j,k,m,c,flag,bundlei,lastheight=0,missing=0,height = -1; char checkstr[1024],line[1024];
struct iguana_peer *addr; struct iguana_bundle *bp; bits256 allhash,hash2,hash1,zero,lastbundle;
if ( coin->FULLNODE == 0 && coin->VALIDATENODE == 0 && iter > 0 )
return;
@ -317,7 +318,7 @@ void iguana_parseline(struct supernet_info *myinfo,struct iguana_info *coin,int3
{
if ( m < coin->MAXPEERS/2 )
{
if ( 0 && m == 0 && coin->seedipaddr[0] != 0 )
if ( (0) && m == 0 && coin->seedipaddr[0] != 0 )
{
addr = &coin->peers->active[m++];
iguana_initpeer(coin,addr,(uint32_t)calc_ipbits(coin->seedipaddr));

7
iguana/iguana_interpreter.c

@ -734,7 +734,7 @@ int32_t iguana_checksig(struct iguana_info *coin,struct iguana_stackdata pubkeya
if ( (retval= (bitcoin_verify(coin->ctx,sig,siglen-1,sigtxid,pubkey,plen) == 0)) == 0 )
{
}
if ( 0 )
if ( (0) )
{
int32_t i; char str[65];
for (i=0; i<siglen; i++)
@ -1000,7 +1000,7 @@ int32_t bitcoin_assembler(struct iguana_info *coin,cJSON *logarray,uint8_t scrip
struct bitcoin_opcode *op; cJSON *array = 0; struct iguana_interpreter STACKS,*stacks = &STACKS;
struct iguana_stackdata args[MAX_PUBKEYS_PER_MULTISIG];
uint8_t databuf[MAX_SCRIPT_ELEMENT_SIZE]; char *asmstr,*str,*hexstr; cJSON *item;
int32_t c,numops,dlen,plen,numvars,numused,numargs=0,i,j,k,n,len,datalen,errs=0; int64_t val;
int32_t c,numops,dlen,plen,numvars,numused,numargs=0,i,j,k,n=0,len,datalen,errs=0; int64_t val;
iguana_optableinit(coin);
if ( (asmstr= jstr(interpreter,"interpreter")) == 0 || asmstr[0] == 0 )
return(0);
@ -1438,6 +1438,7 @@ int32_t bitcoin_assembler(struct iguana_info *coin,cJSON *logarray,uint8_t scrip
}
else if ( (op->flags & IGUANA_STACKFLAG) != 0 )
{
val = 0;
if ( op->opcode == IGUANA_OP_PICK || op->opcode == IGUANA_OP_ROLL )
{
if ( interpret != 0 && stacks->stackdepth < (val= iguana_num(args[0])) )
@ -1505,7 +1506,7 @@ int32_t bitcoin_assembler(struct iguana_info *coin,cJSON *logarray,uint8_t scrip
}
else if ( (op->flags & IGUANA_MATHFLAG) != 0 )
{
int64_t numA,numB,numC;
int64_t numA=0,numB=0,numC=0;
for (i=0; i<op->stackitems; i++)
{
if ( args[i].size != sizeof(int32_t) )

450
iguana/iguana_json.c

@ -191,7 +191,10 @@ cJSON *SuperNET_helpjson()
#include "../includes/iguana_apideclares.h"
#undef IGUANA_ARGS
#undef _IGUANA_APIDEC_H_
#include "../includes/iguana_apiundefs.h"
if ( array != 0 )
jadd(json,"API",array);
jadd(json,"agents",agents);
@ -200,7 +203,7 @@ cJSON *SuperNET_helpjson()
int32_t agentform(FILE *fp,char *form,int32_t max,char *agent,cJSON *methoditem)
{
cJSON *item,*fieldsarray; int32_t j,m,width,size = 0;
cJSON *item,*fieldsarray; int32_t j,m,width=1,size = 0;
char *methodstr,*typestr,outstr[2048],outstr2[2048],fields[8192],str[2],agent_method[256],*fieldname;
form[0] = 0;
if ( (methodstr= jstr(methoditem,"method")) == 0 )
@ -293,7 +296,7 @@ int32_t templates_emit(char *retbuf,int32_t maxsize,char *template,char *agent,c
int32_t pretty_form(FILE *fp,char *formheader,char *formfooter,char *fieldtemplate,char *agent,cJSON *methoditem,cJSON *helpitem,char *suffix)
{
cJSON *item,*fieldsarray; int32_t j,m,formsize,fieldsize,iter,width,size = 0;
cJSON *item,*fieldsarray; int32_t j,m,formsize,fieldsize,iter,width=1,size = 0;
char *methodstr,*typestr,*fieldname,*helpstr,*curlstr,*urlstr,*itemhelp;
char outstr[2048],outstr2[2048],str[2],widthstr[16],both[512];
if ( (methodstr= jstr(methoditem,"method")) == 0 )
@ -493,421 +496,13 @@ char *SuperNET_htmlstr(char *fname,char *htmlstr,int32_t maxsize,char *agentstr)
return(OS_filestr(&filesize,"index7778.html"));
}
cJSON *iguana_peerjson(struct iguana_info *coin,struct iguana_peer *addr)
{
cJSON *array,*json = cJSON_CreateObject();
jaddstr(json,"ipaddr",addr->ipaddr);
if ( addr->supernet != 0 )
jaddstr(json,"ipaddr",addr->ipaddr);
jaddstr(json,"supernet","yes");
jaddnum(json,"protover",addr->protover);
jaddnum(json,"relay",addr->relayflag);
jaddnum(json,"height",addr->height);
jaddnum(json,"rank",addr->rank);
jaddnum(json,"usock",addr->usock);
if ( addr->dead != 0 )
jaddnum(json,"dead",addr->dead);
jaddnum(json,"ready",addr->ready);
jaddnum(json,"recvblocks",addr->recvblocks);
jaddnum(json,"recvtotal",addr->recvtotal);
jaddnum(json,"lastcontact",addr->lastcontact);
if ( addr->numpings > 0 )
jaddnum(json,"aveping",addr->pingsum/addr->numpings);
array = cJSON_CreateObject();
jaddnum(array,"version",addr->msgcounts.version);
jaddnum(array,"verack",addr->msgcounts.verack);
jaddnum(array,"getaddr",addr->msgcounts.getaddr);
jaddnum(array,"addr",addr->msgcounts.addr);
jaddnum(array,"inv",addr->msgcounts.inv);
jaddnum(array,"getdata",addr->msgcounts.getdata);
jaddnum(array,"notfound",addr->msgcounts.notfound);
jaddnum(array,"getblocks",addr->msgcounts.getblocks);
jaddnum(array,"getheaders",addr->msgcounts.getheaders);
jaddnum(array,"headers",addr->msgcounts.headers);
jaddnum(array,"tx",addr->msgcounts.tx);
jaddnum(array,"block",addr->msgcounts.block);
jaddnum(array,"mempool",addr->msgcounts.mempool);
jaddnum(array,"ping",addr->msgcounts.ping);
jaddnum(array,"pong",addr->msgcounts.pong);
jaddnum(array,"reject",addr->msgcounts.reject);
jaddnum(array,"filterload",addr->msgcounts.filterload);
jaddnum(array,"filteradd",addr->msgcounts.filteradd);
jaddnum(array,"filterclear",addr->msgcounts.filterclear);
jaddnum(array,"merkleblock",addr->msgcounts.merkleblock);
jaddnum(array,"alert",addr->msgcounts.alert);
jadd(json,"msgcounts",array);
return(json);
}
cJSON *iguana_peersjson(struct iguana_info *coin,int32_t addronly)
{
cJSON *retjson,*array; int32_t i; struct iguana_peer *addr;
if ( coin == 0 || coin->peers == 0 )
return(0);
array = cJSON_CreateArray();
for (i=0; i<coin->MAXPEERS; i++)
{
addr = &coin->peers->active[i];
if ( addr->usock >= 0 && addr->ipbits != 0 && addr->ipaddr[0] != 0 )
{
if ( addronly != 0 )
jaddistr(array,addr->ipaddr);
else jaddi(array,iguana_peerjson(coin,addr));
}
}
if ( addronly == 0 )
{
retjson = cJSON_CreateObject();
jadd(retjson,"peers",array);
jaddnum(retjson,"maxpeers",coin->MAXPEERS);
jaddstr(retjson,"coin",coin->symbol);
return(retjson);
}
else return(array);
}
#include "../includes/iguana_apidefs.h"
#include "../includes/iguana_apideclares.h"
STRING_ARG(iguana,peers,activecoin)
{
if ( coin != 0 )
return(jprint(iguana_peersjson(coin,0),1));
else return(clonestr("{\"error\":\"peers needs coin\"}"));
}
STRING_ARG(iguana,getconnectioncount,activecoin)
{
int32_t i,num = 0; char buf[512];
if ( coin != 0 && coin->peers != 0 )
{
for (i=0; i<sizeof(coin->peers->active)/sizeof(*coin->peers->active); i++)
if ( coin->peers->active[i].usock >= 0 )
num++;
sprintf(buf,"{\"result\":\"%d\"}",num);
return(clonestr(buf));
} else return(clonestr("{\"error\":\"getconnectioncount needs coin\"}"));
}
ZERO_ARGS(bitcoinrpc,getdifficulty)
{
char buf[512];
if ( coin != 0 )
{
sprintf(buf,"{\"result\":\"success\",\"proof-of-work\":\"%.8f\",\"search-interval\": 0}",PoW_from_compact(coin->blocks.hwmchain.RO.bits,coin->chain->unitval));
return(clonestr(buf));
} else return(clonestr("{\"error\":\"getdifficulty needs coin\"}"));
}
STRING_ARG(iguana,addcoin,newcoin)
{
char *symbol,*seedip; int32_t retval;
if ( (symbol= newcoin) == 0 && coin != 0 )
symbol = coin->symbol;
if ( symbol != 0 )
{
if ( (seedip= jstr(json,"seedipaddr")) != 0 )
safecopy(myinfo->seedipaddr,seedip,sizeof(myinfo->seedipaddr));
printf(">> addcoin.%s seedipaddr.%s\n",symbol,myinfo->seedipaddr);
#ifdef __PNACL__
// if ( strcmp(symbol,"BTC") == 0 )
// return(clonestr("{\"result\":\"BTC for chrome app is not yet\"}"));
#ifdef WIN32
/**
* workaround for MSVS compiler bug -
* instead of going on if-else-if block split the if-else-if into two function
*/
char *SuperNET_parser2(struct supernet_info *myinfo, char *agentstr, char *method, cJSON *json, char *remoteaddr);
#endif
if ( (retval= iguana_launchcoin(myinfo,symbol,json,0)) > 0 )
{
if ( myinfo->rpcsymbol[0] == 0 )
safecopy(myinfo->rpcsymbol,symbol,sizeof(myinfo->rpcsymbol));
return(clonestr("{\"result\":\"coin added\"}"));
}
else if ( retval == 0 )
return(clonestr("{\"result\":\"coin already there\"}"));
else return(clonestr("{\"error\":\"error adding coin\"}"));
} else return(clonestr("{\"error\":\"addcoin needs newcoin\"}"));
}
STRING_ARG(iguana,startcoin,activecoin)
{
if ( coin != 0 )
{
coin->active = 1;
return(clonestr("{\"result\":\"coin started\"}"));
} else return(clonestr("{\"error\":\"startcoin needs coin\"}"));
}
STRING_ARG(iguana,stopcoin,activecoin)
{
if ( activecoin[0] != 0 )
coin = iguana_coinfind(activecoin);
if ( coin != 0 )
{
coin->active = 0;
//iguana_coinpurge(coin);
return(clonestr("{\"result\":\"coin stopped\"}"));
} else return(clonestr("{\"error\":\"stopcoin needs coin\"}"));
}
STRING_ARG(iguana,pausecoin,activecoin)
{
if ( coin != 0 )
{
coin->active = 0;
return(clonestr("{\"result\":\"coin paused\"}"));
} else return(clonestr("{\"error\":\"pausecoin needs coin\"}"));
}
TWO_STRINGS(iguana,addnode,activecoin,ipaddr)
{
struct iguana_peer *addr; int32_t i,n;
if ( coin == 0 )
coin = iguana_coinfind(activecoin);
if ( coin != 0 && strcmp(coin->symbol,"RELAY") == 0 )
basilisk_addrelay_info(myinfo,0,(uint32_t)calc_ipbits(ipaddr),GENESIS_PUBKEY);
printf("coin.%p.[%s] addnode.%s -> %s\n",coin,coin!=0?coin->symbol:"",activecoin,ipaddr);
if ( coin != 0 && coin->peers != 0 && ipaddr != 0 && is_ipaddr(ipaddr) != 0 )
{
//iguana_possible_peer(coin,ipaddr);
if ( (addr= iguana_peerslot(coin,(uint32_t)calc_ipbits(ipaddr),1)) != 0 )
{
addr->supernet = 1;
if ( addr->usock >= 0 )
{
if ( (n= coin->peers->numranked) != 0 )
{
for (i=0; i<n; i++)
{
if ( addr == coin->peers->ranked[i] )
break;
}
if ( i == n )
{
if ( i == IGUANA_MAXPEERS )
i--;
else coin->peers->numranked = n+1;
coin->peers->ranked[i] = addr;
addr->recvblocks = coin->peers->ranked[0]->recvblocks + 100;
addr->recvtotal = coin->peers->ranked[0]->recvtotal*1.1 + 100;
printf("set (%s) -> slot.%d numranked.%d\n",ipaddr,i,coin->peers->numranked);
} else printf("(%s) is already peer.%d\n",ipaddr,i);
}
return(clonestr("{\"result\":\"peer was already connected\"}"));
}
if ( addr->pending == 0 )
{
addr->pending = (uint32_t)time(NULL);
iguana_launch(coin,"connection",iguana_startconnection,addr,IGUANA_CONNTHREAD);
return(clonestr("{\"result\":\"addnode submitted\"}"));
} else return(clonestr("{\"result\":\"addnode connection was already pending\"}"));
} else return(clonestr("{\"result\":\"addnode cant find peer slot\"}"));
}
else if ( coin == 0 )
return(clonestr("{\"error\":\"addnode needs active coin, do an addcoin first\"}"));
else return(clonestr("{\"error\":\"addnode needs ipaddr\"}"));
}
TWO_STRINGS(iguana,persistent,activecoin,ipaddr)
{
int32_t i;
if ( coin != 0 && coin->peers != 0 && ipaddr != 0 )
{
for (i=0; i<IGUANA_MAXPEERS; i++)
{
if ( strcmp(coin->peers->active[i].ipaddr,ipaddr) == 0 )
{
coin->peers->active[i].persistent_peer = juint(json,"interval")+3;
return(clonestr("{\"result\":\"node marked as persistent\"}"));
}
}
return(clonestr("{\"result\":\"node wasnt active\"}"));
} else return(clonestr("{\"error\":\"persistent needs coin and ipaddr\"}"));
}
TWO_STRINGS(iguana,removenode,activecoin,ipaddr)
{
int32_t i;
if ( coin != 0 && coin->peers != 0 && ipaddr != 0 )
{
for (i=0; i<IGUANA_MAXPEERS; i++)
{
if ( strcmp(coin->peers->active[i].ipaddr,ipaddr) == 0 )
{
coin->peers->active[i].rank = 0;
coin->peers->active[i].dead = (uint32_t)time(NULL);
return(clonestr("{\"result\":\"node marked as dead\"}"));
}
}
return(clonestr("{\"result\":\"node wasnt active\"}"));
} else return(clonestr("{\"error\":\"removenode needs coin and ipaddr\"}"));
}
TWO_STRINGS(iguana,oneshot,activecoin,ipaddr)
{
if ( coin != 0 && ipaddr != 0 )
{
iguana_possible_peer(coin,ipaddr);
return(clonestr("{\"result\":\"addnode submitted\"}"));
} else return(clonestr("{\"error\":\"addnode needs coin and ipaddr\"}"));
}
TWO_STRINGS(iguana,nodestatus,activecoin,ipaddr)
{
int32_t i; struct iguana_peer *addr;
if ( coin != 0 && coin->peers != 0 && ipaddr != 0 )
{
for (i=0; i<coin->MAXPEERS; i++)
{
addr = &coin->peers->active[i];
if ( strcmp(addr->ipaddr,ipaddr) == 0 )
return(jprint(iguana_peerjson(coin,addr),1));
}
return(clonestr("{\"result\":\"nodestatus couldnt find ipaddr\"}"));
} else return(clonestr("{\"error\":\"nodestatus needs ipaddr\"}"));
}
STRING_AND_INT(iguana,maxpeers,activecoin,max)
{
cJSON *retjson; int32_t i; struct iguana_peer *addr;
if ( coin != 0 && coin->peers != 0 )
{
retjson = cJSON_CreateObject();
if ( max > IGUANA_MAXPEERS )
max = IGUANA_MAXPEERS;
if ( max > coin->MAXPEERS )
{
for (i=max; i<coin->MAXPEERS; i++)
if ( (addr= coin->peers->ranked[i]) != 0 )
addr->dead = 1;
}
coin->MAXPEERS = max;
jaddnum(retjson,"maxpeers",coin->MAXPEERS);
jaddstr(retjson,"coin",coin->symbol);
return(jprint(retjson,1));
} else return(clonestr("{\"error\":\"maxpeers needs coin\"}"));
}
char *hmac_dispatch(char *(*hmacfunc)(char *dest,char *key,int32_t key_size,char *message),char *name,char *message,char *password)
{
char hexstr[1025]; cJSON *json;
if ( message != 0 && password != 0 && message[0] != 0 && password[0] != 0 )
{
memset(hexstr,0,sizeof(hexstr));
(*hmacfunc)(hexstr,password,password==0?0:(int32_t)strlen(password),message);
json = cJSON_CreateObject();
jaddstr(json,"result","hmac calculated");
jaddstr(json,"message",message);
jaddstr(json,name,hexstr);
return(jprint(json,1));
} else return(clonestr("{\"error\":\"hmac needs message and passphrase\"}"));
}
char *hash_dispatch(void (*hashfunc)(char *hexstr,uint8_t *buf,uint8_t *msg,int32_t len),char *name,char *message)
{
char hexstr[65537]; uint8_t databuf[32768]; cJSON *json;
if ( message != 0 && message[0] != 0 )
{
memset(hexstr,0,sizeof(hexstr));
(*hashfunc)(hexstr,databuf,(uint8_t *)message,(int32_t)strlen(message));
json = cJSON_CreateObject();
jaddstr(json,"result","hash calculated");
jaddstr(json,"message",message);
jaddstr(json,name,hexstr);
return(jprint(json,1));
} else return(clonestr("{\"error\":\"hash needs message\"}"));
}
TWO_HASHES(hash,curve25519_pair,element,scalar)
{
cJSON *retjson = cJSON_CreateObject();
jaddbits256(retjson,"result",curve25519(element,scalar));
return(jprint(retjson,1));
}
STRING_ARG(hash,NXT,passphrase) { return(hash_dispatch(calc_NXTaddr,"NXT",passphrase)); }
STRING_ARG(hash,curve25519,pubkey) { return(hash_dispatch(calc_curve25519_str,"curve25519",pubkey)); }
STRING_ARG(hash,crc32,message) { return(hash_dispatch(calc_crc32str,"crc32",message)); }
STRING_ARG(hash,base64_encode,message) { return(hash_dispatch(calc_base64_encodestr,"base64_encode",message)); }
STRING_ARG(hash,base64_decode,message) { return(hash_dispatch(calc_base64_decodestr,"base64_decode",message)); }
STRING_ARG(hash,rmd160_sha256,message) { return(hash_dispatch(rmd160ofsha256,"rmd160_sha256",message)); }
STRING_ARG(hash,sha256_sha256,message) { return(hash_dispatch(sha256_sha256,"sha256_sha256",message)); }
STRING_ARG(hash,hex,message) { return(hash_dispatch(calc_hexstr,"hex",message)); }
STRING_ARG(hash,unhex,message) { return(hash_dispatch(calc_unhexstr,"unhex",message)); }
STRING_ARG(hash,sha224,message) { return(hash_dispatch(calc_sha224,"sha224",message)); }
STRING_ARG(hash,sha256,message) { return(hash_dispatch(vcalc_sha256,"sha256",message)); }
STRING_ARG(hash,sha384,message) { return(hash_dispatch(calc_sha384,"sha384",message)); }
STRING_ARG(hash,sha512,message) { return(hash_dispatch(calc_sha512,"sha512",message)); }
STRING_ARG(hash,rmd128,message) { return(hash_dispatch(calc_rmd128,"rmd128",message)); }
STRING_ARG(hash,rmd160,message) { return(hash_dispatch(calc_rmd160,"rmd160",message)); }
STRING_ARG(hash,rmd256,message) { return(hash_dispatch(calc_rmd256,"rmd256",message)); }
STRING_ARG(hash,rmd320,message) { return(hash_dispatch(calc_rmd320,"rmd320",message)); }
STRING_ARG(hash,sha1,message) { return(hash_dispatch(calc_sha1,"sha1",message)); }
STRING_ARG(hash,md2,message) { return(hash_dispatch(calc_md2str,"md2",message)); }
STRING_ARG(hash,md4,message) { return(hash_dispatch(calc_md4str,"md4",message)); }
STRING_ARG(hash,md5,message) { return(hash_dispatch(calc_md5str,"md5",message)); }
STRING_ARG(hash,tiger192_3,message) { return(hash_dispatch(calc_tiger,"tiger",message)); }
STRING_ARG(hash,whirlpool,message) { return(hash_dispatch(calc_whirlpool,"whirlpool",message)); }
TWO_STRINGS(hmac,sha224,message,passphrase) { return(hmac_dispatch(hmac_sha224_str,"sha224",message,passphrase)); }
TWO_STRINGS(hmac,sha256,message,passphrase) { return(hmac_dispatch(hmac_sha256_str,"sha256",message,passphrase)); }
TWO_STRINGS(hmac,sha384,message,passphrase) { return(hmac_dispatch(hmac_sha384_str,"sha384",message,passphrase)); }
TWO_STRINGS(hmac,sha512,message,passphrase) { return(hmac_dispatch(hmac_sha512_str,"sha512",message,passphrase)); }
TWO_STRINGS(hmac,rmd128,message,passphrase) { return(hmac_dispatch(hmac_rmd128_str,"rmd128",message,passphrase)); }
TWO_STRINGS(hmac,rmd160,message,passphrase) { return(hmac_dispatch(hmac_rmd160_str,"rmd160",message,passphrase)); }
TWO_STRINGS(hmac,rmd256,message,passphrase) { return(hmac_dispatch(hmac_rmd256_str,"rmd256",message,passphrase)); }
TWO_STRINGS(hmac,rmd320,message,passphrase) { return(hmac_dispatch(hmac_rmd320_str,"rmd320",message,passphrase)); }
TWO_STRINGS(hmac,sha1,message,passphrase) { return(hmac_dispatch(hmac_sha1_str,"sha1",message,passphrase)); }
TWO_STRINGS(hmac,md2,message,passphrase) { return(hmac_dispatch(hmac_md2_str,"md2",message,passphrase)); }
TWO_STRINGS(hmac,md4,message,passphrase) { return(hmac_dispatch(hmac_md4_str,"md4",message,passphrase)); }
TWO_STRINGS(hmac,md5,message,passphrase) { return(hmac_dispatch(hmac_md5_str,"md5",message,passphrase)); }
TWO_STRINGS(hmac,tiger192_3,message,passphrase) { return(hmac_dispatch(hmac_tiger_str,"tiger",message,passphrase)); }
TWO_STRINGS(hmac,whirlpool,message,passphrase) { return(hmac_dispatch(hmac_whirlpool_str,"whirlpool",message,passphrase)); }
STRING_ARG(SuperNET,bitcoinrpc,setcoin)
{
char buf[1024];
if ( setcoin != 0 && setcoin[0] != 0 )
{
strcpy(myinfo->rpcsymbol,setcoin);
touppercase(myinfo->rpcsymbol);
printf("bitcoinrpc.%s\n",myinfo->rpcsymbol);
if ( iguana_launchcoin(myinfo,myinfo->rpcsymbol,json,0) < 0 )
return(clonestr("{\"error\":\"error creating coin\"}"));
else
{
sprintf(buf,"{\"result\":\"success\",\"setcoin\":\"%s\"}",setcoin);
return(clonestr(buf));
}
} else return(clonestr("{\"error\":\"bitcoinrpc needs setcoin value\"}"));
}
ZERO_ARGS(SuperNET,help)
{
cJSON *helpjson,*retjson;
if ( (helpjson= SuperNET_helpjson()) != 0 )
{
retjson = cJSON_CreateObject();
jadd(retjson,"result",helpjson);
return(jprint(retjson,1));
} else return(clonestr("{\"error\":\"cant get helpjson\"}"));
}
TWO_STRINGS(SuperNET,html,agentform,htmlfile)
{
char *htmlstr; cJSON *retjson; int32_t max = 4*1024*1024;
if ( htmlfile == 0 || htmlfile[0] == 0 )
htmlfile = "forms.html";
//if ( (fp= fopen(htmlfile,"w")) == 0 )
// printf("error opening htmlfile.(%s)\n",htmlfile);
htmlstr = malloc(max);
htmlstr = SuperNET_htmlstr(htmlfile,htmlstr,max,agentform);
retjson = cJSON_CreateObject();
jaddstr(retjson,"result",htmlstr);
free(htmlstr);
//if ( fp != 0 )
// fclose(fp);
return(jprint(retjson,1));
}
#undef IGUANA_ARGS
#include "../includes/iguana_apiundefs.h"
char *SuperNET_parser(struct supernet_info *myinfo,char *agentstr,char *method,cJSON *json,char *remoteaddr)
{
@ -1025,12 +620,31 @@ char *SuperNET_parser(struct supernet_info *myinfo,char *agentstr,char *method,c
#define STRING_ARRAY_OBJ_STRING IGUANA_DISPATCH_SAOS
#include "../includes/iguana_apideclares.h"
//#undef IGUANA_ARGS
#ifdef WIN32
return SuperNET_parser2(myinfo, agentstr, method, json, remoteaddr);
#else
#undef IGUANA_ARGS
#undef _IGUANA_APIDEC_H_
#include "../includes/iguana_apiundefs.h"
char errstr[512];
sprintf(errstr,"{\"error\":\"unsupported call\",\"agent\":\"%s\",\"method\":\"%s\"}",agentstr,method);
return(clonestr(errstr));
#endif
}
#ifdef WIN32
char *SuperNET_parser2(struct supernet_info *myinfo, char *agentstr, char *method, cJSON *json, char *remoteaddr) {
char *coinstr; struct iguana_info *coin = 0;
if (remoteaddr != 0 && (remoteaddr[0] == 0 || strcmp(remoteaddr, "127.0.0.1") == 0))
remoteaddr = 0;
#include "../includes/iguana_apideclares2.h"
#undef IGUANA_ARGS
#undef _IGUANA_APIDEC_H_
#include "../includes/iguana_apiundefs.h"
char errstr[512];
sprintf(errstr, "{\"error\":\"unsupported call\",\"agent\":\"%s\",\"method\":\"%s\"}", agentstr, method);
return(clonestr(errstr));
}
#endif

14
iguana/iguana_mofn.c

@ -238,6 +238,13 @@ int32_t gfshare_test(struct supernet_info *myinfo,int32_t M,int32_t N,int32_t da
return ok!=1;
}
void iguana_fixsecp(struct supernet_info *myinfo)
{
myinfo->ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY);
secp256k1_pedersen_context_initialize(myinfo->ctx);
secp256k1_rangeproof_context_initialize(myinfo->ctx);
}
void libgfshare_init(struct supernet_info *myinfo,uint8_t _logs[256],uint8_t _exps[510])
{
uint32_t i,x = 1;
@ -255,7 +262,7 @@ void libgfshare_init(struct supernet_info *myinfo,uint8_t _logs[256],uint8_t _ex
for (i=255; i<510; i++)
_exps[i] = _exps[i % 255];
_logs[0] = 0; // can't log(0) so just set it neatly to 0
if ( 0 )
if ( (0) )
{
void test_mofn(struct supernet_info *myinfo);
gfshare_test(myinfo,6,11,32);
@ -595,7 +602,7 @@ void test_mofn(struct supernet_info *myinfo)
{
if ( memcmp(secret.bytes,recover.bytes,sizeof(secret)) != 0 )
printf("FAILED m.%d M.%d N.%d\n",m,M,N);
else if ( 0 )
else if ( (0) )
{
char str[65];
printf("%s PASSED m.%d M.%d N.%d\n",bits256_str(str,recover),m,M,N);
@ -651,6 +658,7 @@ int32_t iguana_schnorr_peersign(void *ctx,uint8_t *allpub33,uint8_t *partialsig6
bits256 iguana_schnorr_noncepair(void *ctx,bits256 *pubkey,uint8_t odd_even,bits256 msg256,bits256 privkey,int32_t maxj)
{
bits256 privnonce; int32_t j; uint8_t pubkey33[33];
memset(privnonce.bytes,0,sizeof(privnonce));
for (j=0; j<maxj; j++)
{
privnonce = bitcoin_schnorr_noncepair(ctx,pubkey33,msg256,privkey);
@ -773,7 +781,7 @@ void iguana_schnorr(struct supernet_info *myinfo)
printf("error combining k.%d sig64 iter.%d\n",k,iter);
else if ( bitcoin_schnorr_verify(myinfo->ctx,sig64,msg256,allpub2,33) < 0 )
printf("allpub2 error verifying combined sig k.%d\n",k);
else if ( 0 ) // doesnt replicate with subsets
else if ( (0) ) // doesnt replicate with subsets
{
if ( bitcoin_pubkey_combine(myinfo->ctx,allpub,0,pubkeys,n,0,0) == 0 )
{

16
iguana/iguana_msg.c

@ -449,7 +449,7 @@ void iguana_gotaddr(struct iguana_info *coin,struct iguana_peer *addr,struct igu
expand_ipbits(ipaddr,ipbits);
if ( port != 0 )
sprintf(ipport,"%s:%d",ipaddr,port);
if ( 0 )
if ( (0) )
{
int32_t i;
printf("{{");
@ -459,7 +459,7 @@ void iguana_gotaddr(struct iguana_info *coin,struct iguana_peer *addr,struct igu
}
if ( strcmp(coin->symbol,"BTC") != 0 || (rand() % 10) == 0 )
iguana_possible_peer(coin,ipport);
if ( 0 && strcmp("TAZ",coin->symbol) == 0 )
if ( (0) && strcmp("TAZ",coin->symbol) == 0 )
printf("iguana_gotaddr: %s from %s\n",ipaddr,addr->ipaddr);
}
@ -713,7 +713,7 @@ int32_t iguana_rwtx(struct supernet_info *myinfo,uint8_t zcash,int32_t rwflag,st
memcpy(joinsplitsig,&serialized[len],64), len += 64;
}
}
if ( 0 )
if ( (0) )
{
*txidp = bits256_doublesha256(txidstr,txstart,len);
char str[65];
@ -955,7 +955,7 @@ int32_t iguana_msgparser(struct supernet_info *myinfo,struct iguana_info *coin,s
}
if ( addr != 0 )
{
if ( 0 && addr->msgcounts.verack == 0 )
if ( (0) && addr->msgcounts.verack == 0 )
printf("iguana_msgparser verack.%d from (%s) parse.(%s) len.%d\n",addr->msgcounts.verack,addr->ipaddr,H->command,recvlen);
//iguana_peerblockrequest(coin,addr->blockspace,IGUANA_MAXPACKETSIZE,addr,iguana_blockhash(coin,100),0);
addr->lastcontact = (uint32_t)time(NULL);
@ -1010,7 +1010,7 @@ int32_t iguana_msgparser(struct supernet_info *myinfo,struct iguana_info *coin,s
else
{
intvectors = 'I', addr->msgcounts.inv++;
if ( 0 && strcmp(H->command,"inv2") == 0 )
if ( (0) && strcmp(H->command,"inv2") == 0 )
printf("GOT INV2.%d\n",recvlen);
len = iguana_intvectors(coin,addr,1,data,recvlen); // indirectly issues getdata
}
@ -1056,7 +1056,7 @@ int32_t iguana_msgparser(struct supernet_info *myinfo,struct iguana_info *coin,s
}
len += iguana_rwvarint32(0,&data[len],&tmp);
char str[65],str2[65];
if ( 0 && coin->chain->auxpow != 0 )
if ( (0) && coin->chain->auxpow != 0 )
printf("%d %d of %d: %s %s v.%08x numtx.%d cmp.%d\n",len,i,n,bits256_str(str,hash2),bits256_str(str2,zmsg.zH.prev_block),zmsg.zH.version,tmp,bits256_cmp(prevhash2,zmsg.zH.prev_block));
}
else len += iguana_rwblock(myinfo,coin->chain->symbol,coin->chain->zcash,coin->chain->auxpow,coin->chain->hashalgo,0,&hash2,&data[len],(void *)&zmsg,recvlen);
@ -1151,7 +1151,7 @@ int32_t iguana_msgparser(struct supernet_info *myinfo,struct iguana_info *coin,s
len = 0;
if ( (sendlen= iguana_peeraddrrequest(coin,addr,&addr->blockspace[sizeof(H)],IGUANA_MAXPACKETSIZE)) > 0 )
{
if ( 0 )
if ( (0) )
{
int32_t checklen; uint32_t checkbits; char checkaddr[64];
checklen = iguana_rwvarint(0,&addr->blockspace[sizeof(H)],&x);
@ -1263,4 +1263,4 @@ int32_t iguana_msgparser(struct supernet_info *myinfo,struct iguana_info *coin,s
}
}
return(retval);
}
}

244
iguana/iguana_notary.c

@ -38,7 +38,7 @@ void dpow_fifoupdate(struct supernet_info *myinfo,struct dpow_checkpoint *fifo,s
memset(newfifo,0,sizeof(newfifo));
for (i=DPOW_FIFOSIZE-1; i>0; i--)
{
if ( 0 && bits256_nonz(fifo[i-1].blockhash.hash) != 0 && (tip.blockhash.height - fifo[i-1].blockhash.height) != i )
if ( (0) && bits256_nonz(fifo[i-1].blockhash.hash) != 0 && (tip.blockhash.height - fifo[i-1].blockhash.height) != i )
printf("(%d != %d) ",(tip.blockhash.height - fifo[i-1].blockhash.height),i);
if ( (ind= (tip.blockhash.height - fifo[i-1].blockhash.height)) >= 0 && ind < DPOW_FIFOSIZE )
newfifo[ind] = fifo[i-1];
@ -147,7 +147,7 @@ void iguana_dPoWupdate(struct supernet_info *myinfo,struct dpow_info *dp)
{
int32_t height,num; uint32_t blocktime; bits256 blockhash; struct iguana_info *src,*dest;
//fprintf(stderr,"dp.%p dPoWupdate (%s -> %s)\n",dp,dp!=0?dp->symbol:"",dp!=0?dp->dest:"");
if ( strcmp(dp->symbol,"KMD") == 0 )
//if ( strcmp(dp->symbol,"KMD") == 0 )
{
num = dpow_nanomsg_update(myinfo);
//fprintf(stderr,"%d ",num);
@ -224,10 +224,12 @@ void dpow_addresses()
#include "../includes/iguana_apidefs.h"
#include "../includes/iguana_apideclares.h"
#include "../includes/iguana_apideclares2.h"
TWO_STRINGS(iguana,dpow,symbol,pubkey)
{
char *retstr,srcaddr[64],destaddr[64]; struct iguana_info *src,*dest; cJSON *ismine; int32_t i,srcvalid,destvalid; struct dpow_info *dp = &myinfo->DPOWS[myinfo->numdpows];
destvalid = srcvalid = 0;
if ( myinfo->NOTARY.RELAYID < 0 )
{
if ( (retstr= basilisk_addrelay_info(myinfo,0,(uint32_t)calc_ipbits(myinfo->ipaddr),myinfo->myaddr.persistent)) != 0 )
@ -372,7 +374,6 @@ THREE_STRINGS(iguana,passthru,asset,function,hex)
else return(clonestr("{\"error\":\"assetchain not active, start in bitcoind mode\"}"));
}
TWO_STRINGS(dex,send,hex,handler)
{
uint8_t data[8192]; int32_t datalen; char *retstr;
@ -612,6 +613,95 @@ HASH_AND_STRING_AND_INT(dex,gettxout,txid,symbol,vout)
return(_dex_gettxout(myinfo,symbol,txid,vout));
}
TWO_STRINGS(dex,listunspent,symbol,address)
{
if ( symbol != 0 && strcmp(symbol,"BTC") == 0 && (coin= iguana_coinfind("BTC")) != 0 && coin->FULLNODE == 0 && myinfo->blocktrail_apikey[0] != 0 )
{
char url[1024],*retstr,*coinaddr,*script; int32_t i,n,vout; cJSON *retjson,*data,*item,*item3,*data3; bits256 txid; uint64_t val;
sprintf(url,"https://api.blocktrail.com/v1/btc/address/%s/unspent-outputs?api_key=%s",address,myinfo->blocktrail_apikey);
if ( (retstr= issue_curl(url)) != 0 )
{
if ( (retjson= cJSON_Parse(retstr)) != 0 )
{
data = jarray(&n,retjson,"data");
data3 = cJSON_CreateArray();
//[{"hash":"e0a40dac21103e92e0dc9311a0233640489afc5beb5ba3b009848a8e9151dc55","time":"2017-02-21T16:48:28+0000","confirmations":1,"is_coinbase":false,"value":4100000,"index":1,"address":"19rjYdJtRN3qoammX3r1gxy9bvh8p8DmRc","type":"pubkeyhash","multisig":null,"script":"OP_DUP OP_HASH160 6128e7459989d35d530bcd4066c9aaf1f925430a OP_EQUALVERIFY OP_CHECKSIG","script_hex":"76a9146128e7459989d35d530bcd4066c9aaf1f925430a88ac"}]
/*{
"txid" : "e95d3083baf733dfda2fcd1110fe2937cb3580f8b1b237aad547528440dfa873",
"vout" : 1,
"address" : "RNgdefRo2iRLWqDXEogJrsTw35MgDPQP4R",
"account" : "",
"scriptPubKey" : "76a91493088c5f3546225e0ef6ba9c9c6a74d4c2df877388ac",
"amount" : 150.00000000,
"interest" : 0.30000000,
"confirmations" : 20599,
"spendable" : true
}*/
for (i=0; i<n; i++)
{
item = jitem(data,i);
txid = jbits256(item,"hash");
vout = jint(item,"index");
val = j64bits(item,"value");
coinaddr = jstr(item,"address");
script = jstr(item,"script_hex");
item3 = cJSON_CreateObject();
jaddbits256(item3,"txid",txid);
jaddnum(item3,"vout",vout);
jaddnum(item3,"amount",dstr(val));
jaddnum(item3,"value",dstr(val));
if ( coinaddr != 0 )
jaddstr(item3,"address",coinaddr);
if ( script != 0 )
jaddstr(item3,"scriptPubKey",script);
jaddnum(item3,"confirmations",jint(item,"confirmations"));
jadd(item3,"spendable",jtrue());
jaddi(data3,item3);
}
free(retstr);
retstr = jprint(data3,1);
free_json(retjson);
}
return(retstr);
}
}
return(_dex_listunspent(myinfo,symbol,address));
}
TWO_STRINGS_AND_TWO_DOUBLES(dex,listtransactions,symbol,address,count,skip)
{
if ( symbol != 0 && strcmp(symbol,"BTC") == 0 && (coin= iguana_coinfind("BTC")) != 0 && coin->FULLNODE == 0 && myinfo->blocktrail_apikey[0] != 0 )
{
char url[1024],*retstr,*retstr2; cJSON *retjson,*retjson2,*retjson3,*data,*data2; int32_t i,n;
sprintf(url,"https://api.blocktrail.com/v1/btc/address/%s/transactions?api_key=%s",address,myinfo->blocktrail_apikey);
if ( (retstr= issue_curl(url)) != 0 )
{
sprintf(url,"https://api.blocktrail.com/v1/btc/address/%s/unconfirmed-transactions?api_key=%s",address,myinfo->blocktrail_apikey);
if ( (retstr2= issue_curl(url)) != 0 )
{
if ( (retjson= cJSON_Parse(retstr)) != 0 && (retjson2= cJSON_Parse(retstr2)) != 0 )
{
data = jarray(&n,retjson,"data");
data2 = jarray(&n,retjson2,"data");
retjson3 = jduplicate(data);
if ( n > 0 )
{
for (i=0; i<n; i++)
jaddi(retjson3,jduplicate(jitem(data2,i)));
}
printf("combined (%s) and (%s) -> (%s)\n",retstr,retstr2,jprint(retjson3,0));
free(retstr);
free(retstr2);
free_json(retjson);
free_json(retjson2);
return(jprint(retjson3,1));
}
}
}
}
return(_dex_listtransactions(myinfo,symbol,address,count,skip));
}
STRING_ARG(dex,getinfo,symbol)
{
return(_dex_getinfo(myinfo,symbol));
@ -657,14 +747,14 @@ TWO_STRINGS(dex,validateaddress,symbol,address)
return(_dex_validateaddress(myinfo,symbol,address));
}
TWO_STRINGS(dex,listunspent,symbol,address)
STRING_ARG(dex,getmessage,argstr)
{
return(_dex_listunspent(myinfo,symbol,address));
return(_dex_getmessage(myinfo,argstr));
}
TWO_STRINGS_AND_TWO_DOUBLES(dex,listtransactions,symbol,address,count,skip)
STRING_ARG(dex,psock,argstr)
{
return(_dex_listtransactions(myinfo,symbol,address,count,skip));
return(_dex_psock(myinfo,argstr));
}
STRING_ARG(dex,getnotaries,symbol)
@ -698,6 +788,146 @@ THREE_STRINGS_AND_THREE_INTS(dex,kvupdate,symbol,key,value,flags,unused,unusedb)
} else return(clonestr("{\"error\":\"free updates only on KV chain\"}"));
}
#include "kmd_lookup.h"
TWO_STRINGS(dex,listunspent2,symbol,address)
{
cJSON *retjson;
if ( myinfo->DEXEXPLORER != 0 )
{
if ( symbol != 0 && address != 0 && (coin= iguana_coinfind(symbol)) != 0 )
{
if ( coin != 0 )
coin->DEXEXPLORER = myinfo->DEXEXPLORER * myinfo->IAMNOTARY * (iguana_isnotarychain(coin->symbol) >= 0);
if ( strcmp(coin->symbol,"BTC") == 0 || coin->DEXEXPLORER == 0 )
return(clonestr("[]"));
if ( (retjson= kmd_listunspent(myinfo,coin,address)) != 0 )
return(jprint(retjson,1));
}
}
if ( symbol != 0 && address != 0 )
return(_dex_listunspent2(myinfo,symbol,address));
else return(clonestr("{\"error\":\"dex listunspent2 null symbol, address or coin\"}"));
}
TWO_STRINGS_AND_TWO_DOUBLES(dex,listtransactions2,symbol,address,count,skip)
{
cJSON *retjson;
if ( myinfo->DEXEXPLORER != 0 )
{
if ( symbol != 0 && address != 0 && (coin= iguana_coinfind(symbol)) != 0 )
{
if ( coin != 0 )
coin->DEXEXPLORER = myinfo->DEXEXPLORER * myinfo->IAMNOTARY * (iguana_isnotarychain(coin->symbol) >= 0);
if ( strcmp(coin->symbol,"BTC") == 0 || coin->DEXEXPLORER == 0 )
return(clonestr("[]"));
if ( (retjson= kmd_listtransactions(myinfo,coin,address,count,skip)) != 0 )
return(jprint(retjson,1));
}
}
if ( symbol != 0 && address != 0 )
return(_dex_listtransactions2(myinfo,symbol,address,count,skip));
else return(clonestr("{\"error\":\"dex listunspent2 null symbol, address or coin\"}"));
}
HASH_AND_STRING_AND_INT(dex,gettxin,txid,symbol,vout)
{
if ( myinfo->DEXEXPLORER != 0 )
{
if ( symbol != 0 && (coin= iguana_coinfind(symbol)) != 0 && coin->DEXEXPLORER != 0 )
return(jprint(kmd_gettxin(coin,txid,vout),1));
if ( coin != 0 )
coin->DEXEXPLORER = myinfo->DEXEXPLORER * myinfo->IAMNOTARY * (iguana_isnotarychain(coin->symbol) >= 0);
}
if ( symbol != 0 )
return(_dex_gettxin(myinfo,symbol,txid,vout));
else return(clonestr("{\"error\":\"dex gettxin null symbolor coin\"}"));
}
TWO_STRINGS(dex,listspent,symbol,address)
{
if ( myinfo->DEXEXPLORER != 0 )
{
if ( symbol != 0 && address != 0 && (coin= iguana_coinfind(symbol)) != 0 && coin->DEXEXPLORER != 0 )
return(jprint(kmd_listspent(myinfo,coin,address),1));
if ( coin != 0 )
coin->DEXEXPLORER = myinfo->DEXEXPLORER * myinfo->IAMNOTARY * (iguana_isnotarychain(coin->symbol) >= 0);
}
if ( symbol != 0 && address != 0 )
return(_dex_listspent(myinfo,symbol,address));
else return(clonestr("{\"error\":\"dex listspent null symbol, address or coin\"}"));
}
TWO_STRINGS(dex,getbalance,symbol,address)
{
char url[512],*retstr; cJSON *retjson; uint64_t val;
if ( myinfo->DEXEXPLORER != 0 )
{
if ( symbol != 0 && address != 0 && (coin= iguana_coinfind(symbol)) != 0 && coin->DEXEXPLORER != 0 )
return(jprint(kmd_getbalance(myinfo,coin,address),1));
if ( coin != 0 )
coin->DEXEXPLORER = myinfo->DEXEXPLORER * myinfo->IAMNOTARY * (iguana_isnotarychain(coin->symbol) >= 0);
}
if ( symbol != 0 && address != 0 )
{
if ( strcmp(symbol,"BTC") == 0 && myinfo->blocktrail_apikey[0] != 0 )
{
sprintf(url,"https://api.blocktrail.com/v1/btc/address/%s?api_key=%s",address,myinfo->blocktrail_apikey);
if ( (retstr= issue_curl(url)) != 0 )
{
if ( (retjson= cJSON_Parse(retstr)) != 0 )
{
//printf("balance\n");
if ( (val= j64bits(retjson,"balance")) != 0 )
{
jdelete(retjson,"balance");
jaddnum(retjson,"balance",dstr(val));
}
//printf("sent\n");
if ( (val= j64bits(retjson,"sent")) != 0 )
{
jdelete(retjson,"sent");
jaddnum(retjson,"sent",dstr(val));
}
//printf("received\n");
if ( (val= j64bits(retjson,"received")) != 0 )
{
jdelete(retjson,"received");
jaddnum(retjson,"received",dstr(val));
}
//printf("unconfirmed_sent\n");
if ( (val= j64bits(retjson,"unconfirmed_sent")) != 0 )
{
jdelete(retjson,"unconfirmed_sent");
jaddnum(retjson,"unconfirmed_sent",dstr(val));
}
//printf("unconfirmed_received\n");
if ( (val= j64bits(retjson,"unconfirmed_received")) != 0 )
{
jdelete(retjson,"unconfirmed_received");
jaddnum(retjson,"unconfirmed_received",dstr(val));
}
//printf("(%s) -> (%s)\n",retstr,jprint(retjson,0));
free(retstr);
retstr = jprint(retjson,1);
}
}
return(retstr);
}
return(_dex_getbalance(myinfo,symbol,address));
} else return(clonestr("{\"error\":\"dex getbalance null symbol, address or coin\"}"));
}
STRING_ARG(dex,explorer,symbol)
{
if ( symbol != 0 && (coin= iguana_coinfind(symbol)) != 0 )
{
myinfo->DEXEXPLORER = 1;
coin->DEXEXPLORER = 1;
return(clonestr("{\"result\":\"success\"}"));
}
return(clonestr("{\"error\":\"coin not active\"}"));
}
#include "../includes/iguana_apiundefs.h"

261
iguana/iguana_payments.c

@ -175,7 +175,7 @@ int32_t iguana_RTbestunspent(struct supernet_info *myinfo,struct iguana_info *co
}
if ( iguana_RTunspent_check(myinfo,coin,unspents[i]) != 0 )
{
printf("(%d u%d) %.8f already used\n",unspents[i].hdrsi,unspents[i].unspentind,dstr(atx_value));
//printf("(%d u%d) %.8f already used\n",unspents[i].hdrsi,unspents[i].unspentind,dstr(atx_value));
continue;
}
if ( maxmode == 0 )
@ -274,7 +274,7 @@ char *iguana_signrawtx(struct supernet_info *myinfo,struct iguana_info *coin,int
memset(&msgtx,0,sizeof(msgtx));
if ( V == 0 )
V = calloc(numinputs,sizeof(*V)), flagV = 1;
//printf("SIGN.(%s) priv.(%s) %llx %llx\n",jprint(vins,0),jprint(privkeys,0),(long long)V->signers[0].privkey.txid,(long long)V->signers[1].privkey.txid);
//printf("SIGN.(%s) priv.(%s) %llx %llx (%s)\n",jprint(vins,0),jprint(privkeys,0),(long long)V->signers[0].privkey.txid,(long long)V->signers[1].privkey.txid,vins!=0?jprint(vins,0):"no vins");
if ( V != 0 )
{
if ( iguana_signrawtransaction(myinfo,coin,height,&msgtx,&signedtx,signedtxidp,V,numinputs,rawtx,vins,privkeys) > 0 )
@ -341,10 +341,40 @@ bits256 iguana_sendrawtransaction(struct supernet_info *myinfo,struct iguana_inf
return(txid);
}
uint64_t iguana_interest(struct supernet_info *myinfo,struct iguana_info *coin,bits256 txid,int32_t vout,uint64_t value)
uint64_t _iguana_interest(uint32_t now,int32_t chainheight,uint32_t txlocktime,uint64_t value)
{
char *retstr; int32_t height; cJSON *retjson; struct iguana_txid T,*tx;
int32_t minutes; uint64_t numerator=0,denominator=0,interest = 0;
if ( (minutes= ((uint32_t)time(NULL) - 60 - txlocktime) / 60) >= 60 )
{
if ( minutes > 365 * 24 * 60 )
minutes = 365 * 24 * 60;
if ( chainheight >= 250000 )
minutes -= 59;
denominator = (((uint64_t)365 * 24 * 60) / minutes);
if ( denominator == 0 )
denominator = 1; // max KOMODO_INTEREST per transfer, do it at least annually!
if ( value > 25000LL*SATOSHIDEN && chainheight > 155949 )
{
numerator = (value / 20); // assumes 5%!
if ( chainheight < 250000 )
interest = (numerator / denominator);
else interest = (numerator * minutes) / ((uint64_t)365 * 24 * 60);
}
else if ( value >= 10*SATOSHIDEN )
{
numerator = (value * KOMODO_INTEREST);
if ( chainheight < 250000 || numerator * minutes < 365 * 24 * 60 )
interest = (numerator / denominator) / SATOSHIDEN;
else interest = ((numerator * minutes) / ((uint64_t)365 * 24 * 60)) / SATOSHIDEN;
}
//fprintf(stderr,"komodo_interest.%d %lld %.8f nLockTime.%u tiptime.%u minutes.%d interest %lld %.8f (%llu / %llu)\n",chainheight,(long long)value,(double)value/SATOSHIDEN,txlocktime,now,minutes,(long long)interest,(double)interest/SATOSHIDEN,(long long)numerator,(long long)denominator);
}
return(interest);
}
uint64_t iguana_interest(struct supernet_info *myinfo,struct iguana_info *coin,bits256 txid,int32_t vout,uint64_t value)
{
char *retstr; int32_t height; cJSON *retjson=0; struct iguana_txid T,*tx; uint64_t interest=0;
if ( coin->FULLNODE < 0 ) // komodod is running
{
if ( (retjson= dpow_gettxout(myinfo,coin,txid,vout)) != 0 )
@ -367,28 +397,11 @@ uint64_t iguana_interest(struct supernet_info *myinfo,struct iguana_info *coin,b
}
else // we have it local
{
if ( (tx= iguana_txidfind(coin,&height,&T,txid,coin->bundlescount)) != 0 && tx->locktime >LOCKTIME_THRESHOLD )
if ( (tx= iguana_txidfind(coin,&height,&T,txid,coin->bundlescount)) != 0 && tx->locktime > LOCKTIME_THRESHOLD )
{
if ( (minutes= ((uint32_t)time(NULL) - 60 - tx->locktime) / 60) >= 60 )
{
denominator = (((uint64_t)365 * 24 * 60) / minutes);
if ( denominator == 0 )
denominator = 1; // max KOMODO_INTEREST per transfer, do it at least annually!
if ( value > 25000LL*SATOSHIDEN && height > 155949 )
{
numerator = (value / 20); // assumes 5%!
interest = (numerator / denominator);
}
else if ( value >= 10*SATOSHIDEN )
{
numerator = (value * KOMODO_INTEREST);
interest = (numerator / denominator) / SATOSHIDEN;
}
fprintf(stderr,"komodo_interest %lld %.8f nLockTime.%u tiptime.%u minutes.%d interest %lld %.8f (%llu / %llu)\n",(long long)value,(double)value/SATOSHIDEN,tx->locktime,(uint32_t)time(NULL),minutes,(long long)interest,(double)interest/SATOSHIDEN,(long long)numerator,(long long)denominator);
}
interest = _iguana_interest((uint32_t)time(NULL),coin->longestchain,tx->locktime,value);
}
}
char str[65]; printf("interest for %s.v%d %.8f %.8f\n",bits256_str(str,txid),vout,dstr(value),dstr(interest));
return(interest);
}
@ -410,7 +423,7 @@ uint64_t iguana_interests(struct supernet_info *myinfo,struct iguana_info *coin,
char *iguana_calcrawtx(struct supernet_info *myinfo,struct iguana_info *coin,cJSON **vinsp,cJSON *txobj,int64_t satoshis,char *changeaddr,int64_t txfee,cJSON *addresses,int32_t minconf,uint8_t *opreturn,int32_t oplen,int64_t burnamount,char *remoteaddr,struct vin_info *V,int32_t maxmode)
{
uint8_t addrtype,rmd160[20],spendscript[IGUANA_MAXSCRIPTSIZE]; char *coinaddr; int32_t allocflag=0,max,i,j,m,n,num,spendlen; char *spendscriptstr,*rawtx=0; bits256 txid; cJSON *vins=0,*array,*item; uint64_t value,avail=0,total,change; struct iguana_outpoint *unspents = 0;
uint8_t addrtype,rmd160[20],spendscript[IGUANA_MAXSCRIPTSIZE]; char *coinaddr; int32_t allocflag=0,max,i,j,m,n,num,spendlen; char *spendscriptstr,*rawtx=0; bits256 txid; cJSON *vins=0,*array,*item; uint64_t value,avail=0,total,change,interest; struct iguana_outpoint *unspents = 0;
*vinsp = 0;
max = 0;//10000;
satoshis += burnamount;
@ -436,6 +449,8 @@ char *iguana_calcrawtx(struct supernet_info *myinfo,struct iguana_info *coin,cJS
}
unspents = realloc(unspents,(1 + max) * sizeof(*unspents));
value = jdouble(item,"amount") * SATOSHIDEN;
if ( (0) && jdouble(item,"interest") != 0 )
printf("utxo has interest of %.8f\n",jdouble(item,"interest"));
iguana_outptset(myinfo,coin,&unspents[max++],jbits256(item,"txid"),jint(item,"vout"),value,spendscriptstr);
avail += value;
}
@ -452,13 +467,19 @@ char *iguana_calcrawtx(struct supernet_info *myinfo,struct iguana_info *coin,cJS
free(unspents);
return(0);
}*/
printf("avail %.8f satoshis %.8f, txfee %.8f burnamount %.8f vin0.scriptlen %d\n",dstr(avail),dstr(satoshis),dstr(txfee),dstr(burnamount),unspents[0].spendlen);
printf("avail %.8f satoshis %.8f, txfee %.8f burnamount %.8f vin0.scriptlen %d num.%d\n",dstr(avail),dstr(satoshis),dstr(txfee),dstr(burnamount),unspents[0].spendlen,num);
if ( txobj != 0 && avail >= satoshis+txfee )
{
if ( (vins= iguana_RTinputsjson(myinfo,coin,&total,satoshis + txfee,unspents,num,maxmode)) != 0 )
{
if ( strcmp(coin->symbol,"KMD") == 0 )
total += iguana_interests(myinfo,coin,vins);
{
if ( (interest= iguana_interests(myinfo,coin,vins)) != 0 )
{
total += interest;
printf("boost total by interest %.8f\n",dstr(interest));
}
}
if ( total < (satoshis + txfee) )
{
free_json(vins);
@ -510,6 +531,91 @@ char *iguana_calcrawtx(struct supernet_info *myinfo,struct iguana_info *coin,cJS
return(rawtx);
}
char *iguana_calcutxorawtx(struct supernet_info *myinfo,struct iguana_info *coin,cJSON **vinsp,cJSON *txobj,int64_t satoshis,char *changeaddr,int64_t txfee,cJSON *utxos,char *remoteaddr,struct vin_info *V,int32_t maxmode)
{
uint8_t addrtype,rmd160[20],spendscript[IGUANA_MAXSCRIPTSIZE]; int32_t allocflag=0,max,i,n,num,spendlen; char *spendscriptstr,*rawtx=0; bits256 txid; cJSON *sobj,*vins=0,*item; uint64_t value,avail=0,total,change,interests; struct iguana_outpoint *unspents = 0;
*vinsp = 0;
max = 0;
interests = 0;
if ( (n= cJSON_GetArraySize(utxos)) == 0 )
return(0);
for (i=0; i<n; i++)
{
item = jitem(utxos,i);
if ( (spendscriptstr= jstr(item,"scriptPubKey")) != 0 && is_hexstr(spendscriptstr,0) > 16 )
{
}
else if ( (sobj= jobj(item,"scriptPubKey")) == 0 || (spendscriptstr= jstr(sobj,"hex")) == 0 )
{
printf("no spendscript (%s)\n",jprint(item,0));
continue;
}
unspents = realloc(unspents,(1 + max) * sizeof(*unspents));
value = jdouble(item,"value") * SATOSHIDEN;
interests += SATOSHIDEN * jdouble(item,"interest");
iguana_outptset(myinfo,coin,&unspents[max++],jbits256(item,"txid"),jint(item,"vout"),value,spendscriptstr);
avail += value;
}
if ( unspents == 0 )
return(0);
num = max;
printf("avail %.8f interests %.8f satoshis %.8f, txfee %.8f vin0.scriptlen %d\n",dstr(avail),dstr(interests),dstr(satoshis),dstr(txfee),unspents[0].spendlen);
if ( txobj != 0 && avail >= satoshis+txfee )
{
if ( (vins= iguana_RTinputsjson(myinfo,coin,&total,satoshis + txfee,unspents,num,maxmode)) != 0 )
{
if ( strcmp(coin->symbol,"KMD") == 0 )
{
if ( (interests= iguana_interests(myinfo,coin,vins)) != 0 )
{
total += interests;
printf("boost total by interest %.8f\n",dstr(interests));
}
}
if ( total < (satoshis + txfee) )
{
free_json(vins);
free(unspents);
printf("insufficient total %.8f vs (%.8f + %.8f)\n",dstr(total),dstr(satoshis),dstr(txfee));
return(0);
}
if ( (change= (total - (satoshis + txfee))) > 10000 && (changeaddr == 0 || changeaddr[0] == 0) )
{
printf("no changeaddr for %.8f\n",dstr(change));
free_json(vins);
free(unspents);
return(0);
}
iguana_createvins(myinfo,coin,txobj,vins);
if ( change > 10000 )
{
if ( iguana_addressvalidate(coin,&addrtype,changeaddr) < 0 )
{
free_json(vins);
free(unspents);
printf("illegal destination address.(%s)\n",changeaddr);
return(0);
}
bitcoin_addr2rmd160(&addrtype,rmd160,changeaddr);
spendlen = bitcoin_standardspend(spendscript,0,rmd160);
bitcoin_txoutput(txobj,spendscript,spendlen,change);
}
if ( vins != 0 && V == 0 )
{
V = calloc(cJSON_GetArraySize(vins),sizeof(*V)), allocflag = 1;
//iguana_vinprivkeys(myinfo,coin,V,vins);
}
rawtx = bitcoin_json2hex(myinfo,coin,&txid,txobj,V);
if ( allocflag != 0 )
free(V);
}
}
free(unspents);
*vinsp = vins;
return(rawtx);
}
void iguana_RTunspentslock(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *vins)
{
struct iguana_outpoint spentpt; char coinaddr[64]; int32_t i,RTspentflag,num,spentheight,lockedflag;
@ -557,7 +663,7 @@ char *sendtoaddress(struct supernet_info *myinfo,struct iguana_info *coin,char *
jaddnum(valsobj,"basilisktag",basilisktag);
jaddnum(valsobj,"locktime",locktime);
jaddnum(valsobj,"timeout",30000);
if ( 0 && comment != 0 && is_hexstr(comment,0) > 0 )
if ( (0) && comment != 0 && is_hexstr(comment,0) > 0 )
jaddstr(valsobj,"opreturn",comment);
if ( (retstr= basilisk_bitcoinrawtx(myinfo,coin,remoteaddr,basilisktag,jint(valsobj,"timeout"),valsobj,V)) != 0 )
{
@ -602,6 +708,7 @@ char *sendtoaddress(struct supernet_info *myinfo,struct iguana_info *coin,char *
#include "../includes/iguana_apidefs.h"
#include "../includes/iguana_apideclares.h"
#include "../includes/iguana_apideclares2.h"
STRING_AND_INT(bitcoinrpc,sendrawtransaction,rawtx,allowhighfees)
{
@ -973,6 +1080,7 @@ HASH_AND_INT(bitcoinrpc,getrawtransaction,txid,verbose)
if ( coin->notarychain >= 0 && coin->FULLNODE == 0 )
return(_dex_getrawtransaction(myinfo,coin->symbol,txid));
HASH_FIND(hh,coin->RTdataset,txid.bytes,sizeof(txid),RTptr);
memset(checktxid.bytes,0,sizeof(checktxid));
if ( RTptr != 0 && RTptr->rawtxbytes != 0 && RTptr->txlen > 0 )
{
checktxid = RTptr->txid;
@ -1061,7 +1169,7 @@ char *iguana_validaterawtx(struct supernet_info *myinfo,struct iguana_info *coin
if ( (txobj= bitcoin_hex2json(coin,coin->blocks.hwmchain.height,&msgtx->txid,msgtx,rawtx,extraspace,extralen,0,0,suppress_pubkeys)) != 0 )
{
//printf("txobj.(%s)\n",jprint(txobj,0));
if ( 0 && (checkstr= bitcoin_json2hex(myinfo,coin,&txid,txobj,0)) != 0 )
if ( (0) && (checkstr= bitcoin_json2hex(myinfo,coin,&txid,txobj,0)) != 0 )
{
// no guarantee byte for byte identical tx is recreated
if ( strcmp(rawtx,checkstr) != 0 )
@ -1074,7 +1182,7 @@ char *iguana_validaterawtx(struct supernet_info *myinfo,struct iguana_info *coin
break;
jaddnum(retjson,"mismatch position",i);
jadd(retjson,"origtx",txobj);
if ( 0 && (txobj= bitcoin_hex2json(coin,coin->blocks.hwmchain.height,&txid,msgtx,checkstr,extraspace,extralen,0,0,suppress_pubkeys)) != 0 )
if ( (0) && (txobj= bitcoin_hex2json(coin,coin->blocks.hwmchain.height,&txid,msgtx,checkstr,extraspace,extralen,0,0,suppress_pubkeys)) != 0 )
jadd(retjson,"checktx",txobj);
free(checkstr);
return(jprint(retjson,1));
@ -1586,4 +1694,99 @@ THREE_INTS(iguana,splitfunds,satoshis,duplicates,sendflag)
return(jprint(retjson,1));
}
P2SH_SPENDAPI(iguana,spendmsig,activecoin,vintxid,vinvout,destaddress,destamount,destaddress2,destamount2,M,N,pubA,wifA,pubB,wifB,pubC,wifC)
{
struct vin_info V; uint8_t p2sh_rmd160[20],serialized[2096],spendscript[32],pubkeys[3][65],*pubkeyptrs[3]; int32_t spendlen,height = 0;
char msigaddr[64],*retstr; cJSON *retjson,*txobj; struct iguana_info *active;
bits256 signedtxid; char *signedtx;
struct iguana_msgtx msgtx;
if ( remoteaddr != 0 )
return(clonestr("{\"error\":\"no remote\"}"));
if ( myinfo->expiration == 0 )
return(clonestr("{\"error\":\"need to unlock wallet\"}"));
if ( (active= iguana_coinfind(activecoin)) == 0 )
return(clonestr("{\"error\":\"activecoin isnt active\"}"));
if ( M > N || N > 3 )
return(clonestr("{\"error\":\"illegal M or N\"}"));
memset(&V,0,sizeof(V));
txobj = bitcoin_txcreate(active->symbol,active->chain->isPoS,0,coin->chain->normal_txversion,0);
if ( destaddress[0] != 0 && destamount > 0. )
bitcoin_txaddspend(active,txobj,destaddress,destamount * SATOSHIDEN);
if ( destaddress2[0] != 0 && destamount2 > 0. )
bitcoin_txaddspend(active,txobj,destaddress2,destamount2 * SATOSHIDEN);
if ( pubA[0] != 0 && (retstr= _setVsigner(active,&V,0,pubA,wifA)) != 0 )
return(retstr);
if ( N >= 2 && pubB[0] != 0 && (retstr= _setVsigner(active,&V,1,pubB,wifB)) != 0 )
return(retstr);
if ( N == 3 && pubC[0] != 0 && (retstr= _setVsigner(active,&V,2,pubC,wifC)) != 0 )
return(retstr);
V.M = M, V.N = N, V.type = IGUANA_SCRIPT_P2SH;
V.p2shlen = bitcoin_MofNspendscript(p2sh_rmd160,V.p2shscript,0,&V);
spendlen = bitcoin_p2shspend(spendscript,0,p2sh_rmd160);
if ( pubA[0] != 0 )
{
decode_hex(pubkeys[0],(int32_t)strlen(pubA)>>1,pubA);
pubkeyptrs[0] = pubkeys[0];
}
if ( pubB[0] != 0 )
{
decode_hex(pubkeys[1],(int32_t)strlen(pubB)>>1,pubB);
pubkeyptrs[1] = pubkeys[1];
}
if ( pubC[0] != 0 )
{
decode_hex(pubkeys[2],(int32_t)strlen(pubC)>>1,pubC);
pubkeyptrs[2] = pubkeys[2];
}
bitcoin_txinput(active,txobj,vintxid,vinvout,0xffffffff,spendscript,spendlen,V.p2shscript,V.p2shlen,pubkeyptrs,N,0,0);
bitcoin_address(msigaddr,active->chain->p2shtype,V.p2shscript,V.p2shlen);
retjson = cJSON_CreateObject();
if ( bitcoin_verifyvins(active,height,&signedtxid,&signedtx,&msgtx,serialized,sizeof(serialized),&V,SIGHASH_ALL,1,V.suppress_pubkeys) == 0 )
{
jaddstr(retjson,"result","msigtx");
if ( signedtx != 0 )
jaddstr(retjson,"signedtx",signedtx), free(signedtx);
jaddbits256(retjson,"txid",signedtxid);
} else jaddstr(retjson,"error","couldnt sign tx");
jaddstr(retjson,"msigaddr",msigaddr);
return(jprint(retjson,1));
}
STRING_ARRAY_OBJ_STRING(bitcoinrpc,signrawtransaction,rawtx,vins,privkeys,sighash)
{
char *signedtx = 0; struct vin_info *V; bits256 signedtxid; int32_t complete,numinputs = 1; struct iguana_msgtx msgtx; cJSON *retjson; int uselessbitcoin_error = 0;
retjson = cJSON_CreateObject();
if ( remoteaddr != 0 )
return(clonestr("{\"error\":\"no remote\"}"));
if ( myinfo->expiration == 0 )
return(clonestr("{\"error\":\"need to unlock wallet\"}"));
//printf("rawtx.(%s) vins.(%s) privkeys.(%s) sighash.(%s)\n",rawtx,jprint(vins,0),jprint(privkeys,0),sighash);
if ( sighash == 0 || sighash[0] == 0 )
sighash = "ALL";
if ( strcmp(sighash,"ALL") != 0 )
jaddstr(retjson,"error","only sighash all (ALL) supported for now");
if ( (numinputs= cJSON_GetArraySize(vins)) > 0 )
{
V = calloc(numinputs,sizeof(*V));
memset(&msgtx,0,sizeof(msgtx));
if ( (complete= iguana_signrawtransaction(myinfo,coin,coin->blocks.hwmchain.height,&msgtx,&signedtx,&signedtxid,V,numinputs,rawtx,vins,privkeys)) >= 0 )
{
if ( signedtx != 0 )
{
jaddstr(retjson,"result",signedtx);
jadd(retjson,"complete",complete!=0?jtrue():jfalse());
free(signedtx);
} else jaddstr(retjson,"error",uselessbitcoin_error != 0 ? "-22" : "no transaction from verifyvins");
}
else if ( complete == -2 )
jaddstr(retjson,"error",uselessbitcoin_error != 0 ? "-22" : "hex2json -> json2hex error");
else if ( complete == -1 )
jaddstr(retjson,"error",uselessbitcoin_error != 0 ? "-22" : "couldnt load serialized tx or mismatched numinputs");
free(V);
//for (i=0; i<msgtx.tx_in; i++)
// if ( msgtx.vins[i].redeemscript != 0 )
// free(msgtx.vins[i].redeemscript), msgtx.vins[i].redeemscript = 0;
} else jaddstr(retjson,"error",uselessbitcoin_error != 0 ? "-22" : "no rawtx or rawtx too big");
return(jprint(retjson,1));
}
#include "../includes/iguana_apiundefs.h"

12
iguana/iguana_peers.c

@ -594,7 +594,7 @@ int32_t iguana_send(struct iguana_info *coin,struct iguana_peer *addr,uint8_t *s
}
}
addr->totalsent += len;
if ( 0 && addr->basilisk != 0 )
if ( (0) && addr->basilisk != 0 )
printf("verack.%d (%s) sent.%d bytes to %s\n",addr->msgcounts.verack,cmdstr,len,addr->ipaddr);
return(len);
}
@ -623,7 +623,7 @@ int32_t iguana_queue_send(struct iguana_peer *addr,int32_t delay,uint8_t *serial
packet->embargo.millis += delay;
}
memcpy(packet->serialized,serialized,datalen);
if ( 0 && addr->supernet != 0 )
if ( (0) && addr->supernet != 0 )
printf("%p queue send.(%s) %d to (%s)\n",packet,serialized+4,datalen,addr->ipaddr);
queue_enqueue("sendQ",&addr->sendQ,&packet->DL);
return(datalen);
@ -1050,7 +1050,7 @@ int32_t iguana_pollsendQ(struct iguana_info *coin,struct iguana_peer *addr)
struct iguana_packet *packet;
if ( (packet= queue_dequeue(&addr->sendQ)) != 0 )
{
if ( 0 && (addr->supernet != 0 || strcmp((char *)&packet->serialized[4],"SuperNET") == 0) )
if ( (0) && (addr->supernet != 0 || strcmp((char *)&packet->serialized[4],"SuperNET") == 0) )
printf("%s: send.(%s).%d usock.%d dead.%u ready.%u supernet.%d\n",addr->ipaddr,packet->serialized+4,packet->datalen,addr->usock,addr->dead,addr->ready,addr->supernet);
if ( strcmp((char *)&packet->serialized[4],"getdata") == 0 )
{
@ -1385,18 +1385,18 @@ void iguana_dedicatedloop(struct supernet_info *myinfo,struct iguana_info *coin,
}
}
//printf(">>>>>>>>>>>>>> finish %s dedicatedloop.%s\n",coin->symbol,addr->ipaddr);
if ( 0 )
if ( (0) )
{
if ( addr->vinsfp != 0 )
fclose(addr->vinsfp), addr->vinsfp = 0;
if ( addr->voutsfp != 0 )
fclose(addr->voutsfp), addr->voutsfp = 0;
fclose(addr->voutsfp), addr->voutsfp = 0;
}
iguana_iAkill(coin,addr,addr->dead != 0);
myfree(buf,bufsize);
//if ( addr->filehash2 != 0 )
// myfree(addr->filehash2,addr->maxfilehash2*sizeof(*addr->filehash2)), addr->filehash2 = 0;
if ( 0 )
if ( (0) )
{
iguana_mempurge(&addr->RAWMEM);
iguana_mempurge(&addr->TXDATA);

64
iguana/iguana_ramchain.c

@ -56,7 +56,7 @@ struct iguana_kvitem *iguana_hashsetPT(struct iguana_ramchain *ramchain,int32_t
printf("fatal alloc errorC in hashset\n");
iguana_exit(0,0);
}
if ( 0 && ramchain->expanded && selector == 'T' )
if ( (0) && ramchain->expanded && selector == 'T' )
printf("hashmem.%p selector.%c added.(%s) itemind.%x ptr.%p\n",ramchain->hashmem,selector,str,itemind,ptr);
if ( selector == 'T' )
HASH_ADD_KEYPTR(hh,ramchain->txids,key,keylen,ptr);
@ -64,14 +64,14 @@ struct iguana_kvitem *iguana_hashsetPT(struct iguana_ramchain *ramchain,int32_t
ptr->hh.itemind = itemind;
//if ( strcmp(str,"0000000000000000000000000000000000000000000000000000000000000000") == 0 )
// printf("added null txid?\n"), getchar();
if ( 0 && ramchain->expanded && selector == 'T' )
if ( (0) && ramchain->expanded && selector == 'T' )
printf("selector.%c added.(%s) itemind.%x ptr.%p tmp.%p\n",selector,str,itemind,ptr,tmp);
if ( itemind == 0 )
{
printf("negative itemind\n");
iguana_exit(0,0);
}
if ( 0 )
if ( (0) )
{
if ( selector == 'T' )
HASH_FIND(hh,ramchain->txids,key,keylen,tmp);
@ -88,7 +88,7 @@ struct iguana_kvitem *iguana_hashsetPT(struct iguana_ramchain *ramchain,int32_t
void iguana_blocksetcounters(struct iguana_info *coin,struct iguana_block *block,struct iguana_ramchain * ramchain)
{
if ( 0 && coin->virtualchain != 0 )
if ( (0) && coin->virtualchain != 0 )
printf("iguana_blocksetcounters.%s 1st txidind.%u <- ht.%d\n",coin->symbol,ramchain->H.txidind,block->height);
block->RO.firsttxidind = ramchain->H.txidind;
block->RO.firstvout = ramchain->H.unspentind;
@ -110,7 +110,7 @@ int32_t iguana_peerfname(struct iguana_info *coin,int32_t *hdrsip,char *dirname,
bp = 0, bundlei = -2;
if ( bits256_nonz(prevhash2) == 0 || (bp= iguana_bundlefind(coin,&bp,&bundlei,prevhash2)) == 0 || bundlei >= coin->chain->bundlesize-1 )
{
if ( 0 && dispflag != 0 )
if ( (0) && dispflag != 0 )
printf("iguana_peerfname %s error finding.(%s) spec.%p bp.%p\n",coin->symbol,bits256_str(str,hash2),bp!=0?bp->speculative:0,bp);
return(-2);
} else bundlei++;
@ -191,7 +191,7 @@ uint32_t iguana_ramchain_addtxid(struct iguana_info *coin,RAMCHAIN_FUNC,bits256
}
else
{
if ( 0 && ramchain->expanded != 0 )
if ( (0) && ramchain->expanded != 0 )
printf("T.%p txidind.%d numvouts.%d numvins.%d\n",T,txidind,numvouts,numvins);
t->txidind = txidind, t->txid = txid, t->numvouts = numvouts, t->numvins = numvins;
t->bundlei = bundlei;
@ -464,7 +464,7 @@ uint32_t iguana_ramchain_addspend(struct iguana_info *coin,RAMCHAIN_FUNC,bits256
{
external = 1;
txidind = ramchain->externalind++;
if ( 0 && ramchain->expanded != 0 )
if ( (0) && ramchain->expanded != 0 )
{ char str[65]; printf("%p X[%d] <- %s\n",X,txidind,bits256_str(str,prev_hash)); }
if ( ramchain->H.ROflag != 0 )
{
@ -580,7 +580,7 @@ uint32_t iguana_ramchain_addspend256(struct iguana_info *coin,struct iguana_peer
} else s->scriptpos = 0;
//else printf("spend256 scriptfpos.%d\n",s->scriptfpos);
char str[65];
if ( 0 && coin->virtualchain != 0 )
if ( (0) && coin->virtualchain != 0 )
printf("W.%p s.%d vout.%d/%d [%d] %s fpos.%u slen.%d\n",s,spendind,s->prevout,prev_vout,bp->hdrsi,bits256_str(str,prev_hash),(uint32_t)s->scriptpos,(int32_t)s->vinscriptlen);
}
return(spendind);
@ -813,7 +813,7 @@ int64_t _iguana_rdata_action(char *fname,FILE *fp,bits256 lhashes[IGUANA_NUMLHAS
//P2 = 0;//iguana_ramchain_offset(fname,rdata,RAMCHAIN_LARG(IGUANA_LHASH_FIRSTSPENDS),fparg,fpos,P2,&offset,(sizeof(struct iguana_pkextra) * numpkinds),srcsize);
A = iguana_ramchain_offset(fname,rdata,RAMCHAIN_LARG(IGUANA_LHASH_ACCOUNTS),fparg,fpos,A,&offset,(sizeof(struct iguana_account) * numpkinds),srcsize);
char str[65];
if ( 0 && X != 0 )
if ( (0) && X != 0 )
printf("%p X[1] -> %s\n",&X[1],bits256_str(str,X[1]));
X = iguana_ramchain_offset(fname,rdata,RAMCHAIN_LARG(IGUANA_LHASH_EXTERNALS),fparg,fpos,X,&offset,(sizeof(bits256) * numexternaltxids),srcsize);
TXbits = iguana_ramchain_offset(fname,rdata,RAMCHAIN_LARG(IGUANA_LHASH_TXBITS),fparg,fpos,TXbits,&offset,hconv_bitlen(txbits),srcsize);
@ -823,7 +823,7 @@ int64_t _iguana_rdata_action(char *fname,FILE *fp,bits256 lhashes[IGUANA_NUMLHAS
{
Ux = destptr, Sx = destptr, P = destptr, A = destptr, X = destptr, TXbits = destptr, PKbits = destptr, Kspace = destptr; //U2 = destptr, P2 = destptr,
U = iguana_ramchain_offset(fname,rdata,RAMCHAIN_LARG(IGUANA_LHASH_UNSPENTS),fparg,fpos,U,&offset,(sizeof(struct iguana_unspent20) * numunspents),srcsize);
if ( 0 && lhashes != 0 )
if ( (0) && lhashes != 0 )
printf("iter.%d lhashes.%p offset.%ld destptr.%p len.%ld fparg.%p fpos.%ld srcsize.%ld\n",iter,RAMCHAIN_LARG(IGUANA_LHASH_SPENDS),(long)offset,destptr,(long)sizeof(struct iguana_spend256) * numspends,fparg,(long)fpos,(long)srcsize);
S = iguana_ramchain_offset(fname,rdata,RAMCHAIN_LARG(IGUANA_LHASH_SPENDS),fparg,fpos,S,&offset,(sizeof(struct iguana_spend256) * numspends),srcsize);
}
@ -871,7 +871,7 @@ int64_t _iguana_rdata_action(char *fname,FILE *fp,bits256 lhashes[IGUANA_NUMLHAS
int64_t iguana_ramchain_action(char *fname,RAMCHAIN_FUNC,FILE *fp,bits256 lhashes[IGUANA_NUMLHASHES],struct iguana_ramchaindata *destdata,uint64_t fpos,struct iguana_ramchaindata *srcdata,int32_t numblocks,int32_t scriptspace,uint8_t zcash)
{
if ( 0 && ramchain->expanded == 0 )
if ( (0) && ramchain->expanded == 0 )
printf("action.%p (%p %p %p) %ld allocated.%ld [%d:%d %d:%d]\n",srcdata,fp,lhashes,destdata,(long)fpos,(long)srcdata->allocsize,srcdata->txsparsebits,srcdata->numtxsparse,srcdata->pksparsebits,srcdata->numpksparse);
return(_iguana_rdata_action(fname,fp,lhashes,destdata,fpos,ramchain->expanded,srcdata->numtxids,srcdata->numunspents,srcdata->numspends,srcdata->numpkinds,srcdata->numexternaltxids,scriptspace,srcdata->txsparsebits,srcdata->numtxsparse,srcdata->pksparsebits,srcdata->numpksparse,srcdata->allocsize,RAMCHAIN_ARG,numblocks,zcash));
}
@ -882,7 +882,7 @@ int64_t iguana_ramchain_size(char *fname,RAMCHAIN_FUNC,int32_t numblocks,int32_t
if ( (rdata= ramchain->H.data) != 0 )
{
allocsize = iguana_ramchain_action(fname,RAMCHAIN_ARG,0,0,0,0,rdata,numblocks,scriptspace,zcash);
if ( 0 && ramchain->expanded != 0 )
if ( (0) && ramchain->expanded != 0 )
printf("%p iguana_ramchain_size.expanded.%d %u: Koffset.%u scriptoffset.%u stacksize.%u stackspace.%u [%u]\n",ramchain,ramchain->expanded,(int32_t)allocsize,(int32_t)rdata->Koffset,(int32_t)ramchain->H.scriptoffset,(int32_t)ramchain->H.stacksize,(int32_t)rdata->stackspace,scriptspace);
}
return(allocsize);
@ -902,7 +902,7 @@ long iguana_ramchain_setsize(char *fname,struct iguana_ramchain *ramchain,struct
rdata->scriptspace = ramchain->H.scriptoffset;
rdata->stackspace = ramchain->H.stacksize;
rdata->allocsize = iguana_ramchain_size(fname,RAMCHAIN_ARG,numblocks,rdata->scriptspace,zcash);
if ( 0 && rdata->scriptspace != 0 )
if ( (0) && rdata->scriptspace != 0 )
printf("iguana_ramchain_setsize: Koffset.%d scriptspace.%d stackspace.%d (scriptoffset.%d stacksize.%d) allocsize.%d\n",(int32_t)rdata->Koffset,(int32_t)rdata->scriptspace,(int32_t)rdata->stackspace,(int32_t)ramchain->H.scriptoffset,(int32_t)ramchain->H.stacksize,(int32_t)rdata->allocsize);
ramchain->datasize = rdata->allocsize;
return((long)rdata->allocsize);
@ -929,7 +929,7 @@ int64_t iguana_ramchain_saveaction(char *fname,RAMCHAIN_FUNC,FILE *fp,struct igu
before = ftell(fp);
iguana_ramchain_action(fname,RAMCHAIN_ARG,fp,0,rdata,0,rdata,numblocks,scriptspace,zcash);
after = ftell(fp);
if ( 0 && ramchain->expanded == 0 )
if ( (0) && ramchain->expanded == 0 )
{
int32_t i; for (i=0; i<scriptspace&&i<25; i++)
printf("%02x",Kspace[i]);
@ -964,7 +964,7 @@ int64_t iguana_ramchain_init(char *fname,struct iguana_ramchain *ramchain,struct
numpkinds = numunspents;
_iguana_rdata_action(fname,0,0,rdata,0,expanded,numtxids,numunspents,numspends,numpkinds,numexternaltxids,scriptspace,0,0,0,0,0,RAMCHAIN_ARG,numblocks,zcash);
offset += rdata->allocsize;
if ( 0 && expanded != 0 )
if ( (0) && expanded != 0 )
printf("init T.%d U.%d S.%d P.%d X.%d -> %ld\n",numtxids,numunspents,numspends,numpkinds,numexternaltxids,(long)offset);
if ( rdata->allocsize != iguana_ramchain_size(fname,RAMCHAIN_ARG,numblocks,scriptspace,zcash) )
{
@ -997,12 +997,12 @@ int32_t iguana_ramchain_alloc(char *fname,struct iguana_info *coin,struct iguana
memset(ramchain,0,sizeof(*ramchain));
ramchain->height = height;
allocsize = _iguana_rdata_action(fname,0,0,0,0,1,numtxids,numunspents,numspends,numpkinds,numexternaltxids,scriptspace,0,0,0,0,0,RAMCHAIN_ARG,numblocks,zcash);
if ( 0 && ramchain->expanded != 0 )
if ( (0) && ramchain->expanded != 0 )
printf("T.%d U.%d S.%d P.%d X.%d -> %ld\n",numtxids,numunspents,numspends,numpkinds,numexternaltxids,(long)allocsize);
memset(mem,0,sizeof(*mem));
memset(hashmem,0,sizeof(*hashmem));
hashsize = iguana_hashmemsize(numtxids,numunspents,numspends,numpkinds,numexternaltxids,scriptspace);
while ( 0 && (x= (myallocated(0,-1)+hashsize+allocsize + 65536)) > coin->MAXMEM )
while ( (0) && (x= (myallocated(0,-1)+hashsize+allocsize + 65536)) > coin->MAXMEM )
{
char str[65],str2[65]; fprintf(stderr,"ht.%d wait for allocated %s < MAXMEM %s | elapsed %.2f minutes hashsize.%ld allocsize.%ld\n",height,mbstr(str,myallocated(0,-1)+hashsize+allocsize),mbstr(str2,coin->MAXMEM),(double)(time(NULL)-coin->startutc)/60.,(long)hashsize,(long)allocsize);
sleep(13);
@ -1018,7 +1018,7 @@ int32_t iguana_ramchain_alloc(char *fname,struct iguana_info *coin,struct iguana
long iguana_ramchain_save(struct iguana_info *coin,RAMCHAIN_FUNC,uint32_t ipbits,bits256 hash2,bits256 prevhash2,int32_t bundlei,struct iguana_bundle *bp,uint8_t zcash)
{
struct iguana_ramchaindata *rdata,tmp; char fname[1024]; long fpos = -1; int32_t hdrsi,checki; FILE *fp;
struct iguana_ramchaindata *rdata,tmp; char fname[1024]; long fpos = -1; int32_t hdrsi,checki = 0; FILE *fp;
if ( (rdata= ramchain->H.data) == 0 )
{
printf("ramchainsave no data ptr\n");
@ -1045,7 +1045,7 @@ long iguana_ramchain_save(struct iguana_info *coin,RAMCHAIN_FUNC,uint32_t ipbits
iguana_ramchain_lhashes(fname,RAMCHAIN_ARG,rdata,rdata,bp!=0?bp->n:1,ramchain->H.scriptoffset,zcash);
tmp = *rdata;
iguana_ramchain_compact(fname,RAMCHAIN_ARG,&tmp,rdata,bp!=0?bp->n:1,zcash);
if ( 0 && ramchain->expanded != 0 )
if ( (0) && ramchain->expanded != 0 )
printf("compact.%s: Koffset.%d scriptoffset.%d stacksize.%d allocsize.%d\n",fname,(int32_t)rdata->Koffset,ramchain->H.scriptoffset,ramchain->H.stacksize,(int32_t)rdata->allocsize);
if ( fwrite(&tmp,1,sizeof(tmp),fp) != sizeof(tmp) )
{
@ -1346,7 +1346,7 @@ int32_t iguana_Xspendmap(struct iguana_info *coin,struct iguana_ramchain *ramcha
bp->startutxo = bp->utxofinish = (uint32_t)time(NULL);
if ( bp->Xvalid == 0 )
{
if ( 0 && (rand() % 10) == 0 )
if ( (0) && (rand() % 10) == 0 )
printf("[%d] filesize %ld Xspendptr.%p %p num.%d\n",bp->hdrsi,filesize,ramchain->Xspendptr,ramchain->Xspendinds,ramchain->numXspends);
bp->Xvalid = 1;
}
@ -1362,7 +1362,7 @@ int32_t iguana_Xspendmap(struct iguana_info *coin,struct iguana_ramchain *ramcha
ramchain->Xspendinds = 0;
}
}
else if ( 0 && iter == 1 )
else if ( (0) && iter == 1 )
printf("couldnt map.(%s)\n",fname);
}
return(ramchain->numXspends);
@ -1370,7 +1370,7 @@ int32_t iguana_Xspendmap(struct iguana_info *coin,struct iguana_ramchain *ramcha
struct iguana_ramchain *_iguana_ramchain_map(struct supernet_info *myinfo,struct iguana_info *coin,char *fname,struct iguana_bundle *bp,int32_t numblocks,struct iguana_ramchain *ramchain,struct OS_memspace *hashmem,uint32_t ipbits,bits256 hash2,bits256 prevhash2,int32_t bundlei,long fpos,int32_t allocextras,int32_t expanded,uint8_t zcash)
{
RAMCHAIN_DECLARE; int32_t valid,iter,i,checki,hdrsi; long filesize; void *ptr; char str[65],str2[65],dirstr[65]; struct iguana_block *block; struct iguana_zblockRO zRO; struct iguana_ramchaindata *rdata;
RAMCHAIN_DECLARE; int32_t valid,iter,i,checki,hdrsi; long filesize=0; void *ptr; char str[65],str2[65],dirstr[65]; struct iguana_block *block; struct iguana_zblockRO zRO; struct iguana_ramchaindata *rdata;
/*if ( ramchain->expanded != 0 && (ramchain->sigsfileptr == 0 || ramchain->sigsfilesize == 0) )
{
sprintf(sigsfname,"sigs/%s/%s",coin->symbol,bits256_str(str,hash2));
@ -1423,7 +1423,7 @@ struct iguana_ramchain *_iguana_ramchain_map(struct supernet_info *myinfo,struct
ramchain->expanded = expanded;
ramchain->numblocks = (bp == 0) ? 1 : bp->n;
//printf("ptr.%p exp.%d extra.%d %p mapped P[%d] fpos.%d + %ld -> %ld vs %ld offset.%u:%u stack.%u:%u\n",ptr,expanded,allocextras,rdata,(int32_t)rdata->Poffset,(int32_t)fpos,(long)rdata->allocsize,(long)(fpos + rdata->allocsize),ramchain->filesize,rscriptoffset,rdata->scriptspace,rstacksize,rdata->stackspace);
if ( 0 && bp != 0 )
if ( (0) && bp != 0 )
{
/*blocksRO = (struct iguana_blockRO *)rdata;
for (i=0; i<bp->n; i++)
@ -1637,7 +1637,7 @@ int32_t iguana_ramchain_cmp(struct iguana_ramchain *A,struct iguana_ramchain *B,
int32_t iguana_ramchain_iterate(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_ramchain *dest,struct iguana_ramchain *ramchain,struct iguana_bundle *bp,int16_t bundlei)
{
RAMCHAIN_DECLARE; RAMCHAIN_DESTDECLARE; RAMCHAIN_DESTZEROES;
int32_t j,hdrsi,prevout,scriptlen; uint32_t timestamp=0,unspentind,sequenceid,destspendind=0,desttxidind=0; uint16_t fileid; uint64_t scriptpos; int64_t crypto777_payment = 0;
int32_t j,hdrsi,prevout,scriptlen; uint32_t timestamp=0,unspentind,sequenceid=0,destspendind=0,desttxidind=0; uint16_t fileid; uint64_t scriptpos; int64_t crypto777_payment = 0;
bits256 prevhash; uint64_t value; uint8_t type; struct iguana_unspent *u;
struct iguana_txid *tx; struct iguana_ramchaindata *rdata; uint8_t rmd160[20];
//if ( dest != 0 )
@ -1667,7 +1667,7 @@ int32_t iguana_ramchain_iterate(struct supernet_info *myinfo,struct iguana_info
{
if ( coin->active == 0 )
return(-1);;
if ( 0 && ramchain->expanded == 0 && dest != 0 )
if ( (0) && ramchain->expanded == 0 && dest != 0 )
printf("ITER [%d] TXID.%d -> dest.%p desttxid.%d dest->hashmem.%p numtxids.%d\n",rdata->height,ramchain->H.txidind,dest,dest!=0?dest->H.txidind:0,dest!=0?dest->hashmem:0,rdata->numtxids);
tx = &T[ramchain->H.txidind];
if ( iguana_ramchain_addtxid(coin,RAMCHAIN_ARG,tx->txid,tx->numvouts,tx->numvins,tx->locktime,tx->version,tx->timestamp,bundlei) == 0 )
@ -1678,7 +1678,7 @@ int32_t iguana_ramchain_iterate(struct supernet_info *myinfo,struct iguana_info
if ( dest->expanded != 0 )
iguana_opreturn(myinfo,1,coin,tx->timestamp,bp,0,bp->bundleheight + bundlei,(((uint64_t)bp->hdrsi << 32) | dest->H.unspentind),0,0,0,0);
//char str[65];
if ( 0 && ramchain->expanded == 0 )
if ( (0) && ramchain->expanded == 0 )
printf("ITER [%d] TXID.%d -> dest.%p desttxid.%d dest->hashmem.%p numtxids.%d\n",rdata->height,ramchain->H.txidind,dest,dest!=0?dest->H.txidind:0,dest!=0?dest->hashmem:0,rdata->numtxids);
if ( iguana_ramchain_addtxid(coin,RAMCHAIN_DESTARG,tx->txid,tx->numvouts,tx->numvins,tx->locktime,tx->version,tx->timestamp,bundlei) == 0 )
return(-2);
@ -1689,6 +1689,7 @@ int32_t iguana_ramchain_iterate(struct supernet_info *myinfo,struct iguana_info
if ( coin->active == 0 )
return(-1);
fileid = 0;
unspentind = 0;
scriptpos = 0;
scriptlen = 0;
memset(rmd160,0,sizeof(rmd160));
@ -1740,7 +1741,7 @@ int32_t iguana_ramchain_iterate(struct supernet_info *myinfo,struct iguana_info
} //else printf("no script\n");*/
if ( (unspentind= iguana_ramchain_addunspent20(coin,0,RAMCHAIN_ARG,value,0,scriptlen,tx->txid,j,type,bp,rmd160)) == 0 )
return(-4);
if ( 0 )
if ( (0) )
{
int32_t i; for (i=0; i<20; i++)
printf("%02x",rmd160[i]);
@ -1839,7 +1840,7 @@ int32_t iguana_ramchain_iterate(struct supernet_info *myinfo,struct iguana_info
long iguana_ramchain_data(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_peer *addr,struct iguana_txblock *origtxdata,struct iguana_msgtx *txarray,int32_t txn_count,uint8_t *data,int32_t recvlen,struct iguana_bundle *bp,struct iguana_block *block)
{
int32_t verifyflag = 0;
RAMCHAIN_DECLARE; struct iguana_ramchain R,*mapchain,*ramchain = &addr->ramchain; struct iguana_msgtx *tx; char fname[1024]; uint8_t rmd160[20]; struct iguana_ramchaindata *rdata; int32_t i,j,fpos,pubkeysize,sigsize,subdir,firsti=1,err,flag,bundlei; uint32_t scriptspace,stackspace; struct iguana_blockRO RO;
RAMCHAIN_DECLARE; struct iguana_ramchain R,*mapchain,*ramchain = &addr->ramchain; struct iguana_msgtx *tx; char fname[1024]; uint8_t rmd160[20]; struct iguana_ramchaindata *rdata; int32_t i,j,fpos,pubkeysize,sigsize,subdir,firsti=1,err,flag,bundlei=0; uint32_t scriptspace,stackspace; struct iguana_blockRO RO;
if ( block == 0 || bp == 0 || addr == 0 || (block != 0 && (bundlei= block->bundlei) < 0) )
{
//printf("iguana_ramchain_data: null ptr %p %p %p\n",block,bp,addr);
@ -2028,7 +2029,7 @@ void iguana_blockdelete(struct iguana_info *coin,bits256 hash2,int32_t i)
void iguana_blockunmark(struct iguana_info *coin,struct iguana_block *block,struct iguana_bundle *bp,int32_t i,int32_t deletefile)
{
void *ptr; int32_t recvlen,height = -1;
if ( 0 && bp != 0 )
if ( (0) && bp != 0 )
printf("UNMARK.[%d:%d]\n",bp->hdrsi,i);
if ( block != 0 )
{
@ -2056,7 +2057,7 @@ void iguana_blockunmark(struct iguana_info *coin,struct iguana_block *block,stru
}
if ( deletefile != 0 && block != 0 )
iguana_blockdelete(coin,block->RO.hash2,i);
if ( 0 && coin->RTheight > 0 && height > 0 && height < coin->blocks.hwmchain.height )
if ( (0) && coin->RTheight > 0 && height > 0 && height < coin->blocks.hwmchain.height )
{
printf("reduce %s HWM height from %d to %d\n",coin->symbol,coin->blocks.hwmchain.height,height);
if ( (block= iguana_blockfind("unmark",coin,iguana_blockhash(coin,height))) != 0 )
@ -2188,9 +2189,6 @@ void iguana_bundlemapfree(struct iguana_info *coin,struct OS_memspace *mem,struc
{
for (j=starti; j<=endi; j++)
{
//printf("R[%d]\n",j);
R[j].fileptr = 0;
R[j].filesize = 0;
iguana_ramchain_free(coin,&R[j],1);
}
myfree(R,n * sizeof(*R));

10
iguana/iguana_realtime.c

@ -170,7 +170,7 @@ void iguana_RTcoinaddr(struct iguana_info *coin,struct iguana_RTtxid *RTptr,stru
}
}
//printf("%s %.8f [%.8f - %.8f] -> %.8f\n",coinaddr,dstr(value),dstr(coin->RTcredits),dstr(coin->RTdebits),dstr(coin->histbalance)+dstr(coin->RTcredits)-dstr(coin->RTdebits));
if ( 0 && strcmp("BTC",coin->symbol) != 0 && strcmp("LTC",coin->symbol) != 0 && strcmp("DOGE",coin->symbol) != 0 )
if ( (0) && strcmp("BTC",coin->symbol) != 0 && strcmp("LTC",coin->symbol) != 0 && strcmp("DOGE",coin->symbol) != 0 )
printf("%lld %s %.8f h %.8f, cr %.8f deb %.8f [%.8f] numunspents.%d %p\n",(long long)polarity,coinaddr,dstr(value),dstr(RTaddr->histbalance),dstr(RTaddr->credits),dstr(RTaddr->debits),dstr(RTaddr->credits)-dstr(RTaddr->debits)+dstr(RTaddr->histbalance),RTaddr->numunspents,unspent);
}
@ -352,7 +352,7 @@ struct iguana_RTtxid *iguana_RTtxid_create(struct iguana_info *coin,struct iguan
}
HASH_ADD_KEYPTR(hh,coin->RTdataset,RTptr->txid.bytes,sizeof(RTptr->txid),RTptr);
bits256_str(str,txid);
if ( 0 && strcmp("BTC",coin->symbol) != 0 )
if ( (0) && strcmp("BTC",coin->symbol) != 0 )
printf("%s.%d txid.(%s) vouts.%d vins.%d version.%d lock.%u t.%u %lld\n",coin->symbol,block->height,str,numvouts,numvins,version,locktime,timestamp,(long long)polarity);
}
else if ( RTptr->txn_count != txn_count || RTptr->numvouts != numvouts || RTptr->numvins != numvins )
@ -630,7 +630,7 @@ void *iguana_RTrawdata(struct iguana_info *coin,bits256 hash2,uint8_t *data,int3
return(&ptr[sizeof(*recvlenp) + sizeof(checknumtx)]);
} else printf("checklen.%d vs %d, checknumtx %d vs %d\n",checklen,(int32_t)(filesize - sizeof(checklen) - sizeof(checknumtx)),checknumtx,*numtxp);
}
else if ( 0 )
else if ( (0) )
{
OS_removefile(fname,0);
printf("(%s) removed to suppress errors\n",fname);
@ -701,7 +701,7 @@ int32_t iguana_RTiterate(struct supernet_info *myinfo,struct iguana_info *coin,i
{
num++;
iguana_blockQ("RTiterate",coin,0,-1,block->RO.hash2,1);
if ( 0 && coin->peers != 0 && (n= coin->peers->numranked) > 0 )
if ( (0) && coin->peers != 0 && (n= coin->peers->numranked) > 0 )
{
if ( (addr= coin->peers->ranked[rand() % n]) != 0 )
iguana_sendblockreqPT(coin,addr,0,-1,block->RO.hash2,1);
@ -809,7 +809,7 @@ void iguana_RTnewblock(struct supernet_info *myinfo,struct iguana_info *coin,str
}*/
if ( block->height < coin->firstRTheight || block->height >= coin->firstRTheight+sizeof(coin->RTblocks)/sizeof(*coin->RTblocks) )
{
if ( 0 && coin->firstRTheight > 0 )
if ( (0) && coin->firstRTheight > 0 )
printf("iguana_RTnewblock illegal blockheight.%d\n",block->height);
return;
}

62
iguana/iguana_recv.c

@ -85,7 +85,7 @@ int32_t iguana_sendblockreqPT(struct iguana_info *coin,struct iguana_peer *addr,
}
if ( checkbp != bp || j != bundlei )
bp = 0, bundlei = -1;
if ( 0 && coin->enableCACHE != 0 && iguana_speculativesearch(coin,&block,hash2) != 0 )
if ( (0) && coin->enableCACHE != 0 && iguana_speculativesearch(coin,&block,hash2) != 0 )
{
if ( block != 0 && block->hdrsi != 0 && block->bundlei != 0 )
{
@ -127,7 +127,7 @@ int32_t iguana_sendblockreqPT(struct iguana_info *coin,struct iguana_peer *addr,
iguana_send(coin,addr,serialized,len);
if ( block != 0 )
block->issued = addr->pendtime;
if ( 0 && coin->current == bp )
if ( (0) && coin->current == bp )
printf("REQ.(%s) [%d:%d] %s n.%d\n",bits256_str(hexstr,hash2),bundlei,bp!=0?bp->hdrsi:-1,addr->ipaddr,addr->pendblocks);
} else printf("MSG_BLOCK null datalen.%d\n",len);
return(len);
@ -267,7 +267,7 @@ int32_t iguana_speculativefind(struct iguana_info *coin,struct iguana_bundle *bp
for (j=numcached=0; j<bp->n; j++)
if ( bp->speculativecache[j] != 0 )
numcached++;
if ( 0 && bp == coin->current )
if ( (0) && bp == coin->current )
printf("cache %s [%d:%d] h.%d s.%d c.%d -> %d\n",bits256_str(str,block->RO.hash2),bp->hdrsi,i,bp->numhashes,bp->numsaved,bp->numcached,numcached);
return(i);
}
@ -326,7 +326,7 @@ void iguana_oldgotblockM(struct supernet_info *myinfo,struct iguana_info *coin,s
printf("iguana_getblockM: illegal recvlen.%d\n",recvlen);
return;
}
if ( 0 )
if ( (0) )
{
for (i=0; i<txdata->space[0]; i++)
if ( txdata->space[i] != 0 )
@ -356,7 +356,7 @@ void iguana_oldgotblockM(struct supernet_info *myinfo,struct iguana_info *coin,s
{
printf("got block that doesnt validate? %s\n",bits256_str(str,origtxdata->zblock.RO.hash2));
return;
} else if ( 0 && coin->enableCACHE != 0 )
} else if ( (0) && coin->enableCACHE != 0 )
printf("c.%d v.(%s) %s n%d\n",coin->enableCACHE,bits256_str(str,origtxdata->zblock.RO.hash2),addr->ipaddr,addr->pendblocks);
origtxdata->zblock.txvalid = 1;
if ( fromcache == 0 && coin->virtualchain == 0 && addr != 0 && addr != &coin->internaladdr )
@ -430,7 +430,7 @@ void iguana_oldgotblockM(struct supernet_info *myinfo,struct iguana_info *coin,s
else
{
iguana_bundletime(coin,bp,bundlei,block,0);
if ( 0 && bp == coin->current )
if ( (0) && bp == coin->current )
printf("recv [%d:%d] %s\n",bp->hdrsi,bundlei,bits256_str(str,block->RO.hash2));
}
}
@ -462,7 +462,7 @@ void iguana_oldgotblockM(struct supernet_info *myinfo,struct iguana_info *coin,s
req = iguana_bundlereq(coin,addr,'B',data,copyflag * recvlen);
req->copyflag = 1;
req->H = *H;
if ( 0 && iguana_sethdr(&checkH,coin->chain->netmagic,H->command,req->serializeddata,recvlen) > 0 && memcmp(&checkH,H,sizeof(checkH)) != 0 )
if ( (0) && iguana_sethdr(&checkH,coin->chain->netmagic,H->command,req->serializeddata,recvlen) > 0 && memcmp(&checkH,H,sizeof(checkH)) != 0 )
{
int z;
for (z=0; z<sizeof(checkH); z++)
@ -527,7 +527,7 @@ void iguana_oldgotblockM(struct supernet_info *myinfo,struct iguana_info *coin,s
req->addr = addr;
//if ( (bits256_cmp(origtxdata->zblock.RO.hash2,coin->blocks.hwmchain.RO.hash2) == 0 || req->zblock.mainchain == 0 || req->zblock.valid == 0 || req->zblock.txvalid == 0) && iguana_RTrawdata(coin,origtxdata->zblock.RO.hash2,0,&len,&numtx,1) == 0 )
queue_enqueue("recvQ",&coin->recvQ,&req->DL);
if ( 0 && strcmp("BTCD",coin->symbol) == 0 )
if ( (0) && strcmp("BTCD",coin->symbol) == 0 )
printf("%s Q.(%s)\n",coin->symbol,bits256_str(str,origtxdata->zblock.RO.hash2));
} else printf("nonz fpos.%d %s\n",txdata->zblock.fpos,bits256_str(str,origtxdata->zblock.RO.hash2));
}
@ -609,7 +609,7 @@ int32_t iguana_bundlestats_update(struct iguana_info *coin,struct iguana_block *
else
{
iguana_bundletime(coin,bp,bundlei,block,0);
if ( 0 && bp == coin->current )
if ( (0) && bp == coin->current )
printf("recv [%d:%d] %s\n",bp->hdrsi,bundlei,bits256_str(str,block->RO.hash2));
return(0);
}
@ -648,7 +648,7 @@ struct iguana_bundlereq *iguana_recv_bundlereq(struct iguana_info *coin,struct i
req = iguana_bundlereq(coin,addr,'B',data,copyflag * recvlen);
req->copyflag = 1;
req->H = *H;
if ( 0 && iguana_sethdr(&checkH,coin->chain->netmagic,H->command,req->serializeddata,recvlen) > 0 && memcmp(&checkH,H,sizeof(checkH)) != 0 )
if ( (0) && iguana_sethdr(&checkH,coin->chain->netmagic,H->command,req->serializeddata,recvlen) > 0 && memcmp(&checkH,H,sizeof(checkH)) != 0 )
{
int z;
for (z=0; z<sizeof(checkH); z++)
@ -859,7 +859,7 @@ void iguana_gotblockM(struct supernet_info *myinfo,struct iguana_info *coin,stru
copyflag = (coin->enableCACHE != 0) && (strcmp(coin->symbol,"BTC") != 0);
req = iguana_recv_bundlereq(coin,addr,copyflag,H,data,recvlen,bp,bundlei,txdata);
queue_enqueue("recvQ",&coin->recvQ,&req->DL);
if ( 0 && bp->hdrsi == 0 && strcmp("SYS",coin->symbol) == 0 )
if ( (0) && bp->hdrsi == 0 && strcmp("SYS",coin->symbol) == 0 )
printf("[%d:%d].s%d %s Q.(%s) %s\n",bp->hdrsi,bundlei,numsaved,coin->symbol,bits256_str(str,origtxdata->zblock.RO.hash2),addr->ipaddr);
if ( numsaved < coin->chain->bundlesize )
{
@ -991,14 +991,14 @@ void iguana_gotblockhashesM(struct iguana_info *coin,struct iguana_peer *addr,bi
req = iguana_bundlereq(coin,addr,'S',0,0);
req->hashes = blockhashes, req->n = n;
char str[65];
if ( 0 && n > 2 && addr != 0 )
if ( (0) && n > 2 && addr != 0 )
printf("addr.%d %s [%d]\n",addr->rank,bits256_str(str,blockhashes[1]),n);
queue_enqueue("recvQ",&coin->recvQ,&req->DL);
if ( strcmp("BTC",coin->symbol) != 0 )
{
if ( n > coin->chain->bundlesize )
iguana_sendblockreqPT(coin,addr,0,-1,blockhashes[1],0);
if ( 0 && coin->RTheight > 0 )
if ( (0) && coin->RTheight > 0 )
{
for (i=1; i<num; i++)
iguana_sendblockreqPT(coin,0,0,-1,blockhashes[i],0);
@ -1051,7 +1051,7 @@ uint32_t iguana_allhashcmp(struct supernet_info *myinfo,struct iguana_info *coin
//n = 0;
//if ( bp->hdrsi < coin->MAXBUNDLES || (coin->current != 0 && coin->lastpending != 0 && bp->hdrsi >= coin->current->hdrsi && bp->hdrsi <= coin->lastpending->hdrsi) )
// n = iguana_bundleissuemissing(myinfo,coin,bp,1,3.);
if ( 0 && n > 2 )
if ( (0) && n > 2 )
printf("ALLHASHES FOUND! %d allhashes.%d issued %d\n",bp->bundleheight,coin->allhashes,n);
//if ( bp->queued == 0 )
// iguana_bundleQ(myinfo,coin,bp,bp->n*5 + (rand() % 500));
@ -1105,7 +1105,7 @@ int32_t iguana_bundlehashadd(struct iguana_info *coin,struct iguana_bundle *bp,i
if ( firstflag != 0 && bp->emitfinish == 0 )
{
//block->fpos = -1;
if ( 0 && iguana_ramchainfile(SuperNET_MYINFO(0),coin,0,&blockR,bp,bundlei,block) == 0 )
if ( (0) && iguana_ramchainfile(SuperNET_MYINFO(0),coin,0,&blockR,bp,bundlei,block) == 0 )
{
size = sizeof(blockR);
iguana_ramchain_free(coin,&blockR,1);
@ -1192,7 +1192,7 @@ void iguana_mainchain_clear(struct supernet_info *myinfo,struct iguana_info *coi
return;
}
}
if ( 0 && tmp != mainchain && coin->RTheight > 0 )
if ( (0) && tmp != mainchain && coin->RTheight > 0 )
printf("iguana_mainchain_clear: unexpected mismatch ht.%d vs %d %s\n",tmp->height,mainchain->height,bits256_str(str,tmp->RO.hash2));
}
}
@ -1208,7 +1208,7 @@ int32_t iguana_height_estimate(struct iguana_info *coin,struct iguana_block **ma
if ( tmp->mainchain != 0 && tmp->height >= 0 )
{
char str[65];
if ( 0 && n > 0 && coin->RTheight > 0 )
if ( (0) && n > 0 && coin->RTheight > 0 )
printf("%s M.%d dist.%d -> %d\n",bits256_str(str,block->RO.hash2),tmp->height,n,tmp->height+n);
*mainchainp = tmp;
return(tmp->height + n);
@ -1416,7 +1416,7 @@ struct iguana_bundlereq *iguana_recvblockhdrs(struct supernet_info *myinfo,struc
prevhash2 = zblocks[i].RO.hash2;
}
char str[65];
if ( 0 && bp == coin->current )
if ( (0) && bp == coin->current )
printf("i.%d n.%d match.%d blockhdrs.%s hdrsi.%d\n",i,n,match,bits256_str(str,zblocks[0].RO.hash2),firstbp!=0?firstbp->hdrsi:-1);
/*if ( firstbp != 0 && match >= coin->chain->bundlesize-1 )
{
@ -1479,7 +1479,7 @@ struct iguana_bundlereq *iguana_recvblockhashes(struct supernet_info *myinfo,str
memset(zero.bytes,0,sizeof(zero));
bp = 0, bundlei = -2;
iguana_bundlefind(coin,&bp,&bundlei,blockhashes[1]);
if ( 0 && strcmp("BTCD",coin->symbol) == 0 )//0 && num >= coin->chain->bundlesize )
if ( (0) && strcmp("BTCD",coin->symbol) == 0 )//0 && num >= coin->chain->bundlesize )
printf("blockhashes[%d] %d of %d %s bp.%d[%d]\n",num,bp==0?-1:bp->hdrsi,coin->bundlescount,bits256_str(str,blockhashes[1]),bp==0?-1:bp->bundleheight,bundlei);
if ( num < 2 )
return(req);
@ -1510,7 +1510,7 @@ struct iguana_bundlereq *iguana_recvblockhashes(struct supernet_info *myinfo,str
iguana_blockQ("recvhash1",coin,0,-1,bp->nextbundlehash2,1);
}
//printf("call allhashes\n");
if ( 0 && bp->hdrsi == coin->bundlescount-1 )
if ( (0) && bp->hdrsi == coin->bundlescount-1 )
iguana_autoextend(myinfo,coin,bp);
if ( iguana_allhashcmp(myinfo,coin,bp,blockhashes,num) > 0 )
return(req);
@ -1567,11 +1567,11 @@ struct iguana_bundlereq *iguana_recvblockhashes(struct supernet_info *myinfo,str
{
blockhashes[0] = bp->hashes[0];
vcalc_sha256(0,allhash.bytes,blockhashes[0].bytes,coin->chain->bundlesize * sizeof(*blockhashes));
if ( 0 && i == starti )
if ( (0) && i == starti )
printf("vcalc.(%s) [%d].(%s)\n",bits256_str(str,allhash),bp->hdrsi,bits256_str(str2,bp->hashes[0]));
if ( bits256_cmp(allhash,bp->allhash) == 0 )
{
if ( 0 && bp->speculative == 0 )
if ( (0) && bp->speculative == 0 )
printf("matched allhashes.[%d]\n",bp->hdrsi);
if ( bp->queued != 0 )
bp->queued = 0;
@ -1655,11 +1655,11 @@ struct iguana_bundlereq *iguana_recvblock(struct supernet_info *myinfo,struct ig
coin->longestchain = prevblock->height+1;
} else iguana_blockQ("prev",coin,0,-1,origblock->RO.prev_block,1);
}
if ( 0 && block != 0 )
if ( (0) && block != 0 )
printf("%s received.(%s) [%d:%d]\n",coin->symbol,bits256_str(str,origblock->RO.hash2),block->hdrsi,block->bundlei);
if ( (bp= iguana_bundleset(myinfo,coin,&block,&bundlei,(struct iguana_block *)origblock)) != 0 && bp == coin->current && block != 0 && bp->speculative != 0 && bundlei >= 0 )
{
if ( 0 && strcmp("BTCD",coin->symbol) == 0 )
if ( (0) && strcmp("BTCD",coin->symbol) == 0 )
printf("%s received.(%s) %s\n",coin->symbol,bits256_str(str,origblock->RO.hash2),addr->ipaddr);
if ( bp->speculative != 0 && bp->numspec <= bundlei )
{
@ -1730,7 +1730,7 @@ struct iguana_bundlereq *iguana_recvblock(struct supernet_info *myinfo,struct ig
}
} // else printf("RECV MAINCHAIN.%d\n",coin->blocks.hwmchain.height);
}
if ( 0 && time(NULL) > bp->hdrtime+3 && bundlei == 1 && bp != 0 && bp->numhashes < bp->n && strcmp("BTC",coin->symbol) != 0 && bp->speculative == 0 && bp == coin->current )
if ( (0) && time(NULL) > bp->hdrtime+3 && bundlei == 1 && bp != 0 && bp->numhashes < bp->n && strcmp("BTC",coin->symbol) != 0 && bp->speculative == 0 && bp == coin->current )
{
printf("reissue hdrs request for [%d]\n",bp->hdrsi);
bp->hdrtime = (uint32_t)time(NULL);
@ -1916,7 +1916,7 @@ int32_t iguana_reqblocks(struct supernet_info *myinfo,struct iguana_info *coin)
if ( 1 && (rand() % 100000) == 0 )//|| bp->bundleheight > coin->longestchain-coin->chain->bundlesize )
printf("%s %s MAIN.%d t %.3f lag %.3f\n",coin->symbol,bits256_str(str,hash2),coin->blocks.hwmchain.height+1,threshold,lag);
}
if ( 0 && bp != 0 && bundlei < bp->n-1 && (bits256_nonz(bp->hashes[bundlei+1]) != 0 || (bp->speculative != 0 && bits256_nonz(bp->speculative[bundlei+1]) != 0)) )
if ( (0) && bp != 0 && bundlei < bp->n-1 && (bits256_nonz(bp->hashes[bundlei+1]) != 0 || (bp->speculative != 0 && bits256_nonz(bp->speculative[bundlei+1]) != 0)) )
{
int32_t j;
//memset(bp->hashes[bundlei].bytes,0,sizeof(bp->hashes[bundlei]));
@ -2014,7 +2014,7 @@ int32_t iguana_reqhdrs(struct iguana_info *coin)
if ( now > bp->issuetime+lag && now > bp->hdrtime+3 )
{
bp->hdrtime = now;
if ( 0 && bp == coin->current )
if ( (0) && bp == coin->current )
printf("LAG.%d hdrsi.%d numhashes.%d:%d needhdrs.%d qsize.%d zcount.%d\n",(uint32_t)(now-bp->hdrtime),i,bp->numhashes,bp->n,iguana_needhdrs(coin),queue_size(&coin->hdrsQ),coin->zcount);
if ( bp->issuetime == 0 )
coin->numpendings++;
@ -2045,7 +2045,7 @@ int32_t iguana_reqhdrs(struct iguana_info *coin)
}
}
}
if ( 0 && n > 0 )
if ( (0) && n > 0 )
printf("REQ HDRS pending.%d\n",n);
coin->zcount = 0;
}
@ -2062,7 +2062,7 @@ int32_t iguana_blockQ(char *argstr,struct iguana_info *coin,struct iguana_bundle
//getchar();
return(-1);
}
if ( 0 && coin->enableCACHE != 0 && iguana_speculativesearch(coin,&block,hash2) != 0 && block != 0 && block->txvalid != 0 )
if ( (0) && coin->enableCACHE != 0 && iguana_speculativesearch(coin,&block,hash2) != 0 && block != 0 && block->txvalid != 0 )
{
//printf("found valid [%d:%d] in blockQ\n",block!=0?block->hdrsi:-1,block!=0?block->bundlei:-1);
return(0);
@ -2159,7 +2159,7 @@ int32_t iguana_pollQsPT(struct iguana_info *coin,struct iguana_peer *addr)
{
uint8_t serialized[sizeof(struct iguana_msghdr) + sizeof(uint32_t)*32 + sizeof(bits256)];
struct iguana_block *block; struct iguana_blockreq *req=0; char *hashstr=0; bits256 hash2;
int32_t bundlei,priority,i,m,z,pend,limit,height=-1,datalen,flag = 0; struct stritem *hashitem;
int32_t bundlei,priority,i,m=0,z,pend,limit,height=-1,datalen,flag = 0; struct stritem *hashitem;
uint32_t now; struct iguana_bundle *bp; struct iguana_peer *ptr;
if ( addr->msgcounts.verack == 0 )
return(0);
@ -2193,7 +2193,7 @@ int32_t iguana_pollQsPT(struct iguana_info *coin,struct iguana_peer *addr)
}
if ( bp == 0 || bp->speculative == 0 || bp == coin->current || bp->hdrsi == coin->bundlescount-1 || bp->numhashes < bp->n )
{
if ( 0 && bp == coin->current )
if ( (0) && bp == coin->current )
printf("%s request HDR.(%s) numhashes.%d [%d]\n",addr!=0?addr->ipaddr:"local",hashstr,bp!=0?bp->numhashes:0,bp!=0?bp->hdrsi:-1);
iguana_send(coin,addr,serialized,datalen);
addr->pendhdrs++;

22
iguana/iguana_rpc.c

@ -31,7 +31,8 @@ char *sglue(GLUEARGS,char *agent,char *method)
//printf("userpass.(%s)\n",userpass);
jaddstr(json,"agent",agent);
jaddstr(json,"method",method);
jaddstr(json,"coin",coin->symbol);
if ( coin != 0 )
jaddstr(json,"coin",coin->symbol);
if ( userpass != 0 )
jaddstr(json,"userpass",userpass);
if ( coin != 0 && coin->FULLNODE >= 0 && coin->chain->userpass[0] != 0 )
@ -1100,11 +1101,18 @@ char *SuperNET_rpcparse(struct supernet_info *myinfo,char *retbuf,int32_t bufsiz
}
else
{
//printf("ARGJSON.(%s)\n",jprint(argjson,0));
coin = iguana_coinchoose(myinfo,symbol,argjson,port);
if ( userpass != 0 && jstr(argjson,"userpass") == 0 )
jaddstr(argjson,"userpass",userpass);
retstr = SuperNET_JSON(myinfo,coin,argjson,remoteaddr,port);
cJSON *arg;
if ( jstr(argjson,"agent") != 0 && strcmp(jstr(argjson,"agent"),"bitcoinrpc") != 0 && jobj(argjson,"params") != 0 )
{
arg = jobj(argjson,"params");
if ( is_cJSON_Array(arg) != 0 && cJSON_GetArraySize(arg) == 1 )
arg = jitem(arg,0);
} else arg = argjson;
//printf("ARGJSON.(%s)\n",jprint(arg,0));
coin = iguana_coinchoose(myinfo,symbol,arg,port);
if ( userpass != 0 && jstr(arg,"userpass") == 0 )
jaddstr(arg,"userpass",userpass);
retstr = SuperNET_JSON(myinfo,coin,arg,remoteaddr,port);
}
free_json(argjson);
free_json(json);
@ -1144,7 +1152,7 @@ void iguana_rpcloop(void *args)
{
static char *jsonbuf;
uint16_t port; struct supernet_info *myinfo = args; char filetype[128],content_type[128];
int32_t recvlen,flag,bindsock,postflag,contentlen,sock,remains,numsent,jsonflag,hdrsize,len;
int32_t recvlen,flag,bindsock,postflag=0,contentlen,sock,remains,numsent,jsonflag=0,hdrsize,len;
socklen_t clilen; char helpname[512],remoteaddr[64],*buf,*retstr,*space;//,*retbuf; ,n,i,m
struct sockaddr_in cli_addr; uint32_t ipbits,i,size = IGUANA_WIDTH*IGUANA_HEIGHT*16 + 512;
if ( (port= myinfo->argport) == 0 )

15
iguana/iguana_scripts.c

@ -77,6 +77,13 @@ int32_t bitcoin_checklocktimeverify(uint8_t *script,int32_t n,uint32_t locktime)
return(n);
}
int32_t bitcoin_timelockspend(uint8_t *script,int32_t n,uint8_t rmd160[20],uint32_t timestamp)
{
n = bitcoin_checklocktimeverify(script,n,timestamp);
n = bitcoin_standardspend(script,n,rmd160);
return(n);
}
int32_t bitcoin_MofNspendscript(uint8_t p2sh_rmd160[20],uint8_t *script,int32_t n,const struct vin_info *vp)
{
int32_t i,plen;
@ -333,9 +340,9 @@ int32_t _iguana_calcrmd160(struct iguana_info *coin,struct vin_info *vp)
if ( (plen= vp->spendscript[2]+5) != vp->spendlen )
{
return(IGUANA_SCRIPT_STRANGE);
while ( plen < vp->spendlen )
/*while ( plen < vp->spendlen )
if ( vp->spendscript[plen++] != 0x61 ) // nop
return(IGUANA_SCRIPT_STRANGE);
return(IGUANA_SCRIPT_STRANGE);*/
}
return(IGUANA_SCRIPT_76A988AC);
}
@ -480,7 +487,7 @@ char *iguana_scriptaddress(struct iguana_info *coin,char *coinaddr,uint8_t *scri
int32_t bitcoin_scriptget(struct iguana_info *coin,int32_t *hashtypep,uint32_t *sigsizep,uint32_t *pubkeysizep,uint8_t **userdatap,uint32_t *userdatalenp,struct vin_info *vp,uint8_t *scriptsig,int32_t len,int32_t spendtype)
{
char asmstr[IGUANA_MAXSCRIPTSIZE*3]; int32_t j,n,siglen,plen; uint8_t *p2shscript;
int32_t j,n,siglen,plen; uint8_t *p2shscript;
j = n = 0;
*userdatap = 0;
*userdatalenp = *pubkeysizep = *sigsizep = 0;
@ -552,7 +559,7 @@ int32_t bitcoin_scriptget(struct iguana_info *coin,int32_t *hashtypep,uint32_t *
decode_hex(vp->rmd160,20,"010966776006953d5567439e5e39f86a0d273bee");//3564a74f9ddb4372301c49154605573d7d1a88fe");
vp->type = IGUANA_SCRIPT_76A988AC;
}*/
vp->spendlen = iguana_scriptgen(coin,&vp->M,&vp->N,vp->coinaddr,vp->spendscript,asmstr,vp->rmd160,vp->type,(const struct vin_info *)vp,vp->vin.prev_vout);
vp->spendlen = iguana_scriptgen(coin,&vp->M,&vp->N,vp->coinaddr,vp->spendscript,0,vp->rmd160,vp->type,(const struct vin_info *)vp,vp->vin.prev_vout);
//printf("type.%d asmstr.(%s) spendlen.%d\n",vp->type,asmstr,vp->spendlen);
return(vp->spendlen);
}

10
iguana/iguana_secp.c

@ -137,9 +137,9 @@ int32_t bitcoin_sign(void *ctx,char *symbol,uint8_t *sig,bits256 txhash2,bits256
// printf("%02x",pubkey[i]);
//printf(" bitcoin_sign's pubkey\n");
} else printf("secpub mismatch\n");
} //else printf("secpub mismatch\n");
} else printf("pubkey create error\n");
} else printf("recover error\n");
} //else printf("recover error\n");
} else printf("secp256k1_ecdsa_sign_recoverable error\n");
}
else
@ -566,9 +566,9 @@ int32_t iguana_schnorr_test(void *ctx)
{
sigs[i] = sig64[i];
continue;
for (j=0; j<64; j++)
printf("%02x",sig64[i][j]);
printf(" sig[%d]\n",i);
//for (j=0; j<64; j++)
// printf("%02x",sig64[i][j]);
//printf(" sig[%d]\n",i);
}
for (i=0; i<N; i++)
{

198
iguana/iguana_sign.c

@ -86,7 +86,7 @@ int32_t iguana_vinparse(struct iguana_info *coin,int32_t rwflag,uint8_t *seriali
serialized[len++] = ((p2shlen >> 8) & 0xff);
} else return(-1);
memcpy(&serialized[len],msg->redeemscript,p2shlen), len += p2shlen;
if ( 0 )
if ( (0) )
{
int32_t j;
for (j=0; j<p2shlen; j++)
@ -97,7 +97,7 @@ int32_t iguana_vinparse(struct iguana_info *coin,int32_t rwflag,uint8_t *seriali
}
//printf("sequence starts.%d %08x\n",len,*(int32_t *)&serialized[len]);
len += iguana_rwnum(rwflag,&serialized[len],sizeof(msg->sequence),&msg->sequence);
if ( 0 )
if ( (0) )
{
int32_t i; char str[65];
for (i=0; i<len; i++)
@ -122,7 +122,7 @@ int32_t iguana_voutparse(int32_t rwflag,uint8_t *serialized,struct iguana_msgvou
else if ( msg->pk_scriptlen > 0 )
{
memcpy(&serialized[len],msg->pk_script,msg->pk_scriptlen);
if ( 0 )
if ( (0) )
{
int32_t i;
for (i=0; i<msg->pk_scriptlen; i++)
@ -294,7 +294,7 @@ int32_t iguana_parsevinobj(struct supernet_info *myinfo,struct iguana_info *coin
// continue;
if ( serialized[len + m + siglen - 1] == SIGHASH_ALL )
memcpy(V->signers[i++].sig,&serialized[len + m],siglen);
if ( 0 )
if ( (0) )
{
int32_t j;
for (j=0; j<siglen; j++)
@ -568,6 +568,22 @@ void iguana_vinobjset(struct iguana_msgvin *vin,cJSON *item,uint8_t *spendscript
}
}
int32_t iguana_vinarray_check(cJSON *vinarray,bits256 txid)
{
bits256 array_txid; cJSON *item; int32_t i,n = cJSON_GetArraySize(vinarray);
for (i=0; i<n; i++)
{
item = jitem(vinarray,i);
array_txid = jbits256(item,"txid");
if ( bits256_cmp(array_txid,txid) == 0 )
{
printf("vinarray.[%d] duplicate\n",i);
return(i);
}
}
return(-1);
}
int32_t iguana_rwmsgtx(struct iguana_info *coin,int32_t height,int32_t rwflag,cJSON *json,uint8_t *serialized,int32_t maxsize,struct iguana_msgtx *msg,bits256 *txidp,char *vpnstr,uint8_t *extraspace,int32_t extralen,cJSON *vins,int32_t suppress_pubkeys)
{
int32_t i,n,len = 0,extraused=0; uint8_t spendscript[IGUANA_MAXSCRIPTSIZE],*txstart = serialized,*sigser=0; char txidstr[65]; cJSON *vinarray=0,*voutarray=0; bits256 sigtxid;
@ -657,7 +673,7 @@ int32_t iguana_rwmsgtx(struct iguana_info *coin,int32_t height,int32_t rwflag,cJ
jaddi(voutarray,iguana_voutjson(coin,&msg->vouts[i],i,*txidp));
}
len += iguana_rwnum(rwflag,&serialized[len],sizeof(msg->lock_time),&msg->lock_time);
//printf("lock_time.%08x len.%d\n",msg->lock_time,len);
//printf("lock_time.%08x len.%d\n",msg->lock_time,len);
if ( strcmp(coin->symbol,"VPN") == 0 )
{
uint16_t ddosflag = 0;
@ -688,13 +704,16 @@ int32_t iguana_rwmsgtx(struct iguana_info *coin,int32_t height,int32_t rwflag,cJ
iguana_vinobjset(&msg->vins[i],jitem(vins,i),spendscript,sizeof(spendscript));
sigtxid = bitcoin_sigtxid(coin,height,sigser,maxsize*2,msg,i,msg->vins[i].spendscript,msg->vins[i].spendlen,SIGHASH_ALL,vpnstr,suppress_pubkeys);
//printf("after vini.%d vinscript.%p spendscript.%p spendlen.%d (%s)\n",i,msg->vins[i].vinscript,msg->vins[i].spendscript,msg->vins[i].spendlen,jprint(jitem(vins,i),0));
jaddi(vinarray,iguana_vinjson(coin,&msg->vins[i],sigtxid));
if ( iguana_vinarray_check(vinarray,msg->vins[i].prev_hash) < 0 )
jaddi(vinarray,iguana_vinjson(coin,&msg->vins[i],sigtxid));
if ( msg->vins[i].spendscript == spendscript )
msg->vins[i].spendscript = 0;
} else jaddi(vinarray,iguana_vinjson(coin,&msg->vins[i],sigtxid));
} else if ( iguana_vinarray_check(vinarray,msg->vins[i].prev_hash) < 0 )
jaddi(vinarray,iguana_vinjson(coin,&msg->vins[i],sigtxid));
}
free(sigser);
jadd(json,"vin",vinarray);
msg->tx_in = cJSON_GetArraySize(vinarray);
jaddnum(json,"numvins",msg->tx_in);
}
if ( voutarray != 0 )
@ -833,6 +852,7 @@ cJSON *bitcoin_data2json(struct iguana_info *coin,int32_t height,bits256 *txidp,
jaddstr(txobj,"error","couldnt decode transaction");
jaddstr(txobj,"coin",coin->symbol);
}
//printf("msgtx.(%s)\n",jprint(txobj,0));
if ( n != len )
{
int32_t i;
@ -944,7 +964,7 @@ int32_t iguana_msgtx_Vset(struct iguana_info *coin,uint8_t *serialized,int32_t m
}
len += scriptlen;
}
if ( 0 )
if ( (0) )
{
int32_t i; for (i=0; i<len; i++)
printf("%02x",script[i]);
@ -1013,13 +1033,13 @@ int32_t bitcoin_verifyvins(struct iguana_info *coin,int32_t height,bits256 *sign
{
flag++;
numsigs++;
int32_t z;
/*int32_t z;
for (z=0; z<siglen-1; z++)
printf("%02x",sig[z]);
printf(" <- sig[%d]\n",j);
for (z=0; z<33; z++)
printf("%02x",vp->signers[j].pubkey[z]);
printf(" <- pub, SIG.%d.%d VERIFIED numsigs.%d vs M.%d\n",vini,j,numsigs,vp->M);
printf(" <- pub, SIG.%d.%d VERIFIED numsigs.%d vs M.%d\n",vini,j,numsigs,vp->M);*/
}
}
if ( numsigs >= vp->M )
@ -1115,9 +1135,9 @@ void iguana_ensure_privkey(struct supernet_info *myinfo,struct iguana_info *coin
waddr->privkey = privkey;
if ( bitcoin_priv2wif(waddr->wifstr,waddr->privkey,coin->chain->wiftype) > 0 )
{
if ( 0 && waddr->wiftype != coin->chain->wiftype )
if ( (0) && waddr->wiftype != coin->chain->wiftype )
printf("ensurepriv warning: mismatched wiftype %02x != %02x\n",waddr->wiftype,coin->chain->wiftype);
if ( 0 && waddr->addrtype != coin->chain->pubtype )
if ( (0) && waddr->addrtype != coin->chain->pubtype )
printf("ensurepriv warning: mismatched addrtype %02x != %02x\n",waddr->addrtype,coin->chain->pubtype);
}
}
@ -1220,7 +1240,7 @@ cJSON *iguana_pubkeysjson(uint8_t *pubkeyptrs[],int32_t numpubkeys)
cJSON *bitcoin_txinput(struct iguana_info *coin,cJSON *txobj,bits256 txid,int32_t vout,uint32_t sequenceid,uint8_t *spendscript,int32_t spendlen,uint8_t *redeemscript,int32_t p2shlen,uint8_t *pubkeys[],int32_t numpubkeys,uint8_t *sig,int32_t siglen)
{
cJSON *item,*vins; char p2shscriptstr[IGUANA_MAXSCRIPTSIZE*2+1]; uint8_t *script,len;
cJSON *item,*vins; char p2shscriptstr[IGUANA_MAXSCRIPTSIZE*2+1]; uint8_t *script,len=0;
vins = jduplicate(jobj(txobj,"vin"));
jdelete(txobj,"vin");
item = cJSON_CreateObject();
@ -1284,7 +1304,7 @@ cJSON *bitcoin_txoutput(cJSON *txobj,uint8_t *paymentscript,int32_t len,uint64_t
int32_t iguana_interpreter(struct iguana_info *coin,cJSON *logarray,int64_t nLockTime,struct vin_info *V,int32_t numvins)
{
uint8_t script[IGUANA_MAXSCRIPTSIZE],*activescript,savescript[IGUANA_MAXSCRIPTSIZE]; char str[IGUANA_MAXSCRIPTSIZE*2+1]; int32_t vini,scriptlen,activescriptlen,savelen,errs = 0; cJSON *spendscript,*item;
uint8_t script[IGUANA_MAXSCRIPTSIZE],*activescript,savescript[IGUANA_MAXSCRIPTSIZE]; char str[IGUANA_MAXSCRIPTSIZE*2+1]; int32_t vini,scriptlen,activescriptlen,savelen,errs = 0; cJSON *spendscript,*item=0;
for (vini=0; vini<numvins; vini++)
{
savelen = V[vini].spendlen;
@ -1319,7 +1339,7 @@ int32_t iguana_interpreter(struct iguana_info *coin,cJSON *logarray,int64_t nLoc
}
init_hexbytes_noT(str,activescript,activescriptlen);
//printf("activescript.(%s)\n",str);
if ( logarray != 0 )
if ( logarray != 0 && item != 0 )
jaddstr(item,"original",str);
init_hexbytes_noT(str,script,scriptlen);
//printf("reconstructed.(%s)\n",str);
@ -1344,72 +1364,11 @@ int32_t iguana_interpreter(struct iguana_info *coin,cJSON *logarray,int64_t nLoc
return(0);
}
#include "../includes/iguana_apidefs.h"
#include "../includes/iguana_apideclares.h"
P2SH_SPENDAPI(iguana,spendmsig,activecoin,vintxid,vinvout,destaddress,destamount,destaddress2,destamount2,M,N,pubA,wifA,pubB,wifB,pubC,wifC)
{
struct vin_info V; uint8_t p2sh_rmd160[20],serialized[2096],spendscript[32],pubkeys[3][65],*pubkeyptrs[3]; int32_t spendlen,height = 0;
char msigaddr[64],*retstr; cJSON *retjson,*txobj; struct iguana_info *active;
bits256 signedtxid; char *signedtx;
struct iguana_msgtx msgtx;
if ( remoteaddr != 0 )
return(clonestr("{\"error\":\"no remote\"}"));
if ( myinfo->expiration == 0 )
return(clonestr("{\"error\":\"need to unlock wallet\"}"));
if ( (active= iguana_coinfind(activecoin)) == 0 )
return(clonestr("{\"error\":\"activecoin isnt active\"}"));
if ( M > N || N > 3 )
return(clonestr("{\"error\":\"illegal M or N\"}"));
memset(&V,0,sizeof(V));
txobj = bitcoin_txcreate(active->symbol,active->chain->isPoS,0,coin->chain->normal_txversion,0);
if ( destaddress[0] != 0 && destamount > 0. )
bitcoin_txaddspend(active,txobj,destaddress,destamount * SATOSHIDEN);
if ( destaddress2[0] != 0 && destamount2 > 0. )
bitcoin_txaddspend(active,txobj,destaddress2,destamount2 * SATOSHIDEN);
if ( pubA[0] != 0 && (retstr= _setVsigner(active,&V,0,pubA,wifA)) != 0 )
return(retstr);
if ( N >= 2 && pubB[0] != 0 && (retstr= _setVsigner(active,&V,1,pubB,wifB)) != 0 )
return(retstr);
if ( N == 3 && pubC[0] != 0 && (retstr= _setVsigner(active,&V,2,pubC,wifC)) != 0 )
return(retstr);
V.M = M, V.N = N, V.type = IGUANA_SCRIPT_P2SH;
V.p2shlen = bitcoin_MofNspendscript(p2sh_rmd160,V.p2shscript,0,&V);
spendlen = bitcoin_p2shspend(spendscript,0,p2sh_rmd160);
if ( pubA[0] != 0 )
{
decode_hex(pubkeys[0],(int32_t)strlen(pubA)>>1,pubA);
pubkeyptrs[0] = pubkeys[0];
}
if ( pubB[0] != 0 )
{
decode_hex(pubkeys[1],(int32_t)strlen(pubB)>>1,pubB);
pubkeyptrs[1] = pubkeys[1];
}
if ( pubC[0] != 0 )
{
decode_hex(pubkeys[2],(int32_t)strlen(pubC)>>1,pubC);
pubkeyptrs[2] = pubkeys[2];
}
bitcoin_txinput(active,txobj,vintxid,vinvout,0xffffffff,spendscript,spendlen,V.p2shscript,V.p2shlen,pubkeyptrs,N,0,0);
bitcoin_address(msigaddr,active->chain->p2shtype,V.p2shscript,V.p2shlen);
retjson = cJSON_CreateObject();
if ( bitcoin_verifyvins(active,height,&signedtxid,&signedtx,&msgtx,serialized,sizeof(serialized),&V,SIGHASH_ALL,1,V.suppress_pubkeys) == 0 )
{
jaddstr(retjson,"result","msigtx");
if ( signedtx != 0 )
jaddstr(retjson,"signedtx",signedtx), free(signedtx);
jaddbits256(retjson,"txid",signedtxid);
} else jaddstr(retjson,"error","couldnt sign tx");
jaddstr(retjson,"msigaddr",msigaddr);
return(jprint(retjson,1));
}
int32_t iguana_signrawtransaction(struct supernet_info *myinfo,struct iguana_info *coin,int32_t height,struct iguana_msgtx *msgtx,char **signedtxp,bits256 *signedtxidp,struct vin_info *V,int32_t numinputs,char *rawtx,cJSON *vins,cJSON *privkeysjson)
{
uint8_t *serialized,*serialized2,*serialized3,*serialized4,*extraspace,pubkeys[64][33]; int32_t finalized,i,len,n,z,plen,maxsize,complete = 0,extralen = 65536; char *checkstr,*privkeystr,*signedtx = 0; bits256 privkeys[64],privkey,txid; cJSON *item; cJSON *txobj = 0;
uint8_t *serialized,*serialized2,*serialized3,*serialized4,*extraspace,pubkeys[64][33]; int32_t finalized,i,len,n,z,plen,maxsize,complete = 0,extralen = 65536; char *privkeystr,*signedtx = 0; bits256 privkeys[64],privkey,txid; cJSON *item; cJSON *txobj = 0;
maxsize = 1000000;
memset(privkey.bytes,0,sizeof(privkey));
if ( rawtx != 0 && rawtx[0] != 0 && (len= (int32_t)strlen(rawtx)>>1) < maxsize )
{
serialized = malloc(maxsize);
@ -1419,30 +1378,14 @@ int32_t iguana_signrawtransaction(struct supernet_info *myinfo,struct iguana_inf
extraspace = malloc(extralen);
memset(msgtx,0,sizeof(*msgtx));
decode_hex(serialized,len,rawtx);
// printf("call hex2json.(%s) vins.(%s)\n",rawtx,jprint(vins,0));
if ( (txobj= bitcoin_hex2json(coin,height,&txid,msgtx,rawtx,extraspace,extralen,serialized4,vins,V->suppress_pubkeys)) != 0 )
{
if ( 0 && vins != 0 )
printf("txobj.(%s)\n",jprint(txobj,0));
if ( jobj(txobj,"error") != 0 )
{
printf("txobj.(%s)\n",jprint(txobj,0));
}
if ( 0 && (checkstr= bitcoin_json2hex(myinfo,coin,&txid,txobj,V)) != 0 ) // no guarantee of identical regen
{
if ( strcmp(rawtx,checkstr) != 0 )
{
printf("RAW.(%s) ->\nNEW.(%s)\n",rawtx,checkstr);
//free_json(txobj);
//free(checkstr);
//free(serialized), free(serialized2), free(serialized3), free(serialized4);
//free(extraspace);
//return(-2);
}
free(checkstr);
}
//printf("back from bitcoin_hex2json (%s)\n",jprint(vins,0));
} else fprintf(stderr,"no txobj from bitcoin_hex2json\n");
if ( (numinputs= cJSON_GetArraySize(vins)) > 0 )
{
//printf("numinputs.%d msgtx.%d\n",numinputs,msgtx->tx_in);
memset(msgtx,0,sizeof(*msgtx));
if ( iguana_rwmsgtx(coin,height,0,0,serialized,maxsize,msgtx,&txid,"",extraspace,65536,vins,V->suppress_pubkeys) > 0 && numinputs == msgtx->tx_in )
{
@ -1462,27 +1405,24 @@ int32_t iguana_signrawtransaction(struct supernet_info *myinfo,struct iguana_inf
iguana_ensure_privkey(myinfo,coin,privkey);
}
}
//printf("after privkeys tx_in.%d\n",msgtx->tx_in);
for (i=0; i<msgtx->tx_in; i++)
{
if ( msgtx->vins[i].p2shlen != 0 )
{
char coinaddr[64]; uint32_t userdatalen,sigsize,pubkeysize; uint8_t *userdata; int32_t j,k,hashtype,type,flag; struct vin_info mvin,mainvin; bits256 zero;
memset(zero.bytes,0,sizeof(zero));
coinaddr[0] = 0;
sigsize = 0;
flag = (msgtx->vins[i].vinscript[0] == 0);
type = bitcoin_scriptget(coin,&hashtype,&sigsize,&pubkeysize,&userdata,&userdatalen,&mainvin,msgtx->vins[i].vinscript+flag,msgtx->vins[i].scriptlen-flag,0);
if ( flag != 0 && pubkeysize == 33 ) // jl777: need to generalize this
{
for (k=0; k<sigsize; k++)
printf("%02x",mainvin.signers[0].sig[k]);
}
printf(" main vinscript type.%d sigsize.%d pubkeysize.%d\n",type,sigsize,pubkeysize);
//printf("i.%d flag.%d type.%d scriptlen.%d\n",i,flag,type,msgtx->vins[i].scriptlen);
if ( msgtx->vins[i].redeemscript != 0 )
{
//for (j=0; j<msgtx->vins[i].p2shlen; j++)
// printf("%02x",msgtx->vins[i].redeemscript[j]);
bitcoin_address(coinaddr,coin->chain->p2shtype,msgtx->vins[i].redeemscript,msgtx->vins[i].p2shlen);
type = iguana_calcrmd160(coin,0,&mvin,msgtx->vins[i].redeemscript,msgtx->vins[i].p2shlen,zero,0,01);
type = iguana_calcrmd160(coin,0,&mvin,msgtx->vins[i].redeemscript,msgtx->vins[i].p2shlen,zero,0,0);
for (j=0; j<mvin.N; j++)
{
if ( V->suppress_pubkeys == 0 )
@ -1510,12 +1450,12 @@ int32_t iguana_signrawtransaction(struct supernet_info *myinfo,struct iguana_inf
for (z=0; z<33; z++)
V[i].signers[j].pubkey[z] = pubkeys[k][z];
}
printf("%s -> V[%d].signer.[%d] <- privkey.%d\n",mvin.signers[j].coinaddr,i,j,k);
//printf("%s -> V[%d].signer.[%d] <- privkey.%d\n",mvin.signers[j].coinaddr,i,j,k);
break;
}
}
}
printf("type.%d p2sh.[%d] -> %s M.%d N.%d\n",type,i,mvin.coinaddr,mvin.M,mvin.N);
//printf("type.%d p2sh.[%d] -> %s M.%d N.%d\n",type,i,mvin.coinaddr,mvin.M,mvin.N);
}
}
if ( i < V->N )
@ -1533,16 +1473,17 @@ int32_t iguana_signrawtransaction(struct supernet_info *myinfo,struct iguana_inf
}
}
finalized = iguana_vininfo_create(myinfo,coin,serialized2,maxsize,msgtx,vins,numinputs,V);
//printf("finalized.%d\n",finalized);
if ( (complete= bitcoin_verifyvins(coin,height,signedtxidp,&signedtx,msgtx,serialized3,maxsize,V,SIGHASH_ALL,1,V->suppress_pubkeys)) > 0 && signedtx != 0 )
{
int32_t tmp; char str[65];
if ( (tmp= iguana_interpreter(coin,0,iguana_lockval(finalized,jint(txobj,"locktime")),V,numinputs)) < 0 )
{
//printf("iguana_interpreter %d error.(%s)\n",tmp,signedtx);
printf("iguana_interpreter %d error.(%s)\n",tmp,signedtx);
complete = 0;
} else printf("%s signed\n",bits256_str(str,*signedtxidp));
}
}
} else printf("complete.%d\n",complete);
} else printf("rwmsgtx error\n");
} else fprintf(stderr,"no inputs in vins.(%s)\n",vins!=0?jprint(vins,0):"null");
free(extraspace);
free(serialized), free(serialized2), free(serialized3), free(serialized4);
@ -1553,43 +1494,4 @@ int32_t iguana_signrawtransaction(struct supernet_info *myinfo,struct iguana_inf
return(complete);
}
STRING_ARRAY_OBJ_STRING(bitcoinrpc,signrawtransaction,rawtx,vins,privkeys,sighash)
{
char *signedtx = 0; struct vin_info *V; bits256 signedtxid; int32_t complete,numinputs = 1; struct iguana_msgtx msgtx; cJSON *retjson; int uselessbitcoin_error = 0;
retjson = cJSON_CreateObject();
if ( remoteaddr != 0 )
return(clonestr("{\"error\":\"no remote\"}"));
if ( myinfo->expiration == 0 )
return(clonestr("{\"error\":\"need to unlock wallet\"}"));
//printf("rawtx.(%s) vins.(%s) privkeys.(%s) sighash.(%s)\n",rawtx,jprint(vins,0),jprint(privkeys,0),sighash);
if ( sighash == 0 || sighash[0] == 0 )
sighash = "ALL";
if ( strcmp(sighash,"ALL") != 0 )
jaddstr(retjson,"error","only sighash all (ALL) supported for now");
if ( (numinputs= cJSON_GetArraySize(vins)) > 0 )
{
V = calloc(numinputs,sizeof(*V));
memset(&msgtx,0,sizeof(msgtx));
if ( (complete= iguana_signrawtransaction(myinfo,coin,coin->blocks.hwmchain.height,&msgtx,&signedtx,&signedtxid,V,numinputs,rawtx,vins,privkeys)) >= 0 )
{
if ( signedtx != 0 )
{
jaddstr(retjson,"result",signedtx);
jadd(retjson,"complete",complete!=0?jtrue():jfalse());
free(signedtx);
} else jaddstr(retjson,"error",uselessbitcoin_error != 0 ? "-22" : "no transaction from verifyvins");
}
else if ( complete == -2 )
jaddstr(retjson,"error",uselessbitcoin_error != 0 ? "-22" : "hex2json -> json2hex error");
else if ( complete == -1 )
jaddstr(retjson,"error",uselessbitcoin_error != 0 ? "-22" : "couldnt load serialized tx or mismatched numinputs");
free(V);
//for (i=0; i<msgtx.tx_in; i++)
// if ( msgtx.vins[i].redeemscript != 0 )
// free(msgtx.vins[i].redeemscript), msgtx.vins[i].redeemscript = 0;
} else jaddstr(retjson,"error",uselessbitcoin_error != 0 ? "-22" : "no rawtx or rawtx too big");
return(jprint(retjson,1));
}
#include "../includes/iguana_apiundefs.h"

26
iguana/iguana_spendvectors.c

@ -238,8 +238,8 @@ struct iguana_bundle *iguana_fastexternalspent(struct supernet_info *myinfo,stru
int32_t iguana_spendvectors(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_bundle *bp,struct iguana_ramchain *ramchain,int32_t starti,int32_t numblocks,int32_t convertflag,int32_t iterate)
{
static uint64_t total,emitted;
int32_t iter,spendind,n=0,txidind,errs=0,emit=0,i,j,k; double startmillis; bits256 prevhash;
uint32_t spent_unspentind,spent_pkind,now,starttime; struct iguana_ramchaindata *rdata;
int32_t iter,spendind=0,n=0,txidind,errs=0,emit=0,i,j,k; double startmillis; bits256 prevhash;
uint32_t spent_unspentind=0,spent_pkind,now,starttime; struct iguana_ramchaindata *rdata;
struct iguana_bundle *spentbp; struct iguana_blockRO *B; struct iguana_spendvector *ptr;
struct iguana_unspent *u,*spentU; struct iguana_txid *T; char str[65];
struct iguana_spend *S,*s; //void *fastfind = 0;
@ -270,7 +270,7 @@ int32_t iguana_spendvectors(struct supernet_info *myinfo,struct iguana_info *coi
ptr = mycalloc('x',sizeof(*ptr),n);
total += n;
startmillis = OS_milliseconds();
if ( 0 && strcmp(coin->symbol,"BTC") == 0 )
if ( (0) && strcmp(coin->symbol,"BTC") == 0 )
printf("start UTXOGEN.%d max.%d ptr.%p millis.%.3f\n",bp->bundleheight,n,ptr,startmillis);
starttime = (uint32_t)time(NULL);
iguana_ramchain_prefetch(coin,&bp->ramchain,3);
@ -383,7 +383,7 @@ int32_t iguana_spendvectors(struct supernet_info *myinfo,struct iguana_info *coi
ptr[emit].unspentind = spent_unspentind;
ptr[emit].fromheight = bp->bundleheight + i;
ptr[emit].tmpflag = 1;
if ( 0 && bp == coin->current )
if ( (0) && bp == coin->current )
printf("fromht.%d spends [%d] TMPVECTOR u%d s%u\n",ptr[emit].fromheight,ptr[emit].hdrsi,ptr[emit].unspentind,spendind);
emit++;
}
@ -436,7 +436,7 @@ int32_t iguana_spendvectors(struct supernet_info *myinfo,struct iguana_info *coi
//printf("ALLOC tmpspends.[%d]\n",bp->hdrsi);
ptr = 0;
}
if ( 0 && bp == coin->current )
if ( (0) && bp == coin->current )
printf("spendvectors.[%d]: tmpspends.%p[%d] after += emit.%d X.%p\n",bp->hdrsi,bp->tmpspends,bp->numtmpspends,emit,bp->ramchain.Xspendinds);
} else errs = -iguana_spendvectorsave(coin,bp,ramchain,ptr!=0?ptr:bp->tmpspends,emit,n);
}
@ -486,12 +486,12 @@ int32_t iguana_balancegen(struct iguana_info *coin,int32_t incremental,struct ig
spendind = B[starti].firstvin;
unspentind = B[starti].firstvout;
emit = startemit;
if ( 0 && (coin->RTheight == 0 || bp->bundleheight+bp->n < coin->RTheight) )
if ( (0) && (coin->RTheight == 0 || bp->bundleheight+bp->n < coin->RTheight) )
fprintf(stderr,"BALANCEGEN.[%d] %p[%d] starti.%d s%d <-> endi.%d s%d startemit.%d\n",bp->hdrsi,Xspendinds,numXspends,starti,spendind,endi,B[endi].firstvin+B[endi].numvins,startemit);
for (i=starti; i<=endi; i++)
{
now = (uint32_t)time(NULL);
if ( 0 && bp == coin->current )
if ( (0) && bp == coin->current )
printf("hdrs.[%d] B[%d] 1st txidind.%d txn_count.%d firstvin.%d firstvout.%d\n",bp->hdrsi,i,B[i].firsttxidind,B[i].txn_count,B[i].firstvin,B[i].firstvout);
if ( txidind != B[i].firsttxidind || spendind != B[i].firstvin || unspentind != B[i].firstvout )
{
@ -506,7 +506,7 @@ int32_t iguana_balancegen(struct iguana_info *coin,int32_t incremental,struct ig
printf("balancegen: txidind %u != %u T[txidind].firsttxidind || spendind %u != %u T[txidind].firstvin errs.%d (%d %d)\n",txidind,(uint32_t)T[txidind].txidind,spendind,(uint32_t)T[txidind].firstvin,errs,unspentind,B[i].firstvout);
return(-1);
}
if ( 0 && bp == coin->current )
if ( (0) && bp == coin->current )
printf("starti.%d txidind.%d txi.%d numvins.%d spendind.%d\n",i,txidind,j,T[txidind].numvins,spendind);
/*if ( bp == coin->current )//ramchain == &coin->RTramchain )
{
@ -541,7 +541,7 @@ int32_t iguana_balancegen(struct iguana_info *coin,int32_t incremental,struct ig
spent_hdrsi = spend->hdrsi;
h = spend->fromheight;
}
if ( 0 && bp == coin->current )
if ( (0) && bp == coin->current )
printf("external prevout.%d (emit.%d numX.%d) %p u%d p%d errs.%d spent_hdrsi.%d s%u\n",s->prevout,emit,numXspends,Xspendinds,spent_unspentind,spent_pkind,errs,spent_hdrsi,spendind);
}
else if ( s->prevout >= 0 )
@ -567,7 +567,7 @@ int32_t iguana_balancegen(struct iguana_info *coin,int32_t incremental,struct ig
spentbp = 0;
if ( (spentbp= coin->bundles[spent_hdrsi]) != 0 && spent_unspentind > 0 && spent_pkind > 0 )
{
if ( 0 && bp == coin->current )
if ( (0) && bp == coin->current )
printf("[%d] spendind.%u -> [%d] u%d\n",bp->hdrsi,spendind,spent_hdrsi,spent_unspentind);
if ( iguana_volatileupdate(coin,incremental,&spentbp->ramchain,spent_hdrsi,spent_unspentind,spent_pkind,spent_value,spendind,h) < 0 ) //(spentbp == coin->current) ? &coin->RTramchain :
errs++;
@ -967,7 +967,7 @@ int32_t iguana_balanceflush(struct supernet_info *myinfo,struct iguana_info *coi
}
char str[65]; printf("BALANCES WRITTEN for %d orig.%d bundles %s\n",coin->balanceswritten,coin->origbalanceswritten,bits256_str(str,coin->balancehash));
//iguana_utxoaddr_gen(myinfo,coin,(coin->balanceswritten - 1) * coin->chain->bundlesize);
if ( 0 && coin->balanceswritten > coin->origbalanceswritten+10 ) // strcmp(coin->symbol,"BTC") == 0 &&
if ( (0) && coin->balanceswritten > coin->origbalanceswritten+10 ) // strcmp(coin->symbol,"BTC") == 0 &&
{
coin->active = 0;
coin->started = 0;
@ -1119,7 +1119,7 @@ int32_t iguana_convert(struct iguana_info *coin,int32_t helperid,struct iguana_b
total[helperid % max] += converted;
for (i=sum=0; i<max; i++)
sum += total[i];
if ( 0 && converted != 0 && bp != coin->current )
if ( (0) && converted != 0 && bp != coin->current )
printf("[%4d] millis %7.3f converted.%-7d balance calc.%-4d of %4d | total.%llu of %llu depth.%d\n",bp->hdrsi,OS_milliseconds()-startmillis,converted,m,n,(long long)sum,(long long)total_tmpspends,(int32_t)depth);
}
depth--;
@ -1134,7 +1134,7 @@ int32_t iguana_bundlevalidate(struct supernet_info *myinfo,struct iguana_info *c
if ( coin->chain->zcash != 0 )
{
static uint32_t counter;
if ( 0 && counter++ < 3 )
if ( (0) && counter++ < 3 )
printf("need to process joinsplits before can validate.%s\n",coin->symbol);
bp->validated = (uint32_t)time(NULL);
forceflag = 1;

5
iguana/iguana_tradebots.c

@ -221,6 +221,7 @@ char *tradebot_control(struct supernet_info *myinfo,char *exchangestr,char *boti
#include "../includes/iguana_apidefs.h"
#include "../includes/iguana_apideclares.h"
#include "../includes/iguana_apideclares2.h"
HASH_ARRAY_STRING(tradebot,liquidity,hash,vals,targetcoin)
{
@ -228,9 +229,11 @@ HASH_ARRAY_STRING(tradebot,liquidity,hash,vals,targetcoin)
return(clonestr("{\"result\":\"targetcoin updated\"}"));
}
ZERO_ARGS(tradebot,amlp)
STRING_ARG(tradebot,amlp,blocktrail)
{
myinfo->IAMLP = 1;
if ( blocktrail != 0 )
safecopy(myinfo->blocktrail_apikey,blocktrail,sizeof(myinfo->blocktrail_apikey));
return(clonestr("{\"result\":\"liquidity provider active\"}"));
}

4
iguana/iguana_tx.c

@ -44,7 +44,7 @@ int32_t iguana_scriptdata(struct iguana_info *coin, uint8_t *scriptspace, long f
memcpy(scriptspace,(void *)(fileptr[0] + (uint32_t)scriptpos),scriptlen);
return(retval);
}
else if ( 0 )
else if ( (0) )
{
printf("munmap (%s)\n",fname);
munmap((void *)fileptr[0],fileptr[1]);
@ -350,7 +350,7 @@ int32_t iguana_peerblockrequest(struct supernet_info *myinfo,struct iguana_info
{
addr->lastsent = block->height;
printf("Sendlen.%d block.%d %s to %s\n",total,block->height,bits256_str(str,block->RO.hash2),addr->ipaddr);
if ( 0 )
if ( (0) )
{
struct iguana_txblock txdata; int32_t checklen; static struct OS_memspace RAWMEM;
if ( RAWMEM.ptr == 0 )

22
iguana/iguana_txidfind.c

@ -18,7 +18,7 @@
int32_t iguana_alloctxbits(struct iguana_info *coin,struct iguana_ramchain *ramchain)
{
static int64_t total; struct iguana_ramchaindata *rdata;
if ( 0 && ramchain->txbits == 0 && (rdata= ramchain->H.data) != 0 )
if ( (0) && ramchain->txbits == 0 && (rdata= ramchain->H.data) != 0 )
{
int32_t tlen; uint8_t *TXbits;
TXbits = RAMCHAIN_PTR(rdata,TXoffset);
@ -65,7 +65,7 @@ uint32_t iguana_sparseadd(uint8_t *bits,uint32_t ind,int32_t width,uint32_t tabl
printf("iguana_sparseadd tablesize zero illegal\n");
return(0);
}
if ( 0 && setind == 0 )
if ( (0) && setind == 0 )
{
char str[65];
for (i=n=0; i<tablesize; i++)
@ -88,7 +88,7 @@ uint32_t iguana_sparseadd(uint8_t *bits,uint32_t ind,int32_t width,uint32_t tabl
//if ( setind == 0 )
// ramchain->sparsesearches++;
//else ramchain->sparseadds++;
if ( 0 && (rdata= ramchain->H.data) != 0 && (ramchain->sparsesearches % 1000000) == 0 )
if ( (0) && (rdata= ramchain->H.data) != 0 && (ramchain->sparsesearches % 1000000) == 0 )
printf("[%3d] %7d.[%-2d %8d] %5.3f adds.(%-10ld %10ld) search.(hits.%-10ld %10ld) %5.2f%% max.%ld\n",ramchain->height/rdata->numblocks,ramchain->height,width,tablesize,(double)(ramchain->sparseadditers + ramchain->sparsesearchiters)/(1+ramchain->sparsesearches+ramchain->sparseadds),ramchain->sparseadds,ramchain->sparseadditers,ramchain->sparsehits,ramchain->sparsesearches,100.*(double)ramchain->sparsehits/(1+ramchain->sparsesearches),ramchain->sparsemax+1);
if ( width == 32 )
{
@ -123,7 +123,7 @@ uint32_t iguana_sparseadd(uint8_t *bits,uint32_t ind,int32_t width,uint32_t tabl
else
{
bitoffset = (ind * width);
if ( 0 && setind == 0 )
if ( (0) && setind == 0 )
printf("tablesize.%d width.%d bitoffset.%d\n",tablesize,width,(int32_t)bitoffset);
for (i=0; i<tablesize; i++,ind++,bitoffset+=width)
{
@ -141,7 +141,7 @@ uint32_t iguana_sparseadd(uint8_t *bits,uint32_t ind,int32_t width,uint32_t tabl
{
ptr = &bits[bitoffset >> 3];
modval = (bitoffset & 7);
if ( 0 && setind == 0 )
if ( (0) && setind == 0 )
printf("tablesize.%d width.%d bitoffset.%d modval.%d i.%d\n",tablesize,width,(int32_t)bitoffset,modval,i);
for (x=j=0; j<width; j++,modval++)
{
@ -152,7 +152,7 @@ uint32_t iguana_sparseadd(uint8_t *bits,uint32_t ind,int32_t width,uint32_t tabl
}
}
else x = bits[bitoffset >> 3];
if ( 0 && setind == 0 )
if ( (0) && setind == 0 )
printf("x.%d\n",x);
if ( x == 0 )
{
@ -179,7 +179,7 @@ uint32_t iguana_sparseadd(uint8_t *bits,uint32_t ind,int32_t width,uint32_t tabl
}
}
else bits[bitoffset >> 3] = setind;
if ( 0 )
if ( (0) )
{
for (x=j=0; j<width; j++)
{
@ -317,7 +317,7 @@ struct iguana_txid *iguana_txidfind(struct iguana_info *coin,int32_t *heightp,st
//printf("found txidind.%d\n",txidind);
if ( bits256_cmp(txid,T[txidind].txid) == 0 )
{
if ( 0 )
if ( (0) )
{
int32_t j; struct iguana_block *block;
for (j=0; j<bp->n; j++)
@ -395,7 +395,7 @@ int32_t iguana_txidfastfind(struct iguana_info *coin,int32_t *heightp,bits256 tx
}
return(firstvout);
}
else if ( 0 )
else if ( (0) )
{
int32_t k;
for (k=-16; k<0; k++)
@ -497,7 +497,7 @@ uint32_t iguana_fastfindinit(struct iguana_info *coin)
{
fprintf(stderr,".");
sorted = coin->fast[i];
if ( 0 )
if ( (0) )
{
coin->fast[i] = calloc(1,coin->fastsizes[i]);
memcpy(coin->fast[i],sorted,coin->fastsizes[i]);
@ -509,7 +509,7 @@ uint32_t iguana_fastfindinit(struct iguana_info *coin)
if ( (num+1)*16 + tablesize*sizeof(*hashtable) == coin->fastsizes[i] )
{
hashtable = (int32_t *)((long)sorted + (1 + num)*16);
if ( 0 )
if ( (0) )
{
coin->fasttables[i] = calloc(tablesize,sizeof(*hashtable));
memcpy(coin->fasttables[i],hashtable,tablesize * sizeof(*hashtable));

36
iguana/iguana_unspents.c

@ -361,7 +361,7 @@ struct iguana_pkhash *iguana_pkhashfind(struct iguana_info *coin,struct iguana_r
{
if ( (bp= coin->bundles[i]) != 0 )
{
if ( 0 && coin->RTramchain_busy != 0 )
if ( (0) && coin->RTramchain_busy != 0 )
{
printf("iguana_pkhashfind: unexpected access when RTramchain_busy\n");
return(0);
@ -511,10 +511,10 @@ int32_t iguana_RTscanunspents(struct supernet_info *myinfo,struct iguana_info *c
int64_t iguana_RTpkhashbalance(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *array,uint64_t *spentp,struct iguana_outpoint *unspents,int32_t *nump,struct iguana_ramchain *ramchain,struct iguana_pkhash *p,struct iguana_outpoint lastpt,uint8_t rmd160[20],char *coinaddr,uint8_t *pubkey33,int32_t lastheight,int32_t minconf,int32_t maxconf,char *remoteaddr,int32_t includespent)
{
struct iguana_unspent *U; struct iguana_utxo *U2; int32_t firstslot,vout,spentflag,max,uheight,spentheight; uint32_t pkind=0,unspentind; uint64_t spent = 0,checkval,deposits = 0; struct iguana_txid *T; struct iguana_account *A2; struct iguana_outpoint outpt; struct iguana_ramchaindata *rdata = 0; uint64_t RTspend = 0; bits256 txid;
struct iguana_unspent *U; struct iguana_utxo *U2; int32_t firstslot,vout,spentflag,max,uheight,spentheight=0; uint32_t pkind=0,unspentind; uint64_t spent = 0,checkval,deposits = 0; struct iguana_txid *T; struct iguana_account *A2; struct iguana_outpoint outpt; struct iguana_ramchaindata *rdata = 0; uint64_t RTspend = 0; bits256 txid;
max = *nump;
*spentp = *nump = 0;
if ( 0 && coin->RTramchain_busy != 0 )
if ( (0) && coin->RTramchain_busy != 0 )
{
printf("iguana_pkhashbalance: unexpected access when RTramchain_busy\n");
return(0);
@ -599,7 +599,7 @@ int64_t iguana_RTpkhashbalance(struct supernet_info *myinfo,struct iguana_info *
}
unspentind = U2[unspentind].prevunspentind;
}
if ( 0 && llabs((int64_t)spent - (int64_t)checkval - (int64_t)RTspend) > SMALLVAL )
if ( (0) && llabs((int64_t)spent - (int64_t)checkval - (int64_t)RTspend) > SMALLVAL )
printf("spend %s: [%d] deposits %.8f spent %.8f check %.8f (%.8f) vs A2[%u] %.8f\n",lastheight==IGUANA_MAXHEIGHT?"checkerr":"",lastpt.hdrsi,dstr(deposits),dstr(spent),dstr(checkval)+dstr(RTspend),dstr(*spentp),pkind,dstr(A2[pkind].total));
}
(*spentp) = spent;
@ -613,7 +613,7 @@ int32_t iguana_RTpkhasharray(struct supernet_info *myinfo,struct iguana_info *co
int32_t i,n,m,numunspents; uint64_t spent,deposits,netbalance,total; struct iguana_outpoint lastpt; struct iguana_pkhash *p,_p; struct iguana_ramchain *ramchain; struct iguana_bundle *bp;
if ( coin->RTheight == 0 )
return(-1);
if ( 0 && coin->RTramchain_busy != 0 )
if ( (0) && coin->RTramchain_busy != 0 )
{
printf("iguana_pkhasharray: unexpected access when RTramchain_busy\n");
return(-1);
@ -682,7 +682,7 @@ uint64_t iguana_RTunspents(struct supernet_info *myinfo,struct iguana_info *coin
{
uint64_t total=0,sum=0; struct iguana_pkhash *P; uint8_t *addrtypes,*pubkeys; int32_t i,j,numunspents,maxunspents,flag = 0; char coinaddr[64];
//portable_mutex_lock(&coin->RTmutex);
while ( 0 && coin->RTramchain_busy != 0 )
while ( (0) && coin->RTramchain_busy != 0 )
{
fprintf(stderr,"iguana_pkhasharray: %s unexpected access when RTramchain_busy\n",coin->symbol);
sleep(1);
@ -916,7 +916,7 @@ void iguana_unspents_mark(struct supernet_info *myinfo,struct iguana_info *coin,
printf("slot.[%d] <- %s/v%d\n",firstslot,bits256_str(str,txid),vout);
coin->markedunspents[firstslot] = txid;
coin->markedunspents[firstslot].ushorts[15] = vout;
if ( coin->utxofp == 0 )
if ( (0) && coin->utxofp == 0 )
{
sprintf(fname,"%s/%s/utxo.dat",GLOBAL_DBDIR,coin->symbol), OS_compatible_path(fname);
if ( (coin->utxofp= fopen(fname,"rb+")) == 0 )
@ -939,6 +939,7 @@ void iguana_unspents_mark(struct supernet_info *myinfo,struct iguana_info *coin,
void iguana_unspents_markinit(struct supernet_info *myinfo,struct iguana_info *coin)
{
char *filestr,fname[1024]; FILE *fp; long filesize; bits256 filetxid; cJSON *array,*item; int32_t i,filevout,n,firstslot;
return;
sprintf(fname,"%s/%s/utxo.dat",GLOBAL_DBDIR,coin->symbol), OS_compatible_path(fname);
if ( (fp= fopen(fname,"rb")) != 0 )
{
@ -948,7 +949,7 @@ void iguana_unspents_markinit(struct supernet_info *myinfo,struct iguana_info *c
{
if ( firstslot >= 0 )
{
char str[65]; printf("%s slot.[%d] <- %s/v%d\n",fname,firstslot,bits256_str(str,filetxid),filevout);
//char str[65]; printf("%s slot.[%d] <- %s/v%d\n",fname,firstslot,bits256_str(str,filetxid),filevout);
coin->markedunspents[firstslot] = filetxid;
coin->markedunspents[firstslot].ushorts[15] = filevout;
}
@ -974,7 +975,7 @@ void iguana_unspents_markinit(struct supernet_info *myinfo,struct iguana_info *c
{
if ( firstslot >= 0 )
{
char str[65]; printf("slot.[%d] <- %s/v%d\n",firstslot,bits256_str(str,filetxid),filevout);
//char str[65]; printf("slot.[%d] <- %s/v%d\n",firstslot,bits256_str(str,filetxid),filevout);
coin->markedunspents[firstslot] = filetxid;
coin->markedunspents[firstslot].ushorts[15] = filevout;
}
@ -1181,7 +1182,7 @@ cJSON *iguana_RTlistunspent(struct supernet_info *myinfo,struct iguana_info *coi
int32_t iguana_RTunspentslists(struct supernet_info *myinfo,struct iguana_info *coin,uint64_t *totalp,struct iguana_outpoint *unspents,int32_t max,uint64_t required,int32_t minconf,cJSON *addresses,char *remoteaddr)
{
uint64_t sum = 0; int32_t i,n,firstslot,numunspents,numaddrs; uint8_t pubkey[65]; char *coinaddr,*spendscriptstr; struct iguana_outpoint outpt; cJSON *array,*item;
uint64_t sum = 0; int32_t i=0,n,firstslot,numunspents,numaddrs; uint8_t pubkey[65]; char *coinaddr,*spendscriptstr; struct iguana_outpoint outpt; cJSON *array,*item;
*totalp = 0;
numunspents = 0;
if ( (numaddrs= cJSON_GetArraySize(addresses)) == 0 )
@ -1538,7 +1539,7 @@ int32_t iguana_utxoaddr_check(struct supernet_info *myinfo,struct iguana_info *c
sum = 0;
bitcoin_address(coinaddr,utxoaddr->p2sh == 0 ? coin->chain->pubtype : coin->chain->p2shtype,utxoaddr->rmd160,sizeof(utxoaddr->rmd160));
numunspents += iguana_RTaddr_unspents(myinfo,coin,&sum,&unspents[numunspents],max-numunspents,coinaddr,0,lastheight,0);
if ( 0 && utxoaddr->histbalance != 0 && strcmp(coin->symbol,"BTCD") == 0 )
if ( (0) && utxoaddr->histbalance != 0 && strcmp(coin->symbol,"BTCD") == 0 )
{
total += utxoaddr->histbalance;
//printf("fiat/revs sendtoaddress %s %.8f # total %.8f\n",coinaddr,dstr(utxoaddr->histbalance),dstr(total));
@ -1554,7 +1555,7 @@ int32_t iguana_utxoaddr_check(struct supernet_info *myinfo,struct iguana_info *c
flag = 1;
//break;
}
if ( 0 && flag == 0 )//sum != utxoaddr->histbalance || checkbalance != sum )
if ( (0) && flag == 0 )//sum != utxoaddr->histbalance || checkbalance != sum )
{
bad++;
for (i=0; i<numunspents; i++)
@ -1624,7 +1625,7 @@ uint64_t iguana_RTstart(struct supernet_info *myinfo,struct iguana_info *coin,in
uint64_t iguana_utxoaddr_gen(struct supernet_info *myinfo,struct iguana_info *coin,int32_t maxheight)
{
char fname[1024],fname2[1024],coinaddr[64],str[65],checkaddr[64]; struct iguana_utxoaddr *utxoaddr,UA,*tmp,*last=0; uint16_t hdrsi; uint8_t *table,item[UTXOADDR_ITEMSIZE]; uint32_t *counts,*offsets,offset,n; int32_t total,errs=0,height=0,j,k,ind,tablesize=0; struct iguana_bundle *bp; struct iguana_ramchaindata *rdata=0; uint64_t checkbalance=0,balance = 0;
char fname[1024],fname2[1024],coinaddr[64],str[65],checkaddr[64]; struct iguana_utxoaddr *utxoaddr,UA,*tmp,*last=0; uint16_t hdrsi; uint8_t *table,item[UTXOADDR_ITEMSIZE]; uint32_t *counts,*offsets,offset,n; int32_t total,errs=0,height=0,ind,tablesize=0; struct iguana_bundle *bp; struct iguana_ramchaindata *rdata=0; uint64_t checkbalance=0,balance = 0;
for (hdrsi=0; hdrsi<coin->bundlescount-1; hdrsi++)
{
if ( (bp= coin->bundles[hdrsi]) != 0 && bp->bundleheight < maxheight )
@ -1633,7 +1634,7 @@ uint64_t iguana_utxoaddr_gen(struct supernet_info *myinfo,struct iguana_info *co
sprintf(fname2,"%s/%s/utxoaddrs.%d",GLOBAL_DBDIR,coin->symbol,height), OS_portable_path(fname2);
if ( iguana_utxoaddr_map(coin,fname2) != 0 )
{
if ( 0 && strcmp("BTCD",coin->symbol) == 0 )
if ( (0) && strcmp("BTCD",coin->symbol) == 0 )
errs = iguana_utxoaddr_validate(myinfo,coin,height);
printf("nogen %s HIST BALANCE %s %.8f errs %d\n",fname2,bits256_str(str,coin->utxoaddrhash),dstr(coin->histbalance),errs);
if ( errs == 0 && coin->histbalance > 0 && height > 0 )
@ -1731,14 +1732,14 @@ uint64_t iguana_utxoaddr_gen(struct supernet_info *myinfo,struct iguana_info *co
{
qsort(&table[offsets[ind] * UTXOADDR_ITEMSIZE],counts[ind],UTXOADDR_ITEMSIZE,_utxoaddr_cmp);
continue;
for (j=0; j<counts[ind]; j++)
/*for (j=0; j<counts[ind]; j++)
{
iguana_rwutxoaddr(0,ind,&table[(offsets[ind]+j) * UTXOADDR_ITEMSIZE],&UA);
for (k=0; k<20; k++)
printf("%02x",UA.rmd160[k]);
bitcoin_address(coinaddr,coin->chain->pubtype,UA.rmd160,sizeof(UA.rmd160));
//printf(" [%4d] p%-5d %12.8f ind.%04x %d %s\n",UA.hdrsi,UA.pkind,dstr(UA.histbalance),ind,j,coinaddr);
}
}*/
}
}
if ( iguana_utxoaddr_save(coin,fname,balance,counts,offsets,table) == 0 )
@ -1762,7 +1763,7 @@ uint64_t iguana_utxoaddr_gen(struct supernet_info *myinfo,struct iguana_info *co
{
printf("validating %s HIST BALANCE %s %.8f errs %d\n",fname2,bits256_str(str,coin->utxoaddrhash),dstr(coin->histbalance),errs);
errs = 0;
if ( 0 && strcmp("BTCD",coin->symbol) == 0 )
if ( (0) && strcmp("BTCD",coin->symbol) == 0 )
errs = iguana_utxoaddr_validate(myinfo,coin,height);
printf("gen %s HIST BALANCE %s %.8f errs %d\n",fname2,bits256_str(str,coin->utxoaddrhash),dstr(coin->histbalance),errs);
if ( errs != 0 || height == 0 )
@ -1798,6 +1799,7 @@ void iguana_utxoaddrs_purge(struct iguana_info *coin)
#include "../includes/iguana_apidefs.h"
#include "../includes/iguana_apideclares.h"
#include "../includes/iguana_apideclares2.h"
STRING_AND_INT(iguana,snapshot,symbol,height)
{

2
iguana/iguana_volatiles.c

@ -290,7 +290,7 @@ int32_t iguana_volatileupdate(struct iguana_info *coin,int32_t incremental,struc
utxo = &spentchain->Uextras[spent_unspentind];
if ( utxo->spentflag == 0 )
{
if ( 0 && fromheight/coin->chain->bundlesize >= coin->current->hdrsi )
if ( (0) && fromheight/coin->chain->bundlesize >= coin->current->hdrsi )
printf("iguana_volatileupdate.%d: [%d] spent.(u%u %.8f pkind.%d) fromht.%d [%d] spendind.%d\n",incremental,spent_hdrsi,spent_unspentind,dstr(spent_value),spent_pkind,fromheight,fromheight/coin->chain->bundlesize,spendind);
utxo->prevunspentind = A2[spent_pkind].lastunspentind;
utxo->spendind = spendind;

14
iguana/iguana_wallet.c

@ -818,7 +818,7 @@ cJSON *iguana_walletiterate(struct supernet_info *myinfo,struct iguana_info *coi
}
printf("persistent address not found in wallet, autoadd.(%s)\n",coinaddr);
}
else if ( persistent_flag != 0 && 0 )
else if ( persistent_flag != 0 && (0) )
printf("found persistent address in wallet\n");
}
portable_mutex_unlock(&myinfo->bu_mutex);
@ -995,6 +995,7 @@ cJSON *iguana_privkeysjson(struct supernet_info *myinfo,struct iguana_info *coin
#include "../includes/iguana_apidefs.h"
#include "../includes/iguana_apideclares.h"
#include "../includes/iguana_apideclares2.h"
int64_t iguana_addressreceived(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *json,char *remoteaddr,cJSON *txids,cJSON *vouts,cJSON *unspents,cJSON *spends,char *coinaddr,int32_t minconf,int32_t firstheight)
{
@ -1360,7 +1361,16 @@ TWOSTRINGS_AND_INT(bitcoinrpc,walletpassphrase,password,permanentfile,timeout)
if ( coin != 0 )
{
bitcoin_address(coin->changeaddr,coin->chain->pubtype,myinfo->persistent_pubkey33,33);
if ( coin->FULLNODE < 0 )
{
char wifstr[64];
bitcoin_priv2wif(wifstr,myinfo->persistent_priv,coin->chain->wiftype);
jumblr_importprivkey(myinfo,coin,wifstr);
}
}
if ( bits256_nonz(myinfo->persistent_priv) != 0 )
smartaddress_add(myinfo,myinfo->persistent_priv,"","");
//basilisk_unspents_update(myinfo,coin);
return(retstr);
}
@ -1593,7 +1603,7 @@ STRING_ARG(bitcoinrpc,dumpwallet,filename)
{
if ( (walletobj= jobj(strobj,"wallet")) != 0 )
jadd(retjson,"wallet",jduplicate(walletobj));
if ( 0 && (walletobj= iguana_walletjson(myinfo)) != 0 )
if ( (0) && (walletobj= iguana_walletjson(myinfo)) != 0 )
jadd(retjson,"memory",walletobj);
free_json(strobj);
}

778
iguana/kmd_lookup.h

@ -0,0 +1,778 @@
/******************************************************************************
* 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. *
* *
******************************************************************************/
#ifndef INCLUDE_KMDLOOKUP_H
#define INCLUDE_KMDLOOKUP_H
#define KMD_EXPLORER_LAG 3
struct kmd_voutinfo
{
bits256 spendtxid;
uint64_t amount;
uint16_t spendvini;
uint8_t type_rmd160[21], pad;
} PACKED;
struct kmd_transaction
{
bits256 txid; int32_t height,numvouts,numvins; uint32_t timestamp;
struct kmd_voutinfo vouts[];
} PACKED;
struct kmd_transactionhh
{
UT_hash_handle hh;
struct kmd_transaction *tx;
long fpos;
int32_t numvouts,numvins;
struct kmd_transactionhh *ptrs[];
};
struct kmd_addresshh
{
UT_hash_handle hh;
struct kmd_transactionhh *prev,*lastprev;
uint8_t type_rmd160[21], pad;
};
struct kmd_addresshh *_kmd_address(struct iguana_info *coin,uint8_t type_rmd160[21])
{
struct kmd_addresshh *addr;
portable_mutex_lock(&coin->kmdmutex);
HASH_FIND(hh,coin->kmd_addresses,type_rmd160,21,addr);
portable_mutex_unlock(&coin->kmdmutex);
if ( addr != 0 && 0 )
{
char coinaddr[64];
bitcoin_address(coinaddr,type_rmd160[0],&type_rmd160[1],20);
printf("%s found (%s) %02x\n",coin->symbol,coinaddr,type_rmd160[0]);
}
return(addr);
}
struct kmd_addresshh *_kmd_addressadd(struct iguana_info *coin,uint8_t type_rmd160[21])
{
struct kmd_addresshh *addr;
addr = calloc(1,sizeof(*addr));
memcpy(addr->type_rmd160,type_rmd160,21);
if ( 0 )
{
char coinaddr[64];
bitcoin_address(coinaddr,type_rmd160[0],&type_rmd160[1],20);
printf("%s NEW ADDRESS.(%s) %02x\n",coin->symbol,coinaddr,type_rmd160[0]);
}
portable_mutex_lock(&coin->kmdmutex);
HASH_ADD_KEYPTR(hh,coin->kmd_addresses,addr->type_rmd160,21,addr);
portable_mutex_unlock(&coin->kmdmutex);
return(addr);
}
struct kmd_addresshh *kmd_address(struct iguana_info *coin,char *coinaddr)
{
uint8_t type_rmd160[21];
bitcoin_addr2rmd160(&type_rmd160[0],&type_rmd160[1],coinaddr);
return(_kmd_address(coin,type_rmd160));
}
struct kmd_transactionhh *kmd_transaction(struct iguana_info *coin,bits256 txid)
{
struct kmd_transactionhh *tx;
portable_mutex_lock(&coin->kmdmutex);
HASH_FIND(hh,coin->kmd_transactions,txid.bytes,sizeof(txid),tx);
portable_mutex_unlock(&coin->kmdmutex);
return(tx);
}
int32_t kmd_transactionvin(struct iguana_info *coin,bits256 spendtxid,int32_t vini,bits256 txid,int32_t vout)
{
struct kmd_transactionhh *ptr,*spendptr=0;
if ( bits256_nonz(txid) == 0 || vout < 0 )
return(0); // coinbase must be
if ( (ptr= kmd_transaction(coin,txid)) != 0 && vout < ptr->numvouts && (spendptr= kmd_transaction(coin,spendtxid)) != 0 )
{
ptr->ptrs[(vout<<1) + 1] = spendptr;
if ( bits256_cmp(ptr->tx->vouts[vout].spendtxid,spendtxid) != 0 || ptr->tx->vouts[vout].spendvini != vini )
{
if ( bits256_nonz(ptr->tx->vouts[vout].spendtxid) != 0 )
printf("ht.%d vout.%d overwriting nonz spend\n",ptr->tx->height,vout);
//uint8_t type_rmd160[21]; char str[65];
//bitcoin_addr2rmd160(&type_rmd160[0],&type_rmd160[1],"RR5yAkzaxJeCVTwvpgCGsNcSPAZjeq3av4");
//if ( memcmp(type_rmd160,ptr->tx->vouts[vout].type_rmd160,21) == 0 )
// printf("RR5yAkzaxJeCVTwvpgCGsNcSPAZjeq3av4 %p vout.%d spend %.8f by %s/%d %p\n",ptr,vout,dstr(ptr->tx->vouts[vout].amount),bits256_str(str,spendtxid),vini,spendptr);
ptr->tx->vouts[vout].spendtxid = spendtxid;
ptr->tx->vouts[vout].spendvini = vini;
}
return(0);
}
char str[65]; printf("%s.vin error %s vout.%d of %d vs ptr %p [%d] spent.%p\n",coin->symbol,bits256_str(str,txid),vout,ptr!=0?ptr->numvouts:-1,ptr,ptr!=0?ptr->numvouts:-1,spendptr);
return(-1);
}
void kmd_transactionvout(struct iguana_info *coin,struct kmd_transactionhh *ptr,int32_t vout,uint64_t amount,uint8_t type_rmd160[21],bits256 spendtxid,int32_t spendvini)
{
struct kmd_addresshh *addr; struct kmd_transaction *tx = 0;
if ( 0 )
{
char coinaddr[64],str[65];
bitcoin_address(coinaddr,type_rmd160[0],&type_rmd160[1],20);
if ( strcmp(coinaddr,"RCsKEQ3r5Xxw4ZtK4CH9VzvfGpTFMdPpsh") == 0 )
printf("%s ht.%d %s VOUT %d %.8f\n",coinaddr,ptr->tx->height,bits256_str(str,ptr->tx->txid),vout,dstr(amount));
}
if ( vout < ptr->numvouts && (tx= ptr->tx) != 0 )
{
tx->vouts[vout].spendtxid = spendtxid;
tx->vouts[vout].spendvini = spendvini;
tx->vouts[vout].amount = amount;
memcpy(tx->vouts[vout].type_rmd160,type_rmd160,21);
if ( (addr= _kmd_address(coin,type_rmd160)) == 0 )
addr = _kmd_addressadd(coin,type_rmd160);
if ( addr != 0 )
{
if ( addr->prev != ptr )
{
ptr->ptrs[vout << 1] = addr->prev;
addr->lastprev = addr->prev;
addr->prev = ptr;
}
else
{
//printf("tricky case same address in different vouts, make sure backlink is right\n");
ptr->ptrs[vout<<1] = addr->lastprev;
}
} else printf("kmd_transactionvout unexpected null addr\n");
} else printf("vout.%d wont fit into numvouts.[%d] or null tx.%p\n",vout,ptr->numvouts,tx);
}
struct kmd_transactionhh *kmd_transactionadd(struct iguana_info *coin,struct kmd_transaction *tx,int32_t numvouts,int32_t numvins)
{
struct kmd_transactionhh *ptr; //char str[65];
if ( (ptr= kmd_transaction(coin,tx->txid)) == 0 )
{
ptr = calloc(1,sizeof(*ptr) + (sizeof(*ptr->ptrs)*numvouts*2));
ptr->numvouts = numvouts;
ptr->numvins = numvins;
ptr->tx = tx;
portable_mutex_lock(&coin->kmdmutex);
//char str[65]; printf("%s ht.%d u.%u NEW TXID.(%s) vouts.[%d]\n",coin->symbol,tx->height,tx->timestamp,bits256_str(str,tx->txid),numvouts);
HASH_ADD_KEYPTR(hh,coin->kmd_transactions,tx->txid.bytes,sizeof(tx->txid),ptr);
portable_mutex_unlock(&coin->kmdmutex);
} // else printf("warning adding already existing txid %s\n",bits256_str(str,tx->txid));
return(ptr);
}
struct kmd_transaction *kmd_transactionalloc(bits256 txid,int32_t height,uint32_t timestamp,int32_t numvouts,int32_t numvins)
{
struct kmd_transaction *tx;
tx = calloc(1,sizeof(*tx) + sizeof(struct kmd_voutinfo)*numvouts);
tx->numvouts = numvouts;
tx->numvins = numvins;
tx->txid = txid;
tx->height = height;
tx->timestamp = timestamp;
return(tx);
}
void kmd_flushfiles(struct iguana_info *coin)
{
if ( coin->kmd_txidfp != 0 )
fflush(coin->kmd_txidfp);
if ( coin->kmd_spendfp != 0 )
fflush(coin->kmd_spendfp);
}
FILE *kmd_txidinit(struct iguana_info *coin)
{
int32_t i; FILE *fp; char fname[1024]; struct kmd_transactionhh *ptr; struct kmd_transaction T,*tx; struct kmd_voutinfo V; long lastpos=0;
sprintf(fname,"%s/TRANSACTIONS/%s",GLOBAL_DBDIR,coin->symbol);
if ( (fp= fopen(fname,"rb+")) != 0 )
{
while ( fread(&T,1,sizeof(T),fp) == sizeof(T) )
{
if ( (tx= kmd_transactionalloc(T.txid,T.height,T.timestamp,T.numvouts,T.numvins)) != 0 )
{
//char str[65]; printf("INIT %s.[%d] vins.[%d] ht.%d %u\n",bits256_str(str,T.txid),T.numvouts,T.numvins,T.height,T.timestamp);
if ( (ptr= kmd_transactionadd(coin,tx,T.numvouts,T.numvins)) != 0 )
{
if ( ptr != kmd_transaction(coin,tx->txid) )
printf("%s ERROR: %p != %p for ht.%d\n",coin->symbol,ptr,kmd_transaction(coin,tx->txid),tx->height);
ptr->fpos = lastpos;
ptr->numvins = T.numvins;
ptr->numvouts = T.numvouts;
for (i=0; i<T.numvouts; i++)
{
if ( fread(&V,1,sizeof(V),fp) == sizeof(V) )
{
kmd_transactionvout(coin,ptr,i,V.amount,V.type_rmd160,V.spendtxid,V.spendvini);
}
else
{
printf("%s error loading vout.%d ht.%d\n",coin->symbol,i,T.height);
break;
}
}
if ( i == T.numvouts )
{
lastpos = ftell(fp);
if ( T.height > coin->kmd_height )
coin->kmd_height = T.height;
} else break;
}
} else break;
}
printf("%s finished txidinit fpos %ld vs lastpos %ld\n",coin->symbol,ftell(fp),lastpos);
fseek(fp,lastpos,SEEK_SET);
} else fp = fopen(fname,"wb+");
return(fp);
}
FILE *kmd_spendinit(struct iguana_info *coin)
{
int32_t i,numvins,spentvout; FILE *fp; char fname[1024],str[65]; bits256 txid,spenttxid; struct kmd_transactionhh *ptr,*tmp; struct kmd_voutinfo *vptr; long lastpos=0;
sprintf(fname,"%s/TRANSACTIONS/%s.spends",GLOBAL_DBDIR,coin->symbol);
if ( (fp= fopen(fname,"rb+")) != 0 )
{
while ( fread(&txid,1,sizeof(txid),fp) == sizeof(txid) )
{
if ( fread(&numvins,1,sizeof(numvins),fp) == sizeof(numvins) )
{
for (i=0; i<numvins; i++)
{
if ( fread(&spenttxid,1,sizeof(spenttxid),fp) == sizeof(spenttxid) &&
fread(&spentvout,1,sizeof(spentvout),fp) == sizeof(spentvout) )
{
if ( kmd_transactionvin(coin,txid,i,spenttxid,spentvout) < 0 )
{
printf("%s error adding spend %s %d of %d\n",coin->symbol,bits256_str(str,txid),i,numvins);
//break;
}
} else break;
}
if ( i == numvins )
lastpos = ftell(fp);
else break;
} else break;
}
printf("%s finished spendinit fpos %ld vs lastpos %ld\n",coin->symbol,ftell(fp),lastpos);
fseek(fp,lastpos,SEEK_SET);
HASH_ITER(hh,coin->kmd_transactions,ptr,tmp)
{
//printf("scan for spends ht.%d\n",ptr->tx->height);
for (i=0; i<ptr->numvouts; i++)
{
vptr = &ptr->tx->vouts[i];
if ( vptr->spendvini >= 0 && bits256_nonz(vptr->spendtxid) != 0 )
{
if ( ptr->ptrs[(i<<1) + 1] != kmd_transaction(coin,vptr->spendtxid) )
{
printf("%s mismatch %s spend.%d %p %p\n",coin->symbol,bits256_str(str,vptr->spendtxid),i,ptr->ptrs[(i<<1) + 1],kmd_transaction(coin,vptr->spendtxid));
}
}
}
}
} else fp = fopen(fname,"wb+");
return(fp);
}
cJSON *kmd_transactionjson(int32_t height,struct kmd_transactionhh *ptr,char *typestr)
{
int32_t i; char coinaddr[64]; cJSON *item,*array,*obj = cJSON_CreateObject();
array = cJSON_CreateArray();
jaddstr(obj,"type",typestr);
jaddbits256(obj,"txid",ptr->tx->txid);
jaddnum(obj,"height",ptr->tx->height);
jaddnum(obj,"timestamp",ptr->tx->timestamp);
for (i=0; i<ptr->numvouts; i++)
{
item = cJSON_CreateObject();
bitcoin_address(coinaddr,ptr->tx->vouts[i].type_rmd160[0],&ptr->tx->vouts[i].type_rmd160[1],20);
jaddnum(item,coinaddr,dstr(ptr->tx->vouts[i].amount));
jaddi(array,item);
}
jadd(obj,"vouts",array);
return(obj);
}
cJSON *kmd_unspentjson(struct supernet_info *myinfo,struct iguana_info *coin,int32_t height,struct kmd_transaction *tx,int32_t vout,int32_t is_listunspent)
{
char *script; cJSON *sobj,*txout,*item = cJSON_CreateObject();
jaddstr(item,"type","received");
jaddnum(item,"height",tx->height);
jaddnum(item,"timestamp",tx->timestamp);
jaddbits256(item,"txid",tx->txid);
jaddnum(item,"vout",vout);
jaddnum(item,"amount",dstr(tx->vouts[vout].amount));
if ( strcmp(coin->symbol,"KMD") == 0 )
jaddnum(item,"interest",dstr(_iguana_interest((uint32_t)time(NULL),coin->longestchain,tx->timestamp,tx->vouts[vout].amount)));
if ( is_listunspent != 0 )
{
//char str[65]; printf("get spendscriptstr for %s/v%d\n",bits256_str(str,tx->txid),vout);
if ( (txout= dpow_gettxout(myinfo,coin,tx->txid,vout)) != 0 )
{
//printf("got.(%s)\n",jprint(txout,0));
if ( (sobj= jobj(txout,"scriptPubKey")) != 0 && (script= jstr(sobj,"hex")) != 0 )
jaddstr(item,"scriptPubKey",script);
free_json(txout);
}
}
return(item);
}
cJSON *kmd_spentjson(int32_t height,struct kmd_transaction *tx,int32_t vout,struct kmd_transactionhh *spent)
{
cJSON *item = cJSON_CreateObject();
jaddstr(item,"type","sent");
jaddnum(item,"confirmations",height - tx->height);
jaddnum(item,"height",tx->height);
jaddnum(item,"timestamp",tx->timestamp);
jaddbits256(item,"txid",tx->txid);
jaddnum(item,"vout",vout);
jaddnum(item,"amount",dstr(tx->vouts[vout].amount));
jaddbits256(item,"spendtxid",tx->vouts[vout].spendtxid);
jaddnum(item,"vin",tx->vouts[vout].spendvini);
if ( spent != 0 )
{
jadd(item,"paid",kmd_transactionjson(height,spent,"paid"));
}
return(item);
}
int32_t kmd_height(struct iguana_info *coin)
{
char params[64],*curlstr; cJSON *curljson; int32_t height = 0;
strcpy(params,"[]");
if ( (curlstr= bitcoind_passthru(coin->symbol,coin->chain->serverport,coin->chain->userpass,"getinfo",params)) != 0 )
{
if ( (curljson= cJSON_Parse(curlstr)) != 0 )
{
height = juint(curljson,"blocks");
//printf("kmd_height.%d (%s)\n",height,jprint(curljson,0));
free_json(curljson);
}
free(curlstr);
}
return(height);
}
cJSON *kmd_gettxin(struct iguana_info *coin,bits256 txid,int32_t vout)
{
struct kmd_transactionhh *ptr,*spendptr; struct kmd_transaction *tx; cJSON *retjson;
if ( (ptr= kmd_transaction(coin,txid)) != 0 && (tx= ptr->tx) != 0 )
{
if ( vout >= ptr->numvouts )
return(cJSON_Parse("{\"error\":\"vout too big\"}"));
if ( (spendptr= ptr->ptrs[(vout << 1) + 1]) != 0 )
{
retjson = cJSON_CreateObject();
jaddstr(retjson,"result","success");
jaddstr(retjson,"status","spent");
jaddnum(retjson,"height",tx->height);
jaddnum(retjson,"timestamp",tx->timestamp);
jaddbits256(retjson,"txid",txid);
jaddnum(retjson,"vout",vout);
jaddnum(retjson,"value",dstr(tx->vouts[vout].amount));
jaddbits256(retjson,"spendtxid",tx->vouts[vout].spendtxid);
jaddnum(retjson,"vin",tx->vouts[vout].spendvini);
} else return(cJSON_Parse("{\"result\":\"success\",\"status\":\"unspent\"}"));
}
return(cJSON_Parse("{\"error\":\"txid not found\"}"));
}
cJSON *kmd_listaddress(struct supernet_info *myinfo,struct iguana_info *coin,char *coinaddr,int32_t mode,cJSON *array)
{
struct kmd_addresshh *addr; struct kmd_transactionhh *ptr=0,*spent,*prev=0; uint8_t type_rmd160[21]; int32_t i; char *retstr; cJSON *retjson;
if ( array == 0 )
array = cJSON_CreateArray();
//printf("%s listaddress.(%s)\n",coin->symbol,coinaddr);
if ( (retstr= bitcoinrpc_validateaddress(myinfo,coin,0,0,coinaddr)) != 0 )
{
if ( (retjson= cJSON_Parse(retstr)) != 0 )
{
if ( jobj(retjson,"error") != 0 && is_cJSON_False(jobj(retjson,"error")) == 0 )
{
printf("%s\n",retstr);
free(retstr);
return(retjson);
}
free_json(retjson);
}
free(retstr);
}
/*if ( time(NULL) > coin->kmd_lasttime+30 )
{
coin->kmd_lasttime = (uint32_t)time(NULL);
if ( (height= kmd_height(coin)) > coin->kmd_height+KMD_EXPLORER_LAG*2 )
{
printf("height.%d > kmd_height.%d\n",height,coin->kmd_height);
return(cJSON_Parse("[]"));
}
}*/
if ( strcmp("1111111111111111111114oLvT2",coinaddr) == 0 ) // null rmd160 from coinbase
return(cJSON_Parse("[]"));
bitcoin_addr2rmd160(&type_rmd160[0],&type_rmd160[1],coinaddr);
if ( (addr= _kmd_address(coin,type_rmd160)) != 0 && (ptr= addr->prev) != 0 && ptr->tx != 0 )
{
while ( ptr != 0 )
{
prev = 0;
for (i=0; i<ptr->numvouts; i++)
{
if ( memcmp(ptr->tx->vouts[i].type_rmd160,type_rmd160,21) == 0 )
{
spent = ptr->ptrs[(i<<1) + 1];
//if ( strcmp("RFpYbieWuKm2ZsTaKeWkrrEdeSkVzhqX8x",coinaddr) == 0 )
// printf("mode.%d [%d] %s ht.%d amount %.8f spent.%p\n",mode,coin->kmd_height,coinaddr,ptr->tx->height,dstr(ptr->tx->vouts[i].amount),spent);
if ( (mode == 0 && spent == 0) || (mode == 1 && spent != 0) || mode == 2 )
{
//if ( fulltx == 0 )
{
if ( mode == 0 )
jaddi(array,kmd_unspentjson(myinfo,coin,coin->kmd_height,ptr->tx,i,1));
else if ( mode == 1 )
jaddi(array,kmd_spentjson(coin->kmd_height,ptr->tx,i,spent));
else if ( mode == 2 )
{
if ( spent != 0 )
jaddi(array,kmd_spentjson(coin->kmd_height,ptr->tx,i,spent));
else jaddi(array,kmd_unspentjson(myinfo,coin,coin->kmd_height,ptr->tx,i,0));
}
}
/*else if ( flag == 0 )
{
if ( mode == 0 )
jaddi(array,kmd_transactionjson(coin->kmd_height,ptr,"received"));
else if ( mode == 1 )
{
jaddi(array,kmd_transactionjson(coin->kmd_height,ptr,"received"));
jaddi(array,kmd_transactionjson(coin->kmd_height,spent,"sent"));
}
else if ( mode == 2 )
{
if ( spent != 0 )
jaddi(array,kmd_transactionjson(coin->kmd_height,ptr,"spent"));
else jaddi(array,kmd_transactionjson(coin->kmd_height,ptr,"received"));
}
flag = 1;
}*/
}
if ( ptr->ptrs[i<<1] != 0 )
{
if ( prev == 0 )
prev = ptr->ptrs[i<<1];
else if ( prev != ptr->ptrs[i<<1] )
printf("%s ht.%d prev.%p != %p\n",coinaddr,ptr->tx->height,prev,ptr->ptrs[i<<1]);
}
}
}
ptr = prev;
}
} //else printf("no valid entry for (%s) %p %p\n",coinaddr,addr,ptr);
return(array);
}
cJSON *kmd_listunspent(struct supernet_info *myinfo,struct iguana_info *coin,char *coinaddr)
{
cJSON *retjson;
retjson = kmd_listaddress(myinfo,coin,coinaddr,0,0);
//printf("KMD utxos.(%s)\n",jprint(retjson,0));
return(retjson);
}
cJSON *kmd_listspent(struct supernet_info *myinfo,struct iguana_info *coin,char *coinaddr)
{
return(kmd_listaddress(myinfo,coin,coinaddr,1,0));
}
cJSON *kmd_listtransactions(struct supernet_info *myinfo,struct iguana_info *coin,char *coinaddr,int32_t count,int32_t skip)
{
cJSON *array = cJSON_CreateArray();
//if ( (height= kmd_height(coin)) > coin->kmd_height+KMD_EXPLORER_LAG )
// return(cJSON_Parse("[]"));
if ( count == 0 )
count = 100;
array = kmd_listaddress(myinfo,coin,coinaddr,0,0);
array = kmd_listaddress(myinfo,coin,coinaddr,1,array);
return(array);
}
int64_t _kmd_getbalance(struct supernet_info *myinfo,struct iguana_info *coin,char *coinaddr,uint64_t *receivedp,uint64_t *sentp,uint64_t *interestp)
{
int32_t iter,i,n; cJSON *array,*item; uint64_t value;
for (iter=1; iter<=2; iter++)
{
if ( (array= kmd_listaddress(myinfo,coin,coinaddr,iter,0)) != 0 )
{
if ( (n= cJSON_GetArraySize(array)) > 0 )
{
for (i=0; i<n; i++)
{
item = jitem(array,i);
if ( (value= jdouble(item,"amount")*SATOSHIDEN) != 0 || (value= jdouble(item,"value")*SATOSHIDEN) != 0 )
{
if ( iter == 2 )
{
*receivedp += value;
*interestp += jdouble(item,"interest") * SATOSHIDEN;
} else *sentp += value;
}
}
}
free_json(array);
}
}
return(*receivedp - *sentp);
}
cJSON *kmd_getbalance(struct supernet_info *myinfo,struct iguana_info *coin,char *coinaddr)
{
cJSON *retjson; double netbalance=0.,fbalance; uint64_t interest,i,s,r,sent=0,received=0; int64_t balance=0; struct kmd_addresshh *addr,*tmp; char address[64]; int32_t height = coin->kmd_height+1;
retjson = cJSON_CreateObject();
fbalance = 0.;
interest = 0;
if ( strcmp(coinaddr,"*") == 0 )
{
HASH_ITER(hh,coin->kmd_addresses,addr,tmp)
{
bitcoin_address(address,addr->type_rmd160[0],&addr->type_rmd160[1],20);
s = r = i = 0;
balance += _kmd_getbalance(myinfo,coin,address,&r,&s,&i);
netbalance += dstr(r);
netbalance -= dstr(s);
if ( (r - s) > 100000*SATOSHIDEN )
printf("{\"address\":\"%s\",\"received\":%.8f,\"sent\":%.8f,\"balance\":%.8f,\"supply\":%.8f,\"supplyf\":%.8f,\"interest\":%.8f}\n",address,dstr(r),dstr(s),dstr(r)-dstr(s),dstr(balance),netbalance,dstr(interest));
received += r;
sent += s;
interest += i;
}
if ( strcmp("KMD",coin->symbol) == 0 )
jaddnum(retjson,"interestpaid",dstr(balance) - 100000000 - (height*3));
}
else
{
balance = _kmd_getbalance(myinfo,coin,coinaddr,&received,&sent,&interest);
netbalance = dstr(balance);
}
jaddstr(retjson,"result","success");
jaddnum(retjson,"received",dstr(received));
jaddnum(retjson,"sent",dstr(sent));
//if ( fabs(netbalance*SATOSHIDEN - balance) > 1 )
jaddnum(retjson,"balancef",netbalance+1./(SATOSHIDEN*2)-SMALLVAL);
//else
jaddnum(retjson,"balance",dstr(balance));
jaddnum(retjson,"interest",dstr(interest));
jaddnum(retjson,"height",height);
if ( strcmp("KMD",coin->symbol) == 0 )
jaddnum(retjson,"mined",height*3);
return(retjson);
}
char *kmd_bitcoinblockhashstr(char *coinstr,char *serverport,char *userpass,int32_t height)
{
char numstr[128],*blockhashstr=0; bits256 hash2; struct iguana_info *coin;
sprintf(numstr,"%d",height);
if ( (blockhashstr= bitcoind_passthru(coinstr,serverport,userpass,"getblockhash",numstr)) == 0 )
return(0);
hash2 = bits256_conv(blockhashstr);
if ( blockhashstr == 0 || blockhashstr[0] == 0 || bits256_nonz(hash2) == 0 )
{
printf("%s couldnt get blockhash for %u, probably curl is disabled %p\n",coinstr,height,blockhashstr);
if ( blockhashstr != 0 )
free(blockhashstr);
if ( height == 0 )
{
if ( (coin= iguana_coinfind(coinstr)) != 0 )
{
bits256_str(numstr,*(bits256 *)coin->chain->genesis_hashdata);
return(clonestr(numstr));
}
}
return(0);
}
return(blockhashstr);
}
cJSON *kmd_blockjson(int32_t *heightp,char *coinstr,char *serverport,char *userpass,char *blockhashstr,int32_t height)
{
cJSON *json = 0; int32_t flag = 0; char buf[1024],*blocktxt = 0;
if ( blockhashstr == 0 )
blockhashstr = kmd_bitcoinblockhashstr(coinstr,serverport,userpass,height), flag = 1;
if ( blockhashstr != 0 )
{
sprintf(buf,"\"%s\"",blockhashstr);
blocktxt = bitcoind_passthru(coinstr,serverport,userpass,"getblock",buf);
//printf("get_blockjson.(%d %s) %s\n",height,blockhashstr,blocktxt);
if ( blocktxt != 0 && blocktxt[0] != 0 && (json= cJSON_Parse(blocktxt)) != 0 && heightp != 0 )
if ( (*heightp= juint(json,"height")) != height )
*heightp = -1;
if ( flag != 0 && blockhashstr != 0 )
free(blockhashstr);
if ( blocktxt != 0 )
free(blocktxt);
}
return(json);
}
int32_t _kmd_bitcoinscan(struct iguana_info *coin)
{
int32_t h,num=0,loadheight,lag,i,n,j,iter,numtxids,numvins,numvouts,flag=0,height=-1; cJSON *txjson,*vouts,*vins,*blockjson,*txids,*vout,*vin,*sobj,*addresses; bits256 zero,txid; char *curlstr,params[128],str[65]; struct kmd_transactionhh *ptr; struct kmd_transaction *tx; uint8_t type_rmd160[21];
if ( coin->kmd_didinit == 0 )
{
if ( (coin->kmd_txidfp= kmd_txidinit(coin)) == 0 )
printf("error initializing %s.kmd txid\n",coin->symbol);
else if ( (coin->kmd_spendfp= kmd_spendinit(coin)) == 0 )
printf("error initializing %s.kmd spend\n",coin->symbol);
coin->kmd_didinit = 1;
}
height = kmd_height(coin);
loadheight = coin->kmd_height+1;
lag = (strcmp(coin->symbol,"KMD") == 0 ? KMD_EXPLORER_LAG : 1);
while ( loadheight < height-lag )
{
flag = 0;
if ( (loadheight % 10000) == 0 )
printf("loading %s ht.%d vs height.%d - lag.%d kmdheight.%d\n",coin->symbol,loadheight,height,lag,coin->kmd_height);//,jprint(kmd_getbalance(coin,"*"),1));
if ( (blockjson= kmd_blockjson(&h,coin->symbol,coin->chain->serverport,coin->chain->userpass,0,loadheight)) != 0 )
{
if ( (txids= jarray(&numtxids,blockjson,"tx")) != 0 )
{
for (iter=0; iter<2; iter++)
for (i=0; i<numtxids; i++)
{
memset(&zero,0,sizeof(zero));
txid = jbits256(jitem(txids,i),0);
if ( iter == 0 && kmd_transaction(coin,txid) != 0 )
{
//printf("already have txid.%s\n",bits256_str(str,txid));
continue;
}
sprintf(params,"[\"%s\", 1]",bits256_str(str,txid));
if ( (curlstr= bitcoind_passthru(coin->symbol,coin->chain->serverport,coin->chain->userpass,"getrawtransaction",params)) != 0 )
{
if ( (txjson= cJSON_Parse(curlstr)) != 0 )
{
if ( bits256_cmp(txid,jbits256(txjson,"txid")) != 0 )
{
printf("txid mismatch error ht.%d i.%d\n",loadheight,i);
continue;
}
vouts = jarray(&numvouts,txjson,"vout");
vins = jarray(&numvins,txjson,"vin");
tx = 0;
ptr = 0;
if ( iter == 0 )
{
if ( (tx= kmd_transactionalloc(txid,loadheight,jint(txjson,"blocktime"),numvouts,numvins)) != 0 )
ptr = kmd_transactionadd(coin,tx,numvouts,numvins);
else printf("error init tx ptr.%p tx.%p\n",ptr,tx);
}
else
{
if ( (ptr= kmd_transaction(coin,txid)) != 0 )
tx = ptr->tx;
}
if ( ptr != 0 && tx != 0 )
{
if ( iter == 0 )
{
sobj = addresses = 0;
for (j=0; j<numvouts; j++)
{
vout = jitem(vouts,j);
if ( (sobj= jobj(vout,"scriptPubKey")) != 0 && (addresses= jarray(&n,sobj,"addresses")) != 0 )
{
bitcoin_addr2rmd160(&type_rmd160[0],&type_rmd160[1],jstri(addresses,0));
kmd_transactionvout(coin,ptr,j,jdouble(vout,"value")*SATOSHIDEN,type_rmd160,zero,-1);
//fprintf(stderr,"%.8f ",jdouble(vout,"value"));
} // else printf("missing sobj.%p or addresses.%p (%s)\n",sobj,addresses,jprint(vout,0)); //likely OP_RETURN
sobj = addresses = 0;
}
//fprintf(stderr,"numvouts.%d ht.%d %s\n",numvouts,height,coin->symbol);
if ( coin->kmd_txidfp != 0 )
{
ptr->fpos = ftell(coin->kmd_txidfp);
fwrite(tx,1,sizeof(*tx) + tx->numvouts*sizeof(*tx->vouts),coin->kmd_txidfp);
}
}
else
{
if ( coin->kmd_spendfp != 0 )
{
fwrite(&txid,1,sizeof(txid),coin->kmd_spendfp);
fwrite(&numvins,1,sizeof(numvins),coin->kmd_spendfp);
}
for (j=0; j<numvins; j++)
{
bits256 spenttxid; int32_t spentvout;
vin = jitem(vins,j);
spenttxid = jbits256(vin,"txid");
spentvout = jint(vin,"vout");
//if ( bits256_nonz(spenttxid) == 0 || spentvout < 0 )
// printf("null spenttxid ht.%d j.%d spentvout.%d\n",loadheight,j,spentvout);
if ( kmd_transactionvin(coin,txid,j,spenttxid,spentvout) < 0 )
{
printf("error i.%d of numvins.%d (%s)\n",j,numvins,jprint(vin,0));
flag++;
}
if ( coin->kmd_spendfp != 0 )
{
fwrite(&spenttxid,1,sizeof(spenttxid),coin->kmd_spendfp);
fwrite(&spentvout,1,sizeof(spentvout),coin->kmd_spendfp);
}
}
}
} else printf("incomplete at ht.%d i.%d %p %p\n",loadheight,i,ptr,tx);
free_json(txjson);
} else printf("parseerror.(%s)\n",curlstr);
free(curlstr);
}
}
num++;
kmd_flushfiles(coin);
}
free_json(blockjson);
}
if ( flag != 0 || num > 500 )
break;
coin->kmd_height = loadheight++;
}
return(num);
}
void kmd_bitcoinscan()
{
char *retstr; cJSON *array; int32_t i,n; struct iguana_info *coin; // scan allcoins also
if ( (retstr= dpow_notarychains(0,0,0,0)) != 0 )
{
if ( (array= cJSON_Parse(retstr)) != 0 )
{
if ( (n= cJSON_GetArraySize(array)) > 0 )
{
for (i=0; i<n; i++)
{
if ( (coin= iguana_coinfind(jstri(array,i))) != 0 && strcmp(coin->symbol,"BTC") != 0 )
{
//if ( strcmp("KMD",coin->symbol) == 0 )
_kmd_bitcoinscan(coin);
usleep(250000);
}
}
}
free_json(array);
}
free(retstr);
}
}
#endif

1
iguana/m_mm

@ -0,0 +1 @@
gcc -o marketmaker -I../crypto777 exchanges/mm.c ../crypto777/cJSON.c ../agents/libcrypto777.a -lcurl -lpthread -lm

4
iguana/m_osx

@ -3,6 +3,6 @@
rm ../agents/iguana *.o
git pull
cd secp256k1; ./m_unix; cd ..
gcc -g -Wno-deprecated -c -O2 -DLIQUIDITY_PROVIDER=1 *.c ../basilisk/basilisk.c ../gecko/gecko.c ../datachain/datachain.c
gcc -g -Wno-address-of-packed-member -Wno-deprecated -c -O2 -DLIQUIDITY_PROVIDER=1 *.c ../basilisk/basilisk.c ../gecko/gecko.c ../datachain/datachain.c
gcc -g -Wno-deprecated -c -DLIQUIDITY_PROVIDER=1 main.c iguana777.c iguana_bundles.c ../basilisk/basilisk.c
gcc -g -o ../agents/iguana *.o ../agents/libcrypto777.a -lcurl -lssl -lcrypto -lpthread -lz -lm
gcc -g -o ../agents/iguana *.o ../agents/libcrypto777.a -lnanomsg -lcurl -lssl -lcrypto -lpthread -lz -lm

2
iguana/m_unix

@ -9,4 +9,4 @@ cd secp256k1; ./m_unix; cd ..
cd ../crypto777; ./m_unix; cd ../iguana
gcc -g -fno-aggressive-loop-optimizations -Wno-deprecated -c *.c ../basilisk/basilisk.c ../gecko/gecko.c ../datachain/datachain.c
gcc -g -fno-aggressive-loop-optimizations -Wno-deprecated -c main.c iguana777.c iguana_bundles.c ../basilisk/basilisk.c
gcc -g -o ../agents/iguana *.o ../agents/libcrypto777.a -lpthread -lm
gcc -g -o ../agents/iguana *.o ../agents/libcrypto777.a -lpthread -lm -lnanomsg

522
iguana/main.c

@ -24,6 +24,7 @@
#include "../pnacl_main.h"
#include "iguana777.h"
struct iguana_jsonitem { struct queueitem DL; struct supernet_info *myinfo; uint32_t fallback,expired,allocsize; char *retjsonstr; char remoteaddr[64]; uint16_t port; char jsonstr[]; };
uint16_t SuperNET_API2num(char *agent,char *method)
@ -274,7 +275,7 @@ char *SuperNET_processJSON(struct supernet_info *myinfo,struct iguana_info *coin
//char str[65]; printf("processJSON %p %s\n",&myinfo->privkey,bits256_str(str,myinfo->privkey));
if ( json != 0 )
{
if ( (tag= j64bits(json,"tag")) == 0 )
if ( jobj(json,"tag") == 0 || (tag= j64bits(json,"tag")) == 0 )
{
OS_randombytes((uint8_t *)&tag,sizeof(tag));
jadd64bits(json,"tag",tag);
@ -304,7 +305,7 @@ char *SuperNET_processJSON(struct supernet_info *myinfo,struct iguana_info *coin
{
if ( is_cJSON_Array(retjson) == 0 )
{
if ( j64bits(retjson,"tag") != tag )
if ( jobj(retjson,"tag") == 0 || j64bits(retjson,"tag") != tag )
{
if ( jobj(retjson,"tag") != 0 )
jdelete(retjson,"tag");
@ -346,7 +347,7 @@ char *SuperNET_JSON(struct supernet_info *myinfo,struct iguana_info *coin,cJSON
timestamp = (uint32_t)time(NULL);
jaddnum(json,"timestamp",timestamp);
}
if ( (tag= j64bits(json,"tag")) == 0 )
if ( jobj(json,"tag") == 0 || (tag= j64bits(json,"tag")) == 0 )
{
OS_randombytes((uint8_t *)&tag,sizeof(tag));
jadd64bits(json,"tag",tag);
@ -461,6 +462,19 @@ rm BTC.xz; mksquashfs DB/BTC BTC.xz -comp xz -b 1048576 -comp xz -Xdict-size 102
https://github.com/vasi/squashfuse
*/
void DEX_explorerloop(void *ptr)
{
struct supernet_info *myinfo = ptr;
while ( 1 )
{
if ( myinfo->DEXEXPLORER != 0 )
{
kmd_bitcoinscan();
}
usleep(100000);
}
}
void mainloop(struct supernet_info *myinfo)
{
struct iguana_info *coin; int32_t counter=0,depth; double lastmilli = 0;
@ -543,7 +557,7 @@ void iguana_appletests(struct supernet_info *myinfo)
{
char *str;
//iguana_chaingenesis(1,1403138561,0x1e0fffff,8359109,bits256_conv("fd1751cc6963d88feca94c0d01da8883852647a37a0a67ce254d62dd8c9d5b2b")); // BTCD
if ( 0 )
if ( (0) )
{
char genesisblock[1024];
//iguana_chaingenesis("VPN",0,bits256_conv("00000ac7d764e7119da60d3c832b1d4458da9bc9ef9d5dd0d91a15f690a46d99"),genesisblock,"scrypt",1,1409839200,0x1e0fffff,64881664,bits256_conv("698a93a1cacd495a7a4fb3864ad8d06ed4421dedbc57f9aaad733ea53b1b5828")); // VPN
@ -571,13 +585,13 @@ void iguana_appletests(struct supernet_info *myinfo)
bitcoin_sharedsecret(myinfo->ctx,hash2,pubkey,33);
printf("secp256k1 elapsed %.3f for %d iterations\n",OS_milliseconds() - startmillis,i);
getchar();**/
if ( 0 && (str= SuperNET_JSON(myinfo,iguana_coinfind("BTCD"),cJSON_Parse("{\"protover\":70002,\"RELAY\":1,\"VALIDATE\":1,\"portp2p\":14631,\"rpc\":14632,\"agent\":\"iguana\",\"method\":\"addcoin\",\"startpend\":512,\"endpend\":512,\"services\":129,\"maxpeers\":8,\"newcoin\":\"BTCD\",\"active\":1,\"numhelpers\":1,\"poll\":100}"),0,myinfo->rpcport)) != 0 )
if ( (0) && (str= SuperNET_JSON(myinfo,iguana_coinfind("BTCD"),cJSON_Parse("{\"protover\":70002,\"RELAY\":1,\"VALIDATE\":1,\"portp2p\":14631,\"rpc\":14632,\"agent\":\"iguana\",\"method\":\"addcoin\",\"startpend\":512,\"endpend\":512,\"services\":129,\"maxpeers\":8,\"newcoin\":\"BTCD\",\"active\":1,\"numhelpers\":1,\"poll\":100}"),0,myinfo->rpcport)) != 0 )
{
free(str);
if ( 1 && (str= SuperNET_JSON(myinfo,iguana_coinfind("BTC"),cJSON_Parse("{\"portp2p\":8333,\"RELAY\":0,\"VALIDATE\":0,\"agent\":\"iguana\",\"method\":\"addcoin\",\"startpend\":1,\"endpend\":1,\"services\":128,\"maxpeers\":8,\"newcoin\":\"BTC\",\"active\":0,\"numhelpers\":1,\"poll\":100}"),0,myinfo->rpcport)) != 0 )
{
free(str);
if ( 0 && (str= SuperNET_JSON(myinfo,iguana_coinfind("BTCD"),cJSON_Parse("{\"agent\":\"SuperNET\",\"method\":\"login\",\"handle\":\"alice\",\"password\":\"alice\",\"passphrase\":\"alice\"}"),0,myinfo->rpcport)) != 0 )
if ( (0) && (str= SuperNET_JSON(myinfo,iguana_coinfind("BTCD"),cJSON_Parse("{\"agent\":\"SuperNET\",\"method\":\"login\",\"handle\":\"alice\",\"password\":\"alice\",\"passphrase\":\"alice\"}"),0,myinfo->rpcport)) != 0 )
{
free(str);
if ( (str= SuperNET_JSON(myinfo,iguana_coinfind("BTCD"),cJSON_Parse("{\"agent\":\"SuperNET\",\"method\":\"login\",\"handle\":\"bob\",\"password\":\"bob\",\"passphrase\":\"bob\"}"),0,myinfo->rpcport)) != 0 )
@ -641,7 +655,7 @@ int32_t iguana_commandline(struct supernet_info *myinfo,char *arg)
free(str);
}
free_json(argjson);
if ( 0 )
if ( (0) )
{
uint32_t buf[81],c;
OS_randombytes((void *)buf,sizeof(buf));
@ -670,6 +684,8 @@ void iguana_ensuredirs()
sprintf(dirname,"%s",GLOBAL_GENESISDIR), OS_ensure_directory(dirname);
sprintf(dirname,"%s",GLOBAL_CONFSDIR), OS_ensure_directory(dirname);
sprintf(dirname,"%s",GLOBAL_DBDIR), OS_ensure_directory(dirname);
sprintf(dirname,"%s/SWAPS",GLOBAL_DBDIR), OS_ensure_directory(dirname);
sprintf(dirname,"%s/TRANSACTIONS",GLOBAL_DBDIR), OS_ensure_directory(dirname);
sprintf(dirname,"%s/purgeable",GLOBAL_DBDIR), OS_ensure_directory(dirname);
sprintf(dirname,"%s",GLOBAL_TMPDIR), OS_ensure_directory(dirname);
sprintf(dirname,"%s",GLOBAL_VALIDATEDIR), OS_ensure_directory(dirname);
@ -731,6 +747,29 @@ void iguana_urlinit(struct supernet_info *myinfo,int32_t ismainnet,int32_t usess
else strcat(myinfo->NXTAPIURL,"6876/nxt");
}
void jumblr_loop(void *ptr)
{
struct iguana_info *coin; char BTCaddr[64],KMDaddr[64]; bits256 privkey; uint32_t t; struct supernet_info *myinfo = ptr; int32_t mult = 10;
printf("JUMBLR loop\n");
while ( 1 )
{
if ( (coin= iguana_coinfind("KMD")) != 0 && coin->FULLNODE < 0 )
{
privkey = jumblr_privkey(myinfo,BTCaddr,KMDaddr,JUMBLR_DEPOSITPREFIX);
// if BTC has arrived in deposit address, invoke DEX -> KMD
// if BTC has arrived in destination address, invoke DEX -> BTC
jumblr_DEXcheck(myinfo,coin,BTCaddr,KMDaddr,privkey);
t = (uint32_t)time(NULL);
if ( myinfo->jumblr_passphrase[0] != 0 && (t % (120 * mult)) < 60 )
{
jumblr_iteration(myinfo,coin,(t % (360 * mult)) / (120 * mult),t % (120 * mult));
}
//printf("t.%u %p.%d %s\n",t,coin,coin!=0?coin->FULLNODE:0,myinfo->jumblr_passphrase);
}
sleep(55);
}
}
void iguana_launchdaemons(struct supernet_info *myinfo)
{
int32_t i; char *helperargs,helperstr[512];
@ -746,6 +785,9 @@ void iguana_launchdaemons(struct supernet_info *myinfo)
if ( COMMANDLINE_ARGFILE == 0 )
iguana_launch(0,"rpcloop",iguana_rpcloop,myinfo,IGUANA_PERMTHREAD); // limit to oneprocess
printf("launch mainloop\n");
OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)DEX_explorerloop,(void *)myinfo);
OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)jumblr_loop,(void *)myinfo);
OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)dpow_psockloop,(void *)myinfo);
mainloop(myinfo);
}
@ -984,6 +1026,435 @@ void SuperNET_parsepeers(struct supernet_info *myinfo,cJSON *array,int32_t n,int
#include "../includes/iguana_apidefs.h"
#include "../includes/iguana_apideclares.h"
#include "../includes/iguana_apideclares2.h"
STRING_ARG(iguana,initfastfind,activecoin)
{
if ( (coin= iguana_coinfind(activecoin)) != 0 )
{
iguana_fastfindcreate(coin);
return(clonestr("{\"result\":\"fast find initialized\"}"));
} else return(clonestr("{\"error\":\"no coin to initialize\"}"));
}
TWO_STRINGS_AND_TWO_DOUBLES(iguana,balance,activecoin,address,lastheightd,minconfd)
{
int32_t lastheight,minconf,maxconf=1<<30; cJSON *array,*retjson = cJSON_CreateObject();
if ( activecoin != 0 && activecoin[0] != 0 )
coin = iguana_coinfind(activecoin);
if ( coin != 0 )
{
if ( (minconf= minconfd) <= 0 )
minconf = 1;
lastheight = lastheightd;
jaddstr(retjson,"address",address);
if ( bitcoin_validaddress(coin,address) < 0 )
{
jaddstr(retjson,"error","illegal address");
return(jprint(retjson,1));
}
jadd64bits(retjson,"RTbalance",iguana_RTbalance(coin,address));
array = cJSON_CreateArray();
jaddistr(array,address);
jadd(retjson,"unspents",iguana_RTlistunspent(myinfo,coin,array,minconf,maxconf,remoteaddr,1));
free_json(array);
if ( lastheight > 0 )
jaddnum(retjson,"RTheight",coin->RTheight);
}
return(jprint(retjson,1));
}
STRING_ARG(iguana,validate,activecoin)
{
int32_t i,total,validated; struct iguana_bundle *bp; cJSON *retjson;
if ( (coin= iguana_coinfind(activecoin)) != 0 )
{
for (i=total=validated=0; i<coin->bundlescount; i++)
if ( (bp= coin->bundles[i]) != 0 )
{
validated += iguana_bundlevalidate(myinfo,coin,bp,1);
total += bp->n;
}
retjson = cJSON_CreateObject();
jaddstr(retjson,"result","validation run");
jaddstr(retjson,"coin",coin->symbol);
jaddnum(retjson,"validated",validated);
jaddnum(retjson,"total",total);
jaddnum(retjson,"bundles",coin->bundlescount);
jaddnum(retjson,"accuracy",(double)validated/total);
return(jprint(retjson,1));
} else return(clonestr("{\"error\":\"no active coin\"}"));
}
STRING_ARG(iguana,removecoin,activecoin)
{
struct iguana_bundle *bp; int32_t i,height; char fname[1024];
if ( (coin= iguana_coinfind(activecoin)) != 0 )
{
coin->active = 0;
coin->started = 0;
if ( (0) )
{
for (i=0; i<IGUANA_MAXPEERS; i++)
{
sprintf(fname,"%s/%s/vouts/%04d.vouts",GLOBAL_DBDIR,coin->symbol,i), OS_removefile(fname,0);
sprintf(fname,"%s/%s/%04d.vins",coin->VALIDATEDIR,coin->symbol,i), OS_removefile(fname,0);
}
sprintf(fname,"%s/%s/vouts/*",GLOBAL_DBDIR,coin->symbol), OS_removefile(fname,0);
sprintf(fname,"%s/%s/*",coin->VALIDATEDIR,coin->symbol), OS_removefile(fname,0);
for (i=0; i<coin->bundlescount; i++)
{
sprintf(fname,"%s/%s/balancecrc.%d",GLOBAL_DBDIR,coin->symbol,i), OS_removefile(fname,0);
if ( (bp= coin->bundles[i]) != 0 )
{
iguana_bundlepurgefiles(coin,bp);
iguana_bundleremove(coin,bp->hdrsi,1);
}
}
for (height=0; height<coin->longestchain; height+=IGUANA_SUBDIRDIVISOR)
{
sprintf(fname,"%s/%s/%d",GLOBAL_DBDIR,coin->symbol,height/IGUANA_SUBDIRDIVISOR);
OS_remove_directory(fname);
}
sprintf(fname,"%s/%s/*",GLOBAL_DBDIR,coin->symbol), OS_remove_directory(fname);
}
return(clonestr("{\"result\":\"success\"}"));
}
return(clonestr("{\"error\":\"no active coin\"}"));
}
INT_ARG(bitcoinrpc,getblockhash,height)
{
cJSON *retjson;
if ( coin->notarychain >= 0 && coin->FULLNODE == 0 )
return(_dex_getblockhash(myinfo,coin->symbol,height));
retjson = cJSON_CreateObject();
jaddbits256(retjson,"result",iguana_blockhash(coin,height));
return(jprint(retjson,1));
}
HASH_AND_TWOINTS(bitcoinrpc,getblock,blockhash,verbose,remoteonly)
{
char *blockstr,*datastr; struct iguana_msgblock msg; struct iguana_block *block; cJSON *retjson; bits256 txid; int32_t len;
if ( coin->notarychain >= 0 && coin->FULLNODE == 0 )
return(_dex_getblock(myinfo,coin->symbol,blockhash));
retjson = cJSON_CreateObject();
memset(&msg,0,sizeof(msg));
if ( remoteonly == 0 && (block= iguana_blockfind("getblockRPC",coin,blockhash)) != 0 )
{
if ( verbose != 0 )
return(jprint(iguana_blockjson(myinfo,coin,block,1),1));
else
{
if ( (len= iguana_peerblockrequest(myinfo,coin,coin->blockspace,coin->blockspacesize,0,blockhash,0)) > 0 )
{
datastr = malloc(len*2 + 1);
init_hexbytes_noT(datastr,coin->blockspace,len);
jaddstr(retjson,"result",datastr);
free(datastr);
return(jprint(retjson,1));
}
jaddstr(retjson,"error","error getting rawblock");
}
}
else if ( coin->APIblockstr != 0 )
jaddstr(retjson,"error","already have pending request");
else
{
memset(txid.bytes,0,sizeof(txid));
if ( (blockstr= iguana_APIrequest(coin,blockhash,txid,5)) != 0 )
{
jaddstr(retjson,"result",blockstr);
free(blockstr);
} else jaddstr(retjson,"error","cant find blockhash");
}
return(jprint(retjson,1));
}
ZERO_ARGS(bitcoinrpc,getbestblockhash)
{
cJSON *retjson;
if ( coin->notarychain >= 0 && coin->FULLNODE == 0 )
return(_dex_getbestblockhash(myinfo,coin->symbol));
retjson = cJSON_CreateObject();
char str[65]; jaddstr(retjson,"result",bits256_str(str,coin->blocks.hwmchain.RO.hash2));
return(jprint(retjson,1));
}
ZERO_ARGS(bitcoinrpc,getblockcount)
{
cJSON *retjson = cJSON_CreateObject();
//printf("result %d\n",coin->blocks.hwmchain.height);
jaddnum(retjson,"result",coin->blocks.hwmchain.height);
return(jprint(retjson,1));
}
STRING_AND_INT(iguana,bundleaddresses,activecoin,height)
{
struct iguana_info *ptr;
if ( (ptr= iguana_coinfind(activecoin)) != 0 )
return(iguana_bundleaddrs(ptr,height / coin->chain->bundlesize));
else return(clonestr("{\"error\":\"activecoin is not active\"}"));
}
STRING_AND_INT(iguana,PoSweights,activecoin,height)
{
struct iguana_info *ptr; int32_t num,nonz,errs,bundleheight; struct iguana_pkhash *refP; uint64_t *weights,supply; cJSON *retjson;
if ( (ptr= iguana_coinfind(activecoin)) != 0 )
{
//for (bundleheight=coin->chain->bundlesize; bundleheight<height; bundleheight+=coin->chain->bundlesize)
{
bundleheight = (height / ptr->chain->bundlesize) * ptr->chain->bundlesize;
if ( (weights= iguana_PoS_weights(myinfo,ptr,&refP,&supply,&num,&nonz,&errs,bundleheight)) != 0 )
{
retjson = cJSON_CreateObject();
jaddstr(retjson,"result",errs == 0 ? "success" : "error");
jaddnum(retjson,"bundleheight",bundleheight);
jaddnum(retjson,"numaddresses",num);
jaddnum(retjson,"nonzero",nonz);
jaddnum(retjson,"errors",errs);
jaddnum(retjson,"supply",dstr(supply));
free(weights);
return(jprint(retjson,1));
} else return(clonestr("{\"error\":\"iguana_PoS_weights returned null\"}"));
}
}
return(clonestr("{\"error\":\"activecoin is not active\"}"));
}
STRING_ARG(iguana,stakers,activecoin)
{
struct iguana_info *ptr; int32_t i,datalen,pkind,hdrsi; bits256 hash2; struct iguana_bundle *bp; cJSON *retjson,*array; struct iguana_pkhash *refP; struct iguana_ramchaindata *rdata; char coinaddr[64]; uint8_t refrmd160[20]; bits256 *sortbuf;
if ( (ptr= iguana_coinfind(activecoin)) != 0 && ptr->RTheight > ptr->chain->bundlesize )
{
hdrsi = (ptr->RTheight / ptr->chain->bundlesize) - 1;
if ( (bp= ptr->bundles[hdrsi]) != 0 && bp->weights != 0 && (rdata= bp->ramchain.H.data) != 0 && bp->weights != 0 )
{
sortbuf = calloc(bp->numweights,2 * sizeof(*sortbuf));
for (i=datalen=0; i<bp->numweights; i++)
datalen += iguana_rwnum(1,&((uint8_t *)sortbuf)[datalen],sizeof(bp->weights[i]),(void *)&bp->weights[i]);
hash2 = bits256_doublesha256(0,(uint8_t *)sortbuf,datalen);
refP = RAMCHAIN_PTR(rdata,Poffset);
retjson = cJSON_CreateObject();
array = cJSON_CreateArray();
memset(refrmd160,0,sizeof(refrmd160));
for (i=0; i<ptr->chain->bundlesize; i++)
{
if ( (pkind= iguana_staker_sort(ptr,&hash2,refrmd160,refP,bp->weights,bp->numweights,sortbuf)) > 0 )
{
bitcoin_address(coinaddr,ptr->chain->pubtype,refP[pkind].rmd160,sizeof(refP[pkind].rmd160));
jaddistr(array,coinaddr);
} else jaddistr(array,"error");
}
jaddstr(retjson,"result","success");
jadd(retjson,"stakers",array);
return(jprint(retjson,1));
} else return(clonestr("{\"error\":\"iguana_stakers needs PoSweights and weights\"}"));
}
return(clonestr("{\"error\":\"activecoin is not active\"}"));
}
STRING_AND_INT(iguana,bundlehashes,activecoin,height)
{
struct iguana_info *ptr; struct iguana_bundle *bp; int32_t i,hdrsi; cJSON *retjson,*array; struct iguana_ramchaindata *rdata;
if ( (ptr= iguana_coinfind(activecoin)) != 0 )
{
hdrsi = height / coin->chain->bundlesize;
if ( hdrsi < coin->bundlescount && hdrsi >= 0 && (bp= coin->bundles[hdrsi]) != 0 )
{
if ( (rdata= bp->ramchain.H.data) != 0 )
{
array = cJSON_CreateArray();
for (i=0; i<IGUANA_NUMLHASHES; i++)
jaddinum(array,rdata->lhashes[i].txid);
retjson = cJSON_CreateObject();
jaddstr(retjson,"result","success");
jaddbits256(retjson,"sha256",rdata->sha256);
jadd(retjson,"bundlehashes",array);
return(jprint(retjson,1));
} else return(clonestr("{\"error\":\"ramchain not there\"}"));
} else return(clonestr("{\"error\":\"height is too big\"}"));
} else return(clonestr("{\"error\":\"activecoin is not active\"}"));
}
// low priority RPC
HASH_AND_TWOINTS(bitcoinrpc,listsinceblock,blockhash,target,flag)
{
/*"transactions" : [
{
"account" : "doc test",
"address" : "mmXgiR6KAhZCyQ8ndr2BCfEq1wNG2UnyG6",
"category" : "receive",
"amount" : 0.10000000,
"vout" : 0,
"confirmations" : 76478,
"blockhash" : "000000000017c84015f254498c62a7c884a51ccd75d4dd6dbdcb6434aa3bd44d",
"blockindex" : 1,
"blocktime" : 1399294967,
"txid" : "85a98fdf1529f7d5156483ad020a51b7f3340e47448cf932f470b72ff01a6821",
"walletconflicts" : [
],
"time" : 1399294967,
"timereceived" : 1418924714
},*/
cJSON *retjson = cJSON_CreateObject();
jaddstr(retjson,"error","low priority RPC not implemented");
return(jprint(retjson,1));
}
ZERO_ARGS(bitcoinrpc,gettxoutsetinfo)
{
cJSON *retjson = cJSON_CreateObject();
jaddstr(retjson,"error","low priority RPC not implemented");
return(jprint(retjson,1));
}
ZERO_ARGS(bitcoinrpc,listaddressgroupings)
{
if ( remoteaddr != 0 )
return(clonestr("{\"error\":\"no remote\"}"));
return(clonestr("{\"error\":\"low priority RPC not implemented\"}"));
}
SS_D_I_S(bitcoinrpc,move,fromaccount,toaccount,amount,minconf,comment)
{
cJSON *retjson;
if ( remoteaddr != 0 )
return(clonestr("{\"error\":\"no remote\"}"));
if ( myinfo->expiration == 0 )
return(clonestr("{\"error\":\"need to unlock wallet\"}"));
retjson = cJSON_CreateObject();
return(jprint(retjson,1));
}
ZERO_ARGS(pax,start)
{
void PAX_init();
PAX_init();
return(clonestr("{\"result\":\"PAX_init called\"}"));
}
STRING_AND_TWOINTS(mouse,change,name,x,y)
{
printf("mouse (%s) x.%d y.%d\n",name,x,y);
return(clonestr("{\"result\":\"changed\"}"));
}
STRING_ARG(mouse,leave,name)
{
printf("mouse (%s) leave\n",name);
return(clonestr("{\"result\":\"left\"}"));
}
STRING_AND_TWOINTS(mouse,click,name,x,y)
{
printf("mouse (%s) x.%d y.%d click\n",name,x,y);
return(clonestr("{\"result\":\"click\"}"));
}
STRING_AND_INT(keyboard,key,name,c)
{
printf(" KEY.(%s) c.%d (%c)\n",name,c,c);
return(clonestr("{\"result\":\"key\"}"));
}
STRING_AND_TWOINTS(mouse,image,name,x,y)
{
printf("mouse CREATE (%s) x.%d y.%d\n",name,x,y);
return(clonestr("{\"result\":\"opened\"}"));
}
STRING_ARG(mouse,close,name)
{
printf("mouse CLOSE (%s)\n",name);
return(clonestr("{\"result\":\"closed\"}"));
}
HASH_ARRAY_STRING(basilisk,geckotx,hash,vals,hexstr)
{
struct iguana_info *btcd; char *retstr=0,*symbol; uint8_t *data,*allocptr,space[4096]; int32_t datalen; bits256 txid;
if ( (btcd= iguana_coinfind("BTCD")) != 0 && (symbol= jstr(vals,"symbol")) != 0 )
{
if ( (data= get_dataptr(BASILISK_HDROFFSET,&allocptr,&datalen,space,sizeof(space),hexstr)) != 0 )
{
txid = bits256_doublesha256(0,data,datalen);
retstr = gecko_sendrawtransaction(myinfo,symbol,data,datalen,txid,vals,hexstr);
} else retstr = clonestr("{\"error\":\"no tx submitted\"}");
if ( allocptr != 0 )
free(allocptr);
if ( retstr == 0 )
retstr = clonestr("{\"error\":\"couldnt create geckotx\"}");
return(retstr);
} return(clonestr("{\"error\":\"need symbol and chain and BTCD to create new gecko tx\"}"));
}
HASH_ARRAY_STRING(basilisk,geckoblock,hash,vals,hexstr)
{
return(clonestr("{\"error\":\"geckoblock is an internal reporting function\"}"));
}
HASH_ARRAY_STRING(basilisk,geckoheaders,hash,vals,hexstr)
{
return(clonestr("{\"error\":\"geckoheaders is an internal reporting function\"}"));
}
HASH_ARRAY_STRING(basilisk,geckoget,hash,vals,hexstr)
{
struct iguana_info *btcd,*virt; char *symbol;
if ( (btcd= iguana_coinfind("BTCD")) != 0 && (symbol= jstr(vals,"symbol")) != 0 )
{
if ( (virt= iguana_coinfind(symbol)) != 0 )
{
basilisk_wait(myinfo,virt);
return(basilisk_respond_geckoget(myinfo,"GET",&coin->internaladdr,remoteaddr,0,vals,0,0,hash,0));
} else return(clonestr("{\"error\":\"geckoget needs virtualchain\"}"));
}
return(clonestr("{\"error\":\"geckoget needs BTCD\"}"));
}
TWO_STRINGS(SuperNET,decryptjson,password,permanentfile)
{
char pass[8192],fname2[1023],destfname[1024]; cJSON *retjson; bits256 wallethash,wallet2priv;
safecopy(pass,password,sizeof(pass));
safecopy(fname2,permanentfile,sizeof(fname2));
wallethash = wallet2priv = GENESIS_PRIVKEY;
if ( strlen(pass) == sizeof(wallethash)*2 && is_hexstr(pass,(int32_t)sizeof(bits256)*2) > 0 )
wallethash = bits256_conv(pass);
if ( strlen(fname2) == sizeof(wallet2priv)*2 && is_hexstr(fname2,(int32_t)sizeof(bits256)*2) > 0 )
wallet2priv = bits256_conv(fname2);
if ( (retjson= SuperNET_decryptedjson(destfname,pass,sizeof(pass),wallethash,fname2,sizeof(fname2),wallet2priv)) != 0 )
{
//printf("decrypt pass.(%s) fname2.(%s) -> destfname.(%s)\n",pass,fname2,destfname);
//obj = jduplicate(jobj(retjson,"payload"));
//jdelete(retjson,"payload");
//jadd(retjson,"result",obj);
return(jprint(retjson,1));
} else return(clonestr("{\"error\":\"couldnt decrypt json file\"}"));
}
THREE_STRINGS(SuperNET,encryptjson,password,permanentfile,payload)
{
char destfname[4096],pass[8192],fname2[1023]; cJSON *argjson,*retjson = cJSON_CreateObject();
safecopy(pass,password,sizeof(pass));
safecopy(fname2,permanentfile,sizeof(fname2));
argjson = jduplicate(json);
//printf("argjson.(%s)\n",jprint(argjson,0));
jdelete(argjson,"agent");
jdelete(argjson,"method");
jdelete(argjson,"password");
jdelete(argjson,"permanentfile");
jdelete(argjson,"timestamp");
jdelete(argjson,"tag");
if ( _SuperNET_encryptjson(myinfo,destfname,pass,sizeof(pass),fname2,sizeof(fname2),argjson) == 0 )
{
jaddstr(retjson,"result","success");
jaddstr(retjson,"filename",destfname);
} else jaddstr(retjson,"error","couldnt encrypt json file");
free_json(argjson);
return(jprint(retjson,1));
}
STRING_ARG(SuperNET,addr2rmd160,address)
{
@ -1420,7 +1891,7 @@ ZERO_ARGS(SuperNET,logout)
ZERO_ARGS(SuperNET,activehandle)
{
cJSON *retjson;
cJSON *retjson; char BTCaddr[64],KMDaddr[64];
if ( remoteaddr != 0 )
return(clonestr("{\"error\":\"no remote\"}"));
retjson = SuperNET_rosettajson(myinfo,myinfo->persistent_priv,0);
@ -1436,6 +1907,15 @@ ZERO_ARGS(SuperNET,activehandle)
jaddstr(retjson,"status","unlocked");
jaddnum(retjson,"duration",myinfo->expiration - time(NULL));
} else jaddstr(retjson,"status","locked");
if ( myinfo->jumblr_passphrase[0] != 0 )
{
jumblr_privkey(myinfo,BTCaddr,KMDaddr,JUMBLR_DEPOSITPREFIX);
jaddstr(retjson,"BTCdeposit","notyet");
jaddstr(retjson,"KMDdeposit",KMDaddr);
jumblr_privkey(myinfo,BTCaddr,KMDaddr,"");
jaddstr(retjson,"BTCjumblr","notyet");
jaddstr(retjson,"KMDjumblr",KMDaddr);
}
SuperNET_MYINFOadd(myinfo);
return(jprint(retjson,1));
}
@ -1563,7 +2043,7 @@ FOUR_STRINGS(SuperNET,login,handle,password,permanentfile,passphrase)
free(str);
myinfo->expiration = (uint32_t)(time(NULL) + 3600);
return(SuperNET_activehandle(IGUANA_CALLARGS));
} else return(clonestr("{\"error\":\"need passphrase\"}"));
} else return(clonestr("{\"error\":\"need passphrase or wallet doesnt exist\"}"));
return(SuperNET_activehandle(IGUANA_CALLARGS));
}
@ -1575,7 +2055,7 @@ void komodo_ICO_batch(cJSON *array,int32_t batchid)
if ( (n= cJSON_GetArraySize(array)) > 0 )
{
totalKMD = totalREVS = 0;
for (iter=2; iter<3; iter++)
for (iter=0; iter<1; iter++)
for (i=0; i<n; i++)
{
item = jitem(array,i);
@ -1611,9 +2091,11 @@ void komodo_ICO_batch(cJSON *array,int32_t batchid)
printf("# %s KMD %.8f\n",coinaddr,dstr(kmdamount));
if ( (iter & 1) == 0 )
{
printf("curl --url \"http://127.0.0.1:7778\" --data \"{\\\"agent\\\":\\\"dex\\\",\\\"method\\\":\\\"importaddress\\\",\\\"address\\\":\\\"%s\\\",\\\"symbol\\\":\\\"KMD\\\"}\" # %.8f\n",coinaddr,dstr(kmdamount));
printf("sleep 3\n");
//printf("curl --url \"http://127.0.0.1:7778\" --data \"{\\\"agent\\\":\\\"dex\\\",\\\"method\\\":\\\"listunspent\\\",\\\"address\\\":\\\"%s\\\",\\\"symbol\\\":\\\"KMD\\\"}\"\n",coinaddr);
if ( (0) )
{
printf("curl --url \"http://127.0.0.1:7778\" --data \"{\\\"agent\\\":\\\"dex\\\",\\\"method\\\":\\\"importaddress\\\",\\\"address\\\":\\\"%s\\\",\\\"symbol\\\":\\\"KMD\\\"}\" # %.8f\n",coinaddr,dstr(kmdamount));
printf("sleep 3\n");
} else printf("curl --url \"http://127.0.0.1:7778\" --data \"{\\\"agent\\\":\\\"dex\\\",\\\"method\\\":\\\"listunspent\\\",\\\"address\\\":\\\"%s\\\",\\\"symbol\\\":\\\"KMD\\\"}\"\n",coinaddr);
}
else
{
@ -1673,9 +2155,9 @@ void iguana_main(void *arg)
else printf("ENDIAN ERROR\n");
mycalloc(0,0,0);
#ifdef __APPLE__
char *batchstr,*batchstr2; cJSON *batchjson; long batchsize; char fname[512],fname2[512]; int32_t batchid = 5;
char *batchstr,*batchstr2; cJSON *batchjson; long batchsize; char fname[512],fname2[512]; int32_t batchid = 14;
sprintf(fname,"REVS.raw"), sprintf(fname2,"REVS.rawtxids");
if ( 0 && (batchstr= OS_filestr(&batchsize,fname)) != 0 && (batchstr2= OS_filestr(&batchsize,fname2)) != 0 )
if ( (0) && (batchstr= OS_filestr(&batchsize,fname)) != 0 && (batchstr2= OS_filestr(&batchsize,fname2)) != 0 )
{
komodo_REVS_merge(batchstr,batchstr2);
}
@ -1699,6 +2181,7 @@ void iguana_main(void *arg)
myinfo->rpcport = IGUANA_RPCPORT;
myinfo->dpowsock = myinfo->dexsock = myinfo->pubsock = myinfo->subsock = myinfo->reqsock = myinfo->repsock = -1;
dex_init(myinfo);
myinfo->psockport = 30000;
if ( arg != 0 )
{
if ( strcmp((char *)arg,"OStests") == 0 )
@ -1707,6 +2190,7 @@ void iguana_main(void *arg)
{
myinfo->rpcport = IGUANA_NOTARYPORT;
myinfo->IAMNOTARY = 1;
myinfo->DEXEXPLORER = 1;
}
}
#ifdef IGUANA_OSTESTS
@ -1721,8 +2205,10 @@ void iguana_main(void *arg)
}
strcpy(myinfo->rpcsymbol,"BTCD");
iguana_urlinit(myinfo,ismainnet,usessl);
portable_mutex_init(&myinfo->pending_mutex);
portable_mutex_init(&myinfo->dpowmutex);
portable_mutex_init(&myinfo->notarymutex);
portable_mutex_init(&myinfo->psockmutex);
#if LIQUIDITY_PROVIDER
myinfo->tradingexchanges[myinfo->numexchanges++] = exchange_create(clonestr("nxtae"),0);
myinfo->tradingexchanges[myinfo->numexchanges++] = exchange_create(clonestr("bitcoin"),0);
@ -1759,7 +2245,7 @@ void iguana_main(void *arg)
{
basilisks_init(myinfo);
}
if ( 0 )
if ( (0) )
{
char *jsonstr = "[\"03b7621b44118017a16043f19b30cc8a4cfe068ac4e42417bae16ba460c80f3828\", \"02ebfc784a4ba768aad88d44d1045d240d47b26e248cafaf1c5169a42d7a61d344\", \"03750cf30d739cd7632f77c1c02812dd7a7181628b0558058d4755838117e05339\", \"0394f3529d2e8cc69ffa7a2b55f3761e7be978fa1896ef4c55dc9c275e77e5bf5e\", \"0243c1eeb3777af47187d542e5f8c84f0ac4b05cf5a7ad77faa8cb6d2d56db7823\", \"02bb298844175640a34e908ffdfa2839f77aba3d5edadefee16beb107826e00063\", \"02fa88e549b4b871498f892e527a5d57287916809f8cc3163f641d71c535e8df5a\", \"032f799e370f06476793a122fcd623db7804898fe5aef5572095cfee6353df34bf\", \"02c06fe5401faff4442ef87b7d1b56c2e5a214166615f9a2f2030c71b0cb067ae8\", \"038ac67ca49a8169bcc5de83fe020071095a2c3b2bc4d1c17386977329758956d5\"]";
@ -1778,3 +2264,7 @@ void iguana_main(void *arg)
iguana_launchdaemons(myinfo);
}
// features
// komodod convert passphrase to privkey
// Z -> Z
// iguana init nanomsg in own thread

3
iguana/mini-gmp.c

@ -4394,7 +4394,7 @@ int32_t bitcoin_base58decode(uint8_t *data,char *coinaddr)
//memset(data,0,be_sz);
//for (i=0; i<count; i++)
// data[i+zeroes] = revdata[count - 1 - i];
//printf("len.%d be_sz.%d zeroes.%d data[0] %02x %02x\n",be_sz+zeroes,be_sz,zeroes,data[0],data[1]);
//printf(" count.%d len.%d be_sz.%d zeroes.%d data[0] %02x %02x\n",(int32_t)count,be_sz+zeroes,be_sz,zeroes,data[0],data[1]);
mpz_clear(bn), mpz_clear(bn58);
return(be_sz);
}
@ -4416,6 +4416,7 @@ void mpz_from_bits256(mpz_t bn,bits256 x)
bits256 mpz_to_bits256(mpz_t bn)
{
bits256 x,rev; size_t count; int32_t i;
memset(x.bytes,0,sizeof(x));
mpz_export(rev.bytes,&count,1,sizeof(uint64_t),1,0,bn);
for (i=0; i<32; i++)
x.bytes[i] = rev.bytes[31-i];

2
iguana/pangea_api.c

@ -530,7 +530,7 @@ char *pangea_hexmsg(struct supernet_info *myinfo,struct gecko_chain *cat,void *d
}
}
}
else if ( 0 )
else if ( (0) )
{
for (i=0; i<datalen; i++)
printf("%02x",serialized[i]);

2
iguana/pangea_hand.c

@ -811,7 +811,7 @@ int32_t pangea_lastman(struct supernet_info *myinfo,struct table_info *tp)
printf("DUPLICATE LASTMAN!\n");
return(1);
}
if ( 0 && tp->priv.myind == activej && tp->priv.automuck == 0 )
if ( (0) && tp->priv.myind == activej && tp->priv.automuck == 0 )
{
pangea_sendcmd(myinfo,tp,"faceup",-1,tp->priv.holecards[0].bytes,sizeof(tp->priv.holecards[0]),tp->priv.cardis[0],tp->priv.cardis[0] != 0xff);
pangea_sendcmd(myinfo,tp,"faceup",-1,tp->priv.holecards[1].bytes,sizeof(tp->priv.holecards[1]),tp->priv.cardis[1],tp->priv.cardis[1] != 0xff);

22
iguana/pangea_json.c

@ -227,6 +227,7 @@ cJSON *pangea_tablestatus(struct supernet_info *myinfo,struct table_info *tp)
jaddi64bits(array,tp->active[i]!=0?tp->active[i]->nxt64bits:0);
jadd(json,"addrs",array);*/
total = 0;
str = "error";
for (iter=0; iter<6; iter++)
{
array = cJSON_CreateArray();
@ -243,22 +244,23 @@ cJSON *pangea_tablestatus(struct supernet_info *myinfo,struct table_info *tp)
case 3: val = p->betstatus; str = "status"; break;
case 4: val = p->bets; str = "bets"; break;
case 5: val = p->won; str = "won"; break;
default: str = "error"; break;
}
}
if ( iter == 5 )
won[i] = val;
else
{
if ( iter == 3 )
jaddistr(array,pangea_statusstr((int32_t)val));
else
{
if ( iter == 4 )
total += val, bets[i] = val;
else if ( iter == 2 )
snapshot[i] = val;
jaddinum(array,val);
}
if ( iter == 3 )
jaddistr(array,pangea_statusstr((int32_t)val));
else
{
if ( iter == 4 )
total += val, bets[i] = val;
else if ( iter == 2 )
snapshot[i] = val;
jaddinum(array,val);
}
}
}
jadd(json,str,array);

563
iguana/ramchain_api.c

@ -13,316 +13,425 @@
* *
******************************************************************************/
// deprecated
#include "iguana777.h"
#include "../includes/iguana_apidefs.h"
#include "../includes/iguana_apideclares.h"
#include "../includes/iguana_apideclares2.h"
STRING_ARG(iguana,peers,activecoin)
{
if ( coin != 0 )
return(jprint(iguana_peersjson(coin,0),1));
else return(clonestr("{\"error\":\"peers needs coin\"}"));
}
STRING_ARG(iguana,initfastfind,activecoin)
STRING_ARG(iguana,getconnectioncount,activecoin)
{
if ( (coin= iguana_coinfind(activecoin)) != 0 )
int32_t i,num = 0; char buf[512];
if ( coin != 0 && coin->peers != 0 )
{
iguana_fastfindcreate(coin);
return(clonestr("{\"result\":\"fast find initialized\"}"));
} else return(clonestr("{\"error\":\"no coin to initialize\"}"));
for (i=0; i<sizeof(coin->peers->active)/sizeof(*coin->peers->active); i++)
if ( coin->peers->active[i].usock >= 0 )
num++;
sprintf(buf,"{\"result\":\"%d\"}",num);
return(clonestr(buf));
} else return(clonestr("{\"error\":\"getconnectioncount needs coin\"}"));
}
TWO_STRINGS_AND_TWO_DOUBLES(iguana,balance,activecoin,address,lastheightd,minconfd)
ZERO_ARGS(bitcoinrpc,getdifficulty)
{
int32_t lastheight,minconf,maxconf=1<<30; cJSON *array,*retjson = cJSON_CreateObject();
if ( activecoin != 0 && activecoin[0] != 0 )
coin = iguana_coinfind(activecoin);
char buf[512];
if ( coin != 0 )
{
if ( (minconf= minconfd) <= 0 )
minconf = 1;
lastheight = lastheightd;
jaddstr(retjson,"address",address);
if ( bitcoin_validaddress(coin,address) < 0 )
sprintf(buf,"{\"result\":\"success\",\"proof-of-work\":\"%.8f\",\"search-interval\": 0}",PoW_from_compact(coin->blocks.hwmchain.RO.bits,coin->chain->unitval));
return(clonestr(buf));
} else return(clonestr("{\"error\":\"getdifficulty needs coin\"}"));
}
STRING_ARG(iguana,addcoin,newcoin)
{
char *symbol,*seedip; int32_t retval;
if ( (symbol= newcoin) == 0 && coin != 0 )
symbol = coin->symbol;
if ( symbol != 0 )
{
if ( (seedip= jstr(json,"seedipaddr")) != 0 )
safecopy(myinfo->seedipaddr,seedip,sizeof(myinfo->seedipaddr));
printf(">> addcoin.%s seedipaddr.%s\n",symbol,myinfo->seedipaddr);
#ifdef __PNACL__
// if ( strcmp(symbol,"BTC") == 0 )
// return(clonestr("{\"result\":\"BTC for chrome app is not yet\"}"));
#endif
if ( (retval= iguana_launchcoin(myinfo,symbol,json,0)) > 0 )
{
jaddstr(retjson,"error","illegal address");
return(jprint(retjson,1));
if ( myinfo->rpcsymbol[0] == 0 )
safecopy(myinfo->rpcsymbol,symbol,sizeof(myinfo->rpcsymbol));
return(clonestr("{\"result\":\"coin added\"}"));
}
jadd64bits(retjson,"RTbalance",iguana_RTbalance(coin,address));
array = cJSON_CreateArray();
jaddistr(array,address);
jadd(retjson,"unspents",iguana_RTlistunspent(myinfo,coin,array,minconf,maxconf,remoteaddr,1));
free_json(array);
if ( lastheight > 0 )
jaddnum(retjson,"RTheight",coin->RTheight);
}
return(jprint(retjson,1));
else if ( retval == 0 )
return(clonestr("{\"result\":\"coin already there\"}"));
else return(clonestr("{\"error\":\"error adding coin\"}"));
} else return(clonestr("{\"error\":\"addcoin needs newcoin\"}"));
}
STRING_ARG(iguana,validate,activecoin)
STRING_ARG(iguana,startcoin,activecoin)
{
int32_t i,total,validated; struct iguana_bundle *bp; cJSON *retjson;
if ( (coin= iguana_coinfind(activecoin)) != 0 )
if ( coin != 0 )
{
for (i=total=validated=0; i<coin->bundlescount; i++)
if ( (bp= coin->bundles[i]) != 0 )
{
validated += iguana_bundlevalidate(myinfo,coin,bp,1);
total += bp->n;
}
retjson = cJSON_CreateObject();
jaddstr(retjson,"result","validation run");
jaddstr(retjson,"coin",coin->symbol);
jaddnum(retjson,"validated",validated);
jaddnum(retjson,"total",total);
jaddnum(retjson,"bundles",coin->bundlescount);
jaddnum(retjson,"accuracy",(double)validated/total);
return(jprint(retjson,1));
} else return(clonestr("{\"error\":\"no active coin\"}"));
coin->active = 1;
return(clonestr("{\"result\":\"coin started\"}"));
} else return(clonestr("{\"error\":\"startcoin needs coin\"}"));
}
STRING_ARG(iguana,stopcoin,activecoin)
{
if ( activecoin[0] != 0 )
coin = iguana_coinfind(activecoin);
if ( coin != 0 )
{
coin->active = 0;
//iguana_coinpurge(coin);
return(clonestr("{\"result\":\"coin stopped\"}"));
} else return(clonestr("{\"error\":\"stopcoin needs coin\"}"));
}
STRING_ARG(iguana,removecoin,activecoin)
STRING_ARG(iguana,pausecoin,activecoin)
{
struct iguana_bundle *bp; int32_t i,height; char fname[1024];
if ( (coin= iguana_coinfind(activecoin)) != 0 )
if ( coin != 0 )
{
coin->active = 0;
coin->started = 0;
if ( 0 )
return(clonestr("{\"result\":\"coin paused\"}"));
} else return(clonestr("{\"error\":\"pausecoin needs coin\"}"));
}
TWO_STRINGS(iguana,addnode,activecoin,ipaddr)
{
struct iguana_peer *addr; int32_t i,n;
if ( coin == 0 )
coin = iguana_coinfind(activecoin);
if ( coin != 0 && strcmp(coin->symbol,"RELAY") == 0 )
basilisk_addrelay_info(myinfo,0,(uint32_t)calc_ipbits(ipaddr),GENESIS_PUBKEY);
printf("coin.%p.[%s] addnode.%s -> %s\n",coin,coin!=0?coin->symbol:"",activecoin,ipaddr);
if ( coin != 0 && coin->peers != 0 && ipaddr != 0 && is_ipaddr(ipaddr) != 0 )
{
//iguana_possible_peer(coin,ipaddr);
if ( (addr= iguana_peerslot(coin,(uint32_t)calc_ipbits(ipaddr),1)) != 0 )
{
for (i=0; i<IGUANA_MAXPEERS; i++)
addr->supernet = 1;
if ( addr->usock >= 0 )
{
sprintf(fname,"%s/%s/vouts/%04d.vouts",GLOBAL_DBDIR,coin->symbol,i), OS_removefile(fname,0);
sprintf(fname,"%s/%s/%04d.vins",coin->VALIDATEDIR,coin->symbol,i), OS_removefile(fname,0);
}
sprintf(fname,"%s/%s/vouts/*",GLOBAL_DBDIR,coin->symbol), OS_removefile(fname,0);
sprintf(fname,"%s/%s/*",coin->VALIDATEDIR,coin->symbol), OS_removefile(fname,0);
for (i=0; i<coin->bundlescount; i++)
{
sprintf(fname,"%s/%s/balancecrc.%d",GLOBAL_DBDIR,coin->symbol,i), OS_removefile(fname,0);
if ( (bp= coin->bundles[i]) != 0 )
if ( (n= coin->peers->numranked) != 0 )
{
iguana_bundlepurgefiles(coin,bp);
iguana_bundleremove(coin,bp->hdrsi,1);
for (i=0; i<n; i++)
{
if ( addr == coin->peers->ranked[i] )
break;
}
if ( i == n )
{
if ( i == IGUANA_MAXPEERS )
i--;
else coin->peers->numranked = n+1;
coin->peers->ranked[i] = addr;
addr->recvblocks = coin->peers->ranked[0]->recvblocks + 100;
addr->recvtotal = coin->peers->ranked[0]->recvtotal*1.1 + 100;
printf("set (%s) -> slot.%d numranked.%d\n",ipaddr,i,coin->peers->numranked);
} else printf("(%s) is already peer.%d\n",ipaddr,i);
}
return(clonestr("{\"result\":\"peer was already connected\"}"));
}
for (height=0; height<coin->longestchain; height+=IGUANA_SUBDIRDIVISOR)
if ( addr->pending == 0 )
{
sprintf(fname,"%s/%s/%d",GLOBAL_DBDIR,coin->symbol,height/IGUANA_SUBDIRDIVISOR);
OS_remove_directory(fname);
}
sprintf(fname,"%s/%s/*",GLOBAL_DBDIR,coin->symbol), OS_remove_directory(fname);
}
return(clonestr("{\"result\":\"success\"}"));
addr->pending = (uint32_t)time(NULL);
iguana_launch(coin,"connection",iguana_startconnection,addr,IGUANA_CONNTHREAD);
return(clonestr("{\"result\":\"addnode submitted\"}"));
} else return(clonestr("{\"result\":\"addnode connection was already pending\"}"));
} else return(clonestr("{\"result\":\"addnode cant find peer slot\"}"));
}
return(clonestr("{\"error\":\"no active coin\"}"));
else if ( coin == 0 )
return(clonestr("{\"error\":\"addnode needs active coin, do an addcoin first\"}"));
else return(clonestr("{\"error\":\"addnode needs ipaddr\"}"));
}
INT_ARG(bitcoinrpc,getblockhash,height)
TWO_STRINGS(iguana,persistent,activecoin,ipaddr)
{
cJSON *retjson;
if ( coin->notarychain >= 0 && coin->FULLNODE == 0 )
return(_dex_getblockhash(myinfo,coin->symbol,height));
retjson = cJSON_CreateObject();
jaddbits256(retjson,"result",iguana_blockhash(coin,height));
return(jprint(retjson,1));
int32_t i;
if ( coin != 0 && coin->peers != 0 && ipaddr != 0 )
{
for (i=0; i<IGUANA_MAXPEERS; i++)
{
if ( strcmp(coin->peers->active[i].ipaddr,ipaddr) == 0 )
{
coin->peers->active[i].persistent_peer = juint(json,"interval")+3;
return(clonestr("{\"result\":\"node marked as persistent\"}"));
}
}
return(clonestr("{\"result\":\"node wasnt active\"}"));
} else return(clonestr("{\"error\":\"persistent needs coin and ipaddr\"}"));
}
HASH_AND_TWOINTS(bitcoinrpc,getblock,blockhash,verbose,remoteonly)
TWO_STRINGS(iguana,removenode,activecoin,ipaddr)
{
char *blockstr,*datastr; struct iguana_msgblock msg; struct iguana_block *block; cJSON *retjson; bits256 txid; int32_t len;
if ( coin->notarychain >= 0 && coin->FULLNODE == 0 )
return(_dex_getblock(myinfo,coin->symbol,blockhash));
retjson = cJSON_CreateObject();
memset(&msg,0,sizeof(msg));
if ( remoteonly == 0 && (block= iguana_blockfind("getblockRPC",coin,blockhash)) != 0 )
int32_t i;
if ( coin != 0 && coin->peers != 0 && ipaddr != 0 )
{
if ( verbose != 0 )
return(jprint(iguana_blockjson(myinfo,coin,block,1),1));
else
for (i=0; i<IGUANA_MAXPEERS; i++)
{
if ( (len= iguana_peerblockrequest(myinfo,coin,coin->blockspace,coin->blockspacesize,0,blockhash,0)) > 0 )
if ( strcmp(coin->peers->active[i].ipaddr,ipaddr) == 0 )
{
datastr = malloc(len*2 + 1);
init_hexbytes_noT(datastr,coin->blockspace,len);
jaddstr(retjson,"result",datastr);
free(datastr);
return(jprint(retjson,1));
coin->peers->active[i].rank = 0;
coin->peers->active[i].dead = (uint32_t)time(NULL);
return(clonestr("{\"result\":\"node marked as dead\"}"));
}
jaddstr(retjson,"error","error getting rawblock");
}
}
else if ( coin->APIblockstr != 0 )
jaddstr(retjson,"error","already have pending request");
else
{
memset(txid.bytes,0,sizeof(txid));
if ( (blockstr= iguana_APIrequest(coin,blockhash,txid,5)) != 0 )
{
jaddstr(retjson,"result",blockstr);
free(blockstr);
} else jaddstr(retjson,"error","cant find blockhash");
}
return(jprint(retjson,1));
return(clonestr("{\"result\":\"node wasnt active\"}"));
} else return(clonestr("{\"error\":\"removenode needs coin and ipaddr\"}"));
}
ZERO_ARGS(bitcoinrpc,getbestblockhash)
TWO_STRINGS(iguana,oneshot,activecoin,ipaddr)
{
cJSON *retjson;
if ( coin->notarychain >= 0 && coin->FULLNODE == 0 )
return(_dex_getbestblockhash(myinfo,coin->symbol));
retjson = cJSON_CreateObject();
char str[65]; jaddstr(retjson,"result",bits256_str(str,coin->blocks.hwmchain.RO.hash2));
return(jprint(retjson,1));
if ( coin != 0 && ipaddr != 0 )
{
iguana_possible_peer(coin,ipaddr);
return(clonestr("{\"result\":\"addnode submitted\"}"));
} else return(clonestr("{\"error\":\"addnode needs coin and ipaddr\"}"));
}
ZERO_ARGS(bitcoinrpc,getblockcount)
cJSON *iguana_peerjson(struct iguana_info *coin,struct iguana_peer *addr)
{
cJSON *retjson = cJSON_CreateObject();
//printf("result %d\n",coin->blocks.hwmchain.height);
jaddnum(retjson,"result",coin->blocks.hwmchain.height);
return(jprint(retjson,1));
cJSON *array,*json = cJSON_CreateObject();
jaddstr(json,"ipaddr",addr->ipaddr);
if ( addr->supernet != 0 )
jaddstr(json,"ipaddr",addr->ipaddr);
jaddstr(json,"supernet","yes");
jaddnum(json,"protover",addr->protover);
jaddnum(json,"relay",addr->relayflag);
jaddnum(json,"height",addr->height);
jaddnum(json,"rank",addr->rank);
jaddnum(json,"usock",addr->usock);
if ( addr->dead != 0 )
jaddnum(json,"dead",addr->dead);
jaddnum(json,"ready",addr->ready);
jaddnum(json,"recvblocks",addr->recvblocks);
jaddnum(json,"recvtotal",addr->recvtotal);
jaddnum(json,"lastcontact",addr->lastcontact);
if ( addr->numpings > 0 )
jaddnum(json,"aveping",addr->pingsum/addr->numpings);
array = cJSON_CreateObject();
jaddnum(array,"version",addr->msgcounts.version);
jaddnum(array,"verack",addr->msgcounts.verack);
jaddnum(array,"getaddr",addr->msgcounts.getaddr);
jaddnum(array,"addr",addr->msgcounts.addr);
jaddnum(array,"inv",addr->msgcounts.inv);
jaddnum(array,"getdata",addr->msgcounts.getdata);
jaddnum(array,"notfound",addr->msgcounts.notfound);
jaddnum(array,"getblocks",addr->msgcounts.getblocks);
jaddnum(array,"getheaders",addr->msgcounts.getheaders);
jaddnum(array,"headers",addr->msgcounts.headers);
jaddnum(array,"tx",addr->msgcounts.tx);
jaddnum(array,"block",addr->msgcounts.block);
jaddnum(array,"mempool",addr->msgcounts.mempool);
jaddnum(array,"ping",addr->msgcounts.ping);
jaddnum(array,"pong",addr->msgcounts.pong);
jaddnum(array,"reject",addr->msgcounts.reject);
jaddnum(array,"filterload",addr->msgcounts.filterload);
jaddnum(array,"filteradd",addr->msgcounts.filteradd);
jaddnum(array,"filterclear",addr->msgcounts.filterclear);
jaddnum(array,"merkleblock",addr->msgcounts.merkleblock);
jaddnum(array,"alert",addr->msgcounts.alert);
jadd(json,"msgcounts",array);
return(json);
}
STRING_AND_INT(iguana,bundleaddresses,activecoin,height)
cJSON *iguana_peersjson(struct iguana_info *coin,int32_t addronly)
{
struct iguana_info *ptr;
if ( (ptr= iguana_coinfind(activecoin)) != 0 )
return(iguana_bundleaddrs(ptr,height / coin->chain->bundlesize));
else return(clonestr("{\"error\":\"activecoin is not active\"}"));
cJSON *retjson,*array; int32_t i; struct iguana_peer *addr;
if ( coin == 0 || coin->peers == 0 )
return(0);
array = cJSON_CreateArray();
for (i=0; i<coin->MAXPEERS; i++)
{
addr = &coin->peers->active[i];
if ( addr->usock >= 0 && addr->ipbits != 0 && addr->ipaddr[0] != 0 )
{
if ( addronly != 0 )
jaddistr(array,addr->ipaddr);
else jaddi(array,iguana_peerjson(coin,addr));
}
}
if ( addronly == 0 )
{
retjson = cJSON_CreateObject();
jadd(retjson,"peers",array);
jaddnum(retjson,"maxpeers",coin->MAXPEERS);
jaddstr(retjson,"coin",coin->symbol);
return(retjson);
}
else return(array);
}
STRING_AND_INT(iguana,PoSweights,activecoin,height)
TWO_STRINGS(iguana,nodestatus,activecoin,ipaddr)
{
struct iguana_info *ptr; int32_t num,nonz,errs,bundleheight; struct iguana_pkhash *refP; uint64_t *weights,supply; cJSON *retjson;
if ( (ptr= iguana_coinfind(activecoin)) != 0 )
int32_t i; struct iguana_peer *addr;
if ( coin != 0 && coin->peers != 0 && ipaddr != 0 )
{
//for (bundleheight=coin->chain->bundlesize; bundleheight<height; bundleheight+=coin->chain->bundlesize)
for (i=0; i<coin->MAXPEERS; i++)
{
bundleheight = (height / ptr->chain->bundlesize) * ptr->chain->bundlesize;
if ( (weights= iguana_PoS_weights(myinfo,ptr,&refP,&supply,&num,&nonz,&errs,bundleheight)) != 0 )
{
retjson = cJSON_CreateObject();
jaddstr(retjson,"result",errs == 0 ? "success" : "error");
jaddnum(retjson,"bundleheight",bundleheight);
jaddnum(retjson,"numaddresses",num);
jaddnum(retjson,"nonzero",nonz);
jaddnum(retjson,"errors",errs);
jaddnum(retjson,"supply",dstr(supply));
free(weights);
return(jprint(retjson,1));
} else return(clonestr("{\"error\":\"iguana_PoS_weights returned null\"}"));
addr = &coin->peers->active[i];
if ( strcmp(addr->ipaddr,ipaddr) == 0 )
return(jprint(iguana_peerjson(coin,addr),1));
}
}
return(clonestr("{\"error\":\"activecoin is not active\"}"));
return(clonestr("{\"result\":\"nodestatus couldnt find ipaddr\"}"));
} else return(clonestr("{\"error\":\"nodestatus needs ipaddr\"}"));
}
STRING_ARG(iguana,stakers,activecoin)
STRING_AND_INT(iguana,maxpeers,activecoin,max)
{
struct iguana_info *ptr; int32_t i,datalen,pkind,hdrsi; bits256 hash2; struct iguana_bundle *bp; cJSON *retjson,*array; struct iguana_pkhash *refP; struct iguana_ramchaindata *rdata; char coinaddr[64]; uint8_t refrmd160[20]; bits256 *sortbuf;
if ( (ptr= iguana_coinfind(activecoin)) != 0 && ptr->RTheight > ptr->chain->bundlesize )
cJSON *retjson; int32_t i; struct iguana_peer *addr;
if ( coin != 0 && coin->peers != 0 )
{
hdrsi = (ptr->RTheight / ptr->chain->bundlesize) - 1;
if ( (bp= ptr->bundles[hdrsi]) != 0 && bp->weights != 0 && (rdata= bp->ramchain.H.data) != 0 && bp->weights != 0 )
retjson = cJSON_CreateObject();
if ( max > IGUANA_MAXPEERS )
max = IGUANA_MAXPEERS;
if ( max > coin->MAXPEERS )
{
sortbuf = calloc(bp->numweights,2 * sizeof(*sortbuf));
for (i=datalen=0; i<bp->numweights; i++)
datalen += iguana_rwnum(1,&((uint8_t *)sortbuf)[datalen],sizeof(bp->weights[i]),(void *)&bp->weights[i]);
hash2 = bits256_doublesha256(0,(uint8_t *)sortbuf,datalen);
refP = RAMCHAIN_PTR(rdata,Poffset);
retjson = cJSON_CreateObject();
array = cJSON_CreateArray();
memset(refrmd160,0,sizeof(refrmd160));
for (i=0; i<ptr->chain->bundlesize; i++)
{
if ( (pkind= iguana_staker_sort(ptr,&hash2,refrmd160,refP,bp->weights,bp->numweights,sortbuf)) > 0 )
{
bitcoin_address(coinaddr,ptr->chain->pubtype,refP[pkind].rmd160,sizeof(refP[pkind].rmd160));
jaddistr(array,coinaddr);
} else jaddistr(array,"error");
}
jaddstr(retjson,"result","success");
jadd(retjson,"stakers",array);
return(jprint(retjson,1));
} else return(clonestr("{\"error\":\"iguana_stakers needs PoSweights and weights\"}"));
}
return(clonestr("{\"error\":\"activecoin is not active\"}"));
for (i=max; i<coin->MAXPEERS; i++)
if ( (addr= coin->peers->ranked[i]) != 0 )
addr->dead = 1;
}
coin->MAXPEERS = max;
jaddnum(retjson,"maxpeers",coin->MAXPEERS);
jaddstr(retjson,"coin",coin->symbol);
return(jprint(retjson,1));
} else return(clonestr("{\"error\":\"maxpeers needs coin\"}"));
}
STRING_AND_INT(iguana,bundlehashes,activecoin,height)
char *hmac_dispatch(char *(*hmacfunc)(char *dest,char *key,int32_t key_size,char *message),char *name,char *message,char *password)
{
struct iguana_info *ptr; struct iguana_bundle *bp; int32_t i,hdrsi; cJSON *retjson,*array; struct iguana_ramchaindata *rdata;
if ( (ptr= iguana_coinfind(activecoin)) != 0 )
char hexstr[1025]; cJSON *json;
if ( message != 0 && password != 0 && message[0] != 0 && password[0] != 0 )
{
hdrsi = height / coin->chain->bundlesize;
if ( hdrsi < coin->bundlescount && hdrsi >= 0 && (bp= coin->bundles[hdrsi]) != 0 )
{
if ( (rdata= bp->ramchain.H.data) != 0 )
{
array = cJSON_CreateArray();
for (i=0; i<IGUANA_NUMLHASHES; i++)
jaddinum(array,rdata->lhashes[i].txid);
retjson = cJSON_CreateObject();
jaddstr(retjson,"result","success");
jaddbits256(retjson,"sha256",rdata->sha256);
jadd(retjson,"bundlehashes",array);
return(jprint(retjson,1));
} else return(clonestr("{\"error\":\"ramchain not there\"}"));
} else return(clonestr("{\"error\":\"height is too big\"}"));
} else return(clonestr("{\"error\":\"activecoin is not active\"}"));
memset(hexstr,0,sizeof(hexstr));
(*hmacfunc)(hexstr,password,password==0?0:(int32_t)strlen(password),message);
json = cJSON_CreateObject();
jaddstr(json,"result","hmac calculated");
jaddstr(json,"message",message);
jaddstr(json,name,hexstr);
return(jprint(json,1));
} else return(clonestr("{\"error\":\"hmac needs message and passphrase\"}"));
}
// low priority RPC
char *hash_dispatch(void (*hashfunc)(char *hexstr,uint8_t *buf,uint8_t *msg,int32_t len),char *name,char *message)
{
char hexstr[65537]; uint8_t databuf[32768]; cJSON *json;
if ( message != 0 && message[0] != 0 )
{
memset(hexstr,0,sizeof(hexstr));
(*hashfunc)(hexstr,databuf,(uint8_t *)message,(int32_t)strlen(message));
json = cJSON_CreateObject();
jaddstr(json,"result","hash calculated");
jaddstr(json,"message",message);
jaddstr(json,name,hexstr);
return(jprint(json,1));
} else return(clonestr("{\"error\":\"hash needs message\"}"));
}
HASH_AND_TWOINTS(bitcoinrpc,listsinceblock,blockhash,target,flag)
TWO_HASHES(hash,curve25519_pair,element,scalar)
{
/*"transactions" : [
{
"account" : "doc test",
"address" : "mmXgiR6KAhZCyQ8ndr2BCfEq1wNG2UnyG6",
"category" : "receive",
"amount" : 0.10000000,
"vout" : 0,
"confirmations" : 76478,
"blockhash" : "000000000017c84015f254498c62a7c884a51ccd75d4dd6dbdcb6434aa3bd44d",
"blockindex" : 1,
"blocktime" : 1399294967,
"txid" : "85a98fdf1529f7d5156483ad020a51b7f3340e47448cf932f470b72ff01a6821",
"walletconflicts" : [
],
"time" : 1399294967,
"timereceived" : 1418924714
},*/
cJSON *retjson = cJSON_CreateObject();
jaddstr(retjson,"error","low priority RPC not implemented");
jaddbits256(retjson,"result",curve25519(element,scalar));
return(jprint(retjson,1));
}
ZERO_ARGS(bitcoinrpc,gettxoutsetinfo)
STRING_ARG(hash,NXT,passphrase) { return(hash_dispatch(calc_NXTaddr,"NXT",passphrase)); }
STRING_ARG(hash,curve25519,pubkey) { return(hash_dispatch(calc_curve25519_str,"curve25519",pubkey)); }
STRING_ARG(hash,crc32,message) { return(hash_dispatch(calc_crc32str,"crc32",message)); }
STRING_ARG(hash,base64_encode,message) { return(hash_dispatch(calc_base64_encodestr,"base64_encode",message)); }
STRING_ARG(hash,base64_decode,message) { return(hash_dispatch(calc_base64_decodestr,"base64_decode",message)); }
STRING_ARG(hash,rmd160_sha256,message) { return(hash_dispatch(rmd160ofsha256,"rmd160_sha256",message)); }
STRING_ARG(hash,sha256_sha256,message) { return(hash_dispatch(sha256_sha256,"sha256_sha256",message)); }
STRING_ARG(hash,hex,message) { return(hash_dispatch(calc_hexstr,"hex",message)); }
STRING_ARG(hash,unhex,message) { return(hash_dispatch(calc_unhexstr,"unhex",message)); }
STRING_ARG(hash,sha224,message) { return(hash_dispatch(calc_sha224,"sha224",message)); }
STRING_ARG(hash,sha256,message) { return(hash_dispatch(vcalc_sha256,"sha256",message)); }
STRING_ARG(hash,sha384,message) { return(hash_dispatch(calc_sha384,"sha384",message)); }
STRING_ARG(hash,sha512,message) { return(hash_dispatch(calc_sha512,"sha512",message)); }
STRING_ARG(hash,rmd128,message) { return(hash_dispatch(calc_rmd128,"rmd128",message)); }
STRING_ARG(hash,rmd160,message) { return(hash_dispatch(calc_rmd160,"rmd160",message)); }
STRING_ARG(hash,rmd256,message) { return(hash_dispatch(calc_rmd256,"rmd256",message)); }
STRING_ARG(hash,rmd320,message) { return(hash_dispatch(calc_rmd320,"rmd320",message)); }
STRING_ARG(hash,sha1,message) { return(hash_dispatch(calc_sha1,"sha1",message)); }
STRING_ARG(hash,md2,message) { return(hash_dispatch(calc_md2str,"md2",message)); }
STRING_ARG(hash,md4,message) { return(hash_dispatch(calc_md4str,"md4",message)); }
STRING_ARG(hash,md5,message) { return(hash_dispatch(calc_md5str,"md5",message)); }
STRING_ARG(hash,tiger192_3,message) { return(hash_dispatch(calc_tiger,"tiger",message)); }
STRING_ARG(hash,whirlpool,message) { return(hash_dispatch(calc_whirlpool,"whirlpool",message)); }
TWO_STRINGS(hmac,sha224,message,passphrase) { return(hmac_dispatch(hmac_sha224_str,"sha224",message,passphrase)); }
TWO_STRINGS(hmac,sha256,message,passphrase) { return(hmac_dispatch(hmac_sha256_str,"sha256",message,passphrase)); }
TWO_STRINGS(hmac,sha384,message,passphrase) { return(hmac_dispatch(hmac_sha384_str,"sha384",message,passphrase)); }
TWO_STRINGS(hmac,sha512,message,passphrase) { return(hmac_dispatch(hmac_sha512_str,"sha512",message,passphrase)); }
TWO_STRINGS(hmac,rmd128,message,passphrase) { return(hmac_dispatch(hmac_rmd128_str,"rmd128",message,passphrase)); }
TWO_STRINGS(hmac,rmd160,message,passphrase) { return(hmac_dispatch(hmac_rmd160_str,"rmd160",message,passphrase)); }
TWO_STRINGS(hmac,rmd256,message,passphrase) { return(hmac_dispatch(hmac_rmd256_str,"rmd256",message,passphrase)); }
TWO_STRINGS(hmac,rmd320,message,passphrase) { return(hmac_dispatch(hmac_rmd320_str,"rmd320",message,passphrase)); }
TWO_STRINGS(hmac,sha1,message,passphrase) { return(hmac_dispatch(hmac_sha1_str,"sha1",message,passphrase)); }
TWO_STRINGS(hmac,md2,message,passphrase) { return(hmac_dispatch(hmac_md2_str,"md2",message,passphrase)); }
TWO_STRINGS(hmac,md4,message,passphrase) { return(hmac_dispatch(hmac_md4_str,"md4",message,passphrase)); }
TWO_STRINGS(hmac,md5,message,passphrase) { return(hmac_dispatch(hmac_md5_str,"md5",message,passphrase)); }
TWO_STRINGS(hmac,tiger192_3,message,passphrase) { return(hmac_dispatch(hmac_tiger_str,"tiger",message,passphrase)); }
TWO_STRINGS(hmac,whirlpool,message,passphrase) { return(hmac_dispatch(hmac_whirlpool_str,"whirlpool",message,passphrase)); }
STRING_ARG(SuperNET,bitcoinrpc,setcoin)
{
cJSON *retjson = cJSON_CreateObject();
jaddstr(retjson,"error","low priority RPC not implemented");
return(jprint(retjson,1));
char buf[1024];
if ( setcoin != 0 && setcoin[0] != 0 )
{
strcpy(myinfo->rpcsymbol,setcoin);
touppercase(myinfo->rpcsymbol);
printf("bitcoinrpc.%s\n",myinfo->rpcsymbol);
if ( iguana_launchcoin(myinfo,myinfo->rpcsymbol,json,0) < 0 )
return(clonestr("{\"error\":\"error creating coin\"}"));
else
{
sprintf(buf,"{\"result\":\"success\",\"setcoin\":\"%s\"}",setcoin);
return(clonestr(buf));
}
} else return(clonestr("{\"error\":\"bitcoinrpc needs setcoin value\"}"));
}
ZERO_ARGS(bitcoinrpc,listaddressgroupings)
ZERO_ARGS(SuperNET,help)
{
if ( remoteaddr != 0 )
return(clonestr("{\"error\":\"no remote\"}"));
return(clonestr("{\"error\":\"low priority RPC not implemented\"}"));
cJSON *helpjson,*retjson;
if ( (helpjson= SuperNET_helpjson()) != 0 )
{
retjson = cJSON_CreateObject();
jadd(retjson,"result",helpjson);
return(jprint(retjson,1));
} else return(clonestr("{\"error\":\"cant get helpjson\"}"));
}
SS_D_I_S(bitcoinrpc,move,fromaccount,toaccount,amount,minconf,comment)
TWO_STRINGS(SuperNET,html,agentform,htmlfile)
{
cJSON *retjson;
if ( remoteaddr != 0 )
return(clonestr("{\"error\":\"no remote\"}"));
if ( myinfo->expiration == 0 )
return(clonestr("{\"error\":\"need to unlock wallet\"}"));
char *htmlstr; cJSON *retjson; int32_t max = 4*1024*1024;
if ( htmlfile == 0 || htmlfile[0] == 0 )
htmlfile = "forms.html";
//if ( (fp= fopen(htmlfile,"w")) == 0 )
// printf("error opening htmlfile.(%s)\n",htmlfile);
htmlstr = malloc(max);
htmlstr = SuperNET_htmlstr(htmlfile,htmlstr,max,agentform);
retjson = cJSON_CreateObject();
jaddstr(retjson,"result",htmlstr);
free(htmlstr);
//if ( fp != 0 )
// fclose(fp);
return(jprint(retjson,1));
}
ZERO_ARGS(pax,start)
{
void PAX_init();
PAX_init();
return(clonestr("{\"result\":\"PAX_init called\"}"));
}
#undef IGUANA_ARGS
#undef _IGUANA_APIDEC_H_
#include "../includes/iguana_apiundefs.h"

2
iguana/secp256k1/src/ecmult_const_impl.h

@ -60,7 +60,7 @@ static int secp256k1_wnaf_const(int *wnaf, secp256k1_scalar s, int w) {
int word = 0;
/* 1 2 3 */
int u_last;
int u;
int u=0;
#ifdef USE_ENDOMORPHISM
int flip;

2
iguana/secp256k1/src/modules/rangeproof/rangeproof_impl.h

@ -406,7 +406,7 @@ SECP256K1_INLINE static void secp256k1_rangeproof_ch32xor(unsigned char *x, cons
SECP256K1_INLINE static int secp256k1_rangeproof_rewind_inner(secp256k1_scalar *blind,uint64_t *v,
unsigned char *message,int *mlen,secp256k1_scalar *ev,secp256k1_scalar *s,int *rsizes,int rings, const unsigned char *nonce,const unsigned char *commit,const unsigned char *proof,int len)
{
unsigned char prep[4096]; unsigned char tmp[32]; uint64_t value; int offset,i,j,b,skip1,skip2,npub;
unsigned char prep[4096]; unsigned char tmp[32]; uint64_t value=0; int offset,i,j,b,skip1,skip2,npub;
secp256k1_scalar s_orig[128]; secp256k1_scalar sec[32]; secp256k1_scalar stmp;
npub = ((rings - 1) << 2) + rsizes[rings-1];
VERIFY_CHECK(npub <= 128);

2
iguana/secp256k1/src/modules/recovery/main_impl.h

@ -123,7 +123,7 @@ static int secp256k1_ecdsa_sig_recover(const secp256k1_ecmult_context *ctx, cons
int secp256k1_ecdsa_sign_recoverable(const secp256k1_context* ctx, secp256k1_ecdsa_recoverable_signature *signature, const unsigned char *msg32, const unsigned char *seckey, secp256k1_nonce_function noncefp, const void* noncedata) {
secp256k1_scalar r, s;
secp256k1_scalar sec, non, msg;
int recid;
int recid = 0;
int ret = 0;
int overflow = 0;
VERIFY_CHECK(ctx != NULL);

2
iguana/tests/DEXinit

@ -0,0 +1,2 @@
#!/bin/bash
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"InstantDEX\",\"method\":\"init\"}"

164
iguana/tests/KMD.batch10

@ -0,0 +1,164 @@
# RQC6A3SKtLb2zmqDDwFvRH6Zz4mZufmp3d KMD 6266.43352646
./komodo-cli sendtoaddress RQC6A3SKtLb2zmqDDwFvRH6Zz4mZufmp3d 6266.43352646
sleep 3
echo "6266.43352646 <- expected amount RQC6A3SKtLb2zmqDDwFvRH6Zz4mZufmp3d"
# R9SpRcd2KRD45B7SqzuUFhNnsnx7YqgkN6 KMD 1203.04246569
./komodo-cli sendtoaddress R9SpRcd2KRD45B7SqzuUFhNnsnx7YqgkN6 1203.04246569
sleep 3
echo "1203.04246569 <- expected amount R9SpRcd2KRD45B7SqzuUFhNnsnx7YqgkN6"
# RCA8H1npFPW5pnJRzycF8tFEJmn6XZhD4j KMD 9683.15249375
./komodo-cli sendtoaddress RCA8H1npFPW5pnJRzycF8tFEJmn6XZhD4j 9683.15249375
sleep 3
echo "9683.15249375 <- expected amount RCA8H1npFPW5pnJRzycF8tFEJmn6XZhD4j"
# RTJXwRhuAH9iyztyuRuGC8G7DamTgSMGvT KMD 306877.42641191
./komodo-cli sendtoaddress RTJXwRhuAH9iyztyuRuGC8G7DamTgSMGvT 306877.42641191
sleep 3
echo "306877.42641191 <- expected amount RTJXwRhuAH9iyztyuRuGC8G7DamTgSMGvT"
# RQantoJxT8szwfAqUM3enLPe85YiQtwndH KMD 150.23706901
./komodo-cli sendtoaddress RQantoJxT8szwfAqUM3enLPe85YiQtwndH 150.23706901
sleep 3
echo "150.23706901 <- expected amount RQantoJxT8szwfAqUM3enLPe85YiQtwndH"
# RLvvwtBUupmGDy81CJNp6RxKbxxbuu3jRY KMD 1985.04626121
./komodo-cli sendtoaddress RLvvwtBUupmGDy81CJNp6RxKbxxbuu3jRY 1985.04626121
sleep 3
echo "1985.04626121 <- expected amount RLvvwtBUupmGDy81CJNp6RxKbxxbuu3jRY"
# RFdRKqe82MmvSxZQjgtLfzdf8mNHztKpPE KMD 1664.32251109
./komodo-cli sendtoaddress RFdRKqe82MmvSxZQjgtLfzdf8mNHztKpPE 1664.32251109
sleep 3
echo "1664.32251109 <- expected amount RFdRKqe82MmvSxZQjgtLfzdf8mNHztKpPE"
# RE1NYFqFG2vmhhHVY7QFC7sTp7zBxvSSP3 KMD 5.99800973
./komodo-cli sendtoaddress RE1NYFqFG2vmhhHVY7QFC7sTp7zBxvSSP3 5.99800973
sleep 3
echo "5.99800973 <- expected amount RE1NYFqFG2vmhhHVY7QFC7sTp7zBxvSSP3"
# RNYMy1joru9gFitzokTSi5qFFc5nS4iFxc KMD 9671.53271075
./komodo-cli sendtoaddress RNYMy1joru9gFitzokTSi5qFFc5nS4iFxc 9671.53271075
sleep 3
echo "9671.53271075 <- expected amount RNYMy1joru9gFitzokTSi5qFFc5nS4iFxc"
# RF4jZsF5BUckQqX5hsS68kjQMYSba8Fypm KMD 40223.19497203, REVS 101.00000000
# RF4jZsF5BUckQqX5hsS68kjQMYSba8Fypm KMD 40223.19497203
./komodo-cli sendtoaddress RF4jZsF5BUckQqX5hsS68kjQMYSba8Fypm 40223.19497203
sleep 3
echo "40223.19497203 <- expected amount RF4jZsF5BUckQqX5hsS68kjQMYSba8Fypm"
# RPqAFgwnB1hjae6Ar4Kms973uS93HbDkoB KMD 72698.53877152
./komodo-cli sendtoaddress RPqAFgwnB1hjae6Ar4Kms973uS93HbDkoB 72698.53877152
sleep 3
echo "72698.53877152 <- expected amount RPqAFgwnB1hjae6Ar4Kms973uS93HbDkoB"
# RVzFdNGRn8Ekr4XaeDSfE9fjqvKdcVicJe KMD 9683.15249375
./komodo-cli sendtoaddress RVzFdNGRn8Ekr4XaeDSfE9fjqvKdcVicJe 9683.15249375
sleep 3
echo "9683.15249375 <- expected amount RVzFdNGRn8Ekr4XaeDSfE9fjqvKdcVicJe"
# RTbTzn7FGJWwrH1E3fMwuZPs3YVH1MvVoB KMD 3532.13792522
./komodo-cli sendtoaddress RTbTzn7FGJWwrH1E3fMwuZPs3YVH1MvVoB 3532.13792522
sleep 3
echo "3532.13792522 <- expected amount RTbTzn7FGJWwrH1E3fMwuZPs3YVH1MvVoB"
# RDdUQ5t6SYYGZUdAxBk5i7QdTWvzAshxNZ KMD 309.69366537
./komodo-cli sendtoaddress RDdUQ5t6SYYGZUdAxBk5i7QdTWvzAshxNZ 309.69366537
sleep 3
echo "309.69366537 <- expected amount RDdUQ5t6SYYGZUdAxBk5i7QdTWvzAshxNZ"
# RYYgc5UD7X18E6CrDXCs1cts5WDwaWhm1Z KMD 3873.26099750
./komodo-cli sendtoaddress RYYgc5UD7X18E6CrDXCs1cts5WDwaWhm1Z 3873.26099750
sleep 3
echo "3873.26099750 <- expected amount RYYgc5UD7X18E6CrDXCs1cts5WDwaWhm1Z"
# RXdBJ5cWDcS38ykuggEQZh3vSztxwmG3ut KMD 62053.93460050
./komodo-cli sendtoaddress RXdBJ5cWDcS38ykuggEQZh3vSztxwmG3ut 62053.93460050
sleep 3
echo "62053.93460050 <- expected amount RXdBJ5cWDcS38ykuggEQZh3vSztxwmG3ut"
# REKnBAyZMnhKzRozzcuv6fKRtoBsKTFYjs KMD 6506.14889316
./komodo-cli sendtoaddress REKnBAyZMnhKzRozzcuv6fKRtoBsKTFYjs 6506.14889316
sleep 3
echo "6506.14889316 <- expected amount REKnBAyZMnhKzRozzcuv6fKRtoBsKTFYjs"
# RY422uSvkAoZy81uGot5PmXuMrtChhJ3uL KMD 812.78437655
./komodo-cli sendtoaddress RY422uSvkAoZy81uGot5PmXuMrtChhJ3uL 812.78437655
sleep 3
echo "812.78437655 <- expected amount RY422uSvkAoZy81uGot5PmXuMrtChhJ3uL"
# R9o3CQms16CLu63j9WdqsaWB3XsssRXEq8 KMD 1452.47287406
./komodo-cli sendtoaddress R9o3CQms16CLu63j9WdqsaWB3XsssRXEq8 1452.47287406
sleep 3
echo "1452.47287406 <- expected amount R9o3CQms16CLu63j9WdqsaWB3XsssRXEq8"
# RWTfFTP7c9WxLhgxd2EXSsKszpDVPXHN8A KMD 867.82549038
./komodo-cli sendtoaddress RWTfFTP7c9WxLhgxd2EXSsKszpDVPXHN8A 867.82549038
sleep 3
echo "867.82549038 <- expected amount RWTfFTP7c9WxLhgxd2EXSsKszpDVPXHN8A"
# RHJ55iWUQNbKcSn8shbv1RbGuip3RSRHFv KMD 693.08132289
./komodo-cli sendtoaddress RHJ55iWUQNbKcSn8shbv1RbGuip3RSRHFv 693.08132289
sleep 3
echo "693.08132289 <- expected amount RHJ55iWUQNbKcSn8shbv1RbGuip3RSRHFv"
# RCfBinKfJ1wGSxXLPNTmC9bohFRoofUiVm KMD 8521.17419450
./komodo-cli sendtoaddress RCfBinKfJ1wGSxXLPNTmC9bohFRoofUiVm 8521.17419450
sleep 3
echo "8521.17419450 <- expected amount RCfBinKfJ1wGSxXLPNTmC9bohFRoofUiVm"
# RNEZRHeWE3KgSTUr3qvH7RNvM2JWZZkygM KMD 5328.53865807
./komodo-cli sendtoaddress RNEZRHeWE3KgSTUr3qvH7RNvM2JWZZkygM 5328.53865807
sleep 3
echo "5328.53865807 <- expected amount RNEZRHeWE3KgSTUr3qvH7RNvM2JWZZkygM"
# RH7tsX9PaKECxSEALpu5EWdmEKikY7R2n1 KMD 29049.45748125
./komodo-cli sendtoaddress RH7tsX9PaKECxSEALpu5EWdmEKikY7R2n1 29049.45748125
sleep 3
echo "29049.45748125 <- expected amount RH7tsX9PaKECxSEALpu5EWdmEKikY7R2n1"
# RYHxrTNpqrAHRbULboJVYHWqmnmVhzzrot KMD 4840.60793162
./komodo-cli sendtoaddress RYHxrTNpqrAHRbULboJVYHWqmnmVhzzrot 4840.60793162
sleep 3
echo "4840.60793162 <- expected amount RYHxrTNpqrAHRbULboJVYHWqmnmVhzzrot"
# RLCEGw7zmAhZQYtP23Z2TD45gAT9ZuZKct KMD 2420.78812342
./komodo-cli sendtoaddress RLCEGw7zmAhZQYtP23Z2TD45gAT9ZuZKct 2420.78812342
sleep 3
echo "2420.78812342 <- expected amount RLCEGw7zmAhZQYtP23Z2TD45gAT9ZuZKct"
# RGQmMzmUfa6R5dZvvL5wvy2vxPLEcgkkyC KMD 137.73071692, REVS 2.73426759
# RGQmMzmUfa6R5dZvvL5wvy2vxPLEcgkkyC KMD 137.73071692
./komodo-cli sendtoaddress RGQmMzmUfa6R5dZvvL5wvy2vxPLEcgkkyC 137.73071692
sleep 3
echo "137.73071692 <- expected amount RGQmMzmUfa6R5dZvvL5wvy2vxPLEcgkkyC"
# RRdDD2YoR5cfwktePGGFT5cEyRcWkEjzvM KMD 9737.34607711
./komodo-cli sendtoaddress RRdDD2YoR5cfwktePGGFT5cEyRcWkEjzvM 9737.34607711
sleep 3
echo "9737.34607711 <- expected amount RRdDD2YoR5cfwktePGGFT5cEyRcWkEjzvM"
# RKbb9NGB3pU2BaByoDwyZDH74E7koR2Lga KMD 1903.31162313
./komodo-cli sendtoaddress RKbb9NGB3pU2BaByoDwyZDH74E7koR2Lga 1903.31162313
sleep 3
echo "1903.31162313 <- expected amount RKbb9NGB3pU2BaByoDwyZDH74E7koR2Lga"
# RQsSsmpzFagxRaYk6cTMpNHa4eYLihKn8h KMD 99.84182062
./komodo-cli sendtoaddress RQsSsmpzFagxRaYk6cTMpNHa4eYLihKn8h 99.84182062
sleep 3
echo "99.84182062 <- expected amount RQsSsmpzFagxRaYk6cTMpNHa4eYLihKn8h"
# RKQPNcePppEkV4CMXZrwqEMAvRHbruKVdF KMD 1167.24851677
./komodo-cli sendtoaddress RKQPNcePppEkV4CMXZrwqEMAvRHbruKVdF 1167.24851677
sleep 3
echo "1167.24851677 <- expected amount RKQPNcePppEkV4CMXZrwqEMAvRHbruKVdF"
# RHKuiEoakr9yeWQT9UZzCrqPgR8MPBaGvD KMD 15095.38306803
./komodo-cli sendtoaddress RHKuiEoakr9yeWQT9UZzCrqPgR8MPBaGvD 15095.38306803
sleep 3
echo "15095.38306803 <- expected amount RHKuiEoakr9yeWQT9UZzCrqPgR8MPBaGvD"
# total KMD 618514.84605397 REVS 0.00000000

161
iguana/tests/KMD.batch10.importaddress

@ -0,0 +1,161 @@
# RQC6A3SKtLb2zmqDDwFvRH6Zz4mZufmp3d KMD 6266.43352646
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RQC6A3SKtLb2zmqDDwFvRH6Zz4mZufmp3d\",\"symbol\":\"KMD\"}" # 6266.43352646
sleep 3
echo "6266.43352646 <- expected amount RQC6A3SKtLb2zmqDDwFvRH6Zz4mZufmp3d"
# R9SpRcd2KRD45B7SqzuUFhNnsnx7YqgkN6 KMD 1203.04246569
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"R9SpRcd2KRD45B7SqzuUFhNnsnx7YqgkN6\",\"symbol\":\"KMD\"}" # 1203.04246569
sleep 3
echo "1203.04246569 <- expected amount R9SpRcd2KRD45B7SqzuUFhNnsnx7YqgkN6"
# RCA8H1npFPW5pnJRzycF8tFEJmn6XZhD4j KMD 9683.15249375
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RCA8H1npFPW5pnJRzycF8tFEJmn6XZhD4j\",\"symbol\":\"KMD\"}" # 9683.15249375
sleep 3
echo "9683.15249375 <- expected amount RCA8H1npFPW5pnJRzycF8tFEJmn6XZhD4j"
# RTJXwRhuAH9iyztyuRuGC8G7DamTgSMGvT KMD 306877.42641191
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RTJXwRhuAH9iyztyuRuGC8G7DamTgSMGvT\",\"symbol\":\"KMD\"}" # 306877.42641191
sleep 3
echo "306877.42641191 <- expected amount RTJXwRhuAH9iyztyuRuGC8G7DamTgSMGvT"
# RQantoJxT8szwfAqUM3enLPe85YiQtwndH KMD 150.23706901
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RQantoJxT8szwfAqUM3enLPe85YiQtwndH\",\"symbol\":\"KMD\"}" # 150.23706901
sleep 3
echo "150.23706901 <- expected amount RQantoJxT8szwfAqUM3enLPe85YiQtwndH"
# RLvvwtBUupmGDy81CJNp6RxKbxxbuu3jRY KMD 1985.04626121
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RLvvwtBUupmGDy81CJNp6RxKbxxbuu3jRY\",\"symbol\":\"KMD\"}" # 1985.04626121
sleep 3
echo "1985.04626121 <- expected amount RLvvwtBUupmGDy81CJNp6RxKbxxbuu3jRY"
# RFdRKqe82MmvSxZQjgtLfzdf8mNHztKpPE KMD 1664.32251109
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RFdRKqe82MmvSxZQjgtLfzdf8mNHztKpPE\",\"symbol\":\"KMD\"}" # 1664.32251109
sleep 3
echo "1664.32251109 <- expected amount RFdRKqe82MmvSxZQjgtLfzdf8mNHztKpPE"
# RE1NYFqFG2vmhhHVY7QFC7sTp7zBxvSSP3 KMD 5.99800973
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RE1NYFqFG2vmhhHVY7QFC7sTp7zBxvSSP3\",\"symbol\":\"KMD\"}" # 5.99800973
sleep 3
echo "5.99800973 <- expected amount RE1NYFqFG2vmhhHVY7QFC7sTp7zBxvSSP3"
# RNYMy1joru9gFitzokTSi5qFFc5nS4iFxc KMD 9671.53271075
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RNYMy1joru9gFitzokTSi5qFFc5nS4iFxc\",\"symbol\":\"KMD\"}" # 9671.53271075
sleep 3
echo "9671.53271075 <- expected amount RNYMy1joru9gFitzokTSi5qFFc5nS4iFxc"
# RF4jZsF5BUckQqX5hsS68kjQMYSba8Fypm KMD 40223.19497203, REVS 101.00000000
# RF4jZsF5BUckQqX5hsS68kjQMYSba8Fypm KMD 40223.19497203
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RF4jZsF5BUckQqX5hsS68kjQMYSba8Fypm\",\"symbol\":\"KMD\"}" # 40223.19497203
sleep 3
echo "40223.19497203 <- expected amount RF4jZsF5BUckQqX5hsS68kjQMYSba8Fypm"
# RPqAFgwnB1hjae6Ar4Kms973uS93HbDkoB KMD 72698.53877152
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RPqAFgwnB1hjae6Ar4Kms973uS93HbDkoB\",\"symbol\":\"KMD\"}" # 72698.53877152
sleep 3
echo "72698.53877152 <- expected amount RPqAFgwnB1hjae6Ar4Kms973uS93HbDkoB"
# RVzFdNGRn8Ekr4XaeDSfE9fjqvKdcVicJe KMD 9683.15249375
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RVzFdNGRn8Ekr4XaeDSfE9fjqvKdcVicJe\",\"symbol\":\"KMD\"}" # 9683.15249375
sleep 3
echo "9683.15249375 <- expected amount RVzFdNGRn8Ekr4XaeDSfE9fjqvKdcVicJe"
# RTbTzn7FGJWwrH1E3fMwuZPs3YVH1MvVoB KMD 3532.13792522
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RTbTzn7FGJWwrH1E3fMwuZPs3YVH1MvVoB\",\"symbol\":\"KMD\"}" # 3532.13792522
sleep 3
echo "3532.13792522 <- expected amount RTbTzn7FGJWwrH1E3fMwuZPs3YVH1MvVoB"
# RDdUQ5t6SYYGZUdAxBk5i7QdTWvzAshxNZ KMD 309.69366537
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RDdUQ5t6SYYGZUdAxBk5i7QdTWvzAshxNZ\",\"symbol\":\"KMD\"}" # 309.69366537
sleep 3
echo "309.69366537 <- expected amount RDdUQ5t6SYYGZUdAxBk5i7QdTWvzAshxNZ"
# RYYgc5UD7X18E6CrDXCs1cts5WDwaWhm1Z KMD 3873.26099750
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RYYgc5UD7X18E6CrDXCs1cts5WDwaWhm1Z\",\"symbol\":\"KMD\"}" # 3873.26099750
sleep 3
echo "3873.26099750 <- expected amount RYYgc5UD7X18E6CrDXCs1cts5WDwaWhm1Z"
# RXdBJ5cWDcS38ykuggEQZh3vSztxwmG3ut KMD 62053.93460050
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RXdBJ5cWDcS38ykuggEQZh3vSztxwmG3ut\",\"symbol\":\"KMD\"}" # 62053.93460050
sleep 3
echo "62053.93460050 <- expected amount RXdBJ5cWDcS38ykuggEQZh3vSztxwmG3ut"
# REKnBAyZMnhKzRozzcuv6fKRtoBsKTFYjs KMD 6506.14889316
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"REKnBAyZMnhKzRozzcuv6fKRtoBsKTFYjs\",\"symbol\":\"KMD\"}" # 6506.14889316
sleep 3
echo "6506.14889316 <- expected amount REKnBAyZMnhKzRozzcuv6fKRtoBsKTFYjs"
# RY422uSvkAoZy81uGot5PmXuMrtChhJ3uL KMD 812.78437655
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RY422uSvkAoZy81uGot5PmXuMrtChhJ3uL\",\"symbol\":\"KMD\"}" # 812.78437655
sleep 3
echo "812.78437655 <- expected amount RY422uSvkAoZy81uGot5PmXuMrtChhJ3uL"
# R9o3CQms16CLu63j9WdqsaWB3XsssRXEq8 KMD 1452.47287406
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"R9o3CQms16CLu63j9WdqsaWB3XsssRXEq8\",\"symbol\":\"KMD\"}" # 1452.47287406
sleep 3
echo "1452.47287406 <- expected amount R9o3CQms16CLu63j9WdqsaWB3XsssRXEq8"
# RWTfFTP7c9WxLhgxd2EXSsKszpDVPXHN8A KMD 867.82549038
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RWTfFTP7c9WxLhgxd2EXSsKszpDVPXHN8A\",\"symbol\":\"KMD\"}" # 867.82549038
sleep 3
echo "867.82549038 <- expected amount RWTfFTP7c9WxLhgxd2EXSsKszpDVPXHN8A"
# RHJ55iWUQNbKcSn8shbv1RbGuip3RSRHFv KMD 693.08132289
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RHJ55iWUQNbKcSn8shbv1RbGuip3RSRHFv\",\"symbol\":\"KMD\"}" # 693.08132289
sleep 3
echo "693.08132289 <- expected amount RHJ55iWUQNbKcSn8shbv1RbGuip3RSRHFv"
# RCfBinKfJ1wGSxXLPNTmC9bohFRoofUiVm KMD 8521.17419450
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RCfBinKfJ1wGSxXLPNTmC9bohFRoofUiVm\",\"symbol\":\"KMD\"}" # 8521.17419450
sleep 3
echo "8521.17419450 <- expected amount RCfBinKfJ1wGSxXLPNTmC9bohFRoofUiVm"
# RNEZRHeWE3KgSTUr3qvH7RNvM2JWZZkygM KMD 5328.53865807
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RNEZRHeWE3KgSTUr3qvH7RNvM2JWZZkygM\",\"symbol\":\"KMD\"}" # 5328.53865807
sleep 3
echo "5328.53865807 <- expected amount RNEZRHeWE3KgSTUr3qvH7RNvM2JWZZkygM"
# RH7tsX9PaKECxSEALpu5EWdmEKikY7R2n1 KMD 29049.45748125
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RH7tsX9PaKECxSEALpu5EWdmEKikY7R2n1\",\"symbol\":\"KMD\"}" # 29049.45748125
sleep 3
echo "29049.45748125 <- expected amount RH7tsX9PaKECxSEALpu5EWdmEKikY7R2n1"
# RYHxrTNpqrAHRbULboJVYHWqmnmVhzzrot KMD 4840.60793162
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RYHxrTNpqrAHRbULboJVYHWqmnmVhzzrot\",\"symbol\":\"KMD\"}" # 4840.60793162
sleep 3
echo "4840.60793162 <- expected amount RYHxrTNpqrAHRbULboJVYHWqmnmVhzzrot"
# RLCEGw7zmAhZQYtP23Z2TD45gAT9ZuZKct KMD 2420.78812342
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RLCEGw7zmAhZQYtP23Z2TD45gAT9ZuZKct\",\"symbol\":\"KMD\"}" # 2420.78812342
sleep 3
echo "2420.78812342 <- expected amount RLCEGw7zmAhZQYtP23Z2TD45gAT9ZuZKct"
# RGQmMzmUfa6R5dZvvL5wvy2vxPLEcgkkyC KMD 137.73071692, REVS 2.73426759
# RGQmMzmUfa6R5dZvvL5wvy2vxPLEcgkkyC KMD 137.73071692
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RGQmMzmUfa6R5dZvvL5wvy2vxPLEcgkkyC\",\"symbol\":\"KMD\"}" # 137.73071692
sleep 3
echo "137.73071692 <- expected amount RGQmMzmUfa6R5dZvvL5wvy2vxPLEcgkkyC"
# RRdDD2YoR5cfwktePGGFT5cEyRcWkEjzvM KMD 9737.34607711
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RRdDD2YoR5cfwktePGGFT5cEyRcWkEjzvM\",\"symbol\":\"KMD\"}" # 9737.34607711
sleep 3
echo "9737.34607711 <- expected amount RRdDD2YoR5cfwktePGGFT5cEyRcWkEjzvM"
# RKbb9NGB3pU2BaByoDwyZDH74E7koR2Lga KMD 1903.31162313
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RKbb9NGB3pU2BaByoDwyZDH74E7koR2Lga\",\"symbol\":\"KMD\"}" # 1903.31162313
sleep 3
echo "1903.31162313 <- expected amount RKbb9NGB3pU2BaByoDwyZDH74E7koR2Lga"
# RQsSsmpzFagxRaYk6cTMpNHa4eYLihKn8h KMD 99.84182062
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RQsSsmpzFagxRaYk6cTMpNHa4eYLihKn8h\",\"symbol\":\"KMD\"}" # 99.84182062
sleep 3
echo "99.84182062 <- expected amount RQsSsmpzFagxRaYk6cTMpNHa4eYLihKn8h"
# RKQPNcePppEkV4CMXZrwqEMAvRHbruKVdF KMD 1167.24851677
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RKQPNcePppEkV4CMXZrwqEMAvRHbruKVdF\",\"symbol\":\"KMD\"}" # 1167.24851677
sleep 3
echo "1167.24851677 <- expected amount RKQPNcePppEkV4CMXZrwqEMAvRHbruKVdF"
# RHKuiEoakr9yeWQT9UZzCrqPgR8MPBaGvD KMD 15095.38306803
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RHKuiEoakr9yeWQT9UZzCrqPgR8MPBaGvD\",\"symbol\":\"KMD\"}" # 15095.38306803
sleep 3
echo "15095.38306803 <- expected amount RHKuiEoakr9yeWQT9UZzCrqPgR8MPBaGvD"

129
iguana/tests/KMD.batch10.listunspent

@ -0,0 +1,129 @@
# RQC6A3SKtLb2zmqDDwFvRH6Zz4mZufmp3d KMD 6266.43352646
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RQC6A3SKtLb2zmqDDwFvRH6Zz4mZufmp3d\",\"symbol\":\"KMD\"}"
echo "6266.43352646 <- expected amount RQC6A3SKtLb2zmqDDwFvRH6Zz4mZufmp3d"
# R9SpRcd2KRD45B7SqzuUFhNnsnx7YqgkN6 KMD 1203.04246569
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"R9SpRcd2KRD45B7SqzuUFhNnsnx7YqgkN6\",\"symbol\":\"KMD\"}"
echo "1203.04246569 <- expected amount R9SpRcd2KRD45B7SqzuUFhNnsnx7YqgkN6"
# RCA8H1npFPW5pnJRzycF8tFEJmn6XZhD4j KMD 9683.15249375
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RCA8H1npFPW5pnJRzycF8tFEJmn6XZhD4j\",\"symbol\":\"KMD\"}"
echo "9683.15249375 <- expected amount RCA8H1npFPW5pnJRzycF8tFEJmn6XZhD4j"
# RTJXwRhuAH9iyztyuRuGC8G7DamTgSMGvT KMD 306877.42641191
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RTJXwRhuAH9iyztyuRuGC8G7DamTgSMGvT\",\"symbol\":\"KMD\"}"
echo "306877.42641191 <- expected amount RTJXwRhuAH9iyztyuRuGC8G7DamTgSMGvT"
# RQantoJxT8szwfAqUM3enLPe85YiQtwndH KMD 150.23706901
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RQantoJxT8szwfAqUM3enLPe85YiQtwndH\",\"symbol\":\"KMD\"}"
echo "150.23706901 <- expected amount RQantoJxT8szwfAqUM3enLPe85YiQtwndH"
# RLvvwtBUupmGDy81CJNp6RxKbxxbuu3jRY KMD 1985.04626121
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RLvvwtBUupmGDy81CJNp6RxKbxxbuu3jRY\",\"symbol\":\"KMD\"}"
echo "1985.04626121 <- expected amount RLvvwtBUupmGDy81CJNp6RxKbxxbuu3jRY"
# RFdRKqe82MmvSxZQjgtLfzdf8mNHztKpPE KMD 1664.32251109
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RFdRKqe82MmvSxZQjgtLfzdf8mNHztKpPE\",\"symbol\":\"KMD\"}"
echo "1664.32251109 <- expected amount RFdRKqe82MmvSxZQjgtLfzdf8mNHztKpPE"
# RE1NYFqFG2vmhhHVY7QFC7sTp7zBxvSSP3 KMD 5.99800973
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RE1NYFqFG2vmhhHVY7QFC7sTp7zBxvSSP3\",\"symbol\":\"KMD\"}"
echo "5.99800973 <- expected amount RE1NYFqFG2vmhhHVY7QFC7sTp7zBxvSSP3"
# RNYMy1joru9gFitzokTSi5qFFc5nS4iFxc KMD 9671.53271075
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RNYMy1joru9gFitzokTSi5qFFc5nS4iFxc\",\"symbol\":\"KMD\"}"
echo "9671.53271075 <- expected amount RNYMy1joru9gFitzokTSi5qFFc5nS4iFxc"
# RF4jZsF5BUckQqX5hsS68kjQMYSba8Fypm KMD 40223.19497203, REVS 101.00000000
# RF4jZsF5BUckQqX5hsS68kjQMYSba8Fypm KMD 40223.19497203
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RF4jZsF5BUckQqX5hsS68kjQMYSba8Fypm\",\"symbol\":\"KMD\"}"
echo "40223.19497203 <- expected amount RF4jZsF5BUckQqX5hsS68kjQMYSba8Fypm"
# RPqAFgwnB1hjae6Ar4Kms973uS93HbDkoB KMD 72698.53877152
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RPqAFgwnB1hjae6Ar4Kms973uS93HbDkoB\",\"symbol\":\"KMD\"}"
echo "72698.53877152 <- expected amount RPqAFgwnB1hjae6Ar4Kms973uS93HbDkoB"
# RVzFdNGRn8Ekr4XaeDSfE9fjqvKdcVicJe KMD 9683.15249375
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RVzFdNGRn8Ekr4XaeDSfE9fjqvKdcVicJe\",\"symbol\":\"KMD\"}"
echo "9683.15249375 <- expected amount RVzFdNGRn8Ekr4XaeDSfE9fjqvKdcVicJe"
# RTbTzn7FGJWwrH1E3fMwuZPs3YVH1MvVoB KMD 3532.13792522
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RTbTzn7FGJWwrH1E3fMwuZPs3YVH1MvVoB\",\"symbol\":\"KMD\"}"
echo "3532.13792522 <- expected amount RTbTzn7FGJWwrH1E3fMwuZPs3YVH1MvVoB"
# RDdUQ5t6SYYGZUdAxBk5i7QdTWvzAshxNZ KMD 309.69366537
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RDdUQ5t6SYYGZUdAxBk5i7QdTWvzAshxNZ\",\"symbol\":\"KMD\"}"
echo "309.69366537 <- expected amount RDdUQ5t6SYYGZUdAxBk5i7QdTWvzAshxNZ"
# RYYgc5UD7X18E6CrDXCs1cts5WDwaWhm1Z KMD 3873.26099750
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RYYgc5UD7X18E6CrDXCs1cts5WDwaWhm1Z\",\"symbol\":\"KMD\"}"
echo "3873.26099750 <- expected amount RYYgc5UD7X18E6CrDXCs1cts5WDwaWhm1Z"
# RXdBJ5cWDcS38ykuggEQZh3vSztxwmG3ut KMD 62053.93460050
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RXdBJ5cWDcS38ykuggEQZh3vSztxwmG3ut\",\"symbol\":\"KMD\"}"
echo "62053.93460050 <- expected amount RXdBJ5cWDcS38ykuggEQZh3vSztxwmG3ut"
# REKnBAyZMnhKzRozzcuv6fKRtoBsKTFYjs KMD 6506.14889316
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"REKnBAyZMnhKzRozzcuv6fKRtoBsKTFYjs\",\"symbol\":\"KMD\"}"
echo "6506.14889316 <- expected amount REKnBAyZMnhKzRozzcuv6fKRtoBsKTFYjs"
# RY422uSvkAoZy81uGot5PmXuMrtChhJ3uL KMD 812.78437655
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RY422uSvkAoZy81uGot5PmXuMrtChhJ3uL\",\"symbol\":\"KMD\"}"
echo "812.78437655 <- expected amount RY422uSvkAoZy81uGot5PmXuMrtChhJ3uL"
# R9o3CQms16CLu63j9WdqsaWB3XsssRXEq8 KMD 1452.47287406
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"R9o3CQms16CLu63j9WdqsaWB3XsssRXEq8\",\"symbol\":\"KMD\"}"
echo "1452.47287406 <- expected amount R9o3CQms16CLu63j9WdqsaWB3XsssRXEq8"
# RWTfFTP7c9WxLhgxd2EXSsKszpDVPXHN8A KMD 867.82549038
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RWTfFTP7c9WxLhgxd2EXSsKszpDVPXHN8A\",\"symbol\":\"KMD\"}"
echo "867.82549038 <- expected amount RWTfFTP7c9WxLhgxd2EXSsKszpDVPXHN8A"
# RHJ55iWUQNbKcSn8shbv1RbGuip3RSRHFv KMD 693.08132289
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RHJ55iWUQNbKcSn8shbv1RbGuip3RSRHFv\",\"symbol\":\"KMD\"}"
echo "693.08132289 <- expected amount RHJ55iWUQNbKcSn8shbv1RbGuip3RSRHFv"
# RCfBinKfJ1wGSxXLPNTmC9bohFRoofUiVm KMD 8521.17419450
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RCfBinKfJ1wGSxXLPNTmC9bohFRoofUiVm\",\"symbol\":\"KMD\"}"
echo "8521.17419450 <- expected amount RCfBinKfJ1wGSxXLPNTmC9bohFRoofUiVm"
# RNEZRHeWE3KgSTUr3qvH7RNvM2JWZZkygM KMD 5328.53865807
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RNEZRHeWE3KgSTUr3qvH7RNvM2JWZZkygM\",\"symbol\":\"KMD\"}"
echo "5328.53865807 <- expected amount RNEZRHeWE3KgSTUr3qvH7RNvM2JWZZkygM"
# RH7tsX9PaKECxSEALpu5EWdmEKikY7R2n1 KMD 29049.45748125
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RH7tsX9PaKECxSEALpu5EWdmEKikY7R2n1\",\"symbol\":\"KMD\"}"
echo "29049.45748125 <- expected amount RH7tsX9PaKECxSEALpu5EWdmEKikY7R2n1"
# RYHxrTNpqrAHRbULboJVYHWqmnmVhzzrot KMD 4840.60793162
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RYHxrTNpqrAHRbULboJVYHWqmnmVhzzrot\",\"symbol\":\"KMD\"}"
echo "4840.60793162 <- expected amount RYHxrTNpqrAHRbULboJVYHWqmnmVhzzrot"
# RLCEGw7zmAhZQYtP23Z2TD45gAT9ZuZKct KMD 2420.78812342
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RLCEGw7zmAhZQYtP23Z2TD45gAT9ZuZKct\",\"symbol\":\"KMD\"}"
echo "2420.78812342 <- expected amount RLCEGw7zmAhZQYtP23Z2TD45gAT9ZuZKct"
# RGQmMzmUfa6R5dZvvL5wvy2vxPLEcgkkyC KMD 137.73071692, REVS 2.73426759
# RGQmMzmUfa6R5dZvvL5wvy2vxPLEcgkkyC KMD 137.73071692
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RGQmMzmUfa6R5dZvvL5wvy2vxPLEcgkkyC\",\"symbol\":\"KMD\"}"
echo "137.73071692 <- expected amount RGQmMzmUfa6R5dZvvL5wvy2vxPLEcgkkyC"
# RRdDD2YoR5cfwktePGGFT5cEyRcWkEjzvM KMD 9737.34607711
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RRdDD2YoR5cfwktePGGFT5cEyRcWkEjzvM\",\"symbol\":\"KMD\"}"
echo "9737.34607711 <- expected amount RRdDD2YoR5cfwktePGGFT5cEyRcWkEjzvM"
# RKbb9NGB3pU2BaByoDwyZDH74E7koR2Lga KMD 1903.31162313
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RKbb9NGB3pU2BaByoDwyZDH74E7koR2Lga\",\"symbol\":\"KMD\"}"
echo "1903.31162313 <- expected amount RKbb9NGB3pU2BaByoDwyZDH74E7koR2Lga"
# RQsSsmpzFagxRaYk6cTMpNHa4eYLihKn8h KMD 99.84182062
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RQsSsmpzFagxRaYk6cTMpNHa4eYLihKn8h\",\"symbol\":\"KMD\"}"
echo "99.84182062 <- expected amount RQsSsmpzFagxRaYk6cTMpNHa4eYLihKn8h"
# RKQPNcePppEkV4CMXZrwqEMAvRHbruKVdF KMD 1167.24851677
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RKQPNcePppEkV4CMXZrwqEMAvRHbruKVdF\",\"symbol\":\"KMD\"}"
echo "1167.24851677 <- expected amount RKQPNcePppEkV4CMXZrwqEMAvRHbruKVdF"
# RHKuiEoakr9yeWQT9UZzCrqPgR8MPBaGvD KMD 15095.38306803
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RHKuiEoakr9yeWQT9UZzCrqPgR8MPBaGvD\",\"symbol\":\"KMD\"}"
echo "15095.38306803 <- expected amount RHKuiEoakr9yeWQT9UZzCrqPgR8MPBaGvD"

64
iguana/tests/KMD.batch10.txids

@ -0,0 +1,64 @@
8b0336f166b8b6348c7af6b382ba5d5f4aa6e266922b19725e79290ee9839bf2
6266.43352646 <- expected amount RQC6A3SKtLb2zmqDDwFvRH6Zz4mZufmp3d
f88163328ebfd735ffe40077fadb0fb8b79020943a8e5822b47fba735a4a20a2
1203.04246569 <- expected amount R9SpRcd2KRD45B7SqzuUFhNnsnx7YqgkN6
af967b9d98defc983047da835bd783fe66b527292052acf56197456344431826
9683.15249375 <- expected amount RCA8H1npFPW5pnJRzycF8tFEJmn6XZhD4j
fedd862fdf4749676410a4b7babf3139c6cf624fd8f6c9620fd95256a7300600
306877.42641191 <- expected amount RTJXwRhuAH9iyztyuRuGC8G7DamTgSMGvT
97cae9d83eadecc26cacd272880bd5120bb66aa3df3a65f37d53793c9c1d3154
150.23706901 <- expected amount RQantoJxT8szwfAqUM3enLPe85YiQtwndH
d641a19ecb1f4d0e5938a18e794ab3b3931f12669e952b40ccadad71c29b7f09
1985.04626121 <- expected amount RLvvwtBUupmGDy81CJNp6RxKbxxbuu3jRY
f14d32323d2f001a2bf6ca8b88c3a15252a71d80174d6390c61902d06d5f4b84
1664.32251109 <- expected amount RFdRKqe82MmvSxZQjgtLfzdf8mNHztKpPE
fcda442735f5627876d069940adc2448f3ba60024a214f48cbbc88123167961d
5.99800973 <- expected amount RE1NYFqFG2vmhhHVY7QFC7sTp7zBxvSSP3
f13e4009f2c3fa3c4f97a0798f1bf1e3df0a4f8470613a125683bd052b1d94ae
9671.53271075 <- expected amount RNYMy1joru9gFitzokTSi5qFFc5nS4iFxc
edb2103b5a7577241d8d3cc7564426b6230ed9ed6a26b0a43cc8ec09d5a76bf3
40223.19497203 <- expected amount RF4jZsF5BUckQqX5hsS68kjQMYSba8Fypm
8cdc1454b6f872eac3d95c95295816678f1bcb759bc8a7134399951c2b4d0a2f
72698.53877152 <- expected amount RPqAFgwnB1hjae6Ar4Kms973uS93HbDkoB
70ea0803296924e353f9c21a3a24b9167868b84219610f6b0e5544622ade573d
9683.15249375 <- expected amount RVzFdNGRn8Ekr4XaeDSfE9fjqvKdcVicJe
df969fd9a0676e0a51c132432fd67fc1dba5e3fa6049bc1c81a0f3d2d32f1bf6
3532.13792522 <- expected amount RTbTzn7FGJWwrH1E3fMwuZPs3YVH1MvVoB
1b06ade94bbc568b7fd6d9a5eb786aa05df77956c4dc3012fff2225dc3338b3c
309.69366537 <- expected amount RDdUQ5t6SYYGZUdAxBk5i7QdTWvzAshxNZ
6356a4dd940d6e859b58fe866eacd8ff58f2d68ae46eec4376e722a26a7fa542
3873.26099750 <- expected amount RYYgc5UD7X18E6CrDXCs1cts5WDwaWhm1Z
dea38f0d030f416d7030c8531b23fedd559410f82f23d4927e62ec3b987406fe
62053.93460050 <- expected amount RXdBJ5cWDcS38ykuggEQZh3vSztxwmG3ut
f0c32f919b860494e924953cbb8c18b7ebc48579eca47ca1f42212afa8471b89
6506.14889316 <- expected amount REKnBAyZMnhKzRozzcuv6fKRtoBsKTFYjs
ce24b5ff26df4d10e2a34dfaa00949e6eab54c921d5be815c39b0dec50a7aac1
812.78437655 <- expected amount RY422uSvkAoZy81uGot5PmXuMrtChhJ3uL
d301f1d220d66363aa9c8a4ce2ae3ff24b7b554577e862a8f4a0fa3650c87591
1452.47287406 <- expected amount R9o3CQms16CLu63j9WdqsaWB3XsssRXEq8
50b56b7eaa17403473c107706ca4f7d15dc43907e643ff70b9613476e9a88a1a
867.82549038 <- expected amount RWTfFTP7c9WxLhgxd2EXSsKszpDVPXHN8A
48de26c072cc1792774528721c912b9c88245ecad1e8cc8c0e18d9b030dc483e
693.08132289 <- expected amount RHJ55iWUQNbKcSn8shbv1RbGuip3RSRHFv
4faf242258a3b3a78f2e4d4217370c5bc1bd836990e4889f74c040cad2aaabfb
8521.17419450 <- expected amount RCfBinKfJ1wGSxXLPNTmC9bohFRoofUiVm
00f9410471f1953fa2379f9add97d377c0618ed03a489fbff2c2b4d2a41e59c3
5328.53865807 <- expected amount RNEZRHeWE3KgSTUr3qvH7RNvM2JWZZkygM
8cf3efea2f6972a7e04b6d75478e54e6667fe8f88effc8a20b38f9dbbc9b03e7
29049.45748125 <- expected amount RH7tsX9PaKECxSEALpu5EWdmEKikY7R2n1
12f13b23bfbb519a7e2c18c7d4826ab702eee8769f4f27914e9d3b6c13b7c315
4840.60793162 <- expected amount RYHxrTNpqrAHRbULboJVYHWqmnmVhzzrot
62315b5822e8b04541cbb0db97dcd65b93ab3b95c6ef5d6aebf3a8efa4ea55d1
2420.78812342 <- expected amount RLCEGw7zmAhZQYtP23Z2TD45gAT9ZuZKct
3c45078d8bf67b966d4dd73a12a9963ae0638fae5af4f2a49de6f54bf507d9de
137.73071692 <- expected amount RGQmMzmUfa6R5dZvvL5wvy2vxPLEcgkkyC
5e4daa037126cd384ec76452baa4a8388c468fd6e81d1f72b249b8de922fd403
9737.34607711 <- expected amount RRdDD2YoR5cfwktePGGFT5cEyRcWkEjzvM
5ab178d63a2d12f5d8c906e9de598708284d0d9e13da61dd5658dc5f5040755b
1903.31162313 <- expected amount RKbb9NGB3pU2BaByoDwyZDH74E7koR2Lga
8ba4ff8dcfda0490c7927afb042768de0ea8d9f8eea89112430bc8363c736703
99.84182062 <- expected amount RQsSsmpzFagxRaYk6cTMpNHa4eYLihKn8h
7d9c76b94c599a9cb2a0aa5301d722186fc130ac883929ef6952d9cf95e2fbd0
1167.24851677 <- expected amount RKQPNcePppEkV4CMXZrwqEMAvRHbruKVdF
7e291c577c4695ae3a6363ff9091d3e1f2d61d3038e324c0222677ec8cf27aee
15095.38306803 <- expected amount RHKuiEoakr9yeWQT9UZzCrqPgR8MPBaGvD

191
iguana/tests/KMD.batch11

@ -0,0 +1,191 @@
sleep 99999
# RWTfFTP7c9WxLhgxd2EXSsKszpDVPXHN8A KMD 42.40642295
./komodo-cli sendtoaddress RWTfFTP7c9WxLhgxd2EXSsKszpDVPXHN8A 42.40642295
sleep 3
echo "42.40642295 <- expected amount RWTfFTP7c9WxLhgxd2EXSsKszpDVPXHN8A"
# RMnuGgpEzWcxYi861E7BjGMURCFX2Szj2v KMD 1248.93505747
./komodo-cli sendtoaddress RMnuGgpEzWcxYi861E7BjGMURCFX2Szj2v 1248.93505747
sleep 3
echo "1248.93505747 <- expected amount RMnuGgpEzWcxYi861E7BjGMURCFX2Szj2v"
# RC8jWr1QQsRyo1pDkue8AxGs58Wyz4F3wZ KMD 2684.14739323
./komodo-cli sendtoaddress RC8jWr1QQsRyo1pDkue8AxGs58Wyz4F3wZ 2684.14739323
sleep 3
echo "2684.14739323 <- expected amount RC8jWr1QQsRyo1pDkue8AxGs58Wyz4F3wZ"
# RTUWRmRe543k8vrwuRXQ7BkFhkK4i2dq5A KMD 19366.30498750
./komodo-cli sendtoaddress RTUWRmRe543k8vrwuRXQ7BkFhkK4i2dq5A 19366.30498750
sleep 3
echo "19366.30498750 <- expected amount RTUWRmRe543k8vrwuRXQ7BkFhkK4i2dq5A"
# RPqAFgwnB1hjae6Ar4Kms973uS93HbDkoB KMD 209558.53271075
./komodo-cli sendtoaddress RPqAFgwnB1hjae6Ar4Kms973uS93HbDkoB 209558.53271075
sleep 3
echo "209558.53271075 <- expected amount RPqAFgwnB1hjae6Ar4Kms973uS93HbDkoB"
# RNW6Kkcdktbeemd2n8NVPCfgnRirzWoiZY KMD 32675.00548454
./komodo-cli sendtoaddress RNW6Kkcdktbeemd2n8NVPCfgnRirzWoiZY 32675.00548454
sleep 3
echo "32675.00548454 <- expected amount RNW6Kkcdktbeemd2n8NVPCfgnRirzWoiZY"
# RNUw6ePdaQ4mXSo9koqGtMDzEC43gCvDrK KMD 15037.55193116
./komodo-cli sendtoaddress RNUw6ePdaQ4mXSo9koqGtMDzEC43gCvDrK 15037.55193116
sleep 3
echo "15037.55193116 <- expected amount RNUw6ePdaQ4mXSo9koqGtMDzEC43gCvDrK"
# RLu6gRHKwXjvv64QZGiLT7uHEVRrH9mHDn KMD 1022.54090334
./komodo-cli sendtoaddress RLu6gRHKwXjvv64QZGiLT7uHEVRrH9mHDn 1022.54090334
sleep 3
echo "1022.54090334 <- expected amount RLu6gRHKwXjvv64QZGiLT7uHEVRrH9mHDn"
# RTJXwRhuAH9iyztyuRuGC8G7DamTgSMGvT KMD 172688.45447080
./komodo-cli sendtoaddress RTJXwRhuAH9iyztyuRuGC8G7DamTgSMGvT 172688.45447080
sleep 3
echo "172688.45447080 <- expected amount RTJXwRhuAH9iyztyuRuGC8G7DamTgSMGvT"
# RDKb3QykRJNfLKWLcbbv9z7xqbtxwB54GC KMD 35255.61377633
./komodo-cli sendtoaddress RDKb3QykRJNfLKWLcbbv9z7xqbtxwB54GC 35255.61377633
sleep 3
echo "35255.61377633 <- expected amount RDKb3QykRJNfLKWLcbbv9z7xqbtxwB54GC"
# RH7cfyUkBwrLbxfWBggcbV3UgzaAHyy3J8 KMD 4509.36353351
./komodo-cli sendtoaddress RH7cfyUkBwrLbxfWBggcbV3UgzaAHyy3J8 4509.36353351
sleep 3
echo "4509.36353351 <- expected amount RH7cfyUkBwrLbxfWBggcbV3UgzaAHyy3J8"
# RCSH7RtDM51e346niSiUk9HiYDrDiqcyev KMD 8622.26398257
./komodo-cli sendtoaddress RCSH7RtDM51e346niSiUk9HiYDrDiqcyev 8622.26398257
sleep 3
echo "8622.26398257 <- expected amount RCSH7RtDM51e346niSiUk9HiYDrDiqcyev"
# RBYMsuS89HQKxNCZB3xb1UxRyfLMLvrbmc KMD 1904.65394401, REVS 37.80134078
# RBYMsuS89HQKxNCZB3xb1UxRyfLMLvrbmc KMD 1904.65394401
./komodo-cli sendtoaddress RBYMsuS89HQKxNCZB3xb1UxRyfLMLvrbmc 1904.65394401
sleep 3
echo "1904.65394401 <- expected amount RBYMsuS89HQKxNCZB3xb1UxRyfLMLvrbmc"
# RUr4x8gjCU9EmbLWpYBdsJDyt1oye52iog KMD 1894.96063707
./komodo-cli sendtoaddress RUr4x8gjCU9EmbLWpYBdsJDyt1oye52iog 1894.96063707
sleep 3
echo "1894.96063707 <- expected amount RUr4x8gjCU9EmbLWpYBdsJDyt1oye52iog"
# RBW6wjWoEsu22APzSfJemWi96bQZFJvEGZ KMD 55379.83556127
./komodo-cli sendtoaddress RBW6wjWoEsu22APzSfJemWi96bQZFJvEGZ 55379.83556127
sleep 3
echo "55379.83556127 <- expected amount RBW6wjWoEsu22APzSfJemWi96bQZFJvEGZ"
# RAMvDwi58oyArqfGseWZsYbR2BN3L7ghVX KMD 109.47952512
./komodo-cli sendtoaddress RAMvDwi58oyArqfGseWZsYbR2BN3L7ghVX 109.47952512
sleep 3
echo "109.47952512 <- expected amount RAMvDwi58oyArqfGseWZsYbR2BN3L7ghVX"
# RXs11ZkaMLV9ZVAJ93LNjF4TRri2QBHn4J KMD 2903.00911762
./komodo-cli sendtoaddress RXs11ZkaMLV9ZVAJ93LNjF4TRri2QBHn4J 2903.00911762
sleep 3
echo "2903.00911762 <- expected amount RXs11ZkaMLV9ZVAJ93LNjF4TRri2QBHn4J"
# RHy56MTg74v8AY1Eo2RgbohbMbdHjUDN47 KMD 8344.85486318
./komodo-cli sendtoaddress RHy56MTg74v8AY1Eo2RgbohbMbdHjUDN47 8344.85486318
sleep 3
echo "8344.85486318 <- expected amount RHy56MTg74v8AY1Eo2RgbohbMbdHjUDN47"
# RQM36oUWQFipUvhPnyoNr8f8CgmJ6W6HR3 KMD 9295.82639400
./komodo-cli sendtoaddress RQM36oUWQFipUvhPnyoNr8f8CgmJ6W6HR3 9295.82639400
sleep 3
echo "9295.82639400 <- expected amount RQM36oUWQFipUvhPnyoNr8f8CgmJ6W6HR3"
# RLyaf3XgjHruSeJd4oj83E8btck7kYPmVz KMD 5784.90308850
./komodo-cli sendtoaddress RLyaf3XgjHruSeJd4oj83E8btck7kYPmVz 5784.90308850
sleep 3
echo "5784.90308850 <- expected amount RLyaf3XgjHruSeJd4oj83E8btck7kYPmVz"
# RFkDDs1eZCQmAKknvyrP5XbpyeaihFaFL2 KMD 4345.79883919
./komodo-cli sendtoaddress RFkDDs1eZCQmAKknvyrP5XbpyeaihFaFL2 4345.79883919
sleep 3
echo "4345.79883919 <- expected amount RFkDDs1eZCQmAKknvyrP5XbpyeaihFaFL2"
# RQgfzPR4zeCyLWaddHysGEVzoKLZa5E4Ut KMD 5743.12343812
./komodo-cli sendtoaddress RQgfzPR4zeCyLWaddHysGEVzoKLZa5E4Ut 5743.12343812
sleep 3
echo "5743.12343812 <- expected amount RQgfzPR4zeCyLWaddHysGEVzoKLZa5E4Ut"
# RTSn55yrw2xUWM8bxVcG84ga84dofPfsuD KMD 9680.24754799
./komodo-cli sendtoaddress RTSn55yrw2xUWM8bxVcG84ga84dofPfsuD 9680.24754799
sleep 3
echo "9680.24754799 <- expected amount RTSn55yrw2xUWM8bxVcG84ga84dofPfsuD"
# RBboFD6fhYF11C883DxvLx5dDmbbs73XC3 KMD 1819.54181879
./komodo-cli sendtoaddress RBboFD6fhYF11C883DxvLx5dDmbbs73XC3 1819.54181879
sleep 3
echo "1819.54181879 <- expected amount RBboFD6fhYF11C883DxvLx5dDmbbs73XC3"
# RCKVUKnC3pjVkjnDfnBj1Eu68yc8ELdMC5 KMD 863.61179282, REVS 0.91962079
# RCKVUKnC3pjVkjnDfnBj1Eu68yc8ELdMC5 KMD 863.61179282
./komodo-cli sendtoaddress RCKVUKnC3pjVkjnDfnBj1Eu68yc8ELdMC5 863.61179282
sleep 3
echo "863.61179282 <- expected amount RCKVUKnC3pjVkjnDfnBj1Eu68yc8ELdMC5"
# RU3EDov1PTPAY8WhG5eGUANp2rvtki1yc9 KMD 0.00050130
./komodo-cli sendtoaddress RU3EDov1PTPAY8WhG5eGUANp2rvtki1yc9 0.00050130
sleep 3
echo "0.00050130 <- expected amount RU3EDov1PTPAY8WhG5eGUANp2rvtki1yc9"
# RHJ55iWUQNbKcSn8shbv1RbGuip3RSRHFv KMD 693.08132289
./komodo-cli sendtoaddress RHJ55iWUQNbKcSn8shbv1RbGuip3RSRHFv 693.08132289
sleep 3
echo "693.08132289 <- expected amount RHJ55iWUQNbKcSn8shbv1RbGuip3RSRHFv"
# RUrV1qvjBapCDGQnwpdhyneGhX1wiHZwVr KMD 16087.76566759, REVS 319.20361833
# RUrV1qvjBapCDGQnwpdhyneGhX1wiHZwVr KMD 16087.76566759
./komodo-cli sendtoaddress RUrV1qvjBapCDGQnwpdhyneGhX1wiHZwVr 16087.76566759
sleep 3
echo "16087.76566759 <- expected amount RUrV1qvjBapCDGQnwpdhyneGhX1wiHZwVr"
# R9V8qEoa5zjgoJ2kDARXTyhjjvkzcTANC5 KMD 5577.49583640
./komodo-cli sendtoaddress R9V8qEoa5zjgoJ2kDARXTyhjjvkzcTANC5 5577.49583640
sleep 3
echo "5577.49583640 <- expected amount R9V8qEoa5zjgoJ2kDARXTyhjjvkzcTANC5"
# RJJdqon3kYcXtyiTujiHBxAMj9QXrgfUbw KMD 774.65219950
./komodo-cli sendtoaddress RJJdqon3kYcXtyiTujiHBxAMj9QXrgfUbw 774.65219950
sleep 3
echo "774.65219950 <- expected amount RJJdqon3kYcXtyiTujiHBxAMj9QXrgfUbw"
# RNqJvqLSS9zpCJYFv8gDPgeUBx72Hk4as2 KMD 13362.75044137
./komodo-cli sendtoaddress RNqJvqLSS9zpCJYFv8gDPgeUBx72Hk4as2 13362.75044137
sleep 3
echo "13362.75044137 <- expected amount RNqJvqLSS9zpCJYFv8gDPgeUBx72Hk4as2"
# RH8i5cGy1QMK2sTehLEAqjX2Ph8FJ94LWJ KMD 8569.02441659
./komodo-cli sendtoaddress RH8i5cGy1QMK2sTehLEAqjX2Ph8FJ94LWJ 8569.02441659
sleep 3
echo "8569.02441659 <- expected amount RH8i5cGy1QMK2sTehLEAqjX2Ph8FJ94LWJ"
# RCEXKrX2kkQQrFu6arLBLNYYZFtdgHwATt KMD 9683.15249375
./komodo-cli sendtoaddress RCEXKrX2kkQQrFu6arLBLNYYZFtdgHwATt 9683.15249375
sleep 3
echo "9683.15249375 <- expected amount RCEXKrX2kkQQrFu6arLBLNYYZFtdgHwATt"
# RE3f1f5XQsntqQkwpVZwyzr1YbupdPbjiS KMD 7916.77211172
./komodo-cli sendtoaddress RE3f1f5XQsntqQkwpVZwyzr1YbupdPbjiS 7916.77211172
sleep 3
echo "7916.77211172 <- expected amount RE3f1f5XQsntqQkwpVZwyzr1YbupdPbjiS"
# RWoKDt8BzEQc3WtYUpXmCxRwB1Tg3AWcPR KMD 722.28571081
./komodo-cli sendtoaddress RWoKDt8BzEQc3WtYUpXmCxRwB1Tg3AWcPR 722.28571081
sleep 3
echo "722.28571081 <- expected amount RWoKDt8BzEQc3WtYUpXmCxRwB1Tg3AWcPR"
# RNwfApozgMUmKvJCdrJWQZZCw3hEUWaNk1 KMD 709.73247788
./komodo-cli sendtoaddress RNwfApozgMUmKvJCdrJWQZZCw3hEUWaNk1 709.73247788
sleep 3
echo "709.73247788 <- expected amount RNwfApozgMUmKvJCdrJWQZZCw3hEUWaNk1"
# RKQPNcePppEkV4CMXZrwqEMAvRHbruKVdF KMD 419.36278156
./komodo-cli sendtoaddress RKQPNcePppEkV4CMXZrwqEMAvRHbruKVdF 419.36278156
sleep 3
echo "419.36278156 <- expected amount RKQPNcePppEkV4CMXZrwqEMAvRHbruKVdF"
# total KMD 675297.04318319 REVS 0.00000000

188
iguana/tests/KMD.batch11.importaddress

@ -0,0 +1,188 @@
# RWTfFTP7c9WxLhgxd2EXSsKszpDVPXHN8A KMD 42.40642295
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RWTfFTP7c9WxLhgxd2EXSsKszpDVPXHN8A\",\"symbol\":\"KMD\"}" # 42.40642295
sleep 3
echo "42.40642295 <- expected amount RWTfFTP7c9WxLhgxd2EXSsKszpDVPXHN8A"
# RMnuGgpEzWcxYi861E7BjGMURCFX2Szj2v KMD 1248.93505747
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RMnuGgpEzWcxYi861E7BjGMURCFX2Szj2v\",\"symbol\":\"KMD\"}" # 1248.93505747
sleep 3
echo "1248.93505747 <- expected amount RMnuGgpEzWcxYi861E7BjGMURCFX2Szj2v"
# RC8jWr1QQsRyo1pDkue8AxGs58Wyz4F3wZ KMD 2684.14739323
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RC8jWr1QQsRyo1pDkue8AxGs58Wyz4F3wZ\",\"symbol\":\"KMD\"}" # 2684.14739323
sleep 3
echo "2684.14739323 <- expected amount RC8jWr1QQsRyo1pDkue8AxGs58Wyz4F3wZ"
# RTUWRmRe543k8vrwuRXQ7BkFhkK4i2dq5A KMD 19366.30498750
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RTUWRmRe543k8vrwuRXQ7BkFhkK4i2dq5A\",\"symbol\":\"KMD\"}" # 19366.30498750
sleep 3
echo "19366.30498750 <- expected amount RTUWRmRe543k8vrwuRXQ7BkFhkK4i2dq5A"
# RPqAFgwnB1hjae6Ar4Kms973uS93HbDkoB KMD 209558.53271075
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RPqAFgwnB1hjae6Ar4Kms973uS93HbDkoB\",\"symbol\":\"KMD\"}" # 209558.53271075
sleep 3
echo "209558.53271075 <- expected amount RPqAFgwnB1hjae6Ar4Kms973uS93HbDkoB"
# RNW6Kkcdktbeemd2n8NVPCfgnRirzWoiZY KMD 32675.00548454
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RNW6Kkcdktbeemd2n8NVPCfgnRirzWoiZY\",\"symbol\":\"KMD\"}" # 32675.00548454
sleep 3
echo "32675.00548454 <- expected amount RNW6Kkcdktbeemd2n8NVPCfgnRirzWoiZY"
# RNUw6ePdaQ4mXSo9koqGtMDzEC43gCvDrK KMD 15037.55193116
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RNUw6ePdaQ4mXSo9koqGtMDzEC43gCvDrK\",\"symbol\":\"KMD\"}" # 15037.55193116
sleep 3
echo "15037.55193116 <- expected amount RNUw6ePdaQ4mXSo9koqGtMDzEC43gCvDrK"
# RLu6gRHKwXjvv64QZGiLT7uHEVRrH9mHDn KMD 1022.54090334
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RLu6gRHKwXjvv64QZGiLT7uHEVRrH9mHDn\",\"symbol\":\"KMD\"}" # 1022.54090334
sleep 3
echo "1022.54090334 <- expected amount RLu6gRHKwXjvv64QZGiLT7uHEVRrH9mHDn"
# RTJXwRhuAH9iyztyuRuGC8G7DamTgSMGvT KMD 172688.45447080
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RTJXwRhuAH9iyztyuRuGC8G7DamTgSMGvT\",\"symbol\":\"KMD\"}" # 172688.45447080
sleep 3
echo "172688.45447080 <- expected amount RTJXwRhuAH9iyztyuRuGC8G7DamTgSMGvT"
# RDKb3QykRJNfLKWLcbbv9z7xqbtxwB54GC KMD 35255.61377633
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RDKb3QykRJNfLKWLcbbv9z7xqbtxwB54GC\",\"symbol\":\"KMD\"}" # 35255.61377633
sleep 3
echo "35255.61377633 <- expected amount RDKb3QykRJNfLKWLcbbv9z7xqbtxwB54GC"
# RH7cfyUkBwrLbxfWBggcbV3UgzaAHyy3J8 KMD 4509.36353351
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RH7cfyUkBwrLbxfWBggcbV3UgzaAHyy3J8\",\"symbol\":\"KMD\"}" # 4509.36353351
sleep 3
echo "4509.36353351 <- expected amount RH7cfyUkBwrLbxfWBggcbV3UgzaAHyy3J8"
# RCSH7RtDM51e346niSiUk9HiYDrDiqcyev KMD 8622.26398257
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RCSH7RtDM51e346niSiUk9HiYDrDiqcyev\",\"symbol\":\"KMD\"}" # 8622.26398257
sleep 3
echo "8622.26398257 <- expected amount RCSH7RtDM51e346niSiUk9HiYDrDiqcyev"
# RBYMsuS89HQKxNCZB3xb1UxRyfLMLvrbmc KMD 1904.65394401, REVS 37.80134078
# RBYMsuS89HQKxNCZB3xb1UxRyfLMLvrbmc KMD 1904.65394401
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RBYMsuS89HQKxNCZB3xb1UxRyfLMLvrbmc\",\"symbol\":\"KMD\"}" # 1904.65394401
sleep 3
echo "1904.65394401 <- expected amount RBYMsuS89HQKxNCZB3xb1UxRyfLMLvrbmc"
# RUr4x8gjCU9EmbLWpYBdsJDyt1oye52iog KMD 1894.96063707
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RUr4x8gjCU9EmbLWpYBdsJDyt1oye52iog\",\"symbol\":\"KMD\"}" # 1894.96063707
sleep 3
echo "1894.96063707 <- expected amount RUr4x8gjCU9EmbLWpYBdsJDyt1oye52iog"
# RBW6wjWoEsu22APzSfJemWi96bQZFJvEGZ KMD 55379.83556127
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RBW6wjWoEsu22APzSfJemWi96bQZFJvEGZ\",\"symbol\":\"KMD\"}" # 55379.83556127
sleep 3
echo "55379.83556127 <- expected amount RBW6wjWoEsu22APzSfJemWi96bQZFJvEGZ"
# RAMvDwi58oyArqfGseWZsYbR2BN3L7ghVX KMD 109.47952512
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RAMvDwi58oyArqfGseWZsYbR2BN3L7ghVX\",\"symbol\":\"KMD\"}" # 109.47952512
sleep 3
echo "109.47952512 <- expected amount RAMvDwi58oyArqfGseWZsYbR2BN3L7ghVX"
# RXs11ZkaMLV9ZVAJ93LNjF4TRri2QBHn4J KMD 2903.00911762
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RXs11ZkaMLV9ZVAJ93LNjF4TRri2QBHn4J\",\"symbol\":\"KMD\"}" # 2903.00911762
sleep 3
echo "2903.00911762 <- expected amount RXs11ZkaMLV9ZVAJ93LNjF4TRri2QBHn4J"
# RHy56MTg74v8AY1Eo2RgbohbMbdHjUDN47 KMD 8344.85486318
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RHy56MTg74v8AY1Eo2RgbohbMbdHjUDN47\",\"symbol\":\"KMD\"}" # 8344.85486318
sleep 3
echo "8344.85486318 <- expected amount RHy56MTg74v8AY1Eo2RgbohbMbdHjUDN47"
# RQM36oUWQFipUvhPnyoNr8f8CgmJ6W6HR3 KMD 9295.82639400
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RQM36oUWQFipUvhPnyoNr8f8CgmJ6W6HR3\",\"symbol\":\"KMD\"}" # 9295.82639400
sleep 3
echo "9295.82639400 <- expected amount RQM36oUWQFipUvhPnyoNr8f8CgmJ6W6HR3"
# RLyaf3XgjHruSeJd4oj83E8btck7kYPmVz KMD 5784.90308850
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RLyaf3XgjHruSeJd4oj83E8btck7kYPmVz\",\"symbol\":\"KMD\"}" # 5784.90308850
sleep 3
echo "5784.90308850 <- expected amount RLyaf3XgjHruSeJd4oj83E8btck7kYPmVz"
# RFkDDs1eZCQmAKknvyrP5XbpyeaihFaFL2 KMD 4345.79883919
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RFkDDs1eZCQmAKknvyrP5XbpyeaihFaFL2\",\"symbol\":\"KMD\"}" # 4345.79883919
sleep 3
echo "4345.79883919 <- expected amount RFkDDs1eZCQmAKknvyrP5XbpyeaihFaFL2"
# RQgfzPR4zeCyLWaddHysGEVzoKLZa5E4Ut KMD 5743.12343812
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RQgfzPR4zeCyLWaddHysGEVzoKLZa5E4Ut\",\"symbol\":\"KMD\"}" # 5743.12343812
sleep 3
echo "5743.12343812 <- expected amount RQgfzPR4zeCyLWaddHysGEVzoKLZa5E4Ut"
# RTSn55yrw2xUWM8bxVcG84ga84dofPfsuD KMD 9680.24754799
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RTSn55yrw2xUWM8bxVcG84ga84dofPfsuD\",\"symbol\":\"KMD\"}" # 9680.24754799
sleep 3
echo "9680.24754799 <- expected amount RTSn55yrw2xUWM8bxVcG84ga84dofPfsuD"
# RBboFD6fhYF11C883DxvLx5dDmbbs73XC3 KMD 1819.54181879
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RBboFD6fhYF11C883DxvLx5dDmbbs73XC3\",\"symbol\":\"KMD\"}" # 1819.54181879
sleep 3
echo "1819.54181879 <- expected amount RBboFD6fhYF11C883DxvLx5dDmbbs73XC3"
# RCKVUKnC3pjVkjnDfnBj1Eu68yc8ELdMC5 KMD 863.61179282, REVS 0.91962079
# RCKVUKnC3pjVkjnDfnBj1Eu68yc8ELdMC5 KMD 863.61179282
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RCKVUKnC3pjVkjnDfnBj1Eu68yc8ELdMC5\",\"symbol\":\"KMD\"}" # 863.61179282
sleep 3
echo "863.61179282 <- expected amount RCKVUKnC3pjVkjnDfnBj1Eu68yc8ELdMC5"
# RU3EDov1PTPAY8WhG5eGUANp2rvtki1yc9 KMD 0.00050130
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RU3EDov1PTPAY8WhG5eGUANp2rvtki1yc9\",\"symbol\":\"KMD\"}" # 0.00050130
sleep 3
echo "0.00050130 <- expected amount RU3EDov1PTPAY8WhG5eGUANp2rvtki1yc9"
# RHJ55iWUQNbKcSn8shbv1RbGuip3RSRHFv KMD 693.08132289
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RHJ55iWUQNbKcSn8shbv1RbGuip3RSRHFv\",\"symbol\":\"KMD\"}" # 693.08132289
sleep 3
echo "693.08132289 <- expected amount RHJ55iWUQNbKcSn8shbv1RbGuip3RSRHFv"
# RUrV1qvjBapCDGQnwpdhyneGhX1wiHZwVr KMD 16087.76566759, REVS 319.20361833
# RUrV1qvjBapCDGQnwpdhyneGhX1wiHZwVr KMD 16087.76566759
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RUrV1qvjBapCDGQnwpdhyneGhX1wiHZwVr\",\"symbol\":\"KMD\"}" # 16087.76566759
sleep 3
echo "16087.76566759 <- expected amount RUrV1qvjBapCDGQnwpdhyneGhX1wiHZwVr"
# R9V8qEoa5zjgoJ2kDARXTyhjjvkzcTANC5 KMD 5577.49583640
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"R9V8qEoa5zjgoJ2kDARXTyhjjvkzcTANC5\",\"symbol\":\"KMD\"}" # 5577.49583640
sleep 3
echo "5577.49583640 <- expected amount R9V8qEoa5zjgoJ2kDARXTyhjjvkzcTANC5"
# RJJdqon3kYcXtyiTujiHBxAMj9QXrgfUbw KMD 774.65219950
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RJJdqon3kYcXtyiTujiHBxAMj9QXrgfUbw\",\"symbol\":\"KMD\"}" # 774.65219950
sleep 3
echo "774.65219950 <- expected amount RJJdqon3kYcXtyiTujiHBxAMj9QXrgfUbw"
# RNqJvqLSS9zpCJYFv8gDPgeUBx72Hk4as2 KMD 13362.75044137
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RNqJvqLSS9zpCJYFv8gDPgeUBx72Hk4as2\",\"symbol\":\"KMD\"}" # 13362.75044137
sleep 3
echo "13362.75044137 <- expected amount RNqJvqLSS9zpCJYFv8gDPgeUBx72Hk4as2"
# RH8i5cGy1QMK2sTehLEAqjX2Ph8FJ94LWJ KMD 8569.02441659
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RH8i5cGy1QMK2sTehLEAqjX2Ph8FJ94LWJ\",\"symbol\":\"KMD\"}" # 8569.02441659
sleep 3
echo "8569.02441659 <- expected amount RH8i5cGy1QMK2sTehLEAqjX2Ph8FJ94LWJ"
# RCEXKrX2kkQQrFu6arLBLNYYZFtdgHwATt KMD 9683.15249375
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RCEXKrX2kkQQrFu6arLBLNYYZFtdgHwATt\",\"symbol\":\"KMD\"}" # 9683.15249375
sleep 3
echo "9683.15249375 <- expected amount RCEXKrX2kkQQrFu6arLBLNYYZFtdgHwATt"
# RE3f1f5XQsntqQkwpVZwyzr1YbupdPbjiS KMD 7916.77211172
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RE3f1f5XQsntqQkwpVZwyzr1YbupdPbjiS\",\"symbol\":\"KMD\"}" # 7916.77211172
sleep 3
echo "7916.77211172 <- expected amount RE3f1f5XQsntqQkwpVZwyzr1YbupdPbjiS"
# RWoKDt8BzEQc3WtYUpXmCxRwB1Tg3AWcPR KMD 722.28571081
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RWoKDt8BzEQc3WtYUpXmCxRwB1Tg3AWcPR\",\"symbol\":\"KMD\"}" # 722.28571081
sleep 3
echo "722.28571081 <- expected amount RWoKDt8BzEQc3WtYUpXmCxRwB1Tg3AWcPR"
# RNwfApozgMUmKvJCdrJWQZZCw3hEUWaNk1 KMD 709.73247788
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RNwfApozgMUmKvJCdrJWQZZCw3hEUWaNk1\",\"symbol\":\"KMD\"}" # 709.73247788
sleep 3
echo "709.73247788 <- expected amount RNwfApozgMUmKvJCdrJWQZZCw3hEUWaNk1"
# RKQPNcePppEkV4CMXZrwqEMAvRHbruKVdF KMD 419.36278156
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"importaddress\",\"address\":\"RKQPNcePppEkV4CMXZrwqEMAvRHbruKVdF\",\"symbol\":\"KMD\"}" # 419.36278156
sleep 3
echo "419.36278156 <- expected amount RKQPNcePppEkV4CMXZrwqEMAvRHbruKVdF"

151
iguana/tests/KMD.batch11.listunspent

@ -0,0 +1,151 @@
# RWTfFTP7c9WxLhgxd2EXSsKszpDVPXHN8A KMD 42.40642295
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RWTfFTP7c9WxLhgxd2EXSsKszpDVPXHN8A\",\"symbol\":\"KMD\"}"
echo "42.40642295 <- expected amount RWTfFTP7c9WxLhgxd2EXSsKszpDVPXHN8A"
# RMnuGgpEzWcxYi861E7BjGMURCFX2Szj2v KMD 1248.93505747
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RMnuGgpEzWcxYi861E7BjGMURCFX2Szj2v\",\"symbol\":\"KMD\"}"
echo "1248.93505747 <- expected amount RMnuGgpEzWcxYi861E7BjGMURCFX2Szj2v"
# RC8jWr1QQsRyo1pDkue8AxGs58Wyz4F3wZ KMD 2684.14739323
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RC8jWr1QQsRyo1pDkue8AxGs58Wyz4F3wZ\",\"symbol\":\"KMD\"}"
echo "2684.14739323 <- expected amount RC8jWr1QQsRyo1pDkue8AxGs58Wyz4F3wZ"
# RTUWRmRe543k8vrwuRXQ7BkFhkK4i2dq5A KMD 19366.30498750
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RTUWRmRe543k8vrwuRXQ7BkFhkK4i2dq5A\",\"symbol\":\"KMD\"}"
echo "19366.30498750 <- expected amount RTUWRmRe543k8vrwuRXQ7BkFhkK4i2dq5A"
# RPqAFgwnB1hjae6Ar4Kms973uS93HbDkoB KMD 209558.53271075
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RPqAFgwnB1hjae6Ar4Kms973uS93HbDkoB\",\"symbol\":\"KMD\"}"
echo "209558.53271075 <- expected amount RPqAFgwnB1hjae6Ar4Kms973uS93HbDkoB"
# RNW6Kkcdktbeemd2n8NVPCfgnRirzWoiZY KMD 32675.00548454
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RNW6Kkcdktbeemd2n8NVPCfgnRirzWoiZY\",\"symbol\":\"KMD\"}"
echo "32675.00548454 <- expected amount RNW6Kkcdktbeemd2n8NVPCfgnRirzWoiZY"
# RNUw6ePdaQ4mXSo9koqGtMDzEC43gCvDrK KMD 15037.55193116
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RNUw6ePdaQ4mXSo9koqGtMDzEC43gCvDrK\",\"symbol\":\"KMD\"}"
echo "15037.55193116 <- expected amount RNUw6ePdaQ4mXSo9koqGtMDzEC43gCvDrK"
# RLu6gRHKwXjvv64QZGiLT7uHEVRrH9mHDn KMD 1022.54090334
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RLu6gRHKwXjvv64QZGiLT7uHEVRrH9mHDn\",\"symbol\":\"KMD\"}"
echo "1022.54090334 <- expected amount RLu6gRHKwXjvv64QZGiLT7uHEVRrH9mHDn"
# RTJXwRhuAH9iyztyuRuGC8G7DamTgSMGvT KMD 172688.45447080
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RTJXwRhuAH9iyztyuRuGC8G7DamTgSMGvT\",\"symbol\":\"KMD\"}"
echo "172688.45447080 <- expected amount RTJXwRhuAH9iyztyuRuGC8G7DamTgSMGvT"
# RDKb3QykRJNfLKWLcbbv9z7xqbtxwB54GC KMD 35255.61377633
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RDKb3QykRJNfLKWLcbbv9z7xqbtxwB54GC\",\"symbol\":\"KMD\"}"
echo "35255.61377633 <- expected amount RDKb3QykRJNfLKWLcbbv9z7xqbtxwB54GC"
# RH7cfyUkBwrLbxfWBggcbV3UgzaAHyy3J8 KMD 4509.36353351
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RH7cfyUkBwrLbxfWBggcbV3UgzaAHyy3J8\",\"symbol\":\"KMD\"}"
echo "4509.36353351 <- expected amount RH7cfyUkBwrLbxfWBggcbV3UgzaAHyy3J8"
# RCSH7RtDM51e346niSiUk9HiYDrDiqcyev KMD 8622.26398257
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RCSH7RtDM51e346niSiUk9HiYDrDiqcyev\",\"symbol\":\"KMD\"}"
echo "8622.26398257 <- expected amount RCSH7RtDM51e346niSiUk9HiYDrDiqcyev"
# RBYMsuS89HQKxNCZB3xb1UxRyfLMLvrbmc KMD 1904.65394401, REVS 37.80134078
# RBYMsuS89HQKxNCZB3xb1UxRyfLMLvrbmc KMD 1904.65394401
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RBYMsuS89HQKxNCZB3xb1UxRyfLMLvrbmc\",\"symbol\":\"KMD\"}"
echo "1904.65394401 <- expected amount RBYMsuS89HQKxNCZB3xb1UxRyfLMLvrbmc"
# RUr4x8gjCU9EmbLWpYBdsJDyt1oye52iog KMD 1894.96063707
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RUr4x8gjCU9EmbLWpYBdsJDyt1oye52iog\",\"symbol\":\"KMD\"}"
echo "1894.96063707 <- expected amount RUr4x8gjCU9EmbLWpYBdsJDyt1oye52iog"
# RBW6wjWoEsu22APzSfJemWi96bQZFJvEGZ KMD 55379.83556127
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RBW6wjWoEsu22APzSfJemWi96bQZFJvEGZ\",\"symbol\":\"KMD\"}"
echo "55379.83556127 <- expected amount RBW6wjWoEsu22APzSfJemWi96bQZFJvEGZ"
# RAMvDwi58oyArqfGseWZsYbR2BN3L7ghVX KMD 109.47952512
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RAMvDwi58oyArqfGseWZsYbR2BN3L7ghVX\",\"symbol\":\"KMD\"}"
echo "109.47952512 <- expected amount RAMvDwi58oyArqfGseWZsYbR2BN3L7ghVX"
# RXs11ZkaMLV9ZVAJ93LNjF4TRri2QBHn4J KMD 2903.00911762
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RXs11ZkaMLV9ZVAJ93LNjF4TRri2QBHn4J\",\"symbol\":\"KMD\"}"
echo "2903.00911762 <- expected amount RXs11ZkaMLV9ZVAJ93LNjF4TRri2QBHn4J"
# RHy56MTg74v8AY1Eo2RgbohbMbdHjUDN47 KMD 8344.85486318
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RHy56MTg74v8AY1Eo2RgbohbMbdHjUDN47\",\"symbol\":\"KMD\"}"
echo "8344.85486318 <- expected amount RHy56MTg74v8AY1Eo2RgbohbMbdHjUDN47"
# RQM36oUWQFipUvhPnyoNr8f8CgmJ6W6HR3 KMD 9295.82639400
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RQM36oUWQFipUvhPnyoNr8f8CgmJ6W6HR3\",\"symbol\":\"KMD\"}"
echo "9295.82639400 <- expected amount RQM36oUWQFipUvhPnyoNr8f8CgmJ6W6HR3"
# RLyaf3XgjHruSeJd4oj83E8btck7kYPmVz KMD 5784.90308850
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RLyaf3XgjHruSeJd4oj83E8btck7kYPmVz\",\"symbol\":\"KMD\"}"
echo "5784.90308850 <- expected amount RLyaf3XgjHruSeJd4oj83E8btck7kYPmVz"
# RFkDDs1eZCQmAKknvyrP5XbpyeaihFaFL2 KMD 4345.79883919
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RFkDDs1eZCQmAKknvyrP5XbpyeaihFaFL2\",\"symbol\":\"KMD\"}"
echo "4345.79883919 <- expected amount RFkDDs1eZCQmAKknvyrP5XbpyeaihFaFL2"
# RQgfzPR4zeCyLWaddHysGEVzoKLZa5E4Ut KMD 5743.12343812
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RQgfzPR4zeCyLWaddHysGEVzoKLZa5E4Ut\",\"symbol\":\"KMD\"}"
echo "5743.12343812 <- expected amount RQgfzPR4zeCyLWaddHysGEVzoKLZa5E4Ut"
# RTSn55yrw2xUWM8bxVcG84ga84dofPfsuD KMD 9680.24754799
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RTSn55yrw2xUWM8bxVcG84ga84dofPfsuD\",\"symbol\":\"KMD\"}"
echo "9680.24754799 <- expected amount RTSn55yrw2xUWM8bxVcG84ga84dofPfsuD"
# RBboFD6fhYF11C883DxvLx5dDmbbs73XC3 KMD 1819.54181879
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RBboFD6fhYF11C883DxvLx5dDmbbs73XC3\",\"symbol\":\"KMD\"}"
echo "1819.54181879 <- expected amount RBboFD6fhYF11C883DxvLx5dDmbbs73XC3"
# RCKVUKnC3pjVkjnDfnBj1Eu68yc8ELdMC5 KMD 863.61179282, REVS 0.91962079
# RCKVUKnC3pjVkjnDfnBj1Eu68yc8ELdMC5 KMD 863.61179282
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RCKVUKnC3pjVkjnDfnBj1Eu68yc8ELdMC5\",\"symbol\":\"KMD\"}"
echo "863.61179282 <- expected amount RCKVUKnC3pjVkjnDfnBj1Eu68yc8ELdMC5"
# RU3EDov1PTPAY8WhG5eGUANp2rvtki1yc9 KMD 0.00050130
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RU3EDov1PTPAY8WhG5eGUANp2rvtki1yc9\",\"symbol\":\"KMD\"}"
echo "0.00050130 <- expected amount RU3EDov1PTPAY8WhG5eGUANp2rvtki1yc9"
# RHJ55iWUQNbKcSn8shbv1RbGuip3RSRHFv KMD 693.08132289
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RHJ55iWUQNbKcSn8shbv1RbGuip3RSRHFv\",\"symbol\":\"KMD\"}"
echo "693.08132289 <- expected amount RHJ55iWUQNbKcSn8shbv1RbGuip3RSRHFv"
# RUrV1qvjBapCDGQnwpdhyneGhX1wiHZwVr KMD 16087.76566759, REVS 319.20361833
# RUrV1qvjBapCDGQnwpdhyneGhX1wiHZwVr KMD 16087.76566759
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RUrV1qvjBapCDGQnwpdhyneGhX1wiHZwVr\",\"symbol\":\"KMD\"}"
echo "16087.76566759 <- expected amount RUrV1qvjBapCDGQnwpdhyneGhX1wiHZwVr"
# R9V8qEoa5zjgoJ2kDARXTyhjjvkzcTANC5 KMD 5577.49583640
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"R9V8qEoa5zjgoJ2kDARXTyhjjvkzcTANC5\",\"symbol\":\"KMD\"}"
echo "5577.49583640 <- expected amount R9V8qEoa5zjgoJ2kDARXTyhjjvkzcTANC5"
# RJJdqon3kYcXtyiTujiHBxAMj9QXrgfUbw KMD 774.65219950
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RJJdqon3kYcXtyiTujiHBxAMj9QXrgfUbw\",\"symbol\":\"KMD\"}"
echo "774.65219950 <- expected amount RJJdqon3kYcXtyiTujiHBxAMj9QXrgfUbw"
# RNqJvqLSS9zpCJYFv8gDPgeUBx72Hk4as2 KMD 13362.75044137
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RNqJvqLSS9zpCJYFv8gDPgeUBx72Hk4as2\",\"symbol\":\"KMD\"}"
echo "13362.75044137 <- expected amount RNqJvqLSS9zpCJYFv8gDPgeUBx72Hk4as2"
# RH8i5cGy1QMK2sTehLEAqjX2Ph8FJ94LWJ KMD 8569.02441659
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RH8i5cGy1QMK2sTehLEAqjX2Ph8FJ94LWJ\",\"symbol\":\"KMD\"}"
echo "8569.02441659 <- expected amount RH8i5cGy1QMK2sTehLEAqjX2Ph8FJ94LWJ"
# RCEXKrX2kkQQrFu6arLBLNYYZFtdgHwATt KMD 9683.15249375
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RCEXKrX2kkQQrFu6arLBLNYYZFtdgHwATt\",\"symbol\":\"KMD\"}"
echo "9683.15249375 <- expected amount RCEXKrX2kkQQrFu6arLBLNYYZFtdgHwATt"
# RE3f1f5XQsntqQkwpVZwyzr1YbupdPbjiS KMD 7916.77211172
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RE3f1f5XQsntqQkwpVZwyzr1YbupdPbjiS\",\"symbol\":\"KMD\"}"
echo "7916.77211172 <- expected amount RE3f1f5XQsntqQkwpVZwyzr1YbupdPbjiS"
# RWoKDt8BzEQc3WtYUpXmCxRwB1Tg3AWcPR KMD 722.28571081
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RWoKDt8BzEQc3WtYUpXmCxRwB1Tg3AWcPR\",\"symbol\":\"KMD\"}"
echo "722.28571081 <- expected amount RWoKDt8BzEQc3WtYUpXmCxRwB1Tg3AWcPR"
# RNwfApozgMUmKvJCdrJWQZZCw3hEUWaNk1 KMD 709.73247788
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RNwfApozgMUmKvJCdrJWQZZCw3hEUWaNk1\",\"symbol\":\"KMD\"}"
echo "709.73247788 <- expected amount RNwfApozgMUmKvJCdrJWQZZCw3hEUWaNk1"
# RKQPNcePppEkV4CMXZrwqEMAvRHbruKVdF KMD 419.36278156
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listunspent\",\"address\":\"RKQPNcePppEkV4CMXZrwqEMAvRHbruKVdF\",\"symbol\":\"KMD\"}"
echo "419.36278156 <- expected amount RKQPNcePppEkV4CMXZrwqEMAvRHbruKVdF"

Some files were not shown because too many files changed in this diff

Loading…
Cancel
Save