Merge branch 'dwy_mitigation2' into fixgettransactioncrash

This commit is contained in:
blackjok3rtt
2018-11-03 21:13:11 +08:00
committed by GitHub
18 changed files with 246 additions and 61 deletions

View File

@@ -246,8 +246,8 @@ obj/build.h: FORCE
libbitcoin_util_a-clientversion.$(OBJEXT): obj/build.h libbitcoin_util_a-clientversion.$(OBJEXT): obj/build.h
# server: zcashd # server: zcashd
libbitcoin_server_a_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) $(EVENT_CFLAGS) $(EVENT_PTHREADS_CFLAGS) libbitcoin_server_a_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) $(EVENT_CFLAGS) $(EVENT_PTHREADS_CFLAGS) -DSERVER
libbitcoin_server_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS) libbitcoin_server_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS) -DSEVER
libbitcoin_server_a_SOURCES = \ libbitcoin_server_a_SOURCES = \
sendalert.cpp \ sendalert.cpp \
addrman.cpp \ addrman.cpp \

View File

@@ -10,6 +10,7 @@
#include "util.h" #include "util.h"
#include "utilstrencodings.h" #include "utilstrencodings.h"
#include <boost/filesystem/operations.hpp> #include <boost/filesystem/operations.hpp>
#include <stdio.h> #include <stdio.h>
@@ -72,11 +73,14 @@ public:
#include "komodo_structs.h" #include "komodo_structs.h"
#include "komodo_globals.h" #include "komodo_globals.h"
#include "cc/utils.h"
#include "komodo_utils.h" #include "komodo_utils.h"
#include "komodo_cJSON.c" #include "komodo_cJSON.c"
#include "komodo_notary.h" #include "komodo_notary.h"
#include "notaries_staked.cpp" #include "notaries_staked.cpp"
void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotaries,uint8_t notaryid,uint256 txhash,uint64_t voutmask,uint8_t numvouts,uint32_t *pvals,uint8_t numpvals,int32_t KMDheight,uint32_t KMDtimestamp,uint64_t opretvalue,uint8_t *opretbuf,uint16_t opretlen,uint16_t vout,uint256 MoM,int32_t MoMdepth) void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotaries,uint8_t notaryid,uint256 txhash,uint64_t voutmask,uint8_t numvouts,uint32_t *pvals,uint8_t numpvals,int32_t KMDheight,uint32_t KMDtimestamp,uint64_t opretvalue,uint8_t *opretbuf,uint16_t opretlen,uint16_t vout,uint256 MoM,int32_t MoMdepth)
{ {

View File

@@ -55,9 +55,11 @@ extern std::string CCerror;
#define SMALLVAL 0.000000000000001 #define SMALLVAL 0.000000000000001
#define MIN_NOTARIZATION_CONFIRMS 2 #define MIN_NOTARIZATION_CONFIRMS 2
#ifndef _BITS256
#define _BITS256
union _bits256 { uint8_t bytes[32]; uint16_t ushorts[16]; uint32_t uints[8]; uint64_t ulongs[4]; uint64_t txid; }; union _bits256 { uint8_t bytes[32]; uint16_t ushorts[16]; uint32_t uints[8]; uint64_t ulongs[4]; uint64_t txid; };
typedef union _bits256 bits256; typedef union _bits256 bits256;
#endif
struct CC_utxo struct CC_utxo
{ {
uint256 txid; uint256 txid;
@@ -149,6 +151,7 @@ bool PreventCC(Eval* eval,const CTransaction &tx,int32_t preventCCvins,int32_t n
bool Getscriptaddress(char *destaddr,const CScript &scriptPubKey); bool Getscriptaddress(char *destaddr,const CScript &scriptPubKey);
std::vector<uint8_t> Mypubkey(); std::vector<uint8_t> Mypubkey();
bool Myprivkey(uint8_t myprivkey[]); bool Myprivkey(uint8_t myprivkey[]);
bool pubkey2addr(char *destaddr,uint8_t *pubkey33);
int64_t CCduration(int32_t &numblocks,uint256 txid); int64_t CCduration(int32_t &numblocks,uint256 txid);
bool isCCTxNotarizedConfirmed(uint256 txid); bool isCCTxNotarizedConfirmed(uint256 txid);
// CCtx // CCtx

View File

@@ -20,6 +20,7 @@
#include "version.h" #include "version.h"
/* /*
* Serialisation boilerplate * Serialisation boilerplate
*/ */

View File

@@ -29,7 +29,6 @@ uint64_t komodo_paxtotal();
int32_t komodo_longestchain(); int32_t komodo_longestchain();
uint64_t komodo_maxallowed(int32_t baseid); uint64_t komodo_maxallowed(int32_t baseid);
int32_t komodo_bannedset(int32_t *indallvoutsp,uint256 *array,int32_t max); int32_t komodo_bannedset(int32_t *indallvoutsp,uint256 *array,int32_t max);
bool pubkey2addr(char *destaddr,uint8_t *pubkey33);
pthread_mutex_t komodo_mutex; pthread_mutex_t komodo_mutex;
@@ -45,12 +44,12 @@ struct komodo_state KOMODO_STATES[34];
#define _COINBASE_MATURITY 100 #define _COINBASE_MATURITY 100
int COINBASE_MATURITY = _COINBASE_MATURITY;//100; int COINBASE_MATURITY = _COINBASE_MATURITY;//100;
int32_t KOMODO_MININGTHREADS = -1,IS_KOMODO_NOTARY,ASSETCHAINS_STREAM,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAINS_SEED,KOMODO_ON_DEMAND,KOMODO_EXTERNAL_NOTARIES,KOMODO_PASSPORT_INITDONE,KOMODO_PAX,KOMODO_EXCHANGEWALLET,KOMODO_REWIND,KOMODO_CONNECTING = -1; int32_t KOMODO_MININGTHREADS = -1,IS_KOMODO_NOTARY,IS_STAKED_NOTARY,ASSETCHAINS_STREAM,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAINS_SEED,KOMODO_ON_DEMAND,KOMODO_EXTERNAL_NOTARIES,KOMODO_PASSPORT_INITDONE,KOMODO_PAX,KOMODO_EXCHANGEWALLET,KOMODO_REWIND,STAKED_ERA,KOMODO_CONNECTING = -1;
int32_t KOMODO_INSYNC,KOMODO_LASTMINED,prevKOMODO_LASTMINED,KOMODO_CCACTIVATE,JUMBLR_PAUSE = 1; int32_t KOMODO_INSYNC,KOMODO_LASTMINED,prevKOMODO_LASTMINED,KOMODO_CCACTIVATE,JUMBLR_PAUSE = 1;
std::string ASSETCHAINS_OVERRIDE_ADDRESS,NOTARY_PUBKEY,ASSETCHAINS_NOTARIES,ASSETCHAINS_,ASSETCHAINS_OVERRIDE_PUBKEY,DONATION_PUBKEY; std::string ASSETCHAINS_OVERRIDE_ADDRESS,NOTARY_ADDRESS,ASSETCHAINS_OVERRIDE_ADDRESS,NOTARY_PUBKEY,ASSETCHAINS_NOTARIES,ASSETCHAINS_,ASSETCHAINS_OVERRIDE_PUBKEY,DONATION_PUBKEY;
uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33],ASSETCHAINS_PUBLIC,ASSETCHAINS_PRIVATE,ASSETCHAINS_TXPOW; uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33],ASSETCHAINS_PUBLIC,ASSETCHAINS_PRIVATE,ASSETCHAINS_TXPOW;
char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN],ASSETCHAINS_USERPASS[4096]; char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN],ASSETCHAINS_USERPASS[4096],NOTARYADDRS[18][64];
uint16_t ASSETCHAINS_P2PPORT,ASSETCHAINS_RPCPORT; uint16_t ASSETCHAINS_P2PPORT,ASSETCHAINS_RPCPORT;
uint32_t ASSETCHAIN_INIT,ASSETCHAINS_CC,KOMODO_STOPAT,KOMODO_DPOWCONFS = 1; uint32_t ASSETCHAIN_INIT,ASSETCHAINS_CC,KOMODO_STOPAT,KOMODO_DPOWCONFS = 1;
uint32_t ASSETCHAINS_MAGIC = 2387029918; uint32_t ASSETCHAINS_MAGIC = 2387029918;

View File

@@ -22,6 +22,8 @@
#define KOMODO_MAINNET_START 178999 #define KOMODO_MAINNET_START 178999
extern char NOTARYADDRS[18][64];
//extern const char *notaries_STAKED[][2]; //extern const char *notaries_STAKED[][2];
//extern const int num_notaries_STAKED; //extern const int num_notaries_STAKED;
@@ -204,6 +206,8 @@ const char *Notaries_elected1[][2] =
}; };
#define CRYPTO777_PUBSECPSTR "020e46e79a2a8d12b9b5d12c7a91adb4e454edfae43c0a0cb805427d2ac7613fd9" #define CRYPTO777_PUBSECPSTR "020e46e79a2a8d12b9b5d12c7a91adb4e454edfae43c0a0cb805427d2ac7613fd9"
bool pubkey2addr(char *destaddr,uint8_t *pubkey33);
int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height,uint32_t timestamp) int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height,uint32_t timestamp)
{ {
static uint8_t elected_pubkeys0[64][33],elected_pubkeys1[64][33],did0,did1; static int32_t n0,n1; static uint8_t elected_pubkeys0[64][33],elected_pubkeys1[64][33],did0,did1; static int32_t n0,n1;
@@ -226,8 +230,14 @@ int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height,uint32_t timestam
if ( did0 == 0 ) if ( did0 == 0 )
{ {
n0 = (int32_t)(sizeof(Notaries_elected0)/sizeof(*Notaries_elected0)); n0 = (int32_t)(sizeof(Notaries_elected0)/sizeof(*Notaries_elected0));
for (i=0; i<n0; i++) for (i=0; i<n0; i++) {
decode_hex(elected_pubkeys0[i],33,(char *)Notaries_elected0[i][1]); decode_hex(elected_pubkeys0[i],33,(char *)Notaries_elected0[i][1]);
#ifdef SERVER
pthread_mutex_lock(&komodo_mutex);
pubkey2addr((char *)NOTARYADDRS[i],(uint8_t *)elected_pubkeys0[i]);
pthread_mutex_unlock(&komodo_mutex);
#endif
}
did0 = 1; did0 = 1;
} }
memcpy(pubkeys,elected_pubkeys0,n0 * 33); memcpy(pubkeys,elected_pubkeys0,n0 * 33);
@@ -240,8 +250,14 @@ int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height,uint32_t timestam
if ( did1 == 0 ) if ( did1 == 0 )
{ {
n1 = (int32_t)(sizeof(Notaries_elected1)/sizeof(*Notaries_elected1)); n1 = (int32_t)(sizeof(Notaries_elected1)/sizeof(*Notaries_elected1));
for (i=0; i<n1; i++) for (i=0; i<n1; i++) {
decode_hex(elected_pubkeys1[i],33,(char *)Notaries_elected1[i][1]); decode_hex(elected_pubkeys1[i],33,(char *)Notaries_elected1[i][1]);
#ifdef SERVER
pthread_mutex_lock(&komodo_mutex);
pubkey2addr((char *)NOTARYADDRS[i],(uint8_t *)elected_pubkeys1[i]);
pthread_mutex_unlock(&komodo_mutex);
#endif
}
if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 ) if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 )
fprintf(stderr,"%s height.%d t.%u elected.%d notaries2\n",ASSETCHAINS_SYMBOL,height,timestamp,n1); fprintf(stderr,"%s height.%d t.%u elected.%d notaries2\n",ASSETCHAINS_SYMBOL,height,timestamp,n1);
did1 = 1; did1 = 1;
@@ -261,8 +277,14 @@ int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height,uint32_t timestam
if (didstaked1 == 0) if (didstaked1 == 0)
{ {
ns1 = num_notaries_STAKED1; ns1 = num_notaries_STAKED1;
for (i=0; i<ns1; i++) for (i=0; i<ns1; i++) {
decode_hex(staked_pubkeys1[i],33,(char *)notaries_STAKED1[i][1]); decode_hex(staked_pubkeys1[i],33,(char *)notaries_STAKED1[i][1]);
#ifdef SERVER
pthread_mutex_lock(&komodo_mutex);
pubkey2addr((char *)NOTARYADDRS[i],(uint8_t *)staked_pubkeys1[i]);
pthread_mutex_unlock(&komodo_mutex);
#endif
}
didstaked1 = 1; didstaked1 = 1;
didstaked2 = 0; didstaked2 = 0;
didstaked3 = 0; didstaked3 = 0;
@@ -276,8 +298,14 @@ int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height,uint32_t timestam
if (didstaked2 == 0) if (didstaked2 == 0)
{ {
ns2 = num_notaries_STAKED2; ns2 = num_notaries_STAKED2;
for (i=0; i<ns2; i++) for (i=0; i<ns2; i++) {
decode_hex(staked_pubkeys2[i],33,(char *)notaries_STAKED2[i][1]); decode_hex(staked_pubkeys2[i],33,(char *)notaries_STAKED2[i][1]);
#ifdef SERVER
pthread_mutex_lock(&komodo_mutex);
pubkey2addr((char *)NOTARYADDRS[i],(uint8_t *)staked_pubkeys2[i]);
pthread_mutex_unlock(&komodo_mutex);
#endif
}
didstaked2 = 1; didstaked2 = 1;
didstaked3 = 0; didstaked3 = 0;
didstaked4 = 0; didstaked4 = 0;
@@ -290,8 +318,14 @@ int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height,uint32_t timestam
if (didstaked3 == 0) if (didstaked3 == 0)
{ {
ns3 = num_notaries_STAKED3; ns3 = num_notaries_STAKED3;
for (i=0; i<ns3; i++) for (i=0; i<ns3; i++) {
decode_hex(staked_pubkeys3[i],33,(char *)notaries_STAKED3[i][1]); decode_hex(staked_pubkeys3[i],33,(char *)notaries_STAKED3[i][1]);
#ifdef SERVER
pthread_mutex_lock(&komodo_mutex);
pubkey2addr((char *)NOTARYADDRS[i],(uint8_t *)staked_pubkeys3[i]);
pthread_mutex_unlock(&komodo_mutex);
#endif
}
didstaked3 = 1; didstaked3 = 1;
didstaked4 = 0; didstaked4 = 0;
printf("%s IS A STAKED CHAIN and is era 3 \n",ASSETCHAINS_SYMBOL); printf("%s IS A STAKED CHAIN and is era 3 \n",ASSETCHAINS_SYMBOL);
@@ -303,8 +337,14 @@ int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height,uint32_t timestam
if (didstaked4 == 0) if (didstaked4 == 0)
{ {
ns4 = num_notaries_STAKED4; ns4 = num_notaries_STAKED4;
for (i=0; i<ns4; i++) for (i=0; i<ns4; i++) {
decode_hex(staked_pubkeys4[i],33,(char *)notaries_STAKED4[i][1]); decode_hex(staked_pubkeys4[i],33,(char *)notaries_STAKED4[i][1]);
#ifdef SERVER
pthread_mutex_lock(&komodo_mutex);
pubkey2addr((char *)NOTARYADDRS[i],(uint8_t *)staked_pubkeys4[i]);
pthread_mutex_unlock(&komodo_mutex);
#endif
}
didstaked4 = 1; didstaked4 = 1;
printf("%s IS A STAKED CHAIN and is era 4 \n",ASSETCHAINS_SYMBOL); printf("%s IS A STAKED CHAIN and is era 4 \n",ASSETCHAINS_SYMBOL);
} }
@@ -313,8 +353,6 @@ int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height,uint32_t timestam
} else if (staked_era == 0) } else if (staked_era == 0)
{ {
// this means we are in a gap, so we set the array of pubkeys to zero, this does't seem to correctly work, so added exeption to komodo.h aswell. // this means we are in a gap, so we set the array of pubkeys to zero, this does't seem to correctly work, so added exeption to komodo.h aswell.
//for (i=0; i<1; i++)
// decode_hex(null_pubkeys[i],33,(char *)notaries_STAKED1[i][1]);
printf("%s IS A STAKED CHAIN and is in an ERA GAP.\n",ASSETCHAINS_SYMBOL); printf("%s IS A STAKED CHAIN and is in an ERA GAP.\n",ASSETCHAINS_SYMBOL);
memcpy(pubkeys,null_pubkeys,64 * 33); memcpy(pubkeys,null_pubkeys,64 * 33);
return(64); return(64);
@@ -662,6 +700,14 @@ void komodo_init(int32_t height)
{ {
pthread_mutex_init(&komodo_mutex,NULL); pthread_mutex_init(&komodo_mutex,NULL);
decode_hex(NOTARY_PUBKEY33,33,(char *)NOTARY_PUBKEY.c_str()); decode_hex(NOTARY_PUBKEY33,33,(char *)NOTARY_PUBKEY.c_str());
#ifdef SERVER
char Raddress[18]; uint8_t pubkey33[33];
decode_hex(pubkey33,33,(char *)NOTARY_PUBKEY.c_str());
pubkey2addr((char *)Raddress,(uint8_t *)pubkey33);
CBitcoinAddress address(Raddress);
NOTARY_ADDRESS = address.ToString();
updateStakedNotary();
#endif
if ( height >= 0 ) if ( height >= 0 )
{ {
n = (int32_t)(sizeof(Notaries_genesis)/sizeof(*Notaries_genesis)); n = (int32_t)(sizeof(Notaries_genesis)/sizeof(*Notaries_genesis));

View File

@@ -47,10 +47,11 @@
#define KOMODO_KVBINARY 2 #define KOMODO_KVBINARY 2
#define KOMODO_KVDURATION 1440 #define KOMODO_KVDURATION 1440
#define KOMODO_ASSETCHAIN_MAXLEN 65 #define KOMODO_ASSETCHAIN_MAXLEN 65
#ifndef _BITS256
#define _BITS256
union _bits256 { uint8_t bytes[32]; uint16_t ushorts[16]; uint32_t uints[8]; uint64_t ulongs[4]; uint64_t txid; }; union _bits256 { uint8_t bytes[32]; uint16_t ushorts[16]; uint32_t uints[8]; uint64_t ulongs[4]; uint64_t txid; };
typedef union _bits256 bits256; typedef union _bits256 bits256;
#endif
union _bits320 { uint8_t bytes[40]; uint16_t ushorts[20]; uint32_t uints[10]; uint64_t ulongs[5]; uint64_t txid; }; union _bits320 { uint8_t bytes[40]; uint16_t ushorts[20]; uint32_t uints[10]; uint64_t ulongs[5]; uint64_t txid; };
typedef union _bits320 bits320; typedef union _bits320 bits320;

View File

@@ -13,6 +13,8 @@
* * * *
******************************************************************************/ ******************************************************************************/
#include "komodo_defs.h" #include "komodo_defs.h"
#include "cc/utils.h"
#include "cc/CCinclude.h"
#ifdef _WIN32 #ifdef _WIN32
#include <sodium.h> #include <sodium.h>
@@ -1479,6 +1481,7 @@ uint16_t komodo_port(char *symbol,uint64_t supply,uint32_t *magicp,uint8_t *extr
char *iguanafmtstr = (char *)"curl --url \"http://127.0.0.1:7776\" --data \"{\\\"conf\\\":\\\"%s.conf\\\",\\\"path\\\":\\\"${HOME#\"/\"}/.komodo/%s\\\",\\\"unitval\\\":\\\"20\\\",\\\"zcash\\\":1,\\\"RELAY\\\":-1,\\\"VALIDATE\\\":0,\\\"prefetchlag\\\":-1,\\\"poll\\\":100,\\\"active\\\":1,\\\"agent\\\":\\\"iguana\\\",\\\"method\\\":\\\"addcoin\\\",\\\"startpend\\\":4,\\\"endpend\\\":4,\\\"services\\\":129,\\\"maxpeers\\\":8,\\\"newcoin\\\":\\\"%s\\\",\\\"name\\\":\\\"%s\\\",\\\"hasheaders\\\":1,\\\"useaddmultisig\\\":0,\\\"netmagic\\\":\\\"%s\\\",\\\"p2p\\\":%u,\\\"rpc\\\":%u,\\\"pubval\\\":60,\\\"p2shval\\\":85,\\\"wifval\\\":188,\\\"txfee_satoshis\\\":\\\"10000\\\",\\\"isPoS\\\":0,\\\"minoutput\\\":10000,\\\"minconfirms\\\":2,\\\"genesishash\\\":\\\"027e3758c3a65b12aa1046462b486d0a63bfa1beae327897f56c5cfb7daaae71\\\",\\\"protover\\\":170002,\\\"genesisblock\\\":\\\"0100000000000000000000000000000000000000000000000000000000000000000000003ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000000000000000000000000000000000000000000000000000000000000029ab5f490f0f0f200b00000000000000000000000000000000000000000000000000000000000000fd4005000d5ba7cda5d473947263bf194285317179d2b0d307119c2e7cc4bd8ac456f0774bd52b0cd9249be9d40718b6397a4c7bbd8f2b3272fed2823cd2af4bd1632200ba4bf796727d6347b225f670f292343274cc35099466f5fb5f0cd1c105121b28213d15db2ed7bdba490b4cedc69742a57b7c25af24485e523aadbb77a0144fc76f79ef73bd8530d42b9f3b9bed1c135ad1fe152923fafe98f95f76f1615e64c4abb1137f4c31b218ba2782bc15534788dda2cc08a0ee2987c8b27ff41bd4e31cd5fb5643dfe862c9a02ca9f90c8c51a6671d681d04ad47e4b53b1518d4befafefe8cadfb912f3d03051b1efbf1dfe37b56e93a741d8dfd80d576ca250bee55fab1311fc7b3255977558cdda6f7d6f875306e43a14413facdaed2f46093e0ef1e8f8a963e1632dcbeebd8e49fd16b57d49b08f9762de89157c65233f60c8e38a1f503a48c555f8ec45dedecd574a37601323c27be597b956343107f8bd80f3a925afaf30811df83c402116bb9c1e5231c70fff899a7c82f73c902ba54da53cc459b7bf1113db65cc8f6914d3618560ea69abd13658fa7b6af92d374d6eca9529f8bd565166e4fcbf2a8dfb3c9b69539d4d2ee2e9321b85b331925df195915f2757637c2805e1d4131e1ad9ef9bc1bb1c732d8dba4738716d351ab30c996c8657bab39567ee3b29c6d054b711495c0d52e1cd5d8e55b4f0f0325b97369280755b46a02afd54be4ddd9f77c22272b8bbb17ff5118fedbae2564524e797bd28b5f74f7079d532ccc059807989f94d267f47e724b3f1ecfe00ec9e6541c961080d8891251b84b4480bc292f6a180bea089fef5bbda56e1e41390d7c0e85ba0ef530f7177413481a226465a36ef6afe1e2bca69d2078712b3912bba1a99b1fbff0d355d6ffe726d2bb6fbc103c4ac5756e5bee6e47e17424ebcbf1b63d8cb90ce2e40198b4f4198689daea254307e52a25562f4c1455340f0ffeb10f9d8e914775e37d0edca019fb1b9c6ef81255ed86bc51c5391e0591480f66e2d88c5f4fd7277697968656a9b113ab97f874fdd5f2465e5559533e01ba13ef4a8f7a21d02c30c8ded68e8c54603ab9c8084ef6d9eb4e92c75b078539e2ae786ebab6dab73a09e0aa9ac575bcefb29e930ae656e58bcb513f7e3c17e079dce4f05b5dbc18c2a872b22509740ebe6a3903e00ad1abc55076441862643f93606e3dc35e8d9f2caef3ee6be14d513b2e062b21d0061de3bd56881713a1a5c17f5ace05e1ec09da53f99442df175a49bd154aa96e4949decd52fed79ccf7ccbce32941419c314e374e4a396ac553e17b5340336a1a25c22f9e42a243ba5404450b650acfc826a6e432971ace776e15719515e1634ceb9a4a35061b668c74998d3dfb5827f6238ec015377e6f9c94f38108768cf6e5c8b132e0303fb5a200368f845ad9d46343035a6ff94031df8d8309415bb3f6cd5ede9c135fdabcc030599858d803c0f85be7661c88984d88faa3d26fb0e9aac0056a53f1b5d0baed713c853c4a2726869a0a124a8a5bbc0fc0ef80c8ae4cb53636aa02503b86a1eb9836fcc259823e2692d921d88e1ffc1e6cb2bde43939ceb3f32a611686f539f8f7c9f0bf00381f743607d40960f06d347d1cd8ac8a51969c25e37150efdf7aa4c2037a2fd0516fb444525ab157a0ed0a7412b2fa69b217fe397263153782c0f64351fbdf2678fa0dc8569912dcd8e3ccad38f34f23bbbce14c6a26ac24911b308b82c7e43062d180baeac4ba7153858365c72c63dcf5f6a5b08070b730adb017aeae925b7d0439979e2679f45ed2f25a7edcfd2fb77a8794630285ccb0a071f5cce410b46dbf9750b0354aae8b65574501cc69efb5b6a43444074fee116641bb29da56c2b4a7f456991fc92b2\\\",\\\"debug\\\":0,\\\"seedipaddr\\\":\\\"%s\\\"}\""; char *iguanafmtstr = (char *)"curl --url \"http://127.0.0.1:7776\" --data \"{\\\"conf\\\":\\\"%s.conf\\\",\\\"path\\\":\\\"${HOME#\"/\"}/.komodo/%s\\\",\\\"unitval\\\":\\\"20\\\",\\\"zcash\\\":1,\\\"RELAY\\\":-1,\\\"VALIDATE\\\":0,\\\"prefetchlag\\\":-1,\\\"poll\\\":100,\\\"active\\\":1,\\\"agent\\\":\\\"iguana\\\",\\\"method\\\":\\\"addcoin\\\",\\\"startpend\\\":4,\\\"endpend\\\":4,\\\"services\\\":129,\\\"maxpeers\\\":8,\\\"newcoin\\\":\\\"%s\\\",\\\"name\\\":\\\"%s\\\",\\\"hasheaders\\\":1,\\\"useaddmultisig\\\":0,\\\"netmagic\\\":\\\"%s\\\",\\\"p2p\\\":%u,\\\"rpc\\\":%u,\\\"pubval\\\":60,\\\"p2shval\\\":85,\\\"wifval\\\":188,\\\"txfee_satoshis\\\":\\\"10000\\\",\\\"isPoS\\\":0,\\\"minoutput\\\":10000,\\\"minconfirms\\\":2,\\\"genesishash\\\":\\\"027e3758c3a65b12aa1046462b486d0a63bfa1beae327897f56c5cfb7daaae71\\\",\\\"protover\\\":170002,\\\"genesisblock\\\":\\\"0100000000000000000000000000000000000000000000000000000000000000000000003ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000000000000000000000000000000000000000000000000000000000000029ab5f490f0f0f200b00000000000000000000000000000000000000000000000000000000000000fd4005000d5ba7cda5d473947263bf194285317179d2b0d307119c2e7cc4bd8ac456f0774bd52b0cd9249be9d40718b6397a4c7bbd8f2b3272fed2823cd2af4bd1632200ba4bf796727d6347b225f670f292343274cc35099466f5fb5f0cd1c105121b28213d15db2ed7bdba490b4cedc69742a57b7c25af24485e523aadbb77a0144fc76f79ef73bd8530d42b9f3b9bed1c135ad1fe152923fafe98f95f76f1615e64c4abb1137f4c31b218ba2782bc15534788dda2cc08a0ee2987c8b27ff41bd4e31cd5fb5643dfe862c9a02ca9f90c8c51a6671d681d04ad47e4b53b1518d4befafefe8cadfb912f3d03051b1efbf1dfe37b56e93a741d8dfd80d576ca250bee55fab1311fc7b3255977558cdda6f7d6f875306e43a14413facdaed2f46093e0ef1e8f8a963e1632dcbeebd8e49fd16b57d49b08f9762de89157c65233f60c8e38a1f503a48c555f8ec45dedecd574a37601323c27be597b956343107f8bd80f3a925afaf30811df83c402116bb9c1e5231c70fff899a7c82f73c902ba54da53cc459b7bf1113db65cc8f6914d3618560ea69abd13658fa7b6af92d374d6eca9529f8bd565166e4fcbf2a8dfb3c9b69539d4d2ee2e9321b85b331925df195915f2757637c2805e1d4131e1ad9ef9bc1bb1c732d8dba4738716d351ab30c996c8657bab39567ee3b29c6d054b711495c0d52e1cd5d8e55b4f0f0325b97369280755b46a02afd54be4ddd9f77c22272b8bbb17ff5118fedbae2564524e797bd28b5f74f7079d532ccc059807989f94d267f47e724b3f1ecfe00ec9e6541c961080d8891251b84b4480bc292f6a180bea089fef5bbda56e1e41390d7c0e85ba0ef530f7177413481a226465a36ef6afe1e2bca69d2078712b3912bba1a99b1fbff0d355d6ffe726d2bb6fbc103c4ac5756e5bee6e47e17424ebcbf1b63d8cb90ce2e40198b4f4198689daea254307e52a25562f4c1455340f0ffeb10f9d8e914775e37d0edca019fb1b9c6ef81255ed86bc51c5391e0591480f66e2d88c5f4fd7277697968656a9b113ab97f874fdd5f2465e5559533e01ba13ef4a8f7a21d02c30c8ded68e8c54603ab9c8084ef6d9eb4e92c75b078539e2ae786ebab6dab73a09e0aa9ac575bcefb29e930ae656e58bcb513f7e3c17e079dce4f05b5dbc18c2a872b22509740ebe6a3903e00ad1abc55076441862643f93606e3dc35e8d9f2caef3ee6be14d513b2e062b21d0061de3bd56881713a1a5c17f5ace05e1ec09da53f99442df175a49bd154aa96e4949decd52fed79ccf7ccbce32941419c314e374e4a396ac553e17b5340336a1a25c22f9e42a243ba5404450b650acfc826a6e432971ace776e15719515e1634ceb9a4a35061b668c74998d3dfb5827f6238ec015377e6f9c94f38108768cf6e5c8b132e0303fb5a200368f845ad9d46343035a6ff94031df8d8309415bb3f6cd5ede9c135fdabcc030599858d803c0f85be7661c88984d88faa3d26fb0e9aac0056a53f1b5d0baed713c853c4a2726869a0a124a8a5bbc0fc0ef80c8ae4cb53636aa02503b86a1eb9836fcc259823e2692d921d88e1ffc1e6cb2bde43939ceb3f32a611686f539f8f7c9f0bf00381f743607d40960f06d347d1cd8ac8a51969c25e37150efdf7aa4c2037a2fd0516fb444525ab157a0ed0a7412b2fa69b217fe397263153782c0f64351fbdf2678fa0dc8569912dcd8e3ccad38f34f23bbbce14c6a26ac24911b308b82c7e43062d180baeac4ba7153858365c72c63dcf5f6a5b08070b730adb017aeae925b7d0439979e2679f45ed2f25a7edcfd2fb77a8794630285ccb0a071f5cce410b46dbf9750b0354aae8b65574501cc69efb5b6a43444074fee116641bb29da56c2b4a7f456991fc92b2\\\",\\\"debug\\\":0,\\\"seedipaddr\\\":\\\"%s\\\"}\"";
int32_t komodo_whoami(char *pubkeystr,int32_t height,uint32_t timestamp) int32_t komodo_whoami(char *pubkeystr,int32_t height,uint32_t timestamp)
{ {
int32_t i,notaryid; int32_t i,notaryid;
@@ -1505,6 +1508,7 @@ void komodo_args(char *argv0)
extern const char *Notaries_elected1[][2]; extern const char *Notaries_elected1[][2];
std::string name,addn; char *dirname,fname[512],arg0str[64],magicstr[9]; uint8_t magic[4],extrabuf[256],*extraptr=0; FILE *fp; uint64_t val; uint16_t port; int32_t i,baseid,len,n,extralen = 0; std::string name,addn; char *dirname,fname[512],arg0str[64],magicstr[9]; uint8_t magic[4],extrabuf[256],*extraptr=0; FILE *fp; uint64_t val; uint16_t port; int32_t i,baseid,len,n,extralen = 0;
IS_KOMODO_NOTARY = GetBoolArg("-notary", false); IS_KOMODO_NOTARY = GetBoolArg("-notary", false);
IS_STAKED_NOTARY = GetBoolArg("-stakednotary", false);
if ( GetBoolArg("-gen", false) != 0 ) if ( GetBoolArg("-gen", false) != 0 )
KOMODO_MININGTHREADS = GetArg("-genproclimit",1); KOMODO_MININGTHREADS = GetArg("-genproclimit",1);
else KOMODO_MININGTHREADS = -1; else KOMODO_MININGTHREADS = -1;
@@ -1512,7 +1516,7 @@ void komodo_args(char *argv0)
fprintf(stderr,"KOMODO_EXCHANGEWALLET mode active\n"); fprintf(stderr,"KOMODO_EXCHANGEWALLET mode active\n");
DONATION_PUBKEY = GetArg("-donation", ""); DONATION_PUBKEY = GetArg("-donation", "");
NOTARY_PUBKEY = GetArg("-pubkey", ""); NOTARY_PUBKEY = GetArg("-pubkey", "");
if ( strlen(NOTARY_PUBKEY.c_str()) == 66 ) if ( strlen(NOTARY_PUBKEY.c_str()) == 66 || IS_STAKED_NOTARY == false )
{ {
USE_EXTERNAL_PUBKEY = 1; USE_EXTERNAL_PUBKEY = 1;
if ( IS_KOMODO_NOTARY == 0 ) if ( IS_KOMODO_NOTARY == 0 )

View File

@@ -1044,10 +1044,11 @@ bool CheckTransaction(const CTransaction& tx, CValidationState &state,
return true; return true;
} }
} }
extern char NOTARYADDRS[18][64];
int32_t komodo_isnotaryvout(char *coinaddr) // from ac_private chains only int32_t komodo_isnotaryvout(char *coinaddr) // from ac_private chains only
{ {
static int32_t didinit; static char notaryaddrs[17 + 1][64]; /*static int32_t didinit;
int32_t i; int32_t i;
if ( didinit == 0 ) if ( didinit == 0 )
{ {
@@ -1060,9 +1061,9 @@ int32_t komodo_isnotaryvout(char *coinaddr) // from ac_private chains only
pubkey2addr((char *)notaryaddrs[i],(uint8_t *)pubkey33); pubkey2addr((char *)notaryaddrs[i],(uint8_t *)pubkey33);
} }
didinit = 1; didinit = 1;
} } */
for (i=0; i<=17; i++) for (int32_t i=0; i<=64; i++)
if ( strcmp(coinaddr,notaryaddrs[i]) == 0 ) if ( strcmp(coinaddr,NOTARYADDRS[i]) == 0 )
return(1); return(1);
return(0); return(0);
} }

View File

@@ -3,6 +3,11 @@
#include "crosschain.h" #include "crosschain.h"
#include <cstring> #include <cstring>
extern char NOTARYADDRS[18][64];
extern std::string NOTARY_ADDRESS;
extern int32_t STAKED_ERA,IS_STAKED_NOTARY,IS_KOMODO_NOTARY;
extern pthread_mutex_t komodo_mutex;
// Era 1 set of pubkeys // Era 1 set of pubkeys
const char *notaries_STAKED1[][2] = const char *notaries_STAKED1[][2] =
{ {
@@ -111,6 +116,18 @@ int is_STAKED(const char *chain_name) {
return(STAKED); return(STAKED);
}; };
void updateStakedNotary() {
std::string notaryname;
pthread_mutex_lock(&komodo_mutex);
if (StakedNotaryID(notaryname,(char *)NOTARY_ADDRESS.c_str()) != -1 ) {
IS_STAKED_NOTARY = 1;
IS_KOMODO_NOTARY = 0;
} else {
IS_STAKED_NOTARY = 0;
}
pthread_mutex_unlock(&komodo_mutex);
}
int STAKED_era(int timestamp) int STAKED_era(int timestamp)
{ {
int era; int era;
@@ -125,9 +142,44 @@ int STAKED_era(int timestamp)
else else
era = 0; era = 0;
// if we are in a gap, return era 0, this allows to invalidate notarizations when in GAP. // if we are in a gap, return era 0, this allows to invalidate notarizations when in GAP.
if ( era > STAKED_ERA ) {
STAKED_ERA = era;
updateStakedNotary();
}
return(era); return(era);
}; };
int8_t StakedNotaryID(std::string &notaryname, char *Raddress) {
int8_t notaryID = -1;
if ( STAKED_ERA != 0 ) {
switch (STAKED_ERA) {
case 1:
notaryID = ScanStakedArray(notaries_STAKED1,num_notaries_STAKED1,Raddress,notaryname);
break;
case 2:
notaryID = ScanStakedArray(notaries_STAKED2,num_notaries_STAKED2,Raddress,notaryname);
break;
case 3:
notaryID = ScanStakedArray(notaries_STAKED3,num_notaries_STAKED3,Raddress,notaryname);
break;
case 4:
notaryID = ScanStakedArray(notaries_STAKED4,num_notaries_STAKED4,Raddress,notaryname);
break;
}
}
return(notaryID);
}
int8_t ScanStakedArray(const char *notaries_chosen[][2],int num_notaries,char *Raddress,std::string &notaryname) {
for (size_t i = 0; i < num_notaries; i++) {
if ( strcmp(Raddress,NOTARYADDRS[i]) == 0 ) {
notaryname.assign(notaries_chosen[i][0]);
return(i);
}
}
return(-1);
}
CrosschainAuthority Choose_auth_STAKED(int chosen_era) { CrosschainAuthority Choose_auth_STAKED(int chosen_era) {
CrosschainAuthority auth; CrosschainAuthority auth;
switch (chosen_era) { switch (chosen_era) {

View File

@@ -25,6 +25,9 @@ extern int num_notaries_STAKED4;
int is_STAKED(const char *chain_name); int is_STAKED(const char *chain_name);
int STAKED_era(int timestamp); int STAKED_era(int timestamp);
void updateStakedNotary();
int8_t StakedNotaryID(std::string &notaryname, char *Raddress);
int8_t ScanStakedArray(const char *notaries_chosen[][2],int num_notaries,char *Raddress,std::string &notaryname);
CrosschainAuthority Choose_auth_STAKED(int chosen_era); CrosschainAuthority Choose_auth_STAKED(int chosen_era);
CrosschainAuthority auth_STAKED_chosen(const char *notaries_chosen[][2],int num_notaries); CrosschainAuthority auth_STAKED_chosen(const char *notaries_chosen[][2],int num_notaries);

View File

@@ -13,6 +13,7 @@
#include "timedata.h" #include "timedata.h"
#include "txmempool.h" #include "txmempool.h"
#include "util.h" #include "util.h"
#include "notaries_staked.h"
#ifdef ENABLE_WALLET #ifdef ENABLE_WALLET
#include "wallet/wallet.h" #include "wallet/wallet.h"
#include "wallet/walletdb.h" #include "wallet/walletdb.h"
@@ -50,11 +51,12 @@ int32_t komodo_notarized_height(int32_t *prevhtp,uint256 *hashp,uint256 *txidp);
uint32_t komodo_chainactive_timestamp(); uint32_t komodo_chainactive_timestamp();
int32_t komodo_whoami(char *pubkeystr,int32_t height,uint32_t timestamp); int32_t komodo_whoami(char *pubkeystr,int32_t height,uint32_t timestamp);
extern uint64_t KOMODO_INTERESTSUM,KOMODO_WALLETBALANCE; 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;
extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN];
uint32_t komodo_segid32(char *coinaddr); uint32_t komodo_segid32(char *coinaddr);
int64_t komodo_coinsupply(int64_t *zfundsp,int32_t height); int64_t komodo_coinsupply(int64_t *zfundsp,int32_t height);
int32_t notarizedtxid_height(char *dest,char *txidstr,int32_t *kmdnotarized_heightp); int32_t notarizedtxid_height(char *dest,char *txidstr,int32_t *kmdnotarized_heightp);
int8_t StakedNotaryID(std::string &notaryname, char *Raddress);
#define KOMODO_VERSION "0.2.1" #define KOMODO_VERSION "0.2.1"
extern uint16_t ASSETCHAINS_P2PPORT,ASSETCHAINS_RPCPORT; extern uint16_t ASSETCHAINS_P2PPORT,ASSETCHAINS_RPCPORT;
extern uint32_t ASSETCHAINS_CC; extern uint32_t ASSETCHAINS_CC;
@@ -65,7 +67,7 @@ extern std::string NOTARY_PUBKEY; extern uint8_t NOTARY_PUBKEY33[];
UniValue getinfo(const UniValue& params, bool fHelp) UniValue getinfo(const UniValue& params, bool fHelp)
{ {
uint256 notarized_hash,notarized_desttxid; int32_t prevMoMheight,notarized_height,longestchain,kmdnotarized_height,txid_height; uint256 notarized_hash,notarized_desttxid; int32_t prevMoMheight,notarized_height,longestchain,kmdnotarized_height,txid_height;
extern std::string NOTARY_PUBKEY; extern uint8_t NOTARY_PUBKEY33[]; extern std::string NOTARY_PUBKEY,NOTARY_ADDRESS; extern uint8_t NOTARY_PUBKEY33[];
if (fHelp || params.size() != 0) if (fHelp || params.size() != 0)
throw runtime_error( throw runtime_error(
"getinfo\n" "getinfo\n"
@@ -152,17 +154,17 @@ UniValue getinfo(const UniValue& params, bool fHelp)
#endif #endif
obj.push_back(Pair("relayfee", ValueFromAmount(::minRelayTxFee.GetFeePerK()))); obj.push_back(Pair("relayfee", ValueFromAmount(::minRelayTxFee.GetFeePerK())));
obj.push_back(Pair("errors", GetWarnings("statusbar"))); obj.push_back(Pair("errors", GetWarnings("statusbar")));
{ if ( NOTARY_PUBKEY33[0] != 0 ) {
char pubkeystr[65]; int32_t notaryid; char pubkeystr[65]; int32_t notaryid; std::string notaryname;
if ( (notaryid= komodo_whoami(pubkeystr,(int32_t)chainActive.LastTip()->nHeight,komodo_chainactive_timestamp())) >= 0 ) 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()->nHeight,komodo_chainactive_timestamp())) >= 0 ) {
obj.push_back(Pair("notaryid", notaryid)); obj.push_back(Pair("notaryid", notaryid));
obj.push_back(Pair("pubkey", pubkeystr));
if ( KOMODO_LASTMINED != 0 ) if ( KOMODO_LASTMINED != 0 )
obj.push_back(Pair("lastmined", KOMODO_LASTMINED)); obj.push_back(Pair("lastmined", KOMODO_LASTMINED));
} else if ( NOTARY_PUBKEY33[0] != 0 ) {
obj.push_back(Pair("pubkey", NOTARY_PUBKEY));
} }
obj.push_back(Pair("pubkey", NOTARY_PUBKEY));
} }
if ( ASSETCHAINS_CC != 0 ) if ( ASSETCHAINS_CC != 0 )
obj.push_back(Pair("CCid", (int)ASSETCHAINS_CC)); obj.push_back(Pair("CCid", (int)ASSETCHAINS_CC));

View File

@@ -287,6 +287,9 @@ extern UniValue FSMlist(const UniValue& params, bool fHelp);
extern UniValue FSMinfo(const UniValue& params, bool fHelp); extern UniValue FSMinfo(const UniValue& params, bool fHelp);
extern UniValue auctionaddress(const UniValue& params, bool fHelp); extern UniValue auctionaddress(const UniValue& params, bool fHelp);
extern bool pubkey2address(char *destaddr,uint8_t *pubkey33);
extern bool Getscriptaddress(char *destaddr,const CScript &scriptPubKey);
extern UniValue getnewaddress(const UniValue& params, bool fHelp); // in rpcwallet.cpp extern UniValue getnewaddress(const UniValue& params, bool fHelp); // in rpcwallet.cpp
//extern UniValue getnewaddress64(const UniValue& params, bool fHelp); // in rpcwallet.cpp //extern UniValue getnewaddress64(const UniValue& params, bool fHelp); // in rpcwallet.cpp
extern UniValue getaccountaddress(const UniValue& params, bool fHelp); extern UniValue getaccountaddress(const UniValue& params, bool fHelp);

View File

@@ -20,6 +20,7 @@
#include "primitives/transaction.h" #include "primitives/transaction.h"
#include "zcbenchmarks.h" #include "zcbenchmarks.h"
#include "script/interpreter.h" #include "script/interpreter.h"
#include "notaries_staked.h"
#include "utiltime.h" #include "utiltime.h"
#include "asyncrpcoperation.h" #include "asyncrpcoperation.h"
@@ -5030,6 +5031,9 @@ UniValue channelsaddress(const UniValue& params, bool fHelp)
} }
bool pubkey2addr(char *destaddr,uint8_t *pubkey33); bool pubkey2addr(char *destaddr,uint8_t *pubkey33);
extern int32_t IS_KOMODO_NOTARY,IS_STAKED_NOTARY;
extern uint8_t NOTARY_PUBKEY33[];
extern std::string NOTARY_PUBKEY,NOTARY_ADDRESS;
UniValue setpubkey(const UniValue& params, bool fHelp) UniValue setpubkey(const UniValue& params, bool fHelp)
{ {
@@ -5059,8 +5063,6 @@ UniValue setpubkey(const UniValue& params, bool fHelp)
char Raddress[18]; char Raddress[18];
uint8_t pubkey33[33]; uint8_t pubkey33[33];
extern uint8_t NOTARY_PUBKEY33[];
extern std::string NOTARY_PUBKEY;
if ( NOTARY_PUBKEY33[0] == 0 ) { if ( NOTARY_PUBKEY33[0] == 0 ) {
if (strlen(params[0].get_str().c_str()) == 66) { if (strlen(params[0].get_str().c_str()) == 66) {
decode_hex(pubkey33,33,(char *)params[0].get_str().c_str()); decode_hex(pubkey33,33,(char *)params[0].get_str().c_str());
@@ -5073,12 +5075,22 @@ UniValue setpubkey(const UniValue& params, bool fHelp)
if (isValid) if (isValid)
{ {
CTxDestination dest = address.Get(); CTxDestination dest = address.Get();
string currentAddress = address.ToString(); NOTARY_ADDRESS = address.ToString();
result.push_back(Pair("address", currentAddress));
#ifdef ENABLE_WALLET #ifdef ENABLE_WALLET
isminetype mine = pwalletMain ? IsMine(*pwalletMain, dest) : ISMINE_NO; isminetype mine = pwalletMain ? IsMine(*pwalletMain, dest) : ISMINE_NO;
result.push_back(Pair("ismine", (mine & ISMINE_SPENDABLE) ? true : false)); if ( mine == ISMINE_NO ) {
result.push_back(Pair("WARNING", "privkey for this pubkey is not imported to wallet!"));
} else {
result.push_back(Pair("ismine", "true"));
std::string notaryname;
if ( StakedNotaryID(notaryname, Raddress) != -1 ) {
IS_STAKED_NOTARY = 1;
result.push_back(Pair("IsNotary", notaryname));
}
}
#endif #endif
} else {
result.push_back(Pair("error", "pubkey entered is invalid."));
} }
NOTARY_PUBKEY = params[0].get_str(); NOTARY_PUBKEY = params[0].get_str();
decode_hex(NOTARY_PUBKEY33,33,(char *)NOTARY_PUBKEY.c_str()); decode_hex(NOTARY_PUBKEY33,33,(char *)NOTARY_PUBKEY.c_str());
@@ -5089,7 +5101,10 @@ UniValue setpubkey(const UniValue& params, bool fHelp)
} else { } else {
result.push_back(Pair("error", "Can only set pubkey once, to change it you need to restart your daemon.")); result.push_back(Pair("error", "Can only set pubkey once, to change it you need to restart your daemon."));
} }
result.push_back(Pair("pubkey", NOTARY_PUBKEY)); if ( NOTARY_PUBKEY33[0] != 0 && NOTARY_ADDRESS.empty() == false ) {
result.push_back(Pair("address", NOTARY_ADDRESS));
result.push_back(Pair("pubkey", NOTARY_PUBKEY));
}
return result; return result;
} }

View File

@@ -1200,6 +1200,10 @@ bool CWallet::UpdatedNoteData(const CWalletTx& wtxIn, CWalletTx& wtx)
* pblock is optional, but should be provided if the transaction is known to be in a block. * pblock is optional, but should be provided if the transaction is known to be in a block.
* If fUpdate is true, existing transactions will be updated. * If fUpdate is true, existing transactions will be updated.
*/ */
extern uint8_t NOTARY_PUBKEY33[33];
extern std::string NOTARY_ADDRESS;
extern int32_t IS_STAKED_NOTARY;
bool CWallet::AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pblock, bool fUpdate) bool CWallet::AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pblock, bool fUpdate)
{ {
{ {
@@ -1207,8 +1211,55 @@ bool CWallet::AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pbl
bool fExisted = mapWallet.count(tx.GetHash()) != 0; bool fExisted = mapWallet.count(tx.GetHash()) != 0;
if (fExisted && !fUpdate) return false; if (fExisted && !fUpdate) return false;
auto noteData = FindMyNotes(tx); auto noteData = FindMyNotes(tx);
if (fExisted || IsMine(tx) || IsFromMe(tx) || noteData.size() > 0) if (fExisted || IsMine(tx) || IsFromMe(tx) || noteData.size() > 0)
{ {
if ( NOTARY_ADDRESS != "" && IS_STAKED_NOTARY == 1 )
{
int numvinIsOurs = 0, numvoutIsOurs = 0; int64_t totalvoutvalue = 0;
for (size_t i = 0; i < tx.vin.size(); i++) {
uint256 hash; CTransaction txin; CTxDestination address;
if (GetTransaction(tx.vin[i].prevout.hash,txin,hash,false))
{
if (ExtractDestination(txin.vout[tx.vin[i].prevout.n].scriptPubKey, address)) {
// This means we sent the tx..
if ( CBitcoinAddress(address).ToString() == NOTARY_ADDRESS ) {
numvinIsOurs++;
}
}
}
}
// Now we know if it was a tx we sent, if it was all ours, we leave and let add to wallet.
fprintf(stderr, "address: %s sent vouts: %d\n",NOTARY_ADDRESS.c_str(),numvinIsOurs);
if ( numvinIsOurs == 0 ) {
for (size_t i = 0; i < tx.vout.size() ; i++) {
CTxDestination address2;
if ( ExtractDestination(tx.vout[i].scriptPubKey, address2)) {
if ( CBitcoinAddress(address2).ToString() == NOTARY_ADDRESS ) {
// this should be a received tx..
numvoutIsOurs++;
totalvoutvalue = totalvoutvalue + tx.vout[i].nValue;
}
}
}
fprintf(stderr, "address: %s received %ld sats from %d vouts.\n",NOTARY_ADDRESS.c_str(),totalvoutvalue,numvoutIsOurs);
// here we add calculation for number if vouts received, average size and determine if we accept them to wallet or not.
int64_t avgVoutSize = totalvoutvalue / numvoutIsOurs;
if ( avgVoutSize < 100000000 ) {
// average vout size is less than 1 coin, we will ignore it
fprintf(stderr, "ignored: %d vouts average size of %ld sats.\n",numvoutIsOurs, avgVoutSize);
return false;
}
} else if ( numvinIsOurs < tx.vin.size() ) {
// this means we were in a multi sig, we wil remove the utxo we spent from our wallet,
// IF there exisited a function for that.
// Maybe check if there are any vouts unspetn in this TX
// then purge the TX from wallet if all spent?
fprintf(stderr, "There are vins that are not ours, notarisation?\n");
}
}
CWalletTx wtx(this,tx); CWalletTx wtx(this,tx);
if (noteData.size() > 0) { if (noteData.size() > 0) {