From a08b1ae8e84dd63ef08797a34c92b38606028745 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 9 Oct 2017 21:51:32 +0300 Subject: [PATCH 001/188] README --- README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/README.md b/README.md index 2bbd8a743..6c927185c 100644 --- a/README.md +++ b/README.md @@ -39,10 +39,25 @@ sudo apt-get install build-essential pkg-config libcurl3-gnutls-dev libc6-dev li Komodo ------ +We have a release process that goes through several stages before it reaches master. This allows the most conservative users just use the master branch, which is only updated after the other branches have signed off on a release. + +99% of the activity is in the dev branch, this is where I am testing each change one by one and there are literally thousands of updates. Only use this branch if you really want to be on the bleeding edge. I try to keep things stable, but there are times where necessarily there are bugs in the dev branch, since I am actively developing and debugging here. A good rule is to wait for at least 4 hours from the last update before using the dev branch (unless you know what you are doing) + +After things look good in the dev branch, it is propagated to the beta branch, this is the version the notary nodes use. They are knowledegable command line server guys and so they have a keen eye for anything that wasnt caught during the dev cycle. + +After the notary nodes verify things are working and the latest release is deemed stable, it is propagated to the dPoW branch. From here an automated Jenkins process builds it for all OS, and since the notary nodes are all unix, it is possible for some issues to be caught at this stage. The dPoW branch is what goes into the GUI installers. + +After the GUI are updated and released and it is verified that no significant support issues were created, the master branch is finally updated. + +Master branch: exchanges and users that build from the repo without changing branches +dPoW branch: autobuild into GUI installers, unix, osx, windows +beta branch: notary nodes, command line unix +dev branch: bleeding edge, possibly wont even compile, multiple updates per hour ``` git clone https://github.com/jl777/komodo cd komodo +#you might want to: git checkout ; git pull ./zcutil/fetch-params.sh # -j8 uses 8 threads - replace 8 with number of threads you want to use ./zcutil/build.sh -j8 From 42c6ba054c77d5821001b328dd5b6a3fc5751004 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Oct 2017 13:17:06 +0300 Subject: [PATCH 002/188] New interest --- src/komodo_interest.h | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/src/komodo_interest.h b/src/komodo_interest.h index 6355173d8..4d3350545 100644 --- a/src/komodo_interest.h +++ b/src/komodo_interest.h @@ -64,9 +64,30 @@ uint64_t komodo_moneysupply(int32_t height) else return(COIN * 100000000 + (height-1) * 3 + komodo_earned_interest(height,-1)); } +uint64_t _komodo_interestnew(uint64_t nValue,uint32_t nLockTime,uint32_t tiptime) +{ + int32_t minutes; uint64_t interest = 0; + if ( (minutes= (tiptime - nLockTime) / 60) >= 60 ) + { + if ( minutes > 365 * 24 * 60 ) + minutes = 365 * 24 * 60; + minutes -= 59; + interest = ((nValue / 10512000) * minutes); + } + return(interest); +} + +uint64_t komodo_interestnew(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uint32_t tiptime) +{ + uint64_t interest = 0; + if ( komodo_moneysupply(txheight) < MAX_MONEY && nLockTime >= LOCKTIME_THRESHOLD && tiptime != 0 && nLockTime < tiptime && nValue >= 10*COIN ) + interest = _komodo_interestnew(nValue,nLockTime,tiptime); + return(interest); +} + uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uint32_t tiptime) { - int32_t minutes,exception; uint64_t numerator,denominator,interest = 0; uint32_t activation; + int32_t minutes,exception; uint64_t interestnew,numerator,denominator,interest = 0; uint32_t activation; activation = 1491350400; // 1491350400 5th April if ( ASSETCHAINS_SYMBOL[0] != 0 ) return(0); @@ -111,11 +132,15 @@ uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uin interest = (numerator / denominator); else interest = (numerator * minutes) / ((uint64_t)365 * 24 * 60); } - else + else if ( txheight < 1000000 ) { numerator = (nValue * KOMODO_INTEREST); interest = (numerator / denominator) / COIN; + interestnew = _komodo_interestnew(nValue,nLockTime,tiptime); + //if ( interest != interestnew ) + printf("path0 current interest %.8f vs new %.8f for ht.%d %.8f locktime.%u tiptime.%u\n",dstr(interest),dstr(interestnew),txheight,dstr(nValue),nLockTime,tiptime); } + else interest = _komodo_interestnew(nValue,nLockTime,tiptime); } else { @@ -132,12 +157,16 @@ uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uin interest = (numerator / denominator) / COIN; else interest = ((numerator * minutes) / ((uint64_t)365 * 24 * 60)) / COIN; } - else + else if ( txheight < 1000000 ) { numerator = (nValue / 20); // assumes 5%! interest = ((numerator * minutes) / ((uint64_t)365 * 24 * 60)); //fprintf(stderr,"interest %llu %.8f <- numerator.%llu minutes.%d\n",(long long)interest,(double)interest/COIN,(long long)numerator,(int32_t)minutes); + interestnew = _komodo_interestnew(nValue,nLockTime,tiptime); + if ( interest != interestnew ) + printf("path1 current interest %.8f vs new %.8f for ht.%d %.8f locktime.%u tiptime.%u\n",dstr(interest),dstr(interestnew),txheight,dstr(nValue),nLockTime,tiptime); } + else interest = _komodo_interestnew(nValue,nLockTime,tiptime); } if ( 0 && numerator == (nValue * KOMODO_INTEREST) ) fprintf(stderr,"komodo_interest.%d %lld %.8f nLockTime.%u tiptime.%u minutes.%d interest %lld %.8f (%llu / %llu) prod.%llu\n",txheight,(long long)nValue,(double)nValue/COIN,nLockTime,tiptime,minutes,(long long)interest,(double)interest/COIN,(long long)numerator,(long long)denominator,(long long)(numerator * minutes)); From 50a979bc87a87588fb56350fd8573e5562b04ca0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Oct 2017 13:32:02 +0300 Subject: [PATCH 003/188] Test --- src/komodo_interest.h | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/komodo_interest.h b/src/komodo_interest.h index 4d3350545..c05445394 100644 --- a/src/komodo_interest.h +++ b/src/komodo_interest.h @@ -13,13 +13,15 @@ * * ******************************************************************************/ +#define dstr(x) ((double)(x) / SATOSHIDEN) + #define KOMODO_INTEREST ((uint64_t)(0.05 * COIN)) // 5% int64_t MAX_MONEY = 200000000 * 100000000LL; uint64_t komodo_earned_interest(int32_t height,int64_t paidinterest) { static uint64_t *interests; static int32_t maxheight; - uint64_t total; int32_t ind,incr = 100000; + uint64_t total; int32_t ind,incr = 10000; if ( height >= maxheight ) { if ( interests == 0 ) @@ -36,16 +38,20 @@ uint64_t komodo_earned_interest(int32_t height,int64_t paidinterest) } ind = (height << 1); if ( paidinterest < 0 ) // request + { return(interests[ind]); + } else { if ( interests[ind + 1] != paidinterest ) { + fprintf(stderr,"interests.%d %.8f %.8f vs paidinterest.%d\n",height,dstr(interests[ind]),dstr(interests[ind+1]),dstr(paidinterest)); interests[ind + 1] = paidinterest; - if ( height == 0 ) - interests[ind] = interests[ind + 1]; - else interests[ind] = interests[ind - 2] + interests[ind + 1]; - total = interests[ind]; + if ( height <= 1 ) + interests[ind] = 0; + else interests[ind] = interests[ind - 2] + interests[ind - 1]; + total = interests[ind] + paidinterest; + fprintf(stderr,"reset interests[height.%d to maxheight.%d] <- %.8f\n",height,maxheight,dstr(total)); for (++height; height Date: Tue, 10 Oct 2017 13:34:24 +0300 Subject: [PATCH 004/188] Test --- src/komodo_interest.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_interest.h b/src/komodo_interest.h index c05445394..454ed3587 100644 --- a/src/komodo_interest.h +++ b/src/komodo_interest.h @@ -45,7 +45,7 @@ uint64_t komodo_earned_interest(int32_t height,int64_t paidinterest) { if ( interests[ind + 1] != paidinterest ) { - fprintf(stderr,"interests.%d %.8f %.8f vs paidinterest.%d\n",height,dstr(interests[ind]),dstr(interests[ind+1]),dstr(paidinterest)); + fprintf(stderr,"interests.%d %.8f %.8f vs paidinterest %.8f\n",height,dstr(interests[ind]),dstr(interests[ind+1]),dstr(paidinterest)); interests[ind + 1] = paidinterest; if ( height <= 1 ) interests[ind] = 0; From 2f38e8886bd7c414acdcee15911059052d430133 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Oct 2017 13:36:03 +0300 Subject: [PATCH 005/188] Test --- src/komodo_interest.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/komodo_interest.h b/src/komodo_interest.h index 454ed3587..06641ed2c 100644 --- a/src/komodo_interest.h +++ b/src/komodo_interest.h @@ -13,6 +13,7 @@ * * ******************************************************************************/ +#define SATOSHIDEN ((uint64_t)100000000L) #define dstr(x) ((double)(x) / SATOSHIDEN) #define KOMODO_INTEREST ((uint64_t)(0.05 * COIN)) // 5% From 5dd58d6112d67be0f3c0305c033849bb2da4f041 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Oct 2017 13:49:50 +0300 Subject: [PATCH 006/188] Test --- src/komodo_interest.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/komodo_interest.h b/src/komodo_interest.h index 06641ed2c..a407aabd8 100644 --- a/src/komodo_interest.h +++ b/src/komodo_interest.h @@ -23,6 +23,7 @@ uint64_t komodo_earned_interest(int32_t height,int64_t paidinterest) { static uint64_t *interests; static int32_t maxheight; uint64_t total; int32_t ind,incr = 10000; + // need to make interests persistent before 2030 if ( height >= maxheight ) { if ( interests == 0 ) @@ -145,7 +146,7 @@ uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uin numerator = (nValue * KOMODO_INTEREST); interest = (numerator / denominator) / COIN; interestnew = _komodo_interestnew(nValue,nLockTime,tiptime); - if ( interest != interestnew ) + if ( interest < interestnew || interestnew < 0.9999*interest ) fprintf(stderr,"path0 current interest %.8f vs new %.8f for ht.%d %.8f locktime.%u tiptime.%u\n",dstr(interest),dstr(interestnew),txheight,dstr(nValue),nLockTime,tiptime); } else interest = _komodo_interestnew(nValue,nLockTime,tiptime); @@ -171,7 +172,7 @@ uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uin interest = ((numerator * minutes) / ((uint64_t)365 * 24 * 60)); //fprintf(stderr,"interest %llu %.8f <- numerator.%llu minutes.%d\n",(long long)interest,(double)interest/COIN,(long long)numerator,(int32_t)minutes); interestnew = _komodo_interestnew(nValue,nLockTime,tiptime); - if ( interest != interestnew ) + if ( interest < interestnew || interestnew < 0.9999*interest ) fprintf(stderr,"path1 current interest %.8f vs new %.8f for ht.%d %.8f locktime.%u tiptime.%u\n",dstr(interest),dstr(interestnew),txheight,dstr(nValue),nLockTime,tiptime); } else interest = _komodo_interestnew(nValue,nLockTime,tiptime); From 6da8d0d55eba534924c93919aee3b9ebc390e674 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Oct 2017 14:15:58 +0300 Subject: [PATCH 007/188] Test --- src/komodo_interest.h | 6 +++--- src/main.cpp | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/komodo_interest.h b/src/komodo_interest.h index a407aabd8..27ab20be4 100644 --- a/src/komodo_interest.h +++ b/src/komodo_interest.h @@ -23,7 +23,7 @@ uint64_t komodo_earned_interest(int32_t height,int64_t paidinterest) { static uint64_t *interests; static int32_t maxheight; uint64_t total; int32_t ind,incr = 10000; - // need to make interests persistent before 2030 + // need to make interests persistent before 2030, or just hardfork interest/mining rewards disable after MAX_MONEY is exceeded if ( height >= maxheight ) { if ( interests == 0 ) @@ -45,7 +45,7 @@ uint64_t komodo_earned_interest(int32_t height,int64_t paidinterest) } else { - if ( interests[ind + 1] != paidinterest ) + if ( interests[ind + 1] != paidinterest ) // need to handle skips like at 80000 { fprintf(stderr,"interests.%d %.8f %.8f vs paidinterest %.8f\n",height,dstr(interests[ind]),dstr(interests[ind+1]),dstr(paidinterest)); interests[ind + 1] = paidinterest; @@ -68,7 +68,7 @@ uint64_t komodo_earned_interest(int32_t height,int64_t paidinterest) uint64_t komodo_moneysupply(int32_t height) { - if ( height <= 1 || ASSETCHAINS_SYMBOL[0] != 0 ) + if ( height <= 1 || ASSETCHAINS_SYMBOL[0] == 0 ) return(0); else return(COIN * 100000000 + (height-1) * 3 + komodo_earned_interest(height,-1)); } diff --git a/src/main.cpp b/src/main.cpp index b354c1430..8f028dbb7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2365,7 +2365,8 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin return false; control.Add(vChecks); } - komodo_earned_interest(pindex->nHeight,sum); + if ( ASSETCHAINS_SYMBOL[0] == 0 ) + komodo_earned_interest(pindex->nHeight,sum); CTxUndo undoDummy; if (i > 0) { blockundo.vtxundo.push_back(CTxUndo()); From 1f8581e154e1d5f1a58fafe720f9626a2a5b8b16 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Oct 2017 14:29:37 +0300 Subject: [PATCH 008/188] Test --- src/komodo_interest.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_interest.h b/src/komodo_interest.h index 27ab20be4..a01d9adea 100644 --- a/src/komodo_interest.h +++ b/src/komodo_interest.h @@ -61,7 +61,7 @@ uint64_t komodo_earned_interest(int32_t height,int64_t paidinterest) interests[ind + 1] = 0; } } - else fprintf(stderr,"interests.%d %.8f %.8f\n",height,dstr(interests[ind]),dstr(interests[ind+1])); + //else fprintf(stderr,"interests.%d %.8f %.8f\n",height,dstr(interests[ind]),dstr(interests[ind+1])); } return(0); } From 319fa8be5567ca96f4f85bd9c53ff32a525992c1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Oct 2017 14:42:34 +0300 Subject: [PATCH 009/188] Test --- src/komodo_interest.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/komodo_interest.h b/src/komodo_interest.h index a01d9adea..4292c6771 100644 --- a/src/komodo_interest.h +++ b/src/komodo_interest.h @@ -24,6 +24,7 @@ uint64_t komodo_earned_interest(int32_t height,int64_t paidinterest) static uint64_t *interests; static int32_t maxheight; uint64_t total; int32_t ind,incr = 10000; // need to make interests persistent before 2030, or just hardfork interest/mining rewards disable after MAX_MONEY is exceeded + return(0); if ( height >= maxheight ) { if ( interests == 0 ) @@ -47,13 +48,13 @@ uint64_t komodo_earned_interest(int32_t height,int64_t paidinterest) { if ( interests[ind + 1] != paidinterest ) // need to handle skips like at 80000 { - fprintf(stderr,"interests.%d %.8f %.8f vs paidinterest %.8f\n",height,dstr(interests[ind]),dstr(interests[ind+1]),dstr(paidinterest)); + //fprintf(stderr,"interests.%d %.8f %.8f vs paidinterest %.8f\n",height,dstr(interests[ind]),dstr(interests[ind+1]),dstr(paidinterest)); interests[ind + 1] = paidinterest; if ( height <= 1 ) interests[ind] = 0; else interests[ind] = interests[ind - 2] + interests[ind - 1]; total = interests[ind] + paidinterest; - fprintf(stderr,"reset interests[height.%d to maxheight.%d] <- %.8f\n",height,maxheight,dstr(total)); + //fprintf(stderr,"reset interests[height.%d to maxheight.%d] <- %.8f\n",height,maxheight,dstr(total)); for (++height; height Date: Tue, 10 Oct 2017 14:59:33 +0300 Subject: [PATCH 010/188] Test --- src/komodo_interest.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_interest.h b/src/komodo_interest.h index 4292c6771..662087ae1 100644 --- a/src/komodo_interest.h +++ b/src/komodo_interest.h @@ -173,7 +173,7 @@ uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uin interest = ((numerator * minutes) / ((uint64_t)365 * 24 * 60)); //fprintf(stderr,"interest %llu %.8f <- numerator.%llu minutes.%d\n",(long long)interest,(double)interest/COIN,(long long)numerator,(int32_t)minutes); interestnew = _komodo_interestnew(nValue,nLockTime,tiptime); - if ( interest < interestnew || interestnew < 0.9999*interest ) + if ( interest < interestnew || (interestnew < 0.9999*interest && (interest-interestnow) > 10000) ) fprintf(stderr,"path1 current interest %.8f vs new %.8f for ht.%d %.8f locktime.%u tiptime.%u\n",dstr(interest),dstr(interestnew),txheight,dstr(nValue),nLockTime,tiptime); } else interest = _komodo_interestnew(nValue,nLockTime,tiptime); From 4a5b2da93bd43db1b9e31754aa485313a0e42e3c Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Oct 2017 15:04:52 +0300 Subject: [PATCH 011/188] Test --- src/komodo_interest.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_interest.h b/src/komodo_interest.h index 662087ae1..54791e48d 100644 --- a/src/komodo_interest.h +++ b/src/komodo_interest.h @@ -173,7 +173,7 @@ uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uin interest = ((numerator * minutes) / ((uint64_t)365 * 24 * 60)); //fprintf(stderr,"interest %llu %.8f <- numerator.%llu minutes.%d\n",(long long)interest,(double)interest/COIN,(long long)numerator,(int32_t)minutes); interestnew = _komodo_interestnew(nValue,nLockTime,tiptime); - if ( interest < interestnew || (interestnew < 0.9999*interest && (interest-interestnow) > 10000) ) + if ( interest < interestnew || (interestnew < 0.9999*interest && (interest-interestnew) > 10000) ) fprintf(stderr,"path1 current interest %.8f vs new %.8f for ht.%d %.8f locktime.%u tiptime.%u\n",dstr(interest),dstr(interestnew),txheight,dstr(nValue),nLockTime,tiptime); } else interest = _komodo_interestnew(nValue,nLockTime,tiptime); From 2ec7c24dc739c0ee2e57575fb11f637b1e93aa5a Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Oct 2017 15:11:11 +0300 Subject: [PATCH 012/188] Test --- src/komodo.h | 3 ++- src/komodo_interest.h | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index e1e40448d..23ccb6338 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -547,7 +547,8 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) numvalid = bitweight(signedmask); if ( (((height < 90000 || (signedmask & 1) != 0) && numvalid >= KOMODO_MINRATIFY) || numvalid > (numnotaries/5)) ) { - printf("%s ht.%d txi.%d signedmask.%llx numvins.%d numvouts.%d <<<<<<<<<<< notarized\n",ASSETCHAINS_SYMBOL,height,i,(long long)signedmask,numvins,numvouts); + if ( height > 500000 ) + printf("%s ht.%d txi.%d signedmask.%llx numvins.%d numvouts.%d <<<<<<<<<<< notarized\n",ASSETCHAINS_SYMBOL,height,i,(long long)signedmask,numvins,numvouts); notarized = 1; } if ( NOTARY_PUBKEY33[0] != 0 && ASSETCHAINS_SYMBOL[0] == 0 ) diff --git a/src/komodo_interest.h b/src/komodo_interest.h index 54791e48d..508ae2fac 100644 --- a/src/komodo_interest.h +++ b/src/komodo_interest.h @@ -173,7 +173,7 @@ uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uin interest = ((numerator * minutes) / ((uint64_t)365 * 24 * 60)); //fprintf(stderr,"interest %llu %.8f <- numerator.%llu minutes.%d\n",(long long)interest,(double)interest/COIN,(long long)numerator,(int32_t)minutes); interestnew = _komodo_interestnew(nValue,nLockTime,tiptime); - if ( interest < interestnew || (interestnew < 0.9999*interest && (interest-interestnew) > 10000) ) + if ( interest < interestnew || (interestnew < 0.9999*interest && (interest-interestnew) > 50000) ) fprintf(stderr,"path1 current interest %.8f vs new %.8f for ht.%d %.8f locktime.%u tiptime.%u\n",dstr(interest),dstr(interestnew),txheight,dstr(nValue),nLockTime,tiptime); } else interest = _komodo_interestnew(nValue,nLockTime,tiptime); From fc28273bfe9a1c8f83604c67d404712c5ace6f3a Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Oct 2017 15:20:08 +0300 Subject: [PATCH 013/188] Test --- src/komodo_interest.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_interest.h b/src/komodo_interest.h index 508ae2fac..82581bb03 100644 --- a/src/komodo_interest.h +++ b/src/komodo_interest.h @@ -173,7 +173,7 @@ uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uin interest = ((numerator * minutes) / ((uint64_t)365 * 24 * 60)); //fprintf(stderr,"interest %llu %.8f <- numerator.%llu minutes.%d\n",(long long)interest,(double)interest/COIN,(long long)numerator,(int32_t)minutes); interestnew = _komodo_interestnew(nValue,nLockTime,tiptime); - if ( interest < interestnew || (interestnew < 0.9999*interest && (interest-interestnew) > 50000) ) + if ( interest < interestnew )//|| (interestnew < 0.9999*interest && (interest-interestnew) > 50000) ) fprintf(stderr,"path1 current interest %.8f vs new %.8f for ht.%d %.8f locktime.%u tiptime.%u\n",dstr(interest),dstr(interestnew),txheight,dstr(nValue),nLockTime,tiptime); } else interest = _komodo_interestnew(nValue,nLockTime,tiptime); From 6cfebd395ac5992ccc32de3f1b08b43b61f8b11c Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Oct 2017 15:44:55 +0300 Subject: [PATCH 014/188] Test --- src/komodo_interest.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/komodo_interest.h b/src/komodo_interest.h index 82581bb03..930e2675a 100644 --- a/src/komodo_interest.h +++ b/src/komodo_interest.h @@ -140,14 +140,21 @@ uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uin numerator = (nValue / 20); // assumes 5%! if ( txheight < 250000 ) interest = (numerator / denominator); - else interest = (numerator * minutes) / ((uint64_t)365 * 24 * 60); + else if ( txheight < 1000000 ) + { + interest = (numerator * minutes) / ((uint64_t)365 * 24 * 60); + interestnew = _komodo_interestnew(nValue,nLockTime,tiptime); + //if ( interest < interestnew || interestnew < 0.9999*interest ) + fprintf(stderr,"path0 current interest %.8f vs new %.8f for ht.%d %.8f locktime.%u tiptime.%u\n",dstr(interest),dstr(interestnew),txheight,dstr(nValue),nLockTime,tiptime); + } + else interest = _komodo_interestnew(nValue,nLockTime,tiptime); } else if ( txheight < 1000000 ) { numerator = (nValue * KOMODO_INTEREST); interest = (numerator / denominator) / COIN; interestnew = _komodo_interestnew(nValue,nLockTime,tiptime); - //if ( interest < interestnew || interestnew < 0.9999*interest ) + if ( interest < interestnew ) fprintf(stderr,"path0 current interest %.8f vs new %.8f for ht.%d %.8f locktime.%u tiptime.%u\n",dstr(interest),dstr(interestnew),txheight,dstr(nValue),nLockTime,tiptime); } else interest = _komodo_interestnew(nValue,nLockTime,tiptime); From fb58b26e51b8225df77de20642c1f942b809e95f Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Oct 2017 16:00:35 +0300 Subject: [PATCH 015/188] Test --- src/komodo_interest.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/komodo_interest.h b/src/komodo_interest.h index 930e2675a..1795a64bf 100644 --- a/src/komodo_interest.h +++ b/src/komodo_interest.h @@ -144,8 +144,8 @@ uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uin { interest = (numerator * minutes) / ((uint64_t)365 * 24 * 60); interestnew = _komodo_interestnew(nValue,nLockTime,tiptime); - //if ( interest < interestnew || interestnew < 0.9999*interest ) - fprintf(stderr,"path0 current interest %.8f vs new %.8f for ht.%d %.8f locktime.%u tiptime.%u\n",dstr(interest),dstr(interestnew),txheight,dstr(nValue),nLockTime,tiptime); + if ( interest < interestnew ) + printf("path0 current interest %.8f vs new %.8f for ht.%d %.8f locktime.%u tiptime.%u\n",dstr(interest),dstr(interestnew),txheight,dstr(nValue),nLockTime,tiptime); } else interest = _komodo_interestnew(nValue,nLockTime,tiptime); } @@ -155,7 +155,7 @@ uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uin interest = (numerator / denominator) / COIN; interestnew = _komodo_interestnew(nValue,nLockTime,tiptime); if ( interest < interestnew ) - fprintf(stderr,"path0 current interest %.8f vs new %.8f for ht.%d %.8f locktime.%u tiptime.%u\n",dstr(interest),dstr(interestnew),txheight,dstr(nValue),nLockTime,tiptime); + printf("path0 current interest %.8f vs new %.8f for ht.%d %.8f locktime.%u tiptime.%u\n",dstr(interest),dstr(interestnew),txheight,dstr(nValue),nLockTime,tiptime); } else interest = _komodo_interestnew(nValue,nLockTime,tiptime); } @@ -181,7 +181,7 @@ uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uin //fprintf(stderr,"interest %llu %.8f <- numerator.%llu minutes.%d\n",(long long)interest,(double)interest/COIN,(long long)numerator,(int32_t)minutes); interestnew = _komodo_interestnew(nValue,nLockTime,tiptime); if ( interest < interestnew )//|| (interestnew < 0.9999*interest && (interest-interestnew) > 50000) ) - fprintf(stderr,"path1 current interest %.8f vs new %.8f for ht.%d %.8f locktime.%u tiptime.%u\n",dstr(interest),dstr(interestnew),txheight,dstr(nValue),nLockTime,tiptime); + printf("path1 current interest %.8f vs new %.8f for ht.%d %.8f locktime.%u tiptime.%u\n",dstr(interest),dstr(interestnew),txheight,dstr(nValue),nLockTime,tiptime); } else interest = _komodo_interestnew(nValue,nLockTime,tiptime); } From 1625f62f58265e9aead7dbd168be516fdebab7ba Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Oct 2017 23:51:01 +0300 Subject: [PATCH 016/188] More delay for assetchains.old --- src/assetchains.old | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/assetchains.old b/src/assetchains.old index aba219688..e7584afcd 100755 --- a/src/assetchains.old +++ b/src/assetchains.old @@ -1,6 +1,6 @@ #!/bin/bash set -x -delay=10 +delay=60 source pubkey.txt echo $pubkey From 1248a49e4f2d540ce1b45139e841b67c109d572a Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 15 Oct 2017 01:54:15 +0300 Subject: [PATCH 017/188] Fix windows .conf locations --- src/komodo_utils.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 4f2fd726e..e330a66ac 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1580,8 +1580,8 @@ void komodo_args(char *argv0) while ( fname[strlen(fname)-1] != '\\' ) fname[strlen(fname)-1] = 0; if ( iter == 0 ) - strcat(fname,".komodo\\komodo.conf"); - else strcat(fname,".bitcoin\\bitcoin.conf"); + strcat(fname,"Komodo\\komodo.conf"); + else strcat(fname,"Bitcoin\\bitcoin.conf"); #else while ( fname[strlen(fname)-1] != '/' ) fname[strlen(fname)-1] = 0; From 9cb1ec9c6ee2a26dcb7ca3eadc551a084c6128a5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 15 Oct 2017 02:04:29 +0300 Subject: [PATCH 018/188] WIN32 -> _WIN32 --- src/bitcoind.cpp | 2 +- src/compat.h | 10 +++++----- src/init.cpp | 14 +++++++------- src/komodo_pax.h | 2 +- src/komodo_structs.h | 2 +- src/komodo_utils.h | 10 +++++----- src/metrics.cpp | 4 ++-- src/net.cpp | 16 ++++++++-------- src/net.h | 2 +- src/netbase.cpp | 18 +++++++++--------- src/netbase.h | 2 +- src/protocol.cpp | 2 +- src/random.cpp | 6 +++--- src/support/pagelocker.cpp | 6 +++--- src/test/alert_tests.cpp | 2 +- src/util.cpp | 30 +++++++++++++++--------------- src/util.h | 6 +++--- src/wallet/db.cpp | 2 +- 18 files changed, 68 insertions(+), 68 deletions(-) diff --git a/src/bitcoind.cpp b/src/bitcoind.cpp index 26e9c8327..050305117 100644 --- a/src/bitcoind.cpp +++ b/src/bitcoind.cpp @@ -173,7 +173,7 @@ bool AppInit(int argc, char* argv[]) exit(1); } -#ifndef WIN32 +#ifndef _WIN32 fDaemon = GetBoolArg("-daemon", false); if (fDaemon) { diff --git a/src/compat.h b/src/compat.h index feaa544e2..27afc8b2a 100644 --- a/src/compat.h +++ b/src/compat.h @@ -10,7 +10,7 @@ #include "config/bitcoin-config.h" #endif -#ifdef WIN32 +#ifdef _WIN32 #ifdef _WIN32_WINNT #undef _WIN32_WINNT #endif @@ -46,7 +46,7 @@ #include #endif -#ifdef WIN32 +#ifdef _WIN32 #define MSG_DONTWAIT 0 #else typedef u_int SOCKET; @@ -64,7 +64,7 @@ typedef u_int SOCKET; #define SOCKET_ERROR -1 #endif -#ifdef WIN32 +#ifdef _WIN32 #ifndef S_IRUSR #define S_IRUSR 0400 #define S_IWUSR 0200 @@ -78,7 +78,7 @@ typedef u_int SOCKET; #define MSG_NOSIGNAL 0 #endif -#ifndef WIN32 +#ifndef _WIN32 // PRIO_MAX is not defined on Solaris #ifndef PRIO_MAX #define PRIO_MAX 20 @@ -94,7 +94,7 @@ size_t strnlen( const char *start, size_t max_len); #endif // HAVE_DECL_STRNLEN bool static inline IsSelectableSocket(SOCKET s) { -#ifdef WIN32 +#ifdef _WIN32 return true; #else return (s < FD_SETSIZE); diff --git a/src/init.cpp b/src/init.cpp index 7905b268e..fe10401a8 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -40,7 +40,7 @@ #include #include -#ifndef WIN32 +#ifndef _WIN32 #include #endif @@ -74,7 +74,7 @@ bool fFeeEstimatesInitialized = false; static CZMQNotificationInterface* pzmqNotificationInterface = NULL; #endif -#ifdef WIN32 +#ifdef _WIN32 // Win32 LevelDB doesn't use file descriptors, and the ones used for // accessing block files don't count towards the fd_set size limit // anyway. @@ -236,7 +236,7 @@ void Shutdown() } #endif -#ifndef WIN32 +#ifndef _WIN32 try { boost::filesystem::remove(GetPidFile()); } catch (const boost::filesystem::filesystem_error& e) { @@ -334,7 +334,7 @@ std::string HelpMessage(HelpMessageMode mode) strUsage += HelpMessageOpt("-maxorphantx=", strprintf(_("Keep at most unconnectable transactions in memory (default: %u)"), DEFAULT_MAX_ORPHAN_TRANSACTIONS)); strUsage += HelpMessageOpt("-par=", strprintf(_("Set the number of script verification threads (%u to %d, 0 = auto, <0 = leave that many cores free, default: %d)"), -(int)boost::thread::hardware_concurrency(), MAX_SCRIPTCHECK_THREADS, DEFAULT_SCRIPTCHECK_THREADS)); -#ifndef WIN32 +#ifndef _WIN32 strUsage += HelpMessageOpt("-pid=", strprintf(_("Specify pid file (default: %s)"), "komodod.pid")); #endif strUsage += HelpMessageOpt("-prune=", strprintf(_("Reduce storage requirements by pruning (deleting) old blocks. This mode disables wallet support and is incompatible with -txindex. " @@ -716,7 +716,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) // Disable confusing "helpful" text message on abort, Ctrl-C _set_abort_behavior(0, _WRITE_ABORT_MSG | _CALL_REPORTFAULT); #endif -#ifdef WIN32 +#ifdef _WIN32 // Enable Data Execution Prevention (DEP) // Minimum supported OS versions: WinXP SP3, WinVista >= SP1, Win Server 2008 // A failure is non-critical and needs no further attention! @@ -733,7 +733,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) if (!SetupNetworking()) return InitError("Error: Initializing networking failed"); -#ifndef WIN32 +#ifndef _WIN32 if (GetBoolArg("-sysperms", false)) { #ifdef ENABLE_WALLET if (!GetBoolArg("-disablewallet", false)) @@ -1047,7 +1047,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) return InitError(strprintf(_("Cannot obtain a lock on data directory %s. Komodo is probably already running.") + " %s.", strDataDir, e.what())); } -#ifndef WIN32 +#ifndef _WIN32 CreatePidFile(GetPidFile(), getpid()); #endif if (GetBoolArg("-shrinkdebugfile", !fDebug)) diff --git a/src/komodo_pax.h b/src/komodo_pax.h index 55b14bd4a..f5655e6f1 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -233,7 +233,7 @@ int32_t komodo_pax_opreturn(int32_t height,uint8_t *opret,int32_t maxsize) { static uint32_t lastcrc; FILE *fp; char fname[512]; uint32_t crc32,check,timestamp; int32_t i,n=0,retval,fsize,len=0; uint8_t data[8192]; -#ifdef WIN32 +#ifdef _WIN32 sprintf(fname,"%s\\%s",GetDataDir(false).string().c_str(),(char *)"komodofeed"); #else sprintf(fname,"%s/%s",GetDataDir(false).string().c_str(),(char *)"komodofeed"); diff --git a/src/komodo_structs.h b/src/komodo_structs.h index a35e7e008..510a7e488 100644 --- a/src/komodo_structs.h +++ b/src/komodo_structs.h @@ -16,7 +16,7 @@ #include "uthash.h" #include "utlist.h" -/*#ifdef WIN32 +/*#ifdef _WIN32 #define PACKED #else #define PACKED __attribute__((packed)) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index e330a66ac..e3749a5b1 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1305,7 +1305,7 @@ void komodo_statefname(char *fname,char *symbol,char *str) } else { -#ifdef WIN32 +#ifdef _WIN32 strcat(fname,"\\"); #else strcat(fname,"/"); @@ -1315,7 +1315,7 @@ void komodo_statefname(char *fname,char *symbol,char *str) { strcat(fname,symbol); //printf("statefname.(%s) -> (%s)\n",symbol,fname); -#ifdef WIN32 +#ifdef _WIN32 strcat(fname,"\\"); #else strcat(fname,"/"); @@ -1347,7 +1347,7 @@ void komodo_configfile(char *symbol,uint16_t port) password[i*2] = 0; sprintf(buf,"%s.conf",symbol); BITCOIND_PORT = port; -#ifdef WIN32 +#ifdef _WIN32 sprintf(fname,"%s\\%s",GetDataDir(false).string().c_str(),buf); #else sprintf(fname,"%s/%s",GetDataDir(false).string().c_str(),buf); @@ -1371,7 +1371,7 @@ void komodo_configfile(char *symbol,uint16_t port) } } strcpy(fname,GetDataDir().string().c_str()); -#ifdef WIN32 +#ifdef _WIN32 while ( fname[strlen(fname)-1] != '\\' ) fname[strlen(fname)-1] = 0; strcat(fname,"komodo.conf"); @@ -1576,7 +1576,7 @@ void komodo_args(char *argv0) for (iter=0; iter<2; iter++) { strcpy(fname,GetDataDir().string().c_str()); -#ifdef WIN32 +#ifdef _WIN32 while ( fname[strlen(fname)-1] != '\\' ) fname[strlen(fname)-1] = 0; if ( iter == 0 ) diff --git a/src/metrics.cpp b/src/metrics.cpp index 92e4b6590..b45b5dc6b 100644 --- a/src/metrics.cpp +++ b/src/metrics.cpp @@ -411,7 +411,7 @@ void ThreadShowMetricsScreen() // Get current window size if (isTTY) { - #ifdef WIN32 +#ifdef _WIN32 CONSOLE_SCREEN_BUFFER_INFO csbi; GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi); cols = csbi.srWindow.Right - csbi.srWindow.Left + 1; @@ -421,7 +421,7 @@ void ThreadShowMetricsScreen() if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &w) != -1 && w.ws_col != 0) { cols = w.ws_col; } - #endif +#endif } if (isScreen) { diff --git a/src/net.cpp b/src/net.cpp index 073353be5..0dcdae7db 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -17,7 +17,7 @@ #include "ui_interface.h" #include "crypto/common.h" -#ifdef WIN32 +#ifdef _WIN32 #include #else #include @@ -42,7 +42,7 @@ // Fix for ancient MinGW versions, that don't have defined these in ws2tcpip.h. // Todo: Can be removed when our pull-tester is upgraded to a modern MinGW version. -#ifdef WIN32 +#ifdef _WIN32 #ifndef PROTECTION_LEVEL_UNRESTRICTED #define PROTECTION_LEVEL_UNRESTRICTED 10 #endif @@ -930,7 +930,7 @@ static void AcceptConnection(const ListenSocket& hListenSocket) { // According to the internet TCP_NODELAY is not carried into accepted sockets // on all platforms. Set it again here just to be sure. int set = 1; -#ifdef WIN32 +#ifdef _WIN32 setsockopt(hSocket, IPPROTO_TCP, TCP_NODELAY, (const char*)&set, sizeof(int)); #else setsockopt(hSocket, IPPROTO_TCP, TCP_NODELAY, (void*)&set, sizeof(int)); @@ -1727,7 +1727,7 @@ bool BindListenPort(const CService &addrBind, string& strError, bool fWhiteliste } -#ifndef WIN32 +#ifndef _WIN32 #ifdef SO_NOSIGPIPE // Different way of disabling SIGPIPE on BSD setsockopt(hListenSocket, SOL_SOCKET, SO_NOSIGPIPE, (void*)&nOne, sizeof(int)); @@ -1753,13 +1753,13 @@ bool BindListenPort(const CService &addrBind, string& strError, bool fWhiteliste // and enable it by default or not. Try to enable it, if possible. if (addrBind.IsIPv6()) { #ifdef IPV6_V6ONLY -#ifdef WIN32 +#ifdef _WIN32 setsockopt(hListenSocket, IPPROTO_IPV6, IPV6_V6ONLY, (const char*)&nOne, sizeof(int)); #else setsockopt(hListenSocket, IPPROTO_IPV6, IPV6_V6ONLY, (void*)&nOne, sizeof(int)); #endif #endif -#ifdef WIN32 +#ifdef _WIN32 int nProtLevel = PROTECTION_LEVEL_UNRESTRICTED; setsockopt(hListenSocket, IPPROTO_IPV6, IPV6_PROTECTION_LEVEL, (const char*)&nProtLevel, sizeof(int)); #endif @@ -1800,7 +1800,7 @@ void static Discover(boost::thread_group& threadGroup) if (!fDiscover) return; -#ifdef WIN32 +#ifdef _WIN32 // Get local host IP char pszHostName[256] = ""; if (gethostname(pszHostName, sizeof(pszHostName)) != SOCKET_ERROR) @@ -1945,7 +1945,7 @@ public: delete pnodeLocalHost; pnodeLocalHost = NULL; -#ifdef WIN32 +#ifdef _WIN32 // Shutdown Windows Sockets WSACleanup(); #endif diff --git a/src/net.h b/src/net.h index bb79acf17..6f28f3872 100644 --- a/src/net.h +++ b/src/net.h @@ -22,7 +22,7 @@ #include #include -#ifndef WIN32 +#ifndef _WIN32 #include #endif diff --git a/src/netbase.cpp b/src/netbase.cpp index c65d66ac1..6a28532f1 100644 --- a/src/netbase.cpp +++ b/src/netbase.cpp @@ -26,7 +26,7 @@ #include #endif -#ifndef WIN32 +#ifndef _WIN32 #if HAVE_INET_PTON #include #endif @@ -129,7 +129,7 @@ bool static LookupIntern(const char *pszName, std::vector& vIP, unsign aiHint.ai_socktype = SOCK_STREAM; aiHint.ai_protocol = IPPROTO_TCP; aiHint.ai_family = AF_UNSPEC; -#ifdef WIN32 +#ifdef _WIN32 aiHint.ai_flags = fAllowLookup ? 0 : AI_NUMERICHOST; #else aiHint.ai_flags = fAllowLookup ? AI_ADDRCONFIG : AI_NUMERICHOST; @@ -454,7 +454,7 @@ bool static ConnectSocketDirectly(const CService &addrConnect, SOCKET& hSocketRe #endif //Disable Nagle's algorithm -#ifdef WIN32 +#ifdef _WIN32 setsockopt(hSocket, IPPROTO_TCP, TCP_NODELAY, (const char*)&set, sizeof(int)); #else setsockopt(hSocket, IPPROTO_TCP, TCP_NODELAY, (void*)&set, sizeof(int)); @@ -488,7 +488,7 @@ bool static ConnectSocketDirectly(const CService &addrConnect, SOCKET& hSocketRe return false; } socklen_t nRetSize = sizeof(nRet); -#ifdef WIN32 +#ifdef _WIN32 if (getsockopt(hSocket, SOL_SOCKET, SO_ERROR, (char*)(&nRet), &nRetSize) == SOCKET_ERROR) #else if (getsockopt(hSocket, SOL_SOCKET, SO_ERROR, &nRet, &nRetSize) == SOCKET_ERROR) @@ -505,7 +505,7 @@ bool static ConnectSocketDirectly(const CService &addrConnect, SOCKET& hSocketRe return false; } } -#ifdef WIN32 +#ifdef _WIN32 else if (WSAGetLastError() != WSAEISCONN) #else else @@ -1348,7 +1348,7 @@ bool operator<(const CSubNet& a, const CSubNet& b) return (a.network < b.network || (a.network == b.network && memcmp(a.netmask, b.netmask, 16) < 0)); } -#ifdef WIN32 +#ifdef _WIN32 std::string NetworkErrorString(int err) { char buf[256]; @@ -1386,7 +1386,7 @@ bool CloseSocket(SOCKET& hSocket) { if (hSocket == INVALID_SOCKET) return false; -#ifdef WIN32 +#ifdef _WIN32 int ret = closesocket(hSocket); #else int ret = close(hSocket); @@ -1398,7 +1398,7 @@ bool CloseSocket(SOCKET& hSocket) bool SetSocketNonBlocking(SOCKET& hSocket, bool fNonBlocking) { if (fNonBlocking) { -#ifdef WIN32 +#ifdef _WIN32 u_long nOne = 1; if (ioctlsocket(hSocket, FIONBIO, &nOne) == SOCKET_ERROR) { #else @@ -1409,7 +1409,7 @@ bool SetSocketNonBlocking(SOCKET& hSocket, bool fNonBlocking) return false; } } else { -#ifdef WIN32 +#ifdef _WIN32 u_long nZero = 0; if (ioctlsocket(hSocket, FIONBIO, &nZero) == SOCKET_ERROR) { #else diff --git a/src/netbase.h b/src/netbase.h index 21ac0aa4c..83ce22663 100644 --- a/src/netbase.h +++ b/src/netbase.h @@ -22,7 +22,7 @@ extern bool fNameLookup; /** -timeout default */ static const int DEFAULT_CONNECT_TIMEOUT = 5000; -#ifdef WIN32 +#ifdef _WIN32 // In MSVC, this is defined as a macro, undefine it to prevent a compile and link error #undef SetPort #endif diff --git a/src/protocol.cpp b/src/protocol.cpp index dd855aa33..33b9ee773 100644 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -8,7 +8,7 @@ #include "util.h" #include "utilstrencodings.h" -#ifndef WIN32 +#ifndef _WIN32 # include #endif diff --git a/src/random.cpp b/src/random.cpp index 29faa32a7..87b3f648e 100644 --- a/src/random.cpp +++ b/src/random.cpp @@ -6,7 +6,7 @@ #include "random.h" #include "support/cleanse.h" -#ifdef WIN32 +#ifdef _WIN32 #include "compat.h" // for Windows API #endif #include "serialize.h" // for begin_ptr(vec) @@ -15,7 +15,7 @@ #include -#ifndef WIN32 +#ifndef _WIN32 #include #endif @@ -24,7 +24,7 @@ static inline int64_t GetPerformanceCounter() { int64_t nCounter = 0; -#ifdef WIN32 +#ifdef _WIN32 QueryPerformanceCounter((LARGE_INTEGER*)&nCounter); #else timeval t; diff --git a/src/support/pagelocker.cpp b/src/support/pagelocker.cpp index 440e0a519..d0b0d4dd8 100644 --- a/src/support/pagelocker.cpp +++ b/src/support/pagelocker.cpp @@ -8,7 +8,7 @@ #include "config/bitcoin-config.h" #endif -#ifdef WIN32 +#ifdef _WIN32 #ifdef _WIN32_WINNT #undef _WIN32_WINNT #endif @@ -49,7 +49,7 @@ static inline size_t GetSystemPageSize() bool MemoryPageLocker::Lock(const void* addr, size_t len) { -#ifdef WIN32 +#ifdef _WIN32 return VirtualLock(const_cast(addr), len) != 0; #else return mlock(addr, len) == 0; @@ -58,7 +58,7 @@ bool MemoryPageLocker::Lock(const void* addr, size_t len) bool MemoryPageLocker::Unlock(const void* addr, size_t len) { -#ifdef WIN32 +#ifdef _WIN32 return VirtualUnlock(const_cast(addr), len) != 0; #else return munlock(addr, len) == 0; diff --git a/src/test/alert_tests.cpp b/src/test/alert_tests.cpp index ab3841c48..ef607dacc 100644 --- a/src/test/alert_tests.cpp +++ b/src/test/alert_tests.cpp @@ -340,7 +340,7 @@ BOOST_AUTO_TEST_CASE(AlertNotify) // Windows built-in echo semantics are different than posixy shells. Quotes and // whitespace are printed literally. -#ifndef WIN32 +#ifndef _WIN32 BOOST_CHECK_EQUAL(r[0], "Alert 1"); BOOST_CHECK_EQUAL(r[1], "Alert 2, cancels 1"); BOOST_CHECK_EQUAL(r[2], "Alert 2, cancels 1"); diff --git a/src/util.cpp b/src/util.cpp index b452cea72..ec83e17ce 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -23,7 +23,7 @@ #include #endif -#ifndef WIN32 +#ifndef _WIN32 // for posix_fallocate #ifdef __linux__ @@ -335,7 +335,7 @@ void ParseParameters(int argc, const char* const argv[]) strValue = str.substr(is_index+1); str = str.substr(0, is_index); } -#ifdef WIN32 +#ifdef _WIN32 boost::to_lower(str); if (boost::algorithm::starts_with(str, "/")) str = "-" + str.substr(1); @@ -419,7 +419,7 @@ std::string HelpMessageOpt(const std::string &option, const std::string &message static std::string FormatException(const std::exception* pex, const char* pszThread) { -#ifdef WIN32 +#ifdef _WIN32 char pszModule[MAX_PATH] = ""; GetModuleFileNameA(NULL, pszModule, sizeof(pszModule)); #else @@ -455,7 +455,7 @@ boost::filesystem::path GetDefaultDataDir() // Windows >= Vista: C:\Users\Username\AppData\Roaming\Zcash // Mac: ~/Library/Application Support/Zcash // Unix: ~/.zcash -#ifdef WIN32 +#ifdef _WIN32 // Windows if ( symbol[0] == 0 ) return GetSpecialFolderPath(CSIDL_APPDATA) / "Komodo"; @@ -502,7 +502,7 @@ static boost::filesystem::path ZC_GetBaseParamsDir() // Windows >= Vista: C:\Users\Username\AppData\Roaming\ZcashParams // Mac: ~/Library/Application Support/ZcashParams // Unix: ~/.zcash-params -#ifdef WIN32 +#ifdef _WIN32 // Windows return GetSpecialFolderPath(CSIDL_APPDATA) / "ZcashParams"; #else @@ -648,7 +648,7 @@ void ReadConfigFile(map& mapSettingsRet, //fprintf(stderr,"from conf file %s RPC %u, used to be %u\n",ASSETCHAINS_SYMBOL,BITCOIND_PORT,BITCOIND_PORT); } -#ifndef WIN32 +#ifndef _WIN32 boost::filesystem::path GetPidFile() { boost::filesystem::path pathPidFile(GetArg("-pid", "komodod.pid")); @@ -669,13 +669,13 @@ void CreatePidFile(const boost::filesystem::path &path, pid_t pid) bool RenameOver(boost::filesystem::path src, boost::filesystem::path dest) { -#ifdef WIN32 +#ifdef _WIN32 return MoveFileExA(src.string().c_str(), dest.string().c_str(), MOVEFILE_REPLACE_EXISTING) != 0; #else int rc = std::rename(src.string().c_str(), dest.string().c_str()); return (rc == 0); -#endif /* WIN32 */ +#endif /* _WIN32 */ } /** @@ -700,7 +700,7 @@ bool TryCreateDirectory(const boost::filesystem::path& p) void FileCommit(FILE *fileout) { fflush(fileout); // harmless if redundantly called -#ifdef WIN32 +#ifdef _WIN32 HANDLE hFile = (HANDLE)_get_osfhandle(_fileno(fileout)); FlushFileBuffers(hFile); #else @@ -815,7 +815,7 @@ void ShrinkDebugFile() fclose(file); } -#ifdef WIN32 +#ifdef _WIN32 boost::filesystem::path GetSpecialFolderPath(int nFolder, bool fCreate) { namespace fs = boost::filesystem; @@ -838,7 +838,7 @@ boost::filesystem::path GetTempPath() { #else // TODO: remove when we don't support filesystem v2 anymore boost::filesystem::path path; -#ifdef WIN32 +#ifdef _WIN32 char pszPath[MAX_PATH] = ""; if (GetTempPathA(MAX_PATH, pszPath)) @@ -898,7 +898,7 @@ void SetupEnvironment() bool SetupNetworking() { -#ifdef WIN32 +#ifdef _WIN32 // Initialize Windows Sockets WSADATA wsadata; int ret = WSAStartup(MAKEWORD(2,2), &wsadata); @@ -910,15 +910,15 @@ bool SetupNetworking() void SetThreadPriority(int nPriority) { -#ifdef WIN32 +#ifdef _WIN32 SetThreadPriority(GetCurrentThread(), nPriority); -#else // WIN32 +#else // _WIN32 #ifdef PRIO_THREAD setpriority(PRIO_THREAD, 0, nPriority); #else // PRIO_THREAD setpriority(PRIO_PROCESS, 0, nPriority); #endif // PRIO_THREAD -#endif // WIN32 +#endif // _WIN32 } std::string PrivacyInfo() diff --git a/src/util.h b/src/util.h index 361a9271f..424c6693a 100644 --- a/src/util.h +++ b/src/util.h @@ -124,7 +124,7 @@ boost::filesystem::path GetDefaultDataDir(); const boost::filesystem::path &GetDataDir(bool fNetSpecific = true); void ClearDatadirCache(); boost::filesystem::path GetConfigFile(); -#ifndef WIN32 +#ifndef _WIN32 boost::filesystem::path GetPidFile(); void CreatePidFile(const boost::filesystem::path &path, pid_t pid); #endif @@ -133,7 +133,7 @@ public: missing_zcash_conf() : std::runtime_error("Missing komodo.conf") { } }; void ReadConfigFile(std::map& mapSettingsRet, std::map >& mapMultiSettingsRet); -#ifdef WIN32 +#ifdef _WIN32 boost::filesystem::path GetSpecialFolderPath(int nFolder, bool fCreate = true); #endif boost::filesystem::path GetTempPath(); @@ -150,7 +150,7 @@ std::string LicenseInfo(); inline bool IsSwitchChar(char c) { -#ifdef WIN32 +#ifdef _WIN32 return c == '-' || c == '/'; #else return c == '-'; diff --git a/src/wallet/db.cpp b/src/wallet/db.cpp index 766e2afda..c6beb8a52 100644 --- a/src/wallet/db.cpp +++ b/src/wallet/db.cpp @@ -13,7 +13,7 @@ #include -#ifndef WIN32 +#ifndef _WIN32 #include #endif From db402e48fc2dc33365e69646d40e63d241ef5c1b Mon Sep 17 00:00:00 2001 From: ca333 Date: Sun, 15 Oct 2017 23:51:22 +0200 Subject: [PATCH 019/188] linux build os detection --- depends/packages/packages.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/depends/packages/packages.mk b/depends/packages/packages.mk index b1951431a..3cf52d62f 100644 --- a/depends/packages/packages.mk +++ b/depends/packages/packages.mk @@ -1,7 +1,7 @@ rust_packages := rust librustzcash zcash_packages := libsnark libgmp libsodium -ifeq ($(host_os),linux) +ifeq ($(build_os),linux) packages := boost openssl libevent zeromq $(zcash_packages) googletest googlemock else packages := boost openssl libevent zeromq $(zcash_packages) googletest googlemock libcurl From 89559d8575fa0bb06e5ab503866e5259986fcb5f Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 16 Oct 2017 21:16:37 +0300 Subject: [PATCH 020/188] Remove print --- src/komodo_utils.h | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index e3749a5b1..cc935a363 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1507,17 +1507,17 @@ void komodo_args(char *argv0) KOMODO_PAX = 1; } else KOMODO_PAX = GetArg("-pax",0); name = GetArg("-ac_name",""); - if ( argv0 != 0 ) - { - len = (int32_t)strlen(argv0); - for (i=0; i matches suffix (%s) -> ac_name.(%s)\n",argv0,argv0suffix[i],argv0names[i]); - name = argv0names[i]; - break; + if ( argv0 != 0 ) + { + len = (int32_t)strlen(argv0); + for (i=0; i matches suffix (%s) -> ac_name.(%s)\n",argv0,argv0suffix[i],argv0names[i]); + name = argv0names[i]; + break; } } } From 79383e0a78d68cea33acc7bea66b046c9f5ce8ec Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 18 Oct 2017 22:40:29 +0300 Subject: [PATCH 021/188] Change to new interest calc --- src/wallet/wallet.cpp | 105 +++++++++++++++++------------------------- src/wallet/wallet.h | 4 +- 2 files changed, 44 insertions(+), 65 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 13045f21e..595497b22 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2202,7 +2202,7 @@ CAmount CWallet::GetImmatureWatchOnlyBalance() const /** * populate vCoins with vector of available COutputs. */ -uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uint32_t tiptime); +uint64_t komodo_interestnew(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uint32_t tiptime); uint64_t komodo_accrued_interest(int32_t *txheightp,uint32_t *locktimep,uint256 hash,int32_t n,int32_t checkheight,uint64_t checkvalue); void CWallet::AvailableCoins(vector& vCoins, bool fOnlyConfirmed, const CCoinControl *coinControl, bool fIncludeZeroValue, bool fIncludeCoinBase) const @@ -2250,9 +2250,9 @@ void CWallet::AvailableCoins(vector& vCoins, bool fOnlyConfirmed, const komodo_accrued_interest(&txheight,&locktime,wtxid,i,0,pcoin->vout[i].nValue); if ( (tipindex= chainActive.Tip()) != 0 ) { - interest = komodo_interest(txheight,pcoin->vout[i].nValue,locktime,tipindex->nTime); + interest = komodo_interestnew(txheight,pcoin->vout[i].nValue,locktime,tipindex->nTime); } else interest = 0; - //interest = komodo_interest(chainActive.Tip()->nHeight+1,pcoin->vout[i].nValue,pcoin->nLockTime,chainActive.Tip()->nTime); + //interest = komodo_interestnew(chainActive.Tip()->nHeight+1,pcoin->vout[i].nValue,pcoin->nLockTime,chainActive.Tip()->nTime); if ( interest != 0 ) { //printf("wallet nValueRet %.8f += interest %.8f ht.%d lock.%u/%u tip.%u\n",(double)pcoin->vout[i].nValue/COIN,(double)interest/COIN,txheight,locktime,pcoin->nLockTime,tipindex->nTime); @@ -2333,13 +2333,12 @@ static void ApproximateBestSubset(vector vCoins,set >& setCoinsRet, CAmount& nValueRet, uint64_t *interestp) const +bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int nConfTheirs, vector vCoins,set >& setCoinsRet, CAmount& nValueRet) const { - uint64_t interests[10000],lowest_interest = 0; int32_t count = 0; + int32_t count = 0; //uint64_t lowest_interest = 0; setCoinsRet.clear(); - memset(interests,0,sizeof(interests)); + //memset(interests,0,sizeof(interests)); nValueRet = 0; - //*interestp = 0; // List of values less than target pair > coinLowestLarger; coinLowestLarger.first = std::numeric_limits::max(); @@ -2368,20 +2367,20 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int { setCoinsRet.insert(coin.second); nValueRet += coin.first; - if ( KOMODO_EXCHANGEWALLET == 0 ) - *interestp += pcoin->vout[i].interest; + //if ( KOMODO_EXCHANGEWALLET == 0 ) + // *interestp += pcoin->vout[i].interest; return true; } else if (n < nTargetValue + CENT) { vValue.push_back(coin); nTotalLower += n; - if ( KOMODO_EXCHANGEWALLET == 0 && count < sizeof(interests)/sizeof(*interests) ) - { + //if ( KOMODO_EXCHANGEWALLET == 0 && count < sizeof(interests)/sizeof(*interests) ) + //{ //fprintf(stderr,"count.%d %.8f\n",count,(double)pcoin->vout[i].interest/COIN); - interests[count++] = pcoin->vout[i].interest; - } - if ( count >= sizeof(interests)/sizeof(*interests) && nTotalLower > 2*nTargetValue + CENT ) + //interests[count++] = pcoin->vout[i].interest; + //} + if ( nTotalLower > 4*nTargetValue + CENT ) { //fprintf(stderr,"why bother with all the utxo if we have double what is needed?\n"); break; @@ -2390,8 +2389,8 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int else if (n < coinLowestLarger.first) { coinLowestLarger = coin; - if ( KOMODO_EXCHANGEWALLET == 0 ) - lowest_interest = pcoin->vout[i].interest; + //if ( KOMODO_EXCHANGEWALLET == 0 ) + // lowest_interest = pcoin->vout[i].interest; } } @@ -2401,8 +2400,8 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int { setCoinsRet.insert(vValue[i].second); nValueRet += vValue[i].first; - if ( KOMODO_EXCHANGEWALLET == 0 && i < count ) - *interestp += interests[i]; + //if ( KOMODO_EXCHANGEWALLET == 0 && i < count ) + // *interestp += interests[i]; } return true; } @@ -2413,8 +2412,8 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int return false; setCoinsRet.insert(coinLowestLarger.second); nValueRet += coinLowestLarger.first; - if ( KOMODO_EXCHANGEWALLET == 0 ) - *interestp += lowest_interest; + //if ( KOMODO_EXCHANGEWALLET == 0 ) + // *interestp += lowest_interest; return true; } @@ -2434,8 +2433,8 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int { setCoinsRet.insert(coinLowestLarger.second); nValueRet += coinLowestLarger.first; - if ( KOMODO_EXCHANGEWALLET == 0 ) - *interestp += lowest_interest; + //if ( KOMODO_EXCHANGEWALLET == 0 ) + // *interestp += lowest_interest; } else { for (unsigned int i = 0; i < vValue.size(); i++) @@ -2443,8 +2442,8 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int { setCoinsRet.insert(vValue[i].second); nValueRet += vValue[i].first; - if ( KOMODO_EXCHANGEWALLET == 0 && i < count ) - *interestp += interests[i]; + //if ( KOMODO_EXCHANGEWALLET == 0 && i < count ) + // *interestp += interests[i]; } LogPrint("selectcoins", "SelectCoins() best subset: "); @@ -2457,15 +2456,15 @@ bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int return true; } -bool CWallet::SelectCoins(const CAmount& nTargetValue, set >& setCoinsRet, CAmount& nValueRet, bool& fOnlyCoinbaseCoinsRet, bool& fNeedCoinbaseCoinsRet, const CCoinControl* coinControl,uint64_t *interestp) const +bool CWallet::SelectCoins(const CAmount& nTargetValue, set >& setCoinsRet, CAmount& nValueRet, bool& fOnlyCoinbaseCoinsRet, bool& fNeedCoinbaseCoinsRet, const CCoinControl* coinControl) const { // Output parameter fOnlyCoinbaseCoinsRet is set to true when the only available coins are coinbase utxos. - uint64_t tmp,interest = 0; int32_t retval; - if ( interestp == 0 ) - { - interestp = &tmp; - *interestp = 0; - } + uint64_t tmp; int32_t retval; + //if ( interestp == 0 ) + //{ + // interestp = &tmp; + // *interestp = 0; + //} vector vCoinsNoCoinbase, vCoinsWithCoinbase; AvailableCoins(vCoinsNoCoinbase, true, coinControl, false, false); AvailableCoins(vCoinsWithCoinbase, true, coinControl, false, true); @@ -2507,8 +2506,8 @@ bool CWallet::SelectCoins(const CAmount& nTargetValue, setvout[out.i].nValue; - if ( KOMODO_EXCHANGEWALLET == 0 ) - *interestp += out.tx->vout[out.i].interest; + //if ( KOMODO_EXCHANGEWALLET == 0 ) + // *interestp += out.tx->vout[out.i].interest; setCoinsRet.insert(make_pair(out.tx, out.i)); } return (nValueRet >= nTargetValue); @@ -2548,36 +2547,16 @@ bool CWallet::SelectCoins(const CAmount& nTargetValue, set& vecSend, CWalletTx& wtxNew, CReserveKey& reservekey, CAmount& nFeeRet, int& nChangePosRet, std::string& strFailReason, const CCoinControl* coinControl, bool sign) { - uint64_t interest2,interest = 0; CAmount nValue = 0; unsigned int nSubtractFeeFromAmount = 0; + uint64_t interest2 = 0; CAmount nValue = 0; unsigned int nSubtractFeeFromAmount = 0; BOOST_FOREACH (const CRecipient& recipient, vecSend) { if (nValue < 0 || recipient.nAmount < 0) @@ -2733,7 +2712,7 @@ bool CWallet::CreateTransaction(const vector& vecSend, CWalletTx& wt bool fOnlyCoinbaseCoins = false; bool fNeedCoinbaseCoins = false; interest2 = 0; - if (!SelectCoins(nTotalValue, setCoins, nValueIn, fOnlyCoinbaseCoins, fNeedCoinbaseCoins, coinControl,&interest)) + if (!SelectCoins(nTotalValue, setCoins, nValueIn, fOnlyCoinbaseCoins, fNeedCoinbaseCoins, coinControl)) { if (fOnlyCoinbaseCoins && Params().GetConsensus().fCoinbaseMustBeProtected) { strFailReason = _("Coinbase funds can only be sent to a zaddr"); @@ -2762,13 +2741,13 @@ bool CWallet::CreateTransaction(const vector& vecSend, CWalletTx& wt age += 1; dPriority += (double)nCredit * age; } - if ( KOMODO_EXCHANGEWALLET != 0 ) - { + //if ( KOMODO_EXCHANGEWALLET != 0 ) + //{ //fprintf(stderr,"KOMODO_EXCHANGEWALLET disable interest sum %.8f, interest2 %.8f\n",(double)interest/COIN,(double)interest2/COIN); - interest = 0; // interest2 also - } + //interest = 0; // interest2 also + //} CAmount nChange = (nValueIn - nValue + interest2); -fprintf(stderr,"wallet change %.8f (%.8f - %.8f) interest %.8f interest2 %.8f total %.8f\n",(double)nChange/COIN,(double)nValueIn/COIN,(double)nValue/COIN,(double)interest2/COIN,(double)interest/COIN,(double)nTotalValue/COIN); +fprintf(stderr,"wallet change %.8f (%.8f - %.8f) interest2 %.8f total %.8f\n",(double)nChange/COIN,(double)nValueIn/COIN,(double)nValue/COIN,(double)interest2/COIN,(double)nTotalValue/COIN); if (nSubtractFeeFromAmount == 0) nChange -= nFeeRet; diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index a47449fde..01285ca2b 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -584,7 +584,7 @@ public: class CWallet : public CCryptoKeyStore, public CValidationInterface { private: - bool SelectCoins(const CAmount& nTargetValue, std::set >& setCoinsRet, CAmount& nValueRet, bool& fOnlyCoinbaseCoinsRet, bool& fNeedCoinbaseCoinsRet, const CCoinControl *coinControl = NULL,uint64_t *interestp = NULL) const; + bool SelectCoins(const CAmount& nTargetValue, std::set >& setCoinsRet, CAmount& nValueRet, bool& fOnlyCoinbaseCoinsRet, bool& fNeedCoinbaseCoinsRet, const CCoinControl *coinControl = NULL) const; CWalletDB *pwalletdbEncryption; @@ -811,7 +811,7 @@ public: bool CanSupportFeature(enum WalletFeature wf) { AssertLockHeld(cs_wallet); return nWalletMaxVersion >= wf; } void AvailableCoins(std::vector& vCoins, bool fOnlyConfirmed=true, const CCoinControl *coinControl = NULL, bool fIncludeZeroValue=false, bool fIncludeCoinBase=true) const; - bool SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int nConfTheirs, std::vector vCoins, std::set >& setCoinsRet, CAmount& nValueRet,uint64_t *interestp) const; + bool SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int nConfTheirs, std::vector vCoins, std::set >& setCoinsRet, CAmount& nValueRet) const; bool IsSpent(const uint256& hash, unsigned int n) const; bool IsSpent(const uint256& nullifier) const; From f19ffc34cad85ea469a6436fc7e7327255dff25b Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 18 Oct 2017 22:43:08 +0300 Subject: [PATCH 022/188] Test --- src/wallet/wallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 595497b22..a2aa33661 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2663,7 +2663,7 @@ bool CWallet::CreateTransaction(const vector& vecSend, CWalletTx& wt nFeeRet = 0; while (true) { - interest = 0; + //interest = 0; txNew.vin.clear(); txNew.vout.clear(); wtxNew.fFromMe = true; From 01071eaabafd3dd7ad48c8fac70b60f790a56c5e Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 19 Oct 2017 23:29:42 +0300 Subject: [PATCH 023/188] Disable pax pow for now --- src/dpowassets | 66 +++++++++++++++++++++++++------------------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/src/dpowassets b/src/dpowassets index d4ba0a2bf..fde738e44 100755 --- a/src/dpowassets +++ b/src/dpowassets @@ -25,37 +25,37 @@ curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dp curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"MNZ\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"USD\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"EUR\",\"pubkey\":\"$pubkey\"}" - -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"JPY\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"GBP\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"AUD\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"CAD\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"CHF\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"NZD\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"CNY\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"RUB\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"MXN\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"BRL\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"INR\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"HKD\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"TRY\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"ZAR\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"PLN\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"NOK\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"SEK\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"DKK\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"CZK\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"HUF\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"ILS\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"KRW\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"MYR\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"PHP\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"RON\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"SGD\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"THB\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"BGN\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"IDR\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"HRK\",\"pubkey\":\"$pubkey\"}" +#curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"USD\",\"pubkey\":\"$pubkey\"}" +#curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"EUR\",\"pubkey\":\"$pubkey\"}" + # +#curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"JPY\",\"pubkey\":\"$pubkey\"}" +#curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"GBP\",\"pubkey\":\"$pubkey\"}" +#curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"AUD\",\"pubkey\":\"$pubkey\"}" +#curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"CAD\",\"pubkey\":\"$pubkey\"}" +#curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"CHF\",\"pubkey\":\"$pubkey\"}" +#curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"NZD\",\"pubkey\":\"$pubkey\"}" +#curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"CNY\",\"pubkey\":\"$pubkey\"}" +#curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"RUB\",\"pubkey\":\"$pubkey\"}" +#curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"MXN\",\"pubkey\":\"$pubkey\"}" +#curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"BRL\",\"pubkey\":\"$pubkey\"}" +#curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"INR\",\"pubkey\":\"$pubkey\"}" +#curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"HKD\",\"pubkey\":\"$pubkey\"}" +#curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"TRY\",\"pubkey\":\"$pubkey\"}" +#curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"ZAR\",\"pubkey\":\"$pubkey\"}" +#curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"PLN\",\"pubkey\":\"$pubkey\"}" +#curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"NOK\",\"pubkey\":\"$pubkey\"}" +#curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"SEK\",\"pubkey\":\"$pubkey\"}" +#curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"DKK\",\"pubkey\":\"$pubkey\"}" +#curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"CZK\",\"pubkey\":\"$pubkey\"}" +#curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"HUF\",\"pubkey\":\"$pubkey\"}" +#curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"ILS\",\"pubkey\":\"$pubkey\"}" +#curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"KRW\",\"pubkey\":\"$pubkey\"}" +#curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"MYR\",\"pubkey\":\"$pubkey\"}" +#curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"PHP\",\"pubkey\":\"$pubkey\"}" +#curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"RON\",\"pubkey\":\"$pubkey\"}" +#curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"SGD\",\"pubkey\":\"$pubkey\"}" +#curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"THB\",\"pubkey\":\"$pubkey\"}" +#curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"BGN\",\"pubkey\":\"$pubkey\"}" +#curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"IDR\",\"pubkey\":\"$pubkey\"}" +#curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"HRK\",\"pubkey\":\"$pubkey\"}" From a2d7c036e0c5590a86296c17a65e3a980d81f411 Mon Sep 17 00:00:00 2001 From: ca333 Date: Sun, 22 Oct 2017 04:08:53 +0200 Subject: [PATCH 024/188] darwin 333 --- depends/packages/boost.mk | 11 ++++++++++- depends/packages/libgmp.mk | 6 ++++++ depends/packages/libsnark.mk | 13 +++++++------ depends/packages/packages.mk | 2 +- src/crypto/equihash.cpp | 3 ++- src/gtest/test_transaction.cpp | 25 +++++++++++++++++++++++++ src/primitives/transaction.h | 3 +++ user-config.jam | 1 + 8 files changed, 55 insertions(+), 9 deletions(-) create mode 100644 user-config.jam diff --git a/depends/packages/boost.mk b/depends/packages/boost.mk index a2e820163..679faacde 100644 --- a/depends/packages/boost.mk +++ b/depends/packages/boost.mk @@ -19,6 +19,7 @@ $(package)_config_opts_i686_linux=address-model=32 architecture=x86 $(package)_toolset_$(host_os)=gcc $(package)_archiver_$(host_os)=$($(package)_ar) $(package)_toolset_darwin=gcc +$(package)_archiver_darwin=$($(package)_ar) $(package)_config_libraries=chrono,filesystem,program_options,system,thread,test $(package)_cxxflags=-fvisibility=hidden $(package)_cxxflags_linux=-fPIC @@ -34,10 +35,18 @@ define $(package)_config_cmds ./bootstrap.sh --without-icu --with-libraries=$(boost_config_libraries) endef +ifeq ($(host_os),linux) define $(package)_build_cmds ./b2 -d2 -j2 -d1 --prefix=$($(package)_staging_prefix_dir) $($(package)_config_opts) cxxflags=-std=c++11 stage endef - define $(package)_stage_cmds ./b2 -d0 -j4 --prefix=$($(package)_staging_prefix_dir) $($(package)_config_opts) cxxflags=-std=c++11 install endef +else +define $(package)_build_cmds + ./b2 -d2 -j2 -d1 --prefix=$($(package)_staging_prefix_dir) $($(package)_config_opts) stage +endef +define $(package)_stage_cmds + ./b2 -d0 -j4 --prefix=$($(package)_staging_prefix_dir) $($(package)_config_opts) install +endef +endif diff --git a/depends/packages/libgmp.mk b/depends/packages/libgmp.mk index 4a05377e2..f06e4a6c4 100644 --- a/depends/packages/libgmp.mk +++ b/depends/packages/libgmp.mk @@ -29,9 +29,15 @@ define $(package)_config_cmds $($(package)_autoconf) --host=$(host) --build=$(build) endef +ifeq ($(build_os),darwin) +define $(package)_build_cmds + $(MAKE) +endef +else define $(package)_build_cmds $(MAKE) CPPFLAGS='-fPIC' endef +endif define $(package)_stage_cmds $(MAKE) DESTDIR=$($(package)_staging_dir) install ; echo '=== staging find for $(package):' ; find $($(package)_staging_dir) diff --git a/depends/packages/libsnark.mk b/depends/packages/libsnark.mk index 62a171ac6..00c897d73 100644 --- a/depends/packages/libsnark.mk +++ b/depends/packages/libsnark.mk @@ -9,23 +9,24 @@ $(package)_git_commit=3854b20c25e8bc567aab2b558dec84d45f4a3e73 $(package)_dependencies=libgmp libsodium ifeq ($(build_os),darwin) +define $(package)_set_vars + $(package)_build_env=CC="$($(package)_cc)" CXX="$($(package)_cxx)" + $(package)_build_env+=CXXFLAGS="$($(package)_cxxflags) -DBINARY_OUTPUT -DSTATICLIB -DNO_PT_COMPRESSION=1 " +endef define $(package)_build_cmds -CC=gcc-5 CXX=g++-5 CXXFLAGS="-arch x86_64 -DBINARY_OUTPUT -DNO_PT_COMPRESSION=1" $(MAKE) lib DEPINST=$(host_prefix) CURVE=ALT_BN128 MULTICORE=0 NO_PROCPS=1 NO_GTEST=1 NO_DOCS=1 STATIC=1 NO_SUPERCOP=1 FEATUREFLAGS=-DMONTGOMERY_OUTPUT + $(MAKE) lib DEPINST=$(host_prefix) CURVE=ALT_BN128 MULTICORE=1 NO_PROCPS=1 NO_GTEST=1 NO_DOCS=1 STATIC=1 NO_SUPERCOP=1 FEATUREFLAGS=-DMONTGOMERY_OUTPUT OPTFLAGS="-O2 -march=x86-64" endef else ifeq ($(host_os),mingw32) define $(package)_build_cmds -CXX="x86_64-w64-mingw32-g++-posix" CXXFLAGS="-DBINARY_OUTPUT -DPTW32_STATIC_LIB -DSTATICLIB -DNO_PT_COMPRESSION=1 -fopenmp" $(MAKE) lib DEPINST=$(host_prefix) CURVE=ALT_BN128 MULTICORE=1 NO_PROCPS=1 NO_GTEST=1 NO_DOCS=1 STATIC=1 NO_SUPERCOP=1 FEATUREFLAGS=-DMONTGOMERY_OUTPUT OPTFLAGS="-O2 -march=x86-64" + CXX="x86_64-w64-mingw32-g++-posix" CXXFLAGS="-DBINARY_OUTPUT -DPTW32_STATIC_LIB -DSTATICLIB -DNO_PT_COMPRESSION=1 -fopenmp" $(MAKE) lib DEPINST=$(host_prefix) CURVE=ALT_BN128 MULTICORE=1 NO_PROCPS=1 NO_GTEST=1 NO_DOCS=1 STATIC=1 NO_SUPERCOP=1 FEATUREFLAGS=-DMONTGOMERY_OUTPUT OPTFLAGS="-O2 -march=x86-64" endef else define $(package)_build_cmds -CXXFLAGS="-fPIC -DBINARY_OUTPUT -DNO_PT_COMPRESSION=1" $(MAKE) lib DEPINST=$(host_prefix) CURVE=ALT_BN128 MULTICORE=1 NO_PROCPS=1 NO_GTEST=1 NO_DOCS=1 STATIC=1 NO_SUPERCOP=1 FEATUREFLAGS=-DMONTGOMERY_OUTPUT OPTFLAGS="-O2 -march=x86-64" + CXXFLAGS="-fPIC -DBINARY_OUTPUT -DNO_PT_COMPRESSION=1" $(MAKE) lib DEPINST=$(host_prefix) CURVE=ALT_BN128 MULTICORE=1 NO_PROCPS=1 NO_GTEST=1 NO_DOCS=1 STATIC=1 NO_SUPERCOP=1 FEATUREFLAGS=-DMONTGOMERY_OUTPUT OPTFLAGS="-O2 -march=x86-64" endef endif - - - define $(package)_stage_cmds $(MAKE) install STATIC=1 DEPINST=$(host_prefix) PREFIX=$($(package)_staging_dir)$(host_prefix) CURVE=ALT_BN128 NO_SUPERCOP=1 endef diff --git a/depends/packages/packages.mk b/depends/packages/packages.mk index 3cf52d62f..b1951431a 100644 --- a/depends/packages/packages.mk +++ b/depends/packages/packages.mk @@ -1,7 +1,7 @@ rust_packages := rust librustzcash zcash_packages := libsnark libgmp libsodium -ifeq ($(build_os),linux) +ifeq ($(host_os),linux) packages := boost openssl libevent zeromq $(zcash_packages) googletest googlemock else packages := boost openssl libevent zeromq $(zcash_packages) googletest googlemock libcurl diff --git a/src/crypto/equihash.cpp b/src/crypto/equihash.cpp index 7da805bc8..9e6d18590 100644 --- a/src/crypto/equihash.cpp +++ b/src/crypto/equihash.cpp @@ -28,6 +28,7 @@ #include +/* #ifdef __APPLE__ #include #include @@ -51,7 +52,7 @@ #define __LITTLE_ENDIAN LITTLE_ENDIAN #define __BYTE_ORDER BYTE_ORDER #endif - +*/ EhSolverCancelledException solver_cancelled; template diff --git a/src/gtest/test_transaction.cpp b/src/gtest/test_transaction.cpp index a339f7652..e75588685 100644 --- a/src/gtest/test_transaction.cpp +++ b/src/gtest/test_transaction.cpp @@ -38,8 +38,13 @@ TEST(Transaction, JSDescriptionRandomized) { libzcash::JSOutput(addr, 50), libzcash::JSOutput(addr, 50) }; + #ifdef __LP64__ // required for building on MacOS + boost::array inputMap; + boost::array outputMap; + #else boost::array inputMap; boost::array outputMap; + #endif { auto jsdesc = JSDescription::Randomized( @@ -48,12 +53,22 @@ TEST(Transaction, JSDescriptionRandomized) { inputMap, outputMap, 0, 0, false); + #ifdef __LP64__ // required for building on MacOS + std::set inputSet(inputMap.begin(), inputMap.end()); + std::set expectedInputSet {0, 1}; + #else std::set inputSet(inputMap.begin(), inputMap.end()); std::set expectedInputSet {0, 1}; + #endif EXPECT_EQ(expectedInputSet, inputSet); + #ifdef __LP64__ // required for building on MacOS + std::set outputSet(outputMap.begin(), outputMap.end()); + std::set expectedOutputSet {0, 1}; + #else std::set outputSet(outputMap.begin(), outputMap.end()); std::set expectedOutputSet {0, 1}; + #endif EXPECT_EQ(expectedOutputSet, outputSet); } @@ -64,8 +79,13 @@ TEST(Transaction, JSDescriptionRandomized) { inputMap, outputMap, 0, 0, false, GenZero); + #ifdef __LP64__ // required for building on MacOS + boost::array expectedInputMap {1, 0}; + boost::array expectedOutputMap {1, 0}; + #else boost::array expectedInputMap {1, 0}; boost::array expectedOutputMap {1, 0}; + #endif EXPECT_EQ(expectedInputMap, inputMap); EXPECT_EQ(expectedOutputMap, outputMap); } @@ -77,8 +97,13 @@ TEST(Transaction, JSDescriptionRandomized) { inputMap, outputMap, 0, 0, false, GenMax); + #ifdef __LP64__ // required for building on MacOS + boost::array expectedInputMap {0, 1}; + boost::array expectedOutputMap {0, 1}; + #else boost::array expectedInputMap {0, 1}; boost::array expectedOutputMap {0, 1}; + #endif EXPECT_EQ(expectedInputMap, inputMap); EXPECT_EQ(expectedOutputMap, outputMap); } diff --git a/src/primitives/transaction.h b/src/primitives/transaction.h index b42dfeda0..699b7a89f 100644 --- a/src/primitives/transaction.h +++ b/src/primitives/transaction.h @@ -12,7 +12,10 @@ #include "serialize.h" #include "uint256.h" #include "consensus/consensus.h" + +#ifndef __APPLE__ #include +#endif #include diff --git a/user-config.jam b/user-config.jam new file mode 100644 index 000000000..e473b46e7 --- /dev/null +++ b/user-config.jam @@ -0,0 +1 @@ +using : : : " " "" "" "" "" "" : ; From b5bde7e5919f27fa3c32e2b71a9ea43bec23475d Mon Sep 17 00:00:00 2001 From: ca333 Date: Mon, 23 Oct 2017 00:33:56 +0200 Subject: [PATCH 025/188] 333 --- zcutil/build-mac.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zcutil/build-mac.sh b/zcutil/build-mac.sh index e503d0974..d53f4052e 100755 --- a/zcutil/build-mac.sh +++ b/zcutil/build-mac.sh @@ -43,7 +43,7 @@ PREFIX="$(pwd)/depends/$TRIPLET" make "$@" -C ./depends/ V=1 NO_QT=1 ./autogen.sh -CPPFLAGS="-I$PREFIX/include -arch x86_64" LDFLAGS="-L$PREFIX/lib -arch x86_64 -Wl,-no_pie -fopenmp" \ +CPPFLAGS="-I$PREFIX/include -arch x86_64" LDFLAGS="-L$PREFIX/lib -arch x86_64 -Wl,-no_pie" \ CXXFLAGS='-arch x86_64 -I/usr/local/Cellar/gcc5/5.4.0/include/c++/5.4.0 -I$PREFIX/include -fwrapv -fno-strict-aliasing -Werror -g -Wl,-undefined -Wl,dynamic_lookup' \ ./configure --prefix="${PREFIX}" --with-gui=no "$HARDENING_ARG" "$LCOV_ARG" From ee5e8026aec4af0e6ed3acc43c239230a1d82685 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 23 Oct 2017 11:39:58 +0300 Subject: [PATCH 026/188] Allow asset chains notarization.11 --- src/komodo.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index 23ccb6338..2687e2add 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -545,7 +545,9 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) } else printf("cant get scriptPubKey for ht.%d txi.%d vin.%d\n",height,i,j); } numvalid = bitweight(signedmask); - if ( (((height < 90000 || (signedmask & 1) != 0) && numvalid >= KOMODO_MINRATIFY) || numvalid > (numnotaries/5)) ) + if ( (((height < 90000 || (signedmask & 1) != 0) && numvalid >= KOMODO_MINRATIFY) || + (numvalid >= KOMODO_MINRATIFY && ASSETCHAINS_SYMBOL[0] != 0) || + numvalid > (numnotaries/5)) ) { if ( height > 500000 ) printf("%s ht.%d txi.%d signedmask.%llx numvins.%d numvouts.%d <<<<<<<<<<< notarized\n",ASSETCHAINS_SYMBOL,height,i,(long long)signedmask,numvins,numvouts); From a0b9382cb9bccf94aec0a72658406d43ade9c885 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 23 Oct 2017 12:10:22 +0300 Subject: [PATCH 027/188] Test --- src/komodo.h | 4 ++-- src/komodo_bitcoind.h | 12 ++++++++---- src/komodo_notary.h | 32 +++++++++++++++++++++++++++----- src/komodo_structs.h | 2 +- 4 files changed, 38 insertions(+), 12 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 2687e2add..0395f3d65 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -549,8 +549,8 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) (numvalid >= KOMODO_MINRATIFY && ASSETCHAINS_SYMBOL[0] != 0) || numvalid > (numnotaries/5)) ) { - if ( height > 500000 ) - printf("%s ht.%d txi.%d signedmask.%llx numvins.%d numvouts.%d <<<<<<<<<<< notarized\n",ASSETCHAINS_SYMBOL,height,i,(long long)signedmask,numvins,numvouts); + if ( height > 500000 || ASSETCHAINS_SYMBOL[0] != 0 ) + printf("[%s] ht.%d txi.%d signedmask.%llx numvins.%d numvouts.%d <<<<<<<<<<< notarized\n",ASSETCHAINS_SYMBOL,height,i,(long long)signedmask,numvins,numvouts); notarized = 1; } if ( NOTARY_PUBKEY33[0] != 0 && ASSETCHAINS_SYMBOL[0] == 0 ) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 5be8da5e2..e040a4a09 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -427,15 +427,18 @@ int32_t komodo_verifynotarization(char *symbol,char *dest,int32_t height,int32_t sprintf(params,"[\"%s\", 1]",NOTARIZED_DESTTXID.ToString().c_str()); if ( strcmp(symbol,ASSETCHAINS_SYMBOL[0]==0?(char *)"KMD":ASSETCHAINS_SYMBOL) != 0 ) return(0); - //printf("[%s] src.%s dest.%s params.[%s] ht.%d notarized.%d\n",ASSETCHAINS_SYMBOL,symbol,dest,params,height,NOTARIZED_HEIGHT); + if ( ASSETCHAINS_SYMBOL[0] != 0 ) + printf("[%s] src.%s dest.%s params.[%s] ht.%d notarized.%d\n",ASSETCHAINS_SYMBOL,symbol,dest,params,height,NOTARIZED_HEIGHT); if ( strcmp(dest,"KMD") == 0 ) { if ( KMDUSERPASS[0] != 0 ) { if ( ASSETCHAINS_SYMBOL[0] != 0 ) + { jsonstr = komodo_issuemethod(KMDUSERPASS,(char *)"getrawtransaction",params,7771); - } - //else jsonstr = _dex_getrawtransaction(); +printf("got (%s)\n",jsonstr); + } + }//else jsonstr = _dex_getrawtransaction(); else return(0); // need universal way to issue DEX* API, since notaries mine most blocks, this ok } else if ( strcmp(dest,"BTC") == 0 ) @@ -460,7 +463,8 @@ int32_t komodo_verifynotarization(char *symbol,char *dest,int32_t height,int32_t if ( (txjson= jobj(json,(char *)"result")) != 0 && (vouts= jarray(&n,txjson,(char *)"vout")) > 0 ) { vout = jitem(vouts,n-1); - //printf("vout.(%s)\n",jprint(vout,0)); + if ( ASSETCHAINS_SYMBOL[0] != 0 ) + printf("vout.(%s)\n",jprint(vout,0)); if ( (skey= jobj(vout,(char *)"scriptPubKey")) != 0 ) { if ( (hexstr= jstr(skey,(char *)"hex")) != 0 ) diff --git a/src/komodo_notary.h b/src/komodo_notary.h index e47638c8e..28ea470c0 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -320,26 +320,48 @@ int32_t komodo_notarized_height(uint256 *hashp,uint256 *txidp) int32_t komodo_notarizeddata(int32_t nHeight,uint256 *notarized_hashp,uint256 *notarized_desttxidp) { - struct notarized_checkpoint *np = 0; int32_t i; char symbol[16],dest[16]; struct komodo_state *sp; + struct notarized_checkpoint *np = 0; int32_t i,flag = 0; char symbol[16],dest[16]; struct komodo_state *sp; if ( (sp= komodo_stateptr(symbol,dest)) != 0 ) { if ( sp->NUM_NPOINTS > 0 ) { - for (i=0; iNUM_NPOINTS; i++) + flag = 0; + if ( sp->last_NPOINTSi < sp->NUM_POINTS && sp->last_NPOINTSi > 0 ) { - if ( sp->NPOINTS[i].nHeight >= nHeight ) - break; - np = &sp->NPOINTS[i]; + np = &sp->NPOINTS[sp->last_NPOINTSi-1]; + for (i=sp->last_NPOINTSi; iNUM_NPOINTS; i++) + { + if ( sp->NPOINTS[i].nHeight >= nHeight ) + { + flag = 1; + break; + } + np = &sp->NPOINTS[i]; + sp->last_NPOINTSi = i; + } + } + if ( flag == 0 ) + { + np = 0; + for (i=0; iNUM_NPOINTS; i++) + { + if ( sp->NPOINTS[i].nHeight >= nHeight ) + break; + np = &sp->NPOINTS[i]; + sp->last_NPOINTSi = i; + } } } if ( np != 0 ) { + char str[65],str2[65]; printf("[%s] notarized_ht.%d %s -> %s\n",ASSETCHAINS_SYMBOL,np->notarized_height,bits256_str(str,np->notarized_hash),bits256_str(str2,np->notarized_desttxid)); *notarized_hashp = np->notarized_hash; *notarized_desttxidp = np->notarized_desttxid; return(np->notarized_height); } } memset(notarized_hashp,0,sizeof(*notarized_hashp)); + memset(notarized_desttxidp,0,sizeof(*notarized_desttxidp)); return(0); } diff --git a/src/komodo_structs.h b/src/komodo_structs.h index 510a7e488..8db0a6f43 100644 --- a/src/komodo_structs.h +++ b/src/komodo_structs.h @@ -84,7 +84,7 @@ struct komodo_state int32_t SAVEDHEIGHT,CURRENT_HEIGHT,NOTARIZED_HEIGHT; uint32_t SAVEDTIMESTAMP; uint64_t deposited,issued,withdrawn,approved,redeemed,shorted; - struct notarized_checkpoint *NPOINTS; int32_t NUM_NPOINTS; + struct notarized_checkpoint *NPOINTS; int32_t NUM_NPOINTS,last_NPOINTSi; struct komodo_event **Komodo_events; int32_t Komodo_numevents; uint32_t RTbufs[64][3]; uint64_t RTmask; }; From f480802b461b65b5de14bf39a6c9df2c37df5d43 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 23 Oct 2017 12:11:58 +0300 Subject: [PATCH 028/188] Test --- src/komodo_notary.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_notary.h b/src/komodo_notary.h index 28ea470c0..abb878921 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -354,7 +354,7 @@ int32_t komodo_notarizeddata(int32_t nHeight,uint256 *notarized_hashp,uint256 *n } if ( np != 0 ) { - char str[65],str2[65]; printf("[%s] notarized_ht.%d %s -> %s\n",ASSETCHAINS_SYMBOL,np->notarized_height,bits256_str(str,np->notarized_hash),bits256_str(str2,np->notarized_desttxid)); + char str[65],str2[65]; printf("[%s] notarized_ht.%d\n",ASSETCHAINS_SYMBOL,np->notarized_height); *notarized_hashp = np->notarized_hash; *notarized_desttxidp = np->notarized_desttxid; return(np->notarized_height); From 7df54c32755b17f73fd37ef4db584a47a3f9b411 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 23 Oct 2017 12:14:21 +0300 Subject: [PATCH 029/188] Test --- src/komodo_notary.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_notary.h b/src/komodo_notary.h index abb878921..80de01629 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -326,7 +326,7 @@ int32_t komodo_notarizeddata(int32_t nHeight,uint256 *notarized_hashp,uint256 *n if ( sp->NUM_NPOINTS > 0 ) { flag = 0; - if ( sp->last_NPOINTSi < sp->NUM_POINTS && sp->last_NPOINTSi > 0 ) + if ( sp->last_NPOINTSi < sp->NUM_NPOINTS && sp->last_NPOINTSi > 0 ) { np = &sp->NPOINTS[sp->last_NPOINTSi-1]; for (i=sp->last_NPOINTSi; iNUM_NPOINTS; i++) From a4f48f007952ce975ddb0a846b01f61f279d24e5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 23 Oct 2017 12:21:44 +0300 Subject: [PATCH 030/188] Test --- src/komodo.h | 2 +- src/komodo_events.h | 5 +++-- src/komodo_notary.h | 2 ++ 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 0395f3d65..83f7eb446 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -103,7 +103,7 @@ int32_t komodo_parsestatefile(struct komodo_state *sp,FILE *fp,char *symbol,char errs++; if ( fread(¬arized_desttxid,1,sizeof(notarized_desttxid),fp) != sizeof(notarized_desttxid) ) errs++; - if ( 0 && sp != 0 ) + if ( ASSETCHAINS_SYMBOL[0] != 0 && sp != 0 ) printf("%s load[%s.%d] NOTARIZED %d %s\n",ASSETCHAINS_SYMBOL,symbol,sp->NUM_NPOINTS,notarized_height,notarized_hash.ToString().c_str()); //if ( matched != 0 ) global independent states -> inside *sp komodo_eventadd_notarized(sp,symbol,ht,dest,notarized_hash,notarized_desttxid,notarized_height); diff --git a/src/komodo_events.h b/src/komodo_events.h index 0ee3aa1f3..886854fd6 100644 --- a/src/komodo_events.h +++ b/src/komodo_events.h @@ -41,12 +41,13 @@ void komodo_eventadd_notarized(struct komodo_state *sp,char *symbol,int32_t heig struct komodo_event_notarized N; if ( komodo_verifynotarization(symbol,dest,height,notarizedheight,notarized_hash,notarized_desttxid) != 0 ) { - if ( height > 50000 ) + if ( height > 50000 || ASSETCHAINS_SYMBOL[0] != 0 ) printf("[%s] error validating notarization ht.%d notarized_height.%d, if on a pruned %s node this can be ignored\n",ASSETCHAINS_SYMBOL,height,notarizedheight,dest); } else { - //fprintf(stderr,"validated %s ht.%d notarized %d\n",ASSETCHAINS_SYMBOL,height,notarizedheight); + if ( ASSETCHAINS_SYMBOL[0] != 0 ) + fprintf(stderr,"validated [%s] ht.%d notarized %d\n",ASSETCHAINS_SYMBOL,height,notarizedheight); memset(&N,0,sizeof(N)); N.blockhash = notarized_hash; N.desttxid = notarized_desttxid; diff --git a/src/komodo_notary.h b/src/komodo_notary.h index 80de01629..73100a7df 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -289,6 +289,8 @@ void komodo_notarized_update(struct komodo_state *sp,int32_t nHeight,int32_t not printf("komodo_notarized_update REJECT notarized_height %d > %d nHeight\n",notarized_height,nHeight); return; } + if ( ASSETCHAINS_SYMBOL[0] != 0 ) + printf("[%s] komodo_notarized_update nHeight.%d notarized_height.%d\n",ASSETCHAINS_SYMBOL,nHeight,notarized_height); portable_mutex_lock(&komodo_mutex); sp->NPOINTS = (struct notarized_checkpoint *)realloc(sp->NPOINTS,(sp->NUM_NPOINTS+1) * sizeof(*sp->NPOINTS)); np = &sp->NPOINTS[sp->NUM_NPOINTS++]; From fac8d1ff97e40860fc27b9f2ac9b57ed2e60407f Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 23 Oct 2017 12:36:34 +0300 Subject: [PATCH 031/188] Test --- src/komodo.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index 83f7eb446..d2d330f20 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -80,7 +80,8 @@ int32_t komodo_parsestatefile(struct komodo_state *sp,FILE *fp,char *symbol,char else matched = (strcmp(symbol,ASSETCHAINS_SYMBOL) == 0); if ( fread(&ht,1,sizeof(ht),fp) != sizeof(ht) ) errs++; - //printf("fpos.%ld func.(%d %c) ht.%d ",ftell(fp),func,func,ht); + if ( ASSETCHAINS_SYMBOL[0] != 0 ) + printf("matched.%d fpos.%ld func.(%d %c) ht.%d ",matched,ftell(fp),func,func,ht); if ( func == 'P' ) { if ( (num= fgetc(fp)) <= 64 ) @@ -204,6 +205,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar if ( (sp= komodo_stateptr(symbol,dest)) == 0 ) { KOMODO_INITDONE = (uint32_t)time(NULL); + printf("[%s] no komodo_stateptr\n",ASSETCHAINS_SYMBOL); return; } if ( fp == 0 ) From 5d3c01863135f2542ee653aa490b959abbe39b11 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 23 Oct 2017 12:40:34 +0300 Subject: [PATCH 032/188] Test --- src/komodo.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index d2d330f20..ae26eb9f5 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -80,8 +80,8 @@ int32_t komodo_parsestatefile(struct komodo_state *sp,FILE *fp,char *symbol,char else matched = (strcmp(symbol,ASSETCHAINS_SYMBOL) == 0); if ( fread(&ht,1,sizeof(ht),fp) != sizeof(ht) ) errs++; - if ( ASSETCHAINS_SYMBOL[0] != 0 ) - printf("matched.%d fpos.%ld func.(%d %c) ht.%d ",matched,ftell(fp),func,func,ht); + if ( ASSETCHAINS_SYMBOL[0] != 0 && func != 'T' ) + printf("matched.%d fpos.%ld func.(%d %c) ht.%d\n",matched,ftell(fp),func,func,ht); if ( func == 'P' ) { if ( (num= fgetc(fp)) <= 64 ) From 7c18529bef5545361edb1ec2616141b46e1597b1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 23 Oct 2017 12:52:15 +0300 Subject: [PATCH 033/188] Test --- src/komodo.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index ae26eb9f5..030775fa9 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -391,6 +391,8 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr opretlen = scriptbuf[len++]; opretlen += (scriptbuf[len++] << 8); } + if ( ASSETCHAINS_SYMBOL[0] != 0 ) + printf("notarized.%d notarizedht.%d sp.Nht %d sp.ht %d opretlen.%d (%c %d)\n",notarized,*notarizedheightp,sp->NOTARIZED_HEIGHT,sp->CURRENT_HEIGHT,opretlen,scriptbuf[len+32*2+4]); 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); @@ -403,7 +405,7 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr sp->NOTARIZED_DESTTXID = desttxid; komodo_stateupdate(height,0,0,0,zero,0,0,0,0,0,0,0,0,0,0); len += 4; - if ( 0 && ASSETCHAINS_SYMBOL[0] == 0 ) + if ( ASSETCHAINS_SYMBOL[0] != 0 ) printf("%s ht.%d NOTARIZED.%d %s.%s %sTXID.%s (%s) lens.(%d %d)\n",ASSETCHAINS_SYMBOL,height,*notarizedheightp,ASSETCHAINS_SYMBOL[0]==0?"KMD":ASSETCHAINS_SYMBOL,kmdtxid.ToString().c_str(),ASSETCHAINS_SYMBOL[0]==0?"BTC":"KMD",desttxid.ToString().c_str(),(char *)&scriptbuf[len],opretlen,len); if ( ASSETCHAINS_SYMBOL[0] == 0 ) { From 66134a2290bce9a32775e27c5a7223a295ad6878 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 23 Oct 2017 12:53:51 +0300 Subject: [PATCH 034/188] Test --- src/komodo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index 030775fa9..7bbcd6f6c 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -392,7 +392,7 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr opretlen += (scriptbuf[len++] << 8); } if ( ASSETCHAINS_SYMBOL[0] != 0 ) - printf("notarized.%d notarizedht.%d sp.Nht %d sp.ht %d opretlen.%d (%c %d)\n",notarized,*notarizedheightp,sp->NOTARIZED_HEIGHT,sp->CURRENT_HEIGHT,opretlen,scriptbuf[len+32*2+4]); + printf("notarized.%d notarizedht.%d sp.Nht %d sp.ht %d opretlen.%d (%c %d)\n",notarized,*notarizedheightp,sp->NOTARIZED_HEIGHT,sp->CURRENT_HEIGHT,opretlen,scriptbuf[len+32*2+4],scriptbuf[len+32*2+4]); 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); From 0b27cefac1aa475d0a5e5ff522f4c4ee9d09393a Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 23 Oct 2017 13:00:54 +0300 Subject: [PATCH 035/188] Test --- src/komodo.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 7bbcd6f6c..72bc026a0 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -392,7 +392,7 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr opretlen += (scriptbuf[len++] << 8); } if ( ASSETCHAINS_SYMBOL[0] != 0 ) - printf("notarized.%d notarizedht.%d sp.Nht %d sp.ht %d opretlen.%d (%c %d)\n",notarized,*notarizedheightp,sp->NOTARIZED_HEIGHT,sp->CURRENT_HEIGHT,opretlen,scriptbuf[len+32*2+4],scriptbuf[len+32*2+4]); + printf("[%s] notarized.%d notarizedht.%d sp.Nht %d sp.ht %d opretlen.%d (%c %c %c)\n",ASSETCHAINS_SYMBOL,notarized,*notarizedheightp,sp->NOTARIZED_HEIGHT,sp->CURRENT_HEIGHT,opretlen,scriptbuf[len+32*2+4],scriptbuf[len+32*2+4+1],scriptbuf[len+32*2+4+2]); 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); @@ -596,7 +596,8 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) } if ( NOTARY_PUBKEY33[0] != 0 && ASSETCHAINS_SYMBOL[0] == 0 ) printf(") "); - //printf("%s ht.%d txi.%d signedmask.%llx numvins.%d numvouts.%d notarized.%d special.%d isratification.%d\n",ASSETCHAINS_SYMBOL,height,i,(long long)signedmask,numvins,numvouts,notarized,specialtx,isratification); + if ( ASSETCHAINS_SYMBOL[0] == 0 ) + printf("[%s] ht.%d txi.%d signedmask.%llx numvins.%d numvouts.%d notarized.%d special.%d isratification.%d\n",ASSETCHAINS_SYMBOL,height,i,(long long)signedmask,numvins,numvouts,notarized,specialtx,isratification); if ( notarized != 0 && (notarizedheight != 0 || specialtx != 0) ) { if ( isratification != 0 ) From d0d61f8f47ecd887376f9d7fa63015abf047b876 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 23 Oct 2017 13:03:39 +0300 Subject: [PATCH 036/188] Test --- src/komodo.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 72bc026a0..f94a54b57 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -81,7 +81,7 @@ int32_t komodo_parsestatefile(struct komodo_state *sp,FILE *fp,char *symbol,char if ( fread(&ht,1,sizeof(ht),fp) != sizeof(ht) ) errs++; if ( ASSETCHAINS_SYMBOL[0] != 0 && func != 'T' ) - printf("matched.%d fpos.%ld func.(%d %c) ht.%d\n",matched,ftell(fp),func,func,ht); + printf("[%s] matched.%d fpos.%ld func.(%d %c) ht.%d\n",ASSETCHAINS_SYMBOL,matched,ftell(fp),func,func,ht); if ( func == 'P' ) { if ( (num= fgetc(fp)) <= 64 ) @@ -157,7 +157,7 @@ int32_t komodo_parsestatefile(struct komodo_state *sp,FILE *fp,char *symbol,char { if ( fread(opret,1,olen,fp) != olen ) errs++; - if ( 0 && matched != 0 ) + if ( ASSETCHAINS_SYMBOL[0] != 0 && matched != 0 ) { int32_t i; for (i=0; i Date: Mon, 23 Oct 2017 13:15:57 +0300 Subject: [PATCH 037/188] Test --- src/komodo_notary.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_notary.h b/src/komodo_notary.h index 73100a7df..d159c3d9f 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -170,7 +170,7 @@ int32_t komodo_ratify_threshold(int32_t height,uint64_t signedmask) 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 ( height >= 180000 ) + if ( height >= 180000 || ASSETCHAINS_SYMBOL[0] != 0 ) { n = (int32_t)(sizeof(Notaries_elected)/sizeof(*Notaries_elected)); for (i=0; i Date: Mon, 23 Oct 2017 13:21:14 +0300 Subject: [PATCH 038/188] 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 e040a4a09..d7a6e1d94 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -436,7 +436,7 @@ int32_t komodo_verifynotarization(char *symbol,char *dest,int32_t height,int32_t if ( ASSETCHAINS_SYMBOL[0] != 0 ) { jsonstr = komodo_issuemethod(KMDUSERPASS,(char *)"getrawtransaction",params,7771); -printf("got (%s)\n",jsonstr); +printf("userpass.(%s) got (%s)\n",KMDUSERPASS,jsonstr); } }//else jsonstr = _dex_getrawtransaction(); else return(0); // need universal way to issue DEX* API, since notaries mine most blocks, this ok From 36c733e967f4e336ebfe598dbe91f918ed01bd12 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 23 Oct 2017 13:27:15 +0300 Subject: [PATCH 039/188] Test --- src/komodo_bitcoind.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index d7a6e1d94..787e72ad7 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:7776",0,0,(char *)(cmdstr)) +//#define issue_curl(cmdstr) bitcoind_RPC(0,(char *)"curl",(char *)"http://127.0.0.1:7776",0,0,(char *)(cmdstr)) struct MemoryStruct { char *memory; size_t size; }; struct return_string { char *ptr; size_t len; }; @@ -196,7 +196,7 @@ try_again: databuf = (char *)malloc(256 + strlen(command) + strlen(params)); sprintf(databuf,"{\"id\":\"jl777\",\"method\":\"%s\",\"params\":%s%s%s}",command,bracket0,params,bracket1); - //printf("url.(%s) userpass.(%s) databuf.(%s)\n",url,userpass,databuf); + printf("url.(%s) userpass.(%s) databuf.(%s)\n",url,userpass,databuf); // } //else if ( specialcase != 0 ) fprintf(stderr,"databuf.(%s)\n",params); curl_easy_setopt(curl_handle,CURLOPT_POST,1L); @@ -339,7 +339,7 @@ char *komodo_issuemethod(char *userpass,char *method,char *params,uint16_t port) { sprintf(url,(char *)"http://127.0.0.1:%u",port); sprintf(postdata,"{\"method\":\"%s\",\"params\":%s}",method,params); - //printf("postdata.(%s) USERPASS.(%s)\n",postdata,KMDUSERPASS); + printf("[%s] (%s) postdata.(%s) params.(%s) USERPASS.(%s)\n",ASSETCHAINS_SYMBOL,url,postdata,params,KMDUSERPASS); retstr2 = bitcoind_RPC(&retstr,(char *)"debug",url,userpass,method,params); //retstr = curl_post(&cHandle,url,USERPASS,postdata,0,0,0,0); } From 05e307ec9e9b8efefc9f1815e7f50580b85bfa51 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 23 Oct 2017 13:40:00 +0300 Subject: [PATCH 040/188] Test --- src/komodo_bitcoind.h | 8 ++++---- src/komodo_globals.h | 2 +- src/komodo_utils.h | 23 +++++++++++++++-------- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 787e72ad7..a48abae69 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -196,7 +196,7 @@ try_again: databuf = (char *)malloc(256 + strlen(command) + strlen(params)); sprintf(databuf,"{\"id\":\"jl777\",\"method\":\"%s\",\"params\":%s%s%s}",command,bracket0,params,bracket1); - printf("url.(%s) userpass.(%s) databuf.(%s)\n",url,userpass,databuf); + //printf("url.(%s) userpass.(%s) databuf.(%s)\n",url,userpass,databuf); // } //else if ( specialcase != 0 ) fprintf(stderr,"databuf.(%s)\n",params); curl_easy_setopt(curl_handle,CURLOPT_POST,1L); @@ -339,7 +339,7 @@ char *komodo_issuemethod(char *userpass,char *method,char *params,uint16_t port) { sprintf(url,(char *)"http://127.0.0.1:%u",port); sprintf(postdata,"{\"method\":\"%s\",\"params\":%s}",method,params); - printf("[%s] (%s) postdata.(%s) params.(%s) USERPASS.(%s)\n",ASSETCHAINS_SYMBOL,url,postdata,params,KMDUSERPASS); + //printf("[%s] (%s) postdata.(%s) params.(%s) USERPASS.(%s)\n",ASSETCHAINS_SYMBOL,url,postdata,params,KMDUSERPASS); retstr2 = bitcoind_RPC(&retstr,(char *)"debug",url,userpass,method,params); //retstr = curl_post(&cHandle,url,USERPASS,postdata,0,0,0,0); } @@ -353,7 +353,7 @@ int32_t notarizedtxid_height(char *dest,char *txidstr,int32_t *kmdnotarized_heig *kmdnotarized_heightp = 0; if ( strcmp(dest,"KMD") == 0 ) { - port = 7771; + port = KMD_PORT; userpass = KMDUSERPASS; } else if ( strcmp(dest,"BTC") == 0 ) @@ -435,7 +435,7 @@ int32_t komodo_verifynotarization(char *symbol,char *dest,int32_t height,int32_t { if ( ASSETCHAINS_SYMBOL[0] != 0 ) { - jsonstr = komodo_issuemethod(KMDUSERPASS,(char *)"getrawtransaction",params,7771); + jsonstr = komodo_issuemethod(KMDUSERPASS,(char *)"getrawtransaction",params,KMD_PORT); printf("userpass.(%s) got (%s)\n",KMDUSERPASS,jsonstr); } }//else jsonstr = _dex_getrawtransaction(); diff --git a/src/komodo_globals.h b/src/komodo_globals.h index 6d8d6c325..2976deb8e 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -52,7 +52,7 @@ uint32_t ASSETCHAINS_MAGIC = 2387029918; uint64_t ASSETCHAINS_SUPPLY = 10; uint32_t KOMODO_INITDONE; -char KMDUSERPASS[4096],BTCUSERPASS[4096]; uint16_t BITCOIND_PORT = 7771; +char KMDUSERPASS[4096],BTCUSERPASS[4096]; uint16_t KMD_PORT = 7771,BITCOIND_PORT = 7771; uint64_t PENDING_KOMODO_TX; struct komodo_kv *KOMODO_KV; diff --git a/src/komodo_utils.h b/src/komodo_utils.h index cc935a363..d2fda32c9 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1261,9 +1261,9 @@ void iguana_initQ(queue_t *Q,char *name) free(item); } -void komodo_userpass(char *username,char *password,FILE *fp) +uint16_t komodo_userpass(char *username,char *password,FILE *fp) { - char *rpcuser,*rpcpassword,*str,line[8192]; + char *rpcuser,*rpcpassword,*str,line[8192]; uint16_t port = 0; rpcuser = rpcpassword = 0; username[0] = password[0] = 0; while ( fgets(line,sizeof(line),fp) != 0 ) @@ -1275,6 +1275,11 @@ void komodo_userpass(char *username,char *password,FILE *fp) rpcuser = parse_conf_line(str,(char *)"rpcuser"); else if ( (str= strstr(line,(char *)"rpcpassword")) != 0 ) rpcpassword = parse_conf_line(str,(char *)"rpcpassword"); + else if ( (str= strstr(line,(char *)"rpcport")) != 0 ) + { + port = atoi(parse_conf_line(str,(char *)"rpcport")); + printf("rpcport.%u in file\n",port); + } } if ( rpcuser != 0 && rpcpassword != 0 ) { @@ -1286,6 +1291,7 @@ void komodo_userpass(char *username,char *password,FILE *fp) free(rpcuser); if ( rpcpassword != 0 ) free(rpcpassword); + return(port); } void komodo_statefname(char *fname,char *symbol,char *str) @@ -1328,7 +1334,7 @@ void komodo_statefname(char *fname,char *symbol,char *str) void komodo_configfile(char *symbol,uint16_t port) { static char myusername[512],mypassword[8192]; - FILE *fp; uint8_t buf2[33]; char fname[512],buf[128],username[512],password[8192]; uint32_t crc,r,r2,i; + FILE *fp; uint16_t port; uint8_t buf2[33]; char fname[512],buf[128],username[512],password[8192]; uint32_t crc,r,r2,i; if ( symbol != 0 && port != 0 ) { r = (uint32_t)time(NULL); @@ -1386,16 +1392,17 @@ void komodo_configfile(char *symbol,uint16_t port) #endif if ( (fp= fopen(fname,"rb")) != 0 ) { - komodo_userpass(username,password,fp); + if ( (port= komodo_userpass(username,password,fp)) != 0 ) + KMD_PORT = port; sprintf(KMDUSERPASS,"%s:%s",username,password); fclose(fp); //printf("KOMODO.(%s) -> userpass.(%s)\n",fname,KMDUSERPASS); } else printf("couldnt open.(%s)\n",fname); } -int32_t komodo_userpass(char *userpass,char *symbol) +uint16_t komodo_userpass(char *userpass,char *symbol) { - FILE *fp; char fname[512],username[512],password[512],confname[16]; + FILE *fp; uint16_t port = 0; char fname[512],username[512],password[512],confname[16]; userpass[0] = 0; if ( strcmp("KMD",symbol) == 0 ) { @@ -1409,12 +1416,12 @@ int32_t komodo_userpass(char *userpass,char *symbol) komodo_statefname(fname,symbol,confname); if ( (fp= fopen(fname,"rb")) != 0 ) { - komodo_userpass(username,password,fp); + port = komodo_userpass(username,password,fp); sprintf(userpass,"%s:%s",username,password); fclose(fp); return((int32_t)strlen(userpass)); } - return(-1); + return(port); } uint32_t komodo_assetmagic(char *symbol,uint64_t supply) From 9850ab03d4004400fdf621348e9f01b0e44f89de Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 23 Oct 2017 13:42:02 +0300 Subject: [PATCH 041/188] Test --- src/komodo_utils.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index d2fda32c9..fc099c248 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1334,7 +1334,7 @@ void komodo_statefname(char *fname,char *symbol,char *str) void komodo_configfile(char *symbol,uint16_t port) { static char myusername[512],mypassword[8192]; - FILE *fp; uint16_t port; uint8_t buf2[33]; char fname[512],buf[128],username[512],password[8192]; uint32_t crc,r,r2,i; + FILE *fp; uint16_t kmdport; uint8_t buf2[33]; char fname[512],buf[128],username[512],password[8192]; uint32_t crc,r,r2,i; if ( symbol != 0 && port != 0 ) { r = (uint32_t)time(NULL); @@ -1392,8 +1392,8 @@ void komodo_configfile(char *symbol,uint16_t port) #endif if ( (fp= fopen(fname,"rb")) != 0 ) { - if ( (port= komodo_userpass(username,password,fp)) != 0 ) - KMD_PORT = port; + if ( (kmdport= komodo_userpass(username,password,fp)) != 0 ) + KMD_PORT = kmdport; sprintf(KMDUSERPASS,"%s:%s",username,password); fclose(fp); //printf("KOMODO.(%s) -> userpass.(%s)\n",fname,KMDUSERPASS); From 21abd4df815cab904da29ffaf2b3b550dd9ddc99 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 23 Oct 2017 13:45:05 +0300 Subject: [PATCH 042/188] Test --- src/komodo_bitcoind.h | 2 +- src/komodo_utils.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index a48abae69..390d84736 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -436,7 +436,7 @@ int32_t komodo_verifynotarization(char *symbol,char *dest,int32_t height,int32_t if ( ASSETCHAINS_SYMBOL[0] != 0 ) { jsonstr = komodo_issuemethod(KMDUSERPASS,(char *)"getrawtransaction",params,KMD_PORT); -printf("userpass.(%s) got (%s)\n",KMDUSERPASS,jsonstr); +//printf("userpass.(%s) got (%s)\n",KMDUSERPASS,jsonstr); } }//else jsonstr = _dex_getrawtransaction(); else return(0); // need universal way to issue DEX* API, since notaries mine most blocks, this ok diff --git a/src/komodo_utils.h b/src/komodo_utils.h index fc099c248..92577dae0 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1278,7 +1278,7 @@ uint16_t komodo_userpass(char *username,char *password,FILE *fp) else if ( (str= strstr(line,(char *)"rpcport")) != 0 ) { port = atoi(parse_conf_line(str,(char *)"rpcport")); - printf("rpcport.%u in file\n",port); + //printf("rpcport.%u in file\n",port); } } if ( rpcuser != 0 && rpcpassword != 0 ) From 34c68daaa911a6d5f177bc1a3b1a80a5debfcbe5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 23 Oct 2017 13:49:19 +0300 Subject: [PATCH 043/188] Test --- src/komodo.h | 6 +++--- src/komodo_bitcoind.h | 2 +- src/komodo_notary.h | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index f94a54b57..6d11e2773 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -80,7 +80,7 @@ int32_t komodo_parsestatefile(struct komodo_state *sp,FILE *fp,char *symbol,char else matched = (strcmp(symbol,ASSETCHAINS_SYMBOL) == 0); if ( fread(&ht,1,sizeof(ht),fp) != sizeof(ht) ) errs++; - if ( ASSETCHAINS_SYMBOL[0] != 0 && func != 'T' ) + if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 && func != 'T' ) printf("[%s] matched.%d fpos.%ld func.(%d %c) ht.%d\n",ASSETCHAINS_SYMBOL,matched,ftell(fp),func,func,ht); if ( func == 'P' ) { @@ -157,7 +157,7 @@ int32_t komodo_parsestatefile(struct komodo_state *sp,FILE *fp,char *symbol,char { if ( fread(opret,1,olen,fp) != olen ) errs++; - if ( ASSETCHAINS_SYMBOL[0] != 0 && matched != 0 ) + if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 && matched != 0 ) { int32_t i; for (i=0; iNOTARIZED_HEIGHT,sp->CURRENT_HEIGHT,opretlen,scriptbuf[len+32*2+4],scriptbuf[len+32*2+4+1],scriptbuf[len+32*2+4+2]); if ( j == 1 && opretlen >= 32*2+4 && strcmp(ASSETCHAINS_SYMBOL[0]==0?"KMD":ASSETCHAINS_SYMBOL,(char *)&scriptbuf[len+32*2+4]) == 0 ) { diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 390d84736..1db988f12 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -463,7 +463,7 @@ int32_t komodo_verifynotarization(char *symbol,char *dest,int32_t height,int32_t if ( (txjson= jobj(json,(char *)"result")) != 0 && (vouts= jarray(&n,txjson,(char *)"vout")) > 0 ) { vout = jitem(vouts,n-1); - if ( ASSETCHAINS_SYMBOL[0] != 0 ) + if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 ) printf("vout.(%s)\n",jprint(vout,0)); if ( (skey= jobj(vout,(char *)"scriptPubKey")) != 0 ) { diff --git a/src/komodo_notary.h b/src/komodo_notary.h index d159c3d9f..7795161ab 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -289,7 +289,7 @@ void komodo_notarized_update(struct komodo_state *sp,int32_t nHeight,int32_t not printf("komodo_notarized_update REJECT notarized_height %d > %d nHeight\n",notarized_height,nHeight); return; } - if ( ASSETCHAINS_SYMBOL[0] != 0 ) + if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 ) printf("[%s] komodo_notarized_update nHeight.%d notarized_height.%d\n",ASSETCHAINS_SYMBOL,nHeight,notarized_height); portable_mutex_lock(&komodo_mutex); sp->NPOINTS = (struct notarized_checkpoint *)realloc(sp->NPOINTS,(sp->NUM_NPOINTS+1) * sizeof(*sp->NPOINTS)); From 05c1e522c0672341171124476becbe582bab709c Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 23 Oct 2017 13:54:39 +0300 Subject: [PATCH 044/188] Test --- src/komodo.h | 4 ++-- src/komodo_bitcoind.h | 2 +- src/komodo_events.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 6d11e2773..2362ab142 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -406,7 +406,7 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr komodo_stateupdate(height,0,0,0,zero,0,0,0,0,0,0,0,0,0,0); len += 4; if ( ASSETCHAINS_SYMBOL[0] != 0 ) - printf("%s ht.%d NOTARIZED.%d %s.%s %sTXID.%s (%s) lens.(%d %d)\n",ASSETCHAINS_SYMBOL,height,*notarizedheightp,ASSETCHAINS_SYMBOL[0]==0?"KMD":ASSETCHAINS_SYMBOL,kmdtxid.ToString().c_str(),ASSETCHAINS_SYMBOL[0]==0?"BTC":"KMD",desttxid.ToString().c_str(),(char *)&scriptbuf[len],opretlen,len); + printf("[%s] ht.%d NOTARIZED.%d %s.%s %sTXID.%s (%s) lens.(%d %d)\n",ASSETCHAINS_SYMBOL,height,*notarizedheightp,ASSETCHAINS_SYMBOL[0]==0?"KMD":ASSETCHAINS_SYMBOL,kmdtxid.ToString().c_str(),ASSETCHAINS_SYMBOL[0]==0?"BTC":"KMD",desttxid.ToString().c_str(),(char *)&scriptbuf[len],opretlen,len); if ( ASSETCHAINS_SYMBOL[0] == 0 ) { if ( signedfp == 0 ) @@ -596,7 +596,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) } if ( NOTARY_PUBKEY33[0] != 0 && ASSETCHAINS_SYMBOL[0] == 0 ) printf(") "); - if ( ASSETCHAINS_SYMBOL[0] == 0 ) + if ( 0 && ASSETCHAINS_SYMBOL[0] == 0 ) printf("[%s] ht.%d txi.%d signedmask.%llx numvins.%d numvouts.%d notarized.%d special.%d isratification.%d\n",ASSETCHAINS_SYMBOL,height,i,(long long)signedmask,numvins,numvouts,notarized,specialtx,isratification); if ( notarized != 0 && (notarizedheight != 0 || specialtx != 0) ) { diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 1db988f12..e4d216741 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -427,7 +427,7 @@ int32_t komodo_verifynotarization(char *symbol,char *dest,int32_t height,int32_t sprintf(params,"[\"%s\", 1]",NOTARIZED_DESTTXID.ToString().c_str()); if ( strcmp(symbol,ASSETCHAINS_SYMBOL[0]==0?(char *)"KMD":ASSETCHAINS_SYMBOL) != 0 ) return(0); - if ( ASSETCHAINS_SYMBOL[0] != 0 ) + if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 ) printf("[%s] src.%s dest.%s params.[%s] ht.%d notarized.%d\n",ASSETCHAINS_SYMBOL,symbol,dest,params,height,NOTARIZED_HEIGHT); if ( strcmp(dest,"KMD") == 0 ) { diff --git a/src/komodo_events.h b/src/komodo_events.h index 886854fd6..753413e9f 100644 --- a/src/komodo_events.h +++ b/src/komodo_events.h @@ -46,7 +46,7 @@ void komodo_eventadd_notarized(struct komodo_state *sp,char *symbol,int32_t heig } else { - if ( ASSETCHAINS_SYMBOL[0] != 0 ) + if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 ) fprintf(stderr,"validated [%s] ht.%d notarized %d\n",ASSETCHAINS_SYMBOL,height,notarizedheight); memset(&N,0,sizeof(N)); N.blockhash = notarized_hash; From 514018d9ac37c314a3380ba7fcf3c5139d79fe60 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 23 Oct 2017 14:36:00 +0300 Subject: [PATCH 045/188] Test --- src/komodo.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index 2362ab142..77e67645f 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -105,7 +105,7 @@ int32_t komodo_parsestatefile(struct komodo_state *sp,FILE *fp,char *symbol,char if ( fread(¬arized_desttxid,1,sizeof(notarized_desttxid),fp) != sizeof(notarized_desttxid) ) errs++; if ( ASSETCHAINS_SYMBOL[0] != 0 && sp != 0 ) - printf("%s load[%s.%d] NOTARIZED %d %s\n",ASSETCHAINS_SYMBOL,symbol,sp->NUM_NPOINTS,notarized_height,notarized_hash.ToString().c_str()); + printf("%s load[%s.%d -> %s] NOTARIZED %d %s\n",ASSETCHAINS_SYMBOL,symbol,sp->NUM_NPOINTS,dest,notarized_height,notarized_hash.ToString().c_str()); //if ( matched != 0 ) global independent states -> inside *sp komodo_eventadd_notarized(sp,symbol,ht,dest,notarized_hash,notarized_desttxid,notarized_height); } @@ -208,6 +208,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar printf("[%s] no komodo_stateptr\n",ASSETCHAINS_SYMBOL); return; } + printf("[%s] (%s) -> (%s)\n",ASSETCHAINS_SYMBOL,symbol,dest); if ( fp == 0 ) { komodo_statefname(fname,ASSETCHAINS_SYMBOL,(char *)"komodostate"); From ca74f186938e8bdf70b4bf811e01506248a17e3c Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 23 Oct 2017 14:39:25 +0300 Subject: [PATCH 046/188] Test --- src/komodo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index 77e67645f..b8ab21a3f 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -208,7 +208,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar printf("[%s] no komodo_stateptr\n",ASSETCHAINS_SYMBOL); return; } - printf("[%s] (%s) -> (%s)\n",ASSETCHAINS_SYMBOL,symbol,dest); + //printf("[%s] (%s) -> (%s)\n",ASSETCHAINS_SYMBOL,symbol,dest); if ( fp == 0 ) { komodo_statefname(fname,ASSETCHAINS_SYMBOL,(char *)"komodostate"); From 5d1193043af785f16c9413391784f798ec35ca5d Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 23 Oct 2017 14:39:53 +0300 Subject: [PATCH 047/188] Test --- src/komodo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index b8ab21a3f..2eb0aa21f 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -104,7 +104,7 @@ int32_t komodo_parsestatefile(struct komodo_state *sp,FILE *fp,char *symbol,char errs++; if ( fread(¬arized_desttxid,1,sizeof(notarized_desttxid),fp) != sizeof(notarized_desttxid) ) errs++; - if ( ASSETCHAINS_SYMBOL[0] != 0 && sp != 0 ) + if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 && sp != 0 ) printf("%s load[%s.%d -> %s] NOTARIZED %d %s\n",ASSETCHAINS_SYMBOL,symbol,sp->NUM_NPOINTS,dest,notarized_height,notarized_hash.ToString().c_str()); //if ( matched != 0 ) global independent states -> inside *sp komodo_eventadd_notarized(sp,symbol,ht,dest,notarized_hash,notarized_desttxid,notarized_height); From 78b3ac8f87a666080da4aa95914455066d202a89 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 23 Oct 2017 14:58:43 +0300 Subject: [PATCH 048/188] Test --- src/komodo_notary.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_notary.h b/src/komodo_notary.h index 7795161ab..486b6c10e 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -356,7 +356,7 @@ int32_t komodo_notarizeddata(int32_t nHeight,uint256 *notarized_hashp,uint256 *n } if ( np != 0 ) { - char str[65],str2[65]; printf("[%s] notarized_ht.%d\n",ASSETCHAINS_SYMBOL,np->notarized_height); + //char str[65],str2[65]; printf("[%s] notarized_ht.%d\n",ASSETCHAINS_SYMBOL,np->notarized_height); *notarized_hashp = np->notarized_hash; *notarized_desttxidp = np->notarized_desttxid; return(np->notarized_height); From ebfe4120fb17c110179b4bd8aaf9c90120d3eff5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 23 Oct 2017 15:49:13 +0300 Subject: [PATCH 049/188] Speed up npoints --- src/komodo_notary.h | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/komodo_notary.h b/src/komodo_notary.h index 486b6c10e..575c9e91e 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -331,15 +331,18 @@ int32_t komodo_notarizeddata(int32_t nHeight,uint256 *notarized_hashp,uint256 *n if ( sp->last_NPOINTSi < sp->NUM_NPOINTS && sp->last_NPOINTSi > 0 ) { np = &sp->NPOINTS[sp->last_NPOINTSi-1]; - for (i=sp->last_NPOINTSi; iNUM_NPOINTS; i++) + if ( np->nHeight < nHeight ) { - if ( sp->NPOINTS[i].nHeight >= nHeight ) + for (i=sp->last_NPOINTSi; iNUM_NPOINTS; i++) { - flag = 1; - break; + if ( sp->NPOINTS[i].nHeight >= nHeight ) + { + flag = 1; + break; + } + np = &sp->NPOINTS[i]; + sp->last_NPOINTSi = i; } - np = &sp->NPOINTS[i]; - sp->last_NPOINTSi = i; } } if ( flag == 0 ) From db758ed3de989174672d75e47982c30265ebf054 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 23 Oct 2017 15:55:29 +0300 Subject: [PATCH 050/188] Test --- src/komodo_notary.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/komodo_notary.h b/src/komodo_notary.h index 575c9e91e..d7912a0c5 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -322,7 +322,7 @@ int32_t komodo_notarized_height(uint256 *hashp,uint256 *txidp) int32_t komodo_notarizeddata(int32_t nHeight,uint256 *notarized_hashp,uint256 *notarized_desttxidp) { - struct notarized_checkpoint *np = 0; int32_t i,flag = 0; char symbol[16],dest[16]; struct komodo_state *sp; + struct notarized_checkpoint *np = 0; int32_t i=0,flag = 0; char symbol[16],dest[16]; struct komodo_state *sp; if ( (sp= komodo_stateptr(symbol,dest)) != 0 ) { if ( sp->NUM_NPOINTS > 0 ) @@ -351,7 +351,10 @@ int32_t komodo_notarizeddata(int32_t nHeight,uint256 *notarized_hashp,uint256 *n for (i=0; iNUM_NPOINTS; i++) { if ( sp->NPOINTS[i].nHeight >= nHeight ) + { + printf("i.%d np->ht %d [%d].ht %d >= nHeight.%d\n",i,np->nHeight,i,sp->NPOINTS[i].nHeight,nHeight); break; + } np = &sp->NPOINTS[i]; sp->last_NPOINTSi = i; } @@ -360,6 +363,8 @@ int32_t komodo_notarizeddata(int32_t nHeight,uint256 *notarized_hashp,uint256 *n if ( np != 0 ) { //char str[65],str2[65]; printf("[%s] notarized_ht.%d\n",ASSETCHAINS_SYMBOL,np->notarized_height); + if ( np->nHeight >= nHeight || (i < sp->NUM_NPOINTS && np[1].nHeight < nHeight) ) + printf("flag.%d i.%d np->ht %d [1].ht %d >= nHeight.%d\n",flag,i,np->nHeight,np[1].nHeight,nHeight); *notarized_hashp = np->notarized_hash; *notarized_desttxidp = np->notarized_desttxid; return(np->notarized_height); From 435de47a217284691a784e4dd0e6fb456ec3fee6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 23 Oct 2017 15:56:39 +0300 Subject: [PATCH 051/188] Test --- src/komodo_notary.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/komodo_notary.h b/src/komodo_notary.h index d7912a0c5..5861003ea 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -337,6 +337,7 @@ int32_t komodo_notarizeddata(int32_t nHeight,uint256 *notarized_hashp,uint256 *n { if ( sp->NPOINTS[i].nHeight >= nHeight ) { + printf("flag.1 i.%d np->ht %d [%d].ht %d >= nHeight.%d, last.%d num.%d\n",i,np->nHeight,i,sp->NPOINTS[i].nHeight,nHeight,sp->last_NPOINTSi,sp->NUM_NPOINTS); flag = 1; break; } From b3e1e4e67a141409cd3e683e96d33d1b3c294f46 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 23 Oct 2017 16:20:00 +0300 Subject: [PATCH 052/188] Test --- src/komodo_notary.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_notary.h b/src/komodo_notary.h index 5861003ea..55bf0e0bd 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -337,7 +337,7 @@ int32_t komodo_notarizeddata(int32_t nHeight,uint256 *notarized_hashp,uint256 *n { if ( sp->NPOINTS[i].nHeight >= nHeight ) { - printf("flag.1 i.%d np->ht %d [%d].ht %d >= nHeight.%d, last.%d num.%d\n",i,np->nHeight,i,sp->NPOINTS[i].nHeight,nHeight,sp->last_NPOINTSi,sp->NUM_NPOINTS); + //printf("flag.1 i.%d np->ht %d [%d].ht %d >= nHeight.%d, last.%d num.%d\n",i,np->nHeight,i,sp->NPOINTS[i].nHeight,nHeight,sp->last_NPOINTSi,sp->NUM_NPOINTS); flag = 1; break; } From 20b13d813cc9b2e4a90ea2d4a99eca2370c4cbf3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 23 Oct 2017 16:22:13 +0300 Subject: [PATCH 053/188] Test --- src/komodo_notary.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_notary.h b/src/komodo_notary.h index 55bf0e0bd..8da2a1e9c 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -353,7 +353,7 @@ int32_t komodo_notarizeddata(int32_t nHeight,uint256 *notarized_hashp,uint256 *n { if ( sp->NPOINTS[i].nHeight >= nHeight ) { - printf("i.%d np->ht %d [%d].ht %d >= nHeight.%d\n",i,np->nHeight,i,sp->NPOINTS[i].nHeight,nHeight); + //printf("i.%d np->ht %d [%d].ht %d >= nHeight.%d\n",i,np->nHeight,i,sp->NPOINTS[i].nHeight,nHeight); break; } np = &sp->NPOINTS[i]; @@ -365,7 +365,7 @@ int32_t komodo_notarizeddata(int32_t nHeight,uint256 *notarized_hashp,uint256 *n { //char str[65],str2[65]; printf("[%s] notarized_ht.%d\n",ASSETCHAINS_SYMBOL,np->notarized_height); if ( np->nHeight >= nHeight || (i < sp->NUM_NPOINTS && np[1].nHeight < nHeight) ) - printf("flag.%d i.%d np->ht %d [1].ht %d >= nHeight.%d\n",flag,i,np->nHeight,np[1].nHeight,nHeight); + printf("warning: flag.%d i.%d np->ht %d [1].ht %d >= nHeight.%d\n",flag,i,np->nHeight,np[1].nHeight,nHeight); *notarized_hashp = np->notarized_hash; *notarized_desttxidp = np->notarized_desttxid; return(np->notarized_height); From 890374f4b0eb1c52a91ce690b83f849322381224 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 23 Oct 2017 16:44:59 +0300 Subject: [PATCH 054/188] 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 f5655e6f1..d1713e234 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -638,7 +638,11 @@ uint64_t komodo_paxprice(uint64_t *seedp,int32_t height,char *base,char *rel,uin if ( ASSETCHAINS_SYMBOL[0] == 0 && chainActive.Tip() != 0 && height > chainActive.Tip()->nHeight ) { if ( height < 100000000 ) - printf("komodo_paxprice height.%d vs tip.%d\n",height,chainActive.Tip()->nHeight); + { + static uint32_t counter; + if ( counter++ < 3 ) + printf("komodo_paxprice height.%d vs tip.%d\n",height,chainActive.Tip()->nHeight); + } return(0); } *seedp = komodo_seed(height); From d430a5e8ca4c43b2d4ca6ab2e30a4b97f991ae84 Mon Sep 17 00:00:00 2001 From: Scott Sadler Date: Sun, 22 Oct 2017 21:57:07 -0700 Subject: [PATCH 055/188] upgrade cJSON and move customizations to komodo_cJSON --- src/bitcoin-cli.cpp | 2 +- src/cJSON.c | 3577 +++++++++++++++++++++++++++++++------------ src/cJSON.h | 451 +++--- src/komodo.h | 2 +- src/komodo_cJSON.c | 559 +++++++ src/komodo_cJSON.h | 127 ++ src/komodo_jumblr.h | 18 +- src/komodo_notary.h | 2 + 8 files changed, 3516 insertions(+), 1222 deletions(-) mode change 100755 => 100644 src/cJSON.c mode change 100755 => 100644 src/cJSON.h create mode 100755 src/komodo_cJSON.c create mode 100755 src/komodo_cJSON.h diff --git a/src/bitcoin-cli.cpp b/src/bitcoin-cli.cpp index bb9aeb580..cac650a00 100644 --- a/src/bitcoin-cli.cpp +++ b/src/bitcoin-cli.cpp @@ -72,7 +72,7 @@ public: #include "komodo_globals.h" #include "komodo_utils.h" -#include "cJSON.c" +#include "komodo_cJSON.c" #include "komodo_notary.h" 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 KMDheight,uint32_t KMDtimestamp,uint64_t opretvalue,uint8_t *opretbuf,uint16_t opretlen,uint16_t vout) diff --git a/src/cJSON.c b/src/cJSON.c old mode 100755 new mode 100644 index 82b78a403..5b58f2ffc --- a/src/cJSON.c +++ b/src/cJSON.c @@ -1,1136 +1,2699 @@ - /* - Copyright (c) 2009 Dave Gamble - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. - */ + Copyright (c) 2009-2017 Dave Gamble and cJSON contributors + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. +*/ /* cJSON */ /* JSON parser in C. */ + +#ifdef __GNUC__ +#pragma GCC visibility push(default) +#endif + +#include +#include #include +#include +#include +#include +#include +#include + +#ifdef __GNUC__ +#pragma GCC visibility pop +#endif #include "cJSON.h" -#ifndef DBL_EPSILON -#define DBL_EPSILON 2.2204460492503131E-16 +/* define our own boolean type */ +#define true ((cJSON_bool)1) +#define false ((cJSON_bool)0) + +typedef struct { + const unsigned char *json; + size_t position; +} cJSON_error; +static cJSON_error global_error = { NULL, 0 }; + +CJSON_PUBLIC(const char *) cJSON_GetErrorPtr(void) +{ + return (const char*) (global_error.json + global_error.position); +} + +/* This is a safeguard to prevent copy-pasters from using incompatible C and header files */ +#if (CJSON_VERSION_MAJOR != 1) || (CJSON_VERSION_MINOR != 5) || (CJSON_VERSION_PATCH != 9) + #error cJSON.h and cJSON.c have different versions. Make sure that both have the same. #endif -static const char *ep; - -long stripquotes(char *str) +CJSON_PUBLIC(const char*) cJSON_Version(void) { - long len,offset; - if ( str == 0 ) - return(0); - len = strlen(str); - if ( str[0] == '"' && str[len-1] == '"' ) - str[len-1] = 0, offset = 1; - else offset = 0; - return(offset); + static char version[15]; + sprintf(version, "%i.%i.%i", CJSON_VERSION_MAJOR, CJSON_VERSION_MINOR, CJSON_VERSION_PATCH); + + return version; } -const char *cJSON_GetErrorPtr(void) {return ep;} - -static int32_t cJSON_strcasecmp(const char *s1,const char *s2) +/* Case insensitive string comparison, doesn't consider two NULL pointers equal though */ +static int case_insensitive_strcmp(const unsigned char *string1, const unsigned char *string2) { - if (!s1) return (s1==s2)?0:1;if (!s2) return 1; - for(; tolower((int32_t)(*s1)) == tolower((int32_t)(*s2)); ++s1, ++s2) if(*s1 == 0) return 0; - return tolower((int32_t)(*(const unsigned char *)s1)) - tolower((int32_t)(*(const unsigned char *)s2)); + if ((string1 == NULL) || (string2 == NULL)) + { + return 1; + } + + if (string1 == string2) + { + return 0; + } + + for(; tolower(*string1) == tolower(*string2); (void)string1++, string2++) + { + if (*string1 == '\0') + { + return 0; + } + } + + return tolower(*string1) - tolower(*string2); } -static void *(*cJSON_malloc)(size_t sz) = malloc; -static void (*cJSON_free)(void *ptr) = free; - -static char* cJSON_strdup(const char* str) +typedef struct internal_hooks { - size_t len; - char* copy; - - len = strlen(str) + 1; - if (!(copy = (char*)cJSON_malloc(len+1))) return 0; - memcpy(copy,str,len); + void *(*allocate)(size_t size); + void (*deallocate)(void *pointer); + void *(*reallocate)(void *pointer, size_t size); +} internal_hooks; + +static internal_hooks global_hooks = { malloc, free, realloc }; + +static unsigned char* cJSON_strdup(const unsigned char* string, const internal_hooks * const hooks) +{ + size_t length = 0; + unsigned char *copy = NULL; + + if (string == NULL) + { + return NULL; + } + + length = strlen((const char*)string) + sizeof(""); + if (!(copy = (unsigned char*)hooks->allocate(length))) + { + return NULL; + } + memcpy(copy, string, length); + return copy; } -void cJSON_InitHooks(cJSON_Hooks* hooks) +CJSON_PUBLIC(void) cJSON_InitHooks(cJSON_Hooks* hooks) { - if (!hooks) { /* Reset hooks */ - cJSON_malloc = malloc; - cJSON_free = free; + if (hooks == NULL) + { + /* Reset hooks */ + global_hooks.allocate = malloc; + global_hooks.deallocate = free; + global_hooks.reallocate = realloc; return; } - - cJSON_malloc = (hooks->malloc_fn)?hooks->malloc_fn:malloc; - cJSON_free = (hooks->free_fn)?hooks->free_fn:free; + + global_hooks.allocate = malloc; + if (hooks->malloc_fn != NULL) + { + global_hooks.allocate = hooks->malloc_fn; + } + + global_hooks.deallocate = free; + if (hooks->free_fn != NULL) + { + global_hooks.deallocate = hooks->free_fn; + } + + /* use realloc only if both free and malloc are used */ + global_hooks.reallocate = NULL; + if ((global_hooks.allocate == malloc) && (global_hooks.deallocate == free)) + { + global_hooks.reallocate = realloc; + } } /* Internal constructor. */ -static cJSON *cJSON_New_Item(void) +static cJSON *cJSON_New_Item(const internal_hooks * const hooks) { - cJSON* node = (cJSON*)cJSON_malloc(sizeof(cJSON)); - if (node) memset(node,0,sizeof(cJSON)); - return node; + cJSON* node = (cJSON*)hooks->allocate(sizeof(cJSON)); + if (node) + { + memset(node, '\0', sizeof(cJSON)); + } + + return node; } /* Delete a cJSON structure. */ -void cJSON_Delete(cJSON *c) +CJSON_PUBLIC(void) cJSON_Delete(cJSON *item) { - cJSON *next; - while (c) - { - next=c->next; - if (!(c->type&cJSON_IsReference) && c->child) cJSON_Delete(c->child); - if (!(c->type&cJSON_IsReference) && c->valuestring) cJSON_free(c->valuestring); - if (c->string) cJSON_free(c->string); - cJSON_free(c); - c=next; - } + cJSON *next = NULL; + while (item != NULL) + { + next = item->next; + if (!(item->type & cJSON_IsReference) && (item->child != NULL)) + { + cJSON_Delete(item->child); + } + if (!(item->type & cJSON_IsReference) && (item->valuestring != NULL)) + { + global_hooks.deallocate(item->valuestring); + } + if (!(item->type & cJSON_StringIsConst) && (item->string != NULL)) + { + global_hooks.deallocate(item->string); + } + global_hooks.deallocate(item); + item = next; + } } -/* Parse the input text to generate a number, and populate the result into item. */ -static const char *parse_number(cJSON *item,const char *num) +/* get the decimal point character of the current locale */ +static unsigned char get_decimal_point(void) { - double n=0,sign=1,scale=0;int32_t subscale=0,signsubscale=1; - - if (*num=='-') sign=-1,num++; /* Has sign? */ - if (*num=='0') num++; /* is zero */ - if (*num>='1' && *num<='9') do n=(n*10.0)+(*num++ -'0'); while (*num>='0' && *num<='9'); /* Number? */ - if (*num=='.' && num[1]>='0' && num[1]<='9') {num++; do n=(n*10.0)+(*num++ -'0'),scale--; while (*num>='0' && *num<='9');} /* Fractional part? */ - if (*num=='e' || *num=='E') /* Exponent? */ - { num++;if (*num=='+') num++; else if (*num=='-') signsubscale=-1,num++; /* With sign? */ - while (*num>='0' && *num<='9') subscale=(subscale*10)+(*num++ - '0'); /* Number? */ - } - - n=sign*n*pow(10.0,(scale+subscale*signsubscale)); /* number = +/- number.fraction * 10^+/- exponent */ - - item->valuedouble=n; - item->valueint=(int64_t)n; - item->type=cJSON_Number; - return num; + struct lconv *lconv = localeconv(); + return (unsigned char) lconv->decimal_point[0]; +} + +typedef struct +{ + const unsigned char *content; + size_t length; + size_t offset; + size_t depth; /* How deeply nested (in arrays/objects) is the input at the current offset. */ + internal_hooks hooks; +} parse_buffer; + +/* check if the given size is left to read in a given parse buffer (starting with 1) */ +#define can_read(buffer, size) ((buffer != NULL) && (((buffer)->offset + size) <= (buffer)->length)) +#define cannot_read(buffer, size) (!can_read(buffer, size)) +/* check if the buffer can be accessed at the given index (starting with 0) */ +#define can_access_at_index(buffer, index) ((buffer != NULL) && (((buffer)->offset + index) < (buffer)->length)) +#define cannot_access_at_index(buffer, index) (!can_access_at_index(buffer, index)) +/* get a pointer to the buffer at the position */ +#define buffer_at_offset(buffer) ((buffer)->content + (buffer)->offset) + +/* Parse the input text to generate a number, and populate the result into item. */ +static cJSON_bool parse_number(cJSON * const item, parse_buffer * const input_buffer) +{ + double number = 0; + unsigned char *after_end = NULL; + unsigned char number_c_string[64]; + unsigned char decimal_point = get_decimal_point(); + size_t i = 0; + + if ((input_buffer == NULL) || (input_buffer->content == NULL)) + { + return false; + } + + /* copy the number into a temporary buffer and replace '.' with the decimal point + * of the current locale (for strtod) + * This also takes care of '\0' not necessarily being available for marking the end of the input */ + for (i = 0; (i < (sizeof(number_c_string) - 1)) && can_access_at_index(input_buffer, i); i++) + { + switch (buffer_at_offset(input_buffer)[i]) + { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case '+': + case '-': + case 'e': + case 'E': + number_c_string[i] = buffer_at_offset(input_buffer)[i]; + break; + + case '.': + number_c_string[i] = decimal_point; + break; + + default: + goto loop_end; + } + } +loop_end: + number_c_string[i] = '\0'; + + number = strtod((const char*)number_c_string, (char**)&after_end); + if (number_c_string == after_end) + { + return false; /* parse_error */ + } + + item->valuedouble = number; + + /* use saturation in case of overflow */ + if (number >= INT_MAX) + { + item->valueint = INT_MAX; + } + else if (number <= INT_MIN) + { + item->valueint = INT_MIN; + } + else + { + item->valueint = (int)number; + } + + item->type = cJSON_Number; + + input_buffer->offset += (size_t)(after_end - number_c_string); + return true; +} + +/* don't ask me, but the original cJSON_SetNumberValue returns an integer or double */ +CJSON_PUBLIC(double) cJSON_SetNumberHelper(cJSON *object, double number) +{ + if (number >= INT_MAX) + { + object->valueint = INT_MAX; + } + else if (number <= INT_MIN) + { + object->valueint = INT_MIN; + } + else + { + object->valueint = (int)number; + } + + return object->valuedouble = number; +} + +typedef struct +{ + unsigned char *buffer; + size_t length; + size_t offset; + size_t depth; /* current nesting depth (for formatted printing) */ + cJSON_bool noalloc; + cJSON_bool format; /* is this print a formatted print */ + internal_hooks hooks; +} printbuffer; + +/* realloc printbuffer if necessary to have at least "needed" bytes more */ +static unsigned char* ensure(printbuffer * const p, size_t needed) +{ + unsigned char *newbuffer = NULL; + size_t newsize = 0; + + if ((p == NULL) || (p->buffer == NULL)) + { + return NULL; + } + + if ((p->length > 0) && (p->offset >= p->length)) + { + /* make sure that offset is valid */ + return NULL; + } + + if (needed > INT_MAX) + { + /* sizes bigger than INT_MAX are currently not supported */ + return NULL; + } + + needed += p->offset + 1; + if (needed <= p->length) + { + return p->buffer + p->offset; + } + + if (p->noalloc) { + return NULL; + } + + /* calculate new buffer size */ + if (needed > (INT_MAX / 2)) + { + /* overflow of int, use INT_MAX if possible */ + if (needed <= INT_MAX) + { + newsize = INT_MAX; + } + else + { + return NULL; + } + } + else + { + newsize = needed * 2; + } + + if (p->hooks.reallocate != NULL) + { + /* reallocate with realloc if available */ + newbuffer = (unsigned char*)p->hooks.reallocate(p->buffer, newsize); + if (newbuffer == NULL) + { + p->hooks.deallocate(p->buffer); + p->length = 0; + p->buffer = NULL; + + return NULL; + } + } + else + { + /* otherwise reallocate manually */ + newbuffer = (unsigned char*)p->hooks.allocate(newsize); + if (!newbuffer) + { + p->hooks.deallocate(p->buffer); + p->length = 0; + p->buffer = NULL; + + return NULL; + } + if (newbuffer) + { + memcpy(newbuffer, p->buffer, p->offset + 1); + } + p->hooks.deallocate(p->buffer); + } + p->length = newsize; + p->buffer = newbuffer; + + return newbuffer + p->offset; +} + +/* calculate the new length of the string in a printbuffer and update the offset */ +static void update_offset(printbuffer * const buffer) +{ + const unsigned char *buffer_pointer = NULL; + if ((buffer == NULL) || (buffer->buffer == NULL)) + { + return; + } + buffer_pointer = buffer->buffer + buffer->offset; + + buffer->offset += strlen((const char*)buffer_pointer); } /* Render the number nicely from the given item into a string. */ -static char *print_number(cJSON *item) +static cJSON_bool print_number(const cJSON * const item, printbuffer * const output_buffer) { - char *str; - double d = item->valuedouble; - if ( fabs(((double)item->valueint) - d) <= DBL_EPSILON && d >= (1. - DBL_EPSILON) && d < (1LL << 62) )//d <= INT_MAX && d >= INT_MIN ) - { - str = (char *)cJSON_malloc(24); /* 2^64+1 can be represented in 21 chars + sign. */ - if ( str != 0 ) - sprintf(str,"%lld",(long long)item->valueint); - } - else - { - str = (char *)cJSON_malloc(66); /* This is a nice tradeoff. */ - if ( str != 0 ) - { - if ( fabs(floor(d) - d) <= DBL_EPSILON && fabs(d) < 1.0e60 ) - sprintf(str,"%.0f",d); - //else if (fabs(d)<1.0e-6 || fabs(d)>1.0e9) sprintf(str,"%e",d); - else - sprintf(str,"%.8f",d); - } - } - return str; -} + unsigned char *output_pointer = NULL; + double d = item->valuedouble; + int length = 0; + size_t i = 0; + unsigned char number_buffer[26]; /* temporary buffer to print the number into */ + unsigned char decimal_point = get_decimal_point(); + double test; -static unsigned parse_hex4(const char *str) -{ - unsigned h=0; - if (*str>='0' && *str<='9') h+=(*str)-'0'; else if (*str>='A' && *str<='F') h+=10+(*str)-'A'; else if (*str>='a' && *str<='f') h+=10+(*str)-'a'; else return 0; - h=h<<4;str++; - if (*str>='0' && *str<='9') h+=(*str)-'0'; else if (*str>='A' && *str<='F') h+=10+(*str)-'A'; else if (*str>='a' && *str<='f') h+=10+(*str)-'a'; else return 0; - h=h<<4;str++; - if (*str>='0' && *str<='9') h+=(*str)-'0'; else if (*str>='A' && *str<='F') h+=10+(*str)-'A'; else if (*str>='a' && *str<='f') h+=10+(*str)-'a'; else return 0; - h=h<<4;str++; - if (*str>='0' && *str<='9') h+=(*str)-'0'; else if (*str>='A' && *str<='F') h+=10+(*str)-'A'; else if (*str>='a' && *str<='f') h+=10+(*str)-'a'; else return 0; - return h; -} + if (output_buffer == NULL) + { + return false; + } -/* Parse the input text into an unescaped cstring, and populate item. */ -static const unsigned char firstByteMark[7] = { 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC }; -static const char *parse_string(cJSON *item,const char *str) -{ - const char *ptr=str+1;char *ptr2;char *out;int32_t len=0;unsigned uc,uc2; - if (*str!='\"') {ep=str;return 0;} /* not a string! */ - - while (*ptr!='\"' && *ptr && ++len) if (*ptr++ == '\\') ptr++; // Skip escaped quotes - - out=(char*)cJSON_malloc(len+2); /* This is how long we need for the string, roughly. */ - if (!out) return 0; - - ptr=str+1;ptr2=out; - while (*ptr!='\"' && *ptr) - { - if (*ptr!='\\') + /* This checks for NaN and Infinity */ + if ((d * 0) != 0) + { + length = sprintf((char*)number_buffer, "null"); + } + else + { + /* Try 15 decimal places of precision to avoid nonsignificant nonzero digits */ + length = sprintf((char*)number_buffer, "%1.15g", d); + + /* Check whether the original double can be recovered */ + if ((sscanf((char*)number_buffer, "%lg", &test) != 1) || ((double)test != d)) { - if ( *ptr == '%' && is_hexstr((char *)&ptr[1],2) && isprint(_decode_hex((char *)&ptr[1])) != 0 ) - *ptr2++ = _decode_hex((char *)&ptr[1]), ptr += 3; - else *ptr2++ = *ptr++; + /* If not, print with 17 decimal places of precision */ + length = sprintf((char*)number_buffer, "%1.17g", d); } - else - { - ptr++; - switch (*ptr) - { - case 'b': *ptr2++='\b'; break; - case 'f': *ptr2++='\f'; break; - case 'n': *ptr2++='\n'; break; - case 'r': *ptr2++='\r'; break; - case 't': *ptr2++='\t'; break; - case 'u': // transcode utf16 to utf8 - uc=parse_hex4(ptr+1);ptr+=4; // get the unicode char - - if ((uc>=0xDC00 && uc<=0xDFFF) || uc==0) break; // check for invalid - - if (uc>=0xD800 && uc<=0xDBFF) // UTF16 surrogate pairs - { - if (ptr[1]!='\\' || ptr[2]!='u') break; // missing second-half of surrogate. - uc2=parse_hex4(ptr+3);ptr+=6; - if (uc2<0xDC00 || uc2>0xDFFF) break; // invalid second-half of surrogate - uc=0x10000 + (((uc&0x3FF)<<10) | (uc2&0x3FF)); - } - - len=4;if (uc<0x80) len=1;else if (uc<0x800) len=2;else if (uc<0x10000) len=3; ptr2+=len; - - switch (len) { - case 4: *--ptr2 =((uc | 0x80) & 0xBF); uc >>= 6; - case 3: *--ptr2 =((uc | 0x80) & 0xBF); uc >>= 6; - case 2: *--ptr2 =((uc | 0x80) & 0xBF); uc >>= 6; - case 1: *--ptr2 =(uc | firstByteMark[len]); - } - ptr2+=len; - break; - default: *ptr2++=*ptr; break; - } - ptr++; - } - } - *ptr2=0; - if (*ptr=='\"') ptr++; - item->valuestring=out; - item->type=cJSON_String; - return ptr; + } + + /* sprintf failed or buffer overrun occured */ + if ((length < 0) || (length > (int)(sizeof(number_buffer) - 1))) + { + return false; + } + + /* reserve appropriate space in the output */ + output_pointer = ensure(output_buffer, (size_t)length); + if (output_pointer == NULL) + { + return false; + } + + /* copy the printed number to the output and replace locale + * dependent decimal point with '.' */ + for (i = 0; i < ((size_t)length); i++) + { + if (number_buffer[i] == decimal_point) + { + output_pointer[i] = '.'; + continue; + } + + output_pointer[i] = number_buffer[i]; + } + output_pointer[i] = '\0'; + + output_buffer->offset += (size_t)length; + + return true; +} + +/* parse 4 digit hexadecimal number */ +static unsigned parse_hex4(const unsigned char * const input) +{ + unsigned int h = 0; + size_t i = 0; + + for (i = 0; i < 4; i++) + { + /* parse digit */ + if ((input[i] >= '0') && (input[i] <= '9')) + { + h += (unsigned int) input[i] - '0'; + } + else if ((input[i] >= 'A') && (input[i] <= 'F')) + { + h += (unsigned int) 10 + input[i] - 'A'; + } + else if ((input[i] >= 'a') && (input[i] <= 'f')) + { + h += (unsigned int) 10 + input[i] - 'a'; + } + else /* invalid */ + { + return 0; + } + + if (i < 3) + { + /* shift left to make place for the next nibble */ + h = h << 4; + } + } + + return h; +} + +/* converts a UTF-16 literal to UTF-8 + * A literal can be one or two sequences of the form \uXXXX */ +static unsigned char utf16_literal_to_utf8(const unsigned char * const input_pointer, const unsigned char * const input_end, unsigned char **output_pointer) +{ + long unsigned int codepoint = 0; + unsigned int first_code = 0; + const unsigned char *first_sequence = input_pointer; + unsigned char utf8_length = 0; + unsigned char utf8_position = 0; + unsigned char sequence_length = 0; + unsigned char first_byte_mark = 0; + + if ((input_end - first_sequence) < 6) + { + /* input ends unexpectedly */ + goto fail; + } + + /* get the first utf16 sequence */ + first_code = parse_hex4(first_sequence + 2); + + /* check that the code is valid */ + if (((first_code >= 0xDC00) && (first_code <= 0xDFFF))) + { + goto fail; + } + + /* UTF16 surrogate pair */ + if ((first_code >= 0xD800) && (first_code <= 0xDBFF)) + { + const unsigned char *second_sequence = first_sequence + 6; + unsigned int second_code = 0; + sequence_length = 12; /* \uXXXX\uXXXX */ + + if ((input_end - second_sequence) < 6) + { + /* input ends unexpectedly */ + goto fail; + } + + if ((second_sequence[0] != '\\') || (second_sequence[1] != 'u')) + { + /* missing second half of the surrogate pair */ + goto fail; + } + + /* get the second utf16 sequence */ + second_code = parse_hex4(second_sequence + 2); + /* check that the code is valid */ + if ((second_code < 0xDC00) || (second_code > 0xDFFF)) + { + /* invalid second half of the surrogate pair */ + goto fail; + } + + + /* calculate the unicode codepoint from the surrogate pair */ + codepoint = 0x10000 + (((first_code & 0x3FF) << 10) | (second_code & 0x3FF)); + } + else + { + sequence_length = 6; /* \uXXXX */ + codepoint = first_code; + } + + /* encode as UTF-8 + * takes at maximum 4 bytes to encode: + * 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx */ + if (codepoint < 0x80) + { + /* normal ascii, encoding 0xxxxxxx */ + utf8_length = 1; + } + else if (codepoint < 0x800) + { + /* two bytes, encoding 110xxxxx 10xxxxxx */ + utf8_length = 2; + first_byte_mark = 0xC0; /* 11000000 */ + } + else if (codepoint < 0x10000) + { + /* three bytes, encoding 1110xxxx 10xxxxxx 10xxxxxx */ + utf8_length = 3; + first_byte_mark = 0xE0; /* 11100000 */ + } + else if (codepoint <= 0x10FFFF) + { + /* four bytes, encoding 1110xxxx 10xxxxxx 10xxxxxx 10xxxxxx */ + utf8_length = 4; + first_byte_mark = 0xF0; /* 11110000 */ + } + else + { + /* invalid unicode codepoint */ + goto fail; + } + + /* encode as utf8 */ + for (utf8_position = (unsigned char)(utf8_length - 1); utf8_position > 0; utf8_position--) + { + /* 10xxxxxx */ + (*output_pointer)[utf8_position] = (unsigned char)((codepoint | 0x80) & 0xBF); + codepoint >>= 6; + } + /* encode first byte */ + if (utf8_length > 1) + { + (*output_pointer)[0] = (unsigned char)((codepoint | first_byte_mark) & 0xFF); + } + else + { + (*output_pointer)[0] = (unsigned char)(codepoint & 0x7F); + } + + *output_pointer += utf8_length; + + return sequence_length; + +fail: + return 0; +} + +/* Parse the input text into an unescaped cinput, and populate item. */ +static cJSON_bool parse_string(cJSON * const item, parse_buffer * const input_buffer) +{ + const unsigned char *input_pointer = buffer_at_offset(input_buffer) + 1; + const unsigned char *input_end = buffer_at_offset(input_buffer) + 1; + unsigned char *output_pointer = NULL; + unsigned char *output = NULL; + + /* not a string */ + if (buffer_at_offset(input_buffer)[0] != '\"') + { + goto fail; + } + + { + /* calculate approximate size of the output (overestimate) */ + size_t allocation_length = 0; + size_t skipped_bytes = 0; + while (((size_t)(input_end - input_buffer->content) < input_buffer->length) && (*input_end != '\"')) + { + /* is escape sequence */ + if (input_end[0] == '\\') + { + if ((size_t)(input_end + 1 - input_buffer->content) >= input_buffer->length) + { + /* prevent buffer overflow when last input character is a backslash */ + goto fail; + } + skipped_bytes++; + input_end++; + } + input_end++; + } + if (((size_t)(input_end - input_buffer->content) >= input_buffer->length) || (*input_end != '\"')) + { + goto fail; /* string ended unexpectedly */ + } + + /* This is at most how much we need for the output */ + allocation_length = (size_t) (input_end - buffer_at_offset(input_buffer)) - skipped_bytes; + output = (unsigned char*)input_buffer->hooks.allocate(allocation_length + sizeof("")); + if (output == NULL) + { + goto fail; /* allocation failure */ + } + } + + output_pointer = output; + /* loop through the string literal */ + while (input_pointer < input_end) + { + if (*input_pointer != '\\') + { + *output_pointer++ = *input_pointer++; + } + /* escape sequence */ + else + { + unsigned char sequence_length = 2; + if ((input_end - input_pointer) < 1) + { + goto fail; + } + + switch (input_pointer[1]) + { + case 'b': + *output_pointer++ = '\b'; + break; + case 'f': + *output_pointer++ = '\f'; + break; + case 'n': + *output_pointer++ = '\n'; + break; + case 'r': + *output_pointer++ = '\r'; + break; + case 't': + *output_pointer++ = '\t'; + break; + case '\"': + case '\\': + case '/': + *output_pointer++ = input_pointer[1]; + break; + + /* UTF-16 literal */ + case 'u': + sequence_length = utf16_literal_to_utf8(input_pointer, input_end, &output_pointer); + if (sequence_length == 0) + { + /* failed to convert UTF16-literal to UTF-8 */ + goto fail; + } + break; + + default: + goto fail; + } + input_pointer += sequence_length; + } + } + + /* zero terminate the output */ + *output_pointer = '\0'; + + item->type = cJSON_String; + item->valuestring = (char*)output; + + input_buffer->offset = (size_t) (input_end - input_buffer->content); + input_buffer->offset++; + + return true; + +fail: + if (output != NULL) + { + input_buffer->hooks.deallocate(output); + } + + if (input_pointer != NULL) + { + input_buffer->offset = (size_t)(input_pointer - input_buffer->content); + } + + return false; } /* Render the cstring provided to an escaped version that can be printed. */ -static char *print_string_ptr(const char *str) +static cJSON_bool print_string_ptr(const unsigned char * const input, printbuffer * const output_buffer) { - const char *ptr;char *ptr2,*out;int32_t len=0;unsigned char token; - - if (!str) return cJSON_strdup(""); - ptr=str;while ((token=*ptr) && ++len) {if (strchr("\"\\\b\f\n\r\t",token)) len++; else if (token<32) len+=5;ptr++;} - - out=(char*)cJSON_malloc(len+3+1); - if (!out) return 0; - - ptr2=out;ptr=str; - *ptr2++='\"'; - while (*ptr) - { - if ((unsigned char)*ptr>31 && *ptr!='\"' && *ptr!='\\') *ptr2++=*ptr++; - else - { - *ptr2++='\\'; - switch (token=*ptr++) - { - case '\\': *ptr2++='\\'; break; - case '\"': *ptr2++='\"'; break; - case '\b': *ptr2++='b'; break; - case '\f': *ptr2++='f'; break; - case '\n': *ptr2++='n'; break; - case '\r': *ptr2++='r'; break; - case '\t': *ptr2++='t'; break; - default: sprintf(ptr2,"u%04x",token);ptr2+=5; break; /* escape and print */ - } - } - } - *ptr2++='\"';*ptr2++=0; - return out; + const unsigned char *input_pointer = NULL; + unsigned char *output = NULL; + unsigned char *output_pointer = NULL; + size_t output_length = 0; + /* numbers of additional characters needed for escaping */ + size_t escape_characters = 0; + + if (output_buffer == NULL) + { + return false; + } + + /* empty string */ + if (input == NULL) + { + output = ensure(output_buffer, sizeof("\"\"")); + if (output == NULL) + { + return false; + } + strcpy((char*)output, "\"\""); + + return true; + } + + /* set "flag" to 1 if something needs to be escaped */ + for (input_pointer = input; *input_pointer; input_pointer++) + { + switch (*input_pointer) + { + case '\"': + case '\\': + case '\b': + case '\f': + case '\n': + case '\r': + case '\t': + /* one character escape sequence */ + escape_characters++; + break; + default: + if (*input_pointer < 32) + { + /* UTF-16 escape sequence uXXXX */ + escape_characters += 5; + } + break; + } + } + output_length = (size_t)(input_pointer - input) + escape_characters; + + output = ensure(output_buffer, output_length + sizeof("\"\"")); + if (output == NULL) + { + return false; + } + + /* no characters have to be escaped */ + if (escape_characters == 0) + { + output[0] = '\"'; + memcpy(output + 1, input, output_length); + output[output_length + 1] = '\"'; + output[output_length + 2] = '\0'; + + return true; + } + + output[0] = '\"'; + output_pointer = output + 1; + /* copy the string */ + for (input_pointer = input; *input_pointer != '\0'; (void)input_pointer++, output_pointer++) + { + if ((*input_pointer > 31) && (*input_pointer != '\"') && (*input_pointer != '\\')) + { + /* normal character, copy */ + *output_pointer = *input_pointer; + } + else + { + /* character needs to be escaped */ + *output_pointer++ = '\\'; + switch (*input_pointer) + { + case '\\': + *output_pointer = '\\'; + break; + case '\"': + *output_pointer = '\"'; + break; + case '\b': + *output_pointer = 'b'; + break; + case '\f': + *output_pointer = 'f'; + break; + case '\n': + *output_pointer = 'n'; + break; + case '\r': + *output_pointer = 'r'; + break; + case '\t': + *output_pointer = 't'; + break; + default: + /* escape and print as unicode codepoint */ + sprintf((char*)output_pointer, "u%04x", *input_pointer); + output_pointer += 4; + break; + } + } + } + output[output_length + 1] = '\"'; + output[output_length + 2] = '\0'; + + return true; +} + +/* Invoke print_string_ptr (which is useful) on an item. */ +static cJSON_bool print_string(const cJSON * const item, printbuffer * const p) +{ + return print_string_ptr((unsigned char*)item->valuestring, p); } -/* Invote print_string_ptr (which is useful) on an item. */ -static char *print_string(cJSON *item) {return print_string_ptr(item->valuestring);} /* Predeclare these prototypes. */ -static const char *parse_value(cJSON *item,const char *value); -static char *print_value(cJSON *item,int32_t depth,int32_t fmt); -static const char *parse_array(cJSON *item,const char *value); -static char *print_array(cJSON *item,int32_t depth,int32_t fmt); -static const char *parse_object(cJSON *item,const char *value); -static char *print_object(cJSON *item,int32_t depth,int32_t fmt); +static cJSON_bool parse_value(cJSON * const item, parse_buffer * const input_buffer); +static cJSON_bool print_value(const cJSON * const item, printbuffer * const output_buffer); +static cJSON_bool parse_array(cJSON * const item, parse_buffer * const input_buffer); +static cJSON_bool print_array(const cJSON * const item, printbuffer * const output_buffer); +static cJSON_bool parse_object(cJSON * const item, parse_buffer * const input_buffer); +static cJSON_bool print_object(const cJSON * const item, printbuffer * const output_buffer); /* Utility to jump whitespace and cr/lf */ -static const char *skip(const char *in) {while (in && *in && (unsigned char)*in<=32) in++; return in;} +static parse_buffer *buffer_skip_whitespace(parse_buffer * const buffer) +{ + if ((buffer == NULL) || (buffer->content == NULL)) + { + return NULL; + } + + while (can_access_at_index(buffer, 0) && (buffer_at_offset(buffer)[0] <= 32)) + { + buffer->offset++; + } + + if (buffer->offset == buffer->length) + { + buffer->offset--; + } + + return buffer; +} /* Parse an object - create a new root, and populate. */ -cJSON *cJSON_ParseWithOpts(const char *value,const char **return_parse_end,int32_t require_null_terminated) +CJSON_PUBLIC(cJSON *) cJSON_ParseWithOpts(const char *value, const char **return_parse_end, cJSON_bool require_null_terminated) { - const char *end=0; - cJSON *c=cJSON_New_Item(); - ep=0; - if (!c) return 0; /* memory fail */ - - end=parse_value(c,skip(value)); - if (!end) {cJSON_Delete(c);return 0;} /* parse failure. ep is set. */ - - /* if we require null-terminated JSON without appended garbage, skip and then check for a null terminator */ - if (require_null_terminated) {end=skip(end);if (*end) {cJSON_Delete(c);ep=end;return 0;}} - if (return_parse_end) *return_parse_end=end; - return c; + parse_buffer buffer = { 0, 0, 0, 0, { 0, 0, 0 } }; + cJSON *item = NULL; + + /* reset error position */ + global_error.json = NULL; + global_error.position = 0; + + if (value == NULL) + { + goto fail; + } + + buffer.content = (const unsigned char*)value; + buffer.length = strlen((const char*)value) + sizeof(""); + buffer.offset = 0; + buffer.hooks = global_hooks; + + item = cJSON_New_Item(&global_hooks); + if (item == NULL) /* memory fail */ + { + goto fail; + } + + if (!parse_value(item, buffer_skip_whitespace(&buffer))) + { + /* parse failure. ep is set. */ + goto fail; + } + + /* if we require null-terminated JSON without appended garbage, skip and then check for a null terminator */ + if (require_null_terminated) + { + buffer_skip_whitespace(&buffer); + if ((buffer.offset >= buffer.length) || buffer_at_offset(&buffer)[0] != '\0') + { + goto fail; + } + } + if (return_parse_end) + { + *return_parse_end = (const char*)buffer_at_offset(&buffer); + } + + return item; + +fail: + if (item != NULL) + { + cJSON_Delete(item); + } + + if (value != NULL) + { + cJSON_error local_error; + local_error.json = (const unsigned char*)value; + local_error.position = 0; + + if (buffer.offset < buffer.length) + { + local_error.position = buffer.offset; + } + else if (buffer.length > 0) + { + local_error.position = buffer.length - 1; + } + + if (return_parse_end != NULL) + { + *return_parse_end = (const char*)local_error.json + local_error.position; + } + + global_error = local_error; + } + + return NULL; } + /* Default options for cJSON_Parse */ -cJSON *cJSON_Parse(const char *value) +CJSON_PUBLIC(cJSON *) cJSON_Parse(const char *value) { - return(cJSON_ParseWithOpts(value,0,0)); + return cJSON_ParseWithOpts(value, 0, 0); +} + +#define cjson_min(a, b) ((a < b) ? a : b) + +static unsigned char *print(const cJSON * const item, cJSON_bool format, const internal_hooks * const hooks) +{ + printbuffer buffer[1]; + unsigned char *printed = NULL; + + memset(buffer, 0, sizeof(buffer)); + + /* create buffer */ + buffer->buffer = (unsigned char*) hooks->allocate(256); + buffer->format = format; + buffer->hooks = *hooks; + if (buffer->buffer == NULL) + { + goto fail; + } + + /* print the value */ + if (!print_value(item, buffer)) + { + goto fail; + } + update_offset(buffer); + + /* check if reallocate is available */ + if (hooks->reallocate != NULL) + { + printed = (unsigned char*) hooks->reallocate(buffer->buffer, buffer->length); + buffer->buffer = NULL; + if (printed == NULL) { + goto fail; + } + } + else /* otherwise copy the JSON over to a new buffer */ + { + printed = (unsigned char*) hooks->allocate(buffer->offset + 1); + if (printed == NULL) + { + goto fail; + } + memcpy(printed, buffer->buffer, cjson_min(buffer->length, buffer->offset + 1)); + printed[buffer->offset] = '\0'; /* just to be sure */ + + /* free the buffer */ + hooks->deallocate(buffer->buffer); + } + + return printed; + +fail: + if (buffer->buffer != NULL) + { + hooks->deallocate(buffer->buffer); + } + + if (printed != NULL) + { + hooks->deallocate(printed); + } + + return NULL; } /* Render a cJSON item/entity/structure to text. */ -char *cJSON_Print(cJSON *item) +CJSON_PUBLIC(char *) cJSON_Print(const cJSON *item) { - return(print_value(item,0,1)); + return (char*)print(item, true, &global_hooks); +} + +CJSON_PUBLIC(char *) cJSON_PrintUnformatted(const cJSON *item) +{ + return (char*)print(item, false, &global_hooks); +} + +CJSON_PUBLIC(char *) cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON_bool fmt) +{ + printbuffer p = { 0, 0, 0, 0, 0, 0, { 0, 0, 0 } }; + + if (prebuffer < 0) + { + return NULL; + } + + p.buffer = (unsigned char*)global_hooks.allocate((size_t)prebuffer); + if (!p.buffer) + { + return NULL; + } + + p.length = (size_t)prebuffer; + p.offset = 0; + p.noalloc = false; + p.format = fmt; + p.hooks = global_hooks; + + if (!print_value(item, &p)) + { + global_hooks.deallocate(p.buffer); + return NULL; + } + + return (char*)p.buffer; +} + +CJSON_PUBLIC(cJSON_bool) cJSON_PrintPreallocated(cJSON *item, char *buf, const int len, const cJSON_bool fmt) +{ + printbuffer p = { 0, 0, 0, 0, 0, 0, { 0, 0, 0 } }; + + if ((len < 0) || (buf == NULL)) + { + return false; + } + + p.buffer = (unsigned char*)buf; + p.length = (size_t)len; + p.offset = 0; + p.noalloc = true; + p.format = fmt; + p.hooks = global_hooks; + + return print_value(item, &p); } -char *cJSON_PrintUnformatted(cJSON *item) {return print_value(item,0,0);} /* Parser core - when encountering text, process appropriately. */ -static const char *parse_value(cJSON *item,const char *value) +static cJSON_bool parse_value(cJSON * const item, parse_buffer * const input_buffer) { - if (!value) return 0; /* Fail on null. */ - if (!strncmp(value,"null",4)) { item->type=cJSON_NULL; return value+4; } - if (!strncmp(value,"false",5)) { item->type=cJSON_False; return value+5; } - if (!strncmp(value,"true",4)) { item->type=cJSON_True; item->valueint=1; return value+4; } - if (*value=='\"') { return parse_string(item,value); } - if (*value=='-' || (*value>='0' && *value<='9')) { return parse_number(item,value); } - if (*value=='[') { return parse_array(item,value); } - if (*value=='{') { return parse_object(item,value); } - - ep=value;return 0; /* failure. */ + if ((input_buffer == NULL) || (input_buffer->content == NULL)) + { + return false; /* no input */ + } + + /* parse the different types of values */ + /* null */ + if (can_read(input_buffer, 4) && (strncmp((const char*)buffer_at_offset(input_buffer), "null", 4) == 0)) + { + item->type = cJSON_NULL; + input_buffer->offset += 4; + return true; + } + /* false */ + if (can_read(input_buffer, 5) && (strncmp((const char*)buffer_at_offset(input_buffer), "false", 5) == 0)) + { + item->type = cJSON_False; + input_buffer->offset += 5; + return true; + } + /* true */ + if (can_read(input_buffer, 4) && (strncmp((const char*)buffer_at_offset(input_buffer), "true", 4) == 0)) + { + item->type = cJSON_True; + item->valueint = 1; + input_buffer->offset += 4; + return true; + } + /* string */ + if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == '\"')) + { + return parse_string(item, input_buffer); + } + /* number */ + if (can_access_at_index(input_buffer, 0) && ((buffer_at_offset(input_buffer)[0] == '-') || ((buffer_at_offset(input_buffer)[0] >= '0') && (buffer_at_offset(input_buffer)[0] <= '9')))) + { + return parse_number(item, input_buffer); + } + /* array */ + if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == '[')) + { + return parse_array(item, input_buffer); + } + /* object */ + if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == '{')) + { + return parse_object(item, input_buffer); + } + + + return false; } /* Render a value to text. */ -static char *print_value(cJSON *item,int32_t depth,int32_t fmt) +static cJSON_bool print_value(const cJSON * const item, printbuffer * const output_buffer) { - char *out=0; - if (!item) return 0; - switch ((item->type)&255) - { - case cJSON_NULL: out=cJSON_strdup("null"); break; - case cJSON_False: out=cJSON_strdup("false");break; - case cJSON_True: out=cJSON_strdup("true"); break; - case cJSON_Number: out=print_number(item);break; - case cJSON_String: out=print_string(item);break; - case cJSON_Array: out=print_array(item,depth,fmt);break; - case cJSON_Object: out=print_object(item,depth,fmt);break; - } - return out; + unsigned char *output = NULL; + + if ((item == NULL) || (output_buffer == NULL)) + { + return false; + } + + switch ((item->type) & 0xFF) + { + case cJSON_NULL: + output = ensure(output_buffer, 5); + if (output == NULL) + { + return false; + } + strcpy((char*)output, "null"); + return true; + + case cJSON_False: + output = ensure(output_buffer, 6); + if (output == NULL) + { + return false; + } + strcpy((char*)output, "false"); + return true; + + case cJSON_True: + output = ensure(output_buffer, 5); + if (output == NULL) + { + return false; + } + strcpy((char*)output, "true"); + return true; + + case cJSON_Number: + return print_number(item, output_buffer); + + case cJSON_Raw: + { + size_t raw_length = 0; + if (item->valuestring == NULL) + { + if (!output_buffer->noalloc) + { + output_buffer->hooks.deallocate(output_buffer->buffer); + } + return false; + } + + raw_length = strlen(item->valuestring) + sizeof(""); + output = ensure(output_buffer, raw_length); + if (output == NULL) + { + return false; + } + memcpy(output, item->valuestring, raw_length); + return true; + } + + case cJSON_String: + return print_string(item, output_buffer); + + case cJSON_Array: + return print_array(item, output_buffer); + + case cJSON_Object: + return print_object(item, output_buffer); + + default: + return false; + } } /* Build an array from input text. */ -static const char *parse_array(cJSON *item,const char *value) +static cJSON_bool parse_array(cJSON * const item, parse_buffer * const input_buffer) { - cJSON *child; - if (*value!='[') {ep=value;return 0;} /* not an array! */ - - item->type=cJSON_Array; - value=skip(value+1); - if (*value==']') return value+1; /* empty array. */ - - item->child=child=cJSON_New_Item(); - if (!item->child) return 0; /* memory fail */ - value=skip(parse_value(child,skip(value))); /* skip any spacing, get the value. */ - if (!value) return 0; - - while (*value==',') - { - cJSON *new_item; - if (!(new_item=cJSON_New_Item())) return 0; /* memory fail */ - child->next=new_item;new_item->prev=child;child=new_item; - value=skip(parse_value(child,skip(value+1))); - if (!value) return 0; /* memory fail */ - } - - if (*value==']') return value+1; /* end of array */ - ep=value;return 0; /* malformed. */ + cJSON *head = NULL; /* head of the linked list */ + cJSON *current_item = NULL; + + if (input_buffer->depth >= CJSON_NESTING_LIMIT) + { + return false; /* to deeply nested */ + } + input_buffer->depth++; + + if (buffer_at_offset(input_buffer)[0] != '[') + { + /* not an array */ + goto fail; + } + + input_buffer->offset++; + buffer_skip_whitespace(input_buffer); + if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == ']')) + { + /* empty array */ + goto success; + } + + /* check if we skipped to the end of the buffer */ + if (cannot_access_at_index(input_buffer, 0)) + { + input_buffer->offset--; + goto fail; + } + + /* step back to character in front of the first element */ + input_buffer->offset--; + /* loop through the comma separated array elements */ + do + { + /* allocate next item */ + cJSON *new_item = cJSON_New_Item(&(input_buffer->hooks)); + if (new_item == NULL) + { + goto fail; /* allocation failure */ + } + + /* attach next item to list */ + if (head == NULL) + { + /* start the linked list */ + current_item = head = new_item; + } + else + { + /* add to the end and advance */ + current_item->next = new_item; + new_item->prev = current_item; + current_item = new_item; + } + + /* parse next value */ + input_buffer->offset++; + buffer_skip_whitespace(input_buffer); + if (!parse_value(current_item, input_buffer)) + { + goto fail; /* failed to parse value */ + } + buffer_skip_whitespace(input_buffer); + } + while (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == ',')); + + if (cannot_access_at_index(input_buffer, 0) || buffer_at_offset(input_buffer)[0] != ']') + { + goto fail; /* expected end of array */ + } + +success: + input_buffer->depth--; + + item->type = cJSON_Array; + item->child = head; + + input_buffer->offset++; + + return true; + +fail: + if (head != NULL) + { + cJSON_Delete(head); + } + + return false; } /* Render an array to text */ -static char *print_array(cJSON *item,int32_t depth,int32_t fmt) +static cJSON_bool print_array(const cJSON * const item, printbuffer * const output_buffer) { - char **entries; - char *out=0,*ptr,*ret;int32_t len=5; - cJSON *child=item->child; - int32_t numentries=0,i=0,fail=0; - - /* How many entries in the array? */ - while (child) numentries++,child=child->next; - /* Explicitly handle numentries==0 */ - if (!numentries) - { - out=(char*)cJSON_malloc(3+1); - if (out) strcpy(out,"[]"); - return out; - } - /* Allocate an array to hold the values for each */ - entries=(char**)cJSON_malloc((1+numentries)*sizeof(char*)); - if (!entries) return 0; - memset(entries,0,numentries*sizeof(char*)); - /* Retrieve all the results: */ - child=item->child; - while (child && !fail) - { - ret=print_value(child,depth+1,fmt); - entries[i++]=ret; - if (ret) len+=strlen(ret)+2+(fmt?1:0); else fail=1; - child=child->next; - } - - /* If we didn't fail, try to malloc the output string */ - if (!fail) out=(char*)cJSON_malloc(len+1); - /* If that fails, we fail. */ - if (!out) fail=1; - - /* Handle failure. */ - if (fail) - { - for (i=0;ichild; + + if (output_buffer == NULL) + { + return false; + } + + /* Compose the output array. */ + /* opening square bracket */ + output_pointer = ensure(output_buffer, 1); + if (output_pointer == NULL) + { + return false; + } + + *output_pointer = '['; + output_buffer->offset++; + output_buffer->depth++; + + while (current_element != NULL) + { + if (!print_value(current_element, output_buffer)) + { + return false; + } + update_offset(output_buffer); + if (current_element->next) + { + length = (size_t) (output_buffer->format ? 2 : 1); + output_pointer = ensure(output_buffer, length + 1); + if (output_pointer == NULL) + { + return false; + } + *output_pointer++ = ','; + if(output_buffer->format) + { + *output_pointer++ = ' '; + } + *output_pointer = '\0'; + output_buffer->offset += length; + } + current_element = current_element->next; + } + + output_pointer = ensure(output_buffer, 2); + if (output_pointer == NULL) + { + return false; + } + *output_pointer++ = ']'; + *output_pointer = '\0'; + output_buffer->depth--; + + return true; } /* Build an object from the text. */ -static const char *parse_object(cJSON *item,const char *value) +static cJSON_bool parse_object(cJSON * const item, parse_buffer * const input_buffer) { - cJSON *child; - if (*value!='{') {ep=value;return 0;} /* not an object! */ - - item->type=cJSON_Object; - value=skip(value+1); - if (*value=='}') return value+1; /* empty array. */ - - item->child=child=cJSON_New_Item(); - if (!item->child) return 0; - value=skip(parse_string(child,skip(value))); - if (!value) return 0; - child->string=child->valuestring;child->valuestring=0; - if (*value!=':') {ep=value;return 0;} /* fail! */ - value=skip(parse_value(child,skip(value+1))); /* skip any spacing, get the value. */ - if (!value) return 0; - - while (*value==',') - { - cJSON *new_item; - if (!(new_item=cJSON_New_Item())) return 0; /* memory fail */ - child->next=new_item;new_item->prev=child;child=new_item; - value=skip(parse_string(child,skip(value+1))); - if (!value) return 0; - child->string=child->valuestring;child->valuestring=0; - if (*value!=':') {ep=value;return 0;} /* fail! */ - value=skip(parse_value(child,skip(value+1))); /* skip any spacing, get the value. */ - if (!value) return 0; - } - - if (*value=='}') return value+1; /* end of array */ - ep=value;return 0; /* malformed. */ + cJSON *head = NULL; /* linked list head */ + cJSON *current_item = NULL; + + if (input_buffer->depth >= CJSON_NESTING_LIMIT) + { + return false; /* to deeply nested */ + } + input_buffer->depth++; + + if (cannot_access_at_index(input_buffer, 0) || (buffer_at_offset(input_buffer)[0] != '{')) + { + goto fail; /* not an object */ + } + + input_buffer->offset++; + buffer_skip_whitespace(input_buffer); + if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == '}')) + { + goto success; /* empty object */ + } + + /* check if we skipped to the end of the buffer */ + if (cannot_access_at_index(input_buffer, 0)) + { + input_buffer->offset--; + goto fail; + } + + /* step back to character in front of the first element */ + input_buffer->offset--; + /* loop through the comma separated array elements */ + do + { + /* allocate next item */ + cJSON *new_item = cJSON_New_Item(&(input_buffer->hooks)); + if (new_item == NULL) + { + goto fail; /* allocation failure */ + } + + /* attach next item to list */ + if (head == NULL) + { + /* start the linked list */ + current_item = head = new_item; + } + else + { + /* add to the end and advance */ + current_item->next = new_item; + new_item->prev = current_item; + current_item = new_item; + } + + /* parse the name of the child */ + input_buffer->offset++; + buffer_skip_whitespace(input_buffer); + if (!parse_string(current_item, input_buffer)) + { + goto fail; /* faile to parse name */ + } + buffer_skip_whitespace(input_buffer); + + /* swap valuestring and string, because we parsed the name */ + current_item->string = current_item->valuestring; + current_item->valuestring = NULL; + + if (cannot_access_at_index(input_buffer, 0) || (buffer_at_offset(input_buffer)[0] != ':')) + { + goto fail; /* invalid object */ + } + + /* parse the value */ + input_buffer->offset++; + buffer_skip_whitespace(input_buffer); + if (!parse_value(current_item, input_buffer)) + { + goto fail; /* failed to parse value */ + } + buffer_skip_whitespace(input_buffer); + } + while (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == ',')); + + if (cannot_access_at_index(input_buffer, 0) || (buffer_at_offset(input_buffer)[0] != '}')) + { + goto fail; /* expected end of object */ + } + +success: + input_buffer->depth--; + + item->type = cJSON_Object; + item->child = head; + + input_buffer->offset++; + return true; + +fail: + if (head != NULL) + { + cJSON_Delete(head); + } + + return false; } /* Render an object to text. */ -static char *print_object(cJSON *item,int32_t depth,int32_t fmt) +static cJSON_bool print_object(const cJSON * const item, printbuffer * const output_buffer) { - char **entries=0,**names=0; - char *out=0,*ptr,*ret,*str;int32_t len=7,i=0,j; - cJSON *child=item->child,*firstchild; - int32_t numentries=0,fail=0; - // Count the number of entries - firstchild = child; - while ( child ) + unsigned char *output_pointer = NULL; + size_t length = 0; + cJSON *current_item = item->child; + + if (output_buffer == NULL) { - numentries++; - child = child->next; - if ( child == firstchild ) + return false; + } + + /* Compose the output: */ + length = (size_t) (output_buffer->format ? 2 : 1); /* fmt: {\n */ + output_pointer = ensure(output_buffer, length + 1); + if (output_pointer == NULL) + { + return false; + } + + *output_pointer++ = '{'; + output_buffer->depth++; + if (output_buffer->format) + { + *output_pointer++ = '\n'; + } + output_buffer->offset += length; + + while (current_item) + { + if (output_buffer->format) { - printf("cJSON infinite loop detected\n"); - break; + size_t i; + output_pointer = ensure(output_buffer, output_buffer->depth); + if (output_pointer == NULL) + { + return false; + } + for (i = 0; i < output_buffer->depth; i++) + { + *output_pointer++ = '\t'; + } + output_buffer->offset += output_buffer->depth; + } + + /* print key */ + if (!print_string_ptr((unsigned char*)current_item->string, output_buffer)) + { + return false; + } + update_offset(output_buffer); + + length = (size_t) (output_buffer->format ? 2 : 1); + output_pointer = ensure(output_buffer, length); + if (output_pointer == NULL) + { + return false; + } + *output_pointer++ = ':'; + if (output_buffer->format) + { + *output_pointer++ = '\t'; + } + output_buffer->offset += length; + + /* print value */ + if (!print_value(current_item, output_buffer)) + { + return false; + } + update_offset(output_buffer); + + /* print comma if not last */ + length = (size_t) ((output_buffer->format ? 1 : 0) + (current_item->next ? 1 : 0)); + output_pointer = ensure(output_buffer, length + 1); + if (output_pointer == NULL) + { + return false; + } + if (current_item->next) + { + *output_pointer++ = ','; + } + + if (output_buffer->format) + { + *output_pointer++ = '\n'; + } + *output_pointer = '\0'; + output_buffer->offset += length; + + current_item = current_item->next; + } + + output_pointer = ensure(output_buffer, output_buffer->format ? (output_buffer->depth + 1) : 2); + if (output_pointer == NULL) + { + return false; + } + if (output_buffer->format) + { + size_t i; + for (i = 0; i < (output_buffer->depth - 1); i++) + { + *output_pointer++ = '\t'; } } - /* Explicitly handle empty object case */ - if (!numentries) - { - out=(char*)cJSON_malloc(fmt?depth+4+1:3+1); - if (!out) return 0; - ptr=out;*ptr++='{'; - if (fmt) {*ptr++='\n';for (i=0;ichild;depth++;if (fmt) len+=depth; - while ( child ) - { - names[i]=str=print_string_ptr(child->string); - entries[i++]=ret=print_value(child,depth,fmt); - if (str && ret) len+=strlen(ret)+strlen(str)+2+(fmt?2+depth:0); else fail=1; - child=child->next; - if ( child == firstchild ) - break; - } - - /* Try to allocate the output string */ - if (!fail) out=(char*)cJSON_malloc(len+1); - if (!out) fail=1; - - /* Handle failure */ - if (fail) - { - for (i=0;idepth--; + + return true; } /* Get Array size/item / object item. */ -int32_t cJSON_GetArraySize(cJSON *array) {cJSON *c; if ( array == 0 ) return(0); c=array->child;int32_t i=0;while(c)i++,c=c->next;return i;} -cJSON *cJSON_GetArrayItem(cJSON *array,int32_t item) {cJSON *c=array->child; while (c && item>0) item--,c=c->next; return c;} -cJSON *cJSON_GetObjectItem(cJSON *object,const char *string) {cJSON *c=object->child; while (c && cJSON_strcasecmp(c->string,string)) c=c->next; return c;} +CJSON_PUBLIC(int) cJSON_GetArraySize(const cJSON *array) +{ + cJSON *child = NULL; + size_t size = 0; + + if (array == NULL) + { + return 0; + } + + child = array->child; + + while(child != NULL) + { + size++; + child = child->next; + } + + /* FIXME: Can overflow here. Cannot be fixed without breaking the API */ + + return (int)size; +} + +static cJSON* get_array_item(const cJSON *array, size_t index) +{ + cJSON *current_child = NULL; + + if (array == NULL) + { + return NULL; + } + + current_child = array->child; + while ((current_child != NULL) && (index > 0)) + { + index--; + current_child = current_child->next; + } + + return current_child; +} + +CJSON_PUBLIC(cJSON *) cJSON_GetArrayItem(const cJSON *array, int index) +{ + if (index < 0) + { + return NULL; + } + + return get_array_item(array, (size_t)index); +} + +static cJSON *get_object_item(const cJSON * const object, const char * const name, const cJSON_bool case_sensitive) +{ + cJSON *current_element = NULL; + + if ((object == NULL) || (name == NULL)) + { + return NULL; + } + + current_element = object->child; + if (case_sensitive) + { + while ((current_element != NULL) && (strcmp(name, current_element->string) != 0)) + { + current_element = current_element->next; + } + } + else + { + while ((current_element != NULL) && (case_insensitive_strcmp((const unsigned char*)name, (const unsigned char*)(current_element->string)) != 0)) + { + current_element = current_element->next; + } + } + + return current_element; +} + +CJSON_PUBLIC(cJSON *) cJSON_GetObjectItem(const cJSON * const object, const char * const string) +{ + return get_object_item(object, string, false); +} + +CJSON_PUBLIC(cJSON *) cJSON_GetObjectItemCaseSensitive(const cJSON * const object, const char * const string) +{ + return get_object_item(object, string, true); +} + +CJSON_PUBLIC(cJSON_bool) cJSON_HasObjectItem(const cJSON *object, const char *string) +{ + return cJSON_GetObjectItem(object, string) ? 1 : 0; +} /* Utility for array list handling. */ -static void suffix_object(cJSON *prev,cJSON *item) {prev->next=item;item->prev=prev;} +static void suffix_object(cJSON *prev, cJSON *item) +{ + prev->next = item; + item->prev = prev; +} + /* Utility for handling references. */ -static cJSON *create_reference(cJSON *item) {cJSON *ref=cJSON_New_Item();if (!ref) return 0;memcpy(ref,item,sizeof(cJSON));ref->string=0;ref->type|=cJSON_IsReference;ref->next=ref->prev=0;return ref;} +static cJSON *create_reference(const cJSON *item, const internal_hooks * const hooks) +{ + cJSON *reference = NULL; + if (item == NULL) + { + return NULL; + } + + reference = cJSON_New_Item(hooks); + if (reference == NULL) + { + return NULL; + } + + memcpy(reference, item, sizeof(cJSON)); + reference->string = NULL; + reference->type |= cJSON_IsReference; + reference->next = reference->prev = NULL; + return reference; +} /* Add item to array/object. */ -void cJSON_AddItemToArray(cJSON *array, cJSON *item) {cJSON *c=array->child;if (!item) return; if (!c) {array->child=item;} else {while (c && c->next) c=c->next; suffix_object(c,item);}} -void cJSON_AddItemToObject(cJSON *object,const char *string,cJSON *item) {if (!item) return; if (item->string) cJSON_free(item->string);item->string=cJSON_strdup(string);cJSON_AddItemToArray(object,item);} -void cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item) {cJSON_AddItemToArray(array,create_reference(item));} -void cJSON_AddItemReferenceToObject(cJSON *object,const char *string,cJSON *item) {cJSON_AddItemToObject(object,string,create_reference(item));} +CJSON_PUBLIC(void) cJSON_AddItemToArray(cJSON *array, cJSON *item) +{ + cJSON *child = NULL; -cJSON *cJSON_DetachItemFromArray(cJSON *array,int32_t which) {cJSON *c=array->child;while (c && which>0) c=c->next,which--;if (!c) return 0; - if (c->prev) c->prev->next=c->next;if (c->next) c->next->prev=c->prev;if (c==array->child) array->child=c->next;c->prev=c->next=0;return c;} -void cJSON_DeleteItemFromArray(cJSON *array,int32_t which) {cJSON_Delete(cJSON_DetachItemFromArray(array,which));} -cJSON *cJSON_DetachItemFromObject(cJSON *object,const char *string) {int32_t i=0;cJSON *c=object->child;while (c && cJSON_strcasecmp(c->string,string)) i++,c=c->next;if (c) return cJSON_DetachItemFromArray(object,i);return 0;} -void cJSON_DeleteItemFromObject(cJSON *object,const char *string) {cJSON_Delete(cJSON_DetachItemFromObject(object,string));} + if ((item == NULL) || (array == NULL)) + { + return; + } + + child = array->child; + + if (child == NULL) + { + /* list is empty, start new one */ + array->child = item; + } + else + { + /* append to the end */ + while (child->next) + { + child = child->next; + } + suffix_object(child, item); + } +} + +CJSON_PUBLIC(void) cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item) +{ + if (item == NULL) + { + return; + } + + /* call cJSON_AddItemToObjectCS for code reuse */ + cJSON_AddItemToObjectCS(object, (char*)cJSON_strdup((const unsigned char*)string, &global_hooks), item); + /* remove cJSON_StringIsConst flag */ + item->type &= ~cJSON_StringIsConst; +} + +#if defined (__clang__) || ((__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ > 5)))) + #pragma GCC diagnostic push +#endif +#ifdef __GNUC__ +#pragma GCC diagnostic ignored "-Wcast-qual" +#endif + +/* Add an item to an object with constant string as key */ +CJSON_PUBLIC(void) cJSON_AddItemToObjectCS(cJSON *object, const char *string, cJSON *item) +{ + if ((item == NULL) || (string == NULL)) + { + return; + } + if (!(item->type & cJSON_StringIsConst) && item->string) + { + global_hooks.deallocate(item->string); + } + item->string = (char*)string; + item->type |= cJSON_StringIsConst; + cJSON_AddItemToArray(object, item); +} +#if defined (__clang__) || ((__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ > 5)))) + #pragma GCC diagnostic pop +#endif + +CJSON_PUBLIC(void) cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item) +{ + if (array == NULL) + { + return; + } + + cJSON_AddItemToArray(array, create_reference(item, &global_hooks)); +} + +CJSON_PUBLIC(void) cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *item) +{ + if ((object == NULL) || (string == NULL)) + { + return; + } + + cJSON_AddItemToObject(object, string, create_reference(item, &global_hooks)); +} + +CJSON_PUBLIC(cJSON *) cJSON_DetachItemViaPointer(cJSON *parent, cJSON * const item) +{ + if ((parent == NULL) || (item == NULL)) + { + return NULL; + } + + if (item->prev != NULL) + { + /* not the first element */ + item->prev->next = item->next; + } + if (item->next != NULL) + { + /* not the last element */ + item->next->prev = item->prev; + } + + if (item == parent->child) + { + /* first element */ + parent->child = item->next; + } + /* make sure the detached item doesn't point anywhere anymore */ + item->prev = NULL; + item->next = NULL; + + return item; +} + +CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromArray(cJSON *array, int which) +{ + if (which < 0) + { + return NULL; + } + + return cJSON_DetachItemViaPointer(array, get_array_item(array, (size_t)which)); +} + +CJSON_PUBLIC(void) cJSON_DeleteItemFromArray(cJSON *array, int which) +{ + cJSON_Delete(cJSON_DetachItemFromArray(array, which)); +} + +CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObject(cJSON *object, const char *string) +{ + cJSON *to_detach = cJSON_GetObjectItem(object, string); + + return cJSON_DetachItemViaPointer(object, to_detach); +} + +CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObjectCaseSensitive(cJSON *object, const char *string) +{ + cJSON *to_detach = cJSON_GetObjectItemCaseSensitive(object, string); + + return cJSON_DetachItemViaPointer(object, to_detach); +} + +CJSON_PUBLIC(void) cJSON_DeleteItemFromObject(cJSON *object, const char *string) +{ + cJSON_Delete(cJSON_DetachItemFromObject(object, string)); +} + +CJSON_PUBLIC(void) cJSON_DeleteItemFromObjectCaseSensitive(cJSON *object, const char *string) +{ + cJSON_Delete(cJSON_DetachItemFromObjectCaseSensitive(object, string)); +} /* Replace array/object items with new ones. */ -void cJSON_ReplaceItemInArray(cJSON *array,int32_t which,cJSON *newitem) {cJSON *c=array->child;while (c && which>0) c=c->next,which--;if (!c) return; - newitem->next=c->next;newitem->prev=c->prev;if (newitem->next) newitem->next->prev=newitem; - if (c==array->child) array->child=newitem; else newitem->prev->next=newitem;c->next=c->prev=0;cJSON_Delete(c);} -void cJSON_ReplaceItemInObject(cJSON *object,const char *string,cJSON *newitem){int32_t i=0;cJSON *c=object->child;while(c && cJSON_strcasecmp(c->string,string))i++,c=c->next;if(c){newitem->string=cJSON_strdup(string);cJSON_ReplaceItemInArray(object,i,newitem);}} +CJSON_PUBLIC(void) cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem) +{ + cJSON *after_inserted = NULL; + + if (which < 0) + { + return; + } + + after_inserted = get_array_item(array, (size_t)which); + if (after_inserted == NULL) + { + cJSON_AddItemToArray(array, newitem); + return; + } + + newitem->next = after_inserted; + newitem->prev = after_inserted->prev; + after_inserted->prev = newitem; + if (after_inserted == array->child) + { + array->child = newitem; + } + else + { + newitem->prev->next = newitem; + } +} + +CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON * const parent, cJSON * const item, cJSON * replacement) +{ + if ((parent == NULL) || (replacement == NULL) || (item == NULL)) + { + return false; + } + + if (replacement == item) + { + return true; + } + + replacement->next = item->next; + replacement->prev = item->prev; + + if (replacement->next != NULL) + { + replacement->next->prev = replacement; + } + if (replacement->prev != NULL) + { + replacement->prev->next = replacement; + } + if (parent->child == item) + { + parent->child = replacement; + } + + item->next = NULL; + item->prev = NULL; + cJSON_Delete(item); + + return true; +} + +CJSON_PUBLIC(void) cJSON_ReplaceItemInArray(cJSON *array, int which, cJSON *newitem) +{ + if (which < 0) + { + return; + } + + cJSON_ReplaceItemViaPointer(array, get_array_item(array, (size_t)which), newitem); +} + +static cJSON_bool replace_item_in_object(cJSON *object, const char *string, cJSON *replacement, cJSON_bool case_sensitive) +{ + if ((replacement == NULL) || (string == NULL)) + { + return false; + } + + /* replace the name in the replacement */ + if (!(replacement->type & cJSON_StringIsConst) && (replacement->string != NULL)) + { + cJSON_free(replacement->string); + } + replacement->string = (char*)cJSON_strdup((const unsigned char*)string, &global_hooks); + replacement->type &= ~cJSON_StringIsConst; + + cJSON_ReplaceItemViaPointer(object, get_object_item(object, string, case_sensitive), replacement); + + return true; +} + +CJSON_PUBLIC(void) cJSON_ReplaceItemInObject(cJSON *object, const char *string, cJSON *newitem) +{ + replace_item_in_object(object, string, newitem, false); +} + +CJSON_PUBLIC(void) cJSON_ReplaceItemInObjectCaseSensitive(cJSON *object, const char *string, cJSON *newitem) +{ + replace_item_in_object(object, string, newitem, true); +} /* Create basic types: */ -cJSON *cJSON_CreateNull(void) {cJSON *item=cJSON_New_Item();if(item)item->type=cJSON_NULL;return item;} -cJSON *cJSON_CreateTrue(void) {cJSON *item=cJSON_New_Item();if(item)item->type=cJSON_True;return item;} -cJSON *cJSON_CreateFalse(void) {cJSON *item=cJSON_New_Item();if(item)item->type=cJSON_False;return item;} -cJSON *cJSON_CreateBool(int32_t b) {cJSON *item=cJSON_New_Item();if(item)item->type=b?cJSON_True:cJSON_False;return item;} -cJSON *cJSON_CreateNumber(double num) {cJSON *item=cJSON_New_Item();if(item){item->type=cJSON_Number;item->valuedouble=num;item->valueint=(int64_t)num;}return item;} -cJSON *cJSON_CreateString(const char *string) {cJSON *item=cJSON_New_Item();if(item){item->type=cJSON_String;item->valuestring=cJSON_strdup(string);}return item;} -cJSON *cJSON_CreateArray(void) {cJSON *item=cJSON_New_Item();if(item)item->type=cJSON_Array;return item;} -cJSON *cJSON_CreateObject(void) {cJSON *item=cJSON_New_Item();if(item)item->type=cJSON_Object;return item;} +CJSON_PUBLIC(cJSON *) cJSON_CreateNull(void) +{ + cJSON *item = cJSON_New_Item(&global_hooks); + if(item) + { + item->type = cJSON_NULL; + } + + return item; +} + +CJSON_PUBLIC(cJSON *) cJSON_CreateTrue(void) +{ + cJSON *item = cJSON_New_Item(&global_hooks); + if(item) + { + item->type = cJSON_True; + } + + return item; +} + +CJSON_PUBLIC(cJSON *) cJSON_CreateFalse(void) +{ + cJSON *item = cJSON_New_Item(&global_hooks); + if(item) + { + item->type = cJSON_False; + } + + return item; +} + +CJSON_PUBLIC(cJSON *) cJSON_CreateBool(cJSON_bool b) +{ + cJSON *item = cJSON_New_Item(&global_hooks); + if(item) + { + item->type = b ? cJSON_True : cJSON_False; + } + + return item; +} + +CJSON_PUBLIC(cJSON *) cJSON_CreateNumber(double num) +{ + cJSON *item = cJSON_New_Item(&global_hooks); + if(item) + { + item->type = cJSON_Number; + item->valuedouble = num; + + /* use saturation in case of overflow */ + if (num >= INT_MAX) + { + item->valueint = INT_MAX; + } + else if (num <= INT_MIN) + { + item->valueint = INT_MIN; + } + else + { + item->valueint = (int)num; + } + } + + return item; +} + +CJSON_PUBLIC(cJSON *) cJSON_CreateString(const char *string) +{ + cJSON *item = cJSON_New_Item(&global_hooks); + if(item) + { + item->type = cJSON_String; + item->valuestring = (char*)cJSON_strdup((const unsigned char*)string, &global_hooks); + if(!item->valuestring) + { + cJSON_Delete(item); + return NULL; + } + } + + return item; +} + +CJSON_PUBLIC(cJSON *) cJSON_CreateRaw(const char *raw) +{ + cJSON *item = cJSON_New_Item(&global_hooks); + if(item) + { + item->type = cJSON_Raw; + item->valuestring = (char*)cJSON_strdup((const unsigned char*)raw, &global_hooks); + if(!item->valuestring) + { + cJSON_Delete(item); + return NULL; + } + } + + return item; +} + +CJSON_PUBLIC(cJSON *) cJSON_CreateArray(void) +{ + cJSON *item = cJSON_New_Item(&global_hooks); + if(item) + { + item->type=cJSON_Array; + } + + return item; +} + +CJSON_PUBLIC(cJSON *) cJSON_CreateObject(void) +{ + cJSON *item = cJSON_New_Item(&global_hooks); + if (item) + { + item->type = cJSON_Object; + } + + return item; +} /* Create Arrays: */ -cJSON *cJSON_CreateIntArray(int64_t *numbers,int32_t count) {int32_t i;cJSON *n=0,*p=0,*a=cJSON_CreateArray();for(i=0;a && ichild=n;else suffix_object(p,n);p=n;}return a;} -cJSON *cJSON_CreateFloatArray(float *numbers,int32_t count) {int32_t i;cJSON *n=0,*p=0,*a=cJSON_CreateArray();for(i=0;a && ichild=n;else suffix_object(p,n);p=n;}return a;} -cJSON *cJSON_CreateDoubleArray(double *numbers,int32_t count) {int32_t i;cJSON *n=0,*p=0,*a=cJSON_CreateArray();for(i=0;a && ichild=n;else suffix_object(p,n);p=n;}return a;} -cJSON *cJSON_CreateStringArray(char **strings,int32_t count) {int32_t i;cJSON *n=0,*p=0,*a=cJSON_CreateArray();for(i=0;a && ichild=n;else suffix_object(p,n);p=n;}return a;} +CJSON_PUBLIC(cJSON *) cJSON_CreateIntArray(const int *numbers, int count) +{ + size_t i = 0; + cJSON *n = NULL; + cJSON *p = NULL; + cJSON *a = NULL; + + if ((count < 0) || (numbers == NULL)) + { + return NULL; + } + + a = cJSON_CreateArray(); + for(i = 0; a && (i < (size_t)count); i++) + { + n = cJSON_CreateNumber(numbers[i]); + if (!n) + { + cJSON_Delete(a); + return NULL; + } + if(!i) + { + a->child = n; + } + else + { + suffix_object(p, n); + } + p = n; + } + + return a; +} + +CJSON_PUBLIC(cJSON *) cJSON_CreateFloatArray(const float *numbers, int count) +{ + size_t i = 0; + cJSON *n = NULL; + cJSON *p = NULL; + cJSON *a = NULL; + + if ((count < 0) || (numbers == NULL)) + { + return NULL; + } + + a = cJSON_CreateArray(); + + for(i = 0; a && (i < (size_t)count); i++) + { + n = cJSON_CreateNumber((double)numbers[i]); + if(!n) + { + cJSON_Delete(a); + return NULL; + } + if(!i) + { + a->child = n; + } + else + { + suffix_object(p, n); + } + p = n; + } + + return a; +} + +CJSON_PUBLIC(cJSON *) cJSON_CreateDoubleArray(const double *numbers, int count) +{ + size_t i = 0; + cJSON *n = NULL; + cJSON *p = NULL; + cJSON *a = NULL; + + if ((count < 0) || (numbers == NULL)) + { + return NULL; + } + + a = cJSON_CreateArray(); + + for(i = 0;a && (i < (size_t)count); i++) + { + n = cJSON_CreateNumber(numbers[i]); + if(!n) + { + cJSON_Delete(a); + return NULL; + } + if(!i) + { + a->child = n; + } + else + { + suffix_object(p, n); + } + p = n; + } + + return a; +} + +CJSON_PUBLIC(cJSON *) cJSON_CreateStringArray(const char **strings, int count) +{ + size_t i = 0; + cJSON *n = NULL; + cJSON *p = NULL; + cJSON *a = NULL; + + if ((count < 0) || (strings == NULL)) + { + return NULL; + } + + a = cJSON_CreateArray(); + + for (i = 0; a && (i < (size_t)count); i++) + { + n = cJSON_CreateString(strings[i]); + if(!n) + { + cJSON_Delete(a); + return NULL; + } + if(!i) + { + a->child = n; + } + else + { + suffix_object(p,n); + } + p = n; + } + + return a; +} /* Duplication */ -cJSON *cJSON_Duplicate(cJSON *item,int32_t recurse) +CJSON_PUBLIC(cJSON *) cJSON_Duplicate(const cJSON *item, cJSON_bool recurse) { - cJSON *newitem,*cptr,*nptr=0,*newchild; - /* Bail on bad ptr */ - if (!item) return 0; - /* Create new item */ - newitem=cJSON_New_Item(); - if (!newitem) return 0; - /* Copy over all vars */ - newitem->type=item->type&(~cJSON_IsReference),newitem->valueint=item->valueint,newitem->valuedouble=item->valuedouble; - if (item->valuestring) {newitem->valuestring=cJSON_strdup(item->valuestring); if (!newitem->valuestring) {cJSON_Delete(newitem);return 0;}} - if (item->string) {newitem->string=cJSON_strdup(item->string); if (!newitem->string) {cJSON_Delete(newitem);return 0;}} - /* If non-recursive, then we're done! */ - if (!recurse) return newitem; - /* Walk the ->next chain for the child. */ - cptr=item->child; - while (cptr) - { - newchild=cJSON_Duplicate(cptr,1); /* Duplicate (with recurse) each item in the ->next chain */ - if (!newchild) {cJSON_Delete(newitem);return 0;} - if (nptr) {nptr->next=newchild,newchild->prev=nptr;nptr=newchild;} /* If newitem->child already set, then crosswire ->prev and ->next and move on */ - else {newitem->child=newchild;nptr=newchild;} /* Set newitem->child and move to it */ - cptr=cptr->next; - } - return newitem; -} + cJSON *newitem = NULL; + cJSON *child = NULL; + cJSON *next = NULL; + cJSON *newchild = NULL; -void cJSON_Minify(char *json) -{ - char *into=json; - while (*json) - { - if (*json==' ') json++; - else if (*json=='\t') json++; // Whitespace characters. - else if (*json=='\r') json++; - else if (*json=='\n') json++; - else if (*json=='/' && json[1]=='/') while (*json && *json!='\n') json++; // double-slash comments, to end of line. - else if (*json=='/' && json[1]=='*') {while (*json && !(*json=='*' && json[1]=='/')) json++;json+=2;} // multiline comments. - else if (*json=='\"'){*into++=*json++;while (*json && *json!='\"'){if (*json=='\\') *into++=*json++;*into++=*json++;}*into++=*json++;} // string literals, which are \" sensitive. - else *into++=*json++; // All other characters. - } - *into=0; // and null-terminate. -} - -// the following written by jl777 -/****************************************************************************** - * Copyright © 2014-2017 The SuperNET Developers. * - * * - * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * - * the top-level directory of this distribution for the individual copyright * - * holder information and the developer policies on copyright and licensing. * - * * - * Unless otherwise agreed in a custom licensing agreement, no part of the * - * SuperNET software, including this file may be copied, modified, propagated * - * or distributed except according to the terms contained in the LICENSE file * - * * - * Removal or modification of this copyright notice is prohibited. * - * * - ******************************************************************************/ - -void copy_cJSON(struct destbuf *dest,cJSON *obj) -{ - char *str; - int i; - long offset; - dest->buf[0] = 0; - if ( obj != 0 ) + /* Bail on bad ptr */ + if (!item) { - str = cJSON_Print(obj); - if ( str != 0 ) + goto fail; + } + /* Create new item */ + newitem = cJSON_New_Item(&global_hooks); + if (!newitem) + { + goto fail; + } + /* Copy over all vars */ + newitem->type = item->type & (~cJSON_IsReference); + newitem->valueint = item->valueint; + newitem->valuedouble = item->valuedouble; + if (item->valuestring) + { + newitem->valuestring = (char*)cJSON_strdup((unsigned char*)item->valuestring, &global_hooks); + if (!newitem->valuestring) { - offset = stripquotes(str); - //strcpy(dest,str+offset); - for (i=0; ibuf[i]= str[offset+i]) == 0 ) - break; - dest->buf[i] = 0; - free(str); + goto fail; } } -} - -void copy_cJSON2(char *dest,int32_t maxlen,cJSON *obj) -{ - struct destbuf tmp; - maxlen--; - dest[0] = 0; - if ( maxlen > sizeof(tmp.buf) ) - maxlen = sizeof(tmp.buf); - copy_cJSON(&tmp,obj); - if ( strlen(tmp.buf) < maxlen ) - strcpy(dest,tmp.buf); - else dest[0] = 0; -} - -int64_t _get_cJSON_int(cJSON *json) -{ - struct destbuf tmp; - if ( json != 0 ) + if (item->string) { - copy_cJSON(&tmp,json); - if ( tmp.buf[0] != 0 ) - return(calc_nxt64bits(tmp.buf)); - } - return(0); -} - -int64_t get_cJSON_int(cJSON *json,char *field) -{ - cJSON *numjson; - if ( json != 0 ) - { - numjson = cJSON_GetObjectItem(json,field); - if ( numjson != 0 ) - return(_get_cJSON_int(numjson)); - } - return(0); -} - -int64_t conv_floatstr(char *numstr) -{ - double val,corr; - val = atof(numstr); - corr = (val < 0.) ? -0.50000000001 : 0.50000000001; - return((int64_t)(val * SATOSHIDEN + corr)); -} - -int64_t _conv_cJSON_float(cJSON *json) -{ - int64_t conv_floatstr(char *); - struct destbuf tmp; - if ( json != 0 ) - { - copy_cJSON(&tmp,json); - return(conv_floatstr(tmp.buf)); - } - return(0); -} - -int64_t conv_cJSON_float(cJSON *json,char *field) -{ - if ( json != 0 ) - return(_conv_cJSON_float(cJSON_GetObjectItem(json,field))); - return(0); -} - -int32_t extract_cJSON_str(char *dest,int32_t max,cJSON *json,char *field) -{ - int32_t safecopy(char *dest,char *src,long len); - char *str; - cJSON *obj; - int32_t len; - long offset; - dest[0] = 0; - obj = cJSON_GetObjectItem(json,field); - if ( obj != 0 ) - { - str = cJSON_Print(obj); - offset = stripquotes(str); - len = safecopy(dest,str+offset,max); - free(str); - return(len); - } - return(0); -} - -cJSON *gen_list_json(char **list) -{ - cJSON *array,*item; - array = cJSON_CreateArray(); - while ( list != 0 && *list != 0 && *list[0] != 0 ) - { - item = cJSON_CreateString(*list++); - cJSON_AddItemToArray(array,item); - } - return(array); -} - -uint64_t get_API_nxt64bits(cJSON *obj) -{ - uint64_t nxt64bits = 0; - struct destbuf tmp; - if ( obj != 0 ) - { - if ( is_cJSON_Number(obj) != 0 ) - return((uint64_t)obj->valuedouble); - copy_cJSON(&tmp,obj); - nxt64bits = calc_nxt64bits(tmp.buf); - } - return(nxt64bits); -} -uint64_t j64bits(cJSON *json,char *field) { if ( field == 0 ) return(get_API_nxt64bits(json)); return(get_API_nxt64bits(cJSON_GetObjectItem(json,field))); } -uint64_t j64bitsi(cJSON *json,int32_t i) { return(get_API_nxt64bits(cJSON_GetArrayItem(json,i))); } - -uint64_t get_satoshi_obj(cJSON *json,char *field) -{ - int32_t i,n; - uint64_t prev,satoshis,mult = 1; - struct destbuf numstr,checkstr; - cJSON *numjson; - numjson = cJSON_GetObjectItem(json,field); - copy_cJSON(&numstr,numjson); - satoshis = prev = 0; mult = 1; n = (int32_t)strlen(numstr.buf); - for (i=n-1; i>=0; i--,mult*=10) - { - satoshis += (mult * (numstr.buf[i] - '0')); - if ( satoshis < prev ) - printf("get_satoshi_obj numstr.(%s) i.%d prev.%llu vs satoshis.%llu\n",numstr.buf,i,(unsigned long long)prev,(unsigned long long)satoshis); - prev = satoshis; - } - sprintf(checkstr.buf,"%llu",(long long)satoshis); - if ( strcmp(checkstr.buf,numstr.buf) != 0 ) - { - printf("SATOSHI GREMLIN?? numstr.(%s) -> %.8f -> (%s)\n",numstr.buf,dstr(satoshis),checkstr.buf); - } - return(satoshis); -} - -void add_satoshis_json(cJSON *json,char *field,uint64_t satoshis) -{ - cJSON *obj; - char numstr[64]; - sprintf(numstr,"%lld",(long long)satoshis); - obj = cJSON_CreateString(numstr); - cJSON_AddItemToObject(json,field,obj); - if ( satoshis != get_satoshi_obj(json,field) ) - printf("error adding satoshi obj %ld -> %ld\n",(unsigned long)satoshis,(unsigned long)get_satoshi_obj(json,field)); -} - -char *cJSON_str(cJSON *json) -{ - if ( json != 0 && is_cJSON_String(json) != 0 ) - return(json->valuestring); - return(0); -} - -void jadd(cJSON *json,char *field,cJSON *item) { if ( json != 0 )cJSON_AddItemToObject(json,field,item); } -void jaddstr(cJSON *json,char *field,char *str) { if ( json != 0 && str != 0 ) cJSON_AddItemToObject(json,field,cJSON_CreateString(str)); } -void jaddnum(cJSON *json,char *field,double num) { if ( json != 0 )cJSON_AddItemToObject(json,field,cJSON_CreateNumber(num)); } -void jadd64bits(cJSON *json,char *field,uint64_t nxt64bits) { char numstr[64]; sprintf(numstr,"%llu",(long long)nxt64bits), jaddstr(json,field,numstr); } -void jaddi(cJSON *json,cJSON *item) { if ( json != 0 ) cJSON_AddItemToArray(json,item); } -void jaddistr(cJSON *json,char *str) { if ( json != 0 ) cJSON_AddItemToArray(json,cJSON_CreateString(str)); } -void jaddinum(cJSON *json,double num) { if ( json != 0 ) cJSON_AddItemToArray(json,cJSON_CreateNumber(num)); } -void jaddi64bits(cJSON *json,uint64_t nxt64bits) { char numstr[64]; sprintf(numstr,"%llu",(long long)nxt64bits), jaddistr(json,numstr); } -char *jstr(cJSON *json,char *field) { if ( json == 0 ) return(0); if ( field == 0 ) return(cJSON_str(json)); return(cJSON_str(cJSON_GetObjectItem(json,field))); } - -char *jstri(cJSON *json,int32_t i) { return(cJSON_str(cJSON_GetArrayItem(json,i))); } -char *jprint(cJSON *json,int32_t freeflag) -{ - char *str; - /*static portable_mutex_t mutex; static int32_t initflag; - if ( initflag == 0 ) - { - portable_mutex_init(&mutex); - initflag = 1; - }*/ - if ( json == 0 ) - return(clonestr((char *)"{}")); - //portable_mutex_lock(&mutex); - //usleep(5000); - str = cJSON_Print(json), _stripwhite(str,' '); - if ( freeflag != 0 ) - free_json(json); - //portable_mutex_unlock(&mutex); - return(str); -} - -bits256 get_API_bits256(cJSON *obj) -{ - bits256 hash; char *str; - memset(hash.bytes,0,sizeof(hash)); - if ( obj != 0 ) - { - if ( is_cJSON_String(obj) != 0 && (str= obj->valuestring) != 0 && strlen(str) == 64 ) - decode_hex(hash.bytes,sizeof(hash),str); - } - return(hash); -} -bits256 jbits256(cJSON *json,char *field) { if ( field == 0 ) return(get_API_bits256(json)); return(get_API_bits256(cJSON_GetObjectItem(json,field))); } -bits256 jbits256i(cJSON *json,int32_t i) { return(get_API_bits256(cJSON_GetArrayItem(json,i))); } -void jaddbits256(cJSON *json,char *field,bits256 hash) { char str[65]; bits256_str(str,hash), jaddstr(json,field,str); } -void jaddibits256(cJSON *json,bits256 hash) { char str[65]; bits256_str(str,hash), jaddistr(json,str); } - -char *get_cJSON_fieldname(cJSON *obj) -{ - if ( obj != 0 ) - { - if ( obj->child != 0 && obj->child->string != 0 ) - return(obj->child->string); - else if ( obj->string != 0 ) - return(obj->string); - } - return((char *)""); -} - -int32_t jnum(cJSON *obj,char *field) -{ - char *str; int32_t polarity = 1; - if ( field != 0 ) - obj = jobj(obj,field); - if ( obj != 0 ) - { - if ( is_cJSON_Number(obj) != 0 ) - return(obj->valuedouble); - else if ( is_cJSON_String(obj) != 0 && (str= jstr(obj,0)) != 0 ) + newitem->string = (item->type&cJSON_StringIsConst) ? item->string : (char*)cJSON_strdup((unsigned char*)item->string, &global_hooks); + if (!newitem->string) { - if ( str[0] == '-' ) - polarity = -1, str++; - return(polarity * (int32_t)calc_nxt64bits(str)); + goto fail; } } - return(0); -} - -void ensure_jsonitem(cJSON *json,char *field,char *value) -{ - cJSON *obj = cJSON_GetObjectItem(json,field); - if ( obj == 0 ) - cJSON_AddItemToObject(json,field,cJSON_CreateString(value)); - else cJSON_ReplaceItemInObject(json,field,cJSON_CreateString(value)); -} - -int32_t in_jsonarray(cJSON *array,char *value) -{ - int32_t i,n; - struct destbuf remote; - if ( array != 0 && is_cJSON_Array(array) != 0 ) + /* If non-recursive, then we're done! */ + if (!recurse) { - n = cJSON_GetArraySize(array); - for (i=0; inext chain for the child. */ + child = item->child; + while (child != NULL) + { + newchild = cJSON_Duplicate(child, true); /* Duplicate (with recurse) each item in the ->next chain */ + if (!newchild) { - if ( array == 0 || n == 0 ) - break; - copy_cJSON(&remote,cJSON_GetArrayItem(array,i)); - if ( strcmp(remote.buf,value) == 0 ) - return(1); + goto fail; } - } - return(0); -} - -int32_t myatoi(char *str,int32_t range) -{ - long x; char *ptr; - x = strtol(str,&ptr,10); - if ( range != 0 && x >= range ) - x = (range - 1); - return((int32_t)x); -} - -int32_t get_API_int(cJSON *obj,int32_t val) -{ - struct destbuf buf; - if ( obj != 0 ) - { - if ( is_cJSON_Number(obj) != 0 ) - return((int32_t)obj->valuedouble); - copy_cJSON(&buf,obj); - val = myatoi(buf.buf,0); - if ( val < 0 ) - val = 0; - } - return(val); -} -int32_t jint(cJSON *json,char *field) { if ( json == 0 ) return(0); if ( field == 0 ) return(get_API_int(json,0)); return(get_API_int(cJSON_GetObjectItem(json,field),0)); } -int32_t jinti(cJSON *json,int32_t i) { if ( json == 0 ) return(0); return(get_API_int(cJSON_GetArrayItem(json,i),0)); } - -uint32_t get_API_uint(cJSON *obj,uint32_t val) -{ - struct destbuf buf; - if ( obj != 0 ) - { - if ( is_cJSON_Number(obj) != 0 ) - return((uint32_t)obj->valuedouble); - copy_cJSON(&buf,obj); - val = myatoi(buf.buf,0); - } - return(val); -} -uint32_t juint(cJSON *json,char *field) { if ( json == 0 ) return(0); if ( field == 0 ) return(get_API_uint(json,0)); return(get_API_uint(cJSON_GetObjectItem(json,field),0)); } -uint32_t juinti(cJSON *json,int32_t i) { if ( json == 0 ) return(0); return(get_API_uint(cJSON_GetArrayItem(json,i),0)); } - -double get_API_float(cJSON *obj) -{ - double val = 0.; - struct destbuf buf; - if ( obj != 0 ) - { - if ( is_cJSON_Number(obj) != 0 ) - return(obj->valuedouble); - copy_cJSON(&buf,obj); - val = atof(buf.buf); - } - return(val); -} - -double jdouble(cJSON *json,char *field) -{ - if ( json != 0 ) - { - if ( field == 0 ) - return(get_API_float(json)); - else return(get_API_float(cJSON_GetObjectItem(json,field))); - } else return(0.); -} - -double jdoublei(cJSON *json,int32_t i) -{ - if ( json != 0 ) - return(get_API_float(cJSON_GetArrayItem(json,i))); - else return(0.); -} - -cJSON *jobj(cJSON *json,char *field) { if ( json != 0 ) return(cJSON_GetObjectItem(json,field)); return(0); } - -void jdelete(cJSON *json,char *field) -{ - if ( jobj(json,field) != 0 ) - cJSON_DeleteItemFromObject(json,field); -} - -cJSON *jduplicate(cJSON *json) { return(cJSON_Duplicate(json,1)); } - -cJSON *jitem(cJSON *array,int32_t i) { if ( array != 0 && is_cJSON_Array(array) != 0 && cJSON_GetArraySize(array) > i ) return(cJSON_GetArrayItem(array,i)); return(0); } -cJSON *jarray(int32_t *nump,cJSON *json,char *field) -{ - cJSON *array; - if ( json != 0 ) - { - if ( field == 0 ) - array = json; - else array = cJSON_GetObjectItem(json,field); - if ( array != 0 && is_cJSON_Array(array) != 0 && (*nump= cJSON_GetArraySize(array)) > 0 ) - return(array); - } - *nump = 0; - return(0); -} - -int32_t expand_nxt64bits(char *NXTaddr,uint64_t nxt64bits) -{ - int32_t i,n; - uint64_t modval; - char rev[64]; - for (i=0; nxt64bits!=0; i++) - { - modval = nxt64bits % 10; - rev[i] = (char)(modval + '0'); - nxt64bits /= 10; - } - n = i; - for (i=0; i= 22 ) - { - printf("calc_nxt64bits: illegal NXTaddr.(%s) too long\n",NXTaddr); - return(0); - } - else if ( strcmp(NXTaddr,"0") == 0 || strcmp(NXTaddr,"false") == 0 ) - { - // printf("zero address?\n"); getchar(); - return(0); - } - if ( NXTaddr[0] == '-' ) - polarity = -1, NXTaddr++, n--; - mult = 1; - lastval = 0; - for (i=n-1; i>=0; i--,mult*=10) - { - c = NXTaddr[i]; - if ( c < '0' || c > '9' ) + if (next != NULL) { - printf("calc_nxt64bits: illegal char.(%c %d) in (%s).%d\n",c,c,NXTaddr,(int32_t)i); -#ifdef __APPLE__ - //while ( 1 ) + /* If newitem->child already set, then crosswire ->prev and ->next and move on */ + next->next = newchild; + newchild->prev = next; + next = newchild; + } + else + { + /* Set newitem->child and move to it */ + newitem->child = newchild; + next = newchild; + } + child = child->next; + } + + return newitem; + +fail: + if (newitem != NULL) + { + cJSON_Delete(newitem); + } + + return NULL; +} + +CJSON_PUBLIC(void) cJSON_Minify(char *json) +{ + unsigned char *into = (unsigned char*)json; + + if (json == NULL) + { + return; + } + + while (*json) + { + if (*json == ' ') + { + json++; + } + else if (*json == '\t') + { + /* Whitespace characters. */ + json++; + } + else if (*json == '\r') + { + json++; + } + else if (*json=='\n') + { + json++; + } + else if ((*json == '/') && (json[1] == '/')) + { + /* double-slash comments, to end of line. */ + while (*json && (*json != '\n')) { - //sleep(60); - printf("calc_nxt64bits: illegal char.(%c %d) in (%s).%d\n",c,c,NXTaddr,(int32_t)i); + json++; } -#endif - return(0); } - nxt64bits += mult * (c - '0'); - if ( nxt64bits < lastval ) - printf("calc_nxt64bits: warning: 64bit overflow %llx < %llx\n",(long long)nxt64bits,(long long)lastval); - lastval = nxt64bits; + else if ((*json == '/') && (json[1] == '*')) + { + /* multiline comments. */ + while (*json && !((*json == '*') && (json[1] == '/'))) + { + json++; + } + json += 2; + } + else if (*json == '\"') + { + /* string literals, which are \" sensitive. */ + *into++ = (unsigned char)*json++; + while (*json && (*json != '\"')) + { + if (*json == '\\') + { + *into++ = (unsigned char)*json++; + } + *into++ = (unsigned char)*json++; + } + *into++ = (unsigned char)*json++; + } + else + { + /* All other characters. */ + *into++ = (unsigned char)*json++; + } } - while ( *NXTaddr == '0' && *NXTaddr != 0 ) - NXTaddr++; - if ( cmp_nxt64bits(NXTaddr,nxt64bits) != 0 ) - printf("error calculating nxt64bits: %s -> %llx -> %s\n",NXTaddr,(long long)nxt64bits,nxt64str(nxt64bits)); - if ( polarity < 0 ) - return(-(int64_t)nxt64bits); - return(nxt64bits); + + /* and null-terminate. */ + *into = '\0'; } -cJSON *addrs_jsonarray(uint64_t *addrs,int32_t num) +CJSON_PUBLIC(cJSON_bool) cJSON_IsInvalid(const cJSON * const item) { - int32_t j; cJSON *array; - array = cJSON_CreateArray(); - for (j=0; jtype & 0xFF) == cJSON_Invalid; } -void free_json(cJSON *json) { if ( json != 0 ) cJSON_Delete(json); } +CJSON_PUBLIC(cJSON_bool) cJSON_IsFalse(const cJSON * const item) +{ + if (item == NULL) + { + return false; + } + + return (item->type & 0xFF) == cJSON_False; +} + +CJSON_PUBLIC(cJSON_bool) cJSON_IsTrue(const cJSON * const item) +{ + if (item == NULL) + { + return false; + } + + return (item->type & 0xff) == cJSON_True; +} + + +CJSON_PUBLIC(cJSON_bool) cJSON_IsBool(const cJSON * const item) +{ + if (item == NULL) + { + return false; + } + + return (item->type & (cJSON_True | cJSON_False)) != 0; +} +CJSON_PUBLIC(cJSON_bool) cJSON_IsNull(const cJSON * const item) +{ + if (item == NULL) + { + return false; + } + + return (item->type & 0xFF) == cJSON_NULL; +} + +CJSON_PUBLIC(cJSON_bool) cJSON_IsNumber(const cJSON * const item) +{ + if (item == NULL) + { + return false; + } + + return (item->type & 0xFF) == cJSON_Number; +} + +CJSON_PUBLIC(cJSON_bool) cJSON_IsString(const cJSON * const item) +{ + if (item == NULL) + { + return false; + } + + return (item->type & 0xFF) == cJSON_String; +} + +CJSON_PUBLIC(cJSON_bool) cJSON_IsArray(const cJSON * const item) +{ + if (item == NULL) + { + return false; + } + + return (item->type & 0xFF) == cJSON_Array; +} + +CJSON_PUBLIC(cJSON_bool) cJSON_IsObject(const cJSON * const item) +{ + if (item == NULL) + { + return false; + } + + return (item->type & 0xFF) == cJSON_Object; +} + +CJSON_PUBLIC(cJSON_bool) cJSON_IsRaw(const cJSON * const item) +{ + if (item == NULL) + { + return false; + } + + return (item->type & 0xFF) == cJSON_Raw; +} + +CJSON_PUBLIC(cJSON_bool) cJSON_Compare(const cJSON * const a, const cJSON * const b, const cJSON_bool case_sensitive) +{ + if ((a == NULL) || (b == NULL) || ((a->type & 0xFF) != (b->type & 0xFF)) || cJSON_IsInvalid(a)) + { + return false; + } + + /* check if type is valid */ + switch (a->type & 0xFF) + { + case cJSON_False: + case cJSON_True: + case cJSON_NULL: + case cJSON_Number: + case cJSON_String: + case cJSON_Raw: + case cJSON_Array: + case cJSON_Object: + break; + + default: + return false; + } + + /* identical objects are equal */ + if (a == b) + { + return true; + } + + switch (a->type & 0xFF) + { + /* in these cases and equal type is enough */ + case cJSON_False: + case cJSON_True: + case cJSON_NULL: + return true; + + case cJSON_Number: + if (a->valuedouble == b->valuedouble) + { + return true; + } + return false; + + case cJSON_String: + case cJSON_Raw: + if ((a->valuestring == NULL) || (b->valuestring == NULL)) + { + return false; + } + if (strcmp(a->valuestring, b->valuestring) == 0) + { + return true; + } + + return false; + + case cJSON_Array: + { + cJSON *a_element = a->child; + cJSON *b_element = b->child; + + for (; (a_element != NULL) && (b_element != NULL);) + { + if (!cJSON_Compare(a_element, b_element, case_sensitive)) + { + return false; + } + + a_element = a_element->next; + b_element = b_element->next; + } + + /* one of the arrays is longer than the other */ + if (a_element != b_element) { + return false; + } + + return true; + } + + case cJSON_Object: + { + cJSON *a_element = NULL; + cJSON *b_element = NULL; + cJSON_ArrayForEach(a_element, a) + { + /* TODO This has O(n^2) runtime, which is horrible! */ + b_element = get_object_item(b, a_element->string, case_sensitive); + if (b_element == NULL) + { + return false; + } + + if (!cJSON_Compare(a_element, b_element, case_sensitive)) + { + return false; + } + } + + /* doing this twice, once on a and b to prevent true comparison if a subset of b + * TODO: Do this the proper way, this is just a fix for now */ + cJSON_ArrayForEach(b_element, b) + { + a_element = get_object_item(a, b_element->string, case_sensitive); + if (a_element == NULL) + { + return false; + } + + if (!cJSON_Compare(b_element, a_element, case_sensitive)) + { + return false; + } + } + + return true; + } + + default: + return false; + } +} + +CJSON_PUBLIC(void *) cJSON_malloc(size_t size) +{ + return global_hooks.allocate(size); +} + +CJSON_PUBLIC(void) cJSON_free(void *object) +{ + global_hooks.deallocate(object); +} diff --git a/src/cJSON.h b/src/cJSON.h old mode 100755 new mode 100644 index d3076aa53..fb8971575 --- a/src/cJSON.h +++ b/src/cJSON.h @@ -1,27 +1,24 @@ /* - Copyright (c) 2009 Dave Gamble - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. - */ + Copyright (c) 2009-2017 Dave Gamble and cJSON contributors -#ifndef cJSON__h -#define cJSON__h + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. +*/ #include #include @@ -31,199 +28,241 @@ #include #include -//#include "../crypto777/OS_portable.h" - -#define MAX_JSON_FIELD 4096 // on the big side +#ifndef cJSON__h +#define cJSON__h #ifdef __cplusplus extern "C" { #endif - - /* cJSON Types: */ -#define cJSON_False 0 -#define cJSON_True 1 -#define cJSON_NULL 2 -#define cJSON_Number 3 -#define cJSON_String 4 -#define cJSON_Array 5 -#define cJSON_Object 6 - -#define is_cJSON_Null(json) ((json) != 0 && ((json)->type & 0xff) == cJSON_NULL) -#define is_cJSON_Array(json) ((json) != 0 && ((json)->type & 0xff) == cJSON_Array) -#define is_cJSON_String(json) ((json) != 0 && ((json)->type & 0xff) == cJSON_String) -#define is_cJSON_Number(json) ((json) != 0 && ((json)->type & 0xff) == cJSON_Number) -#define is_cJSON_Object(json) ((json) != 0 && ((json)->type & 0xff) == cJSON_Object) -#define is_cJSON_True(json) ((json) != 0 && ((json)->type & 0xff) == cJSON_True) -#define is_cJSON_False(json) ((json) != 0 && ((json)->type & 0xff) == cJSON_False) - + +/* project version */ +#define CJSON_VERSION_MAJOR 1 +#define CJSON_VERSION_MINOR 5 +#define CJSON_VERSION_PATCH 9 + +#include + +/* cJSON Types: */ +#define cJSON_Invalid (0) +#define cJSON_False (1 << 0) +#define cJSON_True (1 << 1) +#define cJSON_NULL (1 << 2) +#define cJSON_Number (1 << 3) +#define cJSON_String (1 << 4) +#define cJSON_Array (1 << 5) +#define cJSON_Object (1 << 6) +#define cJSON_Raw (1 << 7) /* raw json */ + #define cJSON_IsReference 256 - - /* The cJSON structure: */ - typedef struct cJSON { - struct cJSON *next,*prev; /* next/prev allow you to walk array/object chains. Alternatively, use GetArraySize/GetArrayItem/GetObjectItem */ - struct cJSON *child; /* An array or object item will have a child pointer pointing to a chain of the items in the array/object. */ - - int32_t type; /* The type of the item, as above. */ - - char *valuestring; /* The item's string, if type==cJSON_String */ - int64_t valueint; /* The item's number, if type==cJSON_Number */ - double valuedouble; /* The item's number, if type==cJSON_Number */ - - char *string; /* The item's name string, if this item is the child of, or is in the list of subitems of an object. */ - } cJSON; - - typedef struct cJSON_Hooks { - void *(*malloc_fn)(size_t sz); - void (*free_fn)(void *ptr); - } cJSON_Hooks; - - /* Supply malloc, realloc and free functions to cJSON */ - extern void cJSON_InitHooks(cJSON_Hooks* hooks); - - - /* Supply a block of JSON, and this returns a cJSON object you can interrogate. Call cJSON_Delete when finished. */ - extern cJSON *cJSON_Parse(const char *value); - /* Render a cJSON entity to text for transfer/storage. Free the char* when finished. */ - extern char *cJSON_Print(cJSON *item); - /* Render a cJSON entity to text for transfer/storage without any formatting. Free the char* when finished. */ - extern char *cJSON_PrintUnformatted(cJSON *item); - /* Delete a cJSON entity and all subentities. */ - extern void cJSON_Delete(cJSON *c); - - /* Returns the number of items in an array (or object). */ - extern int cJSON_GetArraySize(cJSON *array); - /* Retrieve item number "item" from array "array". Returns NULL if unsuccessful. */ - extern cJSON *cJSON_GetArrayItem(cJSON *array,int32_t item); - /* Get item "string" from object. Case insensitive. */ - extern cJSON *cJSON_GetObjectItem(cJSON *object,const char *string); - - /* For analysing failed parses. This returns a pointer to the parse error. You'll probably need to look a few chars back to make sense of it. Defined when cJSON_Parse() returns 0. 0 when cJSON_Parse() succeeds. */ - extern const char *cJSON_GetErrorPtr(void); - - /* These calls create a cJSON item of the appropriate type. */ - extern cJSON *cJSON_CreateNull(void); - extern cJSON *cJSON_CreateTrue(void); - extern cJSON *cJSON_CreateFalse(void); - extern cJSON *cJSON_CreateBool(int32_t b); - extern cJSON *cJSON_CreateNumber(double num); - extern cJSON *cJSON_CreateString(const char *string); - extern cJSON *cJSON_CreateArray(void); - extern cJSON *cJSON_CreateObject(void); - - /* These utilities create an Array of count items. */ - extern cJSON *cJSON_CreateIntArray(int64_t *numbers,int32_t count); - extern cJSON *cJSON_CreateFloatArray(float *numbers,int32_t count); - extern cJSON *cJSON_CreateDoubleArray(double *numbers,int32_t count); - extern cJSON *cJSON_CreateStringArray(char **strings,int32_t count); - - /* Append item to the specified array/object. */ - extern void cJSON_AddItemToArray(cJSON *array, cJSON *item); - extern void cJSON_AddItemToObject(cJSON *object,const char *string,cJSON *item); - /* Append reference to item to the specified array/object. Use this when you want to add an existing cJSON to a new cJSON, but don't want to corrupt your existing cJSON. */ - extern void cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item); - extern void cJSON_AddItemReferenceToObject(cJSON *object,const char *string,cJSON *item); - - /* Remove/Detatch items from Arrays/Objects. */ - extern cJSON *cJSON_DetachItemFromArray(cJSON *array,int32_t which); - extern void cJSON_DeleteItemFromArray(cJSON *array,int32_t which); - extern cJSON *cJSON_DetachItemFromObject(cJSON *object,const char *string); - extern void cJSON_DeleteItemFromObject(cJSON *object,const char *string); - - /* Update array items. */ - extern void cJSON_ReplaceItemInArray(cJSON *array,int32_t which,cJSON *newitem); - extern void cJSON_ReplaceItemInObject(cJSON *object,const char *string,cJSON *newitem); - - /* Duplicate a cJSON item */ - extern cJSON *cJSON_Duplicate(cJSON *item,int32_t recurse); - /* Duplicate will create a new, identical cJSON item to the one you pass, in new memory that will - need to be released. With recurse!=0, it will duplicate any children connected to the item. - The item->next and ->prev pointers are always zero on return from Duplicate. */ - - /* ParseWithOpts allows you to require (and check) that the JSON is null terminated, and to retrieve the pointer to the final byte parsed. */ - extern cJSON *cJSON_ParseWithOpts(const char *value,const char **return_parse_end,int32_t require_null_terminated); - - extern void cJSON_Minify(char *json); - - /* Macros for creating things quickly. */ -#define cJSON_AddNullToObject(object,name) cJSON_AddItemToObject(object, name, cJSON_CreateNull()) -#define cJSON_AddTrueToObject(object,name) cJSON_AddItemToObject(object, name, cJSON_CreateTrue()) -#define cJSON_AddFalseToObject(object,name) cJSON_AddItemToObject(object, name, cJSON_CreateFalse()) -#define cJSON_AddBoolToObject(object,name,b) cJSON_AddItemToObject(object, name, cJSON_CreateBool(b)) -#define cJSON_AddNumberToObject(object,name,n) cJSON_AddItemToObject(object, name, cJSON_CreateNumber(n)) -#define cJSON_AddStringToObject(object,name,s) cJSON_AddItemToObject(object, name, cJSON_CreateString(s)) - - struct destbuf { char buf[MAX_JSON_FIELD]; }; - - /* When assigning an integer value, it needs to be propagated to valuedouble too. */ -#define cJSON_SetIntValue(object,val) ((object)?(object)->valueint=(object)->valuedouble=(val):(val)) -#define jfieldstr get_cJSON_fieldname - - char *cJSON_str(cJSON *json); - char *jstr(cJSON *json,char *field); - char *jprint(cJSON *json,int32_t freeflag); - int32_t jint(cJSON *json,char *field); - uint32_t juint(cJSON *json,char *field); - char *jstri(cJSON *json,int32_t i); - int32_t jinti(cJSON *json,int32_t i); - uint32_t juinti(cJSON *json,int32_t i); - uint64_t j64bitsi(cJSON *json,int32_t i); - double jdoublei(cJSON *json,int32_t i); - double jdouble(cJSON *json,char *field); - cJSON *jobj(cJSON *json,char *field); - cJSON *jarray(int32_t *nump,cJSON *json,char *field); - cJSON *jitem(cJSON *array,int32_t i); - uint64_t j64bits(cJSON *json,char *field); - void jadd(cJSON *json,char *field,cJSON *item); - void jaddstr(cJSON *json,char *field,char *str); - void jaddnum(cJSON *json,char *field,double num); - void jadd64bits(cJSON *json,char *field,uint64_t nxt64bits); - void jaddi(cJSON *json,cJSON *item); - void jaddistr(cJSON *json,char *str); - void jaddinum(cJSON *json,double num); - void jaddi64bits(cJSON *json,uint64_t nxt64bits); - void jdelete(cJSON *object,char *string); - cJSON *jduplicate(cJSON *json); - int32_t jnum(cJSON *obj,char *field); - - bits256 jbits256(cJSON *json,char *field); - bits256 jbits256i(cJSON *json,int32_t i); - void jaddbits256(cJSON *json,char *field,bits256 hash); - void jaddibits256(cJSON *json,bits256 hash); - void copy_cJSON(struct destbuf *dest,cJSON *obj); - void copy_cJSON2(char *dest,int32_t maxlen,cJSON *obj); - cJSON *gen_list_json(char **list); - int32_t extract_cJSON_str(char *dest,int32_t max,cJSON *json,char *field); +#define cJSON_StringIsConst 512 - void free_json(cJSON *json); - int64_t _conv_cJSON_float(cJSON *json); - int64_t conv_cJSON_float(cJSON *json,char *field); - int64_t get_cJSON_int(cJSON *json,char *field); - void add_satoshis_json(cJSON *json,char *field,uint64_t satoshis); - uint64_t get_satoshi_obj(cJSON *json,char *field); - - int32_t get_API_int(cJSON *obj,int32_t val); - uint32_t get_API_uint(cJSON *obj,uint32_t val); - uint64_t get_API_nxt64bits(cJSON *obj); - double get_API_float(cJSON *obj); - char *get_cJSON_fieldname(cJSON *obj); - void ensure_jsonitem(cJSON *json,char *field,char *value); - int32_t in_jsonarray(cJSON *array,char *value); - char *bitcoind_RPC(char **retstrp,char *debugstr,char *url,char *userpass,char *command,char *params); - uint64_t calc_nxt64bits(const char *str); - int32_t expand_nxt64bits(char *str,uint64_t nxt64bits); - char *nxt64str(uint64_t nxt64bits); - char *nxt64str2(uint64_t nxt64bits); - cJSON *addrs_jsonarray(uint64_t *addrs,int32_t num); - int32_t myatoi(char *str,int32_t range); +/* The cJSON structure: */ +typedef struct cJSON +{ + /* next/prev allow you to walk array/object chains. Alternatively, use GetArraySize/GetArrayItem/GetObjectItem */ + struct cJSON *next; + struct cJSON *prev; + /* An array or object item will have a child pointer pointing to a chain of the items in the array/object. */ + struct cJSON *child; - char *stringifyM(char *str); -#define replace_backslashquotes unstringify - char *unstringify(char *str); -#define jtrue cJSON_CreateTrue -#define jfalse cJSON_CreateFalse + /* The type of the item, as above. */ + int type; -#define jfieldname get_cJSON_fieldname + /* The item's string, if type==cJSON_String and type == cJSON_Raw */ + char *valuestring; + /* writing to valueint is DEPRECATED, use cJSON_SetNumberValue instead */ + int valueint; + /* The item's number, if type==cJSON_Number */ + double valuedouble; + + /* The item's name string, if this item is the child of, or is in the list of subitems of an object. */ + char *string; +} cJSON; + +typedef struct cJSON_Hooks +{ + void *(*malloc_fn)(size_t sz); + void (*free_fn)(void *ptr); +} cJSON_Hooks; + +typedef int cJSON_bool; + +#if !defined(__WINDOWS__) && (defined(WIN32) || defined(WIN64) || defined(_MSC_VER) || defined(_WIN32)) +#define __WINDOWS__ +#endif +#ifdef __WINDOWS__ + +/* When compiling for windows, we specify a specific calling convention to avoid issues where we are being called from a project with a different default calling convention. For windows you have 2 define options: + +CJSON_HIDE_SYMBOLS - Define this in the case where you don't want to ever dllexport symbols +CJSON_EXPORT_SYMBOLS - Define this on library build when you want to dllexport symbols (default) +CJSON_IMPORT_SYMBOLS - Define this if you want to dllimport symbol + +For *nix builds that support visibility attribute, you can define similar behavior by + +setting default visibility to hidden by adding +-fvisibility=hidden (for gcc) +or +-xldscope=hidden (for sun cc) +to CFLAGS + +then using the CJSON_API_VISIBILITY flag to "export" the same symbols the way CJSON_EXPORT_SYMBOLS does + +*/ + +/* export symbols by default, this is necessary for copy pasting the C and header file */ +#if !defined(CJSON_HIDE_SYMBOLS) && !defined(CJSON_IMPORT_SYMBOLS) && !defined(CJSON_EXPORT_SYMBOLS) +#define CJSON_EXPORT_SYMBOLS +#endif + +#if defined(CJSON_HIDE_SYMBOLS) +#define CJSON_PUBLIC(type) type __stdcall +#elif defined(CJSON_EXPORT_SYMBOLS) +#define CJSON_PUBLIC(type) __declspec(dllexport) type __stdcall +#elif defined(CJSON_IMPORT_SYMBOLS) +#define CJSON_PUBLIC(type) __declspec(dllimport) type __stdcall +#endif +#else /* !WIN32 */ +#if (defined(__GNUC__) || defined(__SUNPRO_CC) || defined (__SUNPRO_C)) && defined(CJSON_API_VISIBILITY) +#define CJSON_PUBLIC(type) __attribute__((visibility("default"))) type +#else +#define CJSON_PUBLIC(type) type +#endif +#endif + +/* Limits how deeply nested arrays/objects can be before cJSON rejects to parse them. + * This is to prevent stack overflows. */ +#ifndef CJSON_NESTING_LIMIT +#define CJSON_NESTING_LIMIT 1000 +#endif + +/* returns the version of cJSON as a string */ +CJSON_PUBLIC(const char*) cJSON_Version(void); + +/* Supply malloc, realloc and free functions to cJSON */ +CJSON_PUBLIC(void) cJSON_InitHooks(cJSON_Hooks* hooks); + +/* Memory Management: the caller is always responsible to free the results from all variants of cJSON_Parse (with cJSON_Delete) and cJSON_Print (with stdlib free, cJSON_Hooks.free_fn, or cJSON_free as appropriate). The exception is cJSON_PrintPreallocated, where the caller has full responsibility of the buffer. */ +/* Supply a block of JSON, and this returns a cJSON object you can interrogate. */ +CJSON_PUBLIC(cJSON *) cJSON_Parse(const char *value); +/* ParseWithOpts allows you to require (and check) that the JSON is null terminated, and to retrieve the pointer to the final byte parsed. */ +/* If you supply a ptr in return_parse_end and parsing fails, then return_parse_end will contain a pointer to the error so will match cJSON_GetErrorPtr(). */ +CJSON_PUBLIC(cJSON *) cJSON_ParseWithOpts(const char *value, const char **return_parse_end, cJSON_bool require_null_terminated); + +/* Render a cJSON entity to text for transfer/storage. */ +CJSON_PUBLIC(char *) cJSON_Print(const cJSON *item); +/* Render a cJSON entity to text for transfer/storage without any formatting. */ +CJSON_PUBLIC(char *) cJSON_PrintUnformatted(const cJSON *item); +/* Render a cJSON entity to text using a buffered strategy. prebuffer is a guess at the final size. guessing well reduces reallocation. fmt=0 gives unformatted, =1 gives formatted */ +CJSON_PUBLIC(char *) cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON_bool fmt); +/* Render a cJSON entity to text using a buffer already allocated in memory with given length. Returns 1 on success and 0 on failure. */ +/* NOTE: cJSON is not always 100% accurate in estimating how much memory it will use, so to be safe allocate 5 bytes more than you actually need */ +CJSON_PUBLIC(cJSON_bool) cJSON_PrintPreallocated(cJSON *item, char *buffer, const int length, const cJSON_bool format); +/* Delete a cJSON entity and all subentities. */ +CJSON_PUBLIC(void) cJSON_Delete(cJSON *c); + +/* Returns the number of items in an array (or object). */ +CJSON_PUBLIC(int) cJSON_GetArraySize(const cJSON *array); +/* Retrieve item number "item" from array "array". Returns NULL if unsuccessful. */ +CJSON_PUBLIC(cJSON *) cJSON_GetArrayItem(const cJSON *array, int index); +/* Get item "string" from object. Case insensitive. */ +CJSON_PUBLIC(cJSON *) cJSON_GetObjectItem(const cJSON * const object, const char * const string); +CJSON_PUBLIC(cJSON *) cJSON_GetObjectItemCaseSensitive(const cJSON * const object, const char * const string); +CJSON_PUBLIC(cJSON_bool) cJSON_HasObjectItem(const cJSON *object, const char *string); +/* For analysing failed parses. This returns a pointer to the parse error. You'll probably need to look a few chars back to make sense of it. Defined when cJSON_Parse() returns 0. 0 when cJSON_Parse() succeeds. */ +CJSON_PUBLIC(const char *) cJSON_GetErrorPtr(void); + +/* These functions check the type of an item */ +CJSON_PUBLIC(cJSON_bool) cJSON_IsInvalid(const cJSON * const item); +CJSON_PUBLIC(cJSON_bool) cJSON_IsFalse(const cJSON * const item); +CJSON_PUBLIC(cJSON_bool) cJSON_IsTrue(const cJSON * const item); +CJSON_PUBLIC(cJSON_bool) cJSON_IsBool(const cJSON * const item); +CJSON_PUBLIC(cJSON_bool) cJSON_IsNull(const cJSON * const item); +CJSON_PUBLIC(cJSON_bool) cJSON_IsNumber(const cJSON * const item); +CJSON_PUBLIC(cJSON_bool) cJSON_IsString(const cJSON * const item); +CJSON_PUBLIC(cJSON_bool) cJSON_IsArray(const cJSON * const item); +CJSON_PUBLIC(cJSON_bool) cJSON_IsObject(const cJSON * const item); +CJSON_PUBLIC(cJSON_bool) cJSON_IsRaw(const cJSON * const item); + +/* These calls create a cJSON item of the appropriate type. */ +CJSON_PUBLIC(cJSON *) cJSON_CreateNull(void); +CJSON_PUBLIC(cJSON *) cJSON_CreateTrue(void); +CJSON_PUBLIC(cJSON *) cJSON_CreateFalse(void); +CJSON_PUBLIC(cJSON *) cJSON_CreateBool(cJSON_bool boolean); +CJSON_PUBLIC(cJSON *) cJSON_CreateNumber(double num); +CJSON_PUBLIC(cJSON *) cJSON_CreateString(const char *string); +/* raw json */ +CJSON_PUBLIC(cJSON *) cJSON_CreateRaw(const char *raw); +CJSON_PUBLIC(cJSON *) cJSON_CreateArray(void); +CJSON_PUBLIC(cJSON *) cJSON_CreateObject(void); + +/* These utilities create an Array of count items. */ +CJSON_PUBLIC(cJSON *) cJSON_CreateIntArray(const int *numbers, int count); +CJSON_PUBLIC(cJSON *) cJSON_CreateFloatArray(const float *numbers, int count); +CJSON_PUBLIC(cJSON *) cJSON_CreateDoubleArray(const double *numbers, int count); +CJSON_PUBLIC(cJSON *) cJSON_CreateStringArray(const char **strings, int count); + +/* Append item to the specified array/object. */ +CJSON_PUBLIC(void) cJSON_AddItemToArray(cJSON *array, cJSON *item); +CJSON_PUBLIC(void) cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item); +/* Use this when string is definitely const (i.e. a literal, or as good as), and will definitely survive the cJSON object. + * WARNING: When this function was used, make sure to always check that (item->type & cJSON_StringIsConst) is zero before + * writing to `item->string` */ +CJSON_PUBLIC(void) cJSON_AddItemToObjectCS(cJSON *object, const char *string, cJSON *item); +/* Append reference to item to the specified array/object. Use this when you want to add an existing cJSON to a new cJSON, but don't want to corrupt your existing cJSON. */ +CJSON_PUBLIC(void) cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item); +CJSON_PUBLIC(void) cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *item); + +/* Remove/Detatch items from Arrays/Objects. */ +CJSON_PUBLIC(cJSON *) cJSON_DetachItemViaPointer(cJSON *parent, cJSON * const item); +CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromArray(cJSON *array, int which); +CJSON_PUBLIC(void) cJSON_DeleteItemFromArray(cJSON *array, int which); +CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObject(cJSON *object, const char *string); +CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObjectCaseSensitive(cJSON *object, const char *string); +CJSON_PUBLIC(void) cJSON_DeleteItemFromObject(cJSON *object, const char *string); +CJSON_PUBLIC(void) cJSON_DeleteItemFromObjectCaseSensitive(cJSON *object, const char *string); + +/* Update array items. */ +CJSON_PUBLIC(void) cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem); /* Shifts pre-existing items to the right. */ +CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON * const parent, cJSON * const item, cJSON * replacement); +CJSON_PUBLIC(void) cJSON_ReplaceItemInArray(cJSON *array, int which, cJSON *newitem); +CJSON_PUBLIC(void) cJSON_ReplaceItemInObject(cJSON *object,const char *string,cJSON *newitem); +CJSON_PUBLIC(void) cJSON_ReplaceItemInObjectCaseSensitive(cJSON *object,const char *string,cJSON *newitem); + +/* Duplicate a cJSON item */ +CJSON_PUBLIC(cJSON *) cJSON_Duplicate(const cJSON *item, cJSON_bool recurse); +/* Duplicate will create a new, identical cJSON item to the one you pass, in new memory that will +need to be released. With recurse!=0, it will duplicate any children connected to the item. +The item->next and ->prev pointers are always zero on return from Duplicate. */ +/* Recursively compare two cJSON items for equality. If either a or b is NULL or invalid, they will be considered unequal. + * case_sensitive determines if object keys are treated case sensitive (1) or case insensitive (0) */ +CJSON_PUBLIC(cJSON_bool) cJSON_Compare(const cJSON * const a, const cJSON * const b, const cJSON_bool case_sensitive); + + +CJSON_PUBLIC(void) cJSON_Minify(char *json); + +/* Macros for creating things quickly. */ +#define cJSON_AddNullToObject(object,name) cJSON_AddItemToObject(object, name, cJSON_CreateNull()) +#define cJSON_AddTrueToObject(object,name) cJSON_AddItemToObject(object, name, cJSON_CreateTrue()) +#define cJSON_AddFalseToObject(object,name) cJSON_AddItemToObject(object, name, cJSON_CreateFalse()) +#define cJSON_AddBoolToObject(object,name,b) cJSON_AddItemToObject(object, name, cJSON_CreateBool(b)) +#define cJSON_AddNumberToObject(object,name,n) cJSON_AddItemToObject(object, name, cJSON_CreateNumber(n)) +#define cJSON_AddStringToObject(object,name,s) cJSON_AddItemToObject(object, name, cJSON_CreateString(s)) +#define cJSON_AddRawToObject(object,name,s) cJSON_AddItemToObject(object, name, cJSON_CreateRaw(s)) + +/* When assigning an integer value, it needs to be propagated to valuedouble too. */ +#define cJSON_SetIntValue(object, number) ((object) ? (object)->valueint = (object)->valuedouble = (number) : (number)) +/* helper for the cJSON_SetNumberValue macro */ +CJSON_PUBLIC(double) cJSON_SetNumberHelper(cJSON *object, double number); +#define cJSON_SetNumberValue(object, number) ((object != NULL) ? cJSON_SetNumberHelper(object, (double)number) : (number)) + +/* Macro for iterating over an array or object */ +#define cJSON_ArrayForEach(element, array) for(element = (array != NULL) ? (array)->child : NULL; element != NULL; element = element->next) + +/* malloc/free objects using the malloc/free functions that have been set with cJSON_InitHooks */ +CJSON_PUBLIC(void *) cJSON_malloc(size_t size); +CJSON_PUBLIC(void) cJSON_free(void *object); #ifdef __cplusplus } diff --git a/src/komodo.h b/src/komodo.h index 2eb0aa21f..185bfa347 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -42,7 +42,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block); #include "komodo_utils.h" #include "komodo_curve25519.h" -#include "cJSON.c" +#include "komodo_cJSON.c" #include "komodo_bitcoind.h" #include "komodo_interest.h" #include "komodo_pax.h" diff --git a/src/komodo_cJSON.c b/src/komodo_cJSON.c new file mode 100755 index 000000000..ca2c6517c --- /dev/null +++ b/src/komodo_cJSON.c @@ -0,0 +1,559 @@ + +/* + Copyright (c) 2009 Dave Gamble + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + */ + +/* cJSON */ +/* JSON parser in C. */ +#include + +#include "cJSON.h" +#include "komodo_cJSON.h" +#include "cJSON.c" + +#ifndef DBL_EPSILON +#define DBL_EPSILON 2.2204460492503131E-16 +#endif + +static const char *ep; + +long stripquotes(char *str) +{ + long len,offset; + if ( str == 0 ) + return(0); + len = strlen(str); + if ( str[0] == '"' && str[len-1] == '"' ) + str[len-1] = 0, offset = 1; + else offset = 0; + return(offset); +} + +static int32_t cJSON_strcasecmp(const char *s1,const char *s2) +{ + if (!s1) return (s1==s2)?0:1;if (!s2) return 1; + for(; tolower((int32_t)(*s1)) == tolower((int32_t)(*s2)); ++s1, ++s2) if(*s1 == 0) return 0; + return tolower((int32_t)(*(const unsigned char *)s1)) - tolower((int32_t)(*(const unsigned char *)s2)); +} + +// the following written by jl777 +/****************************************************************************** + * Copyright © 2014-2017 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + +void copy_cJSON(struct destbuf *dest,cJSON *obj) +{ + char *str; + int i; + long offset; + dest->buf[0] = 0; + if ( obj != 0 ) + { + str = cJSON_Print(obj); + if ( str != 0 ) + { + offset = stripquotes(str); + //strcpy(dest,str+offset); + for (i=0; ibuf[i]= str[offset+i]) == 0 ) + break; + dest->buf[i] = 0; + free(str); + } + } +} + +void copy_cJSON2(char *dest,int32_t maxlen,cJSON *obj) +{ + struct destbuf tmp; + maxlen--; + dest[0] = 0; + if ( maxlen > sizeof(tmp.buf) ) + maxlen = sizeof(tmp.buf); + copy_cJSON(&tmp,obj); + if ( strlen(tmp.buf) < maxlen ) + strcpy(dest,tmp.buf); + else dest[0] = 0; +} + +int64_t _get_cJSON_int(cJSON *json) +{ + struct destbuf tmp; + if ( json != 0 ) + { + copy_cJSON(&tmp,json); + if ( tmp.buf[0] != 0 ) + return(calc_nxt64bits(tmp.buf)); + } + return(0); +} + +int64_t get_cJSON_int(cJSON *json,char *field) +{ + cJSON *numjson; + if ( json != 0 ) + { + numjson = cJSON_GetObjectItem(json,field); + if ( numjson != 0 ) + return(_get_cJSON_int(numjson)); + } + return(0); +} + +int64_t conv_floatstr(char *numstr) +{ + double val,corr; + val = atof(numstr); + corr = (val < 0.) ? -0.50000000001 : 0.50000000001; + return((int64_t)(val * SATOSHIDEN + corr)); +} + +int64_t _conv_cJSON_float(cJSON *json) +{ + int64_t conv_floatstr(char *); + struct destbuf tmp; + if ( json != 0 ) + { + copy_cJSON(&tmp,json); + return(conv_floatstr(tmp.buf)); + } + return(0); +} + +int64_t conv_cJSON_float(cJSON *json,char *field) +{ + if ( json != 0 ) + return(_conv_cJSON_float(cJSON_GetObjectItem(json,field))); + return(0); +} + +int32_t extract_cJSON_str(char *dest,int32_t max,cJSON *json,char *field) +{ + int32_t safecopy(char *dest,char *src,long len); + char *str; + cJSON *obj; + int32_t len; + long offset; + dest[0] = 0; + obj = cJSON_GetObjectItem(json,field); + if ( obj != 0 ) + { + str = cJSON_Print(obj); + offset = stripquotes(str); + len = safecopy(dest,str+offset,max); + free(str); + return(len); + } + return(0); +} + +cJSON *gen_list_json(char **list) +{ + cJSON *array,*item; + array = cJSON_CreateArray(); + while ( list != 0 && *list != 0 && *list[0] != 0 ) + { + item = cJSON_CreateString(*list++); + cJSON_AddItemToArray(array,item); + } + return(array); +} + +uint64_t get_API_nxt64bits(cJSON *obj) +{ + uint64_t nxt64bits = 0; + struct destbuf tmp; + if ( obj != 0 ) + { + if ( cJSON_IsNumber(obj) != 0 ) + return((uint64_t)obj->valuedouble); + copy_cJSON(&tmp,obj); + nxt64bits = calc_nxt64bits(tmp.buf); + } + return(nxt64bits); +} +uint64_t j64bits(cJSON *json,char *field) { if ( field == 0 ) return(get_API_nxt64bits(json)); return(get_API_nxt64bits(cJSON_GetObjectItem(json,field))); } +uint64_t j64bitsi(cJSON *json,int32_t i) { return(get_API_nxt64bits(cJSON_GetArrayItem(json,i))); } + +uint64_t get_satoshi_obj(cJSON *json,char *field) +{ + int32_t i,n; + uint64_t prev,satoshis,mult = 1; + struct destbuf numstr,checkstr; + cJSON *numjson; + numjson = cJSON_GetObjectItem(json,field); + copy_cJSON(&numstr,numjson); + satoshis = prev = 0; mult = 1; n = (int32_t)strlen(numstr.buf); + for (i=n-1; i>=0; i--,mult*=10) + { + satoshis += (mult * (numstr.buf[i] - '0')); + if ( satoshis < prev ) + printf("get_satoshi_obj numstr.(%s) i.%d prev.%llu vs satoshis.%llu\n",numstr.buf,i,(unsigned long long)prev,(unsigned long long)satoshis); + prev = satoshis; + } + sprintf(checkstr.buf,"%llu",(long long)satoshis); + if ( strcmp(checkstr.buf,numstr.buf) != 0 ) + { + printf("SATOSHI GREMLIN?? numstr.(%s) -> %.8f -> (%s)\n",numstr.buf,dstr(satoshis),checkstr.buf); + } + return(satoshis); +} + +void add_satoshis_json(cJSON *json,char *field,uint64_t satoshis) +{ + cJSON *obj; + char numstr[64]; + sprintf(numstr,"%lld",(long long)satoshis); + obj = cJSON_CreateString(numstr); + cJSON_AddItemToObject(json,field,obj); + if ( satoshis != get_satoshi_obj(json,field) ) + printf("error adding satoshi obj %ld -> %ld\n",(unsigned long)satoshis,(unsigned long)get_satoshi_obj(json,field)); +} + +char *cJSON_str(cJSON *json) +{ + if ( json != 0 && cJSON_IsString(json) != 0 ) + return(json->valuestring); + return(0); +} + +void jadd(cJSON *json,char *field,cJSON *item) { if ( json != 0 )cJSON_AddItemToObject(json,field,item); } +void jaddstr(cJSON *json,char *field,char *str) { if ( json != 0 && str != 0 ) cJSON_AddItemToObject(json,field,cJSON_CreateString(str)); } +void jaddnum(cJSON *json,char *field,double num) { if ( json != 0 )cJSON_AddItemToObject(json,field,cJSON_CreateNumber(num)); } +void jadd64bits(cJSON *json,char *field,uint64_t nxt64bits) { char numstr[64]; sprintf(numstr,"%llu",(long long)nxt64bits), jaddstr(json,field,numstr); } +void jaddi(cJSON *json,cJSON *item) { if ( json != 0 ) cJSON_AddItemToArray(json,item); } +void jaddistr(cJSON *json,char *str) { if ( json != 0 ) cJSON_AddItemToArray(json,cJSON_CreateString(str)); } +void jaddinum(cJSON *json,double num) { if ( json != 0 ) cJSON_AddItemToArray(json,cJSON_CreateNumber(num)); } +void jaddi64bits(cJSON *json,uint64_t nxt64bits) { char numstr[64]; sprintf(numstr,"%llu",(long long)nxt64bits), jaddistr(json,numstr); } +char *jstr(cJSON *json,char *field) { if ( json == 0 ) return(0); if ( field == 0 ) return(cJSON_str(json)); return(cJSON_str(cJSON_GetObjectItem(json,field))); } + +char *jstri(cJSON *json,int32_t i) { return(cJSON_str(cJSON_GetArrayItem(json,i))); } +char *jprint(cJSON *json,int32_t freeflag) +{ + char *str; + /*static portable_mutex_t mutex; static int32_t initflag; + if ( initflag == 0 ) + { + portable_mutex_init(&mutex); + initflag = 1; + }*/ + if ( json == 0 ) + return(clonestr((char *)"{}")); + //portable_mutex_lock(&mutex); + //usleep(5000); + str = cJSON_Print(json), _stripwhite(str,' '); + if ( freeflag != 0 ) + free_json(json); + //portable_mutex_unlock(&mutex); + return(str); +} + +bits256 get_API_bits256(cJSON *obj) +{ + bits256 hash; char *str; + memset(hash.bytes,0,sizeof(hash)); + if ( obj != 0 ) + { + if ( cJSON_IsString(obj) != 0 && (str= obj->valuestring) != 0 && strlen(str) == 64 ) + decode_hex(hash.bytes,sizeof(hash),str); + } + return(hash); +} +bits256 jbits256(cJSON *json,char *field) { if ( field == 0 ) return(get_API_bits256(json)); return(get_API_bits256(cJSON_GetObjectItem(json,field))); } +bits256 jbits256i(cJSON *json,int32_t i) { return(get_API_bits256(cJSON_GetArrayItem(json,i))); } +void jaddbits256(cJSON *json,char *field,bits256 hash) { char str[65]; bits256_str(str,hash), jaddstr(json,field,str); } +void jaddibits256(cJSON *json,bits256 hash) { char str[65]; bits256_str(str,hash), jaddistr(json,str); } + +char *get_cJSON_fieldname(cJSON *obj) +{ + if ( obj != 0 ) + { + if ( obj->child != 0 && obj->child->string != 0 ) + return(obj->child->string); + else if ( obj->string != 0 ) + return(obj->string); + } + return((char *)""); +} + +int32_t jnum(cJSON *obj,char *field) +{ + char *str; int32_t polarity = 1; + if ( field != 0 ) + obj = jobj(obj,field); + if ( obj != 0 ) + { + if ( cJSON_IsNumber(obj) != 0 ) + return(obj->valuedouble); + else if ( cJSON_IsString(obj) != 0 && (str= jstr(obj,0)) != 0 ) + { + if ( str[0] == '-' ) + polarity = -1, str++; + return(polarity * (int32_t)calc_nxt64bits(str)); + } + } + return(0); +} + +void ensure_jsonitem(cJSON *json,char *field,char *value) +{ + cJSON *obj = cJSON_GetObjectItem(json,field); + if ( obj == 0 ) + cJSON_AddItemToObject(json,field,cJSON_CreateString(value)); + else cJSON_ReplaceItemInObject(json,field,cJSON_CreateString(value)); +} + +int32_t in_jsonarray(cJSON *array,char *value) +{ + int32_t i,n; + struct destbuf remote; + if ( array != 0 && cJSON_IsArray(array) != 0 ) + { + n = cJSON_GetArraySize(array); + for (i=0; i= range ) + x = (range - 1); + return((int32_t)x); +} + +int32_t get_API_int(cJSON *obj,int32_t val) +{ + struct destbuf buf; + if ( obj != 0 ) + { + if ( cJSON_IsNumber(obj) != 0 ) + return((int32_t)obj->valuedouble); + copy_cJSON(&buf,obj); + val = myatoi(buf.buf,0); + if ( val < 0 ) + val = 0; + } + return(val); +} + +int32_t jint(cJSON *json,char *field) { if ( json == 0 ) return(0); if ( field == 0 ) return(get_API_int(json,0)); return(get_API_int(cJSON_GetObjectItem(json,field),0)); } +int32_t jinti(cJSON *json,int32_t i) { if ( json == 0 ) return(0); return(get_API_int(cJSON_GetArrayItem(json,i),0)); } + +uint32_t get_API_uint(cJSON *obj,uint32_t val) +{ + struct destbuf buf; + if ( obj != 0 ) + { + if ( cJSON_IsNumber(obj) != 0 ) + return((uint32_t)obj->valuedouble); + copy_cJSON(&buf,obj); + val = myatoi(buf.buf,0); + } + return(val); +} +uint32_t juint(cJSON *json,char *field) { if ( json == 0 ) return(0); if ( field == 0 ) return(get_API_uint(json,0)); return(get_API_uint(cJSON_GetObjectItem(json,field),0)); } +uint32_t juinti(cJSON *json,int32_t i) { if ( json == 0 ) return(0); return(get_API_uint(cJSON_GetArrayItem(json,i),0)); } + +double get_API_float(cJSON *obj) +{ + double val = 0.; + struct destbuf buf; + if ( obj != 0 ) + { + if ( cJSON_IsNumber(obj) != 0 ) + return(obj->valuedouble); + copy_cJSON(&buf,obj); + val = atof(buf.buf); + } + return(val); +} + +double jdouble(cJSON *json,char *field) +{ + if ( json != 0 ) + { + if ( field == 0 ) + return(get_API_float(json)); + else return(get_API_float(cJSON_GetObjectItem(json,field))); + } else return(0.); +} + +double jdoublei(cJSON *json,int32_t i) +{ + if ( json != 0 ) + return(get_API_float(cJSON_GetArrayItem(json,i))); + else return(0.); +} + +cJSON *jobj(cJSON *json,char *field) { if ( json != 0 ) return(cJSON_GetObjectItem(json,field)); return(0); } + +void jdelete(cJSON *json,char *field) +{ + if ( jobj(json,field) != 0 ) + cJSON_DeleteItemFromObject(json,field); +} + +cJSON *jduplicate(cJSON *json) { return(cJSON_Duplicate(json,1)); } + +cJSON *jitem(cJSON *array,int32_t i) { if ( array != 0 && cJSON_IsArray(array) != 0 && cJSON_GetArraySize(array) > i ) return(cJSON_GetArrayItem(array,i)); return(0); } +cJSON *jarray(int32_t *nump,cJSON *json,char *field) +{ + cJSON *array; + if ( json != 0 ) + { + if ( field == 0 ) + array = json; + else array = cJSON_GetObjectItem(json,field); + if ( array != 0 && cJSON_IsArray(array) != 0 && (*nump= cJSON_GetArraySize(array)) > 0 ) + return(array); + } + *nump = 0; + return(0); +} + +int32_t expand_nxt64bits(char *NXTaddr,uint64_t nxt64bits) +{ + int32_t i,n; + uint64_t modval; + char rev[64]; + for (i=0; nxt64bits!=0; i++) + { + modval = nxt64bits % 10; + rev[i] = (char)(modval + '0'); + nxt64bits /= 10; + } + n = i; + for (i=0; i= 22 ) + { + printf("calc_nxt64bits: illegal NXTaddr.(%s) too long\n",NXTaddr); + return(0); + } + else if ( strcmp(NXTaddr,"0") == 0 || strcmp(NXTaddr,"false") == 0 ) + { + // printf("zero address?\n"); getchar(); + return(0); + } + if ( NXTaddr[0] == '-' ) + polarity = -1, NXTaddr++, n--; + mult = 1; + lastval = 0; + for (i=n-1; i>=0; i--,mult*=10) + { + c = NXTaddr[i]; + if ( c < '0' || c > '9' ) + { + printf("calc_nxt64bits: illegal char.(%c %d) in (%s).%d\n",c,c,NXTaddr,(int32_t)i); +#ifdef __APPLE__ + //while ( 1 ) + { + //sleep(60); + printf("calc_nxt64bits: illegal char.(%c %d) in (%s).%d\n",c,c,NXTaddr,(int32_t)i); + } +#endif + return(0); + } + nxt64bits += mult * (c - '0'); + if ( nxt64bits < lastval ) + printf("calc_nxt64bits: warning: 64bit overflow %llx < %llx\n",(long long)nxt64bits,(long long)lastval); + lastval = nxt64bits; + } + while ( *NXTaddr == '0' && *NXTaddr != 0 ) + NXTaddr++; + if ( cmp_nxt64bits(NXTaddr,nxt64bits) != 0 ) + printf("error calculating nxt64bits: %s -> %llx -> %s\n",NXTaddr,(long long)nxt64bits,nxt64str(nxt64bits)); + if ( polarity < 0 ) + return(-(int64_t)nxt64bits); + return(nxt64bits); +} + +cJSON *addrs_jsonarray(uint64_t *addrs,int32_t num) +{ + int32_t j; cJSON *array; + array = cJSON_CreateArray(); + for (j=0; j +#include +#include +#include +#include +#include +#include + +#include "cJSON.h" + +//#include "../crypto777/OS_portable.h" + +#define MAX_JSON_FIELD 4096 // on the big side + +#ifdef __cplusplus +extern "C" +{ +#endif + + /* Macros for creating things quickly. */ +#define cJSON_AddNullToObject(object,name) cJSON_AddItemToObject(object, name, cJSON_CreateNull()) +#define cJSON_AddTrueToObject(object,name) cJSON_AddItemToObject(object, name, cJSON_CreateTrue()) +#define cJSON_AddFalseToObject(object,name) cJSON_AddItemToObject(object, name, cJSON_CreateFalse()) +#define cJSON_AddBoolToObject(object,name,b) cJSON_AddItemToObject(object, name, cJSON_CreateBool(b)) +#define cJSON_AddNumberToObject(object,name,n) cJSON_AddItemToObject(object, name, cJSON_CreateNumber(n)) +#define cJSON_AddStringToObject(object,name,s) cJSON_AddItemToObject(object, name, cJSON_CreateString(s)) + + struct destbuf { char buf[MAX_JSON_FIELD]; }; + +#define jfieldstr get_cJSON_fieldname + + char *cJSON_str(cJSON *json); + char *jstr(cJSON *json,char *field); + char *jprint(cJSON *json,int32_t freeflag); + int32_t jint(cJSON *json,char *field); + uint32_t juint(cJSON *json,char *field); + char *jstri(cJSON *json,int32_t i); + int32_t jinti(cJSON *json,int32_t i); + uint32_t juinti(cJSON *json,int32_t i); + uint64_t j64bitsi(cJSON *json,int32_t i); + double jdoublei(cJSON *json,int32_t i); + double jdouble(cJSON *json,char *field); + cJSON *jobj(cJSON *json,char *field); + cJSON *jarray(int32_t *nump,cJSON *json,char *field); + cJSON *jitem(cJSON *array,int32_t i); + uint64_t j64bits(cJSON *json,char *field); + void jadd(cJSON *json,char *field,cJSON *item); + void jaddstr(cJSON *json,char *field,char *str); + void jaddnum(cJSON *json,char *field,double num); + void jadd64bits(cJSON *json,char *field,uint64_t nxt64bits); + void jaddi(cJSON *json,cJSON *item); + void jaddistr(cJSON *json,char *str); + void jaddinum(cJSON *json,double num); + void jaddi64bits(cJSON *json,uint64_t nxt64bits); + void jdelete(cJSON *object,char *string); + cJSON *jduplicate(cJSON *json); + int32_t jnum(cJSON *obj,char *field); + + bits256 jbits256(cJSON *json,char *field); + bits256 jbits256i(cJSON *json,int32_t i); + void jaddbits256(cJSON *json,char *field,bits256 hash); + void jaddibits256(cJSON *json,bits256 hash); + void copy_cJSON(struct destbuf *dest,cJSON *obj); + void copy_cJSON2(char *dest,int32_t maxlen,cJSON *obj); + cJSON *gen_list_json(char **list); + int32_t extract_cJSON_str(char *dest,int32_t max,cJSON *json,char *field); + + void free_json(cJSON *json); + int64_t _conv_cJSON_float(cJSON *json); + int64_t conv_cJSON_float(cJSON *json,char *field); + int64_t get_cJSON_int(cJSON *json,char *field); + void add_satoshis_json(cJSON *json,char *field,uint64_t satoshis); + uint64_t get_satoshi_obj(cJSON *json,char *field); + + int32_t get_API_int(cJSON *obj,int32_t val); + uint32_t get_API_uint(cJSON *obj,uint32_t val); + uint64_t get_API_nxt64bits(cJSON *obj); + double get_API_float(cJSON *obj); + char *get_cJSON_fieldname(cJSON *obj); + void ensure_jsonitem(cJSON *json,char *field,char *value); + int32_t in_jsonarray(cJSON *array,char *value); + char *bitcoind_RPC(char **retstrp,char *debugstr,char *url,char *userpass,char *command,char *params); + uint64_t calc_nxt64bits(const char *str); + int32_t expand_nxt64bits(char *str,uint64_t nxt64bits); + char *nxt64str(uint64_t nxt64bits); + char *nxt64str2(uint64_t nxt64bits); + cJSON *addrs_jsonarray(uint64_t *addrs,int32_t num); + int32_t myatoi(char *str,int32_t range); + + char *stringifyM(char *str); +#define replace_backslashquotes unstringify + char *unstringify(char *str); +#define jtrue cJSON_CreateTrue +#define jfalse cJSON_CreateFalse + +#define jfieldname get_cJSON_fieldname + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/komodo_jumblr.h b/src/komodo_jumblr.h index f0bfecc9c..baafc6dbe 100755 --- a/src/komodo_jumblr.h +++ b/src/komodo_jumblr.h @@ -141,7 +141,7 @@ int32_t Jumblr_depositaddradd(char *depositaddr) // external { if ( (retjson= cJSON_Parse(retstr)) != 0 ) { - if ( (ismine= jobj(retjson,(char *)"ismine")) != 0 && is_cJSON_True(ismine) != 0 ) + if ( (ismine= jobj(retjson,(char *)"ismine")) != 0 && cJSON_IsTrue(ismine) != 0 ) { retval = 0; safecopy(Jumblr_deposit,depositaddr,sizeof(Jumblr_deposit)); @@ -149,7 +149,7 @@ int32_t Jumblr_depositaddradd(char *depositaddr) // external else { retval = JUMBLR_ERROR_NOTINWALLET; - printf("%s not in wallet: ismine.%p %d %s\n",depositaddr,ismine,is_cJSON_True(ismine),jprint(retjson,0)); + printf("%s not in wallet: ismine.%p %d %s\n",depositaddr,ismine,cJSON_IsTrue(ismine),jprint(retjson,0)); } free_json(retjson); } @@ -366,7 +366,7 @@ int64_t jumblr_balance(char *addr) //printf("jumblr.[%s].(%s)\n","KMD",retstr); if ( (retjson= cJSON_Parse(retstr)) != 0 ) { - if ( (n= cJSON_GetArraySize(retjson)) > 0 && is_cJSON_Array(retjson) != 0 ) + if ( (n= cJSON_GetArraySize(retjson)) > 0 && cJSON_IsArray(retjson) != 0 ) for (i=0; i 0 && is_cJSON_Array(array) != 0 ) + if ( (n= cJSON_GetArraySize(array)) > 0 && cJSON_IsArray(array) != 0 ) { //printf("%s -> n%d\n",retstr,n); for (i=0; i 0 && is_cJSON_Array(array) != 0 ) + if ( (n= cJSON_GetArraySize(array)) > 0 && cJSON_IsArray(array) != 0 ) { for (i=0; i Date: Tue, 24 Oct 2017 05:27:21 +0200 Subject: [PATCH 056/188] 333 --- depends/packages/libcurl.mk | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/depends/packages/libcurl.mk b/depends/packages/libcurl.mk index 349469f11..642fc066d 100644 --- a/depends/packages/libcurl.mk +++ b/depends/packages/libcurl.mk @@ -13,11 +13,12 @@ ifeq ($(build_os),darwin) define $(package)_set_vars $(package)_build_env=MACOSX_DEPLOYMENT_TARGET="10.9" endef -else +endif + define $(package)_config_cmds $($(package)_conf_tool) $($(package)_config_opts) endef -endif + ifeq ($(build_os),darwin) define $(package)_build_cmds From 9e8cfd58a93b24ef20ad4ed00bbffef6f04465cc Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 24 Oct 2017 13:24:02 +0300 Subject: [PATCH 057/188] Undefine cJSON bools --- src/cJSON.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cJSON.c b/src/cJSON.c index 5b58f2ffc..b67ca698d 100644 --- a/src/cJSON.c +++ b/src/cJSON.c @@ -43,8 +43,8 @@ #include "cJSON.h" /* define our own boolean type */ -#define true ((cJSON_bool)1) -#define false ((cJSON_bool)0) +//#define true ((cJSON_bool)1) +//#define false ((cJSON_bool)0) typedef struct { const unsigned char *json; From 2c1ea2350a6905f2aec22931c7d04cb2e2d586e6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 26 Oct 2017 15:51:25 +0300 Subject: [PATCH 058/188] Remove print --- src/komodo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index 185bfa347..c5057646f 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -407,7 +407,7 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr komodo_stateupdate(height,0,0,0,zero,0,0,0,0,0,0,0,0,0,0); len += 4; if ( ASSETCHAINS_SYMBOL[0] != 0 ) - printf("[%s] ht.%d NOTARIZED.%d %s.%s %sTXID.%s (%s) lens.(%d %d)\n",ASSETCHAINS_SYMBOL,height,*notarizedheightp,ASSETCHAINS_SYMBOL[0]==0?"KMD":ASSETCHAINS_SYMBOL,kmdtxid.ToString().c_str(),ASSETCHAINS_SYMBOL[0]==0?"BTC":"KMD",desttxid.ToString().c_str(),(char *)&scriptbuf[len],opretlen,len); + printf("[%s] ht.%d NOTARIZED.%d %s.%s %sTXID.%s lens.(%d %d)\n",ASSETCHAINS_SYMBOL,height,*notarizedheightp,ASSETCHAINS_SYMBOL[0]==0?"KMD":ASSETCHAINS_SYMBOL,kmdtxid.ToString().c_str(),ASSETCHAINS_SYMBOL[0]==0?"BTC":"KMD",desttxid.ToString().c_str(),opretlen,len); if ( ASSETCHAINS_SYMBOL[0] == 0 ) { if ( signedfp == 0 ) From 31e342b831a486fa3b5fbb1f52ca7c87a166eadf Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 30 Oct 2017 21:03:20 +0200 Subject: [PATCH 059/188] Notarize CHIPS --- src/dpowassets | 1 + src/komodo_interest.h | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/dpowassets b/src/dpowassets index fde738e44..5e0facea0 100755 --- a/src/dpowassets +++ b/src/dpowassets @@ -23,6 +23,7 @@ curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dp curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"CEAL\",\"pubkey\":\"$pubkey\"}" curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"MESH\",\"pubkey\":\"$pubkey\"}" curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"MNZ\",\"pubkey\":\"$pubkey\"}" +curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"CHIPS\",\"pubkey\":\"$pubkey\"}" #curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"USD\",\"pubkey\":\"$pubkey\"}" diff --git a/src/komodo_interest.h b/src/komodo_interest.h index 1795a64bf..c5a35492d 100644 --- a/src/komodo_interest.h +++ b/src/komodo_interest.h @@ -90,7 +90,7 @@ uint64_t _komodo_interestnew(uint64_t nValue,uint32_t nLockTime,uint32_t tiptime uint64_t komodo_interestnew(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uint32_t tiptime) { uint64_t interest = 0; - if ( komodo_moneysupply(txheight) < MAX_MONEY && nLockTime >= LOCKTIME_THRESHOLD && tiptime != 0 && nLockTime < tiptime && nValue >= 10*COIN ) + if ( txheight < 7777777 && komodo_moneysupply(txheight) < MAX_MONEY && nLockTime >= LOCKTIME_THRESHOLD && tiptime != 0 && nLockTime < tiptime && nValue >= 10*COIN ) interest = _komodo_interestnew(nValue,nLockTime,tiptime); return(interest); } @@ -101,6 +101,8 @@ uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uin activation = 1491350400; // 1491350400 5th April if ( ASSETCHAINS_SYMBOL[0] != 0 ) return(0); + if ( txheight >= 7777777 ) + return(0); if ( komodo_moneysupply(txheight) < MAX_MONEY && nLockTime >= LOCKTIME_THRESHOLD && tiptime != 0 && nLockTime < tiptime && nValue >= 10*COIN ) { if ( (minutes= (tiptime - nLockTime) / 60) >= 60 ) From eeaec53966634f55a44ec48ad08cb9691d8bb499 Mon Sep 17 00:00:00 2001 From: ca333 Date: Tue, 31 Oct 2017 01:43:52 +0100 Subject: [PATCH 060/188] update travis config --- .travis.yml | 94 +++++++++++++---------------------------------------- 1 file changed, 22 insertions(+), 72 deletions(-) diff --git a/.travis.yml b/.travis.yml index 662ac5681..250756396 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,73 +1,23 @@ -# errata: -# - A travis bug causes caches to trample eachother when using the same -# compiler key (which we don't use anyway). This is worked around for now by -# replacing the "compilers" with a build name prefixed by the no-op ":" -# command. See: https://github.com/travis-ci/casher/issues/6 - -os: linux language: cpp -compiler: gcc -env: - global: - - MAKEJOBS=-j3 - - RUN_TESTS=false - - BOOST_TEST_RANDOM=1$TRAVIS_BUILD_ID - - CCACHE_SIZE=100M - - CCACHE_TEMPDIR=/tmp/.ccache-temp - - CCACHE_COMPRESS=1 - - BASE_OUTDIR=$TRAVIS_BUILD_DIR/out - - SDK_URL=https://bitcoincore.org/depends-sources/sdks - - PYTHON_DEBUG=1 - - WINEDEBUG=fixme-all -cache: - apt: true - directories: - - depends/built - - depends/sdk-sources - - $HOME/.ccache -matrix: - fast_finish: true - include: - - compiler: ": ARM" - env: HOST=arm-linux-gnueabihf PACKAGES="g++-arm-linux-gnueabihf" DEP_OPTS="NO_QT=1" GOAL="install" BITCOIN_CONFIG="--enable-glibc-back-compat --enable-reduce-exports" - - compiler: ": Win32" - env: HOST=i686-w64-mingw32 PACKAGES="nsis gcc-mingw-w64-i686 g++-mingw-w64-i686 binutils-mingw-w64-i686 mingw-w64-dev wine bc" RUN_TESTS=true GOAL="deploy" BITCOIN_CONFIG="--enable-reduce-exports" MAKEJOBS="-j2" - - compiler: ": 32-bit + dash" - env: HOST=i686-pc-linux-gnu PACKAGES="g++-multilib bc python-zmq" PPA="ppa:chris-lea/zeromq" RUN_TESTS=true GOAL="install" BITCOIN_CONFIG="--enable-zmq --enable-glibc-back-compat --enable-reduce-exports LDFLAGS=-static-libstdc++" USE_SHELL="/bin/dash" - - compiler: ": Win64" - env: HOST=x86_64-w64-mingw32 PACKAGES="nsis gcc-mingw-w64-x86-64 g++-mingw-w64-x86-64 binutils-mingw-w64-x86-64 mingw-w64-dev wine bc" RUN_TESTS=true GOAL="deploy" BITCOIN_CONFIG="--enable-reduce-exports" MAKEJOBS="-j2" - - compiler: ": bitcoind" - env: HOST=x86_64-unknown-linux-gnu PACKAGES="bc python-zmq" PPA="ppa:chris-lea/zeromq" DEP_OPTS="NO_QT=1 NO_UPNP=1 DEBUG=1" RUN_TESTS=true GOAL="install" BITCOIN_CONFIG="--enable-zmq --enable-glibc-back-compat --enable-reduce-exports CPPFLAGS=-DDEBUG_LOCKORDER" - - compiler: ": No wallet" - env: HOST=x86_64-unknown-linux-gnu DEP_OPTS="NO_WALLET=1" RUN_TESTS=true GOAL="install" BITCOIN_CONFIG="--enable-glibc-back-compat --enable-reduce-exports" - - compiler: ": Cross-Mac" - env: HOST=x86_64-apple-darwin11 PACKAGES="cmake libcap-dev libz-dev libbz2-dev" BITCOIN_CONFIG="--enable-reduce-exports" OSX_SDK=10.9 GOAL="deploy" - exclude: - - compiler: gcc -install: - - if [ -n "$PACKAGES" ]; then sudo rm -f /etc/apt/sources.list.d/travis_ci_zeromq3-source.list; fi - - if [ -n "$PACKAGES" ]; then travis_retry sudo apt-get update; fi - - if [ -n "$PACKAGES" ]; then travis_retry sudo apt-get install --no-install-recommends --no-upgrade -qq $PACKAGES; fi -before_script: - - unset CC; unset CXX - - mkdir -p depends/SDKs depends/sdk-sources - - if [ -n "$OSX_SDK" -a ! -f depends/sdk-sources/MacOSX${OSX_SDK}.sdk.tar.gz ]; then wget $SDK_URL/MacOSX${OSX_SDK}.sdk.tar.gz -O depends/sdk-sources/MacOSX${OSX_SDK}.sdk.tar.gz; fi - - if [ -n "$OSX_SDK" -a -f depends/sdk-sources/MacOSX${OSX_SDK}.sdk.tar.gz ]; then tar -C depends/SDKs -xf depends/sdk-sources/MacOSX${OSX_SDK}.sdk.tar.gz; fi - - make $MAKEJOBS -C depends HOST=$HOST $DEP_OPTS -script: - - if [ -n "$USE_SHELL" ]; then export CONFIG_SHELL="$USE_SHELL"; fi - - OUTDIR=$BASE_OUTDIR/$TRAVIS_PULL_REQUEST/$TRAVIS_JOB_NUMBER-$HOST - - BITCOIN_CONFIG_ALL="--disable-dependency-tracking --prefix=$TRAVIS_BUILD_DIR/depends/$HOST --bindir=$OUTDIR/bin --libdir=$OUTDIR/lib" - - depends/$HOST/native/bin/ccache --max-size=$CCACHE_SIZE - - if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then export CCACHE_READONLY=1; fi - - test -n "$USE_SHELL" && eval '"$USE_SHELL" -c "./autogen.sh"' || ./autogen.sh - - ./configure --cache-file=config.cache $BITCOIN_CONFIG_ALL $BITCOIN_CONFIG || ( cat config.log && false) - - make distdir PACKAGE=bitcoin VERSION=$HOST - - cd bitcoin-$HOST - - ./configure --cache-file=../config.cache $BITCOIN_CONFIG_ALL $BITCOIN_CONFIG || ( cat config.log && false) - - make $MAKEJOBS $GOAL || ( echo "Build failure. Verbose build follows." && make $GOAL V=1 ; false ) - - export LD_LIBRARY_PATH=$TRAVIS_BUILD_DIR/depends/$HOST/lib - - if [ "$RUN_TESTS" = "true" ]; then make check; fi - - if [ "$RUN_TESTS" = "true" ]; then qa/pull-tester/rpc-tests.sh; fi -after_script: - - if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then (echo "Upload goes here. Something like: scp -r $BASE_OUTDIR server" || echo "upload failed"); fi + +compiler: + - gcc + +before_install: + - sudo add-apt-repository --yes ppa:ubuntu-sdk-team/ppa + - sudo apt-get update -qq + - sudo apt-get install build-essential pkg-config libcurl3-gnutls-dev libc6-dev libevent-dev m4 g++-multilib autoconf libtool ncurses-dev unzip git python zlib1g-dev wget bsdmainutils automake libssl-dev libprotobuf-dev protobuf-compiler libdb++-dev ntp ntpdate +#install: + +script: + - ./zcutil/build.sh -j 5 + +notifications: + irc: + channels: + - "chat.freenode.net#komodoplatform" + template: + - "%{repository}/%{branch} (%{commit} - %{author}): %{message}" + - "Alt Message : %{repository_slug} - (%{commit} - %{author}): %{message}, Build Time: %{duration}" + - "Change view : %{compare_url}" + - "Build details : %{build_url}" From 314350e695f07001e2188e87bc37064b96e40e05 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 3 Nov 2017 19:22:56 +0200 Subject: [PATCH 061/188] KOMODO_ENDOFERA --- src/komodo.h | 1 + src/komodo_interest.h | 8 +++++--- src/main.cpp | 8 ++++---- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index c5057646f..95aa1583a 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -25,6 +25,7 @@ #define KOMODO_ASSETCHAINS_WAITNOTARIZE #define KOMODO_PAXMAX (10000 * COIN) +#define KOMODO_ENDOFERA 7777777 #include #include diff --git a/src/komodo_interest.h b/src/komodo_interest.h index c5a35492d..917791498 100644 --- a/src/komodo_interest.h +++ b/src/komodo_interest.h @@ -19,6 +19,7 @@ #define KOMODO_INTEREST ((uint64_t)(0.05 * COIN)) // 5% int64_t MAX_MONEY = 200000000 * 100000000LL; +#ifdef notanymore uint64_t komodo_earned_interest(int32_t height,int64_t paidinterest) { static uint64_t *interests; static int32_t maxheight; @@ -73,6 +74,7 @@ uint64_t komodo_moneysupply(int32_t height) return(0); else return(COIN * 100000000 + (height-1) * 3 + komodo_earned_interest(height,-1)); } +#endif uint64_t _komodo_interestnew(uint64_t nValue,uint32_t nLockTime,uint32_t tiptime) { @@ -90,7 +92,7 @@ uint64_t _komodo_interestnew(uint64_t nValue,uint32_t nLockTime,uint32_t tiptime uint64_t komodo_interestnew(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uint32_t tiptime) { uint64_t interest = 0; - if ( txheight < 7777777 && komodo_moneysupply(txheight) < MAX_MONEY && nLockTime >= LOCKTIME_THRESHOLD && tiptime != 0 && nLockTime < tiptime && nValue >= 10*COIN ) + if ( txheight < KOMODO_ENDOFERA && nLockTime >= LOCKTIME_THRESHOLD && tiptime != 0 && nLockTime < tiptime && nValue >= 10*COIN ) //komodo_moneysupply(txheight) < MAX_MONEY && interest = _komodo_interestnew(nValue,nLockTime,tiptime); return(interest); } @@ -101,9 +103,9 @@ uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uin activation = 1491350400; // 1491350400 5th April if ( ASSETCHAINS_SYMBOL[0] != 0 ) return(0); - if ( txheight >= 7777777 ) + if ( txheight >= KOMODO_ENDOFERA ) return(0); - if ( komodo_moneysupply(txheight) < MAX_MONEY && nLockTime >= LOCKTIME_THRESHOLD && tiptime != 0 && nLockTime < tiptime && nValue >= 10*COIN ) + if ( nLockTime >= LOCKTIME_THRESHOLD && tiptime != 0 && nLockTime < tiptime && nValue >= 10*COIN ) //komodo_moneysupply(txheight) < MAX_MONEY && { if ( (minutes= (tiptime - nLockTime) / 60) >= 60 ) { diff --git a/src/main.cpp b/src/main.cpp index 8f028dbb7..e86a665ec 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1490,7 +1490,7 @@ bool ReadBlockFromDisk(CBlock& block, const CBlockIndex* pindex) return true; } -uint64_t komodo_moneysupply(int32_t height); +//uint64_t komodo_moneysupply(int32_t height); extern char ASSETCHAINS_SYMBOL[16]; extern uint32_t ASSETCHAINS_MAGIC; extern uint64_t ASSETCHAINS_SUPPLY; @@ -1502,7 +1502,7 @@ CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams) { if ( nHeight == 1 ) return(100000000 * COIN); // ICO allocation - else if ( komodo_moneysupply(nHeight) < MAX_MONEY ) + else if ( nHeight < KOMODO_ENDOFERA ) //komodo_moneysupply(nHeight) < MAX_MONEY ) return(3 * COIN); else return(0); } @@ -2365,8 +2365,8 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin return false; control.Add(vChecks); } - if ( ASSETCHAINS_SYMBOL[0] == 0 ) - komodo_earned_interest(pindex->nHeight,sum); + //if ( ASSETCHAINS_SYMBOL[0] == 0 ) + // komodo_earned_interest(pindex->nHeight,sum); CTxUndo undoDummy; if (i > 0) { blockundo.vtxundo.push_back(CTxUndo()); From e8cb981dd050908bf29b3a007fa8cd2621b995a2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 3 Nov 2017 19:24:53 +0200 Subject: [PATCH 062/188] Test --- src/komodo.h | 1 - src/komodo_interest.h | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index 95aa1583a..c5057646f 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -25,7 +25,6 @@ #define KOMODO_ASSETCHAINS_WAITNOTARIZE #define KOMODO_PAXMAX (10000 * COIN) -#define KOMODO_ENDOFERA 7777777 #include #include diff --git a/src/komodo_interest.h b/src/komodo_interest.h index 917791498..798eda48e 100644 --- a/src/komodo_interest.h +++ b/src/komodo_interest.h @@ -16,6 +16,7 @@ #define SATOSHIDEN ((uint64_t)100000000L) #define dstr(x) ((double)(x) / SATOSHIDEN) +#define KOMODO_ENDOFERA 7777777 #define KOMODO_INTEREST ((uint64_t)(0.05 * COIN)) // 5% int64_t MAX_MONEY = 200000000 * 100000000LL; From 17746e454a750f5c9a4ccd09d5886812f60aa17a Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 4 Nov 2017 04:50:59 +0200 Subject: [PATCH 063/188] Faster init test --- src/komodo.h | 133 ++++++++++++++++++++++++++++++++++++++++++- src/komodo_gateway.h | 62 +++++++++++++++++++- 2 files changed, 192 insertions(+), 3 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index c5057646f..d555dd941 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -192,7 +192,138 @@ int32_t komodo_parsestatefile(struct komodo_state *sp,FILE *fp,char *symbol,char return(func); } else return(-1); } - + +int32_t memread(void *dest,int32_t size,uint8_t *filedata,long *fposp,long datalen) +{ + if ( *fposp+size <= datalen ) + { + memcpy(dest,&filedata[*fposp],size); + (*fposp) += size; + return(size); + } + return(-1); +} + +long komodo_parsestatefiledata(struct komodo_state *sp,uint8_t *filedata,long *fposp,long datalen,char *symbol,char *dest) +{ + static int32_t errs; + int32_t func,ht,notarized_height,num,matched=0; uint256 notarized_hash,notarized_desttxid; uint8_t pubkeys[64][33]; long fpos = *fposp; + if ( fpos < datalen ) + { + func = filedata[fpos++]; + if ( ASSETCHAINS_SYMBOL[0] == 0 && strcmp(symbol,"KMD") == 0 ) + matched = 1; + else matched = (strcmp(symbol,ASSETCHAINS_SYMBOL) == 0); + if ( memread(&ht,sizeof(ht),filedata,&fpos,datalen) != sizeof(ht) ) + errs++; + if ( func == 'P' ) + { + if ( (num= filedata[fpos++]) <= 64 ) + { + if ( memread(pubkeys,33*num,filedata,&fpos,datalen) != 33*num ) + errs++; + else + { + //printf("updated %d pubkeys at %s ht.%d\n",num,symbol,ht); + if ( (KOMODO_EXTERNAL_NOTARIES != 0 && matched != 0) || (strcmp(symbol,"KMD") == 0 && KOMODO_EXTERNAL_NOTARIES == 0) ) + komodo_eventadd_pubkeys(sp,symbol,ht,num,pubkeys); + } + } else printf("illegal num.%d\n",num); + } + else if ( func == 'N' ) + { + if ( memread(¬arized_height,sizeof(notarized_height),filedata,&fpos,datalen) != sizeof(notarized_height) ) + errs++; + if ( memread(¬arized_hash,sizeof(notarized_hash),filedata,&fpos,datalen) != sizeof(notarized_hash) ) + errs++; + if ( memread(¬arized_desttxid,sizeof(notarized_desttxid),filedata,&fpos,datalen) != sizeof(notarized_desttxid) ) + errs++; + //if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 && sp != 0 ) + printf("%s load[%s.%d -> %s] NOTARIZED %d %s\n",ASSETCHAINS_SYMBOL,symbol,sp->NUM_NPOINTS,dest,notarized_height,notarized_hash.ToString().c_str()); + //if ( matched != 0 ) global independent states -> inside *sp + komodo_eventadd_notarized(sp,symbol,ht,dest,notarized_hash,notarized_desttxid,notarized_height); + } + else if ( func == 'U' ) // deprecated + { + uint8_t n,nid; uint256 hash; uint64_t mask; + n = filedata[fpos++]; + nid = filedata[fpos++]; + //printf("U %d %d\n",n,nid); + if ( memread(&mask,sizeof(mask),filedata,&fpos,datalen) != sizeof(mask) ) + errs++; + if ( memread(&hash,sizeof(hash),filedata,&fpos,datalen) != sizeof(hash) ) + errs++; + } + else if ( func == 'K' ) + { + int32_t kheight; + if ( memread(&kheight,sizeof(kheight),filedata,&fpos,datalen) != sizeof(kheight) ) + errs++; + komodo_eventadd_kmdheight(sp,symbol,ht,kheight,0); + } + else if ( func == 'T' ) + { + int32_t kheight,ktimestamp; + if ( memread(&kheight,sizeof(kheight),filedata,&fpos,datalen) != sizeof(kheight) ) + errs++; + if ( memread(&ktimestamp,sizeof(ktimestamp),filedata,&fpos,datalen) != sizeof(ktimestamp) ) + errs++; + //if ( matched != 0 ) global independent states -> inside *sp + //printf("%s.%d load[%s] ht.%d t.%u\n",ASSETCHAINS_SYMBOL,ht,symbol,kheight,ktimestamp); + komodo_eventadd_kmdheight(sp,symbol,ht,kheight,ktimestamp); + } + else if ( func == 'R' ) + { + uint16_t olen,v; uint64_t ovalue; uint256 txid; uint8_t opret[16384]; + if ( memread(&txid,sizeof(txid),filedata,&fpos,datalen) != sizeof(txid) ) + errs++; + if ( memread(&v,sizeof(v),filedata,&fpos,datalen) != sizeof(v) ) + errs++; + if ( memread(&ovalue,sizeof(ovalue),filedata,&fpos,datalen) != sizeof(ovalue) ) + errs++; + if ( memread(&olen,sizeof(olen),filedata,&fpos,datalen) != sizeof(olen) ) + errs++; + if ( olen < sizeof(opret) ) + { + if ( memread(opret,olen,filedata,&fpos,datalen) != olen ) + errs++; + if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 && matched != 0 ) + { + int32_t i; for (i=0; i global PAX + } else + { + int32_t i; + for (i=0; i global PVALS + //printf("%s load[%s] prices %d\n",ASSETCHAINS_SYMBOL,symbol,ht); + komodo_eventadd_pricefeed(sp,symbol,ht,pvals,numpvals); + //printf("load pvals ht.%d numpvals.%d\n",ht,numpvals); + } else printf("error loading pvals[%d]\n",numpvals); + } + else printf("[%s] %s illegal func.(%d %c)\n",ASSETCHAINS_SYMBOL,symbol,func,func); + *fposp = fpos; + return(fpos); + } else return(-1); +} + 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 KMDheight,uint32_t KMDtimestamp,uint64_t opretvalue,uint8_t *opretbuf,uint16_t opretlen,uint16_t vout) { static FILE *fp; static int32_t errs,didinit; diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 225d1a927..f7ad35e6a 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1351,11 +1351,59 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 return(typestr); } +void *OS_loadfile(char *fname,char **bufp,long *lenp,long *allocsizep) +{ + FILE *fp; + long filesize,buflen = *allocsizep; + char *buf = *bufp; + *lenp = 0; + if ( (fp= fopen(fname,"rb")) != 0 ) + { + fseek(fp,0,SEEK_END); + filesize = ftell(fp); + if ( filesize == 0 ) + { + fclose(fp); + *lenp = 0; + printf("OS_loadfile null size.(%s)\n",fname); + return(0); + } + if ( filesize > buflen-1 ) + { + *allocsizep = filesize+1; + *bufp = buf = realloc(buf,(long)*allocsizep); + } + rewind(fp); + if ( buf == 0 ) + printf("Null buf ???\n"); + else + { + if ( fread(buf,1,(long)filesize,fp) != (unsigned long)filesize ) + printf("error reading filesize.%ld\n",(long)filesize); + buf[filesize] = 0; + } + fclose(fp); + *lenp = filesize; + //printf("loaded.(%s)\n",buf); + } //else printf("OS_loadfile couldnt load.(%s)\n",fname); + return(buf); +} + +uint8_t *OS_fileptr(long *allocsizep,char *fname) +{ + long filesize = 0; char *buf = 0; void *retptr; + *allocsizep = 0; + retptr = OS_loadfile(fname,&buf,&filesize,allocsizep); + return(retptr); +} + +long komodo_parsestatefiledata(struct komodo_state *sp,uint8_t *filedata,long fpos,long datalen,char *symbol,char *dest); + void komodo_passport_iteration() { static long lastpos[34]; static char userpass[33][1024]; static uint32_t lasttime,callcounter; int32_t maxseconds = 10; - FILE *fp; int32_t baseid,limit,n,ht,isrealtime,expired,refid,blocks,longest; struct komodo_state *sp,*refsp; char *retstr,fname[512],*base,symbol[16],dest[16]; uint32_t buf[3],starttime; cJSON *infoobj,*result; uint64_t RTmask = 0; + FILE *fp; uint8_t *filedata; long fpos,datalen; int32_t baseid,limit,n,ht,isrealtime,expired,refid,blocks,longest; struct komodo_state *sp,*refsp; char *retstr,fname[512],*base,symbol[16],dest[16]; uint32_t buf[3],starttime; cJSON *infoobj,*result; uint64_t RTmask = 0; //printf("PASSPORT.(%s)\n",ASSETCHAINS_SYMBOL); expired = 0; while ( KOMODO_INITDONE == 0 ) @@ -1411,7 +1459,17 @@ void komodo_passport_iteration() komodo_nameset(symbol,dest,base); sp = komodo_stateptrget(symbol); n = 0; - if ( (fp= fopen(fname,"rb")) != 0 && sp != 0 ) + if ( (filedata= OS_fileptr(&datalen,fname)) != 0 ) + { + fpos = 0; + while ( komodo_parsestatefiledata(sp,filedata,&fpos,datalen,symbol,dest) >= 0 ) + ; + printf("took %d seconds to process %s %ldKB\n",(int32_t)(time(NULL)-starttime),fname,datalen/1024); + lastpos[baseid] = fpos; + free(filedata), filedata = 0; + datalen = 0; + } + else if ( (fp= fopen(fname,"rb")) != 0 && sp != 0 ) { fseek(fp,0,SEEK_END); if ( ftell(fp) > lastpos[baseid] ) From e9c761589b93f2c69c2891db0312e6396fbc62cd Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 4 Nov 2017 04:53:04 +0200 Subject: [PATCH 064/188] 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 f7ad35e6a..2472f6770 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1351,11 +1351,11 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 return(typestr); } -void *OS_loadfile(char *fname,char **bufp,long *lenp,long *allocsizep) +void *OS_loadfile(char *fname,uint8_t **bufp,long *lenp,long *allocsizep) { FILE *fp; long filesize,buflen = *allocsizep; - char *buf = *bufp; + uint8_t *buf = *bufp; *lenp = 0; if ( (fp= fopen(fname,"rb")) != 0 ) { @@ -1371,7 +1371,7 @@ void *OS_loadfile(char *fname,char **bufp,long *lenp,long *allocsizep) if ( filesize > buflen-1 ) { *allocsizep = filesize+1; - *bufp = buf = realloc(buf,(long)*allocsizep); + *bufp = buf = (uint8_t *)realloc(buf,(long)*allocsizep); } rewind(fp); if ( buf == 0 ) @@ -1391,10 +1391,10 @@ void *OS_loadfile(char *fname,char **bufp,long *lenp,long *allocsizep) uint8_t *OS_fileptr(long *allocsizep,char *fname) { - long filesize = 0; char *buf = 0; void *retptr; + long filesize = 0; uint8_t *buf = 0; void *retptr; *allocsizep = 0; retptr = OS_loadfile(fname,&buf,&filesize,allocsizep); - return(retptr); + return((uint8_t *)retptr); } long komodo_parsestatefiledata(struct komodo_state *sp,uint8_t *filedata,long fpos,long datalen,char *symbol,char *dest); From b356016e7782f3495e27a586e4ffdb9a4ae91ef5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 4 Nov 2017 04:53:37 +0200 Subject: [PATCH 065/188] 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 2472f6770..ae15e1019 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1397,7 +1397,7 @@ uint8_t *OS_fileptr(long *allocsizep,char *fname) return((uint8_t *)retptr); } -long komodo_parsestatefiledata(struct komodo_state *sp,uint8_t *filedata,long fpos,long datalen,char *symbol,char *dest); +long komodo_parsestatefiledata(struct komodo_state *sp,uint8_t *filedata,long *fposp,long datalen,char *symbol,char *dest); void komodo_passport_iteration() { From f7ec3a985a0e9ab22018476392d5218dd049fcd3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 4 Nov 2017 05:04:26 +0200 Subject: [PATCH 066/188] Test --- src/komodo.h | 2 +- src/komodo_gateway.h | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index d555dd941..1bcc477ac 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -238,7 +238,7 @@ long komodo_parsestatefiledata(struct komodo_state *sp,uint8_t *filedata,long *f errs++; if ( memread(¬arized_desttxid,sizeof(notarized_desttxid),filedata,&fpos,datalen) != sizeof(notarized_desttxid) ) errs++; - //if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 && sp != 0 ) + if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 && sp != 0 ) printf("%s load[%s.%d -> %s] NOTARIZED %d %s\n",ASSETCHAINS_SYMBOL,symbol,sp->NUM_NPOINTS,dest,notarized_height,notarized_hash.ToString().c_str()); //if ( matched != 0 ) global independent states -> inside *sp komodo_eventadd_notarized(sp,symbol,ht,dest,notarized_hash,notarized_desttxid,notarized_height); diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index ae15e1019..ca00f1531 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1452,7 +1452,7 @@ void komodo_passport_iteration() base = (char *)CURRENCIES[baseid]; if ( baseid+1 != refid ) { - if ( baseid == 32 || ASSETCHAINS_SYMBOL[0] == 0 ) + if ( baseid == 32 || strcmp(ASSETCHAINS_SYMBOL,base) == 0 ) { refsp->RTmask &= ~(1LL << baseid); komodo_statefname(fname,baseid<32?base:(char *)"",(char *)"komodostate"); @@ -1462,6 +1462,7 @@ void komodo_passport_iteration() if ( (filedata= OS_fileptr(&datalen,fname)) != 0 ) { fpos = 0; + printf("processing %s %ldKB\n",fname,datalen/1024); while ( komodo_parsestatefiledata(sp,filedata,&fpos,datalen,symbol,dest) >= 0 ) ; printf("took %d seconds to process %s %ldKB\n",(int32_t)(time(NULL)-starttime),fname,datalen/1024); @@ -1472,6 +1473,7 @@ void komodo_passport_iteration() else if ( (fp= fopen(fname,"rb")) != 0 && sp != 0 ) { fseek(fp,0,SEEK_END); + printf("couldnt OS_fileptr(%s), freading %ldKB\n",fname,ftell(fp)/1024) if ( ftell(fp) > lastpos[baseid] ) { if ( ASSETCHAINS_SYMBOL[0] != 0 ) From 5b32c90080cfa03e1ded7224a002a032b2d71835 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 4 Nov 2017 05:05:55 +0200 Subject: [PATCH 067/188] 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 ca00f1531..2495bd9b6 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1473,7 +1473,7 @@ void komodo_passport_iteration() else if ( (fp= fopen(fname,"rb")) != 0 && sp != 0 ) { fseek(fp,0,SEEK_END); - printf("couldnt OS_fileptr(%s), freading %ldKB\n",fname,ftell(fp)/1024) + printf("couldnt OS_fileptr(%s), freading %ldKB\n",fname,ftell(fp)/1024); if ( ftell(fp) > lastpos[baseid] ) { if ( ASSETCHAINS_SYMBOL[0] != 0 ) From 13b0e935d8a5a4b55de7d975af27147ddedce7b5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 4 Nov 2017 05:14:59 +0200 Subject: [PATCH 068/188] 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 2495bd9b6..dc427eaff 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1442,7 +1442,6 @@ void komodo_passport_iteration() return; } lasttime = starttime; - //printf("PASSPORT %s refid.%d\n",ASSETCHAINS_SYMBOL,refid); for (baseid=32; baseid>=0; baseid--) { if ( time(NULL) >= starttime+maxseconds ) @@ -1450,6 +1449,7 @@ void komodo_passport_iteration() sp = 0; isrealtime = 0; base = (char *)CURRENCIES[baseid]; + printf("PASSPORT %s baseid+1 %d refid.%d\n",ASSETCHAINS_SYMBOL,baseid+1,refid); if ( baseid+1 != refid ) { if ( baseid == 32 || strcmp(ASSETCHAINS_SYMBOL,base) == 0 ) @@ -1462,10 +1462,10 @@ void komodo_passport_iteration() if ( (filedata= OS_fileptr(&datalen,fname)) != 0 ) { fpos = 0; - printf("processing %s %ldKB\n",fname,datalen/1024); + fprintf(stderr,"processing %s %ldKB\n",fname,datalen/1024); while ( komodo_parsestatefiledata(sp,filedata,&fpos,datalen,symbol,dest) >= 0 ) ; - printf("took %d seconds to process %s %ldKB\n",(int32_t)(time(NULL)-starttime),fname,datalen/1024); + fprintf(stderr,"took %d seconds to process %s %ldKB\n",(int32_t)(time(NULL)-starttime),fname,datalen/1024); lastpos[baseid] = fpos; free(filedata), filedata = 0; datalen = 0; @@ -1473,7 +1473,7 @@ void komodo_passport_iteration() else if ( (fp= fopen(fname,"rb")) != 0 && sp != 0 ) { fseek(fp,0,SEEK_END); - printf("couldnt OS_fileptr(%s), freading %ldKB\n",fname,ftell(fp)/1024); + fprintf(stderr,"couldnt OS_fileptr(%s), freading %ldKB\n",fname,ftell(fp)/1024); if ( ftell(fp) > lastpos[baseid] ) { if ( ASSETCHAINS_SYMBOL[0] != 0 ) @@ -1498,7 +1498,7 @@ void komodo_passport_iteration() printf("from.(%s) lastpos[%s] %ld isrt.%d\n",ASSETCHAINS_SYMBOL,CURRENCIES[baseid],lastpos[baseid],komodo_isrealtime(&ht)); } //else fprintf(stderr,"%s.%ld ",CURRENCIES[baseid],ftell(fp)); fclose(fp); - } //else printf("error.(%s) %p\n",fname,sp); + } else fprintf(stderr,"load error.(%s) %p\n",fname,sp); komodo_statefname(fname,baseid<32?base:(char *)"",(char *)"realtime"); if ( (fp= fopen(fname,"rb")) != 0 ) { From 08775bc1faacce1aa0a5c7b44041fa17482b90f3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 4 Nov 2017 05:20:45 +0200 Subject: [PATCH 069/188] Test --- src/komodo.h | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 1bcc477ac..bb4735f49 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -345,10 +345,23 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar komodo_statefname(fname,ASSETCHAINS_SYMBOL,(char *)"komodostate"); if ( (fp= fopen(fname,"rb+")) != 0 ) { - while ( komodo_parsestatefile(sp,fp,symbol,dest) >= 0 ) - ; + uint8_t *filedata; long datalen,fpos; + if ( (filedata= OS_fileptr(&datalen,fname)) != 0 ) + { + fpos = 0; + fprintf(stderr,"processing %s %ldKB\n",fname,datalen/1024); + while ( komodo_parsestatefiledata(sp,filedata,&fpos,datalen,symbol,dest) >= 0 ) + ; + fprintf(stderr,"took %d seconds to process %s %ldKB\n",(int32_t)(time(NULL)-starttime),fname,datalen/1024); + free(filedata); + fseek(fp,fpos,SEEK_SET); + } + else + { + while ( komodo_parsestatefile(sp,fp,symbol,dest) >= 0 ) + ; + } } else fp = fopen(fname,"wb+"); - printf("fname.(%s) fpos.%ld\n",fname,ftell(fp)); KOMODO_INITDONE = (uint32_t)time(NULL); } if ( height <= 0 ) From 0cd5ab88aa74f32bb0f092c375e151519763ca3f Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 4 Nov 2017 05:25:59 +0200 Subject: [PATCH 070/188] Test --- src/komodo_gateway.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index dc427eaff..5d7716259 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1449,23 +1449,23 @@ void komodo_passport_iteration() sp = 0; isrealtime = 0; base = (char *)CURRENCIES[baseid]; - printf("PASSPORT %s baseid+1 %d refid.%d\n",ASSETCHAINS_SYMBOL,baseid+1,refid); - if ( baseid+1 != refid ) + //printf("PASSPORT %s baseid+1 %d refid.%d\n",ASSETCHAINS_SYMBOL,baseid+1,refid); + if ( baseid+1 != refid ) // only need to import state from a different coin { - if ( baseid == 32 || strcmp(ASSETCHAINS_SYMBOL,base) == 0 ) + if ( baseid == 32 ) // only care about KMD's state { refsp->RTmask &= ~(1LL << baseid); komodo_statefname(fname,baseid<32?base:(char *)"",(char *)"komodostate"); komodo_nameset(symbol,dest,base); sp = komodo_stateptrget(symbol); n = 0; - if ( (filedata= OS_fileptr(&datalen,fname)) != 0 ) + if ( lastpos[baseid] == 0 && (filedata= OS_fileptr(&datalen,fname)) != 0 ) { fpos = 0; - fprintf(stderr,"processing %s %ldKB\n",fname,datalen/1024); + fprintf(stderr,"%s processing %s %ldKB\n",ASSETCHAINS_SYMBOL,fname,datalen/1024); while ( komodo_parsestatefiledata(sp,filedata,&fpos,datalen,symbol,dest) >= 0 ) ; - fprintf(stderr,"took %d seconds to process %s %ldKB\n",(int32_t)(time(NULL)-starttime),fname,datalen/1024); + fprintf(stderr,"%s took %d seconds to process %s %ldKB\n",ASSETCHAINS_SYMBOL,(int32_t)(time(NULL)-starttime),fname,datalen/1024); lastpos[baseid] = fpos; free(filedata), filedata = 0; datalen = 0; @@ -1494,7 +1494,7 @@ void komodo_passport_iteration() n++; } lastpos[baseid] = ftell(fp); - if ( lastpos[baseid] == 0 && strcmp(symbol,"KMD") == 0 ) + if ( 0 && lastpos[baseid] == 0 && strcmp(symbol,"KMD") == 0 ) printf("from.(%s) lastpos[%s] %ld isrt.%d\n",ASSETCHAINS_SYMBOL,CURRENCIES[baseid],lastpos[baseid],komodo_isrealtime(&ht)); } //else fprintf(stderr,"%s.%ld ",CURRENCIES[baseid],ftell(fp)); fclose(fp); From 9ddeeba22691915fb0377aab10e45131dcc47e57 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 4 Nov 2017 05:27:08 +0200 Subject: [PATCH 071/188] Test --- src/komodo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index bb4735f49..dd5ffa869 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -345,7 +345,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar komodo_statefname(fname,ASSETCHAINS_SYMBOL,(char *)"komodostate"); if ( (fp= fopen(fname,"rb+")) != 0 ) { - uint8_t *filedata; long datalen,fpos; + uint8_t *filedata; long datalen,fpos; uint32_t starttime = (uint32_t)time(NULL); if ( (filedata= OS_fileptr(&datalen,fname)) != 0 ) { fpos = 0; From 58f293eb9882106258b8b970257bd913b26204c1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 4 Nov 2017 05:36:09 +0200 Subject: [PATCH 072/188] Test --- src/komodo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index dd5ffa869..9e332a34f 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -354,7 +354,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar ; fprintf(stderr,"took %d seconds to process %s %ldKB\n",(int32_t)(time(NULL)-starttime),fname,datalen/1024); free(filedata); - fseek(fp,fpos,SEEK_SET); + fseek(fp,0,SEEK_END); } else { From cb7f1d47c1fba2409997ed305f4aaa0b2d5726a1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 4 Nov 2017 05:39:44 +0200 Subject: [PATCH 073/188] 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 5d7716259..3ecf453c5 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1370,7 +1370,7 @@ void *OS_loadfile(char *fname,uint8_t **bufp,long *lenp,long *allocsizep) } if ( filesize > buflen-1 ) { - *allocsizep = filesize+1; + *allocsizep = filesize; *bufp = buf = (uint8_t *)realloc(buf,(long)*allocsizep); } rewind(fp); From 211f7541264e2bb6c87ae8a719eccd18df6940ac Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 4 Nov 2017 05:48:50 +0200 Subject: [PATCH 074/188] 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 3ecf453c5..441544d0b 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1473,7 +1473,7 @@ void komodo_passport_iteration() else if ( (fp= fopen(fname,"rb")) != 0 && sp != 0 ) { fseek(fp,0,SEEK_END); - fprintf(stderr,"couldnt OS_fileptr(%s), freading %ldKB\n",fname,ftell(fp)/1024); + //fprintf(stderr,"couldnt OS_fileptr(%s), freading %ldKB\n",fname,ftell(fp)/1024); if ( ftell(fp) > lastpos[baseid] ) { if ( ASSETCHAINS_SYMBOL[0] != 0 ) From 3b40d63139bba4890e927369b5b1c8fce812b913 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 5 Nov 2017 12:06:10 +0200 Subject: [PATCH 075/188] komodostate.ind --- src/komodo.h | 20 +++---- src/komodo_gateway.h | 122 ++++++++++++++++++++++++++++++++++++++++++- src/purge | 5 ++ 3 files changed, 132 insertions(+), 15 deletions(-) create mode 100755 src/purge diff --git a/src/komodo.h b/src/komodo.h index 9e332a34f..f057e1e86 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -204,10 +204,10 @@ int32_t memread(void *dest,int32_t size,uint8_t *filedata,long *fposp,long datal return(-1); } -long komodo_parsestatefiledata(struct komodo_state *sp,uint8_t *filedata,long *fposp,long datalen,char *symbol,char *dest) +int32_t komodo_parsestatefiledata(struct komodo_state *sp,uint8_t *filedata,long *fposp,long datalen,char *symbol,char *dest) { static int32_t errs; - int32_t func,ht,notarized_height,num,matched=0; uint256 notarized_hash,notarized_desttxid; uint8_t pubkeys[64][33]; long fpos = *fposp; + int32_t func= -1,ht,notarized_height,num,matched=0; uint256 notarized_hash,notarized_desttxid; uint8_t pubkeys[64][33]; long fpos = *fposp; if ( fpos < datalen ) { func = filedata[fpos++]; @@ -320,8 +320,9 @@ long komodo_parsestatefiledata(struct komodo_state *sp,uint8_t *filedata,long *f } else printf("[%s] %s illegal func.(%d %c)\n",ASSETCHAINS_SYMBOL,symbol,func,func); *fposp = fpos; - return(fpos); - } else return(-1); + return(func); + } + return(-1); } 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 KMDheight,uint32_t KMDtimestamp,uint64_t opretvalue,uint8_t *opretbuf,uint16_t opretlen,uint16_t vout) @@ -345,17 +346,8 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar komodo_statefname(fname,ASSETCHAINS_SYMBOL,(char *)"komodostate"); if ( (fp= fopen(fname,"rb+")) != 0 ) { - uint8_t *filedata; long datalen,fpos; uint32_t starttime = (uint32_t)time(NULL); - if ( (filedata= OS_fileptr(&datalen,fname)) != 0 ) - { - fpos = 0; - fprintf(stderr,"processing %s %ldKB\n",fname,datalen/1024); - while ( komodo_parsestatefiledata(sp,filedata,&fpos,datalen,symbol,dest) >= 0 ) - ; - fprintf(stderr,"took %d seconds to process %s %ldKB\n",(int32_t)(time(NULL)-starttime),fname,datalen/1024); - free(filedata); + if ( komodo_faststateinit(sp,fname) == 0 ) fseek(fp,0,SEEK_END); - } else { while ( komodo_parsestatefile(sp,fp,symbol,dest) >= 0 ) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 441544d0b..ffb07918e 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1351,6 +1351,13 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 return(typestr); } +void komodo_stateind_set(struct komodo_state *sp,uint32_t *inds,int32_t n,uint8_t *filedata,long datalen,char *symbol,char *dest) +{ + uint8_t func; long fpos; + komodo_parsestatefiledata(sp,filedata,&fpos,datalen,symbol,dest); + // scan backwards to set all the sp-> fields to the current valid value +} + void *OS_loadfile(char *fname,uint8_t **bufp,long *lenp,long *allocsizep) { FILE *fp; @@ -1397,7 +1404,120 @@ uint8_t *OS_fileptr(long *allocsizep,char *fname) return((uint8_t *)retptr); } -long komodo_parsestatefiledata(struct komodo_state *sp,uint8_t *filedata,long *fposp,long datalen,char *symbol,char *dest); +int32_t komodo_parsestatefiledata(struct komodo_state *sp,uint8_t *filedata,long *fposp,long datalen,char *symbol,char *dest); + +long komodo_stateind_validate(struct komodo_state *sp,char *indfname,uint8_t *filedata,long datalen,uint32_t *prevpos100p,uint32_t *indcounterp,char *symbol,char *dest) +{ + FILE *fp; long fsize,fpos=-1; uint8_t *inds,func; int32_t i,n; uint32_t offset,tmp,prevpos100 = 0; + *indcounterp = *prevpos100p = 0; + if ( (inds= OS_fileptr(&fsize,indfname)) != 0 ) + { + if ( (fsize % sizeof(uint32_t)) == 0 ) + { + n = (int32_t)(fsize / sizeof(uint32_t)); + for (i=0; i> 8); + fpos = prevpos100 + offset; + if ( fpos >= datalen || filedata[fpos] != func ) + { + printf("validate.%d error (%u %d) prev100 %u -> fpos.%ld datalen.%ld [%d]\n",i,offset,func,prevpos100,fpos,datalen,fpos < datalen ? filedata[fpos] : -1); + return(-1); + } + } + } + *indcounterp = n; + *prevpos100p = prevpos100; + printf("%s validated[%d] fpos.%ld datalen.%ld\n",indfname,i,fpos,datalen); + if ( sp != 0 ) + komodo_stateind_set(sp,(uint32_t *)inds,n,filedata,fpos,symbol,dest); + free(inds); + return(fpos); + } else printf("wrong filesize %s %ld\n",indfname,fsize); + } + free(inds); + return(-1); +} + +long komodo_indfile_update(FILE *indfp,uint32_t *prevpos100p,long lastfpos,long newfpos,uint8_t func,uint32_t *indcounterp) +{ + uint32_t tmp; + if ( indfp != 0 ) + { + tmp = ((uint32_t)(lastfpos - *prevpos100p) << 8) | (func & 0xff); + if ( ftell(indfp)/sizeof(uint32_t) != *indcounterp ) + printf("indfp fpos %ld -> ind.%d vs counter.%u\n",ftell(indfp),ftell(indfp)/sizeof(uint32_t),*indcounterp); + fwrite(&tmp,1,sizeof(tmp),indfp), (*indcounterp)++; + if ( (*indcounterp % 100) == 0 ) + { + *prevpos100p = (uint32_t)newfpos; + fwrite(prevpos100p,1,sizeof(*prevpos100p),indfp), (*indcounterp)++; + } + } + return(newfpos); +} + +int32_t komodo_faststateinit(struct komodo_state *sp,char *fname,char *symbol,char *dest) +{ + FILE *indfp; char indfname[1024]; uint8_t *filedata; long processed=-1,datalen,fpos,lastfpos; uint32_t tmp,prevpos100,indcounter,starttime; int32_t func,finished = 0; + stattime = (uint32_t)time(NULL); + safecopy(indfname,fname,sizeof(indfname)-4); + strcat(indfname,".ind"); + if ( (filedata= OS_fileptr(&datalen,fname)) != 0 ) + { + if ( datalen >= (1LL << 32) || GetArg("-genind",0) != 0 || (processed= komodo_stateind_validate(0,indfname,filedata,datalen,&prevpos100,&indcounter)) < 0 ) + { + lastfpos = fpos = 0; + indcounter = prevpos100 = 0; + if ( (indfp= fopen(indfname,"wb")) != 0 ) + fwrite(&prevpos100,1,sizeof(prevpos100),indfp), indcounter++; + fprintf(stderr,"processing %s %ldKB\n",fname,datalen/1024); + while ( (func= komodo_parsestatefiledata(sp,filedata,&fpos,datalen,symbol,dest)) >= 0 ) + { + lastfpos = komodo_indfile_update(indfp,&prevpos100,lastfpos,fpos,func,&indcounter); + } + if ( indfp != 0 ) + { + fclose(indfp); + if ( komodo_stateind_validate(0,indfname,filedata,datalen,symbol,dest) < 0 ) + printf("unexpected komodostate.ind validate failure %s datalen.%ld\n",indfname,datalen); + else printf("%s validated\n",indfname); + } + finished = 1; + fprintf(stderr,"took %d seconds to process %s %ldKB\n",(int32_t)(time(NULL)-starttime),fname,datalen/1024); + } + else if ( processed > 0 ) + { + if ( (indfp= fopen(indfname,"rb+")) != 0 ) + { + lastfpos = fpos = processed; + fseek(indfp,indcounter * sizeof(uint32_t),SEEK_SET); + if ( ftell(indfp) == indcounter * sizeof(uint32_t) ) + { + while ( (func= komodo_parsestatefiledata(sp,filedata,&fpos,datalen,symbol,dest)) >= 0 ) + lastfpos = komodo_indfile_update(indfp,&prevpos100,lastfpos,fpos,func,&indcounter); + } + fclose(indfp); + if ( komodo_stateind_validate(sp,indfname,filedata,datalen,system,dest) < 0 ) + printf("unexpected komodostate.ind validate failure %s datalen.%ld\n",indfname,datalen); + else + { + printf("%s validated updated from processed.%ld to %ld [%ld]\n",indfname,processed,fpos,fpos-processed); + finished = 1; + } + } + } else printf("komodo_faststateinit unexpected case\n"); + free(filedata); + return(finished == 1); + } + return(-1); +} void komodo_passport_iteration() { diff --git a/src/purge b/src/purge new file mode 100755 index 000000000..08928e922 --- /dev/null +++ b/src/purge @@ -0,0 +1,5 @@ +rm -rf ~/.komodo/$1/chainstate +rm -rf ~/.komodo/$1/database +rm -rf ~/.komodo/$1/blocks +rm -rf ~/.komodo/$1/komodostate + From 52129d3054a7b919d08f4e0156a9aee7a94c2179 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 5 Nov 2017 12:07:13 +0200 Subject: [PATCH 076/188] Test --- src/komodo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index f057e1e86..e49eb7452 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -346,7 +346,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar komodo_statefname(fname,ASSETCHAINS_SYMBOL,(char *)"komodostate"); if ( (fp= fopen(fname,"rb+")) != 0 ) { - if ( komodo_faststateinit(sp,fname) == 0 ) + if ( komodo_faststateinit(sp,fname,symbol,dest) == 0 ) fseek(fp,0,SEEK_END); else { From 3d40ead2a476510b216f21ea12d9acd227d868cd Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 5 Nov 2017 12:08:52 +0200 Subject: [PATCH 077/188] 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 ffb07918e..3ebf22bc4 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1471,7 +1471,7 @@ int32_t komodo_faststateinit(struct komodo_state *sp,char *fname,char *symbol,ch strcat(indfname,".ind"); if ( (filedata= OS_fileptr(&datalen,fname)) != 0 ) { - if ( datalen >= (1LL << 32) || GetArg("-genind",0) != 0 || (processed= komodo_stateind_validate(0,indfname,filedata,datalen,&prevpos100,&indcounter)) < 0 ) + if ( datalen >= (1LL << 32) || GetArg("-genind",0) != 0 || (processed= komodo_stateind_validate(0,indfname,filedata,datalen,&prevpos100,&indcounter,symbol,dest)) < 0 ) { lastfpos = fpos = 0; indcounter = prevpos100 = 0; From af786d5de8702d100a5b71bb8ebfcc4d79c8a3a9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 5 Nov 2017 12:10:29 +0200 Subject: [PATCH 078/188] 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 3ebf22bc4..ec006c9ee 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1351,10 +1351,12 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 return(typestr); } +int32_t komodo_parsestatefiledata(struct komodo_state *sp,uint8_t *filedata,long *fposp,long datalen,char *symbol,char *dest); + void komodo_stateind_set(struct komodo_state *sp,uint32_t *inds,int32_t n,uint8_t *filedata,long datalen,char *symbol,char *dest) { uint8_t func; long fpos; - komodo_parsestatefiledata(sp,filedata,&fpos,datalen,symbol,dest); + //komodo_parsestatefiledata(sp,filedata,&fpos,datalen,symbol,dest); // scan backwards to set all the sp-> fields to the current valid value } @@ -1404,8 +1406,6 @@ uint8_t *OS_fileptr(long *allocsizep,char *fname) return((uint8_t *)retptr); } -int32_t komodo_parsestatefiledata(struct komodo_state *sp,uint8_t *filedata,long *fposp,long datalen,char *symbol,char *dest); - long komodo_stateind_validate(struct komodo_state *sp,char *indfname,uint8_t *filedata,long datalen,uint32_t *prevpos100p,uint32_t *indcounterp,char *symbol,char *dest) { FILE *fp; long fsize,fpos=-1; uint8_t *inds,func; int32_t i,n; uint32_t offset,tmp,prevpos100 = 0; @@ -1466,7 +1466,7 @@ long komodo_indfile_update(FILE *indfp,uint32_t *prevpos100p,long lastfpos,long int32_t komodo_faststateinit(struct komodo_state *sp,char *fname,char *symbol,char *dest) { FILE *indfp; char indfname[1024]; uint8_t *filedata; long processed=-1,datalen,fpos,lastfpos; uint32_t tmp,prevpos100,indcounter,starttime; int32_t func,finished = 0; - stattime = (uint32_t)time(NULL); + starttime = (uint32_t)time(NULL); safecopy(indfname,fname,sizeof(indfname)-4); strcat(indfname,".ind"); if ( (filedata= OS_fileptr(&datalen,fname)) != 0 ) From b8359369fba6746e389aaeb415ac96e4c9532614 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 5 Nov 2017 12:12:10 +0200 Subject: [PATCH 079/188] 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 ec006c9ee..7dae417b5 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1452,7 +1452,7 @@ long komodo_indfile_update(FILE *indfp,uint32_t *prevpos100p,long lastfpos,long { tmp = ((uint32_t)(lastfpos - *prevpos100p) << 8) | (func & 0xff); if ( ftell(indfp)/sizeof(uint32_t) != *indcounterp ) - printf("indfp fpos %ld -> ind.%d vs counter.%u\n",ftell(indfp),ftell(indfp)/sizeof(uint32_t),*indcounterp); + printf("indfp fpos %ld -> ind.%ld vs counter.%u\n",ftell(indfp),ftell(indfp)/sizeof(uint32_t),*indcounterp); fwrite(&tmp,1,sizeof(tmp),indfp), (*indcounterp)++; if ( (*indcounterp % 100) == 0 ) { @@ -1485,7 +1485,7 @@ int32_t komodo_faststateinit(struct komodo_state *sp,char *fname,char *symbol,ch if ( indfp != 0 ) { fclose(indfp); - if ( komodo_stateind_validate(0,indfname,filedata,datalen,symbol,dest) < 0 ) + if ( komodo_stateind_validate(0,indfname,filedata,datalen,&prevpos100,&indcounter,symbol,dest) < 0 ) printf("unexpected komodostate.ind validate failure %s datalen.%ld\n",indfname,datalen); else printf("%s validated\n",indfname); } @@ -1504,7 +1504,7 @@ int32_t komodo_faststateinit(struct komodo_state *sp,char *fname,char *symbol,ch lastfpos = komodo_indfile_update(indfp,&prevpos100,lastfpos,fpos,func,&indcounter); } fclose(indfp); - if ( komodo_stateind_validate(sp,indfname,filedata,datalen,system,dest) < 0 ) + if ( komodo_stateind_validate(sp,indfname,filedata,datalen,&prevpos100,&indcountersystem,dest) < 0 ) printf("unexpected komodostate.ind validate failure %s datalen.%ld\n",indfname,datalen); else { From 79a6f2aee26b7681d0fa49132a31c76d8144b325 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 5 Nov 2017 12:13:18 +0200 Subject: [PATCH 080/188] 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 7dae417b5..a7228f2aa 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1504,7 +1504,7 @@ int32_t komodo_faststateinit(struct komodo_state *sp,char *fname,char *symbol,ch lastfpos = komodo_indfile_update(indfp,&prevpos100,lastfpos,fpos,func,&indcounter); } fclose(indfp); - if ( komodo_stateind_validate(sp,indfname,filedata,datalen,&prevpos100,&indcountersystem,dest) < 0 ) + if ( komodo_stateind_validate(sp,indfname,filedata,datalen,&prevpos100,&indcounter,system,dest) < 0 ) printf("unexpected komodostate.ind validate failure %s datalen.%ld\n",indfname,datalen); else { From 4c87a8df446b54ab703b4340c638ebff99ef08cb Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 5 Nov 2017 12:16:19 +0200 Subject: [PATCH 081/188] 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 a7228f2aa..c0b3a5845 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1504,7 +1504,7 @@ int32_t komodo_faststateinit(struct komodo_state *sp,char *fname,char *symbol,ch lastfpos = komodo_indfile_update(indfp,&prevpos100,lastfpos,fpos,func,&indcounter); } fclose(indfp); - if ( komodo_stateind_validate(sp,indfname,filedata,datalen,&prevpos100,&indcounter,system,dest) < 0 ) + if ( komodo_stateind_validate(sp,indfname,filedata,datalen,&prevpos100,&indcounter,symbol,dest) < 0 ) printf("unexpected komodostate.ind validate failure %s datalen.%ld\n",indfname,datalen); else { From 6cc0f9de1289468903d2e61219ed0aa5598f3928 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 5 Nov 2017 12:21:05 +0200 Subject: [PATCH 082/188] Test --- src/komodo_gateway.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index c0b3a5845..b82f96714 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1442,6 +1442,7 @@ long komodo_stateind_validate(struct komodo_state *sp,char *indfname,uint8_t *fi } else printf("wrong filesize %s %ld\n",indfname,fsize); } free(inds); + fprintf(stderr,"indvalidate return -1\n"); return(-1); } @@ -1471,6 +1472,7 @@ int32_t komodo_faststateinit(struct komodo_state *sp,char *fname,char *symbol,ch strcat(indfname,".ind"); if ( (filedata= OS_fileptr(&datalen,fname)) != 0 ) { + fprintf(stderr,"faststateinit %s datalen.%ld\n",indfname,datalen); if ( datalen >= (1LL << 32) || GetArg("-genind",0) != 0 || (processed= komodo_stateind_validate(0,indfname,filedata,datalen,&prevpos100,&indcounter,symbol,dest)) < 0 ) { lastfpos = fpos = 0; @@ -1516,6 +1518,7 @@ int32_t komodo_faststateinit(struct komodo_state *sp,char *fname,char *symbol,ch free(filedata); return(finished == 1); } + fprintf(stderr,"faststateinit return -1\n"); return(-1); } From 1ff645e6f5e33dc2750595b2e9fc5512fbf44fbd Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 5 Nov 2017 12:29:26 +0200 Subject: [PATCH 083/188] Test --- src/komodo_gateway.h | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index b82f96714..e93d0836c 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1466,20 +1466,19 @@ long komodo_indfile_update(FILE *indfp,uint32_t *prevpos100p,long lastfpos,long int32_t komodo_faststateinit(struct komodo_state *sp,char *fname,char *symbol,char *dest) { - FILE *indfp; char indfname[1024]; uint8_t *filedata; long processed=-1,datalen,fpos,lastfpos; uint32_t tmp,prevpos100,indcounter,starttime; int32_t func,finished = 0; + FILE *indfp; char indfname[1024]; uint8_t *filedata; long validated=-1,datalen,fpos,lastfpos; uint32_t tmp,prevpos100,indcounter,starttime; int32_t func,finished = 0; starttime = (uint32_t)time(NULL); safecopy(indfname,fname,sizeof(indfname)-4); strcat(indfname,".ind"); if ( (filedata= OS_fileptr(&datalen,fname)) != 0 ) { - fprintf(stderr,"faststateinit %s datalen.%ld\n",indfname,datalen); - if ( datalen >= (1LL << 32) || GetArg("-genind",0) != 0 || (processed= komodo_stateind_validate(0,indfname,filedata,datalen,&prevpos100,&indcounter,symbol,dest)) < 0 ) + if ( datalen >= (1LL << 32) || GetArg("-genind",0) != 0 || (validated= komodo_stateind_validate(0,indfname,filedata,datalen,&prevpos100,&indcounter,symbol,dest)) < 0 ) { lastfpos = fpos = 0; indcounter = prevpos100 = 0; if ( (indfp= fopen(indfname,"wb")) != 0 ) fwrite(&prevpos100,1,sizeof(prevpos100),indfp), indcounter++; - fprintf(stderr,"processing %s %ldKB\n",fname,datalen/1024); + fprintf(stderr,"processing %s %ldKB, validated.%ld\n",fname,datalen/1024,validated); while ( (func= komodo_parsestatefiledata(sp,filedata,&fpos,datalen,symbol,dest)) >= 0 ) { lastfpos = komodo_indfile_update(indfp,&prevpos100,lastfpos,fpos,func,&indcounter); @@ -1494,11 +1493,12 @@ int32_t komodo_faststateinit(struct komodo_state *sp,char *fname,char *symbol,ch finished = 1; fprintf(stderr,"took %d seconds to process %s %ldKB\n",(int32_t)(time(NULL)-starttime),fname,datalen/1024); } - else if ( processed > 0 ) + else if ( validated > 0 ) { if ( (indfp= fopen(indfname,"rb+")) != 0 ) { - lastfpos = fpos = processed; + lastfpos = fpos = validated; + fprintf(stderr,"validated %ld -> %ld vs indcounter %u, prevpos100 %u offset.%ld\n",validated,validated/sizeof(uint32_t),indcounter,prevpos100,indcounter * sizeof(uint32_t)); fseek(indfp,indcounter * sizeof(uint32_t),SEEK_SET); if ( ftell(indfp) == indcounter * sizeof(uint32_t) ) { @@ -1510,7 +1510,7 @@ int32_t komodo_faststateinit(struct komodo_state *sp,char *fname,char *symbol,ch printf("unexpected komodostate.ind validate failure %s datalen.%ld\n",indfname,datalen); else { - printf("%s validated updated from processed.%ld to %ld [%ld]\n",indfname,processed,fpos,fpos-processed); + printf("%s validated updated from validated.%ld to %ld [%ld]\n",indfname,validated,fpos,fpos-validated); finished = 1; } } @@ -1518,7 +1518,6 @@ int32_t komodo_faststateinit(struct komodo_state *sp,char *fname,char *symbol,ch free(filedata); return(finished == 1); } - fprintf(stderr,"faststateinit return -1\n"); return(-1); } From e75dc69d019f79fafbd60a787e020650a3363ae5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 5 Nov 2017 12:37:14 +0200 Subject: [PATCH 084/188] Test --- src/komodo_gateway.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index e93d0836c..673f37a7c 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -274,7 +274,7 @@ int32_t komodo_paxcmp(char *symbol,int32_t kmdheight,uint64_t value,uint64_t che return(0); else { - if ( kmdheight >= 238000 ) + if ( ASSETCHAINS_SYMBOL[0] != 0 ) printf("ht.%d ignore mismatched %s value %lld vs checkvalue %lld -> ratio.%d\n",kmdheight,symbol,(long long)value,(long long)checkvalue,ratio); return(-1); } @@ -1418,6 +1418,8 @@ long komodo_stateind_validate(struct komodo_state *sp,char *indfname,uint8_t *fi for (i=0; i n-10 ) + printf("%d: tmp.%08x prevpos100.%u\n",i,tmp,prevpos100); if ( (i % 100) == 0 ) prevpos100 = tmp; else @@ -1498,7 +1500,7 @@ int32_t komodo_faststateinit(struct komodo_state *sp,char *fname,char *symbol,ch if ( (indfp= fopen(indfname,"rb+")) != 0 ) { lastfpos = fpos = validated; - fprintf(stderr,"validated %ld -> %ld vs indcounter %u, prevpos100 %u offset.%ld\n",validated,validated/sizeof(uint32_t),indcounter,prevpos100,indcounter * sizeof(uint32_t)); + fprintf(stderr,"validated %ld -> indcounter %u, prevpos100 %u offset.%ld\n",validated,indcounter,prevpos100,indcounter * sizeof(uint32_t)); fseek(indfp,indcounter * sizeof(uint32_t),SEEK_SET); if ( ftell(indfp) == indcounter * sizeof(uint32_t) ) { @@ -1510,7 +1512,7 @@ int32_t komodo_faststateinit(struct komodo_state *sp,char *fname,char *symbol,ch printf("unexpected komodostate.ind validate failure %s datalen.%ld\n",indfname,datalen); else { - printf("%s validated updated from validated.%ld to %ld [%ld]\n",indfname,validated,fpos,fpos-validated); + printf("%s validated updated from validated.%ld to %ld new.[%ld] -> indcounter %u, prevpos100 %u offset.%ld\n",indfname,validated,fpos,fpos-validated,indcounter,prevpos100,indcounter * sizeof(uint32_t)); finished = 1; } } From 8c18d226b342b9d5fba6ffd7a6fe1a556e148132 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 5 Nov 2017 12:39:07 +0200 Subject: [PATCH 085/188] Test --- src/komodo.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index e49eb7452..77f7dc04b 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -328,7 +328,7 @@ int32_t komodo_parsestatefiledata(struct komodo_state *sp,uint8_t *filedata,long 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 KMDheight,uint32_t KMDtimestamp,uint64_t opretvalue,uint8_t *opretbuf,uint16_t opretlen,uint16_t vout) { static FILE *fp; static int32_t errs,didinit; - struct komodo_state *sp; char fname[512],symbol[16],dest[16]; int32_t ht,func; uint8_t num,pubkeys[64][33]; + struct komodo_state *sp; char fname[512],symbol[16],dest[16]; int32_t retval,ht,func; uint8_t num,pubkeys[64][33]; if ( didinit == 0 ) { portable_mutex_init(&KOMODO_KV_mutex); @@ -346,10 +346,11 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar komodo_statefname(fname,ASSETCHAINS_SYMBOL,(char *)"komodostate"); if ( (fp= fopen(fname,"rb+")) != 0 ) { - if ( komodo_faststateinit(sp,fname,symbol,dest) == 0 ) + if ( (retval= komodo_faststateinit(sp,fname,symbol,dest)) == 0 ) fseek(fp,0,SEEK_END); else { + fprintf(stderr,"komodo_faststateinit retval.%d\n",retval);) while ( komodo_parsestatefile(sp,fp,symbol,dest) >= 0 ) ; } From a3a7ec859293365158a4b7fe035ce4fd9375ce76 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 5 Nov 2017 12:40:11 +0200 Subject: [PATCH 086/188] Test --- src/komodo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index 77f7dc04b..f3d21d634 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -350,7 +350,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar fseek(fp,0,SEEK_END); else { - fprintf(stderr,"komodo_faststateinit retval.%d\n",retval);) + fprintf(stderr,"komodo_faststateinit retval.%d\n",retval); while ( komodo_parsestatefile(sp,fp,symbol,dest) >= 0 ) ; } From f7f9608782eacfd9d803e220edd81bf352fd94de Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 5 Nov 2017 12:48:02 +0200 Subject: [PATCH 087/188] Test --- src/komodo.h | 2 +- src/komodo_gateway.h | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index f3d21d634..02253950e 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -346,7 +346,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar komodo_statefname(fname,ASSETCHAINS_SYMBOL,(char *)"komodostate"); if ( (fp= fopen(fname,"rb+")) != 0 ) { - if ( (retval= komodo_faststateinit(sp,fname,symbol,dest)) == 0 ) + if ( (retval= komodo_faststateinit(sp,fname,symbol,dest)) > 0 ) fseek(fp,0,SEEK_END); else { diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 673f37a7c..e4d368a34 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1412,6 +1412,7 @@ long komodo_stateind_validate(struct komodo_state *sp,char *indfname,uint8_t *fi *indcounterp = *prevpos100p = 0; if ( (inds= OS_fileptr(&fsize,indfname)) != 0 ) { + fprintf(stderr,"validate %s fsize.%ld datalen.%ld n.%ld\n",indfname,fsize,datalen,fsize / sizeof(uint32_t)); if ( (fsize % sizeof(uint32_t)) == 0 ) { n = (int32_t)(fsize / sizeof(uint32_t)); @@ -1419,7 +1420,7 @@ long komodo_stateind_validate(struct komodo_state *sp,char *indfname,uint8_t *fi { memcpy(&tmp,&inds[i * sizeof(uint32_t)],sizeof(uint32_t)); if ( i > n-10 ) - printf("%d: tmp.%08x prevpos100.%u\n",i,tmp,prevpos100); + printf("%d: tmp.%08x [%c] prevpos100.%u\n",i,tmp,tmp&0xff,prevpos100); if ( (i % 100) == 0 ) prevpos100 = tmp; else From 1f14a5164a418d6752922d749b80bfd5a35e744a Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 5 Nov 2017 13:00:24 +0200 Subject: [PATCH 088/188] Test --- src/komodo_gateway.h | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index e4d368a34..abba20564 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1457,7 +1457,8 @@ long komodo_indfile_update(FILE *indfp,uint32_t *prevpos100p,long lastfpos,long tmp = ((uint32_t)(lastfpos - *prevpos100p) << 8) | (func & 0xff); if ( ftell(indfp)/sizeof(uint32_t) != *indcounterp ) printf("indfp fpos %ld -> ind.%ld vs counter.%u\n",ftell(indfp),ftell(indfp)/sizeof(uint32_t),*indcounterp); - fwrite(&tmp,1,sizeof(tmp),indfp), (*indcounterp)++; + fprintf(stderr,"ftell.%ld indcounter.%u lastfpos.%ld newfpos.%ld func.%02x\n",ftell(indfp),*indcounterp,lastfpos,newfpos,func); + fwrite(&tmp,1,sizeof(tmp),indfp), (*indcounterp)++; if ( (*indcounterp % 100) == 0 ) { *prevpos100p = (uint32_t)newfpos; @@ -1506,7 +1507,11 @@ int32_t komodo_faststateinit(struct komodo_state *sp,char *fname,char *symbol,ch if ( ftell(indfp) == indcounter * sizeof(uint32_t) ) { while ( (func= komodo_parsestatefiledata(sp,filedata,&fpos,datalen,symbol,dest)) >= 0 ) + { lastfpos = komodo_indfile_update(indfp,&prevpos100,lastfpos,fpos,func,&indcounter); + if ( lastfpos != fpos ) + fprintf(stderr,"unexpected lastfpos.%ld != %ld\n",lastfpos,fpos); + } } fclose(indfp); if ( komodo_stateind_validate(sp,indfname,filedata,datalen,&prevpos100,&indcounter,symbol,dest) < 0 ) @@ -1528,7 +1533,7 @@ void komodo_passport_iteration() { static long lastpos[34]; static char userpass[33][1024]; static uint32_t lasttime,callcounter; int32_t maxseconds = 10; - FILE *fp; uint8_t *filedata; long fpos,datalen; int32_t baseid,limit,n,ht,isrealtime,expired,refid,blocks,longest; struct komodo_state *sp,*refsp; char *retstr,fname[512],*base,symbol[16],dest[16]; uint32_t buf[3],starttime; cJSON *infoobj,*result; uint64_t RTmask = 0; + FILE *fp; uint8_t *filedata; long fpos,datalen,lastfpos; int32_t baseid,limit,n,ht,isrealtime,expired,refid,blocks,longest; struct komodo_state *sp,*refsp; char *retstr,fname[512],*base,symbol[16],dest[16]; uint32_t buf[3],starttime; cJSON *infoobj,*result; uint64_t RTmask = 0; //printf("PASSPORT.(%s)\n",ASSETCHAINS_SYMBOL); expired = 0; while ( KOMODO_INITDONE == 0 ) @@ -1589,9 +1594,9 @@ void komodo_passport_iteration() fpos = 0; fprintf(stderr,"%s processing %s %ldKB\n",ASSETCHAINS_SYMBOL,fname,datalen/1024); while ( komodo_parsestatefiledata(sp,filedata,&fpos,datalen,symbol,dest) >= 0 ) - ; + lastfpos = fpos; fprintf(stderr,"%s took %d seconds to process %s %ldKB\n",ASSETCHAINS_SYMBOL,(int32_t)(time(NULL)-starttime),fname,datalen/1024); - lastpos[baseid] = fpos; + lastpos[baseid] = lastfpos; free(filedata), filedata = 0; datalen = 0; } From 01c8221f8dcfee9bd3e5d7a5edc114f635f9c636 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 5 Nov 2017 13:21:35 +0200 Subject: [PATCH 089/188] 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 abba20564..78b9c0908 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1441,7 +1441,7 @@ long komodo_stateind_validate(struct komodo_state *sp,char *indfname,uint8_t *fi if ( sp != 0 ) komodo_stateind_set(sp,(uint32_t *)inds,n,filedata,fpos,symbol,dest); free(inds); - return(fpos); + return(datalen); } else printf("wrong filesize %s %ld\n",indfname,fsize); } free(inds); @@ -1490,9 +1490,9 @@ int32_t komodo_faststateinit(struct komodo_state *sp,char *fname,char *symbol,ch if ( indfp != 0 ) { fclose(indfp); - if ( komodo_stateind_validate(0,indfname,filedata,datalen,&prevpos100,&indcounter,symbol,dest) < 0 ) + if ( (fpos= komodo_stateind_validate(0,indfname,filedata,datalen,&prevpos100,&indcounter,symbol,dest)) < 0 ) printf("unexpected komodostate.ind validate failure %s datalen.%ld\n",indfname,datalen); - else printf("%s validated\n",indfname); + else printf("%s validated fpos.%ld\n",indfname,fpos); } finished = 1; fprintf(stderr,"took %d seconds to process %s %ldKB\n",(int32_t)(time(NULL)-starttime),fname,datalen/1024); From 052562c1a2e1875b2a742c54370a04cd6d698eb5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 5 Nov 2017 13:27:22 +0200 Subject: [PATCH 090/188] Test --- src/komodo_gateway.h | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 78b9c0908..57b3a0163 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1534,7 +1534,7 @@ void komodo_passport_iteration() static long lastpos[34]; static char userpass[33][1024]; static uint32_t lasttime,callcounter; int32_t maxseconds = 10; FILE *fp; uint8_t *filedata; long fpos,datalen,lastfpos; int32_t baseid,limit,n,ht,isrealtime,expired,refid,blocks,longest; struct komodo_state *sp,*refsp; char *retstr,fname[512],*base,symbol[16],dest[16]; uint32_t buf[3],starttime; cJSON *infoobj,*result; uint64_t RTmask = 0; - //printf("PASSPORT.(%s)\n",ASSETCHAINS_SYMBOL); + printf("PASSPORT.(%s)\n",ASSETCHAINS_SYMBOL); expired = 0; while ( KOMODO_INITDONE == 0 ) { @@ -1566,11 +1566,6 @@ void komodo_passport_iteration() starttime = (uint32_t)time(NULL); if ( callcounter++ < 1 ) limit = 10000; - if ( 0 && starttime == lasttime ) - { - usleep(1000); - return; - } lasttime = starttime; for (baseid=32; baseid>=0; baseid--) { From 5b5c0bf3eb3d03d28174c2f4879eacdca78f36e0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 5 Nov 2017 13:51:17 +0200 Subject: [PATCH 091/188] test --- src/komodo_gateway.h | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 57b3a0163..9d29a2441 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1408,10 +1408,11 @@ uint8_t *OS_fileptr(long *allocsizep,char *fname) long komodo_stateind_validate(struct komodo_state *sp,char *indfname,uint8_t *filedata,long datalen,uint32_t *prevpos100p,uint32_t *indcounterp,char *symbol,char *dest) { - FILE *fp; long fsize,fpos=-1; uint8_t *inds,func; int32_t i,n; uint32_t offset,tmp,prevpos100 = 0; + FILE *fp; long fsize,lastfpos,fpos=-1; uint8_t *inds,func; int32_t i,n; uint32_t offset,tmp,prevpos100 = 0; *indcounterp = *prevpos100p = 0; if ( (inds= OS_fileptr(&fsize,indfname)) != 0 ) { + lastfpos = 0; fprintf(stderr,"validate %s fsize.%ld datalen.%ld n.%ld\n",indfname,fsize,datalen,fsize / sizeof(uint32_t)); if ( (fsize % sizeof(uint32_t)) == 0 ) { @@ -1428,12 +1429,13 @@ long komodo_stateind_validate(struct komodo_state *sp,char *indfname,uint8_t *fi func = (tmp & 0xff); offset = (tmp >> 8); fpos = prevpos100 + offset; - if ( fpos >= datalen || filedata[fpos] != func ) + if ( fpos >= datalen || filedata[lastfpos] != func ) { printf("validate.%d error (%u %d) prev100 %u -> fpos.%ld datalen.%ld [%d]\n",i,offset,func,prevpos100,fpos,datalen,fpos < datalen ? filedata[fpos] : -1); return(-1); } } + lastfpos = fpos; } *indcounterp = n; *prevpos100p = prevpos100; @@ -1441,7 +1443,7 @@ long komodo_stateind_validate(struct komodo_state *sp,char *indfname,uint8_t *fi if ( sp != 0 ) komodo_stateind_set(sp,(uint32_t *)inds,n,filedata,fpos,symbol,dest); free(inds); - return(datalen); + return(fpos); } else printf("wrong filesize %s %ld\n",indfname,fsize); } free(inds); @@ -1454,7 +1456,7 @@ long komodo_indfile_update(FILE *indfp,uint32_t *prevpos100p,long lastfpos,long uint32_t tmp; if ( indfp != 0 ) { - tmp = ((uint32_t)(lastfpos - *prevpos100p) << 8) | (func & 0xff); + tmp = ((uint32_t)(newfpos - *prevpos100p) << 8) | (func & 0xff); if ( ftell(indfp)/sizeof(uint32_t) != *indcounterp ) printf("indfp fpos %ld -> ind.%ld vs counter.%u\n",ftell(indfp),ftell(indfp)/sizeof(uint32_t),*indcounterp); fprintf(stderr,"ftell.%ld indcounter.%u lastfpos.%ld newfpos.%ld func.%02x\n",ftell(indfp),*indcounterp,lastfpos,newfpos,func); @@ -1534,7 +1536,6 @@ void komodo_passport_iteration() static long lastpos[34]; static char userpass[33][1024]; static uint32_t lasttime,callcounter; int32_t maxseconds = 10; FILE *fp; uint8_t *filedata; long fpos,datalen,lastfpos; int32_t baseid,limit,n,ht,isrealtime,expired,refid,blocks,longest; struct komodo_state *sp,*refsp; char *retstr,fname[512],*base,symbol[16],dest[16]; uint32_t buf[3],starttime; cJSON *infoobj,*result; uint64_t RTmask = 0; - printf("PASSPORT.(%s)\n",ASSETCHAINS_SYMBOL); expired = 0; while ( KOMODO_INITDONE == 0 ) { From 5d5c720dbf2b9c6554bc09bb33ef7ef4fbba09e4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 5 Nov 2017 14:23:38 +0200 Subject: [PATCH 092/188] 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 9d29a2441..edacc2664 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1429,9 +1429,9 @@ long komodo_stateind_validate(struct komodo_state *sp,char *indfname,uint8_t *fi func = (tmp & 0xff); offset = (tmp >> 8); fpos = prevpos100 + offset; - if ( fpos >= datalen || filedata[lastfpos] != func ) + if ( lastfpos >= datalen || filedata[lastfpos] != func ) { - printf("validate.%d error (%u %d) prev100 %u -> fpos.%ld datalen.%ld [%d]\n",i,offset,func,prevpos100,fpos,datalen,fpos < datalen ? filedata[fpos] : -1); + printf("validate.%d error (%u %d) prev100 %u -> fpos.%ld datalen.%ld [%d] (%c) vs (%c)\n",i,offset,func,prevpos100,fpos,datalen,lastfpos < datalen ? filedata[lastfpos] : -1,func,filedata[lastfpos]); return(-1); } } From 75f0def0129b31fe31ba17431d170be2e712f14f Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 5 Nov 2017 14:33:18 +0200 Subject: [PATCH 093/188] Test --- src/komodo_gateway.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index edacc2664..1116b639d 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1413,7 +1413,7 @@ long komodo_stateind_validate(struct komodo_state *sp,char *indfname,uint8_t *fi if ( (inds= OS_fileptr(&fsize,indfname)) != 0 ) { lastfpos = 0; - fprintf(stderr,"validate %s fsize.%ld datalen.%ld n.%ld\n",indfname,fsize,datalen,fsize / sizeof(uint32_t)); + fprintf(stderr,"validate %s fsize.%ld datalen.%ld n.%ld lastfpos.%ld\n",indfname,fsize,datalen,fsize / sizeof(uint32_t),lastfpos); if ( (fsize % sizeof(uint32_t)) == 0 ) { n = (int32_t)(fsize / sizeof(uint32_t)); @@ -1431,7 +1431,8 @@ long komodo_stateind_validate(struct komodo_state *sp,char *indfname,uint8_t *fi fpos = prevpos100 + offset; if ( lastfpos >= datalen || filedata[lastfpos] != func ) { - printf("validate.%d error (%u %d) prev100 %u -> fpos.%ld datalen.%ld [%d] (%c) vs (%c)\n",i,offset,func,prevpos100,fpos,datalen,lastfpos < datalen ? filedata[lastfpos] : -1,func,filedata[lastfpos]); + printf("validate.%d error (%u %d) prev100 %u -> fpos.%ld datalen.%ld [%d] (%c) vs (%c) lastfpos.%ld\n",i,offset,func,prevpos100,fpos,datalen,lastfpos < datalen ? filedata[lastfpos] : -1,func,filedata[lastfpos],lastfpos); + exit(-1); return(-1); } } From ac7d572b6904ee5093de89889c60cda916b5fb97 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 5 Nov 2017 14:37:48 +0200 Subject: [PATCH 094/188] 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 1116b639d..fe48c9718 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1408,7 +1408,7 @@ uint8_t *OS_fileptr(long *allocsizep,char *fname) long komodo_stateind_validate(struct komodo_state *sp,char *indfname,uint8_t *filedata,long datalen,uint32_t *prevpos100p,uint32_t *indcounterp,char *symbol,char *dest) { - FILE *fp; long fsize,lastfpos,fpos=-1; uint8_t *inds,func; int32_t i,n; uint32_t offset,tmp,prevpos100 = 0; + FILE *fp; long fsize,lastfpos=0,fpos=-1; uint8_t *inds,func; int32_t i,n; uint32_t offset,tmp,prevpos100 = 0; *indcounterp = *prevpos100p = 0; if ( (inds= OS_fileptr(&fsize,indfname)) != 0 ) { From d60660744902fadc0fdeae31163feee54d1d2355 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 5 Nov 2017 14:40:16 +0200 Subject: [PATCH 095/188] 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 fe48c9718..9a2a9e840 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1408,7 +1408,7 @@ uint8_t *OS_fileptr(long *allocsizep,char *fname) long komodo_stateind_validate(struct komodo_state *sp,char *indfname,uint8_t *filedata,long datalen,uint32_t *prevpos100p,uint32_t *indcounterp,char *symbol,char *dest) { - FILE *fp; long fsize,lastfpos=0,fpos=-1; uint8_t *inds,func; int32_t i,n; uint32_t offset,tmp,prevpos100 = 0; + FILE *fp; long fsize,lastfpos=0,fpos=0; uint8_t *inds,func; int32_t i,n; uint32_t offset,tmp,prevpos100 = 0; *indcounterp = *prevpos100p = 0; if ( (inds= OS_fileptr(&fsize,indfname)) != 0 ) { From 651ce5743f530ef5ac11af6bec0c22a35c589711 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 5 Nov 2017 14:54:47 +0200 Subject: [PATCH 096/188] Test --- src/komodo_gateway.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 9a2a9e840..49dc005d1 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1413,7 +1413,7 @@ long komodo_stateind_validate(struct komodo_state *sp,char *indfname,uint8_t *fi if ( (inds= OS_fileptr(&fsize,indfname)) != 0 ) { lastfpos = 0; - fprintf(stderr,"validate %s fsize.%ld datalen.%ld n.%ld lastfpos.%ld\n",indfname,fsize,datalen,fsize / sizeof(uint32_t),lastfpos); + //fprintf(stderr,"validate %s fsize.%ld datalen.%ld n.%ld lastfpos.%ld\n",indfname,fsize,datalen,fsize / sizeof(uint32_t),lastfpos); if ( (fsize % sizeof(uint32_t)) == 0 ) { n = (int32_t)(fsize / sizeof(uint32_t)); @@ -1432,7 +1432,6 @@ long komodo_stateind_validate(struct komodo_state *sp,char *indfname,uint8_t *fi if ( lastfpos >= datalen || filedata[lastfpos] != func ) { printf("validate.%d error (%u %d) prev100 %u -> fpos.%ld datalen.%ld [%d] (%c) vs (%c) lastfpos.%ld\n",i,offset,func,prevpos100,fpos,datalen,lastfpos < datalen ? filedata[lastfpos] : -1,func,filedata[lastfpos],lastfpos); - exit(-1); return(-1); } } @@ -1460,7 +1459,7 @@ long komodo_indfile_update(FILE *indfp,uint32_t *prevpos100p,long lastfpos,long tmp = ((uint32_t)(newfpos - *prevpos100p) << 8) | (func & 0xff); if ( ftell(indfp)/sizeof(uint32_t) != *indcounterp ) printf("indfp fpos %ld -> ind.%ld vs counter.%u\n",ftell(indfp),ftell(indfp)/sizeof(uint32_t),*indcounterp); - fprintf(stderr,"ftell.%ld indcounter.%u lastfpos.%ld newfpos.%ld func.%02x\n",ftell(indfp),*indcounterp,lastfpos,newfpos,func); + //fprintf(stderr,"ftell.%ld indcounter.%u lastfpos.%ld newfpos.%ld func.%02x\n",ftell(indfp),*indcounterp,lastfpos,newfpos,func); fwrite(&tmp,1,sizeof(tmp),indfp), (*indcounterp)++; if ( (*indcounterp % 100) == 0 ) { From 95880660c64cc6289955968ad672ff40aa83a7c9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 5 Nov 2017 15:02:23 +0200 Subject: [PATCH 097/188] 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 49dc005d1..68367718e 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1420,7 +1420,7 @@ long komodo_stateind_validate(struct komodo_state *sp,char *indfname,uint8_t *fi for (i=0; i n-10 ) + if ( 0 && i > n-10 ) printf("%d: tmp.%08x [%c] prevpos100.%u\n",i,tmp,tmp&0xff,prevpos100); if ( (i % 100) == 0 ) prevpos100 = tmp; @@ -1439,7 +1439,7 @@ long komodo_stateind_validate(struct komodo_state *sp,char *indfname,uint8_t *fi } *indcounterp = n; *prevpos100p = prevpos100; - printf("%s validated[%d] fpos.%ld datalen.%ld\n",indfname,i,fpos,datalen); + printf("%s validated[%d] fpos.%ld datalen.%ld, offset %ld vs fsize.%ld\n",indfname,i,fpos,datalen,i * sizeof(uint32_t),fsize); if ( sp != 0 ) komodo_stateind_set(sp,(uint32_t *)inds,n,filedata,fpos,symbol,dest); free(inds); From e3c63db23b06ddd35c0ef000851aad517f4c906f Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 5 Nov 2017 15:06:37 +0200 Subject: [PATCH 098/188] Test --- src/komodo_gateway.h | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 68367718e..766df3995 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1459,7 +1459,7 @@ long komodo_indfile_update(FILE *indfp,uint32_t *prevpos100p,long lastfpos,long tmp = ((uint32_t)(newfpos - *prevpos100p) << 8) | (func & 0xff); if ( ftell(indfp)/sizeof(uint32_t) != *indcounterp ) printf("indfp fpos %ld -> ind.%ld vs counter.%u\n",ftell(indfp),ftell(indfp)/sizeof(uint32_t),*indcounterp); - //fprintf(stderr,"ftell.%ld indcounter.%u lastfpos.%ld newfpos.%ld func.%02x\n",ftell(indfp),*indcounterp,lastfpos,newfpos,func); + fprintf(stderr,"ftell.%ld indcounter.%u lastfpos.%ld newfpos.%ld func.%02x\n",ftell(indfp),*indcounterp,lastfpos,newfpos,func); fwrite(&tmp,1,sizeof(tmp),indfp), (*indcounterp)++; if ( (*indcounterp % 100) == 0 ) { @@ -1504,18 +1504,21 @@ int32_t komodo_faststateinit(struct komodo_state *sp,char *fname,char *symbol,ch if ( (indfp= fopen(indfname,"rb+")) != 0 ) { lastfpos = fpos = validated; - fprintf(stderr,"validated %ld -> indcounter %u, prevpos100 %u offset.%ld\n",validated,indcounter,prevpos100,indcounter * sizeof(uint32_t)); - fseek(indfp,indcounter * sizeof(uint32_t),SEEK_SET); - if ( ftell(indfp) == indcounter * sizeof(uint32_t) ) + fprintf(stderr,"datalen.%ld validated %ld -> indcounter %u, prevpos100 %u offset.%ld\n",datalen,validated,indcounter,prevpos100,indcounter * sizeof(uint32_t)); + if ( fpos < datalen ) { - while ( (func= komodo_parsestatefiledata(sp,filedata,&fpos,datalen,symbol,dest)) >= 0 ) + fseek(indfp,indcounter * sizeof(uint32_t),SEEK_SET); + if ( ftell(indfp) == indcounter * sizeof(uint32_t) ) { - lastfpos = komodo_indfile_update(indfp,&prevpos100,lastfpos,fpos,func,&indcounter); - if ( lastfpos != fpos ) - fprintf(stderr,"unexpected lastfpos.%ld != %ld\n",lastfpos,fpos); + while ( (func= komodo_parsestatefiledata(sp,filedata,&fpos,datalen,symbol,dest)) >= 0 ) + { + lastfpos = komodo_indfile_update(indfp,&prevpos100,lastfpos,fpos,func,&indcounter); + if ( lastfpos != fpos ) + fprintf(stderr,"unexpected lastfpos.%ld != %ld\n",lastfpos,fpos); + } } + fclose(indfp); } - fclose(indfp); if ( komodo_stateind_validate(sp,indfname,filedata,datalen,&prevpos100,&indcounter,symbol,dest) < 0 ) printf("unexpected komodostate.ind validate failure %s datalen.%ld\n",indfname,datalen); else From b883389a8207fa9e5ac74024df6faa40d0f67804 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 5 Nov 2017 15:12:47 +0200 Subject: [PATCH 099/188] 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 766df3995..ca43d184d 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1413,7 +1413,7 @@ long komodo_stateind_validate(struct komodo_state *sp,char *indfname,uint8_t *fi if ( (inds= OS_fileptr(&fsize,indfname)) != 0 ) { lastfpos = 0; - //fprintf(stderr,"validate %s fsize.%ld datalen.%ld n.%ld lastfpos.%ld\n",indfname,fsize,datalen,fsize / sizeof(uint32_t),lastfpos); + fprintf(stderr,"inds.%p validate %s fsize.%ld datalen.%ld n.%ld lastfpos.%ld\n",inds,indfname,fsize,datalen,fsize / sizeof(uint32_t),lastfpos); if ( (fsize % sizeof(uint32_t)) == 0 ) { n = (int32_t)(fsize / sizeof(uint32_t)); @@ -1439,9 +1439,9 @@ long komodo_stateind_validate(struct komodo_state *sp,char *indfname,uint8_t *fi } *indcounterp = n; *prevpos100p = prevpos100; - printf("%s validated[%d] fpos.%ld datalen.%ld, offset %ld vs fsize.%ld\n",indfname,i,fpos,datalen,i * sizeof(uint32_t),fsize); if ( sp != 0 ) komodo_stateind_set(sp,(uint32_t *)inds,n,filedata,fpos,symbol,dest); + printf("free inds.%p %s validated[%d] fpos.%ld datalen.%ld, offset %ld vs fsize.%ld\n",inds,indfname,i,fpos,datalen,i * sizeof(uint32_t),fsize); free(inds); return(fpos); } else printf("wrong filesize %s %ld\n",indfname,fsize); @@ -1519,6 +1519,7 @@ int32_t komodo_faststateinit(struct komodo_state *sp,char *fname,char *symbol,ch } fclose(indfp); } + printf("call validate datalen.%ld\n",datalen); if ( komodo_stateind_validate(sp,indfname,filedata,datalen,&prevpos100,&indcounter,symbol,dest) < 0 ) printf("unexpected komodostate.ind validate failure %s datalen.%ld\n",indfname,datalen); else @@ -1528,6 +1529,7 @@ int32_t komodo_faststateinit(struct komodo_state *sp,char *fname,char *symbol,ch } } } else printf("komodo_faststateinit unexpected case\n"); + printf("free filedata.%p\n",filedata); free(filedata); return(finished == 1); } From 3e394a57e006a922b7df173a2fef6de1526dfbfb Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 5 Nov 2017 15:16:04 +0200 Subject: [PATCH 100/188] 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 ca43d184d..4e2bbcabf 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1418,7 +1418,7 @@ long komodo_stateind_validate(struct komodo_state *sp,char *indfname,uint8_t *fi { n = (int32_t)(fsize / sizeof(uint32_t)); for (i=0; i n-10 ) printf("%d: tmp.%08x [%c] prevpos100.%u\n",i,tmp,tmp&0xff,prevpos100); From 05d9b22010c98eca43beeb29aa20e7f17f1a3f90 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 5 Nov 2017 15:18:10 +0200 Subject: [PATCH 101/188] Test --- src/komodo_gateway.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 4e2bbcabf..62957da3b 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1437,6 +1437,7 @@ long komodo_stateind_validate(struct komodo_state *sp,char *indfname,uint8_t *fi } lastfpos = fpos; } +fpos=datalen; *indcounterp = n; *prevpos100p = prevpos100; if ( sp != 0 ) From 37c74e15e16baa35eef934c9d84a920a4d230cfd Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 5 Nov 2017 15:20:09 +0200 Subject: [PATCH 102/188] Test --- src/komodo_gateway.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 62957da3b..53e31317f 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1418,7 +1418,7 @@ long komodo_stateind_validate(struct komodo_state *sp,char *indfname,uint8_t *fi { n = (int32_t)(fsize / sizeof(uint32_t)); for (i=0; i n-10 ) printf("%d: tmp.%08x [%c] prevpos100.%u\n",i,tmp,tmp&0xff,prevpos100); @@ -1437,13 +1437,12 @@ long komodo_stateind_validate(struct komodo_state *sp,char *indfname,uint8_t *fi } lastfpos = fpos; } -fpos=datalen; *indcounterp = n; *prevpos100p = prevpos100; if ( sp != 0 ) komodo_stateind_set(sp,(uint32_t *)inds,n,filedata,fpos,symbol,dest); + else free(inds); printf("free inds.%p %s validated[%d] fpos.%ld datalen.%ld, offset %ld vs fsize.%ld\n",inds,indfname,i,fpos,datalen,i * sizeof(uint32_t),fsize); - free(inds); return(fpos); } else printf("wrong filesize %s %ld\n",indfname,fsize); } From 2baa86a396ca67826f05269b18857f82b2f2b29e Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 5 Nov 2017 15:22:53 +0200 Subject: [PATCH 103/188] 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 53e31317f..4f5abb2fc 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1377,10 +1377,10 @@ void *OS_loadfile(char *fname,uint8_t **bufp,long *lenp,long *allocsizep) printf("OS_loadfile null size.(%s)\n",fname); return(0); } - if ( filesize > buflen-1 ) + if ( filesize > buflen ) { *allocsizep = filesize; - *bufp = buf = (uint8_t *)realloc(buf,(long)*allocsizep); + *bufp = buf = (uint8_t *)realloc(buf,(long)*allocsizep+64); } rewind(fp); if ( buf == 0 ) @@ -1441,8 +1441,8 @@ long komodo_stateind_validate(struct komodo_state *sp,char *indfname,uint8_t *fi *prevpos100p = prevpos100; if ( sp != 0 ) komodo_stateind_set(sp,(uint32_t *)inds,n,filedata,fpos,symbol,dest); - else free(inds); printf("free inds.%p %s validated[%d] fpos.%ld datalen.%ld, offset %ld vs fsize.%ld\n",inds,indfname,i,fpos,datalen,i * sizeof(uint32_t),fsize); + free(inds); return(fpos); } else printf("wrong filesize %s %ld\n",indfname,fsize); } From dbd0722f1c2806a004a9e3f6407bcb3d71259ebc Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 5 Nov 2017 15:25:59 +0200 Subject: [PATCH 104/188] Test --- src/komodo_gateway.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 4f5abb2fc..c795f5b74 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1441,7 +1441,7 @@ long komodo_stateind_validate(struct komodo_state *sp,char *indfname,uint8_t *fi *prevpos100p = prevpos100; if ( sp != 0 ) komodo_stateind_set(sp,(uint32_t *)inds,n,filedata,fpos,symbol,dest); - printf("free inds.%p %s validated[%d] fpos.%ld datalen.%ld, offset %ld vs fsize.%ld\n",inds,indfname,i,fpos,datalen,i * sizeof(uint32_t),fsize); + //printf("free inds.%p %s validated[%d] fpos.%ld datalen.%ld, offset %ld vs fsize.%ld\n",inds,indfname,i,fpos,datalen,i * sizeof(uint32_t),fsize); free(inds); return(fpos); } else printf("wrong filesize %s %ld\n",indfname,fsize); @@ -1519,17 +1519,15 @@ int32_t komodo_faststateinit(struct komodo_state *sp,char *fname,char *symbol,ch } fclose(indfp); } - printf("call validate datalen.%ld\n",datalen); if ( komodo_stateind_validate(sp,indfname,filedata,datalen,&prevpos100,&indcounter,symbol,dest) < 0 ) printf("unexpected komodostate.ind validate failure %s datalen.%ld\n",indfname,datalen); else { - printf("%s validated updated from validated.%ld to %ld new.[%ld] -> indcounter %u, prevpos100 %u offset.%ld\n",indfname,validated,fpos,fpos-validated,indcounter,prevpos100,indcounter * sizeof(uint32_t)); + printf("%s validated updated from validated.%ld to %ld new.[%ld] -> indcounter %u, prevpos100 %u offset.%ld | elapsed %d seconds\n",indfname,validated,fpos,fpos-validated,indcounter,prevpos100,indcounter * sizeof(uint32_t),(int32_t)(time(NULL) - starttime)); finished = 1; } } } else printf("komodo_faststateinit unexpected case\n"); - printf("free filedata.%p\n",filedata); free(filedata); return(finished == 1); } From 43430608217eddac9cc2745f1aa51b216c6a36be Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 5 Nov 2017 16:22:06 +0200 Subject: [PATCH 105/188] Test --- src/komodo_gateway.h | 129 ++++++++++++++++++++++++++++++++++++--- src/wallet/rpcwallet.cpp | 2 + 2 files changed, 124 insertions(+), 7 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index c795f5b74..fe0e13b7e 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1036,8 +1036,6 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 //printf("komodo_opreturn skip %s\n",ASSETCHAINS_SYMBOL); return("assetchain"); } - //else if ( KOMODO_PAX == 0 ) - // return("nopax"); memset(baseids,0xff,sizeof(baseids)); memset(values,0,sizeof(values)); memset(srcvalues,0,sizeof(srcvalues)); @@ -1048,8 +1046,11 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 if ( opretbuf[0] == 'K' && opretlen != 40 ) { komodo_kvupdate(opretbuf,opretlen,value); + return("kv"); } - else if ( opretbuf[0] == 'D' ) + else if ( KOMODO_PAX == 0 ) + return("nopax"); + if ( opretbuf[0] == 'D' ) { tokomodo = 0; if ( opretlen == 38 ) // any KMD tx @@ -1355,9 +1356,123 @@ int32_t komodo_parsestatefiledata(struct komodo_state *sp,uint8_t *filedata,long void komodo_stateind_set(struct komodo_state *sp,uint32_t *inds,int32_t n,uint8_t *filedata,long datalen,char *symbol,char *dest) { - uint8_t func; long fpos; - //komodo_parsestatefiledata(sp,filedata,&fpos,datalen,symbol,dest); - // scan backwards to set all the sp-> fields to the current valid value + uint8_t func; long lastK,lastT,lastN,lastV,fpos=0,lastfpos=0; int32_t i,count,doissue,iter,numn,numv,numN,numV; uint32_t tmp,prevpos100; + count = numN = numV = numn = numv = 0; + lastK = lastT = lastN = lastV; + for (iter=0; iter<2; iter++) + { + for (prevpos100=i=0; i> 8); + fpos = prevpos100 + offset; + if ( lastfpos >= datalen || filedata[lastfpos] != func ) + printf("lastfpos.%ld >= datalen.%ld or [%d] != fund.%d\n",lastfpos,datalen,filedata[lastfpos],func); + else if ( iter == 0 ) + { + switch ( func ) + { + default: case 'P': case 'U': case 'D': + inds[i] &= 0xffffff00; + break; + case 'K': + lastK = lastfpos; + inds[i] &= 0xffffff00; + break; + case 'T': + lastT = lastfpos; + inds[i] &= 0xffffff00; + break; + case 'N': + lastN = lastfpos; + numN++; + break; + case 'V': + lastV = lastfpos; + numV++; + break; + case 'R': break; + } + } + else + { + doissue = 0; + if ( func == 'K' ) + { + if ( lastK == lastfpos ) + doissue = 1, printf("trigger lastK\n"); + } + else if ( func == 'T' ) + { + if ( lastT == lastfpos ) + doissue = 1, printf("trigger lastT\n"); + } + else if ( func == 'N' ) + { + if ( numn > numN-128 ) + doissue = 1; + numn++; + } + else if ( func == 'V' ) + { + if ( numv > numV-1440 ) + doissue = 1; + numv++; + } + else if ( func == 'R' ) + doissue = 1; + if ( doissue != 0 ) + { + printf("issue %c total.%d lastfpos.%ld\n",func,count,lastfpos); + komodo_parsestatefiledata(sp,filedata,&lastfpos,datalen,symbol,dest); + count++; + } + } + } + lastfpos = fpos; + } + } + + else if ( func == 'K' ) // KMD height: stop after 1st + else if ( func == 'T' ) // KMD height+timestamp: stop after 1st + + else if ( func == 'N' ) // notarization, scan backwards 1440+ blocks; + else if ( func == 'V' ) // price feed: can stop after 1440+ + else if ( func == 'R' ) // opreturn: + { + uint16_t olen,v; uint64_t ovalue; uint256 txid; uint8_t opret[16384]; + if ( memread(&txid,sizeof(txid),filedata,&fpos,datalen) != sizeof(txid) ) + errs++; + if ( memread(&v,sizeof(v),filedata,&fpos,datalen) != sizeof(v) ) + errs++; + if ( memread(&ovalue,sizeof(ovalue),filedata,&fpos,datalen) != sizeof(ovalue) ) + errs++; + if ( memread(&olen,sizeof(olen),filedata,&fpos,datalen) != sizeof(olen) ) + errs++; + if ( olen < sizeof(opret) ) + { + if ( memread(opret,olen,filedata,&fpos,datalen) != olen ) + errs++; + if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 && matched != 0 ) + { + int32_t i; for (i=0; i global PAX + } else + { + int32_t i; + for (i=0; i ind.%ld vs counter.%u\n",ftell(indfp),ftell(indfp)/sizeof(uint32_t),*indcounterp); - fprintf(stderr,"ftell.%ld indcounter.%u lastfpos.%ld newfpos.%ld func.%02x\n",ftell(indfp),*indcounterp,lastfpos,newfpos,func); + //fprintf(stderr,"ftell.%ld indcounter.%u lastfpos.%ld newfpos.%ld func.%02x\n",ftell(indfp),*indcounterp,lastfpos,newfpos,func); fwrite(&tmp,1,sizeof(tmp),indfp), (*indcounterp)++; if ( (*indcounterp % 100) == 0 ) { diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 21ee626f6..269b306cc 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -612,6 +612,8 @@ UniValue paxdeposit(const UniValue& params, bool fHelp) { uint64_t available,deposited,issued,withdrawn,approved,redeemed,seed,komodoshis = 0; int32_t height; char destaddr[64]; uint8_t i,pubkey37[33]; bool fSubtractFeeFromAmount = false; + if ( KOMODO_PAX == 0 ) + throw JSONRPCError(RPC_TYPE_ERROR, "paxdeposit disabled, since pax not enabled with komodod -pax"); if ( komodo_is_issuer() != 0 ) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "paxdeposit only from KMD"); if (!EnsureWalletIsAvailable(fHelp)) From bf9c62be24aa97eb83487c9bed2c16ecc6620277 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 5 Nov 2017 16:24:33 +0200 Subject: [PATCH 106/188] Test --- src/komodo_gateway.h | 36 +++--------------------------------- 1 file changed, 3 insertions(+), 33 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index fe0e13b7e..1fb2e3b23 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1356,7 +1356,7 @@ int32_t komodo_parsestatefiledata(struct komodo_state *sp,uint8_t *filedata,long void komodo_stateind_set(struct komodo_state *sp,uint32_t *inds,int32_t n,uint8_t *filedata,long datalen,char *symbol,char *dest) { - uint8_t func; long lastK,lastT,lastN,lastV,fpos=0,lastfpos=0; int32_t i,count,doissue,iter,numn,numv,numN,numV; uint32_t tmp,prevpos100; + uint8_t func; long lastK,lastT,lastN,lastV,fpos=0,lastfpos=0; int32_t i,count,doissue,iter,numn,numv,numN,numV; uint32_t tmp,prevpos100,offset; count = numN = numV = numn = numv = 0; lastK = lastT = lastN = lastV; for (iter=0; iter<2; iter++) @@ -1437,42 +1437,12 @@ void komodo_stateind_set(struct komodo_state *sp,uint32_t *inds,int32_t n,uint8_ lastfpos = fpos; } } - - else if ( func == 'K' ) // KMD height: stop after 1st + /*else if ( func == 'K' ) // KMD height: stop after 1st else if ( func == 'T' ) // KMD height+timestamp: stop after 1st else if ( func == 'N' ) // notarization, scan backwards 1440+ blocks; else if ( func == 'V' ) // price feed: can stop after 1440+ - else if ( func == 'R' ) // opreturn: - { - uint16_t olen,v; uint64_t ovalue; uint256 txid; uint8_t opret[16384]; - if ( memread(&txid,sizeof(txid),filedata,&fpos,datalen) != sizeof(txid) ) - errs++; - if ( memread(&v,sizeof(v),filedata,&fpos,datalen) != sizeof(v) ) - errs++; - if ( memread(&ovalue,sizeof(ovalue),filedata,&fpos,datalen) != sizeof(ovalue) ) - errs++; - if ( memread(&olen,sizeof(olen),filedata,&fpos,datalen) != sizeof(olen) ) - errs++; - if ( olen < sizeof(opret) ) - { - if ( memread(opret,olen,filedata,&fpos,datalen) != olen ) - errs++; - if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 && matched != 0 ) - { - int32_t i; for (i=0; i global PAX - } else - { - int32_t i; - for (i=0; i Date: Sun, 5 Nov 2017 16:26:53 +0200 Subject: [PATCH 107/188] Test --- src/wallet/rpcwallet.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 269b306cc..ee9fb71bb 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -480,6 +480,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]; +extern int32_t KOMODO_PAX; int32_t komodo_is_issuer(); int32_t iguana_rwnum(int32_t rwflag,uint8_t *serialized,int32_t len,void *endianedp); int32_t komodo_isrealtime(int32_t *kmdheightp); From 4978e8cfda68f3dd1514f3572683aa2631f2f8cc Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 5 Nov 2017 16:31:02 +0200 Subject: [PATCH 108/188] 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 1fb2e3b23..a757624fd 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1371,8 +1371,8 @@ void komodo_stateind_set(struct komodo_state *sp,uint32_t *inds,int32_t n,uint8_ func = (tmp & 0xff); offset = (tmp >> 8); fpos = prevpos100 + offset; - if ( lastfpos >= datalen || filedata[lastfpos] != func ) - printf("lastfpos.%ld >= datalen.%ld or [%d] != fund.%d\n",lastfpos,datalen,filedata[lastfpos],func); + if ( lastfpos >= datalen || (filedata[lastfpos] != func && func != 0) ) + printf("lastfpos.%ld >= datalen.%ld or [%d] != func.%d\n",lastfpos,datalen,filedata[lastfpos],func); else if ( iter == 0 ) { switch ( func ) From 40537f140ba1d27caca9f3c10e13f3bcb2309f52 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 5 Nov 2017 16:32:59 +0200 Subject: [PATCH 109/188] Test --- src/komodo_gateway.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index a757624fd..5969fb4c0 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1357,8 +1357,8 @@ int32_t komodo_parsestatefiledata(struct komodo_state *sp,uint8_t *filedata,long void komodo_stateind_set(struct komodo_state *sp,uint32_t *inds,int32_t n,uint8_t *filedata,long datalen,char *symbol,char *dest) { uint8_t func; long lastK,lastT,lastN,lastV,fpos=0,lastfpos=0; int32_t i,count,doissue,iter,numn,numv,numN,numV; uint32_t tmp,prevpos100,offset; - count = numN = numV = numn = numv = 0; - lastK = lastT = lastN = lastV; + count = numR = numN = numV = numn = numv = 0; + lastK = lastT = lastN = lastV = -1; for (iter=0; iter<2; iter++) { for (prevpos100=i=0; i Date: Sun, 5 Nov 2017 16:34:01 +0200 Subject: [PATCH 110/188] 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 5969fb4c0..aecb9fbf5 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1356,7 +1356,7 @@ int32_t komodo_parsestatefiledata(struct komodo_state *sp,uint8_t *filedata,long void komodo_stateind_set(struct komodo_state *sp,uint32_t *inds,int32_t n,uint8_t *filedata,long datalen,char *symbol,char *dest) { - uint8_t func; long lastK,lastT,lastN,lastV,fpos=0,lastfpos=0; int32_t i,count,doissue,iter,numn,numv,numN,numV; uint32_t tmp,prevpos100,offset; + uint8_t func; long lastK,lastT,lastN,lastV,fpos=0,lastfpos=0; int32_t i,count,doissue,iter,numn,numv,numN,numV,numR; uint32_t tmp,prevpos100,offset; count = numR = numN = numV = numn = numv = 0; lastK = lastT = lastN = lastV = -1; for (iter=0; iter<2; iter++) From 0c6f830182cc68845b7e221f5b8dfa3b877e8009 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 5 Nov 2017 16:43:51 +0200 Subject: [PATCH 111/188] 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 aecb9fbf5..20cdbc05f 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1372,7 +1372,7 @@ void komodo_stateind_set(struct komodo_state *sp,uint32_t *inds,int32_t n,uint8_ offset = (tmp >> 8); fpos = prevpos100 + offset; if ( lastfpos >= datalen || (filedata[lastfpos] != func && func != 0) ) - printf("lastfpos.%ld >= datalen.%ld or [%d] != func.%d\n",lastfpos,datalen,filedata[lastfpos],func); + printf("i.%d/n.%d lastfpos.%ld >= datalen.%ld or [%d] != func.%d\n",i,n,lastfpos,datalen,filedata[lastfpos],func); else if ( iter == 0 ) { switch ( func ) @@ -1422,7 +1422,7 @@ void komodo_stateind_set(struct komodo_state *sp,uint32_t *inds,int32_t n,uint8_ } else if ( func == 'V' ) { - if ( numv > numV-1440 ) + if ( KOMODO_PAX != 0 || numv > numV-1440 ) doissue = 1; numv++; } From 7730b5c45ab863e7abe90f8030de73b843e255fa Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 5 Nov 2017 16:46:02 +0200 Subject: [PATCH 112/188] 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 20cdbc05f..a7ee5eaa2 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1149,7 +1149,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 if ( baseids[i] < 0 ) { static uint32_t counter; - if ( counter++ < 3 ) + if ( ++counter < 1 ) printf("%d of %d illegal baseid.%d, this can be ignored\n",i,n,baseids[i]); continue; } @@ -1356,12 +1356,12 @@ int32_t komodo_parsestatefiledata(struct komodo_state *sp,uint8_t *filedata,long void komodo_stateind_set(struct komodo_state *sp,uint32_t *inds,int32_t n,uint8_t *filedata,long datalen,char *symbol,char *dest) { - uint8_t func; long lastK,lastT,lastN,lastV,fpos=0,lastfpos=0; int32_t i,count,doissue,iter,numn,numv,numN,numV,numR; uint32_t tmp,prevpos100,offset; + uint8_t func; long lastK,lastT,lastN,lastV,fpos,lastfpos; int32_t i,count,doissue,iter,numn,numv,numN,numV,numR; uint32_t tmp,prevpos100,offset; count = numR = numN = numV = numn = numv = 0; lastK = lastT = lastN = lastV = -1; for (iter=0; iter<2; iter++) { - for (prevpos100=i=0; i Date: Sun, 5 Nov 2017 16:46:45 +0200 Subject: [PATCH 113/188] 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 a7ee5eaa2..8a9baee45 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1361,7 +1361,7 @@ void komodo_stateind_set(struct komodo_state *sp,uint32_t *inds,int32_t n,uint8_ lastK = lastT = lastN = lastV = -1; for (iter=0; iter<2; iter++) { - for (latfpos=fpos=prevpos100=i=0; i Date: Sun, 5 Nov 2017 16:50:37 +0200 Subject: [PATCH 114/188] Test --- src/komodo_gateway.h | 9 +++++---- src/komodo_kv.h | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 8a9baee45..5655db040 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1048,8 +1048,9 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 komodo_kvupdate(opretbuf,opretlen,value); return("kv"); } - else if ( KOMODO_PAX == 0 ) - return("nopax"); + //else if ( KOMODO_PAX == 0 ) + // return("nopax"); + printf("OPRET.%c\n",opretbuf[0]); if ( opretbuf[0] == 'D' ) { tokomodo = 0; @@ -1149,7 +1150,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 if ( baseids[i] < 0 ) { static uint32_t counter; - if ( ++counter < 1 ) + if ( counter++ < 0 ) printf("%d of %d illegal baseid.%d, this can be ignored\n",i,n,baseids[i]); continue; } @@ -1361,7 +1362,7 @@ void komodo_stateind_set(struct komodo_state *sp,uint32_t *inds,int32_t n,uint8_ lastK = lastT = lastN = lastV = -1; for (iter=0; iter<2; iter++) { - for (lastfpos=fpos=prevpos100=i=0; i opretlen ) { static uint32_t counter; - if ( counter++ < 3 ) + if ( ++counter < 1 ) printf("komodo_kvupdate: keylen.%d + 13 > opretlen.%d, this can be ignored\n",keylen,opretlen); return; } From ddef24809caee31a594aa60a50446f7ff606ff91 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 5 Nov 2017 16:51:54 +0200 Subject: [PATCH 115/188] 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 5655db040..c8004a23d 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1362,7 +1362,7 @@ void komodo_stateind_set(struct komodo_state *sp,uint32_t *inds,int32_t n,uint8_ lastK = lastT = lastN = lastV = -1; for (iter=0; iter<2; iter++) { - for (latfpos=fpos=prevpos100=i=0; i Date: Sun, 5 Nov 2017 16:54:41 +0200 Subject: [PATCH 116/188] Test --- src/komodo_gateway.h | 1 - src/komodo_utils.h | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index c8004a23d..ca54983bc 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1050,7 +1050,6 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 } //else if ( KOMODO_PAX == 0 ) // return("nopax"); - printf("OPRET.%c\n",opretbuf[0]); if ( opretbuf[0] == 'D' ) { tokomodo = 0; diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 92577dae0..7db4f6fff 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1512,7 +1512,7 @@ void komodo_args(char *argv0) { USE_EXTERNAL_PUBKEY = 1; KOMODO_PAX = 1; - } else KOMODO_PAX = GetArg("-pax",0); + } else KOMODO_PAX = GetArg("-pax",1); name = GetArg("-ac_name",""); if ( argv0 != 0 ) { From 02b20e4022ff130a619d1596065bdaa1f3edd488 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 5 Nov 2017 16:56:47 +0200 Subject: [PATCH 117/188] 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 ca54983bc..07187c41c 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1048,8 +1048,8 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 komodo_kvupdate(opretbuf,opretlen,value); return("kv"); } - //else if ( KOMODO_PAX == 0 ) - // return("nopax"); + else if ( KOMODO_PAX == 0 ) + return("nopax"); if ( opretbuf[0] == 'D' ) { tokomodo = 0; diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 7db4f6fff..92577dae0 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1512,7 +1512,7 @@ void komodo_args(char *argv0) { USE_EXTERNAL_PUBKEY = 1; KOMODO_PAX = 1; - } else KOMODO_PAX = GetArg("-pax",1); + } else KOMODO_PAX = GetArg("-pax",0); name = GetArg("-ac_name",""); if ( argv0 != 0 ) { From 3a48f81a308dece1c8c3d8c7a05a7a4830a4f25b Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 5 Nov 2017 16:58:04 +0200 Subject: [PATCH 118/188] 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 07187c41c..b69857141 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1048,7 +1048,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 komodo_kvupdate(opretbuf,opretlen,value); return("kv"); } - else if ( KOMODO_PAX == 0 ) + else if ( ASSETCHAINS_SYMBOL[0] == 0 && KOMODO_PAX == 0 ) return("nopax"); if ( opretbuf[0] == 'D' ) { @@ -1566,7 +1566,7 @@ int32_t komodo_faststateinit(struct komodo_state *sp,char *fname,char *symbol,ch strcat(indfname,".ind"); if ( (filedata= OS_fileptr(&datalen,fname)) != 0 ) { - if ( datalen >= (1LL << 32) || GetArg("-genind",0) != 0 || (validated= komodo_stateind_validate(0,indfname,filedata,datalen,&prevpos100,&indcounter,symbol,dest)) < 0 ) + if ( 1 )//datalen >= (1LL << 32) || GetArg("-genind",0) != 0 || (validated= komodo_stateind_validate(0,indfname,filedata,datalen,&prevpos100,&indcounter,symbol,dest)) < 0 ) { lastfpos = fpos = 0; indcounter = prevpos100 = 0; From e31b96160784943af2bf5f29373afdbc941bc794 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 5 Nov 2017 18:47:09 +0200 Subject: [PATCH 119/188] Remove prints --- 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 b69857141..d4d72781d 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1407,12 +1407,12 @@ void komodo_stateind_set(struct komodo_state *sp,uint32_t *inds,int32_t n,uint8_ if ( func == 'K' ) { if ( lastK == lastfpos ) - doissue = 1, printf("trigger lastK\n"); + doissue = 1; } else if ( func == 'T' ) { if ( lastT == lastfpos ) - doissue = 1, printf("trigger lastT\n"); + doissue = 1; } else if ( func == 'N' ) { From e9d73912befb3fa9dc9952e1a0e8a7f34ad3dcfe Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 6 Nov 2017 13:52:29 +0200 Subject: [PATCH 120/188] Fix help error --- src/komodo_gateway.h | 2 +- src/wallet/rpcwallet.cpp | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index d4d72781d..1bdc6034c 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1422,7 +1422,7 @@ void komodo_stateind_set(struct komodo_state *sp,uint32_t *inds,int32_t n,uint8_ } else if ( func == 'V' ) { - if ( KOMODO_PAX != 0 || numv > numV-1440 ) + if ( KOMODO_PAX != 0 && numv > numV-1440 ) doissue = 1; numv++; } diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index ee9fb71bb..c72527c01 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -614,7 +614,9 @@ UniValue paxdeposit(const UniValue& params, bool fHelp) uint64_t available,deposited,issued,withdrawn,approved,redeemed,seed,komodoshis = 0; int32_t height; char destaddr[64]; uint8_t i,pubkey37[33]; bool fSubtractFeeFromAmount = false; if ( KOMODO_PAX == 0 ) - throw JSONRPCError(RPC_TYPE_ERROR, "paxdeposit disabled, since pax not enabled with komodod -pax"); + { + throw runtime_error("paxdeposit dispabled without -pax"); + } if ( komodo_is_issuer() != 0 ) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "paxdeposit only from KMD"); if (!EnsureWalletIsAvailable(fHelp)) From 7c130297c27fadb9557b89d155e836eb5c99f02f Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 10 Nov 2017 19:07:36 +0200 Subject: [PATCH 121/188] KOMODO_ASSETCHAIN_MAXLEN -> 65 --- src/bitcoind.cpp | 2 +- src/chainparams.cpp | 2 +- src/coins.cpp | 2 +- src/komodo.h | 10 +++++----- src/komodo_bitcoind.h | 2 +- src/komodo_gateway.h | 12 ++++++------ src/komodo_globals.h | 3 ++- src/komodo_notary.h | 4 ++-- src/komodo_structs.h | 4 ++-- src/komodo_utils.h | 2 +- src/main.cpp | 2 +- src/miner.cpp | 2 +- src/rpcblockchain.cpp | 2 +- src/rpcrawtransaction.cpp | 2 +- src/util.cpp | 4 ++-- src/wallet/rpcwallet.cpp | 2 +- src/wallet/wallet.cpp | 2 +- src/zcash/CreateJoinSplit.cpp | 2 +- 18 files changed, 31 insertions(+), 30 deletions(-) diff --git a/src/bitcoind.cpp b/src/bitcoind.cpp index 050305117..6bff57071 100644 --- a/src/bitcoind.cpp +++ b/src/bitcoind.cpp @@ -42,7 +42,7 @@ */ static bool fDaemon; -extern char ASSETCHAINS_SYMBOL[16]; +extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; void komodo_passport_iteration(); void WaitForShutdown(boost::thread_group* threadGroup) diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 17b5dab6e..c6b3f393f 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -30,7 +30,7 @@ using namespace std; * + Contains no strange transactions */ void *chainparams_commandline(void *ptr); -extern char ASSETCHAINS_SYMBOL[16]; +extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; extern uint16_t ASSETCHAINS_PORT; extern uint32_t ASSETCHAIN_INIT; extern uint32_t ASSETCHAINS_MAGIC; diff --git a/src/coins.cpp b/src/coins.cpp index 27cac5a6f..aa858eeb8 100644 --- a/src/coins.cpp +++ b/src/coins.cpp @@ -387,7 +387,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); uint64_t komodo_accrued_interest(int32_t *txheightp,uint32_t *locktimep,uint256 hash,int32_t n,int32_t checkheight,uint64_t checkvalue); -extern char ASSETCHAINS_SYMBOL[16]; +extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; CAmount CCoinsViewCache::GetValueIn(int32_t nHeight,int64_t *interestp,const CTransaction& tx,uint32_t tiptime) const { diff --git a/src/komodo.h b/src/komodo.h index 02253950e..fb2160da7 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -56,14 +56,14 @@ int32_t komodo_parsestatefile(struct komodo_state *sp,FILE *fp,char *symbol,char void komodo_currentheight_set(int32_t height) { - char symbol[16],dest[16]; struct komodo_state *sp; + char symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN]; struct komodo_state *sp; if ( (sp= komodo_stateptr(symbol,dest)) != 0 ) sp->CURRENT_HEIGHT = height; } int32_t komodo_currentheight() { - char symbol[16],dest[16]; struct komodo_state *sp; + char symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN]; struct komodo_state *sp; if ( (sp= komodo_stateptr(symbol,dest)) != 0 ) return(sp->CURRENT_HEIGHT); else return(0); @@ -328,7 +328,7 @@ int32_t komodo_parsestatefiledata(struct komodo_state *sp,uint8_t *filedata,long 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 KMDheight,uint32_t KMDtimestamp,uint64_t opretvalue,uint8_t *opretbuf,uint16_t opretlen,uint16_t vout) { static FILE *fp; static int32_t errs,didinit; - struct komodo_state *sp; char fname[512],symbol[16],dest[16]; int32_t retval,ht,func; uint8_t num,pubkeys[64][33]; + struct komodo_state *sp; char fname[512],symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN]; int32_t retval,ht,func; uint8_t num,pubkeys[64][33]; if ( didinit == 0 ) { portable_mutex_init(&KOMODO_KV_mutex); @@ -475,7 +475,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scriptbuf,int32_t scriptlen,int32_t height,uint256 txhash,int32_t i,int32_t j,uint64_t *voutmaskp,int32_t *specialtxp,int32_t *notarizedheightp,uint64_t value,int32_t notarized,uint64_t signedmask) { static uint256 zero; static FILE *signedfp; - int32_t opretlen,nid,k,len = 0; uint256 kmdtxid,desttxid; uint8_t crypto777[33]; struct komodo_state *sp; char symbol[16],dest[16]; + int32_t opretlen,nid,k,len = 0; uint256 kmdtxid,desttxid; uint8_t crypto777[33]; struct komodo_state *sp; char symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN]; if ( (sp= komodo_stateptr(symbol,dest)) == 0 ) return(-1); if ( scriptlen == 35 && scriptbuf[0] == 33 && scriptbuf[34] == 0xac ) @@ -633,7 +633,7 @@ int32_t komodo_notarycmp(uint8_t *scriptPubKey,int32_t scriptlen,uint8_t pubkeys void komodo_connectblock(CBlockIndex *pindex,CBlock& block) { static int32_t hwmheight; - uint64_t signedmask,voutmask; char symbol[16],dest[16]; struct komodo_state *sp; + uint64_t signedmask,voutmask; char symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN]; struct komodo_state *sp; uint8_t scriptbuf[4096],pubkeys[64][33],rmd160[20],scriptPubKey[35]; uint256 kmdtxid,zero,btctxid,txhash; int32_t i,j,k,numnotaries,notarized,scriptlen,isratification,nid,numvalid,specialtx,notarizedheight,notaryid,len,numvouts,numvins,height,txn_count; memset(&zero,0,sizeof(zero)); diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index e4d216741..d356bd6bf 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -559,7 +559,7 @@ uint32_t komodo_txtime(uint256 hash) void komodo_disconnect(CBlockIndex *pindex,CBlock& block) { - char symbol[16],dest[16]; struct komodo_state *sp; + char symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN]; struct komodo_state *sp; //fprintf(stderr,"disconnect ht.%d\n",pindex->nHeight); komodo_init(pindex->nHeight); if ( (sp= komodo_stateptr(symbol,dest)) != 0 ) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 1bdc6034c..a83bac7d5 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -105,7 +105,7 @@ void komodo_paxdelete(struct pax_transaction *pax) void komodo_gateway_deposit(char *coinaddr,uint64_t value,char *symbol,uint64_t fiatoshis,uint8_t *rmd160,uint256 txid,uint16_t vout,uint8_t type,int32_t height,int32_t otherheight,char *source,int32_t approved) // assetchain context { - struct pax_transaction *pax; uint8_t buf[35]; int32_t addflag = 0; struct komodo_state *sp; char str[16],dest[16],*s; + struct pax_transaction *pax; uint8_t buf[35]; int32_t addflag = 0; struct komodo_state *sp; char str[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN],*s; //if ( KOMODO_PAX == 0 ) // return; //if ( strcmp(symbol,ASSETCHAINS_SYMBOL) != 0 ) @@ -197,7 +197,7 @@ int32_t komodo_rwapproval(int32_t rwflag,uint8_t *opretbuf,struct pax_transactio int32_t komodo_issued_opreturn(char *base,uint256 *txids,uint16_t *vouts,int64_t *values,int64_t *srcvalues,int32_t *kmdheights,int32_t *otherheights,int8_t *baseids,uint8_t *rmd160s,uint8_t *opretbuf,int32_t opretlen,int32_t iskomodo) { - struct pax_transaction p,*pax; int32_t i,n=0,j,len=0,incr,height,otherheight; uint8_t type,rmd160[20]; uint64_t fiatoshis; char symbol[16]; + struct pax_transaction p,*pax; int32_t i,n=0,j,len=0,incr,height,otherheight; uint8_t type,rmd160[20]; uint64_t fiatoshis; char symbol[KOMODO_ASSETCHAIN_MAXLEN]; //if ( KOMODO_PAX == 0 ) // return(0); incr = 34 + (iskomodo * (2*sizeof(fiatoshis) + 2*sizeof(height) + 20 + 4)); @@ -290,7 +290,7 @@ int32_t komodo_paxcmp(char *symbol,int32_t kmdheight,uint64_t value,uint64_t che uint64_t komodo_paxtotal() { - struct pax_transaction *pax,*pax2,*tmp,*tmp2; char symbol[16],dest[16],*str; int32_t i,ht; int64_t checktoshis; uint64_t seed,total = 0; struct komodo_state *basesp; + struct pax_transaction *pax,*pax2,*tmp,*tmp2; char symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN],*str; int32_t i,ht; int64_t checktoshis; uint64_t seed,total = 0; struct komodo_state *basesp; if ( KOMODO_PASSPORT_INITDONE == 0 ) //KOMODO_PAX == 0 || return(0); if ( komodo_isrealtime(&ht) == 0 ) @@ -464,7 +464,7 @@ int32_t komodo_pending_withdraws(char *opretstr) // todo: enforce deterministic int32_t komodo_gateway_deposits(CMutableTransaction *txNew,char *base,int32_t tokomodo) { - struct pax_transaction *pax,*tmp; char symbol[16],dest[16]; uint8_t *script,opcode,opret[16384],data[16384]; int32_t i,baseid,ht,len=0,opretlen=0,numvouts=1; struct komodo_state *sp; uint64_t available,deposited,issued,withdrawn,approved,redeemed,mask,sum = 0; + struct pax_transaction *pax,*tmp; char symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN]; uint8_t *script,opcode,opret[16384],data[16384]; int32_t i,baseid,ht,len=0,opretlen=0,numvouts=1; struct komodo_state *sp; uint64_t available,deposited,issued,withdrawn,approved,redeemed,mask,sum = 0; if ( KOMODO_PASSPORT_INITDONE == 0 )//KOMODO_PAX == 0 || return(0); struct komodo_state *kmdsp = komodo_stateptrget((char *)"KMD"); @@ -652,7 +652,7 @@ void komodo_passport_iteration(); int32_t komodo_check_deposit(int32_t height,const CBlock& block) // verify above block is valid pax pricing { static uint256 array[64]; static int32_t numbanned,indallvouts; - int32_t i,j,k,n,ht,baseid,txn_count,activation,num,opretlen,offset=1,errs=0,matched=0,kmdheights[256],otherheights[256]; uint256 hash,txids[256]; char symbol[16],base[16]; uint16_t vouts[256]; int8_t baseids[256]; uint8_t *script,opcode,rmd160s[256*20]; uint64_t total,available,deposited,issued,withdrawn,approved,redeemed,checktoshis,seed; int64_t values[256],srcvalues[256]; struct pax_transaction *pax; struct komodo_state *sp; + int32_t i,j,k,n,ht,baseid,txn_count,activation,num,opretlen,offset=1,errs=0,matched=0,kmdheights[256],otherheights[256]; uint256 hash,txids[256]; char symbol[KOMODO_ASSETCHAIN_MAXLEN],base[KOMODO_ASSETCHAIN_MAXLEN]; uint16_t vouts[256]; int8_t baseids[256]; uint8_t *script,opcode,rmd160s[256*20]; uint64_t total,available,deposited,issued,withdrawn,approved,redeemed,checktoshis,seed; int64_t values[256],srcvalues[256]; struct pax_transaction *pax; struct komodo_state *sp; activation = 235300; if ( *(int32_t *)&array[0] == 0 ) numbanned = komodo_bannedset(&indallvouts,array,(int32_t)(sizeof(array)/sizeof(*array))); @@ -1626,7 +1626,7 @@ void komodo_passport_iteration() { static long lastpos[34]; static char userpass[33][1024]; static uint32_t lasttime,callcounter; int32_t maxseconds = 10; - FILE *fp; uint8_t *filedata; long fpos,datalen,lastfpos; int32_t baseid,limit,n,ht,isrealtime,expired,refid,blocks,longest; struct komodo_state *sp,*refsp; char *retstr,fname[512],*base,symbol[16],dest[16]; uint32_t buf[3],starttime; cJSON *infoobj,*result; uint64_t RTmask = 0; + FILE *fp; uint8_t *filedata; long fpos,datalen,lastfpos; int32_t baseid,limit,n,ht,isrealtime,expired,refid,blocks,longest; struct komodo_state *sp,*refsp; char *retstr,fname[512],*base,symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN]; uint32_t buf[3],starttime; cJSON *infoobj,*result; uint64_t RTmask = 0; expired = 0; while ( KOMODO_INITDONE == 0 ) { diff --git a/src/komodo_globals.h b/src/komodo_globals.h index 2976deb8e..bd01daa53 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -30,6 +30,7 @@ pthread_mutex_t komodo_mutex; #define KOMODO_ELECTION_GAP 2000 //((ASSETCHAINS_SYMBOL[0] == 0) ? 2000 : 100) #define IGUANA_MAXSCRIPTSIZE 10001 +#define KOMODO_ASSETCHAIN_MAXLEN 65 struct pax_transaction *PAX; int32_t NUM_PRICES; uint32_t *PVALS; @@ -45,7 +46,7 @@ int32_t KOMODO_LASTMINED,prevKOMODO_LASTMINED; std::string NOTARY_PUBKEY,ASSETCHAINS_NOTARIES; uint8_t NOTARY_PUBKEY33[33]; -char ASSETCHAINS_SYMBOL[16]; +char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; uint16_t ASSETCHAINS_PORT; uint32_t ASSETCHAIN_INIT; uint32_t ASSETCHAINS_MAGIC = 2387029918; diff --git a/src/komodo_notary.h b/src/komodo_notary.h index 5e6b1707f..c725f03c4 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -307,7 +307,7 @@ void komodo_notarized_update(struct komodo_state *sp,int32_t nHeight,int32_t not //struct komodo_state *komodo_stateptr(char *symbol,char *dest); int32_t komodo_notarized_height(uint256 *hashp,uint256 *txidp) { - char symbol[16],dest[16]; struct komodo_state *sp; + char symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN]; struct komodo_state *sp; if ( (sp= komodo_stateptr(symbol,dest)) != 0 ) { *hashp = sp->NOTARIZED_HASH; @@ -324,7 +324,7 @@ int32_t komodo_notarized_height(uint256 *hashp,uint256 *txidp) int32_t komodo_notarizeddata(int32_t nHeight,uint256 *notarized_hashp,uint256 *notarized_desttxidp) { - struct notarized_checkpoint *np = 0; int32_t i=0,flag = 0; char symbol[16],dest[16]; struct komodo_state *sp; + struct notarized_checkpoint *np = 0; int32_t i=0,flag = 0; char symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN]; struct komodo_state *sp; if ( (sp= komodo_stateptr(symbol,dest)) != 0 ) { if ( sp->NUM_NPOINTS > 0 ) diff --git a/src/komodo_structs.h b/src/komodo_structs.h index 8db0a6f43..e56ef751e 100644 --- a/src/komodo_structs.h +++ b/src/komodo_structs.h @@ -60,7 +60,7 @@ struct komodo_event uint16_t len; int32_t height; uint8_t type,reorged; - char symbol[16]; + char symbol[KOMODO_ASSETCHAIN_MAXLEN]; uint8_t space[]; }; @@ -71,7 +71,7 @@ struct pax_transaction uint64_t komodoshis,fiatoshis,validated; int32_t marked,height,otherheight,approved,didstats,ready; uint16_t vout; - char symbol[16],source[16],coinaddr[64]; uint8_t rmd160[20],type,buf[35]; + char symbol[KOMODO_ASSETCHAIN_MAXLEN],source[KOMODO_ASSETCHAIN_MAXLEN],coinaddr[64]; uint8_t rmd160[20],type,buf[35]; }; struct knotary_entry { UT_hash_handle hh; uint8_t pubkey[33],notaryid; }; diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 92577dae0..c6469a350 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1402,7 +1402,7 @@ void komodo_configfile(char *symbol,uint16_t port) uint16_t komodo_userpass(char *userpass,char *symbol) { - FILE *fp; uint16_t port = 0; char fname[512],username[512],password[512],confname[16]; + FILE *fp; uint16_t port = 0; char fname[512],username[512],password[512],confname[KOMODO_ASSETCHAIN_MAXLEN]; userpass[0] = 0; if ( strcmp("KMD",symbol) == 0 ) { diff --git a/src/main.cpp b/src/main.cpp index e86a665ec..e06749072 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1491,7 +1491,7 @@ bool ReadBlockFromDisk(CBlock& block, const CBlockIndex* pindex) } //uint64_t komodo_moneysupply(int32_t height); -extern char ASSETCHAINS_SYMBOL[16]; +extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; extern uint32_t ASSETCHAINS_MAGIC; extern uint64_t ASSETCHAINS_SUPPLY; diff --git a/src/miner.cpp b/src/miner.cpp index 721b19cef..bbdbe93da 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -110,7 +110,7 @@ void UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams, #define KOMODO_ELECTION_GAP 2000 #define ROUNDROBIN_DELAY 61 extern int32_t ASSETCHAINS_SEED,IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAIN_INIT,KOMODO_INITDONE,KOMODO_ON_DEMAND,KOMODO_INITDONE,KOMODO_PASSPORT_INITDONE; -extern char ASSETCHAINS_SYMBOL[16]; +extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; extern std::string NOTARY_PUBKEY; extern uint8_t NOTARY_PUBKEY33[33]; uint32_t Mining_start,Mining_height; diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 8088da58f..5375187dd 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -515,7 +515,7 @@ UniValue gettxoutsetinfo(const UniValue& params, bool fHelp) #define IGUANA_MAXSCRIPTSIZE 10001 #define KOMODO_KVDURATION 1440 #define KOMODO_KVBINARY 2 -extern char ASSETCHAINS_SYMBOL[16]; +extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; 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(uint64_t *seedp,int32_t height,char *base,char *rel,uint64_t basevolume); diff --git a/src/rpcrawtransaction.cpp b/src/rpcrawtransaction.cpp index 54f49798c..3f3b4c5e0 100644 --- a/src/rpcrawtransaction.cpp +++ b/src/rpcrawtransaction.cpp @@ -144,7 +144,7 @@ void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry) out.push_back(Pair("value", ValueFromAmount(txout.nValue))); if ( pindex != 0 && tx.nLockTime != 0 && (tipindex= chainActive.Tip()) != 0 ) { - extern char ASSETCHAINS_SYMBOL[16]; + extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; interest = komodo_interest(pindex->nHeight,txout.nValue,tx.nLockTime,tipindex->nTime); if ( 0 && strcmp("REVS",ASSETCHAINS_SYMBOL) == 0 ) fprintf(stderr,"TxtoJSON interest %llu %.8f (%d %llu %u %u)\n",(long long)interest,(double)interest/COIN,(int32_t)pindex->nHeight,(long long)txout.nValue,(uint32_t)tx.nLockTime,(int32_t)tipindex->nTime); diff --git a/src/util.cpp b/src/util.cpp index ec83e17ce..4005d36c4 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -441,13 +441,13 @@ void PrintExceptionContinue(const std::exception* pex, const char* pszThread) strMiscWarning = message; } -extern char ASSETCHAINS_SYMBOL[16]; +extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; //int64_t MAX_MONEY = 200000000 * 100000000LL; boost::filesystem::path GetDefaultDataDir() { namespace fs = boost::filesystem; - char symbol[16]; + char symbol[KOMODO_ASSETCHAIN_MAXLEN]; if ( ASSETCHAINS_SYMBOL[0] != 0 ) strcpy(symbol,ASSETCHAINS_SYMBOL); else symbol[0] = 0; diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index c72527c01..1dd95ebd1 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -479,7 +479,7 @@ UniValue sendtoaddress(const UniValue& params, bool fHelp) 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]; +extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; extern int32_t KOMODO_PAX; int32_t komodo_is_issuer(); int32_t iguana_rwnum(int32_t rwflag,uint8_t *serialized,int32_t len,void *endianedp); diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index a2aa33661..283eb7953 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -38,7 +38,7 @@ bool bSpendZeroConfChange = true; bool fSendFreeTransactions = false; bool fPayAtLeastCustomFee = true; extern int32_t KOMODO_EXCHANGEWALLET; -extern char ASSETCHAINS_SYMBOL[16]; +extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; /** * Fees smaller than this (in satoshi) are considered zero fee (for transaction creation) diff --git a/src/zcash/CreateJoinSplit.cpp b/src/zcash/CreateJoinSplit.cpp index f29b2ec82..1f1d09f29 100644 --- a/src/zcash/CreateJoinSplit.cpp +++ b/src/zcash/CreateJoinSplit.cpp @@ -6,7 +6,7 @@ #include "primitives/transaction.h" #include "zcash/JoinSplit.hpp" #include "libsnark/common/profiling.hpp" -char ASSETCHAINS_SYMBOL[16]; +char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; int64_t MAX_MONEY = 200000000 * 100000000LL; uint16_t BITCOIND_PORT = 7771; From 261c245b7b677e8a25de144b79de0dcafa739875 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 10 Nov 2017 19:08:41 +0200 Subject: [PATCH 122/188] Test --- src/bitcoind.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/bitcoind.cpp b/src/bitcoind.cpp index 6bff57071..bf4934da4 100644 --- a/src/bitcoind.cpp +++ b/src/bitcoind.cpp @@ -42,6 +42,7 @@ */ static bool fDaemon; +#define KOMODO_ASSETCHAIN_MAXLEN 65 extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; void komodo_passport_iteration(); From cc30b05e0d3d88b68147133fcddb8a3433d8dec1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 10 Nov 2017 19:10:09 +0200 Subject: [PATCH 123/188] Test --- src/komodo_structs.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/komodo_structs.h b/src/komodo_structs.h index e56ef751e..cd3adfa00 100644 --- a/src/komodo_structs.h +++ b/src/komodo_structs.h @@ -40,6 +40,7 @@ #define KOMODO_KVPROTECTED 1 #define KOMODO_KVBINARY 2 #define KOMODO_KVDURATION 1440 +#define KOMODO_ASSETCHAIN_MAXLEN 65 union _bits256 { uint8_t bytes[32]; uint16_t ushorts[16]; uint32_t uints[8]; uint64_t ulongs[4]; uint64_t txid; }; typedef union _bits256 bits256; From 5416af1ddc0ca2c69386dea5cb17b1b6f7e016b9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 10 Nov 2017 19:15:34 +0200 Subject: [PATCH 124/188] KOMODO_DEFS_H --- src/komodo-tx.cpp | 1 + src/komodo.h | 1 + src/komodo_bitcoind.h | 2 ++ src/komodo_defs.h | 9 +++++++++ src/komodo_events.h | 1 + src/komodo_gateway.h | 1 + src/komodo_globals.h | 2 ++ src/komodo_interest.h | 2 ++ src/komodo_jumblr.h | 1 + src/komodo_kv.h | 2 ++ src/komodo_notary.h | 2 ++ src/komodo_pax.h | 2 ++ src/komodo_structs.h | 2 ++ src/komodo_utils.h | 2 ++ src/miner.cpp | 5 ++--- 15 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 src/komodo_defs.h diff --git a/src/komodo-tx.cpp b/src/komodo-tx.cpp index 19d0440dd..645bc30a2 100644 --- a/src/komodo-tx.cpp +++ b/src/komodo-tx.cpp @@ -27,6 +27,7 @@ using namespace std; #include "arith_uint256.h" #include "komodo_structs.h" #include "komodo_globals.h" +#include "komodo_defs.h" #include "komodo_interest.h" diff --git a/src/komodo.h b/src/komodo.h index fb2160da7..e8ab6d6be 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -15,6 +15,7 @@ #ifndef H_KOMODO_H #define H_KOMODO_H +#include "komodo_defs.h" #ifdef _WIN32 #define printf(...) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index d356bd6bf..29849f295 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -23,6 +23,8 @@ #include #endif +#include "komodo_defs.h" + //#define issue_curl(cmdstr) bitcoind_RPC(0,(char *)"curl",(char *)"http://127.0.0.1:7776",0,0,(char *)(cmdstr)) struct MemoryStruct { char *memory; size_t size; }; diff --git a/src/komodo_defs.h b/src/komodo_defs.h new file mode 100644 index 000000000..db792c44e --- /dev/null +++ b/src/komodo_defs.h @@ -0,0 +1,9 @@ +#ifndef KOMODO_DEFS_H +#define KOMODO_DEFS_H + +#define ASSETCHAINS_MINHEIGHT 128 +#define KOMODO_ELECTION_GAP 2000 +#define ROUNDROBIN_DELAY 61 +#define KOMODO_ASSETCHAIN_MAXLEN 65 + +#endif diff --git a/src/komodo_events.h b/src/komodo_events.h index 753413e9f..ff054c3bb 100644 --- a/src/komodo_events.h +++ b/src/komodo_events.h @@ -15,6 +15,7 @@ #ifndef H_KOMODOEVENTS_H #define H_KOMODOEVENTS_H +#include "komodo_defs.h" struct komodo_event *komodo_eventadd(struct komodo_state *sp,int32_t height,char *symbol,uint8_t type,uint8_t *data,uint16_t datalen) { diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index a83bac7d5..d655f2aa5 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -14,6 +14,7 @@ ******************************************************************************/ // paxdeposit equivalent in reverse makes opreturn and KMD does the same in reverse +#include "komodo_defs.h" int32_t pax_fiatstatus(uint64_t *available,uint64_t *deposited,uint64_t *issued,uint64_t *withdrawn,uint64_t *approved,uint64_t *redeemed,char *base) { diff --git a/src/komodo_globals.h b/src/komodo_globals.h index bd01daa53..e945beeee 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -13,6 +13,8 @@ * * ******************************************************************************/ +#include "komodo_defs.h" + 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,uint32_t ktime,uint64_t opretvalue,uint8_t *opretbuf,uint16_t opretlen,uint16_t vout); void komodo_init(int32_t height); int32_t komodo_notarizeddata(int32_t nHeight,uint256 *notarized_hashp,uint256 *notarized_desttxidp); diff --git a/src/komodo_interest.h b/src/komodo_interest.h index 798eda48e..97f288b4c 100644 --- a/src/komodo_interest.h +++ b/src/komodo_interest.h @@ -13,6 +13,8 @@ * * ******************************************************************************/ +#include "komodo_defs.h" + #define SATOSHIDEN ((uint64_t)100000000L) #define dstr(x) ((double)(x) / SATOSHIDEN) diff --git a/src/komodo_jumblr.h b/src/komodo_jumblr.h index baafc6dbe..a5eff09a5 100755 --- a/src/komodo_jumblr.h +++ b/src/komodo_jumblr.h @@ -27,6 +27,7 @@ #ifdef _WIN32 #include #endif +#include "komodo_defs.h" #define JUMBLR_ADDR "RGhxXpXSSBTBm9EvNsXnTQczthMCxHX91t" #define JUMBLR_BTCADDR "18RmTJe9qMech8siuhYfMtHo8RtcN1obC6" diff --git a/src/komodo_kv.h b/src/komodo_kv.h index 6d080069a..0d86fadd0 100644 --- a/src/komodo_kv.h +++ b/src/komodo_kv.h @@ -16,6 +16,8 @@ #ifndef H_KOMODOKV_H #define H_KOMODOKV_H +#include "komodo_defs.h" + int32_t komodo_kvcmp(uint8_t *refvalue,uint16_t refvaluesize,uint8_t *value,uint16_t valuesize) { if ( refvalue == 0 && value == 0 ) diff --git a/src/komodo_notary.h b/src/komodo_notary.h index c725f03c4..a306f848f 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -13,6 +13,8 @@ * * ******************************************************************************/ +#include "komodo_defs.h" + #include "komodo_cJSON.h" #define KOMODO_MAINNET_START 178999 diff --git a/src/komodo_pax.h b/src/komodo_pax.h index d1713e234..bcf6fa5d7 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -13,6 +13,8 @@ * * ******************************************************************************/ +#include "komodo_defs.h" + #define USD 0 #define EUR 1 #define JPY 2 diff --git a/src/komodo_structs.h b/src/komodo_structs.h index cd3adfa00..40212c3e3 100644 --- a/src/komodo_structs.h +++ b/src/komodo_structs.h @@ -13,6 +13,8 @@ * * ******************************************************************************/ +#include "komodo_defs.h" + #include "uthash.h" #include "utlist.h" diff --git a/src/komodo_utils.h b/src/komodo_utils.h index c6469a350..ef64ad75c 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -12,6 +12,8 @@ * Removal or modification of this copyright notice is prohibited. * * * ******************************************************************************/ +#include "komodo_defs.h" + #ifdef _WIN32 #include #include diff --git a/src/miner.cpp b/src/miner.cpp index bbdbe93da..5c12d0af6 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -106,9 +106,8 @@ void UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams, pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, consensusParams); } -#define ASSETCHAINS_MINHEIGHT 128 -#define KOMODO_ELECTION_GAP 2000 -#define ROUNDROBIN_DELAY 61 +#include "komodo_defs.h" + extern int32_t ASSETCHAINS_SEED,IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAIN_INIT,KOMODO_INITDONE,KOMODO_ON_DEMAND,KOMODO_INITDONE,KOMODO_PASSPORT_INITDONE; extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; extern std::string NOTARY_PUBKEY; From fa09a600b899f32d2d611d433adaffa90894b645 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 10 Nov 2017 19:17:16 +0200 Subject: [PATCH 125/188] Test --- src/rpcblockchain.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 5375187dd..10f617765 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -512,6 +512,8 @@ UniValue gettxoutsetinfo(const UniValue& params, bool fHelp) return ret; } +#include "komodo_defs.h" + #define IGUANA_MAXSCRIPTSIZE 10001 #define KOMODO_KVDURATION 1440 #define KOMODO_KVBINARY 2 From 037a30c3d14ca75c78a84953da4ee0639757ceed Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 10 Nov 2017 19:18:39 +0200 Subject: [PATCH 126/188] Test --- src/rpcrawtransaction.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/rpcrawtransaction.cpp b/src/rpcrawtransaction.cpp index 3f3b4c5e0..dac9d49e8 100644 --- a/src/rpcrawtransaction.cpp +++ b/src/rpcrawtransaction.cpp @@ -22,6 +22,8 @@ #include "wallet/wallet.h" #endif +#include "komodo_defs.h" + #include #include From b978bc5b67a7629f393aeeb09c1640c1af4317ea Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 10 Nov 2017 19:20:03 +0200 Subject: [PATCH 127/188] Test --- src/chainparams.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/chainparams.cpp b/src/chainparams.cpp index c6b3f393f..13409c8c4 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -30,6 +30,8 @@ using namespace std; * + Contains no strange transactions */ void *chainparams_commandline(void *ptr); +#include "komodo_defs.h" + extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; extern uint16_t ASSETCHAINS_PORT; extern uint32_t ASSETCHAIN_INIT; From 997cf5a1d23943171e1c628d6a09d3af39d6f618 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 10 Nov 2017 19:20:58 +0200 Subject: [PATCH 128/188] Test --- src/coins.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/coins.cpp b/src/coins.cpp index aa858eeb8..37d969010 100644 --- a/src/coins.cpp +++ b/src/coins.cpp @@ -8,6 +8,7 @@ #include "random.h" #include "version.h" #include "policy/fees.h" +#include "komodo_defs.h" #include From 7ce53ed0507edcd6777614c6fe6d5155e5070f33 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 10 Nov 2017 19:21:59 +0200 Subject: [PATCH 129/188] Test --- src/util.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/util.cpp b/src/util.cpp index 4005d36c4..be7517573 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -15,6 +15,7 @@ #include "sync.h" #include "utilstrencodings.h" #include "utiltime.h" +#include "komodo_defs.h" #include From bdc72415977cf159337e4b88c805ff2541b9e78f Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 10 Nov 2017 19:23:11 +0200 Subject: [PATCH 130/188] Test --- src/wallet/rpcwallet.cpp | 1 + src/wallet/wallet.cpp | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 1dd95ebd1..dbc3aab84 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -471,6 +471,7 @@ UniValue sendtoaddress(const UniValue& params, bool fHelp) return wtx.GetHash().GetHex(); } +#include "komodo_defs.h" #define KOMODO_KVPROTECTED 1 #define KOMODO_KVBINARY 2 diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 283eb7953..67f7a7fe0 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -37,6 +37,8 @@ unsigned int nTxConfirmTarget = DEFAULT_TX_CONFIRM_TARGET; bool bSpendZeroConfChange = true; bool fSendFreeTransactions = false; bool fPayAtLeastCustomFee = true; +#include "komodo_defs.h" + extern int32_t KOMODO_EXCHANGEWALLET; extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; From 9282f3e9fc0f6f83124d78f18245af544bc50047 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 10 Nov 2017 19:24:54 +0200 Subject: [PATCH 131/188] Test --- src/zcash/CreateJoinSplit.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/zcash/CreateJoinSplit.cpp b/src/zcash/CreateJoinSplit.cpp index 1f1d09f29..9c7760e4f 100644 --- a/src/zcash/CreateJoinSplit.cpp +++ b/src/zcash/CreateJoinSplit.cpp @@ -6,6 +6,7 @@ #include "primitives/transaction.h" #include "zcash/JoinSplit.hpp" #include "libsnark/common/profiling.hpp" +#include "komodo_defs.h" char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; int64_t MAX_MONEY = 200000000 * 100000000LL; uint16_t BITCOIND_PORT = 7771; From eea03b7b5db7764503858514e1c9951f5216add5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 22 Nov 2017 10:53:16 +0400 Subject: [PATCH 132/188] jumblr_pause and jumblr_resume Thanks to @amigo for the feature request --- src/komodo_globals.h | 2 +- src/komodo_interest.h | 2 +- src/komodo_jumblr.h | 2 ++ src/rpcmisc.cpp | 22 +++++++++++++++++++++- src/rpcserver.cpp | 2 ++ src/rpcserver.h | 2 ++ 6 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/komodo_globals.h b/src/komodo_globals.h index e945beeee..144064d7a 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -44,7 +44,7 @@ struct komodo_state KOMODO_STATES[34]; int COINBASE_MATURITY = _COINBASE_MATURITY;//100; int32_t IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAINS_SEED,KOMODO_ON_DEMAND,KOMODO_EXTERNAL_NOTARIES,KOMODO_PASSPORT_INITDONE,KOMODO_PAX,KOMODO_EXCHANGEWALLET,KOMODO_REWIND; -int32_t KOMODO_LASTMINED,prevKOMODO_LASTMINED; +int32_t KOMODO_LASTMINED,prevKOMODO_LASTMINED,JUMBLR_PAUSE; std::string NOTARY_PUBKEY,ASSETCHAINS_NOTARIES; uint8_t NOTARY_PUBKEY33[33]; diff --git a/src/komodo_interest.h b/src/komodo_interest.h index 97f288b4c..63d0152ca 100644 --- a/src/komodo_interest.h +++ b/src/komodo_interest.h @@ -82,7 +82,7 @@ uint64_t komodo_moneysupply(int32_t height) uint64_t _komodo_interestnew(uint64_t nValue,uint32_t nLockTime,uint32_t tiptime) { int32_t minutes; uint64_t interest = 0; - if ( (minutes= (tiptime - nLockTime) / 60) >= 60 ) + if ( tiptime > nLockTime && (minutes= (tiptime - nLockTime) / 60) >= 60 ) { if ( minutes > 365 * 24 * 60 ) minutes = 365 * 24 * 60; diff --git a/src/komodo_jumblr.h b/src/komodo_jumblr.h index a5eff09a5..951ed9de0 100755 --- a/src/komodo_jumblr.h +++ b/src/komodo_jumblr.h @@ -630,6 +630,8 @@ void jumblr_iteration() { static int32_t lastheight; static uint32_t lasttime; char *zaddr,*addr,*retstr,secretaddr[64]; cJSON *array; int32_t i,iter,height,counter,chosen_one,n; uint64_t smallest,medium,biggest,amount=0,total=0; double fee; struct jumblr_item *ptr,*tmp; uint16_t r,s; + if ( JUMBLR_PAUSE != 0 ) + return; if ( lasttime == 0 ) { if ( (retstr= jumblr_zlistaddresses()) != 0 ) diff --git a/src/rpcmisc.cpp b/src/rpcmisc.cpp index 42307470f..6008e341d 100644 --- a/src/rpcmisc.cpp +++ b/src/rpcmisc.cpp @@ -47,7 +47,7 @@ uint64_t komodo_interestsum(); int32_t komodo_longestchain(); int32_t komodo_notarized_height(uint256 *hashp,uint256 *txidp); int32_t komodo_whoami(char *pubkeystr,int32_t height); -extern int32_t KOMODO_LASTMINED; +extern int32_t KOMODO_LASTMINED,JUMBLR_PAUSE; extern char ASSETCHAINS_SYMBOL[]; int32_t notarizedtxid_height(char *dest,char *txidstr,int32_t *kmdnotarized_heightp); #define KOMODO_VERSION "0.1.1" @@ -224,6 +224,26 @@ UniValue jumblr_secret(const UniValue& params, bool fHelp) return(result); } +UniValue jumblr_pause(const UniValue& params, bool fHelp) +{ + int32_t retval; UniValue result(UniValue::VOBJ); + if (fHelp ) + throw runtime_error("jumblr_pause\n"); + JUMBLR_PAUSE = 1; + result.push_back(Pair("result", "paused")); + return(result); +} + +UniValue jumblr_resume(const UniValue& params, bool fHelp) +{ + int32_t retval; UniValue result(UniValue::VOBJ); + if (fHelp ) + throw runtime_error("jumblr_resume\n"); + JUMBLR_PAUSE = 0; + result.push_back(Pair("result", "resumed")); + return(result); +} + UniValue validateaddress(const UniValue& params, bool fHelp) { if (fHelp || params.size() != 1) diff --git a/src/rpcserver.cpp b/src/rpcserver.cpp index 518ba4693..94521004d 100644 --- a/src/rpcserver.cpp +++ b/src/rpcserver.cpp @@ -338,6 +338,8 @@ static const CRPCCommand vRPCCommands[] = { "util", "z_validateaddress", &z_validateaddress, true }, /* uses wallet if enabled */ { "util", "jumblr_deposit", &jumblr_deposit, true }, { "util", "jumblr_secret", &jumblr_secret, true }, + { "util", "jumblr_pause", &jumblr_pause, true }, + { "util", "jumblr_resume", &jumblr_resume, true }, /* Not shown in help */ { "hidden", "invalidateblock", &invalidateblock, true }, diff --git a/src/rpcserver.h b/src/rpcserver.h index ecf7b0573..f59972472 100644 --- a/src/rpcserver.h +++ b/src/rpcserver.h @@ -248,6 +248,8 @@ extern UniValue zc_sample_joinsplit(const UniValue& params, bool fHelp); extern UniValue jumblr_deposit(const UniValue& params, bool fHelp); extern UniValue jumblr_secret(const UniValue& params, bool fHelp); +extern UniValue jumblr_pause(const UniValue& params, bool fHelp); +extern UniValue jumblr_resume(const UniValue& params, bool fHelp); extern UniValue getrawtransaction(const UniValue& params, bool fHelp); // in rcprawtransaction.cpp extern UniValue listunspent(const UniValue& params, bool fHelp); From 67030c8be03e07afa34e8b7a4fb6bee745669a30 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 30 Nov 2017 22:01:00 +0400 Subject: [PATCH 133/188] MSHARK --- src/assetchains | 1 + src/assetchains.old | 1 + src/dpowassets | 1 + src/fiat-cli | 1 + src/fiat/mshark | 2 ++ 5 files changed, 6 insertions(+) create mode 100755 src/fiat/mshark diff --git a/src/assetchains b/src/assetchains index f220139cf..6b80a62ea 100755 --- a/src/assetchains +++ b/src/assetchains @@ -36,6 +36,7 @@ komodo_asset BET 999999 komodo_asset CRYPTO 999999 komodo_asset HODL 9999999 komodo_asset SHARK 1401 +komodo_asset MSHARK 1400000 komodo_asset BOTS 999999 komodo_asset MGW 999999 #komodo_asset MVP 1000000 diff --git a/src/assetchains.old b/src/assetchains.old index e7584afcd..601eda111 100755 --- a/src/assetchains.old +++ b/src/assetchains.old @@ -13,6 +13,7 @@ echo $pubkey ./komodod -pubkey=$pubkey -ac_name=CRYPTO -ac_supply=999999 -addnode=78.47.196.146 $1 & ./komodod -pubkey=$pubkey -ac_name=HODL -ac_supply=9999999 -addnode=78.47.196.146 $1 & ./komodod -pubkey=$pubkey -ac_name=SHARK -ac_supply=1401 -addnode=78.47.196.146 $1 & +./komodod -pubkey=$pubkey -ac_name=MSHARK -ac_supply=1400000 -addnode=78.47.196.146 $1 & ./komodod -pubkey=$pubkey -ac_name=BOTS -ac_supply=999999 -addnode=78.47.196.146 $1 & ./komodod -pubkey=$pubkey -ac_name=MGW -ac_supply=999999 -addnode=78.47.196.146 $1 & #./komodod -pubkey=$pubkey -ac_name=MVP -ac_supply=1000000 -addnode=78.47.196.146 $1 & diff --git a/src/dpowassets b/src/dpowassets index 5e0facea0..6c1c75c2c 100755 --- a/src/dpowassets +++ b/src/dpowassets @@ -14,6 +14,7 @@ curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dp curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"CRYPTO\",\"pubkey\":\"$pubkey\"}" curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"HODL\",\"pubkey\":\"$pubkey\"}" curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"SHARK\",\"pubkey\":\"$pubkey\"}" +curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"MSHARK\",\"pubkey\":\"$pubkey\"}" curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"BOTS\",\"pubkey\":\"$pubkey\"}" curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"MGW\",\"pubkey\":\"$pubkey\"}" #curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"MVP\",\"pubkey\":\"$pubkey\"}" diff --git a/src/fiat-cli b/src/fiat-cli index e83a7f757..5c8940f82 100755 --- a/src/fiat-cli +++ b/src/fiat-cli @@ -41,6 +41,7 @@ echo bet; fiat/bet $1 $2 $3 $4 echo crypto; fiat/crypto $1 $2 $3 $4 echo hodl; fiat/hodl $1 $2 $3 $4 echo shark; fiat/shark $1 $2 $3 $4 +echo mshark; fiat/mshark $1 $2 $3 $4 echo bots; fiat/bots $1 $2 $3 $4 echo mgw; fiat/mgw $1 $2 $3 $4 #echo mvp; fiat/mvp $1 $2 $3 $4 diff --git a/src/fiat/mshark b/src/fiat/mshark new file mode 100755 index 000000000..1f0c950c6 --- /dev/null +++ b/src/fiat/mshark @@ -0,0 +1,2 @@ +#!/bin/bash +./komodo-cli -ac_name=MSHARK $1 $2 $3 $4 $5 $6 From 4ea19a87a1b73ca9e0612878282d25c3afa823c7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 30 Nov 2017 23:42:15 +0400 Subject: [PATCH 134/188] Test --- src/wallet/wallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 67f7a7fe0..341b2bf5a 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2749,7 +2749,7 @@ bool CWallet::CreateTransaction(const vector& vecSend, CWalletTx& wt //interest = 0; // interest2 also //} CAmount nChange = (nValueIn - nValue + interest2); -fprintf(stderr,"wallet change %.8f (%.8f - %.8f) interest2 %.8f total %.8f\n",(double)nChange/COIN,(double)nValueIn/COIN,(double)nValue/COIN,(double)interest2/COIN,(double)nTotalValue/COIN); +//fprintf(stderr,"wallet change %.8f (%.8f - %.8f) interest2 %.8f total %.8f\n",(double)nChange/COIN,(double)nValueIn/COIN,(double)nValue/COIN,(double)interest2/COIN,(double)nTotalValue/COIN); if (nSubtractFeeFromAmount == 0) nChange -= nFeeRet; From 8bec736c1ffc5a268c8a8e1e03b00802a68f39a6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 1 Jan 2018 15:36:45 +0700 Subject: [PATCH 135/188] AXO, ETOMIC, BTCH --- src/assetchains | 3 +++ src/assetchains.old | 4 ++++ src/dpowassets | 3 +++ src/fiat-cli | 3 +++ src/fiat/axo | 2 ++ src/fiat/btch | 2 ++ src/fiat/etomic | 2 ++ 7 files changed, 19 insertions(+) create mode 100755 src/fiat/axo create mode 100755 src/fiat/btch create mode 100755 src/fiat/etomic diff --git a/src/assetchains b/src/assetchains index 6b80a62ea..0d3773eec 100755 --- a/src/assetchains +++ b/src/assetchains @@ -46,6 +46,9 @@ komodo_asset KV 1000000 komodo_asset CEAL 366666666 komodo_asset MESH 1000007 komodo_asset MNZ 257142858 +komodo_asset AXO 200000000 +komodo_asset ETOMIC 100000000 +komodo_asset BTCH 20998641 komodo_asset USD komodo_asset EUR diff --git a/src/assetchains.old b/src/assetchains.old index 601eda111..c92d4cf1a 100755 --- a/src/assetchains.old +++ b/src/assetchains.old @@ -23,6 +23,10 @@ echo $pubkey ./komodod -pubkey=$pubkey -ac_name=CEAL -ac_supply=366666666 -addnode=78.47.196.146 $1 & ./komodod -pubkey=$pubkey -ac_name=MESH -ac_supply=1000007 -addnode=78.47.196.146 $1 & ./komodod -pubkey=$pubkey -ac_name=MNZ -ac_supply=257142858 -addnode=51.15.138.138 $1 & +./komodod -pubkey=$pubkey -ac_name=AXO -ac_supply=200000000 -addnode=78.47.196.146 & +./komodod -pubkey=$pubkey -ac_name=ETOMIC -ac_supply=100000000 -addnode=78.47.196.146 & +./komodod -pubkey=$pubkey -ac_name=BTCH -ac_supply=20998641 -addnode=78.47.196.146 & + sleep $delay ./komodod -pubkey=$pubkey -ac_name=USD -addnode=78.47.196.146 $1 & diff --git a/src/dpowassets b/src/dpowassets index 6c1c75c2c..b047eeae2 100755 --- a/src/dpowassets +++ b/src/dpowassets @@ -25,6 +25,9 @@ curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dp curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"MESH\",\"pubkey\":\"$pubkey\"}" curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"MNZ\",\"pubkey\":\"$pubkey\"}" curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"CHIPS\",\"pubkey\":\"$pubkey\"}" +curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"AXO\",\"pubkey\":\"$pubkey\"}" +curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"ETOMIC\",\"pubkey\":\"$pubkey\"}" +curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"BTCH\",\"pubkey\":\"$pubkey\"}" #curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"USD\",\"pubkey\":\"$pubkey\"}" diff --git a/src/fiat-cli b/src/fiat-cli index 5c8940f82..f38ea57a0 100755 --- a/src/fiat-cli +++ b/src/fiat-cli @@ -51,3 +51,6 @@ echo kv; fiat/kv $1 $2 $3 $4 echo ceal; fiat/ceal $1 $2 $3 $4 echo mesh; fiat/mesh $1 $2 $3 $4 echo mnz; fiat/mnz $1 $2 $3 $4 +echo mnz; fiat/axo $1 $2 $3 $4 +echo mnz; fiat/etomic $1 $2 $3 $4 +echo mnz; fiat/btch $1 $2 $3 $4 diff --git a/src/fiat/axo b/src/fiat/axo new file mode 100755 index 000000000..18d38cac0 --- /dev/null +++ b/src/fiat/axo @@ -0,0 +1,2 @@ +#!/bin/bash +./komodo-cli -ac_name=AXO $1 $2 $3 $4 $5 $6 diff --git a/src/fiat/btch b/src/fiat/btch new file mode 100755 index 000000000..6a57ea8d1 --- /dev/null +++ b/src/fiat/btch @@ -0,0 +1,2 @@ +#!/bin/bash +./komodo-cli -ac_name=BTCH $1 $2 $3 $4 $5 $6 diff --git a/src/fiat/etomic b/src/fiat/etomic new file mode 100755 index 000000000..76eb0191c --- /dev/null +++ b/src/fiat/etomic @@ -0,0 +1,2 @@ +#!/bin/bash +./komodo-cli -ac_name=ETOMIC $1 $2 $3 $4 $5 $6 From cb84dc08eeee2638a8985eeed68b1dda13321123 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 1 Jan 2018 15:38:26 +0700 Subject: [PATCH 136/188] Fix --- src/fiat-cli | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/fiat-cli b/src/fiat-cli index f38ea57a0..59753d0ed 100755 --- a/src/fiat-cli +++ b/src/fiat-cli @@ -51,6 +51,6 @@ echo kv; fiat/kv $1 $2 $3 $4 echo ceal; fiat/ceal $1 $2 $3 $4 echo mesh; fiat/mesh $1 $2 $3 $4 echo mnz; fiat/mnz $1 $2 $3 $4 -echo mnz; fiat/axo $1 $2 $3 $4 -echo mnz; fiat/etomic $1 $2 $3 $4 -echo mnz; fiat/btch $1 $2 $3 $4 +echo axo; fiat/axo $1 $2 $3 $4 +echo etomic; fiat/etomic $1 $2 $3 $4 +echo btch; fiat/btch $1 $2 $3 $4 From dfd450dff9a95cdfc8e7e9df018d875b68ed4760 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Jan 2018 13:23:58 +0700 Subject: [PATCH 137/188] signedmasks for asset chains --- src/komodo.h | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index e8ab6d6be..d5856f119 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -546,22 +546,22 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr len += 4; if ( ASSETCHAINS_SYMBOL[0] != 0 ) printf("[%s] ht.%d NOTARIZED.%d %s.%s %sTXID.%s lens.(%d %d)\n",ASSETCHAINS_SYMBOL,height,*notarizedheightp,ASSETCHAINS_SYMBOL[0]==0?"KMD":ASSETCHAINS_SYMBOL,kmdtxid.ToString().c_str(),ASSETCHAINS_SYMBOL[0]==0?"BTC":"KMD",desttxid.ToString().c_str(),opretlen,len); + if ( signedfp == 0 ) + { + char fname[512]; + komodo_statefname(fname,ASSETCHAINS_SYMBOL,(char *)"signedmasks"); + if ( (signedfp= fopen(fname,"rb+")) == 0 ) + signedfp = fopen(fname,"wb"); + else fseek(signedfp,0,SEEK_END); + } + if ( signedfp != 0 ) + { + fwrite(&height,1,sizeof(height),signedfp); + fwrite(&signedmask,1,sizeof(signedmask),signedfp); + fflush(signedfp); + } if ( ASSETCHAINS_SYMBOL[0] == 0 ) { - if ( signedfp == 0 ) - { - char fname[512]; - komodo_statefname(fname,(char *)"",(char *)"signedmasks"); - if ( (signedfp= fopen(fname,"rb+")) == 0 ) - signedfp = fopen(fname,"wb"); - else fseek(signedfp,0,SEEK_END); - } - if ( signedfp != 0 ) - { - fwrite(&height,1,sizeof(height),signedfp); - fwrite(&signedmask,1,sizeof(signedmask),signedfp); - fflush(signedfp); - } if ( opretlen > len && scriptbuf[len] == 'A' ) { //for (i=0; i Date: Tue, 2 Jan 2018 14:22:50 +0700 Subject: [PATCH 138/188] Test --- src/komodo.h | 47 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 15 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index d5856f119..74d1c5cdd 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -546,22 +546,22 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr len += 4; if ( ASSETCHAINS_SYMBOL[0] != 0 ) printf("[%s] ht.%d NOTARIZED.%d %s.%s %sTXID.%s lens.(%d %d)\n",ASSETCHAINS_SYMBOL,height,*notarizedheightp,ASSETCHAINS_SYMBOL[0]==0?"KMD":ASSETCHAINS_SYMBOL,kmdtxid.ToString().c_str(),ASSETCHAINS_SYMBOL[0]==0?"BTC":"KMD",desttxid.ToString().c_str(),opretlen,len); - if ( signedfp == 0 ) - { - char fname[512]; - komodo_statefname(fname,ASSETCHAINS_SYMBOL,(char *)"signedmasks"); - if ( (signedfp= fopen(fname,"rb+")) == 0 ) - signedfp = fopen(fname,"wb"); - else fseek(signedfp,0,SEEK_END); - } - if ( signedfp != 0 ) - { - fwrite(&height,1,sizeof(height),signedfp); - fwrite(&signedmask,1,sizeof(signedmask),signedfp); - fflush(signedfp); - } if ( ASSETCHAINS_SYMBOL[0] == 0 ) { + if ( signedfp == 0 ) + { + char fname[512]; + komodo_statefname(fname,ASSETCHAINS_SYMBOL,(char *)"signedmasks"); + if ( (signedfp= fopen(fname,"rb+")) == 0 ) + signedfp = fopen(fname,"wb"); + else fseek(signedfp,0,SEEK_END); + } + if ( signedfp != 0 ) + { + fwrite(&height,1,sizeof(height),signedfp); + fwrite(&signedmask,1,sizeof(signedmask),signedfp); + fflush(signedfp); + } if ( opretlen > len && scriptbuf[len] == 'A' ) { //for (i=0; i= KOMODO_MINRATIFY && ASSETCHAINS_SYMBOL[0] != 0) || numvalid > (numnotaries/5)) ) { - if ( height > 500000 || ASSETCHAINS_SYMBOL[0] != 0 ) + if ( ASSETCHAINS_SYMBOL[0] != 0 ) + { + static FILE *signedfp; + if ( signedfp == 0 ) + { + char fname[512]; + komodo_statefname(fname,ASSETCHAINS_SYMBOL,(char *)"signedmasks"); + if ( (signedfp= fopen(fname,"rb+")) == 0 ) + signedfp = fopen(fname,"wb"); + else fseek(signedfp,0,SEEK_END); + } + if ( signedfp != 0 ) + { + fwrite(&height,1,sizeof(height),signedfp); + fwrite(&signedmask,1,sizeof(signedmask),signedfp); + fflush(signedfp); + } printf("[%s] ht.%d txi.%d signedmask.%llx numvins.%d numvouts.%d <<<<<<<<<<< notarized\n",ASSETCHAINS_SYMBOL,height,i,(long long)signedmask,numvins,numvouts); + } notarized = 1; } if ( NOTARY_PUBKEY33[0] != 0 && ASSETCHAINS_SYMBOL[0] == 0 ) From 1132e84500f88e4ed354c7c5cb025b4d92f06c75 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 2 Jan 2018 14:24:59 +0700 Subject: [PATCH 139/188] Test --- src/komodo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index 74d1c5cdd..c6467d957 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -709,7 +709,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) fwrite(&signedmask,1,sizeof(signedmask),signedfp); fflush(signedfp); } - printf("[%s] ht.%d txi.%d signedmask.%llx numvins.%d numvouts.%d <<<<<<<<<<< notarized\n",ASSETCHAINS_SYMBOL,height,i,(long long)signedmask,numvins,numvouts); + printf("[%s] ht.%d txi.%d signedmask.%llx numvins.%d numvouts.%d <<<<<<<<<<< notarized\n",ASSETCHAINS_SYMBOL,height,i,(long long)signedmask,numvins,numvouts); } notarized = 1; } From ee92f1369d7b5d8923674e7b64f51226f12ef5c9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 3 Jan 2018 01:06:03 +0700 Subject: [PATCH 140/188] -SHARK --- src/assetchains | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/assetchains b/src/assetchains index 0d3773eec..6063ad379 100755 --- a/src/assetchains +++ b/src/assetchains @@ -35,7 +35,7 @@ komodo_asset JUMBLR 999999 komodo_asset BET 999999 komodo_asset CRYPTO 999999 komodo_asset HODL 9999999 -komodo_asset SHARK 1401 +#komodo_asset SHARK 1401 komodo_asset MSHARK 1400000 komodo_asset BOTS 999999 komodo_asset MGW 999999 From 5faab5a65a8fbbfdefc6c819c9d1f638f843e96d Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 4 Jan 2018 18:35:35 +0700 Subject: [PATCH 141/188] -SHARK --- src/assetchains.old | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/assetchains.old b/src/assetchains.old index c92d4cf1a..9e14165fe 100755 --- a/src/assetchains.old +++ b/src/assetchains.old @@ -12,7 +12,7 @@ echo $pubkey ./komodod -pubkey=$pubkey -ac_name=BET -ac_supply=999999 -addnode=78.47.196.146 $1 & ./komodod -pubkey=$pubkey -ac_name=CRYPTO -ac_supply=999999 -addnode=78.47.196.146 $1 & ./komodod -pubkey=$pubkey -ac_name=HODL -ac_supply=9999999 -addnode=78.47.196.146 $1 & -./komodod -pubkey=$pubkey -ac_name=SHARK -ac_supply=1401 -addnode=78.47.196.146 $1 & +#./komodod -pubkey=$pubkey -ac_name=SHARK -ac_supply=1401 -addnode=78.47.196.146 $1 & ./komodod -pubkey=$pubkey -ac_name=MSHARK -ac_supply=1400000 -addnode=78.47.196.146 $1 & ./komodod -pubkey=$pubkey -ac_name=BOTS -ac_supply=999999 -addnode=78.47.196.146 $1 & ./komodod -pubkey=$pubkey -ac_name=MGW -ac_supply=999999 -addnode=78.47.196.146 $1 & From b91547118a609f4b022e7137bdf557d5d1c278fe Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 4 Jan 2018 18:45:07 +0700 Subject: [PATCH 142/188] -fiat -shark fiat-cli --- src/fiat-cli | 66 ++++++++++++++++++++++++++-------------------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/src/fiat-cli b/src/fiat-cli index 59753d0ed..0d9dc87af 100755 --- a/src/fiat-cli +++ b/src/fiat-cli @@ -1,37 +1,37 @@ #!/bin/bash #set -x -echo aud; fiat/aud $1 $2 $3 $4 -echo bgn; fiat/bgn $1 $2 $3 $4 -echo cad; fiat/cad $1 $2 $3 $4 -echo chf; fiat/chf $1 $2 $3 $4 -echo cny; fiat/cny $1 $2 $3 $4 -echo czk; fiat/czk $1 $2 $3 $4 -echo dkk; fiat/dkk $1 $2 $3 $4 -echo eur; fiat/eur $1 $2 $3 $4 -echo gbp; fiat/gbp $1 $2 $3 $4 -echo hkd; fiat/hkd $1 $2 $3 $4 -echo hrk; fiat/hrk $1 $2 $3 $4 -echo huf; fiat/huf $1 $2 $3 $4 -echo idr; fiat/idr $1 $2 $3 $4 -echo ils; fiat/ils $1 $2 $3 $4 -echo inr; fiat/inr $1 $2 $3 $4 -echo jpy; fiat/jpy $1 $2 $3 $4 -echo krw; fiat/krw $1 $2 $3 $4 -echo mxn; fiat/mxn $1 $2 $3 $4 -echo myr; fiat/myr $1 $2 $3 $4 -echo nok; fiat/nok $1 $2 $3 $4 -echo nzd; fiat/nzd $1 $2 $3 $4 -echo php; fiat/php $1 $2 $3 $4 -echo pln; fiat/pln $1 $2 $3 $4 -echo brl; fiat/brl $1 $2 $3 $4 -echo ron; fiat/ron $1 $2 $3 $4 -echo rub; fiat/rub $1 $2 $3 $4 -echo sek; fiat/sek $1 $2 $3 $4 -echo sgd; fiat/sgd $1 $2 $3 $4 -echo thb; fiat/thb $1 $2 $3 $4 -echo try; fiat/try $1 $2 $3 $4 -echo usd; fiat/usd $1 $2 $3 $4 -echo zar; fiat/zar $1 $2 $3 $4 +#echo aud; fiat/aud $1 $2 $3 $4 +#echo bgn; fiat/bgn $1 $2 $3 $4 +#echo cad; fiat/cad $1 $2 $3 $4 +#echo chf; fiat/chf $1 $2 $3 $4 +#echo cny; fiat/cny $1 $2 $3 $4 +#echo czk; fiat/czk $1 $2 $3 $4 +#echo dkk; fiat/dkk $1 $2 $3 $4 +#echo eur; fiat/eur $1 $2 $3 $4 +#echo gbp; fiat/gbp $1 $2 $3 $4 +#echo hkd; fiat/hkd $1 $2 $3 $4 +#echo hrk; fiat/hrk $1 $2 $3 $4 +#echo huf; fiat/huf $1 $2 $3 $4 +#echo idr; fiat/idr $1 $2 $3 $4 +#echo ils; fiat/ils $1 $2 $3 $4 +#echo inr; fiat/inr $1 $2 $3 $4 +#echo jpy; fiat/jpy $1 $2 $3 $4 +#echo krw; fiat/krw $1 $2 $3 $4 +#echo mxn; fiat/mxn $1 $2 $3 $4 +#echo myr; fiat/myr $1 $2 $3 $4 +#echo nok; fiat/nok $1 $2 $3 $4 +#echo nzd; fiat/nzd $1 $2 $3 $4 +#echo php; fiat/php $1 $2 $3 $4 +#echo pln; fiat/pln $1 $2 $3 $4 +#echo brl; fiat/brl $1 $2 $3 $4 +#echo ron; fiat/ron $1 $2 $3 $4 +#echo rub; fiat/rub $1 $2 $3 $4 +#echo sek; fiat/sek $1 $2 $3 $4 +#echo sgd; fiat/sgd $1 $2 $3 $4 +#echo thb; fiat/thb $1 $2 $3 $4 +#echo try; fiat/try $1 $2 $3 $4 +#echo usd; fiat/usd $1 $2 $3 $4 +#echo zar; fiat/zar $1 $2 $3 $4 echo revs; fiat/revs $1 $2 $3 $4 echo supernet; fiat/supernet $1 $2 $3 $4 echo dex; fiat/dex $1 $2 $3 $4 @@ -40,7 +40,7 @@ echo jumblr; fiat/jumblr $1 $2 $3 $4 echo bet; fiat/bet $1 $2 $3 $4 echo crypto; fiat/crypto $1 $2 $3 $4 echo hodl; fiat/hodl $1 $2 $3 $4 -echo shark; fiat/shark $1 $2 $3 $4 +#echo shark; fiat/shark $1 $2 $3 $4 echo mshark; fiat/mshark $1 $2 $3 $4 echo bots; fiat/bots $1 $2 $3 $4 echo mgw; fiat/mgw $1 $2 $3 $4 From df473cc2775205c011cfe7f8bd5d58dc4f44afc0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 7 Jan 2018 18:06:14 +0700 Subject: [PATCH 143/188] Check for null index in FindFork --- src/chain.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/chain.cpp b/src/chain.cpp index 5b8ce076c..9cd13d997 100644 --- a/src/chain.cpp +++ b/src/chain.cpp @@ -51,6 +51,8 @@ CBlockLocator CChain::GetLocator(const CBlockIndex *pindex) const { } const CBlockIndex *CChain::FindFork(const CBlockIndex *pindex) const { + if ( pindex == 0 ) + return(0); if (pindex->nHeight > Height()) pindex = pindex->GetAncestor(Height()); while (pindex && !Contains(pindex)) From da925f7863f69240ff0aeabe4bfb1e649691f0f1 Mon Sep 17 00:00:00 2001 From: ca333 Date: Mon, 22 Jan 2018 06:02:44 +0100 Subject: [PATCH 144/188] 333 removed unneeded dependencies --- README.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 6c927185c..65f34d3d4 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ It downloads and stores the entire history of Komodo transactions; depending on - Komodo Platform public material: [Komodo Platform public material](https://docs.google.com/document/d/1AbhWrtagu4vYdkl-vsWz-HSNyNvK-W-ZasHCqe7CZy0) ## List of Komodo Platform Technologies Delayed Proof of Work (dPoW) - Additional security layer. -zk-SNARKs - Komodo Platform�s privacy technology +zk-SNARKs - Komodo Platform's privacy technology Jumblr - Decentralized tumbler for KMD and other cryptocurrencies Assetchains - Easy way to fork Komodo coin Pegged Assets - Chains that maintain a peg to fiat currencies @@ -26,15 +26,14 @@ Block Time: 1M 2s Block Reward: 3KMD Mining Algorithm: Equihash ## About this Project -Komodo has being evolved from Zcash project, where we used some of their codebase and extended it with new technologies. -Same Zcash is based on Bitcoin's code, with differnece Zcash intends to offer a far higher standard of privacy through a sophisticated zero-knowledge proving scheme that preserves confidentiality of transaction metadata. Technical details are available in our [Protocol Specification](https://github.com/zcash/zips/raw/master/protocol/protocol.pdf). +Komodo is based on Zcash and has been by our innovative consensus algorithm called dPoW which utilizes Bitcoin's hashrate to store Komodo blockchain information into the Bitcoin blockchain. Other new and native Komodo features are the privacy technology called JUMBLR or our assetchain capabilities (one click plug and play blockchain solutions). More details are available under https://komodoplatform.com/. ## Getting started Dependencies ------------ ``` #The following packages are needed: -sudo apt-get install build-essential pkg-config libcurl3-gnutls-dev libc6-dev libevent-dev m4 g++-multilib autoconf libtool ncurses-dev unzip git python zlib1g-dev wget bsdmainutils automake libboost-all-dev libssl-dev libprotobuf-dev protobuf-compiler libqt4-dev libqrencode-dev libdb++-dev ntp ntpdate +sudo apt-get install build-essential pkg-config libc6-dev m4 g++-multilib autoconf libtool ncurses-dev unzip git python python-zmq zlib1g-dev wget libcurl3-gnutls-dev bsdmainutils automake ``` Komodo From f41277aa91f8c1c86088fbe403d4fe040cefbc5b Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 25 Jan 2018 16:54:37 +0400 Subject: [PATCH 145/188] PIZZA and BEER --- src/fiat-cli | 2 ++ src/fiat/beer | 2 ++ src/fiat/pizza | 2 ++ 3 files changed, 6 insertions(+) create mode 100755 src/fiat/beer create mode 100755 src/fiat/pizza diff --git a/src/fiat-cli b/src/fiat-cli index 0d9dc87af..14d0f0b18 100755 --- a/src/fiat-cli +++ b/src/fiat-cli @@ -54,3 +54,5 @@ echo mnz; fiat/mnz $1 $2 $3 $4 echo axo; fiat/axo $1 $2 $3 $4 echo etomic; fiat/etomic $1 $2 $3 $4 echo btch; fiat/btch $1 $2 $3 $4 +echo pizza; fiat/pizza $1 $2 $3 $4 +echo beer; fiat/beer $1 $2 $3 $4 diff --git a/src/fiat/beer b/src/fiat/beer new file mode 100755 index 000000000..34317bb93 --- /dev/null +++ b/src/fiat/beer @@ -0,0 +1,2 @@ +#!/bin/bash +./komodo-cli -ac_name=BEER $1 $2 $3 $4 $5 $6 diff --git a/src/fiat/pizza b/src/fiat/pizza new file mode 100755 index 000000000..d8400d9d3 --- /dev/null +++ b/src/fiat/pizza @@ -0,0 +1,2 @@ +#!/bin/bash +./komodo-cli -ac_name=PIZZA $1 $2 $3 $4 $5 $6 From b3b56273c63da546051d80b08b918b9e4141e87b Mon Sep 17 00:00:00 2001 From: Mihail Fedorov Date: Sat, 27 Jan 2018 04:46:39 +0300 Subject: [PATCH 146/188] So long and thanks for all the pax --- src/assetchains | 66 ++++++++++++++++++++++++------------------------- src/assetfunds | 34 ------------------------- 2 files changed, 33 insertions(+), 67 deletions(-) delete mode 100755 src/assetfunds diff --git a/src/assetchains b/src/assetchains index 6063ad379..784ffa28e 100755 --- a/src/assetchains +++ b/src/assetchains @@ -1,7 +1,7 @@ #!/bin/bash source pubkey.txt args=("$@") -seed_ip='78.47.196.146' +seed_ip=`getent hosts aseed.mewhub.com | awk '{ print $1 }'` komodo_binary='./komodod' delay=20 @@ -50,35 +50,35 @@ komodo_asset AXO 200000000 komodo_asset ETOMIC 100000000 komodo_asset BTCH 20998641 -komodo_asset USD -komodo_asset EUR -komodo_asset JPY -komodo_asset GBP -komodo_asset AUD -komodo_asset CAD -komodo_asset CHF -komodo_asset NZD -komodo_asset CNY -komodo_asset RUB -komodo_asset MXN -komodo_asset BRL -komodo_asset INR -komodo_asset HKD -komodo_asset TRY -komodo_asset ZAR -komodo_asset PLN -komodo_asset NOK -komodo_asset SEK -komodo_asset DKK -komodo_asset CZK -komodo_asset HUF -komodo_asset ILS -komodo_asset KRW -komodo_asset MYR -komodo_asset PHP -komodo_asset RON -komodo_asset SGD -komodo_asset THB -komodo_asset BGN -komodo_asset IDR -komodo_asset HRK +#komodo_asset USD +#komodo_asset EUR +#komodo_asset JPY +#komodo_asset GBP +#komodo_asset AUD +#komodo_asset CAD +#komodo_asset CHF +#komodo_asset NZD +#komodo_asset CNY +#komodo_asset RUB +#komodo_asset MXN +#komodo_asset BRL +#komodo_asset INR +#komodo_asset HKD +#komodo_asset TRY +#komodo_asset ZAR +#komodo_asset PLN +#komodo_asset NOK +#komodo_asset SEK +#komodo_asset DKK +#komodo_asset CZK +#komodo_asset HUF +#komodo_asset ILS +#komodo_asset KRW +#komodo_asset MYR +#komodo_asset PHP +#komodo_asset RON +#komodo_asset SGD +#komodo_asset THB +#komodo_asset BGN +#komodo_asset IDR +#komodo_asset HRK diff --git a/src/assetfunds b/src/assetfunds deleted file mode 100755 index 6aede587c..000000000 --- a/src/assetfunds +++ /dev/null @@ -1,34 +0,0 @@ -#!/bin/bash -set -x -./komodo-cli paxdeposit $1 0.01 aud -./komodo-cli paxdeposit $1 0.01 bgn -./komodo-cli paxdeposit $1 0.01 cad -./komodo-cli paxdeposit $1 0.01 chf -./komodo-cli paxdeposit $1 0.01 cny -./komodo-cli paxdeposit $1 0.01 czk -./komodo-cli paxdeposit $1 0.01 dkk -./komodo-cli paxdeposit $1 0.01 eur -./komodo-cli paxdeposit $1 0.01 gbp -./komodo-cli paxdeposit $1 0.01 hkd -./komodo-cli paxdeposit $1 0.01 hrk -./komodo-cli paxdeposit $1 0.01 huf -./komodo-cli paxdeposit $1 0.01 idr -./komodo-cli paxdeposit $1 0.01 ils -./komodo-cli paxdeposit $1 0.01 inr -./komodo-cli paxdeposit $1 0.01 jpy -./komodo-cli paxdeposit $1 0.01 krw -./komodo-cli paxdeposit $1 0.01 mxn -./komodo-cli paxdeposit $1 0.01 myr -./komodo-cli paxdeposit $1 0.01 nok -./komodo-cli paxdeposit $1 0.01 nzd -./komodo-cli paxdeposit $1 0.01 php -./komodo-cli paxdeposit $1 0.01 pln -./komodo-cli paxdeposit $1 0.01 brl -./komodo-cli paxdeposit $1 0.01 ron -./komodo-cli paxdeposit $1 0.01 rub -./komodo-cli paxdeposit $1 0.01 sek -./komodo-cli paxdeposit $1 0.01 sgd -./komodo-cli paxdeposit $1 0.01 thb -./komodo-cli paxdeposit $1 0.01 try -./komodo-cli paxdeposit $1 0.01 usd -./komodo-cli paxdeposit $1 0.01 zar From 26e6a849ac4f2cc5a64ba070ba83bc4666ea1aa3 Mon Sep 17 00:00:00 2001 From: Mihail Fedorov Date: Sat, 27 Jan 2018 04:47:14 +0300 Subject: [PATCH 147/188] So long and thanks for all the pax --- src/assetchains | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/assetchains b/src/assetchains index 784ffa28e..b05fa1507 100755 --- a/src/assetchains +++ b/src/assetchains @@ -1,7 +1,7 @@ #!/bin/bash source pubkey.txt args=("$@") -seed_ip=`getent hosts aseed.mewhub.com | awk '{ print $1 }'` +seed_ip=`getent hosts seed.mewhub.com | awk '{ print $1 }'` komodo_binary='./komodod' delay=20 From 580a1ae0cf233b5a9ecb919c51d088de67589959 Mon Sep 17 00:00:00 2001 From: Mihail Fedorov Date: Sat, 27 Jan 2018 05:14:24 +0300 Subject: [PATCH 148/188] VOTE chain --- src/assetchains | 1 + 1 file changed, 1 insertion(+) diff --git a/src/assetchains b/src/assetchains index b05fa1507..1ca93b3c2 100755 --- a/src/assetchains +++ b/src/assetchains @@ -49,6 +49,7 @@ komodo_asset MNZ 257142858 komodo_asset AXO 200000000 komodo_asset ETOMIC 100000000 komodo_asset BTCH 20998641 +komodo_asset VOTE 49999999999 #komodo_asset USD #komodo_asset EUR From b3f7ce9b7a50bb349776790ce39db7280202eedf Mon Sep 17 00:00:00 2001 From: DeckerSU Date: Sat, 27 Jan 2018 13:28:43 +0300 Subject: [PATCH 149/188] added checkpoints for KMD blockchain. need to be tested. - added method SetCheckpointData for CChainParams. - as we can't check asset it or not in CMainParams() constructor, because command line arguments don't initialized at that time, we will execute SetCheckpointData in chainparams_commandline later. changes was tested in komodo-qt wallet, but additional tests wouldn't be superfluous. --- src/chainparams.cpp | 187 ++++++++++++++++++++++++++++++++++++++++++++ src/chainparams.h | 5 +- 2 files changed, 191 insertions(+), 1 deletion(-) diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 13409c8c4..d84278b31 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -118,6 +118,7 @@ public: fRequireStandard = true; fMineBlocksOnDemand = false; fTestnetToBeDeprecatedFieldRPC = false; +/* checkpointData = (Checkpoints::CCheckpointData) { boost::assign::map_list_of @@ -131,6 +132,17 @@ public: 2777 // * estimated number of transactions per day after checkpoint // total number of tx / (checkpoint block height / (24 * 24)) }; +*/ + +// LogPrintf(">>>>>>>> ac_name = %u\n",GetArg("-ac_name","").c_str()); + +// if ( GetArg("-ac_name","").c_str()[0] != 0 ) +// { +// } +// else +// { +// } + if ( pthread_create((pthread_t *)malloc(sizeof(pthread_t)),NULL,chainparams_commandline,(void *)&consensus) != 0 ) { @@ -139,8 +151,14 @@ public: }; static CMainParams mainParams; +void CChainParams::SetCheckpointData(Checkpoints::CCheckpointData checkpointData) +{ + CChainParams::checkpointData = checkpointData; +} + void *chainparams_commandline(void *ptr) { + Checkpoints::CCheckpointData checkpointData; while ( ASSETCHAINS_PORT == 0 ) { #ifdef _WIN32 @@ -158,7 +176,176 @@ void *chainparams_commandline(void *ptr) mainParams.pchMessageStart[2] = (ASSETCHAINS_MAGIC >> 16) & 0xff; mainParams.pchMessageStart[3] = (ASSETCHAINS_MAGIC >> 24) & 0xff; fprintf(stderr,">>>>>>>>>> %s: port.%u/%u magic.%08x %u %u coins\n",ASSETCHAINS_SYMBOL,ASSETCHAINS_PORT,ASSETCHAINS_PORT+1,ASSETCHAINS_MAGIC,ASSETCHAINS_MAGIC,(uint32_t)ASSETCHAINS_SUPPLY); + + checkpointData = //(Checkpoints::CCheckpointData) + { + boost::assign::map_list_of + (0, mainParams.consensus.hashGenesisBlock), + //(2500, uint256S("0x0e6a3d5a46eba97c4e7618d66a39f115729e1176433c98481124c2bf733aa54e")) + //(15000, uint256S("0x00f0bd236790e903321a2d22f85bd6bf8a505f6ef4eddb20458a65d37e14d142")), + //(100000, uint256S("0x0f02eb1f3a4b89df9909fec81a4bd7d023e32e24e1f5262d9fc2cc36a715be6f")), + (int64_t)1481120910, // * UNIX timestamp of last checkpoint block + (int64_t)110415, // * total number of transactions between genesis and last checkpoint + // (the tx=... number in the SetBestChain debug.log lines) + (double)2777 // * estimated number of transactions per day after checkpoint + // total number of tx / (checkpoint block height / (24 * 24)) + }; + } + else + { + checkpointData = //(Checkpoints::CCheckpointData) + { + boost::assign::map_list_of + + (0, mainParams.consensus.hashGenesisBlock) + ( 5000, uint256S("0x049cfc91eef411e96603a42c9a77c5e30e9fe96f783ab818f4c00fb56fb29b6c")) + ( 10000, uint256S("0x0a0169db3614311cd4181deb73cfcf7f640e7dc956cda34e0121a0351925e9ae")) + ( 15000, uint256S("0x00f0bd236790e903321a2d22f85bd6bf8a505f6ef4eddb20458a65d37e14d142")) + ( 20000, uint256S("0x01bbf0c38892bdcced62b538329cf63bc7badca3e7e1bff8eb10345436871c6e")) + ( 25000, uint256S("0x04ca27808268dda8f942b647a6df844be1b263a661a13740293db962022d1f9e")) + ( 30000, uint256S("0x04c9e8cfbcd37399085e529b50147de8afb80c76c48752c122d56f23316a7acb")) + ( 35000, uint256S("0x00815f1240354cff7487c67f7dff78e248cb9053ed2c92751d1a9ad42d3eaedf")) + ( 40000, uint256S("0x00eafd9dfb1e5f1bf1cca0c49be628538900daf69b665464443d29c2c3b6a2fe")) + ( 45000, uint256S("0x0377730632caf694b92f40d03ae0fbe5bd86a1205014b71d975453ac793b0af9")) + ( 50000, uint256S("0x00076e16d3fa5194da559c17cf9cf285e21d1f13154ae4f7c7b87919549345aa")) + ( 55000, uint256S("0x0005a0701a83e05b639418ea4c87018544a4d22b2b49e5f111161e8ffc455108")) + ( 60000, uint256S("0x0000296fc15f8599b7c6561d0e0a96f24766135ed79107b603d6dd6e55142c0d")) + ( 65000, uint256S("0x000861f5d7970d5399733b4605074d47f877d6536f74ffae6f08e871ee29e6f2")) + ( 70000, uint256S("0x0002af1d487c567526c517b52996944dca344e139cddca77c2e72f746e73b263")) + ( 75000, uint256S("0x0d08129659be5f105e70c047769359eaf3475d61a726750859fdca3e1a2bf5cc")) + ( 80000, uint256S("0x0af5f3f1caae4f08c74a82689731d1ef8e55107c06f9a996e251b8ecb96989ad")) + ( 85000, uint256S("0x00000c8ee29086c5fb39eddad0619773b9ce936c77c13e5e5118a4998e939544")) + ( 90000, uint256S("0x06d3bb7f9ee5b55f67b2dc13c680699a2f736f43a44b4e4cfd41a58aa00f063f")) + ( 95000, uint256S("0x0670981b269879aae83a88f6f0c4db34763c93fd410d96435f2acb4e6580b976")) + ( 100000, uint256S("0x0f02eb1f3a4b89df9909fec81a4bd7d023e32e24e1f5262d9fc2cc36a715be6f")) + ( 105000, uint256S("0x018b97d7e6d259add24afe0e08fc125dc21d734e8831b68b430f5c3896deb4af")) + ( 110000, uint256S("0x09644ff52734e0e911a9ba7ecd03cf7995b25301840a9637891ef9af69f59c32")) + ( 115000, uint256S("0x0ee382b4729b8ceb918a92913f9c144a6a4f8a50bfc0f8b4aac5b12592caed7f")) + ( 120000, uint256S("0x082a7918a0dd9cb2df65f55acb8d0a4a535b3fa684d92c3ebcb24ed7019d975b")) + ( 125000, uint256S("0x00008f76c4484fd539c9d02fc69c40a50b6f9e00984d33890b85cc0324159e9e")) + ( 130000, uint256S("0x011b09e53acfe46f310e8c960a9c4f4f490cc7b2cd3791d7a6a80d6e8ac96b36")) + ( 135000, uint256S("0x01e0cd48358fa05646baa6f00e26717474d6049a537c8861b324d1f497dc3d4a")) + ( 140000, uint256S("0x0e6db36fd8a9d1b7baf359c8bd5c76635d0bcada973a75b5d2028ca3baea4961")) + ( 145000, uint256S("0x00010c40b57316ce6cde076807c9db956452a3c82cb09fe7d56c6bb1a7e24726")) + ( 150000, uint256S("0x0a817f15b9da636f453a7a01835cfc534ed1a55ce7f08c566471d167678bedce")) + ( 155000, uint256S("0x0528084fd00223bd9747635d7a4d8cc79f158795cad654efb78e4e4cc5f23d6a")) + ( 160000, uint256S("0x00003a09f26ae9fb7ebbfa3ef589b81ccd8909a82430f7414bc68d5a5a3316ab")) + ( 165000, uint256S("0x00004a0c6a29e7d1f22ea4e44d05e861fec5fcd8eebc5a61574c4ecf29dbb9be")) + ( 170000, uint256S("0x0cf9eac27badc0ae9a2b370dd7cc3fcb550f139349551e60978f394a2e1b262b")) + ( 175000, uint256S("0x0000137856b825d431da27ff4c3cf22f5482fa21952d45b0db0ec6774fb9b510")) + ( 180000, uint256S("0x000000b0afcccf98aa0afb6ac61050892bd9415857d66313d1f67fd1bbac312f")) + ( 185000, uint256S("0x00c2af8f88d84de080067f8ae1c25754e32e5516d20c11f85b9adae2d683687b")) + ( 190000, uint256S("0x00000033d85b3e7d19e02278ef300b8ab957d3dd3e58b4c81166ba0a58af5c3f")) + ( 195000, uint256S("0x000000964b6068be1dd4ee6893d183e86cba82a2744fb5439c463d0ba7e053b6")) + ( 200000, uint256S("0x000001763a9337328651ca57ac487cc0507087be5838fb74ca4165ff19f0e84f")) + ( 205000, uint256S("0x049fc6832e64a75ae898b32804e151e7561ea49082858c3d4af89a7de4b82f06")) + ( 210000, uint256S("0x0000000d9078b9c9604cc663eafafba8f3643bb3f3ddbb78fed4993236e1edb5")) + ( 215000, uint256S("0x00060089ecc21bcc62094e2f7f0448fe163415f6ef2f2aafe047757889ca82fe")) + ( 220000, uint256S("0x000082c78e6c2a13a9c23dd7a6faaf962fc133142b4a2d07725561f59c03bfa2")) + ( 225000, uint256S("0x00030026483167fe13505cf27049307ce42e0d9c5aa093aed10baa4f49edf4ca")) + ( 230000, uint256S("0x000183a3e17988060a35776b99c1f0b43393bbe7153b2718dfc57f428191de4e")) + ( 235000, uint256S("0x000184995f0ec024ed3783e322c8cfa5e68d9f0c77c3aaea301b22d311619156")) + ( 240000, uint256S("0x0000002cc7cf6d0a44ab57f9bd3bfa11a865bbf1cd87a2081095bc90981633a3")) + ( 245000, uint256S("0x004c5f19a88c8fe8a604006dbd2d44c94baef2a00876a17d8e2be2124003f979")) + ( 250000, uint256S("0x0dd54ef5f816c7fde9d2b1c8c1a26412b3c761cc5dd3901fa5c4cd1900892fba")) + ( 255000, uint256S("0x0b6da9e4f50c8bc7a92c539bc7474ffd6c29e0a8531f0dbbbc261fff1f990827")) + ( 260000, uint256S("0x0cac8b12bf7233ee5a68fcde9e251852b177833fefa2a9f39ec28474b0851cb9")) + ( 265000, uint256S("0x04feb5b4029f3b8b8eb3e6661a78eadd1a26b4af00ac59b5f05b261afcfd2818")) + ( 270000, uint256S("0x01bc5897bd20b8b61acf4989987ba85fbc37d9ebe848924aa8effcb08bf48fe0")) + ( 275000, uint256S("0x0416bc29eb5a12231826e546ba90fcd38aeef387ff77b45849cd418a9c1a6f12")) + ( 280000, uint256S("0x000007593e9880b171d46bce59aa0cec2a1b1f53d1fd7e8f71ccb2b9182374a4")) + ( 285000, uint256S("0x05a338b2d90cd79740221fe8635b7a834f2e486fcbb2464a4294f5a21231a5f5")) + ( 290000, uint256S("0x064ca3912cdcd833702d07a530e98bc5c6c1cd738a8825c7240b17cd68ca0cc4")) + ( 295000, uint256S("0x036b3bb318d743fd78db983a9aadd52869991d48913c4eebe2a074387d67cc5a")) + ( 300000, uint256S("0x000000fa5efd1998959926047727519ed7de06dcf9f2cd92a4f71e907e1312dc")) + ( 305000, uint256S("0x00003656231e83de2348755153ed175794696a113d7e8a15c01f90fdb7c2f287")) + ( 310000, uint256S("0x0cf6baf727eb931da0813ed8b032648c4766be79e146b0d40c643f9d8edf40f7")) + ( 315000, uint256S("0x082469974c152ebe69f1787f0d06aa5d9dd1dc69c880febde7eac2bc800146dd")) + ( 320000, uint256S("0x0000063df36b99bfb2516f55cb548a5baed1f2d8ae69c3559dc478c5c2eb32df")) + ( 325000, uint256S("0x0cb926b303a1514ba0a2f729af88ccb143517f396e9e0bde09b0736900698e0f")) + ( 330000, uint256S("0x000000be3d8bb6e31c3b534819aae7014cbbe9a44ab3e799dc1bfc724c6ab184")) + ( 335000, uint256S("0x0d0756608189fd5bbd8ec50e76180074e69e973439cc09df49134e4cb970ed4d")) + ( 340000, uint256S("0x0d814eacdb9c97003d703c0ff79b1b97b9ed8615fe12b1afaede946e5fdfe0a7")) + ( 345000, uint256S("0x000000c2910f510f1de325d300202da1a391f2719dd378173299151c3da94e85")) + ( 350000, uint256S("0x0000000228ef321323f81dae00c98d7960fc7486fb2d881007fee60d1e34653f")) + ( 355000, uint256S("0x03e6a55e382b478e0fab9c3584da3629fd9b977986a333a406b24b0d3559bf44")) + ( 360000, uint256S("0x0859c86dd718bcb5b58af06389197794e2beea6239653f2e6fa7b8a7433d29ea")) + ( 365000, uint256S("0x07896332665c707a8f55398a998e7878e8d2681ba79dd95c2859b1dafc9343d0")) + ( 370000, uint256S("0x040efd8c64cf5cf96ecf75468741a8880d1386eb5e349bef0a55116d4023944c")) + ( 375000, uint256S("0x053029e7599a09fe6c01203997d7ca738dd4c6d216a433695a0d514def1eccc0")) + ( 380000, uint256S("0x0cae44e7a421c389b88a5a204d3e39779e93aeacaab1b693741bf279fd0c8acd")) + ( 385000, uint256S("0x0b4032d2c799ba93644231ce57134dd24e13ec0dc267c1ed5912389691d2bd72")) + ( 390000, uint256S("0x0afd0f166f33a881ef289af7ea7010d58c4bbd560dee10b561c79e1b8dfd0593")) + ( 395000, uint256S("0x083774b88cf1b138d67c242d9b33c54f69d7e901b5e8144dc4a2303ab9927102")) + ( 400000, uint256S("0x036d294c5be96f4c0efb28e652eb3968231e87204a823991a85c5fdab3c43ae6")) + ( 405000, uint256S("0x0522e33bb2161fb1b33acef9a4a438fcf420dcae8a0b472e234d223d731c42b2")) + ( 410000, uint256S("0x0361d06aa807c66b87befea8119a485341d1118b694c3dbb4c3cf0b85ac69e9b")) + ( 415000, uint256S("0x072d5653d8673f64ef8b9c655f7b8021072070a072b799013ff6e96de99a59e6")) + ( 420000, uint256S("0x013b693d66955be69d4501cb1d307ca323a5c8473e25866ae7e700cdce0c654f")) + ( 425000, uint256S("0x0ef0c55af27c6971289a790dee2b2ec728fb9c6555ff9306c07f1083cf0fb4b5")) + ( 430000, uint256S("0x0ccbeeaba28291e0316a9cf54c005097c61dc67ba6f32283406d6c83b828da00")) + ( 435000, uint256S("0x020ed6b7fe1124400baba7feed463ba0c90e7e6903493fdc1a1a18c4a506055a")) + ( 440000, uint256S("0x055aaadca1908abeedc831a3f9115aa31284fc223d010590caf7b612960b61a4")) + ( 445000, uint256S("0x06d2327fa25ea7e2be742fc0e45fc4f9adb41811f21be0357f8543c5434df715")) + ( 450000, uint256S("0x0906ef1e8dc194f1f03bd4ce1ac8c6992fd721ef2c5ccbf4871ec8cdbb456c18")) + ( 455000, uint256S("0x0b8b92eec29eb20262dcf9916f0ca36d6abf0c39d321d3f480a5535cb978db71")) + ( 460000, uint256S("0x0cb04591f69a255b1127aaff3bbd59eaa21a5d9cca999de197516c251895c536")) + ( 465000, uint256S("0x029985ae78d8bb8fd170aeb3ab02ea76134ed0c19ae00211cc28a61fe5755b88")) + ( 470000, uint256S("0x01a2f4b56f37b223e75572862ad1ba956ec179332f8cd40590d7253563c86ba8")) + ( 475000, uint256S("0x0a34c6f9d4d9cb8c78c14b8041a7cc1874cfcbb22a34a5c068d1d6ff3ed9fdf0")) + ( 480000, uint256S("0x0ebab25030179996ae25969f34f6a297c7ffce1994f9b4186082a47032a9a7dc")) + ( 485000, uint256S("0x06a096e6bccf3b85537a30f95db6a414deacc0509bc84da264c2830df1a1d9b0")) + ( 490000, uint256S("0x0af828930ef13405cb536b88a3d1d4e0d84dc79ee260402c56bfa86e261c74ff")) + ( 495000, uint256S("0x09d44905bfd12849d3c2178b2ba882f8e9d6565b6e4d7a97c70a92bd6de7c5e6")) + ( 500000, uint256S("0x0bebdb417f7a51fe0c36fcf94e2ed29895a9a862eaa61601272866a7ecd6391b")) + ( 505000, uint256S("0x0c1609f4f3561baa1fc975877948af94d2107c88686a9821bc240016cc87d953")) + ( 510000, uint256S("0x0cf9a5a4997b871e615e5e398627e45fa15b3e6970ae22b47bdd11b0f5fa0fa7")) + ( 515000, uint256S("0x034171d4819e9961de13309743a32a179abede97d60ea64101dc04c97a1a0807")) + ( 520000, uint256S("0x0648fa44d5bbc2cc04a782e083c11df64ac06185f0f8e11a7416625ebb6409a6")) + ( 525000, uint256S("0x0000000ef17d63af3159e52cd351b6f000536ad88adc3a937bb747955fed58a2")) + ( 530000, uint256S("0x08e3af153995ba09e50086b64145cf4cd57db6b29f16f06f28d80d7f6121cfad")) + ( 535000, uint256S("0x02a0ffd00b51e2061b85de50a9223d9c84f4e357dc1046397bb9d7d4a827a3fb")) + ( 540000, uint256S("0x04bf07d026af29025c1ac2815e067f4a41d2872701ac9780eb3015d51cdcd854")) + ( 545000, uint256S("0x0a0d6d86635946792ad0dca57ed227a5360fc8b6d79e47132aac11e90a4963ce")) + ( 550000, uint256S("0x06df52fc5f9ba03ccc3a7673b01ab47990bd5c4947f6e1bc0ba14d21cd5bcccd")) + ( 555000, uint256S("0x0baf38eea8e08fcad3a9d760f27377e79c291b08e7fb4920cadd5cb7bab547f3")) + ( 560000, uint256S("0x00000004c34abbf1366adbae965b644c01debf15409acc715ff51cb221d92dd7")) + ( 565000, uint256S("0x067bae7119f083e0fa1820bc8e25dcfa7717e42aabaef18beefd87d974953dfb")) + ( 570000, uint256S("0x00000011a7ce7b628b7be17777d8dea2574d83f165e23c9e44aa705975820fd3")) + ( 575000, uint256S("0x0e1110a193a30d3f8d369017233a2486b11c748b3d033859a2eb7b37062d303e")) + ( 580000, uint256S("0x083cb58484aff80f48e3537e0451d49e544b3efa3da97274800c91e567d33a92")) + ( 585000, uint256S("0x0224cf835428d03472edf4f7b6fcc63b9d8d6f1d5a90ad8186bf123d541b4ea8")) + ( 590000, uint256S("0x0cfcf3b9517894e4df49db5faf8b74f3a9e01eb83c0cc5051c115d4424615dae")) + ( 595000, uint256S("0x0000000a45266983dd81e0df381a3b0455699b2f76d5b4d3f17b87d657a1b56d")) + ( 600000, uint256S("0x00000005080d5689c3b4466e551cd1986e5d2024a62a79b1335afe12c42779e4")) + ( 605000, uint256S("0x0000001c691da36848542299af859d4eb3fa408a0f425b1fbe6d622d2100623a")) + ( 610000, uint256S("0x040d8c7a0ac89e3ed8605a198583a795986aacbf18722a9897d7b925bcf757f6")) + ( 615000, uint256S("0x0449cf00fc36206389c14cbf1d762f8b96bb0440ccea5b46703e7c69b0e2bc42")) + ( 620000, uint256S("0x07227a41340c25ee1a7e9b60414259780202ffa990079fc91d8faeac9af03e60")) + ( 625000, uint256S("0x047c2472fe2afabb3d38decf24bba4ba712b60e7a1782f4afae3ede3f912f493")) + ( 630000, uint256S("0x0a7f1f04e66260cf972ab1374a9126b8abc1adaa3ab4669db5d4d4ddb9ad493d")) + ( 635000, uint256S("0x048df95165eb821dabf37ef28cf7f3be72e216e95377684253dab806985b50a4")) + ( 640000, uint256S("0x066b3c6a6a3c8dc58bef509a972c3e3ade14493b40e1b361ecbc928134e302be")) + ( 645000, uint256S("0x07d059888c9ade3bbe16d6b4d70ee9b8302d104b37a3c6cd61f81012aabd0e1e")) + ( 650000, uint256S("0x039a3cb760cc6e564974caf69e8ae621c14567f3a36e4991f77fd869294b1d52")) + ( 655000, uint256S("0x089350ee8d28b44837eb4b1fe77704953d5de2077f10c74a888d9d3ea1e13c2a")) + ( 660000, uint256S("0x000000023f8a582a61ae2f6fab6fe8197e79b7a68aaac67432421b09f1bdd4ba")) + ( 665000, uint256S("0x0b16edce865e7a0d662115774e0c0d3abbf9c69004155b693ddc933f051bfb26")) + ( 670000, uint256S("0x09070b109b089490bc372fd8358abae352d6db0e46ade6ed2200e4d4ff7aa6af")) + ( 675000, uint256S("0x08d9edeed3b6ac55991e9f32af0218ff8fa9dc808078623f4c831eb09d4f186b")) + ( 680000, uint256S("0x00000003eb2b30bfac929d3496acecab19625ac9f854a86aaf9678bea99e1cc1")) + ( 681777, uint256S("0x0000243296b9b26c040f471fdd9398ef72e57062cf05c19b9ba2fefac8165306")), + (int64_t)1516924927, // * UNIX timestamp of last checkpoint block + (int64_t)1253783, // * total number of transactions between genesis and last checkpoint + // (the tx=... number in the SetBestChain debug.log lines) + (double)2777 // * estimated number of transactions per day after checkpoint + // total number of tx / (checkpoint block height / (24 * 24)) + }; + } + + mainParams.SetCheckpointData(checkpointData); + ASSETCHAIN_INIT = 1; return(0); } diff --git a/src/chainparams.h b/src/chainparams.h index 8499d7d17..00d2c255f 100644 --- a/src/chainparams.h +++ b/src/chainparams.h @@ -87,15 +87,18 @@ public: void SetRegTestCoinbaseMustBeProtected() { consensus.fCoinbaseMustBeProtected = true; } void SetDefaultPort(uint16_t port) { nDefaultPort = port; } + void SetCheckpointData(Checkpoints::CCheckpointData checkpointData); + //void setnonce(uint32_t nonce) { memcpy(&genesis.nNonce,&nonce,sizeof(nonce)); } //void settimestamp(uint32_t timestamp) { genesis.nTime = timestamp; } //void setgenesis(CBlock &block) { genesis = block; } //void recalc_genesis(uint32_t nonce) { genesis = CreateGenesisBlock(ASSETCHAINS_TIMESTAMP, nonce, GENESIS_NBITS, 1, COIN); }; int nDefaultPort = 0; CMessageHeader::MessageStartChars pchMessageStart; // jl777 moved + Consensus::Params consensus; + protected: CChainParams() {} - Consensus::Params consensus; //! Raw pub key bytes for the broadcast alert signing key. std::vector vAlertPubKey; From 8a52db13e1de17bf109c735716f84f4e37f3c5c2 Mon Sep 17 00:00:00 2001 From: Mihail Fedorov Date: Sat, 27 Jan 2018 17:26:42 +0300 Subject: [PATCH 150/188] pax --- src/fiat-cli | 1 + src/fiat/aud | 2 -- src/fiat/bgn | 2 -- src/fiat/brl | 2 -- src/fiat/cad | 2 -- src/fiat/chf | 2 -- src/fiat/cny | 2 -- src/fiat/czk | 2 -- src/fiat/dkk | 2 -- src/fiat/eur | 2 -- src/fiat/gbp | 2 -- src/fiat/hkd | 2 -- src/fiat/hrk | 2 -- src/fiat/huf | 2 -- src/fiat/idr | 2 -- src/fiat/ils | 2 -- src/fiat/inr | 2 -- src/fiat/jpy | 2 -- src/fiat/krw | 2 -- src/fiat/mvp | 2 -- src/fiat/mxn | 2 -- src/fiat/myr | 2 -- src/fiat/nok | 2 -- src/fiat/nzd | 2 -- src/fiat/php | 2 -- src/fiat/pln | 2 -- src/fiat/ron | 2 -- src/fiat/rub | 2 -- src/fiat/sek | 2 -- src/fiat/sgd | 2 -- src/fiat/shark | 2 -- src/fiat/thb | 2 -- src/fiat/try | 2 -- src/fiat/usd | 2 -- src/fiat/zar | 2 -- 35 files changed, 1 insertion(+), 68 deletions(-) delete mode 100755 src/fiat/aud delete mode 100755 src/fiat/bgn delete mode 100755 src/fiat/brl delete mode 100755 src/fiat/cad delete mode 100755 src/fiat/chf delete mode 100755 src/fiat/cny delete mode 100755 src/fiat/czk delete mode 100755 src/fiat/dkk delete mode 100755 src/fiat/eur delete mode 100755 src/fiat/gbp delete mode 100755 src/fiat/hkd delete mode 100755 src/fiat/hrk delete mode 100755 src/fiat/huf delete mode 100755 src/fiat/idr delete mode 100755 src/fiat/ils delete mode 100755 src/fiat/inr delete mode 100755 src/fiat/jpy delete mode 100755 src/fiat/krw delete mode 100755 src/fiat/mvp delete mode 100755 src/fiat/mxn delete mode 100755 src/fiat/myr delete mode 100755 src/fiat/nok delete mode 100755 src/fiat/nzd delete mode 100755 src/fiat/php delete mode 100755 src/fiat/pln delete mode 100755 src/fiat/ron delete mode 100755 src/fiat/rub delete mode 100755 src/fiat/sek delete mode 100755 src/fiat/sgd delete mode 100755 src/fiat/shark delete mode 100755 src/fiat/thb delete mode 100755 src/fiat/try delete mode 100755 src/fiat/usd delete mode 100755 src/fiat/zar diff --git a/src/fiat-cli b/src/fiat-cli index 14d0f0b18..81ed6b56a 100755 --- a/src/fiat-cli +++ b/src/fiat-cli @@ -56,3 +56,4 @@ echo etomic; fiat/etomic $1 $2 $3 $4 echo btch; fiat/btch $1 $2 $3 $4 echo pizza; fiat/pizza $1 $2 $3 $4 echo beer; fiat/beer $1 $2 $3 $4 +echo vote; fiat/vote $1 $2 $3 $4 diff --git a/src/fiat/aud b/src/fiat/aud deleted file mode 100755 index 6fa6e2cbb..000000000 --- a/src/fiat/aud +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -./komodo-cli -ac_name=AUD $1 $2 $3 $4 $5 $6 diff --git a/src/fiat/bgn b/src/fiat/bgn deleted file mode 100755 index fdc0f5763..000000000 --- a/src/fiat/bgn +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -./komodo-cli -ac_name=BGN $1 $2 $3 $4 $5 $6 diff --git a/src/fiat/brl b/src/fiat/brl deleted file mode 100755 index b36365d99..000000000 --- a/src/fiat/brl +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -./komodo-cli -ac_name=BRL $1 $2 $3 $4 $5 $6 diff --git a/src/fiat/cad b/src/fiat/cad deleted file mode 100755 index 509150867..000000000 --- a/src/fiat/cad +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -./komodo-cli -ac_name=CAD $1 $2 $3 $4 $5 $6 diff --git a/src/fiat/chf b/src/fiat/chf deleted file mode 100755 index fbe57148c..000000000 --- a/src/fiat/chf +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -./komodo-cli -ac_name=CHF $1 $2 $3 $4 $5 $6 diff --git a/src/fiat/cny b/src/fiat/cny deleted file mode 100755 index aa4e2ca25..000000000 --- a/src/fiat/cny +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -./komodo-cli -ac_name=CNY $1 $2 $3 $4 $5 $6 diff --git a/src/fiat/czk b/src/fiat/czk deleted file mode 100755 index c0c1072d2..000000000 --- a/src/fiat/czk +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -./komodo-cli -ac_name=CZK $1 $2 $3 $4 $5 $6 diff --git a/src/fiat/dkk b/src/fiat/dkk deleted file mode 100755 index aaa6108e0..000000000 --- a/src/fiat/dkk +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -./komodo-cli -ac_name=DKK $1 $2 $3 $4 $5 $6 diff --git a/src/fiat/eur b/src/fiat/eur deleted file mode 100755 index 67de01b7d..000000000 --- a/src/fiat/eur +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -./komodo-cli -ac_name=EUR $1 $2 $3 $4 $5 $6 diff --git a/src/fiat/gbp b/src/fiat/gbp deleted file mode 100755 index eb4528f95..000000000 --- a/src/fiat/gbp +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -./komodo-cli -ac_name=GBP $1 $2 $3 $4 $5 $6 diff --git a/src/fiat/hkd b/src/fiat/hkd deleted file mode 100755 index 006ba7fe6..000000000 --- a/src/fiat/hkd +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -./komodo-cli -ac_name=HKD $1 $2 $3 $4 $5 $6 diff --git a/src/fiat/hrk b/src/fiat/hrk deleted file mode 100755 index 393b21fe3..000000000 --- a/src/fiat/hrk +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -./komodo-cli -ac_name=HRK $1 $2 $3 $4 $5 $6 diff --git a/src/fiat/huf b/src/fiat/huf deleted file mode 100755 index 55a4f7c50..000000000 --- a/src/fiat/huf +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -./komodo-cli -ac_name=HUF $1 $2 $3 $4 $5 $6 diff --git a/src/fiat/idr b/src/fiat/idr deleted file mode 100755 index 62ce7968d..000000000 --- a/src/fiat/idr +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -./komodo-cli -ac_name=IDR $1 $2 $3 $4 $5 $6 diff --git a/src/fiat/ils b/src/fiat/ils deleted file mode 100755 index de1e552b8..000000000 --- a/src/fiat/ils +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -./komodo-cli -ac_name=ILS $1 $2 $3 $4 $5 $6 diff --git a/src/fiat/inr b/src/fiat/inr deleted file mode 100755 index 10ffc9d51..000000000 --- a/src/fiat/inr +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -./komodo-cli -ac_name=INR $1 $2 $3 $4 $5 $6 diff --git a/src/fiat/jpy b/src/fiat/jpy deleted file mode 100755 index 5b8fd3768..000000000 --- a/src/fiat/jpy +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -./komodo-cli -ac_name=JPY $1 $2 $3 $4 $5 $6 diff --git a/src/fiat/krw b/src/fiat/krw deleted file mode 100755 index 7b895b1f4..000000000 --- a/src/fiat/krw +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -./komodo-cli -ac_name=KRW $1 $2 $3 $4 $5 $6 diff --git a/src/fiat/mvp b/src/fiat/mvp deleted file mode 100755 index 998d700a3..000000000 --- a/src/fiat/mvp +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -./komodo-cli -ac_name=MVP $1 $2 $3 $4 $5 $6 diff --git a/src/fiat/mxn b/src/fiat/mxn deleted file mode 100755 index d5d8d97fb..000000000 --- a/src/fiat/mxn +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -./komodo-cli -ac_name=MXN $1 $2 $3 $4 $5 $6 diff --git a/src/fiat/myr b/src/fiat/myr deleted file mode 100755 index 8c700a53c..000000000 --- a/src/fiat/myr +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -./komodo-cli -ac_name=MYR $1 $2 $3 $4 $5 $6 diff --git a/src/fiat/nok b/src/fiat/nok deleted file mode 100755 index e0e35b444..000000000 --- a/src/fiat/nok +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -./komodo-cli -ac_name=NOK $1 $2 $3 $4 $5 $6 diff --git a/src/fiat/nzd b/src/fiat/nzd deleted file mode 100755 index c9610b218..000000000 --- a/src/fiat/nzd +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -./komodo-cli -ac_name=NZD $1 $2 $3 $4 $5 $6 diff --git a/src/fiat/php b/src/fiat/php deleted file mode 100755 index c22e73293..000000000 --- a/src/fiat/php +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -./komodo-cli -ac_name=PHP $1 $2 $3 $4 $5 $6 diff --git a/src/fiat/pln b/src/fiat/pln deleted file mode 100755 index 6dfb0debb..000000000 --- a/src/fiat/pln +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -./komodo-cli -ac_name=PLN $1 $2 $3 $4 $5 $6 diff --git a/src/fiat/ron b/src/fiat/ron deleted file mode 100755 index 0b2a6effd..000000000 --- a/src/fiat/ron +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -./komodo-cli -ac_name=RON $1 $2 $3 $4 $5 $6 diff --git a/src/fiat/rub b/src/fiat/rub deleted file mode 100755 index 8d1575578..000000000 --- a/src/fiat/rub +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -./komodo-cli -ac_name=RUB $1 $2 $3 $4 $5 $6 diff --git a/src/fiat/sek b/src/fiat/sek deleted file mode 100755 index 25a14d414..000000000 --- a/src/fiat/sek +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -./komodo-cli -ac_name=SEK $1 $2 $3 $4 $5 $6 diff --git a/src/fiat/sgd b/src/fiat/sgd deleted file mode 100755 index 89a1bc5ae..000000000 --- a/src/fiat/sgd +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -./komodo-cli -ac_name=SGD $1 $2 $3 $4 $5 $6 diff --git a/src/fiat/shark b/src/fiat/shark deleted file mode 100755 index 4bda53889..000000000 --- a/src/fiat/shark +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -./komodo-cli -ac_name=SHARK $1 $2 $3 $4 $5 $6 diff --git a/src/fiat/thb b/src/fiat/thb deleted file mode 100755 index ed72913c1..000000000 --- a/src/fiat/thb +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -./komodo-cli -ac_name=THB $1 $2 $3 $4 $5 $6 diff --git a/src/fiat/try b/src/fiat/try deleted file mode 100755 index dcfa574a6..000000000 --- a/src/fiat/try +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -./komodo-cli -ac_name=TRY $1 $2 $3 $4 $5 $6 diff --git a/src/fiat/usd b/src/fiat/usd deleted file mode 100755 index 81b9e16c6..000000000 --- a/src/fiat/usd +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -./komodo-cli -ac_name=USD $1 $2 $3 $4 $5 $6 diff --git a/src/fiat/zar b/src/fiat/zar deleted file mode 100755 index a3dd891c0..000000000 --- a/src/fiat/zar +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -./komodo-cli -ac_name=ZAR $1 $2 $3 $4 $5 $6 From 0b7ef28990b387e42e2749cce1a68c5261819e1a Mon Sep 17 00:00:00 2001 From: ca333 Date: Sun, 28 Jan 2018 03:02:05 +0100 Subject: [PATCH 151/188] add native btch bins --- src/komodo_utils.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index ef64ad75c..1d6b7154a 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1494,12 +1494,12 @@ int32_t komodo_whoami(char *pubkeystr,int32_t height) char *argv0suffix[] = { - (char *)"mnzd", (char *)"mnz-cli", (char *)"mnzd.exe", (char *)"mnz-cli.exe" + (char *)"mnzd", (char *)"mnz-cli", (char *)"mnzd.exe", (char *)"mnz-cli.exe", (char *)"btchd", (char *)"btch-cli", (char *)"btchd.exe", (char *)"btch-cli.exe" }; char *argv0names[] = { - (char *)"MNZ", (char *)"MNZ", (char *)"MNZ", (char *)"MNZ" + (char *)"MNZ", (char *)"MNZ", (char *)"MNZ", (char *)"MNZ", (char *)"BTCH", (char *)"BTCH", (char *)"BTCH", (char *)"BTCH" }; void komodo_args(char *argv0) From f6d8f2cce9755fc9d44f3788293472b5a3cd8af1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 28 Jan 2018 19:58:35 +0400 Subject: [PATCH 152/188] rpcworkqueue=64 --- 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 1d6b7154a..2bc6ea1e7 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1364,7 +1364,7 @@ void komodo_configfile(char *symbol,uint16_t port) { if ( (fp= fopen(fname,"wb")) != 0 ) { - fprintf(fp,"rpcuser=user%u\nrpcpassword=pass%s\nrpcport=%u\nserver=1\ntxindex=1\n\n",crc,password,port); + fprintf(fp,"rpcuser=user%u\nrpcpassword=pass%s\nrpcport=%u\nserver=1\ntxindex=1\nrpcworkqueue=64\n",crc,password,port); fclose(fp); printf("Created (%s)\n",fname); } else printf("Couldnt create (%s)\n",fname); From 0a8ac8b037945db889fc69e9d0e0965be2b45bcb Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 29 Jan 2018 16:12:00 +0400 Subject: [PATCH 153/188] VOTE chain --- src/assetchains.old | 131 ++++++++++++++++++++++---------------------- src/fiat/vote | 2 + 2 files changed, 67 insertions(+), 66 deletions(-) create mode 100755 src/fiat/vote diff --git a/src/assetchains.old b/src/assetchains.old index 9e14165fe..7b7c3ee74 100755 --- a/src/assetchains.old +++ b/src/assetchains.old @@ -12,11 +12,9 @@ echo $pubkey ./komodod -pubkey=$pubkey -ac_name=BET -ac_supply=999999 -addnode=78.47.196.146 $1 & ./komodod -pubkey=$pubkey -ac_name=CRYPTO -ac_supply=999999 -addnode=78.47.196.146 $1 & ./komodod -pubkey=$pubkey -ac_name=HODL -ac_supply=9999999 -addnode=78.47.196.146 $1 & -#./komodod -pubkey=$pubkey -ac_name=SHARK -ac_supply=1401 -addnode=78.47.196.146 $1 & ./komodod -pubkey=$pubkey -ac_name=MSHARK -ac_supply=1400000 -addnode=78.47.196.146 $1 & ./komodod -pubkey=$pubkey -ac_name=BOTS -ac_supply=999999 -addnode=78.47.196.146 $1 & ./komodod -pubkey=$pubkey -ac_name=MGW -ac_supply=999999 -addnode=78.47.196.146 $1 & -#./komodod -pubkey=$pubkey -ac_name=MVP -ac_supply=1000000 -addnode=78.47.196.146 $1 & ./komodod -pubkey=$pubkey -ac_name=COQUI -ac_supply=72000000 -addnode=78.47.196.146 $1 & ./komodod -pubkey=$pubkey -ac_name=WLC -ac_supply=210000000 -addnode=148.251.190.89 $1 & ./komodod -pubkey=$pubkey -ac_name=KV -ac_supply=1000000 -addnode=78.47.196.146 $1 & @@ -26,69 +24,70 @@ echo $pubkey ./komodod -pubkey=$pubkey -ac_name=AXO -ac_supply=200000000 -addnode=78.47.196.146 & ./komodod -pubkey=$pubkey -ac_name=ETOMIC -ac_supply=100000000 -addnode=78.47.196.146 & ./komodod -pubkey=$pubkey -ac_name=BTCH -ac_supply=20998641 -addnode=78.47.196.146 & +./komodod -pubkey=$pubkey -ac_name=VOTE -ac_supply=49999999999 -addnode=78.47.196.146 & -sleep $delay +#sleep $delay -./komodod -pubkey=$pubkey -ac_name=USD -addnode=78.47.196.146 $1 & -sleep $delay -./komodod -pubkey=$pubkey -ac_name=EUR -addnode=78.47.196.146 $1 & -sleep $delay -./komodod -pubkey=$pubkey -ac_name=JPY -addnode=78.47.196.146 $1 & -sleep $delay -./komodod -pubkey=$pubkey -ac_name=GBP -addnode=78.47.196.146 $1 & -sleep $delay -./komodod -pubkey=$pubkey -ac_name=AUD -addnode=78.47.196.146 $1 & -sleep $delay -./komodod -pubkey=$pubkey -ac_name=CAD -addnode=78.47.196.146 $1 & -sleep $delay -./komodod -pubkey=$pubkey -ac_name=CHF -addnode=78.47.196.146 $1 & -sleep $delay -./komodod -pubkey=$pubkey -ac_name=NZD -addnode=78.47.196.146 $1 & -sleep $delay -./komodod -pubkey=$pubkey -ac_name=CNY -addnode=78.47.196.146 $1 & -sleep $delay -./komodod -pubkey=$pubkey -ac_name=RUB -addnode=78.47.196.146 $1 & -sleep $delay -./komodod -pubkey=$pubkey -ac_name=MXN -addnode=78.47.196.146 $1 & -sleep $delay -./komodod -pubkey=$pubkey -ac_name=BRL -addnode=78.47.196.146 $1 & -sleep $delay -./komodod -pubkey=$pubkey -ac_name=INR -addnode=78.47.196.146 $1 & -sleep $delay -./komodod -pubkey=$pubkey -ac_name=HKD -addnode=78.47.196.146 $1 & -sleep $delay -./komodod -pubkey=$pubkey -ac_name=TRY -addnode=78.47.196.146 $1 & -sleep $delay -./komodod -pubkey=$pubkey -ac_name=ZAR -addnode=78.47.196.146 $1 & -sleep $delay -./komodod -pubkey=$pubkey -ac_name=PLN -addnode=78.47.196.146 $1 & -sleep $delay -./komodod -pubkey=$pubkey -ac_name=NOK -addnode=78.47.196.146 $1 & -sleep $delay -./komodod -pubkey=$pubkey -ac_name=SEK -addnode=78.47.196.146 $1 & -sleep $delay -./komodod -pubkey=$pubkey -ac_name=DKK -addnode=78.47.196.146 $1 & -sleep $delay -./komodod -pubkey=$pubkey -ac_name=CZK -addnode=78.47.196.146 $1 & -sleep $delay -./komodod -pubkey=$pubkey -ac_name=HUF -addnode=78.47.196.146 $1 & -sleep $delay -./komodod -pubkey=$pubkey -ac_name=ILS -addnode=78.47.196.146 $1 & -sleep $delay -./komodod -pubkey=$pubkey -ac_name=KRW -addnode=78.47.196.146 $1 & -sleep $delay -./komodod -pubkey=$pubkey -ac_name=MYR -addnode=78.47.196.146 $1 & -sleep $delay -./komodod -pubkey=$pubkey -ac_name=PHP -addnode=78.47.196.146 $1 & -sleep $delay -./komodod -pubkey=$pubkey -ac_name=RON -addnode=78.47.196.146 $1 & -sleep $delay -./komodod -pubkey=$pubkey -ac_name=SGD -addnode=78.47.196.146 $1 & -sleep $delay -./komodod -pubkey=$pubkey -ac_name=THB -addnode=78.47.196.146 $1 & -sleep $delay -./komodod -pubkey=$pubkey -ac_name=BGN -addnode=78.47.196.146 $1 & -sleep $delay -./komodod -pubkey=$pubkey -ac_name=IDR -addnode=78.47.196.146 $1 & -sleep $delay -./komodod -pubkey=$pubkey -ac_name=HRK -addnode=78.47.196.146 $1 & +#./komodod -pubkey=$pubkey -ac_name=USD -addnode=78.47.196.146 $1 & +#sleep $delay +#./komodod -pubkey=$pubkey -ac_name=EUR -addnode=78.47.196.146 $1 & +#sleep $delay +#./komodod -pubkey=$pubkey -ac_name=JPY -addnode=78.47.196.146 $1 & +#sleep $delay +#./komodod -pubkey=$pubkey -ac_name=GBP -addnode=78.47.196.146 $1 & +#sleep $delay +#./komodod -pubkey=$pubkey -ac_name=AUD -addnode=78.47.196.146 $1 & +#sleep $delay +#./komodod -pubkey=$pubkey -ac_name=CAD -addnode=78.47.196.146 $1 & +#sleep $delay +#./komodod -pubkey=$pubkey -ac_name=CHF -addnode=78.47.196.146 $1 & +#sleep $delay +#./komodod -pubkey=$pubkey -ac_name=NZD -addnode=78.47.196.146 $1 & +#sleep $delay +#./komodod -pubkey=$pubkey -ac_name=CNY -addnode=78.47.196.146 $1 & +#sleep $delay +#./komodod -pubkey=$pubkey -ac_name=RUB -addnode=78.47.196.146 $1 & +#sleep $delay +#./komodod -pubkey=$pubkey -ac_name=MXN -addnode=78.47.196.146 $1 & +#sleep $delay +#./komodod -pubkey=$pubkey -ac_name=BRL -addnode=78.47.196.146 $1 & +#sleep $delay +#./komodod -pubkey=$pubkey -ac_name=INR -addnode=78.47.196.146 $1 & +#sleep $delay +#./komodod -pubkey=$pubkey -ac_name=HKD -addnode=78.47.196.146 $1 & +#sleep $delay +#./komodod -pubkey=$pubkey -ac_name=TRY -addnode=78.47.196.146 $1 & +#sleep $delay +#./komodod -pubkey=$pubkey -ac_name=ZAR -addnode=78.47.196.146 $1 & +#sleep $delay +#./komodod -pubkey=$pubkey -ac_name=PLN -addnode=78.47.196.146 $1 & +#sleep $delay +#./komodod -pubkey=$pubkey -ac_name=NOK -addnode=78.47.196.146 $1 & +#sleep $delay +#./komodod -pubkey=$pubkey -ac_name=SEK -addnode=78.47.196.146 $1 & +#sleep $delay +#./komodod -pubkey=$pubkey -ac_name=DKK -addnode=78.47.196.146 $1 & +#sleep $delay +#./komodod -pubkey=$pubkey -ac_name=CZK -addnode=78.47.196.146 $1 & +#sleep $delay +#./komodod -pubkey=$pubkey -ac_name=HUF -addnode=78.47.196.146 $1 & +#sleep $delay +#./komodod -pubkey=$pubkey -ac_name=ILS -addnode=78.47.196.146 $1 & +#sleep $delay +#./komodod -pubkey=$pubkey -ac_name=KRW -addnode=78.47.196.146 $1 & +#sleep $delay +#./komodod -pubkey=$pubkey -ac_name=MYR -addnode=78.47.196.146 $1 & +#sleep $delay +#./komodod -pubkey=$pubkey -ac_name=PHP -addnode=78.47.196.146 $1 & +#sleep $delay +#./komodod -pubkey=$pubkey -ac_name=RON -addnode=78.47.196.146 $1 & +#sleep $delay +#./komodod -pubkey=$pubkey -ac_name=SGD -addnode=78.47.196.146 $1 & +#sleep $delay +#./komodod -pubkey=$pubkey -ac_name=THB -addnode=78.47.196.146 $1 & +#sleep $delay +#./komodod -pubkey=$pubkey -ac_name=BGN -addnode=78.47.196.146 $1 & +#sleep $delay +#./komodod -pubkey=$pubkey -ac_name=IDR -addnode=78.47.196.146 $1 & +#sleep $delay +#./komodod -pubkey=$pubkey -ac_name=HRK -addnode=78.47.196.146 $1 & diff --git a/src/fiat/vote b/src/fiat/vote new file mode 100755 index 000000000..67f47953e --- /dev/null +++ b/src/fiat/vote @@ -0,0 +1,2 @@ +#!/bin/bash +./komodo-cli -ac_name=VOTE $1 $2 $3 $4 $5 $6 From 6fdd9555a38304f99a91b97cf346d9d5ff45a86b Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 29 Jan 2018 16:22:47 +0400 Subject: [PATCH 154/188] PIZZA and BEER, why not --- src/assetchains.old | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/assetchains.old b/src/assetchains.old index 7b7c3ee74..20f47d006 100755 --- a/src/assetchains.old +++ b/src/assetchains.old @@ -25,7 +25,8 @@ echo $pubkey ./komodod -pubkey=$pubkey -ac_name=ETOMIC -ac_supply=100000000 -addnode=78.47.196.146 & ./komodod -pubkey=$pubkey -ac_name=BTCH -ac_supply=20998641 -addnode=78.47.196.146 & ./komodod -pubkey=$pubkey -ac_name=VOTE -ac_supply=49999999999 -addnode=78.47.196.146 & - +./komodod -pubkey=$pubkey -ac_name=BEER -ac_supply=100000000 -addnode=24.54.206.138 & +./komodod -pubkey=$pubkey -ac_name=PIZZA -ac_supply=100000000 -addnode=24.54.206.138 & #sleep $delay #./komodod -pubkey=$pubkey -ac_name=USD -addnode=78.47.196.146 $1 & From 3e71f5857f508ff15e31259562f72831b43e26de Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 30 Jan 2018 17:22:45 +0400 Subject: [PATCH 155/188] Disable KV functions for KMD --- src/komodo_kv.h | 2 ++ src/wallet/rpcwallet.cpp | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/komodo_kv.h b/src/komodo_kv.h index 0d86fadd0..9aca2d387 100644 --- a/src/komodo_kv.h +++ b/src/komodo_kv.h @@ -101,6 +101,8 @@ void komodo_kvupdate(uint8_t *opretbuf,int32_t opretlen,uint64_t value) { static uint256 zeroes; uint32_t flags; uint256 pubkey,refpubkey,sig; int32_t i,refvaluesize,hassig,coresize,haspubkey,height,kvheight; uint16_t keylen,valuesize,newflag = 0; uint8_t *key,*valueptr,keyvalue[IGUANA_MAXSCRIPTSIZE]; struct komodo_kv *ptr; char *transferpubstr,*tstr; uint64_t fee; + if ( ASSETCHAINS_SYMBOL[0] == 0 ) // disable KV for KMD + return; iguana_rwnum(0,&opretbuf[1],sizeof(keylen),&keylen); iguana_rwnum(0,&opretbuf[3],sizeof(valuesize),&valuesize); iguana_rwnum(0,&opretbuf[5],sizeof(height),&height); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index dbc3aab84..d4fab38cc 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -503,6 +503,8 @@ UniValue kvupdate(const UniValue& params, bool fHelp) throw runtime_error("kvupdate key value flags/passphrase"); if (!EnsureWalletIsAvailable(fHelp)) return 0; + if ( ASSETCHAINS_SYMBOL[0] == 0 ) + return(0); haveprivkey = 0; memset(&sig,0,sizeof(sig)); memset(&privkey,0,sizeof(privkey)); From b92d9db11b8e3315081ed9268cd2b8f4911e6204 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 2 Feb 2018 12:53:09 +0200 Subject: [PATCH 156/188] Fix typo --- 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 d4fab38cc..3a891affa 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -618,7 +618,7 @@ UniValue paxdeposit(const UniValue& params, bool fHelp) bool fSubtractFeeFromAmount = false; if ( KOMODO_PAX == 0 ) { - throw runtime_error("paxdeposit dispabled without -pax"); + throw runtime_error("paxdeposit disabled without -pax"); } if ( komodo_is_issuer() != 0 ) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "paxdeposit only from KMD"); From c83c59f97e672206b7372e51221617c5ec8984d7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 2 Feb 2018 13:19:15 +0200 Subject: [PATCH 157/188] Fix sendmany --- src/wallet/rpcwallet.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 3a891affa..d87a6a998 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -1265,7 +1265,8 @@ UniValue sendmany(const UniValue& params, bool fHelp) EnsureWalletIsUnlocked(); // Check funds - CAmount nBalance = GetAccountBalance(strAccount, nMinDepth, ISMINE_SPENDABLE); + CAmount nBalance = ValueFromAmount(pwalletMain->GetBalance()); + //CAmount nBalance = GetAccountBalance(strAccount, nMinDepth, ISMINE_SPENDABLE); if (totalAmount > nBalance) throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Account has insufficient funds"); From 170d7b7ac9896a01b0a4e372c470e72397d3f385 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 2 Feb 2018 13:30:47 +0200 Subject: [PATCH 158/188] 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 d87a6a998..930f61c09 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -1265,7 +1265,7 @@ UniValue sendmany(const UniValue& params, bool fHelp) EnsureWalletIsUnlocked(); // Check funds - CAmount nBalance = ValueFromAmount(pwalletMain->GetBalance()); + CAmount nBalance = pwalletMain->GetBalance(); //CAmount nBalance = GetAccountBalance(strAccount, nMinDepth, ISMINE_SPENDABLE); if (totalAmount > nBalance) throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Account has insufficient funds"); From d1f29a9d00d420bdc62398bf5b22137d1c0b2e7a Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 2 Feb 2018 13:36:12 +0200 Subject: [PATCH 159/188] Test --- src/wallet/wallet.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 341b2bf5a..9dc96f10c 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2733,10 +2733,10 @@ bool CWallet::CreateTransaction(const vector& vecSend, CWalletTx& wt //a chance at a free transaction. //But mempool inputs might still be in the mempool, so their age stays 0 //fprintf(stderr,"nCredit %.8f interest %.8f\n",(double)nCredit/COIN,(double)pcoin.first->vout[pcoin.second].interest/COIN); - if ( KOMODO_EXCHANGEWALLET == 0 ) + if ( KOMODO_EXCHANGEWALLET == 0 && ASSETCHAINS_SYMBOL[0] == 0 ) { interest2 += pcoin.first->vout[pcoin.second].interest; - fprintf(stderr,"%.8f ",(double)pcoin.first->vout[pcoin.second].interest/COIN); + //fprintf(stderr,"%.8f ",(double)pcoin.first->vout[pcoin.second].interest/COIN); } int age = pcoin.first->GetDepthInMainChain(); if (age != 0) From 9d83c1ad0f8af3fd6d99a728c0e1b67f3c379ef4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 2 Feb 2018 13:44:30 +0200 Subject: [PATCH 160/188] 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 930f61c09..407436a2f 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -1241,8 +1241,8 @@ UniValue sendmany(const UniValue& params, bool fHelp) if (!address.IsValid()) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, string("Invalid Komodo address: ")+name_); - if (setAddress.count(address)) - throw JSONRPCError(RPC_INVALID_PARAMETER, string("Invalid parameter, duplicated address: ")+name_); + //if (setAddress.count(address)) + // throw JSONRPCError(RPC_INVALID_PARAMETER, string("Invalid parameter, duplicated address: ")+name_); setAddress.insert(address); CScript scriptPubKey = GetScriptForDestination(address.Get()); From 2d8bd77a057948f21828d9cf8b0422f19ebc67d3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 2 Feb 2018 13:44:57 +0200 Subject: [PATCH 161/188] Test --- src/policy/fees.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/policy/fees.cpp b/src/policy/fees.cpp index d4965a9b5..dd534d803 100644 --- a/src/policy/fees.cpp +++ b/src/policy/fees.cpp @@ -61,7 +61,7 @@ unsigned int TxConfirmStats::FindBucketIndex(double val) if ( it != bucketMap.end() ) { static uint32_t counter; - if ( counter++ < 10 ) + if ( counter++ < 1 ) fprintf(stderr,"%s FindBucketIndex violation: from val %f\n",ASSETCHAINS_SYMBOL,val); } return it->second; From 8b6a0cb8beef047c7f1ffbd957202885b50ead4a Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 2 Feb 2018 20:59:09 +0200 Subject: [PATCH 162/188] Stupid accounts --- 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 407436a2f..ccf4fc34a 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -105,8 +105,8 @@ void WalletTxToJSON(const CWalletTx& wtx, UniValue& entry) string AccountFromValue(const UniValue& value) { string strAccount = value.get_str(); - if (strAccount != "") - throw JSONRPCError(RPC_WALLET_ACCOUNTS_UNSUPPORTED, "Accounts are unsupported"); + //if (strAccount != "") + // throw JSONRPCError(RPC_WALLET_ACCOUNTS_UNSUPPORTED, "Accounts are unsupported"); return strAccount; } From de615b43f72fcc938b8dad9ff66793541821a048 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 10 Feb 2018 15:12:32 +0200 Subject: [PATCH 163/188] Disable price feed --- src/miner.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 5c12d0af6..d7fc3a94d 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -398,7 +398,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) txNew.vin[0].scriptSig = CScript() << nHeight << OP_0; if ( ASSETCHAINS_SYMBOL[0] == 0 ) { - int32_t i,opretlen; uint8_t opret[256],*ptr; + /*int32_t i,opretlen; uint8_t opret[256],*ptr; if ( (nHeight % 60) == 0 || komodo_gateway_deposits(&txNew,(char *)"KMD",1) == 0 ) { if ( (opretlen= komodo_pax_opreturn((int32_t)nHeight,opret,sizeof(opret))) > 0 ) // have pricefeed @@ -411,7 +411,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) txNew.vout[1].nValue = 0; //fprintf(stderr,"opretlen.%d\n",opretlen); } //else printf("null opretlen for prices\n"); - } + }*/ } else if ( komodo_is_issuer() != 0 ) { From 8f8b5a2ac649feebdbfd3d00f3806f1aa0d5cb5a Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 10 Feb 2018 21:42:04 +0200 Subject: [PATCH 164/188] -SHARK --- src/dpowassets | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/dpowassets b/src/dpowassets index b047eeae2..3fe8aa1b0 100755 --- a/src/dpowassets +++ b/src/dpowassets @@ -13,11 +13,9 @@ curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dp curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"BET\",\"pubkey\":\"$pubkey\"}" curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"CRYPTO\",\"pubkey\":\"$pubkey\"}" curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"HODL\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"SHARK\",\"pubkey\":\"$pubkey\"}" curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"MSHARK\",\"pubkey\":\"$pubkey\"}" curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"BOTS\",\"pubkey\":\"$pubkey\"}" curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"MGW\",\"pubkey\":\"$pubkey\"}" -#curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"MVP\",\"pubkey\":\"$pubkey\"}" curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"COQUI\",\"pubkey\":\"$pubkey\"}" curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"WLC\",\"pubkey\":\"$pubkey\"}" curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"KV\",\"pubkey\":\"$pubkey\"}" @@ -28,6 +26,8 @@ curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dp curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"AXO\",\"pubkey\":\"$pubkey\"}" curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"ETOMIC\",\"pubkey\":\"$pubkey\"}" curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"BTCH\",\"pubkey\":\"$pubkey\"}" +#curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"CHAIN\",\"pubkey\":\"$pubkey\"}" +curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"VOTE\",\"pubkey\":\"$pubkey\"}" #curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"USD\",\"pubkey\":\"$pubkey\"}" From 8683bd8d11e9af7c7ece45ea8873cd6658c65e9b Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 13 Feb 2018 21:29:42 +0200 Subject: [PATCH 165/188] Debugging --- src/komodo.h | 6 +- src/komodo_bitcoind.h | 6 +- src/komodo_gateway.h | 21 +++++ src/komodo_globals.h | 8 +- src/komodo_interest.h | 13 +-- src/komodo_notary.h | 186 +++++++++++++++++++++++++++++------------- src/komodo_structs.h | 3 +- src/komodo_utils.h | 76 +++++++++++++---- src/main.cpp | 37 ++++++++- src/miner.cpp | 58 +++++++++---- src/pow.cpp | 18 ++-- src/rpcmisc.cpp | 4 +- 12 files changed, 318 insertions(+), 118 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index c6467d957..3b22453a4 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -473,7 +473,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar } } -int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scriptbuf,int32_t scriptlen,int32_t height,uint256 txhash,int32_t i,int32_t j,uint64_t *voutmaskp,int32_t *specialtxp,int32_t *notarizedheightp,uint64_t value,int32_t notarized,uint64_t signedmask) +int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scriptbuf,int32_t scriptlen,int32_t height,uint256 txhash,int32_t i,int32_t j,uint64_t *voutmaskp,int32_t *specialtxp,int32_t *notarizedheightp,uint64_t value,int32_t notarized,uint64_t signedmask,uint32_t timestamp) { static uint256 zero; static FILE *signedfp; int32_t opretlen,nid,k,len = 0; uint256 kmdtxid,desttxid; uint8_t crypto777[33]; struct komodo_state *sp; char symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN]; @@ -499,7 +499,7 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr *specialtxp = 1; //printf(">>>>>>>> "); } - else if ( komodo_chosennotary(&nid,height,scriptbuf + 1) >= 0 ) + else if ( komodo_chosennotary(&nid,height,scriptbuf + 1,timestamp) >= 0 ) { //printf("found notary.k%d\n",k); if ( notaryid < 64 ) @@ -741,7 +741,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) #else memcpy(scriptbuf,(uint8_t *)&block.vtx[i].vout[j].scriptPubKey[0],len); #endif - notaryid = komodo_voutupdate(&isratification,notaryid,scriptbuf,len,height,txhash,i,j,&voutmask,&specialtx,¬arizedheight,(uint64_t)block.vtx[i].vout[j].nValue,notarized,signedmask); + notaryid = komodo_voutupdate(&isratification,notaryid,scriptbuf,len,height,txhash,i,j,&voutmask,&specialtx,¬arizedheight,(uint64_t)block.vtx[i].vout[j].nValue,notarized,signedmask,(uint32_t)chainActive.Tip()->GetBlockTime()); if ( 0 && i > 0 ) { for (k=0; k= 225000 ) - komodo_chosennotary(¬aryid,height,_pubkey33); + komodo_chosennotary(¬aryid,height,_pubkey33,timestamp); if ( height >= 34000 && notaryid >= 0 ) { if ( height < 79693 ) @@ -777,7 +777,7 @@ int32_t komodo_is_special(int32_t height,uint8_t pubkey33[33]) else limit = 66; for (i=1; i 0 ) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index d655f2aa5..d814bd6bf 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -719,6 +719,27 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block) // verify above } return(0); } + if ( ASSETCHAINS_SYMBOL[0] != 0 && ASSETCHAINS_COMMISSION != 0 ) + { + total = 0; + for (i=1; i nLockTime && (minutes= (tiptime - nLockTime) / 60) >= 60 ) + if ( nLockTime >= LOCKTIME_THRESHOLD && tiptime > nLockTime && (minutes= (tiptime - nLockTime) / 60) >= 60 ) { if ( minutes > 365 * 24 * 60 ) minutes = 365 * 24 * 60; @@ -152,7 +153,7 @@ uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uin interest = (numerator * minutes) / ((uint64_t)365 * 24 * 60); interestnew = _komodo_interestnew(nValue,nLockTime,tiptime); if ( interest < interestnew ) - printf("path0 current interest %.8f vs new %.8f for ht.%d %.8f locktime.%u tiptime.%u\n",dstr(interest),dstr(interestnew),txheight,dstr(nValue),nLockTime,tiptime); + printf("pathA current interest %.8f vs new %.8f for ht.%d %.8f locktime.%u tiptime.%u\n",dstr(interest),dstr(interestnew),txheight,dstr(nValue),nLockTime,tiptime); } else interest = _komodo_interestnew(nValue,nLockTime,tiptime); } @@ -162,7 +163,7 @@ uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uin interest = (numerator / denominator) / COIN; interestnew = _komodo_interestnew(nValue,nLockTime,tiptime); if ( interest < interestnew ) - printf("path0 current interest %.8f vs new %.8f for ht.%d %.8f locktime.%u tiptime.%u\n",dstr(interest),dstr(interestnew),txheight,dstr(nValue),nLockTime,tiptime); + printf("pathB current interest %.8f vs new %.8f for ht.%d %.8f locktime.%u tiptime.%u\n",dstr(interest),dstr(interestnew),txheight,dstr(nValue),nLockTime,tiptime); } else interest = _komodo_interestnew(nValue,nLockTime,tiptime); } @@ -187,8 +188,8 @@ uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uin interest = ((numerator * minutes) / ((uint64_t)365 * 24 * 60)); //fprintf(stderr,"interest %llu %.8f <- numerator.%llu minutes.%d\n",(long long)interest,(double)interest/COIN,(long long)numerator,(int32_t)minutes); interestnew = _komodo_interestnew(nValue,nLockTime,tiptime); - if ( interest < interestnew )//|| (interestnew < 0.9999*interest && (interest-interestnew) > 50000) ) - printf("path1 current interest %.8f vs new %.8f for ht.%d %.8f locktime.%u tiptime.%u\n",dstr(interest),dstr(interestnew),txheight,dstr(nValue),nLockTime,tiptime); + if ( interest < interestnew ) + fprintf(stderr,"pathC current interest %.8f vs new %.8f for ht.%d %.8f locktime.%u tiptime.%u\n",dstr(interest),dstr(interestnew),txheight,dstr(nValue),nLockTime,tiptime); } else interest = _komodo_interestnew(nValue,nLockTime,tiptime); } diff --git a/src/komodo_notary.h b/src/komodo_notary.h index a306f848f..9da3b6d05 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -58,7 +58,7 @@ const char *Notaries_genesis[][2] = { "titomane_SH", "035f49d7a308dd9a209e894321f010d21b7793461b0c89d6d9231a3fe5f68d9960" }, }; -const char *Notaries_elected[][2] = +const char *Notaries_elected0[][2] = { { "0_jl777_testA", "03b7621b44118017a16043f19b30cc8a4cfe068ac4e42417bae16ba460c80f3828" }, { "0_jl777_testB", "02ebfc784a4ba768aad88d44d1045d240d47b26e248cafaf1c5169a42d7a61d344" }, @@ -126,62 +126,99 @@ const char *Notaries_elected[][2] = { "xxspot2_XX", "03d85b221ea72ebcd25373e7961f4983d12add66a92f899deaf07bab1d8b6f5573" } }; -int32_t komodo_electednotary(uint8_t *pubkey33,int32_t height) -{ - char pubkeystr[67]; int32_t i; uint8_t legacy33[33]; - for (i=0; i<33; i++) - sprintf(&pubkeystr[i*2],"%02x",pubkey33[i]); - pubkeystr[66] = 0; - //printf("%s vs\n",pubkeystr); - for (i=0; i elected %s\n",i,(char *)Notaries_elected[i][1]); - return(i); - } - } - /*if ( height < 300000 ) - { - for (i=0; i elected %s\n",i,(char *)Notaries_elected[i][1]); - return(i+64); - } - } - decode_hex(legacy33,33,(char *)"0252b6185bf8ea7efe8bbc345ddc8da87329149f30233088387abd716d4aa9e974"); - if ( memcmp(pubkey33,legacy33,33) == 0 ) - return(128); - }*/ - return(-1); -} +#define KOMODO_NOTARIES_TIMESTAMP1 1600000000 +#define KOMODO_NOTARIES_HEIGHT1 ((800000 / KOMODO_ELECTION_GAP) * KOMODO_ELECTION_GAP) -int32_t komodo_ratify_threshold(int32_t height,uint64_t signedmask) +const char *Notaries_elected1[][2] = { - int32_t htind,numnotaries,i,wt = 0; - htind = height / KOMODO_ELECTION_GAP; - numnotaries = Pubkeys[htind].numnotaries; - for (i=0; i (numnotaries >> 1) || (wt > 7 && (signedmask & 1) != 0) ) - return(1); - else return(0); -} + { "0_jl777_testA", "03b7621b44118017a16043f19b30cc8a4cfe068ac4e42417bae16ba460c80f3828" }, + { "0_jl777_testB", "02ebfc784a4ba768aad88d44d1045d240d47b26e248cafaf1c5169a42d7a61d344" }, + { "0_kolo_testA", "0287aa4b73988ba26cf6565d815786caf0d2c4af704d7883d163ee89cd9977edec" }, + { "artik_AR", "029acf1dcd9f5ff9c455f8bb717d4ae0c703e089d16cf8424619c491dff5994c90" }, + { "artik_EU", "03f54b2c24f82632e3cdebe4568ba0acf487a80f8a89779173cdb78f74514847ce" }, + { "artik_NA", "0224e31f93eff0cc30eaf0b2389fbc591085c0e122c4d11862c1729d090106c842" }, + { "artik_SH", "02bdd8840a34486f38305f311c0e2ae73e84046f6e9c3dd3571e32e58339d20937" }, + { "badass_EU", "0209d48554768dd8dada988b98aca23405057ac4b5b46838a9378b95c3e79b9b9e" }, + { "badass_NA", "02afa1a9f948e1634a29dc718d218e9d150c531cfa852843a1643a02184a63c1a7" }, + { "badass_SH", "026b49dd3923b78a592c1b475f208e23698d3f085c4c3b4906a59faf659fd9530b" }, + { "crackers_EU", "03bc819982d3c6feb801ec3b720425b017d9b6ee9a40746b84422cbbf929dc73c3" }, // 10 + { "crackers_NA", "03205049103113d48c7c7af811b4c8f194dafc43a50d5313e61a22900fc1805b45" }, + { "crackers_SH", "02be28310e6312d1dd44651fd96f6a44ccc269a321f907502aae81d246fabdb03e" }, + { "durerus_EU", "02bcbd287670bdca2c31e5d50130adb5dea1b53198f18abeec7211825f47485d57" }, + { "etszombi_AR", "031c79168d15edabf17d9ec99531ea9baa20039d0cdc14d9525863b83341b210e9" }, + { "etszombi_EU", "0281b1ad28d238a2b217e0af123ce020b79e91b9b10ad65a7917216eda6fe64bf7" }, // 15 + { "etszombi_SH", "025d7a193c0757f7437fad3431f027e7b5ed6c925b77daba52a8755d24bf682dde" }, + { "farl4web_EU", "0300ecf9121cccf14cf9423e2adb5d98ce0c4e251721fa345dec2e03abeffbab3f" }, + { "farl4web_SH", "0396bb5ed3c57aa1221d7775ae0ff751e4c7dc9be220d0917fa8bbdf670586c030" }, + { "fullmoon_AR", "0254b1d64840ce9ff6bec9dd10e33beb92af5f7cee628f999cb6bc0fea833347cc" }, + { "fullmoon_NA", "031fb362323b06e165231c887836a8faadb96eda88a79ca434e28b3520b47d235b" }, // 20 + { "fullmoon_SH", "030e12b42ec33a80e12e570b6c8274ce664565b5c3da106859e96a7208b93afd0d" }, + { "grewal_NA", "03adc0834c203d172bce814df7c7a5e13dc603105e6b0adabc942d0421aefd2132" }, + { "grewal_SH", "03212a73f5d38a675ee3cdc6e82542a96c38c3d1c79d25a1ed2e42fcf6a8be4e68" }, + { "indenodes_AR", "02ec0fa5a40f47fd4a38ea5c89e375ad0b6ddf4807c99733c9c3dc15fb978ee147" }, + { "indenodes_EU", "0221387ff95c44cb52b86552e3ec118a3c311ca65b75bf807c6c07eaeb1be8303c" }, + { "indenodes_NA", "02698c6f1c9e43b66e82dbb163e8df0e5a2f62f3a7a882ca387d82f86e0b3fa988" }, + { "indenodes_SH", "0334e6e1ec8285c4b85bd6dae67e17d67d1f20e7328efad17ce6fd24ae97cdd65e" }, + { "jeezy_EU", "023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6" }, + { "jsgalt_NA", "027b3fb6fede798cd17c30dbfb7baf9332b3f8b1c7c513f443070874c410232446" }, + { "karasugoi_NA", "02a348b03b9c1a8eac1b56f85c402b041c9bce918833f2ea16d13452309052a982" }, // 30 + { "kashifali_EU", "033777c52a0190f261c6f66bd0e2bb299d30f012dcb8bfff384103211edb8bb207" }, + { "kolo_AR", "03016d19344c45341e023b72f9fb6e6152fdcfe105f3b4f50b82a4790ff54e9dc6" }, + { "kolo_SH", "02aa24064500756d9b0959b44d5325f2391d8e95c6127e109184937152c384e185" }, + { "metaphilibert_AR", "02adad675fae12b25fdd0f57250b0caf7f795c43f346153a31fe3e72e7db1d6ac6" }, + { "movecrypto_AR", "022783d94518e4dc77cbdf1a97915b29f427d7bc15ea867900a76665d3112be6f3" }, + { "movecrypto_EU", "021ab53bc6cf2c46b8a5456759f9d608966eff87384c2b52c0ac4cc8dd51e9cc42" }, + { "movecrypto_NA", "02efb12f4d78f44b0542d1c60146738e4d5506d27ec98a469142c5c84b29de0a80" }, + { "movecrypto_SH", "031f9739a3ebd6037a967ce1582cde66e79ea9a0551c54731c59c6b80f635bc859" }, + { "muros_AR", "022d77402fd7179335da39479c829be73428b0ef33fb360a4de6890f37c2aa005e" }, + { "noashh_AR", "029d93ef78197dc93892d2a30e5a54865f41e0ca3ab7eb8e3dcbc59c8756b6e355" }, // 40 + { "noashh_EU", "02061c6278b91fd4ac5cab4401100ffa3b2d5a277e8f71db23401cc071b3665546" }, + { "noashh_NA", "033c073366152b6b01535e15dd966a3a8039169584d06e27d92a69889b720d44e1" }, + { "nxtswe_EU", "032fb104e5eaa704a38a52c126af8f67e870d70f82977e5b2f093d5c1c21ae5899" }, + { "polycryptoblog_NA", "02708dcda7c45fb54b78469673c2587bfdd126e381654819c4c23df0e00b679622" }, + { "pondsea_AR", "032e1c213787312099158f2d74a89e8240a991d162d4ce8017d8504d1d7004f735" }, + { "pondsea_EU", "0225aa6f6f19e543180b31153d9e6d55d41bc7ec2ba191fd29f19a2f973544e29d" }, + { "pondsea_NA", "031bcfdbb62268e2ff8dfffeb9ddff7fe95fca46778c77eebff9c3829dfa1bb411" }, + { "pondsea_SH", "02209073bc0943451498de57f802650311b1f12aa6deffcd893da198a544c04f36" }, + { "popcornbag_AR", "02761f106fb34fbfc5ddcc0c0aa831ed98e462a908550b280a1f7bd32c060c6fa3" }, + { "popcornbag_NA", "03c6085c7fdfff70988fda9b197371f1caf8397f1729a844790e421ee07b3a93e8" }, // 50 + { "ptytrader_NA", "0328c61467148b207400b23875234f8a825cce65b9c4c9b664f47410b8b8e3c222" }, + { "ptytrader_SH", "0250c93c492d8d5a6b565b90c22bee07c2d8701d6118c6267e99a4efd3c7748fa4" }, + { "rnr_AR", "029bdb08f931c0e98c2c4ba4ef45c8e33a34168cb2e6bf953cef335c359d77bfcd" }, + { "rnr_EU", "03f5c08dadffa0ffcafb8dd7ffc38c22887bd02702a6c9ac3440deddcf2837692b" }, + { "rnr_NA", "02e17c5f8c3c80f584ed343b8dcfa6d710dfef0889ec1e7728ce45ce559347c58c" }, + { "rnr_SH", "037536fb9bdfed10251f71543fb42679e7c52308bcd12146b2568b9a818d8b8377" }, + { "titomane_AR", "03cda6ca5c2d02db201488a54a548dbfc10533bdc275d5ea11928e8d6ab33c2185" }, + { "titomane_EU", "02e41feded94f0cc59f55f82f3c2c005d41da024e9a805b41105207ef89aa4bfbd" }, + { "titomane_SH", "035f49d7a308dd9a209e894321f010d21b7793461b0c89d6d9231a3fe5f68d9960" }, + { "vanbreuk_EU", "024f3cad7601d2399c131fd070e797d9cd8533868685ddbe515daa53c2e26004c3" }, // 60 + { "xrobesx_NA", "03f0cc6d142d14a40937f12dbd99dbd9021328f45759e26f1877f2a838876709e1" }, + { "xxspot1_XX", "02ef445a392fcaf3ad4176a5da7f43580e8056594e003eba6559a713711a27f955" }, + { "xxspot2_XX", "03d85b221ea72ebcd25373e7961f4983d12add66a92f899deaf07bab1d8b6f5573" } +}; -int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height) +int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height,uint32_t timestamp) { int32_t i,htind,n; uint64_t mask = 0; struct knotary_entry *kp,*tmp; - if ( height >= 180000 || ASSETCHAINS_SYMBOL[0] != 0 ) + if ( height >= KOMODO_NOTARIES_HARDCODED || ASSETCHAINS_SYMBOL[0] != 0 ) { - n = (int32_t)(sizeof(Notaries_elected)/sizeof(*Notaries_elected)); - for (i=0; i= KOMODO_MAXBLOCKS / KOMODO_ELECTION_GAP ) + htind = (KOMODO_MAXBLOCKS / KOMODO_ELECTION_GAP) - 1; pthread_mutex_lock(&komodo_mutex); n = Pubkeys[htind].numnotaries; HASH_ITER(hh,Pubkeys[htind].Notaries,kp,tmp) @@ -199,6 +236,38 @@ int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height) return(-1); } +int32_t komodo_electednotary(int32_t *numnotariesp,uint8_t *pubkey33,int32_t height,uint32_t timestamp) +{ + char pubkeystr[67]; int32_t i,n; uint8_t pubkeys[64][33]; + for (i=0; i<33; i++) + sprintf(&pubkeystr[i*2],"%02x",pubkey33[i]); + pubkeystr[66] = 0; + //printf("%s vs\n",pubkeystr); + n = komodo_notaries(pubkeys,height,timestamp); + *numnotariesp = n; + for (i=0; i= KOMODO_MAXBLOCKS / KOMODO_ELECTION_GAP ) + htind = (KOMODO_MAXBLOCKS / KOMODO_ELECTION_GAP) - 1; + numnotaries = Pubkeys[htind].numnotaries; + for (i=0; i (numnotaries >> 1) || (wt > 7 && (signedmask & 1) != 0) ) + return(1); + else return(0); +} + void komodo_notarysinit(int32_t origheight,uint8_t pubkeys[64][33],int32_t num) { static int32_t hwmheight; @@ -212,6 +281,8 @@ void komodo_notarysinit(int32_t origheight,uint8_t pubkeys[64][33],int32_t num) height /= KOMODO_ELECTION_GAP; height = ((height + 1) * KOMODO_ELECTION_GAP); htind = (height / KOMODO_ELECTION_GAP); + if ( htind >= KOMODO_MAXBLOCKS / KOMODO_ELECTION_GAP ) + htind = (KOMODO_MAXBLOCKS / KOMODO_ELECTION_GAP) - 1; //printf("htind.%d activation %d from %d vs %d | hwmheight.%d %s\n",htind,height,origheight,(((origheight+KOMODO_ELECTION_GAP/2)/KOMODO_ELECTION_GAP)+1)*KOMODO_ELECTION_GAP,hwmheight,ASSETCHAINS_SYMBOL); } else htind = 0; pthread_mutex_lock(&komodo_mutex); @@ -244,7 +315,7 @@ void komodo_notarysinit(int32_t origheight,uint8_t pubkeys[64][33],int32_t num) hwmheight = origheight; } -int32_t komodo_chosennotary(int32_t *notaryidp,int32_t height,uint8_t *pubkey33) +int32_t komodo_chosennotary(int32_t *notaryidp,int32_t height,uint8_t *pubkey33,uint32_t timestamp) { // -1 if not notary, 0 if notary, 1 if special notary struct knotary_entry *kp; int32_t numnotaries=0,htind,modval = -1; @@ -255,18 +326,19 @@ int32_t komodo_chosennotary(int32_t *notaryidp,int32_t height,uint8_t *pubkey33) printf("komodo_chosennotary ht.%d illegal\n",height); return(-1); } - if ( height >= 180000 ) + if ( height >= KOMODO_NOTARIES_HARDCODED || ASSETCHAINS_SYMBOL[0] != 0 ) { - if ( (*notaryidp= komodo_electednotary(pubkey33,height)) >= 0 ) + if ( (*notaryidp= komodo_electednotary(&numnotaries,pubkey33,height,timestamp)) >= 0 && numnotaries != 0 ) { - numnotaries = (int32_t)(sizeof(Notaries_elected)/sizeof(*Notaries_elected)); modval = ((height % numnotaries) == *notaryidp); return(modval); } } - if ( height >= 250000 )//300000 ) + if ( height >= 250000 ) return(-1); htind = height / KOMODO_ELECTION_GAP; + if ( htind >= KOMODO_MAXBLOCKS / KOMODO_ELECTION_GAP ) + htind = (KOMODO_MAXBLOCKS / KOMODO_ELECTION_GAP) - 1; pthread_mutex_lock(&komodo_mutex); HASH_FIND(hh,Pubkeys[htind].Notaries,pubkey33,33,kp); pthread_mutex_unlock(&komodo_mutex); @@ -405,7 +477,7 @@ void komodo_init(int32_t height) // Minerids[i] = -2; didinit = 1; } - else if ( 0 && height == KOMODO_MAINNET_START ) + /*else if ( 0 && height == KOMODO_MAINNET_START ) { n = (int32_t)(sizeof(Notaries_elected)/sizeof(*Notaries_elected)); for (k=0; k 100000000 ) + { + ASSETCHAINS_DECAY = 0; + printf("ASSETCHAINS_DECAY cant be more than 100000000\n"); + } + if ( strlen(ASSETCHAINS_OVERRIDE_PUBKEY.c_str()) == 66 && ASSETCHAINS_COMMISSION > 0 && ASSETCHAINS_COMMISSION <= 1000000 ) + decode_hex(ASSETCHAINS_OVERRIDE_PUBKEY33,33,(char *)ASSETCHAINS_OVERRIDE_PUBKEY.c_str()); + else + { + ASSETCHAINS_COMMISSION = 0; + printf("ASSETCHAINS_COMMISSION needs an ASETCHAINS_OVERRIDE_PUBKEY\n"); + } + if ( ASSETCHAINS_ENDSUBSIDY != 0 || ASSETCHAINS_REWARD != 0 || ASSETCHAINS_HALVING != 0 || ASSETCHAINS_DECAY != 0 || ASSETCHAINS_COMMISSION != 0 ) + { + printf("end.%d reward.%llu halving.%llu decay.%llu perc.%llu\n",ASSETCHAINS_ENDSUBSIDY,(long long)ASSETCHAINS_REWARD,(long long)ASSETCHAINS_HALVING,(long long)ASSETCHAINS_DECAY,(long long)ASSETCHAINS_COMMISSION); + extraptr = extrabuf; + memcpy(extraptr,ASSETCHAINS_OVERRIDE_PUBKEY33,33), extralen = 33; + extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_ENDSUBSIDY),(void *)&ASSETCHAINS_ENDSUBSIDY); + extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_REWARD),(void *)&ASSETCHAINS_REWARD); + extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_HALVING),(void *)&ASSETCHAINS_HALVING); + extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_DECAY),(void *)&ASSETCHAINS_DECAY); + extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_COMMISSION),(void *)&ASSETCHAINS_COMMISSION); + } addn = GetArg("-seednode",""); if ( strlen(addn.c_str()) > 0 ) ASSETCHAINS_SEED = 1; @@ -1545,7 +1589,7 @@ void komodo_args(char *argv0) MAX_MONEY = komodo_maxallowed(baseid); else MAX_MONEY = (ASSETCHAINS_SUPPLY+1) * SATOSHIDEN; //printf("baseid.%d MAX_MONEY.%s %.8f\n",baseid,ASSETCHAINS_SYMBOL,(double)MAX_MONEY/SATOSHIDEN); - ASSETCHAINS_PORT = komodo_port(ASSETCHAINS_SYMBOL,ASSETCHAINS_SUPPLY,&ASSETCHAINS_MAGIC); + ASSETCHAINS_PORT = komodo_port(ASSETCHAINS_SYMBOL,ASSETCHAINS_SUPPLY,&ASSETCHAINS_MAGIC,extraptr,extralen); while ( (dirname= (char *)GetDataDir(false).string().c_str()) == 0 || dirname[0] == 0 ) { fprintf(stderr,"waiting for datadir\n"); @@ -1564,8 +1608,8 @@ void komodo_args(char *argv0) COINBASE_MATURITY = 1; LogPrintf("ASSETCHAINS_PORT %s %u\n",ASSETCHAINS_SYMBOL,ASSETCHAINS_PORT); } - ASSETCHAINS_NOTARIES = GetArg("-ac_notaries",""); - komodo_assetchain_pubkeys((char *)ASSETCHAINS_NOTARIES.c_str()); + //ASSETCHAINS_NOTARIES = GetArg("-ac_notaries",""); + //komodo_assetchain_pubkeys((char *)ASSETCHAINS_NOTARIES.c_str()); iguana_rwnum(1,magic,sizeof(ASSETCHAINS_MAGIC),(void *)&ASSETCHAINS_MAGIC); for (i=0; i<4; i++) sprintf(&magicstr[i<<1],"%02x",magic[i]); @@ -1615,7 +1659,7 @@ void komodo_args(char *argv0) break; } } - BITCOIND_PORT = GetArg("-rpcport", BaseParams().RPCPort()); + BITCOIND_PORT = GetArg("-rpcport", BaseParams().RPCPort()); //fprintf(stderr,"%s chain params initialized\n",ASSETCHAINS_SYMBOL); } diff --git a/src/main.cpp b/src/main.cpp index e06749072..0ac888c71 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1493,11 +1493,11 @@ bool ReadBlockFromDisk(CBlock& block, const CBlockIndex* pindex) //uint64_t komodo_moneysupply(int32_t height); extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; extern uint32_t ASSETCHAINS_MAGIC; -extern uint64_t ASSETCHAINS_SUPPLY; +extern uint64_t ASSETCHAINS_ENDSUBSIDY,ASSETCHAINS_REWARD,ASSETCHAINS_HALVING,ASSETCHAINS_LINEAR,ASSETCHAINS_COMMISSION,ASSETCHAINS_SUPPLY = 10; CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams) { - CAmount nSubsidy = 3 * COIN; + int32_t numhalvings; uint64_t numerator; CAmount nSubsidy = 3 * COIN; if ( ASSETCHAINS_SYMBOL[0] == 0 ) { if ( nHeight == 1 ) @@ -1510,7 +1510,38 @@ CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams) { if ( nHeight == 1 ) return(ASSETCHAINS_SUPPLY * COIN + (ASSETCHAINS_MAGIC & 0xffffff)); - else return(10000); + else if ( ASSETCHAINS_ENDSUBSIDY == 0 || nHeight < ASSETCHAINS_ENDSUBSIDY ) + { + if ( ASSETCHAINS_REWARD == 0 ) + return(10000); + else if ( ASSETCHAINS_ENDHEIGHT != 0 && nHeight >= ASSETCHAINS_ENDHEIGHT ) + return(0); + else + { + nSubsidy = ASSETCHAINS_REWARD; + if ( ASSETCHAINS_HALVING != 0 ) + { + if ( (numhalvings= (nHeight / ASSETCHAINS_HALVING)) > 0 ) + { + if ( numhalvings >= 64 && ASSETCHAINS_DECAY == 0 ) + return(0); + if ( ASSETCHAINS_DECAY == 0 ) + nSubsidy >>= numhalvings; + else if ( ASSETCHAINS_DECAY == 100000000 && ASSETCHAINS_ENDHEIGHT != 0 ) + { + numerator = (ASSETCHAINS_ENDHEIGHT - nHeight); + nSubsidy = (nSubidy * numerator) / ASSETCHAINS_ENDHEIGHT; + } + else + { + for (i=0; i 0 ) // have pricefeed @@ -411,14 +411,14 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) txNew.vout[1].nValue = 0; //fprintf(stderr,"opretlen.%d\n",opretlen); } //else printf("null opretlen for prices\n"); - }*/ + } } else if ( komodo_is_issuer() != 0 ) { komodo_gateway_deposits(&txNew,ASSETCHAINS_SYMBOL,0); if ( txNew.vout.size() > 1 ) fprintf(stderr,"%s txNew numvouts.%d\n",ASSETCHAINS_SYMBOL,(int32_t)txNew.vout.size()); - } + }*/ pblock->vtx[0] = txNew; pblocktemplate->vTxFees[0] = -nFees; @@ -640,7 +640,7 @@ void static BitcoinMiner() unsigned int n = chainparams.EquihashN(); unsigned int k = chainparams.EquihashK(); - int32_t notaryid = -1; + uint8_t *script; uint64_t total,checktoshis; int32_t i,j,notaryid = -1; while ( (ASSETCHAIN_INIT == 0 || KOMODO_INITDONE == 0) ) //chainActive.Tip()->nHeight != 235300 && { sleep(1); @@ -648,7 +648,7 @@ void static BitcoinMiner() break; } //sleep(60); - komodo_chosennotary(¬aryid,chainActive.Tip()->nHeight,NOTARY_PUBKEY33); + komodo_chosennotary(¬aryid,chainActive.Tip()->nHeight,NOTARY_PUBKEY33,(uint32_t)chainActive.Tip()->GetBlockTime()); std::string solver; //if ( notaryid >= 0 || ASSETCHAINS_SYMBOL[0] != 0 ) @@ -741,14 +741,42 @@ void static BitcoinMiner() CBlock *pblock = &pblocktemplate->block; if ( ASSETCHAINS_SYMBOL[0] != 0 ) { - if ( pblock->vtx.size() == 1 && pblock->vtx[0].vout.size() == 1 && Mining_height > ASSETCHAINS_MINHEIGHT ) + if ( ASSETCHAINS_REWARD == 0 ) { - static uint32_t counter; - if ( counter++ < 10 ) - fprintf(stderr,"skip generating %s on-demand block, no tx avail\n",ASSETCHAINS_SYMBOL); - sleep(10); - continue; - } else fprintf(stderr,"%s vouts.%d mining.%d vs %d\n",ASSETCHAINS_SYMBOL,(int32_t)pblock->vtx[0].vout.size(),Mining_height,ASSETCHAINS_MINHEIGHT); + if ( pblock->vtx.size() == 1 && pblock->vtx[0].vout.size() == 1 && Mining_height > ASSETCHAINS_MINHEIGHT ) + { + static uint32_t counter; + if ( counter++ < 10 ) + fprintf(stderr,"skip generating %s on-demand block, no tx avail\n",ASSETCHAINS_SYMBOL); + sleep(10); + continue; + } else fprintf(stderr,"%s vouts.%d mining.%d vs %d\n",ASSETCHAINS_SYMBOL,(int32_t)pblock->vtx[0].vout.size(),Mining_height,ASSETCHAINS_MINHEIGHT); + } + else if ( ASSETCHAINS_COMMISSION != 0 ) + { + total = 0; + for (i=1; ivtx.size(); i++) + { + n = pblock->vtx[i].vout.size(); + for (j=0; jvtx[i].vout[j].nValue; + } + if ( (checktoshis = (total * ASSETCHAINS_COMMISSION) / COIN) != 0 ) + { + pblock->vtx[0].vout[1].nValue = checktoshis; + pblock->vtx[0].vout.resize(2); + pblock->vtx[0].vout[1].scriptPubKey.resize(35); + script = (uint8_t *)pblock->vtx[0].vout[1].scriptPubKey.data(); + script[0] = 33; + for (i=0; i<33; i++) + script[i+1] = ASSETCHAINS_OVERRIDE_PUBKEY33[i]; + script[34] = OP_CHECKSIG; + } + } + else + { + pblock->vtx[0].vout.resize(1); + } } IncrementExtraNonce(pblock, pindexPrev, nExtraNonce); LogPrintf("Running KomodoMiner.%s with %u transactions in block (%u bytes)\n",solver.c_str(),pblock->vtx.size(),::GetSerializeSize(*pblock,SER_NETWORK,PROTOCOL_VERSION)); diff --git a/src/pow.cpp b/src/pow.cpp index cbee3f6a6..39d4fbc42 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -115,13 +115,14 @@ bool CheckEquihashSolution(const CBlockHeader *pblock, const CChainParams& param return true; } -int32_t komodo_chosennotary(int32_t *notaryidp,int32_t height,uint8_t *pubkey33); -int32_t komodo_is_special(int32_t height,uint8_t pubkey33[33]); +int32_t komodo_chosennotary(int32_t *notaryidp,int32_t height,uint8_t *pubkey33,uint32_t timestamp); +int32_t komodo_is_special(int32_t height,uint8_t pubkey33[33],uint32_t timestamp); int32_t komodo_currentheight(); CBlockIndex *komodo_chainactive(int32_t height); int8_t komodo_minerid(int32_t height,uint8_t *pubkey33); void komodo_index2pubkey33(uint8_t *pubkey33,CBlockIndex *pindex,int32_t height); extern int32_t KOMODO_CHOSEN_ONE; +extern char ASSETCHAINS_SYMBOL[]; #define KOMODO_ELECTION_GAP 2000 int32_t komodo_eligiblenotary(uint8_t pubkeys[66][33],int32_t *mids,int32_t *nonzpkeysp,int32_t height); @@ -132,15 +133,16 @@ extern std::string NOTARY_PUBKEY; bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash, unsigned int nBits, const Consensus::Params& params) { extern int32_t KOMODO_REWIND; - bool fNegative,fOverflow; int32_t i,nonzpkeys=0,nonz=0,special=0,special2=0,notaryid=-1,duplicate,flag = 0, mids[66]; + bool fNegative,fOverflow; int32_t i,nonzpkeys=0,nonz=0,special=0,special2=0,notaryid=-1,duplicate,flag = 0, mids[66]; uint32_t timestamp = 0; arith_uint256 bnTarget; CBlockIndex *pindex; uint8_t pubkeys[66][33]; - + if ( (pindex= chainActive.Tip()) != 0 ) + timestamp = (uint32_t)pindex->GetBlockTime(); bnTarget.SetCompact(nBits, &fNegative, &fOverflow); if ( height == 0 ) height = komodo_currentheight() + 1; - special = komodo_chosennotary(¬aryid,height,pubkey33); - flag = komodo_eligiblenotary(pubkeys,mids,&nonzpkeys,height); - if ( height > 34000 ) // 0 -> non-special notary + special = komodo_chosennotary(¬aryid,height,pubkey33,timestamp); + flag = komodo_eligiblenotary(pubkeys,mids,&nonzpkeys,height,timestamp); + if ( height > 34000 && ASSETCHAINS_SYMBOL[0] == 0 ) // 0 -> non-special notary { for (i=0; i<33; i++) { @@ -149,7 +151,7 @@ bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash, unsigned in } if ( nonz == 0 ) return(true); // will come back via different path with pubkey set - special2 = komodo_is_special(height,pubkey33); + special2 = komodo_is_special(height,pubkey33,timestamp); if ( notaryid >= 0 ) { if ( height > 10000 && height < 80000 && (special != 0 || special2 > 0) ) diff --git a/src/rpcmisc.cpp b/src/rpcmisc.cpp index 6008e341d..d34cfde05 100644 --- a/src/rpcmisc.cpp +++ b/src/rpcmisc.cpp @@ -46,7 +46,7 @@ int32_t Jumblr_secretaddradd(char *secretaddr); uint64_t komodo_interestsum(); int32_t komodo_longestchain(); int32_t komodo_notarized_height(uint256 *hashp,uint256 *txidp); -int32_t komodo_whoami(char *pubkeystr,int32_t height); +int32_t komodo_whoami(char *pubkeystr,int32_t height,uint32_t timestamp); extern int32_t KOMODO_LASTMINED,JUMBLR_PAUSE; extern char ASSETCHAINS_SYMBOL[]; int32_t notarizedtxid_height(char *dest,char *txidstr,int32_t *kmdnotarized_heightp); @@ -139,7 +139,7 @@ UniValue getinfo(const UniValue& params, bool fHelp) obj.push_back(Pair("errors", GetWarnings("statusbar"))); { char pubkeystr[65]; int32_t notaryid; - if ( (notaryid= komodo_whoami(pubkeystr,(int32_t)chainActive.Tip()->nHeight)) >= 0 ) + if ( (notaryid= komodo_whoami(pubkeystr,(int32_t)chainActive.Tip()->nHeight,(int32_t)(uint32_t)(uint32_t)chainActive.Tip()->GetBlocktime())) >= 0 ) { obj.push_back(Pair("notaryid", notaryid)); obj.push_back(Pair("pubkey", pubkeystr)); From 9757c8f97eff7665559fdc352f8e54a15927113d Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 13 Feb 2018 21:33:49 +0200 Subject: [PATCH 166/188] Test --- src/komodo_utils.h | 2 +- src/main.cpp | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index d18bfc659..0c9281e58 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1572,7 +1572,7 @@ void komodo_args(char *argv0) } if ( ASSETCHAINS_ENDSUBSIDY != 0 || ASSETCHAINS_REWARD != 0 || ASSETCHAINS_HALVING != 0 || ASSETCHAINS_DECAY != 0 || ASSETCHAINS_COMMISSION != 0 ) { - printf("end.%d reward.%llu halving.%llu decay.%llu perc.%llu\n",ASSETCHAINS_ENDSUBSIDY,(long long)ASSETCHAINS_REWARD,(long long)ASSETCHAINS_HALVING,(long long)ASSETCHAINS_DECAY,(long long)ASSETCHAINS_COMMISSION); + printf("end.%llu reward.%llu halving.%llu decay.%llu perc.%llu\n",(long long)ASSETCHAINS_ENDSUBSIDY,(long long)ASSETCHAINS_REWARD,(long long)ASSETCHAINS_HALVING,(long long)ASSETCHAINS_DECAY,(long long)ASSETCHAINS_COMMISSION); extraptr = extrabuf; memcpy(extraptr,ASSETCHAINS_OVERRIDE_PUBKEY33,33), extralen = 33; extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_ENDSUBSIDY),(void *)&ASSETCHAINS_ENDSUBSIDY); diff --git a/src/main.cpp b/src/main.cpp index 0ac888c71..9e6674580 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1493,7 +1493,7 @@ bool ReadBlockFromDisk(CBlock& block, const CBlockIndex* pindex) //uint64_t komodo_moneysupply(int32_t height); extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; extern uint32_t ASSETCHAINS_MAGIC; -extern uint64_t ASSETCHAINS_ENDSUBSIDY,ASSETCHAINS_REWARD,ASSETCHAINS_HALVING,ASSETCHAINS_LINEAR,ASSETCHAINS_COMMISSION,ASSETCHAINS_SUPPLY = 10; +extern uint64_t ASSETCHAINS_ENDSUBSIDY,ASSETCHAINS_REWARD,ASSETCHAINS_HALVING,ASSETCHAINS_LINEAR,ASSETCHAINS_COMMISSION,ASSETCHAINS_SUPPLY; CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams) { @@ -1514,7 +1514,7 @@ CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams) { if ( ASSETCHAINS_REWARD == 0 ) return(10000); - else if ( ASSETCHAINS_ENDHEIGHT != 0 && nHeight >= ASSETCHAINS_ENDHEIGHT ) + else if ( ASSETCHAINS_ENDSUBSIDY != 0 && nHeight >= ASSETCHAINS_ENDSUBSIDY ) return(0); else { @@ -1527,10 +1527,10 @@ CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams) return(0); if ( ASSETCHAINS_DECAY == 0 ) nSubsidy >>= numhalvings; - else if ( ASSETCHAINS_DECAY == 100000000 && ASSETCHAINS_ENDHEIGHT != 0 ) + else if ( ASSETCHAINS_DECAY == 100000000 && ASSETCHAINS_ENDSUBSIDY != 0 ) { - numerator = (ASSETCHAINS_ENDHEIGHT - nHeight); - nSubsidy = (nSubidy * numerator) / ASSETCHAINS_ENDHEIGHT; + numerator = (ASSETCHAINS_ENDSUBSIDY - nHeight); + nSubsidy = (nSubidy * numerator) / ASSETCHAINS_ENDSUBSIDY; } else { From 53a94b280dc6785a8f6e34d4f37dcb5ea4e48fac Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 13 Feb 2018 21:34:09 +0200 Subject: [PATCH 167/188] Test --- src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 9e6674580..8d66ebe72 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1497,7 +1497,7 @@ extern uint64_t ASSETCHAINS_ENDSUBSIDY,ASSETCHAINS_REWARD,ASSETCHAINS_HALVING,AS CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams) { - int32_t numhalvings; uint64_t numerator; CAmount nSubsidy = 3 * COIN; + int32_t numhalvings,i; uint64_t numerator; CAmount nSubsidy = 3 * COIN; if ( ASSETCHAINS_SYMBOL[0] == 0 ) { if ( nHeight == 1 ) @@ -1530,7 +1530,7 @@ CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams) else if ( ASSETCHAINS_DECAY == 100000000 && ASSETCHAINS_ENDSUBSIDY != 0 ) { numerator = (ASSETCHAINS_ENDSUBSIDY - nHeight); - nSubsidy = (nSubidy * numerator) / ASSETCHAINS_ENDSUBSIDY; + nSubsidy = (nSubsidy * numerator) / ASSETCHAINS_ENDSUBSIDY; } else { From 6e94384f91302ff758d76ab770033f7e7f76a87b Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 13 Feb 2018 21:37:32 +0200 Subject: [PATCH 168/188] Test --- src/komodo_utils.h | 6 +++--- src/main.cpp | 12 ++++++++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 0c9281e58..22cc4fdf2 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1548,10 +1548,10 @@ void komodo_args(char *argv0) ASSETCHAINS_DECAY = GetArg("-ac_decay",0); ASSETCHAINS_COMMISSION = GetArg("-ac_perc",0); ASSETCHAINS_OVERRIDE_PUBKEY = GetArg("-ac_pubkey",""); - if ( ASSETCHAINS_HALVING != 0 && ASSETCHAINS_HALVING < 10000 ) + if ( ASSETCHAINS_HALVING != 0 && ASSETCHAINS_HALVING < 1440 ) { - ASSETCHAINS_HALVING = 10000; - printf("ASSETCHAINS_HALVING must be at least 10000 blocks\n"); + ASSETCHAINS_HALVING = 1440; + printf("ASSETCHAINS_HALVING must be at least 1440 blocks\n"); } if ( ASSETCHAINS_DECAY == 100000000 && ASSETCHAINS_ENDSUBSIDY == 0 ) { diff --git a/src/main.cpp b/src/main.cpp index 8d66ebe72..7f373e03b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1497,6 +1497,7 @@ extern uint64_t ASSETCHAINS_ENDSUBSIDY,ASSETCHAINS_REWARD,ASSETCHAINS_HALVING,AS CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams) { + static uint64_t cached_subsidy; static int32_t cached_numhalvings; int32_t numhalvings,i; uint64_t numerator; CAmount nSubsidy = 3 * COIN; if ( ASSETCHAINS_SYMBOL[0] == 0 ) { @@ -1534,8 +1535,15 @@ CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams) } else { - for (i=0; i 0 && cached_numhalvings == numhalvings ) + nSubsidy = cached_subsidy; + else + { + for (i=0; i Date: Tue, 13 Feb 2018 21:59:39 +0200 Subject: [PATCH 169/188] Test --- src/miner.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index bf6596065..ed2523a5a 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -109,9 +109,10 @@ void UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams, #include "komodo_defs.h" extern int32_t ASSETCHAINS_SEED,IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAIN_INIT,KOMODO_INITDONE,KOMODO_ON_DEMAND,KOMODO_INITDONE,KOMODO_PASSPORT_INITDONE; +extern uint32_t ASSETCHAINS_REWARD,ASSETCHAINS_COMMISSION; extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; extern std::string NOTARY_PUBKEY; -extern uint8_t NOTARY_PUBKEY33[33]; +extern uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33]; uint32_t Mining_start,Mining_height; int32_t komodo_chosennotary(int32_t *notaryidp,int32_t height,uint8_t *pubkey33,uint32_t timestamp); int32_t komodo_is_special(int32_t height,uint8_t pubkey33[33],uint32_t timestamp); @@ -763,8 +764,8 @@ void static BitcoinMiner() } if ( (checktoshis = (total * ASSETCHAINS_COMMISSION) / COIN) != 0 ) { - pblock->vtx[0].vout[1].nValue = checktoshis; pblock->vtx[0].vout.resize(2); + pblock->vtx[0].vout[1].nValue = checktoshis; pblock->vtx[0].vout[1].scriptPubKey.resize(35); script = (uint8_t *)pblock->vtx[0].vout[1].scriptPubKey.data(); script[0] = 33; From 3ca78e01424a5f94cc4bbc659b6b664a9ede5d22 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 13 Feb 2018 22:06:20 +0200 Subject: [PATCH 170/188] Test --- src/miner.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index ed2523a5a..d447327a0 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -554,7 +554,7 @@ CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey) { for (i=0; i<65; i++) fprintf(stderr,"%d ",komodo_minerid(chainActive.Tip()->nHeight-i,0)); - fprintf(stderr," minerids.special %d from ht.%d\n",komodo_is_special(chainActive.Tip()->nHeight+1,NOTARY_PUBKEY33),chainActive.Tip()->nHeight); + fprintf(stderr," minerids.special %d from ht.%d\n",komodo_is_special(chainActive.Tip()->nHeight+1,NOTARY_PUBKEY33,chainActive.Tip()->nHeight); } return CreateNewBlock(scriptPubKey); } @@ -764,9 +764,9 @@ void static BitcoinMiner() } if ( (checktoshis = (total * ASSETCHAINS_COMMISSION) / COIN) != 0 ) { - pblock->vtx[0].vout.resize(2); + pblock->vtx[0].vout.resize((long)2); pblock->vtx[0].vout[1].nValue = checktoshis; - pblock->vtx[0].vout[1].scriptPubKey.resize(35); + pblock->vtx[0].vout[1].scriptPubKey.resize((long)35); script = (uint8_t *)pblock->vtx[0].vout[1].scriptPubKey.data(); script[0] = 33; for (i=0; i<33; i++) @@ -776,7 +776,7 @@ void static BitcoinMiner() } else { - pblock->vtx[0].vout.resize(1); + pblock->vtx[0].vout.resize((long)1); } } IncrementExtraNonce(pblock, pindexPrev, nExtraNonce); From d209491abf01aa4da4acb540b80d24411525a85a Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 13 Feb 2018 22:25:30 +0200 Subject: [PATCH 171/188] Test --- src/komodo_gateway.h | 13 ++++++------- src/komodo_utils.h | 4 ++-- src/miner.cpp | 27 +-------------------------- 3 files changed, 9 insertions(+), 35 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index d814bd6bf..b5ec33fb5 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -653,7 +653,7 @@ void komodo_passport_iteration(); int32_t komodo_check_deposit(int32_t height,const CBlock& block) // verify above block is valid pax pricing { static uint256 array[64]; static int32_t numbanned,indallvouts; - int32_t i,j,k,n,ht,baseid,txn_count,activation,num,opretlen,offset=1,errs=0,matched=0,kmdheights[256],otherheights[256]; uint256 hash,txids[256]; char symbol[KOMODO_ASSETCHAIN_MAXLEN],base[KOMODO_ASSETCHAIN_MAXLEN]; uint16_t vouts[256]; int8_t baseids[256]; uint8_t *script,opcode,rmd160s[256*20]; uint64_t total,available,deposited,issued,withdrawn,approved,redeemed,checktoshis,seed; int64_t values[256],srcvalues[256]; struct pax_transaction *pax; struct komodo_state *sp; + int32_t i,j,k,n,ht,baseid,txn_count,activation,num,opretlen,offset=1,errs=0,matched=0,kmdheights[256],otherheights[256]; uint256 hash,txids[256]; char symbol[KOMODO_ASSETCHAIN_MAXLEN],base[KOMODO_ASSETCHAIN_MAXLEN]; uint16_t vouts[256]; int8_t baseids[256]; uint8_t *script,opcode,rmd160s[256*20]; uint64_t total,subsidy,available,deposited,issued,withdrawn,approved,redeemed,checktoshis,seed; int64_t values[256],srcvalues[256]; struct pax_transaction *pax; struct komodo_state *sp; activation = 235300; if ( *(int32_t *)&array[0] == 0 ) numbanned = komodo_bannedset(&indallvouts,array,(int32_t)(sizeof(array)/sizeof(*array))); @@ -721,6 +721,9 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block) // verify above } if ( ASSETCHAINS_SYMBOL[0] != 0 && ASSETCHAINS_COMMISSION != 0 ) { + script = (uint8_t *)block.vtx[0].vout[0].scriptPubKey.data(); + if ( script[0] != 33 || script[34] != OP_CHECKSIG || memcmp(script+1,ASSETCHAINS_OVERRIDE_PUBKEY33,33) != 0 ) + return(-1); total = 0; for (i=1; i 0 && ASSETCHAINS_COMMISSION <= 1000000 ) + if ( strlen(ASSETCHAINS_OVERRIDE_PUBKEY.c_str()) == 66 && ASSETCHAINS_COMMISSION > 0 && ASSETCHAINS_COMMISSION <= 100000000 ) decode_hex(ASSETCHAINS_OVERRIDE_PUBKEY33,33,(char *)ASSETCHAINS_OVERRIDE_PUBKEY.c_str()); else { ASSETCHAINS_COMMISSION = 0; - printf("ASSETCHAINS_COMMISSION needs an ASETCHAINS_OVERRIDE_PUBKEY\n"); + printf("ASSETCHAINS_COMMISSION needs an ASETCHAINS_OVERRIDE_PUBKEY and cant be more than 100000000 (100%%)\n"); } if ( ASSETCHAINS_ENDSUBSIDY != 0 || ASSETCHAINS_REWARD != 0 || ASSETCHAINS_HALVING != 0 || ASSETCHAINS_DECAY != 0 || ASSETCHAINS_COMMISSION != 0 ) { diff --git a/src/miner.cpp b/src/miner.cpp index d447327a0..ddd484759 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -554,7 +554,7 @@ CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey) { for (i=0; i<65; i++) fprintf(stderr,"%d ",komodo_minerid(chainActive.Tip()->nHeight-i,0)); - fprintf(stderr," minerids.special %d from ht.%d\n",komodo_is_special(chainActive.Tip()->nHeight+1,NOTARY_PUBKEY33,chainActive.Tip()->nHeight); + fprintf(stderr," minerids.special %d from ht.%d\n",komodo_is_special(chainActive.Tip()->nHeight+1,NOTARY_PUBKEY33,chainActive.Tip()->nHeight)); } return CreateNewBlock(scriptPubKey); } @@ -753,31 +753,6 @@ void static BitcoinMiner() continue; } else fprintf(stderr,"%s vouts.%d mining.%d vs %d\n",ASSETCHAINS_SYMBOL,(int32_t)pblock->vtx[0].vout.size(),Mining_height,ASSETCHAINS_MINHEIGHT); } - else if ( ASSETCHAINS_COMMISSION != 0 ) - { - total = 0; - for (i=1; ivtx.size(); i++) - { - n = pblock->vtx[i].vout.size(); - for (j=0; jvtx[i].vout[j].nValue; - } - if ( (checktoshis = (total * ASSETCHAINS_COMMISSION) / COIN) != 0 ) - { - pblock->vtx[0].vout.resize((long)2); - pblock->vtx[0].vout[1].nValue = checktoshis; - pblock->vtx[0].vout[1].scriptPubKey.resize((long)35); - script = (uint8_t *)pblock->vtx[0].vout[1].scriptPubKey.data(); - script[0] = 33; - for (i=0; i<33; i++) - script[i+1] = ASSETCHAINS_OVERRIDE_PUBKEY33[i]; - script[34] = OP_CHECKSIG; - } - } - else - { - pblock->vtx[0].vout.resize((long)1); - } } IncrementExtraNonce(pblock, pindexPrev, nExtraNonce); LogPrintf("Running KomodoMiner.%s with %u transactions in block (%u bytes)\n",solver.c_str(),pblock->vtx.size(),::GetSerializeSize(*pblock,SER_NETWORK,PROTOCOL_VERSION)); From 6b1d77f5853d8836776016045666638f031f8622 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 13 Feb 2018 22:27:18 +0200 Subject: [PATCH 172/188] 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 b5ec33fb5..2b3d382ac 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -733,7 +733,7 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block) // verify above } if ( (checktoshis = (total * ASSETCHAINS_COMMISSION) / COIN) != 0 ) { - subsidy = GetBlockSubsidy(height,chainparams.GetConsensus()); + subsidy = GetBlockSubsidy(height,Params().GetConsensus()); if ( block.vtx[0].vout.size() != 1 || block.vtx[0].vout[0].nValue != checktoshis+subsidy ) return(-1); } From da7b748e6bd4b051cd1450d8c084e31ccc878531 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 13 Feb 2018 22:30:59 +0200 Subject: [PATCH 173/188] Test --- src/miner.cpp | 2 +- src/pow.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index ddd484759..9abd309f3 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -554,7 +554,7 @@ CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey) { for (i=0; i<65; i++) fprintf(stderr,"%d ",komodo_minerid(chainActive.Tip()->nHeight-i,0)); - fprintf(stderr," minerids.special %d from ht.%d\n",komodo_is_special(chainActive.Tip()->nHeight+1,NOTARY_PUBKEY33,chainActive.Tip()->nHeight)); + fprintf(stderr," minerids.special %d from ht.%d\n",komodo_is_special(chainActive.Tip()->nHeight+1,NOTARY_PUBKEY33,chainActive.Tip()->GetBlockTime()),chainActive.Tip()->nHeight)); } return CreateNewBlock(scriptPubKey); } diff --git a/src/pow.cpp b/src/pow.cpp index 39d4fbc42..fde35cb57 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -141,7 +141,7 @@ bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash, unsigned in if ( height == 0 ) height = komodo_currentheight() + 1; special = komodo_chosennotary(¬aryid,height,pubkey33,timestamp); - flag = komodo_eligiblenotary(pubkeys,mids,&nonzpkeys,height,timestamp); + flag = komodo_eligiblenotary(pubkeys,mids,&nonzpkeys,height); if ( height > 34000 && ASSETCHAINS_SYMBOL[0] == 0 ) // 0 -> non-special notary { for (i=0; i<33; i++) From ac756fd8bbb7a323f939eae3ec561360fedb2c56 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 13 Feb 2018 22:32:14 +0200 Subject: [PATCH 174/188] Test --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index 9abd309f3..44acf06c6 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -554,7 +554,7 @@ CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey) { for (i=0; i<65; i++) fprintf(stderr,"%d ",komodo_minerid(chainActive.Tip()->nHeight-i,0)); - fprintf(stderr," minerids.special %d from ht.%d\n",komodo_is_special(chainActive.Tip()->nHeight+1,NOTARY_PUBKEY33,chainActive.Tip()->GetBlockTime()),chainActive.Tip()->nHeight)); + fprintf(stderr," minerids.special %d from ht.%d\n",komodo_is_special(chainActive.Tip()->nHeight+1,NOTARY_PUBKEY33,chainActive.Tip()->GetBlockTime()),chainActive.Tip()->nHeight); } return CreateNewBlock(scriptPubKey); } From 698c5e7e94eb39d16d422ec2cab8e162b513ff53 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 13 Feb 2018 22:34:29 +0200 Subject: [PATCH 175/188] Test --- src/pow.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pow.cpp b/src/pow.cpp index fde35cb57..033f8d9e3 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -13,6 +13,7 @@ #include "streams.h" #include "uint256.h" #include "util.h" +#include "consensus/validation.h" #include "sodium.h" From ae0bb3d3c3188ac1f8c55ef281941d78bc34ebb8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 13 Feb 2018 22:36:44 +0200 Subject: [PATCH 176/188] Test --- src/komodo_bitcoind.h | 7 +++++++ src/pow.cpp | 5 ++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index de77c6fb3..2a226a714 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -658,6 +658,13 @@ int32_t komodo_blockload(CBlock& block,CBlockIndex *pindex) return(0); } +uint32_t komodo_chainactive_timestamp() +{ + if ( chainActive.Tip() != 0 ) + return((uint32_t)chainActive.Tip()->GetBlockTime()); + else return(0); +} + CBlockIndex *komodo_chainactive(int32_t height) { if ( chainActive.Tip() != 0 ) diff --git a/src/pow.cpp b/src/pow.cpp index 033f8d9e3..9621fadad 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -13,13 +13,13 @@ #include "streams.h" #include "uint256.h" #include "util.h" -#include "consensus/validation.h" #include "sodium.h" #ifdef ENABLE_RUST #include "librustzcash.h" #endif // ENABLE_RUST +uint32_t komodo_chainactive_timestamp(); unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params& params) { @@ -136,8 +136,7 @@ bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash, unsigned in extern int32_t KOMODO_REWIND; bool fNegative,fOverflow; int32_t i,nonzpkeys=0,nonz=0,special=0,special2=0,notaryid=-1,duplicate,flag = 0, mids[66]; uint32_t timestamp = 0; arith_uint256 bnTarget; CBlockIndex *pindex; uint8_t pubkeys[66][33]; - if ( (pindex= chainActive.Tip()) != 0 ) - timestamp = (uint32_t)pindex->GetBlockTime(); + timestamp = komodo_chainactive_timestamp(); bnTarget.SetCompact(nBits, &fNegative, &fOverflow); if ( height == 0 ) height = komodo_currentheight() + 1; From e169b65ff0ac7a435952d71552905920fc647667 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 13 Feb 2018 22:37:47 +0200 Subject: [PATCH 177/188] New features in testing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit New komodod -ac parameters for assetchains. If -ac_reward= is non-zero, the chain will mine normally and start with -ac_reward for the block reward. if -ac_end= is set, then -ac_reward will be 0 after endheight is reached if -ac_halving= is set, then every blocks the block reward is reduced according to one of three methods. 1440 (approx a day) is the most frequent halving period if -ac_decay is not set, then the normal bitcoin halving is done. if -ac_decay= is set to be exactly 100000000, then the -ac_reward is scaled linearly toward 0, with 0 at endheight. for all other values of numerator (less than 100000000) the reward is iteratively reduced by the number of "halving" periods, ie. numhalvings = (height / -ac_halving); for (i=0; i is nonzero and less than equal 100000000 and -ac_pubkey= is set to a 33byte hexstr (len 66 starting with 02 or 03) then there will be a second vout in the coinbase transaction that is exactly the commission rate indicated by -ac_perc, with 100000000 being the max of 100%. wallets will need to be customized to make sure to pay the -ac_perc of transaction size as txfee. chains with a percentage override can only be mined by the -ac_pubkey address bitcoin behavior would be -ac_reward=5000000000 -ac_halving=210000 KMD behavior would be -ac_reward = 300000000 -ac_end=7777777 a more smoothly reducing reward that halves every 210000 blocks would be:  -ac_reward=5000000000 -ac_halving=10000 -ac_decay=96777000 This release also supports a second slate of hardcoded notaries --- 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 2a226a714..e904a5b1b 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -662,7 +662,7 @@ uint32_t komodo_chainactive_timestamp() { if ( chainActive.Tip() != 0 ) return((uint32_t)chainActive.Tip()->GetBlockTime()); - else return(0); + else return(0); } CBlockIndex *komodo_chainactive(int32_t height) From e34a9d43fee54989617040f00e0981ea6f0e910d Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 13 Feb 2018 22:42:34 +0200 Subject: [PATCH 178/188] Fix --- .gitignore | 2 ++ src/komodo_bitcoind.h | 2 +- src/rpcmisc.cpp | 3 ++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 3e934cb9f..5b8b361e1 100644 --- a/.gitignore +++ b/.gitignore @@ -114,3 +114,5 @@ libzcashconsensus.pc src/fiat/-usd contrib/debian/files contrib/debian/substvars + +src/rpcmisc~.cpp diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index e904a5b1b..2a226a714 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -662,7 +662,7 @@ uint32_t komodo_chainactive_timestamp() { if ( chainActive.Tip() != 0 ) return((uint32_t)chainActive.Tip()->GetBlockTime()); - else return(0); + else return(0); } CBlockIndex *komodo_chainactive(int32_t height) diff --git a/src/rpcmisc.cpp b/src/rpcmisc.cpp index d34cfde05..3fdd3bb89 100644 --- a/src/rpcmisc.cpp +++ b/src/rpcmisc.cpp @@ -46,6 +46,7 @@ int32_t Jumblr_secretaddradd(char *secretaddr); uint64_t komodo_interestsum(); int32_t komodo_longestchain(); int32_t komodo_notarized_height(uint256 *hashp,uint256 *txidp); +uint32_t komodo_chainactive_timestamp(); int32_t komodo_whoami(char *pubkeystr,int32_t height,uint32_t timestamp); extern int32_t KOMODO_LASTMINED,JUMBLR_PAUSE; extern char ASSETCHAINS_SYMBOL[]; @@ -139,7 +140,7 @@ UniValue getinfo(const UniValue& params, bool fHelp) obj.push_back(Pair("errors", GetWarnings("statusbar"))); { char pubkeystr[65]; int32_t notaryid; - if ( (notaryid= komodo_whoami(pubkeystr,(int32_t)chainActive.Tip()->nHeight,(int32_t)(uint32_t)(uint32_t)chainActive.Tip()->GetBlocktime())) >= 0 ) + if ( (notaryid= komodo_whoami(pubkeystr,(int32_t)chainActive.Tip()->nHeight,komodo_chainactive_timestamp())) >= 0 ) { obj.push_back(Pair("notaryid", notaryid)); obj.push_back(Pair("pubkey", pubkeystr)); From 85ef725a7d5700e5b35bf5f46ddf2d8e516c15c4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 13 Feb 2018 22:52:45 +0200 Subject: [PATCH 179/188] Test --- src/komodo.h | 2 +- src/komodo_bitcoind.h | 11 ++++++----- src/rpcblockchain.cpp | 12 +++++++++--- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 3b22453a4..129ea3b5f 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -646,7 +646,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) return; } //fprintf(stderr,"%s connect.%d\n",ASSETCHAINS_SYMBOL,pindex->nHeight); - numnotaries = komodo_notaries(pubkeys,pindex->nHeight); + numnotaries = komodo_notaries(pubkeys,pindex->nHeight,pindex->GetBlockTime()); calc_rmd160_sha256(rmd160,pubkeys[0],33); if ( pindex->nHeight > hwmheight ) hwmheight = pindex->nHeight; diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 2a226a714..e73cae4e5 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -710,27 +710,28 @@ void komodo_connectpindex(CBlockIndex *pindex) komodo_connectblock(pindex,block); } -int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height); -int32_t komodo_electednotary(uint8_t *pubkey33,int32_t height); +int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height,uint32_t timestamp); +int32_t komodo_electednotary(uint8_t *pubkey33,int32_t height,uint32_t timestamp); int8_t komodo_minerid(int32_t height,uint8_t *pubkey33) { - int32_t num,i; CBlockIndex *pindex; uint8_t _pubkey33[33],pubkeys[64][33]; + int32_t num,i; CBlockIndex *pindex; uint32_t timestamp=0; uint8_t _pubkey33[33],pubkeys[64][33]; if ( pubkey33 == 0 && (pindex= chainActive[height]) != 0 ) { + timestamp = pindex->GetBlockTime(); if ( pubkey33 == 0 ) { pubkey33 = _pubkey33; komodo_index2pubkey33(pubkey33,pindex,height); } - if ( (num= komodo_notaries(pubkeys,height)) > 0 ) + if ( (num= komodo_notaries(pubkeys,height,timestamp)) > 0 ) { for (i=0; inHeight; + else + { + CBlockIndex *pblockindex = chainActive[height]; + if ( pblockindex != 0 ) + timestamp = pblockindex->GetBlockTime(); + } if ( (n= komodo_minerids(minerids,height,(int32_t)(sizeof(minerids)/sizeof(*minerids)))) > 0 ) { memset(tally,0,sizeof(tally)); - numnotaries = komodo_notaries(pubkeys,height); + numnotaries = komodo_notaries(pubkeys,height,timestamp); if ( numnotaries > 0 ) { for (i=0; i Date: Tue, 13 Feb 2018 22:54:45 +0200 Subject: [PATCH 180/188] Test --- src/rpcblockchain.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 5a15fb918..e004252b4 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -638,13 +638,22 @@ UniValue minerids(const UniValue& params, bool fHelp) UniValue notaries(const UniValue& params, bool fHelp) { - UniValue a(UniValue::VARR); UniValue ret(UniValue::VOBJ); int32_t i,j,n,m; char *hexstr; uint8_t pubkeys[64][33]; char btcaddr[64],kmdaddr[64],*ptr; + UniValue a(UniValue::VARR); uint32_t timestamp=0; UniValue ret(UniValue::VOBJ); 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); int32_t height = atoi(params[0].get_str().c_str()); if ( height < 0 ) + { height = chainActive.Tip()->nHeight; + timestamp = chainActive.Tip()->GetBlockTime(); + } + else + { + CBlockIndex *pblockindex = chainActive[height]; + if ( pblockindex != 0 ) + timestamp = pblockindex->GetBlockTime(); + } //fprintf(stderr,"notaries as of height.%d\n",height); //if ( height > chainActive.Height()+20000 ) // throw JSONRPCError(RPC_INVALID_PARAMETER, "Block height out of range"); From 148e99adac7e1ca09b753cd13ef9433eccf40195 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 13 Feb 2018 22:55:14 +0200 Subject: [PATCH 181/188] Test --- src/rpcblockchain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index e004252b4..91f694abb 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -659,7 +659,7 @@ UniValue notaries(const UniValue& params, bool fHelp) // throw JSONRPCError(RPC_INVALID_PARAMETER, "Block height out of range"); //else { - if ( (n= komodo_notaries(pubkeys,height)) > 0 ) + if ( (n= komodo_notaries(pubkeys,height,timestamp)) > 0 ) { for (i=0; i Date: Tue, 13 Feb 2018 22:57:25 +0200 Subject: [PATCH 182/188] Test --- src/komodo_bitcoind.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index e73cae4e5..d4364a3ea 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -711,11 +711,11 @@ void komodo_connectpindex(CBlockIndex *pindex) } int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height,uint32_t timestamp); -int32_t komodo_electednotary(uint8_t *pubkey33,int32_t height,uint32_t timestamp); +int32_t komodo_electednotary(int32_t *numnotariesp,uint8_t *pubkey33,int32_t height,uint32_t timestamp); int8_t komodo_minerid(int32_t height,uint8_t *pubkey33) { - int32_t num,i; CBlockIndex *pindex; uint32_t timestamp=0; uint8_t _pubkey33[33],pubkeys[64][33]; + int32_t num,i,numnotaries; CBlockIndex *pindex; uint32_t timestamp=0; uint8_t _pubkey33[33],pubkeys[64][33]; if ( pubkey33 == 0 && (pindex= chainActive[height]) != 0 ) { timestamp = pindex->GetBlockTime(); @@ -731,7 +731,7 @@ int8_t komodo_minerid(int32_t height,uint8_t *pubkey33) return(i); } } - return(komodo_electednotary(pubkey33,height,timestamp)); + return(komodo_electednotary(&numnotaries,pubkey33,height,timestamp)); } int32_t komodo_eligiblenotary(uint8_t pubkeys[66][33],int32_t *mids,int32_t *nonzpkeysp,int32_t height) From e8a05f61f00bac808779f535cfb43915c4b7d89d Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 13 Feb 2018 23:00:15 +0200 Subject: [PATCH 183/188] 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 2d9d31dfb..617e9c423 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1565,7 +1565,7 @@ void komodo_args(char *argv0) } if ( strlen(ASSETCHAINS_OVERRIDE_PUBKEY.c_str()) == 66 && ASSETCHAINS_COMMISSION > 0 && ASSETCHAINS_COMMISSION <= 100000000 ) decode_hex(ASSETCHAINS_OVERRIDE_PUBKEY33,33,(char *)ASSETCHAINS_OVERRIDE_PUBKEY.c_str()); - else + else if ( ASSETCHAINS_COMMISSION != 0 ) { ASSETCHAINS_COMMISSION = 0; printf("ASSETCHAINS_COMMISSION needs an ASETCHAINS_OVERRIDE_PUBKEY and cant be more than 100000000 (100%%)\n"); From 036a250c6e284064345de476a103ad07ad77756c Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 13 Feb 2018 23:04:01 +0200 Subject: [PATCH 184/188] Test --- src/komodo_notary.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_notary.h b/src/komodo_notary.h index 9da3b6d05..438d81809 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -321,7 +321,7 @@ int32_t komodo_chosennotary(int32_t *notaryidp,int32_t height,uint8_t *pubkey33, struct knotary_entry *kp; int32_t numnotaries=0,htind,modval = -1; komodo_init(0); *notaryidp = -1; - if ( height < 0 || height >= KOMODO_MAXBLOCKS ) + if ( height < 0 )//|| height >= KOMODO_MAXBLOCKS ) { printf("komodo_chosennotary ht.%d illegal\n",height); return(-1); From fc5bee9e146dc3127f4f840b190b8f2537742ad5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 14 Feb 2018 00:57:33 +0200 Subject: [PATCH 185/188] -print --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 7f373e03b..72f25f1fc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -737,7 +737,7 @@ bool IsFinalTx(const CTransaction &tx, int nBlockHeight, int64_t nBlockTime) } else if (!txin.IsFinal()) { - printf("non-final txin seq.%x locktime.%u vs nTime.%u\n",txin.nSequence,(uint32_t)tx.nLockTime,(uint32_t)nBlockTime); + //printf("non-final txin seq.%x locktime.%u vs nTime.%u\n",txin.nSequence,(uint32_t)tx.nLockTime,(uint32_t)nBlockTime); return false; } } From c989bc86e3a7d3244de828519128a10dd9453373 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Sat, 17 Feb 2018 20:45:00 -0800 Subject: [PATCH 186/188] Read hashReserved from disk instead of assuming 0 Related to https://github.com/zcash/zcash/pull/2931 --- src/txdb.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/txdb.cpp b/src/txdb.cpp index 868d3d4cd..9a23596d9 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -302,6 +302,7 @@ bool CBlockTreeDB::LoadBlockIndexGuts() pindexNew->nUndoPos = diskindex.nUndoPos; pindexNew->hashAnchor = diskindex.hashAnchor; pindexNew->nVersion = diskindex.nVersion; + pindexNew->hashReserved = diskindex.hashReserved; pindexNew->hashMerkleRoot = diskindex.hashMerkleRoot; pindexNew->nTime = diskindex.nTime; pindexNew->nBits = diskindex.nBits; From 253cd526acb50ce5220582f404d7ab556e4afa84 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 18 Feb 2018 23:59:52 +0200 Subject: [PATCH 187/188] MAX_MONEY to handle mining chains --- src/komodo_utils.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 617e9c423..9f7384883 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1587,7 +1587,9 @@ void komodo_args(char *argv0) strncpy(ASSETCHAINS_SYMBOL,name.c_str(),sizeof(ASSETCHAINS_SYMBOL)-1); if ( (baseid= komodo_baseid(ASSETCHAINS_SYMBOL)) >= 0 && baseid < 32 ) MAX_MONEY = komodo_maxallowed(baseid); - else MAX_MONEY = (ASSETCHAINS_SUPPLY+1) * SATOSHIDEN; + else if ( ASSETCHAINS_REWARD == 0 ) + MAX_MONEY = (ASSETCHAINS_SUPPLY+1) * SATOSHIDEN; + else MAX_MONEY = (ASSETCHAINS_SUPPLY+1) * SATOSHIDEN + ASSETCHAINS_REWARD * (ASSETCHAINS_ENDSUBSIDY==0 ? 10000000 : ASSETCHAINS_ENDSUBSIDY); //printf("baseid.%d MAX_MONEY.%s %.8f\n",baseid,ASSETCHAINS_SYMBOL,(double)MAX_MONEY/SATOSHIDEN); ASSETCHAINS_PORT = komodo_port(ASSETCHAINS_SYMBOL,ASSETCHAINS_SUPPLY,&ASSETCHAINS_MAGIC,extraptr,extralen); while ( (dirname= (char *)GetDataDir(false).string().c_str()) == 0 || dirname[0] == 0 ) From 052f0068008a5f6db587551bfeee1165cbccc222 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 19 Feb 2018 00:08:02 +0200 Subject: [PATCH 188/188] ASSETCHAINS_CC --- src/komodo_globals.h | 2 +- src/komodo_utils.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/komodo_globals.h b/src/komodo_globals.h index f666d9c6f..6c2e56f5b 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -44,7 +44,7 @@ struct komodo_state KOMODO_STATES[34]; int COINBASE_MATURITY = _COINBASE_MATURITY;//100; int32_t IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAINS_SEED,KOMODO_ON_DEMAND,KOMODO_EXTERNAL_NOTARIES,KOMODO_PASSPORT_INITDONE,KOMODO_PAX,KOMODO_EXCHANGEWALLET,KOMODO_REWIND; -int32_t KOMODO_LASTMINED,prevKOMODO_LASTMINED,JUMBLR_PAUSE; +int32_t KOMODO_LASTMINED,prevKOMODO_LASTMINED,JUMBLR_PAUSE,ASSETCHAINS_CC; std::string NOTARY_PUBKEY,ASSETCHAINS_NOTARIES,ASSETCHAINS_OVERRIDE_PUBKEY; uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33]; diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 9f7384883..231d1a3c4 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1535,6 +1535,7 @@ void komodo_args(char *argv0) } } } + ASSETCHAINS_CC = GetArg("-ac_cc",0); if ( (KOMODO_REWIND= GetArg("-rewind",0)) != 0 ) { printf("KOMODO_REWIND %d\n",KOMODO_REWIND);