inital commit for notarypay 0BR

This commit is contained in:
blackjok3r
2019-04-17 17:42:24 +08:00
parent 9f1c4f88e9
commit ab7558ab9d
7 changed files with 131 additions and 7 deletions

View File

@@ -75,6 +75,8 @@ uint32_t komodo_segid32(char *coinaddr);
int64_t komodo_coinsupply(int64_t *zfundsp,int64_t *sproutfundsp,int32_t height);
int32_t notarizedtxid_height(char *dest,char *txidstr,int32_t *kmdnotarized_heightp);
int8_t StakedNotaryID(std::string &notaryname, char *Raddress);
uint64_t komodo_notarypayamount(int32_t nHeight, int64_t notarycount);
int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height,uint32_t timestamp);
#define KOMODO_VERSION "0.3.3b"
#define VERUS_VERSION "0.4.0g"
@@ -168,7 +170,7 @@ UniValue geterablockheights(const UniValue& params, bool fHelp)
{
if (fHelp || params.size() != 0)
throw runtime_error(
"getnotarysendmany\n"
"geterablockheights\n"
"Returns a JSON object with the first block in each era.\n"
);
@@ -1216,6 +1218,106 @@ UniValue getaddressdeltas(const UniValue& params, bool fHelp)
}
}
CAmount checkburnaddress(CAmount &received, int64_t &nNotaryPay, int32_t &height, std::string sAddress)
{
CBitcoinAddress address(sAddress);
uint160 hashBytes; int type = 0; CAmount balance = 0;
if (address.GetIndexKey(hashBytes, type, false))
{
std::vector<std::pair<CAddressIndexKey, CAmount> > addressIndex;
if (GetAddressIndex(hashBytes, type, addressIndex))
{
for (std::vector<std::pair<CAddressIndexKey, CAmount> >::const_iterator it=addressIndex.begin(); it!=addressIndex.end(); it++)
{
if (it->second > 0)
received += it->second;
balance += it->second;
}
// Get notary pay from current chain tip
CBlockIndex* pindex = chainActive.LastTip();
nNotaryPay = pindex->nNotaryPay;
height = pindex->GetHeight();
}
}
return balance;
}
UniValue checknotarization(const UniValue& params, bool fHelp)
{
if (fHelp || params.size() != 0)
throw runtime_error(
"checknotarization\n"
"\nReturns true if burn address balance is greater than total notary pay. (requires addressindex to be enabled).\n"
);
UniValue result(UniValue::VOBJ); CAmount balance = 0, received = 0; int64_t nNotaryPay = 0; int32_t height;
// helper to test burn address's
/*uint8_t priv[32] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
uint8_t pub[33] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
char coinaddr[64]; uint8_t buf33[33];
//pubkey2addr(coinaddr, pub);
priv2addr(coinaddr,buf33,priv);
fprintf(stderr, "what.%s\n", coinaddr);
result.push_back(Pair("address", coinaddr));
return result;
*/
if ( ASSETCHAINS_NOTARY_PAY[0] == 0 )
throw runtime_error("only works for ac_notarypay chains");
// pubkey 020000000000000000000000000000000
balance = checkburnaddress(received, nNotaryPay, height, "REDVp3ox1pbcWYCzySadfHhk8UU3HM4k5x");
if ( nNotaryPay >= balance || received != balance )
return false;
return true;
}
UniValue getnotarypayinfo(const UniValue& params, bool fHelp)
{
if (fHelp || params.size() != 0)
throw runtime_error(
"getnotarypayinfo\n"
"\nReturns infomation about ac_notaypay status (requires addressindex to be enabled).\n"
"\nResult:\n"
"{\n"
" \"height\" (number) The current block height\n"
" \"balance\" (number) The current balance of the burn address\n"
" \"spent\" (bool) true if coins have been spent from the burn address\n"
" \"Total_NotaryPay\" (number) Total amount paid to notaries\n"
" \"Estimated_Notarizations_Left\" (number) the estimated amount of notarizations left before the balance is consumed\n"
" \"Estimated_Days_Left\" (number) the estimated amount of days the current balance will last\n"
" \"Estimated_Height\" (number) the estimated block height funds will run out\n"
"}\n"
);
if ( ASSETCHAINS_NOTARY_PAY[0] == 0 )
throw runtime_error("only works for ac_notarypay chains");
UniValue result(UniValue::VOBJ); CAmount balance = 0, received = 0; int64_t TotalNotaryPay = 0, NotaryPay, notaleft = 0, daysleft = 0, notarycount; int32_t height, endheight = 0; uint8_t notarypubkeys[64][33] = {0};
// pubkey 020000000000000000000000000000000
balance = checkburnaddress(received, TotalNotaryPay, height, "REDVp3ox1pbcWYCzySadfHhk8UU3HM4k5x");
notarycount = komodo_notaries(notarypubkeys, height, chainActive[height]->GetBlockTime());
NotaryPay = komodo_notarypayamount(height, notarycount);
bool spent = (received != balance);
if ( !spent )
{
notaleft = (balance - TotalNotaryPay) / NotaryPay;
daysleft = (((ASSETCHAINS_BLOCKTIME * 5) * notaleft) / 3600) / 24;
endheight = (notaleft * 5) + height;
}
result.push_back(Pair("height", height));
result.push_back(Pair("balance", ValueFromAmount(balance)));
result.push_back(Pair("spent", spent));
result.push_back(Pair("Total_NotaryPay", ValueFromAmount(TotalNotaryPay)));
result.push_back(Pair("Estimated_Notarizations_Left", notaleft));
result.push_back(Pair("Estimated_Days_Left", daysleft));
result.push_back(Pair("Estimated_Height", endheight));
return result;
}
UniValue getaddressbalance(const UniValue& params, bool fHelp)
{
if (fHelp ||params.size() > 2 || params.size() == 0)