Browse Source

Merge pull request #669 from jl777/jl777

notarize Merkle of Merkle
patch-3
jl777 7 years ago
committed by GitHub
parent
commit
f4b685bccd
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      basilisk/basilisk.c
  2. 2
      crypto777/OS_portable.h
  3. 37
      crypto777/iguana_utils.c
  4. 2
      datachain/datachain.c
  5. 2
      gecko/gecko_miner.c
  6. 6
      iguana/dPoW.h
  7. 147
      iguana/dpow/dpow_fsm.c
  8. 5
      iguana/dpow/dpow_network.c
  9. 7
      iguana/dpow/dpow_rpc.c
  10. 5
      iguana/dpow/dpow_tx.c
  11. 15
      iguana/exchanges/LP_bitcoin.c
  12. 23
      iguana/exchanges/LP_cache.c
  13. 5
      iguana/exchanges/LP_commands.c
  14. 21
      iguana/exchanges/LP_rpc.c
  15. 2
      iguana/exchanges/coins
  16. 4
      iguana/iguana_blocks.c
  17. 120
      iguana/iguana_notary.c
  18. 2
      iguana/iguana_recv.c
  19. 2
      iguana/iguana_tx.c
  20. 2
      includes/iguana_apideclares.h
  21. 2
      includes/iguana_funcs.h

4
basilisk/basilisk.c

@ -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);

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 )
{

6
iguana/dPoW.h

@ -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 )
{
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;

5
iguana/dpow/dpow_network.c

@ -1899,8 +1899,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);
}
char str[65];
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);
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\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));
}
}
@ -2241,7 +2242,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

7
iguana/dpow/dpow_rpc.c

@ -266,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 )
{
@ -746,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;
@ -758,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;

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 && src_or_dest == 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 )

15
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 && 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 bits256_calcaddrhash(char *symbol,uint8_t *serialized,int32_t len)
{
bits256 hash;

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;

5
iguana/exchanges/LP_commands.c

@ -247,8 +247,8 @@ jpg(srcfile, destfile, power2=7, password, data="", required, ind=0)\n\
{
if ( (IPC_ENDPOINT= nn_socket(AF_SP,NN_PAIR)) >= 0 )
{
sprintf(bindpoint,"ws://*:%u",port);
sprintf(endpoint,"ws://127.0.0.1:%u",port);
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");
@ -261,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);

21
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);
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);

2
iguana/exchanges/coins

File diff suppressed because one or more lines are too long

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)
{

120
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<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\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;
@ -151,7 +76,7 @@ void dpow_srcupdate(struct supernet_info *myinfo,struct dpow_info *dp,int32_t he
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;
@ -161,10 +86,10 @@ void dpow_srcupdate(struct supernet_info *myinfo,struct dpow_info *dp,int32_t he
if ( bits256_nonz(hash) != 0 )
{
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 )
{
blocktime = juint(blockjson,"time");
free_json(blockjson);
if ( height > 0 && blocktime > 0 )
@ -197,7 +122,7 @@ 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 )
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;
@ -272,7 +197,7 @@ 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;
int32_t height,num; uint32_t blocktime; bits256 blockhash,merkleroot; struct iguana_info *src,*dest;
//fprintf(stderr,"dp.%p dPoWupdate (%s -> %s)\n",dp,dp!=0?dp->symbol:"",dp!=0?dp->dest:"");
//if ( strcmp(dp->symbol,"KMD") == 0 )
{
@ -284,7 +209,7 @@ void iguana_dPoWupdate(struct supernet_info *myinfo,struct dpow_info *dp)
if ( src != 0 && dest != 0 )
{
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 )
@ -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 )
@ -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 )

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
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);

Loading…
Cancel
Save