From 8e3430ee2dc9f24be72307e43fc77397d46f8c40 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 29 Oct 2016 16:56:32 -0300 Subject: [PATCH 001/254] test --- src/komodo_gateway.h | 74 +++++++++++++++++++++++--------------------- src/komodo_utils.h | 7 +++++ 2 files changed, 46 insertions(+), 35 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 79ff30f18..87edc62da 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -121,9 +121,7 @@ int32_t komodo_gateway_depositremove(uint256 txid,uint16_t vout) // assetchain c const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int32_t opretlen,uint256 txid,uint16_t vout) { uint8_t rmd160[20],addrtype,shortflag,pubkey33[33]; int32_t i,j,len,tokomodo=0; char base[4],coinaddr[64],destaddr[64]; int64_t fiatoshis,checktoshis; const char *typestr = "unknown"; -#ifdef KOMODO_ISSUER - tokomodo = 1; -#endif + tokomodo = (komodo_is_issuer() == 0); if ( opretbuf[0] == ((tokomodo != 0) ? 'D' : 'W') ) { if ( opretlen == 34 ) @@ -134,51 +132,57 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 fiatoshis = -fiatoshis; bitcoin_address(coinaddr,addrtype,rmd160,20); checktoshis = PAX_fiatdest(tokomodo,destaddr,pubkey33,coinaddr,height,base,fiatoshis); - for (i=0; i %s ",dstr(fiatoshis),shortflag!=0?'-':'+',base,coinaddr); - for (i=0; i<32; i++) - printf("%02x",((uint8_t *)&txid)[i]); - printf(" <- txid.v%u ",vout); - for (i=0; i<33; i++) - printf("%02x",pubkey33[i]); - printf(" checkpubkey check %.8f v %.8f dest.(%s)\n",dstr(checktoshis),dstr(value),destaddr); typestr = "deposit"; -#ifdef KOMODO_ISSUER - if ( strncmp(KOMODO_SOURCE,base,strlen(base)) == 0 && value >= (9999*checktoshis)/10000 && shortflag == ASSETCHAINS_SHORTFLAG ) + if ( tokomodo == 0 && strncmp(KOMODO_SOURCE,base,strlen(base)) == 0 ) { - komodo_gateway_deposit(value,shortflag,base,fiatoshis,rmd160,txid,vout); + for (i=0; i %s ",dstr(fiatoshis),shortflag!=0?'-':'+',base,coinaddr); + for (i=0; i<32; i++) + printf("%02x",((uint8_t *)&txid)[i]); + printf(" <- txid.v%u ",vout); + for (i=0; i<33; i++) + printf("%02x",pubkey33[i]); + printf(" checkpubkey check %.8f v %.8f dest.(%s)\n",dstr(checktoshis),dstr(value),destaddr); + if ( value >= (9999*checktoshis)/10000 && shortflag == ASSETCHAINS_SHORTFLAG ) + { + komodo_gateway_deposit(value,shortflag,base,fiatoshis,rmd160,txid,vout); + } } -#else - if ( tokomodo != 0 && value <= (10000*checktoshis)/9999 ) + else { - + if ( value <= (10000*checktoshis)/9999 ) + { + + } } -#endif } } else { - for (i=0; i= '0' && c <= '9' ) From 32323ea12ed87e4de9488b8bc485b99861536310 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 29 Oct 2016 16:59:36 -0300 Subject: [PATCH 002/254] test --- src/komodo_bitcoind.h | 5 +++-- src/komodo_gateway.h | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index d46c4eca0..d37f4647f 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -227,7 +227,8 @@ try_again: free(s.ptr); return(0); } - printf( "curl_easy_perform() failed: %s %s.(%s %s), retries: %d\n",curl_easy_strerror(res),debugstr,url,command,numretries); + if ( (rand() % 1000) == 0 ) + printf( "curl_easy_perform() failed: %s %s.(%s %s), retries: %d\n",curl_easy_strerror(res),debugstr,url,command,numretries); free(s.ptr); sleep((1< Date: Sat, 29 Oct 2016 17:05:49 -0300 Subject: [PATCH 003/254] 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 609b8a3d7..5b9e47bcd 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -122,7 +122,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 { uint8_t rmd160[20],addrtype,shortflag,pubkey33[33]; int32_t i,j,len,tokomodo=0; char base[4],coinaddr[64],destaddr[64]; int64_t fiatoshis,checktoshis; const char *typestr = "unknown"; tokomodo = (komodo_is_issuer() == 0); - if ( opretbuf[0] == ((tokomodo != 0) ? 'D' : 'W') ) + if ( opretbuf[0] == ((tokomodo == 0) ? 'D' : 'W') ) { if ( opretlen == 34 ) { @@ -133,7 +133,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 bitcoin_address(coinaddr,addrtype,rmd160,20); checktoshis = PAX_fiatdest(tokomodo,destaddr,pubkey33,coinaddr,height,base,fiatoshis); typestr = "deposit"; - if ( tokomodo == 0 && strncmp(KOMODO_SOURCE,base,strlen(base)) == 0 ) + if ( tokomodo == 0 && strncmp(ASSETCHAINS_SYMBOL,base,strlen(base)) == 0 ) { for (i=0; i Date: Sat, 29 Oct 2016 17:21:29 -0300 Subject: [PATCH 004/254] test --- src/miner.cpp | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 0cce3e779..208bfe773 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -99,6 +99,7 @@ void UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams, } int32_t komodo_pax_opreturn(uint8_t *opret,int32_t maxsize); +void komodo_gateway_deposits(CMutableTransaction& txNew); extern int32_t KOMODO_INITDONE; extern uint64_t KOMODO_DEPOSIT; extern char ASSETCHAINS_SYMBOL[16]; @@ -351,23 +352,29 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) //txNew.nLockTime = (uint32_t)time(NULL) - 60; txNew.vin.resize(1); txNew.vin[0].prevout.SetNull(); - int32_t i,opretlen; uint8_t opret[256],*ptr; - if ( (opretlen= komodo_pax_opreturn(opret,sizeof(opret))) > 0 ) - { - txNew.vout.resize(2); - txNew.vout[1].scriptPubKey.resize(opretlen); - ptr = (uint8_t *)txNew.vout[1].scriptPubKey.data(); - for (i=0; i 0 ) + { + txNew.vout.resize(2); + txNew.vout[1].scriptPubKey.resize(opretlen); + ptr = (uint8_t *)txNew.vout[1].scriptPubKey.data(); + for (i=0; ivtx[0] = txNew; pblocktemplate->vTxFees[0] = -nFees; From f2ab07e1516f5ab38c8ba723a819ddf90831552d Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 29 Oct 2016 17:27:37 -0300 Subject: [PATCH 005/254] test --- src/komodo_gateway.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 5b9e47bcd..a8c4bc92a 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -47,7 +47,7 @@ void komodo_gateway_deposits(CMutableTransaction& txNew) } data[len++] = ptr->vout & 0xff; data[len++] = (ptr->vout >> 8) & 0xff; - printf(" vout.%u DEPOSIT %.8f\n",ptr->vout,(double)KOMODO_DEPOSIT/COIN); + printf(" vout.%u DEPOSIT %.8f <- komodo_gateway_deposits\n",ptr->vout,(double)KOMODO_DEPOSIT/COIN); PENDING_KOMODO_TX += ptr->fiatoshis; numvouts++; queue_enqueue((char *)"PENDINGS",&PendingsQ,&ptr->DL); @@ -70,7 +70,7 @@ int32_t komodo_check_deposit(const CBlock& block) // verify above block is valid return(0); } -void komodo_gateway_deposit(uint64_t value,int32_t shortflag,char *symbol,uint64_t fiatoshis,uint8_t *rmd160,uint256 txid,uint16_t vout) // assetchain context +void komodo_gateway_deposit(char *coinaddr,uint64_t value,int32_t shortflag,char *symbol,uint64_t fiatoshis,uint8_t *rmd160,uint256 txid,uint16_t vout) // assetchain context { struct pax_transaction *ptr; ptr = (struct pax_transaction *)calloc(1,sizeof(*ptr)); @@ -82,6 +82,7 @@ void komodo_gateway_deposit(uint64_t value,int32_t shortflag,char *symbol,uint64 ptr->txid = txid; ptr->vout = vout; KOMODO_DEPOSIT += fiatoshis; + printf("ADD DEPOSIT %s %.8f -> %s TO QUEUE\n",symbol,dstr(fiatoshis),coinaddr); queue_enqueue((char *)"DEPOSITS",&DepositsQ,&ptr->DL); } @@ -146,7 +147,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 printf(" checkpubkey check %.8f v %.8f dest.(%s)\n",dstr(checktoshis),dstr(value),destaddr); if ( value >= (9999*checktoshis)/10000 && shortflag == ASSETCHAINS_SHORTFLAG ) { - komodo_gateway_deposit(value,shortflag,base,fiatoshis,rmd160,txid,vout); + komodo_gateway_deposit(coinaddr,value,shortflag,base,fiatoshis,rmd160,txid,vout); } } else From f8e4269d8ffe36aa928102d15ff45e499b2f5eaa Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 29 Oct 2016 17:34:15 -0300 Subject: [PATCH 006/254] test --- src/miner.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 208bfe773..2a1fe6570 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -440,12 +440,11 @@ CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey) CPubKey pubkey; CScript scriptPubKey; if (!reservekey.GetReservedKey(pubkey)) return NULL; - scriptPubKey = CScript() << ToByteVector(pubkey) << OP_CHECKSIG; if ( USE_EXTERNAL_PUBKEY != 0 ) { //fprintf(stderr,"use notary pubkey\n"); scriptPubKey = CScript() << ParseHex(NOTARY_PUBKEY) << OP_CHECKSIG; - } + } else scriptPubKey = CScript() << ToByteVector(pubkey) << OP_CHECKSIG; return CreateNewBlock(scriptPubKey); } From f6c647ed5f22141ad3f0fa9d101c9a5d01be26b5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 29 Oct 2016 17:44:35 -0300 Subject: [PATCH 007/254] test --- src/miner.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 2a1fe6570..0c7cc3f10 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -437,14 +437,25 @@ int32_t komodo_chosennotary(int32_t *notaryidp,int32_t height,uint8_t *pubkey33) CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey) { - CPubKey pubkey; CScript scriptPubKey; - if (!reservekey.GetReservedKey(pubkey)) - return NULL; + CPubKey pubkey; CScript scriptPubKey; uint8_t *script,*ptr; int32_t i; if ( USE_EXTERNAL_PUBKEY != 0 ) { //fprintf(stderr,"use notary pubkey\n"); scriptPubKey = CScript() << ParseHex(NOTARY_PUBKEY) << OP_CHECKSIG; - } else scriptPubKey = CScript() << ToByteVector(pubkey) << OP_CHECKSIG; + } + else + { + if (!reservekey.GetReservedKey(pubkey)) + return NULL; + scriptPubKey.resize(35); + ptr = (uint8_t *)pubkey.data(); + script = (uint8_t *)scriptPubKey.data(); + script[0] = 33; + for (i=0; i<33; i++) + script[i+1] = ptr[i]; + script[34] = OP_CHECKSIG; + //scriptPubKey = CScript() << ToByteVector(pubkey) << OP_CHECKSIG; + } return CreateNewBlock(scriptPubKey); } From f66f65ec9ccfbe17dd3979721a570c261a501a92 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 29 Oct 2016 17:47:07 -0300 Subject: [PATCH 008/254] test --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index 0c7cc3f10..b1fa15ebc 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -448,7 +448,7 @@ CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey) if (!reservekey.GetReservedKey(pubkey)) return NULL; scriptPubKey.resize(35); - ptr = (uint8_t *)pubkey.data(); + ptr = (uint8_t *)pubkey.begin(); script = (uint8_t *)scriptPubKey.data(); script[0] = 33; for (i=0; i<33; i++) From d581f2297cb5bfb6036e815185adb0c3588180aa Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 29 Oct 2016 17:56:23 -0300 Subject: [PATCH 009/254] test --- src/miner.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index b1fa15ebc..6eb4c552d 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -352,6 +352,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) //txNew.nLockTime = (uint32_t)time(NULL) - 60; txNew.vin.resize(1); txNew.vin[0].prevout.SetNull(); + txNew.vout.resize(1); txNew.vout[0].scriptPubKey = scriptPubKeyIn; txNew.vout[0].nValue = GetBlockSubsidy(nHeight,chainparams.GetConsensus()); // Add fees @@ -369,7 +370,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) ptr[i] = opret[i]; txNew.vout[1].nValue = 0; //fprintf(stderr,"opretlen.%d\n",opretlen); - } else txNew.vout.resize(1); + } } else { From 87f0ea102b20a6d76364946cdf879e0f78c2c4f6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 29 Oct 2016 18:10:02 -0300 Subject: [PATCH 010/254] test --- src/main.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index f034da6e8..f38016488 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2243,7 +2243,8 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin LogPrint("bench", " - Connect %u transactions: %.2fms (%.3fms/tx, %.3fms/txin) [%.2fs]\n", (unsigned)block.vtx.size(), 0.001 * (nTime1 - nTimeStart), 0.001 * (nTime1 - nTimeStart) / block.vtx.size(), nInputs <= 1 ? 0 : 0.001 * (nTime1 - nTimeStart) / (nInputs-1), nTimeConnect * 0.000001); CAmount blockReward = nFees + GetBlockSubsidy(pindex->nHeight, chainparams.GetConsensus()); - if (block.vtx[0].GetValueOut() > blockReward) + if (block.vtx[0].vout[0].nValue > blockReward) + //if (block.vtx[0].GetValueOut() > blockReward) return state.DoS(100, error("ConnectBlock(): coinbase pays too much (actual=%d vs limit=%d)", block.vtx[0].GetValueOut(), blockReward), From 45440ae306731498933786bf88d7da373460a8a0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 29 Oct 2016 18:30:04 -0300 Subject: [PATCH 011/254] 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 a8c4bc92a..30e8bcdc1 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -144,7 +144,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 printf(" <- txid.v%u ",vout); for (i=0; i<33; i++) printf("%02x",pubkey33[i]); - printf(" checkpubkey check %.8f v %.8f dest.(%s)\n",dstr(checktoshis),dstr(value),destaddr); + printf(" checkpubkey check %.8f v %.8f dest.(%s) height.%d\n",dstr(checktoshis),dstr(value),destaddr,height); if ( value >= (9999*checktoshis)/10000 && shortflag == ASSETCHAINS_SHORTFLAG ) { komodo_gateway_deposit(coinaddr,value,shortflag,base,fiatoshis,rmd160,txid,vout); From 0e17b196969dcfde4ae677165cdbd43891091f15 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 29 Oct 2016 18:33:42 -0300 Subject: [PATCH 012/254] test --- src/komodo_pax.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_pax.h b/src/komodo_pax.h index c65d09878..169d29c63 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -248,7 +248,7 @@ uint64_t komodo_paxcalc(uint32_t *pvals,int32_t baseid,int32_t relid,uint64_t ba usdvol = komodo_paxvol(basevolume,baseusd) / MINDENOMS[baseid]; usdkmd = ((uint64_t)btcusd * 1000000000) / kmdbtc; //printf("base -> USD %llu, BTC %llu KMDUSD %llu\n",(long long)baseusd,(long long)btcusd,(long long)kmdusd); - printf("usdkmd.%llu basevolume.%llu baseusd.%llu paxvol.%llu usdvol.%llu\n",(long long)usdkmd,(long long)basevolume,(long long)baseusd,(long long)komodo_paxvol(basevolume,baseusd),(long long)usdvol); + printf("usdkmd.%llu basevolume.%llu baseusd.%llu paxvol.%llu usdvol.%llu -> %.8f\n",(long long)usdkmd,(long long)basevolume,(long long)baseusd,(long long)komodo_paxvol(basevolume,baseusd),(long long)usdvol,dstr(MINDENOMS[USD] * komodo_paxvol(usdvol,usdkmd))); return(MINDENOMS[USD] * komodo_paxvol(usdvol,usdkmd)); } } From 77701fd3c67f3685254c578eaa7effe5221424d0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 29 Oct 2016 18:38:13 -0300 Subject: [PATCH 013/254] 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 30e8bcdc1..7cb2cd65c 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -132,7 +132,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 if ( fiatoshis < 0 ) fiatoshis = -fiatoshis; bitcoin_address(coinaddr,addrtype,rmd160,20); - checktoshis = PAX_fiatdest(tokomodo,destaddr,pubkey33,coinaddr,height,base,fiatoshis); + checktoshis = PAX_fiatdest(tokomodo,destaddr,pubkey33,coinaddr,height-1,base,fiatoshis); typestr = "deposit"; if ( tokomodo == 0 && strncmp(ASSETCHAINS_SYMBOL,base,strlen(base)) == 0 ) { From 5082453032f7dab34b8abda9d37faaa73d38952c Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 29 Oct 2016 18:44:34 -0300 Subject: [PATCH 014/254] test --- src/komodo_gateway.h | 22 +++++++++++----------- src/miner.cpp | 4 ++-- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 7cb2cd65c..8a742b27f 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -24,16 +24,16 @@ struct pax_transaction char symbol[4]; uint8_t rmd160[20],shortflag; }; -void komodo_gateway_deposits(CMutableTransaction& txNew) +void komodo_gateway_deposits(CMutableTransaction *txNew) { struct pax_transaction *ptr; uint8_t *script,opret[10000],data[10000]; int32_t i,len=0,opretlen=0,numvouts=1; PENDING_KOMODO_TX = 0; while ( (ptr= (struct pax_transaction *)queue_dequeue(&DepositsQ)) != 0 ) { - txNew.vout.resize(numvouts+1); - txNew.vout[numvouts].nValue = ptr->fiatoshis; - txNew.vout[numvouts].scriptPubKey.resize(25); - script = (uint8_t *)&txNew.vout[numvouts].scriptPubKey[0]; + txNew->vout.resize(numvouts+1); + txNew->vout[numvouts].nValue = ptr->fiatoshis; + txNew->vout[numvouts].scriptPubKey.resize(25); + script = (uint8_t *)&txNew->vout[numvouts].scriptPubKey[0]; *script++ = 0x76; *script++ = 0xa9; *script++ = 20; @@ -55,13 +55,13 @@ void komodo_gateway_deposits(CMutableTransaction& txNew) if ( numvouts > 1 ) { opretlen = komodo_opreturnscript(opret,'I',data,len); - txNew.vout.resize(numvouts+1); - txNew.vout[numvouts].nValue = 0; - txNew.vout[numvouts].scriptPubKey.resize(opretlen); - script = (uint8_t *)&txNew.vout[numvouts].scriptPubKey[0]; + txNew->vout.resize(numvouts+1); + txNew->vout[numvouts].nValue = 0; + txNew->vout[numvouts].scriptPubKey.resize(opretlen); + script = (uint8_t *)&txNew->vout[numvouts].scriptPubKey[0]; memcpy(script,opret,opretlen); - } - printf("total numvouts.%d %.8f\n",numvouts,dstr(PENDING_KOMODO_TX)); + printf("total numvouts.%d %.8f opretlen.%d\n",numvouts,dstr(PENDING_KOMODO_TX),opretlen); + } else KOMODO_DEPOSIT = 0; } int32_t komodo_check_deposit(const CBlock& block) // verify above block is valid pax pricing diff --git a/src/miner.cpp b/src/miner.cpp index 6eb4c552d..8974bac36 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -99,7 +99,7 @@ void UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams, } int32_t komodo_pax_opreturn(uint8_t *opret,int32_t maxsize); -void komodo_gateway_deposits(CMutableTransaction& txNew); +void komodo_gateway_deposits(CMutableTransaction *txNew); extern int32_t KOMODO_INITDONE; extern uint64_t KOMODO_DEPOSIT; extern char ASSETCHAINS_SYMBOL[16]; @@ -374,7 +374,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) } else { - komodo_gateway_deposits(txNew); + komodo_gateway_deposits(&txNew); } pblock->vtx[0] = txNew; From bfeb19766139b85d7a59d2346cda17c9899466e5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 29 Oct 2016 18:53:28 -0300 Subject: [PATCH 015/254] test --- src/komodo_gateway.h | 4 ++-- src/miner.cpp | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 8a742b27f..28c86cf8b 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -145,14 +145,14 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 for (i=0; i<33; i++) printf("%02x",pubkey33[i]); printf(" checkpubkey check %.8f v %.8f dest.(%s) height.%d\n",dstr(checktoshis),dstr(value),destaddr,height); - if ( value >= (9999*checktoshis)/10000 && shortflag == ASSETCHAINS_SHORTFLAG ) + if ( value >= checktoshis && shortflag == ASSETCHAINS_SHORTFLAG ) { komodo_gateway_deposit(coinaddr,value,shortflag,base,fiatoshis,rmd160,txid,vout); } } else { - if ( value <= (10000*checktoshis)/9999 ) + if ( value <= checktoshis ) { } diff --git a/src/miner.cpp b/src/miner.cpp index 8974bac36..c76a24b63 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -375,6 +375,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) else { komodo_gateway_deposits(&txNew); + fprintf(stderr,"txNew numvouts.%d\n",txNew.vout.size()); } pblock->vtx[0] = txNew; From 6607800cd7c74c9041fb055e9afcfb3de2240efb Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 29 Oct 2016 18:56:08 -0300 Subject: [PATCH 016/254] test --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index c76a24b63..597a62e6c 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -375,7 +375,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) else { komodo_gateway_deposits(&txNew); - fprintf(stderr,"txNew numvouts.%d\n",txNew.vout.size()); + fprintf(stderr,"txNew numvouts.%d\n",(int32_t)txNew.vout.size()); } pblock->vtx[0] = txNew; From 4cea91470f549c95457642e7c3401d29284f201f Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 30 Oct 2016 06:33:59 -0300 Subject: [PATCH 017/254] 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 974cb8431..da9314601 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1351,7 +1351,7 @@ void komodo_args() else { ASSETCHAINS_PORT = 8777; - fprintf(stderr,"IS_KOMODO_NOTARY %d %s\n",IS_KOMODO_NOTARY,NOTARY_PUBKEY.c_str()); + //fprintf(stderr,"IS_KOMODO_NOTARY %d %s\n",IS_KOMODO_NOTARY,NOTARY_PUBKEY.c_str()); } //fprintf(stderr,"%s chain params initialized\n",ASSETCHAINS_SYMBOL); } \ No newline at end of file From 0233ea287216020aa2b295d849f993d4035848e1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 30 Oct 2016 06:54:10 -0300 Subject: [PATCH 018/254] test --- src/rpcmining.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/rpcmining.cpp b/src/rpcmining.cpp index 0808bc9ad..8900ad43a 100644 --- a/src/rpcmining.cpp +++ b/src/rpcmining.cpp @@ -603,7 +603,7 @@ Value getblocktemplate(const Array& params, bool fHelp) entry.push_back(Pair("fee", pblocktemplate->vTxFees[index_in_template])); entry.push_back(Pair("sigops", pblocktemplate->vTxSigOps[index_in_template])); - if (tx.IsCoinBase()) { + /* if (tx.IsCoinBase()) { // Show founders' reward if it is required if (pblock->vtx[0].vout.size() > 1) { // Correct this if GetBlockTemplate changes the order @@ -611,9 +611,8 @@ Value getblocktemplate(const Array& params, bool fHelp) } entry.push_back(Pair("required", true)); txCoinbase = entry; - } else { + } else*/ transactions.push_back(entry); - } } Object aux; @@ -804,8 +803,7 @@ Value getblocksubsidy(const Array& params, bool fHelp) "1. height (numeric, optional) The block height. If not provided, defaults to the current height of the chain.\n" "\nResult:\n" "{\n" - " \"miner\" : x.xxx (numeric) The mining reward amount in ZEC.\n" - " \"founders\" : x.xxx (numeric) The founders reward amount in ZEC.\n" + " \"miner\" : x.xxx (numeric) The mining reward amount in KMD.\n" "}\n" "\nExamples:\n" + HelpExampleCli("getblocksubsidy", "1000") From 992b308b7d0bd980653be8d177dd095213912e95 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 30 Oct 2016 07:22:55 -0300 Subject: [PATCH 019/254] test --- src/komodo_utils.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index da9314601..0bf293bf9 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1331,6 +1331,7 @@ void komodo_args() ASSETCHAINS_SHORTFLAG = 1; for (i=0; ASSETCHAINS_SYMBOL[i+1]!=0; i++) ASSETCHAINS_SYMBOL[i] = ASSETCHAINS_SYMBOL[i+1]; + ASSETCHAINS_SYMBOL[i] = 0; } //fprintf(stderr,"after args: %c%s port.%u magic.%08x supply.%u\n",ASSETCHAINS_SHORTFLAG!=0?'-':'+',ASSETCHAINS_SYMBOL,ASSETCHAINS_PORT,ASSETCHAINS_MAGIC,(int32_t)ASSETCHAINS_SUPPLY); while ( (dirname= (char *)GetDataDir(false).string().c_str()) == 0 || dirname[0] == 0 ) From dadaab0a4f2b8d8218228fda1fa20a4611a53613 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 30 Oct 2016 07:29:01 -0300 Subject: [PATCH 020/254] test --- src/util.cpp | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/util.cpp b/src/util.cpp index 19823cc05..a586a7516 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -401,19 +401,27 @@ void PrintExceptionContinue(const std::exception* pex, const char* pszThread) } extern char ASSETCHAINS_SYMBOL[16]; +extern int32_t ASSETCHAINS_SHORTFLAG; boost::filesystem::path GetDefaultDataDir() { namespace fs = boost::filesystem; + char symbol[16]; + if ( ASSETCHAINS_SYMBOL[0] != 0 ) + { + if ( ASSETCHAINS_SHORTFLAG != 0 ) + sprintf(symbol,"-%s",ASSETCHAINS_SYMBOL); + else strcpy(symbol,ASSETCHAINS_SYMBOL); + } else symbol[0] = 0; // Windows < Vista: C:\Documents and Settings\Username\Application Data\Zcash // Windows >= Vista: C:\Users\Username\AppData\Roaming\Zcash // Mac: ~/Library/Application Support/Zcash // Unix: ~/.zcash #ifdef WIN32 // Windows - if ( ASSETCHAINS_SYMBOL[0] == 0 ) + if ( symbol[0] == 0 ) return GetSpecialFolderPath(CSIDL_APPDATA) / "Komodo"; - else return GetSpecialFolderPath(CSIDL_APPDATA) / "Komodo" / ASSETCHAINS_SYMBOL; + else return GetSpecialFolderPath(CSIDL_APPDATA) / "Komodo" / symbol; #else fs::path pathRet; char* pszHome = getenv("HOME"); @@ -425,19 +433,19 @@ boost::filesystem::path GetDefaultDataDir() // Mac pathRet /= "Library/Application Support"; TryCreateDirectory(pathRet); - if ( ASSETCHAINS_SYMBOL[0] == 0 ) + if ( symbol[0] == 0 ) return pathRet / "Komodo"; else { pathRet /= "Komodo"; TryCreateDirectory(pathRet); - return pathRet / ASSETCHAINS_SYMBOL; + return pathRet / symbol; } #else // Unix - if ( ASSETCHAINS_SYMBOL[0] == 0 ) + if ( symbol[0] == 0 ) return pathRet / ".komodo"; - else return pathRet / ".komodo" / ASSETCHAINS_SYMBOL; + else return pathRet / ".komodo" / symbol; #endif #endif } From 56060a1a533c7a22300aae2e7c2fdf13dfaed27b Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 30 Oct 2016 07:31:47 -0300 Subject: [PATCH 021/254] 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 0bf293bf9..afd4f2033 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1325,7 +1325,6 @@ void komodo_args() strcpy((char *)&buf[len],ASSETCHAINS_SYMBOL); len += strlen(ASSETCHAINS_SYMBOL); ASSETCHAINS_MAGIC = calc_crc32(0,buf,len); - ASSETCHAINS_PORT = GetArg("-ac_port",8000 + (ASSETCHAINS_MAGIC % 7777)); if ( ASSETCHAINS_SYMBOL[0] == '-' ) { ASSETCHAINS_SHORTFLAG = 1; @@ -1333,6 +1332,7 @@ void komodo_args() ASSETCHAINS_SYMBOL[i] = ASSETCHAINS_SYMBOL[i+1]; ASSETCHAINS_SYMBOL[i] = 0; } + ASSETCHAINS_PORT = GetArg("-ac_port",8000+ASSETCHAINS_SHORTFLAG*7777 + (ASSETCHAINS_MAGIC % 7777)); //fprintf(stderr,"after args: %c%s port.%u magic.%08x supply.%u\n",ASSETCHAINS_SHORTFLAG!=0?'-':'+',ASSETCHAINS_SYMBOL,ASSETCHAINS_PORT,ASSETCHAINS_MAGIC,(int32_t)ASSETCHAINS_SUPPLY); while ( (dirname= (char *)GetDataDir(false).string().c_str()) == 0 || dirname[0] == 0 ) { From 950245db8538f8102716e833d5787089153e1d5d Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 30 Oct 2016 07:38:24 -0300 Subject: [PATCH 022/254] 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 28c86cf8b..e626571c7 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -145,7 +145,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 for (i=0; i<33; i++) printf("%02x",pubkey33[i]); printf(" checkpubkey check %.8f v %.8f dest.(%s) height.%d\n",dstr(checktoshis),dstr(value),destaddr,height); - if ( value >= checktoshis && shortflag == ASSETCHAINS_SHORTFLAG ) + if ( value >= checktoshis )//&& shortflag == ASSETCHAINS_SHORTFLAG ) { komodo_gateway_deposit(coinaddr,value,shortflag,base,fiatoshis,rmd160,txid,vout); } From a2474b2598c5cf6fdd693fbb99f42f354e08ec16 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 30 Oct 2016 07:41:06 -0300 Subject: [PATCH 023/254] test --- .gitignore | 2 ++ src/fiat/_usd | 3 +++ 2 files changed, 5 insertions(+) create mode 100644 src/fiat/_usd diff --git a/.gitignore b/.gitignore index 370866819..a62806be2 100644 --- a/.gitignore +++ b/.gitignore @@ -121,3 +121,5 @@ qa/pull-tester/test.*/* /doc/doxygen/ libzcashconsensus.pc + +src/fiat/-usd diff --git a/src/fiat/_usd b/src/fiat/_usd new file mode 100644 index 000000000..f5b373730 --- /dev/null +++ b/src/fiat/_usd @@ -0,0 +1,3 @@ + + +./komodo-cli -ac_name=-USD $1 $2 $3 $4 From ab59d41011419ff2edd26a74aa206c6d5b79f907 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 30 Oct 2016 07:41:33 -0300 Subject: [PATCH 024/254] test --- src/fiat/_usd | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 src/fiat/_usd diff --git a/src/fiat/_usd b/src/fiat/_usd old mode 100644 new mode 100755 From 7adbc036f50a51f551eb05918e344dea8d509acc Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 30 Oct 2016 07:46:35 -0300 Subject: [PATCH 025/254] test --- src/miner.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 597a62e6c..920ed4806 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -100,7 +100,7 @@ void UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams, int32_t komodo_pax_opreturn(uint8_t *opret,int32_t maxsize); void komodo_gateway_deposits(CMutableTransaction *txNew); -extern int32_t KOMODO_INITDONE; +extern int32_t KOMODO_INITDONE,ASSETCHAINS_SHORTFLAG; extern uint64_t KOMODO_DEPOSIT; extern char ASSETCHAINS_SYMBOL[16]; @@ -523,7 +523,7 @@ void static BitcoinMiner(CWallet *pwallet) try { while (true) { - if (chainparams.MiningRequiresPeers()) + if (ASSETCHAINS_SHORTFLAG == 0 && chainparams.MiningRequiresPeers()) { // Busy-wait for the network to come online so we don't waste time mining // on an obsolete chain. In regtest mode we expect to fly solo. From 2f74c54eb0e6cf617961413c634f1f4865781df8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 30 Oct 2016 07:50:50 -0300 Subject: [PATCH 026/254] test --- src/komodo_gateway.h | 2 ++ src/miner.cpp | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index e626571c7..4cef6e507 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -52,6 +52,8 @@ void komodo_gateway_deposits(CMutableTransaction *txNew) numvouts++; queue_enqueue((char *)"PENDINGS",&PendingsQ,&ptr->DL); } + while ( (ptr= (struct pax_transaction *)queue_dequeue(&PendingsQ)) != 0 ) + queue_enqueue((char *)"DEPOSITS",&DepositsQ,&ptr->DL); if ( numvouts > 1 ) { opretlen = komodo_opreturnscript(opret,'I',data,len); diff --git a/src/miner.cpp b/src/miner.cpp index 920ed4806..c1a585226 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -375,7 +375,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) else { komodo_gateway_deposits(&txNew); - fprintf(stderr,"txNew numvouts.%d\n",(int32_t)txNew.vout.size()); + //fprintf(stderr,"txNew numvouts.%d\n",(int32_t)txNew.vout.size()); } pblock->vtx[0] = txNew; From b9d5210b9dee4faae1fadb584515f3aa9b26a2b7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 30 Oct 2016 08:02:27 -0300 Subject: [PATCH 027/254] test --- src/komodo_gateway.h | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 4cef6e507..8c11714b4 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -47,7 +47,7 @@ void komodo_gateway_deposits(CMutableTransaction *txNew) } data[len++] = ptr->vout & 0xff; data[len++] = (ptr->vout >> 8) & 0xff; - printf(" vout.%u DEPOSIT %.8f <- komodo_gateway_deposits\n",ptr->vout,(double)KOMODO_DEPOSIT/COIN); + printf(" vout.%u DEPOSIT %.8f <- komodo_gateway_deposits\n",ptr->vout,(double)txNew->vout[numvouts].nValue/COIN); PENDING_KOMODO_TX += ptr->fiatoshis; numvouts++; queue_enqueue((char *)"PENDINGS",&PendingsQ,&ptr->DL); @@ -163,12 +163,11 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 } else { - if ( tokomodo == 0 && strncmp(KOMODO_SOURCE,base,strlen(base)) == 0 ) + for (i=0; i Date: Sun, 30 Oct 2016 08:12:39 -0300 Subject: [PATCH 028/254] test --- src/komodo_gateway.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 8c11714b4..583d9f368 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -56,6 +56,11 @@ void komodo_gateway_deposits(CMutableTransaction *txNew) queue_enqueue((char *)"DEPOSITS",&DepositsQ,&ptr->DL); if ( numvouts > 1 ) { + if ( ASSETCHAINS_SHORTFLAG != 0 ) + data[len++] = '-'; + for (i=0; ASSETCHAINS_SYMBOL[i]!=0; i++) + data[len++] = ASSETCHAINS_SYMBOL[i]; + data[len++] = 0; opretlen = komodo_opreturnscript(opret,'I',data,len); txNew->vout.resize(numvouts+1); txNew->vout[numvouts].nValue = 0; From a1236e32418a01ec42fe829bfd4da334664bce3a Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 30 Oct 2016 08:16:58 -0300 Subject: [PATCH 029/254] test --- src/komodo_gateway.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 583d9f368..e3014a0d9 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -171,9 +171,15 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 for (i=0; i Date: Sun, 30 Oct 2016 08:21:26 -0300 Subject: [PATCH 030/254] 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 e3014a0d9..c7e629e29 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -178,7 +178,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 else shortflag = 0; for (i=0; i<4; i++) base[i] = opretbuf[opretlen-4+i]; - printf("BASE.(%s)\n",base); + printf("BASE.(%s) vs (%s)\n",base,KOMODO_SOURCE); if ( strncmp(KOMODO_SOURCE,base,strlen(base)) == 0 && opretbuf[0] == 'I' ) { uint256 issuedtxid; uint16_t issuedvout; From a6400079556c5ade22c0404a29bf69ae2595075b Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 30 Oct 2016 08:24:13 -0300 Subject: [PATCH 031/254] test --- src/komodo.h | 4 ++-- src/komodo_gateway.h | 4 ++-- src/main.cpp | 1 - 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 18fb286a4..8ccd7c8cf 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -303,7 +303,7 @@ int32_t komodo_voutupdate(int32_t notaryid,uint8_t *scriptbuf,int32_t scriptlen, //for (k=0; k= 32*2+4 && strcmp(KOMODO_SOURCE,(char *)&scriptbuf[len+32*2+4]) == 0 ) + 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); @@ -315,7 +315,7 @@ int32_t komodo_voutupdate(int32_t notaryid,uint8_t *scriptbuf,int32_t scriptlen, NOTARIZED_HASH = kmdtxid; NOTARIZED_DESTTXID = desttxid; komodo_stateupdate(height,0,0,0,zero,0,0,0,0,0,0,0,0,0); - } else printf("reject ht.%d NOTARIZED.%d %s.%s DESTTXID.%s (%s)\n",height,*notarizedheightp,KOMODO_SOURCE,kmdtxid.ToString().c_str(),desttxid.ToString().c_str(),(char *)&scriptbuf[len]); + } else printf("reject ht.%d NOTARIZED.%d %s.%s DESTTXID.%s (%s)\n",height,*notarizedheightp,ASSETCHAINS_SYMBOL[0]==0?"KMD":ASSETCHAINS_SYMBOL,kmdtxid.ToString().c_str(),desttxid.ToString().c_str(),(char *)&scriptbuf[len]); } else if ( i == 0 && j == 1 && opretlen == 149 ) komodo_paxpricefeed(height,&scriptbuf[len],opretlen); diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index c7e629e29..94d894392 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -178,8 +178,8 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 else shortflag = 0; for (i=0; i<4; i++) base[i] = opretbuf[opretlen-4+i]; - printf("BASE.(%s) vs (%s)\n",base,KOMODO_SOURCE); - if ( strncmp(KOMODO_SOURCE,base,strlen(base)) == 0 && opretbuf[0] == 'I' ) + printf("BASE.(%s) vs (%s)\n",base,ASSETCHAINS_SYMBOL); + if ( strncmp(ASSETCHAINS_SYMBOL,base,strlen(base)) == 0 && opretbuf[0] == 'I' ) { uint256 issuedtxid; uint16_t issuedvout; opretbuf++, opretlen--; diff --git a/src/main.cpp b/src/main.cpp index f38016488..409827edc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -552,7 +552,6 @@ CBlockTreeDB *pblocktree = NULL; #define KOMODO_TESTNET_EXPIRATION 60000 //#define KOMODO_ENABLE_INTEREST enabling this is a hardfork -#define KOMODO_SOURCE "KMD" #define KOMODO_PAX #define KOMODO_ZCASH #include "komodo.h" From bd6bd0b185813776c226d2c5d34bdd467207621d Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 30 Oct 2016 08:27:18 -0300 Subject: [PATCH 032/254] 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 94d894392..cd946e4df 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -191,7 +191,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 printf("%02x",((uint8_t *)&issuedtxid)[j]); } issuedvout = opretbuf[len++]; - issuedvout = (opretbuf[len++] << 8) | vout; + issuedvout = (opretbuf[len++] << 8) | issuedvout; printf(" issuedtxid v%d i.%d opretlen.%d\n",issuedvout,i,opretlen); if ( komodo_gateway_depositremove(issuedtxid,issuedvout) == 0 ) printf("error removing deposit\n"); From 63b289ade0ddd5b214827c852a3dca65a6bcace5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 30 Oct 2016 09:09:33 -0300 Subject: [PATCH 033/254] test --- src/komodo_gateway.h | 75 ++++++++++++++++++++++++++++---------------- 1 file changed, 48 insertions(+), 27 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index cd946e4df..0ca23875c 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -24,11 +24,51 @@ struct pax_transaction char symbol[4]; uint8_t rmd160[20],shortflag; }; +int32_t komodo_issued_opreturn(int32_t *shortflagp,char *base,uint256 *txids,uint16_t *vouts,uint8_t *opretbuf,int32_t opretlen) +{ + int32_t i,n,j,len; + if ( opretbuf[opretlen-5] == '-' ) + *shortflagp = 1; + else *shortflagp = 0; + for (i=0; i<4; i++) + base[i] = opretbuf[opretlen-4+i]; + printf("BASE.(%s) vs (%s)\n",base,ASSETCHAINS_SYMBOL); + if ( strncmp(ASSETCHAINS_SYMBOL,base,strlen(base)) == 0 ) // shortflag + { + opretbuf++, opretlen--; + for (n=len=0; nvout.resize(numvouts+1); txNew->vout[numvouts].nValue = ptr->fiatoshis; @@ -71,12 +111,6 @@ void komodo_gateway_deposits(CMutableTransaction *txNew) } else KOMODO_DEPOSIT = 0; } -int32_t komodo_check_deposit(const CBlock& block) // verify above block is valid pax pricing -{ - // reenable rpc auth - return(0); -} - void komodo_gateway_deposit(char *coinaddr,uint64_t value,int32_t shortflag,char *symbol,uint64_t fiatoshis,uint8_t *rmd160,uint256 txid,uint16_t vout) // assetchain context { struct pax_transaction *ptr; @@ -128,7 +162,7 @@ int32_t komodo_gateway_depositremove(uint256 txid,uint16_t vout) // assetchain c const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int32_t opretlen,uint256 txid,uint16_t vout) { - uint8_t rmd160[20],addrtype,shortflag,pubkey33[33]; int32_t i,j,len,tokomodo=0; char base[4],coinaddr[64],destaddr[64]; int64_t fiatoshis,checktoshis; const char *typestr = "unknown"; + uint8_t rmd160[20],addrtype,shortflag,pubkey33[33]; int32_t i,j,len,tokomodo=0; char base[4],coinaddr[64],destaddr[64]; uint256 txids[64]; uint16_t vouts[64]; int64_t fiatoshis,checktoshis; const char *typestr = "unknown"; tokomodo = (komodo_is_issuer() == 0); if ( opretbuf[0] == ((tokomodo == 0) ? 'D' : 'W') ) { @@ -171,29 +205,16 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 for (i=0; i 0 ) { - uint256 issuedtxid; uint16_t issuedvout; - opretbuf++, opretlen--; - for (i=len=0; i Date: Sun, 30 Oct 2016 09:12:57 -0300 Subject: [PATCH 034/254] test --- src/komodo_gateway.h | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 0ca23875c..d1621fdcb 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -24,7 +24,7 @@ struct pax_transaction char symbol[4]; uint8_t rmd160[20],shortflag; }; -int32_t komodo_issued_opreturn(int32_t *shortflagp,char *base,uint256 *txids,uint16_t *vouts,uint8_t *opretbuf,int32_t opretlen) +int32_t komodo_issued_opreturn(uint8_t *shortflagp,char *base,uint256 *txids,uint16_t *vouts,uint8_t *opretbuf,int32_t opretlen) { int32_t i,n,j,len; if ( opretbuf[opretlen-5] == '-' ) @@ -46,8 +46,6 @@ int32_t komodo_issued_opreturn(int32_t *shortflagp,char *base,uint256 *txids,uin vouts[n] = opretbuf[len++]; vouts[n] = (opretbuf[len++] << 8) | vouts[n]; printf(" issuedtxid v%d i.%d opretlen.%d\n",vouts[n],n,opretlen); - if ( komodo_gateway_depositremove(txids[n],vouts[n]) == 0 ) - printf("error removing deposit\n"); } } return(n); @@ -56,7 +54,7 @@ int32_t komodo_issued_opreturn(int32_t *shortflagp,char *base,uint256 *txids,uin int32_t komodo_check_deposit(const CBlock& block) // verify above block is valid pax pricing { int32_t i,n; - n = block.vout.size(); + n = block.vtx[0].vout.size(); for (i=1; i Date: Sun, 30 Oct 2016 09:32:35 -0300 Subject: [PATCH 035/254] test --- src/komodo_gateway.h | 63 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 50 insertions(+), 13 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index d1621fdcb..d88a2c3ee 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -32,9 +32,9 @@ int32_t komodo_issued_opreturn(uint8_t *shortflagp,char *base,uint256 *txids,uin else *shortflagp = 0; for (i=0; i<4; i++) base[i] = opretbuf[opretlen-4+i]; - printf("BASE.(%s) vs (%s)\n",base,ASSETCHAINS_SYMBOL); if ( strncmp(ASSETCHAINS_SYMBOL,base,strlen(base)) == 0 ) // shortflag { + printf("BASE.(%s) vs (%s)\n",base,ASSETCHAINS_SYMBOL); opretbuf++, opretlen--; for (n=len=0; n 0 && num == n-2 ) + { + for (i=1; imutex); + ptr = 0; + if ( Q->list != 0 ) + { + item = &ptr->DL; + matchflag = 0; + DL_FOREACH(Q->list,item) + { + ptr = (struct pax_transaction *)item; + if ( memcmp(&ptr->txid,&txid,sizeof(txid)) == 0 && ptr->vout == vout ) + { + if ( ptr->fiatoshis == block.vtx[0].vout[i].nValue ) + { + printf("matched %.8f vout.%d\n",dstr(ptr->fiatoshis),i); + matchflag = 1; + } else printf("error finding %.8f vout.%d\n",dstr(ptr->fiatoshis),i); + break; + } + } + } + portable_mutex_unlock(&Q->mutex); + } + if ( matchflag == 0 ) + { + printf("couldnt find vout.[%d]\n",i); + return(-1); + } + } + } + } + return(0); +} + const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int32_t opretlen,uint256 txid,uint16_t vout) { uint8_t rmd160[20],addrtype,shortflag,pubkey33[33]; int32_t i,j,n,len,tokomodo=0; char base[4],coinaddr[64],destaddr[64]; uint256 txids[64]; uint16_t vouts[64]; int64_t fiatoshis,checktoshis; const char *typestr = "unknown"; @@ -235,7 +272,7 @@ void komodo_gateway_voutupdate(char *symbol,int32_t isspecial,int32_t height,int if ( script[offset++] == 0x6a ) { offset += komodo_scriptitemlen(&opretlen,&script[offset]); - if ( isspecial != 0 && len >= offset+32*2+4 && strcmp((char *)&script[offset+32*2+4],"KMD") == 0 ) + if ( isspecial != 0 && len >= offset+32*2+4 && strcmp((char *)&script[offset+32*2+4],ASSETCHAINS_SYMBOL[0]==0?"KMD":ASSETCHAINS_SYMBOL) == 0 ) typestr = "notarized"; else if ( txi == 0 && vout == 1 && opretlen == 149 ) { From 3eda531d27c86afd321714a875d7f998e67690e8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 30 Oct 2016 09:33:54 -0300 Subject: [PATCH 036/254] 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 d88a2c3ee..e4efead95 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -149,7 +149,7 @@ int32_t komodo_gateway_depositremove(uint256 txid,uint16_t vout) // assetchain c int32_t komodo_check_deposit(const CBlock& block) // verify above block is valid pax pricing { - int32_t i,n,scriptlen,num,iter; uint256 txids[64]; uint8_t shortflag; char base[16]; uint16_t vouts[64]; uint8_t *script; queue_t *Q; struct pax_transaction *ptr; struct queueitem *item; + int32_t i,n,scriptlen,num,iter,matchflag; uint256 txids[64]; uint8_t shortflag; char base[16]; uint16_t vouts[64]; uint8_t *script; queue_t *Q; struct pax_transaction *ptr; struct queueitem *item; n = block.vtx[0].vout.size(); script = (uint8_t *)block.vtx[0].vout[n-1].scriptPubKey.data(); if ( script[0] == 0x6a ) @@ -171,7 +171,7 @@ int32_t komodo_check_deposit(const CBlock& block) // verify above block is valid DL_FOREACH(Q->list,item) { ptr = (struct pax_transaction *)item; - if ( memcmp(&ptr->txid,&txid,sizeof(txid)) == 0 && ptr->vout == vout ) + if ( memcmp(&ptr->txid,&txids[i-1],sizeof(txids[i-1])) == 0 && ptr->vout == vouts[i-1] ) { if ( ptr->fiatoshis == block.vtx[0].vout[i].nValue ) { From 6a38a681c295c77dd5b0541d56d9c1869c6b9997 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 30 Oct 2016 09:41:03 -0300 Subject: [PATCH 037/254] 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 e4efead95..f0ee61080 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -152,10 +152,10 @@ int32_t komodo_check_deposit(const CBlock& block) // verify above block is valid int32_t i,n,scriptlen,num,iter,matchflag; uint256 txids[64]; uint8_t shortflag; char base[16]; uint16_t vouts[64]; uint8_t *script; queue_t *Q; struct pax_transaction *ptr; struct queueitem *item; n = block.vtx[0].vout.size(); script = (uint8_t *)block.vtx[0].vout[n-1].scriptPubKey.data(); - if ( script[0] == 0x6a ) + if ( n > 2 && script[0] == 0x6a ) { scriptlen = block.vtx[0].vout[n-1].scriptPubKey.size(); - if ( (num= komodo_issued_opreturn(&shortflag,base,txids,vouts,script,scriptlen)) > 0 && num == n-2 ) + if ( (num= komodo_issued_opreturn(&shortflag,base,txids,vouts,script,scriptlen)) > 0 ) { for (i=1; i Date: Sun, 30 Oct 2016 09:44:30 -0300 Subject: [PATCH 038/254] 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 f0ee61080..7871197b0 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -235,8 +235,9 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 } } } - else + else if ( strncmp("KMD",&opretbuf[opretlen-4],3) != 0 ) { + for (i=0; i Date: Sun, 30 Oct 2016 09:45:12 -0300 Subject: [PATCH 039/254] 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 7871197b0..32a5b49a7 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -235,7 +235,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 } } } - else if ( strncmp("KMD",&opretbuf[opretlen-4],3) != 0 ) + else if ( strncmp((char *)"KMD",&opretbuf[opretlen-4],3) != 0 ) { for (i=0; i Date: Sun, 30 Oct 2016 09:45:28 -0300 Subject: [PATCH 040/254] 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 32a5b49a7..3dfc3daca 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -235,7 +235,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 } } } - else if ( strncmp((char *)"KMD",&opretbuf[opretlen-4],3) != 0 ) + else if ( strncmp((char *)"KMD",(char *)&opretbuf[opretlen-4],3) != 0 ) { for (i=0; i Date: Sun, 30 Oct 2016 09:48:40 -0300 Subject: [PATCH 041/254] test --- src/komodo_gateway.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 3dfc3daca..3a5694196 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -152,6 +152,7 @@ int32_t komodo_check_deposit(const CBlock& block) // verify above block is valid int32_t i,n,scriptlen,num,iter,matchflag; uint256 txids[64]; uint8_t shortflag; char base[16]; uint16_t vouts[64]; uint8_t *script; queue_t *Q; struct pax_transaction *ptr; struct queueitem *item; n = block.vtx[0].vout.size(); script = (uint8_t *)block.vtx[0].vout[n-1].scriptPubKey.data(); + printf("checkdeposit n.%d [%02x]\n",n,script[0]); if ( n > 2 && script[0] == 0x6a ) { scriptlen = block.vtx[0].vout[n-1].scriptPubKey.size(); @@ -191,6 +192,7 @@ int32_t komodo_check_deposit(const CBlock& block) // verify above block is valid } } } + printf("scriptlen.%d num.%d\n",scriptlen,num); } return(0); } From 59642d51a7105627d9e4cfc7ce802570ace3e763 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 30 Oct 2016 09:52:11 -0300 Subject: [PATCH 042/254] test --- src/main.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 409827edc..8b07ab6c5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3039,6 +3039,7 @@ bool CheckBlockHeader(int32_t height,CBlockIndex *pindex, const CBlockHeader& bl return true; } +int32_t komodo_check_deposit(const CBlock& block); bool CheckBlock(int32_t height,CBlockIndex *pindex,const CBlock& block, CValidationState& state, bool fCheckPOW, bool fCheckMerkleRoot) { // These are checks that are independent of context. @@ -3095,7 +3096,8 @@ bool CheckBlock(int32_t height,CBlockIndex *pindex,const CBlock& block, CValidat if (nSigOps > MAX_BLOCK_SIGOPS) return state.DoS(100, error("CheckBlock(): out-of-bounds SigOpCount"), REJECT_INVALID, "bad-blk-sigops", true); - + if ( komodo_check_deposit(block) < 0 ) + return(false); return true; } From 5ebbe19b97ea573c6f653d06b0ce126d3c0f926a Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 30 Oct 2016 09:58:43 -0300 Subject: [PATCH 043/254] 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 3a5694196..dd4ede007 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -153,10 +153,10 @@ int32_t komodo_check_deposit(const CBlock& block) // verify above block is valid n = block.vtx[0].vout.size(); script = (uint8_t *)block.vtx[0].vout[n-1].scriptPubKey.data(); printf("checkdeposit n.%d [%02x]\n",n,script[0]); - if ( n > 2 && script[0] == 0x6a ) + if ( n > 2 && script[0] == 0x6a && script[1] == 'I' ) { scriptlen = block.vtx[0].vout[n-1].scriptPubKey.size(); - if ( (num= komodo_issued_opreturn(&shortflag,base,txids,vouts,script,scriptlen)) > 0 ) + if ( (num= komodo_issued_opreturn(&shortflag,base,txids,vouts,script+1,scriptlen-1)) > 0 ) { for (i=1; i Date: Sun, 30 Oct 2016 10:02:16 -0300 Subject: [PATCH 044/254] 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 dd4ede007..4587fb829 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -152,7 +152,7 @@ int32_t komodo_check_deposit(const CBlock& block) // verify above block is valid int32_t i,n,scriptlen,num,iter,matchflag; uint256 txids[64]; uint8_t shortflag; char base[16]; uint16_t vouts[64]; uint8_t *script; queue_t *Q; struct pax_transaction *ptr; struct queueitem *item; n = block.vtx[0].vout.size(); script = (uint8_t *)block.vtx[0].vout[n-1].scriptPubKey.data(); - printf("checkdeposit n.%d [%02x]\n",n,script[0]); + printf("checkdeposit n.%d [%02x] [%c] %d vs %d\n",n,script[0],script[1],script[1],'I'); if ( n > 2 && script[0] == 0x6a && script[1] == 'I' ) { scriptlen = block.vtx[0].vout[n-1].scriptPubKey.size(); From 12d47153575aac8786d8361a5305a05d9b18bce5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 30 Oct 2016 10:08:41 -0300 Subject: [PATCH 045/254] test --- src/komodo_gateway.h | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 4587fb829..f8e2a20dd 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -149,14 +149,16 @@ int32_t komodo_gateway_depositremove(uint256 txid,uint16_t vout) // assetchain c int32_t komodo_check_deposit(const CBlock& block) // verify above block is valid pax pricing { - int32_t i,n,scriptlen,num,iter,matchflag; uint256 txids[64]; uint8_t shortflag; char base[16]; uint16_t vouts[64]; uint8_t *script; queue_t *Q; struct pax_transaction *ptr; struct queueitem *item; + int32_t i,n,opretlen,num,iter,matchflag,offset=1; uint256 txids[64]; uint8_t shortflag; char base[16]; uint16_t vouts[64]; uint8_t *script; queue_t *Q; struct pax_transaction *ptr; struct queueitem *item; n = block.vtx[0].vout.size(); script = (uint8_t *)block.vtx[0].vout[n-1].scriptPubKey.data(); - printf("checkdeposit n.%d [%02x] [%c] %d vs %d\n",n,script[0],script[1],script[1],'I'); - if ( n > 2 && script[0] == 0x6a && script[1] == 'I' ) + if ( n <= 2 || script[0] != 0x6a ) + return(0); + offset += komodo_scriptitemlen(&opretlen,&script[offset]); + printf("checkdeposit n.%d [%02x] [%c] %d vs %d\n",n,script[0],script[offset],script[offset],'I'); + if ( script[offset] == 'I' && opretlen < block.vtx[0].vout[n-1].scriptPubKey.size() ) { - scriptlen = block.vtx[0].vout[n-1].scriptPubKey.size(); - if ( (num= komodo_issued_opreturn(&shortflag,base,txids,vouts,script+1,scriptlen-1)) > 0 ) + if ( (num= komodo_issued_opreturn(&shortflag,base,txids,vouts,&script[offset],opretlen)) > 0 ) { for (i=1; i Date: Sun, 30 Oct 2016 10:12:07 -0300 Subject: [PATCH 046/254] test --- src/komodo_gateway.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index f8e2a20dd..d9b5d45cb 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -34,18 +34,18 @@ int32_t komodo_issued_opreturn(uint8_t *shortflagp,char *base,uint256 *txids,uin base[i] = opretbuf[opretlen-4+i]; if ( strncmp(ASSETCHAINS_SYMBOL,base,strlen(base)) == 0 ) // shortflag { - printf("BASE.(%s) vs (%s)\n",base,ASSETCHAINS_SYMBOL); + //printf("BASE.(%s) vs (%s)\n",base,ASSETCHAINS_SYMBOL); opretbuf++, opretlen--; for (n=len=0; n 0 ) @@ -178,7 +178,7 @@ int32_t komodo_check_deposit(const CBlock& block) // verify above block is valid { if ( ptr->fiatoshis == block.vtx[0].vout[i].nValue ) { - printf("matched %.8f vout.%d\n",dstr(ptr->fiatoshis),i); + //printf("matched %.8f vout.%d\n",dstr(ptr->fiatoshis),i); matchflag = 1; } else printf("error finding %.8f vout.%d\n",dstr(ptr->fiatoshis),i); break; @@ -194,7 +194,7 @@ int32_t komodo_check_deposit(const CBlock& block) // verify above block is valid } } } - printf("opretlen.%d num.%d\n",opretlen,num); + //printf("opretlen.%d num.%d\n",opretlen,num); } return(0); } @@ -242,9 +242,9 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 else if ( strncmp((char *)"KMD",(char *)&opretbuf[opretlen-4],3) != 0 ) { - for (i=0; i 0 ) From 2b4feae2ffb38aa474d1ecc68a80abd2fee33641 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 30 Oct 2016 10:18:15 -0300 Subject: [PATCH 047/254] 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 d9b5d45cb..12fa892ca 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -74,7 +74,7 @@ void komodo_gateway_deposits(CMutableTransaction *txNew) } data[len++] = ptr->vout & 0xff; data[len++] = (ptr->vout >> 8) & 0xff; - printf(" vout.%u DEPOSIT %.8f <- komodo_gateway_deposits\n",ptr->vout,(double)txNew->vout[numvouts].nValue/COIN); + printf(" vout.%u DEPOSIT %.8f <- paxdeposit.%s\n",ptr->vout,(double)txNew->vout[numvouts].nValue/COIN,ASSETCHAINS_SYMBOL); PENDING_KOMODO_TX += ptr->fiatoshis; numvouts++; queue_enqueue((char *)"PENDINGS",&PendingsQ,&ptr->DL); @@ -94,7 +94,7 @@ void komodo_gateway_deposits(CMutableTransaction *txNew) txNew->vout[numvouts].scriptPubKey.resize(opretlen); script = (uint8_t *)&txNew->vout[numvouts].scriptPubKey[0]; memcpy(script,opret,opretlen); - printf("total numvouts.%d %.8f opretlen.%d\n",numvouts,dstr(PENDING_KOMODO_TX),opretlen); + //printf("total numvouts.%d %.8f opretlen.%d\n",numvouts,dstr(PENDING_KOMODO_TX),opretlen); } else KOMODO_DEPOSIT = 0; } From 4ef3572a4337df3fcddc052c449f1c89c3ca3c99 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 30 Oct 2016 10:24:24 -0300 Subject: [PATCH 048/254] 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 12fa892ca..12726ceca 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -225,7 +225,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 for (i=0; i<33; i++) printf("%02x",pubkey33[i]); printf(" checkpubkey check %.8f v %.8f dest.(%s) height.%d\n",dstr(checktoshis),dstr(value),destaddr,height); - if ( value >= checktoshis )//&& shortflag == ASSETCHAINS_SHORTFLAG ) + if ( value >= checktoshis && shortflag == ASSETCHAINS_SHORTFLAG ) { komodo_gateway_deposit(coinaddr,value,shortflag,base,fiatoshis,rmd160,txid,vout); } @@ -247,7 +247,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 //printf(" komodo_opreturn[%c]: ht.%d %.8f opretlen.%d\n",opretbuf[0],height,dstr(value),opretlen); if ( tokomodo == 0 && opretbuf[0] == 'I' ) { - if ( (n= komodo_issued_opreturn(&shortflag,base,txids,vouts,opretbuf,opretlen)) > 0 ) + if ( (n= komodo_issued_opreturn(&shortflag,base,txids,vouts,opretbuf,opretlen)) > 0 && shortflag == ASSETCHAINS_SHORTFLAG ) { for (i=0; i Date: Sun, 30 Oct 2016 13:05:23 -0300 Subject: [PATCH 049/254] test --- src/komodo_gateway.h | 15 ++++++++------- src/main.cpp | 12 ++++-------- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 12726ceca..8e54d6a37 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -116,7 +116,7 @@ void komodo_gateway_deposit(char *coinaddr,uint64_t value,int32_t shortflag,char int32_t komodo_gateway_depositremove(uint256 txid,uint16_t vout) // assetchain context { - int32_t iter,n=0; queue_t *Q; struct pax_transaction *ptr; struct queueitem *item; + int32_t iter,i,n=0; queue_t *Q; struct pax_transaction *ptr; struct queueitem *item; for (iter=0; iter<2; iter++) { Q = (iter == 0) ? &DepositsQ : &PendingsQ; @@ -132,7 +132,9 @@ int32_t komodo_gateway_depositremove(uint256 txid,uint16_t vout) // assetchain c if ( KOMODO_DEPOSIT >= ptr->fiatoshis ) KOMODO_DEPOSIT -= ptr->fiatoshis; else KOMODO_DEPOSIT = 0; - printf("DELETE %.8f DEPOSIT %s %.8f\n",dstr(ptr->komodoshis),ptr->symbol,dstr(ptr->fiatoshis)); + for (i=0; i<32; i++) + printf("%02x",((uint8_t *)&txid)[i]); + printf(" v%d DELETE %.8f DEPOSIT %s %.8f\n",vout,dstr(ptr->komodoshis),ptr->symbol,dstr(ptr->fiatoshis)); DL_DELETE(Q->list,&ptr->DL); n++; free(ptr); @@ -241,10 +243,6 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 } else if ( strncmp((char *)"KMD",(char *)&opretbuf[opretlen-4],3) != 0 ) { - - //for (i=0; i 0 && shortflag == ASSETCHAINS_SHORTFLAG ) @@ -252,11 +250,14 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 for (i=0; iFromTx(tx, nHeight); + inputs.ModifyCoins(tx.GetHash())->FromTx(tx, nHeight); // add outputs } void UpdateCoins(const CTransaction& tx, CValidationState &state, CCoinsViewCache &inputs, int nHeight) From 65c873ea533c190186cd3b65f85c104df5419ba7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 30 Oct 2016 13:16:09 -0300 Subject: [PATCH 050/254] test --- src/komodo_gateway.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 8e54d6a37..449db892e 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -151,7 +151,7 @@ int32_t komodo_gateway_depositremove(uint256 txid,uint16_t vout) // assetchain c int32_t komodo_check_deposit(const CBlock& block) // verify above block is valid pax pricing { - int32_t i,n,opretlen,num,iter,matchflag,offset=1; uint256 txids[64]; uint8_t shortflag; char base[16]; uint16_t vouts[64]; uint8_t *script; queue_t *Q; struct pax_transaction *ptr; struct queueitem *item; + int32_t i,j,n,opretlen,num,iter,matchflag,offset=1; uint256 txids[64]; uint8_t shortflag; char base[16]; uint16_t vouts[64]; uint8_t *script; queue_t *Q; struct pax_transaction *ptr; struct queueitem *item; n = block.vtx[0].vout.size(); script = (uint8_t *)block.vtx[0].vout[n-1].scriptPubKey.data(); if ( n <= 2 || script[0] != 0x6a ) @@ -180,7 +180,9 @@ int32_t komodo_check_deposit(const CBlock& block) // verify above block is valid { if ( ptr->fiatoshis == block.vtx[0].vout[i].nValue ) { - //printf("matched %.8f vout.%d\n",dstr(ptr->fiatoshis),i); + for (j=0; j<32; j++) + printf("%02x",((uint8_t *)&ptr->txid)[j]); + printf(" v%d matched %.8f vout.%d\n",ptr->vout,dstr(ptr->fiatoshis),i); matchflag = 1; } else printf("error finding %.8f vout.%d\n",dstr(ptr->fiatoshis),i); break; From e21335280da0fab1b33e2098207525f52e7049dc Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 30 Oct 2016 13:19:51 -0300 Subject: [PATCH 051/254] 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 449db892e..5939f5902 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -34,18 +34,18 @@ int32_t komodo_issued_opreturn(uint8_t *shortflagp,char *base,uint256 *txids,uin base[i] = opretbuf[opretlen-4+i]; if ( strncmp(ASSETCHAINS_SYMBOL,base,strlen(base)) == 0 ) // shortflag { - //printf("BASE.(%s) vs (%s)\n",base,ASSETCHAINS_SYMBOL); + printf("BASE.(%s) vs (%s)\n",base,ASSETCHAINS_SYMBOL); opretbuf++, opretlen--; for (n=len=0; nvout[numvouts].scriptPubKey.resize(opretlen); script = (uint8_t *)&txNew->vout[numvouts].scriptPubKey[0]; memcpy(script,opret,opretlen); - //printf("total numvouts.%d %.8f opretlen.%d\n",numvouts,dstr(PENDING_KOMODO_TX),opretlen); + printf("total numvouts.%d %.8f opretlen.%d\n",numvouts,dstr(PENDING_KOMODO_TX),opretlen); } else KOMODO_DEPOSIT = 0; } From 4c9681781871d2c511017d500e9fe056b3978b9c Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 30 Oct 2016 13:23:05 -0300 Subject: [PATCH 052/254] 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 5939f5902..5f820c8bd 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -247,7 +247,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 { if ( tokomodo == 0 && opretbuf[0] == 'I' ) { - if ( (n= komodo_issued_opreturn(&shortflag,base,txids,vouts,opretbuf,opretlen)) > 0 && shortflag == ASSETCHAINS_SHORTFLAG ) + if ( (n= komodo_issued_opreturn(&shortflag,base,txids,vouts,opretbuf,opretlen)) > 0 )//&& shortflag == ASSETCHAINS_SHORTFLAG ) { for (i=0; i Date: Sun, 30 Oct 2016 13:24:52 -0300 Subject: [PATCH 053/254] test --- src/komodo_gateway.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 5f820c8bd..379da62ec 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -151,7 +151,7 @@ int32_t komodo_gateway_depositremove(uint256 txid,uint16_t vout) // assetchain c int32_t komodo_check_deposit(const CBlock& block) // verify above block is valid pax pricing { - int32_t i,j,n,opretlen,num,iter,matchflag,offset=1; uint256 txids[64]; uint8_t shortflag; char base[16]; uint16_t vouts[64]; uint8_t *script; queue_t *Q; struct pax_transaction *ptr; struct queueitem *item; + int32_t i,j,n,opretlen,num,iter,matchflag,offset=1; uint256 hash,txids[64]; uint8_t shortflag; char base[16]; uint16_t vouts[64]; uint8_t *script; queue_t *Q; struct pax_transaction *ptr; struct queueitem *item; n = block.vtx[0].vout.size(); script = (uint8_t *)block.vtx[0].vout[n-1].scriptPubKey.data(); if ( n <= 2 || script[0] != 0x6a ) @@ -182,7 +182,11 @@ int32_t komodo_check_deposit(const CBlock& block) // verify above block is valid { for (j=0; j<32; j++) printf("%02x",((uint8_t *)&ptr->txid)[j]); - printf(" v%d matched %.8f vout.%d\n",ptr->vout,dstr(ptr->fiatoshis),i); + printf(" v%d matched %.8f vout.%d ",ptr->vout,dstr(ptr->fiatoshis),i); + hash = block.GetHash(); + for (j=0; j<32; j++) + printf("%02x",((uint8_t *)&hash)[j]); + printf(".blockhash\n"); matchflag = 1; } else printf("error finding %.8f vout.%d\n",dstr(ptr->fiatoshis),i); break; From e1ee4f1d3b218b685a4f2034ecc7ff7eb86d7b8c Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 30 Oct 2016 13:42:51 -0300 Subject: [PATCH 054/254] test --- src/komodo_bitcoind.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index d37f4647f..49ea94c49 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -364,7 +364,12 @@ uint32_t komodo_txtime(uint256 hash) void komodo_disconnect(CBlockIndex *pindex,CBlock& block) { + int32_t i; uint256 hash; komodo_init(); + hash = block.GetHash(); + for (i=0; i<32; i++) + printf("%02x",((uint8_t *)&hash)[i]); + printf(" <- disconnect block\n"); //uint256 zero; //printf("disconnect ht.%d\n",pindex->nHeight); //memset(&zero,0,sizeof(zero)); From 3aca270523397a306caefd1b35cdcd1dcb0b6784 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 30 Oct 2016 14:59:59 -0300 Subject: [PATCH 055/254] test --- src/komodo_utils.h | 60 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 47 insertions(+), 13 deletions(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index afd4f2033..d6452b93c 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1309,9 +1309,54 @@ void komodo_configfile(char *symbol,uint16_t port) } else printf("couldnt open.(%s)\n",fname); } +uint32_t komodo_assetmagic(char *symbol,uint64_t supply) +{ + uint8_t buf[512]; int32_t len = 0; + len = iguana_rwnum(1,&buf[len],sizeof(supply),(void *)&supply); + strcpy((char *)&buf[len],symbol); + len += strlen(symbol); + return(calc_crc32(0,buf,len)); +} + +int32_t komodo_shortflag(char *symbol) +{ + int32_t i,shortflag = 0; + if ( symbol[0] == '-' ) + { + shortflag = 1; + for (i=0; symbol[i+1]!=0; i++) + symbol[i] = symbol[i+1]; + symbol[i] = 0; + } + return(shortflag); +} + +uint16_t komodo_assetport(uint32_t magic,int32_t shortflag) +{ + return(8000 + shortflag*7777 + (magic % 7777)); +} + +uint16_t komodo_port(char *symbol,uint64_t supply,uint32_t *magicp,int32_t *shortflagp) +{ + *magicp = komodo_assetmagic(symbol,supply); + *shortflagp = komodo_shortflag(symbol); + return(komodo_assetport(*magicp,*shortflagp)); +} + +void komodo_ports(uint16_t ports[MAX_CURRENCIES]) +{ + int32_t i,shortflag; uint32_t magic; + for (i=0; i Date: Sun, 30 Oct 2016 18:14:01 -0300 Subject: [PATCH 056/254] test --- src/komodo_bitcoind.h | 10 +++++----- src/komodo_gateway.h | 6 +++--- src/miner.cpp | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 49ea94c49..98d331bcf 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -364,12 +364,12 @@ uint32_t komodo_txtime(uint256 hash) void komodo_disconnect(CBlockIndex *pindex,CBlock& block) { - int32_t i; uint256 hash; + //int32_t i; uint256 hash; komodo_init(); - hash = block.GetHash(); - for (i=0; i<32; i++) - printf("%02x",((uint8_t *)&hash)[i]); - printf(" <- disconnect block\n"); + //hash = block.GetHash(); + //for (i=0; i<32; i++) + // printf("%02x",((uint8_t *)&hash)[i]); + //printf(" <- disconnect block\n"); //uint256 zero; //printf("disconnect ht.%d\n",pindex->nHeight); //memset(&zero,0,sizeof(zero)); diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 379da62ec..338c4073b 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -261,9 +261,9 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 if ( komodo_gateway_depositremove(txids[i],vouts[i]) == 0 ) printf("error removing deposit\n"); } - for (i=0; i<32; i++) - printf("%02x",((uint8_t *)&txid)[i]); - printf(" v%d komodo_opreturn[%c]: ht.%d %.8f opretlen.%d\n",vout,opretbuf[0],height,dstr(value),opretlen); + //for (i=0; i<32; i++) + // printf("%02x",((uint8_t *)&txid)[i]); + //printf(" v%d komodo_opreturn[%c]: ht.%d %.8f opretlen.%d\n",vout,opretbuf[0],height,dstr(value),opretlen); } } } diff --git a/src/miner.cpp b/src/miner.cpp index c1a585226..c8c273f23 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -115,11 +115,11 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) while ( ASSETCHAINS_SYMBOL[0] != 0 && chainActive.Tip()->nHeight > 10 && mempool.GetTotalTxSize() <= 0 ) { sleep(10); + printf("KOMODO_DEPOSIT %llu pblock->nHeight %d mempool.GetTotalTxSize(%d)\n",(long long)KOMODO_DEPOSIT,(int32_t)chainActive.Tip()->nHeight,(int32_t)mempool.GetTotalTxSize()); if ( KOMODO_INITDONE == 0 || time(NULL) < KOMODO_INITDONE+60 ) continue; if ( KOMODO_DEPOSIT != 0 ) { - printf("KOMODO_DEPOSIT %llu pblock->nHeight %d mempool.GetTotalTxSize(%d)\n",(long long)KOMODO_DEPOSIT,(int32_t)chainActive.Tip()->nHeight,(int32_t)mempool.GetTotalTxSize()); break; } } From 87c4ee0695fc4b71a3526fa627b5d871a167ba25 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 30 Oct 2016 18:26:22 -0300 Subject: [PATCH 057/254] test --- src/miner.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index c8c273f23..37ff5bac0 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -115,7 +115,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) while ( ASSETCHAINS_SYMBOL[0] != 0 && chainActive.Tip()->nHeight > 10 && mempool.GetTotalTxSize() <= 0 ) { sleep(10); - printf("KOMODO_DEPOSIT %llu pblock->nHeight %d mempool.GetTotalTxSize(%d)\n",(long long)KOMODO_DEPOSIT,(int32_t)chainActive.Tip()->nHeight,(int32_t)mempool.GetTotalTxSize()); + printf("miner KOMODO_DEPOSIT %llu pblock->nHeight %d mempool.GetTotalTxSize(%d)\n",(long long)KOMODO_DEPOSIT,(int32_t)chainActive.Tip()->nHeight,(int32_t)mempool.GetTotalTxSize()); if ( KOMODO_INITDONE == 0 || time(NULL) < KOMODO_INITDONE+60 ) continue; if ( KOMODO_DEPOSIT != 0 ) @@ -440,6 +440,7 @@ int32_t komodo_chosennotary(int32_t *notaryidp,int32_t height,uint8_t *pubkey33) CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey) { CPubKey pubkey; CScript scriptPubKey; uint8_t *script,*ptr; int32_t i; + fprintf(stderr,"%s createnewblockwith key\n",ASSETCHAINS_SYMBOL); if ( USE_EXTERNAL_PUBKEY != 0 ) { //fprintf(stderr,"use notary pubkey\n"); @@ -523,7 +524,7 @@ void static BitcoinMiner(CWallet *pwallet) try { while (true) { - if (ASSETCHAINS_SHORTFLAG == 0 && chainparams.MiningRequiresPeers()) + if (chainparams.MiningRequiresPeers()) { // Busy-wait for the network to come online so we don't waste time mining // on an obsolete chain. In regtest mode we expect to fly solo. @@ -540,7 +541,7 @@ void static BitcoinMiner(CWallet *pwallet) } while (true); //fprintf(stderr,"Found peers\n"); } - //fprintf(stderr,"create new block\n"); + fprintf(stderr,"%s create new block\n",ASSETCHAINS_SYMBOL); // // Create new block // @@ -572,6 +573,7 @@ void static BitcoinMiner(CWallet *pwallet) //fprintf(stderr,"I am the chosen one for ht.%d\n",pindexPrev->nHeight+1); } else Mining_start = 0; Mining_height = pindexPrev->nHeight+1; + fprintf(stderr,"%s start mining loop\n",ASSETCHAINS_SYMBOL); while (true) { // Hash state From 1a3c101822d008e755ef0f9abd2b46e53dd7fb4b Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 30 Oct 2016 18:35:44 -0300 Subject: [PATCH 058/254] test --- src/miner.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 37ff5bac0..cf76c0dc3 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -511,7 +511,7 @@ void static BitcoinMiner(CWallet *pwallet) std::string solver = GetArg("-equihashsolver", "tromp"); assert(solver == "tromp" || solver == "default"); LogPrint("pow", "Using Equihash solver \"%s\" with n = %u, k = %u\n", solver, n, k); - //fprintf(stderr,"Mining with %s\n",solver.c_str()); + fprintf(stderr,"Mining with %s\n",solver.c_str()); std::mutex m_cs; bool cancelSolver = false; boost::signals2::connection c = uiInterface.NotifyBlockTip.connect( @@ -539,7 +539,7 @@ void static BitcoinMiner(CWallet *pwallet) break; MilliSleep(1000); } while (true); - //fprintf(stderr,"Found peers\n"); + fprintf(stderr,"%s Found peers\n",ASSETCHAINS_SYMBOL); } fprintf(stderr,"%s create new block\n",ASSETCHAINS_SYMBOL); // From f8e367eba895e4ecbdd6c412b7b3493b54934ea6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 30 Oct 2016 18:39:51 -0300 Subject: [PATCH 059/254] test --- src/miner.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index cf76c0dc3..ed4f472aa 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -522,6 +522,7 @@ void static BitcoinMiner(CWallet *pwallet) ); try { + fprintf(stderr,"try %s Mining with %s\n",ASSETCHAINS_SYMBOL,solver.c_str()); while (true) { if (chainparams.MiningRequiresPeers()) @@ -537,7 +538,9 @@ void static BitcoinMiner(CWallet *pwallet) } if (!fvNodesEmpty && !IsInitialBlockDownload()) break; - MilliSleep(1000); + MilliSleep(5000); + fprintf(stderr,"fvNodesEmpty %d IsInitialBlockDownload() %d\n",(int32_t)fvNodesEmpty,(int32_t)IsInitialBlockDownload()); + } while (true); fprintf(stderr,"%s Found peers\n",ASSETCHAINS_SYMBOL); } From 8e157f5204cfb5cd3f92a4ee9cfa7a308953dc1a Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 30 Oct 2016 18:44:41 -0300 Subject: [PATCH 060/254] test --- src/main.cpp | 9 +++++++++ src/miner.cpp | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 8cb98cb7a..4099af178 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1469,16 +1469,25 @@ bool IsInitialBlockDownload() const CChainParams& chainParams = Params(); LOCK(cs_main); if (fImporting || fReindex) + { + fprintf(stderr,"fImporting %d || %d fReindex\n",(int32_t)fImporting,(int32_t)fReindex); return true; + } if (fCheckpointsEnabled && chainActive.Height() < Checkpoints::GetTotalBlocksEstimate(chainParams.Checkpoints())) + { + fprintf(stderr,"checkpoint -> initialdownload\n"); return true; + } static bool lockIBDState = false; if (lockIBDState) return false; bool state = (chainActive.Height() < pindexBestHeader->nHeight - 24 * 6 || pindexBestHeader->GetBlockTime() < GetTime() - chainParams.MaxTipAge()); if (!state) + { + fprintf(stderr,"lockIBDState tru\n"); lockIBDState = true; + } return state; } diff --git a/src/miner.cpp b/src/miner.cpp index ed4f472aa..a2a506bda 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -539,7 +539,7 @@ void static BitcoinMiner(CWallet *pwallet) if (!fvNodesEmpty && !IsInitialBlockDownload()) break; MilliSleep(5000); - fprintf(stderr,"fvNodesEmpty %d IsInitialBlockDownload() %d\n",(int32_t)fvNodesEmpty,(int32_t)IsInitialBlockDownload()); + fprintf(stderr,"fvNodesEmpty %d IsInitialBlockDownload(%s) %d\n",(int32_t)fvNodesEmpty,ASSETCHAINS_SYMBOL,(int32_t)IsInitialBlockDownload()); } while (true); fprintf(stderr,"%s Found peers\n",ASSETCHAINS_SYMBOL); From cb237ef8c63306cc48ff77dfd6f566e5244edad1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 30 Oct 2016 18:50:46 -0300 Subject: [PATCH 061/254] test --- src/main.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 4099af178..ef0b3c0b8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1466,7 +1466,7 @@ CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams) bool IsInitialBlockDownload() { - const CChainParams& chainParams = Params(); + int32_t gap; const CChainParams& chainParams = Params(); LOCK(cs_main); if (fImporting || fReindex) { @@ -1480,9 +1480,14 @@ bool IsInitialBlockDownload() } static bool lockIBDState = false; if (lockIBDState) + { + fprintf(stderr,"lockIBDState true\n"); return false; - bool state = (chainActive.Height() < pindexBestHeader->nHeight - 24 * 6 || + } + gap = ASSETCHAINS_SYMBOL[0] == 0 ? 24 * 6 : 1; + bool state = (chainActive.Height() < pindexBestHeader->nHeight - gap || pindexBestHeader->GetBlockTime() < GetTime() - chainParams.MaxTipAge()); + fprintf(stderr,"height.%d < best.%d\n",chainActive.Height(),pindexBestHeader->nHeight); if (!state) { fprintf(stderr,"lockIBDState tru\n"); From a4e1979db30d5b0de05e0e7d92f086f1685b2b65 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 30 Oct 2016 18:53:01 -0300 Subject: [PATCH 062/254] test --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index ef0b3c0b8..65977aee1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1487,7 +1487,7 @@ bool IsInitialBlockDownload() gap = ASSETCHAINS_SYMBOL[0] == 0 ? 24 * 6 : 1; bool state = (chainActive.Height() < pindexBestHeader->nHeight - gap || pindexBestHeader->GetBlockTime() < GetTime() - chainParams.MaxTipAge()); - fprintf(stderr,"height.%d < best.%d\n",chainActive.Height(),pindexBestHeader->nHeight); + fprintf(stderr,"height.%d < best.%d, %u < %u - %u\n",chainActive.Height(),pindexBestHeader->nHeight,(uint32_t)pindexBestHeader->GetBlockTime(),(uint32_t)GetTime(),(uint32_t)chainParams.MaxTipAge()); if (!state) { fprintf(stderr,"lockIBDState tru\n"); From 5fb71d9c4fb7d48ec72fcebbf7d9aa71fb899756 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 30 Oct 2016 18:54:51 -0300 Subject: [PATCH 063/254] test --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 65977aee1..24956edf1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1487,7 +1487,7 @@ bool IsInitialBlockDownload() gap = ASSETCHAINS_SYMBOL[0] == 0 ? 24 * 6 : 1; bool state = (chainActive.Height() < pindexBestHeader->nHeight - gap || pindexBestHeader->GetBlockTime() < GetTime() - chainParams.MaxTipAge()); - fprintf(stderr,"height.%d < best.%d, %u < %u - %u\n",chainActive.Height(),pindexBestHeader->nHeight,(uint32_t)pindexBestHeader->GetBlockTime(),(uint32_t)GetTime(),(uint32_t)chainParams.MaxTipAge()); + fprintf(stderr,"height.%d < best.%d, %u < %u %u - %u\n",chainActive.Height(),pindexBestHeader->nHeight,(uint32_t)pindexBestHeader->GetBlockTime(),(uint32_t)(GetTime() - chainParams.MaxTipAge()),(uint32_t)GetTime(),(uint32_t)chainParams.MaxTipAge()); if (!state) { fprintf(stderr,"lockIBDState tru\n"); From 5b362944dc8d58e5bb31b35ba5a7d635efb36b05 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 30 Oct 2016 18:58:06 -0300 Subject: [PATCH 064/254] test --- src/main.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 24956edf1..560d2d9e8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1466,7 +1466,7 @@ CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams) bool IsInitialBlockDownload() { - int32_t gap; const CChainParams& chainParams = Params(); + int32_t gap,diff; const CChainParams& chainParams = Params(); LOCK(cs_main); if (fImporting || fReindex) { @@ -1485,9 +1485,10 @@ bool IsInitialBlockDownload() return false; } gap = ASSETCHAINS_SYMBOL[0] == 0 ? 24 * 6 : 1; + diff = ASSETCHAINS_SYMBOL[0] == 0 ? chainParams.MaxTipAge() : 60; bool state = (chainActive.Height() < pindexBestHeader->nHeight - gap || - pindexBestHeader->GetBlockTime() < GetTime() - chainParams.MaxTipAge()); - fprintf(stderr,"height.%d < best.%d, %u < %u %u - %u\n",chainActive.Height(),pindexBestHeader->nHeight,(uint32_t)pindexBestHeader->GetBlockTime(),(uint32_t)(GetTime() - chainParams.MaxTipAge()),(uint32_t)GetTime(),(uint32_t)chainParams.MaxTipAge()); + pindexBestHeader->GetBlockTime() < GetTime() - diff); + fprintf(stderr,"height.%d < best.%d, %u < %u %u - %u\n",chainActive.Height(),pindexBestHeader->nHeight,(uint32_t)pindexBestHeader->GetBlockTime(),(uint32_t)(GetTime() - diff),(uint32_t)GetTime(),(uint32_t)diff); if (!state) { fprintf(stderr,"lockIBDState tru\n"); From e1e3f309d01316a94913f5b600325abc009d27eb Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 30 Oct 2016 19:05:05 -0300 Subject: [PATCH 065/254] test --- src/main.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 560d2d9e8..37006f7e9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1466,7 +1466,7 @@ CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams) bool IsInitialBlockDownload() { - int32_t gap,diff; const CChainParams& chainParams = Params(); + const CChainParams& chainParams = Params(); LOCK(cs_main); if (fImporting || fReindex) { @@ -1484,11 +1484,11 @@ bool IsInitialBlockDownload() fprintf(stderr,"lockIBDState true\n"); return false; } - gap = ASSETCHAINS_SYMBOL[0] == 0 ? 24 * 6 : 1; - diff = ASSETCHAINS_SYMBOL[0] == 0 ? chainParams.MaxTipAge() : 60; - bool state = (chainActive.Height() < pindexBestHeader->nHeight - gap || - pindexBestHeader->GetBlockTime() < GetTime() - diff); - fprintf(stderr,"height.%d < best.%d, %u < %u %u - %u\n",chainActive.Height(),pindexBestHeader->nHeight,(uint32_t)pindexBestHeader->GetBlockTime(),(uint32_t)(GetTime() - diff),(uint32_t)GetTime(),(uint32_t)diff); + bool state; + if ( ASSETCHAINS_SYMBOL[0] == 0 ) + state = (chainActive.Height() < pindexBestHeader->nHeight - 24*6) || + pindexBestHeader->GetBlockTime() < (GetTime() - chainParams.MaxTipAge()); + else state = (chainActive.Height() < pindexBestHeader->nHeight - 10); if (!state) { fprintf(stderr,"lockIBDState tru\n"); From 08f08d150caf77d75235297cad6b29fa078ffc9a Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 30 Oct 2016 19:10:54 -0300 Subject: [PATCH 066/254] test --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 37006f7e9..f0fd1a741 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1481,7 +1481,7 @@ bool IsInitialBlockDownload() static bool lockIBDState = false; if (lockIBDState) { - fprintf(stderr,"lockIBDState true\n"); + fprintf(stderr,"lockIBDState true %d < %d\n",chainActive.Height(),pindexBestHeader->nHeight - 10); return false; } bool state; From ced1a10b52f8485b8c8d0e948b2a0c15fcffff63 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 30 Oct 2016 19:12:23 -0300 Subject: [PATCH 067/254] test --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index f0fd1a741..d66f8d012 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1481,7 +1481,7 @@ bool IsInitialBlockDownload() static bool lockIBDState = false; if (lockIBDState) { - fprintf(stderr,"lockIBDState true %d < %d\n",chainActive.Height(),pindexBestHeader->nHeight - 10); + //fprintf(stderr,"lockIBDState true %d < %d\n",chainActive.Height(),pindexBestHeader->nHeight - 10); return false; } bool state; From 12691d502cf58e5a7bd93435684da18a5b903387 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 30 Oct 2016 19:16:53 -0300 Subject: [PATCH 068/254] test --- src/main.cpp | 6 +++--- src/miner.cpp | 14 +++++++------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index d66f8d012..bd82624af 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1470,12 +1470,12 @@ bool IsInitialBlockDownload() LOCK(cs_main); if (fImporting || fReindex) { - fprintf(stderr,"fImporting %d || %d fReindex\n",(int32_t)fImporting,(int32_t)fReindex); + //fprintf(stderr,"fImporting %d || %d fReindex\n",(int32_t)fImporting,(int32_t)fReindex); return true; } if (fCheckpointsEnabled && chainActive.Height() < Checkpoints::GetTotalBlocksEstimate(chainParams.Checkpoints())) { - fprintf(stderr,"checkpoint -> initialdownload\n"); + //fprintf(stderr,"checkpoint -> initialdownload\n"); return true; } static bool lockIBDState = false; @@ -1491,7 +1491,7 @@ bool IsInitialBlockDownload() else state = (chainActive.Height() < pindexBestHeader->nHeight - 10); if (!state) { - fprintf(stderr,"lockIBDState tru\n"); + //fprintf(stderr,"lockIBDState tru\n"); lockIBDState = true; } return state; diff --git a/src/miner.cpp b/src/miner.cpp index a2a506bda..4cbebba64 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -440,7 +440,7 @@ int32_t komodo_chosennotary(int32_t *notaryidp,int32_t height,uint8_t *pubkey33) CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey) { CPubKey pubkey; CScript scriptPubKey; uint8_t *script,*ptr; int32_t i; - fprintf(stderr,"%s createnewblockwith key\n",ASSETCHAINS_SYMBOL); + //fprintf(stderr,"%s createnewblockwith key\n",ASSETCHAINS_SYMBOL); if ( USE_EXTERNAL_PUBKEY != 0 ) { //fprintf(stderr,"use notary pubkey\n"); @@ -511,7 +511,7 @@ void static BitcoinMiner(CWallet *pwallet) std::string solver = GetArg("-equihashsolver", "tromp"); assert(solver == "tromp" || solver == "default"); LogPrint("pow", "Using Equihash solver \"%s\" with n = %u, k = %u\n", solver, n, k); - fprintf(stderr,"Mining with %s\n",solver.c_str()); + //fprintf(stderr,"Mining with %s\n",solver.c_str()); std::mutex m_cs; bool cancelSolver = false; boost::signals2::connection c = uiInterface.NotifyBlockTip.connect( @@ -522,7 +522,7 @@ void static BitcoinMiner(CWallet *pwallet) ); try { - fprintf(stderr,"try %s Mining with %s\n",ASSETCHAINS_SYMBOL,solver.c_str()); + //fprintf(stderr,"try %s Mining with %s\n",ASSETCHAINS_SYMBOL,solver.c_str()); while (true) { if (chainparams.MiningRequiresPeers()) @@ -539,12 +539,12 @@ void static BitcoinMiner(CWallet *pwallet) if (!fvNodesEmpty && !IsInitialBlockDownload()) break; MilliSleep(5000); - fprintf(stderr,"fvNodesEmpty %d IsInitialBlockDownload(%s) %d\n",(int32_t)fvNodesEmpty,ASSETCHAINS_SYMBOL,(int32_t)IsInitialBlockDownload()); + //fprintf(stderr,"fvNodesEmpty %d IsInitialBlockDownload(%s) %d\n",(int32_t)fvNodesEmpty,ASSETCHAINS_SYMBOL,(int32_t)IsInitialBlockDownload()); } while (true); - fprintf(stderr,"%s Found peers\n",ASSETCHAINS_SYMBOL); + //fprintf(stderr,"%s Found peers\n",ASSETCHAINS_SYMBOL); } - fprintf(stderr,"%s create new block\n",ASSETCHAINS_SYMBOL); + //fprintf(stderr,"%s create new block\n",ASSETCHAINS_SYMBOL); // // Create new block // @@ -576,7 +576,7 @@ void static BitcoinMiner(CWallet *pwallet) //fprintf(stderr,"I am the chosen one for ht.%d\n",pindexPrev->nHeight+1); } else Mining_start = 0; Mining_height = pindexPrev->nHeight+1; - fprintf(stderr,"%s start mining loop\n",ASSETCHAINS_SYMBOL); + //fprintf(stderr,"%s start mining loop\n",ASSETCHAINS_SYMBOL); while (true) { // Hash state From 08c2e8e7e8cd2151b58d11601426066266a1200b Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 30 Oct 2016 19:20:08 -0300 Subject: [PATCH 069/254] test --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index 4cbebba64..9063445ea 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -115,11 +115,11 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) while ( ASSETCHAINS_SYMBOL[0] != 0 && chainActive.Tip()->nHeight > 10 && mempool.GetTotalTxSize() <= 0 ) { sleep(10); - printf("miner KOMODO_DEPOSIT %llu pblock->nHeight %d mempool.GetTotalTxSize(%d)\n",(long long)KOMODO_DEPOSIT,(int32_t)chainActive.Tip()->nHeight,(int32_t)mempool.GetTotalTxSize()); if ( KOMODO_INITDONE == 0 || time(NULL) < KOMODO_INITDONE+60 ) continue; if ( KOMODO_DEPOSIT != 0 ) { + printf("miner KOMODO_DEPOSIT %llu pblock->nHeight %d mempool.GetTotalTxSize(%d)\n",(long long)KOMODO_DEPOSIT,(int32_t)chainActive.Tip()->nHeight,(int32_t)mempool.GetTotalTxSize()); break; } } From b469f7908430da94352fb37d2180b27130eabecf Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 30 Oct 2016 20:06:51 -0300 Subject: [PATCH 070/254] test --- src/assetchains | 65 +++++++++++++++++++++++++------------------------ src/miner.cpp | 5 +++- 2 files changed, 37 insertions(+), 33 deletions(-) diff --git a/src/assetchains b/src/assetchains index 32700d0da..ad820d7c2 100755 --- a/src/assetchains +++ b/src/assetchains @@ -1,32 +1,33 @@ -./komodod -ac_name=USD -addnode=78.47.196.146 & -./komodod -ac_name=EUR -addnode=78.47.196.146 & -./komodod -ac_name=JPY -addnode=78.47.196.146 & -./komodod -ac_name=GBP -addnode=78.47.196.146 & -./komodod -ac_name=AUD -addnode=78.47.196.146 & -./komodod -ac_name=CAD -addnode=78.47.196.146 & -./komodod -ac_name=CHF -addnode=78.47.196.146 & -./komodod -ac_name=NZD -addnode=78.47.196.146 & -./komodod -ac_name=CNY -addnode=78.47.196.146 & -./komodod -ac_name=RUB -addnode=78.47.196.146 & -./komodod -ac_name=MXN -addnode=78.47.196.146 & -./komodod -ac_name=BRL -addnode=78.47.196.146 & -./komodod -ac_name=INR -addnode=78.47.196.146 & -./komodod -ac_name=HKD -addnode=78.47.196.146 & -./komodod -ac_name=TRY -addnode=78.47.196.146 & -./komodod -ac_name=ZAR -addnode=78.47.196.146 & -./komodod -ac_name=PLN -addnode=78.47.196.146 & -./komodod -ac_name=NOK -addnode=78.47.196.146 & -./komodod -ac_name=SEK -addnode=78.47.196.146 & -./komodod -ac_name=DKK -addnode=78.47.196.146 & -./komodod -ac_name=CZK -addnode=78.47.196.146 & -./komodod -ac_name=HUF -addnode=78.47.196.146 & -./komodod -ac_name=ILS -addnode=78.47.196.146 & -./komodod -ac_name=KRW -addnode=78.47.196.146 & -./komodod -ac_name=MYR -addnode=78.47.196.146 & -./komodod -ac_name=PHP -addnode=78.47.196.146 & -./komodod -ac_name=RON -addnode=78.47.196.146 & -./komodod -ac_name=SGD -addnode=78.47.196.146 & -./komodod -ac_name=THB -addnode=78.47.196.146 & -./komodod -ac_name=BGN -addnode=78.47.196.146 & -./komodod -ac_name=IDR -addnode=78.47.196.146 & -./komodod -ac_name=HRK -addnode=78.47.196.146 & +.include pubkey.txt +./komodod -pub=$pubkey -ac_name=USD -addnode=78.47.196.146 & +./komodod -pub=$pubkey -ac_name=EUR -addnode=78.47.196.146 & +./komodod -pub=$pubkey -ac_name=JPY -addnode=78.47.196.146 & +./komodod -pub=$pubkey -ac_name=GBP -addnode=78.47.196.146 & +./komodod -pub=$pubkey -ac_name=AUD -addnode=78.47.196.146 & +./komodod -pub=$pubkey -ac_name=CAD -addnode=78.47.196.146 & +./komodod -pub=$pubkey -ac_name=CHF -addnode=78.47.196.146 & +./komodod -pub=$pubkey -ac_name=NZD -addnode=78.47.196.146 & +./komodod -pub=$pubkey -ac_name=CNY -addnode=78.47.196.146 & +./komodod -pub=$pubkey -ac_name=RUB -addnode=78.47.196.146 & +./komodod -pub=$pubkey -ac_name=MXN -addnode=78.47.196.146 & +./komodod -pub=$pubkey -ac_name=BRL -addnode=78.47.196.146 & +./komodod -pub=$pubkey -ac_name=INR -addnode=78.47.196.146 & +./komodod -pub=$pubkey -ac_name=HKD -addnode=78.47.196.146 & +./komodod -pub=$pubkey -ac_name=TRY -addnode=78.47.196.146 & +./komodod -pub=$pubkey -ac_name=ZAR -addnode=78.47.196.146 & +./komodod -pub=$pubkey -ac_name=PLN -addnode=78.47.196.146 & +./komodod -pub=$pubkey -ac_name=NOK -addnode=78.47.196.146 & +./komodod -pub=$pubkey -ac_name=SEK -addnode=78.47.196.146 & +./komodod -pub=$pubkey -ac_name=DKK -addnode=78.47.196.146 & +./komodod -pub=$pubkey -ac_name=CZK -addnode=78.47.196.146 & +./komodod -pub=$pubkey -ac_name=HUF -addnode=78.47.196.146 & +./komodod -pub=$pubkey -ac_name=ILS -addnode=78.47.196.146 & +./komodod -pub=$pubkey -ac_name=KRW -addnode=78.47.196.146 & +./komodod -pub=$pubkey -ac_name=MYR -addnode=78.47.196.146 & +./komodod -pub=$pubkey -ac_name=PHP -addnode=78.47.196.146 & +./komodod -pub=$pubkey -ac_name=RON -addnode=78.47.196.146 & +./komodod -pub=$pubkey -ac_name=SGD -addnode=78.47.196.146 & +./komodod -pub=$pubkey -ac_name=THB -addnode=78.47.196.146 & +./komodod -pub=$pubkey -ac_name=BGN -addnode=78.47.196.146 & +./komodod -pub=$pubkey -ac_name=IDR -addnode=78.47.196.146 & +./komodod -pub=$pubkey -ac_name=HRK -addnode=78.47.196.146 & diff --git a/src/miner.cpp b/src/miner.cpp index 9063445ea..f08635047 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -619,7 +619,10 @@ void static BitcoinMiner(CWallet *pwallet) std::lock_guard lock{m_cs}; cancelSolver = false; } - fprintf(stderr,"%s Block found %d\n",ASSETCHAINS_SYMBOL,Mining_height); + int32_t i; uint256 hash = pblock->GetHash(); + for (i=0; i<32; i++) + printf("%02x",((uint8_t *)&hash)[i]); + fprintf(stderr," <- %s Block found %d\n",ASSETCHAINS_SYMBOL,Mining_height); SetThreadPriority(THREAD_PRIORITY_LOWEST); // In regression test mode, stop mining after a block is found. if (chainparams.MineBlocksOnDemand()) { From 533a5d5d2044740535bba4d9f2b74625b4dfdf29 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 30 Oct 2016 20:11:00 -0300 Subject: [PATCH 071/254] test --- src/bitcoind.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bitcoind.cpp b/src/bitcoind.cpp index 6d802b873..4ee421f0d 100644 --- a/src/bitcoind.cpp +++ b/src/bitcoind.cpp @@ -97,8 +97,8 @@ bool AppInit(int argc, char* argv[]) try { void komodo_args(); - fprintf(stderr,"call komodo_args\n"); komodo_args(); + fprintf(stderr,"call komodo_args NOTARY_PUBKEY.(%s)\n",NOTARY_PUBKEY.c_str()); while ( ASSETCHAIN_INIT == 0 ) { sleep(1); From 65e5244a3e921bbc4898d41b3a385550c5395982 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 30 Oct 2016 20:13:45 -0300 Subject: [PATCH 072/254] test --- src/assetchains | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/assetchains b/src/assetchains index ad820d7c2..409b01885 100755 --- a/src/assetchains +++ b/src/assetchains @@ -1,4 +1,4 @@ -.include pubkey.txt +pubkey= `cat pubkey.txt` ./komodod -pub=$pubkey -ac_name=USD -addnode=78.47.196.146 & ./komodod -pub=$pubkey -ac_name=EUR -addnode=78.47.196.146 & ./komodod -pub=$pubkey -ac_name=JPY -addnode=78.47.196.146 & From 428baa350c88c1164c0909cb4cf0561817af3e66 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 30 Oct 2016 20:16:49 -0300 Subject: [PATCH 073/254] test --- src/assetchains | 1 + 1 file changed, 1 insertion(+) diff --git a/src/assetchains b/src/assetchains index 409b01885..5a800ddfc 100755 --- a/src/assetchains +++ b/src/assetchains @@ -1,4 +1,5 @@ pubkey= `cat pubkey.txt` +echo PUBKEY=($pubkey) ./komodod -pub=$pubkey -ac_name=USD -addnode=78.47.196.146 & ./komodod -pub=$pubkey -ac_name=EUR -addnode=78.47.196.146 & ./komodod -pub=$pubkey -ac_name=JPY -addnode=78.47.196.146 & From df8c239e9d87bb3fb8243dc1b686ec5b5b3cd881 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 30 Oct 2016 20:19:54 -0300 Subject: [PATCH 074/254] test --- src/assetchains | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/assetchains b/src/assetchains index 5a800ddfc..80911ea88 100755 --- a/src/assetchains +++ b/src/assetchains @@ -1,5 +1,5 @@ pubkey= `cat pubkey.txt` -echo PUBKEY=($pubkey) +echo PUBKEY $pubkey ./komodod -pub=$pubkey -ac_name=USD -addnode=78.47.196.146 & ./komodod -pub=$pubkey -ac_name=EUR -addnode=78.47.196.146 & ./komodod -pub=$pubkey -ac_name=JPY -addnode=78.47.196.146 & From 91452e48cf6bd06c8f15526268e311940d537b8c Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 30 Oct 2016 20:22:41 -0300 Subject: [PATCH 075/254] test --- src/assetchains | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/assetchains b/src/assetchains index 80911ea88..3d13d2286 100755 --- a/src/assetchains +++ b/src/assetchains @@ -1,5 +1,5 @@ -pubkey= `cat pubkey.txt` -echo PUBKEY $pubkey +.include pubkey.txt + ./komodod -pub=$pubkey -ac_name=USD -addnode=78.47.196.146 & ./komodod -pub=$pubkey -ac_name=EUR -addnode=78.47.196.146 & ./komodod -pub=$pubkey -ac_name=JPY -addnode=78.47.196.146 & From 75b1611be0ac535973d1c918f45386a2524ccecc Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 30 Oct 2016 20:23:22 -0300 Subject: [PATCH 076/254] test --- src/assetchains | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/assetchains b/src/assetchains index 3d13d2286..d51b1b1eb 100755 --- a/src/assetchains +++ b/src/assetchains @@ -1,4 +1,4 @@ -.include pubkey.txt +include pubkey.txt ./komodod -pub=$pubkey -ac_name=USD -addnode=78.47.196.146 & ./komodod -pub=$pubkey -ac_name=EUR -addnode=78.47.196.146 & From 189c6c0207af5fffff0d4c00b81353ac1006aaf4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 30 Oct 2016 20:26:03 -0300 Subject: [PATCH 077/254] test --- src/assetchains | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/assetchains b/src/assetchains index d51b1b1eb..a2e29c0cc 100755 --- a/src/assetchains +++ b/src/assetchains @@ -1,4 +1,4 @@ -include pubkey.txt +source pubkey.txt ./komodod -pub=$pubkey -ac_name=USD -addnode=78.47.196.146 & ./komodod -pub=$pubkey -ac_name=EUR -addnode=78.47.196.146 & From 4cd591113f2d3e6d78abf08f635da0e5fb76b268 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 30 Oct 2016 20:28:04 -0300 Subject: [PATCH 078/254] test --- src/assetchains | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/assetchains b/src/assetchains index a2e29c0cc..ae9f569cc 100755 --- a/src/assetchains +++ b/src/assetchains @@ -1,5 +1,5 @@ source pubkey.txt - +echo $pubkey ./komodod -pub=$pubkey -ac_name=USD -addnode=78.47.196.146 & ./komodod -pub=$pubkey -ac_name=EUR -addnode=78.47.196.146 & ./komodod -pub=$pubkey -ac_name=JPY -addnode=78.47.196.146 & From e53d8727ea1e2538655361b5acbfda675920cd7d Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 30 Oct 2016 20:30:08 -0300 Subject: [PATCH 079/254] test --- src/assetchains | 64 ++++++++++++++++++++++++------------------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/src/assetchains b/src/assetchains index ae9f569cc..b93265332 100755 --- a/src/assetchains +++ b/src/assetchains @@ -1,34 +1,34 @@ source pubkey.txt echo $pubkey -./komodod -pub=$pubkey -ac_name=USD -addnode=78.47.196.146 & -./komodod -pub=$pubkey -ac_name=EUR -addnode=78.47.196.146 & -./komodod -pub=$pubkey -ac_name=JPY -addnode=78.47.196.146 & -./komodod -pub=$pubkey -ac_name=GBP -addnode=78.47.196.146 & -./komodod -pub=$pubkey -ac_name=AUD -addnode=78.47.196.146 & -./komodod -pub=$pubkey -ac_name=CAD -addnode=78.47.196.146 & -./komodod -pub=$pubkey -ac_name=CHF -addnode=78.47.196.146 & -./komodod -pub=$pubkey -ac_name=NZD -addnode=78.47.196.146 & -./komodod -pub=$pubkey -ac_name=CNY -addnode=78.47.196.146 & -./komodod -pub=$pubkey -ac_name=RUB -addnode=78.47.196.146 & -./komodod -pub=$pubkey -ac_name=MXN -addnode=78.47.196.146 & -./komodod -pub=$pubkey -ac_name=BRL -addnode=78.47.196.146 & -./komodod -pub=$pubkey -ac_name=INR -addnode=78.47.196.146 & -./komodod -pub=$pubkey -ac_name=HKD -addnode=78.47.196.146 & -./komodod -pub=$pubkey -ac_name=TRY -addnode=78.47.196.146 & -./komodod -pub=$pubkey -ac_name=ZAR -addnode=78.47.196.146 & -./komodod -pub=$pubkey -ac_name=PLN -addnode=78.47.196.146 & -./komodod -pub=$pubkey -ac_name=NOK -addnode=78.47.196.146 & -./komodod -pub=$pubkey -ac_name=SEK -addnode=78.47.196.146 & -./komodod -pub=$pubkey -ac_name=DKK -addnode=78.47.196.146 & -./komodod -pub=$pubkey -ac_name=CZK -addnode=78.47.196.146 & -./komodod -pub=$pubkey -ac_name=HUF -addnode=78.47.196.146 & -./komodod -pub=$pubkey -ac_name=ILS -addnode=78.47.196.146 & -./komodod -pub=$pubkey -ac_name=KRW -addnode=78.47.196.146 & -./komodod -pub=$pubkey -ac_name=MYR -addnode=78.47.196.146 & -./komodod -pub=$pubkey -ac_name=PHP -addnode=78.47.196.146 & -./komodod -pub=$pubkey -ac_name=RON -addnode=78.47.196.146 & -./komodod -pub=$pubkey -ac_name=SGD -addnode=78.47.196.146 & -./komodod -pub=$pubkey -ac_name=THB -addnode=78.47.196.146 & -./komodod -pub=$pubkey -ac_name=BGN -addnode=78.47.196.146 & -./komodod -pub=$pubkey -ac_name=IDR -addnode=78.47.196.146 & -./komodod -pub=$pubkey -ac_name=HRK -addnode=78.47.196.146 & +./komodod -pubkey=$pubkey -ac_name=USD -addnode=78.47.196.146 & +./komodod -pubkey=$pubkey -ac_name=EUR -addnode=78.47.196.146 & +./komodod -pubkey=$pubkey -ac_name=JPY -addnode=78.47.196.146 & +./komodod -pubkey=$pubkey -ac_name=GBP -addnode=78.47.196.146 & +./komodod -pubkey=$pubkey -ac_name=AUD -addnode=78.47.196.146 & +./komodod -pubkey=$pubkey -ac_name=CAD -addnode=78.47.196.146 & +./komodod -pubkey=$pubkey -ac_name=CHF -addnode=78.47.196.146 & +./komodod -pubkey=$pubkey -ac_name=NZD -addnode=78.47.196.146 & +./komodod -pubkey=$pubkey -ac_name=CNY -addnode=78.47.196.146 & +./komodod -pubkey=$pubkey -ac_name=RUB -addnode=78.47.196.146 & +./komodod -pubkey=$pubkey -ac_name=MXN -addnode=78.47.196.146 & +./komodod -pubkey=$pubkey -ac_name=BRL -addnode=78.47.196.146 & +./komodod -pubkey=$pubkey -ac_name=INR -addnode=78.47.196.146 & +./komodod -pubkey=$pubkey -ac_name=HKD -addnode=78.47.196.146 & +./komodod -pubkey=$pubkey -ac_name=TRY -addnode=78.47.196.146 & +./komodod -pubkey=$pubkey -ac_name=ZAR -addnode=78.47.196.146 & +./komodod -pubkey=$pubkey -ac_name=PLN -addnode=78.47.196.146 & +./komodod -pubkey=$pubkey -ac_name=NOK -addnode=78.47.196.146 & +./komodod -pubkey=$pubkey -ac_name=SEK -addnode=78.47.196.146 & +./komodod -pubkey=$pubkey -ac_name=DKK -addnode=78.47.196.146 & +./komodod -pubkey=$pubkey -ac_name=CZK -addnode=78.47.196.146 & +./komodod -pubkey=$pubkey -ac_name=HUF -addnode=78.47.196.146 & +./komodod -pubkey=$pubkey -ac_name=ILS -addnode=78.47.196.146 & +./komodod -pubkey=$pubkey -ac_name=KRW -addnode=78.47.196.146 & +./komodod -pubkey=$pubkey -ac_name=MYR -addnode=78.47.196.146 & +./komodod -pubkey=$pubkey -ac_name=PHP -addnode=78.47.196.146 & +./komodod -pubkey=$pubkey -ac_name=RON -addnode=78.47.196.146 & +./komodod -pubkey=$pubkey -ac_name=SGD -addnode=78.47.196.146 & +./komodod -pubkey=$pubkey -ac_name=THB -addnode=78.47.196.146 & +./komodod -pubkey=$pubkey -ac_name=BGN -addnode=78.47.196.146 & +./komodod -pubkey=$pubkey -ac_name=IDR -addnode=78.47.196.146 & +./komodod -pubkey=$pubkey -ac_name=HRK -addnode=78.47.196.146 & From e647aac37a505f507778ec15cad45c4d888eb71d Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 30 Oct 2016 20:46:42 -0300 Subject: [PATCH 080/254] test --- src/komodo_gateway.h | 6 +++--- src/komodo_pax.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 338c4073b..73a9a8341 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -34,18 +34,18 @@ int32_t komodo_issued_opreturn(uint8_t *shortflagp,char *base,uint256 *txids,uin base[i] = opretbuf[opretlen-4+i]; if ( strncmp(ASSETCHAINS_SYMBOL,base,strlen(base)) == 0 ) // shortflag { - printf("BASE.(%s) vs (%s)\n",base,ASSETCHAINS_SYMBOL); + //printf("BASE.(%s) vs (%s)\n",base,ASSETCHAINS_SYMBOL); opretbuf++, opretlen--; for (n=len=0; n USD %llu, BTC %llu KMDUSD %llu\n",(long long)baseusd,(long long)btcusd,(long long)kmdusd); - printf("usdkmd.%llu basevolume.%llu baseusd.%llu paxvol.%llu usdvol.%llu -> %.8f\n",(long long)usdkmd,(long long)basevolume,(long long)baseusd,(long long)komodo_paxvol(basevolume,baseusd),(long long)usdvol,dstr(MINDENOMS[USD] * komodo_paxvol(usdvol,usdkmd))); + //printf("usdkmd.%llu basevolume.%llu baseusd.%llu paxvol.%llu usdvol.%llu -> %.8f\n",(long long)usdkmd,(long long)basevolume,(long long)baseusd,(long long)komodo_paxvol(basevolume,baseusd),(long long)usdvol,dstr(MINDENOMS[USD] * komodo_paxvol(usdvol,usdkmd))); return(MINDENOMS[USD] * komodo_paxvol(usdvol,usdkmd)); } } From 0ae2af2b59d06204c42e68f427332285f4dbcad7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 31 Oct 2016 07:47:53 -0300 Subject: [PATCH 081/254] test --- src/miner.cpp | 7 ++++--- src/wallet/wallet.h | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index f08635047..e3e32a4a2 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -98,6 +98,7 @@ void UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams, pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, consensusParams); } +#define ASSETCHAINS_MINHEIGHT 100 int32_t komodo_pax_opreturn(uint8_t *opret,int32_t maxsize); void komodo_gateway_deposits(CMutableTransaction *txNew); extern int32_t KOMODO_INITDONE,ASSETCHAINS_SHORTFLAG; @@ -112,7 +113,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) if(!pblocktemplate.get()) return NULL; CBlock *pblock = &pblocktemplate->block; // pointer for convenience - while ( ASSETCHAINS_SYMBOL[0] != 0 && chainActive.Tip()->nHeight > 10 && mempool.GetTotalTxSize() <= 0 ) + while ( ASSETCHAINS_SYMBOL[0] != 0 && chainActive.Tip()->nHeight > ASSETCHAINS_MINHEIGHT && mempool.GetTotalTxSize() <= 0 ) { sleep(10); if ( KOMODO_INITDONE == 0 || time(NULL) < KOMODO_INITDONE+60 ) @@ -569,7 +570,7 @@ void static BitcoinMiner(CWallet *pwallet) int32_t notaryid; uint32_t savebits; int64_t nStart = GetTime(); savebits = pblock->nBits; arith_uint256 hashTarget = arith_uint256().SetCompact(pblock->nBits); - if ( komodo_chosennotary(¬aryid,pindexPrev->nHeight+1,NOTARY_PUBKEY33) > 0 ) + if ( ASSETCHAINS_SYMBOL[0] == 0 && komodo_chosennotary(¬aryid,pindexPrev->nHeight+1,NOTARY_PUBKEY33) > 0 ) { hashTarget = arith_uint256().SetCompact(KOMODO_MINDIFF_NBITS); Mining_start = (uint32_t)time(NULL); @@ -621,7 +622,7 @@ void static BitcoinMiner(CWallet *pwallet) } int32_t i; uint256 hash = pblock->GetHash(); for (i=0; i<32; i++) - printf("%02x",((uint8_t *)&hash)[i]); + fprintf(stderr,"%02x",((uint8_t *)&hash)[i]); fprintf(stderr," <- %s Block found %d\n",ASSETCHAINS_SYMBOL,Mining_height); SetThreadPriority(THREAD_PRIORITY_LOWEST); // In regression test mode, stop mining after a block is found. diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index dfcbc1af8..c75f1f54d 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -58,7 +58,7 @@ static const unsigned int MAX_FREE_TRANSACTION_CREATE_SIZE = 1000; //! Size of witness cache // Should be large enough that we can expect not to reorg beyond our cache // unless there is some exceptional network disruption. -static const unsigned int WITNESS_CACHE_SIZE = COINBASE_MATURITY; +static const unsigned int WITNESS_CACHE_SIZE = COINBASE_MATURITY+1; class CAccountingEntry; class CBlockIndex; From 1e9d15c61c960f18b6ae9705c563c8e31e2ad128 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 31 Oct 2016 09:59:17 -0300 Subject: [PATCH 082/254] test --- src/komodo_notary.h | 63 ++++++++++++++++++++++++++++++------------- src/rpcblockchain.cpp | 44 ++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+), 19 deletions(-) diff --git a/src/komodo_notary.h b/src/komodo_notary.h index 0e5447087..d30942f0b 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -13,7 +13,7 @@ * * ******************************************************************************/ -const char *Notaries[][2] = +const char *Notaries_genesis[][2] = { { "jl777_testA", "03b7621b44118017a16043f19b30cc8a4cfe068ac4e42417bae16ba460c80f3828" }, { "jl777_testB", "02ebfc784a4ba768aad88d44d1045d240d47b26e248cafaf1c5169a42d7a61d344" }, @@ -60,18 +60,6 @@ struct knotary_entry { UT_hash_handle hh; uint8_t pubkey[33],notaryid; }; struct knotaries_entry { int32_t height,numnotaries; struct knotary_entry *Notaries; } Pubkeys[10000]; struct notarized_checkpoint { uint256 notarized_hash,notarized_desttxid; int32_t nHeight,notarized_height; } *NPOINTS; int32_t NUM_NPOINTS; -int32_t komodo_ratify_threshold(int32_t height,uint64_t signedmask) -{ - int32_t numnotaries,i,wt = 0; - numnotaries = Pubkeys[height / KOMODO_ELECTION_GAP].numnotaries; - for (i=0; i (numnotaries >> 1) || (wt > 7 && (signedmask & 3) != 0) ) - return(1); // N/2+1 || N/3 + devsig - else return(0); -} - void komodo_nutxoadd(int32_t height,int32_t notaryid,uint256 txhash,uint64_t voutmask,int32_t numvouts) { struct nutxo_entry *np; @@ -84,7 +72,7 @@ void komodo_nutxoadd(int32_t height,int32_t notaryid,uint256 txhash,uint64_t vou np->voutmask = voutmask; np->notaryid = notaryid; HASH_ADD_KEYPTR(hh,NUTXOS,&np->txhash,sizeof(np->txhash),np); - printf("Add NUTXO[%d] <- %s notaryid.%d t%u %s %llx\n",Num_nutxos,Notaries[notaryid][0],notaryid,komodo_txtime(txhash),txhash.ToString().c_str(),(long long)voutmask); + //printf("Add NUTXO[%d] <- %s notaryid.%d t%u %s %llx\n",Num_nutxos,Notaries[notaryid][0],notaryid,komodo_txtime(txhash),txhash.ToString().c_str(),(long long)voutmask); Num_nutxos++; pthread_mutex_unlock(&komodo_mutex); } @@ -101,6 +89,42 @@ int32_t komodo_nutxofind(int32_t height,uint256 txhash,int32_t vout) return(-1); } +int32_t komodo_ratify_threshold(int32_t height,uint64_t signedmask) +{ + int32_t htind,numnotaries,i,wt = 0; + if ( (htind= KOMODO_PUBKEYS_HEIGHT(height) / KOMODO_ELECTION_GAP) == 1 ) + htind = 0; + numnotaries = Pubkeys[htind].numnotaries; + for (i=0; i (numnotaries >> 1) || (wt > 7 && (signedmask & 3) != 0) ) + return(1); + else return(0); +} + +int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height) +{ + int32_t i,htind,n; uint64_t mask = 0; struct knotary_entry *kp,*tmp; + if ( (htind= KOMODO_PUBKEYS_HEIGHT(height) / KOMODO_ELECTION_GAP) == 1 ) + htind = 0; + pthread_mutex_lock(&komodo_mutex); + n = Pubkeys[htind].num; + HASH_ITER(hh,Pubkeys[htind].Notaries,kp,tmp) + { + if ( kp->notaryid < n ) + { + mask |= (1LL << kp->notaryid); + memcpy(pubkeys[kp->notaryid],kp->pubkey,33); + } + } + pthread_mutex_unlock(&komodo_mutex); + if ( mask == ((1LL << n)-1) ) + return(n); + printf("error retrieving notaries ht.%d got mask.%llx for n.%d\n",height,(long long)mask,n); + return(-1); +} + void komodo_notarysinit(int32_t height,uint8_t pubkeys[64][33],int32_t num) { int32_t k,i,htind; struct knotary_entry *kp; struct knotaries_entry N; @@ -120,8 +144,7 @@ void komodo_notarysinit(int32_t height,uint8_t pubkeys[64][33],int32_t num) } } N.numnotaries = num; - htind = KOMODO_PUBKEYS_HEIGHT(height) / KOMODO_ELECTION_GAP; - if ( htind == 1 ) + if ( (htind= KOMODO_PUBKEYS_HEIGHT(height) / KOMODO_ELECTION_GAP) == 1 ) htind = 0; for (i=htind; i= sizeof(Pubkeys)/sizeof(*Pubkeys) ) return(-1); + if ( (htind= KOMODO_PUBKEYS_HEIGHT(height) / KOMODO_ELECTION_GAP) == 1 ) + htind = 0; pthread_mutex_lock(&komodo_mutex); - HASH_FIND(hh,Pubkeys[height/KOMODO_ELECTION_GAP].Notaries,pubkey33,33,kp); + HASH_FIND(hh,Pubkeys[htind].Notaries,pubkey33,33,kp); pthread_mutex_unlock(&komodo_mutex); if ( kp != 0 ) { - if ( (numnotaries= Pubkeys[height/KOMODO_ELECTION_GAP].numnotaries) > 0 ) + if ( (numnotaries= Pubkeys[htind].numnotaries) > 0 ) { *notaryidp = kp->notaryid; modval = ((height % numnotaries) == kp->notaryid); diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 607500c70..48a175401 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -384,6 +384,50 @@ uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uin uint32_t komodo_txtime(uint256 hash); uint64_t komodo_paxprice(int32_t height,char *base,char *rel,uint64_t basevolume); int32_t komodo_paxprices(int32_t *heights,uint64_t *prices,int32_t max,char *base,char *rel); +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); + +Value notaries(const Array& params, bool fHelp) +{ + if ( fHelp || params.size() != 1 ) + throw runtime_error("notaries height\n"); + LOCK(cs_main); + int32_t n,height = atoi(params[0].get_str().c_str()); + if ( height < 0 || height > chainActive.Height() ) + throw JSONRPCError(RPC_INVALID_PARAMETER, "Block height out of range"); + else + { + Array a; Object item; int32_t i,j,n,m; char *hexstr; std::string hex,addr; uint8_t pubkeys[64][33]; char btcaddr[64],kmdaddr[64],*ptr; + hex.resize(67); + if ( (n= komodo_notaries(pubkeys,height)) > 0 ) + { + for (i=0; i Date: Mon, 31 Oct 2016 10:24:43 -0300 Subject: [PATCH 083/254] test --- src/rpcclient.cpp | 3 ++- src/rpcserver.cpp | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/rpcclient.cpp b/src/rpcclient.cpp index 81df5927a..30142ee82 100644 --- a/src/rpcclient.cpp +++ b/src/rpcclient.cpp @@ -107,7 +107,8 @@ static const CRPCConvertParam vRPCConvertParams[] = { "z_getoperationresult", 0}, { "z_importkey", 1 }, { "paxprice", 4 }, - { "paxprice2", 3 }, + { "paxprices", 3 }, + { "notaries", 1 }, }; class CRPCConvertTable diff --git a/src/rpcserver.cpp b/src/rpcserver.cpp index 801a4ff95..41725499c 100644 --- a/src/rpcserver.cpp +++ b/src/rpcserver.cpp @@ -302,6 +302,7 @@ static const CRPCCommand vRPCCommands[] = { "blockchain", "verifychain", &verifychain, true }, { "blockchain", "paxprice", &paxprice, true }, { "blockchain", "paxprices", &paxprices, true }, + { "blockchain", "notaries", ¬aries, true }, /* Mining */ { "mining", "getblocktemplate", &getblocktemplate, true }, From ef5b15b0de3c7e556afa8e9aec791536d3a51f00 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 31 Oct 2016 10:26:44 -0300 Subject: [PATCH 084/254] test --- src/komodo_notary.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/komodo_notary.h b/src/komodo_notary.h index d30942f0b..bd7b4ce47 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -109,7 +109,7 @@ int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height) if ( (htind= KOMODO_PUBKEYS_HEIGHT(height) / KOMODO_ELECTION_GAP) == 1 ) htind = 0; pthread_mutex_lock(&komodo_mutex); - n = Pubkeys[htind].num; + n = Pubkeys[htind].numnotaries; HASH_ITER(hh,Pubkeys[htind].Notaries,kp,tmp) { if ( kp->notaryid < n ) @@ -230,12 +230,12 @@ void komodo_init() iguana_initQ(&PendingsQ,(char *)"Pendings"); pthread_mutex_init(&komodo_mutex,NULL); decode_hex(NOTARY_PUBKEY33,33,(char *)NOTARY_PUBKEY.c_str()); - n = (int32_t)(sizeof(Notaries)/sizeof(*Notaries)); + n = (int32_t)(sizeof(Notaries_genesis)/sizeof(*Notaries_genesis)); for (k=0; k Date: Mon, 31 Oct 2016 10:28:33 -0300 Subject: [PATCH 085/254] test --- src/rpcblockchain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 48a175401..48b16131f 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -389,6 +389,7 @@ char *bitcoin_address(char *coinaddr,uint8_t addrtype,uint8_t *pubkey_or_rmd160, Value notaries(const Array& params, bool fHelp) { + Array a; Object ret,item; int32_t i,j,n,m; char *hexstr; std::string hex,addr; uint8_t pubkeys[64][33]; char btcaddr[64],kmdaddr[64],*ptr; if ( fHelp || params.size() != 1 ) throw runtime_error("notaries height\n"); LOCK(cs_main); @@ -397,7 +398,6 @@ Value notaries(const Array& params, bool fHelp) throw JSONRPCError(RPC_INVALID_PARAMETER, "Block height out of range"); else { - Array a; Object item; int32_t i,j,n,m; char *hexstr; std::string hex,addr; uint8_t pubkeys[64][33]; char btcaddr[64],kmdaddr[64],*ptr; hex.resize(67); if ( (n= komodo_notaries(pubkeys,height)) > 0 ) { From a8af456e27cbb7e35585c19b9147d4e9648eb7c4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 31 Oct 2016 10:29:15 -0300 Subject: [PATCH 086/254] test --- src/rpcblockchain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 48b16131f..9663cac9b 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -393,7 +393,7 @@ Value notaries(const Array& params, bool fHelp) if ( fHelp || params.size() != 1 ) throw runtime_error("notaries height\n"); LOCK(cs_main); - int32_t n,height = atoi(params[0].get_str().c_str()); + int32_t height = atoi(params[0].get_str().c_str()); if ( height < 0 || height > chainActive.Height() ) throw JSONRPCError(RPC_INVALID_PARAMETER, "Block height out of range"); else From 2c938114fd98fecb5c3012930eb8c7d187339636 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 31 Oct 2016 10:31:15 -0300 Subject: [PATCH 087/254] test --- src/rpcserver.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/rpcserver.h b/src/rpcserver.h index 135139ef9..a7b166176 100644 --- a/src/rpcserver.h +++ b/src/rpcserver.h @@ -243,6 +243,7 @@ extern json_spirit::Value getblockhash(const json_spirit::Array& params, bool fH 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 paxprice(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value paxprices(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value paxdeposit(const json_spirit::Array& params, bool fHelp); From 98622aa76cd6eb20cb7f0690a361ac5e206a5a77 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 31 Oct 2016 10:42:39 -0300 Subject: [PATCH 088/254] test --- src/komodo_notary.h | 3 ++- src/rpcblockchain.cpp | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/komodo_notary.h b/src/komodo_notary.h index bd7b4ce47..865e5d6cb 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -116,9 +116,10 @@ int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height) { mask |= (1LL << kp->notaryid); memcpy(pubkeys[kp->notaryid],kp->pubkey,33); - } + } else printf("illegal notaryid.%d vs n.%d\n",kp->notaryid,n); } pthread_mutex_unlock(&komodo_mutex); + printf("notaries ht.%d got mask.%llx for n.%d\n",height,(long long)mask,n); if ( mask == ((1LL << n)-1) ) return(n); printf("error retrieving notaries ht.%d got mask.%llx for n.%d\n",height,(long long)mask,n); diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 9663cac9b..33bc9dd82 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -389,7 +389,7 @@ char *bitcoin_address(char *coinaddr,uint8_t addrtype,uint8_t *pubkey_or_rmd160, Value notaries(const Array& params, bool fHelp) { - Array a; Object ret,item; int32_t i,j,n,m; char *hexstr; std::string hex,addr; uint8_t pubkeys[64][33]; char btcaddr[64],kmdaddr[64],*ptr; + Array a; Object ret; int32_t i,j,n,m; char *hexstr; std::string hex,addr; uint8_t pubkeys[64][33]; char btcaddr[64],kmdaddr[64],*ptr; if ( fHelp || params.size() != 1 ) throw runtime_error("notaries height\n"); LOCK(cs_main); @@ -403,6 +403,7 @@ Value notaries(const Array& params, bool fHelp) { for (i=0; i Date: Mon, 31 Oct 2016 10:46:34 -0300 Subject: [PATCH 089/254] test --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index bd82624af..047752d91 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1488,7 +1488,7 @@ bool IsInitialBlockDownload() if ( ASSETCHAINS_SYMBOL[0] == 0 ) state = (chainActive.Height() < pindexBestHeader->nHeight - 24*6) || pindexBestHeader->GetBlockTime() < (GetTime() - chainParams.MaxTipAge()); - else state = (chainActive.Height() < pindexBestHeader->nHeight - 10); + else state = (chainActive.Height() < pindexBestHeader->nHeight - 1); if (!state) { //fprintf(stderr,"lockIBDState tru\n"); From 6f3d11ee0c880d5f8f36855b3e441b0d12dbf96d Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 31 Oct 2016 10:47:14 -0300 Subject: [PATCH 090/254] test --- src/assetchains | 1 + 1 file changed, 1 insertion(+) diff --git a/src/assetchains b/src/assetchains index b93265332..f030f43d4 100755 --- a/src/assetchains +++ b/src/assetchains @@ -1,5 +1,6 @@ source pubkey.txt echo $pubkey + ./komodod -pubkey=$pubkey -ac_name=USD -addnode=78.47.196.146 & ./komodod -pubkey=$pubkey -ac_name=EUR -addnode=78.47.196.146 & ./komodod -pubkey=$pubkey -ac_name=JPY -addnode=78.47.196.146 & From ff4657a716e497c1fdeecc9fe916d98d2317bebe Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 31 Oct 2016 11:00:19 -0300 Subject: [PATCH 091/254] test --- src/rpcblockchain.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 33bc9dd82..660d23068 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -389,7 +389,7 @@ char *bitcoin_address(char *coinaddr,uint8_t addrtype,uint8_t *pubkey_or_rmd160, Value notaries(const Array& params, bool fHelp) { - Array a; Object ret; int32_t i,j,n,m; char *hexstr; std::string hex,addr; uint8_t pubkeys[64][33]; char btcaddr[64],kmdaddr[64],*ptr; + Array a; Object ret; int32_t i,j,n,m; char *hexstr; uint8_t pubkeys[64][33]; char btcaddr[64],kmdaddr[64],*ptr; if ( fHelp || params.size() != 1 ) throw runtime_error("notaries height\n"); LOCK(cs_main); @@ -398,23 +398,25 @@ Value notaries(const Array& params, bool fHelp) throw JSONRPCError(RPC_INVALID_PARAMETER, "Block height out of range"); else { - hex.resize(67); if ( (n= komodo_notaries(pubkeys,height)) > 0 ) { for (i=0; i Date: Mon, 31 Oct 2016 11:07:34 -0300 Subject: [PATCH 092/254] test --- src/assetchains | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/assetchains b/src/assetchains index f030f43d4..81e8b603e 100755 --- a/src/assetchains +++ b/src/assetchains @@ -2,34 +2,66 @@ source pubkey.txt echo $pubkey ./komodod -pubkey=$pubkey -ac_name=USD -addnode=78.47.196.146 & +sleep 10 ./komodod -pubkey=$pubkey -ac_name=EUR -addnode=78.47.196.146 & +sleep 10 ./komodod -pubkey=$pubkey -ac_name=JPY -addnode=78.47.196.146 & +sleep 10 ./komodod -pubkey=$pubkey -ac_name=GBP -addnode=78.47.196.146 & +sleep 10 ./komodod -pubkey=$pubkey -ac_name=AUD -addnode=78.47.196.146 & +sleep 10 ./komodod -pubkey=$pubkey -ac_name=CAD -addnode=78.47.196.146 & +sleep 10 ./komodod -pubkey=$pubkey -ac_name=CHF -addnode=78.47.196.146 & +sleep 10 ./komodod -pubkey=$pubkey -ac_name=NZD -addnode=78.47.196.146 & +sleep 10 ./komodod -pubkey=$pubkey -ac_name=CNY -addnode=78.47.196.146 & +sleep 10 ./komodod -pubkey=$pubkey -ac_name=RUB -addnode=78.47.196.146 & +sleep 10 ./komodod -pubkey=$pubkey -ac_name=MXN -addnode=78.47.196.146 & +sleep 10 ./komodod -pubkey=$pubkey -ac_name=BRL -addnode=78.47.196.146 & +sleep 10 ./komodod -pubkey=$pubkey -ac_name=INR -addnode=78.47.196.146 & +sleep 10 ./komodod -pubkey=$pubkey -ac_name=HKD -addnode=78.47.196.146 & +sleep 10 ./komodod -pubkey=$pubkey -ac_name=TRY -addnode=78.47.196.146 & +sleep 10 ./komodod -pubkey=$pubkey -ac_name=ZAR -addnode=78.47.196.146 & +sleep 10 ./komodod -pubkey=$pubkey -ac_name=PLN -addnode=78.47.196.146 & +sleep 10 ./komodod -pubkey=$pubkey -ac_name=NOK -addnode=78.47.196.146 & +sleep 10 ./komodod -pubkey=$pubkey -ac_name=SEK -addnode=78.47.196.146 & +sleep 10 ./komodod -pubkey=$pubkey -ac_name=DKK -addnode=78.47.196.146 & +sleep 10 ./komodod -pubkey=$pubkey -ac_name=CZK -addnode=78.47.196.146 & +sleep 10 ./komodod -pubkey=$pubkey -ac_name=HUF -addnode=78.47.196.146 & +sleep 10 ./komodod -pubkey=$pubkey -ac_name=ILS -addnode=78.47.196.146 & +sleep 10 ./komodod -pubkey=$pubkey -ac_name=KRW -addnode=78.47.196.146 & +sleep 10 ./komodod -pubkey=$pubkey -ac_name=MYR -addnode=78.47.196.146 & +sleep 10 ./komodod -pubkey=$pubkey -ac_name=PHP -addnode=78.47.196.146 & +sleep 10 ./komodod -pubkey=$pubkey -ac_name=RON -addnode=78.47.196.146 & +sleep 10 ./komodod -pubkey=$pubkey -ac_name=SGD -addnode=78.47.196.146 & +sleep 10 ./komodod -pubkey=$pubkey -ac_name=THB -addnode=78.47.196.146 & +sleep 10 ./komodod -pubkey=$pubkey -ac_name=BGN -addnode=78.47.196.146 & +sleep 10 ./komodod -pubkey=$pubkey -ac_name=IDR -addnode=78.47.196.146 & +sleep 10 ./komodod -pubkey=$pubkey -ac_name=HRK -addnode=78.47.196.146 & +sleep 10 From 69900ca444d23ada7491e58ab0936e83de557467 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 31 Oct 2016 11:09:04 -0300 Subject: [PATCH 093/254] test --- src/rpcblockchain.cpp | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 660d23068..0f811ebac 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -406,21 +406,18 @@ Value notaries(const Array& params, bool fHelp) std::string btcaddress,kmdaddress,hex; bitcoin_address(btcaddr,0,pubkeys[i],33); m = (int32_t)strlen(btcaddr); - btcaddress.resize(m+1); + btcaddress.resize(m); ptr = (char *)btcaddress.data(); - strcpy(ptr,btcaddr); - ptr[m] = 0; + memcpy(ptr,btcaddr,n); bitcoin_address(kmdaddr,60,pubkeys[i],33); m = (int32_t)strlen(kmdaddr); - kmdaddress.resize(m+1); + kmdaddress.resize(m); ptr = (char *)kmdaddress.data(); - strcpy(ptr,kmdaddr); - ptr[m] = 0; - hex.resize(67); + memcpy(ptr,kmdaddr,m); + hex.resize(66); hexstr = (char *)hex.data(); for (j=0; j<33; j++) sprintf(&hexstr[j*2],"%02x",pubkeys[i][j]); - hexstr[j*2] = 0; item.push_back(Pair("pubkey", hex)); item.push_back(Pair("BTCaddress", btcaddress)); item.push_back(Pair("KMDaddress", kmdaddress)); From 4961429861f9fb5acf32e07db104cb31dd9a79fa Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 31 Oct 2016 11:47:08 -0300 Subject: [PATCH 094/254] test --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 047752d91..7c352da7b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1488,7 +1488,7 @@ bool IsInitialBlockDownload() if ( ASSETCHAINS_SYMBOL[0] == 0 ) state = (chainActive.Height() < pindexBestHeader->nHeight - 24*6) || pindexBestHeader->GetBlockTime() < (GetTime() - chainParams.MaxTipAge()); - else state = (chainActive.Height() < pindexBestHeader->nHeight - 1); + else state = (chainActive.Height() < pindexBestHeader->nHeight - 100); if (!state) { //fprintf(stderr,"lockIBDState tru\n"); From 91bf7621900f4406cea7ecaed1085b75d26ff7a9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 31 Oct 2016 11:58:48 -0300 Subject: [PATCH 095/254] test --- src/init.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/init.cpp b/src/init.cpp index 91412bbc3..1d0ffdb0b 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1493,7 +1493,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) #ifdef ENABLE_WALLET // Generate coins in the background if (pwalletMain) - GenerateBitcoins(GetBoolArg("-gen", true), pwalletMain, GetArg("-genproclimit", 1)); + GenerateBitcoins(GetBoolArg("-gen", false), pwalletMain, GetArg("-genproclimit", 1)); #endif // ********************************************************* Step 11: finished From 20149fe9e0b097afcea422aa84bb88c0e2fc231e Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 31 Oct 2016 12:35:38 -0300 Subject: [PATCH 096/254] test --- src/assetchains | 32 -------------------------------- 1 file changed, 32 deletions(-) diff --git a/src/assetchains b/src/assetchains index 81e8b603e..f030f43d4 100755 --- a/src/assetchains +++ b/src/assetchains @@ -2,66 +2,34 @@ source pubkey.txt echo $pubkey ./komodod -pubkey=$pubkey -ac_name=USD -addnode=78.47.196.146 & -sleep 10 ./komodod -pubkey=$pubkey -ac_name=EUR -addnode=78.47.196.146 & -sleep 10 ./komodod -pubkey=$pubkey -ac_name=JPY -addnode=78.47.196.146 & -sleep 10 ./komodod -pubkey=$pubkey -ac_name=GBP -addnode=78.47.196.146 & -sleep 10 ./komodod -pubkey=$pubkey -ac_name=AUD -addnode=78.47.196.146 & -sleep 10 ./komodod -pubkey=$pubkey -ac_name=CAD -addnode=78.47.196.146 & -sleep 10 ./komodod -pubkey=$pubkey -ac_name=CHF -addnode=78.47.196.146 & -sleep 10 ./komodod -pubkey=$pubkey -ac_name=NZD -addnode=78.47.196.146 & -sleep 10 ./komodod -pubkey=$pubkey -ac_name=CNY -addnode=78.47.196.146 & -sleep 10 ./komodod -pubkey=$pubkey -ac_name=RUB -addnode=78.47.196.146 & -sleep 10 ./komodod -pubkey=$pubkey -ac_name=MXN -addnode=78.47.196.146 & -sleep 10 ./komodod -pubkey=$pubkey -ac_name=BRL -addnode=78.47.196.146 & -sleep 10 ./komodod -pubkey=$pubkey -ac_name=INR -addnode=78.47.196.146 & -sleep 10 ./komodod -pubkey=$pubkey -ac_name=HKD -addnode=78.47.196.146 & -sleep 10 ./komodod -pubkey=$pubkey -ac_name=TRY -addnode=78.47.196.146 & -sleep 10 ./komodod -pubkey=$pubkey -ac_name=ZAR -addnode=78.47.196.146 & -sleep 10 ./komodod -pubkey=$pubkey -ac_name=PLN -addnode=78.47.196.146 & -sleep 10 ./komodod -pubkey=$pubkey -ac_name=NOK -addnode=78.47.196.146 & -sleep 10 ./komodod -pubkey=$pubkey -ac_name=SEK -addnode=78.47.196.146 & -sleep 10 ./komodod -pubkey=$pubkey -ac_name=DKK -addnode=78.47.196.146 & -sleep 10 ./komodod -pubkey=$pubkey -ac_name=CZK -addnode=78.47.196.146 & -sleep 10 ./komodod -pubkey=$pubkey -ac_name=HUF -addnode=78.47.196.146 & -sleep 10 ./komodod -pubkey=$pubkey -ac_name=ILS -addnode=78.47.196.146 & -sleep 10 ./komodod -pubkey=$pubkey -ac_name=KRW -addnode=78.47.196.146 & -sleep 10 ./komodod -pubkey=$pubkey -ac_name=MYR -addnode=78.47.196.146 & -sleep 10 ./komodod -pubkey=$pubkey -ac_name=PHP -addnode=78.47.196.146 & -sleep 10 ./komodod -pubkey=$pubkey -ac_name=RON -addnode=78.47.196.146 & -sleep 10 ./komodod -pubkey=$pubkey -ac_name=SGD -addnode=78.47.196.146 & -sleep 10 ./komodod -pubkey=$pubkey -ac_name=THB -addnode=78.47.196.146 & -sleep 10 ./komodod -pubkey=$pubkey -ac_name=BGN -addnode=78.47.196.146 & -sleep 10 ./komodod -pubkey=$pubkey -ac_name=IDR -addnode=78.47.196.146 & -sleep 10 ./komodod -pubkey=$pubkey -ac_name=HRK -addnode=78.47.196.146 & -sleep 10 From e2c35fcd479e22c0c5980e0d2fff4e924d812c1d Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 31 Oct 2016 14:32:48 -0300 Subject: [PATCH 097/254] test --- src/komodo_gateway.h | 4 ++-- src/komodo_notary.h | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 73a9a8341..92ef5aee6 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -26,7 +26,7 @@ struct pax_transaction int32_t komodo_issued_opreturn(uint8_t *shortflagp,char *base,uint256 *txids,uint16_t *vouts,uint8_t *opretbuf,int32_t opretlen) { - int32_t i,n,j,len; + int32_t i,n=0,j,len; if ( opretbuf[opretlen-5] == '-' ) *shortflagp = 1; else *shortflagp = 0; @@ -257,7 +257,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(" issuedtxid v%d i.%d opretlen.%d\n",vouts[i],i,opretlen); + printf(" issuedtxid v%d i.%d of n.%d opretlen.%d\n",vouts[i],i,n,opretlen); if ( komodo_gateway_depositremove(txids[i],vouts[i]) == 0 ) printf("error removing deposit\n"); } diff --git a/src/komodo_notary.h b/src/komodo_notary.h index 865e5d6cb..35d92e289 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -119,7 +119,6 @@ int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height) } else printf("illegal notaryid.%d vs n.%d\n",kp->notaryid,n); } pthread_mutex_unlock(&komodo_mutex); - printf("notaries ht.%d got mask.%llx for n.%d\n",height,(long long)mask,n); if ( mask == ((1LL << n)-1) ) return(n); printf("error retrieving notaries ht.%d got mask.%llx for n.%d\n",height,(long long)mask,n); From a55c8425079d3f9c7a9177e7261093969d108a18 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 31 Oct 2016 14:42:25 -0300 Subject: [PATCH 098/254] test --- src/komodo_gateway.h | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 92ef5aee6..ab0f62dfe 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -251,7 +251,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 { if ( tokomodo == 0 && opretbuf[0] == 'I' ) { - if ( (n= komodo_issued_opreturn(&shortflag,base,txids,vouts,opretbuf,opretlen)) > 0 )//&& shortflag == ASSETCHAINS_SHORTFLAG ) + if ( (n= komodo_issued_opreturn(&shortflag,base,txids,vouts,opretbuf,opretlen)) > 0 && shortflag == ASSETCHAINS_SHORTFLAG ) { for (i=0; i Date: Mon, 31 Oct 2016 14:46:29 -0300 Subject: [PATCH 099/254] test --- src/komodo_gateway.h | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index ab0f62dfe..f288c6877 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -337,7 +337,7 @@ int32_t komodo_gateway_tx(char *symbol,int32_t height,int32_t txi,char *txidstr, int32_t komodo_gateway_block(char *symbol,int32_t height,uint16_t port) { - char *retstr,*retstr2,params[128],*txidstr; int32_t i,n,retval = -1; cJSON *json,*tx,*result,*result2; + char *retstr,*retstr2,params[128],*txidstr; int32_t i,n,retval = -1; cJSON *json,*tx=0,*result=0,*result2; sprintf(params,"[%d]",height); if ( (retstr= komodo_issuemethod((char *)"getblockhash",params,port)) != 0 ) { @@ -359,16 +359,16 @@ int32_t komodo_gateway_block(char *symbol,int32_t height,uint16_t port) if ( i == n ) retval = 0; //else printf("error i.%d vs n.%d\n",i,n); - } + } else printf("cant get result.%p or tx.%p\n",result,tx); free_json(json); - } + } else printf("cant parse2.(%s)\n",retstr2); free(retstr2); - } + } else printf("error getblock %s\n",params); } else printf("strlen.%ld (%s)\n",strlen(txidstr),txidstr); free_json(result); - } + } else printf("couldnt parse.(%s)\n",retstr); free(retstr); - } + } else printf("error from getblockhash %d\n",height); return(retval); } @@ -385,7 +385,6 @@ void komodo_gateway_iteration(char *symbol) { for (i=0; i<1000 && KMDHEIGHT Date: Mon, 31 Oct 2016 14:53:02 -0300 Subject: [PATCH 100/254] 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 f288c6877..7a42be6e8 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -327,7 +327,7 @@ int32_t komodo_gateway_tx(char *symbol,int32_t height,int32_t txi,char *txidstr, } } } - } + } else printf("error getting txids.(%s)\n",retstr); free_json(json); } free(retstr); @@ -358,7 +358,7 @@ int32_t komodo_gateway_block(char *symbol,int32_t height,uint16_t port) break; if ( i == n ) retval = 0; - //else printf("error i.%d vs n.%d\n",i,n); + else printf("komodo_gateway_block ht.%d error i.%d vs n.%d\n",height,i,n); } else printf("cant get result.%p or tx.%p\n",result,tx); free_json(json); } else printf("cant parse2.(%s)\n",retstr2); From 408a4d913699cf1158c99e7293d0f8625b47f447 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 31 Oct 2016 15:24:38 -0300 Subject: [PATCH 101/254] test --- src/rpcmining.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/rpcmining.cpp b/src/rpcmining.cpp index 8900ad43a..3a11eaf0c 100644 --- a/src/rpcmining.cpp +++ b/src/rpcmining.cpp @@ -603,15 +603,15 @@ Value getblocktemplate(const Array& params, bool fHelp) entry.push_back(Pair("fee", pblocktemplate->vTxFees[index_in_template])); entry.push_back(Pair("sigops", pblocktemplate->vTxSigOps[index_in_template])); - /* if (tx.IsCoinBase()) { + if (tx.IsCoinBase()) { // Show founders' reward if it is required - if (pblock->vtx[0].vout.size() > 1) { + //if (pblock->vtx[0].vout.size() > 1) { // Correct this if GetBlockTemplate changes the order - entry.push_back(Pair("foundersreward", (int64_t)tx.vout[1].nValue)); - } + // entry.push_back(Pair("foundersreward", (int64_t)tx.vout[1].nValue)); + //} entry.push_back(Pair("required", true)); txCoinbase = entry; - } else*/ + } else transactions.push_back(entry); } From 0dbbf6de072705d7707df9f128c550e717b59a7e Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 31 Oct 2016 15:58:54 -0300 Subject: [PATCH 102/254] test --- src/komodo_gateway.h | 8 ++++---- src/komodo_notary.h | 2 ++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 7a42be6e8..36739723e 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -151,7 +151,7 @@ int32_t komodo_gateway_depositremove(uint256 txid,uint16_t vout) // assetchain c int32_t komodo_check_deposit(const CBlock& block) // verify above block is valid pax pricing { - int32_t i,j,n,opretlen,num,iter,matchflag,offset=1; uint256 hash,txids[64]; uint8_t shortflag; char base[16]; uint16_t vouts[64]; uint8_t *script; queue_t *Q; struct pax_transaction *ptr; struct queueitem *item; + int32_t i,j,n,opretlen,num,iter,matchflag,offset=1; uint256 txids[64]; uint8_t shortflag; char base[16]; uint16_t vouts[64]; uint8_t *script; queue_t *Q; struct pax_transaction *ptr; struct queueitem *item; n = block.vtx[0].vout.size(); script = (uint8_t *)block.vtx[0].vout[n-1].scriptPubKey.data(); if ( n <= 2 || script[0] != 0x6a ) @@ -180,13 +180,13 @@ int32_t komodo_check_deposit(const CBlock& block) // verify above block is valid { if ( ptr->fiatoshis == block.vtx[0].vout[i].nValue ) { - for (j=0; j<32; j++) + /*for (j=0; j<32; j++) printf("%02x",((uint8_t *)&ptr->txid)[j]); printf(" v%d matched %.8f vout.%d ",ptr->vout,dstr(ptr->fiatoshis),i); hash = block.GetHash(); for (j=0; j<32; j++) printf("%02x",((uint8_t *)&hash)[j]); - printf(".blockhash\n"); + printf(".blockhash\n");*/ matchflag = 1; } else printf("error finding %.8f vout.%d\n",dstr(ptr->fiatoshis),i); break; @@ -259,7 +259,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 printf("%02x",((uint8_t *)&txids[i])[j]); printf(" issuedtxid v%d i.%d of n.%d opretlen.%d\n",vouts[i],i,n,opretlen); if ( komodo_gateway_depositremove(txids[i],vouts[i]) == 0 ) - printf("error removing deposit\n"); + printf("%s error removing deposit\n",ASSETCHAINS_SYMBOL); } } } diff --git a/src/komodo_notary.h b/src/komodo_notary.h index 35d92e289..bb897e8bd 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -92,6 +92,8 @@ int32_t komodo_nutxofind(int32_t height,uint256 txhash,int32_t vout) int32_t komodo_ratify_threshold(int32_t height,uint64_t signedmask) { int32_t htind,numnotaries,i,wt = 0; + if ( ASSETCHAINS_SYMBOL[0] != 0 ) + return(2); if ( (htind= KOMODO_PUBKEYS_HEIGHT(height) / KOMODO_ELECTION_GAP) == 1 ) htind = 0; numnotaries = Pubkeys[htind].numnotaries; From 23d34a32c86dcb9e46df2e7c298713820ea06eae Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 31 Oct 2016 16:15:40 -0300 Subject: [PATCH 103/254] 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 36739723e..87a74e5f5 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -210,6 +210,9 @@ int32_t komodo_check_deposit(const CBlock& block) // verify above block is valid const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int32_t opretlen,uint256 txid,uint16_t vout) { uint8_t rmd160[20],addrtype,shortflag,pubkey33[33]; int32_t i,j,n,len,tokomodo=0; char base[4],coinaddr[64],destaddr[64]; uint256 txids[64]; uint16_t vouts[64]; int64_t fiatoshis,checktoshis; const char *typestr = "unknown"; + for (i=0; i %s ",dstr(fiatoshis),shortflag!=0?'-':'+',base,coinaddr); tokomodo = (komodo_is_issuer() == 0); if ( opretbuf[0] == ((tokomodo == 0) ? 'D' : 'W') ) { @@ -224,9 +227,6 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 typestr = "deposit"; if ( tokomodo == 0 && strncmp(ASSETCHAINS_SYMBOL,base,strlen(base)) == 0 ) { - for (i=0; i %s ",dstr(fiatoshis),shortflag!=0?'-':'+',base,coinaddr); for (i=0; i<32; i++) printf("%02x",((uint8_t *)&txid)[i]); printf(" <- txid.v%u ",vout); From 95db8239e9dd410ea283cd3fe1ab13c3ad4c5a7b Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 31 Oct 2016 16:19:34 -0300 Subject: [PATCH 104/254] test --- src/komodo_gateway.h | 4 ++-- src/komodo_utils.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 87a74e5f5..f010c5649 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -210,10 +210,10 @@ int32_t komodo_check_deposit(const CBlock& block) // verify above block is valid const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int32_t opretlen,uint256 txid,uint16_t vout) { uint8_t rmd160[20],addrtype,shortflag,pubkey33[33]; int32_t i,j,n,len,tokomodo=0; char base[4],coinaddr[64],destaddr[64]; uint256 txids[64]; uint16_t vouts[64]; int64_t fiatoshis,checktoshis; const char *typestr = "unknown"; + tokomodo = (komodo_is_issuer() == 0); for (i=0; i %s ",dstr(fiatoshis),shortflag!=0?'-':'+',base,coinaddr); - tokomodo = (komodo_is_issuer() == 0); + printf(" DEPOSIT.[%c] tokomodo.%d %.8f %c%s -> %s ",opretbuf[0],tokomodo,dstr(fiatoshis),shortflag!=0?'-':'+',base,coinaddr); if ( opretbuf[0] == ((tokomodo == 0) ? 'D' : 'W') ) { if ( opretlen == 34 ) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index d6452b93c..420d1c228 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -802,7 +802,7 @@ int32_t komodo_baseid(char *origbase) int32_t komodo_is_issuer() { - if ( ASSETCHAINS_SYMBOL[0] != 0 && COINBASE_MATURITY == 1 ) + if ( ASSETCHAINS_SYMBOL[0] != 0 && COINBASE_MATURITY < 10 ) return(1); else return(0); } From a5355664fbf9f231255a87e487deb5b385a76ccb Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 31 Oct 2016 16:34:52 -0300 Subject: [PATCH 105/254] test --- src/main.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 7c352da7b..b86ecc9b2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3315,8 +3315,10 @@ static bool IsSuperMajority(int minVersion, const CBlockIndex* pstart, unsigned bool ProcessNewBlock(CValidationState &state, CNode* pfrom, CBlock* pblock, bool fForceProcessing, CDiskBlockPos *dbp) { // Preliminary checks - bool checked = CheckBlock(komodo_block2height(pblock),0,*pblock, state); - + bool checked; + if ( ASSETCHAINS_SYMBOL[0] == 0 ) + checked = CheckBlock(komodo_block2height(pblock),0,*pblock, state); + else checked = CheckBlock(0,0,*pblock, state); { LOCK(cs_main); bool fRequested = MarkBlockAsReceived(pblock->GetHash()); From 2d657c5bac193ca7c24d639dd3eb4a72ff2e192f Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 31 Oct 2016 16:51:59 -0300 Subject: [PATCH 106/254] test --- src/komodo.h | 15 +++++++++------ src/komodo_gateway.h | 22 ++++++---------------- src/komodo_globals.h | 2 +- 3 files changed, 16 insertions(+), 23 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 8ccd7c8cf..a338787c2 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -343,12 +343,15 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) uint8_t scriptbuf[4096],pubkeys[64][33]; uint256 kmdtxid,btctxid,txhash; int32_t i,j,k,numvalid,specialtx,notarizedheight,notaryid,len,numvouts,numvins,height,txn_count; komodo_init(); - KOMODO_INITDONE = (uint32_t)time(NULL); -#ifdef KOMODO_ISSUER - komodo_gateway_issuer(); -#else - komodo_gateway_redeemer(); -#endif + if ( ASSETCHAINS_SYMBOL[0] != 0 ) + { + while ( KOMODO_REALTIME == 0 || time(NULL) < KOMODO_REALTIME+10 ) + { + fprintf(stderr,"komodo_connect.(%s) waiting for realtime\n",ASSETCHAINS_SYMBOL); + sleep(3); + } + KOMODO_INITDONE = (uint32_t)time(NULL); + } if ( pindex != 0 ) { height = pindex->nHeight; diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index f010c5649..dc4e98788 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -211,9 +211,9 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 { uint8_t rmd160[20],addrtype,shortflag,pubkey33[33]; int32_t i,j,n,len,tokomodo=0; char base[4],coinaddr[64],destaddr[64]; uint256 txids[64]; uint16_t vouts[64]; int64_t fiatoshis,checktoshis; const char *typestr = "unknown"; tokomodo = (komodo_is_issuer() == 0); - for (i=0; i %s ",opretbuf[0],tokomodo,dstr(fiatoshis),shortflag!=0?'-':'+',base,coinaddr); + //for (i=0; i %s ",opretbuf[0],tokomodo,dstr(fiatoshis),shortflag!=0?'-':'+',base,coinaddr); if ( opretbuf[0] == ((tokomodo == 0) ? 'D' : 'W') ) { if ( opretlen == 34 ) @@ -377,6 +377,7 @@ void komodo_gateway_iteration(char *symbol) char *retstr; int32_t i,kmdheight; cJSON *infoobj,*result; uint256 zero; uint16_t port = 7771; if ( KMDHEIGHT <= 0 ) KMDHEIGHT = 1; + KOMODO_REALTIME = 0; if ( (retstr= komodo_issuemethod((char *)"getinfo",0,port)) != 0 ) { if ( (infoobj= cJSON_Parse(retstr)) != 0 ) @@ -396,6 +397,8 @@ void komodo_gateway_iteration(char *symbol) printf("error KMDHEIGHT %d\n",KMDHEIGHT); break; } + if ( KMDHEIGHT == kmdheight ) + KOMODO_REALTIME = (uint32_t)time(NULL); usleep(10000); } } @@ -409,16 +412,3 @@ void komodo_gateway_iteration(char *symbol) sleep(30); } } - -#ifdef KOMODO_ISSUER -void komodo_gateway_issuer() // from "assetchain" connectblock() -{ - // check for redeems -} -#else - -void komodo_gateway_redeemer() // from "KMD" connectblock() -{ - -} -#endif diff --git a/src/komodo_globals.h b/src/komodo_globals.h index 11062e866..4cd550141 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -29,6 +29,6 @@ uint64_t ASSETCHAINS_SUPPLY = 10; int32_t NOTARIZED_HEIGHT,Num_nutxos,KMDHEIGHT = 43000; uint256 NOTARIZED_HASH,NOTARIZED_DESTTXID; pthread_mutex_t komodo_mutex; -uint32_t KOMODO_INITDONE; +uint32_t KOMODO_INITDONE,KOMODO_REALTIME; char KMDUSERPASS[1024]; uint16_t BITCOIND_PORT = 7771; uint64_t KOMODO_DEPOSIT,PENDING_KOMODO_TX; From 1fdfe03cd7b8836049a1e37725b5ed8a03c05ed6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 31 Oct 2016 17:10:13 -0300 Subject: [PATCH 107/254] test --- src/komodo.h | 2 +- src/komodo_gateway.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index a338787c2..4ceea53e2 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -347,7 +347,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) { while ( KOMODO_REALTIME == 0 || time(NULL) < KOMODO_REALTIME+10 ) { - fprintf(stderr,"komodo_connect.(%s) waiting for realtime\n",ASSETCHAINS_SYMBOL); + fprintf(stderr,"komodo_connect.(%s) waiting for realtime RT.%u now.%u\n",ASSETCHAINS_SYMBOL,KOMODO_REALTIME,(uint32_t)time(NULL)); sleep(3); } KOMODO_INITDONE = (uint32_t)time(NULL); diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index dc4e98788..f27e7652f 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -397,10 +397,10 @@ void komodo_gateway_iteration(char *symbol) printf("error KMDHEIGHT %d\n",KMDHEIGHT); break; } - if ( KMDHEIGHT == kmdheight ) - KOMODO_REALTIME = (uint32_t)time(NULL); usleep(10000); } + if ( KMDHEIGHT >= kmdheight ) + KOMODO_REALTIME = (uint32_t)time(NULL); } free_json(infoobj); } From f67800d0ff896c19c9a1bd5edc1f71d9d3c3f406 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 31 Oct 2016 17:12:53 -0300 Subject: [PATCH 108/254] test --- src/komodo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index 4ceea53e2..8e0d27f71 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -345,7 +345,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) komodo_init(); if ( ASSETCHAINS_SYMBOL[0] != 0 ) { - while ( KOMODO_REALTIME == 0 || time(NULL) < KOMODO_REALTIME+10 ) + while ( KOMODO_REALTIME == 0 || time(NULL) <= KOMODO_REALTIME ) { fprintf(stderr,"komodo_connect.(%s) waiting for realtime RT.%u now.%u\n",ASSETCHAINS_SYMBOL,KOMODO_REALTIME,(uint32_t)time(NULL)); sleep(3); From 509cd0c10a25cb727b0c3c347642bbd13309b419 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 31 Oct 2016 17:21:35 -0300 Subject: [PATCH 109/254] test --- src/komodo_gateway.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index f27e7652f..04dd96840 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -151,7 +151,7 @@ int32_t komodo_gateway_depositremove(uint256 txid,uint16_t vout) // assetchain c int32_t komodo_check_deposit(const CBlock& block) // verify above block is valid pax pricing { - int32_t i,j,n,opretlen,num,iter,matchflag,offset=1; uint256 txids[64]; uint8_t shortflag; char base[16]; uint16_t vouts[64]; uint8_t *script; queue_t *Q; struct pax_transaction *ptr; struct queueitem *item; + int32_t i,j,n,opretlen,num,iter,matchflag,offset=1; uint256 hash,txids[64]; uint8_t shortflag; char base[16]; uint16_t vouts[64]; uint8_t *script; queue_t *Q; struct pax_transaction *ptr; struct queueitem *item; n = block.vtx[0].vout.size(); script = (uint8_t *)block.vtx[0].vout[n-1].scriptPubKey.data(); if ( n <= 2 || script[0] != 0x6a ) @@ -197,7 +197,10 @@ int32_t komodo_check_deposit(const CBlock& block) // verify above block is valid } if ( matchflag == 0 ) { - printf("couldnt find vout.[%d]\n",i); + hash = block.GetHash(); + for (j=0; j<32; j++) + printf("%02x",((uint8_t *)&hash)[j]); + printf(" blockhash couldnt find vout.[%d]\n",i); return(-1); } } From 92bf98e5c7081732ed1bdfcd89801b9b7c52ce08 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 31 Oct 2016 17:32:29 -0300 Subject: [PATCH 110/254] 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 04dd96840..2b4ae3512 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -157,7 +157,7 @@ int32_t komodo_check_deposit(const CBlock& block) // verify above block is valid if ( n <= 2 || script[0] != 0x6a ) return(0); offset += komodo_scriptitemlen(&opretlen,&script[offset]); - //printf("checkdeposit n.%d [%02x] [%c] %d vs %d\n",n,script[0],script[offset],script[offset],'I'); + printf("checkdeposit n.%d [%02x] [%c] %d vs %d\n",n,script[0],script[offset],script[offset],'I'); if ( script[offset] == 'I' && opretlen < block.vtx[0].vout[n-1].scriptPubKey.size() ) { if ( (num= komodo_issued_opreturn(&shortflag,base,txids,vouts,&script[offset],opretlen)) > 0 ) From 8f64a3a95da7e86277c839ebdc6d5e1fdf6aaa2d Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 31 Oct 2016 17:40:17 -0300 Subject: [PATCH 111/254] test --- src/komodo_gateway.h | 8 ++++---- src/main.cpp | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 2b4ae3512..1ce2236ff 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -149,7 +149,7 @@ int32_t komodo_gateway_depositremove(uint256 txid,uint16_t vout) // assetchain c return(n); } -int32_t komodo_check_deposit(const CBlock& block) // verify above block is valid pax pricing +int32_t komodo_check_deposit(int32_t height,const CBlock& block) // verify above block is valid pax pricing { int32_t i,j,n,opretlen,num,iter,matchflag,offset=1; uint256 hash,txids[64]; uint8_t shortflag; char base[16]; uint16_t vouts[64]; uint8_t *script; queue_t *Q; struct pax_transaction *ptr; struct queueitem *item; n = block.vtx[0].vout.size(); @@ -157,7 +157,7 @@ int32_t komodo_check_deposit(const CBlock& block) // verify above block is valid if ( n <= 2 || script[0] != 0x6a ) return(0); offset += komodo_scriptitemlen(&opretlen,&script[offset]); - printf("checkdeposit n.%d [%02x] [%c] %d vs %d\n",n,script[0],script[offset],script[offset],'I'); + //printf("checkdeposit n.%d [%02x] [%c] %d vs %d\n",n,script[0],script[offset],script[offset],'I'); if ( script[offset] == 'I' && opretlen < block.vtx[0].vout[n-1].scriptPubKey.size() ) { if ( (num= komodo_issued_opreturn(&shortflag,base,txids,vouts,&script[offset],opretlen)) > 0 ) @@ -200,8 +200,8 @@ int32_t komodo_check_deposit(const CBlock& block) // verify above block is valid hash = block.GetHash(); for (j=0; j<32; j++) printf("%02x",((uint8_t *)&hash)[j]); - printf(" blockhash couldnt find vout.[%d]\n",i); - return(-1); + printf(" ht.%d blockhash couldnt find vout.[%d]\n",height,i); + //return(-1); } } } diff --git a/src/main.cpp b/src/main.cpp index b86ecc9b2..5d4bf33f0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3050,7 +3050,7 @@ bool CheckBlockHeader(int32_t height,CBlockIndex *pindex, const CBlockHeader& bl return true; } -int32_t komodo_check_deposit(const CBlock& block); +int32_t komodo_check_deposit(int32_t height,const CBlock& block); bool CheckBlock(int32_t height,CBlockIndex *pindex,const CBlock& block, CValidationState& state, bool fCheckPOW, bool fCheckMerkleRoot) { // These are checks that are independent of context. @@ -3107,7 +3107,7 @@ bool CheckBlock(int32_t height,CBlockIndex *pindex,const CBlock& block, CValidat if (nSigOps > MAX_BLOCK_SIGOPS) return state.DoS(100, error("CheckBlock(): out-of-bounds SigOpCount"), REJECT_INVALID, "bad-blk-sigops", true); - if ( komodo_check_deposit(block) < 0 ) + if ( komodo_check_deposit(height,block) < 0 ) return(false); return true; } From 6210f3287153c49b653917661a76d54266b8b12b Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 31 Oct 2016 19:15:39 -0300 Subject: [PATCH 112/254] test --- src/komodo.h | 2 +- src/komodo_gateway.h | 169 +++++++++++++++++-------------------------- src/komodo_notary.h | 4 +- 3 files changed, 70 insertions(+), 105 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 8e0d27f71..46bfd224f 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -31,7 +31,7 @@ char *komodo_issuemethod(char *method,char *params,uint16_t port); #define GENESIS_NBITS 0x1f00ffff #include "komodo_globals.h" #include "komodo_utils.h" -queue_t DepositsQ,PendingsQ; +//queue_t DepositsQ,PendingsQ; #include "cJSON.c" #include "komodo_bitcoind.h" diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 1ce2236ff..d9505d3fe 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -17,12 +17,57 @@ struct pax_transaction { - struct queueitem DL; + UT_hash_handle hh; uint256 txid; uint64_t komodoshis,fiatoshis; + int32_t mark; uint16_t vout; - char symbol[4]; uint8_t rmd160[20],shortflag; -}; + char symbol[16]; uint8_t rmd160[20],shortflag; +} *PAX; + +void komodo_gateway_deposit(char *coinaddr,uint64_t value,int32_t shortflag,char *symbol,uint64_t fiatoshis,uint8_t *rmd160,uint256 txid,uint16_t vout) // assetchain context +{ + struct pax_transaction *pax; + pax = (struct pax_transaction *)calloc(1,sizeof(*pax)); + strcpy(pax->coinaddr,coinaddr); + pax->komodoshis = value; + pax->shortflag = shortflag; + strcpy(pax->symbol,symbol); + pax->fiatoshis = fiatoshis; + memcpy(pax->rmd160,rmd160,20); + pax->txid = txid; + pax->vout = vout; + printf("ADD DEPOSIT %s %.8f -> %s TO PAX\n",symbol,dstr(fiatoshis),coinaddr); + pthread_mutex_lock(&komodo_mutex); + HASH_ADD_KEYPTR(hh,PAX,&pax->txid,sizeof(pax->txid),pax); + pthread_mutex_unlock(&komodo_mutex); + KOMODO_DEPOSIT += fiatoshis; +} + +struct pax_transaction *komodo_paxfind(struct pax_transaction *space,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(struct pax_transaction *space,uint256 txid,uint16_t vout,int32_t mark) +{ + struct pax_transaction *pax; + pthread_mutex_lock(&komodo_mutex); + HASH_FIND(hh,PAX,&txid,sizeof(txid),pax); + if ( pax != 0 ) + { + pax->marked = mark; + memcpy(space,pax,sizeof(*pax)); + } + pthread_mutex_unlock(&komodo_mutex); + return(pax); +} int32_t komodo_issued_opreturn(uint8_t *shortflagp,char *base,uint256 *txids,uint16_t *vouts,uint8_t *opretbuf,int32_t opretlen) { @@ -53,10 +98,12 @@ int32_t komodo_issued_opreturn(uint8_t *shortflagp,char *base,uint256 *txids,uin void komodo_gateway_deposits(CMutableTransaction *txNew) { - struct pax_transaction *ptr; uint8_t *script,opret[10000],data[10000]; int32_t i,len=0,opretlen=0,numvouts=1; + struct pax_transaction *pax,*tmp; uint8_t *script,opret[10000],data[10000]; int32_t i,len=0,opretlen=0,numvouts=1; PENDING_KOMODO_TX = 0; - while ( numvouts < 64 && (ptr= (struct pax_transaction *)queue_dequeue(&DepositsQ)) != 0 ) + HASH_ITER(hh,PAX,ptr,tmp) { + if ( pax->mark != 0 ) + continue; txNew->vout.resize(numvouts+1); txNew->vout[numvouts].nValue = ptr->fiatoshis; txNew->vout[numvouts].scriptPubKey.resize(25); @@ -76,11 +123,9 @@ void komodo_gateway_deposits(CMutableTransaction *txNew) data[len++] = (ptr->vout >> 8) & 0xff; printf(" vout.%u DEPOSIT %.8f <- paxdeposit.%s\n",ptr->vout,(double)txNew->vout[numvouts].nValue/COIN,ASSETCHAINS_SYMBOL); PENDING_KOMODO_TX += ptr->fiatoshis; - numvouts++; - queue_enqueue((char *)"PENDINGS",&PendingsQ,&ptr->DL); + if ( numvouts++ >= 64 ) + break; } - while ( (ptr= (struct pax_transaction *)queue_dequeue(&PendingsQ)) != 0 ) - queue_enqueue((char *)"DEPOSITS",&DepositsQ,&ptr->DL); if ( numvouts > 1 ) { if ( ASSETCHAINS_SHORTFLAG != 0 ) @@ -98,60 +143,9 @@ void komodo_gateway_deposits(CMutableTransaction *txNew) } else KOMODO_DEPOSIT = 0; } -void komodo_gateway_deposit(char *coinaddr,uint64_t value,int32_t shortflag,char *symbol,uint64_t fiatoshis,uint8_t *rmd160,uint256 txid,uint16_t vout) // assetchain context -{ - struct pax_transaction *ptr; - ptr = (struct pax_transaction *)calloc(1,sizeof(*ptr)); - ptr->komodoshis = value; - ptr->fiatoshis = fiatoshis; - memcpy(ptr->symbol,symbol,3); - memcpy(ptr->rmd160,rmd160,20); - ptr->shortflag = shortflag; - ptr->txid = txid; - ptr->vout = vout; - KOMODO_DEPOSIT += fiatoshis; - printf("ADD DEPOSIT %s %.8f -> %s TO QUEUE\n",symbol,dstr(fiatoshis),coinaddr); - queue_enqueue((char *)"DEPOSITS",&DepositsQ,&ptr->DL); -} - -int32_t komodo_gateway_depositremove(uint256 txid,uint16_t vout) // assetchain context -{ - int32_t iter,i,n=0; queue_t *Q; struct pax_transaction *ptr; struct queueitem *item; - for (iter=0; iter<2; iter++) - { - Q = (iter == 0) ? &DepositsQ : &PendingsQ; - portable_mutex_lock(&Q->mutex); - if ( Q->list != 0 ) - { - item = &ptr->DL; - DL_FOREACH(Q->list,item) - { - ptr = (struct pax_transaction *)item; - if ( memcmp(&ptr->txid,&txid,sizeof(txid)) == 0 && ptr->vout == vout ) - { - if ( KOMODO_DEPOSIT >= ptr->fiatoshis ) - KOMODO_DEPOSIT -= ptr->fiatoshis; - else KOMODO_DEPOSIT = 0; - for (i=0; i<32; i++) - printf("%02x",((uint8_t *)&txid)[i]); - printf(" v%d DELETE %.8f DEPOSIT %s %.8f\n",vout,dstr(ptr->komodoshis),ptr->symbol,dstr(ptr->fiatoshis)); - DL_DELETE(Q->list,&ptr->DL); - n++; - free(ptr); - break; - } - } - } - portable_mutex_unlock(&Q->mutex); - } - if ( queue_size(&DepositsQ) == 0 && queue_size(&PendingsQ) == 0 ) - KOMODO_DEPOSIT = PENDING_KOMODO_TX = 0; - return(n); -} - int32_t komodo_check_deposit(int32_t height,const CBlock& block) // verify above block is valid pax pricing { - int32_t i,j,n,opretlen,num,iter,matchflag,offset=1; uint256 hash,txids[64]; uint8_t shortflag; char base[16]; uint16_t vouts[64]; uint8_t *script; queue_t *Q; struct pax_transaction *ptr; struct queueitem *item; + int32_t i,j,n,opretlen,offset=1; uint256 hash,txids[64]; uint8_t shortflag; char base[16]; uint16_t vouts[64]; uint8_t *script; struct pax_transaction *pax,space; n = block.vtx[0].vout.size(); script = (uint8_t *)block.vtx[0].vout[n-1].scriptPubKey.data(); if ( n <= 2 || script[0] != 0x6a ) @@ -164,45 +158,16 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block) // verify above { for (i=1; imutex); - ptr = 0; - if ( Q->list != 0 ) - { - item = &ptr->DL; - matchflag = 0; - DL_FOREACH(Q->list,item) - { - ptr = (struct pax_transaction *)item; - if ( memcmp(&ptr->txid,&txids[i-1],sizeof(txids[i-1])) == 0 && ptr->vout == vouts[i-1] ) - { - if ( ptr->fiatoshis == block.vtx[0].vout[i].nValue ) - { - /*for (j=0; j<32; j++) - printf("%02x",((uint8_t *)&ptr->txid)[j]); - printf(" v%d matched %.8f vout.%d ",ptr->vout,dstr(ptr->fiatoshis),i); - hash = block.GetHash(); - for (j=0; j<32; j++) - printf("%02x",((uint8_t *)&hash)[j]); - printf(".blockhash\n");*/ - matchflag = 1; - } else printf("error finding %.8f vout.%d\n",dstr(ptr->fiatoshis),i); - break; - } - } - } - portable_mutex_unlock(&Q->mutex); - } - if ( matchflag == 0 ) - { - hash = block.GetHash(); - for (j=0; j<32; j++) - printf("%02x",((uint8_t *)&hash)[j]); - printf(" ht.%d blockhash couldnt find vout.[%d]\n",height,i); - //return(-1); - } + if ( (pax= komodo_paxfind(&space,txids[i-1],vouts[i-1])) == 0 || ptr->fiatoshis != block.vtx[0].vout[i].nValue ) + break; + } + if ( i != n-1 ) + { + hash = block.GetHash(); + for (j=0; j<32; j++) + printf("%02x",((uint8_t *)&hash)[j]); + printf(" ht.%d blockhash couldnt find vout.[%d]\n",height,i); + //return(-1); } } //printf("opretlen.%d num.%d\n",opretlen,num); @@ -212,7 +177,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) { - uint8_t rmd160[20],addrtype,shortflag,pubkey33[33]; int32_t i,j,n,len,tokomodo=0; char base[4],coinaddr[64],destaddr[64]; uint256 txids[64]; uint16_t vouts[64]; int64_t fiatoshis,checktoshis; const char *typestr = "unknown"; + uint8_t rmd160[20],addrtype,shortflag,pubkey33[33]; int32_t i,j,n,len,tokomodo=0; char base[4],coinaddr[64],destaddr[64]; struct pax_transaction space; uint256 txids[64]; uint16_t vouts[64]; int64_t fiatoshis,checktoshis; const char *typestr = "unknown"; tokomodo = (komodo_is_issuer() == 0); //for (i=0; i Date: Mon, 31 Oct 2016 19:17:42 -0300 Subject: [PATCH 113/254] 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 d9505d3fe..1cdb49dc9 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -145,7 +145,7 @@ void komodo_gateway_deposits(CMutableTransaction *txNew) int32_t komodo_check_deposit(int32_t height,const CBlock& block) // verify above block is valid pax pricing { - int32_t i,j,n,opretlen,offset=1; uint256 hash,txids[64]; uint8_t shortflag; char base[16]; uint16_t vouts[64]; uint8_t *script; struct pax_transaction *pax,space; + int32_t i,j,n,num,opretlen,offset=1; uint256 hash,txids[64]; uint8_t shortflag; char base[16]; uint16_t vouts[64]; uint8_t *script; struct pax_transaction *pax,space; n = block.vtx[0].vout.size(); script = (uint8_t *)block.vtx[0].vout[n-1].scriptPubKey.data(); if ( n <= 2 || script[0] != 0x6a ) @@ -158,7 +158,7 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block) // verify above { for (i=1; ifiatoshis != block.vtx[0].vout[i].nValue ) + if ( (pax= komodo_paxfind(&space,txids[i-1],vouts[i-1])) == 0 || pax->fiatoshis != block.vtx[0].vout[i].nValue ) break; } if ( i != n-1 ) From 8ec26042da2217a6703df4acd99f7f47b77484d4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 31 Oct 2016 19:18:26 -0300 Subject: [PATCH 114/254] 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 1cdb49dc9..4f44c45f7 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -22,7 +22,7 @@ struct pax_transaction uint64_t komodoshis,fiatoshis; int32_t mark; uint16_t vout; - char symbol[16]; uint8_t rmd160[20],shortflag; + char symbol[16],coinaddr[64]; uint8_t rmd160[20],shortflag; } *PAX; void komodo_gateway_deposit(char *coinaddr,uint64_t value,int32_t shortflag,char *symbol,uint64_t fiatoshis,uint8_t *rmd160,uint256 txid,uint16_t vout) // assetchain context @@ -100,7 +100,7 @@ void komodo_gateway_deposits(CMutableTransaction *txNew) { struct pax_transaction *pax,*tmp; uint8_t *script,opret[10000],data[10000]; int32_t i,len=0,opretlen=0,numvouts=1; PENDING_KOMODO_TX = 0; - HASH_ITER(hh,PAX,ptr,tmp) + HASH_ITER(hh,PAX,pax,tmp) { if ( pax->mark != 0 ) continue; From 93760f48a318bc2d451cac6ada08f4ab598d0ba9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 31 Oct 2016 19:20:24 -0300 Subject: [PATCH 115/254] test --- src/komodo_gateway.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 4f44c45f7..da7b8c5ed 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -20,7 +20,7 @@ struct pax_transaction UT_hash_handle hh; uint256 txid; uint64_t komodoshis,fiatoshis; - int32_t mark; + int32_t marked; uint16_t vout; char symbol[16],coinaddr[64]; uint8_t rmd160[20],shortflag; } *PAX; @@ -105,24 +105,24 @@ void komodo_gateway_deposits(CMutableTransaction *txNew) if ( pax->mark != 0 ) continue; txNew->vout.resize(numvouts+1); - txNew->vout[numvouts].nValue = ptr->fiatoshis; + txNew->vout[numvouts].nValue = pax->fiatoshis; txNew->vout[numvouts].scriptPubKey.resize(25); script = (uint8_t *)&txNew->vout[numvouts].scriptPubKey[0]; *script++ = 0x76; *script++ = 0xa9; *script++ = 20; - memcpy(script,ptr->rmd160,20), script += 20; + memcpy(script,pax->rmd160,20), script += 20; *script++ = 0x88; *script++ = 0xac; for (i=0; i<32; i++) { - printf("%02x",((uint8_t *)&ptr->txid)[i]); - data[len++] = ((uint8_t *)&ptr->txid)[i]; + printf("%02x",((uint8_t *)&pax->txid)[i]); + data[len++] = ((uint8_t *)&pax->txid)[i]; } - data[len++] = ptr->vout & 0xff; - data[len++] = (ptr->vout >> 8) & 0xff; - printf(" vout.%u DEPOSIT %.8f <- paxdeposit.%s\n",ptr->vout,(double)txNew->vout[numvouts].nValue/COIN,ASSETCHAINS_SYMBOL); - PENDING_KOMODO_TX += ptr->fiatoshis; + data[len++] = pax->vout & 0xff; + data[len++] = (pax->vout >> 8) & 0xff; + printf(" vout.%u DEPOSIT %.8f <- paxdeposit.%s\n",pax->vout,(double)txNew->vout[numvouts].nValue/COIN,ASSETCHAINS_SYMBOL); + PENDING_KOMODO_TX += pax->fiatoshis; if ( numvouts++ >= 64 ) break; } From 15a04b7852743b3f9fca39a2069b52b5df33a0cb Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 31 Oct 2016 19:21:05 -0300 Subject: [PATCH 116/254] 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 da7b8c5ed..ed79bf856 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -102,7 +102,7 @@ void komodo_gateway_deposits(CMutableTransaction *txNew) PENDING_KOMODO_TX = 0; HASH_ITER(hh,PAX,pax,tmp) { - if ( pax->mark != 0 ) + if ( pax->marked != 0 ) continue; txNew->vout.resize(numvouts+1); txNew->vout[numvouts].nValue = pax->fiatoshis; From 32888d61143e9b40bcaa34b9f6dc111193ef4c30 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 31 Oct 2016 19:40:07 -0300 Subject: [PATCH 117/254] 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 ed79bf856..c4e08cbe8 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -191,7 +191,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 if ( fiatoshis < 0 ) fiatoshis = -fiatoshis; bitcoin_address(coinaddr,addrtype,rmd160,20); - checktoshis = PAX_fiatdest(tokomodo,destaddr,pubkey33,coinaddr,height-1,base,fiatoshis); + checktoshis = PAX_fiatdest(tokomodo,destaddr,pubkey33,coinaddr,height,base,fiatoshis); typestr = "deposit"; if ( tokomodo == 0 && strncmp(ASSETCHAINS_SYMBOL,base,strlen(base)) == 0 ) { From 4141ccfd1859f627c263fe9426024db6d78baeab Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 31 Oct 2016 19:51:58 -0300 Subject: [PATCH 118/254] test --- src/komodo_notary.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/komodo_notary.h b/src/komodo_notary.h index 6e834cba6..38ef1bf4c 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -92,8 +92,6 @@ int32_t komodo_nutxofind(int32_t height,uint256 txhash,int32_t vout) int32_t komodo_ratify_threshold(int32_t height,uint64_t signedmask) { int32_t htind,numnotaries,i,wt = 0; - if ( ASSETCHAINS_SYMBOL[0] != 0 ) - return(2); if ( (htind= KOMODO_PUBKEYS_HEIGHT(height) / KOMODO_ELECTION_GAP) == 1 ) htind = 0; numnotaries = Pubkeys[htind].numnotaries; From b8b96fdc408cf68f5783f735d902b8cace7beb29 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 31 Oct 2016 20:02:51 -0300 Subject: [PATCH 119/254] test --- src/komodo_gateway.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index c4e08cbe8..e0edd233f 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -147,6 +147,11 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block) // verify above { int32_t i,j,n,num,opretlen,offset=1; uint256 hash,txids[64]; uint8_t shortflag; char base[16]; uint16_t vouts[64]; uint8_t *script; struct pax_transaction *pax,space; n = block.vtx[0].vout.size(); + while ( KOMODO_REALTIME == 0 || time(null) < KOMODO_REALTIME ) + { + printf("komodo_check_deposit waiting for realtime\n"); + sleep(3); + } script = (uint8_t *)block.vtx[0].vout[n-1].scriptPubKey.data(); if ( n <= 2 || script[0] != 0x6a ) return(0); From 40cc514091583794a79fcdf0f008e786e17b7e91 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 31 Oct 2016 20:03:58 -0300 Subject: [PATCH 120/254] 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 e0edd233f..0293712fa 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -147,7 +147,7 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block) // verify above { int32_t i,j,n,num,opretlen,offset=1; uint256 hash,txids[64]; uint8_t shortflag; char base[16]; uint16_t vouts[64]; uint8_t *script; struct pax_transaction *pax,space; n = block.vtx[0].vout.size(); - while ( KOMODO_REALTIME == 0 || time(null) < KOMODO_REALTIME ) + while ( KOMODO_REALTIME == 0 || time(NULL) <= KOMODO_REALTIME ) { printf("komodo_check_deposit waiting for realtime\n"); sleep(3); From 96360d474c1a9ec575f780fceba09ac7842563bc Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 31 Oct 2016 20:07:15 -0300 Subject: [PATCH 121/254] test --- src/komodo_gateway.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 0293712fa..7ffffbfc0 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -147,11 +147,6 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block) // verify above { int32_t i,j,n,num,opretlen,offset=1; uint256 hash,txids[64]; uint8_t shortflag; char base[16]; uint16_t vouts[64]; uint8_t *script; struct pax_transaction *pax,space; n = block.vtx[0].vout.size(); - while ( KOMODO_REALTIME == 0 || time(NULL) <= KOMODO_REALTIME ) - { - printf("komodo_check_deposit waiting for realtime\n"); - sleep(3); - } script = (uint8_t *)block.vtx[0].vout[n-1].scriptPubKey.data(); if ( n <= 2 || script[0] != 0x6a ) return(0); @@ -226,6 +221,11 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 { if ( (n= komodo_issued_opreturn(&shortflag,base,txids,vouts,opretbuf,opretlen)) > 0 && shortflag == ASSETCHAINS_SHORTFLAG ) { + while ( KOMODO_REALTIME == 0 || time(NULL) <= KOMODO_REALTIME ) + { + printf("komodo_opreturn waiting for realtime\n"); + sleep(3); + } for (i=0; i Date: Mon, 31 Oct 2016 20:13:42 -0300 Subject: [PATCH 122/254] test --- src/komodo_gateway.h | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 7ffffbfc0..805189be0 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -20,24 +20,33 @@ struct pax_transaction UT_hash_handle hh; uint256 txid; uint64_t komodoshis,fiatoshis; - int32_t marked; + int32_t marked,height; uint16_t vout; char symbol[16],coinaddr[64]; uint8_t rmd160[20],shortflag; } *PAX; -void komodo_gateway_deposit(char *coinaddr,uint64_t value,int32_t shortflag,char *symbol,uint64_t fiatoshis,uint8_t *rmd160,uint256 txid,uint16_t vout) // assetchain context +void komodo_gateway_deposit(char *coinaddr,uint64_t value,int32_t shortflag,char *symbol,uint64_t fiatoshis,uint8_t *rmd160,uint256 txid,uint16_t vout,int32_t height) // assetchain context { struct pax_transaction *pax; pax = (struct pax_transaction *)calloc(1,sizeof(*pax)); - strcpy(pax->coinaddr,coinaddr); - pax->komodoshis = value; - pax->shortflag = shortflag; - strcpy(pax->symbol,symbol); - pax->fiatoshis = fiatoshis; - memcpy(pax->rmd160,rmd160,20); + if ( coinaddr != 0 ) + { + strcpy(pax->coinaddr,coinaddr); + pax->komodoshis = value; + pax->shortflag = shortflag; + strcpy(pax->symbol,symbol); + pax->fiatoshis = fiatoshis; + memcpy(pax->rmd160,rmd160,20); + pax->height = height; + printf("ADD DEPOSIT %s %.8f -> %s TO PAX ht.%d\n",symbol,dstr(fiatoshis),coinaddr,height); + } + else + { + pax->marked = height; + printf("MARK DEPOSIT ht.%d\n",height); + } pax->txid = txid; pax->vout = vout; - printf("ADD DEPOSIT %s %.8f -> %s TO PAX\n",symbol,dstr(fiatoshis),coinaddr); pthread_mutex_lock(&komodo_mutex); HASH_ADD_KEYPTR(hh,PAX,&pax->txid,sizeof(pax->txid),pax); pthread_mutex_unlock(&komodo_mutex); @@ -203,7 +212,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 printf(" checkpubkey check %.8f v %.8f dest.(%s) height.%d\n",dstr(checktoshis),dstr(value),destaddr,height); if ( value >= checktoshis && shortflag == ASSETCHAINS_SHORTFLAG ) { - komodo_gateway_deposit(coinaddr,value,shortflag,base,fiatoshis,rmd160,txid,vout); + komodo_gateway_deposit(coinaddr,value,shortflag,base,fiatoshis,rmd160,txid,vout,height); } } else @@ -221,18 +230,16 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 { if ( (n= komodo_issued_opreturn(&shortflag,base,txids,vouts,opretbuf,opretlen)) > 0 && shortflag == ASSETCHAINS_SHORTFLAG ) { - while ( KOMODO_REALTIME == 0 || time(NULL) <= KOMODO_REALTIME ) - { - printf("komodo_opreturn waiting for realtime\n"); - sleep(3); - } for (i=0; i Date: Mon, 31 Oct 2016 20:39:53 -0300 Subject: [PATCH 123/254] test --- src/rpcserver.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/rpcserver.cpp b/src/rpcserver.cpp index 41725499c..a46c66a46 100644 --- a/src/rpcserver.cpp +++ b/src/rpcserver.cpp @@ -973,8 +973,10 @@ static bool HTTPReq_JSONRPC(AcceptedConnection *conn, // Parse request Value valRequest; if (!read_string(strRequest, valRequest)) + { + fprintf(stderr,"CANTPARSE.(%s)\n",strRequest.c_str()); throw JSONRPCError(RPC_PARSE_ERROR, "Parse error"); - + } // Return immediately if in warmup { LOCK(cs_rpcWarmup); From da61ef214cf2cf9604cebd78b6a0750d786bce9a Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 1 Nov 2016 14:34:36 -0300 Subject: [PATCH 124/254] boost round robin rate --- src/miner.cpp | 6 +++--- src/rpcserver.cpp | 1 - 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index e3e32a4a2..3563c83fe 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -606,10 +606,10 @@ void static BitcoinMiner(CWallet *pwallet) solutionTargetChecks.increment(); if ( UintToArith256(pblock->GetHash()) > hashTarget ) return false; - if ( Mining_start != 0 && time(NULL) < Mining_start+50 ) + if ( Mining_start != 0 && time(NULL) < Mining_start+30 ) { - printf("Round robin diff sleep %d\n",(int32_t)(Mining_start+50-time(NULL))); - sleep(Mining_start+50-time(NULL)); + printf("Round robin diff sleep %d\n",(int32_t)(Mining_start+30-time(NULL))); + sleep(Mining_start+30-time(NULL)); } // Found a solution SetThreadPriority(THREAD_PRIORITY_NORMAL); diff --git a/src/rpcserver.cpp b/src/rpcserver.cpp index a46c66a46..95bd02b0d 100644 --- a/src/rpcserver.cpp +++ b/src/rpcserver.cpp @@ -966,7 +966,6 @@ static bool HTTPReq_JSONRPC(AcceptedConnection *conn, conn->stream() << HTTPError(HTTP_UNAUTHORIZED, false) << std::flush; return false; } - JSONRequest jreq; try { From 0b3487d0d347155d6cc2464dccd66bf831c4abdf Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 2 Nov 2016 08:31:58 -0300 Subject: [PATCH 125/254] 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 805189be0..986296d71 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -188,9 +188,6 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 { uint8_t rmd160[20],addrtype,shortflag,pubkey33[33]; int32_t i,j,n,len,tokomodo=0; char base[4],coinaddr[64],destaddr[64]; struct pax_transaction space; uint256 txids[64]; uint16_t vouts[64]; int64_t fiatoshis,checktoshis; const char *typestr = "unknown"; tokomodo = (komodo_is_issuer() == 0); - //for (i=0; i %s ",opretbuf[0],tokomodo,dstr(fiatoshis),shortflag!=0?'-':'+',base,coinaddr); if ( opretbuf[0] == ((tokomodo == 0) ? 'D' : 'W') ) { if ( opretlen == 34 ) @@ -226,6 +223,9 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 } else if ( strncmp((char *)"KMD",(char *)&opretbuf[opretlen-4],3) != 0 ) { + for (i=0; i 0 && shortflag == ASSETCHAINS_SHORTFLAG ) From 5031571f776eaa37b3d36c8a70279410b301d185 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 2 Nov 2016 08:45:09 -0300 Subject: [PATCH 126/254] 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 986296d71..2143f5b1b 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -188,6 +188,9 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 { uint8_t rmd160[20],addrtype,shortflag,pubkey33[33]; int32_t i,j,n,len,tokomodo=0; char base[4],coinaddr[64],destaddr[64]; struct pax_transaction space; uint256 txids[64]; uint16_t vouts[64]; int64_t fiatoshis,checktoshis; const char *typestr = "unknown"; tokomodo = (komodo_is_issuer() == 0); + for (i=0; i 0 && shortflag == ASSETCHAINS_SHORTFLAG ) From 4a8e2406f5549a31dcbbe7c3cf87cbdd41483819 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 2 Nov 2016 08:51:30 -0300 Subject: [PATCH 127/254] test --- src/komodo_gateway.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 2143f5b1b..48b083203 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -188,9 +188,12 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 { uint8_t rmd160[20],addrtype,shortflag,pubkey33[33]; int32_t i,j,n,len,tokomodo=0; char base[4],coinaddr[64],destaddr[64]; struct pax_transaction space; uint256 txids[64]; uint16_t vouts[64]; int64_t fiatoshis,checktoshis; const char *typestr = "unknown"; tokomodo = (komodo_is_issuer() == 0); - for (i=0; i Date: Wed, 2 Nov 2016 09:45:38 -0300 Subject: [PATCH 128/254] test --- src/rpcblockchain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 0f811ebac..1dadc4784 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -394,7 +394,7 @@ Value notaries(const Array& params, bool fHelp) throw runtime_error("notaries height\n"); LOCK(cs_main); int32_t height = atoi(params[0].get_str().c_str()); - if ( height < 0 || height > chainActive.Height() ) + if ( height < 0 || height > chainActive.Height()+2000 ) throw JSONRPCError(RPC_INVALID_PARAMETER, "Block height out of range"); else { From af3816456287463929a8905e6e8e7bbde36077cf Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 4 Nov 2016 08:57:16 -0300 Subject: [PATCH 129/254] test --- src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 5d4bf33f0..9c9d4d21d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -550,8 +550,8 @@ CBlockTreeDB *pblocktree = NULL; // Komodo globals -#define KOMODO_TESTNET_EXPIRATION 60000 -//#define KOMODO_ENABLE_INTEREST enabling this is a hardfork +#define KOMODO_TESTNET_EXPIRATION 100000 +#define KOMODO_ENABLE_INTEREST //enabling this is a hardfork #define KOMODO_PAX #define KOMODO_ZCASH #include "komodo.h" From 2d4c201cefa8a383bb44624e42e6d43d5a270654 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 4 Nov 2016 09:16:44 -0300 Subject: [PATCH 130/254] test --- src/coins.cpp | 3 ++- src/wallet/wallet.cpp | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/coins.cpp b/src/coins.cpp index 4272ed611..a3acfd559 100644 --- a/src/coins.cpp +++ b/src/coins.cpp @@ -398,7 +398,8 @@ CAmount CCoinsViewCache::GetValueIn(int32_t nHeight,int64_t *interestp,const CTr nResult += value; interest = komodo_interest(nHeight,value,tx.nLockTime,tiptime); #ifdef KOMODO_ENABLE_INTEREST - nResult += interest; + if ( nHeight >= 60000 ) + nResult += interest; #endif (*interestp) += interest; } diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index df9b8ee43..f0f4daff0 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2400,7 +2400,8 @@ bool CWallet::SelectCoins(const CAmount& nTargetValue, setvout[out.i].nValue; interest = komodo_interest(chainActive.Tip()->nHeight,out.tx->vout[out.i].nValue,out.tx->nLockTime,chainActive.Tip()->nTime); #ifdef KOMODO_ENABLE_INTEREST - nValueRet += interest; + if ( txheight >= 60000 ) + nValueRet += interest; #endif fprintf(stderr,"interest %llu from %llu lock.%u tip.%u\n",(long long)interest,(long long)out.tx->vout[out.i].nValue,out.tx->nLockTime,chainActive.Tip()->nTime); setCoinsRet.insert(make_pair(out.tx, out.i)); From 6e576848c084170095f0f1ff383a05aab7d28e79 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 4 Nov 2016 13:58:26 -0300 Subject: [PATCH 131/254] test --- src/komodo_gateway.h | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 48b083203..b353b1f1c 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -169,6 +169,7 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block) // verify above { if ( (pax= komodo_paxfind(&space,txids[i-1],vouts[i-1])) == 0 || pax->fiatoshis != block.vtx[0].vout[i].nValue ) break; + else printf("found issued %.8f\n",dstr(block.vtx[0].vout[i].nValue)); } if ( i != n-1 ) { @@ -188,16 +189,16 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 { uint8_t rmd160[20],addrtype,shortflag,pubkey33[33]; int32_t i,j,n,len,tokomodo=0; char base[4],coinaddr[64],destaddr[64]; struct pax_transaction space; uint256 txids[64]; uint16_t vouts[64]; int64_t fiatoshis,checktoshis; const char *typestr = "unknown"; tokomodo = (komodo_is_issuer() == 0); - if ( ASSETCHAINS_SYMBOL[0] != 0 ) - { - for (i=0; i 0 && shortflag == ASSETCHAINS_SHORTFLAG ) { for (i=0; i Date: Fri, 4 Nov 2016 14:10:54 -0300 Subject: [PATCH 132/254] test --- src/komodo_gateway.h | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index b353b1f1c..88d00dc8b 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -169,7 +169,7 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block) // verify above { if ( (pax= komodo_paxfind(&space,txids[i-1],vouts[i-1])) == 0 || pax->fiatoshis != block.vtx[0].vout[i].nValue ) break; - else printf("found issued %.8f\n",dstr(block.vtx[0].vout[i].nValue)); + komodo_paxmark(&space,txids[i-1],vouts[i-1],height); } if ( i != n-1 ) { @@ -193,7 +193,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 { if ( opretlen == 34 ) { - if ( ASSETCHAINS_SYMBOL[0] != 0 ) + if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 ) { for (i=0; i= checktoshis && shortflag == ASSETCHAINS_SHORTFLAG ) { - komodo_gateway_deposit(coinaddr,value,shortflag,base,fiatoshis,rmd160,txid,vout,height); + if ( komodo_paxfind(&space,txid,vout) == 0 ) + komodo_gateway_deposit(coinaddr,value,shortflag,base,fiatoshis,rmd160,txid,vout,height); } } else @@ -232,7 +233,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 { if ( tokomodo == 0 && opretbuf[0] == 'I' ) { - if ( ASSETCHAINS_SYMBOL[0] != 0 ) + if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 ) { for (i=0; i Date: Fri, 4 Nov 2016 14:27:09 -0300 Subject: [PATCH 133/254] test --- src/komodo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index 46bfd224f..c62382f1d 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -422,7 +422,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) } } } - if ( komodo_isratify(1,numvalid) > 13 ) + if ( komodo_isratify(1,numvalid) > 7 ) { memset(&txhash,0,sizeof(txhash)); komodo_stateupdate(height,pubkeys,numvalid,0,txhash,0,0,0,0,0,0,0,0,0); From 6e564cb5270a66ce034e992596283bf62ec76caa Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 4 Nov 2016 15:22:28 -0300 Subject: [PATCH 134/254] test --- src/komodo_gateway.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 88d00dc8b..5705b331c 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -72,6 +72,7 @@ struct pax_transaction *komodo_paxmark(struct pax_transaction *space,uint256 txi if ( pax != 0 ) { pax->marked = mark; + char str[65]; printf("paxmark.ht %d (%s).v%d\n",mark,bits256_str(str,txid),vout); memcpy(space,pax,sizeof(*pax)); } pthread_mutex_unlock(&komodo_mutex); From 2f4cbc942a4065db616348e383059beaab23d74a Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 4 Nov 2016 15:24:09 -0300 Subject: [PATCH 135/254] 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 5705b331c..77b3d3637 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -72,7 +72,9 @@ struct pax_transaction *komodo_paxmark(struct pax_transaction *space,uint256 txi if ( pax != 0 ) { pax->marked = mark; - char str[65]; printf("paxmark.ht %d (%s).v%d\n",mark,bits256_str(str,txid),vout); + 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); From cb040aa153d7c105f56ba513ab4c4a846820e155 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 4 Nov 2016 16:10:13 -0300 Subject: [PATCH 136/254] test --- src/komodo_gateway.h | 20 +++++++++----------- src/miner.cpp | 2 +- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 77b3d3637..5e79a0b59 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -170,17 +170,15 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block) // verify above { for (i=1; ifiatoshis != block.vtx[0].vout[i].nValue ) - break; - komodo_paxmark(&space,txids[i-1],vouts[i-1],height); - } - if ( i != n-1 ) - { - hash = block.GetHash(); - for (j=0; j<32; j++) - printf("%02x",((uint8_t *)&hash)[j]); - printf(" ht.%d blockhash couldnt find vout.[%d]\n",height,i); - //return(-1); + if ( (pax= komodo_paxfind(&space,txids[i-1],vouts[i-1])) != 0 && pax->fiatoshis == block.vtx[0].vout[i].nValue ) + komodo_paxmark(&space,txids[i-1],vouts[i-1],height); + else + { + hash = block.GetHash(); + for (j=0; j<32; j++) + printf("%02x",((uint8_t *)&hash)[j]); + printf(" ht.%d blockhash couldnt find vout.[%d]\n",height,i); + } } } //printf("opretlen.%d num.%d\n",opretlen,num); diff --git a/src/miner.cpp b/src/miner.cpp index 3563c83fe..4db4cb02a 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -606,7 +606,7 @@ void static BitcoinMiner(CWallet *pwallet) solutionTargetChecks.increment(); if ( UintToArith256(pblock->GetHash()) > hashTarget ) return false; - if ( Mining_start != 0 && time(NULL) < Mining_start+30 ) + if ( ASSETCHAINS_SYMBOL[0] == 0 && Mining_start != 0 && time(NULL) < Mining_start+30 ) { printf("Round robin diff sleep %d\n",(int32_t)(Mining_start+30-time(NULL))); sleep(Mining_start+30-time(NULL)); From d43c7a934147e31d9a21d0aa16c81c63f2fcfd59 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 4 Nov 2016 16:14:53 -0300 Subject: [PATCH 137/254] test --- src/komodo_gateway.h | 62 ++++++++++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 28 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 5e79a0b59..fa5501fff 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -25,34 +25,6 @@ struct pax_transaction char symbol[16],coinaddr[64]; uint8_t rmd160[20],shortflag; } *PAX; -void komodo_gateway_deposit(char *coinaddr,uint64_t value,int32_t shortflag,char *symbol,uint64_t fiatoshis,uint8_t *rmd160,uint256 txid,uint16_t vout,int32_t height) // assetchain context -{ - struct pax_transaction *pax; - pax = (struct pax_transaction *)calloc(1,sizeof(*pax)); - if ( coinaddr != 0 ) - { - strcpy(pax->coinaddr,coinaddr); - pax->komodoshis = value; - pax->shortflag = shortflag; - strcpy(pax->symbol,symbol); - pax->fiatoshis = fiatoshis; - memcpy(pax->rmd160,rmd160,20); - pax->height = height; - printf("ADD DEPOSIT %s %.8f -> %s TO PAX ht.%d\n",symbol,dstr(fiatoshis),coinaddr,height); - } - else - { - pax->marked = height; - printf("MARK DEPOSIT ht.%d\n",height); - } - pax->txid = txid; - pax->vout = vout; - pthread_mutex_lock(&komodo_mutex); - HASH_ADD_KEYPTR(hh,PAX,&pax->txid,sizeof(pax->txid),pax); - pthread_mutex_unlock(&komodo_mutex); - KOMODO_DEPOSIT += fiatoshis; -} - struct pax_transaction *komodo_paxfind(struct pax_transaction *space,uint256 txid,uint16_t vout) { struct pax_transaction *pax; @@ -81,6 +53,40 @@ struct pax_transaction *komodo_paxmark(struct pax_transaction *space,uint256 txi return(pax); } +void komodo_gateway_deposit(char *coinaddr,uint64_t value,int32_t shortflag,char *symbol,uint64_t fiatoshis,uint8_t *rmd160,uint256 txid,uint16_t vout,int32_t height) // assetchain context +{ + struct pax_transaction *pax; + pthread_mutex_lock(&komodo_mutex); + HASH_FIND(hh,PAX,&txid,sizeof(txid),pax); + if ( pax == 0 ) + pax = (struct pax_transaction *)calloc(1,sizeof(*pax)); + if ( coinaddr != 0 ) + { + strcpy(pax->coinaddr,coinaddr); + pax->komodoshis = value; + pax->shortflag = shortflag; + strcpy(pax->symbol,symbol); + pax->fiatoshis = fiatoshis; + memcpy(pax->rmd160,rmd160,20); + pax->height = height; + if ( pax->marked == 0 ) + printf("ADD DEPOSIT %s %.8f -> %s TO PAX ht.%d\n",symbol,dstr(fiatoshis),coinaddr,height); + else printf("MARKED.%d DEPOSIT %s %.8f -> %s TO PAX ht.%d\n",pax->marked,symbol,dstr(fiatoshis),coinaddr,height); + } + else + { + pax->marked = height; + printf("MARK DEPOSIT ht.%d\n",height); + } + pax->txid = txid; + pax->vout = vout; + pthread_mutex_lock(&komodo_mutex); + HASH_ADD_KEYPTR(hh,PAX,&pax->txid,sizeof(pax->txid),pax); + pthread_mutex_unlock(&komodo_mutex); + KOMODO_DEPOSIT += fiatoshis; + pthread_mutex_unlock(&komodo_mutex); +} + int32_t komodo_issued_opreturn(uint8_t *shortflagp,char *base,uint256 *txids,uint16_t *vouts,uint8_t *opretbuf,int32_t opretlen) { int32_t i,n=0,j,len; From 2ef81a6e8b70441d458ba5f5b70ce0ce53b2d7f2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 4 Nov 2016 16:18:27 -0300 Subject: [PATCH 138/254] test --- src/komodo_gateway.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index fa5501fff..15bbeb327 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -184,6 +184,7 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block) // verify above for (j=0; j<32; j++) printf("%02x",((uint8_t *)&hash)[j]); printf(" ht.%d blockhash couldnt find vout.[%d]\n",height,i); + komodo_paxmark(&space,txids[i-1],vouts[i-1],height); } } } From 2ab43fd2fe8be83d8a47a43c29ed69b0556add75 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 4 Nov 2016 16:26:07 -0300 Subject: [PATCH 139/254] test --- src/komodo_gateway.h | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 15bbeb327..779fe5452 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -25,6 +25,17 @@ struct pax_transaction char symbol[16],coinaddr[64]; uint8_t rmd160[20],shortflag; } *PAX; +uint64_t komodo_paxtotal() +{ + struct pax_transaction *pax,*tmp; uint64_t total = 0; + HASH_ITER(hh,PAX,pax,tmp) + { + if ( pax->marked == 0 ) + total += pax->fiatoshis; + } + return(total); +} + struct pax_transaction *komodo_paxfind(struct pax_transaction *space,uint256 txid,uint16_t vout) { struct pax_transaction *pax; @@ -41,6 +52,13 @@ struct pax_transaction *komodo_paxmark(struct pax_transaction *space,uint256 txi struct pax_transaction *pax; pthread_mutex_lock(&komodo_mutex); HASH_FIND(hh,PAX,&txid,sizeof(txid),pax); + if ( pax == 0 ) + { + pax = (struct pax_transaction *)calloc(1,sizeof(*pax)); + pax->txid = txid; + pax->vout = vout; + HASH_ADD_KEYPTR(hh,PAX,&pax->txid,sizeof(pax->txid),pax); + } if ( pax != 0 ) { pax->marked = mark; @@ -80,11 +98,8 @@ void komodo_gateway_deposit(char *coinaddr,uint64_t value,int32_t shortflag,char } pax->txid = txid; pax->vout = vout; - pthread_mutex_lock(&komodo_mutex); HASH_ADD_KEYPTR(hh,PAX,&pax->txid,sizeof(pax->txid),pax); pthread_mutex_unlock(&komodo_mutex); - KOMODO_DEPOSIT += fiatoshis; - pthread_mutex_unlock(&komodo_mutex); } int32_t komodo_issued_opreturn(uint8_t *shortflagp,char *base,uint256 *txids,uint16_t *vouts,uint8_t *opretbuf,int32_t opretlen) @@ -401,4 +416,5 @@ void komodo_gateway_iteration(char *symbol) printf("error from %s\n",symbol); sleep(30); } + KOMODO_DEPOSIT = komodo_paxtotal(); } From fd8dd3c26d8c009430b057c2568268f88420463c Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 4 Nov 2016 18:11:04 -0300 Subject: [PATCH 140/254] test --- src/coins.cpp | 3 ++- src/komodo_gateway.h | 5 ++++- src/wallet/wallet.cpp | 3 ++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/coins.cpp b/src/coins.cpp index a3acfd559..bbff5495b 100644 --- a/src/coins.cpp +++ b/src/coins.cpp @@ -384,6 +384,7 @@ const CScript &CCoinsViewCache::GetSpendFor(const CTxIn& input) const } uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uint32_t tiptime); +extern char ASSETCHAINS_SYMBOL[16]; CAmount CCoinsViewCache::GetValueIn(int32_t nHeight,int64_t *interestp,const CTransaction& tx,uint32_t tiptime) const { @@ -398,7 +399,7 @@ CAmount CCoinsViewCache::GetValueIn(int32_t nHeight,int64_t *interestp,const CTr nResult += value; interest = komodo_interest(nHeight,value,tx.nLockTime,tiptime); #ifdef KOMODO_ENABLE_INTEREST - if ( nHeight >= 60000 ) + if ( ASSETCHAINS_SYMBOL[0] == 0 && nHeight >= 60000 ) nResult += interest; #endif (*interestp) += interest; diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 779fe5452..6533f73cb 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -243,8 +243,11 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 komodo_gateway_deposit(coinaddr,value,shortflag,base,fiatoshis,rmd160,txid,vout,height); } } - else + else if ( tokomodo != 0 && ASSETCHAINS_SYMBOL[0] == 0 ) { + for (i=0; i return all selected outputs (we want all selected to go into the transaction for sure) if (coinControl && coinControl->HasSelected()) { + extern char ASSETCHAINS_SYMBOL[16]; uint64_t interest; BOOST_FOREACH(const COutput& out, vCoins) { @@ -2400,7 +2401,7 @@ bool CWallet::SelectCoins(const CAmount& nTargetValue, setvout[out.i].nValue; interest = komodo_interest(chainActive.Tip()->nHeight,out.tx->vout[out.i].nValue,out.tx->nLockTime,chainActive.Tip()->nTime); #ifdef KOMODO_ENABLE_INTEREST - if ( txheight >= 60000 ) + if ( ASSETCHAINS_SYMBOL[0] == 0 && txheight >= 60000 ) nValueRet += interest; #endif fprintf(stderr,"interest %llu from %llu lock.%u tip.%u\n",(long long)interest,(long long)out.tx->vout[out.i].nValue,out.tx->nLockTime,chainActive.Tip()->nTime); From c5dec2a575a7ef59df10a7c7ae9e78abda13a984 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 4 Nov 2016 19:10:19 -0300 Subject: [PATCH 141/254] test --- src/wallet/rpcwallet.cpp | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index be53660f6..fd3f2da42 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -469,11 +469,14 @@ Value sendtoaddress(const Array& params, bool fHelp) uint64_t PAX_fiatdest(int32_t tokomodo,char *destaddr,uint8_t pubkey33[33],char *coinaddr,int32_t height,char *base,int64_t fiatoshis); int32_t komodo_opreturnscript(uint8_t *script,uint8_t type,uint8_t *opret,int32_t opretlen); #define CRYPTO777_KMDADDR "RXL3YXG2ceaB6C5hfJcN4fvmLH2C34knhA" +extern char ASSETCHAINS_SYMBOL[16]; Value paxdeposit(const Array& params, bool fHelp) { uint64_t komodoshis = 0; char destaddr[64]; uint8_t i,pubkey33[33]; bool fSubtractFeeFromAmount = false; + if ( ASSETCHAINS_SYMBOL[0] != 0 ) + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "paxdeposit only from KMD"); if (!EnsureWalletIsAvailable(fHelp)) return Value::null; if (fHelp || params.size() != 3) @@ -490,7 +493,6 @@ Value paxdeposit(const Array& params, bool fHelp) CBitcoinAddress destaddress(CRYPTO777_KMDADDR); if (!destaddress.IsValid()) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid dest Bitcoin address"); - for (i=0; i<33; i++) printf("%02x",pubkey33[i]); printf(" ht.%d srcaddr.(%s) %s fiatoshis.%lld -> dest.(%s) komodoshis.%llu\n",chainActive.Tip()->nHeight,(char *)params[0].get_str().c_str(),(char *)base.c_str(),(long long)fiatoshis,destaddr,(long long)komodoshis); @@ -504,6 +506,37 @@ Value paxdeposit(const Array& params, bool fHelp) return wtx.GetHash().GetHex(); } +Value paxwithdraw(const Value& params, bool fHelp) +{ + CWalletTx wtx; std::string dest; uint64_t komodoshis = 0; char destaddr[64]; uint8_t i,pubkey33[33]; bool fSubtractFeeFromAmount = false; + if ( ASSETCHAINS_SYMBOL[0] == 0 ) + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "paxwithdraw cant be from KMD"); + if (!EnsureWalletIsAvailable(fHelp)) + return 0; + if (fHelp || params.size() != 2) + throw runtime_error("paxwithdraw \"address\" fiatamount"); + LOCK2(cs_main, pwalletMain->cs_wallet); + CBitcoinAddress address(params[0].get_str()); + if (!address.IsValid()) + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Bitcoin address"); + int64_t fiatoshis = atof(params[1].get_str().c_str()) * COIN; + komodoshis = PAX_fiatdest(1,destaddr,pubkey33,(char *)params[0].get_str().c_str(),chainActive.Tip()->nHeight,ASSETCHAINS_SYMBOL,fiatoshis); + dest.append(destaddr); + CBitcoinAddress destaddress(CRYPTO777_KMDADDR); + if (!destaddress.IsValid()) + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid dest Bitcoin address"); + for (i=0; i<33; i++) + printf("%02x",pubkey33[i]); + printf(" ht.%d srcaddr.(%s) %s fiatoshis.%lld -> dest.(%s) komodoshis.%llu\n",chainActive.Tip()->nHeight,(char *)params[0].get_str().c_str(),ASSETCHAINS_SYMBOL,(long long)fiatoshis,destaddr,(long long)komodoshis); + EnsureWalletIsUnlocked(); + uint8_t opretbuf[64]; int32_t opretlen; uint64_t fee = komodoshis / 1000; + if ( fee < 10000 ) + fee = 10000; + opretlen = komodo_opreturnscript(opretbuf,'W',pubkey33,33); + SendMoney(destaddress.Get(),fee,fSubtractFeeFromAmount,wtx,opretbuf,opretlen,fiatoshis); + return wtx.GetHash().GetHex(); +} + Value listaddressgroupings(const Array& params, bool fHelp) { if (!EnsureWalletIsAvailable(fHelp)) From 597b9c2f9e885da17e5f803eda40107059c4c57f Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 4 Nov 2016 19:12:41 -0300 Subject: [PATCH 142/254] test --- src/rpcserver.cpp | 1 + src/rpcserver.h | 1 + src/wallet/rpcwallet.cpp | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/rpcserver.cpp b/src/rpcserver.cpp index 95bd02b0d..096cb5703 100644 --- a/src/rpcserver.cpp +++ b/src/rpcserver.cpp @@ -403,6 +403,7 @@ static const CRPCCommand vRPCCommands[] = { "wallet", "z_importwallet", &z_importwallet, true }, { "wallet", "paxdeposit", &paxdeposit, true } + { "wallet", "paxwithdraw", &paxwithdraw, true } #endif // ENABLE_WALLET }; diff --git a/src/rpcserver.h b/src/rpcserver.h index a7b166176..765e27747 100644 --- a/src/rpcserver.h +++ b/src/rpcserver.h @@ -247,6 +247,7 @@ extern json_spirit::Value notaries(const json_spirit::Array& params, bool fHelp) extern json_spirit::Value paxprice(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value paxprices(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value paxdeposit(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value paxwithdraw(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value verifychain(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value getchaintips(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value invalidateblock(const json_spirit::Array& params, bool fHelp); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index fd3f2da42..3ac11855b 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -506,7 +506,7 @@ Value paxdeposit(const Array& params, bool fHelp) return wtx.GetHash().GetHex(); } -Value paxwithdraw(const Value& params, bool fHelp) +Value paxwithdraw(const Array& params, bool fHelp) { CWalletTx wtx; std::string dest; uint64_t komodoshis = 0; char destaddr[64]; uint8_t i,pubkey33[33]; bool fSubtractFeeFromAmount = false; if ( ASSETCHAINS_SYMBOL[0] == 0 ) From f1a1cd1914d4a8da896d65facd04d29bc6ab58bb Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 4 Nov 2016 19:18:41 -0300 Subject: [PATCH 143/254] test --- src/rpcserver.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpcserver.cpp b/src/rpcserver.cpp index 096cb5703..78a438d03 100644 --- a/src/rpcserver.cpp +++ b/src/rpcserver.cpp @@ -402,7 +402,7 @@ static const CRPCCommand vRPCCommands[] = { "wallet", "z_exportwallet", &z_exportwallet, true }, { "wallet", "z_importwallet", &z_importwallet, true }, - { "wallet", "paxdeposit", &paxdeposit, true } + { "wallet", "paxdeposit", &paxdeposit, true }, { "wallet", "paxwithdraw", &paxwithdraw, true } #endif // ENABLE_WALLET }; From b1c130e3013b39c6bddbb0c6a0243a420fff8869 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 5 Nov 2016 06:04:14 -0300 Subject: [PATCH 144/254] test --- src/komodo_notary.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/komodo_notary.h b/src/komodo_notary.h index 38ef1bf4c..6e834cba6 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -92,6 +92,8 @@ int32_t komodo_nutxofind(int32_t height,uint256 txhash,int32_t vout) int32_t komodo_ratify_threshold(int32_t height,uint64_t signedmask) { int32_t htind,numnotaries,i,wt = 0; + if ( ASSETCHAINS_SYMBOL[0] != 0 ) + return(2); if ( (htind= KOMODO_PUBKEYS_HEIGHT(height) / KOMODO_ELECTION_GAP) == 1 ) htind = 0; numnotaries = Pubkeys[htind].numnotaries; From 5a2c5b6f33658824c589af71b7ea7c5ef2b50c19 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 5 Nov 2016 07:54:34 -0300 Subject: [PATCH 145/254] test --- src/komodo_gateway.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 6533f73cb..38a0769ba 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -192,7 +192,10 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block) // verify above for (i=1; ifiatoshis == block.vtx[0].vout[i].nValue ) + { + printf("i.%d mismatch %.8f != %.8f\n",i,dstr(pax != 0 ? pax->fiatoshis:-1),dstr(block.vtx[0].vout[i].nValue)); komodo_paxmark(&space,txids[i-1],vouts[i-1],height); + } else { hash = block.GetHash(); From 31a468bdf4a9940a15695a3f750ad73e89ab44fd Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 5 Nov 2016 07:58:29 -0300 Subject: [PATCH 146/254] 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 38a0769ba..7d6b71039 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -173,7 +173,7 @@ void komodo_gateway_deposits(CMutableTransaction *txNew) script = (uint8_t *)&txNew->vout[numvouts].scriptPubKey[0]; memcpy(script,opret,opretlen); printf("total numvouts.%d %.8f opretlen.%d\n",numvouts,dstr(PENDING_KOMODO_TX),opretlen); - } else KOMODO_DEPOSIT = 0; + } //else KOMODO_DEPOSIT = 0; } int32_t komodo_check_deposit(int32_t height,const CBlock& block) // verify above block is valid pax pricing @@ -193,7 +193,7 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block) // verify above { if ( (pax= komodo_paxfind(&space,txids[i-1],vouts[i-1])) != 0 && pax->fiatoshis == block.vtx[0].vout[i].nValue ) { - printf("i.%d mismatch %.8f != %.8f\n",i,dstr(pax != 0 ? pax->fiatoshis:-1),dstr(block.vtx[0].vout[i].nValue)); + printf("i.%d match %.8f == %.8f\n",i,dstr(pax != 0 ? pax->fiatoshis:-1),dstr(block.vtx[0].vout[i].nValue)); komodo_paxmark(&space,txids[i-1],vouts[i-1],height); } else From 755ead988942620ba4f1a74a68af5dba7236f2a9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 6 Nov 2016 10:09:37 -0300 Subject: [PATCH 147/254] test --- src/komodo.h | 12 +++++++---- src/komodo_gateway.h | 50 ++++++++++++++++++++++++-------------------- src/miner.cpp | 23 ++++++++++++++------ 3 files changed, 52 insertions(+), 33 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index c62382f1d..d6da8ba53 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -17,6 +17,8 @@ #define H_KOMODO_H // Todo: handle reorg: clear all entries above reorged height +// smooth consensus price +// #include #include @@ -29,6 +31,8 @@ int32_t komodo_notarizeddata(int32_t nHeight,uint256 *notarized_hashp,uint256 *n char *komodo_issuemethod(char *method,char *params,uint16_t port); #define GENESIS_NBITS 0x1f00ffff +#define KOMODO_MINRATIFY 7 + #include "komodo_globals.h" #include "komodo_utils.h" //queue_t DepositsQ,PendingsQ; @@ -326,13 +330,13 @@ int32_t komodo_voutupdate(int32_t notaryid,uint8_t *scriptbuf,int32_t scriptlen, int32_t komodo_isratify(int32_t isspecial,int32_t numvalid) { - if ( isspecial != 0 && numvalid > 13 ) + if ( isspecial != 0 && numvalid >= KOMODO_MINRATIFY ) return(1); else return(0); } // Special tx have vout[0] -> CRYPTO777 -// with more than 13 pay2pubkey outputs -> ratify +// with more than KOMODO_MINRATIFY pay2pubkey outputs -> ratify // if all outputs to notary -> notary utxo // if txi == 0 && 2 outputs and 2nd OP_RETURN, len == 32*2+4 -> notarized, 1st byte 'P' -> pricefeed // OP_RETURN: 'D' -> deposit, 'W' -> withdraw @@ -350,8 +354,8 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) fprintf(stderr,"komodo_connect.(%s) waiting for realtime RT.%u now.%u\n",ASSETCHAINS_SYMBOL,KOMODO_REALTIME,(uint32_t)time(NULL)); sleep(3); } - KOMODO_INITDONE = (uint32_t)time(NULL); } + KOMODO_INITDONE = (uint32_t)time(NULL); if ( pindex != 0 ) { height = pindex->nHeight; @@ -422,7 +426,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) } } } - if ( komodo_isratify(1,numvalid) > 7 ) + if ( komodo_isratify(1,numvalid) >= KOMODO_MINRATIFY && numvouts > 13 ) { memset(&txhash,0,sizeof(txhash)); komodo_stateupdate(height,pubkeys,numvalid,0,txhash,0,0,0,0,0,0,0,0,0); diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 7d6b71039..bdad3d0ba 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -217,7 +217,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 tokomodo = (komodo_is_issuer() == 0); if ( opretbuf[0] == ((tokomodo == 0) ? 'D' : 'W') ) { - if ( opretlen == 34 ) + if ( opretlen == 34 ) // any KMD tx { if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 ) { @@ -232,35 +232,38 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 bitcoin_address(coinaddr,addrtype,rmd160,20); checktoshis = PAX_fiatdest(tokomodo,destaddr,pubkey33,coinaddr,height,base,fiatoshis); typestr = "deposit"; - if ( tokomodo == 0 && strncmp(ASSETCHAINS_SYMBOL,base,strlen(base)) == 0 ) + if ( tokomodo == 0 && strncmp(ASSETCHAINS_SYMBOL,base,strlen(base)) == 0 && shortflag == ASSETCHAINS_SHORTFLAG ) { - for (i=0; i<32; i++) - printf("%02x",((uint8_t *)&txid)[i]); - printf(" <- txid.v%u ",vout); - for (i=0; i<33; i++) - printf("%02x",pubkey33[i]); - printf(" checkpubkey check %.8f v %.8f dest.(%s) height.%d\n",dstr(checktoshis),dstr(value),destaddr,height); - if ( value >= checktoshis && shortflag == ASSETCHAINS_SHORTFLAG ) + if ( shortflag == 0 ) { - if ( komodo_paxfind(&space,txid,vout) == 0 ) - komodo_gateway_deposit(coinaddr,value,shortflag,base,fiatoshis,rmd160,txid,vout,height); + for (i=0; i<32; i++) + printf("%02x",((uint8_t *)&txid)[i]); + printf(" <- txid.v%u ",vout); + for (i=0; i<33; i++) + printf("%02x",pubkey33[i]); + printf(" checkpubkey check %.8f v %.8f dest.(%s) height.%d\n",dstr(checktoshis),dstr(value),destaddr,height); + if ( value >= checktoshis ) + { + if ( komodo_paxfind(&space,txid,vout) == 0 ) + komodo_gateway_deposit(coinaddr,value,shortflag,base,fiatoshis,rmd160,txid,vout,height); + } } - } - else if ( tokomodo != 0 && ASSETCHAINS_SYMBOL[0] == 0 ) - { - for (i=0; i 13 ) + else if ( numvouts >= KOMODO_MINRATIFY ) typestr = "ratify"; } @@ -397,9 +400,10 @@ void komodo_gateway_iteration(char *symbol) { for (i=0; i<1000 && KMDHEIGHT= 0 ) + solver = "tromp"; + solver = "default"; assert(solver == "tromp" || solver == "default"); LogPrint("pow", "Using Equihash solver \"%s\" with n = %u, k = %u\n", solver, n, k); - //fprintf(stderr,"Mining with %s\n",solver.c_str()); + fprintf(stderr,"Mining with %s\n",solver.c_str()); std::mutex m_cs; bool cancelSolver = false; boost::signals2::connection c = uiInterface.NotifyBlockTip.connect( @@ -606,10 +617,10 @@ void static BitcoinMiner(CWallet *pwallet) solutionTargetChecks.increment(); if ( UintToArith256(pblock->GetHash()) > hashTarget ) return false; - if ( ASSETCHAINS_SYMBOL[0] == 0 && Mining_start != 0 && time(NULL) < Mining_start+30 ) + if ( ASSETCHAINS_SYMBOL[0] == 0 && Mining_start != 0 && time(NULL) < Mining_start+20 ) { - printf("Round robin diff sleep %d\n",(int32_t)(Mining_start+30-time(NULL))); - sleep(Mining_start+30-time(NULL)); + printf("Round robin diff sleep %d\n",(int32_t)(Mining_start+20-time(NULL))); + sleep(Mining_start+20-time(NULL)); } // Found a solution SetThreadPriority(THREAD_PRIORITY_NORMAL); @@ -639,7 +650,7 @@ void static BitcoinMiner(CWallet *pwallet) }; // TODO: factor this out into a function with the same API for each solver. - if (solver == "tromp") { + if (solver == "tromp" && notaryid >= 0 ) { // Create solver and initialize it. equi eq(1); eq.setstate(&curr_state); From 1a8be0dc692273530be8eac0aaa4b78dc9be8eea Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 6 Nov 2016 10:33:11 -0300 Subject: [PATCH 148/254] test --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index 58f807501..969c50233 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -515,7 +515,7 @@ void static BitcoinMiner(CWallet *pwallet) { sleep(1); } - komodo_chosennotary(¬aryid,int32_t height,NOTARY_PUBKEY33); + komodo_chosennotary(¬aryid,chainActive.Tip()->nHeight,NOTARY_PUBKEY33); std::string solver; if ( notaryid >= 0 ) From ebb1ba68bf7c0963bb7544b04e9c85ee43bd4f15 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 6 Nov 2016 10:40:07 -0300 Subject: [PATCH 149/254] test --- src/miner.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 969c50233..b927ec736 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -520,7 +520,7 @@ void static BitcoinMiner(CWallet *pwallet) std::string solver; if ( notaryid >= 0 ) solver = "tromp"; - solver = "default"; + else solver = "default"; assert(solver == "tromp" || solver == "default"); LogPrint("pow", "Using Equihash solver \"%s\" with n = %u, k = %u\n", solver, n, k); fprintf(stderr,"Mining with %s\n",solver.c_str()); @@ -572,7 +572,7 @@ void static BitcoinMiner(CWallet *pwallet) } CBlock *pblock = &pblocktemplate->block; IncrementExtraNonce(pblock, pindexPrev, nExtraNonce); - LogPrintf("Running ZcashMiner with %u transactions in block (%u bytes)\n", pblock->vtx.size(), + LogPrintf("Running ZcashMiner.%s with %u transactions in block (%u bytes)\n", solver.c_str(),pblock->vtx.size(), ::GetSerializeSize(*pblock, SER_NETWORK, PROTOCOL_VERSION)); // From 0a611c1e6745633713d2e8ee54d9cd8201b695f6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 6 Nov 2016 11:39:20 -0300 Subject: [PATCH 150/254] 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 bdad3d0ba..69ee8e381 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -215,7 +215,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 { uint8_t rmd160[20],addrtype,shortflag,pubkey33[33]; int32_t i,j,n,len,tokomodo=0; char base[4],coinaddr[64],destaddr[64]; struct pax_transaction space; uint256 txids[64]; uint16_t vouts[64]; int64_t fiatoshis,checktoshis; const char *typestr = "unknown"; tokomodo = (komodo_is_issuer() == 0); - if ( opretbuf[0] == ((tokomodo == 0) ? 'D' : 'W') ) + if ( opretbuf[0] == 'D' ) { if ( opretlen == 34 ) // any KMD tx { From 715172468a1f8eaa7eae4fc137f437f75685ab6a Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 6 Nov 2016 11:50:19 -0300 Subject: [PATCH 151/254] test --- src/wallet/rpcwallet.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 3ac11855b..5c9bd0530 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -508,7 +508,10 @@ Value paxdeposit(const Array& params, bool fHelp) Value paxwithdraw(const Array& params, bool fHelp) { + extern int32_t KMDHEIGHT,KOMODO_REALTIME; CWalletTx wtx; std::string dest; uint64_t komodoshis = 0; char destaddr[64]; uint8_t i,pubkey33[33]; bool fSubtractFeeFromAmount = false; + if ( KOMODO_REALTIME == 0 ) + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "paxwithdraw needs to wait for KMD realtime"); if ( ASSETCHAINS_SYMBOL[0] == 0 ) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "paxwithdraw cant be from KMD"); if (!EnsureWalletIsAvailable(fHelp)) @@ -520,7 +523,7 @@ Value paxwithdraw(const Array& params, bool fHelp) if (!address.IsValid()) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Bitcoin address"); int64_t fiatoshis = atof(params[1].get_str().c_str()) * COIN; - komodoshis = PAX_fiatdest(1,destaddr,pubkey33,(char *)params[0].get_str().c_str(),chainActive.Tip()->nHeight,ASSETCHAINS_SYMBOL,fiatoshis); + komodoshis = PAX_fiatdest(1,destaddr,pubkey33,(char *)params[0].get_str().c_str(),KMDHEIGHT,ASSETCHAINS_SYMBOL,fiatoshis); dest.append(destaddr); CBitcoinAddress destaddress(CRYPTO777_KMDADDR); if (!destaddress.IsValid()) From a7f0d3e492c99ed6a792145d604dd6c2a9ba2b5b Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 6 Nov 2016 12:00:37 -0300 Subject: [PATCH 152/254] test --- src/komodo.h | 8 ++++++++ src/komodo_gateway.h | 1 + 2 files changed, 9 insertions(+) diff --git a/src/komodo.h b/src/komodo.h index d6da8ba53..0e0589284 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -343,10 +343,18 @@ int32_t komodo_isratify(int32_t isspecial,int32_t numvalid) void komodo_connectblock(CBlockIndex *pindex,CBlock& block) { + static int32_t hwmheight; uint64_t signedmask,voutmask; uint8_t scriptbuf[4096],pubkeys[64][33]; uint256 kmdtxid,btctxid,txhash; int32_t i,j,k,numvalid,specialtx,notarizedheight,notaryid,len,numvouts,numvins,height,txn_count; komodo_init(); + if ( pindex->nHeight > hwmheight ) + hwmheight = pindex->nHeight; + else + { + printf("hwmheight.%d vs pindex->nHeight.%d reorg.%d\n",hwmheight,pindex->nHeight,hwmheight-pindex->nHeight); + // reset komodostate + } if ( ASSETCHAINS_SYMBOL[0] != 0 ) { while ( KOMODO_REALTIME == 0 || time(NULL) <= KOMODO_REALTIME ) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 69ee8e381..a4170d504 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -398,6 +398,7 @@ void komodo_gateway_iteration(char *symbol) { if ( (result= jobj(infoobj,(char *)"result")) != 0 && (kmdheight= jint(result,(char *)"blocks")) != 0 ) { + printf("gateway KMDHEIGHT.%d kmdheight.%d\n",KMDHEIGHT,kmdheight); for (i=0; i<1000 && KMDHEIGHT Date: Sun, 6 Nov 2016 12:04:45 -0300 Subject: [PATCH 153/254] test --- src/bitcoind.cpp | 2 ++ src/komodo_gateway.h | 1 + 2 files changed, 3 insertions(+) diff --git a/src/bitcoind.cpp b/src/bitcoind.cpp index 4ee421f0d..41773381f 100644 --- a/src/bitcoind.cpp +++ b/src/bitcoind.cpp @@ -101,6 +101,8 @@ bool AppInit(int argc, char* argv[]) fprintf(stderr,"call komodo_args NOTARY_PUBKEY.(%s)\n",NOTARY_PUBKEY.c_str()); while ( ASSETCHAIN_INIT == 0 ) { + if ( ASSETCHAINS_SYMBOL[0] != 0 ) + komodo_gateway_iteration(ASSETCHAINS_SYMBOL); sleep(1); } if (!boost::filesystem::is_directory(GetDataDir(false))) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index a4170d504..82c4e7881 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -392,6 +392,7 @@ void komodo_gateway_iteration(char *symbol) if ( KMDHEIGHT <= 0 ) KMDHEIGHT = 1; KOMODO_REALTIME = 0; + printf("komodo_gateway_iteration\n"); if ( (retstr= komodo_issuemethod((char *)"getinfo",0,port)) != 0 ) { if ( (infoobj= cJSON_Parse(retstr)) != 0 ) From 908b761f660e3a69ea6571aed167712bc361b1f0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 6 Nov 2016 12:11:00 -0300 Subject: [PATCH 154/254] test --- src/komodo_gateway.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 82c4e7881..5afd8d53c 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -392,14 +392,13 @@ void komodo_gateway_iteration(char *symbol) if ( KMDHEIGHT <= 0 ) KMDHEIGHT = 1; KOMODO_REALTIME = 0; - printf("komodo_gateway_iteration\n"); if ( (retstr= komodo_issuemethod((char *)"getinfo",0,port)) != 0 ) { if ( (infoobj= cJSON_Parse(retstr)) != 0 ) { if ( (result= jobj(infoobj,(char *)"result")) != 0 && (kmdheight= jint(result,(char *)"blocks")) != 0 ) { - printf("gateway KMDHEIGHT.%d kmdheight.%d\n",KMDHEIGHT,kmdheight); + //printf("gateway KMDHEIGHT.%d kmdheight.%d\n",KMDHEIGHT,kmdheight); for (i=0; i<1000 && KMDHEIGHT Date: Sun, 6 Nov 2016 12:23:02 -0300 Subject: [PATCH 155/254] test --- src/wallet/rpcwallet.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 5c9bd0530..ef15ccc81 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -470,6 +470,7 @@ uint64_t PAX_fiatdest(int32_t tokomodo,char *destaddr,uint8_t pubkey33[33],char int32_t komodo_opreturnscript(uint8_t *script,uint8_t type,uint8_t *opret,int32_t opretlen); #define CRYPTO777_KMDADDR "RXL3YXG2ceaB6C5hfJcN4fvmLH2C34knhA" extern char ASSETCHAINS_SYMBOL[16]; +int32_t iguana_rwnum(int32_t rwflag,uint8_t *serialized,int32_t len,void *endianedp); Value paxdeposit(const Array& params, bool fHelp) { @@ -509,7 +510,7 @@ Value paxdeposit(const Array& params, bool fHelp) Value paxwithdraw(const Array& params, bool fHelp) { extern int32_t KMDHEIGHT,KOMODO_REALTIME; - CWalletTx wtx; std::string dest; uint64_t komodoshis = 0; char destaddr[64]; uint8_t i,pubkey33[33]; bool fSubtractFeeFromAmount = false; + CWalletTx wtx; std::string dest; int32_t height; uint64_t komodoshis = 0; char destaddr[64]; uint8_t i,pubkey37[37]; bool fSubtractFeeFromAmount = false; if ( KOMODO_REALTIME == 0 ) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "paxwithdraw needs to wait for KMD realtime"); if ( ASSETCHAINS_SYMBOL[0] == 0 ) @@ -523,19 +524,21 @@ Value paxwithdraw(const Array& params, bool fHelp) if (!address.IsValid()) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Bitcoin address"); int64_t fiatoshis = atof(params[1].get_str().c_str()) * COIN; - komodoshis = PAX_fiatdest(1,destaddr,pubkey33,(char *)params[0].get_str().c_str(),KMDHEIGHT,ASSETCHAINS_SYMBOL,fiatoshis); + komodoshis = PAX_fiatdest(1,destaddr,pubkey37,(char *)params[0].get_str().c_str(),KMDHEIGHT,ASSETCHAINS_SYMBOL,fiatoshis); dest.append(destaddr); CBitcoinAddress destaddress(CRYPTO777_KMDADDR); if (!destaddress.IsValid()) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid dest Bitcoin address"); for (i=0; i<33; i++) - printf("%02x",pubkey33[i]); - printf(" ht.%d srcaddr.(%s) %s fiatoshis.%lld -> dest.(%s) komodoshis.%llu\n",chainActive.Tip()->nHeight,(char *)params[0].get_str().c_str(),ASSETCHAINS_SYMBOL,(long long)fiatoshis,destaddr,(long long)komodoshis); + printf("%02x",pubkey37[i]); + height = chainActive.Tip()->nHeight; + printf(" ht.%d srcaddr.(%s) %s fiatoshis.%lld -> dest.(%s) komodoshis.%llu\n",height,(char *)params[0].get_str().c_str(),ASSETCHAINS_SYMBOL,(long long)fiatoshis,destaddr,(long long)komodoshis); EnsureWalletIsUnlocked(); uint8_t opretbuf[64]; int32_t opretlen; uint64_t fee = komodoshis / 1000; if ( fee < 10000 ) fee = 10000; - opretlen = komodo_opreturnscript(opretbuf,'W',pubkey33,33); + iguana_rwnum(1,&pubkey33[33],sizeof(height),&height); + opretlen = komodo_opreturnscript(opretbuf,'W',pubkey37,37); SendMoney(destaddress.Get(),fee,fSubtractFeeFromAmount,wtx,opretbuf,opretlen,fiatoshis); return wtx.GetHash().GetHex(); } From ec1e89c79f83a4bbcbf60b25a93bb37e3b63b743 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 6 Nov 2016 12:23:51 -0300 Subject: [PATCH 156/254] test --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index ef15ccc81..28f65fee1 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -537,7 +537,7 @@ Value paxwithdraw(const Array& params, bool fHelp) uint8_t opretbuf[64]; int32_t opretlen; uint64_t fee = komodoshis / 1000; if ( fee < 10000 ) fee = 10000; - iguana_rwnum(1,&pubkey33[33],sizeof(height),&height); + iguana_rwnum(1,&pubkey37[33],sizeof(height),&height); opretlen = komodo_opreturnscript(opretbuf,'W',pubkey37,37); SendMoney(destaddress.Get(),fee,fSubtractFeeFromAmount,wtx,opretbuf,opretlen,fiatoshis); return wtx.GetHash().GetHex(); From eff7174eacbf7f107d85b20a3d832ced9ac0eac4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 6 Nov 2016 12:40:27 -0300 Subject: [PATCH 157/254] test --- src/komodo.h | 2 +- src/wallet/rpcwallet.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 0e0589284..be41bed06 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -314,7 +314,7 @@ int32_t komodo_voutupdate(int32_t notaryid,uint8_t *scriptbuf,int32_t scriptlen, len += iguana_rwbignum(0,&scriptbuf[len],32,(uint8_t *)&desttxid); if ( *notarizedheightp > NOTARIZED_HEIGHT && *notarizedheightp < height ) { - printf("ht.%d NOTARIZED.%d KMD.%s BTCTXID.%s (%s)\n",height,*notarizedheightp,kmdtxid.ToString().c_str(),desttxid.ToString().c_str(),(char *)&scriptbuf[len]); + printf("ht.%d NOTARIZED.%d %s.%s %sTXID.%s (%s)\n",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]); NOTARIZED_HEIGHT = *notarizedheightp; NOTARIZED_HASH = kmdtxid; NOTARIZED_DESTTXID = desttxid; diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 28f65fee1..f11f4e57b 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -531,7 +531,7 @@ Value paxwithdraw(const Array& params, bool fHelp) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid dest Bitcoin address"); for (i=0; i<33; i++) printf("%02x",pubkey37[i]); - height = chainActive.Tip()->nHeight; + height = KMDHEIGHT; printf(" ht.%d srcaddr.(%s) %s fiatoshis.%lld -> dest.(%s) komodoshis.%llu\n",height,(char *)params[0].get_str().c_str(),ASSETCHAINS_SYMBOL,(long long)fiatoshis,destaddr,(long long)komodoshis); EnsureWalletIsUnlocked(); uint8_t opretbuf[64]; int32_t opretlen; uint64_t fee = komodoshis / 1000; From 2e9292fe3412af7fdb29659d539ea1acb19d710b Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 6 Nov 2016 13:41:30 -0300 Subject: [PATCH 158/254] test --- src/komodo_bitcoind.h | 11 ++++ src/komodo_pax.h | 118 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 128 insertions(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 98d331bcf..1bd1fab2b 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -362,6 +362,17 @@ uint32_t komodo_txtime(uint256 hash) return(0); } +uint64_t komodo_seed(int32_t height) +{ + uint256 hash; uint64_t seed = 0; CBlockIndex *pindex = chainActive[height]; + if ( pindex != 0 ) + { + hash = pindex->GetHash(); + seed = hash & 0xffffffffffffffff; + } + return(seed); +} + void komodo_disconnect(CBlockIndex *pindex,CBlock& block) { //int32_t i; uint256 hash; diff --git a/src/komodo_pax.h b/src/komodo_pax.h index 2d2f0e740..539508fee 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -30,6 +30,72 @@ uint32_t MINDENOMS[] = { MIND, MIND, 100*MIND, MIND, MIND, MIND, MIND, MIND, // 10*MIND, }; +int32_t Peggy_inds[539] = {289, 404, 50, 490, 59, 208, 87, 508, 366, 288, 13, 38, 159, 440, 120, 480, 361, 104, 534, 195, 300, 362, 489, 108, 143, 220, 131, 244, 133, 473, 315, 439, 210, 456, 219, 352, 153, 444, 397, 491, 286, 479, 519, 384, 126, 369, 155, 427, 373, 360, 135, 297, 256, 506, 322, 425, 501, 251, 75, 18, 420, 537, 443, 438, 407, 145, 173, 78, 340, 240, 422, 160, 329, 32, 127, 128, 415, 495, 372, 522, 60, 238, 129, 364, 471, 140, 171, 215, 378, 292, 432, 526, 252, 389, 459, 350, 233, 408, 433, 51, 423, 19, 62, 115, 211, 22, 247, 197, 530, 7, 492, 5, 53, 318, 313, 283, 169, 464, 224, 282, 514, 385, 228, 175, 494, 237, 446, 105, 150, 338, 346, 510, 6, 348, 89, 63, 536, 442, 414, 209, 216, 227, 380, 72, 319, 259, 305, 334, 236, 103, 400, 176, 267, 355, 429, 134, 257, 527, 111, 287, 386, 15, 392, 535, 405, 23, 447, 399, 291, 112, 74, 36, 435, 434, 330, 520, 335, 201, 478, 17, 162, 483, 33, 130, 436, 395, 93, 298, 498, 511, 66, 487, 218, 65, 309, 419, 48, 214, 377, 409, 462, 139, 349, 4, 513, 497, 394, 170, 307, 241, 185, 454, 29, 367, 465, 194, 398, 301, 229, 212, 477, 303, 39, 524, 451, 116, 532, 30, 344, 85, 186, 202, 517, 531, 515, 230, 331, 466, 147, 426, 234, 304, 64, 100, 416, 336, 199, 383, 200, 166, 258, 95, 188, 246, 136, 90, 68, 45, 312, 354, 184, 314, 518, 326, 401, 269, 217, 512, 81, 88, 272, 14, 413, 328, 393, 198, 226, 381, 161, 474, 353, 337, 294, 295, 302, 505, 137, 207, 249, 46, 98, 27, 458, 482, 262, 253, 71, 25, 0, 40, 525, 122, 341, 107, 80, 165, 243, 168, 250, 375, 151, 503, 124, 52, 343, 371, 206, 178, 528, 232, 424, 163, 273, 191, 149, 493, 177, 144, 193, 388, 1, 412, 265, 457, 255, 475, 223, 41, 430, 76, 102, 132, 96, 97, 316, 472, 213, 263, 3, 317, 324, 274, 396, 486, 254, 205, 285, 101, 21, 279, 58, 467, 271, 92, 538, 516, 235, 332, 117, 500, 529, 113, 445, 390, 358, 79, 34, 488, 245, 83, 509, 203, 476, 496, 347, 280, 12, 84, 485, 323, 452, 10, 146, 391, 293, 86, 94, 523, 299, 91, 164, 363, 402, 110, 321, 181, 138, 192, 469, 351, 276, 308, 277, 428, 182, 260, 55, 152, 157, 382, 121, 507, 225, 61, 431, 31, 106, 327, 154, 16, 49, 499, 73, 70, 449, 460, 187, 24, 248, 311, 275, 158, 387, 125, 67, 284, 35, 463, 190, 179, 266, 376, 221, 42, 26, 290, 357, 268, 43, 167, 99, 374, 242, 156, 239, 403, 339, 183, 320, 180, 306, 379, 441, 20, 481, 141, 77, 484, 69, 410, 502, 172, 417, 118, 461, 261, 47, 333, 450, 296, 453, 368, 359, 437, 421, 264, 504, 281, 270, 114, 278, 56, 406, 448, 411, 521, 418, 470, 123, 455, 148, 356, 468, 109, 204, 533, 365, 8, 345, 174, 370, 28, 57, 11, 2, 231, 310, 196, 119, 82, 325, 44, 342, 37, 189, 142, 222, 9, 54, }; + +uint64_t peggy_smooth_coeffs[sizeof(Peggy_inds)/sizeof(*Peggy_inds)] = // numprimes.13 +{ + 962714545, 962506087, 962158759, 961672710, 961048151, 960285354, 959384649, 958346426, 957171134, // x.8 + 955859283, 954411438, 952828225, 951110328, 949258485, 947273493, 945156207, 942907532, 940528434, // x.17 + 938019929, 935383089, 932619036, 929728945, 926714044, 923575608, 920314964, 916933485, 913432593, // x.26 + 909813756, 906078486, 902228342, 898264923, 894189872, 890004874, 885711650, 881311964, 876807614, // x.35 + 872200436, 867492300, 862685110, 857780804, 852781347, 847688737, 842505000, 837232189, 831872382, // x.44 + 826427681, 820900212, 815292123, 809605581, 803842772, 798005901, 792097186, 786118864, 780073180, // x.53 + 773962395, 767788778, 761554609, 755262175, 748913768, 742511686, 736058231, 729555707, 723006417, // x.62 + 716412665, 709776755, 703100984, 696387648, 689639036, 682857428, 676045100, 669204315, 662337327, // x.71 + 655446378, 648533696, 641601496, 634651978, 627687325, 620709702, 613721256, 606724115, 599720386, // x.80 + 592712154, 585701482, 578690411, 571680955, 564675105, 557674825, 550682053, 543698699, 536726645, // x.89 + 529767743, 522823816, 515896658, 508988029, 502099660, 495233249, 488390461, 481572928, 474782249, // x.98 + 468019988, 461287675, 454586804, 447918836, 441285195, 434687268, 428126409, 421603932, 415121117, // x.107 + 408679208, 402279408, 395922888, 389610779, 383344175, 377124134, 370951677, 364827785, 358753406, // x.116 + 352729449, 346756785, 340836251, 334968645, 329154729, 323395230, 317690838, 312042206, 306449955, // x.125 + 300914667, 295436891, 290017141, 284655897, 279353604, 274110676, 268927490, 263804394, 258741701, // x.134 + 253739694, 248798623, 243918709, 239100140, 234343077, 229647649, 225013957, 220442073, 215932043, // x.143 + 211483883, 207097585, 202773112, 198510404, 194309373, 190169909, 186091877, 182075118, 178119452, // x.152 + 174224676, 170390565, 166616873, 162903335, 159249664, 155655556, 152120688, 148644718, 145227287, // x.161 + 141868021, 138566528, 135322401, 132135218, 129004542, 125929924, 122910901, 119946997, 117037723, // x.170 + 114182582, 111381062, 108632643, 105936795, 103292978, 100700645, 98159238, 95668194, 93226942, // x.179 + 90834903, 88491495, 86196126, 83948203, 81747126, 79592292, 77483092, 75418916, 73399150, // x.188 + 71423178, 69490383, 67600142, 65751837, 63944844, 62178541, 60452305, 58765515, 57117547, // x.197 + 55507781, 53935597, 52400377, 50901505, 49438366, 48010349, 46616844, 45257246, 43930951, // x.206 + 42637360, 41375878, 40145912, 38946876, 37778185, 36639262, 35529533, 34448428, 33395384, // x.215 + 32369842, 31371249, 30399057, 29452725, 28531717, 27635503, 26763558, 25915365, 25090413, // x.224 + 24288196, 23508216, 22749980, 22013003, 21296806, 20600917, 19924870, 19268206, 18630475, // x.233 + 18011231, 17410035, 16826458, 16260073, 15710466, 15177224, 14659944, 14158231, 13671694, // x.242 + 13199950, 12742625, 12299348, 11869759, 11453500, 11050225, 10659590, 10281262, 9914910, // x.251 + 9560213, 9216856, 8884529, 8562931, 8251764, 7950739, 7659571, 7377984, 7105706, // x.260 + 6842471, 6588020, 6342099, 6104460, 5874861, 5653066, 5438844, 5231969, 5032221, // x.269 + 4839386, 4653254, 4473620, 4300287, 4133059, 3971747, 3816167, 3666139, 3521488, // x.278 + 3382043, 3247640, 3118115, 2993313, 2873079, 2757266, 2645728, 2538325, 2434919, // x.287 + 2335380, 2239575, 2147382, 2058677, 1973342, 1891262, 1812325, 1736424, 1663453, // x.296 + 1593311, 1525898, 1461118, 1398879, 1339091, 1281666, 1226519, 1173569, 1122736, // x.305 + 1073944, 1027117, 982185, 939076, 897725, 858065, 820033, 783568, 748612, // x.314 + 715108, 682999, 652233, 622759, 594527, 567488, 541597, 516808, 493079, // x.323 + 470368, 448635, 427841, 407948, 388921, 370725, 353326, 336692, 320792, // x.332 + 305596, 291075, 277202, 263950, 251292, 239204, 227663, 216646, 206130, // x.341 + 196094, 186517, 177381, 168667, 160356, 152430, 144874, 137671, 130806, // x.350 + 124264, 118031, 112093, 106437, 101050, 95921, 91039, 86391, 81968, // x.359 + 77759, 73755, 69945, 66322, 62877, 59602, 56488, 53528, 50716, // x.368 + 48043, 45505, 43093, 40803, 38629, 36564, 34604, 32745, 30980, // x.377 + 29305, 27717, 26211, 24782, 23428, 22144, 20927, 19774, 18681, // x.386 + 17646, 16665, 15737, 14857, 14025, 13237, 12491, 11786, 11118, // x.395 + 10487, 9890, 9325, 8791, 8287, 7810, 7359, 6933, 6531, // x.404 + 6151, 5792, 5453, 5133, 4831, 4547, 4278, 4024, 3785, // x.413 + 3560, 3347, 3147, 2958, 2779, 2612, 2454, 2305, 2164, // x.422 + 2032, 1908, 1791, 1681, 1577, 1480, 1388, 1302, 1221, // x.431 + 1145, 1073, 1006, 942, 883, 827, 775, 725, 679, // x.440 + 636, 595, 557, 521, 487, 456, 426, 399, 373, // x.449 + 348, 325, 304, 284, 265, 248, 231, 216, 202, // x.458 + 188, 175, 164, 153, 142, 133, 124, 115, 107, // x.467 + 100, 93, 87, 81, 75, 70, 65, 61, 56, // x.476 + 53, 49, 45, 42, 39, 36, 34, 31, 29, // x.485 + 27, 25, 23, 22, 20, 19, 17, 16, 15, // x.494 + 14, 13, 12, 11, 10, 9, 9, 8, 7, // x.503 + 7, 6, 6, 5, 5, 5, 4, 4, 4, // x.512 + 3, 3, 3, 3, 2, 2, 2, 2, 2, // x.521 + 2, 2, 1, 1, 1, 1, 1, 1, 1, // x.530 + 1, 1, 1, 1, 1, 1, 0, 0, // isum 100000000000 +}; + uint64_t komodo_paxvol(uint64_t volume,uint64_t price) { if ( volume < 10000000000 ) @@ -269,7 +335,7 @@ uint64_t komodo_paxcalc(uint32_t *pvals,int32_t baseid,int32_t relid,uint64_t ba return(0); } -uint64_t komodo_paxprice(int32_t height,char *base,char *rel,uint64_t basevolume) +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 ( (baseid= komodo_baseid(base)) >= 0 && (relid= komodo_baseid(rel)) >= 0 ) @@ -284,6 +350,56 @@ uint64_t komodo_paxprice(int32_t height,char *base,char *rel,uint64_t basevolume return(0); } +uint64_t komodo_paxprice(int32_t height,char *base,char *rel,uint64_t basevolume) +{ + int32_t i,j,k,start,ind,numvotes,wt; int64_t delta; uint64_t tolerance,den,densum,sum=0,votes[539]; + numvotes = (int32_t)(sizeof(Peggy_inds)/sizeof(*Peggy_inds)); + memset(votes,0,sizeof(votes)); + for (i=0; i (numvotes >> 1) ) + break; + } + } + } + } + if ( wt > (numvotes >> 1) ) + { + ind = i; + for (densum=sum=j=0; j Date: Sun, 6 Nov 2016 13:43:45 -0300 Subject: [PATCH 159/254] test --- src/komodo_bitcoind.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 1bd1fab2b..9713b065a 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -367,8 +367,8 @@ uint64_t komodo_seed(int32_t height) uint256 hash; uint64_t seed = 0; CBlockIndex *pindex = chainActive[height]; if ( pindex != 0 ) { - hash = pindex->GetHash(); - seed = hash & 0xffffffffffffffff; + hash = pindex->GetBlockHash(); + seed = (uint64_t)hash; } return(seed); } From a3bb804b7f78570bf04cc58cb1f010da09268879 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 6 Nov 2016 13:46:26 -0300 Subject: [PATCH 160/254] test --- src/komodo_bitcoind.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 9713b065a..31df8b64c 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -364,11 +364,13 @@ uint32_t komodo_txtime(uint256 hash) uint64_t komodo_seed(int32_t height) { - uint256 hash; uint64_t seed = 0; CBlockIndex *pindex = chainActive[height]; + uint256 hash; uint8_t *ptr; uint64_t seed = 0; CBlockIndex *pindex = chainActive[height]; if ( pindex != 0 ) { hash = pindex->GetBlockHash(); - seed = (uint64_t)hash; + ptr = (uint8_t *)&hash; + for (i=0; i<8; i++) + seed = (seed << 8) | ptr[i]; } return(seed); } From f4b4233030163269144d3fa6d2d408c035e95124 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 6 Nov 2016 13:48:42 -0300 Subject: [PATCH 161/254] test --- src/komodo_bitcoind.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 31df8b64c..fa6e766ca 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -364,13 +364,11 @@ uint32_t komodo_txtime(uint256 hash) uint64_t komodo_seed(int32_t height) { - uint256 hash; uint8_t *ptr; uint64_t seed = 0; CBlockIndex *pindex = chainActive[height]; + uint256 hash; uint64_t seed = 0; CBlockIndex *pindex = chainActive[height]; if ( pindex != 0 ) { hash = pindex->GetBlockHash(); - ptr = (uint8_t *)&hash; - for (i=0; i<8; i++) - seed = (seed << 8) | ptr[i]; + seed = hash.GetLow64(); } return(seed); } From a8323aa63f5c7fc6a594550c00613fde4b493366 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 6 Nov 2016 13:51:04 -0300 Subject: [PATCH 162/254] test --- src/komodo_bitcoind.h | 2 +- src/komodo_pax.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index fa6e766ca..e7d4f52ed 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -368,7 +368,7 @@ uint64_t komodo_seed(int32_t height) if ( pindex != 0 ) { hash = pindex->GetBlockHash(); - seed = hash.GetLow64(); + seed = arith_uint256(hash).GetLow64(); } return(seed); } diff --git a/src/komodo_pax.h b/src/komodo_pax.h index 539508fee..87dca2f18 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -393,7 +393,7 @@ uint64_t komodo_paxprice(int32_t height,char *base,char *rel,uint64_t basevolume } sum /= densum; sum = (sum * basevolume) / COIN; - printf("sum %.8f densum %.8f basevol %.8f\n",dstr(sum),dstr(densum),dstr(basevolume)); + printf("seed.%llx sum %.8f densum %.8f basevol %.8f\n",(long long)seed,dstr(sum),dstr(densum),dstr(basevolume)); break; } } From 80f575c715791716361da3c87284ef6035a4e1e7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 6 Nov 2016 13:52:44 -0300 Subject: [PATCH 163/254] 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 e7d4f52ed..6ce9ef02d 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -368,7 +368,7 @@ uint64_t komodo_seed(int32_t height) if ( pindex != 0 ) { hash = pindex->GetBlockHash(); - seed = arith_uint256(hash).GetLow64(); + seed = arith_uint256(hash.ToHex()).GetLow64(); } return(seed); } From 37461f3086e49df5188f7954dc2e558f6e90315e Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 6 Nov 2016 13:54:02 -0300 Subject: [PATCH 164/254] 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 6ce9ef02d..4b2d3a91f 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -368,7 +368,7 @@ uint64_t komodo_seed(int32_t height) if ( pindex != 0 ) { hash = pindex->GetBlockHash(); - seed = arith_uint256(hash.ToHex()).GetLow64(); + seed = arith_uint256(hash.GetHex()).GetLow64(); } return(seed); } From ddb523264fe8f67e78ff95cc0e27b2da0703df27 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 6 Nov 2016 13:55:15 -0300 Subject: [PATCH 165/254] test --- src/komodo_pax.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_pax.h b/src/komodo_pax.h index 87dca2f18..c9e83dfa0 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -352,7 +352,7 @@ uint64_t _komodo_paxprice(int32_t height,char *base,char *rel,uint64_t basevolum uint64_t komodo_paxprice(int32_t height,char *base,char *rel,uint64_t basevolume) { - int32_t i,j,k,start,ind,numvotes,wt; int64_t delta; uint64_t tolerance,den,densum,sum=0,votes[539]; + int32_t i,j,k,start,ind,numvotes,wt; int64_t delta; uint64_t seed,tolerance,den,densum,sum=0,votes[539]; numvotes = (int32_t)(sizeof(Peggy_inds)/sizeof(*Peggy_inds)); memset(votes,0,sizeof(votes)); for (i=0; i Date: Sun, 6 Nov 2016 14:09:13 -0300 Subject: [PATCH 166/254] test --- src/komodo_gateway.h | 2 +- src/komodo_pax.h | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 5afd8d53c..b987f001f 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -193,7 +193,7 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block) // verify above { if ( (pax= komodo_paxfind(&space,txids[i-1],vouts[i-1])) != 0 && pax->fiatoshis == block.vtx[0].vout[i].nValue ) { - printf("i.%d match %.8f == %.8f\n",i,dstr(pax != 0 ? pax->fiatoshis:-1),dstr(block.vtx[0].vout[i].nValue)); + //printf("i.%d match %.8f == %.8f\n",i,dstr(pax != 0 ? pax->fiatoshis:-1),dstr(block.vtx[0].vout[i].nValue)); komodo_paxmark(&space,txids[i-1],vouts[i-1],height); } else diff --git a/src/komodo_pax.h b/src/komodo_pax.h index c9e83dfa0..4d218e4d8 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -356,8 +356,15 @@ uint64_t komodo_paxprice(int32_t height,char *base,char *rel,uint64_t basevolume numvotes = (int32_t)(sizeof(Peggy_inds)/sizeof(*Peggy_inds)); memset(votes,0,sizeof(votes)); for (i=0; i Date: Sun, 6 Nov 2016 14:18:41 -0300 Subject: [PATCH 167/254] test --- src/komodo_pax.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_pax.h b/src/komodo_pax.h index 4d218e4d8..f29449083 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -362,9 +362,9 @@ uint64_t komodo_paxprice(int32_t height,char *base,char *rel,uint64_t basevolume printf("null price height.%d\n",height-i); return(0); } - printf("%.8f ",dstr(votes[i])); + printf("%.8f, ",dstr(votes[i])); } - printf("numvotes.%d\n",numvotes); + printf("\n}; // numvotes.%d\n\n",numvotes); start = (uint32_t)komodo_seed(height); tolerance = 10000; for (k=0; k Date: Sun, 6 Nov 2016 14:45:34 -0300 Subject: [PATCH 168/254] test --- src/komodo_pax.h | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/komodo_pax.h b/src/komodo_pax.h index f29449083..3164d22ce 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -355,18 +355,20 @@ uint64_t komodo_paxprice(int32_t height,char *base,char *rel,uint64_t basevolume int32_t i,j,k,start,ind,numvotes,wt; int64_t delta; uint64_t seed,tolerance,den,densum,sum=0,votes[539]; numvotes = (int32_t)(sizeof(Peggy_inds)/sizeof(*Peggy_inds)); memset(votes,0,sizeof(votes)); - for (i=0; i Date: Sun, 6 Nov 2016 14:54:20 -0300 Subject: [PATCH 169/254] test --- src/komodo_pax.h | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/komodo_pax.h b/src/komodo_pax.h index 3164d22ce..00e6fde97 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -352,7 +352,7 @@ uint64_t _komodo_paxprice(int32_t height,char *base,char *rel,uint64_t basevolum uint64_t komodo_paxprice(int32_t height,char *base,char *rel,uint64_t basevolume) { - int32_t i,j,k,start,ind,numvotes,wt; int64_t delta; uint64_t seed,tolerance,den,densum,sum=0,votes[539]; + int32_t i,j,k,ind,numvotes,wt; int64_t delta; uint64_t seed,tolerance,den,densum,sum=0,votes[539]; numvotes = (int32_t)(sizeof(Peggy_inds)/sizeof(*Peggy_inds)); memset(votes,0,sizeof(votes)); for (sum=i=0; i Date: Sun, 6 Nov 2016 15:01:58 -0300 Subject: [PATCH 170/254] test --- src/komodo_pax.h | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/komodo_pax.h b/src/komodo_pax.h index 00e6fde97..7f76ec351 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -352,24 +352,33 @@ uint64_t _komodo_paxprice(int32_t height,char *base,char *rel,uint64_t basevolum uint64_t komodo_paxprice(int32_t height,char *base,char *rel,uint64_t basevolume) { - int32_t i,j,k,ind,numvotes,wt; int64_t delta; uint64_t seed,tolerance,den,densum,sum=0,votes[539]; + int32_t i,j,k,ind,zeroes,numvotes,wt,nonz; int64_t delta; uint64_t lastprice,seed,tolerance,den,densum,sum=0,votes[539]; numvotes = (int32_t)(sizeof(Peggy_inds)/sizeof(*Peggy_inds)); memset(votes,0,sizeof(votes)); - for (sum=i=0; i> 1) ) + return(0); + sum /= nonz; + lastprice = sum; + for (i=0; i Date: Sun, 6 Nov 2016 15:10:07 -0300 Subject: [PATCH 171/254] test --- src/komodo_pax.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/komodo_pax.h b/src/komodo_pax.h index 7f76ec351..48aad1fb3 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -299,7 +299,7 @@ void komodo_pvals(int32_t height,uint32_t *pvals,uint8_t numpvals) uint64_t komodo_paxcalc(uint32_t *pvals,int32_t baseid,int32_t relid,uint64_t basevolume) { - uint32_t pvalb,pvalr,kmdbtc,btcusd; uint64_t usdvol,baseusd,usdkmd,baserel,ranked[32]; + uint32_t pvalb,pvalr,kmdbtc,btcusd; uint64_t val,usdvol,baseusd,usdkmd,baserel,ranked[32]; if ( basevolume > 1000000*COIN ) return(0); if ( (pvalb= pvals[baseid]) != 0 ) @@ -329,7 +329,11 @@ uint64_t komodo_paxcalc(uint32_t *pvals,int32_t baseid,int32_t relid,uint64_t ba else if ( (pvalr= pvals[relid]) != 0 ) { baserel = ((uint64_t)pvalb * 1000000000) / pvalr; - return(komodo_paxvol(basevolume,baserel)); + val = komodo_paxvol(basevolume,baserel); + if ( MINDENOMS[base] > MINDENOMS[rel] ) + val = (val * MINDENOMS[rel]) / MINDENOMS[base]; + else if ( MINDENOMS[base] < MINDENOMS[rel] ) + val = (val / MINDENOMS[base]) * MINDENOMS[rel]; } } return(0); @@ -378,7 +382,6 @@ uint64_t komodo_paxprice(int32_t height,char *base,char *rel,uint64_t basevolume //printf("\n}; // numvotes.%d\n\n",numvotes); seed = komodo_seed(height); tolerance = sum / 50; - printf("aveprice %.8f seed %llx\n",dstr(sum),(long long)seed); for (k=0; k Date: Sun, 6 Nov 2016 15:11:26 -0300 Subject: [PATCH 172/254] test --- src/komodo_pax.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/komodo_pax.h b/src/komodo_pax.h index 48aad1fb3..aa5617526 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -330,10 +330,10 @@ uint64_t komodo_paxcalc(uint32_t *pvals,int32_t baseid,int32_t relid,uint64_t ba { baserel = ((uint64_t)pvalb * 1000000000) / pvalr; val = komodo_paxvol(basevolume,baserel); - if ( MINDENOMS[base] > MINDENOMS[rel] ) - val = (val * MINDENOMS[rel]) / MINDENOMS[base]; - else if ( MINDENOMS[base] < MINDENOMS[rel] ) - val = (val / MINDENOMS[base]) * MINDENOMS[rel]; + if ( MINDENOMS[baseid] > MINDENOMS[relid] ) + val = (val * MINDENOMS[relid]) / MINDENOMS[baseid]; + else if ( MINDENOMS[baseid] < MINDENOMS[relid] ) + val = (val / MINDENOMS[baseid]) * MINDENOMS[relid]; } } return(0); From 4bac07d4ebc122d3653ffbe429f99910763a96a3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 6 Nov 2016 15:20:13 -0300 Subject: [PATCH 173/254] test --- src/komodo_pax.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/komodo_pax.h b/src/komodo_pax.h index aa5617526..80fab4332 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -334,6 +334,7 @@ uint64_t komodo_paxcalc(uint32_t *pvals,int32_t baseid,int32_t relid,uint64_t ba val = (val * MINDENOMS[relid]) / MINDENOMS[baseid]; else if ( MINDENOMS[baseid] < MINDENOMS[relid] ) val = (val / MINDENOMS[baseid]) * MINDENOMS[relid]; + return(val); } } return(0); From 1a6bc62c7189ddca1f17569e5f675f2f10d53686 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 6 Nov 2016 15:34:33 -0300 Subject: [PATCH 174/254] test --- src/komodo_pax.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/komodo_pax.h b/src/komodo_pax.h index 80fab4332..6f01468dd 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -299,7 +299,7 @@ void komodo_pvals(int32_t height,uint32_t *pvals,uint8_t numpvals) uint64_t komodo_paxcalc(uint32_t *pvals,int32_t baseid,int32_t relid,uint64_t basevolume) { - uint32_t pvalb,pvalr,kmdbtc,btcusd; uint64_t val,usdvol,baseusd,usdkmd,baserel,ranked[32]; + uint32_t pvalb,pvalr,kmdbtc,btcusd; uint64_t usdvol,baseusd,usdkmd,baserel,ranked[32]; if ( basevolume > 1000000*COIN ) return(0); if ( (pvalb= pvals[baseid]) != 0 ) @@ -329,12 +329,11 @@ uint64_t komodo_paxcalc(uint32_t *pvals,int32_t baseid,int32_t relid,uint64_t ba else if ( (pvalr= pvals[relid]) != 0 ) { baserel = ((uint64_t)pvalb * 1000000000) / pvalr; - val = komodo_paxvol(basevolume,baserel); if ( MINDENOMS[baseid] > MINDENOMS[relid] ) - val = (val * MINDENOMS[relid]) / MINDENOMS[baseid]; + baserel /= (MINDENOMS[baseid] / MINDENOMS[relid]); else if ( MINDENOMS[baseid] < MINDENOMS[relid] ) - val = (val / MINDENOMS[baseid]) * MINDENOMS[relid]; - return(val); + baserel *= (MINDENOMS[relid] / MINDENOMS[baseid]); + return(komodo_paxvol(basevolume,baserel)); } } return(0); From 8bca5843a21cb592099a40294a636b4e1ce14fb1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 6 Nov 2016 15:41:38 -0300 Subject: [PATCH 175/254] test --- src/komodo_pax.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/komodo_pax.h b/src/komodo_pax.h index 6f01468dd..f4ff36cbc 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -329,6 +329,7 @@ uint64_t komodo_paxcalc(uint32_t *pvals,int32_t baseid,int32_t relid,uint64_t ba else if ( (pvalr= pvals[relid]) != 0 ) { baserel = ((uint64_t)pvalb * 1000000000) / pvalr; + printf("baserel.%lld %lld %lld %.8f %.8f\n",(long long)baserel,(long long)MINDENOMS[baseid],(long long)MINDENOMS[relid],MINDENOMS[baseid]/MINDENOMS[relid],MINDENOMS[relid]/MINDENOMS[baseid]); if ( MINDENOMS[baseid] > MINDENOMS[relid] ) baserel /= (MINDENOMS[baseid] / MINDENOMS[relid]); else if ( MINDENOMS[baseid] < MINDENOMS[relid] ) From 5d2990457be2037b2315c52eef60a73ad11316cd Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 6 Nov 2016 15:48:17 -0300 Subject: [PATCH 176/254] test --- src/komodo_pax.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/komodo_pax.h b/src/komodo_pax.h index f4ff36cbc..469eb0469 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -323,7 +323,7 @@ uint64_t komodo_paxcalc(uint32_t *pvals,int32_t baseid,int32_t relid,uint64_t ba if ( baseid != MAX_CURRENCIES ) { pax_rank(ranked,pvals); - return(10 * ranked[baseid]); // map to percentage + return(10 * ranked[baseid]); // scaled percentage of M1 total } } else if ( (pvalr= pvals[relid]) != 0 ) @@ -358,6 +358,8 @@ uint64_t _komodo_paxprice(int32_t height,char *base,char *rel,uint64_t basevolum uint64_t komodo_paxprice(int32_t height,char *base,char *rel,uint64_t basevolume) { int32_t i,j,k,ind,zeroes,numvotes,wt,nonz; int64_t delta; uint64_t lastprice,seed,tolerance,den,densum,sum=0,votes[539]; + return(_komodo_paxprice(height,base,rel,basevolume)); + numvotes = (int32_t)(sizeof(Peggy_inds)/sizeof(*Peggy_inds)); memset(votes,0,sizeof(votes)); for (sum=i=zeroes=nonz=0; i Date: Sun, 6 Nov 2016 15:58:48 -0300 Subject: [PATCH 177/254] test --- src/komodo_pax.h | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/komodo_pax.h b/src/komodo_pax.h index 469eb0469..d08a786df 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -301,7 +301,10 @@ uint64_t komodo_paxcalc(uint32_t *pvals,int32_t baseid,int32_t relid,uint64_t ba { uint32_t pvalb,pvalr,kmdbtc,btcusd; uint64_t usdvol,baseusd,usdkmd,baserel,ranked[32]; if ( basevolume > 1000000*COIN ) + { + printf("paxcalc overflow %.8f\n",dstr(basevolume)); return(0); + } if ( (pvalb= pvals[baseid]) != 0 ) { if ( relid == MAX_CURRENCIES ) @@ -314,17 +317,18 @@ uint64_t komodo_paxcalc(uint32_t *pvals,int32_t baseid,int32_t relid,uint64_t ba usdvol = komodo_paxvol(basevolume,baseusd) / MINDENOMS[baseid]; usdkmd = ((uint64_t)btcusd * 1000000000) / kmdbtc; //printf("base -> USD %llu, BTC %llu KMDUSD %llu\n",(long long)baseusd,(long long)btcusd,(long long)kmdusd); - //printf("usdkmd.%llu basevolume.%llu baseusd.%llu paxvol.%llu usdvol.%llu -> %.8f\n",(long long)usdkmd,(long long)basevolume,(long long)baseusd,(long long)komodo_paxvol(basevolume,baseusd),(long long)usdvol,dstr(MINDENOMS[USD] * komodo_paxvol(usdvol,usdkmd))); + printf("usdkmd.%llu basevolume.%llu baseusd.%llu paxvol.%llu usdvol.%llu -> %.8f\n",(long long)usdkmd,(long long)basevolume,(long long)baseusd,(long long)komodo_paxvol(basevolume,baseusd),(long long)usdvol,dstr(MINDENOMS[USD] * komodo_paxvol(usdvol,usdkmd))); return(MINDENOMS[USD] * komodo_paxvol(usdvol,usdkmd)); - } + } else printf("zero val in KMD conv %llu %llu %llu\n",(long long)pvals[USD],(long long)kmdbtc,(long long)btcusc); } else if ( baseid == relid ) { if ( baseid != MAX_CURRENCIES ) { pax_rank(ranked,pvals); + printf("%s M1 percentage %.8f\n",CURRENCIES[baseid],dstr(10 * ranked[baseid])); return(10 * ranked[baseid]); // scaled percentage of M1 total - } + } else return(basevolume); } else if ( (pvalr= pvals[relid]) != 0 ) { @@ -336,7 +340,8 @@ uint64_t komodo_paxcalc(uint32_t *pvals,int32_t baseid,int32_t relid,uint64_t ba baserel *= (MINDENOMS[relid] / MINDENOMS[baseid]); return(komodo_paxvol(basevolume,baserel)); } - } + else printf("null pval for %s\n",CURRENCIES[relid]); + } else printf("null pval for %s\n",CURRENCIES[baseid]); return(0); } @@ -370,7 +375,7 @@ uint64_t komodo_paxprice(int32_t height,char *base,char *rel,uint64_t basevolume //printf("null price height.%d\n",height-i); //return(0); } else sum += votes[i], nonz++; - //printf("%.8f, ",dstr(votes[i])); + printf("%.8f, ",dstr(votes[i])); } if ( nonz <= (numvotes >> 1) ) return(0); @@ -382,7 +387,7 @@ uint64_t komodo_paxprice(int32_t height,char *base,char *rel,uint64_t basevolume votes[i] = lastprice; else lastprice = votes[i]; } - //printf("\n}; // numvotes.%d\n\n",numvotes); + printf("\n}; // numvotes.%d\n\n",numvotes); seed = komodo_seed(height); tolerance = sum / 50; for (k=0; k Date: Sun, 6 Nov 2016 16:00:07 -0300 Subject: [PATCH 178/254] test --- src/komodo_pax.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_pax.h b/src/komodo_pax.h index d08a786df..0a2f49ccb 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -319,7 +319,7 @@ uint64_t komodo_paxcalc(uint32_t *pvals,int32_t baseid,int32_t relid,uint64_t ba //printf("base -> USD %llu, BTC %llu KMDUSD %llu\n",(long long)baseusd,(long long)btcusd,(long long)kmdusd); printf("usdkmd.%llu basevolume.%llu baseusd.%llu paxvol.%llu usdvol.%llu -> %.8f\n",(long long)usdkmd,(long long)basevolume,(long long)baseusd,(long long)komodo_paxvol(basevolume,baseusd),(long long)usdvol,dstr(MINDENOMS[USD] * komodo_paxvol(usdvol,usdkmd))); return(MINDENOMS[USD] * komodo_paxvol(usdvol,usdkmd)); - } else printf("zero val in KMD conv %llu %llu %llu\n",(long long)pvals[USD],(long long)kmdbtc,(long long)btcusc); + } else printf("zero val in KMD conv %llu %llu %llu\n",(long long)pvals[USD],(long long)kmdbtc,(long long)btcusd); } else if ( baseid == relid ) { @@ -333,7 +333,7 @@ uint64_t komodo_paxcalc(uint32_t *pvals,int32_t baseid,int32_t relid,uint64_t ba else if ( (pvalr= pvals[relid]) != 0 ) { baserel = ((uint64_t)pvalb * 1000000000) / pvalr; - printf("baserel.%lld %lld %lld %.8f %.8f\n",(long long)baserel,(long long)MINDENOMS[baseid],(long long)MINDENOMS[relid],MINDENOMS[baseid]/MINDENOMS[relid],MINDENOMS[relid]/MINDENOMS[baseid]); + printf("baserel.%lld %lld %lld %.8f %.8f\n",(long long)baserel,(long long)MINDENOMS[baseid],(long long)MINDENOMS[relid],dstr(MINDENOMS[baseid]/MINDENOMS[relid]),dstr(MINDENOMS[relid]/MINDENOMS[baseid])); if ( MINDENOMS[baseid] > MINDENOMS[relid] ) baserel /= (MINDENOMS[baseid] / MINDENOMS[relid]); else if ( MINDENOMS[baseid] < MINDENOMS[relid] ) From fde4e779cfbfcfa7f0ace2250fdc439e249842c2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 6 Nov 2016 16:11:14 -0300 Subject: [PATCH 179/254] test --- src/komodo_pax.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_pax.h b/src/komodo_pax.h index 0a2f49ccb..e9353a90f 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -300,7 +300,7 @@ void komodo_pvals(int32_t height,uint32_t *pvals,uint8_t numpvals) uint64_t komodo_paxcalc(uint32_t *pvals,int32_t baseid,int32_t relid,uint64_t basevolume) { uint32_t pvalb,pvalr,kmdbtc,btcusd; uint64_t usdvol,baseusd,usdkmd,baserel,ranked[32]; - if ( basevolume > 1000000*COIN ) + if ( basevolume > 10000*COIN ) { printf("paxcalc overflow %.8f\n",dstr(basevolume)); return(0); @@ -335,9 +335,9 @@ uint64_t komodo_paxcalc(uint32_t *pvals,int32_t baseid,int32_t relid,uint64_t ba baserel = ((uint64_t)pvalb * 1000000000) / pvalr; printf("baserel.%lld %lld %lld %.8f %.8f\n",(long long)baserel,(long long)MINDENOMS[baseid],(long long)MINDENOMS[relid],dstr(MINDENOMS[baseid]/MINDENOMS[relid]),dstr(MINDENOMS[relid]/MINDENOMS[baseid])); if ( MINDENOMS[baseid] > MINDENOMS[relid] ) - baserel /= (MINDENOMS[baseid] / MINDENOMS[relid]); + basevolume /= (MINDENOMS[baseid] / MINDENOMS[relid]); else if ( MINDENOMS[baseid] < MINDENOMS[relid] ) - baserel *= (MINDENOMS[relid] / MINDENOMS[baseid]); + basevolume *= (MINDENOMS[relid] / MINDENOMS[baseid]); return(komodo_paxvol(basevolume,baserel)); } else printf("null pval for %s\n",CURRENCIES[relid]); From ecc2479afa2089fe5612b96a710bb8af27d21ae2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 6 Nov 2016 16:18:06 -0300 Subject: [PATCH 180/254] test --- src/komodo_pax.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/komodo_pax.h b/src/komodo_pax.h index e9353a90f..2092d2707 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -363,8 +363,7 @@ uint64_t _komodo_paxprice(int32_t height,char *base,char *rel,uint64_t basevolum uint64_t komodo_paxprice(int32_t height,char *base,char *rel,uint64_t basevolume) { int32_t i,j,k,ind,zeroes,numvotes,wt,nonz; int64_t delta; uint64_t lastprice,seed,tolerance,den,densum,sum=0,votes[539]; - return(_komodo_paxprice(height,base,rel,basevolume)); - + //return(_komodo_paxprice(height,base,rel,basevolume)); numvotes = (int32_t)(sizeof(Peggy_inds)/sizeof(*Peggy_inds)); memset(votes,0,sizeof(votes)); for (sum=i=zeroes=nonz=0; i> 1) ) return(0); @@ -387,7 +386,7 @@ uint64_t komodo_paxprice(int32_t height,char *base,char *rel,uint64_t basevolume votes[i] = lastprice; else lastprice = votes[i]; } - printf("\n}; // numvotes.%d\n\n",numvotes); + //printf("\n}; // numvotes.%d\n\n",numvotes); seed = komodo_seed(height); tolerance = sum / 50; for (k=0; k Date: Sun, 6 Nov 2016 16:22:16 -0300 Subject: [PATCH 181/254] test --- src/komodo_pax.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_pax.h b/src/komodo_pax.h index 2092d2707..5452090c6 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -333,7 +333,7 @@ uint64_t komodo_paxcalc(uint32_t *pvals,int32_t baseid,int32_t relid,uint64_t ba else if ( (pvalr= pvals[relid]) != 0 ) { baserel = ((uint64_t)pvalb * 1000000000) / pvalr; - printf("baserel.%lld %lld %lld %.8f %.8f\n",(long long)baserel,(long long)MINDENOMS[baseid],(long long)MINDENOMS[relid],dstr(MINDENOMS[baseid]/MINDENOMS[relid]),dstr(MINDENOMS[relid]/MINDENOMS[baseid])); + //printf("baserel.%lld %lld %lld %.8f %.8f\n",(long long)baserel,(long long)MINDENOMS[baseid],(long long)MINDENOMS[relid],dstr(MINDENOMS[baseid]/MINDENOMS[relid]),dstr(MINDENOMS[relid]/MINDENOMS[baseid])); if ( MINDENOMS[baseid] > MINDENOMS[relid] ) basevolume /= (MINDENOMS[baseid] / MINDENOMS[relid]); else if ( MINDENOMS[baseid] < MINDENOMS[relid] ) From b4ac3c4120fb63ca3cb52364f36aa48e3380b406 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 6 Nov 2016 16:34:26 -0300 Subject: [PATCH 182/254] test --- src/komodo_pax.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_pax.h b/src/komodo_pax.h index 5452090c6..a4c669ea0 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -368,7 +368,7 @@ uint64_t komodo_paxprice(int32_t height,char *base,char *rel,uint64_t basevolume memset(votes,0,sizeof(votes)); for (sum=i=zeroes=nonz=0; i Date: Sun, 6 Nov 2016 16:39:57 -0300 Subject: [PATCH 183/254] test --- src/komodo_pax.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_pax.h b/src/komodo_pax.h index a4c669ea0..cf797bb03 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -368,7 +368,7 @@ uint64_t komodo_paxprice(int32_t height,char *base,char *rel,uint64_t basevolume memset(votes,0,sizeof(votes)); for (sum=i=zeroes=nonz=0; i Date: Sun, 6 Nov 2016 16:47:02 -0300 Subject: [PATCH 184/254] test --- src/komodo_pax.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/komodo_pax.h b/src/komodo_pax.h index cf797bb03..b706ed912 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -363,7 +363,11 @@ uint64_t _komodo_paxprice(int32_t height,char *base,char *rel,uint64_t basevolum uint64_t komodo_paxprice(int32_t height,char *base,char *rel,uint64_t basevolume) { int32_t i,j,k,ind,zeroes,numvotes,wt,nonz; int64_t delta; uint64_t lastprice,seed,tolerance,den,densum,sum=0,votes[539]; - //return(_komodo_paxprice(height,base,rel,basevolume)); + if ( basevolume > 10000*COIN ) + { + printf("komodo_paxprice overflow %.8f\n",dstr(basevolume)); + return(0); + } numvotes = (int32_t)(sizeof(Peggy_inds)/sizeof(*Peggy_inds)); memset(votes,0,sizeof(votes)); for (sum=i=zeroes=nonz=0; i Date: Sun, 6 Nov 2016 17:47:54 -0300 Subject: [PATCH 185/254] test --- src/komodo_gateway.h | 27 ++++++++++++++++++++------- src/komodo_pax.h | 6 +++--- src/miner.cpp | 4 ++-- 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index b987f001f..f882e061d 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -110,7 +110,7 @@ int32_t komodo_issued_opreturn(uint8_t *shortflagp,char *base,uint256 *txids,uin else *shortflagp = 0; for (i=0; i<4; i++) base[i] = opretbuf[opretlen-4+i]; - if ( strncmp(ASSETCHAINS_SYMBOL,base,strlen(base)) == 0 ) // shortflag + if ( (strcmp(base,"KMD") == 0 && ASSETCHAINS_SYMBOL[0] == 0) || strncmp(ASSETCHAINS_SYMBOL,base,strlen(base)) == 0 ) // shortflag { //printf("BASE.(%s) vs (%s)\n",base,ASSETCHAINS_SYMBOL); opretbuf++, opretlen--; @@ -129,7 +129,7 @@ int32_t komodo_issued_opreturn(uint8_t *shortflagp,char *base,uint256 *txids,uin return(n); } -void komodo_gateway_deposits(CMutableTransaction *txNew) +void komodo_gateway_deposits(CMutableTransaction *txNew,int32_t shortflag,char *symbol) { struct pax_transaction *pax,*tmp; uint8_t *script,opret[10000],data[10000]; int32_t i,len=0,opretlen=0,numvouts=1; PENDING_KOMODO_TX = 0; @@ -155,16 +155,17 @@ void komodo_gateway_deposits(CMutableTransaction *txNew) data[len++] = pax->vout & 0xff; data[len++] = (pax->vout >> 8) & 0xff; printf(" vout.%u DEPOSIT %.8f <- paxdeposit.%s\n",pax->vout,(double)txNew->vout[numvouts].nValue/COIN,ASSETCHAINS_SYMBOL); - PENDING_KOMODO_TX += pax->fiatoshis; + if ( shortflag == 0 && strcmp(symbol,"KMD") == 0 ) + PENDING_KOMODO_TX += pax->fiatoshis; if ( numvouts++ >= 64 ) break; } if ( numvouts > 1 ) { - if ( ASSETCHAINS_SHORTFLAG != 0 ) + if ( shortflag != 0 ) data[len++] = '-'; - for (i=0; ASSETCHAINS_SYMBOL[i]!=0; i++) - data[len++] = ASSETCHAINS_SYMBOL[i]; + for (i=0; symbol[i]!=0; i++) + data[len++] = symbol[i]; data[len++] = 0; opretlen = komodo_opreturnscript(opret,'I',data,len); txNew->vout.resize(numvouts+1); @@ -173,7 +174,7 @@ void komodo_gateway_deposits(CMutableTransaction *txNew) script = (uint8_t *)&txNew->vout[numvouts].scriptPubKey[0]; memcpy(script,opret,opretlen); printf("total numvouts.%d %.8f opretlen.%d\n",numvouts,dstr(PENDING_KOMODO_TX),opretlen); - } //else KOMODO_DEPOSIT = 0; + } } int32_t komodo_check_deposit(int32_t height,const CBlock& block) // verify above block is valid pax pricing @@ -208,6 +209,14 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block) // verify above } //printf("opretlen.%d num.%d\n",opretlen,num); } + else if ( script[offset] == 'X' && opretlen < block.vtx[0].vout[n-1].scriptPubKey.size() ) + { + if ( (num= komodo_issued_opreturn(&shortflag,base,txids,vouts,&script[offset],opretlen)) > 0 ) + { + // return(-1) if invalid withdraw redeem + // check txid in assetchain, verify fiatoshis and conversion rate + } + } return(0); } @@ -283,6 +292,10 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 } } } + else if ( tomomodo != 0 && opretbuf[0] == 'X' ) + { + // verify and update limits + } } return(typestr); } diff --git a/src/komodo_pax.h b/src/komodo_pax.h index b706ed912..312aa403c 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -317,7 +317,7 @@ uint64_t komodo_paxcalc(uint32_t *pvals,int32_t baseid,int32_t relid,uint64_t ba usdvol = komodo_paxvol(basevolume,baseusd) / MINDENOMS[baseid]; usdkmd = ((uint64_t)btcusd * 1000000000) / kmdbtc; //printf("base -> USD %llu, BTC %llu KMDUSD %llu\n",(long long)baseusd,(long long)btcusd,(long long)kmdusd); - printf("usdkmd.%llu basevolume.%llu baseusd.%llu paxvol.%llu usdvol.%llu -> %.8f\n",(long long)usdkmd,(long long)basevolume,(long long)baseusd,(long long)komodo_paxvol(basevolume,baseusd),(long long)usdvol,dstr(MINDENOMS[USD] * komodo_paxvol(usdvol,usdkmd))); + //printf("usdkmd.%llu basevolume.%llu baseusd.%llu paxvol.%llu usdvol.%llu -> %.8f\n",(long long)usdkmd,(long long)basevolume,(long long)baseusd,(long long)komodo_paxvol(basevolume,baseusd),(long long)usdvol,dstr(MINDENOMS[USD] * komodo_paxvol(usdvol,usdkmd))); return(MINDENOMS[USD] * komodo_paxvol(usdvol,usdkmd)); } else printf("zero val in KMD conv %llu %llu %llu\n",(long long)pvals[USD],(long long)kmdbtc,(long long)btcusd); } @@ -326,7 +326,7 @@ uint64_t komodo_paxcalc(uint32_t *pvals,int32_t baseid,int32_t relid,uint64_t ba if ( baseid != MAX_CURRENCIES ) { pax_rank(ranked,pvals); - printf("%s M1 percentage %.8f\n",CURRENCIES[baseid],dstr(10 * ranked[baseid])); + //printf("%s M1 percentage %.8f\n",CURRENCIES[baseid],dstr(10 * ranked[baseid])); return(10 * ranked[baseid]); // scaled percentage of M1 total } else return(basevolume); } @@ -426,7 +426,7 @@ uint64_t komodo_paxprice(int32_t height,char *base,char *rel,uint64_t basevolume } sum /= densum; sum = (sum * basevolume) / 100000; - printf("seed.%llx sum %.8f densum %.8f basevol %.8f\n",(long long)seed,dstr(sum),dstr(densum),dstr(basevolume)); + //printf("seed.%llx sum %.8f densum %.8f basevol %.8f\n",(long long)seed,dstr(sum),dstr(densum),dstr(basevolume)); break; } } diff --git a/src/miner.cpp b/src/miner.cpp index b927ec736..279676586 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -100,7 +100,7 @@ void UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams, #define ASSETCHAINS_MINHEIGHT 100 int32_t komodo_pax_opreturn(uint8_t *opret,int32_t maxsize); -void komodo_gateway_deposits(CMutableTransaction *txNew); +void komodo_gateway_deposits(CMutableTransaction *txNew,int32_t shortflag,char *symbol); extern int32_t KOMODO_INITDONE,ASSETCHAINS_SHORTFLAG; extern uint64_t KOMODO_DEPOSIT; extern char ASSETCHAINS_SYMBOL[16]; @@ -375,7 +375,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) } else { - komodo_gateway_deposits(&txNew); + komodo_gateway_deposits(&txNew,0,"KMD"); //fprintf(stderr,"txNew numvouts.%d\n",(int32_t)txNew.vout.size()); } From 0920fed96f9d306d7a7c3db9c38f766c20ffa62d Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 6 Nov 2016 17:51:40 -0300 Subject: [PATCH 186/254] 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 f882e061d..42851628a 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -292,7 +292,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 } } } - else if ( tomomodo != 0 && opretbuf[0] == 'X' ) + else if ( tokomodo != 0 && opretbuf[0] == 'X' ) { // verify and update limits } From c74774e9ff3eac5661f2b82a9d324fad527edee3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 6 Nov 2016 17:54:38 -0300 Subject: [PATCH 187/254] test --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index 279676586..3ea5ee392 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -375,7 +375,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) } else { - komodo_gateway_deposits(&txNew,0,"KMD"); + komodo_gateway_deposits(&txNew,0,(char *)"KMD"); //fprintf(stderr,"txNew numvouts.%d\n",(int32_t)txNew.vout.size()); } From b6441e83fc85b545aeb6dcd77f8efa7a1b0f9842 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 6 Nov 2016 18:04:54 -0300 Subject: [PATCH 188/254] test --- src/wallet/rpcwallet.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index f11f4e57b..0fe334b8d 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -511,14 +511,14 @@ Value paxwithdraw(const Array& params, bool fHelp) { extern int32_t KMDHEIGHT,KOMODO_REALTIME; CWalletTx wtx; std::string dest; int32_t height; uint64_t komodoshis = 0; char destaddr[64]; uint8_t i,pubkey37[37]; bool fSubtractFeeFromAmount = false; - if ( KOMODO_REALTIME == 0 ) - throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "paxwithdraw needs to wait for KMD realtime"); if ( ASSETCHAINS_SYMBOL[0] == 0 ) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "paxwithdraw cant be from KMD"); if (!EnsureWalletIsAvailable(fHelp)) return 0; if (fHelp || params.size() != 2) throw runtime_error("paxwithdraw \"address\" fiatamount"); + if ( KOMODO_REALTIME == 0 ) + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "paxwithdraw needs to wait for KMD realtime"); LOCK2(cs_main, pwalletMain->cs_wallet); CBitcoinAddress address(params[0].get_str()); if (!address.IsValid()) From b2d64a0f06907f852fd6ef2b125ea4b2206e7431 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 6 Nov 2016 18:29:52 -0300 Subject: [PATCH 189/254] test --- src/komodo_gateway.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 42851628a..b5969d716 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -73,11 +73,14 @@ struct pax_transaction *komodo_paxmark(struct pax_transaction *space,uint256 txi void komodo_gateway_deposit(char *coinaddr,uint64_t value,int32_t shortflag,char *symbol,uint64_t fiatoshis,uint8_t *rmd160,uint256 txid,uint16_t vout,int32_t height) // assetchain context { - struct pax_transaction *pax; + struct pax_transaction *pax; int32_t addflag = 0; pthread_mutex_lock(&komodo_mutex); HASH_FIND(hh,PAX,&txid,sizeof(txid),pax); if ( pax == 0 ) + { pax = (struct pax_transaction *)calloc(1,sizeof(*pax)); + addflag = 1; + } if ( coinaddr != 0 ) { strcpy(pax->coinaddr,coinaddr); @@ -98,7 +101,8 @@ void komodo_gateway_deposit(char *coinaddr,uint64_t value,int32_t shortflag,char } pax->txid = txid; pax->vout = vout; - HASH_ADD_KEYPTR(hh,PAX,&pax->txid,sizeof(pax->txid),pax); + if ( addflag != 0 ) + HASH_ADD_KEYPTR(hh,PAX,&pax->txid,sizeof(pax->txid),pax); pthread_mutex_unlock(&komodo_mutex); } From 8d52488fa83b2e43b3155782165923f5578d3691 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 6 Nov 2016 18:42:29 -0300 Subject: [PATCH 190/254] test --- src/komodo_gateway.h | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index b5969d716..0c56eb0f6 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -79,8 +79,11 @@ void komodo_gateway_deposit(char *coinaddr,uint64_t value,int32_t shortflag,char if ( pax == 0 ) { pax = (struct pax_transaction *)calloc(1,sizeof(*pax)); - addflag = 1; + pax->txid = txid; + pax->vout = vout; + HASH_ADD_KEYPTR(hh,PAX,&pax->txid,sizeof(pax->txid),pax); } + pthread_mutex_unlock(&komodo_mutex); if ( coinaddr != 0 ) { strcpy(pax->coinaddr,coinaddr); @@ -99,11 +102,6 @@ void komodo_gateway_deposit(char *coinaddr,uint64_t value,int32_t shortflag,char pax->marked = height; printf("MARK DEPOSIT ht.%d\n",height); } - pax->txid = txid; - pax->vout = vout; - if ( addflag != 0 ) - HASH_ADD_KEYPTR(hh,PAX,&pax->txid,sizeof(pax->txid),pax); - pthread_mutex_unlock(&komodo_mutex); } int32_t komodo_issued_opreturn(uint8_t *shortflagp,char *base,uint256 *txids,uint16_t *vouts,uint8_t *opretbuf,int32_t opretlen) From 53c47c90a6a3b35eb0bbb77de386ad5ec1bf9202 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 6 Nov 2016 20:06:13 -0300 Subject: [PATCH 191/254] test --- src/komodo_gateway.h | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 0c56eb0f6..0d5501d0e 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -25,7 +25,7 @@ struct pax_transaction char symbol[16],coinaddr[64]; uint8_t rmd160[20],shortflag; } *PAX; -uint64_t komodo_paxtotal() +/*uint64_t komodo_paxtotal() { struct pax_transaction *pax,*tmp; uint64_t total = 0; HASH_ITER(hh,PAX,pax,tmp) @@ -34,6 +34,20 @@ uint64_t komodo_paxtotal() total += pax->fiatoshis; } return(total); +}*/ + +uint64_t dpow_paxtotal(struct dpow_info *dp) +{ + struct pax_transaction *pax,*tmp; uint64_t total = 0; + tmp = 0; + while ( (pax= PAX->hh.next) != 0 && pax != tmp ) + { + if ( pax->marked == 0 ) + total += pax->fiatoshis; + tmp = pax; + pax = pax->hh.next; + } + return(total); } struct pax_transaction *komodo_paxfind(struct pax_transaction *space,uint256 txid,uint16_t vout) @@ -135,7 +149,9 @@ void komodo_gateway_deposits(CMutableTransaction *txNew,int32_t shortflag,char * { struct pax_transaction *pax,*tmp; uint8_t *script,opret[10000],data[10000]; int32_t i,len=0,opretlen=0,numvouts=1; PENDING_KOMODO_TX = 0; - HASH_ITER(hh,PAX,pax,tmp) + //HASH_ITER(hh,PAX,pax,tmp) + tmp = 0; + while ( (pax= PAX->hh.next) != 0 && pax != tmp ) { if ( pax->marked != 0 ) continue; @@ -161,6 +177,8 @@ void komodo_gateway_deposits(CMutableTransaction *txNew,int32_t shortflag,char * PENDING_KOMODO_TX += pax->fiatoshis; if ( numvouts++ >= 64 ) break; + tmp = pax; + pax = pax->hh.next; } if ( numvouts > 1 ) { From 77be6cd9d3f7ebef344524502765e5d5245c6466 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 6 Nov 2016 20:54:32 -0300 Subject: [PATCH 192/254] test --- src/komodo_bitcoind.h | 4 +-- src/komodo_gateway.h | 73 +++++++++++++++++++++++++++++++++---------- src/miner.cpp | 3 +- 3 files changed, 60 insertions(+), 20 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 4b2d3a91f..a5c735bb3 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -23,6 +23,8 @@ #include #endif +#define issue_curl(cmdstr) bitcoind_RPC(0,"curl","http://127.0.0.1:7771",0,cmdstr,0) + struct MemoryStruct { char *memory; size_t size; }; struct return_string { char *ptr; size_t len; }; @@ -137,7 +139,6 @@ char *post_process_bitcoind_RPC(char *debugstr,char *command,char *rpcstr,char * * ************************************************************************/ - char *bitcoind_RPC(char **retstrp,char *debugstr,char *url,char *userpass,char *command,char *params) { static int didinit,count,count2; static double elapsedsum,elapsedsum2; @@ -344,7 +345,6 @@ char *komodo_issuemethod(char *method,char *params,uint16_t port) } return(retstr2); } -//curl --url "http://127.0.0.1:13033" --user "user1557335368:pass111720054" --data "{\"method\":\"getinfo\",\"params\":[]}" uint32_t komodo_txtime(uint256 hash) { diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 0d5501d0e..1cbb986d9 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -36,7 +36,7 @@ struct pax_transaction return(total); }*/ -uint64_t dpow_paxtotal(struct dpow_info *dp) +uint64_t komodo_paxtotal() { struct pax_transaction *pax,*tmp; uint64_t total = 0; tmp = 0; @@ -147,9 +147,11 @@ int32_t komodo_issued_opreturn(uint8_t *shortflagp,char *base,uint256 *txids,uin void komodo_gateway_deposits(CMutableTransaction *txNew,int32_t shortflag,char *symbol) { - struct pax_transaction *pax,*tmp; uint8_t *script,opret[10000],data[10000]; int32_t i,len=0,opretlen=0,numvouts=1; + struct pax_transaction *pax,*tmp; uint8_t *script,opcode,opret[10000],data[10000]; int32_t i,len=0,opretlen=0,numvouts=1; PENDING_KOMODO_TX = 0; - //HASH_ITER(hh,PAX,pax,tmp) + if ( strcmp(symbol,"KMD") != 0 ) + opcode = 'I'; + else opcode = 'X'; tmp = 0; while ( (pax= PAX->hh.next) != 0 && pax != tmp ) { @@ -172,9 +174,10 @@ void komodo_gateway_deposits(CMutableTransaction *txNew,int32_t shortflag,char * } data[len++] = pax->vout & 0xff; data[len++] = (pax->vout >> 8) & 0xff; - printf(" vout.%u DEPOSIT %.8f <- paxdeposit.%s\n",pax->vout,(double)txNew->vout[numvouts].nValue/COIN,ASSETCHAINS_SYMBOL); - if ( shortflag == 0 && strcmp(symbol,"KMD") == 0 ) + printf(" vout.%u DEPOSIT %.8f <- paxdeposit.%s\n",pax->vout,(double)txNew->vout[numvouts].nValue/COIN,symbol); + if ( strcmp(symbol,"KMD") != 0 ) PENDING_KOMODO_TX += pax->fiatoshis; + else PENDING_KOMODO_TX += pax->komodoshis; if ( numvouts++ >= 64 ) break; tmp = pax; @@ -187,7 +190,7 @@ void komodo_gateway_deposits(CMutableTransaction *txNew,int32_t shortflag,char * for (i=0; symbol[i]!=0; i++) data[len++] = symbol[i]; data[len++] = 0; - opretlen = komodo_opreturnscript(opret,'I',data,len); + opretlen = komodo_opreturnscript(opret,opcode,data,len); txNew->vout.resize(numvouts+1); txNew->vout[numvouts].nValue = 0; txNew->vout[numvouts].scriptPubKey.resize(opretlen); @@ -199,20 +202,30 @@ void komodo_gateway_deposits(CMutableTransaction *txNew,int32_t shortflag,char * 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; uint256 hash,txids[64]; uint8_t shortflag; char base[16]; uint16_t vouts[64]; uint8_t *script; struct pax_transaction *pax,space; + int32_t i,j,n,num,opretlen,offset=1; uint256 hash,txids[64]; uint8_t shortflag; char symbol[16],base[16]; uint16_t vouts[64]; uint8_t *script,opcode; struct pax_transaction *pax,space; n = block.vtx[0].vout.size(); script = (uint8_t *)block.vtx[0].vout[n-1].scriptPubKey.data(); if ( n <= 2 || script[0] != 0x6a ) return(0); offset += komodo_scriptitemlen(&opretlen,&script[offset]); //printf("checkdeposit n.%d [%02x] [%c] %d vs %d\n",n,script[0],script[offset],script[offset],'I'); - if ( script[offset] == 'I' && opretlen < block.vtx[0].vout[n-1].scriptPubKey.size() ) + if ( ASSETCHAINS_SYMBOL[0] == 0 ) + { + opcode = 'X'; + strcpy(symbol,"KMD"); + } + else + { + strcpy(symbol,ASSETCHAINS_SYMBOL); + opcode = 'I'; + } + if ( script[offset] == opcode && opretlen < block.vtx[0].vout[n-1].scriptPubKey.size() ) { if ( (num= komodo_issued_opreturn(&shortflag,base,txids,vouts,&script[offset],opretlen)) > 0 ) { for (i=1; ifiatoshis == block.vtx[0].vout[i].nValue ) + if ( (pax= komodo_paxfind(&space,txids[i-1],vouts[i-1])) != 0 && ((opcode == 'I' && pax->fiatoshis == block.vtx[0].vout[i].nValue) || (opcode == 'X' && pax->komodoshis == block.vtx[0].vout[i].nValue)) ) { //printf("i.%d match %.8f == %.8f\n",i,dstr(pax != 0 ? pax->fiatoshis:-1),dstr(block.vtx[0].vout[i].nValue)); komodo_paxmark(&space,txids[i-1],vouts[i-1],height); @@ -229,14 +242,6 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block) // verify above } //printf("opretlen.%d num.%d\n",opretlen,num); } - else if ( script[offset] == 'X' && opretlen < block.vtx[0].vout[n-1].scriptPubKey.size() ) - { - if ( (num= komodo_issued_opreturn(&shortflag,base,txids,vouts,&script[offset],opretlen)) > 0 ) - { - // return(-1) if invalid withdraw redeem - // check txid in assetchain, verify fiatoshis and conversion rate - } - } return(0); } @@ -461,4 +466,38 @@ void komodo_gateway_iteration(char *symbol) sleep(30); } KOMODO_DEPOSIT = komodo_paxtotal(); + if ( ASSETCHAINS_SYMBOL[0] == 0 ) + { + //[{"prev_hash":"5d5c9a49489b558de9e84f991f996dedaae6b9d0f157f82b2fec64662476d5cf","prev_vout":2,"EUR":0.78329000,"fiat":"EUR","height":57930,"KMD":0.10000000,"address":"RDhEGYScNQYetCyG75Kf8Fg61UWPdwc1C5"}] + char *retstr,*base,*coinaddr,*txidstr; uint64_t value; cJSON *array; int32_t n,vout,shortflag,height; uint256 txid; uint8_t rmd160[20],addrtype; + if ( (retstr= issue_curl("{\"agent\":\"dpow\",\"method\":\"pending\",\"fiat\":\"EUR\"}")) != 0 ) + { + if ( (array= cJSON_Parse(retstr)) != 0 ) + { + if ( (n= cJSON_GetArraySize(array)) > 0 ) + { + for (i=0; i 0 && height > 0 ) + { + fiatoshis = jdouble(item,base) * COIN; + decode_hex((uint8_t *)&txid,sizeof(txid),txidstr); + bitcoin_addr2rmd160(&addrtype,rmd160,coinaddr); + komodo_gateway_deposit(coinaddr,value,shortflag,base,fiatoshis,rmd160,txid,vout,height); + } + } + } + } + printf("retstr.(%s)\n",retstr); + free(retstr); + } + } } diff --git a/src/miner.cpp b/src/miner.cpp index 3ea5ee392..dc4d9f416 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -113,7 +113,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) if(!pblocktemplate.get()) return NULL; CBlock *pblock = &pblocktemplate->block; // pointer for convenience - while ( ASSETCHAINS_SYMBOL[0] != 0 && chainActive.Tip()->nHeight > ASSETCHAINS_MINHEIGHT && mempool.GetTotalTxSize() <= 0 ) + while ( chainActive.Tip()->nHeight > ASSETCHAINS_MINHEIGHT && mempool.GetTotalTxSize() <= 0 ) { sleep(10); if ( KOMODO_INITDONE == 0 || time(NULL) < KOMODO_INITDONE+60 ) @@ -372,6 +372,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) txNew.vout[1].nValue = 0; //fprintf(stderr,"opretlen.%d\n",opretlen); } + komodo_gateway_deposits(&txNew,0,(char *)"EUR"); } else { From 51508fedbd78a179fc8f0d48c7e01bc6ef5e0b47 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 6 Nov 2016 20:57:01 -0300 Subject: [PATCH 193/254] test --- src/komodo_bitcoind.h | 2 +- src/komodo_gateway.h | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index a5c735bb3..ae4250816 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -23,7 +23,7 @@ #include #endif -#define issue_curl(cmdstr) bitcoind_RPC(0,"curl","http://127.0.0.1:7771",0,cmdstr,0) +#define issue_curl(cmdstr) bitcoind_RPC(0,"curl","http://127.0.0.1:7771",0,(char *)(cmdstr),0) struct MemoryStruct { char *memory; size_t size; }; struct return_string { char *ptr; size_t len; }; diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 1cbb986d9..1f7c8c42e 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -479,13 +479,13 @@ void komodo_gateway_iteration(char *symbol) for (i=0; i 0 && height > 0 ) { fiatoshis = jdouble(item,base) * COIN; From 52bc445a1f9fafcf177fe9e3edc684d8913fa2c1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 6 Nov 2016 21:00:20 -0300 Subject: [PATCH 194/254] test --- src/komodo_bitcoind.h | 2 +- src/komodo_gateway.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index ae4250816..f44c166d9 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -23,7 +23,7 @@ #include #endif -#define issue_curl(cmdstr) bitcoind_RPC(0,"curl","http://127.0.0.1:7771",0,(char *)(cmdstr),0) +#define issue_curl(cmdstr) bitcoind_RPC(0,(char *)"curl",(char *)"http://127.0.0.1:7771",0,(char *)(cmdstr),0) struct MemoryStruct { char *memory; size_t size; }; struct return_string { char *ptr; size_t len; }; diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 1f7c8c42e..18a419e04 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -153,7 +153,7 @@ void komodo_gateway_deposits(CMutableTransaction *txNew,int32_t shortflag,char * opcode = 'I'; else opcode = 'X'; tmp = 0; - while ( (pax= PAX->hh.next) != 0 && pax != tmp ) + while ( (pax= (struct pax_transaction *)PAX->hh.next) != 0 && pax != tmp ) { if ( pax->marked != 0 ) continue; @@ -181,7 +181,7 @@ void komodo_gateway_deposits(CMutableTransaction *txNew,int32_t shortflag,char * if ( numvouts++ >= 64 ) break; tmp = pax; - pax = pax->hh.next; + pax = (struct pax_transaction *)pax->hh.next; } if ( numvouts > 1 ) { From 55a913eec1eec96ee8e092017e9f510a55efd44f Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 6 Nov 2016 21:01:46 -0300 Subject: [PATCH 195/254] 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 18a419e04..ea09a3b7e 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -40,12 +40,12 @@ uint64_t komodo_paxtotal() { struct pax_transaction *pax,*tmp; uint64_t total = 0; tmp = 0; - while ( (pax= PAX->hh.next) != 0 && pax != tmp ) + while ( (pax= (struct pax_transaction *)PAX->hh.next) != 0 && pax != tmp ) { if ( pax->marked == 0 ) total += pax->fiatoshis; tmp = pax; - pax = pax->hh.next; + pax = (struct pax_transaction *)pax->hh.next; } return(total); } From e5e414c279147c1ee004c94c56545453f5c86ea8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 6 Nov 2016 21:02:56 -0300 Subject: [PATCH 196/254] 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 ea09a3b7e..7e3219cea 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -469,7 +469,7 @@ void komodo_gateway_iteration(char *symbol) if ( ASSETCHAINS_SYMBOL[0] == 0 ) { //[{"prev_hash":"5d5c9a49489b558de9e84f991f996dedaae6b9d0f157f82b2fec64662476d5cf","prev_vout":2,"EUR":0.78329000,"fiat":"EUR","height":57930,"KMD":0.10000000,"address":"RDhEGYScNQYetCyG75Kf8Fg61UWPdwc1C5"}] - char *retstr,*base,*coinaddr,*txidstr; uint64_t value; cJSON *array; int32_t n,vout,shortflag,height; uint256 txid; uint8_t rmd160[20],addrtype; + char *retstr,*base,*coinaddr,*txidstr; uint64_t value,fiatoshis; cJSON *array,*item; int32_t n,vout,shortflag,height; uint256 txid; uint8_t rmd160[20],addrtype; if ( (retstr= issue_curl("{\"agent\":\"dpow\",\"method\":\"pending\",\"fiat\":\"EUR\"}")) != 0 ) { if ( (array= cJSON_Parse(retstr)) != 0 ) From 3f083c258de50ce5db2d6ae59c1c9d8956f916ce Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 6 Nov 2016 21:13:41 -0300 Subject: [PATCH 197/254] test --- src/bitcoind.cpp | 3 +++ src/komodo_gateway.h | 9 +++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/bitcoind.cpp b/src/bitcoind.cpp index 41773381f..b5dac427a 100644 --- a/src/bitcoind.cpp +++ b/src/bitcoind.cpp @@ -34,6 +34,7 @@ static bool fDaemon; extern char ASSETCHAINS_SYMBOL[16]; void komodo_gateway_iteration(char *symbol); +void komodo_iteration(char *symbol); void WaitForShutdown(boost::thread_group* threadGroup) { @@ -44,6 +45,8 @@ void WaitForShutdown(boost::thread_group* threadGroup) MilliSleep(2000); if ( ASSETCHAINS_SYMBOL[0] != 0 ) komodo_gateway_iteration(ASSETCHAINS_SYMBOL); + else komodo_iteration("EUR"); + fShutdown = ShutdownRequested(); } if (threadGroup) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 7e3219cea..83005cd88 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -466,11 +466,16 @@ void komodo_gateway_iteration(char *symbol) sleep(30); } KOMODO_DEPOSIT = komodo_paxtotal(); +} + +void komodo_iteration(char *symbol) +{ + char *retstr,*base,*coinaddr,*txidstr,cmd[512]; uint64_t value,fiatoshis; cJSON *array,*item; int32_t i,n,vout,shortflag,height; uint256 txid; uint8_t rmd160[20],addrtype; if ( ASSETCHAINS_SYMBOL[0] == 0 ) { //[{"prev_hash":"5d5c9a49489b558de9e84f991f996dedaae6b9d0f157f82b2fec64662476d5cf","prev_vout":2,"EUR":0.78329000,"fiat":"EUR","height":57930,"KMD":0.10000000,"address":"RDhEGYScNQYetCyG75Kf8Fg61UWPdwc1C5"}] - char *retstr,*base,*coinaddr,*txidstr; uint64_t value,fiatoshis; cJSON *array,*item; int32_t n,vout,shortflag,height; uint256 txid; uint8_t rmd160[20],addrtype; - if ( (retstr= issue_curl("{\"agent\":\"dpow\",\"method\":\"pending\",\"fiat\":\"EUR\"}")) != 0 ) + sprintf(cmd,"{\"agent\":\"dpow\",\"method\":\"pending\",\"fiat\":\"%s\"}",symbol); + if ( (retstr= issue_curl(cmd)) != 0 ) { if ( (array= cJSON_Parse(retstr)) != 0 ) { From c6f76053471b1a5b2af29da61b618928ac8c7704 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 6 Nov 2016 21:14:28 -0300 Subject: [PATCH 198/254] test --- src/bitcoind.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bitcoind.cpp b/src/bitcoind.cpp index b5dac427a..738247604 100644 --- a/src/bitcoind.cpp +++ b/src/bitcoind.cpp @@ -45,7 +45,7 @@ void WaitForShutdown(boost::thread_group* threadGroup) MilliSleep(2000); if ( ASSETCHAINS_SYMBOL[0] != 0 ) komodo_gateway_iteration(ASSETCHAINS_SYMBOL); - else komodo_iteration("EUR"); + else komodo_iteration((char *)"EUR"); fShutdown = ShutdownRequested(); } From f266f0144c76292f20bfacc9f55fcf3f9bdca991 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 6 Nov 2016 21:21:46 -0300 Subject: [PATCH 199/254] 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 f44c166d9..5cab4fb15 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -23,7 +23,7 @@ #include #endif -#define issue_curl(cmdstr) bitcoind_RPC(0,(char *)"curl",(char *)"http://127.0.0.1:7771",0,(char *)(cmdstr),0) +#define issue_curl(cmdstr) bitcoind_RPC(0,(char *)"curl",(char *)"http://127.0.0.1:7775",0,(char *)(cmdstr),0) struct MemoryStruct { char *memory; size_t size; }; struct return_string { char *ptr; size_t len; }; From 26fa12367284c9463c20e63aa73ec52dd893d614 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 7 Nov 2016 07:41:23 -0300 Subject: [PATCH 200/254] test --- src/komodo_gateway.h | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 83005cd88..d415161f9 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -349,32 +349,37 @@ void komodo_gateway_voutupdate(char *symbol,int32_t isspecial,int32_t height,int int32_t komodo_gateway_tx(char *symbol,int32_t height,int32_t txi,char *txidstr,uint32_t port) { - char *retstr,params[256],*hexstr; uint8_t script[10000]; cJSON *json,*result,*vouts,*item,*sobj; int32_t vout,n,len,isspecial,retval = -1; uint64_t value; bits256 txid; + char *retstr,params[256],*hexstr; uint8_t script[10000]; cJSON *json,*result,*vouts,*item,*sobj; int32_t vout,n,len,isspecial,retval = -1; uint64_t value,vpub_old,vpub_new; bits256 txid; sprintf(params,"[\"%s\", 1]",txidstr); if ( (retstr= komodo_issuemethod((char *)"getrawtransaction",params,port)) != 0 ) { if ( (json= cJSON_Parse(retstr)) != 0 ) { - if ( (result= jobj(json,(char *)"result")) != 0 && (vouts= jarray(&n,result,(char *)"vout")) != 0 ) + if ( (result= jobj(json,(char *)"result")) != 0 ) { + vpub_old = j64bits(result,(char *)"vpub_old"); + vpub_new = j64bits(result,(char *)"vpub_new"); retval = 0; - isspecial = 0; - txid = jbits256(result,(char *)"txid"); - for (vout=0; vout> 1; - if ( vout == 0 && ((memcmp(&hexstr[2],CRYPTO777_PUBSECPSTR,66) == 0 && len == 35) || (memcmp(&hexstr[6],CRYPTO777_RMD160STR,40) == 0 && len == 25)) ) - isspecial = 1; - else if ( len <= sizeof(script) ) + if ( (hexstr= jstr(sobj,(char *)"hex")) != 0 ) { - decode_hex(script,len,hexstr); - komodo_gateway_voutupdate(symbol,isspecial,height,txi,txid,vout,n,value,script,len); + len = (int32_t)strlen(hexstr) >> 1; + if ( vout == 0 && ((memcmp(&hexstr[2],CRYPTO777_PUBSECPSTR,66) == 0 && len == 35) || (memcmp(&hexstr[6],CRYPTO777_RMD160STR,40) == 0 && len == 25)) ) + isspecial = 1; + else if ( len <= sizeof(script) ) + { + decode_hex(script,len,hexstr); + komodo_gateway_voutupdate(symbol,isspecial,height,txi,txid,vout,n,value,script,len); + } } } } From df6a64f772d50ee3f12a7016695b406b2b6394b0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 7 Nov 2016 07:49:09 -0300 Subject: [PATCH 201/254] 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 d415161f9..0890df521 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -357,8 +357,8 @@ int32_t komodo_gateway_tx(char *symbol,int32_t height,int32_t txi,char *txidstr, { if ( (result= jobj(json,(char *)"result")) != 0 ) { - vpub_old = j64bits(result,(char *)"vpub_old"); - vpub_new = j64bits(result,(char *)"vpub_new"); + vpub_old = jdouble(result,(char *)"vpub_old") * COIN; + vpub_new = jdouble(result,(char *)"vpub_new") * COIN; retval = 0; if ( vpub_old == 0 && vpub_new == 0 && (vouts= jarray(&n,result,(char *)"vout")) != 0 ) { From a10aafcc06050a52fb9e093f3c9a35d47c84b1f9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 7 Nov 2016 07:55:33 -0300 Subject: [PATCH 202/254] 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 0890df521..548c904c1 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -357,6 +357,7 @@ int32_t komodo_gateway_tx(char *symbol,int32_t height,int32_t txi,char *txidstr, { if ( (result= jobj(json,(char *)"result")) != 0 ) { + printf("RESULT.(%s)\n",jprint(result,0)); vpub_old = jdouble(result,(char *)"vpub_old") * COIN; vpub_new = jdouble(result,(char *)"vpub_new") * COIN; retval = 0; @@ -384,7 +385,7 @@ int32_t komodo_gateway_tx(char *symbol,int32_t height,int32_t txi,char *txidstr, } } } - } else printf("error getting txids.(%s)\n",retstr); + } else printf("error getting txids.(%s) %p\n",retstr,result); free_json(json); } free(retstr); From ee0744d2b5e816f4f62cb1623f6cd5134528a05d Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 7 Nov 2016 08:10:17 -0300 Subject: [PATCH 203/254] test --- src/komodo_gateway.h | 9 ++++----- src/komodo_pax.h | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 548c904c1..352971965 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -349,7 +349,7 @@ void komodo_gateway_voutupdate(char *symbol,int32_t isspecial,int32_t height,int int32_t komodo_gateway_tx(char *symbol,int32_t height,int32_t txi,char *txidstr,uint32_t port) { - char *retstr,params[256],*hexstr; uint8_t script[10000]; cJSON *json,*result,*vouts,*item,*sobj; int32_t vout,n,len,isspecial,retval = -1; uint64_t value,vpub_old,vpub_new; bits256 txid; + char *retstr,params[256],*hexstr; uint8_t script[10000]; cJSON *oldpub,*newpub,*json,*result,*vouts,*item,*sobj; int32_t vout,n,len,isspecial,retval = -1; uint64_t value; bits256 txid; sprintf(params,"[\"%s\", 1]",txidstr); if ( (retstr= komodo_issuemethod((char *)"getrawtransaction",params,port)) != 0 ) { @@ -357,11 +357,10 @@ int32_t komodo_gateway_tx(char *symbol,int32_t height,int32_t txi,char *txidstr, { if ( (result= jobj(json,(char *)"result")) != 0 ) { - printf("RESULT.(%s)\n",jprint(result,0)); - vpub_old = jdouble(result,(char *)"vpub_old") * COIN; - vpub_new = jdouble(result,(char *)"vpub_new") * COIN; + oldpub = jobj(result,(char *)"vpub_old"); + newpub = jobj(result,(char *)"vpub_new"); retval = 0; - if ( vpub_old == 0 && vpub_new == 0 && (vouts= jarray(&n,result,(char *)"vout")) != 0 ) + if ( oldpub == 0 && newpub == 0 && (vouts= jarray(&n,result,(char *)"vout")) != 0 ) { isspecial = 0; txid = jbits256(result,(char *)"txid"); diff --git a/src/komodo_pax.h b/src/komodo_pax.h index 312aa403c..ac94d8886 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -319,7 +319,7 @@ uint64_t komodo_paxcalc(uint32_t *pvals,int32_t baseid,int32_t relid,uint64_t ba //printf("base -> USD %llu, BTC %llu KMDUSD %llu\n",(long long)baseusd,(long long)btcusd,(long long)kmdusd); //printf("usdkmd.%llu basevolume.%llu baseusd.%llu paxvol.%llu usdvol.%llu -> %.8f\n",(long long)usdkmd,(long long)basevolume,(long long)baseusd,(long long)komodo_paxvol(basevolume,baseusd),(long long)usdvol,dstr(MINDENOMS[USD] * komodo_paxvol(usdvol,usdkmd))); return(MINDENOMS[USD] * komodo_paxvol(usdvol,usdkmd)); - } else printf("zero val in KMD conv %llu %llu %llu\n",(long long)pvals[USD],(long long)kmdbtc,(long long)btcusd); + } //else printf("zero val in KMD conv %llu %llu %llu\n",(long long)pvals[USD],(long long)kmdbtc,(long long)btcusd); } else if ( baseid == relid ) { From 0f0d8331c4acdcb4aeaf81191a066447c59ae8a0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 7 Nov 2016 08:30:47 -0300 Subject: [PATCH 204/254] test --- src/chainparams.cpp | 2 +- src/komodo_gateway.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 127983a17..991cc1333 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -137,7 +137,7 @@ void *chainparams_commandline(void *ptr) { sleep(1); } - fprintf(stderr,">>>>>>>> port.%u\n",ASSETCHAINS_PORT); + //fprintf(stderr,">>>>>>>> port.%u\n",ASSETCHAINS_PORT); if ( ASSETCHAINS_SYMBOL[0] != 0 ) { mainParams.SetDefaultPort(ASSETCHAINS_PORT); diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 352971965..6e147e650 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -40,7 +40,7 @@ uint64_t komodo_paxtotal() { struct pax_transaction *pax,*tmp; uint64_t total = 0; tmp = 0; - while ( (pax= (struct pax_transaction *)PAX->hh.next) != 0 && pax != tmp ) + while ( PAX != 0 && (pax= (struct pax_transaction *)PAX->hh.next) != 0 && pax != tmp ) { if ( pax->marked == 0 ) total += pax->fiatoshis; @@ -153,7 +153,7 @@ void komodo_gateway_deposits(CMutableTransaction *txNew,int32_t shortflag,char * opcode = 'I'; else opcode = 'X'; tmp = 0; - while ( (pax= (struct pax_transaction *)PAX->hh.next) != 0 && pax != tmp ) + while ( PAX != 0 && (pax= (struct pax_transaction *)PAX->hh.next) != 0 && pax != tmp ) { if ( pax->marked != 0 ) continue; From 6458297e3037e807787c170fc34e9056dbd6a1e6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 7 Nov 2016 09:16:20 -0300 Subject: [PATCH 205/254] test --- src/komodo.h | 2 +- src/komodo_gateway.h | 5 +++-- src/miner.cpp | 5 +++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index be41bed06..2c812bc38 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -152,7 +152,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar } if ( height <= 0 ) { - printf("early return: stateupdate height.%d\n",height); + //printf("early return: stateupdate height.%d\n",height); return; } if ( fp != 0 ) // write out funcid, height, other fields, call side effect function diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 6e147e650..b3d5da869 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -174,10 +174,10 @@ void komodo_gateway_deposits(CMutableTransaction *txNew,int32_t shortflag,char * } data[len++] = pax->vout & 0xff; data[len++] = (pax->vout >> 8) & 0xff; - printf(" vout.%u DEPOSIT %.8f <- paxdeposit.%s\n",pax->vout,(double)txNew->vout[numvouts].nValue/COIN,symbol); if ( strcmp(symbol,"KMD") != 0 ) PENDING_KOMODO_TX += pax->fiatoshis; else PENDING_KOMODO_TX += pax->komodoshis; + printf(" vout.%u DEPOSIT %.8f <- paxdeposit.%s pending %.8f\n",pax->vout,(double)txNew->vout[numvouts].nValue/COIN,symbol,dstr(PENDING_KOMODO_TX)); if ( numvouts++ >= 64 ) break; tmp = pax; @@ -470,7 +470,8 @@ void komodo_gateway_iteration(char *symbol) printf("error from %s\n",symbol); sleep(30); } - KOMODO_DEPOSIT = komodo_paxtotal(); + if ( (KOMODO_DEPOSIT= komodo_paxtotal()) != 0 ) + printf("KOMODO_DEPOSIT %.8f RT.%u\n",dstr(KOMODO_DEPOSIT),KOMODO_REALTIME); } void komodo_iteration(char *symbol) diff --git a/src/miner.cpp b/src/miner.cpp index dc4d9f416..06c1aac80 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -113,6 +113,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) if(!pblocktemplate.get()) return NULL; CBlock *pblock = &pblocktemplate->block; // pointer for convenience + fprintf(stderr,"CreateNewBlock initdone.%d deposit %.8f\n",KOMODO_INITDONE,dstr(KOMODO_DEPOSIT)); while ( chainActive.Tip()->nHeight > ASSETCHAINS_MINHEIGHT && mempool.GetTotalTxSize() <= 0 ) { sleep(10); @@ -442,7 +443,7 @@ int32_t komodo_chosennotary(int32_t *notaryidp,int32_t height,uint8_t *pubkey33) CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey) { CPubKey pubkey; CScript scriptPubKey; uint8_t *script,*ptr; int32_t i; - //fprintf(stderr,"%s createnewblockwith key\n",ASSETCHAINS_SYMBOL); + fprintf(stderr,"%s createnewblockwith key\n",ASSETCHAINS_SYMBOL); if ( USE_EXTERNAL_PUBKEY != 0 ) { //fprintf(stderr,"use notary pubkey\n"); @@ -557,7 +558,7 @@ void static BitcoinMiner(CWallet *pwallet) } while (true); //fprintf(stderr,"%s Found peers\n",ASSETCHAINS_SYMBOL); } - //fprintf(stderr,"%s create new block\n",ASSETCHAINS_SYMBOL); + fprintf(stderr,"%s create new block\n",ASSETCHAINS_SYMBOL); // // Create new block // From 63d48f2fc9bb4375aa0883ad722c44aa5088481b Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 7 Nov 2016 09:18:12 -0300 Subject: [PATCH 206/254] test --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index 06c1aac80..1afd34b4b 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -113,7 +113,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) if(!pblocktemplate.get()) return NULL; CBlock *pblock = &pblocktemplate->block; // pointer for convenience - fprintf(stderr,"CreateNewBlock initdone.%d deposit %.8f\n",KOMODO_INITDONE,dstr(KOMODO_DEPOSIT)); + fprintf(stderr,"CreateNewBlock initdone.%d deposit %.8f\n",KOMODO_INITDONE,(double)KOMODO_DEPOSIT/COIN); while ( chainActive.Tip()->nHeight > ASSETCHAINS_MINHEIGHT && mempool.GetTotalTxSize() <= 0 ) { sleep(10); From 581c5dedb330c004fb5f07265d233cfe5ec05361 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 7 Nov 2016 09:22:18 -0300 Subject: [PATCH 207/254] test --- src/komodo_gateway.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index b3d5da869..da5af5d88 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -155,6 +155,7 @@ void komodo_gateway_deposits(CMutableTransaction *txNew,int32_t shortflag,char * tmp = 0; while ( PAX != 0 && (pax= (struct pax_transaction *)PAX->hh.next) != 0 && pax != tmp ) { + printf("pax.%p marked.%d %.8f -> %.8f\n",pax,pax->marked,dstr(pax->komodoshis),dstr(pax->fiatoshis)); if ( pax->marked != 0 ) continue; txNew->vout.resize(numvouts+1); From f846a85733062831e2e3e5110f7c1767ee8f9e3a Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 7 Nov 2016 14:21:35 -0300 Subject: [PATCH 208/254] test --- src/komodo_gateway.h | 8 +++++--- src/komodo_globals.h | 2 +- src/miner.cpp | 10 +++++----- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index da5af5d88..1ad9e22da 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -43,7 +43,11 @@ uint64_t komodo_paxtotal() while ( PAX != 0 && (pax= (struct pax_transaction *)PAX->hh.next) != 0 && pax != tmp ) { if ( pax->marked == 0 ) - total += pax->fiatoshis; + { + if ( ASSETCHAINS_SYMBOL[0] == 0 ) + total += pax->fiatoshis; + else total += pax->komodoshis; + } tmp = pax; pax = (struct pax_transaction *)pax->hh.next; } @@ -471,8 +475,6 @@ void komodo_gateway_iteration(char *symbol) printf("error from %s\n",symbol); sleep(30); } - if ( (KOMODO_DEPOSIT= komodo_paxtotal()) != 0 ) - printf("KOMODO_DEPOSIT %.8f RT.%u\n",dstr(KOMODO_DEPOSIT),KOMODO_REALTIME); } void komodo_iteration(char *symbol) diff --git a/src/komodo_globals.h b/src/komodo_globals.h index 4cd550141..e0516aa31 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -31,4 +31,4 @@ uint256 NOTARIZED_HASH,NOTARIZED_DESTTXID; pthread_mutex_t komodo_mutex; uint32_t KOMODO_INITDONE,KOMODO_REALTIME; char KMDUSERPASS[1024]; uint16_t BITCOIND_PORT = 7771; -uint64_t KOMODO_DEPOSIT,PENDING_KOMODO_TX; +uint64_t PENDING_KOMODO_TX; diff --git a/src/miner.cpp b/src/miner.cpp index 1afd34b4b..51d8add99 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -102,29 +102,29 @@ void UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams, int32_t komodo_pax_opreturn(uint8_t *opret,int32_t maxsize); void komodo_gateway_deposits(CMutableTransaction *txNew,int32_t shortflag,char *symbol); extern int32_t KOMODO_INITDONE,ASSETCHAINS_SHORTFLAG; -extern uint64_t KOMODO_DEPOSIT; extern char ASSETCHAINS_SYMBOL[16]; CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) { - const CChainParams& chainparams = Params(); + uint64_t deposits; const CChainParams& chainparams = Params(); // Create new block unique_ptr pblocktemplate(new CBlockTemplate()); if(!pblocktemplate.get()) return NULL; CBlock *pblock = &pblocktemplate->block; // pointer for convenience - fprintf(stderr,"CreateNewBlock initdone.%d deposit %.8f\n",KOMODO_INITDONE,(double)KOMODO_DEPOSIT/COIN); while ( chainActive.Tip()->nHeight > ASSETCHAINS_MINHEIGHT && mempool.GetTotalTxSize() <= 0 ) { + deposit = komodo_paxtotal(); + fprintf(stderr,"CreateNewBlock initdone.%d deposit %.8f mempool.%d\n",KOMODO_INITDONE,(double)deposits/COIN,(int32_t)mempool.GetTotalTxSize()); sleep(10); if ( KOMODO_INITDONE == 0 || time(NULL) < KOMODO_INITDONE+60 ) continue; - if ( KOMODO_DEPOSIT != 0 ) + if ( deposit != 0 ) { - printf("miner KOMODO_DEPOSIT %llu pblock->nHeight %d mempool.GetTotalTxSize(%d)\n",(long long)KOMODO_DEPOSIT,(int32_t)chainActive.Tip()->nHeight,(int32_t)mempool.GetTotalTxSize()); break; } } + printf("miner KOMODO_DEPOSIT %llu pblock->nHeight %d mempool.GetTotalTxSize(%d)\n",(long long)deposit,(int32_t)chainActive.Tip()->nHeight,(int32_t)mempool.GetTotalTxSize()); // -regtest only: allow overriding block.nVersion with // -blockversion=N to test forking scenarios From 9cc05f24d7fca1bf32b4549cba9612099bd98783 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 7 Nov 2016 14:24:18 -0300 Subject: [PATCH 209/254] test --- src/miner.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 51d8add99..da72e6c35 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -100,6 +100,7 @@ void UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams, #define ASSETCHAINS_MINHEIGHT 100 int32_t komodo_pax_opreturn(uint8_t *opret,int32_t maxsize); +uint64_t komodo_paxtotal(); void komodo_gateway_deposits(CMutableTransaction *txNew,int32_t shortflag,char *symbol); extern int32_t KOMODO_INITDONE,ASSETCHAINS_SHORTFLAG; extern char ASSETCHAINS_SYMBOL[16]; @@ -114,17 +115,17 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) CBlock *pblock = &pblocktemplate->block; // pointer for convenience while ( chainActive.Tip()->nHeight > ASSETCHAINS_MINHEIGHT && mempool.GetTotalTxSize() <= 0 ) { - deposit = komodo_paxtotal(); + deposits = komodo_paxtotal(); fprintf(stderr,"CreateNewBlock initdone.%d deposit %.8f mempool.%d\n",KOMODO_INITDONE,(double)deposits/COIN,(int32_t)mempool.GetTotalTxSize()); sleep(10); if ( KOMODO_INITDONE == 0 || time(NULL) < KOMODO_INITDONE+60 ) continue; - if ( deposit != 0 ) + if ( deposits != 0 ) { break; } } - printf("miner KOMODO_DEPOSIT %llu pblock->nHeight %d mempool.GetTotalTxSize(%d)\n",(long long)deposit,(int32_t)chainActive.Tip()->nHeight,(int32_t)mempool.GetTotalTxSize()); + printf("miner KOMODO_DEPOSIT %llu pblock->nHeight %d mempool.GetTotalTxSize(%d)\n",(long long)deposits,(int32_t)chainActive.Tip()->nHeight,(int32_t)mempool.GetTotalTxSize()); // -regtest only: allow overriding block.nVersion with // -blockversion=N to test forking scenarios From 27ec4f4ea3b27cfd39b0940fc77ceb281e860d1b Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 7 Nov 2016 14:32:55 -0300 Subject: [PATCH 210/254] 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 1ad9e22da..faea16680 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -269,7 +269,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 if ( fiatoshis < 0 ) fiatoshis = -fiatoshis; bitcoin_address(coinaddr,addrtype,rmd160,20); - checktoshis = PAX_fiatdest(tokomodo,destaddr,pubkey33,coinaddr,height,base,fiatoshis); + checktoshis = PAX_fiatdest(tokomodo,destaddr,pubkey33,coinaddr,height-1,base,fiatoshis); typestr = "deposit"; if ( tokomodo == 0 && strncmp(ASSETCHAINS_SYMBOL,base,strlen(base)) == 0 && shortflag == ASSETCHAINS_SHORTFLAG ) { From 05a37d87828cac23f8d0d514f8bcb8f1b7c1c0ca Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 7 Nov 2016 14:57:08 -0300 Subject: [PATCH 211/254] test --- src/komodo_gateway.h | 87 ++++++++++++++++++++++++---------------- src/wallet/rpcwallet.cpp | 11 ++--- 2 files changed, 58 insertions(+), 40 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index faea16680..27b3e3f17 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -112,7 +112,7 @@ void komodo_gateway_deposit(char *coinaddr,uint64_t value,int32_t shortflag,char memcpy(pax->rmd160,rmd160,20); pax->height = height; if ( pax->marked == 0 ) - printf("ADD DEPOSIT %s %.8f -> %s TO PAX ht.%d\n",symbol,dstr(fiatoshis),coinaddr,height); + printf("ADD DEPOSIT %s %.8f -> %s TO PAX ht.%d total %.8f\n",symbol,dstr(fiatoshis),coinaddr,height,dstr(komodo_total())); else printf("MARKED.%d DEPOSIT %s %.8f -> %s TO PAX ht.%d\n",pax->marked,symbol,dstr(fiatoshis),coinaddr,height); } else @@ -252,49 +252,66 @@ 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) { - uint8_t rmd160[20],addrtype,shortflag,pubkey33[33]; int32_t i,j,n,len,tokomodo=0; char base[4],coinaddr[64],destaddr[64]; struct pax_transaction space; uint256 txids[64]; uint16_t vouts[64]; int64_t fiatoshis,checktoshis; const char *typestr = "unknown"; + uint8_t rmd160[20],addrtype,shortflag,pubkey33[33]; int32_t i,j,n,len,kmdheight,tokomodo=0; char base[4],coinaddr[64],destaddr[64]; struct pax_transaction space; uint256 txids[64]; uint16_t vouts[64]; int64_t fiatoshis,checktoshis; const char *typestr = "unknown"; tokomodo = (komodo_is_issuer() == 0); if ( opretbuf[0] == 'D' ) { - if ( opretlen == 34 ) // any KMD tx + if ( opretlen == 38 ) // any KMD tx { - if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 ) + iguana_rwnum(0,&opretbuf[34],sizeof(kmdheight),&kmdheight); + if ( kmdheight <= height ) { - for (i=0; i= checktoshis ) - { - if ( komodo_paxfind(&space,txid,vout) == 0 ) - komodo_gateway_deposit(coinaddr,value,shortflag,base,fiatoshis,rmd160,txid,vout,height); - } - } - else // short + if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 ) { for (i=0; i dest.(RQY5zAq49YYc8knVkBBpxuxbQa3xwhaw5z) komodoshis.7763390 + //6a22440245555240420f00000000003c8390ec7bac0c84d9ceb39b1f31564c983123b8e4 opretbuf[36] + //9b51f402d7f5afde938b96f0c69d4114f2033a7ebd4db11eee7f2b6a94f00bca + /*{ + "base" : "eur", + "rel" : "kmd", + "height" : 59480, + "timestamp" : 1478540309, + "price" : 7.76339000, + "invprice" : 0.12880971, + "basevolume" : 1.00000000, + "relvolume" : 7.76339000 + }*/ + if ( tokomodo == 0 && strncmp(ASSETCHAINS_SYMBOL,base,strlen(base)) == 0 && shortflag == ASSETCHAINS_SHORTFLAG ) + { + if ( shortflag == 0 ) { - + for (i=0; i<32; i++) + printf("%02x",((uint8_t *)&txid)[i]); + printf(" <- txid.v%u ",vout); + for (i=0; i<33; i++) + printf("%02x",pubkey33[i]); + printf(" checkpubkey check %.8f v %.8f dest.(%s) kmdheight.%d height.%d\n",dstr(checktoshis),dstr(value),destaddr,kmdheight,height); + if ( value >= checktoshis ) + { + if ( komodo_paxfind(&space,txid,vout) == 0 ) + komodo_gateway_deposit(coinaddr,value,shortflag,base,fiatoshis,rmd160,txid,vout,kmdheight); + } + } + else // short + { + for (i=0; inHeight,(char *)base.c_str(),fiatoshis); + komodoshis = PAX_fiatdest(0,destaddr,pubkey37,(char *)params[0].get_str().c_str(),chainActive.Tip()->nHeight,(char *)base.c_str(),fiatoshis); dest.append(destaddr); CBitcoinAddress destaddress(CRYPTO777_KMDADDR); if (!destaddress.IsValid()) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid dest Bitcoin address"); for (i=0; i<33; i++) - printf("%02x",pubkey33[i]); + printf("%02x",pubkey37[i]); printf(" ht.%d srcaddr.(%s) %s fiatoshis.%lld -> dest.(%s) komodoshis.%llu\n",chainActive.Tip()->nHeight,(char *)params[0].get_str().c_str(),(char *)base.c_str(),(long long)fiatoshis,destaddr,(long long)komodoshis); EnsureWalletIsUnlocked(); CWalletTx wtx; uint8_t opretbuf[64]; int32_t opretlen; uint64_t fee = komodoshis / 1000; if ( fee < 10000 ) fee = 10000; - opretlen = komodo_opreturnscript(opretbuf,'D',pubkey33,33); + iguana_rwnum(1,&pubkey37[33],sizeof(height),&height); + opretlen = komodo_opreturnscript(opretbuf,'D',pubkey37,33); SendMoney(address.Get(),fee,fSubtractFeeFromAmount,wtx,opretbuf,opretlen,komodoshis); return wtx.GetHash().GetHex(); } From 3835b9885ca503fab76d39873f440d0db86cb372 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 7 Nov 2016 14:58:46 -0300 Subject: [PATCH 212/254] 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 27b3e3f17..74b6e7bed 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -112,7 +112,7 @@ void komodo_gateway_deposit(char *coinaddr,uint64_t value,int32_t shortflag,char memcpy(pax->rmd160,rmd160,20); pax->height = height; if ( pax->marked == 0 ) - printf("ADD DEPOSIT %s %.8f -> %s TO PAX ht.%d total %.8f\n",symbol,dstr(fiatoshis),coinaddr,height,dstr(komodo_total())); + printf("ADD DEPOSIT %s %.8f -> %s TO PAX ht.%d total %.8f\n",symbol,dstr(fiatoshis),coinaddr,height,dstr(komodo_paxtotal())); else printf("MARKED.%d DEPOSIT %s %.8f -> %s TO PAX ht.%d\n",pax->marked,symbol,dstr(fiatoshis),coinaddr,height); } else From eef6d3e43fa29732afb2f70741315e8f16dee386 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 7 Nov 2016 15:01:23 -0300 Subject: [PATCH 213/254] test --- src/wallet/rpcwallet.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 148f9cfbb..554abef48 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -474,7 +474,7 @@ int32_t iguana_rwnum(int32_t rwflag,uint8_t *serialized,int32_t len,void *endian Value paxdeposit(const Array& params, bool fHelp) { - uint64_t komodoshis = 0; char destaddr[64]; uint8_t i,pubkey37[33]; + uint64_t komodoshis = 0; int32_t height; char destaddr[64]; uint8_t i,pubkey37[33]; bool fSubtractFeeFromAmount = false; if ( ASSETCHAINS_SYMBOL[0] != 0 ) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "paxdeposit only from KMD"); @@ -489,7 +489,8 @@ Value paxdeposit(const Array& params, bool fHelp) int64_t fiatoshis = atof(params[1].get_str().c_str()) * COIN; std::string base = params[2].get_str(); std::string dest; - komodoshis = PAX_fiatdest(0,destaddr,pubkey37,(char *)params[0].get_str().c_str(),chainActive.Tip()->nHeight,(char *)base.c_str(),fiatoshis); + height = chainActive.Tip()->nHeight; + komodoshis = PAX_fiatdest(0,destaddr,pubkey37,(char *)params[0].get_str().c_str(),height,(char *)base.c_str(),fiatoshis); dest.append(destaddr); CBitcoinAddress destaddress(CRYPTO777_KMDADDR); if (!destaddress.IsValid()) From 6b450b70649c725aec8ee04c726f282a1c651474 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 7 Nov 2016 15:09:19 -0300 Subject: [PATCH 214/254] test --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 554abef48..3beae86c1 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -504,7 +504,7 @@ Value paxdeposit(const Array& params, bool fHelp) if ( fee < 10000 ) fee = 10000; iguana_rwnum(1,&pubkey37[33],sizeof(height),&height); - opretlen = komodo_opreturnscript(opretbuf,'D',pubkey37,33); + opretlen = komodo_opreturnscript(opretbuf,'D',pubkey37,37); SendMoney(address.Get(),fee,fSubtractFeeFromAmount,wtx,opretbuf,opretlen,komodoshis); return wtx.GetHash().GetHex(); } From 2274b29bd49842521779ddb91d013c95287a8484 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 7 Nov 2016 15:14:56 -0300 Subject: [PATCH 215/254] test --- src/miner.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index da72e6c35..cf8bea4fc 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -116,7 +116,8 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) while ( chainActive.Tip()->nHeight > ASSETCHAINS_MINHEIGHT && mempool.GetTotalTxSize() <= 0 ) { deposits = komodo_paxtotal(); - fprintf(stderr,"CreateNewBlock initdone.%d deposit %.8f mempool.%d\n",KOMODO_INITDONE,(double)deposits/COIN,(int32_t)mempool.GetTotalTxSize()); + if ( ASSETCHAINS_SYMBOL[0] != 0 ) + fprintf(stderr,"CreateNewBlock initdone.%d deposit %.8f mempool.%d\n",KOMODO_INITDONE,(double)deposits/COIN,(int32_t)mempool.GetTotalTxSize()); sleep(10); if ( KOMODO_INITDONE == 0 || time(NULL) < KOMODO_INITDONE+60 ) continue; @@ -125,7 +126,8 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) break; } } - printf("miner KOMODO_DEPOSIT %llu pblock->nHeight %d mempool.GetTotalTxSize(%d)\n",(long long)deposits,(int32_t)chainActive.Tip()->nHeight,(int32_t)mempool.GetTotalTxSize()); + if ( ASSETCHAINS_SYMBOL[0] != 0 ) + printf("miner KOMODO_DEPOSIT %llu pblock->nHeight %d mempool.GetTotalTxSize(%d)\n",(long long)deposits,(int32_t)chainActive.Tip()->nHeight,(int32_t)mempool.GetTotalTxSize()); // -regtest only: allow overriding block.nVersion with // -blockversion=N to test forking scenarios @@ -444,7 +446,8 @@ int32_t komodo_chosennotary(int32_t *notaryidp,int32_t height,uint8_t *pubkey33) CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey) { CPubKey pubkey; CScript scriptPubKey; uint8_t *script,*ptr; int32_t i; - fprintf(stderr,"%s createnewblockwith key\n",ASSETCHAINS_SYMBOL); + if ( ASSETCHAINS_SYMBOL[0] != 0 ) + fprintf(stderr,"%s createnewblockwith key\n",ASSETCHAINS_SYMBOL); if ( USE_EXTERNAL_PUBKEY != 0 ) { //fprintf(stderr,"use notary pubkey\n"); @@ -559,7 +562,8 @@ void static BitcoinMiner(CWallet *pwallet) } while (true); //fprintf(stderr,"%s Found peers\n",ASSETCHAINS_SYMBOL); } - fprintf(stderr,"%s create new block\n",ASSETCHAINS_SYMBOL); + if ( ASSETCHAINS_SYMBOL[0] != 0 ) + fprintf(stderr,"%s create new block\n",ASSETCHAINS_SYMBOL); // // Create new block // From 3f0813b335440ff572a8970c6ebb376fcfecad17 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 7 Nov 2016 15:22:43 -0300 Subject: [PATCH 216/254] test --- src/komodo_gateway.h | 2 +- src/miner.cpp | 12 +++++------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 74b6e7bed..243385ad8 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -153,7 +153,7 @@ void komodo_gateway_deposits(CMutableTransaction *txNew,int32_t shortflag,char * { struct pax_transaction *pax,*tmp; uint8_t *script,opcode,opret[10000],data[10000]; int32_t i,len=0,opretlen=0,numvouts=1; PENDING_KOMODO_TX = 0; - if ( strcmp(symbol,"KMD") != 0 ) + if ( strcmp(symbol,"KMD") == 0 ) opcode = 'I'; else opcode = 'X'; tmp = 0; diff --git a/src/miner.cpp b/src/miner.cpp index cf8bea4fc..f993a598c 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -113,11 +113,10 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) if(!pblocktemplate.get()) return NULL; CBlock *pblock = &pblocktemplate->block; // pointer for convenience + fprintf(stderr,"start CreateNewBlock initdone.%d deposit %.8f mempool.%d\n",KOMODO_INITDONE,(double)komodo_paxtotal()/COIN,(int32_t)mempool.GetTotalTxSize()); while ( chainActive.Tip()->nHeight > ASSETCHAINS_MINHEIGHT && mempool.GetTotalTxSize() <= 0 ) { deposits = komodo_paxtotal(); - if ( ASSETCHAINS_SYMBOL[0] != 0 ) - fprintf(stderr,"CreateNewBlock initdone.%d deposit %.8f mempool.%d\n",KOMODO_INITDONE,(double)deposits/COIN,(int32_t)mempool.GetTotalTxSize()); sleep(10); if ( KOMODO_INITDONE == 0 || time(NULL) < KOMODO_INITDONE+60 ) continue; @@ -127,7 +126,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) } } if ( ASSETCHAINS_SYMBOL[0] != 0 ) - printf("miner KOMODO_DEPOSIT %llu pblock->nHeight %d mempool.GetTotalTxSize(%d)\n",(long long)deposits,(int32_t)chainActive.Tip()->nHeight,(int32_t)mempool.GetTotalTxSize()); + printf("miner KOMODO_DEPOSIT %llu pblock->nHeight %d mempool.GetTotalTxSize(%d)\n",(long long)komodo_paxtotal(),(int32_t)chainActive.Tip()->nHeight,(int32_t)mempool.GetTotalTxSize()); // -regtest only: allow overriding block.nVersion with // -blockversion=N to test forking scenarios @@ -326,8 +325,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) if (fPrintPriority) { - LogPrintf("priority %.1f fee %s txid %s\n", - dPriority, feeRate.ToString(), tx.GetHash().ToString()); + LogPrintf("priority %.1f fee %s txid %s\n",dPriority, feeRate.ToString(), tx.GetHash().ToString()); } // Add transactions that depend on this one to the priority queue @@ -381,7 +379,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) else { komodo_gateway_deposits(&txNew,0,(char *)"KMD"); - //fprintf(stderr,"txNew numvouts.%d\n",(int32_t)txNew.vout.size()); + fprintf(stderr,"txNew numvouts.%d\n",(int32_t)txNew.vout.size()); } pblock->vtx[0] = txNew; @@ -592,7 +590,7 @@ void static BitcoinMiner(CWallet *pwallet) { hashTarget = arith_uint256().SetCompact(KOMODO_MINDIFF_NBITS); Mining_start = (uint32_t)time(NULL); - //fprintf(stderr,"I am the chosen one for ht.%d\n",pindexPrev->nHeight+1); + fprintf(stderr,"I am the chosen one for %s ht.%d\n",ASSETCHAINS_SYMBOL,pindexPrev->nHeight+1); } else Mining_start = 0; Mining_height = pindexPrev->nHeight+1; //fprintf(stderr,"%s start mining loop\n",ASSETCHAINS_SYMBOL); From 31eef660e414351f1c9caeacbb387c0e0ab4bb1e Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 7 Nov 2016 15:39:42 -0300 Subject: [PATCH 217/254] test --- src/komodo_pax.h | 2 +- src/miner.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_pax.h b/src/komodo_pax.h index ac94d8886..77fb30f37 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -426,7 +426,7 @@ uint64_t komodo_paxprice(int32_t height,char *base,char *rel,uint64_t basevolume } sum /= densum; sum = (sum * basevolume) / 100000; - //printf("seed.%llx sum %.8f densum %.8f basevol %.8f\n",(long long)seed,dstr(sum),dstr(densum),dstr(basevolume)); + printf("paxprice seed.%llx sum %.8f densum %.8f basevol %.8f height.%d\n",(long long)seed,dstr(sum),dstr(densum),dstr(basevolume),height); break; } } diff --git a/src/miner.cpp b/src/miner.cpp index f993a598c..5125f3b88 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -113,7 +113,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) if(!pblocktemplate.get()) return NULL; CBlock *pblock = &pblocktemplate->block; // pointer for convenience - fprintf(stderr,"start CreateNewBlock initdone.%d deposit %.8f mempool.%d\n",KOMODO_INITDONE,(double)komodo_paxtotal()/COIN,(int32_t)mempool.GetTotalTxSize()); + fprintf(stderr,"start CreateNewBlock %s initdone.%d deposit %.8f mempool.%d\n",ASSETCHAINS_SYMBOL,KOMODO_INITDONE,(double)komodo_paxtotal()/COIN,(int32_t)mempool.GetTotalTxSize()); while ( chainActive.Tip()->nHeight > ASSETCHAINS_MINHEIGHT && mempool.GetTotalTxSize() <= 0 ) { deposits = komodo_paxtotal(); From 1e004600c733e7e59fdca5fe66e35be25cd00669 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 7 Nov 2016 15:50:13 -0300 Subject: [PATCH 218/254] test --- src/komodo_gateway.h | 35 ++++++++++++++++++++++------------- src/komodo_pax.h | 1 + src/wallet/rpcwallet.cpp | 2 +- 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 243385ad8..4a218b4a6 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -274,19 +274,28 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 bitcoin_address(coinaddr,addrtype,rmd160,20); checktoshis = PAX_fiatdest(tokomodo,destaddr,pubkey33,coinaddr,kmdheight,base,fiatoshis); typestr = "deposit"; - //0245555240420f00000000003c8390ec7bac0c84d9ceb39b1f31564c983123b8e4 ht.59480 srcaddr.(RMGrD8DzED6YYT63z1TaF4sVTCB7Qqvj1Z) eur fiatoshis.1000000 -> dest.(RQY5zAq49YYc8knVkBBpxuxbQa3xwhaw5z) komodoshis.7763390 - //6a22440245555240420f00000000003c8390ec7bac0c84d9ceb39b1f31564c983123b8e4 opretbuf[36] - //9b51f402d7f5afde938b96f0c69d4114f2033a7ebd4db11eee7f2b6a94f00bca - /*{ - "base" : "eur", - "rel" : "kmd", - "height" : 59480, - "timestamp" : 1478540309, - "price" : 7.76339000, - "invprice" : 0.12880971, - "basevolume" : 1.00000000, - "relvolume" : 7.76339000 - }*/ + //paxprice seed.0 sum 0.07766840 densum 1000.00000000 basevol 0.01000000 height.59532 + + // 0.07759490 + /* ./komodo-cli paxdeposit RMGrD8DzED6YYT63z1TaF4sVTCB7Qqvj1Z 0.01 eur + 0245555240420f00000000003c8390ec7bac0c84d9ceb39b1f31564c983123b8e4 ht.59532 srcaddr.(RMGrD8DzED6YYT63z1TaF4sVTCB7Qqvj1Z) eur fiatoshis.1000000 -> dest.(RQY5zAq49YYc8knVkBBpxuxbQa3xwhaw5z) komodoshis.7759490 + 6a26440245555240420f00000000003c8390ec7bac0c84d9ceb39b1f31564c983123b8e48ce80000 opretbuf[40] + b1d7350ef5a9502e1249384abccbc5aa78e3172d182757431f548728583de4a2 + root@devbox2:~/komodo/src# start CreateNewBlock initdone.1478543278 deposit 0.00000000 mempool.274 + start CreateNewBlock initdone.1478543372 deposit 0.00000000 mempool.0 + b1d7350ef5a9502e1249384abccbc5aa78e3172d182757431f548728583de4a2 <- txid.v2 0245555240420f00000000003c8390ec7bac0c84d9ceb39b1f31564c983123b8e4 checkpubkey check 0.07766840 v 0.07759490 dest.(RQY5zAq49YYc8knVkBBpxuxbQa3xwhaw5z) kmdheight.59532 height.59533 + ./komodo-cli paxprice eur kmd 59532 + { + "base" : "eur", + "rel" : "kmd", + "height" : 59532, + "timestamp" : 1478543277, + "price" : 7.75949000, + "invprice" : 0.12887445, + "basevolume" : 1.00000000, + "relvolume" : 7.75949000 + } +*/ if ( tokomodo == 0 && strncmp(ASSETCHAINS_SYMBOL,base,strlen(base)) == 0 && shortflag == ASSETCHAINS_SHORTFLAG ) { if ( shortflag == 0 ) diff --git a/src/komodo_pax.h b/src/komodo_pax.h index 77fb30f37..0c9ab121b 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -471,6 +471,7 @@ uint64_t PAX_fiatdest(int32_t tokomodo,char *destaddr,uint8_t pubkey33[33],char if ( fiatoshis < 0 ) shortflag = 1, fiatoshis = -fiatoshis; komodoshis = komodo_paxprice(height,base,(char *)"KMD",(uint64_t)fiatoshis); + printf("PAX_fiatdest ht.%d price %s %.8f -> KMD %.8f\n",height,base,(double)fiatoshis/COIN,(double)komodoshis/COIN); if ( bitcoin_addr2rmd160(&addrtype,rmd160,coinaddr) == 20 ) { PAX_pubkey(1,pubkey33,&addrtype,rmd160,base,&shortflag,tokomodo != 0 ? &komodoshis : &fiatoshis); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 3beae86c1..302f830e6 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -497,7 +497,7 @@ Value paxdeposit(const Array& params, bool fHelp) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid dest Bitcoin address"); for (i=0; i<33; i++) printf("%02x",pubkey37[i]); - printf(" ht.%d srcaddr.(%s) %s fiatoshis.%lld -> dest.(%s) komodoshis.%llu\n",chainActive.Tip()->nHeight,(char *)params[0].get_str().c_str(),(char *)base.c_str(),(long long)fiatoshis,destaddr,(long long)komodoshis); + printf(" ht.%d srcaddr.(%s) %s fiatoshis.%lld -> dest.(%s) komodoshis.%llu\n",height,(char *)params[0].get_str().c_str(),(char *)base.c_str(),(long long)fiatoshis,destaddr,(long long)komodoshis); EnsureWalletIsUnlocked(); CWalletTx wtx; uint8_t opretbuf[64]; int32_t opretlen; uint64_t fee = komodoshis / 1000; From 0bda62491474f0328a321df5143b30e9e5ed1fe1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 7 Nov 2016 16:08:35 -0300 Subject: [PATCH 219/254] test --- src/komodo_gateway.h | 25 ++----------------------- src/komodo_pax.h | 10 +++++----- src/rpcblockchain.cpp | 7 ++++--- src/wallet/rpcwallet.cpp | 10 +++++----- 4 files changed, 16 insertions(+), 36 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 4a218b4a6..42987a53d 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -252,7 +252,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) { - uint8_t rmd160[20],addrtype,shortflag,pubkey33[33]; int32_t i,j,n,len,kmdheight,tokomodo=0; char base[4],coinaddr[64],destaddr[64]; struct pax_transaction space; uint256 txids[64]; uint16_t vouts[64]; int64_t fiatoshis,checktoshis; const char *typestr = "unknown"; + uint8_t rmd160[20],addrtype,shortflag,pubkey33[33]; int32_t i,j,n,len,kmdheight,tokomodo=0; char base[4],coinaddr[64],destaddr[64]; struct pax_transaction space; uint256 txids[64]; uint16_t vouts[64]; uint64_t seed; int64_t fiatoshis,checktoshis; const char *typestr = "unknown"; tokomodo = (komodo_is_issuer() == 0); if ( opretbuf[0] == 'D' ) { @@ -272,30 +272,9 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 if ( fiatoshis < 0 ) fiatoshis = -fiatoshis; bitcoin_address(coinaddr,addrtype,rmd160,20); - checktoshis = PAX_fiatdest(tokomodo,destaddr,pubkey33,coinaddr,kmdheight,base,fiatoshis); + checktoshis = PAX_fiatdest(&seed,tokomodo,destaddr,pubkey33,coinaddr,kmdheight,base,fiatoshis); typestr = "deposit"; //paxprice seed.0 sum 0.07766840 densum 1000.00000000 basevol 0.01000000 height.59532 - - // 0.07759490 - /* ./komodo-cli paxdeposit RMGrD8DzED6YYT63z1TaF4sVTCB7Qqvj1Z 0.01 eur - 0245555240420f00000000003c8390ec7bac0c84d9ceb39b1f31564c983123b8e4 ht.59532 srcaddr.(RMGrD8DzED6YYT63z1TaF4sVTCB7Qqvj1Z) eur fiatoshis.1000000 -> dest.(RQY5zAq49YYc8knVkBBpxuxbQa3xwhaw5z) komodoshis.7759490 - 6a26440245555240420f00000000003c8390ec7bac0c84d9ceb39b1f31564c983123b8e48ce80000 opretbuf[40] - b1d7350ef5a9502e1249384abccbc5aa78e3172d182757431f548728583de4a2 - root@devbox2:~/komodo/src# start CreateNewBlock initdone.1478543278 deposit 0.00000000 mempool.274 - start CreateNewBlock initdone.1478543372 deposit 0.00000000 mempool.0 - b1d7350ef5a9502e1249384abccbc5aa78e3172d182757431f548728583de4a2 <- txid.v2 0245555240420f00000000003c8390ec7bac0c84d9ceb39b1f31564c983123b8e4 checkpubkey check 0.07766840 v 0.07759490 dest.(RQY5zAq49YYc8knVkBBpxuxbQa3xwhaw5z) kmdheight.59532 height.59533 - ./komodo-cli paxprice eur kmd 59532 - { - "base" : "eur", - "rel" : "kmd", - "height" : 59532, - "timestamp" : 1478543277, - "price" : 7.75949000, - "invprice" : 0.12887445, - "basevolume" : 1.00000000, - "relvolume" : 7.75949000 - } -*/ if ( tokomodo == 0 && strncmp(ASSETCHAINS_SYMBOL,base,strlen(base)) == 0 && shortflag == ASSETCHAINS_SHORTFLAG ) { if ( shortflag == 0 ) diff --git a/src/komodo_pax.h b/src/komodo_pax.h index 0c9ab121b..a10c4fc0c 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -360,7 +360,7 @@ uint64_t _komodo_paxprice(int32_t height,char *base,char *rel,uint64_t basevolum return(0); } -uint64_t komodo_paxprice(int32_t height,char *base,char *rel,uint64_t basevolume) +uint64_t komodo_paxprice(uint64_t *seedp,int32_t height,char *base,char *rel,uint64_t basevolume) { int32_t i,j,k,ind,zeroes,numvotes,wt,nonz; int64_t delta; uint64_t lastprice,seed,tolerance,den,densum,sum=0,votes[539]; if ( basevolume > 10000*COIN ) @@ -391,7 +391,7 @@ uint64_t komodo_paxprice(int32_t height,char *base,char *rel,uint64_t basevolume else lastprice = votes[i]; } //printf("\n}; // numvotes.%d\n\n",numvotes); - seed = komodo_seed(height); + *seedp = seed = komodo_seed(height); tolerance = sum / 50; for (k=0; k KMD %.8f\n",height,base,(double)fiatoshis/COIN,(double)komodoshis/COIN); + komodoshis = komodo_paxprice(seedp,height,base,(char *)"KMD",(uint64_t)fiatoshis); + //printf("PAX_fiatdest ht.%d price %s %.8f -> KMD %.8f\n",height,base,(double)fiatoshis/COIN,(double)komodoshis/COIN); if ( bitcoin_addr2rmd160(&addrtype,rmd160,coinaddr) == 20 ) { PAX_pubkey(1,pubkey33,&addrtype,rmd160,base,&shortflag,tokomodo != 0 ? &komodoshis : &fiatoshis); diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 1dadc4784..50175873e 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -382,7 +382,7 @@ Value gettxoutsetinfo(const Array& params, bool fHelp) uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uint32_t tiptime); uint32_t komodo_txtime(uint256 hash); -uint64_t komodo_paxprice(int32_t height,char *base,char *rel,uint64_t basevolume); +uint64_t komodo_paxprice(uint64_t *seedp,int32_t height,char *base,char *rel,uint64_t basevolume); int32_t komodo_paxprices(int32_t *heights,uint64_t *prices,int32_t max,char *base,char *rel); 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); @@ -434,16 +434,17 @@ Value paxprice(const Array& params, bool fHelp) if ( fHelp || params.size() < 3 || params.size() > 4 ) throw runtime_error("paxprice \"base\" \"rel\" height amount\n"); LOCK(cs_main); - Object ret; uint64_t basevolume=0,relvolume; + Object ret; uint64_t basevolume=0,relvolume,seed; std::string base = params[0].get_str(); std::string rel = params[1].get_str(); int32_t height = atoi(params[2].get_str().c_str()); if ( params.size() == 3 || (basevolume= COIN * atof(params[3].get_str().c_str())) == 0 ) basevolume = COIN; - relvolume = komodo_paxprice(height,(char *)base.c_str(),(char *)rel.c_str(),basevolume); + relvolume = komodo_paxprice(&seed,height,(char *)base.c_str(),(char *)rel.c_str(),basevolume); ret.push_back(Pair("base", base)); ret.push_back(Pair("rel", rel)); ret.push_back(Pair("height", height)); + ret.push_back(Pair("seed", seed)); if ( height < 0 || height > chainActive.Height() ) throw JSONRPCError(RPC_INVALID_PARAMETER, "Block height out of range"); else diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 302f830e6..e51113356 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -466,7 +466,7 @@ Value sendtoaddress(const Array& params, bool fHelp) return wtx.GetHash().GetHex(); } -uint64_t PAX_fiatdest(int32_t tokomodo,char *destaddr,uint8_t pubkey37[37],char *coinaddr,int32_t height,char *base,int64_t fiatoshis); +uint64_t PAX_fiatdest(uint64_t *seedp,int32_t tokomodo,char *destaddr,uint8_t pubkey37[37],char *coinaddr,int32_t height,char *base,int64_t fiatoshis); int32_t komodo_opreturnscript(uint8_t *script,uint8_t type,uint8_t *opret,int32_t opretlen); #define CRYPTO777_KMDADDR "RXL3YXG2ceaB6C5hfJcN4fvmLH2C34knhA" extern char ASSETCHAINS_SYMBOL[16]; @@ -490,14 +490,14 @@ Value paxdeposit(const Array& params, bool fHelp) std::string base = params[2].get_str(); std::string dest; height = chainActive.Tip()->nHeight; - komodoshis = PAX_fiatdest(0,destaddr,pubkey37,(char *)params[0].get_str().c_str(),height,(char *)base.c_str(),fiatoshis); + komodoshis = PAX_fiatdest(&seed,0,destaddr,pubkey37,(char *)params[0].get_str().c_str(),height,(char *)base.c_str(),fiatoshis); dest.append(destaddr); CBitcoinAddress destaddress(CRYPTO777_KMDADDR); if (!destaddress.IsValid()) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid dest Bitcoin address"); for (i=0; i<33; i++) printf("%02x",pubkey37[i]); - printf(" ht.%d srcaddr.(%s) %s fiatoshis.%lld -> dest.(%s) komodoshis.%llu\n",height,(char *)params[0].get_str().c_str(),(char *)base.c_str(),(long long)fiatoshis,destaddr,(long long)komodoshis); + printf(" ht.%d srcaddr.(%s) %s fiatoshis.%lld -> dest.(%s) komodoshis.%llu seed.%llx\n",height,(char *)params[0].get_str().c_str(),(char *)base.c_str(),(long long)fiatoshis,destaddr,(long long)komodoshis,(long long)seed); EnsureWalletIsUnlocked(); CWalletTx wtx; uint8_t opretbuf[64]; int32_t opretlen; uint64_t fee = komodoshis / 1000; @@ -526,7 +526,7 @@ Value paxwithdraw(const Array& params, bool fHelp) if (!address.IsValid()) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Bitcoin address"); int64_t fiatoshis = atof(params[1].get_str().c_str()) * COIN; - komodoshis = PAX_fiatdest(1,destaddr,pubkey37,(char *)params[0].get_str().c_str(),KMDHEIGHT,ASSETCHAINS_SYMBOL,fiatoshis); + komodoshis = PAX_fiatdest(&seed,1,destaddr,pubkey37,(char *)params[0].get_str().c_str(),KMDHEIGHT,ASSETCHAINS_SYMBOL,fiatoshis); dest.append(destaddr); CBitcoinAddress destaddress(CRYPTO777_KMDADDR); if (!destaddress.IsValid()) @@ -534,7 +534,7 @@ Value paxwithdraw(const Array& params, bool fHelp) for (i=0; i<33; i++) printf("%02x",pubkey37[i]); height = KMDHEIGHT; - printf(" ht.%d srcaddr.(%s) %s fiatoshis.%lld -> dest.(%s) komodoshis.%llu\n",height,(char *)params[0].get_str().c_str(),ASSETCHAINS_SYMBOL,(long long)fiatoshis,destaddr,(long long)komodoshis); + printf(" ht.%d srcaddr.(%s) %s fiatoshis.%lld -> dest.(%s) komodoshis.%llu seed.%llx\n",height,(char *)params[0].get_str().c_str(),ASSETCHAINS_SYMBOL,(long long)fiatoshis,destaddr,(long long)komodoshis,(long long)seed); EnsureWalletIsUnlocked(); uint8_t opretbuf[64]; int32_t opretlen; uint64_t fee = komodoshis / 1000; if ( fee < 10000 ) From c93dc546d24edec9baf67256f558ecf040936637 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 7 Nov 2016 16:13:37 -0300 Subject: [PATCH 220/254] test --- src/komodo.h | 6 +++--- src/komodo_bitcoind.h | 8 ++++---- src/komodo_notary.h | 28 ++++++++++++++-------------- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 2c812bc38..38b5c9e51 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -26,7 +26,7 @@ #include void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotaries,uint8_t notaryid,uint256 txhash,uint64_t voutmask,uint8_t numvouts,uint32_t *pvals,uint8_t numpvals,int32_t kheight,uint64_t opretvalue,uint8_t *opretbuf,uint16_t opretlen,uint16_t vout); -void komodo_init(); +void komodo_init(int32_t height); int32_t komodo_notarizeddata(int32_t nHeight,uint256 *notarized_hashp,uint256 *notarized_desttxidp); char *komodo_issuemethod(char *method,char *params,uint16_t port); @@ -150,7 +150,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar printf("fname.(%s) fpos.%ld\n",fname,ftell(fp)); KOMODO_INITDONE = (uint32_t)time(NULL); } - if ( height <= 0 ) + if ( height <= 0 || ) { //printf("early return: stateupdate height.%d\n",height); return; @@ -347,7 +347,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) uint64_t signedmask,voutmask; uint8_t scriptbuf[4096],pubkeys[64][33]; uint256 kmdtxid,btctxid,txhash; int32_t i,j,k,numvalid,specialtx,notarizedheight,notaryid,len,numvouts,numvins,height,txn_count; - komodo_init(); + komodo_init(pindex->nHeight); if ( pindex->nHeight > hwmheight ) hwmheight = pindex->nHeight; else diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 5cab4fb15..4306548c1 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -376,7 +376,7 @@ uint64_t komodo_seed(int32_t height) void komodo_disconnect(CBlockIndex *pindex,CBlock& block) { //int32_t i; uint256 hash; - komodo_init(); + komodo_init(pindex->nHeight); //hash = block.GetHash(); //for (i=0; i<32; i++) // printf("%02x",((uint8_t *)&hash)[i]); @@ -390,7 +390,6 @@ void komodo_disconnect(CBlockIndex *pindex,CBlock& block) int32_t komodo_block2height(CBlock *block) { int32_t i,n,height = 0; uint8_t *ptr; - komodo_init(); #ifdef KOMODO_ZCASH ptr = (uint8_t *)block->vtx[0].vin[0].scriptSig.data(); #else @@ -409,6 +408,7 @@ int32_t komodo_block2height(CBlock *block) } //printf(" <- coinbase.%d ht.%d\n",(int32_t)block->vtx[0].vin[0].scriptSig.size(),height); } + komodo_init(height); return(height); } @@ -419,14 +419,14 @@ void komodo_block2pubkey33(uint8_t *pubkey33,CBlock& block) #else uint8_t *ptr = (uint8_t *)&block.vtx[0].vout[0].scriptPubKey[0]; #endif - komodo_init(); + komodo_init(0); memcpy(pubkey33,ptr+1,33); } void komodo_index2pubkey33(uint8_t *pubkey33,CBlockIndex *pindex,int32_t height) { CBlock block; - komodo_init(); + komodo_init(height); memset(pubkey33,0,33); if ( pindex != 0 ) { diff --git a/src/komodo_notary.h b/src/komodo_notary.h index 6e834cba6..a106f8503 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -222,25 +222,25 @@ int32_t komodo_notarizeddata(int32_t nHeight,uint256 *notarized_hashp,uint256 *n return(0); } -void komodo_init() +void komodo_init(int32_t height) { static int didinit; uint256 zero; int32_t k,n; uint8_t pubkeys[64][33]; - if ( didinit == 0 ) + if ( height > didinit ) { - didinit = 1; - //iguana_initQ(&DepositsQ,(char *)"Deposits"); - //iguana_initQ(&PendingsQ,(char *)"Pendings"); - pthread_mutex_init(&komodo_mutex,NULL); - decode_hex(NOTARY_PUBKEY33,33,(char *)NOTARY_PUBKEY.c_str()); - n = (int32_t)(sizeof(Notaries_genesis)/sizeof(*Notaries_genesis)); - for (k=0; k Date: Mon, 7 Nov 2016 16:15:28 -0300 Subject: [PATCH 221/254] test --- src/komodo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index 38b5c9e51..97bbd83ef 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -150,7 +150,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar printf("fname.(%s) fpos.%ld\n",fname,ftell(fp)); KOMODO_INITDONE = (uint32_t)time(NULL); } - if ( height <= 0 || ) + if ( height <= 0 ) { //printf("early return: stateupdate height.%d\n",height); return; From 0f0fb1d9bedd70c43f201ec3817ef03c0b0717f8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 7 Nov 2016 16:17:12 -0300 Subject: [PATCH 222/254] test --- src/wallet/rpcwallet.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index e51113356..8060c85f4 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -474,7 +474,7 @@ int32_t iguana_rwnum(int32_t rwflag,uint8_t *serialized,int32_t len,void *endian Value paxdeposit(const Array& params, bool fHelp) { - uint64_t komodoshis = 0; int32_t height; char destaddr[64]; uint8_t i,pubkey37[33]; + uint64_t seed,komodoshis = 0; int32_t height; char destaddr[64]; uint8_t i,pubkey37[33]; bool fSubtractFeeFromAmount = false; if ( ASSETCHAINS_SYMBOL[0] != 0 ) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "paxdeposit only from KMD"); @@ -512,7 +512,7 @@ Value paxdeposit(const Array& params, bool fHelp) Value paxwithdraw(const Array& params, bool fHelp) { extern int32_t KMDHEIGHT,KOMODO_REALTIME; - CWalletTx wtx; std::string dest; int32_t height; uint64_t komodoshis = 0; char destaddr[64]; uint8_t i,pubkey37[37]; bool fSubtractFeeFromAmount = false; + CWalletTx wtx; std::string dest; int32_t height; uint64_t seed,komodoshis = 0; char destaddr[64]; uint8_t i,pubkey37[37]; bool fSubtractFeeFromAmount = false; if ( ASSETCHAINS_SYMBOL[0] == 0 ) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "paxwithdraw cant be from KMD"); if (!EnsureWalletIsAvailable(fHelp)) From abdd8672409d461ea0f0aa82add5ef354501f661 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 7 Nov 2016 16:24:01 -0300 Subject: [PATCH 223/254] test --- src/komodo_gateway.h | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 42987a53d..d06c49ee3 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -259,6 +259,14 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 if ( opretlen == 38 ) // any KMD tx { iguana_rwnum(0,&opretbuf[34],sizeof(kmdheight),&kmdheight); + memset(base,0,sizeof(base)); + PAX_pubkey(0,&opretbuf[1],&addrtype,rmd160,base,&shortflag,&fiatoshis); + if ( fiatoshis < 0 ) + fiatoshis = -fiatoshis; + bitcoin_address(coinaddr,addrtype,rmd160,20); + checktoshis = PAX_fiatdest(&seed,tokomodo,destaddr,pubkey33,coinaddr,kmdheight,base,fiatoshis); + typestr = "deposit"; + printf("kmdheight.%d vs height.%d check %.8f vs %.8f\n",kmdheight,height,dstr(checktoshis),dstr(value)); if ( kmdheight <= height ) { if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 ) @@ -267,13 +275,6 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 printf("%02x",opretbuf[i]); printf(" opret[%c] tokomodo.%d\n",opretbuf[0],tokomodo); } - memset(base,0,sizeof(base)); - PAX_pubkey(0,&opretbuf[1],&addrtype,rmd160,base,&shortflag,&fiatoshis); - if ( fiatoshis < 0 ) - fiatoshis = -fiatoshis; - bitcoin_address(coinaddr,addrtype,rmd160,20); - checktoshis = PAX_fiatdest(&seed,tokomodo,destaddr,pubkey33,coinaddr,kmdheight,base,fiatoshis); - typestr = "deposit"; //paxprice seed.0 sum 0.07766840 densum 1000.00000000 basevol 0.01000000 height.59532 if ( tokomodo == 0 && strncmp(ASSETCHAINS_SYMBOL,base,strlen(base)) == 0 && shortflag == ASSETCHAINS_SHORTFLAG ) { From 654dfaaf85e15fa88048c565abb93f236c7ef10e Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 7 Nov 2016 16:36:49 -0300 Subject: [PATCH 224/254] test --- src/bitcoind.cpp | 6 ++++-- src/komodo_gateway.h | 16 ++++++++-------- src/komodo_utils.h | 2 +- src/miner.cpp | 3 ++- src/wallet/rpcwallet.cpp | 2 +- 5 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/bitcoind.cpp b/src/bitcoind.cpp index 738247604..0ea3f12b1 100644 --- a/src/bitcoind.cpp +++ b/src/bitcoind.cpp @@ -35,6 +35,7 @@ static bool fDaemon; extern char ASSETCHAINS_SYMBOL[16]; void komodo_gateway_iteration(char *symbol); void komodo_iteration(char *symbol); +int32_t komodo_is_issuer(); void WaitForShutdown(boost::thread_group* threadGroup) { @@ -43,7 +44,7 @@ void WaitForShutdown(boost::thread_group* threadGroup) while (!fShutdown) { MilliSleep(2000); - if ( ASSETCHAINS_SYMBOL[0] != 0 ) + if ( komodo_is_issuer() != 0 ) komodo_gateway_iteration(ASSETCHAINS_SYMBOL); else komodo_iteration((char *)"EUR"); @@ -62,6 +63,7 @@ void WaitForShutdown(boost::thread_group* threadGroup) // extern int32_t IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,ASSETCHAIN_INIT; extern std::string NOTARY_PUBKEY; +int32_t komodo_is_issuer(); bool AppInit(int argc, char* argv[]) { @@ -104,7 +106,7 @@ bool AppInit(int argc, char* argv[]) fprintf(stderr,"call komodo_args NOTARY_PUBKEY.(%s)\n",NOTARY_PUBKEY.c_str()); while ( ASSETCHAIN_INIT == 0 ) { - if ( ASSETCHAINS_SYMBOL[0] != 0 ) + if ( komodo_is_issuer() != 0 ) komodo_gateway_iteration(ASSETCHAINS_SYMBOL); sleep(1); } diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index d06c49ee3..40a0c6ae0 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -44,7 +44,7 @@ uint64_t komodo_paxtotal() { if ( pax->marked == 0 ) { - if ( ASSETCHAINS_SYMBOL[0] == 0 ) + if ( komodo_is_issuer() != 0 ) total += pax->fiatoshis; else total += pax->komodoshis; } @@ -80,9 +80,9 @@ struct pax_transaction *komodo_paxmark(struct pax_transaction *space,uint256 txi if ( pax != 0 ) { pax->marked = mark; - int32_t i; for (i=0; i<32; i++) - printf("%02x",((uint8_t *)&txid)[i]); - printf(" paxmark.ht %d vout%d\n",mark,vout); + //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); @@ -238,9 +238,9 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block) // verify above else { hash = block.GetHash(); - for (j=0; j<32; j++) - printf("%02x",((uint8_t *)&hash)[j]); - printf(" ht.%d blockhash couldnt find vout.[%d]\n",height,i); + //for (j=0; j<32; j++) + // printf("%02x",((uint8_t *)&hash)[j]); + //printf(" ht.%d blockhash couldnt find vout.[%d]\n",height,i); komodo_paxmark(&space,txids[i-1],vouts[i-1],height); } } @@ -266,7 +266,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 bitcoin_address(coinaddr,addrtype,rmd160,20); checktoshis = PAX_fiatdest(&seed,tokomodo,destaddr,pubkey33,coinaddr,kmdheight,base,fiatoshis); typestr = "deposit"; - printf("kmdheight.%d vs height.%d check %.8f vs %.8f\n",kmdheight,height,dstr(checktoshis),dstr(value)); + printf("kmdheight.%d vs height.%d check %.8f vs %.8f tokomodo.%d %d\n",kmdheight,height,dstr(checktoshis),dstr(value),tokomodo,strncmp(ASSETCHAINS_SYMBOL,base,strlen(base)) == 0); if ( kmdheight <= height ) { if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 ) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 420d1c228..7465c730e 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -802,7 +802,7 @@ int32_t komodo_baseid(char *origbase) int32_t komodo_is_issuer() { - if ( ASSETCHAINS_SYMBOL[0] != 0 && COINBASE_MATURITY < 10 ) + if ( ASSETCHAINS_SYMBOL[0] != 0 && komodo_baseid(ASSETCHAINS_SYMBOL) >= 0 ) return(1); else return(0); } diff --git a/src/miner.cpp b/src/miner.cpp index 5125f3b88..984a9efaf 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -101,6 +101,7 @@ void UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams, #define ASSETCHAINS_MINHEIGHT 100 int32_t komodo_pax_opreturn(uint8_t *opret,int32_t maxsize); uint64_t komodo_paxtotal(); +int32_t komodo_is_issuer(); void komodo_gateway_deposits(CMutableTransaction *txNew,int32_t shortflag,char *symbol); extern int32_t KOMODO_INITDONE,ASSETCHAINS_SHORTFLAG; extern char ASSETCHAINS_SYMBOL[16]; @@ -376,7 +377,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) } komodo_gateway_deposits(&txNew,0,(char *)"EUR"); } - else + else if ( komodo_is_issuer() != 0 ) { komodo_gateway_deposits(&txNew,0,(char *)"KMD"); fprintf(stderr,"txNew numvouts.%d\n",(int32_t)txNew.vout.size()); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 8060c85f4..7854f2d00 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -476,7 +476,7 @@ Value paxdeposit(const Array& params, bool fHelp) { uint64_t seed,komodoshis = 0; int32_t height; char destaddr[64]; uint8_t i,pubkey37[33]; bool fSubtractFeeFromAmount = false; - if ( ASSETCHAINS_SYMBOL[0] != 0 ) + if ( komodo_is_issuer() != 0 ) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "paxdeposit only from KMD"); if (!EnsureWalletIsAvailable(fHelp)) return Value::null; From beb9352f1f743fda05c44251e65083989627cd12 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 7 Nov 2016 16:39:40 -0300 Subject: [PATCH 225/254] test --- src/wallet/rpcwallet.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 7854f2d00..c6946a9c1 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -470,6 +470,7 @@ uint64_t PAX_fiatdest(uint64_t *seedp,int32_t tokomodo,char *destaddr,uint8_t pu int32_t komodo_opreturnscript(uint8_t *script,uint8_t type,uint8_t *opret,int32_t opretlen); #define CRYPTO777_KMDADDR "RXL3YXG2ceaB6C5hfJcN4fvmLH2C34knhA" extern char ASSETCHAINS_SYMBOL[16]; +int32_t komodo_is_issuer(); int32_t iguana_rwnum(int32_t rwflag,uint8_t *serialized,int32_t len,void *endianedp); Value paxdeposit(const Array& params, bool fHelp) From 2191f5ca6a587258de26add419a4d008ca57c33b Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 7 Nov 2016 16:45:29 -0300 Subject: [PATCH 226/254] test --- src/komodo_gateway.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 40a0c6ae0..a5d35b09f 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -252,8 +252,9 @@ 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) { - uint8_t rmd160[20],addrtype,shortflag,pubkey33[33]; int32_t i,j,n,len,kmdheight,tokomodo=0; char base[4],coinaddr[64],destaddr[64]; struct pax_transaction space; uint256 txids[64]; uint16_t vouts[64]; uint64_t seed; int64_t fiatoshis,checktoshis; const char *typestr = "unknown"; + uint8_t rmd160[20],addrtype,shortflag,pubkey33[33]; int32_t i,j,n,len,tokomodo,kmdheight; char base[4],coinaddr[64],destaddr[64]; struct pax_transaction space; uint256 txids[64]; uint16_t vouts[64]; uint64_t seed; int64_t fiatoshis,checktoshis; const char *typestr = "unknown"; tokomodo = (komodo_is_issuer() == 0); + printf("ASSETCHAIN.(%s) -> tokomodo.%d is_issuer.%d\n",ASSETCHAINS_SYMBOL,tokomodo,komodo_is_issuer()); if ( opretbuf[0] == 'D' ) { if ( opretlen == 38 ) // any KMD tx @@ -266,7 +267,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 bitcoin_address(coinaddr,addrtype,rmd160,20); checktoshis = PAX_fiatdest(&seed,tokomodo,destaddr,pubkey33,coinaddr,kmdheight,base,fiatoshis); typestr = "deposit"; - printf("kmdheight.%d vs height.%d check %.8f vs %.8f tokomodo.%d %d\n",kmdheight,height,dstr(checktoshis),dstr(value),tokomodo,strncmp(ASSETCHAINS_SYMBOL,base,strlen(base)) == 0); + printf("kmdheight.%d vs height.%d check %.8f vs %.8f tokomodo.%d %d\n",kmdheight,height,dstr(checktoshis),dstr(value),komodo_is_issuer(),strncmp(ASSETCHAINS_SYMBOL,base,strlen(base)) == 0); if ( kmdheight <= height ) { if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 ) @@ -276,7 +277,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 printf(" opret[%c] tokomodo.%d\n",opretbuf[0],tokomodo); } //paxprice seed.0 sum 0.07766840 densum 1000.00000000 basevol 0.01000000 height.59532 - if ( tokomodo == 0 && strncmp(ASSETCHAINS_SYMBOL,base,strlen(base)) == 0 && shortflag == ASSETCHAINS_SHORTFLAG ) + if ( strncmp(ASSETCHAINS_SYMBOL,base,strlen(base)) == 0 && shortflag == ASSETCHAINS_SHORTFLAG ) { if ( shortflag == 0 ) { From 15b7788ae01f08fb3740cdda4f4628c355540643 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 7 Nov 2016 16:50:36 -0300 Subject: [PATCH 227/254] test --- src/komodo_gateway.h | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index a5d35b09f..550e1a2f8 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -252,7 +252,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) { - uint8_t rmd160[20],addrtype,shortflag,pubkey33[33]; int32_t i,j,n,len,tokomodo,kmdheight; char base[4],coinaddr[64],destaddr[64]; struct pax_transaction space; uint256 txids[64]; uint16_t vouts[64]; uint64_t seed; int64_t fiatoshis,checktoshis; const char *typestr = "unknown"; + uint8_t rmd160[20],addrtype,shortflag,pubkey33[33]; int32_t i,j,n,len,tokomodo,kmdheight; char base[4],coinaddr[64],destaddr[64]; struct pax_transaction space; uint256 txids[64]; uint16_t vouts[64]; double diff; uint64_t seed; int64_t fiatoshis,checktoshis; const char *typestr = "unknown"; tokomodo = (komodo_is_issuer() == 0); printf("ASSETCHAIN.(%s) -> tokomodo.%d is_issuer.%d\n",ASSETCHAINS_SYMBOL,tokomodo,komodo_is_issuer()); if ( opretbuf[0] == 'D' ) @@ -267,7 +267,10 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 bitcoin_address(coinaddr,addrtype,rmd160,20); checktoshis = PAX_fiatdest(&seed,tokomodo,destaddr,pubkey33,coinaddr,kmdheight,base,fiatoshis); typestr = "deposit"; - printf("kmdheight.%d vs height.%d check %.8f vs %.8f tokomodo.%d %d\n",kmdheight,height,dstr(checktoshis),dstr(value),komodo_is_issuer(),strncmp(ASSETCHAINS_SYMBOL,base,strlen(base)) == 0); + printf("kmdheight.%d vs height.%d check %.8f vs %.8f tokomodo.%d %d seed.%llx\n",kmdheight,height,dstr(checktoshis),dstr(value),komodo_is_issuer(),strncmp(ASSETCHAINS_SYMBOL,base,strlen(base)) == 0,(long long)seed); + diff = ((double)value / checktoshis) - 1.; + if ( diff < 0. ) + diff = -diff; if ( kmdheight <= height ) { if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 ) @@ -277,7 +280,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 printf(" opret[%c] tokomodo.%d\n",opretbuf[0],tokomodo); } //paxprice seed.0 sum 0.07766840 densum 1000.00000000 basevol 0.01000000 height.59532 - if ( strncmp(ASSETCHAINS_SYMBOL,base,strlen(base)) == 0 && shortflag == ASSETCHAINS_SHORTFLAG ) + if ( tokomodo == 0 && strncmp(ASSETCHAINS_SYMBOL,base,strlen(base)) == 0 && shortflag == ASSETCHAINS_SHORTFLAG ) { if ( shortflag == 0 ) { @@ -287,7 +290,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 for (i=0; i<33; i++) printf("%02x",pubkey33[i]); printf(" checkpubkey check %.8f v %.8f dest.(%s) kmdheight.%d height.%d\n",dstr(checktoshis),dstr(value),destaddr,kmdheight,height); - if ( value >= checktoshis ) + if ( value >= checktoshis || (seed == 0 && diff < .01) ) { if ( komodo_paxfind(&space,txid,vout) == 0 ) komodo_gateway_deposit(coinaddr,value,shortflag,base,fiatoshis,rmd160,txid,vout,kmdheight); @@ -298,7 +301,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 for (i=0; i Date: Mon, 7 Nov 2016 16:56:55 -0300 Subject: [PATCH 228/254] 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 550e1a2f8..e4c76f722 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -42,6 +42,7 @@ uint64_t komodo_paxtotal() tmp = 0; while ( PAX != 0 && (pax= (struct pax_transaction *)PAX->hh.next) != 0 && pax != tmp ) { + printf("pax.%p marked.%d fiat %.8f KMD %.8f\n",pax,pax->marked,dstr(pax->fiatoshis),dstr(pax->komodoshis)); if ( pax->marked == 0 ) { if ( komodo_is_issuer() != 0 ) @@ -254,7 +255,6 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 { uint8_t rmd160[20],addrtype,shortflag,pubkey33[33]; int32_t i,j,n,len,tokomodo,kmdheight; char base[4],coinaddr[64],destaddr[64]; struct pax_transaction space; uint256 txids[64]; uint16_t vouts[64]; double diff; uint64_t seed; int64_t fiatoshis,checktoshis; const char *typestr = "unknown"; tokomodo = (komodo_is_issuer() == 0); - printf("ASSETCHAIN.(%s) -> tokomodo.%d is_issuer.%d\n",ASSETCHAINS_SYMBOL,tokomodo,komodo_is_issuer()); if ( opretbuf[0] == 'D' ) { if ( opretlen == 38 ) // any KMD tx From b5bf65f5507715ed0efe32d8aea1fa556074f013 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 7 Nov 2016 17:03:53 -0300 Subject: [PATCH 229/254] test --- src/komodo_gateway.h | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index e4c76f722..abb5ce625 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -66,7 +66,7 @@ struct pax_transaction *komodo_paxfind(struct pax_transaction *space,uint256 txi return(pax); } -struct pax_transaction *komodo_paxmark(struct pax_transaction *space,uint256 txid,uint16_t vout,int32_t mark) +struct pax_transaction *komodo_paxmark(int32_t height,struct pax_transaction *space,uint256 txid,uint16_t vout,int32_t mark) { struct pax_transaction *pax; pthread_mutex_lock(&komodo_mutex); @@ -77,6 +77,7 @@ struct pax_transaction *komodo_paxmark(struct pax_transaction *space,uint256 txi pax->txid = txid; pax->vout = vout; HASH_ADD_KEYPTR(hh,PAX,&pax->txid,sizeof(pax->txid),pax); + printf("ht.%d create pax.%p mark.%d\n",height,pax,mark); } if ( pax != 0 ) { @@ -101,6 +102,7 @@ void komodo_gateway_deposit(char *coinaddr,uint64_t value,int32_t shortflag,char pax->txid = txid; pax->vout = vout; HASH_ADD_KEYPTR(hh,PAX,&pax->txid,sizeof(pax->txid),pax); + printf("ht.%d create pax.%p\n",height,pax); } pthread_mutex_unlock(&komodo_mutex); if ( coinaddr != 0 ) @@ -113,13 +115,13 @@ void komodo_gateway_deposit(char *coinaddr,uint64_t value,int32_t shortflag,char memcpy(pax->rmd160,rmd160,20); pax->height = height; if ( pax->marked == 0 ) - printf("ADD DEPOSIT %s %.8f -> %s TO PAX ht.%d total %.8f\n",symbol,dstr(fiatoshis),coinaddr,height,dstr(komodo_paxtotal())); - else printf("MARKED.%d DEPOSIT %s %.8f -> %s TO PAX ht.%d\n",pax->marked,symbol,dstr(fiatoshis),coinaddr,height); + printf("%p ADD DEPOSIT %s %.8f -> %s TO PAX ht.%d total %.8f\n",pax,symbol,dstr(fiatoshis),coinaddr,height,dstr(komodo_paxtotal())); + else printf("%p MARKED.%d DEPOSIT %s %.8f -> %s TO PAX ht.%d\n",pax,pax->marked,symbol,dstr(fiatoshis),coinaddr,height); } else { pax->marked = height; - printf("MARK DEPOSIT ht.%d\n",height); + printf("pax.%p MARK DEPOSIT ht.%d\n",pax,height); } } @@ -234,7 +236,7 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block) // verify above if ( (pax= komodo_paxfind(&space,txids[i-1],vouts[i-1])) != 0 && ((opcode == 'I' && pax->fiatoshis == block.vtx[0].vout[i].nValue) || (opcode == 'X' && pax->komodoshis == block.vtx[0].vout[i].nValue)) ) { //printf("i.%d match %.8f == %.8f\n",i,dstr(pax != 0 ? pax->fiatoshis:-1),dstr(block.vtx[0].vout[i].nValue)); - komodo_paxmark(&space,txids[i-1],vouts[i-1],height); + komodo_paxmark(height,&space,txids[i-1],vouts[i-1],height); } else { @@ -242,7 +244,7 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block) // verify above //for (j=0; j<32; j++) // printf("%02x",((uint8_t *)&hash)[j]); //printf(" ht.%d blockhash couldnt find vout.[%d]\n",height,i); - komodo_paxmark(&space,txids[i-1],vouts[i-1],height); + komodo_paxmark(height,&space,txids[i-1],vouts[i-1],height); } } } @@ -327,7 +329,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(" issuedtxid v%d i.%d of n.%d opretlen.%d\n",vouts[i],i,n,opretlen); - if ( komodo_paxmark(&space,txids[i],vouts[i],height) == 0 ) + if ( komodo_paxmark(height,&space,txids[i],vouts[i],height) == 0 ) komodo_gateway_deposit(0,0,0,0,0,0,txids[i],vouts[i],height); } } From 6a2841dcd1ee894b80bddd53f169114dbc442f7e Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 7 Nov 2016 17:12:36 -0300 Subject: [PATCH 230/254] test --- src/komodo_gateway.h | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index abb5ce625..4529842e4 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -40,17 +40,21 @@ uint64_t komodo_paxtotal() { struct pax_transaction *pax,*tmp; uint64_t total = 0; tmp = 0; - while ( PAX != 0 && (pax= (struct pax_transaction *)PAX->hh.next) != 0 && pax != tmp ) + if ( PAX != 0 ) { - printf("pax.%p marked.%d fiat %.8f KMD %.8f\n",pax,pax->marked,dstr(pax->fiatoshis),dstr(pax->komodoshis)); - if ( pax->marked == 0 ) + pax = (struct pax_transaction *)PAX->hh.next; + while ( pax != 0 && pax != tmp ) { - if ( komodo_is_issuer() != 0 ) - total += pax->fiatoshis; - else total += pax->komodoshis; + printf("PAX.[%p %p] pax.%p marked.%d fiat %.8f KMD %.8f\n",PAX->hh.next,PAX->hh.prev,pax,pax->marked,dstr(pax->fiatoshis),dstr(pax->komodoshis)); + if ( pax->marked == 0 ) + { + if ( komodo_is_issuer() != 0 ) + total += pax->fiatoshis; + else total += pax->komodoshis; + } + tmp = pax; + pax = (struct pax_transaction *)pax->hh.next; } - tmp = pax; - pax = (struct pax_transaction *)pax->hh.next; } return(total); } @@ -102,7 +106,7 @@ void komodo_gateway_deposit(char *coinaddr,uint64_t value,int32_t shortflag,char pax->txid = txid; pax->vout = vout; HASH_ADD_KEYPTR(hh,PAX,&pax->txid,sizeof(pax->txid),pax); - printf("ht.%d create pax.%p\n",height,pax); + printf("[%s] ht.%d create pax.%p\n",ASSETCHAINS_SYMBOL,height,pax); } pthread_mutex_unlock(&komodo_mutex); if ( coinaddr != 0 ) @@ -115,7 +119,7 @@ void komodo_gateway_deposit(char *coinaddr,uint64_t value,int32_t shortflag,char memcpy(pax->rmd160,rmd160,20); pax->height = height; if ( pax->marked == 0 ) - printf("%p ADD DEPOSIT %s %.8f -> %s TO PAX ht.%d total %.8f\n",pax,symbol,dstr(fiatoshis),coinaddr,height,dstr(komodo_paxtotal())); + printf("[%s] %p ADD DEPOSIT %s %.8f -> %s TO PAX ht.%d total %.8f\n",ASSETCHAINS_SYMBOL,pax,symbol,dstr(fiatoshis),coinaddr,height,dstr(komodo_paxtotal())); else printf("%p MARKED.%d DEPOSIT %s %.8f -> %s TO PAX ht.%d\n",pax,pax->marked,symbol,dstr(fiatoshis),coinaddr,height); } else @@ -156,11 +160,14 @@ void komodo_gateway_deposits(CMutableTransaction *txNew,int32_t shortflag,char * { struct pax_transaction *pax,*tmp; uint8_t *script,opcode,opret[10000],data[10000]; int32_t i,len=0,opretlen=0,numvouts=1; PENDING_KOMODO_TX = 0; + if ( PAX == 0 ) + return; if ( strcmp(symbol,"KMD") == 0 ) opcode = 'I'; else opcode = 'X'; tmp = 0; - while ( PAX != 0 && (pax= (struct pax_transaction *)PAX->hh.next) != 0 && pax != tmp ) + pax = (struct pax_transaction *)PAX->hh.next; + while ( pax != 0 && pax != tmp ) { printf("pax.%p marked.%d %.8f -> %.8f\n",pax,pax->marked,dstr(pax->komodoshis),dstr(pax->fiatoshis)); if ( pax->marked != 0 ) From 32d525ebf359f792ddf555dc5e44aaaec73a7dfc Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 7 Nov 2016 17:15:07 -0300 Subject: [PATCH 231/254] test --- src/komodo_gateway.h | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 4529842e4..bbffa8a79 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -25,17 +25,6 @@ struct pax_transaction char symbol[16],coinaddr[64]; uint8_t rmd160[20],shortflag; } *PAX; -/*uint64_t komodo_paxtotal() -{ - struct pax_transaction *pax,*tmp; uint64_t total = 0; - HASH_ITER(hh,PAX,pax,tmp) - { - if ( pax->marked == 0 ) - total += pax->fiatoshis; - } - return(total); -}*/ - uint64_t komodo_paxtotal() { struct pax_transaction *pax,*tmp; uint64_t total = 0; @@ -45,7 +34,7 @@ uint64_t komodo_paxtotal() pax = (struct pax_transaction *)PAX->hh.next; while ( pax != 0 && pax != tmp ) { - printf("PAX.[%p %p] pax.%p marked.%d fiat %.8f KMD %.8f\n",PAX->hh.next,PAX->hh.prev,pax,pax->marked,dstr(pax->fiatoshis),dstr(pax->komodoshis)); + //printf("PAX.[%p %p] pax.%p marked.%d fiat %.8f KMD %.8f\n",PAX->hh.next,PAX->hh.prev,pax,pax->marked,dstr(pax->fiatoshis),dstr(pax->komodoshis)); if ( pax->marked == 0 ) { if ( komodo_is_issuer() != 0 ) @@ -81,7 +70,7 @@ struct pax_transaction *komodo_paxmark(int32_t height,struct pax_transaction *sp pax->txid = txid; pax->vout = vout; HASH_ADD_KEYPTR(hh,PAX,&pax->txid,sizeof(pax->txid),pax); - printf("ht.%d create pax.%p mark.%d\n",height,pax,mark); + //printf("ht.%d create pax.%p mark.%d\n",height,pax,mark); } if ( pax != 0 ) { @@ -106,7 +95,7 @@ void komodo_gateway_deposit(char *coinaddr,uint64_t value,int32_t shortflag,char pax->txid = txid; pax->vout = vout; HASH_ADD_KEYPTR(hh,PAX,&pax->txid,sizeof(pax->txid),pax); - printf("[%s] ht.%d create pax.%p\n",ASSETCHAINS_SYMBOL,height,pax); + //printf("[%s] ht.%d create pax.%p\n",ASSETCHAINS_SYMBOL,height,pax); } pthread_mutex_unlock(&komodo_mutex); if ( coinaddr != 0 ) From ceb6be460613f62a4bc91b4b04a88d64bcceed48 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 7 Nov 2016 17:20:10 -0300 Subject: [PATCH 232/254] test --- src/komodo_gateway.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index bbffa8a79..20a942443 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -27,16 +27,17 @@ struct pax_transaction uint64_t komodo_paxtotal() { - struct pax_transaction *pax,*tmp; uint64_t total = 0; + struct pax_transaction *pax,*tmp; int32_t n = 0; uint64_t total = 0; + pthread_mutex_lock(&komodo_mutex); tmp = 0; if ( PAX != 0 ) { pax = (struct pax_transaction *)PAX->hh.next; - while ( pax != 0 && pax != tmp ) + while ( pax != 0 && pax != tmp && n++ < 1000000 ) { - //printf("PAX.[%p %p] pax.%p marked.%d fiat %.8f KMD %.8f\n",PAX->hh.next,PAX->hh.prev,pax,pax->marked,dstr(pax->fiatoshis),dstr(pax->komodoshis)); if ( pax->marked == 0 ) { + //printf("PAX.[%p %p] pax.%p marked.%d fiat %.8f KMD %.8f\n",PAX->hh.next,PAX->hh.prev,pax,pax->marked,dstr(pax->fiatoshis),dstr(pax->komodoshis)); if ( komodo_is_issuer() != 0 ) total += pax->fiatoshis; else total += pax->komodoshis; @@ -45,6 +46,9 @@ uint64_t komodo_paxtotal() pax = (struct pax_transaction *)pax->hh.next; } } + pthread_mutex_unlock(&komodo_mutex); + if ( n >= 1000000 ) + printf("komodo_paxtotal n.%d iterations?\n",n); return(total); } From c169f64b2302f27d7e3b779f5c097af581d3ac16 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 7 Nov 2016 17:41:05 -0300 Subject: [PATCH 233/254] test --- src/komodo_gateway.h | 80 +++++++++++++++++++++++++------------------- 1 file changed, 46 insertions(+), 34 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 20a942443..296845cd5 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -28,16 +28,16 @@ struct pax_transaction uint64_t komodo_paxtotal() { struct pax_transaction *pax,*tmp; int32_t n = 0; uint64_t total = 0; - pthread_mutex_lock(&komodo_mutex); + /*pthread_mutex_lock(&komodo_mutex); tmp = 0; if ( PAX != 0 ) { pax = (struct pax_transaction *)PAX->hh.next; while ( pax != 0 && pax != tmp && n++ < 1000000 ) { + printf("PAX.[%p %p] pax.%p marked.%d fiat %.8f KMD %.8f\n",PAX->hh.next,PAX->hh.prev,pax,pax->marked,dstr(pax->fiatoshis),dstr(pax->komodoshis)); if ( pax->marked == 0 ) { - //printf("PAX.[%p %p] pax.%p marked.%d fiat %.8f KMD %.8f\n",PAX->hh.next,PAX->hh.prev,pax,pax->marked,dstr(pax->fiatoshis),dstr(pax->komodoshis)); if ( komodo_is_issuer() != 0 ) total += pax->fiatoshis; else total += pax->komodoshis; @@ -48,7 +48,16 @@ uint64_t komodo_paxtotal() } pthread_mutex_unlock(&komodo_mutex); if ( n >= 1000000 ) - printf("komodo_paxtotal n.%d iterations?\n",n); + printf("komodo_paxtotal n.%d iterations?\n",n);*/ + HASH_ITER(hh,PAX,pax,tmp) + { + if ( pax->marked == 0 ) + { + if ( komodo_is_issuer() != 0 ) + total += pax->fiatoshis; + else total += pax->komodoshis; + } + } return(total); } @@ -153,43 +162,46 @@ void komodo_gateway_deposits(CMutableTransaction *txNew,int32_t shortflag,char * { struct pax_transaction *pax,*tmp; uint8_t *script,opcode,opret[10000],data[10000]; int32_t i,len=0,opretlen=0,numvouts=1; PENDING_KOMODO_TX = 0; - if ( PAX == 0 ) - return; if ( strcmp(symbol,"KMD") == 0 ) opcode = 'I'; else opcode = 'X'; - tmp = 0; - pax = (struct pax_transaction *)PAX->hh.next; - while ( pax != 0 && pax != tmp ) + HASH_ITER(hh,PAX,pax,tmp) { - printf("pax.%p marked.%d %.8f -> %.8f\n",pax,pax->marked,dstr(pax->komodoshis),dstr(pax->fiatoshis)); - if ( pax->marked != 0 ) - continue; - txNew->vout.resize(numvouts+1); - txNew->vout[numvouts].nValue = pax->fiatoshis; - txNew->vout[numvouts].scriptPubKey.resize(25); - script = (uint8_t *)&txNew->vout[numvouts].scriptPubKey[0]; - *script++ = 0x76; - *script++ = 0xa9; - *script++ = 20; - memcpy(script,pax->rmd160,20), script += 20; - *script++ = 0x88; - *script++ = 0xac; - for (i=0; i<32; i++) + //if ( PAX == 0 ) + // return; + tmp = 0; + //pax = (struct pax_transaction *)PAX->hh.next; + //while ( pax != 0 && pax != tmp ) { - printf("%02x",((uint8_t *)&pax->txid)[i]); - data[len++] = ((uint8_t *)&pax->txid)[i]; + printf("pax.%p marked.%d %.8f -> %.8f\n",pax,pax->marked,dstr(pax->komodoshis),dstr(pax->fiatoshis)); + if ( pax->marked != 0 ) + continue; + txNew->vout.resize(numvouts+1); + txNew->vout[numvouts].nValue = pax->fiatoshis; + txNew->vout[numvouts].scriptPubKey.resize(25); + script = (uint8_t *)&txNew->vout[numvouts].scriptPubKey[0]; + *script++ = 0x76; + *script++ = 0xa9; + *script++ = 20; + memcpy(script,pax->rmd160,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 ( strcmp(symbol,"KMD") != 0 ) + PENDING_KOMODO_TX += pax->fiatoshis; + else PENDING_KOMODO_TX += pax->komodoshis; + printf(" vout.%u DEPOSIT %.8f <- paxdeposit.%s pending %.8f\n",pax->vout,(double)txNew->vout[numvouts].nValue/COIN,symbol,dstr(PENDING_KOMODO_TX)); + if ( numvouts++ >= 64 ) + break; + //tmp = pax; + //pax = (struct pax_transaction *)pax->hh.next; } - data[len++] = pax->vout & 0xff; - data[len++] = (pax->vout >> 8) & 0xff; - if ( strcmp(symbol,"KMD") != 0 ) - PENDING_KOMODO_TX += pax->fiatoshis; - else PENDING_KOMODO_TX += pax->komodoshis; - printf(" vout.%u DEPOSIT %.8f <- paxdeposit.%s pending %.8f\n",pax->vout,(double)txNew->vout[numvouts].nValue/COIN,symbol,dstr(PENDING_KOMODO_TX)); - if ( numvouts++ >= 64 ) - break; - tmp = pax; - pax = (struct pax_transaction *)pax->hh.next; } if ( numvouts > 1 ) { From e5430f52c7d5a6632ba8b7779f57726cad662ab3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 7 Nov 2016 17:56:48 -0300 Subject: [PATCH 234/254] test --- src/komodo_gateway.h | 60 +++++++++++++++++++------------------------- src/miner.cpp | 37 ++++++++++++++++++++------- 2 files changed, 54 insertions(+), 43 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 296845cd5..3339252e8 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -27,7 +27,7 @@ struct pax_transaction uint64_t komodo_paxtotal() { - struct pax_transaction *pax,*tmp; int32_t n = 0; uint64_t total = 0; + struct pax_transaction *pax,*tmp; uint64_t total = 0; /*pthread_mutex_lock(&komodo_mutex); tmp = 0; if ( PAX != 0 ) @@ -167,41 +167,33 @@ void komodo_gateway_deposits(CMutableTransaction *txNew,int32_t shortflag,char * else opcode = 'X'; HASH_ITER(hh,PAX,pax,tmp) { - //if ( PAX == 0 ) - // return; - tmp = 0; - //pax = (struct pax_transaction *)PAX->hh.next; - //while ( pax != 0 && pax != tmp ) - { + if ( ASSETCHAINS_SYMBOL[0] != 0 ) printf("pax.%p marked.%d %.8f -> %.8f\n",pax,pax->marked,dstr(pax->komodoshis),dstr(pax->fiatoshis)); - if ( pax->marked != 0 ) - continue; - txNew->vout.resize(numvouts+1); - txNew->vout[numvouts].nValue = pax->fiatoshis; - txNew->vout[numvouts].scriptPubKey.resize(25); - script = (uint8_t *)&txNew->vout[numvouts].scriptPubKey[0]; - *script++ = 0x76; - *script++ = 0xa9; - *script++ = 20; - memcpy(script,pax->rmd160,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 ( strcmp(symbol,"KMD") != 0 ) - PENDING_KOMODO_TX += pax->fiatoshis; - else PENDING_KOMODO_TX += pax->komodoshis; - printf(" vout.%u DEPOSIT %.8f <- paxdeposit.%s pending %.8f\n",pax->vout,(double)txNew->vout[numvouts].nValue/COIN,symbol,dstr(PENDING_KOMODO_TX)); - if ( numvouts++ >= 64 ) - break; - //tmp = pax; - //pax = (struct pax_transaction *)pax->hh.next; + if ( pax->marked != 0 ) + continue; + txNew->vout.resize(numvouts+1); + txNew->vout[numvouts].nValue = pax->fiatoshis; + txNew->vout[numvouts].scriptPubKey.resize(25); + script = (uint8_t *)&txNew->vout[numvouts].scriptPubKey[0]; + *script++ = 0x76; + *script++ = 0xa9; + *script++ = 20; + memcpy(script,pax->rmd160,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 ( strcmp(symbol,"KMD") != 0 ) + PENDING_KOMODO_TX += pax->fiatoshis; + else PENDING_KOMODO_TX += pax->komodoshis; + printf(" vout.%u DEPOSIT %.8f <- paxdeposit.%s pending %.8f\n",pax->vout,(double)txNew->vout[numvouts].nValue/COIN,symbol,dstr(PENDING_KOMODO_TX)); + if ( numvouts++ >= 64 ) + break; } if ( numvouts > 1 ) { diff --git a/src/miner.cpp b/src/miner.cpp index 984a9efaf..1129340e6 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -114,7 +114,8 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) if(!pblocktemplate.get()) return NULL; CBlock *pblock = &pblocktemplate->block; // pointer for convenience - fprintf(stderr,"start CreateNewBlock %s initdone.%d deposit %.8f mempool.%d\n",ASSETCHAINS_SYMBOL,KOMODO_INITDONE,(double)komodo_paxtotal()/COIN,(int32_t)mempool.GetTotalTxSize()); + if ( ASSETCHAINS_SYMBOL[0] != 0 ) + fprintf(stderr,"start CreateNewBlock %s initdone.%d deposit %.8f mempool.%d\n",ASSETCHAINS_SYMBOL,KOMODO_INITDONE,(double)komodo_paxtotal()/COIN,(int32_t)mempool.GetTotalTxSize()); while ( chainActive.Tip()->nHeight > ASSETCHAINS_MINHEIGHT && mempool.GetTotalTxSize() <= 0 ) { deposits = komodo_paxtotal(); @@ -578,8 +579,8 @@ void static BitcoinMiner(CWallet *pwallet) } CBlock *pblock = &pblocktemplate->block; IncrementExtraNonce(pblock, pindexPrev, nExtraNonce); - LogPrintf("Running ZcashMiner.%s with %u transactions in block (%u bytes)\n", solver.c_str(),pblock->vtx.size(), - ::GetSerializeSize(*pblock, SER_NETWORK, PROTOCOL_VERSION)); + LogPrintf("Running ZcashMiner.%s with %u transactions in block (%u bytes)\n",solver.c_str(),pblock->vtx.size(),::GetSerializeSize(*pblock,SER_NETWORK,PROTOCOL_VERSION)); + frintf(stderr,"Running ZcashMiner.%s with %u transactions in block (%u bytes)\n",solver.c_str(),pblock->vtx.size(),::GetSerializeSize(*pblock,SER_NETWORK,PROTOCOL_VERSION)); // // Search @@ -594,9 +595,9 @@ void static BitcoinMiner(CWallet *pwallet) fprintf(stderr,"I am the chosen one for %s ht.%d\n",ASSETCHAINS_SYMBOL,pindexPrev->nHeight+1); } else Mining_start = 0; Mining_height = pindexPrev->nHeight+1; - //fprintf(stderr,"%s start mining loop\n",ASSETCHAINS_SYMBOL); while (true) { + fprintf(stderr,"%s start mining loop\n",ASSETCHAINS_SYMBOL); // Hash state crypto_generichash_blake2b_state state; EhInitialiseState(n, k, state); @@ -610,19 +611,22 @@ void static BitcoinMiner(CWallet *pwallet) crypto_generichash_blake2b_state curr_state; curr_state = state; crypto_generichash_blake2b_update(&curr_state,pblock->nNonce.begin(),pblock->nNonce.size()); - // (x_1, x_2, ...) = A(I, V, n, k) LogPrint("pow", "Running Equihash solver \"%s\" with nNonce = %s\n",solver, pblock->nNonce.ToString()); - std::function)> validBlock = [&pblock, &hashTarget, &pwallet, &reservekey, &m_cs, &cancelSolver, &chainparams] - (std::vector soln) { + (std::vector soln) + { // Write the solution to the hash and compute the result. LogPrint("pow", "- Checking solution against target\n"); pblock->nSolution = soln; solutionTargetChecks.increment(); if ( UintToArith256(pblock->GetHash()) > hashTarget ) + { + if ( ASSETCHAINS_SYMBOL[0] != 0 ) + printf("missed target\n"); return false; + } if ( ASSETCHAINS_SYMBOL[0] == 0 && Mining_start != 0 && time(NULL) < Mining_start+20 ) { printf("Round robin diff sleep %d\n",(int32_t)(Mining_start+20-time(NULL))); @@ -707,14 +711,29 @@ void static BitcoinMiner(CWallet *pwallet) boost::this_thread::interruption_point(); // Regtest mode doesn't require peers if (vNodes.empty() && chainparams.MiningRequiresPeers()) + { + if ( ASSETCHAINS_SYMBOL[0] != 0 ) + printf("no nodes, break\n"); break; + } if ((UintToArith256(pblock->nNonce) & 0xffff) == 0xffff) + { + if ( ASSETCHAINS_SYMBOL[0] != 0 ) + printf("0xffff, break\n"); break; + } if (mempool.GetTransactionsUpdated() != nTransactionsUpdatedLast && GetTime() - nStart > 60) + { + if ( ASSETCHAINS_SYMBOL[0] != 0 ) + printf("timeout, break\n"); break; - if (pindexPrev != chainActive.Tip()) + } + if ( pindexPrev != chainActive.Tip() ) + { + if ( ASSETCHAINS_SYMBOL[0] != 0 ) + printf("Tip advanced, break\n"); break; - + } // Update nNonce and nTime pblock->nNonce = ArithToUint256(UintToArith256(pblock->nNonce) + 1); pblock->nBits = savebits; From bd67847c5f46d4e65f64bc4b986981a1e3c4ba5c Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 7 Nov 2016 17:58:29 -0300 Subject: [PATCH 235/254] test --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index 1129340e6..91860bf67 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -580,7 +580,7 @@ void static BitcoinMiner(CWallet *pwallet) CBlock *pblock = &pblocktemplate->block; IncrementExtraNonce(pblock, pindexPrev, nExtraNonce); LogPrintf("Running ZcashMiner.%s with %u transactions in block (%u bytes)\n",solver.c_str(),pblock->vtx.size(),::GetSerializeSize(*pblock,SER_NETWORK,PROTOCOL_VERSION)); - frintf(stderr,"Running ZcashMiner.%s with %u transactions in block (%u bytes)\n",solver.c_str(),pblock->vtx.size(),::GetSerializeSize(*pblock,SER_NETWORK,PROTOCOL_VERSION)); + fprintf(stderr,"Running ZcashMiner.%s with %u transactions in block (%u bytes)\n",solver.c_str(),pblock->vtx.size(),::GetSerializeSize(*pblock,SER_NETWORK,PROTOCOL_VERSION)); // // Search From 529f87603e5fdc6a73f1ca1bf8618b2c11669aa8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 7 Nov 2016 18:00:08 -0300 Subject: [PATCH 236/254] test --- src/miner.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 91860bf67..6514f4f50 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -580,8 +580,6 @@ void static BitcoinMiner(CWallet *pwallet) CBlock *pblock = &pblocktemplate->block; IncrementExtraNonce(pblock, pindexPrev, nExtraNonce); LogPrintf("Running ZcashMiner.%s with %u transactions in block (%u bytes)\n",solver.c_str(),pblock->vtx.size(),::GetSerializeSize(*pblock,SER_NETWORK,PROTOCOL_VERSION)); - fprintf(stderr,"Running ZcashMiner.%s with %u transactions in block (%u bytes)\n",solver.c_str(),pblock->vtx.size(),::GetSerializeSize(*pblock,SER_NETWORK,PROTOCOL_VERSION)); - // // Search // From 7ca711bac3a368e4d9775415ae1248fbb9c1cf15 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 7 Nov 2016 18:05:15 -0300 Subject: [PATCH 237/254] test --- src/komodo_gateway.h | 4 ++-- src/miner.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 3339252e8..2c2335e9a 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -167,10 +167,10 @@ void komodo_gateway_deposits(CMutableTransaction *txNew,int32_t shortflag,char * else opcode = 'X'; HASH_ITER(hh,PAX,pax,tmp) { - if ( ASSETCHAINS_SYMBOL[0] != 0 ) - printf("pax.%p marked.%d %.8f -> %.8f\n",pax,pax->marked,dstr(pax->komodoshis),dstr(pax->fiatoshis)); if ( pax->marked != 0 ) continue; + if ( ASSETCHAINS_SYMBOL[0] != 0 ) + printf("pax.%p marked.%d %.8f -> %.8f\n",pax,pax->marked,dstr(pax->komodoshis),dstr(pax->fiatoshis)); txNew->vout.resize(numvouts+1); txNew->vout[numvouts].nValue = pax->fiatoshis; txNew->vout[numvouts].scriptPubKey.resize(25); diff --git a/src/miner.cpp b/src/miner.cpp index 6514f4f50..e56cd5240 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -524,7 +524,7 @@ void static BitcoinMiner(CWallet *pwallet) komodo_chosennotary(¬aryid,chainActive.Tip()->nHeight,NOTARY_PUBKEY33); std::string solver; - if ( notaryid >= 0 ) + if ( notaryid >= 0 || ASSETCHAINS[0] != 0 ) solver = "tromp"; else solver = "default"; assert(solver == "tromp" || solver == "default"); From d4a1821d06a5c25106b594a82972e589c26aa797 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 7 Nov 2016 18:07:48 -0300 Subject: [PATCH 238/254] test --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index e56cd5240..ec5519b90 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -524,7 +524,7 @@ void static BitcoinMiner(CWallet *pwallet) komodo_chosennotary(¬aryid,chainActive.Tip()->nHeight,NOTARY_PUBKEY33); std::string solver; - if ( notaryid >= 0 || ASSETCHAINS[0] != 0 ) + if ( notaryid >= 0 || ASSETCHAINS_SYMBOL[0] != 0 ) solver = "tromp"; else solver = "default"; assert(solver == "tromp" || solver == "default"); From 81041ab233dde77721fa0a01eecead0ad380d5c4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 7 Nov 2016 18:27:39 -0300 Subject: [PATCH 239/254] test --- src/komodo_gateway.h | 30 +++++++++++++++++++----------- src/miner.cpp | 16 ++++++---------- 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 2c2335e9a..8d0fc0447 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -214,7 +214,7 @@ void komodo_gateway_deposits(CMutableTransaction *txNew,int32_t shortflag,char * 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; uint256 hash,txids[64]; uint8_t shortflag; char symbol[16],base[16]; uint16_t vouts[64]; uint8_t *script,opcode; struct pax_transaction *pax,space; + int32_t i,j,n,num,opretlen,offset=1,errs=0,matched=0; uint256 hash,txids[64]; uint8_t shortflag; char symbol[16],base[16]; uint16_t vouts[64]; uint8_t *script,opcode; struct pax_transaction *pax,space; n = block.vtx[0].vout.size(); script = (uint8_t *)block.vtx[0].vout[n-1].scriptPubKey.data(); if ( n <= 2 || script[0] != 0x6a ) @@ -239,18 +239,26 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block) // verify above { if ( (pax= komodo_paxfind(&space,txids[i-1],vouts[i-1])) != 0 && ((opcode == 'I' && pax->fiatoshis == block.vtx[0].vout[i].nValue) || (opcode == 'X' && pax->komodoshis == block.vtx[0].vout[i].nValue)) ) { - //printf("i.%d match %.8f == %.8f\n",i,dstr(pax != 0 ? pax->fiatoshis:-1),dstr(block.vtx[0].vout[i].nValue)); + if ( pax->marked != 0 ) + errs++; + else matched++; + 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); } else { hash = block.GetHash(); - //for (j=0; j<32; j++) - // printf("%02x",((uint8_t *)&hash)[j]); - //printf(" ht.%d blockhash couldnt find vout.[%d]\n",height,i); + for (j=0; j<32; j++) + printf("%02x",((uint8_t *)&hash)[j]); + printf(" ht.%d blockhash couldnt find vout.[%d]\n",height,i); komodo_paxmark(height,&space,txids[i-1],vouts[i-1],height); } } + if ( matched != num ) + { + printf("matched.%d vs num.%d\n",matched,num); + return(-1); + } } //printf("opretlen.%d num.%d\n",opretlen,num); } @@ -318,14 +326,14 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 } else if ( strncmp((char *)"KMD",(char *)&opretbuf[opretlen-4],3) != 0 ) { + if ( ASSETCHAINS_SYMBOL[0] != 0 ) + { + for (i=0; i 0 && shortflag == ASSETCHAINS_SHORTFLAG ) { for (i=0; inHeight > ASSETCHAINS_MINHEIGHT && mempool.GetTotalTxSize() <= 0 ) { deposits = komodo_paxtotal(); - sleep(10); if ( KOMODO_INITDONE == 0 || time(NULL) < KOMODO_INITDONE+60 ) continue; if ( deposits != 0 ) - { break; - } + sleep(10); } if ( ASSETCHAINS_SYMBOL[0] != 0 ) printf("miner KOMODO_DEPOSIT %llu pblock->nHeight %d mempool.GetTotalTxSize(%d)\n",(long long)komodo_paxtotal(),(int32_t)chainActive.Tip()->nHeight,(int32_t)mempool.GetTotalTxSize()); @@ -446,8 +444,6 @@ int32_t komodo_chosennotary(int32_t *notaryidp,int32_t height,uint8_t *pubkey33) CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey) { CPubKey pubkey; CScript scriptPubKey; uint8_t *script,*ptr; int32_t i; - if ( ASSETCHAINS_SYMBOL[0] != 0 ) - fprintf(stderr,"%s createnewblockwith key\n",ASSETCHAINS_SYMBOL); if ( USE_EXTERNAL_PUBKEY != 0 ) { //fprintf(stderr,"use notary pubkey\n"); @@ -562,8 +558,8 @@ void static BitcoinMiner(CWallet *pwallet) } while (true); //fprintf(stderr,"%s Found peers\n",ASSETCHAINS_SYMBOL); } - if ( ASSETCHAINS_SYMBOL[0] != 0 ) - fprintf(stderr,"%s create new block\n",ASSETCHAINS_SYMBOL); + //if ( ASSETCHAINS_SYMBOL[0] != 0 ) + // fprintf(stderr,"%s create new block\n",ASSETCHAINS_SYMBOL); // // Create new block // @@ -595,7 +591,7 @@ void static BitcoinMiner(CWallet *pwallet) Mining_height = pindexPrev->nHeight+1; while (true) { - fprintf(stderr,"%s start mining loop\n",ASSETCHAINS_SYMBOL); + //fprintf(stderr,"%s start mining loop\n",ASSETCHAINS_SYMBOL); // Hash state crypto_generichash_blake2b_state state; EhInitialiseState(n, k, state); @@ -621,8 +617,8 @@ void static BitcoinMiner(CWallet *pwallet) solutionTargetChecks.increment(); if ( UintToArith256(pblock->GetHash()) > hashTarget ) { - if ( ASSETCHAINS_SYMBOL[0] != 0 ) - printf("missed target\n"); + //if ( ASSETCHAINS_SYMBOL[0] != 0 ) + // printf("missed target\n"); return false; } if ( ASSETCHAINS_SYMBOL[0] == 0 && Mining_start != 0 && time(NULL) < Mining_start+20 ) From 8a8080c5ae838f91b27070a75d53274c5900228e Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 7 Nov 2016 18:32:02 -0300 Subject: [PATCH 240/254] 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 8d0fc0447..ca51f3a86 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -141,18 +141,18 @@ int32_t komodo_issued_opreturn(uint8_t *shortflagp,char *base,uint256 *txids,uin base[i] = opretbuf[opretlen-4+i]; if ( (strcmp(base,"KMD") == 0 && ASSETCHAINS_SYMBOL[0] == 0) || strncmp(ASSETCHAINS_SYMBOL,base,strlen(base)) == 0 ) // shortflag { - //printf("BASE.(%s) vs (%s)\n",base,ASSETCHAINS_SYMBOL); + printf("BASE.(%s) vs (%s)\n",base,ASSETCHAINS_SYMBOL); opretbuf++, opretlen--; for (n=len=0; n 60000 ) + return(-1); } } //printf("opretlen.%d num.%d\n",opretlen,num); @@ -326,14 +327,14 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 } else if ( strncmp((char *)"KMD",(char *)&opretbuf[opretlen-4],3) != 0 ) { - if ( ASSETCHAINS_SYMBOL[0] != 0 ) - { - for (i=0; i 0 && shortflag == ASSETCHAINS_SHORTFLAG ) { for (i=0; i Date: Mon, 7 Nov 2016 18:51:09 -0300 Subject: [PATCH 241/254] test --- src/komodo_gateway.h | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index ca51f3a86..3914abbfc 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -237,21 +237,30 @@ 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)) ) + if ( (pax= komodo_paxfind(&space,txids[i-1],vouts[i-1])) != 0 ) { - if ( pax->marked != 0 ) - errs++; - else matched++; - 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); + 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 ) + errs++; + else matched++; + 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); + } + else + { + hash = block.GetHash(); + for (j=0; j<32; j++) + printf("%02x",((uint8_t *)&hash)[j]); + printf(" ht.%d blockhash couldnt find vout.[%d]\n",height,i); + komodo_paxmark(height,&space,txids[i-1],vouts[i-1],height); + } } else { - hash = block.GetHash(); for (j=0; j<32; j++) - printf("%02x",((uint8_t *)&hash)[j]); - printf(" ht.%d blockhash couldnt find vout.[%d]\n",height,i); - komodo_paxmark(height,&space,txids[i-1],vouts[i-1],height); + printf("%02x",((uint8_t *)&txids[i-1])[j]); + printf("cant paxfind txid\n"); } } if ( matched != num ) From f6b5fa431d6bed9223cd54b9b3e1ef076cd0c2bf Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 7 Nov 2016 19:16:30 -0300 Subject: [PATCH 242/254] 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 3914abbfc..e7a8587e0 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -88,9 +88,9 @@ struct pax_transaction *komodo_paxmark(int32_t height,struct pax_transaction *sp if ( pax != 0 ) { pax->marked = mark; - //int32_t i; for (i=0; i<32; i++) - // printf("%02x",((uint8_t *)&txid)[i]); - //printf(" paxmark.ht %d vout%d\n",mark,vout); + 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); @@ -141,7 +141,6 @@ int32_t komodo_issued_opreturn(uint8_t *shortflagp,char *base,uint256 *txids,uin base[i] = opretbuf[opretlen-4+i]; if ( (strcmp(base,"KMD") == 0 && ASSETCHAINS_SYMBOL[0] == 0) || strncmp(ASSETCHAINS_SYMBOL,base,strlen(base)) == 0 ) // shortflag { - printf("BASE.(%s) vs (%s)\n",base,ASSETCHAINS_SYMBOL); opretbuf++, opretlen--; for (n=len=0; nfiatoshis:-1),dstr(block.vtx[0].vout[i].nValue)); - komodo_paxmark(height,&space,txids[i-1],vouts[i-1],height); } else { @@ -253,15 +251,15 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block) // verify above for (j=0; j<32; j++) printf("%02x",((uint8_t *)&hash)[j]); printf(" ht.%d blockhash couldnt find vout.[%d]\n",height,i); - komodo_paxmark(height,&space,txids[i-1],vouts[i-1],height); } } else { for (j=0; j<32; j++) printf("%02x",((uint8_t *)&txids[i-1])[j]); - printf("cant paxfind txid\n"); + printf(" cant paxfind txid\n"); } + komodo_paxmark(height,&space,txids[i-1],vouts[i-1],height); } if ( matched != num ) { @@ -348,11 +346,14 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 { for (i=0; i Date: Mon, 7 Nov 2016 19:43:46 -0300 Subject: [PATCH 243/254] test --- src/komodo.h | 2 +- src/komodo_gateway.h | 23 +++++++++++------------ 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 97bbd83ef..85006cd37 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -191,7 +191,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar errs++; if ( fwrite(opretbuf,1,olen,fp) != olen ) errs++; - //printf("ht.%d R opret[%d]\n",height,olen); + printf("ht.%d R opret[%d]\n",height,olen); komodo_opreturn(height,opretvalue,opretbuf,olen,txhash,vout); } else if ( notarypubs != 0 && numnotaries > 0 ) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index e7a8587e0..b91617e86 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -108,7 +108,9 @@ void komodo_gateway_deposit(char *coinaddr,uint64_t value,int32_t shortflag,char pax->txid = txid; pax->vout = vout; HASH_ADD_KEYPTR(hh,PAX,&pax->txid,sizeof(pax->txid),pax); - //printf("[%s] ht.%d create pax.%p\n",ASSETCHAINS_SYMBOL,height,pax); + int32_t i; for (i=0; i<32; i++) + printf("%02x",((uint8_t *)&txid)[i]); + printf(" v.%d [%s] ht.%d create pax.%p\n",vout,ASSETCHAINS_SYMBOL,height,pax); } pthread_mutex_unlock(&komodo_mutex); if ( coinaddr != 0 ) @@ -295,13 +297,6 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 diff = -diff; if ( kmdheight <= height ) { - if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 ) - { - for (i=0; i= checktoshis || (seed == 0 && diff < .01) ) { if ( komodo_paxfind(&space,txid,vout) == 0 ) + { komodo_gateway_deposit(coinaddr,value,shortflag,base,fiatoshis,rmd160,txid,vout,kmdheight); + } else printf("duplicate deposit\n"); } } else // short @@ -340,19 +337,21 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 { for (i=0; i 0 && shortflag == ASSETCHAINS_SHORTFLAG ) { for (i=0; i Date: Mon, 7 Nov 2016 19:51:59 -0300 Subject: [PATCH 244/254] test --- src/komodo.h | 1 + src/miner.cpp | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 85006cd37..a7cda36c6 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -368,6 +368,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) { height = pindex->nHeight; txn_count = block.vtx.size(); + printf("%s ht.%d connect txn_count.%d\n",ASSETCHAINS_SYMBOL,height,txn_count); for (i=0; iblock; // pointer for convenience if ( ASSETCHAINS_SYMBOL[0] != 0 ) - fprintf(stderr,"start CreateNewBlock %s initdone.%d deposit %.8f mempool.%d\n",ASSETCHAINS_SYMBOL,KOMODO_INITDONE,(double)komodo_paxtotal()/COIN,(int32_t)mempool.GetTotalTxSize()); + fprintf(stderr,"start CreateNewBlock %s initdone.%d deposit %.8f mempool.%d RT.%u\n",ASSETCHAINS_SYMBOL,KOMODO_INITDONE,(double)komodo_paxtotal()/COIN,(int32_t)mempool.GetTotalTxSize(),KOMODO_REALTIME); while ( chainActive.Tip()->nHeight > ASSETCHAINS_MINHEIGHT && mempool.GetTotalTxSize() <= 0 ) { deposits = komodo_paxtotal(); - if ( KOMODO_INITDONE == 0 || time(NULL) < KOMODO_INITDONE+60 ) + if ( KOMODO_INITDONE == 0 || time(NULL) < KOMODO_INITDONE+60 || KOMODO_REALTIME == 0 ) continue; if ( deposits != 0 ) break; From e0bf88b064cd1b84b9d2caae7c55a5bc664afc7c Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 7 Nov 2016 20:04:20 -0300 Subject: [PATCH 245/254] test --- src/komodo.h | 3 ++- src/komodo_gateway.h | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index a7cda36c6..39bf693f5 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -368,7 +368,8 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) { height = pindex->nHeight; txn_count = block.vtx.size(); - printf("%s ht.%d connect txn_count.%d\n",ASSETCHAINS_SYMBOL,height,txn_count); + if ( ASSETCHAINS_SYMBOL[0] != 0 ) + printf("%s ht.%d connect txn_count.%d\n",ASSETCHAINS_SYMBOL,height,txn_count); for (i=0; i Date: Mon, 7 Nov 2016 20:19:39 -0300 Subject: [PATCH 246/254] test --- src/komodo.h | 11 +++++++---- src/komodo_gateway.h | 12 ++++++------ 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 39bf693f5..637e65fdd 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -304,9 +304,6 @@ int32_t komodo_voutupdate(int32_t notaryid,uint8_t *scriptbuf,int32_t scriptlen, opretlen = scriptbuf[len++]; opretlen = (opretlen << 8) + scriptbuf[len++]; } - //for (k=0; k= 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); @@ -323,7 +320,13 @@ int32_t komodo_voutupdate(int32_t notaryid,uint8_t *scriptbuf,int32_t scriptlen, } else if ( i == 0 && j == 1 && opretlen == 149 ) komodo_paxpricefeed(height,&scriptbuf[len],opretlen); - else komodo_stateupdate(height,0,0,0,txhash,0,0,0,0,0,value,&scriptbuf[len],opretlen,j); + else + { + for (k=0; k 0 && shortflag == ASSETCHAINS_SHORTFLAG ) { for (i=0; i Date: Mon, 7 Nov 2016 20:20:30 -0300 Subject: [PATCH 247/254] test --- src/komodo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index 637e65fdd..b013c96e2 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -322,7 +322,7 @@ int32_t komodo_voutupdate(int32_t notaryid,uint8_t *scriptbuf,int32_t scriptlen, komodo_paxpricefeed(height,&scriptbuf[len],opretlen); else { - for (k=0; k Date: Mon, 7 Nov 2016 20:36:14 -0300 Subject: [PATCH 248/254] 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 a0d96700f..ee121e29b 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -279,6 +279,12 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 { uint8_t rmd160[20],addrtype,shortflag,pubkey33[33]; int32_t i,j,n,len,tokomodo,kmdheight; char base[4],coinaddr[64],destaddr[64]; struct pax_transaction space; uint256 txids[64]; uint16_t vouts[64]; double diff; uint64_t seed; int64_t fiatoshis,checktoshis; const char *typestr = "unknown"; tokomodo = (komodo_is_issuer() == 0); + if ( ASSETCHAINS_SYMBOL[0] != 0 ) + { + for (i=0; i 0 && shortflag == ASSETCHAINS_SHORTFLAG ) From 7cbf644437fb88fc692d48a4ef53e8f432054388 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 7 Nov 2016 20:51:02 -0300 Subject: [PATCH 249/254] test --- src/komodo_gateway.h | 2 +- src/miner.cpp | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index ee121e29b..1aeedfe08 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -163,7 +163,7 @@ void komodo_gateway_deposits(CMutableTransaction *txNew,int32_t shortflag,char * { struct pax_transaction *pax,*tmp; uint8_t *script,opcode,opret[10000],data[10000]; int32_t i,len=0,opretlen=0,numvouts=1; PENDING_KOMODO_TX = 0; - if ( strcmp(symbol,"KMD") == 0 ) + if ( strcmp(symbol,"KMD") != 0 ) opcode = 'I'; else opcode = 'X'; HASH_ITER(hh,PAX,pax,tmp) diff --git a/src/miner.cpp b/src/miner.cpp index d444b8855..0514238c8 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -378,13 +378,11 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) } else if ( komodo_is_issuer() != 0 ) { - komodo_gateway_deposits(&txNew,0,(char *)"KMD"); + komodo_gateway_deposits(&txNew,0,ASSETCHAINS_SYMBOL); fprintf(stderr,"txNew numvouts.%d\n",(int32_t)txNew.vout.size()); } - pblock->vtx[0] = txNew; pblocktemplate->vTxFees[0] = -nFees; - // Randomise nonce arith_uint256 nonce = UintToArith256(GetRandHash()); // Clear the top and bottom 16 bits (for local use as thread flags and counters) From 1938746c00529b0dfe84692dcf7c4bd65970b264 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 7 Nov 2016 20:58:14 -0300 Subject: [PATCH 250/254] test --- src/komodo.h | 10 +++++----- src/komodo_gateway.h | 18 +++++++++--------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index b013c96e2..e2e30224d 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -191,7 +191,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar errs++; if ( fwrite(opretbuf,1,olen,fp) != olen ) errs++; - printf("ht.%d R opret[%d]\n",height,olen); + //printf("ht.%d R opret[%d]\n",height,olen); komodo_opreturn(height,opretvalue,opretbuf,olen,txhash,vout); } else if ( notarypubs != 0 && numnotaries > 0 ) @@ -322,9 +322,9 @@ int32_t komodo_voutupdate(int32_t notaryid,uint8_t *scriptbuf,int32_t scriptlen, komodo_paxpricefeed(height,&scriptbuf[len],opretlen); else { - int32_t k; for (k=0; knHeight; txn_count = block.vtx.size(); - if ( ASSETCHAINS_SYMBOL[0] != 0 ) + if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 ) printf("%s ht.%d connect txn_count.%d\n",ASSETCHAINS_SYMBOL,height,txn_count); for (i=0; itxid)[i]); + //printf("%02x",((uint8_t *)&pax->txid)[i]); data[len++] = ((uint8_t *)&pax->txid)[i]; } data[len++] = pax->vout & 0xff; @@ -192,7 +192,7 @@ void komodo_gateway_deposits(CMutableTransaction *txNew,int32_t shortflag,char * if ( strcmp(symbol,"KMD") != 0 ) PENDING_KOMODO_TX += pax->fiatoshis; else PENDING_KOMODO_TX += pax->komodoshis; - printf(" vout.%u DEPOSIT %.8f <- paxdeposit.%s pending %.8f\n",pax->vout,(double)txNew->vout[numvouts].nValue/COIN,symbol,dstr(PENDING_KOMODO_TX)); + //printf(" vout.%u DEPOSIT %.8f <- paxdeposit.%s pending %.8f\n",pax->vout,(double)txNew->vout[numvouts].nValue/COIN,symbol,dstr(PENDING_KOMODO_TX)); if ( numvouts++ >= 64 ) break; } @@ -245,7 +245,7 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block) // verify above if ( pax->marked != 0 ) errs++; else matched++; - printf("errs.%d i.%d match %.8f == %.8f\n",errs,i,dstr(pax != 0 ? pax->fiatoshis:-1),dstr(block.vtx[0].vout[i].nValue)); + //printf("errs.%d i.%d match %.8f == %.8f\n",errs,i,dstr(pax != 0 ? pax->fiatoshis:-1),dstr(block.vtx[0].vout[i].nValue)); } else { @@ -279,7 +279,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 { uint8_t rmd160[20],addrtype,shortflag,pubkey33[33]; int32_t i,j,n,len,tokomodo,kmdheight; char base[4],coinaddr[64],destaddr[64]; struct pax_transaction space; uint256 txids[64]; uint16_t vouts[64]; double diff; uint64_t seed; int64_t fiatoshis,checktoshis; const char *typestr = "unknown"; tokomodo = (komodo_is_issuer() == 0); - if ( ASSETCHAINS_SYMBOL[0] != 0 ) + if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 ) { for (i=0; i Date: Mon, 7 Nov 2016 21:07:13 -0300 Subject: [PATCH 251/254] test --- src/komodo_gateway.h | 20 ++++++++++---------- src/miner.cpp | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 2afa3281e..3279cfd95 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -88,9 +88,9 @@ struct pax_transaction *komodo_paxmark(int32_t height,struct pax_transaction *sp if ( pax != 0 ) { pax->marked = mark; - int32_t i; for (i=0; i<32; i++) - printf("%02x",((uint8_t *)&txid)[i]); - printf(" paxmark.ht %d vout%d\n",mark,vout); + //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); @@ -108,9 +108,9 @@ void komodo_gateway_deposit(char *coinaddr,uint64_t value,int32_t shortflag,char pax->txid = txid; pax->vout = vout; HASH_ADD_KEYPTR(hh,PAX,&pax->txid,sizeof(pax->txid),pax); - int32_t i; for (i=0; i<32; i++) - printf("%02x",((uint8_t *)&txid)[i]); - printf(" v.%d [%s] ht.%d create pax.%p\n",vout,ASSETCHAINS_SYMBOL,height,pax); + //int32_t i; for (i=0; i<32; i++) + // printf("%02x",((uint8_t *)&txid)[i]); + //printf(" v.%d [%s] ht.%d create pax.%p\n",vout,ASSETCHAINS_SYMBOL,height,pax); } pthread_mutex_unlock(&komodo_mutex); if ( coinaddr != 0 ) @@ -250,9 +250,9 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block) // verify above else { hash = block.GetHash(); - for (j=0; j<32; j++) - printf("%02x",((uint8_t *)&hash)[j]); - printf(" ht.%d blockhash couldnt find vout.[%d]\n",height,i); + //for (j=0; j<32; j++) + // printf("%02x",((uint8_t *)&hash)[j]); + //printf(" ht.%d blockhash couldnt find vout.[%d]\n",height,i); } } else @@ -265,7 +265,7 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block) // verify above } if ( matched != num ) { - printf("matched.%d vs num.%d\n",matched,num); + //printf("matched.%d vs num.%d\n",matched,num); if ( height > 60000 ) return(-1); } diff --git a/src/miner.cpp b/src/miner.cpp index 0514238c8..45cfdef45 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -116,7 +116,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) CBlock *pblock = &pblocktemplate->block; // pointer for convenience if ( ASSETCHAINS_SYMBOL[0] != 0 ) fprintf(stderr,"start CreateNewBlock %s initdone.%d deposit %.8f mempool.%d RT.%u\n",ASSETCHAINS_SYMBOL,KOMODO_INITDONE,(double)komodo_paxtotal()/COIN,(int32_t)mempool.GetTotalTxSize(),KOMODO_REALTIME); - while ( chainActive.Tip()->nHeight > ASSETCHAINS_MINHEIGHT && mempool.GetTotalTxSize() <= 0 ) + while ( chainActive.Tip() == 0 || chainActive.Tip()->nHeight < ASSETCHAINS_MINHEIGHT || mempool.GetTotalTxSize() <= 0 ) { deposits = komodo_paxtotal(); if ( KOMODO_INITDONE == 0 || time(NULL) < KOMODO_INITDONE+60 || KOMODO_REALTIME == 0 ) From 4b71bef66b933e99eefb0d52ac65668a2ee4fbca Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 7 Nov 2016 21:11:49 -0300 Subject: [PATCH 252/254] test --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index 45cfdef45..76c1ae3a0 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -116,7 +116,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) CBlock *pblock = &pblocktemplate->block; // pointer for convenience if ( ASSETCHAINS_SYMBOL[0] != 0 ) fprintf(stderr,"start CreateNewBlock %s initdone.%d deposit %.8f mempool.%d RT.%u\n",ASSETCHAINS_SYMBOL,KOMODO_INITDONE,(double)komodo_paxtotal()/COIN,(int32_t)mempool.GetTotalTxSize(),KOMODO_REALTIME); - while ( chainActive.Tip() == 0 || chainActive.Tip()->nHeight < ASSETCHAINS_MINHEIGHT || mempool.GetTotalTxSize() <= 0 ) + while ( mempool.GetTotalTxSize() <= 0 ) { deposits = komodo_paxtotal(); if ( KOMODO_INITDONE == 0 || time(NULL) < KOMODO_INITDONE+60 || KOMODO_REALTIME == 0 ) From dd05179345e6a23bb3dfb2e6a2232a2ca24797dd Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 7 Nov 2016 21:32:17 -0300 Subject: [PATCH 253/254] 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 7465c730e..2d8884a4d 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -796,7 +796,7 @@ int32_t komodo_baseid(char *origbase) for (i=0; i<=MAX_CURRENCIES; i++) if ( strcmp(CURRENCIES[i],base) == 0 ) return(i); - printf("illegal base.(%s) %s\n",origbase,base); + //printf("illegal base.(%s) %s\n",origbase,base); return(-1); } From 030ffec28e6cdef8ad5e9678dc9edf8a780aaf8b Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 8 Nov 2016 08:11:49 -0300 Subject: [PATCH 254/254] test --- src/wallet/rpcwallet.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index c6946a9c1..892cf4fc1 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -515,13 +515,13 @@ Value paxwithdraw(const Array& params, bool fHelp) extern int32_t KMDHEIGHT,KOMODO_REALTIME; CWalletTx wtx; std::string dest; int32_t height; uint64_t seed,komodoshis = 0; char destaddr[64]; uint8_t i,pubkey37[37]; bool fSubtractFeeFromAmount = false; if ( ASSETCHAINS_SYMBOL[0] == 0 ) - throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "paxwithdraw cant be from KMD"); + return(0); if (!EnsureWalletIsAvailable(fHelp)) return 0; if (fHelp || params.size() != 2) throw runtime_error("paxwithdraw \"address\" fiatamount"); if ( KOMODO_REALTIME == 0 ) - throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "paxwithdraw needs to wait for KMD realtime"); + return(0); LOCK2(cs_main, pwalletMain->cs_wallet); CBitcoinAddress address(params[0].get_str()); if (!address.IsValid())