Hush Full Node software. We were censored from Github, this is where all development happens now. https://hush.is
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123 lines
5.6 KiB

8 years ago
/******************************************************************************
8 years ago
* Copyright © 2014-2017 The SuperNET Developers. *
8 years ago
* *
* 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. *
* *
******************************************************************************/
8 years ago
8 years ago
#define KOMODO_INTEREST ((uint64_t)(0.05 * COIN)) // 5%
8 years ago
8 years ago
uint64_t komodo_earned_interest(int32_t height,int64_t paidinterest)
8 years ago
{
static uint64_t *interests; static int32_t maxheight;
8 years ago
uint64_t total; int32_t ind,incr = 100000;
8 years ago
if ( height >= maxheight )
{
8 years ago
if ( interests == 0 )
{
8 years ago
maxheight = height + incr;
interests = (uint64_t *)calloc(maxheight,sizeof(*interests) * 2);
8 years ago
}
else
{
interests = (uint64_t *)realloc(interests,(maxheight + incr) * sizeof(*interests) * 2);
memset(&interests[maxheight << 1],0,incr * sizeof(*interests) * 2);
maxheight += incr;
}
8 years ago
}
ind = (height << 1);
if ( paidinterest < 0 ) // request
return(interests[ind]);
else
{
if ( interests[ind + 1] != 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];
for (++height; height<maxheight; height++)
{
ind = (height << 1);
interests[ind] = total;
interests[ind + 1] = 0;
}
}
}
8 years ago
return(0);
8 years ago
}
uint64_t komodo_moneysupply(int32_t height)
{
8 years ago
if ( height <= 1 || ASSETCHAINS_SYMBOL[0] == 0 )
8 years ago
return(0);
8 years ago
else return(COIN * 100000000 + (height-1) * 3 + komodo_earned_interest(height,-1));
8 years ago
}
uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uint32_t tiptime)
8 years ago
{
7 years ago
int32_t minutes,exception; uint64_t numerator,denominator,interest = 0;
8 years ago
if ( ASSETCHAINS_SYMBOL[0] != 0 )
return(0);
8 years ago
if ( komodo_moneysupply(txheight) < MAX_MONEY && nLockTime >= LOCKTIME_THRESHOLD && tiptime != 0 && nLockTime < tiptime && nValue >= 10*COIN )
8 years ago
{
8 years ago
if ( (minutes= (tiptime - nLockTime) / 60) >= 60 )
8 years ago
{
denominator = (((uint64_t)365 * 24 * 60) / minutes);
if ( denominator == 0 )
denominator = 1; // max KOMODO_INTEREST per transfer, do it at least annually!
7 years ago
if ( nValue > 25000LL*COIN )
7 years ago
{
7 years ago
exception = 0;
7 years ago
if ( nValue == 4000000000000LL )
printf(">>>>>>>>>>>> exception.%d txheight.%d %.8f locktime %u vs tiptime %u <<<<<<<<<\n",exception,txheight,(double)nValue/COIN,nLockTime,tiptime);
7 years ago
if ( txheight <= 155949 )
7 years ago
{
7 years ago
if ( (txheight == 116607 && nValue == 2502721100000LL) ||
7 years ago
(txheight == 126891 && nValue == 2879650000000LL) ||
(txheight == 129510 && nValue == 3000000000000LL) ||
(txheight == 141549 && nValue == 3500000000000LL) ||
(txheight == 154473 && nValue == 3983399350000LL) ||
(txheight == 154736 && nValue == 3983406748175LL) ||
(txheight == 155013 && nValue == 3983414006565LL) ||
(txheight == 155492 && nValue == 3983427592291LL) ||
(txheight == 155613 && nValue == 9997409999999797LL) ||
(txheight == 157927 && nValue == 9997410667451072LL) ||
7 years ago
(txheight == 155613 && nValue == 2590000000000LL) ||
7 years ago
(txheight == 155949 && nValue == 4000000000000LL) )
7 years ago
exception = 1;
7 years ago
if ( exception == 0 )
printf(">>>>>>>>>>>> exception.%d txheight.%d %.8f locktime %u vs tiptime %u <<<<<<<<<\n",exception,txheight,(double)nValue/COIN,nLockTime,tiptime);
7 years ago
}
if ( exception == 0 )
{
numerator = (nValue / 20); // assumes 5%!
interest = (numerator / denominator);
}
else
{
numerator = (nValue * KOMODO_INTEREST);
interest = (numerator / denominator) / COIN;
}
7 years ago
}
else
{
numerator = (nValue * KOMODO_INTEREST);
interest = (numerator / denominator) / COIN;
}
7 years ago
//fprintf(stderr,"komodo_interest %lld %.8f nLockTime.%u tiptime.%u minutes.%d interest %lld %.8f (%llu / %llu)\n",(long long)nValue,(double)nValue/COIN,nLockTime,tiptime,minutes,(long long)interest,(double)interest/COIN,(long long)numerator,(long long)denominator);
8 years ago
}
8 years ago
}
8 years ago
return(interest);
8 years ago
}
8 years ago