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