Merge pull request #391 from jl777/dev
April 5th activation Interest calc fix for small utxo
This commit is contained in:
@@ -346,6 +346,59 @@ char *komodo_issuemethod(char *userpass,char *method,char *params,uint16_t port)
|
|||||||
return(retstr2);
|
return(retstr2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t notarizedtxid_height(char *dest,char *txidstr,int32_t *kmdnotarized_heightp)
|
||||||
|
{
|
||||||
|
char *jsonstr,params[256],*userpass; uint16_t port; cJSON *json,*item; int32_t height = 0,txid_height = 0,txid_confirmations = 0;
|
||||||
|
params[0] = 0;
|
||||||
|
*kmdnotarized_heightp = 0;
|
||||||
|
if ( strcmp(dest,"KMD") == 0 )
|
||||||
|
{
|
||||||
|
port = 7771;
|
||||||
|
userpass = KMDUSERPASS;
|
||||||
|
}
|
||||||
|
else if ( strcmp(dest,"BTC") == 0 )
|
||||||
|
{
|
||||||
|
port = 8332;
|
||||||
|
userpass = BTCUSERPASS;
|
||||||
|
}
|
||||||
|
else return(0);
|
||||||
|
if ( userpass[0] != 0 )
|
||||||
|
{
|
||||||
|
if ( (jsonstr= komodo_issuemethod(userpass,(char *)"getinfo",params,port)) != 0 )
|
||||||
|
{
|
||||||
|
//printf("(%s)\n",jsonstr);
|
||||||
|
if ( (json= cJSON_Parse(jsonstr)) != 0 )
|
||||||
|
{
|
||||||
|
if ( (item= jobj(json,(char *)"result")) != 0 )
|
||||||
|
{
|
||||||
|
*kmdnotarized_heightp = jint(item,(char *)"notarized");
|
||||||
|
height = jint(item,(char *)"blocks");
|
||||||
|
}
|
||||||
|
free_json(json);
|
||||||
|
}
|
||||||
|
free(jsonstr);
|
||||||
|
}
|
||||||
|
sprintf(params,"[\"%s\", 1]",txidstr);
|
||||||
|
if ( (jsonstr= komodo_issuemethod(userpass,(char *)"getrawtransaction",params,port)) != 0 )
|
||||||
|
{
|
||||||
|
//printf("(%s)\n",jsonstr);
|
||||||
|
if ( (json= cJSON_Parse(jsonstr)) != 0 )
|
||||||
|
{
|
||||||
|
if ( (item= jobj(json,(char *)"result")) != 0 )
|
||||||
|
{
|
||||||
|
txid_confirmations = jint(item,(char *)"confirmations");
|
||||||
|
if ( txid_confirmations > 0 && height > txid_confirmations )
|
||||||
|
txid_height = height - txid_confirmations;
|
||||||
|
//printf("height.%d tconfs.%d txid_height.%d\n",height,txid_confirmations,txid_height);
|
||||||
|
}
|
||||||
|
free_json(json);
|
||||||
|
}
|
||||||
|
free(jsonstr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return(txid_height);
|
||||||
|
}
|
||||||
|
|
||||||
int32_t komodo_verifynotarizedscript(int32_t height,uint8_t *script,int32_t len,uint256 NOTARIZED_HASH)
|
int32_t komodo_verifynotarizedscript(int32_t height,uint8_t *script,int32_t len,uint256 NOTARIZED_HASH)
|
||||||
{
|
{
|
||||||
int32_t i; uint256 hash; char params[256];
|
int32_t i; uint256 hash; char params[256];
|
||||||
|
|||||||
@@ -66,7 +66,8 @@ uint64_t komodo_moneysupply(int32_t height)
|
|||||||
|
|
||||||
uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uint32_t tiptime)
|
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;
|
int32_t minutes,exception; uint64_t numerator,denominator,interest = 0; uint32_t activation;
|
||||||
|
activation = 1491350400; // 1491350400 5th April
|
||||||
if ( ASSETCHAINS_SYMBOL[0] != 0 )
|
if ( ASSETCHAINS_SYMBOL[0] != 0 )
|
||||||
return(0);
|
return(0);
|
||||||
if ( komodo_moneysupply(txheight) < MAX_MONEY && nLockTime >= LOCKTIME_THRESHOLD && tiptime != 0 && nLockTime < tiptime && nValue >= 10*COIN )
|
if ( komodo_moneysupply(txheight) < MAX_MONEY && nLockTime >= LOCKTIME_THRESHOLD && tiptime != 0 && nLockTime < tiptime && nValue >= 10*COIN )
|
||||||
@@ -118,12 +119,28 @@ uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uin
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
/* 250000 algo
|
||||||
|
numerator = (nValue * KOMODO_INTEREST);
|
||||||
|
if ( txheight < 250000 || numerator * minutes < 365 * 24 * 60 )
|
||||||
|
interest = (numerator / denominator) / COIN;
|
||||||
|
else interest = ((numerator * minutes) / ((uint64_t)365 * 24 * 60)) / COIN;
|
||||||
|
*/
|
||||||
numerator = (nValue * KOMODO_INTEREST);
|
numerator = (nValue * KOMODO_INTEREST);
|
||||||
if ( txheight < 250000 || numerator * minutes < 365 * 24 * 60 )
|
if ( txheight < 250000 && tiptime < activation )
|
||||||
interest = (numerator / denominator) / COIN;
|
{
|
||||||
else interest = ((numerator * minutes) / ((uint64_t)365 * 24 * 60)) / COIN;
|
if ( numerator * minutes < 365 * 24 * 60 )
|
||||||
|
interest = (numerator / denominator) / COIN;
|
||||||
|
else interest = ((numerator * minutes) / ((uint64_t)365 * 24 * 60)) / COIN;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
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));
|
||||||
}
|
}
|
||||||
//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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return(interest);
|
return(interest);
|
||||||
|
|||||||
@@ -1355,7 +1355,7 @@ void komodo_configfile(char *symbol,uint16_t port)
|
|||||||
komodo_userpass(username,password,fp);
|
komodo_userpass(username,password,fp);
|
||||||
sprintf(KMDUSERPASS,"%s:%s",username,password);
|
sprintf(KMDUSERPASS,"%s:%s",username,password);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
//printf("KOMODO.(%s) -> userpass.(%s)\n",fname,KMDUSERPASS);
|
//printf("KOMODO.(%s) -> userpass.(%s)\n",fname,KMDUSERPASS);
|
||||||
} else printf("couldnt open.(%s)\n",fname);
|
} else printf("couldnt open.(%s)\n",fname);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -650,7 +650,7 @@ void static BitcoinMiner(CWallet *pwallet)
|
|||||||
CBlock *pblock = &pblocktemplate->block;
|
CBlock *pblock = &pblocktemplate->block;
|
||||||
if ( ASSETCHAINS_SYMBOL[0] != 0 )
|
if ( ASSETCHAINS_SYMBOL[0] != 0 )
|
||||||
{
|
{
|
||||||
if ( pblock->vtx[0].vout.size() == 1 && Mining_height > ASSETCHAINS_MINHEIGHT )
|
if ( pblock->vtx.size() == 1 && Mining_height > ASSETCHAINS_MINHEIGHT )
|
||||||
{
|
{
|
||||||
static uint32_t counter;
|
static uint32_t counter;
|
||||||
if ( counter++ < 10 )
|
if ( counter++ < 10 )
|
||||||
@@ -703,11 +703,11 @@ void static BitcoinMiner(CWallet *pwallet)
|
|||||||
if ( mids[j] == -1 )
|
if ( mids[j] == -1 )
|
||||||
gpucount++;
|
gpucount++;
|
||||||
}
|
}
|
||||||
if ( gpucount > j/3 )
|
if ( gpucount > j/2 )
|
||||||
{
|
{
|
||||||
double delta;
|
double delta;
|
||||||
i = ((Mining_height + notaryid) % 64);
|
i = ((Mining_height + notaryid) % 64);
|
||||||
delta = sqrt((double)gpucount - j/3) / 2.;
|
delta = sqrt((double)gpucount - j/2) / 2.;
|
||||||
roundrobin_delay += ((delta * i) / 64) - delta;
|
roundrobin_delay += ((delta * i) / 64) - delta;
|
||||||
//fprintf(stderr,"delta.%f %f %f\n",delta,(double)(gpucount - j/3) / 2,(delta * i) / 64);
|
//fprintf(stderr,"delta.%f %f %f\n",delta,(double)(gpucount - j/3) / 2,(delta * i) / 64);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -175,7 +175,7 @@ bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash, unsigned in
|
|||||||
fprintf(stderr,"pow error height.%d loading.%d notaryid.%d\n",height,KOMODO_LOADINGBLOCKS,notaryid);
|
fprintf(stderr,"pow error height.%d loading.%d notaryid.%d\n",height,KOMODO_LOADINGBLOCKS,notaryid);
|
||||||
return error("CheckProofOfWork(): hash doesn't match nBits");
|
return error("CheckProofOfWork(): hash doesn't match nBits");
|
||||||
} else fprintf(stderr,"skip return error height.%d loading.%d\n",height,KOMODO_LOADINGBLOCKS);
|
} else fprintf(stderr,"skip return error height.%d loading.%d\n",height,KOMODO_LOADINGBLOCKS);
|
||||||
} else fprintf(stderr,"skip height.%d loading.%d\n",height,KOMODO_LOADINGBLOCKS);
|
} //else fprintf(stderr,"skip height.%d loading.%d\n",height,KOMODO_LOADINGBLOCKS);
|
||||||
}
|
}
|
||||||
if ( 0 && height > 248000 )
|
if ( 0 && height > 248000 )
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -46,6 +46,9 @@ int32_t komodo_longestchain();
|
|||||||
int32_t komodo_notarized_height(uint256 *hashp,uint256 *txidp);
|
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);
|
||||||
extern int32_t KOMODO_LASTMINED;
|
extern int32_t KOMODO_LASTMINED;
|
||||||
|
extern char ASSETCHAINS_SYMBOL[];
|
||||||
|
int32_t notarizedtxid_height(char *dest,char *txidstr,int32_t *kmdnotarized_heightp);
|
||||||
|
#define KOMODO_VERSION "0.1.0"
|
||||||
|
|
||||||
Value getinfo(const Array& params, bool fHelp)
|
Value getinfo(const Array& params, bool fHelp)
|
||||||
{
|
{
|
||||||
@@ -92,14 +95,24 @@ Value getinfo(const Array& params, bool fHelp)
|
|||||||
Object obj;
|
Object obj;
|
||||||
obj.push_back(Pair("version", CLIENT_VERSION));
|
obj.push_back(Pair("version", CLIENT_VERSION));
|
||||||
obj.push_back(Pair("protocolversion", PROTOCOL_VERSION));
|
obj.push_back(Pair("protocolversion", PROTOCOL_VERSION));
|
||||||
|
obj.push_back(Pair("KMDversion", KOMODO_VERSION));
|
||||||
obj.push_back(Pair("notarized", notarized_height));
|
obj.push_back(Pair("notarized", notarized_height));
|
||||||
obj.push_back(Pair("notarizedhash", notarized_hash.ToString()));
|
obj.push_back(Pair("notarizedhash", notarized_hash.ToString()));
|
||||||
obj.push_back(Pair("notarizedtxid", notarized_desttxid.ToString()));
|
obj.push_back(Pair("notarizedtxid", notarized_desttxid.ToString()));
|
||||||
|
if ( ASSETCHAINS_SYMBOL[0] != 0 )
|
||||||
|
{
|
||||||
|
int32_t kmdnotarized_height,txid_height;
|
||||||
|
txid_height = notarizedtxid_height(ASSETCHAINS_SYMBOL[0] != 0 ? (char *)"KMD" : (char *)"BTC",(char *)notarized_desttxid.ToString().c_str(),&kmdnotarized_height);
|
||||||
|
obj.push_back(Pair("notarizedtxid_height", txid_height));
|
||||||
|
obj.push_back(Pair("kmdnotarized_height", kmdnotarized_height));
|
||||||
|
obj.push_back(Pair("notarized_confirms", txid_height < kmdnotarized_height ? (kmdnotarized_height - txid_height) : 0));
|
||||||
|
}
|
||||||
#ifdef ENABLE_WALLET
|
#ifdef ENABLE_WALLET
|
||||||
if (pwalletMain) {
|
if (pwalletMain) {
|
||||||
obj.push_back(Pair("walletversion", pwalletMain->GetVersion()));
|
obj.push_back(Pair("walletversion", pwalletMain->GetVersion()));
|
||||||
obj.push_back(Pair("balance", ValueFromAmount(pwalletMain->GetBalance())));
|
obj.push_back(Pair("balance", ValueFromAmount(pwalletMain->GetBalance())));
|
||||||
obj.push_back(Pair("interest", ValueFromAmount(komodo_interestsum())));
|
if ( ASSETCHAINS_SYMBOL[0] == 0 )
|
||||||
|
obj.push_back(Pair("interest", ValueFromAmount(komodo_interestsum())));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
obj.push_back(Pair("blocks", (int)chainActive.Height()));
|
obj.push_back(Pair("blocks", (int)chainActive.Height()));
|
||||||
@@ -126,11 +139,13 @@ Value getinfo(const Array& params, bool fHelp)
|
|||||||
obj.push_back(Pair("errors", GetWarnings("statusbar")));
|
obj.push_back(Pair("errors", GetWarnings("statusbar")));
|
||||||
{
|
{
|
||||||
char pubkeystr[65]; int32_t notaryid;
|
char pubkeystr[65]; int32_t notaryid;
|
||||||
notaryid = komodo_whoami(pubkeystr,(int32_t)chainActive.Tip()->nHeight);
|
if ( (notaryid= komodo_whoami(pubkeystr,(int32_t)chainActive.Tip()->nHeight)) >= 0 )
|
||||||
obj.push_back(Pair("notaryid", notaryid));
|
{
|
||||||
obj.push_back(Pair("pubkey", pubkeystr));
|
obj.push_back(Pair("notaryid", notaryid));
|
||||||
if ( KOMODO_LASTMINED != 0 )
|
obj.push_back(Pair("pubkey", pubkeystr));
|
||||||
obj.push_back(Pair("lastmined", KOMODO_LASTMINED));
|
if ( KOMODO_LASTMINED != 0 )
|
||||||
|
obj.push_back(Pair("lastmined", KOMODO_LASTMINED));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user