From aba9ea3c91bceed6deb7601d9cc3db48035719dc Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 22 Nov 2016 15:35:14 -0300 Subject: [PATCH 01/56] test --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index bc5fa3e80..dd4eda01a 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -560,7 +560,7 @@ int32_t komodo_checkpoint(int32_t *notarized_heightp,int32_t nHeight,uint256 has return(-1); notarized_height = komodo_notarizeddata(pindex->nHeight,¬arized_hash,¬arized_desttxid); *notarized_heightp = notarized_height; - if ( nHeight >= 79700 && notarized_height >= 0 && notarized_height <= pindex->nHeight && (notary= mapBlockIndex[notarized_hash]) != 0 ) + if ( notarized_height >= 0 && notarized_height <= pindex->nHeight && (notary= mapBlockIndex[notarized_hash]) != 0 ) { //printf("nHeight.%d -> (%d %s)\n",pindex->Tip()->nHeight,notarized_height,notarized_hash.ToString().c_str()); if ( notary->nHeight == notarized_height ) // if notarized_hash not in chain, reorg From 508b0d3c8866f23af9245f1a9fc4fac5c8ebc558 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 22 Nov 2016 16:05:15 -0300 Subject: [PATCH 02/56] test --- src/komodo.h | 6 +++--- src/komodo_gateway.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 141ca8f2d..350c2afab 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -370,7 +370,7 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr else if ( opretlen == 0x4d ) { opretlen = scriptbuf[len++]; - opretlen = (opretlen << 8) + scriptbuf[len++]; + opretlen += (scriptbuf[len++] << 8); } if ( j == 1 && opretlen >= 32*2+4 && strcmp(ASSETCHAINS_SYMBOL[0]==0?"KMD":ASSETCHAINS_SYMBOL,(char *)&scriptbuf[len+32*2+4]) == 0 ) { @@ -492,8 +492,8 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) } } numvalid = bitweight(signedmask); - //if ( height == 79633 ) - // notarized = 1; + if ( height == 79633 ) + notarized = 1; if ( (((height < 90000 || (signedmask & 1) != 0) && numvalid >= KOMODO_MINRATIFY) || bitweight(signedmask) > (numnotaries>>1)) ) { printf("%s ht.%d txi.%d signedmask.%llx numvins.%d numvouts.%d <<<<<<<<<<< notarized\n",ASSETCHAINS_SYMBOL,height,i,(long long)signedmask,numvins,numvouts); diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 51eb5f02e..38aeb1847 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -480,7 +480,7 @@ void komodo_passport_iteration() else refid = komodo_baseid(ASSETCHAINS_SYMBOL)+1; // illegal base -> baseid.-1 -> 0 //printf("PASSPORT %s refid.%d\n",ASSETCHAINS_SYMBOL,refid); for (baseid=0; baseid<=32; baseid++) - {break; + { sp = 0; isrealtime = 0; base = (char *)CURRENCIES[baseid]; From 367fadca6e3be321923740dd94c39cbb6318765d Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 22 Nov 2016 18:07:20 -0300 Subject: [PATCH 03/56] test --- src/komodo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index 350c2afab..4c89f3d6c 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -379,12 +379,12 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr len += iguana_rwbignum(0,&scriptbuf[len],32,(uint8_t *)&desttxid); if ( notarized != 0 && *notarizedheightp > sp->NOTARIZED_HEIGHT && *notarizedheightp < height ) { - printf("%s ht.%d NOTARIZED.%d %s.%s %sTXID.%s (%s)\n",ASSETCHAINS_SYMBOL,height,*notarizedheightp,ASSETCHAINS_SYMBOL[0]==0?"KMD":ASSETCHAINS_SYMBOL,kmdtxid.ToString().c_str(),ASSETCHAINS_SYMBOL[0]==0?"BTC":"KMD",desttxid.ToString().c_str(),(char *)&scriptbuf[len]); sp->NOTARIZED_HEIGHT = *notarizedheightp; sp->NOTARIZED_HASH = kmdtxid; sp->NOTARIZED_DESTTXID = desttxid; komodo_stateupdate(height,0,0,0,zero,0,0,0,0,0,0,0,0,0,0); len += 4; + printf("%s ht.%d NOTARIZED.%d %s.%s %sTXID.%s (%s) lens.(%d %d)\n",ASSETCHAINS_SYMBOL,height,*notarizedheightp,ASSETCHAINS_SYMBOL[0]==0?"KMD":ASSETCHAINS_SYMBOL,kmdtxid.ToString().c_str(),ASSETCHAINS_SYMBOL[0]==0?"BTC":"KMD",desttxid.ToString().c_str(),(char *)&scriptbuf[len],opretlen,len); if ( opretlen > len )//&& scriptbuf[len] == 'A' ) { printf("Found extradata.[%d] %d - %d\n",opretlen-len,opretlen,len); From 826bfe519441aed0d4cbbdfff7f586f12bfbe39d Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 22 Nov 2016 19:08:54 -0300 Subject: [PATCH 04/56] test --- src/komodo_gateway.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 38aeb1847..5127ce1bd 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -369,12 +369,6 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 memset(kmdheights,0,sizeof(kmdheights)); memset(otherheights,0,sizeof(otherheights)); tokomodo = (komodo_is_issuer() == 0); - if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 ) - { - for (i=0; i 0 ) { From 52e872488f0f0dd070f43b29c95526ab3dd41223 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 23 Nov 2016 10:44:56 -0300 Subject: [PATCH 05/56] test --- src/komodo_gateway.h | 6 +++++- src/miner.cpp | 7 +++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 5127ce1bd..120952004 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -144,7 +144,11 @@ int32_t komodo_issued_opreturn(char *base,uint256 *txids,uint16_t *vouts,int64_t memcpy(&rmd160s[n * 20],p.rmd160,20); baseids[n] = komodo_baseid(p.symbol); } - printf(">>>>>>> iskomodo X: (%s) fiat %.8f kmdheight.%d other.%d\n",symbol,dstr(fiatoshis),height,otherheight); + { + char coinaddr[64]; + bitcoin_address(coinaddr,60,p.rmd160,20); + printf(">>>>>>> approved A: (%s) fiat %.8f kmdheight.%d other.%d -> %s %.8f\n",baseids[n]>=0?CURRENCIES[baseids[n]]:"???",dstr(p.fiatoshis),p.height,p.otherheight,coinaddr,dstr(p.komodoshis)); + } } else { diff --git a/src/miner.cpp b/src/miner.cpp index 0bb74a0cc..737af64f5 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -99,7 +99,7 @@ void UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams, } #define ASSETCHAINS_MINHEIGHT 100 -#define ROUNDROBIN_DELAY 77 +#define ROUNDROBIN_DELAY 59 extern int32_t ASSETCHAINS_SEED,IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAIN_INIT,KOMODO_INITDONE,KOMODO_ON_DEMAND,KOMODO_INITDONE; extern char ASSETCHAINS_SYMBOL[16]; extern std::string NOTARY_PUBKEY; @@ -644,7 +644,10 @@ void static BitcoinMiner(CWallet *pwallet) if ( ASSETCHAINS_SYMBOL[0] == 0 && Mining_start != 0 && time(NULL) < Mining_start+ROUNDROBIN_DELAY ) { //printf("Round robin diff sleep %d\n",(int32_t)(Mining_start+ROUNDROBIN_DELAY-time(NULL))); - sleep(Mining_start+ROUNDROBIN_DELAY-time(NULL)); + int32_t nseconds = Mining_start+ROUNDROBIN_DELAY-time(NULL); + if ( nseconds > 0 ) + sleep(nseconds); + MilliSleep((rand() % 2000) + 1); KOMODO_CHOSEN_ONE = 1; } // Found a solution From ddf827b285bc5823cadc8606c991df5a37cb7bab Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 23 Nov 2016 11:08:44 -0300 Subject: [PATCH 06/56] test --- src/komodo_gateway.h | 41 ++++++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 120952004..a7d1e879f 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -106,17 +106,36 @@ void komodo_gateway_deposit(char *coinaddr,uint64_t value,char *symbol,uint64_t int32_t komodo_rwapproval(int32_t rwflag,uint8_t *opretbuf,struct pax_transaction *pax) { int32_t i,len = 0; - for (i=0; i<32; i++) - opretbuf[len++] = ((uint8_t *)&pax->txid)[i]; - opretbuf[len++] = pax->vout & 0xff; - opretbuf[len++] = (pax->vout >> 8) & 0xff; - len += iguana_rwnum(1,&opretbuf[len],sizeof(pax->fiatoshis),&pax->komodoshis); - len += iguana_rwnum(1,&opretbuf[len],sizeof(pax->fiatoshis),&pax->fiatoshis); - len += iguana_rwnum(1,&opretbuf[len],sizeof(pax->height),&pax->height); - len += iguana_rwnum(1,&opretbuf[len],sizeof(pax->otherheight),&pax->otherheight); - memcpy(&opretbuf[len],pax->rmd160,20), len += 20; - for (i=0; i<4; i++) - opretbuf[len++] = pax->source[i]; + if ( rwflag == 1 ) + { + for (i=0; i<32; i++) + opretbuf[len++] = ((uint8_t *)&pax->txid)[i]; + opretbuf[len++] = pax->vout & 0xff; + opretbuf[len++] = (pax->vout >> 8) & 0xff; + } + else + { + for (i=0; i<32; i++) + ((uint8_t *)&pax->txid)[i] = opretbuf[len++]; + pax->vout = opretbuf[len++]; + pax->vout += ((uint32_t)opretbuf[len++] << 8); + } + len += iguana_rwnum(rwflag,&opretbuf[len],sizeof(pax->fiatoshis),&pax->komodoshis); + len += iguana_rwnum(rwflag,&opretbuf[len],sizeof(pax->fiatoshis),&pax->fiatoshis); + len += iguana_rwnum(rwflag,&opretbuf[len],sizeof(pax->height),&pax->height); + len += iguana_rwnum(rwflag,&opretbuf[len],sizeof(pax->otherheight),&pax->otherheight); + if ( rwflag != 0 ) + { + memcpy(&opretbuf[len],pax->rmd160,20), len += 20; + for (i=0; i<4; i++) + opretbuf[len++] = pax->source[i]; + } + else + { + memcpy(pax->rmd160,&opretbuf[len],20), len += 20; + for (i=0; i<4; i++) + pax->source[i] = opretbuf[len++]; + } return(len); } From ad66994d08b440ae8a6654a3746ceaf1955b6530 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 23 Nov 2016 11:14:55 -0300 Subject: [PATCH 07/56] test --- src/komodo_gateway.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index a7d1e879f..de250015e 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -116,11 +116,15 @@ int32_t komodo_rwapproval(int32_t rwflag,uint8_t *opretbuf,struct pax_transactio else { for (i=0; i<32; i++) + { ((uint8_t *)&pax->txid)[i] = opretbuf[len++]; + printf("%02x ",((uint8_t *)&pax->txid)[i]); + } pax->vout = opretbuf[len++]; pax->vout += ((uint32_t)opretbuf[len++] << 8); + printf(" txid v.%d\n",pax->vout); } - len += iguana_rwnum(rwflag,&opretbuf[len],sizeof(pax->fiatoshis),&pax->komodoshis); + len += iguana_rwnum(rwflag,&opretbuf[len],sizeof(pax->komodoshis),&pax->komodoshis); len += iguana_rwnum(rwflag,&opretbuf[len],sizeof(pax->fiatoshis),&pax->fiatoshis); len += iguana_rwnum(rwflag,&opretbuf[len],sizeof(pax->height),&pax->height); len += iguana_rwnum(rwflag,&opretbuf[len],sizeof(pax->otherheight),&pax->otherheight); @@ -135,6 +139,7 @@ int32_t komodo_rwapproval(int32_t rwflag,uint8_t *opretbuf,struct pax_transactio memcpy(pax->rmd160,&opretbuf[len],20), len += 20; for (i=0; i<4; i++) pax->source[i] = opretbuf[len++]; + printf("%02x %02x %02x %02x\n",source[0],source[1],source[2],source[3]); } return(len); } From a9b072e256c8f42d6f86a95667857f0e4ba107cc Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 23 Nov 2016 11:16:15 -0300 Subject: [PATCH 08/56] test --- src/komodo_gateway.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index de250015e..bd4cbe2e0 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -139,7 +139,7 @@ int32_t komodo_rwapproval(int32_t rwflag,uint8_t *opretbuf,struct pax_transactio memcpy(pax->rmd160,&opretbuf[len],20), len += 20; for (i=0; i<4; i++) pax->source[i] = opretbuf[len++]; - printf("%02x %02x %02x %02x\n",source[0],source[1],source[2],source[3]); + printf("%02x %02x %02x %02x\n",pax->source[0],pax->source[1],pax->source[2],pax->source[3]); } return(len); } From 1dbea87266114ef23c82f91f01e7f1fb34c67dae Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 23 Nov 2016 11:22:35 -0300 Subject: [PATCH 09/56] test --- src/komodo_gateway.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index bd4cbe2e0..49adb0f0f 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -118,7 +118,7 @@ int32_t komodo_rwapproval(int32_t rwflag,uint8_t *opretbuf,struct pax_transactio for (i=0; i<32; i++) { ((uint8_t *)&pax->txid)[i] = opretbuf[len++]; - printf("%02x ",((uint8_t *)&pax->txid)[i]); + printf("%02x",((uint8_t *)&pax->txid)[i]); } pax->vout = opretbuf[len++]; pax->vout += ((uint32_t)opretbuf[len++] << 8); @@ -139,7 +139,7 @@ int32_t komodo_rwapproval(int32_t rwflag,uint8_t *opretbuf,struct pax_transactio memcpy(pax->rmd160,&opretbuf[len],20), len += 20; for (i=0; i<4; i++) pax->source[i] = opretbuf[len++]; - printf("%02x %02x %02x %02x\n",pax->source[0],pax->source[1],pax->source[2],pax->source[3]); + printf("%02x %02x %02x %02x %s\n",pax->source[0],pax->source[1],pax->source[2],pax->source[3],pax->source); } return(len); } @@ -166,7 +166,7 @@ int32_t komodo_issued_opreturn(char *base,uint256 *txids,uint16_t *vouts,int64_t kmdheights[n] = p.height; otherheights[n] = p.otherheight; memcpy(&rmd160s[n * 20],p.rmd160,20); - baseids[n] = komodo_baseid(p.symbol); + baseids[n] = komodo_baseid(p.source); } { char coinaddr[64]; From f2db1a97bdf355cde48b8599c64c56d9a274266a Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 23 Nov 2016 11:25:34 -0300 Subject: [PATCH 10/56] test --- src/komodo.h | 2 +- src/komodo_gateway.h | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 4c89f3d6c..dcb31efd5 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -100,7 +100,7 @@ int32_t komodo_parsestatefile(struct komodo_state *sp,FILE *fp,char *symbol,char if ( fread(¬arized_desttxid,1,sizeof(notarized_desttxid),fp) != sizeof(notarized_desttxid) ) errs++; //if ( 0 && sp != 0 ) - printf("%s %p %p[%d] load[%s] NOTARIZED %d %s\n",ASSETCHAINS_SYMBOL,sp,sp->NPOINTS,sp->NUM_NPOINTS,symbol,notarized_height,notarized_hash.ToString().c_str()); + printf("%s load[%s.%d] NOTARIZED %d %s\n",ASSETCHAINS_SYMBOL,symbol,sp->NUM_NPOINTS,notarized_height,notarized_hash.ToString().c_str()); //if ( matched != 0 ) global independent states -> inside *sp komodo_eventadd_notarized(sp,symbol,ht,dest,notarized_hash,notarized_desttxid,notarized_height); } diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 49adb0f0f..1096909de 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -204,7 +204,8 @@ uint64_t komodo_paxtotal() { if ( komodo_is_issuer() != 0 ) total += pax->fiatoshis; - else total += pax->komodoshis; + else if ( pax->approved != 0 ) + total += pax->komodoshis; } } } @@ -453,7 +454,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 { for (i=0; i 0 ) @@ -473,7 +474,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 } } } - printf("extra.[%d]\n",n); + printf("extra.[%d] after %.8f\n",n,dstr(komodo_paxtotal()); } else if ( tokomodo == 0 && opretbuf[0] == 'I' ) { From 74a9722e8ce1762b249998915d3c938c9f7e545d Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 23 Nov 2016 11:29:20 -0300 Subject: [PATCH 11/56] test --- src/komodo_gateway.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 1096909de..b57e8ba22 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -454,7 +454,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 { for (i=0; i 0 ) From ecfc4f44775bc2cb6e7a15c5f77dc67a321e38c2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 23 Nov 2016 11:33:26 -0300 Subject: [PATCH 12/56] test --- src/komodo_gateway.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index b57e8ba22..a67633ce8 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -474,7 +474,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 } } } - printf("extra.[%d] after %.8f\n",n,dstr(komodo_paxtotal()); + printf("extra.[%d] after %.8f\n",n,dstr(komodo_paxtotal())); } else if ( tokomodo == 0 && opretbuf[0] == 'I' ) { From e8ce1079fa115638dfcb48703502b7667d632e95 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 23 Nov 2016 12:20:11 -0300 Subject: [PATCH 13/56] test --- src/komodo.h | 10 ++++++---- src/komodo_gateway.h | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index dcb31efd5..82f5ec874 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -99,7 +99,7 @@ int32_t komodo_parsestatefile(struct komodo_state *sp,FILE *fp,char *symbol,char errs++; if ( fread(¬arized_desttxid,1,sizeof(notarized_desttxid),fp) != sizeof(notarized_desttxid) ) errs++; - //if ( 0 && sp != 0 ) + if ( 0 && sp != 0 ) printf("%s load[%s.%d] NOTARIZED %d %s\n",ASSETCHAINS_SYMBOL,symbol,sp->NUM_NPOINTS,notarized_height,notarized_hash.ToString().c_str()); //if ( matched != 0 ) global independent states -> inside *sp komodo_eventadd_notarized(sp,symbol,ht,dest,notarized_hash,notarized_desttxid,notarized_height); @@ -384,10 +384,12 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr sp->NOTARIZED_DESTTXID = desttxid; komodo_stateupdate(height,0,0,0,zero,0,0,0,0,0,0,0,0,0,0); len += 4; - printf("%s ht.%d NOTARIZED.%d %s.%s %sTXID.%s (%s) lens.(%d %d)\n",ASSETCHAINS_SYMBOL,height,*notarizedheightp,ASSETCHAINS_SYMBOL[0]==0?"KMD":ASSETCHAINS_SYMBOL,kmdtxid.ToString().c_str(),ASSETCHAINS_SYMBOL[0]==0?"BTC":"KMD",desttxid.ToString().c_str(),(char *)&scriptbuf[len],opretlen,len); - if ( opretlen > len )//&& scriptbuf[len] == 'A' ) + if ( ASSETCHAINS[0] == 0 ) + printf("%s ht.%d NOTARIZED.%d %s.%s %sTXID.%s (%s) lens.(%d %d)\n",ASSETCHAINS_SYMBOL,height,*notarizedheightp,ASSETCHAINS_SYMBOL[0]==0?"KMD":ASSETCHAINS_SYMBOL,kmdtxid.ToString().c_str(),ASSETCHAINS_SYMBOL[0]==0?"BTC":"KMD",desttxid.ToString().c_str(),(char *)&scriptbuf[len],opretlen,len); + if ( ASSETCHAINS[0] == 0 && opretlen > len && scriptbuf[len] == 'A' ) { - printf("Found extradata.[%d] %d - %d\n",opretlen-len,opretlen,len); + if ( ) + printf("Found extradata.[%d] %d - %d\n",opretlen-len,opretlen,len); komodo_stateupdate(height,0,0,0,txhash,0,0,0,0,0,0,value,&scriptbuf[len],opretlen-len,j); } } else printf("notarized.%d %llx reject ht.%d NOTARIZED.%d %s.%s DESTTXID.%s (%s)\n",notarized,(long long)signedmask,height,*notarizedheightp,ASSETCHAINS_SYMBOL[0]==0?"KMD":ASSETCHAINS_SYMBOL,kmdtxid.ToString().c_str(),desttxid.ToString().c_str(),(char *)&scriptbuf[len]); diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index a67633ce8..55883c293 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -117,8 +117,8 @@ int32_t komodo_rwapproval(int32_t rwflag,uint8_t *opretbuf,struct pax_transactio { for (i=0; i<32; i++) { - ((uint8_t *)&pax->txid)[i] = opretbuf[len++]; - printf("%02x",((uint8_t *)&pax->txid)[i]); + ((uint8_t *)&pax->txid)[31-i] = opretbuf[len++]; + printf("%02x",((uint8_t *)&pax->txid)[31-i]); } pax->vout = opretbuf[len++]; pax->vout += ((uint32_t)opretbuf[len++] << 8); From 58033467ff5eecf53c6352a36501046acf22f8d3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 23 Nov 2016 12:37:07 -0300 Subject: [PATCH 14/56] test --- src/komodo.h | 9 ++++----- src/komodo_structs.h | 2 +- src/komodo_utils.h | 10 ++++++++++ src/rpcmisc.cpp | 9 +++++++++ 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 82f5ec874..18a1a3f1d 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -388,8 +388,7 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr printf("%s ht.%d NOTARIZED.%d %s.%s %sTXID.%s (%s) lens.(%d %d)\n",ASSETCHAINS_SYMBOL,height,*notarizedheightp,ASSETCHAINS_SYMBOL[0]==0?"KMD":ASSETCHAINS_SYMBOL,kmdtxid.ToString().c_str(),ASSETCHAINS_SYMBOL[0]==0?"BTC":"KMD",desttxid.ToString().c_str(),(char *)&scriptbuf[len],opretlen,len); if ( ASSETCHAINS[0] == 0 && opretlen > len && scriptbuf[len] == 'A' ) { - if ( ) - printf("Found extradata.[%d] %d - %d\n",opretlen-len,opretlen,len); + printf("Found extradata.[%d] %d - %d\n",opretlen-len,opretlen,len); komodo_stateupdate(height,0,0,0,txhash,0,0,0,0,0,0,value,&scriptbuf[len],opretlen-len,j); } } else printf("notarized.%d %llx reject ht.%d NOTARIZED.%d %s.%s DESTTXID.%s (%s)\n",notarized,(long long)signedmask,height,*notarizedheightp,ASSETCHAINS_SYMBOL[0]==0?"KMD":ASSETCHAINS_SYMBOL,kmdtxid.ToString().c_str(),desttxid.ToString().c_str(),(char *)&scriptbuf[len]); @@ -419,12 +418,12 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr return(notaryid); } -int32_t komodo_isratify(int32_t isspecial,int32_t numvalid) +/*int32_t komodo_isratify(int32_t isspecial,int32_t numvalid) { if ( isspecial != 0 && numvalid >= KOMODO_MINRATIFY ) return(1); else return(0); -} +}*/ // Special tx have vout[0] -> CRYPTO777 // with more than KOMODO_MINRATIFY pay2pubkey outputs -> ratify @@ -496,7 +495,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) numvalid = bitweight(signedmask); if ( height == 79633 ) notarized = 1; - if ( (((height < 90000 || (signedmask & 1) != 0) && numvalid >= KOMODO_MINRATIFY) || bitweight(signedmask) > (numnotaries>>1)) ) + if ( (((height < 90000 || (signedmask & 1) != 0) && numvalid >= KOMODO_MINRATIFY) || numvalid > (numnotaries>>1)) ) { printf("%s ht.%d txi.%d signedmask.%llx numvins.%d numvouts.%d <<<<<<<<<<< notarized\n",ASSETCHAINS_SYMBOL,height,i,(long long)signedmask,numvins,numvouts); notarized = 1; diff --git a/src/komodo_structs.h b/src/komodo_structs.h index b7d776702..309d7a688 100644 --- a/src/komodo_structs.h +++ b/src/komodo_structs.h @@ -23,7 +23,7 @@ #endif*/ #define GENESIS_NBITS 0x1f00ffff -#define KOMODO_MINRATIFY 7 +#define KOMODO_MINRATIFY ((height < 90000) ? 7 : 13) #define KOMODO_MAXBLOCKS 5000000 #define KOMODO_EVENT_RATIFY 'P' diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 399fc4c69..397ce3499 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1429,6 +1429,16 @@ void komodo_ports(uint16_t ports[MAX_CURRENCIES]) char *iguanafmtstr = (char *)"curl --url \"http://127.0.0.1:7778\" --data \"{\\\"conf\\\":\\\"%s.conf\\\",\\\"path\\\":\\\"${HOME#\"/\"}/.komodo/%s\\\",\\\"unitval\\\":\\\"20\\\",\\\"zcash\\\":1,\\\"RELAY\\\":1,\\\"VALIDATE\\\":1,\\\"prefetchlag\\\":-1,\\\"poll\\\":100,\\\"active\\\":1,\\\"agent\\\":\\\"iguana\\\",\\\"method\\\":\\\"addcoin\\\",\\\"startpend\\\":4,\\\"endpend\\\":4,\\\"services\\\":129,\\\"maxpeers\\\":8,\\\"newcoin\\\":\\\"%s\\\",\\\"name\\\":\\\"%s\\\",\\\"hasheaders\\\":1,\\\"useaddmultisig\\\":0,\\\"netmagic\\\":\\\"%s\\\",\\\"p2p\\\":%u,\\\"rpc\\\":%u,\\\"pubval\\\":60,\\\"p2shval\\\":85,\\\"wifval\\\":188,\\\"txfee_satoshis\\\":\\\"10000\\\",\\\"isPoS\\\":0,\\\"minoutput\\\":10000,\\\"minconfirms\\\":2,\\\"genesishash\\\":\\\"027e3758c3a65b12aa1046462b486d0a63bfa1beae327897f56c5cfb7daaae71\\\",\\\"protover\\\":170002,\\\"genesisblock\\\":\\\"0100000000000000000000000000000000000000000000000000000000000000000000003ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000000000000000000000000000000000000000000000000000000000000029ab5f490f0f0f200b00000000000000000000000000000000000000000000000000000000000000fd4005000d5ba7cda5d473947263bf194285317179d2b0d307119c2e7cc4bd8ac456f0774bd52b0cd9249be9d40718b6397a4c7bbd8f2b3272fed2823cd2af4bd1632200ba4bf796727d6347b225f670f292343274cc35099466f5fb5f0cd1c105121b28213d15db2ed7bdba490b4cedc69742a57b7c25af24485e523aadbb77a0144fc76f79ef73bd8530d42b9f3b9bed1c135ad1fe152923fafe98f95f76f1615e64c4abb1137f4c31b218ba2782bc15534788dda2cc08a0ee2987c8b27ff41bd4e31cd5fb5643dfe862c9a02ca9f90c8c51a6671d681d04ad47e4b53b1518d4befafefe8cadfb912f3d03051b1efbf1dfe37b56e93a741d8dfd80d576ca250bee55fab1311fc7b3255977558cdda6f7d6f875306e43a14413facdaed2f46093e0ef1e8f8a963e1632dcbeebd8e49fd16b57d49b08f9762de89157c65233f60c8e38a1f503a48c555f8ec45dedecd574a37601323c27be597b956343107f8bd80f3a925afaf30811df83c402116bb9c1e5231c70fff899a7c82f73c902ba54da53cc459b7bf1113db65cc8f6914d3618560ea69abd13658fa7b6af92d374d6eca9529f8bd565166e4fcbf2a8dfb3c9b69539d4d2ee2e9321b85b331925df195915f2757637c2805e1d4131e1ad9ef9bc1bb1c732d8dba4738716d351ab30c996c8657bab39567ee3b29c6d054b711495c0d52e1cd5d8e55b4f0f0325b97369280755b46a02afd54be4ddd9f77c22272b8bbb17ff5118fedbae2564524e797bd28b5f74f7079d532ccc059807989f94d267f47e724b3f1ecfe00ec9e6541c961080d8891251b84b4480bc292f6a180bea089fef5bbda56e1e41390d7c0e85ba0ef530f7177413481a226465a36ef6afe1e2bca69d2078712b3912bba1a99b1fbff0d355d6ffe726d2bb6fbc103c4ac5756e5bee6e47e17424ebcbf1b63d8cb90ce2e40198b4f4198689daea254307e52a25562f4c1455340f0ffeb10f9d8e914775e37d0edca019fb1b9c6ef81255ed86bc51c5391e0591480f66e2d88c5f4fd7277697968656a9b113ab97f874fdd5f2465e5559533e01ba13ef4a8f7a21d02c30c8ded68e8c54603ab9c8084ef6d9eb4e92c75b078539e2ae786ebab6dab73a09e0aa9ac575bcefb29e930ae656e58bcb513f7e3c17e079dce4f05b5dbc18c2a872b22509740ebe6a3903e00ad1abc55076441862643f93606e3dc35e8d9f2caef3ee6be14d513b2e062b21d0061de3bd56881713a1a5c17f5ace05e1ec09da53f99442df175a49bd154aa96e4949decd52fed79ccf7ccbce32941419c314e374e4a396ac553e17b5340336a1a25c22f9e42a243ba5404450b650acfc826a6e432971ace776e15719515e1634ceb9a4a35061b668c74998d3dfb5827f6238ec015377e6f9c94f38108768cf6e5c8b132e0303fb5a200368f845ad9d46343035a6ff94031df8d8309415bb3f6cd5ede9c135fdabcc030599858d803c0f85be7661c88984d88faa3d26fb0e9aac0056a53f1b5d0baed713c853c4a2726869a0a124a8a5bbc0fc0ef80c8ae4cb53636aa02503b86a1eb9836fcc259823e2692d921d88e1ffc1e6cb2bde43939ceb3f32a611686f539f8f7c9f0bf00381f743607d40960f06d347d1cd8ac8a51969c25e37150efdf7aa4c2037a2fd0516fb444525ab157a0ed0a7412b2fa69b217fe397263153782c0f64351fbdf2678fa0dc8569912dcd8e3ccad38f34f23bbbce14c6a26ac24911b308b82c7e43062d180baeac4ba7153858365c72c63dcf5f6a5b08070b730adb017aeae925b7d0439979e2679f45ed2f25a7edcfd2fb77a8794630285ccb0a071f5cce410b46dbf9750b0354aae8b65574501cc69efb5b6a43444074fee116641bb29da56c2b4a7f456991fc92b2\\\",\\\"debug\\\":0,\\\"seedipaddr\\\":\\\"%s\\\"}\""; +int32_t komodo_whoami(char *pubkeystr,int32_t height) +{ + int32_t i,notaryid; uint8_t + for (i=0; i<33; i++) + sprintf(&pubkeystr[i<<1],NOTARY_PUBKEY33[i]); + pubkeystr[66] = 0; + komodo_chosennotary(¬aryid,height,NOTARY_PUBKEY33); + return(notaryid); +} + void komodo_args() { std::string name,addn; char *dirname,fname[512],magicstr[9]; uint8_t magic[4]; FILE *fp; int32_t i,len; diff --git a/src/rpcmisc.cpp b/src/rpcmisc.cpp index e6bf47e4f..ed65e69a4 100644 --- a/src/rpcmisc.cpp +++ b/src/rpcmisc.cpp @@ -42,6 +42,7 @@ using namespace std; uint64_t komodo_interestsum(); int32_t komodo_longestchain(); int32_t komodo_notarized_height(uint256 *hashp,uint256 *txidp); +int32_t komodo_whoami(char *pubkeystr,int32_t height); Value getinfo(const Array& params, bool fHelp) { @@ -120,6 +121,14 @@ Value getinfo(const Array& params, bool fHelp) #endif obj.push_back(Pair("relayfee", ValueFromAmount(::minRelayTxFee.GetFeePerK()))); obj.push_back(Pair("errors", GetWarnings("statusbar"))); + { + char pubkeystr[65]; int32_t notaryid; + if ( (notaryid= komodo_whoami(pubkeystr,longestchain)) >= 0 ) + { + obj.push_back(Pair("notaryid", notaryid)); + obj.push_back(Pair("pubkey", pubkeystr)); + } + } return obj; } From fbd1641c2967c3cba3ce9c3683d873eb4a807192 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 23 Nov 2016 12:37:36 -0300 Subject: [PATCH 15/56] test --- src/komodo_gateway.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 55883c293..e2d98777d 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -116,10 +116,9 @@ int32_t komodo_rwapproval(int32_t rwflag,uint8_t *opretbuf,struct pax_transactio else { for (i=0; i<32; i++) - { ((uint8_t *)&pax->txid)[31-i] = opretbuf[len++]; - printf("%02x",((uint8_t *)&pax->txid)[31-i]); - } + for (i=0; i<32; i++) + printf("%02x",((uint8_t *)&pax->txid)[i]); pax->vout = opretbuf[len++]; pax->vout += ((uint32_t)opretbuf[len++] << 8); printf(" txid v.%d\n",pax->vout); From 2e6851a15fe9bf8ae110df31a99c68d3a4cfe64b Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 23 Nov 2016 12:38:58 -0300 Subject: [PATCH 16/56] test --- src/komodo.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 18a1a3f1d..909f00a53 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -384,9 +384,9 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr sp->NOTARIZED_DESTTXID = desttxid; komodo_stateupdate(height,0,0,0,zero,0,0,0,0,0,0,0,0,0,0); len += 4; - if ( ASSETCHAINS[0] == 0 ) + if ( ASSETCHAINS_SYMBOL[0] == 0 ) printf("%s ht.%d NOTARIZED.%d %s.%s %sTXID.%s (%s) lens.(%d %d)\n",ASSETCHAINS_SYMBOL,height,*notarizedheightp,ASSETCHAINS_SYMBOL[0]==0?"KMD":ASSETCHAINS_SYMBOL,kmdtxid.ToString().c_str(),ASSETCHAINS_SYMBOL[0]==0?"BTC":"KMD",desttxid.ToString().c_str(),(char *)&scriptbuf[len],opretlen,len); - if ( ASSETCHAINS[0] == 0 && opretlen > len && scriptbuf[len] == 'A' ) + if ( ASSETCHAINS_SYMBOL[0] == 0 && opretlen > len && scriptbuf[len] == 'A' ) { printf("Found extradata.[%d] %d - %d\n",opretlen-len,opretlen,len); komodo_stateupdate(height,0,0,0,txhash,0,0,0,0,0,0,value,&scriptbuf[len],opretlen-len,j); From 2d868edf6827dc01f32f218abb88f4d0b943365e Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 23 Nov 2016 12:41:15 -0300 Subject: [PATCH 17/56] test --- src/komodo_utils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 397ce3499..941a046c3 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1431,7 +1431,7 @@ char *iguanafmtstr = (char *)"curl --url \"http://127.0.0.1:7778\" --data \"{\\\ int32_t komodo_whoami(char *pubkeystr,int32_t height) { - int32_t i,notaryid; uint8_t + int32_t i,notaryid; for (i=0; i<33; i++) sprintf(&pubkeystr[i<<1],NOTARY_PUBKEY33[i]); pubkeystr[66] = 0; From dbaf1154707fa50f824fd40ebbcd546949af160f Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 23 Nov 2016 13:03:06 -0300 Subject: [PATCH 18/56] test --- src/komodo.h | 28 +++++++++++++++++++++++----- src/komodo_bitcoind.h | 8 ++++++++ src/rpcblockchain.cpp | 35 +++++++++++++++++++++++++++++++++++ src/rpcclient.cpp | 1 + src/rpcserver.cpp | 1 + src/rpcserver.h | 1 + 6 files changed, 69 insertions(+), 5 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 909f00a53..ee0a27b39 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -324,7 +324,8 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scriptbuf,int32_t scriptlen,int32_t height,uint256 txhash,int32_t i,int32_t j,uint64_t *voutmaskp,int32_t *specialtxp,int32_t *notarizedheightp,uint64_t value,int32_t notarized,uint64_t signedmask) { - static uint256 zero; int32_t opretlen,nid,k,len = 0; uint256 kmdtxid,desttxid; uint8_t crypto777[33]; struct komodo_state *sp; char symbol[16],dest[16]; + static uint256 zero; static FILE *fp; + int32_t opretlen,nid,k,len = 0; uint256 kmdtxid,desttxid; uint8_t crypto777[33]; struct komodo_state *sp; char symbol[16],dest[16]; if ( (sp= komodo_stateptr(symbol,dest)) == 0 ) return(-1); if ( scriptlen == 35 && scriptbuf[0] == 33 && scriptbuf[34] == 0xac ) @@ -375,7 +376,7 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr if ( j == 1 && opretlen >= 32*2+4 && strcmp(ASSETCHAINS_SYMBOL[0]==0?"KMD":ASSETCHAINS_SYMBOL,(char *)&scriptbuf[len+32*2+4]) == 0 ) { len += iguana_rwbignum(0,&scriptbuf[len],32,(uint8_t *)&kmdtxid); - len += iguana_rwnum(0,&scriptbuf[len],4,(uint8_t *)notarizedheightp); + len += iguana_rwnum(0,&scriptbuf[len],sizeof(*notarizedheightp),(uint8_t *)notarizedheightp); len += iguana_rwbignum(0,&scriptbuf[len],32,(uint8_t *)&desttxid); if ( notarized != 0 && *notarizedheightp > sp->NOTARIZED_HEIGHT && *notarizedheightp < height ) { @@ -386,10 +387,27 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr len += 4; if ( ASSETCHAINS_SYMBOL[0] == 0 ) printf("%s ht.%d NOTARIZED.%d %s.%s %sTXID.%s (%s) lens.(%d %d)\n",ASSETCHAINS_SYMBOL,height,*notarizedheightp,ASSETCHAINS_SYMBOL[0]==0?"KMD":ASSETCHAINS_SYMBOL,kmdtxid.ToString().c_str(),ASSETCHAINS_SYMBOL[0]==0?"BTC":"KMD",desttxid.ToString().c_str(),(char *)&scriptbuf[len],opretlen,len); - if ( ASSETCHAINS_SYMBOL[0] == 0 && opretlen > len && scriptbuf[len] == 'A' ) + if ( ASSETCHAINS_SYMBOL[0] == 0 ) { - printf("Found extradata.[%d] %d - %d\n",opretlen-len,opretlen,len); - komodo_stateupdate(height,0,0,0,txhash,0,0,0,0,0,0,value,&scriptbuf[len],opretlen-len,j); + if ( signedfp == 0 ) + { + char fname[512]; + komodo_statefname(fname,"","signedmasks"); + if ( (signedfp= fopen(fname,"rb+")) == 0 ) + signedfp = fopen(fname,"wb"); + else fseek(signedfp,0,SEEK_END); + } + if ( signedfp != 0 ) + { + fwrite(&height,1,sizeof(height),signedfp); + fwrite(&signedmask,1,sizeof(signedmask),signedfp); + fflush(signedfp); + } + if ( opretlen > len && scriptbuf[len] == 'A' ) + { + printf("Found extradata.[%d] %d - %d\n",opretlen-len,opretlen,len); + komodo_stateupdate(height,0,0,0,txhash,0,0,0,0,0,0,value,&scriptbuf[len],opretlen-len,j); + } } } else printf("notarized.%d %llx reject ht.%d NOTARIZED.%d %s.%s DESTTXID.%s (%s)\n",notarized,(long long)signedmask,height,*notarizedheightp,ASSETCHAINS_SYMBOL[0]==0?"KMD":ASSETCHAINS_SYMBOL,kmdtxid.ToString().c_str(),desttxid.ToString().c_str(),(char *)&scriptbuf[len]); } diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index dd4eda01a..21a2340a5 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -529,6 +529,14 @@ int8_t komodo_minerid(int32_t height) return(-1); } +int32_t komodo_minerids(uint8_t *minerids,int32_t height) +{ + int32_t i,n=0; + for (i=0; i<1000; i++,n++) + minerids[i] = komodo_minerid(height - i); + return(n); +} + int32_t komodo_is_special(int32_t height,uint8_t pubkey33[33]) { int32_t i,notaryid,minerid,limit; diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index b79c2e90c..e44ff19e3 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -387,6 +387,41 @@ int32_t komodo_paxprices(int32_t *heights,uint64_t *prices,int32_t max,char *bas int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height); char *bitcoin_address(char *coinaddr,uint8_t addrtype,uint8_t *pubkey_or_rmd160,int32_t len); uint32_t komodo_interest_args(int32_t *txheightp,uint32_t *tiptimep,uint64_t *valuep,uint256 hash,int32_t n); +int32_t komodo_minerids(uint8_t *minerids,int32_t height); + +Value minerids(const Array& params, bool fHelp) +{ + Object ret; Array a; uint8_t minerids[1000],pubkeys[64][33]; int32_t i,j,n,tally[65]; + if ( fHelp || params.size() != 1 ) + throw runtime_error("minerids needs height\n"); + LOCK(cs_main); + if ( (n= komodo_minerids(minerids,height)) > 0 && n <= 64 ) + { + memset(tally,0,sizeof(tally)); + for (i=0; i= 64 ) + tally[64]++; + else tally[minerids[i]]++; + } + if ( (n= komodo_notaries(pubkeys,height)) > 0 ) + { + for (i=0; i<64; i++) + { + Object item; std::string hex; char *hexstr; + hex.resize(66); + hexstr = (char *)hex.data(); + for (j=0; j<33; j++) + sprintf(&hexstr[j*2],"%02x",pubkeys[i][j]); + item.push_back(Pair("pubkey", hex)); + item.push_back(Pair("blocks", tally[i])); + a.push_back(item); + } + } + ret.push_back(Pair("mined", a)); + } else ret.push_back(Pair("error", (char *)"couldnt extract minerids")); + return ret; +} Value notaries(const Array& params, bool fHelp) { diff --git a/src/rpcclient.cpp b/src/rpcclient.cpp index adf10ccb7..19f159a6e 100644 --- a/src/rpcclient.cpp +++ b/src/rpcclient.cpp @@ -110,6 +110,7 @@ static const CRPCConvertParam vRPCConvertParams[] = { "paxprices", 3 }, { "paxpending", 3 }, { "notaries", 1 }, + { "minerids", 1 }, }; class CRPCConvertTable diff --git a/src/rpcserver.cpp b/src/rpcserver.cpp index 4f04bdcc1..6e9bf5c35 100644 --- a/src/rpcserver.cpp +++ b/src/rpcserver.cpp @@ -304,6 +304,7 @@ static const CRPCCommand vRPCCommands[] = { "blockchain", "paxpending", &paxpending, true }, { "blockchain", "paxprices", &paxprices, true }, { "blockchain", "notaries", ¬aries, true }, + { "blockchain", "minerids", &minerids, true }, /* Mining */ { "mining", "getblocktemplate", &getblocktemplate, true }, diff --git a/src/rpcserver.h b/src/rpcserver.h index 77a4818bb..87ceec137 100644 --- a/src/rpcserver.h +++ b/src/rpcserver.h @@ -244,6 +244,7 @@ extern json_spirit::Value getblock(const json_spirit::Array& params, bool fHelp) extern json_spirit::Value gettxoutsetinfo(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value gettxout(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value notaries(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value minerids(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value paxprice(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value paxpending(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value paxprices(const json_spirit::Array& params, bool fHelp); From 056447a68de4eb74cd3f95e9fc3708a111966cd9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 23 Nov 2016 13:07:11 -0300 Subject: [PATCH 19/56] test --- src/komodo.h | 2 +- src/komodo_bitcoind.h | 4 ++++ src/rpcblockchain.cpp | 3 +++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index ee0a27b39..e11a026bf 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -385,7 +385,7 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr sp->NOTARIZED_DESTTXID = desttxid; komodo_stateupdate(height,0,0,0,zero,0,0,0,0,0,0,0,0,0,0); len += 4; - if ( ASSETCHAINS_SYMBOL[0] == 0 ) + if ( 0 && ASSETCHAINS_SYMBOL[0] == 0 ) printf("%s ht.%d NOTARIZED.%d %s.%s %sTXID.%s (%s) lens.(%d %d)\n",ASSETCHAINS_SYMBOL,height,*notarizedheightp,ASSETCHAINS_SYMBOL[0]==0?"KMD":ASSETCHAINS_SYMBOL,kmdtxid.ToString().c_str(),ASSETCHAINS_SYMBOL[0]==0?"BTC":"KMD",desttxid.ToString().c_str(),(char *)&scriptbuf[len],opretlen,len); if ( ASSETCHAINS_SYMBOL[0] == 0 ) { diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 21a2340a5..7f2d202a1 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -533,7 +533,11 @@ int32_t komodo_minerids(uint8_t *minerids,int32_t height) { int32_t i,n=0; for (i=0; i<1000; i++,n++) + { + if ( height-i <= 0 ) + break; minerids[i] = komodo_minerid(height - i); + } return(n); } diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index e44ff19e3..b8d37c9b7 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -395,6 +395,9 @@ Value minerids(const Array& params, bool fHelp) if ( fHelp || params.size() != 1 ) throw runtime_error("minerids needs height\n"); LOCK(cs_main); + int32_t height = atoi(params[0].get_str().c_str()); + if ( height < 0 ) + height = 0; if ( (n= komodo_minerids(minerids,height)) > 0 && n <= 64 ) { memset(tally,0,sizeof(tally)); From db976543db604a5eec2298e138aca0bcf4fd503e Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 23 Nov 2016 13:07:38 -0300 Subject: [PATCH 20/56] test --- src/komodo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index e11a026bf..074b76831 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -392,7 +392,7 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr if ( signedfp == 0 ) { char fname[512]; - komodo_statefname(fname,"","signedmasks"); + komodo_statefname(fname,"",(char *)"signedmasks"); if ( (signedfp= fopen(fname,"rb+")) == 0 ) signedfp = fopen(fname,"wb"); else fseek(signedfp,0,SEEK_END); From c96e160a3f1ed8a3d4ffb237f2f2977c53162bb8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 23 Nov 2016 13:10:36 -0300 Subject: [PATCH 21/56] test --- src/komodo.h | 2 +- src/komodo_utils.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 074b76831..19d3b92b5 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -324,7 +324,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scriptbuf,int32_t scriptlen,int32_t height,uint256 txhash,int32_t i,int32_t j,uint64_t *voutmaskp,int32_t *specialtxp,int32_t *notarizedheightp,uint64_t value,int32_t notarized,uint64_t signedmask) { - static uint256 zero; static FILE *fp; + static uint256 zero; static FILE *signedfp; int32_t opretlen,nid,k,len = 0; uint256 kmdtxid,desttxid; uint8_t crypto777[33]; struct komodo_state *sp; char symbol[16],dest[16]; if ( (sp= komodo_stateptr(symbol,dest)) == 0 ) return(-1); diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 941a046c3..5602292a5 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1433,7 +1433,7 @@ int32_t komodo_whoami(char *pubkeystr,int32_t height) { int32_t i,notaryid; for (i=0; i<33; i++) - sprintf(&pubkeystr[i<<1],NOTARY_PUBKEY33[i]); + sprintf(&pubkeystr[i<<1],"%02x",NOTARY_PUBKEY33[i]); pubkeystr[66] = 0; komodo_chosennotary(¬aryid,height,NOTARY_PUBKEY33); return(notaryid); From 403b5de8380b5ea2dc45717dca8c61ef13dbd68a Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 23 Nov 2016 13:12:46 -0300 Subject: [PATCH 22/56] test --- src/komodo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index 19d3b92b5..970634402 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -392,7 +392,7 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr if ( signedfp == 0 ) { char fname[512]; - komodo_statefname(fname,"",(char *)"signedmasks"); + komodo_statefname(fname,(char *)"",(char *)"signedmasks"); if ( (signedfp= fopen(fname,"rb+")) == 0 ) signedfp = fopen(fname,"wb"); else fseek(signedfp,0,SEEK_END); From 47cbf8e6f035777d0b083bff5495ffad786d940e Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 23 Nov 2016 13:15:46 -0300 Subject: [PATCH 23/56] test --- src/rpcblockchain.cpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index b8d37c9b7..4e73ce9df 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -391,7 +391,7 @@ int32_t komodo_minerids(uint8_t *minerids,int32_t height); Value minerids(const Array& params, bool fHelp) { - Object ret; Array a; uint8_t minerids[1000],pubkeys[64][33]; int32_t i,j,n,tally[65]; + Object ret; Array a; uint8_t minerids[1000],pubkeys[64][33]; int32_t i,j,n,numnotaries,tally[65]; if ( fHelp || params.size() != 1 ) throw runtime_error("minerids needs height\n"); LOCK(cs_main); @@ -401,14 +401,15 @@ Value minerids(const Array& params, bool fHelp) if ( (n= komodo_minerids(minerids,height)) > 0 && n <= 64 ) { memset(tally,0,sizeof(tally)); - for (i=0; i= 64 ) - tally[64]++; - else tally[minerids[i]]++; - } - if ( (n= komodo_notaries(pubkeys,height)) > 0 ) + numnotaries = komodo_notaries(pubkeys,height); + if ( numnotaries > 0 ) { + for (i=0; i= numnotaries ) + tally[64]++; + else tally[minerids[i]]++; + } for (i=0; i<64; i++) { Object item; std::string hex; char *hexstr; @@ -421,6 +422,9 @@ Value minerids(const Array& params, bool fHelp) a.push_back(item); } } + item.push_back(Pair("pubkey", (char *)"external miner")); + item.push_back(Pair("blocks", tally[64])); + a.push_back(item); ret.push_back(Pair("mined", a)); } else ret.push_back(Pair("error", (char *)"couldnt extract minerids")); return ret; From 14ecdc679fd2f9cdd89c70f4587d3ac4712bd3a9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 23 Nov 2016 13:17:15 -0300 Subject: [PATCH 24/56] test --- src/rpcblockchain.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 4e73ce9df..09d7352b9 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -421,10 +421,11 @@ Value minerids(const Array& params, bool fHelp) item.push_back(Pair("blocks", tally[i])); a.push_back(item); } + Object item; + item.push_back(Pair("pubkey", (char *)"external miners")); + item.push_back(Pair("blocks", tally[64])); + a.push_back(item); } - item.push_back(Pair("pubkey", (char *)"external miner")); - item.push_back(Pair("blocks", tally[64])); - a.push_back(item); ret.push_back(Pair("mined", a)); } else ret.push_back(Pair("error", (char *)"couldnt extract minerids")); return ret; From 55ecfab2cce5e3da4d0ba6d6287df357380bf99f Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 23 Nov 2016 13:33:28 -0300 Subject: [PATCH 25/56] test --- src/rpcblockchain.cpp | 6 +++--- src/rpcclient.cpp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 09d7352b9..4d1dbcde6 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -396,8 +396,8 @@ Value minerids(const Array& params, bool fHelp) throw runtime_error("minerids needs height\n"); LOCK(cs_main); int32_t height = atoi(params[0].get_str().c_str()); - if ( height < 0 ) - height = 0; + if ( height <= 0 ) + height = chainActive.Tip()->nHeight; if ( (n= komodo_minerids(minerids,height)) > 0 && n <= 64 ) { memset(tally,0,sizeof(tally)); @@ -421,7 +421,7 @@ Value minerids(const Array& params, bool fHelp) item.push_back(Pair("blocks", tally[i])); a.push_back(item); } - Object item; + Object item; item.push_back(Pair("pubkey", (char *)"external miners")); item.push_back(Pair("blocks", tally[64])); a.push_back(item); diff --git a/src/rpcclient.cpp b/src/rpcclient.cpp index 19f159a6e..7375bbdcd 100644 --- a/src/rpcclient.cpp +++ b/src/rpcclient.cpp @@ -108,7 +108,7 @@ static const CRPCConvertParam vRPCConvertParams[] = { "z_importkey", 1 }, { "paxprice", 4 }, { "paxprices", 3 }, - { "paxpending", 3 }, + { "paxpending", 0 }, { "notaries", 1 }, { "minerids", 1 }, }; From d6be719d8ae8f4cb43f0c3be980737dd214c0f3b Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 23 Nov 2016 13:45:20 -0300 Subject: [PATCH 26/56] test --- src/komodo_gateway.h | 20 ++++++++++++-------- src/rpcblockchain.cpp | 2 +- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index e2d98777d..1461e9031 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -51,9 +51,9 @@ struct pax_transaction *komodo_paxmark(int32_t height,struct pax_transaction *sp return(pax); } -void komodo_gateway_deposit(char *coinaddr,uint64_t value,char *symbol,uint64_t fiatoshis,uint8_t *rmd160,uint256 txid,uint16_t vout,int32_t height,int32_t otherheight,char *source) // assetchain context +void komodo_gateway_deposit(char *coinaddr,uint64_t value,char *symbol,uint64_t fiatoshis,uint8_t *rmd160,uint256 txid,uint16_t vout,int32_t height,int32_t otherheight,char *source,int32_t approved) // assetchain context { - struct pax_transaction *pax; int32_t addflag = 0; struct komodo_state *sp; char str[16],dest[16]; + struct pax_transaction *pax; int32_t addflag = 0; struct komodo_state *sp; char str[16],dest[16],*s; sp = komodo_stateptr(str,dest); pthread_mutex_lock(&komodo_mutex); HASH_FIND(hh,PAX,&txid,sizeof(txid),pax); @@ -92,7 +92,12 @@ void komodo_gateway_deposit(char *coinaddr,uint64_t value,char *symbol,uint64_t if ( pax->marked == 0 ) { if ( addflag != 0 ) - printf("[%s] addflag.%d ADD %s %s %.8f -> %s TO PAX ht.%d otherht.%d total %.8f\n",ASSETCHAINS_SYMBOL,addflag,ASSETCHAINS_SYMBOL[0]==0?"WITHDRAW":"DEPOSIT",symbol,dstr(ASSETCHAINS_SYMBOL[0]==0?pax->komodoshis:pax->fiatoshis),pax->coinaddr,pax->height,pax->otherheight,dstr(komodo_paxtotal())); + { + if ( (pax->approved= approved) != 0 ) + s = (char *)"APPROVED"; + else s = (char *)(ASSETCHAINS_SYMBOL[0]==0?"WITHDRAW":"DEPOSIT"); + printf("[%s] addflag.%d ADD %s %s %.8f -> %s TO PAX ht.%d otherht.%d total %.8f\n",ASSETCHAINS_SYMBOL,addflag,s,symbol,dstr(ASSETCHAINS_SYMBOL[0]==0?pax->komodoshis:pax->fiatoshis),pax->coinaddr,pax->height,pax->otherheight,dstr(komodo_paxtotal())); + } } //else printf("%p MARKED.%d DEPOSIT %s %.8f -> %s TO PAX ht.%d otherht.%d\n",pax,pax->marked,symbol,dstr(fiatoshis),coinaddr,height,otherheight); } @@ -138,7 +143,6 @@ int32_t komodo_rwapproval(int32_t rwflag,uint8_t *opretbuf,struct pax_transactio memcpy(pax->rmd160,&opretbuf[len],20), len += 20; for (i=0; i<4; i++) pax->source[i] = opretbuf[len++]; - printf("%02x %02x %02x %02x %s\n",pax->source[0],pax->source[1],pax->source[2],pax->source[3],pax->source); } return(len); } @@ -422,7 +426,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 { if ( komodo_paxfind(&space,txid,vout) == 0 ) { - komodo_gateway_deposit(coinaddr,value,base,fiatoshis,rmd160,txid,vout,kmdheight,height,(char *)"KMD"); + komodo_gateway_deposit(coinaddr,value,base,fiatoshis,rmd160,txid,vout,kmdheight,height,(char *)"KMD",0); } else printf("duplicate deposit\n"); } } @@ -444,7 +448,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 { printf("notarize %s %.8f -> %.8f kmd.%d other.%d\n",ASSETCHAINS_SYMBOL,dstr(value),dstr(komodoshis),kmdheight,height); } - komodo_gateway_deposit(coinaddr,komodoshis,(char *)"KMD",value,rmd160,txid,vout,kmdheight,height,source); + komodo_gateway_deposit(coinaddr,komodoshis,(char *)"KMD",value,rmd160,txid,vout,kmdheight,height,source,0); } } else if ( tokomodo != 0 && opretbuf[0] == 'A' ) @@ -463,7 +467,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 if ( (pax= komodo_paxfind(&space,txids[i],vouts[i])) == 0 && baseids[i] >= 0 ) { bitcoin_address(coinaddr,60,&rmd160s[i*20],20); - komodo_gateway_deposit(coinaddr,0,0,0,0,txids[i],vouts[i],kmdheights[i],otherheights[i],CURRENCIES[baseids[i]]); + komodo_gateway_deposit(coinaddr,0,0,0,0,txids[i],vouts[i],kmdheights[i],otherheights[i],CURRENCIES[baseids[i]],kmdheights[i]); printf("i.%d (%s) <- %.8f\n",i,coinaddr,dstr(values[i])); } else printf("i.%d pax.%p baseids[] %d\n",i,pax,baseids[i]); if ( (pax= komodo_paxfind(&space,txids[i],vouts[i])) != 0 ) @@ -485,7 +489,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 { bitcoin_address(coinaddr,60,&rmd160s[i*20],20); if ( komodo_paxmark(height,&space,txids[i],vouts[i],height) == 0 && baseids[i] >= 0 ) - komodo_gateway_deposit(coinaddr,0,0,0,0,txids[i],vouts[i],height,0,CURRENCIES[baseids[i]]); + komodo_gateway_deposit(coinaddr,0,0,0,0,txids[i],vouts[i],height,0,CURRENCIES[baseids[i]],0); } } } diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 4d1dbcde6..80c462eaf 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -398,7 +398,7 @@ Value minerids(const Array& params, bool fHelp) int32_t height = atoi(params[0].get_str().c_str()); if ( height <= 0 ) height = chainActive.Tip()->nHeight; - if ( (n= komodo_minerids(minerids,height)) > 0 && n <= 64 ) + if ( (n= komodo_minerids(minerids,height)) > 0 ) { memset(tally,0,sizeof(tally)); numnotaries = komodo_notaries(pubkeys,height); From 8711ee8f28b1cb0c5c4d731fbe2abd66e009b230 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 23 Nov 2016 13:57:34 -0300 Subject: [PATCH 27/56] test --- src/rpcblockchain.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 80c462eaf..418fbc73e 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -417,6 +417,7 @@ Value minerids(const Array& params, bool fHelp) hexstr = (char *)hex.data(); for (j=0; j<33; j++) sprintf(&hexstr[j*2],"%02x",pubkeys[i][j]); + item.push_back(Pair("notaryid", i)); item.push_back(Pair("pubkey", hex)); item.push_back(Pair("blocks", tally[i])); a.push_back(item); From 75e47988cfcd03a703bfc7c8a33a9c485ed5da65 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 23 Nov 2016 14:09:38 -0300 Subject: [PATCH 28/56] test --- src/komodo_gateway.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 1461e9031..441e0a9d1 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -230,6 +230,7 @@ int32_t komodo_pending_withdraws(char *opretstr) if ( len == 0 ) opretbuf[len++] = 'A'; len += komodo_rwapproval(1,&opretbuf[len],pax); + printf("%s.(marked.%u approved.%d) %p\n",pax->source,pax->marked,pax->approved,pax); } } if ( len > 0 ) @@ -473,7 +474,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 if ( (pax= komodo_paxfind(&space,txids[i],vouts[i])) != 0 ) { pax->approved = kmdheights[i]; - printf("i.%d approved.%d\n",i,kmdheights[i]); + printf("i.%d approved.%d <<<<<<<<<<<<< APPROVED %p\n",i,kmdheights[i],pax); } } } From dfe40c435a1b10984a09a9bcf1dab6398655239d Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 23 Nov 2016 14:24:26 -0300 Subject: [PATCH 29/56] test --- src/komodo_gateway.h | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 441e0a9d1..eb08ccb29 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -15,18 +15,16 @@ // paxdeposit equivalent in reverse makes opreturn and KMD does the same in reverse -struct pax_transaction *komodo_paxfind(struct pax_transaction *space,uint256 txid,uint16_t vout) +struct pax_transaction *komodo_paxfind(uint256 txid,uint16_t vout) { struct pax_transaction *pax; pthread_mutex_lock(&komodo_mutex); HASH_FIND(hh,PAX,&txid,sizeof(txid),pax); - if ( pax != 0 ) - memcpy(space,pax,sizeof(*pax)); pthread_mutex_unlock(&komodo_mutex); return(pax); } -struct pax_transaction *komodo_paxmark(int32_t height,struct pax_transaction *space,uint256 txid,uint16_t vout,int32_t mark) +struct pax_transaction *komodo_paxmark(int32_t height,uint256 txid,uint16_t vout,int32_t mark) { struct pax_transaction *pax; pthread_mutex_lock(&komodo_mutex); @@ -45,7 +43,6 @@ struct pax_transaction *komodo_paxmark(int32_t height,struct pax_transaction *sp //int32_t i; for (i=0; i<32; i++) // printf("%02x",((uint8_t *)&txid)[i]); //printf(" paxmark.ht %d vout%d\n",mark,vout); - memcpy(space,pax,sizeof(*pax)); } pthread_mutex_unlock(&komodo_mutex); return(pax); @@ -314,7 +311,7 @@ int32_t komodo_gateway_deposits(CMutableTransaction *txNew,char *base,int32_t to int32_t komodo_check_deposit(int32_t height,const CBlock& block) // verify above block is valid pax pricing { - int32_t i,j,n,num,opretlen,offset=1,errs=0,matched=0,kmdheights[64],otherheights[64]; uint256 hash,txids[64]; char symbol[16],base[16]; uint16_t vouts[64]; int8_t baseids[64]; uint8_t *script,opcode,rmd160s[64*20]; int64_t values[64]; struct pax_transaction *pax,space; + int32_t i,j,n,num,opretlen,offset=1,errs=0,matched=0,kmdheights[64],otherheights[64]; uint256 hash,txids[64]; char symbol[16],base[16]; uint16_t vouts[64]; int8_t baseids[64]; uint8_t *script,opcode,rmd160s[64*20]; int64_t values[64]; struct pax_transaction *pax; memset(baseids,0xff,sizeof(baseids)); memset(values,0,sizeof(values)); memset(rmd160s,0,sizeof(rmd160s)); @@ -344,7 +341,7 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block) // verify above { for (i=1; ifiatoshis == block.vtx[0].vout[i].nValue) || (opcode == 'X' && pax->komodoshis == block.vtx[0].vout[i].nValue)) ) { @@ -353,7 +350,7 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block) // verify above else matched++; if ( 0 && opcode == 'X' ) printf("errs.%d i.%d match %.8f == %.8f\n",errs,i,dstr(pax != 0 ? pax->fiatoshis:-1),dstr(block.vtx[0].vout[i].nValue)); - komodo_paxmark(height,&space,txids[i-1],vouts[i-1],height); + komodo_paxmark(height,txids[i-1],vouts[i-1],height); } else { @@ -394,7 +391,7 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block) // verify above const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int32_t opretlen,uint256 txid,uint16_t vout,char *source) { - uint8_t rmd160[20],rmd160s[64*20],addrtype,shortflag,pubkey33[33]; int32_t i,j,n,len,tokomodo,kmdheight,otherheights[64],kmdheights[64]; int8_t baseids[64]; char base[4],coinaddr[64],destaddr[64]; struct pax_transaction space; uint256 txids[64]; uint16_t vouts[64]; uint64_t convtoshis,seed; int64_t fiatoshis,komodoshis,checktoshis,values[64]; struct pax_transaction *pax; + uint8_t rmd160[20],rmd160s[64*20],addrtype,shortflag,pubkey33[33]; int32_t i,j,n,len,tokomodo,kmdheight,otherheights[64],kmdheights[64]; int8_t baseids[64]; char base[4],coinaddr[64],destaddr[64]; uint256 txids[64]; uint16_t vouts[64]; uint64_t convtoshis,seed; int64_t fiatoshis,komodoshis,checktoshis,values[64]; struct pax_transaction *pax; const char *typestr = "unknown"; memset(baseids,0xff,sizeof(baseids)); memset(values,0,sizeof(values)); @@ -425,7 +422,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 printf(" checkpubkey check %.8f v %.8f dest.(%s) kmdheight.%d height.%d\n",dstr(checktoshis),dstr(value),destaddr,kmdheight,height); if ( value >= checktoshis-(checktoshis >> 10) ) { - if ( komodo_paxfind(&space,txid,vout) == 0 ) + if ( komodo_paxfind(txid,vout) == 0 ) { komodo_gateway_deposit(coinaddr,value,base,fiatoshis,rmd160,txid,vout,kmdheight,height,(char *)"KMD",0); } else printf("duplicate deposit\n"); @@ -445,7 +442,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 printf("%s.height.%d vs height.%d check %.8f/%.8f vs %.8f tokomodo.%d %d seed.%llx -> (%s)\n",ASSETCHAINS_SYMBOL,kmdheight,height,dstr(checktoshis),dstr(komodoshis),dstr(value),komodo_is_issuer(),strncmp(ASSETCHAINS_SYMBOL,base,strlen(base)) == 0,(long long)seed,coinaddr); if ( checktoshis <= komodoshis+(komodoshis >> 10) ) { - if ( (pax= komodo_paxfind(&space,txid,vout)) == 0 ) + if ( (pax= komodo_paxfind(txid,vout)) == 0 ) { printf("notarize %s %.8f -> %.8f kmd.%d other.%d\n",ASSETCHAINS_SYMBOL,dstr(value),dstr(komodoshis),kmdheight,height); } @@ -465,16 +462,18 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 { for (i=0; i= 0 ) + if ( (pax= komodo_paxfind(txids[i],vouts[i])) == 0 && baseids[i] >= 0 ) { bitcoin_address(coinaddr,60,&rmd160s[i*20],20); komodo_gateway_deposit(coinaddr,0,0,0,0,txids[i],vouts[i],kmdheights[i],otherheights[i],CURRENCIES[baseids[i]],kmdheights[i]); printf("i.%d (%s) <- %.8f\n",i,coinaddr,dstr(values[i])); - } else printf("i.%d pax.%p baseids[] %d\n",i,pax,baseids[i]); - if ( (pax= komodo_paxfind(&space,txids[i],vouts[i])) != 0 ) + } else printf("i.%d of n.%d pax.%p baseids[] %d\n",i,n,pax,baseids[i]); + if ( (pax= komodo_paxfind(txids[i],vouts[i])) != 0 ) { pax->approved = kmdheights[i]; - printf("i.%d approved.%d <<<<<<<<<<<<< APPROVED %p\n",i,kmdheights[i],pax); + for (j=0; j<32; i++) + printf("%02x",((uint8_t *)&txids[i])[j]); + printf(" i.%d approved.%d <<<<<<<<<<<<< APPROVED %p\n",i,kmdheights[i],pax); } } } @@ -489,7 +488,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 for (i=0; i= 0 ) + if ( komodo_paxmark(height,txids[i],vouts[i],height) == 0 && baseids[i] >= 0 ) komodo_gateway_deposit(coinaddr,0,0,0,0,txids[i],vouts[i],height,0,CURRENCIES[baseids[i]],0); } } From 26ffac88686fef103f27ad805be03c1575d7f06f Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 23 Nov 2016 14:29:48 -0300 Subject: [PATCH 30/56] test --- src/komodo_gateway.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index eb08ccb29..1a43a5444 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -462,17 +462,17 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 { for (i=0; i= 0 ) { bitcoin_address(coinaddr,60,&rmd160s[i*20],20); komodo_gateway_deposit(coinaddr,0,0,0,0,txids[i],vouts[i],kmdheights[i],otherheights[i],CURRENCIES[baseids[i]],kmdheights[i]); - printf("i.%d (%s) <- %.8f\n",i,coinaddr,dstr(values[i])); - } else printf("i.%d of n.%d pax.%p baseids[] %d\n",i,n,pax,baseids[i]); + printf(" i.%d (%s) <- %.8f\n",i,coinaddr,dstr(values[i])); + } else printf(" i.%d of n.%d pax.%p baseids[] %d\n",i,n,pax,baseids[i]); if ( (pax= komodo_paxfind(txids[i],vouts[i])) != 0 ) { pax->approved = kmdheights[i]; - for (j=0; j<32; i++) - printf("%02x",((uint8_t *)&txids[i])[j]); printf(" i.%d approved.%d <<<<<<<<<<<<< APPROVED %p\n",i,kmdheights[i],pax); } } From 71c9af7c8efcda41b3904861229d45eb87a58a84 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 23 Nov 2016 14:40:01 -0300 Subject: [PATCH 31/56] test --- src/komodo_gateway.h | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 1a43a5444..9150518f4 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -160,18 +160,18 @@ int32_t komodo_issued_opreturn(char *base,uint256 *txids,uint16_t *vouts,int64_t { memset(&p,0,sizeof(p)); len += komodo_rwapproval(0,&opretbuf[len],&p); - if ( values != 0 && kmdheights != 0 && otherheights != 0 && baseids != 0 ) + if ( values != 0 && kmdheights != 0 && otherheights != 0 && baseids != 0 && rmd160s != 0 ) { values[n] = (ASSETCHAINS_SYMBOL[0] == 0) ? p.komodoshis : p.fiatoshis; kmdheights[n] = p.height; otherheights[n] = p.otherheight; memcpy(&rmd160s[n * 20],p.rmd160,20); baseids[n] = komodo_baseid(p.source); - } - { - char coinaddr[64]; - bitcoin_address(coinaddr,60,p.rmd160,20); - printf(">>>>>>> approved A: (%s) fiat %.8f kmdheight.%d other.%d -> %s %.8f\n",baseids[n]>=0?CURRENCIES[baseids[n]]:"???",dstr(p.fiatoshis),p.height,p.otherheight,coinaddr,dstr(p.komodoshis)); + { + char coinaddr[64]; + bitcoin_address(coinaddr,60,&rmd160s[n * 20],20); + printf(">>>>>>> approved A: (%s) fiat %.8f kmdheight.%d other.%d -> %s %.8f\n",baseids[n]>=0?CURRENCIES[baseids[n]]:"???",dstr(p.komodoshis),kmdheights[n],otherheights[n],coinaddr,dstr(values[n])); + } } } else @@ -464,6 +464,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 { for (j=0; j<32; j++) printf("%02x",((uint8_t *)&txids[i])[j]); + printf(" v%d %.8f k.%d ht.%d base.%d\n",vouts[i],dstr(values[i]),kmdheights[i],otherheights[i],baseids[i]); if ( (pax= komodo_paxfind(txids[i],vouts[i])) == 0 && baseids[i] >= 0 ) { bitcoin_address(coinaddr,60,&rmd160s[i*20],20); From 63342b19eca74f464579ca5eb3ab6296d8f0f973 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 23 Nov 2016 14:46:36 -0300 Subject: [PATCH 32/56] test --- src/komodo_gateway.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 9150518f4..a4d31dbf0 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -162,6 +162,8 @@ int32_t komodo_issued_opreturn(char *base,uint256 *txids,uint16_t *vouts,int64_t len += komodo_rwapproval(0,&opretbuf[len],&p); if ( values != 0 && kmdheights != 0 && otherheights != 0 && baseids != 0 && rmd160s != 0 ) { + txids[n] = p.txid; + vouts[n] = p.vout; values[n] = (ASSETCHAINS_SYMBOL[0] == 0) ? p.komodoshis : p.fiatoshis; kmdheights[n] = p.height; otherheights[n] = p.otherheight; @@ -170,7 +172,7 @@ int32_t komodo_issued_opreturn(char *base,uint256 *txids,uint16_t *vouts,int64_t { char coinaddr[64]; bitcoin_address(coinaddr,60,&rmd160s[n * 20],20); - printf(">>>>>>> approved A: (%s) fiat %.8f kmdheight.%d other.%d -> %s %.8f\n",baseids[n]>=0?CURRENCIES[baseids[n]]:"???",dstr(p.komodoshis),kmdheights[n],otherheights[n],coinaddr,dstr(values[n])); + printf(">>>>>>> approved A: (%s) fiat %.8f kmdheight.%d other.%d -> %s %.8f\n",baseids[n]>=0?CURRENCIES[baseids[n]]:"???",dstr(p.fiatoshis),kmdheights[n],otherheights[n],coinaddr,dstr(values[n])); } } } From a6972662ed0065a9210cc0efcac21dccbe7307cf Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 23 Nov 2016 14:54:50 -0300 Subject: [PATCH 33/56] test --- src/komodo_gateway.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index a4d31dbf0..dd57e3d41 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -118,9 +118,9 @@ int32_t komodo_rwapproval(int32_t rwflag,uint8_t *opretbuf,struct pax_transactio else { for (i=0; i<32; i++) - ((uint8_t *)&pax->txid)[31-i] = opretbuf[len++]; + ((uint8_t *)&pax->txid)[i] = opretbuf[len++]; for (i=0; i<32; i++) - printf("%02x",((uint8_t *)&pax->txid)[i]); + printf("%02x",((uint8_t *)&pax->txid)[31-i]); pax->vout = opretbuf[len++]; pax->vout += ((uint32_t)opretbuf[len++] << 8); printf(" txid v.%d\n",pax->vout); From b89ab77cc2966f632fa7450d5e2f2804f23d0451 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 23 Nov 2016 15:15:29 -0300 Subject: [PATCH 34/56] test --- src/komodo_gateway.h | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index dd57e3d41..0fd4a31e2 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -144,7 +144,7 @@ int32_t komodo_rwapproval(int32_t rwflag,uint8_t *opretbuf,struct pax_transactio return(len); } -int32_t komodo_issued_opreturn(char *base,uint256 *txids,uint16_t *vouts,int64_t *values,int32_t *kmdheights,int32_t *otherheights,int8_t *baseids,uint8_t *rmd160s,uint8_t *opretbuf,int32_t opretlen,int32_t iskomodo) +int32_t komodo_issued_opreturn(char *base,uint256 *txids,uint16_t *vouts,int64_t *values,int64_t *srcvalues,int32_t *kmdheights,int32_t *otherheights,int8_t *baseids,uint8_t *rmd160s,uint8_t *opretbuf,int32_t opretlen,int32_t iskomodo) { struct pax_transaction p; int32_t i,n=0,j,len=0,incr,height,otherheight; uint8_t rmd160[20]; uint64_t fiatoshis; char symbol[16]; for (i=0; i<4; i++) @@ -160,11 +160,12 @@ int32_t komodo_issued_opreturn(char *base,uint256 *txids,uint16_t *vouts,int64_t { memset(&p,0,sizeof(p)); len += komodo_rwapproval(0,&opretbuf[len],&p); - if ( values != 0 && kmdheights != 0 && otherheights != 0 && baseids != 0 && rmd160s != 0 ) + if ( values != 0 && srcvalues != 0 && kmdheights != 0 && otherheights != 0 && baseids != 0 && rmd160s != 0 ) { txids[n] = p.txid; vouts[n] = p.vout; values[n] = (ASSETCHAINS_SYMBOL[0] == 0) ? p.komodoshis : p.fiatoshis; + srcvalues[n] = (ASSETCHAINS_SYMBOL[0] == 0) ? p.fiatoshis : p.komodoshis; kmdheights[n] = p.height; otherheights[n] = p.otherheight; memcpy(&rmd160s[n * 20],p.rmd160,20); @@ -313,9 +314,10 @@ int32_t komodo_gateway_deposits(CMutableTransaction *txNew,char *base,int32_t to int32_t komodo_check_deposit(int32_t height,const CBlock& block) // verify above block is valid pax pricing { - int32_t i,j,n,num,opretlen,offset=1,errs=0,matched=0,kmdheights[64],otherheights[64]; uint256 hash,txids[64]; char symbol[16],base[16]; uint16_t vouts[64]; int8_t baseids[64]; uint8_t *script,opcode,rmd160s[64*20]; int64_t values[64]; struct pax_transaction *pax; + int32_t i,j,n,num,opretlen,offset=1,errs=0,matched=0,kmdheights[64],otherheights[64]; uint256 hash,txids[64]; char symbol[16],base[16]; uint16_t vouts[64]; int8_t baseids[64]; uint8_t *script,opcode,rmd160s[64*20]; int64_t values[64],srcvalues[64]; struct pax_transaction *pax; memset(baseids,0xff,sizeof(baseids)); memset(values,0,sizeof(values)); + memset(srcvalues,0,sizeof(srcvalues)); memset(rmd160s,0,sizeof(rmd160s)); memset(kmdheights,0,sizeof(kmdheights)); memset(otherheights,0,sizeof(otherheights)); @@ -339,7 +341,7 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block) // verify above } if ( script[offset] == opcode && opretlen < block.vtx[0].vout[n-1].scriptPubKey.size() ) { - if ( (num= komodo_issued_opreturn(base,txids,vouts,values,kmdheights,otherheights,baseids,rmd160s,&script[offset],opretlen,opcode == 'X')) > 0 ) + if ( (num= komodo_issued_opreturn(base,txids,vouts,values,srcvalues,kmdheights,otherheights,baseids,rmd160s,&script[offset],opretlen,opcode == 'X')) > 0 ) { for (i=1; i 0 ) + if ( (n= komodo_issued_opreturn(base,txids,vouts,values,srcvalues,kmdheights,otherheights,baseids,rmd160s,opretbuf,opretlen,1)) > 0 ) { for (i=0; i KMD %.8f vs %.8f\n",kmdheights[i],base,(double)fiatoshis/COIN,(double)values[i]/COIN,(double)checktoshis/COIN); for (j=0; j<32; j++) printf("%02x",((uint8_t *)&txids[i])[j]); printf(" v%d %.8f k.%d ht.%d base.%d\n",vouts[i],dstr(values[i]),kmdheights[i],otherheights[i],baseids[i]); - if ( (pax= komodo_paxfind(txids[i],vouts[i])) == 0 && baseids[i] >= 0 ) + if ( (pax= komodo_paxfind(txids[i],vouts[i])) == 0 ) { bitcoin_address(coinaddr,60,&rmd160s[i*20],20); komodo_gateway_deposit(coinaddr,0,0,0,0,txids[i],vouts[i],kmdheights[i],otherheights[i],CURRENCIES[baseids[i]],kmdheights[i]); @@ -486,7 +492,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 { if ( strncmp((char *)"KMD",(char *)&opretbuf[opretlen-4],3) != 0 ) { - if ( (n= komodo_issued_opreturn(base,txids,vouts,values,kmdheights,otherheights,baseids,rmd160s,opretbuf,opretlen,0)) > 0 ) + if ( (n= komodo_issued_opreturn(base,txids,vouts,values,srcvalues,kmdheights,otherheights,baseids,rmd160s,opretbuf,opretlen,0)) > 0 ) { for (i=0; i Date: Wed, 23 Nov 2016 15:16:57 -0300 Subject: [PATCH 35/56] test --- src/komodo_gateway.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 0fd4a31e2..935ceaed3 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -395,10 +395,11 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block) // verify above const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int32_t opretlen,uint256 txid,uint16_t vout,char *source) { - uint8_t rmd160[20],rmd160s[64*20],addrtype,shortflag,pubkey33[33]; int32_t i,j,n,len,tokomodo,kmdheight,otherheights[64],kmdheights[64]; int8_t baseids[64]; char base[4],coinaddr[64],destaddr[64]; uint256 txids[64]; uint16_t vouts[64]; uint64_t convtoshis,seed; int64_t fiatoshis,komodoshis,checktoshis,values[64]; struct pax_transaction *pax; + uint8_t rmd160[20],rmd160s[64*20],addrtype,shortflag,pubkey33[33]; int32_t i,j,n,len,tokomodo,kmdheight,otherheights[64],kmdheights[64]; int8_t baseids[64]; char base[4],coinaddr[64],destaddr[64]; uint256 txids[64]; uint16_t vouts[64]; uint64_t convtoshis,seed; int64_t fiatoshis,komodoshis,checktoshis,values[64],srcvalues[64]; struct pax_transaction *pax; const char *typestr = "unknown"; memset(baseids,0xff,sizeof(baseids)); memset(values,0,sizeof(values)); + memset(srcvalues,0,sizeof(srcvalues)); memset(rmd160s,0,sizeof(rmd160s)); memset(kmdheights,0,sizeof(kmdheights)); memset(otherheights,0,sizeof(otherheights)); From 0cc6ad813ffad55661687d0257efeb146abbe5ac Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 23 Nov 2016 15:38:26 -0300 Subject: [PATCH 36/56] test --- src/komodo.h | 2 +- src/komodo_gateway.h | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 970634402..3bded0254 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -152,7 +152,7 @@ int32_t komodo_parsestatefile(struct komodo_state *sp,FILE *fp,char *symbol,char { if ( fread(opret,1,olen,fp) != olen ) errs++; - //if ( matched != 0 ) + if ( 0 && matched != 0 ) { int32_t i; for (i=0; i 0 ) { for (i=0; i KMD %.8f vs %.8f\n",kmdheights[i],base,(double)fiatoshis/COIN,(double)values[i]/COIN,(double)checktoshis/COIN); + seed = 0; + while ( seed == 0 ) + { + checktoshis = komodo_paxprice(&seed,kmdheights[i],CURRENCIES[baseids[i]],(char *)"KMD",(uint64_t)srcvalues[i]); + printf("PAX_fiatdest ht.%d price %s %.8f -> KMD %.8f vs %.8f\n",kmdheights[i],CURRENCIES[baseids[i]],(double)srcvalues[i]/COIN,(double)values[i]/COIN,(double)checktoshis/COIN); + if ( seed == 0 ) + sleep(3); + } for (j=0; j<32; j++) printf("%02x",((uint8_t *)&txids[i])[j]); printf(" v%d %.8f k.%d ht.%d base.%d\n",vouts[i],dstr(values[i]),kmdheights[i],otherheights[i],baseids[i]); if ( (pax= komodo_paxfind(txids[i],vouts[i])) == 0 ) { bitcoin_address(coinaddr,60,&rmd160s[i*20],20); - komodo_gateway_deposit(coinaddr,0,0,0,0,txids[i],vouts[i],kmdheights[i],otherheights[i],CURRENCIES[baseids[i]],kmdheights[i]); + komodo_gateway_deposit(coinaddr,values[i],CURRENCIES[baseids[i]],srcvalues[i],&rmd160s[i*20],txids[i],vouts[i],kmdheights[i],otherheights[i],CURRENCIES[baseids[i]],kmdheights[i]); printf(" i.%d (%s) <- %.8f\n",i,coinaddr,dstr(values[i])); } else printf(" i.%d of n.%d pax.%p baseids[] %d\n",i,n,pax,baseids[i]); if ( (pax= komodo_paxfind(txids[i],vouts[i])) != 0 ) From 992c3be5b46a177d192bec3661a44888eee1beff Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 23 Nov 2016 15:56:02 -0300 Subject: [PATCH 37/56] test --- src/komodo_gateway.h | 35 +++++++++++++++++++++++++---------- src/komodo_structs.h | 2 +- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 252fe890d..b1db4c1d2 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -194,7 +194,7 @@ int32_t komodo_issued_opreturn(char *base,uint256 *txids,uint16_t *vouts,int64_t uint64_t komodo_paxtotal() { - struct pax_transaction *pax,*tmp; char symbol[16],dest[16]; int32_t ht; uint64_t total = 0; + struct pax_transaction *pax,*tmp; char symbol[16],dest[16]; int32_t ht; int64_t checktoshis; uint64_t seed,total = 0; if ( komodo_isrealtime(&ht) == 0 ) return(0); komodo_stateptr(symbol,dest); @@ -208,7 +208,25 @@ uint64_t komodo_paxtotal() if ( komodo_is_issuer() != 0 ) total += pax->fiatoshis; else if ( pax->approved != 0 ) - total += pax->komodoshis; + { + if ( pax->validated != 0 ) + total += pax->komodoshis; + else + { + seed = 0; + checktoshis = komodo_paxprice(&seed,pax->height,pax->source,(char *)"KMD",(uint64_t)pax->fiatvalue); + printf("PAX_fiatdest ht.%d price %s %.8f -> KMD %.8f vs %.8f\n",pax->height,pax->symbol,(double)pax->fiatoshis/COIN,(double)pax->komodoshis/COIN,(double)checktoshis/COIN); + printf(" v%d %.8f k.%d ht.%d base.%d\n",pax->vout,dstr(pax->komodoshis),pax->height,pax->otherheight,pax->symbol); + if ( seed != 0 ) + { + if ( checktoshis == pax->komodoshis ) + { + total += pax->komodoshis; + pax->validated = pax->komodoshis; + } else pax->marked = pax->height; + } + } + } } } } @@ -255,7 +273,9 @@ int32_t komodo_gateway_deposits(CMutableTransaction *txNew,char *base,int32_t to HASH_ITER(hh,PAX,pax,tmp) { //printf("pax.%s marked.%d %.8f -> %.8f\n",pax->symbol,pax->marked,dstr(pax->komodoshis),dstr(pax->fiatoshis)); - if ( pax->marked != 0 || strcmp(pax->symbol,symbol) != 0 || (strcmp(symbol,"KMD") == 0 && pax->approved == 0) ) + if ( strcmp(symbol,"KMD") == 0 && (pax->approved == 0 || pax->validated == 0 ) + continue; + if ( pax->marked != 0 || strcmp(pax->symbol,symbol) != 0 ) continue; //if ( ASSETCHAINS_SYMBOL[0] != 0 ) printf("pax.%s marked.%d %.8f -> %.8f\n",ASSETCHAINS_SYMBOL,pax->marked,dstr(pax->komodoshis),dstr(pax->fiatoshis)); @@ -469,13 +489,8 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 if ( baseids[i] < 0 ) continue; seed = 0; - while ( seed == 0 ) - { - checktoshis = komodo_paxprice(&seed,kmdheights[i],CURRENCIES[baseids[i]],(char *)"KMD",(uint64_t)srcvalues[i]); - printf("PAX_fiatdest ht.%d price %s %.8f -> KMD %.8f vs %.8f\n",kmdheights[i],CURRENCIES[baseids[i]],(double)srcvalues[i]/COIN,(double)values[i]/COIN,(double)checktoshis/COIN); - if ( seed == 0 ) - sleep(3); - } + checktoshis = komodo_paxprice(&seed,kmdheights[i],CURRENCIES[baseids[i]],(char *)"KMD",(uint64_t)srcvalues[i]); + printf("PAX_fiatdest ht.%d price %s %.8f -> KMD %.8f vs %.8f\n",kmdheights[i],CURRENCIES[baseids[i]],(double)srcvalues[i]/COIN,(double)values[i]/COIN,(double)checktoshis/COIN); for (j=0; j<32; j++) printf("%02x",((uint8_t *)&txids[i])[j]); printf(" v%d %.8f k.%d ht.%d base.%d\n",vouts[i],dstr(values[i]),kmdheights[i],otherheights[i],baseids[i]); diff --git a/src/komodo_structs.h b/src/komodo_structs.h index 309d7a688..2741fafb9 100644 --- a/src/komodo_structs.h +++ b/src/komodo_structs.h @@ -56,7 +56,7 @@ struct pax_transaction { UT_hash_handle hh; uint256 txid; - uint64_t komodoshis,fiatoshis; + uint64_t komodoshis,fiatoshis,validated; int32_t marked,height,otherheight,approved; uint16_t vout; char symbol[16],source[16],coinaddr[64]; uint8_t rmd160[20],shortflag; From f186b8a19d565c4ae5c16fb23e7aa74fc67c76e6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 23 Nov 2016 15:58:15 -0300 Subject: [PATCH 38/56] test --- src/komodo_gateway.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index b1db4c1d2..dade96dde 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -214,9 +214,9 @@ uint64_t komodo_paxtotal() else { seed = 0; - checktoshis = komodo_paxprice(&seed,pax->height,pax->source,(char *)"KMD",(uint64_t)pax->fiatvalue); + checktoshis = komodo_paxprice(&seed,pax->height,pax->source,(char *)"KMD",(uint64_t)pax->fiatoshis); printf("PAX_fiatdest ht.%d price %s %.8f -> KMD %.8f vs %.8f\n",pax->height,pax->symbol,(double)pax->fiatoshis/COIN,(double)pax->komodoshis/COIN,(double)checktoshis/COIN); - printf(" v%d %.8f k.%d ht.%d base.%d\n",pax->vout,dstr(pax->komodoshis),pax->height,pax->otherheight,pax->symbol); + printf(" v%d %.8f k.%d ht.%d\n",pax->vout,dstr(pax->komodoshis),pax->height,pax->otherheight); if ( seed != 0 ) { if ( checktoshis == pax->komodoshis ) @@ -273,7 +273,7 @@ int32_t komodo_gateway_deposits(CMutableTransaction *txNew,char *base,int32_t to HASH_ITER(hh,PAX,pax,tmp) { //printf("pax.%s marked.%d %.8f -> %.8f\n",pax->symbol,pax->marked,dstr(pax->komodoshis),dstr(pax->fiatoshis)); - if ( strcmp(symbol,"KMD") == 0 && (pax->approved == 0 || pax->validated == 0 ) + if ( strcmp(symbol,"KMD") == 0 && (pax->approved == 0 || pax->validated == 0) ) continue; if ( pax->marked != 0 || strcmp(pax->symbol,symbol) != 0 ) continue; From e3f9967438670a121f49ca6cfb8cb3aa9b9f2a4b Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 23 Nov 2016 16:07:56 -0300 Subject: [PATCH 39/56] test --- src/komodo_gateway.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index dade96dde..82a11720f 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -254,6 +254,7 @@ int32_t komodo_pending_withdraws(char *opretstr) if ( len > 0 ) init_hexbytes_noT(opretstr,opretbuf,len); else opretstr[0] = 0; + printf("PAXTOTAL %.8f\n",dstr(komodo_paxtotal())); return(len); } From e8cbe5fb58b222e18b118aa57505b9fa2b8c558a Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 23 Nov 2016 16:17:37 -0300 Subject: [PATCH 40/56] test --- src/komodo_gateway.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 82a11720f..169818cbe 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -219,7 +219,7 @@ uint64_t komodo_paxtotal() printf(" v%d %.8f k.%d ht.%d\n",pax->vout,dstr(pax->komodoshis),pax->height,pax->otherheight); if ( seed != 0 ) { - if ( checktoshis == pax->komodoshis ) + if ( checktoshis >= pax->komodoshis ) { total += pax->komodoshis; pax->validated = pax->komodoshis; From 52b2e68d9da5a5388fc1d0dbf7bb4311ad9991da Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 23 Nov 2016 18:16:58 -0300 Subject: [PATCH 41/56] test --- src/komodo_gateway.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 169818cbe..e164566a1 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -393,7 +393,7 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block) // verify above { if ( opcode == 'X' ) { - matched++; + //matched++; for (j=0; j<32; j++) printf("%02x",((uint8_t *)&txids[i-1])[j]); printf(" cant paxfind X txid\n"); @@ -405,8 +405,11 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block) // verify above if ( matched != num ) { // can easily happen depending on order of loading - if ( height > 60000 ) - printf("WARNING: ht.%d (%c) matched.%d vs num.%d\n",height,opcode,matched,num); + if ( height > 60000 && opcode == 'X' ) + { + printf("REJECT: ht.%d (%c) matched.%d vs num.%d\n",height,opcode,matched,num); + return(-1); + } } } //printf("opretlen.%d num.%d\n",opretlen,num); @@ -477,7 +480,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 } else if ( tokomodo != 0 && opretbuf[0] == 'A' ) { - if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 ) + if ( ASSETCHAINS_SYMBOL[0] != 0 ) { for (i=0; i Date: Wed, 23 Nov 2016 18:21:28 -0300 Subject: [PATCH 42/56] test --- src/komodo_gateway.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index e164566a1..f99349149 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -528,6 +528,10 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 } } } + else if ( opretbuf[0] == 'X' ) + { + printf("got X opreturn\n"); + } return(typestr); } From 4c58b338bf867a8b96a9d9eaf14a9e8958aaa3a4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 23 Nov 2016 18:25:53 -0300 Subject: [PATCH 43/56] test --- src/komodo_gateway.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index f99349149..5b7fc18bf 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -530,7 +530,16 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 } else if ( opretbuf[0] == 'X' ) { - printf("got X opreturn\n"); + printf("got X opreturn height.%d\n",height); + if ( (n= komodo_issued_opreturn(base,txids,vouts,values,srcvalues,kmdheights,otherheights,baseids,rmd160s,opretbuf,opretlen,1)) > 0 ) + { + for (i=0; i= 0 ) + komodo_gateway_deposit(coinaddr,0,0,0,0,txids[i],vouts[i],height,0,(char *)"KMD",0); + } + } } return(typestr); } From cddf571e366d84dbd0b9ab14e0787808890ebf35 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 23 Nov 2016 18:46:22 -0300 Subject: [PATCH 44/56] test --- src/komodo_gateway.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 5b7fc18bf..09381f2d0 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -536,7 +536,8 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 for (i=0; i= 0 ) + printf("i.%d of %d: %.8f -> %s\n",i,n,dstr(values[i]),coinaddr); + if ( komodo_paxmark(height,txids[i],vouts[i],height) == 0 ) komodo_gateway_deposit(coinaddr,0,0,0,0,txids[i],vouts[i],height,0,(char *)"KMD",0); } } From e988a431ec7ee626e7a5b07e6427a10aaf50eae4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 23 Nov 2016 18:53:07 -0300 Subject: [PATCH 45/56] test --- src/komodo_gateway.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 09381f2d0..1a1d76f65 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -155,7 +155,7 @@ int32_t komodo_issued_opreturn(char *base,uint256 *txids,uint16_t *vouts,int64_t incr = 34 + (iskomodo * (2*sizeof(fiatoshis) + 2*sizeof(height) + 20 + 4)); for (n=0; n Date: Wed, 23 Nov 2016 18:55:56 -0300 Subject: [PATCH 46/56] test --- src/komodo_gateway.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 1a1d76f65..70ebbf061 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -149,6 +149,9 @@ int32_t komodo_issued_opreturn(char *base,uint256 *txids,uint16_t *vouts,int64_t struct pax_transaction p; int32_t i,n=0,j,len=0,incr,height,otherheight; uint8_t rmd160[20]; uint64_t fiatoshis; char symbol[16]; for (i=0; i<4; i++) base[i] = opretbuf[opretlen-4+i]; + for (i=0; i Date: Wed, 23 Nov 2016 19:06:47 -0300 Subject: [PATCH 47/56] test --- src/komodo_gateway.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 70ebbf061..d053696e8 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -151,7 +151,7 @@ int32_t komodo_issued_opreturn(char *base,uint256 *txids,uint16_t *vouts,int64_t base[i] = opretbuf[opretlen-4+i]; for (i=0; i 0 ) init_hexbytes_noT(opretstr,opretbuf,len); else opretstr[0] = 0; - printf("PAXTOTAL %.8f\n",dstr(komodo_paxtotal())); + printf("komodo_pending_withdraws len.%d PAXTOTAL %.8f\n",len,dstr(komodo_paxtotal())); return(len); } From e0357628beefc96f4423dee741f1fd335af27c27 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 23 Nov 2016 19:20:00 -0300 Subject: [PATCH 48/56] test --- src/komodo_gateway.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index d053696e8..4ad1c7dd2 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -305,12 +305,13 @@ int32_t komodo_gateway_deposits(CMutableTransaction *txNew,char *base,int32_t to else { //[{"prev_hash":"5d5c9a49489b558de9e84f991f996dedaae6b9d0f157f82b2fec64662476d5cf","prev_vout":2,"EUR":0.10000000,"fiat":"EUR","kmdheight":57930,"height":153,"KMD":0.78329000,"address":"RDhEGYScNQYetCyG75Kf8Fg61UWPdwc1C5","rmd160":"306c507eea639e7220b3069ed9f49f3bc97eaca1"}] - len += iguana_rwnum(1,&data[len],sizeof(pax->fiatoshis),&pax->fiatoshis); + len += komodo_rwapproval(1,&data[len],pax); + /*len += iguana_rwnum(1,&data[len],sizeof(pax->fiatoshis),&pax->fiatoshis); len += iguana_rwnum(1,&data[len],sizeof(pax->height),&pax->height); len += iguana_rwnum(1,&data[len],sizeof(pax->otherheight),&pax->otherheight); for (i=0; pax->symbol[i]!=0&&i<3; i++) // must be 3 letter currency data[len++] = pax->symbol[i]; - data[len++] = 0; + data[len++] = 0;*/ PENDING_KOMODO_TX += pax->komodoshis; printf(" vout.%u DEPOSIT %.8f <- pax.%s pending %.8f | ",pax->vout,(double)txNew->vout[numvouts].nValue/COIN,symbol,dstr(PENDING_KOMODO_TX)); } From 16bed6ace19ac18a52ba31bc93cf7befc572031b Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 23 Nov 2016 19:27:24 -0300 Subject: [PATCH 49/56] test --- src/komodo_gateway.h | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 4ad1c7dd2..ad069807c 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -147,6 +147,7 @@ int32_t komodo_rwapproval(int32_t rwflag,uint8_t *opretbuf,struct pax_transactio int32_t komodo_issued_opreturn(char *base,uint256 *txids,uint16_t *vouts,int64_t *values,int64_t *srcvalues,int32_t *kmdheights,int32_t *otherheights,int8_t *baseids,uint8_t *rmd160s,uint8_t *opretbuf,int32_t opretlen,int32_t iskomodo) { struct pax_transaction p; int32_t i,n=0,j,len=0,incr,height,otherheight; uint8_t rmd160[20]; uint64_t fiatoshis; char symbol[16]; + incr = 34 + (iskomodo * (2*sizeof(fiatoshis) + 2*sizeof(height) + 20 + 4)); for (i=0; i<4; i++) base[i] = opretbuf[opretlen-4+i]; for (i=0; irmd160,20), script += 20; *script++ = 0x88; *script++ = 0xac; - for (i=0; i<32; i++) - { - //printf("%02x",((uint8_t *)&pax->txid)[i]); - data[len++] = ((uint8_t *)&pax->txid)[i]; - } - data[len++] = pax->vout & 0xff; - data[len++] = (pax->vout >> 8) & 0xff; if ( tokomodo == 0 ) + { + for (i=0; i<32; i++) + { + //printf("%02x",((uint8_t *)&pax->txid)[i]); + data[len++] = ((uint8_t *)&pax->txid)[i]; + } + data[len++] = pax->vout & 0xff; + data[len++] = (pax->vout >> 8) & 0xff; PENDING_KOMODO_TX += pax->fiatoshis; + } else { //[{"prev_hash":"5d5c9a49489b558de9e84f991f996dedaae6b9d0f157f82b2fec64662476d5cf","prev_vout":2,"EUR":0.10000000,"fiat":"EUR","kmdheight":57930,"height":153,"KMD":0.78329000,"address":"RDhEGYScNQYetCyG75Kf8Fg61UWPdwc1C5","rmd160":"306c507eea639e7220b3069ed9f49f3bc97eaca1"}] From 947d956f553d0677efa914fd8fbabf9eaecb89af Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 23 Nov 2016 19:54:20 -0300 Subject: [PATCH 50/56] test --- src/komodo_gateway.h | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index ad069807c..9e2f1f43c 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -146,7 +146,7 @@ int32_t komodo_rwapproval(int32_t rwflag,uint8_t *opretbuf,struct pax_transactio int32_t komodo_issued_opreturn(char *base,uint256 *txids,uint16_t *vouts,int64_t *values,int64_t *srcvalues,int32_t *kmdheights,int32_t *otherheights,int8_t *baseids,uint8_t *rmd160s,uint8_t *opretbuf,int32_t opretlen,int32_t iskomodo) { - struct pax_transaction p; int32_t i,n=0,j,len=0,incr,height,otherheight; uint8_t rmd160[20]; uint64_t fiatoshis; char symbol[16]; + struct pax_transaction p; int32_t i,n=0,j,len=0,incr,height,otherheight; uint8_t type,rmd160[20]; uint64_t fiatoshis; char symbol[16]; incr = 34 + (iskomodo * (2*sizeof(fiatoshis) + 2*sizeof(height) + 20 + 4)); for (i=0; i<4; i++) base[i] = opretbuf[opretlen-4+i]; @@ -155,10 +155,10 @@ int32_t komodo_issued_opreturn(char *base,uint256 *txids,uint16_t *vouts,int64_t printf(" opretlen.%d vs %d incr.%d\n",opretlen,(int32_t)(2*sizeof(fiatoshis) + 2*sizeof(height) + 20 + 4),incr); if ( ASSETCHAINS_SYMBOL[0] == 0 || strncmp(ASSETCHAINS_SYMBOL,base,strlen(base)) == 0 ) { + type = opretbuf[0]; opretbuf++, opretlen--; for (n=0; n>>>>>> approved A: (%s) fiat %.8f kmdheight.%d other.%d -> %s %.8f\n",baseids[n]>=0?CURRENCIES[baseids[n]]:"???",dstr(p.fiatoshis),kmdheights[n],otherheights[n],coinaddr,dstr(values[n])); + printf(">>>>>>> %s: (%s) fiat %.8f kmdheight.%d other.%d -> %s %.8f\n",type=='A'?"approvedA":"issuedX",baseids[n]>=0?CURRENCIES[baseids[n]]:"???",dstr(p.fiatoshis),kmdheights[n],otherheights[n],coinaddr,dstr(values[n])); } } } @@ -190,6 +190,7 @@ int32_t komodo_issued_opreturn(char *base,uint256 *txids,uint16_t *vouts,int64_t vouts[n] = opretbuf[len++]; vouts[n] = (opretbuf[len++] << 8) | vouts[n]; } + printf(" komodo_issued_opreturn issuedtxid v%d i.%d opretlen.%d\n",vouts[n],n,opretlen); } } return(n); @@ -370,6 +371,7 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block) // verify above { if ( (num= komodo_issued_opreturn(base,txids,vouts,values,srcvalues,kmdheights,otherheights,baseids,rmd160s,&script[offset],opretlen,opcode == 'X')) > 0 ) { + printf("komodo_check_deposit opcode.%c num.%d n.%d\n",opcode,num,n); for (i=1; imarked != 0 ) errs++; else matched++; - if ( 0 && opcode == 'X' ) + if ( opcode == 'X' ) printf("errs.%d i.%d match %.8f == %.8f\n",errs,i,dstr(pax != 0 ? pax->fiatoshis:-1),dstr(block.vtx[0].vout[i].nValue)); komodo_paxmark(height,txids[i-1],vouts[i-1],height); } @@ -389,8 +391,8 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block) // verify above if ( opcode == 'X' ) { for (j=0; j<32; j++) - printf("%02x",((uint8_t *)&hash)[j]); - printf(" ht.%d blockhash X couldnt find vout.[%d]\n",height,i); + printf("%02x",((uint8_t *)&txids[i-1])[j]); + printf(" cant paxfind X txid\n"); // validate amount! via fiat chain } } @@ -399,11 +401,10 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block) // verify above { if ( opcode == 'X' ) { - //matched++; + for (j=0; j<32; j++) - printf("%02x",((uint8_t *)&txids[i-1])[j]); - printf(" cant paxfind X txid\n"); - // validate amount! via fiat chain + printf("%02x",((uint8_t *)&hash)[j]); + printf(" ht.%d blockhash X couldnt find vout.[%d]\n",height,i); } else if ( opcode == 'I' ) matched++; } From 1d996b5f608ccb0d6e68000d97f4f6201dfa0692 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 23 Nov 2016 20:03:26 -0300 Subject: [PATCH 51/56] test --- src/komodo_gateway.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 9e2f1f43c..b8c4661a9 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -382,12 +382,13 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block) // verify above errs++; else matched++; if ( opcode == 'X' ) - printf("errs.%d i.%d match %.8f == %.8f\n",errs,i,dstr(pax != 0 ? pax->fiatoshis:-1),dstr(block.vtx[0].vout[i].nValue)); - komodo_paxmark(height,txids[i-1],vouts[i-1],height); + printf("errs.%d i.%d match %.8f == %.8f pax.%p\n",errs,i,dstr(pax != 0 ? pax->komodoshis:-1),dstr(block.vtx[0].vout[i].nValue),pax); + //komodo_paxmark(height,txids[i-1],vouts[i-1],height); + //if ( pax->marked == 0 ) + // printf("unexpected unmarked %p\n",pax); } else { - hash = block.GetHash(); if ( opcode == 'X' ) { for (j=0; j<32; j++) @@ -401,7 +402,7 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block) // verify above { if ( opcode == 'X' ) { - + hash = block.GetHash(); for (j=0; j<32; j++) printf("%02x",((uint8_t *)&hash)[j]); printf(" ht.%d blockhash X couldnt find vout.[%d]\n",height,i); From 4cfa59e19f40c6286e6164446d1f897b9ae76964 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 23 Nov 2016 20:12:39 -0300 Subject: [PATCH 52/56] test --- src/komodo_gateway.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index b8c4661a9..5b0cf0b88 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -371,7 +371,6 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block) // verify above { if ( (num= komodo_issued_opreturn(base,txids,vouts,values,srcvalues,kmdheights,otherheights,baseids,rmd160s,&script[offset],opretlen,opcode == 'X')) > 0 ) { - printf("komodo_check_deposit opcode.%c num.%d n.%d\n",opcode,num,n); for (i=1; imarked != 0 ) errs++; else matched++; - if ( opcode == 'X' ) + if ( 0 && opcode == 'X' ) printf("errs.%d i.%d match %.8f == %.8f pax.%p\n",errs,i,dstr(pax != 0 ? pax->komodoshis:-1),dstr(block.vtx[0].vout[i].nValue),pax); //komodo_paxmark(height,txids[i-1],vouts[i-1],height); //if ( pax->marked == 0 ) @@ -394,7 +393,6 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block) // verify above for (j=0; j<32; j++) printf("%02x",((uint8_t *)&txids[i-1])[j]); printf(" cant paxfind X txid\n"); - // validate amount! via fiat chain } } } From c35c0838645da4f0e608e9ba82d8bd64e61f3d85 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 23 Nov 2016 20:20:14 -0300 Subject: [PATCH 53/56] test --- src/komodo_gateway.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 5b0cf0b88..51451494e 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -377,7 +377,7 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block) // verify above { if ( ((opcode == 'I' && pax->fiatoshis == block.vtx[0].vout[i].nValue) || (opcode == 'X' && pax->komodoshis == block.vtx[0].vout[i].nValue)) ) { - if ( pax->marked != 0 ) + if ( pax->marked != 0 && height >= 80820 ) errs++; else matched++; if ( 0 && opcode == 'X' ) From 6d898f429458954931e4ccad91a28a6b8422bcee Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 23 Nov 2016 20:36:00 -0300 Subject: [PATCH 54/56] test --- src/komodo_gateway.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 51451494e..1fa3c9877 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -150,9 +150,9 @@ int32_t komodo_issued_opreturn(char *base,uint256 *txids,uint16_t *vouts,int64_t incr = 34 + (iskomodo * (2*sizeof(fiatoshis) + 2*sizeof(height) + 20 + 4)); for (i=0; i<4; i++) base[i] = opretbuf[opretlen-4+i]; - for (i=0; i Date: Wed, 23 Nov 2016 20:45:22 -0300 Subject: [PATCH 55/56] test --- src/assetfunds | 64 +++++++++++++++++++++++++------------------------- src/komodo.h | 5 ++-- 2 files changed, 34 insertions(+), 35 deletions(-) diff --git a/src/assetfunds b/src/assetfunds index b2bee93c1..df5f715a6 100755 --- a/src/assetfunds +++ b/src/assetfunds @@ -1,33 +1,33 @@ #!/bin/bash -./komodo-cli paxdeposit $1 aud 0.01 -./komodo-cli paxdeposit $1 bgn 0.01 -./komodo-cli paxdeposit $1 cad 0.01 -./komodo-cli paxdeposit $1 chf 0.01 -./komodo-cli paxdeposit $1 cny 0.01 -./komodo-cli paxdeposit $1 czk 0.01 -./komodo-cli paxdeposit $1 dkk 0.01 -./komodo-cli paxdeposit $1 eur 0.01 -./komodo-cli paxdeposit $1 gbp 0.01 -./komodo-cli paxdeposit $1 hkd 0.01 -./komodo-cli paxdeposit $1 hrk 0.01 -./komodo-cli paxdeposit $1 huf 0.01 -./komodo-cli paxdeposit $1 idr 0.01 -./komodo-cli paxdeposit $1 ils 0.01 -./komodo-cli paxdeposit $1 inr 0.01 -./komodo-cli paxdeposit $1 jpy 0.01 -./komodo-cli paxdeposit $1 krw 0.01 -./komodo-cli paxdeposit $1 mxn 0.01 -./komodo-cli paxdeposit $1 myr 0.01 -./komodo-cli paxdeposit $1 nok 0.01 -./komodo-cli paxdeposit $1 nzd 0.01 -./komodo-cli paxdeposit $1 php 0.01 -./komodo-cli paxdeposit $1 pln 0.01 -./komodo-cli paxdeposit $1 brl 0.01 -./komodo-cli paxdeposit $1 ron 0.01 -./komodo-cli paxdeposit $1 rub 0.01 -./komodo-cli paxdeposit $1 sek 0.01 -./komodo-cli paxdeposit $1 sgd 0.01 -./komodo-cli paxdeposit $1 thb 0.01 -./komodo-cli paxdeposit $1 try 0.01 -./komodo-cli paxdeposit $1 usd 0.01 -./komodo-cli paxdeposit $1 zar 0.01 +./komodo-cli paxdeposit $1 0.01 aud +./komodo-cli paxdeposit $1 0.01 bgn +./komodo-cli paxdeposit $1 0.01 cad +./komodo-cli paxdeposit $1 0.01 chf +./komodo-cli paxdeposit $1 0.01 cny +./komodo-cli paxdeposit $1 0.01 czk +./komodo-cli paxdeposit $1 0.01 dkk +./komodo-cli paxdeposit $1 0.01 eur +./komodo-cli paxdeposit $1 0.01 gbp +./komodo-cli paxdeposit $1 0.01 hkd +./komodo-cli paxdeposit $1 0.01 hrk +./komodo-cli paxdeposit $1 0.01 huf +./komodo-cli paxdeposit $1 0.01 idr +./komodo-cli paxdeposit $1 0.01 ils +./komodo-cli paxdeposit $1 0.01 inr +./komodo-cli paxdeposit $1 0.01 jpy +./komodo-cli paxdeposit $1 0.01 krw +./komodo-cli paxdeposit $1 0.01 mxn +./komodo-cli paxdeposit $1 0.01 myr +./komodo-cli paxdeposit $1 0.01 nok +./komodo-cli paxdeposit $1 0.01 nzd +./komodo-cli paxdeposit $1 0.01 php +./komodo-cli paxdeposit $1 0.01 pln +./komodo-cli paxdeposit $1 0.01 brl +./komodo-cli paxdeposit $1 0.01 ron +./komodo-cli paxdeposit $1 0.01 rub +./komodo-cli paxdeposit $1 0.01 sek +./komodo-cli paxdeposit $1 0.01 sgd +./komodo-cli paxdeposit $1 0.01 thb +./komodo-cli paxdeposit $1 0.01 try +./komodo-cli paxdeposit $1 0.01 usd +./komodo-cli paxdeposit $1 0.01 zar diff --git a/src/komodo.h b/src/komodo.h index 3bded0254..970ef50b9 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -17,9 +17,8 @@ #define H_KOMODO_H // Todo: -// 1. error check fiat redeem amounts -// 2. net balance limiter -// 3. verify: reorgs +// 1. net balance limiter +// 2. verify: reorgs // non komodod (non-hardfork) todo: // a. automate notarization fee payouts From 4307bd89d65ca16af8893dd422ae509209094039 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 24 Nov 2016 07:23:52 -0300 Subject: [PATCH 56/56] test --- src/komodo_bitcoind.h | 2 ++ src/komodo_pax.h | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 7f2d202a1..db1ea8319 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -376,6 +376,8 @@ uint64_t komodo_seed(int32_t height) { uint256 hash; uint64_t seed = 0; CBlockIndex *pindex; memset(&hash,0,sizeof(hash)); + if ( height > 10 ) + height -= 10; if ( ASSETCHAINS_SYMBOL[0] == 0 ) { if ( (pindex= chainActive[height]) != 0 ) diff --git a/src/komodo_pax.h b/src/komodo_pax.h index 77f7c5f1f..e7db138b1 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -348,6 +348,8 @@ uint64_t komodo_paxcalc(uint32_t *pvals,int32_t baseid,int32_t relid,uint64_t ba uint64_t _komodo_paxprice(int32_t height,char *base,char *rel,uint64_t basevolume) { int32_t baseid=-1,relid=-1,i; uint32_t *ptr; + if ( height > 10 ) + height -= 10; if ( (baseid= komodo_baseid(base)) >= 0 && (relid= komodo_baseid(rel)) >= 0 ) { for (i=NUM_PRICES-1; i>=0; i--)