From d09e8ea10f13e9c05738889ef86bb49f338559d2 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Thu, 12 Dec 2019 16:46:33 -0500 Subject: [PATCH] This is needed for now --- src/notaries_staked.cpp | 133 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 133 insertions(+) create mode 100644 src/notaries_staked.cpp diff --git a/src/notaries_staked.cpp b/src/notaries_staked.cpp new file mode 100644 index 000000000..db1696ed5 --- /dev/null +++ b/src/notaries_staked.cpp @@ -0,0 +1,133 @@ + +#include "notaries_staked.h" +#include "crosschain.h" +#include "cc/CCinclude.h" +#include "komodo_defs.h" +#include + +extern pthread_mutex_t staked_mutex; + +int8_t is_STAKED(const char *chain_name) +{ + static int8_t STAKED,doneinit; + if ( chain_name[0] == 0 ) + return(0); + if (doneinit == 1 && ASSETCHAINS_SYMBOL[0] != 0) + return(STAKED); + else STAKED = 0; + if ( (strcmp(chain_name, "LABS") == 0) ) + STAKED = 1; // These chains are allowed coin emissions. + else if ( (strncmp(chain_name, "LABS", 4) == 0) ) + STAKED = 2; // These chains have no coin emission, block subsidy is always 0, and comission is 0. Notary pay is allowed. + else if ( (strcmp(chain_name, "CFEK") == 0) || (strncmp(chain_name, "CFEK", 4) == 0) ) + STAKED = 3; // These chains have no speical rules at all. + else if ( (strcmp(chain_name, "TEST") == 0) || (strncmp(chain_name, "TEST", 4) == 0) ) + STAKED = 4; // These chains are for testing consensus to create a chain etc. Not meant to be actually used for anything important. + else if ( (strcmp(chain_name, "THIS_CHAIN_IS_BANNED") == 0) ) + STAKED = 255; // Any chain added to this group is banned, no notarisations are valid, as a consensus rule. Can be used to remove a chain from cluster if needed. + doneinit = 1; + return(STAKED); +}; + +int32_t STAKED_era(int timestamp) +{ + int8_t era = 0; + if (timestamp <= STAKED_NOTARIES_TIMESTAMP[0]) + return(1); + for (int32_t i = 1; i < NUM_STAKED_ERAS; i++) + { + if (timestamp <= STAKED_NOTARIES_TIMESTAMP[i] && timestamp >= (STAKED_NOTARIES_TIMESTAMP[i-1] + STAKED_ERA_GAP)) + return(i+1); + } + // if we are in a gap, return era 0, this allows to invalidate notarizations when in GAP. + return(0); +}; + +int8_t StakedNotaryID(std::string ¬aryname, char *Raddress) { + if ( STAKED_ERA != 0 ) + { + for (int8_t i = 0; i < num_notaries_STAKED[STAKED_ERA-1]; i++) { + if ( strcmp(Raddress,NOTARYADDRS[i]) == 0 ) { + notaryname.assign(notaries_STAKED[STAKED_ERA-1][i][0]); + return(i); + } + } + } + return(-1); +} + +int8_t numStakedNotaries(uint8_t pubkeys[64][33],int8_t era) { + int i; int8_t retval = 0; + static uint8_t staked_pubkeys[NUM_STAKED_ERAS][64][33],didinit[NUM_STAKED_ERAS]; + static char ChainName[65]; + + if ( ChainName[0] == 0 ) + { + if ( ASSETCHAINS_SYMBOL[0] == 0 ) + strcpy(ChainName,"KMD"); + else + strcpy(ChainName,ASSETCHAINS_SYMBOL); + } + + if ( era == 0 ) + { + // era is zero so we need to null out the pubkeys. + memset(pubkeys,0,64 * 33); + printf("%s is a STAKED chain and is in an ERA GAP.\n",ChainName); + return(64); + } + else + { + if ( didinit[era-1] == 0 ) + { + for (i=0; i