Browse Source

Merge pull request #674 from jl777/dev

notary testnet
ordermatch percentage improvements
new coins
bug fixes
patch-1
jl777 7 years ago
committed by GitHub
parent
commit
179804dceb
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 24
      basilisk/basilisk.c
  2. 6
      basilisk/basilisk_bitcoin.c
  3. 2
      crypto777/OS_portable.h
  4. 37
      crypto777/iguana_utils.c
  5. 2
      datachain/datachain.c
  6. 2
      gecko/gecko_miner.c
  7. 8
      iguana/dPoW.h
  8. 147
      iguana/dpow/dpow_fsm.c
  9. 64
      iguana/dpow/dpow_network.c
  10. 171
      iguana/dpow/dpow_rpc.c
  11. 5
      iguana/dpow/dpow_tx.c
  12. 1
      iguana/elected
  13. 51
      iguana/exchanges/LP_bitcoin.c
  14. 23
      iguana/exchanges/LP_cache.c
  15. 53
      iguana/exchanges/LP_commands.c
  16. 6
      iguana/exchanges/LP_include.h
  17. 17
      iguana/exchanges/LP_nativeDEX.c
  18. 17
      iguana/exchanges/LP_network.c
  19. 24
      iguana/exchanges/LP_ordermatch.c
  20. 9
      iguana/exchanges/LP_prices.c
  21. 49
      iguana/exchanges/LP_privkey.c
  22. 31
      iguana/exchanges/LP_rpc.c
  23. 151
      iguana/exchanges/LP_transaction.c
  24. 12
      iguana/exchanges/LP_utxo.c
  25. 2
      iguana/exchanges/coins
  26. 4
      iguana/exchanges/mm.c
  27. 6
      iguana/exchanges/opreturn
  28. 5
      iguana/exchanges/opreturndecrypt
  29. 6
      iguana/exchanges/stats.c
  30. 4
      iguana/iguana_blocks.c
  31. 142
      iguana/iguana_notary.c
  32. 2
      iguana/iguana_recv.c
  33. 2
      iguana/iguana_tx.c
  34. 2
      iguana/kmd_lookup.h
  35. 2
      iguana/m_notary
  36. 2
      iguana/m_notary_run
  37. 26
      iguana/main.c
  38. 2
      includes/iguana_apideclares.h
  39. 2
      includes/iguana_funcs.h
  40. 2
      includes/iguana_structs.h

24
basilisk/basilisk.c

@ -931,20 +931,20 @@ void basilisks_loop(void *arg)
relay = iguana_coinfind("RELAY");
startmilli = OS_milliseconds();
endmilli = startmilli + 1000;
//fprintf(stderr,"A ");
//fprintf(stderr,"A ");
basilisk_issued_purge(myinfo,600000);
//fprintf(stderr,"B ");
//fprintf(stderr,"B ");
basilisk_p2pQ_process(myinfo,777);
//fprintf(stderr,"C ");
//fprintf(stderr,"C ");
if ( myinfo->IAMNOTARY != 0 )
{
if ( relay != 0 )
{
//fprintf(stderr,"D ");
//fprintf(stderr,"D ");
basilisk_ping_send(myinfo,relay);
}
counter++;
//fprintf(stderr,"E ");
//fprintf(stderr,"E ");
if ( myinfo->numdpows == 1 )
{
iguana_dPoWupdate(myinfo,&myinfo->DPOWS[0]);
@ -961,11 +961,11 @@ void basilisks_loop(void *arg)
}
endmilli = startmilli + 30;
}
//fprintf(stderr,"F ");
//fprintf(stderr,"F ");
}
else
{
//fprintf(stderr,"G ");
//fprintf(stderr,"G ");
dex_updateclient(myinfo);
if ( myinfo->IAMLP != 0 )
endmilli = startmilli + 500;
@ -973,15 +973,15 @@ void basilisks_loop(void *arg)
}
if ( myinfo->expiration != 0 && (myinfo->dexsock >= 0 || myinfo->IAMLP != 0 || myinfo->DEXactive > time(NULL)) )
{
//fprintf(stderr,"H ");
//fprintf(stderr,"H ");
for (i=0; i<100; i++)
if ( basilisk_requests_poll(myinfo) <= 0 )
break;
}
//printf("RELAYID.%d endmilli %f vs now %f\n",myinfo->NOTARY.RELAYID,endmilli,startmilli);
//printf("RELAYID.%d endmilli %f vs now %f\n",myinfo->NOTARY.RELAYID,endmilli,startmilli);
while ( OS_milliseconds() < endmilli )
usleep(10000);
//printf("finished waiting numdpow.%d\n",myinfo->numdpows);
//printf("finished waiting numdpow.%d\n",myinfo->numdpows);
iter++;
}
}
@ -1183,7 +1183,7 @@ HASH_ARRAY_STRING(basilisk,sendmessage,hash,vals,hexstr)
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,numtx=0; bits256 txid,blockhash; struct basilisk_item *ptr,Lptr; uint64_t value; int32_t timeoutmillis,vout,height,n,m;
char *retstr=0,*symbol,*coinaddr,*infostr; cJSON *retjson,*sobj,*info,*addrs,*txoutjson,*txjson,*array; uint32_t basilisktag,blocktime,numtx=0; bits256 txid,blockhash,merkleroot; 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 )
@ -1219,7 +1219,7 @@ HASH_ARRAY_STRING(basilisk,value,hash,vals,hexstr)
jadd64bits(retjson,"satoshis",value);
jaddnum(retjson,"value",dstr(value));
jaddnum(retjson,"amount",dstr(value));
height = dpow_getchaintip(myinfo,&blockhash,&blocktime,0,&numtx,coin);
height = dpow_getchaintip(myinfo,&merkleroot,&blockhash,&blocktime,0,&numtx,coin);
jaddnum(retjson,"height",height);
jaddnum(retjson,"numconfirms",jint(txoutjson,"confirmations"));
jaddbits256(retjson,"txid",txid);

6
basilisk/basilisk_bitcoin.c

@ -26,7 +26,7 @@ char *bitcoin_balance(struct iguana_info *coin,char *coinaddr,int32_t lastheight
{
int32_t i,n,height,maxconf=1<<30; int64_t balance = 0; char params[512],*curlstr; cJSON *array,*retjson,*curljson;
retjson = cJSON_CreateObject();
if ( (curlstr= bitcoind_passthru(coin->symbol,coin->chain->serverport,coin->chain->userpass,"getinfo",params)) != 0 )
if ( (curlstr= bitcoind_getinfo(coin->symbol,coin->chain->serverport,coin->chain->userpass,coin->getinfostr)) != 0 )
{
if ( (curljson= cJSON_Parse(curlstr)) != 0 )
{
@ -181,7 +181,7 @@ int32_t basilisk_bitcoinscan(struct iguana_info *coin,uint8_t origblockspace[IGU
{
struct iguana_txblock txdata; struct iguana_block B; int32_t len,starti,h,num=0,loadheight,hexlen,datalen,n,i,numtxids,flag=0,j,height=-1; cJSON *curljson,*blockjson,*txids; char *bitstr,*curlstr,params[128],str[65]; struct iguana_msghdr H; struct iguana_msgblock *msg; uint8_t *blockspace,revbits[4],bitsbuf[4]; bits256 hash2,checkhash2;
strcpy(params,"[]");
if ( (curlstr= bitcoind_passthru(coin->symbol,coin->chain->serverport,coin->chain->userpass,"getinfo",params)) != 0 )
if ( (curlstr= bitcoind_getinfo(coin->symbol,coin->chain->serverport,coin->chain->userpass,coin->getinfostr)) != 0 )
{
if ( (curljson= cJSON_Parse(curlstr)) != 0 )
{
@ -602,7 +602,7 @@ char *iguana_utxoduplicates(struct supernet_info *myinfo,struct iguana_info *coi
free_json(vins);
return(rawtx);
}
printf("%s splitfunds tx.(%s) vins.(%s)\n",coin->symbol,rawtx,jprint(vins,0));
//printf("%s splitfunds tx.(%s) vins.(%s)\n",coin->symbol,rawtx,jprint(vins,0));
if ( signedtxidp != 0 )
{
if ( (signedtx= iguana_signrawtx(myinfo,coin,0,signedtxidp,completedp,vins,rawtx,0,0)) != 0 )

2
crypto777/OS_portable.h

@ -286,6 +286,8 @@ void *iguana_memalloc(struct OS_memspace *mem,long size,int32_t clearflag);
int64_t iguana_memfree(struct OS_memspace *mem,void *ptr,int32_t size);
// generic functions
bits256 iguana_merkle(char *symbol,bits256 *tree,int32_t txn_count);
bits256 bits256_calctxid(char *symbol,uint8_t *serialized,int32_t len);
int32_t unhex(char c);
void touppercase(char *str);
uint32_t is_ipaddr(char *str);

37
crypto777/iguana_utils.c

@ -1285,3 +1285,40 @@ double get_theoretical(double *avebidp,double *aveaskp,double *highbidp,double *
return(theoretical);
}
bits256 bits256_calctxid(char *symbol,uint8_t *serialized,int32_t len)
{
bits256 txid,revtxid; int32_t i;
memset(txid.bytes,0,sizeof(txid));
if ( strcmp(symbol,"GRS") != 0 && strcmp(symbol,"SMART") != 0 )
txid = bits256_doublesha256(0,serialized,len);
else
{
vcalc_sha256(0,revtxid.bytes,serialized,len);
for (i=0; i<32; i++)
txid.bytes[i] = revtxid.bytes[31 - i];
}
return(txid);
}
bits256 iguana_merkle(char *symbol,bits256 *tree,int32_t txn_count)
{
int32_t i,n=0,prev; uint8_t serialized[sizeof(bits256) * 2];
if ( txn_count == 1 )
return(tree[0]);
prev = 0;
while ( txn_count > 1 )
{
if ( (txn_count & 1) != 0 )
tree[prev + txn_count] = tree[prev + txn_count-1], txn_count++;
n += txn_count;
for (i=0; i<txn_count; i+=2)
{
iguana_rwbignum(1,serialized,sizeof(*tree),tree[prev + i].bytes);
iguana_rwbignum(1,&serialized[sizeof(*tree)],sizeof(*tree),tree[prev + i + 1].bytes);
tree[n + (i >> 1)] = bits256_calctxid(symbol,serialized,sizeof(serialized));
}
prev = n;
txn_count >>= 1;
}
return(tree[n]);
}

2
datachain/datachain.c

@ -88,7 +88,7 @@ int32_t datachain_checkpoint_update(struct supernet_info *myinfo,struct iguana_i
}
if ( n > 0 && lastheight >= 0 && bits256_nonz(lasthash2) != 0 )
{
merkle = iguana_merkle(tree,num);
merkle = iguana_merkle(coin->symbol,tree,num);
coin->lastcheckpoint = datachain_checkpoint(myinfo,coin,coin->lastcheckpoint,timestamp,merkle,lastheight,lasthash2);
}
}

2
gecko/gecko_miner.c

@ -204,7 +204,7 @@ char *gecko_blockconstruct(struct supernet_info *myinfo,struct iguana_info *virt
}
if ( (coinbasestr= gecko_coinbasestr(myinfo,virt,&txids[0],newblock->RO.timestamp,minerpubkey,blockreward,coinbase,coinbaselen,coinbasespend)) != 0 )
{
newblock->RO.merkle_root = iguana_merkle(txids,txn_count + 1);
newblock->RO.merkle_root = iguana_merkle("GECKO",txids,txn_count + 1);
newblock->RO.txn_count = (txn_count + 1);
if ( txn_count > 0 )
{

8
iguana/dPoW.h

@ -47,7 +47,7 @@
#define DPOW_MAXSIGLEN 128
#define DEX_VERSION 0x0105
#define DPOW_SOCK 7775
#define DPOW_SOCKPORT 7775
#define DEX_SOCK 7774
#define PUB_SOCK 7773
#define REP_SOCK 7772
@ -104,12 +104,12 @@ struct dpow_checkpoint
struct dpow_block
{
bits256 hashmsg,desttxid,srctxid,beacon,commit;
bits256 hashmsg,desttxid,srctxid,beacon,commit,MoM;
struct iguana_info *srccoin,*destcoin; char *opret_symbol;
uint64_t destsigsmasks[DPOW_MAXRELAYS],srcsigsmasks[DPOW_MAXRELAYS];
uint64_t recvmask,bestmask,ratifybestmask,ratifyrecvmask,pendingbestmask,pendingratifybestmask,ratifysigmasks[2];
struct dpow_entry notaries[DPOW_MAXRELAYS];
uint32_t state,starttime,timestamp,waiting,sigcrcs[2],txidcrcs[2],utxocrcs[2],lastepoch,paxwdcrc;
uint32_t MoMdepth,state,starttime,timestamp,waiting,sigcrcs[2],txidcrcs[2],utxocrcs[2],lastepoch,paxwdcrc;
int32_t rawratifiedlens[2],height,numnotaries,numerrors,completed,minsigs,duration,numratified,isratify,require0,scores[DPOW_MAXRELAYS];
int8_t myind,bestk,ratifybestk,pendingbestk,pendingratifybestk;
cJSON *ratified;
@ -146,7 +146,7 @@ int32_t dpow_paxpending(uint8_t *hex,uint32_t *paxwdcrcp);
void dex_updateclient(struct supernet_info *myinfo);
char *dex_reqsend(struct supernet_info *myinfo,char *handler,uint8_t *data,int32_t datalen,int32_t M,char *field);
char *basilisk_respond_addmessage(struct supernet_info *myinfo,uint8_t *key,int32_t keylen,uint8_t *data,int32_t datalen,int32_t sendping,uint32_t duration);
int32_t dpow_getchaintip(struct supernet_info *myinfo,bits256 *blockhashp,uint32_t *blocktimep,bits256 *txs,uint32_t *numtxp,struct iguana_info *coin);
int32_t dpow_getchaintip(struct supernet_info *myinfo,bits256 *merklerootp,bits256 *blockhashp,uint32_t *blocktimep,bits256 *txs,uint32_t *numtxp,struct iguana_info *coin);
void dpow_send(struct supernet_info *myinfo,struct dpow_info *dp,struct dpow_block *bp,bits256 srchash,bits256 desthash,uint32_t channel,uint32_t msgbits,uint8_t *data,int32_t datalen);
int32_t dpow_nanomsg_update(struct supernet_info *myinfo);
int32_t dpow_haveutxo(struct supernet_info *myinfo,struct iguana_info *coin,bits256 *txidp,int32_t *voutp,char *coinaddr,char *srccoin);

147
iguana/dpow/dpow_fsm.c

@ -162,12 +162,147 @@ int32_t dpow_checkutxo(struct supernet_info *myinfo,struct dpow_info *dp,struct
uint32_t Numallocated;
int32_t dpow_txhasnotarization(struct supernet_info *myinfo,struct iguana_info *coin,bits256 txid,int32_t height)
{
cJSON *txobj,*vins,*vin,*vouts,*vout,*spentobj,*sobj; char *hexstr; uint8_t script[35]; bits256 spenttxid; uint64_t notarymask; int32_t i,j,numnotaries,len,spentvout,numvins,numvouts,hasnotarization = 0;
if ( (txobj= dpow_gettransaction(myinfo,coin,txid)) != 0 )
{
if ( (vins= jarray(&numvins,txobj,"vin")) != 0 )
{
if ( numvins >= DPOW_MIN_ASSETCHAIN_SIGS )
{
notarymask = numnotaries = 0;
for (i=0; i<numvins; i++)
{
vin = jitem(vins,i);
spenttxid = jbits256(vin,"txid");
spentvout = jint(vin,"vout");
if ( (spentobj= dpow_gettransaction(myinfo,coin,spenttxid)) != 0 )
{
if ( (vouts= jarray(&numvouts,spentobj,"vout")) != 0 )
{
if ( spentvout < numvouts )
{
vout = jitem(vouts,spentvout);
if ( (sobj= jobj(vout,"scriptPubKey")) != 0 && (hexstr= jstr(sobj,"hex")) != 0 && (len= is_hexstr(hexstr,0)) == sizeof(script)*2 )
{
len >>= 1;
decode_hex(script,len,hexstr);
if ( script[0] == 33 && script[34] == 0xac )
{
for (j=0; j<Notaries_num; j++)
{
if ( strncmp(Notaries_elected[j][1],hexstr+2,66) == 0 )
{
if ( ((1LL << j) & notarymask) == 0 )
{
printf("n%d ",j);
numnotaries++;
notarymask |= (1LL << j);
break;
}
}
}
}
}
}
}
free_json(spentobj);
}
}
if ( numnotaries > 0 )
{
if ( numnotaries >= DPOW_MIN_ASSETCHAIN_SIGS )
hasnotarization = 1;
printf("numnotaries.%d %s hasnotarization.%d ht.%d\n",numnotaries,coin->symbol,hasnotarization,height);
}
}
}
free_json(txobj);
}
return(hasnotarization);
}
int32_t dpow_hasnotarization(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *blockjson,int32_t ht)
{
int32_t i,n,hasnotarization = 0; bits256 txid; cJSON *txarray;
if ( (txarray= jarray(&n,blockjson,"tx")) != 0 )
{
for (i=0; i<n; i++)
{
txid = jbits256i(txarray,i);
hasnotarization += dpow_txhasnotarization(myinfo,coin,txid,ht);
}
}
return(hasnotarization);
}
bits256 dpow_calcMoM(uint32_t *MoMdepthp,struct supernet_info *myinfo,struct iguana_info *coin,int32_t height)
{
bits256 MoM,blockhash,merkle,*merkles; cJSON *blockjson; int32_t ht,maxdepth = 8192,MoMdepth = 0;
memset(MoM.bytes,0,sizeof(MoM));
blockhash = dpow_getblockhash(myinfo,coin,height);
if ( (blockjson= dpow_getblock(myinfo,coin,blockhash)) != 0 )
{
merkle = jbits256(blockjson,"merkleroot");
free_json(blockjson);
if ( bits256_nonz(merkle) != 0 )
{
merkles = calloc(maxdepth,sizeof(*merkles));
merkles[MoMdepth++] = merkle;
while ( MoMdepth < maxdepth && MoMdepth < height )
{
ht = height - MoMdepth;
blockhash = dpow_getblockhash(myinfo,coin,ht);
if ( (blockjson= dpow_getblock(myinfo,coin,blockhash)) != 0 )
{
if ( dpow_hasnotarization(myinfo,coin,blockjson,ht) > 0 )
{
free_json(blockjson);
break;
}
merkle = jbits256(blockjson,"merkleroot");
free_json(blockjson);
if ( bits256_nonz(merkle) != 0 )
merkles[MoMdepth++] = merkle;
else
{
printf("%s MoMdepth.%d ht.%d from height.%d, null merkleroot\n",coin->symbol,MoMdepth,ht,height);
MoMdepth = 0;
break;
}
}
else
{
printf("%s MoMdepth.%d ht.%d from height.%d, no blockhash\n",coin->symbol,MoMdepth,ht,height);
MoMdepth = 0;
break;
}
}
if ( MoMdepth > 0 && MoMdepth < maxdepth )
{
MoM = iguana_merkle(coin->symbol,merkles,MoMdepth);
char str[65]; printf("%s from height.%d MoMdepth.%d -> MoM %s\n",coin->symbol,height,MoMdepth,bits256_str(str,MoM));
}
else
{
printf("unexpected %s from height.%d MoMdepth.%d vs max.%d\n",coin->symbol,height,MoMdepth,maxdepth);
MoMdepth = 0;
}
free(merkles);
} else printf("%s.ht%d null merkles\n",coin->symbol,height);
} else printf("%s.ht%d null block\n",coin->symbol,height);
*MoMdepthp = MoMdepth;
return(MoM);
}
void dpow_statemachinestart(void *ptr)
{
void **ptrs = ptr;
struct supernet_info *myinfo; struct dpow_info *dp; struct dpow_checkpoint checkpoint;
int32_t i,j,ht,extralen,destprevvout0,srcprevvout0,numratified=0,kmdheight,myind = -1; uint8_t extras[10000],pubkeys[64][33]; cJSON *ratified=0,*item; struct iguana_info *src,*dest; char *jsonstr,*handle,*hexstr,str[65],str2[65],srcaddr[64],destaddr[64]; bits256 zero,srchash,destprevtxid0,srcprevtxid0; struct dpow_block *bp; struct dpow_entry *ep = 0; uint32_t duration,minsigs,starttime,srctime;
int32_t i,j,ht,extralen,destprevvout0,srcprevvout0,numratified=0,kmdheight,myind = -1; uint8_t extras[10000],pubkeys[64][33]; cJSON *ratified=0,*item; struct iguana_info *src,*dest; char *jsonstr,*handle,*hexstr,str[65],str2[65],srcaddr[64],destaddr[64]; bits256 zero,MoM,merkleroot,srchash,destprevtxid0,srcprevtxid0; struct dpow_block *bp; struct dpow_entry *ep = 0; uint32_t MoMdepth,duration,minsigs,starttime,srctime;
memset(&zero,0,sizeof(zero));
MoM = zero;
srcprevtxid0 = destprevtxid0 = zero;
srcprevvout0 = destprevvout0 = -1;
myinfo = ptrs[0];
@ -179,22 +314,28 @@ void dpow_statemachinestart(void *ptr)
memcpy(&checkpoint,&ptrs[5],sizeof(checkpoint));
src = iguana_coinfind(dp->symbol);
dest = iguana_coinfind(dp->dest);
dpow_getchaintip(myinfo,&srchash,&srctime,dp->srctx,&dp->numsrctx,src);
dpow_getchaintip(myinfo,&srchash,&srctime,dp->desttx,&dp->numdesttx,dest);
dpow_getchaintip(myinfo,&merkleroot,&srchash,&srctime,dp->desttx,&dp->numdesttx,dest);
dpow_getchaintip(myinfo,&merkleroot,&srchash,&srctime,dp->srctx,&dp->numsrctx,src);
if ( src == 0 || dest == 0 )
{
printf("null coin ptr? (%s %p or %s %p)\n",dp->symbol,src,dp->dest,dest);
free(ptr);
return;
}
MoMdepth = 0;
if ( strcmp(src->symbol,"KMD") == 0 )
kmdheight = checkpoint.blockhash.height;
else if ( strcmp(dest->symbol,"KMD") == 0 )
{
kmdheight = dest->longestchain;
MoM = dpow_calcMoM(&MoMdepth,myinfo,src,checkpoint.blockhash.height);
}
if ( (bp= dp->blocks[checkpoint.blockhash.height]) == 0 )
{
bp = calloc(1,sizeof(*bp));
Numallocated++;
bp->MoM = MoM;
bp->MoMdepth = MoMdepth;
bp->minsigs = minsigs;
bp->duration = duration;
bp->srccoin = src;

64
iguana/dpow/dpow_network.c

@ -13,6 +13,10 @@
* *
******************************************************************************/
extern uint16_t Notaries_port;
extern int32_t Notaries_numseeds;
extern char *Notaries_seeds[];
struct signed_nnpacket
{
uint8_t sig64[64];
@ -24,14 +28,14 @@ struct signed_nnpacket
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", "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" };
int32_t i,j,mask = 0;
OS_randombytes((void *)&i,sizeof(i));
srand(i);
for (i=0; i<sizeof(myinfo->dexseed_ipaddrs)/sizeof(*myinfo->dexseed_ipaddrs); i++)
{
while ( 1 )
{
j = (rand() % (sizeof(seeds)/sizeof(*seeds)));
j = (rand() % Notaries_numseeds);
if ( i < 2 )
j = i;
if ( ((1 << j) & mask) == 0 )
@ -41,8 +45,8 @@ void dex_init(struct supernet_info *myinfo)
#ifdef NOTARY_TESTMODE
seeds[j] = NOTARY_TESTMODE;
#endif
printf("seed.[%d] <- %s\n",i,seeds[j]);
strcpy(myinfo->dexseed_ipaddrs[i],seeds[j]);
printf("seed.[%d] <- %s\n",i,Notaries_seeds[j]);
strcpy(myinfo->dexseed_ipaddrs[i],Notaries_seeds[j]);
myinfo->dexipbits[i] = (uint32_t)calc_ipbits(myinfo->dexseed_ipaddrs[i]);
}
myinfo->numdexipbits = i;
@ -1002,8 +1006,8 @@ char *_dex_getnotaries(struct supernet_info *myinfo,char *symbol)
}
else
{
extern const char *Notaries_elected[][2];
myinfo->numnotaries = 64;//sizeof(Notaries_elected)/sizeof(*Notaries_elected);
extern char *Notaries_elected[][2]; extern int32_t Notaries_num;
myinfo->numnotaries = Notaries_num;//sizeof(Notaries_elected)/sizeof(*Notaries_elected);
for (i=0; i<myinfo->numnotaries; i++)
{
decode_hex(myinfo->notaries[i],33,(char *)Notaries_elected[i][1]);
@ -1292,7 +1296,7 @@ int32_t dpow_addnotary(struct supernet_info *myinfo,struct dpow_info *dp,char *i
if ( myinfo->IAMNOTARY == 0 )
return(-1);
portable_mutex_lock(&myinfo->notarymutex);
if ( myinfo->dpowsock >= 0 && myinfo->dexsock >= 0 )
if ( myinfo->dpowsock >= 0 )//&& myinfo->dexsock >= 0 )
{
ipbits = (uint32_t)calc_ipbits(ipaddr);
for (iter=0; iter<2; iter++)
@ -1315,9 +1319,9 @@ int32_t dpow_addnotary(struct supernet_info *myinfo,struct dpow_info *dp,char *i
ptr[n] = ipbits;
if ( iter == 0 && strcmp(ipaddr,myinfo->ipaddr) != 0 )
{
retval = nn_connect(myinfo->dpowsock,nanomsg_tcpname(0,str,ipaddr,DPOW_SOCK));
retval = nn_connect(myinfo->dpowsock,nanomsg_tcpname(0,str,ipaddr,Notaries_port));
printf("NN_CONNECT to (%s)\n",str);
retval = nn_connect(myinfo->dexsock,nanomsg_tcpname(0,str,ipaddr,DEX_SOCK));
//retval = nn_connect(myinfo->dexsock,nanomsg_tcpname(0,str,ipaddr,DEX_SOCK));
}
n++;
qsort(ptr,n,sizeof(uint32_t),_increasing_ipbits);
@ -1338,7 +1342,7 @@ int32_t dpow_addnotary(struct supernet_info *myinfo,struct dpow_info *dp,char *i
void dpow_nanomsginit(struct supernet_info *myinfo,char *ipaddr)
{
char str[512]; int32_t timeout,retval,maxsize,dpowsock,dexsock,repsock,pubsock;
char str[512],bindpoint[64]; int32_t timeout,retval,maxsize,dpowsock,dexsock,repsock,pubsock;
if ( myinfo->ipaddr[0] == 0 )
{
printf("need to set ipaddr before nanomsg\n");
@ -1353,13 +1357,14 @@ void dpow_nanomsginit(struct supernet_info *myinfo,char *ipaddr)
pubsock = myinfo->pubsock;
if ( dpowsock < 0 && (dpowsock= nn_socket(AF_SP,NN_BUS)) >= 0 )
{
if ( nn_bind(dpowsock,nanomsg_tcpname(myinfo,str,myinfo->ipaddr,DPOW_SOCK)) < 0 )
sprintf(bindpoint,"tcp://*:%u",Notaries_port);
if ( nn_bind(dpowsock,bindpoint) < 0 ) //nanomsg_tcpname(myinfo,str,myinfo->ipaddr,Notaries_port
{
printf("error binding to dpowsock (%s)\n",nanomsg_tcpname(myinfo,str,myinfo->ipaddr,DPOW_SOCK));
printf("error binding to dpowsock (%s)\n",bindpoint);
nn_close(dpowsock);
dpowsock = -1;
}
else
else if ( 0 )
{
printf("NN_BIND to %s\n",str);
if ( dexsock < 0 && (dexsock= nn_socket(AF_SP,NN_BUS)) >= 0 )
@ -1422,15 +1427,15 @@ void dpow_nanomsginit(struct supernet_info *myinfo,char *ipaddr)
}
}
}
myinfo->dpowipbits[0] = (uint32_t)calc_ipbits(myinfo->ipaddr);
myinfo->numdpowipbits = 1;
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)));
myinfo->nanoinit = (uint32_t)time(NULL);
}
myinfo->dpowipbits[0] = (uint32_t)calc_ipbits(myinfo->ipaddr);
myinfo->numdpowipbits = 1;
timeout = 1;
nn_setsockopt(dpowsock,NN_SOL_SOCKET,NN_RCVTIMEO,&timeout,sizeof(timeout));
maxsize = 1024 * 1024;
printf("%s RCVBUF.%d\n",bindpoint,nn_setsockopt(dpowsock,NN_SOL_SOCKET,NN_RCVBUF,&maxsize,sizeof(maxsize)));
myinfo->nanoinit = (uint32_t)time(NULL);
} //else printf("error creating nanosocket\n");
if ( myinfo->dpowsock != dpowsock )
myinfo->dpowsock = dpowsock;
@ -1869,7 +1874,7 @@ void dpow_notarize_update(struct supernet_info *myinfo,struct dpow_info *dp,stru
bp->pendingbestk = bp->bestk;
bp->pendingbestmask = bp->bestmask;
dpow_signedtxgen(myinfo,dp,bp->destcoin,bp,bp->bestk,bp->bestmask,bp->myind,DPOW_SIGBTCCHANNEL,1,0);
printf("finished signing\n");
//printf("finished signing\n");
}
if ( bp->destsigsmasks[bp->bestk] == bp->bestmask ) // have all sigs
{
@ -1895,8 +1900,9 @@ void dpow_notarize_update(struct supernet_info *myinfo,struct dpow_info *dp,stru
if ( 0 && bp->myind <= 1 )
printf("mypaxcrc.%x\n",bp->paxwdcrc);
}
if ( (rand() % 130) == 0 )
printf("%p ht.%d [%d] ips.%d %s NOTARIZE.%d matches.%d paxmatches.%d bestmatches.%d bestk.%d %llx recv.%llx sigmasks.(%llx %llx) senderind.%d state.%x (%x %x %x) pax.%x\n",bp,bp->height,bp->myind,dp->numipbits,dp->symbol,bp->minsigs,matches,paxmatches,bestmatches,bp->bestk,(long long)bp->bestmask,(long long)bp->recvmask,(long long)(bp->bestk>=0?bp->destsigsmasks[bp->bestk]:0),(long long)(bp->bestk>=0?bp->srcsigsmasks[bp->bestk]:0),senderind,bp->state,bp->hashmsg.uints[0],bp->desttxid.uints[0],bp->srctxid.uints[0],bp->paxwdcrc);
char str[65];
if ( (rand() % 130) == 0 || strcmp(dp->symbol,"PIZZA") == 0 )
printf("%p ht.%d [%d] ips.%d %s NOTARIZE.%d matches.%d paxmatches.%d bestmatches.%d bestk.%d %llx recv.%llx sigmasks.(%llx %llx) senderind.%d state.%x (%x %x %x) MoM.%s [%d]\n",bp,bp->height,bp->myind,dp->numipbits,dp->symbol,bp->minsigs,matches,paxmatches,bestmatches,bp->bestk,(long long)bp->bestmask,(long long)bp->recvmask,(long long)(bp->bestk>=0?bp->destsigsmasks[bp->bestk]:0),(long long)(bp->bestk>=0?bp->srcsigsmasks[bp->bestk]:0),senderind,bp->state,bp->hashmsg.uints[0],bp->desttxid.uints[0],bp->srctxid.uints[0],bits256_str(str,bp->MoM),bp->MoMdepth);
}
}
@ -2009,7 +2015,7 @@ void dpow_ipbitsadd(struct supernet_info *myinfo,struct dpow_info *dp,uint32_t *
if ( j == n )
missing++;
}
if ( (numipbits == 1 || missing < matched || matched > 0) && missing > 0 )
if ( (numipbits == 1 || missing < matched || matched >= 0) && missing > 0 )
{
for (i=0; i<numipbits; i++)
if ( ipbits[i] != 0 )
@ -2019,7 +2025,7 @@ void dpow_ipbitsadd(struct supernet_info *myinfo,struct dpow_info *dp,uint32_t *
dpow_addnotary(myinfo,dp,ipaddr);
}
} else if ( missing > 0 )
printf("IGNORE from.%d RECV numips.%d numipbits.%d matched.%d missing.%d\n",fromid,numipbits,n,matched,missing);
printf("IGNORE from.%d RECV numips.%d numipbits.%d matched.%d missing.%d maxipbits.%d\n",fromid,numipbits,n,matched,missing,maxipbits);
expand_ipbits(ipaddr,senderipbits);
dpow_addnotary(myinfo,dp,ipaddr);
expand_ipbits(ipaddr,myinfo->myaddr.myipbits);
@ -2093,7 +2099,7 @@ int32_t dpow_nanomsg_update(struct supernet_info *myinfo)
} else flags |= 1;
if ( freeptr != 0 )
nn_freemsg(freeptr), np = 0, freeptr = 0;
if ( myinfo->dexsock >= 0 ) // from servers
if ( 0 && myinfo->dexsock >= 0 ) // from servers
{
freeptr = 0;
if ( (flags & 2) == 0 && (size= signed_nn_recv(&freeptr,myinfo,myinfo->notaries,myinfo->numnotaries,myinfo->dexsock,&dexp)) > 0 )
@ -2111,7 +2117,7 @@ int32_t dpow_nanomsg_update(struct supernet_info *myinfo)
if ( freeptr != 0 )
nn_freemsg(freeptr), dexp = 0, freeptr = 0;
}
if ( myinfo->repsock >= 0 ) // from clients
if ( 0 && myinfo->repsock >= 0 ) // from clients
{
dexp = 0;
if ( (flags & 4) == 0 && (size= nn_recv(myinfo->repsock,&dexp,NN_MSG,0)) > 0 )
@ -2237,7 +2243,7 @@ int32_t dpow_rwopret(int32_t rwflag,uint8_t *opret,bits256 *hashmsg,int32_t *hei
{
memcpy(&opret[opretlen],extras,extralen);
opretlen += extralen;
printf("added extra.%d opreturn for withdraws paxwdcrc.%08x\n",extralen,calc_crc32(0,extras,extralen));
printf("added extra.%d crc.%08x\n",extralen,calc_crc32(0,extras,extralen));
}
}
else

171
iguana/dpow/dpow_rpc.c

@ -15,13 +15,34 @@
#define issue_curl(cmdstr) bitcoind_RPC(0,"curl",cmdstr,0,0,0,0)
char *bitcoind_getinfo(char *symbol,char *serverport,char *userpass,char *getinfostr)
{
char buf[1],*retstr; cJSON *retjson;
buf[0] = 0;
if ( getinfostr[0] == 0 )
strcpy(getinfostr,"getinfo");
retstr = bitcoind_passthru(symbol,serverport,userpass,getinfostr,buf);
if ( (retjson= cJSON_Parse(retstr)) != 0 )
{
if ( jobj(retjson,"error") != 0 && strcmp(getinfostr,"getinfo") == 0 )
{
strcpy(getinfostr,"getblockchaininfo");
free(retstr);
retstr = bitcoind_passthru(symbol,serverport,userpass,getinfostr,buf);
printf("switch to getblockchaininfo -> (%s)\n",retstr);
}
free(retjson);
}
return(retstr);
}
cJSON *dpow_getinfo(struct supernet_info *myinfo,struct iguana_info *coin)
{
char buf[128],*retstr=0; cJSON *json = 0;
if ( coin->FULLNODE < 0 )
{
buf[0] = 0;
retstr = bitcoind_passthru(coin->symbol,coin->chain->serverport,coin->chain->userpass,"getinfo",buf);
retstr = bitcoind_getinfo(coin->symbol,coin->chain->serverport,coin->chain->userpass,coin->getinfostr);
usleep(10000);
}
else if ( coin->FULLNODE > 0 || coin->VALIDATENODE > 0 )
@ -49,78 +70,79 @@ cJSON *dpow_getinfo(struct supernet_info *myinfo,struct iguana_info *coin)
}
return(json);
}
const char *Notaries_elected[][2] =
char *Notaries_elected[64][2];
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" };
int32_t Notaries_numseeds = (int32_t)(sizeof(seeds)/sizeof(*seeds)),Notaries_num,Notaries_BTCminsigs = DPOW_MINSIGS,Notaries_minsigs = DPOW_MIN_ASSETCHAIN_SIGS;
uint16_t Notaries_port = DPOW_SOCKPORT;
char *Notaries_seeds[64];
int32_t komodo_initjson(char *fname)
{
{ "0_jl777_testA", "03b7621b44118017a16043f19b30cc8a4cfe068ac4e42417bae16ba460c80f3828" },
{ "0_jl777_testB", "02ebfc784a4ba768aad88d44d1045d240d47b26e248cafaf1c5169a42d7a61d344" },
{ "0_kolo_testA", "0287aa4b73988ba26cf6565d815786caf0d2c4af704d7883d163ee89cd9977edec" },
{ "artik_AR", "029acf1dcd9f5ff9c455f8bb717d4ae0c703e089d16cf8424619c491dff5994c90" },
{ "artik_EU", "03f54b2c24f82632e3cdebe4568ba0acf487a80f8a89779173cdb78f74514847ce" },
{ "artik_NA", "0224e31f93eff0cc30eaf0b2389fbc591085c0e122c4d11862c1729d090106c842" },
{ "artik_SH", "02bdd8840a34486f38305f311c0e2ae73e84046f6e9c3dd3571e32e58339d20937" },
{ "badass_EU", "0209d48554768dd8dada988b98aca23405057ac4b5b46838a9378b95c3e79b9b9e" },
{ "badass_NA", "02afa1a9f948e1634a29dc718d218e9d150c531cfa852843a1643a02184a63c1a7" },
{ "badass_SH", "026b49dd3923b78a592c1b475f208e23698d3f085c4c3b4906a59faf659fd9530b" },
{ "crackers_EU", "03bc819982d3c6feb801ec3b720425b017d9b6ee9a40746b84422cbbf929dc73c3" }, // 10
{ "crackers_NA", "03205049103113d48c7c7af811b4c8f194dafc43a50d5313e61a22900fc1805b45" },
{ "crackers_SH", "02be28310e6312d1dd44651fd96f6a44ccc269a321f907502aae81d246fabdb03e" },
{ "durerus_EU", "02bcbd287670bdca2c31e5d50130adb5dea1b53198f18abeec7211825f47485d57" },
{ "etszombi_AR", "031c79168d15edabf17d9ec99531ea9baa20039d0cdc14d9525863b83341b210e9" },
{ "etszombi_EU", "0281b1ad28d238a2b217e0af123ce020b79e91b9b10ad65a7917216eda6fe64bf7" },
{ "etszombi_SH", "025d7a193c0757f7437fad3431f027e7b5ed6c925b77daba52a8755d24bf682dde" },
{ "farl4web_EU", "0300ecf9121cccf14cf9423e2adb5d98ce0c4e251721fa345dec2e03abeffbab3f" },
{ "farl4web_SH", "0396bb5ed3c57aa1221d7775ae0ff751e4c7dc9be220d0917fa8bbdf670586c030" },
{ "fullmoon_AR", "0254b1d64840ce9ff6bec9dd10e33beb92af5f7cee628f999cb6bc0fea833347cc" },
{ "fullmoon_NA", "031fb362323b06e165231c887836a8faadb96eda88a79ca434e28b3520b47d235b" }, // 20
{ "fullmoon_SH", "030e12b42ec33a80e12e570b6c8274ce664565b5c3da106859e96a7208b93afd0d" },
{ "grewal_NA", "03adc0834c203d172bce814df7c7a5e13dc603105e6b0adabc942d0421aefd2132" },
{ "grewal_SH", "03212a73f5d38a675ee3cdc6e82542a96c38c3d1c79d25a1ed2e42fcf6a8be4e68" },
{ "indenodes_AR", "02ec0fa5a40f47fd4a38ea5c89e375ad0b6ddf4807c99733c9c3dc15fb978ee147" },
{ "indenodes_EU", "0221387ff95c44cb52b86552e3ec118a3c311ca65b75bf807c6c07eaeb1be8303c" },
{ "indenodes_NA", "02698c6f1c9e43b66e82dbb163e8df0e5a2f62f3a7a882ca387d82f86e0b3fa988" },
{ "indenodes_SH", "0334e6e1ec8285c4b85bd6dae67e17d67d1f20e7328efad17ce6fd24ae97cdd65e" },
{ "jeezy_EU", "023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6" },
{ "jsgalt_NA", "027b3fb6fede798cd17c30dbfb7baf9332b3f8b1c7c513f443070874c410232446" },
{ "karasugoi_NA", "02a348b03b9c1a8eac1b56f85c402b041c9bce918833f2ea16d13452309052a982" }, // 30
{ "kashifali_EU", "033777c52a0190f261c6f66bd0e2bb299d30f012dcb8bfff384103211edb8bb207" },
{ "kolo_AR", "03016d19344c45341e023b72f9fb6e6152fdcfe105f3b4f50b82a4790ff54e9dc6" },
{ "kolo_SH", "02aa24064500756d9b0959b44d5325f2391d8e95c6127e109184937152c384e185" },
{ "metaphilibert_AR", "02adad675fae12b25fdd0f57250b0caf7f795c43f346153a31fe3e72e7db1d6ac6" },
{ "movecrypto_AR", "022783d94518e4dc77cbdf1a97915b29f427d7bc15ea867900a76665d3112be6f3" },
{ "movecrypto_EU", "021ab53bc6cf2c46b8a5456759f9d608966eff87384c2b52c0ac4cc8dd51e9cc42" },
{ "movecrypto_NA", "02efb12f4d78f44b0542d1c60146738e4d5506d27ec98a469142c5c84b29de0a80" },
{ "movecrypto_SH", "031f9739a3ebd6037a967ce1582cde66e79ea9a0551c54731c59c6b80f635bc859" },
{ "muros_AR", "022d77402fd7179335da39479c829be73428b0ef33fb360a4de6890f37c2aa005e" },
{ "noashh_AR", "029d93ef78197dc93892d2a30e5a54865f41e0ca3ab7eb8e3dcbc59c8756b6e355" }, // 40
{ "noashh_EU", "02061c6278b91fd4ac5cab4401100ffa3b2d5a277e8f71db23401cc071b3665546" },
{ "noashh_NA", "033c073366152b6b01535e15dd966a3a8039169584d06e27d92a69889b720d44e1" },
{ "nxtswe_EU", "032fb104e5eaa704a38a52c126af8f67e870d70f82977e5b2f093d5c1c21ae5899" },
{ "polycryptoblog_NA", "02708dcda7c45fb54b78469673c2587bfdd126e381654819c4c23df0e00b679622" },
{ "pondsea_AR", "032e1c213787312099158f2d74a89e8240a991d162d4ce8017d8504d1d7004f735" },
{ "pondsea_EU", "0225aa6f6f19e543180b31153d9e6d55d41bc7ec2ba191fd29f19a2f973544e29d" },
{ "pondsea_NA", "031bcfdbb62268e2ff8dfffeb9ddff7fe95fca46778c77eebff9c3829dfa1bb411" },
{ "pondsea_SH", "02209073bc0943451498de57f802650311b1f12aa6deffcd893da198a544c04f36" },
{ "popcornbag_AR", "02761f106fb34fbfc5ddcc0c0aa831ed98e462a908550b280a1f7bd32c060c6fa3" },
{ "popcornbag_NA", "03c6085c7fdfff70988fda9b197371f1caf8397f1729a844790e421ee07b3a93e8" }, // 50
{ "ptytrader_NA", "0328c61467148b207400b23875234f8a825cce65b9c4c9b664f47410b8b8e3c222" },
{ "ptytrader_SH", "0250c93c492d8d5a6b565b90c22bee07c2d8701d6118c6267e99a4efd3c7748fa4" },
{ "rnr_AR", "029bdb08f931c0e98c2c4ba4ef45c8e33a34168cb2e6bf953cef335c359d77bfcd" },
{ "rnr_EU", "03f5c08dadffa0ffcafb8dd7ffc38c22887bd02702a6c9ac3440deddcf2837692b" },
{ "rnr_NA", "02e17c5f8c3c80f584ed343b8dcfa6d710dfef0889ec1e7728ce45ce559347c58c" },
{ "rnr_SH", "037536fb9bdfed10251f71543fb42679e7c52308bcd12146b2568b9a818d8b8377" },
{ "titomane_AR", "03cda6ca5c2d02db201488a54a548dbfc10533bdc275d5ea11928e8d6ab33c2185" },
{ "titomane_EU", "02e41feded94f0cc59f55f82f3c2c005d41da024e9a805b41105207ef89aa4bfbd" },
{ "titomane_SH", "035f49d7a308dd9a209e894321f010d21b7793461b0c89d6d9231a3fe5f68d9960" },
{ "vanbreuk_EU", "024f3cad7601d2399c131fd070e797d9cd8533868685ddbe515daa53c2e26004c3" }, // 60
{ "xrobesx_NA", "03f0cc6d142d14a40937f12dbd99dbd9021328f45759e26f1877f2a838876709e1" },
{ "xxspot1_XX", "02ef445a392fcaf3ad4176a5da7f43580e8056594e003eba6559a713711a27f955" },
{ "xxspot2_XX", "03d85b221ea72ebcd25373e7961f4983d12add66a92f899deaf07bab1d8b6f5573" }
};
char *fstr,*field,*hexstr; cJSON *argjson,*array,*item; long fsize; uint16_t port; int32_t i,n,num,retval = -1;
for (i=0; i<Notaries_numseeds; i++)
Notaries_seeds[i] = seeds[i];
if ( (fstr= OS_filestr(&fsize,fname)) != 0 )
{
if ( (argjson= cJSON_Parse(fstr)) != 0 )
{
if ( (port= juint(argjson,"port")) != 0 )
Notaries_port = port;
if ( (num= juint(argjson,"BTCminsigs")) > Notaries_BTCminsigs )
Notaries_BTCminsigs = num;
if ( (num= juint(argjson,"minsigs")) > Notaries_minsigs )
Notaries_minsigs = num;
if ( (array= jarray(&n,argjson,"seeds")) != 0 && n <= 64 )
{
for (i=0; i<n; i++)
{
Notaries_seeds[i] = clonestr(jstri(array,i));
printf("%s ",Notaries_seeds[i]);
}
printf("Notaries_numseeds.%d\n",Notaries_numseeds);
}
if ( (array= jarray(&n,argjson,"notaries")) != 0 && n <= 64 )
{
for (i=0; i<n; i++)
{
item = jitem(array,i);
field = jfieldname(item);
if ( (hexstr= jstr(item,field)) != 0 && is_hexstr(hexstr,0) == 66 )
{
Notaries_elected[i][0] = clonestr(field);
Notaries_elected[i][1] = clonestr(hexstr);
//printf("%d of %d: %s %s\n",i,n,field,hexstr);
}
else
{
printf("couldnt find (%s) in %s or non-hex (%s)\n",field,jprint(item,0),hexstr!=0?hexstr:"");
break;
}
}
if ( i == n )
{
Notaries_num = n;
retval = 0;
printf("numnotaries %d, port.%d minsigs.%d BTCminsigs.%d\n",Notaries_num,Notaries_port,Notaries_BTCminsigs,Notaries_minsigs);
}
}
free_json(argjson);
}
free(fstr);
}
return(retval);
}
int32_t komodo_notaries(char *symbol,uint8_t pubkeys[64][33],int32_t height)
{
int32_t i,num=-1; struct iguana_info *coin; char params[256],*retstr,*pubkeystr; cJSON *retjson,*item,*array;
if ( (coin= iguana_coinfind(symbol)) != 0 )
int32_t i; //,num=-1; struct iguana_info *coin; char params[256],*retstr,*pubkeystr; cJSON *retjson,*item,*array;
if ( Notaries_num > 0 )
{
for (i=0; i<Notaries_num; i++)
decode_hex(pubkeys[i],33,Notaries_elected[i][1]);
return(Notaries_num);
} else return(-1);
/*if ( (coin= iguana_coinfind(symbol)) != 0 )
{
if ( height < 0 )
{
@ -168,7 +190,7 @@ int32_t komodo_notaries(char *symbol,uint8_t pubkeys[64][33],int32_t height)
}
}
//printf("komodo_notaries returns.%d\n",num);
return(num);
return(num);*/
}
bits256 dpow_getbestblockhash(struct supernet_info *myinfo,struct iguana_info *coin)
@ -244,7 +266,7 @@ bits256 dpow_getblockhash(struct supernet_info *myinfo,struct iguana_info *coin,
sprintf(buf,"%d",height);
retstr = bitcoind_passthru(coin->symbol,coin->chain->serverport,coin->chain->userpass,"getblockhash",buf);
//printf("%s ht.%d -> getblockhash.(%s)\n",coin->symbol,height,retstr);
usleep(10000);
usleep(1000);
}
else if ( coin->FULLNODE > 0 || coin->VALIDATENODE > 0 )
{
@ -724,7 +746,7 @@ void init_alladdresses(struct supernet_info *myinfo,struct iguana_info *coin)
}
}
int32_t dpow_getchaintip(struct supernet_info *myinfo,bits256 *blockhashp,uint32_t *blocktimep,bits256 *txs,uint32_t *numtxp,struct iguana_info *coin)
int32_t dpow_getchaintip(struct supernet_info *myinfo,bits256 *merklerootp,bits256 *blockhashp,uint32_t *blocktimep,bits256 *txs,uint32_t *numtxp,struct iguana_info *coin)
{
int32_t n,i,height = -1,maxtx = *numtxp; bits256 besthash,oldhash; cJSON *array,*json;
*numtxp = *blocktimep = 0;
@ -736,6 +758,9 @@ int32_t dpow_getchaintip(struct supernet_info *myinfo,bits256 *blockhashp,uint32
{
if ( (height= juint(json,"height")) != 0 && (*blocktimep= juint(json,"time")) != 0 )
{
*merklerootp = jbits256(json,"merkleroot");
//if ( bits256_nonz(*merklerootp) == 0 )
// printf("block has no merkle? (%s)\n",jprint(json,0));
coin->lastbestheight = height;
if ( height > coin->longestchain )
coin->longestchain = height;
@ -1243,7 +1268,7 @@ int32_t dpow_issuer_iteration(struct dpow_info *dp,struct iguana_info *coin,int3
if ( height <= 0 )
height = 1;
*isrealtimep = 0;
if ( (retstr= dpow_issuemethod(coin->chain->userpass,(char *)"getinfo",0,port)) != 0 )
if ( (retstr= dpow_issuemethod(coin->chain->userpass,(char *)coin->getinfostr,0,port)) != 0 )
{
if ( (infoobj= cJSON_Parse(retstr)) != 0 )
{

5
iguana/dpow/dpow_tx.c

@ -230,6 +230,11 @@ int32_t dpow_voutstandard(struct dpow_block *bp,uint8_t *serialized,int32_t m,in
printf("%02x",extras[i]);
printf(" <- withdraw.%d %08x\n",n,paxwdcrc);
}
else if ( Notaries_port != DPOW_SOCKPORT && bp->MoMdepth > 0 && strcmp(bp->destcoin->symbol,"KMD") == 0 ) // only testnets for now
{
n += iguana_rwbignum(1,&extras[n],sizeof(bp->MoM),bp->MoM.bytes);
n += iguana_rwnum(1,&extras[n],sizeof(bp->MoMdepth),(uint32_t *)&bp->MoMdepth);
}
satoshis = 0;
len += iguana_rwnum(1,&serialized[len],sizeof(satoshis),&satoshis);
if ( bp->isratify != 0 )

1
iguana/elected

File diff suppressed because one or more lines are too long

51
iguana/exchanges/LP_bitcoin.c

@ -2023,21 +2023,6 @@ char *bitcoind_passthrut(char *coinstr,char *serverport,char *userpass,char *met
return(bitcoind_RPC(0,coinstr,serverport,userpass,method,params,timeout));
}
bits256 bits256_calctxid(char *symbol,uint8_t *serialized,int32_t len)
{
bits256 txid,revtxid; int32_t i;
memset(txid.bytes,0,sizeof(txid));
if ( strcmp(symbol,"GRS") != 0 )
txid = bits256_doublesha256(0,serialized,len);
else
{
vcalc_sha256(0,revtxid.bytes,serialized,len);
for (i=0; i<32; i++)
txid.bytes[i] = revtxid.bytes[31 - i];
}
return(txid);
}
bits256 bits256_calcaddrhash(char *symbol,uint8_t *serialized,int32_t len)
{
bits256 hash;
@ -2066,7 +2051,7 @@ int32_t bitcoin_addr2rmd160(char *symbol,uint8_t taddr,uint8_t *addrtypep,uint8_
memset(rmd160,0,20);
if ( coinaddr == 0 || coinaddr[0] == 0 )
return(0);
if ( coinaddr[0] == '0' && coinaddr[1] == 'x' && is_hexstr(coinaddr+2,0) == 40 )
if ( coinaddr[0] == '0' && coinaddr[1] == 'x' && is_hexstr(coinaddr+2,0) == 40 ) // for ETH
{
decode_hex(rmd160,20,coinaddr+2); // not rmd160 hash but hopefully close enough;
return(20);
@ -2101,12 +2086,12 @@ int32_t bitcoin_addr2rmd160(char *symbol,uint8_t taddr,uint8_t *addrtypep,uint8_
hash = bits256_calcaddrhash(symbol,buf,20+offset);
*addrtypep = (taddr == 0) ? *buf : buf[1];
memcpy(rmd160,buf+offset,20);
if ( strcmp(symbol,"GRS") != 0 && (buf[20+offset]&0xff) == hash.bytes[31] && (buf[21+offset]&0xff) == hash.bytes[30] && (buf[22+offset]&0xff) == hash.bytes[29] && (buf[23+offset]&0xff) == hash.bytes[28] )
if ( (buf[20+offset]&0xff) == hash.bytes[31] && (buf[21+offset]&0xff) == hash.bytes[30] && (buf[22+offset]&0xff) == hash.bytes[29] && (buf[23+offset]&0xff) == hash.bytes[28] )
{
//printf("coinaddr.(%s) valid checksum addrtype.%02x\n",coinaddr,*addrtypep);
return(20);
}
else if ( strcmp(symbol,"GRS") == 0 && (buf[20+offset]&0xff) == hash.bytes[0] && (buf[21+offset]&0xff) == hash.bytes[1] && (buf[22+offset]&0xff) == hash.bytes[2] && (buf[23+offset]&0xff) == hash.bytes[3] )
else if ( (strcmp(symbol,"GRS") == 0 || strcmp(symbol,"SMART") == 0) && (buf[20+offset]&0xff) == hash.bytes[0] && (buf[21+offset]&0xff) == hash.bytes[1] && (buf[22+offset]&0xff) == hash.bytes[2] && (buf[23+offset]&0xff) == hash.bytes[3] )
return(20);
else
{
@ -2187,7 +2172,7 @@ char *bitcoin_address(char *symbol,char *coinaddr,uint8_t taddr,uint8_t addrtype
data[1] = addrtype;
} else data[0] = addrtype;
hash = bits256_calcaddrhash(symbol,data,20+offset);
if ( strcmp(symbol,"GRS") != 0 )
if ( strcmp(symbol,"GRS") != 0 && strcmp(symbol,"SMART") != 0 )
{
for (i=0; i<4; i++)
data[20+offset+i] = hash.bytes[31-i];
@ -2199,6 +2184,7 @@ char *bitcoin_address(char *symbol,char *coinaddr,uint8_t taddr,uint8_t addrtype
}
if ( (coinaddr= bitcoin_base58encode(coinaddr,data,24+offset)) != 0 )
{
//printf("coinaddr.%p %s\n",coinaddr,coinaddr!=0?coinaddr:"null");
} else printf("null coinaddr taddr.%02x\n",taddr);
return(coinaddr);
}
@ -2251,7 +2237,7 @@ int32_t base58encode_checkbuf(char *symbol,uint8_t taddr,uint8_t addrtype,uint8_
//for (i=0; i<32; i++)
// printf("%02x",hash.bytes[i]);
//printf(" checkhash\n");
if ( strcmp(symbol,"GRS") != 0 )
if ( strcmp(symbol,"GRS") != 0 && strcmp(symbol,"SMART") != 0 )
{
for (i=0; i<4; i++)
data[data_len+i+offset] = hash.bytes[31-i];
@ -2287,7 +2273,7 @@ int32_t bitcoin_wif2priv(char *symbol,uint8_t wiftaddr,uint8_t *addrtypep,bits25
ptr = buf;
hash = bits256_calcaddrhash(symbol,ptr,len - 4);
*addrtypep = (wiftaddr == 0) ? *ptr : ptr[1];
if ( strcmp(symbol,"GRS") != 0 && (ptr[len - 4]&0xff) == hash.bytes[31] && (ptr[len - 3]&0xff) == hash.bytes[30] &&(ptr[len - 2]&0xff) == hash.bytes[29] && (ptr[len - 1]&0xff) == hash.bytes[28] )
if ( (ptr[len - 4]&0xff) == hash.bytes[31] && (ptr[len - 3]&0xff) == hash.bytes[30] &&(ptr[len - 2]&0xff) == hash.bytes[29] && (ptr[len - 1]&0xff) == hash.bytes[28] )
{
//int32_t i; for (i=0; i<len; i++)
// printf("%02x ",ptr[i]);
@ -2295,7 +2281,7 @@ int32_t bitcoin_wif2priv(char *symbol,uint8_t wiftaddr,uint8_t *addrtypep,bits25
//printf("wifstr.(%s) valid len.%d\n",wifstr,len);
return(32);
}
else if ( strcmp(symbol,"GRS") == 0 && (ptr[len - 4]&0xff) == hash.bytes[0] && (ptr[len - 3]&0xff) == hash.bytes[1] &&(ptr[len - 2]&0xff) == hash.bytes[2] && (ptr[len - 1]&0xff) == hash.bytes[3] )
else if ( (strcmp(symbol,"GRS") == 0 || strcmp(symbol,"SMART") == 0) && (ptr[len - 4]&0xff) == hash.bytes[0] && (ptr[len - 3]&0xff) == hash.bytes[1] &&(ptr[len - 2]&0xff) == hash.bytes[2] && (ptr[len - 1]&0xff) == hash.bytes[3] )
return(32);
else if ( 0 ) // gets errors when len is 37
{
@ -2309,14 +2295,16 @@ int32_t bitcoin_wif2priv(char *symbol,uint8_t wiftaddr,uint8_t *addrtypep,bits25
int32_t bitcoin_wif2addr(void *ctx,char *symbol,uint8_t wiftaddr,uint8_t taddr,uint8_t pubtype,char *coinaddr,char *wifstr)
{
bits256 privkey; uint8_t addrtype,pubkey33[33];
bits256 privkey; int32_t len; uint8_t addrtype,pubkey33[33];
if ( strcmp(symbol,"BCH") == 0 )
symbol = "BTC";
coinaddr[0] = 0;
if ( bitcoin_wif2priv(symbol,wiftaddr,&addrtype,&privkey,wifstr) == sizeof(privkey) )
if ( (len= bitcoin_wif2priv(symbol,wiftaddr,&addrtype,&privkey,wifstr)) == sizeof(privkey) )
{
bitcoin_priv2pub(ctx,symbol,pubkey33,coinaddr,privkey,taddr,pubtype);
}
//printf("priv2pub returns.(%s)\n",coinaddr);
return(0);
} else printf("wif2priv returns len.%d\n",len);
return(-1);
}
@ -3412,12 +3400,13 @@ bits256 bitcoin_sigtxid(char *symbol,uint8_t taddr,uint8_t pubtype,uint8_t p2sht
sbtcflag = 1;
else if ( strcmp(symbol,"BTCP") == 0 )
btcpflag = 1;
// else printf("normal symbol.(%s)\n",symbol);
if ( ((hashtype & ~SIGHASH_FORKID) & 0xff) != SIGHASH_ALL )
{
printf("currently only SIGHASH_ALL supported, not %d\n",hashtype);
return(sigtxid);
}
if ( (hashtype & SIGHASH_FORKID) == 0 || sbtcflag != 0 )
if ( (hashtype & SIGHASH_FORKID) == 0 || sbtcflag != 0 || btcpflag != 0 )
{
for (i=0; i<dest.tx_in; i++)
{
@ -3449,7 +3438,7 @@ bits256 bitcoin_sigtxid(char *symbol,uint8_t taddr,uint8_t pubtype,uint8_t p2sht
if ( btcpflag != 0 )
{
hashtype = 0x2a41;
printf("BTCP detected: hardcode hashtype to %08x\n",hashtype);
//printf("BTCP detected: hardcode hashtype to %08x\n",hashtype);
}
len += iguana_rwnum(1,&serialized[len],sizeof(hashtype),&hashtype);
if ( sbtcflag != 0 )
@ -3533,10 +3522,10 @@ bits256 bitcoin_sigtxid(char *symbol,uint8_t taddr,uint8_t pubtype,uint8_t p2sht
len += iguana_voutparse(1,&serialized[len],&dest.vouts[i]);
outputhash = bits256_doublesha256(0,serialized,len);
char str[65]; printf("prevouthash.%s ",bits256_str(str,prevouthash));
printf("seqhash.%s ",bits256_str(str,seqhash));
printf("outputhash.%s ",bits256_str(str,outputhash));
printf("vini.%d prev.%s/v%d\n",vini,bits256_str(str,dest.vins[vini].prev_hash),dest.vins[vini].prev_vout);
//char str[65]; printf("prevouthash.%s ",bits256_str(str,prevouthash));
//printf("seqhash.%s ",bits256_str(str,seqhash));
//printf("outputhash.%s ",bits256_str(str,outputhash));
//printf("vini.%d prev.%s/v%d\n",vini,bits256_str(str,dest.vins[vini].prev_hash),dest.vins[vini].prev_vout);
/*01000000
997c1040c67ee2f9ab21abf7457f7aec4503970e974e532b6578f326c270b7eb
445066705e799022b7095f7ceca255149f43acfc47e7f59e551f7bce2930b13b

23
iguana/exchanges/LP_cache.c

@ -159,29 +159,6 @@ void LP_cacheptrs_init(struct iguana_info *coin)
OS_truncate(fname,len);
}
bits256 iguana_merkle(char *symbol,bits256 *tree,int32_t txn_count)
{
int32_t i,n=0,prev; uint8_t serialized[sizeof(bits256) * 2];
if ( txn_count == 1 )
return(tree[0]);
prev = 0;
while ( txn_count > 1 )
{
if ( (txn_count & 1) != 0 )
tree[prev + txn_count] = tree[prev + txn_count-1], txn_count++;
n += txn_count;
for (i=0; i<txn_count; i+=2)
{
iguana_rwbignum(1,serialized,sizeof(*tree),tree[prev + i].bytes);
iguana_rwbignum(1,&serialized[sizeof(*tree)],sizeof(*tree),tree[prev + i + 1].bytes);
tree[n + (i >> 1)] = bits256_calctxid(symbol,serialized,sizeof(serialized));
}
prev = n;
txn_count >>= 1;
}
return(tree[n]);
}
bits256 validate_merkle(int32_t pos,bits256 txid,cJSON *proofarray,int32_t proofsize)
{
int32_t i; uint8_t serialized[sizeof(bits256) * 2]; bits256 hash,proof;

53
iguana/exchanges/LP_commands.c

@ -160,13 +160,14 @@ bot_settings(botid, newprice, newvolume)\n\
bot_status(botid)\n\
bot_stop(botid)\n\
bot_pause(botid)\n\
calcaddress(passphrase)\n\
calcaddress(passphrase, coin=KMD)\n\
convaddress(coin, address, destcoin)\n\
instantdex_deposit(weeks, amount, broadcast=1)\n\
instantdex_claim()\n\
timelock(coin, duration, destaddr=(tradeaddr), amount)\n\
unlockedspend(coin, txid)\n\
getendpoint()\n\
opreturndecrypt(coin, txid, passphrase)\n\
getendpoint(port=5555)\n\
jpg(srcfile, destfile, power2=7, password, data="", required, ind=0)\n\
\"}"));
//sell(base, rel, price, basevolume, timeout=10, duration=3600)\n\
@ -233,22 +234,25 @@ jpg(srcfile, destfile, power2=7, password, data="", required, ind=0)\n\
}
else if ( strcmp(method,"getendpoint") == 0 )
{
int32_t err,mode;
int32_t err,mode; uint16_t wsport = 5555; char endpoint[64],bindpoint[64];
if ( juint(argjson,"port") != 0 )
wsport = juint(argjson,"port");
retjson = cJSON_CreateObject();
if ( IPC_ENDPOINT >= 0 )
{
jaddstr(retjson,"error","IPC endpoint already exists");
jaddstr(retjson,"endpoint","ws://*:5555");
jaddnum(retjson,"socket",IPC_ENDPOINT);
}
else
{
if ( (IPC_ENDPOINT= nn_socket(AF_SP,NN_PAIR)) >= 0 )
{
if ( (err= nn_bind(IPC_ENDPOINT,"ws://*:5555")) >= 0 )
sprintf(bindpoint,"ws://*:%u",wsport);
sprintf(endpoint,"ws://127.0.0.1:%u",wsport);
if ( (err= nn_bind(IPC_ENDPOINT,bindpoint)) >= 0 )
{
jaddstr(retjson,"result","success");
jaddstr(retjson,"endpoint","ws://127.0.0.1:5555");
jaddstr(retjson,"endpoint",endpoint);
jaddnum(retjson,"socket",IPC_ENDPOINT);
mode = NN_WS_MSG_TYPE_TEXT;
err = nn_setsockopt(IPC_ENDPOINT,NN_SOL_SOCKET,NN_WS_MSG_TYPE,&mode,sizeof(mode));
@ -257,6 +261,7 @@ jpg(srcfile, destfile, power2=7, password, data="", required, ind=0)\n\
else
{
jaddstr(retjson,"error",(char *)nn_strerror(nn_errno()));
jaddstr(retjson,"bind",bindpoint);
jaddnum(retjson,"err",err);
jaddnum(retjson,"socket",IPC_ENDPOINT);
nn_close(IPC_ENDPOINT);
@ -336,17 +341,39 @@ jpg(srcfile, destfile, power2=7, password, data="", required, ind=0)\n\
}
else if ( strcmp(method,"calcaddress") == 0 )
{
bits256 privkey,pub; uint8_t pubkey33[33]; char *passphrase,coinaddr[64],wifstr[64];
bits256 privkey,pub; uint8_t pubtype,wiftaddr,p2shtype,taddr,wiftype,pubkey33[33]; char *passphrase,coinaddr[64],wifstr[64],pubsecp[67];
if ( (passphrase= jstr(argjson,"passphrase")) != 0 )
{
conv_NXTpassword(privkey.bytes,pub.bytes,(uint8_t *)passphrase,(int32_t)strlen(passphrase));
privkey.bytes[0] &= 248, privkey.bytes[31] &= 127, privkey.bytes[31] |= 64;
bitcoin_priv2pub(ctx,"KMD",pubkey33,coinaddr,privkey,0,60);
if ( (coin= jstr(argjson,"coin")) == 0 || (ptr= LP_coinfind(coin)) == 0 )
{
coin = "KMD";
taddr = 0;
pubtype = 60;
p2shtype = 85;
wiftype = 188;
wiftaddr = 0;
}
else
{
coin = ptr->symbol;
taddr = ptr->taddr;
pubtype = ptr->pubtype;
p2shtype = ptr->p2shtype;
wiftype = ptr->wiftype;
wiftaddr = ptr->wiftaddr;
}
retjson = cJSON_CreateObject();
jaddstr(retjson,"passphrase",passphrase);
bitcoin_priv2pub(ctx,coin,pubkey33,coinaddr,privkey,taddr,pubtype);
init_hexbytes_noT(pubsecp,pubkey33,33);
jaddstr(retjson,"pubsecp",pubsecp);
jaddstr(retjson,"coinaddr",coinaddr);
bitcoin_priv2pub(ctx,coin,pubkey33,coinaddr,privkey,taddr,p2shtype);
jaddstr(retjson,"p2shaddr",coinaddr);
jaddbits256(retjson,"privkey",privkey);
bitcoin_priv2wif("KMD",0,wifstr,privkey,188);
bitcoin_priv2wif(coin,wiftaddr,wifstr,privkey,wiftype);
jaddstr(retjson,"wif",wifstr);
return(jprint(retjson,1));
} else return(clonestr("{\"error\":\"need to have passphrase\"}"));
@ -560,6 +587,10 @@ jpg(srcfile, destfile, power2=7, password, data="", required, ind=0)\n\
{
return(LP_timelock(coin,juint(argjson,"duration"),jstr(argjson,"destaddr"),jdouble(argjson,"amount")*SATOSHIDEN));
}
else if ( strcmp(method,"opreturndecrypt") == 0 )
{
return(LP_opreturndecrypt(ctx,coin,jbits256(argjson,"txid"),jstr(argjson,"passphrase")));
}
else if ( strcmp(method,"unlockedspend") == 0 )
{
return(LP_unlockedspend(ctx,coin,jbits256(argjson,"txid")));
@ -572,8 +603,10 @@ jpg(srcfile, destfile, power2=7, password, data="", required, ind=0)\n\
{
if ( (ptr= LP_coinsearch(coin)) != 0 )
{
if ( jobj(argjson,"outputs") == 0 )
if ( jobj(argjson,"outputs") == 0 && jstr(argjson,"opreturn") == 0 )
return(clonestr("{\"error\":\"withdraw needs to have outputs\"}"));
else if ( ptr->etomic[0] != 0 )
return(clonestr("{\"error\":\"use eth_withdraw for ETH/ERC20\"}"));
else return(LP_withdraw(ptr,argjson));
}
return(clonestr("{\"error\":\"cant find coind\"}"));

6
iguana/exchanges/LP_include.h

@ -98,8 +98,8 @@ void emscripten_usleep(int32_t x); // returns immediate, no sense for sleeping
#define LP_SWAPSTEP_TIMEOUT 30
#define LP_MIN_TXFEE 1000
#define LP_MINVOL 20
#define LP_MINCLIENTVOL 200
#define LP_MINVOL 100
#define LP_MINCLIENTVOL 1000
#define LP_MINSIZE_TXFEEMULT 10
#define LP_REQUIRED_TXFEE 0.75
@ -508,6 +508,8 @@ char *LP_pricepings(void *ctx,char *myipaddr,int32_t pubsock,char *base,char *re
int32_t LP_merkleproof(struct iguana_info *coin,char *coinaddr,struct electrum_info *ep,bits256 txid,int32_t height);
cJSON *electrum_address_gethistory(char *symbol,struct electrum_info *ep,cJSON **retjsonp,char *addr,bits256 reftxid);
cJSON *LP_myzdebits();
int32_t LP_opreturn_decrypt(uint16_t *ind16p,uint8_t *decoded,uint8_t *encoded,int32_t encodedlen,char *passphrase);
int32_t LP_opreturn_encrypt(uint8_t *dest,int32_t maxsize,uint8_t *data,int32_t datalen,char *passphrase,uint16_t ind16);
void LP_pendswap_add(uint32_t expiration,uint32_t requestid,uint32_t quoteid);
int32_t _LP_utxos_remove(bits256 txid,int32_t vout);
int32_t LP_utxos_remove(bits256 txid,int32_t vout);

17
iguana/exchanges/LP_nativeDEX.c

@ -828,7 +828,7 @@ void LP_initcoins(void *ctx,int32_t pubsock,cJSON *coins)
item = jitem(coins,i);
if ( (symbol= jstr(item,"coin")) != 0 )
{
printf("%s, ",jstr(item,"coin"));
printf("%s.%d ",jstr(item,"coin"),LP_numpriceinfos);
LP_coincreate(item);
LP_priceinfoadd(jstr(item,"coin"));
if ( (coin= LP_coinfind(symbol)) != 0 )
@ -847,6 +847,19 @@ void LP_initcoins(void *ctx,int32_t pubsock,cJSON *coins)
{
bech32_tests();
}
else if ( 0 && strcmp(coin->symbol,"SMART") == 0 )
{
uint8_t txdata[8129]; int32_t len; bits256 txid,txid2,ktxid; char str[65];
char *txstr = "0100000005c9a9c56f4e702766c582127587ee49695ba5b9e5c449290a4f8a0505c12beeb7000000006b483045022100867f85d9f8d7f543225448f1d2383ff7d60a325b5f643557ea36325372de9993022034ccd202ee017c3d8a2dfa615b72d661b891d2071b1c15d4d7ab063762c79d2f012103f9be43471012e3e6daaa7a91a68cbc667fa61791e4a93f8e8d53255a93b68d03ffffffffe062eb6845b69856d62ceb3fd9b7e05c383b8b88b9359bc7c8ac49cd7dd2b2bb010000006b483045022100d4ef1c6d5f24ad3877f57f8ae4a1c0f8aa2f6de5ccaa8ed8e10b2937a4316c1402200d41b154a892a98d40c4d39e619992cca1eba4b5939bbf2b418062cd1275a8b101210302649cc91eda9d5fbc9d41b4a14f98917a00cdc6fc952c9fdf8a98a544cfcca9ffffffff561ee4189323bf8f619bcedd1f9e02033adb588db31cb3dc7ec3bda23f73aac4000000006b483045022100d4a5ab03675f585cc055c76fdaa80333757c42583883dfcde08cb0aeb57f256a022063440e24ef4ef5b44dcb0e7aacaa4562effd80f9a1d9b273daa581066c8359fb0121035c0e6d900a5e8c27901ce7edcdc9bfafea44dbfb714274271114245d7e895198ffffffff56cf1fa6d5779fd2bded063d63455809373ff2bf79edf921be7e92f918ef43df010000006b48304502210091d15d5fcb518103f04fdc819513200d30033f9a1e29960458375e7c71247d31022064a233c4073ac88652a0324f6973914b08bfcf76e928afae0099dc2d7eb227750121032946d47c35c0a98ae7ccad30fee846007434fff25cf70973b5c76deb4be2a14fffffffff4754ee214a33da0116730b43238cc6ff0510b8cebc59a42b1f0609e2a10aa8c8000000006b483045022100f3cea95cd6451d706fb1766cec30450ef000649df15d7d7bebcecbfe6ec48e98022016e687a7d956d2ab089d76306046d33ce5ace55fcb4595021de3f97c4293d1b601210367db63755cf13760c81b8cb0c13eee10474064dfacc7c45a8c3271b5b058f0ccffffffff025e489467030000001976a9147283e4813a5e5fb8d723e75403ba10e05a7820db88ac60f71b00000000001976a914d740ff057317d3b12d5a6dadac5bb7ff87e48afe88ac578a0500";
len = (int32_t)strlen(txstr) >> 1;
decode_hex(txdata,len,txstr);
vcalc_sha256(0,txid.bytes,txdata,len);
txid2 = bits256_doublesha256(0,txdata,len);
HashKeccak(ktxid.bytes,txdata,len);
printf("txid %s\n",bits256_str(str,txid));
printf("txid2 %s\n",bits256_str(str,txid2));
printf("ktxid %s\n",bits256_str(str,ktxid));
}
}
}
}
@ -1426,7 +1439,7 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu
//strcpy(LP_publicaddr,pushaddr);
//LP_publicport = mypullport;
//LP_mybussock = LP_coinbus(mybusport);
printf("got %s, initpeers. LP_mypubsock.%d pullsock.%d RPC_port.%u mypullport.%d mypubport.%d pushaddr.%s\n",myipaddr,LP_mypubsock,LP_mypullsock,RPC_port,mypullport,mypubport,pushaddr);
printf("got %s, initpeers. LP_mypubsock.%d pullsock.%d RPC_port.%u mypullport.%d mypubport.%d\n",myipaddr,LP_mypubsock,LP_mypullsock,RPC_port,mypullport,mypubport);
LP_passphrase_init(passphrase,jstr(argjson,"gui"),juint(argjson,"netid"),jstr(argjson,"seednode"));
#ifndef FROM_JS
if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_psockloop,(void *)myipaddr) != 0 )

17
iguana/exchanges/LP_network.c

@ -433,7 +433,7 @@ struct LP_queuedcommand
void LP_commandQ_loop(void *ctx)
{
struct LP_queuedcommand *ptr,*tmp; int32_t size,nonz; char *retstr; cJSON *argjson,*retjson,*result;
struct LP_queuedcommand *ptr,*tmp; int32_t len,size,nonz; char *retstr; cJSON *argjson,*retjson,*result;
while ( LP_STOP_RECEIVED == 0 )
{
nonz = 0;
@ -443,9 +443,9 @@ void LP_commandQ_loop(void *ctx)
portable_mutex_lock(&LP_commandQmutex);
DL_DELETE(LP_commandQ,ptr);
portable_mutex_unlock(&LP_commandQmutex);
if ( ptr->stats_JSONonly < 0 )
if ( ptr->stats_JSONonly < 0 ) // broadcast passthrough
{
if ( ptr->responsesock >= 0 )
if ( 1 && ptr->responsesock >= 0 )
{
if ( (result= cJSON_Parse(ptr->msg)) != 0 )
{
@ -455,6 +455,7 @@ void LP_commandQ_loop(void *ctx)
retstr = jprint(retjson,1);
if ( (size= nn_send(ptr->responsesock,retstr,(int32_t)strlen(retstr),0)) <= 0 )
printf("error sending event\n");
free(retstr);
}
}
}
@ -462,9 +463,10 @@ void LP_commandQ_loop(void *ctx)
{
if ( (retstr= LP_command_process(ctx,"127.0.0.1",ptr->responsesock,argjson,(uint8_t *)ptr->msg,ptr->msglen,ptr->stats_JSONonly)) != 0 )
{
//printf("processed.(%s)\n",retstr);
if ( ptr->retstrp != 0 )
(*ptr->retstrp) = retstr;
if ( 0 && ptr->queueid != 0 )
printf("sock.%d queueid.%d processed.(%s) -> (%s)\n",ptr->responsesock,ptr->queueid,ptr->msg,retstr);
if ( ptr->responsesock >= 0 )
{
if ( (result= cJSON_Parse(retstr)) != 0 && ptr->queueid != 0 )
@ -474,8 +476,12 @@ void LP_commandQ_loop(void *ctx)
jaddnum(retjson,"queueid",ptr->queueid);
jadd(retjson,"result",result);
retstr = jprint(retjson,1);
//printf("send (%s)\n",retstr);
}
if ( (size= nn_send(ptr->responsesock,retstr,(int32_t)strlen(retstr)+1,0)) <= 0 )
len = (int32_t)strlen(retstr);
if ( ptr->queueid == 0 )
len++;
if ( (size= nn_send(ptr->responsesock,retstr,len,0)) <= 0 )
printf("error sending result\n");
}
if ( retstr != 0 )
@ -504,6 +510,7 @@ void LP_queuecommand(char **retstrp,char *buf,int32_t responsesock,int32_t stats
if ( (ptr->retstrp= retstrp) != 0 )
*retstrp = 0;
ptr->msglen = msglen;
ptr->queueid = queueid;
ptr->responsesock = responsesock;
ptr->stats_JSONonly = stats_JSONonly;
memcpy(ptr->msg,buf,msglen);

24
iguana/exchanges/LP_ordermatch.c

@ -531,6 +531,9 @@ int32_t LP_connectstartbob(void *ctx,int32_t pubsock,char *base,char *rel,double
printf("bob tries %u-%u again i.%d\n",swap->I.req.requestid,swap->I.req.quoteid,i);
LP_reserved_msg(1,qp->srccoin,qp->destcoin,zero,jprint(reqjson,0));
}
sleep(1);
printf("send CONNECT for %u-%u\n",qp->R.requestid,qp->R.quoteid);
LP_reserved_msg(1,qp->srccoin,qp->destcoin,zero,jprint(reqjson,0));
if ( IPC_ENDPOINT >= 0 )
LP_queuecommand(0,jprint(reqjson,1),IPC_ENDPOINT,-1,0);
else free_json(reqjson);
@ -891,7 +894,7 @@ double LP_trades_pricevalidate(struct LP_quoteinfo *qp,struct iguana_info *coin,
struct LP_quoteinfo *LP_trades_gotrequest(void *ctx,struct LP_quoteinfo *qp,struct LP_quoteinfo *newqp,char *pairstr)
{
double price=0.,p=0.,qprice,myprice,bestprice,range,bid,ask; struct iguana_info *coin,*othercoin; struct LP_utxoinfo A,B,*autxo,*butxo; cJSON *reqjson; char str[65]; struct LP_address_utxo *utxos[1000]; int32_t i,r,counter,max = (int32_t)(sizeof(utxos)/sizeof(*utxos));
double price=0.,p=0.,qprice,myprice,bestprice,range,bid,ask; struct iguana_info *coin,*othercoin; struct LP_utxoinfo A,B,*autxo,*butxo; cJSON *reqjson; char str[65]; struct LP_address_utxo *utxos[4096]; int32_t i,r,counter,max = (int32_t)(sizeof(utxos)/sizeof(*utxos));
*newqp = *qp;
qp = newqp;
//printf("bob %s received REQUEST.(%llu)\n",bits256_str(str,G.LP_mypub25519),(long long)qp->aliceid);
@ -1443,7 +1446,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,
char *LP_autobuy(void *ctx,char *myipaddr,int32_t mypubsock,char *base,char *rel,double maxprice,double relvolume,int32_t timeout,int32_t duration,char *gui,uint32_t nonce,bits256 destpubkey,uint32_t tradeid)
{
uint64_t desttxfee,txfee; uint32_t lastnonce; int64_t bestsatoshis=0,destsatoshis; struct iguana_info *basecoin,*relcoin; struct LP_utxoinfo *autxo,B,A; struct LP_quoteinfo Q; bits256 pubkeys[100]; struct LP_address_utxo *utxos[1000]; int32_t max=(int32_t)(sizeof(utxos)/sizeof(*utxos));
uint64_t desttxfee,txfee; uint32_t lastnonce; int64_t bestsatoshis=0,destsatoshis; struct iguana_info *basecoin,*relcoin; struct LP_utxoinfo *autxo,B,A; struct LP_quoteinfo Q; bits256 pubkeys[100]; struct LP_address_utxo *utxos[4096]; int32_t maxiters=100,i,max=(int32_t)(sizeof(utxos)/sizeof(*utxos));
basecoin = LP_coinfind(base);
relcoin = LP_coinfind(rel);
if ( gui == 0 )
@ -1488,11 +1491,22 @@ char *LP_autobuy(void *ctx,char *myipaddr,int32_t mypubsock,char *base,char *rel
memset(pubkeys,0,sizeof(pubkeys));
LP_txfees(&txfee,&desttxfee,base,rel);
destsatoshis = SATOSHIDEN * relvolume + 2*desttxfee;
memset(&A,0,sizeof(A));
LP_address_utxo_reset(relcoin);
if ( (autxo= LP_address_myutxopair(&A,0,utxos,max,relcoin,relcoin->smartaddr,txfee,dstr(destsatoshis),maxprice,desttxfee)) == 0 )
autxo = 0;
for (i=0; i<maxiters; i++)
{
memset(&A,0,sizeof(A));
if ( (autxo= LP_address_myutxopair(&A,0,utxos,max,relcoin,relcoin->smartaddr,txfee,dstr(destsatoshis),maxprice,desttxfee)) != 0 )
break;
destsatoshis *= 0.98;
if ( destsatoshis < desttxfee*LP_MINSIZE_TXFEEMULT )
break;
}
if ( destsatoshis < desttxfee*LP_MINSIZE_TXFEEMULT || i == maxiters )
{
return(clonestr("{\"error\":\"cant find a deposit that is close enough in size. make another deposit that is just a bit larger than what you want to trade\"}"));
//printf("bestfit selected alice (%.8f %.8f) for %.8f sats %.8f\n",dstr(autxo->payment.value),dstr(autxo->fee.value),dstr(destsatoshis),dstr(autxo->swap_satoshis));
}
printf("bestfit.[%d] selected alice (%.8f %.8f) for %.8f sats %.8f\n",i,dstr(autxo->payment.value),dstr(autxo->fee.value),dstr(destsatoshis),dstr(autxo->swap_satoshis));
if ( destsatoshis - desttxfee < autxo->swap_satoshis )
{
destsatoshis -= desttxfee;

9
iguana/exchanges/LP_prices.c

@ -644,9 +644,14 @@ struct LP_priceinfo *LP_priceinfoadd(char *symbol)
struct LP_priceinfo *pp; cJSON *retjson;
if ( symbol == 0 )
return(0);
if ( (pp= LP_priceinfofind(symbol)) != 0 )
{
printf("%s already there\n",symbol);
return(pp);
}
if ( LP_numpriceinfos >= sizeof(LP_priceinfos)/sizeof(*LP_priceinfos) )
{
printf("cant add any more priceinfos\n");
printf("cant add any more priceinfos than %d\n",LP_numpriceinfos);
return(0);
}
pp = &LP_priceinfos[LP_numpriceinfos];
@ -654,7 +659,7 @@ struct LP_priceinfo *LP_priceinfoadd(char *symbol)
safecopy(pp->symbol,symbol,sizeof(pp->symbol));
pp->coinbits = stringbits(symbol);
pp->ind = LP_numpriceinfos++;
LP_numpriceinfos++;
//LP_numpriceinfos++;
if ( (retjson= LP_priceinfomatrix(0)) != 0 )
free_json(retjson);
return(pp);

49
iguana/exchanges/LP_privkey.c

@ -536,7 +536,7 @@ int32_t JPG_encrypt(uint16_t ind,uint8_t encoded[JPG_ENCRYPTED_MAXSIZE],uint8_t
int32_t i; for (i=0; i<msglen; i++)
printf("%02x",encoded[i]);
printf(" encoded.%d\n",msglen);
return(msglen);
return(msglen);
}
uint8_t *JPG_decrypt(uint16_t *indp,int32_t *recvlenp,uint8_t space[JPG_ENCRYPTED_MAXSIZE + crypto_box_ZEROBYTES],uint8_t *encoded,bits256 privkey)
@ -552,11 +552,14 @@ uint8_t *JPG_decrypt(uint16_t *indp,int32_t *recvlenp,uint8_t space[JPG_ENCRYPTE
cipherlen = msglen - (len + crypto_box_NONCEBYTES);
if ( cipherlen > 0 && cipherlen <= JPG_ENCRYPTED_MAXSIZE + crypto_box_ZEROBYTES )
{
//int32_t i; for (i=0; i<cipherlen; i++)
// printf("%02x",cipher[i]);
//printf(" cipherlen\n");
if ( (extracted= _SuperNET_decipher(nonce,cipher,space,cipherlen,pubkey,privkey)) != 0 )
{
int32_t i; for (i=0; i<msglen; i++)
printf("%02x",encoded[i]);
printf(" restored\n");
//int32_t i; for (i=0; i<msglen; i++)
// printf("%02x",encoded[i]);
//printf(" restored\n");
msglen = (cipherlen - crypto_box_ZEROBYTES);
*recvlenp = msglen;
*indp = ind;
@ -565,6 +568,44 @@ uint8_t *JPG_decrypt(uint16_t *indp,int32_t *recvlenp,uint8_t space[JPG_ENCRYPTE
return(extracted);
}
int32_t LP_opreturn_decrypt(uint16_t *ind16p,uint8_t *decoded,uint8_t *encoded,int32_t encodedlen,char *passphrase)
{
bits256 privkey; int32_t msglen; uint8_t *extracted,space[JPG_ENCRYPTED_MAXSIZE + crypto_box_ZEROBYTES];
if ( passphrase != 0 && passphrase[0] != 0 )
{
vcalc_sha256(0,privkey.bytes,(uint8_t *)passphrase,(int32_t)strlen(passphrase));
msglen = ((int32_t)encoded[1] << 8) | encoded[0];
*ind16p = ((int32_t)encoded[3] << 8) | encoded[2];
if ( msglen == encodedlen && (extracted= JPG_decrypt(ind16p,&msglen,space,encoded,privkey)) != 0 )
{
memcpy(decoded,extracted,msglen);
return(msglen);
} else return(-1);
}
else
{
*ind16p = calc_crc32(0,extracted,encodedlen);
memcpy(decoded,extracted,encodedlen);
return(encodedlen);
}
}
int32_t LP_opreturn_encrypt(uint8_t *dest,int32_t maxsize,uint8_t *data,int32_t datalen,char *passphrase,uint16_t ind16)
{
bits256 privkey; int32_t len; uint8_t encoded[JPG_ENCRYPTED_MAXSIZE];
vcalc_sha256(0,privkey.bytes,(uint8_t *)passphrase,(int32_t)strlen(passphrase));
if ( (len= JPG_encrypt(ind16,encoded,data,datalen,privkey)) > 0 )
{
//printf("datalen.%d -> len.%d max.%d\n",datalen,len,maxsize);
if ( len <= maxsize )
{
memcpy(dest,encoded,len);
return(len);
}
}
return(-1);
}
// from https://github.com/owencm/C-Steganography-Framework
#include "../../crypto777/jpeg/cdjpeg.h" // Common decls for compressing and decompressing jpegs

31
iguana/exchanges/LP_rpc.c

@ -401,7 +401,7 @@ int32_t LP_address_isvalid(char *symbol,char *address)
cJSON *LP_listunspent(char *symbol,char *coinaddr,bits256 reftxid,bits256 reftxid2)
{
char buf[128],*retstr; struct LP_address *ap; cJSON *retjson; int32_t numconfs,usecache=1; struct iguana_info *coin;
char buf[128],*retstr; bits256 txid; struct LP_address *ap; cJSON *retjson,*txjson,*array,*item; int32_t i,n,numconfs,vout,usecache=1; struct iguana_info *coin;
if ( symbol == 0 || symbol[0] == 0 )
return(cJSON_Parse("{\"error\":\"null symbol\"}"));
coin = LP_coinfind(symbol);
@ -431,9 +431,26 @@ cJSON *LP_listunspent(char *symbol,char *coinaddr,bits256 reftxid,bits256 reftxi
sprintf(buf,"[%d, 99999999, [\"%s\"]]",numconfs,coinaddr);
//printf("LP_listunspent.(%s %s)\n",symbol,coinaddr);
retjson = bitcoin_json(coin,"listunspent",buf);
retstr = jprint(retjson,0);
LP_unspents_cache(coin->symbol,coinaddr,retstr,1);
free(retstr);
if ( (n= cJSON_GetArraySize(retjson)) > 0 )
{
array = cJSON_CreateArray();
for (i=0; i<n; i++)
{
item = jitem(retjson,i);
txid = jbits256(item,"txid");
vout = jint(item,"vout");
if ( (txjson= LP_gettxout(symbol,coinaddr,txid,vout)) != 0 )
{
jaddi(array,jduplicate(item));
free_json(txjson);
}
}
free_json(retjson);
retjson = array;
retstr = jprint(array,0);
LP_unspents_cache(coin->symbol,coinaddr,retstr,1);
free(retstr);
}
if ( ap != 0 )
ap->unspenttime = (uint32_t)time(NULL);
return(retjson);
@ -540,7 +557,8 @@ int32_t LP_importaddress(char *symbol,char *address)
return(-2);
coin = LP_coinfind(symbol);
if ( coin == 0 )
return(-2);
return(-3);
//printf("import.(%s %s)\n",symbol,address);
if ( coin->electrum != 0 )
{
/*if ( (retjson= electrum_address_subscribe(symbol,coin->electrum,&retjson,address)) != 0 )
@ -554,6 +572,7 @@ int32_t LP_importaddress(char *symbol,char *address)
{
if ( (validatejson= LP_validateaddress(symbol,address)) != 0 )
{
//printf("validated.(%s)\n",jprint(validatejson,0));
if ( (isvalid= is_cJSON_True(jobj(validatejson,"isvalid")) != 0) != 0 )
{
if ( is_cJSON_True(jobj(validatejson,"iswatchonly")) != 0 || is_cJSON_True(jobj(validatejson,"ismine")) != 0 )
@ -561,6 +580,7 @@ int32_t LP_importaddress(char *symbol,char *address)
}
free_json(validatejson);
}
//printf("%s (%s) isvalid.%d doneflag.%d\n",symbol,address,isvalid,doneflag);
if ( isvalid == 0 )
return(-1);
if ( doneflag != 0 )
@ -590,7 +610,6 @@ cJSON *LP_importprivkey(char *symbol,char *wifstr,char *label,int32_t flag)
ctx = bitcoin_ctx();
bitcoin_wif2addr(ctx,symbol,coin->wiftaddr,coin->taddr,coin->pubtype,address,wifstr);
#ifdef LP_DONT_IMPORTPRIVKEY
//bitcoin_wif2addr(ctx,symbol,coin->wiftaddr,coin->taddr,coin->pubtype,address,wifstr);
if ( LP_importaddress(symbol,address) < 0 )
{
printf("%s importaddress %s from %s failed, isvalid.%d\n",symbol,address,wifstr,bitcoin_validaddress(symbol,coin->taddr,coin->pubtype,coin->p2shtype,address));

151
iguana/exchanges/LP_transaction.c

@ -1226,10 +1226,10 @@ int32_t LP_vins_select(void *ctx,struct iguana_info *coin,int64_t *totalp,int64_
return(n);
}
char *LP_createrawtransaction(cJSON **txobjp,int32_t *numvinsp,struct iguana_info *coin,struct vin_info *V,int32_t max,bits256 privkey,cJSON *outputs,cJSON *vins,cJSON *privkeys,int64_t txfee,bits256 utxotxid,int32_t utxovout,uint32_t locktime,char *opretstr)
char *LP_createrawtransaction(cJSON **txobjp,int32_t *numvinsp,struct iguana_info *coin,struct vin_info *V,int32_t max,bits256 privkey,cJSON *outputs,cJSON *vins,cJSON *privkeys,int64_t txfee,bits256 utxotxid,int32_t utxovout,uint32_t locktime,char *opretstr,char *passphrase)
{
static void *ctx;
cJSON *txobj,*item; uint8_t addrtype,rmd160[20],script[8192],spendscript[256]; char *coinaddr,*rawtxbytes,*scriptstr; bits256 txid; uint32_t timestamp; int64_t change=0,adjust=0,total,value,amount = 0; int32_t i,len,dustcombine,scriptlen,spendlen,suppress_pubkeys,ignore_cltverr,numvouts=0,numvins=0,numutxos=0; struct LP_address_utxo *utxos[LP_MAXVINS*256]; struct LP_address *ap;
cJSON *txobj,*item; uint8_t addrtype,rmd160[20],data[8192+64],script[8192],spendscript[256]; char *coinaddr,*rawtxbytes,*scriptstr; bits256 txid; uint32_t crc32,timestamp; int64_t change=0,adjust=0,total,value,amount = 0; int32_t origspendlen=0,i,offset,len,dustcombine,scriptlen,spendlen,suppress_pubkeys,ignore_cltverr,numvouts=0,numvins=0,numutxos=0; struct LP_address_utxo *utxos[LP_MAXVINS*256]; struct LP_address *ap;
if ( ctx == 0 )
ctx = bitcoin_ctx();
*numvinsp = 0;
@ -1335,6 +1335,7 @@ char *LP_createrawtransaction(cJSON **txobjp,int32_t *numvinsp,struct iguana_inf
else
{
printf("custom script.%d too long %d\n",i,spendlen);
free_json(txobj);
return(0);
}
}
@ -1346,7 +1347,7 @@ char *LP_createrawtransaction(cJSON **txobjp,int32_t *numvinsp,struct iguana_inf
else spendlen = bitcoin_p2shspend(spendscript,0,rmd160);
if ( i == numvouts-1 && strcmp(coinaddr,coin->smartaddr) == 0 && change != 0 )
{
printf("combine last vout %.8f with change %.8f\n",dstr(value+adjust),dstr(change));
//printf("combine last vout %.8f with change %.8f\n",dstr(value+adjust),dstr(change));
value += change;
change = 0;
}
@ -1370,8 +1371,22 @@ char *LP_createrawtransaction(cJSON **txobjp,int32_t *numvinsp,struct iguana_inf
if ( opretstr != 0 )
{
spendlen = (int32_t)strlen(opretstr) >> 1;
if ( spendlen < sizeof(script) )
if ( spendlen < sizeof(script)-60 )
{
if ( passphrase != 0 && passphrase[0] != 0 )
{
decode_hex(data,spendlen,opretstr);
offset = 2 + (spendlen >= 16);
origspendlen = spendlen;
crc32 = calc_crc32(0,data,spendlen);
spendlen = LP_opreturn_encrypt(&script[offset],(int32_t)sizeof(script)-offset,data,spendlen,passphrase,crc32&0xffff);
if ( spendlen < 0 )
{
printf("error encrpting opreturn data\n");
free_json(txobj);
return(0);
}
} else offset = crc32 = 0;
len = 0;
script[len++] = SCRIPT_OP_RETURN;
if ( spendlen < 76 )
@ -1387,13 +1402,27 @@ char *LP_createrawtransaction(cJSON **txobjp,int32_t *numvinsp,struct iguana_inf
script[len++] = (spendlen & 0xff);
script[len++] = ((spendlen >> 8) & 0xff);
}
decode_hex(&script[len],spendlen,opretstr);
if ( passphrase != 0 && passphrase[0] != 0 )
{
if ( offset != len )
{
printf("offset.%d vs len.%d, reencrypt\n",offset,len);
spendlen = LP_opreturn_encrypt(&script[len],(int32_t)sizeof(script)-len,data,origspendlen,passphrase,crc32&0xffff);
if ( spendlen < 0 )
{
printf("error encrpting opreturn data\n");
free_json(txobj);
return(0);
}
} //else printf("offset.%d already in right place\n",offset);
} else decode_hex(&script[len],spendlen,opretstr);
txobj = bitcoin_txoutput(txobj,script,len + spendlen,0);
printf("OP_RETURN.[%d, %d] script.(%s)\n",len,spendlen,opretstr);
//printf("OP_RETURN.[%d, %d] script.(%s)\n",len,spendlen,opretstr);
}
else
{
printf("custom script.%d too long %d\n",i,spendlen);
free_json(txobj);
return(0);
}
}
@ -1405,10 +1434,96 @@ char *LP_createrawtransaction(cJSON **txobjp,int32_t *numvinsp,struct iguana_inf
return(rawtxbytes);
}
char *LP_opreturndecrypt(void *ctx,char *symbol,bits256 utxotxid,char *passphrase)
{
cJSON *txjson,*vouts,*opret,*sobj,*retjson; uint16_t utxovout; char *opretstr,*hexstr; uint8_t *opretdata,*databuf,*decoded; uint16_t ind16; uint32_t crc32; int32_t i,len,numvouts,opretlen,datalen; struct iguana_info *coin;
if ( (coin= LP_coinfind(symbol)) == 0 )
return(clonestr("{\"error\":\"cant find coin\"}"));
retjson = cJSON_CreateObject();
utxovout = 0;
if ( (txjson= LP_gettx("LP_opreturn_decrypt",coin->symbol,utxotxid,1)) != 0 )
{
if ( (vouts= jarray(&numvouts,txjson,"vout")) != 0 && numvouts >= 1 )
{
opret = jitem(vouts,numvouts - 1);
jaddstr(retjson,"coin",symbol);
jaddbits256(retjson,"opreturntxid",utxotxid);
if ( (sobj= jobj(opret,"scriptPubKey")) != 0 )
{
if ( (opretstr= jstr(sobj,"hex")) != 0 )
{
jaddstr(retjson,"opreturn",opretstr);
opretlen = (int32_t)strlen(opretstr) >> 1;
opretdata = malloc(opretlen);
decode_hex(opretdata,opretlen,opretstr);
databuf = &opretdata[2];
datalen = 0;
if ( opretdata[0] != 0x6a )
jaddstr(retjson,"error","not opreturn data");
else if ( (datalen= opretdata[1]) < 76 )
{
if ( &databuf[datalen] != &opretdata[opretlen] )
databuf = 0, jaddstr(retjson,"error","mismatched short opretlen");
}
else if ( opretdata[1] == 0x4c )
{
datalen = opretdata[2];
databuf++;
if ( &databuf[datalen] != &opretdata[opretlen] )
databuf = 0, jaddstr(retjson,"error","mismatched opretlen");
}
else if ( opretdata[1] == 0x4d )
{
datalen = opretdata[3];
datalen <<= 8;
datalen |= opretdata[2];
databuf += 2;
if ( &databuf[datalen] != &opretdata[opretlen] )
databuf = 0, jaddstr(retjson,"error","mismatched big opretlen");
}
else databuf = 0, jaddstr(retjson,"error","unexpected opreturn data type");
if ( databuf != 0 )
{
decoded = calloc(1,opretlen+1);
if ( (len= LP_opreturn_decrypt(&ind16,decoded,databuf,datalen,passphrase)) < 0 )
jaddstr(retjson,"error","decrypt error");
else
{
crc32 = calc_crc32(0,decoded,len);
if ( (crc32 & 0xffff) == ind16 )
{
jaddstr(retjson,"result","success");
hexstr = malloc(len*2+1);
init_hexbytes_noT(hexstr,decoded,len);
jaddstr(retjson,"decrypted",hexstr);
for (i=0; i<len; i++)
if ( isprint(decoded[i]) == 0 )
break;
if ( i == len )
{
memcpy(hexstr,decoded,len);
hexstr[len] = 0;
jaddstr(retjson,"original",hexstr);
}
free(hexstr);
} else jaddstr(retjson,"error","decrypt crc16 error");
}
free(decoded);
}
free(opretdata);
}
}
}
free_json(txjson);
}
return(jprint(retjson,1));
}
char *LP_withdraw(struct iguana_info *coin,cJSON *argjson)
{
static void *ctx;
int32_t iter,i,utxovout,autofee,completed=0,maxV,numvins,numvouts,datalen,suppress_pubkeys; bits256 privkey; struct LP_address *ap; char changeaddr[64],vinaddr[64],str[65],*signedtx=0,*rawtx=0; struct vin_info *V; uint32_t locktime; cJSON *retjson,*item,*outputs,*vins=0,*txobj=0,*privkeys=0; struct iguana_msgtx msgtx; bits256 utxotxid,signedtxid; uint64_t txfee,newtxfee=10000;
int32_t allocated_outputs=0,iter,i,utxovout,autofee,completed=0,maxV,numvins,numvouts,datalen,suppress_pubkeys; bits256 privkey; struct LP_address *ap; char changeaddr[64],vinaddr[64],str[65],*signedtx=0,*rawtx=0; struct vin_info *V; uint32_t locktime; cJSON *retjson,*item,*outputs,*vins=0,*txobj=0,*privkeys=0; struct iguana_msgtx msgtx; bits256 utxotxid,signedtxid; uint64_t txfee,newtxfee=10000;
//printf("withdraw.%s %s\n",coin->symbol,jprint(argjson,0));
if ( coin->etomic[0] != 0 )
{
if ( (coin= LP_coinfind("ETOMIC")) == 0 )
@ -1418,8 +1533,20 @@ char *LP_withdraw(struct iguana_info *coin,cJSON *argjson)
ctx = bitcoin_ctx();
if ( (outputs= jarray(&numvouts,argjson,"outputs")) == 0 )
{
printf("no outputs in argjson (%s)\n",jprint(argjson,0));
return(clonestr("{\"error\":\"no outputs specified\"}"));
if ( jstr(argjson,"opreturn") == 0 )
{
printf("no outputs in argjson (%s)\n",jprint(argjson,0));
return(clonestr("{\"error\":\"no outputs specified\"}"));
}
else
{
outputs = cJSON_CreateArray();
item = cJSON_CreateObject();
jaddnum(item,coin->smartaddr,0.0001);
jaddi(outputs,item);
numvouts = 1;
allocated_outputs = 1;
}
}
utxotxid = jbits256(argjson,"utxotxid");
utxovout = jint(argjson,"utxovout");
@ -1446,13 +1573,15 @@ char *LP_withdraw(struct iguana_info *coin,cJSON *argjson)
{
printf("LP_withdraw error utxo reset %s\n",coin->symbol);
free(V);
if ( allocated_outputs != 0 )
free_json(outputs);
return(0);
}
privkeys = cJSON_CreateArray();
vins = cJSON_CreateArray();
memset(V,0,sizeof(*V) * maxV);
numvins = 0;
if ( (rawtx= LP_createrawtransaction(&txobj,&numvins,coin,V,maxV,privkey,outputs,vins,privkeys,iter == 0 ? txfee : newtxfee,utxotxid,utxovout,locktime,jstr(argjson,"opreturn"))) != 0 )
if ( (rawtx= LP_createrawtransaction(&txobj,&numvins,coin,V,maxV,privkey,outputs,vins,privkeys,iter == 0 ? txfee : newtxfee,utxotxid,utxovout,locktime,jstr(argjson,"opreturn"),jstr(argjson,"passphrase"))) != 0 )
{
completed = 0;
memset(&msgtx,0,sizeof(msgtx));
@ -1513,6 +1642,8 @@ char *LP_withdraw(struct iguana_info *coin,cJSON *argjson)
jadd(retjson,"tx",txobj);
jaddbits256(retjson,"txid",signedtxid);
jadd(retjson,"complete",completed!=0?jtrue():jfalse());
if ( allocated_outputs != 0 )
free_json(outputs);
return(jprint(retjson,1));
}

12
iguana/exchanges/LP_utxo.c

@ -471,7 +471,7 @@ int32_t LP_address_utxoadd(int32_t skipsearch,uint32_t timestamp,char *debug,str
struct LP_address *LP_address_utxo_reset(struct iguana_info *coin)
{
struct LP_address *ap; struct LP_address_utxo *up,*tmp; int32_t i,n,m,vout,height; cJSON *array,*item,*txobj; bits256 zero; int64_t value; bits256 txid; uint32_t now;
struct LP_address *ap; struct LP_address_utxo *up,*tmp; int32_t i,n,numconfs,m,vout,height; cJSON *array,*item,*txobj; bits256 zero; int64_t value; bits256 txid; uint32_t now;
LP_address(coin,coin->smartaddr);
memset(zero.bytes,0,sizeof(zero));
LP_listunspent_issue(coin->symbol,coin->smartaddr,2,zero,zero);
@ -511,10 +511,16 @@ struct LP_address *LP_address_utxo_reset(struct iguana_info *coin)
if ( 1 )
{
if ( (txobj= LP_gettxout(coin->symbol,coin->smartaddr,txid,vout)) == 0 )
{
//printf("skip null gettxout %s.v%d\n",bits256_str(str,txid),vout);
continue;
}
else free_json(txobj);
if ( LP_numconfirms(coin->symbol,coin->smartaddr,txid,vout,0) <= 0 )
if ( (numconfs= LP_numconfirms(coin->symbol,coin->smartaddr,txid,vout,0)) <= 0 )
{
//printf("skip numconfs.%d %s.v%d\n",numconfs,bits256_str(str,txid),vout);
continue;
}
}
LP_address_utxoadd(1,now,"withdraw",coin,coin->smartaddr,txid,vout,value,height,-1);
if ( (up= LP_address_utxofind(coin,coin->smartaddr,txid,vout)) == 0 )
@ -525,7 +531,7 @@ struct LP_address *LP_address_utxo_reset(struct iguana_info *coin)
//printf("%.8f ",dstr(value));
}
}
printf("added %d from %s listunspents\n",m,coin->symbol);
printf("added %d of %d from %s listunspents\n",m,n,coin->symbol);
}
free_json(array);
}

2
iguana/exchanges/coins

File diff suppressed because one or more lines are too long

4
iguana/exchanges/mm.c

@ -204,8 +204,8 @@ int main(int argc, const char * argv[])
nn_freemsg(ptr);
}
}
}
}
} else printf("nn_connect error to IPC_ENDPOINT\n");
} else printf("error opening IPC_ENDPOINT\n");
}
else if ( argv[1] != 0 && strcmp(argv[1],"hush") == 0 )
{

6
iguana/exchanges/opreturn

@ -0,0 +1,6 @@
#!/bin/bash
source userpass
curl -X POST --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"withdraw\",\"coin\":\"COQUI\",\"passphrase\":\"$2\", \"opreturn\":\"$(echo -n "$1" | od -A n -t x1 | perl -pe 's/\W+//g')\"}"
#curl -X POST --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"withdraw\",\"coin\":\"COQUI\",\"outputs\":[{\"RGCVXhUxepCxh77thy7XgMrQ5XU9u7SWSR\":0.01}], \"opreturn\":\"$(echo -n "$1" | od -A n -t x1 | perl -pe 's/\W+//g')\"}"
#curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"withdraw\",\"coin\":\"HUSH\",\"outputs\":[{\"t1JTXxWyBrxdWNTaNa5gYPPfpJkhqESvyov\":$1}], \"opreturn\":\"deadbeef\"}"

5
iguana/exchanges/opreturndecrypt

@ -0,0 +1,5 @@
#!/bin/bash
source userpass
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"opreturndecrypt\",\"coin\":\"KMD\",\"txid\":\"06e59c6e9217ef1e526a1419e231e5f927689765feab9cd48167e089301f6fc2\",\"passphrase\":\"test\"}"
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"opreturndecrypt\",\"coin\":\"KMD\",\"txid\":\"34bf4bc2247e43c0c6a2223b79d3f1a3e9962102fb4a563612e5bbb91fb85348\",\"passphrase\":\"test\"}"
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"opreturndecrypt\",\"coin\":\"KMD\",\"txid\":\"a9e94e6890d6998b3c2b89685e8c7c2b9e380a53fb813192701d0966480807eb\",\"passphrase\":\"test\"}"

6
iguana/exchanges/stats.c

@ -516,7 +516,7 @@ char *stats_rpcparse(char *retbuf,int32_t bufsize,int32_t *jsonflagp,int32_t *po
cJSON *retitem,*retarray = cJSON_CreateArray();
origargjson = argjson;
symbol[0] = 0;
for (i=0; i<n; i++)
for (i=0; i<n; i++) // array cmd path doesnt support event streaming
{
argjson = jitem(origargjson,i);
if ( userpass != 0 && jstr(argjson,"userpass") == 0 )
@ -573,7 +573,7 @@ char *stats_rpcparse(char *retbuf,int32_t bufsize,int32_t *jsonflagp,int32_t *po
if ( IPC_ENDPOINT >= 0 && (queueid= juint(arg,"queueid")) > 0 )
{
buf = jprint(arg,0);
LP_queuecommand(&retstr,buf,IPC_ENDPOINT,-1,queueid);
LP_queuecommand(&retstr,buf,IPC_ENDPOINT,1,queueid);
free(buf);
retstr = clonestr("{\"result\":\"success\",\"status\":\"queued\"}");
} else retstr = stats_JSON(ctx,"127.0.0.1",-1,arg,remoteaddr,port);
@ -582,7 +582,7 @@ char *stats_rpcparse(char *retbuf,int32_t bufsize,int32_t *jsonflagp,int32_t *po
if ( IPC_ENDPOINT >= 0 && (queueid= juint(arg,"queueid")) > 0 )
{
buf = jprint(arg,0);
LP_queuecommand(&retstr,buf,IPC_ENDPOINT,-1,queueid);
LP_queuecommand(&retstr,buf,IPC_ENDPOINT,1,queueid);
free(buf);
} else retstr = stats_JSON(ctx,myipaddr,-1,arg,remoteaddr,port);
#endif

4
iguana/iguana_blocks.c

@ -137,7 +137,7 @@ void iguana_blockcopy(uint8_t zcash,uint8_t auxpow,struct iguana_info *coin,stru
}
}
bits256 iguana_merkle(bits256 *tree,int32_t txn_count)
/*bits256 iguana_merkle(bits256 *tree,int32_t txn_count)
{
int32_t i,n=0,prev; uint8_t serialized[sizeof(bits256) * 2];
if ( txn_count == 1 )
@ -158,7 +158,7 @@ bits256 iguana_merkle(bits256 *tree,int32_t txn_count)
txn_count >>= 1;
}
return(tree[n]);
}
}*/
struct iguana_block *iguana_prevblock(struct iguana_info *coin,struct iguana_block *block,int32_t PoSflag)
{

142
iguana/iguana_notary.c

@ -58,81 +58,6 @@ void dpow_checkpointset(struct supernet_info *myinfo,struct dpow_checkpoint *che
checkpoint->blockhash.height = height;
}
int32_t dpow_txhasnotarization(struct supernet_info *myinfo,struct iguana_info *coin,bits256 txid)
{
cJSON *txobj,*vins,*vin,*vouts,*vout,*spentobj,*sobj; char *hexstr; uint8_t script[35]; bits256 spenttxid; uint64_t notarymask; int32_t i,j,numnotaries,len,spentvout,numvins,numvouts,hasnotarization = 0;
if ( (txobj= dpow_gettransaction(myinfo,coin,txid)) != 0 )
{
if ( (vins= jarray(&numvins,txobj,"vin")) != 0 )
{
if ( numvins >= DPOW_MIN_ASSETCHAIN_SIGS )
{
notarymask = numnotaries = 0;
for (i=0; i<numvins; i++)
{
vin = jitem(vins,i);
spenttxid = jbits256(vin,"txid");
spentvout = jint(vin,"vout");
if ( (spentobj= dpow_gettransaction(myinfo,coin,spenttxid)) != 0 )
{
if ( (vouts= jarray(&numvouts,spentobj,"vout")) != 0 )
{
if ( spentvout < numvouts )
{
vout = jitem(vouts,spentvout);
if ( (sobj= jobj(vout,"scriptPubKey")) != 0 && (hexstr= jstr(sobj,"hex")) != 0 && (len= is_hexstr(hexstr,0)) == sizeof(script)*2 )
{
len >>= 1;
decode_hex(script,len,hexstr);
if ( script[0] == 33 && script[34] == 0xac )
{
for (j=0; j<sizeof(Notaries_elected)/sizeof(*Notaries_elected); j++)
{
if ( strncmp(Notaries_elected[j][1],hexstr+2,66) == 0 )
{
if ( ((1LL << j) & notarymask) == 0 )
{
printf("n%d ",j);
numnotaries++;
notarymask |= (1LL << j);
break;
}
}
}
}
}
}
}
free_json(spentobj);
}
}
if ( numnotaries > 0 )
{
if ( numnotaries >= DPOW_MIN_ASSETCHAIN_SIGS )
hasnotarization = 1;
printf("numnotaries.%d %s hasnotarization.%d\n",numnotaries,coin->symbol,hasnotarization);
}
}
}
free_json(txobj);
}
return(hasnotarization);
}
int32_t dpow_hasnotarization(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *blockjson)
{
int32_t i,n,hasnotarization = 0; bits256 txid; cJSON *txarray;
if ( (txarray= jarray(&n,blockjson,"tx")) != 0 )
{
for (i=0; i<n; i++)
{
txid = jbits256i(txarray,i);
hasnotarization += dpow_txhasnotarization(myinfo,coin,txid);
}
}
return(hasnotarization);
}
void dpow_srcupdate(struct supernet_info *myinfo,struct dpow_info *dp,int32_t height,bits256 hash,uint32_t timestamp,uint32_t blocktime)
{
void **ptrs; char str[65]; cJSON *blockjson; struct iguana_info *coin; struct dpow_checkpoint checkpoint; int32_t freq,minsigs,i,ht; struct dpow_block *bp;
@ -141,17 +66,17 @@ void dpow_srcupdate(struct supernet_info *myinfo,struct dpow_info *dp,int32_t he
if ( strcmp("BTC",dp->dest) == 0 )
{
freq = DPOW_CHECKPOINTFREQ;
minsigs = DPOW_MINSIGS;
minsigs = Notaries_BTCminsigs; //DPOW_MINSIGS;
}
else
{
minsigs = DPOW_MIN_ASSETCHAIN_SIGS;
minsigs = Notaries_minsigs; //DPOW_MIN_ASSETCHAIN_SIGS;
if ( strcmp("CHIPS",dp->symbol) == 0 )
freq = 100;
else freq = 1;
}
dpow_fifoupdate(myinfo,dp->srcfifo,dp->last);
if ( strcmp(dp->dest,"KMD") == 0 )
if ( strcmp(dp->dest,"KMD") == 0 || strcmp(dp->dest,"CHAIN") == 0 )
{
//if ( dp->SRCREALTIME == 0 )
// return;
@ -162,9 +87,9 @@ void dpow_srcupdate(struct supernet_info *myinfo,struct dpow_info *dp,int32_t he
{
if ( (blockjson= dpow_getblock(myinfo,coin,hash)) != 0 )
{
if ( dpow_hasnotarization(myinfo,coin,blockjson) <= 0 )
height = jint(blockjson,"height");
if ( dpow_hasnotarization(myinfo,coin,blockjson,height) <= 0 )
{
height = jint(blockjson,"height");
blocktime = juint(blockjson,"time");
free_json(blockjson);
if ( height > 0 && blocktime > 0 )
@ -197,9 +122,9 @@ void dpow_srcupdate(struct supernet_info *myinfo,struct dpow_info *dp,int32_t he
ptrs[0] = (void *)myinfo;
ptrs[1] = (void *)dp;
ptrs[2] = (void *)(uint64_t)minsigs;
if ( strcmp(dp->dest,"KMD") == 0 )
ptrs[3] = (void *)(DPOW_DURATION * 60); // essentially try forever for assetchains
else ptrs[3] = (void *)DPOW_DURATION;
if ( strcmp(dp->dest,"KMD") != 0 && strcmp(dp->dest,"CHAIN") != 0 )
ptrs[3] = (void *)DPOW_DURATION;
else ptrs[3] = (void *)(DPOW_DURATION * 60); // essentially try forever for assetchains
ptrs[4] = 0;
memcpy(&ptrs[5],&checkpoint,sizeof(checkpoint));
dp->activehash = checkpoint.blockhash.hash;
@ -264,7 +189,7 @@ void dpow_destupdate(struct supernet_info *myinfo,struct dpow_info *dp,int32_t h
dpow_fifoupdate(myinfo,dp->destfifo,dp->destchaintip);
if ( strcmp(dp->dest,"BTC") == 0 )
{
printf("%s destupdate ht.%d\n",dp->dest,height);
//printf("%s destupdate ht.%d\n",dp->dest,height);
dpow_destconfirm(myinfo,dp,&dp->destfifo[DPOW_BTCCONFIRMS]);
}
else dpow_destconfirm(myinfo,dp,&dp->destfifo[DPOW_KOMODOCONFIRMS*2]); // todo: change to notarized KMD depth
@ -272,22 +197,22 @@ void dpow_destupdate(struct supernet_info *myinfo,struct dpow_info *dp,int32_t h
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:"");
int32_t height,num; uint32_t blocktime; bits256 blockhash,merkleroot; struct iguana_info *src,*dest;
//if ( strcmp(dp->symbol,"KMD") == 0 )
{
num = dpow_nanomsg_update(myinfo);
//fprintf(stderr,"%d ",num);
//fprintf(stderr,"nano.%d ",num);
}
src = iguana_coinfind(dp->symbol);
dest = iguana_coinfind(dp->dest);
if ( src != 0 && dest != 0 )
{
//fprintf(stderr,"dp.%p dPoWupdate (%s -> %s)\n",dp,dp!=0?dp->symbol:"",dp!=0?dp->dest:"");
dp->numdesttx = sizeof(dp->desttx)/sizeof(*dp->desttx);
if ( (height= dpow_getchaintip(myinfo,&blockhash,&blocktime,dp->desttx,&dp->numdesttx,dest)) != dp->destchaintip.blockhash.height && height >= 0 )
if ( (height= dpow_getchaintip(myinfo,&merkleroot,&blockhash,&blocktime,dp->desttx,&dp->numdesttx,dest)) != dp->destchaintip.blockhash.height && height >= 0 )
{
char str[65];
if ( strcmp(dp->symbol,"KMD") == 0 )//|| height != dp->destchaintip.blockhash.height+1 )
if ( (0) && strcmp(dp->symbol,"KMD") == 0 )//|| height != dp->destchaintip.blockhash.height+1 )
printf("[%s].%d %s %s height.%d vs last.%d\n",dp->symbol,dp->SRCHEIGHT,dp->dest,bits256_str(str,blockhash),height,dp->destchaintip.blockhash.height);
if ( height <= dp->destchaintip.blockhash.height )
{
@ -297,13 +222,13 @@ void iguana_dPoWupdate(struct supernet_info *myinfo,struct dpow_info *dp)
} else dpow_destupdate(myinfo,dp,height,blockhash,(uint32_t)time(NULL),blocktime);
} // else printf("error getchaintip for %s\n",dp->dest);
dp->numsrctx = sizeof(dp->srctx)/sizeof(*dp->srctx);
if ( strcmp(dp->dest,"KMD") == 0 && dp->SRCHEIGHT < src->longestchain )
if ( (strcmp(dp->dest,"KMD") == 0 || strcmp(dp->dest,"CHAIN") == 0) && dp->SRCHEIGHT < src->longestchain )
{
//fprintf(stderr,"[I ");
dp->SRCHEIGHT = dpow_issuer_iteration(dp,src,dp->SRCHEIGHT,&dp->SRCREALTIME);
//fprintf(stderr," %d] ",dp->SRCHEIGHT);
}
if ( (height= dpow_getchaintip(myinfo,&blockhash,&blocktime,dp->srctx,&dp->numsrctx,src)) != dp->last.blockhash.height && height >= 0 )
if ( (height= dpow_getchaintip(myinfo,&merkleroot,&blockhash,&blocktime,dp->srctx,&dp->numsrctx,src)) != dp->last.blockhash.height && height >= 0 )
{
//char str[65]; printf("[%s].%d %s %s height.%d vs last.%d\n",dp->dest,dp->SRCHEIGHT,dp->symbol,bits256_str(str,blockhash),height,dp->last.blockhash.height);
if ( dp->lastheight == 0 )
@ -347,9 +272,9 @@ void iguana_dPoWupdate(struct supernet_info *myinfo,struct dpow_info *dp)
void dpow_addresses()
{
int32_t i; char coinaddr[64]; uint8_t pubkey[33];
for (i=0; i<sizeof(Notaries)/sizeof(*Notaries); i++)
for (i=0; i<Notaries_num; i++)
{
decode_hex(pubkey,33,Notaries[i][1]);
decode_hex(pubkey,33,Notaries_elected[i][1]);
bitcoin_address(coinaddr,60,pubkey,33);
printf("%s ",coinaddr);
}
@ -360,9 +285,9 @@ void dpow_addresses()
#include "../includes/iguana_apideclares.h"
#include "../includes/iguana_apideclares2.h"
TWO_STRINGS(iguana,dpow,symbol,pubkey)
THREE_STRINGS(iguana,dpow,symbol,dest,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];
char *retstr,srcaddr[64],destaddr[64]; struct iguana_info *src,*destcoin; cJSON *ismine; int32_t i,srcvalid,destvalid; struct dpow_info *dp = &myinfo->DPOWS[myinfo->numdpows];
destvalid = srcvalid = 0;
if ( myinfo->NOTARY.RELAYID < 0 )
{
@ -380,21 +305,22 @@ TWO_STRINGS(iguana,dpow,symbol,pubkey)
return(clonestr("{\"error\":\"need 33 byte pubkey\"}"));
if ( symbol == 0 || symbol[0] == 0 )
symbol = "KMD";
if ( dest == 0 || dest[0] == 0 )
{
if ( strcmp(symbol,"KMD") == 0 )
dest = "BTC";
else dest = "KMD";
}
//if ( myinfo->numdpows == 1 )
// komodo_assetcoins(-1);
if ( iguana_coinfind(symbol) == 0 )
return(clonestr("{\"error\":\"cant dPoW an inactive coin\"}"));
if ( strcmp(symbol,"KMD") == 0 && iguana_coinfind("BTC") == 0 )
return(clonestr("{\"error\":\"cant dPoW KMD without BTC\"}"));
else if ( myinfo->numdpows == 0 && strcmp(symbol,"KMD") != 0 && iguana_coinfind("KMD") == 0 )
return(clonestr("{\"error\":\"cant dPoW without KMD\"}"));
else if ( iguana_coinfind(dest) == 0 )
return(clonestr("{\"error\":\"cant dPoW without KMD (dest)\"}"));
if ( myinfo->numdpows > 1 )
{
if ( strcmp(symbol,"KMD") == 0 || iguana_coinfind("BTC") == 0 )
{
dp->symbol[0] = 0;
return(clonestr("{\"error\":\"cant dPoW KMD or BTC again\"}"));
}
for (i=1; i<myinfo->numdpows; i++)
if ( strcmp(symbol,myinfo->DPOWS[i].symbol) == 0 )
{
@ -410,14 +336,14 @@ TWO_STRINGS(iguana,dpow,symbol,pubkey)
}
else
{
strcpy(dp->dest,"KMD");
strcpy(dp->dest,dest);
dp->srcconfirms = DPOW_THIRDPARTY_CONFIRMS;
}
if ( dp->srcconfirms > DPOW_FIFOSIZE )
dp->srcconfirms = DPOW_FIFOSIZE;
src = iguana_coinfind(dp->symbol);
dest = iguana_coinfind(dp->dest);
if ( src == 0 || dest == 0 )
destcoin = iguana_coinfind(dp->dest);
if ( src == 0 || destcoin == 0 )
{
dp->symbol[0] = 0;
return(clonestr("{\"error\":\"source coin or dest coin not there\"}"));
@ -435,8 +361,8 @@ TWO_STRINGS(iguana,dpow,symbol,pubkey)
free(retstr);
retstr = 0;
}
bitcoin_address(destaddr,dest->chain->pubtype,dp->minerkey33,33);
if ( (retstr= dpow_validateaddress(myinfo,dest,destaddr)) != 0 )
bitcoin_address(destaddr,destcoin->chain->pubtype,dp->minerkey33,33);
if ( (retstr= dpow_validateaddress(myinfo,destcoin,destaddr)) != 0 )
{
json = cJSON_Parse(retstr);
if ( (ismine= jobj(json,"ismine")) != 0 && is_cJSON_True(ismine) != 0 )
@ -626,7 +552,7 @@ void _iguana_notarystats(char *fname,int32_t totals[64],int32_t dispflag)
if ( dispflag != 0 )
{
printf("after %s\n",fname);
for (i=0; i<64; i++)
for (i=0; i<Notaries_num; i++)
{
if ( totals[i] != 0 )
printf("%s, %d\n",Notaries_elected[i][0],totals[i]);

2
iguana/iguana_recv.c

@ -704,7 +704,7 @@ int32_t iguana_txmerkle(struct iguana_info *coin,bits256 *tree,int32_t treesize,
{
for (i=0; i<origtxdata->zblock.RO.txn_count; i++)
tree[i] = txarray[i].txid;
merkle_root = iguana_merkle(tree,origtxdata->zblock.RO.txn_count);
merkle_root = iguana_merkle(coin->symbol,tree,origtxdata->zblock.RO.txn_count);
if ( bits256_cmp(merkle_root,origtxdata->zblock.RO.merkle_root) != 0 )
{
char str[65],str2[65];

2
iguana/iguana_tx.c

@ -346,7 +346,7 @@ int32_t iguana_peerblockrequest(struct supernet_info *myinfo,struct iguana_info
}
if ( i == block->RO.txn_count )
{
merkle_root = iguana_merkle(tree,block->RO.txn_count);
merkle_root = iguana_merkle(coin->symbol,tree,block->RO.txn_count);
if ( bits256_cmp(merkle_root,block->RO.merkle_root) == 0 )
{
if ( addr != 0 && addr->lastsent != block->height )

2
iguana/kmd_lookup.h

@ -354,7 +354,7 @@ 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 ( (curlstr= bitcoind_getinfo(coin->symbol,coin->chain->serverport,coin->chain->userpass,coin->getinfostr)) != 0 )
{
if ( (curljson= cJSON_Parse(curlstr)) != 0 )
{

2
iguana/m_notary

@ -2,4 +2,4 @@
pkill -15 iguana
rm -f ../agents/iguana *.o
git pull
./m_notary_run
./m_notary_run $1

2
iguana/m_notary_run

@ -8,7 +8,7 @@ clang -g -Wno-deprecated -c -O2 -DISNOTARYNODE=1 -DLIQUIDITY_PROVIDER=1 *.c ../b
clang -g -Wno-deprecated -c -DISNOTARYNODE=1 -DLIQUIDITY_PROVIDER=1 main.c iguana777.c iguana_bundles.c ../basilisk/basilisk.c
clang -g -o ../agents/iguana *.o ../agents/libcrypto777.a -lnanomsg -lcurl -lssl -lcrypto -lpthread -lz -lm
../agents/iguana notary & #> iguana.log 2> error.log &
stdbuf -oL $1 ../agents/iguana notary & #> iguana.log 2> error.log &
myip=`curl -s4 checkip.amazonaws.com`
source pubkey.txt

26
iguana/main.c

@ -2157,9 +2157,11 @@ void komodo_REVS_merge(char *str,char *str2)
getchar();
}
int32_t komodo_initjson(char *fname);
void iguana_main(void *arg)
{
int32_t usessl = 0,ismainnet = 1, do_OStests = 0; struct supernet_info *myinfo;
int32_t usessl = 0,ismainnet = 1, do_OStests = 0; struct supernet_info *myinfo; char *elected = "elected";
if ( (IGUANA_BIGENDIAN= iguana_isbigendian()) > 0 )
printf("BIGENDIAN\n");
else if ( IGUANA_BIGENDIAN == 0 )
@ -2192,7 +2194,6 @@ void iguana_main(void *arg)
iguana_Qinit();
libgfshare_init(myinfo,myinfo->logs,myinfo->exps);
myinfo->dpowsock = myinfo->dexsock = myinfo->pubsock = myinfo->subsock = myinfo->reqsock = myinfo->repsock = -1;
dex_init(myinfo);
myinfo->psockport = 30000;
if ( arg != 0 )
{
@ -2206,18 +2207,31 @@ void iguana_main(void *arg)
iguana_notarystats(totals,1);
exit(0);
}
else if ( strcmp((char *)arg,"notary") == 0 )
else if ( strncmp((char *)arg,"-port=",6) == 0 )
{
myinfo->rpcport = atoi(&((char *)arg)[6]);
printf("OVERRIDE IGUANA port <- %u\n",myinfo->rpcport);
}
else if ( strcmp((char *)arg,"notary") == 0 ) // must be second to last
{
myinfo->rpcport = IGUANA_NOTARYPORT;
myinfo->IAMNOTARY = 1;
myinfo->DEXEXPLORER = 0;//1; disable as SPV is used now
}
else if ( strncmp((char *)arg,"-port=",6) == 0 )
else
{
myinfo->rpcport = atoi(&((char *)arg)[6]);
printf("OVERRIDE IGUANA port <- %u\n",myinfo->rpcport);
myinfo->rpcport = IGUANA_NOTARYPORT;
myinfo->IAMNOTARY = 1;
myinfo->DEXEXPLORER = 0;//1; disable as SPV is used now
elected = (char *)arg;
}
}
if ( komodo_initjson(elected) < 0 )
{
printf("didnt find any elected notaries JSON in (%s)\n",elected);
exit(-1);
}
dex_init(myinfo);
#ifdef IGUANA_OSTESTS
do_OStests = 1;
#endif

2
includes/iguana_apideclares.h

@ -173,7 +173,7 @@ STRING_AND_INT(iguana,snapshot,symbol,height);
INT_ARRAY_STRING(iguana,dividends,height,vals,symbol);
THREE_STRINGS(iguana,passthru,asset,function,hex);
STRING_ARG(iguana,initfastfind,activecoin);
TWO_STRINGS(iguana,dpow,symbol,pubkey);
THREE_STRINGS(iguana,dpow,symbol,dest,pubkey);
STRING_ARG(iguana,peers,activecoin);
STRING_AND_INT(iguana,maxpeers,activecoin,max);
STRING_ARG(iguana,getconnectioncount,activecoin);

2
includes/iguana_funcs.h

@ -416,7 +416,7 @@ int32_t iguana_bundlefname(struct iguana_info *coin,struct iguana_bundle *bp,cha
int32_t iguana_bundleremove(struct iguana_info *coin,int32_t hdrsi,int32_t tmpfiles);
int32_t iguana_voutsfname(struct iguana_info *coin,int32_t roflag,char *fname,int32_t slotid);
int32_t iguana_vinsfname(struct iguana_info *coin,int32_t roflag,char *fname,int32_t slotid);
bits256 iguana_merkle(bits256 *tree,int32_t txn_count);
bits256 iguana_merkle(char *symbol,bits256 *tree,int32_t txn_count);
int32_t iguana_bundleready(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_bundle *bp,int32_t requiredflag);
int32_t iguana_blast(struct iguana_info *coin,struct iguana_peer *addr);
int32_t iguana_validated(struct iguana_info *coin);

2
includes/iguana_structs.h

@ -528,7 +528,7 @@ struct iguana_info
#ifdef DEPRECATED_HHUTXO
struct iguana_hhaccount *accountstable;
#endif
char lastdispstr[2048];
char lastdispstr[2048],getinfostr[64];
double txidfind_totalmillis,txidfind_num,spendtxid_totalmillis,spendtxid_num;
struct iguana_monitorinfo monitoring[256];
int32_t notarychain,didaddresses;

Loading…
Cancel
Save