#include "notaries_staked.h" #include "crosschain.h" #include "cc/CCinclude.h" #include extern char NOTARYADDRS[64][36]; extern std::string NOTARY_ADDRESS,NOTARY_PUBKEY; extern int32_t STAKED_ERA,IS_STAKED_NOTARY,IS_KOMODO_NOTARY; extern pthread_mutex_t staked_mutex; extern uint8_t NOTARY_PUBKEY33[33],NUM_NOTARIES; 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); if ( (strcmp(chain_name, "LABS") == 0) || (strcmp(chain_name, "LABST2") == 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 ot 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 updateStakedNotary() { std::string notaryname; char Raddress[18]; uint8_t pubkey33[33]; decode_hex(pubkey33,33,(char *)NOTARY_PUBKEY.c_str()); pubkey2addr((char *)Raddress,(uint8_t *)pubkey33); NOTARY_ADDRESS.clear(); NOTARY_ADDRESS.assign(Raddress); return(StakedNotaryID(notaryname,Raddress)); } 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_pubkeys1[64][33],staked_pubkeys2[64][33],didstaked1,didstaked2; static uint8_t staked_pubkeys3[64][33],staked_pubkeys4[64][33],didstaked3,didstaked4; static char ChainName[65]; if ( ChainName[0] == 0 ) { if ( ASSETCHAINS_SYMBOL[0] == 0 ) strcpy(ChainName,"KMD"); else strcpy(ChainName,ASSETCHAINS_SYMBOL); } if ( era != 0 ) { switch (era) { case 1: if ( didstaked1 == 0 ) { for (i=0; i