Merge branch 'master' into FSM

This commit is contained in:
blackjok3rtt
2018-12-17 11:49:30 +08:00
committed by GitHub
55 changed files with 1547 additions and 892 deletions

View File

@@ -606,6 +606,68 @@ UniValue getblockhash(const UniValue& params, bool fHelp)
return pblockindex->GetBlockHash().GetHex();
}
extern uint64_t ASSETCHAINS_STAKED;
int32_t komodo_isPoS(CBlock *pblock);
uint32_t komodo_segid32(char *coinaddr);
UniValue getlastsegidstakes(const UniValue& params, bool fHelp)
{
if (fHelp || params.size() != 1)
throw runtime_error(
"getlastsegidstakes depth\n"
"\nReturns object containing the counts of the last X blocks staked by each segid.\n"
"\nArguments:\n"
"1. depth (numeric, required) The amount of blocks to scan back."
"\nResult:\n"
"{\n"
" \"0\" : n, (numeric) number of stakes from segid 0 in the last X blocks.\n"
" .....\n"
"}\n"
"\nExamples:\n"
+ HelpExampleCli("getlastsegidstakes", "1000")
+ HelpExampleRpc("getlastsegidstakes", "1000")
);
if ( ASSETCHAINS_STAKED == 0 )
throw runtime_error("Only applies to ac_staked chains\n");
LOCK(cs_main);
int depth = params[0].get_int();
int32_t segids[64] = {0};
for (int64_t i = chainActive.Height(); i > chainActive.Height()-depth; i--)
{
CBlockIndex* pblockindex = chainActive[i];
CBlock block;
if (fHavePruned && !(pblockindex->nStatus & BLOCK_HAVE_DATA) && pblockindex->nTx > 0)
throw JSONRPCError(RPC_INTERNAL_ERROR, "Block not available (pruned data)");
if(!ReadBlockFromDisk(block, pblockindex,1))
throw JSONRPCError(RPC_INTERNAL_ERROR, "Can't read block from disk");
if ( komodo_isPoS((CBlock *)&block) != 0 )
{
CTxDestination voutaddress; int32_t segid;
if ( ExtractDestination(block.vtx[block.vtx.size()-1].vout[0].scriptPubKey,voutaddress) )
{
segid = (int32_t)komodo_segid32((char *)CBitcoinAddress(voutaddress).ToString().c_str()) & 0x3f;
segids[segid] += 1;
}
}
}
UniValue ret(UniValue::VOBJ);
for (int8_t i = 0; i < 64; i++)
{
char str[4];
sprintf(str, "%d", i);
ret.push_back(Pair(str,segids[i]));
}
return ret;
}
/*uint256 _komodo_getblockhash(int32_t nHeight)
{
uint256 hash;
@@ -859,7 +921,7 @@ UniValue kvsearch(const UniValue& params, bool fHelp)
" \"currentheight\": xxxxx, (numeric) current height of the chain\n"
" \"key\": \"xxxxx\", (string) key\n"
" \"keylen\": xxxxx, (string) length of the key \n"
" \"owner\": \"xxxxx\" (string) hex string representing the owner of the key \n"
" \"owner\": \"xxxxx\" (string) hex string representing the owner of the key \n"
" \"height\": xxxxx, (numeric) height the key was stored at\n"
" \"expiration\": xxxxx, (numeric) height the key will expire\n"
" \"flags\": x (numeric) 1 if the key was created with a password; 0 otherwise.\n"

View File

@@ -36,6 +36,8 @@ static const CRPCConvertParam vRPCConvertParams[] =
{ "sendtoaddress", 1 },
{ "sendtoaddress", 4 },
{ "settxfee", 0 },
{ "getnotarysendmany", 0 },
{ "getnotarysendmany", 1 },
{ "getreceivedbyaddress", 1 },
{ "getreceivedbyaccount", 1 },
{ "listreceivedbyaddress", 0 },
@@ -72,6 +74,7 @@ static const CRPCConvertParam vRPCConvertParams[] =
{ "listunspent", 2 },
{ "getblock", 1 },
{ "getblockheader", 1 },
{ "getlastsegidstakes", 0 },
{ "gettransaction", 1 },
{ "getrawtransaction", 1 },
{ "createrawtransaction", 0 },

View File

@@ -92,7 +92,7 @@ UniValue height_MoM(const UniValue& params, bool fHelp)
ret.push_back(Pair("kmdendi",kmdendi));
}
} else ret.push_back(Pair("error",(char *)"no MoM for height"));
return ret;
}
@@ -171,9 +171,14 @@ UniValue migrate_converttoexport(const UniValue& params, bool fHelp)
if (targetSymbol.size() == 0 || targetSymbol.size() > 32)
throw runtime_error("targetSymbol length must be >0 and <=32");
if (strcmp(ASSETCHAINS_SYMBOL,targetSymbol.c_str()) == 0)
throw runtime_error("cant send a coin to the same chain");
CAmount burnAmount = AmountFromValue(params[2]);
if (burnAmount <= 0)
throw JSONRPCError(RPC_TYPE_ERROR, "Invalid amount for export");
if (burnAmount > 1000000LL*COIN)
throw JSONRPCError(RPC_TYPE_ERROR, "Invalid amount for export, cannot export more than 1 million coins per export.");
{
CAmount needed = 0;
for (int i=0; i<tx.vout.size(); i++) needed += tx.vout[i].nValue;
@@ -222,8 +227,8 @@ UniValue migrate_createimporttransaction(const UniValue& params, bool fHelp)
CTransaction burnTx;
if (!E_UNMARSHAL(txData, ss >> burnTx))
throw runtime_error("Couldn't parse burnTx");
vector<CTxOut> payouts;
if (!E_UNMARSHAL(ParseHexV(params[1], "argument 2"), ss >> payouts))
throw runtime_error("Couldn't parse payouts");
@@ -242,7 +247,7 @@ UniValue migrate_completeimporttransaction(const UniValue& params, bool fHelp)
throw runtime_error("migrate_completeimporttransaction importTx\n\n"
"Takes a cross chain import tx with proof generated on assetchain "
"and extends proof to target chain proof root");
if (ASSETCHAINS_SYMBOL[0] != 0)
throw runtime_error("Must be called on KMD");
@@ -296,7 +301,7 @@ UniValue scanNotarisationsDB(const UniValue& params, bool fHelp)
if (height == 0) {
height = chainActive.Height();
}
Notarisation nota;
int matchedHeight = ScanNotarisationsDB(height, symbol, limit, nota);
if (!matchedHeight) return NullUniValue;

View File

@@ -332,7 +332,7 @@ UniValue setgenerate(const UniValue& params, bool fHelp)
if (params.size() > 0)
fGenerate = params[0].get_bool();
int nGenProcLimit = GetArg("-genproclimit", -1);;
int nGenProcLimit = GetArg("-genproclimit", 0);;
if (params.size() > 1)
{
nGenProcLimit = params[1].get_int();

View File

@@ -13,6 +13,7 @@
#include "timedata.h"
#include "txmempool.h"
#include "util.h"
#include "notaries_staked.h"
#ifdef ENABLE_WALLET
#include "wallet/wallet.h"
#include "wallet/walletdb.h"
@@ -51,11 +52,12 @@ bool komodo_txnotarizedconfirmed(uint256 txid);
uint32_t komodo_chainactive_timestamp();
int32_t komodo_whoami(char *pubkeystr,int32_t height,uint32_t timestamp);
extern uint64_t KOMODO_INTERESTSUM,KOMODO_WALLETBALANCE;
extern int32_t KOMODO_LASTMINED,JUMBLR_PAUSE,KOMODO_LONGESTCHAIN;
extern int32_t KOMODO_LASTMINED,JUMBLR_PAUSE,KOMODO_LONGESTCHAIN,IS_STAKED_NOTARY,IS_KOMODO_NOTARY,STAKED_ERA;
extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN];
uint32_t komodo_segid32(char *coinaddr);
int64_t komodo_coinsupply(int64_t *zfundsp,int32_t height);
int32_t notarizedtxid_height(char *dest,char *txidstr,int32_t *kmdnotarized_heightp);
int8_t StakedNotaryID(std::string &notaryname, char *Raddress);
#define KOMODO_VERSION "0.3.1"
#define VERUS_VERSION "0.4.0g"
extern uint16_t ASSETCHAINS_P2PPORT,ASSETCHAINS_RPCPORT;
@@ -64,7 +66,84 @@ extern uint32_t ASSETCHAINS_MAGIC;
extern uint64_t ASSETCHAINS_COMMISSION,ASSETCHAINS_STAKED,ASSETCHAINS_SUPPLY,ASSETCHAINS_LASTERA;
extern int32_t ASSETCHAINS_LWMAPOS,ASSETCHAINS_SAPLING;
extern uint64_t ASSETCHAINS_ENDSUBSIDY[],ASSETCHAINS_REWARD[],ASSETCHAINS_HALVING[],ASSETCHAINS_DECAY[];
extern std::string NOTARY_PUBKEY; extern uint8_t NOTARY_PUBKEY33[];
extern std::string NOTARY_PUBKEY,NOTARY_ADDRESS; extern uint8_t NOTARY_PUBKEY33[];
int32_t getera(int now)
{
for (int32_t i = 0; i < NUM_STAKED_ERAS; i++) {
if ( now <= STAKED_NOTARIES_TIMESTAMP[i] ) {
return(i);
}
}
}
UniValue getiguanajson(const UniValue& params, bool fHelp)
{
if (fHelp || params.size() != 0)
throw runtime_error("getiguanajson\nreturns json for iguana, for the current ERA.");
UniValue json(UniValue::VOBJ);
UniValue seeds(UniValue::VARR);
UniValue notaries(UniValue::VARR);
// get the current era, use local time for now.
// should ideally take blocktime of last known block?
int now = time(NULL);
int32_t era = getera(now);
// loop over seeds array and push back to json array for seeds
for (int8_t i = 0; i < 8; i++) {
seeds.push_back(iguanaSeeds[i][0]);
}
// loop over era's notaries and push back each pair to the notary array
for (int8_t i = 0; i < num_notaries_STAKED[era]; i++) {
UniValue notary(UniValue::VOBJ);
notary.push_back(Pair(notaries_STAKED[era][i][0],notaries_STAKED[era][i][1]));
notaries.push_back(notary);
}
// get the min sigs .. this always rounds UP so mine sigs in iguana is +1 min sigs in komodod, due to some rounding error.
int minsigs;
if ( num_notaries_STAKED[era]/5 > overrideMinSigs )
minsigs = (num_notaries_STAKED[era] / 5) + 1;
else
minsigs = overrideMinSigs;
json.push_back(Pair("port",iguanaPort));
json.push_back(Pair("BTCminsigs",BTCminsigs));
json.push_back(Pair("minsigs",minsigs));
json.push_back(Pair("seeds", seeds));
json.push_back(Pair("notaries",notaries));
return json;
}
UniValue getnotarysendmany(const UniValue& params, bool fHelp)
{
if (fHelp || params.size() > 1)
throw runtime_error(
"getnotarysendmany\n"
"Returns a sendmany JSON array with all current notaries Raddress's.\n"
"\nExamples:\n"
+ HelpExampleCli("getnotarysendmany", "10")
+ HelpExampleRpc("getnotarysendmany", "10")
);
int amount = 0;
if ( params.size() == 1 ) {
amount = params[0].get_int();
}
int era = getera(time(NULL));
UniValue ret(UniValue::VOBJ);
for (int i = 0; i<num_notaries_STAKED[era]; i++)
{
char Raddress[18]; uint8_t pubkey33[33];
decode_hex(pubkey33,33,(char *)notaries_STAKED[era][i][1]);
pubkey2addr((char *)Raddress,(uint8_t *)pubkey33);
ret.push_back(Pair(Raddress,amount));
}
return ret;
}
UniValue getinfo(const UniValue& params, bool fHelp)
{
@@ -162,17 +241,17 @@ UniValue getinfo(const UniValue& params, bool fHelp)
#endif
obj.push_back(Pair("relayfee", ValueFromAmount(::minRelayTxFee.GetFeePerK())));
obj.push_back(Pair("errors", GetWarnings("statusbar")));
{
char pubkeystr[65]; int32_t notaryid;
if ( (notaryid= komodo_whoami(pubkeystr,(int32_t)chainActive.LastTip()->GetHeight(),komodo_chainactive_timestamp())) >= 0 )
{
if ( NOTARY_PUBKEY33[0] != 0 ) {
char pubkeystr[65]; int32_t notaryid; std::string notaryname;
if ( (notaryid= StakedNotaryID(notaryname, (char *)NOTARY_ADDRESS.c_str())) != -1 ) {
obj.push_back(Pair("notaryid", notaryid));
obj.push_back(Pair("notaryname", notaryname));
} else if( (notaryid= komodo_whoami(pubkeystr,(int32_t)chainActive.LastTip()->GetHeight(),komodo_chainactive_timestamp())) >= 0 ) {
obj.push_back(Pair("notaryid", notaryid));
obj.push_back(Pair("pubkey", pubkeystr));
if ( KOMODO_LASTMINED != 0 )
obj.push_back(Pair("lastmined", KOMODO_LASTMINED));
} else if ( NOTARY_PUBKEY33[0] != 0 ) {
obj.push_back(Pair("pubkey", NOTARY_PUBKEY));
obj.push_back(Pair("lastmined", KOMODO_LASTMINED));
}
obj.push_back(Pair("pubkey", NOTARY_PUBKEY));
}
if ( ASSETCHAINS_CC != 0 )
obj.push_back(Pair("CCid", (int)ASSETCHAINS_CC));
@@ -183,6 +262,8 @@ UniValue getinfo(const UniValue& params, bool fHelp)
obj.push_back(Pair("rpcport", ASSETCHAINS_RPCPORT));
if ( ASSETCHAINS_SYMBOL[0] != 0 )
{
if ( is_STAKED(ASSETCHAINS_SYMBOL) != 0 )
obj.push_back(Pair("StakedEra", STAKED_ERA));
//obj.push_back(Pair("name", ASSETCHAINS_SYMBOL));
obj.push_back(Pair("magic", (int)ASSETCHAINS_MAGIC));
obj.push_back(Pair("premine", ASSETCHAINS_SUPPLY));
@@ -1303,22 +1384,22 @@ UniValue txnotarizedconfirmed(const UniValue& params, bool fHelp)
if (fHelp || params.size() < 1 || params.size() > 1)
{
string msg = "txnotarizedconfirmed txid\n"
"\nReturns true if transaction is notarized on chain that has dPoW or if confirmation number is greater than 60 on chain taht does not have dPoW.\n"
"\nReturns true if transaction is notarized on chain that has dPoW or if confirmation number is greater than 60 on chain taht does not have dPoW.\n"
"\nArguments:\n"
"1. txid (string, required) Transaction id.\n"
"1. txid (string, required) Transaction id.\n"
"\nResult:\n"
"{\n"
" true, (bool) The value the check.\n"
"}\n"
" true, (bool) The value the check.\n"
"}\n"
;
throw runtime_error(msg);
}
txid = uint256S((char *)params[0].get_str().c_str());
notarizedconfirmed=komodo_txnotarizedconfirmed(txid);
UniValue result(UniValue::VOBJ);
result.push_back(Pair("result", notarizedconfirmed));
result.push_back(Pair("result", notarizedconfirmed));
return result;
}

View File

@@ -547,7 +547,7 @@ int32_t gettxout_scriptPubKey(uint8_t *scriptPubKey,int32_t maxsize,uint256 txid
uint256 hashBlock;
if ( GetTransaction(txid,tx,hashBlock,false) == 0 )
return(-1);
else if ( n < tx.vout.size() )
else if ( n < tx.vout.size() )
{
ptr = (uint8_t *)&tx.vout[n].scriptPubKey[0];
m = tx.vout[n].scriptPubKey.size();
@@ -1286,7 +1286,7 @@ UniValue sendrawtransaction(const UniValue& params, bool fHelp)
}
} else if (fHaveChain) {
throw JSONRPCError(RPC_TRANSACTION_ALREADY_IN_CHAIN, "transaction already in block chain");
}
}
RelayTransaction(tx);
return hashTx.GetHex();

View File

@@ -276,6 +276,8 @@ static const CRPCCommand vRPCCommands[] =
// --------------------- ------------------------ ----------------------- ----------
/* Overall control/query calls */
{ "control", "help", &help, true },
{ "control", "getiguanajson", &getiguanajson, true },
{ "control", "getnotarysendmany", &getnotarysendmany, true },
{ "control", "stop", &stop, true },
/* P2P networking */
@@ -302,6 +304,7 @@ static const CRPCCommand vRPCCommands[] =
{ "blockchain", "getblockhashes", &getblockhashes, true },
{ "blockchain", "getblockhash", &getblockhash, true },
{ "blockchain", "getblockheader", &getblockheader, true },
{ "blockchain", "getlastsegidstakes", &getlastsegidstakes, true },
{ "blockchain", "getchaintips", &getchaintips, true },
{ "blockchain", "getdifficulty", &getdifficulty, true },
{ "blockchain", "getmempoolinfo", &getmempoolinfo, true },
@@ -364,16 +367,16 @@ static const CRPCCommand vRPCCommands[] =
// auction
{ "auction", "auctionaddress", &auctionaddress, true },
// lotto
{ "lotto", "lottoaddress", &lottoaddress, true },
// fsm
{ "FSM", "FSMaddress", &FSMaddress, true },
{ "FSM", "FSMcreate", &FSMcreate, true },
{ "FSM", "FSMlist", &FSMlist, true },
{ "FSM", "FSMinfo", &FSMinfo, true },
// rewards
{ "rewards", "rewardslist", &rewardslist, true },
{ "rewards", "rewardsinfo", &rewardsinfo, true },
@@ -382,7 +385,7 @@ static const CRPCCommand vRPCCommands[] =
{ "rewards", "rewardslock", &rewardslock, true },
{ "rewards", "rewardsunlock", &rewardsunlock, true },
{ "rewards", "rewardsaddress", &rewardsaddress, true },
// faucet
{ "faucet", "faucetinfo", &faucetinfo, true },
{ "faucet", "faucetfund", &faucetfund, true },
@@ -399,7 +402,7 @@ static const CRPCCommand vRPCCommands[] =
{ "channels", "channelspayment", &channelspayment, true },
{ "channels", "channelsclose", &channelsclose, true },
{ "channels", "channelsrefund", &channelsrefund, true },
// Oracles
{ "oracles", "oraclesaddress", &oraclesaddress, true },
{ "oracles", "oracleslist", &oracleslist, true },
@@ -508,6 +511,7 @@ static const CRPCCommand vRPCCommands[] =
{ "wallet", "getaccountaddress", &getaccountaddress, true },
{ "wallet", "getaccount", &getaccount, true },
{ "wallet", "getaddressesbyaccount", &getaddressesbyaccount, true },
{ "wallet", "cleanwallettransactions", &cleanwallettransactions, false },
{ "wallet", "getbalance", &getbalance, false },
{ "wallet", "getbalance64", &getbalance64, false },
{ "wallet", "getnewaddress", &getnewaddress, true },

View File

@@ -317,6 +317,7 @@ extern UniValue signmessage(const UniValue& params, bool fHelp);
extern UniValue verifymessage(const UniValue& params, bool fHelp);
extern UniValue getreceivedbyaddress(const UniValue& params, bool fHelp);
extern UniValue getreceivedbyaccount(const UniValue& params, bool fHelp);
extern UniValue cleanwallettransactions(const UniValue& params, bool fHelp);
extern UniValue getbalance(const UniValue& params, bool fHelp);
extern UniValue getbalance64(const UniValue& params, bool fHelp);
extern UniValue getunconfirmedbalance(const UniValue& params, bool fHelp);
@@ -341,6 +342,8 @@ extern UniValue encryptwallet(const UniValue& params, bool fHelp);
extern UniValue validateaddress(const UniValue& params, bool fHelp);
extern UniValue txnotarizedconfirmed(const UniValue& params, bool fHelp);
extern UniValue getinfo(const UniValue& params, bool fHelp);
extern UniValue getiguanajson(const UniValue& params, bool fHelp);
extern UniValue getnotarysendmany(const UniValue& params, bool fHelp);
extern UniValue setpubkey(const UniValue& params, bool fHelp);
extern UniValue getwalletinfo(const UniValue& params, bool fHelp);
extern UniValue getblockchaininfo(const UniValue& params, bool fHelp);
@@ -382,6 +385,7 @@ extern UniValue getblockhashes(const UniValue& params, bool fHelp);
extern UniValue getblockdeltas(const UniValue& params, bool fHelp);
extern UniValue getblockhash(const UniValue& params, bool fHelp);
extern UniValue getblockheader(const UniValue& params, bool fHelp);
extern UniValue getlastsegidstakes(const UniValue& params, bool fHelp);
extern UniValue getblock(const UniValue& params, bool fHelp);
extern UniValue gettxoutsetinfo(const UniValue& params, bool fHelp);
extern UniValue gettxout(const UniValue& params, bool fHelp);